From 6a8527a3948ceb7f5a7434288a90ac19082a03e2 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 13 Jul 2024 22:36:59 +0800 Subject: [PATCH] refactor: commit search (#256) --- src/Resources/Locales/en_US.axaml | 4 +++- src/Resources/Locales/zh_CN.axaml | 4 +++- src/Resources/Locales/zh_TW.axaml | 4 +++- src/ViewModels/Repository.cs | 39 +++++++++++++++++++------------ src/Views/Repository.axaml | 4 +++- src/Views/Repository.axaml.cs | 2 +- 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 547d9e51..ef8ffd06 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -455,8 +455,10 @@ RESOLVE Search Commit Search By - Information File + Message + SHA + Author & Committer Search Branches & Tags Statistics SUBMODULES diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index c9f525b3..20265dab 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -457,8 +457,10 @@ 解决冲突 查找提交 搜索途径 - 摘要 文件 + 提交信息 + 提交指纹 + 作者及提交者 快速查找分支、标签 提交统计 子模块列表 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 38c4af51..70b7bbf1 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -457,8 +457,10 @@ 解決衝突 查詢提交 查詢方式 - 摘要 檔案 + 提交資訊 + 提交指紋 + 作者及提交者 快速查找分支、標籤 提交統計 子模組列表 diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 4f0ecfa1..b42d9681 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -545,24 +545,33 @@ namespace SourceGit.ViewModels { var visible = new List(); - if (_searchCommitFilterType == 0) + switch (_searchCommitFilterType) { - 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)) + case 0: + foreach (var c in _histories.Commits) { - visible.Add(c); + if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)) + visible.Add(c); } - } - } - else - { - visible = new Commands.QueryCommits(FullPath, $"-1000 -- \"{_searchCommitFilter}\"", false).Result(); + + break; + case 1: + foreach (var c in _histories.Commits) + { + 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(() => diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index d5914163..8b4ceeb6 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -580,7 +580,9 @@ HorizontalAlignment="Right" SelectedIndex="{Binding SearchCommitFilterType, Mode=TwoWay}"> - + + + diff --git a/src/Views/Repository.axaml.cs b/src/Views/Repository.axaml.cs index 3a05d517..409ceeda 100644 --- a/src/Views/Repository.axaml.cs +++ b/src/Views/Repository.axaml.cs @@ -73,7 +73,7 @@ namespace SourceGit.Views { if (e.Key == Key.Enter) { - if (DataContext is ViewModels.Repository repo) + if (DataContext is ViewModels.Repository repo && !string.IsNullOrWhiteSpace(repo.SearchCommitFilter)) repo.StartSearchCommits(); e.Handled = true;