diff options
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | .travis.yml | 6 | ||||
| -rw-r--r-- | Makefile | 10 | ||||
| -rw-r--r-- | README.md | 9 | ||||
| -rw-r--r-- | branch.go | 1 | ||||
| -rw-r--r-- | git.go | 1 | ||||
| -rwxr-xr-x | script/build-libgit2-static.sh | 18 | ||||
| -rwxr-xr-x | script/build-libgit2.sh | 13 | ||||
| -rwxr-xr-x | script/with-static.sh | 11 | ||||
| -rw-r--r-- | settings.go (renamed from settings/settings.go) | 49 | ||||
| -rw-r--r-- | settings_test.go (renamed from settings/settings_test.go) | 26 | ||||
| m--------- | vendor/libgit2 | 0 |
12 files changed, 76 insertions, 71 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8eb5872 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/libgit2"] + path = vendor/libgit2 + url = https://github.com/libgit2/libgit2 diff --git a/.travis.yml b/.travis.yml index 5bc4f9f..27a1585 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,10 @@ language: go go: - - 1.0 - 1.1 - 1.2 - tip -install: - - script/build-libgit2.sh - - export PKG_CONFIG_PATH=$PWD/libgit2/install/lib/pkgconfig - - export LD_LIBRARY_PATH=$PWD/libgit2/install/lib - matrix: allow_failures: - go: tip diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4ecc8a4 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +default: test + +build-libgit2: + ./script/build-libgit2-static.sh + +test: build-libgit2 + ./script/with-static.sh go test ./... + +install: build-libgit2 + ./script/with-static.sh go install ./... @@ -6,7 +6,14 @@ Go bindings for [libgit2](http://libgit2.github.com/). These bindings are for to Installing ---------- -Just `go get github.com/libgit2/git2go`. You'll need to have top-of-the-branch libgit2 from development installed in your system and available via `pkg-config`. These bindings are in sync with the top of `development`. +This project needs libgit2, which is written in C so we need to build that as well. In order to build libgit2, you need `cmake`, `pkg-config` and a C compiler. You will also need the development packages for OpenSSL and LibSSH2 if you want to use HTTPS and SSH respectively. + +Run `go get github.com/libgit2/git2go` to download the code and go to your `$GOPATH/src/github.com/libgt2/git2go` dir. From there, we need to build the C code and put it into the resulting go binary. + + git submodule update --init # get libgit2 + make install + +will compile libgit2 and run `go install` such that it's statically linked to the git2go package. License ------- @@ -1,7 +1,6 @@ package git /* -#cgo pkg-config: libgit2 #include <git2.h> #include <git2/errors.h> */ @@ -1,7 +1,6 @@ package git /* -#cgo pkg-config: libgit2 #include <git2.h> #include <git2/errors.h> */ diff --git a/script/build-libgit2-static.sh b/script/build-libgit2-static.sh new file mode 100755 index 0000000..b4d4241 --- /dev/null +++ b/script/build-libgit2-static.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -ex + +VENDORED_PATH=vendor/libgit2 + +cd $VENDORED_PATH && +mkdir -p build && +cd build && +cmake -DTHREADSAFE=ON \ + -DBUILD_CLAR=OFF \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_C_FLAGS=-fPIC \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DCMAKE_INSTALL_PREFIX=../install \ + .. && + +cmake --build . diff --git a/script/build-libgit2.sh b/script/build-libgit2.sh deleted file mode 100755 index 8376a15..0000000 --- a/script/build-libgit2.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -set -ex - -git clone --depth 1 --single-branch git://github.com/libgit2/libgit2 libgit2 - -cd libgit2 -cmake -DTHREADSAFE=ON \ - -DBUILD_CLAR=OFF \ - -DCMAKE_INSTALL_PREFIX=$PWD/install \ - . - -make install diff --git a/script/with-static.sh b/script/with-static.sh new file mode 100755 index 0000000..0caed5e --- /dev/null +++ b/script/with-static.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -ex + +export BUILD="$PWD/vendor/libgit2/build" +export PCFILE="$BUILD/libgit2.pc" + +export CGO_LDFLAGS="$BUILD/libgit2.a -L$BUILD $(pkg-config --static --libs $PCFILE)" +export CGO_CFLAGS="-I$PWD/vendor/libgit2/include" + +$@ diff --git a/settings/settings.go b/settings.go index 6661c5d..c7f1850 100644 --- a/settings/settings.go +++ b/settings.go @@ -1,7 +1,6 @@ -package settings +package git /* -#cgo pkg-config: libgit2 #include <git2.h> int _go_git_opts_get_search_path(int level, git_buf *buf) @@ -23,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) @@ -51,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)) @@ -66,12 +59,28 @@ func SetSearchPath(level git.ConfigLevel, path string) error { 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 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); + err := C._go_git_opts_get_size_t(opt, &val) if err < 0 { return 0, MakeGitError(err) } @@ -84,26 +93,10 @@ func setSizet(opt C.int, val int) error { defer runtime.UnlockOSThread() cval := C.size_t(val) - err := C._go_git_opts_set_size_t(opt, cval); + 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) -} - -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) -} diff --git a/settings/settings_test.go b/settings_test.go index 55b08c8..3a4ce0a 100644 --- a/settings/settings_test.go +++ b/settings_test.go @@ -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) -} diff --git a/vendor/libgit2 b/vendor/libgit2 new file mode 160000 +Subproject 28f087c8642ff9c8dd6964e101e6d8539db6281 |
