diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-02 00:15:39 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-02 11:09:12 +1100 |
commit | cc9293b38698af48da0c18309fb22eb83b986ceb (patch) | |
tree | c9e28ec110da1207a1591bca4a0e31448445dab7 /pkg/gui/merge_panel.go | |
parent | efe43077bc6385cf33f328a8382a27cd8663c815 (diff) |
add mutex to prevent crashes with merge conflicts
Diffstat (limited to 'pkg/gui/merge_panel.go')
-rw-r--r-- | pkg/gui/merge_panel.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go index 5ae0ec9b6..2bd1eb6e3 100644 --- a/pkg/gui/merge_panel.go +++ b/pkg/gui/merge_panel.go @@ -79,18 +79,27 @@ func (gui *Gui) takeOverScrolling() { } func (gui *Gui) handleSelectTop(g *gocui.Gui, v *gocui.View) error { + gui.State.Panels.Merging.ConflictsMutex.Lock() + defer gui.State.Panels.Merging.ConflictsMutex.Unlock() + gui.takeOverScrolling() gui.State.Panels.Merging.ConflictTop = true return gui.refreshMergePanel() } func (gui *Gui) handleSelectBottom(g *gocui.Gui, v *gocui.View) error { + gui.State.Panels.Merging.ConflictsMutex.Lock() + defer gui.State.Panels.Merging.ConflictsMutex.Unlock() + gui.takeOverScrolling() gui.State.Panels.Merging.ConflictTop = false return gui.refreshMergePanel() } func (gui *Gui) handleSelectNextConflict(g *gocui.Gui, v *gocui.View) error { + gui.State.Panels.Merging.ConflictsMutex.Lock() + defer gui.State.Panels.Merging.ConflictsMutex.Unlock() + gui.takeOverScrolling() if gui.State.Panels.Merging.ConflictIndex >= len(gui.State.Panels.Merging.Conflicts)-1 { return nil @@ -100,6 +109,9 @@ func (gui *Gui) handleSelectNextConflict(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleSelectPrevConflict(g *gocui.Gui, v *gocui.View) error { + gui.State.Panels.Merging.ConflictsMutex.Lock() + defer gui.State.Panels.Merging.ConflictsMutex.Unlock() + gui.takeOverScrolling() if gui.State.Panels.Merging.ConflictIndex <= 0 { return nil @@ -172,6 +184,9 @@ func (gui *Gui) handlePopFileSnapshot(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handlePickHunk(g *gocui.Gui, v *gocui.View) error { + gui.State.Panels.Merging.ConflictsMutex.Lock() + defer gui.State.Panels.Merging.ConflictsMutex.Unlock() + gui.takeOverScrolling() conflict := gui.State.Panels.Merging.Conflicts[gui.State.Panels.Merging.ConflictIndex] @@ -198,6 +213,9 @@ func (gui *Gui) handlePickHunk(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handlePickBothHunks(g *gocui.Gui, v *gocui.View) error { + gui.State.Panels.Merging.ConflictsMutex.Lock() + defer gui.State.Panels.Merging.ConflictsMutex.Unlock() + gui.takeOverScrolling() conflict := gui.State.Panels.Merging.Conflicts[gui.State.Panels.Merging.ConflictIndex] @@ -211,6 +229,13 @@ func (gui *Gui) handlePickBothHunks(g *gocui.Gui, v *gocui.View) error { return gui.refreshMergePanel() } +func (gui *Gui) refreshMergePanelWithLock() error { + gui.State.Panels.Merging.ConflictsMutex.Lock() + defer gui.State.Panels.Merging.ConflictsMutex.Unlock() + + return gui.refreshMergePanel() +} + func (gui *Gui) refreshMergePanel() error { panelState := gui.State.Panels.Merging cat, err := gui.catSelectedFile() |