@@ -15,7 +15,7 @@ import (
1515// Tree is basically like a directory - it references a bunch of other trees
1616// and/or blobs (i.e. files and sub-directories)
1717type Tree struct {
18- Entries [ ]TreeEntry
18+ Entries map [ string ]TreeEntry
1919 Hash core.Hash
2020
2121 r * Repository
@@ -97,13 +97,12 @@ func (t *Tree) dir(baseName string) (*Tree, error) {
9797var errEntryNotFound = errors .New ("entry not found" )
9898
9999func (t * Tree ) entry (baseName string ) (* TreeEntry , error ) {
100- for _ , entry := range t .Entries {
101- if entry .Name == baseName {
102- return & entry , nil
103- }
100+ entry , ok := t .Entries [baseName ]
101+ if ! ok {
102+ return nil , errEntryNotFound
104103 }
105104
106- return nil , errEntryNotFound
105+ return & entry , nil
107106}
108107
109108func (t * Tree ) Files () chan * File {
@@ -145,6 +144,8 @@ func (t *Tree) Decode(o core.Object) error {
145144 return nil
146145 }
147146
147+ t .Entries = make (map [string ]TreeEntry )
148+
148149 r := bufio .NewReader (o .Reader ())
149150 for {
150151 mode , err := r .ReadString (' ' )
@@ -172,11 +173,12 @@ func (t *Tree) Decode(o core.Object) error {
172173 return err
173174 }
174175
175- t .Entries = append (t .Entries , TreeEntry {
176+ baseName := name [:len (name )- 1 ]
177+ t .Entries [baseName ] = TreeEntry {
176178 Hash : hash ,
177179 Mode : os .FileMode (fm ),
178- Name : name [: len ( name ) - 1 ] ,
179- })
180+ Name : baseName ,
181+ }
180182 }
181183
182184 return nil
0 commit comments