Skip to content

Commit

Permalink
Update to libgit2 b6011e29
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmn committed Jun 8, 2015
1 parent 85fde1f commit 36e0a25
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 155 deletions.
4 changes: 2 additions & 2 deletions clone.go
Expand Up @@ -12,7 +12,7 @@ import (

type CloneOptions struct {
*CheckoutOpts
*RemoteCallbacks
*FetchOptions
Bare bool
CheckoutBranch string
RemoteCreateCallback C.git_remote_create_cb
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions git.go
Expand Up @@ -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
Expand Down
42 changes: 23 additions & 19 deletions index.go
Expand Up @@ -12,7 +12,6 @@ import "C"
import (
"fmt"
"runtime"
"time"
"unsafe"
)

Expand All @@ -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
}
Expand All @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions odb.go
Expand Up @@ -11,6 +11,7 @@ import (
"reflect"
"runtime"
"unsafe"
"fmt"
)

type Odb struct {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion odb_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit 36e0a25

Please sign in to comment.