1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-17 01:42:45 +02:00

avoid deadlock

This commit is contained in:
Jesse Duffield
2022-01-29 11:22:35 +11:00
parent cb0d3a480a
commit 1a74ed3214
3 changed files with 6 additions and 15 deletions

View File

@ -1,8 +1,6 @@
package controllers package controllers
import ( import (
"sync"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
@ -21,7 +19,6 @@ type RemotesController struct {
getSelectedRemote func() *models.Remote getSelectedRemote func() *models.Remote
setRemoteBranches func([]*models.RemoteBranch) setRemoteBranches func([]*models.RemoteBranch)
getContexts func() context.ContextTree getContexts func() context.ContextTree
fetchMutex *sync.Mutex
} }
var _ types.IController = &RemotesController{} var _ types.IController = &RemotesController{}
@ -33,7 +30,6 @@ func NewRemotesController(
getContexts func() context.ContextTree, getContexts func() context.ContextTree,
getSelectedRemote func() *models.Remote, getSelectedRemote func() *models.Remote,
setRemoteBranches func([]*models.RemoteBranch), setRemoteBranches func([]*models.RemoteBranch),
fetchMutex *sync.Mutex,
) *RemotesController { ) *RemotesController {
return &RemotesController{ return &RemotesController{
c: c, c: c,
@ -42,7 +38,6 @@ func NewRemotesController(
getContext: getContext, getContext: getContext,
getSelectedRemote: getSelectedRemote, getSelectedRemote: getSelectedRemote,
setRemoteBranches: setRemoteBranches, setRemoteBranches: setRemoteBranches,
fetchMutex: fetchMutex,
} }
} }
@ -176,9 +171,6 @@ func (self *RemotesController) edit(remote *models.Remote) error {
func (self *RemotesController) fetch(remote *models.Remote) error { func (self *RemotesController) fetch(remote *models.Remote) error {
return self.c.WithWaitingStatus(self.c.Tr.FetchingRemoteStatus, func() error { return self.c.WithWaitingStatus(self.c.Tr.FetchingRemoteStatus, func() error {
self.fetchMutex.Lock()
defer self.fetchMutex.Unlock()
err := self.git.Sync.FetchRemote(remote.Name) err := self.git.Sync.FetchRemote(remote.Name)
if err != nil { if err != nil {
_ = self.c.Error(err) _ = self.c.Error(err)

View File

@ -397,7 +397,7 @@ type Modes struct {
type guiMutexes struct { type guiMutexes struct {
RefreshingFilesMutex *sync.Mutex RefreshingFilesMutex *sync.Mutex
RefreshingStatusMutex *sync.Mutex RefreshingStatusMutex *sync.Mutex
FetchMutex *sync.Mutex SyncMutex *sync.Mutex
BranchCommitsMutex *sync.Mutex BranchCommitsMutex *sync.Mutex
LineByLinePanelMutex *sync.Mutex LineByLinePanelMutex *sync.Mutex
SubprocessMutex *sync.Mutex SubprocessMutex *sync.Mutex
@ -514,7 +514,7 @@ func NewGui(
Mutexes: guiMutexes{ Mutexes: guiMutexes{
RefreshingFilesMutex: &sync.Mutex{}, RefreshingFilesMutex: &sync.Mutex{},
RefreshingStatusMutex: &sync.Mutex{}, RefreshingStatusMutex: &sync.Mutex{},
FetchMutex: &sync.Mutex{}, SyncMutex: &sync.Mutex{},
BranchCommitsMutex: &sync.Mutex{}, BranchCommitsMutex: &sync.Mutex{},
LineByLinePanelMutex: &sync.Mutex{}, LineByLinePanelMutex: &sync.Mutex{},
SubprocessMutex: &sync.Mutex{}, SubprocessMutex: &sync.Mutex{},
@ -537,7 +537,7 @@ func NewGui(
cmn, cmn,
osCommand, osCommand,
gitConfig, gitConfig,
gui.Mutexes.FetchMutex, gui.Mutexes.SyncMutex,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -666,7 +666,6 @@ func (gui *Gui) setControllers() {
getContexts, getContexts,
gui.getSelectedRemote, gui.getSelectedRemote,
func(branches []*models.RemoteBranch) { gui.State.RemoteBranches = branches }, func(branches []*models.RemoteBranch) { gui.State.RemoteBranches = branches },
gui.Mutexes.FetchMutex,
), ),
Menu: controllers.NewMenuController( Menu: controllers.NewMenuController(
controllerCommon, controllerCommon,

View File

@ -75,7 +75,7 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error {
gui.Common, gui.Common,
gui.OSCommand, gui.OSCommand,
git_config.NewStdCachedGitConfig(gui.Log), git_config.NewStdCachedGitConfig(gui.Log),
gui.Mutexes.FetchMutex, gui.Mutexes.SyncMutex,
) )
if err != nil { if err != nil {
return err return err
@ -84,8 +84,8 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error {
// these two mutexes are used by our background goroutines (triggered via `gui.goEvery`. We don't want to // these two mutexes are used by our background goroutines (triggered via `gui.goEvery`. We don't want to
// switch to a repo while one of these goroutines is in the process of updating something // switch to a repo while one of these goroutines is in the process of updating something
gui.Mutexes.FetchMutex.Lock() gui.Mutexes.SyncMutex.Lock()
defer gui.Mutexes.FetchMutex.Unlock() defer gui.Mutexes.SyncMutex.Unlock()
gui.Mutexes.RefreshingFilesMutex.Lock() gui.Mutexes.RefreshingFilesMutex.Lock()
defer gui.Mutexes.RefreshingFilesMutex.Unlock() defer gui.Mutexes.RefreshingFilesMutex.Unlock()