Repository navigation
refactor(repo): return &[WorktreeInfo] from list_worktrees - #2383
Merged
Merged
Conversation
Mirrors the canonical shape of `local_branches`/`remote_branches` (`get_or_try_init(...).map(Vec::as_slice)`) and drops the per-call clone the cache introduced in #2375 deferred. Callers that need ownership use `.iter().cloned()` / `.to_vec()`; callers that only iterate or index work against the slice unchanged. Side cleanups falling out of the migration: - `prepare_worktree_removal` collapses its `owned_worktrees` local into a single match binding. - `collect::collect` drops the `OnceCell<Result<Vec<_>>>` carrier in the rayon scope — the scope just warms `repo.list_worktrees()` now that the result is cached on `RepoCache` itself. - Deletes unused `Repository::current_worktree_info()` (zero callers). 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
…-each (#2389) Two small follow-ups to #2383. `sort_worktrees_with_cache` takes `&[WorktreeInfo]` instead of an owned `Vec<WorktreeInfo>`, cloning once when materializing the sorted output. The call site in `collect::collect` drops its `.to_vec()` — one fewer `Vec<WorktreeInfo>` allocation on the `wt list` hot path. `step_for_each` holds `Vec<&WorktreeInfo>` rather than cloning each entry into a `Vec<WorktreeInfo>` — the loop only borrows (`worktree_display_name(wt, ...)`, `execute_shell_command(&wt.path, ...)`), so the clone was unnecessary. No behavior change. > _This was written by Claude Code on behalf of @max-sixty_ 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.
Follows #2375. That PR cached
list_worktreesonRepoCachebut kept theVec<WorktreeInfo>return type (cloning from the cache on each call) to minimize churn — explicitly deferring this signature change. The sibling inventorieslocal_branchesandremote_branchesalready return&[T]; this bringslist_worktreesin line and eliminates the per-call clones.The implementation mirrors
remote_branchesinsrc/git/repository/branches.rs:get_or_try_init(...).map(Vec::as_slice).Call-site migration is mostly mechanical — slice ops (
.iter(),[0],.is_empty(),.len()) work unchanged. Callers that need ownership switch from.into_iter()to.iter().cloned(); one call tosort_worktrees_with_cacheuses.to_vec(). Inlist/collect, the oldOnceCell<Result<Vec<_>>>carrier inside the rayon scope is gone — the scope just warmsrepo.list_worktrees(), which already caches onRepoCache, and the value is re-read after the scope. Inrepository_ext::prepare_worktree_removal, theowned_worktreesscoped-local dance collapses to a single match binding. Also deletes unusedRepository::current_worktree_info()(zero callers, noticed while reviewing the diff).Subprocess count for
wt switchis unchanged — still 1git worktree listcall per command, confirmed viaWORKTRUNK_PICKER_DRY_RUN=1 RUST_LOG=worktrunk=debug wt switch.