11package transactional
22
33import (
4+ "io"
5+
6+ "gopkg.in/src-d/go-git.v4/plumbing/storer"
47 "gopkg.in/src-d/go-git.v4/storage"
58)
69
@@ -10,7 +13,13 @@ import (
1013//
1114// The API and functionality of this package are considered EXPERIMENTAL and is
1215// not considered stable nor production ready.
13- type Storage struct {
16+ type Storage interface {
17+ storage.Storer
18+ Commit () error
19+ }
20+
21+ // basic implements the Storage interface.
22+ type basic struct {
1423 s , temporal storage.Storer
1524
1625 * ObjectStorage
@@ -20,11 +29,18 @@ type Storage struct {
2029 * ConfigStorage
2130}
2231
32+ // packageWriter implements storer.PackfileWriter interface over
33+ // a Storage with a temporal storer that supports it.
34+ type packageWriter struct {
35+ * basic
36+ pw storer.PackfileWriter
37+ }
38+
2339// NewStorage returns a new Storage based on two repositories, base is the base
24- // repository where the read operations are read and temportal is were all
40+ // repository where the read operations are read and temporal is were all
2541// the write operations are stored.
26- func NewStorage (base , temporal storage.Storer ) * Storage {
27- return & Storage {
42+ func NewStorage (base , temporal storage.Storer ) Storage {
43+ st := & basic {
2844 s : base ,
2945 temporal : temporal ,
3046
@@ -34,10 +50,20 @@ func NewStorage(base, temporal storage.Storer) *Storage {
3450 ShallowStorage : NewShallowStorage (base , temporal ),
3551 ConfigStorage : NewConfigStorage (base , temporal ),
3652 }
53+
54+ pw , ok := temporal .(storer.PackfileWriter )
55+ if ok {
56+ return & packageWriter {
57+ basic : st ,
58+ pw : pw ,
59+ }
60+ }
61+
62+ return st
3763}
3864
3965// Module it honors the storage.ModuleStorer interface.
40- func (s * Storage ) Module (name string ) (storage.Storer , error ) {
66+ func (s * basic ) Module (name string ) (storage.Storer , error ) {
4167 base , err := s .s .Module (name )
4268 if err != nil {
4369 return nil , err
@@ -52,7 +78,7 @@ func (s *Storage) Module(name string) (storage.Storer, error) {
5278}
5379
5480// Commit it copies the content of the temporal storage into the base storage.
55- func (s * Storage ) Commit () error {
81+ func (s * basic ) Commit () error {
5682 for _ , c := range []interface { Commit () error }{
5783 s .ObjectStorage ,
5884 s .ReferenceStorage ,
@@ -67,3 +93,8 @@ func (s *Storage) Commit() error {
6793
6894 return nil
6995}
96+
97+ // PackfileWriter honors storage.PackfileWriter.
98+ func (s * packageWriter ) PackfileWriter () (io.WriteCloser , error ) {
99+ return s .pw .PackfileWriter ()
100+ }
0 commit comments