gunk-dev/the-valley

refs.go

sourcefce1c319f644main's published tip history
24.4 KiB
1package main
2
3// The refs transport: a reconciliation loop over the integration requests
4// durable in the served repository.
5//
6// It polls, deliberately. The bus is unauthenticated (bd-d853d9c), which
7// gates automated consumers, and the requests are durable in git with the
8// bus as a projection over them (architecture.md). So the controller
9// level-triggers over the request refs themselves and converges: each pass
10// recomputes the verdict for every request against the current tip, acts
11// only where the answer has changed since the last pass, and needs no
12// subscription at all. It publishes outcomes to the bus exactly as the
13// post-receive hook publishes ref updates. Consuming events arrives in a
14// later phase.
15//
16// # The request ref
17//
18// A request is a ref:
19//
20// refs/the-valley/integration-requests/<target>/<change> -> commit
21//
22// The target segment names the protected branch, so the change's target
23// stream is refs/heads/<target>; the last segment names the change. The
24// commit is the change's head, its tree is what the attestations are over,
25// and the delta is the merge base with the target's tip to that head.
26// Nothing else is encoded: a change is a diff targeting a stream
27// (ida-93e4f91), and every part of that is already in git. A request
28// whose last segment is c-<change ID> is the request of the change with a
29// record under that ID, and the records decide whether it may land at all
30// (records.go).
31
32import (
33 "the-valley/change"
34 "the-valley/integrator/verdict"
35
36 "fmt"
37 "sort"
38 "strings"
39 "time"
40)
41
42const (
43 requestPrefix = "refs/the-valley/integration-requests"
44 outcomePrefix = "refs/the-valley/integration-outcomes"
45)
46
47// request is one integration request as the refs transport found it.
48type request struct {
49 ref string
50 change string
51 target string
52 head string
53}
54
55// requests lists the pending requests, in ref order so a pass is
56// deterministic, along with the refs under the namespace that are not
57// requests at all.
58//
59// Any holder of the approve grant can write this namespace, and anyone at all
60// where a repository is served without the pre-receive hook, so a name that
61// does not parse is an ordinary thing to find there and not a reason to stop: one
62// unreadable ref must not hold up every readable one. It is reported and
63// skipped.
64func (in *integrator) requests() ([]request, []string, error) {
65 out, err := git(in.repo, "for-each-ref", "--format=%(refname) %(objectname)", requestPrefix)
66 if err != nil {
67 return nil, nil, err
68 }
69 var found []request
70 var malformed []string
71 for _, line := range strings.Split(strings.TrimSpace(out), "\n") {
72 if line == "" {
73 continue
74 }
75 ref, head, ok := strings.Cut(line, " ")
76 if !ok {
77 continue
78 }
79 rest := strings.TrimPrefix(ref, requestPrefix+"/")
80 target, change, ok := strings.Cut(rest, "/")
81 if !ok || strings.Contains(change, "/") || target == "" || change == "" {
82 malformed = append(malformed, ref)
83 continue
84 }
85 found = append(found, request{ref: ref, change: change, target: "refs/heads/" + target, head: head})
86 }
87 sort.Slice(found, func(i, j int) bool { return found[i].ref < found[j].ref })
88 sort.Strings(malformed)
89 return found, malformed, nil
90}
91
92// reconcile is one pass: judge every request against the current tip of its
93// target, and act where the answer has changed.
94//
95// The change records are read once, before any request is judged. A pass
96// that cannot read them judges nothing: which heads are versions of
97// changes that are not ready is what keeps those heads from landing. The
98// requests a withdrawn change voids are deleted before the rest are
99// judged.
100func (in *integrator) reconcile() error {
101 requests, malformed, err := in.requests()
102 if err != nil {
103 return err
104 }
105 for _, ref := range malformed {
106 fmt.Fprintf(in.out, "%s: not a request ref; one is %s/<target>/<change>. Skipped.\n", ref, requestPrefix)
107 }
108 if len(requests) == 0 {
109 return nil
110 }
111 idx, err := in.readRecords()
112 if err != nil {
113 return err
114 }
115 for _, u := range idx.unreadable {
116 fmt.Fprintf(in.out, "WARNING: %s is a change record that does not read: %s. Requests are judged as though it did not exist, so a head it names is not held back by it. The hook refuses such a record, so the repository's storage is corrupt; restore the record or delete it.\n", u.ref, u.why)
117 }
118 requests = in.voidWithdrawn(requests, idx)
119 for _, r := range requests {
120 if err := in.handle(r, idx); err != nil {
121 // One bad request must not stop the pass: the integrator is a
122 // controller, and a request it cannot judge is one request's
123 // problem.
124 fmt.Fprintf(in.out, "%s: %v\n", r.change, err)
125 }
126 }
127 return nil
128}
129
130// handle judges one request and acts on the verdict. A decision it
131// reports is timed, and its timing line follows the report and the
132// recorded outcome; a refusal said before, and so not said again, is not
133// timed again either.
134func (in *integrator) handle(r request, idx *recordIndex) error {
135 watch := newStopwatch()
136 tip, err := gitLine(in.repo, "rev-parse", "--verify", "--quiet", r.target)
137 if err != nil {
138 return fmt.Errorf("no target %s to integrate onto", r.target)
139 }
140 // Level-triggering: the verdict is a function of the request's head,
141 // the target's tip, and the evidence stored for the change, so an
142 // unchanged answer is one where none of the three has moved.
143 // Re-announcing an unchanged answer would be a retry storm; missing a
144 // moved one would strand a contributor who pushed the attestation a
145 // previous pass said was absent.
146 evidence, err := in.evidenceState()
147 if err != nil {
148 return err
149 }
150 memo := fmt.Sprintf("%s %s %s", r.head, tip, evidence)
151 last, err := in.readMemo(r)
152 if err != nil {
153 return err
154 }
155 if in.answered(last, memo) {
156 return nil
157 }
158 // From here on the request has been taken up, so whatever happens is
159 // this pass's answer to it — including a failure. Recording that is
160 // what keeps the next tick from asking the identical question.
161 done := watch.stage(stageRefusal)
162 outcome, err := in.refuse(r, idx, tip, last, memo)
163 done()
164 if err == nil && outcome == "" {
165 outcome, err = in.act(r, tip, watch)
166 }
167 if err != nil {
168 printTiming := in.timing(r, tip, failedMemo, watch)
169 memoErr := in.writeMemo(r, memo+" "+failedMemo+" "+in.now().Format(time.RFC3339))
170 printTiming()
171 if memoErr != nil {
172 return fmt.Errorf("%v (and the failure could not be recorded: %v)", err, memoErr)
173 }
174 return err
175 }
176 if last == memo+" "+string(outcome) {
177 return nil
178 }
179 printTiming := in.timing(r, tip, string(outcome), watch)
180 err = in.writeMemo(r, memo+" "+string(outcome))
181 printTiming()
182 return err
183}
184
185// refuse applies the rules that refuse a request before it is judged
186// (records.go), and reports a refusal. It reports one only when it is new:
187// a refusal is decided again on every pass, and saying the same one every
188// tick would bury it.
189func (in *integrator) refuse(r request, idx *recordIndex, tip, last, memo string) (verdict.Outcome, error) {
190 outcome, why, err := in.recordRefusal(r, idx, tip)
191 if err == nil && outcome == "" {
192 outcome, why, err = in.mergeRefusal(r, tip)
193 }
194 if err != nil {
195 return "", err
196 }
197 if outcome != "" && last != memo+" "+string(outcome) {
198 in.reportRefusal(r, tip, outcome, why)
199 }
200 // A record that does not read may name a commit this request brings,
201 // and whether it holds that commit back cannot be told. That is said
202 // with the request, whatever is decided about it.
203 if outcome == "" || last != memo+" "+string(outcome) {
204 for _, u := range in.uncheckable(r, idx, tip) {
205 fmt.Fprintf(in.out, "WARNING: %s may name a commit %s brings, and does not read, so whether it holds that commit back cannot be checked\n", u.ref, r.change)
206 }
207 }
208 return outcome, nil
209}
210
211// reportRefusal prints a refusal the way report prints a verdict.
212func (in *integrator) reportRefusal(r request, tip string, outcome verdict.Outcome, why string) {
213 fmt.Fprintf(in.out, "%s -> %s @ %s: %s\n", r.change, r.target, verdict.Short(tip), outcome)
214 fmt.Fprintf(in.out, " %s\n", why)
215 fmt.Fprintf(in.out, " no event: a refusal is not staleness, and the request stays where it is\n")
216}
217
218// failedMemo marks a memo written for a pass that could not act on its own
219// verdict, and retryAfter is how long that answer stands.
220//
221// A failure here is a function of the same three things the verdict is, so
222// the identical attempt fails identically until one of them moves — and
223// moving any of them already re-judges the request, whatever the memo says.
224// The window exists for the other kind of failure: a bus, a disk, a lock,
225// something outside the three that will be different later. Minutes rather
226// than ticks, because a controller that reports the same refusal every
227// fifteen seconds has buried the report it was making.
228const (
229 failedMemo = "failed"
230 retryAfter = 10 * time.Minute
231)
232
233// answered says whether this pass already has this request's answer, given
234// the last memo written for it. An outcome stands until the request, the
235// tip, or the evidence moves; a recorded failure stands the same way, and
236// additionally expires, so a transient one is retried without being
237// retried at tick rate. A refusal never stands: what refused it can change
238// while the three stay where they are, as when a draft is readied again,
239// so it is decided again on every pass. Nor does a voiding: a request
240// filed again at the same head is a fresh approval.
241func (in *integrator) answered(last, memo string) bool {
242 rest, ok := strings.CutPrefix(last, memo+" ")
243 if !ok {
244 return false
245 }
246 switch verdict.Outcome(rest) {
247 case refusedNotReady, refusedMerge, voidedWithdrawn:
248 return false
249 }
250 when, failed := strings.CutPrefix(rest, failedMemo+" ")
251 if !failed {
252 return true
253 }
254 at, err := time.Parse(time.RFC3339, when)
255 if err != nil {
256 return false
257 }
258 return in.now().Sub(at) < retryAfter
259}
260
261// act judges one request and does what the verdict says, returning the
262// outcome so the memo can record it.
263func (in *integrator) act(r request, tip string, watch *stopwatch) (verdict.Outcome, error) {
264 ch, snap, landed, err := in.materialize(r, tip, watch)
265 if err != nil {
266 return "", err
267 }
268 v := verdict.Decide(ch, snap)
269 in.report(r, tip, v)
270 if landed.composition != "" {
271 fmt.Fprintf(in.out, " policy %s\n", landed.composition)
272 }
273
274 switch v.Outcome {
275 case verdict.Land:
276 outcome, err := in.land(ch, v, r, tip, landed, watch)
277 if outcome != "" || err != nil {
278 if outcome == "" {
279 outcome = v.Outcome
280 }
281 return outcome, err
282 }
283 case verdict.Stale:
284 done := watch.stage(stagePublish)
285 in.publishStale(ch, v, tip)
286 done()
287 case verdict.Reject:
288 // There is no rejection event. The failure model is unified on
289 // staleness (architecture.md), and a change whose evidence is
290 // forged is not stale — so rather than stretch either event to
291 // cover it, the vocabulary stays as it is and the refusal is the
292 // integrator's own output. The request stays put; nothing about
293 // it will change on its own.
294 fmt.Fprintf(in.out, " no event: a forged attestation is not staleness, and the vocabulary has no other word\n")
295 }
296 return v.Outcome, nil
297}
298
299// landing is the commit a verdict would move the target to, and what the
300// verdict was computed under.
301type landing struct {
302 commit string // the commit that would be the target's new tip
303 digest string // the valley-tree-v1 digest of the resulting tree
304 policy string // a digest of the composed policy the verdict used
305
306 // composition is what the pass has to say about how the policy layers
307 // resolved, or empty when both were where they are configured to be.
308 composition string
309
310 // notes are the contributor's attestations as stored, by check name.
311 // The verdict does not read them; what lands countersigns them.
312 notes map[string][]byte
313}
314
315// materialize gathers everything the verdict is a function of: the applied
316// delta, the required checks, the recomputed closures, and what intervening
317// landings touched.
318func (in *integrator) materialize(r request, tip string, watch *stopwatch) (verdict.Change, verdict.Snapshot, landing, error) {
319 var land landing
320 done := watch.stage(stageCheckout)
321 wt, err := addWorktree(in.repo, tip)
322 done()
323 if err != nil {
324 return verdict.Change{}, verdict.Snapshot{}, land, err
325 }
326 defer wt.remove()
327
328 base, err := gitLine(in.repo, "merge-base", tip, r.head)
329 if err != nil {
330 return verdict.Change{}, verdict.Snapshot{}, land, fmt.Errorf("%s and %s share no history", verdict.Short(r.head), r.target)
331 }
332 done = watch.stage(stageEvidence)
333 attested, err := in.treeDigest(wt, r.head)
334 if err != nil {
335 done()
336 return verdict.Change{}, verdict.Snapshot{}, land, err
337 }
338 ch := verdict.Change{ID: r.change, Target: r.target, Base: base, Head: r.head, Attested: attested}
339 ch.Evidence, land.notes, err = in.collectEvidence(wt, r.head, attested)
340 done()
341 if err != nil {
342 return ch, verdict.Snapshot{}, land, err
343 }
344
345 // The policy is read from the integrator's own side and never from the
346 // tree being gated: the project layer from this checkout of the target
347 // tip, the floor from the instance repository's integrated tip. Both
348 // are resolved once and held for the whole pass.
349 done = watch.stage(stagePolicy)
350 pol, closePolicy, err := in.policy.open(wt)
351 if err != nil {
352 done()
353 return ch, verdict.Snapshot{}, land, err
354 }
355 defer closePolicy()
356 land.composition = pol.note
357 cat, policyDigest, err := pol.catalogue()
358 if err != nil {
359 done()
360 return ch, verdict.Snapshot{}, land, err
361 }
362 land.policy = policyDigest
363 derived, err := pol.derive(wt, base, r.head)
364 if err != nil {
365 done()
366 return ch, verdict.Snapshot{}, land, err
367 }
368 required, err := pol.required(derived, cat)
369 done()
370 if err != nil {
371 return ch, verdict.Snapshot{}, land, err
372 }
373
374 snap := verdict.Snapshot{Required: required, Touched: map[string]bool{}, Now: in.now()}
375
376 // Apply the delta. A base that is already the tip is a fast-forward:
377 // the head lands as it stands and its tree is the tree that was
378 // attested.
379 if base == tip {
380 land.commit = r.head
381 land.digest = attested
382 snap.Apply = verdict.Applied{Clean: true, Tree: attested}
383 } else {
384 done = watch.stage(stageApply)
385 tree, conflict, err := mergeDelta(in.repo, base, tip, r.head)
386 if err != nil {
387 done()
388 return ch, snap, land, err
389 }
390 if conflict != "" {
391 done()
392 snap.Apply = verdict.Applied{Clean: false, Conflict: conflict}
393 return ch, snap, land, nil
394 }
395 if land.commit, err = in.commitTree(tree, tip, r); err != nil {
396 done()
397 return ch, snap, land, err
398 }
399 land.digest, err = in.treeDigest(wt, tree)
400 done()
401 if err != nil {
402 return ch, snap, land, err
403 }
404 snap.Apply = verdict.Applied{Clean: true, Tree: land.digest}
405
406 // What intervening landings touched, in the policy's own terms:
407 // the classes the deriver matches over base..tip. Asking the
408 // deriver rather than matching globs here keeps one implementation
409 // of what a class covers.
410 done = watch.stage(stagePolicy)
411 intervening, err := pol.derive(wt, base, tip)
412 done()
413 if err != nil {
414 return ch, snap, land, err
415 }
416 snap.Touched = intervening.classes
417 }
418
419 // The closures only have to be recomputed when the tree moved: an
420 // unmoved tree presents the identical computation by construction.
421 if land.digest != attested {
422 done = watch.stage(stageClosures)
423 snap.Closures, snap.ClosureErrors = in.closures(wt, land.commit, required)
424 done()
425 }
426 return ch, snap, land, nil
427}
428
429// committerEmail is the address on the commits the integrator makes. git
430// wants an address and there is none to give: the integrator is a service,
431// not a correspondent. .invalid never resolves, which says so in the address
432// itself. Which integrator committed is carried by the name beside it.
433const committerEmail = "integrator@the-valley.invalid"
434
435// commitTree turns the merged tree into the commit that would become the
436// target's new tip. The tip is its only parent, so the ref write is a
437// fast-forward; the change's authorship is carried over from its head.
438//
439// Both identities are stated here rather than left to git. The author is the
440// asker's, because re-parenting a delta is not authoring it. The committer is
441// the integrator, under the name it signs its transfer statement with: the
442// commit and the statement about it then name the same actor. Leaving either
443// to git would ask git to guess an identity from the environment, and under
444// the unit there is nothing to guess from — which is a landing that fails for
445// a reason that has nothing to do with the change.
446func (in *integrator) commitTree(tree, tip string, r request) (string, error) {
447 message, err := git(in.repo, "log", "-1", "--format=%B", r.head)
448 if err != nil {
449 return "", err
450 }
451 author, err := git(in.repo, "log", "-1", "--format=%an%n%ae%n%aI", r.head)
452 if err != nil {
453 return "", err
454 }
455 fields := strings.Split(strings.TrimRight(author, "\n"), "\n")
456 if len(fields) != 3 {
457 return "", fmt.Errorf("cannot read the authorship of %s", verdict.Short(r.head))
458 }
459 cmd := []string{"commit-tree", tree, "-p", tip, "-m", strings.TrimRight(message, "\n")}
460 // The committer date is the author's, so that the commit id is a function
461 // of what the pass decided from — the tree, the tip, the message and the
462 // authorship — and of nothing else. A pass that dies between here and the
463 // ref write recomputes the identical commit next time round instead of
464 // leaving another unreferenced one behind. Nothing reads this date: when
465 // the landing happened is recorded, signed, in the transfer statement.
466 out, err := in.gitEnv(map[string]string{
467 "GIT_AUTHOR_NAME": fields[0],
468 "GIT_AUTHOR_EMAIL": fields[1],
469 "GIT_AUTHOR_DATE": fields[2],
470 "GIT_COMMITTER_NAME": in.signerName,
471 "GIT_COMMITTER_EMAIL": committerEmail,
472 "GIT_COMMITTER_DATE": fields[2],
473 }, cmd...)
474 return strings.TrimSpace(out), err
475}
476
477// land moves the protected ref, stores the evidence, and says so on the
478// bus. The ref write is a compare-and-swap against the tip the verdict was
479// computed over, so a request that lost a race to another lands nothing and
480// is judged again next pass against the tip that won.
481//
482// The order is the commit point's. Everything that can fail while the
483// integrator is still deciding happens first, and the ref write is the
484// commit. Composing the transfer statement — vetting it, writing it down,
485// signing it — is part of deciding: a claim the integrator cannot write
486// down is a claim it has not made, and a stream moved on a decision that
487// cannot be stated is a landing nothing records. A failure before the
488// commit point leaves the stream where it was and the request where it was,
489// which is a transaction abandoned before it committed and costs one pass
490// to redo.
491//
492// Past the commit point the landing is a fact in the stream, and what is
493// left is recording it: handing the ref move to the host to publish,
494// storing the evidence, consuming the request, and saying so on the bus.
495// None of those may be skipped because an earlier one failed, and
496// consuming the request in particular may not be reachable only through
497// something that can fail — a request left pending for a change
498// already in the stream is re-judged against an empty delta on every pass,
499// forever. So each step runs, each failure is reported, and the landing is
500// reported as having happened, because it did.
501func (in *integrator) land(ch verdict.Change, v verdict.Verdict, r request, tip string, l landing, watch *stopwatch) (verdict.Outcome, error) {
502 done := watch.stage(stageSign)
503 transfer, err := in.composeTransfer(ch, v, l.digest, l.commit, tip, l.policy)
504 if err != nil {
505 done()
506 return "", err
507 }
508 evidence, err := in.countersign(ch, v, l, transfer)
509 done()
510 if err != nil {
511 return "", err
512 }
513
514 // Judging and signing can take minutes, and a change can be unreadied
515 // or withdrawn meanwhile, or a record can come to name a commit this
516 // request brings. So every record is read again here, as the last
517 // thing before the commit point, and a refusal lands nothing. A record
518 // written between this read and the ref write is still missed: refs
519 // offer no way to make the two one step. What lands then is still the
520 // head the operator approved.
521 done = watch.stage(stageRefusal)
522 outcome, why, err := in.finalRefusal(r, tip)
523 done()
524 if err != nil || outcome != "" {
525 if outcome != "" {
526 in.reportRefusal(r, tip, outcome, why)
527 }
528 return outcome, err
529 }
530
531 // The commit point.
532 done = watch.stage(stageLand)
533 _, err = git(in.repo, "update-ref", ch.Target, l.commit, tip)
534 done()
535 if err != nil {
536 return "", fmt.Errorf("%s moved under the verdict; nothing landed: %w", ch.Target, err)
537 }
538 fmt.Fprintf(in.out, " landed %s %s -> %s\n", ch.Target, verdict.Short(tip), verdict.Short(l.commit))
539 done = watch.stage(stageRecord)
540 in.queueRefUpdate(ch.Target, tip, l.commit)
541
542 var unrecorded []string
543 refs, err := in.store(evidence)
544 if err != nil {
545 unrecorded = append(unrecorded, fmt.Sprintf("the evidence was not stored (%v)", err))
546 }
547 for _, ref := range refs {
548 fmt.Fprintf(in.out, " evidence %s\n", ref)
549 }
550 // The request is consumed only if it still names the head that landed.
551 // A second approval can replace it while this pass works — the asker's
552 // write is leased against what it read, and nothing stops it reading
553 // the request this pass is about to land — and a delete that did not
554 // compare would take the new request with the old one. A request that
555 // moved is a new request, and it stands for the next pass.
556 if _, err := git(in.repo, "update-ref", "-d", r.ref, r.head); err != nil {
557 if now, found := gitTry(in.repo, "rev-parse", "--verify", "--quiet", r.ref); found && now != r.head {
558 fmt.Fprintf(in.out, " request %s moved to %s while %s landed; it stands for the next pass\n",
559 r.ref, verdict.Short(now), verdict.Short(r.head))
560 } else {
561 unrecorded = append(unrecorded, fmt.Sprintf("the request ref %s was not consumed (%v)", r.ref, err))
562 }
563 }
564 done()
565 // The bus comes last. Everything above is the landing's own record; an
566 // event is a best-effort notice of it, and a bus that fails or hangs
567 // must not leave any of that record undone.
568 done = watch.stage(stagePublish)
569 in.publishRefUpdated(ch.Target, tip, l.commit)
570 in.publishLanded(ch, v, tip, l.commit)
571 done()
572 if len(unrecorded) > 0 {
573 return "", fmt.Errorf("%s landed as %s and the landing is not fully recorded: %s",
574 ch.ID, verdict.Short(l.commit), strings.Join(unrecorded, "; "))
575 }
576 return "", nil
577}
578
579// report prints the verdict, per check, in the order it was judged.
580func (in *integrator) report(r request, tip string, v verdict.Verdict) {
581 fmt.Fprintf(in.out, "%s -> %s @ %s: %s\n", r.change, r.target, verdict.Short(tip), v.Outcome)
582 fmt.Fprintf(in.out, " %s\n", v.Reason)
583 for _, cv := range v.Checks {
584 if cv.Transferred {
585 fmt.Fprintf(in.out, " check %-24s transferred (%s)\n", cv.Name, cv.Rule)
586 continue
587 }
588 fmt.Fprintf(in.out, " check %-24s %s\n", cv.Name, cv.Reason)
589 }
590}
591
592// The memo is the level-trigger's memory: what this integrator last decided
593// about a request, keyed by the request. It is durable in git like
594// everything else the transport reads, so a restarted controller does not
595// re-announce a judgement it has already made.
596func (in *integrator) memoRef(r request) string {
597 return outcomePrefix + "/" + strings.TrimPrefix(r.ref, requestPrefix+"/")
598}
599
600func (in *integrator) readMemo(r request) (string, error) {
601 out, ok := gitTry(in.repo, "cat-file", "blob", in.memoRef(r))
602 if !ok {
603 return "", nil
604 }
605 return strings.TrimSpace(out), nil
606}
607
608func (in *integrator) writeMemo(r request, value string) error {
609 blob, err := in.writeBlob([]byte(value + "\n"))
610 if err != nil {
611 return err
612 }
613 _, err = git(in.repo, "update-ref", in.memoRef(r), blob)
614 return err
615}
616
617// evidenceState digests the attestation namespace: every ref under it and
618// the object it points at, as change.EvidenceFingerprint reads them.
619// Attestation refs are create-only, so this moves exactly when evidence
620// arrives.
621//
622// It is deliberately the whole namespace rather than the refs for one
623// change's subject digest, which would take a checkout to compute and would
624// have to be recomputed before the memo could rule the work out. So an
625// attestation for one change re-judges every pending request. That is the
626// conservative direction — a pass that runs and changes nothing costs a
627// pass; a verdict never revisited strands a change — and it is bounded by
628// the number of requests pending.
629func (in *integrator) evidenceState() (string, error) {
630 out, err := git(in.repo, "for-each-ref", "--format=%(refname) %(objectname)", attestationPrefix)
631 if err != nil {
632 return "", err
633 }
634 var lines []string
635 if out = strings.TrimSuffix(out, "\n"); out != "" {
636 lines = strings.Split(out, "\n")
637 }
638 return change.EvidenceFingerprint(lines), nil
639}
640
641func (in *integrator) now() time.Time {
642 if !in.clock.IsZero() {
643 return in.clock
644 }
645 return time.Now().UTC()
646}