mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-04 19:50:19 +00:00
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
This commit is contained in:
commit
38f4f15824
@ -102,6 +102,17 @@ GIT_EXTERN(void) git_note_free(git_note *note);
|
|||||||
*/
|
*/
|
||||||
GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo);
|
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
|
* Loop over all the notes within a specified namespace
|
||||||
* and issue a callback for each one.
|
* 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_EXTERN(int) git_note_foreach(
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
const char *notes_ref,
|
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
|
void *payload
|
||||||
);
|
);
|
||||||
|
|
||||||
|
16
src/notes.c
16
src/notes.c
@ -451,13 +451,13 @@ void git_note_free(git_note *note)
|
|||||||
|
|
||||||
static int process_entry_path(
|
static int process_entry_path(
|
||||||
const char* entry_path,
|
const char* entry_path,
|
||||||
git_oid note_oid,
|
const git_oid *note_oid,
|
||||||
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)
|
void *payload)
|
||||||
{
|
{
|
||||||
int i = 0, j = 0, error = -1, len;
|
int i = 0, j = 0, error = -1, len;
|
||||||
git_oid target_oid;
|
|
||||||
git_buf buf = GIT_BUF_INIT;
|
git_buf buf = GIT_BUF_INIT;
|
||||||
|
git_note_data note_data;
|
||||||
|
|
||||||
if (git_buf_puts(&buf, entry_path) < 0)
|
if (git_buf_puts(&buf, entry_path) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -492,10 +492,12 @@ static int process_entry_path(
|
|||||||
goto cleanup;
|
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;
|
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:
|
cleanup:
|
||||||
git_buf_free(&buf);
|
git_buf_free(&buf);
|
||||||
@ -505,7 +507,7 @@ cleanup:
|
|||||||
int git_note_foreach(
|
int git_note_foreach(
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
const char *notes_ref,
|
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)
|
void *payload)
|
||||||
{
|
{
|
||||||
int error = -1;
|
int error = -1;
|
||||||
@ -530,7 +532,7 @@ int git_note_foreach(
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
while (item) {
|
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;
|
goto cleanup;
|
||||||
|
|
||||||
if (git_iterator_advance(iter, &item) < 0)
|
if (git_iterator_advance(iter, &item) < 0)
|
||||||
|
@ -68,7 +68,7 @@ static struct {
|
|||||||
|
|
||||||
#define EXPECTATIONS_COUNT (sizeof(list_expectations)/sizeof(list_expectations[0])) - 1
|
#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;
|
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_assert(*count < EXPECTATIONS_COUNT);
|
||||||
|
|
||||||
cl_git_pass(git_oid_fromstr(&expected_note_oid, list_expectations[*count].note_sha));
|
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_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)++;
|
(*count)++;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user