Skip to content

perf(switch): strip remote prefix via inventory instead of two subprocesses - #2372

Merged
max-sixty merged 1 commit into
mainfrom
strip-remote-prefix-inventory
Apr 22, 2026
Merged

max-sixty merged 1 commit into
mainfrom
strip-remote-prefix-inventory

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Repository::strip_remote_prefix ran git rev-parse --verify refs/remotes/<ref> followed by git remote every call — two subprocesses to satisfy wt switch origin/<branch> in the picker path. The remote-branch inventory from #2368 already splits each ref into short_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 return None. The one subtle change is that origin/HEAD now returns None instead of Some("HEAD") — parse_remote_branch_line drops the symref. The switch call site would have mishandled "HEAD" as a branch name anyway, so this is a correctness improvement.

…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]>
@max-sixty
max-sixty merged commit 6fac76c into main Apr 22, 2026
25 checks passed
@max-sixty
max-sixty deleted the strip-remote-prefix-inventory branch April 22, 2026 02:00
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]>
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