maintner: start of git polling (just proto and maintner plumbing, no git)

This is just the start of git commit metadata importing, but without
any of the git-specific bits. This is just the proto changes and the
changes to wire up the guts with maintner. The guts will come in a
following CL.

Change-Id: I321590dc30ba5c62346911526fed647fc0d0b3ad
Reviewed-on: https://go-review.googlesource.com/37938
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/maintner/maintner.go b/maintner/maintner.go
index 993c128..1b26cfa 100644
--- a/maintner/maintner.go
+++ b/maintner/maintner.go
@@ -16,6 +16,7 @@
 	"fmt"
 	"io/ioutil"
 	"log"
+	"regexp"
 	"strings"
 	"sync"
 	"time"
@@ -36,10 +37,11 @@
 type Corpus struct {
 	MutationLogger MutationLogger
 
-	mu           sync.RWMutex
-	githubIssues map[githubRepo]map[int32]*githubIssue // repo -> num -> issue
-	githubUsers  map[int64]*githubUser
-	githubRepos  []repoObj
+	mu               sync.RWMutex
+	githubIssues     map[githubRepo]map[int32]*githubIssue // repo -> num -> issue
+	githubUsers      map[int64]*githubUser
+	pollGithubIssues []polledGithubIssues
+	pollGitDirs      []polledGitCommits
 	// If true, log new commits
 	shouldLog bool
 	debug     bool
@@ -47,16 +49,20 @@
 	// TODO
 }
 
