Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 9631774

Browse files
committed
storage: transactional, package documentation
Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
1 parent 12dc3ef commit 9631774

File tree

8 files changed

+75
-21
lines changed

8 files changed

+75
-21
lines changed

storage/transactional/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ package transactional
22

33
import "gopkg.in/src-d/go-git.v4/config"
44

5+
// ConfigStorage implements the storer.ConfigStorage for the transactional package.
56
type ConfigStorage struct {
67
config.ConfigStorer
78
temporal config.ConfigStorer
89

910
set bool
1011
}
1112

13+
// NewConfigStorage returns a new ConfigStorer based on a base storer and a
14+
// temporal storer.
1215
func NewConfigStorage(s, temporal config.ConfigStorer) *ConfigStorage {
1316
return &ConfigStorage{ConfigStorer: s, temporal: temporal}
1417
}
1518

19+
// SetConfig honors the storer.ConfigStorer interface.
1620
func (c *ConfigStorage) SetConfig(cfg *config.Config) error {
1721
if err := c.temporal.SetConfig(cfg); err != nil {
1822
return err
@@ -22,6 +26,7 @@ func (c *ConfigStorage) SetConfig(cfg *config.Config) error {
2226
return nil
2327
}
2428

29+
// Config honors the storer.ConfigStorer interface.
2530
func (c *ConfigStorage) Config() (*config.Config, error) {
2631
if !c.set {
2732
return c.ConfigStorer.Config()
@@ -30,6 +35,7 @@ func (c *ConfigStorage) Config() (*config.Config, error) {
3035
return c.temporal.Config()
3136
}
3237

38+
// Commit it copies the config from the temporal storage into the base storage.
3339
func (c *ConfigStorage) Commit() error {
3440
if !c.set {
3541
return nil

storage/transactional/doc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Package transactional is a transactional implementation of git.Storer, it
2+
// demux the write and read operation of two separate storers, allowing to merge
3+
// content calling Storage.Commit.
4+
//
5+
// The API and functionality of this package are considered EXPERIMENTAL and is
6+
// not considered stable nor production ready.
7+
package transactional

storage/transactional/index.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@ import (
55
"gopkg.in/src-d/go-git.v4/plumbing/storer"
66
)
77

8+
// IndexStorage implements the storer.IndexStorage for the transactional package.
89
type IndexStorage struct {
910
storer.IndexStorer
1011
temporal storer.IndexStorer
1112

1213
set bool
1314
}
1415

16+
// NewIndexStorage returns a new IndexStorer based on a base storer and a
17+
// temporal storer.
1518
func NewIndexStorage(s, temporal storer.IndexStorer) *IndexStorage {
1619
return &IndexStorage{
1720
IndexStorer: s,
1821
temporal: temporal,
1922
}
2023
}
2124

25+
// SetIndex honors the storer.IndexStorer interface.
2226
func (s *IndexStorage) SetIndex(idx *index.Index) (err error) {
2327
if err := s.temporal.SetIndex(idx); err != nil {
2428
return err
@@ -28,6 +32,7 @@ func (s *IndexStorage) SetIndex(idx *index.Index) (err error) {
2832
return nil
2933
}
3034

35+
// Index honors the storer.IndexStorer interface.
3136
func (s *IndexStorage) Index() (*index.Index, error) {
3237
if !s.set {
3338
return s.IndexStorer.Index()
@@ -36,15 +41,16 @@ func (s *IndexStorage) Index() (*index.Index, error) {
3641
return s.temporal.Index()
3742
}
3843

39-
func (c *IndexStorage) Commit() error {
40-
if !c.set {
44+
// Commit it copies the index from the temporal storage into the base storage.
45+
func (s *IndexStorage) Commit() error {
46+
if !s.set {
4147
return nil
4248
}
4349

44-
idx, err := c.temporal.Index()
50+
idx, err := s.temporal.Index()
4551
if err != nil {
4652
return err
4753
}
4854

49-
return c.IndexStorer.SetIndex(idx)
55+
return s.IndexStorer.SetIndex(idx)
5056
}

storage/transactional/module.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

storage/transactional/object.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ import (
55
"gopkg.in/src-d/go-git.v4/plumbing/storer"
66
)
77

8+
// ObjectStorage implements the storer.EncodedObjectStorer for the transactional package.
89
type ObjectStorage struct {
910
storer.EncodedObjectStorer
1011
temporal storer.EncodedObjectStorer
1112
}
1213

13-
func NewObjectStorage(s, temporal storer.EncodedObjectStorer) *ObjectStorage {
14-
return &ObjectStorage{EncodedObjectStorer: s, temporal: temporal}
14+
// NewObjectStorage returns a new EncodedObjectStorer based on a base storer and
15+
// a temporal storer.
16+
func NewObjectStorage(base, temporal storer.EncodedObjectStorer) *ObjectStorage {
17+
return &ObjectStorage{EncodedObjectStorer: base, temporal: temporal}
1518
}
1619

20+
// SetEncodedObject honors the storer.EncodedObjectStorer interface.
1721
func (o *ObjectStorage) SetEncodedObject(obj plumbing.EncodedObject) (plumbing.Hash, error) {
1822
return o.temporal.SetEncodedObject(obj)
1923
}
2024

25+
// HasEncodedObject honors the storer.EncodedObjectStorer interface.
2126
func (o *ObjectStorage) HasEncodedObject(h plumbing.Hash) error {
2227
err := o.EncodedObjectStorer.HasEncodedObject(h)
2328
if err == plumbing.ErrObjectNotFound {
@@ -27,6 +32,7 @@ func (o *ObjectStorage) HasEncodedObject(h plumbing.Hash) error {
2732
return err
2833
}
2934

35+
// EncodedObjectSize honors the storer.EncodedObjectStorer interface.
3036
func (o *ObjectStorage) EncodedObjectSize(h plumbing.Hash) (int64, error) {
3137
sz, err := o.EncodedObjectStorer.EncodedObjectSize(h)
3238
if err == plumbing.ErrObjectNotFound {
@@ -36,6 +42,7 @@ func (o *ObjectStorage) EncodedObjectSize(h plumbing.Hash) (int64, error) {
3642
return sz, err
3743
}
3844

45+
// EncodedObject honors the storer.EncodedObjectStorer interface.
3946
func (o *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) {
4047
obj, err := o.EncodedObjectStorer.EncodedObject(t, h)
4148
if err == plumbing.ErrObjectNotFound {
@@ -45,6 +52,7 @@ func (o *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (p
4552
return obj, err
4653
}
4754

55+
// IterEncodedObjects honors the storer.EncodedObjectStorer interface.
4856
func (o *ObjectStorage) IterEncodedObjects(t plumbing.ObjectType) (storer.EncodedObjectIter, error) {
4957
baseIter, err := o.EncodedObjectStorer.IterEncodedObjects(t)
5058
if err != nil {
@@ -62,6 +70,7 @@ func (o *ObjectStorage) IterEncodedObjects(t plumbing.ObjectType) (storer.Encode
6270
}), nil
6371
}
6472

73+
// Commit it copies the objects of the temporal storage into the base storage.
6574
func (o *ObjectStorage) Commit() error {
6675
iter, err := o.temporal.IterEncodedObjects(plumbing.AnyObject)
6776
if err != nil {

storage/transactional/reference.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"gopkg.in/src-d/go-git.v4/storage"
77
)
88

9+
// ReferenceStorage implements the storer.ReferenceStorage for the transactional package.
910
type ReferenceStorage struct {
1011
storer.ReferenceStorer
1112
temporal storer.ReferenceStorer
@@ -19,20 +20,24 @@ type ReferenceStorage struct {
1920
packRefs bool
2021
}
2122

22-
func NewReferenceStorage(s, temporal storer.ReferenceStorer) *ReferenceStorage {
23+
// NewReferenceStorage returns a new ReferenceStorer based on a base storer and
24+
// a temporal storer.
25+
func NewReferenceStorage(base, temporal storer.ReferenceStorer) *ReferenceStorage {
2326
return &ReferenceStorage{
24-
ReferenceStorer: s,
27+
ReferenceStorer: base,
2528
temporal: temporal,
2629

2730
deleted: make(map[plumbing.ReferenceName]struct{}, 0),
2831
}
2932
}
3033

34+
// SetReference honors the storer.ReferenceStorer interface.
3135
func (r *ReferenceStorage) SetReference(ref *plumbing.Reference) error {
3236
delete(r.deleted, ref.Name())
3337
return r.temporal.SetReference(ref)
3438
}
3539

40+
// SetReference honors the storer.ReferenceStorer interface.
3641
func (r *ReferenceStorage) CheckAndSetReference(ref, old *plumbing.Reference) error {
3742
if old == nil {
3843
return r.SetReference(ref)
@@ -54,6 +59,7 @@ func (r *ReferenceStorage) CheckAndSetReference(ref, old *plumbing.Reference) er
5459
return r.SetReference(ref)
5560
}
5661

62+
// Reference honors the storer.ReferenceStorer interface.
5763
func (r ReferenceStorage) Reference(n plumbing.ReferenceName) (*plumbing.Reference, error) {
5864
if _, deleted := r.deleted[n]; deleted {
5965
return nil, plumbing.ErrReferenceNotFound
@@ -67,6 +73,7 @@ func (r ReferenceStorage) Reference(n plumbing.ReferenceName) (*plumbing.Referen
6773
return ref, err
6874
}
6975

76+
// IterReferences honors the storer.ReferenceStorer interface.
7077
func (r ReferenceStorage) IterReferences() (storer.ReferenceIter, error) {
7178
baseIter, err := r.ReferenceStorer.IterReferences()
7279
if err != nil {
@@ -84,6 +91,7 @@ func (r ReferenceStorage) IterReferences() (storer.ReferenceIter, error) {
8491
}), nil
8592
}
8693

94+
// CountLooseRefs honors the storer.ReferenceStorer interface.
8795
func (r ReferenceStorage) CountLooseRefs() (int, error) {
8896
tc, err := r.temporal.CountLooseRefs()
8997
if err != nil {
@@ -98,16 +106,20 @@ func (r ReferenceStorage) CountLooseRefs() (int, error) {
98106
return tc + bc, nil
99107
}
100108

109+
// PackRefs honors the storer.ReferenceStorer interface.
101110
func (r ReferenceStorage) PackRefs() error {
102111
r.packRefs = true
103112
return nil
104113
}
105114

115+
// RemoveReference honors the storer.ReferenceStorer interface.
106116
func (r ReferenceStorage) RemoveReference(n plumbing.ReferenceName) error {
107117
r.deleted[n] = struct{}{}
108118
return r.temporal.RemoveReference(n)
109119
}
110120

121+
// Commit it copies the reference information of the temporal storage into the
122+
// base storage.
111123
func (r ReferenceStorage) Commit() error {
112124
for name := range r.deleted {
113125
if err := r.ReferenceStorer.RemoveReference(name); err != nil {

storage/transactional/shallow.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@ import (
55
"gopkg.in/src-d/go-git.v4/plumbing/storer"
66
)
77

8+
// ShallowStorage implements the storer.ShallowStorer for the transactional package.
89
type ShallowStorage struct {
910
storer.ShallowStorer
1011
temporal storer.ShallowStorer
1112
}
1213

13-
func NewShallowStorage(s, temporal storer.ShallowStorer) *ShallowStorage {
14+
// NewShallowStorage returns a new ShallowStorage based on a base storer and
15+
// a temporal storer.
16+
func NewShallowStorage(base, temporal storer.ShallowStorer) *ShallowStorage {
1417
return &ShallowStorage{
15-
ShallowStorer: s,
18+
ShallowStorer: base,
1619
temporal: temporal,
1720
}
1821
}
1922

23+
// SetShallow honors the storer.ShallowStorer interface.
2024
func (s *ShallowStorage) SetShallow(commits []plumbing.Hash) error {
2125
return s.temporal.SetShallow(commits)
2226
}
2327

28+
// Shallow honors the storer.ShallowStorer interface.
2429
func (s *ShallowStorage) Shallow() ([]plumbing.Hash, error) {
2530
shallow, err := s.temporal.Shallow()
2631
if err != nil {
@@ -34,6 +39,8 @@ func (s *ShallowStorage) Shallow() ([]plumbing.Hash, error) {
3439
return s.ShallowStorer.Shallow()
3540
}
3641

42+
// Commit it copies the shallow information of the temporal storage into the
43+
// base storage.
3744
func (s *ShallowStorage) Commit() error {
3845
commits, err := s.temporal.Shallow()
3946
if err != nil || len(commits) == 0 {

storage/transactional/storage.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import (
44
"gopkg.in/src-d/go-git.v4/storage"
55
)
66

7-
// Storage is an implementation of git.Storer that stores data on disk in the
8-
// standard git format (this is, the .git directory). Zero values of this type
9-
// are not safe to use, see the NewStorage function below.
7+
// Storage is a transactional implementation of git.Storer, it demux the write
8+
// and read operation of two separate storers, allowing to merge content calling
9+
// Storage.Commit.
10+
//
11+
// The API and functionality of this package are considered EXPERIMENTAL and is
12+
// not considered stable nor production ready.
1013
type Storage struct {
1114
s, temporal storage.Storer
1215

@@ -17,19 +20,23 @@ type Storage struct {
1720
*ConfigStorage
1821
}
1922

20-
func NewStorage(s, temporal storage.Storer) *Storage {
23+
// 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
25+
// the write operations are stored.
26+
func NewStorage(base, temporal storage.Storer) *Storage {
2127
return &Storage{
22-
s: s,
28+
s: base,
2329
temporal: temporal,
2430

25-
ObjectStorage: NewObjectStorage(s, temporal),
26-
ReferenceStorage: NewReferenceStorage(s, temporal),
27-
IndexStorage: NewIndexStorage(s, temporal),
28-
ShallowStorage: NewShallowStorage(s, temporal),
29-
ConfigStorage: NewConfigStorage(s, temporal),
31+
ObjectStorage: NewObjectStorage(base, temporal),
32+
ReferenceStorage: NewReferenceStorage(base, temporal),
33+
IndexStorage: NewIndexStorage(base, temporal),
34+
ShallowStorage: NewShallowStorage(base, temporal),
35+
ConfigStorage: NewConfigStorage(base, temporal),
3036
}
3137
}
3238

39+
// Module it honors the storage.ModuleStorer interface.
3340
func (s *Storage) Module(name string) (storage.Storer, error) {
3441
base, err := s.s.Module(name)
3542
if err != nil {
@@ -44,6 +51,7 @@ func (s *Storage) Module(name string) (storage.Storer, error) {
4451
return NewStorage(base, temporal), nil
4552
}
4653

54+
// Commit it copies the content of the temporal storage into the base storage.
4755
func (s *Storage) Commit() error {
4856
for _, c := range []interface{ Commit() error }{
4957
s.ObjectStorage,

0 commit comments

Comments
 (0)