-
Notifications
You must be signed in to change notification settings - Fork 16
/
readonly.go
61 lines (52 loc) · 1.67 KB
/
readonly.go
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 readonly
import (
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing/storer"
"github.com/go-git/go-git/v5/storage"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/go-git/go-git/v5/storage/transactional"
)
type store struct {
storer.EncodedObjectStorer
storer.ReferenceStorer
storer.ShallowStorer
storer.IndexStorer
config.ConfigStorer
base storage.Storer
}
// readonly store is a shortcut to transactional store without
// the commit hooks, meaning any write changes performed to this store
// are never persisted and only held in memory throughout the duration
// of this object
func NewStorage(base storage.Storer) storage.Storer {
return &store{
NewObjectStorage(base),
NewReferenceStorage(base),
NewShallowStorage(base),
NewIndexStorage(base),
NewConfigStorage(base),
base,
}
}
func (s *store) Module(name string) (storage.Storer, error) {
modStore, err := s.base.Module(name)
if err != nil {
return nil, err
}
return NewStorage(modStore), nil
}
func NewConfigStorage(base storage.Storer) config.ConfigStorer {
return transactional.NewConfigStorage(base, memory.NewStorage())
}
func NewShallowStorage(base storage.Storer) storer.ShallowStorer {
return transactional.NewShallowStorage(base, memory.NewStorage())
}
func NewIndexStorage(base storage.Storer) storer.IndexStorer {
return transactional.NewIndexStorage(base, memory.NewStorage())
}
func NewReferenceStorage(base storage.Storer) storer.ReferenceStorer {
return transactional.NewReferenceStorage(base, memory.NewStorage())
}
func NewObjectStorage(base storage.Storer) storer.EncodedObjectStorer {
return transactional.NewObjectStorage(base, memory.NewStorage())
}