summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-10-07 07:27:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-10-07 07:27:56 (GMT)
commit43c9e7e365d7a8961767d0bd4a305ca378800a2a (patch)
tree342920df153ff2430522658d9338f2d8734f01fe /ref-filter.c
parent2a5aa826eec2eec64b4065f599ee7fb613a871ba (diff)
parentbea4dbeafda3ddc4404f2e94dce0b66a4105399a (diff)
downloadgit-43c9e7e365d7a8961767d0bd4a305ca378800a2a.zip
git-43c9e7e365d7a8961767d0bd4a305ca378800a2a.tar.gz
git-43c9e7e365d7a8961767d0bd4a305ca378800a2a.tar.bz2
Merge branch 'tb/ref-filter-empty-modifier'
In the "--format=..." option of the "git for-each-ref" command (and its friends, i.e. the listing mode of "git branch/tag"), "%(atom:)" (e.g. "%(refname:)", "%(body:)" used to error out. Instead, treat them as if the colon and an empty string that follows it were not there. * tb/ref-filter-empty-modifier: ref-filter.c: pass empty-string as NULL to atom parsers
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 5532362..45a3be8 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -413,8 +413,16 @@ static int parse_ref_filter_atom(const struct ref_format *format,
REALLOC_ARRAY(used_atom, used_atom_cnt);
used_atom[at].name = xmemdupz(atom, ep - atom);
used_atom[at].type = valid_atom[i].cmp_type;
- if (arg)
+ if (arg) {
arg = used_atom[at].name + (arg - atom) + 1;
+ if (!*arg) {
+ /*
+ * Treat empty sub-arguments list as NULL (i.e.,
+ * "%(atom:)" is equivalent to "%(atom)").
+ */
+ arg = NULL;
+ }
+ }
memset(&used_atom[at].u, 0, sizeof(used_atom[at].u));
if (valid_atom[i].parser)
valid_atom[i].parser(format, &used_atom[at], arg);