|
@ -1,12 +1,13 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
import { Strings } from '../../system'; |
|
|
|
|
|
import { GitDiff, GitDiffHunk, GitDiffHunkLine, GitDiffLine, GitDiffShortStat, GitFile, GitFileStatus } from '../git'; |
|
|
import { GitDiff, GitDiffHunk, GitDiffHunkLine, GitDiffLine, GitDiffShortStat, GitFile, GitFileStatus } from '../git'; |
|
|
|
|
|
import { debug, Strings } from '../../system'; |
|
|
|
|
|
|
|
|
const nameStatusDiffRegex = /^(.*?)\t(.*?)(?:\t(.*?))?$/gm; |
|
|
const nameStatusDiffRegex = /^(.*?)\t(.*?)(?:\t(.*?))?$/gm; |
|
|
const shortStatDiffRegex = /^\s*(\d+)\sfiles? changed(?:,\s+(\d+)\s+insertions?\(\+\))?(?:,\s+(\d+)\s+deletions?\(-\))?/; |
|
|
const shortStatDiffRegex = /^\s*(\d+)\sfiles? changed(?:,\s+(\d+)\s+insertions?\(\+\))?(?:,\s+(\d+)\s+deletions?\(-\))?/; |
|
|
const unifiedDiffRegex = /^@@ -([\d]+)(?:,([\d]+))? \+([\d]+)(?:,([\d]+))? @@(?:.*?)\n([\s\S]*?)(?=^@@)/gm; |
|
|
const unifiedDiffRegex = /^@@ -([\d]+)(?:,([\d]+))? \+([\d]+)(?:,([\d]+))? @@(?:.*?)\n([\s\S]*?)(?=^@@)/gm; |
|
|
|
|
|
|
|
|
export class GitDiffParser { |
|
|
export class GitDiffParser { |
|
|
|
|
|
@debug({ args: false, singleLine: true }) |
|
|
static parse(data: string, debug: boolean = false): GitDiff | undefined { |
|
|
static parse(data: string, debug: boolean = false): GitDiff | undefined { |
|
|
if (!data) return undefined; |
|
|
if (!data) return undefined; |
|
|
|
|
|
|
|
@ -59,6 +60,7 @@ export class GitDiffParser { |
|
|
return diff; |
|
|
return diff; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@debug({ args: false, singleLine: true }) |
|
|
static parseHunk(hunk: GitDiffHunk): GitDiffHunkLine[] { |
|
|
static parseHunk(hunk: GitDiffHunk): GitDiffHunkLine[] { |
|
|
const currentLines: (GitDiffLine | undefined)[] = []; |
|
|
const currentLines: (GitDiffLine | undefined)[] = []; |
|
|
const previousLines: (GitDiffLine | undefined)[] = []; |
|
|
const previousLines: (GitDiffLine | undefined)[] = []; |
|
@ -122,6 +124,7 @@ export class GitDiffParser { |
|
|
return hunkLines; |
|
|
return hunkLines; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@debug({ args: false, singleLine: true }) |
|
|
static parseNameStatus(data: string, repoPath: string): GitFile[] | undefined { |
|
|
static parseNameStatus(data: string, repoPath: string): GitFile[] | undefined { |
|
|
if (!data) return undefined; |
|
|
if (!data) return undefined; |
|
|
|
|
|
|
|
@ -156,6 +159,7 @@ export class GitDiffParser { |
|
|
return files; |
|
|
return files; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@debug({ args: false, singleLine: true }) |
|
|
static parseShortStat(data: string): GitDiffShortStat | undefined { |
|
|
static parseShortStat(data: string): GitDiffShortStat | undefined { |
|
|
if (!data) return undefined; |
|
|
if (!data) return undefined; |
|
|
|
|
|
|
|
|