Browse Source

Adds branch/tag option to open/diff revision cmds

Changes default sort of branch/tag pickers to be by date desc
main
Eric Amodio 4 years ago
parent
commit
89784cd42a
14 changed files with 125 additions and 59 deletions
  1. +19
    -18
      src/commands/diffWithRevision.ts
  2. +9
    -5
      src/commands/openBranchOnRemote.ts
  3. +12
    -11
      src/commands/openFileAtRevision.ts
  4. +1
    -1
      src/commands/openFileAtRevisionFrom.ts
  5. +5
    -1
      src/commands/openFileOnRemote.ts
  6. +2
    -2
      src/git/gitService.ts
  7. +30
    -10
      src/quickpicks/commitPicker.ts
  8. +8
    -4
      src/quickpicks/quickPicksItems.ts
  9. +9
    -4
      src/quickpicks/referencePicker.ts
  10. +1
    -1
      src/terminal/linkProvider.ts
  11. +10
    -2
      src/views/nodes/compareBranchNode.ts
  12. +9
    -0
      src/views/nodes/compareNode.ts
  13. +5
    -0
      src/views/nodes/fileHistoryTrackerNode.ts
  14. +5
    -0
      src/views/nodes/lineHistoryTrackerNode.ts

+ 19
- 18
src/commands/diffWithRevision.ts View File

