List of usage examples for org.eclipse.jgit.util RawParseUtils nextLF
public static final int nextLF(byte[] b, int ptr)
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
private static PatchLineComment parseComment(byte[] note, MutableInteger curr, String currentFileName, PatchSet.Id psId, RevId revId, boolean isForBase, Charset enc, Status status) throws ConfigInvalidException { Change.Id changeId = psId.getParentKey(); // Check if there is a new file. boolean newFile = (RawParseUtils.match(note, curr.value, FILE.getBytes(UTF_8))) != -1; if (newFile) { // If so, parse the new file name. currentFileName = parseFilename(note, curr, changeId, enc); } else if (currentFileName == null) { throw parseException(changeId, "could not parse %s", FILE); }//from w w w. jav a 2s . c o m CommentRange range = parseCommentRange(note, curr); if (range == null) { throw parseException(changeId, "could not parse %s", COMMENT_RANGE); } Timestamp commentTime = parseTimestamp(note, curr, changeId, enc); Account.Id aId = parseAuthor(note, curr, changeId, enc); boolean hasParent = (RawParseUtils.match(note, curr.value, PARENT.getBytes(enc))) != -1; String parentUUID = null; if (hasParent) { parentUUID = parseStringField(note, curr, changeId, enc, PARENT); } String uuid = parseStringField(note, curr, changeId, enc, UUID); int commentLength = parseCommentLength(note, curr, changeId, enc); String message = RawParseUtils.decode(enc, note, curr.value, curr.value + commentLength); checkResult(message, "message contents", changeId); PatchLineComment plc = new PatchLineComment( new PatchLineComment.Key(new Patch.Key(psId, currentFileName), uuid), range.getEndLine(), aId, parentUUID, commentTime); plc.setMessage(message); plc.setSide((short) (isForBase ? 0 : 1)); if (range.getStartCharacter() != -1) { plc.setRange(range); } plc.setRevId(revId); plc.setStatus(status); curr.value = RawParseUtils.nextLF(note, curr.value + commentLength); curr.value = RawParseUtils.nextLF(note, curr.value); return plc; }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
private static String parseStringField(byte[] note, MutableInteger curr, Change.Id changeId, Charset enc, String fieldName) throws ConfigInvalidException { int endOfLine = RawParseUtils.nextLF(note, curr.value); checkHeaderLineFormat(note, curr, fieldName, enc, changeId); int startOfField = RawParseUtils.endOfFooterLineKey(note, curr.value) + 2; curr.value = endOfLine;// w ww . jav a2s . c o m return RawParseUtils.decode(enc, note, startOfField, endOfLine - 1); }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
private static PatchSet.Id parsePsId(byte[] note, MutableInteger curr, Change.Id changeId, Charset enc, String fieldName) throws ConfigInvalidException { checkHeaderLineFormat(note, curr, fieldName, enc, changeId); int startOfPsId = RawParseUtils.endOfFooterLineKey(note, curr.value) + 1; MutableInteger i = new MutableInteger(); int patchSetId = RawParseUtils.parseBase10(note, startOfPsId, i); int endOfLine = RawParseUtils.nextLF(note, curr.value); if (i.value != endOfLine - 1) { throw parseException(changeId, "could not parse %s", fieldName); }// w ww . j ava2 s .c o m checkResult(patchSetId, "patchset id", changeId); curr.value = endOfLine; return new PatchSet.Id(changeId, patchSetId); }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
private static String parseFilename(byte[] note, MutableInteger curr, Change.Id changeId, Charset enc) throws ConfigInvalidException { checkHeaderLineFormat(note, curr, FILE, enc, changeId); int startOfFileName = RawParseUtils.endOfFooterLineKey(note, curr.value) + 2; int endOfLine = RawParseUtils.nextLF(note, curr.value); curr.value = endOfLine;/* w w w . j a v a2 s .co m*/ curr.value = RawParseUtils.nextLF(note, curr.value); return QuotedString.GIT_PATH.dequote(RawParseUtils.decode(enc, note, startOfFileName, endOfLine - 1)); }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
private static Timestamp parseTimestamp(byte[] note, MutableInteger curr, Change.Id changeId, Charset enc) throws ConfigInvalidException { int endOfLine = RawParseUtils.nextLF(note, curr.value); Timestamp commentTime;/* ww w. ja v a2 s.c o m*/ String dateString = RawParseUtils.decode(enc, note, curr.value, endOfLine - 1); try { commentTime = new Timestamp(GitDateParser.parse(dateString, null, Locale.US).getTime()); } catch (ParseException e) { throw new ConfigInvalidException("could not parse comment timestamp", e); } curr.value = endOfLine; return checkResult(commentTime, "comment timestamp", changeId); }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
private static Account.Id parseAuthor(byte[] note, MutableInteger curr, Change.Id changeId, Charset enc) throws ConfigInvalidException { checkHeaderLineFormat(note, curr, AUTHOR, enc, changeId); int startOfAccountId = RawParseUtils.endOfFooterLineKey(note, curr.value) + 2; PersonIdent ident = RawParseUtils.parsePersonIdent(note, startOfAccountId); Account.Id aId = parseIdent(ident, changeId); curr.value = RawParseUtils.nextLF(note, curr.value); return checkResult(aId, "comment author", changeId); }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
private static int parseCommentLength(byte[] note, MutableInteger curr, Change.Id changeId, Charset enc) throws ConfigInvalidException { checkHeaderLineFormat(note, curr, LENGTH, enc, changeId); int startOfLength = RawParseUtils.endOfFooterLineKey(note, curr.value) + 1; MutableInteger i = new MutableInteger(); int commentLength = RawParseUtils.parseBase10(note, startOfLength, i); int endOfLine = RawParseUtils.nextLF(note, curr.value); if (i.value != endOfLine - 1) { throw parseException(changeId, "could not parse %s", PATCH_SET); }//from w ww .j a v a2s .c om curr.value = endOfLine; return checkResult(commentLength, "comment length", changeId); }