Skip to content

Commit 1a5a211

Browse files
committed
Merge branch 'stable'
* stable: HistoryView: Don't show the 'loading commit' thing until after 500 ms. HistoryView: Remove raw view HistoryView: don't load in commit information in a separate thread anymore Fix UTF-8 bug in NSString_RegEx CommitView: Don't keep rearranging when iterating over files IndexController: de-privatize the index-stopping stuff
2 parents 4476892 + 5972bd4 commit 1a5a211

9 files changed

+224
-387
lines changed

NSString_RegEx.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ - (NSArray *) substringsMatchingRegularExpression:(NSString *)pattern count:(int
5757
break;
5858

5959
NSRange range = NSMakeRange(pmatch[i].rm_so, pmatch[i].rm_eo - pmatch[i].rm_so);
60-
NSString * substring = [self substringWithRange:range];
60+
NSString * substring = [[[NSString alloc] initWithBytes:[self UTF8String] + range.location
61+
length:range.length
62+
encoding:NSUTF8StringEncoding] autorelease];
6163
[outMatches addObject:substring];
6264

6365
if (ranges)

PBGitCommit.m

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,10 @@ - (NSString *)realSha
6666
return str;
6767
}
6868

69-
// NOTE: This method should remain threadsafe, as we load it in async
70-
// from the web view.
69+
// FIXME: Remove this method once it's unused.
7170
- (NSString*) details
7271
{
73-
if (details != nil)
74-
return details;
75-
76-
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", @"--no-color", [self realSha], nil];
77-
if (![PBGitDefaults showWhitespaceDifferences])
78-
[arguments insertObject:@"-w" atIndex:1];
79-
80-
details = [self.repository outputForArguments:arguments];
81-
82-
return details;
72+
return @"";
8373
}
8474

8575
- (NSString *) patch

PBGitCommitController.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#import "PBChangedFile.h"
1212
#import "PBWebChangesController.h"
1313
#import "NSString_RegEx.h"
14-
14+
#import "PBGitIndexController.h"
1515

1616
@interface PBGitCommitController (PrivateMethods)
1717
- (NSArray *) linesFromNotification:(NSNotification *)notification;
@@ -240,6 +240,7 @@ - (NSMutableDictionary *)dictionaryForLines:(NSArray *)lines
240240
- (void) addFilesFromDictionary:(NSMutableDictionary *)dictionary staged:(BOOL)staged tracked:(BOOL)tracked
241241
{
242242
// Iterate over all existing files
243+
[indexController stopTrackingIndex];
243244
for (PBChangedFile *file in files) {
244245
NSArray *fileStatus = [dictionary objectForKey:file.path];
245246
// Object found, this is still a cached / uncached thing
@@ -270,6 +271,7 @@ - (void) addFilesFromDictionary:(NSMutableDictionary *)dictionary staged:(BOOL)s
270271
file.hasUnstagedChanges = NO;
271272
}
272273
}
274+
[indexController resumeTrackingIndex];
273275

274276
// Do new files
275277
if (![[dictionary allKeys] count])

PBGitHistoryController.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ - (void) updateKeys
6666

6767
switch (self.selectedTab) {
6868
case 0: self.webCommit = realCommit; break;
69-
case 1: self.rawCommit = realCommit; break;
70-
case 2: self.gitTree = realCommit.tree; break;
69+
case 1: self.gitTree = realCommit.tree; break;
7170
}
7271
}
7372

PBGitHistoryView.xib

Lines changed: 148 additions & 358 deletions
Large diffs are not rendered by default.

PBGitIndexController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@
3636
- (NSString *) stagedChangesForFile:(PBChangedFile *)file;
3737
- (NSString *) unstagedChangesForFile:(PBChangedFile *)file;
3838

39+
- (void)stopTrackingIndex;
40+
- (void)resumeTrackingIndex;
41+
3942
- (NSMenu *) menuForTable:(NSTableView *)table;
4043
@end

PBGitIndexController.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
#define FileChangesTableViewType @"GitFileChangedType"
1414

15-
@interface PBGitIndexController (PrivateMethods)
16-
- (void)stopTrackingIndex;
17-
- (void)resumeTrackingIndex;
18-
@end
19-
2015
@implementation PBGitIndexController
2116

2217
@synthesize contextSize;

PBWebHistoryController.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "PBWebHistoryController.h"
10+
#import "PBGitDefaults.h"
1011

1112
@implementation PBWebHistoryController
1213

@@ -49,6 +50,37 @@ - (void) changeContentTo: (PBGitCommit *) content
4950

