From e26603f7e640659333821ba028138e769bf993dd Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Sat, 30 Dec 2023 11:48:20 +0100 Subject: [PATCH] fix: Make repo discovery quicker --- internal/pkg/repo/discover.go | 49 ++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/internal/pkg/repo/discover.go b/internal/pkg/repo/discover.go index 132e0a9..917e3f8 100644 --- a/internal/pkg/repo/discover.go +++ b/internal/pkg/repo/discover.go @@ -7,28 +7,29 @@ import ( ) func GetRepoPaths(baseDir string) ([]string, error) { - result := []string{} - if err := filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error { - if err != nil { - return fmt.Errorf("failed to walk path %s: %w", path, err) - } - if !info.IsDir() { - return nil - } - relPath, err := filepath.Rel(baseDir, path) - if err != nil { - return fmt.Errorf("failed to get relative path for %s: %w", path, err) - } - if info.Name() != ".git" { - return nil - } - - result = append(result, filepath.Dir(relPath)) - - return err - }); err != nil { - return nil, err - } - - return result, nil + result := []string{} + + entries, err := os.ReadDir(baseDir) + if err != nil { + return result, err + } + + for _, entry := range entries { + if !entry.IsDir() { + continue + } + + if entry.Name() == ".git" { + return []string{baseDir}, nil + } + + paths, err := GetRepoPaths(fmt.Sprintf("%s/%s", baseDir, entry.Name())) + if err != nil { + return result, err + } + + result = append(result, paths...) + } + + return result, nil }