Skip to content

Commit

Permalink
feat: --statistics for gix excludes query
Browse files Browse the repository at this point in the history
With it one gets some insights into the work done to fulfil the query.
  • Loading branch information
Byron committed May 9, 2023
1 parent c8d6982 commit 450b232
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions gitoxide-core/src/repository/exclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ pub mod query {
pub format: OutputFormat,
pub overrides: Vec<OsString>,
pub show_ignore_patterns: bool,
pub statistics: bool,
}
}

pub fn query(
repo: gix::Repository,
pathspecs: impl Iterator<Item = gix::path::Spec>,
mut out: impl io::Write,
mut err: impl io::Write,
query::Options {
overrides,
format,
show_ignore_patterns,
statistics,
}: query::Options,
) -> anyhow::Result<()> {
if format != OutputFormat::Human {
Expand Down Expand Up @@ -62,5 +65,10 @@ pub fn query(
}
}
}

if let Some(stats) = statistics.then(|| cache.take_statistics()) {
out.flush()?;
writeln!(err, "{:#?}", stats).ok();
}
Ok(())
}
5 changes: 4 additions & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ pub fn main() -> Result<()> {
},
Subcommands::Exclude(cmd) => match cmd {
exclude::Subcommands::Query {
statistics,
patterns,
pathspecs,
show_ignore_patterns,
Expand All @@ -871,7 +872,7 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
None,
move |_progress, out, _err| {
move |_progress, out, err| {
use gix::bstr::ByteSlice;
core::repository::exclude::query(
repository(Mode::Strict)?,
Expand All @@ -886,10 +887,12 @@ pub fn main() -> Result<()> {
Box::new(pathspecs.into_iter())
},
out,
err,
core::repository::exclude::query::Options {
format,
show_ignore_patterns,
overrides: patterns,
statistics,
},
)
},
Expand Down
3 changes: 3 additions & 0 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ pub mod exclude {
pub enum Subcommands {
/// Check if path-specs are excluded and print the result similar to `git check-ignore`.
Query {
/// Print various statistics to stderr
#[clap(long, short = 's')]
statistics: bool,
/// Show actual ignore patterns instead of un-excluding an entry.
///
/// That way one can understand why an entry might not be excluded.
Expand Down

0 comments on commit 450b232

Please sign in to comment.