Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit d5f74d2

Browse files
committed
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 <[email protected]>
1 parent 522327b commit d5f74d2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

plumbing/format/packfile/encoder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ func (s *EncoderSuite) deltaOverDeltaCyclicTest(c *C) {
233233
// is nil.
234234
po1.SetOriginal(po1.Original)
235235
pd2.SetOriginal(pd2.Original)
236-
pd2.Original = nil
236+
pd2.SetOriginal(nil)
237237

238238
pd3.SetOriginal(pd3.Original)
239-
pd3.Original = nil
239+
pd3.SetOriginal(nil)
240240

241241
pd4.SetOriginal(pd4.Original)
242242

plumbing/format/packfile/object_pack.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func newDeltaObjectToPack(base *ObjectToPack, original, delta plumbing.EncodedOb
5353

5454
// BackToOriginal converts that ObjectToPack to a non-deltified object if it was one
5555
func (o *ObjectToPack) BackToOriginal() {
56-
if o.IsDelta() {
56+
if o.IsDelta() && o.Original != nil {
5757
o.Object = o.Original
5858
o.Base = nil
5959
o.Depth = 0
@@ -77,13 +77,17 @@ func (o *ObjectToPack) WantWrite() bool {
7777
return o.Offset == 1
7878
}
7979

80-
// SetOriginal sets both Original and saves size, type and hash
80+
// SetOriginal sets both Original and saves size, type and hash. If object
81+
// is nil Original is set but previous resolved values are kept
8182
func (o *ObjectToPack) SetOriginal(obj plumbing.EncodedObject) {
8283
o.Original = obj
83-
o.originalSize = obj.Size()
84-
o.originalType = obj.Type()
85-
o.originalHash = obj.Hash()
86-
o.resolvedOriginal = true
84+
85+
if obj != nil {
86+
o.originalSize = obj.Size()
87+
o.originalType = obj.Type()
88+
o.originalHash = obj.Hash()
89+
o.resolvedOriginal = true
90+
}
8791
}
8892

8993
func (o *ObjectToPack) Type() plumbing.ObjectType {

0 commit comments

Comments
 (0)