diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-04-01 10:55:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-01 10:55:30 +0800 |
commit | 124b072f0b69650baff086b9688d198f5a6761af (patch) | |
tree | fa18f7930053a8408e124875b5dec20e0309332b /routers/web/repo | |
parent | 3a73645502392110369b5d78fa2c9136e77e4aa2 (diff) | |
download | gitea-124b072f0b69650baff086b9688d198f5a6761af.tar.gz gitea-124b072f0b69650baff086b9688d198f5a6761af.zip |
Remove `git.Command.Run` and `git.Command.RunInDir*` (#19280)
Follows #19266, #8553, Close #18553, now there are only three `Run..(&RunOpts{})` functions.
* before: `stdout, err := RunInDir(path)`
* now: `stdout, _, err := RunStdString(&git.RunOpts{Dir:path})`
Diffstat (limited to 'routers/web/repo')
-rw-r--r-- | routers/web/repo/http.go | 21 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 2 |
2 files changed, 11 insertions, 12 deletions
diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index 82ac95c1bc..1306a54369 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -313,7 +313,7 @@ func dummyInfoRefs(ctx *context.Context) { return } - refs, err := git.NewCommand(ctx, "receive-pack", "--stateless-rpc", "--advertise-refs", ".").RunInDirBytes(tmpDir) + refs, _, err := git.NewCommand(ctx, "receive-pack", "--stateless-rpc", "--advertise-refs", ".").RunStdBytes(&git.RunOpts{Dir: tmpDir}) if err != nil { log.Error(fmt.Sprintf("%v - %s", err, string(refs))) } @@ -397,7 +397,7 @@ func (h *serviceHandler) sendFile(contentType, file string) { var safeGitProtocolHeader = regexp.MustCompile(`^[0-9a-zA-Z]+=[0-9a-zA-Z]+(:[0-9a-zA-Z]+=[0-9a-zA-Z]+)*$`) func getGitConfig(ctx gocontext.Context, option, dir string) string { - out, err := git.NewCommand(ctx, "config", option).RunInDir(dir) + out, _, err := git.NewCommand(ctx, "config", option).RunStdString(&git.RunOpts{Dir: dir}) if err != nil { log.Error("%v - %s", err, out) } @@ -472,13 +472,12 @@ func serviceRPC(ctx gocontext.Context, h serviceHandler, service string) { var stderr bytes.Buffer cmd := git.NewCommand(h.r.Context(), service, "--stateless-rpc", h.dir) cmd.SetDescription(fmt.Sprintf("%s %s %s [repo_path: %s]", git.GitExecutable, service, "--stateless-rpc", h.dir)) - if err := cmd.RunWithContext(&git.RunContext{ - Timeout: -1, - Dir: h.dir, - Env: append(os.Environ(), h.environ...), - Stdout: h.w, - Stdin: reqBody, - Stderr: &stderr, + if err := cmd.Run(&git.RunOpts{ + Dir: h.dir, + Env: append(os.Environ(), h.environ...), + Stdout: h.w, + Stdin: reqBody, + Stderr: &stderr, }); err != nil { if err.Error() != "signal: killed" { log.Error("Fail to serve RPC(%s) in %s: %v - %s", service, h.dir, err, stderr.String()) @@ -512,7 +511,7 @@ func getServiceType(r *http.Request) string { } func updateServerInfo(ctx gocontext.Context, dir string) []byte { - out, err := git.NewCommand(ctx, "update-server-info").RunInDirBytes(dir) + out, _, err := git.NewCommand(ctx, "update-server-info").RunStdBytes(&git.RunOpts{Dir: dir}) if err != nil { log.Error(fmt.Sprintf("%v - %s", err, string(out))) } @@ -542,7 +541,7 @@ func GetInfoRefs(ctx *context.Context) { } h.environ = append(os.Environ(), h.environ...) - refs, _, err := git.NewCommand(ctx, service, "--stateless-rpc", "--advertise-refs", ".").RunWithContextBytes(&git.RunContext{Env: h.environ, Dir: h.dir}) + refs, _, err := git.NewCommand(ctx, service, "--stateless-rpc", "--advertise-refs", ".").RunStdBytes(&git.RunOpts{Env: h.environ, Dir: h.dir}) if err != nil { log.Error(fmt.Sprintf("%v - %s", err, string(refs))) } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 32d9a65cbd..b324ae4d2e 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -340,7 +340,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C } if commitSHA != "" { // Get immediate parent of the first commit in the patch, grab history back - parentCommit, err = git.NewCommand(ctx, "rev-list", "-1", "--skip=1", commitSHA).RunInDir(ctx.Repo.GitRepo.Path) + parentCommit, _, err = git.NewCommand(ctx, "rev-list", "-1", "--skip=1", commitSHA).RunStdString(&git.RunOpts{Dir: ctx.Repo.GitRepo.Path}) if err == nil { parentCommit = strings.TrimSpace(parentCommit) } |