Skip to content

Commit

Permalink
perf(git): Skip submodules update on existing checkouts
Browse files Browse the repository at this point in the history
Fixes #14603
  • Loading branch information
epage committed Nov 11, 2024
1 parent ecb6398 commit e82ad5f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/cargo/sources/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,14 @@ impl GitDatabase {
.filter(|co| co.is_fresh())
{
Some(co) => co,
None => GitCheckout::clone_into(dest, self, rev, gctx)?,
None => {
let (checkout, guard) = GitCheckout::clone_into(dest, self, rev, gctx)?;
checkout.update_submodules(gctx)?;
guard.mark_ok()?;
checkout
}
};
checkout.update_submodules(gctx)?;

Ok(checkout)
}

Expand Down Expand Up @@ -280,7 +285,7 @@ impl<'a> GitCheckout<'a> {
database: &'a GitDatabase,
revision: git2::Oid,
gctx: &GlobalContext,
) -> CargoResult<GitCheckout<'a>> {
) -> CargoResult<(GitCheckout<'a>, CheckoutGuard)> {
let dirname = into.parent().unwrap();
paths::create_dir_all(&dirname)?;
if into.exists() {
Expand Down Expand Up @@ -329,8 +334,8 @@ impl<'a> GitCheckout<'a> {
let repo = repo.unwrap();

let checkout = GitCheckout::new(database, revision, repo);
checkout.reset(gctx)?;
Ok(checkout)
let guard = checkout.reset(gctx)?;
Ok((checkout, guard))
}

/// Checks if the `HEAD` of this checkout points to the expected revision.
Expand All @@ -355,10 +360,11 @@ impl<'a> GitCheckout<'a> {
/// To enable this we have a dummy file in our checkout, [`.cargo-ok`],
/// which if present means that the repo has been successfully reset and is
/// ready to go. Hence if we start to do a reset, we make sure this file
/// *doesn't* exist, and then once we're done we create the file.
/// *doesn't* exist. The caller of [`reset`] has an option to perform additional operations
/// (e.g. submodule update) before marking the check-out as ready.
///
/// [`.cargo-ok`]: CHECKOUT_READY_LOCK
fn reset(&self, gctx: &GlobalContext) -> CargoResult<()> {
fn reset(&self, gctx: &GlobalContext) -> CargoResult<CheckoutGuard> {
let guard = CheckoutGuard::guard(&self.path);
info!("reset {} to {}", self.repo.path().display(), self.revision);

Expand All @@ -370,8 +376,7 @@ impl<'a> GitCheckout<'a> {
let object = self.repo.find_object(self.revision, None)?;
reset(&self.repo, &object, gctx)?;

guard.mark_ok()?;
Ok(())
Ok(guard)
}

/// Like `git submodule update --recursive` but for this git checkout.
Expand Down

0 comments on commit e82ad5f

Please sign in to comment.