MCPcopy Index your code
hub / github.com/go-git/go-git / HashesWithPrefix

Method HashesWithPrefix

storage/filesystem/object.go:564–600  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
564func (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.

Callers 2

TestHashesWithPrefixMethod · 0.95

Calls 6

requireIndexMethod · 0.95
hashListAsMapFunction · 0.85
ObjectsWithPrefixMethod · 0.80
EntriesMethod · 0.65
NextMethod · 0.65
CloseMethod · 0.65

Tested by 2

TestHashesWithPrefixMethod · 0.76