Skip to content

Commit

Permalink
improve error handling and reporting of ein t query
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Feb 25, 2023
1 parent d23fe4b commit d5616b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions gitoxide-core/src/query/engine/update.rs
Expand Up @@ -22,6 +22,7 @@ pub fn update(
repo: &gix::Repository,
con: &mut rusqlite::Connection,
progress: &mut impl gix::Progress,
mut err: impl std::io::Write,
Options {
object_cache_size_mb,
find_copies_harder,
Expand Down Expand Up @@ -294,7 +295,7 @@ pub fn update(
}
}
if tx_stats.send(Ok((chunk_id, out_chunk))).is_err() {
break;
bail!("Thread failed to send result");
}
}
Ok(())
Expand Down Expand Up @@ -357,7 +358,7 @@ pub fn update(
}
}
Err(gix::traverse::commit::ancestors::Error::FindExisting { .. }) => {
eprintln!("shallow repository - commit history is truncated");
writeln!(err, "shallow repository - commit history is truncated").ok();
break;
}
Err(err) => return Err(err.into()),
Expand Down
9 changes: 7 additions & 2 deletions gitoxide-core/src/query/mod.rs
Expand Up @@ -15,9 +15,14 @@ mod db;
mod engine;
pub use engine::Command;

pub fn prepare(repo_dir: &std::path::Path, mut progress: impl gix::Progress, opts: Options) -> anyhow::Result<Engine> {
pub fn prepare(
repo_dir: &std::path::Path,
mut progress: impl gix::Progress,
err: impl std::io::Write,
opts: Options,
) -> anyhow::Result<Engine> {
let repo = gix::discover(repo_dir)?;
let mut con = db::create(repo.git_dir().join("ein.query"))?;
let commits = engine::update(&repo, &mut con, &mut progress, opts)?;
let commits = engine::update(&repo, &mut con, &mut progress, err, opts)?;
Ok(Engine { repo, con, commits })
}
3 changes: 2 additions & 1 deletion src/porcelain/main.rs
Expand Up @@ -57,10 +57,11 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
move |mut progress, out, err| {
move |mut progress, out, mut err| {
let engine = query::prepare(
&repo_dir,
&mut progress,
&mut err,
query::Options {
object_cache_size_mb,
find_copies_harder,
Expand Down

0 comments on commit d5616b6

Please sign in to comment.