aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/object_pack.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-12-18 18:11:38 +0100
committerAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-12-20 12:06:36 +0100
commitc932bd462fed2ff470d9ff40f15102237a3287f8 (patch)
tree49aecd1f4d1f356f5f482f5d9eaa801c3907ef37 /plumbing/format/packfile/object_pack.go
parentfbe632ef8d41c17caa76b6ed3f1d404e1f047299 (diff)
downloadgo-git-c932bd462fed2ff470d9ff40f15102237a3287f8.tar.gz
Improve delta reutilization
- Remove wrong 'if' on delta selector that causes poor delta reutilizations - packfile.Encoder now can write deltas and objects in a non specific order - ObjectToPack now saves the Offset on the packfile to be able to obtain base offset in a recursive manner and write them before the delta itself - Added encoder test to check cyclic delta chains - Check the output packfile hash in all encoder tests Signed-off-by: Antonio Jesus Navarro Perez <antnavper@gmail.com>
Diffstat (limited to 'plumbing/format/packfile/object_pack.go')
-rw-r--r--plumbing/format/packfile/object_pack.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/plumbing/format/packfile/object_pack.go b/plumbing/format/packfile/object_pack.go
index e22e783..1563517 100644
--- a/plumbing/format/packfile/object_pack.go
+++ b/plumbing/format/packfile/object_pack.go
@@ -13,12 +13,16 @@ type ObjectToPack struct {
// If the main object is not a delta, Base will be null
Base *ObjectToPack
// Original is the object that we can generate applying the delta to
- // Base, or the same object as EncodedObject in the case of a non-delta
+ // Base, or the same object as Object in the case of a non-delta
// object.
Original plumbing.EncodedObject
// Depth is the amount of deltas needed to resolve to obtain Original
// (delta based on delta based on ...)
Depth int
+
+ // offset in pack when object has been already written, or 0 if it
+ // has not been written yet
+ Offset int64
}
// newObjectToPack creates a correct ObjectToPack based on a non-delta object
@@ -41,6 +45,32 @@ 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() {
+ o.Object = o.Original
+ o.Base = nil
+ o.Depth = 0
+ }
+}
+
+// IsWritten returns if that ObjectToPack was
+// already written into the packfile or not
+func (o *ObjectToPack) IsWritten() bool {
+ return o.Offset > 1
+}
+
+// MarkWantWrite marks this ObjectToPack as WantWrite
+// to avoid delta chain loops
+func (o *ObjectToPack) MarkWantWrite() {
+ o.Offset = 1
+}
+
+// WantWrite checks if this ObjectToPack was marked as WantWrite before
+func (o *ObjectToPack) WantWrite() bool {
+ return o.Offset == 1
+}
+
func (o *ObjectToPack) Type() plumbing.ObjectType {
if o.Original != nil {
return o.Original.Type()