diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-09-22 21:14:17 -0700 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-29 11:01:41 -0800 |
commit | aa092f5474da3e9c3ff4f40b88849726b645f39f (patch) | |
tree | 08655a5576a113c2946b5eac2ca801b3f5eece6f /storage/memory/storage.go | |
parent | 2de4f034288bac895b0a87dcfb5cc3a2f9026f43 (diff) | |
download | go-git-aa092f5474da3e9c3ff4f40b88849726b645f39f.tar.gz |
plumbing: add `HasEncodedObject` method to Storer
This allows the user to check whether an object exists, without
reading all the object data from storage.
Issue: KBFS-2445
Diffstat (limited to 'storage/memory/storage.go')
-rw-r--r-- | storage/memory/storage.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/storage/memory/storage.go b/storage/memory/storage.go index 2d1a4b6..c76d163 100644 --- a/storage/memory/storage.go +++ b/storage/memory/storage.go @@ -115,6 +115,14 @@ func (o *ObjectStorage) SetEncodedObject(obj plumbing.EncodedObject) (plumbing.H return h, nil } +func (o *ObjectStorage) HasEncodedObject(h plumbing.Hash) (err error) { + _, ok := o.Objects[h] + if !ok { + return plumbing.ErrObjectNotFound + } + return nil +} + 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) { |