@@ -457,7 +457,7 @@ export class GitService extends Disposable {
457457
458458 try {
459459 const data = await Git . blame ( root , file , uri . sha , { ignoreWhitespace : Container . config . blame . ignoreWhitespace } ) ;
460- const blame = GitBlameParser . parse ( data , root , file ) ;
460+ const blame = GitBlameParser . parse ( data , root , file , await this . getCurrentUsername ( root ) ) ;
461461 return blame ;
462462 }
463463 catch ( ex ) {
@@ -526,7 +526,7 @@ export class GitService extends Disposable {
526526
527527 try {
528528 const data = await Git . blame_contents ( root , file , contents , { correlationKey : `:${ key } ` , ignoreWhitespace : Container . config . blame . ignoreWhitespace } ) ;
529- const blame = GitBlameParser . parse ( data , root , file ) ;
529+ const blame = GitBlameParser . parse ( data , root , file , await this . getCurrentUsername ( root ) ) ;
530530 return blame ;
531531 }
532532 catch ( ex ) {
@@ -576,7 +576,7 @@ export class GitService extends Disposable {
576576
577577 try {
578578 const data = await Git . blame ( uri . repoPath , fileName , uri . sha , { ignoreWhitespace : Container . config . blame . ignoreWhitespace , startLine : lineToBlame , endLine : lineToBlame } ) ;
579- const blame = GitBlameParser . parse ( data , uri . repoPath , fileName ) ;
579+ const blame = GitBlameParser . parse ( data , uri . repoPath , fileName , await this . getCurrentUsername ( uri . repoPath ! ) ) ;
580580 if ( blame === undefined ) return undefined ;
581581
582582 return {
@@ -618,7 +618,8 @@ export class GitService extends Disposable {
618618
619619 try {
620620 const data = await Git . blame_contents ( uri . repoPath , fileName , contents , { ignoreWhitespace : Container . config . blame . ignoreWhitespace , startLine : lineToBlame , endLine : lineToBlame } ) ;
621- const blame = GitBlameParser . parse ( data , uri . repoPath , fileName ) ;
621+ const currentUser = await this . getCurrentUsername ( uri . repoPath ! ) ;
622+ const blame = GitBlameParser . parse ( data , uri . repoPath , fileName , currentUser ) ;
622623 if ( blame === undefined ) return undefined ;
623624
624625 return {
@@ -723,6 +724,18 @@ export class GitService extends Disposable {
723724 return await Git . config_get ( key , repoPath ) ;
724725 }
725726
727+ // TODO: Clear cache when git config changes
728+ private _userNameMapCache : Map < string , string | undefined > = new Map ( ) ;
729+
730+ async getCurrentUsername ( repoPath : string ) {
731+ let user = this . _userNameMapCache . get ( repoPath ) ;
732+ if ( user === undefined ) {
733+ user = await Git . config_get ( 'user.name' , repoPath ) ;
734+ this . _userNameMapCache . set ( repoPath , user ) ;
735+ }
736+ return user ;
737+ }
738+
726739 async getDiffForFile ( uri : GitUri , sha1 ?: string , sha2 ?: string ) : Promise < GitDiff | undefined > {
727740 if ( sha1 !== undefined && sha2 === undefined && uri . sha !== undefined ) {
728741 sha2 = uri . sha ;
@@ -868,7 +881,17 @@ export class GitService extends Disposable {
868881
869882 try {
870883 const data = await Git . log ( repoPath , { maxCount : maxCount , ref : options . ref , reverse : options . reverse } ) ;
871- const log = GitLogParser . parse ( data , GitCommitType . Branch , repoPath , undefined , options . ref , maxCount , options . reverse ! , undefined ) ;
884+ const log = GitLogParser . parse (
885+ data ,
886+ GitCommitType . Branch ,
887+ repoPath ,
888+ undefined ,
889+ options . ref ,
890+ await this . getCurrentUsername ( repoPath ) ,
891+ maxCount ,
892+ options . reverse ! ,
893+ undefined
894+ ) ;
872895
873896 if ( log !== undefined ) {
874897 const opts = { ...options } ;
@@ -914,7 +937,17 @@ export class GitService extends Disposable {
914937
915938 try {
916939 const data = await Git . log_search ( repoPath , searchArgs , { maxCount : maxCount } ) ;
917- const log = GitLogParser . parse ( data , GitCommitType . Branch , repoPath , undefined , undefined , maxCount , false , undefined ) ;
940+ const log = GitLogParser . parse (
941+ data ,
942+ GitCommitType . Branch ,
943+ repoPath ,
944+ undefined ,
945+ undefined ,
946+ await this . getCurrentUsername ( repoPath ) ,
947+ maxCount ,
948+ false ,
949+ undefined
950+ ) ;
918951
919952 if ( log !== undefined ) {
920953 const opts = { ...options } ;
@@ -1015,7 +1048,17 @@ export class GitService extends Disposable {
10151048 : options . maxCount ;
10161049
10171050 const data = await Git . log_file ( root , file , { ...opts , maxCount : maxCount , startLine : range && range . start . line + 1 , endLine : range && range . end . line + 1 } ) ;
1018- const log = GitLogParser . parse ( data , GitCommitType . File , root , file , opts . ref , maxCount , opts . reverse ! , range ) ;
1051+ const log = GitLogParser . parse (
1052+ data ,
1053+ GitCommitType . File ,
1054+ root ,
1055+ file ,
1056+ opts . ref ,
1057+ await this . getCurrentUsername ( root ) ,
1058+ maxCount ,
1059+ opts . reverse ! ,
1060+ range
1061+ ) ;
10191062
10201063 if ( log !== undefined ) {
10211064 const opts = { ...options } ;
0 commit comments