Add suitable message when not displaying binary files

This commit is contained in:
Nick O'Leary 2017-12-11 17:05:27 +00:00
parent bb59cd5742
commit 028d66befc
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 143 additions and 129 deletions

View File

@ -1678,9 +1678,10 @@ RED.diff = (function() {
function createUnifiedDiffTable(files,commitOptions) { function createUnifiedDiffTable(files,commitOptions) {
var diffPanel = $('<div></div>'); var diffPanel = $('<div></div>');
console.log(files);
files.forEach(function(file) { files.forEach(function(file) {
var hunks = file.hunks; var hunks = file.hunks;
var isBinary = file.binary;
var codeTable = $("<table>").appendTo(diffPanel); var codeTable = $("<table>").appendTo(diffPanel);
$('<colgroup><col width="50"><col width="50"><col width="100%"></colgroup>').appendTo(codeTable); $('<colgroup><col width="50"><col width="50"><col width="100%"></colgroup>').appendTo(codeTable);
var codeBody = $('<tbody>').appendTo(codeTable); var codeBody = $('<tbody>').appendTo(codeTable);
@ -1744,7 +1745,12 @@ RED.diff = (function() {
}) })
} }
if (isBinary) {
var diffBinaryRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
var binaryContent = $('<td colspan="3"></td>').appendTo(diffBinaryRow);
$('<span></span>').text("Cannot show binary file contents").appendTo(binaryContent);
} else {
hunks.forEach(function(hunk) { hunks.forEach(function(hunk) {
var diffRow = $('<tr class="node-text-diff-header">').appendTo(codeBody); var diffRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
var content = $('<td colspan="3"></td>').appendTo(diffRow); var content = $('<td colspan="3"></td>').appendTo(diffRow);
@ -1880,6 +1886,7 @@ RED.diff = (function() {
} }
}); });
}); });
}
if (commitOptions.unmerged) { if (commitOptions.unmerged) {
conflictHeader = $('<span style="float: right;"><span>'+resolvedConflicts+'</span> of <span>'+unresolvedConflicts+'</span> conflicts resolved</span>').appendTo(content); conflictHeader = $('<span style="float: right;"><span>'+resolvedConflicts+'</span> of <span>'+unresolvedConflicts+'</span> conflicts resolved</span>').appendTo(content);
} }
@ -2041,7 +2048,9 @@ RED.diff = (function() {
} else { } else {
lines = diff.split("\n"); lines = diff.split("\n");
} }
var diffHeader = /^diff --git a\/(.*) b\/(.*)$/;
var fileHeader = /^\+\+\+ b\/(.*)\t?/; var fileHeader = /^\+\+\+ b\/(.*)\t?/;
var binaryFile = /^Binary files /;
var hunkHeader = /^@@ -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @@ ?(.*)$/; var hunkHeader = /^@@ -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @@ ?(.*)$/;
var conflictHunkHeader = /^@+ -((\d+)(,(\d+))?) -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @+/; var conflictHunkHeader = /^@+ -((\d+)(,(\d+))?) -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @+/;
var files = []; var files = [];
@ -2050,16 +2059,21 @@ RED.diff = (function() {
var currentHunk; var currentHunk;
for (var i=0;i<lines.length;i++) { for (var i=0;i<lines.length;i++) {
var line = lines[i]; var line = lines[i];
if (/^diff/.test(line)) { var diffLine = diffHeader.exec(line);
if (diffLine) {
if (currentHunk) { if (currentHunk) {
currentFile.hunks.push(currentHunk); currentFile.hunks.push(currentHunk);
files.push(currentFile); files.push(currentFile);
} }
currentHunk = null; currentHunk = null;
currentFile = { currentFile = {
file: null, file: diffLine[1],
hunks: [] hunks: []
} }
} else if (binaryFile.test(line)) {
if (currentFile) {
currentFile.binary = true;
}
} else { } else {
var fileLine = fileHeader.exec(line); var fileLine = fileHeader.exec(line);
if (fileLine) { if (fileLine) {
@ -2106,8 +2120,8 @@ RED.diff = (function() {
} }
if (currentHunk) { if (currentHunk) {
currentFile.hunks.push(currentHunk); currentFile.hunks.push(currentHunk);
files.push(currentFile);
} }
files.push(currentFile);
return files; return files;
} }