Skip to content

Commit fe015f9

Browse files
committed
fix: endpoint of a graph path has been added twice (#528)
1 parent c7332af commit fe015f9

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

src/Models/CommitGraph.cs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
146146

147147
var temp = new CommitGraph();
148148
var unsolved = new List<PathHelper>();
149-
var mapUnsolved = new Dictionary<string, PathHelper>();
150149
var ended = new List<PathHelper>();
151150
var offsetY = -HALF_HEIGHT;
152151
var colorIdx = 0;
@@ -174,19 +173,17 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
174173
if (commit.Parents.Count > 0)
175174
{
176175
major.Next = commit.Parents[0];
177-
if (!mapUnsolved.ContainsKey(major.Next))
178-
mapUnsolved.Add(major.Next, major);
176+
major.Add(offsetX, offsetY, HALF_HEIGHT);
179177
}
180178
else
181179
{
182-
major.Next = "ENDED";
180+
major.Add(offsetX, offsetY, HALF_HEIGHT, true);
183181
ended.Add(l);
184182
}
185-
186-
major.Add(offsetX, offsetY, HALF_HEIGHT);
187183
}
188184
else
189185
{
186+
l.Add(major.LastX, offsetY, HALF_HEIGHT, true);
190187
ended.Add(l);
191188
}
192189

@@ -195,13 +192,16 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
195192
}
196193
else
197194
{
198-
if (!mapUnsolved.ContainsKey(l.Next))
199-
mapUnsolved.Add(l.Next, l);
200195
offsetX += UNIT_WIDTH;
201196
l.Add(offsetX, offsetY, HALF_HEIGHT);
202197
}
203198
}
204199

200+
// Remove ended curves from unsolved
201+
foreach (var l in ended)
202+
unsolved.Remove(l);
203+
ended.Clear();
204+
205205
// Create new curve for branch head
206206
if (major == null)
207207
{
@@ -218,13 +218,8 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
218218
}
219219

220220
// Calculate link position of this commit.
221-
Point position = new Point(offsetX, offsetY);
222-
int dotColor = 0;
223-
if (major != null)
224-
{
225-
position = new Point(major.LastX, offsetY);
226-
dotColor = major.Path.Color;
227-
}
221+
Point position = new Point(major?.LastX ?? offsetX, offsetY);
222+
int dotColor = major?.Path.Color ?? 0;
228223
Dot anchor = new Dot() { Center = position, Color = dotColor };
229224
if (commit.IsCurrentHead)
230225
anchor.Type = DotType.Head;
@@ -239,11 +234,12 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
239234
{
240235
for (int j = 1; j < commit.Parents.Count; j++)
241236
{
242-
var parent = commit.Parents[j];
243-
if (mapUnsolved.TryGetValue(parent, out var value))
237+
var parentSHA = commit.Parents[j];
238+
var parent = unsolved.Find(x => x.Next.Equals(parentSHA, StringComparison.Ordinal));
239+
if (parent != null)
244240
{
245241
// Try to change the merge state of linked graph
246-
var l = value;
242+
var l = parent;
247243
if (isMerged)
248244
l.IsMerged = true;
249245

@@ -260,28 +256,17 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
260256
offsetX += UNIT_WIDTH;
261257

262258
// Create new curve for parent commit that not includes before
263-
var l = new PathHelper(parent, isMerged, colorIdx, position, new Point(offsetX, position.Y + HALF_HEIGHT));
259+
var l = new PathHelper(parentSHA, isMerged, colorIdx, position, new Point(offsetX, position.Y + HALF_HEIGHT));
264260
unsolved.Add(l);
265261
temp.Paths.Add(l.Path);
266262
colorIdx = (colorIdx + 1) % _penCount;
267263
}
268264
}
269265
}
270266

271-
// Remove ended curves from unsolved
272-
foreach (var l in ended)
273-
{
274-
l.Add(position.X, position.Y, HALF_HEIGHT, true);
275-
unsolved.Remove(l);
276-
}
277-
278267
// Margins & merge state (used by Views.Histories).
279268
commit.IsMerged = isMerged;
280269
commit.Margin = new Thickness(Math.Max(offsetX + HALF_WIDTH, oldCount * UNIT_WIDTH + H_MARGIN) + H_MARGIN, 0, 0, 0);
281-
282-
// Clean up
283-
ended.Clear();
284-
mapUnsolved.Clear();
285270
}
286271

287272
// Deal with curves haven't ended yet.

0 commit comments

Comments
 (0)