summary refs log tree commit diff
path: root/LibGitTest/Test2.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LibGitTest/Test2.cs')
-rw-r--r--LibGitTest/Test2.cs67
1 files changed, 67 insertions, 0 deletions
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