@page "/GitLog"
@using System.Web
@using LibGit
@using LibGit.Extensions
GitLog
Repo: @Repo
@if (heads.Count > 0)
{
Revision:
@Rev
}
@if (commits != null)
{
Heads |
Commit |
Author |
Message |
@foreach (var commit in commits)
{
@foreach (var _ref in heads.Where(x=>x.CommitId == commit.CommitId))
{
@_ref.Name
}
|
@commit.CommitId[..7] |
@commit.AuthorName |
@commit.Message |
}
}
@code {
string? Repo { get; set; }
string? Rev { get; set; }
List commits = new();
List heads = new();
protected override async Task OnInitializedAsync()
{
var query = new Uri(NavigationManager.Uri).Query;
var queryDictionary = HttpUtility.ParseQueryString(query);
if((Repo = queryDictionary["repo"]) == null)
{
return;
}
var repo = new GitRepo(new WebRepoSource(queryDictionary["repo"])
{
SessionStorage = sessionStorage
});
if((Rev = queryDictionary["rev"]) == null)
{
Rev = "HEAD";
}
var ss = new SemaphoreSlim(2,2);
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(queryDictionary["repo"])
{
SessionStorage = sessionStorage
}).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 == Rev).CommitId).GetAsyncEnumerator();
while (await log.MoveNextAsync())
{
commits.Add(log.Current);
if (commits.Count % 50 == 0)
{
StateHasChanged();
await Task.Delay(1);
}
}
}
}