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 /tree.go | |
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 'tree.go')
-rw-r--r-- | tree.go | 45 |
1 files changed, 28 insertions, 17 deletions
@@ -39,9 +39,12 @@ func (t *Tree) File(path string) (*File, error) { return nil, ErrFileNotFound } - obj, ok := t.r.Storage.Get(*hash) - if !ok { - return nil, ErrFileNotFound // a git submodule + obj, err := t.r.Storage.Get(*hash) + if err != nil { + if err == core.ObjectNotFoundErr { + return nil, ErrFileNotFound // a git submodule + } + return nil, err } if obj.Type() != core.BlobObject { @@ -81,9 +84,12 @@ func (t *Tree) dir(baseName string) (*Tree, error) { return nil, errDirNotFound } - obj, ok := t.r.Storage.Get(entry.Hash) - if !ok { // git submodule - return nil, errDirNotFound + obj, err := t.r.Storage.Get(entry.Hash) + if err != nil { + if err == core.ObjectNotFoundErr { // git submodule + return nil, errDirNotFound + } + return nil, err } if obj.Type() != core.TreeObject { @@ -120,9 +126,13 @@ func (t *Tree) Files() chan *File { func (t *Tree) walkEntries(base string, ch chan *File) { for _, entry := range t.Entries { - obj, ok := t.r.Storage.Get(entry.Hash) - if !ok { - continue // ignore entries without hash (= submodule dirs) + obj, err := t.r.Storage.Get(entry.Hash) + if err != nil { + if err == core.ObjectNotFoundErr { + continue // ignore entries without hash (= submodule dirs) + } + //FIXME: Refactor this function to return an error. Ideally this would be + // moved into a FileIter type. } if obj.Type() == core.TreeObject { @@ -187,19 +197,20 @@ func (t *Tree) Decode(o core.Object) error { } type TreeIter struct { - iter + core.ObjectIter + r *Repository } -func NewTreeIter(r *Repository) *TreeIter { - return &TreeIter{newIter(r)} +func NewTreeIter(r *Repository, iter core.ObjectIter) *TreeIter { + return &TreeIter{iter, r} } -func (i *TreeIter) Next() (*Tree, error) { - obj := <-i.ch - if obj == nil { - return nil, io.EOF +func (iter *TreeIter) Next() (*Tree, error) { + obj, err := iter.ObjectIter.Next() + if err != nil { + return nil, err } - tree := &Tree{r: i.r} + tree := &Tree{r: iter.r} return tree, tree.Decode(obj) } |