Skip to content

Commit

Permalink
add gix status --format to communicate the current format is very s…
Browse files Browse the repository at this point in the history
…imple.
  • Loading branch information
Byron committed Mar 13, 2024
1 parent 84c74ff commit 23bea36
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
16 changes: 14 additions & 2 deletions gitoxide-core/src/repository/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ pub enum Ignored {
Matching,
}

#[derive(Copy, Clone)]
pub enum Format {
Simplified,
PorcelainV2,
}

pub struct Options {
pub ignored: Option<Ignored>,
pub format: OutputFormat,
pub format: Format,
pub output_format: OutputFormat,
pub submodules: Option<Submodules>,
pub thread_limit: Option<usize>,
pub statistics: bool,
Expand All @@ -42,16 +49,20 @@ pub fn show(
Options {
ignored,
format,
output_format,
submodules,
thread_limit,
allow_write,
statistics,
index_worktree_renames,
}: Options,
) -> anyhow::Result<()> {
if format != OutputFormat::Human {
if output_format != OutputFormat::Human {
bail!("Only human format is supported right now");
}
if !matches!(format, Format::Simplified) {
bail!("Only the simplified format is currently implemented");
}

let start = std::time::Instant::now();
let prefix = repo.prefix()?.unwrap_or(Path::new(""));
Expand Down Expand Up @@ -98,6 +109,7 @@ pub fn show(
None => gix::status::Submodule::AsConfigured { check_dirty: false },
})
.into_index_worktree_iter(pathspecs)?;

for item in iter.by_ref() {
let item = item?;
match item {
Expand Down
11 changes: 10 additions & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub fn main() -> Result<()> {
),
Subcommands::Status(crate::plumbing::options::status::Platform {
ignored,
format: status_format,
statistics,
submodules,
no_write,
Expand All @@ -228,6 +229,14 @@ pub fn main() -> Result<()> {
err,
progress,
core::repository::status::Options {
format: match status_format.unwrap_or_default() {
crate::plumbing::options::status::Format::Simplified => {
core::repository::status::Format::Simplified
}
crate::plumbing::options::status::Format::PorcelainV2 => {
core::repository::status::Format::PorcelainV2
}
},
ignored: ignored.map(|ignored| match ignored.unwrap_or_default() {
crate::plumbing::options::status::Ignored::Matching => {
core::repository::status::Ignored::Matching
Expand All @@ -236,7 +245,7 @@ pub fn main() -> Result<()> {
core::repository::status::Ignored::Collapsed
}
}),
format,
output_format: 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! MacOS also scales if reading a lot of files for refresh index
allow_write: !no_write,
Expand Down
12 changes: 12 additions & 0 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,21 @@ pub mod status {
// allowing to ignore directories, naturally traversing the entire content.
}

#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
pub enum Format {
/// A basic format that is easy to read, and useful for a first glimpse as flat list.
#[default]
Simplified,
/// Output very similar to `git status --porcelain=2`.
PorcelainV2,
}

#[derive(Debug, clap::Parser)]
#[command(about = "compute repository status similar to `git status`")]
pub struct Platform {
/// The way status data is displayed.
#[clap(long, short = 'f')]
pub format: Option<Format>,
/// If enabled, show ignored files and directories.
#[clap(long)]
pub ignored: Option<Option<Ignored>>,
Expand Down

0 comments on commit 23bea36

Please sign in to comment.