git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/4] check-attr -z: a single -z should apply to both input and output

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 12, 2013, 06:18 UTC
Message-ID
<1373609927-3244-5-git-send-email-gitster@pobox.com>
In-Reply-To
<1373609927-3244-1-git-send-email-gitster@pobox.com>

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>
---
 Documentation/git-check-attr.txt |  9 +++++++--
 builtin/check-attr.c             | 14 +++++++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-check-attr.txt b/Documentation/git-check-attr.txt
index 5abdbaa..760aca9 100644
--- a/Documentation/git-check-attr.txt
+++ b/Documentation/git-check-attr.txt
@@ -31,8 +31,9 @@ OPTIONS
 	Read file names from stdin instead of from the command-line.
 
 -z::
-	Only meaningful with `--stdin`; paths are separated with a
-	NUL character instead of a linefeed character.
+	The output format is modified to be machine-parseable.
+	If `--stdin` is also given, input paths are separated
+	with a NUL character instead of a linefeed character.
 
 \--::
 	Interpret all preceding arguments as attributes and all following
@@ -48,6 +49,10 @@ OUTPUT
 The output is of the form:
 <path> COLON SP <attribute> COLON SP <info> LF
 
+unless `-z` is in effect, in which case NUL is used as delimiter:
+<path> NUL <attribute> NUL <info> NUL
+
+
 <path> is the path of a file being queried, <attribute> is an attribute
 being queried and <info> can be either:
 
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 7cc9b5d..cd46690 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -20,7 +20,7 @@ static const struct option check_attr_options[] = {
 	OPT_BOOLEAN(0,  "cached", &cached_attrs, N_("use .gitattributes only from the index")),
 	OPT_BOOLEAN(0 , "stdin", &stdin_paths, N_("read file names from stdin")),
 	OPT_BOOLEAN('z', NULL, &nul_term_line,
-		    N_("input paths are terminated by a NUL character")),
+		    N_("terminate input and output records by a NUL character")),
 	OPT_END()
 };
 
@@ -38,8 +38,16 @@ static void output_attr(int cnt, struct git_attr_check *check,
 		else if (ATTR_UNSET(value))
 			value = "unspecified";
 
-		quote_c_style(file, NULL, stdout, 0);
-		printf(": %s: %s\n", git_attr_name(check[j].attr), value);
+		if (nul_term_line) {
+			printf("%s%c" /* path */
+			       "%s%c" /* attrname */
+			       "%s%c" /* attrvalue */,
+			       file, 0, git_attr_name(check[j].attr), 0, value, 0);
+		} else {
+			quote_c_style(file, NULL, stdout, 0);
+			printf(": %s: %s\n", git_attr_name(check[j].attr), value);
+		}
+
 	}
 }
 
-- 
1.8.3.2-911-g2c4daa5
Previous: Junio C HamanoNext: Eric Sunshine
Message 5 of 6 in “Make check-{attr,ignore} -z consistent”
  1. 0/4 Make check-{attr,ignore} -z consistentJunio C Hamano, Jul 12, 2013
  2. 1/4 check-ignore: the name of the character is NUL, not NULLJunio C Hamano, Jul 12, 2013
  3. 2/4 check-attr: the name of the character is NUL, not NULLJunio C Hamano, Jul 12, 2013
  4. 3/4 check-ignore -z: a single -z should apply to both input and outputJunio C Hamano, Jul 12, 2013
  5. 4/4 check-attr -z: a single -z should apply to both input and outputJunio C Hamano, Jul 12, 2013
  6. Eric SunshineJul 12, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.