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

[PATCH 3/7] sha1_name: remove upstream_mark()

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
May 23, 2013, 15:12 UTC
Message-ID
<1369321970-7759-4-git-send-email-artagnon@gmail.com>
In-Reply-To
<1369321970-7759-1-git-send-email-artagnon@gmail.com>

The first caller get_sha1_basic() just wants to make sure that no non-numerical @{...} form was matched, so that it can proceed with processing numerical @{...} forms. Since we're going to introduce more non-numerical @{...} forms, replace this upstream_mark() call with a call to at_mark() passing NULL as the last argument; we don't care what the kind is: all we need to know is if the return value is zero (parse failure).

The second caller interpret_branch_name() will be expanded in the future to handle all possible AT_KIND_* values. So, replace the upstream_mark() call with an upstream_mark() call capturing at_kind and using it in a switch statement to perform the appropriate action.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 sha1_name.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 7aabd94..106716e 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -443,15 +443,6 @@ static inline int at_mark(const char *string, int len, int *kind)
 	return 0;
 }
 
-static inline int upstream_mark(const char *string, int len)
-{
-	int suffix_len, kind;
-	suffix_len = at_mark(string, len, &kind);
-	if (suffix_len && kind == AT_KIND_UPSTREAM)
-		return suffix_len;
-	return 0;
-}
-
 static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags);
 
 static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
@@ -469,7 +460,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 	if (len && str[len-1] == '}') {
 		for (at = len-2; at >= 0; at--) {
 			if (str[at] == '@' && str[at+1] == '{') {
-				if (!upstream_mark(str + at, len - at)) {
+				if (!at_mark(str + at, len - at, NULL)) {
 					reflog_len = (len-1) - (at+2);
 					len = at;
 				}
@@ -1044,6 +1035,7 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
 	int namelen = strlen(name);
 	int len = interpret_nth_prior_checkout(name, buf);
 	int tmp_len;
+	int at_kind;
 
 	if (!len)
 		return len; /* syntax Ok, not enough switches */
@@ -1072,15 +1064,21 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
 	cp = strchr(name, '@');
 	if (!cp)
 		return -1;
-	tmp_len = upstream_mark(cp, namelen - (cp - name));
+	tmp_len = at_mark(cp, namelen - (cp - name), &at_kind);
 	if (!tmp_len)
 		return -1;
 	len = cp + tmp_len - name;
 	cp = xstrndup(name, cp - name);
 	branch = branch_get(*cp ? cp : NULL);
-	die_no_upstream(branch, cp);
-	free(cp);
-	cp = shorten_unambiguous_ref(branch->merge[0]->dst, 0);
+
+	switch (at_kind) {
+	case AT_KIND_UPSTREAM:
+		die_no_upstream(branch, cp);
+		free(cp);
+		cp = shorten_unambiguous_ref(branch->merge[0]->dst, 0);
+		break;
+	}
+
 	strbuf_reset(buf);
 	strbuf_addstr(buf, cp);
 	free(cp);
-- 
1.8.3.rc3.17.gd95ec6c.dirty
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 4 of 17 in “Let's get that @{push}!”
  1. 0/7 Let's get that @{push}!Ramkumar Ramachandra, May 23, 2013
  2. 1/7 sha1_name: abstract upstream_mark() logicRamkumar Ramachandra, May 23, 2013
  3. 2/7 sha1_name: factor out die_no_upstream()Ramkumar Ramachandra, May 23, 2013
  4. 3/7 sha1_name: remove upstream_mark()Ramkumar Ramachandra, May 23, 2013
  5. 4/7 remote: expose parse_push_refspec()Ramkumar Ramachandra, May 23, 2013
  6. 5/7 remote: expose get_ref_match()Ramkumar Ramachandra, May 23, 2013
  7. 6/7 sha1_name: prepare to introduce AT_KIND_PUSHRamkumar Ramachandra, May 23, 2013
  8. Felipe ContrerasMay 24, 2013
  9. Ramkumar RamachandraMay 24, 2013
  10. 7/7 sha1_name: implement finding @{push}Ramkumar Ramachandra, May 23, 2013
  11. Duy NguyenMay 24, 2013
  12. Ramkumar RamachandraMay 24, 2013
  13. Duy NguyenMay 24, 2013
  14. Ramkumar RamachandraMay 24, 2013
  15. Junio C HamanoMay 24, 2013
  16. Ramkumar RamachandraMay 24, 2013
  17. Junio C HamanoMay 24, 2013

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.