diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-06-27 02:15:26 +0800 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-06-26 14:15:26 -0400 |
commit | edc94c70413048107ea728ff330f32ca3de6df88 (patch) | |
tree | cf5bcc5ba8ee4b2e585dc14a6cf7440ce88bc073 /routers/repo/http.go | |
parent | 161e12e157a48f9bcd2de50c187c77444aa2a9a8 (diff) | |
download | gitea-edc94c70413048107ea728ff330f32ca3de6df88.tar.gz gitea-edc94c70413048107ea728ff330f32ca3de6df88.zip |
Monitor all git commands; move blame to git package and replace git as a variable (#6864)
* monitor all git commands; move blame to git package and replace git as a variable
* use git command but not other commands
* fix build
* move exec.Command to git.NewCommand
* fix fmt
* remove unrelated changes
* remove unrelated changes
* refactor IsEmpty and add tests
* fix tests
* fix tests
* fix tests
* fix tests
* remove gitLogger
* fix fmt
* fix isEmpty
* fix lint
* fix tests
Diffstat (limited to 'routers/repo/http.go')
-rw-r--r-- | routers/repo/http.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/routers/repo/http.go b/routers/repo/http.go index 3072209448..48f5625051 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -22,6 +22,7 @@ import ( "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -343,19 +344,11 @@ var routes = []route{ {regexp.MustCompile(`(.*?)/objects/pack/pack-[0-9a-f]{40}\.idx$`), "GET", getIdxFile}, } -// FIXME: use process module -func gitCommand(dir string, args ...string) []byte { - cmd := exec.Command("git", args...) - cmd.Dir = dir - out, err := cmd.Output() +func getGitConfig(option, dir string) string { + out, err := git.NewCommand("config", option).RunInDir(dir) if err != nil { log.Error("%v - %s", err, out) } - return out -} - -func getGitConfig(option, dir string) string { - out := string(gitCommand(dir, "config", option)) return out[0 : len(out)-1] } @@ -422,7 +415,7 @@ func serviceRPC(h serviceHandler, service string) { h.environ = append(h.environ, "SSH_ORIGINAL_COMMAND="+service) var stderr bytes.Buffer - cmd := exec.Command("git", service, "--stateless-rpc", h.dir) + cmd := exec.Command(git.GitExecutable, service, "--stateless-rpc", h.dir) cmd.Dir = h.dir if service == "receive-pack" { cmd.Env = append(os.Environ(), h.environ...) @@ -453,7 +446,11 @@ func getServiceType(r *http.Request) string { } func updateServerInfo(dir string) []byte { - return gitCommand(dir, "update-server-info") + out, err := git.NewCommand("update-server-info").RunInDirBytes(dir) + if err != nil { + log.Error(fmt.Sprintf("%v - %s", err, string(out))) + } + return out } func packetWrite(str string) []byte { @@ -468,7 +465,10 @@ func getInfoRefs(h serviceHandler) { h.setHeaderNoCache() if hasAccess(getServiceType(h.r), h, false) { service := getServiceType(h.r) - refs := gitCommand(h.dir, service, "--stateless-rpc", "--advertise-refs", ".") + refs, err := git.NewCommand(service, "--stateless-rpc", "--advertise-refs", ".").RunInDirBytes(h.dir) + if err != nil { + log.Error(fmt.Sprintf("%v - %s", err, string(refs))) + } h.w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-advertisement", service)) h.w.WriteHeader(http.StatusOK) |