Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
e4807eec
未验证
提交
e4807eec
编辑于
6 years ago
作者:
Nick Thomas
浏览文件
操作
下载
补丁
差异文件
Remove local git receive-pack implementation
上级
dd755e07
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
3
隐藏空白变更内容
行内
左右并排
显示
3 个更改的文件
internal/git/git-http.go
+0
-22
0 个添加, 22 个删除
internal/git/git-http.go
internal/git/git-http_test.go
+0
-115
0 个添加, 115 个删除
internal/git/git-http_test.go
internal/git/receive-pack.go
+2
-31
2 个添加, 31 个删除
internal/git/receive-pack.go
有
2 个添加
和
168 个删除
internal/git/git-http.go
+
0
−
22
浏览文件 @
e4807eec
...
@@ -8,9 +8,7 @@ import (
...
@@ -8,9 +8,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
"os/exec"
"path/filepath"
"path/filepath"
"strings"
"sync"
"sync"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
...
@@ -67,22 +65,6 @@ func repoPreAuthorizeHandler(myAPI *api.API, handleFunc api.HandleFunc) http.Han
...
@@ -67,22 +65,6 @@ func repoPreAuthorizeHandler(myAPI *api.API, handleFunc api.HandleFunc) http.Han
},
""
)
},
""
)
}
}
func
startGitCommand
(
a
*
api
.
Response
,
stdin
io
.
Reader
,
stdout
io
.
Writer
,
action
string
,
options
...
string
)
(
cmd
*
exec
.
Cmd
,
err
error
)
{
// Prepare our Git subprocess
args
:=
[]
string
{
subCommand
(
action
),
"--stateless-rpc"
}
args
=
append
(
args
,
options
...
)
args
=
append
(
args
,
a
.
RepoPath
)
cmd
=
gitCommandApi
(
a
,
"git"
,
args
...
)
cmd
.
Stdin
=
stdin
cmd
.
Stdout
=
stdout
if
err
=
cmd
.
Start
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"start %v: %v"
,
cmd
.
Args
,
err
)
}
return
cmd
,
nil
}
func
writePostRPCHeader
(
w
http
.
ResponseWriter
,
action
string
)
{
func
writePostRPCHeader
(
w
http
.
ResponseWriter
,
action
string
)
{
w
.
Header
()
.
Set
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-result"
,
action
))
w
.
Header
()
.
Set
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-result"
,
action
))
w
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache"
)
w
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache"
)
...
@@ -95,10 +77,6 @@ func getService(r *http.Request) string {
...
@@ -95,10 +77,6 @@ func getService(r *http.Request) string {
return
filepath
.
Base
(
r
.
URL
.
Path
)
return
filepath
.
Base
(
r
.
URL
.
Path
)
}
}
func
subCommand
(
rpc
string
)
string
{
return
strings
.
TrimPrefix
(
rpc
,
"git-"
)
}
type
countReadCloser
struct
{
type
countReadCloser
struct
{
n
int64
n
int64
io
.
ReadCloser
io
.
ReadCloser
...
...
此差异已折叠。
点击以展开。
internal/git/git-http_test.go
已删除
100644 → 0
+
0
−
115
浏览文件 @
dd755e07
package
git
import
(
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"testing"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
)
const
(
expectedBytes
=
102400
GL_ID
=
"test-user"
)
// From https://npf.io/2015/06/testing-exec-command/
func
fakeExecCommand
(
command
string
,
args
...
string
)
*
exec
.
Cmd
{
cs
:=
[]
string
{
"-test.run=TestGitCommandProcess"
,
"--"
,
command
}
cs
=
append
(
cs
,
args
...
)
cmd
:=
exec
.
Command
(
os
.
Args
[
0
],
cs
...
)
return
cmd
}
func
createTestPayload
()
[]
byte
{
return
bytes
.
Repeat
([]
byte
{
'0'
},
expectedBytes
)
}
func
TestHandleReceivePack
(
t
*
testing
.
T
)
{
testHandlePostRpc
(
t
,
"git-receive-pack"
,
handleReceivePack
)
}
func
testHandlePostRpc
(
t
*
testing
.
T
,
action
string
,
handler
func
(
*
HttpResponseWriter
,
*
http
.
Request
,
*
api
.
Response
)
error
)
{
execCommand
=
fakeExecCommand
defer
func
()
{
execCommand
=
exec
.
Command
}()
testInput
:=
createTestPayload
()
body
:=
bytes
.
NewReader
([]
byte
(
testInput
))
url
:=
fmt
.
Sprintf
(
"/gitlab/gitlab-ce.git/?service=%s"
,
action
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
body
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
resp
:=
&
api
.
Response
{
GL_ID
:
GL_ID
}
rr
:=
httptest
.
NewRecorder
()
handler
(
NewHttpResponseWriter
(
rr
),
req
,
resp
)
// Check HTTP status code
if
status
:=
rr
.
Code
;
status
!=
http
.
StatusOK
{
t
.
Errorf
(
"handler returned wrong status code: expected: %v, got %v"
,
http
.
StatusOK
,
status
)
}
ct
:=
fmt
.
Sprintf
(
"application/x-%s-result"
,
action
)
headers
:=
[]
struct
{
key
string
value
string
}{
{
"Content-Type"
,
ct
},
{
"Cache-Control"
,
"no-cache"
},
}
// Check HTTP headers
for
_
,
h
:=
range
headers
{
if
value
:=
rr
.
Header
()
.
Get
(
h
.
key
);
value
!=
h
.
value
{
t
.
Errorf
(
"HTTP header %v does not match: expected: %v, got %v"
,
h
.
key
,
h
.
value
,
value
)
}
}
if
rr
.
Body
.
String
()
!=
string
(
testInput
)
{
t
.
Errorf
(
"handler did not receive expected data: got %d, expected %d bytes"
,
len
(
rr
.
Body
.
String
()),
len
(
testInput
))
}
}
func
stringInSlice
(
a
string
,
list
[]
string
)
bool
{
for
_
,
b
:=
range
list
{
if
b
==
a
{
return
true
}
}
return
false
}
func
TestGitCommandProcess
(
t
*
testing
.
T
)
{
if
os
.
Getenv
(
"GL_ID"
)
!=
GL_ID
{
return
}
defer
os
.
Exit
(
0
)
uploadPack
:=
stringInSlice
(
"upload-pack"
,
os
.
Args
)
if
uploadPack
{
// First, send a large payload to stdout so that this executable will be blocked
// until the reader consumes the data
testInput
:=
createTestPayload
()
body
:=
bytes
.
NewReader
([]
byte
(
testInput
))
io
.
Copy
(
os
.
Stdout
,
body
)
// Now consume all the data to unblock the sender
ioutil
.
ReadAll
(
os
.
Stdin
)
}
else
{
io
.
Copy
(
os
.
Stdout
,
os
.
Stdin
)
}
}
此差异已折叠。
点击以展开。
internal/git/receive-pack.go
+
2
−
31
浏览文件 @
e4807eec
package
git
package
git
import
(
import
(
"context"
"fmt"
"fmt"
"io"
"net/http"
"net/http"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
...
@@ -20,41 +18,14 @@ func handleReceivePack(w *HttpResponseWriter, r *http.Request, a *api.Response)
...
@@ -20,41 +18,14 @@ func handleReceivePack(w *HttpResponseWriter, r *http.Request, a *api.Response)
cr
,
cw
:=
helper
.
NewWriteAfterReader
(
r
.
Body
,
w
)
cr
,
cw
:=
helper
.
NewWriteAfterReader
(
r
.
Body
,
w
)
defer
cw
.
Flush
()
defer
cw
.
Flush
()
var
err
error
gitProtocol
:=
r
.
Header
.
Get
(
"Git-Protocol"
)
if
a
.
GitalyServer
.
Address
==
""
{
err
=
handleReceivePackLocally
(
a
,
r
,
cr
,
cw
,
action
)
}
else
{
gitProtocol
:=
r
.
Header
.
Get
(
"Git-Protocol"
)
err
=
handleReceivePackWithGitaly
(
r
.
Context
(),
a
,
cr
,
cw
,
gitProtocol
)
}
return
err
}
func
handleReceivePackLocally
(
a
*
api
.
Response
,
r
*
http
.
Request
,
stdin
io
.
Reader
,
stdout
io
.
Writer
,
action
string
)
error
{
cmd
,
err
:=
startGitCommand
(
a
,
stdin
,
stdout
,
action
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"startGitCommand: %v"
,
err
)
}
defer
helper
.
CleanUpProcessGroup
(
cmd
)
if
err
:=
cmd
.
Wait
();
err
!=
nil
{
helper
.
LogError
(
r
,
fmt
.
Errorf
(
"wait for %v: %v"
,
cmd
.
Args
,
err
))
// Return nil because the response body has been written to already.
return
nil
}
return
nil
}
func
handleReceivePackWithGitaly
(
ctx
context
.
Context
,
a
*
api
.
Response
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
,
gitProtocol
string
)
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
(
ctx
,
&
a
.
Repository
,
a
.
GL_ID
,
a
.
GL_USERNAME
,
a
.
GL_REPOSITORY
,
a
.
GitConfigOptions
,
c
lientRequest
,
clientResponse
,
gitProtocol
);
err
!=
nil
{
if
err
:=
smarthttp
.
ReceivePack
(
r
.
Context
()
,
&
a
.
Repository
,
a
.
GL_ID
,
a
.
GL_USERNAME
,
a
.
GL_REPOSITORY
,
a
.
GitConfigOptions
,
c
r
,
cw
,
gitProtocol
);
err
!=
nil
{
return
fmt
.
Errorf
(
"smarthttp.ReceivePack: %v"
,
err
)
return
fmt
.
Errorf
(
"smarthttp.ReceivePack: %v"
,
err
)
}
}
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录