diff options
author | Martin Fick <mfick@codeaurora.org> | 2017-03-31 11:31:47 -0600 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2017-04-19 09:42:47 +0200 |
commit | f9b69677f643a694ec403666a30de2f3d146dd73 (patch) | |
tree | c987659bcb5e3698d111552a8ed7eb3804f539a6 | |
parent | b6fc8e2f3cb1af6f7cbc624acfac01bec002baf8 (diff) | |
download | jgit-f9b69677f643a694ec403666a30de2f3d146dd73.tar.gz jgit-f9b69677f643a694ec403666a30de2f3d146dd73.zip |
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
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index ea37e79381..1f2ab9df87 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -1149,6 +1149,33 @@ public abstract class Repository implements AutoCloseable { } /** + * 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. * <p> * The new index will be read before it is returned to the caller. Read |