mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
refactor: commit search
* no longer depends on the commits displayed in histories view * limit the number of commits returned by all search methods to a maximum of 1000
This commit is contained in:
parent
48e1de809b
commit
c90abd0ca2
3 changed files with 24 additions and 22 deletions
|
@ -14,17 +14,22 @@ namespace SourceGit.Commands
|
||||||
_findFirstMerged = needFindHead;
|
_findFirstMerged = needFindHead;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryCommits(string repo, int maxCount, string messageFilter, bool isFile)
|
public QueryCommits(string repo, string filter, Models.CommitSearchMethod method)
|
||||||
{
|
{
|
||||||
string search;
|
string search;
|
||||||
if (isFile)
|
|
||||||
|
if (method == Models.CommitSearchMethod.ByUser)
|
||||||
{
|
{
|
||||||
search = $"-- \"{messageFilter}\"";
|
search = $"-i --author=\"{filter}\" --committer=\"{filter}\"";
|
||||||
|
}
|
||||||
|
else if (method == Models.CommitSearchMethod.ByFile)
|
||||||
|
{
|
||||||
|
search = $"-- \"{filter}\"";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var argsBuilder = new StringBuilder();
|
var argsBuilder = new StringBuilder();
|
||||||
var words = messageFilter.Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
var words = filter.Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (var word in words)
|
foreach (var word in words)
|
||||||
{
|
{
|
||||||
var escaped = word.Trim().Replace("\"", "\\\"", StringComparison.Ordinal);
|
var escaped = word.Trim().Replace("\"", "\\\"", StringComparison.Ordinal);
|
||||||
|
@ -36,7 +41,7 @@ namespace SourceGit.Commands
|
||||||
|
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
Context = 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 --branches --remotes " + search;
|
Args = $"log -1000 --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;
|
_findFirstMerged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,13 @@ using Avalonia.Media;
|
||||||
|
|
||||||
namespace SourceGit.Models
|
namespace SourceGit.Models
|
||||||
{
|
{
|
||||||
|
public enum CommitSearchMethod
|
||||||
|
{
|
||||||
|
ByUser,
|
||||||
|
ByMessage,
|
||||||
|
ByFile,
|
||||||
|
}
|
||||||
|
|
||||||
public class Commit
|
public class Commit
|
||||||
{
|
{
|
||||||
public static double OpacityForNotMerged
|
public static double OpacityForNotMerged
|
||||||
|
|
|
@ -548,6 +548,7 @@ namespace SourceGit.ViewModels
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IsSearchLoadingVisible = true;
|
IsSearchLoadingVisible = true;
|
||||||
|
SearchResultSelectedCommit = null;
|
||||||
IsSearchCommitSuggestionOpen = false;
|
IsSearchCommitSuggestionOpen = false;
|
||||||
SearchCommitFilterSuggestion.Clear();
|
SearchCommitFilterSuggestion.Clear();
|
||||||
|
|
||||||
|
@ -558,29 +559,18 @@ namespace SourceGit.ViewModels
|
||||||
switch (_searchCommitFilterType)
|
switch (_searchCommitFilterType)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
foreach (var c in _histories.Commits)
|
var commit = new Commands.QuerySingleCommit(_fullpath, _searchCommitFilter).Result();
|
||||||
{
|
if (commit != null)
|
||||||
if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase))
|
visible.Add(commit);
|
||||||
visible.Add(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
foreach (var c in _histories.Commits)
|
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByUser).Result();
|
||||||
{
|
|
||||||
if (c.Author.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| c.Committer.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| c.Author.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| c.Committer.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase))
|
|
||||||
visible.Add(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
visible = new Commands.QueryCommits(_fullpath, 1000, _searchCommitFilter, false).Result();
|
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByMessage).Result();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
visible = new Commands.QueryCommits(_fullpath, 1000, _searchCommitFilter, true).Result();
|
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByFile).Result();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue