diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index 9a39d6a..d5db218 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -1,5 +1,5 @@ 'use strict'; -import { commands, TextEditor, Uri, window } from 'vscode'; +import { commands, Range, TextEditor, Uri, window } from 'vscode'; import { ActiveEditorCommand, Commands } from '../commands'; import { GitService, GitUri, IGitLog } from '../gitService'; import { Logger } from '../logger'; @@ -12,7 +12,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand { super(Commands.ShowQuickFileHistory); } - async execute(editor: TextEditor, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem, log?: IGitLog, nextPageCommand?: CommandQuickPickItem) { + async execute(editor: TextEditor, uri?: Uri, range?: Range, maxCount?: number, goBackCommand?: CommandQuickPickItem, log?: IGitLog, nextPageCommand?: CommandQuickPickItem) { if (!(uri instanceof Uri)) { uri = editor && editor.document && editor.document.uri; } @@ -28,7 +28,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand { const progressCancellation = FileHistoryQuickPick.showProgress(gitUri); try { if (!log) { - log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount); + log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, range, maxCount); if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`); } @@ -45,7 +45,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand { new CommandQuickPickItem({ label: `go back \u21A9`, description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(pick.commit.fileName)}` - }, Commands.ShowQuickFileHistory, [uri, maxCount, goBackCommand, log]), + }, Commands.ShowQuickFileHistory, [uri, undefined, maxCount, goBackCommand, log]), { showFileHistory: false }, log); } diff --git a/src/git/enrichers/logParserEnricher.ts b/src/git/enrichers/logParserEnricher.ts index e3f8722..9224187 100644 --- a/src/git/enrichers/logParserEnricher.ts +++ b/src/git/enrichers/logParserEnricher.ts @@ -24,8 +24,6 @@ interface ILogEntry { summary?: string; } -const shaRegex = /^[a-f0-9]{40}$/; - export class GitLogParserEnricher implements IGitEnricher { private _parseEntries(data: string, isRepoPath: boolean): ILogEntry[] { @@ -45,7 +43,8 @@ export class GitLogParserEnricher implements IGitEnricher { } if (!entry) { - if (!shaRegex.test(lineParts[0])) continue; + if (!Git.ShaRegex.test(lineParts[0])) continue; + entry = { sha: lineParts[0] }; @@ -87,13 +86,28 @@ export class GitLogParserEnricher implements IGitEnricher { case 'filename': if (isRepoPath) { position++; + + let diff = false; while (++position < lines.length) { lineParts = lines[position].split(' '); - if (/^[a-f0-9]{40}$/.test(lineParts[0])) { + + if (Git.ShaRegex.test(lineParts[0])) { position--; break; } + if (diff) continue; + + if (lineParts[0] === 'diff') { + diff = true; + entry.fileName = lineParts[2].substring(2); + const originalFileName = lineParts[3].substring(2); + if (entry.fileName !== originalFileName) { + entry.originalFileName = originalFileName; + } + continue; + } + if (entry.fileStatuses == null) { entry.fileStatuses = []; } @@ -118,7 +132,10 @@ export class GitLogParserEnricher implements IGitEnricher { entry.fileStatuses.push(status); } - entry.fileName = entry.fileStatuses.filter(_ => !!_.fileName).map(_ => _.fileName).join(', '); + + if (entry.fileStatuses) { + entry.fileName = entry.fileStatuses.filter(_ => !!_.fileName).map(_ => _.fileName).join(', '); + } } else { position += 2; diff --git a/src/gitCodeLensProvider.ts b/src/gitCodeLensProvider.ts index be294f5..03502f6 100644 --- a/src/gitCodeLensProvider.ts +++ b/src/gitCodeLensProvider.ts @@ -384,7 +384,7 @@ export default class GitCodeLensProvider implements CodeLensProvider { lens.command = { title: title, command: CodeLensCommand.ShowQuickFileHistory, - arguments: [Uri.file(lens.uri.fsPath)] + arguments: [Uri.file(lens.uri.fsPath), lens.isFullRange ? undefined : lens.blameRange] }; return lens; } diff --git a/src/quickPicks/commitFileDetails.ts b/src/quickPicks/commitFileDetails.ts index 54d2d06..0904776 100644 --- a/src/quickPicks/commitFileDetails.ts +++ b/src/quickPicks/commitFileDetails.ts @@ -81,13 +81,13 @@ export class CommitFileDetailsQuickPick { items.push(new CommandQuickPickItem({ label: `$(history) Show File History`, description: `\u00a0 \u2014 \u00a0\u00a0 of ${path.basename(commit.fileName)}` - }, Commands.ShowQuickFileHistory, [commit.uri, undefined, currentCommand, fileLog])); + }, Commands.ShowQuickFileHistory, [commit.uri, undefined, undefined, currentCommand, fileLog])); } items.push(new CommandQuickPickItem({ label: `$(history) Show ${workingFileName && options.showFileHistory ? 'Previous ' : ''}File History`, description: `\u00a0 \u2014 \u00a0\u00a0 of ${path.basename(commit.fileName)} \u00a0\u2022\u00a0 starting from \u00a0$(git-commit) ${commit.shortSha}` - }, Commands.ShowQuickFileHistory, [new GitUri(commit.uri, commit), undefined, currentCommand])); + }, Commands.ShowQuickFileHistory, [new GitUri(commit.uri, commit), undefined, undefined, currentCommand])); if (goBackCommand) { items.splice(0, 0, goBackCommand); diff --git a/src/quickPicks/fileHistory.ts b/src/quickPicks/fileHistory.ts index 956a3b4..599edcf 100644 --- a/src/quickPicks/fileHistory.ts +++ b/src/quickPicks/fileHistory.ts @@ -29,7 +29,7 @@ export class FileHistoryQuickPick { items.splice(0, 0, new CommandQuickPickItem({ label: `$(sync) Show All Commits`, description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while` - }, Commands.ShowQuickFileHistory, [Uri.file(uri.fsPath), 0, goBackCommand])); + }, Commands.ShowQuickFileHistory, [Uri.file(uri.fsPath), undefined, 0, goBackCommand])); if (nextPageCommand) { index++; @@ -40,14 +40,14 @@ export class FileHistoryQuickPick { const npc = new CommandQuickPickItem({ label: `$(arrow-right) Show Next Commits`, description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} newer commits` - }, Commands.ShowQuickFileHistory, [uri, log.maxCount, goBackCommand, undefined, nextPageCommand]); + }, Commands.ShowQuickFileHistory, [uri, undefined, log.maxCount, goBackCommand, undefined, nextPageCommand]); const last = Iterables.last(log.commits.values()); previousPageCommand = new CommandQuickPickItem({ label: `$(arrow-left) Show Previous Commits`, description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits` - }, Commands.ShowQuickFileHistory, [new GitUri(uri, last), log.maxCount, goBackCommand, undefined, npc]); + }, Commands.ShowQuickFileHistory, [new GitUri(uri, last), undefined, log.maxCount, goBackCommand, undefined, npc]); index++; items.splice(0, 0, previousPageCommand); @@ -66,7 +66,7 @@ export class FileHistoryQuickPick { new CommandQuickPickItem({ label: `go back \u21A9`, description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(uri.fsPath)}` - }, Commands.ShowQuickFileHistory, [uri, log.maxCount, undefined, log]) + }, Commands.ShowQuickFileHistory, [uri, undefined, log.maxCount, undefined, log]) ])); }