mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Adds support for ranged quick file history
Fixes ranged diffWithPrevious command execution via CodeLens
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { commands, TextEditor, Uri, window } from 'vscode';
|
import { commands, Range, TextEditor, Uri, window } from 'vscode';
|
||||||
import { ActiveEditorCommand, Commands } from '../commands';
|
import { ActiveEditorCommand, Commands } from '../commands';
|
||||||
import { GitService, GitUri, IGitLog } from '../gitService';
|
import { GitService, GitUri, IGitLog } from '../gitService';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
@@ -12,7 +12,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.ShowQuickFileHistory);
|
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)) {
|
if (!(uri instanceof Uri)) {
|
||||||
uri = editor && editor.document && editor.document.uri;
|
uri = editor && editor.document && editor.document.uri;
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
|
|||||||
const progressCancellation = FileHistoryQuickPick.showProgress(gitUri);
|
const progressCancellation = FileHistoryQuickPick.showProgress(gitUri);
|
||||||
try {
|
try {
|
||||||
if (!log) {
|
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`);
|
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({
|
new CommandQuickPickItem({
|
||||||
label: `go back \u21A9`,
|
label: `go back \u21A9`,
|
||||||
description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(pick.commit.fileName)}`
|
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 },
|
{ showFileHistory: false },
|
||||||
log);
|
log);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ interface ILogEntry {
|
|||||||
summary?: string;
|
summary?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shaRegex = /^[a-f0-9]{40}$/;
|
|
||||||
|
|
||||||
export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
||||||
|
|
||||||
private _parseEntries(data: string, isRepoPath: boolean): ILogEntry[] {
|
private _parseEntries(data: string, isRepoPath: boolean): ILogEntry[] {
|
||||||
@@ -45,7 +43,8 @@ export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
if (!shaRegex.test(lineParts[0])) continue;
|
if (!Git.ShaRegex.test(lineParts[0])) continue;
|
||||||
|
|
||||||
entry = {
|
entry = {
|
||||||
sha: lineParts[0]
|
sha: lineParts[0]
|
||||||
};
|
};
|
||||||
@@ -87,13 +86,28 @@ export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
|||||||
case 'filename':
|
case 'filename':
|
||||||
if (isRepoPath) {
|
if (isRepoPath) {
|
||||||
position++;
|
position++;
|
||||||
|
|
||||||
|
let diff = false;
|
||||||
while (++position < lines.length) {
|
while (++position < lines.length) {
|
||||||
lineParts = lines[position].split(' ');
|
lineParts = lines[position].split(' ');
|
||||||
if (/^[a-f0-9]{40}$/.test(lineParts[0])) {
|
|
||||||
|
if (Git.ShaRegex.test(lineParts[0])) {
|
||||||
position--;
|
position--;
|
||||||
break;
|
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) {
|
if (entry.fileStatuses == null) {
|
||||||
entry.fileStatuses = [];
|
entry.fileStatuses = [];
|
||||||
}
|
}
|
||||||
@@ -118,7 +132,10 @@ export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
|||||||
|
|
||||||
entry.fileStatuses.push(status);
|
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 {
|
else {
|
||||||
position += 2;
|
position += 2;
|
||||||
|
|||||||
@@ -384,7 +384,7 @@ export default class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
lens.command = {
|
lens.command = {
|
||||||
title: title,
|
title: title,
|
||||||
command: CodeLensCommand.ShowQuickFileHistory,
|
command: CodeLensCommand.ShowQuickFileHistory,
|
||||||
arguments: [Uri.file(lens.uri.fsPath)]
|
arguments: [Uri.file(lens.uri.fsPath), lens.isFullRange ? undefined : lens.blameRange]
|
||||||
};
|
};
|
||||||
return lens;
|
return lens;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,13 +81,13 @@ export class CommitFileDetailsQuickPick {
|
|||||||
items.push(new CommandQuickPickItem({
|
items.push(new CommandQuickPickItem({
|
||||||
label: `$(history) Show File History`,
|
label: `$(history) Show File History`,
|
||||||
description: `\u00a0 \u2014 \u00a0\u00a0 of ${path.basename(commit.fileName)}`
|
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({
|
items.push(new CommandQuickPickItem({
|
||||||
label: `$(history) Show ${workingFileName && options.showFileHistory ? 'Previous ' : ''}File History`,
|
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}`
|
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) {
|
if (goBackCommand) {
|
||||||
items.splice(0, 0, goBackCommand);
|
items.splice(0, 0, goBackCommand);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export class FileHistoryQuickPick {
|
|||||||
items.splice(0, 0, new CommandQuickPickItem({
|
items.splice(0, 0, new CommandQuickPickItem({
|
||||||
label: `$(sync) Show All Commits`,
|
label: `$(sync) Show All Commits`,
|
||||||
description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while`
|
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) {
|
if (nextPageCommand) {
|
||||||
index++;
|
index++;
|
||||||
@@ -40,14 +40,14 @@ export class FileHistoryQuickPick {
|
|||||||
const npc = new CommandQuickPickItem({
|
const npc = new CommandQuickPickItem({
|
||||||
label: `$(arrow-right) Show Next Commits`,
|
label: `$(arrow-right) Show Next Commits`,
|
||||||
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} newer 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());
|
const last = Iterables.last(log.commits.values());
|
||||||
|
|
||||||
previousPageCommand = new CommandQuickPickItem({
|
previousPageCommand = new CommandQuickPickItem({
|
||||||
label: `$(arrow-left) Show Previous Commits`,
|
label: `$(arrow-left) Show Previous Commits`,
|
||||||
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older 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++;
|
index++;
|
||||||
items.splice(0, 0, previousPageCommand);
|
items.splice(0, 0, previousPageCommand);
|
||||||
@@ -66,7 +66,7 @@ export class FileHistoryQuickPick {
|
|||||||
new CommandQuickPickItem({
|
new CommandQuickPickItem({
|
||||||
label: `go back \u21A9`,
|
label: `go back \u21A9`,
|
||||||
description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(uri.fsPath)}`
|
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])
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user