@@ -612,7 +612,7 @@ export class GitService extends Disposable {
612612 args : Container . config . advanced . blame . customArguments ,
613613 ignoreWhitespace : Container . config . blame . ignoreWhitespace
614614 } ) ;
615- const blame = GitBlameParser . parse ( data , root , file , await this . getCurrentUsername ( root ) ) ;
615+ const blame = GitBlameParser . parse ( data , root , file , await this . getCurrentUser ( root ) ) ;
616616 return blame ;
617617 }
618618 catch ( ex ) {
@@ -692,7 +692,7 @@ export class GitService extends Disposable {
692692 correlationKey : `:${ key } ` ,
693693 ignoreWhitespace : Container . config . blame . ignoreWhitespace
694694 } ) ;
695- const blame = GitBlameParser . parse ( data , root , file , await this . getCurrentUsername ( root ) ) ;
695+ const blame = GitBlameParser . parse ( data , root , file , await this . getCurrentUser ( root ) ) ;
696696 return blame ;
697697 }
698698 catch ( ex ) {
@@ -755,7 +755,7 @@ export class GitService extends Disposable {
755755 data ,
756756 uri . repoPath ,
757757 fileName ,
758- await this . getCurrentUsername ( uri . repoPath ! )
758+ await this . getCurrentUser ( uri . repoPath ! )
759759 ) ;
760760 if ( blame === undefined ) return undefined ;
761761
@@ -808,7 +808,7 @@ export class GitService extends Disposable {
808808 startLine : lineToBlame ,
809809 endLine : lineToBlame
810810 } ) ;
811- const currentUser = await this . getCurrentUsername ( uri . repoPath ! ) ;
811+ const currentUser = await this . getCurrentUser ( uri . repoPath ! ) ;
812812 const blame = GitBlameParser . parse ( data , uri . repoPath , fileName , currentUser ) ;
813813 if ( blame === undefined ) return undefined ;
814814
@@ -925,14 +925,34 @@ export class GitService extends Disposable {
925925 }
926926
927927 // TODO: Clear cache when git config changes
928- private _userNameMapCache : Map < string , string | undefined > = new Map ( ) ;
928+ private _userMapCache = new Map < string , { name ?: string ; email ?: string } | null > ( ) ;
929929
930- async getCurrentUsername ( repoPath : string ) {
931- let user = this . _userNameMapCache . get ( repoPath ) ;
932- if ( user === undefined ) {
933- user = await Git . config_get ( 'user.name' , repoPath ) ;
934- this . _userNameMapCache . set ( repoPath , user ) ;
930+ async getCurrentUser ( repoPath : string ) {
931+ let user = this . _userMapCache . get ( repoPath ) ;
932+ if ( user != null ) return user ;
933+ if ( user === null ) return undefined ;
934+
935+ const data = await Git . config_getRegex ( 'user.(name|email)' , repoPath ) ;
936+ if ( ! data ) {
937+ this . _userMapCache . set ( repoPath , null ) ;
938+ return undefined ;
935939 }
940+
941+ user = { name : undefined , email : undefined } ;
942+
943+ let match : RegExpExecArray | null = null ;
944+ const userConfigRegex = / ^ u s e r \. ( n a m e | e m a i l ) ( .* ) $ / gm;
945+ do {
946+ match = userConfigRegex . exec ( data ) ;
947+ if ( match == null ) {
948+ break ;
949+ }
950+
951+ // Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
952+ user [ match [ 1 ] as 'name' | 'email' ] = ( ' ' + match [ 2 ] ) . substr ( 1 ) ;
953+ } while ( match !== null ) ;
954+
955+ this . _userMapCache . set ( repoPath , user ) ;
936956 return user ;
937957 }
938958
@@ -1120,7 +1140,7 @@ export class GitService extends Disposable {
11201140 repoPath ,
11211141 undefined ,
11221142 options . ref ,
1123- await this . getCurrentUsername ( repoPath ) ,
1143+ await this . getCurrentUser ( repoPath ) ,
11241144 maxCount ,
11251145 options . reverse ! ,
11261146 undefined
@@ -1182,7 +1202,7 @@ export class GitService extends Disposable {
11821202 repoPath ,
11831203 undefined ,
11841204 undefined ,
1185- await this . getCurrentUsername ( repoPath ) ,
1205+ await this . getCurrentUser ( repoPath ) ,
11861206 maxCount ,
11871207 false ,
11881208 undefined
@@ -1337,7 +1357,7 @@ export class GitService extends Disposable {
13371357 root ,
13381358 file ,
13391359 opts . ref ,
1340- await this . getCurrentUsername ( root ) ,
1360+ await this . getCurrentUser ( root ) ,
13411361 maxCount ,
13421362 opts . reverse ! ,
13431363 range
0 commit comments