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