Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into mempack
Browse files Browse the repository at this point in the history
  • Loading branch information
lhchavez committed Jan 8, 2019
2 parents d7fd15b + 2609f4c commit b609c04
Show file tree
Hide file tree
Showing 28 changed files with 204 additions and 83 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/static-build/
4 changes: 2 additions & 2 deletions branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (repo *Repository) RemoteName(canonicalBranchName string) (string, error) {
if ret < 0 {
return "", MakeGitError(ret)
}
defer C.git_buf_free(&nameBuf)
defer C.git_buf_dispose(&nameBuf)

return C.GoString(nameBuf.ptr), nil
}
Expand Down Expand Up @@ -256,7 +256,7 @@ func (repo *Repository) UpstreamName(canonicalBranchName string) (string, error)
if ret < 0 {
return "", MakeGitError(ret)
}
defer C.git_buf_free(&nameBuf)
defer C.git_buf_dispose(&nameBuf)

return C.GoString(nameBuf.ptr), nil
}
2 changes: 1 addition & 1 deletion checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func (c *Commit) RawMessage() string {
func (c *Commit) ExtractSignature() (string, string, error) {

var c_signed C.git_buf
defer C.git_buf_free(&c_signed)
defer C.git_buf_dispose(&c_signed)

var c_signature C.git_buf
defer C.git_buf_free(&c_signature)
defer C.git_buf_dispose(&c_signature)

oid := c.Id()
repo := C.git_commit_owner(c.cast_ptr)
Expand Down
12 changes: 6 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (c *Config) LookupString(name string) (string, error) {
if ret < 0 {
return "", MakeGitError(ret)
}
defer C.git_buf_free(&valBuf)
defer C.git_buf_dispose(&valBuf)

return C.GoString(valBuf.ptr), nil
}
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -390,7 +390,7 @@ func (iter *ConfigIterator) Free() {

func ConfigFindGlobal() (string, error) {
var buf C.git_buf
defer C.git_buf_free(&buf)
defer C.git_buf_dispose(&buf)

runtime.LockOSThread()
defer runtime.UnlockOSThread()
Expand All @@ -405,7 +405,7 @@ func ConfigFindGlobal() (string, error) {

func ConfigFindSystem() (string, error) {
var buf C.git_buf
defer C.git_buf_free(&buf)
defer C.git_buf_dispose(&buf)

runtime.LockOSThread()
defer runtime.UnlockOSThread()
Expand All @@ -420,7 +420,7 @@ func ConfigFindSystem() (string, error) {

func ConfigFindXDG() (string, error) {
var buf C.git_buf
defer C.git_buf_free(&buf)
defer C.git_buf_dispose(&buf)

runtime.LockOSThread()
defer runtime.UnlockOSThread()
Expand All @@ -438,7 +438,7 @@ func ConfigFindXDG() (string, error) {
// Look for the file in %PROGRAMDATA%\Git\config used by portable git.
func ConfigFindProgramdata() (string, error) {
var buf C.git_buf
defer C.git_buf_free(&buf)
defer C.git_buf_dispose(&buf)

runtime.LockOSThread()
defer runtime.UnlockOSThread()
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (result *DescribeResult) Format(opts *DescribeFormatOptions) (string, error
if ecode < 0 {
return "", MakeGitError(ecode)
}
defer C.git_buf_free(&resultBuf)
defer C.git_buf_dispose(&resultBuf)

return C.GoString(resultBuf.ptr), nil
}
Expand Down
2 changes: 1 addition & 1 deletion diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const (
func (stats *DiffStats) String(format DiffStatsFormat,
width uint) (string, error) {
buf := C.git_buf{}
defer C.git_buf_free(&buf)
defer C.git_buf_dispose(&buf)

runtime.LockOSThread()
defer runtime.UnlockOSThread()
Expand Down
16 changes: 5 additions & 11 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -309,7 +303,7 @@ func Discover(start string, across_fs bool, ceiling_dirs []string) (string, erro
defer C.free(unsafe.Pointer(cstart))

var buf C.git_buf
defer C.git_buf_free(&buf)
defer C.git_buf_dispose(&buf)

runtime.LockOSThread()
defer runtime.UnlockOSThread()
Expand Down
7 changes: 3 additions & 4 deletions git_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
package git

/*
#cgo CFLAGS: -I${SRCDIR}/vendor/libgit2/include
#cgo LDFLAGS: -L${SRCDIR}/vendor/libgit2/build/ -lgit2
#cgo windows LDFLAGS: -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 <git2.h>
#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 27
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module github.com/libgit2/git2go
14 changes: 14 additions & 0 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 21 additions & 5 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package git
import (
"io/ioutil"
"os"
"path"
"runtime"
"testing"
)
Expand Down Expand Up @@ -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)

id, err := odb.Write(content, ObjectBlob)
checkFatal(t, err)
treeId, err := idx.WriteTreeTo(repo2)

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" {
Expand Down
24 changes: 22 additions & 2 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion note.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c *NoteCollection) DefaultRef() (string, error) {
}

ret := C.GoString(buf.ptr)
C.git_buf_free(&buf)
C.git_buf_dispose(&buf)

return ret, nil
}
Expand Down
16 changes: 8 additions & 8 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -67,7 +67,7 @@ func (o *Object) ShortId() (string, error) {
if ecode < 0 {
return "", MakeGitError(ecode)
}
defer C.git_buf_free(&resultBuf)
defer C.git_buf_dispose(&resultBuf)
return C.GoString(resultBuf.ptr), nil
}

Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit b609c04

Please sign in to comment.