aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/delta_selector.go
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2017-09-06 12:13:41 +0200
committerMiguel Molina <miguel@erizocosmi.co>2017-09-06 12:13:41 +0200
commit0b68b0fd8e8a0f57419a72479ddeb8d267f15f72 (patch)
treea6b49669163d3a0a1c85141513eeb52c3ee6561e /plumbing/format/packfile/delta_selector.go
parent2dc59a6925f47e9d1bc99dd64d86e37b79b65d11 (diff)
downloadgo-git-0b68b0fd8e8a0f57419a72479ddeb8d267f15f72.tar.gz
packfile: reuse delta indexes when possible
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Diffstat (limited to 'plumbing/format/packfile/delta_selector.go')
-rw-r--r--plumbing/format/packfile/delta_selector.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/plumbing/format/packfile/delta_selector.go b/plumbing/format/packfile/delta_selector.go
index cc0ae0f..78b5733 100644
--- a/plumbing/format/packfile/delta_selector.go
+++ b/plumbing/format/packfile/delta_selector.go
@@ -172,6 +172,7 @@ func (dw *deltaSelector) sort(objectsToPack []*ObjectToPack) {
}
func (dw *deltaSelector) walk(objectsToPack []*ObjectToPack) error {
+ indexMap := make(map[plumbing.Hash]deltaIndex)
for i := 0; i < len(objectsToPack); i++ {
target := objectsToPack[i]
@@ -196,7 +197,7 @@ func (dw *deltaSelector) walk(objectsToPack []*ObjectToPack) error {
break
}
- if err := dw.tryToDeltify(base, target); err != nil {
+ if err := dw.tryToDeltify(indexMap, base, target); err != nil {
return err
}
}
@@ -205,7 +206,7 @@ func (dw *deltaSelector) walk(objectsToPack []*ObjectToPack) error {
return nil
}
-func (dw *deltaSelector) tryToDeltify(base, target *ObjectToPack) error {
+func (dw *deltaSelector) tryToDeltify(indexMap map[plumbing.Hash]deltaIndex, base, target *ObjectToPack) error {
// If the sizes are radically different, this is a bad pairing.
if target.Size() < base.Size()>>4 {
return nil
@@ -238,8 +239,12 @@ func (dw *deltaSelector) tryToDeltify(base, target *ObjectToPack) error {
return err
}
+ if _, ok := indexMap[base.Hash()]; !ok {
+ indexMap[base.Hash()] = make(deltaIndex)
+ }
+
// Now we can generate the delta using originals
- delta, err := GetDelta(base.Original, target.Original)
+ delta, err := getDelta(indexMap[base.Hash()], base.Original, target.Original)
if err != nil {
return err
}