Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ void _go_git_writestream_free(git_writestream *stream);
*/
import "C"
import (
"io"
"reflect"
"runtime"
"unsafe"
Expand Down Expand Up @@ -68,40 +67,14 @@ func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
size = C.size_t(0)
}

ecode := C.git_blob_create_frombuffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size)
ecode := C.git_blob_create_from_buffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size)
runtime.KeepAlive(repo)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
return newOidFromC(&id), nil
}

type BlobChunkCallback func(maxLen int) ([]byte, error)

type BlobCallbackData struct {
Callback BlobChunkCallback
Error error
}

//export blobChunkCb
func blobChunkCb(buffer *C.char, maxLen C.size_t, handle unsafe.Pointer) int {
payload := pointerHandles.Get(handle)
data, ok := payload.(*BlobCallbackData)
if !ok {
panic("could not retrieve blob callback data")
}

goBuf, err := data.Callback(int(maxLen))
if err == io.EOF {
return 0
} else if err != nil {
data.Error = err
return -1
}
C.memcpy(unsafe.Pointer(buffer), unsafe.Pointer(&goBuf[0]), C.size_t(len(goBuf)))
return len(goBuf)
}

func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, error) {
var chintPath *C.char = nil
var stream *C.git_writestream
Expand All @@ -114,7 +87,7 @@ func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, err
runtime.LockOSThread()
defer runtime.UnlockOSThread()

ecode := C.git_blob_create_fromstream(&stream, repo.ptr, chintPath)
ecode := C.git_blob_create_from_stream(&stream, repo.ptr, chintPath)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
Expand Down Expand Up @@ -166,7 +139,7 @@ func (stream *BlobWriteStream) Commit() (*Oid, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()

ecode := C.git_blob_create_fromstream_commit(&oid, stream.ptr)
ecode := C.git_blob_create_from_stream_commit(&oid, stream.ptr)
runtime.KeepAlive(stream)
if ecode < 0 {
return nil, MakeGitError(ecode)
Expand Down
2 changes: 1 addition & 1 deletion branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (i *BranchIterator) ForEach(f BranchIteratorFunc) error {
}
}

if err != nil && IsErrorCode(err, ErrIterOver) {
if err != nil && IsErrorCode(err, ErrorCodeIterOver) {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestBranchIterator(t *testing.T) {
t.Fatalf("expected BranchLocal, not %v", t)
}
b, bt, err = i.Next()
if !IsErrorCode(err, ErrIterOver) {
if !IsErrorCode(err, ErrorCodeIterOver) {
t.Fatal("expected iterover")
}
}
Expand All @@ -49,7 +49,7 @@ func TestBranchIteratorEach(t *testing.T) {
}

err = i.ForEach(f)
if err != nil && !IsErrorCode(err, ErrIterOver) {
if err != nil && !IsErrorCode(err, ErrorCodeIterOver) {
t.Fatal(err)
}

Expand Down
49 changes: 25 additions & 24 deletions checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (
type CheckoutNotifyCallback func(why CheckoutNotifyType, path string, baseline, target, workdir DiffFile) ErrorCode
type CheckoutProgressCallback func(path string, completed, total uint) ErrorCode

type CheckoutOpts struct {
type CheckoutOptions struct {
Strategy CheckoutStrategy // Default will be a dry run
DisableFilters bool // Don't apply filters like CRLF conversion
DirMode os.FileMode // Default is 0755
Expand All @@ -65,32 +65,33 @@ type CheckoutOpts struct {
Baseline *Tree
}

func checkoutOptionsFromC(c *C.git_checkout_options) CheckoutOpts {
opts := CheckoutOpts{}
opts.Strategy = CheckoutStrategy(c.checkout_strategy)
opts.DisableFilters = c.disable_filters != 0
opts.DirMode = os.FileMode(c.dir_mode)
opts.FileMode = os.FileMode(c.file_mode)
opts.FileOpenFlags = int(c.file_open_flags)
opts.NotifyFlags = CheckoutNotifyType(c.notify_flags)
func checkoutOptionsFromC(c *C.git_checkout_options) CheckoutOptions {
opts := CheckoutOptions{
Strategy: CheckoutStrategy(c.checkout_strategy),
DisableFilters: c.disable_filters != 0,
DirMode: os.FileMode(c.dir_mode),
FileMode: os.FileMode(c.file_mode),
FileOpenFlags: int(c.file_open_flags),
NotifyFlags: CheckoutNotifyType(c.notify_flags),
}
if c.notify_payload != nil {
opts.NotifyCallback = pointerHandles.Get(c.notify_payload).(*CheckoutOpts).NotifyCallback
opts.NotifyCallback = pointerHandles.Get(c.notify_payload).(*CheckoutOptions).NotifyCallback
}
if c.progress_payload != nil {
opts.ProgressCallback = pointerHandles.Get(c.progress_payload).(*CheckoutOpts).ProgressCallback
opts.ProgressCallback = pointerHandles.Get(c.progress_payload).(*CheckoutOptions).ProgressCallback
}
if c.target_directory != nil {
opts.TargetDirectory = C.GoString(c.target_directory)
}
return opts
}

func (opts *CheckoutOpts) toC() *C.git_checkout_options {
func (opts *CheckoutOptions) toC() *C.git_checkout_options {
if opts == nil {
return nil
}
c := C.git_checkout_options{}
populateCheckoutOpts(&c, opts)
populateCheckoutOptions(&c, opts)
return &c
}

Expand All @@ -110,7 +111,7 @@ func checkoutNotifyCallback(why C.git_checkout_notify_t, cpath *C.char, cbaselin
if cworkdir != nil {
workdir = diffFileFromC((*C.git_diff_file)(cworkdir))
}
opts := pointerHandles.Get(data).(*CheckoutOpts)
opts := pointerHandles.Get(data).(*CheckoutOptions)
if opts.NotifyCallback == nil {
return 0
}
Expand All @@ -119,17 +120,17 @@ func checkoutNotifyCallback(why C.git_checkout_notify_t, cpath *C.char, cbaselin

//export checkoutProgressCallback
func checkoutProgressCallback(path *C.char, completed_steps, total_steps C.size_t, data unsafe.Pointer) int {
opts := pointerHandles.Get(data).(*CheckoutOpts)
opts := pointerHandles.Get(data).(*CheckoutOptions)
if opts.ProgressCallback == nil {
return 0
}
return int(opts.ProgressCallback(C.GoString(path), uint(completed_steps), uint(total_steps)))
}

// Convert the CheckoutOpts struct to the corresponding
// Convert the CheckoutOptions struct to the corresponding
// C-struct. Returns a pointer to ptr, or nil if opts is nil, in order
// to help with what to pass.
func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.git_checkout_options {
func populateCheckoutOptions(ptr *C.git_checkout_options, opts *CheckoutOptions) *C.git_checkout_options {
if opts == nil {
return nil
}
Expand Down Expand Up @@ -165,7 +166,7 @@ func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.gi
return ptr
}

func freeCheckoutOpts(ptr *C.git_checkout_options) {
func freeCheckoutOptions(ptr *C.git_checkout_options) {
if ptr == nil {
return
}
Expand All @@ -180,12 +181,12 @@ func freeCheckoutOpts(ptr *C.git_checkout_options) {

// Updates files in the index and the working tree to match the content of
// the commit pointed at by HEAD. opts may be nil.
func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
func (v *Repository) CheckoutHead(opts *CheckoutOptions) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()

cOpts := opts.toC()
defer freeCheckoutOpts(cOpts)
defer freeCheckoutOptions(cOpts)

ret := C.git_checkout_head(v.ptr, cOpts)
runtime.KeepAlive(v)
Expand All @@ -199,7 +200,7 @@ func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
// Updates files in the working tree to match the content of the given
// index. If index is nil, the repository's index will be used. opts
// may be nil.
func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOptions) error {
var iptr *C.git_index = nil
if index != nil {
iptr = index.ptr
Expand All @@ -209,7 +210,7 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
defer runtime.UnlockOSThread()

cOpts := opts.toC()
defer freeCheckoutOpts(cOpts)
defer freeCheckoutOptions(cOpts)

ret := C.git_checkout_index(v.ptr, iptr, cOpts)
runtime.KeepAlive(v)
Expand All @@ -220,12 +221,12 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
return nil
}

func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOpts) error {
func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOptions) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()

cOpts := opts.toC()
defer freeCheckoutOpts(cOpts)
defer freeCheckoutOptions(cOpts)

ret := C.git_checkout_tree(v.ptr, tree.ptr, cOpts)
runtime.KeepAlive(v)
Expand Down
4 changes: 2 additions & 2 deletions cherrypick.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type CherrypickOptions struct {
Version uint
Mainline uint
MergeOpts MergeOptions
CheckoutOpts CheckoutOpts
CheckoutOpts CheckoutOptions
}

func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
Expand Down Expand Up @@ -41,7 +41,7 @@ func freeCherrypickOpts(ptr *C.git_cherrypick_options) {
if ptr == nil {
return
}
freeCheckoutOpts(&ptr.checkout_opts)
freeCheckoutOptions(&ptr.checkout_opts)
}

func DefaultCherrypickOptions() (CherrypickOptions, error) {
Expand Down
2 changes: 1 addition & 1 deletion cherrypick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func checkout(t *testing.T, repo *Repository, commit *Commit) {
t.Fatal(err)
}

err = repo.CheckoutTree(tree, &CheckoutOpts{Strategy: CheckoutSafe})
err = repo.CheckoutTree(tree, &CheckoutOptions{Strategy: CheckoutSafe})
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 6 additions & 6 deletions clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ func remoteCreateCallback(cremote unsafe.Pointer, crepo unsafe.Pointer, cname, c
runtime.SetFinalizer(repo, nil)

if opts, ok := pointerHandles.Get(payload).(CloneOptions); ok {
remote, err := opts.RemoteCreateCallback(repo, name, url)
remote, errorCode := opts.RemoteCreateCallback(repo, name, url)
// clear finalizer as the calling C function will
// free the remote itself
runtime.SetFinalizer(remote, nil)

if err == ErrOk && remote != nil {
if errorCode == ErrorCodeOK && remote != nil {
cptr := (**C.git_remote)(cremote)
*cptr = remote.ptr
} else if err == ErrOk && remote == nil {
} else if errorCode == ErrorCodeOK && remote == nil {
panic("no remote created by callback")
}

return C.int(err)
return C.int(errorCode)
} else {
panic("invalid remote create callback")
}
Expand All @@ -82,7 +82,7 @@ func populateCloneOptions(ptr *C.git_clone_options, opts *CloneOptions) {
if opts == nil {
return
}
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
populateCheckoutOptions(&ptr.checkout_opts, opts.CheckoutOpts)
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
ptr.bare = cbool(opts.Bare)

Expand All @@ -98,7 +98,7 @@ func freeCloneOptions(ptr *C.git_clone_options) {
return
}

freeCheckoutOpts(&ptr.checkout_opts)
freeCheckoutOptions(&ptr.checkout_opts)

if ptr.remote_cb_payload != nil {
pointerHandles.Untrack(ptr.remote_cb_payload)
Expand Down
4 changes: 2 additions & 2 deletions clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func TestCloneWithCallback(t *testing.T) {

remote, err := r.Remotes.Create(REMOTENAME, url)
if err != nil {
return nil, ErrGeneric
return nil, ErrorCodeGeneric
}

return remote, ErrOk
return remote, ErrorCodeOK
},
}

Expand Down
Loading