@@ -96,26 +96,32 @@ type LsTreeOptions struct {
9696 CommandOptions
9797}
9898
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 ) {
101101 var opt LsTreeOptions
102102 if len (opts ) > 0 {
103103 opt = opts [0 ]
104104 }
105105
106+ cache , ok := r .cachedTrees .Get (treeID )
107+ if ok {
108+ log ("Cached tree hit: %s" , treeID )
109+ return cache .(* Tree ), nil
110+ }
111+
106112 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
108114 if err != nil {
109115 return nil , err
110116 }
111117 t := & Tree {
112- id : MustIDFromString (rev ),
118+ id : MustIDFromString (treeID ),
113119 repo : r ,
114120 }
115121
116122 stdout , err := NewCommand ("ls-tree" ).
117123 AddOptions (opt .CommandOptions ).
118- AddArgs (rev ).
124+ AddArgs (treeID ).
119125 RunInDirWithTimeout (opt .Timeout , r .path )
120126 if err != nil {
121127 return nil , err
@@ -126,5 +132,6 @@ func (r *Repository) LsTree(rev string, opts ...LsTreeOptions) (*Tree, error) {
126132 return nil , err
127133 }
128134
135+ r .cachedTrees .Set (treeID , t )
129136 return t , nil
130137}
0 commit comments