Skip to content

Commit 5ea2d5e

Browse files
committed
Merge pull request #155 from ksuther/master
Asynchronously update submodules and load commit diffs
2 parents 2cedd04 + 542ff91 commit 5ea2d5e

File tree

4 files changed

+103
-93
lines changed

4 files changed

+103
-93
lines changed

Controller/PBSubmoduleController.m

+31-30
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,37 @@ - (id) initWithRepository:(PBGitRepository *) repo {
2121

2222

2323
- (void) reload {
24-
NSArray *arguments = [NSArray arrayWithObjects:@"submodule", @"status", @"--recursive", nil];
25-
NSString *output = [repository outputInWorkdirForArguments:arguments];
26-
NSArray *lines = [output componentsSeparatedByString:@"\n"];
27-
28-
NSMutableArray *loadedSubmodules = [[NSMutableArray alloc] initWithCapacity:[lines count]];
29-
30-
for (NSString *submoduleLine in lines) {
31-
if ([submoduleLine length] == 0)
32-
continue;
33-
PBGitSubmodule *submodule = [[PBGitSubmodule alloc] initWithRawSubmoduleStatusString:submoduleLine];
34-
if (submodule)
35-
[loadedSubmodules addObject:submodule];
36-
}
37-
38-
NSMutableArray *groupedSubmodules = [[NSMutableArray alloc] init];
39-
for (PBGitSubmodule *submodule in loadedSubmodules) {
40-
BOOL added = NO;
41-
for (PBGitSubmodule *addedItem in groupedSubmodules) {
42-
if ([[submodule path] hasPrefix:[addedItem path]]) {
43-
[addedItem addSubmodule:submodule];
44-
added = YES;
45-
}
46-
}
47-
if (!added) {
48-
[groupedSubmodules addObject:submodule];
49-
}
50-
}
51-
52-
53-
submodules = loadedSubmodules;
24+
dispatch_async(PBGetWorkQueue(), ^{
25+
NSArray *arguments = [NSArray arrayWithObjects:@"submodule", @"status", @"--recursive", nil];
26+
NSString *output = [repository outputInWorkdirForArguments:arguments];
27+
NSArray *lines = [output componentsSeparatedByString:@"\n"];
28+
29+
NSMutableArray *loadedSubmodules = [[NSMutableArray alloc] initWithCapacity:[lines count]];
30+
31+
for (NSString *submoduleLine in lines) {
32+
if ([submoduleLine length] == 0)
33+
continue;
34+
PBGitSubmodule *submodule = [[PBGitSubmodule alloc] initWithRawSubmoduleStatusString:submoduleLine];
35+
if (submodule)
36+
[loadedSubmodules addObject:submodule];
37+
}
38+
39+
NSMutableArray *groupedSubmodules = [[NSMutableArray alloc] init];
40+
for (PBGitSubmodule *submodule in loadedSubmodules) {
41+
BOOL added = NO;
42+
for (PBGitSubmodule *addedItem in groupedSubmodules) {
43+
if ([[submodule path] hasPrefix:[addedItem path]]) {
44+
[addedItem addSubmodule:submodule];
45+
added = YES;
46+
}
47+
}
48+
if (!added) {
49+
[groupedSubmodules addObject:submodule];
50+
}
51+
}
52+
53+
submodules = loadedSubmodules;
54+
});
5455
}
5556

5657
#pragma mark -

English.lproj/PBChangeRemoteUrlSheet.xib

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<object class="NSWindowTemplate" id="1005">
4444
<int key="NSWindowStyleMask">15</int>
4545
<int key="NSWindowBacking">2</int>
46-
<string key="NSWindowRect">{{63, 1353}, {764, 148}}</string>
46+
<string key="NSWindowRect">{{63, 500}, {764, 148}}</string>
4747
<int key="NSWTFlags">544735232</int>
4848
<string key="NSWindowTitle">Change Remote URL</string>
4949
<string key="NSWindowClass">NSWindow</string>

English.lproj/PBCloneRepositoryPanel.xib

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<object class="NSWindowTemplate" id="1005">
4444
<int key="NSWindowStyleMask">15</int>
4545
<int key="NSWindowBacking">2</int>
46-
<string key="NSWindowRect">{{63, 1353}, {488, 185}}</string>
46+
<string key="NSWindowRect">{{63, 500}, {488, 185}}</string>
4747
<int key="NSWTFlags">544735232</int>
4848
<string key="NSWindowTitle">Clone Git Repository</string>
4949
<string key="NSWindowClass">NSWindow</string>

PBWebCommitController.m

+70-61
Original file line numberDiff line numberDiff line change
@@ -83,67 +83,76 @@ - (void)commitDetailsLoaded:(NSNotification *)notification
8383
{
8484
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadToEndOfFileCompletionNotification object:nil];
8585

86-
NSData *data = [[notification userInfo] valueForKey:NSFileHandleNotificationDataItem];
87-
if (!data)
88-
return;
89-
90-
NSString *details = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
91-
if (!details)
92-
details = [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
93-
94-
if (!details)
95-
return;
96-
97-
// Header
98-
NSArray *headerItems = [self parseHeader:details];
99-
NSString *header = [self htmlForHeader:headerItems withRefs:[self refsForCurrentCommit]];
100-
101-
// In case the commit is a merge, we need to explicity give diff-tree the
102-
// list of parents, or else it will yield an empty result.
103-
// If it's not a merge, this won't hurt.
104-
NSMutableArray *allParents = [NSMutableArray array];
105-
106-
for (NSDictionary *item in headerItems)
107-
if ([[item objectForKey:kHeaderKeyName] isEqualToString:@"parent"])
108-
[allParents addObject:[item objectForKey:kHeaderKeyContent]];
109-
110-
NSArray *parents = [self chooseDiffParents:allParents];
111-
112-
// File Stats
113-
NSMutableDictionary *stats = [self parseStats:details];
114-
115-
// File list
116-
NSMutableArray *args = [NSMutableArray arrayWithObjects:@"diff-tree", @"--root", @"-r", @"-C90%", @"-M90%", nil];
117-
[args addObjectsFromArray:parents];
118-
[args addObject:currentSha];
119-
NSString *dt = [repository outputInWorkdirForArguments:args];
120-
NSString *fileList = [GLFileView parseDiffTree:dt withStats:stats];
121-
122-
// Diffs list
123-
args = [NSMutableArray arrayWithObjects:@"diff-tree", @"--root", @"--cc", @"-C90%", @"-M90%", nil];
124-
[args addObjectsFromArray:parents];
125-
[args addObject:currentSha];
126-
NSString *d = [repository outputInWorkdirForArguments:args];
127-
NSString *html;
128-
if(showLongDiffs || [d length] < 200000)
129-
{
130-
showLongDiffs = FALSE;
131-
NSString *diffs = [GLFileView parseDiff:d];
132-
html = [NSString stringWithFormat:@"%@%@<div id='diffs'>%@</div>",header,fileList,diffs];
133-
} else {
134-
html = [NSString stringWithFormat:@"%@%@<div id='diffs'><p>This is a very large commit. It may take a long time to load the diff. Click <a href='' onclick='showFullDiff(); return false;'>here</a> to show anyway.</p></div>",header,fileList,currentSha];
135-
}
136-
137-
html = [html stringByReplacingOccurrencesOfString:@"{SHA_PREV}" withString:[NSString stringWithFormat:@"%@^",currentSha]];
138-
html = [html stringByReplacingOccurrencesOfString:@"{SHA}" withString:currentSha];
139-
140-
[[view windowScriptObject] callWebScriptMethod:@"showCommit" withArguments:[NSArray arrayWithObject:html]];
141-
142-
#ifdef DEBUG_BUILD
143-
NSString *dom = [(DOMHTMLElement*)[[[view mainFrame] DOMDocument] documentElement] outerHTML];
144-
NSString *tmpFile = @"~/tmp/test2.html";
145-
[dom writeToFile:[tmpFile stringByExpandingTildeInPath] atomically:true encoding:NSUTF8StringEncoding error:nil];
146-
#endif
86+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
87+
NSData *data = [[notification userInfo] valueForKey:NSFileHandleNotificationDataItem];
88+
if (!data)
89+
return;
90+
91+
NSString *details = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
92+
if (!details)
93+
details = [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
94+
95+
if (!details)
96+
return;
97+
98+
// Header
99+
NSArray *headerItems = [self parseHeader:details];
100+
NSString *header = [self htmlForHeader:headerItems withRefs:[self refsForCurrentCommit]];
101+
102+
// In case the commit is a merge, we need to explicity give diff-tree the
103+
// list of parents, or else it will yield an empty result.
104+
// If it's not a merge, this won't hurt.
105+
NSMutableArray *allParents = [NSMutableArray array];
106+
107+
for (NSDictionary *item in headerItems)
108+
if ([[item objectForKey:kHeaderKeyName] isEqualToString:@"parent"])
109+
[allParents addObject:[item objectForKey:kHeaderKeyContent]];
110+
111+
NSArray *parents = [self chooseDiffParents:allParents];
112+
113+
// File Stats
114+
NSMutableDictionary *stats = [self parseStats:details];
115+
116+
// File list
117+
NSMutableArray *args = [NSMutableArray arrayWithObjects:@"diff-tree", @"--root", @"-r", @"-C90%", @"-M90%", nil];
118+
[args addObjectsFromArray:parents];
119+
[args addObject:currentSha];
120+
NSString *dt = [repository outputInWorkdirForArguments:args];
121+
NSString *fileList = [GLFileView parseDiffTree:dt withStats:stats];
122+
123+
// Diffs list
124+
NSString *loadingSha = currentSha;
125+
126+
args = [NSMutableArray arrayWithObjects:@"diff-tree", @"--root", @"--cc", @"-C90%", @"-M90%", nil];
127+
[args addObjectsFromArray:parents];
128+
[args addObject:loadingSha];
129+
NSString *d = [repository outputInWorkdirForArguments:args];
130+
NSString *html;
131+
if(showLongDiffs || [d length] < 200000)
132+
{
133+
showLongDiffs = FALSE;
134+
NSString *diffs = [GLFileView parseDiff:d];
135+
html = [NSString stringWithFormat:@"%@%@<div id='diffs'>%@</div>",header,fileList,diffs];
136+
} else {
137+
html = [NSString stringWithFormat:@"%@%@<div id='diffs'><p>This is a very large commit. It may take a long time to load the diff. Click <a href='' onclick='showFullDiff(); return false;'>here</a> to show anyway.</p></div>",header,fileList,currentSha];
138+
}
139+
140+
html = [html stringByReplacingOccurrencesOfString:@"{SHA_PREV}" withString:[NSString stringWithFormat:@"%@^",currentSha]];
141+
html = [html stringByReplacingOccurrencesOfString:@"{SHA}" withString:currentSha];
142+
143+
dispatch_async(dispatch_get_main_queue(), ^{
144+
// If a bunch of commits were selected quickly we check to make sure the commit we requested is still active
145+
if ([currentSha isEqualToString:loadingSha]) {
146+
[[view windowScriptObject] callWebScriptMethod:@"showCommit" withArguments:[NSArray arrayWithObject:html]];
147+
148+
#ifdef DEBUG_BUILD
149+
NSString *dom = [(DOMHTMLElement*)[[[view mainFrame] DOMDocument] documentElement] outerHTML];
150+
NSString *tmpFile = @"~/tmp/test2.html";
151+
[dom writeToFile:[tmpFile stringByExpandingTildeInPath] atomically:true encoding:NSUTF8StringEncoding error:nil];
152+
#endif
153+
}
154+
});
155+
});
147156
}
148157

149158
- (NSString*) refsForCurrentCommit

0 commit comments

Comments
 (0)