mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-13 18:40:50 +08:00
Co-authored-by: Rūdolfs Ošiņš <rudolfs@osins.org> Signed-off-by: xphoniex <dj.2dixx@gmail.com> Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
105 lines
1.8 KiB
TypeScript
105 lines
1.8 KiB
TypeScript
export const lineNumberR = (line: LineDiff): string | number => {
|
|
switch (line.type) {
|
|
case LineDiffType.Addition: {
|
|
return line.lineNo;
|
|
}
|
|
case LineDiffType.Context: {
|
|
return line.lineNoNew;
|
|
}
|
|
case LineDiffType.Deletion: {
|
|
return " ";
|
|
}
|
|
}
|
|
};
|
|
|
|
export const lineNumberL = (line: LineDiff): string | number => {
|
|
switch (line.type) {
|
|
case LineDiffType.Addition: {
|
|
return " ";
|
|
}
|
|
case LineDiffType.Context: {
|
|
return line.lineNoOld;
|
|
}
|
|
case LineDiffType.Deletion: {
|
|
return line.lineNo;
|
|
}
|
|
}
|
|
};
|
|
|
|
export const lineSign = (line: LineDiff): string => {
|
|
switch (line.type) {
|
|
case LineDiffType.Addition: {
|
|
return "+";
|
|
}
|
|
case LineDiffType.Context: {
|
|
return " ";
|
|
}
|
|
case LineDiffType.Deletion: {
|
|
return "-";
|
|
}
|
|
}
|
|
};
|
|
|
|
export enum LineDiffType {
|
|
Addition = "addition",
|
|
Context = "context",
|
|
Deletion = "deletion",
|
|
}
|
|
|
|
export interface Addition {
|
|
type: LineDiffType.Addition;
|
|
line: string;
|
|
lineNo: number;
|
|
}
|
|
|
|
export interface Context {
|
|
type: LineDiffType.Context;
|
|
line: string;
|
|
lineNoNew: number;
|
|
lineNoOld: number;
|
|
}
|
|
|
|
export interface Deletion {
|
|
type: LineDiffType.Deletion;
|
|
line: string;
|
|
lineNo: number;
|
|
}
|
|
|
|
export type LineDiff = Addition | Deletion | Context;
|
|
|
|
export interface FileDiff {
|
|
path: string;
|
|
diff: Changeset;
|
|
eof: EofNewLine | null;
|
|
}
|
|
|
|
export interface Changeset {
|
|
type: string;
|
|
hunks: Hunk[];
|
|
}
|
|
|
|
export interface Hunk {
|
|
header: string;
|
|
lines: LineDiff[];
|
|
}
|
|
|
|
export interface Diff {
|
|
added: FileDiff[];
|
|
deleted: FileDiff[];
|
|
moved: string[];
|
|
copied: string[];
|
|
modified: FileDiff[];
|
|
stats: DiffStats;
|
|
}
|
|
|
|
export interface DiffStats {
|
|
insertions: number;
|
|
deletions: number;
|
|
}
|
|
|
|
export enum EofNewLine {
|
|
OldMissing = "oldMissing",
|
|
NewMissing = "newMissing",
|
|
BothMissing = "bothMissing",
|
|
}
|