@@ -2333,32 +2333,30 @@ process.umask = function() { return 0; };
2333
2333
var oldLine2 = null ; // Used for combined diff
2334
2334
var newLine = null ;
2335
2335
2336
+ /* Add previous block(if exists) before start a new file */
2336
2337
var saveBlock = function ( ) {
2337
-
2338
- /* Add previous block(if exists) before start a new file */
2339
2338
if ( currentBlock ) {
2340
2339
currentFile . blocks . push ( currentBlock ) ;
2341
2340
currentBlock = null ;
2342
2341
}
2343
2342
} ;
2344
2343
2344
+ /*
2345
+ * Add previous file(if exists) before start a new one
2346
+ * if it has name (to avoid binary files errors)
2347
+ */
2345
2348
var saveFile = function ( ) {
2346
-
2347
- /*
2348
- * Add previous file(if exists) before start a new one
2349
- * if it has name (to avoid binary files errors)
2350
- */
2351
2349
if ( currentFile && currentFile . newName ) {
2352
2350
files . push ( currentFile ) ;
2353
2351
currentFile = null ;
2354
2352
}
2355
2353
} ;
2356
2354
2355
+ /* Create file structure */
2357
2356
var startFile = function ( ) {
2358
2357
saveBlock ( ) ;
2359
2358
saveFile ( ) ;
2360
2359
2361
- /* Create file structure */
2362
2360
currentFile = { } ;
2363
2361
currentFile . blocks = [ ] ;
2364
2362
currentFile . deletedLines = 0 ;
@@ -2479,18 +2477,72 @@ process.umask = function() { return 0; };
2479
2477
return ;
2480
2478
}
2481
2479
2482
- var values = [ ] ;
2483
- if ( utils . startsWith ( line , 'diff' ) ) {
2480
+ if (
2481
+ utils . startsWith ( line , 'diff' ) || // Git diffs always start with diff
2482
+ ! currentFile || // If we do not have a file yet, we should crete one
2483
+ (
2484
+ currentFile && // If we already have some file in progress and
2485
+ (
2486
+ currentFile . oldName && utils . startsWith ( line , '---' ) || // Either we reached a old file identification line
2487
+ currentFile . newName && utils . startsWith ( line , '+++' ) // Or we reached a new file identification line
2488
+ )
2489
+ )
2490
+ ) {
2484
2491
startFile ( ) ;
2485
- } else if ( currentFile && ! currentFile . oldName && ( values = getSrcFilename ( line , config ) ) ) {
2492
+ }
2493
+
2494
+ var values ;
2495
+
2496
+ /*
2497
+ * --- Date Timestamp[FractionalSeconds] TimeZone
2498
+ * --- 2002-02-21 23:30:39.942229878 -0800
2499
+ */
2500
+ if ( currentFile && ! currentFile . oldName &&
2501
+ utils . startsWith ( line , '---' ) && ( values = getSrcFilename ( line , config ) ) ) {
2486
2502
currentFile . oldName = values ;
2487
2503
currentFile . language = getExtension ( currentFile . oldName , currentFile . language ) ;
2488
- } else if ( currentFile && ! currentFile . newName && ( values = getDstFilename ( line , config ) ) ) {
2504
+ return ;
2505
+ }
2506
+
2507
+ /*
2508
+ * +++ Date Timestamp[FractionalSeconds] TimeZone
2509
+ * +++ 2002-02-21 23:30:39.942229878 -0800
2510
+ */
2511
+ if ( currentFile && ! currentFile . newName &&
2512
+ utils . startsWith ( line , '+++' ) && ( values = getDstFilename ( line , config ) ) ) {
2489
2513
currentFile . newName = values ;
2490
2514
currentFile . language = getExtension ( currentFile . newName , currentFile . language ) ;
2491
- } else if ( currentFile && utils . startsWith ( line , '@@' ) ) {
2515
+ return ;
2516
+ }
2517
+
2518
+ if ( currentFile && utils . startsWith ( line , '@' ) ) {
2492
2519
startBlock ( line ) ;
2493
- } else if ( ( values = oldMode . exec ( line ) ) ) {
2520
+ return ;
2521
+ }
2522
+
2523
+ /*
2524
+ * There are three types of diff lines. These lines are defined by the way they start.
2525
+ * 1. New line starts with: +
2526
+ * 2. Old line starts with: -
2527
+ * 3. Context line starts with: <SPACE>
2528
+ */
2529
+ if ( currentBlock && ( utils . startsWith ( line , '+' ) || utils . startsWith ( line , '-' ) || utils . startsWith ( line , ' ' ) ) ) {
2530
+ createLine ( line ) ;
2531
+ return ;
2532
+ }
2533
+
2534
+ if (
2535
+ ( currentFile && currentFile . blocks . length ) ||
2536
+ ( currentBlock && currentBlock . lines . length )
2537
+ ) {
2538
+ startFile ( ) ;
2539
+ }
2540
+
2541
+ /*
2542
+ * Git diffs provide more information regarding files modes, renames, copies,
2543
+ * commits between changes and similarity indexes
2544
+ */
2545
+ if ( ( values = oldMode . exec ( line ) ) ) {
2494
2546
currentFile . oldMode = values [ 1 ] ;
2495
2547
} else if ( ( values = newMode . exec ( line ) ) ) {
2496
2548
currentFile . newMode = values [ 1 ] ;
@@ -2532,8 +2584,6 @@ process.umask = function() { return 0; };
2532
2584
} else if ( ( values = combinedDeletedFile . exec ( line ) ) ) {
2533
2585
currentFile . deletedFileMode = values [ 1 ] ;
2534
2586
currentFile . isDeleted = true ;
2535
- } else if ( currentBlock ) {
2536
- createLine ( line ) ;
2537
2587
}
2538
2588
} ) ;
2539
2589
0 commit comments