@@ -123,7 +123,6 @@ import { GitStatusParser } from '../../../git/parsers/statusParser';
123123import { GitTagParser } from '../../../git/parsers/tagParser' ;
124124import { GitTreeParser } from '../../../git/parsers/treeParser' ;
125125import { GitWorktreeParser } from '../../../git/parsers/worktreeParser' ;
126- import type { RemoteProviders } from '../../../git/remotes/remoteProviders' ;
127126import { getRemoteProviderMatcher , loadRemoteProviders } from '../../../git/remotes/remoteProviders' ;
128127import type { GitSearch , GitSearchResultData , GitSearchResults , SearchQuery } from '../../../git/search' ;
129128import { getGitArgsFromSearchQuery , getSearchQueryComparisonKey } from '../../../git/search' ;
@@ -239,6 +238,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
239238 private readonly _contributorsCache = new Map < string , Promise < GitContributor [ ] > > ( ) ;
240239 private readonly _mergeStatusCache = new Map < string , GitMergeStatus | null > ( ) ;
241240 private readonly _rebaseStatusCache = new Map < string , GitRebaseStatus | null > ( ) ;
241+ private readonly _remotesCache = new Map < string , Promise < GitRemote [ ] > > ( ) ;
242242 private readonly _repoInfoCache = new Map < string , RepositoryInfo > ( ) ;
243243 private readonly _stashesCache = new Map < string , GitStash | null > ( ) ;
244244 private readonly _tagsCache = new Map < string , Promise < PagedResult < GitTag > > > ( ) ;
@@ -253,6 +253,11 @@ export class LocalGitProvider implements GitProvider, Disposable {
253253 this . git . setLocator ( this . ensureGit . bind ( this ) ) ;
254254
255255 this . _disposables . push (
256+ configuration . onDidChange ( e => {
257+ if ( configuration . changed ( e , 'remotes' ) ) {
258+ this . resetCaches ( 'remotes' ) ;
259+ }
260+ } , this ) ,
256261 this . container . events . on ( 'git:cache:reset' , e =>
257262 e . data . repoPath
258263 ? this . resetCache ( e . data . repoPath , ...( e . data . caches ?? emptyArray ) )
@@ -280,6 +285,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
280285 this . _contributorsCache . delete ( `stats|${ repo . path } ` ) ;
281286 }
282287
288+ if ( e . changed ( RepositoryChange . Remotes , RepositoryChange . RemoteProviders , RepositoryChangeComparisonMode . Any ) ) {
289+ this . _remotesCache . delete ( repo . path ) ;
290+ }
291+
283292 if ( e . changed ( RepositoryChange . Index , RepositoryChange . Unknown , RepositoryChangeComparisonMode . Any ) ) {
284293 this . _trackedPaths . clear ( ) ;
285294 }
@@ -1069,6 +1078,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
10691078 this . _contributorsCache . delete ( repoPath ) ;
10701079 }
10711080
1081+ if ( caches . length === 0 || caches . includes ( 'remotes' ) ) {
1082+ this . _remotesCache . delete ( repoPath ) ;
1083+ }
1084+
10721085 if ( caches . length === 0 || caches . includes ( 'stashes' ) ) {
10731086 this . _stashesCache . delete ( repoPath ) ;
10741087 }
@@ -1098,6 +1111,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
10981111 this . _contributorsCache . clear ( ) ;
10991112 }
11001113
1114+ if ( caches . length === 0 || caches . includes ( 'remotes' ) ) {
1115+ this . _remotesCache . clear ( ) ;
1116+ }
1117+
11011118 if ( caches . length === 0 || caches . includes ( 'stashes' ) ) {
11021119 this . _stashesCache . clear ( ) ;
11031120 }
@@ -3989,28 +4006,46 @@ export class LocalGitProvider implements GitProvider, Disposable {
39894006 }
39904007
39914008 @log ( { args : { 1 : false } } )
3992- async getRemotes (
3993- repoPath : string | undefined ,
3994- options ?: { providers ?: RemoteProviders ; sort ?: boolean } ,
3995- ) : Promise < GitRemote [ ] > {
4009+ async getRemotes ( repoPath : string | undefined , options ?: { sort ?: boolean } ) : Promise < GitRemote [ ] > {
39964010 if ( repoPath == null ) return [ ] ;
39974011
3998- const providers = options ?. providers ?? loadRemoteProviders ( configuration . get ( 'remotes' , null ) ) ;
4012+ let remotesPromise = this . useCaching ? this . _remotesCache . get ( repoPath ) : undefined ;
4013+ if ( remotesPromise == null ) {
4014+ async function load ( this : LocalGitProvider ) : Promise < GitRemote [ ] > {
4015+ const providers = loadRemoteProviders (
4016+ configuration . get ( 'remotes' , this . container . git . getRepository ( repoPath ! ) ?. folder ?. uri ?? null ) ,
4017+ ) ;
39994018
4000- try {
4001- const data = await this . git . remote ( repoPath ) ;
4002- const remotes = GitRemoteParser . parse ( data , repoPath , getRemoteProviderMatcher ( this . container , providers ) ) ;
4003- if ( remotes == null ) return [ ] ;
4019+ try {
4020+ const data = await this . git . remote ( repoPath ! ) ;
4021+ const remotes = GitRemoteParser . parse (
4022+ data ,
4023+ repoPath ! ,
4024+ getRemoteProviderMatcher ( this . container , providers ) ,
4025+ ) ;
4026+ if ( remotes == null ) return [ ] ;
40044027
4005- if ( options ?. sort ) {
4006- GitRemote . sort ( remotes ) ;
4028+ return remotes ;
4029+ } catch ( ex ) {
4030+ this . _remotesCache . delete ( repoPath ! ) ;
4031+ Logger . error ( ex ) ;
4032+ return [ ] ;
4033+ }
40074034 }
40084035
4009- return remotes ;
4010- } catch ( ex ) {
4011- Logger . error ( ex ) ;
4012- return [ ] ;
4036+ remotesPromise = load . call ( this ) ;
4037+
4038+ if ( this . useCaching ) {
4039+ this . _remotesCache . set ( repoPath , remotesPromise ) ;
4040+ }
4041+ }
4042+
4043+ const remotes = await remotesPromise ;
4044+ if ( options ?. sort ) {
4045+ GitRemote . sort ( remotes ) ;
40134046 }
4047+
4048+ return remotes ;
40144049 }
40154050
40164051 @gate ( )
0 commit comments