1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package commit
import (
"context"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *server) CommitIsAncestor(ctx context.Context, in *gitalypb.CommitIsAncestorRequest) (*gitalypb.CommitIsAncestorResponse, error) {
if in.AncestorId == "" {
return nil, status.Errorf(codes.InvalidArgument, "Bad Request (empty ancestor sha)")
}
if in.ChildId == "" {
return nil, status.Errorf(codes.InvalidArgument, "Bad Request (empty child sha)")
}
ret, err := s.commitIsAncestorName(ctx, in.Repository, in.AncestorId, in.ChildId)
return &gitalypb.CommitIsAncestorResponse{Value: ret}, err
}
// Assumes that `path`, `ancestorID` and `childID` are populated :trollface:
func (s *server) commitIsAncestorName(ctx context.Context, repo *gitalypb.Repository, ancestorID, childID string) (bool, error) {
ctxlogrus.Extract(ctx).WithFields(log.Fields{
"ancestorSha": ancestorID,
"childSha": childID,
}).Debug("commitIsAncestor")
cmd, err := s.gitCmdFactory.New(ctx, repo, git.SubCmd{Name: "merge-base",
Flags: []git.Option{git.Flag{Name: "--is-ancestor"}}, Args: []string{ancestorID, childID}})
if err != nil {
if _, ok := status.FromError(err); ok {
return false, err
}
return false, status.Errorf(codes.Internal, err.Error())
}
return cmd.Wait() == nil, nil
}
|