diff options
| author | Junio C Hamano <gitster@pobox.com> | 2020-12-17 15:06:40 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2020-12-17 15:06:40 -0800 |
| commit | e5ace7167a7d84cc906fd01768c470d75763a22d (patch) | |
| tree | e7a203a787d80f3f107f93783de0342829e7ff2a /oid-array.c | |
| parent | Merge branch 'tb/partial-clone-filters-fix' (diff) | |
| parent | commit-graph: use size_t for array allocation and indexing (diff) | |
| download | git-e5ace7167a7d84cc906fd01768c470d75763a22d.tar.gz git-e5ace7167a7d84cc906fd01768c470d75763a22d.zip | |
Merge branch 'jk/oid-array-cleanup'
Code clean-up.
* jk/oid-array-cleanup:
commit-graph: use size_t for array allocation and indexing
commit-graph: replace packed_oid_list with oid_array
commit-graph: drop count_distinct_commits() function
oid-array: provide a for-loop iterator
oid-array: make sort function public
cache.h: move hash/oid functions to hash.h
t0064: make duplicate tests more robust
t0064: drop sha1 mention from filename
oid-array.h: drop sha1 mention from header guard
Diffstat (limited to 'oid-array.c')
| -rw-r--r-- | oid-array.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/oid-array.c b/oid-array.c index 8657a5cedf..8e1bcedc0c 100644 --- a/oid-array.c +++ b/oid-array.c @@ -14,8 +14,10 @@ static int void_hashcmp(const void *a, const void *b) return oidcmp(a, b); } -static void oid_array_sort(struct oid_array *array) +void oid_array_sort(struct oid_array *array) { + if (array->sorted) + return; QSORT(array->oid, array->nr, void_hashcmp); array->sorted = 1; } @@ -28,8 +30,7 @@ static const unsigned char *sha1_access(size_t index, void *table) int oid_array_lookup(struct oid_array *array, const struct object_id *oid) { - if (!array->sorted) - oid_array_sort(array); + oid_array_sort(array); return sha1_pos(oid->hash, array->oid, array->nr, sha1_access); } @@ -64,14 +65,10 @@ int oid_array_for_each_unique(struct oid_array *array, { size_t i; - if (!array->sorted) - oid_array_sort(array); + oid_array_sort(array); - for (i = 0; i < array->nr; i++) { - int ret; - if (i > 0 && oideq(array->oid + i, array->oid + i - 1)) - continue; - ret = fn(array->oid + i, data); + for (i = 0; i < array->nr; i = oid_array_next_unique(array, i)) { + int ret = fn(array->oid + i, data); if (ret) return ret; } |
