Support for shallow-since clones/fetches by malcolmwood76 · Pull Request #7093 · libgit2/libgit2 · GitHub
Skip to content

Support for shallow-since clones/fetches#7093

Open
malcolmwood76 wants to merge 5 commits into
libgit2:mainfrom
mathworks:shallowsince
Open

Support for shallow-since clones/fetches#7093
malcolmwood76 wants to merge 5 commits into
libgit2:mainfrom
mathworks:shallowsince

Conversation

@malcolmwood76

@malcolmwood76 malcolmwood76 commented Jun 19, 2025

Copy link
Copy Markdown

Support for the Git "shallow-since" option for clone/fetch. In the Git protocol the term "deepen-since" is used. The implementation below works well when the specified date is older than the newest commit - i.e. when there are commits to fetch.

The Git command-line gives a very poor error when the date specified is newer than newest last commit - i.e. no commits to fetch. The message is "error processing shallow info: 4".

Unfortunately, with this change libgit2 gives an even poorer error (GIT_EEOF). See the function: test_online_shallow__clone_since_recent.

With packet tracing enabled in the Git command-line I can see a "0002" message arriving after the one about "refs/tags/nearly-dangling". But in my test this doesn't seem to arrive, and we get GIT_EEOF in the call to recv_pkt at smart_protocol.c:447 instead.

fixes #6611

Comment thread include/git2/remote.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that we have shallow_since, depth is no longer the only variable that determines whether a fetch is shallow or not. Consider clone.c: if (!options.fetch_opts.depth)
options.fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So we could have a new function that takes git_fetch_options and returns true/false if the fetch would be shallow.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Tried this, but it's difficult to get a combination of name and behaviour. You only know if the fetch "would be shallow" if you know how many commits there are, which we don't. An "unshallow" operation is largely indistinguishable from a shallow fetch with a large depth.

Comment thread src/libgit2/transports/local.c Outdated
Comment thread src/libgit2/transports/smart_pkt.c Outdated

if (wants->depth > 0) {

if (wants->shallow_since != GIT_FETCH_SINCE_UNSPECIFIED) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we do this argument validation up in git_fetch_negotiate?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Can't see a better location that would definitely be hit by every codepath.

Comment thread src/libgit2/transports/smart_pkt.c Outdated
mwood added 2 commits June 20, 2025 13:47
@malcolmwood76

Copy link
Copy Markdown
Author

Renamed the detault value of shallow_since to "GIT_FETCH_SINCE_FULL", and change the value to zero. This makes its usage more consistent with the usage of "depth".

@malcolmwood76 malcolmwood76 changed the title Support for shallow-since clones/fetches Support for shallow-since clones/fetches - fixes #6611 Jun 20, 2025
@malcolmwood76 malcolmwood76 changed the title Support for shallow-since clones/fetches - fixes #6611 Support for shallow-since clones/fetches Jun 20, 2025
@lrm29

lrm29 commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

LGTM

@sigma67

sigma67 commented Feb 26, 2026

Copy link
Copy Markdown

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.

"Shallow Since" Clones Support

3 participants