diff --git a/html/lib/diffHighlighter.js b/html/lib/diffHighlighter.js
index a9b30cd..73dc787 100644
--- a/html/lib/diffHighlighter.js
+++ b/html/lib/diffHighlighter.js
@@ -21,46 +21,76 @@ var highlightDiff = function(diff, element, callbacks) {
var diffContent = "";
var finalContent = "";
var lines = content.split('\n');
+ var binary = false;
var hunk_start_line_1 = -1;
var hunk_start_line_2 = -1;
var header = false;
+ var finishContent = function()
+ {
+ finalContent += '
' +
+ '';
+ if (!binary) {
+ finalContent += '
' +
+ '
' + line1 + "
" +
+ '
' + line2 + "
" +
+ '
' + diffContent + "
" +
+ '
';
+ }
+ else {
+ if (callbacks["binaryFile"])
+ finalContent += callbacks["binaryFile"](filename);
+ else
+ finalContent += "
Binary file differs
";
+ }
+
+ finalContent += '
';
+ line1 = "";
+ line2 = "";
+ diffContent = "";
+ }
for (var lineno = 0; lineno < lines.length; lineno++) {
var l = lines[lineno];
var firstChar = l.charAt(0);
- if (header) {
- if (firstChar == "+" || firstChar == "-")
- continue;
- } else if (firstChar == "d") { // New file, we have to reset everything
+ // Matches "diff --git ...."
+
+ if (firstChar == "d") { // New file, we have to reset everything
header = true;
if (file_index++) // Finish last file
- {
- finalContent += '' +
- '' +
- '
' +
- '
' + line1 + "
" +
- '
' + line2 + "
" +
- '
' + diffContent + "
" +
- '
' +
- '
';
- line1 = "";
- line2 = "";
- diffContent = "";
- }
+ finishContent();
+
+ binary = false;
if(match = l.match(/diff --git a\/(\S*)/)) {
filename = match[1];
if (callbacks["newfile"])
callbacks["newfile"](filename, "file_index_" + (file_index - 1));
}
+
continue;
}
+ if (header) {
+ if (firstChar == "+" || firstChar == "-")
+ continue;
+ if (firstChar == "B") // "Binary files"
+ {
+ binary = true;
+ Controller.log_("Binary file");
+ }
+
+ // Finish the header
+ if (firstChar == "@")
+ header = false;
+ else
+ continue;
+ }
+
if (firstChar == "+") {
// Highlight trailing whitespace
if (m = l.match(/\s+$/))
@@ -93,14 +123,7 @@ var highlightDiff = function(diff, element, callbacks) {
}
}
- finalContent += '' +
- '' +
- '
' +
- '
' + line1 + "
" +
- '
' + line2 + "
" +
- '
' + diffContent + "
" +
- '
' +
- '
';
+ finishContent();
// This takes about 7ms
element.innerHTML = finalContent;
diff --git a/html/views/history/history.js b/html/views/history/history.js
index cd489a4..140fa9a 100644
--- a/html/views/history/history.js
+++ b/html/views/history/history.js
@@ -33,13 +33,6 @@ var Commit = function(obj) {
this.author_date = new Date(parseInt(match[3]) * 1000);
- this.files = this.raw.match(/diff --git a\/\S*/g);
-
- for (var i=0; i < this.files.length; i++) {
- var match = this.files[i].match(/diff --git a\/(.*)/);
- this.files[i] = match[1];
- }
-
match = this.header.match(/\ncommitter (.*) <(.*@.*)> ([0-9].*)/);
this.committer_name = match[1];
this.committer_email = match[2];