Skip to content

Commit

Permalink
keep-going support on the command-line (#301)
Browse files Browse the repository at this point in the history
That way it's possible to see all the errors that happened which
may help with debugging certain issues.
  • Loading branch information
Byron committed Mar 6, 2022
1 parent ecebc55 commit 73a7393
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
20 changes: 19 additions & 1 deletion gitoxide-core/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::bail;
use std::path::{Path, PathBuf};

use git_repository as git;
use git_repository::worktree::index::checkout;
use git_repository::{odb::FindExt, Progress};

pub struct Options {
Expand Down Expand Up @@ -106,6 +107,7 @@ pub mod checkout_exclusive {
pub index: super::Options,
/// If true, all files will be written with zero bytes despite having made an ODB lookup.
pub empty_files: bool,
pub keep_going: bool,
}
}

Expand All @@ -117,6 +119,7 @@ pub fn checkout_exclusive(
checkout_exclusive::Options {
index: Options { object_hash, .. },
empty_files,
keep_going,
}: checkout_exclusive::Options,
) -> anyhow::Result<()> {
let repo = repo
Expand Down Expand Up @@ -157,6 +160,7 @@ pub fn checkout_exclusive(
// TODO: turn the two following flags into an enum
destination_is_initially_empty: true,
overwrite_existing: false,
keep_going,
..Default::default()
};

Expand All @@ -168,7 +172,7 @@ pub fn checkout_exclusive(
bytes.init(None, git::progress::bytes());

let start = std::time::Instant::now();
match &repo {
let checkout::Outcome { errors, collisions } = match &repo {
Some(repo) => git::worktree::index::checkout(
&mut index,
dest_directory,
Expand Down Expand Up @@ -209,5 +213,19 @@ pub fn checkout_exclusive(
entries_for_checkout,
repo.is_none().then(|| "empty").unwrap_or_default()
));

if !(collisions.is_empty() && errors.is_empty()) {
let mut messages = Vec::new();
if !errors.is_empty() {
messages.push(format!("kept going through {} errors(s)", errors.len()));
}
if !collisions.is_empty() {
messages.push(format!("encountered {} collision(s)", collisions.len()));
}
bail!(
"One or more errors occurred - checkout is incomplete: {}",
messages.join(", ")
);
}
Ok(())
}
2 changes: 2 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn main() -> Result<()> {
directory,
empty_files,
repository,
keep_going,
} => prepare_and_run(
"index-checkout",
verbose,
Expand All @@ -97,6 +98,7 @@ pub fn main() -> Result<()> {
core::index::checkout_exclusive::Options {
index: core::index::Options { object_hash, format },
empty_files,
keep_going,
},
)
},
Expand Down
3 changes: 3 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ pub mod index {
/// in the index. Use this measure the impact on extracting objects on overall performance.
#[clap(long, short = 'r')]
repository: Option<PathBuf>,
/// Ignore errors and keep checking out as many files as possible, and report all errors at the end of the operation.
#[clap(long, short = 'k')]
keep_going: bool,
/// Enable to query the object database yet write only empty files. This is useful to measure the overhead of ODB query
/// compared to writing the bytes to disk.
#[clap(long, short = 'e', requires = "repository")]
Expand Down

0 comments on commit 73a7393

Please sign in to comment.