Skip to main content

Crate git_lfs_filter

Crate git_lfs_filter 

Source
Expand description

Clean and smudge filters and the filter-process protocol for Git LFS.

Git invokes content filters whenever a file moves between the working tree and a git blob: a clean filter runs on the way in (git add) and a smudge filter runs on the way out (git checkout). LFS hooks into both ends. Clean hashes the working-tree bytes, hands them to the local LFS store, and emits a small pointer file (which is what git ends up storing); smudge takes the pointer back from git, looks up the real bytes (fetching from the server if they’re not local), and writes the content into the working tree.

This crate implements both filters plus the long-running filter-process protocol, which modern git uses by default: one subprocess handles many files in a single session over a pkt-line-framed connection.

Three entry points: clean runs the clean side (CleanOutcome reports whether the input was an already-canonical pointer that passed through verbatim or content that was hashed and stored), smudge runs the smudge side and errors with SmudgeError::ObjectMissing when the local store doesn’t have the object, and filter_process is the long-running variant, multiplexing many clean and smudge requests in one pkt-line session.

Pointer extensions chain external programs between the raw bytes and the stored object. CleanExtension and SmudgeExtension describe one chain stage each (name, priority, command); a clean run pipes the file through each registered extension in priority order and records the per-stage OID in the resulting pointer, and smudge undoes the chain in reverse. build_pointer_with_extensions runs the chain on a preview path that doesn’t insert into the store, used by git lfs pointer --file=X to show what clean would emit.

Two convenience variants on the smudge side: smudge_object_to streams an already-parsed pointer’s object content to a writer (used by pull and checkout, which have the pointer in hand from an index walk and don’t need the pointer-detection front end); smudge_with_fetch fetches missing objects via a caller-supplied closure rather than erroring out.

See docs/spec.md § “Intercepting Git” for the protocol contract.

Structs§

CleanExtension
One pointer extension’s clean side.
SmudgeExtension
One pointer extension’s smudge side.

Enums§

CleanError
Things that can go wrong while running clean.
CleanOutcome
Result of running the clean filter on a piece of input.
FilterProcessError
Things that can go wrong while running filter_process.
SmudgeError
Things that can go wrong while running smudge.
SmudgeOutcome
Result of running the smudge filter on a piece of input.

Functions§

build_pointer_with_extensions
Run input through the configured extensions chain in priority order and return the resulting Pointer without inserting the final stage’s output anywhere.
clean
Apply the clean filter to input, writing the resulting pointer (or the pass-through bytes) to output.
filter_process
Run the filter-process protocol against input/output (typically stdin/stdout). Returns when git closes its end of the pipe.
smudge
Apply the smudge filter to input, writing the working-tree content (or pass-through bytes) to output.
smudge_object_to
Stream the working-tree content for an already-parsed pointer to output.
smudge_with_fetch
Like smudge, but on a missing-object miss invokes fetch to populate the store, then streams the freshly-fetched bytes to output.

Type Aliases§

FetchError
Boxed error returned by the on-demand fetch closure passed to smudge_with_fetch or filter_process.