Add Go functions for git_config_find_* functions

ConfigFindGlobal -> git_config_find_global
ConfigFindSystem -> git_config_find_system
ConfigFindXDG    -> git_config_find_xdg
This commit is contained in:
Tarrant Rollins 2015-01-13 19:48:45 -08:00
parent 57412d0293
commit 548bb9b5e9
1 changed files with 47 additions and 5 deletions

View File

@ -35,14 +35,14 @@ const (
)
type ConfigEntry struct {
Name string
Name string
Value string
Level ConfigLevel
}
func newConfigEntryFromC(centry *C.git_config_entry) *ConfigEntry {
return &ConfigEntry{
Name: C.GoString(centry.name),
Name: C.GoString(centry.name),
Value: C.GoString(centry.value),
Level: ConfigLevel(centry.level),
}
@ -74,7 +74,6 @@ func (c *Config) AddFile(path string, level ConfigLevel, force bool) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), cbool(force))
if ret < 0 {
return MakeGitError(ret)
@ -130,7 +129,6 @@ func (c *Config) LookupString(name string) (string, error) {
return C.GoString(ptr), nil
}
func (c *Config) LookupBool(name string) (bool, error) {
var out C.int
cname := C.CString(name)
@ -234,7 +232,6 @@ func (c *Config) SetInt32(name string, value int32) (err error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@ -368,3 +365,48 @@ func (iter *ConfigIterator) Free() {
runtime.SetFinalizer(iter, nil)
C.free(unsafe.Pointer(iter.ptr))
}
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
}