Commit f95e8cc0 by Vicent Martí

notes: Cleanup error handling

parent d3a60dc2
...@@ -265,7 +265,7 @@ static int note_remove(git_repository *repo, ...@@ -265,7 +265,7 @@ static int note_remove(git_repository *repo,
static int note_get_default_ref(const char **out, git_repository *repo) static int note_get_default_ref(const char **out, git_repository *repo)
{ {
int error; int ret;
git_config *cfg; git_config *cfg;
*out = NULL; *out = NULL;
...@@ -273,13 +273,13 @@ static int note_get_default_ref(const char **out, git_repository *repo) ...@@ -273,13 +273,13 @@ static int note_get_default_ref(const char **out, git_repository *repo)
if (git_repository_config__weakptr(&cfg, repo) < 0) if (git_repository_config__weakptr(&cfg, repo) < 0)
return -1; return -1;
error = git_config_get_string(cfg, "core.notesRef", out); ret = git_config_get_string(cfg, "core.notesRef", out);
if (error == GIT_ENOTFOUND) { if (ret == GIT_ENOTFOUND) {
*out = GIT_NOTES_DEFAULT_REF; *out = GIT_NOTES_DEFAULT_REF;
return 0; return 0;
} }
return error; return ret;
} }
int git_note_read(git_note **out, git_repository *repo, int git_note_read(git_note **out, git_repository *repo,
...@@ -293,11 +293,8 @@ int git_note_read(git_note **out, git_repository *repo, ...@@ -293,11 +293,8 @@ int git_note_read(git_note **out, git_repository *repo,
*out = NULL; *out = NULL;
if (!notes_ref) { if (!notes_ref && note_get_default_ref(&notes_ref, repo) < 0)
error = note_get_default_ref(&notes_ref, repo); return -1;
if (error < 0)
return error;
}
error = git_reference_lookup(&ref, repo, notes_ref); error = git_reference_lookup(&ref, repo, notes_ref);
if (error < 0) if (error < 0)
...@@ -337,11 +334,8 @@ int git_note_create( ...@@ -337,11 +334,8 @@ int git_note_create(
git_commit *commit = NULL; git_commit *commit = NULL;
git_reference *ref; git_reference *ref;
if (!notes_ref) { if (!notes_ref && note_get_default_ref(&notes_ref, repo) < 0)
error = note_get_default_ref(&notes_ref, repo); return -1;
if (error < 0)
return error;
}
error = git_reference_lookup(&ref, repo, notes_ref); error = git_reference_lookup(&ref, repo, notes_ref);
if (error < 0 && error != GIT_ENOTFOUND) if (error < 0 && error != GIT_ENOTFOUND)
...@@ -385,11 +379,9 @@ int git_note_remove(git_repository *repo, const char *notes_ref, ...@@ -385,11 +379,9 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
git_commit *commit; git_commit *commit;
git_reference *ref; git_reference *ref;
if (!notes_ref) {
error = note_get_default_ref(&notes_ref, repo); if (!notes_ref && note_get_default_ref(&notes_ref, repo) < 0)
if (error < 0) return -1;
return error;
}
error = git_reference_lookup(&ref, repo, notes_ref); error = git_reference_lookup(&ref, repo, notes_ref);
if (error < 0) if (error < 0)
......
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