Commit 07011e60 by Patrick Steinhardt

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.
parent 0f88adb6
...@@ -375,20 +375,6 @@ static int add_parents_to_list(git_revwalk *walk, git_commit_list_node *commit, ...@@ -375,20 +375,6 @@ static int add_parents_to_list(git_revwalk *walk, git_commit_list_node *commit,
return 0; return 0;
} }
static int everybody_uninteresting(git_commit_list *orig)
{
git_commit_list *list = orig;
while (list) {
git_commit_list_node *commit = list->item;
list = list->next;
if (!commit->uninteresting)
return 0;
}
return 1;
}
/* How many unintersting commits we want to look at after we run out of interesting ones */ /* How many unintersting commits we want to look at after we run out of interesting ones */
#define SLOP 5 #define SLOP 5
...@@ -398,16 +384,15 @@ static int still_interesting(git_commit_list *list, int64_t time, int slop) ...@@ -398,16 +384,15 @@ static int still_interesting(git_commit_list *list, int64_t time, int slop)
if (!list) if (!list)
return 0; return 0;
/* for (; list; list = list->next) {
* If the destination list has commits with an earlier date /*
* than our source we want to continue looking. * If the destination list has commits with an earlier date than
*/ * our source or if it still contains interesting commits we
if (time <= list->item->time) * want to continue looking.
return SLOP; */
if (!list->item->uninteresting || list->item->time > time)
/* If we find interesting commits, we reset the slop count */ return SLOP;
if (!everybody_uninteresting(list)) }
return SLOP;
/* Everything's uninteresting, reduce the count */ /* Everything's uninteresting, reduce the count */
return slop - 1; return slop - 1;
......
[core]
bare = true
repositoryformatversion = 0
filemode = false
symlinks = false
ignorecase = true
Unnamed repository; edit this file 'description' to name the repository.
P pack-9adacb9971981a1a3264fd473da5b800f2715959.pack
# pack-refs with: peeled fully-peeled sorted
3ae0f53011bdb7e68f99bde4943449f36c1c318a refs/heads/A
061978578d7c9ff2ba92dd36d31fd8d809871030 refs/heads/B
743398b425d6c216d6cfaae3786b5bc436393ae5 refs/heads/C
790ba0facf6fd103699a5c40cd19dad277ff49cd refs/heads/D
d3d783066cf7d95def6844b9c5118c1e7bcce7df refs/heads/E
d3d783066cf7d95def6844b9c5118c1e7bcce7df refs/heads/master
...@@ -555,3 +555,30 @@ void test_revwalk_basic__old_hidden_commit_two(void) ...@@ -555,3 +555,30 @@ void test_revwalk_basic__old_hidden_commit_two(void)
cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid, _walk)); 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));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment