Skip to content

Commit

Permalink
Cleanup (#190)
Browse files Browse the repository at this point in the history
* Remove unused dependency

* Fix lint

* Rustfmt

* Update dependencies
  • Loading branch information
Jake-Shadle authored Dec 11, 2023
1 parent 988078b commit 9590201
Show file tree
Hide file tree
Showing 8 changed files with 695 additions and 549 deletions.
1,163 changes: 650 additions & 513 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,32 @@ flate2 = { version = "1.0", default-features = false, features = [
] }
home = "0.5"
http = "0.2"
memchr = "2.3"
rayon = "1.5"
remove_dir_all = "0.8"
reqwest = { version = "0.11", default-features = false, features = [
"rustls-tls",
# We could do this manually, but..meh
"gzip",
] }
ring = "0.16"
rusty-s3 = { version = "0.4", optional = true }
ring = "0.17"
rusty-s3 = { version = "0.5", optional = true }
serde = { version = "1.0", features = ["derive", "rc"] }
quick-xml = { version = "0.27", features = ["serialize"], optional = true }
quick-xml = { version = "0.30", features = ["serialize"], optional = true }
tame-gcs = { version = "0.12", optional = true }
tame-index = { version = "0.5", features = ["git", "sparse"] }
tame-index = { version = "0.8", features = ["git", "sparse"] }
tame-oauth = { version = "0.9", features = ["gcp"], optional = true }
tar = "0.4"
tempfile = "3.1"
time = { version = "0.3", features = ["formatting", "macros"] }
toml = "0.7"
toml = "0.8"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
url = { version = "2.2", features = ["serde"] }
walkdir = "2.3"
zstd = "0.12"
zstd = "0.13"

[dependencies.gix]
version = "0.52"
version = "0.55"
features = [
"max-performance-safe",
"blocking-network-client",
Expand Down
6 changes: 3 additions & 3 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ skip = [
# tracing-subscriber and similar-asserts
{ name = "regex-syntax", version = "=0.6.29" },
# hyper/tokio
{ name = "socket2", version = "=0.4.9" },
{ name = "socket2", version = "=0.4.10" },
# only a couple left on old 1.0 version
{ name = "syn", version = "=1.0.109" },
]
skip-tree = [
# similar
{ name = "bstr", version = "=0.2.17" },
# h2/hyper
{ name = "indexmap", version = "=1.9.3" },
# ugh
{ name = "windows-sys" },
# gix has a several duplicates I don't feel like dealing with atm
{ name = "gix" },
]

[licenses]
Expand Down
11 changes: 4 additions & 7 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,10 @@ pub fn read_lock_files(
{
// This will most likely be an extremely short list, so we just do a
// linear search
let Some((ind, registry)) = registries
.iter()
.enumerate()
.find(|(_, reg)| {
source.ends_with(tame_index::CRATES_IO_INDEX) && reg.is_crates_io() || source.ends_with(reg.index.as_str())
})
else {
let Some((ind, registry)) = registries.iter().enumerate().find(|(_, reg)| {
source.ends_with(tame_index::CRATES_IO_INDEX) && reg.is_crates_io()
|| source.ends_with(reg.index.as_str())
}) else {
warn!(
"skipping '{}:{}': unknown registry index '{reg_src}' encountered",
pkg.name, pkg.version
Expand Down
16 changes: 13 additions & 3 deletions src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub async fn registry(
tame_index::index::RemoteGitIndex::new(
tame_index::index::GitIndex::new(location)
.context("unable to open git index")?,
&tame_index::index::FileLock::unlocked(),
)
.context("failed to fetch")?
};
Expand All @@ -114,12 +115,15 @@ pub async fn registry(
// worth it for a few hundred crates (probably), but see
// https://github.com/frewsxcv/rust-crates-index/blob/a9b60653efb72d9e6be98c4f8fe56194475cbd3f/src/git/mod.rs#L316-L360
// for a way this could be done in the future
let unlocked = &tame_index::index::FileLock::unlocked();
for name in krates {
let Ok(name) = name.as_str().try_into() else {
warn!("crate name '{name}' is invalid");
continue;
};
if let Err(err) = rgi.krate(name, true /* write the cache entry */) {
if let Err(err) =
rgi.krate(name, true /* write the cache entry */, unlocked)
{
warn!("unable to write .cache entry: {err:#}");
}
}
Expand All @@ -144,8 +148,14 @@ pub async fn registry(
// We don't particularly care if an individual crate fails here
// since the index will be healed by cargo, but still good to
// know if something was amiss
for (name, res) in
index.krates(krates.into_iter().collect(), true, None).await
for (name, res) in index
.krates(
krates.into_iter().collect(),
true,
None,
&tame_index::index::FileLock::unlocked(),
)
.await
{
match res {
Ok(Some(_)) => {}
Expand Down
19 changes: 9 additions & 10 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub(crate) fn checkout(
"autocrlf"
.try_into()
.context("autocrlf is not a valid key")?,
"false",
"false".into(),
);
Ok(())
})
Expand Down Expand Up @@ -154,7 +154,9 @@ impl Submodule {
}

fn read_submodule_config(config: &gix::config::File<'_>) -> Vec<Submodule> {
let Some(iter) = config.sections_by_name("submodule") else { return Vec::new(); };
let Some(iter) = config.sections_by_name("submodule") else {
return Vec::new();
};

iter.filter_map(|sec| {
// Each submodule _should_ be a subsection with a name, that
Expand Down Expand Up @@ -209,7 +211,7 @@ fn modify_config(
.context("failed to open local config")?;
local_config.write_all(config.detect_newline_style())?;
config
.write_to_filter(&mut local_config, |s| {
.write_to_filter(&mut local_config, &mut |s| {
s.meta().source == gix::config::Source::Local
})
.context("failed to write submodules to config")?;
Expand Down Expand Up @@ -252,8 +254,8 @@ fn reset(repo: &mut gix::Repository, rev: gix::ObjectId) -> Result<()> {
let objects = repo.objects.clone().into_arc()?;
move |oid, buf| objects.find_blob(oid, buf)
},
&mut Discard,
&mut Discard,
&Discard,
&Discard,
&Default::default(),
opts,
)
Expand Down Expand Up @@ -393,10 +395,7 @@ pub(crate) fn prepare_submodules(src: PathBuf, target: PathBuf, rev: gix::Object
// A submodule which is listed in .gitmodules but not actually
// checked out will not have a head id, so we should ignore it.
let Some(head) = subm.head_id else {
tracing::debug!(
"skipping submodule '{}' without HEAD",
subm.name
);
tracing::debug!("skipping submodule '{}' without HEAD", subm.name);
return Ok(());
};

Expand Down Expand Up @@ -452,7 +451,7 @@ pub(crate) fn prepare_submodules(src: PathBuf, target: PathBuf, rev: gix::Object
"autocrlf"
.try_into()
.context("autocrlf is not a valid key")?,
"false",
"false".into(),
);

config
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ pub struct Krate {
}

impl Ord for Krate {
#[inline]
fn cmp(&self, b: &Self) -> std::cmp::Ordering {
self.source.cmp(&b.source)
}
}

impl PartialOrd for Krate {
#[inline]
fn partial_cmp(&self, b: &Self) -> Option<std::cmp::Ordering> {
self.source.partial_cmp(&b.source)
Some(self.cmp(b))
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ async fn maybe_fetch_index(index_path: &Path, registry: &Registry) -> anyhow::Re
{
let span = tracing::debug_span!("fetch", index = index_url.clone());
let _sf = span.enter();
let mut rgi = tame_index::index::RemoteGitIndex::new(gi)?;
rgi.fetch()?;
let unlocked = &tame_index::index::FileLock::unlocked();
let mut rgi = tame_index::index::RemoteGitIndex::new(gi, unlocked)?;
rgi.fetch(unlocked)?;
}

// Write a file to the directory to let cargo know when it was updated
std::fs::File::create(last_updated).context("failed to crate .last-updated")?;
Ok(())
})
Expand Down Expand Up @@ -488,7 +488,9 @@ pub async fn crates(ctx: &crate::Ctx) -> anyhow::Result<Summary> {
// As each remote I/O op completes, pass it off to the thread pool to do
// the more CPU intensive work of decompression, etc
while let Some(res) = tasks.join_next().await {
let Ok(res) = res else { continue; };
let Ok(res) = res else {
continue;
};

if let Some(pkg) = res {
let _ = tx.send(pkg);
Expand Down

0 comments on commit 9590201

Please sign in to comment.