summaryrefslogtreecommitdiff
path: root/src/libgit2/transports/smart.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libgit2/transports/smart.c')
-rw-r--r--src/libgit2/transports/smart.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/libgit2/transports/smart.c b/src/libgit2/transports/smart.c
index 9d1afeb05..b0925c8bb 100644
--- a/src/libgit2/transports/smart.c
+++ b/src/libgit2/transports/smart.c
@@ -496,17 +496,35 @@ const git_oid * git_shallowarray_get(git_shallowarray *array, size_t idx)
int git_shallowarray_add(git_shallowarray *array, git_oid *oid)
{
size_t oid_index;
+
if (git_array_search(&oid_index, array->array, (git_array_compare_cb)git_oid_cmp, &oid) < 0) {
git_oid *tmp = git_array_alloc(array->array);
+ GIT_ERROR_CHECK_ALLOC(tmp);
+
git_oid_cpy(tmp, oid);
}
+
return 0;
}
int git_shallowarray_remove(git_shallowarray *array, git_oid *oid)
{
- GIT_UNUSED(array);
- GIT_UNUSED(oid);
- /* no git_array_removeā€¦ meh */
- return -1;
+ git_array_oid_t new_array = GIT_ARRAY_INIT;
+ git_oid *element;
+ git_oid *tmp;
+ size_t i;
+
+ git_array_foreach(array->array, i, element) {
+ if (git_oid_cmp(oid, element)) {
+ tmp = git_array_alloc(new_array);
+ GIT_ERROR_CHECK_ALLOC(tmp);
+
+ git_oid_cpy(tmp, element);
+ }
+ }
+
+ git_array_clear(array->array);
+ array->array = new_array;
+
+ return 0;
}