aboutsummaryrefslogtreecommitdiffstats
path: root/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'file.go')
-rw-r--r--file.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/file.go b/file.go
index b0b0141..9ef0e56 100644
--- a/file.go
+++ b/file.go
@@ -33,3 +33,34 @@ func (f *File) Lines() []string {
}
return splits
}
+
+type FileIter struct {
+ w TreeWalker
+}
+
+func NewFileIter(r *Repository, t *Tree) *FileIter {
+ return &FileIter{w: *NewTreeWalker(r, t)}
+}
+
+func (iter *FileIter) Next() (*File, error) {
+ for {
+ name, entry, obj, err := iter.w.Next()
+ if err != nil {
+ return nil, err
+ }
+
+ if obj.Type() != core.BlobObject {
+ // Skip non-blob objects
+ continue
+ }
+
+ blob := &Blob{}
+ blob.Decode(obj)
+
+ return &File{Name: name, Reader: blob.Reader(), Hash: entry.Hash}, nil
+ }
+}
+
+func (iter *FileIter) Close() {
+ iter.w.Close()
+}