Skip to content

Commit d50cbe4

Browse files
ebiedermgitster
authored andcommitted
oid-array: teach oid-array to handle multiple kinds of oids
While looking at how to handle input of both SHA-1 and SHA-256 oids in get_oid_with_context, I realized that the oid_array in repo_for_each_abbrev might have more than one kind of oid stored in it simultaneously. Update to oid_array_append to ensure that oids added to an oid array always have an algorithm set. Update void_hashcmp to first verify two oids use the same hash algorithm before comparing them to each other. With that oid-array should be safe to use with different kinds of oids simultaneously. Signed-off-by: "Eric W. Biederman" <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5e9d802 commit d50cbe4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

oid-array.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ void oid_array_append(struct oid_array *array, const struct object_id *oid)
66
{
77
ALLOC_GROW(array->oid, array->nr + 1, array->alloc);
88
oidcpy(&array->oid[array->nr++], oid);
9+
if (!oid->algo)
10+
oid_set_algo(&array->oid[array->nr - 1], the_hash_algo);
911
array->sorted = 0;
1012
}
1113

12-
static int void_hashcmp(const void *a, const void *b)
14+
static int void_hashcmp(const void *va, const void *vb)
1315
{
14-
return oidcmp(a, b);
16+
const struct object_id *a = va, *b = vb;
17+
int ret;
18+
if (a->algo == b->algo)
19+
ret = oidcmp(a, b);
20+
else
21+
ret = a->algo > b->algo ? 1 : -1;
22+
return ret;
1523
}
1624

1725
void oid_array_sort(struct oid_array *array)

0 commit comments

Comments
 (0)