aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/parser.go
diff options
context:
space:
mode:
authorKyungmin Bae <kyungmin.bae@devsisters.com>2020-05-24 02:29:58 +0900
committerKyungmin Bae <kyungmin.bae@devsisters.com>2020-05-24 02:29:58 +0900
commit10199949b9e5a71f72241c4bb23f3d733287065c (patch)
tree52b3efdb1944d9c833522d32a0af5c4b275a3ab6 /plumbing/format/packfile/parser.go
parent6d8103df45ce09ffd5323b4ef46d26440400a54f (diff)
downloadgo-git-10199949b9e5a71f72241c4bb23f3d733287065c.tar.gz
Close Reader & Writer of EncodedObject after use
Diffstat (limited to 'plumbing/format/packfile/parser.go')
-rw-r--r--plumbing/format/packfile/parser.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/plumbing/format/packfile/parser.go b/plumbing/format/packfile/parser.go
index d411c5b..4b5a570 100644
--- a/plumbing/format/packfile/parser.go
+++ b/plumbing/format/packfile/parser.go
@@ -4,11 +4,12 @@ import (
"bytes"
"errors"
"io"
- "io/ioutil"
+ stdioutil "io/ioutil"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/cache"
"github.com/go-git/go-git/v5/plumbing/storer"
+ "github.com/go-git/go-git/v5/utils/ioutil"
)
var (
@@ -283,7 +284,7 @@ func (p *Parser) resolveDeltas() error {
if !obj.IsDelta() && len(obj.Children) > 0 {
for _, child := range obj.Children {
- if err := p.resolveObject(ioutil.Discard, child, content); err != nil {
+ if err := p.resolveObject(stdioutil.Discard, child, content); err != nil {
return err
}
}
@@ -298,7 +299,7 @@ func (p *Parser) resolveDeltas() error {
return nil
}
-func (p *Parser) get(o *objectInfo, buf *bytes.Buffer) error {
+func (p *Parser) get(o *objectInfo, buf *bytes.Buffer) (err error) {
if !o.ExternalRef { // skip cache check for placeholder parents
b, ok := p.cache.Get(o.Offset)
if ok {
@@ -310,17 +311,21 @@ func (p *Parser) get(o *objectInfo, buf *bytes.Buffer) error {
// If it's not on the cache and is not a delta we can try to find it in the
// storage, if there's one. External refs must enter here.
if p.storage != nil && !o.Type.IsDelta() {
- e, err := p.storage.EncodedObject(plumbing.AnyObject, o.SHA1)
+ var e plumbing.EncodedObject
+ e, err = p.storage.EncodedObject(plumbing.AnyObject, o.SHA1)
if err != nil {
return err
}
o.Type = e.Type()
- r, err := e.Reader()
+ var r io.ReadCloser
+ r, err = e.Reader()
if err != nil {
return err
}
+ defer ioutil.CheckClose(r, &err)
+
_, err = buf.ReadFrom(io.LimitReader(r, e.Size()))
return err
}