All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Øystein Walle" <oystwa@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] for-each-ref: add option to omit newlines
Date: Thu, 13 Feb 2014 12:10:33 -0800	[thread overview]
Message-ID: <xmqq38jmlqo6.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1392314429-15281-1-git-send-email-oystwa@gmail.com> ("Øystein Walle"'s message of "Thu, 13 Feb 2014 19:00:29 +0100")

Ø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(),
 	};
 

  parent reply	other threads:[~2014-02-13 20:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13 18:00 [PATCH] for-each-ref: add option to omit newlines Øystein Walle
2014-02-13 18:15 ` Øystein Walle
2014-02-13 20:10 ` Junio C Hamano [this message]
2014-02-14  8:11   ` Øystein Walle
2014-02-14 16:28     ` Junio C Hamano
2014-02-14 23:03       ` Øystein Walle
2014-02-14 23:24         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq38jmlqo6.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=oystwa@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.