Skip to content

refactor(prune): bundle try_remove's loop-invariant args into RemovalContext - #2811

Merged
max-sixty merged 3 commits into
mainfrom
prune-try-remove-ctx
May 19, 2026
Merged

max-sixty merged 3 commits into
mainfrom
prune-try-remove-ctx

Conversation

@max-sixty

@max-sixty max-sixty commented May 19, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #2808. That PR fixed the Windows .git/config race in wt step prune by adding a prune-local RwLock parameter to try_remove, pushing it to 8 parameters and a #[allow(clippy::too_many_arguments)] — deliberately deferred as an optional standalone cleanup to keep the race fix minimal.

Of try_remove's 8 arguments, only candidate varies; the other 7 are identical at all three call sites in step_prune (two in the rx loop, one for deferred_current). This bundles them into a RemovalContext<'a> struct of borrows, constructed once and passed by reference, following the existing CommandContext / RemovedWorktreeOutputContext / TemplateContext pattern. Each call site collapses from a 9-line argument block to one line, the loop-invariant relationship is now expressed in the type rather than re-asserted by hand three times, and the #[allow] is removed (clippy is clean without it).

The B-prime concurrency semantics are intact: the struct carries &RwLock<()> like the other borrows, and try_remove still acquires the check_lock write guard as the first statement of its body, held over the whole body — load-bearing for the Windows fix.

Pure refactor, no behavior change. Rebased onto main after #2806 (the approval-boundary TOCTOU fix), which renamed try_remove's run_hooks: bool to hook_plan: &ApprovedHookPlan; RemovalContext carries that field unchanged.

Follow-up commit: the struct refactor incidentally pushed handle_remove_output(...) past rustfmt's fn_call_width (the ctx.-prefixed args), splitting it multi-line and moving the trailing )?; onto its own line — which LLVM-cov flags as a codecov/patch miss despite the line executing (line 205 is covered and 205→210 is straight-line). Reading the Copy fields into locals keeps that call byte-identical to its covered form on main, so the diff stays a faithful no-behavior-change refactor.

…Context

try_remove had 8 parameters (1 varying Candidate + 7 loop-invariant),
carrying #[allow(clippy::too_many_arguments)] since #2808. The 7 invariant
args are identical at all three call sites; bundling them into a
RemovalContext<'a> struct of borrows — built once in step_prune — collapses
each call site to one line and drops the #[allow]. Follows the existing
CommandContext / TemplateContext pattern.

check_lock semantics are unchanged: the struct carries &RwLock<()> and
try_remove still acquires the write guard at the top of its body, held over
the whole body (load-bearing for the Windows .git/config race fix in #2808).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes May 19, 2026
@worktrunk-bot
worktrunk-bot dismissed their stale review May 19, 2026 18:53

codecov/patch failed (1 line, 97.05%) — needs maintainer approval per CLAUDE.md

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI noted — flagging two failures for completeness:

codecov/patch (1 missed line, 97.05%) — looks like a benign LLVM-cov artifact, but flagging since CLAUDE.md requires explicit approval before merging with a failing codecov/patch.

The only uncovered diff line is 213, the closing )?; of the multi-line handle_remove_output(...) call. The actual function body executes: line 205 (let mut announcer = HookAnnouncer::new(ctx.repo, ctx.config, true);) is hit, and the original pre-refactor single-line handle_remove_output(&plan, foreground, run_hooks, true, false, &mut announcer)?; was covered. rustfmt split the call across multiple lines when arg count grew (ctx.foreground / ctx.run_hooks widened a few names) and LLVM-cov attributes the trailing paren to a separate region from the call body. No behavioral change vs. the prior covered version.

Dismissing my approval per CLAUDE.md — let me know if you'd like to merge regardless.

affected tests (windows, advisory) — unrelated: config::expansion::tests::{test_expand_template_args_sequence, test_expand_template_args_shell_metachar_safety}. Same failures reproduce on main at e5240b0 (run 26115299320). Pre-existing main-branch flake, not this PR.

The context-struct refactor incidentally reformatted handle_remove_output
into a multi-line call: the `ctx.`-prefixed bool args pushed it past
rustfmt's fn_call_width, and the split moved the trailing `)?;` onto its
own line. LLVM-cov then attributes that line's `?` error-propagation
sub-region (never taken in tests) separately, so codecov/patch flags it as
missed — even though line 205 is covered and 205→213 is straight-line, so
the call demonstrably executes. On main the same code was a single covered
line.

Read the two Copy flags into locals so the call stays on one line,
byte-identical to its pre-refactor form. Minimizes the refactor's blast
radius (an unrelated call shouldn't change formatting) and clears the
spurious codecov/patch miss without a coverage exception.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 6322007 into main May 19, 2026
32 of 33 checks passed
@max-sixty
max-sixty deleted the prune-try-remove-ctx branch May 19, 2026 19:43
@worktrunk-bot worktrunk-bot mentioned this pull request May 19, 2026
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