瀏覽代碼

Times out waiting for built-in Git on startup

main
Eric Amodio 3 年之前
父節點
當前提交
00ac0bb879
共有 2 個檔案被更改,包括 57 行新增27 行删除
  1. +53
    -23
      src/git/providers/localGitProvider.ts
  2. +4
    -4
      src/system/promise.ts

+ 53
- 23
src/git/providers/localGitProvider.ts 查看文件

@ -180,45 +180,70 @@ export class LocalGitProvider implements GitProvider, Disposable {
@log()
private async findGit(): Promise<GitLocation> {
const cc = Logger.getCorrelationContext();
if (!configuration.getAny<boolean>('git.enabled', null, true)) {
Logger.log('Built-in Git is disabled ("git.enabled": false)');
Logger.log(cc, 'Built-in Git is disabled ("git.enabled": false)');
void Messages.showGitDisabledErrorMessage();
throw new UnableToFindGitError();
}
// Try to use the same git as the built-in vscode git extension
const gitApi = await this.getScmGitApi();
if (gitApi != null) {
this.container.context.subscriptions.push(
const scmPromise = this.getScmGitApi();
// Try to use the same git as the built-in vscode git extension, but only wait for a bit
const timeout = 100;
let gitPath;
try {
const gitApi = await Promises.cancellable(scmPromise, timeout);
gitPath = gitApi?.git.path;
} catch {
Logger.log(cc, `Stopped waiting for built-in Git, after ${timeout} ms...`);
}
async function subscribeToScmOpenCloseRepository(
container: Container,
apiPromise: Promise<BuiltInGitApi | undefined>,
) {
const gitApi = await apiPromise;
if (gitApi == null) return;
container.context.subscriptions.push(
gitApi.onDidCloseRepository(e => {
const repository = this.container.git.getCachedRepository(Strings.normalizePath(e.rootUri.fsPath));
const repository = container.git.getCachedRepository(Strings.normalizePath(e.rootUri.fsPath));
if (repository != null) {
repository.closed = true;
}
}),
gitApi.onDidOpenRepository(e => {
const repository = this.container.git.getCachedRepository(Strings.normalizePath(e.rootUri.fsPath));
const repository = container.git.getCachedRepository(Strings.normalizePath(e.rootUri.fsPath));
if (repository != null) {
repository.closed = false;
}
}),
);
}
const gitPath = gitApi?.git.path ?? configuration.getAny<string | string[]>('git.path');
void subscribeToScmOpenCloseRepository(this.container, scmPromise);
const start = process.hrtime();
const location = await findGitPath(gitPath);
Logger.log(
`Git found: ${location.version} @ ${location.path === 'git' ? 'PATH' : location.path} ${
GlyphChars.Dot
} ${Strings.getDurationMilliseconds(start)} ms`,
);
const location = await findGitPath(gitPath ?? configuration.getAny<string | string[]>('git.path'));
if (cc != null) {
cc.exitDetails = ` ${GlyphChars.Dot} Git found (${Strings.getDurationMilliseconds(start)} ms): ${
location.version
} @ ${location.path === 'git' ? 'PATH' : location.path}`;
} else {
Logger.log(
cc,
`Git found: ${location.version} @ ${location.path === 'git' ? 'PATH' : location.path} ${
GlyphChars.Dot
} ${Strings.getDurationMilliseconds(start)} ms`,
);
}
// Warn if git is less than v2.7.2
if (Versions.compare(Versions.fromString(location.version), Versions.fromString('2.7.2')) === -1) {
Logger.log(`Git version (${location.version}) is outdated`);
Logger.log(cc, `Git version (${location.version}) is outdated`);
void Messages.showGitVersionUnsupportedErrorMessage(location.version, '2.7.2');
}
@ -3732,17 +3757,22 @@ export class LocalGitProvider implements GitProvider, Disposable {
});
}
@log()
private _scmGitApi: Promise<BuiltInGitApi | undefined> | undefined;
private async getScmGitApi(): Promise<BuiltInGitApi | undefined> {
return this._scmGitApi ?? (this._scmGitApi = this.getScmGitApiCore());
}
@log()
private async getScmGitApiCore(): Promise<BuiltInGitApi | undefined> {
try {
const extension = extensions.getExtension<GitExtension>('vscode.git');
if (extension != null) {
const gitExtension = extension.isActive ? extension.exports : await extension.activate();
return gitExtension.getAPI(1);
}
} catch {}
if (extension == null) return undefined;
return undefined;
const gitExtension = extension.isActive ? extension.exports : await extension.activate();
return gitExtension?.getAPI(1);
} catch {
return undefined;
}
}
@log()

+ 4
- 4
src/system/promise.ts 查看文件

@ -2,14 +2,14 @@
import { CancellationToken } from 'vscode';
import { map } from './iterable';
export class CancellationError<TPromise = any> extends Error {
constructor(public readonly promise: TPromise, message: string) {
export class CancellationError<T extends Promise<="na">any class="p">>n> ass="o">= Promise<any>> extends Error {
constructor(public readonly promise: T, message: string) {
super(message);
}
}
export class CancellationErrorWithId<T, TPromise = any> extends CancellationError<TPromise> {
constructor(public readonly id: T, promise: TPromise, message: string) {
export class CancellationErrorWithId<TKey, T extends Promise class="err"><any> = Promisean><any>> extends CancellationError<T> {
constructor(public readonly id: TKey, promise: T, message: string) {
super(promise, message);
}
}

Loading…
取消
儲存