3 Star 0 Fork 0

Gitee 极速下载 / gitlab-workhorsesource

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://gitlab.com/gitlab-org/gitlab-workhorse
克隆/下载
info-refs.go 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
Andrew Newdigate 提交于 2018-08-23 14:10 . Lint Workhorse
package git
import (
"context"
"fmt"
"io"
"net/http"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
)
var (
// Testing is only set during workhorse testing.
Testing = false
)
func GetInfoRefsHandler(a *api.API) http.Handler {
return repoPreAuthorizeHandler(a, handleGetInfoRefs)
}
func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response) {
w := NewHttpResponseWriter(rw)
// Log 0 bytes in because we ignore the request body (and there usually is none anyway).
defer w.Log(r, 0)
rpc := getService(r)
if !(rpc == "git-upload-pack" || rpc == "git-receive-pack") {
// The 'dumb' Git HTTP protocol is not supported
http.Error(w, "Not Found", 404)
return
}
w.Header().Set("Content-Type", fmt.Sprintf("application/x-%s-advertisement", rpc))
w.Header().Set("Cache-Control", "no-cache")
gitProtocol := r.Header.Get("Git-Protocol")
var err error
if a.GitalyServer.Address == "" && Testing {
err = handleGetInfoRefsLocalTesting(w, a, rpc)
} else {
err = handleGetInfoRefsWithGitaly(r.Context(), w, a, rpc, gitProtocol)
}
if err != nil {
helper.Fail500(w, r, fmt.Errorf("handleGetInfoRefs: %v", err))
}
}
// This code is not used in production. It is left over from before
// Gitaly. We left it here to allow local workhorse tests to keep working
// until we are done migrating Git HTTP to Gitaly.
func handleGetInfoRefsLocalTesting(w http.ResponseWriter, a *api.Response, rpc string) error {
if err := pktLine(w, fmt.Sprintf("# service=%s\n", rpc)); err != nil {
return fmt.Errorf("pktLine: %v", err)
}
if err := pktFlush(w); err != nil {
return fmt.Errorf("pktFlush: %v", err)
}
cmd, err := startGitCommand(a, nil, w, rpc, "--advertise-refs")
if err != nil {
return fmt.Errorf("startGitCommand: %v", err)
}
defer helper.CleanUpProcessGroup(cmd) // Ensure brute force subprocess clean-up
if err := cmd.Wait(); err != nil {
return fmt.Errorf("wait for %v: %v", cmd.Args, err)
}
return nil
}
func handleGetInfoRefsWithGitaly(ctx context.Context, w http.ResponseWriter, a *api.Response, rpc string, gitProtocol string) error {
smarthttp, err := gitaly.NewSmartHTTPClient(a.GitalyServer)
if err != nil {
return fmt.Errorf("GetInfoRefsHandler: %v", err)
}
infoRefsResponseReader, err := smarthttp.InfoRefsResponseReader(ctx, &a.Repository, rpc, gitConfigOptions(a), gitProtocol)
if err != nil {
return fmt.Errorf("GetInfoRefsHandler: %v", err)
}
if _, err = io.Copy(w, infoRefsResponseReader); err != nil {
return fmt.Errorf("GetInfoRefsHandler: copy Gitaly response: %v", err)
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/gitlab-workhorsesource.git
git@gitee.com:mirrors/gitlab-workhorsesource.git
mirrors
gitlab-workhorsesource
gitlab-workhorsesource
v6.1.2

搜索帮助

344bd9b3 5694891 D2dac590 5694891