From 21fd4ad5f6ee67580fcf831917e54e18b074b5ed Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sun, 21 Jan 2018 13:46:08 -0800 Subject: [PATCH 01/19] rebase: add RebaseOperationReword --- rebase.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rebase.go b/rebase.go index 5206fca..4517dde 100644 --- a/rebase.go +++ b/rebase.go @@ -16,6 +16,8 @@ type RebaseOperationType uint const ( // RebaseOperationPick The given commit is to be cherry-picked. The client should commit the changes and continue if there are no conflicts. RebaseOperationPick RebaseOperationType = C.GIT_REBASE_OPERATION_PICK + // RebaseOperationReword The given commit is to be cherry-picked, but the client should prompt the user to provide an updated commit message. + RebaseOperationReword RebaseOperationType = C.GIT_REBASE_OPERATION_REWORD // RebaseOperationEdit The given commit is to be cherry-picked, but the client should stop to allow the user to edit the changes before committing them. RebaseOperationEdit RebaseOperationType = C.GIT_REBASE_OPERATION_EDIT // RebaseOperationSquash The given commit is to be squashed into the previous commit. The commit message will be merged with the previous message. From 9b850d084e13e0376f3fe8cfb556d2e7b51f398f Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sun, 21 Jan 2018 13:46:54 -0800 Subject: [PATCH 02/19] rebase: make RebaseOperationType a fmt.Stringer Helps with debugging. --- rebase.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rebase.go b/rebase.go index 4517dde..d29e183 100644 --- a/rebase.go +++ b/rebase.go @@ -6,6 +6,7 @@ package git import "C" import ( "errors" + "fmt" "runtime" "unsafe" ) @@ -28,6 +29,24 @@ const ( RebaseOperationExec RebaseOperationType = C.GIT_REBASE_OPERATION_EXEC ) +func (t RebaseOperationType) String() string { + switch t { + case RebaseOperationPick: + return "pick" + case RebaseOperationReword: + return "reword" + case RebaseOperationEdit: + return "edit" + case RebaseOperationSquash: + return "squash" + case RebaseOperationFixup: + return "fixup" + case RebaseOperationExec: + return "exec" + } + return fmt.Sprintf("RebaseOperationType(%d)", t) +} + // Special value indicating that there is no currently active operation var RebaseNoOperation uint = ^uint(0) From cf2379295a47097438e272e1df11458a82d6d00a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 25 Jan 2018 15:59:00 -0800 Subject: [PATCH 03/19] signature: improve Signature.Offset docs Use standard godoc style; be more precise. --- signature.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/signature.go b/signature.go index 16964d2..220fe57 100644 --- a/signature.go +++ b/signature.go @@ -26,7 +26,7 @@ func newSignatureFromC(sig *C.git_signature) *Signature { } } -// the offset in mintes, which is what git wants +// Offset returns the time zone offset of v.When in minutes, which is what git wants. func (v *Signature) Offset() int { _, offset := v.When.Zone() return offset / 60 From 9de57cc90ef4e3d778613ad9eec35dfb9b6b21b2 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 25 Jan 2018 16:43:27 -0800 Subject: [PATCH 04/19] merge: add missing MergeFileFlag constants While we're here, pull in comments as well. While one can pop back and forth between godoc and libgit2 refs, it's much nicer to have it in one place. Note that MergeFileStyleSimplifyAlnum probably should have been called merely MergeFileSimplifyAlnum (no "Style"). It's probably not worth breaking backwards compatibility to fix it, but we avoid the mistake going forwards. --- merge.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/merge.go b/merge.go index bfbf9a3..abe1426 100644 --- a/merge.go +++ b/merge.go @@ -344,9 +344,29 @@ type MergeFileFlags int const ( MergeFileDefault MergeFileFlags = C.GIT_MERGE_FILE_DEFAULT - MergeFileStyleMerge MergeFileFlags = C.GIT_MERGE_FILE_STYLE_MERGE - MergeFileStyleDiff MergeFileFlags = C.GIT_MERGE_FILE_STYLE_DIFF3 + // Create standard conflicted merge files + MergeFileStyleMerge MergeFileFlags = C.GIT_MERGE_FILE_STYLE_MERGE + + // Create diff3-style files + MergeFileStyleDiff MergeFileFlags = C.GIT_MERGE_FILE_STYLE_DIFF3 + + // Condense non-alphanumeric regions for simplified diff file MergeFileStyleSimplifyAlnum MergeFileFlags = C.GIT_MERGE_FILE_SIMPLIFY_ALNUM + + // Ignore all whitespace + MergeFileIgnoreWhitespace MergeFileFlags = C.GIT_MERGE_FILE_IGNORE_WHITESPACE + + // Ignore changes in amount of whitespace + MergeFileIgnoreWhitespaceChange MergeFileFlags = C.GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE + + // Ignore whitespace at end of line + MergeFileIgnoreWhitespaceEOL MergeFileFlags = C.GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL + + // Use the "patience diff" algorithm + MergeFileDiffPatience MergeFileFlags = C.GIT_MERGE_FILE_DIFF_PATIENCE + + // Take extra time to find minimal diff + MergeFileDiffMinimal MergeFileFlags = C.GIT_MERGE_FILE_DIFF_MINIMAL ) type MergeFileOptions struct { From b7ca4a96f55c8f5d601ca3a3e55678fca467c641 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 15 Feb 2018 10:01:14 -0800 Subject: [PATCH 05/19] git: simplify some Oid methods --- git.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/git.go b/git.go index 0925e45..897d261 100644 --- a/git.go +++ b/git.go @@ -189,22 +189,16 @@ func (oid *Oid) Cmp(oid2 *Oid) int { } func (oid *Oid) Copy() *Oid { - ret := new(Oid) - copy(ret[:], oid[:]) - return ret + ret := *oid + return &ret } func (oid *Oid) Equal(oid2 *Oid) bool { - return bytes.Equal(oid[:], oid2[:]) + return *oid == *oid2 } func (oid *Oid) IsZero() bool { - for _, a := range oid { - if a != 0 { - return false - } - } - return true + return *oid == Oid{} } func (oid *Oid) NCmp(oid2 *Oid, n uint) int { From bdca40d27558337f2aa84856b0dd8c6b1b6bb5c8 Mon Sep 17 00:00:00 2001 From: Michel Lespinasse Date: Tue, 3 Jul 2018 16:43:07 -0700 Subject: [PATCH 06/19] git2go: small fixes to odb module - Fix couple cgo issues in odb.Write() and odb.Hash(). This is the same issue - and same solution - as repo.CreateBlobFromBuffer() used to have. - Add test for odb.Read() --- odb.go | 26 ++++++++++++++++++-------- odb_test.go | 33 +++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/odb.go b/odb.go index f236fc4..fa6779f 100644 --- a/odb.go +++ b/odb.go @@ -80,15 +80,19 @@ func (v *Odb) Exists(oid *Oid) bool { func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) { oid = new(Oid) - var cptr unsafe.Pointer - if len(data) > 0 { - cptr = unsafe.Pointer(&data[0]) - } runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_odb_write(oid.toC(), v.ptr, cptr, C.size_t(len(data)), C.git_otype(otype)) + var size C.size_t + if len(data) > 0 { + size = C.size_t(len(data)) + } else { + data = []byte{0} + size = C.size_t(0) + } + + ret := C.git_odb_write(oid.toC(), v.ptr, unsafe.Pointer(&data[0]), size, C.git_otype(otype)) runtime.KeepAlive(v) if ret < 0 { return nil, MakeGitError(ret) @@ -164,13 +168,19 @@ func (v *Odb) ForEach(callback OdbForEachCallback) error { // Hash determines the object-ID (sha1) of a data buffer. func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) { oid = new(Oid) - header := (*reflect.SliceHeader)(unsafe.Pointer(&data)) - ptr := unsafe.Pointer(header.Data) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_odb_hash(oid.toC(), ptr, C.size_t(header.Len), C.git_otype(otype)) + var size C.size_t + if len(data) > 0 { + size = C.size_t(len(data)) + } else { + data = []byte{0} + size = C.size_t(0) + } + + ret := C.git_odb_hash(oid.toC(), unsafe.Pointer(&data[0]), size, C.git_otype(otype)) runtime.KeepAlive(data) if ret < 0 { return nil, MakeGitError(ret) diff --git a/odb_test.go b/odb_test.go index 3d22fc9..8502c36 100644 --- a/odb_test.go +++ b/odb_test.go @@ -1,12 +1,13 @@ package git import ( + "bytes" "errors" "io" "testing" ) -func TestOdbReadHeader(t *testing.T) { +func TestOdbRead(t *testing.T) { t.Parallel() repo := createTestRepo(t) defer cleanupTestRepo(t, repo) @@ -26,13 +27,27 @@ func TestOdbReadHeader(t *testing.T) { 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) } + + obj, err := odb.Read(id) + if err != nil { + t.Fatalf("Read: %v", err) + } + if !bytes.Equal(obj.Data(), data) { + t.Errorf("Read got wrong data") + } + if sz := obj.Len(); sz != uint64(len(data)) { + t.Errorf("Read got size %d, want %d", sz, len(data)) + } + if typ := obj.Type(); typ != ObjectBlob { + t.Errorf("Read got object type %s", typ) + } } func TestOdbStream(t *testing.T) { @@ -82,14 +97,16 @@ committer John Doe 1390682018 +0000 Initial commit.` - oid, error := odb.Hash([]byte(str), ObjectCommit) - checkFatal(t, error) + for _, data := range [][]byte{[]byte(str), doublePointerBytes()} { + oid, error := odb.Hash(data, ObjectCommit) + checkFatal(t, error) - coid, error := odb.Write([]byte(str), ObjectCommit) - checkFatal(t, error) + coid, error := odb.Write(data, ObjectCommit) + checkFatal(t, error) - if oid.Cmp(coid) != 0 { - t.Fatal("Hash and write Oids are different") + if oid.Cmp(coid) != 0 { + t.Fatal("Hash and write Oids are different") + } } } From b3256d9058aa93176190cb69f73afb72f0730100 Mon Sep 17 00:00:00 2001 From: Ryan Graham Date: Tue, 8 May 2018 15:47:34 -0700 Subject: [PATCH 07/19] static: use pkg-config exclusively when using it When using the static linking option on platforms that use pkg-config, use ONLY pkg-config to get the CFLAGS and LDFLAGS. This prevents pulling in dependencies and flags for any non-vendored version that may be present on the host. The main practical effect of this is that if someone doesn't need/want any sort of remote access support at all they can completely disable libcurl, libssh2, libssl, etc and produce a smaller/simpler binary and greatly simplify their build-time dependencies. When done properly, the generated pkg-config file will tell cgo everything it needs to know. This also prevents confusion if there is a system copy of libgit2 that is being given priority over the vendored build. Signed-off-by: Ryan Graham --- git_static.go | 5 ++--- script/build-libgit2-static.sh | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/git_static.go b/git_static.go index 6303734..243669f 100644 --- a/git_static.go +++ b/git_static.go @@ -3,9 +3,8 @@ package git /* -#cgo CFLAGS: -I${SRCDIR}/vendor/libgit2/include -#cgo LDFLAGS: -L${SRCDIR}/vendor/libgit2/build/ -lgit2 -#cgo windows LDFLAGS: -lwinhttp +#cgo windows CFLAGS: -I${SRCDIR}/vendor/libgit2/include +#cgo windows LDFLAGS: -L${SRCDIR}/vendor/libgit2/build/ -lgit2 -lwinhttp #cgo !windows pkg-config: --static ${SRCDIR}/vendor/libgit2/build/libgit2.pc #include diff --git a/script/build-libgit2-static.sh b/script/build-libgit2-static.sh index 5723721..1568ece 100755 --- a/script/build-libgit2-static.sh +++ b/script/build-libgit2-static.sh @@ -16,4 +16,4 @@ cmake -DTHREADSAFE=ON \ -DCMAKE_INSTALL_PREFIX=../install \ .. && -cmake --build . +cmake --build . --target install From dd973b99ad050eae73c3cc3deac162e797c6f530 Mon Sep 17 00:00:00 2001 From: Melvin Date: Thu, 25 Oct 2018 15:13:32 -0700 Subject: [PATCH 08/19] Add index.Clear() to clear the index object --- index.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.go b/index.go index 5106516..dd13460 100644 --- a/index.go +++ b/index.go @@ -145,6 +145,20 @@ func (v *Index) Path() string { return ret } +// Clear clears the index object in memory; changes must be explicitly +// written to disk for them to take effect persistently +func (v *Index) Clear() error { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + err := C.git_index_clear(v.ptr) + runtime.KeepAlive(v) + if err < 0 { + return MakeGitError(err) + } + return nil +} + // Add adds or replaces the given entry to the index, making a copy of // the data func (v *Index) Add(entry *IndexEntry) error { From 8d27336e8a158dccc55c966f57ff7e90acce1614 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Thu, 15 Nov 2018 02:27:03 +0000 Subject: [PATCH 09/19] Add support for Packbuilder.InsertFromWalk() This change adds support for Packbuilder.InsertFromWalk() from libgit2. --- packbuilder.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packbuilder.go b/packbuilder.go index 0e04bbf..576e5ca 100644 --- a/packbuilder.go +++ b/packbuilder.go @@ -85,6 +85,19 @@ func (pb *Packbuilder) InsertTree(id *Oid) error { return nil } +func (pb *Packbuilder) InsertWalk(walk *RevWalk) error { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + ret := C.git_packbuilder_insert_walk(pb.ptr, walk.ptr) + runtime.KeepAlive(pb) + runtime.KeepAlive(walk) + if ret != 0 { + return MakeGitError(ret) + } + return nil +} + func (pb *Packbuilder) ObjectCount() uint32 { ret := uint32(C.git_packbuilder_object_count(pb.ptr)) runtime.KeepAlive(pb) From a2ac1b9ed115b7576b59a3f54abe3a93ce24d44e Mon Sep 17 00:00:00 2001 From: Will Medlar <5326769+wmedlar@users.noreply.github.com> Date: Mon, 17 Dec 2018 01:56:37 -0600 Subject: [PATCH 10/19] Fix typo in constant name --- checkout.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkout.go b/checkout.go index db3118f..2b12058 100644 --- a/checkout.go +++ b/checkout.go @@ -35,7 +35,7 @@ const ( CheckoutDontUpdateIndex CheckoutStrategy = C.GIT_CHECKOUT_DONT_UPDATE_INDEX // Normally checkout updates index entries as it goes; this stops that CheckoutNoRefresh CheckoutStrategy = C.GIT_CHECKOUT_NO_REFRESH // Don't refresh index/config/etc before doing checkout CheckoutSkipUnmerged CheckoutStrategy = C.GIT_CHECKOUT_SKIP_UNMERGED // Allow checkout to skip unmerged files - CheckoutUserOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index + CheckoutUseOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index CheckoutUseTheirs CheckoutStrategy = C.GIT_CHECKOUT_USE_THEIRS // For unmerged files, checkout stage 3 from index CheckoutDisablePathspecMatch CheckoutStrategy = C.GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH // Treat pathspec as simple list of exact match file paths CheckoutSkipLockedDirectories CheckoutStrategy = C.GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES // Ignore directories in use, they will be left empty From 92ebf4515c770993205757f98e3e7d4fa6f69166 Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 25 Dec 2018 08:27:32 +0530 Subject: [PATCH 11/19] Remove unused parameter in OpenOndisk --- config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.go b/config.go index 8dfe0af..7260089 100644 --- a/config.go +++ b/config.go @@ -344,7 +344,7 @@ func (c *Config) OpenLevel(parent *Config, level ConfigLevel) (*Config, error) { } // OpenOndisk creates a new config instance containing a single on-disk file -func OpenOndisk(parent *Config, path string) (*Config, error) { +func OpenOndisk(path string) (*Config, error) { cpath := C.CString(path) defer C.free(unsafe.Pointer(cpath)) From e0ad45065e7ae240cba5fa0a3cbe5c2ee1df85f7 Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 25 Dec 2018 08:44:01 +0530 Subject: [PATCH 12/19] Fixed issues with tests --- config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config_test.go b/config_test.go index 196d4ad..398236e 100644 --- a/config_test.go +++ b/config_test.go @@ -13,7 +13,7 @@ func setupConfig() (*Config, error) { err error ) - c, err = OpenOndisk(nil, tempConfig) + c, err = OpenOndisk(tempConfig) if err != nil { return nil, err } From 344dc33faef98cb383ec0858e33b1aea695cbc1e Mon Sep 17 00:00:00 2001 From: lhchavez Date: Fri, 28 Dec 2018 04:29:20 +0000 Subject: [PATCH 13/19] Return io.EOF on OdbReadStream.Read() This change makes OdbReadStream.Read() comply with the usual io.Reader semantics. --- odb.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/odb.go b/odb.go index f236fc4..fd27363 100644 --- a/odb.go +++ b/odb.go @@ -8,6 +8,7 @@ extern void _go_git_odb_backend_free(git_odb_backend *backend); */ import "C" import ( + "io" "reflect" "runtime" "unsafe" @@ -287,6 +288,9 @@ func (stream *OdbReadStream) Read(data []byte) (int, error) { if ret < 0 { return 0, MakeGitError(ret) } + if ret == 0 { + return 0, io.EOF + } header.Len = int(ret) From ab3470030be17e024c96b7f00c757f8343ca70f5 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Fri, 28 Dec 2018 04:42:09 +0000 Subject: [PATCH 14/19] Add some tests This should prevent regressions in the future. --- odb_test.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/odb_test.go b/odb_test.go index 3d22fc9..090bdf6 100644 --- a/odb_test.go +++ b/odb_test.go @@ -3,6 +3,7 @@ package git import ( "errors" "io" + "io/ioutil" "testing" ) @@ -26,7 +27,7 @@ func TestOdbReadHeader(t *testing.T) { if err != nil { t.Fatalf("ReadHeader: %v", err) } - + if sz != uint64(len(data)) { t.Errorf("ReadHeader got size %d, want %d", sz, len(data)) } @@ -47,22 +48,29 @@ func TestOdbStream(t *testing.T) { str := "hello, world!" - stream, error := odb.NewWriteStream(int64(len(str)), ObjectBlob) + writeStream, error := odb.NewWriteStream(int64(len(str)), ObjectBlob) checkFatal(t, error) - n, error := io.WriteString(stream, str) + n, error := io.WriteString(writeStream, str) checkFatal(t, error) if n != len(str) { t.Fatalf("Bad write length %v != %v", n, len(str)) } - error = stream.Close() + error = writeStream.Close() checkFatal(t, error) expectedId, error := NewOid("30f51a3fba5274d53522d0f19748456974647b4f") checkFatal(t, error) - if stream.Id.Cmp(expectedId) != 0 { + if writeStream.Id.Cmp(expectedId) != 0 { t.Fatal("Wrong data written") } + + readStream, error := odb.NewReadStream(&writeStream.Id) + checkFatal(t, error) + data, error := ioutil.ReadAll(readStream) + if str != string(data) { + t.Fatalf("Wrong data read %v != %v", str, string(data)) + } } func TestOdbHash(t *testing.T) { From f969cc900dde4ba92c814823bc004bd1870079a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 4 Jan 2019 13:18:54 +0000 Subject: [PATCH 15/19] Bump vendored libgit2 to fba70a9d5f This includes updating the `Index.WriteTreeTo` test as it was abusing an oversight of the object creation safety checks and creating a tree referencing a non-existent blob. Instead we update it to the primary purpose of this method which is to write into a repository from an unattached index. --- index_test.go | 26 +++++++++++++++++++++----- vendor/libgit2 | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/index_test.go b/index_test.go index f47dace..43644fa 100644 --- a/index_test.go +++ b/index_test.go @@ -3,6 +3,7 @@ package git import ( "io/ioutil" "os" + "path" "runtime" "testing" ) @@ -59,14 +60,29 @@ func TestIndexWriteTreeTo(t *testing.T) { repo := createTestRepo(t) defer cleanupTestRepo(t, repo) - repo2 := createTestRepo(t) - defer cleanupTestRepo(t, repo2) + idx, err := NewIndex() + checkFatal(t, err) - idx, err := repo.Index() + odb, err := repo.Odb() checkFatal(t, err) - err = idx.AddByPath("README") + + content, err := ioutil.ReadFile(path.Join(repo.Workdir(), "README")) checkFatal(t, err) - treeId, err := idx.WriteTreeTo(repo2) + + id, err := odb.Write(content, ObjectBlob) + checkFatal(t, err) + + err = idx.Add(&IndexEntry{ + Mode: FilemodeBlob, + Uid: 0, + Gid: 0, + Size: uint32(len(content)), + Id: id, + Path: "README", + }) + checkFatal(t, err) + + treeId, err := idx.WriteTreeTo(repo) checkFatal(t, err) if treeId.String() != "b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e" { diff --git a/vendor/libgit2 b/vendor/libgit2 index 838a2f2..fba70a9 160000 --- a/vendor/libgit2 +++ b/vendor/libgit2 @@ -1 +1 @@ -Subproject commit 838a2f2918b6d9fad8768d2498575ff5d75c35f0 +Subproject commit fba70a9d5f1fa433968a3dfd51e3153c8eebe834 From ee6dff2f8e3b130dee5e888f18cae0f74c35e8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 5 Jan 2019 10:45:30 +0000 Subject: [PATCH 16/19] Use git_object_t instead of deprecated git_otype --- object.go | 14 +++++++------- odb.go | 12 ++++++------ reference.go | 2 +- repository.go | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/object.go b/object.go index 66a4618..40ab2bf 100644 --- a/object.go +++ b/object.go @@ -13,12 +13,12 @@ import ( type ObjectType int const ( - ObjectAny ObjectType = C.GIT_OBJ_ANY - ObjectBad ObjectType = C.GIT_OBJ_BAD - ObjectCommit ObjectType = C.GIT_OBJ_COMMIT - ObjectTree ObjectType = C.GIT_OBJ_TREE - ObjectBlob ObjectType = C.GIT_OBJ_BLOB - ObjectTag ObjectType = C.GIT_OBJ_TAG + ObjectAny ObjectType = C.GIT_OBJECT_ANY + ObjectBad ObjectType = C.GIT_OBJECT_BAD + ObjectCommit ObjectType = C.GIT_OBJECT_COMMIT + ObjectTree ObjectType = C.GIT_OBJECT_TREE + ObjectBlob ObjectType = C.GIT_OBJECT_BLOB + ObjectTag ObjectType = C.GIT_OBJECT_TAG ) type Object struct { @@ -217,7 +217,7 @@ func (o *Object) Peel(t ObjectType) (*Object, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() - err := C.git_object_peel(&cobj, o.ptr, C.git_otype(t)) + err := C.git_object_peel(&cobj, o.ptr, C.git_object_t(t)) runtime.KeepAlive(o) if err < 0 { return nil, MakeGitError(err) diff --git a/odb.go b/odb.go index 7ae108a..5768cf4 100644 --- a/odb.go +++ b/odb.go @@ -61,12 +61,12 @@ func (v *Odb) ReadHeader(oid *Oid) (uint64, ObjectType, error) { defer runtime.UnlockOSThread() var sz C.size_t - var cotype C.git_otype + var cotype C.git_object_t ret := C.git_odb_read_header(&sz, &cotype, v.ptr, oid.toC()) runtime.KeepAlive(v) if ret < 0 { - return 0, C.GIT_OBJ_BAD, MakeGitError(ret) + return 0, ObjectBad, MakeGitError(ret) } return uint64(sz), ObjectType(cotype), nil @@ -93,7 +93,7 @@ func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) { size = C.size_t(0) } - ret := C.git_odb_write(oid.toC(), v.ptr, unsafe.Pointer(&data[0]), size, C.git_otype(otype)) + ret := C.git_odb_write(oid.toC(), v.ptr, unsafe.Pointer(&data[0]), size, C.git_object_t(otype)) runtime.KeepAlive(v) if ret < 0 { return nil, MakeGitError(ret) @@ -181,7 +181,7 @@ func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) { size = C.size_t(0) } - ret := C.git_odb_hash(oid.toC(), unsafe.Pointer(&data[0]), size, C.git_otype(otype)) + ret := C.git_odb_hash(oid.toC(), unsafe.Pointer(&data[0]), size, C.git_object_t(otype)) runtime.KeepAlive(data) if ret < 0 { return nil, MakeGitError(ret) @@ -193,7 +193,7 @@ func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) { // contents of the object. func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) { stream := new(OdbReadStream) - var ctype C.git_otype + var ctype C.git_object_t var csize C.size_t runtime.LockOSThread() @@ -221,7 +221,7 @@ func (v *Odb) NewWriteStream(size int64, otype ObjectType) (*OdbWriteStream, err runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.git_off_t(size), C.git_otype(otype)) + ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.git_off_t(size), C.git_object_t(otype)) runtime.KeepAlive(v) if ret < 0 { return nil, MakeGitError(ret) diff --git a/reference.go b/reference.go index 12ecb74..b5f5e47 100644 --- a/reference.go +++ b/reference.go @@ -284,7 +284,7 @@ func (v *Reference) Peel(t ObjectType) (*Object, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() - err := C.git_reference_peel(&cobj, v.ptr, C.git_otype(t)) + err := C.git_reference_peel(&cobj, v.ptr, C.git_object_t(t)) runtime.KeepAlive(v) if err < 0 { return nil, MakeGitError(err) diff --git a/repository.go b/repository.go index d8de97a..74924b7 100644 --- a/repository.go +++ b/repository.go @@ -174,7 +174,7 @@ func (v *Repository) lookupType(id *Oid, t ObjectType) (*Object, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_object_lookup(&ptr, v.ptr, id.toC(), C.git_otype(t)) + ret := C.git_object_lookup(&ptr, v.ptr, id.toC(), C.git_object_t(t)) runtime.KeepAlive(id) if ret < 0 { return nil, MakeGitError(ret) From f3c487966d53ad78e25d2e6750414009f5606dbb Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sat, 5 Jan 2019 20:13:01 +0000 Subject: [PATCH 17/19] Improve the static build script This change: * Uses the installed version of both the library and the pkgconfig file, which fixes path resolution on Ubuntu Xenial. * Uses quoting liberally so that paths with spaces in them are correctly handled. * Moves the build+install directories to static-build/ in the git2go repository to avoid having a dirty vendor/libgit2 checkout. --- .gitignore | 1 + git_static.go | 6 +++--- script/build-libgit2-static.sh | 15 ++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..edc18d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/static-build/ diff --git a/git_static.go b/git_static.go index 243669f..547ae8a 100644 --- a/git_static.go +++ b/git_static.go @@ -3,9 +3,9 @@ package git /* -#cgo windows CFLAGS: -I${SRCDIR}/vendor/libgit2/include -#cgo windows LDFLAGS: -L${SRCDIR}/vendor/libgit2/build/ -lgit2 -lwinhttp -#cgo !windows pkg-config: --static ${SRCDIR}/vendor/libgit2/build/libgit2.pc +#cgo windows CFLAGS: -I${SRCDIR}/static-build/install/include/ +#cgo windows LDFLAGS: -L${SRCDIR}/static-build/install/lib/ -lgit2 -lwinhttp +#cgo !windows pkg-config: --static ${SRCDIR}/static-build/install/lib/pkgconfig/libgit2.pc #include #if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 27 diff --git a/script/build-libgit2-static.sh b/script/build-libgit2-static.sh index 1568ece..680dd93 100755 --- a/script/build-libgit2-static.sh +++ b/script/build-libgit2-static.sh @@ -2,18 +2,19 @@ set -ex -VENDORED_PATH=vendor/libgit2 +ROOT="$(cd "$0/../.." && echo "${PWD}")" +BUILD_PATH="${ROOT}/static-build" +VENDORED_PATH="${ROOT}/vendor/libgit2" -cd $VENDORED_PATH && -mkdir -p install/lib && -mkdir -p build && -cd build && +mkdir -p "${BUILD_PATH}/build" "${BUILD_PATH}/install/lib" + +cd "${BUILD_PATH}/build" && cmake -DTHREADSAFE=ON \ -DBUILD_CLAR=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_C_FLAGS=-fPIC \ -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_INSTALL_PREFIX=../install \ - .. && + -DCMAKE_INSTALL_PREFIX="${BUILD_PATH}/install" \ + "${VENDORED_PATH}" && cmake --build . --target install From e9856f2c38b4cf74341dd9706bff79d95ff9cb21 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sat, 5 Jan 2019 21:42:49 +0000 Subject: [PATCH 18/19] Clean up one leaked temporary directory A `defer cleanupTestRepo()` was missing. --- reset_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reset_test.go b/reset_test.go index 45777e4..89ebc49 100644 --- a/reset_test.go +++ b/reset_test.go @@ -8,6 +8,8 @@ import ( func TestResetToCommit(t *testing.T) { t.Parallel() repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + seedTestRepo(t, repo) // create commit to reset to commitId, _ := updateReadme(t, repo, "testing reset") From 30c57ff09ef08b4019701320f328b3587e326df0 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sun, 6 Jan 2019 07:34:50 -0800 Subject: [PATCH 19/19] Add support for Go 1.11 modules This change adds a `go.mod` file. An empty file is sufficient since this project has no external dependencies. For people that want to use the static version of libgit2, this module can be vendored and the following can be added to their `go.mod` file: replace github.com/libgit2/git2go => ./vendor/github.com/libgit2/git2go --- go.mod | 1 + 1 file changed, 1 insertion(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..688b8e3 --- /dev/null +++ b/go.mod @@ -0,0 +1 @@ +module github.com/libgit2/git2go