Øystein Walle <oys...@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 
+                           '\0'),
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to