Update to libgit2 b6011e29

This commit is contained in:
Carlos Martín Nieto 2015-06-08 04:11:21 +02:00
parent 85fde1fcfb
commit 36e0a256fe
9 changed files with 140 additions and 155 deletions

View File

@ -12,7 +12,7 @@ import (
type CloneOptions struct {
*CheckoutOpts
*RemoteCallbacks
*FetchOptions
Bare bool
CheckoutBranch string
RemoteCreateCallback C.git_remote_create_cb
@ -55,7 +55,7 @@ func populateCloneOptions(ptr *C.git_clone_options, opts *CloneOptions) {
return
}
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
populateRemoteCallbacks(&ptr.remote_callbacks, opts.RemoteCallbacks)
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
ptr.bare = cbool(opts.Bare)
if opts.RemoteCreateCallback != nil {

4
git.go
View File

@ -76,8 +76,8 @@ const (
ErrNonFastForward ErrorCode = C.GIT_ENONFASTFORWARD
// Name/ref spec was not in a valid format
ErrInvalidSpec ErrorCode = C.GIT_EINVALIDSPEC
// Merge conflicts prevented operation
ErrMergeConflict ErrorCode = C.GIT_EMERGECONFLICT
// Checkout conflicts prevented operation
ErrConflict ErrorCode = C.GIT_ECONFLICT
// Lock file prevented operation
ErrLocked ErrorCode = C.GIT_ELOCKED
// Reference value does not match expected

View File

@ -12,7 +12,6 @@ import "C"
import (
"fmt"
"runtime"
"time"
"unsafe"
)
@ -31,13 +30,18 @@ type Index struct {
ptr *C.git_index
}
type IndexTime struct {
seconds int32
nanoseconds uint32
}
type IndexEntry struct {
Ctime time.Time
Mtime time.Time
Ctime IndexTime
Mtime IndexTime
Mode Filemode
Uid uint
Gid uint
Size uint
Uid uint32
Gid uint32
Size uint32
Id *Oid
Path string
}
@ -47,26 +51,26 @@ func newIndexEntryFromC(entry *C.git_index_entry) *IndexEntry {
return nil
}
return &IndexEntry{
time.Unix(int64(entry.ctime.seconds), int64(entry.ctime.nanoseconds)),
time.Unix(int64(entry.mtime.seconds), int64(entry.mtime.nanoseconds)),
IndexTime { int32(entry.ctime.seconds), uint32(entry.ctime.nanoseconds) },
IndexTime { int32(entry.mtime.seconds), uint32(entry.mtime.nanoseconds) },
Filemode(entry.mode),
uint(entry.uid),
uint(entry.gid),
uint(entry.file_size),
uint32(entry.uid),
uint32(entry.gid),
uint32(entry.file_size),
newOidFromC(&entry.id),
C.GoString(entry.path),
}
}
func populateCIndexEntry(source *IndexEntry, dest *C.git_index_entry) {
dest.ctime.seconds = C.git_time_t(source.Ctime.Unix())
dest.ctime.nanoseconds = C.uint(source.Ctime.UnixNano())
dest.mtime.seconds = C.git_time_t(source.Mtime.Unix())
dest.mtime.nanoseconds = C.uint(source.Mtime.UnixNano())
dest.mode = C.uint(source.Mode)
dest.uid = C.uint(source.Uid)
dest.gid = C.uint(source.Gid)
dest.file_size = C.git_off_t(source.Size)
dest.ctime.seconds = C.int32_t(source.Ctime.seconds)
dest.ctime.nanoseconds = C.uint32_t(source.Ctime.nanoseconds)
dest.mtime.seconds = C.int32_t(source.Mtime.seconds)
dest.mtime.nanoseconds = C.uint32_t(source.Mtime.nanoseconds)
dest.mode = C.uint32_t(source.Mode)
dest.uid = C.uint32_t(source.Uid)
dest.gid = C.uint32_t(source.Gid)
dest.file_size = C.uint32_t(source.Size)
dest.id = *source.Id.toC()
dest.path = C.CString(source.Path)
}

8
odb.go
View File

@ -11,6 +11,7 @@ import (
"reflect"
"runtime"
"unsafe"
"fmt"
)
type Odb struct {
@ -106,7 +107,9 @@ func odbForEachCb(id *C.git_oid, handle unsafe.Pointer) int {
}
err := data.callback(newOidFromC(id))
fmt.Println("err %v", err)
if err != nil {
fmt.Println("returning EUSER")
data.err = err
return C.GIT_EUSER
}
@ -127,6 +130,7 @@ func (v *Odb) ForEach(callback OdbForEachCallback) error {
defer pointerHandles.Untrack(handle)
ret := C._go_git_odb_foreach(v.ptr, handle)
fmt.Println("ret %v", ret);
if ret == C.GIT_EUSER {
return data.err
} else if ret < 0 {
@ -172,13 +176,13 @@ func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {
// NewWriteStream opens a write stream to the ODB, which allows you to
// create a new object in the database. The size and type must be
// known in advance
func (v *Odb) NewWriteStream(size int, otype ObjectType) (*OdbWriteStream, error) {
func (v *Odb) NewWriteStream(size int64, otype ObjectType) (*OdbWriteStream, error) {
stream := new(OdbWriteStream)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.size_t(size), C.git_otype(otype))
ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.git_off_t(size), C.git_otype(otype))
if ret < 0 {
return nil, MakeGitError(ret)
}

View File

@ -17,7 +17,7 @@ func TestOdbStream(t *testing.T) {
str := "hello, world!"
stream, error := odb.NewWriteStream(len(str), ObjectBlob)
stream, error := odb.NewWriteStream(int64(len(str)), ObjectBlob)
checkFatal(t, error)
n, error := io.WriteString(stream, str)
checkFatal(t, error)

184
remote.go
View File

@ -69,6 +69,51 @@ type RemoteCallbacks struct {
PushUpdateReferenceCallback
}
type FetchPrune uint
const (
// Use the setting from the configuration
FetchPruneFallback FetchPrune = C.GIT_FETCH_PRUNE_FALLBACK
// Force pruning on
FetchPruneOn FetchPrune = C.GIT_FETCH_PRUNE
// Force pruning off
FetchNoPrune FetchPrune = C.GIT_FETCH_NO_PRUNE
)
type DownloadTags uint
const (
// Use the setting from the configuration.
DownloadTagsFallback DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_FALLBACK
// Ask the server for tags pointing to objects we're already
// downloading.
DownloadTagsAuto DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_AUTO
// Don't ask for any tags beyond the refspecs.
DownloadTagsNone DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_NONE
// Ask for the all the tags.
DownloadTagsAll DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_ALL
)
type FetchOptions struct {
// Callbacks to use for this fetch operation
RemoteCallbacks RemoteCallbacks
// Whether to perform a prune after the fetch
Prune FetchPrune
// Whether to write the results to FETCH_HEAD. Defaults to
// on. Leave this default in order to behave like git.
UpdateFetchhead bool
// Determines how to behave regarding tags on the remote, such
// as auto-downloading tags for objects we're downloading or
// downloading all of them.
//
// The default is to auto-follow tags.
DownloadTags DownloadTags
}
type Remote struct {
ptr *C.git_remote
callbacks RemoteCallbacks
@ -267,23 +312,6 @@ func RemoteIsValidName(name string) bool {
return false
}
func (r *Remote) SetCallbacks(callbacks *RemoteCallbacks) error {
r.callbacks = *callbacks
var ccallbacks C.git_remote_callbacks
populateRemoteCallbacks(&ccallbacks, &r.callbacks)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_remote_set_callbacks(r.ptr, &ccallbacks)
if ecode < 0 {
return MakeGitError(ecode)
}
return nil
}
func (r *Remote) Free() {
runtime.SetFinalizer(r, nil)
C.git_remote_free(r.ptr)
@ -359,18 +387,16 @@ func (repo *Repository) CreateRemoteWithFetchspec(name string, url string, fetch
return remote, nil
}
func (repo *Repository) CreateAnonymousRemote(url, fetch string) (*Remote, error) {
func (repo *Repository) CreateAnonymousRemote(url string) (*Remote, error) {
remote := &Remote{}
curl := C.CString(url)
defer C.free(unsafe.Pointer(curl))
cfetch := C.CString(fetch)
defer C.free(unsafe.Pointer(cfetch))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, curl, cfetch)
ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, curl)
if ret < 0 {
return nil, MakeGitError(ret)
}
@ -395,18 +421,6 @@ func (repo *Repository) LookupRemote(name string) (*Remote, error) {
return remote, nil
}
func (o *Remote) Save() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_save(o.ptr)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
func (o *Remote) Owner() Repository {
return Repository{C.git_remote_owner(o.ptr)}
}
@ -423,42 +437,48 @@ func (o *Remote) PushUrl() string {
return C.GoString(C.git_remote_pushurl(o.ptr))
}
func (o *Remote) SetUrl(url string) error {
func (o *Repository) RemoteSetUrl(remote, url string) error {
curl := C.CString(url)
defer C.free(unsafe.Pointer(curl))
cremote := C.CString(remote)
defer C.free(unsafe.Pointer(cremote))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_set_url(o.ptr, curl)
ret := C.git_remote_set_url(o.ptr, cremote, curl)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
func (o *Remote) SetPushUrl(url string) error {
func (o *Repository) RemoteSetPushUrl(remote, url string) error {
curl := C.CString(url)
defer C.free(unsafe.Pointer(curl))
cremote := C.CString(remote)
defer C.free(unsafe.Pointer(cremote))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_set_pushurl(o.ptr, curl)
ret := C.git_remote_set_pushurl(o.ptr, cremote, curl)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
func (o *Remote) AddFetch(refspec string) error {
func (o *Repository) RemoteAddFetch(remote, refspec string) error {
crefspec := C.CString(refspec)
defer C.free(unsafe.Pointer(crefspec))
cremote := C.CString(remote)
defer C.free(unsafe.Pointer(cremote))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_add_fetch(o.ptr, crefspec)
ret := C.git_remote_add_fetch(o.ptr, cremote, crefspec)
if ret < 0 {
return MakeGitError(ret)
}
@ -519,30 +539,16 @@ func (o *Remote) FetchRefspecs() ([]string, error) {
return refspecs, nil
}
func (o *Remote) SetFetchRefspecs(refspecs []string) error {
crefspecs := C.git_strarray{}
crefspecs.count = C.size_t(len(refspecs))
crefspecs.strings = makeCStringsFromStrings(refspecs)
defer freeStrarray(&crefspecs)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_set_fetch_refspecs(o.ptr, &crefspecs)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
func (o *Remote) AddPush(refspec string) error {
func (o *Repository) RemoteAddPush(remote, refspec string) error {
crefspec := C.CString(refspec)
defer C.free(unsafe.Pointer(crefspec))
cremote := C.CString(remote)
defer C.free(unsafe.Pointer(cremote))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_add_push(o.ptr, crefspec)
ret := C.git_remote_add_push(o.ptr, cremote, crefspec)
if ret < 0 {
return MakeGitError(ret)
}
@ -564,43 +570,26 @@ func (o *Remote) PushRefspecs() ([]string, error) {
return refspecs, nil
}
func (o *Remote) SetPushRefspecs(refspecs []string) error {
crefspecs := C.git_strarray{}
crefspecs.count = C.size_t(len(refspecs))
crefspecs.strings = makeCStringsFromStrings(refspecs)
defer freeStrarray(&crefspecs)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_set_push_refspecs(o.ptr, &crefspecs)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
func (o *Remote) ClearRefspecs() {
C.git_remote_clear_refspecs(o.ptr)
}
func (o *Remote) RefspecCount() uint {
return uint(C.git_remote_refspec_count(o.ptr))
}
func (o *Remote) SetUpdateFetchHead(val bool) {
C.git_remote_set_update_fetchhead(o.ptr, cbool(val))
}
func (o *Remote) UpdateFetchHead() bool {
return C.git_remote_update_fetchhead(o.ptr) > 0
func populateFetchOptions(options *C.git_fetch_options, opts *FetchOptions) {
C.git_fetch_init_options(options, C.GIT_FETCH_OPTIONS_VERSION)
if opts == nil {
return;
}
populateRemoteCallbacks(&options.callbacks, &opts.RemoteCallbacks)
options.prune = C.git_fetch_prune_t(opts.Prune)
options.update_fetchhead = cbool(opts.UpdateFetchhead)
options.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags)
}
// Fetch performs a fetch operation. refspecs specifies which refspecs
// to use for this fetch, use an empty list to use the refspecs from
// the configuration; msg specifies what to use for the reflog
// entries. Leave "" to use defaults.
func (o *Remote) Fetch(refspecs []string, msg string) error {
func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error {
var cmsg *C.char = nil
if msg != "" {
@ -613,29 +602,35 @@ func (o *Remote) Fetch(refspecs []string, msg string) error {
crefspecs.strings = makeCStringsFromStrings(refspecs)
defer freeStrarray(&crefspecs)
var coptions C.git_fetch_options
populateFetchOptions(&coptions, opts);
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_fetch(o.ptr, &crefspecs, cmsg)
ret := C.git_remote_fetch(o.ptr, &crefspecs, &coptions, cmsg)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
func (o *Remote) ConnectFetch() error {
return o.Connect(ConnectDirectionFetch)
func (o *Remote) ConnectFetch(callbacks *RemoteCallbacks) error {
return o.Connect(ConnectDirectionFetch, callbacks)
}
func (o *Remote) ConnectPush() error {
return o.Connect(ConnectDirectionPush)
func (o *Remote) ConnectPush(callbacks *RemoteCallbacks) error {
return o.Connect(ConnectDirectionPush, callbacks)
}
func (o *Remote) Connect(direction ConnectDirection) error {
func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks) error {
var ccallbacks C.git_remote_callbacks;
populateRemoteCallbacks(&ccallbacks, callbacks)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_remote_connect(o.ptr, C.git_direction(direction)); ret != 0 {
if ret := C.git_remote_connect(o.ptr, C.git_direction(direction), &ccallbacks); ret != 0 {
return MakeGitError(ret)
}
return nil
@ -713,11 +708,14 @@ func (o *Remote) PruneRefs() bool {
return C.git_remote_prune_refs(o.ptr) > 0
}
func (o *Remote) Prune() error {
func (o *Remote) Prune(callbacks *RemoteCallbacks) error {
var ccallbacks C.git_remote_callbacks;
populateRemoteCallbacks(&ccallbacks, callbacks)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_prune(o.ptr)
ret := C.git_remote_prune(o.ptr, &ccallbacks)
if ret < 0 {
return MakeGitError(ret)
}

View File

@ -5,27 +5,6 @@ import (
"testing"
)
func TestRefspecs(t *testing.T) {
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
remote, err := repo.CreateAnonymousRemote("git://foo/bar", "refs/heads/*:refs/heads/*")
checkFatal(t, err)
expected := []string{
"refs/heads/*:refs/remotes/origin/*",
"refs/pull/*/head:refs/remotes/origin/*",
}
err = remote.SetFetchRefspecs(expected)
checkFatal(t, err)
actual, err := remote.FetchRefspecs()
checkFatal(t, err)
compareStringList(t, expected, actual)
}
func TestListRemotes(t *testing.T) {
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@ -60,15 +39,15 @@ func TestCertificateCheck(t *testing.T) {
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
checkFatal(t, err)
callbacks := RemoteCallbacks{
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode {
return assertHostname(cert, valid, hostname, t)
options := FetchOptions {
RemoteCallbacks: RemoteCallbacks{
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode {
return assertHostname(cert, valid, hostname, t)
},
},
}
err = remote.SetCallbacks(&callbacks)
checkFatal(t, err)
err = remote.Fetch([]string{}, "")
err = remote.Fetch([]string{}, &options, "")
checkFatal(t, err)
}
@ -79,7 +58,7 @@ func TestRemoteConnect(t *testing.T) {
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
checkFatal(t, err)
err = remote.ConnectFetch()
err = remote.ConnectFetch(nil)
checkFatal(t, err)
}
@ -90,7 +69,7 @@ func TestRemoteLs(t *testing.T) {
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
checkFatal(t, err)
err = remote.ConnectFetch()
err = remote.ConnectFetch(nil)
checkFatal(t, err)
heads, err := remote.Ls()
@ -108,7 +87,7 @@ func TestRemoteLsFiltering(t *testing.T) {
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
checkFatal(t, err)
err = remote.ConnectFetch()
err = remote.ConnectFetch(nil)
checkFatal(t, err)
heads, err := remote.Ls("master")
@ -172,7 +151,7 @@ func TestRemotePrune(t *testing.T) {
remote, err := repo.CreateRemote("origin", remoteUrl)
checkFatal(t, err)
err = remote.Fetch([]string{"test-prune"}, "")
err = remote.Fetch([]string{"test-prune"}, nil, "")
checkFatal(t, err)
_, err = repo.CreateReference("refs/remotes/origin/test-prune", head, true, "remote reference")
@ -187,10 +166,10 @@ func TestRemotePrune(t *testing.T) {
rr, err := repo.LookupRemote("origin")
checkFatal(t, err)
err = rr.ConnectFetch()
err = rr.ConnectFetch(nil)
checkFatal(t, err)
err = rr.Prune()
err = rr.Prune(nil)
checkFatal(t, err)
_, err = repo.LookupReference("refs/remotes/origin/test-prune")

View File

@ -14,7 +14,7 @@ import (
// SubmoduleUpdateOptions
type SubmoduleUpdateOptions struct {
*CheckoutOpts
*RemoteCallbacks
*FetchOptions
CloneCheckoutStrategy CheckoutStrategy
}
@ -348,7 +348,7 @@ func populateSubmoduleUpdateOptions(ptr *C.git_submodule_update_options, opts *S
}
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
populateRemoteCallbacks(&ptr.remote_callbacks, opts.RemoteCallbacks)
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
ptr.clone_checkout_strategy = C.uint(opts.CloneCheckoutStrategy)
return nil

2
vendor/libgit2 vendored

@ -1 +1 @@
Subproject commit 4c02d393748d0db382450871ad9ef6898a2ce360
Subproject commit b6011e296e4db6942d71f5a8548d1308353927ee