HashesWithPrefix returns all objects with a hash that starts with a prefix by searching for them in the packfile and the git object directories.
(prefix []byte)
| 553 | // HashesWithPrefix returns all objects with a hash that starts with a prefix by searching for |
| 554 | // them in the packfile and the git object directories. |
| 555 | func (s *ObjectStorage) HashesWithPrefix(prefix []byte) ([]plumbing.Hash, error) { |
| 556 | hashes, err := s.dir.ObjectsWithPrefix(prefix) |
| 557 | if err != nil { |
| 558 | return nil, err |
| 559 | } |
| 560 | |
| 561 | seen := hashListAsMap(hashes) |
| 562 | |
| 563 | // TODO: This could be faster with some idxfile changes, |
| 564 | // or diving into the packfile. |
| 565 | if err := s.requireIndex(); err != nil { |
| 566 | return nil, err |
| 567 | } |
| 568 | for _, index := range s.index { |
| 569 | ei, err := index.Entries() |
| 570 | if err != nil { |
| 571 | return nil, err |
| 572 | } |
| 573 | for { |
| 574 | e, err := ei.Next() |
| 575 | if err == io.EOF { |
| 576 | break |
| 577 | } else if err != nil { |
| 578 | return nil, err |
| 579 | } |
| 580 | if bytes.HasPrefix(e.Hash[:], prefix) { |
| 581 | if _, ok := seen[e.Hash]; ok { |
| 582 | continue |
| 583 | } |
| 584 | hashes = append(hashes, e.Hash) |
| 585 | } |
| 586 | } |
| 587 | ei.Close() |
| 588 | } |
| 589 | |
| 590 | return hashes, nil |
| 591 | } |
| 592 | |
| 593 | // IterEncodedObjects returns an iterator for all the objects in the packfile |
| 594 | // with the given type. |