Java Code Examples for org.eclipse.jgit.util.RawParseUtils#nextLF()

The following examples show how to use org.eclipse.jgit.util.RawParseUtils#nextLF() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RevTag.java    From onedev with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: GitUtils.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
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);
	if (content[lineEnd - 1] == '\n')
		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();
}
 
Example 3
Source File: FooterLine.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Extract the email address (if present) from the footer.
 * <p>
 * If there is an email address looking string inside of angle brackets
 * (e.g. "&lt;a@b&gt;"), 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);
}
 
Example 4
Source File: RevCommit.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Parse the footer lines (e.g. "Signed-off-by") for machine processing.
 * <p>
 * This method splits all of the footer lines out of the last paragraph of
 * the commit message, providing each line as a key-value pair, ordered by
 * the order of the line's appearance in the commit message itself.
 * <p>
 * A footer line's key must match the pattern {@code ^[A-Za-z0-9-]+:}, while
 * the value is free-form, but must not contain an LF. Very common keys seen
 * in the wild are:
 * <ul>
 * <li>{@code Signed-off-by} (agrees to Developer Certificate of Origin)
 * <li>{@code Acked-by} (thinks change looks sane in context)
 * <li>{@code Reported-by} (originally found the issue this change fixes)
 * <li>{@code Tested-by} (validated change fixes the issue for them)
 * <li>{@code CC}, {@code Cc} (copy on all email related to this change)
 * <li>{@code Bug} (link to project's bug tracking system)
 * </ul>
 *
 * @return ordered list of footer lines; empty list if no footers found.
 */
public final List<FooterLine> getFooterLines() {
	final byte[] raw = buffer;
	int ptr = raw.length - 1;
	while (raw[ptr] == '\n') // trim any trailing LFs, not interesting
		ptr--;

	final int msgB = RawParseUtils.commitMessage(raw, 0);
	final ArrayList<FooterLine> r = new ArrayList<>(4);
	final Charset enc = guessEncoding();
	for (;;) {
		ptr = RawParseUtils.prevLF(raw, ptr);
		if (ptr <= msgB)
			break; // Don't parse commit headers as footer lines.

		final int keyStart = ptr + 2;
		if (raw[keyStart] == '\n')
			break; // Stop at first paragraph break, no footers above it.

		final int keyEnd = RawParseUtils.endOfFooterLineKey(raw, keyStart);
		if (keyEnd < 0)
			continue; // Not a well formed footer line, skip it.

		// Skip over the ': *' at the end of the key before the value.
		//
		int valStart = keyEnd + 1;
		while (valStart < raw.length && raw[valStart] == ' ')
			valStart++;

		// Value ends at the LF, and does not include it.
		//
		int valEnd = RawParseUtils.nextLF(raw, valStart);
		if (raw[valEnd - 1] == '\n')
			valEnd--;

		r.add(new FooterLine(raw, enc, keyStart, keyEnd, valStart, valEnd));
	}
	Collections.reverse(r);
	return r;
}
 
Example 5
Source File: CommitterRevFilter.java    From onedev with MIT License 5 votes vote down vote up
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);
}
 
Example 6
Source File: AuthorRevFilter.java    From onedev with MIT License 5 votes vote down vote up
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);
}