Merge pull request #4949 from zlikavac32/fix-odb-foreach-cb-positive-error-code odb: Fix odb foreach to also close on positive error code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/odb.c b/src/odb.c
index b6833e4..c0cd0ef 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -1260,7 +1260,7 @@ int git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload)
git_vector_foreach(&db->backends, i, internal) {
git_odb_backend *b = internal->backend;
int error = b->foreach(b, cb, payload);
- if (error < 0)
+ if (error != 0)
return error;
}
diff --git a/src/odb_pack.c b/src/odb_pack.c
index c2c5e79..6bdedec 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -478,7 +478,7 @@ static int pack_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb c
return error;
git_vector_foreach(&backend->packs, i, p) {
- if ((error = git_pack_foreach_entry(p, cb, data)) < 0)
+ if ((error = git_pack_foreach_entry(p, cb, data)) != 0)
return error;
}
diff --git a/tests/odb/foreach.c b/tests/odb/foreach.c
index 3e44f10..7a45a57 100644
--- a/tests/odb/foreach.c
+++ b/tests/odb/foreach.c
@@ -81,6 +81,16 @@ static int foreach_stop_first_cb(const git_oid *oid, void *data)
return -123;
}
+static int foreach_stop_cb_positive_ret(const git_oid *oid, void *data)
+{
+ int *nobj = data;
+ (*nobj)++;
+
+ GIT_UNUSED(oid);
+
+ return (*nobj == 1000) ? 321 : 0;
+}
+
void test_odb_foreach__interrupt_foreach(void)
{
int nobj = 0;
@@ -92,6 +102,11 @@ void test_odb_foreach__interrupt_foreach(void)
cl_assert_equal_i(-321, git_odb_foreach(_odb, foreach_stop_cb, &nobj));
cl_assert(nobj == 1000);
+ nobj = 0;
+
+ cl_assert_equal_i(321, git_odb_foreach(_odb, foreach_stop_cb_positive_ret, &nobj));
+ cl_assert(nobj == 1000);
+
git_odb_free(_odb);
git_repository_free(_repo);