Release version 2.0.3

This commit is contained in:
Rodrigo Fernandes 2016-09-02 17:52:43 +01:00
parent 8cf734d016
commit 5303b2ff24
4 changed files with 55 additions and 18 deletions

View file

@ -1,6 +1,6 @@
{
"name": "diff2html",
"version": "2.0.2",
"version": "2.0.3",
"homepage": "https://diff2html.xyz",
"description": "Fast Diff to colorized HTML",
"keywords": [

65
dist/diff2html.js vendored
View file

@ -2415,26 +2415,26 @@ process.umask = function() { return 0; };
var hunkHeaderPrefix = '@@';
/* Add previous block(if exists) before start a new file */
var saveBlock = function() {
function saveBlock() {
if (currentBlock) {
currentFile.blocks.push(currentBlock);
currentBlock = null;
}
};
}
/*
* Add previous file(if exists) before start a new one
* if it has name (to avoid binary files errors)
*/
var saveFile = function() {
function saveFile() {
if (currentFile && currentFile.newName) {
files.push(currentFile);
currentFile = null;
}
};
}
/* Create file structure */
var startFile = function() {
function startFile() {
saveBlock();
saveFile();
@ -2442,9 +2442,9 @@ process.umask = function() { return 0; };
currentFile.blocks = [];
currentFile.deletedLines = 0;
currentFile.addedLines = 0;
};
}
var startBlock = function(line) {
function startBlock(line) {
saveBlock();
var values;
@ -2489,9 +2489,9 @@ process.umask = function() { return 0; };
currentBlock.oldStartLine2 = oldLine2;
currentBlock.newStartLine = newLine;
currentBlock.header = line;
};
}
var createLine = function(line) {
function createLine(line) {
var currentLine = {};
currentLine.content = line;
@ -2522,7 +2522,34 @@ process.umask = function() { return 0; };
currentBlock.lines.push(currentLine);
}
};
}
/*
* Checks if there is a hunk header coming before a new file starts
*
* Hunk header is a group of three lines started by ( `--- ` , `+++ ` , `@@` )
*/
function existHunkHeader(line, lineIdx) {
var idx = lineIdx;
while (idx < diffLines.length - 3) {
if (utils.startsWith(line, 'diff')) {
return false;
}
if (
utils.startsWith(diffLines[idx], oldFileNameHeader) &&
utils.startsWith(diffLines[idx + 1], newFileNameHeader) &&
utils.startsWith(diffLines[idx + 2], hunkHeaderPrefix)
) {
return true;
}
idx++;
}
return false;
}
var diffLines =
diffInput.replace(/\\ No newline at end of file/g, '')
@ -2638,6 +2665,8 @@ process.umask = function() { return 0; };
return;
}
var doesNotExistHunkHeader = !existHunkHeader(line, lineIndex);
/*
* Git diffs provide more information regarding files modes, renames, copies,
* commits between changes and similarity indexes
@ -2653,16 +2682,24 @@ process.umask = function() { return 0; };
currentFile.newFileMode = values[1];
currentFile.isNew = true;
} else if ((values = copyFrom.exec(line))) {
currentFile.oldName = values[1];
if (doesNotExistHunkHeader) {
currentFile.oldName = values[1];
}
currentFile.isCopy = true;
} else if ((values = copyTo.exec(line))) {
currentFile.newName = values[1];
if (doesNotExistHunkHeader) {
currentFile.newName = values[1];
}
currentFile.isCopy = true;
} else if ((values = renameFrom.exec(line))) {
currentFile.oldName = values[1];
if (doesNotExistHunkHeader) {
currentFile.oldName = values[1];
}
currentFile.isRename = true;
} else if ((values = renameTo.exec(line))) {
currentFile.newName = values[1];
if (doesNotExistHunkHeader) {
currentFile.newName = values[1];
}
currentFile.isRename = true;
} else if ((values = similarityIndex.exec(line))) {
currentFile.unchangedPercentage = values[1];

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "diff2html",
"version": "2.0.2",
"version": "2.0.3",
"homepage": "https://diff2html.xyz",
"description": "Fast Diff to colorized HTML",
"keywords": [