Browse Source

Avoids unnecessary calls on opening details

main
Eric Amodio 2 years ago
parent
commit
52e76e1d7b
3 changed files with 26 additions and 21 deletions
  1. +17
    -11
      src/plus/webviews/graph/graphWebview.ts
  2. +1
    -1
      src/webviews/commitDetails/commitDetailsWebviewView.ts
  3. +8
    -9
      src/webviews/rebase/rebaseEditor.ts

+ 17
- 11
src/plus/webviews/graph/graphWebview.ts View File

@ -36,7 +36,6 @@ import { getContext, onDidChangeContext, setContext } from '../../../context';
import { PlusFeatures } from '../../../features';
import { GitSearchError } from '../../../git/errors';
import { getBranchNameWithoutRemote, getRemoteNameFromBranchName } from '../../../git/models/branch';
import type { GitCommit } from '../../../git/models/commit';
import { GitContributor } from '../../../git/models/contributor';
import { GitGraphRowType } from '../../../git/models/graph';
import type { GitGraph } from '../../../git/models/graph';
@ -140,7 +139,7 @@ export interface ShowInCommitGraphCommandArgs {
}
export interface GraphSelectionChangeEvent {
readonly selection: GitCommit[];
readonly selection: GitRevisionReference[];
}
const defaultGraphColumnsSettings: GraphColumnsSettings = {
@ -178,8 +177,8 @@ export class GraphWebview extends WebviewBase {
}
}
private _selection: readonly GitCommit[] | undefined;
get selection(): readonly GitCommit[] | undefined {
private _selection: readonly GitRevisionReference[] | undefined;
get selection(): readonly GitRevisionReference[] | undefined {
return this._selection;
}
@ -853,20 +852,27 @@ export class GraphWebview extends WebviewBase {
this._fireSelectionChangedDebounced = debounce(this.fireSelectionChanged.bind(this), 250);
}
void this._fireSelectionChangedDebounced(item?.id, item?.type);
this._fireSelectionChangedDebounced(item?.id, item?.type);
}
private async fireSelectionChanged(id: string | undefined, type: GitGraphRowType | undefined) {
let commits: GitCommit[] | undefined;
private fireSelectionChanged(id: string | undefined, type: GitGraphRowType | undefined) {
if (this.repository == null) return;
let commits: GitRevisionReference[] | undefined;
if (id != null) {
let commit;
if (type === GitGraphRowType.Stash) {
const stash = await this.repository?.getStash();
commit = stash?.commits.get(id);
commit = GitReference.create(id, this.repository.path, {
refType: 'stash',
name: id,
number: undefined,
});
// const stash = await this.repository?.getStash();
// commit = stash?.commits.get(id);
} else if (type === GitGraphRowType.Working) {
commit = await this.repository?.getCommit(GitRevision.uncommitted);
commit = GitReference.create(GitRevision.uncommitted, this.repository.path, { refType: 'revision' });
} else {
commit = await this.repository?.getCommit(id);
commit = GitReference.create(id, this.repository.path, { refType: 'revision' });
}
if (commit != null) {
commits = [commit];

+ 1
- 1
src/webviews/commitDetails/commitDetailsWebviewView.ts View File

@ -119,7 +119,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase
if (commit == null) {
commit = this.getBestCommitOrStash();
}
if (commit != null) {
if (commit != null && !this._context.commit?.ref.startsWith(commit.ref)) {
if (!isCommit(commit)) {
if (commit.refType === 'stash') {
const stash = await this.container.git.getStash(commit.repoPath);

+ 8
- 9
src/webviews/rebase/rebaseEditor.ts View File

@ -8,6 +8,7 @@ import { CoreCommands } from '../../constants';
import type { Container } from '../../container';
import { emojify } from '../../emojis';
import type { GitCommit } from '../../git/models/commit';
import { GitReference } from '../../git/models/reference';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../git/models/repository';
import { Logger } from '../../logger';
import { showRebaseSwitchToTextWarningMessage } from '../../messages';
@ -434,19 +435,17 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl
context.fireSelectionChangedDebounced = debounce(this.fireSelectionChanged.bind(this), 250);
}
void context.fireSelectionChangedDebounced(context, params.sha);
context.fireSelectionChangedDebounced(context, params.sha);
}
private async fireSelectionChanged(context: RebaseEditorContext, sha: string | undefined) {
let commit: GitCommit | undefined;
if (sha != null) {
commit = await this.container.git.getCommit(context.repoPath, sha);
}
if (commit == null) return;
private fireSelectionChanged(context: RebaseEditorContext, sha: string | undefined) {
if (sha == null) return;
const showDetailsView = configuration.get('rebaseEditor.showDetailsView');
void GitActions.Commit.showDetailsView(commit, {
// Find the full sha
sha = context.commits?.find(c => c.sha.startsWith(sha!))?.sha ?? sha;
void GitActions.Commit.showDetailsView(GitReference.create(sha, context.repoPath, { refType: 'revision' }), {
pin: false,
preserveFocus: true,
preserveVisibility: context.firstSelection ? showDetailsView === false : showDetailsView !== 'selection',

Loading…
Cancel
Save