aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/diff_delta.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/diff_delta.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/diff_delta.go')
-rw-r--r--plumbing/format/packfile/diff_delta.go40
1 files changed, 33 insertions, 7 deletions
diff --git a/plumbing/format/packfile/diff_delta.go b/plumbing/format/packfile/diff_delta.go
index eaed377..7a32d5d 100644
--- a/plumbing/format/packfile/diff_delta.go
+++ b/plumbing/format/packfile/diff_delta.go
@@ -1,6 +1,7 @@
package packfile
import (
+ "fmt"
"io/ioutil"
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -14,28 +15,53 @@ const (
maxCopyLen = 0xffff
)
-// GetDelta returns the way of how to transform base object to target object
-func GetDelta(base, target plumbing.Object) ([]byte, error) {
- baseReader, err := base.Reader()
+// GetOFSDelta returns an offset delta that knows the way of how to transform
+// base object to target object
+func GetOFSDelta(base, target plumbing.Object) (plumbing.Object, error) {
+ return getDelta(base, target, plumbing.OFSDeltaObject)
+}
+
+// GetRefDelta returns a reference delta that knows the way of how to transform
+// base object to target object
+func GetRefDelta(base, target plumbing.Object) (plumbing.Object, error) {
+ return getDelta(base, target, plumbing.REFDeltaObject)
+}
+
+func getDelta(base, target plumbing.Object, t plumbing.ObjectType) (plumbing.Object, error) {
+ if t != plumbing.OFSDeltaObject && t != plumbing.REFDeltaObject {
+ return nil, fmt.Errorf("Type not supported: %v", t)
+ }
+
+ br, err := base.Reader()
if err != nil {
return nil, err
}
- targetReader, err := target.Reader()
+ tr, err := target.Reader()
if err != nil {
return nil, err
}
- baseBuf, err := ioutil.ReadAll(baseReader)
+ bb, err := ioutil.ReadAll(br)
if err != nil {
return nil, err
}
- targetBuf, err := ioutil.ReadAll(targetReader)
+ tb, err := ioutil.ReadAll(tr)
if err != nil {
return nil, err
}
- return DiffDelta(baseBuf, targetBuf), nil
+ db := DiffDelta(bb, tb)
+ delta := &plumbing.MemoryObject{}
+ _, err = delta.Write(db)
+ if err != nil {
+ return nil, err
+ }
+
+ delta.SetSize(int64(len(db)))
+ delta.SetType(t)
+
+ return delta, nil
}
// DiffDelta returns the way of how to transform baseBuf to targetBuf