Skip to content
Closed
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
6 changes: 6 additions & 0 deletions src/Converters/FilterModeConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ public static class FilterModeConverters
_ => Brushes.Transparent,
};
});

public static readonly FuncValueConverter<Models.CommitGraphHighlighting, bool> HighlightModeToIsAllBright =
new FuncValueConverter<Models.CommitGraphHighlighting, bool>(v =>
{
return v == Models.CommitGraphHighlighting.All;
});
}
}
12 changes: 11 additions & 1 deletion src/Models/Commit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;

namespace SourceGit.Models
Expand All @@ -13,6 +13,14 @@ public enum CommitSearchMethod
ByContent,
}

public enum CommitLineageSearchMethod
{
None = 0,
ParentsOnly = 1,
ChildsOnly = 2,
FullLineage = 3,
}

public class Commit
{
public string SHA { get; set; } = string.Empty;
Expand All @@ -27,6 +35,8 @@ public class Commit
public bool IsMerged { get; set; } = false;
public int Color { get; set; } = 0;
public double LeftMargin { get; set; } = 0;
public int Index { get; set; } = -1;
public int PathIndex { get; set; } = -1;

public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
Expand Down
62 changes: 53 additions & 9 deletions src/Models/CommitGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

namespace SourceGit.Models
{
public enum CommitGraphHighlighting
{
All,
CurrentBranchOnly,
SelectedLineageOnly,
CurrentBranchAndSelectedLineage,
}

public record CommitGraphLayout(double StartY, double ClipWidth, double RowHeight);

public class CommitGraph
Expand All @@ -32,6 +40,9 @@ public class Path(int color, bool isMerged)
public List<Point> Points { get; } = [];
public int Color { get; } = color;
public bool IsMerged { get; } = isMerged;
public bool IsHoveredRelated { get; set; } = false;
public int StartCommitIndex { get; set; } = -1;
public int EndCommitIndex { get; set; } = -1;
}

public class Link
Expand All @@ -41,6 +52,8 @@ public class Link
public Point End;
public int Color;
public bool IsMerged;
public int StartCommitIndex;
public int EndCommitIndex;
}

public enum DotType
Expand Down Expand Up @@ -75,6 +88,13 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
var offsetY = -halfHeight;
var colorPicker = new ColorPicker();

var commitMap = new Dictionary<string, int>();
for (int i = 0; i < commits.Count; i++)
{
commits[i].Index = i;
commitMap[commits[i].SHA] = i;
}

foreach (var commit in commits)
{
PathHelper major = null;
Expand Down Expand Up @@ -103,12 +123,14 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
else
{
major.End(offsetX, offsetY, halfHeight);
major.Path.EndCommitIndex = commit.Index;
ended.Add(l);
}
}
else
{
l.End(major.LastX, offsetY, halfHeight);
l.Path.EndCommitIndex = commit.Index;
ended.Add(l);
}

Expand Down Expand Up @@ -137,16 +159,27 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable

if (commit.Parents.Count > 0)
{
major = new PathHelper(commit.Parents[0], isMerged, colorPicker.Next(), new Point(offsetX, offsetY));
major = new PathHelper(commit.Parents[0], isMerged, colorPicker.Next(), new Point(offsetX, offsetY), commit.Index);
unsolved.Add(major);
temp.Paths.Add(major.Path);
}
}
else if (isMerged && !major.IsMerged && commit.Parents.Count > 0)
{
major.ReplaceMerged();
major.Path.EndCommitIndex = commit.Index;
major.ReplaceMerged(commit.Index);
temp.Paths.Add(major.Path);
}
else if (major != null && commit.Parents.Count > 0)
{
// Break at every commit to ensure path-aware highlight is precise.
major.Path.EndCommitIndex = commit.Index;
major.Replace(major.Path.Color, major.Path.IsMerged, commit.Index);
temp.Paths.Add(major.Path);
}

if (major != null)
commit.PathIndex = temp.Paths.IndexOf(major.Path);

