Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2020-10-21 10:45:46 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-10-28 10:49:04 +0300
commita3e59c425f62b2d6fa7a5968a7888a59238ba253 (patch)
tree6e00fe3b1c70b08c23a43fb88247bd4108b30d5e /internal/gitaly/service/operations/merge.go
parentbee8517ab043ff98c283a5f191e68e2bd75eb9de (diff)
operations: Use repository abstraction to resolve refs
The operations service currently uses an open-coded `parseRevision` function, which uses git-rev-parse(1) to resolve a reference. As we have since grown `ResoveRefish` in our repository abstraction which does the same, let's use that one and remove the open-coded variant.
Diffstat (limited to 'internal/gitaly/service/operations/merge.go')
-rw-r--r--internal/gitaly/service/operations/merge.go31
1 files changed, 4 insertions, 27 deletions
diff --git a/internal/gitaly/service/operations/merge.go b/internal/gitaly/service/operations/merge.go
index f062d8197..f186a33e9 100644
--- a/internal/gitaly/service/operations/merge.go
+++ b/internal/gitaly/service/operations/merge.go
@@ -5,7 +5,6 @@ import (
"context"
"errors"
"fmt"
- "io"
"strings"
"gitlab.com/gitlab-org/gitaly/internal/command"
@@ -191,29 +190,6 @@ func (s *server) updateReferenceWithHooks(ctx context.Context, repo *gitalypb.Re
return nil
}
-// parseRevision parses a Git revision and returns its OID.
-func parseRevision(ctx context.Context, repo *gitalypb.Repository, revision string) (string, error) {
- revParse, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{
- Name: "rev-parse",
- Flags: []git.Option{git.Flag{"--verify"}},
- Args: []string{revision},
- })
- if err != nil {
- return "", err
- }
-
- var stdout bytes.Buffer
- if _, err := io.Copy(&stdout, revParse); err != nil {
- return "", err
- }
-
- if err := revParse.Wait(); err != nil {
- return "", err
- }
-
- return text.ChompBytes(stdout.Bytes()), nil
-}
-
func (s *server) userMergeBranch(stream gitalypb.OperationService_UserMergeBranchServer) error {
ctx := stream.Context()
@@ -226,12 +202,13 @@ func (s *server) userMergeBranch(stream gitalypb.OperationService_UserMergeBranc
return helper.ErrInvalidArgument(err)
}
- revision, err := parseRevision(ctx, firstRequest.Repository, string(firstRequest.Branch))
+ repo := firstRequest.Repository
+ repoPath, err := s.locator.GetPath(repo)
if err != nil {
return err
}
- repoPath, err := s.locator.GetPath(firstRequest.Repository)
+ revision, err := git.NewRepository(repo).ResolveRefish(ctx, string(firstRequest.Branch))
if err != nil {
return err
}
@@ -322,7 +299,7 @@ func (s *server) UserFFBranch(ctx context.Context, in *gitalypb.UserFFBranchRequ
return s.userFFBranchRuby(ctx, in)
}
- revision, err := parseRevision(ctx, in.Repository, string(in.Branch))
+ revision, err := git.NewRepository(in.Repository).ResolveRefish(ctx, string(in.Branch))
if err != nil {
return nil, helper.ErrInvalidArgument(err)
}