Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixups for cargo-semver-checks #4

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ jobs:
name: Test
strategy:
matrix:
os: [ubuntu-22.04, windows-2022]
os:
- ubuntu-22.04
#- windows-2022
features: ["--features git", "--features sparse", "--features local-builder,sparse"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
3 changes: 0 additions & 3 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ pub use sparse::SparseIndex;
#[cfg(feature = "sparse")]
pub use sparse_remote::{AsyncRemoteSparseIndex, RemoteSparseIndex};

#[cfg(any(feature = "sparse", feature = "local-builder"))]
pub use reqwest;

/// Global configuration of an index, reflecting the [contents of config.json](https://doc.rust-lang.org/cargo/reference/registries.html#index-format).
#[derive(Eq, PartialEq, PartialOrd, Ord, Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct IndexConfig {
Expand Down
55 changes: 53 additions & 2 deletions src/index/git_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ impl RemoteGitIndex {
/// Performs a fetch from the remote index repository.
///
/// This method performs network I/O.
///
/// If there is a new remote HEAD, this will invalidate all local cache entries
#[inline]
pub fn fetch(&mut self) -> Result<(), Error> {
self.fetch_with_options(gix::progress::Discard, &AtomicBool::default())
Expand Down Expand Up @@ -366,3 +364,56 @@ pub enum GitError {
#[error("unable to update HEAD to remote HEAD")]
UnableToUpdateHead,
}

impl GitError {
/// Returns true if the error is a (potentially) spurious network error that
/// indicates a retry of the operation could succeed
#[inline]
pub fn is_spurious(&self) -> bool {
use gix::protocol::transport::IsSpuriousError;

if let Self::Fetch(fe) | Self::CloneFetch(gix::clone::fetch::Error::Fetch(fe)) = self {
fe.is_spurious()
} else {
false
}
}

/// Returns true if a fetch could not be completed successfully due to the
/// repo being locked, and could succeed if retried
#[inline]
pub fn is_locked(&self) -> bool {
if let Self::Fetch(gix::remote::fetch::Error::UpdateRefs(ure))
| Self::CloneFetch(gix::clone::fetch::Error::Fetch(
gix::remote::fetch::Error::UpdateRefs(ure),
)) = self
{
if let gix::remote::fetch::refs::update::Error::EditReferences(ere) = ure {
return match ere {
gix::reference::edit::Error::FileTransactionPrepare(ftpe) => {
use gix::refs::file::transaction::prepare::Error as PrepError;
if let PrepError::LockAcquire { source, .. }
| PrepError::PackedTransactionAcquire(source) = ftpe
{
// currently this is either io or permanentlylocked, but just in case
// more variants are added, we just assume it's possible to retry
// in anything but the permanentlylocked variant
!matches!(source, gix::lock::acquire::Error::PermanentlyLocked { .. })
} else {
false
}
}
gix::reference::edit::Error::FileTransactionCommit(ftce) => {
matches!(
ftce,
gix::refs::file::transaction::commit::Error::LockCommit { .. }
)
}
_ => false,
};
}
}

false
}
}
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ pub use index::{
};
pub use krate::{IndexDependency, IndexKrate, IndexVersion};
pub use krate_name::KrateName;

/// Reexports of some crates for easier downstream usage without requiring adding
/// your own dependencies
pub mod external {
#[cfg(feature = "git")]
pub use gix;
#[cfg(any(feature = "sparse", feature = "local-builder"))]
pub use reqwest;
}