From a80df5380f6f94a8fccaaecac673e3ec9c29bb89 Mon Sep 17 00:00:00 2001 From: Alex Spradlin Date: Tue, 13 Aug 2019 15:20:07 -0700 Subject: RevWalk: Traverse all parents of UNINTERESTING commits When firstParent is set, RevWalk traverses only the first parent of a commit, even though that commit is UNINTERESTING. Since we want the maximal UNINTERESTING set, we shouldn't prune any parents here. This issue is apparent only when some of the commits being traversed are unparsed, since walker.carryFlagsImpl() propagates the UNINTERESTING flag to all parsed ancestors, masking the issue. Therefore teach RevWalk to traverse all parents when a commit is UNINTERESTING and not only the first parent. Since this issue is masked by commit parsing, also test situations when the commits involved are unparsed. Signed-off-by: Alex Spradlin Change-Id: I95e2ad9ae8f1f50fbecae674367ee7e0855519b1 --- .../src/org/eclipse/jgit/junit/TestRepository.java | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'org.eclipse.jgit.junit') diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index e89cf0fb83..362007a982 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -360,6 +360,21 @@ public class TestRepository implements AutoCloseable { return null; // never reached. } + /** + * Create a new, unparsed commit. + *

+ * See {@link #unparsedCommit(int, RevTree, ObjectId...)}. The tree is the + * empty tree (no files or subdirectories). + * + * @param parents + * zero or more IDs of the commit's parents. + * @return the ID of the new commit. + * @throws Exception + */ + public ObjectId unparsedCommit(ObjectId... parents) throws Exception { + return unparsedCommit(1, tree(), parents); + } + /** * Create a new commit. *

@@ -428,6 +443,28 @@ public class TestRepository implements AutoCloseable { */ public RevCommit commit(final int secDelta, final RevTree tree, final RevCommit... parents) throws Exception { + ObjectId id = unparsedCommit(secDelta, tree, parents); + return pool.parseCommit(id); + } + + /** + * Create a new, unparsed commit. + *

+ * The author and committer identities are stored using the current + * timestamp, after being incremented by {@code secDelta}. The message body + * is empty. + * + * @param secDelta + * number of seconds to advance {@link #tick(int)} by. + * @param tree + * the root tree for the commit. + * @param parents + * zero or more IDs of the commit's parents. + * @return the ID of the new commit. + * @throws Exception + */ + public ObjectId unparsedCommit(final int secDelta, final RevTree tree, + final ObjectId... parents) throws Exception { tick(secDelta); final org.eclipse.jgit.lib.CommitBuilder c; @@ -443,7 +480,7 @@ public class TestRepository implements AutoCloseable { id = ins.insert(c); ins.flush(); } - return pool.parseCommit(id); + return id; } /** -- cgit v1.2.3