8000 remote: Handle fetching negative refspecs by ryan-ph · Pull Request #6962 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

remote: Handle fetching negative refspecs #6962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
ryan-ph committed Dec 17, 2024
commit 3d9f4061ca56a3f2c4055904d924974031f59923
9 changes: 9 additions & 0 deletions include/git2/refspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
16 changes: 16 additions & 0 deletions src/libgit2/refspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/libgit2/refspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
0