Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
2b93db7a
Commit
2b93db7a
authored
Jul 03, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use http.Request contexts for Gitaly calls
parent
fadf660e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
17 additions
and
29 deletions
+17
-29
internal/git/blob.go
internal/git/blob.go
+1
-1
internal/git/info-refs.go
internal/git/info-refs.go
+3
-6
internal/git/receive-pack.go
internal/git/receive-pack.go
+4
-3
internal/git/upload-pack.go
internal/git/upload-pack.go
+4
-3
internal/gitaly/commit.go
internal/gitaly/commit.go
+2
-6
internal/gitaly/smarthttp.go
internal/gitaly/smarthttp.go
+3
-10
No files found.
internal/git/blob.go
View file @
2b93db7a
...
@@ -44,7 +44,7 @@ func handleSendBlobWithGitaly(w http.ResponseWriter, r *http.Request, params *bl
...
@@ -44,7 +44,7 @@ func handleSendBlobWithGitaly(w http.ResponseWriter, r *http.Request, params *bl
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"commit.GetBlob: %v"
,
err
))
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"commit.GetBlob: %v"
,
err
))
}
}
if
err
:=
commitClient
.
SendBlob
(
w
,
&
params
.
TreeEntryRequest
);
err
!=
nil
{
if
err
:=
commitClient
.
SendBlob
(
r
.
Context
(),
w
,
&
params
.
TreeEntryRequest
);
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"commit.GetBlob: %v"
,
err
))
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"commit.GetBlob: %v"
,
err
))
}
}
}
}
...
...
internal/git/info-refs.go
View file @
2b93db7a
package
git
package
git
import
(
import
(
"context"
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
...
@@ -8,8 +9,6 @@ import (
...
@@ -8,8 +9,6 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"golang.org/x/net/context"
)
)
func
GetInfoRefsHandler
(
a
*
api
.
API
)
http
.
Handler
{
func
GetInfoRefsHandler
(
a
*
api
.
API
)
http
.
Handler
{
...
@@ -35,7 +34,7 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
...
@@ -35,7 +34,7 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
if
a
.
GitalyServer
.
Address
==
""
{
if
a
.
GitalyServer
.
Address
==
""
{
err
=
handleGetInfoRefsLocally
(
w
,
a
,
rpc
)
err
=
handleGetInfoRefsLocally
(
w
,
a
,
rpc
)
}
else
{
}
else
{
err
=
handleGetInfoRefsWithGitaly
(
w
,
a
,
rpc
)
err
=
handleGetInfoRefsWithGitaly
(
r
.
Context
(),
w
,
a
,
rpc
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -64,14 +63,12 @@ func handleGetInfoRefsLocally(w http.ResponseWriter, a *api.Response, rpc string
...
@@ -64,14 +63,12 @@ func handleGetInfoRefsLocally(w http.ResponseWriter, a *api.Response, rpc string
return
nil
return
nil
}
}
func
handleGetInfoRefsWithGitaly
(
w
http
.
ResponseWriter
,
a
*
api
.
Response
,
rpc
string
)
error
{
func
handleGetInfoRefsWithGitaly
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
a
*
api
.
Response
,
rpc
string
)
error
{
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"GetInfoRefsHandler: %v"
,
err
)
return
fmt
.
Errorf
(
"GetInfoRefsHandler: %v"
,
err
)
}
}
ctx
,
cancelFunc
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancelFunc
()
infoRefsResponseReader
,
err
:=
smarthttp
.
InfoRefsResponseReader
(
ctx
,
&
a
.
Repository
,
rpc
)
infoRefsResponseReader
,
err
:=
smarthttp
.
InfoRefsResponseReader
(
ctx
,
&
a
.
Repository
,
rpc
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"GetInfoRefsHandler: %v"
,
err
)
return
fmt
.
Errorf
(
"GetInfoRefsHandler: %v"
,
err
)
...
...
internal/git/receive-pack.go
View file @
2b93db7a
package
git
package
git
import
(
import
(
"context"
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
...
@@ -23,7 +24,7 @@ func handleReceivePack(w *GitHttpResponseWriter, r *http.Request, a *api.Respons
...
@@ -23,7 +24,7 @@ func handleReceivePack(w *GitHttpResponseWriter, r *http.Request, a *api.Respons
if
a
.
GitalyServer
.
Address
==
""
{
if
a
.
GitalyServer
.
Address
==
""
{
err
=
handleReceivePackLocally
(
a
,
r
,
cr
,
cw
,
action
)
err
=
handleReceivePackLocally
(
a
,
r
,
cr
,
cw
,
action
)
}
else
{
}
else
{
err
=
handleReceivePackWithGitaly
(
a
,
cr
,
cw
)
err
=
handleReceivePackWithGitaly
(
r
.
Context
(),
a
,
cr
,
cw
)
}
}
return
err
return
err
...
@@ -45,13 +46,13 @@ func handleReceivePackLocally(a *api.Response, r *http.Request, stdin io.Reader,
...
@@ -45,13 +46,13 @@ func handleReceivePackLocally(a *api.Response, r *http.Request, stdin io.Reader,
return
nil
return
nil
}
}
func
handleReceivePackWithGitaly
(
a
*
api
.
Response
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
func
handleReceivePackWithGitaly
(
ctx
context
.
Context
,
a
*
api
.
Response
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"smarthttp.ReceivePack: %v"
,
err
)
return
fmt
.
Errorf
(
"smarthttp.ReceivePack: %v"
,
err
)
}
}
if
err
:=
smarthttp
.
ReceivePack
(
&
a
.
Repository
,
a
.
GL_ID
,
a
.
GL_REPOSITORY
,
clientRequest
,
clientResponse
);
err
!=
nil
{
if
err
:=
smarthttp
.
ReceivePack
(
ctx
,
&
a
.
Repository
,
a
.
GL_ID
,
a
.
GL_REPOSITORY
,
clientRequest
,
clientResponse
);
err
!=
nil
{
return
fmt
.
Errorf
(
"smarthttp.ReceivePack: %v"
,
err
)
return
fmt
.
Errorf
(
"smarthttp.ReceivePack: %v"
,
err
)
}
}
...
...
internal/git/upload-pack.go
View file @
2b93db7a
package
git
package
git
import
(
import
(
"context"
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
...
@@ -30,7 +31,7 @@ func handleUploadPack(w *GitHttpResponseWriter, r *http.Request, a *api.Response
...
@@ -30,7 +31,7 @@ func handleUploadPack(w *GitHttpResponseWriter, r *http.Request, a *api.Response
if
a
.
GitalyServer
.
Address
==
""
{
if
a
.
GitalyServer
.
Address
==
""
{
err
=
handleUploadPackLocally
(
a
,
r
,
buffer
,
w
,
action
)
err
=
handleUploadPackLocally
(
a
,
r
,
buffer
,
w
,
action
)
}
else
{
}
else
{
err
=
handleUploadPackWithGitaly
(
a
,
buffer
,
w
)
err
=
handleUploadPackWithGitaly
(
r
.
Context
(),
a
,
buffer
,
w
)
}
}
return
err
return
err
...
@@ -57,13 +58,13 @@ func handleUploadPackLocally(a *api.Response, r *http.Request, stdin *os.File, s
...
@@ -57,13 +58,13 @@ func handleUploadPackLocally(a *api.Response, r *http.Request, stdin *os.File, s
return
nil
return
nil
}
}
func
handleUploadPackWithGitaly
(
a
*
api
.
Response
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
func
handleUploadPackWithGitaly
(
ctx
context
.
Context
,
a
*
api
.
Response
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"smarthttp.UploadPack: %v"
,
err
)
return
fmt
.
Errorf
(
"smarthttp.UploadPack: %v"
,
err
)
}
}
if
err
:=
smarthttp
.
UploadPack
(
&
a
.
Repository
,
clientRequest
,
clientResponse
);
err
!=
nil
{
if
err
:=
smarthttp
.
UploadPack
(
ctx
,
&
a
.
Repository
,
clientRequest
,
clientResponse
);
err
!=
nil
{
return
fmt
.
Errorf
(
"smarthttp.UploadPack: %v"
,
err
)
return
fmt
.
Errorf
(
"smarthttp.UploadPack: %v"
,
err
)
}
}
...
...
internal/gitaly/commit.go
View file @
2b93db7a
package
gitaly
package
gitaly
import
(
import
(
"context"
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
...
@@ -8,18 +9,13 @@ import (
...
@@ -8,18 +9,13 @@ import (
pb
"gitlab.com/gitlab-org/gitaly-proto/go"
pb
"gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitaly/streamio"
"gitlab.com/gitlab-org/gitaly/streamio"
"golang.org/x/net/context"
)
)
type
CommitClient
struct
{
type
CommitClient
struct
{
pb
.
CommitClient
pb
.
CommitClient
}
}
func
(
client
*
CommitClient
)
SendBlob
(
w
http
.
ResponseWriter
,
request
*
pb
.
TreeEntryRequest
)
error
{
func
(
client
*
CommitClient
)
SendBlob
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
request
*
pb
.
TreeEntryRequest
)
error
{
ctx
,
cancelFunc
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancelFunc
()
c
,
err
:=
client
.
TreeEntry
(
ctx
,
request
)
c
,
err
:=
client
.
TreeEntry
(
ctx
,
request
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"rpc failed: %v"
,
err
)
return
fmt
.
Errorf
(
"rpc failed: %v"
,
err
)
...
...
internal/gitaly/smarthttp.go
View file @
2b93db7a
package
gitaly
package
gitaly
import
(
import
(
"context"
"fmt"
"fmt"
"io"
"io"
pb
"gitlab.com/gitlab-org/gitaly-proto/go"
pb
"gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitaly/streamio"
"gitlab.com/gitlab-org/gitaly/streamio"
"golang.org/x/net/context"
)
)
type
SmartHTTPClient
struct
{
type
SmartHTTPClient
struct
{
...
@@ -40,10 +39,7 @@ func infoRefsReader(stream infoRefsClient) io.Reader {
...
@@ -40,10 +39,7 @@ func infoRefsReader(stream infoRefsClient) io.Reader {
})
})
}
}
func
(
client
*
SmartHTTPClient
)
ReceivePack
(
repo
*
pb
.
Repository
,
glId
string
,
glRepository
string
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
func
(
client
*
SmartHTTPClient
)
ReceivePack
(
ctx
context
.
Context
,
repo
*
pb
.
Repository
,
glId
string
,
glRepository
string
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
ctx
,
cancelFunc
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancelFunc
()
stream
,
err
:=
client
.
PostReceivePack
(
ctx
)
stream
,
err
:=
client
.
PostReceivePack
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -89,10 +85,7 @@ func (client *SmartHTTPClient) ReceivePack(repo *pb.Repository, glId string, glR
...
@@ -89,10 +85,7 @@ func (client *SmartHTTPClient) ReceivePack(repo *pb.Repository, glId string, glR
return
nil
return
nil
}
}
func
(
client
*
SmartHTTPClient
)
UploadPack
(
repo
*
pb
.
Repository
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
func
(
client
*
SmartHTTPClient
)
UploadPack
(
ctx
context
.
Context
,
repo
*
pb
.
Repository
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
ctx
,
cancelFunc
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancelFunc
()
stream
,
err
:=
client
.
PostUploadPack
(
ctx
)
stream
,
err
:=
client
.
PostUploadPack
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment