mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
enhance: commit search (#268)
* add `-i` parameter to ignore case while searching commit message * add `--branches --remotes` to search commits from all branches
This commit is contained in:
parent
a68b61da94
commit
d09866e2c3
2 changed files with 20 additions and 10 deletions
|
@ -14,20 +14,30 @@ namespace SourceGit.Commands
|
|||
_findFirstMerged = needFindHead;
|
||||
}
|
||||
|
||||
public QueryCommits(string repo, int maxCount, string messageFilter)
|
||||
public QueryCommits(string repo, int maxCount, string messageFilter, bool isFile)
|
||||
{
|
||||
var argsBuilder = new StringBuilder();
|
||||
var words = messageFilter.Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var word in words)
|
||||
string search;
|
||||
if (isFile)
|
||||
{
|
||||
var escaped = word.Trim().Replace("\"", "\\\"", StringComparison.Ordinal);
|
||||
argsBuilder.Append($"--grep=\"{escaped}\" ");
|
||||
search = $"-- \"{messageFilter}\"";
|
||||
}
|
||||
argsBuilder.Append("--all-match");
|
||||
else
|
||||
{
|
||||
var argsBuilder = new StringBuilder();
|
||||
var words = messageFilter.Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var word in words)
|
||||
{
|
||||
var escaped = word.Trim().Replace("\"", "\\\"", StringComparison.Ordinal);
|
||||
argsBuilder.Append($"--grep=\"{escaped}\" ");
|
||||
}
|
||||
argsBuilder.Append("--all-match -i");
|
||||
search = argsBuilder.ToString();
|
||||
}
|
||||
|
||||
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
Args = $"log -{maxCount} --date-order --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s " + argsBuilder.ToString();
|
||||
Args = $"log -{maxCount} --date-order --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s --branches --remotes " + search;
|
||||
_findFirstMerged = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -566,10 +566,10 @@ namespace SourceGit.ViewModels
|
|||
|
||||
break;
|
||||
case 2:
|
||||
visible = new Commands.QueryCommits(FullPath, 1000, _searchCommitFilter).Result();
|
||||
visible = new Commands.QueryCommits(FullPath, 1000, _searchCommitFilter, false).Result();
|
||||
break;
|
||||
case 3:
|
||||
visible = new Commands.QueryCommits(FullPath, $"-1000 -- \"{_searchCommitFilter}\"", false).Result();
|
||||
visible = new Commands.QueryCommits(FullPath, 1000, _searchCommitFilter, true).Result();
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue