namespace Blog.Models;
///
/// A name, an address and a time — git's author and committer lines, flattened out of libgit2's
/// handles so a page can still read them after the repository has been closed.
///
public sealed record GitSignature(string Name, string Email, DateTimeOffset When);
/// One repository under the repository root, as the index lists it.
/// The directory name, which is also the route segment: blog.git.
/// The same without the suffix, for headings: blog.
///
/// The description file, unless it still holds the placeholder git init writes.
///
/// gitweb.owner from the repository config, which is what cgit reads.
/// The branch HEAD points at, or null when it is unborn.
/// The commit on that branch, and when it landed.
public sealed record GitRepoSummary(
string Name,
string DisplayName,
string? Description,
string? Owner,
string? Head,
GitCommitInfo? Tip);
/// A commit, with everything a page shows about it.
///
/// The branch and tag names whose tips are this commit. Filled in on the log, where the badges
/// mark where each branch has got to; empty everywhere else.
///
public sealed record GitCommitInfo(
string Sha,
string Summary,
string Body,
GitSignature Author,
GitSignature Committer,
IReadOnlyList Parents,
IReadOnlyList Refs)
{
/// Enough of the hash to be unambiguous, and short enough to sit in a table.
public string ShortSha => Sha.Length >= 10 ? Sha[..10] : Sha;
/// A commit with two or more parents is diffed against the first, as git does.
public bool IsMerge => Parents.Count > 1;
}
/// A page of history, and whether there is another one behind it.
public sealed record GitLogPage(IReadOnlyList Commits, bool HasMore);
/// What a tree entry is, as far as the listing cares.
public enum GitEntryKind
{
Directory,
File,
/// Mode 100755. Worth marking: it is the difference between a script and a text file.
Executable,
Symlink,
/// Another repository, pinned at a commit. There is nothing here to browse into.
Submodule
}
/// Full path from the repository root, which is what the tree links carry.
public sealed record GitTreeEntry(string Name, string Path, GitEntryKind Kind, long Size, string Sha);
///
/// Decided the way git decides it: a NUL byte anywhere in the first few kilobytes. Binary blobs
/// are linked to the raw endpoint instead of being printed.
///
///
/// The file, newlines normalised to \n and the final one removed, or null when there is
/// nothing to print. Whole rather than split into lines: the highlighter needs the whole of it to
/// see that a block comment or a fenced code block carries on past the end of a line.
///
public sealed record GitBlob(
string Path,
string Sha,
long Size,
bool IsBinary,
bool TooLarge,
string? Text);
///
/// One path in one revision: a directory listing, or a file. Which of the two is set says which
/// the path turned out to be.
///
/// The revision as it was asked for, for links that stay on this branch.
public sealed record GitPathView(
GitCommitInfo Commit,
string Reference,
string Path,
IReadOnlyList? Entries,
GitBlob? Blob);
public enum GitChange
{
Added,
Deleted,
Modified,
Renamed,
Copied,
TypeChanged
}
///
/// ' ' context, '+' added, '-' removed, '\' for git's
/// "No newline at end of file" note.
///
public sealed record GitDiffLine(char Origin, int? OldNumber, int? NewNumber, string Text);
/// The @@ -a,b +c,d @@ line, section heading and all.
public sealed record GitDiffHunk(string Header, IReadOnlyList Lines);
/// Empty for a binary file, and for one dropped to keep the page finite.
public sealed record GitDiffFile(
string Path,
string? OldPath,
GitChange Change,
int Added,
int Deleted,
bool IsBinary,
bool Skipped,
IReadOnlyList Hunks);
///
/// Set when the diff ran past the line budget and the rest of the files kept their stats but lost
/// their hunks. A commit that vendors a 4 MB file should not render 4 MB of green.
///
public sealed record GitDiff(IReadOnlyList Files, int Added, int Deleted, bool Truncated);
///
/// One file's bytes at one revision, for the raw endpoint. decides
/// whether it is handed over as text or as a download.
///
public sealed record GitRawBlob(byte[] Bytes, bool IsBinary, string Name);
/// A commit and the diff that goes with it — everything the commit page renders.
public sealed record GitCommitView(GitCommitInfo Commit, GitDiff Diff);
/// A branch or a tag, with the commit it points at.
/// An annotated tag's own message. Null for branches and lightweight tags.
public sealed record GitRef(
string Name,
bool IsTag,
string Sha,
GitCommitInfo? Tip,
string? Message);
/// Every ref in a repository, branches and tags kept apart as the refs page shows them.
public sealed record GitRefsView(IReadOnlyList Branches, IReadOnlyList Tags);