Bläddra i källkod

Adds compare node to History view

main
Eric Amodio 4 år sedan
förälder
incheckning
1941707ae0
6 ändrade filer med 71 tillägg och 43 borttagningar
  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 Visa fil

@ -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`",
"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": {
"type": "boolean",
"default": true,
@ -3333,7 +3356,7 @@
"icon": "$(refresh)"
},
{
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"command": "gitlens.views.setBranchComparisonToWorking",
"title": "Switch to Working Tree Comparison",
"category": "GitLens",
"icon": {
@ -3342,7 +3365,7 @@
}
},
{
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"command": "gitlens.views.setBranchComparisonToBranch",
"title": "Switch to Branch Comparison",
"category": "GitLens",
"icon": "$(compare-changes)"
@ -4589,11 +4612,11 @@
"when": "false"
},
{
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "false"
},
{
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"command": "gitlens.views.setBranchComparisonToBranch",
"when": "false"
},
{
@ -6531,12 +6554,12 @@
"group": "inline@1"
},
{
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/",
"group": "inline@2"
},
{
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"command": "gitlens.views.setBranchComparisonToBranch",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/",
"group": "inline@2"
},
@ -6551,12 +6574,12 @@
"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)/",
"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)/",
"group": "1_gitlens@2"
},

+ 1
- 0
src/config.ts Visa fil

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

+ 6
- 1
src/views/historyView.ts Visa fil

@ -24,6 +24,7 @@ import {
BranchesNode,
BranchNode,
BranchOrTagFolderNode,
CompareBranchNode,
ContextValues,
MessageNode,
RemoteNode,
@ -38,7 +39,7 @@ import { debug, gate } from '../system';
import { ViewBase } from './viewBase';
export class HistoryRepositoryNode extends SubscribeableViewNode<HistoryView> {
private children: BranchNode[] | undefined;
private children: (BranchNode | CompareBranchNode)[] | undefined;
constructor(
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();
}
return this.children;

+ 14
- 8
src/views/nodes/compareBranchNode.ts Visa fil

@ -1,19 +1,20 @@
'use strict';
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
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 { GitUri } from '../../git/gitUri';
import { HistoryView } from '../historyView';
import { CommandQuickPickItem, ReferencePicker } from '../../quickpicks';
import { RepositoriesView } from '../repositoriesView';
import { RepositoryNode } from './repositoryNode';
import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode';
import { Container } from '../../container';
import { debug, gate, log, Strings } from '../../system';
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 getId(repoPath: string, name: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${name})`;
@ -22,7 +23,12 @@ export class CompareBranchNode extends ViewNode {
private _children: ViewNode[] | 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);
const comparisons = Container.context.workspaceState.get<BranchComparisons>(WorkspaceState.BranchComparisons);

+ 1
- 25
src/views/repositoriesView.ts Visa fil

@ -8,13 +8,7 @@ import {
ProgressLocation,
window,
} from 'vscode';
import {
configuration,
RepositoriesViewConfig,
ViewBranchesLayout,
ViewFilesLayout,
ViewShowBranchComparison,
} from '../configuration';
import { configuration, RepositoriesViewConfig, ViewBranchesLayout, ViewFilesLayout } from '../configuration';
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { Container } from '../container';
import {
@ -30,7 +24,6 @@ import {
BranchesNode,
BranchNode,
BranchOrTagFolderNode,
CompareBranchNode,
RemoteNode,
RemotesNode,
RepositoriesNode,
@ -38,7 +31,6 @@ import {
StashesNode,
StashNode,
TagsNode,
ViewNode,
} from './nodes';
import { gate } from '../system';
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('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) {
@ -563,12 +545,6 @@ export class RepositoriesView extends ViewBase
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) {
return configuration.updateEffective('views', this.configKey, 'branches', 'layout', layout);
}

+ 18
- 1
src/views/viewCommands.ts Visa fil

@ -11,7 +11,7 @@ import {
OpenFileAtRevisionCommandArgs,
OpenFileOnRemoteCommandArgs,
} from '../commands';
import { FileAnnotationType } from '../config';
import { FileAnnotationType, ViewShowBranchComparison } from '../config';
import { BuiltInCommands, CommandContext, setCommandContext } from '../constants';
import { Container } from '../container';
import { GitReference, GitRevision } from '../git/git';
@ -156,6 +156,16 @@ export class ViewCommands {
n => this.setComparisonNotation(n, '...'),
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.createBranch', this.createBranch, this);
@ -430,6 +440,13 @@ export class ViewCommands {
}
@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: '...' | '..') {
if (!(node instanceof CompareResultsNode) && !(node instanceof CompareBranchNode)) return Promise.resolve();

Laddar…
Avbryt
Spara