Skip to content

Commit

Permalink
utils: ioutil, Pipe implementatio
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed May 2, 2021
1 parent c69d533 commit 67af9d7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
3 changes: 2 additions & 1 deletion plumbing/transport/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/internal/common"
"github.com/go-git/go-git/v5/utils/ioutil"
"golang.org/x/sys/execabs"
)

Expand Down Expand Up @@ -111,7 +112,7 @@ func (c *command) Start() error {
func (c *command) StderrPipe() (io.Reader, error) {
// Pipe returned by Command.StderrPipe has a race with Read + Command.Wait.
// We use an io.Pipe and close it after the command finishes.
r, w := io.Pipe()
r, w := ioutil.Pipe()
c.cmd.Stderr = w
c.stderrCloser = r
return r, nil
Expand Down
2 changes: 1 addition & 1 deletion plumbing/transport/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (s *upSession) UploadPack(ctx context.Context, req *packp.UploadPackRequest
return nil, err
}

pr, pw := io.Pipe()
pr, pw := ioutil.Pipe()
e := packfile.NewEncoder(pw, s.storer, false)
go func() {
// TODO: plumb through a pack window.
Expand Down
2 changes: 1 addition & 1 deletion remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ func pushHashes(
allDelete bool,
) (*packp.ReportStatus, error) {

rd, wr := io.Pipe()
rd, wr := ioutil.Pipe()

config, err := s.Config()
if err != nil {
Expand Down
12 changes: 11 additions & 1 deletion utils/ioutil/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"io"

"github.com/jbenet/go-context/io"
ctxio "github.com/jbenet/go-context/io"
)

type readPeeker interface {
Expand Down Expand Up @@ -168,3 +168,13 @@ func (r *writerOnError) Write(p []byte) (n int, err error) {

return
}

type PipeReader interface {
io.ReadCloser
CloseWithError(err error) error
}

type PipeWriter interface {
io.WriteCloser
CloseWithError(err error) error
}
9 changes: 9 additions & 0 deletions utils/ioutil/pipe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build !js

package ioutil

import "io"

func Pipe() (PipeReader, PipeWriter) {
return io.Pipe()
}
9 changes: 9 additions & 0 deletions utils/ioutil/pipe_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build js

package ioutil

import "github.com/acomagu/bufpipe"

func Pipe() (PipeReader, PipeWriter) {
return bufpipe.New(nil)
}

0 comments on commit 67af9d7

Please sign in to comment.