Commit 0b4d86af by Vicent Marti

Merge pull request #2098 from arthurschreiber/arthur/add-git_reference_is_note

Add `git_reference_is_note`.
parents 40e10630 50ad7cc2
...@@ -510,6 +510,16 @@ GIT_EXTERN(int) git_reference_is_remote(git_reference *ref); ...@@ -510,6 +510,16 @@ GIT_EXTERN(int) git_reference_is_remote(git_reference *ref);
*/ */
GIT_EXTERN(int) git_reference_is_tag(git_reference *ref); GIT_EXTERN(int) git_reference_is_tag(git_reference *ref);
/**
* Check if a reference is a note
*
* @param ref A git reference
*
* @return 1 when the reference lives in the refs/notes
* namespace; 0 otherwise.
*/
GIT_EXTERN(int) git_reference_is_note(git_reference *ref);
typedef enum { typedef enum {
GIT_REF_FORMAT_NORMAL = 0u, GIT_REF_FORMAT_NORMAL = 0u,
......
...@@ -1113,6 +1113,17 @@ int git_reference_is_tag(git_reference *ref) ...@@ -1113,6 +1113,17 @@ int git_reference_is_tag(git_reference *ref)
return git_reference__is_tag(ref->name); return git_reference__is_tag(ref->name);
} }
int git_reference__is_note(const char *ref_name)
{
return git__prefixcmp(ref_name, GIT_REFS_NOTES_DIR) == 0;
}
int git_reference_is_note(git_reference *ref)
{
assert(ref);
return git_reference__is_note(ref->name);
}
static int peel_error(int error, git_reference *ref, const char* msg) static int peel_error(int error, git_reference *ref, const char* msg)
{ {
giterr_set( giterr_set(
......
...@@ -271,6 +271,21 @@ void test_refs_read__can_determine_if_a_reference_is_a_tag(void) ...@@ -271,6 +271,21 @@ void test_refs_read__can_determine_if_a_reference_is_a_tag(void)
assert_is_tag("refs/remotes/test/master", false); assert_is_tag("refs/remotes/test/master", false);
} }
static void assert_is_note(const char *name, bool expected_noteness)
{
git_reference *reference;
cl_git_pass(git_reference_lookup(&reference, g_repo, name));
cl_assert_equal_i(expected_noteness, git_reference_is_note(reference));
git_reference_free(reference);
}
void test_refs_read__can_determine_if_a_reference_is_a_note(void)
{
assert_is_note("refs/notes/fanout", true);
assert_is_note("refs/heads/packed", false);
assert_is_note("refs/remotes/test/master", false);
}
void test_refs_read__invalid_name_returns_EINVALIDSPEC(void) void test_refs_read__invalid_name_returns_EINVALIDSPEC(void)
{ {
git_reference *reference; git_reference *reference;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment