aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/memory.go3
-rw-r--r--core/object.go1
-rw-r--r--formats/packfile/delta.go17
-rw-r--r--formats/packfile/parser_test.go15
-rw-r--r--storage/filesystem/object_test.go8
5 files changed, 33 insertions, 11 deletions
diff --git a/core/memory.go b/core/memory.go
index e3063d6..3d8063d 100644
--- a/core/memory.go
+++ b/core/memory.go
@@ -38,9 +38,6 @@ func (o *MemoryObject) Size() int64 { return o.sz }
// afterwards
func (o *MemoryObject) SetSize(s int64) { o.sz = s }
-// Content returns the contents of the object
-func (o *MemoryObject) Content() []byte { return o.cont }
-
// Reader returns a ObjectReader used to read the object's content.
func (o *MemoryObject) Reader() (ObjectReader, error) {
return ioutil.NopCloser(bytes.NewBuffer(o.cont)), nil
diff --git a/core/object.go b/core/object.go
index d73ab0f..36b669e 100644
--- a/core/object.go
+++ b/core/object.go
@@ -34,7 +34,6 @@ type Object interface {
SetType(ObjectType)
Size() int64
SetSize(int64)
- Content() []byte
Reader() (ObjectReader, error)
Writer() (ObjectWriter, error)
}
diff --git a/formats/packfile/delta.go b/formats/packfile/delta.go
index 95c13d5..d08f969 100644
--- a/formats/packfile/delta.go
+++ b/formats/packfile/delta.go
@@ -1,6 +1,10 @@
package packfile
-import "gopkg.in/src-d/go-git.v4/core"
+import (
+ "io/ioutil"
+
+ "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,
@@ -11,12 +15,21 @@ 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()
+ r, err := base.Reader()
+ if err != nil {
+ return err
+ }
+
w, err := target.Writer()
if err != nil {
return err
}
+ src, err := ioutil.ReadAll(r)
+ if err != nil {
+ return err
+ }
+
dst := PatchDelta(src, delta)
target.SetSize(int64(len(dst)))
diff --git a/formats/packfile/parser_test.go b/formats/packfile/parser_test.go
index 5d41d69..f4aff83 100644
--- a/formats/packfile/parser_test.go
+++ b/formats/packfile/parser_test.go
@@ -240,7 +240,10 @@ func (s *ParserSuite) TestReadNonDeltaObjectContent(c *C) {
obj := &core.MemoryObject{}
err = p.FillFromNonDeltaContent(obj)
c.Assert(err, IsNil, com)
- c.Assert(obj.Content(), DeepEquals, test.expected, com)
+
+ r, _ := obj.Reader()
+ bytes, _ := ioutil.ReadAll(r)
+ c.Assert(bytes, DeepEquals, test.expected, com)
}
}
@@ -297,7 +300,10 @@ func (s *ParserSuite) TestFillOFSDeltaObjectContent(c *C) {
err = p.FillOFSDeltaObjectContent(obj, test.offset)
c.Assert(err, IsNil, com)
c.Assert(obj.Type(), Equals, test.expType, com)
- c.Assert(obj.Content(), DeepEquals, test.expContent, com)
+
+ r, _ := obj.Reader()
+ bytes, _ := ioutil.ReadAll(r)
+ c.Assert(bytes, DeepEquals, test.expContent, com)
}
}
@@ -361,7 +367,10 @@ func (s *ParserSuite) TestFillREFDeltaObjectContent(c *C) {
err = p.FillREFDeltaObjectContent(obj)
c.Assert(err, IsNil, com)
c.Assert(obj.Type(), Equals, test.expType, com)
- c.Assert(obj.Content(), DeepEquals, test.expContent, com)
+
+ r, _ := obj.Reader()
+ bytes, _ := ioutil.ReadAll(r)
+ c.Assert(bytes, DeepEquals, test.expContent, com)
p.ForgetAll()
}
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go
index a784525..5c4c7c8 100644
--- a/storage/filesystem/object_test.go
+++ b/storage/filesystem/object_test.go
@@ -2,6 +2,7 @@ package filesystem
import (
"fmt"
+ "io/ioutil"
"os"
"reflect"
"sort"
@@ -195,9 +196,12 @@ func equalsObjects(a, b core.Object) (bool, string, error) {
asz, bsz), nil
}
- ac := a.Content()
+ r, _ := b.Reader()
+ ac, _ := ioutil.ReadAll(r)
if ac != nil {
- bc := b.Content()
+ r, _ := b.Reader()
+ bc, _ := ioutil.ReadAll(r)
+
if !reflect.DeepEqual(ac, bc) {
return false, fmt.Sprintf("object contents differ"), nil
}