Browse Source

Avoids re-looking up remotes

Cleans up overloads
main
Eric Amodio 2 years ago
parent
commit
67d977c676
3 changed files with 22 additions and 41 deletions
  1. +10
    -28
      src/env/node/git/localGitProvider.ts
  2. +2
    -9
      src/git/gitProvider.ts
  3. +10
    -4
      src/git/gitProviderService.ts

+ 10
- 28
src/env/node/git/localGitProvider.ts View File

@ -66,8 +66,6 @@ import {
GitTag, GitTag,
GitTreeEntry, GitTreeEntry,
GitUser, GitUser,
PullRequest,
PullRequestState,
Repository, Repository,
RepositoryChange, RepositoryChange,
RepositoryChangeComparisonMode, RepositoryChangeComparisonMode,
@ -92,7 +90,7 @@ import { RemoteProvider, RichRemoteProvider } from '../../../git/remotes/provide
import { SearchPattern } from '../../../git/search'; import { SearchPattern } from '../../../git/search';
import { LogCorrelationContext, Logger } from '../../../logger'; import { LogCorrelationContext, Logger } from '../../../logger';
import { Messages } from '../../../messages'; 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 { isFolderGlob, normalizePath, splitPath } from '../../../system/path';
import { any, PromiseOrValue } from '../../../system/promise'; import { any, PromiseOrValue } from '../../../system/promise';
import { import {
@ -2807,33 +2805,19 @@ export class LocalGitProvider implements GitProvider, Disposable {
}; };
} }
async getRichRemoteProvider(
repoPath: string | undefined,
options?: { includeDisconnected?: boolean },
): Promise<GitRemote<RichRemoteProvider> | undefined>;
async getRichRemoteProvider(
remotes: GitRemote[],
options?: { includeDisconnected?: boolean },
): Promise<GitRemote<RichRemoteProvider> | undefined>;
@gate<LocalGitProvider['getRichRemoteProvider']>( @gate<LocalGitProvider['getRichRemoteProvider']>(
(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<LocalGitProvider['getRichRemoteProvider']>({
args: {
0: remotesOrRepoPath =>
Array.isArray(remotesOrRepoPath) ? remotesOrRepoPath.map(r => r.name).join(',') : remotesOrRepoPath,
},
})
@log<LocalGitProvider['getRichRemoteProvider']>({ args: { 1: remotes => remotes?.map(r => r.name).join(',') } })
async getRichRemoteProvider( async getRichRemoteProvider(
remotesOrRepoPath: GitRemote[] | string | undefined,
options?: { includeDisconnected?: boolean },
repoPath: string,
remotes: GitRemote<RemoteProvider | RichRemoteProvider | undefined>[] | undefined,
options?: { includeDisconnected?: boolean | undefined },
): Promise<GitRemote<RichRemoteProvider> | undefined> { ): Promise<GitRemote<RichRemoteProvider> | 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); let richRemote = this._remotesWithApiProviderCache.get(cacheKey);
if (richRemote != null) return richRemote; if (richRemote != null) return richRemote;
@ -2844,9 +2828,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
if (richRemote !== undefined) return richRemote ?? undefined; 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<RemoteProvider | RichRemoteProvider | undefined>, r: GitRemote<RemoteProvider | RichRemoteProvider | undefined>,
): r is GitRemote<RemoteProvider | RichRemoteProvider> => r.provider != null, ): r is GitRemote<RemoteProvider | RichRemoteProvider> => r.provider != null,

+ 2
- 9
src/git/gitProvider.ts View File

@ -308,15 +308,8 @@ export interface GitProvider {
}, },
): Promise<GitReflog | undefined>; ): Promise<GitReflog | undefined>;
getRichRemoteProvider( getRichRemoteProvider(
repoPath: string | undefined,
options?: { includeDisconnected?: boolean | undefined },
): Promise<GitRemote<RichRemoteProvider> | undefined>;
getRichRemoteProvider(
remotes: GitRemote<RemoteProvider | RichRemoteProvider | undefined>[],
options?: { includeDisconnected?: boolean | undefined },
): Promise<GitRemote<RichRemoteProvider> | undefined>;
getRichRemoteProvider(
remotesOrRepoPath: string | GitRemote<RemoteProvider | RichRemoteProvider | undefined>[] | undefined,
repoPath: string,
remotes: GitRemote<RemoteProvider | RichRemoteProvider | undefined>[] | undefined,
options?: { includeDisconnected?: boolean | undefined }, options?: { includeDisconnected?: boolean | undefined },
): Promise<GitRemote<RichRemoteProvider> | undefined>; ): Promise<GitRemote<RichRemoteProvider> | undefined>;
getRemotes( getRemotes(

+ 10
- 4
src/git/gitProviderService.ts View File

@ -1402,9 +1402,13 @@ export class GitProviderService implements Disposable {
): Promise<GitRemote<RichRemoteProvider> | undefined>; ): Promise<GitRemote<RichRemoteProvider> | undefined>;
@gate<GitProviderService['getRichRemoteProvider']>( @gate<GitProviderService['getRichRemoteProvider']>(
(remotesOrRepoPath, options) => (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<GitProviderService['getRichRemoteProvider']>({ @log<GitProviderService['getRichRemoteProvider']>({
args: { args: {
@ -1418,14 +1422,16 @@ export class GitProviderService implements Disposable {
): Promise<GitRemote<RichRemoteProvider> | undefined> { ): Promise<GitRemote<RichRemoteProvider> | undefined> {
if (remotesOrRepoPath == null) return undefined; if (remotesOrRepoPath == null) return undefined;
let remotes;
if (Array.isArray(remotesOrRepoPath)) { if (Array.isArray(remotesOrRepoPath)) {
if (remotesOrRepoPath.length === 0) return undefined; if (remotesOrRepoPath.length === 0) return undefined;
remotes = remotesOrRepoPath;
remotesOrRepoPath = remotesOrRepoPath[0].repoPath; remotesOrRepoPath = remotesOrRepoPath[0].repoPath;
} }
const { provider, path } = this.getProvider(remotesOrRepoPath); const { provider, path } = this.getProvider(remotesOrRepoPath);
return provider.getRichRemoteProvider(path, options);
return provider.getRichRemoteProvider(path, remotes, options);
} }
@log() @log()

Loading…
Cancel
Save