Compare commits

...

1 Commits

Author SHA1 Message Date
Carlos Martín Nieto 785b6024cf Add config snapshot methods
Bring the immutability to Go.
2014-05-18 10:37:17 +02:00
2 changed files with 32 additions and 0 deletions

View File

@ -354,6 +354,22 @@ func (c *Config) Refresh() error {
return nil
}
// Snapshot creates an immutable snapshot from the configuration. This
// means that reads over multiple values will reflect the same version
// of the configuration files
func (c *Config) Snapshot() (*Config, error) {
config := new(Config)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_config_snapshot(&config.ptr, c.ptr); ret < 0 {
return nil, MakeGitError(ret)
}
return config, nil
}
type ConfigIterator struct {
ptr *C.git_config_iterator
}

View File

@ -87,6 +87,22 @@ func (v *Repository) Config() (*Config, error) {
return config, nil
}
// ConfigSnapshot returns a configuration snapshot from the
// repository. This is the preferred form when not changing the
// configuration.
func (v *Repository) ConfigSnapshot() (*Config, error) {
config := new(Config)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_repository_config_snapshot(&config.ptr, v.ptr); ret < 0 {
return nil, MakeGitError(ret)
}
return config, nil
}
func (v *Repository) Index() (*Index, error) {
var ptr *C.git_index