Skip to content

Commit 0484f32

Browse files
feat: parser should not know about cmd anything
1 parent 9601489 commit 0484f32

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

gitdiff/apply_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"io"
77
"io/ioutil"
8-
"os/exec"
98
"path/filepath"
109
"testing"
1110
)
@@ -232,9 +231,7 @@ type applyTest struct {
232231
func (at applyTest) run(t *testing.T, apply func(io.Writer, *Applier, *File) error) {
233232
src, patch, out := at.Files.Load(t)
234233

235-
cmd := exec.Command("echo", "hello")
236-
237-
fileChan, err := Parse(cmd, io.NopCloser(bytes.NewReader(patch)))
234+
fileChan, err := Parse(io.NopCloser(bytes.NewReader(patch)))
238235
if err != nil {
239236
t.Fatalf("failed to parse patch file: %v", err)
240237
}

gitdiff/parser.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"bufio"
88
"fmt"
99
"io"
10-
"os/exec"
1110
"strings"
1211
)
1312

@@ -16,7 +15,7 @@ const commitPrefix = "commit"
1615
// Parse parses a patch with changes to one or more files. Any content before
1716
// the first file is returned as the second value. If an error occurs while
1817
// parsing, it returns all files parsed before the error.
19-
func Parse(cmd *exec.Cmd, r io.ReadCloser) (<-chan *File, error) {
18+
func Parse(r io.Reader) (<-chan *File, error) {
2019
p := newParser(r)
2120
out := make(chan *File)
2221

@@ -28,10 +27,8 @@ func Parse(cmd *exec.Cmd, r io.ReadCloser) (<-chan *File, error) {
2827
return out, err
2928
}
3029

31-
go func(cmd *exec.Cmd, out chan *File, r io.ReadCloser) {
30+
go func(out chan *File, r io.Reader) {
3231
defer close(out)
33-
defer cmd.Wait()
34-
defer r.Close()
3532

3633
ph := &PatchHeader{}
3734
for {
@@ -68,7 +65,7 @@ func Parse(cmd *exec.Cmd, r io.ReadCloser) (<-chan *File, error) {
6865
file.PatchHeader = ph
6966
out <- file
7067
}
71-
}(cmd, out, r)
68+
}(out, r)
7269

7370
return out, nil
7471
}

gitdiff/parser_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io"
99
"os"
10-
"os/exec"
1110
"reflect"
1211
"strings"
1312
"testing"
@@ -503,9 +502,7 @@ Date: Tue Apr 2 22:55:40 2019 -0700
503502
t.Fatalf("unexpected error opening input file: %v", err)
504503
}
505504

506-
cmd := exec.Command("echo", "hello")
507-
508-
fileChan, err := Parse(cmd, f)
505+
fileChan, err := Parse(f)
509506
if test.Err {
510507
if err == nil || err == io.EOF {
511508
t.Fatalf("expected error parsing patch, but got %v", err)
@@ -580,7 +577,7 @@ index ebe9fa54..fe103e1d 100644
580577
}
581578
for i := 0; i < b.N; i++ {
582579
reader := io.NopCloser(strings.NewReader(inputDiff))
583-
ch, err := Parse(&exec.Cmd{}, reader)
580+
ch, err := Parse(reader)
584581
if err != nil {
585582
panic(err)
586583
}

0 commit comments

Comments
 (0)