Skip to content

Commit

Permalink
Move Git history view to SCM package
Browse files Browse the repository at this point in the history
Signed-off-by: Nigel Westbury <nigelipse@miegel.org>
  • Loading branch information
westbury committed Jan 5, 2020
1 parent ec2a866 commit 4a732e9
Show file tree
Hide file tree
Showing 42 changed files with 1,003 additions and 580 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ cache:
- packages/preview/node_modules
- packages/process/node_modules
- packages/python/node_modules
- packages/scm-extra/node_modules
- packages/scm/node_modules
- packages/search-in-workspace/node_modules
- packages/task/node_modules
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Breaking changes:
Before these attributes have to be computed for all nodes and stored as a part of the layout.
From now on they will be computed only on demand for visible nodes.
It decreases requirements to the local storage and allows to invalidate node appearance by simply rerendering a tree.
- [scm][git] the History view (GitHistoryWidget) has moved from the git package to a new package, scm-extra, and renamed to ScmHistoryWidget. GitNavigableListWidget has also moved. [6381](https://github.com/eclipse-theia/theia/pull/6381)

## v0.14.0

Expand Down
1 change: 1 addition & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@theia/process": "^0.14.0",
"@theia/python": "^0.14.0",
"@theia/scm": "^0.14.0",
"@theia/scm-extra": "^0.14.0",
"@theia/search-in-workspace": "^0.14.0",
"@theia/task": "^0.14.0",
"@theia/terminal": "^0.14.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/browser/test/left-panel/left-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ export class LeftPanel {
}

