Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
perf(switch): strip remote prefix via inventory instead of two subprocesses (#2372)
Maximilian Roos6fac76c8ec77
diff --git a/src/git/repository/remotes.rs b/src/git/repository/remotes.rsindex 47e3b2844..782c9db90 100644--- a/src/git/repository/remotes.rs+++ b/src/git/repository/remotes.rs@@ -332,27 +332,12 @@ impl Repository {/// if it's a valid remote-tracking ref. Returns `None` if the name isn't a remote ref/// or the remote can't be identified.///- /// This handles remote names that don't contain `/` (the common case). It lists- /// all configured remotes and finds the one that matches the prefix.- ///- /// TODO: A cleaner approach would be to strip the prefix upstream — either have- /// `list_remote_branches()` return `(remote, local_branch, sha)` tuples, or track- /// `is_remote` on `ListItem` so the picker outputs just the local branch name.- /// Either would eliminate this runtime `git remote` call. See #1260.+ /// Resolved from the remote-branch inventory — no subprocess calls once it's populated.pub fn strip_remote_prefix(&self, ref_name: &str) -> Option<String> {- // Quick check: is this actually a remote-tracking ref?- if !self.is_remote_tracking_branch(ref_name) {- return None;- }-- // List all remotes and find the one that is a prefix of ref_name- let output = self.run_command(&["remote"]).ok()?;- output.lines().find_map(|remote| {- let prefix = format!("{}/", remote.trim());- ref_name- .strip_prefix(&prefix)- .filter(|branch| !branch.is_empty())- .map(|branch| branch.to_string())- })+ self.remote_branches()+ .ok()?+ .iter()+ .find(|r| r.short_name == ref_name)+ .map(|r| r.local_name.clone())}}