mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
refspec: Add func to distinguish negative refspecs
Negative refspecs were added in Git v2.29.0 and are denoted by prefixing a refspec with a caret. This adds a way to distinguish if a refspec is negative and match negative refspecs.
This commit is contained in:
@@ -78,6 +78,15 @@ GIT_EXTERN(int) git_refspec_force(const git_refspec *refspec);
|
||||
*/
|
||||
GIT_EXTERN(git_direction) git_refspec_direction(const git_refspec *spec);
|
||||
|
||||
/**
|
||||
* Check if a refspec's source descriptor matches a negative reference
|
||||
*
|
||||
* @param refspec the refspec
|
||||
* @param refname the name of the reference to check
|
||||
* @return 1 if the refspec matches, 0 otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_refspec_src_matches_negative(const git_refspec *refspec, const char *refname);
|
||||
|
||||
/**
|
||||
* Check if a refspec's source descriptor matches a reference
|
||||
*
|
||||
|
||||
@@ -225,6 +225,14 @@ int git_refspec_force(const git_refspec *refspec)
|
||||
return refspec->force;
|
||||
}
|
||||
|
||||
int git_refspec_src_matches_negative(const git_refspec *refspec, const char *refname)
|
||||
{
|
||||
if (refspec == NULL || refspec->src == NULL || !git_refspec_is_negative(refspec))
|
||||
return false;
|
||||
|
||||
return (wildmatch(refspec->src + 1, refname, 0) == 0);
|
||||
}
|
||||
|
||||
int git_refspec_src_matches(const git_refspec *refspec, const char *refname)
|
||||
{
|
||||
if (refspec == NULL || refspec->src == NULL)
|
||||
@@ -340,6 +348,14 @@ int git_refspec_is_wildcard(const git_refspec *spec)
|
||||
return (spec->src[strlen(spec->src) - 1] == '*');
|
||||
}
|
||||
|
||||
int git_refspec_is_negative(const git_refspec *spec)
|
||||
{
|
||||
GIT_ASSERT_ARG(spec);
|
||||
GIT_ASSERT_ARG(spec->src);
|
||||
|
||||
return (spec->src[0] == '^' && spec->dst == NULL);
|
||||
}
|
||||
|
||||
git_direction git_refspec_direction(const git_refspec *spec)
|
||||
{
|
||||
GIT_ASSERT_ARG(spec);
|
||||
|
||||
@@ -45,6 +45,14 @@ int git_refspec__serialize(git_str *out, const git_refspec *refspec);
|
||||
*/
|
||||
int git_refspec_is_wildcard(const git_refspec *spec);
|
||||
|
||||
/**
|
||||
* Determines if a refspec is a negative refspec.
|
||||
*
|
||||
* @param spec the refspec
|
||||
* @return 1 if the refspec is a negative, 0 otherwise
|
||||
*/
|
||||
int git_refspec_is_negative(const git_refspec *spec);
|
||||
|
||||
/**
|
||||
* DWIM `spec` with `refs` existing on the remote, append the dwim'ed
|
||||
* result in `out`.
|
||||
|
||||
Reference in New Issue
Block a user