diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-30 11:29:47 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-30 11:29:47 +0200 |
commit | 2c527d02ceac3879f82ab53645b6c7c03c0e5d71 (patch) | |
tree | ebdd08843d1f5c6df7dff366ad5de8b4b2977e8c /file.go | |
parent | d47285fa6e39399f639d8a9c3209d7d9bfb63ce4 (diff) | |
download | go-git-2c527d02ceac3879f82ab53645b6c7c03c0e5d71.tar.gz |
TreeWalker optimization
Diffstat (limited to 'file.go')
-rw-r--r-- | file.go | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -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 } } |