diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-11 18:07:29 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-11 18:07:29 +0200 |
commit | 1f64d789038594098ea2c9cf796391f101d0bea5 (patch) | |
tree | 50fb530fc2e48560e70489dc81758f54822dcf50 /formats/packfile/delta.go | |
parent | c1e277a7ca75ff84741d75ad45e29a2ff3e633e3 (diff) | |
download | go-git-1f64d789038594098ea2c9cf796391f101d0bea5.tar.gz |
core: new MemoryObject, move from memory.Object, packfile.Parser, base on new ObjectStorage interface
Diffstat (limited to 'formats/packfile/delta.go')
-rw-r--r-- | formats/packfile/delta.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/formats/packfile/delta.go b/formats/packfile/delta.go index e0bbb65..95c13d5 100644 --- a/formats/packfile/delta.go +++ b/formats/packfile/delta.go @@ -1,5 +1,7 @@ package packfile +import "gopkg.in/src-d/go-git.v4/core" + // See https://github.com/git/git/blob/49fa3dc76179e04b0833542fa52d0f287a4955ac/delta.h // https://github.com/git/git/blob/c2c5f6b1e479f2c38e0e01345350620944e3527f/patch-delta.c, // and https://github.com/tarruda/node-git-core/blob/master/src/js/delta.js @@ -7,6 +9,24 @@ package packfile const deltaSizeMin = 4 +// ApplyDelta writes to taget the result of applying the modification deltas in delta to base. +func ApplyDelta(target, base core.Object, delta []byte) error { + src := base.Content() + w, err := target.Writer() + if err != nil { + return err + } + + dst := PatchDelta(src, delta) + target.SetSize(int64(len(dst))) + + if _, err := w.Write(dst); err != nil { + return err + } + + return nil +} + // PatchDelta returns the result of applying the modification deltas in delta to src. func PatchDelta(src, delta []byte) []byte { if len(delta) < deltaSizeMin { |