fix(worktree): speed up worktree list and stop leaking branch=… lines#42
Merged
fix(worktree): speed up worktree list and stop leaking branch=… lines#42
Conversation
Two bugs surface together in `ckipper worktree list`: 1. Slow scan. `find` recursed unbounded under $CKIPPER_WORKTREES_DIR with only `*/node_modules/*` excluded, so the heavy build/cache trees (`dist`, `.next`, `target`, `__pycache__`, etc.) were walked in full. On a 6 GB / 380k-file worktrees tree the scan took ~700 ms. Pruning the known-heavy directory names brings it to ~30 ms (≈25× faster); bounding by depth was not viable because branches contain slashes (e.g. `feature/OGD-320-…`). 2. Spurious `branch='…'` lines under each bullet. `local branch` (no `=value`) inside the per-iteration loop body behaves like `typeset -p branch` once the variable already carries a value from a prior iteration. Hoist `branch` (and the other loop locals) above the `while` and assign without `local` inside, matching the existing precedent in lib/account/sync/preview.zsh. Adds three regression tests: - pruning skips `.git` files inside node_modules / dist / __pycache__ - branches with slashes still resolve (no depth bound) - output never contains literal `branch=` lines
Owner
Author
|
Folding into #41 per request — both fixes shipping in one PR. |
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 bugs in
ckipper worktree listfixed together because they surface in the same command's output.1. Slow scan — ≈25× faster.
findrecursed unbounded under$CKIPPER_WORKTREES_DIRwith only*/node_modules/*excluded, so heavy build/cache trees (dist,.next,target,__pycache__, etc.) were walked in full. On a 6 GB / 380k-file worktrees tree the scan took ~700 ms. Pruning the known-heavy directory names brings it to ~30 ms. Bounding by depth was not viable because branches contain slashes (e.g.feature/OGD-320-…).2. Spurious
branch='…'lines.local branch(no=value) inside the per-iteration loop body behaves liketypeset -p branchonce the variable already carries a value from a prior iteration, leaking literal lines under each bullet. Hoisted the loop locals above thewhileto match the existing precedent for the same hazard inlib/account/sync/preview.zsh.Before / after on the author's tree
Test plan
bats lib/worktree/worktree_test.bats— 15/15 pass, including 3 new regressionsmake test-unit— 504/504 shell tests passmake lint-shell lint-zsh lint-fmt lint-merge-guards— all cleanzsh -f -c '… ckipper worktree list'shows nobranch=lines and is visibly instant