aboutsummaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
Diffstat (limited to 'storage')
-rw-r--r--storage/filesystem/object.go40
-rw-r--r--storage/filesystem/object_test.go12
-rw-r--r--storage/memory/storage.go48
-rw-r--r--storage/test/storage_suite.go54
4 files changed, 77 insertions, 77 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 7b7bc18..836e7f3 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -53,7 +53,7 @@ func (s *ObjectStorage) loadIdxFile(h plumbing.Hash) error {
return s.index[h].Decode(idx)
}
-func (s *ObjectStorage) NewObject() plumbing.Object {
+func (s *ObjectStorage) NewEncodedObject() plumbing.EncodedObject {
return &plumbing.MemoryObject{}
}
@@ -73,8 +73,8 @@ func (s *ObjectStorage) PackfileWriter() (io.WriteCloser, error) {
return w, nil
}
-// Set adds a new object to the storage.
-func (s *ObjectStorage) SetObject(o plumbing.Object) (plumbing.Hash, error) {
+// SetEncodedObject adds a new object to the storage.
+func (s *ObjectStorage) SetEncodedObject(o plumbing.EncodedObject) (plumbing.Hash, error) {
if o.Type() == plumbing.OFSDeltaObject || o.Type() == plumbing.REFDeltaObject {
return plumbing.ZeroHash, plumbing.ErrInvalidType
}
@@ -104,9 +104,9 @@ func (s *ObjectStorage) SetObject(o plumbing.Object) (plumbing.Hash, error) {
return o.Hash(), nil
}
-// Get returns the object with the given hash, by searching for it in
+// EncodedObject returns the object with the given hash, by searching for it in
// the packfile and the git object directories.
-func (s *ObjectStorage) Object(t plumbing.ObjectType, h plumbing.Hash) (plumbing.Object, error) {
+func (s *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) {
obj, err := s.getFromUnpacked(h)
if err == plumbing.ErrObjectNotFound {
obj, err = s.getFromPackfile(h)
@@ -123,7 +123,7 @@ func (s *ObjectStorage) Object(t plumbing.ObjectType, h plumbing.Hash) (plumbing
return obj, nil
}
-func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.Object, err error) {
+func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedObject, err error) {
f, err := s.dir.Object(h)
if err != nil {
if os.IsNotExist(err) {
@@ -135,7 +135,7 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.Object, e
defer f.Close()
- obj = s.NewObject()
+ obj = s.NewEncodedObject()
r, err := objfile.NewReader(f)
if err != nil {
return nil, err
@@ -161,7 +161,7 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.Object, e
// Get returns the object with the given hash, by searching for it in
// the packfile.
-func (s *ObjectStorage) getFromPackfile(h plumbing.Hash) (plumbing.Object, error) {
+func (s *ObjectStorage) getFromPackfile(h plumbing.Hash) (plumbing.EncodedObject, error) {
pack, offset := s.findObjectInPackfile(h)
if offset == -1 {
return nil, plumbing.ErrObjectNotFound
@@ -194,16 +194,16 @@ func (s *ObjectStorage) findObjectInPackfile(h plumbing.Hash) (plumbing.Hash, in
return plumbing.ZeroHash, -1
}
-// Iter returns an iterator for all the objects in the packfile with the
-// given type.
-func (s *ObjectStorage) IterObjects(t plumbing.ObjectType) (storer.ObjectIter, error) {
+// IterEncodedObjects returns an iterator for all the objects in the packfile
+// with the given type.
+func (s *ObjectStorage) IterEncodedObjects(t plumbing.ObjectType) (storer.EncodedObjectIter, error) {
objects, err := s.dir.Objects()
if err != nil {
return nil, err
}
seen := make(map[plumbing.Hash]bool, 0)
- var iters []storer.ObjectIter
+ var iters []storer.EncodedObjectIter
if len(objects) != 0 {
iters = append(iters, &objectsIter{s: s, t: t, h: objects})
seen = hashListAsMap(objects)
@@ -215,17 +215,17 @@ func (s *ObjectStorage) IterObjects(t plumbing.ObjectType) (storer.ObjectIter, e
}
iters = append(iters, packi...)
- return storer.NewMultiObjectIter(iters), nil
+ return storer.NewMultiEncodedObjectIter(iters), nil
}
func (s *ObjectStorage) buildPackfileIters(
- t plumbing.ObjectType, seen map[plumbing.Hash]bool) ([]storer.ObjectIter, error) {
+ t plumbing.ObjectType, seen map[plumbing.Hash]bool) ([]storer.EncodedObjectIter, error) {
packs, err := s.dir.ObjectPacks()
if err != nil {
return nil, err
}
- var iters []storer.ObjectIter
+ var iters []storer.EncodedObjectIter
for _, h := range packs {
pack, err := s.dir.ObjectPack(h)
if err != nil {
@@ -270,7 +270,7 @@ type packfileIter struct {
total uint32
}
-func newPackfileIter(f fs.File, t plumbing.ObjectType, seen map[plumbing.Hash]bool) (storer.ObjectIter, error) {
+func newPackfileIter(f fs.File, t plumbing.ObjectType, seen map[plumbing.Hash]bool) (storer.EncodedObjectIter, error) {
s := packfile.NewScanner(f)
_, total, err := s.Header()
if err != nil {
@@ -292,7 +292,7 @@ func newPackfileIter(f fs.File, t plumbing.ObjectType, seen map[plumbing.Hash]bo
}, nil
}
-func (iter *packfileIter) Next() (plumbing.Object, error) {
+func (iter *packfileIter) Next() (plumbing.EncodedObject, error) {
if iter.position >= iter.total {
return nil, io.EOF
}
@@ -315,7 +315,7 @@ func (iter *packfileIter) Next() (plumbing.Object, error) {
}
// ForEach is never called since is used inside of a MultiObjectIterator
-func (iter *packfileIter) ForEach(cb func(plumbing.Object) error) error {
+func (iter *packfileIter) ForEach(cb func(plumbing.EncodedObject) error) error {
return nil
}
@@ -330,7 +330,7 @@ type objectsIter struct {
h []plumbing.Hash
}
-func (iter *objectsIter) Next() (plumbing.Object, error) {
+func (iter *objectsIter) Next() (plumbing.EncodedObject, error) {
if len(iter.h) == 0 {
return nil, io.EOF
}
@@ -350,7 +350,7 @@ func (iter *objectsIter) Next() (plumbing.Object, error) {
}
// ForEach is never called since is used inside of a MultiObjectIterator
-func (iter *objectsIter) ForEach(cb func(plumbing.Object) error) error {
+func (iter *objectsIter) ForEach(cb func(plumbing.EncodedObject) error) error {
return nil
}
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go
index f839420..a3a5e68 100644
--- a/storage/filesystem/object_test.go
+++ b/storage/filesystem/object_test.go
@@ -20,7 +20,7 @@ func (s *FsSuite) TestGetFromObjectFile(c *C) {
c.Assert(err, IsNil)
expected := plumbing.NewHash("f3dfe29d268303fc6e1bbce268605fc99573406e")
- obj, err := o.Object(plumbing.AnyObject, expected)
+ obj, err := o.EncodedObject(plumbing.AnyObject, expected)
c.Assert(err, IsNil)
c.Assert(obj.Hash(), Equals, expected)
}
@@ -32,7 +32,7 @@ func (s *FsSuite) TestGetFromPackfile(c *C) {
c.Assert(err, IsNil)
expected := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
- obj, err := o.Object(plumbing.AnyObject, expected)
+ obj, err := o.EncodedObject(plumbing.AnyObject, expected)
c.Assert(err, IsNil)
c.Assert(obj.Hash(), Equals, expected)
})
@@ -60,11 +60,11 @@ func (s *FsSuite) TestIter(c *C) {
o, err := newObjectStorage(dotgit.New(fs))
c.Assert(err, IsNil)
- iter, err := o.IterObjects(plumbing.AnyObject)
+ iter, err := o.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
var count int32
- err = iter.ForEach(func(o plumbing.Object) error {
+ err = iter.ForEach(func(o plumbing.EncodedObject) error {
count++
return nil
})
@@ -80,10 +80,10 @@ func (s *FsSuite) TestIterWithType(c *C) {
o, err := newObjectStorage(dotgit.New(fs))
c.Assert(err, IsNil)
- iter, err := o.IterObjects(plumbing.CommitObject)
+ iter, err := o.IterEncodedObjects(plumbing.CommitObject)
c.Assert(err, IsNil)
- err = iter.ForEach(func(o plumbing.Object) error {
+ err = iter.ForEach(func(o plumbing.EncodedObject) error {
c.Assert(o.Type(), Equals, plumbing.CommitObject)
return nil
})
diff --git a/storage/memory/storage.go b/storage/memory/storage.go
index a7a2150..a912e94 100644
--- a/storage/memory/storage.go
+++ b/storage/memory/storage.go
@@ -27,11 +27,11 @@ func NewStorage() *Storage {
ReferenceStorage: make(ReferenceStorage, 0),
ConfigStorage: ConfigStorage{},
ObjectStorage: ObjectStorage{
- Objects: make(map[plumbing.Hash]plumbing.Object, 0),
- Commits: make(map[plumbing.Hash]plumbing.Object, 0),
- Trees: make(map[plumbing.Hash]plumbing.Object, 0),
- Blobs: make(map[plumbing.Hash]plumbing.Object, 0),
- Tags: make(map[plumbing.Hash]plumbing.Object, 0),
+ Objects: make(map[plumbing.Hash]plumbing.EncodedObject, 0),
+ Commits: make(map[plumbing.Hash]plumbing.EncodedObject, 0),
+ Trees: make(map[plumbing.Hash]plumbing.EncodedObject, 0),
+ Blobs: make(map[plumbing.Hash]plumbing.EncodedObject, 0),
+ Tags: make(map[plumbing.Hash]plumbing.EncodedObject, 0),
},
}
}
@@ -58,18 +58,18 @@ func (c *ConfigStorage) Config() (*config.Config, error) {
}
type ObjectStorage struct {
- Objects map[plumbing.Hash]plumbing.Object
- Commits map[plumbing.Hash]plumbing.Object
- Trees map[plumbing.Hash]plumbing.Object
- Blobs map[plumbing.Hash]plumbing.Object
- Tags map[plumbing.Hash]plumbing.Object
+ Objects map[plumbing.Hash]plumbing.EncodedObject
+ Commits map[plumbing.Hash]plumbing.EncodedObject
+ Trees map[plumbing.Hash]plumbing.EncodedObject
+ Blobs map[plumbing.Hash]plumbing.EncodedObject
+ Tags map[plumbing.Hash]plumbing.EncodedObject
}
-func (o *ObjectStorage) NewObject() plumbing.Object {
+func (o *ObjectStorage) NewEncodedObject() plumbing.EncodedObject {
return &plumbing.MemoryObject{}
}
-func (o *ObjectStorage) SetObject(obj plumbing.Object) (plumbing.Hash, error) {
+func (o *ObjectStorage) SetEncodedObject(obj plumbing.EncodedObject) (plumbing.Hash, error) {
h := obj.Hash()
o.Objects[h] = obj
@@ -89,7 +89,7 @@ func (o *ObjectStorage) SetObject(obj plumbing.Object) (plumbing.Hash, error) {
return h, nil
}
-func (o *ObjectStorage) Object(t plumbing.ObjectType, h plumbing.Hash) (plumbing.Object, error) {
+func (o *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) {
obj, ok := o.Objects[h]
if !ok || (plumbing.AnyObject != t && obj.Type() != t) {
return nil, plumbing.ErrObjectNotFound
@@ -98,8 +98,8 @@ func (o *ObjectStorage) Object(t plumbing.ObjectType, h plumbing.Hash) (plumbing
return obj, nil
}
-func (o *ObjectStorage) IterObjects(t plumbing.ObjectType) (storer.ObjectIter, error) {
- var series []plumbing.Object
+func (o *ObjectStorage) IterEncodedObjects(t plumbing.ObjectType) (storer.EncodedObjectIter, error) {
+ var series []plumbing.EncodedObject
switch t {
case plumbing.AnyObject:
series = flattenObjectMap(o.Objects)
@@ -113,11 +113,11 @@ func (o *ObjectStorage) IterObjects(t plumbing.ObjectType) (storer.ObjectIter, e
series = flattenObjectMap(o.Tags)
}
- return storer.NewObjectSliceIter(series), nil
+ return storer.NewEncodedObjectSliceIter(series), nil
}
-func flattenObjectMap(m map[plumbing.Hash]plumbing.Object) []plumbing.Object {
- objects := make([]plumbing.Object, 0, len(m))
+func flattenObjectMap(m map[plumbing.Hash]plumbing.EncodedObject) []plumbing.EncodedObject {
+ objects := make([]plumbing.EncodedObject, 0, len(m))
for _, obj := range m {
objects = append(objects, obj)
}
@@ -127,23 +127,23 @@ func flattenObjectMap(m map[plumbing.Hash]plumbing.Object) []plumbing.Object {
func (o *ObjectStorage) Begin() storer.Transaction {
return &TxObjectStorage{
Storage: o,
- Objects: make(map[plumbing.Hash]plumbing.Object, 0),
+ Objects: make(map[plumbing.Hash]plumbing.EncodedObject, 0),
}
}
type TxObjectStorage struct {
Storage *ObjectStorage
- Objects map[plumbing.Hash]plumbing.Object
+ Objects map[plumbing.Hash]plumbing.EncodedObject
}
-func (tx *TxObjectStorage) SetObject(obj plumbing.Object) (plumbing.Hash, error) {
+func (tx *TxObjectStorage) SetEncodedObject(obj plumbing.EncodedObject) (plumbing.Hash, error) {
h := obj.Hash()
tx.Objects[h] = obj
return h, nil
}
-func (tx *TxObjectStorage) Object(t plumbing.ObjectType, h plumbing.Hash) (plumbing.Object, error) {
+func (tx *TxObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) {
obj, ok := tx.Objects[h]
if !ok || (plumbing.AnyObject != t && obj.Type() != t) {
return nil, plumbing.ErrObjectNotFound
@@ -155,7 +155,7 @@ func (tx *TxObjectStorage) Object(t plumbing.ObjectType, h plumbing.Hash) (plumb
func (tx *TxObjectStorage) Commit() error {
for h, obj := range tx.Objects {
delete(tx.Objects, h)
- if _, err := tx.Storage.SetObject(obj); err != nil {
+ if _, err := tx.Storage.SetEncodedObject(obj); err != nil {
return err
}
}
@@ -164,7 +164,7 @@ func (tx *TxObjectStorage) Commit() error {
}
func (tx *TxObjectStorage) Rollback() error {
- tx.Objects = make(map[plumbing.Hash]plumbing.Object, 0)
+ tx.Objects = make(map[plumbing.Hash]plumbing.EncodedObject, 0)
return nil
}
diff --git a/storage/test/storage_suite.go b/storage/test/storage_suite.go
index 732c7a9..9d63ff8 100644
--- a/storage/test/storage_suite.go
+++ b/storage/test/storage_suite.go
@@ -15,13 +15,13 @@ import (
)
type Storer interface {
- storer.ObjectStorer
+ storer.EncodedObjectStorer
storer.ReferenceStorer
config.ConfigStorer
}
type TestObject struct {
- Object plumbing.Object
+ Object plumbing.EncodedObject
Hash string
Type plumbing.ObjectType
}
@@ -59,19 +59,19 @@ func NewBaseStorageSuite(s Storer) BaseStorageSuite {
}}
}
-func (s *BaseStorageSuite) TestSetObjectAndGetObject(c *C) {
+func (s *BaseStorageSuite) TestSetEncodedObjectAndEncodedObject(c *C) {
for _, to := range s.testObjects {
comment := Commentf("failed for type %s", to.Type.String())
- h, err := s.Storer.SetObject(to.Object)
+ h, err := s.Storer.SetEncodedObject(to.Object)
c.Assert(err, IsNil)
c.Assert(h.String(), Equals, to.Hash, comment)
- o, err := s.Storer.Object(to.Type, h)
+ o, err := s.Storer.EncodedObject(to.Type, h)
c.Assert(err, IsNil)
c.Assert(objectEquals(o, to.Object), IsNil)
- o, err = s.Storer.Object(plumbing.AnyObject, h)
+ o, err = s.Storer.EncodedObject(plumbing.AnyObject, h)
c.Assert(err, IsNil)
c.Assert(objectEquals(o, to.Object), IsNil)
@@ -80,31 +80,31 @@ func (s *BaseStorageSuite) TestSetObjectAndGetObject(c *C) {
continue
}
- o, err = s.Storer.Object(t, h)
+ o, err = s.Storer.EncodedObject(t, h)
c.Assert(o, IsNil)
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
}
}
}
-func (s *BaseStorageSuite) TestSetObjectInvalid(c *C) {
- o := s.Storer.NewObject()
+func (s *BaseStorageSuite) TestSetEncodedObjectInvalid(c *C) {
+ o := s.Storer.NewEncodedObject()
o.SetType(plumbing.REFDeltaObject)
- _, err := s.Storer.SetObject(o)
+ _, err := s.Storer.SetEncodedObject(o)
c.Assert(err, NotNil)
}
-func (s *BaseStorageSuite) TestStorerIter(c *C) {
+func (s *BaseStorageSuite) TestIterEncodedObjects(c *C) {
for _, o := range s.testObjects {
- h, err := s.Storer.SetObject(o.Object)
+ h, err := s.Storer.SetEncodedObject(o.Object)
c.Assert(err, IsNil)
c.Assert(h, Equals, o.Object.Hash())
}
for _, t := range s.validTypes {
comment := Commentf("failed for type %s)", t.String())
- i, err := s.Storer.IterObjects(t)
+ i, err := s.Storer.IterEncodedObjects(t)
c.Assert(err, IsNil, comment)
o, err := i.Next()
@@ -116,11 +116,11 @@ func (s *BaseStorageSuite) TestStorerIter(c *C) {
c.Assert(err, Equals, io.EOF, comment)
}
- i, err := s.Storer.IterObjects(plumbing.AnyObject)
+ i, err := s.Storer.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
- foundObjects := []plumbing.Object{}
- i.ForEach(func(o plumbing.Object) error {
+ foundObjects := []plumbing.EncodedObject{}
+ i.ForEach(func(o plumbing.EncodedObject) error {
foundObjects = append(foundObjects, o)
return nil
})
@@ -138,7 +138,7 @@ func (s *BaseStorageSuite) TestStorerIter(c *C) {
}
}
-func (s *BaseStorageSuite) TestObjectStorerTxSetObjectAndCommit(c *C) {
+func (s *BaseStorageSuite) TestObjectStorerTxSetEncodedObjectAndCommit(c *C) {
storer, ok := s.Storer.(storer.Transactioner)
if !ok {
c.Skip("not a plumbing.ObjectStorerTx")
@@ -146,12 +146,12 @@ func (s *BaseStorageSuite) TestObjectStorerTxSetObjectAndCommit(c *C) {
tx := storer.Begin()
for _, o := range s.testObjects {
- h, err := tx.SetObject(o.Object)
+ h, err := tx.SetEncodedObject(o.Object)
c.Assert(err, IsNil)
c.Assert(h.String(), Equals, o.Hash)
}
- iter, err := s.Storer.IterObjects(plumbing.AnyObject)
+ iter, err := s.Storer.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
_, err = iter.Next()
c.Assert(err, Equals, io.EOF)
@@ -159,11 +159,11 @@ func (s *BaseStorageSuite) TestObjectStorerTxSetObjectAndCommit(c *C) {
err = tx.Commit()
c.Assert(err, IsNil)
- iter, err = s.Storer.IterObjects(plumbing.AnyObject)
+ iter, err = s.Storer.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
var count int
- iter.ForEach(func(o plumbing.Object) error {
+ iter.ForEach(func(o plumbing.EncodedObject) error {
count++
return nil
})
@@ -179,11 +179,11 @@ func (s *BaseStorageSuite) TestObjectStorerTxSetObjectAndGetObject(c *C) {
tx := storer.Begin()
for _, expected := range s.testObjects {
- h, err := tx.SetObject(expected.Object)
+ h, err := tx.SetEncodedObject(expected.Object)
c.Assert(err, IsNil)
c.Assert(h.String(), Equals, expected.Hash)
- o, err := tx.Object(expected.Type, plumbing.NewHash(expected.Hash))
+ o, err := tx.EncodedObject(expected.Type, plumbing.NewHash(expected.Hash))
c.Assert(err, IsNil)
c.Assert(o.Hash().String(), DeepEquals, expected.Hash)
}
@@ -196,7 +196,7 @@ func (s *BaseStorageSuite) TestObjectStorerTxGetObjectNotFound(c *C) {
}
tx := storer.Begin()
- o, err := tx.Object(plumbing.AnyObject, plumbing.ZeroHash)
+ o, err := tx.EncodedObject(plumbing.AnyObject, plumbing.ZeroHash)
c.Assert(o, IsNil)
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
}
@@ -209,7 +209,7 @@ func (s *BaseStorageSuite) TestObjectStorerTxSetObjectAndRollback(c *C) {
tx := storer.Begin()
for _, o := range s.testObjects {
- h, err := tx.SetObject(o.Object)
+ h, err := tx.SetEncodedObject(o.Object)
c.Assert(err, IsNil)
c.Assert(h.String(), Equals, o.Hash)
}
@@ -217,7 +217,7 @@ func (s *BaseStorageSuite) TestObjectStorerTxSetObjectAndRollback(c *C) {
err := tx.Rollback()
c.Assert(err, IsNil)
- iter, err := s.Storer.IterObjects(plumbing.AnyObject)
+ iter, err := s.Storer.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
_, err = iter.Next()
c.Assert(err, Equals, io.EOF)
@@ -287,7 +287,7 @@ func (s *BaseStorageSuite) TestSetConfigInvalid(c *C) {
c.Assert(err, NotNil)
}
-func objectEquals(a plumbing.Object, b plumbing.Object) error {
+func objectEquals(a plumbing.EncodedObject, b plumbing.EncodedObject) error {
ha := a.Hash()
hb := b.Hash()
if ha != hb {