summaryrefslogtreecommitdiffstats
path: root/pkg/gui/staging_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-10-07 17:54:45 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-10-10 00:23:01 +1100
commitbb081ca764e42a5cfa67a0dd42acbdef4ae57e05 (patch)
tree05286869aa465ce0c7097641c6564cea2e6088c9 /pkg/gui/staging_panel.go
parenta9049b4a82e733521a0249c458eee0e9fdd1295f (diff)
more mutex safety with staging panel
Diffstat (limited to 'pkg/gui/staging_panel.go')
-rw-r--r--pkg/gui/staging_panel.go132
1 files changed, 66 insertions, 66 deletions
diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go
index e2010b980..68c7c8391 100644
--- a/pkg/gui/staging_panel.go
+++ b/pkg/gui/staging_panel.go
@@ -69,18 +69,18 @@ func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx
}
func (gui *Gui) handleTogglePanelClick(g *gocui.Gui, v *gocui.View) error {
- state := gui.State.Panels.LineByLine
-
- state.SecondaryFocused = !state.SecondaryFocused
+ return gui.withLBLActiveCheck(func(state *lineByLinePanelState) error {
+ state.SecondaryFocused = !state.SecondaryFocused
- return gui.refreshStagingPanel(false, v.SelectedLineIdx())
+ return gui.refreshStagingPanel(false, v.SelectedLineIdx())
+ })
}
func (gui *Gui) handleTogglePanel(g *gocui.Gui, v *gocui.View) error {
- state := gui.State.Panels.LineByLine
-
- state.SecondaryFocused = !state.SecondaryFocused
- return gui.refreshStagingPanel(false, -1)
+ return gui.withLBLActiveCheck(func(state *lineByLinePanelState) error {
+ state.SecondaryFocused = !state.SecondaryFocused
+ return gui.refreshStagingPanel(false, -1)
+ })
}
func (gui *Gui) handleStagingEscape() error {
@@ -90,74 +90,74 @@ func (gui *Gui) handleStagingEscape() error {
}
func (gui *Gui) handleToggleStagedSelection(g *gocui.Gui, v *gocui.View) error {
- state := gui.State.Panels.LineByLine
-
- return gui.applySelection(state.SecondaryFocused)
+ return gui.withLBLActiveCheck(func(state *lineByLinePanelState) error {
+ return gui.applySelection(state.SecondaryFocused)
+ })
}
func (gui *Gui) handleResetSelection(g *gocui.Gui, v *gocui.View) error {
- state := gui.State.Panels.LineByLine
-
- if state.SecondaryFocused {
- // for backwards compatibility
- return gui.applySelection(true)
- }
+ return gui.withLBLActiveCheck(func(state *lineByLinePanelState) error {
+ if state.SecondaryFocused {
+ // for backwards compatibility
+ return gui.applySelection(true)
+ }
- if !gui.Config.GetUserConfig().Gui.SkipUnstageLineWarning {
- return gui.ask(askOpts{
- title: gui.Tr.UnstageLinesTitle,
- prompt: gui.Tr.UnstageLinesPrompt,
- handlersManageFocus: true,
- handleConfirm: func() error {
- if err := gui.switchContext(gui.Contexts.Staging.Context); err != nil {
- return err
- }
-
- return gui.applySelection(true)
- },
- handleClose: func() error {
- return gui.switchContext(gui.Contexts.Staging.Context)
- },
- })
- } else {
- return gui.applySelection(true)
- }
+ if !gui.Config.GetUserConfig().Gui.SkipUnstageLineWarning {
+ return gui.ask(askOpts{
+ title: gui.Tr.UnstageLinesTitle,
+ prompt: gui.Tr.UnstageLinesPrompt,
+ handlersManageFocus: true,
+ handleConfirm: func() error {
+ if err := gui.switchContext(gui.Contexts.Staging.Context); err != nil {
+ return err
+ }
+
+ return gui.applySelection(true)
+ },
+ handleClose: func() error {
+ return gui.switchContext(gui.Contexts.Staging.Context)
+ },
+ })
+ } else {
+ return gui.applySelection(true)
+ }
+ })
}
func (gui *Gui) applySelection(reverse bool) error {
- state := gui.State.Panels.LineByLine
-
- file := gui.getSelectedFile()
- if file == nil {
- return nil
- }
+ return gui.withLBLActiveCheck(func(state *lineByLinePanelState) error {
+ file := gui.getSelectedFile()
+ if file == nil {
+ return nil
+ }
- patch := patch.ModifiedPatchForRange(gui.Log, file.Name, state.Diff, state.FirstLineIdx, state.LastLineIdx, reverse, false)
+ patch := patch.ModifiedPatchForRange(gui.Log, file.Name, state.Diff, state.FirstLineIdx, state.LastLineIdx, reverse, false)
- if patch == "" {
- return nil
- }
+ if patch == "" {
+ return nil
+ }
- // apply the patch then refresh this panel
- // create a new temp file with the patch, then call git apply with that patch
- applyFlags := []string{}
- if !reverse || state.SecondaryFocused {
- applyFlags = append(applyFlags, "cached")
- }
- err := gui.GitCommand.ApplyPatch(patch, applyFlags...)
- if err != nil {
- return gui.surfaceError(err)
- }
+ // apply the patch then refresh this panel
+ // create a new temp file with the patch, then call git apply with that patch
+ applyFlags := []string{}
+ if !reverse || state.SecondaryFocused {
+ applyFlags = append(applyFlags, "cached")
+ }
+ err := gui.GitCommand.ApplyPatch(patch, applyFlags...)
+ if err != nil {
+ return gui.surfaceError(err)
+ }
- if state.SelectMode == RANGE {
- state.SelectMode = LINE
- }
+ if state.SelectMode == RANGE {
+ state.SelectMode = LINE
+ }
- if err := gui.refreshSidePanels(refreshOptions{scope: []int{FILES}}); err != nil {
- return err
- }
- if err := gui.refreshStagingPanel(false, -1); err != nil {
- return err
- }
- return nil
+ if err := gui.refreshSidePanels(refreshOptions{scope: []int{FILES}}); err != nil {
+ return err
+ }
+ if err := gui.refreshStagingPanel(false, -1); err != nil {
+ return err
+ }
+ return nil
+ })
}