diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2019-02-02 13:08:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-02 13:08:52 +0100 |
commit | d1b5bceb228e528bf085a3d4e2c35218e692da01 (patch) | |
tree | 9dadb6130108cce350f546e4e30bc421c2b422a1 /storage/transactional/config.go | |
parent | a1f6ef44dfed1253ef7f3bc049f66b15f8fc2ab2 (diff) | |
parent | 96317743391ac87aeb07d292469e212671628437 (diff) | |
download | go-git-d1b5bceb228e528bf085a3d4e2c35218e692da01.tar.gz |
Merge pull request #1006 from mcuadros/transactional-storage
storage: transactional, new storage with transactional capabilities
Diffstat (limited to 'storage/transactional/config.go')
-rw-r--r-- | storage/transactional/config.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/storage/transactional/config.go b/storage/transactional/config.go new file mode 100644 index 0000000..4d8efe1 --- /dev/null +++ b/storage/transactional/config.go @@ -0,0 +1,50 @@ +package transactional + +import "gopkg.in/src-d/go-git.v4/config" + +// ConfigStorage implements the storer.ConfigStorage for the transactional package. +type ConfigStorage struct { + config.ConfigStorer + temporal config.ConfigStorer + + set bool +} + +// NewConfigStorage returns a new ConfigStorer based on a base storer and a +// temporal storer. +func NewConfigStorage(s, temporal config.ConfigStorer) *ConfigStorage { + return &ConfigStorage{ConfigStorer: s, temporal: temporal} +} + +// SetConfig honors the storer.ConfigStorer interface. +func (c *ConfigStorage) SetConfig(cfg *config.Config) error { + if err := c.temporal.SetConfig(cfg); err != nil { + return err + } + + c.set = true + return nil +} + +// Config honors the storer.ConfigStorer interface. +func (c *ConfigStorage) Config() (*config.Config, error) { + if !c.set { + return c.ConfigStorer.Config() + } + + return c.temporal.Config() +} + +// Commit it copies the config from the temporal storage into the base storage. +func (c *ConfigStorage) Commit() error { + if !c.set { + return nil + } + + cfg, err := c.temporal.Config() + if err != nil { + return err + } + + return c.ConfigStorer.SetConfig(cfg) +} |