feature: supports search commit only in current branch

This commit is contained in:
leo 2024-09-27 11:17:02 +08:00
parent 027844f4c5
commit 130c98ad40
No known key found for this signature in database
14 changed files with 47 additions and 36 deletions

View file

@ -14,21 +14,23 @@ namespace SourceGit.Commands
_findFirstMerged = needFindHead; _findFirstMerged = needFindHead;
} }
public QueryCommits(string repo, string filter, Models.CommitSearchMethod method) public QueryCommits(string repo, string filter, Models.CommitSearchMethod method, bool onlyCurrentBranch)
{ {
string search; string search = onlyCurrentBranch ? string.Empty : "--branches --remotes ";
if (method == Models.CommitSearchMethod.ByUser) if (method == Models.CommitSearchMethod.ByUser)
{ {
search = $"-i --author=\"{filter}\" --committer=\"{filter}\""; search += $"-i --author=\"{filter}\" --committer=\"{filter}\"";
} }
else if (method == Models.CommitSearchMethod.ByFile) else if (method == Models.CommitSearchMethod.ByFile)
{ {
search = $"-- \"{filter}\""; search += $"-- \"{filter}\"";
} }
else else
{ {
var argsBuilder = new StringBuilder(); var argsBuilder = new StringBuilder();
argsBuilder.Append(search);
var words = filter.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)
{ {
@ -36,12 +38,13 @@ namespace SourceGit.Commands
argsBuilder.Append($"--grep=\"{escaped}\" "); argsBuilder.Append($"--grep=\"{escaped}\" ");
} }
argsBuilder.Append("--all-match -i"); argsBuilder.Append("--all-match -i");
search = argsBuilder.ToString(); search = argsBuilder.ToString();
} }
WorkingDirectory = repo; WorkingDirectory = repo;
Context = repo; Context = repo;
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; 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 " + search;
_findFirstMerged = false; _findFirstMerged = false;
} }

View file

@ -512,7 +512,6 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">REMOTE HINZUFÜGEN</x:String> <x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">REMOTE HINZUFÜGEN</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">KONFLIKTE BEHEBEN</x:String> <x:String x:Key="Text.Repository.Resolve" xml:space="preserve">KONFLIKTE BEHEBEN</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">Commit suchen</x:String> <x:String x:Key="Text.Repository.Search" xml:space="preserve">Commit suchen</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Suche über</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">Dateiname</x:String> <x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">Dateiname</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Commit-Nachricht</x:String> <x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Commit-Nachricht</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String> <x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>

View file

@ -509,11 +509,11 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADD REMOTE</x:String> <x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADD REMOTE</x:String>
<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.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.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.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.Search.ByUser" xml:space="preserve">Author &amp; Committer</x:String>
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">Current Branch</x:String>
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">Show Tags as Tree</x:String> <x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">Show Tags as Tree</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

@ -491,7 +491,6 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADD REMOTE</x:String> <x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADD REMOTE</x:String>
<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.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.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.BySHA" xml:space="preserve">SHA</x:String>

View file

@ -484,7 +484,6 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADICIONAR REMOTO</x:String> <x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADICIONAR REMOTO</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">RESOLVER</x:String> <x:String x:Key="Text.Repository.Resolve" xml:space="preserve">RESOLVER</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">Pesquisar Commit</x:String> <x:String x:Key="Text.Repository.Search" xml:space="preserve">Pesquisar Commit</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Pesquisar Por</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">Arquivo</x:String> <x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">Arquivo</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Mensagem</x:String> <x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Mensagem</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String> <x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>

View file

@ -1,4 +1,7 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://SourceGit/Resources/Locales/en_US.axaml"/>
</ResourceDictionary.MergedDictionaries>
<x:String x:Key="Text.About" xml:space="preserve">О программе</x:String> <x:String x:Key="Text.About" xml:space="preserve">О программе</x:String>
<x:String x:Key="Text.About.Menu" xml:space="preserve">О SourceGit</x:String> <x:String x:Key="Text.About.Menu" xml:space="preserve">О SourceGit</x:String>
<x:String x:Key="Text.About.BuildWith" xml:space="preserve">• Сборка с </x:String> <x:String x:Key="Text.About.BuildWith" xml:space="preserve">• Сборка с </x:String>
@ -507,7 +510,6 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ДОБАВИТЬ ВНЕШНЕЕ ХРАНИЛИЩЕ</x:String> <x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ДОБАВИТЬ ВНЕШНЕЕ ХРАНИЛИЩЕ</x:String>
<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.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.ByMessage" xml:space="preserve">Сообщение</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String> <x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>

