summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2015-02-21 20:51:28 +0100
committerJunio C Hamano <gitster@pobox.com>2015-02-22 12:01:37 -0800
commit008d5d005d862d9b0309af94dfc266e3b06bdf6d (patch)
tree39b28e6863a17274972a08d19f99b232fd29e766
parent2ae7f90f263760abd242501471f123632395d7b3 (diff)
downloadgit-008d5d005d862d9b0309af94dfc266e3b06bdf6d.tar.gz
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>
-rw-r--r--builtin/for-each-ref.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 47bd624696..9463dca196 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -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;
}