Skip to content

Ask git once per repo, cut scan memory, stop the scan on quit, ctrl+c quits from the key list - #8

Merged
devloop01 merged 4 commits into
mainfrom
claude/kind-newton-7v2sgz
Nov 14, 2026
Merged

devloop01 merged 4 commits into
mainfrom
claude/kind-newton-7v2sgz

Conversation

@devloop01

Copy link
Copy Markdown
Owner

Fixes the four follow-ups left open after #3.

Closes #4, closes #5, closes #6, closes #7.

#4 — Ask git once per repo

During a scan, each repository is now asked once which target folders hold tracked files (git ls-files -z from the repo top), and one git check-ignore --stdin stays running per repository to answer ignore questions path by path.

Measured on a repo with 500 packages, each with node_modules, dist and .turbo (Linux, 4 workers):

git runs scan time
before 1000 562 ms
after 2 48 ms

Safety:

  • Deleting is unchanged. Remove still calls Vet, which asks git about each folder on its own, exactly as before. The new answers only decide what the scan lists, so a wrong one shows a folder that is then refused, never a deleted tracked folder.
  • Fails towards keeping. If git can't list the repo, every folder in it is kept. If the running check-ignore dies or stops answering, sweep falls back to asking per folder.
  • Case. Tracked paths are compared lower-cased, because APFS ignores case.
  • Non-ASCII paths are still asked per folder: git and the disk may spell them differently (core.precomposeunicode).

TestScanAnswersLikeKeep checks that the scan's answer equals keep's for about 130 folders across tracked, ignored, !-rule, nested-repo and non-ASCII cases, and again after killing the running git.

#5 — Hard-link memory

measure kept a map[inode]int64 per target (about 55 bytes per file), and Scan built a second map to attribute shared files. Both are replaced by sorted slices: 16 bytes per file during the scan, plus a 24-byte-per-file list while sizes are attributed at the end. The attribution rule is unchanged: a file linked into several targets is charged to the first one in path order.

#7 — Stop the scan on quit

Progress.Stop() makes a running Scan return soon with the folders it measured to the end. The screen calls it once the user quits, so the scan no longer runs on while sweep waits for deletions to finish.

#6 — Quit keys in the key list

I picked option 2 from the issue: ctrl+c and ctrl+d now quit at the first press from anywhere, including the ? key list. q there still only closes it, as "Press any key to close" says. Say if you'd prefer one of the other options.

Testing

  • GOOS=darwin GOARCH=arm64 go vet ./... passes.
  • The full suite passes with -race on Linux in a copy with the build tags and ioctl constants swapped (the two delete-failure tests need a non-root user, as on main).
  • Each new test fails when its fix is disabled.
  • Not run on macOS locally. The test workflow runs on macos-latest, so CI on this PR is the macOS run. The parts that depend on macOS are the case-insensitive disk and Apple's git answering check-ignore --stdin path by path; TestScanAnswersLikeKeep fails if the latter doesn't hold.

The branch also carries a merge of its earlier history (already in main as #3) with no file changes.


Generated by Claude Code

…y helper

The exported At let any caller build a Candidate that Remove accepts
without Scan's checks, such as the one for a volume mounted inside a
target. It is now a helper in the package's tests that fails on a
folder it can't read.

Tests ask Vet directly about each trap, and a new one checks that a
candidate not from Scan is refused even when its path passes Vet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D9oJWw4k81eBvUNWWQjoMK
…aller bugs

Could delete the wrong thing:
- An empty DIR (a script's unset variable) was read as the current folder.
- git was run with the inherited GIT_DIR / GIT_INDEX_FILE, so from a hook
  or a dotfiles shell it answered for another repo and tracked folders
  looked disposable.
- A target with its own .git (a nested clone, a worktree) in an ignored
  build/ was treated as build output.
- A volume mounted inside a listed folder after the scan was emptied.

Smaller:
- /dev/null counted as a terminal, so sweep > /dev/null opened the screen.
- A build whose version is a bare commit hash was told to upgrade on every
  run, and sweep upgrade replaced it.
- A target that vanished during the scan was listed as a 0.0 KB row that
  could never be deleted.
- The scan status line could be cut inside the … on a very narrow terminal.

Faster: targets in one folder are put to git together, so a project's
node_modules, .next and dist cost two git runs instead of five. The
re-check before each delete still asks per folder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D9oJWw4k81eBvUNWWQjoMK
…trl+c quits from the key list

Scan: each repository is asked once which target folders hold tracked
files, and one git check-ignore stays running per repository for the
ignore rules. A 500-package repo took 1000 git runs; now 2. Remove still
asks git about each folder on its own before deleting it, so these
answers only decide what is listed. Paths that aren't plain ASCII are
still asked per folder: git may spell them differently from the disk.

Scan: hard-linked files are kept in a sorted slice per target (16 bytes
a file, where the map took about 55) and attributed with one sorted list
at the end instead of a second map.

Progress.Stop ends a running scan; the screen calls it on quit, so a
scan no longer runs on while sweep waits for deletions to finish.

ctrl+c and ctrl+d now quit from the key list at the first press. q there
still only closes it, as "Press any key to close" says.

Closes #4, closes #5, closes #6, closes #7.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D9oJWw4k81eBvUNWWQjoMK
…anges)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D9oJWw4k81eBvUNWWQjoMK
@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d449da8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devloop01
devloop01 merged commit 5dba7c6 into main Nov 14, 2026
1 check passed
@devloop01
devloop01 deleted the claude/kind-newton-7v2sgz branch November 14, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants