]> git.ipfire.org Git - thirdparty/git.git/commit
commit-reach: introduce struct paint_state with per-side counters
authorKristofer Karlsson <krka@spotify.com>
Sat, 11 Jul 2026 13:27:42 +0000 (13:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 11 Jul 2026 21:00:11 +0000 (14:00 -0700)
commit351dfe5aa75807a4a9ae7880fd39144a24bcb172
treed440d0287b655629d660c4aa0d612a2c643c9eb5
parentb9bc40f1414642d8245a71c80e8396835c88b60c
commit-reach: introduce struct paint_state with per-side counters

Add a paint_state struct for use by paint_down_to_common() that
wraps a prio_queue with per-side commit counters. Each non-stale
queued commit occupies exactly one counter bucket based on its
paint flags: PARENT1-only, PARENT2-only, or both sides (a pending
merge-base candidate).

The counters are maintained by paint_count_update() which adjusts
the appropriate bucket by a signed delta. An exhaustive switch on
the paint+stale bits documents all valid flag combinations in one
place.

Convert paint_down_to_common() to use paint_state. The loop now
drains the queue via paint_queue_get() which returns NULL when all
counters reach zero, replacing the old pointer-based termination
(max_nonstale). This is equivalent behavior -- both conditions
detect that no non-stale entries remain.

paint_queue_get() uses a "pop first" form: it dequeues a commit,
then checks the counters. This means the loop exits one iteration
earlier than the old code in some topologies (the popped stale
commit is never processed), so a few step counts drop by one.

The existing nonstale_queue is left in place for ahead_behind(),
though nonstale_queue_put_dedup() and nonstale_queue_get_dedup()
became unused and are removed.

Signed-off-by: Kristofer Karlsson <krka@spotify.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/technical/paint-down-to-common.adoc
commit-reach.c
t/t6600-test-reach.sh