aboutsummaryrefslogtreecommitdiffstats
path: root/storage/transactional/storage.go
blob: 6611a430e04583f1af317f03a4ed16113c583a0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package transactional

import (
	"gopkg.in/src-d/go-git.v4/storage"
)

// Storage is an implementation of git.Storer that stores data on disk in the
// standard git format (this is, the .git directory). Zero values of this type
// are not safe to use, see the NewStorage function below.
type Storage struct {
	s, temporal storage.Storer

	*ObjectStorage
	*ReferenceStorage
	*IndexStorage
	*ShallowStorage
	*ConfigStorage
}

func NewStorage(s, temporal storage.Storer) *Storage {
	return &Storage{
		s:        s,
		temporal: temporal,

		ObjectStorage:    NewObjectStorage(s, temporal),
		ReferenceStorage: NewReferenceStorage(s, temporal),
		IndexStorage:     NewIndexStorage(s, temporal),
		ShallowStorage:   NewShallowStorage(s, temporal),
		ConfigStorage:    NewConfigStorage(s, temporal),
	}
}

func (s *Storage) Module(name string) (storage.Storer, error) {
	base, err := s.s.Module(name)
	if err != nil {
		return nil, err
	}

	temporal, err := s.temporal.Module(name)
	if err != nil {
		return nil, err
	}

	return NewStorage(base, temporal), nil
}

func (s *Storage) Commit() error {
	for _, c := range []interface{ Commit() error }{
		s.ObjectStorage,
		s.ReferenceStorage,
		s.IndexStorage,
		s.ShallowStorage,
		s.ConfigStorage,
	} {
		if err := c.Commit(); err != nil {
			return err
		}
	}

	return nil
}