Home Explore Blog CI



git

7th chunk of `Documentation/gitattributes.adoc`
2f49649193db630f57e4ed3420d1f49472b2bd50316c00090000000100000fb3
 filter is well-behaved in this regard: it will not modify
input that is already correctly indented.  In this case, the lack of a
smudge filter means that the clean filter _must_ accept its own output
without modifying it.

If a filter _must_ succeed in order to make the stored contents usable,
you can declare that the filter is `required`, in the configuration:

------------------------
[filter "crypt"]
	clean = openssl enc ...
	smudge = openssl enc -d ...
	required
------------------------

Sequence "%f" on the filter command line is replaced with the name of
the file the filter is working on.  A filter might use this in keyword
substitution.  For example:

------------------------
[filter "p4"]
	clean = git-p4-filter --clean %f
	smudge = git-p4-filter --smudge %f
------------------------

Note that "%f" is the name of the path that is being worked on. Depending
on the version that is being filtered, the corresponding file on disk may
not exist, or may have different contents. So, smudge and clean commands
should not try to access the file on disk, but only act as filters on the
content provided to them on standard input.

Long Running Filter Process
^^^^^^^^^^^^^^^^^^^^^^^^^^^

If the filter command (a string value) is defined via
`filter.<driver>.process` then Git can process all blobs with a
single filter invocation for the entire life of a single Git
command. This is achieved by using the long-running process protocol
(described in Documentation/technical/long-running-process-protocol.adoc).

When Git encounters the first file that needs to be cleaned or smudged,
it starts the filter and performs the handshake. In the handshake, the
welcome message sent by Git is "git-filter-client", only version 2 is
supported, and the supported capabilities are "clean", "smudge", and
"delay".

Afterwards Git sends a list of "key=value" pairs terminated with
a flush packet. The list will contain at least the filter command
(based on the supported capabilities) and the pathname of the file
to filter relative to the repository root. Right after the flush packet
Git sends the content split in zero or more pkt-line packets and a
flush packet to terminate content. Please note, that the filter
must not send any response before it received the content and the
final flush packet. Also note that the "value" of a "key=value" pair
can contain the "=" character whereas the key would never contain
that character.

-----------------------
packet:          git> command=smudge
packet:          git> pathname=path/testfile.dat
packet:          git> 0000
packet:          git> CONTENT
packet:          git> 0000
-----------------------

The filter is expected to respond with a list of "key=value" pairs
terminated with a flush packet. If the filter does not experience
problems then the list must contain a "success" status. Right after
these packets the filter is expected to send the content in zero
or more pkt-line packets and a flush packet at the end. Finally, a
second list of "key=value" pairs terminated with a flush packet
is expected. The filter can change the status in the second list
or keep the status as is with an empty list. Please note that the
empty list must be terminated with a flush packet regardless.

------------------------
packet:          git< status=success
packet:          git< 0000
packet:          git< SMUDGED_CONTENT
packet:          git< 0000
packet:          git< 0000  # empty list, keep "status=success" unchanged!
------------------------

If the result content is empty then the filter is expected to respond
with a "success" status and a flush packet to signal the empty content.

------------------------
packet:          git< status=success
packet:          git< 0000
packet:          git< 0000  # empty content!
packet:          git< 0000  # empty list, keep "status=success" unchanged!
------------------------

In case the filter cannot or does not want to process the content,
it is expected to respond with an "error" status.

-----------------------

Title: Git Filter Configuration and Protocol
Summary
Git's filter attributes allow for content manipulation during checkout and checkin, with options for required filters, filter configuration, and command-line substitutions, and a long-running process protocol for processing all blobs with a single filter invocation for the entire life of a single Git command.