diff options
| author | 2026-03-25 14:31:16 +0000 | |
|---|---|---|
| committer | 2026-03-25 14:31:16 +0000 | |
| commit | 48ff647cf4a8bb8f23fcd6b8616f56a8ef72b980 (patch) | |
| tree | ae199c38042adaa544d5f7d31351661d5831381e /ref/store/files/read_list_collect.go | |
| parent | *: objectstore -> object/store (diff) | |
| signature | No signature | |
*: refstore -> ref/store
Diffstat (limited to 'ref/store/files/read_list_collect.go')
| -rw-r--r-- | ref/store/files/read_list_collect.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/ref/store/files/read_list_collect.go b/ref/store/files/read_list_collect.go new file mode 100644 index 00000000..f4e2cb69 --- /dev/null +++ b/ref/store/files/read_list_collect.go @@ -0,0 +1,78 @@ +package files + +import ( + "errors" + "os" + "path" + "strings" +) + +func (store *Store) collectLooseRefNames() ([]string, error) { + names := make([]string, 0, 16) + seen := make(map[string]struct{}, 16) + + _, err := store.gitRoot.Stat("HEAD") + if err == nil { + names = append(names, "HEAD") + seen["HEAD"] = struct{}{} + } else if !errors.Is(err, os.ErrNotExist) { + return nil, err + } + + var walk func(*os.Root, string) error + + walk = func(root *os.Root, dir string) error { + file, openErr := root.Open(dir) + if openErr != nil { + if errors.Is(openErr, os.ErrNotExist) { + return nil + } + + return openErr + } + + defer func() { _ = file.Close() }() + + entries, readErr := file.ReadDir(-1) + if readErr != nil { + return readErr + } + + for _, entry := range entries { + name := path.Join(dir, entry.Name()) + if entry.IsDir() { + err := walk(root, name) + if err != nil { + return err + } + + continue + } + + if strings.HasSuffix(name, ".lock") { + continue + } + + if _, ok := seen[name]; ok { + continue + } + + seen[name] = struct{}{} + names = append(names, name) + } + + return nil + } + + err = walk(store.commonRoot, "refs") + if err != nil { + return nil, err + } + + err = walk(store.gitRoot, "refs") + if err != nil { + return nil, err + } + + return names, nil +} |
