From cec9bf4824cc04d556fccee979ca92eb11ac0742 Mon Sep 17 00:00:00 2001 From: mbassit Date: Sun, 27 Dec 2015 14:15:37 +0000 Subject: [PATCH 1/5] Fixed crash caused by RepositoryPath ending with whitespace --- Logic/ViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Logic/ViewModel.cs b/Logic/ViewModel.cs index 7289ec4..baadaea 100644 --- a/Logic/ViewModel.cs +++ b/Logic/ViewModel.cs @@ -48,7 +48,7 @@ public string RepositoryPath get { return _repositoryPath; } set { - _repositoryPath = value; + _repositoryPath = value.Trim(); if (IsValidGitRepository(_repositoryPath)) { commandExecutor = new GitCommandExecutor(_repositoryPath); From c2c405eac589272a89dddfd2d813c3c332c61270 Mon Sep 17 00:00:00 2001 From: mbassit Date: Sun, 27 Dec 2015 15:30:30 +0000 Subject: [PATCH 2/5] Added visualization of committer date --- Logic/Commit.cs | 40 +++++++++-------- Logic/LogParser.cs | 110 ++++++++++++++++++++++++--------------------- Logic/ViewModel.cs | 41 +++++++++++------ UI/MainWindow.xaml | 14 +++--- 4 files changed, 115 insertions(+), 90 deletions(-) diff --git a/Logic/Commit.cs b/Logic/Commit.cs index a8bd833..dbfe71b 100644 --- a/Logic/Commit.cs +++ b/Logic/Commit.cs @@ -1,22 +1,24 @@ -namespace GitViz.Logic -{ - public class Commit - { - public string Hash { get; set; } - - public string[] ParentHashes { get; set; } - - public string[] Refs { get; set; } - - public long CommitDate { get; set; } - - public string Subject { get; set; } - - public string ShortHash - { - get { return Hash.Substring(0, 7); } +using System; + +namespace GitViz.Logic +{ + public class Commit + { + public string Hash { get; set; } + + public string[] ParentHashes { get; set; } + + public string[] Refs { get; set; } + + public DateTime CommitDate { get; set; } + + public string Subject { get; set; } + + public string ShortHash + { + get { return Hash.Substring(0, 7); } } - } -} + } +} diff --git a/Logic/LogParser.cs b/Logic/LogParser.cs index a24c9c1..d50c096 100644 --- a/Logic/LogParser.cs +++ b/Logic/LogParser.cs @@ -1,58 +1,64 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; - -namespace GitViz.Logic -{ - public class LogParser - { - public readonly string ExpectedOutputFormat = "%ct %H %P %d %s"; - - public IEnumerable ParseCommits(StreamReader gitLogOutput) - { - while (gitLogOutput.BaseStream != null && !gitLogOutput.EndOfStream) - { - var line = gitLogOutput.ReadLine(); - if (string.IsNullOrWhiteSpace(line)) continue; - yield return ParseCommit(line); - } - gitLogOutput.Close(); +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; + +namespace GitViz.Logic +{ + public class LogParser + { + public readonly string ExpectedOutputFormat = "%ct %H %P %d %s"; + + public IEnumerable ParseCommits(StreamReader gitLogOutput) + { + while (gitLogOutput.BaseStream != null && !gitLogOutput.EndOfStream) + { + var line = gitLogOutput.ReadLine(); + if (string.IsNullOrWhiteSpace(line)) continue; + yield return ParseCommit(line); + } + gitLogOutput.Close(); } - static readonly Regex ParseCommitRegex = new Regex(@"^(?\d*) (?\w{7,40})(?( \w{7,40})+)?([ ]+\((?.*?)\))?\s?((?.*))?"); - - internal static Commit ParseCommit(string logOutputLine) - { - var match = ParseCommitRegex.Match(logOutputLine.Trim()); - - var commitDate = long.Parse(match.Groups["commitDate"].Value); - - var parentHashes = match.Groups["parentHashes"].Success - ? match.Groups["parentHashes"].Value.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries) - : null; - - var refs = match.Groups["refs"].Success - ? match.Groups["refs"] - .Value - .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) - .Select(r => r.Trim()) - .ToArray() + static readonly Regex ParseCommitRegex = new Regex(@"^(?\d*) (?\w{7,40})(?( \w{7,40})+)?([ ]+\((?.*?)\))?\s?((?.*))?"); + + internal static Commit ParseCommit(string logOutputLine) + { + var match = ParseCommitRegex.Match(logOutputLine.Trim()); + + var commitDate = long.Parse(match.Groups["commitDate"].Value); + + var parentHashes = match.Groups["parentHashes"].Success + ? match.Groups["parentHashes"].Value.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries) + : null; + + var refs = match.Groups["refs"].Success + ? match.Groups["refs"] + .Value + .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) + .Select(r => r.Trim()) + .ToArray() : null; var subject = match.Groups["subject"].Success ? match.Groups["subject"].Value - : null; - - return new Commit - { - Hash = match.Groups["hash"].Value, - CommitDate = commitDate, - ParentHashes = parentHashes, - Refs = refs, - Subject = subject, - }; - } - } -} + : null; + + return new Commit + { + Hash = match.Groups["hash"].Value, + CommitDate = ConvertUnixTimeToLocalTime(commitDate), + ParentHashes = parentHashes, + Refs = refs, + Subject = subject, + }; + } + + private static DateTime ConvertUnixTimeToLocalTime(long unixTime) + { + var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + return dateTime.AddSeconds(unixTime).ToLocalTime(); + } + } +} diff --git a/Logic/ViewModel.cs b/Logic/ViewModel.cs index baadaea..4c586de 100644 --- a/Logic/ViewModel.cs +++ b/Logic/ViewModel.cs @@ -51,14 +51,14 @@ public string RepositoryPath _repositoryPath = value.Trim(); if (IsValidGitRepository(_repositoryPath)) { - commandExecutor = new GitCommandExecutor(_repositoryPath); - logRetriever = new LogRetriever(commandExecutor, _parser); + commandExecutor = new GitCommandExecutor(_repositoryPath); + logRetriever = new LogRetriever(commandExecutor, _parser); RefreshGraph(logRetriever); IsNewRepository = true; _watcher = new RepositoryWatcher(_repositoryPath, IsBareGitRepository(_repositoryPath)); _watcher.ChangeDetected += (sender, args) => RefreshGraph(logRetriever); - OnPropertyChanged("WindowTitle"); + OnPropertyChanged("WindowTitle"); } else { @@ -105,15 +105,15 @@ CommitGraph GenerateGraphFromCommits(IEnumerable commits, string activeR .ToList(); } else - { - commitVertices = commits.Select(c => new Vertex(c)) - .ToList(); + { + commitVertices = commits.Select(c => new Vertex(c)) + .ToList(); } // Add all the vertices var headVertex = new Vertex(new Reference { - Name = Reference.HEAD, + Name = Reference.HEAD, }); foreach (var commitVertex in commitVertices) @@ -162,7 +162,7 @@ CommitGraph GenerateGraphFromCommits(IEnumerable commits, string activeR public CommitGraph Graph { get { return _graph; } - set + set { _graph = value; OnPropertyChanged("Graph"); @@ -205,6 +205,19 @@ public Int32 NumOfCommitsToShow } private Int32 _numOfCommitsToShow; + public bool VisualizeCommitDate + { + get { return _visualizeCommitDate; } + set + { + _visualizeCommitDate = value; + if (logRetriever != null) RefreshGraph(logRetriever); //TODO: Refactor. + OnPropertyChanged("VisualizeCommitDate"); + } + } + + private bool _visualizeCommitDate; + static bool IsValidGitRepository(string path) { return !string.IsNullOrEmpty(path) @@ -213,9 +226,9 @@ static bool IsValidGitRepository(string path) IsBareGitRepository(path)); } - static Boolean IsBareGitRepository(String path) + static Boolean IsBareGitRepository(String path) { - String configFileForBareRepository = Path.Combine(path, "config"); + String configFileForBareRepository = Path.Combine(path, "config"); return File.Exists(configFileForBareRepository) && Regex.IsMatch(File.ReadAllText(configFileForBareRepository), @"bare\s*=\s*true", RegexOptions.IgnoreCase); } @@ -229,18 +242,18 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } - #region Commands + #region Commands - public void ExecuteSelectFolder(Object paramter) + public void ExecuteSelectFolder(Object paramter) { var folder = _wpfSystem.UserChooseFolder(RepositoryPath); - if (!String.IsNullOrEmpty(folder)) + if (!String.IsNullOrEmpty(folder)) { RepositoryPath = folder; } } - #endregion + #endregion } } diff --git a/UI/MainWindow.xaml b/UI/MainWindow.xaml index dab4c8d..b6fa576 100644 --- a/UI/MainWindow.xaml +++ b/UI/MainWindow.xaml @@ -15,10 +15,13 @@ - - + + + + + @@ -82,7 +85,8 @@ - + + From 223be936fa82064649f7418e0d104bd45986abed Mon Sep 17 00:00:00 2001 From: mbassit Date: Mon, 28 Dec 2015 13:53:15 +0000 Subject: [PATCH 3/5] Undone whitespace changes introduced in previous commit --- Logic/ViewModel.cs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Logic/ViewModel.cs b/Logic/ViewModel.cs index 4c586de..ef5cc4a 100644 --- a/Logic/ViewModel.cs +++ b/Logic/ViewModel.cs @@ -51,14 +51,14 @@ public string RepositoryPath _repositoryPath = value.Trim(); if (IsValidGitRepository(_repositoryPath)) { - commandExecutor = new GitCommandExecutor(_repositoryPath); - logRetriever = new LogRetriever(commandExecutor, _parser); + commandExecutor = new GitCommandExecutor(_repositoryPath); + logRetriever = new LogRetriever(commandExecutor, _parser); RefreshGraph(logRetriever); IsNewRepository = true; _watcher = new RepositoryWatcher(_repositoryPath, IsBareGitRepository(_repositoryPath)); _watcher.ChangeDetected += (sender, args) => RefreshGraph(logRetriever); - OnPropertyChanged("WindowTitle"); + OnPropertyChanged("WindowTitle"); } else { @@ -105,15 +105,15 @@ CommitGraph GenerateGraphFromCommits(IEnumerable commits, string activeR .ToList(); } else - { - commitVertices = commits.Select(c => new Vertex(c)) - .ToList(); + { + commitVertices = commits.Select(c => new Vertex(c)) + .ToList(); } // Add all the vertices var headVertex = new Vertex(new Reference { - Name = Reference.HEAD, + Name = Reference.HEAD, }); foreach (var commitVertex in commitVertices) @@ -162,7 +162,7 @@ CommitGraph GenerateGraphFromCommits(IEnumerable commits, string activeR public CommitGraph Graph { get { return _graph; } - set + set { _graph = value; OnPropertyChanged("Graph"); @@ -226,9 +226,9 @@ static bool IsValidGitRepository(string path) IsBareGitRepository(path)); } - static Boolean IsBareGitRepository(String path) + static Boolean IsBareGitRepository(String path) { - String configFileForBareRepository = Path.Combine(path, "config"); + String configFileForBareRepository = Path.Combine(path, "config"); return File.Exists(configFileForBareRepository) && Regex.IsMatch(File.ReadAllText(configFileForBareRepository), @"bare\s*=\s*true", RegexOptions.IgnoreCase); } @@ -242,18 +242,18 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } - #region Commands + #region Commands - public void ExecuteSelectFolder(Object paramter) + public void ExecuteSelectFolder(Object paramter) { var folder = _wpfSystem.UserChooseFolder(RepositoryPath); - if (!String.IsNullOrEmpty(folder)) + if (!String.IsNullOrEmpty(folder)) { RepositoryPath = folder; } } - #endregion + #endregion } } From 91957bda568dbb727c08bd6b754cd5d2c7cf4cf7 Mon Sep 17 00:00:00 2001 From: mbassit Date: Mon, 28 Dec 2015 17:26:47 +0000 Subject: [PATCH 4/5] Switched EOL back to Unix style --- Logic/Commit.cs | 48 ++++++++--------- Logic/LogParser.cs | 128 ++++++++++++++++++++++----------------------- 2 files changed, 88 insertions(+), 88 deletions(-) diff --git a/Logic/Commit.cs b/Logic/Commit.cs index dbfe71b..33ec064 100644 --- a/Logic/Commit.cs +++ b/Logic/Commit.cs @@ -1,24 +1,24 @@ -using System; - -namespace GitViz.Logic -{ - public class Commit - { - public string Hash { get; set; } - - public string[] ParentHashes { get; set; } - - public string[] Refs { get; set; } - - public DateTime CommitDate { get; set; } - - public string Subject { get; set; } - - public string ShortHash - { - get { return Hash.Substring(0, 7); } - } - - - } -} +using System; + +namespace GitViz.Logic +{ + public class Commit + { + public string Hash { get; set; } + + public string[] ParentHashes { get; set; } + + public string[] Refs { get; set; } + + public DateTime CommitDate { get; set; } + + public string Subject { get; set; } + + public string ShortHash + { + get { return Hash.Substring(0, 7); } + } + + + } +} diff --git a/Logic/LogParser.cs b/Logic/LogParser.cs index d50c096..01d8e2a 100644 --- a/Logic/LogParser.cs +++ b/Logic/LogParser.cs @@ -1,64 +1,64 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; - -namespace GitViz.Logic -{ - public class LogParser - { - public readonly string ExpectedOutputFormat = "%ct %H %P %d %s"; - - public IEnumerable ParseCommits(StreamReader gitLogOutput) - { - while (gitLogOutput.BaseStream != null && !gitLogOutput.EndOfStream) - { - var line = gitLogOutput.ReadLine(); - if (string.IsNullOrWhiteSpace(line)) continue; - yield return ParseCommit(line); - } - gitLogOutput.Close(); - } - - static readonly Regex ParseCommitRegex = new Regex(@"^(?\d*) (?\w{7,40})(?( \w{7,40})+)?([ ]+\((?.*?)\))?\s?((?.*))?"); - - internal static Commit ParseCommit(string logOutputLine) - { - var match = ParseCommitRegex.Match(logOutputLine.Trim()); - - var commitDate = long.Parse(match.Groups["commitDate"].Value); - - var parentHashes = match.Groups["parentHashes"].Success - ? match.Groups["parentHashes"].Value.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries) - : null; - - var refs = match.Groups["refs"].Success - ? match.Groups["refs"] - .Value - .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) - .Select(r => r.Trim()) - .ToArray() - : null; - - var subject = match.Groups["subject"].Success - ? match.Groups["subject"].Value - : null; - - return new Commit - { - Hash = match.Groups["hash"].Value, - CommitDate = ConvertUnixTimeToLocalTime(commitDate), - ParentHashes = parentHashes, - Refs = refs, - Subject = subject, - }; - } - - private static DateTime ConvertUnixTimeToLocalTime(long unixTime) - { - var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - return dateTime.AddSeconds(unixTime).ToLocalTime(); - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; + +namespace GitViz.Logic +{ + public class LogParser + { + public readonly string ExpectedOutputFormat = "%ct %H %P %d %s"; + + public IEnumerable ParseCommits(StreamReader gitLogOutput) + { + while (gitLogOutput.BaseStream != null && !gitLogOutput.EndOfStream) + { + var line = gitLogOutput.ReadLine(); + if (string.IsNullOrWhiteSpace(line)) continue; + yield return ParseCommit(line); + } + gitLogOutput.Close(); + } + + static readonly Regex ParseCommitRegex = new Regex(@"^(?\d*) (?\w{7,40})(?( \w{7,40})+)?([ ]+\((?.*?)\))?\s?((?.*))?"); + + internal static Commit ParseCommit(string logOutputLine) + { + var match = ParseCommitRegex.Match(logOutputLine.Trim()); + + var commitDate = long.Parse(match.Groups["commitDate"].Value); + + var parentHashes = match.Groups["parentHashes"].Success + ? match.Groups["parentHashes"].Value.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries) + : null; + + var refs = match.Groups["refs"].Success + ? match.Groups["refs"] + .Value + .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) + .Select(r => r.Trim()) + .ToArray() + : null; + + var subject = match.Groups["subject"].Success + ? match.Groups["subject"].Value + : null; + + return new Commit + { + Hash = match.Groups["hash"].Value, + CommitDate = ConvertUnixTimeToLocalTime(commitDate), + ParentHashes = parentHashes, + Refs = refs, + Subject = subject, + }; + } + + private static DateTime ConvertUnixTimeToLocalTime(long unixTime) + { + var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + return dateTime.AddSeconds(unixTime).ToLocalTime(); + } + } +} From 10d4fbe54c4e548bf40459917c83fe4f7ff37db3 Mon Sep 17 00:00:00 2001 From: mbassit Date: Mon, 28 Dec 2015 18:02:34 +0000 Subject: [PATCH 5/5] Added visualization of committer email --- Logic/Commit.cs | 2 ++ Logic/LogParser.cs | 5 +++-- Logic/ViewModel.cs | 13 +++++++++++++ UI/MainWindow.xaml | 13 +++++++++---- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Logic/Commit.cs b/Logic/Commit.cs index 33ec064..0026242 100644 --- a/Logic/Commit.cs +++ b/Logic/Commit.cs @@ -10,6 +10,8 @@ public class Commit public string[] Refs { get; set; } + public string CommitterEmail { get; set; } + public DateTime CommitDate { get; set; } public string Subject { get; set; } diff --git a/Logic/LogParser.cs b/Logic/LogParser.cs index 01d8e2a..207a050 100644 --- a/Logic/LogParser.cs +++ b/Logic/LogParser.cs @@ -8,7 +8,7 @@ namespace GitViz.Logic { public class LogParser { - public readonly string ExpectedOutputFormat = "%ct %H %P %d %s"; + public readonly string ExpectedOutputFormat = "%ct %ce %H %P %d %s"; public IEnumerable ParseCommits(StreamReader gitLogOutput) { @@ -21,7 +21,7 @@ public IEnumerable ParseCommits(StreamReader gitLogOutput) gitLogOutput.Close(); } - static readonly Regex ParseCommitRegex = new Regex(@"^(?\d*) (?\w{7,40})(?( \w{7,40})+)?([ ]+\((?.*?)\))?\s?((?.*))?"); + static readonly Regex ParseCommitRegex = new Regex(@"^(?\d*) (?.+@[^ ]+) (?\w{7,40})(?( \w{7,40})+)?([ ]+\((?.*?)\))?\s?((?.*))?"); internal static Commit ParseCommit(string logOutputLine) { @@ -49,6 +49,7 @@ internal static Commit ParseCommit(string logOutputLine) { Hash = match.Groups["hash"].Value, CommitDate = ConvertUnixTimeToLocalTime(commitDate), + CommitterEmail = match.Groups["committerEmail"].Value, ParentHashes = parentHashes, Refs = refs, Subject = subject, diff --git a/Logic/ViewModel.cs b/Logic/ViewModel.cs index ef5cc4a..60dc197 100644 --- a/Logic/ViewModel.cs +++ b/Logic/ViewModel.cs @@ -218,6 +218,19 @@ public bool VisualizeCommitDate private bool _visualizeCommitDate; + public bool VisualizeCommitterEmail + { + get { return _visualizeCommitterEmail; } + set + { + _visualizeCommitterEmail = value; + if (logRetriever != null) RefreshGraph(logRetriever); //TODO: Refactor. + OnPropertyChanged("VisualizeCommitterEmail"); + } + } + + private bool _visualizeCommitterEmail; + static bool IsValidGitRepository(string path) { return !string.IsNullOrEmpty(path) diff --git a/UI/MainWindow.xaml b/UI/MainWindow.xaml index b6fa576..5e1b2f5 100644 --- a/UI/MainWindow.xaml +++ b/UI/MainWindow.xaml @@ -16,12 +16,16 @@ - - + + + + + + Converter={logic:BooleanToVisibilityConverter}}" Margin="0,5,0,0" Foreground="Black" FontSize="8pt" FontFamily="Consolas" /> @@ -87,6 +91,7 @@ +