aboutsummaryrefslogtreecommitdiffstats
path: root/file.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-30 11:29:47 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-30 11:29:47 +0200
commit2c527d02ceac3879f82ab53645b6c7c03c0e5d71 (patch)
treeebdd08843d1f5c6df7dff366ad5de8b4b2977e8c /file.go
parentd47285fa6e39399f639d8a9c3209d7d9bfb63ce4 (diff)
downloadgo-git-2c527d02ceac3879f82ab53645b6c7c03c0e5d71.tar.gz
TreeWalker optimization
Diffstat (limited to 'file.go')
-rw-r--r--file.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/file.go b/file.go
index ef17c6e..e18caaf 100644
--- a/file.go
+++ b/file.go
@@ -53,23 +53,31 @@ func (f *File) Lines() ([]string, error) {
}
type FileIter struct {
+ r *Repository
w TreeWalker
}
func NewFileIter(r *Repository, t *Tree) *FileIter {
- return &FileIter{w: *NewTreeWalker(r, t)}
+ return &FileIter{r: r, w: *NewTreeWalker(r, t)}
}
func (iter *FileIter) Next() (*File, error) {
for {
- name, entry, obj, err := iter.w.Next()
+ name, entry, err := iter.w.Next()
if err != nil {
return nil, err
}
- if blob, ok := obj.(*Blob); ok {
- return newFile(name, entry.Mode, blob), nil
+ if entry.Mode.IsDir() {
+ continue
}
+
+ blob, err := iter.r.Blob(entry.Hash)
+ if err != nil {
+ return nil, err
+ }
+
+ return newFile(name, entry.Mode, blob), nil
}
}