diff --git a/CHANGELOG.md b/CHANGELOG.md index 996a606..20c5ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Fixed +- [PR#54](https://github.com/EmbarkStudios/krates/pull/54) fixed an issue where the crates.io index was unconditionally opened, and synced, if the `prefer-index` feature was enabled, causing long stalls if using the crates.io sparse index instead. + ## [0.13.0] - 2023-04-04 ### Changed - [PR#53](https://github.com/EmbarkStudios/krates/pull/53) updated `cfg-expr` to 0.14 and `crates-index` to 0.19. diff --git a/deny.toml b/deny.toml index 1b1c53d..c7bd445 100644 --- a/deny.toml +++ b/deny.toml @@ -18,8 +18,10 @@ multiple-versions = "deny" skip = [ # Doesn't matter { name = "hermit-abi" }, +] +skip-tree = [ # dev only but still sigh - { name = "windows-sys", version = "=0.42.0" }, + { name = "windows-sys", version = "<0.48.0" }, ] [sources] diff --git a/src/builder.rs b/src/builder.rs index 3a6c35c..ebe7f65 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -310,8 +310,10 @@ pub struct Builder { target_filters: Vec, workspace_filters: Vec, exclude: Vec, - workspace: bool, ignore_kinds: u32, + workspace: bool, + #[cfg(feature = "prefer-index")] + allow_git_index: bool, } impl Builder { @@ -488,6 +490,18 @@ impl Builder { self } + /// Allow use of the crates.io git index. + /// + /// As of cargo 1.70.0, the git index for crates.io is no longer the default, + /// in favor of the _much_ faster spare HTTP index, it is highly recommended + /// to only set this option to true if you for some reason can't use the + /// HTTP index + #[cfg(feature = "prefer-index")] + pub fn allow_git_index(&mut self, allow: bool) -> &mut Self { + self.allow_git_index = allow; + self + } + /// Builds a [`Krates`] graph using metadata that be retrieved via the /// specified metadata command. If `on_filter` is specified, it will be /// called with each package that was filtered from the graph, if any. @@ -771,7 +785,7 @@ impl Builder { } #[cfg(feature = "prefer-index")] - let index = index::open(); + let index = index::ComboIndex::open(self.allow_git_index); while let Some(pid) = pid_stack.pop() { let is_in_workspace = workspace_members.binary_search(pid).is_ok(); diff --git a/src/builder/index.rs b/src/builder/index.rs index 7c72132..55e6724 100644 --- a/src/builder/index.rs +++ b/src/builder/index.rs @@ -4,6 +4,18 @@ pub(super) struct ComboIndex { } impl ComboIndex { + #[inline] + pub(super) fn open(allow_git: bool) -> Self { + Self { + git: if allow_git { + crates_index::Index::new_cargo_default().ok() + } else { + None + }, + http: crates_index::SparseIndex::from_url("sparse+https://index.crates.io/").ok(), + } + } + #[inline] fn krate(&self, name: &str) -> Option { // Attempt http first, as this will be the default in future cargo versions @@ -15,14 +27,6 @@ impl ComboIndex { } } -#[inline] -pub(super) fn open() -> ComboIndex { - ComboIndex { - git: crates_index::Index::new_cargo_default().ok(), - http: crates_index::SparseIndex::from_url("sparse+https://index.crates.io/").ok(), - } -} - /// Due to , we can't actually /// trust cargo to give us the correct package metadata, so we instead use the /// (presumably) correct data from the the index