Skip to content

Commit 43c9e7e

Browse files
committed
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
2 parents 2a5aa82 + bea4dbe commit 43c9e7e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

ref-filter.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,16 @@ static int parse_ref_filter_atom(const struct ref_format *format,
413413
REALLOC_ARRAY(used_atom, used_atom_cnt);
414414
used_atom[at].name = xmemdupz(atom, ep - atom);
415415
used_atom[at].type = valid_atom[i].cmp_type;
416-
if (arg)
416+
if (arg) {
417417
arg = used_atom[at].name + (arg - atom) + 1;
418+
if (!*arg) {
419+
/*
420+
* Treat empty sub-arguments list as NULL (i.e.,
421+
* "%(atom:)" is equivalent to "%(atom)").
422+
*/
423+
arg = NULL;
424+
}
425+
}
418426
memset(&used_atom[at].u, 0, sizeof(used_atom[at].u));
419427
if (valid_atom[i].parser)
420428
valid_atom[i].parser(format, &used_atom[at], arg);

t/t6300-for-each-ref.sh

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ test_atom() {
5151
}
5252

5353
test_atom head refname refs/heads/master
54+
test_atom head refname: refs/heads/master
5455
test_atom head refname:short master
5556
test_atom head refname:lstrip=1 heads/master
5657
test_atom head refname:lstrip=2 master

0 commit comments

Comments
 (0)