Do not call it "Downgrading" when difference is only build metadata

This commit is contained in:
David Tolnay 2023-10-09 10:40:43 -07:00
parent 4d1bf29a2c
commit 985e1eeef5
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 12 additions and 2 deletions

View file

@ -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)?;

View file

@ -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();