Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Commands/QueryCommits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method
{
builder.Append("-i --author=").Append(filter.Quoted());
}
else if (method == Models.CommitSearchMethod.ByCommitter)
{
builder.Append("-i --committer=").Append(filter.Quoted());
}
else if (method == Models.CommitSearchMethod.ByMessage)
{
var words = filter.Split([' ', '\t', '\r'], StringSplitOptions.RemoveEmptyEntries);
Expand Down
7 changes: 6 additions & 1 deletion src/Models/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

namespace SourceGit.Models
{
// Bound by index to the search-method ComboBox in Views/Repository.axaml, so
// UI-selectable methods must stay first and in dropdown order. ByCommitter is
// internal-only (used by the fulltext `All` search).
public enum CommitSearchMethod
{
BySHA = 0,
All = 0,
BySHA,
ByAuthor,
ByMessage,
ByPath,
ByContent,
ByCommitter,
}

public class Commit : ObservableObject
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@
<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.Search" xml:space="preserve">Search Commit</x:String>
<x:String x:Key="Text.Repository.Search.ByAll" xml:space="preserve">SHA/Author/Message</x:String>
<x:String x:Key="Text.Repository.Search.ByAuthor" xml:space="preserve">Author</x:String>
<x:String x:Key="Text.Repository.Search.ByContent" xml:space="preserve">Content</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Message</x:String>
Expand Down
76 changes: 62 additions & 14 deletions src/ViewModels/SearchCommitContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,21 @@ public void StartSearch()
result.Add(commit);
}
}
else if (_onlySearchCurrentBranch)
{
result = await new Commands.QueryCommits(repoPath, _filter, method, true)
.GetResultAsync()
.ConfigureAwait(false);

foreach (var c in result)
c.IsMerged = true;
}
else
{
result = await new Commands.QueryCommits(repoPath, _filter, method, false)
.GetResultAsync()
.ConfigureAwait(false);
if (method == Models.CommitSearchMethod.All)
result = await SearchAllFieldsAsync(repoPath).ConfigureAwait(false);
else
result = await new Commands.QueryCommits(repoPath, _filter, method, _onlySearchCurrentBranch)
.GetResultAsync()
.ConfigureAwait(false);

if (result.Count > 0)
if (_onlySearchCurrentBranch)
{
foreach (var c in result)
c.IsMerged = true;
}
else if (result.Count > 0)
{
var set = await new Commands.QueryCurrentBranchCommitHashes(repoPath, result[^1].CommitterTime)
.GetResultAsync()
Expand All @@ -171,6 +170,55 @@ public void StartSearch()
}, token);
}

private async Task<List<Models.Commit>> SearchAllFieldsAsync(string repoPath)
{
var result = new List<Models.Commit>();
var seen = new HashSet<string>();

var isCommitSHA = await new Commands.IsCommitSHA(repoPath, _filter)
.GetResultAsync()
.ConfigureAwait(false);

if (isCommitSHA)
{
var commit = await new Commands.QuerySingleCommit(repoPath, _filter)
.GetResultAsync()
.ConfigureAwait(false);

var matchesScope = commit != null;
if (matchesScope && _onlySearchCurrentBranch)
matchesScope = await new Commands.IsAncestor(repoPath, commit.SHA, "HEAD")
.GetResultAsync()
.ConfigureAwait(false);

if (matchesScope && seen.Add(commit.SHA))
result.Add(commit);
}

var fields = new[]
{
Models.CommitSearchMethod.ByMessage,
Models.CommitSearchMethod.ByAuthor,
Models.CommitSearchMethod.ByCommitter,
};

foreach (var field in fields)
{
var matched = await new Commands.QueryCommits(repoPath, _filter, field, _onlySearchCurrentBranch)
.GetResultAsync()
.ConfigureAwait(false);

foreach (var c in matched)
{
if (seen.Add(c.SHA))
result.Add(c);
}
}

result.Sort((l, r) => r.CommitterTime.CompareTo(l.CommitterTime));
return result;
}

public void EndSearch()
{
if (_cancellation is { IsCancellationRequested: false })
Expand Down Expand Up @@ -287,7 +335,7 @@ private void UpdateSuggestions()

private Repository _repo = null;
private CancellationTokenSource _cancellation = null;
private int _method = (int)Models.CommitSearchMethod.ByMessage;
private int _method = (int)Models.CommitSearchMethod.All;
private string _filter = string.Empty;
private bool _onlySearchCurrentBranch = false;
private bool _isQuerying = false;
Expand Down
3 changes: 2 additions & 1 deletion src/Views/Repository.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@
BorderThickness="0"
SelectedIndex="{Binding SearchCommitContext.Method, Mode=TwoWay}">
<ComboBox.Items>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByAll}"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.BySHA}"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByAuthor}"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByMessage}"/>
Expand All @@ -628,7 +629,7 @@
<CheckBox Height="24"
Margin="4,0,0,0"
IsChecked="{Binding SearchCommitContext.OnlySearchCurrentBranch, Mode=TwoWay}"
IsVisible="{Binding SearchCommitContext.Method, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
IsVisible="{Binding SearchCommitContext.Method, Converter={x:Static c:IntConverters.IsNotOne}}">
<TextBlock Text="{DynamicResource Text.Repository.Search.InCurrentBranch}"/>
</CheckBox>
</StackPanel>
Expand Down