diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-08-28 14:22:52 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-08-29 13:04:00 +0300 |
commit | 76dfdf81ccace17f45624960c5ee709ff5da81bf (patch) | |
tree | d126a3d3333ab5cbf793fa27fe2cbf262ae047f9 | |
parent | 716dc218ec034369ca3952b2ae062d3444a7b9bc (diff) |
commit: Refactor RawBlame to write into `streamio` writer diretcly
We manually copy output from git-blame(1) into the stream writer in the
RawBlame RPC. Refactor the code to instead spawn the command such that
it is connected to the writer directly, thus simplifying the code.
-rw-r--r-- | internal/gitaly/service/commit/raw_blame.go | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/internal/gitaly/service/commit/raw_blame.go b/internal/gitaly/service/commit/raw_blame.go index 4da2de5b0..454e143fa 100644 --- a/internal/gitaly/service/commit/raw_blame.go +++ b/internal/gitaly/service/commit/raw_blame.go @@ -2,10 +2,8 @@ package commit import ( "fmt" - "io" "regexp" - "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/v16/internal/git" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" "gitlab.com/gitlab-org/gitaly/v16/internal/structerr" @@ -30,27 +28,22 @@ func (s *server) RawBlame(in *gitalypb.RawBlameRequest, stream gitalypb.CommitSe flags = append(flags, git.ValueFlag{Name: "-L", Value: blameRange}) } + sw := streamio.NewWriter(func(p []byte) error { + return stream.Send(&gitalypb.RawBlameResponse{Data: p}) + }) + cmd, err := s.gitCmdFactory.New(ctx, in.Repository, git.Command{ Name: "blame", Flags: flags, Args: []string{revision}, PostSepArgs: []string{path}, - }, git.WithSetupStdout()) + }, git.WithStdout(sw)) if err != nil { return structerr.NewInternal("cmd: %w", err) } - sw := streamio.NewWriter(func(p []byte) error { - return stream.Send(&gitalypb.RawBlameResponse{Data: p}) - }) - - _, err = io.Copy(sw, cmd) - if err != nil { - return structerr.NewAborted("send: %w", err) - } - if err := cmd.Wait(); err != nil { - ctxlogrus.Extract(ctx).WithError(err).Info("ignoring git-blame error") + return fmt.Errorf("streaming raw blame data: %w", err) } return nil |