Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Documentation/technical/paint-down-to-common.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ dequeues a commit below this threshold.

Single result
~~~~~~~~~~~~~
When only one merge base is needed and the walk is in the
ordered region with generation ordering, the first candidate
found is necessarily the highest-generation common ancestor.
No remaining commit in the queue can be a descendant of this
candidate (generation ordering guarantees children are visited
first), so it cannot be redundant and the walk can stop
immediately.
When only one merge base is needed, the walk stops once it has found
a candidate and the next commit to visit is in the ordered region,
wherever the candidate was found.

No remaining commit can then be a descendant of a candidate: no
commit in the ordered region can descend from one outside it (as
generation numbers never increase along parent links), and
descendants of a candidate inside it were visited first. Candidates
may still be redundant with each other; `remove_redundant()` handles
that.

Related documentation
---------------------
Expand Down
16 changes: 10 additions & 6 deletions commit-reach.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct paint_state {
timestamp_t min_generation;
timestamp_t last_gen;
timestamp_t topo_ceiling;
bool stop_below_ceiling;
};

static void paint_count_update(struct paint_state *state,
Expand Down Expand Up @@ -159,6 +160,9 @@ static struct commit *paint_queue_get(struct paint_state *state)
if (generation < state->min_generation)
return NULL;

if (state->stop_below_ceiling && generation < state->topo_ceiling)
return NULL;

/*
* Check exit condition before decrementing: the counters
* still include this commit, so the last non-stale commit
Expand Down Expand Up @@ -232,13 +236,13 @@ static int paint_down_to_common(struct repository *r,
commit->object.flags |= RESULT;
tail = commit_list_append(commit, tail);
/*
* When the queue is generation-ordered,
* no remaining common ancestor can be a
* descendant of this one.
* Only one merge base is wanted, and once the
* walk is below the topo ceiling no remaining
* commit can be a descendant of a candidate, so
* it is safe to stop there.
*/
if (!(mb_flags & MERGE_BASE_FIND_ALL) &&
state.last_gen < state.topo_ceiling)
break;
if (!(mb_flags & MERGE_BASE_FIND_ALL))
state.stop_below_ceiling = true;
}
/* Mark parents of a found merge stale */
flags |= STALE;
Expand Down
17 changes: 17 additions & 0 deletions t/t6600-test-reach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,23 @@ test_expect_success 'merge-base --all commit-walk steps' '
test_paint_down_steps 81 9 57 37
'

test_expect_success 'merge-base without --all, result found outside commit-graph' '
# sr-MB and the tips are created after the commit-graph files
# were saved, so they are outside every graph, while their grid
# parents are inside the full and no-gdat graphs. Once the walk
# has found sr-MB and enters the graph, it can stop instead of
# walking the grid down to commit-1-1.
mb=$(git commit-tree -m sr-MB -p commit-1-1 "$skew_tree") &&
tip1=$(git commit-tree -m sr-TIP1 \
-p "$mb" -p commit-9-1 "$skew_tree") &&
tip2=$(git commit-tree -m sr-TIP2 \
-p "$mb" -p commit-1-9 "$skew_tree") &&
>input &&
echo "$mb" >expect &&
run_all_modes git merge-base "$tip1" "$tip2" &&
test_paint_down_steps 21 3 11 3
'

test_expect_success 'merge-base --all with clock skew (side-exhaustion)' '
# Verify that the merge base is computed correctly even
# when commits have non-monotonic commit dates.
Expand Down
Loading