8000 Find all git repositories · Issue #201 · BurntSushi/walkdir · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Find all git repositories #201
Open
Open
@Yingrjimsch

Description

@Yingrjimsch

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0