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 <gitster@pobox.com>

Junio C Hamano committed Jul 11, 2013 at 23:02 UTC f7cd8c50b9ab83e084e8f52653ecc8d90665eef2
2 files changed +18 -5
Documentation/git-check-attr.txt
+7 -2
@@ -31,8 +31,9 @@ OPTIONS
31 Read file names from stdin instead of from the command-line.
32
33 -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.
37
38 \--::
39 Interpret all preceding arguments as attributes and all following
@@ -48,6 +49,10 @@ OUTPUT
49 The output is of the form:
50 <path> COLON SP <attribute> COLON SP <info> LF
51
52 +unless `-z` is in effect, in which case NUL is used as delimiter:
53 +<path> NUL <attribute> NUL <info> NUL
54 +
55 +
56 <path> is the path of a file being queried, <attribute> is an attribute
57 being queried and <info> can be either:
58
builtin/check-attr.c
+11 -3
@@ -20,7 +20,7 @@ static const struct option check_attr_options[] = {
20 OPT_BOOLEAN(0, "cached", &cached_attrs, N_("use .gitattributes only from the index")),
21 OPT_BOOLEAN(0 , "stdin", &stdin_paths, N_("read file names from stdin")),
22 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")),
24 OPT_END()
25 };
26
@@ -38,8 +38,16 @@ static void output_attr(int cnt, struct git_attr_check *check,
38 else if (ATTR_UNSET(value))
39 value = "unspecified";
40
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 +
51 }
52 }
53