Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use NGit as backend library for HTTP services

  • Loading branch information...
commit 71412b07c48eab70c0404384ec04acc04d5ef0f1 1 parent 3679a76
linquize authored
18 GitAspx.sln
@@ -9,6 +9,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp-VS2010", "lib\GitS
9 9 EndProject
10 10 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp.Core-VS2010", "lib\GitSharp\GitSharp.Core\GitSharp.Core-VS2010.csproj", "{C46EDD61-C202-465A-93F1-ADE20A83BB59}"
11 11 EndProject
  12 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NGit", "lib\NGit\NGit\NGit.csproj", "{E3BFF8B4-189C-496A-A817-7E8B31E22B91}"
  13 +EndProject
  14 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSch", "lib\NGit\NSch\NSch.csproj", "{A19E6F3F-A25B-4B01-8922-CF0CC35C781D}"
  15 +EndProject
  16 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sharpen", "lib\NGit\Sharpen\Sharpen.csproj", "{72944A6C-45FF-4EF8-B349-8C9CABF519D4}"
  17 +EndProject
12 18 Global
13 19 GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 20 Debug|Any CPU = Debug|Any CPU
@@ -31,6 +37,18 @@ Global
31 37 {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 38 {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 39 {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Release|Any CPU.Build.0 = Release|Any CPU
  40 + {E3BFF8B4-189C-496A-A817-7E8B31E22B91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  41 + {E3BFF8B4-189C-496A-A817-7E8B31E22B91}.Debug|Any CPU.Build.0 = Debug|Any CPU
  42 + {E3BFF8B4-189C-496A-A817-7E8B31E22B91}.Release|Any CPU.ActiveCfg = Release|Any CPU
  43 + {E3BFF8B4-189C-496A-A817-7E8B31E22B91}.Release|Any CPU.Build.0 = Release|Any CPU
  44 + {A19E6F3F-A25B-4B01-8922-CF0CC35C781D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  45 + {A19E6F3F-A25B-4B01-8922-CF0CC35C781D}.Debug|Any CPU.Build.0 = Debug|Any CPU
  46 + {A19E6F3F-A25B-4B01-8922-CF0CC35C781D}.Release|Any CPU.ActiveCfg = Release|Any CPU
  47 + {A19E6F3F-A25B-4B01-8922-CF0CC35C781D}.Release|Any CPU.Build.0 = Release|Any CPU
  48 + {72944A6C-45FF-4EF8-B349-8C9CABF519D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  49 + {72944A6C-45FF-4EF8-B349-8C9CABF519D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
  50 + {72944A6C-45FF-4EF8-B349-8C9CABF519D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
  51 + {72944A6C-45FF-4EF8-B349-8C9CABF519D4}.Release|Any CPU.Build.0 = Release|Any CPU
34 52 EndGlobalSection
35 53 GlobalSection(SolutionProperties) = preSolution
36 54 HideSolutionNode = FALSE
13 GitAspx/GitAspx.csproj
@@ -89,10 +89,13 @@
89 89 <Compile Include="Lib\AppSettings.cs" />
90 90 <Compile Include="Lib\ForbiddenResult.cs" />
91 91 <Compile Include="Lib\WebBrowsingSettings.cs" />
92   - <Compile Include="Lib\SimpleRefWriter.cs" />
  92 + <Compile Include="Lib\GitSharpCoreBasedSimpleRefWriter.cs" />
93 93 <Compile Include="Lib\NotFoundResult.cs" />
94 94 <Compile Include="Lib\GitRepository.cs" />
95 95 <Compile Include="Lib\StructureMapControllerFactory.cs" />
  96 + <Compile Include="Lib\GitSharpCoreBasedRepository.cs" />
  97 + <Compile Include="Lib\NGitBasedRepository.cs" />
  98 + <Compile Include="Lib\NGitBasedSimpleRefWriter.cs" />
96 99 <Compile Include="Properties\AssemblyInfo.cs" />
97 100 <Compile Include="Lib\RepositoryService.cs" />
98 101 <Compile Include="PrettyDate.cs" />
@@ -236,6 +239,14 @@
236 239 <Project>{7311850F-619A-4241-B09F-157792C75FBA}</Project>
237 240 <Name>GitSharp</Name>
238 241 </ProjectReference>
  242 + <ProjectReference Include="..\lib\NGit\NGit\NGit.csproj">
  243 + <Project>{E3BFF8B4-189C-496A-A817-7E8B31E22B91}</Project>
  244 + <Name>NGit</Name>
  245 + </ProjectReference>
  246 + <ProjectReference Include="..\lib\NGit\Sharpen\Sharpen.csproj">
  247 + <Project>{72944A6C-45FF-4EF8-B349-8C9CABF519D4}</Project>
  248 + <Name>Sharpen</Name>
  249 + </ProjectReference>
239 250 </ItemGroup>
240 251 <ItemGroup>
241 252 <Content Include="Views\TreeView\EmptyRepository.cshtml" />
134 GitAspx/Lib/GitRepository.cs
... ... @@ -1,97 +1,33 @@
1 1 namespace GitAspx.Lib
2 2 {
3 3 using System;
4   - using System.Collections.Generic;
5 4 using System.IO;
6   - using System.Linq;
7   - using System.Text;
8   - using GitSharp.Core;
9   - using GitSharp.Core.Transport;
10 5
11   - public class GitRepository
  6 + public abstract class GitRepository
12 7 {
13   - private DirectoryInfo directory;
14   - string rootDirectory;
  8 + protected DirectoryInfo directory;
  9 + protected string rootDirectory;
15 10
16 11 public static GitRepository Open(DirectoryInfo directory, string rootDirectory)
17 12 {
18   - if (GitSharp.Repository.IsValid(directory.FullName))
19   - {
20   - return new GitRepository(directory, rootDirectory);
21   - }
22   -
23   - return null;
  13 + return new NGitBasedRepository(directory, rootDirectory);
24 14 }
25 15
26   - public GitRepository(DirectoryInfo directory, string rootDirectory)
  16 + protected GitRepository(DirectoryInfo directory, string rootDirectory)
27 17 {
28 18 this.directory = directory;
29 19 this.rootDirectory = rootDirectory;
30 20 }
31 21
32   - public void AdvertiseUploadPack(Stream output)
33   - {
34   - using (var repository = GetRepository())
35   - {
36   - var pack = new UploadPack(repository);
37   - pack.sendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
38   - }
39   - }
  22 + public abstract void AdvertiseUploadPack(Stream output);
40 23
41   - public void AdvertiseReceivePack(Stream output)
42   - {
43   - using (var repository = GetRepository())
44   - {
45   - var pack = new ReceivePack(repository);
46   - pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
47   - }
48   - }
  24 + public abstract void AdvertiseReceivePack(Stream output);
49 25
50   - public void Receive(Stream inputStream, Stream outputStream)
51   - {
52   - using (var repository = GetRepository())
53   - {
54   - var pack = new ReceivePack(repository);
55   - pack.setBiDirectionalPipe(false);
56   - pack.receive(inputStream, outputStream, outputStream);
57   - }
58   - }
  26 + public abstract void Receive(Stream inputStream, Stream outputStream);
59 27
60   - public void Upload(Stream inputStream, Stream outputStream)
61   - {
62   - using (var repository = GetRepository())
63   - {
64   - using (var pack = new UploadPack(repository))
65   - {
66   - pack.setBiDirectionalPipe(false);
67   - pack.Upload(inputStream, outputStream, outputStream);
68   - }
69   - }
70   - }
  28 + public abstract void Upload(Stream inputStream, Stream outputStream);
71 29
72   - public CommitInfo GetLatestCommit()
73   - {
74   - using (var repository = new GitSharp.Repository(PhysicalPathDotGit))
75   - {
76   - var commit = repository.Head.CurrentCommit;
77   -
78   - if (commit == null)
79   - {
80   - return null;
81   - }
82   -
83   - return new CommitInfo
84   - {
85   - Message = commit.Message,
86   - Date = commit.CommitDate.LocalDateTime
87   - };
88   - }
89   - }
90   -
91   - private GitSharp.Core.Repository GetRepository()
92   - {
93   - return GitSharp.Core.Repository.Open(directory);
94   - }
  30 + public abstract CommitInfo GetLatestCommit();
95 31
96 32 public string Name
97 33 {
@@ -151,55 +87,7 @@ public string GitDirectory()
151 87 return Path.Combine(PhysicalPathDotGit, ".git");
152 88 }
153 89
154   - public void UpdateServerInfo()
155   - {
156   - using (var rep = GetRepository())
157   - {
158   - if (rep.ObjectDatabase is ObjectDirectory)
159   - {
160   - RefWriter rw = new SimpleRefWriter(rep, rep.getAllRefs().Values);
161   - rw.writePackedRefs();
162   - rw.writeInfoRefs();
163   -
164   - var packs = GetPackRefs(rep);
165   - WriteInfoPacks(packs, rep);
166   - }
167   - }
168   - }
169   -
170   - private void WriteInfoPacks(IEnumerable<string> packs, GitSharp.Core.Repository repository)
171   - {
172   -
173   - var w = new StringBuilder();
174   -
175   - foreach (string pack in packs)
176   - {
177   - w.Append("P ");
178   - w.Append(pack);
179   - w.Append('\n');
180   - }
181   -
182   - var infoPacksPath = Path.Combine(repository.ObjectsDirectory.FullName, "info/packs");
183   - var encoded = Encoding.ASCII.GetBytes(w.ToString());
184   -
185   -
186   - using (Stream fs = File.Create(infoPacksPath))
187   - {
188   - fs.Write(encoded, 0, encoded.Length);
189   - }
190   - }
191   -
192   - private IEnumerable<string> GetPackRefs(GitSharp.Core.Repository repository)
193   - {
194   - var packDir = repository.ObjectsDirectory.GetDirectories().SingleOrDefault(x => x.Name == "pack");
195   -
196   - if (packDir == null)
197   - {
198   - return Enumerable.Empty<string>();
199   - }
200   -
201   - return packDir.GetFiles("*.pack").Select(x => x.Name).ToList();
202   - }
  90 + public abstract void UpdateServerInfo();
203 91 }
204 92
205 93 public class CommitInfo
132 GitAspx/Lib/GitSharpCoreBasedRepository.cs
... ... @@ -0,0 +1,132 @@
  1 +namespace GitAspx.Lib
  2 +{
  3 + using System;
  4 + using System.Collections.Generic;
  5 + using System.IO;
  6 + using System.Linq;
  7 + using System.Text;
  8 + using GitSharp.Core;
  9 + using GitSharp.Core.Transport;
  10 +
  11 + public class GitSharpCoreBasedRepository : GitRepository
  12 + {
  13 + public GitSharpCoreBasedRepository(DirectoryInfo directory, string rootDirectory)
  14 + : base(directory, rootDirectory)
  15 + {
  16 + }
  17 +
  18 + public override void AdvertiseUploadPack(Stream output)
  19 + {
  20 + using (var repository = GetRepository())
  21 + {
  22 + var pack = new UploadPack(repository);
  23 + pack.sendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
  24 + }
  25 + }
  26 +
  27 + public override void AdvertiseReceivePack(Stream output)
  28 + {
  29 + using (var repository = GetRepository())
  30 + {
  31 + var pack = new ReceivePack(repository);
  32 + pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
  33 + }
  34 + }
  35 +
  36 + public override void Receive(Stream inputStream, Stream outputStream)
  37 + {
  38 + using (var repository = GetRepository())
  39 + {
  40 + var pack = new ReceivePack(repository);
  41 + pack.setBiDirectionalPipe(false);
  42 + pack.receive(inputStream, outputStream, outputStream);
  43 + }
  44 + }
  45 +
  46 + public override void Upload(Stream inputStream, Stream outputStream)
  47 + {
  48 + using (var repository = GetRepository())
  49 + {
  50 + using (var pack = new UploadPack(repository))
  51 + {
  52 + pack.setBiDirectionalPipe(false);
  53 + pack.Upload(inputStream, outputStream, outputStream);
  54 + }
  55 + }
  56 + }
  57 +
  58 + public override CommitInfo GetLatestCommit()
  59 + {
  60 + using (var repository = new GitSharp.Repository(PhysicalPathDotGit))
  61 + {
  62 + var commit = repository.Head.CurrentCommit;
  63 +
  64 + if (commit == null)
  65 + {
  66 + return null;
  67 + }
  68 +
  69 + return new CommitInfo
  70 + {
  71 + Message = commit.Message,
  72 + Date = commit.CommitDate.LocalDateTime
  73 + };
  74 + }
  75 + }
  76 +
  77 + private GitSharp.Core.Repository GetRepository()
  78 + {
  79 + return GitSharp.Core.Repository.Open(directory);
  80 + }
  81 +
  82 + public override void UpdateServerInfo()
  83 + {
  84 + using (var rep = GetRepository())
  85 + {
  86 + if (rep.ObjectDatabase is ObjectDirectory)
  87 + {
  88 + RefWriter rw = new GitSharpCoreBasedSimpleRefWriter(rep, rep.getAllRefs().Values);
  89 + rw.writePackedRefs();
  90 + rw.writeInfoRefs();
  91 +
  92 + var packs = GetPackRefs(rep);
  93 + WriteInfoPacks(packs, rep);
  94 + }
  95 + }
  96 + }
  97 +
  98 + private void WriteInfoPacks(IEnumerable<string> packs, GitSharp.Core.Repository repository)
  99 + {
  100 +
  101 + var w = new StringBuilder();
  102 +
  103 + foreach (string pack in packs)
  104 + {
  105 + w.Append("P ");
  106 + w.Append(pack);
  107 + w.Append('\n');
  108 + }
  109 +
  110 + var infoPacksPath = Path.Combine(repository.ObjectsDirectory.FullName, "info/packs");
  111 + var encoded = Encoding.ASCII.GetBytes(w.ToString());
  112 +
  113 +
  114 + using (Stream fs = File.Create(infoPacksPath))
  115 + {
  116 + fs.Write(encoded, 0, encoded.Length);
  117 + }
  118 + }
  119 +
  120 + private IEnumerable<string> GetPackRefs(GitSharp.Core.Repository repository)
  121 + {
  122 + var packDir = repository.ObjectsDirectory.GetDirectories().SingleOrDefault(x => x.Name == "pack");
  123 +
  124 + if (packDir == null)
  125 + {
  126 + return Enumerable.Empty<string>();
  127 + }
  128 +
  129 + return packDir.GetFiles("*.pack").Select(x => x.Name).ToList();
  130 + }
  131 + }
  132 +}
64 GitAspx/Lib/SimpleRefWriter.cs → GitAspx/Lib/GitSharpCoreBasedSimpleRefWriter.cs
... ... @@ -1,33 +1,33 @@
1   -namespace GitAspx.Lib {
2   - using System.Collections.Generic;
3   - using System.IO;
4   - using GitSharp.Core;
5   - using GitSharp.Core.Exceptions;
6   - using GitSharp.Core.Util;
7   -
8   - // Modified code from GitSharp
9   -
10   - public class SimpleRefWriter : RefWriter {
11   - private readonly GitSharp.Core.Repository _db;
12   -
13   - public SimpleRefWriter(GitSharp.Core.Repository db, IEnumerable<Ref> refs)
14   - : base(refs) {
15   - _db = db;
16   - }
17   -
18   - protected override void writeFile(string file, byte[] content) {
19   - FileInfo p = PathUtil.CombineFilePath(_db.Directory, file);
20   - LockFile lck = new LockFile(p);
21   - if (!lck.Lock())
22   - throw new ObjectWritingException("Can't write " + p);
23   - try {
24   - lck.Write(content);
25   - }
26   - catch (IOException) {
27   - throw new ObjectWritingException("Can't write " + p);
28   - }
29   - if (!lck.Commit())
30   - throw new ObjectWritingException("Can't write " + p);
31   - }
32   - }
  1 +namespace GitAspx.Lib {
  2 + using System.Collections.Generic;
  3 + using System.IO;
  4 + using GitSharp.Core;
  5 + using GitSharp.Core.Exceptions;
  6 + using GitSharp.Core.Util;
  7 +
  8 + // Modified code from GitSharp
  9 +
  10 + public class GitSharpCoreBasedSimpleRefWriter : RefWriter {
  11 + private readonly GitSharp.Core.Repository _db;
  12 +
  13 + public GitSharpCoreBasedSimpleRefWriter(GitSharp.Core.Repository db, IEnumerable<Ref> refs)
  14 + : base(refs) {
  15 + _db = db;
  16 + }
  17 +
  18 + protected override void writeFile(string file, byte[] content) {
  19 + FileInfo p = PathUtil.CombineFilePath(_db.Directory, file);
  20 + LockFile lck = new LockFile(p);
  21 + if (!lck.Lock())
  22 + throw new ObjectWritingException("Can't write " + p);
  23 + try {
  24 + lck.Write(content);
  25 + }
  26 + catch (IOException) {
  27 + throw new ObjectWritingException("Can't write " + p);
  28 + }
  29 + if (!lck.Commit())
  30 + throw new ObjectWritingException("Can't write " + p);
  31 + }
  32 + }
33 33 }
158 GitAspx/Lib/NGitBasedRepository.cs
... ... @@ -0,0 +1,158 @@
  1 +namespace GitAspx.Lib
  2 +{
  3 + using System;
  4 + using System.Collections.Generic;
  5 + using System.IO;
  6 + using System.Linq;
  7 + using System.Text;
  8 + using NGit.Api;
  9 + using NGit.Revwalk;
  10 + using NGit.Storage.File;
  11 + using NGit.Transport;
  12 + using Sharpen;
  13 + using NGit;
  14 +
  15 + public class NGitBasedRepository : GitRepository
  16 + {
  17 + public NGitBasedRepository(DirectoryInfo directory, string rootDirectory)
  18 + : base(directory, rootDirectory)
  19 + {
  20 + }
  21 +
  22 + public override void AdvertiseUploadPack(Stream output)
  23 + {
  24 + using (var repository = GetRepository())
  25 + {
  26 + var pack = new UploadPack(repository);
  27 + pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
  28 + }
  29 + }
  30 +
  31 + public override void AdvertiseReceivePack(Stream output)
  32 + {
  33 + using (var repository = GetRepository())
  34 + {
  35 + var pack = new ReceivePack(repository);
  36 + pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
  37 + }
  38 + }
  39 +
  40 + public override void Receive(Stream inputStream, Stream outputStream)
  41 + {
  42 + using (var repository = GetRepository())
  43 + {
  44 + var pack = new ReceivePack(repository);
  45 + pack.SetBiDirectionalPipe(false);
  46 + pack.Receive(inputStream, outputStream, outputStream);
  47 + }
  48 + }
  49 +
  50 + public override void Upload(Stream inputStream, Stream outputStream)
  51 + {
  52 + using (var repository = GetRepository())
  53 + {
  54 + var pack = new UploadPack(repository);
  55 + pack.SetBiDirectionalPipe(false);
  56 + pack.Upload(inputStream, outputStream, outputStream);
  57 + }
  58 + }
  59 +
  60 + public override CommitInfo GetLatestCommit()
  61 + {
  62 + using (var repository = GetRepository())
  63 + {
  64 + var repo = (FileRepository)repository;
  65 + var branch = repo.GetBranch();
  66 + if (branch == null) return null;
  67 + var objId = repo.Resolve(branch);
  68 + if (objId == null) return null;
  69 + RevWalk walk = new RevWalk(repo);
  70 + RevCommit commit = walk.ParseCommit(objId);
  71 + if (commit == null) return null;
  72 +
  73 + return new CommitInfo
  74 + {
  75 + Message = commit.GetFullMessage(),
  76 + Date = commit.GetCommitterIdent().GetWhen().ToLocalTime()
  77 + };
  78 + }
  79 + }
  80 +
  81 + private RepoWrapper GetRepository()
  82 + {
  83 + return new RepoWrapper(Git.Open(new FilePath(directory.FullName)).GetRepository() as FileRepository);
  84 + }
  85 +
  86 + public override void UpdateServerInfo()
  87 + {
  88 + using (var rep = GetRepository())
  89 + {
  90 + var repo = (FileRepository)rep;
  91 + if (repo.ObjectDatabase is ObjectDirectory)
  92 + {
  93 + NGitRefWriter rw = new NGitBasedSimpleRefWriter(repo, repo.GetAllRefs().Values);
  94 + rw.WritePackedRefs();
  95 + rw.WriteInfoRefs();
  96 +
  97 + var packs = GetPackRefs(rep);
  98 + WriteInfoPacks(packs, rep);
  99 + }
  100 + }
  101 + }
  102 +
  103 + private void WriteInfoPacks(IEnumerable<string> packs, FileRepository repository)
  104 + {
  105 +
  106 + var w = new StringBuilder();
  107 +
  108 + foreach (string pack in packs)
  109 + {
  110 + w.Append("P ");
  111 + w.Append(pack);
  112 + w.Append('\n');
  113 + }
  114 +
  115 + var infoPacksPath = Path.Combine(repository.ObjectsDirectory.GetAbsolutePath(), "info/packs");
  116 + var encoded = Encoding.ASCII.GetBytes(w.ToString());
  117 +
  118 +
  119 + using (Stream fs = File.Create(infoPacksPath))
  120 + {
  121 + fs.Write(encoded, 0, encoded.Length);
  122 + }
  123 + }
  124 +
  125 + private IEnumerable<string> GetPackRefs(FileRepository repository)
  126 + {
  127 + var packDir = repository.ObjectsDirectory.GetAbsolutePath();
  128 +
  129 + if (packDir == null)
  130 + {
  131 + return Enumerable.Empty<string>();
  132 + }
  133 +
  134 + return new DirectoryInfo(packDir).GetFiles("*.pack").Select(x => x.Name).ToList();
  135 + }
  136 +
  137 + struct RepoWrapper : IDisposable
  138 + {
  139 + FileRepository repository;
  140 +
  141 + public static implicit operator FileRepository(RepoWrapper wrapper)
  142 + {
  143 + return wrapper.repository;
  144 + }
  145 +
  146 + public RepoWrapper(FileRepository repository)
  147 + {
  148 + this.repository = repository;
  149 + }
  150 +
  151 + public void Dispose()
  152 + {
  153 + if (repository != null)
  154 + repository.Close();
  155 + }
  156 + }
  157 + }
  158 +}
239 GitAspx/Lib/NGitBasedSimpleRefWriter.cs
... ... @@ -0,0 +1,239 @@
  1 +namespace GitAspx.Lib {
  2 + using System.Collections.Generic;
  3 + using System.IO;
  4 + using NGit;
  5 + using NGit.Errors;
  6 + using NGit.Storage.File;
  7 + using NGit.Util;
  8 + using Sharpen;
  9 +
  10 + public class NGitBasedSimpleRefWriter : NGitRefWriter {
  11 + private readonly FileRepository _db;
  12 +
  13 + public NGitBasedSimpleRefWriter(FileRepository db, ICollection<Ref> refs)
  14 + : base(refs) {
  15 + _db = db;
  16 + }
  17 +
  18 + protected internal override void WriteFile(string file, byte[] content) {
  19 + FilePath p = new FilePath(_db.Directory, file);
  20 + LockFile lck = new LockFile(p, FS.DETECTED);
  21 + if (!lck.Lock())
  22 + throw new ObjectWritingException("Can't write " + p);
  23 + try {
  24 + lck.Write(content);
  25 + }
  26 + catch (IOException) {
  27 + throw new ObjectWritingException("Can't write " + p);
  28 + }
  29 + if (!lck.Commit())
  30 + throw new ObjectWritingException("Can't write " + p);
  31 + }
  32 + }
  33 +
  34 + //The following code is copied from NGit, because all protected members in NGit are internally visible only.
  35 +/*
  36 +This code is derived from jgit (http://eclipse.org/jgit).
  37 +Copyright owners are documented in jgit's IP log.
  38 +
  39 +This program and the accompanying materials are made available
  40 +under the terms of the Eclipse Distribution License v1.0 which
  41 +accompanies this distribution, is reproduced below, and is
  42 +available at http://www.eclipse.org/org/documents/edl-v10.php
  43 +
  44 +All rights reserved.
  45 +
  46 +Redistribution and use in source and binary forms, with or
  47 +without modification, are permitted provided that the following
  48 +conditions are met:
  49 +
  50 +- Redistributions of source code must retain the above copyright
  51 + notice, this list of conditions and the following disclaimer.
  52 +
  53 +- Redistributions in binary form must reproduce the above
  54 + copyright notice, this list of conditions and the following
  55 + disclaimer in the documentation and/or other materials provided
  56 + with the distribution.
  57 +
  58 +- Neither the name of the Eclipse Foundation, Inc. nor the
  59 + names of its contributors may be used to endorse or promote
  60 + products derived from this software without specific prior
  61 + written permission.
  62 +
  63 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  64 +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  65 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  66 +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  68 +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  69 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  70 +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  71 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  72 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  73 +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  74 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  75 +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  76 +*/
  77 +
  78 + /// <summary>
  79 + /// Writes out refs to the
  80 + /// <see cref="Constants.INFO_REFS">Constants.INFO_REFS</see>
  81 + /// and
  82 + /// <see cref="Constants.PACKED_REFS">Constants.PACKED_REFS</see>
  83 + /// files.
  84 + /// This class is abstract as the writing of the files must be handled by the
  85 + /// caller. This is because it is used by transport classes as well.
  86 + /// </summary>
  87 + public abstract class NGitRefWriter
  88 + {
  89 + private readonly ICollection<Ref> refs;
  90 +
  91 + /// <param name="refs">
  92 + /// the complete set of references. This should have been computed
  93 + /// by applying updates to the advertised refs already discovered.
  94 + /// </param>
  95 + public NGitRefWriter(ICollection<Ref> refs)
  96 + {
  97 + this.refs = RefComparator.Sort(refs);
  98 + }
  99 +
  100 + /// <param name="refs">
  101 + /// the complete set of references. This should have been computed
  102 + /// by applying updates to the advertised refs already discovered.
  103 + /// </param>
  104 + public NGitRefWriter(IDictionary<string, Ref> refs)
  105 + {
  106 + if (refs is RefMap)
  107 + {
  108 + this.refs = refs.Values;
  109 + }
  110 + else
  111 + {
  112 + this.refs = RefComparator.Sort(refs.Values);
  113 + }
  114 + }
  115 +
  116 + /// <param name="refs">
  117 + /// the complete set of references. This should have been computed
  118 + /// by applying updates to the advertised refs already discovered.
  119 + /// </param>
  120 + public NGitRefWriter(RefList<Ref> refs)
  121 + {
  122 + this.refs = refs.AsList();
  123 + }
  124 +
  125 + /// <summary>
  126 + /// Rebuild the
  127 + /// <see cref="Constants.INFO_REFS">Constants.INFO_REFS</see>
  128 + /// .
  129 + /// <p>
  130 + /// This method rebuilds the contents of the
  131 + /// <see cref="Constants.INFO_REFS">Constants.INFO_REFS</see>
  132 + /// file
  133 + /// to match the passed list of references.
  134 + /// </summary>
  135 + /// <exception cref="System.IO.IOException">
  136 + /// writing is not supported, or attempting to write the file
  137 + /// failed, possibly due to permissions or remote disk full, etc.
  138 + /// </exception>
  139 + public virtual void WriteInfoRefs()
  140 + {
  141 + StringWriter w = new StringWriter();
  142 + char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH];
  143 + foreach (Ref r in refs)
  144 + {
  145 + if (Constants.HEAD.Equals(r.GetName()))
  146 + {
  147 + // Historically HEAD has never been published through
  148 + // the INFO_REFS file. This is a mistake, but its the
  149 + // way things are.
  150 + //
  151 + continue;
  152 + }
  153 + r.GetObjectId().CopyTo(tmp, w);
  154 + w.Write('\t');
  155 + w.Write(r.GetName());
  156 + w.Write('\n');
  157 + if (r.GetPeeledObjectId() != null)
  158 + {
  159 + r.GetPeeledObjectId().CopyTo(tmp, w);
  160 + w.Write('\t');
  161 + w.Write(r.GetName());
  162 + w.Write("^{}\n");
  163 + }
  164 + }
  165 + WriteFile(Constants.INFO_REFS, Constants.Encode(w.ToString()));
  166 + }
  167 +
  168 + /// <summary>
  169 + /// Rebuild the
  170 + /// <see cref="Constants.PACKED_REFS">Constants.PACKED_REFS</see>
  171 + /// file.
  172 + /// <p>
  173 + /// This method rebuilds the contents of the
  174 + /// <see cref="Constants.PACKED_REFS">Constants.PACKED_REFS</see>
  175 + /// file to match the passed list of references, including only those refs
  176 + /// that have a storage type of
  177 + /// <see cref="RefStorage.PACKED">RefStorage.PACKED</see>
  178 + /// .
  179 + /// </summary>
  180 + /// <exception cref="System.IO.IOException">
  181 + /// writing is not supported, or attempting to write the file
  182 + /// failed, possibly due to permissions or remote disk full, etc.
  183 + /// </exception>
  184 + public virtual void WritePackedRefs()
  185 + {
  186 + bool peeled = false;
  187 + foreach (Ref r in refs)
  188 + {
  189 + if (r.GetStorage().IsPacked() && r.IsPeeled())
  190 + {
  191 + peeled = true;
  192 + break;
  193 + }
  194 + }
  195 + StringWriter w = new StringWriter();
  196 + if (peeled)
  197 + {
  198 + w.Write(RefDirectory.PACKED_REFS_HEADER);
  199 + if (peeled)
  200 + {
  201 + w.Write(RefDirectory.PACKED_REFS_PEELED);
  202 + }
  203 + w.Write('\n');
  204 + }
  205 + char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH];
  206 + foreach (Ref r_1 in refs)
  207 + {
  208 + if (r_1.GetStorage() != RefStorage.PACKED)
  209 + {
  210 + continue;
  211 + }
  212 + r_1.GetObjectId().CopyTo(tmp, w);
  213 + w.Write(' ');
  214 + w.Write(r_1.GetName());
  215 + w.Write('\n');
  216 + if (r_1.GetPeeledObjectId() != null)
  217 + {
  218 + w.Write('^');
  219 + r_1.GetPeeledObjectId().CopyTo(tmp, w);
  220 + w.Write('\n');
  221 + }
  222 + }
  223 + WriteFile(Constants.PACKED_REFS, Constants.Encode(w.ToString()));
  224 + }
  225 +
  226 + /// <summary>
  227 + /// Handles actual writing of ref files to the git repository, which may
  228 + /// differ slightly depending on the destination and transport.
  229 + /// </summary>
  230 + /// <remarks>
  231 + /// Handles actual writing of ref files to the git repository, which may
  232 + /// differ slightly depending on the destination and transport.
  233 + /// </remarks>
  234 + /// <param name="file">path to ref file.</param>
  235 + /// <param name="content">byte content of file to be written.</param>
  236 + /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
  237 + protected internal abstract void WriteFile(string file, byte[] content);
  238 + }
  239 +}
2  GitAspx/Lib/RepositoryService.cs
@@ -114,7 +114,7 @@ public GitRepository GetRepository(string cat, string subcat, string project)
114 114 if (!Directory.Exists(directory))
115 115 return null;
116 116
117   - return new GitRepository(new DirectoryInfo(directory), appSettings.RepositoriesDirectory.FullName);
  117 + return GitRepository.Open(new DirectoryInfo(directory), appSettings.RepositoriesDirectory.FullName);
118 118 }
119 119
120 120 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.