gunk-dev/the-valley

refs.go

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