Skip to content

Commit 6b9166a

Browse files
committed
feat: process directories as they are found
1 parent 967d49a commit 6b9166a

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7-
- Nothing yet!
7+
### Added
8+
9+
- Process directories as they are found, instead of waiting for the search to complete.
810

911
## Version 0.3.0 - 2024-06-05
1012

src/main.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#![deny(clippy::pedantic)]
22

3-
use std::collections::HashSet;
43
use std::env;
54
use std::path::PathBuf;
65

76
use clap::Parser;
8-
use ignore::{DirEntry, WalkBuilder};
7+
use ignore::{DirEntry, Walk, WalkBuilder};
98
use rayon::prelude::*;
109

1110
use crate::error::Error;
@@ -59,29 +58,26 @@ fn repository_foreach<T: Iterator<Item = String>>(args: T) -> Result<(), Error>
5958
dbg!(&options);
6059
}
6160

62-
find_repositories(&options)
63-
.par_iter()
64-
.map(|repository| run_command_in_directory(&options, repository))
65-
.collect()
61+
walk_from_options(&options)
62+
.flatten()
63+
.par_bridge()
64+
.map(DirEntry::into_path)
65+
.filter(|path| path.is_dir() && path.join(".git").exists())
66+
.try_for_each(|repository| run_command_in_directory(&options, &repository))
6667
}
6768

6869
/// Parse the command line options.
6970
fn parse_options<T: Iterator<Item = String>>(args: T) -> Result<Options, Error> {
7071
Options::try_parse_from(args).map_err(|err| Error::InvalidUsage { source: err })
7172
}
7273

73-
/// Find all git repositories in a directory and its subdirectories.
74-
fn find_repositories(options: &Options) -> HashSet<PathBuf> {
75-
let walk = WalkBuilder::new(&options.directory)
74+
/// Initialize the directory walker from the options.
75+
fn walk_from_options(options: &Options) -> Walk {
76+
WalkBuilder::new(&options.directory)
7677
.hidden(!options.hidden)
7778
.ignore(!options.no_ignore)
7879
.git_ignore(!options.no_ignore)
79-
.build();
80-
81-
walk.flatten()
82-
.map(DirEntry::into_path)
83-
.filter(|path| path.is_dir() && path.join(".git").exists())
84-
.collect()
80+
.build()
8581
}
8682

8783
/// Run a command in a directory.

0 commit comments

Comments
 (0)