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

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

Introduction

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

Prototype

public PatchType getPatchType() 

Source Link

Document

Get style of patch used to modify this file.

Usage

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

License:Apache License

private static PatchType toPatchType(final FileHeader hdr) {
    PatchType pt;/*from  w w w . j a  v a  2  s .  co m*/

    switch (hdr.getPatchType()) {
    case UNIFIED:
        pt = Patch.PatchType.UNIFIED;
        break;
    case GIT_BINARY:
    case BINARY:
        pt = Patch.PatchType.BINARY;
        break;
    default:
        throw new IllegalArgumentException("Unsupported type " + hdr.getPatchType());
    }

    if (pt != PatchType.BINARY) {
        final byte[] buf = hdr.getBuffer();
        for (int ptr = hdr.getStartOffset(); ptr < hdr.getEndOffset(); ptr++) {
            if (buf[ptr] == '\0') {
                // Its really binary, but Git couldn't see the nul early enough
                // to realize its binary, and instead produced the diff.
                //
                // Force it to be a binary; it really should have been that.
                //
                pt = PatchType.BINARY;
                break;
            }
        }
    }

    return pt;
}

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  a 2 s .c  o 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);
    }
}

From source file:com.google.gitiles.HtmlDiffFormatter.java

License:Open Source License

@Override
public void format(FileHeader hdr, RawText a, RawText b) throws IOException {
    int start = hdr.getStartOffset();
    int end = hdr.getEndOffset();
    if (!hdr.getHunks().isEmpty()) {
        end = hdr.getHunks().get(0).getStartOffset();
    }/*  w w  w  .j  av a  2  s  .  c om*/
    renderHeader(RawParseUtils.decode(hdr.getBuffer(), start, end));

    if (hdr.getPatchType() == PatchType.UNIFIED) {
        getOutputStream().write(DIFF_BEGIN);
        format(hdr.toEditList(), a, b);
        getOutputStream().write(DIFF_END);
    }
}