Skip to content

Commit

Permalink
feat: gix status -s/--statistics to obtain additional information o…
Browse files Browse the repository at this point in the history
…n what happened.

This is useful for understanding performance characteristics in detail.
  • Loading branch information
Byron committed Oct 5, 2023
1 parent 7d9ecdd commit 7ba2fa1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
21 changes: 18 additions & 3 deletions gitoxide-core/src/repository/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Options {
pub format: OutputFormat,
pub submodules: Submodules,
pub thread_limit: Option<usize>,
pub statistics: bool,
}

pub fn show(
Expand All @@ -33,12 +34,13 @@ pub fn show(
// TODO: implement this
submodules: _,
thread_limit,
statistics,
}: Options,
) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("Only human format is supported right now");
}
let mut index = repo.index()?;
let mut index = repo.index_or_empty()?;
let index = gix::threading::make_mut(&mut index);
let pathspec = repo.pathspec(
pathspecs,
Expand All @@ -65,7 +67,7 @@ pub fn show(
_ => unreachable!("state must be attributes stack only"),
},
};
gix_status::index_as_worktree(
let outcome = gix_status::index_as_worktree(
index,
repo.work_dir()
.context("This operation cannot be run on a bare repository")?,
Expand All @@ -86,6 +88,10 @@ pub fn show(
options,
)?;

if statistics {
writeln!(err, "{outcome:#?}").ok();
}

writeln!(err, "\nhead -> index and untracked files aren't implemented yet")?;
progress.show_throughput(start);
Ok(())
Expand Down Expand Up @@ -158,6 +164,15 @@ fn change_to_char(change: &Change<()>) -> u8 {
match change {
Change::Removed => b'D',
Change::Type => b'T',
Change::SubmoduleModification(_) | Change::Modification { .. } => b'M',
Change::SubmoduleModification(_) => b'M',
Change::Modification {
executable_bit_changed, ..
} => {
if *executable_bit_changed {
b'X'
} else {
b'M'
}
}
}
}
7 changes: 6 additions & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ pub fn main() -> Result<()> {
})?;

match cmd {
Subcommands::Status(crate::plumbing::options::status::Platform { submodules, pathspec }) => prepare_and_run(
Subcommands::Status(crate::plumbing::options::status::Platform {
statistics,
submodules,
pathspec,
}) => prepare_and_run(
"status",
trace,
auto_verbose,
Expand All @@ -150,6 +154,7 @@ pub fn main() -> Result<()> {
progress,
core::repository::status::Options {
format,
statistics,
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!
submodules: match submodules {
Submodules::All => core::repository::status::Submodules::All,
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 @@ -205,6 +205,9 @@ pub mod status {
/// Define how to display submodule status.
#[clap(long, default_value = "all")]
pub submodules: Submodules,
/// Print additional statistics to help understanding performance.
#[clap(long, short = 's')]
pub statistics: bool,
/// The git path specifications to list attributes for, or unset to read from stdin one per line.
#[clap(value_parser = CheckPathSpec)]
pub pathspec: Vec<BString>,
Expand Down

0 comments on commit 7ba2fa1

Please sign in to comment.