Skip to content

Commit ae68032

Browse files
spkrkagitster
authored andcommitted
commit-reach: guard !FIND_ALL early exit with generation ordering check
When paint_down_to_common() falls back to commit-date ordering (for v1 commit graphs without corrected commit dates), the !FIND_ALL early exit incorrectly fires. The exit assumes the queue is generation- ordered, so the first RESULT commit found must be the shallowest. With date ordering this is not guaranteed: a closer merge base with a lower committer date (clock skew) may still be in the queue behind deeper commits. Add a gen_ordered flag that is cleared when the date fallback fires, and require it for the early exit. Update the test from the previous commit to test_expect_success. Signed-off-by: Kristofer Karlsson <krka@spotify.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 18cf52c commit ae68032

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

commit-reach.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ static int paint_down_to_common(struct repository *r,
5959
{
6060
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
6161
int i;
62+
int gen_ordered = 1;
6263
timestamp_t last_gen = GENERATION_NUMBER_INFINITY;
6364
struct commit_list **tail = result;
6465

65-
if (!min_generation && !corrected_commit_dates_enabled(r))
66+
if (!min_generation && !corrected_commit_dates_enabled(r)) {
6667
queue.compare = compare_commits_by_commit_date;
68+
gen_ordered = 0;
69+
}
6770

6871
one->object.flags |= PARENT1;
6972
if (!n) {
@@ -98,11 +101,12 @@ static int paint_down_to_common(struct repository *r,
98101
commit->object.flags |= RESULT;
99102
tail = commit_list_append(commit, tail);
100103
/*
101-
* The queue is generation-ordered; no
102-
* remaining common ancestor can be a
104+
* When the queue is generation-ordered,
105+
* no remaining common ancestor can be a
103106
* descendant of this one.
104107
*/
105108
if (!(mb_flags & MERGE_BASE_FIND_ALL) &&
109+
gen_ordered &&
106110
generation < GENERATION_NUMBER_INFINITY)
107111
break;
108112
}

t/t6600-test-reach.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ test_expect_success 'merge-base without --all is one of --all results' '
958958
grep -F -f single all
959959
'
960960

961-
test_expect_failure 'merge-base without --all, clock skew, v1 commit-graph' '
961+
test_expect_success 'merge-base without --all, clock skew, v1 commit-graph' '
962962
git rev-parse skew-M2 >expect &&
963963
merge_base_all_modes skew-P1 skew-P2
964964
'

0 commit comments

Comments
 (0)