git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Kent R. Spillner" <kspillner@acm.org>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	git@vger.kernel.org, "Michael Haggerty" <mhagger@alum.mit.edu>
Subject: [PATCH 3/3] rev_is_head(): use skip_prefix()
Date: Wed,  5 Feb 2014 07:25:17 +0100	[thread overview]
Message-ID: <1391581517-8586-4-git-send-email-mhagger@alum.mit.edu> (raw)
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

  parent reply	other threads:[~2014-02-05  6:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-05  6:25 [PATCH 0/3] Add a function skip_prefix_if_present() Michael Haggerty
2014-02-05  6:25 ` [PATCH 1/3] Add and use " Michael Haggerty
2014-02-05  6:25 ` [PATCH 2/3] diff_scoreopt_parse(): use skip_prefix_if_present() Michael Haggerty
2014-02-05  6:25 ` Michael Haggerty [this message]
2014-02-05  6:55 ` [PATCH 0/3] Add a function skip_prefix_if_present() Michael Haggerty
2014-02-05 17:26   ` Jeff King
2014-02-06 12:19   ` Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1391581517-8586-4-git-send-email-mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kspillner@acm.org \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).