aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-08-29 22:47:13 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-29 22:47:13 +0200
commite4246138cb9ffb819c052ba17a9fbdf915427291 (patch)
treebd938368afe0ffd7c9e1df16256e39e17d8184b5 /core
parentdd4af03ad368cc50dd08912010f5b667bd7569cd (diff)
downloadgo-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 'core')
-rw-r--r--core/object.go21
-rw-r--r--core/storage.go11
2 files changed, 23 insertions, 9 deletions
diff --git a/core/object.go b/core/object.go
index 9c9a74e..7e021cb 100644
--- a/core/object.go
+++ b/core/object.go
@@ -38,17 +38,22 @@ type Object interface {
Writer() (ObjectWriter, error)
}
-// ObjectType internal object type's
+// ObjectType internal object type
+// Integer values from 0 to 7 map to those exposed by git.
+// AnyObject is used to represent any from 0 to 7.
type ObjectType int8
const (
- InvalidObject ObjectType = 0
- CommitObject ObjectType = 1
- TreeObject ObjectType = 2
- BlobObject ObjectType = 3
- TagObject ObjectType = 4
+ InvalidObject ObjectType = 0
+ CommitObject ObjectType = 1
+ TreeObject ObjectType = 2
+ BlobObject ObjectType = 3
+ TagObject ObjectType = 4
+ // 5 reserved for future expansion
OFSDeltaObject ObjectType = 6
REFDeltaObject ObjectType = 7
+
+ AnyObject ObjectType = -127
)
func (t ObjectType) String() string {
@@ -132,7 +137,7 @@ func (iter *ObjectLookupIter) Next() (Object, error) {
return nil, io.EOF
}
hash := iter.series[iter.pos]
- obj, err := iter.storage.Get(hash)
+ obj, err := iter.storage.Get(hash, AnyObject)
if err == nil {
iter.pos++
}
@@ -146,7 +151,7 @@ func (iter *ObjectLookupIter) ForEach(cb func(Object) error) error {
defer iter.Close()
for _, hash := range iter.series {
- obj, err := iter.storage.Get(hash)
+ obj, err := iter.storage.Get(hash, AnyObject)
if err != nil {
return err
}
diff --git a/core/storage.go b/core/storage.go
index f3225d8..f3ec52b 100644
--- a/core/storage.go
+++ b/core/storage.go
@@ -9,7 +9,16 @@ var ErrStop = errors.New("stop iter")
type ObjectStorage interface {
NewObject() Object
Set(Object) (Hash, error)
- Get(Hash) (Object, error)
+ // Get an object by hash with the given ObjectType.
+ //
+ // Implementors should return (nil, core.ErrObjectNotFound) if an object
+ // doesn't exist with both the given hash and object type.
+ //
+ // Valid ObjectType values are CommitObject, BlobObject, TagObject, TreeObject
+ // and AnyObject.
+ //
+ // If AnyObject is given, the object must be looked up regardless of its type.
+ Get(Hash, ObjectType) (Object, error)
Iter(ObjectType) (ObjectIter, error)
}