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
@ -37,6 +37,7 @@ static const char * const git_tag_usage[] = {
|
||||
static unsigned int colopts;
|
||||
static int force_sign_annotate;
|
||||
static int config_sign_tag = -1; /* unspecified */
|
||||
static int omit_empty = 0;
|
||||
|
||||
static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting,
|
||||
struct ref_format *format)
|
||||
@ -74,7 +75,8 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting,
|
||||
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);
|
||||
@ -473,6 +475,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
|
||||
OPT_WITHOUT(&filter.no_commit, N_("print only tags that don't contain the commit")),
|
||||
OPT_MERGED(&filter, N_("print only tags that are merged")),
|
||||
OPT_NO_MERGED(&filter, N_("print only tags that are not merged")),
|
||||
OPT_BOOL(0, "omit-empty", &omit_empty,
|
||||
N_("do not output a newline after empty formatted refs")),
|
||||
OPT_REF_SORT(&sorting_options),
|
||||
{
|
||||
OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"),
|
||||
|
Reference in New Issue
Block a user