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

Commit

Permalink
Expose Storage cache.
Browse files Browse the repository at this point in the history
Signed-off-by: kuba-- <kuba@sourced.tech>
  • Loading branch information
kuba-- committed Sep 7, 2018
1 parent d3cec13 commit 8f6b312
Show file tree
Hide file tree
Showing 25 changed files with 111 additions and 165 deletions.
11 changes: 3 additions & 8 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

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

st, err := filesystem.NewStorage(dotgit)
if err != nil {
panic(err)
}
st := filesystem.NewStorage(dotgit, cache.NewObjectLRUDefault())

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

worktree := memfs.New()

st, err := filesystem.NewStorage(dotgit)
if err != nil {
panic(err)
}
st := filesystem.NewStorage(dotgit, cache.NewObjectLRUDefault())

r, err := Open(st, worktree)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions plumbing/format/packfile/encoder_advanced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"gopkg.in/src-d/go-billy.v4/memfs"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/format/idxfile"
. "gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
Expand All @@ -32,8 +33,7 @@ func (s *EncoderAdvancedSuite) TestEncodeDecode(c *C) {
fixs = append(fixs, fixtures.ByURL("https://github.com/src-d/go-git.git").
ByTag("packfile").ByTag(".git").One())
fixs.Test(c, func(f *fixtures.Fixture) {
storage, err := filesystem.NewStorage(f.DotGit())
c.Assert(err, IsNil)
storage := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
s.testEncodeDecode(c, storage, 10)
})
}
Expand All @@ -47,8 +47,7 @@ func (s *EncoderAdvancedSuite) TestEncodeDecodeNoDeltaCompression(c *C) {
fixs = append(fixs, fixtures.ByURL("https://github.com/src-d/go-git.git").
ByTag("packfile").ByTag(".git").One())
fixs.Test(c, func(f *fixtures.Fixture) {
storage, err := filesystem.NewStorage(f.DotGit())
c.Assert(err, IsNil)
storage := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
s.testEncodeDecode(c, storage, 0)
})
}
Expand Down
4 changes: 2 additions & 2 deletions plumbing/object/change_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"sort"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
Expand All @@ -23,8 +24,7 @@ type ChangeAdaptorSuite struct {
func (s *ChangeAdaptorSuite) SetUpSuite(c *C) {
s.Suite.SetUpSuite(c)
s.Fixture = fixtures.Basic().One()
sto, err := filesystem.NewStorage(s.Fixture.DotGit())
c.Assert(err, IsNil)
sto := filesystem.NewStorage(s.Fixture.DotGit(), cache.NewObjectLRUDefault())
s.Storer = sto
}

Expand Down
7 changes: 3 additions & 4 deletions plumbing/object/change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/format/diff"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
Expand All @@ -25,8 +26,7 @@ func (s *ChangeSuite) SetUpSuite(c *C) {
s.Suite.SetUpSuite(c)
s.Fixture = fixtures.ByURL("https://github.com/src-d/go-git.git").
ByTag(".git").One()
sto, err := filesystem.NewStorage(s.Fixture.DotGit())
c.Assert(err, IsNil)
sto := filesystem.NewStorage(s.Fixture.DotGit(), cache.NewObjectLRUDefault())
s.Storer = sto
}

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

sto, err := filesystem.NewStorage(f.DotGit())
c.Assert(err, IsNil)
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())

iter, err := sto.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
Expand Down
4 changes: 2 additions & 2 deletions plumbing/object/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"

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

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

