libgit2 v1.5.0 #major

This commit introduces libgit2 v1.5.0-alpha to git2go, which brings a
large number of bugfixes and features.

This also marks the start of the v34 release.
This commit is contained in:
lhchavez 2022-04-14 06:49:59 -07:00
parent 7bff4ca7ad
commit f9ce9bd628
10 changed files with 72 additions and 25 deletions

View File

@ -62,7 +62,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
libgit2: libgit2:
- 'v1.3.1' - '1d88605ca9d51f9e8695030853d5914743fbb091'
name: Go (system-wide, dynamic) name: Go (system-wide, dynamic)
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04

View File

@ -10,8 +10,8 @@ package git
#cgo CFLAGS: -DLIBGIT2_STATIC #cgo CFLAGS: -DLIBGIT2_STATIC
#include <git2.h> #include <git2.h>
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 3 || LIBGIT2_VER_MINOR > 3 #if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5
# error "Invalid libgit2 version; this git2go supports libgit2 between v1.3.0 and v1.3.0" # error "Invalid libgit2 version; this git2go supports libgit2 between v1.5.0 and v1.5.0"
#endif #endif
*/ */
import "C" import "C"

View File

@ -8,8 +8,8 @@ package git
#cgo CFLAGS: -DLIBGIT2_DYNAMIC #cgo CFLAGS: -DLIBGIT2_DYNAMIC
#include <git2.h> #include <git2.h>
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 3 || LIBGIT2_VER_MINOR > 3 #if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5
# error "Invalid libgit2 version; this git2go supports libgit2 between v1.3.0 and v1.3.0" # error "Invalid libgit2 version; this git2go supports libgit2 between v1.5.0 and v1.5.0"
#endif #endif
*/ */
import "C" import "C"

View File

@ -8,8 +8,8 @@ package git
#cgo CFLAGS: -DLIBGIT2_STATIC #cgo CFLAGS: -DLIBGIT2_STATIC
#include <git2.h> #include <git2.h>
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 3 || LIBGIT2_VER_MINOR > 3 #if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5
# error "Invalid libgit2 version; this git2go supports libgit2 between v1.3.0 and v1.3.0" # error "Invalid libgit2 version; this git2go supports libgit2 between v1.5.0 and v1.5.0"
#endif #endif
*/ */
import "C" import "C"

View File

