Skip to content

Commit f7cd8c5

Browse files
committed
check-attr -z: a single -z should apply to both input and output
Unless a command has separate --nul-terminated-{input,output} options, the --nul-terminated-records (-z) option should apply to both input and output for consistency. The caller knows that its input paths may need to be protected for LF, and the program shows these problematic paths to its output. Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6dcb92 commit f7cd8c5

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Documentation/git-check-attr.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ OPTIONS
3131
Read file names from stdin instead of from the command-line.
3232

3333
-z::
34-
Only meaningful with `--stdin`; paths are separated with a
35-
NUL character instead of a linefeed character.
34+
The output format is modified to be machine-parseable.
35+
If `--stdin` is also given, input paths are separated
36+
with a NUL character instead of a linefeed character.
3637

3738
\--::
3839
Interpret all preceding arguments as attributes and all following
@@ -48,6 +49,10 @@ OUTPUT
4849
The output is of the form:
4950
<path> COLON SP <attribute> COLON SP <info> LF
5051

52+
unless `-z` is in effect, in which case NUL is used as delimiter:
53+
<path> NUL <attribute> NUL <info> NUL
54+
55+
5156
<path> is the path of a file being queried, <attribute> is an attribute
5257
being queried and <info> can be either:
5358

builtin/check-attr.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static const struct option check_attr_options[] = {
2020
OPT_BOOLEAN(0, "cached", &cached_attrs, N_("use .gitattributes only from the index")),
2121
OPT_BOOLEAN(0 , "stdin", &stdin_paths, N_("read file names from stdin")),
2222
OPT_BOOLEAN('z', NULL, &nul_term_line,
23-
N_("input paths are terminated by a NUL character")),
23+
N_("terminate input and output records by a NUL character")),
2424
OPT_END()
2525
};
2626

@@ -38,8 +38,16 @@ static void output_attr(int cnt, struct git_attr_check *check,
3838
else if (ATTR_UNSET(value))
3939
value = "unspecified";
4040

41-
quote_c_style(file, NULL, stdout, 0);
42-
printf(": %s: %s\n", git_attr_name(check[j].attr), value);
41+
if (nul_term_line) {
42+
printf("%s%c" /* path */
43+
"%s%c" /* attrname */
44+
"%s%c" /* attrvalue */,
45+
file, 0, git_attr_name(check[j].attr), 0, value, 0);
46+
} else {
47+
quote_c_style(file, NULL, stdout, 0);
48+
printf(": %s: %s\n", git_attr_name(check[j].attr), value);
49+
}
50+
4351
}
4452
}
4553

0 commit comments

Comments
 (0)