Introduce `git_note_author`, `git_note_committer`
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
diff --git a/include/git2/notes.h b/include/git2/notes.h
index 98eb2ae..1a7794a 100644
--- a/include/git2/notes.h
+++ b/include/git2/notes.h
@@ -97,6 +97,23 @@ GIT_EXTERN(int) git_note_read(
const git_oid *oid);
/**
+ * Get the note author
+ *
+ * @param note the note
+ * @return the author
+ */
+GIT_EXTERN(const git_signature *) git_note_author(const git_note *note);
+
+/**
+ * Get the note committer
+ *
+ * @param note the note
+ * @return the committer
+ */
+GIT_EXTERN(const git_signature *) git_note_committer(const git_note *note);
+
+
+/**
* Get the note message
*
* @param note the note
diff --git a/src/notes.c b/src/notes.c
index ffe5d34..046a916 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -306,7 +306,11 @@ cleanup:
return error;
}
-static int note_new(git_note **out, git_oid *note_oid, git_blob *blob)
+static int note_new(
+ git_note **out,
+ git_oid *note_oid,
+ git_commit *commit,
+ git_blob *blob)
{
git_note *note = NULL;
@@ -314,6 +318,11 @@ static int note_new(git_note **out, git_oid *note_oid, git_blob *blob)
GITERR_CHECK_ALLOC(note);
git_oid_cpy(¬e->id, note_oid);
+
+ if (git_signature_dup(¬e->author, git_commit_author(commit)) < 0 ||
+ git_signature_dup(¬e->committer, git_commit_committer(commit)) < 0)
+ return -1;
+
note->message = git__strdup((char *)git_blob_rawcontent(blob));
GITERR_CHECK_ALLOC(note->message);
@@ -323,7 +332,11 @@ static int note_new(git_note **out, git_oid *note_oid, git_blob *blob)
}
static int note_lookup(
- git_note **out, git_repository *repo, git_tree *tree, const char *target)
+ git_note **out,
+ git_repository *repo,
+ git_commit *commit,
+ git_tree *tree,
+ const char *target)
{
int error, fanout = 0;
git_oid oid;
@@ -340,7 +353,7 @@ static int note_lookup(
if ((error = git_blob_lookup(&blob, repo, &oid)) < 0)
goto cleanup;
- if ((error = note_new(¬e, &oid, blob)) < 0)
+ if ((error = note_new(¬e, &oid, commit, blob)) < 0)
goto cleanup;
*out = note;
@@ -432,7 +445,7 @@ int git_note_read(git_note **out, git_repository *repo,
if (!(error = retrieve_note_tree_and_commit(
&tree, &commit, repo, ¬es_ref)))
- error = note_lookup(out, repo, tree, target);
+ error = note_lookup(out, repo, commit, tree, target);
git__free(target);
git_tree_free(tree);
@@ -502,6 +515,18 @@ int git_note_default_ref(const char **out, git_repository *repo)
return note_get_default_ref(out, repo);
}
+const git_signature *git_note_committer(const git_note *note)
+{
+ assert(note);
+ return note->committer;
+}
+
+const git_signature *git_note_author(const git_note *note)
+{
+ assert(note);
+ return note->author;
+}
+
const char * git_note_message(const git_note *note)
{
assert(note);
@@ -519,6 +544,8 @@ void git_note_free(git_note *note)
if (note == NULL)
return;
+ git_signature_free(note->committer);
+ git_signature_free(note->author);
git__free(note->message);
git__free(note);
}
diff --git a/src/notes.h b/src/notes.h
index e9cfa00..cfc0ca2 100644
--- a/src/notes.h
+++ b/src/notes.h
@@ -23,6 +23,9 @@
struct git_note {
git_oid id;
+ git_signature *author;
+ git_signature *committer;
+
char *message;
};