aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-06-13 14:23:15 +0200
committerSantiago M. Mola <santi@mola.io>2017-06-13 15:39:49 +0200
commitcbbd2a9ad8ee990c79bd847b0df2823e2449ea4e (patch)
tree25905da2442b2363d0d45bba07485543e5665deb /plumbing
parent4b2d9b42bf18556bc51434e7221927c681bce746 (diff)
downloadgo-git-cbbd2a9ad8ee990c79bd847b0df2823e2449ea4e.tar.gz
transport/internal: remove Wait function, use Close directly
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/transport/file/client.go17
-rw-r--r--plumbing/transport/git/common.go5
-rw-r--r--plumbing/transport/internal/common/common.go26
-rw-r--r--plumbing/transport/test/receive_pack.go3
4 files changed, 19 insertions, 32 deletions
diff --git a/plumbing/transport/file/client.go b/plumbing/transport/file/client.go
index d2a57d0..a199b01 100644
--- a/plumbing/transport/file/client.go
+++ b/plumbing/transport/file/client.go
@@ -3,6 +3,7 @@ package file
import (
"io"
+ "os"
"os/exec"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
@@ -71,10 +72,16 @@ func (c *command) Close() error {
return nil
}
- return c.cmd.Process.Kill()
-}
-
-func (c *command) Wait() error {
defer func() { c.closed = true }()
- return c.cmd.Wait()
+ err := c.cmd.Wait()
+ if _, ok := err.(*os.PathError); ok {
+ return nil
+ }
+
+ // When a repository does not exist, the command exits with code 128.
+ if _, ok := err.(*exec.ExitError); ok {
+ return nil
+ }
+
+ return err
}
diff --git a/plumbing/transport/git/common.go b/plumbing/transport/git/common.go
index 6776b69..fcd02f8 100644
--- a/plumbing/transport/git/common.go
+++ b/plumbing/transport/git/common.go
@@ -98,11 +98,6 @@ func endpointToCommand(cmd string, ep transport.Endpoint) string {
return fmt.Sprintf("%s %s%chost=%s%c", cmd, ep.Path(), 0, host, 0)
}
-// Wait no-op function, required by the interface
-func (c *command) Wait() error {
- return nil
-}
-
// Close closes the TCP connection and connection.
func (c *command) Close() error {
if !c.connected {
diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go
index d947d28..c1e1518 100644
--- a/plumbing/transport/internal/common/common.go
+++ b/plumbing/transport/internal/common/common.go
@@ -59,14 +59,8 @@ type Command interface {
// Start starts the specified command. It does not wait for it to
// complete.
Start() error
- // Wait waits for the command to exit. It must have been started by
- // Start. The returned error is nil if the command runs, has no
- // problems copying stdin, stdout, and stderr, and exits with a zero
- // exit status.
- Wait() error
// Close closes the command and releases any resources used by it. It
- // can be called to forcibly finish the command without calling to Wait
- // or to release resources after calling Wait.
+ // will block until the command exits.
Close() error
}
@@ -178,6 +172,7 @@ func (s *session) handleAdvRefDecodeError(err error) error {
// If repository is not found, we get empty stdout and server writes an
// error to stderr.
if err == packp.ErrEmptyInput {
+ s.finished = true
if err := s.checkNotFoundError(); err != nil {
return err
}
@@ -246,9 +241,7 @@ func (s *session) UploadPack(req *packp.UploadPackRequest) (*packp.UploadPackRes
return nil, err
}
- wc := &waitCloser{s.Command}
- rc := ioutil.NewReadCloser(r, wc)
-
+ rc := ioutil.NewReadCloser(r, s.Command)
return DecodeUploadPackResponse(rc, req)
}
@@ -270,7 +263,7 @@ func (s *session) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.ReportS
if !req.Capabilities.Supports(capability.ReportStatus) {
// If we have neither report-status or sideband, we can only
// check return value error.
- return nil, s.Command.Wait()
+ return nil, s.Command.Close()
}
report := packp.NewReportStatus()
@@ -282,7 +275,7 @@ func (s *session) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.ReportS
return report, err
}
- return report, s.Command.Wait()
+ return report, s.Command.Close()
}
func (s *session) finish() error {
@@ -417,12 +410,3 @@ func DecodeUploadPackResponse(r io.ReadCloser, req *packp.UploadPackRequest) (
return res, nil
}
-
-type waitCloser struct {
- Command Command
-}
-
-// Close waits until the command exits and returns error, if any.
-func (c *waitCloser) Close() error {
- return c.Command.Wait()
-}
diff --git a/plumbing/transport/test/receive_pack.go b/plumbing/transport/test/receive_pack.go
index 066e684..bb1c58a 100644
--- a/plumbing/transport/test/receive_pack.go
+++ b/plumbing/transport/test/receive_pack.go
@@ -39,10 +39,10 @@ func (s *ReceivePackSuite) TestAdvertisedReferencesEmpty(c *C) {
func (s *ReceivePackSuite) TestAdvertisedReferencesNotExists(c *C) {
r, err := s.Client.NewReceivePackSession(s.NonExistentEndpoint, s.EmptyAuth)
c.Assert(err, IsNil)
- defer func() { c.Assert(r.Close(), IsNil) }()
ar, err := r.AdvertisedReferences()
c.Assert(err, Equals, transport.ErrRepositoryNotFound)
c.Assert(ar, IsNil)
+ c.Assert(r.Close(), IsNil)
r, err = s.Client.NewReceivePackSession(s.NonExistentEndpoint, s.EmptyAuth)
c.Assert(err, IsNil)
@@ -54,6 +54,7 @@ func (s *ReceivePackSuite) TestAdvertisedReferencesNotExists(c *C) {
writer, err := r.ReceivePack(req)
c.Assert(err, Equals, transport.ErrRepositoryNotFound)
c.Assert(writer, IsNil)
+ c.Assert(r.Close(), IsNil)
}
func (s *ReceivePackSuite) TestCallAdvertisedReferenceTwice(c *C) {