diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-08-28 15:49:01 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-08-29 13:04:00 +0300 |
commit | 716dc218ec034369ca3952b2ae062d3444a7b9bc (patch) | |
tree | 6553097ef2107db756b69f709ba3f714a869a857 | |
parent | 332f5d7439e93073276e5753ef74b92af4b6238a (diff) |
smarthttp: Simplify ref advertisement
When handling the reference advertisement in our smarthttp service, we
manually copy output from Git into the writer. This is likely done this
way because we also write some preceding lines to that writer ourselves,
but is ultimately unnecessary.
Refactor the code to instead have the command write directly into the
writer to simplify the code and required error handling.
-rw-r--r-- | internal/gitaly/service/smarthttp/inforefs.go | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/internal/gitaly/service/smarthttp/inforefs.go b/internal/gitaly/service/smarthttp/inforefs.go index ca804924a..97b50bbdc 100644 --- a/internal/gitaly/service/smarthttp/inforefs.go +++ b/internal/gitaly/service/smarthttp/inforefs.go @@ -58,7 +58,7 @@ func (s *server) handleInfoRefs(ctx context.Context, service, repoPath string, r "service": service, }).Debug("handleInfoRefs") - cmdOpts := []git.CmdOpt{git.WithGitProtocol(req), git.WithSetupStdout()} + cmdOpts := []git.CmdOpt{git.WithGitProtocol(req), git.WithStdout(w)} if service == "receive-pack" { cmdOpts = append(cmdOpts, git.WithRefTxHook(req.Repository)) } @@ -69,15 +69,6 @@ func (s *server) handleInfoRefs(ctx context.Context, service, repoPath string, r } cmdOpts = append(cmdOpts, git.WithConfig(config...)) - cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), git.Command{ - Name: service, - Flags: []git.Option{git.Flag{Name: "--stateless-rpc"}, git.Flag{Name: "--advertise-refs"}}, - Args: []string{repoPath}, - }, cmdOpts...) - if err != nil { - return structerr.NewInternal("cmd: %w", err) - } - if _, err := pktline.WriteString(w, fmt.Sprintf("# service=git-%s\n", service)); err != nil { return structerr.NewInternal("pktLine: %w", err) } @@ -86,8 +77,13 @@ func (s *server) handleInfoRefs(ctx context.Context, service, repoPath string, r return structerr.NewInternal("pktFlush: %w", err) } - if _, err := io.Copy(w, cmd); err != nil { - return structerr.NewInternal("send: %w", err) + cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), git.Command{ + Name: service, + Flags: []git.Option{git.Flag{Name: "--stateless-rpc"}, git.Flag{Name: "--advertise-refs"}}, + Args: []string{repoPath}, + }, cmdOpts...) + if err != nil { + return structerr.NewInternal("cmd: %w", err) } if err := cmd.Wait(); err != nil { |