Example usage for org.eclipse.jgit.patch FileHeader getOldMode

List of usage examples for org.eclipse.jgit.patch FileHeader getOldMode

Introduction

In this page you can find the example usage for org.eclipse.jgit.patch FileHeader getOldMode.

Prototype

public FileMode getOldMode() 

Source Link

Document

Get the old file mode

Usage

From source file:com.google.gerrit.server.patch.PatchListEntry.java

License:Apache License

PatchListEntry(final FileHeader hdr, List<Edit> editList) {
    changeType = toChangeType(hdr);/*from  w  w  w  .j a  v  a 2 s .com*/
    patchType = toPatchType(hdr);

    switch (changeType) {
    case DELETED:
        oldName = null;
        newName = hdr.getOldPath();
        break;

    case ADDED:
    case MODIFIED:
        oldName = null;
        newName = hdr.getNewPath();
        break;

    case COPIED:
    case RENAMED:
        oldName = hdr.getOldPath();
        newName = hdr.getNewPath();
        break;

    default:
        throw new IllegalArgumentException("Unsupported type " + changeType);
    }

    header = compact(hdr);

    if (hdr instanceof CombinedFileHeader || hdr.getHunks().isEmpty() //
            || hdr.getOldMode() == FileMode.GITLINK || hdr.getNewMode() == FileMode.GITLINK) {
        edits = Collections.emptyList();
    } else {
        edits = Collections.unmodifiableList(editList);
    }

    int ins = 0;
    int del = 0;
    for (Edit e : editList) {
        del += e.getEndA() - e.getBeginA();
        ins += e.getEndB() - e.getBeginB();
    }
    insertions = ins;
    deletions = del;
}

From source file:com.google.gerrit.server.patch.PatchListLoader.java

License:Apache License

private PatchListEntry newEntry(RevTree aTree, FileHeader fileHeader) {
    final FileMode oldMode = fileHeader.getOldMode();
    final FileMode newMode = fileHeader.getNewMode();

    if (oldMode == FileMode.GITLINK || newMode == FileMode.GITLINK) {
        return new PatchListEntry(fileHeader, Collections.<Edit>emptyList());
    }//from w  w w. jav  a2 s.co m

    if (aTree == null // want combined diff
            || fileHeader.getPatchType() != PatchType.UNIFIED || fileHeader.getHunks().isEmpty()) {
        return new PatchListEntry(fileHeader, Collections.<Edit>emptyList());
    }

    List<Edit> edits = fileHeader.toEditList();
    if (edits.isEmpty()) {
        return new PatchListEntry(fileHeader, Collections.<Edit>emptyList());
    } else {
        return new PatchListEntry(fileHeader, edits);
    }
}