Skip to content

Commit

Permalink
Ensures isDiscoveringRepositories covers initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Oct 31, 2023
1 parent d421ae7 commit 79ed7a9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/git/gitProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { count, filter, first, flatMap, join, map, some } from '../system/iterab
import { Logger } from '../system/logger';
import { getLogScope, setLogScopeExit } from '../system/logger.scope';
import { getBestPath, getScheme, isAbsolute, maybeUri, normalizePath } from '../system/path';
import type { Deferred } from '../system/promise';
import { asSettled, cancellable, defer, getSettledValue, isPromise, PromiseCancelledError } from '../system/promise';
import { sortCompare } from '../system/string';
import { VisitedPathsTrie } from '../system/trie';
Expand Down Expand Up @@ -212,12 +213,14 @@ export class GitProviderService implements Disposable {
Promise<GitRemote<RemoteProvider | RichRemoteProvider>[]>
>();
private readonly _disposable: Disposable;
private _initializingDeferred: Deferred<number> | undefined;
private readonly _pendingRepositories = new Map<RepoComparisonKey, Promise<Repository | undefined>>();
private readonly _providers = new Map<GitProviderId, GitProvider>();
private readonly _repositories = new Repositories();
private readonly _visitedPaths = new VisitedPathsTrie();

constructor(private readonly container: Container) {
this._initializingDeferred = defer<number>();
this._disposable = Disposable.from(
container.subscription.onDidChange(this.onSubscriptionChanged, this),
window.onDidChangeWindowState(this.onWindowStateChanged, this),
Expand Down Expand Up @@ -615,7 +618,7 @@ export class GitProviderService implements Disposable {
this._isDiscoveringRepositories = undefined;
}

const deferred = defer<number>();
const deferred = this._initializingDeferred ?? defer<number>();
this._isDiscoveringRepositories = deferred.promise;

try {
Expand Down Expand Up @@ -657,7 +660,12 @@ export class GitProviderService implements Disposable {
queueMicrotask(() => this.fireRepositoriesChanged(added));
}
} finally {
queueMicrotask(() => deferred.fulfill(this._etag));
queueMicrotask(() => {
deferred.fulfill(this._etag);
if (this._initializingDeferred != null) {
this._initializingDeferred = undefined;
}
});
}
}

Expand Down

0 comments on commit 79ed7a9

Please sign in to comment.