diff options
author | Javi Fontan <jfontan@gmail.com> | 2018-08-30 20:28:40 +0200 |
---|---|---|
committer | Javi Fontan <jfontan@gmail.com> | 2018-09-04 12:41:31 +0200 |
commit | 6384ab93a2dbac9045ee19099455cbcfe82d0201 (patch) | |
tree | 66be7ef79ec1267306af9e5e4b9870dde54ef5db /storage/filesystem/object.go | |
parent | 2f1583896bcc3c182d8165d6aeeb23c771cc5417 (diff) | |
download | go-git-6384ab93a2dbac9045ee19099455cbcfe82d0201.tar.gz |
storage/dotgit: add KeepDescriptors option
This option maintains packfile file descriptors opened after reading
objects from them. It improves performance as it does not have to be
opening packfiles each time an object is needed.
Also adds Close to EncodedObjectStorer to close all the files manualy.
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'storage/filesystem/object.go')
-rw-r--r-- | storage/filesystem/object.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index 3519385..3545e27 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -74,6 +74,7 @@ func (s *ObjectStorage) loadIdxFile(h plumbing.Hash) (err error) { } defer ioutil.CheckClose(f, &err) + idxf := idxfile.NewMemoryIndex() d := idxfile.NewDecoder(f) if err = d.Decode(idxf); err != nil { @@ -280,7 +281,9 @@ func (s *ObjectStorage) getFromPackfile(h plumbing.Hash, canBeDelta bool) ( return nil, err } - defer ioutil.CheckClose(f, &err) + if !s.options.KeepDescriptors { + defer ioutil.CheckClose(f, &err) + } idx := s.index[pack] if canBeDelta { @@ -423,6 +426,11 @@ func (s *ObjectStorage) buildPackfileIters(t plumbing.ObjectType, seen map[plumb }, nil } +// Close closes all opened files. +func (s *ObjectStorage) Close() error { + return s.dir.Close() +} + type lazyPackfilesIter struct { hashes []plumbing.Hash open func(h plumbing.Hash) (storer.EncodedObjectIter, error) |