Skip to content

Commit db2e912

Browse files
unknwonaymanbagabas
authored andcommitted
minor fixup logic
1 parent 5154ec5 commit db2e912

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

command.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ func (c *Command) AddEnvs(envs ...string) *Command {
7171
}
7272

7373
// WithContext returns a new Command with the given context.
74-
func (c Command) WithContext(ctx context.Context) *Command {
74+
func (c *Command) WithContext(ctx context.Context) *Command {
7575
c.ctx = ctx
76-
return &c
76+
return c
7777
}
7878

7979
// WithTimeout returns a new Command with given timeout.
80-
func (c Command) WithTimeout(timeout time.Duration) *Command {
80+
func (c *Command) WithTimeout(timeout time.Duration) *Command {
8181
c.timeout = timeout
82-
return &c
82+
return c
8383
}
8484

8585
// SetTimeout sets the timeout for the command.

repo_stash.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import (
1212
type Stash struct {
1313
// Index is the index of the stash.
1414
Index int
15-
1615
// Message is the message of the stash.
1716
Message string
18-
1917
// Files is the list of files in the stash.
2018
Files []string
2119
}
@@ -36,44 +34,43 @@ func (r *Repository) StashList(opts ...StashListOptions) ([]*Stash, error) {
3634
opt = opts[0]
3735
}
3836

39-
stash := make([]*Stash, 0)
37+
stashes := make([]*Stash, 0)
4038
cmd := NewCommand("stash", "list", "--name-only").AddOptions(opt.CommandOptions)
4139
stdout, stderr := new(bytes.Buffer), new(bytes.Buffer)
4240
if err := cmd.RunInDirPipeline(stdout, stderr, r.path); err != nil {
4341
return nil, concatenateError(err, stderr.String())
4442
}
4543

46-
var entry *Stash
44+
var stash *Stash
4745
lines := strings.Split(stdout.String(), "\n")
4846
for i := 0; i < len(lines); i++ {
4947
line := strings.TrimSpace(lines[i])
5048
// Init entry
5149
if match := stashLineRegexp.FindStringSubmatch(line); len(match) == 3 {
52-
if entry != nil {
53-
stash = append(stash, entry)
50+
// Append the previous stash
51+
if stash != nil {
52+
stashes = append(stashes, stash)
5453
}
5554

5655
idx, err := strconv.Atoi(match[1])
5756
if err != nil {
5857
idx = -1
5958
}
60-
entry = &Stash{
59+
stash = &Stash{
6160
Index: idx,
6261
Message: match[2],
6362
Files: make([]string, 0),
6463
}
65-
} else if entry != nil && line != "" {
66-
entry.Files = append(entry.Files, line)
67-
} else {
68-
continue
64+
} else if stash != nil && line != "" {
65+
stash.Files = append(stash.Files, line)
6966
}
7067
}
7168

72-
if entry != nil {
73-
stash = append(stash, entry)
69+
// Append the last stash
70+
if stash != nil {
71+
stashes = append(stashes, stash)
7472
}
75-
76-
return stash, nil
73+
return stashes, nil
7774
}
7875

7976
// StashDiff returns a parsed diff object for the given stash index.
@@ -90,7 +87,7 @@ func (r *Repository) StashDiff(index int, maxFiles, maxFileLines, maxLineChars i
9087
go StreamParseDiff(stdout, done, maxFiles, maxFileLines, maxLineChars)
9188

9289
stderr := new(bytes.Buffer)
93-
err := cmd.RunInDirPipelineWithTimeout(opt.Timeout, w, stderr, r.path)
90+
err := cmd.RunInDirPipeline(w, stderr, r.path)
9491
_ = w.Close() // Close writer to exit parsing goroutine
9592
if err != nil {
9693
return nil, concatenateError(err, stderr.String())

0 commit comments

Comments
 (0)