1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-25 12:24:47 +02:00

more efficient refreshing

This commit is contained in:
Jesse Duffield 2020-03-26 23:20:12 +11:00
parent fbbd16bd82
commit efb51eee96
5 changed files with 54 additions and 83 deletions

View File

@ -53,32 +53,20 @@ 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(g *gocui.Gui) error { func (gui *Gui) refreshBranches() {
if err := gui.refreshRemotes(); err != nil { _ = gui.refreshRemotes()
return err _ = gui.refreshTags()
builder, err := commands.NewBranchListBuilder(gui.Log, gui.GitCommand, gui.State.ReflogCommits)
if err != nil {
_ = gui.createErrorPanel(gui.g, err.Error())
} }
gui.State.Branches = builder.Build()
if err := gui.refreshTags(); err != nil { // TODO: if we're in the remotes view and we've just deleted a remote we need to refresh accordingly
return err if gui.getBranchesView().Context == "local-branches" {
gui.renderLocalBranchesWithSelection()
} }
g.Update(func(g *gocui.Gui) error {
builder, err := commands.NewBranchListBuilder(gui.Log, gui.GitCommand, gui.State.ReflogCommits)
if err != nil {
return err
}
gui.State.Branches = builder.Build()
// TODO: if we're in the remotes view and we've just deleted a remote we need to refresh accordingly
if gui.getBranchesView().Context == "local-branches" {
if err := gui.renderLocalBranchesWithSelection(); err != nil {
return err
}
}
return gui.refreshStatus(g)
})
return nil
} }
func (gui *Gui) renderLocalBranchesWithSelection() error { func (gui *Gui) renderLocalBranchesWithSelection() error {

View File

@ -71,27 +71,26 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
} }
func (gui *Gui) refreshCommits(g *gocui.Gui) error { func (gui *Gui) refreshCommits(g *gocui.Gui) error {
g.Update(func(*gocui.Gui) error { if err := gui.updateWorkTreeState(); err != nil {
// I think this is here for the sake of some kind of rebasing thing return gui.createErrorPanel(gui.g, err.Error())
_ = gui.refreshStatus(g) }
if err := gui.refreshCommitsWithLimit(); err != nil { if err := gui.refreshCommitsWithLimit(); err != nil {
return err return gui.createErrorPanel(gui.g, err.Error())
} }
if err := gui.refreshReflogCommits(); err != nil { if err := gui.refreshReflogCommits(); err != nil {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
if err := gui.refreshBranches(gui.g); err != nil { gui.refreshBranches()
return gui.createErrorPanel(gui.g, err.Error())
} gui.refreshStatus()
if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.MainContext == "patch-building") {
return gui.refreshCommitFilesView()
}
if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.MainContext == "patch-building") {
return gui.refreshCommitFilesView()
}
return nil
})
return nil return nil
} }

View File

@ -157,11 +157,6 @@ type commitFilesPanelState struct {
SelectedLine int SelectedLine int
} }
type statusPanelState struct {
pushables string
pullables string
}
type panelStates struct { type panelStates struct {
Files *filePanelState Files *filePanelState
Branches *branchPanelState Branches *branchPanelState
@ -175,7 +170,6 @@ type panelStates struct {
LineByLine *lineByLinePanelState LineByLine *lineByLinePanelState
Merging *mergingPanelState Merging *mergingPanelState
CommitFiles *commitFilesPanelState CommitFiles *commitFilesPanelState
Status *statusPanelState
} }
type searchingState struct { type searchingState struct {
@ -246,7 +240,6 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
Conflicts: []commands.Conflict{}, Conflicts: []commands.Conflict{},
EditHistory: stack.New(), EditHistory: stack.New(),
}, },
Status: &statusPanelState{},
}, },
ScreenMode: SCREEN_NORMAL, ScreenMode: SCREEN_NORMAL,
SideView: nil, SideView: nil,
@ -930,7 +923,9 @@ func (gui *Gui) fetch(g *gocui.Gui, v *gocui.View, canAskForCredentials bool) (u
_ = gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("Error"), coloredMessage, close, close) _ = gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("Error"), coloredMessage, close, close)
} }
_ = gui.refreshStatus(g) if err := gui.refreshCommits(g); err != nil {
return unamePassOpend, err
}
return unamePassOpend, err return unamePassOpend, err
} }

