diff options
author | John Cai <jcai@gitlab.com> | 2019-04-25 03:29:48 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-04-25 04:38:11 +0300 |
commit | 19b9deebf3a4d9c3795d89400319966d17985412 (patch) | |
tree | 2cfe841691536a7f498165969b4790a07a59877c | |
parent | 80221e5cd697c1974b9bb13b5f6ca66a044c6173 (diff) |
Use constant for escapedNewLine
-rw-r--r-- | internal/command/command.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/internal/command/command.go b/internal/command/command.go index 5aebc5732..c6f911ece 100644 --- a/internal/command/command.go +++ b/internal/command/command.go @@ -20,6 +20,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/config" ) +const ( + escapedNewline = `\n` +) + // GitEnv contains the ENV variables for git commands var GitEnv = []string{ // Force english locale for consistency on the output messages @@ -53,7 +57,9 @@ var exportedEnvVars = []string{ const ( // MaxStderrBytes is at most how many bytes will be written to stderr - MaxStderrBytes = 10000 // 10kb + MaxStderrBytes = 10000 // 10kb + // StderrBufferSize is the buffer size we use for the reader that reads from + // the stderr stream of the command StderrBufferSize = 4096 ) @@ -291,13 +297,13 @@ func writeLines(writer io.Writer, reader io.Reader, done chan struct{}, maxBytes } // only write up to the max - if len(b)+bytesWritten+2 >= maxBytes { - b = b[:maxBytes-bytesWritten-2] + if len(b)+bytesWritten+len(escapedNewline) >= maxBytes { + b = b[:maxBytes-bytesWritten-len(escapedNewline)] } // prepend an escaped newline if bytesWritten > 0 { - b = append([]byte{'\\', 'n'}, b...) + b = append([]byte(escapedNewline), b...) } n, _ := writer.Write(b) |