Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ tmp/
repo/
build/
libgit2/
git2go/

.idea/
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
default: install

.PHONY: install
install: build_libgit2
install: build_libgit2 build_git2go
go install ./...

.PHONY: build_libgit2
build_libgit2:
./scripts/build_libgit2.sh

.PHONY: build_git2go
build_git2go:
./scripts/build_git2go.sh

.PHONY: build
build: clean
./scripts/build.sh
Expand All @@ -23,14 +27,14 @@ restore:

.PHONY: test
test: build_libgit2
go test -covermode=count ./e
go test -covermode=count ./lib
go test -covermode=count ./cmd
go test -covermode=count ./trie
go test -covermode=count ./intercept
go test -covermode=count ./graph
go test -covermode=count ./utils
go test -covermode=count .
go test -tags static,system_libgit2 -covermode=count ./e
go test -tags static,system_libgit2 -covermode=count ./lib
go test -tags static,system_libgit2 -covermode=count ./cmd
go test -tags static,system_libgit2 -covermode=count ./trie
go test -tags static,system_libgit2 -covermode=count ./intercept
go test -tags static,system_libgit2 -covermode=count ./graph
go test -tags static,system_libgit2 -covermode=count ./utils
go test -tags static,system_libgit2 -covermode=count .

.PHONY: showcover
showcover:
Expand Down
40 changes: 23 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
module github.com/mbtproject/mbt

go 1.15
go 1.23

replace github.com/libgit2/git2go/v34 => ./git2go

require (
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/libgit2/git2go/v34 v34.0.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.11.1
)

require (
github.com/cpuguy83/go-md2man v1.0.7
github.com/davecgh/go-spew v1.1.1
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/inconshreveable/mousetrap v1.0.0
github.com/libgit2/git2go/v28 v28.8.6
github.com/mattn/goveralls v0.0.7 // indirect
github.com/pmezard/go-difflib v1.0.0
github.com/russross/blackfriday v0.0.0-20170728175326-4048872b16cc
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
golang.org/x/tools v0.1.0 // indirect
gopkg.in/yaml.v2 v2.2.8
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/goveralls v0.0.12 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/tools v0.8.0 // indirect
golang.org/x/tools/cmd/cover v0.1.0-deprecated // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
124 changes: 84 additions & 40 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package lib
import (
"runtime"

git "github.com/libgit2/git2go/v28"
git "github.com/libgit2/git2go/v34"
"github.com/mbtproject/mbt/e"
)

Expand Down
4 changes: 2 additions & 2 deletions lib/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
"runtime"
"testing"

git "github.com/libgit2/git2go/v28"
git "github.com/libgit2/git2go/v34"
"github.com/mbtproject/mbt/e"
"github.com/stretchr/testify/assert"
)

//noinspection GoUnusedParameter
// noinspection GoUnusedParameter
func noopCb(a *Module, s CmdStage, err error) {}

func stdTestCmdOptions(buff *bytes.Buffer) *CmdOptions {
Expand Down
6 changes: 3 additions & 3 deletions lib/mbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"time"

yaml "github.com/go-yaml/yaml"
git "github.com/libgit2/git2go/v28"
git "github.com/libgit2/git2go/v34"
"github.com/mbtproject/mbt/e"
"github.com/mbtproject/mbt/intercept"
)
Expand Down Expand Up @@ -108,8 +108,8 @@ func (r *TestRepository) Commit(message string) error {
return err
}

