diff --git a/LibGitTest/FileRepoSource.cs b/LibGitTest/FileRepoSource.cs
new file mode 100644
index 0000000..09ec836
--- /dev/null
+++ b/LibGitTest/FileRepoSource.cs
@@ -0,0 +1,18 @@
+using LibGit.Interfaces;
+
+namespace LibGitTest;
+
+public class FileRepoSource : IRepoSource
+{
+ public FileRepoSource(string basePath)
+ {
+ BasePath = basePath;
+ }
+
+ public string BasePath { get; set; }
+
+ public async Task<Stream> GetFileStream(string path)
+ {
+ return File.OpenRead(Path.Join(BasePath, path));
+ }
+}
\ No newline at end of file
diff --git a/LibGitTest/LibGitTest.csproj b/LibGitTest/LibGitTest.csproj
new file mode 100644
index 0000000..ebad2df
--- /dev/null
+++ b/LibGitTest/LibGitTest.csproj
@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net7.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\LibGit\LibGit.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/LibGitTest/Program.cs b/LibGitTest/Program.cs
new file mode 100644
index 0000000..3d87631
--- /dev/null
+++ b/LibGitTest/Program.cs
@@ -0,0 +1,11 @@
+// See https://aka.ms/new-console-template for more information
+
+using LibGit;
+using LibGit.Extensions;
+using LibGitTest;
+
+Console.WriteLine("Hello, World!");
+
+//await Test1.Run();
+//await Test2.Run();
+await Test3.Run();
\ No newline at end of file
diff --git a/LibGitTest/Test1.cs b/LibGitTest/Test1.cs
new file mode 100644
index 0000000..ac88cf9
--- /dev/null
+++ b/LibGitTest/Test1.cs
@@ -0,0 +1,36 @@
+using LibGit;
+
+namespace LibGitTest;
+
+public class Test1
+{
+ public static async Task Run()
+ {
+ var repo = new GitRepo(new FileRepoSource(@"/home/root@Rory/tmpgit/MatrixRoomUtils.git"));
+// var repo = new GitRepo(new WebRepoSource("https://git.rory.gay/MatrixRoomUtils.git/"));
+ var commit = await repo.GetCommit("HEAD");
+
+ while (commit.ParentIds.Count > 0)
+ {
+ Console.WriteLine($"{commit.CommitId[..7]} | {commit.AuthorName.PadRight(16)} | {commit.Message.PadRight(32)[..32]} | {commit.TreeId}");
+ var tree = await commit.GetTreeAsync();
+ await PrintTreeRecursive(tree);
+
+ commit = await repo.GetCommit(commit.ParentIds.First());
+ }
+
+ async Task PrintTreeRecursive(TreeObject tree, int indent = 0)
+ {
+ foreach (var (key, value) in tree.Entries.Where(x => x.Value.Mode.StartsWith("1")))
+ {
+ Console.WriteLine($"{value.Mode.PadLeft(6)} {value.Hash}{"".PadRight(indent)} {key}");
+ }
+
+ foreach (var (key, value) in tree.Entries.Where(x => !x.Value.Mode.StartsWith("1")))
+ {
+ Console.WriteLine($"{value.Mode.PadLeft(6)}{"".PadRight(indent + 41)} {key + "/"}");
+ await PrintTreeRecursive(new TreeObject(tree.RepoSource, value.Hash).ReadFromZlibCompressedObjFile(await tree.RepoSource.GetObjectStreamById(value.Hash)), indent + 2);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/LibGitTest/Test2.cs b/LibGitTest/Test2.cs
new file mode 100644
index 0000000..c25f9b0
--- /dev/null
+++ b/LibGitTest/Test2.cs
@@ -0,0 +1,67 @@
+using LibGit;
+
+namespace LibGitTest;
+
+public class Test2
+{
+ public static async Task Run()
+ {
+ List<CommitObject> commits = new();
+ List<GitRef> heads = new();
+ var repo = new GitRepo(new WebRepoSource("https://git.rory.gay/.fosscord/fosscord-server.git/")
+ {
+ });
+
+ var ss = new SemaphoreSlim(12,12);
+
+ var _heads = repo.GetRefs().GetAsyncEnumerator();
+ while (await _heads.MoveNextAsync())
+ {
+ heads.Add(_heads.Current);
+ var isCached = await ((WebRepoSource)repo.RepoSource).HasObjectCached(_heads.Current.CommitId);
+ Console.WriteLine(_heads.Current.Name+ " - cache miss: " + !isCached);
+ if (!isCached)
+ {
+
+ var _c = _heads.Current.CommitId;
+#pragma warning disable CS4014
+ Task.Run(async () =>
+#pragma warning restore CS4014
+ {
+ await ss.WaitAsync();
+ Console.WriteLine("hi from task");
+ var a = new GitRepo(new WebRepoSource("https://git.rory.gay/.fosscord/fosscord-server.git/")
+ {
+ }).GetCommits(_c).GetAsyncEnumerator();
+ while (
+ await a.MoveNextAsync()
+ && !await ((WebRepoSource)repo.RepoSource)
+ .HasObjectCached(a.Current.CommitId)
+ ) Console.WriteLine($"Prefetched commit {a.Current.CommitId} with {a.Current.ParentIds.Count()} parents");
+ Console.WriteLine($"Reached already-cached log: {a.Current.CommitId}");
+ ss.Release();
+ });
+ }
+ }
+
+
+ var log = repo.GetCommits(heads.First(x=>x.Name == "refs/heads/master").CommitId).GetAsyncEnumerator();
+ while (await log.MoveNextAsync())
+ {
+ commits.Add(log.Current);
+ if (commits.Count % 50 == 0)
+ {
+ // StateHasChanged();
+ await Task.Delay(1);
+ }
+
+ Console.WriteLine($"Fetched in-log commit {log.Current.CommitId}, {12-ss.CurrentCount} tasks running");
+
+ if (ss.CurrentCount == 12)
+ {
+ Console.WriteLine("All tasks finished");
+ return;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/LibGitTest/Test3.cs b/LibGitTest/Test3.cs
new file mode 100644
index 0000000..be7275f
--- /dev/null
+++ b/LibGitTest/Test3.cs
@@ -0,0 +1,17 @@
+using LibGit;
+using LibGit.Extensions;
+
+namespace LibGitTest;
+
+public class Test3
+{
+ public static async Task Run()
+ {
+ var repo = new GitRepo(new FileRepoSource(@"/home/root@Rory/tmpgit/fosscord-server.git"));
+ var packs = repo.GetPacks().GetAsyncEnumerator();
+ while(await packs.MoveNextAsync())
+ {
+ Console.WriteLine(packs.Current.ToJson());
+ }
+ }
+}
\ No newline at end of file
diff --git a/LibGitTest/WebRepoSource.cs b/LibGitTest/WebRepoSource.cs
new file mode 100644
index 0000000..39d9b79
--- /dev/null
+++ b/LibGitTest/WebRepoSource.cs
@@ -0,0 +1,28 @@
+using LibGit.Interfaces;
+
+namespace LibGitTest;
+
+public class WebRepoSource : IRepoSource
+{
+ private const bool _debug = false;
+ public WebRepoSource(string basePath)
+ {
+ BasePath = basePath;
+ }
+
+ public string BasePath { get; set; }
+
+ public async Task<Stream> GetFileStream(string path)
+ {
+ var client = new HttpClient();
+ if(_debug)Console.WriteLine("Fetching file: " + Path.Join(BasePath, path));
+ var response = await client.GetAsync(Path.Join(BasePath, path));
+ if(!response.IsSuccessStatusCode) throw new Exception("Failed to fetch file: " + Path.Join(BasePath, path));
+ return await response.Content.ReadAsStreamAsync();
+ }
+
+ public async Task<bool> HasObjectCached(string currentCommitId)
+ {
+ return Random.Shared.Next(0, 2) == 1;
+ }
+}
\ No newline at end of file
|