Skip to content

Commit

Permalink
for-each-ref: use skip_prefix instead of starts_with
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed May 22, 2015
1 parent adfe5d0 commit 3dbe9db
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions builtin/for-each-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3dbe9db

Please sign in to comment.