1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-17 14:11:02 +02:00
This commit is contained in:
skanehira 2019-03-28 18:58:34 +09:00 committed by Jesse Duffield
parent c350cdba43
commit f34be1896a
7 changed files with 46 additions and 40 deletions

View File

@ -9,11 +9,10 @@ import (
type Commit struct {
Sha string
Name string
Status string // one of "unpushed", "pushed", "merged", or "rebasing"
Status string // one of "unpushed", "pushed", "merged", "rebasing" or "selected"
DisplayString string
Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
Copied bool // to know if this commit is ready to be cherry-picked somewhere
Selected bool
}
// GetDisplayStrings is a function.
@ -24,6 +23,7 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
blue := color.New(color.FgBlue)
cyan := color.New(color.FgCyan)
white := color.New(color.FgWhite)
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,
@ -40,6 +40,8 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
shaColor = green
case "rebasing":
shaColor = blue
case "selected":
shaColor = magenta
default:
shaColor = white
}
@ -53,12 +55,5 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " "
}
name := ""
if c.Selected {
name = color.New(color.FgMagenta).Sprint(c.Name)
} else {
name = white.Sprint(c.Name)
}
return []string{shaColor.Sprint(c.Sha), actionString + name}
return []string{shaColor.Sprint(c.Sha), actionString + white.Sprint(c.Name)}
}

View File

@ -31,16 +31,18 @@ type CommitListBuilder struct {
OSCommand *commands.OSCommand
Tr *i18n.Localizer
CherryPickedCommits []*commands.Commit
DiffEntries []*commands.Commit
}
// NewCommitListBuilder builds a new commit list builder
func NewCommitListBuilder(log *logrus.Entry, gitCommand *commands.GitCommand, osCommand *commands.OSCommand, tr *i18n.Localizer, cherryPickedCommits []*commands.Commit) (*CommitListBuilder, error) {
func NewCommitListBuilder(log *logrus.Entry, gitCommand *commands.GitCommand, osCommand *commands.OSCommand, tr *i18n.Localizer, cherryPickedCommits []*commands.Commit, diffEntries []*commands.Commit) (*CommitListBuilder, error) {
return &CommitListBuilder{
Log: log,
GitCommand: gitCommand,
OSCommand: osCommand,
Tr: tr,
CherryPickedCommits: cherryPickedCommits,
DiffEntries: diffEntries,
}, nil
}
@ -96,6 +98,14 @@ func (c *CommitListBuilder) GetCommits() ([]*commands.Commit, error) {
return nil, err
}
for _, commit := range commits {
for _, entry := range c.DiffEntries {
if entry.Sha == commit.Sha {
commit.Status = "selected"
}
}
}
return commits, nil
}

View File

@ -54,7 +54,7 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) refreshCommits(g *gocui.Gui) error {
g.Update(func(*gocui.Gui) error {
builder, err := git.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedCommits)
builder, err := git.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedCommits, gui.State.DiffEntries)
if err != nil {
return err
}
@ -62,13 +62,6 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error {
if err != nil {
return err
}
for _, commit := range commits {
if _, has := gui.State.DiffEntries[commit.Sha]; has {
commit.Selected = true
}
}
gui.State.Commits = commits
gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits))
@ -472,25 +465,20 @@ func (gui *Gui) handleToggleDiffCommit(g *gocui.Gui, v *gocui.View) error {
}
// if already selected commit delete
if _, has := gui.State.DiffEntries[commit.Sha]; has {
delete(gui.State.DiffEntries, commit.Sha)
gui.setDiffMode()
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) == selectLimit {
return gui.createErrorPanel(gui.g, "you have already selected two commit, please deselect one of two")
gui.State.DiffEntries = gui.unchooseCommit(gui.State.DiffEntries, 0)
}
gui.State.DiffEntries[commit.Sha] = commit
gui.setDiffMode()
gui.State.DiffEntries = append(gui.State.DiffEntries, commit)
}
// if selected tow commits, display diff between
if len(gui.State.DiffEntries) == selectLimit {
var entries []string
for _, entry := range gui.State.DiffEntries {
entries = append(entries, entry.Sha)
}
gui.setDiffMode()
commitText, err := gui.GitCommand.DiffCommits(entries[0], entries[1])
// 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.createErrorPanel(gui.g, err.Error())
@ -514,3 +502,16 @@ func (gui *Gui) setDiffMode() {
gui.refreshCommits(gui.g)
}
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) {
for idx, commit := range commits {
if commit.Sha == target {
return idx, true
}
}
return -1, false
}
func (gui *Gui) unchooseCommit(commits []*commands.Commit, i int) []*commands.Commit {
return append(commits[:i], commits[i+1:]...)
}

View File

@ -136,7 +136,7 @@ type guiState struct {
Commits []*commands.Commit
StashEntries []*commands.StashEntry
CommitFiles []*commands.CommitFile
DiffEntries map[string]*commands.Commit
DiffEntries []*commands.Commit
MenuItemCount int // can't store the actual list because it's of interface{} type
PreviousView string
Platform commands.Platform
@ -156,7 +156,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
Commits: make([]*commands.Commit, 0),
CherryPickedCommits: make([]*commands.Commit, 0),
StashEntries: make([]*commands.StashEntry, 0),
DiffEntries: make(map[string]*commands.Commit),
DiffEntries: make([]*commands.Commit, 0),
Platform: *oSCommand.Platform,
Panels: &panelStates{
Files: &filePanelState{SelectedLine: -1},

View File

@ -30,10 +30,10 @@ func addDutch(i18nObject *i18n.Bundle) error {
Other: "Commits",
}, &i18n.Message{
ID: "CommitsDiffTitle",
Other: "Commits(specific diff mode)",
Other: "Commits (specific diff mode)",
}, &i18n.Message{
ID: "CommitsDiff",
Other: "diff specific commits",
Other: "select commit to diff with another commit",
}, &i18n.Message{
ID: "StashTitle",
Other: "Stash",

View File

@ -38,10 +38,10 @@ func addEnglish(i18nObject *i18n.Bundle) error {
Other: "Commits",
}, &i18n.Message{
ID: "CommitsDiffTitle",
Other: "Commits(specific diff mode)",
Other: "Commits (specific diff mode)",
}, &i18n.Message{
ID: "CommitsDiff",
Other: "diff specific commits",
Other: "select commit to diff with another commit",
}, &i18n.Message{
ID: "StashTitle",
Other: "Stash",

View File

@ -28,10 +28,10 @@ func addPolish(i18nObject *i18n.Bundle) error {
Other: "Commity",
}, &i18n.Message{
ID: "CommitsDiffTitle",
Other: "Commits(specific diff mode)",
Other: "Commits (specific diff mode)",
}, &i18n.Message{
ID: "CommitsDiff",
Other: "diff specific commits",
Other: "select commit to diff with another commit",
}, &i18n.Message{
ID: "StashTitle",
Other: "Schowek",