// Calculate link position of this commit.
var position = new Point(major?.LastX ?? offsetX, offsetY);
Expand All @@ -172,7 +205,8 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
if (isMerged && !parent.IsMerged)
{
parent.Goto(parent.LastX, offsetY + halfHeight, halfHeight);
parent.ReplaceMerged();
parent.Path.EndCommitIndex = commit.Index;
parent.ReplaceMerged(commit.Index);
temp.Paths.Add(parent.Path);
}

Expand All @@ -183,14 +217,16 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
Control = new Point(parent.LastX, position.Y),
Color = parent.Path.Color,
IsMerged = isMerged,
StartCommitIndex = commit.Index,
EndCommitIndex = commitMap.GetValueOrDefault(parentHash, -1),
});
}
else
{
offsetX += unitWidth;

// Create new curve for parent commit that not includes before
var l = new PathHelper(parentHash, isMerged, colorPicker.Next(), position, new Point(offsetX, position.Y + halfHeight));
var l = new PathHelper(parentHash, isMerged, colorPicker.Next(), position, new Point(offsetX, position.Y + halfHeight), commit.Index);
unsolved.Add(l);
temp.Paths.Add(l.Path);
}
Expand All @@ -213,6 +249,7 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
continue;

path.End((i + 0.5) * unitWidth + 4, endY + halfHeight, halfHeight);
path.Path.EndCommitIndex = commits.Count - 1;
}
unsolved.Clear();

Expand Down Expand Up @@ -249,17 +286,18 @@ private class PathHelper

public bool IsMerged => Path.IsMerged;

public PathHelper(string next, bool isMerged, int color, Point start)
public PathHelper(string next, bool isMerged, int color, Point start, int startCommitIndex)
{
Next = next;
LastX = start.X;
_lastY = start.Y;

Path = new Path(color, isMerged);
Path.Points.Add(start);
Path.StartCommitIndex = startCommitIndex;
}

public PathHelper(string next, bool isMerged, int color, Point start, Point to)
public PathHelper(string next, bool isMerged, int color, Point start, Point to, int startCommitIndex)
{
Next = next;
LastX = to.X;
Expand All @@ -268,6 +306,7 @@ public PathHelper(string next, bool isMerged, int color, Point start, Point to)
Path = new Path(color, isMerged);
Path.Points.Add(start);
Path.Points.Add(to);
Path.StartCommitIndex = startCommitIndex;
}

/// <summary>
Expand Down Expand Up @@ -348,16 +387,21 @@ public void End(double x, double y, double halfHeight)
/// <summary>
/// End the current path and create a new from the end.
/// </summary>
public void ReplaceMerged()
public void Replace(int newColor, bool isMerged, int startCommitIndex)
{
var color = Path.Color;
Add(LastX, _lastY);

Path = new Path(color, true);
Path = new Path(newColor, isMerged);
Path.Points.Add(new Point(LastX, _lastY));
Path.StartCommitIndex = startCommitIndex;
_endY = 0;
}

public void ReplaceMerged(int startCommitIndex)
{
Replace(Path.Color, true, startCommitIndex);
}

private void Add(double x, double y)
{
if (_endY < y)
Expand Down
10 changes: 8 additions & 2 deletions src/Models/RepositoryUIStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ public bool EnableTopoOrderInHistory
set;
} = false;

public bool OnlyHighlightCurrentBranchInHistory
public CommitGraphHighlighting CommitGraphHighlighting
{
get;
set;
} = false;
} = CommitGraphHighlighting.All;

public CommitLineageSearchMethod LineageSearchMethod
{
get;
set;
} = CommitLineageSearchMethod.FullLineage;

