summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-26 21:11:21 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-26 21:44:33 +1100
commit91a404d0331132d3aac463a4e77a7c73b81c5961 (patch)
treef9d177489f39185b2a17eade253f58426f39c44c /pkg/commands
parentd027cf969c56f3dcf8bc3ddd73e09f5ba975677f (diff)
separate commits from cherry pick state
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/commit.go18
-rw-r--r--pkg/commands/commit_list_builder.go41
-rw-r--r--pkg/commands/os.go29
3 files changed, 52 insertions, 36 deletions
diff --git a/pkg/commands/commit.go b/pkg/commands/commit.go
index 32daeaa23..a400da928 100644
--- a/pkg/commands/commit.go
+++ b/pkg/commands/commit.go
@@ -2,16 +2,14 @@ package commands
// Commit : A git commit
type Commit struct {
- Sha string
- Name string
- 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
- Tags []string
- ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2'
- Author string
- Date string
+ Sha string
+ Name string
+ Status string // one of "unpushed", "pushed", "merged", "rebasing" or "selected"
+ Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
+ Tags []string
+ ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2'
+ Author string
+ Date string
}
func (c *Commit) ShortSha() string {
diff --git a/pkg/commands/commit_list_builder.go b/pkg/commands/commit_list_builder.go
index 834d478e0..7f7a979b5 100644
--- a/pkg/commands/commit_list_builder.go
+++ b/pkg/commands/commit_list_builder.go
@@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
+ "os/exec"
"path/filepath"
"regexp"
"strings"
@@ -70,13 +71,12 @@ func (c *CommitListBuilder) extractCommitFromLine(line string) *Commit {
}
return &Commit{
- Sha: sha,
- Name: message,
- DisplayString: line,
- Tags: tags,
- ExtraInfo: extraInfo,
- Date: date,
- Author: author,
+ Sha: sha,
+ Name: message,
+ Tags: tags,
+ ExtraInfo: extraInfo,
+ Date: date,
+ Author: author,
}
}
@@ -100,15 +100,20 @@ func (c *CommitListBuilder) GetCommits(limit bool) ([]*Commit, error) {
}
unpushedCommits := c.getUnpushedCommits()
- log := c.getLog(limit)
+ cmd := c.getLogCmd(limit)
- // now we can split it up and turn it into commits
- for _, line := range utils.SplitLines(log) {
+ err = RunLineOutputCmd(cmd, func(line string) (bool, error) {
commit := c.extractCommitFromLine(line)
_, unpushed := unpushedCommits[commit.ShortSha()]
commit.Status = map[bool]string{true: "unpushed", false: "pushed"}[unpushed]
commits = append(commits, commit)
+
+ return false, nil
+ })
+ if err != nil {
+ return nil, err
}
+
if rebaseMode != "" {
currentCommit := commits[len(rebasingCommits)]
blue := color.New(color.FgYellow)
@@ -121,11 +126,6 @@ func (c *CommitListBuilder) GetCommits(limit bool) ([]*Commit, error) {
return nil, err
}
- commits, err = c.setCommitCherryPickStatuses(commits)
- if err != nil {
- return nil, err
- }
-
for _, commit := range commits {
for _, entry := range c.DiffEntries {
if entry.Sha == commit.Sha {
@@ -267,17 +267,6 @@ func (c *CommitListBuilder) setCommitMergedStatuses(commits []*Commit) ([]*Commi
return commits, nil
}
-func (c *CommitListBuilder) setCommitCherryPickStatuses(commits []*Commit) ([]*Commit, error) {
- for _, commit := range commits {
- for _, cherryPickedCommit := range c.CherryPickedCommits {
- if commit.Sha == cherryPickedCommit.Sha {
- commit.Copied = true
- }
- }
- }
- return commits, nil
-}
-
func (c *CommitListBuilder) getMergeBase() (string, error) {
currentBranch, _, err := c.GitCommand.CurrentBranchName()
if err != nil {
diff --git a/pkg/commands/os.go b/pkg/commands/os.go
index 7b96b99c4..517372662 100644
--- a/pkg/commands/os.go
+++ b/pkg/commands/os.go
@@ -1,6 +1,7 @@
package commands
import (
+ "bufio"
"fmt"
"io/ioutil"
"os"
@@ -425,3 +426,31 @@ func Kill(cmd *exec.Cmd) error {
}
return cmd.Process.Kill()
}
+
+func RunLineOutputCmd(cmd *exec.Cmd, onLine func(line string) (bool, error)) error {
+ stdoutPipe, err := cmd.StdoutPipe()
+ if err != nil {
+ return err
+ }
+
+ scanner := bufio.NewScanner(stdoutPipe)
+ scanner.Split(bufio.ScanLines)
+ if err := cmd.Start(); err != nil {
+ return err
+ }
+
+ for scanner.Scan() {
+ line := scanner.Text()
+ stop, err := onLine(line)
+ if err != nil {
+ return err
+ }
+ if stop {
+ cmd.Process.Kill()
+ break
+ }
+ }
+
+ cmd.Wait()
+ return nil
+}