Skip to content

Commit d9e8586

Browse files
committed
Merge branch 'tb/ref-filter-empty-modifier' into maint
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 96d4b17 + bea4dbe commit d9e8586

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

ref-filter.c

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

t/t6300-for-each-ref.sh

Lines changed: 1 addition & 0 deletions
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)