Merge pull request #705 from nulltoken/fix/note_list_callback_signature notes: make git_note_foreach() callback signature easier to cope with from a binding perspective
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
diff --git a/include/git2/notes.h b/include/git2/notes.h
index 7b2ac1f..ece5b27 100644
--- a/include/git2/notes.h
+++ b/include/git2/notes.h
@@ -103,6 +103,17 @@ GIT_EXTERN(void) git_note_free(git_note *note);
GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo);
/**
+ * Basic components of a note
+ *
+ * - Oid of the blob containing the message
+ * - Oid of the git object being annotated
+ */
+typedef struct {
+ git_oid blob_oid;
+ git_oid annotated_object_oid;
+} git_note_data;
+
+/**
* Loop over all the notes within a specified namespace
* and issue a callback for each one.
*
@@ -119,7 +130,7 @@ GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo);
GIT_EXTERN(int) git_note_foreach(
git_repository *repo,
const char *notes_ref,
- int (*note_cb)(const git_oid *note_oid, const git_oid *annotated_object_oid, void *payload),
+ int (*note_cb)(git_note_data *note_data, void *payload),
void *payload
);
diff --git a/src/notes.c b/src/notes.c
index 1da2ac4..a86a75b 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -451,13 +451,13 @@ void git_note_free(git_note *note)
static int process_entry_path(
const char* entry_path,
- git_oid note_oid,
- int (*note_cb)(const git_oid *note_oid, const git_oid *annotated_object_oid, void *payload),
+ const git_oid *note_oid,
+ int (*note_cb)(git_note_data *note_data, void *payload),
void *payload)
{
int i = 0, j = 0, error = -1, len;
- git_oid target_oid;
git_buf buf = GIT_BUF_INIT;
+ git_note_data note_data;
if (git_buf_puts(&buf, entry_path) < 0)
goto cleanup;
@@ -492,10 +492,12 @@ static int process_entry_path(
goto cleanup;
}
- if (git_oid_fromstr(&target_oid, buf.ptr) < 0)
+ if (git_oid_fromstr(¬e_data.annotated_object_oid, buf.ptr) < 0)
return -1;
- error = note_cb(¬e_oid, &target_oid, payload);
+ git_oid_cpy(¬e_data.blob_oid, note_oid);
+
+ error = note_cb(¬e_data, payload);
cleanup:
git_buf_free(&buf);
@@ -505,7 +507,7 @@ cleanup:
int git_note_foreach(
git_repository *repo,
const char *notes_ref,
- int (*note_cb)(const git_oid *note_oid, const git_oid *annotated_object_oid, void *payload),
+ int (*note_cb)(git_note_data *note_data, void *payload),
void *payload)
{
int error = -1;
@@ -530,7 +532,7 @@ int git_note_foreach(
goto cleanup;
while (item) {
- if (process_entry_path(item->path, item->oid, note_cb, payload) < 0)
+ if (process_entry_path(item->path, &item->oid, note_cb, payload) < 0)
goto cleanup;
if (git_iterator_advance(iter, &item) < 0)
diff --git a/tests-clar/notes/notes.c b/tests-clar/notes/notes.c
index 9c50f1a..5185f25 100644
--- a/tests-clar/notes/notes.c
+++ b/tests-clar/notes/notes.c
@@ -68,7 +68,7 @@ static struct {
#define EXPECTATIONS_COUNT (sizeof(list_expectations)/sizeof(list_expectations[0])) - 1
-static int note_list_cb(const git_oid *note_oid, const git_oid *annotated_object_oid, void *payload)
+static int note_list_cb(git_note_data *note_data, void *payload)
{
git_oid expected_note_oid, expected_target_oid;
@@ -77,10 +77,10 @@ static int note_list_cb(const git_oid *note_oid, const git_oid *annotated_object
cl_assert(*count < EXPECTATIONS_COUNT);
cl_git_pass(git_oid_fromstr(&expected_note_oid, list_expectations[*count].note_sha));
- cl_assert(git_oid_cmp(&expected_note_oid, note_oid) == 0);
+ cl_assert(git_oid_cmp(&expected_note_oid, ¬e_data->blob_oid) == 0);
cl_git_pass(git_oid_fromstr(&expected_target_oid, list_expectations[*count].annotated_object_sha));
- cl_assert(git_oid_cmp(&expected_target_oid, annotated_object_oid) == 0);
+ cl_assert(git_oid_cmp(&expected_target_oid, ¬e_data->annotated_object_oid) == 0);
(*count)++;