Skip to content

Batch the pre-commit final newline check - #253

Merged
dpc merged 1 commit into
rustshop:masterfrom
dpc:dpc/jj-stsltmryrtym
Nov 20, 2026
Merged

dpc merged 1 commit into
rustshop:masterfrom
dpc:dpc/jj-stsltmryrtym

Conversation

@dpc

@dpc dpc commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Posted by Tau

Summary

Fixes #252. The default pre-commit newline check launches tail for each eligible tracked file, splits some filenames incorrectly, and can mistake binary files for text. Replace those per-file processes with one standalone checker. With 2,048 synthetic tracked files and only the newline check enabled, the generated hook's median wall time fell from 3.872 s to 0.205 s (18.9×, seven warm runs on x86_64 Linux).

Details

The check preserves the existing filename filters, passes Git paths as NUL-delimited records, and reads only the final byte on the passing path. If a file does not end in LF, the checker scans for NUL bytes before reporting it. NUL-free binaries without an excluded extension may still need an ignore pattern. Unlike a language-specific ast-grep rule, the checker works on the exact file bytes regardless of extension.

To exercise unusual paths, binary files, and staged versus unstaged behavior, run nix build .#checks.x86_64-linux.gitHooks --no-link.

The hook used a `tail` subprocess per tracked text file, paying for
thousands of process launches on every commit. Shell splitting also
lost valid filenames and reported some binary files as missing an LF.
Ast-grep's language-specific node regexes cannot check the raw EOF of
an arbitrary tracked file reliably.

Pass NUL-delimited paths and the existing exclusions to a standalone
Rust checker. Read one byte for files that already end in LF; for the
rest, report a violation only after ruling out NUL bytes. Keep the
legacy inventories for other hooks and accept an empty selection.

The generated newline-only pre-commit dispatcher and runner took
0.205s instead of 3.872s (median of seven warm runs, 2,048 synthetic
tracked files on x86_64 Linux). Both versions rejected a staged
missing-LF text file.

Review: fixed absent paths whose parent was replaced by a file, tested
production package wiring, and guarded the non-UTF-8 filename test on
filesystems that forbid it. The follow-up review passed.
@dpc
dpc merged commit 9197790 into rustshop:master Nov 20, 2026
4 checks passed
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.

Pre-commit: avoid spawning tail for every tracked text file

1 participant