RevWalk: Make createCommit(AnyObjectId, int) protected API This allows sub-types of RevWalk to implement this method and create instances of sub-types of RevCommit that know their position in the Commit Graph. Marked createCommit(AnyObjectId) as @nooverride Existing sub-types of RevWalk within jgit have been updated to override the new method. Sub-types of RevWalk outside of jgit will only receive a warning, that the createCommit(AnyObjectId) method is no longer intended to be overridden and that the new createCommit(AnyObjectId, int) method should be overridden instead. Bug: jgit-250 Change-Id: I0a2115bfef7e73a299780a2c28ef5a01aa1d00e0
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java index 1ff6e98..f72a451 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java
@@ -96,7 +96,7 @@ protected NameRevCommand(Repository repo) { revs = new ArrayList<>(2); walk = new RevWalk(repo) { @Override - public NameRevCommit createCommit(AnyObjectId id) { + protected RevCommit createCommit(AnyObjectId id, int graphPos) { return new NameRevCommit(id); } };
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java index fafc4fb..582313f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java
@@ -36,7 +36,7 @@ public ReverseCommit next() throws MissingObjectException, } @Override - protected RevCommit createCommit(AnyObjectId id) { + protected RevCommit createCommit(AnyObjectId id, int graphPos) { return new ReverseCommit(id); }
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java index c8c454a..99022f0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java
@@ -105,7 +105,7 @@ public void sort(RevSort s, boolean use) { } @Override - protected RevCommit createCommit(AnyObjectId id) { + protected RevCommit createCommit(AnyObjectId id, int graphPos) { return new PlotCommit(id); }
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthWalk.java index 7795ce2..442087d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthWalk.java
@@ -196,7 +196,7 @@ public void markRoot(RevCommit c) throws MissingObjectException, } @Override - protected RevCommit createCommit(AnyObjectId id) { + protected RevCommit createCommit(AnyObjectId id, int graphPos) { return new Commit(id); } @@ -367,7 +367,7 @@ public void markUnshallow(RevObject c) throws MissingObjectException, } @Override - protected RevCommit createCommit(AnyObjectId id) { + protected RevCommit createCommit(AnyObjectId id, int graphPos) { return new Commit(id); }
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java index 8e604ba..4f558bc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
@@ -1764,12 +1764,27 @@ public ObjectWalk toObjectWalkWithSameObjects() { * @param id * the object this walker requires a commit reference for. * @return a new unparsed reference for the object. + * + * @nooverride Since 7.8 This method is not intended to be re-implemented or + * extended by clients. Override + * {@link #createCommit(AnyObjectId, int)} instead. */ protected RevCommit createCommit(AnyObjectId id) { return createCommit(id, commitGraph().findGraphPosition(id)); } - private RevCommit createCommit(AnyObjectId id, int graphPos) { + /** + * Construct a new unparsed commit for the given object. + * + * @param id + * the object this walker requires a commit reference for. + * @param graphPos + * the position of the commit in the commit graph or {@code -1} + * if the commit is not present in the commit graph + * @return a new unparsed reference for the object. + * @since 7.8 + */ + protected RevCommit createCommit(AnyObjectId id, int graphPos) { if (graphPos >= 0) { return new RevCommitCG(id, graphPos); }