parse_fetch: convert to use struct object_id
Convert the parse_fetch function to use struct object_id. Remove the strlen check as get_oid_hex will fail safely on receiving a too-short NUL-terminated string. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Jeff King <peff@peff.net>
brian m. carlson committed
Nov 10, 2015 at 02:22 UTC
8338c911d1c22a6d86d694003a1fa213cbe11bcf
1 file changed
+6
-6
remote-curl.c
+6
-6
@@ -803,19 +803,19 @@ static void parse_fetch(struct strbuf *buf)
803
if (skip_prefix(buf->buf, "fetch ", &p)) {
804
const char *name;
805
struct ref *ref;
806
- unsigned char old_sha1[20];
806
+ struct object_id old_oid;
807
808
- if (strlen(p) < 40 || get_sha1_hex(p, old_sha1))
808
+ if (get_oid_hex(p, &old_oid))
809
die("protocol error: expected sha/ref, got %s'", p);
810
- if (p[40] == ' ')
811
- name = p + 41;
812
- else if (!p[40])
810
+ if (p[GIT_SHA1_HEXSZ] == ' ')
811
+ name = p + GIT_SHA1_HEXSZ + 1;
812
+ else if (!p[GIT_SHA1_HEXSZ])
813
name = "";
814
else
815
die("protocol error: expected sha/ref, got %s'", p);
816
817
ref = alloc_ref(name);
818
- hashcpy(ref->old_oid.hash, old_sha1);
818
+ oidcpy(&ref->old_oid, &old_oid);
819
820
*list = ref;
821
list = &ref->next;