MCPcopy Create free account
hub / github.com/encoder-run/operator / EncodedObject

Method EncodedObject

pkg/cache/redis/object.go:57–88  ·  view source on GitHub ↗

EncodedObject retrieves an encoded object from Redis by its hash.

(t plumbing.ObjectType, h plumbing.Hash)

Source from the content-addressed store, hash-verified

55
56// EncodedObject retrieves an encoded object from Redis by its hash.
57func (s *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) {
58 // if the object type is AnyObject, we need to try and get the object for each type until we find it.
59 if t == plumbing.AnyObject {
60 for _, ot := range []plumbing.ObjectType{plumbing.CommitObject, plumbing.TreeObject, plumbing.BlobObject, plumbing.TagObject, plumbing.OFSDeltaObject, plumbing.REFDeltaObject} {
61 obj, err := s.EncodedObject(ot, h)
62 if err == nil {
63 return obj, nil
64 }
65 }
66 return nil, plumbing.ErrObjectNotFound
67 }
68
69 // Get object data by hash as key with prefix "object:", type and hash.
70 key := fmt.Sprintf("%s:%s", t, h)
71 data, err := s.client.Get(ctx, withNamespace(s.namespacePrefix, objectPrefix, key)).Bytes()
72 if err != nil {
73 if err == redis.Nil {
74 return nil, plumbing.ErrObjectNotFound
75 }
76 return nil, err
77 }
78
79 o := &plumbing.MemoryObject{}
80 o.SetType(t)
81 o.SetSize(int64(len(data)))
82 _, err = o.Write(data)
83 if err != nil {
84 return nil, err
85 }
86
87 return o, nil
88}
89
90// EncodedObjectSize implements storage.Storer.
91func (s *Storage) EncodedObjectSize(h plumbing.Hash) (int64, error) {

Callers

nothing calls this directly

Calls 1

withNamespaceFunction · 0.85

Tested by

no test coverage detected