Thread (12 messages) flat view 12 messages, 3 authors, 2016-06-15
STALE3738d

Revision v1 of 4 in this series.

Revisions (4)
  1. v1 current
  2. v2 [diff vs current]
  3. v3 [diff vs current]
  4. v4 [diff vs current]

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

From: brian m. carlson <hidden>
Date: 2016-06-15 23:05:13
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help