From 5d785ca24e8142de2f2725e776d66b1cb468f984 Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 8 Sep 2021 18:05:06 +0800 Subject: [PATCH 1/4] Simplified output format --- src/cargo/ops/cargo_generate_lockfile.rs | 25 +++++------ tests/testsuite/update.rs | 57 ++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index 181e25b128b..5353250f665 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -130,24 +130,23 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes opts.config.shell().status_with_color(status, msg, color) }; for (removed, added) in compare_dependency_graphs(&previous_resolve, &resolve) { - if removed.len() == 1 && added.len() == 1 { - let msg = if removed[0].source_id().is_git() { + for (pre_package, tar_package) in removed.iter().zip(added.iter()) { + let msg = if pre_package.source_id().is_git() { format!( - "{} -> #{}", - removed[0], - &added[0].source_id().precise().unwrap()[..8] + "{} {} -> #{}", + pre_package, + pre_package.version(), + &tar_package.source_id().precise().unwrap()[..8] ) } else { - format!("{} -> v{}", removed[0], added[0].version()) + format!( + "{} v{} -> v{}", + pre_package.name(), + pre_package.version(), + tar_package.version() + ) }; print_change("Updating", msg, Green)?; - } else { - for package in removed.iter() { - print_change("Removing", format!("{}", package), Red)?; - } - for package in added.iter() { - print_change("Adding", format!("{}", package), Cyan)?; - } } } if opts.dry_run { diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index 33ca18c38b1..ef14548f820 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -678,3 +678,60 @@ fn workspace_only() { assert!(!lock1.contains("0.0.2")); assert!(!lock2.contains("0.0.1")); } + +#[cargo_test] +fn update_mulit_dependence_after_precise() { + Package::new("serde", "0.1.0").publish(); + Package::new("serde", "0.2.0").publish(); + Package::new("serde", "0.1.5").publish(); + Package::new("serde", "0.2.5").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + + [dependencies] + serde_1 = { package = "serde", version = "0.1.0" } + serde_2 = { package = "serde", version = "0.2.0" } + "#, + ) + .file( + "src/main.rs", + r#" + fn main() {} + "#, + ) + .build(); + + p.cargo("generate-lockfile").run(); + + p.cargo("update -p serde:0.1.5 --precise 0.1.0") + .with_stderr( + "\ +[UPDATING] `[..]` index +[UPDATING] serde v0.1.5 -> v0.1.0", + ) + .run(); + + p.cargo("update -p serde:0.2.5 --precise 0.2.0") + .with_stderr( + "\ +[UPDATING] `[..]` index +[UPDATING] serde v0.2.5 -> v0.2.0", + ) + .run(); + + p.cargo("update") + .with_stderr( + "\ +[UPDATING] `[..]` index +[UPDATING] serde v0.1.0 -> v0.1.5 +[UPDATING] serde v0.2.0 -> v0.2.5", + ) + .run(); +} From 223cad2cb8ca8f76758749eac9356e6744bb4e12 Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 8 Sep 2021 18:13:15 +0800 Subject: [PATCH 2/4] fix unused import --- src/cargo/ops/cargo_generate_lockfile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index 5353250f665..df458bdc733 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, HashSet}; use log::debug; -use termcolor::Color::{self, Cyan, Green, Red}; +use termcolor::Color::{self, Green}; use crate::core::registry::PackageRegistry; use crate::core::resolver::features::{CliFeatures, HasDevUnits}; From a59673fc6f7749bf2e5ed93eddecebd0c9bde8ad Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 8 Sep 2021 20:17:54 +0800 Subject: [PATCH 3/4] fix test --- src/cargo/ops/cargo_generate_lockfile.rs | 43 +++++++++++++++++------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index df458bdc733..a018c9fd3ac 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -130,23 +130,42 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes opts.config.shell().status_with_color(status, msg, color) }; for (removed, added) in compare_dependency_graphs(&previous_resolve, &resolve) { - for (pre_package, tar_package) in removed.iter().zip(added.iter()) { - let msg = if pre_package.source_id().is_git() { + if removed.len() == 1 && added.len() == 1 { + let msg = if removed[0].source_id().is_git() { format!( - "{} {} -> #{}", - pre_package, - pre_package.version(), - &tar_package.source_id().precise().unwrap()[..8] + "{} -> #{}", + removed[0], + &added[0].source_id().precise().unwrap()[..8] ) } else { - format!( - "{} v{} -> v{}", - pre_package.name(), - pre_package.version(), - tar_package.version() - ) + format!("{} -> v{}", removed[0], added[0].version()) }; print_change("Updating", msg, Green)?; + } else if removed.len() == added.len() { + for (pre_package, tar_package) in removed.iter().zip(added.iter()) { + let msg = if pre_package.source_id().is_git() { + format!( + "{} -> #{}", + pre_package, + &tar_package.source_id().precise().unwrap()[..8] + ) + } else { + format!( + "{} v{} -> v{}", + pre_package.name(), + pre_package.version(), + tar_package.version() + ) + }; + print_change("Updating", msg, Green)?; + } + } else { + for package in removed.iter() { + print_change("Removing", format!("{}", package), Red)?; + } + for package in added.iter() { + print_change("Adding", format!("{}", package), Cyan)?; + } } } if opts.dry_run { From b29aac301f9079fd4c5b0341b1c2246a8e6c64bb Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 8 Sep 2021 20:19:24 +0800 Subject: [PATCH 4/4] fix bug --- src/cargo/ops/cargo_generate_lockfile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index a018c9fd3ac..26b1693ef6d 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, HashSet}; use log::debug; -use termcolor::Color::{self, Green}; +use termcolor::Color::{self, Cyan, Green, Red}; use crate::core::registry::PackageRegistry; use crate::core::resolver::features::{CliFeatures, HasDevUnits};