Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137import { listCommits, toMirrorCommitSummary } from "./gitmirror";import { loadPullDiff, loadPullInterdiff, type PullDiff } from "./pullDiff";import { resolveChange, type PullDiffView, type PullInterdiffView, type Revspec} from "./pullRoute";import type { Did } from "@atcute/lexicons/syntax";import type { BobbinContext } from "./client";import type { GitTarget } from "./gitclient";import type { CommitSummary } from "./repo";import type { DiffStyle } from "$lib/components/repo/pierre";
const COMMIT_LIMIT = 100;
export interface PullPageDeps { ctx: BobbinContext; git: GitTarget; // todo: fork-based pulls read their head side from the source repo repo: Did; diffStyle: DiffStyle;}
// what either mode hands the pageexport interface PullPageDiff { commits: CommitSummary[]; commitsError?: string; diff?: PullDiff; diffError?: string;}
const listLog = async (deps: PullPageDeps, range: Revspec): Promise<CommitSummary[]> => { const page = await listCommits(deps.ctx, { repo: deps.repo, ranges: [`${range.base}..${range.head}`], limit: COMMIT_LIMIT }); return page.commits.map(toMirrorCommitSummary);};
const message = (cause: unknown) => (cause instanceof Error ? cause.message : String(cause));
const diffOf = (deps: PullPageDeps, spec: Revspec) => loadPullDiff( deps.ctx, deps.git, { baseRepo: deps.repo, baseCommit: spec.base, headRepo: deps.repo, headCommit: spec.head }, deps.diffStyle );
// both dids feed one scratch repo, so the pair is the same as a diff'sconst interdiffOf = (deps: PullPageDeps, a: Revspec, b: Revspec) => loadPullInterdiff( deps.ctx, deps.git, { baseRepo: deps.repo, baseCommit1: a.base, baseCommit2: a.head, headRepo: deps.repo, headCommit1: b.base, headCommit2: b.head }, deps.diffStyle );
// `version` is the whole round being viewed: the commit list always covers it,// whatever range the diff itself was narrowed toexport const prepareDiff = async ( deps: PullPageDeps, view: PullDiffView, version: Revspec): Promise<PullPageDiff> => { const result: PullPageDiff = { commits: [] };
// the two failures are independent — a dead log still leaves a readable diff await Promise.all([ listLog(deps, version).then( (commits) => (result.commits = commits), (cause) => (result.commitsError = message(cause)) ), diffOf(deps, view).then( (diff) => (result.diff = diff), (cause) => (result.diffError = message(cause)) ) ]);
return result;};
export const prepareInterdiff = async ( deps: PullPageDeps, view: PullInterdiffView): Promise<PullPageDiff> => { const result: PullPageDiff = { commits: [] };
let priorCommits: CommitSummary[] = []; try { [result.commits, priorCommits] = await Promise.all([ listLog(deps, view.to), view.changeId ? listLog(deps, view.from) : [] ]); } catch (cause) { result.commitsError = message(cause); }
try { if (!view.changeId) { result.diff = await interdiffOf(deps, view.from, view.to); } else if (result.commitsError) { result.diffError = result.commitsError; } else { const target = resolveChange(view.changeId, priorCommits, result.commits, { from: view.from.base, to: view.to.base }); if (target.kind === "missing") { result.diffError = "Can't find commit with given change-id."; } else if (target.kind === "diff") { result.diff = await diffOf(deps, target.spec); } else { result.diff = await interdiffOf(deps, target.from, target.to); } } } catch (cause) { result.diffError = message(cause); }
return result;};