Skip to content

Commit

Permalink
Avoids unnecessary calls on opening details
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 7, 2022
1 parent 176c2a7 commit 52e76e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
28 changes: 17 additions & 11 deletions src/plus/webviews/graph/graphWebview.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -140,7 +139,7 @@ export interface ShowInCommitGraphCommandArgs {
}

export interface GraphSelectionChangeEvent {
readonly selection: GitCommit[];
readonly selection: GitRevisionReference[];
}

const defaultGraphColumnsSettings: GraphColumnsSettings = {
Expand Down Expand Up @@ -178,8 +177,8 @@ export class GraphWebview extends WebviewBase<State> {
}
}

private _selection: readonly GitCommit[] | undefined;
get selection(): readonly GitCommit[] | undefined {
private _selection: readonly GitRevisionReference[] | undefined;
get selection(): readonly GitRevisionReference[] | undefined {
return this._selection;
}

Expand Down Expand Up @@ -853,20 +852,27 @@ export class GraphWebview extends WebviewBase<State> {
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];
Expand Down
2 changes: 1 addition & 1 deletion src/webviews/commitDetails/commitDetailsWebviewView.ts
Expand Up @@ -119,7 +119,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
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);
Expand Down
17 changes: 8 additions & 9 deletions src/webviews/rebase/rebaseEditor.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 52e76e1

Please sign in to comment.