Move query definitions back into Source impls!
authorDale Wijnand <dale.wijnand@gmail.com>
Fri, 4 May 2018 13:07:51 +0000 (14:07 +0100)
committerDale Wijnand <dale.wijnand@gmail.com>
Fri, 4 May 2018 13:09:34 +0000 (14:09 +0100)
src/cargo/sources/directory.rs
src/cargo/sources/git/source.rs
src/cargo/sources/path.rs
src/cargo/sources/registry/mod.rs
src/cargo/sources/replaced.rs

index 4b55fe49f2d17a8145079035388399eb3da04ece..647c8b475de720aa00fca8da33576c1b09f5c179 100644 (file)
@@ -36,15 +36,6 @@ impl<'cfg> DirectorySource<'cfg> {
             packages: HashMap::new(),
         }
     }
-
-    fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        let packages = self.packages.values().map(|p| &p.0);
-        let matches = packages.filter(|pkg| dep.matches(pkg.summary()));
-        for summary in matches.map(|pkg| pkg.summary().clone()) {
-            f(summary);
-        }
-        Ok(())
-    }
 }
 
 impl<'cfg> Debug for DirectorySource<'cfg> {
@@ -67,7 +58,12 @@ impl<'cfg> Source for DirectorySource<'cfg> {
     }
 
     fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        self.query(dep, f)
+        let packages = self.packages.values().map(|p| &p.0);
+        let matches = packages.filter(|pkg| dep.matches(pkg.summary()));
+        for summary in matches.map(|pkg| pkg.summary().clone()) {
+            f(summary);
+        }
+        Ok(())
     }
 
     fn update(&mut self) -> CargoResult<()> {
index 3256b2d16046ab96bc4268ea33e3ea8c1e719f06..775222ce4f31c65425064798018c63087dfa2dbf 100644 (file)
@@ -52,13 +52,6 @@ impl<'cfg> GitSource<'cfg> {
         self.remote.url()
     }
 
-    fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        let src = self.path_source
-            .as_mut()
-            .expect("BUG: update() must be called before query()");
-        Source::query(src, dep, f)
-    }
-
     pub fn read_packages(&mut self) -> CargoResult<Vec<Package>> {
         if self.path_source.is_none() {
             self.update()?;
@@ -145,7 +138,10 @@ impl<'cfg> Source for GitSource<'cfg> {
     }
 
     fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        self.query(dep, f)
+        let src = self.path_source
+            .as_mut()
+            .expect("BUG: update() must be called before query()");
+        Source::query(src, dep, f)
     }
 
     fn update(&mut self) -> CargoResult<()> {
index 3303cdb7ad8d1366abf88e6d32ed7afb1e562807..e30b8103e3bd9048c35e134470ea2bce3b792eaf 100644 (file)
@@ -62,15 +62,6 @@ impl<'cfg> PathSource<'cfg> {
         self.packages.push(pkg);
     }
 
-    fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        for s in self.packages.iter().map(|p| p.summary()) {
-            if dep.matches(s) {
-                f(s.clone())
-            }
-        }
-        Ok(())
-    }
-
     pub fn root_package(&mut self) -> CargoResult<Package> {
         trace!("root_package; source={:?}", self);
 
@@ -498,7 +489,12 @@ impl<'cfg> Source for PathSource<'cfg> {
     }
 
     fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        self.query(dep, f)
+        for s in self.packages.iter().map(|p| p.summary()) {
+            if dep.matches(s) {
+                f(s.clone())
+            }
+        }
+        Ok(())
     }
 
     fn update(&mut self) -> CargoResult<()> {
index 1d8c0b42d02a21cb9ea13b280692033ce13ba864..d9571c23deee572948297e093faac80f2e0f24dd 100644 (file)
@@ -352,27 +352,6 @@ impl<'cfg> RegistrySource<'cfg> {
         }
     }
 
-    fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        // If this is a precise dependency, then it came from a lockfile and in
-        // theory the registry is known to contain this version. If, however, we
-        // come back with no summaries, then our registry may need to be
-        // updated, so we fall back to performing a lazy update.
-        if dep.source_id().precise().is_some() && !self.updated {
-            let mut called = false;
-            self.index.query(dep, &mut *self.ops, &mut |s| {
-                called = true;
-                f(s);
-            })?;
-            if called {
-                return Ok(());
-            } else {
-                self.do_update()?;
-            }
-        }
-
-        self.index.query(dep, &mut *self.ops, f)
-    }
-
     /// Decode the configuration stored within the registry.
     ///
     /// This requires that the index has been at least checked out.
@@ -455,7 +434,24 @@ impl<'cfg> Source for RegistrySource<'cfg> {
     }
 
     fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        self.query(dep, f)
+        // If this is a precise dependency, then it came from a lockfile and in
+        // theory the registry is known to contain this version. If, however, we
+        // come back with no summaries, then our registry may need to be
+        // updated, so we fall back to performing a lazy update.
+        if dep.source_id().precise().is_some() && !self.updated {
+            let mut called = false;
+            self.index.query(dep, &mut *self.ops, &mut |s| {
+                called = true;
+                f(s);
+            })?;
+            if called {
+                return Ok(());
+            } else {
+                self.do_update()?;
+            }
+        }
+
+        self.index.query(dep, &mut *self.ops, f)
     }
 
     fn update(&mut self) -> CargoResult<()> {
index a9cce6a17d512c72b5be908a02671735b61e6e8d..9d2ea2c41e06f9b7dde894b4d48a0f82503ed422 100644 (file)
@@ -19,19 +19,6 @@ impl<'cfg> ReplacedSource<'cfg> {
             inner: src,
         }
     }
-
-    fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        let (replace_with, to_replace) = (&self.replace_with, &self.to_replace);
-        let dep = dep.clone().map_source(to_replace, replace_with);
-
-        self.inner
-            .query(
-                &dep,
-                &mut |summary| f(summary.map_source(replace_with, to_replace)),
-            )
-            .chain_err(|| format!("failed to query replaced source {}", self.to_replace))?;
-        Ok(())
-    }
 }
 
 impl<'cfg> Source for ReplacedSource<'cfg> {
@@ -48,7 +35,16 @@ impl<'cfg> Source for ReplacedSource<'cfg> {
     }
 
     fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
-        self.query(dep, f)
+        let (replace_with, to_replace) = (&self.replace_with, &self.to_replace);
+        let dep = dep.clone().map_source(to_replace, replace_with);
+
+        self.inner
+            .query(
+                &dep,
+                &mut |summary| f(summary.map_source(replace_with, to_replace)),
+            )
+            .chain_err(|| format!("failed to query replaced source {}", self.to_replace))?;
+        Ok(())
     }
 
     fn update(&mut self) -> CargoResult<()> {