// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: AGPL-3.0-or-later import { getGitMessages } from "@/lib/git-messages"; import type { GitLogEntry, GitRepository, GitTree } from "@/lib/git.server"; import type { Locale } from "@/lib/localization"; import { gitDate, gitHref, gitSize } from "./GitFrame"; /** The reference to keep in links: none for the default branch. */ export function keptRef( repository: GitRepository, reference: string, ): string | undefined { return reference === repository.defaultBranch ? undefined : reference; } /** The path of a tree as links, from the root. */ export function GitBreadcrumbs({ locale, repository, reference, path, }: Readonly<{ locale: Locale; repository: GitRepository; reference: string; path: string; }>) { const text = getGitMessages(locale); const ref = keptRef(repository, reference); const parts = path ? path.split("/") : []; return (

{reference} {text.root} {parts.map((part, index) => { const at = parts.slice(0, index + 1).join("/"); return ( {" / "} {index === parts.length - 1 ? ( {part} ) : ( {part} )} ); })}

); } /** The entries of a tree, or the text of a file. */ export function GitTreeView({ locale, repository, tree, }: Readonly<{ locale: Locale; repository: GitRepository; tree: GitTree }>) { const text = getGitMessages(locale); const ref = keptRef(repository, tree.reference); const raw = gitHref(`/${repository.name}/raw`, { ref: tree.commit, path: tree.path, }); if (tree.kind === "blob") { return (

{gitSize(tree.size)} · {text.raw} ·{" "} {text.log}

{tree.isBinary ? (

{text.binary}

) : (
            {tree.text}
          
)} {tree.isTruncated ? (

{text.truncated}

) : null}
); } const kindWords = { tree: text.directory, link: text.link, submodule: text.submodule, blob: "", }; return (

{text.files}

{(tree.entries ?? []).map((entry) => { const at = tree.path ? `${tree.path}/${entry.name}` : entry.name; return ( ); })}
{text.name} {text.size}
{entry.kind === "submodule" ? ( {entry.name} ) : ( {entry.name} {entry.kind === "tree" ? "/" : ""} )} {entry.kind === "blob" ? gitSize(entry.size) : kindWords[entry.kind]}
); } /** A list of commits. */ export function GitCommitList({ locale, repository, commits, }: Readonly<{ locale: Locale; repository: GitRepository; commits: GitLogEntry[]; }>) { return (
    {commits.map((entry) => (
  1. {entry.subject || entry.commit.slice(0, 12)}

    {entry.commit.slice(0, 12)} · {entry.author} ·{" "}

  2. ))}
); }