From 5e19cc6adfd3add22a7845b200c5f22126179e8d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 1 Mar 2017 01:27:12 -0500 Subject: [PATCH] Fixes filename parsing with git-log Adds originalFilename support to git-log enrichment --- src/git/enrichers/logParserEnricher.ts | 43 ++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/git/enrichers/logParserEnricher.ts b/src/git/enrichers/logParserEnricher.ts index 31b1cae..9fb72c3 100644 --- a/src/git/enrichers/logParserEnricher.ts +++ b/src/git/enrichers/logParserEnricher.ts @@ -13,7 +13,8 @@ interface ILogEntry { committerDate?: string; fileName?: string; - fileStatuses?: { status: GitFileStatus, fileName: string }[]; + originalFileName?: string; + fileStatuses?: { status: GitFileStatus, fileName: string, originalFileName: string }[]; status?: GitFileStatus; @@ -87,10 +88,26 @@ export class GitLogParserEnricher implements IGitEnricher { if (entry.fileStatuses == null) { entry.fileStatuses = []; } - entry.fileStatuses.push({ + + const status = { status: lineParts[0][0] as GitFileStatus, - fileName: lineParts[0].substring(2) - }); + fileName: lineParts[0].substring(1), + originalFileName: undefined as string + }; + + const index = status.fileName.indexOf('\t') + 1; + if (index) { + const next = status.fileName.indexOf('\t', index) + 1; + if (next) { + status.originalFileName = status.fileName.substring(index, next - 1); + status.fileName = status.fileName.substring(next); + } + else { + status.fileName = status.fileName.substring(index); + } + } + + entry.fileStatuses.push(status); } entry.fileName = entry.fileStatuses.filter(_ => !!_.fileName).map(_ => _.fileName).join(', '); } @@ -99,13 +116,25 @@ export class GitLogParserEnricher implements IGitEnricher { lineParts = lines[position].split(' '); if (lineParts.length === 1) { entry.status = lineParts[0][0] as GitFileStatus; - entry.fileName = lineParts[0].substring(2); + entry.fileName = lineParts[0].substring(1); } else { entry.status = lineParts[3][0] as GitFileStatus; - entry.fileName = lineParts[3].substring(2); + entry.fileName = lineParts[0].substring(1); position += 4; } + + const index = entry.fileName.indexOf('\t') + 1; + if (index) { + const next = entry.fileName.indexOf('\t', index) + 1; + if (next) { + entry.originalFileName = entry.fileName.substring(index, next - 1); + entry.fileName = entry.fileName.substring(next); + } + else { + entry.fileName = entry.fileName.substring(index); + } + } } entries.push(entry); @@ -160,7 +189,7 @@ export class GitLogParserEnricher implements IGitEnricher { authors.set(entry.author, author); } - commit = new GitLogCommit(repoPath, entry.sha, relativeFileName, entry.author, moment(entry.authorDate).toDate(), entry.summary, entry.status, entry.fileStatuses); + commit = new GitLogCommit(repoPath, entry.sha, relativeFileName, entry.author, moment(entry.authorDate).toDate(), entry.summary, entry.status, entry.fileStatuses, undefined, entry.originalFileName); if (relativeFileName !== entry.fileName) { commit.originalFileName = entry.fileName;