Skip to content

Commit fb75bb2

Browse files
committed
feat: gix status -s/--statistics to obtain additional information on what happened.
This is useful for understanding performance characteristics in detail.
1 parent 02ffd20 commit fb75bb2

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

gitoxide-core/src/repository/status.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct Options {
2020
pub format: OutputFormat,
2121
pub submodules: Submodules,
2222
pub thread_limit: Option<usize>,
23+
pub statistics: bool,
2324
}
2425

2526
pub fn show(
@@ -33,12 +34,13 @@ pub fn show(
3334
// TODO: implement this
3435
submodules: _,
3536
thread_limit,
37+
statistics,
3638
}: Options,
3739
) -> anyhow::Result<()> {
3840
if format != OutputFormat::Human {
3941
bail!("Only human format is supported right now");
4042
}
41-
let mut index = repo.index()?;
43+
let mut index = repo.index_or_empty()?;
4244
let index = gix::threading::make_mut(&mut index);
4345
let pathspec = repo.pathspec(
4446
pathspecs,
@@ -65,7 +67,7 @@ pub fn show(
6567
_ => unreachable!("state must be attributes stack only"),
6668
},
6769
};
68-
gix_status::index_as_worktree(
70+
let outcome = gix_status::index_as_worktree(
6971
index,
7072
repo.work_dir()
7173
.context("This operation cannot be run on a bare repository")?,
@@ -86,6 +88,10 @@ pub fn show(
8688
options,
8789
)?;
8890

91+
if statistics {
92+
writeln!(err, "{outcome:#?}").ok();
93+
}
94+
8995
writeln!(err, "\nhead -> index and untracked files aren't implemented yet")?;
9096
progress.show_throughput(start);
9197
Ok(())
@@ -158,6 +164,15 @@ fn change_to_char(change: &Change<()>) -> u8 {
158164
match change {
159165
Change::Removed => b'D',
160166
Change::Type => b'T',
161-
Change::SubmoduleModification(_) | Change::Modification { .. } => b'M',
167+
Change::SubmoduleModification(_) => b'M',
168+
Change::Modification {
169+
executable_bit_changed, ..
170+
} => {
171+
if *executable_bit_changed {
172+
b'X'
173+
} else {
174+
b'M'
175+
}
176+
}
162177
}
163178
}

src/plumbing/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ pub fn main() -> Result<()> {
133133
})?;
134134

135135
match cmd {
136-
Subcommands::Status(crate::plumbing::options::status::Platform { submodules, pathspec }) => prepare_and_run(
136+
Subcommands::Status(crate::plumbing::options::status::Platform {
137+
statistics,
138+
submodules,
139+
pathspec,
140+
}) => prepare_and_run(
137141
"status",
138142
trace,
139143
auto_verbose,
@@ -150,6 +154,7 @@ pub fn main() -> Result<()> {
150154
progress,
151155
core::repository::status::Options {
152156
format,
157+
statistics,
153158
thread_limit: thread_limit.or(cfg!(target_os = "macos").then_some(3)), // TODO: make this a configurable when in `gix`, this seems to be optimal on MacOS, linux scales though!
154159
submodules: match submodules {
155160
Submodules::All => core::repository::status::Submodules::All,

src/plumbing/options/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ pub mod status {
205205
/// Define how to display submodule status.
206206
#[clap(long, default_value = "all")]
207207
pub submodules: Submodules,
208+
/// Print additional statistics to help understanding performance.
209+
#[clap(long, short = 's')]
210+
pub statistics: bool,
208211
/// The git path specifications to list attributes for, or unset to read from stdin one per line.
209212
#[clap(value_parser = CheckPathSpec)]
210213
pub pathspec: Vec<BString>,

0 commit comments

Comments
 (0)