Using rayon for discovering repos via dir walking

master^2
Wynd 2025-01-18 21:13:26 +02:00
parent b1a5df8659
commit 54d36fafcb
1 changed files with 24 additions and 14 deletions

View File

@ -3,7 +3,7 @@
use std::{ use std::{
cmp::Reverse, cmp::Reverse,
collections::HashSet, collections::HashSet,
path::{self, Path, PathBuf}, path::{self, PathBuf},
sync::OnceLock, sync::OnceLock,
}; };
@ -504,34 +504,44 @@ pub fn get_commits(
// .sorted_by_cached_key(|a| Reverse(a.time)) // .sorted_by_cached_key(|a| Reverse(a.time))
// .collect_vec(); // .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>) { 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() let Ok(dirs) = scan_path.read_dir()
else { else {
return; return None;
}; };
let dirs: Vec<_> = dirs let dirs: Vec<PathBuf> = dirs
.par_bridge()
.filter_map(|d| d.ok()) .filter_map(|d| d.ok())
.filter(|d| { .filter(|d| {
let dir_name = d.file_name().to_string_lossy().to_string(); let dir_name = d.file_name().to_string_lossy().to_string();
!ignored_repos.contains(&dir_name) !ignored_repos.contains(&dir_name)
}) })
.filter(|d| d.file_type().is_ok_and(|t| t.is_dir())) .filter(|d| d.file_type().is_ok_and(|t| t.is_dir()))
.collect_vec(); .filter_map(|d| {
let dir = d.path();
let dirs = dirs.iter().map(|d| d.path());
for dir in dirs {
let filename = dir.file_name().unwrap_or_default().to_string_lossy(); let filename = dir.file_name().unwrap_or_default().to_string_lossy();
match filename.as_ref() { match filename.as_ref() {
".git" => repos.push(dir), ".git" => Some(vec![dir]),
_ => find_git_repos(&dir, repos, ignored_repos), _ => walk_dir(&dir, ignored_repos),
}
} }
})
.reduce(Vec::new, |mut c, n| {
c.extend(n);
c
});
Some(dirs)
} }
pub fn get_default_until(since: NaiveDate) -> String { pub fn get_default_until(since: NaiveDate) -> String {