import { createServerFn } from "@tanstack/react-start";
import { withAuthorAccount, withAuthorAccounts } from "~/server/commit-authors";
import type { WithAuthorAccount } from "~/server/commit-authors";
import { assertVisibleRevision, isReachableCommit } from "~/server/git/reachable";
import { limitBrowse, limitHeavy, MAX_PAGE } from "~/server/limits";
import { z } from "zod";
import { viewerMiddleware } from "./middleware";
import { repoDb } from "~/server/scoped-db";
import { assertRepoReady, requireRepoAccess } from "~/server/repos";
import { branchSha, listRefs, resolveRevision, splitRevisionPath } from "~/server/git/refs";
import { withStore } from "~/server/git/store";
import type { GitStore } from "~/server/git/store";
import { diffTreesCached } from "~/server/git/diff";
import { renderMarkdown } from "~/server/markdown";
import { notFoundError } from "~/server/errors";
import { lfsBlobPreview } from "~/server/lfs/content";
import { combinedState, listCommitStatuses } from "~/server/statuses";
import { repoRef } from "~/lib/validation";
import type { CommitSummary, RepoRefs, RepoRow, StatusState, TreeEntry } from "~/lib/types";
const README_NAMES = ["readme.md", "readme.markdown", "readme", "readme.txt"];
const MAX_VIEW_BYTES = 1024 * 1024;
const COMMITS_PAGE = 30;
const BINARY_SNIFF = 8000;
const decoder = new TextDecoder();
const FULL_SHA_LENGTH = 40;
const MAX_LISTED_REFS = 90;
function sortEntries(entries: TreeEntry[]): TreeEntry[] {
return [...entries].sort((left, right) => {
const leftDir = left.type === "tree" ? 0 : 1;
const rightDir = right.type === "tree" ? 0 : 1;
return leftDir - rightDir || left.name.localeCompare(right.name);
});
}
function resolveSplat(repo: RepoRow, refs: RepoRefs, splat: string) {
if (!splat) {
const sha = branchSha(refs, repo.default_branch) ?? refs.branches[0]?.sha;
if (!sha) return null;