@page "/git/{Repository}/commit/{Sha}" @inherits GitPage @Title — git
@if (View is not { } view) {

No commit @Sha in @Repository.

} else {

@view.Commit.Summary @foreach (var name in view.Commit.Refs) { @name }

@if (view.Commit.Body is { Length: > 0 } body) {

@body

}
author
@view.Commit.Author.Name <@view.Commit.Author.Email> · @Exact(view.Commit.Author.When)
@if (Differs(view.Commit)) {
committer
@view.Commit.Committer.Name <@view.Commit.Committer.Email> · @Exact(view.Commit.Committer.When)
}
commit
@view.Commit.Sha
@if (view.Commit.Parents.Count > 0) {
parent@(view.Commit.Parents.Count == 1 ? "" : "s")
@foreach (var parent in view.Commit.Parents) { @Shorten(parent) }
}
tree
browse at this commit

@Changed(view.Diff) +@view.Diff.Added -@view.Diff.Deleted

@if (view.Diff.Files.Count == 0) {

@(view.Commit.IsMerge ? "Nothing changed against the first parent — the other side brought it all." : "No changes.")

} else {
@for (var index = 0; index < view.Diff.Files.Count; index++) { var file = view.Diff.Files[index]; }
@file.Path @ChangeLabel(file.Change) +@file.Added -@file.Deleted
} @if (view.Diff.Truncated) {

This diff is longer than one page will show. The files below it keep their counts; read them at this commit's tree instead.

}
@for (var index = 0; index < view.Diff.Files.Count; index++) { var file = view.Diff.Files[index];

@if (file.OldPath is { } old) { @old → } @file.Path +@file.Added -@file.Deleted

@if (file.IsBinary) {

Binary file. Download it as it was here.

} else if (file.Skipped) {

Too far down a long diff to render. @file.Added added, @file.Deleted removed.

} else if (file.Hunks.Count == 0) {

@(ChangeLabel(file.Change) is { Length: > 0 } label ? label : "No textual change") — no lines changed.

} else {
@foreach (var hunk in file.Hunks) { @foreach (var line in hunk.Lines) { @if (line.Origin == '\\') { } else { } } }
@hunk.Header
@line.Text
@line.OldNumber @line.NewNumber @line.Origin@line.Text
}
} }
@code { [Parameter] public string Sha { get; set; } = ""; private GitCommitView? View { get; set; } private string Short => Shorten(View?.Commit.Sha ?? Sha); private string Title => View is { } view ? $"{view.Commit.Summary} · {Repository}" : Repository; protected override void OnParametersSet() { View = Service.GetCommit(Repository, Sha); if (View is null) NotFound(); } private static string Shorten(string sha) => sha.Length >= 10 ? sha[..10] : sha; /// A committer line worth printing is one that says something the author's didn't. private static bool Differs(GitCommitInfo commit) => commit.Committer.Email != commit.Author.Email || commit.Committer.When != commit.Author.When; private static string Changed(GitDiff diff) => diff.Files.Count == 1 ? "1 file changed" : $"{diff.Files.Count} files changed"; private static string Anchor(int index) => $"f{index}"; private static string Row(char origin) => origin switch { '+' => "add", '-' => "del", _ => "ctx" }; }