Skip to content

Commit

Permalink
Fixes #776 - Open Rev when in file/line history
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jul 9, 2019
1 parent a642958 commit c5c7254
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 84 deletions.
26 changes: 21 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,11 @@
{
"command": "gitlens.views.openFileRevision",
"title": "Open Revision",
"category": "GitLens"
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-open-file.svg",
"light": "images/light/icon-open-file.svg"
}
},
{
"command": "gitlens.views.openFileRevisionInRemote",
Expand Down Expand Up @@ -4401,7 +4405,7 @@
},
{
"command": "gitlens.copyMessageToClipboard",
"when": "viewItem =~ /gitlens:(commit|stash|file:commit)\\b/",
"when": "viewItem =~ /gitlens:(commit|stash|file\\b.*?\\+committed\\b.*?)\\b/",
"group": "5_gitlens@2"
},
{
Expand Down Expand Up @@ -4446,9 +4450,21 @@
},
{
"command": "gitlens.views.openFile",
"when": "viewItem =~ /gitlens:(file|history:(file|line)|status:file)\\b/",
"when": "viewItem =~ /gitlens:(history:(file|line)|status:file)\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.openFile",
"when": "viewItem =~ /gitlens:file\\b(?!.*?\\+history\\b.*?)/",
"group": "inline@1",
"alt": "gitlens.views.openFileRevision"
},
{
"command": "gitlens.views.openFileRevision",
"when": "viewItem =~ /gitlens:file\\b.*?\\+history\\b.*?/",
"group": "inline@1",
"alt": "gitlens.views.openFile"
},
{
"command": "gitlens.views.stageFile",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*?\\+unstaged\\b.*?/",
Expand Down Expand Up @@ -4496,7 +4512,7 @@
},
{
"command": "gitlens.views.openFileRevision",
"when": "viewItem =~ /gitlens:file\\b/",
"when": "viewItem =~ /gitlens:file\\b.*?\\+committed\\b.*?/",
"group": "3_gitlens@2"
},
{
Expand All @@ -4517,7 +4533,7 @@
},
{
"command": "gitlens.views.openFileRevisionInRemote",
"when": "viewItem == gitlens:file:commit && gitlens:hasRemotes",
"when": "viewItem =~ /gitlens:file\\b.*?\\+committed\\b.*?/ && gitlens:hasRemotes",
"group": "4_gitlens@2"
},
{
Expand Down
68 changes: 25 additions & 43 deletions src/views/nodes/commitFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,13 @@ import { CommitFormatter, GitFile, GitLogCommit, GitUri, StatusFileFormatter } f
import { View } from '../viewBase';
import { ResourceType, ViewNode, ViewRefFileNode } from './viewNode';

export enum CommitFileNodeDisplayAs {
CommitLabel = 1 << 0,
FileLabel = 1 << 1,

CommitIcon = 1 << 2,
StatusIcon = 1 << 3,
Gravatar = 1 << 4,

File = FileLabel | StatusIcon
}

export class CommitFileNode extends ViewRefFileNode {
constructor(
view: View,
parent: ViewNode,
public readonly file: GitFile,
public commit: GitLogCommit,
private readonly _displayAs: CommitFileNodeDisplayAs,
private readonly _selection?: Selection
private readonly _options: { displayAsCommit?: boolean; inFileHistory?: boolean; selection?: Selection } = {}
) {
super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent);
}
Expand Down Expand Up @@ -70,22 +58,16 @@ export class CommitFileNode extends ViewRefFileNode {
item.description = this.description;
item.tooltip = this.tooltip;

if ((this._displayAs & CommitFileNodeDisplayAs.CommitIcon) === CommitFileNodeDisplayAs.CommitIcon) {
item.iconPath = {
dark: Container.context.asAbsolutePath(paths.join('images', 'dark', 'icon-commit.svg')),
light: Container.context.asAbsolutePath(paths.join('images', 'light', 'icon-commit.svg'))
};
if (this._options.displayAsCommit && this.view.config.avatars) {
item.iconPath = this.commit.getGravatarUri(Container.config.defaultGravatarsStyle);
}
else if ((this._displayAs & CommitFileNodeDisplayAs.StatusIcon) === CommitFileNodeDisplayAs.StatusIcon) {
else {
const icon = GitFile.getStatusIcon(this.file.status);
item.iconPath = {
dark: Container.context.asAbsolutePath(paths.join('images', 'dark', icon)),
light: Container.context.asAbsolutePath(paths.join('images', 'light', icon))
};
}
else if ((this._displayAs & CommitFileNodeDisplayAs.Gravatar) === CommitFileNodeDisplayAs.Gravatar) {
item.iconPath = this.commit.getGravatarUri(Container.config.defaultGravatarsStyle);
}

item.command = this.getCommand();

Expand All @@ -100,15 +82,14 @@ export class CommitFileNode extends ViewRefFileNode {
private _description: string | undefined;
get description() {
if (this._description === undefined) {
this._description =
this._displayAs & CommitFileNodeDisplayAs.CommitLabel
? CommitFormatter.fromTemplate(this.getCommitDescriptionTemplate(), this.commit, {
truncateMessageAtNewLine: true,
dateFormat: Container.config.defaultDateFormat
})
: StatusFileFormatter.fromTemplate(this.getCommitFileDescriptionTemplate(), this.file, {
relativePath: this.relativePath
});
this._description = this._options.displayAsCommit
? CommitFormatter.fromTemplate(this.getCommitDescriptionTemplate(), this.commit, {
truncateMessageAtNewLine: true,
dateFormat: Container.config.defaultDateFormat
})
: StatusFileFormatter.fromTemplate(this.getCommitFileDescriptionTemplate(), this.file, {
relativePath: this.relativePath
});
}
return this._description;
}
Expand All @@ -124,15 +105,14 @@ export class CommitFileNode extends ViewRefFileNode {
private _label: string | undefined;
get label() {
if (this._label === undefined) {
this._label =
this._displayAs & CommitFileNodeDisplayAs.CommitLabel
? CommitFormatter.fromTemplate(this.getCommitTemplate(), this.commit, {
truncateMessageAtNewLine: true,
dateFormat: Container.config.defaultDateFormat
})
: StatusFileFormatter.fromTemplate(this.getCommitFileTemplate(), this.file, {
relativePath: this.relativePath
});
this._label = this._options.displayAsCommit
? CommitFormatter.fromTemplate(this.getCommitTemplate(), this.commit, {
truncateMessageAtNewLine: true,
dateFormat: Container.config.defaultDateFormat
})
: StatusFileFormatter.fromTemplate(this.getCommitFileTemplate(), this.file, {
relativePath: this.relativePath
});
}
return this._label;
}
Expand All @@ -148,15 +128,17 @@ export class CommitFileNode extends ViewRefFileNode {
}

protected get resourceType(): string {
if (!this.commit.isUncommitted) return ResourceType.CommitFile;
if (!this.commit.isUncommitted) {
return `${ResourceType.File}+committed${this._options.inFileHistory ? '+history' : ''}`;
}

return this.commit.isUncommittedStaged ? `${ResourceType.File}+staged` : `${ResourceType.File}+unstaged`;
}

private _tooltip: string | undefined;
get tooltip() {
if (this._tooltip === undefined) {
if (this._displayAs & CommitFileNodeDisplayAs.CommitLabel) {
if (this._options.displayAsCommit) {
// eslint-disable-next-line no-template-curly-in-string
const status = StatusFileFormatter.fromTemplate('${status}${ (originalPath)}', this.file);
this._tooltip = CommitFormatter.fromTemplate(
Expand Down Expand Up @@ -208,7 +190,7 @@ export class CommitFileNode extends ViewRefFileNode {
line = this.commit.line.to.line - 1;
}
else {
line = this._selection !== undefined ? this._selection.active.line : 0;
line = this._options.selection !== undefined ? this._options.selection.active.line : 0;
}

const commandArgs: DiffWithPreviousCommandArgs = {
Expand Down
7 changes: 2 additions & 5 deletions src/views/nodes/commitNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Container } from '../../container';
import { CommitFormatter, GitBranch, GitLogCommit } from '../../git/gitService';
import { Arrays, Iterables, Strings } from '../../system';
import { ViewWithFiles } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { FileNode, FolderNode } from './folderNode';
import { ResourceType, ViewNode, ViewRefNode } from './viewNode';

Expand All @@ -30,10 +30,7 @@ export class CommitNode extends ViewRefNode<ViewWithFiles> {
async getChildren(): Promise<ViewNode[]> {
const commit = this.commit;
let children: FileNode[] = [
...Iterables.map(
commit.files,
s => new CommitFileNode(this.view, this, s, commit.toFileCommit(s), CommitFileNodeDisplayAs.File)
)
...Iterables.map(commit.files, s => new CommitFileNode(this.view, this, s, commit.toFileCommit(s)))
];

if (this.view.config.files.layout !== ViewFilesLayout.List) {
Expand Down
16 changes: 9 additions & 7 deletions src/views/nodes/fileHistoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { Logger } from '../../logger';
import { debug, Iterables } from '../../system';
import { View } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { MessageNode, ShowMoreNode } from './common';
import { insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';
Expand All @@ -29,10 +29,6 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
async getChildren(): Promise<ViewNode[]> {
const children: ViewNode[] = [];

const displayAs =
CommitFileNodeDisplayAs.CommitLabel |
(this.view.config.avatars ? CommitFileNodeDisplayAs.Gravatar : CommitFileNodeDisplayAs.StatusIcon);

if (this.uri.sha === undefined) {
const status = await Container.git.getStatusForFile(this.uri.repoPath!, this.uri.fsPath);
if (status !== undefined && (status.indexStatus !== undefined || status.workingTreeStatus !== undefined)) {
Expand Down Expand Up @@ -69,7 +65,9 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
previousSha,
status.originalFileName || status.fileName
);
children.push(new CommitFileNode(this.view, this, status, commit, displayAs));
children.push(
new CommitFileNode(this.view, this, status, commit, { displayAsCommit: true, inFileHistory: true })
);
}
}

Expand All @@ -82,7 +80,11 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitFileNode(this.view, this, c.files[0], c, displayAs)
c =>
new CommitFileNode(this.view, this, c.files[0], c, {
displayAsCommit: true,
inFileHistory: true
})
),
this
)
Expand Down
23 changes: 16 additions & 7 deletions src/views/nodes/lineHistoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { Logger } from '../../logger';
import { debug, Iterables } from '../../system';
import { View } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { MessageNode, ShowMoreNode } from './common';
import { insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';
Expand All @@ -34,10 +34,6 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
async getChildren(): Promise<ViewNode[]> {
const children: ViewNode[] = [];

const displayAs =
CommitFileNodeDisplayAs.CommitLabel |
(this.view.config.avatars ? CommitFileNodeDisplayAs.Gravatar : CommitFileNodeDisplayAs.StatusIcon);

let selection = this.selection;

if (this.uri.sha === undefined) {
Expand Down Expand Up @@ -87,7 +83,15 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
selection.active.character
);

children.splice(0, 0, new CommitFileNode(this.view, this, file, uncommitted, displayAs, selection));
children.splice(
0,
0,
new CommitFileNode(this.view, this, file, uncommitted, {
displayAsCommit: true,
inFileHistory: true,
selection: selection
})
);

break;
}
Expand All @@ -104,7 +108,12 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
...insertDateMarkers(
Iterables.filterMap(
log.commits.values(),
c => new CommitFileNode(this.view, this, c.files[0], c, displayAs, selection)
c =>
new CommitFileNode(this.view, this, c.files[0], c, {
displayAsCommit: true,
inFileHistory: true,
selection: selection
})
),
this
)
Expand Down
4 changes: 2 additions & 2 deletions src/views/nodes/stashFileNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
import { GitFile, GitLogCommit } from '../../git/gitService';
import { View } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { ResourceType, ViewNode } from './viewNode';

export class StashFileNode extends CommitFileNode {
constructor(view: View, parent: ViewNode, file: GitFile, commit: GitLogCommit) {
super(view, parent, file, commit, CommitFileNodeDisplayAs.File);
super(view, parent, file, commit);
}

protected get resourceType(): ResourceType {
Expand Down
16 changes: 2 additions & 14 deletions src/views/nodes/statusFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Container } from '../../container';
import { GitFile, GitLogCommit, GitUri, StatusFileFormatter } from '../../git/gitService';
import { Strings } from '../../system';
import { View } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { ResourceType, ViewNode } from './viewNode';

export class StatusFileNode extends ViewNode {
Expand Down Expand Up @@ -56,19 +56,7 @@ export class StatusFileNode extends ViewNode {
}

getChildren(): ViewNode[] {
return this.commits.map(
c =>
new CommitFileNode(
this.view,
this,
this.file,
c,
CommitFileNodeDisplayAs.CommitLabel |
(this.view.config.avatars
? CommitFileNodeDisplayAs.Gravatar
: CommitFileNodeDisplayAs.CommitIcon)
)
);
return this.commits.map(c => new CommitFileNode(this.view, this, this.file, c, { displayAsCommit: true }));
}

getTreeItem(): TreeItem {
Expand Down
1 change: 0 additions & 1 deletion src/views/nodes/viewNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export enum ResourceType {
BranchStatusAheadOfUpstream = 'gitlens:branch-status:upstream:ahead',
BranchStatusBehindUpstream = 'gitlens:branch-status:upstream:behind',
Commit = 'gitlens:commit',
CommitFile = 'gitlens:file:commit',
Commits = 'gitlens:commits',
Compare = 'gitlens:compare',
CompareBranch = 'gitlens:compare:branch',
Expand Down

0 comments on commit c5c7254

Please sign in to comment.