aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/server/server.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-25 16:14:32 +0200
committerGitHub <noreply@github.com>2017-07-25 16:14:32 +0200
commitfbf2a4ab4588c78e3d9d0265dba774ae6b388b5f (patch)
tree883e9172499234f9f258fb41190fcd0f9134c0a4 /plumbing/transport/server/server.go
parent25a0420bc0544f826e5517365e986d83bbb926c8 (diff)
parentdb5fa522f36207684ec0d67b98cac6313f0259b6 (diff)
downloadgo-git-fbf2a4ab4588c78e3d9d0265dba774ae6b388b5f.tar.gz
Merge pull request #507 from mcuadros/ctx
transport: context package support allowing cancellation of any network operation
Diffstat (limited to 'plumbing/transport/server/server.go')
-rw-r--r--plumbing/transport/server/server.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/plumbing/transport/server/server.go b/plumbing/transport/server/server.go
index 7c78afe..be36de5 100644
--- a/plumbing/transport/server/server.go
+++ b/plumbing/transport/server/server.go
@@ -3,6 +3,7 @@
package server
import (
+ "context"
"errors"
"fmt"
"io"
@@ -14,6 +15,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/revlist"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
+ "gopkg.in/src-d/go-git.v4/utils/ioutil"
)
var DefaultServer = NewServer(DefaultLoader)
@@ -129,7 +131,7 @@ func (s *upSession) AdvertisedReferences() (*packp.AdvRefs, error) {
return ar, nil
}
-func (s *upSession) UploadPack(req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) {
+func (s *upSession) UploadPack(ctx context.Context, req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) {
if req.IsEmpty() {
return nil, transport.ErrEmptyUploadPackRequest
}
@@ -167,7 +169,9 @@ func (s *upSession) UploadPack(req *packp.UploadPackRequest) (*packp.UploadPackR
pw.CloseWithError(err)
}()
- return packp.NewUploadPackResponseWithPackfile(req, pr), nil
+ return packp.NewUploadPackResponseWithPackfile(req,
+ ioutil.NewContextReadCloser(ctx, pr),
+ ), nil
}
func (s *upSession) objectsToUpload(req *packp.UploadPackRequest) ([]plumbing.Hash, error) {
@@ -222,7 +226,7 @@ var (
ErrUpdateReference = errors.New("failed to update ref")
)
-func (s *rpSession) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.ReportStatus, error) {
+func (s *rpSession) ReceivePack(ctx context.Context, req *packp.ReferenceUpdateRequest) (*packp.ReportStatus, error) {
if s.caps == nil {
s.caps = capability.NewList()
if err := s.setSupportedCapabilities(s.caps); err != nil {
@@ -238,7 +242,8 @@ func (s *rpSession) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.Repor
//TODO: Implement 'atomic' update of references.
- if err := s.writePackfile(req.Packfile); err != nil {
+ r := ioutil.NewContextReadCloser(ctx, req.Packfile)
+ if err := s.writePackfile(r); err != nil {
s.unpackErr = err
s.firstErr = err
return s.reportStatus(), err