blob: 39706005cdf129a366c1c9b2ef83a38d6ddd87ea [file] [log] [blame]
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"context"
"errors"
"golang.org/x/build/maintner"
"golang.org/x/build/maintner/maintnerd/apipb"
)
// apiService implements apipb.MaintnerServiceServer using the Corpus c.
type apiService struct {
c *maintner.Corpus
}
func (s apiService) HasAncestor(ctx context.Context, req *apipb.HasAncestorRequest) (*apipb.HasAncestorResponse, error) {
if len(req.Commit) != 40 {
return nil, errors.New("invalid Commit")
}
if len(req.Ancestor) != 40 {
return nil, errors.New("invalid Ancestor")
}
s.c.RLock()
defer s.c.RUnlock()
commit := s.c.GitCommit(req.Commit)
res := new(apipb.HasAncestorResponse)
if commit == nil {
// TODO: wait for it? kick off a fetch of it and then answer?
// optional?
res.UnknownCommit = true
return res, nil
}
if a := s.c.GitCommit(req.Ancestor); a != nil {
res.HasAncestor = commit.HasAncestor(a)
}
return res, nil
}