summary refs log tree commit diff
path: root/LibGitTest/Test2.cs
blob: c25f9b0cb0f418e5ecb8faefdb0de1b5622f0229 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
            }
        }
    }
}