From df7f0597ba0ef12b3e9fb5666555e3147ec14d53 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 29 Apr 2019 03:22:30 -0400 Subject: [PATCH] Fixes missing originalFileName sometimes Reworks file status parsing -- uses consistent regex now --- src/git/parsers/logParser.ts | 18 +----------------- src/git/parsers/stashParser.ts | 31 +++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/git/parsers/logParser.ts b/src/git/parsers/logParser.ts index ccb10f2..4b285f4 100644 --- a/src/git/parsers/logParser.ts +++ b/src/git/parsers/logParser.ts @@ -9,7 +9,7 @@ const emptyStr = ''; const slash = '/'; const diffRegex = /diff --git a\/(.*) b\/(.*)/; -const fileStatusRegex = /(\S)\S*\t([^\t\n]+)(?:\t(.+))?/; +export const fileStatusRegex = /(\S)\S*\t([^\t\n]+)(?:\t(.+))?/; const logFileSimpleRegex = /^ (.*)\s*(?:(?:diff --git a\/(.*) b\/(.*))|(?:(\S)\S*\t([^\t\n]+)(?:\t(.+))?))/gm; // Using %x00 codes because some shells seem to try to expand things if not @@ -378,22 +378,6 @@ export class GitLogParser { return commit; } - static parseFileName(entry: { fileName?: string; originalFileName?: string }) { - if (entry.fileName === undefined) return; - - const index = entry.fileName.indexOf('\t') + 1; - if (index > 0) { - const next = entry.fileName.indexOf('\t', index) + 1; - if (next > 0) { - entry.originalFileName = entry.fileName.substring(index, next - 1); - entry.fileName = entry.fileName.substring(next); - } - else { - entry.fileName = entry.fileName.substring(index); - } - } - } - @debug({ args: false }) static parseSimple( data: string, diff --git a/src/git/parsers/stashParser.ts b/src/git/parsers/stashParser.ts index f431924..5461658 100644 --- a/src/git/parsers/stashParser.ts +++ b/src/git/parsers/stashParser.ts @@ -1,5 +1,5 @@ 'use strict'; -import { GitCommitType, GitFile, GitFileStatus, GitLogParser, GitStash, GitStashCommit } from '../git'; +import { fileStatusRegex, GitCommitType, GitFile, GitFileStatus, GitStash, GitStashCommit } from '../git'; import { Arrays, debug, Strings } from '../../system'; // import { Logger } from './logger'; @@ -54,6 +54,9 @@ export class GitStashParser { let line: string | undefined = undefined; let token: number; + let match; + let renamedFileName; + while (true) { next = lines.next(); if (next.done) break; @@ -118,18 +121,26 @@ export class GitStashParser { if (line.startsWith('warning:')) continue; - const status = { - status: line[0] as GitFileStatus, - fileName: line.substring(1), - originalFileName: undefined - }; - GitLogParser.parseFileName(status); - - if (status.fileName) { + match = fileStatusRegex.exec(line); + if (match != null) { if (entry.files === undefined) { entry.files = []; } - entry.files.push(status); + + renamedFileName = match[3]; + if (renamedFileName !== undefined) { + entry.files.push({ + status: match[1] as GitFileStatus, + fileName: renamedFileName, + originalFileName: match[2] + }); + } + else { + entry.files.push({ + status: match[1] as GitFileStatus, + fileName: match[2] + }); + } } }