diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-11-06 17:18:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-06 17:18:19 +0000 |
commit | 48bec23593e78f55f1470e10d30b22f3bb7a2c1f (patch) | |
tree | 581a5c41f78346aaa05ed8bff276c6df40fb3e41 /storage | |
parent | 8c1e3e2eb458677af127fc286a43ad262c3cca1e (diff) | |
parent | 1c361adbc1f4b0e3d0743d11f187fb0b3ac4cb4d (diff) | |
download | go-git-48bec23593e78f55f1470e10d30b22f3bb7a2c1f.tar.gz |
Merge pull request #799 from pjbgf/perf2
plumbing: Optimise memory consumption for filesystem storage
Diffstat (limited to 'storage')
-rw-r--r-- | storage/filesystem/object.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index 846a7b8..e812fe9 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -146,6 +146,19 @@ func (s *ObjectStorage) SetEncodedObject(o plumbing.EncodedObject) (h plumbing.H return o.Hash(), err } +// LazyWriter returns a lazy ObjectWriter that is bound to a DotGit file. +// It first write the header passing on the object type and size, so +// that the object contents can be written later, without the need to +// create a MemoryObject and buffering its entire contents into memory. +func (s *ObjectStorage) LazyWriter() (w io.WriteCloser, wh func(typ plumbing.ObjectType, sz int64) error, err error) { + ow, err := s.dir.NewObject() + if err != nil { + return nil, nil, err + } + + return ow, ow.WriteHeader, nil +} + // HasEncodedObject returns nil if the object exists, without actually // reading the object data from storage. func (s *ObjectStorage) HasEncodedObject(h plumbing.Hash) (err error) { |