@@ -203,35 +203,54 @@ func (repo *Repository) commitsByRange(id SHA1, page int) (*list.List, error) {
203203
204204func (repo * Repository ) searchCommits (id SHA1 , opts SearchCommitsOptions ) (* list.List , error ) {
205205 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 }
211207 if len (opts .Authors ) > 0 {
212208 for _ , v := range opts .Authors {
213209 cmd .AddArguments ("--author=" + v )
210+ args = append (args , "--author=" + v )
214211 }
215212 }
216213 if len (opts .Committers ) > 0 {
217214 for _ , v := range opts .Committers {
218215 cmd .AddArguments ("--committer=" + v )
216+ args = append (args , "--committer=" + v )
219217 }
220218 }
221219 if len (opts .After ) > 0 {
222220 cmd .AddArguments ("--after=" + opts .After )
221+ args = append (args , "--after=" + opts .After )
223222 }
224223 if len (opts .Before ) > 0 {
225224 cmd .AddArguments ("--before=" + opts .Before )
225+ args = append (args , "--before=" + opts .Before )
226226 }
227227 if opts .All {
228228 cmd .AddArguments ("--all" )
229229 }
230+ if len (opts .Keywords ) > 0 {
231+ for _ , v := range opts .Keywords {
232+ cmd .AddArguments ("--grep=" + v )
233+ }
234+ }
230235 stdout , err := cmd .RunInDirBytes (repo .Path )
231236 if err != nil {
232237 return nil , err
233238 }
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' }))
235254}
236255
237256func (repo * Repository ) getFilesChanged (id1 , id2 string ) ([]string , error ) {
0 commit comments