diff --git a/settings.go b/settings.go index 8bbdda0..c6dfe1c 100644 --- a/settings.go +++ b/settings.go @@ -86,14 +86,14 @@ func SetMwindowMappedLimit(size int) error { } func EnableCaching(enabled bool) error { - if enabled { - return setSizet(C.GIT_OPT_ENABLE_CACHING, 1) - } else { - return setSizet(C.GIT_OPT_ENABLE_CACHING, 0) - } + if enabled { + return setSizet(C.GIT_OPT_ENABLE_CACHING, 1) + } else { + 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) } @@ -130,8 +130,7 @@ func getSizetSizet(opt C.int) (int, int, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() - var val1 C.size_t - var val2 C.size_t + 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) diff --git a/settings_test.go b/settings_test.go index 3a4ce0a..4e45567 100644 --- a/settings_test.go +++ b/settings_test.go @@ -48,3 +48,36 @@ func TestMmapSizes(t *testing.T) { 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) +} \ No newline at end of file