for-each-ref: use skip_prefix instead of starts_with
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>
Jeff King committed
May 21, 2015 at 00:45 UTC
3dbe9db01bd9c0b0701f72a631ac15b1791f6642
1 file changed
+4
-2
builtin/for-each-ref.c
+4
-2
@@ -659,10 +659,12 @@ static void populate_value(struct refinfo *ref)
659
else if (starts_with(name, "symref"))
660
refname = ref->symref ? ref->symref : "";
661
else if (starts_with(name, "upstream")) {
662
+ const char *branch_name;
663
/* only local branches may have an upstream */
663
- if (!starts_with(ref->refname, "refs/heads/"))
664
+ if (!skip_prefix(ref->refname, "refs/heads/",
665
+ &branch_name))
666
continue;
665
- branch = branch_get(ref->refname + 11);
667
+ branch = branch_get(branch_name);
668
669
refname = branch_get_upstream(branch, NULL);
670
if (!refname)