Quellcode durchsuchen

Adds `Open Revision...` command

Fixes issues with commit paging in certain quick pick menus
main
Eric Amodio vor 7 Jahren
Ursprung
Commit
29b455d447
8 geänderte Dateien mit 126 neuen und 44 gelöschten Zeilen
  1. +4
    -0
      CHANGELOG.md
  2. +2
    -0
      README.md
  3. +9
    -0
      package.json
  4. +1
    -1
      src/commands.ts
  5. +22
    -2
      src/commands/diffWithRevision.ts
  6. +61
    -3
      src/commands/openFileRevision.ts
  7. +20
    -2
      src/commands/showQuickFileHistory.ts
  8. +7
    -36
      src/quickPicks/fileHistory.ts

+ 4
- 0
CHANGELOG.md Datei anzeigen

@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## [Unreleased]
### Added
- Adds `Open Working File` command (`gitlens.openWorkingFile`) - opens the working file for the active file revision -- closes [#236](https://github.com/eamodio/vscode-gitlens/issues/236)
- Adds `Open Revision...` command (`gitlens.openFileRevision`) - opens the selected revision for the active file
### Fixed
- Fixes issues with commit paging in certain quick pick menus
## [7.1.0-beta] - 2017-12-20
### Changed

+ 2
- 0
README.md Datei anzeigen

@ -332,6 +332,8 @@ While GitLens is highly customizable and provides many [configuration settings](
- Adds a `Open Working File"` command (`gitlens.openWorkingFile`) to open the working file for the active file revision
- Adds a `Open Revision...` command (`gitlens.openFileRevision`) to open the selected revision for the active file
- Adds a `Open Changes (with difftool)` command (`gitlens.externalDiff`) to the source control group and source control resource context menus to open the changes of a file or set of files with the configured git difftool
- Adds a `Open All Changes (with difftool)` command (`gitlens.externalDiffAll`) to open all working changes with the configured git difftool

+ 9
- 0
package.json Datei anzeigen

@ -1323,6 +1323,11 @@
"category": "GitLens"
},
{
"command": "gitlens.openFileRevision",
"title": "Open Revision...",
"category": "GitLens"
},
{
"command": "gitlens.openRepoInRemote",
"title": "Open Repository in Remote",
"category": "GitLens"
@ -1738,6 +1743,10 @@
"when": "gitlens:activeIsTracked && gitlens:activeHasRemote"
},
{
"command": "gitlens.openFileRevision",
"when": "gitlens:activeIsTracked"
},
{
"command": "gitlens.openRepoInRemote",
"when": "gitlens:activeHasRemote"
},

+ 1
- 1
src/commands.ts Datei anzeigen

@ -79,7 +79,7 @@ export function configureCommands(
context.subscriptions.push(new Commands.OpenBranchInRemoteCommand(git));
context.subscriptions.push(new Commands.OpenCommitInRemoteCommand(git));
context.subscriptions.push(new Commands.OpenFileInRemoteCommand(git));
context.subscriptions.push(new Commands.OpenFileRevisionCommand(annotationController));
context.subscriptions.push(new Commands.OpenFileRevisionCommand(annotationController, git));
context.subscriptions.push(new Commands.OpenInRemoteCommand());
context.subscriptions.push(new Commands.OpenRepoInRemoteCommand(git));
context.subscriptions.push(new Commands.OpenWorkingFileCommand(annotationController, git));

+ 22
- 2
src/commands/diffWithRevision.ts Datei anzeigen

@ -1,5 +1,5 @@
'use strict';
import { Strings } from '../system';
import { Iterables, Strings } from '../system';
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
import { GlyphChars } from '../constants';
@ -14,6 +14,7 @@ export interface DiffWithRevisionCommandArgs {
line?: number;
showOptions?: TextDocumentShowOptions;
nextPageCommand?: CommandQuickPickItem;
}
export class DiffWithRevisionCommand extends ActiveEditorCommand {
@ -42,14 +43,33 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
if (progressCancellation.token.isCancellationRequested) return undefined;
let previousPageCommand: CommandQuickPickItem | undefined = undefined;
if (log.truncated) {
const npc = new CommandQuickPickItem({
label: `$(arrow-right) Show Next Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} shows ${log.maxCount} newer commits`
}, Commands.DiffWithRevision, [uri, { ...args } as DiffWithRevisionCommandArgs]);
const last = Iterables.last(log.commits.values());
if (last != null) {
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} shows ${log.maxCount} older commits`
}, Commands.DiffWithRevision, [new GitUri(uri, last), { ...args, nextPageCommand: npc } as DiffWithRevisionCommandArgs]);
}
}
const label = `${gitUri.getFormattedPath()}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`;
const pick = await FileHistoryQuickPick.show(this.git, log, gitUri, label, progressCancellation, {
pickerOnly: true,
nextPageCommand: args.nextPageCommand,
previousPageCommand: previousPageCommand,
showAllCommand: log !== undefined && log.truncated
? new CommandQuickPickItem({
label: `$(sync) Show All Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while`
}, Commands.ShowQuickFileHistory, [uri, { ...args, maxCount: 0 }])
}, Commands.DiffWithRevision, [uri, { ...args, maxCount: 0 }])
: undefined
});
if (pick === undefined) return undefined;

+ 61
- 3
src/commands/openFileRevision.ts Datei anzeigen

@ -1,14 +1,22 @@
'use strict';
import { Iterables, Strings } from '../system';
import { Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { AnnotationController, FileAnnotationType } from '../annotations/annotationController';
import { ActiveEditorCommand, Commands, openEditor } from './common';
import { ActiveEditorCommand, Commands, getCommandUri, openEditor } from './common';
import { GlyphChars } from '../constants';
import { GitService, GitUri } from '../gitService';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommandQuickPickItem, FileHistoryQuickPick } from '../quickPicks';
export interface OpenFileRevisionCommandArgs {
uri?: Uri;
maxCount?: number;
line?: number;
showOptions?: TextDocumentShowOptions;
annotationType?: FileAnnotationType;
nextPageCommand?: CommandQuickPickItem;
}
export class OpenFileRevisionCommand extends ActiveEditorCommand {
@ -34,7 +42,8 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
}
constructor(
private readonly annotationController: AnnotationController
private readonly annotationController: AnnotationController,
private readonly git: GitService
) {
super(Commands.OpenFileRevision);
}
@ -46,6 +55,55 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
}
try {
if (args.uri === undefined) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
const gitUri = await GitUri.fromUri(uri, this.git);
const progressCancellation = FileHistoryQuickPick.showProgress(gitUri);
const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: args.maxCount, ref: gitUri.sha });
if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open history compare');
if (progressCancellation.token.isCancellationRequested) return undefined;
let previousPageCommand: CommandQuickPickItem | undefined = undefined;
if (log.truncated) {
const npc = new CommandQuickPickItem({
label: `$(arrow-right) Show Next Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} shows ${log.maxCount} newer commits`
}, Commands.OpenFileRevision, [uri, { ...args } as OpenFileRevisionCommandArgs]);
const last = Iterables.last(log.commits.values());
if (last != null) {
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} shows ${log.maxCount} older commits`
}, Commands.OpenFileRevision, [new GitUri(uri, last), { ...args, nextPageCommand: npc } as OpenFileRevisionCommandArgs]);
}
}
const label = `${gitUri.getFormattedPath()}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`;
const pick = await FileHistoryQuickPick.show(this.git, log, gitUri, label, progressCancellation, {
pickerOnly: true,
nextPageCommand: args.nextPageCommand,
previousPageCommand: previousPageCommand,
showAllCommand: log !== undefined && log.truncated
? new CommandQuickPickItem({
label: `$(sync) Show All Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while`
}, Commands.OpenFileRevision, [uri, { ...args, maxCount: 0 } as OpenFileRevisionCommandArgs])
: undefined
});
if (pick === undefined) return undefined;
if (pick instanceof CommandQuickPickItem) return pick.execute();
args.uri = GitUri.toRevisionUri(pick.commit.sha, pick.commit.uri.fsPath, pick.commit.repoPath);
}
if (args.line !== undefined && args.line !== 0) {
if (args.showOptions === undefined) {
args.showOptions = {};
@ -60,7 +118,7 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
}
catch (ex) {
Logger.error(ex, 'OpenFileRevisionCommand');
return window.showErrorMessage(`Unable to open in file revision. See output channel for more details`);
return window.showErrorMessage(`Unable to open file revision. See output channel for more details`);
}
}
}