err = idx.AddAll([]string{"."}, git.IndexAddCheckPathspec, func(p string, f string) int {
return 0
err = idx.AddAll([]string{"."}, git.IndexAddCheckPathspec, func(p string, f string) error {
return nil
})
if err != nil {
return err
Expand Down
9 changes: 5 additions & 4 deletions lib/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package lib
import (
"fmt"

git "github.com/libgit2/git2go/v28"
git "github.com/libgit2/git2go/v34"
"github.com/mbtproject/mbt/e"
)

Expand Down Expand Up @@ -206,7 +206,8 @@ func (r *libgitRepo) WalkBlobs(commit Commit, callback BlobWalkCallback) error {
walkErr error
)

err = tree.Walk(func(path string, entry *git.TreeEntry) int {
err = tree.Walk(func(path string, entry *git.TreeEntry) error {

if entry.Type == git.ObjectBlob {
b := &libgitBlob{
entry: entry,
Expand All @@ -215,10 +216,10 @@ func (r *libgitRepo) WalkBlobs(commit Commit, callback BlobWalkCallback) error {
}
walkErr = callback(b)
if walkErr != nil {
return -1
return walkErr
}
}
return 0
return nil
})

if walkErr != nil {
Expand Down
24 changes: 17 additions & 7 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,29 @@ lint() {

DIR=$(pwd)
LIBGIT2_PATH=$DIR/libgit2
GIT2GO_PATH=$DIR/git2go
OS=$(uname -s | awk '{print tolower($0)}')
ARCH=$(uname -m)

# Import libgit2
if [ ! -d libgit2 ]
then
./scripts/import_libgit2.sh
fi

# Build git2go
./scripts/build_git2go.sh

# Restore build dependencies
go get golang.org/x/tools/cmd/cover
go get github.com/mattn/goveralls

# Build libgit2
./scripts/build_libgit2.sh

# Set environment so to static link libgit2 when building git2go
export PKG_CONFIG_PATH="$LIBGIT2_PATH/build"
export CGO_LDFLAGS="$(pkg-config --libs --static $LIBGIT2_PATH/build/libgit2.pc)"
export PKG_CONFIG_PATH="$GIT2GO_PATH/static-build/build:$LIBGIT2_PATH/build"
export CGO_CFLAGS="-I$HOME/static/openssl/include -I$HOME/static/libssh2/include"
export CGO_LDFLAGS="$(pkg-config --libs --static $GIT2GO_PATH/static-build/build/libgit2.pc)"
export CGO_ENABLED=1


# All preparation is done at this point.
# Move on to building mbt
Expand Down Expand Up @@ -66,8 +76,8 @@ if [ ! -z $COVERALLS_TOKEN ] && [ -f ./coverage.out ]; then
$HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN
fi

go build -tags static,system_libgit2 -o "build/${OUT}"
shasum -a 1 -p "build/${OUT}" | cut -d ' ' -f 1 > "build/${OUT}.sha1"
go build -tags static,system_libgit2 -ldflags '-extldflags "-static"' -o "build/${OUT}"
shasum -a 1 -U "build/${OUT}" | cut -d ' ' -f 1 > "build/${OUT}.sha1"

# Run go vet (this should happen after the build)
go vet ./*.go
Expand Down
22 changes: 22 additions & 0 deletions scripts/build_git2go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -e

DIR=$(pwd)
GIT2GO_PATH=$DIR/git2go

# First ensure that git2go source tree is available
if [ ! -d git2go ]
then
./scripts/import_git2go.sh
fi

if [ ! -L $GIT2GO_PATH/vendor/libgit2 ]; then
rm -rf $GIT2GO_PATH/vendor/libgit2
ln -s $DIR/libgit2 $GIT2GO_PATH/vendor/libgit2
fi

cd $GIT2GO_PATH
make install-static

cd ${DIR}
22 changes: 21 additions & 1 deletion scripts/build_libgit2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ fi

mkdir -p $LIBGIT2_PATH



cd $HOME
wget https://www.openssl.org/source/openssl-3.3.2.tar.gz
tar xzf openssl-3.3.2.tar.gz
cd openssl-3.3.2
./Configure linux-x86_64 no-shared --prefix=$HOME/static/openssl
make -j$(nproc)
make install_sw
cd $HOME
wget https://www.libssh2.org/download/libssh2-1.11.0.tar.gz
tar xzf libssh2-1.11.0.tar.gz
cd libssh2-1.11.0
mkdir build && cd build
cmake .. -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=$HOME/static/libssh2 \
-DOPENSSL_ROOT_DIR=$HOME/static/openssl
cmake --build . --target install

cd $LIBGIT2_PATH
mkdir -p install/lib
mkdir -p build
Expand All @@ -22,8 +40,10 @@ cmake -DTHREADSAFE=ON \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_C_FLAGS=-fPIC \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_PREFIX_PATH="$HOME/static/openssl;$HOME/static/libssh2" \
-DCMAKE_INSTALL_PREFIX=../install \
-DUSE_SSH=OFF \
-DUSE_SSH=ON \
-DUSE_HTTPS=OpenSSL \
-DCURL=OFF \
..

Expand Down
24 changes: 24 additions & 0 deletions scripts/import_git2go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

#
# Use this utility to import git2go sources into the directory.
#

set -e

DIR="$(pwd)"
GIT2GO_PATH="$DIR/git2go"
GIT2GO_VERSION="v34.0.0"


if [ -d $GIT2GO_PATH ]; then
rm -rf $GIT2GO_PATH
fi

git clone https://github.com/libgit2/git2go.git $GIT2GO_PATH

cd $GIT2GO_PATH
git checkout $GIT2GO_VERSION

cd $DIR
rm -rf $GIT2GO_PATH/.git
5 changes: 2 additions & 3 deletions scripts/import_libgit2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ set -e

DIR="$(pwd)"
LIBGIT2_PATH="$DIR/libgit2"
LIBGIT2_VERSION="v0.28.5"

LIBGIT2_VERSION="v1.5.2"

if [ -d $LIBGIT2_PATH ]; then
rm -rf $LIBGIT2_PATH
Expand All @@ -21,4 +20,4 @@ cd $LIBGIT2_PATH
git checkout $LIBGIT2_VERSION

cd $DIR
rm -rf $LIBGIT2_PATH/.git
rm -rf $LIBGIT2_PATH/.git