Skip to content

Commit 3dbe9db

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent adfe5d0 commit 3dbe9db

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

builtin/for-each-ref.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,12 @@ static void populate_value(struct refinfo *ref)
659659
else if (starts_with(name, "symref"))
660660
refname = ref->symref ? ref->symref : "";
661661
else if (starts_with(name, "upstream")) {
662+
const char *branch_name;
662663
/* 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))
664666
continue;
665-
branch = branch_get(ref->refname + 11);
667+
branch = branch_get(branch_name);
666668

667669
refname = branch_get_upstream(branch, NULL);
668670
if (!refname)

0 commit comments

Comments
 (0)