diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-01-03 14:57:46 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-01-03 17:53:33 +0300 |
commit | aa9f210c73eea36dba5561477932c08b7c855578 (patch) | |
tree | b1c14c269eb6a7709bc30501f9ff0cfef8a65d1f | |
parent | 7196b1cc17fa9e4b2673eaa9e7ef8d63dd2f66b3 (diff) |
repository: Fix intermingled stdout/stderr output for git-fsck(1)
We use two different buffers when spawning git-fsck(1) for its stdout
and stderr. This is inefficient as we now need to handle the overhead
for two buffers and need to spawn two Goroutines for them. Furthermore,
if git-fsck(1) was to print alternately to stdout and stderr, the order
of these messages gets lost as we used to just concatenate stdout and
stderr.
Fix this by using a single buffer for both standard streams. While at
it, convert the code to use a `strings.Builder` instead of a
`bytes.Buffer`, which is more efficient.
-rw-r--r-- | internal/gitaly/service/repository/fsck.go | 10 | ||||
-rw-r--r-- | internal/gitaly/service/repository/fsck_test.go | 6 |
2 files changed, 8 insertions, 8 deletions
diff --git a/internal/gitaly/service/repository/fsck.go b/internal/gitaly/service/repository/fsck.go index 9b5f0a9e9..6ccd7499b 100644 --- a/internal/gitaly/service/repository/fsck.go +++ b/internal/gitaly/service/repository/fsck.go @@ -1,8 +1,8 @@ package repository import ( - "bytes" "context" + "strings" "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service" @@ -16,18 +16,18 @@ func (s *server) Fsck(ctx context.Context, req *gitalypb.FsckRequest) (*gitalypb return nil, structerr.NewInvalidArgument("%w", err) } - var stdout, stderr bytes.Buffer + var output strings.Builder cmd, err := s.gitCmdFactory.New(ctx, repository, git.Command{Name: "fsck"}, - git.WithStdout(&stdout), - git.WithStderr(&stderr), + git.WithStdout(&output), + git.WithStderr(&output), ) if err != nil { return nil, err } if err = cmd.Wait(); err != nil { - return &gitalypb.FsckResponse{Error: append(stdout.Bytes(), stderr.Bytes()...)}, nil + return &gitalypb.FsckResponse{Error: []byte(output.String())}, nil } return &gitalypb.FsckResponse{}, nil diff --git a/internal/gitaly/service/repository/fsck_test.go b/internal/gitaly/service/repository/fsck_test.go index 932bac845..303ad8934 100644 --- a/internal/gitaly/service/repository/fsck_test.go +++ b/internal/gitaly/service/repository/fsck_test.go @@ -151,10 +151,10 @@ func TestFsck(t *testing.T) { }) expectedErr := strings.Join([]string{ - // This first error is a bug: we shouldn't complain about - // the dangling tree. - "dangling tree " + treeID.String(), "error in tree " + treeID.String() + ": duplicateEntries: contains duplicate file entries", + // This error is a bug: we shouldn't complain about the + // dangling tree. + "dangling tree " + treeID.String(), }, "\n") + "\n" return setupData{ |