aboutsummaryrefslogtreecommitdiff
path: root/refstore/chain/list.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-04 12:52:53 +0800
committerGravatar Runxi Yu2026-03-04 12:52:53 +0800
commit845cd640384ed25ce3c18ade9aae37de2ed4c5e0 (patch)
treeac65ff92343c33c23af380b56f94ea1d5a4c4849 /refstore/chain/list.go
parentrefstore/packed: Split (diff)
signatureNo signature
refstore/chain: Split
Diffstat (limited to 'refstore/chain/list.go')
-rw-r--r--refstore/chain/list.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/refstore/chain/list.go b/refstore/chain/list.go
new file mode 100644
index 00000000..e1594e95
--- /dev/null
+++ b/refstore/chain/list.go
@@ -0,0 +1,44 @@
+package chain
+
+import (
+ "fmt"
+
+ "codeberg.org/lindenii/furgit/ref"
+)
+
+// List lists references from every backend and deduplicates by ref name.
+//
+// First-seen wins, so earlier backends have precedence.
+func (chain *Chain) List(pattern string) ([]ref.Ref, error) {
+ var refs []ref.Ref
+
+ seen := map[string]struct{}{}
+
+ for i, backend := range chain.backends {
+ if backend == nil {
+ continue
+ }
+
+ listed, err := backend.List(pattern)
+ if err != nil {
+ return nil, fmt.Errorf("refstore: backend %d list: %w", i, err)
+ }
+
+ for _, entry := range listed {
+ if entry == nil {
+ continue
+ }
+
+ name := entry.Name()
+ if _, ok := seen[name]; ok {
+ continue
+ }
+
+ seen[name] = struct{}{}
+
+ refs = append(refs, entry)
+ }
+ }
+
+ return refs, nil
+}