daemon/config: factor out duplicate xstrdup_tolower
authorJeff King <peff@peff.net>
Thu, 22 May 2014 09:44:09 +0000 (05:44 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 23 May 2014 19:39:44 +0000 (12:39 -0700)
We have two implementations of the same function; let's drop
that to one. We take the name from daemon.c, but the
implementation (which is just slightly more efficient) from
the config code.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/config.c
daemon.c
strbuf.c
strbuf.h
index 20e89fe4e0c7db50267e8e9358c38faea2259fab..00b0c240fcd788edc3d33cd60f48cb49f963ff7f 100644 (file)
@@ -396,19 +396,6 @@ static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
        return 0;
 }
 
-static char *dup_downcase(const char *string)
-{
-       char *result;
-       size_t len, i;
-
-       len = strlen(string);
-       result = xmalloc(len + 1);
-       for (i = 0; i < len; i++)
-               result[i] = tolower(string[i]);
-       result[i] = '\0';
-       return result;
-}
-
 static int get_urlmatch(const char *var, const char *url)
 {
        char *section_tail;
@@ -423,7 +410,7 @@ static int get_urlmatch(const char *var, const char *url)
        if (!url_normalize(url, &config.url))
                die("%s", config.url.err);
 
-       config.section = dup_downcase(var);
+       config.section = xstrdup_tolower(var);
        section_tail = strchr(config.section, '.');
        if (section_tail) {
                *section_tail = '\0';
index 13608c07c674171ace754154c5d1cb7dea6c5e04..d514ba47ff84a407dd72025913a324d9ba77b478 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -475,14 +475,6 @@ static void make_service_overridable(const char *name, int ena)
        die("No such service %s", name);
 }
 
-static char *xstrdup_tolower(const char *str)
-{
-       char *p, *dup = xstrdup(str);
-       for (p = dup; *p; p++)
-               *p = tolower(*p);
-       return dup;
-}
-
 static void parse_host_and_port(char *hostport, char **host,
        char **port)
 {
index 1170d01c4322b494cd900853279766edd030de32..e26cb2c7fa38318d6065b7779e448c9e8e662857 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -570,3 +570,16 @@ int fprintf_ln(FILE *fp, const char *fmt, ...)
                return -1;
        return ret + 1;
 }
+
+char *xstrdup_tolower(const char *string)
+{
+       char *result;
+       size_t len, i;
+
+       len = strlen(string);
+       result = xmalloc(len + 1);
+       for (i = 0; i < len; i++)
+               result[i] = tolower(string[i]);
+       result[i] = '\0';
+       return result;
+}
index 73e80cea69b5e2965cf4ce8c36444f45aae8e19c..7bd36216ff85aca61728b06cd06e451747676257 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
@@ -177,4 +177,6 @@ extern int printf_ln(const char *fmt, ...);
 __attribute__((format (printf,2,3)))
 extern int fprintf_ln(FILE *fp, const char *fmt, ...);
 
+char *xstrdup_tolower(const char *);
+
 #endif /* STRBUF_H */