1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-04 22:34:39 +02:00

more smart refreshing

WIP

WIP

WIP

WIP

WIP

fix how diff entries are handled

WIP

WIP

WIP

WIP

WIP

WIP
This commit is contained in:
Jesse Duffield 2020-03-27 21:25:37 +11:00
parent d0336fe16f
commit c1a4bd0482
7 changed files with 60 additions and 68 deletions

View File

@ -129,14 +129,6 @@ func (c *CommitListBuilder) GetCommits(limit bool) ([]*Commit, error) {
return nil, err return nil, err
} }
for _, commit := range commits {
for _, entry := range c.DiffEntries {
if entry.Sha == commit.Sha {
commit.Status = "selected"
}
}
}
return commits, nil return commits, nil
} }

View File

@ -358,7 +358,7 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error {
if err := gui.GitCommand.FastForward(branch.Name, remoteName, remoteBranchName); err != nil { if err := gui.GitCommand.FastForward(branch.Name, remoteName, remoteBranchName); err != nil {
_ = gui.createErrorPanel(gui.g, err.Error()) _ = gui.createErrorPanel(gui.g, err.Error())
} }
_ = gui.refreshCommits() _ = gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{BRANCHES}})
} }
_ = gui.closeConfirmationPrompt(gui.g, true) _ = gui.closeConfirmationPrompt(gui.g, true)
@ -453,6 +453,9 @@ func (gui *Gui) handleRenameBranch(g *gocui.Gui, v *gocui.View) error {
return nil return nil
} }
// TODO: find a way to not checkout the branch here if it's not the current branch (i.e. find some
// way to get it to show up in the reflog)
promptForNewName := func() error { promptForNewName := func() error {
return gui.createPromptPanel(g, v, gui.Tr.SLocalize("NewBranchNamePrompt")+" "+branch.Name+":", "", func(g *gocui.Gui, v *gocui.View) error { return gui.createPromptPanel(g, v, gui.Tr.SLocalize("NewBranchNamePrompt")+" "+branch.Name+":", "", func(g *gocui.Gui, v *gocui.View) error {
newName := gui.trimmedContent(v) newName := gui.trimmedContent(v)
@ -465,7 +468,7 @@ func (gui *Gui) handleRenameBranch(g *gocui.Gui, v *gocui.View) error {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
return gui.refreshCommits() return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
}) })
} }

View File

@ -177,10 +177,8 @@ func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error {
if err := gui.GitCommand.RenameCommit(v.Buffer()); err != nil { if err := gui.GitCommand.RenameCommit(v.Buffer()); err != nil {
return gui.createErrorPanel(g, err.Error()) return gui.createErrorPanel(g, err.Error())
} }
if err := gui.refreshCommits(); err != nil {
panic(err) return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
}
return gui.handleCommitSelect(g, v)
}) })
} }
@ -225,7 +223,9 @@ func (gui *Gui) handleMidRebaseCommand(action string) (bool, error) {
if err := gui.GitCommand.EditRebaseTodo(gui.State.Panels.Commits.SelectedLine, action); err != nil { if err := gui.GitCommand.EditRebaseTodo(gui.State.Panels.Commits.SelectedLine, action); err != nil {
return false, gui.createErrorPanel(gui.g, err.Error()) return false, gui.createErrorPanel(gui.g, err.Error())
} }
return true, gui.refreshCommits() // TODO: consider doing this in a way that is less expensive. We don't actually
// need to reload all the commits, just the TODO commits.
return true, gui.refreshSidePanels(refreshOptions{scope: []int{COMMITS}})
} }
func (gui *Gui) handleCommitDelete(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitDelete(g *gocui.Gui, v *gocui.View) error {
@ -256,7 +256,7 @@ func (gui *Gui) handleCommitMoveDown(g *gocui.Gui, v *gocui.View) error {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
gui.State.Panels.Commits.SelectedLine++ gui.State.Panels.Commits.SelectedLine++
return gui.refreshCommits() return gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI, scope: []int{COMMITS, BRANCHES}})
} }
return gui.WithWaitingStatus(gui.Tr.SLocalize("MovingStatus"), func() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("MovingStatus"), func() error {
@ -279,7 +279,7 @@ func (gui *Gui) handleCommitMoveUp(g *gocui.Gui, v *gocui.View) error {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
gui.State.Panels.Commits.SelectedLine-- gui.State.Panels.Commits.SelectedLine--
return gui.refreshCommits() return gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI, scope: []int{COMMITS, BRANCHES}})
} }
return gui.WithWaitingStatus(gui.Tr.SLocalize("MovingStatus"), func() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("MovingStatus"), func() error {
@ -334,7 +334,7 @@ func (gui *Gui) handleCommitRevert(g *gocui.Gui, v *gocui.View) error {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
gui.State.Panels.Commits.SelectedLine++ gui.State.Panels.Commits.SelectedLine++
return gui.refreshCommits() return gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI, scope: []int{COMMITS, BRANCHES}})
} }
func (gui *Gui) handleCopyCommit(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCopyCommit(g *gocui.Gui, v *gocui.View) error {
@ -345,12 +345,12 @@ func (gui *Gui) handleCopyCommit(g *gocui.Gui, v *gocui.View) error {
for index, cherryPickedCommit := range gui.State.CherryPickedCommits { for index, cherryPickedCommit := range gui.State.CherryPickedCommits {
if commit.Sha == cherryPickedCommit.Sha { if commit.Sha == cherryPickedCommit.Sha {
gui.State.CherryPickedCommits = append(gui.State.CherryPickedCommits[0:index], gui.State.CherryPickedCommits[index+1:]...) gui.State.CherryPickedCommits = append(gui.State.CherryPickedCommits[0:index], gui.State.CherryPickedCommits[index+1:]...)
return gui.refreshCommits() return gui.renderBranchCommitsWithSelection()
} }
} }
gui.addCommitToCherryPickedCommits(gui.State.Panels.Commits.SelectedLine) gui.addCommitToCherryPickedCommits(gui.State.Panels.Commits.SelectedLine)
return gui.refreshCommits() return gui.renderBranchCommitsWithSelection()
} }
func (gui *Gui) cherryPickedCommitShaMap() map[string]bool { func (gui *Gui) cherryPickedCommitShaMap() map[string]bool {
@ -428,10 +428,11 @@ func (gui *Gui) handleToggleDiffCommit(g *gocui.Gui, v *gocui.View) error {
if idx, has := gui.hasCommit(gui.State.DiffEntries, commit.Sha); has { if idx, has := gui.hasCommit(gui.State.DiffEntries, commit.Sha); has {
gui.State.DiffEntries = gui.unchooseCommit(gui.State.DiffEntries, idx) gui.State.DiffEntries = gui.unchooseCommit(gui.State.DiffEntries, idx)
} else { } else {
if len(gui.State.DiffEntries) == selectLimit { if len(gui.State.DiffEntries) == 0 {
gui.State.DiffEntries = gui.unchooseCommit(gui.State.DiffEntries, 0) gui.State.DiffEntries = []*commands.Commit{commit}
} else {
gui.State.DiffEntries = append(gui.State.DiffEntries[:1], commit)
} }
gui.State.DiffEntries = append(gui.State.DiffEntries, commit)
} }
gui.setDiffMode() gui.setDiffMode()
@ -444,10 +445,9 @@ func (gui *Gui) handleToggleDiffCommit(g *gocui.Gui, v *gocui.View) error {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
return gui.newStringTask("main", commitText) gui.newStringTask("main", commitText)
} }
return gui.renderBranchCommitsWithSelection()
return nil
} }
func (gui *Gui) setDiffMode() { func (gui *Gui) setDiffMode() {
@ -459,8 +459,6 @@ func (gui *Gui) setDiffMode() {
gui.State.Panels.Commits.SpecificDiffMode = false gui.State.Panels.Commits.SpecificDiffMode = false
v.Title = gui.Tr.SLocalize("CommitsTitle") v.Title = gui.Tr.SLocalize("CommitsTitle")
} }
_ = gui.refreshCommits()
} }
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) { func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) {
@ -532,13 +530,7 @@ func (gui *Gui) handleCreateLightweightTag(commitSha string) error {
if err := gui.GitCommand.CreateLightweightTag(v.Buffer(), commitSha); err != nil { if err := gui.GitCommand.CreateLightweightTag(v.Buffer(), commitSha); err != nil {
return gui.createErrorPanel(g, err.Error()) return gui.createErrorPanel(g, err.Error())
} }
if err := gui.refreshCommits(); err != nil { return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{COMMITS, TAGS}})
return gui.createErrorPanel(g, err.Error())
}
if err := gui.refreshTags(); err != nil {
return gui.createErrorPanel(g, err.Error())
}
return gui.handleCommitSelect(g, v)
}) })
} }
@ -557,7 +549,7 @@ func (gui *Gui) renderBranchCommitsWithSelection() error {
commitsView := gui.getCommitsView() commitsView := gui.getCommitsView()
gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits)) gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits))
displayStrings := presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap()) displayStrings := presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.DiffEntries)
gui.renderDisplayStrings(commitsView, displayStrings) gui.renderDisplayStrings(commitsView, displayStrings)
if gui.g.CurrentView() == commitsView && commitsView.Context == "branch-commits" { if gui.g.CurrentView() == commitsView && commitsView.Context == "branch-commits" {
if err := gui.handleCommitSelect(gui.g, commitsView); err != nil { if err := gui.handleCommitSelect(gui.g, commitsView); err != nil {
@ -644,7 +636,7 @@ func (gui *Gui) handleOpenSearchForCommitsPanel(g *gocui.Gui, v *gocui.View) err
// we usually lazyload these commits but now that we're searching we need to load them now // we usually lazyload these commits but now that we're searching we need to load them now
if gui.State.Panels.Commits.LimitCommits { if gui.State.Panels.Commits.LimitCommits {
gui.State.Panels.Commits.LimitCommits = false gui.State.Panels.Commits.LimitCommits = false
if err := gui.refreshCommits(); err != nil { if err := gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{COMMITS}}); err != nil {
return err return err
} }
} }
@ -654,5 +646,5 @@ func (gui *Gui) handleOpenSearchForCommitsPanel(g *gocui.Gui, v *gocui.View) err
func (gui *Gui) handleResetCherryPick(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleResetCherryPick(g *gocui.Gui, v *gocui.View) error {
gui.State.CherryPickedCommits = []*commands.Commit{} gui.State.CherryPickedCommits = []*commands.Commit{}
return gui.refreshCommits() return gui.renderBranchCommitsWithSelection()
} }

View File

@ -57,7 +57,7 @@ func (gui *Gui) handleSubmitCredential(g *gocui.Gui, v *gocui.View) error {
if err != nil { if err != nil {
return err return err
} }
return gui.refreshCommits() return gui.refreshSidePanels(refreshOptions{})
} }
func (gui *Gui) handleCloseCredentialsView(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCloseCredentialsView(g *gocui.Gui, v *gocui.View) error {

View File

@ -922,9 +922,7 @@ 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)
} }
if err := gui.refreshCommits(); err != nil { gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, COMMITS, REMOTES, TAGS}, mode: ASYNC})
return unamePassOpend, err
}
return unamePassOpend, err return unamePassOpend, err
} }