5051
NSArray *arguments = [NSArray arrayWithObjects:content, [[[historyController repository] headRef] simpleRef], nil];
5152
[[self script] callWebScriptMethod:@"loadCommit" withArguments: arguments];
53+
54+
// Now we load the extended details. We used to do this in a separate thread,
55+
// but this caused some funny behaviour because NSTask's and NSThread's don't really
56+
// like each other. Instead, just do it async.
57+
58+
NSMutableArray *taskArguments = [NSMutableArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", @"--no-color", currentSha, nil];
59+
if (![PBGitDefaults showWhitespaceDifferences])
60+
[taskArguments insertObject:@"-w" atIndex:1];
61+
62+
NSFileHandle *handle = [repository handleForArguments:taskArguments];
63+
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
64+
// Remove notification, in case we have another one running
65+
[nc removeObserver:self];
66+
[nc addObserver:self selector:@selector(commitDetailsLoaded:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
67+
[handle readToEndOfFileInBackgroundAndNotify];
68+
}
69+
70+
- (void)commitDetailsLoaded:(NSNotification *)notification
71+
{
72+
NSData *data = [[notification userInfo] valueForKey:NSFileHandleNotificationDataItem];
73+
if (!data)
74+
return;
75+
76+
NSString *details = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
77+
if (!details)
78+
details = [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
79+
80+
if (!details)
81+
return;
82+
83+
[[view windowScriptObject] callWebScriptMethod:@"loadCommitDetails" withArguments:[NSArray arrayWithObject:details]];
5284
}
5385

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

html/views/history/history.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
var commit;
2+
3+
// Create a new Commit object
4+
// obj: PBGitCommit object
25
var Commit = function(obj) {
36
this.object = obj;
47

@@ -7,12 +10,14 @@ var Commit = function(obj) {
710
this.sha = obj.realSha();
811
this.parents = obj.parents;
912
this.subject = obj.subject;
13+
this.notificationID = null;
1014

1115
// TODO:
1216
// this.author_date instant
1317

14-
// This all needs to be async
15-
this.loadedRaw = function(details) {
18+
// This can be called later with the output of
19+
// 'git show' to fill in missing commit details (such as a diff)
20+
this.parseDetails = function(details) {
1621
this.raw = details;
1722

1823
var diffStart = this.raw.indexOf("\ndiff ");
@@ -138,6 +143,7 @@ var selectCommit = function(a) {
138143
Controller.selectCommit_(a);
139144
}
140145

146+
// Relead only refs
141147
var reload = function() {
142148
$("notification").style.display = "none";
143149
commit.reloadRefs();
@@ -159,14 +165,16 @@ var showRefs = function() {
159165

160166
var loadCommit = function(commitObject, currentRef) {
161167
// These are only the things we can do instantly.
162-
// Other information will be loaded later by loadExtendedCommit
168+
// Other information will be loaded later by loadCommitDetails,
169+
// Which will be called from the controller once
170+
// the commit details are in.
171+
172+
if (commit && commit.notificationID)
173+
clearTimeout(commit.notificationID);
174+
163175
commit = new Commit(commitObject);
164-
Controller.callSelector_onObject_callBack_("details", commitObject,
165-
function(data) { commit.loadedRaw(data); loadExtendedCommit(commit); });
166176
commit.currentRef = currentRef;
167177

168-
notify("Loading commit…", 0);
169-
170178
$("commitID").innerHTML = commit.sha;
171179
$("authorID").innerHTML = commit.author_name;
172180
$("subjectID").innerHTML = commit.subject.escapeHTML();
@@ -196,9 +204,18 @@ var loadCommit = function(commitObject, currentRef) {
196204
"<a href='' onclick='selectCommit(this.innerHTML); return false;'>" +
197205
commit.parents[i] + "</a></td>";
198206
}
207+
208+
commit.notificationID = setTimeout(function() {
209+
if (!commit.fullyLoaded)
210+
notify("Loading commit…", 0);
211+
commit.notificationID = null;
212+
}, 500);
213+
199214
}
200215

201216
var showDiff = function() {
217+
218+
// Callback for the diff highlighter. Used to generate a filelist
202219
var newfile = function(name1, name2, id, mode_change, old_mode, new_mode) {
203220
var button = document.createElement("div");
204221
var p = document.createElement("p");
@@ -270,8 +287,15 @@ var enableFeatures = function()
270287
enableFeature("gravatar", $("gravatar"))
271288
}
272289

273-
var loadExtendedCommit = function(commit)
290+
var loadCommitDetails = function(data)
274291
{
292+
commit.parseDetails(data);
293+
294+
if (commit.notificationID)
295+
clearTimeout(commit.notificationID)
296+
else
297+
$("notification").style.display = "none";
298+
275299
var formatEmail = function(name, email) {
276300
return email ? name + " &lt;<a href='mailto:" + email + "'>" + email + "</a>&gt;" : name;
277301
}

0 commit comments

Comments
 (0)