1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "git-compat-util.h"
5 #include "hash-lookup.h"
7 void oid_array_append(struct oid_array
*array
, const struct object_id
*oid
)
9 ALLOC_GROW(array
->oid
, array
->nr
+ 1, array
->alloc
);
10 oidcpy(&array
->oid
[array
->nr
++], oid
);
12 oid_set_algo(&array
->oid
[array
->nr
- 1], the_hash_algo
);
16 static int void_hashcmp(const void *va
, const void *vb
)
18 const struct object_id
*a
= va
, *b
= vb
;
20 if (a
->algo
== b
->algo
)
23 ret
= a
->algo
> b
->algo
? 1 : -1;
27 void oid_array_sort(struct oid_array
*array
)
31 QSORT(array
->oid
, array
->nr
, void_hashcmp
);
35 static const struct object_id
*oid_access(size_t index
, const void *table
)
37 const struct object_id
*array
= table
;
41 int oid_array_lookup(struct oid_array
*array
, const struct object_id
*oid
)
43 oid_array_sort(array
);
44 return oid_pos(oid
, array
->oid
, array
->nr
, oid_access
);
47 void oid_array_clear(struct oid_array
*array
)
49 FREE_AND_NULL(array
->oid
);
56 int oid_array_for_each(struct oid_array
*array
,
62 /* No oid_array_sort() here! See oid-array.h */
64 for (i
= 0; i
< array
->nr
; i
++) {
65 int ret
= fn(array
->oid
+ i
, data
);
72 int oid_array_for_each_unique(struct oid_array
*array
,
78 oid_array_sort(array
);
80 for (i
= 0; i
< array
->nr
; i
= oid_array_next_unique(array
, i
)) {
81 int ret
= fn(array
->oid
+ i
, data
);
88 void oid_array_filter(struct oid_array
*array
,
92 size_t nr
= array
->nr
, src
, dst
;
93 struct object_id
*oids
= array
->oid
;
95 for (src
= dst
= 0; src
< nr
; src
++) {
96 if (want(&oids
[src
], cb_data
)) {
98 oidcpy(&oids
[dst
], &oids
[src
]);