From 6eae74c128e37e590d3a5da3fe0561add4b94d5c Mon Sep 17 00:00:00 2001 From: lhchavez Date: Thu, 14 Oct 2021 04:42:42 -0700 Subject: [PATCH 1/7] libgit2 v1.3.0 #major (#840) This commit introduces libgit2 v1.3.0 to git2go, which brings a large number of [bugfixes and features](https://github.com/libgit2/libgit2/releases/tag/v1.3.0). This also marks the start of the v33 release. --- .github/workflows/backport.yml | 2 +- .github/workflows/ci.yml | 2 +- Build_bundled_static.go | 4 ++-- Build_system_dynamic.go | 4 ++-- Build_system_static.go | 4 ++-- README.md | 13 +++++++------ go.mod | 2 +- vendor/libgit2 | 2 +- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 9f18fac..c0b0d9e 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - branch: [ 'release-1.1', 'release-1.0', 'release-0.28', 'release-0.27' ] + branch: [ 'release-1.2', 'release-1.1', 'release-1.0', 'release-0.28', 'release-0.27' ] runs-on: ubuntu-20.04 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50e5e14..5ab1b48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: fail-fast: false matrix: libgit2: - - '109b4c887ffb63962c7017a66fc4a1f48becb48e' # v1.2.0 with a fixed symbol + - 'v1.3.0' name: Go (system-wide, dynamic) runs-on: ubuntu-20.04 diff --git a/Build_bundled_static.go b/Build_bundled_static.go index 09ed0f5..d9b3713 100644 --- a/Build_bundled_static.go +++ b/Build_bundled_static.go @@ -10,8 +10,8 @@ package git #cgo CFLAGS: -DLIBGIT2_STATIC #include -#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 2 || LIBGIT2_VER_MINOR > 2 -# error "Invalid libgit2 version; this git2go supports libgit2 between v1.2.0 and v1.2.0" +#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 3 || LIBGIT2_VER_MINOR > 3 +# error "Invalid libgit2 version; this git2go supports libgit2 between v1.3.0 and v1.3.0" #endif */ import "C" diff --git a/Build_system_dynamic.go b/Build_system_dynamic.go index 9500188..a8e6942 100644 --- a/Build_system_dynamic.go +++ b/Build_system_dynamic.go @@ -8,8 +8,8 @@ package git #cgo CFLAGS: -DLIBGIT2_DYNAMIC #include -#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 2 || LIBGIT2_VER_MINOR > 2 -# error "Invalid libgit2 version; this git2go supports libgit2 between v1.2.0 and v1.2.0" +#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 3 || LIBGIT2_VER_MINOR > 3 +# error "Invalid libgit2 version; this git2go supports libgit2 between v1.3.0 and v1.3.0" #endif */ import "C" diff --git a/Build_system_static.go b/Build_system_static.go index 309369d..a96894f 100644 --- a/Build_system_static.go +++ b/Build_system_static.go @@ -8,8 +8,8 @@ package git #cgo CFLAGS: -DLIBGIT2_STATIC #include -#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 2 || LIBGIT2_VER_MINOR > 2 -# error "Invalid libgit2 version; this git2go supports libgit2 between v1.2.0 and v1.2.0" +#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 3 || LIBGIT2_VER_MINOR > 3 +# error "Invalid libgit2 version; this git2go supports libgit2 between v1.3.0 and v1.3.0" #endif */ import "C" diff --git a/README.md b/README.md index 7cc36eb..8c4b811 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ Due to the fact that Go 1.11 module versions have semantic meaning and don't nec | libgit2 | git2go | |---------|---------------| -| main | (will be v33) | +| main | (will be v34) | +| 1.3 | v33 | | 1.2 | v32 | | 1.1 | v31 | | 1.0 | v30 | @@ -18,13 +19,13 @@ Due to the fact that Go 1.11 module versions have semantic meaning and don't nec | 0.28 | v28 | | 0.27 | v27 | -You can import them in your project with the version's major number as a suffix. For example, if you have libgit2 v1.2 installed, you'd import git2go v32 with: +You can import them in your project with the version's major number as a suffix. For example, if you have libgit2 v1.2 installed, you'd import git2go v33 with: ```sh -go get github.com/libgit2/git2go/v32 +go get github.com/libgit2/git2go/v33 ``` ```go -import "github.com/libgit2/git2go/v32" +import "github.com/libgit2/git2go/v33" ``` which will ensure there are no sudden changes to the API. @@ -48,7 +49,7 @@ This project wraps the functionality provided by libgit2. If you're using a vers When linking dynamically against a released version of libgit2, install it via your system's package manager. CGo will take care of finding its pkg-config file and set up the linking. Import via Go modules, e.g. to work against libgit2 v1.2 ```go -import "github.com/libgit2/git2go/v32" +import "github.com/libgit2/git2go/v33" ``` ### Versioned branch, static linking @@ -78,7 +79,7 @@ In order to let Go pass the correct flags to `pkg-config`, `-tags static` needs One thing to take into account is that since Go expects the `pkg-config` file to be within the same directory where `make install-static` was called, so the `go.mod` file may need to have a [`replace` directive](https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive) so that the correct setup is achieved. So if `git2go` is checked out at `$GOPATH/src/github.com/libgit2/git2go` and your project at `$GOPATH/src/github.com/my/project`, the `go.mod` file of `github.com/my/project` might need to have a line like - replace github.com/libgit2/git2go/v32 ../../libgit2/git2go + replace github.com/libgit2/git2go/v33 ../../libgit2/git2go Parallelism and network operations ---------------------------------- diff --git a/go.mod b/go.mod index db1ea19..c8028ef 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/libgit2/git2go/v32 +module github.com/libgit2/git2go/v33 go 1.13 diff --git a/vendor/libgit2 b/vendor/libgit2 index 109b4c8..b7bad55 160000 --- a/vendor/libgit2 +++ b/vendor/libgit2 @@ -1 +1 @@ -Subproject commit 109b4c887ffb63962c7017a66fc4a1f48becb48e +Subproject commit b7bad55e4bb0a285b073ba5e02b01d3f522fc95d -- 2.45.2 From f633706986ffe58471b3453531f81a08ecdabfd4 Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 14 Oct 2021 18:02:04 +0300 Subject: [PATCH 2/7] Generate stringer files automatically Added `stringer` annotations to `git.go` for `ErrorClass` and `ErrorCode`. Added `generate` rule for `Makefile` to generate string representations for these types (first building cgo files in `_obj` dir to get C constants). Finally, updated `ci` actions workflow to check that generated files are up to date. Ticket: #543 --- .github/workflows/ci.yml | 16 ++++++++++++++++ Makefile | 14 ++++++++++++++ git.go | 2 ++ 3 files changed, 32 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50e5e14..0edadb2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,3 +105,19 @@ jobs: sudo ./script/build-libgit2.sh --static --system - name: Test run: go test --count=1 --tags "static,system_libgit2" ./... + + check-generate: + name: Check generated files were not modified + runs-on: ubuntu-20.04 + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: '1.17' + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Generate files + run: make generate + - name: Check nothing changed + run: git diff --quiet --exit-code || (echo "detected changes after generate" && exit 1) diff --git a/Makefile b/Makefile index 84262f4..f887648 100644 --- a/Makefile +++ b/Makefile @@ -53,3 +53,17 @@ test-static: static-build/install/lib/libgit2.a install-static: static-build/install/lib/libgit2.a go install --tags "static" ./... + +define _gen_file + rm -fr _obj + go tool cgo $(1) + find ./_obj -type f ! -name '*.go' -exec rm {} \; + mv ./_obj/_cgo_gotypes.go ./_obj/cgo_gotypes.go + cd ./_obj && go generate ./... + find ./_obj -type f -name '*_string.go' -exec mv -v {} . \; + rm -fr ./_obj +endef + +generate: + $(call _gen_file,diff.go) + $(call _gen_file,git.go) diff --git a/git.go b/git.go index 383c492..b7c8b3c 100644 --- a/git.go +++ b/git.go @@ -14,6 +14,7 @@ import ( "unsafe" ) +//go:generate stringer -type ErrorClass -trimprefix ErrorClass -tags static type ErrorClass int const ( @@ -48,6 +49,7 @@ const ( ErrorClassPatch ErrorClass = C.GIT_ERROR_PATCH ) +//go:generate stringer -type ErrorCode -trimprefix ErrorCode -tags static type ErrorCode int const ( -- 2.45.2 From 67bd1b00f668198e1527331c3c3a8bfc3e9de350 Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 8 Nov 2021 11:19:55 +0300 Subject: [PATCH 3/7] Show status on stringer check Apply review comments about stringer workflow steps Co-authored-by: lhchavez --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0edadb2..8a8adf3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,4 +120,4 @@ jobs: - name: Generate files run: make generate - name: Check nothing changed - run: git diff --quiet --exit-code || (echo "detected changes after generate" && exit 1) + run: git diff --quiet --exit-code || (echo "detected changes after generate" ; git status ; exit 1) -- 2.45.2 From 0cbbc1dc99237cde8931b33eb5be85213eb4a235 Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 8 Nov 2021 17:08:10 +0300 Subject: [PATCH 4/7] Update .github/workflows/ci.yml Review fixes for workflow Co-authored-by: lhchavez --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a8adf3..a929f93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -117,6 +117,10 @@ jobs: id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 + - name: Install libgit2 build dependencies + run: | + git submodule update --init + sudo apt-get install -y --no-install-recommends libssh2-1-dev - name: Generate files run: make generate - name: Check nothing changed -- 2.45.2 From 0e14c5c3cde537620ee5b340bab205cfa5b9edfb Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 8 Nov 2021 17:09:24 +0300 Subject: [PATCH 5/7] Fixed generate makefile target --- Makefile | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index f887648..71c5ee0 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,10 @@ TEST_ARGS ?= --count=1 default: test + +generate: static-build/install/lib/libgit2.a + go generate --tags "static" ./... + # System library # ============== # This uses whatever version of libgit2 can be found in the system. @@ -53,17 +57,3 @@ test-static: static-build/install/lib/libgit2.a install-static: static-build/install/lib/libgit2.a go install --tags "static" ./... - -define _gen_file - rm -fr _obj - go tool cgo $(1) - find ./_obj -type f ! -name '*.go' -exec rm {} \; - mv ./_obj/_cgo_gotypes.go ./_obj/cgo_gotypes.go - cd ./_obj && go generate ./... - find ./_obj -type f -name '*_string.go' -exec mv -v {} . \; - rm -fr ./_obj -endef - -generate: - $(call _gen_file,diff.go) - $(call _gen_file,git.go) -- 2.45.2 From a64e4a1a75ab043f0578ea14922cdc4fd1ba6196 Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 8 Nov 2021 17:29:12 +0300 Subject: [PATCH 6/7] Update .github/workflows/ci.yml Co-authored-by: lhchavez --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a929f93..c613e3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,6 +121,7 @@ jobs: run: | git submodule update --init sudo apt-get install -y --no-install-recommends libssh2-1-dev + go install golang.org/x/tools/cmd/stringer@latest - name: Generate files run: make generate - name: Check nothing changed -- 2.45.2 From 9c737a6d50a84f16b4387ddd109ef0fbf4a49b5c Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 8 Nov 2021 17:34:55 +0300 Subject: [PATCH 7/7] ci: export GOPATH --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c613e3c..53f0705 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,6 +123,8 @@ jobs: sudo apt-get install -y --no-install-recommends libssh2-1-dev go install golang.org/x/tools/cmd/stringer@latest - name: Generate files - run: make generate + run: | + export PATH=$(go env GOPATH)/bin:$PATH + make generate - name: Check nothing changed run: git diff --quiet --exit-code || (echo "detected changes after generate" ; git status ; exit 1) -- 2.45.2