@@ -70,7 +70,7 @@ public class Dot
7070 public List < Link > Links { get ; } = [ ] ;
7171 public List < Dot > Dots { get ; } = [ ] ;
7272
73- public static CommitGraph Generate ( List < Commit > commits , bool firstParentOnlyEnabled , CommitGraphHighlighting highlighting , HashSet < string > highlightExtraCommits )
73+ public static CommitGraph Generate ( List < Commit > commits , bool recalculateMergeState , bool firstParentOnlyEnabled , CommitGraphHighlighting highlighting , HashSet < string > highlightExtraCommits )
7474 {
7575 const double unitWidth = 12 ;
7676 const double halfWidth = 6 ;
@@ -89,60 +89,29 @@ public static CommitGraph Generate(List<Commit> commits, bool firstParentOnlyEna
8989 PathHelper major = null ;
9090
9191 // Update merge state of this commit.
92- if ( commit . IsMerged )
93- {
94- merged . Remove ( commit . SHA ) ;
95- foreach ( var p in commit . Parents )
96- merged . Add ( p ) ;
97- }
98- else if ( merged . Remove ( commit . SHA ) )
99- {
100- commit . IsMerged = true ;
101- foreach ( var p in commit . Parents )
102- merged . Add ( p ) ;
103- }
104-
105- // Calculate highlighted state
106- var isHighlighted = false ;
107- if ( highlighting == CommitGraphHighlighting . All )
108- {
109- isHighlighted = true ;
110- }
111- else if ( highlighting == CommitGraphHighlighting . CurrentBranchOnly )
112- {
113- isHighlighted = commit . IsMerged ;
114- }
115- else if ( highlighting == CommitGraphHighlighting . SelectedCommitsOnly )
116- {
117- isHighlighted = highlightExtraCommits . Remove ( commit . SHA ) ;
118- if ( isHighlighted )
119- {
120- commit . IsHighlightedInGraph = true ;
121- foreach ( var p in commit . Parents )
122- highlightExtraCommits . Add ( p ) ;
123- }
124- }
125- else
92+ if ( recalculateMergeState )
12693 {
12794 if ( commit . IsMerged )
12895 {
129- isHighlighted = true ;
96+ merged . Remove ( commit . SHA ) ;
97+ foreach ( var p in commit . Parents )
98+ merged . Add ( p ) ;
13099 }
131- else if ( highlightExtraCommits . Remove ( commit . SHA ) )
100+ else if ( merged . Remove ( commit . SHA ) )
132101 {
133- isHighlighted = true ;
102+ commit . IsMerged = true ;
134103 foreach ( var p in commit . Parents )
135- highlightExtraCommits . Add ( p ) ;
104+ merged . Add ( p ) ;
136105 }
137106 }
138- commit . IsHighlightedInGraph = isHighlighted ;
139107
140108 // Update current y offset
141109 offsetY += unitHeight ;
142110
143111 // Find first curves that links to this commit and marks others that links to this commit ended.
144112 var offsetX = 4 - halfWidth ;
145113 var maxOffsetOld = unsolved . Count > 0 ? unsolved [ ^ 1 ] . LastX : offsetX + unitWidth ;
114+ var isHighlighted = false ;
146115 foreach ( var l in unsolved )
147116 {
148117 if ( l . Next . Equals ( commit . SHA , StringComparison . Ordinal ) )
@@ -151,6 +120,7 @@ public static CommitGraph Generate(List<Commit> commits, bool firstParentOnlyEna
151120 {
152121 offsetX += unitWidth ;
153122 major = l ;
123+ isHighlighted = major . IsHighlighted ;
154124
155125 if ( commit . Parents . Count > 0 )
156126 {
@@ -167,6 +137,9 @@ public static CommitGraph Generate(List<Commit> commits, bool firstParentOnlyEna
167137 {
168138 l . End ( major . LastX , offsetY , halfHeight ) ;
169139 ended . Add ( l ) ;
140+
141+ if ( ! isHighlighted && l . IsHighlighted )
142+ isHighlighted = true ;
170143 }
171144 }
172145 else
@@ -184,6 +157,42 @@ public static CommitGraph Generate(List<Commit> commits, bool firstParentOnlyEna
184157 }
185158 ended . Clear ( ) ;
186159
160+ // Calculate highlighted state
161+ if ( ! isHighlighted )
162+ {
163+ if ( highlighting == CommitGraphHighlighting . All )
164+ {
165+ isHighlighted = true ;
166+ }
167+ else if ( highlighting == CommitGraphHighlighting . CurrentBranchOnly )
168+ {
169+ isHighlighted = commit . IsMerged ;
170+ }
171+ else if ( highlighting == CommitGraphHighlighting . SelectedCommitsOnly )
172+ {
173+ isHighlighted = highlightExtraCommits . Remove ( commit . SHA ) ;
174+ if ( isHighlighted )
175+ {
176+ foreach ( var p in commit . Parents )
177+ highlightExtraCommits . Add ( p ) ;
178+ }
179+ }
180+ else
181+ {
182+ if ( commit . IsMerged )
183+ {
184+ isHighlighted = true ;
185+ }
186+ else if ( highlightExtraCommits . Remove ( commit . SHA ) )
187+ {
188+ isHighlighted = true ;
189+ foreach ( var p in commit . Parents )
190+ highlightExtraCommits . Add ( p ) ;
191+ }
192+ }
193+ }
194+ commit . IsHighlightedInGraph = isHighlighted ;
195+
187196 // If no path found, create new curve for branch head
188197 // Otherwise, create new curve for new merged commit
189198 if ( major == null )
0 commit comments