* Support searching commits with prefix syntax For now, support auther: committer: When more than one prefix is supplied is presented, the result is the union. When different prefixes are supplied, the result is the intersection. For example, "author:alice author:bob" => the result is all commits authored by Alice OR Bob "hello committer:alice" => the result is all commits committed by Alice AND has the keyword 'hello' in the message. Note that there should NOT have any space after the colon(:) of the prefix. For example, "author:bill" => correct "author: bill" => wrong * Remove unneeded logging * Add missing files of test repository * Add missing repo_unit entries to test fixtures * Update test cases * Add tooltip for commits search button * Update tooltip text I have no idea about how to format it with line breaks. * Make the usage example more real * Add a test case * Add new options struct for SearchCommits * Prefer len(s) > 0 over s != "" * Add NewSearchCommitsOptions
Showing the changes to modules/git/commit.go (1 of 41 files). Show all
Unified · Split
| @@ -214,9 +214,48 @@ func (c *Commit) CommitsBeforeUntil(commitID string) (*list.List, error) { · 213 unmodified lines | |||
| 214 | return c.repo.CommitsBetween(c, endCommit) | 214 | return c.repo.CommitsBetween(c, endCommit) |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | // SearchCommitsOptions specify the parameters for SearchCommits | ||
| 218 | type SearchCommitsOptions struct { | ||
| 219 | Keywords []string | ||
| 220 | Authors, Committers []string | ||
| 221 | After, Before string | ||
| 222 | All bool | ||
| 223 | } | ||
| 224 | |||
| 225 | // NewSearchCommitsOptions contruct a SearchCommitsOption from a space-delimited search string | ||
| 226 | func NewSearchCommitsOptions(searchString string, forAllRefs bool) SearchCommitsOptions { | ||
| 227 | var keywords, authors, committers []string | ||
| 228 | var after, before string | ||
| 229 | |||
| 230 | fields := strings.Fields(searchString) | ||
| 231 | for _, k := range fields { | ||
| 232 | switch { | ||
| 233 | case strings.HasPrefix(k, "author:"): | ||
| 234 | authors = append(authors, strings.TrimPrefix(k, "author:")) | ||
| 235 | case strings.HasPrefix(k, "committer:"): | ||
| 236 | committers = append(committers, strings.TrimPrefix(k, "committer:")) | ||
| 237 | case strings.HasPrefix(k, "after:"): | ||
| 238 | after = strings.TrimPrefix(k, "after:") | ||
| 239 | case strings.HasPrefix(k, "before:"): | ||
| 240 | before = strings.TrimPrefix(k, "before:") | ||
| 241 | default: | ||
| 242 | keywords = append(keywords, k) | ||
| 243 | } | ||
| 244 | } | ||
| 245 | |||
| 246 | return SearchCommitsOptions{ | ||
| 247 | Keywords: keywords, | ||
| 248 | Authors: authors, | ||
| 249 | Committers: committers, | ||
| 250 | After: after, | ||
| 251 | Before: before, | ||
| 252 | All: forAllRefs, | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 217 | // SearchCommits returns the commits match the keyword before current revision | 256 | // SearchCommits returns the commits match the keyword before current revision |
| 218 | func (c *Commit) SearchCommits(keyword string, all bool) (*list.List, error) { | 257 | func (c *Commit) SearchCommits(opts SearchCommitsOptions) (*list.List, error) { |
| 219 | return c.repo.searchCommits(c.ID, keyword, all) | 258 | return c.repo.searchCommits(c.ID, opts) |
| 220 | } | 259 | } |
| 221 | 260 | ||
| 222 | // GetFilesChangedSinceCommit get all changed file names between pastCommit to current revision | 261 | // GetFilesChangedSinceCommit get all changed file names between pastCommit to current revision |