This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / web / src / lib / api / diff.ts
1.8 kB 74 lines
1import type { BobbinContext, XrpcRequestInit } from "./client"; 2import { diff as knotDiff } from "./knot"; 3import type { GitSignature } from "./repo"; 4 5export interface NiceCommit { 6 hash?: number[]; 7 // hex form of the hash bytes above 8 this?: string; 9 // hex of the first parent, empty for a root commit 10 parent?: string; 11 parent_hashes?: number[][]; 12 author?: GitSignature; 13 committer?: GitSignature; 14 message?: string; 15 tree?: string; 16 change_id?: string; 17 pgp_signature?: string; 18} 19 20export interface DiffStat { 21 insertions: number; 22 deletions: number; 23 files_changed: number; 24} 25 26export const LineOp = { Context: 0, Delete: 1, Add: 2 } as const; 27export type LineOp = (typeof LineOp)[keyof typeof LineOp]; 28 29export interface DiffLine { 30 Op: LineOp; 31 Line: string; 32} 33 34export interface TextFragment { 35 Comment?: string; 36 OldPosition?: number; 37 OldLines?: number; 38 NewPosition?: number; 39 NewLines?: number; 40 LinesAdded?: number; 41 LinesDeleted?: number; 42 LeadingContext?: number; 43 TrailingContext?: number; 44 Lines?: DiffLine[]; 45} 46 47export interface DiffFile { 48 name: { old: string; new: string }; 49 text_fragments?: TextFragment[]; 50 is_binary?: boolean; 51 is_new?: boolean; 52 is_delete?: boolean; 53 is_copy?: boolean; 54 is_rename?: boolean; 55} 56 57export interface NiceDiff { 58 commit?: NiceCommit; 59 stat?: DiffStat; 60 diff?: DiffFile[]; 61} 62 63// the new path, or the old one for deletions 64export const diffFileName = (file: DiffFile): string => file.name.new || file.name.old; 65 66export interface RepoCommitResponse { 67 ref?: string; 68 diff?: NiceDiff; 69} 70 71// the mirror's temp surface has no diff endpoint, diffs go through 72// bobbin's knot proxy 73export const diffFor = (ctx: BobbinContext, repo: string, ref: string, init?: XrpcRequestInit) => 74 knotDiff<RepoCommitResponse>(ctx, { repo, ref }, init);