mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
PBWebHistoryController: show the commit diff async
This should make the GUI more responsive by allowing the diff to be read in the background. This assumes that [PBGitCommit details] is threadsafe, so we should keep it that way.
This commit is contained in:
@@ -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)
|
||||
|
||||
+21
-21
@@ -8,7 +8,7 @@
|
||||
<string key="IBDocument.HIToolboxVersion">352.00</string>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="3"/>
|
||||
<integer value="9"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@@ -738,7 +738,7 @@
|
||||
<object class="NSTextView" id="239018083">
|
||||
<reference key="NSNextResponder" ref="948090592"/>
|
||||
<int key="NSvFlags">2322</int>
|
||||
<string key="NSFrameSize">{835, 37}</string>
|
||||
<string key="NSFrameSize">{835, 70}</string>
|
||||
<reference key="NSSuperview" ref="948090592"/>
|
||||
<object class="NSTextContainer" key="NSTextContainer" id="53511606">
|
||||
<object class="NSLayoutManager" key="NSLayoutManager">
|
||||
@@ -1125,7 +1125,7 @@
|
||||
<string>WebURLsWithTitlesPboardType</string>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{543, 71}</string>
|
||||
<string key="NSFrameSize">{543, 112}</string>
|
||||
<reference key="NSSuperview" ref="321980917"/>
|
||||
<object class="NSTextContainer" key="NSTextContainer" id="480935218">
|
||||
<object class="NSLayoutManager" key="NSLayoutManager">
|
||||
@@ -1468,22 +1468,6 @@
|
||||
</object>
|
||||
<int key="connectionID">66</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: selection.details</string>
|
||||
<reference key="source" ref="239018083"/>
|
||||
<reference key="destination" ref="391209158"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="239018083"/>
|
||||
<reference key="NSDestination" ref="391209158"/>
|
||||
<string key="NSLabel">value: selection.details</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">selection.details</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">69</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">selectedIndex: selectedTab</string>
|
||||
@@ -1866,6 +1850,22 @@
|
||||
</object>
|
||||
<int key="connectionID">217</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: rawCommit.details</string>
|
||||
<reference key="source" ref="239018083"/>
|
||||
<reference key="destination" ref="1001"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="239018083"/>
|
||||
<reference key="NSDestination" ref="1001"/>
|
||||
<string key="NSLabel">value: rawCommit.details</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">rawCommit.details</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">230</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
@@ -2537,7 +2537,7 @@
|
||||
</object>
|
||||
</object>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>{{387, 484}, {852, 432}}</string>
|
||||
<string>{{592, 572}, {852, 432}}</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
@@ -2567,7 +2567,7 @@
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">225</int>
|
||||
<int key="maxID">230</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 += '<span class="refs ' + ref.type() + (CurrentBranch == ref.ref ? ' currentBranch' : '') + '">' + ref.shortName() + '</span>';
|
||||
refs.innerHTML += '<span class="refs ' + ref.type() + (currentRef == ref.ref ? ' currentBranch' : '') + '">' + ref.shortName() + '</span>';
|
||||
}
|
||||
} 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 + " <<a href='mailto:" + commit.author_email + "'>" + commit.author_email + "</a>>";
|
||||
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 = "<td class='property_name'>Parent:</td><td><a href='' onclick=\"selectCommit(this.innerHTML); return false;\">" + parent + "</a></td>";
|
||||
var newRow = $("commit_header").insertRow(-1);
|
||||
new_row.innerHTML = "<td class='property_name'>Parent:</td><td>" +
|
||||
"<a href='' onclick='selectCommit(this.innerHTML); return false;'>" +
|
||||
commit.parents[i] + "</a></td>";
|
||||
}
|
||||
|
||||
showRefs();
|
||||
// Scroll to top
|
||||
scroll(0, 0);
|
||||
}
|
||||
|
||||
var loadExtendedCommit = function(commit)
|
||||
{
|
||||
if (commit.author_email)
|
||||
$("authorID").innerHTML = commit.author_name + " <<a href='mailto:" + commit.author_email + "'>" + commit.author_email + "</a>>";
|
||||
|
||||
$("date").innerHTML = commit.author_date;
|
||||
$("message").innerHTML = commit.message.replace(/\n/g,"<br>");
|
||||
|
||||
if (commit.diff.length < 200000) {
|
||||
@@ -166,8 +188,6 @@ var loadCommit = function() {
|
||||
} else {
|
||||
$("details").innerHTML = "<a class='showdiff' href='' onclick='showDiffs(); return false;'>This is a large commit. Click here or press 'v' to view.</a>";
|
||||
}
|
||||
|
||||
hideNotification();
|
||||
setGravatar(commit.author_email, $("gravatar"));
|
||||
|
||||
scroll(0, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user