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

Commit d2273d2

Browse files
committed
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 <[email protected]>
1 parent 3a9d5e2 commit d2273d2

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

plumbing/format/packfile/delta_selector.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (dw *deltaSelector) objectsToPack(
103103

104104
otp := newObjectToPack(o)
105105
if _, ok := o.(plumbing.DeltaObject); ok {
106-
otp.Original = nil
106+
otp.CleanOriginal()
107107
}
108108

109109
objectsToPack = append(objectsToPack, otp)
@@ -231,7 +231,8 @@ func (dw *deltaSelector) walk(
231231
delete(indexMap, obj.Hash())
232232

233233
if obj.IsDelta() {
234-
obj.Original = nil
234+
obj.SetOriginal(obj.Original)
235+
obj.CleanOriginal()
235236
}
236237
}
237238

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.SetOriginal(nil)
236+
pd2.CleanOriginal()
237237

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

241241
pd4.SetOriginal(pd4.Original)
242242

plumbing/format/packfile/object_pack.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ func (o *ObjectToPack) SetOriginal(obj plumbing.EncodedObject) {
9090
}
9191
}
9292

93+
// CleanOriginal sets Original to nil
94+
func (o *ObjectToPack) CleanOriginal() {
95+
o.Original = nil
96+
}
97+
9398
func (o *ObjectToPack) Type() plumbing.ObjectType {
9499
if o.Original != nil {
95100
return o.Original.Type()

0 commit comments

Comments
 (0)