Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Repository Tree Graph #820

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
60 changes: 60 additions & 0 deletions Bonobo.Git.Graph/Bonobo.Git.Graph.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{17BDF247-34CF-4EFF-8C5C-CE49FA904396}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Bonobo.Git.Graph</RootNamespace>
<AssemblyName>Bonobo.Git.Graph</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Services" />
<Reference Include="System.Data.Services.Client" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commit.cs" />
<Compile Include="Git.cs" />
<Compile Include="GitDataSource.cs" />
<Compile Include="Graph.cs" />
<Compile Include="GraphLink.cs" />
<Compile Include="GraphNode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Ref.cs" />
<Compile Include="Repository.cs" />
<Compile Include="Tree.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
18 changes: 18 additions & 0 deletions Bonobo.Git.Graph/Commit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Data.Services.Common;

namespace Bonobo.Git.Graph
{
[DataServiceKey("Id")]
public class Commit
{
public string Id { get; set; }
public string ParentIds { get; set; }
public string Message { get; set; }
public string CommitterName { get; set; }
public string CommitterEmail { get; set; }
public DateTime CommitDate { get; set; }
public string CommitDateRelative { get; set; }
public Tree Tree { get; set; }
}
}
101 changes: 101 additions & 0 deletions Bonobo.Git.Graph/Git.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Configuration;
using System.IO;
using System.Web.Hosting;

namespace Bonobo.Git.Graph
{
public abstract class Git
{
private const string TRACE_CATEGORY = "git";
public const string GIT_EXTENSION = "git";

public static string Run(string args, string workingDirectory)
{
var GitPath = HostingEnvironment.MapPath(ConfigurationManager.AppSettings["GitPath"]);

Trace.WriteLine(string.Format("{2}>{0} {1}", GitPath, args, workingDirectory), TRACE_CATEGORY);

var pinfo = new ProcessStartInfo(GitPath)
{
Arguments = args,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = workingDirectory,
};

using (var process = Process.Start(pinfo))
{
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();

Trace.WriteLine(output, TRACE_CATEGORY);

if (!string.IsNullOrEmpty(error))
{
Trace.WriteLine("STDERR: " + error, TRACE_CATEGORY);
throw new Exception(error);
}
return output;
}
}


public static void RunCmd(string args, string workingDirectory)
{

var GitPath = HostingEnvironment.MapPath(ConfigurationManager.AppSettings["GitPath"]);

Trace.WriteLine(string.Format("{2}>{0} {1}", GitPath, args, workingDirectory), TRACE_CATEGORY);

var pinfo = new ProcessStartInfo("cmd.exe")
{
Arguments = "/C \"\"" + GitPath + "\"\" " + args,
CreateNoWindow = true,
RedirectStandardError = true,
UseShellExecute = false,
WorkingDirectory = workingDirectory,
};

using (var process = Process.Start(pinfo))
{
string error = process.StandardError.ReadToEnd();
process.WaitForExit();

if (!string.IsNullOrEmpty(error))
throw new Exception(error);
}
}

public static void RunGitCmd(string args)
{
var GitPath = HostingEnvironment.MapPath(ConfigurationManager.AppSettings["GitPath"]);

Trace.WriteLine(string.Format("{2}>{0} {1}", GitPath, args, ""), TRACE_CATEGORY);

var pinfo = new ProcessStartInfo("cmd.exe")
{
Arguments = "/C " + Path.GetFileName(GitPath) + " " + args,
CreateNoWindow = true,
RedirectStandardError = true,
UseShellExecute = false,
WorkingDirectory = Path.GetDirectoryName(GitPath),
};

using (var process = Process.Start(pinfo))
{
string error = process.StandardError.ReadToEnd();
process.WaitForExit();

if (!string.IsNullOrEmpty(error)) throw new Exception(error);
}
}
}
}
58 changes: 58 additions & 0 deletions Bonobo.Git.Graph/GitDataSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.IO;

