Using rayon for discovering repos via dir walking
parent
b1a5df8659
commit
54d36fafcb
38
src/lib.rs
38
src/lib.rs
|
@ -3,7 +3,7 @@
|
|||
use std::{
|
||||
cmp::Reverse,
|
||||
collections::HashSet,
|
||||
path::{self, Path, PathBuf},
|
||||
path::{self, PathBuf},
|
||||
sync::OnceLock,
|
||||
};
|
||||
|
||||
|
@ -504,34 +504,44 @@ pub fn get_commits(
|
|||
// .sorted_by_cached_key(|a| Reverse(a.time))
|
||||
// .collect_vec();
|
||||
|
||||
Ok((0, 0, commits))
|
||||
// Ok((repos_count, branches_count, commits))
|
||||
Ok((repos_count, branches_count, commits))
|
||||
}
|
||||
|
||||
fn find_git_repos(scan_path: &path::Path, repos: &mut Vec<PathBuf>, ignored_repos: &Vec<String>) {
|
||||
if let Some(path) = walk_dir(scan_path, ignored_repos) {
|
||||
repos.extend(path)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_dir(scan_path: &path::Path, ignored_repos: &Vec<String>) -> Option<Vec<PathBuf>> {
|
||||
let Ok(dirs) = scan_path.read_dir()
|
||||
else {
|
||||
return;
|
||||
return None;
|
||||
};
|
||||
|
||||
let dirs: Vec<_> = dirs
|
||||
let dirs: Vec<PathBuf> = dirs
|
||||
.par_bridge()
|
||||
.filter_map(|d| d.ok())
|
||||
.filter(|d| {
|
||||
let dir_name = d.file_name().to_string_lossy().to_string();
|
||||
!ignored_repos.contains(&dir_name)
|
||||
})
|
||||
.filter(|d| d.file_type().is_ok_and(|t| t.is_dir()))
|
||||
.collect_vec();
|
||||
.filter_map(|d| {
|
||||
let dir = d.path();
|
||||
let filename = dir.file_name().unwrap_or_default().to_string_lossy();
|
||||
|
||||
let dirs = dirs.iter().map(|d| d.path());
|
||||
match filename.as_ref() {
|
||||
".git" => Some(vec![dir]),
|
||||
_ => walk_dir(&dir, ignored_repos),
|
||||
}
|
||||
})
|
||||
.reduce(Vec::new, |mut c, n| {
|
||||
c.extend(n);
|
||||
c
|
||||
});
|
||||
|
||||
for dir in dirs {
|
||||
let filename = dir.file_name().unwrap_or_default().to_string_lossy();
|
||||
match filename.as_ref() {
|
||||
".git" => repos.push(dir),
|
||||
_ => find_git_repos(&dir, repos, ignored_repos),
|
||||
}
|
||||
}
|
||||
Some(dirs)
|
||||
}
|
||||
|
||||
pub fn get_default_until(since: NaiveDate) -> String {
|
||||
|
|
Loading…
Reference in New Issue