forked from libgit2/git2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
174 lines (137 loc) · 3.63 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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_set_cache_object_limit(git_object_t type, size_t size)
{
return git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, type, size);
}
int _go_git_opts_get_size_t(int opt, size_t *val)
{
return git_libgit2_opts(opt, val);
}
int _go_git_opts_get_size_t_size_t(int opt, size_t *val1, size_t *val2)
{
return git_libgit2_opts(opt, val1, val2);
}
*/
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 EnableCaching(enabled bool) error {
if enabled {
return setSizet(C.GIT_OPT_ENABLE_CACHING, 1)
} else {
return setSizet(C.GIT_OPT_ENABLE_CACHING, 0)
}
}
func EnableStrictHashVerification(enabled bool) error {
if enabled {
return setSizet(C.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1)
} else {
return setSizet(C.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0)
}
}
func EnableFsyncGitDir(enabled bool) error {
if enabled {
return setSizet(C.GIT_OPT_ENABLE_FSYNC_GITDIR, 1)
} else {
return setSizet(C.GIT_OPT_ENABLE_FSYNC_GITDIR, 0)
}
}
func CachedMemory() (current int, allowed int, err error) {
return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY)
}
// deprecated: You should use `CachedMemory()` instead.
func GetCachedMemory() (current int, allowed int, err error) {
return CachedMemory()
}
func SetCacheMaxSize(maxSize int) error {
return setSizet(C.GIT_OPT_SET_CACHE_MAX_SIZE, maxSize)
}
func SetCacheObjectLimit(objectType ObjectType, size int) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C._go_git_opts_set_cache_object_limit(C.git_object_t(objectType), C.size_t(size))
if err < 0 {
return MakeGitError(err)
}
return nil
}
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 getSizetSizet(opt C.int) (int, int, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var val1, val2 C.size_t
err := C._go_git_opts_get_size_t_size_t(opt, &val1, &val2)
if err < 0 {
return 0, 0, MakeGitError(err)
}
return int(val1), int(val2), 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
}