for-each-ref: use skip_prefix() to avoid duplicate string comparison
authorRené Scharfe <l.s.r@web.de>
Sat, 21 Feb 2015 19:51:28 +0000 (20:51 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Feb 2015 20:01:37 +0000 (12:01 -0800)
Use skip_prefix() to get the part after "color:" (if present) and only
compare it with "reset" instead of comparing the whole string again.
This gets rid of the duplicate "color:" part of the string constant.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/for-each-ref.c
index 47bd624696d5e94295dda8846f00dcbb80a6ca5a..9463dca196787b62aa1e5aeda89d15869ec2b349 100644 (file)
@@ -180,11 +180,10 @@ static const char *find_next(const char *cp)
 static int verify_format(const char *format)
 {
        const char *cp, *sp;
-       static const char color_reset[] = "color:reset";
 
        need_color_reset_at_eol = 0;
        for (cp = format; *cp && (sp = find_next(cp)); ) {
-               const char *ep = strchr(sp, ')');
+               const char *color, *ep = strchr(sp, ')');
                int at;
 
                if (!ep)
@@ -193,8 +192,8 @@ static int verify_format(const char *format)
                at = parse_atom(sp + 2, ep);
                cp = ep + 1;
 
-               if (starts_with(used_atom[at], "color:"))
-                       need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
+               if (skip_prefix(used_atom[at], "color:", &color))
+                       need_color_reset_at_eol = !!strcmp(color, "reset");
        }
        return 0;
 }