mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
Add Heartwood translation layer for file diffs
Co-authored-by: xphoniex <dj.2dixx@gmail.com> Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
co-authored by
xphoniex
parent
ca10a69ee5
commit
4bb34023c2
+1
-6
@@ -1,5 +1,5 @@
|
||||
import type { Stats, Person } from "@app/lib/project";
|
||||
import type { Diff } from "@app/lib/diff";
|
||||
import type { Diff, DiffStats } from "@app/lib/diff";
|
||||
import { ApiError } from "@app/lib/api";
|
||||
import { getDaysPassed } from "@app/lib/utils";
|
||||
|
||||
@@ -63,11 +63,6 @@ export interface WeeklyActivity {
|
||||
week: number;
|
||||
}
|
||||
|
||||
export interface DiffStats {
|
||||
additions: number;
|
||||
deletions: number;
|
||||
}
|
||||
|
||||
export interface Commit {
|
||||
header: CommitHeader;
|
||||
stats: DiffStats;
|
||||
|
||||
+15
-10
@@ -1,10 +1,10 @@
|
||||
export const lineNumberR = (line: LineDiff): string | number => {
|
||||
switch (line.type) {
|
||||
case LineDiffType.Addition: {
|
||||
return line.lineNum;
|
||||
return line.lineNo;
|
||||
}
|
||||
case LineDiffType.Context: {
|
||||
return line.lineNumNew;
|
||||
return line.lineNoNew;
|
||||
}
|
||||
case LineDiffType.Deletion: {
|
||||
return " ";
|
||||
@@ -18,10 +18,10 @@ export const lineNumberL = (line: LineDiff): string | number => {
|
||||
return " ";
|
||||
}
|
||||
case LineDiffType.Context: {
|
||||
return line.lineNumOld;
|
||||
return line.lineNoOld;
|
||||
}
|
||||
case LineDiffType.Deletion: {
|
||||
return line.lineNum;
|
||||
return line.lineNo;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -41,7 +41,7 @@ export const lineSign = (line: LineDiff): string => {
|
||||
};
|
||||
|
||||
export enum LineDiffType {
|
||||
Addition = "addition",
|
||||
Addition = "insertion",
|
||||
Context = "context",
|
||||
Deletion = "deletion",
|
||||
}
|
||||
@@ -49,20 +49,20 @@ export enum LineDiffType {
|
||||
export interface Addition {
|
||||
type: LineDiffType.Addition;
|
||||
line: string;
|
||||
lineNum: number;
|
||||
lineNo: number;
|
||||
}
|
||||
|
||||
export interface Context {
|
||||
type: LineDiffType.Context;
|
||||
line: string;
|
||||
lineNumNew: number;
|
||||
lineNumOld: number;
|
||||
lineNoNew: number;
|
||||
lineNoOld: number;
|
||||
}
|
||||
|
||||
export interface Deletion {
|
||||
type: LineDiffType.Deletion;
|
||||
line: string;
|
||||
lineNum: number;
|
||||
lineNo: number;
|
||||
}
|
||||
|
||||
export type LineDiff = Addition | Deletion | Context;
|
||||
@@ -84,13 +84,18 @@ export interface Hunk {
|
||||
}
|
||||
|
||||
export interface Diff {
|
||||
created: FileDiff[];
|
||||
added: FileDiff[];
|
||||
deleted: FileDiff[];
|
||||
moved: string[];
|
||||
copied: string[];
|
||||
modified: FileDiff[];
|
||||
}
|
||||
|
||||
export interface DiffStats {
|
||||
insertions: number;
|
||||
deletions: number;
|
||||
}
|
||||
|
||||
export enum EofNewLine {
|
||||
OldMissing = "oldMissing",
|
||||
NewMissing = "newMissing",
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import type { Author, PeerInfo } from "@app/lib/cobs";
|
||||
import type { Comment, Thread } from "@app/lib/issue";
|
||||
import type { Commit, DiffStats } from "@app/lib/commit";
|
||||
import type { Diff } from "@app/lib/diff";
|
||||
import type { Commit } from "@app/lib/commit";
|
||||
import type { Diff, DiffStats } from "@app/lib/diff";
|
||||
import type { Host } from "@app/lib/api";
|
||||
import type { PeerId, Id } from "@app/lib/project";
|
||||
|
||||
|
||||
+33
-1
@@ -276,10 +276,42 @@ export class Project implements ProjectInfo {
|
||||
}
|
||||
|
||||
async getCommit(commit: string): Promise<Commit> {
|
||||
return new Request(
|
||||
const result = await new Request(
|
||||
`projects/${this.id}/commits/${commit}`,
|
||||
this.seed.addr,
|
||||
).get();
|
||||
result.stats["insertions"] = result.stats["additions"];
|
||||
delete result.stats["additions"];
|
||||
result.diff["added"] = result.diff["created"];
|
||||
delete result.diff["created"];
|
||||
|
||||
for (const kind of ["added", "deleted", "modified"]) {
|
||||
for (const file of result.diff[kind]) {
|
||||
for (const hunk of file.diff.hunks) {
|
||||
for (const line of hunk.lines) {
|
||||
if (line["type"] === "addition") {
|
||||
line["type"] = "insertion";
|
||||
}
|
||||
if (line["lineNumOld"]) {
|
||||
line["lineNoOld"] = line["lineNumOld"];
|
||||
delete line["lineNumOld"];
|
||||
}
|
||||
|
||||
if (line["lineNumNew"]) {
|
||||
line["lineNoNew"] = line["lineNumNew"];
|
||||
delete line["lineNumNew"];
|
||||
}
|
||||
|
||||
if (line["lineNum"]) {
|
||||
line["lineNo"] = line["lineNum"];
|
||||
delete line["lineNum"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async getTree(commit: string, path: string): Promise<Tree> {
|
||||
|
||||
Reference in New Issue
Block a user