Commit 734c6fc1 by Russell Belfer

Report errors finding notes

parent de19c4a9
...@@ -13,6 +13,12 @@ ...@@ -13,6 +13,12 @@
#include "iterator.h" #include "iterator.h"
#include "signature.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( static int find_subtree_in_current_level(
git_tree **out, git_tree **out,
git_repository *repo, git_repository *repo,
...@@ -26,7 +32,7 @@ static int find_subtree_in_current_level( ...@@ -26,7 +32,7 @@ static int find_subtree_in_current_level(
*out = NULL; *out = NULL;
if (parent == NULL) if (parent == NULL)
return GIT_ENOTFOUND; return note_error_notfound();
for (i = 0; i < git_tree_entrycount(parent); i++) { for (i = 0; i < git_tree_entrycount(parent); i++) {
entry = git_tree_entry_byindex(parent, i); entry = git_tree_entry_byindex(parent, i);
...@@ -44,7 +50,7 @@ static int find_subtree_in_current_level( ...@@ -44,7 +50,7 @@ static int find_subtree_in_current_level(
return GIT_EEXISTS; return GIT_EEXISTS;
} }
return GIT_ENOTFOUND; return note_error_notfound();
} }
static int find_subtree_r(git_tree **out, git_tree *root, 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, ...@@ -56,9 +62,8 @@ static int find_subtree_r(git_tree **out, git_tree *root,
*out = NULL; *out = NULL;
error = find_subtree_in_current_level(&subtree, repo, root, target, *fanout); 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)); return git_tree_lookup(out, repo, git_tree_id(root));
}
if (error < 0) if (error < 0)
return error; return error;
...@@ -85,7 +90,8 @@ static int find_blob(git_oid *blob, git_tree *tree, const char *target) ...@@ -85,7 +90,8 @@ static int find_blob(git_oid *blob, git_tree *tree, const char *target)
return 0; return 0;
} }
} }
return GIT_ENOTFOUND;
return note_error_notfound();
} }
static int tree_write( static int tree_write(
...@@ -316,8 +322,8 @@ static int note_new(git_note **out, git_oid *note_oid, git_blob *blob) ...@@ -316,8 +322,8 @@ static int note_new(git_note **out, git_oid *note_oid, git_blob *blob)
return 0; return 0;
} }
static int note_lookup(git_note **out, git_repository *repo, static int note_lookup(
git_tree *tree, const char *target) git_note **out, git_repository *repo, git_tree *tree, const char *target)
{ {
int error, fanout = 0; int error, fanout = 0;
git_oid oid; git_oid oid;
...@@ -382,6 +388,7 @@ static int note_get_default_ref(const char **out, git_repository *repo) ...@@ -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"); ret = git_config_get_string(out, cfg, "core.notesRef");
if (ret == GIT_ENOTFOUND) { if (ret == GIT_ENOTFOUND) {
giterr_clear();
*out = GIT_NOTES_DEFAULT_REF; *out = GIT_NOTES_DEFAULT_REF;
return 0; return 0;
} }
...@@ -432,12 +439,10 @@ int git_note_read(git_note **out, git_repository *repo, ...@@ -432,12 +439,10 @@ int git_note_read(git_note **out, git_repository *repo,
target = git_oid_allocfmt(oid); target = git_oid_allocfmt(oid);
GITERR_CHECK_ALLOC(target); GITERR_CHECK_ALLOC(target);
if ((error = retrieve_note_tree_and_commit(&tree, &commit, repo, &notes_ref)) < 0) if (!(error = retrieve_note_tree_and_commit(
goto cleanup; &tree, &commit, repo, &notes_ref)))
error = note_lookup(out, repo, tree, target);
error = note_lookup(out, repo, tree, target);
cleanup:
git__free(target); git__free(target);
git_tree_free(tree); git_tree_free(tree);
git_commit_free(commit); git_commit_free(commit);
...@@ -489,13 +494,11 @@ int git_note_remove(git_repository *repo, const char *notes_ref, ...@@ -489,13 +494,11 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
target = git_oid_allocfmt(oid); target = git_oid_allocfmt(oid);
GITERR_CHECK_ALLOC(target); GITERR_CHECK_ALLOC(target);
if ((error = retrieve_note_tree_and_commit(&tree, &commit, repo, &notes_ref)) < 0) if (!(error = retrieve_note_tree_and_commit(
goto cleanup; &tree, &commit, repo, &notes_ref)))
error = note_remove(
error = note_remove(repo, author, committer, notes_ref, repo, author, committer, notes_ref, tree, target, &commit);
tree, target, &commit);
cleanup:
git__free(target); git__free(target);
git_commit_free(commit); git_commit_free(commit);
git_tree_free(tree); git_tree_free(tree);
...@@ -533,7 +536,7 @@ static int process_entry_path( ...@@ -533,7 +536,7 @@ static int process_entry_path(
const char* entry_path, const char* entry_path,
git_oid *annotated_object_id) git_oid *annotated_object_id)
{ {
int error = -1; int error = 0;
size_t i = 0, j = 0, len; size_t i = 0, j = 0, len;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment