aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/reference.go
diff options
context:
space:
mode:
Diffstat (limited to 'storage/filesystem/reference.go')
-rw-r--r--storage/filesystem/reference.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/storage/filesystem/reference.go b/storage/filesystem/reference.go
new file mode 100644
index 0000000..c8e5434
--- /dev/null
+++ b/storage/filesystem/reference.go
@@ -0,0 +1,61 @@
+package filesystem
+
+import (
+ "fmt"
+
+ "gopkg.in/src-d/go-git.v4/core"
+ "gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
+)
+
+type ReferenceStorage struct {
+ dir *dotgit.DotGit
+ refs map[core.ReferenceName]*core.Reference
+}
+
+func (r *ReferenceStorage) Set(ref *core.Reference) error {
+ return fmt.Errorf("not implemented yet")
+}
+
+func (r *ReferenceStorage) Get(n core.ReferenceName) (*core.Reference, error) {
+ if err := r.load(); err != nil {
+ return nil, err
+ }
+
+ ref, ok := r.refs[n]
+ if !ok {
+ return nil, core.ErrReferenceNotFound
+ }
+
+ return ref, nil
+}
+
+func (r *ReferenceStorage) Iter() (core.ReferenceIter, error) {
+ if err := r.load(); err != nil {
+ return nil, err
+ }
+
+ var refs []*core.Reference
+ for _, ref := range r.refs {
+ refs = append(refs, ref)
+ }
+
+ return core.NewReferenceSliceIter(refs), nil
+}
+
+func (r *ReferenceStorage) load() error {
+ if len(r.refs) != 0 {
+ return nil
+ }
+
+ refs, err := r.dir.Refs()
+ if err != nil {
+ return err
+ }
+
+ r.refs = make(map[core.ReferenceName]*core.Reference, 0)
+ for _, ref := range refs {
+ r.refs[ref.Name()] = ref
+ }
+
+ return nil
+}