use skip_prefix to avoid repeating strings
It's a common idiom to match a prefix and then skip past it with strlen, like: if (starts_with(foo, "bar")) foo += strlen("bar"); This avoids magic numbers, but means we have to repeat the string (and there is no compiler check that we didn't make a typo in one of the strings). We can use skip_prefix to handle this case without repeating ourselves. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
ae021d8791
commit
95b567c7c3
3
pretty.c
3
pretty.c
@ -40,10 +40,9 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
|
||||
const char *fmt;
|
||||
int i;
|
||||
|
||||
if (!starts_with(var, "pretty."))
|
||||
if (!skip_prefix(var, "pretty.", &name))
|
||||
return 0;
|
||||
|
||||
name = var + strlen("pretty.");
|
||||
for (i = 0; i < builtin_formats_len; i++) {
|
||||
if (!strcmp(commit_formats[i].name, name))
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user