forked from libgit2/git2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.go
102 lines (79 loc) · 1.93 KB
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package git
/*
#include <git2.h>
int _go_git_opts_get_search_path(int level, git_buf *buf)
{
return git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, level, buf);
}
int _go_git_opts_set_search_path(int level, const char *path)
{
return git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, level, path);
}
int _go_git_opts_set_size_t(int opt, size_t val)
{
return git_libgit2_opts(opt, val);
}
int _go_git_opts_get_size_t(int opt, size_t *val)
{
return git_libgit2_opts(opt, val);
}
*/
import "C"
import (
"runtime"
"unsafe"
)
func SearchPath(level ConfigLevel) (string, error) {
var buf C.git_buf
defer C.git_buf_dispose(&buf)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C._go_git_opts_get_search_path(C.int(level), &buf)
if err < 0 {
return "", MakeGitError(err)
}
return C.GoString(buf.ptr), nil
}
func SetSearchPath(level ConfigLevel, path string) error {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C._go_git_opts_set_search_path(C.int(level), cpath)
if err < 0 {
return MakeGitError(err)
}
return nil
}
func MwindowSize() (int, error) {
return getSizet(C.GIT_OPT_GET_MWINDOW_SIZE)
}
func SetMwindowSize(size int) error {
return setSizet(C.GIT_OPT_SET_MWINDOW_SIZE, size)
}
func MwindowMappedLimit() (int, error) {
return getSizet(C.GIT_OPT_GET_MWINDOW_MAPPED_LIMIT)
}
func SetMwindowMappedLimit(size int) error {
return setSizet(C.GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, size)
}
func getSizet(opt C.int) (int, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var val C.size_t
err := C._go_git_opts_get_size_t(opt, &val)
if err < 0 {
return 0, MakeGitError(err)
}
return int(val), nil
}
func setSizet(opt C.int, val int) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
cval := C.size_t(val)
err := C._go_git_opts_set_size_t(opt, cval)
if err < 0 {
return MakeGitError(err)
}
return nil
}