Browse Source

Fixes diff header parsing

main
Eric Amodio 1 year ago
parent
commit
e2ff94680c
1 changed files with 5 additions and 5 deletions
  1. +5
    -5
      src/git/parsers/diffParser.ts

+ 5
- 5
src/git/parsers/diffParser.ts View File

@ -6,8 +6,8 @@ const shortStatDiffRegex = /(\d+)\s+files? changed(?:,\s+(\d+)\s+insertions?\(\+
function parseHunkHeaderPart(headerPart: string) {
const [startS, countS] = headerPart.split(',');
const count = Number(countS) || 1;
const start = Number(startS);
const count = Number(countS) || 1;
return { count: count, position: { start: start, end: start + count - 1 } };
}
@ -33,11 +33,11 @@ export function parseGitFileDiff(data: string, includeContents = false): GitDiff
line = lines[i];
if (!line.startsWith('@@')) continue;
const content = line.slice(4, -3);
const [previousHeaderPart, currentHeaderPart] = content.split(' +');
const header = line.split('@@')[1].trim();
const [previousHeaderPart, currentHeaderPart] = header.split(' ');
const current = parseHunkHeaderPart(currentHeaderPart);
const previous = parseHunkHeaderPart(previousHeaderPart);
const current = parseHunkHeaderPart(currentHeaderPart.slice(1));
const previous = parseHunkHeaderPart(previousHeaderPart.slice(1));
const hunkLines = new Map<number, GitDiffHunkLine>();
let fileLineNumber = current.position.start;

Loading…
Cancel
Save