Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/linquize/git-dot-aspx
Browse files Browse the repository at this point in the history
  • Loading branch information
linquize committed Jul 29, 2012
2 parents 851f698 + 71412b0 commit 4da0dc6
Show file tree
Hide file tree
Showing 11 changed files with 611 additions and 160 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -1,3 +1,6 @@
[submodule "lib/GitSharp"] [submodule "lib/GitSharp"]
path = lib/GitSharp path = lib/GitSharp
url = https://github.com/linquize/GitSharp.git url = https://github.com/linquize/GitSharp.git
[submodule "lib/NGit"]
path = lib/NGit
url = https://github.com/linquize/ngit.git
7 changes: 4 additions & 3 deletions GitAspx.Tests/GitAspx.Tests.csproj
Expand Up @@ -35,9 +35,6 @@
<Reference Include="CassiniDev4-lib"> <Reference Include="CassiniDev4-lib">
<HintPath>..\lib\cassinidev\CassiniDev4-lib.dll</HintPath> <HintPath>..\lib\cassinidev\CassiniDev4-lib.dll</HintPath>
</Reference> </Reference>
<Reference Include="GitSharp.Core">
<HintPath>..\lib\GitSharp\GitSharp.Core.dll</HintPath>
</Reference>
<Reference Include="Moq"> <Reference Include="Moq">
<HintPath>..\lib\moq\Moq.dll</HintPath> <HintPath>..\lib\moq\Moq.dll</HintPath>
</Reference> </Reference>
Expand Down Expand Up @@ -70,6 +67,10 @@
<Project>{3A732219-72CE-49B8-84F6-FE74E3762EE7}</Project> <Project>{3A732219-72CE-49B8-84F6-FE74E3762EE7}</Project>
<Name>GitAspx</Name> <Name>GitAspx</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\lib\GitSharp\GitSharp.Core\GitSharp.Core-VS2010.csproj">
<Project>{C46EDD61-C202-465A-93F1-ADE20A83BB59}</Project>
<Name>GitSharp.Core-VS2010</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
18 changes: 18 additions & 0 deletions GitAspx.sln
Expand Up @@ -9,6 +9,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp-VS2010", "lib\GitS
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp.Core-VS2010", "lib\GitSharp\GitSharp.Core\GitSharp.Core-VS2010.csproj", "{C46EDD61-C202-465A-93F1-ADE20A83BB59}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp.Core-VS2010", "lib\GitSharp\GitSharp.Core\GitSharp.Core-VS2010.csproj", "{C46EDD61-C202-465A-93F1-ADE20A83BB59}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NGit", "lib\NGit\NGit\NGit.csproj", "{E3BFF8B4-189C-496A-A817-7E8B31E22B91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSch", "lib\NGit\NSch\NSch.csproj", "{A19E6F3F-A25B-4B01-8922-CF0CC35C781D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sharpen", "lib\NGit\Sharpen\Sharpen.csproj", "{72944A6C-45FF-4EF8-B349-8C9CABF519D4}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Expand All @@ -31,6 +37,18 @@ Global
{C46EDD61-C202-465A-93F1-ADE20A83BB59}.Debug|Any CPU.Build.0 = Debug|Any CPU {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C46EDD61-C202-465A-93F1-ADE20A83BB59}.Release|Any CPU.ActiveCfg = Release|Any CPU {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C46EDD61-C202-465A-93F1-ADE20A83BB59}.Release|Any CPU.Build.0 = Release|Any CPU {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Release|Any CPU.Build.0 = Release|Any CPU
{E3BFF8B4-189C-496A-A817-7E8B31E22B91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3BFF8B4-189C-496A-A817-7E8B31E22B91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3BFF8B4-189C-496A-A817-7E8B31E22B91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3BFF8B4-189C-496A-A817-7E8B31E22B91}.Release|Any CPU.Build.0 = Release|Any CPU
{A19E6F3F-A25B-4B01-8922-CF0CC35C781D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A19E6F3F-A25B-4B01-8922-CF0CC35C781D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A19E6F3F-A25B-4B01-8922-CF0CC35C781D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A19E6F3F-A25B-4B01-8922-CF0CC35C781D}.Release|Any CPU.Build.0 = Release|Any CPU
{72944A6C-45FF-4EF8-B349-8C9CABF519D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72944A6C-45FF-4EF8-B349-8C9CABF519D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72944A6C-45FF-4EF8-B349-8C9CABF519D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72944A6C-45FF-4EF8-B349-8C9CABF519D4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
Expand Down
13 changes: 12 additions & 1 deletion GitAspx/GitAspx.csproj
Expand Up @@ -89,10 +89,13 @@
<Compile Include="Lib\AppSettings.cs" /> <Compile Include="Lib\AppSettings.cs" />
<Compile Include="Lib\ForbiddenResult.cs" /> <Compile Include="Lib\ForbiddenResult.cs" />
<Compile Include="Lib\WebBrowsingSettings.cs" /> <Compile Include="Lib\WebBrowsingSettings.cs" />
<Compile Include="Lib\SimpleRefWriter.cs" /> <Compile Include="Lib\GitSharpCoreBasedSimpleRefWriter.cs" />
<Compile Include="Lib\NotFoundResult.cs" /> <Compile Include="Lib\NotFoundResult.cs" />
<Compile Include="Lib\GitRepository.cs" /> <Compile Include="Lib\GitRepository.cs" />
<Compile Include="Lib\StructureMapControllerFactory.cs" /> <Compile Include="Lib\StructureMapControllerFactory.cs" />
<Compile Include="Lib\GitSharpCoreBasedRepository.cs" />
<Compile Include="Lib\NGitBasedRepository.cs" />
<Compile Include="Lib\NGitBasedSimpleRefWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Lib\RepositoryService.cs" /> <Compile Include="Lib\RepositoryService.cs" />
<Compile Include="PrettyDate.cs" /> <Compile Include="PrettyDate.cs" />
Expand Down Expand Up @@ -236,6 +239,14 @@
<Project>{7311850F-619A-4241-B09F-157792C75FBA}</Project> <Project>{7311850F-619A-4241-B09F-157792C75FBA}</Project>
<Name>GitSharp</Name> <Name>GitSharp</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\lib\NGit\NGit\NGit.csproj">
<Project>{E3BFF8B4-189C-496A-A817-7E8B31E22B91}</Project>
<Name>NGit</Name>
</ProjectReference>
<ProjectReference Include="..\lib\NGit\Sharpen\Sharpen.csproj">
<Project>{72944A6C-45FF-4EF8-B349-8C9CABF519D4}</Project>
<Name>Sharpen</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Views\TreeView\EmptyRepository.cshtml" /> <Content Include="Views\TreeView\EmptyRepository.cshtml" />
Expand Down
134 changes: 11 additions & 123 deletions GitAspx/Lib/GitRepository.cs
@@ -1,97 +1,33 @@
namespace GitAspx.Lib namespace GitAspx.Lib
{ {
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using GitSharp.Core;
using GitSharp.Core.Transport;


public class GitRepository public abstract class GitRepository
{ {
private DirectoryInfo directory; protected DirectoryInfo directory;
string rootDirectory; protected string rootDirectory;


public static GitRepository Open(DirectoryInfo directory, string rootDirectory) public static GitRepository Open(DirectoryInfo directory, string rootDirectory)
{ {
if (GitSharp.Repository.IsValid(directory.FullName)) return new NGitBasedRepository(directory, rootDirectory);
{
return new GitRepository(directory, rootDirectory);
}

return null;
} }


public GitRepository(DirectoryInfo directory, string rootDirectory) protected GitRepository(DirectoryInfo directory, string rootDirectory)
{ {
this.directory = directory; this.directory = directory;
this.rootDirectory = rootDirectory; this.rootDirectory = rootDirectory;
} }


public void AdvertiseUploadPack(Stream output) public abstract void AdvertiseUploadPack(Stream output);
{
using (var repository = GetRepository())
{
var pack = new UploadPack(repository);
pack.sendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
}
}


public void AdvertiseReceivePack(Stream output) public abstract void AdvertiseReceivePack(Stream output);
{
using (var repository = GetRepository())
{
var pack = new ReceivePack(repository);
pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
}
}


public void Receive(Stream inputStream, Stream outputStream) public abstract void Receive(Stream inputStream, Stream outputStream);
{
using (var repository = GetRepository())
{
var pack = new ReceivePack(repository);
pack.setBiDirectionalPipe(false);
pack.receive(inputStream, outputStream, outputStream);
}
}


public void Upload(Stream inputStream, Stream outputStream) public abstract void Upload(Stream inputStream, Stream outputStream);
{
using (var repository = GetRepository())
{
using (var pack = new UploadPack(repository))
{
pack.setBiDirectionalPipe(false);
pack.Upload(inputStream, outputStream, outputStream);
}
}
}


public CommitInfo GetLatestCommit() public abstract CommitInfo GetLatestCommit();
{
using (var repository = new GitSharp.Repository(PhysicalPathDotGit))
{
var commit = repository.Head.CurrentCommit;

if (commit == null)
{
return null;
}

return new CommitInfo
{
Message = commit.Message,
Date = commit.CommitDate.LocalDateTime
};
}
}

private GitSharp.Core.Repository GetRepository()
{
return GitSharp.Core.Repository.Open(directory);
}


public string Name public string Name
{ {
Expand Down Expand Up @@ -151,55 +87,7 @@ public string GitDirectory()
return Path.Combine(PhysicalPathDotGit, ".git"); return Path.Combine(PhysicalPathDotGit, ".git");
} }


public void UpdateServerInfo() public abstract void UpdateServerInfo();
{
using (var rep = GetRepository())
{
if (rep.ObjectDatabase is ObjectDirectory)
{
RefWriter rw = new SimpleRefWriter(rep, rep.getAllRefs().Values);
rw.writePackedRefs();
rw.writeInfoRefs();

var packs = GetPackRefs(rep);
WriteInfoPacks(packs, rep);
}
}
}

private void WriteInfoPacks(IEnumerable<string> packs, GitSharp.Core.Repository repository)
{

var w = new StringBuilder();

foreach (string pack in packs)
{
w.Append("P ");
w.Append(pack);
w.Append('\n');
}

var infoPacksPath = Path.Combine(repository.ObjectsDirectory.FullName, "info/packs");
var encoded = Encoding.ASCII.GetBytes(w.ToString());


using (Stream fs = File.Create(infoPacksPath))
{
fs.Write(encoded, 0, encoded.Length);
}
}

private IEnumerable<string> GetPackRefs(GitSharp.Core.Repository repository)
{
var packDir = repository.ObjectsDirectory.GetDirectories().SingleOrDefault(x => x.Name == "pack");

if (packDir == null)
{
return Enumerable.Empty<string>();
}

return packDir.GetFiles("*.pack").Select(x => x.Name).ToList();
}
} }


public class CommitInfo public class CommitInfo
Expand Down
132 changes: 132 additions & 0 deletions GitAspx/Lib/GitSharpCoreBasedRepository.cs
@@ -0,0 +1,132 @@
namespace GitAspx.Lib
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using GitSharp.Core;
using GitSharp.Core.Transport;

public class GitSharpCoreBasedRepository : GitRepository
{
public GitSharpCoreBasedRepository(DirectoryInfo directory, string rootDirectory)
: base(directory, rootDirectory)
{
}

public override void AdvertiseUploadPack(Stream output)
{
using (var repository = GetRepository())
{
var pack = new UploadPack(repository);
pack.sendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
}
}

public override void AdvertiseReceivePack(Stream output)
{
using (var repository = GetRepository())
{
var pack = new ReceivePack(repository);
pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
}
}

public override void Receive(Stream inputStream, Stream outputStream)
{
using (var repository = GetRepository())
{
var pack = new ReceivePack(repository);
pack.setBiDirectionalPipe(false);
pack.receive(inputStream, outputStream, outputStream);
}
}

public override void Upload(Stream inputStream, Stream outputStream)
{
using (var repository = GetRepository())
{
using (var pack = new UploadPack(repository))
{
pack.setBiDirectionalPipe(false);
pack.Upload(inputStream, outputStream, outputStream);
}
}
}

public override CommitInfo GetLatestCommit()
{
using (var repository = new GitSharp.Repository(PhysicalPathDotGit))
{
var commit = repository.Head.CurrentCommit;

if (commit == null)
{
return null;
}

return new CommitInfo
{
Message = commit.Message,
Date = commit.CommitDate.LocalDateTime
};
}
}

private GitSharp.Core.Repository GetRepository()
{
return GitSharp.Core.Repository.Open(directory);
}

public override void UpdateServerInfo()
{
using (var rep = GetRepository())
{
if (rep.ObjectDatabase is ObjectDirectory)
{
RefWriter rw = new GitSharpCoreBasedSimpleRefWriter(rep, rep.getAllRefs().Values);
rw.writePackedRefs();
rw.writeInfoRefs();

var packs = GetPackRefs(rep);
WriteInfoPacks(packs, rep);
}
}
}

private void WriteInfoPacks(IEnumerable<string> packs, GitSharp.Core.Repository repository)
{

var w = new StringBuilder();

foreach (string pack in packs)
{
w.Append("P ");
w.Append(pack);
w.Append('\n');
}

var infoPacksPath = Path.Combine(repository.ObjectsDirectory.FullName, "info/packs");
var encoded = Encoding.ASCII.GetBytes(w.ToString());


using (Stream fs = File.Create(infoPacksPath))
{
fs.Write(encoded, 0, encoded.Length);
}
}

private IEnumerable<string> GetPackRefs(GitSharp.Core.Repository repository)
{
var packDir = repository.ObjectsDirectory.GetDirectories().SingleOrDefault(x => x.Name == "pack");

if (packDir == null)
{
return Enumerable.Empty<string>();
}

return packDir.GetFiles("*.pack").Select(x => x.Name).ToList();
}
}
}

0 comments on commit 4da0dc6

Please sign in to comment.