Skip to content

Commit

Permalink
remove old diff mode code
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Mar 29, 2020
1 parent 9eb1cbc commit 33d287d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 84 deletions.
4 changes: 1 addition & 3 deletions pkg/commands/commit_list_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ type CommitListBuilder struct {
OSCommand *OSCommand
Tr *i18n.Localizer
CherryPickedCommits []*Commit
DiffEntries []*Commit
}

// 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{
Log: log,
GitCommand: gitCommand,
OSCommand: osCommand,
Tr: tr,
CherryPickedCommits: cherryPickedCommits,
DiffEntries: diffEntries,
}, nil
}

Expand Down
50 changes: 2 additions & 48 deletions pkg/gui/commits_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (gui *Gui) refreshCommits() 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 {
return err
}
Expand Down Expand Up @@ -491,52 +491,6 @@ func (gui *Gui) handleSwitchToCommitFilesPanel(g *gocui.Gui, v *gocui.View) erro
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) {
for idx, commit := range commits {
if commit.Sha == target {
Expand Down Expand Up @@ -633,7 +587,7 @@ func (gui *Gui) renderBranchCommitsWithSelection() error {
commitsView := gui.getCommitsView()

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)
if gui.g.CurrentView() == commitsView && commitsView.Context == "branch-commits" {
if err := gui.handleCommitSelect(gui.g, commitsView); err != nil {
Expand Down
9 changes: 7 additions & 2 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ const (
COMPLETE
)

// if ref is blank we're not diffing anything
type DiffState struct {
Ref string
Left bool
}

type guiState struct {
Files []*commands.File
Branches []*commands.Branch
Expand All @@ -198,7 +204,6 @@ type guiState struct {
// if we're not in filtering mode, CommitFiles and FilteredReflogCommits will be
// one and the same
ReflogCommits []*commands.Commit
DiffEntries []*commands.Commit
Remotes []*commands.Remote
RemoteBranches []*commands.RemoteBranch
Tags []*commands.Tag
Expand All @@ -222,6 +227,7 @@ type guiState struct {
OldInformation string
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
Diff DiffState
}

func (gui *Gui) resetState() {
Expand All @@ -239,7 +245,6 @@ func (gui *Gui) resetState() {
ReflogCommits: make([]*commands.Commit, 0),
CherryPickedCommits: make([]*commands.Commit, 0),
StashEntries: make([]*commands.StashEntry, 0),
DiffEntries: make([]*commands.Commit, 0),
Panels: &panelStates{
Files: &filePanelState{SelectedLine: -1},
Branches: &branchPanelState{SelectedLine: 0},
Expand Down
8 changes: 0 additions & 8 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,14 +835,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleCheckoutCommit,
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",
Contexts: []string{"branch-commits"},
Expand Down
34 changes: 17 additions & 17 deletions pkg/gui/presentation/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ import (
"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))

var displayFunc func(*commands.Commit, map[string]bool, []*commands.Commit) []string
var displayFunc func(*commands.Commit, map[string]bool) []string
if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForCommit
} else {
displayFunc = getDisplayStringsForCommit
}

for i := range commits {
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffEntries)
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap)
}

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)
yellow := color.New(color.FgYellow)
green := color.New(color.FgGreen)
blue := color.New(color.FgBlue)
cyan := color.New(color.FgCyan)
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
// horizontally. For the sake of accessibility I'm considering this a feature,
Expand All @@ -60,11 +60,11 @@ func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedC
shaColor = copied
}

for _, entry := range diffEntries {
if c.Sha == entry.Sha {
shaColor = magenta
}
}
// for _, entry := range diffEntries {
// if c.Sha == entry.Sha {
// shaColor = magenta
// }
// }

tagString := ""
secondColumnString := blue.Sprint(utils.UnixToDate(c.UnixTimestamp))
Expand All @@ -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)}
}

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)
yellow := color.New(color.FgYellow)
green := color.New(color.FgGreen)
blue := color.New(color.FgBlue)
cyan := color.New(color.FgCyan)
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
// horizontally. For the sake of accessibility I'm considering this a feature,
Expand All @@ -114,11 +114,11 @@ func getDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map
shaColor = copied
}

for _, entry := range diffEntries {
if c.Sha == entry.Sha {
shaColor = magenta
}
}
// for _, entry := range diffEntries {
// if c.Sha == entry.Sha {
// shaColor = magenta
// }
// }

actionString := ""
tagString := ""
Expand Down
6 changes: 0 additions & 6 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "CommitsTitle",
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{
ID: "StashTitle",
Other: "Stash",
Expand Down

0 comments on commit 33d287d

Please sign in to comment.