Skip to content

Commit febb6ee

Browse files
committed
feat: Mark "filter commit" in the view to Make the UI experience better
- Add commit filtering by SHA patterns and track filtered head commits. - Add property to track if commit is a filter head in commit model. - Add filter support to commit graph by introducing a new DotType and handling filter head commits. - Enhance commit querying by adding support for solo commit filters in the history view. - Add new filter dot type visualization to the commit graph.
1 parent 0db270b commit febb6ee

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

src/Commands/QueryCommits.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text;
45
using System.Threading.Tasks;
56

67
namespace SourceGit.Commands
78
{
89
public class QueryCommits : Command
910
{
10-
public QueryCommits(string repo, string limits, bool needFindHead = true)
11+
public QueryCommits(string repo, string limits, bool needFindHead = true, List<string> patterns = null)
1112
{
1213
WorkingDirectory = repo;
1314
Context = repo;
1415
Args = $"log --no-show-signature --decorate=full --format=%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s {limits}";
1516
_findFirstMerged = needFindHead;
17+
_patterns = patterns ?? new List<string>();
1618
}
1719

1820
public QueryCommits(string repo, string filter, Models.CommitSearchMethod method, bool onlyCurrentBranch)
@@ -70,6 +72,7 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method
7072
{
7173
case 0:
7274
_current = new Models.Commit() { SHA = line };
75+
_current.IsCommitFilterHead = _patterns.Count > 0 && _patterns.Any(f => line.StartsWith(f));
7376
_commits.Add(_current);
7477
break;
7578
case 1:
@@ -143,6 +146,7 @@ private async Task MarkFirstMergedAsync()
143146
}
144147

145148
private List<Models.Commit> _commits = new List<Models.Commit>();
149+
private List<string> _patterns = new List<string>();
146150
private Models.Commit _current = null;
147151
private bool _findFirstMerged = false;
148152
private bool _isHeadFound = false;

src/Models/Commit.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static double OpacityForNotMerged
4242
public string AuthorTimeShortStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Active.DateOnly);
4343
public string CommitterTimeShortStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(DateTimeFormat.Active.DateOnly);
4444

45+
public bool IsCommitFilterHead { get; set; } = false;
4546
public bool IsMerged { get; set; } = false;
4647
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
4748
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;

src/Models/CommitGraph.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public enum DotType
5353
Default,
5454
Head,
5555
Merge,
56+
Filter,
5657
}
5758

5859
public class Dot
@@ -157,7 +158,9 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
157158
var position = new Point(major?.LastX ?? offsetX, offsetY);
158159
var dotColor = major?.Path.Color ?? 0;
159160
var anchor = new Dot() { Center = position, Color = dotColor, IsMerged = isMerged };
160-
if (commit.IsCurrentHead)
161+
if (commit.IsCommitFilterHead)
162+
anchor.Type = DotType.Filter;
163+
else if (commit.IsCurrentHead)
161164
anchor.Type = DotType.Head;
162165
else if (commit.Parents.Count > 1)
163166
anchor.Type = DotType.Merge;

src/ViewModels/Repository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,9 @@ public void RefreshCommits()
13421342
else
13431343
builder.Append(filters);
13441344

1345-
var commits = new Commands.QueryCommits(_fullpath, builder.ToString()).GetResultAsync().Result;
1345+
var patterns = _settings.HistoriesFilters.Where(f => f.Type == Models.FilterType.SoloCommits).Select(f => f.Pattern).ToList();
1346+
1347+
var commits = new Commands.QueryCommits(_fullpath, builder.ToString(), true, patterns).GetResultAsync().Result;
13461348
var graph = Models.CommitGraph.Parse(commits, _settings.HistoryShowFlags.HasFlag(Models.HistoryShowFlags.FirstParentOnly));
13471349

13481350
Dispatcher.UIThread.Invoke(() =>

src/Views/CommitGraph.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
230230
context.DrawLine(dotFillPen, new Point(center.X, center.Y - 3), new Point(center.X, center.Y + 3));
231231
context.DrawLine(dotFillPen, new Point(center.X - 3, center.Y), new Point(center.X + 3, center.Y));
232232
break;
233+
case Models.CommitGraph.DotType.Filter:
234+
context.DrawEllipse(pen.Brush, null, center, 7, 7);
235+
context.DrawLine(dotFillPen, new Point(center.X, center.Y - 5), new Point(center.X, center.Y + 5));
236+
context.DrawLine(dotFillPen, new Point(center.X - 4, center.Y - 3), new Point(center.X + 4, center.Y + 3));
237+
context.DrawLine(dotFillPen, new Point(center.X + 4, center.Y - 3), new Point(center.X - 4, center.Y + 3));
238+
break;
233239
default:
234240
context.DrawEllipse(dotFill, pen, center, 3, 3);
235241
break;

0 commit comments

Comments
 (0)