@@ -67,6 +67,8 @@ const RepoSearchWarnings = {
6767 doesNotExist : / n o s u c h f i l e o r d i r e c t o r y / i
6868} ;
6969
70+ const userConfigRegex = / ^ u s e r \. ( n a m e | e m a i l ) ( .* ) $ / gm;
71+
7072export enum GitRepoSearchBy {
7173 Author = 'author' ,
7274 ChangedLines = 'changed-lines' ,
@@ -126,6 +128,10 @@ export class GitService extends Disposable {
126128 private onAnyRepositoryChanged ( repo : Repository , reason : RepositoryChange ) {
127129 this . _trackedCache . clear ( ) ;
128130
131+ if ( reason === RepositoryChange . Config ) {
132+ this . _userMapCache . delete ( repo . path ) ;
133+ }
134+
129135 if ( reason === RepositoryChange . Closed ) {
130136 // Send a notification that the repositories changed
131137 setImmediate ( async ( ) => {
@@ -751,12 +757,7 @@ export class GitService extends Disposable {
751757 startLine : lineToBlame ,
752758 endLine : lineToBlame
753759 } ) ;
754- const blame = GitBlameParser . parse (
755- data ,
756- uri . repoPath ,
757- fileName ,
758- await this . getCurrentUser ( uri . repoPath ! )
759- ) ;
760+ const blame = GitBlameParser . parse ( data , uri . repoPath , fileName , await this . getCurrentUser ( uri . repoPath ! ) ) ;
760761 if ( blame === undefined ) return undefined ;
761762
762763 return {
@@ -924,33 +925,31 @@ export class GitService extends Disposable {
924925 return await Git . config_get ( key , repoPath ) ;
925926 }
926927
927- // TODO: Clear cache when git config changes
928928 private _userMapCache = new Map < string , { name ?: string ; email ?: string } | null > ( ) ;
929929
930930 async getCurrentUser ( repoPath : string ) {
931931 let user = this . _userMapCache . get ( repoPath ) ;
932932 if ( user != null ) return user ;
933+ // If we found the repo, but no user data was found just return
933934 if ( user === null ) return undefined ;
934935
935936 const data = await Git . config_getRegex ( 'user.(name|email)' , repoPath ) ;
936937 if ( ! data ) {
938+ // If we found no user data, mark it so we won't bother trying again
937939 this . _userMapCache . set ( repoPath , null ) ;
938940 return undefined ;
939941 }
940942
941943 user = { name : undefined , email : undefined } ;
942944
943945 let match : RegExpExecArray | null = null ;
944- const userConfigRegex = / ^ u s e r \. ( n a m e | e m a i l ) ( .* ) $ / gm;
945946 do {
946947 match = userConfigRegex . exec ( data ) ;
947- if ( match == null ) {
948- break ;
949- }
948+ if ( match == null ) break ;
950949
951950 // Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
952951 user [ match [ 1 ] as 'name' | 'email' ] = ( ' ' + match [ 2 ] ) . substr ( 1 ) ;
953- } while ( match !== null ) ;
952+ } while ( match != null ) ;
954953
955954 this . _userMapCache . set ( repoPath , user ) ;
956955 return user ;
0 commit comments