MCPcopy Create free account
hub / github.com/go-git/go-git / EncodedObject

Method EncodedObject

storage/filesystem/object.go:326–369  ·  view source on GitHub ↗

EncodedObject returns the object with the given hash, by searching for it in the packfile and the git object directories.

(t plumbing.ObjectType, h plumbing.Hash)

Source from the content-addressed store, hash-verified

324// EncodedObject returns the object with the given hash, by searching for it in
325// the packfile and the git object directories.
326func (s *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) {
327 var obj plumbing.EncodedObject
328 var err error
329
330 if s.index != nil {
331 obj, err = s.getFromPackfile(h, false)
332 if err == plumbing.ErrObjectNotFound {
333 obj, err = s.getFromUnpacked(h)
334 }
335 } else {
336 obj, err = s.getFromUnpacked(h)
337 if err == plumbing.ErrObjectNotFound {
338 obj, err = s.getFromPackfile(h, false)
339 }
340 }
341
342 // If the error is still object not found, check if it's a shared object
343 // repository.
344 if err == plumbing.ErrObjectNotFound {
345 dotgits, e := s.dir.Alternates()
346 if e == nil {
347 // Create a new object storage with the DotGit(s) and check for the
348 // required hash object. Skip when not found.
349 for _, dg := range dotgits {
350 o := NewObjectStorage(dg, s.objectCache)
351 enobj, enerr := o.EncodedObject(t, h)
352 if enerr != nil {
353 continue
354 }
355 return enobj, nil
356 }
357 }
358 }
359
360 if err != nil {
361 return nil, err
362 }
363
364 if plumbing.AnyObject != t && obj.Type() != t {
365 return nil, plumbing.ErrObjectNotFound
366 }
367
368 return obj, nil
369}
370
371// DeltaObject returns the object with the given hash, by searching for
372// it in the packfile and the git object directories.

Calls 5

getFromPackfileMethod · 0.95
getFromUnpackedMethod · 0.95
TypeMethod · 0.95
AlternatesMethod · 0.80
NewObjectStorageFunction · 0.70

Tested by 5

TestGetFromObjectFileMethod · 0.76
TestGetFromPackfileMethod · 0.76
TestHashesWithPrefixMethod · 0.76