Merge remote-tracking branch 'upstream/master' into next

This commit is contained in:
Carlos Martín Nieto 2016-08-27 21:07:44 +02:00
commit aadd0c2035
34 changed files with 209 additions and 17 deletions

View File

@ -10,6 +10,8 @@ go:
- 1.3
- 1.4
- 1.5
- 1.6
- 1.7
- tip
matrix:

View File

@ -1,11 +1,8 @@
default: test
build-libgit2:
./script/build-libgit2-static.sh
test: build-libgit2
test:
go run script/check-MakeGitError-thread-lock.go
./script/with-static.sh go test ./...
go test ./...
install: build-libgit2
./script/with-static.sh go install ./...
install:
go install ./...

View File

@ -6,6 +6,7 @@ import (
)
func TestBlame(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

17
blob.go
View File

@ -35,15 +35,24 @@ func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
defer runtime.UnlockOSThread()
var id C.git_oid
var ptr unsafe.Pointer
var size C.size_t
// Go 1.6 added some increased checking of passing pointer to
// C, but its check depends on its expectations of waht we
// pass to the C function, so unless we take the address of
// its contents at the call site itself, it can fail when
// 'data' is a slice of a slice.
//
// When we're given an empty slice, create a dummy one where 0
// isn't out of bounds.
if len(data) > 0 {
ptr = unsafe.Pointer(&data[0])
size = C.size_t(len(data))
} else {
ptr = unsafe.Pointer(nil)
data = []byte{0}
size = C.size_t(0)
}
ecode := C.git_blob_create_frombuffer(&id, repo.ptr, ptr, C.size_t(len(data)))
ecode := C.git_blob_create_frombuffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size)
if ecode < 0 {
return nil, MakeGitError(ecode)
}

View File

