diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-04-09 11:43:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-09 03:43:17 +0000 |
commit | 263a716cb52037f3e7e51f014f6c8cdfad6ae03d (patch) | |
tree | 2ca921707de7f1d35bacefe0f06a9ea0aa676f32 /cmd/hook.go | |
parent | 72dc75e594fb5227abfa1cb74cb652cc33bacc93 (diff) | |
download | gitea-263a716cb52037f3e7e51f014f6c8cdfad6ae03d.tar.gz gitea-263a716cb52037f3e7e51f014f6c8cdfad6ae03d.zip |
Performance optimization for git push (#30104)
Agit returned result should be from `ProcReceive` hook but not
`PostReceive` hook. Then for all non-agit pull requests, it will not
check the pull requests for every pushing `refs/pull/%d/head`.
Diffstat (limited to 'cmd/hook.go')
-rw-r--r-- | cmd/hook.go | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/cmd/hook.go b/cmd/hook.go index 6a3358853d..c04591d79e 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -448,21 +448,24 @@ Gitea or set your environment appropriately.`, "") func hookPrintResults(results []private.HookPostReceiveBranchResult) { for _, res := range results { - if !res.Message { - continue - } + hookPrintResult(res.Message, res.Create, res.Branch, res.URL) + } +} - fmt.Fprintln(os.Stderr, "") - if res.Create { - fmt.Fprintf(os.Stderr, "Create a new pull request for '%s':\n", res.Branch) - fmt.Fprintf(os.Stderr, " %s\n", res.URL) - } else { - fmt.Fprint(os.Stderr, "Visit the existing pull request:\n") - fmt.Fprintf(os.Stderr, " %s\n", res.URL) - } - fmt.Fprintln(os.Stderr, "") - os.Stderr.Sync() +func hookPrintResult(output, isCreate bool, branch, url string) { + if !output { + return + } + fmt.Fprintln(os.Stderr, "") + if isCreate { + fmt.Fprintf(os.Stderr, "Create a new pull request for '%s':\n", branch) + fmt.Fprintf(os.Stderr, " %s\n", url) + } else { + fmt.Fprint(os.Stderr, "Visit the existing pull request:\n") + fmt.Fprintf(os.Stderr, " %s\n", url) } + fmt.Fprintln(os.Stderr, "") + os.Stderr.Sync() } func pushOptions() map[string]string { @@ -691,6 +694,12 @@ Gitea or set your environment appropriately.`, "") } err = writeFlushPktLine(ctx, os.Stdout) + if err == nil { + for _, res := range resp.Results { + hookPrintResult(res.ShouldShowMessage, res.IsCreatePR, res.HeadBranch, res.URL) + } + } + return err } |