mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
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.
This commit is contained in:
+16
-10
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user