@ -1,10 +1,23 @@
package git
import (
"bytes"
"testing"
)
type bufWrapper struct {
buf [64]byte
pointer []byte
}
func doublePointerBytes() []byte {
o := &bufWrapper{}
o.pointer = o.buf[0:10]
return o.pointer[0:1]
}
func TestCreateBlobFromBuffer(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -14,4 +27,16 @@ func TestCreateBlobFromBuffer(t *testing.T) {
if id.String() != "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" {
t.Fatal("Empty buffer did not deliver empty blob id")
}
for _, data := range []([]byte){[]byte("hello there"), doublePointerBytes()} {
id, err = repo.CreateBlobFromBuffer(data)
checkFatal(t, err)
blob, err := repo.LookupBlob(id)
checkFatal(t, err)
if !bytes.Equal(blob.Contents(), data) {
t.Fatal("Loaded bytes don't match original bytes:",
blob.Contents(), "!=", data)
}
}
}

View File

@ -13,6 +13,7 @@ import (
type BranchType uint
const (
BranchAll BranchType = C.GIT_BRANCH_ALL
BranchLocal BranchType = C.GIT_BRANCH_LOCAL
BranchRemote BranchType = C.GIT_BRANCH_REMOTE
)

View File

@ -5,6 +5,7 @@ import (
)
func TestBranchIterator(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -27,6 +28,7 @@ func TestBranchIterator(t *testing.T) {
}
func TestBranchIteratorEach(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -33,6 +33,7 @@ func readReadme(t *testing.T, repo *Repository) string {
}
func TestCherrypick(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -10,6 +10,7 @@ const (
)
func TestClone(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -35,6 +36,7 @@ func TestClone(t *testing.T) {
}
func TestCloneWithCallback(t *testing.T) {
t.Parallel()
testPayload := 0
repo := createTestRepo(t)

View File

@ -88,6 +88,7 @@ var tests = []TestRunner{
}
func TestConfigLookups(t *testing.T) {
t.Parallel()
var (
err error
c *Config

View File

@ -8,6 +8,7 @@ import (
)
func TestDescribeCommit(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

57
diff.go
View File

@ -220,6 +220,33 @@ func (stats *DiffStats) FilesChanged() int {
return int(C.git_diff_stats_files_changed(stats.ptr))
}
type DiffStatsFormat int
const (
DiffStatsNone DiffStatsFormat = C.GIT_DIFF_STATS_NONE
DiffStatsFull DiffStatsFormat = C.GIT_DIFF_STATS_FULL
DiffStatsShort DiffStatsFormat = C.GIT_DIFF_STATS_SHORT
DiffStatsNumber DiffStatsFormat = C.GIT_DIFF_STATS_NUMBER
DiffStatsIncludeSummary DiffStatsFormat = C.GIT_DIFF_STATS_INCLUDE_SUMMARY
)
func (stats *DiffStats) String(format DiffStatsFormat,
width uint) (string, error) {
buf := C.git_buf{}
defer C.git_buf_free(&buf)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_diff_stats_to_buf(&buf,
stats.ptr, C.git_diff_stats_format_t(format), C.size_t(width))
if ret < 0 {
return "", MakeGitError(ret)
}
return C.GoString(buf.ptr), nil
}
func (diff *Diff) Stats() (*DiffStats, error) {
stats := new(DiffStats)
@ -626,6 +653,36 @@ func (v *Repository) DiffTreeToWorkdir(oldTree *Tree, opts *DiffOptions) (*Diff,
return newDiffFromC(diffPtr), nil
}
func (v *Repository) DiffTreeToIndex(oldTree *Tree, index *Index, opts *DiffOptions) (*Diff, error) {
var diffPtr *C.git_diff
var oldPtr *C.git_tree
var indexPtr *C.git_index
if oldTree != nil {
oldPtr = oldTree.cast_ptr
}
if index != nil {
indexPtr = index.ptr
}
copts, notifyData := diffOptionsToC(opts)
defer freeDiffOptions(copts)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_diff_tree_to_index(&diffPtr, v.ptr, oldPtr, indexPtr, copts)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
if notifyData != nil && notifyData.Diff != nil {
return notifyData.Diff, nil
}
return newDiffFromC(diffPtr), nil
}
func (v *Repository) DiffTreeToWorkdirWithIndex(oldTree *Tree, opts *DiffOptions) (*Diff, error) {
var diffPtr *C.git_diff
var oldPtr *C.git_tree

View File

@ -7,6 +7,7 @@ import (
)
func TestFindSimilar(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -61,7 +62,7 @@ func TestFindSimilar(t *testing.T) {
}
func TestDiffTreeToTree(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -189,6 +190,7 @@ func createTestTrees(t *testing.T, repo *Repository) (originalTree *Tree, newTre
}
func TestDiffBlobs(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

6
git.go
View File

@ -3,6 +3,12 @@ package git
/*
#include <git2.h>
#include <git2/sys/openssl.h>
#cgo pkg-config: libgit2
#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 24
# error "Invalid libgit2 version; this git2go supports libgit2 v0.24"
#endif
*/
import "C"
import (

View File

@ -113,6 +113,7 @@ func updateReadme(t *testing.T, repo *Repository, content string) (*Oid, *Oid) {
}
func TestOidZero(t *testing.T) {
t.Parallel()
var zeroId Oid
if !zeroId.IsZero() {
@ -121,6 +122,7 @@ func TestOidZero(t *testing.T) {
}
func TestEmptyOid(t *testing.T) {
t.Parallel()
_, err := NewOid("")
if err == nil || !IsErrorCode(err, ErrGeneric) {
t.Fatal("Should have returned invalid error")

View File

@ -8,6 +8,7 @@ import (
)
func TestCreateRepoAndStage(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -24,6 +25,7 @@ func TestCreateRepoAndStage(t *testing.T) {
}
func TestIndexReadTree(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -53,6 +55,7 @@ func TestIndexReadTree(t *testing.T) {
}
func TestIndexWriteTreeTo(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -72,6 +75,7 @@ func TestIndexWriteTreeTo(t *testing.T) {
}
func TestIndexAddAndWriteTreeTo(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -106,6 +110,7 @@ func TestIndexAddAndWriteTreeTo(t *testing.T) {
}
func TestIndexAddAllNoCallback(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -127,6 +132,7 @@ func TestIndexAddAllNoCallback(t *testing.T) {
}
func TestIndexAddAllCallback(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -155,6 +161,7 @@ func TestIndexAddAllCallback(t *testing.T) {
}
func TestIndexOpen(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -6,6 +6,7 @@ import (
)
func TestMergeWithSelf(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -24,6 +25,7 @@ func TestMergeWithSelf(t *testing.T) {
}
func TestMergeAnalysisWithSelf(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -46,6 +48,7 @@ func TestMergeAnalysisWithSelf(t *testing.T) {
}
func TestMergeSameFile(t *testing.T) {
t.Parallel()
file := MergeFileInput{
Path: "test",
Mode: 33188,
@ -68,6 +71,7 @@ func TestMergeSameFile(t *testing.T) {
}
func TestMergeTreesWithoutAncestor(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -125,6 +129,7 @@ func appendCommit(t *testing.T, repo *Repository) (*Oid, *Oid) {
}
func TestMergeBase(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -8,6 +8,7 @@ import (
)
func TestCreateNote(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -27,6 +28,7 @@ func TestCreateNote(t *testing.T) {
}
func TestNoteIterator(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -63,6 +65,7 @@ func TestNoteIterator(t *testing.T) {
}
func TestRemoveNote(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -86,6 +89,7 @@ func TestRemoveNote(t *testing.T) {
}
func TestDefaultNoteRef(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -5,6 +5,7 @@ import (
)
func TestObjectPoymorphism(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -88,6 +89,7 @@ func checkOwner(t *testing.T, repo *Repository, obj Object) {
}
func TestObjectOwner(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -104,6 +106,7 @@ func TestObjectOwner(t *testing.T) {
}
func TestObjectPeel(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -7,6 +7,7 @@ import (
)
func TestOdbReadHeader(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -35,6 +36,7 @@ func TestOdbReadHeader(t *testing.T) {
}
func TestOdbStream(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -64,7 +66,7 @@ func TestOdbStream(t *testing.T) {
}
func TestOdbHash(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -92,6 +94,7 @@ Initial commit.`
}
func TestOdbForeach(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -6,6 +6,7 @@ import (
)
func TestPatch(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -5,6 +5,7 @@ import (
)
func TestRemotePush(t *testing.T) {
t.Parallel()
repo := createBareTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -8,6 +8,7 @@ import (
)
func TestRefModification(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -53,6 +54,7 @@ func TestRefModification(t *testing.T) {
}
func TestReferenceIterator(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -131,6 +133,7 @@ func TestReferenceIterator(t *testing.T) {
}
func TestReferenceOwner(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -150,6 +153,7 @@ func TestReferenceOwner(t *testing.T) {
}
func TestUtil(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -177,6 +181,7 @@ func TestUtil(t *testing.T) {
}
func TestIsNote(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -210,6 +215,7 @@ func TestIsNote(t *testing.T) {
}
func TestReferenceIsValidName(t *testing.T) {
t.Parallel()
if !ReferenceIsValidName("HEAD") {
t.Errorf("HEAD should be a valid reference name")
}

View File

@ -6,6 +6,7 @@ import (
)
func TestListRemotes(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -33,6 +34,7 @@ func assertHostname(cert *Certificate, valid bool, hostname string, t *testing.T
}
func TestCertificateCheck(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -52,6 +54,7 @@ func TestCertificateCheck(t *testing.T) {
}
func TestRemoteConnect(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -63,6 +66,7 @@ func TestRemoteConnect(t *testing.T) {
}
func TestRemoteLs(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -81,6 +85,7 @@ func TestRemoteLs(t *testing.T) {
}
func TestRemoteLsFiltering(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -107,6 +112,7 @@ func TestRemoteLsFiltering(t *testing.T) {
}
func TestRemotePruneRefs(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -129,6 +135,7 @@ func TestRemotePruneRefs(t *testing.T) {
}
func TestRemotePrune(t *testing.T) {
t.Parallel()
remoteRepo := createTestRepo(t)
defer cleanupTestRepo(t, remoteRepo)

View File

@ -28,7 +28,7 @@ type Repository struct {
// read, write and delete notes from this repository.
Notes NoteCollection
// Tags represents the collection of tags and can be used to create,
// list and iterate tags in this repository.
// list, iterate and remove tags in this repository.
Tags TagsCollection
// Stashes represents the collection of stashes and can be used to
// save, apply and iterate over stash states in this repository.

View File

@ -24,3 +24,19 @@ func (r *Repository) ResetToCommit(commit *Commit, resetType ResetType, opts *Ch
}
return nil
}
func (r *Repository) ResetDefaultToCommit(commit *Commit, pathspecs []string) error {
cpathspecs := C.git_strarray{}
cpathspecs.count = C.size_t(len(pathspecs))
cpathspecs.strings = makeCStringsFromStrings(pathspecs)
defer freeStrarray(&cpathspecs)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reset_default(r.ptr, commit.ptr, &cpathspecs)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}

View File

@ -6,6 +6,7 @@ import (
)
func TestResetToCommit(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
seedTestRepo(t, repo)
// create commit to reset to

View File

@ -5,6 +5,7 @@ import (
)
func TestRevparse(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -17,6 +18,7 @@ func TestRevparse(t *testing.T) {
}
func TestRevparseSingle(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -29,6 +31,7 @@ func TestRevparseSingle(t *testing.T) {
}
func TestRevparseExt(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -13,9 +13,10 @@ if [ "x$TRAVIS_BRANCH" = "xnext" ]; then
fi
cd "${HOME}"
wget -O libgit2-0.23.1.tar.gz https://github.com/libgit2/libgit2/archive/v0.23.1.tar.gz
tar -xzvf libgit2-0.23.1.tar.gz
cd libgit2-0.23.1 && mkdir build && cd build
LG2VER="0.24.0"
wget -O libgit2-${LG2VER}.tar.gz https://github.com/libgit2/libgit2/archive/v${LG2VER}.tar.gz
tar -xzvf libgit2-${LG2VER}.tar.gz
cd libgit2-${LG2VER} && mkdir build && cd build
cmake -DTHREADSAFE=ON -DBUILD_CLAR=OFF -DCMAKE_BUILD_TYPE="RelWithDebInfo" .. && make && sudo make install
sudo ldconfig
cd "${TRAVIS_BUILD_DIR}"

View File

@ -7,6 +7,7 @@ import (
)
func TestStatusFile(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -27,6 +28,7 @@ func TestStatusFile(t *testing.T) {
}
func TestStatusList(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -5,6 +5,7 @@ import (
)
func TestSubmoduleForeach(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

15
tag.go
View File

@ -83,6 +83,21 @@ func (c *TagsCollection) Create(
return oid, nil
}
func (c *TagsCollection) Remove(name string) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
ret := C.git_tag_delete(c.repo.ptr, cname)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
// CreateLightweight creates a new lightweight tag pointing to a commit
// and returns the id of the target object.
//

View File

@ -7,6 +7,7 @@ import (
)
func TestCreateTag(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -26,6 +27,7 @@ func TestCreateTag(t *testing.T) {
}
func TestCreateTagLightweight(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -50,6 +52,7 @@ func TestCreateTagLightweight(t *testing.T) {
}
func TestListTags(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -79,6 +82,7 @@ func TestListTags(t *testing.T) {
}
func TestListTagsWithMatch(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -116,6 +120,7 @@ func TestListTagsWithMatch(t *testing.T) {
}
func TestTagForeach(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)

View File

@ -3,6 +3,7 @@ package git
import "testing"
func TestTreeEntryById(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -22,6 +23,7 @@ func TestTreeEntryById(t *testing.T) {
}
func TestTreeBuilderInsert(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)