summaryrefslogtreecommitdiff
path: root/src/notes.c
diff options
context:
space:
mode:
authorRichard Ipsum <richardipsum@fastmail.co.uk>2017-03-15 18:17:42 +0000
committerRichard Ipsum <richardipsum@fastmail.co.uk>2017-10-07 00:43:29 +0100
commit9a02725d11acb302b0d9ef7013ae81ffd59525c7 (patch)
tree8bf93af54d61b0bf45df4447c9b6b4c343b19cfd /src/notes.c
parent7096bf1ef6b5c7c5659ea9d8c66c85bda8ef20db (diff)
downloadlibgit2-9a02725d11acb302b0d9ef7013ae81ffd59525c7.tar.gz
notes: Add git_note_commit_remove
This also adds tests for this function.
Diffstat (limited to 'src/notes.c')
-rw-r--r--src/notes.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/notes.c b/src/notes.c
index 35ba93d7c..9aef8fcac 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -369,7 +369,9 @@ cleanup:
return error;
}
-static int note_remove(git_repository *repo,
+static int note_remove(
+ git_oid *notes_commit_out,
+ git_repository *repo,
const git_signature *author, const git_signature *committer,
const char *notes_ref, git_tree *tree,
const char *target, git_commit **parents)
@@ -389,6 +391,12 @@ static int note_remove(git_repository *repo,
*parents == NULL ? 0 : 1,
(const git_commit **) parents);
+ if (error < 0)
+ goto cleanup;
+
+ if (notes_commit_out)
+ git_oid_cpy(notes_commit_out, &oid);
+
cleanup:
git_tree_free(tree_after_removal);
return error;
@@ -564,7 +572,7 @@ int git_note_remove(git_repository *repo, const char *notes_ref_in,
if (!(error = retrieve_note_tree_and_commit(
&tree, &commit, &notes_ref, repo, notes_ref_in)))
- error = note_remove(
+ error = note_remove(NULL,
repo, author, committer, notes_ref, tree, target, &commit);
git__free(notes_ref);
@@ -574,6 +582,31 @@ int git_note_remove(git_repository *repo, const char *notes_ref_in,
return error;
}
+int git_note_commit_remove(
+ git_oid *notes_commit_out,
+ git_repository *repo,
+ git_commit *notes_commit,
+ const git_signature *author,
+ const git_signature *committer,
+ const git_oid *oid)
+{
+ int error;
+ git_tree *tree = NULL;
+ char target[GIT_OID_HEXSZ + 1];
+
+ git_oid_tostr(target, sizeof(target), oid);
+
+ if ((error = git_commit_tree(&tree, notes_commit)) < 0)
+ goto cleanup;
+
+ error = note_remove(notes_commit_out,
+ repo, author, committer, NULL, tree, target, &notes_commit);
+
+cleanup:
+ git_tree_free(tree);
+ return error;
+}
+
int git_note_default_ref(git_buf *out, git_repository *repo)
{
char *default_ref;