Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fmt/src/document/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn default_mapping() -> Vec<Mapping> {
toml::from_str(defaults).expect("default mapping must be valid");

mapping
.into_iter()
.flat_map(|(_, doctype)| {
.into_values()
.flat_map(|doctype| {
let mut ms = vec![];
if doctype.extension {
ms.push(Mapping::Extension {
Expand Down
25 changes: 20 additions & 5 deletions fmt/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub fn resolve_file_attrs(
process_changes(changes, time, &author);

// process dirty working tree
let index = repo.index_or_empty().or_raise(make_error)?;
let status_platform = repo.status(gix::progress::Discard).or_raise(make_error)?;
let status_iter = status_platform.into_iter(None).or_raise(make_error)?;
let now = gix::date::Time::now_local_or_utc();
Expand Down Expand Up @@ -241,14 +242,28 @@ pub fn resolve_file_attrs(

if file_type.is_dir() {
if platform.is_excluded() {
log::debug!(path:?, rela_path:?; "skip git ignored directory");
it.skip_current_dir();
continue;
let rela =
gix::path::try_into_bstr(rela_path).or_raise(|| {
Error::new("cannot convert path to git path")
})?;

if !index.path_is_directory(rela.as_ref()) {
log::debug!(path:?, rela_path:?; "skip git ignored directory");
it.skip_current_dir();
continue;
}
}
} else if file_type.is_file() {
if platform.is_excluded() {
log::debug!(path:?, rela_path:?; "skip git ignored file");
continue;
let rela =
gix::path::try_into_bstr(rela_path).or_raise(|| {
Error::new("cannot convert path to git path")
})?;

if index.entry_by_path(rela.as_ref()).is_none() {
log::debug!(path:?, rela_path:?; "skip git ignored file");
continue;
}
Comment on lines 243 to +266

Copilot AI Apr 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion gix::path::try_into_bstr(rela_path) (and its error handling) is repeated for both directories and files. Consider factoring this into a small helper/closure or converting once inside the platform.is_excluded() block to reduce duplication and keep the ignore/index logic consistent across branches.

Copilot uses AI. Check for mistakes.
}
update_attrs(rela_path, now, current_username.as_str());
}
Expand Down
23 changes: 18 additions & 5 deletions fmt/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ fn select_files_with_git(
let mut excludes = worktree
.excludes(None)
.or_raise(|| Error::new("cannot create gix exclude stack"))?;
let index = repo
.index_or_empty()
.or_raise(|| Error::new("cannot open gix index"))?;

while let Some(entry) = it.next() {
let entry = entry.or_raise(|| Error::new("cannot traverse directory"))?;
Expand All @@ -232,9 +235,14 @@ fn select_files_with_git(

if file_type.is_dir() {
if platform.is_excluded() {
log::debug!(path:?, rela_path:?; "skip git ignored directory");
it.skip_current_dir();
continue;
let rela = gix::path::try_into_bstr(rela_path)
.or_raise(|| Error::new("cannot convert path to git path"))?;

if !index.path_is_directory(rela.as_ref()) {
log::debug!(path:?, rela_path:?; "skip git ignored directory");
it.skip_current_dir();
continue;
}
}
if matcher.matched(rela_path, file_type.is_dir()).is_ignore() {
log::debug!(path:?, rela_path:?; "skip glob ignored directory");
Expand All @@ -243,8 +251,13 @@ fn select_files_with_git(
}
} else if file_type.is_file() {
if platform.is_excluded() {
log::debug!(path:?, rela_path:?; "skip git ignored file");
continue;
let rela = gix::path::try_into_bstr(rela_path)
.or_raise(|| Error::new("cannot convert path to git path"))?;

if index.entry_by_path(rela.as_ref()).is_none() {
log::debug!(path:?, rela_path:?; "skip git ignored file");
continue;
}
Comment on lines 237 to +260

Copilot AI Apr 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gix::path::try_into_bstr(rela_path) conversion and the associated error message are duplicated in both the dir and file branches. Consider converting once (e.g., inside the platform.is_excluded() block) and reusing the result to reduce repetition and avoid doing the same conversion logic in two places.

Copilot uses AI. Check for mistakes.
}
if !matcher
.matched(rela_path, file_type.is_dir())
Expand Down
Loading