View File

@ -9,10 +9,10 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
func GetCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool) [][]string { func GetCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffEntries []*commands.Commit) [][]string {
lines := make([][]string, len(commits)) lines := make([][]string, len(commits))
var displayFunc func(*commands.Commit, map[string]bool) []string var displayFunc func(*commands.Commit, map[string]bool, []*commands.Commit) []string
if fullDescription { if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForCommit displayFunc = getFullDescriptionDisplayStringsForCommit
} else { } else {
@ -20,13 +20,13 @@ func GetCommitListDisplayStrings(commits []*commands.Commit, fullDescription boo
} }
for i := range commits { for i := range commits {
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap) lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffEntries)
} }
return lines return lines
} }
func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool) []string { func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffEntries []*commands.Commit) []string {
red := color.New(color.FgRed) red := color.New(color.FgRed)
yellow := color.New(color.FgYellow) yellow := color.New(color.FgYellow)
green := color.New(color.FgGreen) green := color.New(color.FgGreen)
@ -52,8 +52,6 @@ func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedC
shaColor = blue shaColor = blue
case "reflog": case "reflog":
shaColor = blue shaColor = blue
case "selected":
shaColor = magenta
default: default:
shaColor = defaultColor shaColor = defaultColor
} }
@ -62,6 +60,12 @@ func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedC
shaColor = copied shaColor = copied
} }
for _, entry := range diffEntries {
if c.Sha == entry.Sha {
shaColor = magenta
}
}
tagString := "" tagString := ""
secondColumnString := blue.Sprint(utils.UnixToDate(c.UnixTimestamp)) secondColumnString := blue.Sprint(utils.UnixToDate(c.UnixTimestamp))
if c.Action != "" { if c.Action != "" {
@ -76,7 +80,7 @@ func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedC
return []string{shaColor.Sprint(c.ShortSha()), secondColumnString, yellow.Sprint(truncatedAuthor), tagString + defaultColor.Sprint(c.Name)} return []string{shaColor.Sprint(c.ShortSha()), secondColumnString, yellow.Sprint(truncatedAuthor), tagString + defaultColor.Sprint(c.Name)}
} }
func getDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool) []string { func getDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffEntries []*commands.Commit) []string {
red := color.New(color.FgRed) red := color.New(color.FgRed)
yellow := color.New(color.FgYellow) yellow := color.New(color.FgYellow)
green := color.New(color.FgGreen) green := color.New(color.FgGreen)
@ -102,8 +106,6 @@ func getDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map
shaColor = blue shaColor = blue
case "reflog": case "reflog":
shaColor = blue shaColor = blue
case "selected":
shaColor = magenta
default: default:
shaColor = defaultColor shaColor = defaultColor
} }
@ -112,6 +114,12 @@ func getDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map
shaColor = copied shaColor = copied
} }
for _, entry := range diffEntries {
if c.Sha == entry.Sha {
shaColor = magenta
}
}
actionString := "" actionString := ""
tagString := "" tagString := ""
if c.Action != "" { if c.Action != "" {

View File

@ -69,7 +69,7 @@ func (gui *Gui) renderTagsWithSelection() error {
gui.renderDisplayStrings(branchesView, displayStrings) gui.renderDisplayStrings(branchesView, displayStrings)
if gui.g.CurrentView() == branchesView && branchesView.Context == "tags" { if gui.g.CurrentView() == branchesView && branchesView.Context == "tags" {
if err := gui.handleTagSelect(gui.g, branchesView); err != nil { if err := gui.handleTagSelect(gui.g, branchesView); err != nil {
return err return gui.createErrorPanel(gui.g, err.Error())
} }
} }
@ -104,13 +104,7 @@ func (gui *Gui) handleDeleteTag(g *gocui.Gui, v *gocui.View) error {
if err := gui.GitCommand.DeleteTag(tag.Name); err != nil { if err := gui.GitCommand.DeleteTag(tag.Name); err != nil {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
if err := gui.refreshCommits(); err != nil { return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{COMMITS, TAGS}})
return gui.createErrorPanel(g, err.Error())
}
if err := gui.refreshTags(); err != nil {
return gui.createErrorPanel(g, err.Error())
}
return nil
}, nil) }, nil)
} }
@ -131,23 +125,28 @@ func (gui *Gui) handlePushTag(g *gocui.Gui, v *gocui.View) error {
if err := gui.GitCommand.PushTag(v.Buffer(), tag.Name); err != nil { if err := gui.GitCommand.PushTag(v.Buffer(), tag.Name); err != nil {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
return gui.refreshTags() return nil
}) })
} }
func (gui *Gui) handleCreateTag(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCreateTag(g *gocui.Gui, v *gocui.View) error {
return gui.createPromptPanel(gui.g, v, gui.Tr.SLocalize("CreateTagTitle"), "", func(g *gocui.Gui, v *gocui.View) error { return gui.createPromptPanel(gui.g, v, gui.Tr.SLocalize("CreateTagTitle"), "", func(g *gocui.Gui, v *gocui.View) error {
// leaving commit SHA blank so that we're just creating the tag for the current commit // leaving commit SHA blank so that we're just creating the tag for the current commit
if err := gui.GitCommand.CreateLightweightTag(v.Buffer(), ""); err != nil { tagName := v.Buffer()
if err := gui.GitCommand.CreateLightweightTag(tagName, ""); err != nil {
return gui.createErrorPanel(gui.g, err.Error()) return gui.createErrorPanel(gui.g, err.Error())
} }
if err := gui.refreshCommits(); err != nil { return gui.refreshSidePanels(refreshOptions{scope: []int{COMMITS, TAGS}, then: func() {
return gui.createErrorPanel(g, err.Error()) // find the index of the tag and set that as the currently selected line
} for i, tag := range gui.State.Tags {
if err := gui.refreshTags(); err != nil { if tag.Name == tagName {
return gui.createErrorPanel(g, err.Error()) gui.State.Panels.Tags.SelectedLine = i
} gui.renderTagsWithSelection()
return nil return
}
}
},
})
}) })
} }