Expand description
What:
Git’s attribute-file lexer and pattern matcher over raw bytes, as far as a refusal needs them: which lines of an
attributes file set an attribute that can change a file’s bytes on the way into the index, and whether the pattern of
such a line may apply to a path.
Why:
Paths and patterns are byte strings to Git, and attr.c splits a line on the four blank bytes space, tab, carriage
return and line feed only, ends a line’s text at a NUL, and skips a UTF-8 byte order mark on the first line of a worktree
file. Any other reading of the same bytes (Unicode whitespace, lossy decoding, Unicode case folding) can miss a line Git
applies, and a miss accepts a file whose bytes Git would convert. Every spelling the matcher does not model answers that
the line may apply, so the error is always a refusal.
In TS you’d write (pseudocode):
const lines = parseAttributeLines(bytes); // Buffer -> { subject: Buffer; isMacro: boolean; tokens: Buffer[] }[]
mayApply(pattern, base, path); // true unless the pattern provably misses the pathStructs§
- Attribute
Line - One line of an attributes file: a pattern with its attribute tokens, or a macro definition.
Constants§
- CONVERTING_
ATTRIBUTES - The attributes that change a file’s bytes on the way into the index, besides the line-ending ones.
- MATCH_
WORK_ LIMIT - The most cells of the matcher’s table that one comparison may fill; a larger comparison answers that the pattern may apply.
Functions§
- attribute_
name - The attribute a token sets, unsets or leaves unspecified, without the sign and the value.
- may_
apply - What:
Whether the pattern of an attributes line in the directory
basemay apply to the filepath; a spelling the matcher does not model (a quote, an escape, a bracket class,**, a trailing slash), or whose comparison would exceed the work budget, answers yes. Why: Answering yes refuses a file that Git might not have matched; answering no for a file it matches would accept one. - parse_
attribute_ lines - What: The lines of an attributes file’s bytes that set something: patterns with tokens, and macro definitions. Why: A comment or blank line applies nothing. A line ends at its first NUL, as a C string does, and the lines after it are still read, which can only make more lines count. A quoted line is only flagged, because its true pattern, its token boundary and its macro marker depend on C-style unquoting.
- wildcard
- What:
Whether
textmatches the shell patternpattern, byte for byte with ASCII case folded, where*and?stop at a slash. Why: Git’s wildmatch compares bytes and folds ASCII only; folding more than Git does can only make a match more likely.