| 1 |
package transactional |
| 2 |
|
| 3 |
import "github.com/go-git/go-git/v5/config" |
| 4 |
|
| 5 |
// ConfigStorage implements the storer.ConfigStorage for the transactional package. |
| 6 |
type ConfigStorage struct { |
| 7 |
config.ConfigStorer |
| 8 |
temporal config.ConfigStorer |
| 9 |
|
| 10 |
set bool |
| 11 |
} |
| 12 |
|
| 13 |
// NewConfigStorage returns a new ConfigStorer based on a base storer and a |
| 14 |
// temporal storer. |
| 15 |
func NewConfigStorage(s, temporal config.ConfigStorer) *ConfigStorage { |
| 16 |
return &ConfigStorage{ConfigStorer: s, temporal: temporal} |
| 17 |
} |
| 18 |
|
| 19 |
// SetConfig honors the storer.ConfigStorer interface. |
| 20 |
func (c *ConfigStorage) SetConfig(cfg *config.Config) error { |
| 21 |
if err := c.temporal.SetConfig(cfg); err != nil { |
| 22 |
return err |
| 23 |
} |
| 24 |
|
| 25 |
c.set = true |
| 26 |
return nil |
| 27 |
} |
| 28 |
|
| 29 |
// Config honors the storer.ConfigStorer interface. |
| 30 |
func (c *ConfigStorage) Config() (*config.Config, error) { |
| 31 |
if !c.set { |
| 32 |
return c.ConfigStorer.Config() |
| 33 |
} |
| 34 |
|
| 35 |
return c.temporal.Config() |
| 36 |
} |
| 37 |
|
| 38 |
// Commit it copies the config from the temporal storage into the base storage. |
| 39 |
func (c *ConfigStorage) Commit() error { |
| 40 |
if !c.set { |
| 41 |
return nil |
| 42 |
} |
| 43 |
|
| 44 |
cfg, err := c.temporal.Config() |
| 45 |
if err != nil { |
| 46 |
return err |
| 47 |
} |
| 48 |
|
| 49 |
return c.ConfigStorer.SetConfig(cfg) |
| 50 |
} |