Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192import { jsonGet } from "./_request";import { splitMessage, type CommitSummary } from "./repo";import type { BobbinContext, XrpcRequestInit } from "./client";import type * as ShTangledGitDefs from "./lexicons/types/sh/tangled/git/defs";import type * as GetDiff from "./lexicons/types/sh/tangled/git/temp2/getDiff";import type * as GetInterdiff from "./lexicons/types/sh/tangled/git/temp2/getInterdiff";import type * as ListCommits from "./lexicons/types/sh/tangled/git/temp2/listCommits";import type * as MergeCheck from "./lexicons/types/sh/tangled/git/temp2/mergeCheck";
// gitmirror's own xrpc surface, proxied through bobbin — its grpc service is// internal and streaming, so the read paths the frontend needs live hereconst LIST_COMMITS_NSID = "sh.tangled.git.temp2.listCommits";const GET_DIFF_NSID = "sh.tangled.git.temp2.getDiff";const GET_INTERDIFF_NSID = "sh.tangled.git.temp2.getInterdiff";const MERGE_CHECK_NSID = "sh.tangled.git.temp2.mergeCheck";
export type MirrorCommit = ListCommits.Commit;
export const listCommits = ( ctx: BobbinContext, params: ListCommits.$params, init?: XrpcRequestInit) => jsonGet<ListCommits.$output>(ctx, LIST_COMMITS_NSID, params, init);
export type MirrorFileDiff = ShTangledGitDefs.FileDiff;
export const getDiff = (ctx: BobbinContext, params: GetDiff.$params, init?: XrpcRequestInit) => jsonGet<GetDiff.$output>(ctx, GET_DIFF_NSID, params, init);
// `base*` is the older version's span, `head*` the newer one's: gitmirror// rebases base1..base2 onto head1 and diffs the result against head2export const getInterdiff = ( ctx: BobbinContext, params: GetInterdiff.$params, init?: XrpcRequestInit) => jsonGet<GetInterdiff.$output>(ctx, GET_INTERDIFF_NSID, params, init);
export type MirrorConflict = MergeCheck.Conflict;
export const mergeCheck = ( ctx: BobbinContext, params: MergeCheck.$params, init?: XrpcRequestInit) => jsonGet<MergeCheck.$output>(ctx, MERGE_CHECK_NSID, params, init);
export type MirrorFileKind = "new" | "deleted" | "renamed" | "changed";
// an add or delete carries the same path on both sides — gix names both resources// after the change's location — so the side that doesn't exist is the one whose oid// is null, not the one whose path is emptyexport const diffSideExists = (src: ShTangledGitDefs.DiffSrc): boolean => src.path !== "" && !/^0+$/.test(src.oid);
export const diffFileName = (file: MirrorFileDiff): string => file.rhsSrc.path || file.lhsSrc.path;
export const diffFileKind = (file: MirrorFileDiff): MirrorFileKind => { if (!diffSideExists(file.lhsSrc)) return "new"; if (!diffSideExists(file.rhsSrc)) return "deleted"; return file.lhsSrc.path === file.rhsSrc.path ? "changed" : "renamed";};
// the payload has no line text, only aligned line numbers: a pair with one side// missing is a pure insertion or deletion, a pair with both is a replaced lineexport const diffFileStat = (file: MirrorFileDiff): { insertions: number; deletions: number } => { let insertions = 0; let deletions = 0; for (const hunk of file.hunks) { for (const line of hunk.lines) { if (line.rhs !== undefined) insertions++; if (line.lhs !== undefined) deletions++; } } return { insertions, deletions };};
export const toMirrorCommitSummary = (commit: MirrorCommit): CommitSummary => { const [subject, body] = splitMessage(commit.message); return { hash: commit.oid, shortHash: commit.oid.slice(0, 8), subject, body, authorName: commit.author.name, authorEmail: commit.author.email, when: commit.committer.when ?? commit.author.when, // the pull page links a commit row as `firstParent..commit` parent: commit.parents[0], // jj stashes the change id in a commit header, same lookup the appview does changeId: commit.extraHeaders.find((header) => header.key === "change-id")?.value };};