namespace Bonobo.Git.Graph
{
public class GitDataSource
{
private string _DefaultRepositoriesDirectory{ get; set; }

public GitDataSource(string DefaultRepositoriesDirectory)
{
_DefaultRepositoriesDirectory = DefaultRepositoriesDirectory;
}

public IQueryable<Repository> Repositories
{
get
{
var directoryInfo = new DirectoryInfo(_DefaultRepositoriesDirectory);

var repos= from dir in directoryInfo.EnumerateDirectories("*", SearchOption.AllDirectories)
where Repository.IsValid(dir.FullName)
select Repository.Open(dir.FullName, _DefaultRepositoriesDirectory);

return repos.AsQueryable();
}
}

public IQueryable<Graph> RepositoryGraph
{
get
{
var directoryInfo = new DirectoryInfo(_DefaultRepositoriesDirectory);

var repos = from dir in directoryInfo.EnumerateDirectories("*", SearchOption.AllDirectories)
where Repository.IsValid(dir.FullName)
select new Graph(Repository.Open(dir.FullName, _DefaultRepositoriesDirectory));

return repos.AsQueryable();
}
}

public IQueryable<Commit> Commits { get { return null; } }

public IQueryable<Tree> Trees { get { return null; } }

public IQueryable<Ref> Refs { get { return null; } }

public IQueryable<GraphNode> GraphNodes { get { return null; } }

public IQueryable<GraphLink> GraphLinks { get { return null; } }

}
}
126 changes: 126 additions & 0 deletions Bonobo.Git.Graph/Graph.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Services.Common;

namespace Bonobo.Git.Graph
{
[DataServiceKey("Id")]
public class Graph
{
private Repository repository;
private IList<GraphNode> nodes;
private IList<GraphLink> links;

public string Name { get; set; }
public string Id { get; set; }

public IEnumerable<GraphNode> Nodes
{
get
{
if (nodes == null) GenerateGraph();
return nodes;
}
}

public IEnumerable<GraphLink> Links
{
get
{
if (links == null) GenerateGraph();
return links;
}
}

public Graph(Repository repository)
{
this.repository = repository;
this.Name = repository.Name;
this.Id = repository.Id;
}

private void GenerateGraph()
{
if (repository == null) return;

nodes = new List<GraphNode>();
links = new List<GraphLink>();
var lanes = new List<string>();

int i = 0;

var commits = repository.Commits.ToList();
var refs = repository.Refs.ToArray();

foreach (var commit in commits)
{
var id = commit.Id;
var tags = from r in refs
where r.Type == "tags" && r.Id == id
select r.ToString();

var branches = from r in refs
where r.Type == "heads" && r.Id == id
select r.ToString();

var children = from c in commits
where c.ParentIds.Contains(id)
select c;


var lane = -1;
if (children.Count() > 1)
{
lanes.Clear();
}
else
{
var child = children.Where(c=>c.ParentIds.IndexOf(id)==0)
.Select(c=>c.Id).FirstOrDefault();

lane = lanes.IndexOf(child);
}

if (lane < 0)
{
lanes.Add(id);
lane = lanes.Count - 1;
}
else
{
lanes[lane] = id;
}

var node = new GraphNode
{
X = lane, Y = i++, Id = id, Message = commit.Message,
CommitterName = commit.CommitterName, CommitDateRelative = commit.CommitDateRelative,
Tags = string.Join(",", tags),
Branches = string.Join(",", branches),
};

nodes.Add(node);

foreach (var ch in children)
{
var cnode = (from n in nodes
where n.Id == ch.Id
select n).FirstOrDefault();
if (cnode != null)
{
links.Add(new GraphLink
{
X1 = cnode.X,
Y1 = cnode.Y,
X2 = node.X,
Y2 = node.Y,
Id = id
});
}
}
}
}
}
}
19 changes: 19 additions & 0 deletions Bonobo.Git.Graph/GraphLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Services.Common;

namespace Bonobo.Git.Graph
{
[DataServiceKey("Id")]
public class GraphLink
{
public string Id { get; set; }
public int X1 { get; set; }
public int Y1 { get; set; }
public int X2 { get; set; }
public int Y2 { get; set; }

}
}
Loading