aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/object.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-09-21 12:02:17 +0200
committerGitHub <noreply@github.com>2018-09-21 12:02:17 +0200
commitc2ab4ac47d87f4cd674d19228e24b6696bd1db4d (patch)
treea5797901db8d24343a73bbc7423c0ef38a61aa60 /storage/filesystem/object.go
parentf69f5304328165153e452382f44aa2b41df36d0f (diff)
parenta7b0102b83aa86fd299623d35666bfee93fee0c6 (diff)
downloadgo-git-c2ab4ac47d87f4cd674d19228e24b6696bd1db4d.tar.gz
Merge pull request #962 from jfontan/fix/do-not-close-files-in-iterator
storage/filesystem: keep packs open in PackfileIter
Diffstat (limited to 'storage/filesystem/object.go')
-rw-r--r--storage/filesystem/object.go32
1 files changed, 24 insertions, 8 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 9eb085f..68bd140 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -396,7 +396,10 @@ func (s *ObjectStorage) IterEncodedObjects(t plumbing.ObjectType) (storer.Encode
return storer.NewMultiEncodedObjectIter(iters), nil
}
-func (s *ObjectStorage) buildPackfileIters(t plumbing.ObjectType, seen map[plumbing.Hash]struct{}) (storer.EncodedObjectIter, error) {
+func (s *ObjectStorage) buildPackfileIters(
+ t plumbing.ObjectType,
+ seen map[plumbing.Hash]struct{},
+) (storer.EncodedObjectIter, error) {
if err := s.requireIndex(); err != nil {
return nil, err
}
@@ -412,7 +415,10 @@ func (s *ObjectStorage) buildPackfileIters(t plumbing.ObjectType, seen map[plumb
if err != nil {
return nil, err
}
- return newPackfileIter(s.dir.Fs(), pack, t, seen, s.index[h], s.deltaBaseCache)
+ return newPackfileIter(
+ s.dir.Fs(), pack, t, seen, s.index[h],
+ s.deltaBaseCache, s.options.KeepDescriptors,
+ )
},
}, nil
}
@@ -473,16 +479,21 @@ type packfileIter struct {
pack billy.File
iter storer.EncodedObjectIter
seen map[plumbing.Hash]struct{}
+
+ // tells whether the pack file should be left open after iteration or not
+ keepPack bool
}
// NewPackfileIter returns a new EncodedObjectIter for the provided packfile
// and object type. Packfile and index file will be closed after they're
-// used.
+// used. If keepPack is true the packfile won't be closed after the iteration
+// finished.
func NewPackfileIter(
fs billy.Filesystem,
f billy.File,
idxFile billy.File,
t plumbing.ObjectType,
+ keepPack bool,
) (storer.EncodedObjectIter, error) {
idx := idxfile.NewMemoryIndex()
if err := idxfile.NewDecoder(idxFile).Decode(idx); err != nil {
@@ -493,7 +504,8 @@ func NewPackfileIter(
return nil, err
}
- return newPackfileIter(fs, f, t, make(map[plumbing.Hash]struct{}), idx, nil)
+ seen := make(map[plumbing.Hash]struct{})
+ return newPackfileIter(fs, f, t, seen, idx, nil, keepPack)
}
func newPackfileIter(
@@ -503,6 +515,7 @@ func newPackfileIter(
seen map[plumbing.Hash]struct{},
index idxfile.Index,
cache cache.Object,
+ keepPack bool,
) (storer.EncodedObjectIter, error) {
var p *packfile.Packfile
if cache != nil {
@@ -517,9 +530,10 @@ func newPackfileIter(
}
return &packfileIter{
- pack: f,
- iter: iter,
- seen: seen,
+ pack: f,
+ iter: iter,
+ seen: seen,
+ keepPack: keepPack,
}, nil
}
@@ -557,7 +571,9 @@ func (iter *packfileIter) ForEach(cb func(plumbing.EncodedObject) error) error {
func (iter *packfileIter) Close() {
iter.iter.Close()
- _ = iter.pack.Close()
+ if !iter.keepPack {
+ _ = iter.pack.Close()
+ }
}
type objectsIter struct {