1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

smarter refreshing for tags and remotes

This commit is contained in:
Jesse Duffield
2020-03-28 10:27:34 +11:00
parent d97c230747
commit f7add8d788
7 changed files with 75 additions and 39 deletions

View File

@ -54,9 +54,6 @@ func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
// gui.refreshStatus is called at the end of this because that's when we can // gui.refreshStatus is called at the end of this because that's when we can
// be sure there is a state.Branches array to pick the current branch from // be sure there is a state.Branches array to pick the current branch from
func (gui *Gui) refreshBranches() { func (gui *Gui) refreshBranches() {
_ = gui.refreshRemotes()
_ = gui.refreshTags()
builder, err := commands.NewBranchListBuilder(gui.Log, gui.GitCommand, gui.State.ReflogCommits) builder, err := commands.NewBranchListBuilder(gui.Log, gui.GitCommand, gui.State.ReflogCommits)
if err != nil { if err != nil {
_ = gui.createErrorPanel(gui.g, err.Error()) _ = gui.createErrorPanel(gui.g, err.Error())

View File

@ -71,6 +71,13 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
return nil return nil
} }
// whenever we change commits, we should update branches because the upstream/downstream
// counts can change. Whenever we change branches we should probably also change commits
// e.g. in the case of switching branches. We also need the status to be refreshed whenever
// the working tree status changes or the branch upstream/downstream value changes.
// Given how fast the refreshStatus method is, we should really just call it every time
// we refresh, but I'm not sure how to do that asynchronously that prevents a race condition
// other than a mutex.
func (gui *Gui) refreshCommits() error { func (gui *Gui) refreshCommits() error {
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(2) wg.Add(2)
@ -78,6 +85,7 @@ func (gui *Gui) refreshCommits() error {
go func() { go func() {
gui.refreshReflogCommits() gui.refreshReflogCommits()
gui.refreshBranches() gui.refreshBranches()
gui.refreshStatus()
wg.Done() wg.Done()
}() }()
@ -91,8 +99,6 @@ func (gui *Gui) refreshCommits() error {
wg.Wait() wg.Wait()
gui.refreshStatus()
return nil return nil
} }

View File

@ -179,34 +179,35 @@ type searchingState struct {
} }
type guiState struct { type guiState struct {
Files []*commands.File Files []*commands.File
Branches []*commands.Branch Branches []*commands.Branch
Commits []*commands.Commit Commits []*commands.Commit
StashEntries []*commands.StashEntry StashEntries []*commands.StashEntry
CommitFiles []*commands.CommitFile CommitFiles []*commands.CommitFile
ReflogCommits []*commands.Commit ReflogCommits []*commands.Commit
DiffEntries []*commands.Commit DiffEntries []*commands.Commit
Remotes []*commands.Remote Remotes []*commands.Remote
RemoteBranches []*commands.RemoteBranch RemoteBranches []*commands.RemoteBranch
Tags []*commands.Tag Tags []*commands.Tag
MenuItemCount int // can't store the actual list because it's of interface{} type MenuItemCount int // can't store the actual list because it's of interface{} type
PreviousView string PreviousView string
Platform commands.Platform Platform commands.Platform
Updating bool Updating bool
Panels *panelStates Panels *panelStates
MainContext string // used to keep the main and secondary views' contexts in sync MainContext string // used to keep the main and secondary views' contexts in sync
CherryPickedCommits []*commands.Commit CherryPickedCommits []*commands.Commit
SplitMainPanel bool SplitMainPanel bool
RetainOriginalDir bool RetainOriginalDir bool
IsRefreshingFiles bool IsRefreshingFiles bool
RefreshingFilesMutex sync.Mutex RefreshingFilesMutex sync.Mutex
Searching searchingState RefreshingStatusMutex sync.Mutex
ScreenMode int Searching searchingState
SideView *gocui.View ScreenMode int
Ptmx *os.File SideView *gocui.View
PrevMainWidth int Ptmx *os.File
PrevMainHeight int PrevMainWidth int
OldInformation string PrevMainHeight int
OldInformation string
} }
// for now the split view will always be on // for now the split view will always be on

View File

@ -99,7 +99,7 @@ func (gui *Gui) handleDeleteRemoteBranch(g *gocui.Gui, v *gocui.View) error {
return err return err
} }
return gui.refreshRemotes() return gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, REMOTES}})
}) })
}, nil) }, nil)
} }

View File

@ -119,7 +119,7 @@ func (gui *Gui) handleAddRemote(g *gocui.Gui, v *gocui.View) error {
if err := gui.GitCommand.AddRemote(remoteName, remoteUrl); err != nil { if err := gui.GitCommand.AddRemote(remoteName, remoteUrl); err != nil {
return err return err
} }
return gui.refreshRemotes() return gui.refreshSidePanels(refreshOptions{scope: []int{REMOTES}})
}) })
}) })
} }
@ -134,7 +134,7 @@ func (gui *Gui) handleRemoveRemote(g *gocui.Gui, v *gocui.View) error {
return err return err
} }
return gui.refreshRemotes() return gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, REMOTES}})
}, nil) }, nil)
} }
@ -174,7 +174,7 @@ func (gui *Gui) handleEditRemote(g *gocui.Gui, v *gocui.View) error {
if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil { if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
return gui.refreshRemotes() return gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, REMOTES}})
}) })
}) })
} }
@ -190,6 +190,6 @@ func (gui *Gui) handleFetchRemote(g *gocui.Gui, v *gocui.View) error {
return err return err
} }
return gui.refreshRemotes() return gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, REMOTES}})
}) })
} }

View File

@ -12,8 +12,14 @@ import (
// never call this on its own, it should only be called from within refreshCommits() // never call this on its own, it should only be called from within refreshCommits()
func (gui *Gui) refreshStatus() { func (gui *Gui) refreshStatus() {
gui.State.RefreshingStatusMutex.Lock()
defer gui.State.RefreshingStatusMutex.Unlock()
currentBranch := gui.currentBranch() currentBranch := gui.currentBranch()
if currentBranch == nil {
// need to wait for branches to refresh
return
}
status := "" status := ""
if currentBranch.Pushables != "" && currentBranch.Pullables != "" { if currentBranch.Pushables != "" && currentBranch.Pullables != "" {

View File

@ -61,7 +61,7 @@ func (gui *Gui) refreshSidePanels(options refreshOptions) error {
scopeMap = intArrToMap(options.scope) scopeMap = intArrToMap(options.scope)
} }
if scopeMap[COMMITS] || scopeMap[BRANCHES] || scopeMap[REFLOG] || scopeMap[TAGS] || scopeMap[REMOTES] { if scopeMap[COMMITS] || scopeMap[BRANCHES] || scopeMap[REFLOG] {
wg.Add(1) wg.Add(1)
func() { func() {
if options.mode == ASYNC { if options.mode == ASYNC {
@ -97,8 +97,34 @@ func (gui *Gui) refreshSidePanels(options refreshOptions) error {
}() }()
} }
if scopeMap[TAGS] {
wg.Add(1)
func() {
if options.mode == ASYNC {
go gui.refreshTags()
} else {
gui.refreshTags()
}
wg.Done()
}()
}
if scopeMap[REMOTES] {
wg.Add(1)
func() {
if options.mode == ASYNC {
go gui.refreshRemotes()
} else {
gui.refreshRemotes()
}
wg.Done()
}()
}
wg.Wait() wg.Wait()
gui.refreshStatus()
if options.then != nil { if options.then != nil {
options.then() options.then()
} }