Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit bf0593d

Browse files
committed
Merge branch 'master' of github.com:src-d/go-git into f-add-tagging-support
2 parents f8adfff + a2d62f5 commit bf0593d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1028
-187
lines changed

common_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"gopkg.in/src-d/go-git.v4/plumbing"
7+
"gopkg.in/src-d/go-git.v4/plumbing/cache"
78
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
89
"gopkg.in/src-d/go-git.v4/plumbing/transport"
910
"gopkg.in/src-d/go-git.v4/storage/filesystem"
@@ -59,10 +60,7 @@ func (s *BaseSuite) NewRepository(f *fixtures.Fixture) *Repository {
5960
dotgit = f.DotGit()
6061
worktree = memfs.New()
6162

62-
st, err := filesystem.NewStorage(dotgit)
63-
if err != nil {
64-
panic(err)
65-
}
63+
st := filesystem.NewStorage(dotgit, cache.NewObjectLRUDefault())
6664

6765
r, err := Open(st, worktree)
6866
if err != nil {
@@ -89,10 +87,7 @@ func (s *BaseSuite) NewRepositoryWithEmptyWorktree(f *fixtures.Fixture) *Reposit
8987

9088
worktree := memfs.New()
9189

92-
st, err := filesystem.NewStorage(dotgit)
93-
if err != nil {
94-
panic(err)
95-
}
90+
st := filesystem.NewStorage(dotgit, cache.NewObjectLRUDefault())
9691

9792
r, err := Open(st, worktree)
9893
if err != nil {

config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type Config struct {
4040
IsBare bool
4141
// Worktree is the path to the root of the working tree.
4242
Worktree string
43+
// CommentChar is the character indicating the start of a
44+
// comment for commands like commit and tag
45+
CommentChar string
4346
}
4447

4548
Pack struct {
@@ -113,6 +116,7 @@ const (
113116
urlKey = "url"
114117
bareKey = "bare"
115118
worktreeKey = "worktree"
119+
commentCharKey = "commentChar"
116120
windowKey = "window"
117121
mergeKey = "merge"
118122

@@ -151,6 +155,7 @@ func (c *Config) unmarshalCore() {
151155
}
152156

153157
c.Core.Worktree = s.Options.Get(worktreeKey)
158+
c.Core.CommentChar = s.Options.Get(commentCharKey)
154159
}
155160

156161
func (c *Config) unmarshalPack() error {

config/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func (s *ConfigSuite) TestUnmarshall(c *C) {
1313
input := []byte(`[core]
1414
bare = true
1515
worktree = foo
16+
commentchar = bar
1617
[pack]
1718
window = 20
1819
[remote "origin"]
@@ -38,6 +39,7 @@ func (s *ConfigSuite) TestUnmarshall(c *C) {
3839

3940
c.Assert(cfg.Core.IsBare, Equals, true)
4041
c.Assert(cfg.Core.Worktree, Equals, "foo")
42+
c.Assert(cfg.Core.CommentChar, Equals, "bar")
4143
c.Assert(cfg.Pack.Window, Equals, uint(20))
4244
c.Assert(cfg.Remotes, HasLen, 2)
4345
c.Assert(cfg.Remotes["origin"].Name, Equals, "origin")

plumbing/format/diff/unified_encoder.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,13 @@ func (c *hunksGenerator) addLineNumbers(la, lb int, linesBefore int, i int, op O
237237
// we need to search for a reference for the next diff
238238
switch {
239239
case linesBefore != 0 && c.ctxLines != 0:
240-
clb = lb - c.ctxLines + 1
240+
if lb > c.ctxLines {
241+
clb = lb - c.ctxLines + 1
242+
} else {
243+
clb = 1
244+
}
241245
case c.ctxLines == 0:
242-
clb = lb - c.ctxLines
246+
clb = lb
243247
case i != len(c.chunks)-1:
244248
next := c.chunks[i+1]
245249
if next.Type() == op || next.Type() == Equal {

plumbing/format/diff/unified_encoder_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,43 @@ var oneChunkPatchInverted Patch = testPatch{
150150
}
151151

152152
var fixtures []*fixture = []*fixture{{
153+
patch: testPatch{
154+
message: "",
155+
filePatches: []testFilePatch{{
156+
from: &testFile{
157+
mode: filemode.Regular,
158+
path: "README.md",
159+
seed: "hello\nworld\n",
160+
},
161+
to: &testFile{
162+
mode: filemode.Regular,
163+
path: "README.md",
164+
seed: "hello\nbug\n",
165+
},
166+
chunks: []testChunk{{
167+
content: "hello",
168+
op: Equal,
169+
}, {
170+
content: "world",
171+
op: Delete,
172+
}, {
173+
content: "bug",
174+
op: Add,
175+
}},
176+
}},
177+
},
178+
desc: "positive negative number",
179+
context: 2,
180+
diff: `diff --git a/README.md b/README.md
181+
index 94954abda49de8615a048f8d2e64b5de848e27a1..f3dad9514629b9ff9136283ae331ad1fc95748a8 100644
182+
--- a/README.md
183+
+++ b/README.md
184+
@@ -1,2 +1,2 @@
185+
hello
186+
-world
187+
+bug
188+
`,
189+
}, {
153190
patch: testPatch{
154191
message: "",
155192
filePatches: []testFilePatch{{

plumbing/format/gitignore/pattern.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ func (p *pattern) globMatch(path []string, isDir bool) bool {
133133
} else if match {
134134
matched = true
135135
break
136+
} else if len(path) == 0 {
137+
// if nothing left then fail
138+
matched = false
136139
}
137140
}
138141
} else {

plumbing/format/gitignore/pattern_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,9 @@ func (s *PatternSuite) TestGlobMatch_wrongPattern_onTraversal_mismatch(c *C) {
281281
r := p.Match([]string{"value", "head", "vol["}, false)
282282
c.Assert(r, Equals, NoMatch)
283283
}
284+
285+
func (s *PatternSuite) TestGlobMatch_issue_923(c *C) {
286+
p := ParsePattern("**/android/**/GeneratedPluginRegistrant.java", nil)
287+
r := p.Match([]string{"packages", "flutter_tools", "lib", "src", "android", "gradle.dart"}, false)
288+
c.Assert(r, Equals, NoMatch)
289+
}

plumbing/format/idxfile/idxfile.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package idxfile
33
import (
44
"bytes"
55
"io"
6+
"sort"
67

78
"gopkg.in/src-d/go-git.v4/plumbing"
89
"gopkg.in/src-d/go-git.v4/utils/binary"
@@ -34,6 +35,9 @@ type Index interface {
3435
Count() (int64, error)
3536
// Entries returns an iterator to retrieve all index entries.
3637
Entries() (EntryIter, error)
38+
// EntriesByOffset returns an iterator to retrieve all index entries ordered
39+
// by offset.
40+
EntriesByOffset() (EntryIter, error)
3741
}
3842

3943
// MemoryIndex is the in memory representation of an idx file.
@@ -215,6 +219,36 @@ func (idx *MemoryIndex) Entries() (EntryIter, error) {
215219
return &idxfileEntryIter{idx, 0, 0, 0}, nil
216220
}
217221

222+
// EntriesByOffset implements the Index interface.
223+
func (idx *MemoryIndex) EntriesByOffset() (EntryIter, error) {
224+
count, err := idx.Count()
225+
if err != nil {
226+
return nil, err
227+
}
228+
229+
iter := &idxfileEntryOffsetIter{
230+
entries: make(entriesByOffset, count),
231+
}
232+
233+
entries, err := idx.Entries()
234+
if err != nil {
235+
return nil, err
236+
}
237+
238+
for pos := 0; int64(pos) < count; pos++ {
239+
entry, err := entries.Next()
240+
if err != nil {
241+
return nil, err
242+
}
243+
244+
iter.entries[pos] = entry
245+
}
246+
247+
sort.Sort(iter.entries)
248+
249+
return iter, nil
250+
}
251+
218252
// EntryIter is an iterator that will return the entries in a packfile index.
219253
type EntryIter interface {
220254
// Next returns the next entry in the packfile index.
@@ -276,3 +310,38 @@ type Entry struct {
276310
CRC32 uint32
277311
Offset uint64
278312
}
313+
314+
type idxfileEntryOffsetIter struct {
315+
entries entriesByOffset
316+
pos int
317+
}
318+
319+
func (i *idxfileEntryOffsetIter) Next() (*Entry, error) {
320+
if i.pos >= len(i.entries) {
321+
return nil, io.EOF
322+
}
323+
324+
entry := i.entries[i.pos]
325+
i.pos++
326+
327+
return entry, nil
328+
}
329+
330+
func (i *idxfileEntryOffsetIter) Close() error {
331+
i.pos = len(i.entries) + 1
332+
return nil
333+
}
334+
335+
type entriesByOffset []*Entry
336+
337+
func (o entriesByOffset) Len() int {
338+
return len(o)
339+
}
340+
341+
func (o entriesByOffset) Less(i int, j int) bool {
342+
return o[i].Offset < o[j].Offset
343+
}
344+
345+
func (o entriesByOffset) Swap(i int, j int) {
346+
o[i], o[j] = o[j], o[i]
347+
}

plumbing/format/idxfile/idxfile_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ func (s *IndexSuite) TestFindHash(c *C) {
115115
}
116116
}
117117

118+
func (s *IndexSuite) TestEntriesByOffset(c *C) {
119+
idx, err := fixtureIndex()
120+
c.Assert(err, IsNil)
121+
122+
entries, err := idx.EntriesByOffset()
123+
c.Assert(err, IsNil)
124+
125+
for _, pos := range fixtureOffsets {
126+
e, err := entries.Next()
127+
c.Assert(err, IsNil)
128+
129+
c.Assert(e.Offset, Equals, uint64(pos))
130+
}
131+
}
132+
118133
var fixtureHashes = []plumbing.Hash{
119134
plumbing.NewHash("303953e5aa461c203a324821bc1717f9b4fff895"),
120135
plumbing.NewHash("5296768e3d9f661387ccbff18c4dea6c997fd78c"),

plumbing/format/packfile/encoder_advanced_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"gopkg.in/src-d/go-billy.v4/memfs"
1010
"gopkg.in/src-d/go-git.v4/plumbing"
11+
"gopkg.in/src-d/go-git.v4/plumbing/cache"
1112
"gopkg.in/src-d/go-git.v4/plumbing/format/idxfile"
1213
. "gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
1314
"gopkg.in/src-d/go-git.v4/plumbing/storer"
@@ -32,8 +33,7 @@ func (s *EncoderAdvancedSuite) TestEncodeDecode(c *C) {
3233
fixs = append(fixs, fixtures.ByURL("https://github.com/src-d/go-git.git").
3334
ByTag("packfile").ByTag(".git").One())
3435
fixs.Test(c, func(f *fixtures.Fixture) {
35-
storage, err := filesystem.NewStorage(f.DotGit())
36-
c.Assert(err, IsNil)
36+
storage := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
3737
s.testEncodeDecode(c, storage, 10)
3838
})
3939
}
@@ -47,8 +47,7 @@ func (s *EncoderAdvancedSuite) TestEncodeDecodeNoDeltaCompression(c *C) {
4747
fixs = append(fixs, fixtures.ByURL("https://github.com/src-d/go-git.git").
4848
ByTag("packfile").ByTag(".git").One())
4949
fixs.Test(c, func(f *fixtures.Fixture) {
50-
storage, err := filesystem.NewStorage(f.DotGit())
51-
c.Assert(err, IsNil)
50+
storage := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
5251
s.testEncodeDecode(c, storage, 0)
5352
})
5453
}

0 commit comments

Comments
 (0)