summaryrefslogtreecommitdiff
path: root/tests/revwalk/basic.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-04-12 13:32:27 +0100
committerPatrick Steinhardt <ps@pks.im>2018-04-12 13:45:53 +0100
commit54fd80e3f8d7850576c60fa8baf7269df3c9e6a3 (patch)
tree069a77dcc81a2568e5c06b227a46c0c08f08c1d4 /tests/revwalk/basic.c
parent0eca42304a10c9ad6170a38a440dfab8e354d38d (diff)
downloadlibgit2-54fd80e3f8d7850576c60fa8baf7269df3c9e6a3.tar.gz
revwalk: fix uninteresting revs sometimes not limiting graphwalk
When we want to limit our graphwalk, we use the heuristic of checking whether the newest limiting (uninteresting) revision is newer than the oldest interesting revision. We do so by inspecting whether the first item's commit time of the user-supplied list of revisions is newer than the last added interesting revision. This is wrong though, as the user supplied list is in no way guaranteed to be sorted by increasing commit dates. This could lead us to abort the revwalk early before applying all relevant limiting revisions, outputting revisions which should in fact have been hidden. Fix the heuristic by instead checking whether _any_ of the limiting commits was made earlier than the last interesting commit. Add a test.
Diffstat (limited to 'tests/revwalk/basic.c')
-rw-r--r--tests/revwalk/basic.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/revwalk/basic.c b/tests/revwalk/basic.c
index 6a23701f3..1106bf4ce 100644
--- a/tests/revwalk/basic.c
+++ b/tests/revwalk/basic.c
@@ -555,3 +555,30 @@ void test_revwalk_basic__old_hidden_commit_two(void)
cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid, _walk));
}
+
+/*
+ * Ensure that we correctly hide all parent commits of a newer
+ * commit when first hiding older commits.
+ *
+ * % git rev-list D ^B ^A ^E
+ * 790ba0facf6fd103699a5c40cd19dad277ff49cd
+ * b82cee5004151ae0c4f82b69fb71b87477664b6f
+ */
+void test_revwalk_basic__newer_hidden_commit_hides_old_commits(void)
+{
+ git_oid oid;
+
+ revwalk_basic_setup_walk("revwalk.git");
+
+ cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/D"));
+ cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/B"));
+ cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/A"));
+ cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/E"));
+
+ cl_git_pass(git_revwalk_next(&oid, _walk));
+ cl_assert(git_oid_streq(&oid, "b82cee5004151ae0c4f82b69fb71b87477664b6f"));
+ cl_git_pass(git_revwalk_next(&oid, _walk));
+ cl_assert(git_oid_streq(&oid, "790ba0facf6fd103699a5c40cd19dad277ff49cd"));
+
+ cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid, _walk));
+}