diff options
author | Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> | 2022-11-10 23:25:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 23:25:53 +0300 |
commit | 8fd500ed74c0fcec7f416a3614516bfce0fcb3ab (patch) | |
tree | 42f11e40b8c31aca03ee640b69decdf395a9ae54 | |
parent | 0308afcc5c3e3f0a03c6bd158a09712d7cb4d7b8 (diff) |
Git - Add calcellation support for getRefs (#165938)
-rw-r--r-- | extensions/git/src/git.ts | 27 | ||||
-rw-r--r-- | extensions/git/src/repository.ts | 26 |
2 files changed, 35 insertions, 18 deletions
diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 5a7660aa6d5..667e9a001f7 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -198,7 +198,7 @@ async function exec(child: cp.ChildProcess, cancellationToken?: CancellationToke } if (cancellationToken && cancellationToken.isCancellationRequested) { - throw new GitError({ message: 'Cancelled' }); + throw new CancellationError(); } const disposables: IDisposable[] = []; @@ -239,7 +239,7 @@ async function exec(child: cp.ChildProcess, cancellationToken?: CancellationToke // noop } - e(new GitError({ message: 'Cancelled' })); + e(new CancellationError()); }); }); @@ -568,12 +568,21 @@ export class Git { } const startExec = Date.now(); - const bufferResult = await exec(child, options.cancellationToken); - const durExec = Date.now() - startExec; + let bufferResult: IExecutionResult<Buffer>; + + try { + bufferResult = await exec(child, options.cancellationToken); + } catch (ex) { + if (ex instanceof CancellationError) { + this.log(`> git ${args.join(' ')} [${Date.now() - startExec}ms] (cancelled)\n`); + } + + throw ex; + } if (options.log !== false) { // command - this.log(`> git ${args.join(' ')} [${durExec}ms]\n`); + this.log(`> git ${args.join(' ')} [${Date.now() - startExec}ms]\n`); // stdout if (bufferResult.stdout.length > 0 && args.find(a => this.commandsToLog.includes(a))) { @@ -2119,7 +2128,11 @@ export class Repository { .map(([ref]) => ({ name: ref, type: RefType.Head } as Branch)); } - async getRefs(opts?: { sort?: 'alphabetically' | 'committerdate'; contains?: string; pattern?: string; count?: number }): Promise<Ref[]> { + async getRefs(opts?: { sort?: 'alphabetically' | 'committerdate'; contains?: string; pattern?: string; count?: number; cancellationToken?: CancellationToken }): Promise<Ref[]> { + if (opts?.cancellationToken && opts?.cancellationToken.isCancellationRequested) { + throw new CancellationError(); + } + const args = ['for-each-ref']; if (opts?.count) { @@ -2140,7 +2153,7 @@ export class Repository { args.push('--contains', opts.contains); } - const result = await this.exec(args); + const result = await this.exec(args, { cancellationToken: opts?.cancellationToken }); const fn = (line: string): Ref | null => { let match: RegExpExecArray | null; diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 2647cd3fb46..8c5464b6aa8 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -2059,16 +2059,9 @@ export class Repository implements Disposable { this._updateResourceGroupsState(optimisticResourcesGroups); } - const config = workspace.getConfiguration('git'); - let sort = config.get<'alphabetically' | 'committerdate'>('branchSortOrder') || 'alphabetically'; - if (sort !== 'alphabetically' && sort !== 'committerdate') { - sort = 'alphabetically'; - } - - const [HEAD, refs, remotes, submodules, rebaseCommit, mergeInProgress, commitTemplate] = + const [HEAD, remotes, submodules, rebaseCommit, mergeInProgress, commitTemplate] = await Promise.all([ this.repository.getHEADBranch(), - this.repository.getRefs({ sort }), this.repository.getRemotes(), this.repository.getSubmodules(), this.getRebaseCommit(), @@ -2076,7 +2069,6 @@ export class Repository implements Disposable { this.getInputTemplate()]); this._HEAD = HEAD; - this._refs = refs!; this._remotes = remotes!; this._submodules = submodules!; this.rebaseCommit = rebaseCommit; @@ -2084,8 +2076,20 @@ export class Repository implements Disposable { this._sourceControl.commitTemplate = commitTemplate; - // Update resource states based on status data - this._updateResourceGroupsState(await this.getStatus(cancellationToken)); + // Execute cancellable long-running operations + const config = workspace.getConfiguration('git'); + let sort = config.get<'alphabetically' | 'committerdate'>('branchSortOrder') || 'alphabetically'; + if (sort !== 'alphabetically' && sort !== 'committerdate') { + sort = 'alphabetically'; + } + + const [resourceGroups, refs] = + await Promise.all([ + this.getStatus(cancellationToken), + this.repository.getRefs({ sort, cancellationToken })]); + + this._refs = refs!; + this._updateResourceGroupsState(resourceGroups); this._onDidChangeStatus.fire(); } |