Skip to content

commit-reach: remove get_reachable_subset()#2141

Open
spkrka wants to merge 1 commit into
gitgitgadget:masterfrom
spkrka:krka/remove-get-reachable-subset
Open

commit-reach: remove get_reachable_subset()#2141
spkrka wants to merge 1 commit into
gitgitgadget:masterfrom
spkrka:krka/remove-get-reachable-subset

Conversation

@spkrka

@spkrka spkrka commented Jun 8, 2026

Copy link
Copy Markdown

commit-reach: remove get_reachable_subset()

I have investigated what core graph algorithms exist and how
they are implemented and found that there is some overlap.

get_reachable_subset() and tips_reachable_from_bases() answer
the same question: which commits in a target set are reachable
from a set of base commits.

This patch converts the two callers of get_reachable_subset()
to use tips_reachable_from_bases() and deletes the now-unused
function.

tips_reachable_from_bases() has a minor algorithmic edge: it sorts
targets by generation and dynamically raises the pruning floor as
targets are found. In practice this makes no measurable difference
where the target set is typically small. Without a commit-graph, both
degrade identically -- all generation numbers are INFINITY, so
neither can prune. The main value is removing ~70 lines of code.

A few design choices I'd appreciate feedback on:

  • add_missing_tags() converts its sent_tips array to a
    commit_list to match the tips_reachable_from_bases() API.
    This is O(n) list-node allocations, negligible compared to
    the graph walk. An array overload could avoid this, but
    didn't seem worth adding for a single call site.

  • The flag changes from 1 (bit 0) to TMP_MARK (bit 4) because
    tips_reachable_from_bases() uses SEEN (bit 0) internally.
    TMP_MARK is already used for deduplication earlier in the
    same function and is cleared before the reachability block.

  • I kept this as a single commit since the change is small.
    Happy to split into convert-callers + delete-function if
    that's preferred.

  • The test helper and test names are renamed from
    get_reachable_subset to tips_reachable_from_bases to match
    the function being exercised. test_all_modes already covers
    both with and without commit-graph.

@gitgitgadget

gitgitgadget Bot commented Jun 8, 2026

Copy link
Copy Markdown

There is an issue in commit 538378a:
commit-reach: remove get_reachable_subset()

  • Commit not signed off

@spkrka spkrka force-pushed the krka/remove-get-reachable-subset branch from 538378a to e327567 Compare June 8, 2026 08:02
@spkrka

spkrka commented Jun 8, 2026

Copy link
Copy Markdown
Author

/cc @derrickstolee

@spkrka spkrka marked this pull request as ready for review June 8, 2026 08:21
@Rube2024actual

Copy link
Copy Markdown

There is an issue in commit 538378a:
commit-reach: remove get_reachable_subset()

  • Commit not signed off

https://gitgitgadget.github.io/```


get_reachable_subset() and tips_reachable_from_bases() answer the
same question: given a set of bases and a set of tips, which tips
are reachable from at least one base?

get_reachable_subset() was introduced in fcb2c07 (2018-11-02)
for add_missing_tags() in remote.c. tips_reachable_from_bases()
was added in cbfe360 (2023-03-20) as part of the ahead-behind
series. The two were never consolidated.

With a commit-graph, tips_reachable_from_bases() has the edge: its
DFS raises the generation floor as lower targets are found, pruning
more aggressively than the static floor in get_reachable_subset().
Without generation numbers, some edge cases may be slower with DFS
instead of BFS since the date-ordered prio_queue naturally stays
near the top of the graph, but this should not matter in practice
-- worst case both visit the full graph down from the bases.

Remove get_reachable_subset() and convert its only caller
(add_missing_tags in remote.c) to use tips_reachable_from_bases()
directly.

The flag in remote.c changes from 1 (bit 0) to TMP_MARK (bit 4)
because tips_reachable_from_bases() uses SEEN (bit 0) internally.
TMP_MARK is already used for deduplication earlier in the same
function and is cleared before the reachability check.

Signed-off-by: Kristofer Karlsson <krka@spotify.com>
@spkrka spkrka force-pushed the krka/remove-get-reachable-subset branch from e327567 to cc940c7 Compare June 9, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants