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

[PATCH v4 05/12] get_remote_heads: convert to struct object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Nov 10, 2015, 02:22 UTC
Message-ID
<1447122150-672570-6-git-send-email-sandals@crustytoothpaste.net>
In-Reply-To
<1447122150-672570-1-git-send-email-sandals@crustytoothpaste.net>

Replace an unsigned char array with struct object_id and express several hard-coded constants in terms of GIT_SHA1_HEXSZ.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 connect.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/connect.c b/connect.c
index d13a10a9..fd7ffe18 100644
--- a/connect.c
+++ b/connect.c
@@ -120,7 +120,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
 	*list = NULL;
 	for (;;) {
 		struct ref *ref;
-		unsigned char old_sha1[20];
+		struct object_id old_oid;
 		char *name;
 		int len, name_len;
 		char *buffer = packet_buffer;
@@ -139,34 +139,36 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
 		if (len > 4 && skip_prefix(buffer, "ERR ", &arg))
 			die("remote error: %s", arg);
 
-		if (len == 48 && skip_prefix(buffer, "shallow ", &arg)) {
-			if (get_sha1_hex(arg, old_sha1))
+		if (len == GIT_SHA1_HEXSZ + strlen("shallow ") &&
+			skip_prefix(buffer, "shallow ", &arg)) {
+			if (get_oid_hex(arg, &old_oid))
 				die("protocol error: expected shallow sha-1, got '%s'", arg);
 			if (!shallow_points)
 				die("repository on the other end cannot be shallow");
-			sha1_array_append(shallow_points, old_sha1);
+			sha1_array_append(shallow_points, old_oid.hash);
 			continue;
 		}
 
-		if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
+		if (len < GIT_SHA1_HEXSZ + 2 || get_oid_hex(buffer, &old_oid) ||
+			buffer[GIT_SHA1_HEXSZ] != ' ')
 			die("protocol error: expected sha/ref, got '%s'", buffer);
-		name = buffer + 41;
+		name = buffer + GIT_SHA1_HEXSZ + 1;
 
 		name_len = strlen(name);
-		if (len != name_len + 41) {
+		if (len != name_len + GIT_SHA1_HEXSZ + 1) {
 			free(server_capabilities);
 			server_capabilities = xstrdup(name + name_len + 1);
 		}
 
 		if (extra_have && !strcmp(name, ".have")) {
-			sha1_array_append(extra_have, old_sha1);
+			sha1_array_append(extra_have, old_oid.hash);
 			continue;
 		}
 
 		if (!check_ref(name, flags))
 			continue;
-		ref = alloc_ref(buffer + 41);
-		hashcpy(ref->old_oid.hash, old_sha1);
+		ref = alloc_ref(buffer + GIT_SHA1_HEXSZ + 1);
+		oidcpy(&ref->old_oid, &old_oid);
 		*list = ref;
 		list = &ref->next;
 		got_at_least_one_head = 1;
-- 
2.6.2.409.gb049f0a
Previous: brian m. carlsonNext: brian m. carlson
Message 6 of 15 in “object_id part 2”
  1. 00/12 object_id part 2brian m. carlson, Nov 10, 2015
  2. 01/12 sha1_file: introduce has_object_file helper.brian m. carlson, Nov 10, 2015
  3. 02/12 Convert struct ref to use object_id.brian m. carlson, Nov 10, 2015
  4. 03/12 add_sought_entry_mem: convert to struct object_idbrian m. carlson, Nov 10, 2015
  5. 04/12 parse_fetch: convert to use struct object_idbrian m. carlson, Nov 10, 2015
  6. 05/12 get_remote_heads: convert to struct object_idbrian m. carlson, Nov 10, 2015
  7. 06/12 push_refs_with_export: convert to struct object_idbrian m. carlson, Nov 10, 2015
  8. 07/12 ref_newer: convert to use struct object_idbrian m. carlson, Nov 10, 2015
  9. 08/12 object: introduce get_object_hash macro.brian m. carlson, Nov 10, 2015
  10. 09/12 Add several uses of get_object_hash.brian m. carlson, Nov 10, 2015
  11. Jeff KingNov 20, 2015
  12. brian m. carlsonNov 20, 2015
  13. 10/12 Convert struct object to object_idbrian m. carlson, Nov 10, 2015
  14. 11/12 Remove get_object_hash.brian m. carlson, Nov 10, 2015
  15. 12/12 remote: convert functions to struct object_idbrian m. carlson, Nov 10, 2015

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.