aboutsummaryrefslogtreecommitdiffstats
path: root/tree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-02-16 17:58:07 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-02-16 17:58:07 +0100
commita9896315a1b37b66865a0eb7e94e768ef45ff3db (patch)
tree8c4012969e4a5f430d385aa908f369fa843e815e /tree.go
parent1931dfbf38508e790e9f129873bc073aacc6a50f (diff)
parente82d4918b403a641a5295b3f199586b0ab26b15c (diff)
downloadgo-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.go45
1 files changed, 28 insertions, 17 deletions
diff --git a/tree.go b/tree.go
index e88b1e6..339fb7f 100644
--- a/tree.go
+++ b/tree.go
@@ -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)
}