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

Re: [PATCH] for-each-ref: add option to omit newlines

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 13, 2014, 20:10 UTC
Message-ID
<xmqq38jmlqo6.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1392314429-15281-1-git-send-email-oystwa@gmail.com>
Øystein Walle <oystwa@gmail.com> writes:
> On to the patch itself: I contemplated putting '\n' in the default format and
> removing it if -n was given, which would get rid of the need to pass an exta
> argument to show_ref(). But that means we would need to *insert it* when a
> format is given and -n is not...

I would rather see us go in the direction to add "-z" output option, which is what everybody else that produces NUL terminated entries in our suite of subcommands does.

IOW, something along with this line (untested).
 builtin/for-each-ref.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 51798b4..2c8cac8 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -94,6 +94,7 @@ static const char **used_atom;
 static cmp_type *used_atom_type;
 static int used_atom_cnt, need_tagged, need_symref;
 static int need_color_reset_at_eol;
+static int line_termination = '\n';
 
 /*
  * Used to parse format string and sort specifiers
@@ -1023,7 +1024,7 @@ static void show_ref(struct refinfo *info, const char *format, int quote_style)
 		resetv.s = color;
 		print_value(&resetv, quote_style);
 	}
-	putchar('\n');
+	putchar(line_termination);
 }
 
 static struct ref_sort *default_sort(void)
@@ -1088,6 +1089,9 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
 		OPT_STRING(  0 , "format", &format, N_("format"), N_("format to use for the output")),
 		OPT_CALLBACK(0 , "sort", sort_tail, N_("key"),
 			    N_("field name to sort on"), &opt_parse_sort),
+		OPT_SET_INT('z', NULL, &line_termination,
+			    N_("Use NUL instead of LF to end each output records"),
+			    '\0'),
 		OPT_END(),
 	};
 
Previous: Øystein WalleNext: Øystein Walle
Message 3 of 7 in “for-each-ref: add option to omit newlines”
  1. for-each-ref: add option to omit newlinesØystein Walle, Feb 13, 2014
  2. Øystein WalleFeb 13, 2014
  3. Junio C HamanoFeb 13, 2014
  4. Øystein WalleFeb 14, 2014
  5. Junio C HamanoFeb 14, 2014
  6. Øystein WalleFeb 14, 2014
  7. Junio C HamanoFeb 14, 2014

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.