Skip to content

Commit d50a54e

Browse files
committed
Added more test project.
1 parent 013316f commit d50a54e

File tree

8 files changed

+119
-4
lines changed

8 files changed

+119
-4
lines changed

GitReader.sln

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "gitexport", "samples\gitexp
4444
EndProject
4545
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmark", "tests\Benchmark\Benchmark.csproj", "{A33B5307-D2E7-429A-93EC-45AB96D525E7}"
4646
EndProject
47+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "gitextracttest", "tests\gitextracttest\gitextracttest.csproj", "{CC80205D-937B-43A6-AE69-FA99BE72177F}"
48+
EndProject
4749
Global
4850
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4951
Debug|Any CPU = Debug|Any CPU
@@ -90,6 +92,10 @@ Global
9092
{A33B5307-D2E7-429A-93EC-45AB96D525E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
9193
{A33B5307-D2E7-429A-93EC-45AB96D525E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
9294
{A33B5307-D2E7-429A-93EC-45AB96D525E7}.Release|Any CPU.Build.0 = Release|Any CPU
95+
{CC80205D-937B-43A6-AE69-FA99BE72177F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
96+
{CC80205D-937B-43A6-AE69-FA99BE72177F}.Debug|Any CPU.Build.0 = Debug|Any CPU
97+
{CC80205D-937B-43A6-AE69-FA99BE72177F}.Release|Any CPU.ActiveCfg = Release|Any CPU
98+
{CC80205D-937B-43A6-AE69-FA99BE72177F}.Release|Any CPU.Build.0 = Release|Any CPU
9399
EndGlobalSection
94100
GlobalSection(SolutionProperties) = preSolution
95101
HideSolutionNode = FALSE
@@ -100,6 +106,7 @@ Global
100106
{48C10B93-4D7A-4D44-974B-55677CB08B2D} = {FA77DE1C-C141-4C03-AA63-DAFC2E624125}
101107
{04192260-BFB9-490D-B835-E0E4311FEE93} = {6C0A2BF1-2E5A-4040-9617-9438F1A8BBDD}
102108
{A33B5307-D2E7-429A-93EC-45AB96D525E7} = {FA77DE1C-C141-4C03-AA63-DAFC2E624125}
109+
{CC80205D-937B-43A6-AE69-FA99BE72177F} = {FA77DE1C-C141-4C03-AA63-DAFC2E624125}
103110
EndGlobalSection
104111
GlobalSection(ExtensibilityGlobals) = postSolution
105112
SolutionGuid = {AD39B2E0-9F24-4605-A51C-FF43CCA98564}

samples/gitexport/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"gitexporttest": {
44
"commandName": "Project",
5-
"commandLineArgs": "D:\\Projects\\git 69c786637d7a7fe3b2b8f7d989af095f5f49c3a8 export",
5+
"commandLineArgs": "C:\\Projects\\git 69c786637d7a7fe3b2b8f7d989af095f5f49c3a8 export",
66
"workingDirectory": "bin\\Debug\\net48"
77
}
88
}

samples/gitlog/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"gitlog": {
44
"commandName": "Project",
55
"commandLineArgs": ".",
6-
"workingDirectory": "D:\\Projects\\IL2C"
6+
"workingDirectory": "C:\\Projects\\IL2C"
77
}
88
}
99
}

tests/gitexporttest/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"gitexporttest": {
44
"commandName": "Project",
5-
"commandLineArgs": "D:\\Projects\\git 69c786637d7a7fe3b2b8f7d989af095f5f49c3a8 export",
5+
"commandLineArgs": "C:\\Projects\\git 69c786637d7a7fe3b2b8f7d989af095f5f49c3a8 export",
66
"workingDirectory": "bin\\Debug\\net48"
77
}
88
}

tests/gitextracttest/Program.cs

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
////////////////////////////////////////////////////////////////////////////
2+
//
3+
// GitReader - Lightweight Git local repository traversal library.
4+
// Copyright (c) Kouji Matsui (@kozy_kekyo, @[email protected])
5+
//
6+
// Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0
7+
//
8+
////////////////////////////////////////////////////////////////////////////
9+
10+
using GitReader.Primitive;
11+
using System;
12+
using System.Threading.Tasks;
13+
using System.Threading;
14+
using System.IO;
15+
16+
#if DEBUG
17+
using Lepracaun;
18+
#endif
19+
20+
namespace GitReader;
21+
22+
public static class Program
23+
{
24+
private static async Task ExtractObjectAsync(
25+
TextWriter tw,
26+
string repositoryPath, string objectId, string toPath)
27+
{
28+
var basePath = Path.GetDirectoryName(toPath) switch
29+
{
30+
null => Path.DirectorySeparatorChar.ToString(),
31+
"" => ".",
32+
string path => path,
33+
};
34+
if (!Directory.Exists(basePath))
35+
{
36+
Directory.CreateDirectory(basePath);
37+
}
38+
39+
using var repository =
40+
await Repository.Factory.OpenPrimitiveAsync(repositoryPath);
41+
42+
using var result = await repository.OpenRawObjectStreamAsync(objectId);
43+
44+
using var fs = new FileStream(
45+
toPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 65536, true);
46+
47+
await result.Stream.CopyToAsync(fs);
48+
await fs.FlushAsync();
49+
50+
tw.WriteLine($"Extracted an object: Id={objectId}, Type={result.Type}, Path={toPath}");
51+
}
52+
53+
private static Task MainAsync(string[] args)
54+
{
55+
if (args.Length == 3)
56+
{
57+
return ExtractObjectAsync(Console.Out, args[0], args[1], args[2]);
58+
}
59+
60+
Console.WriteLine("usage: gitextracttest <repository path> <object id> <to path>");
61+
return Task.CompletedTask;
62+
}
63+
64+
#if DEBUG
65+
public static void Main(string[] args)
66+
{
67+
// Single-threaded for easier debugging of asynchronous operations.
68+
var sc = new SingleThreadedSynchronizationContext();
69+
SynchronizationContext.SetSynchronizationContext(sc);
70+
71+
sc.Run(MainAsync(args));
72+
}
73+
#else
74+
public static Task Main(string[] args) =>
75+
MainAsync(args);
76+
#endif
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"profiles": {
3+
"gitexporttest": {
4+
"commandName": "Project",
5+
"commandLineArgs": "C:\\Projects\\git 0ae7d685904b85f97a69b243e30f010671d050e3 blob\\output.txt",
6+
"workingDirectory": "bin\\Debug\\net48"
7+
}
8+
}
9+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net48;net6.0</TargetFrameworks>
6+
<Nullable>enable</Nullable>
7+
<AssemblyName>gitexporttest</AssemblyName>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Lepracaun" Version="1.0.0" />
12+
</ItemGroup>
13+
14+
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
15+
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\..\GitReader\GitReader.csproj" />
20+
</ItemGroup>
21+
22+
</Project>

tests/gitlogtest/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"gitlogtest": {
44
"commandName": "Project",
55
"commandLineArgs": ".",
6-
"workingDirectory": "D:\\Projects\\git"
6+
"workingDirectory": "C:\\Projects\\git"
77
}
88
}
99
}

0 commit comments

Comments
 (0)