add_sought_entry_mem: convert to struct object_id

Convert this function to use struct object_id. Express several hardcoded constants in terms of GIT_SHA1_HEXSZ. 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 854ecb9cadde1063883e2a74ae6b8ea46c0a451a
1 file changed +8 -6
builtin/fetch-pack.c
+8 -6
@@ -14,12 +14,14 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
14 const char *name, int namelen)
15 {
16 struct ref *ref = xcalloc(1, sizeof(*ref) + namelen + 1);
17 - unsigned char sha1[20];
18 -
19 - if (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) {
20 - hashcpy(ref->old_oid.hash, sha1);
21 - name += 41;
22 - namelen -= 41;
17 + struct object_id oid;
18 + const int chunksz = GIT_SHA1_HEXSZ + 1;
19 +
20 + if (namelen > chunksz && name[chunksz - 1] == ' ' &&
21 + !get_oid_hex(name, &oid)) {
22 + oidcpy(&ref->old_oid, &oid);
23 + name += chunksz;
24 + namelen -= chunksz;
25 }
26
27 memcpy(ref->name, name, namelen);