From 3c0711d25ac5731737e8a54e746715d2e517ad0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20W?= Date: Sat, 22 Aug 2026 11:30:29 +0200 Subject: [PATCH 1/5] Refactor: move relevant code to new method Histories.RecalculateMergeState() --- src/Models/CommitGraph.cs | 20 +------------------- src/ViewModels/Histories.cs | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/Models/CommitGraph.cs b/src/Models/CommitGraph.cs index 8557f271d..03ffb8c86 100644 --- a/src/Models/CommitGraph.cs +++ b/src/Models/CommitGraph.cs @@ -70,7 +70,7 @@ public class Dot public List Links { get; } = []; public List Dots { get; } = []; - public static CommitGraph Generate(List commits, bool recalculateMergeState, bool firstParentOnlyEnabled, CommitGraphHighlighting highlighting, HashSet highlightExtraCommits) + public static CommitGraph Generate(List commits, bool firstParentOnlyEnabled, CommitGraphHighlighting highlighting, HashSet highlightExtraCommits) { const double unitWidth = 12; const double halfWidth = 6; @@ -82,29 +82,11 @@ public static CommitGraph Generate(List commits, bool recalculateMergeSt var ended = new List(); var offsetY = -halfHeight; var colorPicker = new ColorPicker(); - var merged = new HashSet(); foreach (var commit in commits) { PathHelper major = null; - // Update merge state of this commit. - if (recalculateMergeState) - { - if (commit.IsMerged) - { - merged.Remove(commit.SHA); - foreach (var p in commit.Parents) - merged.Add(p); - } - else if (merged.Remove(commit.SHA)) - { - commit.IsMerged = true; - foreach (var p in commit.Parents) - merged.Add(p); - } - } - // Update current y offset offsetY += unitHeight; diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 15cf15748..7f8333737 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -75,7 +75,8 @@ public List Commits get => _commits; set { - GenerateGraph(value, true); + RecalculateMergeState(value); + GenerateGraph(value); if (SetProperty(ref _commits, value)) PostCommitsChanged(); } @@ -510,7 +511,28 @@ private void PostSelectedCommitsChanged() GenerateGraph(_commits); } - private void GenerateGraph(List commits, bool commitsChanged = false) + private void RecalculateMergeState(List commits) + { + var merged = new HashSet(); + + foreach (var commit in commits) + { + if (commit.IsMerged) + { + merged.Remove(commit.SHA); + foreach (var p in commit.Parents) + merged.Add(p); + } + else if (merged.Remove(commit.SHA)) + { + commit.IsMerged = true; + foreach (var p in commit.Parents) + merged.Add(p); + } + } + } + + private void GenerateGraph(List commits) { var firstParentOnly = _repo.UIStates.HistoryShowFlags.HasFlag(Models.HistoryShowFlags.FirstParentOnly); var highlighting = _repo.UIStates.GraphHighlighting; @@ -522,7 +544,7 @@ private void GenerateGraph(List commits, bool commitsChanged = fa extraHeads.Add(c.SHA); } - Graph = Models.CommitGraph.Generate(commits, commitsChanged, firstParentOnly, highlighting, extraHeads); + Graph = Models.CommitGraph.Generate(commits, firstParentOnly, highlighting, extraHeads); } private Repository _repo = null; From 2c0182835e57989a42aaf052463e781e4d1d0ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20W?= Date: Sun, 23 Aug 2026 20:24:24 +0200 Subject: [PATCH 2/5] Reduce redundant code in RecalculateMergeState() --- src/ViewModels/Histories.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 7f8333737..a4a52e116 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -517,15 +517,11 @@ private void RecalculateMergeState(List commits) foreach (var commit in commits) { + if (merged.Remove(commit.SHA)) + commit.IsMerged = true; + if (commit.IsMerged) { - merged.Remove(commit.SHA); - foreach (var p in commit.Parents) - merged.Add(p); - } - else if (merged.Remove(commit.SHA)) - { - commit.IsMerged = true; foreach (var p in commit.Parents) merged.Add(p); } From 99c257b82aa476519a993730734f580652669846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20W?= Date: Sat, 22 Aug 2026 13:41:48 +0200 Subject: [PATCH 3/5] Reduce redundant highlighting-code by modifying if-conditions --- src/Models/CommitGraph.cs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Models/CommitGraph.cs b/src/Models/CommitGraph.cs index 03ffb8c86..139d74a98 100644 --- a/src/Models/CommitGraph.cs +++ b/src/Models/CommitGraph.cs @@ -146,11 +146,17 @@ public static CommitGraph Generate(List commits, bool firstParentOnlyEna { isHighlighted = true; } - else if (highlighting == CommitGraphHighlighting.CurrentBranchOnly) + + if (!isHighlighted && + (highlighting == CommitGraphHighlighting.CurrentBranchOnly || + highlighting == CommitGraphHighlighting.CurrentBranchAndSelectedCommits)) { isHighlighted = commit.IsMerged; } - else if (highlighting == CommitGraphHighlighting.SelectedCommitsOnly) + + if (!isHighlighted && + (highlighting == CommitGraphHighlighting.SelectedCommitsOnly || + highlighting == CommitGraphHighlighting.CurrentBranchAndSelectedCommits)) { isHighlighted = highlightExtraCommits.Remove(commit.SHA); if (isHighlighted) @@ -159,19 +165,6 @@ public static CommitGraph Generate(List commits, bool firstParentOnlyEna highlightExtraCommits.Add(p); } } - else - { - if (commit.IsMerged) - { - isHighlighted = true; - } - else if (highlightExtraCommits.Remove(commit.SHA)) - { - isHighlighted = true; - foreach (var p in commit.Parents) - highlightExtraCommits.Add(p); - } - } } commit.IsHighlightedInGraph = isHighlighted; From 81dbfa5fc3af57b23aaea55ab25a77895992a3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20W?= Date: Sat, 22 Aug 2026 11:45:37 +0200 Subject: [PATCH 4/5] Highlight first parent separately for "extra" commits * The remaining parents are covered further down (under condition '!firstParentOnlyEnabled'). * This is made in prep for upcoming work on adding a new highlighting option. --- src/Models/CommitGraph.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Models/CommitGraph.cs b/src/Models/CommitGraph.cs index 139d74a98..ccc14126a 100644 --- a/src/Models/CommitGraph.cs +++ b/src/Models/CommitGraph.cs @@ -159,11 +159,9 @@ public static CommitGraph Generate(List commits, bool firstParentOnlyEna highlighting == CommitGraphHighlighting.CurrentBranchAndSelectedCommits)) { isHighlighted = highlightExtraCommits.Remove(commit.SHA); - if (isHighlighted) - { - foreach (var p in commit.Parents) - highlightExtraCommits.Add(p); - } + // Highlight first parent, other parents are dealt with later + if (isHighlighted && commit.Parents.Count > 0) + highlightExtraCommits.Add(commit.Parents[0]); } } commit.IsHighlightedInGraph = isHighlighted; From 3ede80629d555d30abadedc674e9e299725fdbc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20W?= Date: Sat, 22 Aug 2026 13:50:50 +0200 Subject: [PATCH 5/5] Add new graph-highlight option "Selected Commits (only first-parent)" --- src/Models/CommitGraph.cs | 5 +++++ src/Resources/Locales/en_US.axaml | 1 + src/Views/Repository.axaml.cs | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/Models/CommitGraph.cs b/src/Models/CommitGraph.cs index ccc14126a..f2c821c36 100644 --- a/src/Models/CommitGraph.cs +++ b/src/Models/CommitGraph.cs @@ -13,6 +13,7 @@ public enum CommitGraphHighlighting All = 0, CurrentBranchOnly, SelectedCommitsOnly, + SelectedCommitsOnlyFirstParent, CurrentBranchAndSelectedCommits, } @@ -156,6 +157,7 @@ public static CommitGraph Generate(List commits, bool firstParentOnlyEna if (!isHighlighted && (highlighting == CommitGraphHighlighting.SelectedCommitsOnly || + highlighting == CommitGraphHighlighting.SelectedCommitsOnlyFirstParent || highlighting == CommitGraphHighlighting.CurrentBranchAndSelectedCommits)) { isHighlighted = highlightExtraCommits.Remove(commit.SHA); @@ -200,6 +202,9 @@ public static CommitGraph Generate(List commits, bool firstParentOnlyEna // Deal with other parents (the first parent has been processed) if (!firstParentOnlyEnabled) { + if (highlighting == CommitGraphHighlighting.SelectedCommitsOnlyFirstParent) + isHighlighted = false; + for (int j = 1; j < commit.Parents.Count; j++) { var parentHash = commit.Parents[j]; diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 2d589bbec..6932a0c02 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -518,6 +518,7 @@ Current Branch Only Current Branch & Selected Commits Selected Commits Only + Selected Commits (only first-parent) SELECTED {0} COMMITS SHOW COLUMNS Hold 'Ctrl' or 'Shift' to select multiple commits. diff --git a/src/Views/Repository.axaml.cs b/src/Views/Repository.axaml.cs index f5bac41d8..ecee53c52 100644 --- a/src/Views/Repository.axaml.cs +++ b/src/Views/Repository.axaml.cs @@ -487,6 +487,16 @@ private void OnOpenAdvancedHistoriesOption(object sender, RoutedEventArgs e) ev.Handled = true; }; + var selectedCommitsOnlyFirstParent = new MenuItem(); + selectedCommitsOnlyFirstParent.Header = App.Text("Histories.HighlightsInGraph.SelectedCommitsOnlyFirstParent"); + if (histories.GraphHighlighting == Models.CommitGraphHighlighting.SelectedCommitsOnlyFirstParent) + selectedCommitsOnlyFirstParent.Icon = this.CreateMenuIcon("Icons.Check"); + selectedCommitsOnlyFirstParent.Click += (_, ev) => + { + histories.GraphHighlighting = Models.CommitGraphHighlighting.SelectedCommitsOnlyFirstParent; + ev.Handled = true; + }; + var currentBranchAndSelectedCommits = new MenuItem(); currentBranchAndSelectedCommits.Header = App.Text("Histories.HighlightsInGraph.CurrentBranchAndSelectedCommits"); if (histories.GraphHighlighting == Models.CommitGraphHighlighting.CurrentBranchAndSelectedCommits) @@ -516,6 +526,7 @@ private void OnOpenAdvancedHistoriesOption(object sender, RoutedEventArgs e) menu.Items.Add(all); menu.Items.Add(currentBranchOnly); menu.Items.Add(selectedCommitsOnly); + menu.Items.Add(selectedCommitsOnlyFirstParent); menu.Items.Add(currentBranchAndSelectedCommits); menu.Open(button); }