aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkuba-- <kuba@sourced.tech>2018-09-07 09:27:35 +0200
committerkuba-- <kuba@sourced.tech>2018-09-07 13:48:18 +0200
commit8f6b3127c1ff7661113fff2662416c328971a285 (patch)
tree3b127a5edf22140c5a710612cb5e4fcc3879664a
parentd3cec13ac0b195bfb897ed038a08b5130ab9969e (diff)
downloadgo-git-8f6b3127c1ff7661113fff2662416c328971a285.tar.gz
Expose Storage cache.
Signed-off-by: kuba-- <kuba@sourced.tech>
-rw-r--r--common_test.go11
-rw-r--r--plumbing/format/packfile/encoder_advanced_test.go7
-rw-r--r--plumbing/object/change_adaptor_test.go4
-rw-r--r--plumbing/object/change_test.go7
-rw-r--r--plumbing/object/commit_test.go4
-rw-r--r--plumbing/object/difftree_test.go4
-rw-r--r--plumbing/object/file_test.go17
-rw-r--r--plumbing/object/object_test.go4
-rw-r--r--plumbing/object/patch_test.go5
-rw-r--r--plumbing/object/tag_test.go5
-rw-r--r--plumbing/object/tree_test.go4
-rw-r--r--plumbing/revlist/revlist_test.go12
-rw-r--r--plumbing/transport/server/loader.go3
-rw-r--r--plumbing/transport/server/server_test.go4
-rw-r--r--prune_test.go4
-rw-r--r--remote_test.go35
-rw-r--r--repository.go11
-rw-r--r--repository_test.go30
-rw-r--r--storage/filesystem/dotgit/dotgit.go4
-rw-r--r--storage/filesystem/module.go3
-rw-r--r--storage/filesystem/object.go29
-rw-r--r--storage/filesystem/object_test.go25
-rw-r--r--storage/filesystem/storage.go29
-rw-r--r--storage/filesystem/storage_test.go11
-rw-r--r--worktree_commit_test.go4
25 files changed, 111 insertions, 165 deletions
diff --git a/common_test.go b/common_test.go
index efe1ecc..dad0a37 100644
--- a/common_test.go
+++ b/common_test.go
@@ -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"
@@ -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 {
@@ -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 {
diff --git a/plumbing/format/packfile/encoder_advanced_test.go b/plumbing/format/packfile/encoder_advanced_test.go
index fc1419e..e15126e 100644
--- a/plumbing/format/packfile/encoder_advanced_test.go
+++ b/plumbing/format/packfile/encoder_advanced_test.go
@@ -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"
@@ -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)
})
}
@@ -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)
})
}
diff --git a/plumbing/object/change_adaptor_test.go b/plumbing/object/change_adaptor_test.go
index 803c3b8..c7c003b 100644
--- a/plumbing/object/change_adaptor_test.go
+++ b/plumbing/object/change_adaptor_test.go
@@ -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"
@@ -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
}
diff --git a/plumbing/object/change_test.go b/plumbing/object/change_test.go
index b0e89c7..e2f0a23 100644
--- a/plumbing/object/change_test.go
+++ b/plumbing/object/change_test.go
@@ -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"
@@ -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
}
@@ -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)
diff --git a/plumbing/object/commit_test.go b/plumbing/object/commit_test.go
index e72b703..c9acf42 100644
--- a/plumbing/object/commit_test.go
+++ b/plumbing/object/commit_test.go
@@ -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"
@@ -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)
diff --git a/plumbing/object/difftree_test.go b/plumbing/object/difftree_test.go
index ff9ecbc..4af8684 100644
--- a/plumbing/object/difftree_test.go
+++ b/plumbing/object/difftree_test.go
@@ -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"
@@ -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)
}
diff --git a/plumbing/object/file_test.go b/plumbing/object/file_test.go
index edb82d0..4b92749 100644
--- a/plumbing/object/file_test.go
+++ b/plumbing/object/file_test.go
@@ -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"
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
diff --git a/plumbing/object/object_test.go b/plumbing/object/object_test.go
index 68aa1a1..8f0eede 100644
--- a/plumbing/object/object_test.go
+++ b/plumbing/object/object_test.go
@@ -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"
@@ -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
}
diff --git a/plumbing/object/patch_test.go b/plumbing/object/patch_test.go
index 8eb65ec..47057fb 100644
--- a/plumbing/object/patch_test.go
+++ b/plumbing/object/patch_test.go
@@ -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"
)
@@ -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"))
diff --git a/plumbing/object/tag_test.go b/plumbing/object/tag_test.go
index e7dd06e..59c28b0 100644
--- a/plumbing/object/tag_test.go
+++ b/plumbing/object/tag_test.go
@@ -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"
@@ -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
}
diff --git a/plumbing/object/tree_test.go b/plumbing/object/tree_test.go
index 59d5d21..7366421 100644
--- a/plumbing/object/tree_test.go
+++ b/plumbing/object/tree_test.go
@@ -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"
@@ -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)
diff --git a/plumbing/revlist/revlist_test.go b/plumbing/revlist/revlist_test.go
index 55d9bca..dea1c73 100644
--- a/plumbing/revlist/revlist_test.go
+++ b/plumbing/revlist/revlist_test.go
@@ -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"
@@ -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
}
@@ -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)
@@ -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,
diff --git a/plumbing/transport/server/loader.go b/plumbing/transport/server/loader.go
index c83752c..13b3526 100644
--- a/plumbing/transport/server/loader.go
+++ b/plumbing/transport/server/loader.go
@@ -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"
@@ -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
diff --git a/plumbing/transport/server/server_test.go b/plumbing/transport/server/server_test.go
index 33d74d1..302ff48 100644
--- a/plumbing/transport/server/server_test.go
+++ b/plumbing/transport/server/server_test.go
@@ -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"
@@ -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)
diff --git a/prune_test.go b/prune_test.go
index 60652ec..670cd07 100644
--- a/prune_test.go
+++ b/prune_test.go
@@ -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"
@@ -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)
diff --git a/remote_test.go b/remote_test.go
index dd386b0..175faed 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -9,6 +9,7 @@ import (
"gopkg.in/src-d/go-git.v4/config"
"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/protocol/packp"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage"
@@ -238,7 +239,7 @@ func (s *RemoteSuite) TestFetchWithPackfileWriter(c *C) {
defer os.RemoveAll(dir) // clean up
- fss, err := filesystem.NewStorage(osfs.New(dir))
+ fss := filesystem.NewStorage(osfs.New(dir), cache.NewObjectLRUDefault())
c.Assert(err, IsNil)
mock := &mockPackfileWriter{Storer: fss}
@@ -375,8 +376,7 @@ func (s *RemoteSuite) TestFetchFastForwardFS(c *C) {
defer os.RemoveAll(dir) // clean up
- fss, err := filesystem.NewStorage(osfs.New(dir))
- c.Assert(err, IsNil)
+ fss := filesystem.NewStorage(osfs.New(dir), cache.NewObjectLRUDefault())
// This exercises `storage.filesystem.Storage.CheckAndSetReference()`.
s.testFetchFastForward(c, fss)
@@ -400,8 +400,7 @@ func (s *RemoteSuite) TestPushToEmptyRepository(c *C) {
c.Assert(err, IsNil)
srcFs := fixtures.Basic().One().DotGit()
- sto, err := filesystem.NewStorage(srcFs)
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(srcFs, cache.NewObjectLRUDefault())
r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
@@ -438,8 +437,7 @@ func (s *RemoteSuite) TestPushContext(c *C) {
c.Assert(err, IsNil)
fs := fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit()
- sto, err := filesystem.NewStorage(fs)
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
@@ -461,8 +459,7 @@ func (s *RemoteSuite) TestPushTags(c *C) {
c.Assert(err, IsNil)
fs := fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit()
- sto, err := filesystem.NewStorage(fs)
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
@@ -485,15 +482,14 @@ func (s *RemoteSuite) TestPushTags(c *C) {
func (s *RemoteSuite) TestPushNoErrAlreadyUpToDate(c *C) {
fs := fixtures.Basic().One().DotGit()
- sto, err := filesystem.NewStorage(fs)
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
URLs: []string{fs.Root()},
})
- err = r.Push(&PushOptions{
+ err := r.Push(&PushOptions{
RefSpecs: []config.RefSpec{"refs/heads/*:refs/heads/*"},
})
c.Assert(err, Equals, NoErrAlreadyUpToDate)
@@ -501,8 +497,7 @@ func (s *RemoteSuite) TestPushNoErrAlreadyUpToDate(c *C) {
func (s *RemoteSuite) TestPushDeleteReference(c *C) {
fs := fixtures.Basic().One().DotGit()
- sto, err := filesystem.NewStorage(fs)
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
r, err := PlainClone(c.MkDir(), true, &CloneOptions{
URL: fs.Root(),
@@ -526,8 +521,7 @@ func (s *RemoteSuite) TestPushDeleteReference(c *C) {
func (s *RemoteSuite) TestPushRejectNonFastForward(c *C) {
fs := fixtures.Basic().One().DotGit()
- server, err := filesystem.NewStorage(fs)
- c.Assert(err, IsNil)
+ server := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
r, err := PlainClone(c.MkDir(), true, &CloneOptions{
URL: fs.Root(),
@@ -554,12 +548,10 @@ func (s *RemoteSuite) TestPushRejectNonFastForward(c *C) {
func (s *RemoteSuite) TestPushForce(c *C) {
f := fixtures.Basic().One()
- sto, err := filesystem.NewStorage(f.DotGit())
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
dstFs := f.DotGit()
- dstSto, err := filesystem.NewStorage(dstFs)
- c.Assert(err, IsNil)
+ dstSto := filesystem.NewStorage(dstFs, cache.NewObjectLRUDefault())
url := dstFs.Root()
r := newRemote(sto, &config.RemoteConfig{
@@ -703,8 +695,7 @@ func (s *RemoteSuite) TestPushWrongRemoteName(c *C) {
func (s *RemoteSuite) TestGetHaves(c *C) {
f := fixtures.Basic().One()
- sto, err := filesystem.NewStorage(f.DotGit())
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
var localRefs = []*plumbing.Reference{
plumbing.NewReferenceFromStrings(
diff --git a/repository.go b/repository.go
index f619934..bfe06a3 100644
--- a/repository.go
+++ b/repository.go
@@ -13,6 +13,7 @@ import (
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/internal/revision"
"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/object"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
@@ -220,10 +221,7 @@ func PlainInit(path string, isBare bool) (*Repository, error) {
dot, _ = wt.Chroot(GitDirName)
}
- s, err := filesystem.NewStorage(dot)
- if err != nil {
- return nil, err
- }
+ s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
return Init(s, wt)
}
@@ -251,10 +249,7 @@ func PlainOpenWithOptions(path string, o *PlainOpenOptions) (*Repository, error)
return nil, err
}
- s, err := filesystem.NewStorage(dot)
- if err != nil {
- return nil, err
- }
+ s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
return Open(s, wt)
}
diff --git a/repository_test.go b/repository_test.go
index 261af7a..88071cf 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -15,6 +15,7 @@ import (
"gopkg.in/src-d/go-git.v4/config"
"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"
@@ -51,8 +52,7 @@ func (s *RepositorySuite) TestInitNonStandardDotGit(c *C) {
fs := osfs.New(dir)
dot, _ := fs.Chroot("storage")
- storage, err := filesystem.NewStorage(dot)
- c.Assert(err, IsNil)
+ storage := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
wt, _ := fs.Chroot("worktree")
r, err := Init(storage, wt)
@@ -78,8 +78,7 @@ func (s *RepositorySuite) TestInitStandardDotGit(c *C) {
fs := osfs.New(dir)
dot, _ := fs.Chroot(".git")
- storage, err := filesystem.NewStorage(dot)
- c.Assert(err, IsNil)
+ storage := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
r, err := Init(storage, fs)
c.Assert(err, IsNil)
@@ -1058,8 +1057,7 @@ func (s *RepositorySuite) TestPushDepth(c *C) {
func (s *RepositorySuite) TestPushNonExistentRemote(c *C) {
srcFs := fixtures.Basic().One().DotGit()
- sto, err := filesystem.NewStorage(srcFs)
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(srcFs, cache.NewObjectLRUDefault())
r, err := Open(sto, srcFs)
c.Assert(err, IsNil)
@@ -1277,8 +1275,7 @@ func (s *RepositorySuite) TestTags(c *C) {
func (s *RepositorySuite) TestBranches(c *C) {
f := fixtures.ByURL("https://github.com/git-fixtures/root-references.git").One()
- sto, err := filesystem.NewStorage(f.DotGit())
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
r, err := Open(sto, f.DotGit())
c.Assert(err, IsNil)
@@ -1495,8 +1492,7 @@ func (s *RepositorySuite) TestWorktreeBare(c *C) {
func (s *RepositorySuite) TestResolveRevision(c *C) {
f := fixtures.ByURL("https://github.com/git-fixtures/basic.git").One()
- sto, err := filesystem.NewStorage(f.DotGit())
- c.Assert(err, IsNil)
+ sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
r, err := Open(sto, f.DotGit())
c.Assert(err, IsNil)
@@ -1548,9 +1544,9 @@ func (s *RepositorySuite) TestResolveRevisionWithErrors(c *C) {
c.Assert(err, IsNil)
datas := map[string]string{
- "efs/heads/master~": "reference not found",
- "HEAD^3": `Revision invalid : "3" found must be 0, 1 or 2 after "^"`,
- "HEAD^{/whatever}": `No commit message match regexp : "whatever"`,
+ "efs/heads/master~": "reference not found",
+ "HEAD^3": `Revision invalid : "3" found must be 0, 1 or 2 after "^"`,
+ "HEAD^{/whatever}": `No commit message match regexp : "whatever"`,
"4e1243bd22c66e76c2ba9eddc1f91394e57f9f83": "reference not found",
"918c48b83bd081e863dbe1b80f8998f058cd8294": `refname "918c48b83bd081e863dbe1b80f8998f058cd8294" is ambiguous`,
}
@@ -1567,8 +1563,7 @@ func (s *RepositorySuite) testRepackObjects(
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)
@@ -1733,10 +1728,7 @@ func BenchmarkObjects(b *testing.B) {
b.Run(f.URL, func(b *testing.B) {
fs := f.DotGit()
- storer, err := filesystem.NewStorage(fs)
- if err != nil {
- b.Fatal(err)
- }
+ storer := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
worktree, err := fs.Chroot(filepath.Dir(fs.Root()))
if err != nil {
diff --git a/storage/filesystem/dotgit/dotgit.go b/storage/filesystem/dotgit/dotgit.go
index df5cd10..a58c248 100644
--- a/storage/filesystem/dotgit/dotgit.go
+++ b/storage/filesystem/dotgit/dotgit.go
@@ -92,8 +92,8 @@ func New(fs billy.Filesystem) *DotGit {
return NewWithOptions(fs, Options{})
}
-// NewWithOptions creates a new DotGit and sets non default configuration
-// options. See New for complete help.
+// NewWithOptions sets non default configuration options.
+// See New for complete help.
func NewWithOptions(fs billy.Filesystem, o Options) *DotGit {
return &DotGit{
options: o,
diff --git a/storage/filesystem/module.go b/storage/filesystem/module.go
index 7c8c8d8..9272206 100644
--- a/storage/filesystem/module.go
+++ b/storage/filesystem/module.go
@@ -1,6 +1,7 @@
package filesystem
import (
+ "gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/storage"
"gopkg.in/src-d/go-git.v4/storage/filesystem/dotgit"
)
@@ -15,5 +16,5 @@ func (s *ModuleStorage) Module(name string) (storage.Storer, error) {
return nil, err
}
- return NewStorage(fs)
+ return NewStorage(fs, cache.NewObjectLRUDefault()), nil
}
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 3545e27..9eb085f 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -27,24 +27,18 @@ type ObjectStorage struct {
index map[plumbing.Hash]idxfile.Index
}
-// NewObjectStorage creates a new ObjectStorage with the given .git directory.
-func NewObjectStorage(dir *dotgit.DotGit) (ObjectStorage, error) {
- return NewObjectStorageWithOptions(dir, Options{})
-}
-
-// NewObjectStorageWithOptions creates a new ObjectStorage with the given .git
-// directory and sets its options.
-func NewObjectStorageWithOptions(
- dir *dotgit.DotGit,
- ops Options,
-) (ObjectStorage, error) {
- s := ObjectStorage{
+// NewObjectStorage creates a new ObjectStorage with the given .git directory and cache.
+func NewObjectStorage(dir *dotgit.DotGit, cache cache.Object) *ObjectStorage {
+ return NewObjectStorageWithOptions(dir, cache, Options{})
+}
+
+// NewObjectStorageWithOptions creates a new ObjectStorage with the given .git directory, cache and extra options
+func NewObjectStorageWithOptions(dir *dotgit.DotGit, cache cache.Object, ops Options) *ObjectStorage {
+ return &ObjectStorage{
options: ops,
- deltaBaseCache: cache.NewObjectLRUDefault(),
+ deltaBaseCache: cache,
dir: dir,
}
-
- return s, nil
}
func (s *ObjectStorage) requireIndex() error {
@@ -182,10 +176,7 @@ func (s *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (p
// Create a new object storage with the DotGit(s) and check for the
// required hash object. Skip when not found.
for _, dg := range dotgits {
- o, oe := NewObjectStorage(dg)
- if oe != nil {
- continue
- }
+ o := NewObjectStorage(dg, s.deltaBaseCache)
enobj, enerr := o.EncodedObject(t, h)
if enerr != nil {
continue
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go
index 4a921a9..bd4a94b 100644
--- a/storage/filesystem/object_test.go
+++ b/storage/filesystem/object_test.go
@@ -6,6 +6,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/storage/filesystem/dotgit"
. "gopkg.in/check.v1"
@@ -27,8 +28,7 @@ var _ = Suite(&FsSuite{})
func (s *FsSuite) TestGetFromObjectFile(c *C) {
fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
- o, err := NewObjectStorage(dotgit.New(fs))
- c.Assert(err, IsNil)
+ o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault())
expected := plumbing.NewHash("f3dfe29d268303fc6e1bbce268605fc99573406e")
obj, err := o.EncodedObject(plumbing.AnyObject, expected)
@@ -39,8 +39,7 @@ func (s *FsSuite) TestGetFromObjectFile(c *C) {
func (s *FsSuite) TestGetFromPackfile(c *C) {
fixtures.Basic().ByTag(".git").Test(c, func(f *fixtures.Fixture) {
fs := f.DotGit()
- o, err := NewObjectStorage(dotgit.New(fs))
- c.Assert(err, IsNil)
+ o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault())
expected := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
obj, err := o.EncodedObject(plumbing.AnyObject, expected)
@@ -53,8 +52,7 @@ func (s *FsSuite) TestGetFromPackfileKeepDescriptors(c *C) {
fixtures.Basic().ByTag(".git").Test(c, func(f *fixtures.Fixture) {
fs := f.DotGit()
dg := dotgit.NewWithOptions(fs, dotgit.Options{KeepDescriptors: true})
- o, err := NewObjectStorageWithOptions(dg, Options{KeepDescriptors: true})
- c.Assert(err, IsNil)
+ o := NewObjectStorageWithOptions(dg, cache.NewObjectLRUDefault(), Options{KeepDescriptors: true})
expected := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
obj, err := o.EncodedObject(plumbing.AnyObject, expected)
@@ -87,8 +85,7 @@ func (s *FsSuite) TestGetFromPackfileKeepDescriptors(c *C) {
func (s *FsSuite) TestGetFromPackfileMultiplePackfiles(c *C) {
fs := fixtures.ByTag(".git").ByTag("multi-packfile").One().DotGit()
- o, err := NewObjectStorage(dotgit.New(fs))
- c.Assert(err, IsNil)
+ o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault())
expected := plumbing.NewHash("8d45a34641d73851e01d3754320b33bb5be3c4d3")
obj, err := o.getFromPackfile(expected, false)
@@ -104,8 +101,7 @@ func (s *FsSuite) TestGetFromPackfileMultiplePackfiles(c *C) {
func (s *FsSuite) TestIter(c *C) {
fixtures.ByTag(".git").ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
fs := f.DotGit()
- o, err := NewObjectStorage(dotgit.New(fs))
- c.Assert(err, IsNil)
+ o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault())
iter, err := o.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
@@ -125,8 +121,7 @@ func (s *FsSuite) TestIterWithType(c *C) {
fixtures.ByTag(".git").Test(c, func(f *fixtures.Fixture) {
for _, t := range objectTypes {
fs := f.DotGit()
- o, err := NewObjectStorage(dotgit.New(fs))
- c.Assert(err, IsNil)
+ o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault())
iter, err := o.IterEncodedObjects(t)
c.Assert(err, IsNil)
@@ -308,11 +303,7 @@ func BenchmarkGetObjectFromPackfile(b *testing.B) {
for _, f := range fixtures.Basic() {
b.Run(f.URL, func(b *testing.B) {
fs := f.DotGit()
- o, err := NewObjectStorage(dotgit.New(fs))
- if err != nil {
- b.Fatal(err)
- }
-
+ o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault())
for i := 0; i < b.N; i++ {
expected := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
obj, err := o.EncodedObject(plumbing.AnyObject, expected)
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go
index 7fae789..14a772a 100644
--- a/storage/filesystem/storage.go
+++ b/storage/filesystem/storage.go
@@ -2,6 +2,7 @@
package filesystem
import (
+ "gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/storage/filesystem/dotgit"
"gopkg.in/src-d/go-billy.v4"
@@ -32,38 +33,35 @@ type Options struct {
KeepDescriptors bool
}
-// NewStorage returns a new Storage backed by a given `fs.Filesystem`
-func NewStorage(fs billy.Filesystem) (*Storage, error) {
- return NewStorageWithOptions(fs, Options{})
+// NewStorage returns a new Storage backed by a given `fs.Filesystem` and cache.
+func NewStorage(fs billy.Filesystem, cache cache.Object) *Storage {
+ return NewStorageWithOptions(fs, cache, Options{})
}
-// NewStorageWithOptions returns a new Storage backed by a given `fs.Filesystem`
-func NewStorageWithOptions(
- fs billy.Filesystem,
- ops Options,
-) (*Storage, error) {
+// NewStorageWithOptions returns a new Storage with extra options,
+// backed by a given `fs.Filesystem` and cache.
+func NewStorageWithOptions(fs billy.Filesystem, cache cache.Object, ops Options) *Storage {
dirOps := dotgit.Options{
ExclusiveAccess: ops.ExclusiveAccess,
KeepDescriptors: ops.KeepDescriptors,
}
-
dir := dotgit.NewWithOptions(fs, dirOps)
- o, err := NewObjectStorageWithOptions(dir, ops)
- if err != nil {
- return nil, err
- }
return &Storage{
fs: fs,
dir: dir,
- ObjectStorage: o,
+ ObjectStorage: ObjectStorage{
+ options: ops,
+ deltaBaseCache: cache,
+ dir: dir,
+ },
ReferenceStorage: ReferenceStorage{dir: dir},
IndexStorage: IndexStorage{dir: dir},
ShallowStorage: ShallowStorage{dir: dir},
ConfigStorage: ConfigStorage{dir: dir},
ModuleStorage: ModuleStorage{dir: dir},
- }, nil
+ }
}
// Filesystem returns the underlying filesystem
@@ -71,6 +69,7 @@ func (s *Storage) Filesystem() billy.Filesystem {
return s.fs
}
+// Init initializes .git directory
func (s *Storage) Init() error {
return s.dir.Initialize()
}
diff --git a/storage/filesystem/storage_test.go b/storage/filesystem/storage_test.go
index 7f85ef5..6fa0d90 100644
--- a/storage/filesystem/storage_test.go
+++ b/storage/filesystem/storage_test.go
@@ -4,6 +4,7 @@ import (
"io/ioutil"
"testing"
+ "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/test"
@@ -23,8 +24,7 @@ var _ = Suite(&StorageSuite{})
func (s *StorageSuite) SetUpTest(c *C) {
s.dir = c.MkDir()
- storage, err := NewStorage(osfs.New(s.dir))
- c.Assert(err, IsNil)
+ storage := NewStorage(osfs.New(s.dir), cache.NewObjectLRUDefault())
setUpTest(s, c, storage)
}
@@ -44,8 +44,7 @@ func setUpTest(s *StorageSuite, c *C, storage *Storage) {
func (s *StorageSuite) TestFilesystem(c *C) {
fs := memfs.New()
- storage, err := NewStorage(fs)
- c.Assert(err, IsNil)
+ storage := NewStorage(fs, cache.NewObjectLRUDefault())
c.Assert(storage.Filesystem(), Equals, fs)
}
@@ -64,10 +63,10 @@ var _ = Suite(&StorageExclusiveSuite{})
func (s *StorageExclusiveSuite) SetUpTest(c *C) {
s.dir = c.MkDir()
- storage, err := NewStorageWithOptions(
+ storage := NewStorageWithOptions(
osfs.New(s.dir),
+ cache.NewObjectLRUDefault(),
Options{ExclusiveAccess: true})
- c.Assert(err, IsNil)
setUpTest(&s.StorageSuite, c, storage)
}
diff --git a/worktree_commit_test.go b/worktree_commit_test.go
index 6979bd5..62aae8a 100644
--- a/worktree_commit_test.go
+++ b/worktree_commit_test.go
@@ -9,6 +9,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/object"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
@@ -205,8 +206,7 @@ func (s *WorktreeSuite) TestCommitTreeSort(c *C) {
path, err := ioutil.TempDir(os.TempDir(), "test-commit-tree-sort")
c.Assert(err, IsNil)
fs := osfs.New(path)
- st, err := filesystem.NewStorage(fs)
- c.Assert(err, IsNil)
+ st := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
r, err := Init(st, nil)
c.Assert(err, IsNil)