Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find all git repositories #201

Open
Yingrjimsch opened this issue Aug 26, 2024 · 0 comments
Open

Find all git repositories #201

Yingrjimsch opened this issue Aug 26, 2024 · 0 comments

Comments

@Yingrjimsch
Copy link

Hi there I try to get all repositories in my filesystem. Therefore I wrote a WalkDir:

WalkDir::new(root)
        .into_iter()
        .par_bridge() // Convert iterator to a parallel iterator
        .filter_map(|entry| entry.ok())
        .filter(|entry| entry.file_type().is_dir())
        .filter(|entry| {
            let path = entry.path();
            // Check if the directory contains a .git folder
            path.join(".git").is_dir()
        })
        .filter(|entry| {
            let path_str = entry.path().to_string_lossy();
            // Check if the path matches the regex pattern
            regex.is_match(&path_str) ^ reverse
        })
        .map(|entry| entry.into_path())
        .collect()

This works pretty good but it could be faster. My thoughts were, that I could skip_current_dir after the .git folder is found not allowing recursive git folders (which makes sense) but I'm not sure how to achieve that.
Can someone tell me how to do that and if there are other performance optimizations I could try?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant