mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
refactor: determine how shallow clone is handled inside fetch
fn
I think `RemoteKind::to_shallow_setting` should be an implementation detail of `fetch` fn.
This commit is contained in:
parent
8b3508cad7
commit
e2fe3956f9
@ -98,14 +98,12 @@ impl GitRemote {
|
|||||||
// populated the database with the latest version of `reference`, so
|
// populated the database with the latest version of `reference`, so
|
||||||
// return that database and the rev we resolve to.
|
// return that database and the rev we resolve to.
|
||||||
if let Some(mut db) = db {
|
if let Some(mut db) = db {
|
||||||
let shallow =
|
|
||||||
RemoteKind::GitDependency.to_shallow_setting(db.repo.is_shallow(), cargo_config);
|
|
||||||
fetch(
|
fetch(
|
||||||
&mut db.repo,
|
&mut db.repo,
|
||||||
self.url.as_str(),
|
self.url.as_str(),
|
||||||
reference,
|
reference,
|
||||||
cargo_config,
|
cargo_config,
|
||||||
shallow,
|
RemoteKind::GitDependency,
|
||||||
locked_rev,
|
locked_rev,
|
||||||
)
|
)
|
||||||
.with_context(|| format!("failed to fetch into: {}", into.display()))?;
|
.with_context(|| format!("failed to fetch into: {}", into.display()))?;
|
||||||
@ -127,13 +125,12 @@ impl GitRemote {
|
|||||||
}
|
}
|
||||||
paths::create_dir_all(into)?;
|
paths::create_dir_all(into)?;
|
||||||
let mut repo = init(into, true)?;
|
let mut repo = init(into, true)?;
|
||||||
let shallow = RemoteKind::GitDependency.to_shallow_setting(repo.is_shallow(), cargo_config);
|
|
||||||
fetch(
|
fetch(
|
||||||
&mut repo,
|
&mut repo,
|
||||||
self.url.as_str(),
|
self.url.as_str(),
|
||||||
reference,
|
reference,
|
||||||
cargo_config,
|
cargo_config,
|
||||||
shallow,
|
RemoteKind::GitDependency,
|
||||||
locked_rev,
|
locked_rev,
|
||||||
)
|
)
|
||||||
.with_context(|| format!("failed to clone into: {}", into.display()))?;
|
.with_context(|| format!("failed to clone into: {}", into.display()))?;
|
||||||
@ -456,9 +453,15 @@ impl<'a> GitCheckout<'a> {
|
|||||||
cargo_config
|
cargo_config
|
||||||
.shell()
|
.shell()
|
||||||
.status("Updating", format!("git submodule `{}`", url))?;
|
.status("Updating", format!("git submodule `{}`", url))?;
|
||||||
let shallow =
|
fetch(
|
||||||
RemoteKind::GitDependency.to_shallow_setting(repo.is_shallow(), cargo_config);
|
&mut repo,
|
||||||
fetch(&mut repo, &url, &reference, cargo_config, shallow, None).with_context(|| {
|
&url,
|
||||||
|
&reference,
|
||||||
|
cargo_config,
|
||||||
|
RemoteKind::GitDependency,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
"failed to fetch submodule `{}` from {}",
|
"failed to fetch submodule `{}` from {}",
|
||||||
child.name().unwrap_or(""),
|
child.name().unwrap_or(""),
|
||||||
@ -837,7 +840,7 @@ pub fn fetch(
|
|||||||
orig_url: &str,
|
orig_url: &str,
|
||||||
reference: &GitReference,
|
reference: &GitReference,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
shallow: gix::remote::fetch::Shallow,
|
remote_kind: RemoteKind,
|
||||||
locked_rev: Option<git2::Oid>,
|
locked_rev: Option<git2::Oid>,
|
||||||
) -> CargoResult<()> {
|
) -> CargoResult<()> {
|
||||||
if config.frozen() {
|
if config.frozen() {
|
||||||
@ -850,6 +853,9 @@ pub fn fetch(
|
|||||||
anyhow::bail!("can't update a git repository in the offline mode")
|
anyhow::bail!("can't update a git repository in the offline mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let shallow = remote_kind.to_shallow_setting(repo.is_shallow(), config);
|
||||||
|
let is_shallow = !matches!(shallow, gix::remote::fetch::Shallow::NoChange);
|
||||||
|
|
||||||
// If we're fetching from GitHub, attempt GitHub's special fast path for
|
// If we're fetching from GitHub, attempt GitHub's special fast path for
|
||||||
// testing if we've already got an up-to-date copy of the repository.
|
// testing if we've already got an up-to-date copy of the repository.
|
||||||
let is_shallow = !matches!(shallow, gix::remote::fetch::Shallow::NoChange);
|
let is_shallow = !matches!(shallow, gix::remote::fetch::Shallow::NoChange);
|
||||||
@ -878,9 +884,7 @@ pub fn fetch(
|
|||||||
// The `+` symbol on the refspec means to allow a forced (fast-forward)
|
// The `+` symbol on the refspec means to allow a forced (fast-forward)
|
||||||
// update which is needed if there is ever a force push that requires a
|
// update which is needed if there is ever a force push that requires a
|
||||||
// fast-forward.
|
// fast-forward.
|
||||||
if let Some(rev) =
|
if let Some(rev) = locked_rev.filter(|_| is_shallow) {
|
||||||
locked_rev.filter(|_| !matches!(shallow, gix::remote::fetch::Shallow::NoChange))
|
|
||||||
{
|
|
||||||
// If we want a specific revision and know about, obtain that specifically.
|
// If we want a specific revision and know about, obtain that specifically.
|
||||||
refspecs.push(format!("+{0}:refs/remotes/origin/HEAD", rev));
|
refspecs.push(format!("+{0}:refs/remotes/origin/HEAD", rev));
|
||||||
} else {
|
} else {
|
||||||
|
@ -305,13 +305,12 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
|
|||||||
// checkout.
|
// checkout.
|
||||||
let url = self.source_id.url();
|
let url = self.source_id.url();
|
||||||
let repo = self.repo.borrow_mut().unwrap();
|
let repo = self.repo.borrow_mut().unwrap();
|
||||||
let shallow = RemoteKind::Registry.to_shallow_setting(repo.is_shallow(), self.config);
|
|
||||||
git::fetch(
|
git::fetch(
|
||||||
repo,
|
repo,
|
||||||
url.as_str(),
|
url.as_str(),
|
||||||
&self.index_git_ref,
|
&self.index_git_ref,
|
||||||
self.config,
|
self.config,
|
||||||
shallow,
|
RemoteKind::Registry,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.with_context(|| format!("failed to fetch `{}`", url))?;
|
.with_context(|| format!("failed to fetch `{}`", url))?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user