@@ -220,32 +220,49 @@ func (repo *Repository) commitsByRange(id SHA1, page, pageSize int) (*list.List,
220
220
}
221
221
222
222
func (repo * Repository ) searchCommits (id SHA1 , opts SearchCommitsOptions ) (* list.List , error ) {
223
+ // create new git log command with limit of 100 commis
223
224
cmd := NewCommand ("log" , id .String (), "-100" , prettyLogFormat )
225
+ // ignore case
224
226
args := []string {"-i" }
227
+
228
+ // add authors if present in search query
225
229
if len (opts .Authors ) > 0 {
226
230
for _ , v := range opts .Authors {
227
231
args = append (args , "--author=" + v )
228
232
}
229
233
}
234
+
235
+ // add commiters if present in search query
230
236
if len (opts .Committers ) > 0 {
231
237
for _ , v := range opts .Committers {
232
238
args = append (args , "--committer=" + v )
233
239
}
234
240
}
241
+
242
+ // add time constraints if present in search query
235
243
if len (opts .After ) > 0 {
236
244
args = append (args , "--after=" + opts .After )
237
245
}
238
246
if len (opts .Before ) > 0 {
239
247
args = append (args , "--before=" + opts .Before )
240
248
}
249
+
250
+ // pretend that all refs along with HEAD were listed on command line as <commis>
251
+ // https://git-scm.com/docs/git-log#Documentation/git-log.txt---all
252
+ // note this is done only for command created above
241
253
if opts .All {
242
- args = append ( args , "--all" )
254
+ cmd . AddArguments ( "--all" )
243
255
}
256
+
257
+ // add remaining keywords from search string
258
+ // note this is done only for command created above
244
259
if len (opts .Keywords ) > 0 {
245
260
for _ , v := range opts .Keywords {
246
261
cmd .AddArguments ("--grep=" + v )
247
262
}
248
263
}
264
+
265
+ // search for commits matching given constraints and keywords in commit msg
249
266
cmd .AddArguments (args ... )
250
267
stdout , err := cmd .RunInDirBytes (repo .Path )
251
268
if err != nil {
@@ -254,12 +271,21 @@ func (repo *Repository) searchCommits(id SHA1, opts SearchCommitsOptions) (*list
254
271
if len (stdout ) != 0 {
255
272
stdout = append (stdout , '\n' )
256
273
}
274
+
275
+ // if there are any keywords (ie not commiter:, author:, time:)
276
+ // then let's iterate over them
257
277
if len (opts .Keywords ) > 0 {
258
278
for _ , v := range opts .Keywords {
279
+ // ignore anything below 4 characters as too unspecific
259
280
if len (v ) >= 4 {
281
+ // create new git log command with 1 commit limit
260
282
hashCmd := NewCommand ("log" , "-1" , prettyLogFormat )
283
+ // add previous arguments except for --grep and --all
261
284
hashCmd .AddArguments (args ... )
285
+ // add keyword as <commit>
262
286
hashCmd .AddArguments (v )
287
+
288
+ // search with given constraints for commit matching sha hash of v
263
289
hashMatching , err := hashCmd .RunInDirBytes (repo .Path )
264
290
if err != nil || bytes .Contains (stdout , hashMatching ) {
265
291
continue
0 commit comments