mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-23 12:18:51 +02:00
remove old diff mode code
This commit is contained in:
parent
9eb1cbc514
commit
33d287d2f0
@ -34,18 +34,16 @@ type CommitListBuilder struct {
|
|||||||
OSCommand *OSCommand
|
OSCommand *OSCommand
|
||||||
Tr *i18n.Localizer
|
Tr *i18n.Localizer
|
||||||
CherryPickedCommits []*Commit
|
CherryPickedCommits []*Commit
|
||||||
DiffEntries []*Commit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommitListBuilder builds a new commit list builder
|
// NewCommitListBuilder builds a new commit list builder
|
||||||
func NewCommitListBuilder(log *logrus.Entry, gitCommand *GitCommand, osCommand *OSCommand, tr *i18n.Localizer, cherryPickedCommits []*Commit, diffEntries []*Commit) (*CommitListBuilder, error) {
|
func NewCommitListBuilder(log *logrus.Entry, gitCommand *GitCommand, osCommand *OSCommand, tr *i18n.Localizer, cherryPickedCommits []*Commit) (*CommitListBuilder, error) {
|
||||||
return &CommitListBuilder{
|
return &CommitListBuilder{
|
||||||
Log: log,
|
Log: log,
|
||||||
GitCommand: gitCommand,
|
GitCommand: gitCommand,
|
||||||
OSCommand: osCommand,
|
OSCommand: osCommand,
|
||||||
Tr: tr,
|
Tr: tr,
|
||||||
CherryPickedCommits: cherryPickedCommits,
|
CherryPickedCommits: cherryPickedCommits,
|
||||||
DiffEntries: diffEntries,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ func (gui *Gui) refreshCommits() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshCommitsWithLimit() error {
|
func (gui *Gui) refreshCommitsWithLimit() error {
|
||||||
builder, err := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedCommits, gui.State.DiffEntries)
|
builder, err := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedCommits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -491,52 +491,6 @@ func (gui *Gui) handleSwitchToCommitFilesPanel(g *gocui.Gui, v *gocui.View) erro
|
|||||||
return gui.switchFocus(g, gui.getCommitsView(), gui.getCommitFilesView())
|
return gui.switchFocus(g, gui.getCommitsView(), gui.getCommitFilesView())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleToggleDiffCommit(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
selectLimit := 2
|
|
||||||
|
|
||||||
// get selected commit
|
|
||||||
commit := gui.getSelectedCommit(g)
|
|
||||||
if commit == nil {
|
|
||||||
return gui.newStringTask("main", gui.Tr.SLocalize("NoCommitsThisBranch"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// if already selected commit delete
|
|
||||||
if idx, has := gui.hasCommit(gui.State.DiffEntries, commit.Sha); has {
|
|
||||||
gui.State.DiffEntries = gui.unchooseCommit(gui.State.DiffEntries, idx)
|
|
||||||
} else {
|
|
||||||
if len(gui.State.DiffEntries) == 0 {
|
|
||||||
gui.State.DiffEntries = []*commands.Commit{commit}
|
|
||||||
} else {
|
|
||||||
gui.State.DiffEntries = append(gui.State.DiffEntries[:1], commit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.setDiffMode()
|
|
||||||
|
|
||||||
// if selected two commits, display diff between
|
|
||||||
if len(gui.State.DiffEntries) == selectLimit {
|
|
||||||
commitText, err := gui.GitCommand.DiffCommits(gui.State.DiffEntries[0].Sha, gui.State.DiffEntries[1].Sha)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return gui.surfaceError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.newStringTask("main", commitText)
|
|
||||||
}
|
|
||||||
return gui.renderBranchCommitsWithSelection()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) setDiffMode() {
|
|
||||||
v := gui.getCommitsView()
|
|
||||||
if len(gui.State.DiffEntries) != 0 {
|
|
||||||
gui.State.Panels.Commits.SpecificDiffMode = true
|
|
||||||
v.Title = gui.Tr.SLocalize("CommitsDiffTitle")
|
|
||||||
} else {
|
|
||||||
gui.State.Panels.Commits.SpecificDiffMode = false
|
|
||||||
v.Title = gui.Tr.SLocalize("CommitsTitle")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) {
|
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) {
|
||||||
for idx, commit := range commits {
|
for idx, commit := range commits {
|
||||||
if commit.Sha == target {
|
if commit.Sha == target {
|
||||||
@ -633,7 +587,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(), gui.State.DiffEntries)
|
displayStrings := presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap())
|
||||||
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 {
|
||||||
|
@ -185,6 +185,12 @@ const (
|
|||||||
COMPLETE
|
COMPLETE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// if ref is blank we're not diffing anything
|
||||||
|
type DiffState struct {
|
||||||
|
Ref string
|
||||||
|
Left bool
|
||||||
|
}
|
||||||
|
|
||||||
type guiState struct {
|
type guiState struct {
|
||||||
Files []*commands.File
|
Files []*commands.File
|
||||||
Branches []*commands.Branch
|
Branches []*commands.Branch
|
||||||
@ -198,7 +204,6 @@ type guiState struct {
|
|||||||
// if we're not in filtering mode, CommitFiles and FilteredReflogCommits will be
|
// if we're not in filtering mode, CommitFiles and FilteredReflogCommits will be
|
||||||
// one and the same
|
// one and the same
|
||||||
ReflogCommits []*commands.Commit
|
ReflogCommits []*commands.Commit
|
||||||
DiffEntries []*commands.Commit
|
|
||||||
Remotes []*commands.Remote
|
Remotes []*commands.Remote
|
||||||
RemoteBranches []*commands.RemoteBranch
|
RemoteBranches []*commands.RemoteBranch
|
||||||
Tags []*commands.Tag
|
Tags []*commands.Tag
|
||||||
@ -222,6 +227,7 @@ type guiState struct {
|
|||||||
OldInformation string
|
OldInformation string
|
||||||
StartupStage int // one of INITIAL and COMPLETE. Allows us to not load everything at once
|
StartupStage int // one of INITIAL and COMPLETE. Allows us to not load everything at once
|
||||||
FilterPath string // the filename that gets passed to git log
|
FilterPath string // the filename that gets passed to git log
|
||||||
|
Diff DiffState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) resetState() {
|
func (gui *Gui) resetState() {
|
||||||
@ -239,7 +245,6 @@ func (gui *Gui) resetState() {
|
|||||||
ReflogCommits: make([]*commands.Commit, 0),
|
ReflogCommits: make([]*commands.Commit, 0),
|
||||||
CherryPickedCommits: make([]*commands.Commit, 0),
|
CherryPickedCommits: make([]*commands.Commit, 0),
|
||||||
StashEntries: make([]*commands.StashEntry, 0),
|
StashEntries: make([]*commands.StashEntry, 0),
|
||||||
DiffEntries: make([]*commands.Commit, 0),
|
|
||||||
Panels: &panelStates{
|
Panels: &panelStates{
|
||||||
Files: &filePanelState{SelectedLine: -1},
|
Files: &filePanelState{SelectedLine: -1},
|
||||||
Branches: &branchPanelState{SelectedLine: 0},
|
Branches: &branchPanelState{SelectedLine: 0},
|
||||||
|
@ -835,14 +835,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Handler: gui.handleCheckoutCommit,
|
Handler: gui.handleCheckoutCommit,
|
||||||
Description: gui.Tr.SLocalize("checkoutCommit"),
|
Description: gui.Tr.SLocalize("checkoutCommit"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ViewName: "commits",
|
|
||||||
Contexts: []string{"branch-commits"},
|
|
||||||
Key: gui.getKey("commits.toggleDiffCommit"),
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: gui.handleToggleDiffCommit,
|
|
||||||
Description: gui.Tr.SLocalize("CommitsDiff"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
Contexts: []string{"branch-commits"},
|
Contexts: []string{"branch-commits"},
|
||||||
|
@ -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, diffEntries []*commands.Commit) [][]string {
|
func GetCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool) [][]string {
|
||||||
lines := make([][]string, len(commits))
|
lines := make([][]string, len(commits))
|
||||||
|
|
||||||
var displayFunc func(*commands.Commit, map[string]bool, []*commands.Commit) []string
|
var displayFunc func(*commands.Commit, map[string]bool) []string
|
||||||
if fullDescription {
|
if fullDescription {
|
||||||
displayFunc = getFullDescriptionDisplayStringsForCommit
|
displayFunc = getFullDescriptionDisplayStringsForCommit
|
||||||
} else {
|
} else {
|
||||||
@ -20,20 +20,20 @@ func GetCommitListDisplayStrings(commits []*commands.Commit, fullDescription boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range commits {
|
for i := range commits {
|
||||||
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffEntries)
|
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffEntries []*commands.Commit) []string {
|
func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool) []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)
|
||||||
blue := color.New(color.FgBlue)
|
blue := color.New(color.FgBlue)
|
||||||
cyan := color.New(color.FgCyan)
|
cyan := color.New(color.FgCyan)
|
||||||
defaultColor := color.New(theme.DefaultTextColor)
|
defaultColor := color.New(theme.DefaultTextColor)
|
||||||
magenta := color.New(color.FgMagenta)
|
// magenta := color.New(color.FgMagenta)
|
||||||
|
|
||||||
// for some reason, setting the background to blue pads out the other commits
|
// for some reason, setting the background to blue pads out the other commits
|
||||||
// horizontally. For the sake of accessibility I'm considering this a feature,
|
// horizontally. For the sake of accessibility I'm considering this a feature,
|
||||||
@ -60,11 +60,11 @@ func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedC
|
|||||||
shaColor = copied
|
shaColor = copied
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, entry := range diffEntries {
|
// for _, entry := range diffEntries {
|
||||||
if c.Sha == entry.Sha {
|
// if c.Sha == entry.Sha {
|
||||||
shaColor = magenta
|
// shaColor = magenta
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
tagString := ""
|
tagString := ""
|
||||||
secondColumnString := blue.Sprint(utils.UnixToDate(c.UnixTimestamp))
|
secondColumnString := blue.Sprint(utils.UnixToDate(c.UnixTimestamp))
|
||||||
@ -80,14 +80,14 @@ 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, diffEntries []*commands.Commit) []string {
|
func getDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool) []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)
|
||||||
blue := color.New(color.FgBlue)
|
blue := color.New(color.FgBlue)
|
||||||
cyan := color.New(color.FgCyan)
|
cyan := color.New(color.FgCyan)
|
||||||
defaultColor := color.New(theme.DefaultTextColor)
|
defaultColor := color.New(theme.DefaultTextColor)
|
||||||
magenta := color.New(color.FgMagenta)
|
// magenta := color.New(color.FgMagenta)
|
||||||
|
|
||||||
// for some reason, setting the background to blue pads out the other commits
|
// for some reason, setting the background to blue pads out the other commits
|
||||||
// horizontally. For the sake of accessibility I'm considering this a feature,
|
// horizontally. For the sake of accessibility I'm considering this a feature,
|
||||||
@ -114,11 +114,11 @@ func getDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map
|
|||||||
shaColor = copied
|
shaColor = copied
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, entry := range diffEntries {
|
// for _, entry := range diffEntries {
|
||||||
if c.Sha == entry.Sha {
|
// if c.Sha == entry.Sha {
|
||||||
shaColor = magenta
|
// shaColor = magenta
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
actionString := ""
|
actionString := ""
|
||||||
tagString := ""
|
tagString := ""
|
||||||
|
@ -36,12 +36,6 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CommitsTitle",
|
ID: "CommitsTitle",
|
||||||
Other: "Commits",
|
Other: "Commits",
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "CommitsDiffTitle",
|
|
||||||
Other: "Commits (specific diff mode)",
|
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "CommitsDiff",
|
|
||||||
Other: "select commit to diff with another commit",
|
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StashTitle",
|
ID: "StashTitle",
|
||||||
Other: "Stash",
|
Other: "Stash",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user