func NewGitalyClient()

in internal/mode/advanced/git/gitaly.go [62:131]


func NewGitalyClient(config *StorageConfig, fromSHA, toSHA, correlationID string, projectID int64) (*gitalyClient, error) {
	var RPCCred credentials.PerRPCCredentials
	if config.TokenVersion == 0 || config.TokenVersion == 2 {
		RPCCred = gitalyauth.RPCCredentialsV2(config.Token)
	} else {
		return nil, errors.New("Unknown token version")
	}

	connOpts := append(
		gitalyclient.DefaultDialOpts,
		grpc.WithPerRPCCredentials(RPCCred),
		grpc.WithStreamInterceptor(
			grpccorrelation.StreamClientCorrelationInterceptor(
				grpccorrelation.WithClientName(clientName),
			),
		),
		grpc.WithUnaryInterceptor(
			grpccorrelation.UnaryClientCorrelationInterceptor(
				grpccorrelation.WithClientName(clientName),
			),
		),
	)

	ctx := newContext(correlationID)

	conn, err := gitalyclient.Dial(config.Address, connOpts)
	if err != nil {
		return nil, fmt.Errorf("did not connect: %w", err)
	}

	repository := &pb.Repository{
		StorageName:   config.StorageName,
		RelativePath:  config.RelativePath,
		GlProjectPath: config.ProjectPath,
		GlRepository:  strconv.FormatInt(projectID, 10),
	}

	client := &gitalyClient{
		conn:                    conn,
		repository:              repository,
		blobServiceClient:       pb.NewBlobServiceClient(conn),
		repositoryServiceClient: pb.NewRepositoryServiceClient(conn),
		refServiceClient:        pb.NewRefServiceClient(conn),
		commitServiceClient:     pb.NewCommitServiceClient(conn),
		ctx:                     ctx,
		limitFileSize:           config.LimitFileSize,
	}

	if fromSHA == "" {
		client.FromHash = client.getNullSHA()
	} else if fromSHA == ZeroSHA {
		client.FromHash = NullTreeSHA
	} else if fromSHA == ZeroSHA256 {
		client.FromHash = NullTreeSHA256
	} else {
		client.FromHash = fromSHA
	}

	if toSHA == "" {
		head, err := client.lookUpHEAD()
		if err != nil {
			return nil, fmt.Errorf("lookUpHEAD: %w", err)
		}
		client.ToHash = head
	} else {
		client.ToHash = toSHA
	}

	return client, nil
}