Repository navigation
Fix duplicate commits from overlapping history refreshes (#563) - #564
Merged
Merged
Conversation
A burst of git-directory FSEvents (e.g. from `git switch -c <branch>` touching both a ref file and HEAD) can trigger overlapping loadRevisionsWithCompletionBlock: calls on the same PBGitRevList instance. The previous parse operation's trailing commit-batch flush is fire-and-forget and can still land after a newer parse has already reset/appended its own commits, since NSOperation.isCancelled is only checked cooperatively and can lose that race. The result is duplicate commits appended into the history list. Track a per-instance load generation and reject any updateCommits: flush whose generation no longer matches the current one, closing the race regardless of operation-queue/FSEvents timing.
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.
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
git switch -c <branch>) could trigger overlappingPBGitRevListparses, and a stale parse's trailing commit flush could land after a newer parse had already started, duplicating commits in the history list.PBGitRevListwith a per-instance load generation:updateCommits:operation:generation:now rejects any flush whose generation no longer matches the current one, closing the race regardless of operation-queue/FSEvents timing.PBGitHistoryController._repositoryUpdatedNotification:so a burst of git-directory FSEvents (e.g. the ref-file write and HEAD rewrite from a singlegit switch -c) collapses into onerefresh:call.Test plan
xcodebuild -project GitX.xcodeproj -scheme GitX -configuration Debug -destination 'platform=macOS' buildsucceeds.-[PBGitHistoryList updateProjectHistoryForRev:],-[PBGitRevList loadRevisionsWithCompletionBlock:], and-[PBGitRevList updateCommits:operation:generation:]resolve at the expected source lines in the built binary, confirming the generation-guard code is live.git switch -ccalls while watching the commit list ("All" scope) for duplicate rows.