2013-03-05 13:53:04 -06:00
|
|
|
package git
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <git2.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import (
|
2013-11-14 07:24:43 -06:00
|
|
|
"runtime"
|
2013-03-05 13:53:04 -06:00
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2013-09-11 18:01:52 -05:00
|
|
|
type ConfigLevel int
|
|
|
|
|
|
|
|
const (
|
2015-10-26 09:20:18 -05:00
|
|
|
// System-wide on Windows, for compatibility with portable git
|
|
|
|
ConfigLevelProgramdata ConfigLevel = C.GIT_CONFIG_LEVEL_PROGRAMDATA
|
|
|
|
|
2013-09-11 18:01:52 -05:00
|
|
|
// System-wide configuration file; /etc/gitconfig on Linux systems
|
|
|
|
ConfigLevelSystem ConfigLevel = C.GIT_CONFIG_LEVEL_SYSTEM
|
|
|
|
|
|
|
|
// XDG compatible configuration file; typically ~/.config/git/config
|
|
|
|
ConfigLevelXDG ConfigLevel = C.GIT_CONFIG_LEVEL_XDG
|
|
|
|
|
|
|
|
// User-specific configuration file (also called Global configuration
|
|
|
|
// file); typically ~/.gitconfig
|
|
|
|
ConfigLevelGlobal ConfigLevel = C.GIT_CONFIG_LEVEL_GLOBAL
|
|
|
|
|
|
|
|
// Repository specific configuration file; $WORK_DIR/.git/config on
|
|
|
|
// non-bare repos
|
|
|
|
ConfigLevelLocal ConfigLevel = C.GIT_CONFIG_LEVEL_LOCAL
|
|
|
|
|
|
|
|
// Application specific configuration file; freely defined by applications
|
|
|
|
ConfigLevelApp ConfigLevel = C.GIT_CONFIG_LEVEL_APP
|
|
|
|
|
|
|
|
// Represents the highest level available config file (i.e. the most
|
|
|
|
// specific config file available that actually is loaded)
|
|
|
|
ConfigLevelHighest ConfigLevel = C.GIT_CONFIG_HIGHEST_LEVEL
|
|
|
|
)
|
|
|
|
|
2013-09-11 18:39:35 -05:00
|
|
|
type ConfigEntry struct {
|
2015-01-13 21:48:45 -06:00
|
|
|
Name string
|
2013-09-11 18:39:35 -05:00
|
|
|
Value string
|
|
|
|
Level ConfigLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
func newConfigEntryFromC(centry *C.git_config_entry) *ConfigEntry {
|
|
|
|
return &ConfigEntry{
|
2015-01-13 21:48:45 -06:00
|
|
|
Name: C.GoString(centry.name),
|
2013-09-11 18:39:35 -05:00
|
|
|
Value: C.GoString(centry.value),
|
|
|
|
Level: ConfigLevel(centry.level),
|
|
|
|
}
|
|
|
|
}
|
2013-09-11 18:01:52 -05:00
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
type Config struct {
|
|
|
|
ptr *C.git_config
|
|
|
|
}
|
|
|
|
|
2013-09-11 18:01:52 -05:00
|
|
|
// NewConfig creates a new empty configuration object
|
|
|
|
func NewConfig() (*Config, error) {
|
|
|
|
config := new(Config)
|
|
|
|
|
2013-09-21 16:01:37 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
if ret := C.git_config_new(&config.ptr); ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return nil, MakeGitError(ret)
|
2013-09-11 18:01:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddFile adds a file-backed backend to the config object at the specified level.
|
|
|
|
func (c *Config) AddFile(path string, level ConfigLevel, force bool) error {
|
|
|
|
cpath := C.CString(path)
|
|
|
|
defer C.free(unsafe.Pointer(cpath))
|
|
|
|
|
2013-09-21 16:01:37 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 18:01:52 -05:00
|
|
|
ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), cbool(force))
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-09-11 18:01:52 -05:00
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return MakeGitError(ret)
|
2013-09-11 18:01:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
func (c *Config) LookupInt32(name string) (int32, error) {
|
2013-03-05 13:53:04 -06:00
|
|
|
var out C.int32_t
|
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
ret := C.git_config_get_int32(&out, c.ptr, cname)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-03-05 13:53:04 -06:00
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return 0, MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return int32(out), nil
|
|
|
|
}
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
func (c *Config) LookupInt64(name string) (int64, error) {
|
2013-03-05 13:53:04 -06:00
|
|
|
var out C.int64_t
|
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
ret := C.git_config_get_int64(&out, c.ptr, cname)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-03-05 13:53:04 -06:00
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return 0, MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return int64(out), nil
|
|
|
|
}
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
func (c *Config) LookupString(name string) (string, error) {
|
2013-03-05 13:53:04 -06:00
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
2015-09-26 17:37:48 -05:00
|
|
|
valBuf := C.git_buf{}
|
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2017-07-07 16:45:09 -05:00
|
|
|
ret := C.git_config_get_string_buf(&valBuf, c.ptr, cname)
|
|
|
|
runtime.KeepAlive(c)
|
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return "", MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
2015-09-26 17:37:48 -05:00
|
|
|
defer C.git_buf_free(&valBuf)
|
2013-03-05 13:53:04 -06:00
|
|
|
|
2015-09-26 17:37:48 -05:00
|
|
|
return C.GoString(valBuf.ptr), nil
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
func (c *Config) LookupBool(name string) (bool, error) {
|
|
|
|
var out C.int
|
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
2013-09-21 16:01:37 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
ret := C.git_config_get_bool(&out, c.ptr, cname)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-09-11 16:31:24 -05:00
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return false, MakeGitError(ret)
|
2013-09-11 16:31:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return out != 0, nil
|
|
|
|
}
|
|
|
|
|
2013-09-11 18:39:35 -05:00
|
|
|
func (c *Config) NewMultivarIterator(name, regexp string) (*ConfigIterator, error) {
|
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
|
|
|
var cregexp *C.char
|
|
|
|
if regexp == "" {
|
|
|
|
cregexp = nil
|
|
|
|
} else {
|
|
|
|
cregexp = C.CString(regexp)
|
|
|
|
defer C.free(unsafe.Pointer(cregexp))
|
|
|
|
}
|
|
|
|
|
2017-07-07 16:45:09 -05:00
|
|
|
iter := &ConfigIterator{cfg: c}
|
2013-09-21 16:01:37 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 18:39:35 -05:00
|
|
|
ret := C.git_config_multivar_iterator_new(&iter.ptr, c.ptr, cname, cregexp)
|
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return nil, MakeGitError(ret)
|
2013-09-11 18:39:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
runtime.SetFinalizer(iter, (*ConfigIterator).Free)
|
|
|
|
return iter, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewIterator creates an iterator over each entry in the
|
|
|
|
// configuration
|
|
|
|
func (c *Config) NewIterator() (*ConfigIterator, error) {
|
2017-07-07 16:45:09 -05:00
|
|
|
iter := &ConfigIterator{cfg: c}
|
2013-09-21 16:01:37 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 18:39:35 -05:00
|
|
|
ret := C.git_config_iterator_new(&iter.ptr, c.ptr)
|
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return nil, MakeGitError(ret)
|
2013-09-11 18:39:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return iter, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewIteratorGlob creates an iterator over each entry in the
|
|
|
|
// configuration whose name matches the given regular expression
|
|
|
|
func (c *Config) NewIteratorGlob(regexp string) (*ConfigIterator, error) {
|
2017-07-07 16:45:09 -05:00
|
|
|
iter := &ConfigIterator{cfg: c}
|
2013-09-11 18:39:35 -05:00
|
|
|
cregexp := C.CString(regexp)
|
|
|
|
defer C.free(unsafe.Pointer(cregexp))
|
|
|
|
|
2013-09-21 16:01:37 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 18:39:35 -05:00
|
|
|
ret := C.git_config_iterator_glob_new(&iter.ptr, c.ptr, cregexp)
|
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return nil, MakeGitError(ret)
|
2013-09-11 18:39:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return iter, nil
|
|
|
|
}
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
func (c *Config) SetString(name, value string) (err error) {
|
2013-03-05 13:53:04 -06:00
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
|
|
|
cvalue := C.CString(value)
|
|
|
|
defer C.free(unsafe.Pointer(cvalue))
|
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
ret := C.git_config_set_string(c.ptr, cname, cvalue)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-03-05 13:53:04 -06:00
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2013-11-14 07:24:43 -06:00
|
|
|
|
|
|
|
func (c *Config) Free() {
|
|
|
|
runtime.SetFinalizer(c, nil)
|
|
|
|
C.git_config_free(c.ptr)
|
|
|
|
}
|
2013-09-11 16:31:24 -05:00
|
|
|
|
|
|
|
func (c *Config) SetInt32(name string, value int32) (err error) {
|
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
2014-12-05 19:44:57 -06:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
ret := C.git_config_set_int32(c.ptr, cname, C.int32_t(value))
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-09-11 16:31:24 -05:00
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return MakeGitError(ret)
|
2013-09-11 16:31:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) SetInt64(name string, value int64) (err error) {
|
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
2013-09-21 16:01:37 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
ret := C.git_config_set_int64(c.ptr, cname, C.int64_t(value))
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-09-11 16:31:24 -05:00
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return MakeGitError(ret)
|
2013-09-11 16:31:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) SetBool(name string, value bool) (err error) {
|
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
2013-09-21 16:01:37 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
ret := C.git_config_set_bool(c.ptr, cname, cbool(value))
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-09-11 16:31:24 -05:00
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return MakeGitError(ret)
|
2013-09-11 16:31:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) SetMultivar(name, regexp, value string) (err error) {
|
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
|
|
|
cregexp := C.CString(regexp)
|
|
|
|
defer C.free(unsafe.Pointer(cregexp))
|
|
|
|
|
|
|
|
cvalue := C.CString(value)
|
|
|
|
defer C.free(unsafe.Pointer(cvalue))
|
|
|
|
|
2013-09-21 16:01:37 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
ret := C.git_config_set_multivar(c.ptr, cname, cregexp, cvalue)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-09-11 16:31:24 -05:00
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return MakeGitError(ret)
|
2013-09-11 16:31:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) Delete(name string) error {
|
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
2013-09-21 16:01:37 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 16:31:24 -05:00
|
|
|
ret := C.git_config_delete_entry(c.ptr, cname)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
2013-09-11 16:31:24 -05:00
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return MakeGitError(ret)
|
2013-09-11 16:31:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2013-09-11 18:01:52 -05:00
|
|
|
|
|
|
|
// OpenLevel creates a single-level focused config object from a multi-level one
|
|
|
|
func (c *Config) OpenLevel(parent *Config, level ConfigLevel) (*Config, error) {
|
|
|
|
config := new(Config)
|
2013-09-21 16:01:37 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 18:01:52 -05:00
|
|
|
ret := C.git_config_open_level(&config.ptr, parent.ptr, C.git_config_level_t(level))
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(c)
|
|
|
|
runtime.KeepAlive(parent)
|
2013-09-11 18:01:52 -05:00
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return nil, MakeGitError(ret)
|
2013-09-11 18:01:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenOndisk creates a new config instance containing a single on-disk file
|
|
|
|
func OpenOndisk(parent *Config, path string) (*Config, error) {
|
|
|
|
cpath := C.CString(path)
|
|
|
|
defer C.free(unsafe.Pointer(cpath))
|
|
|
|
|
|
|
|
config := new(Config)
|
2013-09-21 16:01:37 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
if ret := C.git_config_open_ondisk(&config.ptr, cpath); ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return nil, MakeGitError(ret)
|
2013-09-11 18:01:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
2013-09-11 18:39:35 -05:00
|
|
|
type ConfigIterator struct {
|
|
|
|
ptr *C.git_config_iterator
|
2017-07-07 16:45:09 -05:00
|
|
|
cfg *Config
|
2013-09-11 18:39:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Next returns the next entry for this iterator
|
|
|
|
func (iter *ConfigIterator) Next() (*ConfigEntry, error) {
|
|
|
|
var centry *C.git_config_entry
|
|
|
|
|
2014-12-05 19:44:57 -06:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-09-11 18:39:35 -05:00
|
|
|
ret := C.git_config_next(¢ry, iter.ptr)
|
|
|
|
if ret < 0 {
|
2014-02-26 09:14:31 -06:00
|
|
|
return nil, MakeGitError(ret)
|
2013-09-11 18:39:35 -05:00
|
|
|
}
|
|
|
|
|
2017-07-07 16:45:09 -05:00
|
|
|
entry := newConfigEntryFromC(centry)
|
|
|
|
runtime.KeepAlive(iter)
|
|
|
|
|
|
|
|
return entry, nil
|
2013-09-11 18:39:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (iter *ConfigIterator) Free() {
|
|
|
|
runtime.SetFinalizer(iter, nil)
|
|
|
|
C.free(unsafe.Pointer(iter.ptr))
|
|
|
|
}
|
2015-01-13 21:48:45 -06:00
|
|
|
|
|
|
|
func ConfigFindGlobal() (string, error) {
|
|
|
|
var buf C.git_buf
|
|
|
|
defer C.git_buf_free(&buf)
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_config_find_global(&buf)
|
|
|
|
if ret < 0 {
|
|
|
|
return "", MakeGitError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return C.GoString(buf.ptr), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConfigFindSystem() (string, error) {
|
|
|
|
var buf C.git_buf
|
|
|
|
defer C.git_buf_free(&buf)
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_config_find_system(&buf)
|
|
|
|
if ret < 0 {
|
|
|
|
return "", MakeGitError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return C.GoString(buf.ptr), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConfigFindXDG() (string, error) {
|
|
|
|
var buf C.git_buf
|
|
|
|
defer C.git_buf_free(&buf)
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_config_find_xdg(&buf)
|
|
|
|
if ret < 0 {
|
|
|
|
return "", MakeGitError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return C.GoString(buf.ptr), nil
|
|
|
|
}
|
2015-10-26 09:20:18 -05:00
|
|
|
|
|
|
|
// ConfigFindProgramdata locate the path to the configuration file in ProgramData.
|
|
|
|
//
|
|
|
|
// Look for the file in %PROGRAMDATA%\Git\config used by portable git.
|
|
|
|
func ConfigFindProgramdata() (string, error) {
|
|
|
|
var buf C.git_buf
|
|
|
|
defer C.git_buf_free(&buf)
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_config_find_programdata(&buf)
|
|
|
|
if ret < 0 {
|
|
|
|
return "", MakeGitError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return C.GoString(buf.ptr), nil
|
|
|
|
}
|