diff options
author | Santiago M. Mola <santi@mola.io> | 2016-08-29 22:47:13 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-29 22:47:13 +0200 |
commit | e4246138cb9ffb819c052ba17a9fbdf915427291 (patch) | |
tree | bd938368afe0ffd7c9e1df16256e39e17d8184b5 /storage/memory/storage.go | |
parent | dd4af03ad368cc50dd08912010f5b667bd7569cd (diff) | |
download | go-git-e4246138cb9ffb819c052ba17a9fbdf915427291.tar.gz |
storage: Add object type hint parameter to ObjectStorage.Get. (#69)
Some storage backends can optimize object lookup if they get
the object type that is expected. So we the signature of the Get
method is now Get(Hash, ObjectType).
Added generic tests for storage backends.
Diffstat (limited to 'storage/memory/storage.go')
-rw-r--r-- | storage/memory/storage.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/storage/memory/storage.go b/storage/memory/storage.go index d67368f..8033541 100644 --- a/storage/memory/storage.go +++ b/storage/memory/storage.go @@ -130,12 +130,11 @@ func (o *ObjectStorage) Set(obj core.Object) (core.Hash, error) { } // Get returns a object with the given hash -func (o *ObjectStorage) Get(h core.Hash) (core.Object, error) { +func (o *ObjectStorage) Get(h core.Hash, t core.ObjectType) (core.Object, error) { obj, ok := o.Objects[h] - if !ok { + if !ok || (core.AnyObject != t && obj.Type() != t) { return nil, core.ErrObjectNotFound } - return obj, nil } @@ -143,6 +142,8 @@ func (o *ObjectStorage) Get(h core.Hash) (core.Object, error) { func (o *ObjectStorage) Iter(t core.ObjectType) (core.ObjectIter, error) { var series []core.Object switch t { + case core.AnyObject: + series = flattenObjectMap(o.Objects) case core.CommitObject: series = flattenObjectMap(o.Commits) case core.TreeObject: |