diff --git a/NSString_RegEx.m b/NSString_RegEx.m index ee0e9bd..38d3848 100644 --- a/NSString_RegEx.m +++ b/NSString_RegEx.m @@ -57,7 +57,9 @@ break; NSRange range = NSMakeRange(pmatch[i].rm_so, pmatch[i].rm_eo - pmatch[i].rm_so); - NSString * substring = [self substringWithRange:range]; + NSString * substring = [[[NSString alloc] initWithBytes:[self UTF8String] + range.location + length:range.length + encoding:NSUTF8StringEncoding] autorelease]; [outMatches addObject:substring]; if (ranges) diff --git a/PBGitCommit.m b/PBGitCommit.m index b883c95..9ebe3b5 100644 --- a/PBGitCommit.m +++ b/PBGitCommit.m @@ -66,20 +66,10 @@ return str; } -// NOTE: This method should remain threadsafe, as we load it in async -// from the web view. +// FIXME: Remove this method once it's unused. - (NSString*) details { - if (details != nil) - return details; - - NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", @"--no-color", [self realSha], nil]; - if (![PBGitDefaults showWhitespaceDifferences]) - [arguments insertObject:@"-w" atIndex:1]; - - details = [self.repository outputForArguments:arguments]; - - return details; + return @""; } - (NSString *) patch diff --git a/PBGitCommitController.m b/PBGitCommitController.m index 1e894ee..3f156aa 100644 --- a/PBGitCommitController.m +++ b/PBGitCommitController.m @@ -11,7 +11,7 @@ #import "PBChangedFile.h" #import "PBWebChangesController.h" #import "NSString_RegEx.h" - +#import "PBGitIndexController.h" @interface PBGitCommitController (PrivateMethods) - (NSArray *) linesFromNotification:(NSNotification *)notification; @@ -240,6 +240,7 @@ - (void) addFilesFromDictionary:(NSMutableDictionary *)dictionary staged:(BOOL)staged tracked:(BOOL)tracked { // Iterate over all existing files + [indexController stopTrackingIndex]; for (PBChangedFile *file in files) { NSArray *fileStatus = [dictionary objectForKey:file.path]; // Object found, this is still a cached / uncached thing @@ -270,6 +271,7 @@ file.hasUnstagedChanges = NO; } } + [indexController resumeTrackingIndex]; // Do new files if (![[dictionary allKeys] count]) diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index f8ad04a..a9fde36 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -66,8 +66,7 @@ switch (self.selectedTab) { case 0: self.webCommit = realCommit; break; - case 1: self.rawCommit = realCommit; break; - case 2: self.gitTree = realCommit.tree; break; + case 1: self.gitTree = realCommit.tree; break; } } diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index b8c820e..68b7789 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -2,14 +2,14 @@ 1050 - 9L30 + 9L31a 677 949.54 353.00 YES - + YES @@ -98,7 +98,7 @@ 293 - {{376, 6}, {99, 25}} + {{376, 6}, {71, 25}} YES @@ -124,23 +124,14 @@ 2 - - NSImage - NSListViewTemplate - - - Raw View - 1 - 2 - - - 3.200000e+01 NSImage NSPathTemplate + Tree View - 0 + 9 + 2 2 @@ -320,7 +311,6 @@ 3 YES - NO YES @@ -410,7 +400,7 @@ 1 - + 274 YES @@ -477,268 +467,10 @@ - - 2 - - - 256 - - YES - - - 274 - - YES - - - 2304 - - YES - - - 2322 - {835, 70} - - - - - - Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum Et harumd und lookum like Greek to me, dereud facilis est er expedit distinct. Nam liber te conscient to factor tum poen legum odioque civiuda - - - YES - - YES - NSFont - NSParagraphStyle - - - YES - - Monaco - 1.000000e+01 - 16 - - - 3 - - YES - - 0.000000e+00 - - - 5.600000e+01 - - - 1.120000e+02 - - - 1.680000e+02 - - - 2.240000e+02 - - - 2.800000e+02 - - - 3.360000e+02 - - - 3.920000e+02 - - - 4.480000e+02 - - - 5.040000e+02 - - - 5.600000e+02 - - - 6.160000e+02 - - - 6.720000e+02 - - - 7.280000e+02 - - - 7.840000e+02 - - - 8.400000e+02 - - - 8.960000e+02 - - - 9.520000e+02 - - - 1.008000e+03 - - - 1.064000e+03 - - - 1.120000e+03 - - - 1.176000e+03 - - - 1.232000e+03 - - - 1.288000e+03 - - - 1.344000e+03 - - - 1.400000e+03 - - - 1.456000e+03 - - - 1.512000e+03 - - - 1.568000e+03 - - - 1.624000e+03 - - - 1.680000e+03 - - - 1.736000e+03 - - - - - - - - - YES - - - 6 - - - - 8.350000e+02 - 1 - - - 2369 - - - - YES - - YES - NSBackgroundColor - NSColor - - - YES - - 6 - System - selectedTextBackgroundColor - - - - 6 - System - selectedTextColor - - - - - - - YES - - YES - NSColor - NSUnderline - - - YES - - 1 - MCAwIDEAA - - - - - - - 6 - {1687, 1e+07} - {83, 0} - - - - {{1, 1}, {835, 185}} - - - - - - {4, -5} - 1 - - 4 - - - - 256 - {{836, 1}, {15, 185}} - - - _doScroller: - 2.240493e-01 - - - - 256 - {{-100, -100}, {87, 18}} - - 1 - - _doScroller: - 1.000000e+00 - 9.456522e-01 - - - {852, 187} - - - 18 - - - - - - {852, 186} - - Raw - - - Item 2 - + 256 YES @@ -869,7 +601,124 @@ Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum Et harumd und lookum like Greek to me, dereud facilis est er expedit distinct. Nam liber te conscient to factor tum poen legum odioque civiuda - + + YES + + YES + NSFont + NSParagraphStyle + + + YES + + Monaco + 1.000000e+01 + 16 + + + 3 + + YES + + 0.000000e+00 + + + 5.600000e+01 + + + 1.120000e+02 + + + 1.680000e+02 + + + 2.240000e+02 + + + 2.800000e+02 + + + 3.360000e+02 + + + 3.920000e+02 + + + 4.480000e+02 + + + 5.040000e+02 + + + 5.600000e+02 + + + 6.160000e+02 + + + 6.720000e+02 + + + 7.280000e+02 + + + 7.840000e+02 + + + 8.400000e+02 + + + 8.960000e+02 + + + 9.520000e+02 + + + 1.008000e+03 + + + 1.064000e+03 + + + 1.120000e+03 + + + 1.176000e+03 + + + 1.232000e+03 + + + 1.288000e+03 + + + 1.344000e+03 + + + 1.400000e+03 + + + 1.456000e+03 + + + 1.512000e+03 + + + 1.568000e+03 + + + 1.624000e+03 + + + 1.680000e+03 + + + 1.736000e+03 + + + + + @@ -896,8 +745,18 @@ YES - - + + 6 + System + selectedTextBackgroundColor + + + + 6 + System + selectedTextColor + + @@ -910,7 +769,10 @@ YES - + + 1 + MCAwIDEAA + @@ -927,7 +789,10 @@ - + + {4, -5} + 1 + 4 @@ -967,21 +832,20 @@ {852, 186} - Tree - + 6 YES YES YES - + @@ -1936,22 +1800,6 @@ 217 - - - value: rawCommit.details - - - - - - value: rawCommit.details - value - rawCommit.details - 2 - - - 230 - commitController @@ -2221,23 +2069,12 @@ YES - Bottom View - - 5 - - - YES - - - - Raw View - 6 @@ -2360,41 +2197,6 @@ - - 22 - - - YES - - - - - - 23 - - - YES - - - - - - - - 24 - - - - - 25 - - - - - 26 - - - 47 @@ -2819,11 +2621,9 @@ 20.IBPluginDependency 21.IBAttributePlaceholdersKey 21.IBPluginDependency - 22.IBPluginDependency 223.IBPluginDependency 224.IBPluginDependency 225.IBPluginDependency - 23.IBPluginDependency 231.IBPluginDependency 236.IBEditorWindowLastContentRect 236.IBWindowTemplateEditedContentRect @@ -2835,15 +2635,12 @@ 237.IBPluginDependency 238.IBPluginDependency 239.IBPluginDependency - 24.IBPluginDependency 240.IBPluginDependency 242.IBPluginDependency 243.IBPluginDependency 245.IBPluginDependency 246.IBPluginDependency 247.IBPluginDependency - 25.IBPluginDependency - 26.IBPluginDependency 261.IBAttributePlaceholdersKey 261.IBPluginDependency 262.IBPluginDependency @@ -2890,7 +2687,6 @@ 47.IBPluginDependency 48.IBPluginDependency 49.IBPluginDependency - 5.IBPluginDependency 50.IBPluginDependency 51.IBPluginDependency 52.IBPluginDependency @@ -2949,8 +2745,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin {{504, 612}, {346, 102}} {{504, 612}, {346, 102}} @@ -2967,9 +2761,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin ToolTip @@ -3038,7 +2829,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin diff --git a/PBGitIndexController.h b/PBGitIndexController.h index a3bc191..184d670 100644 --- a/PBGitIndexController.h +++ b/PBGitIndexController.h @@ -36,5 +36,8 @@ - (NSString *) stagedChangesForFile:(PBChangedFile *)file; - (NSString *) unstagedChangesForFile:(PBChangedFile *)file; +- (void)stopTrackingIndex; +- (void)resumeTrackingIndex; + - (NSMenu *) menuForTable:(NSTableView *)table; @end diff --git a/PBGitIndexController.m b/PBGitIndexController.m index 21c7076..6645ca1 100644 --- a/PBGitIndexController.m +++ b/PBGitIndexController.m @@ -12,11 +12,6 @@ #define FileChangesTableViewType @"GitFileChangedType" -@interface PBGitIndexController (PrivateMethods) -- (void)stopTrackingIndex; -- (void)resumeTrackingIndex; -@end - @implementation PBGitIndexController @synthesize contextSize; diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index 35979a4..1934b73 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -7,6 +7,7 @@ // #import "PBWebHistoryController.h" +#import "PBGitDefaults.h" @implementation PBWebHistoryController @@ -49,6 +50,37 @@ NSArray *arguments = [NSArray arrayWithObjects:content, [[[historyController repository] headRef] simpleRef], nil]; [[self script] callWebScriptMethod:@"loadCommit" withArguments: arguments]; + + // Now we load the extended details. We used to do this in a separate thread, + // but this caused some funny behaviour because NSTask's and NSThread's don't really + // like each other. Instead, just do it async. + + NSMutableArray *taskArguments = [NSMutableArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", @"--no-color", currentSha, nil]; + if (![PBGitDefaults showWhitespaceDifferences]) + [taskArguments insertObject:@"-w" atIndex:1]; + + NSFileHandle *handle = [repository handleForArguments:taskArguments]; + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + // Remove notification, in case we have another one running + [nc removeObserver:self]; + [nc addObserver:self selector:@selector(commitDetailsLoaded:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle]; + [handle readToEndOfFileInBackgroundAndNotify]; +} + +- (void)commitDetailsLoaded:(NSNotification *)notification +{ + NSData *data = [[notification userInfo] valueForKey:NSFileHandleNotificationDataItem]; + if (!data) + return; + + NSString *details = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + if (!details) + details = [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding]; + + if (!details) + return; + + [[view windowScriptObject] callWebScriptMethod:@"loadCommitDetails" withArguments:[NSArray arrayWithObject:details]]; } - (void) selectCommit: (NSString*) sha diff --git a/html/views/history/history.js b/html/views/history/history.js index df2a2b0..6cd7540 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -1,4 +1,7 @@ var commit; + +// Create a new Commit object +// obj: PBGitCommit object var Commit = function(obj) { this.object = obj; @@ -7,12 +10,14 @@ var Commit = function(obj) { this.sha = obj.realSha(); this.parents = obj.parents; this.subject = obj.subject; + this.notificationID = null; // TODO: // this.author_date instant - // This all needs to be async - this.loadedRaw = function(details) { + // This can be called later with the output of + // 'git show' to fill in missing commit details (such as a diff) + this.parseDetails = function(details) { this.raw = details; var diffStart = this.raw.indexOf("\ndiff "); @@ -138,6 +143,7 @@ var selectCommit = function(a) { Controller.selectCommit_(a); } +// Relead only refs var reload = function() { $("notification").style.display = "none"; commit.reloadRefs(); @@ -159,13 +165,15 @@ var showRefs = function() { 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; + // Other information will be loaded later by loadCommitDetails, + // Which will be called from the controller once + // the commit details are in. - notify("Loading commit…", 0); + if (commit && commit.notificationID) + clearTimeout(commit.notificationID); + + commit = new Commit(commitObject); + commit.currentRef = currentRef; $("commitID").innerHTML = commit.sha; $("authorID").innerHTML = commit.author_name; @@ -196,9 +204,18 @@ var loadCommit = function(commitObject, currentRef) { "" + commit.parents[i] + ""; } + + commit.notificationID = setTimeout(function() { + if (!commit.fullyLoaded) + notify("Loading commit…", 0); + commit.notificationID = null; + }, 500); + } var showDiff = function() { + + // Callback for the diff highlighter. Used to generate a filelist var newfile = function(name1, name2, id, mode_change, old_mode, new_mode) { var button = document.createElement("div"); var p = document.createElement("p"); @@ -270,8 +287,15 @@ var enableFeatures = function() enableFeature("gravatar", $("gravatar")) } -var loadExtendedCommit = function(commit) +var loadCommitDetails = function(data) { + commit.parseDetails(data); + + if (commit.notificationID) + clearTimeout(commit.notificationID) + else + $("notification").style.display = "none"; + var formatEmail = function(name, email) { return email ? name + " <" + email + ">" : name; }