Skip to content

Commit d0482b4

Browse files
peffgitster
authored andcommitted
oid-array: make sort function public
We sort the oid-array as a side effect of calling the lookup or unique-iteration functions. But callers may want to sort it themselves (especially as we add new iteration options in future patches). We'll also move the check of the "sorted" flag into the sort function, so callers don't have to remember to check it. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3fa6f2a commit d0482b4

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

oid-array.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ static int void_hashcmp(const void *a, const void *b)
1414
return oidcmp(a, b);
1515
}
1616

17-
static void oid_array_sort(struct oid_array *array)
17+
void oid_array_sort(struct oid_array *array)
1818
{
19+
if (array->sorted)
20+
return;
1921
QSORT(array->oid, array->nr, void_hashcmp);
2022
array->sorted = 1;
2123
}
@@ -28,8 +30,7 @@ static const unsigned char *sha1_access(size_t index, void *table)
2830

2931
int oid_array_lookup(struct oid_array *array, const struct object_id *oid)
3032
{
31-
if (!array->sorted)
32-
oid_array_sort(array);
33+
oid_array_sort(array);
3334
return sha1_pos(oid->hash, array->oid, array->nr, sha1_access);
3435
}
3536

@@ -64,8 +65,7 @@ int oid_array_for_each_unique(struct oid_array *array,
6465
{
6566
size_t i;
6667

67-
if (!array->sorted)
68-
oid_array_sort(array);
68+
oid_array_sort(array);
6969

7070
for (i = 0; i < array->nr; i++) {
7171
int ret;

oid-array.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,9 @@ void oid_array_filter(struct oid_array *array,
106106
for_each_oid_fn want,
107107
void *cbdata);
108108

109+
/**
110+
* Sort the array in order of ascending object id.
111+
*/
112+
void oid_array_sort(struct oid_array *array);
113+
109114
#endif /* OID_ARRAY_H */

0 commit comments

Comments
 (0)