Commit ee7680d53b7328020576813914ac739b66bb8f8d

nulltoken 2012-05-16T21:21:24

notes: make git_note_foreach() callback signature easier to cope with from a binding perspective

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(&note_data.annotated_object_oid, buf.ptr) < 0)
 		return -1;
 
-	error = note_cb(&note_oid, &target_oid, payload);
+	git_oid_cpy(&note_data.blob_oid, note_oid);
+
+	error = note_cb(&note_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, &note_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, &note_data->annotated_object_oid) == 0);
 
 	(*count)++;