mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	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`.
This commit is contained in:
		
							
								
								
									
										37
									
								
								cmd/hook.go
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								cmd/hook.go
									
									
									
									
									
								
							| @@ -448,23 +448,26 @@ Gitea or set your environment appropriately.`, "") | ||||
|  | ||||
| func hookPrintResults(results []private.HookPostReceiveBranchResult) { | ||||
| 	for _, res := range results { | ||||
| 		if !res.Message { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		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() | ||||
| 		hookPrintResult(res.Message, res.Create, res.Branch, res.URL) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| 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 { | ||||
| 	opts := make(map[string]string) | ||||
| 	if pushCount, err := strconv.Atoi(os.Getenv(private.GitPushOptionCount)); err == nil { | ||||
| @@ -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 | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user