Browse Source

Adds compare node to History view

main
Eric Amodio 4 years ago
parent
commit
1941707ae0
6 changed files with 71 additions and 43 deletions
  1. +31
    -8
      package.json
  2. +1
    -0
      src/config.ts
  3. +6
    -1
      src/views/historyView.ts
  4. +14
    -8
      src/views/nodes/compareBranchNode.ts
  5. +1
    -25
      src/views/repositoriesView.ts
  6. +18
    -1
      src/views/viewCommands.ts

+ 31
- 8
package.json View File

@ -1720,6 +1720,29 @@
"markdownDescription": "Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the _History_ view. Only applies when `#gitlens.views.history.files.layout#` is set to `auto`", "markdownDescription": "Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the _History_ view. Only applies when `#gitlens.views.history.files.layout#` is set to `auto`",
"scope": "window" "scope": "window"
}, },
"gitlens.views.history.showBranchComparison": {
"anyOf": [
{
"enum": [
false
]
},
{
"type": "string",
"enum": [
"branch",
"working"
],
"enumDescriptions": [
"Compares the current branch to the user-selected reference",
"Compares the working tree to the user-selected reference"
]
}
],
"default": "working",
"markdownDescription": "Specifies whether to show a comparison of a user-selected reference (branch, tag. etc) to the current branch or the working tree in the _History_ view",
"scope": "window"
},
"gitlens.views.history.showTrackingBranch": { "gitlens.views.history.showTrackingBranch": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
@ -3333,7 +3356,7 @@
"icon": "$(refresh)" "icon": "$(refresh)"
}, },
{ {
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"command": "gitlens.views.setBranchComparisonToWorking",
"title": "Switch to Working Tree Comparison", "title": "Switch to Working Tree Comparison",
"category": "GitLens", "category": "GitLens",
"icon": { "icon": {
@ -3342,7 +3365,7 @@
} }
}, },
{ {
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"command": "gitlens.views.setBranchComparisonToBranch",
"title": "Switch to Branch Comparison", "title": "Switch to Branch Comparison",
"category": "GitLens", "category": "GitLens",
"icon": "$(compare-changes)" "icon": "$(compare-changes)"
@ -4589,11 +4612,11 @@
"when": "false" "when": "false"
}, },
{ {
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "false" "when": "false"
}, },
{ {
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"command": "gitlens.views.setBranchComparisonToBranch",
"when": "false" "when": "false"
}, },
{ {
@ -6531,12 +6554,12 @@
"group": "inline@1" "group": "inline@1"
}, },
{ {
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/", "when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/",
"group": "inline@2" "group": "inline@2"
}, },
{ {
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"command": "gitlens.views.setBranchComparisonToBranch",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/", "when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/",
"group": "inline@2" "group": "inline@2"
}, },
@ -6551,12 +6574,12 @@
"group": "1_gitlens@1" "group": "1_gitlens@1"
}, },
{ {
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/", "when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/",
"group": "1_gitlens@2" "group": "1_gitlens@2"
}, },
{ {
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"command": "gitlens.views.setBranchComparisonToBranch",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/", "when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/",
"group": "1_gitlens@2" "group": "1_gitlens@2"
}, },

+ 1
- 0
src/config.ts View File

@ -504,6 +504,7 @@ export interface HistoryViewConfig {
avatars: boolean; avatars: boolean;
branches: undefined; branches: undefined;
files: ViewsFilesConfig; files: ViewsFilesConfig;
showBranchComparison: false | ViewShowBranchComparison;
showTrackingBranch: boolean; showTrackingBranch: boolean;
} }

+ 6
- 1
src/views/historyView.ts View File

