cmd/coordinator: give scheduler max commit date between go & x/repo commit

When testing, say, x/foo repos against master, we need to rebuild all
the x/repos whenever there's a new commit to master. For scheduling
purposes, the date that should be considered is the max of either the
x/foo commit time or the master commit time.

Change-Id: Ie8fb5f74cc5a14e5b8f7d043ddbf660248c978a6
Reviewed-on: https://go-review.googlesource.com/c/build/+/208438
Reviewed-by: Bryan C. Mills <bcmills@google.com>
diff --git a/cmd/coordinator/coordinator.go b/cmd/coordinator/coordinator.go
index d067c4e..9a54578 100644
--- a/cmd/coordinator/coordinator.go
+++ b/cmd/coordinator/coordinator.go
@@ -360,8 +360,13 @@
 var addWorkTestHook func(buildgo.BuilderRev, *commitDetail)
 
 type commitDetail struct {
+	// CommitTime is the greater of 1 or 2 possible git committer
+	// times: the commit time of the associated BuilderRev.Rev
+	// (for the BuilderRev also passed to addWorkDetail) or
+	// BuilderRev.SubRev (if not empty).
 	CommitTime string // in time.RFC3339 format
-	Branch     string
+
+	Branch string
 }
 
 func addWork(work buildgo.BuilderRev) {
@@ -889,12 +894,16 @@
 	commitBranch := make(map[string]string) // git rev => "master"
 
 	add := func(br buildgo.BuilderRev) {
-		rev := br.SubRev
-		if br.SubRev == "" {
-			rev = br.Rev
+		rev := br.Rev
+		ct := commitTime[br.Rev]
+		if br.SubRev != "" {
+			rev = br.SubRev
+			if t := commitTime[rev]; t > ct {
+				ct = t
+			}
 		}
 		addWorkDetail(br, &commitDetail{
-			CommitTime: commitTime[rev],
+			CommitTime: ct,
 			Branch:     commitBranch[rev],
 		})
 	}
@@ -3430,7 +3439,7 @@
 	conf       *dashboard.BuildConfig
 	startTime  time.Time // actually time of newBuild (~same thing)
 	trySet     *trySet   // or nil
-	commitTime time.Time // non-zero for post-submit builders
+	commitTime time.Time // non-zero for post-submit builders; max of Rev & SubRev's committer time
 	branch     string    // non-empty for post-submit work
 
 	onceInitHelpers sync.Once // guards call of onceInitHelpersFunc
diff --git a/cmd/coordinator/sched.go b/cmd/coordinator/sched.go
index f66e0e7..314f891 100644
--- a/cmd/coordinator/sched.go
+++ b/cmd/coordinator/sched.go
@@ -327,9 +327,14 @@
 	IsGomote           bool
 	IsTry              bool
 	IsHelper           bool
-	CommitTime         time.Time
 	Branch             string
 
+	// CommitTime is the latest commit date of the relevant repos
+	// that make up the work being tested. (For example, x/foo
+	// being tested against master can have either x/foo commit
+	// being newer, or master being newer).
+	CommitTime time.Time
+
 	// The following unexported fields are set by the Scheduler in
 	// Scheduler.GetBuildlet.