diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-04-22 00:35:05 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-04-22 00:35:05 +0200 |
commit | b64894c2063e5875bfd95b537eafcb3e1abf46ff (patch) | |
tree | 989d1d734418b366f23738b228b96dcd6ec1acbd /builtin/for-each-ref.c | |
parent | Merge branch 'ah/format-patch-thread-doc' (diff) | |
parent | branch, for-each-ref, tag: add option to omit empty lines (diff) | |
download | git-b64894c2063e5875bfd95b537eafcb3e1abf46ff.tar.xz git-b64894c2063e5875bfd95b537eafcb3e1abf46ff.zip |
Merge branch 'ow/ref-filter-omit-empty'
"git branch --format=..." and "git format-patch --format=..."
learns "--omit-empty" to hide refs that whose formatting result
becomes an empty string from the output.
* ow/ref-filter-omit-empty:
branch, for-each-ref, tag: add option to omit empty lines
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 0bdc49a6e1..695fc8f4a5 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -22,7 +22,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; @@ -40,6 +40,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")), @@ -112,7 +114,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); |