Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use NGit as backend library for HTTP services

  • Loading branch information...
commit 71412b07c48eab70c0404384ec04acc04d5ef0f1 1 parent 3679a76
@linquize authored
View
18 GitAspx.sln
@@ -9,6 +9,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp-VS2010", "lib\GitS
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp.Core-VS2010", "lib\GitSharp\GitSharp.Core\GitSharp.Core-VS2010.csproj", "{C46EDD61-C202-465A-93F1-ADE20A83BB59}"
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
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -31,6 +37,18 @@ Global
{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.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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
13 GitAspx/GitAspx.csproj
@@ -89,10 +89,13 @@
<Compile Include="Lib\AppSettings.cs" />
<Compile Include="Lib\ForbiddenResult.cs" />
<Compile Include="Lib\WebBrowsingSettings.cs" />
- <Compile Include="Lib\SimpleRefWriter.cs" />
+ <Compile Include="Lib\GitSharpCoreBasedSimpleRefWriter.cs" />
<Compile Include="Lib\NotFoundResult.cs" />
<Compile Include="Lib\GitRepository.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="Lib\RepositoryService.cs" />
<Compile Include="PrettyDate.cs" />
@@ -236,6 +239,14 @@
<Project>{7311850F-619A-4241-B09F-157792C75FBA}</Project>
<Name>GitSharp</Name>
</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>
<Content Include="Views\TreeView\EmptyRepository.cshtml" />
View
134 GitAspx/Lib/GitRepository.cs
@@ -1,97 +1,33 @@
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 GitRepository
+ public abstract class GitRepository
{
- private DirectoryInfo directory;
- string rootDirectory;
+ protected DirectoryInfo directory;
+ protected string rootDirectory;
public static GitRepository Open(DirectoryInfo directory, string rootDirectory)
{
- if (GitSharp.Repository.IsValid(directory.FullName))
- {
- return new GitRepository(directory, rootDirectory);
- }
-
- return null;
+ return new NGitBasedRepository(directory, rootDirectory);
}
- public GitRepository(DirectoryInfo directory, string rootDirectory)
+ protected GitRepository(DirectoryInfo directory, string rootDirectory)
{
this.directory = directory;
this.rootDirectory = rootDirectory;
}
- public void AdvertiseUploadPack(Stream output)
- {
- using (var repository = GetRepository())
- {
- var pack = new UploadPack(repository);
- pack.sendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
- }
- }
+ public abstract void AdvertiseUploadPack(Stream output);
- public void AdvertiseReceivePack(Stream output)
- {
- using (var repository = GetRepository())
- {
- var pack = new ReceivePack(repository);
- pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
- }
- }
+ public abstract void AdvertiseReceivePack(Stream output);
- public void Receive(Stream inputStream, Stream outputStream)
- {
- using (var repository = GetRepository())
- {
- var pack = new ReceivePack(repository);
- pack.setBiDirectionalPipe(false);
- pack.receive(inputStream, outputStream, outputStream);
- }
- }
+ public abstract void Receive(Stream inputStream, Stream outputStream);
- public 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 abstract void Upload(Stream inputStream, Stream outputStream);
- public 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 abstract CommitInfo GetLatestCommit();
public string Name
{
@@ -151,55 +87,7 @@ public string GitDirectory()
return Path.Combine(PhysicalPathDotGit, ".git");
}
- public 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 abstract void UpdateServerInfo();
}
public class CommitInfo
View
132 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();
+ }
+ }
+}
View
64 GitAspx/Lib/SimpleRefWriter.cs → GitAspx/Lib/GitSharpCoreBasedSimpleRefWriter.cs
@@ -1,33 +1,33 @@
-namespace GitAspx.Lib {
- using System.Collections.Generic;
- using System.IO;
- using GitSharp.Core;
- using GitSharp.Core.Exceptions;
- using GitSharp.Core.Util;
-
- // Modified code from GitSharp
-
- public class SimpleRefWriter : RefWriter {
- private readonly GitSharp.Core.Repository _db;
-
- public SimpleRefWriter(GitSharp.Core.Repository db, IEnumerable<Ref> refs)
- : base(refs) {
- _db = db;
- }
-
- protected override void writeFile(string file, byte[] content) {
- FileInfo p = PathUtil.CombineFilePath(_db.Directory, file);
- LockFile lck = new LockFile(p);
- if (!lck.Lock())
- throw new ObjectWritingException("Can't write " + p);
- try {
- lck.Write(content);
- }
- catch (IOException) {
- throw new ObjectWritingException("Can't write " + p);
- }
- if (!lck.Commit())
- throw new ObjectWritingException("Can't write " + p);
- }
- }
+namespace GitAspx.Lib {
+ using System.Collections.Generic;
+ using System.IO;
+ using GitSharp.Core;
+ using GitSharp.Core.Exceptions;
+ using GitSharp.Core.Util;
+
+ // Modified code from GitSharp
+
+ public class GitSharpCoreBasedSimpleRefWriter : RefWriter {
+ private readonly GitSharp.Core.Repository _db;
+
+ public GitSharpCoreBasedSimpleRefWriter(GitSharp.Core.Repository db, IEnumerable<Ref> refs)
+ : base(refs) {
+ _db = db;
+ }
+
+ protected override void writeFile(string file, byte[] content) {
+ FileInfo p = PathUtil.CombineFilePath(_db.Directory, file);
+ LockFile lck = new LockFile(p);
+ if (!lck.Lock())
+ throw new ObjectWritingException("Can't write " + p);
+ try {
+ lck.Write(content);
+ }
+ catch (IOException) {
+ throw new ObjectWritingException("Can't write " + p);
+ }
+ if (!lck.Commit())
+ throw new ObjectWritingException("Can't write " + p);
+ }
+ }
}
View
158 GitAspx/Lib/NGitBasedRepository.cs
@@ -0,0 +1,158 @@
+namespace GitAspx.Lib
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using System.Text;
+ using NGit.Api;
+ using NGit.Revwalk;
+ using NGit.Storage.File;
+ using NGit.Transport;
+ using Sharpen;
+ using NGit;
+
+ public class NGitBasedRepository : GitRepository
+ {
+ public NGitBasedRepository(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())
+ {
+ var pack = new UploadPack(repository);
+ pack.SetBiDirectionalPipe(false);
+ pack.Upload(inputStream, outputStream, outputStream);
+ }
+ }
+
+ public override CommitInfo GetLatestCommit()
+ {
+ using (var repository = GetRepository())
+ {
+ var repo = (FileRepository)repository;
+ var branch = repo.GetBranch();
+ if (branch == null) return null;
+ var objId = repo.Resolve(branch);
+ if (objId == null) return null;
+ RevWalk walk = new RevWalk(repo);
+ RevCommit commit = walk.ParseCommit(objId);
+ if (commit == null) return null;
+
+ return new CommitInfo
+ {
+ Message = commit.GetFullMessage(),
+ Date = commit.GetCommitterIdent().GetWhen().ToLocalTime()
+ };
+ }
+ }
+
+ private RepoWrapper GetRepository()
+ {
+ return new RepoWrapper(Git.Open(new FilePath(directory.FullName)).GetRepository() as FileRepository);
+ }
+
+ public override void UpdateServerInfo()
+ {
+ using (var rep = GetRepository())
+ {
+ var repo = (FileRepository)rep;
+ if (repo.ObjectDatabase is ObjectDirectory)
+ {
+ NGitRefWriter rw = new NGitBasedSimpleRefWriter(repo, repo.GetAllRefs().Values);
+ rw.WritePackedRefs();
+ rw.WriteInfoRefs();
+
+ var packs = GetPackRefs(rep);
+ WriteInfoPacks(packs, rep);
+ }
+ }
+ }
+
+ private void WriteInfoPacks(IEnumerable<string> packs, FileRepository 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.GetAbsolutePath(), "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(FileRepository repository)
+ {
+ var packDir = repository.ObjectsDirectory.GetAbsolutePath();
+
+ if (packDir == null)
+ {
+ return Enumerable.Empty<string>();
+ }
+
+ return new DirectoryInfo(packDir).GetFiles("*.pack").Select(x => x.Name).ToList();
+ }
+
+ struct RepoWrapper : IDisposable
+ {
+ FileRepository repository;
+
+ public static implicit operator FileRepository(RepoWrapper wrapper)
+ {
+ return wrapper.repository;
+ }
+
+ public RepoWrapper(FileRepository repository)
+ {
+ this.repository = repository;
+ }
+
+ public void Dispose()
+ {
+ if (repository != null)
+ repository.Close();
+ }
+ }
+ }
+}
View
239 GitAspx/Lib/NGitBasedSimpleRefWriter.cs
@@ -0,0 +1,239 @@
+namespace GitAspx.Lib {
+ using System.Collections.Generic;
+ using System.IO;
+ using NGit;
+ using NGit.Errors;
+ using NGit.Storage.File;
+ using NGit.Util;
+ using Sharpen;
+
+ public class NGitBasedSimpleRefWriter : NGitRefWriter {
+ private readonly FileRepository _db;
+
+ public NGitBasedSimpleRefWriter(FileRepository db, ICollection<Ref> refs)
+ : base(refs) {
+ _db = db;
+ }
+
+ protected internal override void WriteFile(string file, byte[] content) {
+ FilePath p = new FilePath(_db.Directory, file);
+ LockFile lck = new LockFile(p, FS.DETECTED);
+ if (!lck.Lock())
+ throw new ObjectWritingException("Can't write " + p);
+ try {
+ lck.Write(content);
+ }
+ catch (IOException) {
+ throw new ObjectWritingException("Can't write " + p);
+ }
+ if (!lck.Commit())
+ throw new ObjectWritingException("Can't write " + p);
+ }
+ }
+
+ //The following code is copied from NGit, because all protected members in NGit are internally visible only.
+/*
+This code is derived from jgit (http://eclipse.org/jgit).
+Copyright owners are documented in jgit's IP log.
+
+This program and the accompanying materials are made available
+under the terms of the Eclipse Distribution License v1.0 which
+accompanies this distribution, is reproduced below, and is
+available at http://www.eclipse.org/org/documents/edl-v10.php
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the following
+conditions are met:
+
+- Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+- Neither the name of the Eclipse Foundation, Inc. nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+ /// <summary>
+ /// Writes out refs to the
+ /// <see cref="Constants.INFO_REFS">Constants.INFO_REFS</see>
+ /// and
+ /// <see cref="Constants.PACKED_REFS">Constants.PACKED_REFS</see>
+ /// files.
+ /// This class is abstract as the writing of the files must be handled by the
+ /// caller. This is because it is used by transport classes as well.
+ /// </summary>
+ public abstract class NGitRefWriter
+ {
+ private readonly ICollection<Ref> refs;
+
+ /// <param name="refs">
+ /// the complete set of references. This should have been computed
+ /// by applying updates to the advertised refs already discovered.
+ /// </param>
+ public NGitRefWriter(ICollection<Ref> refs)
+ {
+ this.refs = RefComparator.Sort(refs);
+ }
+
+ /// <param name="refs">
+ /// the complete set of references. This should have been computed
+ /// by applying updates to the advertised refs already discovered.
+ /// </param>
+ public NGitRefWriter(IDictionary<string, Ref> refs)
+ {
+ if (refs is RefMap)
+ {
+ this.refs = refs.Values;
+ }
+ else
+ {
+ this.refs = RefComparator.Sort(refs.Values);
+ }
+ }
+
+ /// <param name="refs">
+ /// the complete set of references. This should have been computed
+ /// by applying updates to the advertised refs already discovered.
+ /// </param>
+ public NGitRefWriter(RefList<Ref> refs)
+ {
+ this.refs = refs.AsList();
+ }
+
+ /// <summary>
+ /// Rebuild the
+ /// <see cref="Constants.INFO_REFS">Constants.INFO_REFS</see>
+ /// .
+ /// <p>
+ /// This method rebuilds the contents of the
+ /// <see cref="Constants.INFO_REFS">Constants.INFO_REFS</see>
+ /// file
+ /// to match the passed list of references.
+ /// </summary>
+ /// <exception cref="System.IO.IOException">
+ /// writing is not supported, or attempting to write the file
+ /// failed, possibly due to permissions or remote disk full, etc.
+ /// </exception>
+ public virtual void WriteInfoRefs()
+ {
+ StringWriter w = new StringWriter();
+ char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH];
+ foreach (Ref r in refs)
+ {
+ if (Constants.HEAD.Equals(r.GetName()))
+ {
+ // Historically HEAD has never been published through
+ // the INFO_REFS file. This is a mistake, but its the
+ // way things are.
+ //
+ continue;
+ }
+ r.GetObjectId().CopyTo(tmp, w);
+ w.Write('\t');
+ w.Write(r.GetName());
+ w.Write('\n');
+ if (r.GetPeeledObjectId() != null)
+ {
+ r.GetPeeledObjectId().CopyTo(tmp, w);
+ w.Write('\t');
+ w.Write(r.GetName());
+ w.Write("^{}\n");
+ }
+ }
+ WriteFile(Constants.INFO_REFS, Constants.Encode(w.ToString()));
+ }
+
+ /// <summary>
+ /// Rebuild the
+ /// <see cref="Constants.PACKED_REFS">Constants.PACKED_REFS</see>
+ /// file.
+ /// <p>
+ /// This method rebuilds the contents of the
+ /// <see cref="Constants.PACKED_REFS">Constants.PACKED_REFS</see>
+ /// file to match the passed list of references, including only those refs
+ /// that have a storage type of
+ /// <see cref="RefStorage.PACKED">RefStorage.PACKED</see>
+ /// .
+ /// </summary>
+ /// <exception cref="System.IO.IOException">
+ /// writing is not supported, or attempting to write the file
+ /// failed, possibly due to permissions or remote disk full, etc.
+ /// </exception>
+ public virtual void WritePackedRefs()
+ {
+ bool peeled = false;
+ foreach (Ref r in refs)
+ {
+ if (r.GetStorage().IsPacked() && r.IsPeeled())
+ {
+ peeled = true;
+ break;
+ }
+ }
+ StringWriter w = new StringWriter();
+ if (peeled)
+ {
+ w.Write(RefDirectory.PACKED_REFS_HEADER);
+ if (peeled)
+ {
+ w.Write(RefDirectory.PACKED_REFS_PEELED);
+ }
+ w.Write('\n');
+ }
+ char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH];
+ foreach (Ref r_1 in refs)
+ {
+ if (r_1.GetStorage() != RefStorage.PACKED)
+ {
+ continue;
+ }
+ r_1.GetObjectId().CopyTo(tmp, w);
+ w.Write(' ');
+ w.Write(r_1.GetName());
+ w.Write('\n');
+ if (r_1.GetPeeledObjectId() != null)
+ {
+ w.Write('^');
+ r_1.GetPeeledObjectId().CopyTo(tmp, w);
+ w.Write('\n');
+ }
+ }
+ WriteFile(Constants.PACKED_REFS, Constants.Encode(w.ToString()));
+ }
+
+ /// <summary>
+ /// Handles actual writing of ref files to the git repository, which may
+ /// differ slightly depending on the destination and transport.
+ /// </summary>
+ /// <remarks>
+ /// Handles actual writing of ref files to the git repository, which may
+ /// differ slightly depending on the destination and transport.
+ /// </remarks>
+ /// <param name="file">path to ref file.</param>
+ /// <param name="content">byte content of file to be written.</param>
+ /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
+ protected internal abstract void WriteFile(string file, byte[] content);
+ }
+}
View
2  GitAspx/Lib/RepositoryService.cs
@@ -114,7 +114,7 @@ public GitRepository GetRepository(string cat, string subcat, string project)
if (!Directory.Exists(directory))
return null;
- return new GitRepository(new DirectoryInfo(directory), appSettings.RepositoriesDirectory.FullName);
+ return GitRepository.Open(new DirectoryInfo(directory), appSettings.RepositoriesDirectory.FullName);
}
public Repository GetBackendRepository(string cat, string subcat, string project)

1 comment on commit 71412b0

@linquize
Owner

Hardcode this for apache mono
NGit.Util.FS.DETECTED.SetUserHome(new Sharpen.FilePath("/var/www"));

Please sign in to comment.
Something went wrong with that request. Please try again.