aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/encoder.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-05-24 19:25:08 +0200
committerGitHub <noreply@github.com>2020-05-24 19:25:08 +0200
commit8019144b6534ff58ad234a355e5b143f1c99b45e (patch)
tree5a67682c34bb20a826ebf430f11181d6892fc0e7 /plumbing/format/packfile/encoder.go
parente7f544844d6d736acfd9d75ee0d4a9d37f450103 (diff)
parent10199949b9e5a71f72241c4bb23f3d733287065c (diff)
downloadgo-git-8019144b6534ff58ad234a355e5b143f1c99b45e.tar.gz
Merge pull request #73 from WKBae/close_objectv5.1.0
Close Reader & Writer of EncodedObject after use
Diffstat (limited to 'plumbing/format/packfile/encoder.go')
-rw-r--r--plumbing/format/packfile/encoder.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/plumbing/format/packfile/encoder.go b/plumbing/format/packfile/encoder.go
index 65fae52..5501f88 100644
--- a/plumbing/format/packfile/encoder.go
+++ b/plumbing/format/packfile/encoder.go
@@ -9,6 +9,7 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/storer"
"github.com/go-git/go-git/v5/utils/binary"
+ "github.com/go-git/go-git/v5/utils/ioutil"
)
// Encoder gets the data from the storage and write it into the writer in PACK
@@ -80,7 +81,7 @@ func (e *Encoder) head(numEntries int) error {
)
}
-func (e *Encoder) entry(o *ObjectToPack) error {
+func (e *Encoder) entry(o *ObjectToPack) (err error) {
if o.WantWrite() {
// A cycle exists in this delta chain. This should only occur if a
// selected object representation disappeared during writing
@@ -119,17 +120,22 @@ func (e *Encoder) entry(o *ObjectToPack) error {
}
e.zw.Reset(e.w)
+
+ defer ioutil.CheckClose(e.zw, &err)
+
or, err := o.Object.Reader()
if err != nil {
return err
}
+ defer ioutil.CheckClose(or, &err)
+
_, err = io.Copy(e.zw, or)
if err != nil {
return err
}
- return e.zw.Close()
+ return nil
}
func (e *Encoder) writeBaseIfDelta(o *ObjectToPack) error {