Skip to content

Commit ba307f5

Browse files
committed
feat: gix status auto-writes changed indices.
This prevents expensive operations to re-occour.
1 parent cb73fc6 commit ba307f5

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

gitoxide-core/src/repository/status.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Options {
2121
pub submodules: Submodules,
2222
pub thread_limit: Option<usize>,
2323
pub statistics: bool,
24+
pub allow_write: bool,
2425
}
2526

2627
pub fn show(
@@ -34,6 +35,7 @@ pub fn show(
3435
// TODO: implement this
3536
submodules: _,
3637
thread_limit,
38+
allow_write,
3739
statistics,
3840
}: Options,
3941
) -> anyhow::Result<()> {
@@ -88,6 +90,13 @@ pub fn show(
8890
options,
8991
)?;
9092

93+
if outcome.entries_updated != 0 && allow_write {
94+
index.write(gix::index::write::Options {
95+
extensions: Default::default(),
96+
skip_hash: false, // TODO: make this based on configuration
97+
})?;
98+
}
99+
91100
if statistics {
92101
writeln!(err, "{outcome:#?}").ok();
93102
}

src/plumbing/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub fn main() -> Result<()> {
136136
Subcommands::Status(crate::plumbing::options::status::Platform {
137137
statistics,
138138
submodules,
139+
no_write,
139140
pathspec,
140141
}) => prepare_and_run(
141142
"status",
@@ -156,6 +157,7 @@ pub fn main() -> Result<()> {
156157
format,
157158
statistics,
158159
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!
160+
allow_write: !no_write,
159161
submodules: match submodules {
160162
Submodules::All => core::repository::status::Submodules::All,
161163
Submodules::RefChange => core::repository::status::Submodules::RefChange,

src/plumbing/options/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ pub mod status {
208208
/// Print additional statistics to help understanding performance.
209209
#[clap(long, short = 's')]
210210
pub statistics: bool,
211+
/// Don't write back a changed index, which forces this operation to always be idempotent.
212+
#[clap(long)]
213+
pub no_write: bool,
211214
/// The git path specifications to list attributes for, or unset to read from stdin one per line.
212215
#[clap(value_parser = CheckPathSpec)]
213216
pub pathspec: Vec<BString>,

0 commit comments

Comments
 (0)