diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2023-05-09 20:38:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-09 20:38:04 +0100 |
commit | 2bbcdee6b666f34e83d1cf9ca9badc66258202d6 (patch) | |
tree | 26a9d405c75564de8e1a3dc8ac4dc1c8ec7421f7 /src/libgit2/oidarray.c | |
parent | 251408cfd4ff8112efaa5c82ec81c9574c4bf022 (diff) | |
parent | 437c5f5a0b6ae6068168081ac6422dba44cff31d (diff) | |
download | libgit2-2bbcdee6b666f34e83d1cf9ca9badc66258202d6.tar.gz |
Merge pull request #6557 from libgit2/ethomson/shallow
Shallow (#6396) with some fixes from review
Diffstat (limited to 'src/libgit2/oidarray.c')
-rw-r--r-- | src/libgit2/oidarray.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/libgit2/oidarray.c b/src/libgit2/oidarray.c index 583017c4e..37f67756a 100644 --- a/src/libgit2/oidarray.c +++ b/src/libgit2/oidarray.c @@ -15,10 +15,17 @@ void git_oidarray_dispose(git_oidarray *arr) git__free(arr->ids); } -void git_oidarray__from_array(git_oidarray *arr, git_array_oid_t *array) +void git_oidarray__from_array(git_oidarray *out, const git_array_oid_t *array) { - arr->count = array->size; - arr->ids = array->ptr; + out->count = array->size; + out->ids = array->ptr; +} + +void git_oidarray__to_array(git_array_oid_t *out, const git_oidarray *array) +{ + out->ptr = array->ids; + out->size = array->count; + out->asize = array->count; } void git_oidarray__reverse(git_oidarray *arr) @@ -33,6 +40,45 @@ void git_oidarray__reverse(git_oidarray *arr) } } +int git_oidarray__add(git_array_oid_t *arr, git_oid *id) +{ + git_oid *add, *iter; + size_t i; + + git_array_foreach(*arr, i, iter) { + if (git_oid_cmp(iter, id) == 0) + return 0; + } + + if ((add = git_array_alloc(*arr)) == NULL) + return -1; + + git_oid_cpy(add, id); + return 0; +} + +bool git_oidarray__remove(git_array_oid_t *arr, git_oid *id) +{ + bool found = false; + size_t remain, i; + git_oid *iter; + + git_array_foreach(*arr, i, iter) { + if (git_oid_cmp(iter, id) == 0) { + arr->size--; + remain = arr->size - i; + + if (remain > 0) + memmove(&arr->ptr[i], &arr->ptr[i+1], remain * sizeof(git_oid)); + + found = true; + break; + } + } + + return found; +} + #ifndef GIT_DEPRECATE_HARD void git_oidarray_free(git_oidarray *arr) |