diff --git a/scripts/run-http-api-with-fixtures b/scripts/run-http-api-with-fixtures index d2e5c9bf7..d3947d4de 100755 --- a/scripts/run-http-api-with-fixtures +++ b/scripts/run-http-api-with-fixtures @@ -88,7 +88,7 @@ run_binary() { $HTTP_API_BINARY --listen 0.0.0.0:8777 --root $WORKSPACE --passphrase $PASSPHRASE } -BINADY=false +BINARY=false NON_INTERACTIVE=false DETACH=false diff --git a/src/lib/commit.ts b/src/lib/commit.ts index fc5a08550..83892d724 100644 --- a/src/lib/commit.ts +++ b/src/lib/commit.ts @@ -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; diff --git a/src/lib/diff.ts b/src/lib/diff.ts index 7a6e71c34..3b637743e 100644 --- a/src/lib/diff.ts +++ b/src/lib/diff.ts @@ -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", diff --git a/src/lib/patch.ts b/src/lib/patch.ts index cd775154f..926f73c1c 100644 --- a/src/lib/patch.ts +++ b/src/lib/patch.ts @@ -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"; diff --git a/src/lib/project.ts b/src/lib/project.ts index 51157b3da..125e35242 100644 --- a/src/lib/project.ts +++ b/src/lib/project.ts @@ -276,10 +276,42 @@ export class Project implements ProjectInfo { } async getCommit(commit: string): Promise { - 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 { diff --git a/src/views/projects/SourceBrowser/Changeset.svelte b/src/views/projects/SourceBrowser/Changeset.svelte index 7d3f30870..bfca4a5c1 100644 --- a/src/views/projects/SourceBrowser/Changeset.svelte +++ b/src/views/projects/SourceBrowser/Changeset.svelte @@ -1,19 +1,18 @@