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
60bee89d
Commit
60bee89d
authored
Mar 19, 2017
by
Richard Ipsum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notes: Add git_note_commit_iterator_new
This also adds tests for this function.
parent
9a02725d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
+76
-0
include/git2/notes.h
+14
-0
src/notes.c
+19
-0
tests/notes/notes.c
+43
-0
No files found.
include/git2/notes.h
View file @
60bee89d
...
...
@@ -52,6 +52,20 @@ GIT_EXTERN(int) git_note_iterator_new(
const
char
*
notes_ref
);
/**
* Creates a new iterator for notes from a commit
*
* The iterator must be freed manually by the user.
*
* @param out pointer to the iterator
* @param notes_commit a pointer to the notes commit object
*
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_note_commit_iterator_new
(
git_note_iterator
**
out
,
git_commit
*
notes_commit
);
/**
* Frees an git_note_iterator
*
* @param it pointer to the iterator
...
...
src/notes.c
View file @
60bee89d
...
...
@@ -766,6 +766,25 @@ cleanup:
return
error
;
}
int
git_note_commit_iterator_new
(
git_note_iterator
**
it
,
git_commit
*
notes_commit
)
{
int
error
;
git_tree
*
tree
;
if
((
error
=
git_commit_tree
(
&
tree
,
notes_commit
))
<
0
)
goto
cleanup
;
if
((
error
=
git_iterator_for_tree
(
it
,
tree
,
NULL
))
<
0
)
git_iterator_free
(
*
it
);
cleanup:
git_tree_free
(
tree
);
return
error
;
}
int
git_note_next
(
git_oid
*
note_id
,
git_oid
*
annotated_id
,
...
...
tests/notes/notes.c
View file @
60bee89d
...
...
@@ -594,3 +594,46 @@ void test_notes_notes__empty_iterate(void)
cl_git_fail
(
git_note_iterator_new
(
&
iter
,
_repo
,
"refs/notes/commits"
));
}
void
test_notes_notes__iterate_from_commit
(
void
)
{
git_note_iterator
*
iter
;
git_note
*
note
;
git_oid
note_id
,
annotated_id
;
git_oid
oids
[
2
];
git_oid
notes_commit_oids
[
2
];
git_commit
*
notes_commits
[
2
];
const
char
*
note_message
[]
=
{
"I decorate a65f
\n
"
,
"I decorate c478
\n
"
};
int
i
,
err
;
cl_git_pass
(
git_oid_fromstr
(
&
(
oids
[
0
]),
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
));
cl_git_pass
(
git_oid_fromstr
(
&
(
oids
[
1
]),
"c47800c7266a2be04c571c04d5a6614691ea99bd"
));
cl_git_pass
(
git_note_commit_create
(
&
notes_commit_oids
[
0
],
NULL
,
_repo
,
NULL
,
_sig
,
_sig
,
&
(
oids
[
0
]),
note_message
[
0
],
0
));
git_commit_lookup
(
&
notes_commits
[
0
],
_repo
,
&
notes_commit_oids
[
0
]);
cl_assert
(
notes_commits
[
0
]);
cl_git_pass
(
git_note_commit_create
(
&
notes_commit_oids
[
1
],
NULL
,
_repo
,
notes_commits
[
0
],
_sig
,
_sig
,
&
(
oids
[
1
]),
note_message
[
1
],
0
));
git_commit_lookup
(
&
notes_commits
[
1
],
_repo
,
&
notes_commit_oids
[
1
]);
cl_assert
(
notes_commits
[
1
]);
cl_git_pass
(
git_note_commit_iterator_new
(
&
iter
,
notes_commits
[
1
]));
for
(
i
=
0
;
(
err
=
git_note_next
(
&
note_id
,
&
annotated_id
,
iter
))
>=
0
;
++
i
)
{
cl_git_pass
(
git_note_commit_read
(
&
note
,
_repo
,
notes_commits
[
1
],
&
annotated_id
));
cl_assert_equal_s
(
git_note_message
(
note
),
note_message
[
i
]);
git_note_free
(
note
);
}
cl_assert_equal_i
(
GIT_ITEROVER
,
err
);
cl_assert_equal_i
(
2
,
i
);
git_note_iterator_free
(
iter
);
git_commit_free
(
notes_commits
[
0
]);
git_commit_free
(
notes_commits
[
1
]);
}
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