Skip to content

Commit 40295b2

Browse files
committed
feat!: walkdir_sorted_new adds max_depth parameter
max_depth parameter determines the maximum depth the WalkDir will recurse into. Example values: * 0 -> Returns only the root path with no children. * 1 -> Returns the root path, with children. * 2..n -> Returns the root path, children and {n}-grandchildren
1 parent dd5f0a4 commit 40295b2

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

gix-features/src/fs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,14 @@ pub mod walkdir {
207207
/// Instantiate a new directory iterator which will not skip hidden files and is sorted, with the given level of `parallelism`.
208208
///
209209
/// Use `precompose_unicode` to represent the `core.precomposeUnicode` configuration option.
210-
pub fn walkdir_sorted_new(root: &Path, _: Parallelism, precompose_unicode: bool) -> WalkDir {
210+
/// Use `max_depth` to limit the depth of the recursive walk.
211+
/// * 0 -> Returns only the root path with no children
212+
/// * 1 -> Root directory and children.
213+
/// * 2..n -> Root directory, children and {n}-grandchildren
214+
pub fn walkdir_sorted_new(root: &Path, _: Parallelism, max_depth: usize, precompose_unicode: bool) -> WalkDir {
211215
WalkDir {
212216
inner: WalkDirImpl::new(root)
217+
.max_depth(max_depth)
213218
.sort_by(|a, b| {
214219
let storage_a;
215220
let storage_b;

gix-ref/src/store/file/loose/iter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl SortedLoosePaths {
2424
gix_features::fs::walkdir_sorted_new(
2525
path,
2626
gix_features::fs::walkdir::Parallelism::Serial,
27+
usize::MAX,
2728
precompose_unicode,
2829
)
2930
.into_iter()

gix-submodule/tests/file/baseline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn common_values_and_names_by_path() -> crate::Result {
6161

6262
fn module_files() -> impl Iterator<Item = (PathBuf, PathBuf)> {
6363
let dir = gix_testtools::scripted_fixture_read_only("basic.sh").expect("valid fixture");
64-
gix_features::fs::walkdir_sorted_new(&dir, Parallelism::Serial, false)
64+
gix_features::fs::walkdir_sorted_new(&dir, Parallelism::Serial, usize::MAX, false)
6565
.follow_links(false)
6666
.into_iter()
6767
.filter_map(move |entry| {

0 commit comments

Comments
 (0)