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