Skip to content

Commit 8e7bfc4

Browse files
committed
enhance: search commits by message (#256)
1 parent 3aad24a commit 8e7bfc4

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/App.JsonCodeGen.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Text.Json;
43
using System.Text.Json.Serialization;
54

src/Commands/QueryCommits.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Text;
34

45
namespace SourceGit.Commands
56
{
@@ -9,10 +10,27 @@ public QueryCommits(string repo, string limits, bool needFindHead = true)
910
{
1011
WorkingDirectory = repo;
1112
Context = repo;
12-
Args = $"log --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 " + limits;
13+
Args = "log --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 " + limits;
1314
_findFirstMerged = needFindHead;
1415
}
1516

17+
public QueryCommits(string repo, int maxCount, string messageFilter)
18+
{
19+
var argsBuilder = new StringBuilder();
20+
var words = messageFilter.Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries);
21+
foreach (var word in words)
22+
{
23+
var escaped = word.Trim().Replace("\"", "\\\"", StringComparison.Ordinal);
24+
argsBuilder.Append($"--grep=\"{escaped}\" ");
25+
}
26+
argsBuilder.Append("--all-match");
27+
28+
WorkingDirectory = repo;
29+
Context = repo;
30+
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 " + argsBuilder.ToString();
31+
_findFirstMerged = false;
32+
}
33+
1634
public List<Models.Commit> Result()
1735
{
1836
var rs = ReadToEnd();

src/ViewModels/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ public void StartSearchCommits()
566566

567567
break;
568568
case 2:
569-
visible = new Commands.QueryCommits(FullPath, $"-1000 --grep=\"{_searchCommitFilter}\"", false).Result();
569+
visible = new Commands.QueryCommits(FullPath, 1000, _searchCommitFilter).Result();
570570
break;
571571
case 3:
572572
visible = new Commands.QueryCommits(FullPath, $"-1000 -- \"{_searchCommitFilter}\"", false).Result();

0 commit comments

Comments
 (0)