aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/object_pack.go
diff options
context:
space:
mode:
authorAntonio Navarro Perez <antnavper@gmail.com>2016-12-14 10:20:00 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-12-14 10:20:00 +0100
commit500b1e1e183c73e3087710fca2f96acfd2e2d5cb (patch)
treeb2777dedd22f7279f2df7da8eb3b433d560c5701 /plumbing/format/packfile/object_pack.go
parent40875ee0df345468f36cb00d54820d622b37cbc5 (diff)
downloadgo-git-500b1e1e183c73e3087710fca2f96acfd2e2d5cb.tar.gz
format/packfile: implement delta encoding (#172)
* format/packfile: implement delta encoding - Added all the logic to the encoder to be able to encode ref-delta and offset-delta objects - Created plumbing.ObjectToPack to handle deltas and standard objects when we are writting them into a packfile - Added specific encoder delta tests, one standard object and one delta, and one standard object and two deltas * Requested changes. * Requested changes
Diffstat (limited to 'plumbing/format/packfile/object_pack.go')
-rw-r--r--plumbing/format/packfile/object_pack.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/plumbing/format/packfile/object_pack.go b/plumbing/format/packfile/object_pack.go
new file mode 100644
index 0000000..dc5a3c7
--- /dev/null
+++ b/plumbing/format/packfile/object_pack.go
@@ -0,0 +1,47 @@
+package packfile
+
+import "gopkg.in/src-d/go-git.v4/plumbing"
+
+// ObjectToPack is a representation of an object that is going to be into a
+// pack file.
+type ObjectToPack struct {
+ // The main object to pack, it could be any object, including deltas
+ Object plumbing.Object
+ // Base is the object that a delta is based on (it could be also another delta).
+ // 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 Object in the case of a non-delta object.
+ Original plumbing.Object
+ // Depth is the amount of deltas needed to resolve to obtain Original
+ // (delta based on delta based on ...)
+ Depth int
+}
+
+// newObjectToPack creates a correct ObjectToPack based on a non-delta object
+func newObjectToPack(o plumbing.Object) *ObjectToPack {
+ return &ObjectToPack{
+ Object: o,
+ Original: o,
+ }
+}
+
+// newDeltaObjectToPack creates a correct ObjectToPack for a delta object, based on
+// his base (could be another delta), the delta target (in this case called original),
+// and the delta Object itself
+func newDeltaObjectToPack(base *ObjectToPack, original, delta plumbing.Object) *ObjectToPack {
+ return &ObjectToPack{
+ Object: delta,
+ Base: base,
+ Original: original,
+ Depth: base.Depth + 1,
+ }
+}
+
+func (o *ObjectToPack) IsDelta() bool {
+ if o.Base != nil {
+ return true
+ }
+
+ return false
+}