|
1 | 1 | #![deny(clippy::pedantic)] |
2 | 2 |
|
3 | | -use std::collections::HashSet; |
4 | 3 | use std::env; |
5 | 4 | use std::path::PathBuf; |
6 | 5 |
|
7 | 6 | use clap::Parser; |
8 | | -use ignore::{DirEntry, WalkBuilder}; |
| 7 | +use ignore::{DirEntry, Walk, WalkBuilder}; |
9 | 8 | use rayon::prelude::*; |
10 | 9 |
|
11 | 10 | use crate::error::Error; |
@@ -59,29 +58,26 @@ fn repository_foreach<T: Iterator<Item = String>>(args: T) -> Result<(), Error> |
59 | 58 | dbg!(&options); |
60 | 59 | } |
61 | 60 |
|
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)) |
66 | 67 | } |
67 | 68 |
|
68 | 69 | /// Parse the command line options. |
69 | 70 | fn parse_options<T: Iterator<Item = String>>(args: T) -> Result<Options, Error> { |
70 | 71 | Options::try_parse_from(args).map_err(|err| Error::InvalidUsage { source: err }) |
71 | 72 | } |
72 | 73 |
|
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) |
76 | 77 | .hidden(!options.hidden) |
77 | 78 | .ignore(!options.no_ignore) |
78 | 79 | .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() |
85 | 81 | } |
86 | 82 |
|
87 | 83 | /// Run a command in a directory. |
|
0 commit comments