@@ -44,20 +44,17 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
4444 return nil , nil , err
4545 }
4646 if len (unHitPaths ) > 0 {
47- revs2 , err := GetLastCommitForPaths (ctx , c , treePath , unHitPaths )
47+ revs2 , err := GetLastCommitForPaths (ctx , cache , c , treePath , unHitPaths )
4848 if err != nil {
4949 return nil , nil , err
5050 }
5151
5252 for k , v := range revs2 {
53- if err := cache .Put (commit .ID .String (), path .Join (treePath , k ), v .ID ().String ()); err != nil {
54- return nil , nil , err
55- }
5653 revs [k ] = v
5754 }
5855 }
5956 } else {
60- revs , err = GetLastCommitForPaths (ctx , c , treePath , entryPaths )
57+ revs , err = GetLastCommitForPaths (ctx , nil , c , treePath , entryPaths )
6158 }
6259 if err != nil {
6360 return nil , nil , err
@@ -70,25 +67,29 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
7067 commitsInfo [i ] = CommitInfo {
7168 Entry : entry ,
7269 }
70+
71+ // Check if we have found a commit for this entry in time
7372 if rev , ok := revs [entry .Name ()]; ok {
7473 entryCommit := convertCommit (rev )
7574 commitsInfo [i ].Commit = entryCommit
76- if entry .IsSubModule () {
77- subModuleURL := ""
78- var fullPath string
79- if len (treePath ) > 0 {
80- fullPath = treePath + "/" + entry .Name ()
81- } else {
82- fullPath = entry .Name ()
83- }
84- if subModule , err := commit .GetSubModule (fullPath ); err != nil {
85- return nil , nil , err
86- } else if subModule != nil {
87- subModuleURL = subModule .URL
88- }
89- subModuleFile := NewSubModuleFile (entryCommit , subModuleURL , entry .ID .String ())
90- commitsInfo [i ].SubModuleFile = subModuleFile
75+ }
76+
77+ // If the entry if a submodule add a submodule file for this
78+ if entry .IsSubModule () {
79+ subModuleURL := ""
80+ var fullPath string
81+ if len (treePath ) > 0 {
82+ fullPath = treePath + "/" + entry .Name ()
83+ } else {
84+ fullPath = entry .Name ()
9185 }
86+ if subModule , err := commit .GetSubModule (fullPath ); err != nil {
87+ return nil , nil , err
88+ } else if subModule != nil {
89+ subModuleURL = subModule .URL
90+ }
91+ subModuleFile := NewSubModuleFile (commitsInfo [i ].Commit , subModuleURL , entry .ID .String ())
92+ commitsInfo [i ].SubModuleFile = subModuleFile
9293 }
9394 }
9495
@@ -175,7 +176,9 @@ func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cac
175176}
176177
177178// GetLastCommitForPaths returns last commit information
178- func GetLastCommitForPaths (ctx context.Context , c cgobject.CommitNode , treePath string , paths []string ) (map [string ]* object.Commit , error ) {
179+ func GetLastCommitForPaths (ctx context.Context , cache * LastCommitCache , c cgobject.CommitNode , treePath string , paths []string ) (map [string ]* object.Commit , error ) {
180+ refSha := c .ID ().String ()
181+
179182 // We do a tree traversal with nodes sorted by commit time
180183 heap := binaryheap .NewWith (func (a , b interface {}) int {
181184 if a .(* commitAndPaths ).commit .CommitTime ().Before (b .(* commitAndPaths ).commit .CommitTime ()) {
@@ -192,10 +195,13 @@ func GetLastCommitForPaths(ctx context.Context, c cgobject.CommitNode, treePath
192195
193196 // Start search from the root commit and with full set of paths
194197 heap .Push (& commitAndPaths {c , paths , initialHashes })
195-
198+ heaploop:
196199 for {
197200 select {
198201 case <- ctx .Done ():
202+ if ctx .Err () == context .DeadlineExceeded {
203+ break heaploop
204+ }
199205 return nil , ctx .Err ()
200206 default :
201207 }
@@ -233,14 +239,14 @@ func GetLastCommitForPaths(ctx context.Context, c cgobject.CommitNode, treePath
233239 }
234240
235241 var remainingPaths []string
236- for i , path := range current .paths {
242+ for i , pth := range current .paths {
237243 // The results could already contain some newer change for the same path,
238244 // so don't override that and bail out on the file early.
239- if resultNodes [path ] == nil {
245+ if resultNodes [pth ] == nil {
240246 if pathUnchanged [i ] {
241247 // The path existed with the same hash in at least one parent so it could
242248 // not have been changed in this commit directly.
243- remainingPaths = append (remainingPaths , path )
249+ remainingPaths = append (remainingPaths , pth )
244250 } else {
245251 // There are few possible cases how can we get here:
246252 // - The path didn't exist in any parent, so it must have been created by
@@ -250,7 +256,10 @@ func GetLastCommitForPaths(ctx context.Context, c cgobject.CommitNode, treePath
250256 // - We are looking at a merge commit and the hash of the file doesn't
251257 // match any of the hashes being merged. This is more common for directories,
252258 // but it can also happen if a file is changed through conflict resolution.
253- resultNodes [path ] = current .commit
259+ resultNodes [pth ] = current .commit
260+ if err := cache .Put (refSha , path .Join (treePath , pth ), current .commit .ID ().String ()); err != nil {
261+ return nil , err
262+ }
254263 }
255264 }
256265 }
0 commit comments