Skip to content

Commit 65365b4

Browse files
committed
feat: make lockfile v4 the default
This commit makes lockfile version 4 the default version when Cargo tries to write to a lockfile. The lockfile version 4 has been stabilized since 1.78.0, and will become default in 1.83.0. the length of transition period is pretty similar as before. One caveat is that in other output from Cargo, e.g., `cargo metatada`, status messages, `SourceID` will display in the v4 URL encoded format. This shouldn't affect the majority of Rust users, as `SourceId` representation should be opaque to them, unless comparing `SourceId` across different version of toolchains.
1 parent f3672cb commit 65365b4

File tree

32 files changed

+52
-90
lines changed

32 files changed

+52
-90
lines changed

src/cargo/core/resolver/resolve.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@ pub enum ResolveVersion {
8484
/// branch specifiers.
8585
///
8686
/// * Introduced in 2020 in version 1.47.
87-
/// * New lockfiles use V3 by default starting in 1.53.
87+
/// * New lockfiles use V3 by default from in 1.53 to 1.82.
8888
V3,
8989
/// SourceId URL serialization is aware of URL encoding. For example,
9090
/// `?branch=foo bar` is now encoded as `?branch=foo+bar` and can be decoded
9191
/// back and forth correctly.
9292
///
9393
/// * Introduced in 2024 in version 1.78.
94+
/// * New lockfiles use V4 by default starting in 1.83.
9495
V4,
9596
/// Unstable. Will collect a certain amount of changes and then go.
9697
///
@@ -107,7 +108,7 @@ impl ResolveVersion {
107108
/// Update this and the description of enum variants of [`ResolveVersion`]
108109
/// when we're changing the default lockfile version.
109110
fn default() -> ResolveVersion {
110-
ResolveVersion::V3
111+
ResolveVersion::V4
111112
}
112113

113114
/// The maximum version of lockfile made into the stable channel.
@@ -137,7 +138,9 @@ impl ResolveVersion {
137138
.unwrap()
138139
};
139140

140-
if rust_version >= &rust(1, 53) {
141+
if rust_version >= &rust(1, 83) {
142+
ResolveVersion::V4
143+
} else if rust_version >= &rust(1, 53) {
141144
ResolveVersion::V3
142145
} else if rust_version >= &rust(1, 41) {
143146
ResolveVersion::V2

src/cargo/core/source_id.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -644,10 +644,7 @@ impl fmt::Display for SourceId {
644644
// Don't replace the URL display for git references,
645645
// because those are kind of expected to be URLs.
646646
write!(f, "{}", self.inner.url)?;
647-
// TODO(-Znext-lockfile-bump): set it to true when the default is
648-
// lockfile v4, because we want Source ID serialization to be
649-
// consistent with lockfile.
650-
if let Some(pretty) = reference.pretty_ref(false) {
647+
if let Some(pretty) = reference.pretty_ref(true) {
651648
write!(f, "?{}", pretty)?;
652649
}
653650

src/cargo/sources/git/source.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,8 @@ fn ident_shallow(id: &SourceId, is_shallow: bool) -> String {
226226
impl<'gctx> Debug for GitSource<'gctx> {
227227
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
228228
write!(f, "git repo at {}", self.remote.url())?;
229-
230-
// TODO(-Znext-lockfile-bump): set it to true when the default is
231-
// lockfile v4, because we want Source ID serialization to be
232-
// consistent with lockfile.
233229
match &self.locked_rev {
234-
Revision::Deferred(git_ref) => match git_ref.pretty_ref(false) {
230+
Revision::Deferred(git_ref) => match git_ref.pretty_ref(true) {
235231
Some(s) => write!(f, " ({})", s),
236232
None => Ok(()),
237233
},

src/cargo/util/toml_mut/dependency.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1002,11 +1002,7 @@ impl GitSource {
10021002
impl std::fmt::Display for GitSource {
10031003
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10041004
let git_ref = self.git_ref();
1005-
1006-
// TODO(-Znext-lockfile-bump): set it to true when the default is
1007-
// lockfile v4, because we want Source ID serialization to be
1008-
// consistent with lockfile.
1009-
if let Some(pretty_ref) = git_ref.pretty_ref(false) {
1005+
if let Some(pretty_ref) = git_ref.pretty_ref(true) {
10101006
write!(f, "{}?{}", self.git, pretty_ref)
10111007
} else {
10121008
write!(f, "{}", self.git)

tests/testsuite/alt_registry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ fn sparse_lockfile() {
17901790
str![[r##"
17911791
# This file is automatically @generated by Cargo.
17921792
# It is not intended for manual editing.
1793-
version = 3
1793+
version = 4
17941794
17951795
[[package]]
17961796
name = "a"

tests/testsuite/cargo_add/add_workspace_non_fuzzy/in/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/not_found/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/path_dependency/in/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/path_dependency/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/specify_version_within_ws_and_conflict_with_lockfile/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/specify_version_within_ws_and_match_with_lockfile/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/with_frozen_within_ws/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/with_locked_within_ws/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/within_workspace.in/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/within_ws/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/within_ws_and_pick_ws_package/in/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/within_ws_and_pick_ws_package/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/within_ws_with_alternative_registry/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/within_ws_without_lockfile/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/without_requiring_registry_auth/in/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_info/without_requiring_registry_auth/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_remove/gc_patch/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_remove/update_lock_file/in/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_remove/update_lock_file/out/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/git.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn cargo_compile_git_dep_pull_request() {
283283
.with_stderr_data(str![[r#"
284284
[UPDATING] git repository `[ROOTURL]/dep1`
285285
[LOCKING] 1 package to latest compatible version
286-
[COMPILING] dep1 v0.5.0 ([ROOTURL]/dep1?rev=refs/pull/330/head#[..])
286+
[COMPILING] dep1 v0.5.0 ([ROOTURL]/dep1?rev=refs%2Fpull%2F330%2Fhead#[..])
287287
[COMPILING] foo v0.0.0 ([ROOT]/foo)
288288
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
289289

tests/testsuite/lockfile_compat.rs

+12-42
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn oldest_lockfile_still_works_with_command(cargo_command: &str) {
2121
let expected_lockfile = str![[r##"
2222
# This file is automatically @generated by Cargo.
2323
# It is not intended for manual editing.
24-
version = 3
24+
version = 4
2525
2626
[[package]]
2727
name = "bar"
@@ -173,7 +173,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
173173
str![[r##"
174174
# This file is automatically @generated by Cargo.
175175
# It is not intended for manual editing.
176-
version = 3
176+
version = 4
177177
178178
[[package]]
179179
name = "bar"
@@ -407,7 +407,7 @@ fn current_lockfile_format() {
407407
let expected = str![[r##"
408408
# This file is automatically @generated by Cargo.
409409
# It is not intended for manual editing.
410-
version = 3
410+
version = 4
411411
412412
[[package]]
413413
name = "bar"
@@ -473,7 +473,7 @@ dependencies = [
473473
str![[r##"
474474
# This file is automatically @generated by Cargo.
475475
# It is not intended for manual editing.
476-
version = 3
476+
version = 4
477477
478478
[[package]]
479479
name = "bar"
@@ -682,7 +682,7 @@ dependencies = [
682682
name = "foo"
683683
version = "0.0.1"
684684
edition = "2015"
685-
authors = []
685+
rust-version = "1.82"
686686
687687
[dependencies]
688688
dep1 = {{ git = '{}', branch = 'master' }}
@@ -937,38 +937,6 @@ Caused by:
937937
.run();
938938
}
939939

940-
#[cargo_test]
941-
fn v4_cannot_be_created_from_scratch() {
942-
let p = project()
943-
.file(
944-
"Cargo.toml",
945-
&format!(
946-
r#"
947-
[package]
948-
name = "foo"
949-
version = "0.0.1"
950-
edition = "2015"
951-
"#,
952-
),
953-
)
954-
.file("src/lib.rs", "")
955-
.build();
956-
957-
p.cargo("fetch").run();
958-
959-
let lockfile = r#"# This file is automatically @generated by Cargo.
960-
# It is not intended for manual editing.
961-
version = 3
962-
963-
[[package]]
964-
name = "foo"
965-
version = "0.0.1"
966-
"#;
967-
968-
let lock = p.read_lockfile();
969-
assert_e2e().eq(&lock, lockfile);
970-
}
971-
972940
fn create_branch(repo: &git2::Repository, branch: &str, head_id: git2::Oid) {
973941
repo.branch(branch, &repo.find_commit(head_id).unwrap(), true)
974942
.unwrap();
@@ -995,6 +963,7 @@ fn v3_and_git_url_encoded(ref_kind: &str, f: impl FnOnce(&git2::Repository, &str
995963
let head_id = repo.head().unwrap().target().unwrap();
996964
// Ref name with special characters
997965
let git_ref = "a-_+#$)";
966+
let encoded_ref = "a-_%2B%23%24%29";
998967
f(&repo, git_ref, head_id);
999968

1000969
let lockfile = format!(
@@ -1025,6 +994,7 @@ dependencies = [
1025994
name = "foo"
1026995
version = "0.0.1"
1027996
edition = "2015"
997+
rust-version = "1.82" # ensure it stays in lockfile v3
1028998
1029999
[dependencies]
10301000
dep1 = {{ git = '{url}', {ref_kind} = '{git_ref}' }}
@@ -1040,8 +1010,8 @@ dependencies = [
10401010
"\
10411011
[UPDATING] git repository `[ROOTURL]/dep1`
10421012
[LOCKING] 1 package to latest compatible version
1043-
[ADDING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..])
1044-
[CHECKING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..])
1013+
[ADDING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={encoded_ref}#[..])
1014+
[CHECKING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={encoded_ref}#[..])
10451015
[CHECKING] foo v0.0.1 ([ROOT]/foo)
10461016
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
10471017
"
@@ -1135,8 +1105,8 @@ dependencies = [
11351105
"\
11361106
[UPDATING] git repository `[ROOTURL]/dep1`
11371107
[LOCKING] 1 package to latest compatible version
1138-
[ADDING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..])
1139-
[CHECKING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..])
1108+
[ADDING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={encoded_ref}#[..])
1109+
[CHECKING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={encoded_ref}#[..])
11401110
[CHECKING] foo v0.0.1 ([ROOT]/foo)
11411111
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
11421112
"
@@ -1281,7 +1251,7 @@ dependencies = [
12811251
// last version of v3 as the default
12821252
("1.82", None, 3),
12831253
// v4 is the default
1284-
("1.83", None, 3),
1254+
("1.83", None, 4),
12851255
("1.83", Some(1), 1),
12861256
("1.83", Some(2), 2),
12871257
("1.83", Some(3), 3),

0 commit comments

Comments
 (0)