Skip to content
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

Add shallow cloning capability #979

Merged
merged 1 commit into from
Sep 18, 2023
Merged

Conversation

blyxyas
Copy link
Member

@blyxyas blyxyas commented Aug 8, 2023

Add shallow cloning (as well as customizable depth), introduced in libgit2 v1.7.0

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Thanks for adding this!

Can you also include a test for it?

src/build.rs Outdated
Comment on lines 174 to 175
/// Specify fetch depth, a value less than zero is interpreted as pull everything (effectively the same as no declaring a limit depth)
pub fn depth(&mut self, depth: i32) -> &mut RepoBuilder<'cb> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of adding a new method here, would it be possible to leave this as a setting that required calling .fetch_options(...) instead? I am reluctant to try to repeat low-level option settings, since that would require deciding which settings are or are not replicated, and possibly causing confusion when something could be specified in multiple places.

Copy link
Member Author

@blyxyas blyxyas Aug 29, 2023

Choose a reason for hiding this comment

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

So should this be removed? I find the depth parameter to be kinda (very) important imo, but it can be removed without any problems.

src/build.rs Outdated
Comment on lines 186 to 193
// if let Some(ref fetch_opts) = &self.fetch_opts {
// fetch_opts.depth(depth);
// } else {
// let mut fo = FetchOptions::new();
// fo.depth(depth);
// self.fetch_options(fo);
// }
// self
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks to be some vestigial work?

src/repo.rs Outdated
Comment on lines 344 to 347
/// Clone a remote repository with a depth of one (shallow cloning)
///
/// Similar to `git clone --depth 1`
pub fn shallow_clone<P: AsRef<Path>>(url: &str, into: P) -> Result<Repository, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the comment on RepoBuilder, I think I would like to avoid having too many convenience functions, since there is a somewhat combinatorial explosion of all the different options someone might want. Using a builder pattern can avoid adding all sorts of variants of different methods.

@blyxyas
Copy link
Member Author

blyxyas commented Aug 26, 2023

I'm not sure how to add a test for this, it seems like there aren't any tests for cloning features.

@ehuss
Copy link
Contributor

ehuss commented Aug 26, 2023

I'm not sure how to add a test for this, it seems like there aren't any tests for cloning features.

At the bottom of remote.rs there are various tests which set RemoteCallbacks options. I would set up a test that creates a repository with 2 commits. Then clone it with depth=1, and verify there is only one commit in the clone. The test.rs module contains some testing utilities for creating commits and such.

@blyxyas
Copy link
Member Author

blyxyas commented Aug 30, 2023

This new commit addresses the comments and contains a first attempt to test it. It should work but it doesn't, I need some guidance here.

The test creates a repo and commits two times to that new repo. Then creates a TempDir to clone the original repo using fetch options with depth set to 1. But when checking for the first commit that shouldn't exist because depth is 1, it's still there (??).

@rawhuul
Copy link

rawhuul commented Sep 10, 2023

Any work on this?

@ehuss
Copy link
Contributor

ehuss commented Sep 12, 2023

Unfortunately it looks like libgit2 does not do shallow clones on local repositories. I think it requires the smart protocol and relies on the server to figure out what to fetch. I don't think we have any testing infrastructure for the smart protocol, so I think we'll just need to not include a test for this for now.

I have filed libgit2/libgit2#6634 on that issue.

@blyxyas
Copy link
Member Author

blyxyas commented Sep 12, 2023

So for now, it can go without a test? (I'll add a fixme)

@ehuss
Copy link
Contributor

ehuss commented Sep 12, 2023

Yep.

@blyxyas blyxyas force-pushed the shallow-clone branch 2 times, most recently from 4680cd1 to 722b7d0 Compare September 12, 2023 21:05
@extrawurst extrawurst mentioned this pull request Sep 16, 2023
@rawhuul
Copy link

rawhuul commented Sep 17, 2023

Why it has not been merged yet? I mean is there nay issue preventing it?

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Thanks!

@ehuss ehuss added this pull request to the merge queue Sep 18, 2023
Merged via the queue into rust-lang:master with commit 2b2fb37 Sep 18, 2023
7 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.

None yet

3 participants