aboutsummaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-14 18:21:10 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-14 18:21:10 +0200
commitf6fe29c80d11662a169806dcf413ecdedcb28fa3 (patch)
tree9958034c27521f720f8c5d83c12120ada196f48a /storage
parent91bf16b2336e6f80f0742be729582fe5fbbada83 (diff)
downloadgo-git-f6fe29c80d11662a169806dcf413ecdedcb28fa3.tar.gz
core: Storage, removing err returning *Storages
Diffstat (limited to 'storage')
-rw-r--r--storage/filesystem/object_test.go5
-rw-r--r--storage/filesystem/storage.go20
-rw-r--r--storage/memory/storage.go12
-rw-r--r--storage/memory/storage_test.go28
4 files changed, 25 insertions, 40 deletions
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go
index 5c4c7c8..8bca5c6 100644
--- a/storage/filesystem/object_test.go
+++ b/storage/filesystem/object_test.go
@@ -76,10 +76,7 @@ func (s *FsSuite) newObjectStorage(c *C, fixtureName string) core.ObjectStorage
store, err := NewStorage(fs, fs.Join(path, ".git/"))
c.Assert(err, IsNil)
- obj, err := store.ObjectStorage()
- c.Assert(err, IsNil)
-
- return obj
+ return store.ObjectStorage()
}
func (s *FsSuite) TestGetCompareWithMemoryStorage(c *C) {
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go
index 8f9c555..63d0215 100644
--- a/storage/filesystem/storage.go
+++ b/storage/filesystem/storage.go
@@ -22,25 +22,21 @@ func NewStorage(fs fs.FS, path string) (*Storage, error) {
return &Storage{dir: dir}, nil
}
-func (s *Storage) ObjectStorage() (core.ObjectStorage, error) {
+func (s *Storage) ObjectStorage() core.ObjectStorage {
if s.o != nil {
- return s.o, nil
+ return s.o
}
- i, err := buildIndex(s.dir)
- if err != nil {
- return nil, err
- }
-
- s.o = &ObjectStorage{dir: s.dir, index: i}
- return s.o, nil
+ //TODO: error being ignored
+ i, _ := buildIndex(s.dir)
+ return &ObjectStorage{dir: s.dir, index: i}
}
-func (s *Storage) ReferenceStorage() (core.ReferenceStorage, error) {
+func (s *Storage) ReferenceStorage() core.ReferenceStorage {
if s.r != nil {
- return s.r, nil
+ return s.r
}
s.r = &ReferenceStorage{dir: s.dir}
- return s.r, nil
+ return s.r
}
diff --git a/storage/memory/storage.go b/storage/memory/storage.go
index 9c97523..32c2973 100644
--- a/storage/memory/storage.go
+++ b/storage/memory/storage.go
@@ -20,9 +20,9 @@ func NewStorage() *Storage {
}
// ObjectStorage returns the ObjectStorage if not exists creates a new one
-func (s *Storage) ObjectStorage() (core.ObjectStorage, error) {
+func (s *Storage) ObjectStorage() core.ObjectStorage {
if s.o != nil {
- return s.o, nil
+ return s.o
}
s.o = &ObjectStorage{
@@ -33,19 +33,19 @@ func (s *Storage) ObjectStorage() (core.ObjectStorage, error) {
Tags: make(map[core.Hash]core.Object, 0),
}
- return s.o, nil
+ return s.o
}
// ReferenceStorage returns the ReferenceStorage if not exists creates a new one
-func (s *Storage) ReferenceStorage() (core.ReferenceStorage, error) {
+func (s *Storage) ReferenceStorage() core.ReferenceStorage {
if s.r != nil {
- return s.r, nil
+ return s.r
}
r := make(ReferenceStorage, 0)
s.r = &r
- return s.r, nil
+ return s.r
}
// ObjectStorage is the implementation of core.ObjectStorage for memory.Object
diff --git a/storage/memory/storage_test.go b/storage/memory/storage_test.go
index 8e9a524..ac97584 100644
--- a/storage/memory/storage_test.go
+++ b/storage/memory/storage_test.go
@@ -16,28 +16,23 @@ var _ = Suite(&StorageSuite{})
func (s *StorageSuite) TestStorageObjectStorage(c *C) {
storage := NewStorage()
- o, err := storage.ObjectStorage()
- c.Assert(err, IsNil)
- e, err := storage.ObjectStorage()
- c.Assert(err, IsNil)
+ o := storage.ObjectStorage()
+ e := storage.ObjectStorage()
c.Assert(o == e, Equals, true)
}
func (s *StorageSuite) TestStorageReferenceStorage(c *C) {
storage := NewStorage()
- o, err := storage.ReferenceStorage()
- c.Assert(err, IsNil)
- e, err := storage.ReferenceStorage()
- c.Assert(err, IsNil)
+ o := storage.ReferenceStorage()
+ e := storage.ReferenceStorage()
c.Assert(o == e, Equals, true)
}
func (s *StorageSuite) TestObjectStorageSetAndGet(c *C) {
storage := NewStorage()
- os, err := storage.ObjectStorage()
- c.Assert(err, IsNil)
+ os := storage.ObjectStorage()
commit := &core.MemoryObject{}
commit.SetType(core.CommitObject)
@@ -91,8 +86,7 @@ func (s *StorageSuite) TestObjectStorageIter(c *C) {
tag.SetType(core.TagObject)
storage := NewStorage()
- os, err := storage.ObjectStorage()
- c.Assert(err, IsNil)
+ os := storage.ObjectStorage()
os.Set(commit)
os.Set(tree)
@@ -134,10 +128,9 @@ func (s *StorageSuite) TestObjectStorageIter(c *C) {
func (s *StorageSuite) TestReferenceStorageSetAndGet(c *C) {
storage := NewStorage()
- rs, err := storage.ReferenceStorage()
- c.Assert(err, IsNil)
+ rs := storage.ReferenceStorage()
- err = rs.Set(core.NewReferenceFromStrings("foo", "bc9968d75e48de59f0870ffb71f5e160bbbdcf52"))
+ err := rs.Set(core.NewReferenceFromStrings("foo", "bc9968d75e48de59f0870ffb71f5e160bbbdcf52"))
c.Assert(err, IsNil)
err = rs.Set(core.NewReferenceFromStrings("bar", "482e0eada5de4039e6f216b45b3c9b683b83bfa"))
@@ -150,10 +143,9 @@ func (s *StorageSuite) TestReferenceStorageSetAndGet(c *C) {
func (s *StorageSuite) TestReferenceStorageIter(c *C) {
storage := NewStorage()
- rs, err := storage.ReferenceStorage()
- c.Assert(err, IsNil)
+ rs := storage.ReferenceStorage()
- err = rs.Set(core.NewReferenceFromStrings("foo", "bc9968d75e48de59f0870ffb71f5e160bbbdcf52"))
+ err := rs.Set(core.NewReferenceFromStrings("foo", "bc9968d75e48de59f0870ffb71f5e160bbbdcf52"))
c.Assert(err, IsNil)
i, err := rs.Iter()