aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/format/packfile/delta_selector.go5
-rw-r--r--plumbing/format/packfile/encoder_test.go4
-rw-r--r--plumbing/format/packfile/object_pack.go17
3 files changed, 18 insertions, 8 deletions
diff --git a/plumbing/format/packfile/delta_selector.go b/plumbing/format/packfile/delta_selector.go
index 1d9fb5f..6710085 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.SaveOriginalMetadata()
+ 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..dfea571 100644
--- a/plumbing/format/packfile/object_pack.go
+++ b/plumbing/format/packfile/object_pack.go
@@ -81,15 +81,24 @@ func (o *ObjectToPack) WantWrite() bool {
// is nil Original is set but previous resolved values are kept
func (o *ObjectToPack) SetOriginal(obj plumbing.EncodedObject) {
o.Original = obj
+ o.SaveOriginalMetadata()
+}
- if obj != nil {
- o.originalSize = obj.Size()
- o.originalType = obj.Type()
- o.originalHash = obj.Hash()
+// SaveOriginalMetadata saves size, type and hash of Original object
+func (o *ObjectToPack) SaveOriginalMetadata() {
+ if o.Original != nil {
+ o.originalSize = o.Original.Size()
+ o.originalType = o.Original.Type()
+ o.originalHash = o.Original.Hash()
o.resolvedOriginal = true
}
}
+// 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()