Skip to content

Commit

Permalink
Do not call it "Downgrading" when difference is only build metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 9, 2023
1 parent 4d1bf29 commit 985e1ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,15 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
format!("{} -> v{}", removed[0], added[0].version())
};

if removed[0].version() > added[0].version() {
// If versions differ only in build metadata, we call it an "update"
// regardless of whether the build metadata has gone up or down.
// This metadata is often stuff like git commit hashes, which are
// not meaningfully ordered.
let removed = removed[0].version();
let added = added[0].version();
if (removed.major, removed.minor, removed.patch, &removed.pre)
> (added.major, added.minor, added.patch, &added.pre)
{
print_change("Downgrading", msg, &style::WARN)?;
} else {
print_change("Updating", msg, &style::GOOD)?;
Expand Down
4 changes: 3 additions & 1 deletion tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,13 @@ fn update_precise_build_metadata() {
)
.run();

// This is not considered "Downgrading". Build metadata are not assumed to
// be ordered.
p.cargo("update serde --precise 0.0.1+first")
.with_stderr(
"\
[UPDATING] `[..]` index
[DOWNGRADING] serde v0.0.1+second -> v0.0.1+first
[UPDATING] serde v0.0.1+second -> v0.0.1+first
",
)
.run();
Expand Down

0 comments on commit 985e1ee

Please sign in to comment.