diff --git a/LibGitTest/FileRepoSource.cs b/LibGitTest/FileRepoSource.cs
index 09ec836..94d767f 100644
--- a/LibGitTest/FileRepoSource.cs
+++ b/LibGitTest/FileRepoSource.cs
@@ -7,10 +7,16 @@ public class FileRepoSource : IRepoSource
public FileRepoSource(string basePath)
{
BasePath = basePath;
+ if (!Directory.Exists(BasePath)) Console.WriteLine("Warning: Base path does not exist: " + BasePath);
}
public string BasePath { get; set; }
+ public async Task<bool> FileExists(string path)
+ {
+ return File.Exists(Path.Join(BasePath, path));
+ }
+
public async Task<Stream> GetFileStream(string path)
{
return File.OpenRead(Path.Join(BasePath, path));
diff --git a/LibGitTest/Test1.cs b/LibGitTest/Test1.cs
index ac88cf9..ebd6f7e 100644
--- a/LibGitTest/Test1.cs
+++ b/LibGitTest/Test1.cs
@@ -1,3 +1,4 @@
+using System.Runtime.CompilerServices;
using LibGit;
namespace LibGitTest;
@@ -6,7 +7,8 @@ public class Test1
{
public static async Task Run()
{
- var repo = new GitRepo(new FileRepoSource(@"/home/root@Rory/tmpgit/MatrixRoomUtils.git"));
+ Console.WriteLine("Test1 running");
+ var repo = new GitRepo(new FileRepoSource(@"/home/Rory/git/matrix/MatrixRoomUtils.git"));
// var repo = new GitRepo(new WebRepoSource("https://git.rory.gay/MatrixRoomUtils.git/"));
var commit = await repo.GetCommit("HEAD");
diff --git a/LibGitTest/Test2.cs b/LibGitTest/Test2.cs
index c25f9b0..46337e6 100644
--- a/LibGitTest/Test2.cs
+++ b/LibGitTest/Test2.cs
@@ -6,23 +6,22 @@ public class Test2
{
public static async Task Run()
{
+ return;
+ Console.WriteLine("Test2 running");
List<CommitObject> commits = new();
List<GitRef> heads = new();
- var repo = new GitRepo(new WebRepoSource("https://git.rory.gay/.fosscord/fosscord-server.git/")
- {
- });
+ var repo = new GitRepo(new WebRepoSource("https://git.rory.gay/.fosscord/fosscord-server.git/"));
+
+ var ss = new SemaphoreSlim(12, 12);
- 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);
+ Console.WriteLine(_heads.Current.Name + " - cache miss: " + !isCached);
if (!isCached)
{
-
var _c = _heads.Current.CommitId;
#pragma warning disable CS4014
Task.Run(async () =>
@@ -34,7 +33,7 @@ public class Test2
{
}).GetCommits(_c).GetAsyncEnumerator();
while (
- await a.MoveNextAsync()
+ await a.MoveNextAsync()
&& !await ((WebRepoSource)repo.RepoSource)
.HasObjectCached(a.Current.CommitId)
) Console.WriteLine($"Prefetched commit {a.Current.CommitId} with {a.Current.ParentIds.Count()} parents");
@@ -43,9 +42,9 @@ public class Test2
});
}
}
-
- var log = repo.GetCommits(heads.First(x=>x.Name == "refs/heads/master").CommitId).GetAsyncEnumerator();
+
+ var log = repo.GetCommits(heads.First(x => x.Name == "refs/heads/master").CommitId).GetAsyncEnumerator();
while (await log.MoveNextAsync())
{
commits.Add(log.Current);
@@ -54,8 +53,8 @@ public class Test2
// StateHasChanged();
await Task.Delay(1);
}
-
- Console.WriteLine($"Fetched in-log commit {log.Current.CommitId}, {12-ss.CurrentCount} tasks running");
+
+ Console.WriteLine($"Fetched in-log commit {log.Current.CommitId}, {12 - ss.CurrentCount} tasks running");
if (ss.CurrentCount == 12)
{
diff --git a/LibGitTest/Test3.cs b/LibGitTest/Test3.cs
index be7275f..24d6986 100644
--- a/LibGitTest/Test3.cs
+++ b/LibGitTest/Test3.cs
@@ -1,5 +1,4 @@
using LibGit;
-using LibGit.Extensions;
namespace LibGitTest;
@@ -7,11 +6,15 @@ public class Test3
{
public static async Task Run()
{
- var repo = new GitRepo(new FileRepoSource(@"/home/root@Rory/tmpgit/fosscord-server.git"));
+ Console.WriteLine("Test3 running");
+ var repo = new GitRepo(new FileRepoSource(@"/home/Rory/git/spacebar/server-master/.git"));
var packs = repo.GetPacks().GetAsyncEnumerator();
+ int count = 0;
while(await packs.MoveNextAsync())
{
- Console.WriteLine(packs.Current.ToJson());
+ count += packs.Current.ObjectCount;
+ // Console.WriteLine(packs.Current.ToJson());
}
+ Console.WriteLine($"Read {count} objects from pack files.");
}
}
\ No newline at end of file
diff --git a/LibGitTest/WebRepoSource.cs b/LibGitTest/WebRepoSource.cs
index 39d9b79..04f5b29 100644
--- a/LibGitTest/WebRepoSource.cs
+++ b/LibGitTest/WebRepoSource.cs
@@ -4,7 +4,7 @@ namespace LibGitTest;
public class WebRepoSource : IRepoSource
{
- private const bool _debug = false;
+ private const bool _debug = true;
public WebRepoSource(string basePath)
{
BasePath = basePath;
@@ -12,9 +12,18 @@ public class WebRepoSource : IRepoSource
public string BasePath { get; set; }
+ public async Task<bool> FileExists(string path)
+ {
+ using var client = new HttpClient();
+ if(_debug)Console.WriteLine("Checking file exists: " + Path.Join(BasePath, path));
+ var response = await client.GetAsync(Path.Join(BasePath, path));
+ if(_debug)Console.WriteLine("Response status code: " + response.StatusCode);
+ return response.IsSuccessStatusCode;
+ }
+
public async Task<Stream> GetFileStream(string path)
{
- var client = new HttpClient();
+ using 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));
|