diff options
author | TheFox0x7 <thefox0x7@gmail.com> | 2025-03-04 20:56:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-04 11:56:11 -0800 |
commit | ae3a18e01a10520f5e12255304c7a9bbb246c41e (patch) | |
tree | 58494c1e9ae3ac68e773efdcfcb98a961d56914a /routers/web/repo | |
parent | 6c8fb8d455cfe25d5aa966674624bce99fba1735 (diff) | |
download | gitea-ae3a18e01a10520f5e12255304c7a9bbb246c41e.tar.gz gitea-ae3a18e01a10520f5e12255304c7a9bbb246c41e.zip |
Remove context from git struct (#33793)
Argument is moved from struct init in command run, which lets us remove
context from struct.
Diffstat (limited to 'routers/web/repo')
-rw-r--r-- | routers/web/repo/githttp.go | 18 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 2 |
2 files changed, 10 insertions, 10 deletions
diff --git a/routers/web/repo/githttp.go b/routers/web/repo/githttp.go index 5b7b0188dc..f93d7fc66a 100644 --- a/routers/web/repo/githttp.go +++ b/routers/web/repo/githttp.go @@ -320,7 +320,7 @@ func dummyInfoRefs(ctx *context.Context) { return } - refs, _, err := git.NewCommand(ctx, "receive-pack", "--stateless-rpc", "--advertise-refs", ".").RunStdBytes(&git.RunOpts{Dir: tmpDir}) + refs, _, err := git.NewCommand("receive-pack", "--stateless-rpc", "--advertise-refs", ".").RunStdBytes(ctx, &git.RunOpts{Dir: tmpDir}) if err != nil { log.Error(fmt.Sprintf("%v - %s", err, string(refs))) } @@ -403,12 +403,12 @@ func (h *serviceHandler) sendFile(ctx *context.Context, contentType, file string // one or more key=value pairs separated by colons var safeGitProtocolHeader = regexp.MustCompile(`^[0-9a-zA-Z]+=[0-9a-zA-Z]+(:[0-9a-zA-Z]+=[0-9a-zA-Z]+)*$`) -func prepareGitCmdWithAllowedService(ctx *context.Context, service string) (*git.Command, error) { +func prepareGitCmdWithAllowedService(service string) (*git.Command, error) { if service == "receive-pack" { - return git.NewCommand(ctx, "receive-pack"), nil + return git.NewCommand("receive-pack"), nil } if service == "upload-pack" { - return git.NewCommand(ctx, "upload-pack"), nil + return git.NewCommand("upload-pack"), nil } return nil, fmt.Errorf("service %q is not allowed", service) @@ -428,7 +428,7 @@ func serviceRPC(ctx *context.Context, h *serviceHandler, service string) { return } - cmd, err := prepareGitCmdWithAllowedService(ctx, service) + cmd, err := prepareGitCmdWithAllowedService(service) if err != nil { log.Error("Failed to prepareGitCmdWithService: %v", err) ctx.Resp.WriteHeader(http.StatusUnauthorized) @@ -458,7 +458,7 @@ func serviceRPC(ctx *context.Context, h *serviceHandler, service string) { var stderr bytes.Buffer cmd.AddArguments("--stateless-rpc").AddDynamicArguments(h.getRepoDir()) - if err := cmd.Run(&git.RunOpts{ + if err := cmd.Run(ctx, &git.RunOpts{ Dir: h.getRepoDir(), Env: append(os.Environ(), h.environ...), Stdout: ctx.Resp, @@ -498,7 +498,7 @@ func getServiceType(ctx *context.Context) string { } func updateServerInfo(ctx gocontext.Context, dir string) []byte { - out, _, err := git.NewCommand(ctx, "update-server-info").RunStdBytes(&git.RunOpts{Dir: dir}) + out, _, err := git.NewCommand("update-server-info").RunStdBytes(ctx, &git.RunOpts{Dir: dir}) if err != nil { log.Error(fmt.Sprintf("%v - %s", err, string(out))) } @@ -521,14 +521,14 @@ func GetInfoRefs(ctx *context.Context) { } setHeaderNoCache(ctx) service := getServiceType(ctx) - cmd, err := prepareGitCmdWithAllowedService(ctx, service) + cmd, err := prepareGitCmdWithAllowedService(service) if err == nil { if protocol := ctx.Req.Header.Get("Git-Protocol"); protocol != "" && safeGitProtocolHeader.MatchString(protocol) { h.environ = append(h.environ, "GIT_PROTOCOL="+protocol) } h.environ = append(os.Environ(), h.environ...) - refs, _, err := cmd.AddArguments("--stateless-rpc", "--advertise-refs", ".").RunStdBytes(&git.RunOpts{Env: h.environ, Dir: h.getRepoDir()}) + refs, _, err := cmd.AddArguments("--stateless-rpc", "--advertise-refs", ".").RunStdBytes(ctx, &git.RunOpts{Env: h.environ, Dir: h.getRepoDir()}) 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 0769f456ec..1d37fd8603 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -242,7 +242,7 @@ func GetMergedBaseCommitID(ctx *context.Context, issue *issues_model.Issue) stri } 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").AddDynamicArguments(commitSHA).RunStdString(&git.RunOpts{Dir: ctx.Repo.GitRepo.Path}) + parentCommit, _, err = git.NewCommand("rev-list", "-1", "--skip=1").AddDynamicArguments(commitSHA).RunStdString(ctx, &git.RunOpts{Dir: ctx.Repo.GitRepo.Path}) if err == nil { parentCommit = strings.TrimSpace(parentCommit) } |