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
Changes from all commits
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
15 changes: 14 additions & 1 deletion src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct RemoteHead<'remote> {
/// Options which can be specified to various fetch operations.
pub struct FetchOptions<'cb> {
callbacks: Option<RemoteCallbacks<'cb>>,
depth: i32,
proxy: Option<ProxyOptions<'cb>>,
prune: FetchPrune,
update_fetchhead: bool,
Expand Down Expand Up @@ -509,6 +510,7 @@ impl<'cb> FetchOptions<'cb> {
follow_redirects: RemoteRedirect::Initial,
custom_headers: Vec::new(),
custom_headers_ptrs: Vec::new(),
depth: 0, // Not limited depth
}
}

Expand Down Expand Up @@ -538,6 +540,17 @@ impl<'cb> FetchOptions<'cb> {
self
}

/// Set fetch depth, a value less or equal to 0 is interpreted as pull
/// everything (effectively the same as not declaring a limit depth).

// FIXME(blyxyas): We currently don't have a test for shallow functions
// because libgit2 doesn't support local shallow clones.
// https://github.com/rust-lang/git2-rs/pull/979#issuecomment-1716299900
pub fn depth(&mut self, depth: i32) -> &mut Self {
self.depth = depth.max(0);
self
}

/// Set how to behave regarding tags on the remote, such as auto-downloading
/// tags for objects we're downloading or downloading all of them.
///
Expand Down Expand Up @@ -590,7 +603,7 @@ impl<'cb> Binding for FetchOptions<'cb> {
prune: crate::call::convert(&self.prune),
update_fetchhead: crate::call::convert(&self.update_fetchhead),
download_tags: crate::call::convert(&self.download_tags),
depth: 0, // GIT_FETCH_DEPTH_FULL.
depth: self.depth,
follow_redirects: self.follow_redirects.raw(),
custom_headers: git_strarray {
count: self.custom_headers_ptrs.len(),
Expand Down