Skip to content

Commit b7645ec

Browse files
committed
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.
1 parent db39ff7 commit b7645ec

File tree

4 files changed

+91
-73
lines changed

4 files changed

+91
-73
lines changed

PBGitCommit.m

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ - (NSArray*) treeContents
3333
return self;
3434
}
3535

36+
// NOTE: This method should remain threadsafe, as we load it in async
37+
// from the web view.
3638
- (NSString*) details
3739
{
3840
if (details != nil)

PBGitHistoryView.xib

+21-21
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<string key="IBDocument.HIToolboxVersion">352.00</string>
99
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
1010
<bool key="EncodedWithXMLCoder">YES</bool>
11-
<integer value="3"/>
11+
<integer value="9"/>
1212
</object>
1313
<object class="NSArray" key="IBDocument.PluginDependencies">
1414
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -738,7 +738,7 @@
738738
<object class="NSTextView" id="239018083">
739739
<reference key="NSNextResponder" ref="948090592"/>
740740
<int key="NSvFlags">2322</int>
741-
<string key="NSFrameSize">{835, 37}</string>
741+
<string key="NSFrameSize">{835, 70}</string>
742742
<reference key="NSSuperview" ref="948090592"/>
743743
<object class="NSTextContainer" key="NSTextContainer" id="53511606">
744744
<object class="NSLayoutManager" key="NSLayoutManager">
@@ -1125,7 +1125,7 @@
11251125
<string>WebURLsWithTitlesPboardType</string>
11261126
</object>
11271127
</object>
1128-
<string key="NSFrameSize">{543, 71}</string>
1128+
<string key="NSFrameSize">{543, 112}</string>
11291129
<reference key="NSSuperview" ref="321980917"/>
11301130
<object class="NSTextContainer" key="NSTextContainer" id="480935218">
11311131
<object class="NSLayoutManager" key="NSLayoutManager">
@@ -1468,22 +1468,6 @@
14681468
</object>
14691469
<int key="connectionID">66</int>
14701470
</object>
1471-
<object class="IBConnectionRecord">
1472-
<object class="IBBindingConnection" key="connection">
1473-
<string key="label">value: selection.details</string>
1474-
<reference key="source" ref="239018083"/>
1475-
<reference key="destination" ref="391209158"/>
1476-
<object class="NSNibBindingConnector" key="connector">
1477-
<reference key="NSSource" ref="239018083"/>
1478-
<reference key="NSDestination" ref="391209158"/>
1479-
<string key="NSLabel">value: selection.details</string>
1480-
<string key="NSBinding">value</string>
1481-
<string key="NSKeyPath">selection.details</string>
1482-
<int key="NSNibBindingConnectorVersion">2</int>
1483-
</object>
1484-
</object>
1485-
<int key="connectionID">69</int>
1486-
</object>
14871471
<object class="IBConnectionRecord">
14881472
<object class="IBBindingConnection" key="connection">
14891473
<string key="label">selectedIndex: selectedTab</string>
@@ -1866,6 +1850,22 @@
18661850
</object>
18671851
<int key="connectionID">217</int>
18681852
</object>
1853+
<object class="IBConnectionRecord">
1854+
<object class="IBBindingConnection" key="connection">
1855+
<string key="label">value: rawCommit.details</string>
1856+
<reference key="source" ref="239018083"/>
1857+
<reference key="destination" ref="1001"/>
1858+
<object class="NSNibBindingConnector" key="connector">
1859+
<reference key="NSSource" ref="239018083"/>
1860+
<reference key="NSDestination" ref="1001"/>
1861+
<string key="NSLabel">value: rawCommit.details</string>
1862+
<string key="NSBinding">value</string>
1863+
<string key="NSKeyPath">rawCommit.details</string>
1864+
<int key="NSNibBindingConnectorVersion">2</int>
1865+
</object>
1866+
</object>
1867+
<int key="connectionID">230</int>
1868+
</object>
18691869
</object>
18701870
<object class="IBMutableOrderedSet" key="objectRecords">
18711871
<object class="NSArray" key="orderedObjects">
@@ -2537,7 +2537,7 @@
25372537
</object>
25382538
</object>
25392539
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2540-
<string>{{387, 484}, {852, 432}}</string>
2540+
<string>{{592, 572}, {852, 432}}</string>
25412541
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
25422542
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
25432543
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2567,7 +2567,7 @@
25672567
</object>
25682568
</object>
25692569
<nil key="sourceID"/>
2570-
<int key="maxID">225</int>
2570+
<int key="maxID">230</int>
25712571
</object>
25722572
<object class="IBClassDescriber" key="IBDocument.Classes">
25732573
<object class="NSMutableArray" key="referencedPartialClassDescriptions">

PBWebHistoryController.m

+3-7
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,16 @@ - (void) changeContentTo: (PBGitCommit *) content
4747
if (content == nil || !finishedLoading)
4848
return;
4949

50-
id script = [view windowScriptObject];
51-
[script setValue: content forKey:@"CommitObject"];
52-
[script setValue:[[[historyController repository] headRef] simpleRef] forKey:@"CurrentBranch"];
53-
5450
// The sha is the same, but refs may have changed.. reload it lazy
5551
if ([currentSha isEqualToString: content.sha])
5652
{
57-
[script callWebScriptMethod:@"reload" withArguments: nil];
53+
[[self script] callWebScriptMethod:@"reload" withArguments: nil];
5854
return;
5955
}
60-
6156
currentSha = content.sha;
6257

63-
[script callWebScriptMethod:@"loadCommit" withArguments: nil];
58+
NSArray *arguments = [NSArray arrayWithObjects:content, [[[historyController repository] headRef] simpleRef], nil];
59+
[[self script] callWebScriptMethod:@"loadCommit" withArguments: arguments];
6460
}
6561

