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§
- Clean
Extension - One pointer extension’s clean side.
- Smudge
Extension - One pointer extension’s smudge side.
Enums§
- Clean
Error - Things that can go wrong while running
clean. - Clean
Outcome - Result of running the
cleanfilter on a piece of input. - Filter
Process Error - Things that can go wrong while running
filter_process. - Smudge
Error - Things that can go wrong while running
smudge. - Smudge
Outcome - Result of running the
smudgefilter on a piece of input.
Functions§
- build_
pointer_ with_ extensions - Run
inputthrough the configuredextensionschain in priority order and return the resultingPointerwithout inserting the final stage’s output anywhere. - clean
- Apply the clean filter to
input, writing the resulting pointer (or the pass-through bytes) tooutput. - 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) tooutput. - smudge_
object_ to - Stream the working-tree content for an already-parsed
pointertooutput. - smudge_
with_ fetch - Like
smudge, but on a missing-object miss invokesfetchto populate the store, then streams the freshly-fetched bytes tooutput.
Type Aliases§
- Fetch
Error - Boxed error returned by the on-demand fetch closure passed to
smudge_with_fetchorfilter_process.