@@ -68,16 +68,6 @@ class UnsafeRepositoryMap extends RepositoryMap<string> {
68
68
}
69
69
}
70
70
71
- /**
72
- * Key - normalized path used in user interface
73
- * Value - value indicating whether the repository should be opened
74
- */
75
- class ParentRepositoryMap extends RepositoryMap {
76
- updateContextKey ( ) : void {
77
- commands . executeCommand ( 'setContext' , 'git.parentRepositoryCount' , this . size ) ;
78
- }
79
- }
80
-
81
71
export interface ModelChangeEvent {
82
72
repository : Repository ;
83
73
uri : Uri ;
@@ -128,6 +118,47 @@ class ClosedRepositoriesManager {
128
118
}
129
119
}
130
120
121
+ class ParentRepositoriesManager {
122
+
123
+ /**
124
+ * Key - normalized path used in user interface
125
+ * Value - value indicating whether the repository should be opened
126
+ */
127
+ private _repositories = new Set < string > ;
128
+ get repositories ( ) : string [ ] {
129
+ return [ ...this . _repositories . values ( ) ] ;
130
+ }
131
+
132
+ constructor ( private readonly globalState : Memento ) { }
133
+
134
+ addRepository ( repository : string ) : void {
135
+ this . _repositories . add ( repository ) ;
136
+ this . onDidChangeRepositories ( ) ;
137
+ }
138
+
139
+ deleteRepository ( repository : string ) : boolean {
140
+ const result = this . _repositories . delete ( repository ) ;
141
+ if ( result ) {
142
+ this . onDidChangeRepositories ( ) ;
143
+ }
144
+
145
+ return result ;
146
+ }
147
+
148
+ hasRepository ( repository : string ) : boolean {
149
+ return this . _repositories . has ( repository ) ;
150
+ }
151
+
152
+ openRepository ( repository : string ) : void {
153
+ this . globalState . update ( `parentRepository:${ repository } ` , true ) ;
154
+ this . deleteRepository ( repository ) ;
155
+ }
156
+
157
+ private onDidChangeRepositories ( ) : void {
158
+ commands . executeCommand ( 'setContext' , 'git.parentRepositoryCount' , this . _repositories . size ) ;
159
+ }
160
+ }
161
+
131
162
export class Model implements IBranchProtectionProviderRegistry , IRemoteSourcePublisherRegistry , IPostCommitCommandsProviderRegistry , IPushErrorHandlerRegistry {
132
163
133
164
private _onDidOpenRepository = new EventEmitter < Repository > ( ) ;
@@ -200,9 +231,9 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
200
231
return this . _unsafeRepositories ;
201
232
}
202
233
203
- private _parentRepositories = new ParentRepositoryMap ( ) ;
204
- get parentRepositories ( ) : ParentRepositoryMap {
205
- return this . _parentRepositories ;
234
+ private _parentRepositoriesManager : ParentRepositoriesManager ;
235
+ get parentRepositories ( ) : string [ ] {
236
+ return this . _parentRepositoriesManager . repositories ;
206
237
}
207
238
208
239
private _closedRepositoriesManager : ClosedRepositoriesManager ;
@@ -225,6 +256,7 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
225
256
constructor ( readonly git : Git , private readonly askpass : Askpass , private globalState : Memento , readonly workspaceState : Memento , private logger : LogOutputChannel , private telemetryReporter : TelemetryReporter ) {
226
257
// Repositories managers
227
258
this . _closedRepositoriesManager = new ClosedRepositoriesManager ( workspaceState ) ;
259
+ this . _parentRepositoriesManager = new ParentRepositoriesManager ( globalState ) ;
228
260
229
261
workspace . onDidChangeWorkspaceFolders ( this . onDidChangeWorkspaceFolders , this , this . disposables ) ;
230
262
window . onDidChangeVisibleTextEditors ( this . onDidChangeVisibleTextEditors , this , this . disposables ) ;
@@ -260,7 +292,7 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
260
292
await initialScanFn ( ) ;
261
293
}
262
294
263
- if ( this . _parentRepositories . size !== 0 &&
295
+ if ( this . parentRepositories . length !== 0 &&
264
296
parentRepositoryConfig === 'prompt' ) {
265
297
// Parent repositories notification
266
298
this . showParentRepositoryNotification ( ) ;
@@ -497,13 +529,13 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
497
529
if ( isRepositoryOutsideWorkspace ) {
498
530
this . logger . trace ( `Repository in parent folder: ${ repositoryRoot } ` ) ;
499
531
500
- if ( ! this . _parentRepositories . has ( repositoryRoot ) ) {
532
+ if ( ! this . _parentRepositoriesManager . hasRepository ( repositoryRoot ) ) {
501
533
// Show a notification if the parent repository is opened after the initial scan
502
534
if ( this . state === 'initialized' && parentRepositoryConfig === 'prompt' ) {
503
535
this . showParentRepositoryNotification ( ) ;
504
536
}
505
537
506
- this . _parentRepositories . set ( repositoryRoot ) ;
538
+ this . _parentRepositoriesManager . addRepository ( repositoryRoot ) ;
507
539
}
508
540
509
541
return ;
@@ -547,11 +579,8 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
547
579
}
548
580
549
581
async openParentRepository ( repoPath : string ) : Promise < void > {
550
- // Mark the repository to be opened from the parent folders
551
- this . globalState . update ( `parentRepository:${ repoPath } ` , true ) ;
552
-
553
582
await this . openRepository ( repoPath ) ;
554
- this . parentRepositories . delete ( repoPath ) ;
583
+ this . _parentRepositoriesManager . openRepository ( repoPath ) ;
555
584
}
556
585
557
586
private async getRepositoryRoot ( repoPath : string ) : Promise < { repositoryRoot : string ; unsafeRepositoryMatch : RegExpMatchArray | null } > {
@@ -907,7 +936,7 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
907
936
}
908
937
909
938
private async showParentRepositoryNotification ( ) : Promise < void > {
910
- const message = this . parentRepositories . size === 1 ?
939
+ const message = this . parentRepositories . length === 1 ?
911
940
l10n . t ( 'A git repository was found in the parent folders of the workspace or the open file(s). Would you like to open the repository?' ) :
912
941
l10n . t ( 'Git repositories were found in the parent folders of the workspace or the open file(s). Would you like to open the repositories?' ) ;
913
942
@@ -925,7 +954,7 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
925
954
await config . update ( 'openRepositoryInParentFolders' , choice === always ? 'always' : 'never' , true ) ;
926
955
927
956
if ( choice === always ) {
928
- for ( const parentRepository of [ ... this . parentRepositories . keys ( ) ] ) {
957
+ for ( const parentRepository of this . parentRepositories ) {
929
958
await this . openParentRepository ( parentRepository ) ;
930
959
}
931
960
}
0 commit comments