@@ -27,6 +27,7 @@ interface LogEntry {
27
27
}
28
28
29
29
const diffRegex = / d i f f - - g i t a \/ ( .* ) b \/ ( .* ) / ;
30
+ const fileStatusRegex = / ( \S ) \S * \t ( [ ^ \t \n ] + ) (?: \t ( .+ ) ) ? / ;
30
31
const logFileSimpleRegex = / ^ < r > ( .* ) \s * (?: (?: d i f f - - g i t a \/ ( .* ) b \/ ( .* ) ) | (?: \S + \t ( [ ^ \t \n ] + ) (?: \t ( .+ ) ) ? ) ) / gm;
31
32
32
33
const emptyEntry : LogEntry = { } ;
@@ -68,6 +69,9 @@ export class GitLogParser {
68
69
const commits : Map < string , GitLogCommit > = new Map ( ) ;
69
70
let truncationCount = maxCount ;
70
71
72
+ let match ;
73
+ let renamedFileName ;
74
+
71
75
while ( true ) {
72
76
next = lines . next ( ) ;
73
77
if ( next . done ) break ;
@@ -151,44 +155,60 @@ export class GitLogParser {
151
155
if ( line . startsWith ( 'warning:' ) ) continue ;
152
156
153
157
if ( type === GitCommitType . Branch ) {
154
- const status = {
155
- status : line [ 0 ] as GitFileStatus ,
156
- fileName : line . substring ( 1 ) ,
157
- originalFileName : undefined
158
- } ;
159
- this . parseFileName ( status ) ;
160
-
161
- if ( status . fileName ) {
158
+ match = fileStatusRegex . exec ( line ) ;
159
+ if ( match != null ) {
162
160
if ( entry . files === undefined ) {
163
161
entry . files = [ ] ;
164
162
}
165
- entry . files . push ( status ) ;
163
+
164
+ renamedFileName = match [ 3 ] ;
165
+ if ( renamedFileName !== undefined ) {
166
+ entry . files . push ( {
167
+ status : match [ 1 ] as GitFileStatus ,
168
+ fileName : renamedFileName ,
169
+ originalFileName : match [ 2 ]
170
+ } ) ;
171
+ }
172
+ else {
173
+ entry . files . push ( {
174
+ status : match [ 1 ] as GitFileStatus ,
175
+ fileName : match [ 2 ]
176
+ } ) ;
177
+ }
166
178
}
167
179
}
168
- else if ( line . startsWith ( 'diff' ) ) {
169
- const matches = diffRegex . exec ( line ) ;
170
- if ( matches != null ) {
171
- let originalFileName ;
172
- [ , entry . fileName , originalFileName ] = matches ;
173
- if ( entry . fileName !== originalFileName ) {
174
- entry . originalFileName = originalFileName ;
175
- entry . status = 'R' ;
180
+ else {
181
+ match = diffRegex . exec ( line ) ;
182
+ if ( match != null ) {
183
+ [ , entry . originalFileName , entry . fileName ] = match ;
184
+ if ( entry . fileName === entry . originalFileName ) {
185
+ entry . originalFileName = undefined ;
186
+ entry . status = 'M' ;
176
187
}
177
188
else {
178
- entry . status = 'M ' ;
189
+ entry . status = 'R ' ;
179
190
}
180
- }
181
191
182
- while ( true ) {
183
- next = lines . next ( ) ;
184
- if ( next . done || next . value === '</f>' ) break ;
192
+ while ( true ) {
193
+ next = lines . next ( ) ;
194
+ if ( next . done || next . value === '</f>' ) break ;
195
+ }
196
+ break ;
197
+ }
198
+ else {
199
+ match = fileStatusRegex . exec ( line ) ;
200
+ if ( match != null ) {
201
+ entry . status = match [ 1 ] as GitFileStatus ;
202
+ renamedFileName = match [ 3 ] ;
203
+ if ( renamedFileName !== undefined ) {
204
+ entry . fileName = renamedFileName ;
205
+ entry . originalFileName = match [ 2 ] ;
206
+ }
207
+ else {
208
+ entry . fileName = match [ 2 ] ;
209
+ }
210
+ }
185
211
}
186
- break ;
187
- }
188
- else {
189
- entry . status = line [ 0 ] as GitFileStatus ;
190
- entry . fileName = line . substring ( 1 ) ;
191
- this . parseFileName ( entry ) ;
192
212
}
193
213
}
194
214
@@ -287,7 +307,8 @@ export class GitLogParser {
287
307
}
288
308
}
289
309
290
- const originalFileName = relativeFileName !== entry . fileName ? entry . fileName : undefined ;
310
+ const originalFileName =
311
+ entry . originalFileName || ( relativeFileName !== entry . fileName ? entry . fileName : undefined ) ;
291
312
if ( type === GitCommitType . File ) {
292
313
entry . files = [
293
314
{
0 commit comments