Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit c97c955

Browse files
committed
core: removing Object.Content, the Reader should be used always
1 parent 7424562 commit c97c955

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

core/memory.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ func (o *MemoryObject) Size() int64 { return o.sz }
3838
// afterwards
3939
func (o *MemoryObject) SetSize(s int64) { o.sz = s }
4040

41-
// Content returns the contents of the object
42-
func (o *MemoryObject) Content() []byte { return o.cont }
43-
4441
// Reader returns a ObjectReader used to read the object's content.
4542
func (o *MemoryObject) Reader() (ObjectReader, error) {
4643
return ioutil.NopCloser(bytes.NewBuffer(o.cont)), nil

core/object.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type Object interface {
3434
SetType(ObjectType)
3535
Size() int64
3636
SetSize(int64)
37-
Content() []byte
3837
Reader() (ObjectReader, error)
3938
Writer() (ObjectWriter, error)
4039
}

formats/packfile/delta.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package packfile
22

3-
import "gopkg.in/src-d/go-git.v4/core"
3+
import (
4+
"io/ioutil"
5+
6+
"gopkg.in/src-d/go-git.v4/core"
7+
)
48

59
// See https://github.com/git/git/blob/49fa3dc76179e04b0833542fa52d0f287a4955ac/delta.h
610
// https://github.com/git/git/blob/c2c5f6b1e479f2c38e0e01345350620944e3527f/patch-delta.c,
@@ -11,12 +15,21 @@ const deltaSizeMin = 4
1115

1216
// ApplyDelta writes to taget the result of applying the modification deltas in delta to base.
1317
func ApplyDelta(target, base core.Object, delta []byte) error {
14-
src := base.Content()
18+
r, err := base.Reader()
19+
if err != nil {
20+
return err
21+
}
22+
1523
w, err := target.Writer()
1624
if err != nil {
1725
return err
1826
}
1927

28+
src, err := ioutil.ReadAll(r)
29+
if err != nil {
30+
return err
31+
}
32+
2033
dst := PatchDelta(src, delta)
2134
target.SetSize(int64(len(dst)))
2235

formats/packfile/parser_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ func (s *ParserSuite) TestReadNonDeltaObjectContent(c *C) {
240240
obj := &core.MemoryObject{}
241241
err = p.FillFromNonDeltaContent(obj)
242242
c.Assert(err, IsNil, com)
243-
c.Assert(obj.Content(), DeepEquals, test.expected, com)
243+
244+
r, _ := obj.Reader()
245+
bytes, _ := ioutil.ReadAll(r)
246+
c.Assert(bytes, DeepEquals, test.expected, com)
244247
}
245248
}
246249

@@ -297,7 +300,10 @@ func (s *ParserSuite) TestFillOFSDeltaObjectContent(c *C) {
297300
err = p.FillOFSDeltaObjectContent(obj, test.offset)
298301
c.Assert(err, IsNil, com)
299302
c.Assert(obj.Type(), Equals, test.expType, com)
300-
c.Assert(obj.Content(), DeepEquals, test.expContent, com)
303+
304+
r, _ := obj.Reader()
305+
bytes, _ := ioutil.ReadAll(r)
306+
c.Assert(bytes, DeepEquals, test.expContent, com)
301307
}
302308
}
303309

@@ -361,7 +367,10 @@ func (s *ParserSuite) TestFillREFDeltaObjectContent(c *C) {
361367
err = p.FillREFDeltaObjectContent(obj)
362368
c.Assert(err, IsNil, com)
363369
c.Assert(obj.Type(), Equals, test.expType, com)
364-
c.Assert(obj.Content(), DeepEquals, test.expContent, com)
370+
371+
r, _ := obj.Reader()
372+
bytes, _ := ioutil.ReadAll(r)
373+
c.Assert(bytes, DeepEquals, test.expContent, com)
365374

366375
p.ForgetAll()
367376
}

storage/filesystem/object_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package filesystem
22

33
import (
44
"fmt"
5+
"io/ioutil"
56
"os"
67
"reflect"
78
"sort"
@@ -195,9 +196,12 @@ func equalsObjects(a, b core.Object) (bool, string, error) {
195196
asz, bsz), nil
196197
}
197198

198-
ac := a.Content()
199+
r, _ := b.Reader()
200+
ac, _ := ioutil.ReadAll(r)
199201
if ac != nil {
200-
bc := b.Content()
202+
r, _ := b.Reader()
203+
bc, _ := ioutil.ReadAll(r)
204+
201205
if !reflect.DeepEqual(ac, bc) {
202206
return false, fmt.Sprintf("object contents differ"), nil
203207
}

0 commit comments

Comments
 (0)