From 785b6024cfa7e95359eb5b0fe8cfc7c8e6c4905e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sun, 18 May 2014 10:37:17 +0200 Subject: [PATCH] Add config snapshot methods Bring the immutability to Go. --- config.go | 16 ++++++++++++++++ repository.go | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/config.go b/config.go index 6b1f093..0d1bbf5 100644 --- a/config.go +++ b/config.go @@ -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 } diff --git a/repository.go b/repository.go index 81a46b1..de4c1fa 100644 --- a/repository.go +++ b/repository.go @@ -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