isGitHistoryContainerVisible(): boolean {
return (this.driver.isExisting('#git-history') && this.driver.element('#git-history').getAttribute('class').split(' ').indexOf('p-mod-hidden') === -1
return (this.driver.isExisting('#scm-history') && this.driver.element('#scm-history').getAttribute('class').split(' ').indexOf('p-mod-hidden') === -1
&& this.isPanelVisible());
}

waitForGitHistoryViewVisible(): void {
this.driver.waitForVisible('#git-history');
this.driver.waitForVisible('#scm-history');
// Wait for animations to finish
this.driver.pause(300);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/browser/test/top-panel/top-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class TopPanel {

toggleScmView(): void {
this.clickMenuTab('View');
this.clickSubMenu('SCM');
this.clickSubMenu('Source Control');
}

toggleGitHistoryView(): void {
this.clickMenuTab('View');
this.clickSubMenu('Git History');
this.clickSubMenu('Source History');
}

toggleOutlineView(): void {
Expand Down
2 changes: 2 additions & 0 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"@theia/preview": "^0.14.0",
"@theia/process": "^0.14.0",
"@theia/python": "^0.14.0",
"@theia/scm": "^0.14.0",
"@theia/scm-extra": "^0.14.0",
"@theia/search-in-workspace": "^0.14.0",
"@theia/task": "^0.14.0",
"@theia/terminal": "^0.14.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ export type ApplicationShellLayoutVersion =
/** layout versioning is introduced, unversiouned layout are not compatible */
2.0 |
/** view containers are introduced, backward compatible to 2.0 */
3.0;
3.0 |
/** git history view is replaced by a more generic scm history view, backward compatible to 3.0 */
4.0;

/**
* When a version is increased, make sure to introduce a migration (ApplicationShellLayoutMigration) to this version.
*/
export const applicationShellLayoutVersion: ApplicationShellLayoutVersion = 3.0;
export const applicationShellLayoutVersion: ApplicationShellLayoutVersion = 4.0;

export const ApplicationShellOptions = Symbol('ApplicationShellOptions');
export const DockPanelRendererFactory = Symbol('DockPanelRendererFactory');
Expand Down
1 change: 1 addition & 0 deletions packages/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@theia/languages": "^0.14.0",
"@theia/navigator": "^0.14.0",
"@theia/scm": "^0.14.0",
"@theia/scm-extra": "^0.14.0",
"@theia/workspace": "^0.14.0",
"@types/diff": "^3.2.2",
"@types/p-queue": "^2.3.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/git/src/browser/blame/blame-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BlameDecorator } from './blame-decorator';
import { EditorManager, EditorKeybindingContexts, EditorWidget, EditorTextFocusContext, StrictEditorTextFocusContext } from '@theia/editor/lib/browser';
import { BlameManager } from './blame-manager';
import URI from '@theia/core/lib/common/uri';
import { EDITOR_CONTEXT_MENU_GIT } from '../git-contribution';
import { EDITOR_CONTEXT_MENU_SCM } from '@theia/scm-extra/lib/browser/scm-extra-contribution';

import debounce = require('lodash.debounce');

Expand Down Expand Up @@ -136,7 +136,7 @@ export class BlameContribution implements CommandContribution, KeybindingContrib
}

registerMenus(menus: MenuModelRegistry): void {
menus.registerMenuAction(EDITOR_CONTEXT_MENU_GIT, {
menus.registerMenuAction(EDITOR_CONTEXT_MENU_SCM, {
commandId: BlameCommands.TOGGLE_GIT_ANNOTATIONS.id,
});
}
Expand Down
20 changes: 14 additions & 6 deletions packages/git/src/browser/diff/git-diff-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FrontendApplication, AbstractViewContribution } from '@theia/core/lib/b
import { WidgetManager } from '@theia/core/lib/browser/widget-manager';
import { injectable, inject } from 'inversify';
import { GitDiffWidget, GIT_DIFF } from './git-diff-widget';
import { ScmService } from '@theia/scm/lib/browser/scm-service';
import { open, OpenerService } from '@theia/core/lib/browser';
import { NavigatorContextMenu, FileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution';
import { UriCommandHandler } from '@theia/core/lib/common/uri-command-handler';
Expand All @@ -27,8 +28,7 @@ import { FileSystem } from '@theia/filesystem/lib/common';
import { DiffUris } from '@theia/core/lib/browser/diff-uris';
import URI from '@theia/core/lib/common/uri';
import { GIT_RESOURCE_SCHEME } from '../git-resource';
import { Git } from '../../common';
import { GitRepositoryProvider } from '../git-repository-provider';
import { Git, Repository } from '../../common';
import { WorkspaceRootUriAwareCommandHandler } from '@theia/workspace/lib/browser/workspace-commands';
import { WorkspaceService } from '@theia/workspace/lib/browser';
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
Expand Down Expand Up @@ -65,7 +65,7 @@ export class GitDiffContribution extends AbstractViewContribution<GitDiffWidget>
@inject(FileSystem) protected readonly fileSystem: FileSystem,
@inject(OpenerService) protected openerService: OpenerService,
@inject(MessageService) protected readonly notifications: MessageService,
@inject(GitRepositoryProvider) protected readonly repositoryProvider: GitRepositoryProvider
@inject(ScmService) protected readonly scmService: ScmService
) {
super({
widgetId: GIT_DIFF,
Expand All @@ -85,8 +85,8 @@ export class GitDiffContribution extends AbstractViewContribution<GitDiffWidget>

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(GitDiffCommands.OPEN_FILE_DIFF, this.newWorkspaceRootUriAwareCommandHandler({
isVisible: uri => !!this.repositoryProvider.findRepository(uri),
isEnabled: uri => !!this.repositoryProvider.findRepository(uri),
isVisible: uri => !!this.findGitRepository(uri),
isEnabled: uri => !!this.findGitRepository(uri),
execute: async fileUri => {
await this.quickOpenService.chooseTagsAndBranches(
async (fromRevision, toRevision) => {
Expand All @@ -112,7 +112,7 @@ export class GitDiffContribution extends AbstractViewContribution<GitDiffWidget>
}
}
}
}, this.repositoryProvider.findRepository(fileUri));
}, this.findGitRepository(fileUri));
}
}));
}
Expand All @@ -126,6 +126,14 @@ export class GitDiffContribution extends AbstractViewContribution<GitDiffWidget>
});
}

protected findGitRepository(uri: URI): Repository | undefined {
const repo = this.scmService.findRepository(uri);
if (repo && repo.provider.id === 'git') {
return { localUri: repo.provider.rootUri };
}
return undefined;
}

