Skip to content

Commit 28b55a7

Browse files
authored
SCM - add cancellation token to history provider (microsoft#249808)
1 parent fd23e62 commit 28b55a7

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

extensions/git/src/git.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,8 @@ export class Repository {
12821282
});
12831283
}
12841284

1285-
async log(options?: LogOptions): Promise<Commit[]> {
1286-
const spawnOptions: SpawnOptions = {};
1285+
async log(options?: LogOptions, cancellationToken?: CancellationToken): Promise<Commit[]> {
1286+
const spawnOptions: SpawnOptions = { cancellationToken };
12871287
const args = ['log', `--format=${COMMIT_FORMAT}`, '-z'];
12881288

12891289
if (options?.shortStats) {

extensions/git/src/historyProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66

7-
import { Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, LogOutputChannel, SourceControlHistoryItemRef, l10n, SourceControlHistoryItemRefsChangeEvent, workspace, ConfigurationChangeEvent } from 'vscode';
7+
import { CancellationToken, Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, LogOutputChannel, SourceControlHistoryItemRef, l10n, SourceControlHistoryItemRefsChangeEvent, workspace, ConfigurationChangeEvent } from 'vscode';
88
import { Repository, Resource } from './repository';
99
import { IDisposable, deltaHistoryItemRefs, dispose, filterEvent, truncate } from './util';
1010
import { toMultiFileDiffEditorUris } from './uri';
@@ -234,7 +234,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
234234
return [...branches, ...remoteBranches, ...tags];
235235
}
236236

237-
async provideHistoryItems(options: SourceControlHistoryOptions): Promise<SourceControlHistoryItem[]> {
237+
async provideHistoryItems(options: SourceControlHistoryOptions, token: CancellationToken): Promise<SourceControlHistoryItem[]> {
238238
if (!this.currentHistoryItemRef || !options.historyItemRefs) {
239239
return [];
240240
}
@@ -259,7 +259,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
259259
logOptions = { ...logOptions, skip: options.skip };
260260
}
261261

262-
const commits = await this.repository.log({ ...logOptions, silent: true });
262+
const commits = await this.repository.log({ ...logOptions, silent: true }, token);
263263

264264
// Avatars
265265
const avatarQuery = {

extensions/git/src/repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,9 @@ export class Repository implements Disposable {
11001100
return this.run(Operation.Config(false), () => this.repository.config('unset', 'local', key));
11011101
}
11021102

1103-
log(options?: LogOptions & { silent?: boolean }): Promise<Commit[]> {
1103+
log(options?: LogOptions & { silent?: boolean }, cancellationToken?: CancellationToken): Promise<Commit[]> {
11041104
const showProgress = !options || options.silent !== true;
1105-
return this.run(Operation.Log(showProgress), () => this.repository.log(options));
1105+
return this.run(Operation.Log(showProgress), () => this.repository.log(options, cancellationToken));
11061106
}
11071107

11081108
logFile(uri: Uri, options?: LogFileOptions, cancellationToken?: CancellationToken): Promise<Commit[]> {

src/vs/workbench/api/browser/mainThreadSCM.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,26 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
195195

196196
constructor(private readonly proxy: ExtHostSCMShape, private readonly handle: number) { }
197197

198-
async resolveHistoryItemChatContext(historyItemId: string): Promise<string | undefined> {
199-
return this.proxy.$resolveHistoryItemChatContext(this.handle, historyItemId, CancellationToken.None);
198+
async resolveHistoryItemChatContext(historyItemId: string, token?: CancellationToken): Promise<string | undefined> {
199+
return this.proxy.$resolveHistoryItemChatContext(this.handle, historyItemId, token ?? CancellationToken.None);
200200
}
201201

202-
async resolveHistoryItemRefsCommonAncestor(historyItemRefs: string[]): Promise<string | undefined> {
203-
return this.proxy.$resolveHistoryItemRefsCommonAncestor(this.handle, historyItemRefs, CancellationToken.None);
202+
async resolveHistoryItemRefsCommonAncestor(historyItemRefs: string[], token: CancellationToken): Promise<string | undefined> {
203+
return this.proxy.$resolveHistoryItemRefsCommonAncestor(this.handle, historyItemRefs, token ?? CancellationToken.None);
204204
}
205205

206-
async provideHistoryItemRefs(historyItemsRefs?: string[]): Promise<ISCMHistoryItemRef[] | undefined> {
207-
const historyItemRefs = await this.proxy.$provideHistoryItemRefs(this.handle, historyItemsRefs, CancellationToken.None);
206+
async provideHistoryItemRefs(historyItemsRefs?: string[], token?: CancellationToken): Promise<ISCMHistoryItemRef[] | undefined> {
207+
const historyItemRefs = await this.proxy.$provideHistoryItemRefs(this.handle, historyItemsRefs, token ?? CancellationToken.None);
208208
return historyItemRefs?.map(ref => ({ ...ref, icon: getIconFromIconDto(ref.icon) }));
209209
}
210210

211-
async provideHistoryItems(options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined> {
212-
const historyItems = await this.proxy.$provideHistoryItems(this.handle, options, CancellationToken.None);
211+
async provideHistoryItems(options: ISCMHistoryOptions, token?: CancellationToken): Promise<ISCMHistoryItem[] | undefined> {
212+
const historyItems = await this.proxy.$provideHistoryItems(this.handle, options, token ?? CancellationToken.None);
213213
return historyItems?.map(historyItem => toISCMHistoryItem(historyItem));
214214
}
215215

216-
async provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined): Promise<ISCMHistoryItemChange[] | undefined> {
217-
const changes = await this.proxy.$provideHistoryItemChanges(this.handle, historyItemId, historyItemParentId, CancellationToken.None);
216+
async provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined, token?: CancellationToken): Promise<ISCMHistoryItemChange[] | undefined> {
217+
const changes = await this.proxy.$provideHistoryItemChanges(this.handle, historyItemId, historyItemParentId, token ?? CancellationToken.None);
218218
return changes?.map(change => ({
219219
uri: URI.revive(change.uri),
220220
originalUri: change.originalUri && URI.revive(change.originalUri),

src/vs/workbench/contrib/scm/common/history.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { CancellationToken } from '../../../../base/common/cancellation.js';
67
import { IObservable } from '../../../../base/common/observable.js';
78
import { ThemeIcon } from '../../../../base/common/themables.js';
89
import { URI } from '../../../../base/common/uri.js';
@@ -21,11 +22,11 @@ export interface ISCMHistoryProvider {
2122

2223
readonly historyItemRefChanges: IObservable<ISCMHistoryItemRefsChangeEvent>;
2324

24-
provideHistoryItemRefs(historyItemsRefs?: string[]): Promise<ISCMHistoryItemRef[] | undefined>;
25-
provideHistoryItems(options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined>;
26-
provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined): Promise<ISCMHistoryItemChange[] | undefined>;
27-
resolveHistoryItemChatContext(historyItemId: string): Promise<string | undefined>;
28-
resolveHistoryItemRefsCommonAncestor(historyItemRefs: string[]): Promise<string | undefined>;
25+
provideHistoryItemRefs(historyItemsRefs?: string[], token?: CancellationToken): Promise<ISCMHistoryItemRef[] | undefined>;
26+
provideHistoryItems(options: ISCMHistoryOptions, token?: CancellationToken): Promise<ISCMHistoryItem[] | undefined>;
27+
provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined, token?: CancellationToken): Promise<ISCMHistoryItemChange[] | undefined>;
28+
resolveHistoryItemChatContext(historyItemId: string, token?: CancellationToken): Promise<string | undefined>;
29+
resolveHistoryItemRefsCommonAncestor(historyItemRefs: string[], token?: CancellationToken): Promise<string | undefined>;
2930
}
3031

3132
export interface ISCMHistoryOptions {

0 commit comments

Comments
 (0)