From 67d977c676f6650604f0b42347734c39401eb919 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 22 Jan 2022 01:44:30 -0500 Subject: [PATCH] Avoids re-looking up remotes Cleans up overloads --- src/env/node/git/localGitProvider.ts | 38 ++++++++++-------------------------- src/git/gitProvider.ts | 11 ++--------- src/git/gitProviderService.ts | 14 +++++++++---- 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index e438007..7392a00 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -66,8 +66,6 @@ import { GitTag, GitTreeEntry, GitUser, - PullRequest, - PullRequestState, Repository, RepositoryChange, RepositoryChangeComparisonMode, @@ -92,7 +90,7 @@ import { RemoteProvider, RichRemoteProvider } from '../../../git/remotes/provide import { SearchPattern } from '../../../git/search'; import { LogCorrelationContext, Logger } from '../../../logger'; import { Messages } from '../../../messages'; -import { Arrays, debug, Functions, gate, Iterables, log, Promises, Strings, Versions } from '../../../system'; +import { Arrays, debug, Functions, gate, Iterables, log, Strings, Versions } from '../../../system'; import { isFolderGlob, normalizePath, splitPath } from '../../../system/path'; import { any, PromiseOrValue } from '../../../system/promise'; import { @@ -2807,33 +2805,19 @@ export class LocalGitProvider implements GitProvider, Disposable { }; } - async getRichRemoteProvider( - repoPath: string | undefined, - options?: { includeDisconnected?: boolean }, - ): Promise | undefined>; - async getRichRemoteProvider( - remotes: GitRemote[], - options?: { includeDisconnected?: boolean }, - ): Promise | undefined>; @gate( - (remotesOrRepoPath, options) => - `${typeof remotesOrRepoPath === 'string' ? remotesOrRepoPath : remotesOrRepoPath[0]?.repoPath}:${ - options?.includeDisconnected ?? false - }`, + (repoPath, remotes, options) => + `${repoPath}|${remotes?.map(r => r.id).join(',') ?? ''}|${options?.includeDisconnected ?? false}`, ) - @log({ - args: { - 0: remotesOrRepoPath => - Array.isArray(remotesOrRepoPath) ? remotesOrRepoPath.map(r => r.name).join(',') : remotesOrRepoPath, - }, - }) + @log({ args: { 1: remotes => remotes?.map(r => r.name).join(',') } }) async getRichRemoteProvider( - remotesOrRepoPath: GitRemote[] | string | undefined, - options?: { includeDisconnected?: boolean }, + repoPath: string, + remotes: GitRemote[] | undefined, + options?: { includeDisconnected?: boolean | undefined }, ): Promise | undefined> { - if (remotesOrRepoPath == null) return undefined; + if (repoPath == null) return undefined; - const cacheKey = typeof remotesOrRepoPath === 'string' ? remotesOrRepoPath : remotesOrRepoPath[0]?.repoPath; + const cacheKey = repoPath; let richRemote = this._remotesWithApiProviderCache.get(cacheKey); if (richRemote != null) return richRemote; @@ -2844,9 +2828,7 @@ export class LocalGitProvider implements GitProvider, Disposable { if (richRemote !== undefined) return richRemote ?? undefined; } - const remotes = ( - typeof remotesOrRepoPath === 'string' ? await this.getRemotes(remotesOrRepoPath) : remotesOrRepoPath - ).filter( + remotes = (remotes ?? (await this.getRemotes(repoPath))).filter( ( r: GitRemote, ): r is GitRemote => r.provider != null, diff --git a/src/git/gitProvider.ts b/src/git/gitProvider.ts index 0cf73f2..071b5b3 100644 --- a/src/git/gitProvider.ts +++ b/src/git/gitProvider.ts @@ -308,15 +308,8 @@ export interface GitProvider { }, ): Promise; getRichRemoteProvider( - repoPath: string | undefined, - options?: { includeDisconnected?: boolean | undefined }, - ): Promise | undefined>; - getRichRemoteProvider( - remotes: GitRemote[], - options?: { includeDisconnected?: boolean | undefined }, - ): Promise | undefined>; - getRichRemoteProvider( - remotesOrRepoPath: string | GitRemote[] | undefined, + repoPath: string, + remotes: GitRemote[] | undefined, options?: { includeDisconnected?: boolean | undefined }, ): Promise | undefined>; getRemotes( diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 326131e..2b888bf 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -1402,9 +1402,13 @@ export class GitProviderService implements Disposable { ): Promise | undefined>; @gate( (remotesOrRepoPath, options) => - `${typeof remotesOrRepoPath === 'string' ? remotesOrRepoPath : remotesOrRepoPath[0]?.repoPath}:${ - options?.includeDisconnected ?? false - }`, + `${ + remotesOrRepoPath == null || typeof remotesOrRepoPath === 'string' + ? remotesOrRepoPath + : remotesOrRepoPath instanceof Uri + ? remotesOrRepoPath.toString() + : `${remotesOrRepoPath[0]?.repoPath}|${remotesOrRepoPath?.map(r => r.id).join(',') ?? ''}` + }|${options?.includeDisconnected ?? false}`, ) @log({ args: { @@ -1418,14 +1422,16 @@ export class GitProviderService implements Disposable { ): Promise | undefined> { if (remotesOrRepoPath == null) return undefined; + let remotes; if (Array.isArray(remotesOrRepoPath)) { if (remotesOrRepoPath.length === 0) return undefined; + remotes = remotesOrRepoPath; remotesOrRepoPath = remotesOrRepoPath[0].repoPath; } const { provider, path } = this.getProvider(remotesOrRepoPath); - return provider.getRichRemoteProvider(path, options); + return provider.getRichRemoteProvider(path, remotes, options); } @log()