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

[PATCH 3/5] sha1_name: move interpret_nth_prior_checkout closer to interpret_branch_name

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Dec 24, 2010, 14:07 UTC
Message-ID
<1293199669-19016-4-git-send-email-pclouds@gmail.com>
In-Reply-To
<1293199669-19016-1-git-send-email-pclouds@gmail.com>

interpret_nth_prior_checkout() is a subfunction of interpret_branch_name(). So it's better to let them be close together (i.e. not letting get_sha1_mb() stays in between).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1_name.c |   84 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 3a98a50..dcdf1e6 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -883,6 +883,48 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
 	return 0;
 }
 
+int get_sha1_mb(const char *name, unsigned char *sha1)
+{
+	struct commit *one, *two;
+	struct commit_list *mbs;
+	unsigned char sha1_tmp[20];
+	const char *dots;
+	int st;
+
+	dots = strstr(name, "...");
+	if (!dots)
+		return get_sha1(name, sha1);
+	if (dots == name)
+		st = get_sha1("HEAD", sha1_tmp);
+	else {
+		struct strbuf sb;
+		strbuf_init(&sb, dots - name);
+		strbuf_add(&sb, name, dots - name);
+		st = get_sha1(sb.buf, sha1_tmp);
+		strbuf_release(&sb);
+	}
+	if (st)
+		return st;
+	one = lookup_commit_reference_gently(sha1_tmp, 0);
+	if (!one)
+		return -1;
+
+	if (get_sha1(dots[3] ? (dots + 3) : "HEAD", sha1_tmp))
+		return -1;
+	two = lookup_commit_reference_gently(sha1_tmp, 0);
+	if (!two)
+		return -1;
+	mbs = get_merge_bases(one, two, 1);
+	if (!mbs || mbs->next)
+		st = -1;
+	else {
+		st = 0;
+		hashcpy(sha1, mbs->item->object.sha1);
+	}
+	free_commit_list(mbs);
+	return st;
+}
+
 /*
  * Parse @{-N} syntax, return the number of characters parsed
  * if successful; otherwise signal an error with negative value.
@@ -931,48 +973,6 @@ release_return:
 	return retval;
 }
 
-int get_sha1_mb(const char *name, unsigned char *sha1)
-{
-	struct commit *one, *two;
-	struct commit_list *mbs;
-	unsigned char sha1_tmp[20];
-	const char *dots;
-	int st;
-
-	dots = strstr(name, "...");
-	if (!dots)
-		return get_sha1(name, sha1);
-	if (dots == name)
-		st = get_sha1("HEAD", sha1_tmp);
-	else {
-		struct strbuf sb;
-		strbuf_init(&sb, dots - name);
-		strbuf_add(&sb, name, dots - name);
-		st = get_sha1(sb.buf, sha1_tmp);
-		strbuf_release(&sb);
-	}
-	if (st)
-		return st;
-	one = lookup_commit_reference_gently(sha1_tmp, 0);
-	if (!one)
-		return -1;
-
-	if (get_sha1(dots[3] ? (dots + 3) : "HEAD", sha1_tmp))
-		return -1;
-	two = lookup_commit_reference_gently(sha1_tmp, 0);
-	if (!two)
-		return -1;
-	mbs = get_merge_bases(one, two, 1);
-	if (!mbs || mbs->next)
-		st = -1;
-	else {
-		st = 0;
-		hashcpy(sha1, mbs->item->object.sha1);
-	}
-	free_commit_list(mbs);
-	return st;
-}
-
 /*
  * This reads short-hand syntax that not only evaluates to a commit
  * object name, but also can act as if the end user spelled the name
-- 
1.7.3.3.476.g10a82
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 4 of 6 in “Custom extended SHA-1 syntax”
  1. 0/5 Custom extended SHA-1 syntaxNguyễn Thái Ngọc Duy, Dec 24, 2010
  2. 1/5 alias: add functions to do param substitution and alias runningNguyễn Thái Ngọc Duy, Dec 24, 2010
  3. 2/5 get_sha1: allow custom SHA-1 mapping with $SHA1^{~alias} syntaxNguyễn Thái Ngọc Duy, Dec 24, 2010
  4. 3/5 sha1_name: move interpret_nth_prior_checkout closer to interpret_branch_nameNguyễn Thái Ngọc Duy, Dec 24, 2010
  5. 4/5 interpret_branch_name: takes @{u} code out and reorder the functionNguyễn Thái Ngọc Duy, Dec 24, 2010
  6. 5/5 get_sha1: allow custom ref mapping with $ref@{~alias} syntaxNguyễn Thái Ngọc Duy, Dec 24, 2010

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.