From edc94c70413048107ea728ff330f32ca3de6df88 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 27 Jun 2019 02:15:26 +0800 Subject: 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 --- routers/repo/http.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'routers/repo/http.go') 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) -- cgit v1.2.3