Skip to content

Commit

Permalink
Restore the shallow clone behavior of the git walkers
Browse files Browse the repository at this point in the history
Resolves trustification#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 <[email protected]>
  • Loading branch information
jcrossley3 committed Sep 11, 2024
1 parent f58d7df commit ee7337a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions modules/importer/src/runner/common/walker/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ impl<H> GitWalker<H, (), ()>
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<String>, handler: H) -> Self {
Self {
source: source.into(),
Expand All @@ -84,7 +87,7 @@ where
working_dir: (),
handler,
progress: (),
depth: 0,
depth: 1, // shallow clone, by default
}
}
}
Expand Down Expand Up @@ -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)
});

Expand All @@ -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()?;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -352,7 +358,7 @@ where

let mut fo = FetchOptions::new();
fo.remote_callbacks(cb);
fo.depth(self.depth);
fo.depth(i32::MAX);
fo
}

Expand Down

0 comments on commit ee7337a

Please sign in to comment.