Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
ee7680d5
Commit
ee7680d5
authored
May 16, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notes: make git_note_foreach() callback signature easier to cope with from a binding perspective
parent
9d0011fd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
11 deletions
+24
-11
include/git2/notes.h
+12
-1
src/notes.c
+9
-7
tests-clar/notes/notes.c
+3
-3
No files found.
include/git2/notes.h
View file @
ee7680d5
...
@@ -103,6 +103,17 @@ GIT_EXTERN(void) git_note_free(git_note *note);
...
@@ -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
);
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);
...
@@ -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
);
);
...
...
src/notes.c
View file @
ee7680d5
...
@@ -451,13 +451,13 @@ void git_note_free(git_note *note)
...
@@ -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(
...
@@ -492,10 +492,12 @@ static int process_entry_path(
goto
cleanup
;
goto
cleanup
;
}
}
if
(
git_oid_fromstr
(
&
targe
t_oid
,
buf
.
ptr
)
<
0
)
if
(
git_oid_fromstr
(
&
note_data
.
annotated_objec
t_oid
,
buf
.
ptr
)
<
0
)
return
-
1
;
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:
cleanup:
git_buf_free
(
&
buf
);
git_buf_free
(
&
buf
);
...
@@ -505,7 +507,7 @@ cleanup:
...
@@ -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(
...
@@ -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
)
...
...
tests-clar/notes/notes.c
View file @
ee7680d5
...
@@ -68,7 +68,7 @@ static struct {
...
@@ -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
...
@@ -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
,
&
note_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
,
&
note_data
->
annotated_object_oid
)
==
0
);
(
*
count
)
++
;
(
*
count
)
++
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment