mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	Backport #28454 (the only conflict is caused by some comments) * Close #24483 * Close #28123 * Close #23682 * Close #23149
This commit is contained in:
		@@ -14,7 +14,6 @@ import (
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
	"unsafe"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/modules/git/internal" //nolint:depguard // only this file can use the internal type CmdArg, other files and packages should use AddXxx functions
 | 
			
		||||
	"code.gitea.io/gitea/modules/log"
 | 
			
		||||
@@ -389,15 +388,11 @@ func (r *runStdError) IsExitCode(code int) bool {
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func bytesToString(b []byte) string {
 | 
			
		||||
	return *(*string)(unsafe.Pointer(&b)) // that's what Golang's strings.Builder.String() does (go/src/strings/builder.go)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RunStdString runs the command with options and returns stdout/stderr as string. and store stderr to returned error (err combined with stderr).
 | 
			
		||||
func (c *Command) RunStdString(opts *RunOpts) (stdout, stderr string, runErr RunStdError) {
 | 
			
		||||
	stdoutBytes, stderrBytes, err := c.RunStdBytes(opts)
 | 
			
		||||
	stdout = bytesToString(stdoutBytes)
 | 
			
		||||
	stderr = bytesToString(stderrBytes)
 | 
			
		||||
	stdout = util.UnsafeBytesToString(stdoutBytes)
 | 
			
		||||
	stderr = util.UnsafeBytesToString(stderrBytes)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return stdout, stderr, &runStdError{err: err, stderr: stderr}
 | 
			
		||||
	}
 | 
			
		||||
@@ -432,7 +427,7 @@ func (c *Command) RunStdBytes(opts *RunOpts) (stdout, stderr []byte, runErr RunS
 | 
			
		||||
	err := c.Run(newOpts)
 | 
			
		||||
	stderr = stderrBuf.Bytes()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, stderr, &runStdError{err: err, stderr: bytesToString(stderr)}
 | 
			
		||||
		return nil, stderr, &runStdError{err: err, stderr: util.UnsafeBytesToString(stderr)}
 | 
			
		||||
	}
 | 
			
		||||
	// even if there is no err, there could still be some stderr output
 | 
			
		||||
	return stdoutBuf.Bytes(), stderr, nil
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user