summaryrefslogtreecommitdiff
path: root/src/libgit2/oidarray.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libgit2/oidarray.c')
-rw-r--r--src/libgit2/oidarray.c52
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)