From e588355f578ad18d21aa14d20c4a76b48e2adfd0 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 8 Jul 2023 20:47:16 +1000 Subject: [PATCH] Add mutex for refreshing branches We had a race condition due to refreshing branches in two different places, one which refreshed reflog commits beforehand. The race condition meant that upon load we wouldn't see recency values (provided by the reflog commits) against the branches --- pkg/gui/controllers/helpers/refresh_helper.go | 3 +++ pkg/gui/gui.go | 17 +++++++++-------- pkg/gui/types/common.go | 17 +++++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 5c5e470b3..6c9064519 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -342,6 +342,9 @@ func (self *RefreshHelper) refreshStateSubmoduleConfigs() error { // self.refreshStatus is called at the end of this because that's when we can // be sure there is a State.Model.Branches array to pick the current branch from func (self *RefreshHelper) refreshBranches() { + self.c.Mutexes().RefreshingBranchesMutex.Lock() + defer self.c.Mutexes().RefreshingBranchesMutex.Unlock() + reflogCommits := self.c.Model().FilteredReflogCommits if self.c.Modes().Filtering.Active() { // in filter mode we filter our reflog commits to just those containing the path diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 5f5955e5a..33057ba42 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -448,14 +448,15 @@ func NewGui( // sake of backwards compatibility. We're making use of short circuiting here ShowExtrasWindow: cmn.UserConfig.Gui.ShowCommandLog && !config.GetAppState().HideCommandLog, Mutexes: types.Mutexes{ - RefreshingFilesMutex: &deadlock.Mutex{}, - RefreshingStatusMutex: &deadlock.Mutex{}, - SyncMutex: &deadlock.Mutex{}, - LocalCommitsMutex: &deadlock.Mutex{}, - SubCommitsMutex: &deadlock.Mutex{}, - SubprocessMutex: &deadlock.Mutex{}, - PopupMutex: &deadlock.Mutex{}, - PtyMutex: &deadlock.Mutex{}, + RefreshingFilesMutex: &deadlock.Mutex{}, + RefreshingBranchesMutex: &deadlock.Mutex{}, + RefreshingStatusMutex: &deadlock.Mutex{}, + SyncMutex: &deadlock.Mutex{}, + LocalCommitsMutex: &deadlock.Mutex{}, + SubCommitsMutex: &deadlock.Mutex{}, + SubprocessMutex: &deadlock.Mutex{}, + PopupMutex: &deadlock.Mutex{}, + PtyMutex: &deadlock.Mutex{}, }, InitialDir: initialDir, } diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index 184288c0a..5a55c85be 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -217,14 +217,15 @@ type Model struct { // if you add a new mutex here be sure to instantiate it. We're using pointers to // mutexes so that we can pass the mutexes to controllers. type Mutexes struct { - RefreshingFilesMutex *deadlock.Mutex - RefreshingStatusMutex *deadlock.Mutex - SyncMutex *deadlock.Mutex - LocalCommitsMutex *deadlock.Mutex - SubCommitsMutex *deadlock.Mutex - SubprocessMutex *deadlock.Mutex - PopupMutex *deadlock.Mutex - PtyMutex *deadlock.Mutex + RefreshingFilesMutex *deadlock.Mutex + RefreshingBranchesMutex *deadlock.Mutex + RefreshingStatusMutex *deadlock.Mutex + SyncMutex *deadlock.Mutex + LocalCommitsMutex *deadlock.Mutex + SubCommitsMutex *deadlock.Mutex + SubprocessMutex *deadlock.Mutex + PopupMutex *deadlock.Mutex + PtyMutex *deadlock.Mutex } type IStateAccessor interface {