mirror of
https://github.com/git/git.git
synced 2024-11-19 09:44:05 +01:00
ref-filter.c: pass empty-string as NULL to atom parsers
Peff points out that different atom parsers handle the empty "sub-argument" list differently. An example of this is the format "%(refname:)". Since callers often use `string_list_split` (which splits the empty string with any delimiter as a 1-ary string_list containing the empty string), this makes handling empty sub-argument strings non-ergonomic. Let's fix this by declaring that atom parser implementations must not care about distinguishing between the empty string "%(refname:)" and no sub-arguments "%(refname)". Current code aborts, either with "unrecognised arg" (e.g. "refname:") or "does not take args" (e.g. "body:") as an error message. Signed-off-by: Taylor Blau <me@ttaylorr.com> Reviewed-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
4010f1d1b7
commit
bea4dbeafd
10
ref-filter.c
10
ref-filter.c
@ -415,8 +415,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);
|
||||
|
@ -51,6 +51,7 @@ test_atom() {
|
||||
}
|
||||
|
||||
test_atom head refname refs/heads/master
|
||||
test_atom head refname: refs/heads/master
|
||||
test_atom head refname:short master
|
||||
test_atom head refname:lstrip=1 heads/master
|
||||
test_atom head refname:lstrip=2 master
|
||||
|
Loading…
Reference in New Issue
Block a user