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

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

Introduction

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

Prototype

public int getEndOffset() 

Source Link

Document

Get offset one past the end of the file script.

Usage

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

License:Apache License

private static int end(final FileHeader h) {
    if (h instanceof CombinedFileHeader) {
        return h.getEndOffset();
    }/*from www .ja v  a2s . c o  m*/
    if (!h.getHunks().isEmpty()) {
        return h.getHunks().get(0).getStartOffset();
    }
    return h.getEndOffset();
}

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 ava2s. com*/

    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.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();
    }//from  w  ww . j ava  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);
    }
}