Skip to content

Commit

Permalink
Merge branch 'pu/jg/rename_detection' (early part)
Browse files Browse the repository at this point in the history
* 'pu/jg/rename_detection' (early part):
  Diff: also show a binary when it's deleted
  DiffHighlighter: Properly show binary changes
  HistoryView: Prettify the file list
  Show renames changes by default
  history.css, history.js: Color changed/deleted/added/moved appendices
  Rudimentary support for renames/deletions of files
  • Loading branch information
pieter committed Jan 26, 2009
2 parents c689510 + 1dc649b commit b651701
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 31 deletions.
2 changes: 1 addition & 1 deletion PBGitCommit.m
Expand Up @@ -73,7 +73,7 @@ - (NSString*) details
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;
}
Expand Down
89 changes: 66 additions & 23 deletions html/lib/diffHighlighter.js
Expand Up @@ -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 = "";
Expand All @@ -33,8 +34,29 @@ var highlightDiff = function(diff, element, callbacks) {

var finishContent = function()
{
finalContent += '<div class="file" id="file_index_' + (file_index - 2) + '">' +
'<div class="fileHeader">' + filename + '</div>';
if (!file_index)
{
file_index++;
return;
}

if (callbacks["newfile"])
callbacks["newfile"](startname, endname, "file_index_" + (file_index - 1));

var title = startname;
var binaryname = endname;
if (endname == "/dev/null") {
binaryname = startname;
title = startname;
}
else if (startname == "/dev/null")
title = endname;
else if (startname != endname)
title = startname + " renamed to " + endname;

finalContent += '<div class="file" id="file_index_' + (file_index - 1) + '">' +
'<div class="fileHeader">' + title + '</div>';

if (!binary) {
finalContent += '<div class="diffContent">' +
'<div class="lineno">' + line1 + "</div>" +
Expand All @@ -44,47 +66,69 @@ var highlightDiff = function(diff, element, callbacks) {
}
else {
if (callbacks["binaryFile"])
finalContent += callbacks["binaryFile"](filename);
finalContent += callbacks["binaryFile"](binaryname);
else
finalContent += "<div>Binary file differs</div>";
}

finalContent += '</div>';

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") { // New file, we have to reset everything
header = true;

if (file_index++) // Finish last file
finishContent();
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

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 == "B") // "Binary files"
}
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 .. 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
Expand Down Expand Up @@ -126,7 +170,6 @@ var highlightDiff = function(diff, element, callbacks) {
}
}

file_index++;
finishContent();

// This takes about 7ms
Expand All @@ -135,4 +178,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));
}
}
50 changes: 47 additions & 3 deletions html/views/history/history.css
Expand Up @@ -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;
}
Expand Down Expand Up @@ -135,4 +136,47 @@ a.showdiff {

.refs.currentBranch {
font-weight: bold;
}
}

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;
}

div.created
{
background-color: #ccffcc;
border-color: #66ff66;
}

div.changed
{
background-color: #ffcc99;
border-color: #ff9933;
}

div.deleted
{
background-color: #ffcccc;
border-color: #ff6666;
}

div.renamed
{
/*No colour needed right now.*/
}
15 changes: 11 additions & 4 deletions html/views/history/history.js
Expand Up @@ -173,8 +173,15 @@ var loadCommit = function(commitObject, currentRef) {
}

var showDiff = function() {
var newfile = function(name, id) {
$("files").innerHTML += "<a href='#" + id + "'>" + name + "</a><br>";
var newfile = function(name1, name2, id) {
if (name1 == name2)
$("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")
$("files").innerHTML += "<div class='button deleted'>deleted</div><p><a href='#" + id + "'>" + name1 + "</a></p>";
else
$("files").innerHTML += "<div class='button renamed' alt='renamed''>renamed</div><p>" + name1 + " &#8594; <a href='#" + id + "'>" + name2 + "</a></p>";
}

var binaryDiff = function(filename) {
Expand All @@ -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)
Expand Down Expand Up @@ -225,4 +232,4 @@ var loadExtendedCommit = function(commit)

hideNotification();
enableFeatures();
}
}

0 comments on commit b651701

Please sign in to comment.