pre-commit/pre_commit/languages
Sharmila Jesupaul 635912514d add pass_filenames_via_stdin for large changesets
pre-commit currently passes selected filenames to hooks via argv.
For large changesets (or --all-files), argv length limits are hit and
filenames are partitioned, causing multiple hook invocations.

This means there is currently no built-in way to pass filenames to an
underlying hook in one shot without chunking / re-running. The only practical
workaround is to set pass_filenames: false and run custom git operations in
hook code to reconstruct the file set, which is expensive and duplicates
pre-commit's own file-selection logic.

This change adds a hook option:

    pass_filenames_via_stdin: true

When enabled, pre-commit sends filenames as NUL-delimited bytes on stdin and
runs the hook in a single invocation (no argv chunking).

Why NUL-delimited stdin:
- safe for filenames containing spaces/newlines
- matches established -0 conventions in unix tooling

Usage for hook authors:
- shell:

    while IFS= read -r -d '' filename; do
        ...
    done

- python:

    data = sys.stdin.buffer.read()
    filenames = [os.fsdecode(p) for p in data.split(b'\0') if p]

Behavior notes:
- default remains argv-based passing
- pass_filenames: false still disables filename passing entirely

Implementation includes schema/runtime wiring, shared NUL encode/decode
helpers, and tests covering defaulting and runtime behavior.
2026-02-18 18:06:34 -08:00
..
__init__.py OMG we're running a hook 2014-03-13 22:12:33 -07:00
conda.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
coursier.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
dart.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
docker.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
docker_image.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
dotnet.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
fail.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
golang.py py310+ 2025-10-09 17:44:05 -04:00
haskell.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
julia.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
lua.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
node.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
perl.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
pygrep.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
python.py adjust python default_language_version to prefer versioned exe 2025-03-18 14:55:24 -04:00
r.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
ruby.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
rust.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
swift.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2024-07-29 21:59:19 +00:00
unsupported.py rename system and script languages to unsupported / unsupported_script 2025-11-08 15:09:16 -05:00
unsupported_script.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00