cache_opts: address PR comments
This commit is contained in:
parent
512f37b369
commit
862cde393c
15
settings.go
15
settings.go
|
@ -86,14 +86,14 @@ func SetMwindowMappedLimit(size int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func EnableCaching(enabled bool) error {
|
func EnableCaching(enabled bool) error {
|
||||||
if enabled {
|
if enabled {
|
||||||
return setSizet(C.GIT_OPT_ENABLE_CACHING, 1)
|
return setSizet(C.GIT_OPT_ENABLE_CACHING, 1)
|
||||||
} else {
|
} else {
|
||||||
return setSizet(C.GIT_OPT_ENABLE_CACHING, 0)
|
return setSizet(C.GIT_OPT_ENABLE_CACHING, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCachedMemory() (int, int, error) {
|
func GetCachedMemory() (current int, allowed int, err error) {
|
||||||
return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY)
|
return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,8 +130,7 @@ func getSizetSizet(opt C.int) (int, int, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
var val1 C.size_t
|
var val1, val2 C.size_t
|
||||||
var val2 C.size_t
|
|
||||||
err := C._go_git_opts_get_size_t_size_t(opt, &val1, &val2)
|
err := C._go_git_opts_get_size_t_size_t(opt, &val1, &val2)
|
||||||
if err < 0 {
|
if err < 0 {
|
||||||
return 0, 0, MakeGitError(err)
|
return 0, 0, MakeGitError(err)
|
||||||
|
|
|
@ -48,3 +48,36 @@ func TestMmapSizes(t *testing.T) {
|
||||||
t.Fatal("Sizes don't match")
|
t.Fatal("Sizes don't match")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEnableCaching(t *testing.T) {
|
||||||
|
err := EnableCaching(false)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
err = EnableCaching(true)
|
||||||
|
checkFatal(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetCachedMemory(t *testing.T) {
|
||||||
|
current, allowed, err := GetCachedMemory()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if current < 0 {
|
||||||
|
t.Fatal("current < 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
if allowed < 0 {
|
||||||
|
t.Fatal("allowed < 0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetCacheMaxSize(t *testing.T) {
|
||||||
|
err := SetCacheMaxSize(0)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
err = SetCacheMaxSize(1024 * 1024)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
// revert to default 256MB
|
||||||
|
err = SetCacheMaxSize(256 * 1024 * 1024)
|
||||||
|
checkFatal(t, err)
|
||||||
|
}
|
Loading…
Reference in New Issue