@@ -96,26 +96,32 @@ type LsTreeOptions struct {
96
96
CommandOptions
97
97
}
98
98
99
- // LsTree returns the tree object in the repository by given revision .
100
- func (r * Repository ) LsTree (rev string , opts ... LsTreeOptions ) (* Tree , error ) {
99
+ // LsTree returns the tree object in the repository by given tree ID .
100
+ func (r * Repository ) LsTree (treeID string , opts ... LsTreeOptions ) (* Tree , error ) {
101
101
var opt LsTreeOptions
102
102
if len (opts ) > 0 {
103
103
opt = opts [0 ]
104
104
}
105
105
106
+ cache , ok := r .cachedTrees .Get (treeID )
107
+ if ok {
108
+ log ("Cached tree hit: %s" , treeID )
109
+ return cache .(* Tree ), nil
110
+ }
111
+
106
112
var err error
107
- rev , err = r .RevParse (rev , RevParseOptions {Timeout : opt .Timeout }) //nolint
113
+ treeID , err = r .RevParse (treeID , RevParseOptions {Timeout : opt .Timeout }) //nolint
108
114
if err != nil {
109
115
return nil , err
110
116
}
111
117
t := & Tree {
112
- id : MustIDFromString (rev ),
118
+ id : MustIDFromString (treeID ),
113
119
repo : r ,
114
120
}
115
121
116
122
stdout , err := NewCommand ("ls-tree" ).
117
123
AddOptions (opt .CommandOptions ).
118
- AddArgs (rev ).
124
+ AddArgs (treeID ).
119
125
RunInDirWithTimeout (opt .Timeout , r .path )
120
126
if err != nil {
121
127
return nil , err
@@ -126,5 +132,6 @@ func (r *Repository) LsTree(rev string, opts ...LsTreeOptions) (*Tree, error) {
126
132
return nil , err
127
133
}
128
134
135
+ r .cachedTrees .Set (treeID , t )
129
136
return t , nil
130
137
}
0 commit comments