From 161b1cf3bdca7fecf5ec03ffdb74260312cd0229 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Wed, 28 Nov 2018 16:27:48 -0800 Subject: sha1-array: provide oid_array_filter Helped-by: Junio C Hamano Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- sha1-array.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'sha1-array.c') diff --git a/sha1-array.c b/sha1-array.c index b94e0ec0f5..d922e94e3f 100644 --- a/sha1-array.c +++ b/sha1-array.c @@ -77,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; +} -- cgit v1.3