aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plumbing/object/blob_test.go7
-rw-r--r--storage/filesystem/object.go11
2 files changed, 17 insertions, 1 deletions
diff --git a/plumbing/object/blob_test.go b/plumbing/object/blob_test.go
index 181436d..e08ff25 100644
--- a/plumbing/object/blob_test.go
+++ b/plumbing/object/blob_test.go
@@ -6,6 +6,7 @@ import (
"io/ioutil"
"gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
. "gopkg.in/check.v1"
)
@@ -70,6 +71,12 @@ func (s *BlobsSuite) TestBlobIter(c *C) {
blobs := []*Blob{}
iter.ForEach(func(b *Blob) error {
+ var err error
+ b.obj, err = packfile.MemoryObjectFromDisk(b.obj)
+ if err != nil {
+ return err
+ }
+
blobs = append(blobs, b)
return nil
})
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 4757938..86d0da9 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -457,12 +457,14 @@ func (it *lazyPackfilesIter) Close() {
}
type packfileIter struct {
+ pack billy.File
iter storer.EncodedObjectIter
seen map[plumbing.Hash]struct{}
}
// NewPackfileIter returns a new EncodedObjectIter for the provided packfile
-// and object type.
+// and object type. Packfile and index file will be closed after they're
+// used.
func NewPackfileIter(
f billy.File,
idxFile billy.File,
@@ -473,6 +475,10 @@ func NewPackfileIter(
return nil, err
}
+ if err := idxFile.Close(); err != nil {
+ return nil, err
+ }
+
return newPackfileIter(f, t, make(map[plumbing.Hash]struct{}), idx, nil)
}
@@ -489,6 +495,7 @@ func newPackfileIter(
}
return &packfileIter{
+ pack: f,
iter: iter,
seen: seen,
}, nil
@@ -514,6 +521,7 @@ func (iter *packfileIter) ForEach(cb func(plumbing.EncodedObject) error) error {
o, err := iter.Next()
if err != nil {
if err == io.EOF {
+ iter.Close()
return nil
}
return err
@@ -527,6 +535,7 @@ func (iter *packfileIter) ForEach(cb func(plumbing.EncodedObject) error) error {
func (iter *packfileIter) Close() {
iter.iter.Close()
+ _ = iter.pack.Close()
}
type objectsIter struct {