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
07871d3a
Commit
07871d3a
authored
Jan 03, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1181 from nvloff/allow_note_overwrite
Allow note overwrite
parents
0db4cd04
8716b499
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
16 deletions
+45
-16
include/git2/notes.h
+3
-1
src/notes.c
+13
-10
tests-clar/notes/notes.c
+28
-4
tests-clar/notes/notesref.c
+1
-1
No files found.
include/git2/notes.h
View file @
07871d3a
...
...
@@ -76,6 +76,7 @@ GIT_EXTERN(const git_oid *) git_note_oid(const git_note *note);
* defaults to "refs/notes/commits"
* @param oid OID of the git object to decorate
* @param note Content of the note to add for object oid
* @param force Overwrite existing note
*
* @return 0 or an error code
*/
...
...
@@ -86,7 +87,8 @@ GIT_EXTERN(int) git_note_create(
const
git_signature
*
committer
,
const
char
*
notes_ref
,
const
git_oid
*
oid
,
const
char
*
note
);
const
char
*
note
,
int
force
);
/**
...
...
src/notes.c
View file @
07871d3a
...
...
@@ -129,10 +129,10 @@ static int manipulate_note_in_tree_r(
git_tree
*
parent
,
git_oid
*
note_oid
,
const
char
*
annotated_object_sha
,
int
fanout
,
int
fanout
,
int
(
*
note_exists_cb
)(
git_tree
**
out
,
git_repository
*
repo
,
git_tree
**
out
,
git_repository
*
repo
,
git_tree
*
parent
,
git_oid
*
note_oid
,
const
char
*
annotated_object_sha
,
...
...
@@ -147,7 +147,7 @@ static int manipulate_note_in_tree_r(
int
fanout
,
int
current_error
))
{
int
error
=
-
1
;
int
error
=
-
1
;
git_tree
*
subtree
=
NULL
,
*
new
=
NULL
;
char
subtree_name
[
3
];
...
...
@@ -270,12 +270,13 @@ static int note_write(git_oid *out,
const
char
*
note
,
git_tree
*
commit_tree
,
const
char
*
target
,
git_commit
**
parents
)
git_commit
**
parents
,
int
allow_note_overwrite
)
{
int
error
;
git_oid
oid
;
git_tree
*
tree
=
NULL
;
// TODO: should we apply filters?
/* create note object */
if
((
error
=
git_blob_create_frombuffer
(
&
oid
,
repo
,
note
,
strlen
(
note
)))
<
0
)
...
...
@@ -283,7 +284,8 @@ static int note_write(git_oid *out,
if
((
error
=
manipulate_note_in_tree_r
(
&
tree
,
repo
,
commit_tree
,
&
oid
,
target
,
0
,
insert_note_in_tree_eexists_cb
,
insert_note_in_tree_enotfound_cb
))
<
0
)
allow_note_overwrite
?
insert_note_in_tree_enotfound_cb
:
insert_note_in_tree_eexists_cb
,
insert_note_in_tree_enotfound_cb
))
<
0
)
goto
cleanup
;
if
(
out
)
...
...
@@ -351,7 +353,7 @@ static int note_remove(git_repository *repo,
int
error
;
git_tree
*
tree_after_removal
=
NULL
;
git_oid
oid
;
if
((
error
=
manipulate_note_in_tree_r
(
&
tree_after_removal
,
repo
,
tree
,
NULL
,
target
,
0
,
remove_note_in_tree_eexists_cb
,
remove_note_in_tree_enotfound_cb
))
<
0
)
...
...
@@ -449,7 +451,8 @@ int git_note_create(
const
git_signature
*
committer
,
const
char
*
notes_ref
,
const
git_oid
*
oid
,
const
char
*
note
)
const
char
*
note
,
int
allow_note_overwrite
)
{
int
error
;
char
*
target
=
NULL
;
...
...
@@ -465,7 +468,7 @@ int git_note_create(
goto
cleanup
;
error
=
note_write
(
out
,
repo
,
author
,
committer
,
notes_ref
,
note
,
tree
,
target
,
&
commit
);
note
,
tree
,
target
,
&
commit
,
allow_note_overwrite
);
cleanup:
git__free
(
target
);
...
...
tests-clar/notes/notes.c
View file @
07871d3a
...
...
@@ -34,7 +34,7 @@ static void create_note(git_oid *note_oid, const char *canonical_namespace, cons
git_oid
oid
;
cl_git_pass
(
git_oid_fromstr
(
&
oid
,
target_sha
));
cl_git_pass
(
git_note_create
(
note_oid
,
_repo
,
_sig
,
_sig
,
canonical_namespace
,
&
oid
,
message
));
cl_git_pass
(
git_note_create
(
note_oid
,
_repo
,
_sig
,
_sig
,
canonical_namespace
,
&
oid
,
message
,
0
));
}
static
struct
{
...
...
@@ -194,16 +194,40 @@ void test_notes_notes__creating_a_note_on_a_target_which_already_has_one_returns
cl_git_pass
(
git_oid_fromstr
(
&
target_oid
,
"08b041783f40edfe12bb406c9c9a8a040177c125"
));
create_note
(
&
note_oid
,
NULL
,
"08b041783f40edfe12bb406c9c9a8a040177c125"
,
"hello world
\n
"
);
error
=
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
NULL
,
&
target_oid
,
"hello world
\n
"
);
error
=
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
NULL
,
&
target_oid
,
"hello world
\n
"
,
0
);
cl_git_fail
(
error
);
cl_assert_equal_i
(
GIT_EEXISTS
,
error
);
create_note
(
&
note_oid
,
"refs/notes/some/namespace"
,
"08b041783f40edfe12bb406c9c9a8a040177c125"
,
"hello world
\n
"
);
error
=
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
"refs/notes/some/namespace"
,
&
target_oid
,
"hello world
\n
"
);
error
=
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
"refs/notes/some/namespace"
,
&
target_oid
,
"hello world
\n
"
,
0
);
cl_git_fail
(
error
);
cl_assert_equal_i
(
GIT_EEXISTS
,
error
);
}
void
test_notes_notes__creating_a_note_on_a_target_can_overwrite_existing_note
(
void
)
{
git_oid
note_oid
,
target_oid
;
git_note
*
note
,
*
namespace_note
;
cl_git_pass
(
git_oid_fromstr
(
&
target_oid
,
"08b041783f40edfe12bb406c9c9a8a040177c125"
));
create_note
(
&
note_oid
,
NULL
,
"08b041783f40edfe12bb406c9c9a8a040177c125"
,
"hello old world
\n
"
);
cl_git_pass
(
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
NULL
,
&
target_oid
,
"hello new world
\n
"
,
1
));
cl_git_pass
(
git_note_read
(
&
note
,
_repo
,
NULL
,
&
target_oid
));
assert_note_equal
(
note
,
"hello new world
\n
"
,
&
note_oid
);
create_note
(
&
note_oid
,
"refs/notes/some/namespace"
,
"08b041783f40edfe12bb406c9c9a8a040177c125"
,
"hello old world
\n
"
);
cl_git_pass
(
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
"refs/notes/some/namespace"
,
&
target_oid
,
"hello new ref world
\n
"
,
1
));
cl_git_pass
(
git_note_read
(
&
namespace_note
,
_repo
,
"refs/notes/some/namespace"
,
&
target_oid
));
assert_note_equal
(
namespace_note
,
"hello new ref world
\n
"
,
&
note_oid
);
git_note_free
(
note
);
git_note_free
(
namespace_note
);
}
static
char
*
messages
[]
=
{
"08c041783f40edfe12bb406c9c9a8a040177c125"
,
"96c45fbe09ab7445fc7c60fd8d17f32494399343"
,
...
...
@@ -244,7 +268,7 @@ void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void)
cl_git_pass
(
git_oid_fromstr
(
&
target_oid
,
"08b041783f40edfe12bb406c9c9a8a040177c125"
));
for
(
i
=
0
;
i
<
MESSAGES_COUNT
;
i
++
)
{
cl_git_pass
(
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
"refs/notes/fanout"
,
&
target_oid
,
messages
[
i
]));
cl_git_pass
(
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
"refs/notes/fanout"
,
&
target_oid
,
messages
[
i
]
,
0
));
cl_git_pass
(
git_note_read
(
&
_note
,
_repo
,
"refs/notes/fanout"
,
&
target_oid
));
git_note_free
(
_note
);
...
...
tests-clar/notes/notesref.c
View file @
07871d3a
...
...
@@ -42,7 +42,7 @@ void test_notes_notesref__config_corenotesref(void)
cl_git_pass
(
git_config_set_string
(
_cfg
,
"core.notesRef"
,
"refs/notes/mydefaultnotesref"
));
cl_git_pass
(
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
NULL
,
&
oid
,
"test123test
\n
"
));
cl_git_pass
(
git_note_create
(
&
note_oid
,
_repo
,
_sig
,
_sig
,
NULL
,
&
oid
,
"test123test
\n
"
,
0
));
cl_git_pass
(
git_note_read
(
&
_note
,
_repo
,
NULL
,
&
oid
));
cl_assert
(
!
strcmp
(
git_note_message
(
_note
),
"test123test
\n
"
));
...
...
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