6662
- (void) selectCommit: (NSString*) sha

html/views/history/history.js

+65-45
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
11
var commit;
22
var Commit = function(obj) {
3-
this.raw = obj.details;
4-
this.refs = obj.refs;
53
this.object = obj;
64

7-
var diffStart = this.raw.indexOf("\ndiff ");
8-
var messageStart = this.raw.indexOf("\n\n") + 2;
5+
this.refs = obj.refs;
6+
this.author_name = obj.author;
7+
this.sha = obj.sha;
8+
this.parents = obj.parents;
9+
this.subject = obj.subject;
910

10-
if (diffStart > 0) {
11-
this.message = this.raw.substring(messageStart, diffStart).replace(/^ /gm, "").escapeHTML();
12-
this.diff = this.raw.substring(diffStart);
13-
} else {
14-
this.message = this.raw.substring(messageStart).replace(/^ /gm, "").escapeHTML();
15-
this.diff = "";
16-
}
17-
this.header = this.raw.substring(0, messageStart);
11+
// TODO:
12+
// this.author_date instant
1813

19-
this.sha = this.header.match(/^commit ([0-9a-f]{40,40})/)[1];
14+
// This all needs to be async
15+
this.loadedRaw = function(details) {
16+
this.raw = details;
2017

21-
var match = this.header.match(/\nauthor (.*) <(.*@.*)> ([0-9].*)/);
22-
this.author_name = match[1];
23-
if (!(match[2].match(/@[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/)))
24-
this.author_email = match[2];
18+
var diffStart = this.raw.indexOf("\ndiff ");
19+
var messageStart = this.raw.indexOf("\n\n") + 2;
2520

26-
this.author_date = new Date(parseInt(match[3]) * 1000);
21+
if (diffStart > 0) {
22+
this.message = this.raw.substring(messageStart, diffStart).replace(/^ /gm, "").escapeHTML();
23+
this.diff = this.raw.substring(diffStart);
24+
} else {
25+
this.message = this.raw.substring(messageStart).replace(/^ /gm, "").escapeHTML();
26+
this.diff = "";
27+
}
28+
this.header = this.raw.substring(0, messageStart);
2729

28-
match = this.header.match(/\ncommitter (.*) <(.*@.*)> ([0-9].*)/);
29-
this.committer_name = match[1];
30-
this.committer_email = match[2];
31-
this.committer_date = new Date(parseInt(match[3]) * 1000);
30+
var match = this.header.match(/\nauthor (.*) <(.*@.*)> ([0-9].*)/);
31+
if (!(match[2].match(/@[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/)))
32+
this.author_email = match[2];
3233

33-
this.parents = obj.parents;
34+
this.author_date = new Date(parseInt(match[3]) * 1000);
35+
36+
match = this.header.match(/\ncommitter (.*) <(.*@.*)> ([0-9].*)/);
37+
this.committer_name = match[1];
38+
this.committer_email = match[2];
39+
this.committer_date = new Date(parseInt(match[3]) * 1000);
40+
}
3441

3542
this.reloadRefs = function() {
3643
this.refs = CommitObject.refs;
3744
}
45+
46+
// this.loadedRaw(this.raw);
3847
};
3948

4049
var gistie = function() {
@@ -118,56 +127,67 @@ var reload = function() {
118127
showRefs();
119128
}
120129

121-
var showRefs = function() {
130+
var showRefs = function(currentRef) {
122131
var refs = $("refs");
123132
if (commit.refs) {
124133
refs.parentNode.style.display = "";
125134
refs.innerHTML = "";
126135
for (var i = 0; i < commit.refs.length; i++) {
127136
var ref = commit.refs[i], curBranch = "";
128-
refs.innerHTML += '<span class="refs ' + ref.type() + (CurrentBranch == ref.ref ? ' currentBranch' : '') + '">' + ref.shortName() + '</span>';
137+
refs.innerHTML += '<span class="refs ' + ref.type() + (currentRef == ref.ref ? ' currentBranch' : '') + '">' + ref.shortName() + '</span>';
129138
}
130139
} else
131140
refs.parentNode.style.display = "none";
132141
}
133142

134-
var loadCommit = function() {
135-
commit = new Commit(CommitObject);
136-
$("notification").style.display = "none";
143+
var loadCommit = function(commitObject, currentRef) {
144+
// These are only the things we can do instantly.
145+
// Other information will be loaded later by loadExtendedCommit
146+
commit = new Commit(commitObject);
147+
Controller.callSelector_onObject_callBack_("details", commitObject,
148+
function(data) { commit.loadedRaw(data); loadExtendedCommit(commit); });
149+
commit.currentRef = currentRef;
137150

138-
$("commitID").innerHTML = commit.sha;
139-
140-
if (commit.author_email)
141-
$("authorID").innerHTML = commit.author_name + " &lt;<a href='mailto:" + commit.author_email + "'>" + commit.author_email + "</a>&gt;";
142-
else
143-
$("authorID").innerHTML = commit.author_name;
151+
notify("Loading commit…", 0);
144152

145-
$("date").innerHTML = commit.author_date;
146-
$("subjectID").innerHTML =CommitObject.subject.escapeHTML();
153+
$("commitID").innerHTML = commit.sha;
154+
$("authorID").innerHTML = commit.author_name;
155+
$("subjectID").innerHTML = commit.subject.escapeHTML();
156+
$("details").innerHTML = ""
157+
$("message").innerHTML = ""
158+
$("date").innerHTML = ""
159+
showRefs(commit.currentRef);
147160

148-
var commitHeader = $("commit_header");
149161
for (var i = 0; i < commitHeader.rows.length; i++) {
150-
var row = commitHeader.rows[i];
162+
var row = $("commit_header").rows[i];
151163
if (row.innerHTML.match(/Parent:/))
152164
row.parentNode.removeChild(row);
153165
}
154166

155167
for (var i = 0; i < commit.parents; i++) {
156-
var parent = commit.parents[i], newRow = commitHeader.insertRow(-1);
157-
new_row.innerHTML = "<td class='property_name'>Parent:</td><td><a href='' onclick=\"selectCommit(this.innerHTML); return false;\">" + parent + "</a></td>";
168+
var newRow = $("commit_header").insertRow(-1);
169+
new_row.innerHTML = "<td class='property_name'>Parent:</td><td>" +
170+
"<a href='' onclick='selectCommit(this.innerHTML); return false;'>" +
171+
commit.parents[i] + "</a></td>";
158172
}
159173

160-
showRefs();
174+
// Scroll to top
175+
scroll(0, 0);
176+
}
177+
178+
var loadExtendedCommit = function(commit)
179+
{
180+
if (commit.author_email)
181+
$("authorID").innerHTML = commit.author_name + " &lt;<a href='mailto:" + commit.author_email + "'>" + commit.author_email + "</a>&gt;";
161182

183+
$("date").innerHTML = commit.author_date;
162184
$("message").innerHTML = commit.message.replace(/\n/g,"<br>");
163185

164186
if (commit.diff.length < 200000) {
165187
showDiffs();
166188
} else {
167189
$("details").innerHTML = "<a class='showdiff' href='' onclick='showDiffs(); return false;'>This is a large commit. Click here or press 'v' to view.</a>";
168190
}
169-
191+
hideNotification();
170192
setGravatar(commit.author_email, $("gravatar"));
171-
172-
scroll(0, 0);
173-
}
193+
}

0 commit comments

Comments
 (0)