From 9867e7065dd62fb5fe4194436450e6bda02099e4 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 22 Mar 2017 03:09:13 -0400 Subject: [PATCH] Adds Show Branch History command Renames Show Repository History to Show Current Branch History Doesn't migrate data yet --- package.json | 11 ++- src/commands.ts | 3 +- src/commands/commands.ts | 5 +- src/commands/showQuickBranchHistory.ts | 75 +++++++++++++++++++ src/commands/showQuickCommitDetails.ts | 2 +- src/commands/showQuickCurrentBranchHistory.ts | 29 ++++++++ src/commands/showQuickFileHistory.ts | 2 +- src/commands/showQuickRepoHistory.ts | 63 ---------------- src/configuration.ts | 4 +- src/extension.ts | 5 +- src/gitCodeLensProvider.ts | 8 +- src/quickPicks.ts | 16 ++-- src/quickPicks/branchHistory.ts | 101 ++++++++++++++++++++++++++ src/quickPicks/fileHistory.ts | 4 +- src/quickPicks/repoHistory.ts | 101 -------------------------- src/quickPicks/repoStatus.ts | 4 +- 16 files changed, 242 insertions(+), 191 deletions(-) create mode 100644 src/commands/showQuickBranchHistory.ts create mode 100644 src/commands/showQuickCurrentBranchHistory.ts delete mode 100644 src/commands/showQuickRepoHistory.ts create mode 100644 src/quickPicks/branchHistory.ts delete mode 100644 src/quickPicks/repoHistory.ts diff --git a/package.json b/package.json index d393bff..3c13946 100644 --- a/package.json +++ b/package.json @@ -439,8 +439,13 @@ "category": "GitLens" }, { + "command": "gitlens.showQuickBranchHistory", + "title": "Show Branch History", + "category": "GitLens" + }, + { "command": "gitlens.showQuickRepoHistory", - "title": "Show Repository History", + "title": "Show Current Branch History", "category": "GitLens" }, { @@ -536,6 +541,10 @@ "when": "gitlens:enabled" }, { + "command": "gitlens.showQuickBranchHistory", + "when": "gitlens:enabled" + }, + { "command": "gitlens.showQuickRepoHistory", "when": "gitlens:enabled" }, diff --git a/src/commands.ts b/src/commands.ts index 0b79f92..d9fcc39 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -23,7 +23,8 @@ export * from './commands/showLastQuickPick'; export * from './commands/showQuickCommitDetails'; export * from './commands/showQuickCommitFileDetails'; export * from './commands/showQuickFileHistory'; -export * from './commands/showQuickRepoHistory'; +export * from './commands/showQuickBranchHistory'; +export * from './commands/showQuickCurrentBranchHistory'; export * from './commands/showQuickRepoStatus'; export * from './commands/toggleBlame'; export * from './commands/toggleCodeLens'; diff --git a/src/commands/commands.ts b/src/commands/commands.ts index 3ff6124..52b4995 100644 --- a/src/commands/commands.ts +++ b/src/commands/commands.ts @@ -2,7 +2,7 @@ import { commands, Disposable, TextEditor, TextEditorEdit, Uri, window, workspace } from 'vscode'; import { BuiltInCommands } from '../constants'; -export type Commands = 'gitlens.closeUnchangedFiles' | 'gitlens.copyMessageToClipboard' | 'gitlens.copyShaToClipboard' | 'gitlens.diffDirectory' | 'gitlens.diffWithBranch' | 'gitlens.diffWithNext' | 'gitlens.diffWithPrevious' | 'gitlens.diffLineWithPrevious' | 'gitlens.diffWithWorking' | 'gitlens.diffLineWithWorking' | 'gitlens.openChangedFiles' | 'gitlens.showBlame' | 'gitlens.showBlameHistory' | 'gitlens.showFileHistory' | 'gitlens.showLastQuickPick' | 'gitlens.showQuickCommitDetails' | 'gitlens.showQuickCommitFileDetails' | 'gitlens.showQuickFileHistory' | 'gitlens.showQuickRepoHistory' | 'gitlens.showQuickRepoStatus' | 'gitlens.toggleBlame' | 'gitlens.toggleCodeLens'; +export type Commands = 'gitlens.closeUnchangedFiles' | 'gitlens.copyMessageToClipboard' | 'gitlens.copyShaToClipboard' | 'gitlens.diffDirectory' | 'gitlens.diffWithBranch' | 'gitlens.diffWithNext' | 'gitlens.diffWithPrevious' | 'gitlens.diffLineWithPrevious' | 'gitlens.diffWithWorking' | 'gitlens.diffLineWithWorking' | 'gitlens.openChangedFiles' | 'gitlens.showBlame' | 'gitlens.showBlameHistory' | 'gitlens.showFileHistory' | 'gitlens.showLastQuickPick' | 'gitlens.showQuickBranchHistory' | 'gitlens.showQuickCommitDetails' | 'gitlens.showQuickCommitFileDetails' | 'gitlens.showQuickFileHistory' | 'gitlens.showQuickRepoHistory' | 'gitlens.showQuickRepoStatus' | 'gitlens.toggleBlame' | 'gitlens.toggleCodeLens'; export const Commands = { CloseUnchangedFiles: 'gitlens.closeUnchangedFiles' as Commands, CopyMessageToClipboard: 'gitlens.copyMessageToClipboard' as Commands, @@ -22,7 +22,8 @@ export const Commands = { ShowQuickCommitDetails: 'gitlens.showQuickCommitDetails' as Commands, ShowQuickCommitFileDetails: 'gitlens.showQuickCommitFileDetails' as Commands, ShowQuickFileHistory: 'gitlens.showQuickFileHistory' as Commands, - ShowQuickRepoHistory: 'gitlens.showQuickRepoHistory' as Commands, + ShowQuickBranchHistory: 'gitlens.showQuickBranchHistory' as Commands, + ShowQuickCurrentBranchHistory: 'gitlens.showQuickRepoHistory' as Commands, ShowQuickRepoStatus: 'gitlens.showQuickRepoStatus' as Commands, ToggleBlame: 'gitlens.toggleBlame' as Commands, ToggleCodeLens: 'gitlens.toggleCodeLens' as Commands diff --git a/src/commands/showQuickBranchHistory.ts b/src/commands/showQuickBranchHistory.ts new file mode 100644 index 0000000..808bf3b --- /dev/null +++ b/src/commands/showQuickBranchHistory.ts @@ -0,0 +1,75 @@ +'use strict'; +import { commands, TextEditor, Uri, window } from 'vscode'; +import { ActiveEditorCachedCommand, Commands } from '../commands'; +import { GitService, GitUri, IGitLog } from '../gitService'; +import { Logger } from '../logger'; +import { BranchesQuickPick, BranchHistoryQuickPick, CommandQuickPickItem } from '../quickPicks'; + +export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand { + + constructor(private git: GitService, private repoPath: string) { + super(Commands.ShowQuickBranchHistory); + } + + async execute(editor: TextEditor, uri?: Uri, branch?: string, maxCount?: number, goBackCommand?: CommandQuickPickItem, log?: IGitLog, nextPageCommand?: CommandQuickPickItem) { + if (!(uri instanceof Uri)) { + uri = editor && editor.document && editor.document.uri; + } + + const gitUri = uri && await GitUri.fromUri(uri, this.git); + + if (maxCount == null) { + maxCount = this.git.config.advanced.maxQuickHistory; + } + + let progressCancellation = branch && BranchHistoryQuickPick.showProgress(branch); + try { + const repoPath = (gitUri && gitUri.repoPath) || await this.git.getRepoPathFromUri(uri, this.repoPath); + if (!repoPath) return window.showWarningMessage(`Unable to show branch history`); + + if (!branch) { + const branches = await this.git.getBranches(repoPath); + + const pick = await BranchesQuickPick.show(branches, `pick a branch to show history`); + if (!pick) return undefined; + + if (pick instanceof CommandQuickPickItem) { + return pick.execute(); + } + + branch = pick.branch.name; + if (!branch) return undefined; + + progressCancellation = BranchHistoryQuickPick.showProgress(branch); + } + + if (!log) { + log = await this.git.getLogForRepo(repoPath, (gitUri && gitUri.sha) || branch, maxCount); + if (!log) return window.showWarningMessage(`Unable to show branch history`); + } + + if (progressCancellation.token.isCancellationRequested) return undefined; + + const pick = await BranchHistoryQuickPick.show(log, gitUri, branch, progressCancellation, goBackCommand, nextPageCommand); + if (!pick) return undefined; + + if (pick instanceof CommandQuickPickItem) { + return pick.execute(); + } + + return commands.executeCommand(Commands.ShowQuickCommitDetails, new GitUri(pick.commit.uri, pick.commit), pick.commit.sha, pick.commit, + new CommandQuickPickItem({ + label: `go back \u21A9`, + description: `\u00a0 \u2014 \u00a0\u00a0 to \u00a0$(git-branch) ${branch} history` + }, Commands.ShowQuickBranchHistory, [uri, branch, maxCount, goBackCommand, log]), + log); + } + catch (ex) { + Logger.error('[GitLens.ShowQuickBranchHistoryCommand]', ex); + return window.showErrorMessage(`Unable to show branch history. See output channel for more details`); + } + finally { + progressCancellation && progressCancellation.dispose(); + } + } +} \ No newline at end of file diff --git a/src/commands/showQuickCommitDetails.ts b/src/commands/showQuickCommitDetails.ts index 7de35e1..7f7e729 100644 --- a/src/commands/showQuickCommitDetails.ts +++ b/src/commands/showQuickCommitDetails.ts @@ -72,7 +72,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand { goBackCommand = new CommandQuickPickItem({ label: `go back \u21A9`, description: `\u00a0 \u2014 \u00a0\u00a0 to branch history` - }, Commands.ShowQuickRepoHistory, [new GitUri(commit.uri, commit)]); + }, Commands.ShowQuickCurrentBranchHistory, [new GitUri(commit.uri, commit)]); } const pick = await CommitDetailsQuickPick.show(this.git, commit as GitLogCommit, uri, goBackCommand, repoLog); diff --git a/src/commands/showQuickCurrentBranchHistory.ts b/src/commands/showQuickCurrentBranchHistory.ts new file mode 100644 index 0000000..61d9fa5 --- /dev/null +++ b/src/commands/showQuickCurrentBranchHistory.ts @@ -0,0 +1,29 @@ +'use strict'; +import { commands, TextEditor, Uri, window } from 'vscode'; +import { ActiveEditorCachedCommand, Commands } from '../commands'; +import { GitService } from '../gitService'; +import { Logger } from '../logger'; +import { CommandQuickPickItem } from '../quickPicks'; + +export class ShowQuickCurrentBranchHistoryCommand extends ActiveEditorCachedCommand { + + constructor(private git: GitService) { + super(Commands.ShowQuickCurrentBranchHistory); + } + + async execute(editor: TextEditor, uri?: Uri, goBackCommand?: CommandQuickPickItem) { + if (!(uri instanceof Uri)) { + uri = editor && editor.document && editor.document.uri; + } + + try { + const branch = (await this.git.getBranch(this.git.repoPath)).name; + + return commands.executeCommand(Commands.ShowQuickBranchHistory, uri, branch, undefined, goBackCommand); + } + catch (ex) { + Logger.error('[GitLens.ShowQuickCurrentBranchHistoryCommand]', ex); + return window.showErrorMessage(`Unable to show branch history. See output channel for more details`); + } + } +} \ No newline at end of file diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index 2eed1a6..03cfb69 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -17,7 +17,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { uri = editor && editor.document && editor.document.uri; } - if (!uri) return commands.executeCommand(Commands.ShowQuickRepoHistory); + if (!uri) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory); const gitUri = await GitUri.fromUri(uri, this.git); diff --git a/src/commands/showQuickRepoHistory.ts b/src/commands/showQuickRepoHistory.ts deleted file mode 100644 index 1c1b8fb..0000000 --- a/src/commands/showQuickRepoHistory.ts +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; -import { commands, TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCachedCommand, Commands } from '../commands'; -import { GitService, GitUri, IGitLog } from '../gitService'; -import { Logger } from '../logger'; -import { CommandQuickPickItem, RepoHistoryQuickPick } from '../quickPicks'; - -export class ShowQuickRepoHistoryCommand extends ActiveEditorCachedCommand { - - constructor(private git: GitService, private repoPath: string) { - super(Commands.ShowQuickRepoHistory); - } - - async execute(editor: TextEditor, uri?: Uri, branch?: string, maxCount?: number, goBackCommand?: CommandQuickPickItem, log?: IGitLog, nextPageCommand?: CommandQuickPickItem) { - if (!(uri instanceof Uri)) { - uri = editor && editor.document && editor.document.uri; - } - - const gitUri = uri && await GitUri.fromUri(uri, this.git); - - if (maxCount == null) { - maxCount = this.git.config.advanced.maxQuickHistory; - } - - branch = branch || (await this.git.getBranch(this.git.repoPath)).name; - - const progressCancellation = RepoHistoryQuickPick.showProgress(branch); - try { - const repoPath = (gitUri && gitUri.repoPath) || await this.git.getRepoPathFromUri(uri, this.repoPath); - if (!repoPath) return window.showWarningMessage(`Unable to show history`); - - if (progressCancellation.token.isCancellationRequested) return undefined; - - if (!log) { - log = await this.git.getLogForRepo(repoPath, (gitUri && gitUri.sha) || branch, maxCount); - if (!log) return window.showWarningMessage(`Unable to show history`); - } - - if (progressCancellation.token.isCancellationRequested) return undefined; - - const pick = await RepoHistoryQuickPick.show(log, gitUri, branch, progressCancellation, goBackCommand, nextPageCommand); - if (!pick) return undefined; - - if (pick instanceof CommandQuickPickItem) { - return pick.execute(); - } - - return commands.executeCommand(Commands.ShowQuickCommitDetails, new GitUri(pick.commit.uri, pick.commit), pick.commit.sha, pick.commit, - new CommandQuickPickItem({ - label: `go back \u21A9`, - description: `\u00a0 \u2014 \u00a0\u00a0 to \u00a0$(git-branch) ${branch} history` - }, Commands.ShowQuickRepoHistory, [uri, branch, maxCount, goBackCommand, log]), - log); - } - catch (ex) { - Logger.error('[GitLens.ShowQuickRepoHistoryCommand]', ex); - return window.showErrorMessage(`Unable to show history. See output channel for more details`); - } - finally { - progressCancellation.dispose(); - } - } -} \ No newline at end of file diff --git a/src/configuration.ts b/src/configuration.ts index 27d5648..4828e52 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -37,7 +37,7 @@ export const CodeLensCommand = { ShowQuickCommitDetails: Commands.ShowQuickCommitDetails as CodeLensCommand, ShowQuickCommitFileDetails: Commands.ShowQuickCommitFileDetails as CodeLensCommand, ShowQuickFileHistory: Commands.ShowQuickFileHistory as CodeLensCommand, - ShowQuickRepoHistory: Commands.ShowQuickRepoHistory as CodeLensCommand + ShowQuickCurrentBranchHistory: Commands.ShowQuickCurrentBranchHistory as CodeLensCommand }; export type CodeLensLocation = 'all' | 'document+containers' | 'document' | 'custom' | 'none'; @@ -86,7 +86,7 @@ export const StatusBarCommand = { ShowQuickCommitDetails: Commands.ShowQuickCommitDetails as StatusBarCommand, ShowQuickCommitFileDetails: Commands.ShowQuickCommitFileDetails as StatusBarCommand, ShowQuickFileHistory: Commands.ShowQuickFileHistory as StatusBarCommand, - ShowQuickRepoHistory: Commands.ShowQuickRepoHistory as StatusBarCommand + ShowQuickCurrentBranchHistory: Commands.ShowQuickCurrentBranchHistory as StatusBarCommand }; export interface IStatusBarConfig { diff --git a/src/extension.ts b/src/extension.ts index 5cb011b..cf69997 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,7 +10,7 @@ import { CopyMessageToClipboardCommand, CopyShaToClipboardCommand } from './comm import { DiffDirectoryCommand, DiffLineWithPreviousCommand, DiffLineWithWorkingCommand, DiffWithBranchCommand, DiffWithNextCommand, DiffWithPreviousCommand, DiffWithWorkingCommand} from './commands'; import { ShowBlameCommand, ToggleBlameCommand } from './commands'; import { ShowBlameHistoryCommand, ShowFileHistoryCommand } from './commands'; -import { ShowLastQuickPickCommand, ShowQuickCommitDetailsCommand, ShowQuickCommitFileDetailsCommand, ShowQuickFileHistoryCommand, ShowQuickRepoHistoryCommand, ShowQuickRepoStatusCommand} from './commands'; +import { ShowLastQuickPickCommand, ShowQuickBranchHistoryCommand, ShowQuickCurrentBranchHistoryCommand, ShowQuickCommitDetailsCommand, ShowQuickCommitFileDetailsCommand, ShowQuickFileHistoryCommand, ShowQuickRepoStatusCommand} from './commands'; import { ToggleCodeLensCommand } from './commands'; import { Keyboard } from './commands'; import { IAdvancedConfig, IBlameConfig } from './configuration'; @@ -104,10 +104,11 @@ export async function activate(context: ExtensionContext) { context.subscriptions.push(new ShowBlameHistoryCommand(git)); context.subscriptions.push(new ShowFileHistoryCommand(git)); context.subscriptions.push(new ShowLastQuickPickCommand()); + context.subscriptions.push(new ShowQuickBranchHistoryCommand(git, repoPath)); + context.subscriptions.push(new ShowQuickCurrentBranchHistoryCommand(git)); context.subscriptions.push(new ShowQuickCommitDetailsCommand(git, repoPath)); context.subscriptions.push(new ShowQuickCommitFileDetailsCommand(git)); context.subscriptions.push(new ShowQuickFileHistoryCommand(git)); - context.subscriptions.push(new ShowQuickRepoHistoryCommand(git, repoPath)); context.subscriptions.push(new ShowQuickRepoStatusCommand(git, repoPath)); context.subscriptions.push(new ToggleCodeLensCommand(git)); } diff --git a/src/gitCodeLensProvider.ts b/src/gitCodeLensProvider.ts index 8d53d46..1e8bfe5 100644 --- a/src/gitCodeLensProvider.ts +++ b/src/gitCodeLensProvider.ts @@ -273,7 +273,7 @@ export default class GitCodeLensProvider implements CodeLensProvider { case CodeLensCommand.ShowQuickCommitDetails: return this._applyShowQuickCommitDetailsCommand(title, lens, blame, recentCommit); case CodeLensCommand.ShowQuickCommitFileDetails: return this._applyShowQuickCommitFileDetailsCommand(title, lens, blame, recentCommit); case CodeLensCommand.ShowQuickFileHistory: return this._applyShowQuickFileHistoryCommand(title, lens, blame, recentCommit); - case CodeLensCommand.ShowQuickRepoHistory: return this._applyShowQuickRepoHistoryCommand(title, lens, blame, recentCommit); + case CodeLensCommand.ShowQuickCurrentBranchHistory: return this._applyShowQuickBranchHistoryCommand(title, lens, blame, recentCommit); default: return lens; } } @@ -294,7 +294,7 @@ export default class GitCodeLensProvider implements CodeLensProvider { case CodeLensCommand.ShowQuickCommitDetails: return this._applyShowQuickCommitDetailsCommand(title, lens, blame); case CodeLensCommand.ShowQuickCommitFileDetails: return this._applyShowQuickCommitFileDetailsCommand(title, lens, blame); case CodeLensCommand.ShowQuickFileHistory: return this._applyShowQuickFileHistoryCommand(title, lens, blame); - case CodeLensCommand.ShowQuickRepoHistory: return this._applyShowQuickRepoHistoryCommand(title, lens, blame); + case CodeLensCommand.ShowQuickCurrentBranchHistory: return this._applyShowQuickBranchHistoryCommand(title, lens, blame); default: return lens; } } @@ -389,10 +389,10 @@ export default class GitCodeLensProvider implements CodeLensProvider { return lens; } - _applyShowQuickRepoHistoryCommand(title: string, lens: T, blame: IGitBlameLines, commit?: GitCommit): T { + _applyShowQuickBranchHistoryCommand(title: string, lens: T, blame: IGitBlameLines, commit?: GitCommit): T { lens.command = { title: title, - command: CodeLensCommand.ShowQuickRepoHistory, + command: CodeLensCommand.ShowQuickCurrentBranchHistory, arguments: [Uri.file(lens.uri.fsPath)] }; return lens; diff --git a/src/quickPicks.ts b/src/quickPicks.ts index 4fe00e7..e39b2f5 100644 --- a/src/quickPicks.ts +++ b/src/quickPicks.ts @@ -1,9 +1,9 @@ 'use strict'; -export { BranchQuickPickItem, BranchesQuickPick } from './quickPicks/branches'; -export { CommandQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem, showQuickPickProgress } from './quickPicks/quickPicks'; -export { CommitQuickPickItem, CommitWithFileStatusQuickPickItem } from './quickPicks/gitQuickPicks'; -export { OpenCommitFilesCommandQuickPickItem, OpenCommitWorkingTreeFilesCommandQuickPickItem, CommitDetailsQuickPick } from './quickPicks/commitDetails'; -export { OpenCommitFileCommandQuickPickItem, OpenCommitWorkingTreeFileCommandQuickPickItem, CommitFileDetailsQuickPick } from './quickPicks/commitFileDetails'; -export { FileHistoryQuickPick } from './quickPicks/fileHistory'; -export { RepoHistoryQuickPick } from './quickPicks/repoHistory'; -export { OpenStatusFileCommandQuickPickItem, OpenStatusFilesCommandQuickPickItem, RepoStatusQuickPick } from './quickPicks/repoStatus'; \ No newline at end of file +export * from './quickPicks/branches'; +export * from './quickPicks/quickPicks'; +export * from './quickPicks/gitQuickPicks'; +export * from './quickPicks/commitDetails'; +export * from './quickPicks/commitFileDetails'; +export * from './quickPicks/branchHistory'; +export * from './quickPicks/fileHistory'; +export * from './quickPicks/repoStatus'; \ No newline at end of file diff --git a/src/quickPicks/branchHistory.ts b/src/quickPicks/branchHistory.ts new file mode 100644 index 0000000..19b8fb3 --- /dev/null +++ b/src/quickPicks/branchHistory.ts @@ -0,0 +1,101 @@ +'use strict'; +import { Iterables } from '../system'; +import { CancellationTokenSource, QuickPickOptions, Uri, window } from 'vscode'; +import { Commands, Keyboard, KeyNoopCommand } from '../commands'; +import { GitUri, IGitLog } from '../gitService'; +import { CommitQuickPickItem } from './gitQuickPicks'; +import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, showQuickPickProgress } from './quickPicks'; + +export class BranchHistoryQuickPick { + + static showProgress(branch: string) { + return showQuickPickProgress(`${branch} history \u2014 search by commit message, filename, or sha`, + { + left: KeyNoopCommand, + ',': KeyNoopCommand, + '.': KeyNoopCommand + }); + } + + static async show(log: IGitLog, uri: GitUri, branch: string, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem): Promise { + const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileNames}`))) as (CommitQuickPickItem | CommandQuickPickItem)[]; + + let previousPageCommand: CommandQuickPickItem; + + if ((log.truncated || (uri && uri.sha))) { + if (log.truncated) { + items.splice(0, 0, new CommandQuickPickItem({ + label: `$(sync) Show All Commits`, + description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while` + }, Commands.ShowQuickBranchHistory, [ + new GitUri(Uri.file(log.repoPath), { fileName: '', repoPath: log.repoPath }), + branch, + 0, + goBackCommand + ])); + } + else { + items.splice(0, 0, new CommandQuickPickItem({ + label: `$(history) Show Branch History`, + description: `\u00a0 \u2014 \u00a0\u00a0 shows \u00a0$(git-branch) ${branch} history` + }, Commands.ShowQuickBranchHistory, [ + new GitUri(Uri.file(log.repoPath), { fileName: '', repoPath: log.repoPath }), + branch, + undefined, + new CommandQuickPickItem({ + label: `go back \u21A9`, + description: `\u00a0 \u2014 \u00a0\u00a0 to \u00a0$(git-branch) ${branch} history` + }, Commands.ShowQuickBranchHistory, [uri, branch, log.maxCount, goBackCommand, log]) + ])); + } + + if (nextPageCommand) { + items.splice(0, 0, nextPageCommand); + } + + if (log.truncated) { + const npc = new CommandQuickPickItem({ + label: `$(arrow-right) Show Next Commits`, + description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} newer commits` + }, Commands.ShowQuickBranchHistory, [uri, branch, 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.ShowQuickBranchHistory, [new GitUri(uri ? uri : last.uri, last), branch, log.maxCount, goBackCommand, undefined, npc]); + + items.splice(0, 0, previousPageCommand); + } + } + + if (goBackCommand) { + items.splice(0, 0, goBackCommand); + } + + if (progressCancellation.token.isCancellationRequested) return undefined; + + const scope = await Keyboard.instance.beginScope({ + left: goBackCommand, + ',': previousPageCommand, + '.': nextPageCommand + }); + + progressCancellation.cancel(); + + const pick = await window.showQuickPick(items, { + matchOnDescription: true, + matchOnDetail: true, + placeHolder: `${branch} history \u2014 search by commit message, filename, or sha`, + ignoreFocusOut: getQuickPickIgnoreFocusOut() + // onDidSelectItem: (item: QuickPickItem) => { + // scope.setKeyCommand('right', item); + // } + } as QuickPickOptions); + + await scope.dispose(); + + return pick; + } +} \ No newline at end of file diff --git a/src/quickPicks/fileHistory.ts b/src/quickPicks/fileHistory.ts index 7602dda..3786212 100644 --- a/src/quickPicks/fileHistory.ts +++ b/src/quickPicks/fileHistory.ts @@ -79,11 +79,9 @@ export class FileHistoryQuickPick { items.splice(index, 0, new CommandQuickPickItem({ label: `$(history) Show Branch History`, description: `\u00a0 \u2014 \u00a0\u00a0 shows the current branch history` - }, Commands.ShowQuickRepoHistory, + }, Commands.ShowQuickCurrentBranchHistory, [ undefined, - undefined, - undefined, new CommandQuickPickItem({ label: `go back \u21A9`, description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(uri.fsPath)}${uri.sha ? ` from \u00a0$(git-commit) ${uri.shortSha}` : ''}` diff --git a/src/quickPicks/repoHistory.ts b/src/quickPicks/repoHistory.ts deleted file mode 100644 index fbb6bbe..0000000 --- a/src/quickPicks/repoHistory.ts +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; -import { Iterables } from '../system'; -import { CancellationTokenSource, QuickPickOptions, Uri, window } from 'vscode'; -import { Commands, Keyboard, KeyNoopCommand } from '../commands'; -import { GitUri, IGitLog } from '../gitService'; -import { CommitQuickPickItem } from './gitQuickPicks'; -import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, showQuickPickProgress } from './quickPicks'; - -export class RepoHistoryQuickPick { - - static showProgress(branch: string) { - return showQuickPickProgress(`${branch} history \u2014 search by commit message, filename, or sha`, - { - left: KeyNoopCommand, - ',': KeyNoopCommand, - '.': KeyNoopCommand - }); - } - - static async show(log: IGitLog, uri: GitUri, branch: string, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem): Promise { - const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileNames}`))) as (CommitQuickPickItem | CommandQuickPickItem)[]; - - let previousPageCommand: CommandQuickPickItem; - - if ((log.truncated || (uri && uri.sha))) { - if (log.truncated) { - items.splice(0, 0, new CommandQuickPickItem({ - label: `$(sync) Show All Commits`, - description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while` - }, Commands.ShowQuickRepoHistory, [ - new GitUri(Uri.file(log.repoPath), { fileName: '', repoPath: log.repoPath }), - branch, - 0, - goBackCommand - ])); - } - else { - items.splice(0, 0, new CommandQuickPickItem({ - label: `$(history) Show Branch History`, - description: `\u00a0 \u2014 \u00a0\u00a0 shows \u00a0$(git-branch) ${branch} history` - }, Commands.ShowQuickRepoHistory, [ - new GitUri(Uri.file(log.repoPath), { fileName: '', repoPath: log.repoPath }), - branch, - undefined, - new CommandQuickPickItem({ - label: `go back \u21A9`, - description: `\u00a0 \u2014 \u00a0\u00a0 to \u00a0$(git-branch) ${branch} history` - }, Commands.ShowQuickRepoHistory, [uri, branch, log.maxCount, goBackCommand, log]) - ])); - } - - if (nextPageCommand) { - items.splice(0, 0, nextPageCommand); - } - - if (log.truncated) { - const npc = new CommandQuickPickItem({ - label: `$(arrow-right) Show Next Commits`, - description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} newer commits` - }, Commands.ShowQuickRepoHistory, [uri, branch, 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.ShowQuickRepoHistory, [new GitUri(uri ? uri : last.uri, last), branch, log.maxCount, goBackCommand, undefined, npc]); - - items.splice(0, 0, previousPageCommand); - } - } - - if (goBackCommand) { - items.splice(0, 0, goBackCommand); - } - - if (progressCancellation.token.isCancellationRequested) return undefined; - - const scope = await Keyboard.instance.beginScope({ - left: goBackCommand, - ',': previousPageCommand, - '.': nextPageCommand - }); - - progressCancellation.cancel(); - - const pick = await window.showQuickPick(items, { - matchOnDescription: true, - matchOnDetail: true, - placeHolder: `${branch} history \u2014 search by commit message, filename, or sha`, - ignoreFocusOut: getQuickPickIgnoreFocusOut() - // onDidSelectItem: (item: QuickPickItem) => { - // scope.setKeyCommand('right', item); - // } - } as QuickPickOptions); - - await scope.dispose(); - - return pick; - } -} \ No newline at end of file diff --git a/src/quickPicks/repoStatus.ts b/src/quickPicks/repoStatus.ts index 5279d48..56aaa49 100644 --- a/src/quickPicks/repoStatus.ts +++ b/src/quickPicks/repoStatus.ts @@ -117,7 +117,7 @@ export class RepoStatusQuickPick { items.splice(0, 0, new CommandQuickPickItem({ label: `$(cloud-upload)\u00a0 ${status.state.ahead} Commits ahead of \u00a0$(git-branch) ${status.upstream}`, description: `\u00a0 \u2014 \u00a0\u00a0 shows commits in \u00a0$(git-branch) ${status.branch} but not \u00a0$(git-branch) ${status.upstream}` - }, Commands.ShowQuickRepoHistory, [ + }, Commands.ShowQuickBranchHistory, [ new GitUri(Uri.file(status.repoPath), { fileName: '', repoPath: status.repoPath, sha: `${status.upstream}..${status.branch}` }), status.branch, 0, @@ -133,7 +133,7 @@ export class RepoStatusQuickPick { items.splice(0, 0, new CommandQuickPickItem({ label: `$(cloud-download)\u00a0 ${status.state.behind} Commits behind \u00a0$(git-branch) ${status.upstream}`, description: `\u00a0 \u2014 \u00a0\u00a0 shows commits in \u00a0$(git-branch) ${status.upstream} but not \u00a0$(git-branch) ${status.branch} (since \u00a0$(git-commit) ${status.sha.substring(0, 8)})` - }, Commands.ShowQuickRepoHistory, [ + }, Commands.ShowQuickBranchHistory, [ new GitUri(Uri.file(status.repoPath), { fileName: '', repoPath: status.repoPath, sha: `${status.sha}..${status.upstream}` }), status.upstream, 0,