Add DiffIgnoreWitespaceEol and deprecate DiffIgnoreWitespaceEol #774

Merged
zegl merged 6 commits from whitespace-typo into main 2021-09-04 15:54:21 -05:00
8 changed files with 176 additions and 106 deletions
Showing only changes of commit d24fd6c49a - Show all commits

View File

@ -2,7 +2,7 @@ name: Backport to older releases
on:
push:
branches:
- master
- main
jobs:

View File

@ -3,51 +3,17 @@ on:
pull_request:
push:
branches:
- master
- main
- release-*
- v*
jobs:
build-legacy:
strategy:
fail-fast: false
matrix:
go: [ '1.9', '1.10' ]
name: Go ${{ matrix.go }}
runs-on: ubuntu-18.04
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}
id: go
- name: Check out code into the GOPATH
uses: actions/checkout@v1
with:
fetch-depth: 1
path: src/github.com/${{ github.repository }}
- name: Build
env:
GOPATH: /home/runner/work/git2go
run: |
git submodule update --init
sudo apt-get install -y --no-install-recommends libssh2-1-dev
make build-libgit2-static
go get -tags static -t github.com/${{ github.repository }}/...
go build -tags static github.com/${{ github.repository }}/...
- name: Test
env:
GOPATH: /home/runner/work/git2go
run: make TEST_ARGS=-test.v test-static
build-static:
strategy:
fail-fast: false
matrix:
go: [ '1.11', '1.12', '1.13', '1.14', '1.15' ]
go: [ '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17' ]
name: Go ${{ matrix.go }}
runs-on: ubuntu-20.04
@ -79,7 +45,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.15'
go-version: '1.17'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
@ -104,7 +70,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.15'
go-version: '1.17'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
@ -127,7 +93,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.15'
go-version: '1.17'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1

View File

@ -2,7 +2,7 @@ name: Tag new releases
on:
push:
branches:
- master
- main
- release-*
jobs:

View File

@ -1,25 +0,0 @@
language: go
arch:
- AMD64
- ppc64le
go:
- tip
install:
- sudo apt-get install -y --no-install-recommends libssh2-1-dev
- make build-libgit2-static
- go get --tags "static" ./...
script:
- make test-static
git:
submodules: true
branches:
only:
- master
- /v\d+/
- /release-.*/

View File

