From d5f74d2d3cd63325c6d16f5e93f78d6462ec9308 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 25 Jan 2018 10:29:46 +0100 Subject: plumbing: format/packfile, check nil objects in ObjectToPack SetOriginal now skips setting resolved values if the provided object is nil. BackToOriginal also skips nil Original objects. Signed-off-by: Javi Fontan --- plumbing/format/packfile/encoder_test.go | 4 ++-- plumbing/format/packfile/object_pack.go | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'plumbing/format') diff --git a/plumbing/format/packfile/encoder_test.go b/plumbing/format/packfile/encoder_test.go index 06cb1c6..63dfafa 100644 --- a/plumbing/format/packfile/encoder_test.go +++ b/plumbing/format/packfile/encoder_test.go @@ -233,10 +233,10 @@ func (s *EncoderSuite) deltaOverDeltaCyclicTest(c *C) { // is nil. po1.SetOriginal(po1.Original) pd2.SetOriginal(pd2.Original) - pd2.Original = nil + pd2.SetOriginal(nil) pd3.SetOriginal(pd3.Original) - pd3.Original = nil + pd3.SetOriginal(nil) pd4.SetOriginal(pd4.Original) diff --git a/plumbing/format/packfile/object_pack.go b/plumbing/format/packfile/object_pack.go index 284871f..877581e 100644 --- a/plumbing/format/packfile/object_pack.go +++ b/plumbing/format/packfile/object_pack.go @@ -53,7 +53,7 @@ func newDeltaObjectToPack(base *ObjectToPack, original, delta plumbing.EncodedOb // BackToOriginal converts that ObjectToPack to a non-deltified object if it was one func (o *ObjectToPack) BackToOriginal() { - if o.IsDelta() { + if o.IsDelta() && o.Original != nil { o.Object = o.Original o.Base = nil o.Depth = 0 @@ -77,13 +77,17 @@ func (o *ObjectToPack) WantWrite() bool { return o.Offset == 1 } -// SetOriginal sets both Original and saves size, type and hash +// SetOriginal sets both Original and saves size, type and hash. If object +// is nil Original is set but previous resolved values are kept func (o *ObjectToPack) SetOriginal(obj plumbing.EncodedObject) { o.Original = obj - o.originalSize = obj.Size() - o.originalType = obj.Type() - o.originalHash = obj.Hash() - o.resolvedOriginal = true + + if obj != nil { + o.originalSize = obj.Size() + o.originalType = obj.Type() + o.originalHash = obj.Hash() + o.resolvedOriginal = true + } } func (o *ObjectToPack) Type() plumbing.ObjectType { -- cgit