+ 20
- 2
src/commands/showQuickFileHistory.ts Datei anzeigen

@ -1,5 +1,5 @@
'use strict';
import { Strings } from '../system';
import { Iterables, Strings } from '../system';
import { commands, Range, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
import { GlyphChars } from '../constants';
@ -44,15 +44,33 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
if (progressCancellation.token.isCancellationRequested) return undefined;
let previousPageCommand: CommandQuickPickItem | undefined = undefined;
if (args.log.truncated) {
const npc = new CommandQuickPickItem({
label: `$(arrow-right) Show Next Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} shows ${args.log.maxCount} newer commits`
}, Commands.ShowQuickFileHistory, [gitUri, { ...args, log: undefined } as ShowQuickFileHistoryCommandArgs]);
const last = Iterables.last(args.log.commits.values());
if (last != null) {
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} shows ${args.log.maxCount} older commits`
}, Commands.ShowQuickFileHistory, [new GitUri(uri, last), { ...args, log: undefined, nextPageCommand: npc } as ShowQuickFileHistoryCommandArgs]);
}
}
const label = `${gitUri.getFormattedPath()}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`;
const pick = await FileHistoryQuickPick.show(this.git, args.log, gitUri, label, progressCancellation, {
goBackCommand: args.goBackCommand,
nextPageCommand: args.nextPageCommand,
previousPageCommand: previousPageCommand,
showAllCommand: args.log !== undefined && args.log.truncated
? new CommandQuickPickItem({
label: `$(sync) Show All Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while`
}, Commands.ShowQuickFileHistory, [uri, { ...args, maxCount: 0 }])
}, Commands.ShowQuickFileHistory, [uri, { ...args, log: undefined, maxCount: 0 }])
: undefined,
showInResultsExplorerCommand: args.log !== undefined
? new ShowCommitsInResultsQuickPickItem(args.log, {

+ 7
- 36
src/quickPicks/fileHistory.ts Datei anzeigen

@ -20,13 +20,11 @@ export class FileHistoryQuickPick {
});
}
static async show(git: GitService, log: GitLog, uri: GitUri, placeHolder: string, progressCancellation: CancellationTokenSource, options: { goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem, pickerOnly?: boolean, showAllCommand?: CommandQuickPickItem, showInResultsExplorerCommand?: CommandQuickPickItem } = {}): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
static async show(git: GitService, log: GitLog, uri: GitUri, placeHolder: string, progressCancellation: CancellationTokenSource, options: { goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem, previousPageCommand?: CommandQuickPickItem, pickerOnly?: boolean, showAllCommand?: CommandQuickPickItem, showInResultsExplorerCommand?: CommandQuickPickItem } = {}): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
options = { pickerOnly: false, ...options };
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as (CommitQuickPickItem | CommandQuickPickItem)[];
let previousPageCommand: CommandQuickPickItem | undefined = undefined;
let index = 0;
if (options.showInResultsExplorerCommand !== undefined) {
@ -39,7 +37,7 @@ export class FileHistoryQuickPick {
index++;
items.splice(0, 0, options.showAllCommand);
}
else {
else if (!options.pickerOnly) {
const workingFileName = await git.findWorkingFileName(log.repoPath, path.relative(log.repoPath, uri.fsPath));
if (workingFileName) {
index++;
@ -66,41 +64,14 @@ export class FileHistoryQuickPick {
}
}
if (options.nextPageCommand) {
if (options.nextPageCommand !== undefined) {
index++;
items.splice(0, 0, options.nextPageCommand);
}
if (log.truncated) {
const npc = new CommandQuickPickItem({
label: `$(arrow-right) Show Next Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} shows ${log.maxCount} newer commits`
}, Commands.ShowQuickFileHistory, [
uri,
{
maxCount: log.maxCount,
goBackCommand: options.goBackCommand,
nextPageCommand: options.nextPageCommand
} as ShowQuickFileHistoryCommandArgs
]);
const last = Iterables.last(log.commits.values());
if (last != null) {
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} shows ${log.maxCount} older commits`
}, Commands.ShowQuickFileHistory, [
new GitUri(uri, last),
{
maxCount: log.maxCount,
goBackCommand: options.goBackCommand,
nextPageCommand: npc
} as ShowQuickFileHistoryCommandArgs
]);
index++;
items.splice(0, 0, previousPageCommand);
}
if (options.previousPageCommand !== undefined) {
index++;
items.splice(0, 0, options.previousPageCommand);
}
}
@ -159,7 +130,7 @@ export class FileHistoryQuickPick {
const scope = await Keyboard.instance.beginScope({
left: options.goBackCommand,
',': previousPageCommand,
',': options.previousPageCommand,
'.': options.nextPageCommand
});

Laden…
Abbrechen
Speichern