Browse Source

Add parseCommit(AnyObjectId) method to Repository.

It is quite common to want to parse a commit without already having a
RevWalk.  Provide a shortcut to do so to make it more convenient, and to
ensure that the RevWalk is released afterwards.

Signed-off-by: Martin Fick<mfick@codeaurora.org>
Change-Id: I9528e80063122ac318f115900422a24ae49a920e
stable-4.8
Martin Fick 8 years ago committed by David Pursehouse
parent
commit
f9b69677f6
  1. 27
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

27
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

@ -1148,6 +1148,33 @@ public abstract class Repository implements AutoCloseable {
return indexFile; return indexFile;
} }
/**
* Locate a reference to a commit and immediately parse its content.
* <p>
* 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 MissingObjectException
* the supplied commit does not exist.
* @throws IncorrectObjectTypeException
* the supplied id is not a commit or an annotated tag.
* @throws IOException
* a pack file or loose object could not be read.
* @since 4.8
*/
public RevCommit parseCommit(AnyObjectId id) throws IncorrectObjectTypeException,
IOException, MissingObjectException {
if (id instanceof RevCommit && ((RevCommit) id).getRawBuffer() != null) {
return (RevCommit) id;
}
try (RevWalk walk = new RevWalk(this)) {
return walk.parseCommit(id);
}
}
/** /**
* Create a new in-core index representation and read an index from disk. * Create a new in-core index representation and read an index from disk.
* <p> * <p>

Loading…
Cancel
Save