Add a cleanup method to the history list.

The cleanup method cancels any background threads and removes KV observers when the repository document is closed.

Also removed KV observers that are no longer needed.
This commit is contained in:
Nathan Kinsinger
2010-07-03 18:35:04 -06:00
parent c17215e55e
commit a849424a46
6 changed files with 35 additions and 29 deletions
+3
View File
@@ -38,10 +38,13 @@
if (!revList || [revList count] == 0)
return;
NSThread *currentThread = [NSThread currentThread];
NSMutableArray *commits = [NSMutableArray array];
NSInteger counter = 0;
for (PBGitCommit *commit in revList) {
if ([currentThread isCancelled])
return;
PBGitSHA *commitSHA = [commit sha];
if (viewAllBranches || [searchSHAs containsObject:commitSHA]) {
[grapher decorateCommit:commit];
+1
View File
@@ -40,6 +40,7 @@
- (id) initWithRepository:(PBGitRepository *)repo;
- (void) forceUpdate;
- (void) updateHistory;
- (void)cleanup;
- (void) updateCommitsFromGrapher:(NSDictionary *)commitData;
+16 -29
View File
@@ -82,6 +82,20 @@
}
- (void)cleanup
{
if (currentRevList) {
[currentRevList removeObserver:self forKeyPath:@"commits"];
[currentRevList cancel];
}
[graphQueue cancelAllOperations];
[repository removeObserver:self forKeyPath:@"currentBranch"];
[repository removeObserver:self forKeyPath:@"currentBranchFilter"];
[repository removeObserver:self forKeyPath:@"hasChanged"];
}
- (NSArray *) projectCommits
{
return [projectRevList.commits copy];
@@ -137,12 +151,9 @@
resetCommits = YES;
self.isUpdating = YES;
[graphQueue setSuspended:YES];
if (graphQueue)
[graphQueue removeObserver:self forKeyPath:@"operations"];
[graphQueue cancelAllOperations];
graphQueue = [[NSOperationQueue alloc] init];
[graphQueue setMaxConcurrentOperationCount:1];
[graphQueue addObserver:self forKeyPath:@"operations" options:0 context:@"operations"];
grapher = [self grapher];
}
@@ -223,15 +234,12 @@
if (currentRevList == parser)
return;
if (currentRevList) {
if (currentRevList)
[currentRevList removeObserver:self forKeyPath:@"commits"];
[currentRevList removeObserver:self forKeyPath:@"isParsing"];
}
currentRevList = parser;
[currentRevList addObserver:self forKeyPath:@"commits" options:NSKeyValueObservingOptionNew context:@"commitsUpdated"];
[currentRevList addObserver:self forKeyPath:@"isParsing" options:0 context:@"revListParsing"];
}
@@ -339,22 +347,6 @@
#pragma mark -
#pragma mark Key Value Observing
- (void) removeObservers
{
[repository removeObserver:self forKeyPath:@"currentBranch"];
[repository removeObserver:self forKeyPath:@"currentBranchFilter"];
[repository removeObserver:self forKeyPath:@"hasChanged"];
if (currentRevList) {
[currentRevList removeObserver:self forKeyPath:@"commits"];
[currentRevList removeObserver:self forKeyPath:@"isParsing"];
}
if (graphQueue)
[graphQueue removeObserver:self forKeyPath:@"operations"];
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([@"currentBranch" isEqualToString:context]) {
@@ -379,11 +371,6 @@
return;
}
if ([@"revListParsing" isEqualToString:context] || [@"operations" isEqualToString:context]) {
[self finishedGraphing];
return;
}
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
+7
View File
@@ -128,6 +128,13 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
revisionList = [[PBGitHistoryList alloc] initWithRepository:self];
}
- (void)close
{
[revisionList cleanup];
[super close];
}
- (id) initWithURL: (NSURL*) path
{
if (![PBGitBinary path])
+1
View File
@@ -25,6 +25,7 @@
- (id) initWithRepository:(PBGitRepository *)repo rev:(PBGitRevSpecifier *)rev shouldGraph:(BOOL)graph;
- (void) loadRevisons;
- (void)cancel;
@property (retain) NSMutableArray *commits;
@property (readonly) BOOL isParsing;
+7
View File
@@ -58,6 +58,12 @@ using namespace std;
}
- (void)cancel
{
[parseThread cancel];
}
- (void) finishedParsing
{
self.isParsing = NO;
@@ -217,6 +223,7 @@ using namespace std;
NSLog(@"[%@ %s] thread has been canceled", [self class], _cmd);
}
[task terminate];
[task waitUntilExit];
}