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

[PATCH 5/5] remote: use exact HEAD lookup if it is available

From
Jeff King <peff@peff.net>
Date
Feb 15, 2009, 06:18 UTC
Message-ID
<20090215061818.GE30414@coredump.intra.peff.net>
In-Reply-To
<20090215060815.GA7473@coredump.intra.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>
---
A possible 6/5 would be to do something similar for local repos (or
resurrecting the HEAD proposal).
 remote.c              |   10 ++++++++++
 t/t5550-http-fetch.sh |   11 +++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/remote.c b/remote.c
index 7ba1bff..a96a910 100644
--- a/remote.c
+++ b/remote.c
@@ -1395,6 +1395,16 @@ 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) {
+		r = find_ref_by_name(refs, head->symref);
+		return r ? copy_ref_with_peer(r) : NULL;
+	}
+
 	/* If refs/heads/master could be right, it is. */
 	if (!all) {
 		const struct ref *m;
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.rc0.256.gf004c.dirty
Previous: Jeff KingNext: Jay Soffian
Message 30 of 41 in “remote HEAD improvements take 2”
  1. 0/4 remote HEAD improvements take 2Jay Soffian, Feb 13, 2009
  2. 1/4 builtin-clone: move locate_head() to remote.c so it can be re-usedJay Soffian, Feb 13, 2009
  3. 2/4 builtin-remote: move duplicated cleanup code its own functionJay Soffian, Feb 13, 2009
  4. 3/4 builtin-remote: teach show to display remote HEADJay Soffian, Feb 13, 2009
  5. 4/4 builtin-remote: add set-head verbJay Soffian, Feb 13, 2009
  6. Junio C HamanoFeb 13, 2009
  7. Jay SoffianFeb 13, 2009
  8. 4/4 builtin-remote: add set-head subcommandJay Soffian, Feb 13, 2009
  9. Junio C HamanoFeb 13, 2009
  10. Jay SoffianFeb 13, 2009
  11. Jeff KingFeb 14, 2009
  12. Junio C HamanoFeb 14, 2009
  13. Jeff KingFeb 14, 2009
  14. Jay SoffianFeb 14, 2009
  15. Jay SoffianFeb 14, 2009
  16. Jeff KingFeb 14, 2009
  17. builtin-remote: better handling of multiple remote HEADsJay Soffian, Feb 14, 2009
  18. Jeff KingFeb 14, 2009
  19. Jay SoffianFeb 14, 2009
  20. Jeff KingFeb 14, 2009
  21. Junio C HamanoFeb 14, 2009
  22. Daniel BarkalowFeb 14, 2009
  23. Jeff KingFeb 14, 2009
  24. Jeff KingFeb 15, 2009
  25. 1/5 test scripts: refactor start_httpd helperJeff King, Feb 15, 2009
  26. 2/5 add basic http clone/fetch testsJeff King, Feb 15, 2009
  27. Junio C HamanoFeb 15, 2009
  28. 3/5 refactor find_refs_by_name to accept const listJeff King, Feb 15, 2009
  29. 4/5 remote: refactor guess_remote_headJeff King, Feb 15, 2009
  30. 5/5 remote: use exact HEAD lookup if it is availableJeff King, Feb 15, 2009
  31. Jay SoffianFeb 15, 2009
  32. Jeff KingFeb 15, 2009
  33. 1/2 transport: cleanup duplicated ref fetching codeJeff King, Feb 15, 2009
  34. 2/2 transport: unambiguously determine local HEADJeff King, Feb 15, 2009
  35. Jeff KingFeb 15, 2009
  36. Jeff KingFeb 15, 2009
  37. Jay SoffianFeb 15, 2009
  38. Jeff KingFeb 15, 2009
  39. Junio C HamanoFeb 16, 2009
  40. Jay SoffianFeb 16, 2009
  41. Jay SoffianFeb 13, 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.