From ee7337ab9e0183ce9017a4d044dc727452c866cf Mon Sep 17 00:00:00 2001 From: Jim Crossley Date: Wed, 11 Sep 2024 19:39:19 -0400 Subject: [PATCH] Restore the shallow clone behavior of the git walkers Resolves #775 I finally figured out how to update the shallow clone, setting the fetch depth to `i32::MAX` to signal infinite fetch depth, per https://git-scm.com/docs/shallow I had wrongly assumed depth=0 signaled infinite depth -- it does for an initial clone, but not an update of a shallow one. Essentially, this improves the "day 0" experience -- the first walk of the shallow clone takes no more than a few minutes. But the annoying ~30 minute fetch is deferred to the first update of the shallow clone, effectively turning it into a deep clone, after which subsequent fetches are fast. I think that's a workable compromise until libgit2's perf issue is addressed. Signed-off-by: Jim Crossley --- modules/importer/src/runner/common/walker/git.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/importer/src/runner/common/walker/git.rs b/modules/importer/src/runner/common/walker/git.rs index 813c88d16..77ea12fc1 100644 --- a/modules/importer/src/runner/common/walker/git.rs +++ b/modules/importer/src/runner/common/walker/git.rs @@ -75,6 +75,9 @@ impl GitWalker where H: Handler, { + /// Create a new GitWalker for a given repo and handler. By + /// default, a "shallow clone" (depth=1) of the repo will be + /// walked. pub fn new(source: impl Into, handler: H) -> Self { Self { source: source.into(), @@ -84,7 +87,7 @@ where working_dir: (), handler, progress: (), - depth: 0, + depth: 1, // shallow clone, by default } } } @@ -195,7 +198,10 @@ where builder.branch(branch); } - let fo = self.create_fetch_options(); + let mut fo = Self::create_fetch_options(); + if self.continuation.0.is_none() { + fo.depth(self.depth); + } builder.fetch_options(fo).clone(&self.source, path) }); @@ -209,7 +215,7 @@ where log::info!("Fetching updates"); let mut remote = repo.find_remote("origin")?; - let mut fo = self.create_fetch_options(); + let mut fo = Self::create_fetch_options(); remote.fetch(&[] as &[&str], Some(&mut fo), None)?; remote.disconnect()?; @@ -317,7 +323,7 @@ where Ok(Continuation(Some(commit.to_string()))) } - fn create_fetch_options<'cb>(&self) -> FetchOptions<'cb> { + fn create_fetch_options<'cb>() -> FetchOptions<'cb> { let mut cb = RemoteCallbacks::new(); cb.transfer_progress(|progress| { let received = progress.received_objects(); @@ -352,7 +358,7 @@ where let mut fo = FetchOptions::new(); fo.remote_callbacks(cb); - fo.depth(self.depth); + fo.depth(i32::MAX); fo }