Commits

Mark Heath  committed 06341a0

got mercurial repository drawing working

  • Participants
  • Parent commits c6a2b9d

Comments (0)

Files changed (4)

File GraphPad/GraphPad.csproj

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

File GraphPad/Logic/GraphLayoutEngine.cs

                 if (col > 0 && grid[row, col - 1] == false)
                 {
                     // 1. work out min column
-                    int minColumn = n.Parents.Max(p => p.GetColumn()) + 1;
+                    int minColumn = n.Parents.Count() > 0 ? n.Parents.Max(p => p.GetColumn()) + 1 : 0;
                     // 2. see if any space is free to left
                     // not sure whether to go forward or back here
                     for (int newCol = minColumn; newCol < col; newCol++)

File GraphPad/Logic/MercurialGraphBuilder.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Mercurial;
+
+namespace GraphPad.Logic
+{
+    class MercurialGraphBuilder
+    {
+        public Graph LoadGraph(string mercurialRepoPath)
+        {
+            var repo = new Repository(mercurialRepoPath);
+            var graph = new Graph();
+
+            // create the nodes
+            foreach (var commit in repo.Log())
+            {
+                var node = new Node();
+                node.Name = commit.RevisionNumber.ToString();
+                node.MetaData["Author"] = commit.AuthorName;
+                node.MetaData["Email"] = commit.AuthorEmailAddress;
+                node.MetaData["Timestamp"] = commit.Timestamp;
+                node.MetaData["Message"] = commit.CommitMessage;
+                graph.Nodes.Add(node);
+            }
+
+            // add the relationships
+            foreach (var commit in repo.Log())
+            {
+                var node = graph.Nodes.Where(n => n.Name == commit.RevisionNumber.ToString()).First();
+                if (commit.LeftParentRevision != -1)
+                {
+                    var parentNode = graph.Nodes.Where(n => n.Name == commit.LeftParentRevision.ToString()).First();
+                    parentNode.AddChild(node);
+                }
+                // bug in the hg lib? - for some reason, is often 0
+                if (commit.RightParentRevision > 0)
+                {
+                    var parentNode = graph.Nodes.Where(n => n.Name == commit.RightParentRevision.ToString()).First();
+                    parentNode.AddChild(node);
+                }
+            }
+
+            // put in the branch, bookmark, tag pointers
+
+            return graph;
+        }
+    }
+}

File GraphPad/MainWindow.xaml.cs

             InitializeComponent();
             this.graphText.TextChanged += new TextChangedEventHandler(graphText_TextChanged);
             this.buttonGit.Click += new RoutedEventHandler(buttonGit_Click);
+            this.buttonMercurial.Click += new RoutedEventHandler(buttonMercurial_Click);
+        }
+
+        void buttonMercurial_Click(object sender, RoutedEventArgs e)
+        {
+            var dialog = new System.Windows.Forms.FolderBrowserDialog();
+            dialog.Description = "Select Mercurial repository";
+            var result = dialog.ShowDialog();
+            if (result == System.Windows.Forms.DialogResult.OK)
+            {
+                var builder = new MercurialGraphBuilder();
+                var graph = builder.LoadGraph(dialog.SelectedPath);
+                RedrawGraph(graph);
+            }
         }
 
         void buttonGit_Click(object sender, RoutedEventArgs e)