summaryrefslogtreecommitdiff
path: root/src/notes.c
diff options
context:
space:
mode:
authorNico von Geyso <Nico.Geyso@FU-Berlin.de>2013-03-06 22:25:01 +0100
committerNico von Geyso <Nico.Geyso@FU-Berlin.de>2013-03-06 22:36:19 +0100
commitf7b18502154edac242ab3760feb05600e09d67b3 (patch)
treeaf284a120d670cd4563830fc92329334527240a8 /src/notes.c
parent1a90dcf64e561b21e0981a7d87d71e349fa37f69 (diff)
downloadlibgit2-f7b18502154edac242ab3760feb05600e09d67b3.tar.gz
fixed minor issues with new note iterator
* fixed style issues * use new iterator functions for git_note_foreach()
Diffstat (limited to 'src/notes.c')
-rw-r--r--src/notes.c86
1 files changed, 37 insertions, 49 deletions
diff --git a/src/notes.c b/src/notes.c
index 987c5a6a3..0b286a77c 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -531,8 +531,7 @@ void git_note_free(git_note *note)
static int process_entry_path(
const char* entry_path,
- git_oid *annotated_object_id
-)
+ git_oid *annotated_object_id)
{
int error = -1;
size_t i = 0, j = 0, len;
@@ -569,8 +568,7 @@ static int process_entry_path(
goto cleanup;
}
- if ((error = git_oid_fromstr(annotated_object_id, buf.ptr)) < 0)
- goto cleanup;
+ error = git_oid_fromstr(annotated_object_id, buf.ptr);
cleanup:
git_buf_free(&buf);
@@ -578,40 +576,33 @@ cleanup:
}
int git_note_foreach(
- git_repository *repo,
- const char *notes_ref,
- git_note_foreach_cb note_cb,
- void *payload)
+ git_repository *repo,
+ const char *notes_ref,
+ git_note_foreach_cb note_cb,
+ void *payload)
{
- int error;
- git_note_iterator *iter = NULL;
- git_tree *tree = NULL;
- git_commit *commit = NULL;
- git_oid annotated_object_id;
- const git_index_entry *item;
-
- if (!(error = retrieve_note_tree_and_commit(
- &tree, &commit, repo, &notes_ref)) &&
- !(error = git_iterator_for_tree(&iter, tree)))
- error = git_iterator_current(iter, &item);
-
- while (!error && item) {
- error = process_entry_path(item->path, &annotated_object_id);
+ int error;
+ git_note_iterator *iter = NULL;
+ git_oid note_id, annotated_id;
- if (note_cb(&item->oid, &annotated_object_id, payload))
- error = GIT_EUSER;
+ if ((error = git_note_iterator_new(&iter, repo, notes_ref)) < 0)
+ return error;
- if (!error)
- error = git_iterator_advance(iter, &item);
- }
+ while (!(error = git_note_next(&note_id, &annotated_id, iter))) {
+ if (note_cb(&note_id, &annotated_id, payload)) {
+ error = GIT_EUSER;
+ break;
+ }
+ }
- git_iterator_free(iter);
- git_tree_free(tree);
- git_commit_free(commit);
+ if (error == GIT_ITEROVER)
+ error = 0;
- return error;
+ git_note_iterator_free(iter);
+ return error;
}
+
void git_note_iterator_free(git_note_iterator *it)
{
if (it == NULL)
@@ -624,23 +615,20 @@ void git_note_iterator_free(git_note_iterator *it)
int git_note_iterator_new(
git_note_iterator **it,
git_repository *repo,
- const char *notes_ref
-)
+ const char *notes_ref)
{
int error;
git_commit *commit = NULL;
git_tree *tree = NULL;
error = retrieve_note_tree_and_commit(&tree, &commit, repo, &notes_ref);
- if (!error) {
- *it = (git_note_iterator *)git__malloc(sizeof(git_iterator));
- GITERR_CHECK_ALLOC(*it);
+ if (error < 0)
+ goto cleanup;
- error = git_iterator_for_tree(it, tree);
- if (error)
- git_iterator_free(*it);
- }
+ if ((error = git_iterator_for_tree(it, tree)) < 0)
+ git_iterator_free(*it);
+cleanup:
git_tree_free(tree);
git_commit_free(commit);
@@ -650,24 +638,24 @@ int git_note_iterator_new(
int git_note_next(
git_oid* note_id,
git_oid* annotated_id,
- git_note_iterator *it
-)
+ git_note_iterator *it)
{
int error;
const git_index_entry *item;
- error = git_iterator_current(it, &item);
- if (!error && item) {
- git_oid_cpy(note_id, &item->oid);
+ if (error = git_iterator_current(it, &item) < 0)
+ goto exit;
+ if (item != NULL) {
+ git_oid_cpy(note_id, &item->oid);
error = process_entry_path(item->path, annotated_id);
- if (!error)
+ if (error >= 0)
error = git_iterator_advance(it, NULL);
- }
-
- if (!error && !item)
+ } else {
error = GIT_ITEROVER;
+ }
+exit:
return error;
}