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

[PATCH 2/2] interpret_branch_name(): unconfuse @{-1}@{u} when @{-1} is detached

From
Junio C Hamano <gitster@pobox.com>
Date
May 8, 2013, 21:18 UTC
Message-ID
<7vd2t1dvbu.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vk3n9dvlu.fsf@alter.siamese.dyndns.org>

Now interpret_nth_prior_checkout() can tell the caller if the result of expansion of @{-1} is a real branch name or the commit object name for a detached HEAD state, let's avoid re-interpreting $HEX@{u} in the latter case.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * This prevents us from mistakenly refering to the upstream of an
   unrelated branch in this sequence:
     HEX=$(git rev-parse --verify HEAD)
     git branch $HEX     
     git checkout HEAD^0
     git checkout -
     git log @{-1}@{u}
   The branch created in the first step has never been checked out,
   and @{-1} does not refer to it.  @{-1}@{u} would first turn into 
   $HEX@{u} but we should not look for upstream of refs/heads/$HEX.
 sha1_name.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 1473bb6..d3b6897 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1004,15 +1004,21 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
 	char *cp;
 	struct branch *upstream;
 	int namelen = strlen(name);
-	int len = interpret_nth_prior_checkout(name, buf, NULL);
+	int detached;
+	int len = interpret_nth_prior_checkout(name, buf, &detached);
 	int tmp_len;
 
 	if (!len)
 		return len; /* syntax Ok, not enough switches */
 	if (0 < len && len == namelen)
 		return len; /* consumed all */
-	else if (0 < len) {
-		/* we have extra data, which might need further processing */
+	else if (0 < len && !detached) {
+		/*
+		 * We have extra data, which might need further
+		 * processing.  E.g. for the original "@{-1}@{u}" we
+		 * have converted @{-1} into buf and yet to process
+		 * the remaining @{u} part.
+		 */
 		struct strbuf tmp = STRBUF_INIT;
 		int used = buf->len;
 		int ret;
-- 
1.8.3-rc1-182-gc61d106
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 7 in “sha1_name.c: signal if @{-N} was a true branch nameor a detached head”
  1. 1/2 sha1_name.c: signal if @{-N} was a true branch nameor a detached headJunio C Hamano, May 8, 2013
  2. 2/2 interpret_branch_name(): unconfuse @{-1}@{u} when @{-1} is detachedJunio C Hamano, May 8, 2013
  3. preparatory analysis of remaining @{...} issuesJunio C Hamano, May 8, 2013
  4. Jeff KingMay 9, 2013
  5. Junio C HamanoMay 9, 2013
  6. Jeff KingMay 13, 2013
  7. Eric SunshineMay 9, 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.