Skip to content

Commit

Permalink
Use new Crate::from_slice constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 authored and Joshua Nelson committed Aug 14, 2020
1 parent 4696a0f commit 5397374
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2018"
log = "0.4"
regex = "1"
structopt = "0.3"
crates-index = "0.15.0"
crates-index = "0.15.1"
crates-index-diff = "7"
reqwest = { version = "0.10.6", features = ["blocking", "json"] } # TODO: Remove blocking when async is ready
semver = { version = "0.9", features = ["serde"] }
Expand Down
10 changes: 1 addition & 9 deletions src/index/crates.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crates_index::Crate;
use failure::ResultExt;
use std::io::{Seek, SeekFrom, Write};

pub(crate) struct Crates {
repo: git2::Repository,
Expand All @@ -18,23 +17,16 @@ impl Crates {
.find_commit(self.repo.refname_to_id("refs/remotes/origin/master")?)?
.tree()?;

// crates_index doesn't publicly expose their slice constructor, so need to write each blob
// to a file before loading it as a `Crate`.
let mut tmp = tempfile::NamedTempFile::new()?;

let mut result = Ok(());

tree.walk(git2::TreeWalkMode::PreOrder, |_, entry| {
result = (|| {
if let Some(blob) = entry.to_object(&self.repo)?.as_blob() {
tmp.write_all(blob.content())?;
if let Ok(krate) = Crate::new(tmp.path()) {
if let Ok(krate) = Crate::from_slice(blob.content()) {
f(krate);
} else {
log::warn!("Not a crate '{}'", entry.name().unwrap());
}
tmp.as_file().set_len(0)?;
tmp.seek(SeekFrom::Start(0))?;
}
Result::<(), failure::Error>::Ok(())
})()
Expand Down

0 comments on commit 5397374

Please sign in to comment.