async showWidget(options: Git.Options.Diff): Promise<GitDiffWidget> {
const widget = await this.widget;
await widget.setContent(options);
Expand Down
82 changes: 51 additions & 31 deletions packages/git/src/browser/diff/git-diff-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@ import { inject, injectable, postConstruct } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { StatefulWidget, DiffUris, Message } from '@theia/core/lib/browser';
import { EditorManager, EditorOpenerOptions, EditorWidget, DiffNavigatorProvider, DiffNavigator } from '@theia/editor/lib/browser';
import { ScmRepository } from '@theia/scm/lib/browser/scm-repository';
import { ScmService } from '@theia/scm/lib/browser/scm-service';
import { GitFileChange, GitFileStatus, Git, WorkingDirectoryStatus } from '../../common';
import { GitScmProvider, GitScmFileChange } from '../git-scm-provider';
import { GitWatcher } from '../../common';
import { GIT_RESOURCE_SCHEME } from '../git-resource';
import { GitNavigableListWidget, GitItemComponent } from '../git-navigable-list-widget';
import { GitFileChangeNode } from '../git-file-change-node';
import { ScmNavigableListWidget, ScmItemComponent } from '@theia/scm-extra/lib/browser/scm-navigable-list-widget';
import { Deferred } from '@theia/core/lib/common/promise-util';
import { GitRepositoryProvider } from '../git-repository-provider';
import * as React from 'react';
import { MaybePromise } from '@theia/core/lib/common/types';
import { ScmFileChangeNode } from '@theia/scm-extra/lib/browser/scm-file-change-node';

// tslint:disable:no-null-keyword

type GitFileChangeNode = ScmFileChangeNode & { fileChange: GitScmFileChange };

export const GIT_DIFF = 'git-diff';
@injectable()
export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> implements StatefulWidget {
export class GitDiffWidget extends ScmNavigableListWidget<GitFileChangeNode> implements StatefulWidget {

protected readonly GIT_DIFF_TITLE = 'Diff';

Expand All @@ -45,9 +51,11 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp
protected deferredListContainer = new Deferred<HTMLElement>();

@inject(Git) protected readonly git: Git;
@inject(GitRepositoryProvider) protected readonly repositoryProvider: GitRepositoryProvider;
@inject(DiffNavigatorProvider) protected readonly diffNavigatorProvider: DiffNavigatorProvider;
@inject(EditorManager) protected readonly editorManager: EditorManager;
@inject(GitWatcher) protected readonly gitWatcher: GitWatcher;
@inject(ScmService) protected readonly sucmService: ScmService;

constructor() {
super();
Expand All @@ -69,7 +77,7 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp
}
}));
this.toDispose.push(this.labelProvider.onDidChange(event => {
const affectsFiles = this.fileChangeNodes.some(node => event.affects(new URI(node.uri)));
const affectsFiles = this.fileChangeNodes.some(node => event.affects(new URI(node.fileChange.uri)));
if (this.options && affectsFiles) {
this.setContent(this.options);
}
Expand All @@ -90,17 +98,29 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp

async setContent(options: Git.Options.Diff): Promise<void> {
this.options = options;
const repository = this.repositoryProvider.findRepositoryOrSelected(options);
if (repository) {
const fileChanges: GitFileChange[] = await this.git.diff(repository, {
const scmRepository = this.findRepositoryOrSelected(options.uri);
if (scmRepository && scmRepository.provider.id === 'git') {
const provider = scmRepository.provider as GitScmProvider;
const repository = { localUri: scmRepository.provider.rootUri };
const gitFileChanges = await this.git.diff(repository, {
range: options.range,
uri: options.uri
});
this.fileChangeNodes = fileChanges;
const scmFileChanges: GitFileChangeNode[] = gitFileChanges
.map(change => new GitScmFileChange(change, provider, options.range))
.map(fileChange => ({ fileChange, commitId: fileChange.gitFileChange.uri }));
this.fileChangeNodes = scmFileChanges;
this.update();
}
}

protected findRepositoryOrSelected(uri?: string): ScmRepository | undefined {
if (uri) {
return this.scmService.findRepository(new URI(uri));
}
return this.scmService.selectedRepository;
}

storeState(): object {
const { fileChangeNodes, options } = this;
return {
Expand All @@ -124,7 +144,7 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp
}

protected render(): React.ReactNode {
this.gitNodes = this.fileChangeNodes;
this.scmNodes = this.fileChangeNodes;
const commitishBar = this.renderDiffListHeader();
const fileChangeList = this.renderFileChangeList();
return <div className='git-diff-container'>{commitishBar}{fileChangeList}</div>;
Expand Down Expand Up @@ -159,7 +179,7 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp
}
protected renderPath(): React.ReactNode {
if (this.options.uri) {
const path = this.gitLabelProvider.relativePath(this.options.uri);
const path = this.scmLabelProvider.relativePath(this.options.uri);
if (path.length > 0) {
return '/' + path;
} else {
Expand Down Expand Up @@ -241,24 +261,24 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp
protected doAddGitDiffListKeyListeners(id: string): void {
const container = document.getElementById(id);
if (container) {
this.addGitListNavigationKeyListeners(container);
this.addListNavigationKeyListeners(container);
}
}

protected renderGitItem(change: GitFileChangeNode): React.ReactNode {
return <GitItemComponent key={change.uri.toString()} {...{
return <ScmItemComponent key={change.fileChange.uri.toString()} {...{
labelProvider: this.labelProvider,
gitLabelProvider: this.gitLabelProvider,
scmLabelProvider: this.scmLabelProvider,
change,
revealChange: () => this.revealChange(change),
revealChange: () => this.revealChange(change.fileChange.gitFileChange),
selectNode: () => this.selectNode(change)
}} />;
}

protected navigateRight(): void {
const selected = this.getSelected();
if (selected && GitFileChangeNode.is(selected)) {
const uri = this.getUriToOpen(selected);
if (selected) {
const uri = this.getUriToOpen(selected.fileChange.gitFileChange);
this.editorManager.getByUri(uri).then(widget => {
if (widget) {
const diffNavigator: DiffNavigator = this.diffNavigatorProvider(widget.editor);
Expand All @@ -269,19 +289,19 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp
this.openSelected();
}
} else {
this.revealChange(selected);
this.revealChange(selected.fileChange.gitFileChange);
}
});
} else if (this.gitNodes.length > 0) {
this.selectNode(this.gitNodes[0]);
} else if (this.scmNodes.length > 0) {
this.selectNode(this.scmNodes[0]);
this.openSelected();
}
}

protected navigateLeft(): void {
const selected = this.getSelected();
if (GitFileChangeNode.is(selected)) {
const uri = this.getUriToOpen(selected);
if (selected) {
const uri = this.getUriToOpen(selected.fileChange.gitFileChange);
this.editorManager.getByUri(uri).then(widget => {
if (widget) {
const diffNavigator: DiffNavigator = this.diffNavigatorProvider(widget.editor);
Expand All @@ -292,27 +312,27 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp
this.openSelected();
}
} else {
this.revealChange(selected);
this.revealChange(selected.fileChange.gitFileChange);
}
});
}
}

protected selectNextNode(): void {
const idx = this.indexOfSelected;
if (idx >= 0 && idx < this.gitNodes.length - 1) {
this.selectNode(this.gitNodes[idx + 1]);
} else if (this.gitNodes.length > 0 && (idx === -1 || idx === this.gitNodes.length - 1)) {
this.selectNode(this.gitNodes[0]);
if (idx >= 0 && idx < this.scmNodes.length - 1) {
this.selectNode(this.scmNodes[idx + 1]);
} else if (this.scmNodes.length > 0 && (idx === -1 || idx === this.scmNodes.length - 1)) {
this.selectNode(this.scmNodes[0]);
}
}

protected selectPreviousNode(): void {
const idx = this.indexOfSelected;
if (idx > 0) {
this.selectNode(this.gitNodes[idx - 1]);
this.selectNode(this.scmNodes[idx - 1]);
} else if (idx === 0) {
this.selectNode(this.gitNodes[this.gitNodes.length - 1]);
this.selectNode(this.scmNodes[this.scmNodes.length - 1]);
}
}

Expand All @@ -323,7 +343,7 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp
protected openSelected(): void {
const selected = this.getSelected();
if (selected) {
this.revealChange(selected);
this.revealChange(selected.fileChange.gitFileChange);
}
}

Expand Down Expand Up @@ -363,8 +383,8 @@ export class GitDiffWidget extends GitNavigableListWidget<GitFileChangeNode> imp

async openChanges(uri: URI, options?: EditorOpenerOptions): Promise<EditorWidget | undefined> {
const stringUri = uri.toString();
const change = this.fileChangeNodes.find(n => n.uri.toString() === stringUri);
return change && this.openChange(change, options);
const change = this.fileChangeNodes.find(n => n.fileChange.uri.toString() === stringUri);
return change && this.openChange(change.fileChange.gitFileChange, options);
}

openChange(change: GitFileChange, options?: EditorOpenerOptions): Promise<EditorWidget | undefined> {
Expand Down
4 changes: 1 addition & 3 deletions packages/git/src/browser/git-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import URI from '@theia/core/lib/common/uri';
import { Command, CommandContribution, CommandRegistry, DisposableCollection, MenuContribution, MenuModelRegistry, Mutable, MenuAction } from '@theia/core';
import { DiffUris, Widget } from '@theia/core/lib/browser';
import { TabBarToolbarContribution, TabBarToolbarRegistry, TabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { EDITOR_CONTEXT_MENU, EditorContextMenu, EditorManager, EditorOpenerOptions, EditorWidget } from '@theia/editor/lib/browser';
import { EditorContextMenu, EditorManager, EditorOpenerOptions, EditorWidget } from '@theia/editor/lib/browser';
import { Git, GitFileChange, GitFileStatus } from '../common';
import { GitRepositoryTracker } from './git-repository-tracker';
import { GitAction, GitQuickOpenService } from './git-quick-open-service';
Expand All @@ -33,8 +33,6 @@ import { GitPreferences } from './git-preferences';
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';

export const EDITOR_CONTEXT_MENU_GIT = [...EDITOR_CONTEXT_MENU, '3_git'];

export namespace GIT_COMMANDS {
export const CLONE = {
id: 'git.clone',
Expand Down
Loading

0 comments on commit 4a732e9

Please sign in to comment.