private static boolean matchAny(final byte[] buf, final int c, final byte[][] srcs) { for (byte[] s : srcs) { if (match(buf, c, s) >= 0) return true; } return false; } }
private boolean match(byte[] b, byte[] src) { int r = RawParseUtils.match(b, bufPtr.value, src); if (r < 0) { return false; } bufPtr.value = r; return true; }
/** * Locate the "author " header line data. * * @param b * buffer to scan. * @param ptr * position in buffer to start the scan at. Most callers should * pass 0 to ensure the scan starts from the beginning of the * commit buffer and does not accidentally look at message body. * @return position just after the space in "author ", so the first * character of the author's name. If no author header can be * located -1 is returned. */ public static final int author(byte[] b, int ptr) { final int sz = b.length; if (ptr == 0) ptr += 46; // skip the "tree ..." line. while (ptr < sz && b[ptr] == 'p') ptr += 48; // skip this parent. return match(b, ptr, author); }
/** * Locate the "committer " header line data. * * @param b * buffer to scan. * @param ptr * position in buffer to start the scan at. Most callers should * pass 0 to ensure the scan starts from the beginning of the * commit buffer and does not accidentally look at message body. * @return position just after the space in "committer ", so the first * character of the committer's name. If no committer header can be * located -1 is returned. */ public static final int committer(byte[] b, int ptr) { final int sz = b.length; if (ptr == 0) ptr += 46; // skip the "tree ..." line. while (ptr < sz && b[ptr] == 'p') ptr += 48; // skip this parent. if (ptr < sz && b[ptr] == 'a') ptr = nextLF(b, ptr); return match(b, ptr, committer); }
/** * Locate the "encoding " header line. * * @param b * buffer to scan. * @param ptr * position in buffer to start the scan at. Most callers should * pass 0 to ensure the scan starts from the beginning of the * buffer and does not accidentally look at the message body. * @return position just after the space in "encoding ", so the first * character of the encoding's name. If no encoding header can be * located -1 is returned (and UTF-8 should be assumed). */ public static final int encoding(byte[] b, int ptr) { final int sz = b.length; while (ptr < sz) { if (b[ptr] == '\n') return -1; if (b[ptr] == 'e') break; ptr = nextLF(b, ptr); } return match(b, ptr, encoding); }
/** * Locate the "tagger " header line data. * * @param b * buffer to scan. * @param ptr * position in buffer to start the scan at. Most callers should * pass 0 to ensure the scan starts from the beginning of the tag * buffer and does not accidentally look at message body. * @return position just after the space in "tagger ", so the first * character of the tagger's name. If no tagger header can be * located -1 is returned. */ public static final int tagger(byte[] b, int ptr) { final int sz = b.length; if (ptr == 0) ptr += 48; // skip the "object ..." line. while (ptr < sz) { if (b[ptr] == '\n') return -1; final int m = match(b, ptr, tagger); if (m >= 0) return m; ptr = nextLF(b, ptr); } return -1; }
private static int skipFile(byte[] buf, int ptr) { ptr = nextLF(buf, ptr); if (match(buf, ptr, OLD_NAME) >= 0) ptr = nextLF(buf, ptr); return ptr; }
@Override int parseGitHeaders(int ptr, int end) { while (ptr < end) { final int eol = nextLF(buf, ptr); if (isHunkHdr(buf, ptr, end) >= 1) { // First hunk header; break out and parse them later. break; } else if (match(buf, ptr, OLD_NAME) >= 0) { parseOldName(ptr, eol); } else if (match(buf, ptr, NEW_NAME) >= 0) { parseNewName(ptr, eol); } else if (match(buf, ptr, INDEX) >= 0) { parseIndexLine(ptr + INDEX.length, eol); } else if (match(buf, ptr, MODE) >= 0) { parseModeLine(ptr + MODE.length, eol); } else if (match(buf, ptr, NEW_FILE_MODE) >= 0) { parseNewFileMode(ptr, eol); } else if (match(buf, ptr, DELETED_FILE_MODE) >= 0) { parseDeletedFileMode(ptr + DELETED_FILE_MODE.length, eol); } else { // Probably an empty patch (stat dirty). break; } ptr = eol; } return ptr; }
} else if (match(buf, ptr, OLD_NAME) >= 0) { parseOldName(ptr, eol); } else if (match(buf, ptr, NEW_NAME) >= 0) { parseNewName(ptr, eol); } else if (match(buf, ptr, OLD_MODE) >= 0) { oldMode = parseFileMode(ptr + OLD_MODE.length, eol); } else if (match(buf, ptr, NEW_MODE) >= 0) { newMode = parseFileMode(ptr + NEW_MODE.length, eol); } else if (match(buf, ptr, DELETED_FILE_MODE) >= 0) { oldMode = parseFileMode(ptr + DELETED_FILE_MODE.length, eol); newMode = FileMode.MISSING; changeType = ChangeType.DELETE; } else if (match(buf, ptr, NEW_FILE_MODE) >= 0) { parseNewFileMode(ptr, eol); } else if (match(buf, ptr, COPY_FROM) >= 0) { oldPath = parseName(oldPath, ptr + COPY_FROM.length, eol); changeType = ChangeType.COPY; } else if (match(buf, ptr, COPY_TO) >= 0) { newPath = parseName(newPath, ptr + COPY_TO.length, eol); changeType = ChangeType.COPY; } else if (match(buf, ptr, RENAME_OLD) >= 0) {
int parseTraditionalHeaders(int ptr, int end) { while (ptr < end) { final int eol = nextLF(buf, ptr); if (isHunkHdr(buf, ptr, eol) >= 1) { // First hunk header; break out and parse them later. break; } else if (match(buf, ptr, OLD_NAME) >= 0) { parseOldName(ptr, eol); } else if (match(buf, ptr, NEW_NAME) >= 0) { parseNewName(ptr, eol); } else { // Possibly an empty patch. break; } ptr = eol; } return ptr; }
private static String refName(CanonicalTreeParser p, boolean peel) { byte[] buf = p.getEntryPathBuffer(); int len = p.getEntryPathLength(); if (peel) { len -= 2; } int ptr = 0; if (RawParseUtils.match(buf, ptr, REFS_DOT_DOT) > 0) { ptr = 7; } return RawParseUtils.decode(buf, ptr, len); }
int parseHunk(int ptr, int end) { final byte[] buf = file.buf; if (match(buf, ptr, LITERAL) >= 0) { type = Type.LITERAL_DEFLATED; length = parseBase10(buf, ptr + LITERAL.length, null); } else if (match(buf, ptr, DELTA) >= 0) { type = Type.DELTA_DEFLATED; length = parseBase10(buf, ptr + DELTA.length, null);
if (match(buf, c, DIFF_GIT) >= 0) break; if (match(buf, c, DIFF_CC) >= 0) break; if (match(buf, c, DIFF_COMBINED) >= 0) break; if (match(buf, c, OLD_NAME) >= 0) break; if (match(buf, c, NEW_NAME) >= 0) break; break; default: if (match(buf, c, SIG_FOOTER) < 0) warn(buf, c, JGitText.get().unexpectedHunkTrailer); if (fh.getHunks().isEmpty() && match(buf, c, GIT_BINARY) >= 0) { fh.patchType = FileHeader.PatchType.GIT_BINARY; return parseGitBinary(fh, eol, end); && match(buf, eol - BIN_TRAILER.length, BIN_TRAILER) >= 0 && matchAny(buf, c, BIN_HEADERS)) {
if (match(buf, c, DIFF_GIT) >= 0) return parseDiffGit(buf, c, end); if (match(buf, c, DIFF_CC) >= 0) return parseDiffCombined(DIFF_CC, buf, c, end); if (match(buf, c, DIFF_COMBINED) >= 0) return parseDiffCombined(DIFF_COMBINED, buf, c, end); if (match(buf, c, OLD_NAME) >= 0 && match(buf, n, NEW_NAME) >= 0) {
&& RawParseUtils.match(buf, start, dotGitmodules) != -1) || (macosx && isMacHFSGitmodules(buf, start, end, id)) || (windows && isNTFSGitmodules(buf, start, end));
&& match(buf, last, Patch.SIG_FOOTER) >= 0) {
private void onOpenPack() throws IOException { final PackIndex idx = idx(); final byte[] buf = new byte[20]; fd.seek(0); fd.readFully(buf, 0, 12); if (RawParseUtils.match(buf, 0, Constants.PACK_SIGNATURE) != 4) { throw new NoPackSignatureException(JGitText.get().notAPACKFile); } final long vers = NB.decodeUInt32(buf, 4); final long packCnt = NB.decodeUInt32(buf, 8); if (vers != 2 && vers != 3) { throw new UnsupportedPackVersionException(vers); } if (packCnt != idx.getObjectCount()) { throw new PackMismatchException(MessageFormat.format( JGitText.get().packObjectCountMismatch, Long.valueOf(packCnt), Long.valueOf(idx.getObjectCount()), getPackFile())); } fd.seek(length - 20); fd.readFully(buf, 0, 20); if (!Arrays.equals(buf, packChecksum)) { throw new PackMismatchException(MessageFormat.format( JGitText.get().packObjectCountMismatch , ObjectId.fromRaw(buf).name() , ObjectId.fromRaw(idx.packChecksum).name() , getPackFile())); } }
private boolean match(byte[] b, byte[] src) { int r = RawParseUtils.match(b, bufPtr.value, src); if (r < 0) { return false; } bufPtr.value = r; return true; }
currentSubtree = null; if (RawParseUtils.match(path, pathOffset, DOT_GIT_ATTRIBUTES_BYTES) == path.length) attributesNode = new LazyLoadingAttributesNode( currentEntry.getObjectId());
private static int skipFile(final byte[] buf, int ptr) { ptr = nextLF(buf, ptr); if (match(buf, ptr, OLD_NAME) >= 0) ptr = nextLF(buf, ptr); return ptr; }