Repository navigation
refactor(git): close remaining cache-staleness vectors after RefSnapshot cutover - #2530
Merged
Merged
Conversation
…hot cutover Two follow-ups deferred from #2528, plus reviewer cleanups. ## 1. Thread `RefSnapshot` through `prepare_worktree_removal` `prepare_worktree_removal` gains `snapshot: Option<&RefSnapshot>`; callers that loop over candidates capture once and pass through: - `step_prune` already captured a snapshot at command entry — now also passes it into `try_remove`, so the inline `prepare_worktree_removal` call reuses it instead of re-running `for-each-ref` per candidate. N+1 captures → 1. - `validate_remove_targets` (multi-target `wt remove`) now captures once at the top of the validation loop. - Single-removal sites (`wt remove`, picker) pass `None` and capture internally — same shape as the existing `worktrees: Option<&[…]>` optional-prefetch parameter. ## 2. Drop the `head_shas` cache The per-worktree `DashMap<PathBuf, Option<String>>` populated by `WorkingTree::prewarm_info` had no invalidation. Anything that moved HEAD mid-command (`wt merge`'s rebase, hook-emitted commits, `wt step commit`) left a stale cache that surfaced in `{{ commit }}` template variables for hooks running after the move. - Field removed from `RepoCache`. - `prewarm_info`'s rev-parse batch drops the bare `HEAD` selector (5 selectors → 4); kept `--symbolic-full-name HEAD` for branch. - `WorkingTreeGitInfo.head_sha` gone (no production consumers; tests updated). - `WorkingTree::head_sha` always reads fresh `git rev-parse HEAD`. Cost is ~5 ms on the few paths that need it; staleness vector is gone. - New test `head_sha_tracks_head_movement` commits between two `head_sha()` calls and asserts the SHA changed — guards against re-introducing a cache. ## 3. Reviewer cleanups - Stale comments at four sites (`command_executor.rs`, `config.rs`, `picker/mod.rs`, `eval.rs`) referenced the deleted HEAD-SHA cache; rewritten to describe current behavior. - `command_executor.rs` `{{ commit }}` resolution: collapsed the branch-matches-running-worktree short-circuit. The arm existed only to reuse the deleted cache; with both arms equally fresh, a single `rev-parse <branch>` covers the branched case. - `step_prune` no longer deep-clones the snapshot for the rayon worker. `Arc::new(snapshot)` + `Arc::clone(&snapshot_arc)` shares by refcount; `try_remove` takes `&RefSnapshot` and auto-derefs from the `Arc`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
One doc nit on the eval test, otherwise the change looks clean. The snapshot threading reuses ref state across prepare_worktree_removal calls correctly: validate_remove_targets only reads, and in step_prune the compute_integration_reason calls inside prepare_worktree_removal are informational (the actual delete decision was already taken by the upstream parallel integration_reason pass).
The on-branch path in `build_hook_context` resolves `{{ commit }}` via
`git rev-parse <branch>`, not `WorkingTree::head_sha`. Both are fresh
reads, but the test description should match the actual code path.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Owner
Author
|
Applied — d399ef9 → 3c0b424. Doc-only fix; the on-branch path goes through |
worktrunk-bot
approved these changes
May 2, 2026
7 tasks done
Merged
max-sixty
added a commit
that referenced
this pull request
May 3, 2026
Cuts v0.47.0. Highlights: - **Integration detection fix** across `wt list`, `wt remove`, `wt merge`, `wt step prune` for the local/upstream-diverged case (#2507, #2513, #2515). - **Faster shell-command dispatch** (~10ms per invocation, 1.49× on trivial aliases) via event-driven signal forwarding (#2537, #2538), plus parallel config load (#2543) and merged cold-start prewarm rev-parse (#2541). - **`wt switch <number>` suggests `pr:N` / `mr:N`** instead of just `--create` (#2516). - **Library API breaking changes**: `RefSnapshot` cutover (#2528, #2530) and the `for-each` direct-exec change (#2465). Full list in `CHANGELOG.md`. See `CHANGELOG.md` for the complete entry. > _This was written by Claude Code on behalf of @max-sixty_ --------- Co-authored-by: Claude <noreply@anthropic.com>
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.
Summary
Two follow-ups deferred from #2528 (the
RefSnapshotcutover that closed the ambient ref-keyed cache staleness class), plus reviewer cleanups.RefSnapshotthroughprepare_worktree_removal— addssnapshot: Option<&RefSnapshot>;step_pruneandvalidate_remove_targetscapture once and reuse across candidates instead of re-runningfor-each-refper candidate (N+1 → 1).head_shascache — the per-worktree HEAD SHA cache had no invalidation. Any flow that moved HEAD mid-command (rebase, hook-emitted commits) left a stale value that surfaced in{{ commit }}template variables for later hooks.WorkingTree::head_shanow always reads fresh; newhead_sha_tracks_head_movementtest guards against re-introducing a cache.command_executor.rs::build_hook_context, and replacedArc::new(snapshot.clone())instep_prune's rayon worker withArc::clone(shares by refcount, no deep copy).Test plan
cargo run -- hook pre-merge --yes— full test + lint suite (3425 tests pass; clippy / doc / doctest with-Dwarningsclean)head_sha_tracks_head_movementexercises the freshness contract directly🤖 Generated with Claude Code