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>
This commit is contained in:

committed by
Junio C Hamano

parent
73876f4861
commit
aabfdc9514
@ -41,6 +41,7 @@ static const char *head;
|
||||
static struct object_id head_oid;
|
||||
static int recurse_submodules = 0;
|
||||
static int submodule_propagate_branches = 0;
|
||||
static int omit_empty = 0;
|
||||
|
||||
static int branch_use_color = -1;
|
||||
static char branch_colors[][COLOR_MAXLEN] = {
|
||||
@ -461,7 +462,8 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
|
||||
string_list_append(output, out.buf);
|
||||
} else {
|
||||
fwrite(out.buf, 1, out.len, stdout);
|
||||
putchar('\n');
|
||||
if (out.len || !omit_empty)
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
@ -670,6 +672,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
|
||||
OPT_BIT('D', NULL, &delete, N_("delete branch (even if not merged)"), 2),
|
||||
OPT_BIT('m', "move", &rename, N_("move/rename a branch and its reflog"), 1),
|
||||
OPT_BIT('M', NULL, &rename, N_("move/rename a branch, even if target exists"), 2),
|
||||
OPT_BOOL(0, "omit-empty", &omit_empty,
|
||||
N_("do not output a newline after empty formatted refs")),
|
||||
OPT_BIT('c', "copy", ©, N_("copy a branch and its reflog"), 1),
|
||||
OPT_BIT('C', NULL, ©, N_("copy a branch, even if target exists"), 2),
|
||||
OPT_BOOL('l', "list", &list, N_("list branch names")),
|
||||
|
Reference in New Issue
Block a user