@ -1,6 +1,6 @@
git2go
======
[![GoDoc](https://godoc.org/github.com/libgit2/git2go?status.svg)](http://godoc.org/github.com/libgit2/git2go) [![Build Status](https://travis-ci.org/libgit2/git2go.svg?branch=master)](https://travis-ci.org/libgit2/git2go)
[![GoDoc](https://godoc.org/github.com/libgit2/git2go?status.svg)](http://godoc.org/github.com/libgit2/git2go) [![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/).
@ -10,7 +10,7 @@ Due to the fact that Go 1.11 module versions have semantic meaning and don't nec
| libgit2 | git2go |
|---------|---------------|
| master | (will be v32) |
| main | (will be v32) |
| 1.1 | v31 |
| 1.0 | v30 |
| 0.99 | v29 |
@ -28,7 +28,7 @@ import "github.com/libgit2/git2go/v31"
which will ensure there are no sudden changes to the API.
The `master` branch follows the tip of libgit2 itself (with some lag) and as such has no guarantees on the stability of libgit2's API. Thus this only supports statically linking against libgit2.
The `main` branch follows the tip of libgit2 itself (with some lag) and as such has no guarantees on the stability of libgit2's API. Thus this only supports statically linking against libgit2.
### Which branch to send Pull requests to
@ -58,16 +58,16 @@ Follow the instructions for [Versioned branch, dynamic linking](#versioned-branc
go test -tags static,system_libgit2 github.com/my/project/...
go install -tags static,system_libgit2 github.com/my/project/...
### Master branch, or vendored static linking
### `main` branch, or vendored static linking
If using `master` or building a branch with the vendored libgit2 statically, we need to build libgit2 first. In order to build it, you need `cmake`, `pkg-config` and a C compiler. You will also need the development packages for OpenSSL (outside of Windows or macOS) and LibSSH2 installed if you want libgit2 to support HTTPS and SSH respectively. Note that even if libgit2 is included in the resulting binary, its dependencies will not be.
If using `main` or building a branch with the vendored libgit2 statically, we need to build libgit2 first. In order to build it, you need `cmake`, `pkg-config` and a C compiler. You will also need the development packages for OpenSSL (outside of Windows or macOS) and LibSSH2 installed if you want libgit2 to support HTTPS and SSH respectively. Note that even if libgit2 is included in the resulting binary, its dependencies will not be.
Run `go get -d github.com/libgit2/git2go` to download the code and go to your `$GOPATH/src/github.com/libgit2/git2go` directory. 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-static
will compile libgit2, link it into git2go and install it. The `master` branch is set up to follow the specific libgit2 version that is vendored, so trying dynamic linking may or may not work depending on the exact versions involved.
will compile libgit2, link it into git2go and install it. The `main` branch is set up to follow the specific libgit2 version that is vendored, so trying dynamic linking may or may not work depending on the exact versions involved.
In order to let Go pass the correct flags to `pkg-config`, `-tags static` needs to be passed to all `go` commands that build any binaries. For instance:
@ -87,7 +87,7 @@ libgit2 may use OpenSSL and LibSSH2 for performing encrypted network connections
Running the tests
-----------------
For the stable version, `go test` will work as usual. For the `master` branch, similarly to installing, running the tests requires building a local libgit2 library, so the Makefile provides a wrapper that makes sure it's built
For the stable version, `go test` will work as usual. For the `main` branch, similarly to installing, running the tests requires building a local libgit2 library, so the Makefile provides a wrapper that makes sure it's built
make test-static

View File

@ -12,6 +12,14 @@ import (
"unsafe"
)
// MessageEncoding is the encoding of commit messages.
type MessageEncoding string
const (
// MessageEncodingUTF8 is the default message encoding.
MessageEncodingUTF8 MessageEncoding = "UTF-8"
)
// Commit
type Commit struct {
Object
@ -67,40 +75,11 @@ func (c *Commit) WithSignatureUsing(f CommitSigningCallback) (*Oid, error) {
// WithSignature creates a new signed commit from the given signature and signature field
func (c *Commit) WithSignature(signature string, signatureField string) (*Oid, error) {
totalCommit := c.ContentToSign()
oid := new(Oid)
var csf *C.char = nil
if signatureField != "" {
csf = C.CString(signatureField)
defer C.free(unsafe.Pointer(csf))
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
cTotalCommit := C.CString(totalCommit)
cSignature := C.CString(signature)
defer C.free(unsafe.Pointer(cTotalCommit))
defer C.free(unsafe.Pointer(cSignature))
ret := C.git_commit_create_with_signature(
oid.toC(),
c.Owner().ptr,
cTotalCommit,
cSignature,
csf,
return c.Owner().CreateCommitWithSignature(
c.ContentToSign(),
signature,
signatureField,
)
runtime.KeepAlive(c)
runtime.KeepAlive(oid)
if ret < 0 {
return nil, MakeGitError(ret)
}
return oid, nil
}
func (c *Commit) ExtractSignature() (string, string, error) {

View File

@ -485,6 +485,102 @@ func (v *Repository) CreateCommit(
return oid, nil
}
// CreateCommitWithSignature creates a commit object from the given contents and
// signature.
func (v *Repository) CreateCommitWithSignature(
commitContent, signature, signatureField string,
) (*Oid, error) {
cCommitContent := C.CString(commitContent)
defer C.free(unsafe.Pointer(cCommitContent))
var cSignature *C.char
if signature != "" {
cSignature = C.CString(string(signature))
defer C.free(unsafe.Pointer(cSignature))
}
var cSignatureField *C.char
if signatureField != "" {
cSignatureField = C.CString(string(signatureField))
defer C.free(unsafe.Pointer(cSignatureField))
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
oid := new(Oid)
ret := C.git_commit_create_with_signature(oid.toC(), v.ptr, cCommitContent, cSignature, cSignatureField)
runtime.KeepAlive(v)
runtime.KeepAlive(oid)
if ret < 0 {
return nil, MakeGitError(ret)
}
return oid, nil
}
// CreateCommitBuffer creates a commit and write it into a buffer.
func (v *Repository) CreateCommitBuffer(
author, committer *Signature,
messageEncoding MessageEncoding,
message string,
tree *Tree,
parents ...*Commit,
) ([]byte, error) {
cmsg := C.CString(message)
defer C.free(unsafe.Pointer(cmsg))
var cencoding *C.char
// Since the UTF-8 encoding is the default, pass in nil whenever UTF-8 is
// provided. That will cause the commit to not have an explicit header for
// it.
if messageEncoding != MessageEncodingUTF8 && messageEncoding != MessageEncoding("") {
cencoding = C.CString(string(messageEncoding))
defer C.free(unsafe.Pointer(cencoding))
}
var cparents []*C.git_commit = nil
var parentsarg **C.git_commit = nil
nparents := len(parents)
if nparents > 0 {
cparents = make([]*C.git_commit, nparents)
for i, v := range parents {
cparents[i] = v.cast_ptr
}
parentsarg = &cparents[0]
}
authorSig, err := author.toC()
if err != nil {
return nil, err
}
defer C.git_signature_free(authorSig)
committerSig, err := committer.toC()
if err != nil {
return nil, err
}
defer C.git_signature_free(committerSig)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var buf C.git_buf
defer C.git_buf_dispose(&buf)
ret := C.git_commit_create_buffer(
&buf, v.ptr,
authorSig, committerSig,
cencoding, cmsg, tree.cast_ptr, C.size_t(nparents), parentsarg)
runtime.KeepAlive(v)
runtime.KeepAlive(buf)
runtime.KeepAlive(parents)
if ret < 0 {
return nil, MakeGitError(ret)
}
return C.GoBytes(unsafe.Pointer(buf.ptr), C.int(buf.size)), nil
}
func (v *Repository) CreateCommitFromIds(
refname string, author, committer *Signature,
message string, tree *Oid, parents ...*Oid) (*Oid, error) {

View File

@ -5,6 +5,60 @@ import (
"time"
)
func TestCreateCommitBuffer(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
loc, err := time.LoadLocation("Europe/Berlin")
checkFatal(t, err)
sig := &Signature{
Name: "Rand Om Hacker",
Email: "random@hacker.com",
When: time.Date(2013, 03, 06, 14, 30, 0, 0, loc),
}
idx, err := repo.Index()
checkFatal(t, err)
err = idx.AddByPath("README")
checkFatal(t, err)
err = idx.Write()
checkFatal(t, err)
treeId, err := idx.WriteTree()
checkFatal(t, err)
message := "This is a commit\n"
tree, err := repo.LookupTree(treeId)
checkFatal(t, err)
for encoding, expected := range map[MessageEncoding]string{
MessageEncodingUTF8: `tree b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e
author Rand Om Hacker <random@hacker.com> 1362576600 +0100
committer Rand Om Hacker <random@hacker.com> 1362576600 +0100
This is a commit
`,
MessageEncoding("ASCII"): `tree b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e
author Rand Om Hacker <random@hacker.com> 1362576600 +0100
committer Rand Om Hacker <random@hacker.com> 1362576600 +0100
encoding ASCII
This is a commit
`,
} {
encoding := encoding
expected := expected
t.Run(string(encoding), func(t *testing.T) {
buf, err := repo.CreateCommitBuffer(sig, sig, encoding, message, tree)
checkFatal(t, err)
if expected != string(buf) {
t.Errorf("mismatched commit buffer, expected %v, got %v", expected, string(buf))
}
})
}
}
func TestCreateCommitFromIds(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)