Skip to content

Commit ab9c87f

Browse files
committed
fix!: fs::walkdir_sorted_new now returns files first.
It's only used by `gix_ref` for reference traversal, which now needs this to be sorted differently to work correctly. As this isn't easily possible in the parallel walk implementation, it's hereby removed.
1 parent 2559851 commit ab9c87f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

gix-features/src/fs.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,21 @@ pub mod walkdir {
338338
///
339339
/// Use `precompose_unicode` to represent the `core.precomposeUnicode` configuration option.
340340
pub fn walkdir_sorted_new(root: &Path, _: Parallelism, precompose_unicode: bool) -> WalkDir {
341+
fn ft_to_number(ft: std::fs::FileType) -> usize {
342+
if ft.is_file() {
343+
1
344+
} else {
345+
2
346+
}
347+
}
341348
WalkDir {
342-
inner: WalkDirImpl::new(root).sort_by_file_name().into(),
349+
inner: WalkDirImpl::new(root)
350+
.sort_by(|a, b| {
351+
ft_to_number(a.file_type())
352+
.cmp(&ft_to_number(b.file_type()))
353+
.then_with(|| a.file_name().cmp(b.file_name()))
354+
})
355+
.into(),
343356
precompose_unicode,
344357
}
345358
}

0 commit comments

Comments
 (0)