@ -1,6 +1,6 @@
git2go git2go
====== ======
[![GoDoc](https://godoc.org/github.com/libgit2/git2go?status.svg)](http://godoc.org/github.com/libgit2/git2go/v33) [![Build Status](https://travis-ci.org/libgit2/git2go.svg?branch=main)](https://travis-ci.org/libgit2/git2go) [![GoDoc](https://godoc.org/github.com/libgit2/git2go?status.svg)](http://godoc.org/github.com/libgit2/git2go/v34) [![Build Status](https://travis-ci.org/libgit2/git2go.svg?branch=main)](https://travis-ci.org/libgit2/git2go)
Go bindings for [libgit2](http://libgit2.github.com/). Go bindings for [libgit2](http://libgit2.github.com/).
@ -10,7 +10,8 @@ Due to the fact that Go 1.11 module versions have semantic meaning and don't nec
| libgit2 | git2go | | libgit2 | git2go |
|---------|---------------| |---------|---------------|
| main | (will be v34) | | main | (will be v35) |
| 1.4 | v34 |
| 1.3 | v33 | | 1.3 | v33 |
| 1.2 | v32 | | 1.2 | v32 |
| 1.1 | v31 | | 1.1 | v31 |
@ -19,13 +20,13 @@ Due to the fact that Go 1.11 module versions have semantic meaning and don't nec
| 0.28 | v28 | | 0.28 | v28 |
| 0.27 | v27 | | 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 v33 with: You can import them in your project with the version's major number as a suffix. For example, if you have libgit2 v1.4 installed, you'd import git2go v34 with:
```sh ```sh
go get github.com/libgit2/git2go/v33 go get github.com/libgit2/git2go/v34
``` ```
```go ```go
import "github.com/libgit2/git2go/v33" import "github.com/libgit2/git2go/v34"
``` ```
which will ensure there are no sudden changes to the API. which will ensure there are no sudden changes to the API.
@ -46,10 +47,10 @@ This project wraps the functionality provided by libgit2. If you're using a vers
### Versioned branch, dynamic linking ### Versioned branch, dynamic linking
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 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.4
```go ```go
import "github.com/libgit2/git2go/v33" import "github.com/libgit2/git2go/v34"
``` ```
### Versioned branch, static linking ### Versioned branch, static linking
@ -79,7 +80,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 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/v33 => ../../libgit2/git2go replace github.com/libgit2/git2go/v34 => ../../libgit2/git2go
Parallelism and network operations Parallelism and network operations
---------------------------------- ----------------------------------

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/libgit2/git2go/v33 module github.com/libgit2/git2go/v34
go 1.13 go 1.13

View File

@ -38,17 +38,17 @@ func registerManagedHTTP() error {
func httpSmartSubtransportFactory(remote *Remote, transport *Transport) (SmartSubtransport, error) { func httpSmartSubtransportFactory(remote *Remote, transport *Transport) (SmartSubtransport, error) {
var proxyFn func(*http.Request) (*url.URL, error) var proxyFn func(*http.Request) (*url.URL, error)
proxyOpts, err := transport.SmartProxyOptions() connectOpts, err := transport.SmartRemoteConnectOptions()
if err != nil { if err != nil {
return nil, err return nil, err
} }
switch proxyOpts.Type { switch connectOpts.ProxyOpts.Type {
case ProxyTypeNone: case ProxyTypeNone:
proxyFn = nil proxyFn = nil
case ProxyTypeAuto: case ProxyTypeAuto:
proxyFn = http.ProxyFromEnvironment proxyFn = http.ProxyFromEnvironment
case ProxyTypeSpecified: case ProxyTypeSpecified:
parsedUrl, err := url.Parse(proxyOpts.Url) parsedUrl, err := url.Parse(connectOpts.ProxyOpts.Url)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -177,6 +177,49 @@ func proxyOptionsFromC(copts *C.git_proxy_options) *ProxyOptions {
} }
} }
// RemoteRedirect are remote redirection settings; whether redirects to another
// host are permitted. By default, git will follow a redirect on the initial
// request (`/info/refs`), but not subsequent requests.
type RemoteRedirect uint32
const (
// RemoteRedirectNone makes remote operations not follow any off-site redirects at any stage of
// the fetch or push.
RemoteRedirectNone RemoteRedirect = C.GIT_REMOTE_REDIRECT_NONE
// RemoteRedirectInitial allows off-site redirects only upon the initial request.
// This is the default.
RemoteRedirectInitial RemoteRedirect = C.GIT_REMOTE_REDIRECT_INITIAL
// RemoteRedirectAll allows redirects at any stage in the fetch or push.
RemoteRedirectAll RemoteRedirect = C.GIT_REMOTE_REDIRECT_ALL
)
// RemoteConnectOptions is the remote creation options structure.
type RemoteConnectOptions struct {
// Callbacks are the callbacks to use for this connection.
Callbacks RemoteCallbacks
// ProxyOpts are the HTTP proxy settings.
ProxyOpts ProxyOptions
// FollowRedirects determines whether to allow off-site redirects. If this
// is not specified, the `http.followRedirects` configuration setting will be
// consulted.
FollowRedirects RemoteRedirect
// CustomHeaders are extra HTTP headers to use in this connection.
CustomHeaders []string
}
func remoteConnectOptionsFromC(copts *C.git_remote_connect_options) *RemoteConnectOptions {
return &RemoteConnectOptions{
ProxyOpts: *proxyOptionsFromC(&copts.proxy_opts),
FollowRedirects: RemoteRedirect(copts.follow_redirects),
CustomHeaders: makeStringsFromCStrings(copts.custom_headers.strings, int(copts.custom_headers.count)),
}
}
type Remote struct { type Remote struct {
doNotCompare doNotCompare
ptr *C.git_remote ptr *C.git_remote

View File

@ -4,6 +4,7 @@ package git
#include <string.h> #include <string.h>
#include <git2.h> #include <git2.h>
#include <git2/sys/remote.h>
#include <git2/sys/transport.h> #include <git2/sys/transport.h>
typedef struct { typedef struct {
@ -84,17 +85,19 @@ type Transport struct {
ptr *C.git_transport ptr *C.git_transport
} }
// SmartProxyOptions gets a copy of the proxy options for this transport. // SmartRemoteConnectOptions gets a copy of the connection options for this transport.
func (t *Transport) SmartProxyOptions() (*ProxyOptions, error) { func (t *Transport) SmartRemoteConnectOptions() (*RemoteConnectOptions, error) {
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
var cpopts C.git_proxy_options var copts C.git_remote_connect_options
if ret := C.git_transport_smart_proxy_options(&cpopts, t.ptr); ret < 0 { if ret := C.git_transport_smart_remote_connect_options(&copts, t.ptr); ret < 0 {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
opts := remoteConnectOptionsFromC(&copts)
C.git_remote_connect_options_dispose(&copts)
return proxyOptionsFromC(&cpopts), nil return opts, nil
} }
// SmartCredentials calls the credentials callback for this transport. // SmartCredentials calls the credentials callback for this transport.

2
vendor/libgit2 vendored

@ -1 +1 @@
Subproject commit 1f5e7f9add5c8bbc602b14feaec216c8877c3c84 Subproject commit 1d88605ca9d51f9e8695030853d5914743fbb091