for-each-ref: use skip_prefix() to avoid duplicate string comparison

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>

René Scharfe committed Feb 21, 2015 at 20:51 UTC 008d5d005d862d9b0309af94dfc266e3b06bdf6d
1 file changed +3 -4
builtin/for-each-ref.c
+3 -4
@@ -180,11 +180,10 @@ static const char *find_next(const char *cp)
180 static int verify_format(const char *format)
181 {
182 const char *cp, *sp;
183 - static const char color_reset[] = "color:reset";
183
184 need_color_reset_at_eol = 0;
185 for (cp = format; *cp && (sp = find_next(cp)); ) {
187 - const char *ep = strchr(sp, ')');
186 + const char *color, *ep = strchr(sp, ')');
187 int at;
188
189 if (!ep)
@@ -193,8 +192,8 @@ static int verify_format(const char *format)
192 at = parse_atom(sp + 2, ep);
193 cp = ep + 1;
194
196 - if (starts_with(used_atom[at], "color:"))
197 - need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
195 + if (skip_prefix(used_atom[at], "color:", &color))
196 + need_color_reset_at_eol = !!strcmp(color, "reset");
197 }
198 return 0;
199 }