refactor: commit search (#256)

This commit is contained in:
leo 2024-07-13 22:36:59 +08:00
parent 38c6c7713e
commit 6a8527a394
No known key found for this signature in database
6 changed files with 37 additions and 20 deletions

View file

@ -455,8 +455,10 @@
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">RESOLVE</x:String> <x:String x:Key="Text.Repository.Resolve" xml:space="preserve">RESOLVE</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">Search Commit</x:String> <x:String x:Key="Text.Repository.Search" xml:space="preserve">Search Commit</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Search By</x:String> <x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Search By</x:String>
<x:String x:Key="Text.Repository.Search.ByBaseInfo" xml:space="preserve">Information</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">File</x:String> <x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">File</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Message</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>
<x:String x:Key="Text.Repository.Search.ByUser" xml:space="preserve">Author &amp; Committer</x:String>
<x:String x:Key="Text.Repository.SearchBranchTag" xml:space="preserve">Search Branches &amp; Tags</x:String> <x:String x:Key="Text.Repository.SearchBranchTag" xml:space="preserve">Search Branches &amp; Tags</x:String>
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">Statistics</x:String> <x:String x:Key="Text.Repository.Statistics" xml:space="preserve">Statistics</x:String>
<x:String x:Key="Text.Repository.Submodules" xml:space="preserve">SUBMODULES</x:String> <x:String x:Key="Text.Repository.Submodules" xml:space="preserve">SUBMODULES</x:String>

View file

@ -457,8 +457,10 @@
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">解决冲突</x:String> <x:String x:Key="Text.Repository.Resolve" xml:space="preserve">解决冲突</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">查找提交</x:String> <x:String x:Key="Text.Repository.Search" xml:space="preserve">查找提交</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">搜索途径</x:String> <x:String x:Key="Text.Repository.Search.By" xml:space="preserve">搜索途径</x:String>
<x:String x:Key="Text.Repository.Search.ByBaseInfo" xml:space="preserve">摘要</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">文件</x:String> <x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">文件</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交信息</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交指纹</x:String>
<x:String x:Key="Text.Repository.Search.ByUser" xml:space="preserve">作者及提交者</x:String>
<x:String x:Key="Text.Repository.SearchBranchTag" xml:space="preserve">快速查找分支、标签</x:String> <x:String x:Key="Text.Repository.SearchBranchTag" xml:space="preserve">快速查找分支、标签</x:String>
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">提交统计</x:String> <x:String x:Key="Text.Repository.Statistics" xml:space="preserve">提交统计</x:String>
<x:String x:Key="Text.Repository.Submodules" xml:space="preserve">子模块列表</x:String> <x:String x:Key="Text.Repository.Submodules" xml:space="preserve">子模块列表</x:String>

View file

@ -457,8 +457,10 @@
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">解決衝突</x:String> <x:String x:Key="Text.Repository.Resolve" xml:space="preserve">解決衝突</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">查詢提交</x:String> <x:String x:Key="Text.Repository.Search" xml:space="preserve">查詢提交</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">查詢方式</x:String> <x:String x:Key="Text.Repository.Search.By" xml:space="preserve">查詢方式</x:String>
<x:String x:Key="Text.Repository.Search.ByBaseInfo" xml:space="preserve">摘要</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">檔案</x:String> <x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">檔案</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交資訊</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交指紋</x:String>
<x:String x:Key="Text.Repository.Search.ByUser" xml:space="preserve">作者及提交者</x:String>
<x:String x:Key="Text.Repository.SearchBranchTag" xml:space="preserve">快速查找分支、標籤</x:String> <x:String x:Key="Text.Repository.SearchBranchTag" xml:space="preserve">快速查找分支、標籤</x:String>
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">提交統計</x:String> <x:String x:Key="Text.Repository.Statistics" xml:space="preserve">提交統計</x:String>
<x:String x:Key="Text.Repository.Submodules" xml:space="preserve">子模組列表</x:String> <x:String x:Key="Text.Repository.Submodules" xml:space="preserve">子模組列表</x:String>

View file

@ -545,24 +545,33 @@ namespace SourceGit.ViewModels
{ {
var visible = new List<Models.Commit>(); var visible = new List<Models.Commit>();
if (_searchCommitFilterType == 0) switch (_searchCommitFilterType)
{ {
foreach (var c in _histories.Commits) case 0:
{ foreach (var c in _histories.Commits)
if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|| c.Subject.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|| 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); if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase))
visible.Add(c);
} }
}
} break;
else case 1:
{ foreach (var c in _histories.Commits)
visible = new Commands.QueryCommits(FullPath, $"-1000 -- \"{_searchCommitFilter}\"", false).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;
case 2:
visible = new Commands.QueryCommits(FullPath, $"-1000 --grep=\"{_searchCommitFilter}\"", false).Result();
break;
case 3:
visible = new Commands.QueryCommits(FullPath, $"-1000 -- \"{_searchCommitFilter}\"", false).Result();
break;
} }
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>

View file

@ -580,7 +580,9 @@
HorizontalAlignment="Right" HorizontalAlignment="Right"
SelectedIndex="{Binding SearchCommitFilterType, Mode=TwoWay}"> SelectedIndex="{Binding SearchCommitFilterType, Mode=TwoWay}">
<ComboBox.Items> <ComboBox.Items>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByBaseInfo}" FontSize="12"/> <TextBlock Text="{DynamicResource Text.Repository.Search.BySHA}" FontSize="12"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByUser}" FontSize="12"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByMessage}" FontSize="12"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByFile}" FontSize="12"/> <TextBlock Text="{DynamicResource Text.Repository.Search.ByFile}" FontSize="12"/>
</ComboBox.Items> </ComboBox.Items>
</ComboBox> </ComboBox>

View file

@ -73,7 +73,7 @@ namespace SourceGit.Views
{ {
if (e.Key == Key.Enter) if (e.Key == Key.Enter)
{ {
if (DataContext is ViewModels.Repository repo) if (DataContext is ViewModels.Repository repo && !string.IsNullOrWhiteSpace(repo.SearchCommitFilter))
repo.StartSearchCommits(); repo.StartSearchCommits();
e.Handled = true; e.Handled = true;