From 70d5067904721e91de4a8d912371973bd25c1b19 Mon Sep 17 00:00:00 2001 From: Srix Date: Thu, 8 May 2014 21:34:45 +0530 Subject: [PATCH 1/4] used platform independent path separator Path.DirectorySeparatorChar. Clicking the Generate button repeatedly doesnot crash applciation. --- GitVersionTree/Forms/MainForm.cs | 764 ++++++++++++++++--------------- 1 file changed, 386 insertions(+), 378 deletions(-) diff --git a/GitVersionTree/Forms/MainForm.cs b/GitVersionTree/Forms/MainForm.cs index c1a55af..7b394f1 100644 --- a/GitVersionTree/Forms/MainForm.cs +++ b/GitVersionTree/Forms/MainForm.cs @@ -1,378 +1,386 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; -using System.Diagnostics; -using System.Collections; -using System.IO; - -namespace GitVersionTree -{ - public partial class MainForm : Form - { - private Dictionary DecorateDictionary = new Dictionary(); - private List> Nodes = new List>(); - - private string DotFilename = Directory.GetParent(Application.ExecutablePath) + @"\" + Application.ProductName + ".dot"; - private string PdfFilename = Directory.GetParent(Application.ExecutablePath) + @"\" + Application.ProductName + ".pdf"; - private string LogFilename = Directory.GetParent(Application.ExecutablePath) + @"\" + Application.ProductName + ".log"; - string RepositoryName; - - public MainForm() - { - InitializeComponent(); - } - - private void MainForm_Load(object sender, EventArgs e) - { - Text = Application.ProductName + " - v" + Application.ProductVersion.Substring(0, 3); - - RefreshPath(); - } - - private void GitPathBrowseButton_Click(object sender, EventArgs e) - { - OpenFileDialog BrowseOpenFileDialog = new OpenFileDialog(); - BrowseOpenFileDialog.Title = "Select git.exe"; - if (!String.IsNullOrEmpty(Reg.Read("GitPath"))) - { - BrowseOpenFileDialog.InitialDirectory = Reg.Read("GitPath"); - } - BrowseOpenFileDialog.FileName = "git.exe"; - BrowseOpenFileDialog.Filter = "Git Application (git.exe)|git.exe"; - if (BrowseOpenFileDialog.ShowDialog() == DialogResult.OK) - { - Reg.Write("GitPath", BrowseOpenFileDialog.FileName); - RefreshPath(); - } - } - - private void GraphvizDotPathBrowseButton_Click(object sender, EventArgs e) - { - OpenFileDialog BrowseOpenFileDialog = new OpenFileDialog(); - BrowseOpenFileDialog.Title = "Select dot.exe"; - if (!String.IsNullOrEmpty(Reg.Read("GraphvizPath"))) - { - BrowseOpenFileDialog.InitialDirectory = Reg.Read("GraphvizPath"); - } - BrowseOpenFileDialog.FileName = "dot.exe"; - BrowseOpenFileDialog.Filter = "Graphviz Dot Application (dot.exe)|dot.exe"; - if (BrowseOpenFileDialog.ShowDialog() == DialogResult.OK) - { - Reg.Write("GraphvizPath", BrowseOpenFileDialog.FileName); - RefreshPath(); - } - } - - private void GitRepositoryPathBrowseButton_Click(object sender, EventArgs e) - { - FolderBrowserDialog BrowseFolderBrowserDialog = new FolderBrowserDialog(); - BrowseFolderBrowserDialog.Description = "Select Git repository"; - BrowseFolderBrowserDialog.ShowNewFolderButton = false; - if (!String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) - { - BrowseFolderBrowserDialog.SelectedPath = Reg.Read("GitRepositoryPath"); - } - if (BrowseFolderBrowserDialog.ShowDialog() == DialogResult.OK) - { - Reg.Write("GitRepositoryPath", BrowseFolderBrowserDialog.SelectedPath); - RefreshPath(); - } - } - - private void GenerateButton_Click(object sender, EventArgs e) - { - if (String.IsNullOrEmpty(Reg.Read("GitPath")) || - String.IsNullOrEmpty(Reg.Read("GraphvizPath")) || - String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) - { - MessageBox.Show("Please select a Git, Graphviz & Git repository.", "Generate", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - else - { - StatusRichTextBox.Text = ""; - RepositoryName = new DirectoryInfo(GitRepositoryPathTextBox.Text).Name; - DotFilename = Directory.GetParent(Application.ExecutablePath) + @"\" + RepositoryName + ".dot"; - PdfFilename = Directory.GetParent(Application.ExecutablePath) + @"\" + RepositoryName + ".pdf"; - LogFilename = Directory.GetParent(Application.ExecutablePath) + @"\" + RepositoryName + ".log"; - File.WriteAllText(LogFilename, ""); - Generate(); - } - } - - private void HomepageLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - Process.Start("https://github.com/crc8/GitVersionTree"); - } - - private void ExitButton_Click(object sender, EventArgs e) - { - Close(); - } - - private void RefreshPath() - { - if (!String.IsNullOrEmpty(Reg.Read("GitPath"))) - { - GitPathTextBox.Text = Reg.Read("GitPath"); - } - if (!String.IsNullOrEmpty(Reg.Read("GraphvizPath"))) - { - GraphvizDotPathTextBox.Text = Reg.Read("GraphvizPath"); - } - if (!String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) - { - GitRepositoryPathTextBox.Text = Reg.Read("GitRepositoryPath"); - } - } - - private void Status(string Message) - { - StatusRichTextBox.AppendText(DateTime.Now + " - " + Message + "\r\n"); - StatusRichTextBox.SelectionStart = StatusRichTextBox.Text.Length; - StatusRichTextBox.ScrollToCaret(); - Refresh(); - } - - private string Execute(string Command, string Argument) - { - string ExecuteResult = String.Empty; - Process ExecuteProcess = new Process(); - ExecuteProcess.StartInfo.UseShellExecute = false; - ExecuteProcess.StartInfo.CreateNoWindow = true; - ExecuteProcess.StartInfo.RedirectStandardOutput = true; - ExecuteProcess.StartInfo.FileName = Command; - ExecuteProcess.StartInfo.Arguments = Argument; - ExecuteProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - ExecuteProcess.Start(); - ExecuteResult = ExecuteProcess.StandardOutput.ReadToEnd(); - ExecuteProcess.WaitForExit(); - if (ExecuteProcess.ExitCode == 0) - { - return ExecuteResult; - } - else - { - return String.Empty; - } - } - - private void Generate() - { - string Result; - string[] MergedColumns; - string[] MergedParents; - - Status("Getting git commit(s) ..."); - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + "\\.git\" log --all --pretty=format:\"%h|%p|%d\""); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get get branch or branch empty ..."); - } - else - { - File.AppendAllText(LogFilename, "[commit(s)]\r\n"); - File.AppendAllText(LogFilename, Result + "\r\n"); - string[] DecorateLines = Result.Split('\n'); - foreach (string DecorateLine in DecorateLines) - { - MergedColumns = DecorateLine.Split('|'); - if (!String.IsNullOrEmpty(MergedColumns[2])) - { - DecorateDictionary.Add(MergedColumns[0], MergedColumns[2]); - } - } - Status("Processed " + DecorateDictionary.Count + " decorate(s) ..."); - } - - Status("Getting git ref branch(es) ..."); - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + "\\.git\" for-each-ref --format=\"%(objectname:short)|%(refname:short)\" "); //refs/heads/ - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get get branch or branch empty ..."); - } - else - { - File.AppendAllText(LogFilename, "[ref branch(es)]\r\n"); - File.AppendAllText(LogFilename, Result + "\r\n"); - string[] RefLines = Result.Split('\n'); - foreach (string RefLine in RefLines) - { - if (!String.IsNullOrEmpty(RefLine)) - { - string[] RefColumns = RefLine.Split('|'); - if (!RefColumns[1].ToLower().StartsWith("refs/tags")) - if (RefColumns[1].ToLower().Contains("master")) - { - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + "\\.git\" log --reverse --first-parent --pretty=format:\"%h\" " + RefColumns[0]); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get commit(s) ..."); - } - else - { - string[] HashLines = Result.Split('\n'); - Nodes.Add(new List()); - foreach (string HashLine in HashLines) - { - Nodes[Nodes.Count - 1].Add(HashLine); - } - } - } - } - } - foreach (string RefLine in RefLines) - { - if (!String.IsNullOrEmpty(RefLine)) - { - string[] RefColumns = RefLine.Split('|'); - if (!RefColumns[1].ToLower().StartsWith("refs/tags")) - if (!RefColumns[1].ToLower().Contains("master")) - { - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + "\\.git\" log --reverse --first-parent --pretty=format:\"%h\" " + RefColumns[0]); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get commit(s) ..."); - } - else - { - string[] HashLines = Result.Split('\n'); - Nodes.Add(new List()); - foreach (string HashLine in HashLines) - { - Nodes[Nodes.Count - 1].Add(HashLine); - } - } - } - } - } - } - - Status("Getting git merged branch(es) ..."); - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + "\\.git\" log --all --merges --pretty=format:\"%h|%p\""); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get get branch or branch empty ..."); - } - else - { - File.AppendAllText(LogFilename, "[merged branch(es)]\r\n"); - File.AppendAllText(LogFilename, Result + "\r\n"); - string[] MergedLines = Result.Split('\n'); - foreach (string MergedLine in MergedLines) - { - MergedColumns = MergedLine.Split('|'); - MergedParents = MergedColumns[1].Split(' '); - if (MergedParents.Length > 1) - { - for (int i = 1; i < MergedParents.Length; i++) - { - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + "\\.git\" log --reverse --first-parent --pretty=format:\"%h\" " + MergedParents[i]); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get commit(s) ..."); - } - else - { - string[] HashLines = Result.Split('\n'); - Nodes.Add(new List()); - foreach (string HashLine in HashLines) - { - Nodes[Nodes.Count - 1].Add(HashLine); - } - Nodes[Nodes.Count - 1].Add(MergedColumns[0]); - } - } - } - } - } - - Status("Processed " + Nodes.Count + " branch(es) ..."); - - StringBuilder DotStringBuilder = new StringBuilder(); - Status("Generating dot file ..."); - DotStringBuilder.Append("strict digraph \"" + RepositoryName + "\" {\r\n"); - //DotStringBuilder.Append(" splines=line;\r\n"); - for (int i = 0; i < Nodes.Count; i++) - { - DotStringBuilder.Append(" node[group=\"" + (i + 1) + "\"];\r\n"); - DotStringBuilder.Append(" "); - for (int j = 0; j < Nodes[i].Count; j++) - { - DotStringBuilder.Append("\"" + Nodes[i][j] + "\""); - if (j < Nodes[i].Count - 1) - { - DotStringBuilder.Append(" -> "); - } - else - { - DotStringBuilder.Append(";"); - } - } - DotStringBuilder.Append("\r\n"); - } - - int DecorateCount = 0; - foreach(KeyValuePair DecorateKeyValuePair in DecorateDictionary) - { - DecorateCount++; - DotStringBuilder.Append(" subgraph Decorate" + DecorateCount + "\r\n"); - DotStringBuilder.Append(" {\r\n"); - DotStringBuilder.Append(" rank=\"same\";\r\n"); - if (DecorateKeyValuePair.Value.Trim().Substring(0, 5) == "(tag:") - { - DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" [shape=\"box\", style=\"filled\", fillcolor=\"#ffffdd\"];\r\n"); - } - else - { - DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" [shape=\"box\", style=\"filled\", fillcolor=\"#ddddff\"];\r\n"); - } - DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" -> \"" + DecorateKeyValuePair.Key + "\" [weight=0, arrowtype=\"none\", dirtype=\"none\", arrowhead=\"none\", style=\"dotted\"];\r\n"); - DotStringBuilder.Append(" }\r\n"); - } - - DotStringBuilder.Append("}\r\n"); - File.WriteAllText(@DotFilename, DotStringBuilder.ToString()); - - Status("Generating version tree ..."); - Process DotProcess = new Process(); - DotProcess.StartInfo.UseShellExecute = false; - DotProcess.StartInfo.CreateNoWindow = true; - DotProcess.StartInfo.RedirectStandardOutput = true; - DotProcess.StartInfo.FileName = GraphvizDotPathTextBox.Text; - DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tpdf -Gsize=10,10 -o\"" + @PdfFilename + "\""; - DotProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - DotProcess.Start(); - DotProcess.WaitForExit(); - - DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tps -o\"" + @PdfFilename.Replace(".pdf", ".ps") + "\""; - DotProcess.Start(); - DotProcess.WaitForExit(); - if (DotProcess.ExitCode == 0) - { - if (File.Exists(@PdfFilename)) - { -#if (!DEBUG) - /* - Process ViewPdfProcess = new Process(); - ViewPdfProcess.StartInfo.FileName = @PdfFilename; - ViewPdfProcess.Start(); - //ViewPdfProcess.WaitForExit(); - //Close(); - */ -#endif - } - } - else - { - Status("Version tree generation failed ..."); - } - - Status("Done! ..."); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Diagnostics; +using System.Collections; +using System.IO; + +namespace GitVersionTree +{ + public partial class MainForm : Form + { + private Dictionary DecorateDictionary = new Dictionary(); + private List> Nodes = new List>(); + + private string DotFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + Application.ProductName + ".dot"; + private string PdfFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + Application.ProductName + ".pdf"; + private string LogFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + Application.ProductName + ".log"; + string RepositoryName; + + public MainForm() + { + InitializeComponent(); + } + + private void MainForm_Load(object sender, EventArgs e) + { + Text = Application.ProductName + " - v" + Application.ProductVersion.Substring(0, 3); + + RefreshPath(); + } + + private void GitPathBrowseButton_Click(object sender, EventArgs e) + { + OpenFileDialog BrowseOpenFileDialog = new OpenFileDialog(); + BrowseOpenFileDialog.Title = "Select git.exe"; + if (!String.IsNullOrEmpty(Reg.Read("GitPath"))) + { + BrowseOpenFileDialog.InitialDirectory = Reg.Read("GitPath"); + } + BrowseOpenFileDialog.FileName = "git.exe"; + BrowseOpenFileDialog.Filter = "Git Application (git.exe)|git.exe"; + if (BrowseOpenFileDialog.ShowDialog() == DialogResult.OK) + { + Reg.Write("GitPath", BrowseOpenFileDialog.FileName); + RefreshPath(); + } + } + + private void GraphvizDotPathBrowseButton_Click(object sender, EventArgs e) + { + OpenFileDialog BrowseOpenFileDialog = new OpenFileDialog(); + BrowseOpenFileDialog.Title = "Select dot.exe"; + if (!String.IsNullOrEmpty(Reg.Read("GraphvizPath"))) + { + BrowseOpenFileDialog.InitialDirectory = Reg.Read("GraphvizPath"); + } + BrowseOpenFileDialog.FileName = "dot.exe"; + BrowseOpenFileDialog.Filter = "Graphviz Dot Application (dot.exe)|dot.exe"; + if (BrowseOpenFileDialog.ShowDialog() == DialogResult.OK) + { + Reg.Write("GraphvizPath", BrowseOpenFileDialog.FileName); + RefreshPath(); + } + } + + private void GitRepositoryPathBrowseButton_Click(object sender, EventArgs e) + { + FolderBrowserDialog BrowseFolderBrowserDialog = new FolderBrowserDialog(); + BrowseFolderBrowserDialog.Description = "Select Git repository"; + BrowseFolderBrowserDialog.ShowNewFolderButton = false; + if (!String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) + { + BrowseFolderBrowserDialog.SelectedPath = Reg.Read("GitRepositoryPath"); + } + if (BrowseFolderBrowserDialog.ShowDialog() == DialogResult.OK) + { + Reg.Write("GitRepositoryPath", BrowseFolderBrowserDialog.SelectedPath); + RefreshPath(); + } + } + + private void GenerateButton_Click(object sender, EventArgs e) + { + + DecorateDictionary.Clear(); + Nodes.Clear(); + + if (String.IsNullOrEmpty(Reg.Read("GitPath")) || + String.IsNullOrEmpty(Reg.Read("GraphvizPath")) || + String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) + { + MessageBox.Show("Please select a Git, Graphviz & Git repository.", "Generate", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + StatusRichTextBox.Text = ""; + RepositoryName = new DirectoryInfo(GitRepositoryPathTextBox.Text).Name; + DotFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + RepositoryName + ".dot"; + PdfFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + RepositoryName + ".pdf"; + LogFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + RepositoryName + ".log"; + File.WriteAllText(LogFilename, ""); + Generate(); + } + } + + private void HomepageLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + Process.Start("https://github.com/crc8/GitVersionTree"); + } + + private void ExitButton_Click(object sender, EventArgs e) + { + Close(); + } + + private void RefreshPath() + { + if (!String.IsNullOrEmpty(Reg.Read("GitPath"))) + { + GitPathTextBox.Text = Reg.Read("GitPath"); + } + if (!String.IsNullOrEmpty(Reg.Read("GraphvizPath"))) + { + GraphvizDotPathTextBox.Text = Reg.Read("GraphvizPath"); + } + if (!String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) + { + GitRepositoryPathTextBox.Text = Reg.Read("GitRepositoryPath"); + } + } + + private void Status(string Message) + { + StatusRichTextBox.AppendText(DateTime.Now + " - " + Message + "\r\n"); + StatusRichTextBox.SelectionStart = StatusRichTextBox.Text.Length; + StatusRichTextBox.ScrollToCaret(); + Refresh(); + } + + private string Execute(string Command, string Argument) + { + string ExecuteResult = String.Empty; + Process ExecuteProcess = new Process(); + ExecuteProcess.StartInfo.UseShellExecute = false; + ExecuteProcess.StartInfo.CreateNoWindow = true; + ExecuteProcess.StartInfo.RedirectStandardOutput = true; + ExecuteProcess.StartInfo.FileName = Command; + ExecuteProcess.StartInfo.Arguments = Argument; + ExecuteProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + ExecuteProcess.Start(); + ExecuteResult = ExecuteProcess.StandardOutput.ReadToEnd(); + ExecuteProcess.WaitForExit(); + if (ExecuteProcess.ExitCode == 0) + { + return ExecuteResult; + } + else + { + return String.Empty; + } + } + + private void Generate() + { + string Result; + string[] MergedColumns; + string[] MergedParents; + + Status("Getting git commit(s) ..."); + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --all --pretty=format:\"%h|%p|%d\""); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get get branch or branch empty ..."); + } + else + { + File.AppendAllText(LogFilename, "[commit(s)]\r\n"); + File.AppendAllText(LogFilename, Result + "\r\n"); + string[] DecorateLines = Result.Split('\n'); + foreach (string DecorateLine in DecorateLines) + { + MergedColumns = DecorateLine.Split('|'); + if (!String.IsNullOrEmpty(MergedColumns[2])) + { + DecorateDictionary.Add(MergedColumns[0], MergedColumns[2]); + } + } + Status("Processed " + DecorateDictionary.Count + " decorate(s) ..."); + } + + Status("Getting git ref branch(es) ..."); + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" for-each-ref --format=\"%(objectname:short)|%(refname:short)\" "); //refs/heads/ + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get get branch or branch empty ..."); + } + else + { + File.AppendAllText(LogFilename, "[ref branch(es)]\r\n"); + File.AppendAllText(LogFilename, Result + "\r\n"); + string[] RefLines = Result.Split('\n'); + foreach (string RefLine in RefLines) + { + if (!String.IsNullOrEmpty(RefLine)) + { + string[] RefColumns = RefLine.Split('|'); + if (!RefColumns[1].ToLower().StartsWith("refs/tags")) + if (RefColumns[1].ToLower().Contains("master")) + { + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --reverse --first-parent --pretty=format:\"%h\" " + RefColumns[0]); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get commit(s) ..."); + } + else + { + string[] HashLines = Result.Split('\n'); + Nodes.Add(new List()); + foreach (string HashLine in HashLines) + { + Nodes[Nodes.Count - 1].Add(HashLine); + } + } + } + } + } + foreach (string RefLine in RefLines) + { + if (!String.IsNullOrEmpty(RefLine)) + { + string[] RefColumns = RefLine.Split('|'); + if (!RefColumns[1].ToLower().StartsWith("refs/tags")) + if (!RefColumns[1].ToLower().Contains("master")) + { + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --reverse --first-parent --pretty=format:\"%h\" " + RefColumns[0]); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get commit(s) ..."); + } + else + { + string[] HashLines = Result.Split('\n'); + Nodes.Add(new List()); + foreach (string HashLine in HashLines) + { + Nodes[Nodes.Count - 1].Add(HashLine); + } + } + } + } + } + } + + Status("Getting git merged branch(es) ..."); + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar + ".git\" log --all --merges --pretty=format:\"%h|%p\""); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get get branch or branch empty ..."); + } + else + { + File.AppendAllText(LogFilename, "[merged branch(es)]\r\n"); + File.AppendAllText(LogFilename, Result + "\r\n"); + string[] MergedLines = Result.Split('\n'); + foreach (string MergedLine in MergedLines) + { + MergedColumns = MergedLine.Split('|'); + MergedParents = MergedColumns[1].Split(' '); + if (MergedParents.Length > 1) + { + for (int i = 1; i < MergedParents.Length; i++) + { + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --reverse --first-parent --pretty=format:\"%h\" " + MergedParents[i]); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get commit(s) ..."); + } + else + { + string[] HashLines = Result.Split('\n'); + Nodes.Add(new List()); + foreach (string HashLine in HashLines) + { + Nodes[Nodes.Count - 1].Add(HashLine); + } + Nodes[Nodes.Count - 1].Add(MergedColumns[0]); + } + } + } + } + } + + Status("Processed " + Nodes.Count + " branch(es) ..."); + + StringBuilder DotStringBuilder = new StringBuilder(); + Status("Generating dot file ..."); + DotStringBuilder.Append("strict digraph \"" + RepositoryName + "\" {\r\n"); + //DotStringBuilder.Append(" splines=line;\r\n"); + for (int i = 0; i < Nodes.Count; i++) + { + DotStringBuilder.Append(" node[group=\"" + (i + 1) + "\"];\r\n"); + DotStringBuilder.Append(" "); + for (int j = 0; j < Nodes[i].Count; j++) + { + DotStringBuilder.Append("\"" + Nodes[i][j] + "\""); + if (j < Nodes[i].Count - 1) + { + DotStringBuilder.Append(" -> "); + } + else + { + DotStringBuilder.Append(";"); + } + } + DotStringBuilder.Append("\r\n"); + } + + int DecorateCount = 0; + foreach(KeyValuePair DecorateKeyValuePair in DecorateDictionary) + { + DecorateCount++; + DotStringBuilder.Append(" subgraph Decorate" + DecorateCount + "\r\n"); + DotStringBuilder.Append(" {\r\n"); + DotStringBuilder.Append(" rank=\"same\";\r\n"); + if (DecorateKeyValuePair.Value.Trim().Substring(0, 5) == "(tag:") + { + DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" [shape=\"box\", style=\"filled\", fillcolor=\"#ffffdd\"];\r\n"); + } + else + { + DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" [shape=\"box\", style=\"filled\", fillcolor=\"#ddddff\"];\r\n"); + } + DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" -> \"" + DecorateKeyValuePair.Key + "\" [weight=0, arrowtype=\"none\", dirtype=\"none\", arrowhead=\"none\", style=\"dotted\"];\r\n"); + DotStringBuilder.Append(" }\r\n"); + } + + DotStringBuilder.Append("}\r\n"); + File.WriteAllText(@DotFilename, DotStringBuilder.ToString()); + + Status("Generating version tree ..."); + Process DotProcess = new Process(); + DotProcess.StartInfo.UseShellExecute = false; + DotProcess.StartInfo.CreateNoWindow = true; + DotProcess.StartInfo.RedirectStandardOutput = true; + DotProcess.StartInfo.FileName = GraphvizDotPathTextBox.Text; + //DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tpdf -Gsize=10,10 -o\"" + @PdfFilename + "\""; + DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tpdf -o\"" + @PdfFilename + "\""; //Gsize renders lfile wiht large commits not readable + Console.WriteLine(DotProcess.StartInfo.Arguments); + DotProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + DotProcess.Start(); + DotProcess.WaitForExit(); + + DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tps -o\"" + @PdfFilename.Replace(".pdf", ".ps") + "\""; + Console.WriteLine(DotProcess.StartInfo.Arguments); + DotProcess.Start(); + DotProcess.WaitForExit(); + + if (DotProcess.ExitCode == 0) + { + if (File.Exists(@PdfFilename)) + { +#if (!DEBUG) + /* + Process ViewPdfProcess = new Process(); + ViewPdfProcess.StartInfo.FileName = @PdfFilename; + ViewPdfProcess.Start(); + //ViewPdfProcess.WaitForExit(); + //Close(); + */ +#endif + } + } + else + { + Status("Version tree generation failed ..."); + } + + Status("Done! ..."); + } + } +} From f18184690e55e91dce3bc4168f3cc09c32849742 Mon Sep 17 00:00:00 2001 From: Srix Date: Thu, 8 May 2014 21:42:44 +0530 Subject: [PATCH 2/4] unix2dos on the file to make windows formating of source code --- GitVersionTree/Forms/MainForm.cs | 772 +++++++++++++++---------------- 1 file changed, 386 insertions(+), 386 deletions(-) diff --git a/GitVersionTree/Forms/MainForm.cs b/GitVersionTree/Forms/MainForm.cs index 7b394f1..6d824cf 100644 --- a/GitVersionTree/Forms/MainForm.cs +++ b/GitVersionTree/Forms/MainForm.cs @@ -1,386 +1,386 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; -using System.Diagnostics; -using System.Collections; -using System.IO; - -namespace GitVersionTree -{ - public partial class MainForm : Form - { - private Dictionary DecorateDictionary = new Dictionary(); - private List> Nodes = new List>(); - - private string DotFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + Application.ProductName + ".dot"; - private string PdfFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + Application.ProductName + ".pdf"; - private string LogFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + Application.ProductName + ".log"; - string RepositoryName; - - public MainForm() - { - InitializeComponent(); - } - - private void MainForm_Load(object sender, EventArgs e) - { - Text = Application.ProductName + " - v" + Application.ProductVersion.Substring(0, 3); - - RefreshPath(); - } - - private void GitPathBrowseButton_Click(object sender, EventArgs e) - { - OpenFileDialog BrowseOpenFileDialog = new OpenFileDialog(); - BrowseOpenFileDialog.Title = "Select git.exe"; - if (!String.IsNullOrEmpty(Reg.Read("GitPath"))) - { - BrowseOpenFileDialog.InitialDirectory = Reg.Read("GitPath"); - } - BrowseOpenFileDialog.FileName = "git.exe"; - BrowseOpenFileDialog.Filter = "Git Application (git.exe)|git.exe"; - if (BrowseOpenFileDialog.ShowDialog() == DialogResult.OK) - { - Reg.Write("GitPath", BrowseOpenFileDialog.FileName); - RefreshPath(); - } - } - - private void GraphvizDotPathBrowseButton_Click(object sender, EventArgs e) - { - OpenFileDialog BrowseOpenFileDialog = new OpenFileDialog(); - BrowseOpenFileDialog.Title = "Select dot.exe"; - if (!String.IsNullOrEmpty(Reg.Read("GraphvizPath"))) - { - BrowseOpenFileDialog.InitialDirectory = Reg.Read("GraphvizPath"); - } - BrowseOpenFileDialog.FileName = "dot.exe"; - BrowseOpenFileDialog.Filter = "Graphviz Dot Application (dot.exe)|dot.exe"; - if (BrowseOpenFileDialog.ShowDialog() == DialogResult.OK) - { - Reg.Write("GraphvizPath", BrowseOpenFileDialog.FileName); - RefreshPath(); - } - } - - private void GitRepositoryPathBrowseButton_Click(object sender, EventArgs e) - { - FolderBrowserDialog BrowseFolderBrowserDialog = new FolderBrowserDialog(); - BrowseFolderBrowserDialog.Description = "Select Git repository"; - BrowseFolderBrowserDialog.ShowNewFolderButton = false; - if (!String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) - { - BrowseFolderBrowserDialog.SelectedPath = Reg.Read("GitRepositoryPath"); - } - if (BrowseFolderBrowserDialog.ShowDialog() == DialogResult.OK) - { - Reg.Write("GitRepositoryPath", BrowseFolderBrowserDialog.SelectedPath); - RefreshPath(); - } - } - - private void GenerateButton_Click(object sender, EventArgs e) - { - - DecorateDictionary.Clear(); - Nodes.Clear(); - - if (String.IsNullOrEmpty(Reg.Read("GitPath")) || - String.IsNullOrEmpty(Reg.Read("GraphvizPath")) || - String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) - { - MessageBox.Show("Please select a Git, Graphviz & Git repository.", "Generate", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - else - { - StatusRichTextBox.Text = ""; - RepositoryName = new DirectoryInfo(GitRepositoryPathTextBox.Text).Name; - DotFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + RepositoryName + ".dot"; - PdfFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + RepositoryName + ".pdf"; - LogFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + RepositoryName + ".log"; - File.WriteAllText(LogFilename, ""); - Generate(); - } - } - - private void HomepageLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - Process.Start("https://github.com/crc8/GitVersionTree"); - } - - private void ExitButton_Click(object sender, EventArgs e) - { - Close(); - } - - private void RefreshPath() - { - if (!String.IsNullOrEmpty(Reg.Read("GitPath"))) - { - GitPathTextBox.Text = Reg.Read("GitPath"); - } - if (!String.IsNullOrEmpty(Reg.Read("GraphvizPath"))) - { - GraphvizDotPathTextBox.Text = Reg.Read("GraphvizPath"); - } - if (!String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) - { - GitRepositoryPathTextBox.Text = Reg.Read("GitRepositoryPath"); - } - } - - private void Status(string Message) - { - StatusRichTextBox.AppendText(DateTime.Now + " - " + Message + "\r\n"); - StatusRichTextBox.SelectionStart = StatusRichTextBox.Text.Length; - StatusRichTextBox.ScrollToCaret(); - Refresh(); - } - - private string Execute(string Command, string Argument) - { - string ExecuteResult = String.Empty; - Process ExecuteProcess = new Process(); - ExecuteProcess.StartInfo.UseShellExecute = false; - ExecuteProcess.StartInfo.CreateNoWindow = true; - ExecuteProcess.StartInfo.RedirectStandardOutput = true; - ExecuteProcess.StartInfo.FileName = Command; - ExecuteProcess.StartInfo.Arguments = Argument; - ExecuteProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - ExecuteProcess.Start(); - ExecuteResult = ExecuteProcess.StandardOutput.ReadToEnd(); - ExecuteProcess.WaitForExit(); - if (ExecuteProcess.ExitCode == 0) - { - return ExecuteResult; - } - else - { - return String.Empty; - } - } - - private void Generate() - { - string Result; - string[] MergedColumns; - string[] MergedParents; - - Status("Getting git commit(s) ..."); - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --all --pretty=format:\"%h|%p|%d\""); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get get branch or branch empty ..."); - } - else - { - File.AppendAllText(LogFilename, "[commit(s)]\r\n"); - File.AppendAllText(LogFilename, Result + "\r\n"); - string[] DecorateLines = Result.Split('\n'); - foreach (string DecorateLine in DecorateLines) - { - MergedColumns = DecorateLine.Split('|'); - if (!String.IsNullOrEmpty(MergedColumns[2])) - { - DecorateDictionary.Add(MergedColumns[0], MergedColumns[2]); - } - } - Status("Processed " + DecorateDictionary.Count + " decorate(s) ..."); - } - - Status("Getting git ref branch(es) ..."); - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" for-each-ref --format=\"%(objectname:short)|%(refname:short)\" "); //refs/heads/ - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get get branch or branch empty ..."); - } - else - { - File.AppendAllText(LogFilename, "[ref branch(es)]\r\n"); - File.AppendAllText(LogFilename, Result + "\r\n"); - string[] RefLines = Result.Split('\n'); - foreach (string RefLine in RefLines) - { - if (!String.IsNullOrEmpty(RefLine)) - { - string[] RefColumns = RefLine.Split('|'); - if (!RefColumns[1].ToLower().StartsWith("refs/tags")) - if (RefColumns[1].ToLower().Contains("master")) - { - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --reverse --first-parent --pretty=format:\"%h\" " + RefColumns[0]); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get commit(s) ..."); - } - else - { - string[] HashLines = Result.Split('\n'); - Nodes.Add(new List()); - foreach (string HashLine in HashLines) - { - Nodes[Nodes.Count - 1].Add(HashLine); - } - } - } - } - } - foreach (string RefLine in RefLines) - { - if (!String.IsNullOrEmpty(RefLine)) - { - string[] RefColumns = RefLine.Split('|'); - if (!RefColumns[1].ToLower().StartsWith("refs/tags")) - if (!RefColumns[1].ToLower().Contains("master")) - { - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --reverse --first-parent --pretty=format:\"%h\" " + RefColumns[0]); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get commit(s) ..."); - } - else - { - string[] HashLines = Result.Split('\n'); - Nodes.Add(new List()); - foreach (string HashLine in HashLines) - { - Nodes[Nodes.Count - 1].Add(HashLine); - } - } - } - } - } - } - - Status("Getting git merged branch(es) ..."); - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar + ".git\" log --all --merges --pretty=format:\"%h|%p\""); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get get branch or branch empty ..."); - } - else - { - File.AppendAllText(LogFilename, "[merged branch(es)]\r\n"); - File.AppendAllText(LogFilename, Result + "\r\n"); - string[] MergedLines = Result.Split('\n'); - foreach (string MergedLine in MergedLines) - { - MergedColumns = MergedLine.Split('|'); - MergedParents = MergedColumns[1].Split(' '); - if (MergedParents.Length > 1) - { - for (int i = 1; i < MergedParents.Length; i++) - { - Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --reverse --first-parent --pretty=format:\"%h\" " + MergedParents[i]); - if (String.IsNullOrEmpty(Result)) - { - Status("Unable to get commit(s) ..."); - } - else - { - string[] HashLines = Result.Split('\n'); - Nodes.Add(new List()); - foreach (string HashLine in HashLines) - { - Nodes[Nodes.Count - 1].Add(HashLine); - } - Nodes[Nodes.Count - 1].Add(MergedColumns[0]); - } - } - } - } - } - - Status("Processed " + Nodes.Count + " branch(es) ..."); - - StringBuilder DotStringBuilder = new StringBuilder(); - Status("Generating dot file ..."); - DotStringBuilder.Append("strict digraph \"" + RepositoryName + "\" {\r\n"); - //DotStringBuilder.Append(" splines=line;\r\n"); - for (int i = 0; i < Nodes.Count; i++) - { - DotStringBuilder.Append(" node[group=\"" + (i + 1) + "\"];\r\n"); - DotStringBuilder.Append(" "); - for (int j = 0; j < Nodes[i].Count; j++) - { - DotStringBuilder.Append("\"" + Nodes[i][j] + "\""); - if (j < Nodes[i].Count - 1) - { - DotStringBuilder.Append(" -> "); - } - else - { - DotStringBuilder.Append(";"); - } - } - DotStringBuilder.Append("\r\n"); - } - - int DecorateCount = 0; - foreach(KeyValuePair DecorateKeyValuePair in DecorateDictionary) - { - DecorateCount++; - DotStringBuilder.Append(" subgraph Decorate" + DecorateCount + "\r\n"); - DotStringBuilder.Append(" {\r\n"); - DotStringBuilder.Append(" rank=\"same\";\r\n"); - if (DecorateKeyValuePair.Value.Trim().Substring(0, 5) == "(tag:") - { - DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" [shape=\"box\", style=\"filled\", fillcolor=\"#ffffdd\"];\r\n"); - } - else - { - DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" [shape=\"box\", style=\"filled\", fillcolor=\"#ddddff\"];\r\n"); - } - DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" -> \"" + DecorateKeyValuePair.Key + "\" [weight=0, arrowtype=\"none\", dirtype=\"none\", arrowhead=\"none\", style=\"dotted\"];\r\n"); - DotStringBuilder.Append(" }\r\n"); - } - - DotStringBuilder.Append("}\r\n"); - File.WriteAllText(@DotFilename, DotStringBuilder.ToString()); - - Status("Generating version tree ..."); - Process DotProcess = new Process(); - DotProcess.StartInfo.UseShellExecute = false; - DotProcess.StartInfo.CreateNoWindow = true; - DotProcess.StartInfo.RedirectStandardOutput = true; - DotProcess.StartInfo.FileName = GraphvizDotPathTextBox.Text; - //DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tpdf -Gsize=10,10 -o\"" + @PdfFilename + "\""; - DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tpdf -o\"" + @PdfFilename + "\""; //Gsize renders lfile wiht large commits not readable - Console.WriteLine(DotProcess.StartInfo.Arguments); - DotProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - DotProcess.Start(); - DotProcess.WaitForExit(); - - DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tps -o\"" + @PdfFilename.Replace(".pdf", ".ps") + "\""; - Console.WriteLine(DotProcess.StartInfo.Arguments); - DotProcess.Start(); - DotProcess.WaitForExit(); - - if (DotProcess.ExitCode == 0) - { - if (File.Exists(@PdfFilename)) - { -#if (!DEBUG) - /* - Process ViewPdfProcess = new Process(); - ViewPdfProcess.StartInfo.FileName = @PdfFilename; - ViewPdfProcess.Start(); - //ViewPdfProcess.WaitForExit(); - //Close(); - */ -#endif - } - } - else - { - Status("Version tree generation failed ..."); - } - - Status("Done! ..."); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Diagnostics; +using System.Collections; +using System.IO; + +namespace GitVersionTree +{ + public partial class MainForm : Form + { + private Dictionary DecorateDictionary = new Dictionary(); + private List> Nodes = new List>(); + + private string DotFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + Application.ProductName + ".dot"; + private string PdfFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + Application.ProductName + ".pdf"; + private string LogFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + Application.ProductName + ".log"; + string RepositoryName; + + public MainForm() + { + InitializeComponent(); + } + + private void MainForm_Load(object sender, EventArgs e) + { + Text = Application.ProductName + " - v" + Application.ProductVersion.Substring(0, 3); + + RefreshPath(); + } + + private void GitPathBrowseButton_Click(object sender, EventArgs e) + { + OpenFileDialog BrowseOpenFileDialog = new OpenFileDialog(); + BrowseOpenFileDialog.Title = "Select git.exe"; + if (!String.IsNullOrEmpty(Reg.Read("GitPath"))) + { + BrowseOpenFileDialog.InitialDirectory = Reg.Read("GitPath"); + } + BrowseOpenFileDialog.FileName = "git.exe"; + BrowseOpenFileDialog.Filter = "Git Application (git.exe)|git.exe"; + if (BrowseOpenFileDialog.ShowDialog() == DialogResult.OK) + { + Reg.Write("GitPath", BrowseOpenFileDialog.FileName); + RefreshPath(); + } + } + + private void GraphvizDotPathBrowseButton_Click(object sender, EventArgs e) + { + OpenFileDialog BrowseOpenFileDialog = new OpenFileDialog(); + BrowseOpenFileDialog.Title = "Select dot.exe"; + if (!String.IsNullOrEmpty(Reg.Read("GraphvizPath"))) + { + BrowseOpenFileDialog.InitialDirectory = Reg.Read("GraphvizPath"); + } + BrowseOpenFileDialog.FileName = "dot.exe"; + BrowseOpenFileDialog.Filter = "Graphviz Dot Application (dot.exe)|dot.exe"; + if (BrowseOpenFileDialog.ShowDialog() == DialogResult.OK) + { + Reg.Write("GraphvizPath", BrowseOpenFileDialog.FileName); + RefreshPath(); + } + } + + private void GitRepositoryPathBrowseButton_Click(object sender, EventArgs e) + { + FolderBrowserDialog BrowseFolderBrowserDialog = new FolderBrowserDialog(); + BrowseFolderBrowserDialog.Description = "Select Git repository"; + BrowseFolderBrowserDialog.ShowNewFolderButton = false; + if (!String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) + { + BrowseFolderBrowserDialog.SelectedPath = Reg.Read("GitRepositoryPath"); + } + if (BrowseFolderBrowserDialog.ShowDialog() == DialogResult.OK) + { + Reg.Write("GitRepositoryPath", BrowseFolderBrowserDialog.SelectedPath); + RefreshPath(); + } + } + + private void GenerateButton_Click(object sender, EventArgs e) + { + + DecorateDictionary.Clear(); + Nodes.Clear(); + + if (String.IsNullOrEmpty(Reg.Read("GitPath")) || + String.IsNullOrEmpty(Reg.Read("GraphvizPath")) || + String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) + { + MessageBox.Show("Please select a Git, Graphviz & Git repository.", "Generate", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + StatusRichTextBox.Text = ""; + RepositoryName = new DirectoryInfo(GitRepositoryPathTextBox.Text).Name; + DotFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + RepositoryName + ".dot"; + PdfFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + RepositoryName + ".pdf"; + LogFilename = Directory.GetParent(Application.ExecutablePath) + Path.DirectorySeparatorChar.ToString() + RepositoryName + ".log"; + File.WriteAllText(LogFilename, ""); + Generate(); + } + } + + private void HomepageLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + Process.Start("https://github.com/crc8/GitVersionTree"); + } + + private void ExitButton_Click(object sender, EventArgs e) + { + Close(); + } + + private void RefreshPath() + { + if (!String.IsNullOrEmpty(Reg.Read("GitPath"))) + { + GitPathTextBox.Text = Reg.Read("GitPath"); + } + if (!String.IsNullOrEmpty(Reg.Read("GraphvizPath"))) + { + GraphvizDotPathTextBox.Text = Reg.Read("GraphvizPath"); + } + if (!String.IsNullOrEmpty(Reg.Read("GitRepositoryPath"))) + { + GitRepositoryPathTextBox.Text = Reg.Read("GitRepositoryPath"); + } + } + + private void Status(string Message) + { + StatusRichTextBox.AppendText(DateTime.Now + " - " + Message + "\r\n"); + StatusRichTextBox.SelectionStart = StatusRichTextBox.Text.Length; + StatusRichTextBox.ScrollToCaret(); + Refresh(); + } + + private string Execute(string Command, string Argument) + { + string ExecuteResult = String.Empty; + Process ExecuteProcess = new Process(); + ExecuteProcess.StartInfo.UseShellExecute = false; + ExecuteProcess.StartInfo.CreateNoWindow = true; + ExecuteProcess.StartInfo.RedirectStandardOutput = true; + ExecuteProcess.StartInfo.FileName = Command; + ExecuteProcess.StartInfo.Arguments = Argument; + ExecuteProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + ExecuteProcess.Start(); + ExecuteResult = ExecuteProcess.StandardOutput.ReadToEnd(); + ExecuteProcess.WaitForExit(); + if (ExecuteProcess.ExitCode == 0) + { + return ExecuteResult; + } + else + { + return String.Empty; + } + } + + private void Generate() + { + string Result; + string[] MergedColumns; + string[] MergedParents; + + Status("Getting git commit(s) ..."); + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --all --pretty=format:\"%h|%p|%d\""); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get get branch or branch empty ..."); + } + else + { + File.AppendAllText(LogFilename, "[commit(s)]\r\n"); + File.AppendAllText(LogFilename, Result + "\r\n"); + string[] DecorateLines = Result.Split('\n'); + foreach (string DecorateLine in DecorateLines) + { + MergedColumns = DecorateLine.Split('|'); + if (!String.IsNullOrEmpty(MergedColumns[2])) + { + DecorateDictionary.Add(MergedColumns[0], MergedColumns[2]); + } + } + Status("Processed " + DecorateDictionary.Count + " decorate(s) ..."); + } + + Status("Getting git ref branch(es) ..."); + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" for-each-ref --format=\"%(objectname:short)|%(refname:short)\" "); //refs/heads/ + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get get branch or branch empty ..."); + } + else + { + File.AppendAllText(LogFilename, "[ref branch(es)]\r\n"); + File.AppendAllText(LogFilename, Result + "\r\n"); + string[] RefLines = Result.Split('\n'); + foreach (string RefLine in RefLines) + { + if (!String.IsNullOrEmpty(RefLine)) + { + string[] RefColumns = RefLine.Split('|'); + if (!RefColumns[1].ToLower().StartsWith("refs/tags")) + if (RefColumns[1].ToLower().Contains("master")) + { + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --reverse --first-parent --pretty=format:\"%h\" " + RefColumns[0]); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get commit(s) ..."); + } + else + { + string[] HashLines = Result.Split('\n'); + Nodes.Add(new List()); + foreach (string HashLine in HashLines) + { + Nodes[Nodes.Count - 1].Add(HashLine); + } + } + } + } + } + foreach (string RefLine in RefLines) + { + if (!String.IsNullOrEmpty(RefLine)) + { + string[] RefColumns = RefLine.Split('|'); + if (!RefColumns[1].ToLower().StartsWith("refs/tags")) + if (!RefColumns[1].ToLower().Contains("master")) + { + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --reverse --first-parent --pretty=format:\"%h\" " + RefColumns[0]); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get commit(s) ..."); + } + else + { + string[] HashLines = Result.Split('\n'); + Nodes.Add(new List()); + foreach (string HashLine in HashLines) + { + Nodes[Nodes.Count - 1].Add(HashLine); + } + } + } + } + } + } + + Status("Getting git merged branch(es) ..."); + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar + ".git\" log --all --merges --pretty=format:\"%h|%p\""); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get get branch or branch empty ..."); + } + else + { + File.AppendAllText(LogFilename, "[merged branch(es)]\r\n"); + File.AppendAllText(LogFilename, Result + "\r\n"); + string[] MergedLines = Result.Split('\n'); + foreach (string MergedLine in MergedLines) + { + MergedColumns = MergedLine.Split('|'); + MergedParents = MergedColumns[1].Split(' '); + if (MergedParents.Length > 1) + { + for (int i = 1; i < MergedParents.Length; i++) + { + Result = Execute(Reg.Read("GitPath"), "--git-dir \"" + Reg.Read("GitRepositoryPath") + Path.DirectorySeparatorChar +".git\" log --reverse --first-parent --pretty=format:\"%h\" " + MergedParents[i]); + if (String.IsNullOrEmpty(Result)) + { + Status("Unable to get commit(s) ..."); + } + else + { + string[] HashLines = Result.Split('\n'); + Nodes.Add(new List()); + foreach (string HashLine in HashLines) + { + Nodes[Nodes.Count - 1].Add(HashLine); + } + Nodes[Nodes.Count - 1].Add(MergedColumns[0]); + } + } + } + } + } + + Status("Processed " + Nodes.Count + " branch(es) ..."); + + StringBuilder DotStringBuilder = new StringBuilder(); + Status("Generating dot file ..."); + DotStringBuilder.Append("strict digraph \"" + RepositoryName + "\" {\r\n"); + //DotStringBuilder.Append(" splines=line;\r\n"); + for (int i = 0; i < Nodes.Count; i++) + { + DotStringBuilder.Append(" node[group=\"" + (i + 1) + "\"];\r\n"); + DotStringBuilder.Append(" "); + for (int j = 0; j < Nodes[i].Count; j++) + { + DotStringBuilder.Append("\"" + Nodes[i][j] + "\""); + if (j < Nodes[i].Count - 1) + { + DotStringBuilder.Append(" -> "); + } + else + { + DotStringBuilder.Append(";"); + } + } + DotStringBuilder.Append("\r\n"); + } + + int DecorateCount = 0; + foreach(KeyValuePair DecorateKeyValuePair in DecorateDictionary) + { + DecorateCount++; + DotStringBuilder.Append(" subgraph Decorate" + DecorateCount + "\r\n"); + DotStringBuilder.Append(" {\r\n"); + DotStringBuilder.Append(" rank=\"same\";\r\n"); + if (DecorateKeyValuePair.Value.Trim().Substring(0, 5) == "(tag:") + { + DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" [shape=\"box\", style=\"filled\", fillcolor=\"#ffffdd\"];\r\n"); + } + else + { + DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" [shape=\"box\", style=\"filled\", fillcolor=\"#ddddff\"];\r\n"); + } + DotStringBuilder.Append(" \"" + DecorateKeyValuePair.Value.Trim() + "\" -> \"" + DecorateKeyValuePair.Key + "\" [weight=0, arrowtype=\"none\", dirtype=\"none\", arrowhead=\"none\", style=\"dotted\"];\r\n"); + DotStringBuilder.Append(" }\r\n"); + } + + DotStringBuilder.Append("}\r\n"); + File.WriteAllText(@DotFilename, DotStringBuilder.ToString()); + + Status("Generating version tree ..."); + Process DotProcess = new Process(); + DotProcess.StartInfo.UseShellExecute = false; + DotProcess.StartInfo.CreateNoWindow = true; + DotProcess.StartInfo.RedirectStandardOutput = true; + DotProcess.StartInfo.FileName = GraphvizDotPathTextBox.Text; + //DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tpdf -Gsize=10,10 -o\"" + @PdfFilename + "\""; + DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tpdf -o\"" + @PdfFilename + "\""; //Gsize renders lfile wiht large commits not readable + Console.WriteLine(DotProcess.StartInfo.Arguments); + DotProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + DotProcess.Start(); + DotProcess.WaitForExit(); + + DotProcess.StartInfo.Arguments = "\"" + @DotFilename + "\" -Tps -o\"" + @PdfFilename.Replace(".pdf", ".ps") + "\""; + Console.WriteLine(DotProcess.StartInfo.Arguments); + DotProcess.Start(); + DotProcess.WaitForExit(); + + if (DotProcess.ExitCode == 0) + { + if (File.Exists(@PdfFilename)) + { +#if (!DEBUG) + /* + Process ViewPdfProcess = new Process(); + ViewPdfProcess.StartInfo.FileName = @PdfFilename; + ViewPdfProcess.Start(); + //ViewPdfProcess.WaitForExit(); + //Close(); + */ +#endif + } + } + else + { + Status("Version tree generation failed ..."); + } + + Status("Done! ..."); + } + } +} From 4a1a40d02967b4b47e9f26698682b14630e15dbe Mon Sep 17 00:00:00 2001 From: Srix Date: Tue, 20 May 2014 17:46:29 +0530 Subject: [PATCH 3/4] added instructions to build in Linux in Readme.md --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3e537d..636fe7b 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,16 @@ Download Latest release: [v1.0](https://github.com/crc8/GitVersionTree/releases) + +Compile on Linux +-------- + +sudo apt-get install mono-devel graphviz +git clone https://github.com/srix/GitVersionTree.git +cd GitVersionTree +xbuild /p:Configuration=Release +GitVersionTree/bin/Release/GitVersionTree.exe + Changelog --------- @@ -88,4 +98,4 @@ License Disclaimer ---------- -The developers of this software provide the software "as is," and you use the software at your own risk. The developers make no warranties as to performance, merchantability, fitness for a particular purpose, or any other warranties whether expressed or implied. No oral or written communication from or information provided by the developers shall create a warranty. Under no circumstances shall the developers be liable for direct, indirect, special, incidental, or consequential damages resulting from the use, misuse, or inability to use this software, even if the developers has been advised of the possibility of such damages. \ No newline at end of file +The developers of this software provide the software "as is," and you use the software at your own risk. The developers make no warranties as to performance, merchantability, fitness for a particular purpose, or any other warranties whether expressed or implied. No oral or written communication from or information provided by the developers shall create a warranty. Under no circumstances shall the developers be liable for direct, indirect, special, incidental, or consequential damages resulting from the use, misuse, or inability to use this software, even if the developers has been advised of the possibility of such damages. From b77195c0233f84b7f4e20ab84dd1f06fb91668ab Mon Sep 17 00:00:00 2001 From: srix Date: Tue, 20 May 2014 18:26:49 +0530 Subject: [PATCH 4/4] added code blocks Linux compiling instruction is wrapped inside code block --- README.md | 196 +++++++++++++++++++++++++++--------------------------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/README.md b/README.md index 636fe7b..38e085e 100644 --- a/README.md +++ b/README.md @@ -1,101 +1,101 @@ -GitVersionTree --------------- - -A tool to help visualize git revisions and branches. - -Introduction ------------- - -(First of all, sorry for my english.) - -Coming from Clearcase background, I find it difficult and confusing sometime to understand and visualize my project development in git when it grows with many branch. - -Using `gitk` or `git log --oneline --color --all --decorate --graph`, I couldn't understand the relationship between each branches. Eg. where this branch come out from and where it merged to etc. Sometime the branch just appear out of nowhere because there is a new commit in a branch. I find it hard to also to follow my master branch inside the 'branch forest' because it won't grow in straight line. It would be more severe when I started out git. - -Therefore, I made this little tool to help me solve my problem. To whoever face this problem also, I hope this tool can help you. - -Screenshot ----------- - -Screenshot of Gitk. Branch may not be in straight line. - -![Screenshot of Gitk](https://raw.github.com/crc8/GitVersionTree/master/sample_gitk.png) - -Screenshot of GitVersionTree. Keeping branch in their own line. From oldest commit at the top down to latest at the bottom. - -![Screenshot of GitVersionTree](https://raw.github.com/crc8/GitVersionTree/master/sample_gvt.png) - -Features --------- - -- Tree is from top to bottom -- Same branch will be in same straight line tree -- Date is sort on the branch itself instead with all branch -- Tag and branch name on the side -- Easy scrolling / zooming with PDF - -Project Status --------------- +GitVersionTree +-------------- + +A tool to help visualize git revisions and branches. + +Introduction +------------ + +(First of all, sorry for my english.) + +Coming from Clearcase background, I find it difficult and confusing sometime to understand and visualize my project development in git when it grows with many branch. + +Using `gitk` or `git log --oneline --color --all --decorate --graph`, I couldn't understand the relationship between each branches. Eg. where this branch come out from and where it merged to etc. Sometime the branch just appear out of nowhere because there is a new commit in a branch. I find it hard to also to follow my master branch inside the 'branch forest' because it won't grow in straight line. It would be more severe when I started out git. + +Therefore, I made this little tool to help me solve my problem. To whoever face this problem also, I hope this tool can help you. + +Screenshot +---------- + +Screenshot of Gitk. Branch may not be in straight line. + +![Screenshot of Gitk](https://raw.github.com/crc8/GitVersionTree/master/sample_gitk.png) + +Screenshot of GitVersionTree. Keeping branch in their own line. From oldest commit at the top down to latest at the bottom. + +![Screenshot of GitVersionTree](https://raw.github.com/crc8/GitVersionTree/master/sample_gvt.png) + +Features +-------- + +- Tree is from top to bottom +- Same branch will be in same straight line tree +- Date is sort on the branch itself instead with all branch +- Tag and branch name on the side +- Easy scrolling / zooming with PDF + +Project Status +-------------- - I would say this project still in beta. -- Contructive feedback are always welcome. +- Contructive feedback are always welcome. - Good to handle git project with less than 500 commits. Should be able to visualize clearly. -- Tested with jquery project with 5000+ commits. Although the tool still can generate the version tree, but you wouldn't want to go thru each commits, only to visualize some development of the important branch only. -- Will generate out a `.pdf` file, a `.dot` file and a `.ps` file. So you can either view PDF with PDF reader, or Dot file with zgrviewer, or Postscript file with Evince. - -Requirement ------------ - -This tool required or need: - -- [Git](http://git-scm.com/) -- [Graphviz](http://www.graphviz.org/) -- [Microsoft(c) .Net Framework 4.0](http://www.microsoft.com/en-us/download/details.aspx?id=17718) -- [Any PDF reader/viewer](http://get.adobe.com/reader/) -- [Postscript viewer](https://projects.gnome.org/evince/) (optional) - -This project was compile using Microsoft(c) Visual Studio 2010 Express Edition. - -Pending -------- - -- Output enhancement (Colors, Node alignment, etc) -- Background process -- Max count selection -- Date range selection -- Integrated Git (?) -- Integrated Graphviz (?) -- Integrated PDF Viewer (?) - -Download --------- - -Latest release: -[v1.0](https://github.com/crc8/GitVersionTree/releases) - - -Compile on Linux --------- - -sudo apt-get install mono-devel graphviz -git clone https://github.com/srix/GitVersionTree.git -cd GitVersionTree -xbuild /p:Configuration=Release -GitVersionTree/bin/Release/GitVersionTree.exe - -Changelog ---------- - -- v1.0 - 17 August 2013 - - - Initial baseline - -License -------- - -[GPL V2](https://raw.github.com/crc8/GitVersionTree/master/LICENSE) - -Disclaimer ----------- - -The developers of this software provide the software "as is," and you use the software at your own risk. The developers make no warranties as to performance, merchantability, fitness for a particular purpose, or any other warranties whether expressed or implied. No oral or written communication from or information provided by the developers shall create a warranty. Under no circumstances shall the developers be liable for direct, indirect, special, incidental, or consequential damages resulting from the use, misuse, or inability to use this software, even if the developers has been advised of the possibility of such damages. +- Tested with jquery project with 5000+ commits. Although the tool still can generate the version tree, but you wouldn't want to go thru each commits, only to visualize some development of the important branch only. +- Will generate out a `.pdf` file, a `.dot` file and a `.ps` file. So you can either view PDF with PDF reader, or Dot file with zgrviewer, or Postscript file with Evince. + +Requirement +----------- + +This tool required or need: + +- [Git](http://git-scm.com/) +- [Graphviz](http://www.graphviz.org/) +- [Microsoft(c) .Net Framework 4.0](http://www.microsoft.com/en-us/download/details.aspx?id=17718) +- [Any PDF reader/viewer](http://get.adobe.com/reader/) +- [Postscript viewer](https://projects.gnome.org/evince/) (optional) + +This project was compile using Microsoft(c) Visual Studio 2010 Express Edition. + +Pending +------- + +- Output enhancement (Colors, Node alignment, etc) +- Background process +- Max count selection +- Date range selection +- Integrated Git (?) +- Integrated Graphviz (?) +- Integrated PDF Viewer (?) + +Download +-------- + +Latest release: +[v1.0](https://github.com/crc8/GitVersionTree/releases) + + +Compile on Linux +-------- + + sudo apt-get install mono-devel graphviz + git clone https://github.com/srix/GitVersionTree.git + cd GitVersionTree + xbuild /p:Configuration=Release + GitVersionTree/bin/Release/GitVersionTree.exe + +Changelog +--------- + +- v1.0 - 17 August 2013 + + - Initial baseline + +License +------- + +[GPL V2](https://raw.github.com/crc8/GitVersionTree/master/LICENSE) + +Disclaimer +---------- + +The developers of this software provide the software "as is," and you use the software at your own risk. The developers make no warranties as to performance, merchantability, fitness for a particular purpose, or any other warranties whether expressed or implied. No oral or written communication from or information provided by the developers shall create a warranty. Under no circumstances shall the developers be liable for direct, indirect, special, incidental, or consequential damages resulting from the use, misuse, or inability to use this software, even if the developers has been advised of the possibility of such damages.