diff options
author | James Fargher <proglottis@gmail.com> | 2021-05-05 07:09:55 +0300 |
---|---|---|
committer | James Fargher <proglottis@gmail.com> | 2021-05-05 07:09:55 +0300 |
commit | 0e7805446f7f4502d487980540ed8ce336f0e650 (patch) | |
tree | 3894fe3a50c4e680a4149cc9d3baaa77bdf1f0de | |
parent | 49219ee575c14bf3ee8f4793efdd185528917a93 (diff) |
Use localrepo FetchRemote in FetchInternalRemotefetch_internal_remote_localrepo_fetch
-rw-r--r-- | internal/gitaly/service/remote/fetch_internal_remote.go | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/internal/gitaly/service/remote/fetch_internal_remote.go b/internal/gitaly/service/remote/fetch_internal_remote.go index d5050a52f..fd14fd430 100644 --- a/internal/gitaly/service/remote/fetch_internal_remote.go +++ b/internal/gitaly/service/remote/fetch_internal_remote.go @@ -8,6 +8,7 @@ import ( "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" + "gitlab.com/gitlab-org/gitaly/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/ref" "gitlab.com/gitlab-org/gitaly/internal/gitalyssh" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -32,30 +33,20 @@ func (s *server) FetchInternalRemote(ctx context.Context, req *gitalypb.FetchInt return nil, fmt.Errorf("upload pack environment: %w", err) } + repo := localrepo.New(s.gitCmdFactory, req.GetRepository(), s.cfg) stderr := &bytes.Buffer{} - flags := []git.Option{ - git.Flag{Name: "--prune"}, - git.Flag{Name: "--atomic"}, - } - options := []git.CmdOpt{ - git.WithEnv(env...), - git.WithStderr(stderr), - git.WithRefTxHook(ctx, req.Repository, s.cfg), - } - - cmd, err := s.gitCmdFactory.New(ctx, req.Repository, - git.SubCmd{ - Name: "fetch", - Flags: flags, - Args: []string{gitalyssh.GitalyInternalURL, mirrorRefSpec}, + err = repo.FetchRemote(ctx, gitalyssh.GitalyInternalURL, localrepo.FetchOpts{ + Env: env, + Stderr: stderr, + Prune: true, + Atomic: true, + RefSpecs: []string{mirrorRefSpec}, + CommandOptions: []git.CmdOpt{ + git.WithRefTxHook(ctx, req.Repository, s.cfg), }, - options..., - ) + }) if err != nil { - return nil, fmt.Errorf("create git fetch: %w", err) - } - if err := cmd.Wait(); err != nil { if featureflag.IsDisabled(ctx, featureflag.FetchInternalRemoteErrors) { // Design quirk: if the fetch fails, this RPC returns Result: false, but no error. ctxlogrus.Extract(ctx).WithError(err).WithField("stderr", stderr.String()).Warn("git fetch failed") |