Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make lockfile v4 the default #14595

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions src/cargo/core/resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ pub enum ResolveVersion {
/// branch specifiers.
///
/// * Introduced in 2020 in version 1.47.
/// * New lockfiles use V3 by default starting in 1.53.
/// * New lockfiles use V3 by default from in 1.53 to 1.82.
V3,
/// SourceId URL serialization is aware of URL encoding. For example,
/// `?branch=foo bar` is now encoded as `?branch=foo+bar` and can be decoded
/// back and forth correctly.
///
/// * Introduced in 2024 in version 1.78.
/// * New lockfiles use V4 by default starting in 1.83.
V4,
/// Unstable. Will collect a certain amount of changes and then go.
///
Expand All @@ -107,7 +108,7 @@ impl ResolveVersion {
/// Update this and the description of enum variants of [`ResolveVersion`]
/// when we're changing the default lockfile version.
fn default() -> ResolveVersion {
ResolveVersion::V3
ResolveVersion::V4
}

/// The maximum version of lockfile made into the stable channel.
Expand All @@ -125,28 +126,23 @@ impl ResolveVersion {
return ResolveVersion::default();
};

let rust_1_41 = PartialVersion {
major: 1,
minor: Some(41),
patch: None,
pre: None,
build: None,
}
.try_into()
.expect("PartialVersion 1.41");
let rust_1_53 = PartialVersion {
major: 1,
minor: Some(53),
patch: None,
pre: None,
build: None,
}
.try_into()
.expect("PartialVersion 1.53");
let rust = |major, minor| -> RustVersion {
PartialVersion {
major,
minor: Some(minor),
patch: None,
pre: None,
build: None,
}
.try_into()
.unwrap()
};

if rust_version >= &rust_1_53 {
if rust_version >= &rust(1, 83) {
ResolveVersion::V4
} else if rust_version >= &rust(1, 53) {
ResolveVersion::V3
} else if rust_version >= &rust_1_41 {
} else if rust_version >= &rust(1, 41) {
ResolveVersion::V2
} else {
ResolveVersion::V1
Expand Down
5 changes: 1 addition & 4 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,7 @@ impl fmt::Display for SourceId {
// Don't replace the URL display for git references,
// because those are kind of expected to be URLs.
write!(f, "{}", self.inner.url)?;
// TODO(-Znext-lockfile-bump): set it to true when the default is
// lockfile v4, because we want Source ID serialization to be
// consistent with lockfile.
if let Some(pretty) = reference.pretty_ref(false) {
if let Some(pretty) = reference.pretty_ref(true) {
write!(f, "?{}", pretty)?;
}

Expand Down
6 changes: 1 addition & 5 deletions src/cargo/sources/git/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,8 @@ fn ident_shallow(id: &SourceId, is_shallow: bool) -> String {
impl<'gctx> Debug for GitSource<'gctx> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "git repo at {}", self.remote.url())?;

// TODO(-Znext-lockfile-bump): set it to true when the default is
// lockfile v4, because we want Source ID serialization to be
// consistent with lockfile.
match &self.locked_rev {
Revision::Deferred(git_ref) => match git_ref.pretty_ref(false) {
Revision::Deferred(git_ref) => match git_ref.pretty_ref(true) {
Some(s) => write!(f, " ({})", s),
None => Ok(()),
},
Expand Down
6 changes: 1 addition & 5 deletions src/cargo/util/toml_mut/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,7 @@ impl GitSource {
impl std::fmt::Display for GitSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let git_ref = self.git_ref();

// TODO(-Znext-lockfile-bump): set it to true when the default is
// lockfile v4, because we want Source ID serialization to be
// consistent with lockfile.
if let Some(pretty_ref) = git_ref.pretty_ref(false) {
if let Some(pretty_ref) = git_ref.pretty_ref(true) {
write!(f, "{}?{}", self.git, pretty_ref)
} else {
write!(f, "{}", self.git)
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ fn sparse_lockfile() {
str![[r##"
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4

[[package]]
name = "a"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/not_found/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/path_dependency/in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/path_dependency/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/within_workspace.in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/within_ws/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_remove/gc_patch/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn cargo_compile_git_dep_pull_request() {
.with_stderr_data(str![[r#"
[UPDATING] git repository `[ROOTURL]/dep1`
[LOCKING] 1 package to latest compatible version
[COMPILING] dep1 v0.5.0 ([ROOTURL]/dep1?rev=refs/pull/330/head#[..])
[COMPILING] dep1 v0.5.0 ([ROOTURL]/dep1?rev=refs%2Fpull%2F330%2Fhead#[..])
epage marked this conversation as resolved.
Show resolved Hide resolved
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

Expand Down
Loading