From dacbaabbb3bd8d976adec4b156f4c098aa51eac7 Mon Sep 17 00:00:00 2001 From: Haacked Date: Thu, 8 Oct 2015 15:32:55 -0700 Subject: [PATCH] Fix crash with repository with one commit Efficient Sugiyama crashes if we have a single commit repository. So we use "CompoundFDP" when there's only one commit. The original attempt to fix this, 50ca739aaadd7249f864d17cae060b1a27e22029, had a bug where we never changed the algorithm back to Efficient Sugiyama. This fixes that. --- SeeGitApp/Models/RepositoryGraphBuilder.cs | 11 ++++++++--- SeeGitApp/ViewModels/MainWindowViewModel.cs | 5 +---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/SeeGitApp/Models/RepositoryGraphBuilder.cs b/SeeGitApp/Models/RepositoryGraphBuilder.cs index 0e463c4..650a0e4 100644 --- a/SeeGitApp/Models/RepositoryGraphBuilder.cs +++ b/SeeGitApp/Models/RepositoryGraphBuilder.cs @@ -49,7 +49,13 @@ public RepositoryGraph Graph() AddBranchReferences(); AddHeadReference(); - _graph.LayoutAlgorithmType = App.LayoutAlgorithm; + // Efficient Sugiyama crashes if we have a single commit repository. So we start with CompoundFDP. + // The original attempt to fix this, 50ca739aaadd7249f864d17cae060b1a27e22029, had a bug where we never + // changed the algorithm back to Efficient Sugiyama. This fixes that. + _graph.LayoutAlgorithmType = + _graph.VertexCount == 1 + ? "CompoundFDP" + : App.LayoutAlgorithm; return _graph; } @@ -130,12 +136,11 @@ private void AddCommitsToGraph(Commit commit, CommitVertex childVertex) // KeyValuePair is faster than a Tuple in this case. // We create as many instances as we pass to the AddCommitToGraph. Queue queue = new Queue(); - CommitWithChildVertex commitIter; queue.Enqueue(new CommitWithChildVertex(commit, childVertex)); while (queue.Count != 0) { - commitIter = queue.Dequeue(); + var commitIter = queue.Dequeue(); if (!AddCommitToGraph(commitIter.Key, commitIter.Value)) continue; diff --git a/SeeGitApp/ViewModels/MainWindowViewModel.cs b/SeeGitApp/ViewModels/MainWindowViewModel.cs index d01b0ef..26dc410 100644 --- a/SeeGitApp/ViewModels/MainWindowViewModel.cs +++ b/SeeGitApp/ViewModels/MainWindowViewModel.cs @@ -62,11 +62,8 @@ public void MonitorRepository(string repositoryWorkingPath) _graphBuilder = _graphBuilderThunk(gitPath); RepositoryPath = Directory.GetParent(gitPath).FullName; - var graph = _graphBuilder.Graph(); - if (graph.VertexCount > 1) - graph.LayoutAlgorithmType = App.LayoutAlgorithm; - Graph = graph; + Graph = _graphBuilder.Graph(); if (!Directory.Exists(gitPath)) MonitorForRepositoryCreation(RepositoryPath);