Commit f7416509 by Marijan Šuflaj

Fix odb foreach to also close on positive error code

In include/git2/odb.h it states that callback can also return
positive value which should break looping.

Implementations of git_odb_foreach() and pack_backend__foreach()
did not respect that.
parent 68166017
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment