Browse Source

Fixes missing originalFileName sometimes

Reworks file status parsing -- uses consistent regex now
main
Eric Amodio 5 years ago
parent
commit
df7f0597ba
2 changed files with 22 additions and 27 deletions
  1. +1
    -17
      src/git/parsers/logParser.ts
  2. +21
    -10
      src/git/parsers/stashParser.ts

+ 1
- 17
src/git/parsers/logParser.ts View File

@ -9,7 +9,7 @@ const emptyStr = '';
const slash = '/'; const slash = '/';
const diffRegex = /diff --git a\/(.*) b\/(.*)/; 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 = /^<r> (.*)\s*(?:(?:diff --git a\/(.*) b\/(.*))|(?:(\S)\S*\t([^\t\n]+)(?:\t(.+))?))/gm; const logFileSimpleRegex = /^<r> (.*)\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 // Using %x00 codes because some shells seem to try to expand things if not
@ -378,22 +378,6 @@ export class GitLogParser {
return commit; 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 }) @debug({ args: false })
static parseSimple( static parseSimple(
data: string, data: string,

+ 21
- 10
src/git/parsers/stashParser.ts View File

@ -1,5 +1,5 @@
'use strict'; '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 { Arrays, debug, Strings } from '../../system';
// import { Logger } from './logger'; // import { Logger } from './logger';
@ -54,6 +54,9 @@ export class GitStashParser {
let line: string | undefined = undefined; let line: string | undefined = undefined;
let token: number; let token: number;
let match;
let renamedFileName;
while (true) { while (true) {
next = lines.next(); next = lines.next();
if (next.done) break; if (next.done) break;
@ -118,18 +121,26 @@ export class GitStashParser {
if (line.startsWith('warning:')) continue; 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) { if (entry.files === undefined) {
entry.files = []; 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]
});
}
} }
} }

Loading…
Cancel
Save