From 963969af78fe3d6a7a2eedd7ab2fdaefc9b860f4 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Thu, 11 Jun 2009 23:37:41 +0100 Subject: [PATCH] CommitController: don't mutate array we enumerate when refreshing index There was a nasty bug in handling the finishing of the index change. This code path was changed when I simplified the file tracking, but as a result the code now mutated the files array, over which we were also enumerating. This can cause all sorts of bad stuff, like files that aren't really deleted from the view, to wrong files that are deleted, to a crash of the system for wrong memory access. --- PBGitCommitController.m | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/PBGitCommitController.m b/PBGitCommitController.m index 8f987ab..0d95c1f 100644 --- a/PBGitCommitController.m +++ b/PBGitCommitController.m @@ -160,17 +160,23 @@ // all files previously marked as deletable - (void) doneProcessingIndex { - [self willChangeValueForKey:@"files"]; - if (!--self.busy) { - self.status = @"Ready"; - for (PBChangedFile *file in files) { - if (!file.hasStagedChanges && !file.hasUnstagedChanges) { - NSLog(@"Deleting file: %@", [file path]); - [files removeObject:file]; - } - } + // if we're still busy, do nothing :) + if (--self.busy) + return; + + NSMutableArray *deleteFiles = [NSMutableArray array]; + for (PBChangedFile *file in files) { + if (!file.hasStagedChanges && !file.hasUnstagedChanges) + [deleteFiles addObject:file]; } - [self didChangeValueForKey:@"files"]; + + if ([deleteFiles count]) { + [self willChangeValueForKey:@"files"]; + for (PBChangedFile *file in deleteFiles) + [files removeObject:file]; + [self didChangeValueForKey:@"files"]; + } + self.status = @"Ready"; } - (void) readOtherFiles:(NSNotification *)notification;