Recognize file-mode changes correctly and display them

diffHighligher.js: Recognize file-mode changes and mark them
history.js: Extend newfile callback by parameters for mode
history.css: Adjust changed-span to accomodate "mode changed"
This commit is contained in:
Johannes Gilger
2009-01-29 14:34:55 +01:00
parent cb40cf6111
commit bb8a615b22
3 changed files with 39 additions and 12 deletions
+29 -6
View File
@@ -15,7 +15,7 @@ var highlightDiff = function(diff, element, callbacks) {
var start = new Date().getTime();
element.className = "diff"
var content = diff.escapeHTML().replace(/\t/g, " ");;
var file_index = 0;
var startname = "";
@@ -26,6 +26,9 @@ var highlightDiff = function(diff, element, callbacks) {
var finalContent = "";
var lines = content.split('\n');
var binary = false;
var mode_change = false;
var old_mode = "";
var new_mode = "";
var hunk_start_line_1 = -1;
var hunk_start_line_2 = -1;
@@ -41,7 +44,7 @@ var highlightDiff = function(diff, element, callbacks) {
}
if (callbacks["newfile"])
callbacks["newfile"](startname, endname, "file_index_" + (file_index - 1));
callbacks["newfile"](startname, endname, "file_index_" + (file_index - 1), mode_change, old_mode, new_mode);
var title = startname;
var binaryname = endname;
@@ -65,10 +68,12 @@ var highlightDiff = function(diff, element, callbacks) {
'</div>';
}
else {
if (callbacks["binaryFile"])
finalContent += callbacks["binaryFile"](binaryname);
else
finalContent += "<div>Binary file differs</div>";
if (binary) {
if (callbacks["binaryFile"])
finalContent += callbacks["binaryFile"](binaryname);
else
finalContent += "<div>Binary file differs</div>";
}
}
finalContent += '</div>';
@@ -91,6 +96,13 @@ var highlightDiff = function(diff, element, callbacks) {
finishContent(); // Finish last file
binary = false;
mode_change = false;
if(match = l.match(/^diff --git (a\/)+(.*) (b\/)+(.*)$/)) { // there are cases when we need to capture filenames from
startname = match[2]; // the diff line, like with mode-changes.
endname = match[4]; // this can get overwritten later if there is a diff or if
} // the file is binary
continue;
}
@@ -131,6 +143,17 @@ var highlightDiff = function(diff, element, callbacks) {
}
}
if (match = l.match(/^old mode (.*)$/)) {
mode_change = true;
old_mode = match[1];
}
if (match = l.match(/^new mode (.*)$/)) {
mode_change = true;
new_mode = match[1];
}
// Finish the header
if (firstChar == "@")
header = false;
+1 -1
View File
@@ -145,7 +145,7 @@ div.button
font-size: 60%;
text-align: center;
width: 50px;
width: 70px;
margin-right: 10px;
+9 -5
View File
@@ -173,9 +173,13 @@ var loadCommit = function(commitObject, currentRef) {
}
var showDiff = function() {
var newfile = function(name1, name2, id) {
if (name1 == name2)
$("files").innerHTML += "<div class='button changed'>changed</div><p><a href='#" + id + "'>" + name1 + "</a></p>";
var newfile = function(name1, name2, id, mode_change, old_mode, new_mode) {
if (name1 == name2) {
if (mode_change)
$("files").innerHTML += "<div class='button changed'>mode changed</div><p><a href='#" + id + "'>" + name1 + "</a> mode " + old_mode + " &#8594; " + new_mode + "</p>";
else
$("files").innerHTML += "<div class='button changed'>changed</div><p><a href='#" + id + "'>" + name1 + "</a></p>";
}
else if (name1 == "/dev/null")
$("files").innerHTML += "<div class='button created'>created</div><p><a href='#" + id + "'>" + name2 + "</a></p>";
else if (name2 == "/dev/null")
@@ -190,8 +194,8 @@ var showDiff = function() {
else
return "Binary file differs";
}
highlightDiff(commit.diff, $("diff"), { "newfile" : newfile, "binaryFile" : binaryDiff});
highlightDiff(commit.diff, $("diff"), { "newfile" : newfile, "binaryFile" : binaryDiff });
}
var showImage = function(element, filename)