Skip to content

Commit 450b232

Browse files
committed
feat: --statistics for gix excludes query
With it one gets some insights into the work done to fulfil the query.
1 parent c8d6982 commit 450b232

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Diff for: gitoxide-core/src/repository/exclude.rs

+8
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ pub mod query {
1414
pub format: OutputFormat,
1515
pub overrides: Vec<OsString>,
1616
pub show_ignore_patterns: bool,
17+
pub statistics: bool,
1718
}
1819
}
1920

2021
pub fn query(
2122
repo: gix::Repository,
2223
pathspecs: impl Iterator<Item = gix::path::Spec>,
2324
mut out: impl io::Write,
25+
mut err: impl io::Write,
2426
query::Options {
2527
overrides,
2628
format,
2729
show_ignore_patterns,
30+
statistics,
2831
}: query::Options,
2932
) -> anyhow::Result<()> {
3033
if format != OutputFormat::Human {
@@ -62,5 +65,10 @@ pub fn query(
6265
}
6366
}
6467
}
68+
69+
if let Some(stats) = statistics.then(|| cache.take_statistics()) {
70+
out.flush()?;
71+
writeln!(err, "{:#?}", stats).ok();
72+
}
6573
Ok(())
6674
}

Diff for: src/plumbing/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ pub fn main() -> Result<()> {
862862
},
863863
Subcommands::Exclude(cmd) => match cmd {
864864
exclude::Subcommands::Query {
865+
statistics,
865866
patterns,
866867
pathspecs,
867868
show_ignore_patterns,
@@ -871,7 +872,7 @@ pub fn main() -> Result<()> {
871872
progress,
872873
progress_keep_open,
873874
None,
874-
move |_progress, out, _err| {
875+
move |_progress, out, err| {
875876
use gix::bstr::ByteSlice;
876877
core::repository::exclude::query(
877878
repository(Mode::Strict)?,
@@ -886,10 +887,12 @@ pub fn main() -> Result<()> {
886887
Box::new(pathspecs.into_iter())
887888
},
888889
out,
890+
err,
889891
core::repository::exclude::query::Options {
890892
format,
891893
show_ignore_patterns,
892894
overrides: patterns,
895+
statistics,
893896
},
894897
)
895898
},

Diff for: src/plumbing/options/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ pub mod exclude {
469469
pub enum Subcommands {
470470
/// Check if path-specs are excluded and print the result similar to `git check-ignore`.
471471
Query {
472+
/// Print various statistics to stderr
473+
#[clap(long, short = 's')]
474+
statistics: bool,
472475
/// Show actual ignore patterns instead of un-excluding an entry.
473476
///
474477
/// That way one can understand why an entry might not be excluded.

0 commit comments

Comments
 (0)