diff options
author | Andrew Newdigate <andrew@troupe.co> | 2017-04-25 18:25:21 +0300 |
---|---|---|
committer | Andrew Newdigate <andrew@troupe.co> | 2017-04-25 18:25:21 +0300 |
commit | 1e7a5c6dd3d54974b000933da9dc966e2e213cea (patch) | |
tree | 62656745a5d3c652e759033576a3eb42baf33c72 | |
parent | c01cccfee61148042ba5dbb37e4bb2de181b402b (diff) |
Handle go1.7 CommandContext and also go1.6
-rw-r--r-- | internal/helper/command.go | 2 | ||||
-rw-r--r-- | internal/helper/command_wrapper_go1.6.go | 14 | ||||
-rw-r--r-- | internal/helper/command_wrapper_go17.go | 14 | ||||
-rw-r--r-- | internal/service/commit/isancestor.go | 7 | ||||
-rw-r--r-- | internal/service/smarthttp/receive_pack.go | 3 | ||||
-rw-r--r-- | internal/service/smarthttp/upload_pack.go | 3 |
6 files changed, 34 insertions, 9 deletions
diff --git a/internal/helper/command.go b/internal/helper/command.go index 80745a240..5b9288757 100644 --- a/internal/helper/command.go +++ b/internal/helper/command.go @@ -26,7 +26,7 @@ func (c *Command) Kill() { func GitCommandReader(ctx context.Context, args ...string) (*Command, error) { // TODO: when we switch to Go 1.7, switch to using // exec.CommandContext - return NewCommand(exec.Command("git", args...), nil, nil) + return NewCommand(CommandWrapper(ctx, "git", args...), nil, nil) } // NewCommand creates a Command from an exec.Cmd diff --git a/internal/helper/command_wrapper_go1.6.go b/internal/helper/command_wrapper_go1.6.go new file mode 100644 index 000000000..71cef0ac8 --- /dev/null +++ b/internal/helper/command_wrapper_go1.6.go @@ -0,0 +1,14 @@ +// +build !go1.7 + +package helper + +import ( + "os/exec" + + "golang.org/x/net/context" +) + +// CommandWrapper handles context until we compile using Go 1.7 +func CommandWrapper(ctx context.Context, name string, arg ...string) *exec.Cmd { + return exec.Command(name, arg...) +} diff --git a/internal/helper/command_wrapper_go17.go b/internal/helper/command_wrapper_go17.go new file mode 100644 index 000000000..c381331b5 --- /dev/null +++ b/internal/helper/command_wrapper_go17.go @@ -0,0 +1,14 @@ +//+build go1.7 + +package helper + +import ( + "os/exec" + + "golang.org/x/net/context" +) + +// CommandWrapper handles context until we compile using Go 1.7 +func CommandWrapper(ctx context.Context, name string, arg ...string) *exec.Cmd { + return exec.CommandContext(ctx, name, arg...) +} diff --git a/internal/service/commit/isancestor.go b/internal/service/commit/isancestor.go index 3afa86fa3..9cccd448c 100644 --- a/internal/service/commit/isancestor.go +++ b/internal/service/commit/isancestor.go @@ -3,7 +3,6 @@ package commit import ( "io/ioutil" "log" - "os/exec" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -30,13 +29,13 @@ func (s *server) CommitIsAncestor(ctx context.Context, in *pb.CommitIsAncestorRe return nil, grpc.Errorf(codes.InvalidArgument, message) } - ret, err := commitIsAncestorName(repoPath, in.AncestorId, in.ChildId) + ret, err := commitIsAncestorName(ctx, repoPath, in.AncestorId, in.ChildId) return &pb.CommitIsAncestorResponse{Value: ret}, err } // Assumes that `path`, `ancestorID` and `childID` are populated :trollface: -func commitIsAncestorName(path, ancestorID, childID string) (bool, error) { - osCommand := exec.Command("git", "--git-dir", path, "merge-base", "--is-ancestor", ancestorID, childID) +func commitIsAncestorName(ctx context.Context, path, ancestorID, childID string) (bool, error) { + osCommand := helper.CommandWrapper(ctx, "git", "--git-dir", path, "merge-base", "--is-ancestor", ancestorID, childID) cmd, err := helper.NewCommand(osCommand, nil, ioutil.Discard) if err != nil { return false, grpc.Errorf(codes.Internal, err.Error()) diff --git a/internal/service/smarthttp/receive_pack.go b/internal/service/smarthttp/receive_pack.go index bde99adf6..195e73219 100644 --- a/internal/service/smarthttp/receive_pack.go +++ b/internal/service/smarthttp/receive_pack.go @@ -3,7 +3,6 @@ package smarthttp import ( "fmt" "log" - "os/exec" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -40,7 +39,7 @@ func (s *server) PostReceivePack(stream pb.SmartHTTP_PostReceivePackServer) erro log.Printf("PostReceivePack: RepoPath=%q GlID=%q", repoPath, req.GlId) - osCommand := exec.Command("git", "receive-pack", "--stateless-rpc", repoPath) + osCommand := helper.CommandWrapper(stream.Context(), "git", "receive-pack", "--stateless-rpc", repoPath) cmd, err := helper.NewCommand(osCommand, stdin, stdout, glIDEnv) if err != nil { diff --git a/internal/service/smarthttp/upload_pack.go b/internal/service/smarthttp/upload_pack.go index 9528155ee..dc8b82df1 100644 --- a/internal/service/smarthttp/upload_pack.go +++ b/internal/service/smarthttp/upload_pack.go @@ -2,7 +2,6 @@ package smarthttp import ( "log" - "os/exec" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -38,7 +37,7 @@ func (s *server) PostUploadPack(stream pb.SmartHTTP_PostUploadPackServer) error log.Printf("PostUploadPack: RepoPath=%q", repoPath) - osCommand := exec.Command("git", "upload-pack", "--stateless-rpc", repoPath) + osCommand := helper.CommandWrapper(stream.Context(), "git", "upload-pack", "--stateless-rpc", repoPath) cmd, err := helper.NewCommand(osCommand, stdin, stdout) if err != nil { |