diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-02-16 17:58:07 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-02-16 17:58:07 +0100 |
commit | a9896315a1b37b66865a0eb7e94e768ef45ff3db (patch) | |
tree | 8c4012969e4a5f430d385aa908f369fa843e815e /formats | |
parent | 1931dfbf38508e790e9f129873bc073aacc6a50f (diff) | |
parent | e82d4918b403a641a5295b3f199586b0ab26b15c (diff) | |
download | go-git-a9896315a1b37b66865a0eb7e94e768ef45ff3db.tar.gz |
Merge pull request #20 from scjalliance/generic-object-storage
Iterable ObjectStorage interface for use in Repository struct
Diffstat (limited to 'formats')
-rw-r--r-- | formats/packfile/reader.go | 17 | ||||
-rw-r--r-- | formats/packfile/reader_test.go | 4 |
2 files changed, 13 insertions, 8 deletions
diff --git a/formats/packfile/reader.go b/formats/packfile/reader.go index 959e411..91aef21 100644 --- a/formats/packfile/reader.go +++ b/formats/packfile/reader.go @@ -144,7 +144,10 @@ func (r *Reader) readObjects(count uint32) error { } func (r *Reader) newRAWObject() (core.Object, error) { - raw := r.s.New() + raw, err := r.s.New() + if err != nil { + return nil, err + } var steps int64 var buf [1]byte @@ -170,7 +173,6 @@ func (r *Reader) newRAWObject() (core.Object, error) { raw.SetType(typ) raw.SetSize(size) - var err error switch raw.Type() { case core.REFDeltaObject: err = r.readREFDelta(raw) @@ -196,9 +198,12 @@ func (r *Reader) readREFDelta(raw core.Object) error { return err } - referenced, ok := r.s.Get(ref) - if !ok { - return ObjectNotFoundErr.n("%s", ref) + referenced, err := r.s.Get(ref) + if err != nil { + if err == core.ObjectNotFoundErr { + return ObjectNotFoundErr.n("%s", ref) + } + return err } d, _ := ioutil.ReadAll(referenced.Reader()) @@ -231,7 +236,7 @@ func (r *Reader) readOFSDelta(raw core.Object, steps int64) error { return PackEntryNotFoundErr.n("offset %d", start+offset) } - referenced, _ := r.s.Get(ref) + referenced, _ := r.s.Get(ref) // FIXME: Handle error returned from Get() d, _ := ioutil.ReadAll(referenced.Reader()) patched := patchDelta(d, buf.Bytes()) if patched == nil { diff --git a/formats/packfile/reader_test.go b/formats/packfile/reader_test.go index 8561a59..f460614 100644 --- a/formats/packfile/reader_test.go +++ b/formats/packfile/reader_test.go @@ -102,8 +102,8 @@ func (s *ReaderSuite) testReadPackfileGitFixture(c *C, file string, f Format) { func AssertObjects(c *C, s *core.RAWObjectStorage, expects []string) { c.Assert(len(expects), Equals, len(s.Objects)) for _, expected := range expects { - obtained, ok := s.Get(core.NewHash(expected)) - c.Assert(ok, Equals, true) + obtained, err := s.Get(core.NewHash(expected)) + c.Assert(err, IsNil) c.Assert(obtained.Hash().String(), Equals, expected) } } |