From 916711324f4b04b1538f6af06b1f4ae85faf2927 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Sat, 12 Sep 2009 23:43:14 +0200 Subject: [PATCH 1/6] IndexController: de-privatize the index-stopping stuff We shouldn't need to do this, but we still need to, because our index operations are split between two different controllers, which is a bit odd. --- PBGitIndexController.h | 3 +++ PBGitIndexController.m | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) 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; From 00731eb285650df15befdda83ffccecd73012324 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Sat, 12 Sep 2009 23:43:35 +0200 Subject: [PATCH 2/6] CommitView: Don't keep rearranging when iterating over files --- PBGitCommitController.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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]) From 3324591e6cb3af729bad654b1772e3bc34d2986e Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Mon, 14 Sep 2009 13:02:36 +0200 Subject: [PATCH 3/6] Fix UTF-8 bug in NSString_RegEx This class would use the location information provided by regex(3) as range for for a substring. However, the information regex(3) returns is a byte-based, while NSString works on characters. This can cause a problem when there are UTF-8 characters in the string, as the wrong subsstring will be returned. This is fixed by taking the UTF bytesequence, and extracting a substring from that, rather than using NSString's own substring method --- NSString_RegEx.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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) From 0363eea494602e3002f45f1790eaff3435151949 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Thu, 17 Sep 2009 23:29:06 +0200 Subject: [PATCH 4/6] HistoryView: don't load in commit information in a separate thread anymore I've seen this hang or crash a few times, so I hope this works better. Instead of running a task in a separate thread, we just let it go through the run loop and catch it when the task is done. This ruins the second subview in the history view, but I don't think anybody ever used that, so I'm going to remove it. --- PBGitCommit.m | 14 ++------------ PBWebHistoryController.m | 32 ++++++++++++++++++++++++++++++++ html/views/history/history.js | 22 ++++++++++++++++------ 3 files changed, 50 insertions(+), 18 deletions(-) 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/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..47d72b7 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; @@ -11,8 +14,9 @@ var Commit = function(obj) { // 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 +142,7 @@ var selectCommit = function(a) { Controller.selectCommit_(a); } +// Relead only refs var reload = function() { $("notification").style.display = "none"; commit.reloadRefs(); @@ -159,10 +164,11 @@ 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 + // Other information will be loaded later by loadCommitDetails, + // Which will be called from the controller once + // the commit details are in. + commit = new Commit(commitObject); - Controller.callSelector_onObject_callBack_("details", commitObject, - function(data) { commit.loadedRaw(data); loadExtendedCommit(commit); }); commit.currentRef = currentRef; notify("Loading commit…", 0); @@ -199,6 +205,8 @@ var loadCommit = function(commitObject, currentRef) { } 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 +278,10 @@ var enableFeatures = function() enableFeature("gravatar", $("gravatar")) } -var loadExtendedCommit = function(commit) +var loadCommitDetails = function(data) { + commit.parseDetails(data); + var formatEmail = function(name, email) { return email ? name + " <" + email + ">" : name; } From 34394d056b5ff0a4620a79c606f26ff4870c67f3 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Thu, 17 Sep 2009 23:32:35 +0200 Subject: [PATCH 5/6] HistoryView: Remove raw view I don't think anybody has ever used this, so let's just remove it. --- PBGitHistoryController.m | 3 +- PBGitHistoryView.xib | 506 ++++++++++++--------------------------- 2 files changed, 149 insertions(+), 360 deletions(-) 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 From 5972bd4f7f194fce53f84c45ba68a4b63de22ffa Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Thu, 17 Sep 2009 23:40:38 +0200 Subject: [PATCH 6/6] HistoryView: Don't show the 'loading commit' thing until after 500 ms. This was annoying me a lot, so it's in stable :) Signed-off-by: Pieter de Bie --- html/views/history/history.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/html/views/history/history.js b/html/views/history/history.js index 47d72b7..6cd7540 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -10,6 +10,7 @@ var Commit = function(obj) { this.sha = obj.realSha(); this.parents = obj.parents; this.subject = obj.subject; + this.notificationID = null; // TODO: // this.author_date instant @@ -168,11 +169,12 @@ var loadCommit = function(commitObject, currentRef) { // Which will be called from the controller once // the commit details are in. + if (commit && commit.notificationID) + clearTimeout(commit.notificationID); + commit = new Commit(commitObject); commit.currentRef = currentRef; - notify("Loading commit…", 0); - $("commitID").innerHTML = commit.sha; $("authorID").innerHTML = commit.author_name; $("subjectID").innerHTML = commit.subject.escapeHTML(); @@ -202,6 +204,13 @@ 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() { @@ -282,6 +291,11 @@ 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; }