diff options
author | Russell Belfer <rb@github.com> | 2012-08-03 17:08:01 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-08-03 17:08:01 -0700 |
commit | 5dca201072724e4230141796d7c9f8836a277de8 (patch) | |
tree | 7eb6b8f3e08c8abc608ee43c0ddc32d4d043a2c6 /tests-clar/notes/notes.c | |
parent | 2031760c626711cc69b4d63ac9798ff333583ca0 (diff) | |
download | libgit2-5dca201072724e4230141796d7c9f8836a277de8.tar.gz |
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/notes/notes.c')
-rw-r--r-- | tests-clar/notes/notes.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests-clar/notes/notes.c b/tests-clar/notes/notes.c index e1387782e..dfd7f5231 100644 --- a/tests-clar/notes/notes.c +++ b/tests-clar/notes/notes.c @@ -95,11 +95,39 @@ void test_notes_notes__can_retrieve_a_list_of_notes_for_a_given_namespace(void) create_note(¬e_oid3, "refs/notes/i-can-see-dead-notes", "9fd738e8f7967c078dceed8190330fc8648ee56a", "I decorate 9fd7 and 4a20\n"); create_note(¬e_oid4, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 9fd7 and 4a20\n"); - cl_git_pass(git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes", note_list_cb, &retrieved_notes)); + cl_git_pass(git_note_foreach +(_repo, "refs/notes/i-can-see-dead-notes", note_list_cb, &retrieved_notes)); cl_assert_equal_i(4, retrieved_notes); } +static int note_cancel_cb(git_note_data *note_data, void *payload) +{ + unsigned int *count = (unsigned int *)payload; + + GIT_UNUSED(note_data); + + (*count)++; + + return (*count > 2); +} + +void test_notes_notes__can_cancel_foreach(void) +{ + git_oid note_oid1, note_oid2, note_oid3, note_oid4; + unsigned int retrieved_notes = 0; + + create_note(¬e_oid1, "refs/notes/i-can-see-dead-notes", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "I decorate a65f\n"); + create_note(¬e_oid2, "refs/notes/i-can-see-dead-notes", "c47800c7266a2be04c571c04d5a6614691ea99bd", "I decorate c478\n"); + create_note(¬e_oid3, "refs/notes/i-can-see-dead-notes", "9fd738e8f7967c078dceed8190330fc8648ee56a", "I decorate 9fd7 and 4a20\n"); + create_note(¬e_oid4, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 9fd7 and 4a20\n"); + + cl_assert_equal_i( + GIT_EUSER, + git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes", + note_cancel_cb, &retrieved_notes)); +} + void test_notes_notes__retrieving_a_list_of_notes_for_an_unknown_namespace_returns_ENOTFOUND(void) { int error; |