Skip to content

Commit

Permalink
Add configuration for git index (#54)
Browse files Browse the repository at this point in the history
* Add configuration for git index

* Update CHANGELOG

* Sigh
  • Loading branch information
Jake-Shadle authored Jun 13, 2023
1 parent a7c9e7c commit 98d4388
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [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.
Expand Down
4 changes: 3 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 16 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,10 @@ pub struct Builder {
target_filters: Vec<TargetFilter>,
workspace_filters: Vec<PathBuf>,
exclude: Vec<crate::PkgSpec>,
workspace: bool,
ignore_kinds: u32,
workspace: bool,
#[cfg(feature = "prefer-index")]
allow_git_index: bool,
}

impl Builder {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
20 changes: 12 additions & 8 deletions src/builder/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crates_index::Crate> {
// Attempt http first, as this will be the default in future cargo versions
Expand All @@ -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 <https://github.com/rust-lang/cargo/issues/11319>, 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
Expand Down

0 comments on commit 98d4388

Please sign in to comment.