git: refresh index stat cache after CLI status

This commit is contained in:
2026-11-07 02:39:08 +00:00
parent 9d11ab381e
commit e1cfaa93bf
4 changed files with 47 additions and 4 deletions
+17 -3
View File
@@ -1,4 +1,4 @@
//! Read-only snapshots and patches. Ordinary Git state only; never refresh/write the index.
//! Snapshots and patches. Only CLI status refreshes the ordinary Git index stat cache.
use crate::Result;
use crate::{
HeadInfo, head_info,
@@ -223,6 +223,13 @@ fn changes(old: &Snapshot, new: &Snapshot) -> Vec<Change> {
.collect()
}
pub fn status(repo: &gix::Repository) -> Result<Status> {
status_inner(repo, false)
}
/// CLI status refreshes cached file stats. RPC status remains read-only.
pub fn refresh_status(repo: &gix::Repository) -> Result<Status> {
status_inner(repo, true)
}
fn status_inner(repo: &gix::Repository, refresh: bool) -> Result<Status> {
repo::worktree(repo)?;
let (index, conflicts) = index(repo)?;
let mut head = tree(repo, "HEAD")?;
@@ -237,13 +244,13 @@ pub fn status(repo: &gix::Repository) -> Result<Status> {
conflicted: conflicts.iter().map(|p| display(p)).collect(),
};
use gix::status::index_worktree::{Item, iter::Summary};
let iter = repo
let mut iter = repo
.status(gix::progress::Discard)
.map_err(|e| error("status", e))?
.untracked_files(gix::status::UntrackedFiles::Files)
.into_index_worktree_iter(Vec::<gix::bstr::BString>::new())
.map_err(|e| error("status", e))?;
for item in iter {
for item in iter.by_ref() {
let item = item.map_err(|e| error("status", e))?;
#[cfg(target_os = "wasi")]
if matches!(
@@ -285,6 +292,13 @@ pub fn status(repo: &gix::Repository) -> Result<Status> {
},
});
}
if refresh
&& let Some(mut outcome) = iter.into_outcome()
&& outcome.has_changes()
{
// A read-only repository must still support status, like native Git.
let _ = outcome.write_changes();
}
result.unstaged.sort_by(|a, b| a.path.cmp(&b.path));
result.untracked.sort();
Ok(result)
+1 -1
View File
@@ -808,7 +808,7 @@ pub fn run(cli: Cli) -> Result<i32> {
porcelain,
branch,
} => {
let mut status = changes::status(&repository)?;
let mut status = changes::refresh_status(&repository)?;
let index = repository
.index_or_empty()
.map_err(|e| error("status index", e))?;