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
Copy link
Copy Markdown

@spkrka spkrka commented Jun 8, 2026

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
Copy link
Copy Markdown

gitgitgadget Bot commented Jun 8, 2026

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

  • Commit not signed off

get_reachable_subset() and tips_reachable_from_bases()
answer the same question: which to-commits are reachable from
any of the from-commits.

get_reachable_subset() used a graph traversal with a prio_queue
until it finds all targets.

tips_reachable_from_bases() uses DFS with a rising generation floor,
and should be strictly faster, both due to additional
pruning via generation numbers as well as O(1) DFS operations
instead of O(log(n)) prio_queue operations.

In practice these perform the same, and the main win is
the code deduplication.

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 538378a to e327567 Compare June 8, 2026 08:02
@spkrka
Copy link
Copy Markdown
Author

spkrka commented Jun 8, 2026

/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/```


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