Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f7a4977
Showing
35 changed files
with
1,126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Oo]bj/ | ||
[Bb]in/ | ||
*.user | ||
/TestResults | ||
*.vspscc | ||
*.vssscc | ||
*.suo | ||
*.[Cc]ache | ||
*.csproj.user | ||
/packages/ | ||
msbuild.log | ||
*.psess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<solution> | ||
<add key="disableSourceControlIntegration" value="true" /> | ||
</solution> | ||
</configuration> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir> | ||
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath> | ||
<NuGetExePath>$(NuGetToolsPath)\nuget.exe</NuGetExePath> | ||
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig> | ||
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir> | ||
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir> | ||
|
||
<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config --> | ||
<PackageSources>""</PackageSources> | ||
|
||
<!-- Enable the restore command to run before builds --> | ||
<RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages> | ||
|
||
<!-- Property that enables building a package from a project --> | ||
<BuildPackage Condition="$(BuildPackage) == ''">false</BuildPackage> | ||
|
||
<!-- Commands --> | ||
<RestoreCommand>"$(NuGetExePath)" install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"</RestoreCommand> | ||
<BuildCommand>"$(NuGetExePath)" pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand> | ||
|
||
<!-- Make the build depend on restore packages --> | ||
<BuildDependsOn Condition="$(RestorePackages) == 'true'"> | ||
RestorePackages; | ||
$(BuildDependsOn); | ||
</BuildDependsOn> | ||
|
||
<!-- Make the build depend on restore packages --> | ||
<BuildDependsOn Condition="$(BuildPackage) == 'true'"> | ||
$(BuildDependsOn); | ||
BuildPackage; | ||
</BuildDependsOn> | ||
</PropertyGroup> | ||
|
||
<Target Name="CheckPrerequisites"> | ||
<!-- Raise an error if we're unable to locate nuget.exe --> | ||
<Error Condition="!Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" /> | ||
</Target> | ||
|
||
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites"> | ||
<Exec Command="$(RestoreCommand)" | ||
LogStandardErrorAsError="true" | ||
Condition="Exists('$(PackagesConfig)')" /> | ||
</Target> | ||
|
||
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites"> | ||
<Exec Command="$(BuildCommand)" | ||
LogStandardErrorAsError="true" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "git-demo-viewer", "git-demo-viewer\git-demo-viewer.csproj", "{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|Mixed Platforms = Debug|Mixed Platforms | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|Mixed Platforms = Release|Mixed Platforms | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Debug|Any CPU.ActiveCfg = Debug|x86 | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Debug|Mixed Platforms.Build.0 = Debug|x86 | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Debug|x86.ActiveCfg = Debug|x86 | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Debug|x86.Build.0 = Debug|x86 | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Release|Any CPU.ActiveCfg = Release|x86 | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Release|Mixed Platforms.ActiveCfg = Release|x86 | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Release|Mixed Platforms.Build.0 = Release|x86 | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Release|x86.ActiveCfg = Release|x86 | ||
{79FE31D5-8F65-49E0-A077-5DE488F9CD2B}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Application x:Class="git_demo_viewer.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Windows; | ||
|
||
namespace git_demo_viewer | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.ComponentModel; | ||
using git_demo_viewer.Graph; | ||
using LibGit2Sharp; | ||
|
||
namespace git_demo_viewer | ||
{ | ||
public class GitViewModel : INotifyPropertyChanged | ||
{ | ||
private GitGraph graph; | ||
private Repository repository; | ||
|
||
public GitGraph Graph | ||
{ | ||
get { return graph; } | ||
set | ||
{ | ||
this.graph = value; | ||
NotifyPropertyChanged("Graph"); | ||
} | ||
} | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
public GitViewModel(Repository repo) | ||
{ | ||
this.repository = repo; | ||
|
||
this.Reload(); | ||
} | ||
|
||
public void Reload() | ||
{ | ||
var g = new GitGraph(); | ||
this.Refresh(g); | ||
this.Graph = g; | ||
} | ||
|
||
public void Refresh() | ||
{ | ||
this.Refresh(this.graph); | ||
} | ||
|
||
public void Refresh(GitGraph graph) | ||
{ | ||
foreach (var branch in this.repository.Branches) | ||
{ | ||
if (!branch.CanonicalName.EndsWith("/HEAD")) | ||
{ | ||
if (AddBranch(graph, branch) == null) | ||
return; | ||
} | ||
} | ||
|
||
} | ||
|
||
private BranchVertex AddBranch(GitGraph graph, Branch branch) | ||
{ | ||
BranchVertex bv; | ||
BranchEdge be; | ||
CommitVertex cv; | ||
|
||
if (graph.TryGetBranchVertex(branch.Name, out bv)) | ||
{ | ||
if (bv.Branch.Tip.Sha == branch.Tip.Sha) | ||
return bv; | ||
|
||
// Found the branch but it's pointing to another commit. Let's remove it | ||
// and re-add it | ||
|
||
if (graph.TryGetCommitVertex(bv.Branch.Tip.Sha, out cv)) | ||
{ | ||
GitEdge e; | ||
|
||
if (this.graph.TryGetEdge(bv, cv, out e)) | ||
this.graph.RemoveEdge(e); | ||
} | ||
|
||
this.graph.RemoveVertex(bv); | ||
} | ||
|
||
cv = AddCommit(graph, branch.Tip); | ||
|
||
if (cv == null) | ||
return null; | ||
|
||
if (bv == null) | ||
bv = new BranchVertex(branch); | ||
|
||
be = new BranchEdge(bv, cv); | ||
|
||
graph.AddVertex(bv); | ||
graph.AddEdge(be); | ||
|
||
return bv; | ||
} | ||
|
||
private CommitVertex AddCommit(GitGraph graph, Commit commit, int depth = 0) | ||
{ | ||
if (depth > 25) | ||
return null; | ||
|
||
CommitVertex existing; | ||
|
||
if (graph.TryGetCommitVertex(commit.Sha, out existing)) | ||
return existing; | ||
|
||
var vertex = new CommitVertex(commit); | ||
graph.AddCommitVertex(vertex); | ||
|
||
foreach (var parent in commit.Parents) | ||
{ | ||
var parentVertex = AddCommit(graph, parent, depth + 1); | ||
|
||
if (parentVertex != null) | ||
graph.AddEdge(new CommitEdge(vertex, parentVertex)); | ||
} | ||
|
||
return vertex; | ||
} | ||
|
||
private void NotifyPropertyChanged(String info) | ||
{ | ||
if (PropertyChanged != null) | ||
PropertyChanged(this, new PropertyChangedEventArgs(info)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using LibGit2Sharp; | ||
using QuickGraph; | ||
|
||
namespace git_demo_viewer.Graph | ||
{ | ||
public class BranchEdge : GitEdge | ||
{ | ||
public BranchEdge(BranchVertex source, CommitVertex target) : | ||
base(source, target) | ||
{ | ||
this.BranchVertex = source; | ||
this.CommitVertex = target; | ||
} | ||
|
||
public override string Title | ||
{ | ||
get { return this.BranchVertex.Branch.Name + " is at " + this.CommitVertex.Title; } | ||
} | ||
|
||
public BranchVertex BranchVertex { get; set; } | ||
|
||
public CommitVertex CommitVertex { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using LibGit2Sharp; | ||
|
||
namespace git_demo_viewer.Graph | ||
{ | ||
public class BranchVertex: GitVertex | ||
{ | ||
public Branch Branch { get; set; } | ||
public override string Title | ||
{ | ||
get { return Branch.Name; } | ||
} | ||
|
||
public BranchVertex(Branch b) | ||
{ | ||
this.Branch = b; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using LibGit2Sharp; | ||
using QuickGraph; | ||
|
||
namespace git_demo_viewer.Graph | ||
{ | ||
public class CommitEdge : GitEdge | ||
{ | ||
public CommitEdge(CommitVertex source, CommitVertex target) | ||
: base(source, target) | ||
{ | ||
this.SourceCommitVertex = source; | ||
this.TargetCommitVertex = target; | ||
} | ||
|
||
|
||
public override string Title | ||
{ | ||
get { return SourceCommitVertex.Title + " is child of " + TargetCommitVertex.Title; } | ||
} | ||
|
||
public CommitVertex SourceCommitVertex { get; set; } | ||
|
||
public CommitVertex TargetCommitVertex { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using LibGit2Sharp; | ||
|
||
namespace git_demo_viewer.Graph | ||
{ | ||
public class CommitVertex : GitVertex | ||
{ | ||
public Commit Commit { get; set; } | ||
|
||
public override string Title | ||
{ | ||
get { return this.Commit.Sha.Substring(0, 6); } | ||
} | ||
|
||
public string Subject | ||
{ | ||
get | ||
{ | ||
if (this.Commit.MessageShort.Length <= 25) | ||
return this.Commit.MessageShort; | ||
|
||
return this.Commit.MessageShort.Substring(0, 25); | ||
} | ||
} | ||
|
||
public CommitVertex(Commit commit) | ||
{ | ||
this.Commit = commit; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return this.Title; | ||
} | ||
} | ||
} |
Oops, something went wrong.