Add another way to recognize binary file names

This commit is contained in:
Rodrigo Fernandes 2016-09-14 18:36:39 +01:00
parent d3b053cae0
commit 2a18c91e70
No known key found for this signature in database
GPG key ID: 08E3C5F38969078E
3 changed files with 61 additions and 2 deletions

View file

@ -195,6 +195,8 @@
var dissimilarityIndex = /^dissimilarity index (\d+)%/;
var index = /^index ([0-9a-z]+)\.\.([0-9a-z]+)\s*(\d{6})?/;
var binaryFiles = /^Binary files (.*) and (.*) differ/;
/* Combined Diff */
var combinedIndex = /^index ([0-9a-z]+),([0-9a-z]+)\.\.([0-9a-z]+)/;
var combinedMode = /^mode (\d{6}),(\d{6})\.\.(\d{6})/;
@ -324,6 +326,10 @@
currentFile.newName = values[1];
}
currentFile.isRename = true;
} else if ((values = binaryFiles.exec(line))) {
currentFile.isBinary = true;
currentFile.oldName = _getFilename(null, values[1], [config.srcPrefix]);
currentFile.newName = _getFilename(null, values[2], [config.dstPrefix]);
} else if ((values = similarityIndex.exec(line))) {
currentFile.unchangedPercentage = values[1];
} else if ((values = dissimilarityIndex.exec(line))) {
@ -383,7 +389,12 @@
}
function _getFilename(linePrefix, line, prefixes) {
var FilenameRegExp = new RegExp('^' + linePrefix + ' "?(.+?)"?$');
var FilenameRegExp;
if (linePrefix) {
FilenameRegExp = new RegExp('^' + linePrefix + ' "?(.+?)"?$');
} else {
FilenameRegExp = new RegExp('^"?(.+?)"?$');
}
var filename;
var values = FilenameRegExp.exec(line);

View file

@ -33,7 +33,7 @@
var cfg = config || {};
cfg.inputFormat = 'json';
var $target = this._getTarget(targetId);
$target.html(Diff2Html.getPrettyHtml(diffJson, cfg.inputFormat));
$target.html(Diff2Html.getPrettyHtml(diffJson, cfg));
synchronisedScroll($target, cfg);
};

View file

@ -573,5 +573,53 @@ describe('DiffParser', function() {
assert.deepEqual(linesContent,
[' function foo() {', '-var bar = "Whoops!";', '+var baz = "Whoops!";', ' }', ' ']);
});
it('should parse diff with prefix', function() {
var diff =
'diff --git "\tTest.scala" "\tScalaTest.scala"\n' +
'similarity index 88%\n' +
'rename from Test.scala\n' +
'rename to ScalaTest.scala\n' +
'index 7d1f9bf..8b13271 100644\n' +
'--- "\tTest.scala"\n' +
'+++ "\tScalaTest.scala"\n' +
'@@ -1,6 +1,8 @@\n' +
' class Test {\n' +
' \n' +
' def method1 = ???\n' +
'+\n' +
'+ def method2 = ???\n' +
' \n' +
' def myMethod = ???\n' +
' \n' +
'@@ -10,7 +12,6 @@ class Test {\n' +
' \n' +
' def + = ???\n' +
' \n' +
'- def |> = ???\n' +
' \n' +
' }\n' +
' \n' +
'diff --git "\ttardis.png" "\ttardis.png"\n' +
'new file mode 100644\n' +
'index 0000000..d503a29\n' +
'Binary files /dev/null and "\ttardis.png" differ\n';
var result = DiffParser.generateDiffJson(diff, {'srcPrefix': '\t', 'dstPrefix': '\t'});
assert.equal(2, result.length);
var file1 = result[0];
assert.equal(2, file1.addedLines);
assert.equal(1, file1.deletedLines);
assert.equal('Test.scala', file1.oldName);
assert.equal('ScalaTest.scala', file1.newName);
assert.equal(2, file1.blocks.length);
assert.equal(8, file1.blocks[0].lines.length);
assert.equal(7, file1.blocks[1].lines.length);
var file2 = result[1];
assert.equal('/dev/null', file2.oldName);
assert.equal('tardis.png', file2.newName);
});
});
});