Commit d788f42a by Richard Ipsum

notes: Rewrite funcs in terms of note_commit funcs

parent 60bee89d
...@@ -424,8 +424,7 @@ static int normalize_namespace(char **out, git_repository *repo, const char *not ...@@ -424,8 +424,7 @@ static int normalize_namespace(char **out, git_repository *repo, const char *not
return note_get_default_ref(out, repo); return note_get_default_ref(out, repo);
} }
static int retrieve_note_tree_and_commit( static int retrieve_note_commit(
git_tree **tree_out,
git_commit **commit_out, git_commit **commit_out,
char **notes_ref_out, char **notes_ref_out,
git_repository *repo, git_repository *repo,
...@@ -443,34 +442,9 @@ static int retrieve_note_tree_and_commit( ...@@ -443,34 +442,9 @@ static int retrieve_note_tree_and_commit(
if (git_commit_lookup(commit_out, repo, &oid) < 0) if (git_commit_lookup(commit_out, repo, &oid) < 0)
return error; return error;
if ((error = git_commit_tree(tree_out, *commit_out)) < 0)
return error;
return 0; return 0;
} }
int git_note_read(git_note **out, git_repository *repo,
const char *notes_ref_in, const git_oid *oid)
{
int error;
char *target = NULL, *notes_ref = NULL;
git_tree *tree = NULL;
git_commit *commit = NULL;
target = git_oid_allocfmt(oid);
GITERR_CHECK_ALLOC(target);
if (!(error = retrieve_note_tree_and_commit(
&tree, &commit, &notes_ref, repo, notes_ref_in)))
error = note_lookup(out, repo, commit, tree, target);
git__free(notes_ref);
git__free(target);
git_tree_free(tree);
git_commit_free(commit);
return error;
}
int git_note_commit_read( int git_note_commit_read(
git_note **out, git_note **out,
git_repository *repo, git_repository *repo,
...@@ -493,37 +467,23 @@ cleanup: ...@@ -493,37 +467,23 @@ cleanup:
return error; return error;
} }
int git_note_create( int git_note_read(git_note **out, git_repository *repo,
git_oid *out, const char *notes_ref_in, const git_oid *oid)
git_repository *repo,
const char *notes_ref_in,
const git_signature *author,
const git_signature *committer,
const git_oid *oid,
const char *note,
int allow_note_overwrite)
{ {
int error; int error;
char *target = NULL, *notes_ref = NULL; char *notes_ref = NULL;
git_commit *commit = NULL; git_commit *commit = NULL;
git_tree *tree = NULL;
target = git_oid_allocfmt(oid); error = retrieve_note_commit(&commit, &notes_ref, repo, notes_ref_in);
GITERR_CHECK_ALLOC(target);
error = retrieve_note_tree_and_commit(&tree, &commit, &notes_ref, repo, notes_ref_in); if (error < 0)
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup; goto cleanup;
error = note_write(NULL, out, repo, author, committer, notes_ref, error = git_note_commit_read(out, repo, commit, oid);
note, tree, target, &commit, allow_note_overwrite);
cleanup: cleanup:
git__free(notes_ref); git__free(notes_ref);
git__free(target);
git_commit_free(commit); git_commit_free(commit);
git_tree_free(tree);
return error; return error;
} }
...@@ -558,27 +518,46 @@ cleanup: ...@@ -558,27 +518,46 @@ cleanup:
return error; return error;
} }
int git_note_remove(git_repository *repo, const char *notes_ref_in, int git_note_create(
const git_signature *author, const git_signature *committer, git_oid *out,
const git_oid *oid) git_repository *repo,
const char *notes_ref_in,
const git_signature *author,
const git_signature *committer,
const git_oid *oid,
const char *note,
int allow_note_overwrite)
{ {
int error; int error;
char *target = NULL, *notes_ref; char *notes_ref = NULL;
git_commit *commit = NULL; git_commit *existing_notes_commit = NULL;
git_tree *tree = NULL; git_reference *ref = NULL;
git_oid notes_blob_oid, notes_commit_oid;
target = git_oid_allocfmt(oid); error = retrieve_note_commit(&existing_notes_commit, &notes_ref,
GITERR_CHECK_ALLOC(target); repo, notes_ref_in);
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;
error = git_note_commit_create(&notes_commit_oid,
&notes_blob_oid,
repo, existing_notes_commit, author,
committer, oid, note,
allow_note_overwrite);
if (error < 0)
goto cleanup;
if (!(error = retrieve_note_tree_and_commit( error = git_reference_create(&ref, repo, notes_ref,
&tree, &commit, &notes_ref, repo, notes_ref_in))) &notes_commit_oid, 1, NULL);
error = note_remove(NULL,
repo, author, committer, notes_ref, tree, target, &commit);
if (out != NULL)
git_oid_cpy(out, &notes_blob_oid);
cleanup:
git__free(notes_ref); git__free(notes_ref);
git__free(target); git_commit_free(existing_notes_commit);
git_commit_free(commit); git_reference_free(ref);
git_tree_free(tree);
return error; return error;
} }
...@@ -607,6 +586,37 @@ cleanup: ...@@ -607,6 +586,37 @@ cleanup:
return error; return error;
} }
int git_note_remove(git_repository *repo, const char *notes_ref_in,
const git_signature *author, const git_signature *committer,
const git_oid *oid)
{
int error;
char *notes_ref_target = NULL;
git_commit *existing_notes_commit = NULL;
git_oid new_notes_commit;
git_reference *notes_ref = NULL;
error = retrieve_note_commit(&existing_notes_commit, &notes_ref_target,
repo, notes_ref_in);
if (error < 0)
goto cleanup;
error = git_note_commit_remove(&new_notes_commit, repo,
existing_notes_commit, author, committer, oid);
if (error < 0)
goto cleanup;
error = git_reference_create(&notes_ref, repo, notes_ref_target,
&new_notes_commit, 1, NULL);
cleanup:
git__free(notes_ref_target);
git_reference_free(notes_ref);
git_commit_free(existing_notes_commit);
return error;
}
int git_note_default_ref(git_buf *out, git_repository *repo) int git_note_default_ref(git_buf *out, git_repository *repo)
{ {
char *default_ref; char *default_ref;
...@@ -731,7 +741,6 @@ int git_note_foreach( ...@@ -731,7 +741,6 @@ int git_note_foreach(
return error; return error;
} }
void git_note_iterator_free(git_note_iterator *it) void git_note_iterator_free(git_note_iterator *it)
{ {
if (it == NULL) if (it == NULL)
...@@ -740,47 +749,43 @@ void git_note_iterator_free(git_note_iterator *it) ...@@ -740,47 +749,43 @@ void git_note_iterator_free(git_note_iterator *it)
git_iterator_free(it); git_iterator_free(it);
} }
int git_note_commit_iterator_new(
int git_note_iterator_new(
git_note_iterator **it, git_note_iterator **it,
git_repository *repo, git_commit *notes_commit)
const char *notes_ref_in)
{ {
int error; int error;
git_commit *commit = NULL; git_tree *tree;
git_tree *tree = NULL;
char *notes_ref;
error = retrieve_note_tree_and_commit(&tree, &commit, &notes_ref, repo, notes_ref_in); if ((error = git_commit_tree(&tree, notes_commit)) < 0)
if (error < 0)
goto cleanup; goto cleanup;
if ((error = git_iterator_for_tree(it, tree, NULL)) < 0) if ((error = git_iterator_for_tree(it, tree, NULL)) < 0)
git_iterator_free(*it); git_iterator_free(*it);
cleanup: cleanup:
git__free(notes_ref);
git_tree_free(tree); git_tree_free(tree);
git_commit_free(commit);
return error; return error;
} }
int git_note_commit_iterator_new( int git_note_iterator_new(
git_note_iterator **it, git_note_iterator **it,
git_commit *notes_commit) git_repository *repo,
const char *notes_ref_in)
{ {
int error; int error;
git_tree *tree; git_commit *commit = NULL;
char *notes_ref;
if ((error = git_commit_tree(&tree, notes_commit)) < 0) error = retrieve_note_commit(&commit, &notes_ref, repo, notes_ref_in);
if (error < 0)
goto cleanup; goto cleanup;
if ((error = git_iterator_for_tree(it, tree, NULL)) < 0) error = git_note_commit_iterator_new(it, commit);
git_iterator_free(*it);
cleanup: cleanup:
git_tree_free(tree); git__free(notes_ref);
git_commit_free(commit);
return error; return error;
} }
......
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