Skip to content

Commit e20b020

Browse files
weihangloByron
authored andcommitted
refactor: remove locked_rev arg
If there is a locked revision, it should substitue for git reference. There is no chance that we will fallback to git reference when locked revision exists.
1 parent e2fe395 commit e20b020

File tree

2 files changed

+32
-40
lines changed

2 files changed

+32
-40
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ impl GitRemote {
9797
// if we can. If that can successfully load our revision then we've
9898
// populated the database with the latest version of `reference`, so
9999
// return that database and the rev we resolve to.
100+
let locked_ref = locked_rev.map(|oid| GitReference::Rev(oid.to_string()));
101+
let reference = locked_ref.as_ref().unwrap_or(reference);
100102
if let Some(mut db) = db {
101103
fetch(
102104
&mut db.repo,
103105
self.url.as_str(),
104106
reference,
105107
cargo_config,
106108
RemoteKind::GitDependency,
107-
locked_rev,
108109
)
109110
.with_context(|| format!("failed to fetch into: {}", into.display()))?;
110111

@@ -131,7 +132,6 @@ impl GitRemote {
131132
reference,
132133
cargo_config,
133134
RemoteKind::GitDependency,
134-
locked_rev,
135135
)
136136
.with_context(|| format!("failed to clone into: {}", into.display()))?;
137137
let rev = match locked_rev {
@@ -459,7 +459,6 @@ impl<'a> GitCheckout<'a> {
459459
&reference,
460460
cargo_config,
461461
RemoteKind::GitDependency,
462-
None,
463462
)
464463
.with_context(|| {
465464
format!(
@@ -841,7 +840,6 @@ pub fn fetch(
841840
reference: &GitReference,
842841
config: &Config,
843842
remote_kind: RemoteKind,
844-
locked_rev: Option<git2::Oid>,
845843
) -> CargoResult<()> {
846844
if config.frozen() {
847845
anyhow::bail!(
@@ -854,7 +852,6 @@ pub fn fetch(
854852
}
855853

856854
let shallow = remote_kind.to_shallow_setting(repo.is_shallow(), config);
857-
let is_shallow = !matches!(shallow, gix::remote::fetch::Shallow::NoChange);
858855

859856
// If we're fetching from GitHub, attempt GitHub's special fast path for
860857
// testing if we've already got an up-to-date copy of the repository.
@@ -884,42 +881,38 @@ pub fn fetch(
884881
// The `+` symbol on the refspec means to allow a forced (fast-forward)
885882
// update which is needed if there is ever a force push that requires a
886883
// fast-forward.
887-
if let Some(rev) = locked_rev.filter(|_| is_shallow) {
888-
// If we want a specific revision and know about, obtain that specifically.
889-
refspecs.push(format!("+{0}:refs/remotes/origin/HEAD", rev));
890-
} else {
891-
match reference {
892-
// For branches and tags we can fetch simply one reference and copy it
893-
// locally, no need to fetch other branches/tags.
894-
GitReference::Branch(b) => {
895-
refspecs.push(format!("+refs/heads/{0}:refs/remotes/origin/{0}", b));
896-
}
897-
GitReference::Tag(t) => {
898-
refspecs.push(format!("+refs/tags/{0}:refs/remotes/origin/tags/{0}", t));
899-
}
884+
match reference {
885+
// For branches and tags we can fetch simply one reference and copy it
886+
// locally, no need to fetch other branches/tags.
887+
GitReference::Branch(b) => {
888+
refspecs.push(format!("+refs/heads/{0}:refs/remotes/origin/{0}", b));
889+
}
900890

901-
GitReference::DefaultBranch => {
902-
refspecs.push(String::from("+HEAD:refs/remotes/origin/HEAD"));
903-
}
891+
GitReference::Tag(t) => {
892+
refspecs.push(format!("+refs/tags/{0}:refs/remotes/origin/tags/{0}", t));
893+
}
904894

905-
GitReference::Rev(rev) => {
906-
if rev.starts_with("refs/") {
907-
refspecs.push(format!("+{0}:{0}", rev));
908-
} else if let Some(oid_to_fetch) = oid_to_fetch {
909-
refspecs.push(format!("+{0}:refs/commit/{0}", oid_to_fetch));
910-
} else if is_shallow && git2::Oid::from_str(&rev).is_ok() {
911-
// There is a specific commit to fetch and we will just do so in shallow-mode only
912-
// to not disturb the previous logic. Note that with typical settings for shallowing,
913-
// we will just fetch a specific slice of the history.
914-
refspecs.push(format!("+{0}:refs/remotes/origin/HEAD", rev));
915-
} else {
916-
// We don't know what the rev will point to. To handle this
917-
// situation we fetch all branches and tags, and then we pray
918-
// it's somewhere in there.
919-
refspecs.push(String::from("+refs/heads/*:refs/remotes/origin/*"));
920-
refspecs.push(String::from("+HEAD:refs/remotes/origin/HEAD"));
921-
tags = true;
922-
}
895+
GitReference::DefaultBranch => {
896+
refspecs.push(String::from("+HEAD:refs/remotes/origin/HEAD"));
897+
}
898+
899+
GitReference::Rev(rev) => {
900+
if rev.starts_with("refs/") {
901+
refspecs.push(format!("+{0}:{0}", rev));
902+
} else if let Some(oid_to_fetch) = oid_to_fetch {
903+
refspecs.push(format!("+{0}:refs/commit/{0}", oid_to_fetch));
904+
} else if is_shallow && rev.parse::<Oid>().is_ok() {
905+
// There is a specific commit to fetch and we will just do so in shallow-mode only
906+
// to not disturb the previous logic. Note that with typical settings for shallowing,
907+
// With shallow histories this is a bit fuzzy, and we opt-out for now.
908+
refspecs.push(format!("+{0}:refs/remotes/origin/HEAD", rev));
909+
} else {
910+
// We don't know what the rev will point to. To handle this
911+
// situation we fetch all branches and tags, and then we pray
912+
// it's somewhere in there.
913+
refspecs.push(String::from("+refs/heads/*:refs/remotes/origin/*"));
914+
refspecs.push(String::from("+HEAD:refs/remotes/origin/HEAD"));
915+
tags = true;
923916
}
924917
}
925918
}

src/cargo/sources/registry/remote.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
311311
&self.index_git_ref,
312312
self.config,
313313
RemoteKind::Registry,
314-
None,
315314
)
316315
.with_context(|| format!("failed to fetch `{}`", url))?;
317316

0 commit comments

Comments
 (0)