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

[PATCH 1/6 (v2)] get_remote_heads(): refactor code to read "server capabilities"

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 1, 2008, 14:12 UTC
Message-ID
<1228140775-29212-2-git-send-email-gitster@pobox.com>
In-Reply-To
<1228140775-29212-1-git-send-email-gitster@pobox.com>

This just moves the code to read the server capability list that is hidden after "40-byte hex object name, SP, refname, NUL" on the information the uploading end initially sends.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 connect.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/connect.c b/connect.c
index 584e04c..932c503 100644
--- a/connect.c
+++ b/connect.c
@@ -49,6 +49,21 @@ static void add_extra_have(struct extra_have_objects *extra, unsigned char *sha1
 }
 
 /*
+ * "line" points at the byte just after "40-byte hex, SP, refname,
+ * NUL".  "len" is the remaining number of bytes.  The caller knows
+ * that the original packet contains more information than that.
+ */
+static void read_extra_info(char *line, int len)
+{
+	/*
+	 * The first such "extra" piece of information is the list of
+	 * server capabilities.
+	 */
+	free(server_capabilities);
+	server_capabilities = xstrdup(line);
+}
+
+/*
  * Read all the refs from the other end
  */
 struct ref **get_remote_heads(int in, struct ref **list,
@@ -78,10 +93,8 @@ struct ref **get_remote_heads(int in, struct ref **list,
 		name = buffer + 41;
 
 		name_len = strlen(name);
-		if (len != name_len + 41) {
-			free(server_capabilities);
-			server_capabilities = xstrdup(name + name_len + 1);
-		}
+		if (len != name_len + 41)
+			read_extra_info(name + name_len + 1, len - (name_len + 41));
 
 		if (extra_have &&
 		    name_len == 5 && !memcmp(".have", name, 5)) {
-- 
1.6.0.4.864.g0f47a
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 17 in “Detecting HEAD more reliably while cloning”
  1. 0/6 Detecting HEAD more reliably while cloningJunio C Hamano, Dec 1, 2008
  2. 1/6 get_remote_heads(): refactor code to read "server capabilities"Junio C Hamano, Dec 1, 2008
  3. 2/6 connect.c::read_extra_info(): prepare to receive more than server capabilitiesJunio C Hamano, Dec 1, 2008
  4. 3/6 connect.c::read_extra_info(): find where HEAD points atJunio C Hamano, Dec 1, 2008
  5. 4/6 clone: find the current branch more explicitlyJunio C Hamano, Dec 1, 2008
  6. 5/6 upload-pack: send the HEAD informationJunio C Hamano, Dec 1, 2008
  7. 6/6 clone: test the new HEAD detection logicJunio C Hamano, Dec 1, 2008
  8. Jakub NarebskiDec 1, 2008
  9. Shawn O. PearceDec 1, 2008
  10. Junio C HamanoDec 1, 2008
  11. Jeff KingDec 1, 2008
  12. Junio C HamanoDec 2, 2008
  13. Jeff KingDec 2, 2008
  14. Junio C HamanoDec 2, 2008
  15. Jeff KingDec 2, 2008
  16. Johannes SixtDec 1, 2008
  17. Junio C HamanoDec 2, 2008

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.