aboutsummaryrefslogtreecommitdiffstats
path: root/storage/memory/storage.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-12-14 23:12:44 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-12-14 23:12:44 +0100
commit0af572dd21c0aa79d13745b633ee24ba6c4d6cf1 (patch)
tree49e81e74e82d84fd88b2fc1e4b0dc7c7bfe9c40f /storage/memory/storage.go
parentdf0f38af83f972f026d7e14150f3d37b95f13484 (diff)
downloadgo-git-0af572dd21c0aa79d13745b633ee24ba6c4d6cf1.tar.gz
move plumbing from top level package to plumbing (#183)
* plumbing: rename Object -> EncodedObject. * plumbing/storer: rename ObjectStorer -> EncodedObjectStorer. * move difftree to plumbing/difftree. * move diff -> utils/diff * make Object/Tag/Blob/Tree/Commit/File depend on storer. * Object and its implementations now depend only on storer.EncodedObjectStorer, not git.Repository. * Tests are decoupled accordingly. * move Object/Commit/File/Tag/Tree to plumbing/object. * move Object/Commit/File/Tag/Tree to plumbing/object. * move checkClose to utils/ioutil. * move RevListObjects to plumbing/revlist.Objects. * move DiffTree to plumbing/difftree package. * rename files with plural nouns to singular * plumbing/object: add GetBlob/GetCommit/GetTag/GetTree.
Diffstat (limited to 'storage/memory/storage.go')
-rw-r--r--storage/memory/storage.go48
1 files changed, 24 insertions, 24 deletions
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
}