From: Jeff King <peff@peff.net>
To: Joachim Schmitz <jojo@schmitz-digital.de>
Cc: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>,
"Junio C Hamano" <gitster@pobox.com>,
git@vger.kernel.org
Subject: [PATCH 4/6] userdiff: drop parse_driver function
Date: Mon, 14 Jan 2013 07:04:14 -0800 [thread overview]
Message-ID: <20130114150414.GD16828@sigill.intra.peff.net> (raw)
In-Reply-To: <20130114145845.GA16497@sigill.intra.peff.net>
When we parse userdiff config, we generally assume that
diff.name.key
will affect the "key" value of the "name" driver. However,
without checking the key, we conflict with the ancient
"diff.color.*" namespace. The current code is careful not to
even create a driver struct if we do not see a key that is
known by the diff-driver code.
However, this carefulness is unnecessary; the default driver
with no keys set behaves exactly the same as having no
driver at all. We can simply set up the driver struct as
soon as we see we have a config key that looks like a
driver. This makes the code a bit more readable.
Signed-off-by: Jeff King <peff@peff.net>
---
This is not strictly related to the series, but I noticed it as a
cleanup while doing the previous patch.
userdiff.c | 50 +++++++++++++++++++++-----------------------------
1 file changed, 21 insertions(+), 29 deletions(-)
diff --git a/userdiff.c b/userdiff.c
index 1a6a0fa..c6cdec4 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -184,28 +184,6 @@ static struct userdiff_driver *userdiff_find_by_namelen(const char *k, int len)
return NULL;
}
-static struct userdiff_driver *parse_driver(const char *var,
- const char *value, const char *type)
-{
- struct userdiff_driver *drv;
- const char *name, *key;
- int namelen;
-
- if (match_config_key(var, "diff", &name, &namelen, &key) < 0 ||
- strcmp(type, key))
- return NULL;
-
- drv = userdiff_find_by_namelen(name, namelen);
- if (!drv) {
- ALLOC_GROW(drivers, ndrivers+1, drivers_alloc);
- drv = &drivers[ndrivers++];
- memset(drv, 0, sizeof(*drv));
- drv->name = xmemdupz(name, namelen);
- drv->binary = -1;
- }
- return drv;
-}
-
static int parse_funcname(struct userdiff_funcname *f, const char *k,
const char *v, int cflags)
{
@@ -233,20 +211,34 @@ int userdiff_config(const char *k, const char *v)
int userdiff_config(const char *k, const char *v)
{
struct userdiff_driver *drv;
+ const char *name, *type;
+ int namelen;
+
+ if (match_config_key(k, "diff", &name, &namelen, &type) || !name)
+ return 0;
+
+ drv = userdiff_find_by_namelen(name, namelen);
+ if (!drv) {
+ ALLOC_GROW(drivers, ndrivers+1, drivers_alloc);
+ drv = &drivers[ndrivers++];
+ memset(drv, 0, sizeof(*drv));
+ drv->name = xmemdupz(name, namelen);
+ drv->binary = -1;
+ }
- if ((drv = parse_driver(k, v, "funcname")))
+ if (!strcmp(type, "funcname"))
return parse_funcname(&drv->funcname, k, v, 0);
- if ((drv = parse_driver(k, v, "xfuncname")))
+ if (!strcmp(type, "xfuncname"))
return parse_funcname(&drv->funcname, k, v, REG_EXTENDED);
- if ((drv = parse_driver(k, v, "binary")))
+ if (!strcmp(type, "binary"))
return parse_tristate(&drv->binary, k, v);
- if ((drv = parse_driver(k, v, "command")))
+ if (!strcmp(type, "command"))
return git_config_string(&drv->external, k, v);
- if ((drv = parse_driver(k, v, "textconv")))
+ if (!strcmp(type, "textconv"))
return git_config_string(&drv->textconv, k, v);
- if ((drv = parse_driver(k, v, "cachetextconv")))
+ if (!strcmp(type, "cachetextconv"))
return parse_bool(&drv->textconv_want_cache, k, v);
- if ((drv = parse_driver(k, v, "wordregex")))
+ if (!strcmp(type, "wordregex"))
return git_config_string(&drv->word_regex, k, v);
return 0;
--
1.8.1.rc1.10.g7d71f7b
next prev parent reply other threads:[~2013-01-14 15:04 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-13 17:42 [PATCH] archive-tar: fix sanity check in config parsing René Scharfe
2013-01-13 20:00 ` Jeff King
2013-01-14 8:17 ` Joachim Schmitz
2013-01-14 12:44 ` Jeff King
2013-01-14 14:58 ` Jeff King
2013-01-14 15:00 ` [PATCH 1/6] config: add helper function for parsing key names Jeff King
2013-01-14 18:08 ` Junio C Hamano
2013-01-15 16:04 ` Jeff King
2013-01-15 17:07 ` Junio C Hamano
2013-01-18 20:53 ` Junio C Hamano
2013-01-23 6:21 ` [PATCHv2 0/8] config key-parsing cleanups Jeff King
2013-01-23 6:23 ` [PATCHv2 1/8] config: add helper function for parsing key names Jeff King
2013-01-23 6:23 ` [PATCHv2 2/8] archive-tar: use parse_config_key when parsing config Jeff King
2013-01-23 6:24 ` [PATCHv2 3/8] convert some config callbacks to parse_config_key Jeff King
2013-01-23 6:25 ` [PATCHv2 4/8] userdiff: drop parse_driver function Jeff King
2013-01-23 6:25 ` [PATCHv2 5/8] submodule: use parse_config_key when parsing config Jeff King
2013-01-23 20:45 ` Jens Lehmann
2013-01-23 6:26 ` [PATCHv2 6/8] submodule: simplify memory handling in config parsing Jeff King
2013-01-23 20:51 ` Jens Lehmann
2013-01-23 6:27 ` [PATCHv2 7/8] help: use parse_config_key for man config Jeff King
2013-01-23 6:27 ` [PATCHv2 8/8] reflog: use parse_config_key in config callback Jeff King
2013-01-23 7:04 ` Junio C Hamano
2013-01-23 7:27 ` [PATCHv2 0/8] config key-parsing cleanups Jonathan Nieder
2013-01-14 15:02 ` [PATCH 2/6] archive-tar: use match_config_key when parsing config Jeff King
2013-01-14 15:03 ` [PATCH 3/6] convert some config callbacks to match_config_key Jeff King
2013-01-14 16:55 ` Jonathan Nieder
2013-01-14 17:06 ` Jeff King
2013-01-14 18:05 ` Jeff King
2013-01-14 15:04 ` Jeff King [this message]
2013-01-14 15:04 ` [PATCH 5/6] submodule: use match_config_key when parsing config Jeff King
2013-01-14 15:07 ` [PATCH 6/6] submodule: simplify memory handling in config parsing Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130114150414.GD16828@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jojo@schmitz-digital.de \
--cc=rene.scharfe@lsrfire.ath.cx \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).