Skip to content

Commit f8c152d

Browse files
committed
Auto merge of #12852 - weihanglo:lockfile-v4, r=ehuss
feat: stabilize lockfile v4
2 parents 251d437 + f8a47fa commit f8c152d

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

src/cargo/core/resolver/encode.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,18 @@ impl EncodableResolve {
154154
/// primary uses is to be used with `resolve_with_previous` to guide the
155155
/// resolver to create a complete Resolve.
156156
pub fn into_resolve(self, original: &str, ws: &Workspace<'_>) -> CargoResult<Resolve> {
157-
let unstable_lockfile_version_allowed = ws.config().cli_unstable().next_lockfile_bump;
158157
let path_deps = build_path_deps(ws)?;
159158
let mut checksums = HashMap::new();
160159

161160
let mut version = match self.version {
162-
Some(4) if ws.config().nightly_features_allowed => {
163-
if unstable_lockfile_version_allowed {
164-
ResolveVersion::V4
161+
Some(n @ 5) if ws.config().nightly_features_allowed => {
162+
if ws.config().cli_unstable().next_lockfile_bump {
163+
ResolveVersion::V5
165164
} else {
166-
anyhow::bail!("lock file version 4 requires `-Znext-lockfile-bump`");
165+
anyhow::bail!("lock file version `{n}` requires `-Znext-lockfile-bump`");
167166
}
168167
}
168+
Some(4) => ResolveVersion::V4,
169169
Some(3) => ResolveVersion::V3,
170170
Some(n) => bail!(
171171
"lock file version `{}` was found, but this version of Cargo \
@@ -694,6 +694,7 @@ impl ser::Serialize for Resolve {
694694
metadata,
695695
patch,
696696
version: match self.version() {
697+
ResolveVersion::V5 => Some(5),
697698
ResolveVersion::V4 => Some(4),
698699
ResolveVersion::V3 => Some(3),
699700
ResolveVersion::V2 | ResolveVersion::V1 => None,
@@ -797,9 +798,10 @@ fn encodable_source_id(id: SourceId, version: ResolveVersion) -> Option<Encodabl
797798
if id.is_path() {
798799
None
799800
} else {
800-
Some(match version {
801-
ResolveVersion::V4 => EncodableSourceId::new(id),
802-
_ => EncodableSourceId::without_url_encoded(id),
801+
Some(if version >= ResolveVersion::V4 {
802+
EncodableSourceId::new(id)
803+
} else {
804+
EncodableSourceId::without_url_encoded(id)
803805
})
804806
}
805807
}

src/cargo/core/resolver/resolve.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ pub enum ResolveVersion {
8080
/// V3 by default staring in 1.53.
8181
#[default]
8282
V3,
83+
/// SourceId URL serialization is aware of URL encoding. For example,
84+
/// `?branch=foo bar` is now encoded as `?branch=foo+bar` and can be decoded
85+
/// back and forth correctly. Introduced in 2024 in version 1.77.
86+
V4,
8387
/// Unstable. Will collect a certain amount of changes and then go.
8488
///
8589
/// Changes made:
86-
///
87-
/// * SourceId URL serialization is aware of URL encoding.
88-
V4,
90+
V5,
8991
}
9092

9193
impl ResolveVersion {
@@ -95,7 +97,7 @@ impl ResolveVersion {
9597
///
9698
/// Update this when you're going to stabilize a new lockfile format.
9799
pub fn max_stable() -> ResolveVersion {
98-
ResolveVersion::V3
100+
ResolveVersion::V4
99101
}
100102
}
101103

src/cargo/core/source_id.rs

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

src/cargo/sources/git/source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<'cfg> Debug for GitSource<'cfg> {
232232
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
233233
write!(f, "git repo at {}", self.remote.url())?;
234234

235-
// TODO(-Znext-lockfile-bump): set it to true when stabilizing
235+
// TODO(-Znext-lockfile-bump): set it to true when the default is
236236
// lockfile v4, because we want Source ID serialization to be
237237
// consistent with lockfile.
238238
match &self.locked_rev {

src/cargo/util/toml_mut/dependency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ impl std::fmt::Display for GitSource {
918918
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
919919
let git_ref = self.git_ref();
920920

921-
// TODO(-Znext-lockfile-bump): set it to true when stabilizing
921+
// TODO(-Znext-lockfile-bump): set it to true when the default is
922922
// lockfile v4, because we want Source ID serialization to be
923923
// consistent with lockfile.
924924
if let Some(pretty_ref) = git_ref.pretty_ref(false) {

tests/testsuite/lockfile_compat.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ perhaps a crate was updated and forgotten to be re-vendored?
890890
}
891891

892892
#[cargo_test]
893-
fn v4_is_unstable() {
893+
fn next_version_is_always_unstable() {
894894
let p = project()
895895
.file(
896896
"Cargo.toml",
@@ -903,7 +903,7 @@ fn v4_is_unstable() {
903903
),
904904
)
905905
.file("src/lib.rs", "")
906-
.file("Cargo.lock", "version = 4")
906+
.file("Cargo.lock", "version = 5")
907907
.build();
908908

909909
p.cargo("fetch")
@@ -913,7 +913,7 @@ fn v4_is_unstable() {
913913
error: failed to parse lock file at: [CWD]/Cargo.lock
914914
915915
Caused by:
916-
lock file version `4` was found, but this version of Cargo does not \
916+
lock file version `5` was found, but this version of Cargo does not \
917917
understand this lock file, perhaps Cargo needs to be updated?
918918
",
919919
)
@@ -928,7 +928,7 @@ Caused by:
928928
error: failed to parse lock file at: [CWD]/Cargo.lock
929929
930930
Caused by:
931-
lock file version 4 requires `-Znext-lockfile-bump`
931+
lock file version `5` requires `-Znext-lockfile-bump`
932932
",
933933
)
934934
.run();
@@ -950,9 +950,7 @@ fn v4_cannot_be_created_from_scratch() {
950950
.file("src/lib.rs", "")
951951
.build();
952952

953-
p.cargo("fetch -Znext-lockfile-bump")
954-
.masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"])
955-
.run();
953+
p.cargo("fetch").run();
956954

957955
let lockfile = r#"# This file is automatically @generated by Cargo.
958956
# It is not intended for manual editing.
@@ -1124,8 +1122,7 @@ dependencies = [
11241122
.file("Cargo.lock", "version = 4")
11251123
.build();
11261124

1127-
p.cargo("check -Znext-lockfile-bump")
1128-
.masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"])
1125+
p.cargo("check")
11291126
.with_stderr(format!(
11301127
"\
11311128
[UPDATING] git repository `{url}`
@@ -1141,10 +1138,7 @@ dependencies = [
11411138

11421139
// Unlike v3_and_git_url_encoded, v4 encodes URL parameters so no git
11431140
// repository re-clone happen.
1144-
p.cargo("check -Znext-lockfile-bump")
1145-
.masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"])
1146-
.with_stderr("[FINISHED] dev [..]")
1147-
.run();
1141+
p.cargo("check").with_stderr("[FINISHED] dev [..]").run();
11481142
}
11491143

11501144
#[cargo_test]

0 commit comments

Comments
 (0)