1
1
package transactional
2
2
3
3
import (
4
+ "io"
5
+
6
+ "gopkg.in/src-d/go-git.v4/plumbing/storer"
4
7
"gopkg.in/src-d/go-git.v4/storage"
5
8
)
6
9
@@ -10,7 +13,13 @@ import (
10
13
//
11
14
// The API and functionality of this package are considered EXPERIMENTAL and is
12
15
// 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 {
14
23
s , temporal storage.Storer
15
24
16
25
* ObjectStorage
@@ -20,11 +29,18 @@ type Storage struct {
20
29
* ConfigStorage
21
30
}
22
31
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
+
23
39
// 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
25
41
// 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 {
28
44
s : base ,
29
45
temporal : temporal ,
30
46
@@ -34,10 +50,20 @@ func NewStorage(base, temporal storage.Storer) *Storage {
34
50
ShallowStorage : NewShallowStorage (base , temporal ),
35
51
ConfigStorage : NewConfigStorage (base , temporal ),
36
52
}
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
37
63
}
38
64
39
65
// 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 ) {
41
67
base , err := s .s .Module (name )
42
68
if err != nil {
43
69
return nil , err
@@ -52,7 +78,7 @@ func (s *Storage) Module(name string) (storage.Storer, error) {
52
78
}
53
79
54
80
// 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 {
56
82
for _ , c := range []interface { Commit () error }{
57
83
s .ObjectStorage ,
58
84
s .ReferenceStorage ,
@@ -67,3 +93,8 @@ func (s *Storage) Commit() error {
67
93
68
94
return nil
69
95
}
96
+
97
+ // PackfileWriter honors storage.PackfileWriter.
98
+ func (s * packageWriter ) PackfileWriter () (io.WriteCloser , error ) {
99
+ return s .pw .PackfileWriter ()
100
+ }
0 commit comments