mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-18 09:45:36 -05:00
Adds shortcut for gitlens.showQuickFileHistory
Adds shortcut for gitlens.showQuickRepoHistory Adds gitlens.advanced.maxQuickHistory to limit the number of quick history entries to show Adds gitlens.diffLineWithPrevious as alt context menu item for gitlens.diffWithPrevious Adds gitlens.diffLineWithWorking as alt context menu item for gitlens.diffWithWorking Adds gitlens.showFileHistory as alt context menu item for gitlens.showQuickFileHistory Removes context menu for gitlens.diffLineWithPrevious Removes context menu for gitlens.diffLineWithWorking Replaces gitlens.menus.fileDiff.enabled & gitlens.menus.lineDiff.enabled with gitlens.menus.diff.enabled
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
import { Iterables } from '../system';
|
||||
import { commands, QuickPickOptions, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
||||
import { commands, QuickPickItem, QuickPickOptions, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
||||
import { EditorCommand } from './commands';
|
||||
import { Commands } from '../constants';
|
||||
import GitProvider, { GitUri } from '../gitProvider';
|
||||
import { Logger } from '../logger';
|
||||
import { CommitQuickPickItem, CompareQuickPickItem } from './quickPickItems';
|
||||
import { CommitQuickPickItem, CompareQuickPickItem, ShowAllCommitsQuickPickItem } from './quickPickItems';
|
||||
import * as moment from 'moment';
|
||||
|
||||
export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
||||
@@ -13,7 +13,7 @@ export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
||||
super(Commands.ShowQuickFileHistory);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri) {
|
||||
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, maxCount?: number) {
|
||||
if (!(uri instanceof Uri)) {
|
||||
if (!editor.document) return undefined;
|
||||
uri = editor.document.uri;
|
||||
@@ -21,48 +21,62 @@ export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
||||
|
||||
const gitUri = GitUri.fromUri(uri, this.git);
|
||||
|
||||
if (maxCount == null) {
|
||||
maxCount = this.git.config.advanced.maxQuickHistory;
|
||||
}
|
||||
|
||||
try {
|
||||
const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath);
|
||||
const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount);
|
||||
if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`);
|
||||
|
||||
const items = Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c));
|
||||
const commitPick = await window.showQuickPick(Array.from(items), <QuickPickOptions>{
|
||||
const commits = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as QuickPickItem[];
|
||||
let placeHolderSuffix = '';
|
||||
if (maxCount !== 0 && commits.length === this.git.config.advanced.maxQuickHistory) {
|
||||
placeHolderSuffix = ` \u2014 Only showing the first ${this.git.config.advanced.maxQuickHistory} commits`;
|
||||
commits.push(new ShowAllCommitsQuickPickItem(this.git.config.advanced.maxQuickHistory));
|
||||
}
|
||||
|
||||
const pick = await window.showQuickPick(commits, {
|
||||
matchOnDescription: true,
|
||||
matchOnDetail: true,
|
||||
placeHolder: Iterables.first(log.commits.values()).fileName
|
||||
});
|
||||
placeHolder: `${Iterables.first(log.commits.values()).fileName}${placeHolderSuffix}`
|
||||
} as QuickPickOptions);
|
||||
|
||||
if (commitPick) {
|
||||
const commit = commitPick.commit;
|
||||
if (!pick) return undefined;
|
||||
if (pick instanceof ShowAllCommitsQuickPickItem) {
|
||||
return commands.executeCommand(Commands.ShowQuickFileHistory, uri, 0);
|
||||
}
|
||||
|
||||
let command: Commands | undefined = Commands.DiffWithWorking;
|
||||
if (commit.previousSha) {
|
||||
const items: CompareQuickPickItem[] = [
|
||||
{
|
||||
label: `Compare with Working Tree`,
|
||||
description: `\u2022 ${commit.sha} $(git-compare) ${commit.fileName}`,
|
||||
detail: null,
|
||||
command: Commands.DiffWithWorking
|
||||
},
|
||||
{
|
||||
label: `Compare with Previous Commit`,
|
||||
description: `\u2022 ${commit.previousSha} $(git-compare) ${commit.sha}`,
|
||||
detail: null,
|
||||
command: Commands.DiffWithPrevious
|
||||
}
|
||||
];
|
||||
const commitPick = pick as CommitQuickPickItem;
|
||||
const commit = commitPick.commit;
|
||||
|
||||
const comparePick = await window.showQuickPick(items, <QuickPickOptions>{
|
||||
matchOnDescription: true,
|
||||
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()}`
|
||||
});
|
||||
let command: Commands | undefined = Commands.DiffWithWorking;
|
||||
if (commit.previousSha) {
|
||||
const items: CompareQuickPickItem[] = [
|
||||
{
|
||||
label: `Compare with Working Tree`,
|
||||
description: `\u2022 ${commit.sha} $(git-compare) ${commit.fileName}`,
|
||||
detail: null,
|
||||
command: Commands.DiffWithWorking
|
||||
},
|
||||
{
|
||||
label: `Compare with Previous Commit`,
|
||||
description: `\u2022 ${commit.previousSha} $(git-compare) ${commit.sha}`,
|
||||
detail: null,
|
||||
command: Commands.DiffWithPrevious
|
||||
}
|
||||
];
|
||||
|
||||
command = comparePick ? comparePick.command : undefined;
|
||||
}
|
||||
const comparePick = await window.showQuickPick(items, {
|
||||
matchOnDescription: true,
|
||||
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()}`
|
||||
} as QuickPickOptions);
|
||||
|
||||
if (command) {
|
||||
return commands.executeCommand(command, commit.uri, commit);
|
||||
}
|
||||
command = comparePick ? comparePick.command : undefined;
|
||||
}
|
||||
|
||||
if (command) {
|
||||
return commands.executeCommand(command, commit.uri, commit);
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
|
||||
Reference in New Issue
Block a user