diff options
Diffstat (limited to 'sha1-array.c')
-rw-r--r-- | sha1-array.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/sha1-array.c b/sha1-array.c index 838b3bf847..3eeadfede9 100644 --- a/sha1-array.c +++ b/sha1-array.c @@ -41,9 +41,26 @@ void oid_array_clear(struct oid_array *array) array->sorted = 0; } + +int oid_array_for_each(struct oid_array *array, + for_each_oid_fn fn, + void *data) +{ + int i; + + /* No oid_array_sort() here! See sha1-array.h */ + + for (i = 0; i < array->nr; i++) { + int ret = fn(array->oid + i, data); + if (ret) + return ret; + } + return 0; +} + int oid_array_for_each_unique(struct oid_array *array, - for_each_oid_fn fn, - void *data) + for_each_oid_fn fn, + void *data) { int i; @@ -52,7 +69,7 @@ int oid_array_for_each_unique(struct oid_array *array, for (i = 0; i < array->nr; i++) { int ret; - if (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1)) + if (i > 0 && oideq(array->oid + i, array->oid + i - 1)) continue; ret = fn(array->oid + i, data); if (ret) @@ -60,3 +77,20 @@ int oid_array_for_each_unique(struct oid_array *array, } return 0; } + +void oid_array_filter(struct oid_array *array, + for_each_oid_fn want, + void *cb_data) +{ + unsigned nr = array->nr, src, dst; + struct object_id *oids = array->oid; + + for (src = dst = 0; src < nr; src++) { + if (want(&oids[src], cb_data)) { + if (src != dst) + oidcpy(&oids[dst], &oids[src]); + dst++; + } + } + array->nr = dst; +} |