diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-01-26 00:04:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-26 00:04:08 +0100 |
commit | 5d5b95168c9ed9f3210ddca5ce220fe3dbbebc0c (patch) | |
tree | 2b6ab08a4daf74c03cb5ae333554ed34f771095a /plumbing/format/packfile/object_pack.go | |
parent | 8c24b1bf2ac5bdb1a1b624b9a80be17f0a4e685b (diff) | |
parent | d5f74d2d3cd63325c6d16f5e93f78d6462ec9308 (diff) | |
download | go-git-5d5b95168c9ed9f3210ddca5ce220fe3dbbebc0c.tar.gz |
Merge pull request #731 from jfontan/fix/crash-with-delta-cycles
plumbing: format/packfile, fix crash with cycle deltas
Diffstat (limited to 'plumbing/format/packfile/object_pack.go')
-rw-r--r-- | plumbing/format/packfile/object_pack.go | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/plumbing/format/packfile/object_pack.go b/plumbing/format/packfile/object_pack.go index 1563517..877581e 100644 --- a/plumbing/format/packfile/object_pack.go +++ b/plumbing/format/packfile/object_pack.go @@ -23,6 +23,12 @@ type ObjectToPack struct { // offset in pack when object has been already written, or 0 if it // has not been written yet Offset int64 + + // Information from the original object + resolvedOriginal bool + originalType plumbing.ObjectType + originalSize int64 + originalHash plumbing.Hash } // newObjectToPack creates a correct ObjectToPack based on a non-delta object @@ -47,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 @@ -71,11 +77,28 @@ func (o *ObjectToPack) WantWrite() bool { return o.Offset == 1 } +// 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 + + if obj != nil { + o.originalSize = obj.Size() + o.originalType = obj.Type() + o.originalHash = obj.Hash() + o.resolvedOriginal = true + } +} + func (o *ObjectToPack) Type() plumbing.ObjectType { if o.Original != nil { return o.Original.Type() } + if o.resolvedOriginal { + return o.originalType + } + if o.Base != nil { return o.Base.Type() } @@ -92,6 +115,10 @@ func (o *ObjectToPack) Hash() plumbing.Hash { return o.Original.Hash() } + if o.resolvedOriginal { + return o.originalHash + } + do, ok := o.Object.(plumbing.DeltaObject) if ok { return do.ActualHash() @@ -105,6 +132,10 @@ func (o *ObjectToPack) Size() int64 { return o.Original.Size() } + if o.resolvedOriginal { + return o.originalSize + } + do, ok := o.Object.(plumbing.DeltaObject) if ok { return do.ActualSize() |