Commits

Mark Heath committed ab22183

initial Git graph builder

Comments (0)

Files changed (3)

GraphPad.Tests/GraphLayoutEngineTests.cs

             AssertNodeIsOnRow(g, "g", 1);
         }
 
+        // failing test, work out how to deal with this
+        [Test]
+        public void CanLayoutAGraphWithMultipleRootNodes()
+        {
+            GraphLayoutEngine l = new GraphLayoutEngine();
+            Graph g = (new GraphBuilder()).GenerateGraph("a-b-c\na-c\nd-e-f");
+            l.Layout(g);
+        }
+
         //  test ideas
         // a-b-c-d\na-e-f-g\nb-h-i-j (should push first branch down?)
 

GraphPad/GraphPad.csproj

     <Compile Include="Gui\ArrowLineBase.cs" />
     <Compile Include="Gui\ArrowEnds.cs" />
     <Compile Include="Gui\ArrowPolyline.cs" />
+    <Compile Include="Logic\GitGraphBuilder.cs" />
     <Compile Include="Logic\Grid.cs" />
     <Compile Include="Logic\NodeExtensions.cs" />
     <Compile Include="Logic\Connection.cs" />

GraphPad/Logic/GitGraphBuilder.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using LibGit2Sharp;
+
+namespace GraphPad.Logic
+{
+    class GitGraphBuilder
+    {
+        public Graph LoadGraph(string gitRepoPath)
+        {
+            var repo = new Repository(gitRepoPath);
+            var graph = new Graph();
+
+            // create the nodes
+            foreach (var commit in repo.Commits)
+            {
+                var node = new Node();
+                node.Name = commit.Sha;
+                node.MetaData["Author"] = commit.Author.Name;
+                node.MetaData["Email"] = commit.Author.Email;
+                node.MetaData["Timestamp"] = commit.Author.When;
+                node.MetaData["Message"] = commit.Message;
+                graph.Nodes.Add(node);
+            }
+
+            // add the relationships
+            foreach (var commit in repo.Commits)
+            {
+                var node = graph.Nodes.Where(n => n.Name == commit.Sha).First();
+                foreach (var parent in commit.Parents)
+                {
+                    var parentNode = graph.Nodes.Where(n => n.Name == parent.Sha).First();
+                    parentNode.AddChild(node);
+                }
+            }
+
+            // put in the branch pointers
+
+            return graph;
+        }
+    }
+}