8000 Release version 2.0.3 · hubgit/diff2html@5303b2f · GitHub
[go: up one dir, main page]

Skip to content

Commit 5303b2f

Browse files
committed
Release version 2.0.3
1 parent 8cf734d commit 5303b2f

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff2html",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"homepage": "https://diff2html.xyz",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

dist/diff2html.js

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,36 +2415,36 @@ process.umask = function() { return 0; };
24152415
var hunkHeaderPrefix = '@@';
24162416

24172417
/* Add previous block(if exists) before start a new file */
2418-
var saveBlock = function() {
2418+
function saveBlock() {
24192419
if (currentBlock) {
24202420
currentFile.blocks.push(currentBlock);
24212421
currentBlock = null;
24222422
}
2423-
};
2423+
}
24242424

24252425
/*
24262426
* Add previous file(if exists) before start a new one
24272427
* if it has name (to avoid binary files errors)
24282428
*/
2429-
var saveFile = function() {
2429+
function saveFile() {
24302430
if (currentFile && currentFile.newName) {
24312431
files.push(currentFile);
24322432
currentFile = null;
24332433
}
2434-
};
2434+
}
24352435

24362436
/* Create file structure */
2437-
var startFile = function() {
2437+
function startFile() {
24382438
saveBlock();
24392439
saveFile();
24402440

24412441
currentFile = {};
24422442
currentFile.blocks = [];
24432443
currentFile.deletedLines = 0;
24442444
currentFile.addedLines = 0;
2445-
};
2445+
}
24462446

2447-
var startBlock = function(line) {
2447+
function startBlock(line) {
24482448
saveBlock();
24492449

24502450
var values;
@@ -2489,9 +2489,9 @@ process.umask = function() { return 0; };
24892489
currentBlock.oldStartLine2 = oldLine2;
24902490
currentBlock.newStartLine = newLine;
24912491
currentBlock.header = line;
2492-
};
2492+
}
24932493

2494-
var createLine = function(line) {
2494+
function createLine(line) {
24952495
var currentLine = {};
24962496
currentLine.content = line;
24972497

@@ -2522,7 +2522,34 @@ process.umask = function() { return 0; };
25222522

25232523
currentBlock.lines.push(currentLine);
25242524
}
2525-
};
2525+
}
2526+
2527+
/*
2528+
* Checks if there is a hunk header coming before a new file starts
2529+
*
2530+
* Hunk header is a group of three lines started by ( `--- ` , `+++ ` , `@@` )
2531+
*/
2532+
function existHunkHeader(line, lineIdx) {
2533+
var idx = lineIdx;
2534+
2535+
while (idx < diffLines.length - 3) {
2536+
if (utils.startsWith(line, 'diff')) {
2537+
return false;
2538+
}
2539+
2540+
if (
2541+
utils.startsWith(diffLines[idx], oldFileNameHeader) &&
2542+
utils.startsWith(diffLines[idx + 1], newFileNameHeader) &&
2543+
utils.startsWith(diffLines[idx + 2], hunkHeaderPrefix)
2544+
) {
2545+
return true;
2546+
}
2547+
2548+
idx++;
2549+
}
2550+
2551+
return false;
2552+
}
25262553

25272554
var diffLines =
25282555
diffInput.replace(/\\ No newline at end of file/g, '')
@@ -2638,6 +2665,8 @@ process.umask = function() { return 0; };
26382665
return;
26392666
}
26402667

2668+
var doesNotExistHunkHeader = !existHunkHeader(line, lineIndex);
2669+
26412670
/*
26422671
* Git diffs provide more information regarding files modes, renames, copies,
26432672
* commits between changes and similarity indexes
@@ -2653,16 +2682,24 @@ process.umask = function() { return 0; };
26532682
currentFile.newFileMode = values[1];
26542683
currentFile.isNew = true;
26552684
} else if ((values = copyFrom.exec(line))) {
2656-
currentFile.oldName = values[1];
2685+
if (doesNotExistHunkHeader) {
2686+
currentFile.oldName = values[1];
2687+
}
26572688
currentFile.isCopy = true;
26582689
} else if ((values = copyTo.exec(line))) {
2659-
currentFile.newName = values[1];
2690+
if (doesNotExistHunkHeader) {
2691+
currentFile.newName = values[1];
2692+
}
26602693
currentFile.isCopy = true;
26612694
} else if ((values = renameFrom.exec(line))) {
2662-
currentFile.oldName = values[1];
2695+
if (doesNotExistHunkHeader) {
2696+
currentFile.oldName = values[1];
2697+
}
26632698
currentFile.isRename = true;
26642699
} else if ((values = renameTo.exec(line))) {
2665-
currentFile.newName = values[1];
2700+
if (doesNotExistHunkHeader) {
2701+
currentFile.newName = values[1];
2702+
}
26662703
currentFile.isRename = true;
26672704
} else if ((values = similarityIndex.exec(line))) {
26682705
currentFile.unchangedPercentage = values[1];

dist/diff2html.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff2html",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"homepage": "https://diff2html.xyz",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

0 commit comments

Comments
 (0)
0