aboutsummaryrefslogtreecommitdiffstats
path: root/file.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-02-22 19:05:49 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-02-22 19:05:49 +0100
commit07ca1ac7f3058ea6d3274a01973541fb84782f5e (patch)
tree8a459b8f2d00d1794103f2bf6febf46aa7f3b853 /file.go
parent9c319b2c4d6bb5cff43d237583b463619e95dc93 (diff)
downloadgo-git-07ca1ac7f3058ea6d3274a01973541fb84782f5e.tar.gz
File, added size and reader is now a methodv3.0.0
Diffstat (limited to 'file.go')
-rw-r--r--file.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/file.go b/file.go
index 9ef0e56..72a7145 100644
--- a/file.go
+++ b/file.go
@@ -2,7 +2,6 @@ package git
import (
"bytes"
- "io"
"strings"
"gopkg.in/src-d/go-git.v3/core"
@@ -11,14 +10,18 @@ import (
// File represents git file objects.
type File struct {
Name string
- io.Reader
- Hash core.Hash
+ Blob
+}
+
+func newFile(name string, b *Blob) *File {
+ return &File{Name: name, Blob: *b}
}
// Contents returns the contents of a file as a string.
func (f *File) Contents() string {
buf := new(bytes.Buffer)
- buf.ReadFrom(f)
+ buf.ReadFrom(f.Reader())
+
return buf.String()
}
@@ -31,6 +34,7 @@ func (f *File) Lines() []string {
if splits[len(splits)-1] == "" {
return splits[:len(splits)-1]
}
+
return splits
}
@@ -44,7 +48,7 @@ func NewFileIter(r *Repository, t *Tree) *FileIter {
func (iter *FileIter) Next() (*File, error) {
for {
- name, entry, obj, err := iter.w.Next()
+ name, _, obj, err := iter.w.Next()
if err != nil {
return nil, err
}
@@ -57,7 +61,7 @@ func (iter *FileIter) Next() (*File, error) {
blob := &Blob{}
blob.Decode(obj)
- return &File{Name: name, Reader: blob.Reader(), Hash: entry.Hash}, nil
+ return newFile(name, blob), nil
}
}