From 498dbf7dc92e288641f1af1acc52704150e8a6c0 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sun, 12 Feb 2017 23:03:30 +0100 Subject: storage: git.Storer move to storage.Storer and module handling --- storage/memory/storage.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'storage/memory/storage.go') diff --git a/storage/memory/storage.go b/storage/memory/storage.go index 6cec47b..fa9a4fa 100644 --- a/storage/memory/storage.go +++ b/storage/memory/storage.go @@ -8,6 +8,7 @@ import ( "srcd.works/go-git.v4/plumbing" "srcd.works/go-git.v4/plumbing/format/index" "srcd.works/go-git.v4/plumbing/storer" + "srcd.works/go-git.v4/storage" ) var ErrUnsupportedObjectType = fmt.Errorf("unsupported object type") @@ -22,6 +23,7 @@ type Storage struct { ShallowStorage IndexStorage ReferenceStorage + ModuleStorage } // NewStorage returns a new Storage base on memory @@ -37,6 +39,7 @@ func NewStorage() *Storage { Blobs: make(map[plumbing.Hash]plumbing.EncodedObject, 0), Tags: make(map[plumbing.Hash]plumbing.EncodedObject, 0), }, + ModuleStorage: make(ModuleStorage, 0), } } @@ -227,3 +230,13 @@ func (s *ShallowStorage) SetShallow(commits []plumbing.Hash) error { func (s ShallowStorage) Shallow() ([]plumbing.Hash, error) { return s, nil } + +type ModuleStorage map[string]*Storage + +func (s ModuleStorage) Module(name string) (storage.Storer, error) { + if _, ok := s[name]; !ok { + s[name] = NewStorage() + } + + return s[name], nil +} -- cgit From ed288b30de1ac3dcb3ce675c4b9af89eb4e6fcba Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Tue, 21 Feb 2017 16:03:39 +0100 Subject: documentation and API improvements --- storage/memory/storage.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'storage/memory/storage.go') diff --git a/storage/memory/storage.go b/storage/memory/storage.go index fa9a4fa..92aeec9 100644 --- a/storage/memory/storage.go +++ b/storage/memory/storage.go @@ -220,6 +220,11 @@ func (r ReferenceStorage) IterReferences() (storer.ReferenceIter, error) { return storer.NewReferenceSliceIter(refs), nil } +func (r ReferenceStorage) RemoveReference(n plumbing.ReferenceName) error { + delete(r, n) + return nil +} + type ShallowStorage []plumbing.Hash func (s *ShallowStorage) SetShallow(commits []plumbing.Hash) error { @@ -234,9 +239,12 @@ func (s ShallowStorage) Shallow() ([]plumbing.Hash, error) { type ModuleStorage map[string]*Storage func (s ModuleStorage) Module(name string) (storage.Storer, error) { - if _, ok := s[name]; !ok { - s[name] = NewStorage() + if m, ok := s[name]; ok { + return m, nil } - return s[name], nil + m := NewStorage() + s[name] = m + + return m, nil } -- cgit