aboutsummaryrefslogtreecommitdiffstats
path: root/tree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-04-22 11:35:12 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-04-22 11:35:12 +0200
commitb08327bfaf27171dddc5516c63e5646c40f0b004 (patch)
treed974021a3d804b055a807363f3ba71d9b6d54825 /tree.go
parentb35fc295b4ac531adc72fc83f2af628c7c163c0e (diff)
downloadgo-git-b08327bfaf27171dddc5516c63e5646c40f0b004.tar.gz
file, added field Modev3.0.1
Diffstat (limited to 'tree.go')
-rw-r--r--tree.go15
1 files changed, 5 insertions, 10 deletions
diff --git a/tree.go b/tree.go
index 246bf8c..50f86e9 100644
--- a/tree.go
+++ b/tree.go
@@ -41,12 +41,12 @@ type TreeEntry struct {
// File returns the hash of the file identified by the `path` argument.
// The path is interpreted as relative to the tree receiver.
func (t *Tree) File(path string) (*File, error) {
- hash, err := t.findHash(path)
+ e, err := t.findEntry(path)
if err != nil {
return nil, ErrFileNotFound
}
- obj, err := t.r.Storage.Get(*hash)
+ obj, err := t.r.Storage.Get(e.Hash)
if err != nil {
if err == core.ObjectNotFoundErr {
return nil, ErrFileNotFound // a git submodule
@@ -61,10 +61,10 @@ func (t *Tree) File(path string) (*File, error) {
blob := &Blob{}
blob.Decode(obj)
- return newFile(path, blob), nil
+ return newFile(path, e.Mode, blob), nil
}
-func (t *Tree) findHash(path string) (*core.Hash, error) {
+func (t *Tree) findEntry(path string) (*TreeEntry, error) {
pathParts := strings.Split(path, "/")
var tree *Tree
@@ -75,12 +75,7 @@ func (t *Tree) findHash(path string) (*core.Hash, error) {
}
}
- entry, err := tree.entry(pathParts[0])
- if err != nil {
- return nil, err
- }
-
- return &entry.Hash, nil
+ return tree.entry(pathParts[0])
}
var errDirNotFound = errors.New("directory not found")