/// This is the main cargo registry by default, but it can be overridden in
/// a `.cargo/config`.
pub fn crates_io(config: &Config) -> CargoResult<SourceId> {
- let cfg = ops::registry_configuration(config, None)?;
- let url = if let Some(ref index) = cfg.index {
- static WARNED: AtomicBool = ATOMIC_BOOL_INIT;
- if !WARNED.swap(true, SeqCst) {
- config.shell().warn("custom registry support via \
- the `registry.index` configuration is \
- being removed, this functionality \
- will not work in the future")?;
- }
- &index[..]
- } else {
- CRATES_IO
- };
- let url = url.to_url()?;
- SourceId::for_registry(&url)
+ config.crates_io_source_id(|| {
+ let cfg = ops::registry_configuration(config, None)?;
+ let url = if let Some(ref index) = cfg.index {
+ static WARNED: AtomicBool = ATOMIC_BOOL_INIT;
+ if !WARNED.swap(true, SeqCst) {
+ config.shell().warn("custom registry support via \
+ the `registry.index` configuration is \
+ being removed, this functionality \
+ will not work in the future")?;
+ }
+ &index[..]
+ } else {
+ CRATES_IO
+ };
+ let url = url.to_url()?;
+ SourceId::for_registry(&url)
+ })
}
pub fn alt_registry(config: &Config, key: &str) -> CargoResult<SourceId> {
use lazycell::LazyCell;
use core::shell::Verbosity;
-use core::{Shell, CliUnstable};
+use core::{Shell, CliUnstable, SourceId};
use ops;
use url::Url;
use util::ToUrl;
cli_flags: CliUnstable,
/// A handle on curl easy mode for http calls
easy: LazyCell<RefCell<Easy>>,
+ /// Cache of the `SourceId` for crates.io
+ crates_io_source_id: LazyCell<SourceId>,
}
impl Config {
},
cli_flags: CliUnstable::default(),
easy: LazyCell::new(),
+ crates_io_source_id: LazyCell::new(),
}
}
}
Ok(http)
}
+
+ pub fn crates_io_source_id<F>(&self, f: F) -> CargoResult<SourceId>
+ where F: FnMut() -> CargoResult<SourceId>
+ {
+ Ok(self.crates_io_source_id.try_borrow_with(f)?.clone())
+ }
}
#[derive(Eq, PartialEq, Clone, Copy)]