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

[PATCH v4 7/8] sha1_name: simplify track finding

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 20, 2014, 19:45 UTC
Message-ID
<1398023106-25958-8-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1398023106-25958-1-git-send-email-felipe.contreras@gmail.com>
It's more efficient to check for the braces first.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 sha1_name.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 906f09d..aa3f3e0 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -417,7 +417,7 @@ static int ambiguous_path(const char *path, int len)
 
 static inline int upstream_mark(const char *string, int len)
 {
-	const char *suffix[] = { "@{upstream}", "@{u}" };
+	const char *suffix[] = { "upstream", "u" };
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(suffix); i++) {
@@ -475,7 +475,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 					nth_prior = 1;
 					continue;
 				}
-				if (!upstream_mark(str + at, len - at)) {
+				if (!upstream_mark(str + at + 2, len - at - 3)) {
 					reflog_len = (len-1) - (at+2);
 					len = at;
 				}
@@ -1089,7 +1089,10 @@ static int interpret_upstream_mark(const char *name, int namelen,
 {
 	int len;
 
-	len = upstream_mark(name + at, namelen - at);
+	if (name[at + 1] != '{' || name[namelen - 1] != '}')
+		return -1;
+
+	len = upstream_mark(name + at + 2, namelen - at - 3);
 	if (!len)
 		return -1;
 
@@ -1097,7 +1100,7 @@ static int interpret_upstream_mark(const char *name, int namelen,
 		return -1;
 
 	set_shortened_ref(buf, get_upstream_branch(name, at));
-	return len + at;
+	return len + at + 3;
 }
 
 /*
-- 
1.9.1+fc3.9.gc73078e
Previous: Felipe ContrerasNext: Felipe Contreras
Message 8 of 9 in “Introduce publish tracking branch”
  1. 0/8 Introduce publish tracking branchFelipe Contreras, Apr 20, 2014
  2. 1/8 t5516 (fetch-push): fix test restorationFelipe Contreras, Apr 20, 2014
  3. 2/8 Add concept of 'publish' branchFelipe Contreras, Apr 20, 2014
  4. 3/8 branch: add --set-publish-to optionFelipe Contreras, Apr 20, 2014
  5. 4/8 push: add --set-publish optionFelipe Contreras, Apr 20, 2014
  6. 5/8 branch: display publish branchFelipe Contreras, Apr 20, 2014
  7. 6/8 sha1_name: cleanup interpret_branch_name()Felipe Contreras, Apr 20, 2014
  8. 7/8 sha1_name: simplify track findingFelipe Contreras, Apr 20, 2014
  9. 8/8 sha1_name: add support for @{publish} marksFelipe Contreras, Apr 20, 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.