Skip to content

Commit 854ecb9

Browse files
bk2204peff
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent f4e54d0 commit 854ecb9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

builtin/fetch-pack.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
1414
const char *name, int namelen)
1515
{
1616
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;
2325
}
2426

2527
memcpy(ref->name, name, namelen);

0 commit comments

Comments
 (0)