Move the settings into the main git2go

This commit is contained in:
Carlos Martín Nieto 2014-06-07 18:33:09 +02:00
parent aabeb7f585
commit 12a3a1e05c
4 changed files with 36 additions and 74 deletions

View File

@ -2,12 +2,9 @@ default: test
build-libgit2:
./script/build-libgit2-static.sh
cat ./vendor/libgit2/libgit2.pc
cat ./vendor/install/lib/pkgconfig/libgit2.pc
test: install build-libgit2
./script/with-static.sh go test
./script/with-less-static.sh go test ./settings
test: build-libgit2
./script/with-static.sh go test ./...
install: build-libgit2
./script/with-static.sh go install ./...

View File

@ -1,13 +0,0 @@
#!/bin/sh
set -ex
export INSTALL_LOCATION=$PWD/vendor/install
export PKG_CONFIG_PATH=$INSTALL_LOCATION/lib/pkgconfig
export PCFILE="$PWD/vendor/libgit2/libgit2.pc"
export CGO_LDFLAGS="$(pkg-config --static --libs $PCFILE)"
export CGO_CFLAGS="$(pkg-config --static --cflags $PCFILE)"
$@

View File

@ -1,4 +1,4 @@
package settings
package git
/*
#include <git2.h>
@ -22,20 +22,14 @@ int _go_git_opts_get_size_t(int opt, size_t *val)
{
return git_libgit2_opts(opt, val);
}
*/
import "C"
import (
"runtime"
"unsafe"
"github.com/libgit2/git2go"
)
func MakeGitError(err C.int) error {
return git.MakeGitError2(int(err))
}
func SearchPath(level git.ConfigLevel) (string, error) {
func SearchPath(level ConfigLevel) (string, error) {
var buf C.git_buf
defer C.git_buf_free(&buf)
@ -50,7 +44,7 @@ func SearchPath(level git.ConfigLevel) (string, error) {
return C.GoString(buf.ptr), nil
}
func SetSearchPath(level git.ConfigLevel, path string) error {
func SetSearchPath(level ConfigLevel, path string) error {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
@ -65,32 +59,6 @@ func SetSearchPath(level git.ConfigLevel, path string) error {
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 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
}
func MwindowSize() (int, error) {
return getSizet(C.GIT_OPT_GET_MWINDOW_SIZE)
}
@ -106,3 +74,29 @@ func MwindowMappedLimit() (int, error) {
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
}

View File

@ -1,21 +1,19 @@
package settings
package git
import (
"testing"
"runtime"
"github.com/libgit2/git2go"
)
type pathPair struct {
Level git.ConfigLevel
Level ConfigLevel
Path string
}
func TestSearchPath(t *testing.T) {
paths := []pathPair{
pathPair{git.ConfigLevelSystem, "/tmp/system"},
pathPair{git.ConfigLevelGlobal, "/tmp/global"},
pathPair{git.ConfigLevelXDG, "/tmp/xdg"},
pathPair{ConfigLevelSystem, "/tmp/system"},
pathPair{ConfigLevelGlobal, "/tmp/global"},
pathPair{ConfigLevelXDG, "/tmp/xdg"},
}
for _, pair := range paths {
@ -50,17 +48,3 @@ func TestMmapSizes(t *testing.T) {
t.Fatal("Sizes don't match")
}
}
func checkFatal(t *testing.T, err error) {
if err == nil {
return
}
// The failure happens at wherever we were called, not here
_, file, line, ok := runtime.Caller(1)
if !ok {
t.Fatal()
}
t.Fatalf("Fail at %v:%v; %v", file, line, err)
}