From f947326a0c7c984792420f2d875f7f519cc7adfa Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 3 May 2018 23:14:21 +0100 Subject: [PATCH] Start moving methods from Registry to Source For now just move `supports_checksums` and `requires_precise` methods down from `Registry` to `Source`, as they're not as entangled as `query`. --- src/cargo/core/registry.rs | 32 ------------------------------- src/cargo/core/source/mod.rs | 18 +++++++++++++++++ src/cargo/sources/directory.rs | 12 ++++++------ src/cargo/sources/git/source.rs | 12 ++++++------ src/cargo/sources/path.rs | 12 ++++++------ src/cargo/sources/registry/mod.rs | 12 ++++++------ src/cargo/sources/replaced.rs | 12 ++++++------ tests/testsuite/resolve.rs | 6 ------ 8 files changed, 48 insertions(+), 68 deletions(-) diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index ba1866bc8..b219105bf 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -21,28 +21,12 @@ pub trait Registry { self.query(dep, &mut |s| ret.push(s))?; Ok(ret) } - - /// Returns whether or not this registry will return summaries with - /// checksums listed. - fn supports_checksums(&self) -> bool; - - /// Returns whether or not this registry will return summaries with - /// the `precise` field in the source id listed. - fn requires_precise(&self) -> bool; } impl<'a, T: ?Sized + Registry + 'a> Registry for Box { fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> { (**self).query(dep, f) } - - fn supports_checksums(&self) -> bool { - (**self).supports_checksums() - } - - fn requires_precise(&self) -> bool { - (**self).requires_precise() - } } /// This structure represents a registry of known packages. It internally @@ -535,14 +519,6 @@ impl<'cfg> Registry for PackageRegistry<'cfg> { f(self.lock(override_summary)); Ok(()) } - - fn supports_checksums(&self) -> bool { - false - } - - fn requires_precise(&self) -> bool { - false - } } fn lock(locked: &LockedMap, patches: &HashMap>, summary: Summary) -> Summary { @@ -703,13 +679,5 @@ pub mod test { Ok(()) } } - - fn supports_checksums(&self) -> bool { - false - } - - fn requires_precise(&self) -> bool { - false - } } } diff --git a/src/cargo/core/source/mod.rs b/src/cargo/core/source/mod.rs index b842a5792..10418714b 100644 --- a/src/cargo/core/source/mod.rs +++ b/src/cargo/core/source/mod.rs @@ -14,6 +14,14 @@ pub trait Source: Registry { /// Returns the `SourceId` corresponding to this source fn source_id(&self) -> &SourceId; + /// Returns whether or not this registry will return summaries with + /// checksums listed. + fn supports_checksums(&self) -> bool; + + /// Returns whether or not this registry will return summaries with + /// the `precise` field in the source id listed. + fn requires_precise(&self) -> bool; + /// The update method performs any network operations required to /// get the entire list of all names, versions and dependencies of /// packages managed by the Source. @@ -52,6 +60,16 @@ impl<'a, T: Source + ?Sized + 'a> Source for Box { (**self).source_id() } + /// Forwards to `Source::supports_checksums` + fn supports_checksums(&self) -> bool { + (**self).supports_checksums() + } + + /// Forwards to `Source::requires_precise` + fn requires_precise(&self) -> bool { + (**self).requires_precise() + } + /// Forwards to `Source::update` fn update(&mut self) -> CargoResult<()> { (**self).update() diff --git a/src/cargo/sources/directory.rs b/src/cargo/sources/directory.rs index a4d36ead4..21a167ac1 100644 --- a/src/cargo/sources/directory.rs +++ b/src/cargo/sources/directory.rs @@ -53,6 +53,12 @@ impl<'cfg> Registry for DirectorySource<'cfg> { } Ok(()) } +} + +impl<'cfg> Source for DirectorySource<'cfg> { + fn source_id(&self) -> &SourceId { + &self.source_id + } fn supports_checksums(&self) -> bool { true @@ -61,12 +67,6 @@ impl<'cfg> Registry for DirectorySource<'cfg> { fn requires_precise(&self) -> bool { true } -} - -impl<'cfg> Source for DirectorySource<'cfg> { - fn source_id(&self) -> &SourceId { - &self.source_id - } fn update(&mut self) -> CargoResult<()> { self.packages.clear(); diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index 98e423101..332f37aa2 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -131,6 +131,12 @@ impl<'cfg> Registry for GitSource<'cfg> { .expect("BUG: update() must be called before query()"); src.query(dep, f) } +} + +impl<'cfg> Source for GitSource<'cfg> { + fn source_id(&self) -> &SourceId { + &self.source_id + } fn supports_checksums(&self) -> bool { false @@ -139,12 +145,6 @@ impl<'cfg> Registry for GitSource<'cfg> { fn requires_precise(&self) -> bool { true } -} - -impl<'cfg> Source for GitSource<'cfg> { - fn source_id(&self) -> &SourceId { - &self.source_id - } fn update(&mut self) -> CargoResult<()> { let lock = diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index aa654abee..e24e49968 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -484,6 +484,12 @@ impl<'cfg> Registry for PathSource<'cfg> { } Ok(()) } +} + +impl<'cfg> Source for PathSource<'cfg> { + fn source_id(&self) -> &SourceId { + &self.source_id + } fn supports_checksums(&self) -> bool { false @@ -492,12 +498,6 @@ impl<'cfg> Registry for PathSource<'cfg> { fn requires_precise(&self) -> bool { false } -} - -impl<'cfg> Source for PathSource<'cfg> { - fn source_id(&self) -> &SourceId { - &self.source_id - } fn update(&mut self) -> CargoResult<()> { if !self.updated { diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 96cce76d4..19c270ab0 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -441,6 +441,12 @@ impl<'cfg> Registry for RegistrySource<'cfg> { self.index.query(dep, &mut *self.ops, f) } +} + +impl<'cfg> Source for RegistrySource<'cfg> { + fn source_id(&self) -> &SourceId { + &self.source_id + } fn supports_checksums(&self) -> bool { true @@ -449,12 +455,6 @@ impl<'cfg> Registry for RegistrySource<'cfg> { fn requires_precise(&self) -> bool { false } -} - -impl<'cfg> Source for RegistrySource<'cfg> { - fn source_id(&self) -> &SourceId { - &self.source_id - } fn update(&mut self) -> CargoResult<()> { // If we have an imprecise version then we don't know what we're going diff --git a/src/cargo/sources/replaced.rs b/src/cargo/sources/replaced.rs index 3f223ef61..84bab7f54 100644 --- a/src/cargo/sources/replaced.rs +++ b/src/cargo/sources/replaced.rs @@ -34,6 +34,12 @@ impl<'cfg> Registry for ReplacedSource<'cfg> { .chain_err(|| format!("failed to query replaced source {}", self.to_replace))?; Ok(()) } +} + +impl<'cfg> Source for ReplacedSource<'cfg> { + fn source_id(&self) -> &SourceId { + &self.to_replace + } fn supports_checksums(&self) -> bool { self.inner.supports_checksums() @@ -42,12 +48,6 @@ impl<'cfg> Registry for ReplacedSource<'cfg> { fn requires_precise(&self) -> bool { self.inner.requires_precise() } -} - -impl<'cfg> Source for ReplacedSource<'cfg> { - fn source_id(&self) -> &SourceId { - &self.to_replace - } fn update(&mut self) -> CargoResult<()> { self.inner diff --git a/tests/testsuite/resolve.rs b/tests/testsuite/resolve.rs index e6377a541..4ba61b321 100644 --- a/tests/testsuite/resolve.rs +++ b/tests/testsuite/resolve.rs @@ -36,12 +36,6 @@ fn resolve_with_config( } Ok(()) } - fn supports_checksums(&self) -> bool { - false - } - fn requires_precise(&self) -> bool { - false - } } let mut registry = MyRegistry(registry); let summary = Summary::new(pkg.clone(), deps, BTreeMap::new(), None, false).unwrap(); -- 2.30.2