@ -8,7 +8,7 @@ import { GitRevision } from '../git/git';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommitPicker, DirectiveQuickPickItem } from '../quickpicks';
import { CommandQuickPickItem, CommitPicker } from '../quickpicks';
import { Strings } from '../system';
export interface DiffWithRevisionCommandArgs {
@ -55,24 +55,25 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
{
picked: gitUri.sha,
keys: ['right', 'alt+right', 'ctrl+right'],
onDidPressKey: async (key, quickpick) => {
const [item] = quickpick.activeItems;
if (item != null && !DirectiveQuickPickItem.is(item)) {
void (await executeCommand<DiffWithCommandArgs>(Commands.DiffWith, {
repoPath: gitUri.repoPath,
lhs: {
sha: item.item.ref,
uri: gitUri,
},
rhs: {
sha: '',
uri: gitUri,
},
line: args!.line,
showOptions: args!.showOptions,
}));
}
onDidPressKey: async (key, item) => {
void (await executeCommand<DiffWithCommandArgs>(Commands.DiffWith, {
repoPath: gitUri.repoPath,
lhs: {
sha: item.item.ref,
uri: gitUri,
},
rhs: {
sha: '',
uri: gitUri,
},
line: args!.line,
showOptions: args!.showOptions,
}));
},
showOtherReferences: CommandQuickPickItem.fromCommand(
'Choose a branch or tag...',
Commands.DiffWithRevisionFrom,
),
},
);
if (pick == null) return;

+ 9
- 5
src/commands/openBranchOnRemote.ts View File

@ -1,9 +1,5 @@
'use strict';
import { TextEditor, Uri, window } from 'vscode';
import { RemoteResourceType } from '../git/git';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { CommandQuickPickItem, ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks';
import {
ActiveEditorCommand,
command,
@ -14,7 +10,12 @@ import {
getRepoPathOrActiveOrPrompt,
isCommandViewContextWithBranch,
} from './common';
import { BranchSorting } from '../configuration';
import { RemoteResourceType } from '../git/git';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { OpenOnRemoteCommandArgs } from './openOnRemote';
import { CommandQuickPickItem, ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks';
export interface OpenBranchOnRemoteCommandArgs {
branch?: string;
@ -67,8 +68,11 @@ export class OpenBranchOnRemoteCommand extends ActiveEditorCommand {
{
autoPick: true,
// checkmarks: false,
filterBranches: b => b.tracking != null,
filter: { branches: b => b.tracking != null },
include: ReferencesQuickPickIncludes.Branches,
sort: {
branches: { current: true, orderBy: BranchSorting.DateDesc },
},
},
);
if (pick == null || pick instanceof CommandQuickPickItem) return;

+ 12
- 11
src/commands/openFileAtRevision.ts View File

@ -9,7 +9,7 @@ import { GitUri } from '../git/gitUri';
import { GitActions } from './gitCommands';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommitPicker, DirectiveQuickPickItem } from '../quickpicks';
import { CommandQuickPickItem, CommitPicker } from '../quickpicks';
import { Strings } from '../system';
export interface OpenFileAtRevisionCommandArgs {
@ -83,17 +83,18 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand {
{
picked: gitUri.sha,
keys: ['right', 'alt+right', 'ctrl+right'],
onDidPressKey: async (key, quickpick) => {
const [item] = quickpick.activeItems;
if (item != null && !DirectiveQuickPickItem.is(item)) {
void (await GitActions.Commit.openFileAtRevision(item.item.uri.fsPath, item.item, {
annotationType: args!.annotationType,
line: args!.line,
preserveFocus: true,
preview: false,
}));
}
onDidPressKey: async (key, item) => {
void (await GitActions.Commit.openFileAtRevision(item.item.uri.fsPath, item.item, {
annotationType: args!.annotationType,
line: args!.line,
preserveFocus: true,
preview: false,
}));
},
showOtherReferences: CommandQuickPickItem.fromCommand(
'Choose a branch or tag...',
Commands.OpenFileAtRevisionFrom,
),
},
);
if (pick == null) return;

+ 1
- 1
src/commands/openFileAtRevisionFrom.ts View File

@ -40,7 +40,7 @@ export class OpenFileAtRevisionFromCommand extends ActiveEditorCommand {
}
if (args.reference == null) {
const title = `Open File at Revision${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const title = `Open File at Branch or Tag${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const pick = await ReferencePicker.show(
gitUri.repoPath,
`${title}${gitUri.getFormattedFilename({ truncateTo: quickPickTitleMaxChars - title.length })}`,

+ 5
- 1
src/commands/openFileOnRemote.ts View File

@ -11,6 +11,7 @@ import {
isCommandViewContextWithCommit,
} from './common';
import { UriComparer } from '../comparers';
import { BranchSorting } from '../configuration';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitRevision, RemoteResourceType } from '../git/git';
@ -124,8 +125,11 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
{
autoPick: true,
// checkmarks: false,
filterBranches: b => b.tracking != null,
filter: { branches: b => b.tracking != null },
include: ReferencesQuickPickIncludes.Branches,
sort: {
branches: { current: true, orderBy: BranchSorting.DateDesc },
},
},
);
if (pick == null) return;

+ 2
- 2
src/git/gitService.ts View File

@ -1176,14 +1176,14 @@ export class GitService implements Disposable {
} = {},
) {
const [branches, tags] = await Promise.all<GitBranch[] | undefined, GitTag[] | undefined>([
include === 'all' || include === 'branches'
include == null || include === 'all' || include === 'branches'
? this.getBranches(repoPath, {
...options,
filter: filter?.branches,
sort: typeof sort === 'boolean' ? undefined : sort?.branches,
})
: undefined,
include === 'all' || include === 'tags'
include == null || include === 'all' || include === 'tags'
? this.getTags(repoPath, {
...options,
filter: filter?.tags,

+ 30
- 10
src/quickpicks/commitPicker.ts View File

@ -1,10 +1,16 @@
'use strict';
import { Disposable, QuickPick, window } from 'vscode';
import { Disposable, window } from 'vscode';
import { configuration } from '../configuration';
import { Container } from '../container';
import { GitLog, GitLogCommit } from '../git/git';
import { KeyboardScope, Keys } from '../keyboard';
import { CommitQuickPickItem, Directive, DirectiveQuickPickItem, getQuickPickIgnoreFocusOut } from '../quickpicks';
import {
CommandQuickPickItem,
CommitQuickPickItem,
Directive,
DirectiveQuickPickItem,
getQuickPickIgnoreFocusOut,
} from '../quickpicks';
import { Iterables, Promises } from '../system';
export namespace CommitPicker {
@ -15,13 +21,11 @@ export namespace CommitPicker {
options?: {
picked?: string;
keys?: Keys[];
onDidPressKey?(
key: Keys,
quickpick: QuickPick<CommitQuickPickItem | DirectiveQuickPickItem>,
): void | Promise<void>;
onDidPressKey?(key: Keys, item: CommitQuickPickItem): void | Promise<void>;
showOtherReferences?: CommandQuickPickItem;
},
): Promise<GitLogCommit | undefined> {
const quickpick = window.createQuickPick<CommitQuickPickItem | DirectiveQuickPickItem>();
const quickpick = window.createQuickPick<CommandQuickPickItem | CommitQuickPickItem | DirectiveQuickPickItem>();
quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut();
quickpick.title = title;
@ -44,13 +48,14 @@ export namespace CommitPicker {
quickpick.items = getItems(log);
if (options?.picked) {
quickpick.activeItems = quickpick.items.filter(i => i.picked);
quickpick.activeItems = quickpick.items.filter(i => (CommandQuickPickItem.is(i) ? false : i.picked));
}
function getItems(log: GitLog | undefined) {
return log == null
? [DirectiveQuickPickItem.create(Directive.Cancel)]
: [
...(options?.showOtherReferences != null ? [options?.showOtherReferences] : []),
...Iterables.map(log.commits.values(), commit =>
CommitQuickPickItem.create(commit, options?.picked === commit.ref, {
compact: true,
@ -102,7 +107,14 @@ export namespace CommitPicker {
{
onDidPressKey: key => {
if (quickpick.activeItems.length !== 0) {
void options.onDidPressKey!(key, quickpick);
const [item] = quickpick.activeItems;
if (
item != null &&
!DirectiveQuickPickItem.is(item) &&
!CommandQuickPickItem.is(item)
) {
void options.onDidPressKey!(key, item);
}
}
},
},
@ -114,7 +126,9 @@ export namespace CommitPicker {
}
try {
const pick = await new Promise<CommitQuickPickItem | DirectiveQuickPickItem | undefined>(resolve => {
const pick = await new Promise<
CommandQuickPickItem | CommitQuickPickItem | DirectiveQuickPickItem | undefined
>(resolve => {
disposables.push(
quickpick.onDidHide(() => resolve()),
quickpick.onDidAccept(() => {
@ -154,6 +168,12 @@ export namespace CommitPicker {
});
if (pick == null || DirectiveQuickPickItem.is(pick)) return undefined;
if (pick instanceof CommandQuickPickItem) {
void (await pick.execute());
return undefined;
}
return pick.item;
} finally {
quickpick.dispose();

+ 8
- 4
src/quickpicks/quickPicksItems.ts View File

@ -75,16 +75,20 @@ export namespace DirectiveQuickPickItem {
}
export class CommandQuickPickItem<Arguments extends any[] = any[]> implements QuickPickItem {
static fromCommand<T>(label: string, command: Commands, args: T): CommandQuickPickItem;
static fromCommand<T>(item: QuickPickItem, command: Commands, args: T): CommandQuickPickItem;
static fromCommand<T>(labelOrItem: string | QuickPickItem, command: Commands, args: T): CommandQuickPickItem {
static fromCommand<T>(label: string, command: Commands, args?: T): CommandQuickPickItem;
static fromCommand<T>(item: QuickPickItem, command: Commands, args?: T): CommandQuickPickItem;
static fromCommand<T>(labelOrItem: string | QuickPickItem, command: Commands, args?: T): CommandQuickPickItem {
return new CommandQuickPickItem(
typeof labelOrItem === 'string' ? { label: labelOrItem } : labelOrItem,
command,
[args],
args == null ? [] : [args],
);
}
static is(item: QuickPickItem): item is CommandQuickPickItem {
return item instanceof CommandQuickPickItem;
}
label!: string;
description?: string;
detail?: string | undefined;

+ 9
- 4
src/quickpicks/referencePicker.ts View File

@ -6,6 +6,7 @@ import { GitBranch, GitReference, GitTag } from '../git/git';
import { KeyboardScope, Keys } from '../keyboard';
import { BranchQuickPickItem, getQuickPickIgnoreFocusOut, RefQuickPickItem, TagQuickPickItem } from '../quickpicks';
import { getBranchesAndOrTags, getValidateGitReferenceFn } from '../commands/quickCommand';
import { BranchSorting, TagSorting } from '../configuration';
export type ReferencesQuickPickItem = BranchQuickPickItem | TagQuickPickItem | RefQuickPickItem;
@ -22,11 +23,11 @@ export interface ReferencesQuickPickOptions {
allowEnteringRefs?: boolean;
autoPick?: boolean;
picked?: string;
filterBranches?(branch: GitBranch): boolean;
filterTags?(tag: GitTag): boolean;
filter?: { branches?(b: GitBranch): boolean; tags?(t: GitTag): boolean };
include?: ReferencesQuickPickIncludes;
keys?: Keys[];
onDidPressKey?(key: Keys, quickpick: QuickPick<ReferencesQuickPickItem>): void | Promise<void>;
sort?: boolean | { branches?: { current?: boolean; orderBy?: BranchSorting }; tags?: { orderBy?: TagSorting } };
}
export namespace ReferencePicker {
@ -135,7 +136,7 @@ export namespace ReferencePicker {
async function getItems(
repoPath: string,
{ picked, filterBranches, filterTags, include }: ReferencesQuickPickOptions,
{ picked, filter, include, sort }: ReferencesQuickPickOptions,
): Promise<ReferencesQuickPickItem[]> {
include = include ?? ReferencesQuickPickIncludes.BranchesAndTags;
@ -149,8 +150,12 @@ export namespace ReferencePicker {
? ['tags']
: [],
{
filter: { branches: filterBranches, tags: filterTags },
filter: filter,
picked: picked,
sort: sort ?? {
branches: { current: false, orderBy: BranchSorting.DateDesc },
tags: { orderBy: TagSorting.DateDesc },
},
},
);

+ 1
- 1
src/terminal/linkProvider.ts View File

@ -32,7 +32,7 @@ export class GitTerminalLinkProvider implements Disposable, TerminalLinkProvider
const links: GitTerminalLink[] = [];
const branchesAndTags = await Container.git.getBranchesAndOrTags(repoPath, { include: 'all' });
const branchesAndTags = await Container.git.getBranchesAndOrTags(repoPath);
// Don't use the shared regex instance directly, because we can be called reentrantly (because of the awaits below)
const regex = new RegExp(refRegex, 'gi');

+ 10
- 2
src/views/nodes/compareBranchNode.ts View File

@ -2,7 +2,7 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { CommitsView } from '../commitsView';
import { BranchComparison, BranchComparisons, GlyphChars, WorkspaceState } from '../../constants';
import { ViewShowBranchComparison } from '../../config';
import { BranchSorting, TagSorting, ViewShowBranchComparison } from '../../configuration';
import { Container } from '../../container';
import { GitBranch, GitRevision } from '../../git/git';
import { GitUri } from '../../git/gitUri';
@ -189,7 +189,15 @@ export class CompareBranchNode extends ViewNode
this.branch.repoPath,
`Compare ${this.branch.name}${this.compareWithWorkingTree ? ' (working)' : ''} with`,
'Choose a reference to compare with',
{ allowEnteringRefs: true, picked: this.branch.ref /*checkmarks: true*/ },
{
allowEnteringRefs: true,
picked: this.branch.ref,
// checkmarks: true,
sort: {
branches: { current: true, orderBy: BranchSorting.DateDesc },
tags: { orderBy: TagSorting.DateDesc },
},
},
);
if (pick === undefined || pick instanceof CommandQuickPickItem) return;

+ 9
- 0
src/views/nodes/compareNode.ts View File

@ -1,6 +1,7 @@
'use strict';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { getRepoPathOrPrompt } from '../../commands';
import { BranchSorting, TagSorting } from '../../configuration';
import { CommandContext, NamedRef, setCommandContext } from '../../constants';
import { GitRevision } from '../../git/git';
import { ReferencePicker, ReferencesQuickPickIncludes } from '../../quickpicks';
@ -150,6 +151,10 @@ export class CompareNode extends ViewNode {
ReferencesQuickPickIncludes.BranchesAndTags |
ReferencesQuickPickIncludes.HEAD |
ReferencesQuickPickIncludes.WorkingTree,
sort: {
branches: { current: true, orderBy: BranchSorting.DateDesc },
tags: { orderBy: TagSorting.DateDesc },
},
},
);
if (pick === undefined) {
@ -190,6 +195,10 @@ export class CompareNode extends ViewNode {
ReferencesQuickPickIncludes.BranchesAndTags |
ReferencesQuickPickIncludes.HEAD |
ReferencesQuickPickIncludes.WorkingTree,
sort: {
branches: { current: true, orderBy: BranchSorting.DateDesc },
tags: { orderBy: TagSorting.DateDesc },
},
});
if (pick == null) {
await this.view.show();

+ 5
- 0
src/views/nodes/fileHistoryTrackerNode.ts View File

@ -2,6 +2,7 @@
import { Disposable, TextEditor, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { MessageNode } from './common';
import { UriComparer } from '../../comparers';
import { BranchSorting, TagSorting } from '../../configuration';
import { Container } from '../../container';
import { FileHistoryView } from '../fileHistoryView';
import { FileHistoryNode } from './fileHistoryNode';
@ -83,6 +84,10 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
allowEnteringRefs: true,
picked: this._base,
// checkmarks: true,
sort: {
branches: { current: true, orderBy: BranchSorting.DateDesc },
tags: { orderBy: TagSorting.DateDesc },
},
},
);
if (pick == null) return;

+ 5
- 0
src/views/nodes/lineHistoryTrackerNode.ts View File

@ -2,6 +2,7 @@
import { Selection, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { MessageNode } from './common';
import { UriComparer } from '../../comparers';
import { BranchSorting, TagSorting } from '../../configuration';
import { Container } from '../../container';
import { FileHistoryView } from '../fileHistoryView';
import { GitReference } from '../../git/git';
@ -91,6 +92,10 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
allowEnteringRefs: true,
picked: this._base,
// checkmarks: true,
sort: {
branches: { current: true, orderBy: BranchSorting.DateDesc },
tags: { orderBy: TagSorting.DateDesc },
},
},
);
if (pick == null) return;

Loading…
Cancel
Save