summaryrefslogtreecommitdiff
path: root/src/notes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/notes.c')
-rw-r--r--src/notes.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/src/notes.c b/src/notes.c
index 7813e9985..212413a5a 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -522,13 +522,13 @@ static int process_entry_path(
int (*note_cb)(git_note_data *note_data, void *payload),
void *payload)
{
- int i = 0, j = 0, error = -1, len;
+ int i = 0, j = 0, error, len;
git_buf buf = GIT_BUF_INIT;
git_note_data note_data;
- if (git_buf_puts(&buf, entry_path) < 0)
+ if ((error = git_buf_puts(&buf, entry_path)) < 0)
goto cleanup;
-
+
len = git_buf_len(&buf);
while (i < len) {
@@ -536,10 +536,9 @@ static int process_entry_path(
i++;
continue;
}
-
+
if (git__fromhex(buf.ptr[i]) < 0) {
/* This is not a note entry */
- error = 0;
goto cleanup;
}
@@ -555,16 +554,17 @@ static int process_entry_path(
if (j != GIT_OID_HEXSZ) {
/* This is not a note entry */
- error = 0;
goto cleanup;
}
- if (git_oid_fromstr(&note_data.annotated_object_oid, buf.ptr) < 0)
- return -1;
+ if ((error = git_oid_fromstr(
+ &note_data.annotated_object_oid, buf.ptr)) < 0)
+ goto cleanup;
git_oid_cpy(&note_data.blob_oid, note_oid);
- error = note_cb(&note_data, payload);
+ if (note_cb(&note_data, payload))
+ error = GIT_EUSER;
cleanup:
git_buf_free(&buf);
@@ -577,34 +577,27 @@ int git_note_foreach(
int (*note_cb)(git_note_data *note_data, void *payload),
void *payload)
{
- int error = -1;
+ int error;
git_iterator *iter = NULL;
git_tree *tree = NULL;
git_commit *commit = NULL;
const git_index_entry *item;
- if ((error = retrieve_note_tree_and_commit(&tree, &commit, repo, &notes_ref)) < 0)
- goto cleanup;
-
- if (git_iterator_for_tree(&iter, repo, tree) < 0)
- goto cleanup;
+ if (!(error = retrieve_note_tree_and_commit(
+ &tree, &commit, repo, &notes_ref)) &&
+ !(error = git_iterator_for_tree(&iter, repo, tree)))
+ error = git_iterator_current(iter, &item);
- if (git_iterator_current(iter, &item) < 0)
- goto cleanup;
-
- while (item) {
- if (process_entry_path(item->path, &item->oid, note_cb, payload) < 0)
- goto cleanup;
+ while (!error && item) {
+ error = process_entry_path(item->path, &item->oid, note_cb, payload);
- if (git_iterator_advance(iter, &item) < 0)
- goto cleanup;
+ if (!error)
+ error = git_iterator_advance(iter, &item);
}
- error = 0;
-
-cleanup:
git_iterator_free(iter);
git_tree_free(tree);
git_commit_free(commit);
+
return error;
}