Skip to content

Commit ba3f2bb

Browse files
committed
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>
1 parent c10ff61 commit ba3f2bb

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
@@ -108,11 +108,14 @@ static int paint_down_to_common(struct repository *r,
108108
{ compare_commits_by_gen_then_commit_date }
109109
};
110110
int i;
111+
int gen_ordered = 1;
111112
timestamp_t last_gen = GENERATION_NUMBER_INFINITY;
112113
struct commit_list **tail = result;
113114

114-
if (!min_generation && !corrected_commit_dates_enabled(r))
115+
if (!min_generation && !corrected_commit_dates_enabled(r)) {
115116
queue.pq.compare = compare_commits_by_commit_date;
117+
gen_ordered = 0;
118+
}
116119

117120
one->object.flags |= PARENT1;
118121
if (!n) {
@@ -147,11 +150,12 @@ static int paint_down_to_common(struct repository *r,
147150
commit->object.flags |= RESULT;
148151
tail = commit_list_append(commit, tail);
149152
/*
150-
* The queue is generation-ordered; no
151-
* remaining common ancestor can be a
153+
* When the queue is generation-ordered,
154+
* no remaining common ancestor can be a
152155
* descendant of this one.
153156
*/
154157
if (!(mb_flags & MERGE_BASE_FIND_ALL) &&
158+
gen_ordered &&
155159
generation < GENERATION_NUMBER_INFINITY)
156160
break;
157161
}

t/t6600-test-reach.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ test_expect_success 'merge-base without --all is one of --all results' '
10031003
grep -F -f single all
10041004
'
10051005

1006-
test_expect_failure 'merge-base without --all, clock skew, v1 commit-graph' '
1006+
test_expect_success 'merge-base without --all, clock skew, v1 commit-graph' '
10071007
git rev-parse skew-M2 >expect &&
10081008
merge_base_all_modes skew-P1 skew-P2
10091009
'

0 commit comments

Comments
 (0)