[PATCH 3/3] rev_is_head(): use skip_prefix()
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Feb 5, 2014, 06:25 UTC
- Message-ID
- <1391581517-8586-4-git-send-email-mhagger@alum.mit.edu>
- In-Reply-To
- <1391581517-8586-1-git-send-email-mhagger@alum.mit.edu>
Change the logic a little bit so that we can use skip_prefix() instead of doing pointer arithmetic with hardcoded numbers.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> --- builtin/show-branch.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/builtin/show-branch.c b/builtin/show-branch.c index f2c3b19..aee7fe5 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -475,14 +475,15 @@ static void snarf_refs(int head, int remotes) static int rev_is_head(const char *head, int headlen, const char *name, unsigned char *head_sha1, unsigned char *sha1) { + const char *short_name; + if ((!head[0]) || (head_sha1 && sha1 && hashcmp(head_sha1, sha1))) return 0; head = skip_prefix_if_present(head, "refs/heads/"); - if (starts_with(name, "refs/heads/")) - name += 11; - else if (starts_with(name, "heads/")) - name += 6; + if ((short_name = skip_prefix(name, "refs/heads/")) || + (short_name = skip_prefix(name, "heads/"))) + return !strcmp(head, short_name); return !strcmp(head, name); }
-- 1.8.5.3