Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Logic/Commit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GitViz.Logic
using System;

namespace GitViz.Logic
{
public class Commit
{
Expand All @@ -8,15 +10,17 @@ public class Commit

public string[] Refs { get; set; }

public long CommitDate { get; set; }

public string CommitterEmail { get; set; }

public DateTime CommitDate { get; set; }

public string Subject { get; set; }

public string ShortHash
{
get { return Hash.Substring(0, 7); }
}
}


}
}
25 changes: 16 additions & 9 deletions Logic/LogParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Commit> ParseCommits(StreamReader gitLogOutput)
{
Expand All @@ -19,9 +19,9 @@ public IEnumerable<Commit> ParseCommits(StreamReader gitLogOutput)
yield return ParseCommit(line);
}
gitLogOutput.Close();
}
static readonly Regex ParseCommitRegex = new Regex(@"^(?<commitDate>\d*) (?<hash>\w{7,40})(?<parentHashes>( \w{7,40})+)?([ ]+\((?<refs>.*?)\))?\s?((?<subject>.*))?");
}

static readonly Regex ParseCommitRegex = new Regex(@"^(?<commitDate>\d*) (?<committerEmail>.+@[^ ]+) (?<hash>\w{7,40})(?<parentHashes>( \w{7,40})+)?([ ]+\((?<refs>.*?)\))?\s?((?<subject>.*))?");

internal static Commit ParseCommit(string logOutputLine)
{
Expand All @@ -39,20 +39,27 @@ internal static Commit ParseCommit(string logOutputLine)
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(r => r.Trim())
.ToArray()
: null;
var subject = match.Groups["subject"].Success
? match.Groups["subject"].Value
: null;

var subject = match.Groups["subject"].Success
? match.Groups["subject"].Value
: null;

return new Commit
{
Hash = match.Groups["hash"].Value,
CommitDate = commitDate,
CommitDate = ConvertUnixTimeToLocalTime(commitDate),
CommitterEmail = match.Groups["committerEmail"].Value,
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();
}
}
}
28 changes: 27 additions & 1 deletion Logic/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public string RepositoryPath
get { return _repositoryPath; }
set
{
_repositoryPath = value;
_repositoryPath = value.Trim();
if (IsValidGitRepository(_repositoryPath))
{
commandExecutor = new GitCommandExecutor(_repositoryPath);
Expand Down Expand Up @@ -205,6 +205,32 @@ 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;

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)
Expand Down
19 changes: 14 additions & 5 deletions UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
<DataTemplate x:Key="CommitTemplate" DataType="{x:Type logic:Vertex}">
<Border x:Name="Border" BorderBrush="DarkSlateGray" Background="#daf5dd" BorderThickness="3" CornerRadius="10,10,10,10" Padding="10">
<StackPanel>
<TextBlock Text="{Binding Path=Commit.ShortHash, Mode=OneWay}" Foreground="Black" FontSize="14pt" FontFamily="Consolas" />
<TextBlock Text="{Binding Path=Commit.Subject, Mode=OneWay}"
Visibility="{Binding Path=DataContext.VisualizeComments, RelativeSource={RelativeSource AncestorType=Window}, Converter={logic:BooleanToVisibilityConverter}}"
Foreground="Black" FontSize="8pt" FontFamily="Consolas" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Commit.ShortHash, Mode=OneWay}" VerticalAlignment="Center" Foreground="Black" FontSize="16pt" FontFamily="Consolas"/>
<StackPanel>
<TextBlock Text="{Binding Path=Commit.CommitDate, StringFormat=dd/MM/yy HH:mm, Mode=OneWay}" Visibility="{Binding Path=DataContext.VisualizeCommitDate, RelativeSource={RelativeSource AncestorType=Window},
Converter={logic:BooleanToVisibilityConverter}}" Margin="10,0,0,0" VerticalAlignment="Top" Foreground="Black" FontSize="8pt" FontFamily="Consolas" />
<TextBlock Text="{Binding Path=Commit.CommitterEmail, Mode=OneWay}" Visibility="{Binding Path=DataContext.VisualizeCommitterEmail, RelativeSource={RelativeSource AncestorType=Window},
Converter={logic:BooleanToVisibilityConverter}}" Margin="10,0,0,0" VerticalAlignment="Bottom" Foreground="Black" FontSize="8pt" FontFamily="Consolas" />
</StackPanel>
</StackPanel>
<TextBlock Text="{Binding Path=Commit.Subject, Mode=OneWay}" Visibility="{Binding Path=DataContext.VisualizeComments, RelativeSource={RelativeSource AncestorType=Window},
Converter={logic:BooleanToVisibilityConverter}}" Margin="0,5,0,0" Foreground="Black" FontSize="8pt" FontFamily="Consolas" />
</StackPanel>
</Border>
<DataTemplate.Triggers>
Expand Down Expand Up @@ -82,7 +89,9 @@
</DockPanel>
<StackPanel DockPanel.Dock="Left" VerticalAlignment="Center" Margin="5" >
<CheckBox Content="Visualize Deleted" VerticalAlignment="Center" IsChecked="{Binding VisualizeUnreachable}"/>
<CheckBox Margin="0,2,0,0" Content="Show Comments" VerticalAlignment="Center" IsChecked="{Binding VisualizeComments}"/>
<CheckBox Content="Show Comments" VerticalAlignment="Center" IsChecked="{Binding VisualizeComments}"/>
<CheckBox Content="Show Commit Date" VerticalAlignment="Center" IsChecked="{Binding VisualizeCommitDate}"/>
<CheckBox Content="Show Committer Email" VerticalAlignment="Center" IsChecked="{Binding VisualizeCommitterEmail}"/>
</StackPanel>

<StackPanel DockPanel.Dock="Left" VerticalAlignment="Center" Orientation="Horizontal" Margin="5">
Expand Down