Clean up alt registries lookup.
authorWithout Boats <woboats@gmail.com>
Fri, 6 Oct 2017 20:29:37 +0000 (13:29 -0700)
committerWithout Boats <woboats@gmail.com>
Fri, 6 Oct 2017 20:29:37 +0000 (13:29 -0700)
src/cargo/core/source/source_id.rs

index 6719b6ed9be3c576d4b12c7669b3cbe0a77b411c..75d180d0f13cece1460c4508bba189c021f50425 100644 (file)
@@ -14,7 +14,7 @@ use ops;
 use sources::git;
 use sources::{PathSource, GitSource, RegistrySource, CRATES_IO};
 use sources::DirectorySource;
-use util::{Config, ConfigValue as CV, CargoResult, ToUrl};
+use util::{Config, CargoResult, ToUrl};
 
 /// Unique identifier for a source of packages.
 #[derive(Clone, Eq, Debug)]
@@ -183,22 +183,17 @@ impl SourceId {
     }
 
     pub fn alt_registry(config: &Config, key: &str) -> CargoResult<SourceId> {
-        let registries = config.get_table("registries")?;
-        match registries.as_ref().and_then(|registries| registries.val.get(key)) {
-            Some(registry)  => {
-                let index = config.get_str(&format!("registries.{}.index", key))?.to_url()?;
-
-                Ok(SourceId {
-                    inner: Arc::new(SourceIdInner {
-                        kind: Kind::Registry,
-                        canonical_url: git::canonicalize_url(&index)?,
-                        url: index,
-                        precise: None,
-                    }),
-                })
-            }
-            None => Err(format!("Required unknown registry source: `{}`", key).into())
-        }
+        if let Some(index) = config.get_string(&format!("registries.{}.index", key))? {
+            let url = index.val.to_url()?;
+            Ok(SourceId {
+                inner: Arc::new(SourceIdInner {
+                    kind: Kind::Registry,
+                    canonical_url: git::canonicalize_url(&url)?,
+                    url: url,
+                    precise: None,
+                }),
+            })
+        } else { Err(format!("No index found for registry: `{}`", key).into()) }
     }
 
     /// Get this source URL