From 882ff473d5f45dff2d537daf9cdf05ea96db96ed Mon Sep 17 00:00:00 2001 From: gibix Date: Mon, 19 Mar 2018 18:43:02 +0100 Subject: [PATCH 1/5] fix #2773 with new precise encode --- src/cargo/ops/cargo_generate_lockfile.rs | 2 +- src/cargo/sources/registry/index.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index c9a61266a09..741974e3b35 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -69,7 +69,7 @@ pub fn update_lockfile(ws: &Workspace, opts: &UpdateOptions) -> CargoResult<()> // seems like a pretty hokey reason to single out // the registry as well. let precise = if dep.source_id().is_registry() { - format!("{}={}", dep.name(), precise) + format!("{}={}->{}", dep.name(), dep.version(), precise) } else { precise.to_string() }; diff --git a/src/cargo/sources/registry/index.rs b/src/cargo/sources/registry/index.rs index eb07c24e873..b47ac26ce17 100644 --- a/src/cargo/sources/registry/index.rs +++ b/src/cargo/sources/registry/index.rs @@ -179,13 +179,18 @@ impl<'cfg> RegistryIndex<'cfg> { .map(|s| s.0.clone()); // Handle `cargo update --precise` here. If specified, our own source - // will have a precise version listed of the form `=` where - // `` is the name of a crate on this source and `` is the + // will have a precise version listed of the form + // `=o->` where `` is the name of a crate on + // this source, `` is the version installed and ` is the // version requested (argument to `--precise`). let summaries = summaries.filter(|s| match source_id.precise() { Some(p) if p.starts_with(&*dep.name()) && p[dep.name().len()..].starts_with('=') => { - let vers = &p[dep.name().len() + 1..]; - s.version().to_string() == vers + let vers: Vec<&str> = p[dep.name().len() + 1..].split("->").collect(); + if dep.version_req().matches(&Version::parse(vers[0]).unwrap()) { + return vers[1] == s.version().to_string() + } + + true } _ => true, }); From b0fbc89c33780ca3e1f2bfeacc67922ee7abe1dc Mon Sep 17 00:00:00 2001 From: gibix Date: Tue, 20 Mar 2018 09:58:51 +0100 Subject: [PATCH 2/5] cargo fmt --- src/cargo/sources/registry/index.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cargo/sources/registry/index.rs b/src/cargo/sources/registry/index.rs index b47ac26ce17..a26bfb8fe91 100644 --- a/src/cargo/sources/registry/index.rs +++ b/src/cargo/sources/registry/index.rs @@ -186,11 +186,11 @@ impl<'cfg> RegistryIndex<'cfg> { let summaries = summaries.filter(|s| match source_id.precise() { Some(p) if p.starts_with(&*dep.name()) && p[dep.name().len()..].starts_with('=') => { let vers: Vec<&str> = p[dep.name().len() + 1..].split("->").collect(); - if dep.version_req().matches(&Version::parse(vers[0]).unwrap()) { - return vers[1] == s.version().to_string() - } - + if dep.version_req().matches(&Version::parse(vers[0]).unwrap()) { + return vers[1] == s.version().to_string() + } { true + } } _ => true, }); From e6254eff19e0124d111b22653800e306c8a84c78 Mon Sep 17 00:00:00 2001 From: gibix Date: Tue, 20 Mar 2018 11:02:29 +0100 Subject: [PATCH 3/5] fix typo , drop return and intermediate vector --- src/cargo/sources/registry/index.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cargo/sources/registry/index.rs b/src/cargo/sources/registry/index.rs index a26bfb8fe91..be03e5753a5 100644 --- a/src/cargo/sources/registry/index.rs +++ b/src/cargo/sources/registry/index.rs @@ -185,10 +185,10 @@ impl<'cfg> RegistryIndex<'cfg> { // version requested (argument to `--precise`). let summaries = summaries.filter(|s| match source_id.precise() { Some(p) if p.starts_with(&*dep.name()) && p[dep.name().len()..].starts_with('=') => { - let vers: Vec<&str> = p[dep.name().len() + 1..].split("->").collect(); - if dep.version_req().matches(&Version::parse(vers[0]).unwrap()) { - return vers[1] == s.version().to_string() - } { + let mut vers = p[dep.name().len() + 1..].splitn(2, "->"); + if dep.version_req().matches(&Version::parse(vers.next().unwrap()).unwrap()) { + vers.next().unwrap() == s.version().to_string() + } else { true } } From a6ad2de0484f1910d42793f3ec73b111403099b7 Mon Sep 17 00:00:00 2001 From: gibix Date: Sat, 24 Mar 2018 20:04:02 +0100 Subject: [PATCH 4/5] cargo fmt --- src/cargo/sources/registry/index.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cargo/sources/registry/index.rs b/src/cargo/sources/registry/index.rs index be03e5753a5..4c28d173364 100644 --- a/src/cargo/sources/registry/index.rs +++ b/src/cargo/sources/registry/index.rs @@ -186,7 +186,9 @@ impl<'cfg> RegistryIndex<'cfg> { let summaries = summaries.filter(|s| match source_id.precise() { Some(p) if p.starts_with(&*dep.name()) && p[dep.name().len()..].starts_with('=') => { let mut vers = p[dep.name().len() + 1..].splitn(2, "->"); - if dep.version_req().matches(&Version::parse(vers.next().unwrap()).unwrap()) { + if dep.version_req() + .matches(&Version::parse(vers.next().unwrap()).unwrap()) + { vers.next().unwrap() == s.version().to_string() } else { true From 1a26e86cc761c3fa4ba95ebe476970eb05a128dc Mon Sep 17 00:00:00 2001 From: gibix Date: Sat, 24 Mar 2018 20:04:19 +0100 Subject: [PATCH 5/5] add precise test --- tests/testsuite/update.rs | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index fd106ca0166..053f0888df7 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -358,3 +358,58 @@ fn change_package_version() { assert_that(p.cargo("build"), execs().with_status(0)); } + +#[test] +fn update_precise() { + Package::new("log", "0.1.0").publish(); + Package::new("serde", "0.1.0").publish(); + Package::new("serde", "0.2.1").publish(); + + let p = project("foo") + .file( + "Cargo.toml", + r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + + [dependencies] + serde = "0.2" + foo = { path = "foo" } + "#, + ) + .file("src/lib.rs", "") + .file( + "foo/Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + serde = "0.1" + "#, + ) + .file("foo/src/lib.rs", "") + .build(); + + assert_that(p.cargo("build"), execs().with_status(0)); + + Package::new("serde", "0.2.0").publish(); + + assert_that( + p.cargo("update") + .arg("-p") + .arg("serde:0.2.1") + .arg("--precise") + .arg("0.2.0"), + execs().with_status(0).with_stderr( + "\ +[UPDATING] registry `[..]` +[UPDATING] serde v0.2.1 -> v0.2.0 +", + ), + ); +}