This is easier to read and avoids magic offset constants
which need to be in sync with the section-name we provide.

Signed-off-by: Jeff King <p...@peff.net>
---
 convert.c  |  6 +-----
 ll-merge.c |  6 +-----
 userdiff.c | 13 +++----------
 3 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/convert.c b/convert.c
index 6602155..e3ecb30 100644
--- a/convert.c
+++ b/convert.c
@@ -465,10 +465,8 @@ static int read_convert_config(const char *var, const char 
*value, void *cb)
         * External conversion drivers are configured using
         * "filter.<name>.variable".
         */
-       if (prefixcmp(var, "filter.") || (ep = strrchr(var, '.')) == var + 6)
+       if (match_config_key(var, "filter", &name, &namelen, &ep) < 0 || !name)
                return 0;
-       name = var + 7;
-       namelen = ep - name;
        for (drv = user_convert; drv; drv = drv->next)
                if (!strncmp(drv->name, name, namelen) && !drv->name[namelen])
                        break;
@@ -479,8 +477,6 @@ static int read_convert_config(const char *var, const char 
*value, void *cb)
                user_convert_tail = &(drv->next);
        }
 
-       ep++;
-
        /*
         * filter.<name>.smudge and filter.<name>.clean specifies
         * the command line:
diff --git a/ll-merge.c b/ll-merge.c
index acea33b..d4c4ff6 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -236,15 +236,13 @@ static int read_merge_config(const char *var, const char 
*value, void *cb)
         * especially, we do not want to look at variables such as
         * "merge.summary", "merge.tool", and "merge.verbosity".
         */
-       if (prefixcmp(var, "merge.") || (ep = strrchr(var, '.')) == var + 5)
+       if (match_config_key(var, "merge", &name, &namelen, &ep) < 0 || !name)
                return 0;
 
        /*
         * Find existing one as we might be processing merge.<name>.var2
         * after seeing merge.<name>.var1.
         */
-       name = var + 6;
-       namelen = ep - name;
        for (fn = ll_user_merge; fn; fn = fn->next)
                if (!strncmp(fn->name, name, namelen) && !fn->name[namelen])
                        break;
@@ -256,8 +254,6 @@ static int read_merge_config(const char *var, const char 
*value, void *cb)
                ll_user_merge_tail = &(fn->next);
        }
 
-       ep++;
-
        if (!strcmp("name", ep)) {
                if (!value)
                        return error("%s: lacks value", var);
diff --git a/userdiff.c b/userdiff.c
index ed958ef..1a6a0fa 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -188,20 +188,13 @@ static struct userdiff_driver *parse_driver(const char 
*var,
                const char *value, const char *type)
 {
        struct userdiff_driver *drv;
-       const char *dot;
-       const char *name;
+       const char *name, *key;
        int namelen;
 
-       if (prefixcmp(var, "diff."))
-               return NULL;
-       dot = strrchr(var, '.');
-       if (dot == var + 4)
-               return NULL;
-       if (strcmp(type, dot+1))
+       if (match_config_key(var, "diff", &name, &namelen, &key) < 0 ||
+           strcmp(type, key))
                return NULL;
 
-       name = var + 5;
-       namelen = dot - name;
        drv = userdiff_find_by_namelen(name, namelen);
        if (!drv) {
                ALLOC_GROW(drivers, ndrivers+1, drivers_alloc);
-- 
1.8.1.rc1.10.g7d71f7b

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to