@@ -203,35 +203,54 @@ func (repo *Repository) commitsByRange(id SHA1, page int) (*list.List, error) {
203
203
204
204
func (repo * Repository ) searchCommits (id SHA1 , opts SearchCommitsOptions ) (* list.List , error ) {
205
205
cmd := NewCommand ("log" , id .String (), "-100" , "-i" , prettyLogFormat )
206
- if len (opts .Keywords ) > 0 {
207
- for _ , v := range opts .Keywords {
208
- cmd .AddArguments ("--grep=" + v )
209
- }
210
- }
206
+ args := []string {"log" , "-i" , prettyLogFormat }
211
207
if len (opts .Authors ) > 0 {
212
208
for _ , v := range opts .Authors {
213
209
cmd .AddArguments ("--author=" + v )
210
+ args = append (args , "--author=" + v )
214
211
}
215
212
}
216
213
if len (opts .Committers ) > 0 {
217
214
for _ , v := range opts .Committers {
218
215
cmd .AddArguments ("--committer=" + v )
216
+ args = append (args , "--committer=" + v )
219
217
}
220
218
}
221
219
if len (opts .After ) > 0 {
222
220
cmd .AddArguments ("--after=" + opts .After )
221
+ args = append (args , "--after=" + opts .After )
223
222
}
224
223
if len (opts .Before ) > 0 {
225
224
cmd .AddArguments ("--before=" + opts .Before )
225
+ args = append (args , "--before=" + opts .Before )
226
226
}
227
227
if opts .All {
228
228
cmd .AddArguments ("--all" )
229
229
}
230
+ if len (opts .Keywords ) > 0 {
231
+ for _ , v := range opts .Keywords {
232
+ cmd .AddArguments ("--grep=" + v )
233
+ }
234
+ }
230
235
stdout , err := cmd .RunInDirBytes (repo .Path )
231
236
if err != nil {
232
237
return nil , err
233
238
}
234
- return repo .parsePrettyFormatLogToList (stdout )
239
+ if len (opts .Keywords ) > 0 {
240
+ for _ , v := range opts .Keywords {
241
+ if len (v ) >= 4 {
242
+ hashCmd := NewCommand (args ... )
243
+ hashCmd .AddArguments ("-1" , v )
244
+ hashMatching , err := hashCmd .RunInDirBytes (repo .Path )
245
+ if err != nil || bytes .Contains (stdout , hashMatching ) {
246
+ continue
247
+ }
248
+ stdout = append (stdout , hashMatching ... )
249
+ stdout = append (stdout , '\n' )
250
+ }
251
+ }
252
+ }
253
+ return repo .parsePrettyFormatLogToList (bytes .TrimSuffix (stdout , []byte {'\n' }))
235
254
}
236
255
237
256
func (repo * Repository ) getFilesChanged (id1 , id2 string ) ([]string , error ) {
0 commit comments