@ -24,6 +24,7 @@ import {
BranchesNode, BranchesNode,
BranchNode, BranchNode,
BranchOrTagFolderNode, BranchOrTagFolderNode,
CompareBranchNode,
ContextValues, ContextValues,
MessageNode, MessageNode,
RemoteNode, RemoteNode,
@ -38,7 +39,7 @@ import { debug, gate } from '../system';
import { ViewBase } from './viewBase'; import { ViewBase } from './viewBase';
export class HistoryRepositoryNode extends SubscribeableViewNode<HistoryView> { export class HistoryRepositoryNode extends SubscribeableViewNode<HistoryView> {
private children: BranchNode[] | undefined;
private children: (BranchNode | CompareBranchNode)[] | undefined;
constructor( constructor(
uri: GitUri, uri: GitUri,
@ -63,6 +64,10 @@ export class HistoryRepositoryNode extends SubscribeableViewNode {
}), }),
]; ];
if (this.view.config.showBranchComparison !== false) {
this.children.push(new CompareBranchNode(this.uri, this.view, this, branch));
}
void this.ensureSubscription(); void this.ensureSubscription();
} }
return this.children; return this.children;

+ 14
- 8
src/views/nodes/compareBranchNode.ts View File

@ -1,19 +1,20 @@
'use strict'; 'use strict';
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { BranchComparison, BranchComparisons, GlyphChars, WorkspaceState } from '../../constants'; import { BranchComparison, BranchComparisons, GlyphChars, WorkspaceState } from '../../constants';
import { ContextValues, ViewNode } from './viewNode';
import { RepositoriesView } from '../repositoriesView';
import { ViewShowBranchComparison } from '../../config';
import { Container } from '../../container';
import { GitBranch, GitRevision } from '../../git/git'; import { GitBranch, GitRevision } from '../../git/git';
import { GitUri } from '../../git/gitUri'; import { GitUri } from '../../git/gitUri';
import { HistoryView } from '../historyView';
import { CommandQuickPickItem, ReferencePicker } from '../../quickpicks'; import { CommandQuickPickItem, ReferencePicker } from '../../quickpicks';
import { RepositoriesView } from '../repositoriesView';
import { RepositoryNode } from './repositoryNode';
import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode'; import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode';
import { Container } from '../../container';
import { debug, gate, log, Strings } from '../../system';
import { FilesQueryResults, ResultsFilesNode } from './resultsFilesNode'; import { FilesQueryResults, ResultsFilesNode } from './resultsFilesNode';
import { ViewShowBranchComparison } from '../../config';
import { RepositoryNode } from './repositoryNode';
import { debug, gate, log, Strings } from '../../system';
import { ContextValues, ViewNode } from './viewNode';
export class CompareBranchNode extends ViewNode<RepositoriesView> {
export class CompareBranchNode extends ViewNode<HistoryView | RepositoriesView> {
static key = ':compare-branch'; static key = ':compare-branch';
static getId(repoPath: string, name: string): string { static getId(repoPath: string, name: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${name})`; return `${RepositoryNode.getId(repoPath)}${this.key}(${name})`;
@ -22,7 +23,12 @@ export class CompareBranchNode extends ViewNode {
private _children: ViewNode[] | undefined; private _children: ViewNode[] | undefined;
private _compareWith: BranchComparison | undefined; private _compareWith: BranchComparison | undefined;
constructor(uri: GitUri, view: RepositoriesView, parent: ViewNode, public readonly branch: GitBranch) {
constructor(
uri: GitUri,
view: HistoryView | RepositoriesView,
parent: ViewNode,
public readonly branch: GitBranch,
) {
super(uri, view, parent); super(uri, view, parent);
const comparisons = Container.context.workspaceState.get<BranchComparisons>(WorkspaceState.BranchComparisons); const comparisons = Container.context.workspaceState.get<BranchComparisons>(WorkspaceState.BranchComparisons);

+ 1
- 25
src/views/repositoriesView.ts View File

@ -8,13 +8,7 @@ import {
ProgressLocation, ProgressLocation,
window, window,
} from 'vscode'; } from 'vscode';
import {
configuration,
RepositoriesViewConfig,
ViewBranchesLayout,
ViewFilesLayout,
ViewShowBranchComparison,
} from '../configuration';
import { configuration, RepositoriesViewConfig, ViewBranchesLayout, ViewFilesLayout } from '../configuration';
import { CommandContext, setCommandContext, WorkspaceState } from '../constants'; import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { Container } from '../container'; import { Container } from '../container';
import { import {
@ -30,7 +24,6 @@ import {
BranchesNode, BranchesNode,
BranchNode, BranchNode,
BranchOrTagFolderNode, BranchOrTagFolderNode,
CompareBranchNode,
RemoteNode, RemoteNode,
RemotesNode, RemotesNode,
RepositoriesNode, RepositoriesNode,
@ -38,7 +31,6 @@ import {
StashesNode, StashesNode,
StashNode, StashNode,
TagsNode, TagsNode,
ViewNode,
} from './nodes'; } from './nodes';
import { gate } from '../system'; import { gate } from '../system';
import { ViewBase } from './viewBase'; import { ViewBase } from './viewBase';
@ -109,16 +101,6 @@ export class RepositoriesView extends ViewBase
); );
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this);
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this);
commands.registerCommand(
this.getQualifiedCommand('setBranchComparisonToWorking'),
n => this.setBranchComparison(n, ViewShowBranchComparison.Working),
this,
);
commands.registerCommand(
this.getQualifiedCommand('setBranchComparisonToBranch'),
n => this.setBranchComparison(n, ViewShowBranchComparison.Branch),
this,
);
} }
protected filterConfigurationChanged(e: ConfigurationChangeEvent) { protected filterConfigurationChanged(e: ConfigurationChangeEvent) {
@ -563,12 +545,6 @@ export class RepositoriesView extends ViewBase
this._onDidChangeAutoRefresh.fire(); this._onDidChangeAutoRefresh.fire();
} }
private setBranchComparison(node: ViewNode, comparisonType: Exclude<ViewShowBranchComparison, false>) {
if (!(node instanceof CompareBranchNode)) return undefined;
return node.setComparisonType(comparisonType);
}
private setBranchesLayout(layout: ViewBranchesLayout) { private setBranchesLayout(layout: ViewBranchesLayout) {
return configuration.updateEffective('views', this.configKey, 'branches', 'layout', layout); return configuration.updateEffective('views', this.configKey, 'branches', 'layout', layout);
} }

+ 18
- 1
src/views/viewCommands.ts View File

@ -11,7 +11,7 @@ import {
OpenFileAtRevisionCommandArgs, OpenFileAtRevisionCommandArgs,
OpenFileOnRemoteCommandArgs, OpenFileOnRemoteCommandArgs,
} from '../commands'; } from '../commands';
import { FileAnnotationType } from '../config';
import { FileAnnotationType, ViewShowBranchComparison } from '../config';
import { BuiltInCommands, CommandContext, setCommandContext } from '../constants'; import { BuiltInCommands, CommandContext, setCommandContext } from '../constants';
import { Container } from '../container'; import { Container } from '../container';
import { GitReference, GitRevision } from '../git/git'; import { GitReference, GitRevision } from '../git/git';
@ -156,6 +156,16 @@ export class ViewCommands {
n => this.setComparisonNotation(n, '...'), n => this.setComparisonNotation(n, '...'),
this, this,
); );
commands.registerCommand(
'gitlens.views.setBranchComparisonToWorking',
n => this.setBranchComparison(n, ViewShowBranchComparison.Working),
this,
);
commands.registerCommand(
'gitlens.views.setBranchComparisonToBranch',
n => this.setBranchComparison(n, ViewShowBranchComparison.Branch),
this,
);
commands.registerCommand('gitlens.views.cherryPick', this.cherryPick, this); commands.registerCommand('gitlens.views.cherryPick', this.cherryPick, this);
commands.registerCommand('gitlens.views.createBranch', this.createBranch, this); commands.registerCommand('gitlens.views.createBranch', this.createBranch, this);
@ -430,6 +440,13 @@ export class ViewCommands {
} }
@debug() @debug()
private setBranchComparison(node: ViewNode, comparisonType: Exclude<ViewShowBranchComparison, false>) {
if (!(node instanceof CompareBranchNode)) return undefined;
return node.setComparisonType(comparisonType);
}
@debug()
private setComparisonNotation(node: ViewNode, comparisonNotation: '...' | '..') { private setComparisonNotation(node: ViewNode, comparisonNotation: '...' | '..') {
if (!(node instanceof CompareResultsNode) && !(node instanceof CompareBranchNode)) return Promise.resolve(); if (!(node instanceof CompareResultsNode) && !(node instanceof CompareBranchNode)) return Promise.resolve();

Loading…
Cancel
Save