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
7096bf1e
Commit
7096bf1e
authored
Mar 15, 2017
by
Richard Ipsum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notes: Add git_note_commit_read
This also adds tests for this function.
parent
a46e743d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
0 deletions
+81
-0
include/git2/notes.h
+19
-0
src/notes.c
+22
-0
tests/notes/notes.c
+40
-0
No files found.
include/git2/notes.h
View file @
7096bf1e
...
...
@@ -94,6 +94,25 @@ GIT_EXTERN(int) git_note_read(
const
char
*
notes_ref
,
const
git_oid
*
oid
);
/**
* Read the note for an object from a note commit
*
* The note must be freed manually by the user.
*
* @param out pointer to the read note; NULL in case of error
* @param repo repository where to look up the note
* @param notes_commit a pointer to the notes commit object
* @param oid OID of the git object to read the note from
*
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_note_commit_read
(
git_note
**
out
,
git_repository
*
repo
,
git_commit
*
notes_commit
,
const
git_oid
*
oid
);
/**
* Get the note author
*
...
...
src/notes.c
View file @
7096bf1e
...
...
@@ -463,6 +463,28 @@ int git_note_read(git_note **out, git_repository *repo,
return
error
;
}
int
git_note_commit_read
(
git_note
**
out
,
git_repository
*
repo
,
git_commit
*
notes_commit
,
const
git_oid
*
oid
)
{
int
error
;
git_tree
*
tree
=
NULL
;
char
target
[
GIT_OID_HEXSZ
+
1
];
git_oid_tostr
(
target
,
sizeof
(
target
),
oid
);
if
((
error
=
git_commit_tree
(
&
tree
,
notes_commit
))
<
0
)
goto
cleanup
;
error
=
note_lookup
(
out
,
repo
,
notes_commit
,
tree
,
target
);
cleanup:
git_tree_free
(
tree
);
return
error
;
}
int
git_note_create
(
git_oid
*
out
,
git_repository
*
repo
,
...
...
tests/notes/notes.c
View file @
7096bf1e
...
...
@@ -375,6 +375,46 @@ static char *messages[] = {
#define MESSAGES_COUNT (sizeof(messages)/sizeof(messages[0])) - 1
/* Test that we can read a note */
void
test_notes_notes__can_read_a_note
(
void
)
{
git_oid
note_oid
,
target_oid
;
git_note
*
note
;
create_note
(
&
note_oid
,
"refs/notes/i-can-see-dead-notes"
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
,
"I decorate 4a20
\n
"
);
cl_git_pass
(
git_oid_fromstr
(
&
target_oid
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
));
cl_git_pass
(
git_note_read
(
&
note
,
_repo
,
"refs/notes/i-can-see-dead-notes"
,
&
target_oid
));
cl_assert_equal_s
(
git_note_message
(
note
),
"I decorate 4a20
\n
"
);
git_note_free
(
note
);
}
/* Test that we can read a note with from commit api */
void
test_notes_notes__can_read_a_note_from_a_commit
(
void
)
{
git_oid
oid
,
notes_commit_oid
;
git_commit
*
notes_commit
;
git_note
*
note
;
cl_git_pass
(
git_oid_fromstr
(
&
oid
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
));
cl_git_pass
(
git_note_commit_create
(
&
notes_commit_oid
,
NULL
,
_repo
,
NULL
,
_sig
,
_sig
,
&
oid
,
"I decorate 4a20
\n
"
,
1
));
git_commit_lookup
(
&
notes_commit
,
_repo
,
&
notes_commit_oid
);
cl_assert
(
notes_commit
);
cl_git_pass
(
git_note_commit_read
(
&
note
,
_repo
,
notes_commit
,
&
oid
));
cl_assert_equal_s
(
git_note_message
(
note
),
"I decorate 4a20
\n
"
);
git_commit_free
(
notes_commit
);
git_note_free
(
note
);
}
/*
* $ git ls-tree refs/notes/fanout
* 040000 tree 4b22b35d44b5a4f589edf3dc89196399771796ea 84
...
...
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