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

Conversation

ryan-ph
Copy link
Contributor
@ryan-ph ryan-ph commented Dec 16, 2024

Add support for fetching with negative refspecs. Fetching from the
remote with a negative refspec will now validate any references fetched
do not match any negative refspecs and at least one non-negative
refspec. As we must ensure that fetched references do not match any of
the negative refspecs provided, we cannot short-circuit when checking
for matching refspecs.

#6741

@ryan-ph
Copy link
Contributor Author
ryan-ph commented Dec 16, 2024

I'm not super familiar with the entire Git spec, so I'm not 100% sure, but I believe this should cover the rest of the functionality for negative refspecs.

If there are other places that need to be updated, please let me know and I can open up a separate PR to handle those places.

@ryan-ph ryan-ph force-pushed the ryanpham/negative-refspec/remote branch 2 times, most recently from 1ce1baa to e99d721 Compare December 16, 2024 15:24
@ryan-ph
Copy link
Contributor Author
ryan-ph commented Dec 16, 2024

Hm, seems like my test introduced some memory leaks. I'm not entirely sure how to read the output, so I can't tell where exactly it's coming from just from looking at the CI check. Is there a way to run the leak checker locally?

edit: Resolved

@ryan-ph ryan-ph force-pushed the ryanpham/negative-refspec/remote branch from e99d721 to 3764c0b Compare December 17, 2024 00:14
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.
Add support for fetching with negative refspecs. Fetching from the
remote with a negative refspec will now validate any references fetched
do not match _any_ negative refspecs and at least one non-negative
refspec. As we must ensure that fetched references do not match any of
the negative refspecs provided, we cannot short-circuit when checking
for matching refspecs.
size_t i;

git_vector_foreach(&remote->active_refspecs, i, spec) {
if (spec->push)
continue;

if (git_refspec_is_negative(spec) && git_refspec_src_matches_negative(spec, refname))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (git_refspec_is_negative(spec) && git_refspec_src_matches_negative(spec, refname))
if (git_refspec_src_matches_negative(spec, refname))

I think the is_negative check is superfluous, it looks like src_matches_negative does the check itself?

Copy link
Contributor Author
@ryan-ph ryan-ph Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 83994da

if (git_refspec_src_matches(spec, refname))
return spec;
match = spec;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a subtle behavior change? Can there be multiple matches here? Previously, we exited the function as soon as we found a match, returning the first match; now, we would clobber the match, this returning the last match. 🤔

Copy link
Contributor Author
@ryan-ph ryan-ph Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Fixed in 6039d28

Comment on lines 208 to 211
git_strarray refspecs = {
.count = 1,
.strings = &refspec_strs,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use designated initializers; we try to keep support for very ancient compilers so that people can do clever things.

Suggested change
git_strarray refspecs = {
.count = 1,
.strings = &refspec_strs,
};
git_strarray refspecs = { &refspec_strs, 1 };

Copy link
Contributor Author
@ryan-ph ryan-ph Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 099e62c

`git_refspec_is_negative()` is already called by
`git_refspec_src_matches_negative()`, so should not be necessary here.
The previous behavior was to return the first match, so this reverts the
clobbering behavior that was introduced in
f7f30ec.
@ryan-ph ryan-ph requested a review from ethomson December 24, 2024 01:44
@ethomson
Copy link
Member

Thanks for this PR; another really nice change. And for thoughtfully responding to my nitpicking review requests. I'm very thankful for this change. 🙏

@ethomson ethomson merged commit ccc2028 into libgit2:main Dec 24, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0