Skip to content

Commit 963969a

Browse files
author
Pieter de Bie
committed
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.
1 parent 5090d4f commit 963969a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

PBGitCommitController.m

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,23 @@ - (void) updateView
160160
// all files previously marked as deletable
161161
- (void) doneProcessingIndex
162162
{
163-
[self willChangeValueForKey:@"files"];
164-
if (!--self.busy) {
165-
self.status = @"Ready";
166-
for (PBChangedFile *file in files) {
167-
if (!file.hasStagedChanges && !file.hasUnstagedChanges) {
168-
NSLog(@"Deleting file: %@", [file path]);
169-
[files removeObject:file];
170-
}
171-
}
163+
// if we're still busy, do nothing :)
164+
if (--self.busy)
165+
return;
166+
167+
NSMutableArray *deleteFiles = [NSMutableArray array];
168+
for (PBChangedFile *file in files) {
169+
if (!file.hasStagedChanges && !file.hasUnstagedChanges)
170+
[deleteFiles addObject:file];
171+
}
172+
173+
if ([deleteFiles count]) {
174+
[self willChangeValueForKey:@"files"];
175+
for (PBChangedFile *file in deleteFiles)
176+
[files removeObject:file];
177+
[self didChangeValueForKey:@"files"];
172178
}
173-
[self didChangeValueForKey:@"files"];
179+
self.status = @"Ready";
174180
}
175181

176182
- (void) readOtherFiles:(NSNotification *)notification;

0 commit comments

Comments
 (0)