aboutsummaryrefslogtreecommitdiffstats
path: root/storage/transactional/index.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2019-02-02 10:14:24 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2019-02-02 10:14:24 +0100
commit96317743391ac87aeb07d292469e212671628437 (patch)
tree990bbe4a11241f2ac3a5f4a71d514884b9c2b962 /storage/transactional/index.go
parent12dc3ef13e5c783b9e304aa8b6a2f7097880ab87 (diff)
downloadgo-git-96317743391ac87aeb07d292469e212671628437.tar.gz
storage: transactional, package documentation
Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
Diffstat (limited to 'storage/transactional/index.go')
-rw-r--r--storage/transactional/index.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/storage/transactional/index.go b/storage/transactional/index.go
index 26042d6..84e0e2f 100644
--- a/storage/transactional/index.go
+++ b/storage/transactional/index.go
@@ -5,6 +5,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/storer"
)
+// IndexStorage implements the storer.IndexStorage for the transactional package.
type IndexStorage struct {
storer.IndexStorer
temporal storer.IndexStorer
@@ -12,6 +13,8 @@ type IndexStorage struct {
set bool
}
+// NewIndexStorage returns a new IndexStorer based on a base storer and a
+// temporal storer.
func NewIndexStorage(s, temporal storer.IndexStorer) *IndexStorage {
return &IndexStorage{
IndexStorer: s,
@@ -19,6 +22,7 @@ func NewIndexStorage(s, temporal storer.IndexStorer) *IndexStorage {
}
}
+// SetIndex honors the storer.IndexStorer interface.
func (s *IndexStorage) SetIndex(idx *index.Index) (err error) {
if err := s.temporal.SetIndex(idx); err != nil {
return err
@@ -28,6 +32,7 @@ func (s *IndexStorage) SetIndex(idx *index.Index) (err error) {
return nil
}
+// Index honors the storer.IndexStorer interface.
func (s *IndexStorage) Index() (*index.Index, error) {
if !s.set {
return s.IndexStorer.Index()
@@ -36,15 +41,16 @@ func (s *IndexStorage) Index() (*index.Index, error) {
return s.temporal.Index()
}
-func (c *IndexStorage) Commit() error {
- if !c.set {
+// Commit it copies the index from the temporal storage into the base storage.
+func (s *IndexStorage) Commit() error {
+ if !s.set {
return nil
}
- idx, err := c.temporal.Index()
+ idx, err := s.temporal.Index()
if err != nil {
return err
}
- return c.IndexStorer.SetIndex(idx)
+ return s.IndexStorer.SetIndex(idx)
}