diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-25 23:58:59 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-25 23:58:59 +0200 |
commit | b9c0a09435392913c0054382500c805cd7cb596b (patch) | |
tree | d5a4bebff33b02215b25515ab769f277c0c07bb9 /storage/filesystem/object.go | |
parent | 859775d320d574979c63a114de1437e3c5d9114c (diff) | |
download | go-git-b9c0a09435392913c0054382500c805cd7cb596b.tar.gz |
formats: objfile idomatic reader/writer
Diffstat (limited to 'storage/filesystem/object.go')
-rw-r--r-- | storage/filesystem/object.go | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index 03939ce..f2f5351 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -118,31 +118,30 @@ func (s *ObjectStorage) getFromUnpacked(h core.Hash) (obj core.Object, err error return nil, err } - defer func() { - errClose := f.Close() - if err == nil { - err = errClose - } - }() + defer f.Close() obj = s.NewObject() - objReader, err := objfile.NewReader(f) + r, err := objfile.NewReader(f) if err != nil { return nil, err } - defer func() { - errClose := objReader.Close() - if err == nil { - err = errClose - } - }() + defer r.Close() - if err := objReader.FillObject(obj); err != nil { + t, size, err := r.Header() + if err != nil { return nil, err } - return obj, nil + obj.SetType(t) + obj.SetSize(size) + w, err := obj.Writer() + if err != nil { + return nil, err + } + + _, err = io.Copy(w, r) + return obj, err } // Get returns the object with the given hash, by searching for it in @@ -278,11 +277,7 @@ type packfileIter struct { total uint32 } -func newPackfileIter( - f fs.File, - t core.ObjectType, - seen map[core.Hash]bool, -) (core.ObjectIter, error) { +func newPackfileIter(f fs.File, t core.ObjectType, seen map[core.Hash]bool) (core.ObjectIter, error) { s := packfile.NewScanner(f) _, total, err := s.Header() if err != nil { @@ -294,7 +289,14 @@ func newPackfileIter( return nil, err } - return &packfileIter{f: f, d: d, t: t, total: total, seen: seen}, nil + return &packfileIter{ + f: f, + d: d, + t: t, + + total: total, + seen: seen, + }, nil } func (iter *packfileIter) Next() (core.Object, error) { |