@@ -44,20 +44,17 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
44
44
return nil , nil , err
45
45
}
46
46
if len (unHitPaths ) > 0 {
47
- revs2 , err := GetLastCommitForPaths (ctx , c , treePath , unHitPaths )
47
+ revs2 , err := GetLastCommitForPaths (ctx , cache , c , treePath , unHitPaths )
48
48
if err != nil {
49
49
return nil , nil , err
50
50
}
51
51
52
52
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
- }
56
53
revs [k ] = v
57
54
}
58
55
}
59
56
} else {
60
- revs , err = GetLastCommitForPaths (ctx , c , treePath , entryPaths )
57
+ revs , err = GetLastCommitForPaths (ctx , nil , c , treePath , entryPaths )
61
58
}
62
59
if err != nil {
63
60
return nil , nil , err
@@ -70,25 +67,29 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
70
67
commitsInfo [i ] = CommitInfo {
71
68
Entry : entry ,
72
69
}
70
+
71
+ // Check if we have found a commit for this entry in time
73
72
if rev , ok := revs [entry .Name ()]; ok {
74
73
entryCommit := convertCommit (rev )
75
74
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 ()
91
85
}
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
92
93
}
93
94
}
94
95
@@ -175,7 +176,9 @@ func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cac
175
176
}
176
177
177
178
// 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
+
179
182
// We do a tree traversal with nodes sorted by commit time
180
183
heap := binaryheap .NewWith (func (a , b interface {}) int {
181
184
if a .(* commitAndPaths ).commit .CommitTime ().Before (b .(* commitAndPaths ).commit .CommitTime ()) {
@@ -192,10 +195,13 @@ func GetLastCommitForPaths(ctx context.Context, c cgobject.CommitNode, treePath
192
195
193
196
// Start search from the root commit and with full set of paths
194
197
heap .Push (& commitAndPaths {c , paths , initialHashes })
195
-
198
+ heaploop:
196
199
for {
197
200
select {
198
201
case <- ctx .Done ():
202
+ if ctx .Err () == context .DeadlineExceeded {
203
+ break heaploop
204
+ }
199
205
return nil , ctx .Err ()
200
206
default :
201
207
}
@@ -233,14 +239,14 @@ func GetLastCommitForPaths(ctx context.Context, c cgobject.CommitNode, treePath
233
239
}
234
240
235
241
var remainingPaths []string
236
- for i , path := range current .paths {
242
+ for i , pth := range current .paths {
237
243
// The results could already contain some newer change for the same path,
238
244
// so don't override that and bail out on the file early.
239
- if resultNodes [path ] == nil {
245
+ if resultNodes [pth ] == nil {
240
246
if pathUnchanged [i ] {
241
247
// The path existed with the same hash in at least one parent so it could
242
248
// not have been changed in this commit directly.
243
- remainingPaths = append (remainingPaths , path )
249
+ remainingPaths = append (remainingPaths , pth )
244
250
} else {
245
251
// There are few possible cases how can we get here:
246
252
// - 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
250
256
// - We are looking at a merge commit and the hash of the file doesn't
251
257
// match any of the hashes being merged. This is more common for directories,
252
258
// 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
+ }
254
263
}
255
264
}
256
265
}
0 commit comments