Repository navigation
refactor(prune): bundle try_remove's loop-invariant args into RemovalContext - #2811
Conversation
…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]>
codecov/patch failed (1 line, 97.05%) — needs maintainer approval per CLAUDE.md
worktrunk-bot
left a comment
There was a problem hiding this comment.
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]>
# Conflicts: # src/commands/step/prune.rs
Follow-up to #2808. That PR fixed the Windows
.git/configrace inwt step pruneby adding a prune-localRwLockparameter totry_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, onlycandidatevaries; the other 7 are identical at all three call sites instep_prune(two in therxloop, one fordeferred_current). This bundles them into aRemovalContext<'a>struct of borrows, constructed once and passed by reference, following the existingCommandContext/RemovedWorktreeOutputContext/TemplateContextpattern. 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, andtry_removestill acquires thecheck_lockwrite 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'srun_hooks: booltohook_plan: &ApprovedHookPlan;RemovalContextcarries that field unchanged.Follow-up commit: the struct refactor incidentally pushed
handle_remove_output(...)past rustfmt'sfn_call_width(thectx.-prefixed args), splitting it multi-line and moving the trailing)?;onto its own line — which LLVM-cov flags as acodecov/patchmiss despite the line executing (line 205 is covered and 205→210 is straight-line). Reading theCopyfields into locals keeps that call byte-identical to its covered form on main, so the diff stays a faithful no-behavior-change refactor.