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

[PATCH 6/8] parse_fetch: convert to use struct object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 9, 2015, 16:28 UTC
Message-ID
<1433867316-663554-7-git-send-email-sandals@crustytoothpaste.net>
In-Reply-To
<1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net>

Convert the parse_fetch function to use struct object_id. Switch from get_sha1_hex to parse_oid_hex to avoid hard-coding constants. Remove the strlen check as parse_oid_hex will fail safely on receiving a too-short NUL-terminated string.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 remote-curl.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index 80cb4c7..46206a0 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -802,19 +802,20 @@ static void parse_fetch(struct strbuf *buf)
 		if (skip_prefix(buf->buf, "fetch ", &p)) {
 			const char *name;
 			struct ref *ref;
-			unsigned char old_sha1[20];
+			struct object_id old_oid;
+			int hexlen;
 
-			if (strlen(p) < 40 || get_sha1_hex(p, old_sha1))
+			if (!(hexlen = parse_oid_hex(p, -1, &old_oid)))
 				die("protocol error: expected sha/ref, got %s'", p);
-			if (p[40] == ' ')
-				name = p + 41;
-			else if (!p[40])
+			if (p[hexlen] == ' ')
+				name = p + hexlen + 1;
+			else if (!p[hexlen])
 				name = "";
 			else
 				die("protocol error: expected sha/ref, got %s'", p);
 
 			ref = alloc_ref(name);
-			hashcpy(ref->old_oid.hash, old_sha1);
+			oidcpy(&ref->old_oid, &old_oid);
 
 			*list = ref;
 			list = &ref->next;
-- 
2.4.0
Previous: brian m. carlsonNext: brian m. carlson
Message 11 of 23 in “object_id part 2”
  1. 0/8 object_id part 2brian m. carlson, Jun 9, 2015
  2. 1/8 refs: convert some internal functions to use object_idbrian m. carlson, Jun 9, 2015
  3. 2/8 sha1_file: introduce has_object_file helper.brian m. carlson, Jun 9, 2015
  4. Duy NguyenJun 10, 2015
  5. brian m. carlsonJun 10, 2015
  6. 3/8 Convert struct ref to use object_id.brian m. carlson, Jun 9, 2015
  7. Michael HaggertyJun 11, 2015
  8. 4/8 Add a utility function to make parsing hex values easier.brian m. carlson, Jun 9, 2015
  9. Michael HaggertyJun 11, 2015
  10. 5/8 add_sought_entry_mem: convert to struct object_idbrian m. carlson, Jun 9, 2015
  11. 6/8 parse_fetch: convert to use struct object_idbrian m. carlson, Jun 9, 2015
  12. 7/8 ref_newer: convert to use struct object_idbrian m. carlson, Jun 9, 2015
  13. Junio C HamanoJun 10, 2015
  14. brian m. carlsonJun 10, 2015
  15. brian m. carlsonJun 11, 2015
  16. Junio C HamanoJun 11, 2015
  17. brian m. carlsonJun 11, 2015
  18. Junio C HamanoJun 11, 2015
  19. brian m. carlsonJun 12, 2015
  20. Junio C HamanoJun 12, 2015
  21. brian m. carlsonJun 12, 2015
  22. Michael HaggertyJun 13, 2015
  23. brian m. carlsonJun 13, 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.