Java Code Examples for org.eclipse.jgit.lib.AnyObjectId#toObjectId()

The following examples show how to use org.eclipse.jgit.lib.AnyObjectId#toObjectId() . 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: RevWalk.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Locate a reference to a tree.
 * <p>
 * This method only returns successfully if the tree object exists, is
 * verified to be a tree.
 *
 * @param id
 *            name of the tree object, or a commit or annotated tag that may
 *            reference a tree.
 * @return reference to the tree object. Never null.
 * @throws org.eclipse.jgit.errors.MissingObjectException
 *             the supplied tree does not exist.
 * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
 *             the supplied id is not a tree, a commit or an annotated tag.
 * @throws java.io.IOException
 *             a pack file or loose object could not be read.
 */
@NonNull
public RevTree parseTree(AnyObjectId id)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	RevObject c = peel(parseAny(id));

	final RevTree t;
	if (c instanceof RevCommit)
		t = ((RevCommit) c).getTree();
	else if (!(c instanceof RevTree))
		throw new IncorrectObjectTypeException(id.toObjectId(),
				Constants.TYPE_TREE);
	else
		t = (RevTree) c;
	parseHeaders(t);
	return t;
}
 
Example 2
Source File: RevWalk.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Locate a reference to a commit and immediately parse its content.
 * <p>
 * Unlike {@link #lookupCommit(AnyObjectId)} this method only returns
 * successfully if the commit object exists, is verified to be a commit, and
 * was parsed without error.
 *
 * @param id
 *            name of the commit object.
 * @return reference to the commit object. Never null.
 * @throws org.eclipse.jgit.errors.MissingObjectException
 *             the supplied commit does not exist.
 * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
 *             the supplied id is not a commit or an annotated tag.
 * @throws java.io.IOException
 *             a pack file or loose object could not be read.
 */
@NonNull
public RevCommit parseCommit(AnyObjectId id)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	RevObject c = peel(parseAny(id));
	if (!(c instanceof RevCommit))
		throw new IncorrectObjectTypeException(id.toObjectId(),
				Constants.TYPE_COMMIT);
	return (RevCommit) c;
}
 
Example 3
Source File: RevWalk.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Locate a reference to an annotated tag and immediately parse its content.
 * <p>
 * Unlike {@link #lookupTag(AnyObjectId)} this method only returns
 * successfully if the tag object exists, is verified to be a tag, and was
 * parsed without error.
 *
 * @param id
 *            name of the tag object.
 * @return reference to the tag object. Never null.
 * @throws org.eclipse.jgit.errors.MissingObjectException
 *             the supplied tag does not exist.
 * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
 *             the supplied id is not a tag or an annotated tag.
 * @throws java.io.IOException
 *             a pack file or loose object could not be read.
 */
@NonNull
public RevTag parseTag(AnyObjectId id) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	RevObject c = parseAny(id);
	if (!(c instanceof RevTag))
		throw new IncorrectObjectTypeException(id.toObjectId(),
				Constants.TYPE_TAG);
	return (RevTag) c;
}