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

[PATCH] name-rev: use skip_prefix() instead of starts_with()

From
René Scharfe <l.s.r@web.de>
Date
Nov 26, 2019, 15:23 UTC
Message-ID
<23925fba-9413-0596-b21a-f49aac922f88@web.de>
Let skip_prefix() advance refname to get rid of two magic numbers.
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/name-rev.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index b0f0776947..c261d661d7 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -161,10 +161,8 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
 {
 	if (shorten_unambiguous)
 		refname = shorten_unambiguous_ref(refname, 0);
-	else if (starts_with(refname, "refs/heads/"))
-		refname = refname + 11;
-	else if (starts_with(refname, "refs/"))
-		refname = refname + 5;
+	else if (!skip_prefix(refname, "refs/heads/", &refname))
+		skip_prefix(refname, "refs/", &refname);
 	return refname;
 }

--
2.24.0
Next: Jeff King
Message 1 of 2 in “name-rev: use skip_prefix() instead of starts_with()”
  1. name-rev: use skip_prefix() instead of starts_with()René Scharfe, Nov 26, 2019
  2. Jeff KingNov 26, 2019

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.