o, err := sto.EncodedObject(plumbing.CommitObject, hash)
c.Assert(err, IsNil)
Expand Down
4 changes: 2 additions & 2 deletions plumbing/object/difftree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"sort"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
Expand All @@ -25,8 +26,7 @@ type DiffTreeSuite struct {
func (s *DiffTreeSuite) SetUpSuite(c *C) {
s.Suite.SetUpSuite(c)
s.Fixture = fixtures.Basic().One()
sto, err := filesystem.NewStorage(s.Fixture.DotGit())
c.Assert(err, IsNil)
sto := filesystem.NewStorage(s.Fixture.DotGit(), cache.NewObjectLRUDefault())
s.Storer = sto
s.cache = make(map[string]storer.EncodedObjectStorer)
}
Expand Down
17 changes: 6 additions & 11 deletions plumbing/object/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
Expand Down Expand Up @@ -44,8 +45,7 @@ var fileIterTests = []struct {
func (s *FileSuite) TestIter(c *C) {
for i, t := range fileIterTests {
f := fixtures.ByURL(t.repo).One()
sto, err := filesystem.NewStorage(f.DotGit())
c.Assert(err, IsNil)
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())

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

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

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

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

func (s *FileSuite) TestFileIterSubmodule(c *C) {
dotgit := fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One().DotGit()
st, err := filesystem.NewStorage(dotgit)

c.Assert(err, IsNil)
st := filesystem.NewStorage(dotgit, cache.NewObjectLRUDefault())

hash := plumbing.NewHash("b685400c1f9316f350965a5993d350bc746b0bf4")
commit, err := GetCommit(st, hash)
Expand Down
4 changes: 2 additions & 2 deletions plumbing/object/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
Expand All @@ -26,8 +27,7 @@ type BaseObjectsSuite struct {
func (s *BaseObjectsSuite) SetUpSuite(c *C) {
s.Suite.SetUpSuite(c)
s.Fixture = fixtures.Basic().One()
storer, err := filesystem.NewStorage(s.Fixture.DotGit())
c.Assert(err, IsNil)
storer := filesystem.NewStorage(s.Fixture.DotGit(), cache.NewObjectLRUDefault())
s.Storer = storer
}

Expand Down
5 changes: 3 additions & 2 deletions plumbing/object/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
. "gopkg.in/check.v1"
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
)

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

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

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

Expand Down
5 changes: 2 additions & 3 deletions plumbing/object/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
"gopkg.in/src-d/go-git.v4/storage/memory"

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

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

Expand Down
4 changes: 2 additions & 2 deletions plumbing/object/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
Expand Down Expand Up @@ -341,8 +342,7 @@ func (s *TreeSuite) TestTreeWalkerNextNonRecursive(c *C) {

func (s *TreeSuite) TestTreeWalkerNextSubmodule(c *C) {
dotgit := fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One().DotGit()
st, err := filesystem.NewStorage(dotgit)
c.Assert(err, IsNil)
st := filesystem.NewStorage(dotgit, cache.NewObjectLRUDefault())

hash := plumbing.NewHash("b685400c1f9316f350965a5993d350bc746b0bf4")
commit, err := GetCommit(st, hash)
Expand Down
12 changes: 5 additions & 7 deletions plumbing/revlist/revlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
Expand Down Expand Up @@ -51,8 +52,7 @@ const (

func (s *RevListSuite) SetUpTest(c *C) {
s.Suite.SetUpSuite(c)
sto, err := filesystem.NewStorage(fixtures.Basic().One().DotGit())
c.Assert(err, IsNil)
sto := filesystem.NewStorage(fixtures.Basic().One().DotGit(), cache.NewObjectLRUDefault())
s.Storer = sto
}

Expand All @@ -67,8 +67,7 @@ func (s *RevListSuite) TestRevListObjects_Submodules(c *C) {
"6ecf0ef2c2dffb796033e5a02219af86ec6584e5": true,
}

sto, err := filesystem.NewStorage(fixtures.ByTag("submodule").One().DotGit())
c.Assert(err, IsNil)
sto := filesystem.NewStorage(fixtures.ByTag("submodule").One().DotGit(), cache.NewObjectLRUDefault())

ref, err := storer.ResolveReference(sto, plumbing.HEAD)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -109,10 +108,9 @@ func (s *RevListSuite) TestRevListObjects(c *C) {
}

func (s *RevListSuite) TestRevListObjectsTagObject(c *C) {
sto, err := filesystem.NewStorage(
sto := filesystem.NewStorage(
fixtures.ByTag("tags").
ByURL("https://github.com/git-fixtures/tags.git").One().DotGit())
c.Assert(err, IsNil)
ByURL("https://github.com/git-fixtures/tags.git").One().DotGit(), cache.NewObjectLRUDefault())

expected := map[string]bool{
"70846e9a10ef7b41064b40f07713d5b8b9a8fc73": true,
Expand Down
3 changes: 2 additions & 1 deletion plumbing/transport/server/loader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
Expand Down Expand Up @@ -43,7 +44,7 @@ func (l *fsLoader) Load(ep *transport.Endpoint) (storer.Storer, error) {
return nil, transport.ErrRepositoryNotFound
}

return filesystem.NewStorage(fs)
return filesystem.NewStorage(fs, cache.NewObjectLRUDefault()), nil
}

// MapLoader is a Loader that uses a lookup map of storer.Storer by
Expand Down
4 changes: 2 additions & 2 deletions plumbing/transport/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server_test
import (
"testing"

"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
"gopkg.in/src-d/go-git.v4/plumbing/transport/client"
"gopkg.in/src-d/go-git.v4/plumbing/transport/server"
Expand Down Expand Up @@ -53,8 +54,7 @@ func (s *BaseSuite) prepareRepositories(c *C) {
fs := fixtures.Basic().One().DotGit()
s.Endpoint, err = transport.NewEndpoint(fs.Root())
c.Assert(err, IsNil)
s.loader[s.Endpoint.String()], err = filesystem.NewStorage(fs)
c.Assert(err, IsNil)
s.loader[s.Endpoint.String()] = filesystem.NewStorage(fs, cache.NewObjectLRUDefault())

s.EmptyEndpoint, err = transport.NewEndpoint("/empty.git")
c.Assert(err, IsNil)
Expand Down
4 changes: 2 additions & 2 deletions prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
Expand All @@ -22,8 +23,7 @@ func (s *PruneSuite) testPrune(c *C, deleteTime time.Time) {
srcFs := fixtures.ByTag("unpacked").One().DotGit()
var sto storage.Storer
var err error
sto, err = filesystem.NewStorage(srcFs)
c.Assert(err, IsNil)
sto = filesystem.NewStorage(srcFs, cache.NewObjectLRUDefault())

los := sto.(storer.LooseObjectStorer)
c.Assert(los, NotNil)
Expand Down
Loading

0 comments on commit 8f6b312

Please sign in to comment.