summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskanehira <sho19921005@gmail.com>2019-03-28 18:58:34 +0900
committerJesse Duffield <jessedduffield@gmail.com>2019-04-06 13:02:20 +1100
commitf34be1896af14df2d636aa9aa3cfa857994a22b5 (patch)
tree5ab2fdbb29f2b95b074aa2075f5e3bab8fd66b8c
parentc350cdba4337fa8961e5fbe16e70d73fae7ccc20 (diff)
fixed some #397
-rw-r--r--pkg/commands/commit.go15
-rw-r--r--pkg/git/commit_list_builder.go12
-rw-r--r--pkg/gui/commits_panel.go43
-rw-r--r--pkg/gui/gui.go4
-rw-r--r--pkg/i18n/dutch.go4
-rw-r--r--pkg/i18n/english.go4
-rw-r--r--pkg/i18n/polish.go4
7 files changed, 46 insertions, 40 deletions
diff --git a/pkg/commands/commit.go b/pkg/commands/commit.go
index 8f23ca001..e8a0a52e7 100644
--- a/pkg/commands/commit.go
+++ b/pkg/commands/commit.go
@@ -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)}
}
diff --git a/pkg/git/commit_list_builder.go b/pkg/git/commit_list_builder.go
index 4f3268195..32116656d 100644
--- a/pkg/git/commit_list_builder.go
+++ b/pkg/git/commit_list_builder.go
@@ -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
}
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index 0d3dd6e84..cd7aa9530 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -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:]...)
+}
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index f6cdd093d..99250c9ac 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -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},
diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go
index c87f93c9b..d5c3423d5 100644
--- a/pkg/i18n/dutch.go
+++ b/pkg/i18n/dutch.go
@@ -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",
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index c5fd61924..5d838cb89 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -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",
diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go
index cf9d7abf5..38ef84489 100644
--- a/pkg/i18n/polish.go
+++ b/pkg/i18n/polish.go
@@ -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",