1 files changed, 121 insertions, 0 deletions
diff --git a/GitRepoViewer/Pages/GitLog.razor b/GitRepoViewer/Pages/GitLog.razor
new file mode 100644
index 0000000..e518bb6
--- /dev/null
+++ b/GitRepoViewer/Pages/GitLog.razor
@@ -0,0 +1,121 @@
+@page "/GitLog"
+@using System.Web
+@using LibGit
+@using LibGit.Extensions
+<h3>GitLog</h3>
+<p>Repo: @Repo</p>
+
+@if (heads.Count > 0)
+{
+ <p>
+ Revision:
+ <details>
+ <summary>@Rev</summary>
+ </details>
+ </p>
+}
+
+@if (commits != null)
+{
+ <table class="table">
+ <thead>
+ <tr>
+ <th>Heads</th>
+ <th>Commit</th>
+ <th>Author</th>
+ <th>Message</th>
+ </tr>
+ </thead>
+ <tbody>
+ @foreach (var commit in commits)
+ {
+ <tr>
+ <td>
+ @foreach (var _ref in heads.Where(x=>x.CommitId == commit.CommitId))
+ {
+ <p>@_ref.Name</p>
+ }
+ </td>
+ <td>@commit.CommitId[..7]</td>
+ <td>@commit.AuthorName</td>
+ <td>@commit.Message</td>
+ </tr>
+ }
+ </tbody>
+ </table>
+}
+
+@code {
+
+ string? Repo { get; set; }
+ string? Rev { get; set; }
+
+ List<CommitObject> commits = new();
+ List<GitRef> 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);
+ }
+ }
+
+ }
+}
\ No newline at end of file
|