diff options
Diffstat (limited to 'plumbing/format/packfile/object_pack.go')
-rw-r--r-- | plumbing/format/packfile/object_pack.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/plumbing/format/packfile/object_pack.go b/plumbing/format/packfile/object_pack.go index 1563517..284871f 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 @@ -71,11 +77,24 @@ func (o *ObjectToPack) WantWrite() bool { return o.Offset == 1 } +// SetOriginal sets both Original and saves size, type and hash +func (o *ObjectToPack) SetOriginal(obj plumbing.EncodedObject) { + o.Original = obj + 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 +111,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 +128,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() |