git/odb: don't close Blob types after decoding

This commit is contained in:
Taylor Blau 2017-06-06 10:49:10 -06:00
parent e571e7f2bf
commit 1d5ef4c427

@ -237,6 +237,12 @@ func (o *ObjectDatabase) open(sha []byte) (*ObjectReader, error) {
// decode decodes an object given by the sha "sha []byte" into the given object
// "into", or returns an error if one was encountered.
//
// Ordinarily, it closes the object's underlying io.ReadCloser (if it implements
// the `io.Closer` interface), but skips this if the "into" Object is of type
// BlobObjectType. Blob's don't exhaust the buffer completely (they instead
// maintain a handle on the blob's contents via an io.LimitedReader) and
// therefore cannot be closed until signaled explicitly by git/odb.Blob.Close().
func (o *ObjectDatabase) decode(sha []byte, into Object) error {
r, err := o.open(sha)
if err != nil {
@ -254,8 +260,10 @@ func (o *ObjectDatabase) decode(sha []byte, into Object) error {
return err
}
if into.Type() != BlobObjectType {
if err = r.Close(); err != nil {
return err
}
}
return nil
}