Skip to content

Commit ffd78e6

Browse files
committed
recursive cache git submodules
- creates GitSource for each submodules - replaces fetch inside update_submodule by GitSource::update_db and db.copy_to - removes recursive update_submodules calls cos db.copy_to already recursive. - adjust git testsuite
1 parent 69eeb23 commit ffd78e6

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! Utilities for handling git repositories, mainly around
22
//! authentication/cloning.
33
4-
use crate::core::{GitReference, Verbosity};
4+
use crate::core::{GitReference, SourceId, Verbosity};
55
use crate::sources::git::fetch::RemoteKind;
66
use crate::sources::git::oxide;
77
use crate::sources::git::oxide::cargo_config_to_gitoxide_overrides;
8+
use crate::sources::git::source::GitSource;
9+
use crate::sources::source::Source as _;
810
use crate::util::HumanBytes;
911
use crate::util::errors::{CargoResult, GitCliError};
1012
use crate::util::{GlobalContext, IntoUrl, MetricsCounter, Progress, network};
@@ -447,7 +449,7 @@ impl<'a> GitCheckout<'a> {
447449
let target = repo.head()?.target();
448450
Ok((target, repo))
449451
});
450-
let mut repo = match head_and_repo {
452+
let repo = match head_and_repo {
451453
Ok((head, repo)) => {
452454
if child.head_id() == head {
453455
return update_submodules(&repo, gctx, &child_remote_url);
@@ -461,24 +463,23 @@ impl<'a> GitCheckout<'a> {
461463
}
462464
};
463465
// Fetch data from origin and reset to the head commit
464-
let reference = GitReference::Rev(head.to_string());
465466
gctx.shell()
466467
.status("Updating", format!("git submodule `{child_remote_url}`"))?;
467-
fetch(
468-
&mut repo,
469-
&child_remote_url,
470-
&reference,
468+
let mut source = GitSource::new(
469+
SourceId::from_url(&format!("git+{child_remote_url}#{head}"))?,
471470
gctx,
472-
RemoteKind::GitDependency,
473471
)
474472
.with_context(|| {
475473
let name = child.name().unwrap_or("");
476474
format!("failed to fetch submodule `{name}` from {child_remote_url}",)
477475
})?;
476+
source.set_quiet(true);
477+
478+
let (db, actual_rev) = source.update_db()?;
479+
db.copy_to(actual_rev, &repo.path(), gctx)?;
478480

479481
let obj = repo.find_object(head, None)?;
480-
reset(&repo, &obj, gctx)?;
481-
update_submodules(&repo, gctx, &child_remote_url)
482+
reset(&repo, &obj, gctx)
482483
}
483484
}
484485
}

tests/testsuite/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ Caused by:
10601060
failed to update submodule `src`
10611061
10621062
Caused by:
1063-
object not found - no match for id ([..]); class=Odb (9); code=NotFound (-3)
1063+
revspec '[..]' not found; class=Reference (4); code=NotFound (-3)
10641064
10651065
"#]];
10661066

0 commit comments

Comments
 (0)