Add config snapshot methods
Bring the immutability to Go.
diff --git a/config.go b/config.go
index 6b1f093..0d1bbf5 100644
--- a/config.go
+++ b/config.go
@@ -354,6 +354,22 @@
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
}
diff --git a/repository.go b/repository.go
index 81a46b1..de4c1fa 100644
--- a/repository.go
+++ b/repository.go
@@ -87,6 +87,22 @@
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