public BranchSortMode LocalBranchSortMode
{
Expand Down
19 changes: 15 additions & 4 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@
<x:String x:Key="Text.Compare.Commits.Tips" xml:space="preserve">Tips: You can cherry-pick selected commits if the other side is HEAD (using context menu).</x:String>
<x:String x:Key="Text.Configure" xml:space="preserve">Repository Configure</x:String>
<x:String x:Key="Text.Configure.CommitMessageTemplate" xml:space="preserve">COMMIT TEMPLATE</x:String>
<x:String x:Key="Text.Configure.CommitMessageTemplate.BuiltinVars" xml:space="preserve">Built-in parameters:
<x:String x:Key="Text.Configure.CommitMessageTemplate.BuiltinVars" xml:space="preserve">Built-in parameters:

${branch_name} Current local branch name.
${files_num} Number of changed files
${files} Paths of changed files
Expand All @@ -218,8 +218,8 @@
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">Template Name:</x:String>
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">CUSTOM ACTION</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">Arguments:</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">Built-in parameters:
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">Built-in parameters:

${REPO} Repository's path
${REMOTE} Selected remote or selected branch's remote
${BRANCH} Selected branch, without ${REMOTE} part for remote branches
Expand Down Expand Up @@ -491,6 +491,15 @@
<x:String x:Key="Text.Histories.Header.CommitTime" xml:space="preserve">COMMIT TIME</x:String>
<x:String x:Key="Text.Histories.Header.DateTime" xml:space="preserve">DATE TIME</x:String>
<x:String x:Key="Text.Histories.Header.GraphAndSubject" xml:space="preserve">GRAPH &amp; SUBJECT</x:String>
<x:String x:Key="Text.Histories.Header.Highlights" xml:space="preserve">Highlighting Mode</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.All" xml:space="preserve">Show All</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchOnly" xml:space="preserve">Current Branch Only</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.SelectedLineageOnly" xml:space="preserve">Selected Lineage Only</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchAndSelectedLineage" xml:space="preserve">Current Branch &amp; Selected Lineage</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.LineageMethod" xml:space="preserve">Lineage Search Method</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.LineageMethod.ParentsOnly" xml:space="preserve">Ancestors Only</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.LineageMethod.ChildsOnly" xml:space="preserve">Descendants Only</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.LineageMethod.FullLineage" xml:space="preserve">Full Lineage</x:String>
<x:String x:Key="Text.Histories.Header.SHA" xml:space="preserve">SHA</x:String>
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">SELECTED {0} COMMITS</x:String>
<x:String x:Key="Text.Histories.ShowColumns" xml:space="preserve">SHOW COLUMNS</x:String>
Expand Down Expand Up @@ -641,6 +650,7 @@
<x:String x:Key="Text.Preferences.Appearance.Theme" xml:space="preserve">Theme</x:String>
<x:String x:Key="Text.Preferences.Appearance.ThemeOverrides" xml:space="preserve">Theme Overrides</x:String>
<x:String x:Key="Text.Preferences.Appearance.UseAutoHideScrollBars" xml:space="preserve">Use auto-hide scrollbars</x:String>
<x:String x:Key="Text.Preferences.Appearance.EnableHoverViewTracking" xml:space="preserve">Enable hover view tracking</x:String>
<x:String x:Key="Text.Preferences.Appearance.UseFixedTabWidth" xml:space="preserve">Use fixed tab width in titlebar</x:String>
<x:String x:Key="Text.Preferences.Appearance.UseNativeWindowFrame" xml:space="preserve">Use native window frame</x:String>
<x:String x:Key="Text.Preferences.DiffMerge" xml:space="preserve">DIFF/MERGE TOOL</x:String>
Expand Down Expand Up @@ -782,6 +792,7 @@
<x:String x:Key="Text.Repository.NewBranch" xml:space="preserve">Create Branch</x:String>
<x:String x:Key="Text.Repository.Notifications.Clear" xml:space="preserve">CLEAR NOTIFICATIONS</x:String>
<x:String x:Key="Text.Repository.OnlyHighlightCurrentBranchInGraph" xml:space="preserve">Only highlight current branch</x:String>
<x:String x:Key="Text.Repository.HighlightSelectedLineageInGraph" xml:space="preserve">Highlight selected commit lineage</x:String>
<x:String x:Key="Text.Repository.OpenAsFolder" xml:space="preserve">Open as Folder</x:String>
<x:String x:Key="Text.Repository.OpenIn" xml:space="preserve">Open in {0}</x:String>
<x:String x:Key="Text.Repository.OpenWithExternalTools" xml:space="preserve">Open in External Tools</x:String>
Expand Down
15 changes: 13 additions & 2 deletions src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<x:String x:Key="Text.Configure" xml:space="preserve">仓库配置</x:String>
<x:String x:Key="Text.Configure.CommitMessageTemplate" xml:space="preserve">提交信息模板</x:String>
<x:String x:Key="Text.Configure.CommitMessageTemplate.BuiltinVars" xml:space="preserve">内置变量:

${branch_name} 当前分支名
${files_num} 变更文件数量
${files} 变更文件路径列表
Expand All @@ -223,7 +223,7 @@
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">自定义操作</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">命令行参数 :</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">内置变量:

${REPO} 仓库路径
${REMOTE} 选中的远程仓库或选中分支所属的远程仓库
${BRANCH} 选中的分支,对于远程分支不包含远程名
Expand Down Expand Up @@ -495,6 +495,15 @@
<x:String x:Key="Text.Histories.Header.CommitTime" xml:space="preserve">提交时间</x:String>
<x:String x:Key="Text.Histories.Header.DateTime" xml:space="preserve">日期时间</x:String>
<x:String x:Key="Text.Histories.Header.GraphAndSubject" xml:space="preserve">路线图与主题</x:String>
<x:String x:Key="Text.Histories.Header.Highlights" xml:space="preserve">高亮模式</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.All" xml:space="preserve">全部显示</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchOnly" xml:space="preserve">仅当前分支</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.SelectedLineageOnly" xml:space="preserve">仅选中谱系</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchAndSelectedLineage" xml:space="preserve">当前分支与选中谱系</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.LineageMethod" xml:space="preserve">谱系搜索方式</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.LineageMethod.ParentsOnly" xml:space="preserve">仅祖先</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.LineageMethod.ChildsOnly" xml:space="preserve">仅后代</x:String>
<x:String x:Key="Text.Histories.Header.Highlights.LineageMethod.FullLineage" xml:space="preserve">完整谱系</x:String>
<x:String x:Key="Text.Histories.Header.SHA" xml:space="preserve">提交指纹</x:String>
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">已选中 {0} 项提交</x:String>
<x:String x:Key="Text.Histories.ShowColumns" xml:space="preserve">显示列</x:String>
Expand Down Expand Up @@ -645,6 +654,7 @@
<x:String x:Key="Text.Preferences.Appearance.Theme" xml:space="preserve">主题</x:String>
<x:String x:Key="Text.Preferences.Appearance.ThemeOverrides" xml:space="preserve">主题自定义</x:String>
<x:String x:Key="Text.Preferences.Appearance.UseAutoHideScrollBars" xml:space="preserve">允许滚动条自动隐藏</x:String>
<x:String x:Key="Text.Preferences.Appearance.EnableHoverViewTracking" xml:space="preserve">开启悬停视图跟踪</x:String>
<x:String x:Key="Text.Preferences.Appearance.UseFixedTabWidth" xml:space="preserve">主标签使用固定宽度</x:String>
<x:String x:Key="Text.Preferences.Appearance.UseNativeWindowFrame" xml:space="preserve">使用系统默认窗体样式</x:String>
<x:String x:Key="Text.Preferences.DiffMerge" xml:space="preserve">对比/合并工具</x:String>
Expand Down Expand Up @@ -786,6 +796,7 @@
<x:String x:Key="Text.Repository.NewBranch" xml:space="preserve">新建分支</x:String>
<x:String x:Key="Text.Repository.Notifications.Clear" xml:space="preserve">清空通知列表</x:String>
<x:String x:Key="Text.Repository.OnlyHighlightCurrentBranchInGraph" xml:space="preserve">仅高亮显示当前分支</x:String>
<x:String x:Key="Text.Repository.HighlightSelectedLineageInGraph" xml:space="preserve">高亮显示所选提交的血缘关系</x:String>
<x:String x:Key="Text.Repository.OpenAsFolder" xml:space="preserve">本仓库(文件夹)</x:String>
<x:String x:Key="Text.Repository.OpenIn" xml:space="preserve">在 {0} 中打开</x:String>
<x:String x:Key="Text.Repository.OpenWithExternalTools" xml:space="preserve">使用外部工具打开</x:String>
Expand Down
Loading