[Feat] Client initialization cache and batch remove#63
Merged
Conversation
Signed-off-by: samzong <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a caching mechanism for the git worktree list and centralizes repository initialization logic within the Client struct to improve performance and consistency. It also adds a RemoveBatch method for efficient multi-worktree removal and updates various operations to utilize the new cached state. Review feedback suggests further performance optimizations, specifically batching the git branch -D command and using internal synchronization methods to avoid redundant cache invalidations and git subprocess calls during worktree creation.
…ectly Signed-off-by: samzong <[email protected]>
samzong
added a commit
that referenced
this pull request
Apr 17, 2026
Fix 7 new lint violations from #63 and #64: - lll: break long lines in worktree.go, worktree_test.go, prune.go, resource.go - perfsprint: use errors.New instead of fmt.Errorf for static strings in prune.go - gocritic/unlambda: simplify exec.Command wrapper in worktree_test.go Signed-off-by: samzong <[email protected]>
samzong
added a commit
that referenced
this pull request
Apr 17, 2026
* fix: resolve lint issues introduced by protection and cache PRs Fix 7 new lint violations from #63 and #64: - lll: break long lines in worktree.go, worktree_test.go, prune.go, resource.go - perfsprint: use errors.New instead of fmt.Errorf for static strings in prune.go - gocritic/unlambda: simplify exec.Command wrapper in worktree_test.go Signed-off-by: samzong <[email protected]> * fix(wt): derive worktree name from -b when no name given - Allow `gmc wt add -b <branch>` without positional args; worktree name defaults to the base branch value. - Split the `-b/--base` flag variable between `wt add` and `wt dup` so dup's "main" default no longer pollutes add at init time. ## Considered and deferred - cmd/worktree.go [BOT-NIT]: wtBaseBranch could be renamed to wtAddBase for symmetry with wtDupBase / wtPruneBase. Deferred — not a behavior concern. - cmd/worktree.go [BOT-SCOPE]: No cmd-level test for the new zero-arg + -b path. Deferred for a follow-up test-only PR. Signed-off-by: samzong <[email protected]> --------- Signed-off-by: samzong <[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.
What's changed?
sync.Once-based lazy init toClientstruct cachingbareRoot,worktreeRoot,searchRoot,repoDir— resolved once per CLI invocationListCached()/InvalidateList()for worktree list caching with explicit invalidation after mutations (Add,Remove,Dup,AddPR,Prune)RemoveBatch()with fail-fast validation, sequential removal, and batchedbranch -DrunWorktreeRemovein cmd layer to useRemoveBatchSync,Prune,Promote,AddPR, etc.) to use cached fields instead of per-call resolutionListCached()to prevent cache corruptionresolveRemoveTargethelper shared byprepareRemoveandRemoveBatchWhy
Clientmethods repeatedly compute values (FindBareRoot,GetWorktreeRoot,List()) that are constant within a single command lifecyclewt rm --all,wt add a b c,wt dup)RemoveBatchvalidates all names upfront (fail-fast for typos) and batches branch deletion at the end