Skip to content

Commit ef38ae8

Browse files
committed
Debounce git-directory refresh notifications (#563)
FSEvents' coalescing window doesn't reliably batch every file written by a single git operation (e.g. `git switch -c` writes a new ref file and rewrites HEAD) into one callback, so PBGitHistoryController could receive multiple PBGitRepositoryEventNotifications in quick succession and call refresh: for each one, triggering redundant, overlapping history reloads. Coalesce bursts of git-directory notifications within a short window into a single refresh: call, and cancel any pending debounced refresh when the view closes.
1 parent d9df533 commit ef38ae8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎Classes/Controllers/PBGitHistoryController.m‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,11 @@ - (void)_repositoryUpdatedNotification:(NSNotification *)notification
198198
{
199199
PBGitRepositoryWatcherEventType eventType = [(NSNumber *)[[notification userInfo] objectForKey:kPBGitRepositoryEventTypeUserInfoKey] unsignedIntValue];
200200
if (eventType & PBGitRepositoryWatcherEventTypeGitDirectory) {
201-
// refresh if the .git repository is modified
202-
[self refresh:self];
201+
// refresh if the .git repository is modified, coalescing bursts of
202+
// git-directory events (e.g. a single `git switch -c` touching both a
203+
// ref file and HEAD) into a single refresh
204+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(refresh:) object:self];
205+
[self performSelector:@selector(refresh:) withObject:self afterDelay:0.2];
203206
}
204207
}
205208

@@ -599,6 +602,7 @@ - (BOOL)hasNonlinearPath
599602
- (void)closeView
600603
{
601604
[[NSNotificationCenter defaultCenter] removeObserver:self];
605+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(refresh:) object:self];
602606

603607
[webHistoryController closeView];
604608
[fileView closeView];

0 commit comments

Comments
 (0)