@@ -8,22 +8,34 @@ import { RepositoryFileSystemProvider } from './repositoryFileSystemProvider';
88import { GitApiImpl } from '../api/api1' ;
99import { fromGitHubCommitUri } from '../common/uri' ;
1010import { CredentialStore } from '../github/credentials' ;
11+ import { GitHubRepository } from '../github/githubRepository' ;
1112import { RepositoriesManager } from '../github/repositoriesManager' ;
1213
1314export class GitHubCommitFileSystemProvider extends RepositoryFileSystemProvider {
15+ private readonly _gitHubRepositories = new Map < string , GitHubRepository > ( ) ;
16+
1417 constructor ( private readonly repos : RepositoriesManager , gitAPI : GitApiImpl , credentialStore : CredentialStore ) {
1518 super ( gitAPI , credentialStore ) ;
1619 }
1720
21+ registerGitHubRepository ( repository : GitHubRepository ) : void {
22+ this . _gitHubRepositories . set ( this . repositoryKey ( repository . remote . owner , repository . remote . repositoryName ) , repository ) ;
23+ }
24+
1825 override async readFile ( uri : vscode . Uri ) : Promise < Uint8Array > {
1926 await this . waitForAuth ( ) ;
20- await this . waitForAnyGitHubRepos ( this . repos ) ;
2127
2228 const params = fromGitHubCommitUri ( uri ) ;
2329 if ( ! params ) {
2430 throw new Error ( `Invalid GitHub commit URI: ${ uri . toString ( ) } ` ) ;
2531 }
2632
33+ const registeredRepository = this . _gitHubRepositories . get ( this . repositoryKey ( params . owner , params . repo ) ) ;
34+ if ( registeredRepository ) {
35+ return registeredRepository . getFile ( uri . path , params . commit ) ;
36+ }
37+
38+ await this . waitForAnyGitHubRepos ( this . repos ) ;
2739 const folderManager = this . repos . getManagerForRepository ( params . owner , params . repo ) ;
2840 if ( ! folderManager ) {
2941 throw new Error ( `Repository not found for owner: ${ params . owner } , repo: ${ params . repo } ` ) ;
@@ -36,4 +48,17 @@ export class GitHubCommitFileSystemProvider extends RepositoryFileSystemProvider
3648
3749 return githubRepo . getFile ( uri . path , params . commit ) ;
3850 }
51+
52+ private repositoryKey ( owner : string , repo : string ) : string {
53+ return `${ owner . toLowerCase ( ) } /${ repo . toLowerCase ( ) } ` ;
54+ }
55+ }
56+
57+ let githubCommitFileSystemProvider : GitHubCommitFileSystemProvider | undefined ;
58+
59+ export function getGitHubCommitFileSystemProvider ( initialize ?: { reposManager : RepositoriesManager , gitAPI : GitApiImpl , credentialStore : CredentialStore } ) : GitHubCommitFileSystemProvider | undefined {
60+ if ( ! githubCommitFileSystemProvider && initialize ) {
61+ githubCommitFileSystemProvider = new GitHubCommitFileSystemProvider ( initialize . reposManager , initialize . gitAPI , initialize . credentialStore ) ;
62+ }
63+ return githubCommitFileSystemProvider ;
3964}
0 commit comments