From 5482dfe450cc1fc465c6eb90409afbb26cb0376c Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Tue, 20 Jan 2009 17:53:05 +0100 Subject: [PATCH 1/6] Rudimentary support for renames/deletions of files diffHighlighter.js, history.js: Distinguish created, renamed, changed and deleted files and display them accordingly --- html/lib/diffHighlighter.js | 73 +++++++++++++++++++++++++---------- html/views/history/history.js | 15 +++++-- 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/html/lib/diffHighlighter.js b/html/lib/diffHighlighter.js index 79f31de..b604e11 100644 --- a/html/lib/diffHighlighter.js +++ b/html/lib/diffHighlighter.js @@ -18,7 +18,8 @@ var highlightDiff = function(diff, element, callbacks) { var file_index = 0; - var filename = ""; + var startname = ""; + var endname = ""; var line1 = ""; var line2 = ""; var diffContent = ""; @@ -33,8 +34,26 @@ var highlightDiff = function(diff, element, callbacks) { var finishContent = function() { - finalContent += '
' + - '
' + filename + '
'; + if (!file_index) + { + file_index++; + return; + } + + if (callbacks["newfile"]) + callbacks["newfile"](startname, endname, "file_index_" + (file_index - 1)); + + var title = startname; + if (endname == "/dev/null") + title = startname; + else if (startname == "/dev/null") + title = endname; + else if (startname != endname) + title = startname + " renamed to " + endname; + + finalContent += '
' + + '
' + title + '
'; + if (!binary) { finalContent += '
' + '
' + line1 + "
" + @@ -50,37 +69,52 @@ var highlightDiff = function(diff, element, callbacks) { } finalContent += '
'; + line1 = ""; line2 = ""; diffContent = ""; + file_index++; + startname = ""; + endname = ""; } for (var lineno = 0; lineno < lines.length; lineno++) { var l = lines[lineno]; var firstChar = l.charAt(0); - // Matches "diff --git ...." + if (firstChar == "d" && l.charAt(1) == "i") { // "diff", i.e. new file, we have to reset everything + header = true; // diff always starts with a header - if (firstChar == "d") { // New file, we have to reset everything - header = true; - - if (file_index++) // Finish last file - 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)); - } + finishContent(); // Finish last file + binary = false; continue; } if (header) { - if (firstChar == "+" || firstChar == "-") + if (firstChar == "-") { + if (match = l.match(/^--- (a\/)?(.*)$/)) + startname = match[2]; continue; + } + if (firstChar == "+") { + if (match = l.match(/^\+\+\+ (b\/)?(.*)$/)) + endname = match[2]; + continue; + } + // If it is a complete rename, we don't know the name yet + // We can figure this out from the 'rename from.. rename to.. thing + if (firstChar == 'r') + { + if (match = l.match(/^rename (from|to) (.*)$/)) + { + if (match[1] == "from") + startname = match[2]; + else + endname = match[2]; + } + continue; + } if (firstChar == "B") // "Binary files" { binary = true; @@ -126,7 +160,6 @@ var highlightDiff = function(diff, element, callbacks) { } } - file_index++; finishContent(); // This takes about 7ms @@ -135,4 +168,4 @@ var highlightDiff = function(diff, element, callbacks) { // TODO: Replace this with a performance pref call if (false) Controller.log_("Total time:" + (new Date().getTime() - start)); -} \ No newline at end of file +} diff --git a/html/views/history/history.js b/html/views/history/history.js index 36d40f7..a748485 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -173,8 +173,15 @@ var loadCommit = function(commitObject, currentRef) { } var showDiff = function() { - var newfile = function(name, id) { - $("files").innerHTML += "" + name + "
"; + var newfile = function(name1, name2, id) { + if (name1 == name2) + $("files").innerHTML += "" + name1 + " changed
"; + else if (name1 == "/dev/null") + $("files").innerHTML += "" + name2 + " created
"; + else if (name2 == "/dev/null") + $("files").innerHTML += "" + name1 + " deleted
"; + else + $("files").innerHTML += "" + name1 + " moved to " + name2 + "
"; } var binaryDiff = function(filename) { @@ -184,7 +191,7 @@ var showDiff = function() { 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) @@ -225,4 +232,4 @@ var loadExtendedCommit = function(commit) hideNotification(); enableFeatures(); -} \ No newline at end of file +} From e2d47cb04963cc7d768905aaaeb523ad815d7020 Mon Sep 17 00:00:00 2001 From: Johannes Gilger Date: Tue, 20 Jan 2009 17:53:06 +0100 Subject: [PATCH 2/6] history.css, history.js: Color changed/deleted/added/moved appendices Signed-off-by: Johannes Gilger --- html/views/history/history.css | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/html/views/history/history.css b/html/views/history/history.css index 0fe68d0..10b52c0 100644 --- a/html/views/history/history.css +++ b/html/views/history/history.css @@ -135,4 +135,20 @@ a.showdiff { .refs.currentBranch { font-weight: bold; -} \ No newline at end of file +} + +.addedfile { + color: green; +} + +.deletedfile { + color: red; +} + +.changedfile { + color: purple; +} + +.movedfile { + color: gray; +} From 22f4ac3f1390c4df4261d43eed60253c007559af Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Sun, 25 Jan 2009 17:32:37 +0000 Subject: [PATCH 3/6] Show renames changes by default Now that we have support to show file renames, we can enable it by default in all the diffs that we use. --- PBGitCommit.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PBGitCommit.m b/PBGitCommit.m index 9f9de44..37dc312 100644 --- a/PBGitCommit.m +++ b/PBGitCommit.m @@ -73,7 +73,7 @@ if (details != nil) return details; - details = [self.repository outputForCommand:[@"show --pretty=raw " stringByAppendingString:[self realSha]]]; + details = [self.repository outputForArguments:[NSArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", [self realSha], nil]]; return details; } From cf14746bda6141221f5a040ebdb7a475fe1c8355 Mon Sep 17 00:00:00 2001 From: Kim Does Date: Sun, 25 Jan 2009 20:59:50 +0000 Subject: [PATCH 4/6] HistoryView: Prettify the file list --- html/views/history/history.css | 48 +++++++++++++++++++++++++++------- html/views/history/history.js | 8 +++--- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/html/views/history/history.css b/html/views/history/history.css index 10b52c0..07c281b 100644 --- a/html/views/history/history.css +++ b/html/views/history/history.css @@ -68,14 +68,15 @@ a.servicebutton{ #files { margin-top: 1em; - font-family: Monaco; - font-size: 10px; } #files a { color: #666666; } +#files p { + margin: 4px; +} #files a:hover { color: #4444ff; } @@ -137,18 +138,45 @@ a.showdiff { font-weight: bold; } -.addedfile { - color: green; +div.button +{ + color: #666666; + + font-size: 60%; + text-align: center; + + width: 50px; + + margin-right: 10px; + + padding: 2px; + + float: left; + clear: both; + + border: 1px solid; + -webkit-border-radius: 3px; } -.deletedfile { - color: red; +div.created +{ + background-color: #ccffcc; + border-color: #66ff66; } -.changedfile { - color: purple; +div.changed +{ + background-color: #ffcc99; + border-color: #ff9933; } -.movedfile { - color: gray; +div.deleted +{ + background-color: #ffcccc; + border-color: #ff6666; +} + +div.renamed +{ + /*No colour needed right now.*/ } diff --git a/html/views/history/history.js b/html/views/history/history.js index a748485..d11358d 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -175,13 +175,13 @@ var loadCommit = function(commitObject, currentRef) { var showDiff = function() { var newfile = function(name1, name2, id) { if (name1 == name2) - $("files").innerHTML += "" + name1 + " changed
"; + $("files").innerHTML += "
changed

" + name1 + "

"; else if (name1 == "/dev/null") - $("files").innerHTML += "" + name2 + " created
"; + $("files").innerHTML += "
created

" + name2 + "

"; else if (name2 == "/dev/null") - $("files").innerHTML += "" + name1 + " deleted
"; + $("files").innerHTML += "
deleted

" + name1 + "

"; else - $("files").innerHTML += "" + name1 + " moved to " + name2 + "
"; + $("files").innerHTML += "
renamed

" + name1 + " → " + name2 + "

"; } var binaryDiff = function(filename) { From b44b0df75a3be7fab3167ed2a91651c2fe62d7e0 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Sun, 25 Jan 2009 21:45:28 +0000 Subject: [PATCH 5/6] DiffHighlighter: Properly show binary changes Binary changes don't have a +++ / --- line, just like a 100% rename doesn't show any changes. We work around this in much the same way -- by reading the filenames for that specific case. --- html/lib/diffHighlighter.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/html/lib/diffHighlighter.js b/html/lib/diffHighlighter.js index b604e11..47fb35a 100644 --- a/html/lib/diffHighlighter.js +++ b/html/lib/diffHighlighter.js @@ -63,7 +63,7 @@ var highlightDiff = function(diff, element, callbacks) { } else { if (callbacks["binaryFile"]) - finalContent += callbacks["binaryFile"](filename); + finalContent += callbacks["binaryFile"](startname); else finalContent += "
Binary file differs
"; } @@ -115,10 +115,17 @@ var highlightDiff = function(diff, element, callbacks) { } continue; } - if (firstChar == "B") // "Binary files" + if (firstChar == "B") // "Binary files .. and .. differ" { binary = true; - Controller.log_("Binary file"); + // We might not have a diff from the binary file if it's new. + // So, we use a regex to figure that out + + if (match = l.match(/^Binary files (a\/)?(.*) and (b\/)(.*) differ$/)) + { + startname = match[2]; + endname = match[4]; + } } // Finish the header From 1dc649bf0985f338ee0b04cdac476e610dbb672f Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Mon, 26 Jan 2009 21:18:29 +0000 Subject: [PATCH 6/6] Diff: also show a binary when it's deleted --- html/lib/diffHighlighter.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/html/lib/diffHighlighter.js b/html/lib/diffHighlighter.js index 47fb35a..d1b65ec 100644 --- a/html/lib/diffHighlighter.js +++ b/html/lib/diffHighlighter.js @@ -44,8 +44,11 @@ var highlightDiff = function(diff, element, callbacks) { callbacks["newfile"](startname, endname, "file_index_" + (file_index - 1)); var title = startname; - if (endname == "/dev/null") + var binaryname = endname; + if (endname == "/dev/null") { + binaryname = startname; title = startname; + } else if (startname == "/dev/null") title = endname; else if (startname != endname) @@ -63,7 +66,7 @@ var highlightDiff = function(diff, element, callbacks) { } else { if (callbacks["binaryFile"]) - finalContent += callbacks["binaryFile"](startname); + finalContent += callbacks["binaryFile"](binaryname); else finalContent += "
Binary file differs
"; }