View file

@ -507,11 +507,11 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">添加远程</x:String> <x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">添加远程</x:String>
<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.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.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.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.Search.ByUser" xml:space="preserve">作者及提交者</x:String>
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">仅在当前分支中查找</x:String>
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">以树型结构展示</x:String> <x:String x:Key="Text.Repository.ShowTagsAsTree" 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

@ -512,11 +512,11 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">新增遠端</x:String> <x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">新增遠端</x:String>
<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.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.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.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.Search.ByUser" xml:space="preserve">作者及提交者</x:String>
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">僅搜尋當前分支</x:String>
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">以樹型結構展示</x:String> <x:String x:Key="Text.Repository.ShowTagsAsTree" 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

@ -544,7 +544,8 @@ namespace SourceGit.ViewModels
private void TryToAddContextMenuItemsForGitLFS(ContextMenu menu, string path) private void TryToAddContextMenuItemsForGitLFS(ContextMenu menu, string path)
{ {
var lfsEnabled = new Commands.LFS(_repo.FullPath).IsEnabled(); var lfsEnabled = new Commands.LFS(_repo.FullPath).IsEnabled();
if (!lfsEnabled) return; if (!lfsEnabled)
return;
var lfs = new MenuItem(); var lfs = new MenuItem();
lfs.Header = App.Text("GitLFS"); lfs.Header = App.Text("GitLFS");

View file

@ -65,7 +65,7 @@ namespace SourceGit.ViewModels
CallUIThread(() => CallUIThread(() =>
{ {
_repo.MarkFetched(); _repo.MarkFetched();
_repo.SetWatcherEnabled(true); _repo.SetWatcherEnabled(true);
}); });
return true; return true;

View file

@ -20,7 +20,7 @@ namespace SourceGit.ViewModels
get => _isLoading; get => _isLoading;
private set => SetProperty(ref _isLoading, value); private set => SetProperty(ref _isLoading, value);
} }
public bool ShowOnlyMyLocks public bool ShowOnlyMyLocks
{ {
get => _showOnlyMyLocks; get => _showOnlyMyLocks;

View file

@ -210,6 +210,12 @@ namespace SourceGit.ViewModels
private set => SetProperty(ref _isSearchLoadingVisible, value); private set => SetProperty(ref _isSearchLoadingVisible, value);
} }
public bool OnlySearchCommitsInCurrentBranch
{
get => _onlySearchCommitsInCurrentBranch;
set => SetProperty(ref _onlySearchCommitsInCurrentBranch, value);
}
public int SearchCommitFilterType public int SearchCommitFilterType
{ {
get => _searchCommitFilterType; get => _searchCommitFilterType;
@ -589,13 +595,13 @@ namespace SourceGit.ViewModels
visible.Add(commit); visible.Add(commit);
break; break;
case 1: case 1:
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByUser).Result(); visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByUser, _onlySearchCommitsInCurrentBranch).Result();
break; break;
case 2: case 2:
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByMessage).Result(); visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByMessage, _onlySearchCommitsInCurrentBranch).Result();
break; break;
case 3: case 3:
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByFile).Result(); visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByFile, _onlySearchCommitsInCurrentBranch).Result();
break; break;
} }
@ -667,8 +673,8 @@ namespace SourceGit.ViewModels
var hasLeft = false; var hasLeft = false;
foreach (var b in _branches) foreach (var b in _branches)
{ {
if (!b.FullName.Equals(local.FullName, StringComparison.Ordinal) && if (!b.FullName.Equals(local.FullName, StringComparison.Ordinal) &&
!b.FullName.Equals(local.Upstream, StringComparison.Ordinal) && !b.FullName.Equals(local.Upstream, StringComparison.Ordinal) &&
!_settings.Filters.Contains(b.FullName)) !_settings.Filters.Contains(b.FullName))
{ {
hasLeft = true; hasLeft = true;
@ -2072,6 +2078,7 @@ namespace SourceGit.ViewModels
private bool _isSearchLoadingVisible = false; private bool _isSearchLoadingVisible = false;
private bool _isSearchCommitSuggestionOpen = false; private bool _isSearchCommitSuggestionOpen = false;
private int _searchCommitFilterType = 2; private int _searchCommitFilterType = 2;
private bool _onlySearchCommitsInCurrentBranch = false;
private bool _enableFirstParentInHistories = false; private bool _enableFirstParentInHistories = false;
private string _searchCommitFilter = string.Empty; private string _searchCommitFilter = string.Empty;
private List<Models.Commit> _searchedCommits = new List<Models.Commit>(); private List<Models.Commit> _searchedCommits = new List<Models.Commit>();

View file

@ -430,7 +430,7 @@ namespace SourceGit.Views
private void OnToggleFilterClicked(object sender, RoutedEventArgs e) private void OnToggleFilterClicked(object sender, RoutedEventArgs e)
{ {
if (DataContext is ViewModels.Repository repo && if (DataContext is ViewModels.Repository repo &&
sender is ToggleButton toggle && sender is ToggleButton toggle &&
toggle.DataContext is ViewModels.BranchTreeNode { Backend: Models.Branch branch } node) toggle.DataContext is ViewModels.BranchTreeNode { Backend: Models.Branch branch } node)
{ {

View file

@ -343,7 +343,7 @@
</Grid> </Grid>
<!-- Commit Search Panel --> <!-- Commit Search Panel -->
<Grid Grid.Row="1" RowDefinitions="24,32,*" Margin="8,0,4,8" IsVisible="{Binding IsSearching}" PropertyChanged="OnSearchCommitPanelPropertyChanged"> <Grid Grid.Row="1" RowDefinitions="26,26,*" Margin="8,0,4,8" IsVisible="{Binding IsSearching}" PropertyChanged="OnSearchCommitPanelPropertyChanged">
<!-- Search Input Box --> <!-- Search Input Box -->
<Grid Grid.Row="0"> <Grid Grid.Row="0">
<TextBox x:Name="TxtSearchCommitsBox" <TextBox x:Name="TxtSearchCommitsBox"
@ -430,18 +430,11 @@
</Popup> </Popup>
</Grid> </Grid>
<Grid Grid.Row="1" ColumnDefinitions="Auto,*"> <StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock Grid.Column="0" <ComboBox MinHeight="24" Height="24"
Text="{DynamicResource Text.Repository.Search.By}" Padding="4,0"
Foreground="{DynamicResource Brush.FG2}" Background="Transparent"
Margin="2,0,0,0"/> BorderThickness="0"
<ComboBox Grid.Column="1"
MinHeight="24" Height="24"
Padding="8,0"
Background="{DynamicResource Brush.Contents}"
BorderBrush="{DynamicResource Brush.Border2}"
HorizontalAlignment="Right"
SelectedIndex="{Binding SearchCommitFilterType, Mode=TwoWay}"> SelectedIndex="{Binding SearchCommitFilterType, Mode=TwoWay}">
<ComboBox.Items> <ComboBox.Items>
<TextBlock Text="{DynamicResource Text.Repository.Search.BySHA}" FontSize="12"/> <TextBlock Text="{DynamicResource Text.Repository.Search.BySHA}" FontSize="12"/>
@ -450,9 +443,17 @@
<TextBlock Text="{DynamicResource Text.Repository.Search.ByFile}" FontSize="12"/> <TextBlock Text="{DynamicResource Text.Repository.Search.ByFile}" FontSize="12"/>
</ComboBox.Items> </ComboBox.Items>
</ComboBox> </ComboBox>
</Grid>
<CheckBox Height="24"
Margin="4,0,0,0"
FontSize="12"
Content="{DynamicResource Text.Repository.Search.InCurrentBranch}"
IsChecked="{Binding OnlySearchCommitsInCurrentBranch, Mode=TwoWay}"
IsVisible="{Binding SearchCommitFilterType, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"/>
</StackPanel>
<ListBox Grid.Row="2" <ListBox Grid.Row="2"
Margin="0,8,0,0"
ItemsSource="{Binding SearchedCommits}" ItemsSource="{Binding SearchedCommits}"
SelectionMode="Single" SelectionMode="Single"
SelectedItem="{Binding SearchResultSelectedCommit, Mode=TwoWay}" SelectedItem="{Binding SearchResultSelectedCommit, Mode=TwoWay}"