View File

@ -10,50 +10,34 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
func (gui *Gui) refreshStatus(g *gocui.Gui) error { // never call this on its own, it should only be called from within refreshCommits()
state := gui.State.Panels.Status func (gui *Gui) refreshStatus() {
currentBranch := gui.currentBranch()
v, err := g.View("status") status := ""
if err != nil {
panic(err)
}
// for some reason if this isn't wrapped in an update the clear seems to
// be applied after the other things or something like that; the panel's
// contents end up cleared
g.Update(func(*gocui.Gui) error {
v.Clear()
// TODO: base this off of the current branch
state.pushables, state.pullables = gui.GitCommand.GetCurrentBranchUpstreamDifferenceCount()
if err := gui.updateWorkTreeState(); err != nil {
return err
}
if currentBranch.Pushables != "" && currentBranch.Pullables != "" {
trackColor := color.FgYellow trackColor := color.FgYellow
if state.pushables == "0" && state.pullables == "0" { if currentBranch.Pushables == "0" && currentBranch.Pullables == "0" {
trackColor = color.FgGreen trackColor = color.FgGreen
} else if state.pushables == "?" && state.pullables == "?" { } else if currentBranch.Pushables == "?" && currentBranch.Pullables == "?" {
trackColor = color.FgRed trackColor = color.FgRed
} }
status := utils.ColoredString(fmt.Sprintf("↑%s↓%s", state.pushables, state.pullables), trackColor) status = utils.ColoredString(fmt.Sprintf("↑%s↓%s ", currentBranch.Pushables, currentBranch.Pullables), trackColor)
branches := gui.State.Branches }
if gui.State.WorkingTreeState != "normal" { if gui.State.WorkingTreeState != "normal" {
status += utils.ColoredString(fmt.Sprintf(" (%s)", gui.State.WorkingTreeState), color.FgYellow) status += utils.ColoredString(fmt.Sprintf("(%s) ", gui.State.WorkingTreeState), color.FgYellow)
} }
if len(branches) > 0 { name := utils.ColoredString(currentBranch.Name, presentation.GetBranchColor(currentBranch.Name))
branch := branches[0] repoName := utils.GetCurrentRepoName()
name := utils.ColoredString(branch.Name, presentation.GetBranchColor(branch.Name)) status += fmt.Sprintf("%s → %s ", repoName, name)
repoName := utils.GetCurrentRepoName()
status += fmt.Sprintf(" %s → %s", repoName, name)
}
fmt.Fprint(v, status) gui.g.Update(func(*gocui.Gui) error {
gui.setViewContent(gui.g, gui.getStatusView(), status)
return nil return nil
}) })
return nil
} }
func runeCount(str string) int { func runeCount(str string) int {
@ -70,10 +54,10 @@ func (gui *Gui) handleCheckForUpdate(g *gocui.Gui, v *gocui.View) error {
} }
func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error {
state := gui.State.Panels.Status currentBranch := gui.currentBranch()
cx, _ := v.Cursor() cx, _ := v.Cursor()
upstreamStatus := fmt.Sprintf("↑%s↓%s", state.pushables, state.pullables) upstreamStatus := fmt.Sprintf("↑%s↓%s", currentBranch.Pushables, currentBranch.Pullables)
repoName := utils.GetCurrentRepoName() repoName := utils.GetCurrentRepoName()
gui.Log.Warn(gui.State.WorkingTreeState) gui.Log.Warn(gui.State.WorkingTreeState)
switch gui.State.WorkingTreeState { switch gui.State.WorkingTreeState {

View File

@ -309,6 +309,11 @@ func (gui *Gui) getSearchView() *gocui.View {
return v return v
} }
func (gui *Gui) getStatusView() *gocui.View {
v, _ := gui.g.View("status")
return v
}
func (gui *Gui) trimmedContent(v *gocui.View) string { func (gui *Gui) trimmedContent(v *gocui.View) string {
return strings.TrimSpace(v.Buffer()) return strings.TrimSpace(v.Buffer())
} }