Repository navigation
perf(switch): strip remote prefix via inventory instead of two subprocesses - #2372
Merged
Merged
Conversation
…cesses `Repository::strip_remote_prefix` spawned `git rev-parse --verify` plus `git remote` on every call. The remote-branch inventory from #2368 already carries `short_name`/`remote_name`/`local_name` split per ref, so look up the entry directly and return `local_name`. The adjacent TODO that was waiting on this shape is satisfied. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
Apr 22, 2026
max-sixty
added a commit
that referenced
this pull request
Apr 22, 2026
…2377) Drops the `git rev-parse --verify refs/remotes/<ref>` subprocess in favor of a lookup against the `Repository::remote_branches()` inventory already populated by a single `for-each-ref` scan per Repository lifetime. Mirrors the cutover #2372 did for `strip_remote_prefix`. Sole caller is `wt switch --create feature <base>`'s safety check that decides whether to unset the auto-assigned upstream on the new branch (so `git push` doesn't push to `main`). Minor behavioural divergence: `<remote>/HEAD` symrefs now return `false` because the inventory excludes them. The call site receives user-supplied base branches (e.g. `origin/main`), not `origin/HEAD`, so this is benign in practice. > _This was written by Claude Code on behalf of Maximilian_ Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repository::strip_remote_prefixrangit rev-parse --verify refs/remotes/<ref>followed bygit remoteevery call — two subprocesses to satisfywt switch origin/<branch>in the picker path. The remote-branch inventory from #2368 already splits each ref intoshort_name/remote_name/local_name, so the lookup collapses to a direct search in the cached slice. The adjacent TODO that was explicitly waiting on this inventory shape is satisfied and removed.Behavioral equivalence holds on every realistic input: local branch names and SHAs still return
None(not in the inventory), and non-existent refs under an existing remote prefix still returnNone. The one subtle change is thatorigin/HEADnow returnsNoneinstead ofSome("HEAD")—parse_remote_branch_linedrops the symref. The switch call site would have mishandled"HEAD"as a branch name anyway, so this is a correctness improvement.