diff --git a/PBGitCommit.m b/PBGitCommit.m index 2812907..1b99db4 100644 --- a/PBGitCommit.m +++ b/PBGitCommit.m @@ -33,6 +33,8 @@ return self; } +// NOTE: This method should remain threadsafe, as we load it in async +// from the web view. - (NSString*) details { if (details != nil) diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index d350cfd..2333984 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -8,7 +8,7 @@ 352.00 YES - + YES @@ -738,7 +738,7 @@ 2322 - {835, 37} + {835, 70} @@ -1125,7 +1125,7 @@ WebURLsWithTitlesPboardType - {543, 71} + {543, 112} @@ -1468,22 +1468,6 @@ 66 - - - value: selection.details - - - - - - value: selection.details - value - selection.details - 2 - - - 69 - selectedIndex: selectedTab @@ -1866,6 +1850,22 @@ 217 + + + value: rawCommit.details + + + + + + value: rawCommit.details + value + rawCommit.details + 2 + + + 230 + @@ -2537,7 +2537,7 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{387, 484}, {852, 432}} + {{592, 572}, {852, 432}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2567,7 +2567,7 @@ - 225 + 230 diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index 624935a..aef28f6 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -47,20 +47,16 @@ if (content == nil || !finishedLoading) return; - id script = [view windowScriptObject]; - [script setValue: content forKey:@"CommitObject"]; - [script setValue:[[[historyController repository] headRef] simpleRef] forKey:@"CurrentBranch"]; - // The sha is the same, but refs may have changed.. reload it lazy if ([currentSha isEqualToString: content.sha]) { - [script callWebScriptMethod:@"reload" withArguments: nil]; + [[self script] callWebScriptMethod:@"reload" withArguments: nil]; return; } - currentSha = content.sha; - [script callWebScriptMethod:@"loadCommit" withArguments: nil]; + NSArray *arguments = [NSArray arrayWithObjects:content, [[[historyController repository] headRef] simpleRef], nil]; + [[self script] callWebScriptMethod:@"loadCommit" withArguments: arguments]; } - (void) selectCommit: (NSString*) sha diff --git a/html/views/history/history.js b/html/views/history/history.js index ac325ed..b2f6bc4 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -1,40 +1,49 @@ var commit; var Commit = function(obj) { - this.raw = obj.details; - this.refs = obj.refs; this.object = obj; - var diffStart = this.raw.indexOf("\ndiff "); - var messageStart = this.raw.indexOf("\n\n") + 2; - - if (diffStart > 0) { - this.message = this.raw.substring(messageStart, diffStart).replace(/^ /gm, "").escapeHTML(); - this.diff = this.raw.substring(diffStart); - } else { - this.message = this.raw.substring(messageStart).replace(/^ /gm, "").escapeHTML(); - this.diff = ""; - } - this.header = this.raw.substring(0, messageStart); - - this.sha = this.header.match(/^commit ([0-9a-f]{40,40})/)[1]; - - var match = this.header.match(/\nauthor (.*) <(.*@.*)> ([0-9].*)/); - this.author_name = match[1]; - if (!(match[2].match(/@[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/))) - this.author_email = match[2]; - - this.author_date = new Date(parseInt(match[3]) * 1000); - - match = this.header.match(/\ncommitter (.*) <(.*@.*)> ([0-9].*)/); - this.committer_name = match[1]; - this.committer_email = match[2]; - this.committer_date = new Date(parseInt(match[3]) * 1000); - + this.refs = obj.refs; + this.author_name = obj.author; + this.sha = obj.sha; this.parents = obj.parents; + this.subject = obj.subject; + + // TODO: + // this.author_date instant + + // This all needs to be async + this.loadedRaw = function(details) { + this.raw = details; + + var diffStart = this.raw.indexOf("\ndiff "); + var messageStart = this.raw.indexOf("\n\n") + 2; + + if (diffStart > 0) { + this.message = this.raw.substring(messageStart, diffStart).replace(/^ /gm, "").escapeHTML(); + this.diff = this.raw.substring(diffStart); + } else { + this.message = this.raw.substring(messageStart).replace(/^ /gm, "").escapeHTML(); + this.diff = ""; + } + this.header = this.raw.substring(0, messageStart); + + var match = this.header.match(/\nauthor (.*) <(.*@.*)> ([0-9].*)/); + if (!(match[2].match(/@[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/))) + this.author_email = match[2]; + + this.author_date = new Date(parseInt(match[3]) * 1000); + + match = this.header.match(/\ncommitter (.*) <(.*@.*)> ([0-9].*)/); + this.committer_name = match[1]; + this.committer_email = match[2]; + this.committer_date = new Date(parseInt(match[3]) * 1000); + } this.reloadRefs = function() { this.refs = CommitObject.refs; } + + // this.loadedRaw(this.raw); }; var gistie = function() { @@ -118,47 +127,60 @@ var reload = function() { showRefs(); } -var showRefs = function() { +var showRefs = function(currentRef) { var refs = $("refs"); if (commit.refs) { refs.parentNode.style.display = ""; refs.innerHTML = ""; for (var i = 0; i < commit.refs.length; i++) { var ref = commit.refs[i], curBranch = ""; - refs.innerHTML += '' + ref.shortName() + ''; + refs.innerHTML += '' + ref.shortName() + ''; } } else refs.parentNode.style.display = "none"; } -var loadCommit = function() { - commit = new Commit(CommitObject); - $("notification").style.display = "none"; +var loadCommit = function(commitObject, currentRef) { + // These are only the things we can do instantly. + // Other information will be loaded later by loadExtendedCommit + commit = new Commit(commitObject); + Controller.callSelector_onObject_callBack_("details", commitObject, + function(data) { commit.loadedRaw(data); loadExtendedCommit(commit); }); + commit.currentRef = currentRef; + + notify("Loading commit…", 0); $("commitID").innerHTML = commit.sha; + $("authorID").innerHTML = commit.author_name; + $("subjectID").innerHTML = commit.subject.escapeHTML(); + $("details").innerHTML = "" + $("message").innerHTML = "" + $("date").innerHTML = "" + showRefs(commit.currentRef); - if (commit.author_email) - $("authorID").innerHTML = commit.author_name + " <" + commit.author_email + ">"; - else - $("authorID").innerHTML = commit.author_name; - - $("date").innerHTML = commit.author_date; - $("subjectID").innerHTML =CommitObject.subject.escapeHTML(); - - var commitHeader = $("commit_header"); for (var i = 0; i < commitHeader.rows.length; i++) { - var row = commitHeader.rows[i]; + var row = $("commit_header").rows[i]; if (row.innerHTML.match(/Parent:/)) row.parentNode.removeChild(row); } for (var i = 0; i < commit.parents; i++) { - var parent = commit.parents[i], newRow = commitHeader.insertRow(-1); - new_row.innerHTML = "Parent:" + parent + ""; + var newRow = $("commit_header").insertRow(-1); + new_row.innerHTML = "Parent:" + + "" + + commit.parents[i] + ""; } - showRefs(); + // Scroll to top + scroll(0, 0); +} +var loadExtendedCommit = function(commit) +{ + if (commit.author_email) + $("authorID").innerHTML = commit.author_name + " <" + commit.author_email + ">"; + + $("date").innerHTML = commit.author_date; $("message").innerHTML = commit.message.replace(/\n/g,""); if (commit.diff.length < 200000) { @@ -166,8 +188,6 @@ var loadCommit = function() { } else { $("details").innerHTML = "This is a large commit. Click here or press 'v' to view."; } - + hideNotification(); setGravatar(commit.author_email, $("gravatar")); - - scroll(0, 0); -} +} \ No newline at end of file