diff --git a/src/lib/diff/utils.ts b/src/lib/diff/utils.ts deleted file mode 100644 index adfd384bf..000000000 --- a/src/lib/diff/utils.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Helper function to extract line numbers from the chunk header in a diff. - * - * @param diff A diff containing a chunk header - * @returns The original and modified file line numbers - */ -export function getLinesFromChunkHeader(diff: string): { - originalLineNumber: number; - currentLineNumber: number; -} { - try { - const diffLines = diff.split('\n'); - const header = diffLines[0]; - const lr = header.split('@@')[1].trim().split(' '); - return { - originalLineNumber: parseInt(lr[0].split(',')[0].slice(1)), - currentLineNumber: parseInt(lr[1].split(',')[0].slice(1)) - }; - } catch { - return { - originalLineNumber: -1, - currentLineNumber: -1 - }; - } -} diff --git a/src/lib/vbranches/ipc.ts b/src/lib/vbranches/ipc.ts index 915ff88b3..da984864a 100644 --- a/src/lib/vbranches/ipc.ts +++ b/src/lib/vbranches/ipc.ts @@ -1,7 +1,6 @@ import { invoke } from '$lib/ipc'; import { plainToInstance } from 'class-transformer'; import { Branch, BranchData, Target } from './types'; -import { getLinesFromChunkHeader } from '$lib/diff/utils'; export async function listVirtualBranches(params: { projectId: string }): Promise { const result = await invoke('list_virtual_branches', params); @@ -78,20 +77,5 @@ export async function fetchFromTarget(params: { projectId: string }) { function sortBranches(branches: Branch[]): Branch[] { branches.sort((a, b) => a.order - b.order); - branches.forEach((branch) => { - const files = branch.files; - files.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime()); - files.forEach((file) => { - const hunks = file.hunks; - // Sort by line before sorting by to prevent random order for hunks - // with the same timestamp. - hunks.sort((a, b) => { - const aln = getLinesFromChunkHeader(a.diff); - const bln = getLinesFromChunkHeader(b.diff); - return aln.currentLineNumber - bln.currentLineNumber; - }); - hunks.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime()); - }); - }); return branches; } diff --git a/src/routes/repo/[projectId]/HunkDiffViewer.svelte b/src/routes/repo/[projectId]/HunkDiffViewer.svelte index 7d50355a7..5556a6fdc 100644 --- a/src/routes/repo/[projectId]/HunkDiffViewer.svelte +++ b/src/routes/repo/[projectId]/HunkDiffViewer.svelte @@ -2,7 +2,6 @@ import { buildDiffRows, documentMap, RowType, type Row } from '$lib/components/Differ/renderer'; import { line, type DiffArray } from '$lib/diff'; import { create } from '$lib/components/Differ/CodeHighlighter'; - import { getLinesFromChunkHeader } from '$lib/diff/utils'; export let diff: string; export let filePath: string; @@ -17,7 +16,11 @@ currentLineNumber: number; } { const diffLines = diff.split('\n'); - const { originalLineNumber, currentLineNumber } = getLinesFromChunkHeader(diff); + const header = diffLines[0]; + + const lr = header.split('@@')[1].trim().split(' '); + const originalLineNumber = parseInt(lr[0].split(',')[0].slice(1)); + const currentLineNumber = parseInt(lr[1].split(',')[0].slice(1)); const before = diffLines .filter((line) => line.startsWith('-'))