diff options
author | Øystein Walle <oystwa@gmail.com> | 2023-04-07 19:53:16 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-04-13 17:07:45 +0200 |
commit | aabfdc9514a51d8d9a2f3afbc29e5044ccf7191b (patch) | |
tree | ce139c4fbbe04454b87b128865b2047f8ae5070f /builtin/for-each-ref.c | |
parent | Git 2.40 (diff) | |
download | git-aabfdc9514a51d8d9a2f3afbc29e5044ccf7191b.tar.xz git-aabfdc9514a51d8d9a2f3afbc29e5044ccf7191b.zip |
branch, for-each-ref, tag: add option to omit empty lines
If the given format string expands to the empty string, a newline is
still printed. This makes using the output linewise more tedious. For
example, git update-ref --stdin does not accept empty lines.
Add options to "git branch", "git for-each-ref", and "git tag" to
not print these empty lines. The default behavior remains the same.
Signed-off-by: Øystein Walle <oystwa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/for-each-ref.c')
-rw-r--r-- | builtin/for-each-ref.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 6f62f40d12..1fc5130481 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -19,7 +19,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) int i; struct ref_sorting *sorting; struct string_list sorting_options = STRING_LIST_INIT_DUP; - int maxcount = 0, icase = 0; + int maxcount = 0, icase = 0, omit_empty = 0; struct ref_array array; struct ref_filter filter; struct ref_format format = REF_FORMAT_INIT; @@ -35,6 +35,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) N_("quote placeholders suitably for python"), QUOTE_PYTHON), OPT_BIT(0 , "tcl", &format.quote_style, N_("quote placeholders suitably for Tcl"), QUOTE_TCL), + OPT_BOOL(0, "omit-empty", &omit_empty, + N_("do not output a newline after empty formatted refs")), OPT_GROUP(""), OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")), @@ -88,7 +90,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) if (format_ref_array_item(array.items[i], &format, &output, &err)) die("%s", err.buf); fwrite(output.buf, 1, output.len, stdout); - putchar('\n'); + if (output.len || !omit_empty) + putchar('\n'); } strbuf_release(&err); |