Skip to content

Commit

Permalink
feat: add gix status --ignored support
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 12, 2024
1 parent 66e87cd commit 84c74ff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gitoxide-core/src/repository/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ pub enum Submodules {
None,
}

#[derive(Copy, Clone)]
pub enum Ignored {
Collapsed,
Matching,
}

pub struct Options {
pub ignored: Option<Ignored>,
pub format: OutputFormat,
pub submodules: Option<Submodules>,
pub thread_limit: Option<usize>,
Expand All @@ -33,6 +40,7 @@ pub fn show(
mut err: impl std::io::Write,
mut progress: impl gix::NestedProgress + 'static,
Options {
ignored,
format,
submodules,
thread_limit,
Expand All @@ -52,6 +60,12 @@ pub fn show(
.status(index_progress)?
.should_interrupt_shared(&gix::interrupt::IS_INTERRUPTED)
.index_worktree_options_mut(|opts| {
if let Some((opts, ignored)) = opts.dirwalk_options.as_mut().zip(ignored) {
opts.set_emit_ignored(Some(match ignored {
Ignored::Collapsed => gix::dir::walk::EmissionMode::CollapseDirectory,
Ignored::Matching => gix::dir::walk::EmissionMode::Matching,
}));
}
opts.rewrites = index_worktree_renames.map(|percentage| gix::diff::Rewrites {
copies: None,
percentage: Some(percentage),
Expand All @@ -60,6 +74,9 @@ pub fn show(
if opts.rewrites.is_some() {
if let Some(opts) = opts.dirwalk_options.as_mut() {
opts.set_emit_untracked(gix::dir::walk::EmissionMode::Matching);
if ignored.is_some() {
opts.set_emit_ignored(Some(gix::dir::walk::EmissionMode::Matching));
}
}
}
opts.thread_limit = thread_limit;
Expand Down
9 changes: 9 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ pub fn main() -> Result<()> {
},
),
Subcommands::Status(crate::plumbing::options::status::Platform {
ignored,
statistics,
submodules,
no_write,
Expand All @@ -227,6 +228,14 @@ pub fn main() -> Result<()> {
err,
progress,
core::repository::status::Options {
ignored: ignored.map(|ignored| match ignored.unwrap_or_default() {
crate::plumbing::options::status::Ignored::Matching => {
core::repository::status::Ignored::Matching
}
crate::plumbing::options::status::Ignored::Collapsed => {
core::repository::status::Ignored::Collapsed
}
}),
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
Expand Down
17 changes: 17 additions & 0 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,26 @@ pub mod status {
None,
}

#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
pub enum Ignored {
/// display all ignored files and directories, but collapse them if possible to simplify.
#[default]
Collapsed,
/// Show exact matches. Note that this may show directories if these are a match as well.
///
/// Simplification will not happen in this mode.
Matching,
// TODO: figure out how to implement traditional, which right now can't be done as it requires ignored folders
// to be fully expanded. This should probably be implemented in `gix_dir` which then simply works by not
// allowing to ignore directories, naturally traversing the entire content.
}

#[derive(Debug, clap::Parser)]
#[command(about = "compute repository status similar to `git status`")]
pub struct Platform {
/// If enabled, show ignored files and directories.
#[clap(long)]
pub ignored: Option<Option<Ignored>>,
/// Define how to display the submodule status. Defaults to git configuration if unset.
#[clap(long)]
pub submodules: Option<Submodules>,
Expand Down

0 comments on commit 84c74ff

Please sign in to comment.