aboutsummaryrefslogtreecommitdiffstats
path: root/storage/transactional/index.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/index.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/index.go')
-rw-r--r--storage/transactional/index.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/storage/transactional/index.go b/storage/transactional/index.go
new file mode 100644
index 0000000..26042d6
--- /dev/null
+++ b/storage/transactional/index.go
@@ -0,0 +1,50 @@
+package transactional
+
+import (
+ "gopkg.in/src-d/go-git.v4/plumbing/format/index"
+ "gopkg.in/src-d/go-git.v4/plumbing/storer"
+)
+
+type IndexStorage struct {
+ storer.IndexStorer
+ temporal storer.IndexStorer
+
+ set bool
+}
+
+func NewIndexStorage(s, temporal storer.IndexStorer) *IndexStorage {
+ return &IndexStorage{
+ IndexStorer: s,
+ temporal: temporal,
+ }
+}
+
+func (s *IndexStorage) SetIndex(idx *index.Index) (err error) {
+ if err := s.temporal.SetIndex(idx); err != nil {
+ return err
+ }
+
+ s.set = true
+ return nil
+}
+
+func (s *IndexStorage) Index() (*index.Index, error) {
+ if !s.set {
+ return s.IndexStorer.Index()
+ }
+
+ return s.temporal.Index()
+}
+
+func (c *IndexStorage) Commit() error {
+ if !c.set {
+ return nil
+ }
+
+ idx, err := c.temporal.Index()
+ if err != nil {
+ return err
+ }
+
+ return c.IndexStorer.SetIndex(idx)
+}