/** * Locate the position of the tag message body. * * @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. * @return position of the user's message buffer. */ public static final int tagMessage(byte[] b, int ptr) { final int sz = b.length; if (ptr == 0) ptr += 48; // skip the "object ..." line. while (ptr < sz && b[ptr] != '\n') ptr = nextLF(b, ptr); if (ptr < sz && b[ptr] == '\n') return ptr + 1; return -1; }
private boolean checkId(byte[] raw) { int p = bufPtr.value; try { tempId.fromString(raw, p); } catch (IllegalArgumentException e) { bufPtr.value = nextLF(raw, p); return false; } p += OBJECT_ID_STRING_LENGTH; if (raw[p] == '\n') { bufPtr.value = p + 1; return true; } bufPtr.value = nextLF(raw, p); return false; }
/** * Get line of the patch script the error appears on. * * @return line of the patch script the error appears on. */ public String getLineText() { final int eol = RawParseUtils.nextLF(buf, offset); return RawParseUtils.decode(UTF_8, buf, offset, eol); }
/** * Extract the email address (if present) from the footer. * <p> * If there is an email address looking string inside of angle brackets * (e.g. "<a@b>"), the return value is the part extracted from inside the * brackets. If no brackets are found, then {@link #getValue()} is returned * if the value contains an '@' sign. Otherwise, null. * * @return email address appearing in the value of this footer, or null. */ public String getEmailAddress() { final int lt = RawParseUtils.nextLF(buffer, valStart, '<'); if (valEnd <= lt) { final int at = RawParseUtils.nextLF(buffer, valStart, '@'); if (valStart < at && at < valEnd) return getValue(); return null; } final int gt = RawParseUtils.nextLF(buffer, lt, '>'); if (valEnd < gt) return null; return RawParseUtils.decode(enc, buffer, lt, gt - 1); }
void parseIndexLine(int ptr, int end) { // "index $asha1..$bsha1[ $mode]" where $asha1 and $bsha1 // can be unique abbreviations // final int dot2 = nextLF(buf, ptr, '.'); final int mode = nextLF(buf, dot2, ' '); oldId = AbbreviatedObjectId.fromString(buf, ptr, dot2 - 1); newId = AbbreviatedObjectId.fromString(buf, dot2 + 1, mode - 1); if (mode < end) newMode = oldMode = parseFileMode(mode, end); }
/** * 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); }
private void parseModeLine(int ptr, int eol) { // "mode $amode,$bmode..$cmode" // int n = 0; while (ptr < eol) { final int comma = nextLF(buf, ptr, ','); if (eol <= comma) break; oldModes[n++] = parseFileMode(ptr, comma); ptr = comma; } final int dot2 = nextLF(buf, ptr, '.'); oldModes[n] = parseFileMode(ptr, dot2); newMode = parseFileMode(dot2 + 1, eol); }
/** {@inheritDoc} */ @Override protected void parseIndexLine(int ptr, int eol) { // "index $asha1,$bsha1..$csha1" // final List<AbbreviatedObjectId> ids = new ArrayList<>(); while (ptr < eol) { final int comma = nextLF(buf, ptr, ','); if (eol <= comma) break; ids.add(AbbreviatedObjectId.fromString(buf, ptr, comma - 1)); ptr = comma; } oldIds = new AbbreviatedObjectId[ids.size() + 1]; ids.toArray(oldIds); final int dot2 = nextLF(buf, ptr, '.'); oldIds[ids.size()] = AbbreviatedObjectId.fromString(buf, ptr, dot2 - 1); newId = AbbreviatedObjectId.fromString(buf, dot2 + 1, eol - 1); oldModes = new FileMode[oldIds.length]; }
private void parseDeletedFileMode(int ptr, int eol) { // "deleted file mode $amode,$bmode" // changeType = ChangeType.DELETE; int n = 0; while (ptr < eol) { final int comma = nextLF(buf, ptr, ','); if (eol <= comma) break; oldModes[n++] = parseFileMode(ptr, comma); ptr = comma; } oldModes[n] = parseFileMode(ptr, eol); newMode = FileMode.MISSING; } }
static RawCharSequence textFor(RevCommit cmit) { final byte[] raw = cmit.getRawBuffer(); final int b = RawParseUtils.author(raw, 0); if (b < 0) return RawCharSequence.EMPTY; final int e = RawParseUtils.nextLF(raw, b, '>'); return new RawCharSequence(raw, b, e); }
static RawCharSequence textFor(RevCommit cmit) { final byte[] raw = cmit.getRawBuffer(); final int b = RawParseUtils.committer(raw, 0); if (b < 0) return RawCharSequence.EMPTY; final int e = RawParseUtils.nextLF(raw, b, '>'); return new RawCharSequence(raw, b, e); }
private static File getSymRef(File workTree, File dotGit, FS fs) throws IOException { byte[] content = IO.readFully(dotGit); if (!isSymRef(content)) throw new IOException(MessageFormat.format( JGitText.get().invalidGitdirRef, dotGit.getAbsolutePath())); int pathStart = 8; int lineEnd = RawParseUtils.nextLF(content, pathStart); while (content[lineEnd - 1] == '\n' || (content[lineEnd - 1] == '\r' && SystemReader.getInstance().isWindows())) lineEnd--; if (lineEnd == pathStart) throw new IOException(MessageFormat.format( JGitText.get().invalidGitdirRef, dotGit.getAbsolutePath())); String gitdirPath = RawParseUtils.decode(content, pathStart, lineEnd); File gitdirFile = fs.resolve(workTree, gitdirPath); if (gitdirFile.isAbsolute()) return gitdirFile; else return new File(workTree, gitdirPath).getCanonicalFile(); }
/** * Parse the "encoding " header as a string. * <p> * Locates the "encoding " header (if present) and returns its value. * * @param b * buffer to scan. * @return the encoding header as specified in the commit; null if the * header was not present and should be assumed. * @since 4.2 */ @Nullable public static String parseEncodingName(byte[] b) { int enc = encoding(b, 0); if (enc < 0) { return null; } int lf = nextLF(b, enc); return decode(UTF_8, b, enc, lf - 1); }
ReflogEntryImpl(byte[] raw, int pos) { oldId = ObjectId.fromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; if (raw[pos++] != ' ') throw new IllegalArgumentException( JGitText.get().rawLogMessageDoesNotParseAsLogEntry); newId = ObjectId.fromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; if (raw[pos++] != ' ') { throw new IllegalArgumentException( JGitText.get().rawLogMessageDoesNotParseAsLogEntry); } who = RawParseUtils.parsePersonIdentOnly(raw, pos); int p0 = RawParseUtils.next(raw, pos, '\t'); if (p0 >= raw.length) comment = ""; // personident has no \t, no comment present //$NON-NLS-1$ else { int p1 = RawParseUtils.nextLF(raw, p0); comment = p1 > p0 ? RawParseUtils.decode(raw, p0, p1 - 1) : ""; //$NON-NLS-1$ } }
void parseHeader() { // Parse "@@ -236,9 +236,9 @@ protected boolean" // final byte[] buf = file.buf; final MutableInteger ptr = new MutableInteger(); ptr.value = nextLF(buf, startOffset, ' '); old.startLine = -parseBase10(buf, ptr.value, ptr); if (buf[ptr.value] == ',') old.lineCount = parseBase10(buf, ptr.value + 1, ptr); else old.lineCount = 1; newStartLine = parseBase10(buf, ptr.value + 1, ptr); if (buf[ptr.value] == ',') newLineCount = parseBase10(buf, ptr.value + 1, ptr); else newLineCount = 1; }
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; }
@Override void parseHeader() { // Parse "@@@ -55,12 -163,13 +163,15 @@@ protected boolean" // final byte[] buf = file.buf; final MutableInteger ptr = new MutableInteger(); ptr.value = nextLF(buf, startOffset, ' '); for (int n = 0; n < old.length; n++) { old[n].startLine = -parseBase10(buf, ptr.value, ptr); if (buf[ptr.value] == ',') old[n].lineCount = parseBase10(buf, ptr.value + 1, ptr); else old[n].lineCount = 1; } newStartLine = parseBase10(buf, ptr.value + 1, ptr); if (buf[ptr.value] == ',') newLineCount = parseBase10(buf, ptr.value + 1, ptr); else newLineCount = 1; }
void parseCanonical(RevWalk walk, byte[] rawTag) throws CorruptObjectException { final MutableInteger pos = new MutableInteger(); final int oType; pos.value = 53; // "object $sha1\ntype " oType = Constants.decodeTypeString(this, rawTag, (byte) '\n', pos); walk.idBuffer.fromString(rawTag, 7); object = walk.lookupAny(walk.idBuffer, oType); int p = pos.value += 4; // "tag " final int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1; tagName = RawParseUtils.decode(UTF_8, rawTag, p, nameEnd); if (walk.isRetainBody()) buffer = rawTag; flags |= PARSED; }