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

The following examples show how to use org.eclipse.jgit.util.RawParseUtils#decode() . 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: RebaseStateUtils.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String readFile(File directory, String fileName)
        throws IOException {
    byte[] content = IO.readFully(new File(directory, fileName));
    // strip off the last LF
    int end = RawParseUtils.prevLF(content, content.length);
    return RawParseUtils.decode(content, 0, end + 1);
}
 
Example 5
Source File: RevTag.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Parse the complete tag message and decode it to a string.
 * <p>
 * This method parses and returns the message portion of the tag buffer,
 * after taking the tag'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 tag message as a string. Never null.
 */
public final String getFullMessage() {
	byte[] raw = buffer;
	int msgB = RawParseUtils.tagMessage(raw, 0);
	if (msgB < 0) {
		return ""; //$NON-NLS-1$
	}
	return RawParseUtils.decode(guessEncoding(), raw, msgB, raw.length);
}
 
Example 6
Source File: RevTag.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Parse the tag message and return the first "line" of it.
 * <p>
 * The first line is everything up to the first pair of LFs. This is the
 * "oneline" format, suitable for output in a single line display.
 * <p>
 * This method parses and returns the message portion of the tag buffer,
 * after taking the tag'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 tag message as a string. Never null. The returned string
 *         does not contain any LFs, even if the first paragraph spanned
 *         multiple lines. Embedded LFs are converted to spaces.
 */
public final String getShortMessage() {
	byte[] raw = buffer;
	int msgB = RawParseUtils.tagMessage(raw, 0);
	if (msgB < 0) {
		return ""; //$NON-NLS-1$
	}

	int msgE = RawParseUtils.endOfParagraph(raw, msgB);
	String str = RawParseUtils.decode(guessEncoding(), raw, msgB, msgE);
	if (RevCommit.hasLF(raw, msgB, msgE)) {
		str = StringUtils.replaceLineBreaksWithSpace(str);
	}
	return str;
}
 
Example 7
Source File: RevCommit.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Parse the complete commit message and decode it to a string.
 * <p>
 * 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.
 */
public final String getFullMessage() {
	byte[] raw = buffer;
	int msgB = RawParseUtils.commitMessage(raw, 0);
	if (msgB < 0) {
		return ""; //$NON-NLS-1$
	}
	return RawParseUtils.decode(guessEncoding(), raw, msgB, raw.length);
}
 
Example 8
Source File: RevCommit.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Parse the commit message and return the first "line" of it.
 * <p>
 * The first line is everything up to the first pair of LFs. This is the
 * "oneline" format, suitable for output in a single line display.
 * <p>
 * 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. The returned
 *         string does not contain any LFs, even if the first paragraph
 *         spanned multiple lines. Embedded LFs are converted to spaces.
 */
public final String getShortMessage() {
	byte[] raw = buffer;
	int msgB = RawParseUtils.commitMessage(raw, 0);
	if (msgB < 0) {
		return ""; //$NON-NLS-1$
	}

	int msgE = RawParseUtils.endOfParagraph(raw, msgB);
	String str = RawParseUtils.decode(guessEncoding(), raw, msgB, msgE);
	if (hasLF(raw, msgB, msgE)) {
		str = StringUtils.replaceLineBreaksWithSpace(str);
	}
	return str;
}
 
Example 9
Source File: ObjectWalk.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Get the current object's complete path.
 * <p>
 * This method is not very efficient and is primarily meant for debugging
 * and final output generation. Applications should try to avoid calling it,
 * and if invoked do so only once per interesting entry, where the name is
 * absolutely required for correct function.
 *
 * @return complete path of the current entry, from the root of the
 *         repository. If the current entry is in a subtree there will be at
 *         least one '/' in the returned string. Null if the current entry
 *         has no path, such as for annotated tags or root level trees.
 */
public String getPathString() {
	if (pathLen == 0) {
		pathLen = updatePathBuf(currVisit);
		if (pathLen == 0)
			return null;
	}
	return RawParseUtils.decode(pathBuf, 0, pathLen);
}
 
Example 10
Source File: FooterLine.java    From onedev with MIT License 2 votes vote down vote up
/**
 * Get key name of this footer.
 *
 * @return key name of this footer; that is the text before the ":" on the
 *         line footer's line. The text is decoded according to the commit's
 *         specified (or assumed) character encoding.
 */
public String getKey() {
	return RawParseUtils.decode(enc, buffer, keyStart, keyEnd);
}
 
Example 11
Source File: FooterLine.java    From onedev with MIT License 2 votes vote down vote up
/**
 * Get value of this footer.
 *
 * @return value of this footer; that is the text after the ":" and any
 *         leading whitespace has been skipped. May be the empty string if
 *         the footer has no value (line ended with ":"). The text is
 *         decoded according to the commit's specified (or assumed)
 *         character encoding.
 */
public String getValue() {
	return RawParseUtils.decode(enc, buffer, valStart, valEnd);
}