diff options
author | Vicent Marti <tanoku@gmail.com> | 2013-06-25 00:25:35 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2013-06-25 00:25:35 +0200 |
commit | 29d7242b1dcd1f09a63417abd648a6217b85d301 (patch) | |
tree | dedc3bc07a500770382ca4c517e4bb015e506c4b /src/notes.c | |
parent | a50086d174658914d4d6462afbc83b02825b1f5b (diff) | |
parent | eddc1f1ed78898a4ca41480045b1d0d5b075e773 (diff) | |
download | libgit2-29d7242b1dcd1f09a63417abd648a6217b85d301.tar.gz |
Merge branch 'development'
Diffstat (limited to 'src/notes.c')
-rw-r--r-- | src/notes.c | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/src/notes.c b/src/notes.c index ef48ac88e..beace1b50 100644 --- a/src/notes.c +++ b/src/notes.c @@ -13,6 +13,12 @@ #include "iterator.h" #include "signature.h" +static int note_error_notfound(void) +{ + giterr_set(GITERR_INVALID, "Note could not be found"); + return GIT_ENOTFOUND; +} + static int find_subtree_in_current_level( git_tree **out, git_repository *repo, @@ -26,7 +32,7 @@ static int find_subtree_in_current_level( *out = NULL; if (parent == NULL) - return GIT_ENOTFOUND; + return note_error_notfound(); for (i = 0; i < git_tree_entrycount(parent); i++) { entry = git_tree_entry_byindex(parent, i); @@ -44,7 +50,7 @@ static int find_subtree_in_current_level( return GIT_EEXISTS; } - return GIT_ENOTFOUND; + return note_error_notfound(); } static int find_subtree_r(git_tree **out, git_tree *root, @@ -56,9 +62,8 @@ static int find_subtree_r(git_tree **out, git_tree *root, *out = NULL; error = find_subtree_in_current_level(&subtree, repo, root, target, *fanout); - if (error == GIT_EEXISTS) { + if (error == GIT_EEXISTS) return git_tree_lookup(out, repo, git_tree_id(root)); - } if (error < 0) return error; @@ -85,7 +90,8 @@ static int find_blob(git_oid *blob, git_tree *tree, const char *target) return 0; } } - return GIT_ENOTFOUND; + + return note_error_notfound(); } static int tree_write( @@ -316,8 +322,8 @@ static int note_new(git_note **out, git_oid *note_oid, git_blob *blob) return 0; } -static int note_lookup(git_note **out, git_repository *repo, - git_tree *tree, const char *target) +static int note_lookup( + git_note **out, git_repository *repo, git_tree *tree, const char *target) { int error, fanout = 0; git_oid oid; @@ -382,6 +388,7 @@ static int note_get_default_ref(const char **out, git_repository *repo) ret = git_config_get_string(out, cfg, "core.notesRef"); if (ret == GIT_ENOTFOUND) { + giterr_clear(); *out = GIT_NOTES_DEFAULT_REF; return 0; } @@ -432,12 +439,10 @@ int git_note_read(git_note **out, git_repository *repo, target = git_oid_allocfmt(oid); GITERR_CHECK_ALLOC(target); - if ((error = retrieve_note_tree_and_commit(&tree, &commit, repo, ¬es_ref)) < 0) - goto cleanup; - - error = note_lookup(out, repo, tree, target); + if (!(error = retrieve_note_tree_and_commit( + &tree, &commit, repo, ¬es_ref))) + error = note_lookup(out, repo, tree, target); -cleanup: git__free(target); git_tree_free(tree); git_commit_free(commit); @@ -489,13 +494,11 @@ int git_note_remove(git_repository *repo, const char *notes_ref, target = git_oid_allocfmt(oid); GITERR_CHECK_ALLOC(target); - if ((error = retrieve_note_tree_and_commit(&tree, &commit, repo, ¬es_ref)) < 0) - goto cleanup; + if (!(error = retrieve_note_tree_and_commit( + &tree, &commit, repo, ¬es_ref))) + error = note_remove( + repo, author, committer, notes_ref, tree, target, &commit); - error = note_remove(repo, author, committer, notes_ref, - tree, target, &commit); - -cleanup: git__free(target); git_commit_free(commit); git_tree_free(tree); @@ -533,7 +536,7 @@ static int process_entry_path( const char* entry_path, git_oid *annotated_object_id) { - int error = -1; + int error = 0; size_t i = 0, j = 0, len; git_buf buf = GIT_BUF_INIT; @@ -576,30 +579,30 @@ 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_oid note_id, annotated_id; + int error; + git_note_iterator *iter = NULL; + git_oid note_id, annotated_id; - if ((error = git_note_iterator_new(&iter, repo, notes_ref)) < 0) - return error; + if ((error = git_note_iterator_new(&iter, repo, notes_ref)) < 0) + return error; - while (!(error = git_note_next(¬e_id, &annotated_id, iter))) { - if (note_cb(¬e_id, &annotated_id, payload)) { - error = GIT_EUSER; - break; - } - } + while (!(error = git_note_next(¬e_id, &annotated_id, iter))) { + if (note_cb(¬e_id, &annotated_id, payload)) { + error = GIT_EUSER; + break; + } + } - if (error == GIT_ITEROVER) - error = 0; + if (error == GIT_ITEROVER) + error = 0; - git_note_iterator_free(iter); - return error; + git_note_iterator_free(iter); + return error; } @@ -644,18 +647,12 @@ int git_note_next( const git_index_entry *item; if ((error = git_iterator_current(&item, it)) < 0) - goto exit; + return error; - if (item != NULL) { - git_oid_cpy(note_id, &item->oid); - error = process_entry_path(item->path, annotated_id); + git_oid_cpy(note_id, &item->oid); - if (error >= 0) - error = git_iterator_advance(NULL, it); - } else { - error = GIT_ITEROVER; - } + if (!(error = process_entry_path(item->path, annotated_id))) + git_iterator_advance(NULL, it); -exit: return error; } |