git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Michael HaggertyNext: Michael Haggerty
Message 4 of 7 in “Add a function skip_prefix_if_present()”
  1. 0/3 Add a function skip_prefix_if_present()Michael Haggerty, Feb 5, 2014
  2. 1/3 Add and use a function skip_prefix_if_present()Michael Haggerty, Feb 5, 2014
  3. 2/3 diff_scoreopt_parse(): use skip_prefix_if_present()Michael Haggerty, Feb 5, 2014
  4. 3/3 rev_is_head(): use skip_prefix()Michael Haggerty, Feb 5, 2014
  5. Michael HaggertyFeb 5, 2014
  6. Jeff KingFeb 5, 2014
  7. Duy NguyenFeb 6, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.