@@ -72,13 +72,20 @@ func (state *getCommitsInfoState) getTargetedEntryPath() string {
72
72
}
73
73
74
74
// repeatedly perform targeted searches for unpopulated entries
75
- func targetedSearch (state * getCommitsInfoState , done chan error ) {
75
+ func targetedSearch (state * getCommitsInfoState , done chan error , cache LastCommitCache ) {
76
76
for {
77
77
entryPath := state .getTargetedEntryPath ()
78
78
if len (entryPath ) == 0 {
79
79
done <- nil
80
80
return
81
81
}
82
+ if cache != nil {
83
+ commit , err := cache .Get (state .headCommit .repo .Path , state .headCommit .ID .String (), entryPath )
84
+ if err == nil && commit != nil {
85
+ state .update (entryPath , commit )
86
+ continue
87
+ }
88
+ }
82
89
command := NewCommand ("rev-list" , "-1" , state .headCommit .ID .String (), "--" , entryPath )
83
90
output , err := command .RunInDir (state .headCommit .repo .Path )
84
91
if err != nil {
@@ -96,6 +103,9 @@ func targetedSearch(state *getCommitsInfoState, done chan error) {
96
103
return
97
104
}
98
105
state .update (entryPath , commit )
106
+ if cache != nil {
107
+ cache .Put (state .headCommit .repo .Path , state .headCommit .ID .String (), entryPath , commit )
108
+ }
99
109
}
100
110
}
101
111
@@ -118,9 +128,9 @@ func initGetCommitInfoState(entries Entries, headCommit *Commit, treePath string
118
128
}
119
129
120
130
// GetCommitsInfo gets information of all commits that are corresponding to these entries
121
- func (tes Entries ) GetCommitsInfo (commit * Commit , treePath string ) ([][]interface {}, error ) {
131
+ func (tes Entries ) GetCommitsInfo (commit * Commit , treePath string , cache LastCommitCache ) ([][]interface {}, error ) {
122
132
state := initGetCommitInfoState (tes , commit , treePath )
123
- if err := getCommitsInfo (state ); err != nil {
133
+ if err := getCommitsInfo (state , cache ); err != nil {
124
134
return nil , err
125
135
}
126
136
if len (state .commits ) < len (state .entryPaths ) {
@@ -188,7 +198,7 @@ func (state *getCommitsInfoState) update(entryPath string, commit *Commit) bool
188
198
189
199
const getCommitsInfoPretty = "--pretty=format:%H %ct %s"
190
200
191
- func getCommitsInfo (state * getCommitsInfoState ) error {
201
+ func getCommitsInfo (state * getCommitsInfoState , cache LastCommitCache ) error {
192
202
ctx , cancel := context .WithTimeout (context .Background (), 1 * time .Minute )
193
203
defer cancel ()
194
204
@@ -215,7 +225,7 @@ func getCommitsInfo(state *getCommitsInfoState) error {
215
225
numThreads := runtime .NumCPU ()
216
226
done := make (chan error , numThreads )
217
227
for i := 0 ; i < numThreads ; i ++ {
218
- go targetedSearch (state , done )
228
+ go targetedSearch (state , done , cache )
219
229
}
220
230
221
231
scanner := bufio .NewScanner (readCloser )
0 commit comments