Skip to content

Commit

Permalink
storage: filesystem, Populate index before use. Fixes go-git#148
Browse files Browse the repository at this point in the history
  • Loading branch information
AriehSchneier committed Mar 27, 2023
1 parent 3f1cfde commit 23da6b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions storage/filesystem/object.go
Expand Up @@ -545,6 +545,9 @@ func (s *ObjectStorage) HashesWithPrefix(prefix []byte) ([]plumbing.Hash, error)

// TODO: This could be faster with some idxfile changes,
// or diving into the packfile.
if err := s.requireIndex(); err != nil {
return nil, err
}
for _, index := range s.index {
ei, err := index.Entries()
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions storage/filesystem/object_test.go
Expand Up @@ -406,6 +406,21 @@ func (s *FsSuite) TestHashesWithPrefix(c *C) {
c.Assert(hashes[0].String(), Equals, "f3dfe29d268303fc6e1bbce268605fc99573406e")
}

func (s *FsSuite) TestHashesWithPrefixFromPackfile(c *C) {
// Same setup as TestGetFromPackfile
fixtures.Basic().ByTag(".git").Test(c, func(f *fixtures.Fixture) {
fs := f.DotGit()
o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault())

expected := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
// Only pass the first 8 bytes
hashes, err := o.HashesWithPrefix(expected[:8])
c.Assert(err, IsNil)
c.Assert(hashes, HasLen, 1)
c.Assert(hashes[0], Equals, expected)
})
}

func BenchmarkPackfileIter(b *testing.B) {
defer fixtures.Clean()

Expand Down

0 comments on commit 23da6b7

Please sign in to comment.