for-each-ref: use skip_prefix instead of starts_with
authorJeff King <peff@peff.net>
Thu, 21 May 2015 04:45:51 +0000 (00:45 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 May 2015 16:33:08 +0000 (09:33 -0700)
This saves us having to maintain a magic number to skip past
the matched prefix.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/for-each-ref.c
index 92bd2b26654262da24523dd5f98f3741df64de1e..2bd19caa9cbe62d197b745d24670859d0a16ac20 100644 (file)
@@ -659,10 +659,12 @@ static void populate_value(struct refinfo *ref)
                else if (starts_with(name, "symref"))
                        refname = ref->symref ? ref->symref : "";
                else if (starts_with(name, "upstream")) {
+                       const char *branch_name;
                        /* only local branches may have an upstream */
-                       if (!starts_with(ref->refname, "refs/heads/"))
+                       if (!skip_prefix(ref->refname, "refs/heads/",
+                                        &branch_name))
                                continue;
-                       branch = branch_get(ref->refname + 11);
+                       branch = branch_get(branch_name);
 
                        refname = branch_get_upstream(branch, NULL);
                        if (!refname)