Skip to content

Commit

Permalink
Fixes 5880: Reorder nodes correct
Browse files Browse the repository at this point in the history
  • Loading branch information
spdr870 committed Dec 11, 2018
1 parent 022e8e1 commit b182d27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 7 additions & 7 deletions GitUI/UserControls/RevisionGrid/Graph/RevisionGraphRevision.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using GitCommands;
using GitUIPluginInterfaces;
Expand Down Expand Up @@ -64,20 +65,19 @@ public int EnsureScoreIsAbove(int minimalScore)

int maxScore = Score;

var processed = new HashSet<RevisionGraphRevision>();

var stack = new Stack<RevisionGraphRevision>();
stack.Push(this);
processed.Add(this);
while (stack.Count > 0)
{
var revision = stack.Pop();

foreach (var parent in revision.Parents.Where(r => r.Score < maxScore + 1 && !processed.Contains(r)))
foreach (var parent in revision.Parents.Where(r => r.Score <= revision.Score))
{
parent.Score = maxScore + 1;
maxScore = parent.Score;
processed.Add(parent);
parent.Score = revision.Score + 1;

Debug.Assert(parent.Score > revision.Score, "Reorder score failed.");

maxScore = Math.Max(parent.Score, maxScore);
stack.Push(parent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,18 @@ private void LoadRandomRevisions()
GitRevision revision = new GitRevision(ObjectId.Random());
if (randomRevisions.Count > 1)
{
revision.ParentIds = new ObjectId[] { randomRevisions[_random.Next(randomRevisions.Count - 1)].ObjectId };
var randomRevision1 = randomRevisions[_random.Next(randomRevisions.Count - 1)];
var randomRevision2 = randomRevisions[_random.Next(randomRevisions.Count - 1)];

revision.ParentIds = new ObjectId[] { randomRevision1.ObjectId, randomRevision2.ObjectId };
}

_revisionGraph.Add(revision, RevisionNodeFlags.None);

randomRevisions.Add(revision);
}

Assert.IsTrue(_revisionGraph.GetTestAccessor().ValidateTopoOrder());
Assert.IsTrue(_revisionGraph.GetTestAccessor().ValidateTopoOrder(), "Revisions not reordered to topo order");
}

private void BuildCache()
Expand Down

0 comments on commit b182d27

Please sign in to comment.