-type repoObj struct {
+type polledGithubIssues struct {
 	name      githubRepo
 	tokenFile string
 }
 
+type polledGitCommits struct {
+	repo *maintpb.GitRepo
+	dir  string
+}
+
 func NewCorpus(logger MutationLogger) *Corpus {
 	return &Corpus{
 		githubIssues:   make(map[githubRepo]map[int32]*githubIssue),
 		githubUsers:    make(map[int64]*githubUser),
-		githubRepos:    []repoObj{},
 		MutationLogger: logger,
 	}
 }
@@ -81,12 +87,34 @@
 func (c *Corpus) AddGithub(owner, repo, tokenFile string) {
 	c.mu.Lock()
 	defer c.mu.Unlock()
-	c.githubRepos = append(c.githubRepos, repoObj{
+	c.pollGithubIssues = append(c.pollGithubIssues, polledGithubIssues{
 		name:      githubRepo(owner + "/" + repo),
 		tokenFile: tokenFile,
 	})
 }
 
+// gerritProjNameRx is the pattern describing a Gerrit project name.
+// TODO: figure out if this is accurate.
+var gerritProjNameRx = regexp.MustCompile(`^[a-z0-9]+[a-z0-9\-\_]*$`)
+
+// AddGoGitRepo registers a git directory to have its metadata slurped into the corpus.
+// The goRepo is a name like "go" or "net". The dir is a path on disk.
+//
+// TODO(bradfitz): this whole interface is temporary. Make this
+// support any git repo and make this (optionally?) use the gitmirror
+// service later instead of a separate copy on disk.
+func (c *Corpus) AddGoGitRepo(goRepo, dir string) {
+	if !gerritProjNameRx.MatchString(goRepo) {
+		panic(fmt.Sprintf("bogus goRepo value %q", goRepo))
+	}
+	c.mu.Lock()
+	defer c.mu.Unlock()
+	c.pollGitDirs = append(c.pollGitDirs, polledGitCommits{
+		repo: &maintpb.GitRepo{GoRepo: goRepo},
+		dir:  dir,
+	})
+}
+
 // githubRepo is a github org & repo, lowercase, joined by a '/',
 // such as "golang/go".
 type githubRepo string
@@ -509,15 +537,28 @@
 // Poll checks for new changes on all repositories being tracked by the Corpus.
 func (c *Corpus) Poll(ctx context.Context) error {
 	group, ctx := errgroup.WithContext(ctx)
-	for _, rp := range c.githubRepos {
+	for _, rp := range c.pollGithubIssues {
 		rp := rp
 		group.Go(func() error {
 			return c.PollGithubLoop(ctx, rp.name, rp.tokenFile)
 		})
 	}
+	for _, rp := range c.pollGitDirs {
+		rp := rp
+		group.Go(func() error {
+			return c.PollGitCommits(ctx, rp)
+		})
+	}
 	return group.Wait()
 }
 
+// PollGithubCommits polls for git commits in a directory.
+func (c *Corpus) PollGitCommits(ctx context.Context, conf polledGitCommits) error {
+	log.Printf("TODO: poll %v from %v", conf.repo, conf.dir)
+	select {} // TODO(bradfitz): actuall poll
+	return nil
+}
+
 // PollGithubLoop checks for new changes on a single Github repository and
 // updates the Corpus with any changes.
 func (c *Corpus) PollGithubLoop(ctx context.Context, rp githubRepo, tokenFile string) error {
diff --git a/maintner/maintnerd/maintnerd.go b/maintner/maintnerd/maintnerd.go
index 72fb9ea..a959620 100644
--- a/maintner/maintnerd/maintnerd.go
+++ b/maintner/maintnerd/maintnerd.go
@@ -13,6 +13,8 @@
 	"net"
 	"os"
 	"path"
+	"path/filepath"
+	"runtime"
 	"strings"
 
 	"golang.org/x/build/maintner"
@@ -32,26 +34,39 @@
 
 var (
 	listen      = flag.String("listen", ":6343", "listen address")
-	watchGithub = flag.String("watch-github", "", "Comma separated list of owner/repo pairs to slurp")
+	watchGithub = flag.String("watch-github", "", "Comma-separated list of owner/repo pairs to slurp")
+	watchGoGit  = flag.Bool("watch-go-git", false, "Watch Go's main git repo.")
 	dataDir     = flag.String("data-dir", "", "Local directory to write protobuf files to")
 	debug       = flag.Bool("debug", false, "Print debug logging information")
 )
 
 func main() {
 	flag.Parse()
-	pairs := strings.Split(*watchGithub, ",")
+	if *dataDir == "" {
+		*dataDir = filepath.Join(os.Getenv("HOME"), "var", "maintnerd")
+		if err := os.MkdirAll(*dataDir, 0755); err != nil {
+			log.Fatal(err)
+		}
+		log.Printf("Storing data in implicit directory %s", *dataDir)
+	}
 	// TODO switch based on flags, for now only local file sync works
 	logger := maintner.NewDiskMutationLogger(*dataDir)
 	corpus := maintner.NewCorpus(logger)
 	if *debug {
 		corpus.SetDebug()
 	}
-	for _, pair := range pairs {
-		splits := strings.SplitN(pair, "/", 2)
-		if len(splits) != 2 || splits[1] == "" {
-			log.Fatalf("Invalid github repo: %s. Should be 'owner/repo,owner2/repo2'", pair)
+	if *watchGithub != "" {
+		for _, pair := range strings.Split(*watchGithub, ",") {
+			splits := strings.SplitN(pair, "/", 2)
+			if len(splits) != 2 || splits[1] == "" {
+				log.Fatalf("Invalid github repo: %s. Should be 'owner/repo,owner2/repo2'", pair)
+			}
+			corpus.AddGithub(splits[0], splits[1], path.Join(os.Getenv("HOME"), ".github-issue-token"))
 		}
-		corpus.AddGithub(splits[0], splits[1], path.Join(os.Getenv("HOME"), ".github-issue-token"))
+	}
+	if *watchGoGit {
+		// Assumes GOROOT is a git checkout. Good enough for now for development.
+		corpus.AddGoGitRepo("go", runtime.GOROOT())
 	}
 	ln, err := net.Listen("tcp", *listen)
 	if err != nil {
@@ -71,4 +86,5 @@
 	if err := corpus.Poll(ctx); err != nil {
 		log.Fatal(err)
 	}
+	log.Fatalf("Exiting.")
 }
diff --git a/maintner/maintpb/maintner.pb.go b/maintner/maintpb/maintner.pb.go
index aff87fd..e8c21bf 100644
--- a/maintner/maintpb/maintner.pb.go
+++ b/maintner/maintpb/maintner.pb.go
@@ -13,6 +13,11 @@
 	GithubIssueMutation
 	GithubIssueCommentMutation
 	GithubUser
+	GitMutation
+	GitRepo
+	GitCommit
+	GitDiffTree
+	GitDiffTreeFile
 */
 package maintpb
 
@@ -34,6 +39,7 @@
 
 type Mutation struct {
 	GithubIssue *GithubIssueMutation `protobuf:"bytes,1,opt,name=github_issue,json=githubIssue" json:"github_issue,omitempty"`
+	Git         *GitMutation         `protobuf:"bytes,2,opt,name=git" json:"git,omitempty"`
 }
 
 func (m *Mutation) Reset()                    { *m = Mutation{} }
@@ -48,6 +54,13 @@
 	return nil
 }
 
+func (m *Mutation) GetGit() *GitMutation {
+	if m != nil {
+		return m.Git
+	}
+	return nil
+}
+
 type GithubIssueMutation struct {
 	Owner            string                        `protobuf:"bytes,1,opt,name=owner" json:"owner,omitempty"`
 	Repo             string                        `protobuf:"bytes,2,opt,name=repo" json:"repo,omitempty"`
@@ -224,41 +237,192 @@
 	return ""
 }
 
+type GitMutation struct {
+	Repo *GitRepo `protobuf:"bytes,1,opt,name=repo" json:"repo,omitempty"`
+	// commit adds a commit, or adds new information to a commit if fields
+	// are added in the future.
+	Commit *GitCommit `protobuf:"bytes,2,opt,name=commit" json:"commit,omitempty"`
+}
+
+func (m *GitMutation) Reset()                    { *m = GitMutation{} }
+func (m *GitMutation) String() string            { return proto.CompactTextString(m) }
+func (*GitMutation) ProtoMessage()               {}
+func (*GitMutation) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
+
+func (m *GitMutation) GetRepo() *GitRepo {
+	if m != nil {
+		return m.Repo
+	}
+	return nil
+}
+
+func (m *GitMutation) GetCommit() *GitCommit {
+	if m != nil {
+		return m.Commit
+	}
+	return nil
+}
+
+// GitRepo identifies a git repo being mutated.
+type GitRepo struct {
+	// If go_repo is set, it identifies a go.googlesource.com/<go_repo> repo.
+	GoRepo string `protobuf:"bytes,1,opt,name=go_repo,json=goRepo" json:"go_repo,omitempty"`
+}
+
+func (m *GitRepo) Reset()                    { *m = GitRepo{} }
+func (m *GitRepo) String() string            { return proto.CompactTextString(m) }
+func (*GitRepo) ProtoMessage()               {}
+func (*GitRepo) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
+
+func (m *GitRepo) GetGoRepo() string {
+	if m != nil {
+		return m.GoRepo
+	}
+	return ""
+}
+
+type GitCommit struct {
+	Sha1 string `protobuf:"bytes,1,opt,name=sha1" json:"sha1,omitempty"`
+	// raw is the "git cat-file commit $sha1" output.
+	Raw      []byte       `protobuf:"bytes,2,opt,name=raw,proto3" json:"raw,omitempty"`
+	DiffTree *GitDiffTree `protobuf:"bytes,3,opt,name=diff_tree,json=diffTree" json:"diff_tree,omitempty"`
+}
+
+func (m *GitCommit) Reset()                    { *m = GitCommit{} }
+func (m *GitCommit) String() string            { return proto.CompactTextString(m) }
+func (*GitCommit) ProtoMessage()               {}
+func (*GitCommit) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
+
+func (m *GitCommit) GetSha1() string {
+	if m != nil {
+		return m.Sha1
+	}
+	return ""
+}
+
+func (m *GitCommit) GetRaw() []byte {
+	if m != nil {
+		return m.Raw
+	}
+	return nil
+}
+
+func (m *GitCommit) GetDiffTree() *GitDiffTree {
+	if m != nil {
+		return m.DiffTree
+	}
+	return nil
+}
+
+// git diff-tree --numstat oldtree newtree
+type GitDiffTree struct {
+	File []*GitDiffTreeFile `protobuf:"bytes,1,rep,name=file" json:"file,omitempty"`
+}
+
+func (m *GitDiffTree) Reset()                    { *m = GitDiffTree{} }
+func (m *GitDiffTree) String() string            { return proto.CompactTextString(m) }
+func (*GitDiffTree) ProtoMessage()               {}
+func (*GitDiffTree) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
+
+func (m *GitDiffTree) GetFile() []*GitDiffTreeFile {
+	if m != nil {
+		return m.File
+	}
+	return nil
+}
+
+// GitDiffTreeFile represents one line of `git diff-tree --numstat` output.
+type GitDiffTreeFile struct {
+	File    string `protobuf:"bytes,1,opt,name=file" json:"file,omitempty"`
+	Added   int64  `protobuf:"varint,2,opt,name=added" json:"added,omitempty"`
+	Deleted int64  `protobuf:"varint,3,opt,name=deleted" json:"deleted,omitempty"`
+	Binary  bool   `protobuf:"varint,4,opt,name=binary" json:"binary,omitempty"`
+}
+
+func (m *GitDiffTreeFile) Reset()                    { *m = GitDiffTreeFile{} }
+func (m *GitDiffTreeFile) String() string            { return proto.CompactTextString(m) }
+func (*GitDiffTreeFile) ProtoMessage()               {}
+func (*GitDiffTreeFile) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} }
+
+func (m *GitDiffTreeFile) GetFile() string {
+	if m != nil {
+		return m.File
+	}
+	return ""
+}
+
+func (m *GitDiffTreeFile) GetAdded() int64 {
+	if m != nil {
+		return m.Added
+	}
+	return 0
+}
+
+func (m *GitDiffTreeFile) GetDeleted() int64 {
+	if m != nil {
+		return m.Deleted
+	}
+	return 0
+}
+
+func (m *GitDiffTreeFile) GetBinary() bool {
+	if m != nil {
+		return m.Binary
+	}
+	return false
+}
+
 func init() {
 	proto.RegisterType((*Mutation)(nil), "maintpb.Mutation")
 	proto.RegisterType((*GithubIssueMutation)(nil), "maintpb.GithubIssueMutation")
 	proto.RegisterType((*GithubIssueCommentMutation)(nil), "maintpb.GithubIssueCommentMutation")
 	proto.RegisterType((*GithubUser)(nil), "maintpb.GithubUser")
+	proto.RegisterType((*GitMutation)(nil), "maintpb.GitMutation")
+	proto.RegisterType((*GitRepo)(nil), "maintpb.GitRepo")
+	proto.RegisterType((*GitCommit)(nil), "maintpb.GitCommit")
+	proto.RegisterType((*GitDiffTree)(nil), "maintpb.GitDiffTree")
+	proto.RegisterType((*GitDiffTreeFile)(nil), "maintpb.GitDiffTreeFile")
 }
 
 func init() { proto.RegisterFile("maintner.proto", fileDescriptor0) }
 
 var fileDescriptor0 = []byte{
-	// 406 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x4d, 0xab, 0xd3, 0x40,
-	0x14, 0x25, 0x5f, 0xcd, 0xeb, 0xed, 0xe3, 0xa1, 0xf3, 0x1e, 0x32, 0x14, 0x17, 0x21, 0x2e, 0x0c,
-	0x08, 0x09, 0x56, 0x77, 0x22, 0x22, 0x2e, 0x44, 0xc4, 0x4d, 0xd0, 0x75, 0x49, 0x9a, 0xeb, 0x38,
-	0x90, 0xcc, 0x84, 0x99, 0x09, 0xd2, 0x1f, 0xe8, 0x4f, 0xf0, 0xff, 0x48, 0x26, 0x49, 0x53, 0x6c,
-	0x4b, 0xc5, 0xdd, 0x3d, 0x73, 0xcf, 0xb9, 0xb9, 0xf7, 0x9c, 0xc0, 0x5d, 0x53, 0x70, 0x61, 0x04,
-	0xaa, 0xb4, 0x55, 0xd2, 0x48, 0x12, 0x5a, 0xdc, 0x96, 0xeb, 0x37, 0x8c, 0x9b, 0x1f, 0x5d, 0x99,
-	0xee, 0x64, 0x93, 0x31, 0x59, 0x17, 0x82, 0x65, 0x96, 0x51, 0x76, 0xdf, 0xb3, 0xd6, 0xec, 0x5b,
-	0xd4, 0x99, 0xe1, 0x0d, 0x6a, 0x53, 0x34, 0xed, 0x5c, 0x0d, 0x53, 0xe2, 0xcf, 0x70, 0xf3, 0xa5,
-	0x33, 0x85, 0xe1, 0x52, 0x90, 0x77, 0x70, 0x3b, 0x8c, 0xda, 0x72, 0xad, 0x3b, 0xa4, 0x4e, 0xe4,
-	0x24, 0xab, 0xcd, 0xd3, 0x74, 0xfc, 0x50, 0xfa, 0xd1, 0x36, 0x3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x7e, 0x18, 0x28, 0x87, 0x2c, 0x27, 0x4d, 0xfc, 0xdb, 0x81, 0xf5, 0x65, 0xde, 0x18, 0x86, 0x73,
-	0x12, 0x86, 0x7b, 0x2d, 0x8c, 0xe9, 0x00, 0xef, 0xe8, 0x80, 0x23, 0x03, 0xfd, 0xff, 0x32, 0x30,
-	0xf8, 0x67, 0x03, 0xe3, 0x0d, 0xc0, 0xbc, 0xd3, 0xc9, 0x19, 0x0f, 0x10, 0xd4, 0x92, 0x71, 0x31,
-	0xfe, 0x90, 0x03, 0x28, 0x17, 0x76, 0xe0, 0xab, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcc, 0x6c,
-	0xf2, 0xa1, 0x7f, 0x03, 0x00, 0x00,
+	// 588 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcd, 0x6e, 0xd3, 0x40,
+	0x10, 0x56, 0xe2, 0x24, 0x4e, 0x26, 0x55, 0x29, 0xdb, 0x0a, 0x56, 0x15, 0x87, 0xc8, 0x20, 0x88,
+	0x00, 0x39, 0x6a, 0xe1, 0x56, 0x21, 0x84, 0x8a, 0x40, 0x1c, 0xb8, 0xac, 0xca, 0x39, 0xb2, 0xbb,
+	0x13, 0x77, 0x25, 0xdb, 0x6b, 0xad, 0xd7, 0xaa, 0xfa, 0x80, 0x3c, 0x02, 0xef, 0x83, 0x76, 0xbc,
+	0x4e, 0xac, 0xfe, 0xa8, 0x88, 0xdb, 0x8c, 0xe7, 0xfb, 0x66, 0x67, 0xbe, 0x99, 0x31, 0xec, 0x17,
+	0x89, 0x2a, 0x6d, 0x89, 0x26, 0xae, 0x8c, 0xb6, 0x9a, 0x85, 0xe4, 0x57, 0xe9, 0xf1, 0x59, 0xa6,
+	0xec, 0x55, 0x93, 0xc6, 0x97, 0xba, 0x58, 0x65, 0x3a, 0x4f, 0xca, 0x6c, 0x45, 0x88, 0xb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, 0x01, 0x04, 0x26, 0xb9, 0xa6, 0xd7, 0xf6,
+	0x84, 0x33, 0xdd, 0xe2, 0x4b, 0xb5, 0xd9, 0xac, 0xad, 0x41, 0x24, 0xc1, 0x6f, 0x5d, 0xee, 0x57,
+	0xb5, 0xd9, 0x5c, 0x18, 0x44, 0x31, 0x95, 0xde, 0x8a, 0xce, 0xa8, 0xd5, 0x2e, 0xc0, 0xde, 0xc3,
+	0x68, 0xa3, 0x72, 0xf7, 0xbb, 0x70, 0x1b, 0xc4, 0xef, 0x23, 0x7f, 0x53, 0x39, 0x0a, 0x42, 0x45,
+	0x05, 0x3c, 0xb9, 0x15, 0x70, 0x85, 0xfa, 0x04, 0x54, 0xa8, 0xb3, 0x9d, 0xc8, 0x89, 0x94, 0x28,
+	0xa9, 0xd4, 0x40, 0xb4, 0x0e, 0xe3, 0x10, 0xfa, 0xcb, 0xa2, 0x52, 0x03, 0xd1, 0xb9, 0xee, 0x87,
+	0x90, 0xaa, 0x32, 0x31, 0x37, 0xb4, 0x1d, 0x53, 0xe1, 0xbd, 0x74, 0x42, 0x73, 0xfe, 0xf0, 0x37,
+	0x00, 0x00, 0xff, 0xff, 0x24, 0xc4, 0x05, 0x93, 0x3e, 0x05, 0x00, 0x00,
 }
diff --git a/maintner/maintpb/maintner.proto b/maintner/maintpb/maintner.proto
index a4dc5e5..774ae8f 100644
--- a/maintner/maintpb/maintner.proto
+++ b/maintner/maintpb/maintner.proto
@@ -11,6 +11,7 @@
 
 message Mutation {
   GithubIssueMutation github_issue = 1;
+  GitMutation git = 2;
 }
 
 message GithubIssueMutation {
@@ -42,3 +43,41 @@
   int64 id = 1;
   string login = 2;
 }
+
+message GitMutation {
+  GitRepo repo = 1;
+
+  // commit adds a commit, or adds new information to a commit if fields
+  // are added in the future.
+  GitCommit commit = 2;
+}
+
+// GitRepo identifies a git repo being mutated.
+message GitRepo {
+  // If go_repo is set, it identifies a go.googlesource.com/<go_repo> repo.
+  string go_repo = 1;
+
+  // TODO: code.googlesource.com and github repos later.
+}
+
+message GitCommit {
+  string sha1 = 1; // the full lowercase 40-hex-byte sha1 sum
+
+  // raw is the "git cat-file commit $sha1" output.
+  bytes raw = 2;
+
+  GitDiffTree diff_tree = 3;
+}
+
+// git diff-tree --numstat oldtree newtree
+message GitDiffTree {
+  repeated GitDiffTreeFile file = 1;
+}
+
+// GitDiffTreeFile represents one line of `git diff-tree --numstat` output.
+message GitDiffTreeFile {
+  string file = 1;
+  int64  added = 2;
+  int64  deleted = 3;
+  bool   binary = 4;
+}