Skip to content

Commit b609c04

Browse files
committed
Merge remote-tracking branch 'upstream/master' into mempack
2 parents d7fd15b + 2609f4c commit b609c04

28 files changed

+204
-83
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/static-build/

branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (repo *Repository) RemoteName(canonicalBranchName string) (string, error) {
208208
if ret < 0 {
209209
return "", MakeGitError(ret)
210210
}
211-
defer C.git_buf_free(&nameBuf)
211+
defer C.git_buf_dispose(&nameBuf)
212212

213213
return C.GoString(nameBuf.ptr), nil
214214
}
@@ -256,7 +256,7 @@ func (repo *Repository) UpstreamName(canonicalBranchName string) (string, error)
256256
if ret < 0 {
257257
return "", MakeGitError(ret)
258258
}
259-
defer C.git_buf_free(&nameBuf)
259+
defer C.git_buf_dispose(&nameBuf)
260260

261261
return C.GoString(nameBuf.ptr), nil
262262
}

checkout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const (
3535
CheckoutDontUpdateIndex CheckoutStrategy = C.GIT_CHECKOUT_DONT_UPDATE_INDEX // Normally checkout updates index entries as it goes; this stops that
3636
CheckoutNoRefresh CheckoutStrategy = C.GIT_CHECKOUT_NO_REFRESH // Don't refresh index/config/etc before doing checkout
3737
CheckoutSkipUnmerged CheckoutStrategy = C.GIT_CHECKOUT_SKIP_UNMERGED // Allow checkout to skip unmerged files
38-
CheckoutUserOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index
38+
CheckoutUseOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index
3939
CheckoutUseTheirs CheckoutStrategy = C.GIT_CHECKOUT_USE_THEIRS // For unmerged files, checkout stage 3 from index
4040
CheckoutDisablePathspecMatch CheckoutStrategy = C.GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH // Treat pathspec as simple list of exact match file paths
4141
CheckoutSkipLockedDirectories CheckoutStrategy = C.GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES // Ignore directories in use, they will be left empty

commit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ func (c *Commit) RawMessage() string {
3737
func (c *Commit) ExtractSignature() (string, string, error) {
3838

3939
var c_signed C.git_buf
40-
defer C.git_buf_free(&c_signed)
40+
defer C.git_buf_dispose(&c_signed)
4141

4242
var c_signature C.git_buf
43-
defer C.git_buf_free(&c_signature)
43+
defer C.git_buf_dispose(&c_signature)
4444

4545
oid := c.Id()
4646
repo := C.git_commit_owner(c.cast_ptr)

config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (c *Config) LookupString(name string) (string, error) {
134134
if ret < 0 {
135135
return "", MakeGitError(ret)
136136
}
137-
defer C.git_buf_free(&valBuf)
137+
defer C.git_buf_dispose(&valBuf)
138138

139139
return C.GoString(valBuf.ptr), nil
140140
}
@@ -344,7 +344,7 @@ func (c *Config) OpenLevel(parent *Config, level ConfigLevel) (*Config, error) {
344344
}
345345

346346
// OpenOndisk creates a new config instance containing a single on-disk file
347-
func OpenOndisk(parent *Config, path string) (*Config, error) {
347+
func OpenOndisk(path string) (*Config, error) {
348348
cpath := C.CString(path)
349349
defer C.free(unsafe.Pointer(cpath))
350350

@@ -390,7 +390,7 @@ func (iter *ConfigIterator) Free() {
390390

391391
func ConfigFindGlobal() (string, error) {
392392
var buf C.git_buf
393-
defer C.git_buf_free(&buf)
393+
defer C.git_buf_dispose(&buf)
394394

395395
runtime.LockOSThread()
396396
defer runtime.UnlockOSThread()
@@ -405,7 +405,7 @@ func ConfigFindGlobal() (string, error) {
405405

406406
func ConfigFindSystem() (string, error) {
407407
var buf C.git_buf
408-
defer C.git_buf_free(&buf)
408+
defer C.git_buf_dispose(&buf)
409409

410410
runtime.LockOSThread()
411411
defer runtime.UnlockOSThread()
@@ -420,7 +420,7 @@ func ConfigFindSystem() (string, error) {
420420

421421
func ConfigFindXDG() (string, error) {
422422
var buf C.git_buf
423-
defer C.git_buf_free(&buf)
423+
defer C.git_buf_dispose(&buf)
424424

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

443443
runtime.LockOSThread()
444444
defer runtime.UnlockOSThread()

config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func setupConfig() (*Config, error) {
1313
err error
1414
)
1515

16-
c, err = OpenOndisk(nil, tempConfig)
16+
c, err = OpenOndisk(tempConfig)
1717
if err != nil {
1818
return nil, err
1919
}

describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (result *DescribeResult) Format(opts *DescribeFormatOptions) (string, error
212212
if ecode < 0 {
213213
return "", MakeGitError(ecode)
214214
}
215-
defer C.git_buf_free(&resultBuf)
215+
defer C.git_buf_dispose(&resultBuf)
216216

217217
return C.GoString(resultBuf.ptr), nil
218218
}

diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const (
246246
func (stats *DiffStats) String(format DiffStatsFormat,
247247
width uint) (string, error) {
248248
buf := C.git_buf{}
249-
defer C.git_buf_free(&buf)
249+
defer C.git_buf_dispose(&buf)
250250

251251
runtime.LockOSThread()
252252
defer runtime.UnlockOSThread()

git.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,16 @@ func (oid *Oid) Cmp(oid2 *Oid) int {
189189
}
190190

191191
func (oid *Oid) Copy() *Oid {
192-
ret := new(Oid)
193-
copy(ret[:], oid[:])
194-
return ret
192+
ret := *oid
193+
return &ret
195194
}
196195

197196
func (oid *Oid) Equal(oid2 *Oid) bool {
198-
return bytes.Equal(oid[:], oid2[:])
197+
return *oid == *oid2
199198
}
200199

201200
func (oid *Oid) IsZero() bool {
202-
for _, a := range oid {
203-
if a != 0 {
204-
return false
205-
}
206-
}
207-
return true
201+
return *oid == Oid{}
208202
}
209203

210204
func (oid *Oid) NCmp(oid2 *Oid, n uint) int {
@@ -309,7 +303,7 @@ func Discover(start string, across_fs bool, ceiling_dirs []string) (string, erro
309303
defer C.free(unsafe.Pointer(cstart))
310304

311305
var buf C.git_buf
312-
defer C.git_buf_free(&buf)
306+
defer C.git_buf_dispose(&buf)
313307

314308
runtime.LockOSThread()
315309
defer runtime.UnlockOSThread()

git_static.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
package git
44

55
/*
6-
#cgo CFLAGS: -I${SRCDIR}/vendor/libgit2/include
7-
#cgo LDFLAGS: -L${SRCDIR}/vendor/libgit2/build/ -lgit2
8-
#cgo windows LDFLAGS: -lwinhttp
9-
#cgo !windows pkg-config: --static ${SRCDIR}/vendor/libgit2/build/libgit2.pc
6+
#cgo windows CFLAGS: -I${SRCDIR}/static-build/install/include/
7+
#cgo windows LDFLAGS: -L${SRCDIR}/static-build/install/lib/ -lgit2 -lwinhttp
8+
#cgo !windows pkg-config: --static ${SRCDIR}/static-build/install/lib/pkgconfig/libgit2.pc
109
#include <git2.h>
1110
1211
#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 27

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module github.com/libgit2/git2go

index.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ func (v *Index) Path() string {
145145
return ret
146146
}
147147

148+
// Clear clears the index object in memory; changes must be explicitly
149+
// written to disk for them to take effect persistently
150+
func (v *Index) Clear() error {
151+
runtime.LockOSThread()
152+
defer runtime.UnlockOSThread()
153+
154+
err := C.git_index_clear(v.ptr)
155+
runtime.KeepAlive(v)
156+
if err < 0 {
157+
return MakeGitError(err)
158+
}
159+
return nil
160+
}
161+
148162
// Add adds or replaces the given entry to the index, making a copy of
149163
// the data
150164
func (v *Index) Add(entry *IndexEntry) error {

index_test.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package git
33
import (
44
"io/ioutil"
55
"os"
6+
"path"
67
"runtime"
78
"testing"
89
)
@@ -59,14 +60,29 @@ func TestIndexWriteTreeTo(t *testing.T) {
5960
repo := createTestRepo(t)
6061
defer cleanupTestRepo(t, repo)
6162

62-
repo2 := createTestRepo(t)
63-
defer cleanupTestRepo(t, repo2)
63+
idx, err := NewIndex()
64+
checkFatal(t, err)
6465

65-
idx, err := repo.Index()
66+
odb, err := repo.Odb()
6667
checkFatal(t, err)
67-
err = idx.AddByPath("README")
68+
69+
content, err := ioutil.ReadFile(path.Join(repo.Workdir(), "README"))
70+
checkFatal(t, err)
71+
72+
id, err := odb.Write(content, ObjectBlob)
6873
checkFatal(t, err)
69-
treeId, err := idx.WriteTreeTo(repo2)
74+
75+
err = idx.Add(&IndexEntry{
76+
Mode: FilemodeBlob,
77+
Uid: 0,
78+
Gid: 0,
79+
Size: uint32(len(content)),
80+
Id: id,
81+
Path: "README",
82+
})
83+
checkFatal(t, err)
84+
85+
treeId, err := idx.WriteTreeTo(repo)
7086
checkFatal(t, err)
7187

7288
if treeId.String() != "b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e" {

merge.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,29 @@ type MergeFileFlags int
344344
const (
345345
MergeFileDefault MergeFileFlags = C.GIT_MERGE_FILE_DEFAULT
346346

347-
MergeFileStyleMerge MergeFileFlags = C.GIT_MERGE_FILE_STYLE_MERGE
348-
MergeFileStyleDiff MergeFileFlags = C.GIT_MERGE_FILE_STYLE_DIFF3
347+
// Create standard conflicted merge files
348+
MergeFileStyleMerge MergeFileFlags = C.GIT_MERGE_FILE_STYLE_MERGE
349+
350+
// Create diff3-style files
351+
MergeFileStyleDiff MergeFileFlags = C.GIT_MERGE_FILE_STYLE_DIFF3
352+
353+
// Condense non-alphanumeric regions for simplified diff file
349354
MergeFileStyleSimplifyAlnum MergeFileFlags = C.GIT_MERGE_FILE_SIMPLIFY_ALNUM
355+
356+
// Ignore all whitespace
357+
MergeFileIgnoreWhitespace MergeFileFlags = C.GIT_MERGE_FILE_IGNORE_WHITESPACE
358+
359+
// Ignore changes in amount of whitespace
360+
MergeFileIgnoreWhitespaceChange MergeFileFlags = C.GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE
361+
362+
// Ignore whitespace at end of line
363+
MergeFileIgnoreWhitespaceEOL MergeFileFlags = C.GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL
364+
365+
// Use the "patience diff" algorithm
366+
MergeFileDiffPatience MergeFileFlags = C.GIT_MERGE_FILE_DIFF_PATIENCE
367+
368+
// Take extra time to find minimal diff
369+
MergeFileDiffMinimal MergeFileFlags = C.GIT_MERGE_FILE_DIFF_MINIMAL
350370
)
351371

352372
type MergeFileOptions struct {

note.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (c *NoteCollection) DefaultRef() (string, error) {
132132
}
133133

134134
ret := C.GoString(buf.ptr)
135-
C.git_buf_free(&buf)
135+
C.git_buf_dispose(&buf)
136136

137137
return ret, nil
138138
}

object.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
type ObjectType int
1414

1515
const (
16-
ObjectAny ObjectType = C.GIT_OBJ_ANY
17-
ObjectBad ObjectType = C.GIT_OBJ_BAD
18-
ObjectCommit ObjectType = C.GIT_OBJ_COMMIT
19-
ObjectTree ObjectType = C.GIT_OBJ_TREE
20-
ObjectBlob ObjectType = C.GIT_OBJ_BLOB
21-
ObjectTag ObjectType = C.GIT_OBJ_TAG
16+
ObjectAny ObjectType = C.GIT_OBJECT_ANY
17+
ObjectBad ObjectType = C.GIT_OBJECT_BAD
18+
ObjectCommit ObjectType = C.GIT_OBJECT_COMMIT
19+
ObjectTree ObjectType = C.GIT_OBJECT_TREE
20+
ObjectBlob ObjectType = C.GIT_OBJECT_BLOB
21+
ObjectTag ObjectType = C.GIT_OBJECT_TAG
2222
)
2323

2424
type Object struct {
@@ -67,7 +67,7 @@ func (o *Object) ShortId() (string, error) {
6767
if ecode < 0 {
6868
return "", MakeGitError(ecode)
6969
}
70-
defer C.git_buf_free(&resultBuf)
70+
defer C.git_buf_dispose(&resultBuf)
7171
return C.GoString(resultBuf.ptr), nil
7272
}
7373

@@ -217,7 +217,7 @@ func (o *Object) Peel(t ObjectType) (*Object, error) {
217217
runtime.LockOSThread()
218218
defer runtime.UnlockOSThread()
219219

220-
err := C.git_object_peel(&cobj, o.ptr, C.git_otype(t))
220+
err := C.git_object_peel(&cobj, o.ptr, C.git_object_t(t))
221221
runtime.KeepAlive(o)
222222
if err < 0 {
223223
return nil, MakeGitError(err)

0 commit comments

Comments
 (0)