8000 2.0.0-rc.8 · hubgit/diff2html@8fe49ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 8fe49ab

Browse files
committed
2.0.0-rc.8
1 parent 8679bc3 commit 8fe49ab

File tree

4 files changed

+59
-38
lines changed

4 files changed

+59
-38
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.0-rc.7",
3+
"version": "2.0.0-rc.8",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

dist/diff2html.js

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,6 +2478,11 @@ var Hogan = {};
24782478
.replace(/\r\n?/g, '\n')
24792479
.split('\n');
24802480

2481+
/* Diff Header */
2482+
var oldFileNameHeader = '--- ';
2483+
var newFileNameHeader = '+++ ';
2484+
var hunkHeaderPrefix = '@@';
2485+
24812486
/* Diff */
24822487
var oldMode = /^old mode (\d{6})/;
24832488
var newMode = /^new mode (\d{6})/;
@@ -2500,22 +2505,31 @@ var Hogan = {};
25002505
var combinedNewFile = /^new file mode (\d{6})/;
25012506
var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/;
25022507

2503-
diffLines.forEach(function(line) {
2508+
diffLines.forEach(function(line, lineIndex) {
25042509
// Unmerged paths, and possibly other non-diffable files
25052510
// https://github.com/scottgonzalez/pretty-diff/issues/11
25062511
// Also, remove some useless lines
25072512
if (!line || utils.startsWith(line, '*')) {
25082513
return;
25092514
}
25102515

2511-
if (
2512-
utils.startsWith(line, 'diff') || // Git diffs always start with diff
2513-
!currentFile || // If we do not have a file yet, we should crete one
2516+
var prevLine = diffLines[lineIndex - 1];
2517+
var nxtLine = diffLines[lineIndex + 1];
2518+
var afterNxtLine = diffLines[lineIndex + 2];
2519+
2520+
if (utils.startsWith(line, 'diff')) {
2521+
startFile();
2522+
currentFile.isGitDiff = true;
2523+
return;
2524+
}
2525+
2526+
if (!currentFile || // If we do not have a file yet, we should crete one
25142527
(
2515-
currentFile && // If we already have some file in progress and
2528+
!currentFile.isGitDiff && currentFile && // If we already have some file in progress and
25162529
(
2517-
currentFile.oldName && utils.startsWith(line, '--- ') || // Either we reached a old file identification line
2518-
currentFile.newName && utils.startsWith(line, '+++ ') // Or we reached a new file identification line
2530+
utils.startsWith(line, oldFileNameHeader) && // If we get to an old file path header line
2531+
// And is followed by the new file path header line and the hunk header line
2532+
utils.startsWith(nxtLine, newFileNameHeader) && utils.startsWith(afterNxtLine, hunkHeaderPrefix)
25192533
)
25202534
)
25212535
) {
@@ -2525,28 +2539,43 @@ var Hogan = {};
25252539
var values;
25262540

25272541
/*
2528-
* --- Date Timestamp[FractionalSeconds] TimeZone
2529-
* --- 2002-02-21 23:30:39.942229878 -0800
2542+
* We need to make sure that we have the three lines of the header.
2543+
* This avoids cases like the ones described in:
2544+
* - https://github.com/rtfpessoa/diff2html/issues/87
25302545
*/
2531-
if (currentFile && !currentFile.oldName &&
2532-
utils.startsWith(line, '--- ') && (values = getSrcFilename(line, config))) {
2533-
currentFile.oldName = values;
2534-
currentFile.language = getExtension(currentFile.oldName, currentFile.language);
2535-
return;
2536-
}
2546+
if (
2547+
(utils.startsWith(line, oldFileNameHeader) &&
2548+
utils.startsWith(nxtLine, newFileNameHeader) && utils.startsWith(afterNxtLine, hunkHeaderPrefix)) ||
2549+
2550+
(utils.startsWith(line, newFileNameHeader) &&
2551+
utils.startsWith(prevLine, oldFileNameHeader) && utils.startsWith(nxtLine, hunkHeaderPrefix))
2552+
) {
2553+
2554+
/*
2555+
* --- Date Timestamp[FractionalSeconds] TimeZone
2556+
* --- 2002-02-21 23:30:39.942229878 -0800
2557+
*/
2558+
if (currentFile && !currentFile.oldName &&
2559+
utils.startsWith(line, '--- ') && (values = getSrcFilename(line, config))) {
2560+
currentFile.oldName = values;
2561+
currentFile.language = getExtension(currentFile.oldName, currentFile.language);
2562+
return;
2563+
}
2564+
2565+
/*
2566+
* +++ Date Timestamp[FractionalSeconds] TimeZone
2567+
* +++ 2002-02-21 23:30:39.942229878 -0800
2568+
*/
2569+
if (currentFile && !currentFile.newName &&
2570+
utils.startsWith(line, '+++ ') && (values = getDstFilename(line, config))) {
2571+
currentFile.newName = values;
2572+
currentFile.language = getExtension(currentFile.newName, currentFile.language);
2573+
return;
2574+
}
25372575

2538-
/*
2539-
* +++ Date Timestamp[FractionalSeconds] TimeZone
2540-
* +++ 2002-02-21 23:30:39.942229878 -0800
2541-
*/
2542-
if (currentFile && !currentFile.newName &&
2543-
utils.startsWith(line, '+++ ') && (values = getDstFilename(line, config))) {
2544-
currentFile.newName = values;
2545-
currentFile.language = getExtension(currentFile.newName, currentFile.language);
2546-
return;
25472576
}
25482577

2549-
if (currentFile && utils.startsWith(line, '@')) {
2578+
if (currentFile && utils.startsWith(line, hunkHeaderPrefix)) {
25502579
startBlock(line);
25512580
return;
25522581
}
@@ -2562,13 +2591,6 @@ var Hogan = {};
25622591
return;
25632592
}
25642593

2565-
if (
2566-
(currentFile && currentFile.blocks.length) ||
2567-
(currentBlock && currentBlock.lines.length)
2568-
) {
2569-
startFile();
2570-
}
2571-
25722594
/*
25732595
* Git diffs provide more information regarding files modes, renames, copies,
25742596
* commits between changes and similarity indexes
@@ -3854,7 +3876,7 @@ module.exports = global.browserTemplates;
38543876
return result;
38553877
}
38563878

3857-
return str.indexOf(start) === 0;
3879+
return str && str.indexOf(start) === 0;
38583880
};
38593881

38603882
Utils.prototype.valueOrEmpty = function(value) {

dist/diff2html.min.js

Lines changed: 2 additions & 3 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.0-rc.7",
3+
"version": "2.0.0-rc.8",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

0 commit comments

Comments
 (0)
0