Преглед изворни кода

Fixes missing originalFileName sometimes

Reworks file status parsing -- uses consistent regex now
main
Eric Amodio пре 5 година
родитељ
комит
df7f0597ba
2 измењених фајлова са 22 додато и 27 уклоњено
  1. +1
    -17
      src/git/parsers/logParser.ts
  2. +21
    -10
      src/git/parsers/stashParser.ts

+ 1
- 17
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 = /^<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
@ -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,

+ 21
- 10
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]
});
}
}
}

Loading…
Откажи
Сачувај