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

[PATCH 19/21] remote: make guess_remote_head() use exact HEAD lookup if it is available

From
Jay Soffian <jaysoffian@gmail.com>
Date
Feb 27, 2009, 19:10 UTC
Message-ID
<710d1a0d6059e6dee31732c2762aed7e909daad7.1235759631.git.jaysoffian@gmail.com>
In-Reply-To
<9d146489b82f3f8108903dcb9acbe569a4b690a1.1235759631.git.jaysoffian@gmail.com>
From: Jeff King <peff@peff.net>

Our usual method for determining the ref pointed to by HEAD is to compare HEAD's sha1 to the sha1 of all refs, trying to find a unique match.

However, some transports actually get to look at HEAD directly; we should make use of that information when it is available. Currently, only http remotes support this feature.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
This patch replaces 19/21 in the original series
series - http://article.gmane.org/gmane.comp.version-control.git/111394
 remote.c              |    8 ++++++++
 t/t5550-http-fetch.sh |   11 +++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/remote.c b/remote.c
index 2123005..9b8522d 100644
--- a/remote.c
+++ b/remote.c
@@ -1476,6 +1476,14 @@ struct ref *guess_remote_head(const struct ref *head,
 	if (!head)
 		return NULL;
 
+	/*
+	 * Some transports support directly peeking at
+	 * where HEAD points; if that is the case, then
+	 * we don't have to guess.
+	 */
+	if (head->symref)
+		return copy_ref(find_ref_by_name(refs, head->symref));
+
 	/* If refs/heads/master could be right, it is. */
 	if (!all) {
 		r = find_ref_by_name(refs, "refs/heads/master");
diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh
index b6e6ec9..05b1b62 100755
--- a/t/t5550-http-fetch.sh
+++ b/t/t5550-http-fetch.sh
@@ -42,5 +42,16 @@ test_expect_success 'fetch changes via http' '
 	test_cmp file clone/file
 '
 
+test_expect_success 'http remote detects correct HEAD' '
+	git push public master:other &&
+	(cd clone &&
+	 git remote set-head origin -d &&
+	 git remote set-head origin -a &&
+	 git symbolic-ref refs/remotes/origin/HEAD > output &&
+	 echo refs/remotes/origin/master > expect &&
+	 test_cmp expect output
+	)
+'
+
 stop_httpd
 test_done
-- 
1.6.2.rc1.309.g5f417
Previous: Jay SoffianNext: Jeff King
Message 4 of 5 in “git remote: set-head and new show output (UPDATED)”
  1. 0/3 git remote: set-head and new show output (UPDATED)Jay Soffian, Feb 27, 2009
  2. remote: make copy_ref() perform a deep copyJay Soffian, Feb 27, 2009
  3. 08/21 remote: let guess_remote_head() optionally return all matchesJay Soffian, Feb 27, 2009
  4. 19/21 remote: make guess_remote_head() use exact HEAD lookup if it is availableJay Soffian, Feb 27, 2009
  5. Jeff KingFeb 28, 2009

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.