Skip to content

Commit 6b2cd0e

Browse files
authored
Merge pull request libgit2#4949 from zlikavac32/fix-odb-foreach-cb-positive-error-code
odb: Fix odb foreach to also close on positive error code
2 parents 6816601 + f741650 commit 6b2cd0e

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/odb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ int git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload)
12601260
git_vector_foreach(&db->backends, i, internal) {
12611261
git_odb_backend *b = internal->backend;
12621262
int error = b->foreach(b, cb, payload);
1263-
if (error < 0)
1263+
if (error != 0)
12641264
return error;
12651265
}
12661266

src/odb_pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static int pack_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb c
478478
return error;
479479

480480
git_vector_foreach(&backend->packs, i, p) {
481-
if ((error = git_pack_foreach_entry(p, cb, data)) < 0)
481+
if ((error = git_pack_foreach_entry(p, cb, data)) != 0)
482482
return error;
483483
}
484484

tests/odb/foreach.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ static int foreach_stop_first_cb(const git_oid *oid, void *data)
8181
return -123;
8282
}
8383

84+
static int foreach_stop_cb_positive_ret(const git_oid *oid, void *data)
85+
{
86+
int *nobj = data;
87+
(*nobj)++;
88+
89+
GIT_UNUSED(oid);
90+
91+
return (*nobj == 1000) ? 321 : 0;
92+
}
93+
8494
void test_odb_foreach__interrupt_foreach(void)
8595
{
8696
int nobj = 0;
@@ -92,6 +102,11 @@ void test_odb_foreach__interrupt_foreach(void)
92102
cl_assert_equal_i(-321, git_odb_foreach(_odb, foreach_stop_cb, &nobj));
93103
cl_assert(nobj == 1000);
94104

105+
nobj = 0;
106+
107+
cl_assert_equal_i(321, git_odb_foreach(_odb, foreach_stop_cb_positive_ret, &nobj));
108+
cl_assert(nobj == 1000);
109+
95110
git_odb_free(_odb);
96111
git_repository_free(_repo);
97112

0 commit comments

Comments
 (0)