From d2273d2510d16c258d46ee72b87fd28b8850f1f2 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 9 Feb 2018 11:39:18 +0100 Subject: plumbing: format/packfile, fix panic retrieving object hash. In some cases the original data is not saved before it is cleaned and forces a panic when it's needed. The change adds ObjectToPack.CleanOriginal to be used to clean original object instead of: object.Original = nil Now when the Original data is freed because it's no longer in the pack window a SetOriginal call is done to make sure that Size, Hash and Size data is not lost. Signed-off-by: Javi Fontan --- plumbing/format/packfile/delta_selector.go | 5 +++-- plumbing/format/packfile/encoder_test.go | 4 ++-- plumbing/format/packfile/object_pack.go | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'plumbing/format') diff --git a/plumbing/format/packfile/delta_selector.go b/plumbing/format/packfile/delta_selector.go index 1d9fb5f..98a91b9 100644 --- a/plumbing/format/packfile/delta_selector.go +++ b/plumbing/format/packfile/delta_selector.go @@ -103,7 +103,7 @@ func (dw *deltaSelector) objectsToPack( otp := newObjectToPack(o) if _, ok := o.(plumbing.DeltaObject); ok { - otp.Original = nil + otp.CleanOriginal() } objectsToPack = append(objectsToPack, otp) @@ -231,7 +231,8 @@ func (dw *deltaSelector) walk( delete(indexMap, obj.Hash()) if obj.IsDelta() { - obj.Original = nil + obj.SetOriginal(obj.Original) + obj.CleanOriginal() } } diff --git a/plumbing/format/packfile/encoder_test.go b/plumbing/format/packfile/encoder_test.go index 63dfafa..84d03fb 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.SetOriginal(nil) + pd2.CleanOriginal() pd3.SetOriginal(pd3.Original) - pd3.SetOriginal(nil) + pd3.CleanOriginal() pd4.SetOriginal(pd4.Original) diff --git a/plumbing/format/packfile/object_pack.go b/plumbing/format/packfile/object_pack.go index 877581e..661278d 100644 --- a/plumbing/format/packfile/object_pack.go +++ b/plumbing/format/packfile/object_pack.go @@ -90,6 +90,11 @@ func (o *ObjectToPack) SetOriginal(obj plumbing.EncodedObject) { } } +// CleanOriginal sets Original to nil +func (o *ObjectToPack) CleanOriginal() { + o.Original = nil +} + func (o *ObjectToPack) Type() plumbing.ObjectType { if o.Original != nil { return o.Original.Type() -- cgit