aboutsummaryrefslogtreecommitdiffstats
path: root/storage/transactional/storage.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-12-10 20:18:50 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2018-12-10 20:18:50 +0100
commit12dc3ef13e5c783b9e304aa8b6a2f7097880ab87 (patch)
tree9425626a16f47f73fc7dd2128d1ea51b5d1be5a3 /storage/transactional/storage.go
parenta2b39f540e5b07cf361b530e19de30707b8ca0d7 (diff)
downloadgo-git-12dc3ef13e5c783b9e304aa8b6a2f7097880ab87.tar.gz
storage: transactional, new storage with transactional capabilities
Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
Diffstat (limited to 'storage/transactional/storage.go')
-rw-r--r--storage/transactional/storage.go60
1 files changed, 60 insertions, 0 deletions
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
+}