Skip to content

Commit 91b4784

Browse files
committed
Merge pull request haacked#80 from Haacked/fix-layout-crash
Fix crash with repository with one commit
2 parents 2b2622e + dacbaab commit 91b4784

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

SeeGitApp/Models/RepositoryGraphBuilder.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ public RepositoryGraph Graph()
4949
AddBranchReferences();
5050
AddHeadReference();
5151

52-
_graph.LayoutAlgorithmType = App.LayoutAlgorithm;
52+
// Efficient Sugiyama crashes if we have a single commit repository. So we start with CompoundFDP.
53+
// The original attempt to fix this, 50ca739aaadd7249f864d17cae060b1a27e22029, had a bug where we never
54+
// changed the algorithm back to Efficient Sugiyama. This fixes that.
55+
_graph.LayoutAlgorithmType =
56+
_graph.VertexCount == 1
57+
? "CompoundFDP"
58+
: App.LayoutAlgorithm;
5359
return _graph;
5460
}
5561

@@ -130,12 +136,11 @@ private void AddCommitsToGraph(Commit commit, CommitVertex childVertex)
130136
// KeyValuePair is faster than a Tuple in this case.
131137
// We create as many instances as we pass to the AddCommitToGraph.
132138
Queue<CommitWithChildVertex> queue = new Queue<CommitWithChildVertex>();
133-
CommitWithChildVertex commitIter;
134139
queue.Enqueue(new CommitWithChildVertex(commit, childVertex));
135140

136141
while (queue.Count != 0)
137142
{
138-
commitIter = queue.Dequeue();
143+
var commitIter = queue.Dequeue();
139144
if (!AddCommitToGraph(commitIter.Key, commitIter.Value))
140145
continue;
141146

SeeGitApp/ViewModels/MainWindowViewModel.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ public void MonitorRepository(string repositoryWorkingPath)
6262

6363
_graphBuilder = _graphBuilderThunk(gitPath);
6464
RepositoryPath = Directory.GetParent(gitPath).FullName;
65-
var graph = _graphBuilder.Graph();
6665

67-
if (graph.VertexCount > 1)
68-
graph.LayoutAlgorithmType = App.LayoutAlgorithm;
69-
Graph = graph;
66+
Graph = _graphBuilder.Graph();
7067

7168
if (!Directory.Exists(gitPath))
7269
MonitorForRepositoryCreation(RepositoryPath);

0 commit comments

Comments
 (0)