Example usage for org.eclipse.jgit.lib FileMode copyTo

List of usage examples for org.eclipse.jgit.lib FileMode copyTo

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib FileMode copyTo.

Prototype

public void copyTo(OutputStream os) throws IOException 

Source Link

Document

Copy this mode as a sequence of octal US-ASCII bytes.

Usage

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

private void formatHeader(ByteArrayOutputStream o, DiffEntry ent) throws IOException {
    final ChangeType type = ent.getChangeType();
    final String oldp = ent.getOldPath();
    final String newp = ent.getNewPath();
    final FileMode oldMode = ent.getOldMode();
    final FileMode newMode = ent.getNewMode();

    formatGitDiffFirstHeaderLine(o, type, oldp, newp);

    if ((type == MODIFY || type == COPY || type == RENAME) && !oldMode.equals(newMode)) {
        o.write(encodeASCII("old mode ")); //$NON-NLS-1$
        oldMode.copyTo(o);
        o.write('\n');

        o.write(encodeASCII("new mode ")); //$NON-NLS-1$
        newMode.copyTo(o);//from  w  ww.  ja v  a2s . c o  m
        o.write('\n');
    }

    switch (type) {
    case ADD:
        o.write(encodeASCII("new file mode ")); //$NON-NLS-1$
        newMode.copyTo(o);
        o.write('\n');
        break;

    case DELETE:
        o.write(encodeASCII("deleted file mode ")); //$NON-NLS-1$
        oldMode.copyTo(o);
        o.write('\n');
        break;

    case RENAME:
        o.write(encodeASCII("similarity index " + ent.getScore() + "%")); //$NON-NLS-1$ //$NON-NLS-2$
        o.write('\n');

        o.write(encode("rename from " + quotePath(oldp))); //$NON-NLS-1$
        o.write('\n');

        o.write(encode("rename to " + quotePath(newp))); //$NON-NLS-1$
        o.write('\n');
        break;

    case COPY:
        o.write(encodeASCII("similarity index " + ent.getScore() + "%")); //$NON-NLS-1$ //$NON-NLS-2$
        o.write('\n');

        o.write(encode("copy from " + quotePath(oldp))); //$NON-NLS-1$
        o.write('\n');

        o.write(encode("copy to " + quotePath(newp))); //$NON-NLS-1$
        o.write('\n');
        break;

    case MODIFY:
        if (0 < ent.getScore()) {
            o.write(encodeASCII("dissimilarity index " //$NON-NLS-1$
                    + (100 - ent.getScore()) + "%")); //$NON-NLS-1$
            o.write('\n');
        }
        break;
    }

    if (ent.getOldId() != null && !ent.getOldId().equals(ent.getNewId())) {
        formatIndexLine(o, ent);
    }
}