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

Commit 208b3c3

Browse files
authored
Merge pull request #949 from kuba--/custom-cache
Expose Storage cache.
2 parents a4b12e4 + 8f6b312 commit 208b3c3

25 files changed

+111
-165
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 {

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
}

plumbing/object/change_adaptor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"sort"
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/filemode"
89
"gopkg.in/src-d/go-git.v4/plumbing/storer"
910
"gopkg.in/src-d/go-git.v4/storage/filesystem"
@@ -23,8 +24,7 @@ type ChangeAdaptorSuite struct {
2324
func (s *ChangeAdaptorSuite) SetUpSuite(c *C) {
2425
s.Suite.SetUpSuite(c)
2526
s.Fixture = fixtures.Basic().One()
26-
sto, err := filesystem.NewStorage(s.Fixture.DotGit())
27-
c.Assert(err, IsNil)
27+
sto := filesystem.NewStorage(s.Fixture.DotGit(), cache.NewObjectLRUDefault())
2828
s.Storer = sto
2929
}
3030

plumbing/object/change_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"sort"
66

77
"gopkg.in/src-d/go-git.v4/plumbing"
8+
"gopkg.in/src-d/go-git.v4/plumbing/cache"
89
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
910
"gopkg.in/src-d/go-git.v4/plumbing/format/diff"
1011
"gopkg.in/src-d/go-git.v4/plumbing/storer"
@@ -25,8 +26,7 @@ func (s *ChangeSuite) SetUpSuite(c *C) {
2526
s.Suite.SetUpSuite(c)
2627
s.Fixture = fixtures.ByURL("https://github.com/src-d/go-git.git").
2728
ByTag(".git").One()
28-
sto, err := filesystem.NewStorage(s.Fixture.DotGit())
29-
c.Assert(err, IsNil)
29+
sto := filesystem.NewStorage(s.Fixture.DotGit(), cache.NewObjectLRUDefault())
3030
s.Storer = sto
3131
}
3232

@@ -253,8 +253,7 @@ func (s *ChangeSuite) TestNoFileFilemodes(c *C) {
253253
s.Suite.SetUpSuite(c)
254254
f := fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One()
255255

256-
sto, err := filesystem.NewStorage(f.DotGit())
257-
c.Assert(err, IsNil)
256+
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
258257

259258
iter, err := sto.IterEncodedObjects(plumbing.AnyObject)
260259
c.Assert(err, IsNil)

plumbing/object/commit_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"gopkg.in/src-d/go-git.v4/plumbing"
11+
"gopkg.in/src-d/go-git.v4/plumbing/cache"
1112

1213
. "gopkg.in/check.v1"
1314
"gopkg.in/src-d/go-git-fixtures.v3"
@@ -247,8 +248,7 @@ func (s *SuiteCommit) TestStringMultiLine(c *C) {
247248
hash := plumbing.NewHash("e7d896db87294e33ca3202e536d4d9bb16023db3")
248249

249250
f := fixtures.ByURL("https://github.com/src-d/go-git.git").One()
250-
sto, err := filesystem.NewStorage(f.DotGit())
251-
c.Assert(err, IsNil)
251+
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
252252

253253
o, err := sto.EncodedObject(plumbing.CommitObject, hash)
254254
c.Assert(err, IsNil)

plumbing/object/difftree_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"sort"
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/filemode"
89
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
910
"gopkg.in/src-d/go-git.v4/plumbing/storer"
@@ -25,8 +26,7 @@ type DiffTreeSuite struct {
2526
func (s *DiffTreeSuite) SetUpSuite(c *C) {
2627
s.Suite.SetUpSuite(c)
2728
s.Fixture = fixtures.Basic().One()
28-
sto, err := filesystem.NewStorage(s.Fixture.DotGit())
29-
c.Assert(err, IsNil)
29+
sto := filesystem.NewStorage(s.Fixture.DotGit(), cache.NewObjectLRUDefault())
3030
s.Storer = sto
3131
s.cache = make(map[string]storer.EncodedObjectStorer)
3232
}

plumbing/object/file_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io"
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/filemode"
89
"gopkg.in/src-d/go-git.v4/plumbing/storer"
910
"gopkg.in/src-d/go-git.v4/storage/filesystem"
@@ -44,8 +45,7 @@ var fileIterTests = []struct {
4445
func (s *FileSuite) TestIter(c *C) {
4546
for i, t := range fileIterTests {
4647
f := fixtures.ByURL(t.repo).One()
47-
sto, err := filesystem.NewStorage(f.DotGit())
48-
c.Assert(err, IsNil)
48+
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
4949

5050
h := plumbing.NewHash(t.commit)
5151
commit, err := GetCommit(sto, h)
@@ -106,8 +106,7 @@ hs_err_pid*
106106
func (s *FileSuite) TestContents(c *C) {
107107
for i, t := range contentsTests {
108108
f := fixtures.ByURL(t.repo).One()
109-
sto, err := filesystem.NewStorage(f.DotGit())
110-
c.Assert(err, IsNil)
109+
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
111110

112111
h := plumbing.NewHash(t.commit)
113112
commit, err := GetCommit(sto, h)
@@ -160,8 +159,7 @@ var linesTests = []struct {
160159
func (s *FileSuite) TestLines(c *C) {
161160
for i, t := range linesTests {
162161
f := fixtures.ByURL(t.repo).One()
163-
sto, err := filesystem.NewStorage(f.DotGit())
164-
c.Assert(err, IsNil)
162+
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
165163

166164
h := plumbing.NewHash(t.commit)
167165
commit, err := GetCommit(sto, h)
@@ -195,8 +193,7 @@ var ignoreEmptyDirEntriesTests = []struct {
195193
func (s *FileSuite) TestIgnoreEmptyDirEntries(c *C) {
196194
for i, t := range ignoreEmptyDirEntriesTests {
197195
f := fixtures.ByURL(t.repo).One()
198-
sto, err := filesystem.NewStorage(f.DotGit())
199-
c.Assert(err, IsNil)
196+
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
200197

201198
h := plumbing.NewHash(t.commit)
202199
commit, err := GetCommit(sto, h)
@@ -251,9 +248,7 @@ func (s *FileSuite) TestFileIter(c *C) {
251248

252249
func (s *FileSuite) TestFileIterSubmodule(c *C) {
253250
dotgit := fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One().DotGit()
254-
st, err := filesystem.NewStorage(dotgit)
255-
256-
c.Assert(err, IsNil)
251+
st := filesystem.NewStorage(dotgit, cache.NewObjectLRUDefault())
257252

258253
hash := plumbing.NewHash("b685400c1f9316f350965a5993d350bc746b0bf4")
259254
commit, err := GetCommit(st, hash)

plumbing/object/object_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"gopkg.in/src-d/go-git.v4/plumbing"
10+
"gopkg.in/src-d/go-git.v4/plumbing/cache"
1011
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
1112
"gopkg.in/src-d/go-git.v4/plumbing/storer"
1213
"gopkg.in/src-d/go-git.v4/storage/filesystem"
@@ -26,8 +27,7 @@ type BaseObjectsSuite struct {
2627
func (s *BaseObjectsSuite) SetUpSuite(c *C) {
2728
s.Suite.SetUpSuite(c)
2829
s.Fixture = fixtures.Basic().One()
29-
storer, err := filesystem.NewStorage(s.Fixture.DotGit())
30-
c.Assert(err, IsNil)
30+
storer := filesystem.NewStorage(s.Fixture.DotGit(), cache.NewObjectLRUDefault())
3131
s.Storer = storer
3232
}
3333

plumbing/object/patch_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
. "gopkg.in/check.v1"
55
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
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/storage/filesystem"
89
)
910

@@ -14,8 +15,8 @@ type PatchSuite struct {
1415
var _ = Suite(&PatchSuite{})
1516

1617
func (s *PatchSuite) TestStatsWithSubmodules(c *C) {
17-
storer, err := filesystem.NewStorage(
18-
fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One().DotGit())
18+
storer := filesystem.NewStorage(
19+
fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One().DotGit(), cache.NewObjectLRUDefault())
1920

2021
commit, err := GetCommit(storer, plumbing.NewHash("b685400c1f9316f350965a5993d350bc746b0bf4"))
2122

plumbing/object/tag_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"gopkg.in/src-d/go-git.v4/plumbing"
10+
"gopkg.in/src-d/go-git.v4/plumbing/cache"
1011
"gopkg.in/src-d/go-git.v4/storage/filesystem"
1112
"gopkg.in/src-d/go-git.v4/storage/memory"
1213

@@ -22,9 +23,7 @@ var _ = Suite(&TagSuite{})
2223

2324
func (s *TagSuite) SetUpSuite(c *C) {
2425
s.BaseObjectsSuite.SetUpSuite(c)
25-
storer, err := filesystem.NewStorage(
26-
fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit())
27-
c.Assert(err, IsNil)
26+
storer := filesystem.NewStorage(fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit(), cache.NewObjectLRUDefault())
2827
s.Storer = storer
2928
}
3029

0 commit comments

Comments
 (0)