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
d3a60dc2
Commit
d3a60dc2
authored
May 05, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #663 from schu/notes-honor-config
Honor core.notesRef config option
parents
674a1985
630c5a4a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
6 deletions
+108
-6
include/git2/notes.h
+10
-0
src/notes.c
+41
-6
tests-clar/notes/notesref.c
+57
-0
No files found.
include/git2/notes.h
View file @
d3a60dc2
...
...
@@ -92,6 +92,16 @@ GIT_EXTERN(int) git_note_remove(git_repository *repo, const char *notes_ref,
*/
GIT_EXTERN
(
void
)
git_note_free
(
git_note
*
note
);
/**
* Get the default notes reference for a repository
*
* @param out Pointer to the default notes reference
* @param repo The Git repository
*
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN
(
int
)
git_note_default_ref
(
const
char
**
out
,
git_repository
*
repo
);
/** @} */
GIT_END_DECL
#endif
src/notes.c
View file @
d3a60dc2
...
...
@@ -9,6 +9,7 @@
#include "git2.h"
#include "refs.h"
#include "config.h"
static
int
find_subtree
(
git_tree
**
subtree
,
const
git_oid
*
root
,
git_repository
*
repo
,
const
char
*
target
,
int
*
fanout
)
...
...
@@ -262,6 +263,25 @@ static int note_remove(git_repository *repo,
return
error
;
}
static
int
note_get_default_ref
(
const
char
**
out
,
git_repository
*
repo
)
{
int
error
;
git_config
*
cfg
;
*
out
=
NULL
;
if
(
git_repository_config__weakptr
(
&
cfg
,
repo
)
<
0
)
return
-
1
;
error
=
git_config_get_string
(
cfg
,
"core.notesRef"
,
out
);
if
(
error
==
GIT_ENOTFOUND
)
{
*
out
=
GIT_NOTES_DEFAULT_REF
;
return
0
;
}
return
error
;
}
int
git_note_read
(
git_note
**
out
,
git_repository
*
repo
,
const
char
*
notes_ref
,
const
git_oid
*
oid
)
{
...
...
@@ -273,8 +293,11 @@ int git_note_read(git_note **out, git_repository *repo,
*
out
=
NULL
;
if
(
!
notes_ref
)
notes_ref
=
GIT_NOTES_DEFAULT_REF
;
if
(
!
notes_ref
)
{
error
=
note_get_default_ref
(
&
notes_ref
,
repo
);
if
(
error
<
0
)
return
error
;
}
error
=
git_reference_lookup
(
&
ref
,
repo
,
notes_ref
);
if
(
error
<
0
)
...
...
@@ -314,8 +337,11 @@ int git_note_create(
git_commit
*
commit
=
NULL
;
git_reference
*
ref
;
if
(
!
notes_ref
)
notes_ref
=
GIT_NOTES_DEFAULT_REF
;
if
(
!
notes_ref
)
{
error
=
note_get_default_ref
(
&
notes_ref
,
repo
);
if
(
error
<
0
)
return
error
;
}
error
=
git_reference_lookup
(
&
ref
,
repo
,
notes_ref
);
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
...
...
@@ -359,8 +385,11 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
git_commit
*
commit
;
git_reference
*
ref
;
if
(
!
notes_ref
)
notes_ref
=
GIT_NOTES_DEFAULT_REF
;
if
(
!
notes_ref
)
{
error
=
note_get_default_ref
(
&
notes_ref
,
repo
);
if
(
error
<
0
)
return
error
;
}
error
=
git_reference_lookup
(
&
ref
,
repo
,
notes_ref
);
if
(
error
<
0
)
...
...
@@ -388,6 +417,12 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
return
error
;
}
int
git_note_default_ref
(
const
char
**
out
,
git_repository
*
repo
)
{
assert
(
repo
);
return
note_get_default_ref
(
out
,
repo
);
}
const
char
*
git_note_message
(
git_note
*
note
)
{
assert
(
note
);
...
...
tests-clar/notes/notesref.c
0 → 100644
View file @
d3a60dc2
#include "clar_libgit2.h"
#include "notes.h"
static
git_repository
*
_repo
;
static
git_note
*
_note
;
static
git_signature
*
_sig
;
static
git_config
*
_cfg
;
void
test_notes_notesref__initialize
(
void
)
{
cl_fixture_sandbox
(
"testrepo.git"
);
cl_git_pass
(
git_repository_open
(
&
_repo
,
"testrepo.git"
));
}
void
test_notes_notesref__cleanup
(
void
)
{
git_note_free
(
_note
);
git_signature_free
(
_sig
);
git_config_free
(
_cfg
);
git_repository_free
(
_repo
);
cl_fixture_cleanup
(
"testrepo.git"
);
}
void
test_notes_notesref__config_corenotesref
(
void
)
{
git_oid
oid
,
note_oid
;
const
char
*
default_ref
;
cl_git_pass
(
git_signature_now
(
&
_sig
,
"alice"
,
"alice@example.com"
));
cl_git_pass
(
git_oid_fromstr
(
&
oid
,
"8496071c1b46c854b31185ea97743be6a8774479"
));
cl_git_pass
(
git_repository_config
(
&
_cfg
,
_repo
));
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_read
(
&
_note
,
_repo
,
NULL
,
&
oid
));
cl_assert
(
!
strcmp
(
git_note_message
(
_note
),
"test123test
\n
"
));
cl_assert
(
!
git_oid_cmp
(
git_note_oid
(
_note
),
&
note_oid
));
git_note_free
(
_note
);
cl_git_pass
(
git_note_read
(
&
_note
,
_repo
,
"refs/notes/mydefaultnotesref"
,
&
oid
));
cl_assert
(
!
strcmp
(
git_note_message
(
_note
),
"test123test
\n
"
));
cl_assert
(
!
git_oid_cmp
(
git_note_oid
(
_note
),
&
note_oid
));
cl_git_pass
(
git_note_default_ref
(
&
default_ref
,
_repo
));
cl_assert
(
!
strcmp
(
default_ref
,
"refs/notes/mydefaultnotesref"
));
cl_git_pass
(
git_config_delete
(
_cfg
,
"core.notesRef"
));
cl_git_pass
(
git_note_default_ref
(
&
default_ref
,
_repo
));
cl_assert
(
!
strcmp
(
default_ref
,
GIT_NOTES_DEFAULT_REF
));
}
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