diff options
author | Russell Belfer <rb@github.com> | 2012-08-04 04:08:01 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-08-04 04:08:01 +0400 |
commit | 5dca201072724e4230141796d7c9f8836a277de8 (patch) | |
tree | 7eb6b8f3e08c8abc608ee43c0ddc32d4d043a2c6 /tests-clar/odb | |
parent | 2031760c626711cc69b4d63ac9798ff333583ca0 (diff) |
Update iterators for consistency across library
This updates all the `foreach()` type functions across the library
that take callbacks from the user to have a consistent behavior.
The rules are:
* A callback terminates the loop by returning any non-zero value
* Once the callback returns non-zero, it will not be called again
(i.e. the loop stops all iteration regardless of state)
* If the callback returns non-zero, the parent fn returns GIT_EUSER
* Although the parent returns GIT_EUSER, no error will be set in
the library and `giterr_last()` will return NULL if called.
This commit makes those changes across the library and adds tests
for most of the iteration APIs to make sure that they follow the
above rules.
Diffstat (limited to 'tests-clar/odb')
-rw-r--r-- | tests-clar/odb/foreach.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests-clar/odb/foreach.c b/tests-clar/odb/foreach.c index 525c70c09..e025fa210 100644 --- a/tests-clar/odb/foreach.c +++ b/tests-clar/odb/foreach.c @@ -31,6 +31,24 @@ static int foreach_cb(git_oid *oid, void *data) void test_odb_foreach__foreach(void) { + nobj = 0; cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL)); cl_assert(nobj == 1683); } + +static int foreach_stop_cb(git_oid *oid, void *data) +{ + GIT_UNUSED(data); + GIT_UNUSED(oid); + + nobj++; + + return (nobj == 1000); +} + +void test_odb_foreach__interrupt_foreach(void) +{ + nobj = 0; + cl_assert_equal_i(GIT_EUSER, git_odb_foreach(_odb, foreach_stop_cb, NULL)); + cl_assert(nobj == 1000); +} |