Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions gitdiff/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"io"
"io/ioutil"
"os/exec"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -232,9 +231,7 @@ type applyTest struct {
func (at applyTest) run(t *testing.T, apply func(io.Writer, *Applier, *File) error) {
src, patch, out := at.Files.Load(t)

cmd := exec.Command("echo", "hello")

fileChan, err := Parse(cmd, io.NopCloser(bytes.NewReader(patch)))
fileChan, err := Parse(io.NopCloser(bytes.NewReader(patch)))
if err != nil {
t.Fatalf("failed to parse patch file: %v", err)
}
Expand Down
9 changes: 3 additions & 6 deletions gitdiff/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bufio"
"fmt"
"io"
"os/exec"
"strings"
)

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

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

go func(cmd *exec.Cmd, out chan *File, r io.ReadCloser) {
go func(out chan *File, r io.Reader) {
defer close(out)
defer cmd.Wait()
defer r.Close()

ph := &PatchHeader{}
for {
Expand Down Expand Up @@ -68,7 +65,7 @@ func Parse(cmd *exec.Cmd, r io.ReadCloser) (<-chan *File, error) {
file.PatchHeader = ph
out <- file
}
}(cmd, out, r)
}(out, r)

return out, nil
}
Expand Down
7 changes: 2 additions & 5 deletions gitdiff/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io"
"os"
"os/exec"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -503,9 +502,7 @@ Date: Tue Apr 2 22:55:40 2019 -0700
t.Fatalf("unexpected error opening input file: %v", err)
}

cmd := exec.Command("echo", "hello")

fileChan, err := Parse(cmd, f)
fileChan, err := Parse(f)
if test.Err {
if err == nil || err == io.EOF {
t.Fatalf("expected error parsing patch, but got %v", err)
Expand Down Expand Up @@ -580,7 +577,7 @@ index ebe9fa54..fe103e1d 100644
}
for i := 0; i < b.N; i++ {
reader := io.NopCloser(strings.NewReader(inputDiff))
ch, err := Parse(&exec.Cmd{}, reader)
ch, err := Parse(reader)
if err != nil {
panic(err)
}
Expand Down