List of usage examples for org.eclipse.jgit.util RawParseUtils decode
public static String decode(final Charset cs, final byte[] buffer, final int start, final int end)
From source file:com.google.gerrit.server.notedb.ChangeNotesParser.java
License:Apache License
private void parseChangeMessage(PatchSet.Id psId, Account.Id accountId, RevCommit commit) { byte[] raw = commit.getRawBuffer(); int size = raw.length; Charset enc = RawParseUtils.parseEncoding(raw); int subjectStart = RawParseUtils.commitMessage(raw, 0); if (subjectStart < 0 || subjectStart >= size) { return;/* ww w . j a v a 2s .c o m*/ } int subjectEnd = RawParseUtils.endOfParagraph(raw, subjectStart); if (subjectEnd == size) { return; } int changeMessageStart; if (raw[subjectEnd] == '\n') { changeMessageStart = subjectEnd + 2; //\n\n ends paragraph } else if (raw[subjectEnd] == '\r') { changeMessageStart = subjectEnd + 4; //\r\n\r\n ends paragraph } else { return; } int ptr = size - 1; int changeMessageEnd = -1; while (ptr > changeMessageStart) { ptr = RawParseUtils.prevLF(raw, ptr, '\r'); if (ptr == -1) { break; } if (raw[ptr] == '\n') { changeMessageEnd = ptr - 1; break; } else if (raw[ptr] == '\r') { changeMessageEnd = ptr - 3; break; } } if (ptr <= changeMessageStart) { return; } String changeMsgString = RawParseUtils.decode(enc, raw, changeMessageStart, changeMessageEnd + 1); ChangeMessage changeMessage = new ChangeMessage(new ChangeMessage.Key(psId.getParentKey(), commit.name()), accountId, new Timestamp(commit.getCommitterIdent().getWhen().getTime()), psId); changeMessage.setMessage(changeMsgString); changeMessages.put(psId, changeMessage); }
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 a2s . co 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;/* www . j a v a 2s . c om*/ return RawParseUtils.decode(enc, note, startOfField, endOfLine - 1); }
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;/*from w ww . j av a 2 s . c om*/ 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;/*from w w w. j a v a2 s.com*/ 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.patch.PatchListEntry.java
License:Apache License
public List<String> getHeaderLines() { final IntList m = RawParseUtils.lineMap(header, 0, header.length); final List<String> headerLines = new ArrayList<>(m.size() - 1); for (int i = 1; i < m.size() - 1; i++) { final int b = m.get(i); int e = m.get(i + 1); if (header[e - 1] == '\n') { e--;// w w w .j ava 2 s. c o m } headerLines.add(RawParseUtils.decode(Constants.CHARSET, header, b, e)); } return headerLines; }
From source file:com.google.gerrit.server.patch.Text.java
License:Apache License
@Override protected String decode(final int s, int e) { if (charset == null) { charset = charset(content, null); }/*from w w w . j a va 2 s .c o m*/ return RawParseUtils.decode(charset, content, s, e); }
From source file:org.eclipse.ptp.internal.rdt.sync.git.core.SyncFileTreeIterator.java
License:Open Source License
@Override protected boolean isEntryIgnored(int pLen) throws IOException { int pOff = pathOffset; if (0 < pOff) pOff--;//from w w w . j ava 2 s . com String p = RawParseUtils.decode(Constants.CHARSET, path, pOff, pLen); return filter.shouldIgnore(p, FileMode.TREE.equals(mode)); }
From source file:org.ms123.common.git.FileHolder.java
License:Open Source License
/** * Load the configuration as a Git text style configuration file. * <p>// w w w. j a va 2 s . com * If the file does not exist, this configuration is cleared, and thus * behaves the same as though the file exists, but is empty. * * @throws IOException * the file could not be read (but does exist). * @throws ConfigInvalidException * the file is not a properly formatted configuration file. */ @Override public void load() throws IOException, ConfigInvalidException { final FileSnapshot oldSnapshot = snapshot; final FileSnapshot newSnapshot = FileSnapshot.save(getFile()); DelimiterInputStream dis = null; try { dis = new DelimiterInputStream(new BufferedInputStream(new FileInputStream(getFile()))); byte[] array = new byte[] { 45, 45, 10 }; byte[] in = dis.readTill(array); final ObjectId newHash = hash(in); if (hash.equals(newHash)) { if (oldSnapshot.equals(newSnapshot)) oldSnapshot.setClean(newSnapshot); else snapshot = newSnapshot; } else { final String decoded; if (in.length >= 3 && in[0] == (byte) 0xEF && in[1] == (byte) 0xBB && in[2] == (byte) 0xBF) { decoded = RawParseUtils.decode(UTF8_CHARSET, in, 3, in.length); utf8Bom = true; } else { decoded = RawParseUtils.decode(in); } String content = null; try { fromText(decoded); content = getString("sw", null, "content"); } catch (org.eclipse.jgit.errors.ConfigInvalidException c) { dis = new DelimiterInputStream(new FileInputStream(getFile())); m_isUnknown = true; } if (content != null) { m_content = content; } else { in = dis.readTill(null); m_content = RawParseUtils.decode(in); } snapshot = newSnapshot; hash = newHash; } } catch (FileNotFoundException noFile) { clear(); snapshot = newSnapshot; } catch (IOException e) { final IOException e2 = new IOException(MessageFormat.format(JGitText.get().cannotReadFile, getFile())); e2.initCause(e); throw e2; } finally { if (dis != null) dis.close(); } }
From source file:playRepository.GitCommit.java
License:Apache License
/** * Parse the complete commit message and decode it to a string. * <p>/*from ww w. j av a2 s . co m*/ * This method parses and returns the message portion of the commit buffer, * after taking the commit's character set into account and decoding the * buffer using that character set. This method is a fairly expensive * operation and produces a new string on each invocation. * * @return decoded commit message as a string. Never null. */ @Override public String getMessage() { if (fullMessage == null) { final byte[] raw = revCommit.getRawBuffer(); final int msgB = RawParseUtils.commitMessage(raw, 0); if (msgB < 0) return ""; //$NON-NLS-1$ final Charset enc = parseEncoding(raw, Charset.defaultCharset()); fullMessage = RawParseUtils.decode(enc, raw, msgB, raw.length); } return fullMessage; }