diff options
| -rw-r--r-- | blob.go | 2 | ||||
| -rw-r--r-- | config_test.go | 21 | ||||
| -rw-r--r-- | index.go | 4 | ||||
| -rw-r--r-- | merge.go | 3 | ||||
| -rw-r--r-- | odb.go | 19 | ||||
| -rw-r--r-- | odb_test.go | 28 | ||||
| -rw-r--r-- | remote.go | 16 | ||||
| -rw-r--r-- | walk.go | 4 |
8 files changed, 80 insertions, 17 deletions
@@ -84,7 +84,7 @@ func (repo *Repository) CreateBlobFromChunks(hintPath string, callback BlobChunk var chintPath *C.char = nil if len(hintPath) > 0 { - C.CString(hintPath) + chintPath = C.CString(hintPath) defer C.free(unsafe.Pointer(chintPath)) } oid := C.git_oid{} diff --git a/config_test.go b/config_test.go index 8c2decc..fea8d8a 100644 --- a/config_test.go +++ b/config_test.go @@ -18,10 +18,22 @@ func setupConfig() (*Config, error) { return nil, err } - c.SetString("foo.bar", "baz") - c.SetBool("foo.bool", true) - c.SetInt32("foo.int32", 32) - c.SetInt64("foo.int64", 64) + err = c.SetString("foo.bar", "baz") + if err != nil { + return nil, err + } + err = c.SetBool("foo.bool", true) + if err != nil { + return nil, err + } + err = c.SetInt32("foo.int32", 32) + if err != nil { + return nil, err + } + err = c.SetInt64("foo.int64", 64) + if err != nil { + return nil, err + } return c, err } @@ -86,6 +98,7 @@ func TestConfigLookups(t *testing.T) { if err != nil { t.Errorf("Setup error: '%v'. Expected none\n", err) + return } defer c.Free() @@ -97,7 +97,7 @@ func NewIndex() (*Index, error) { return nil, MakeGitError(err) } - return &Index{ptr: ptr}, nil + return newIndexFromC(ptr), nil } // OpenIndex creates a new index at the given path. If the file does @@ -115,7 +115,7 @@ func OpenIndex(path string) (*Index, error) { return nil, MakeGitError(err) } - return &Index{ptr: ptr}, nil + return newIndexFromC(ptr), nil } // Path returns the index' path on disk or an empty string if it @@ -178,6 +178,9 @@ const ( MergePreferenceFastForwardOnly MergePreference = C.GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY ) +// MergeAnalysis returns the possible actions which could be taken by +// a 'git-merge' command. There may be multiple answers, so the first +// return value is a bitmask of MergeAnalysis values. func (r *Repository) MergeAnalysis(theirHeads []*AnnotatedCommit) (MergeAnalysis, MergePreference, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() @@ -11,7 +11,6 @@ import ( "reflect" "runtime" "unsafe" - "fmt" ) type Odb struct { @@ -55,6 +54,21 @@ func (v *Odb) AddBackend(backend *OdbBackend, priority int) (err error) { return nil } +func (v *Odb) ReadHeader(oid *Oid) (uint64, ObjectType, error) { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + var sz C.size_t + var cotype C.git_otype + + ret := C.git_odb_read_header(&sz, &cotype, v.ptr, oid.toC()) + if ret < 0 { + return 0, C.GIT_OBJ_BAD, MakeGitError(ret) + } + + return uint64(sz), ObjectType(cotype), nil +} + func (v *Odb) Exists(oid *Oid) bool { ret := C.git_odb_exists(v.ptr, oid.toC()) return ret != 0 @@ -107,9 +121,7 @@ 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 } @@ -130,7 +142,6 @@ 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 { diff --git a/odb_test.go b/odb_test.go index 0d765b9..dfd2ad0 100644 --- a/odb_test.go +++ b/odb_test.go @@ -6,6 +6,34 @@ import ( "testing" ) +func TestOdbReadHeader(t *testing.T) { + repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + + _, _ = seedTestRepo(t, repo) + odb, err := repo.Odb() + if err != nil { + t.Fatalf("Odb: %v", err) + } + data := []byte("hello") + id, err := odb.Write(data, ObjectBlob) + if err != nil { + t.Fatalf("odb.Write: %v", err) + } + + sz, typ, err := odb.ReadHeader(id) + if err != nil { + t.Fatalf("ReadHeader: %v", err) + } + + if sz != uint64(len(data)) { + t.Errorf("ReadHeader got size %d, want %d", sz, len(data)) + } + if typ != ObjectBlob { + t.Errorf("ReadHeader got object type %s", typ) + } +} + func TestOdbStream(t *testing.T) { repo := createTestRepo(t) defer cleanupTestRepo(t, repo) @@ -623,14 +623,16 @@ func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error crefspecs.strings = makeCStringsFromStrings(refspecs) defer freeStrarray(&crefspecs) - var coptions C.git_fetch_options - populateFetchOptions(&coptions, opts); + coptions := (*C.git_fetch_options)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_fetch_options{})))) + defer C.free(unsafe.Pointer(coptions)) + + populateFetchOptions(coptions, opts) defer untrackCalbacksPayload(&coptions.callbacks) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_fetch(o.ptr, &crefspecs, &coptions, cmsg) + ret := C.git_remote_fetch(o.ptr, &crefspecs, coptions, cmsg) if ret < 0 { return MakeGitError(ret) } @@ -710,14 +712,16 @@ func (o *Remote) Push(refspecs []string, opts *PushOptions) error { crefspecs.strings = makeCStringsFromStrings(refspecs) defer freeStrarray(&crefspecs) - var coptions C.git_push_options - populatePushOptions(&coptions, opts) + coptions := (*C.git_push_options)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_push_options{})))) + defer C.free(unsafe.Pointer(coptions)) + + populatePushOptions(coptions, opts) defer untrackCalbacksPayload(&coptions.callbacks) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_push(o.ptr, &crefspecs, &coptions) + ret := C.git_remote_push(o.ptr, &crefspecs, coptions) if ret < 0 { return MakeGitError(ret) } @@ -194,6 +194,10 @@ func (v *RevWalk) Iterate(fun RevWalkIterator) (err error) { return nil } +func (v *RevWalk) SimplifyFirstParent() { + C.git_revwalk_simplify_first_parent(v.ptr) +} + func (v *RevWalk) Sorting(sm SortType) { C.git_revwalk_sorting(v.ptr, C.uint(sm)) } |
