Skip to content

Commit 862cde3

Browse files
cache_opts: address PR comments
1 parent 512f37b commit 862cde3

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

settings.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ func SetMwindowMappedLimit(size int) error {
8686
}
8787

8888
func EnableCaching(enabled bool) error {
89-
if enabled {
90-
return setSizet(C.GIT_OPT_ENABLE_CACHING, 1)
91-
} else {
92-
return setSizet(C.GIT_OPT_ENABLE_CACHING, 0)
93-
}
89+
if enabled {
90+
return setSizet(C.GIT_OPT_ENABLE_CACHING, 1)
91+
} else {
92+
return setSizet(C.GIT_OPT_ENABLE_CACHING, 0)
93+
}
9494
}
9595

96-
func GetCachedMemory() (int, int, error) {
96+
func GetCachedMemory() (current int, allowed int, err error) {
9797
return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY)
9898
}
9999

@@ -130,8 +130,7 @@ func getSizetSizet(opt C.int) (int, int, error) {
130130
runtime.LockOSThread()
131131
defer runtime.UnlockOSThread()
132132

133-
var val1 C.size_t
134-
var val2 C.size_t
133+
var val1, val2 C.size_t
135134
err := C._go_git_opts_get_size_t_size_t(opt, &val1, &val2)
136135
if err < 0 {
137136
return 0, 0, MakeGitError(err)

settings_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,36 @@ func TestMmapSizes(t *testing.T) {
4848
t.Fatal("Sizes don't match")
4949
}
5050
}
51+
52+
func TestEnableCaching(t *testing.T) {
53+
err := EnableCaching(false)
54+
checkFatal(t, err)
55+
56+
err = EnableCaching(true)
57+
checkFatal(t, err)
58+
}
59+
60+
func TestGetCachedMemory(t *testing.T) {
61+
current, allowed, err := GetCachedMemory()
62+
checkFatal(t, err)
63+
64+
if current < 0 {
65+
t.Fatal("current < 0")
66+
}
67+
68+
if allowed < 0 {
69+
t.Fatal("allowed < 0")
70+
}
71+
}
72+
73+
func TestSetCacheMaxSize(t *testing.T) {
74+
err := SetCacheMaxSize(0)
75+
checkFatal(t, err)
76+
77+
err = SetCacheMaxSize(1024 * 1024)
78+
checkFatal(t, err)
79+
80+
// revert to default 256MB
81+
err = SetCacheMaxSize(256 * 1024 * 1024)
82+
checkFatal(t, err)
83+
}

0 commit comments

Comments
 (0)