From 12dc3ef13e5c783b9e304aa8b6a2f7097880ab87 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 10 Dec 2018 20:18:50 +0100 Subject: storage: transactional, new storage with transactional capabilities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Máximo Cuadros --- storage/transactional/storage.go | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'storage/transactional/storage.go') diff --git a/storage/transactional/storage.go b/storage/transactional/storage.go index d5f5a24..6611a43 100644 --- a/storage/transactional/storage.go +++ b/storage/transactional/storage.go @@ -1 +1,61 @@ package transactional + +import ( + "gopkg.in/src-d/go-git.v4/storage" +) + +// Storage is an implementation of git.Storer that stores data on disk in the +// standard git format (this is, the .git directory). Zero values of this type +// are not safe to use, see the NewStorage function below. +type Storage struct { + s, temporal storage.Storer + + *ObjectStorage + *ReferenceStorage + *IndexStorage + *ShallowStorage + *ConfigStorage +} + +func NewStorage(s, temporal storage.Storer) *Storage { + return &Storage{ + s: s, + temporal: temporal, + + ObjectStorage: NewObjectStorage(s, temporal), + ReferenceStorage: NewReferenceStorage(s, temporal), + IndexStorage: NewIndexStorage(s, temporal), + ShallowStorage: NewShallowStorage(s, temporal), + ConfigStorage: NewConfigStorage(s, temporal), + } +} + +func (s *Storage) Module(name string) (storage.Storer, error) { + base, err := s.s.Module(name) + if err != nil { + return nil, err + } + + temporal, err := s.temporal.Module(name) + if err != nil { + return nil, err + } + + return NewStorage(base, temporal), nil +} + +func (s *Storage) Commit() error { + for _, c := range []interface{ Commit() error }{ + s.ObjectStorage, + s.ReferenceStorage, + s.IndexStorage, + s.ShallowStorage, + s.ConfigStorage, + } { + if err := c.Commit(); err != nil { + return err + } + } + + return nil +} -- cgit