From aa97b32e2b630d43e102175195eed36970527e5f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 7 Dec 2014 22:25:26 -0800 Subject: [PATCH] Fix updating the registry too often It turns out that the registry was being queried with git dependencies as well, so this commit alters the core registry not query sources with dependencies that did not originate from the source. Closes #991 --- src/cargo/core/registry.rs | 8 +++--- src/cargo/core/source.rs | 4 +-- tests/support/git.rs | 5 ++++ tests/test_cargo_registry.rs | 50 ++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 5ab42b30f..1c6c592df 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -89,7 +89,7 @@ impl<'a> PackageRegistry<'a> { // source let mut ret = Vec::new(); - for source in self.sources.sources_mut() { + for (_, source) in self.sources.sources_mut() { try!(source.download(package_ids)); let packages = try!(source.get(package_ids)); @@ -283,8 +283,10 @@ impl<'a> Registry for PackageRegistry<'a> { // Ensure the requested source_id is loaded try!(self.ensure_loaded(dep.get_source_id())); let mut ret = Vec::new(); - for src in self.sources.sources_mut() { - ret.extend(try!(src.query(dep)).into_iter()); + for (id, src) in self.sources.sources_mut() { + if id == dep.get_source_id() { + ret.extend(try!(src.query(dep)).into_iter()); + } } ret } else { diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index c81177279..18bdf650f 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -327,7 +327,7 @@ pub struct SourceMap<'src> { pub type Sources<'a, 'src> = Values<'a, SourceId, Box>; pub type SourcesMut<'a, 'src> = iter::Map<'static, (&'a SourceId, &'a mut Box), - &'a mut (Source+'src), + (&'a SourceId, &'a mut (Source+'src)), MutEntries<'a, SourceId, Box>>; impl<'src> SourceMap<'src> { @@ -374,7 +374,7 @@ impl<'src> SourceMap<'src> { } pub fn sources_mut<'a>(&'a mut self) -> SourcesMut<'a, 'src> { - self.map.iter_mut().map(|(_, v)| &mut **v) + self.map.iter_mut().map(|(k, v)| (k, &mut **v)) } } diff --git a/tests/support/git.rs b/tests/support/git.rs index 1216617b5..f41baf451 100644 --- a/tests/support/git.rs +++ b/tests/support/git.rs @@ -1,7 +1,10 @@ use std::io::{mod, fs, File}; +use url::Url; use git2; +use support::path2url; + pub struct RepoBuilder { repo: git2::Repository, files: Vec, @@ -47,4 +50,6 @@ impl RepoBuilder { self.repo.commit(Some("HEAD"), &sig, &sig, "Initial commit", &tree, &[]).unwrap(); } + + pub fn url(&self) -> Url { path2url(self.repo.path().dir_path()) } } diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index 8bb32cbc2..601587a0b 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -5,6 +5,7 @@ use support::{project, execs, cargo_dir}; use support::{UPDATING, DOWNLOADING, COMPILING, PACKAGING, VERIFYING}; use support::paths::{mod, PathExt}; use support::registry as r; +use support::git; use hamcrest::assert_that; @@ -558,3 +559,52 @@ test!(updating_a_dep { ", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING, dir = p.url()).as_slice())); }) + +test!(git_and_registry_dep { + let b = git::repo(&paths::root().join("b")) + .file("Cargo.toml", r#" + [project] + name = "b" + version = "0.0.1" + authors = [] + + [dependencies] + a = "0.0.1" + "#) + .file("src/lib.rs", ""); + b.build(); + let p = project("foo") + .file("Cargo.toml", format!(r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + a = "0.0.1" + + [dependencies.b] + git = '{}' + "#, b.url())) + .file("src/main.rs", "fn main() {}"); + p.build(); + + r::mock_pkg("a", "0.0.1", &[]); + + p.root().move_into_the_past().unwrap(); + assert_that(p.process(cargo_dir().join("cargo")).arg("build"), + execs().with_status(0).with_stdout(format!("\ +{updating} [..] +{updating} [..] +{downloading} a v0.0.1 (registry file://[..]) +{compiling} a v0.0.1 (registry [..]) +{compiling} b v0.0.1 ([..]) +{compiling} foo v0.0.1 ({dir}) +", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING, + dir = p.url()).as_slice())); + p.root().move_into_the_past().unwrap(); + + println!("second"); + assert_that(p.process(cargo_dir().join("cargo")).arg("build"), + execs().with_status(0).with_stdout("")); +})