Java Code Examples for org.eclipse.jgit.lib.ObjectInserter#Formatter

The following examples show how to use org.eclipse.jgit.lib.ObjectInserter#Formatter . 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 3 votes vote down vote up
/**
 * Parse an annotated tag from its canonical format.
 * <p>
 * This method inserts the tag directly into the caller supplied revision
 * pool, making it appear as though the tag exists in the repository, even
 * if it doesn't. The repository under the pool is not affected.
 * <p>
 * The body of the tag (message, tagger, signature) is always retained in
 * the returned {@code RevTag}, even if the supplied {@code RevWalk} has
 * been configured with {@code setRetainBody(false)}.
 *
 * @param rw
 *            the revision pool to allocate the tag within. The tag's object
 *            pointer will be obtained from this pool.
 * @param raw
 *            the canonical formatted tag to be parsed. This buffer will be
 *            retained by the returned {@code RevTag} and must not be
 *            modified by the caller.
 * @return the parsed tag, in an isolated revision pool that is not
 *         available to the caller.
 * @throws org.eclipse.jgit.errors.CorruptObjectException
 *             the tag contains a malformed header that cannot be handled.
 */
public static RevTag parse(RevWalk rw, byte[] raw)
		throws CorruptObjectException {
	try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
		RevTag r = rw.lookupTag(fmt.idFor(Constants.OBJ_TAG, raw));
		r.parseCanonical(rw, raw);
		r.buffer = raw;
		return r;
	}
}
 
Example 2
Source File: RevCommit.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Parse a commit from its canonical format.
 * <p>
 * This method inserts the commit directly into the caller supplied revision
 * pool, making it appear as though the commit exists in the repository,
 * even if it doesn't. The repository under the pool is not affected.
 * <p>
 * The body of the commit (message, author, committer) is always retained in
 * the returned {@code RevCommit}, even if the supplied {@code RevWalk} has
 * been configured with {@code setRetainBody(false)}.
 *
 * @param rw
 *            the revision pool to allocate the commit within. The commit's
 *            tree and parent pointers will be obtained from this pool.
 * @param raw
 *            the canonical formatted commit to be parsed. This buffer will
 *            be retained by the returned {@code RevCommit} and must not be
 *            modified by the caller.
 * @return the parsed commit, in an isolated revision pool that is not
 *         available to the caller.
 * @throws java.io.IOException
 *             in case of RevWalk initialization fails
 */
public static RevCommit parse(RevWalk rw, byte[] raw) throws IOException {
	try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
		RevCommit r = rw.lookupCommit(fmt.idFor(Constants.OBJ_COMMIT, raw));
		r.parseCanonical(rw, raw);
		r.buffer = raw;
		return r;
	}
}