Skip to content

Commit baba59f

Browse files
Adds discovered/found repos to local path map (#3633)
* Adds discovered/found repos to local path map * Move to function, add gating and queue as microtask * Tightens output typing * Removes unneeded variable * Improvements * Tweaks --------- Co-authored-by: Eric Amodio <[email protected]>
1 parent cd18a59 commit baba59f

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

src/git/gitProviderService.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,11 @@ export class GitProviderService implements Disposable {
653653
this.updateContext();
654654

655655
if (added.length) {
656-
// Defer the event trigger enough to let everything unwind
657-
queueMicrotask(() => this.fireRepositoriesChanged(added));
656+
queueMicrotask(() => {
657+
void this.addRepositoriesToPathMap(added);
658+
// Defer the event trigger enough to let everything unwind
659+
this.fireRepositoriesChanged(added);
660+
});
658661
}
659662
} finally {
660663
queueMicrotask(() => {
@@ -2425,8 +2428,11 @@ export class GitProviderService implements Disposable {
24252428
this.updateContext();
24262429

24272430
if (added.length) {
2428-
// Send a notification that the repositories changed
2429-
queueMicrotask(() => this.fireRepositoriesChanged(added));
2431+
queueMicrotask(() => {
2432+
void this.addRepositoriesToPathMap(added);
2433+
// Send a notification that the repositories changed
2434+
this.fireRepositoriesChanged(added);
2435+
});
24302436
}
24312437

24322438
repository = repositories.length === 1 ? repositories[0] : this.getRepository(uri);
@@ -2440,6 +2446,19 @@ export class GitProviderService implements Disposable {
24402446
return promise;
24412447
}
24422448

2449+
@gate()
2450+
@log()
2451+
async addRepositoriesToPathMap(repos: Repository[]): Promise<void> {
2452+
const scope = getLogScope();
2453+
for (const repo of repos) {
2454+
try {
2455+
await this.container.repositoryIdentity.addRepositoryToPathMap(repo);
2456+
} catch (ex) {
2457+
Logger.error(ex, scope);
2458+
}
2459+
}
2460+
}
2461+
24432462
@log()
24442463
async getOrOpenRepositoryForEditor(editor?: TextEditor): Promise<Repository | undefined> {
24452464
editor = editor ?? window.activeTextEditor;

src/plus/repos/repositoryIdentityService.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import type { Container } from '../../container';
44
import { RemoteResourceType } from '../../git/models/remoteResource';
55
import type { Repository } from '../../git/models/repository';
66
import { parseGitRemoteUrl } from '../../git/parsers/remoteParser';
7-
import type { GkProviderId, RepositoryIdentityDescriptor } from '../../gk/models/repositoryIdentities';
7+
import type {
8+
GkProviderId,
9+
RepositoryIdentityDescriptor,
10+
RepositoryIdentityProviderDescriptor,
11+
} from '../../gk/models/repositoryIdentities';
812
import { missingRepositoryId } from '../../gk/models/repositoryIdentities';
913
import { log } from '../../system/decorators/log';
14+
import { getSettledValue } from '../../system/promise';
1015
import type { ServerConnection } from '../gk/serverConnection';
1116

1217
export class RepositoryIdentityService implements Disposable {
@@ -25,6 +30,23 @@ export class RepositoryIdentityService implements Disposable {
2530
return this.locateRepository(identity, options);
2631
}
2732

33+
async getRepositoryIdentity<T extends string | GkProviderId>(
34+
repository: Repository,
35+
): Promise<RepositoryIdentityDescriptor<T>> {
36+
const [bestRemotePromise, initialCommitShaPromise] = await Promise.allSettled([
37+
this.container.git.getBestRemoteWithProvider(repository.uri),
38+
this.container.git.getFirstCommitSha(repository.uri),
39+
]);
40+
const bestRemote = getSettledValue(bestRemotePromise);
41+
42+
return {
43+
name: repository.name,
44+
initialCommitSha: getSettledValue(initialCommitShaPromise),
45+
remote: bestRemote,
46+
provider: bestRemote?.provider?.providerDesc as RepositoryIdentityProviderDescriptor<T>,
47+
};
48+
}
49+
2850
@log()
2951
private async locateRepository<T extends string | GkProviderId>(
3052
identity: RepositoryIdentityDescriptor<T>,
@@ -132,20 +154,29 @@ export class RepositoryIdentityService implements Disposable {
132154
(await this.container.git.validateReference(locatedRepo.uri, identity.initialCommitSha))
133155
) {
134156
foundRepo = locatedRepo;
135-
await this.addFoundRepositoryToMap(foundRepo, identity);
157+
await this.addRepositoryToPathMap(foundRepo, identity);
136158
}
137159
}
138160

139161
return foundRepo;
140162
}
141163

142-
private async addFoundRepositoryToMap<T extends string | GkProviderId>(
164+
async addRepositoryToPathMap<T extends string | GkProviderId>(
143165
repo: Repository,
144166
identity?: RepositoryIdentityDescriptor<T>,
145167
) {
168+
if (repo.virtual) return;
169+
170+
const [identityResult, remotesResult] = await Promise.allSettled([
171+
identity == null ? this.getRepositoryIdentity<T>(repo) : undefined,
172+
repo.git.getRemotes(),
173+
]);
174+
175+
identity ??= getSettledValue(identityResult);
176+
const remotes = getSettledValue(remotesResult) ?? [];
177+
146178
const repoPath = repo.uri.fsPath;
147179

148-
const remotes = await repo.git.getRemotes();
149180
for (const remote of remotes) {
150181
const remoteUrl = remote.provider?.url({ type: RemoteResourceType.Repo });
151182
if (remoteUrl != null) {

0 commit comments

Comments
 (0)