mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 15:30:18 +00:00
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:
@@ -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];
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
- (id) initWithRepository:(PBGitRepository *)repo;
|
||||
- (void) forceUpdate;
|
||||
- (void) updateHistory;
|
||||
- (void)cleanup;
|
||||
|
||||
- (void) updateCommitsFromGrapher:(NSDictionary *)commitData;
|
||||
|
||||
|
||||
+16
-29
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user