diff options
author | Jeff King <peff@peff.net> | 2012-02-07 13:23:02 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-02-07 10:44:54 -0800 |
commit | 6680a0874f86600cc8b4b5327384934d83d752a8 (patch) | |
tree | c1ed228ef790cc7d69b013fd12393ef10792c804 /userdiff.c | |
parent | 65da088244a1c220a6dbc5bf01c758b4b9df63b3 (diff) | |
download | git-6680a0874f86600cc8b4b5327384934d83d752a8.tar.gz |
drop odd return value semantics from userdiff_configjk/userdiff-config-simplify
When the userdiff_config function was introduced in be58e70
(diff: unify external diff and funcname parsing code,
2008-10-05), it used a return value convention unlike any
other config callback. Like other callbacks, it used "-1" to
signal error. But it returned "1" to indicate that it found
something, and "0" otherwise; other callbacks simply
returned "0" to indicate that no error occurred.
This distinction was necessary at the time, because the
userdiff namespace overlapped slightly with the color
configuration namespace. So "diff.color.foo" could mean "the
'foo' slot of diff coloring" or "the 'foo' component of the
"color" userdiff driver". Because the color-parsing code
would die on an unknown color slot, we needed the userdiff
code to indicate that it had matched the variable, letting
us bypass the color-parsing code entirely.
Later, in 8b8e862 (ignore unknown color configuration,
2009-12-12), the color-parsing code learned to silently
ignore unknown slots. This means we no longer need to
protect userdiff-matched variables from reaching the
color-parsing code.
We can therefore change the userdiff_config calling
convention to a more normal one. This drops some code from
each caller, which is nice. But more importantly, it reduces
the cognitive load for readers who may wonder why
userdiff_config is unlike every other config callback.
There's no need to add a new test confirming that this
works; t4020 already contains a test that sets
diff.color.external.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'userdiff.c')
-rw-r--r-- | userdiff.c | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/userdiff.c b/userdiff.c index 76109da4bc..1e7184f7f0 100644 --- a/userdiff.c +++ b/userdiff.c @@ -210,14 +210,7 @@ static int parse_funcname(struct userdiff_funcname *f, const char *k, if (git_config_string(&f->pattern, k, v) < 0) return -1; f->cflags = cflags; - return 1; -} - -static int parse_string(const char **d, const char *k, const char *v) -{ - if (git_config_string(d, k, v) < 0) - return -1; - return 1; + return 0; } static int parse_tristate(int *b, const char *k, const char *v) @@ -226,13 +219,13 @@ static int parse_tristate(int *b, const char *k, const char *v) *b = -1; else *b = git_config_bool(k, v); - return 1; + return 0; } static int parse_bool(int *b, const char *k, const char *v) { *b = git_config_bool(k, v); - return 1; + return 0; } int userdiff_config(const char *k, const char *v) @@ -246,13 +239,13 @@ int userdiff_config(const char *k, const char *v) if ((drv = parse_driver(k, v, "binary"))) return parse_tristate(&drv->binary, k, v); if ((drv = parse_driver(k, v, "command"))) - return parse_string(&drv->external, k, v); + return git_config_string(&drv->external, k, v); if ((drv = parse_driver(k, v, "textconv"))) - return parse_string(&drv->textconv, k, v); + return git_config_string(&drv->textconv, k, v); if ((drv = parse_driver(k, v, "cachetextconv"))) return parse_bool(&drv->textconv_want_cache, k, v); if ((drv = parse_driver(k, v, "wordregex"))) - return parse_string(&drv->word_regex, k, v); + return git_config_string(&drv->word_regex, k, v); return 0; } |