@@ -10,6 +10,8 @@ import { Properties, Property } from "../util/property";
1010import { GitBlame } from "./blame" ;
1111
1212export class GitBlameStream extends EventEmitter {
13+ private static readonly HASH_PATTERN : RegExp = / [ a - z 0 - 9 ] { 40 } / ;
14+
1315 private file : Uri ;
1416 private workTree : string ;
1517 private process : ChildProcess ;
@@ -78,19 +80,25 @@ export class GitBlameStream extends EventEmitter {
7880
7981 private data ( dataChunk : string ) : void {
8082 const lines = dataChunk . split ( "\n" ) ;
81- let commitInfo = this . getCommitTemplate ( ) ;
83+ let commitInfo = GitBlame . blankCommitInfo ( ) ;
84+
85+ commitInfo . filename = this . file . fsPath . replace ( this . workTree , "" ) ;
8286
8387 lines . forEach ( ( line , index ) => {
8488 if ( line && line !== "boundary" ) {
8589 const [ all , key , value ] = Array . from ( line . match ( / ( .* ?) ( .* ) / ) ) ;
8690 if (
87- / [ a - z 0 - 9 ] { 40 } / . test ( key ) &&
91+ GitBlameStream . HASH_PATTERN . test ( key ) &&
8892 lines . hasOwnProperty ( index + 1 ) &&
8993 / ^ ( a u t h o r | c o m m i t t e r ) / . test ( lines [ index + 1 ] ) &&
9094 commitInfo . hash !== ""
9195 ) {
9296 this . commitInfoToCommitEmit ( commitInfo ) ;
93- commitInfo = this . getCommitTemplate ( ) ;
97+ commitInfo = GitBlame . blankCommitInfo ( ) ;
98+ commitInfo . filename = this . file . fsPath . replace (
99+ this . workTree ,
100+ "" ,
101+ ) ;
94102 }
95103 this . processLine ( key , value , commitInfo ) ;
96104 }
@@ -104,25 +112,32 @@ export class GitBlameStream extends EventEmitter {
104112 value : string ,
105113 commitInfo : IGitCommitInfo ,
106114 ) : void {
115+ const [ keyPrefix , keySuffix ] = key . split ( " " ) ;
116+ let owner : IGitCommitAuthor = {
117+ mail : "" ,
118+ name : "" ,
119+ temporary : true ,
120+ timestamp : 0 ,
121+ tz : "" ,
122+ } ;
123+
107124 if ( key === "author" ) {
108- commitInfo . author . name = value ;
109- } else if ( key === "author-mail" ) {
110- commitInfo . author . mail = value ;
111- } else if ( key === "author-time" ) {
112- commitInfo . author . timestamp = parseInt ( value , 10 ) ;
113- } else if ( key === "author-tz" ) {
114- commitInfo . author . tz = value ;
125+ owner = commitInfo . author ;
115126 } else if ( key === "committer" ) {
116- commitInfo . committer . name = value ;
117- } else if ( key === "committer-mail" ) {
118- commitInfo . committer . mail = value ;
119- } else if ( key === "committer-time" ) {
120- commitInfo . committer . timestamp = parseInt ( value , 10 ) ;
121- } else if ( key === "committer-tz" ) {
122- commitInfo . committer . tz = value ;
127+ owner = commitInfo . committer ;
128+ }
129+
130+ if ( ! owner . temporary && ! keySuffix ) {
131+ owner . name = value ;
132+ } else if ( keySuffix === "mail" ) {
133+ owner . mail = value ;
134+ } else if ( keySuffix === "time" ) {
135+ owner . timestamp = parseInt ( value , 10 ) ;
136+ } else if ( keySuffix === "tz" ) {
137+ owner . tz = value ;
123138 } else if ( key === "summary" ) {
124139 commitInfo . summary = value ;
125- } else if ( key . length === 40 ) {
140+ } else if ( GitBlameStream . HASH_PATTERN . test ( key ) ) {
126141 commitInfo . hash = key ;
127142
128143 const hash = key ;
@@ -152,24 +167,4 @@ export class GitBlameStream extends EventEmitter {
152167 this . emit ( "commit" , internalHash , commitInfo ) ;
153168 }
154169 }
155-
156- private getCommitTemplate ( ) : IGitCommitInfo {
157- return {
158- author : {
159- mail : "" ,
160- name : "" ,
161- timestamp : 0 ,
162- tz : "" ,
163- } ,
164- committer : {
165- mail : "" ,
166- name : "" ,
167- timestamp : 0 ,
168- tz : "" ,
169- } ,
170- filename : this . file . fsPath . replace ( this . workTree , "" ) ,
171- hash : "" ,
172- summary : "" ,
173- } ;
174- }
175170}
0 commit comments