gunk-dev/the-valley

list.go

source61364523a8d7main's published tip history
22.4 KiB
1// valley changes: every change, across every repository a host serves,
2// as valley-changes/v1. docs/architecture.md documents the object, and
3// klaus reads it, so a change to any field's name or meaning is a new
4// schema version.
5//
6// Without --all it lists the current repository. With --all it lists every
7// project the serving host publishes at refs/the-valley/projects in its
8// instance repository. The instance is found at policy/valley on main's
9// integrated tip, never in a checked-out or pushed tree, and each
10// project's URL is the instance's with its last path segment replaced, so
11// the transport, user and host are kept. A repository other than the
12// current one is read through a clone this command keeps under the user's
13// cache directory.
14
15package main
16
17import (
18 "bytes"
19 "crypto/sha256"
20 "encoding/hex"
21 "encoding/json"
22 "errors"
23 "fmt"
24 "io"
25 "os"
26 "path/filepath"
27 "regexp"
28 "sort"
29 "strings"
30 "unicode/utf8"
31
32 "the-valley/change"
33)
34
35const (
36 changesSchema = "valley-changes/v1"
37 pendingSchema = "valley-pending/v1"
38
39 projectsRef = "refs/the-valley/projects"
40 valleyPointer = "policy/valley"
41 instanceLayer = "policy/instance"
42)
43
44// The valley-changes/v1 object.
45type jsonChanges struct {
46 Schema string `json:"schema"`
47 Host string `json:"host"`
48 Repos []jsonRepo `json:"repos"`
49}
50
51type jsonRepo struct {
52 Repo string `json:"repo"`
53 URL string `json:"url"`
54 Error *string `json:"error"`
55 Changes []jsonChange `json:"changes"`
56 // Drafts is valley-pending/v1's alone: valley-changes/v1 lists a draft
57 // among the changes, with its state.
58 Drafts *[]jsonChange `json:"drafts,omitempty"`
59 Branches []jsonBranch `json:"branches"`
60}
61
62type jsonChange struct {
63 ChangeID string `json:"change_id"`
64 Handle string `json:"handle"`
65 Target string `json:"target"`
66 Owner string `json:"owner"`
67 State string `json:"state"`
68 Record string `json:"record"`
69 Seq int `json:"seq"`
70 Active int `json:"active"`
71 Versions []jsonVersion `json:"versions"`
72 Includes []string `json:"includes"`
73 Restack *jsonRestack `json:"restack"`
74 // Knots lists the knots in the project's plan graph that link the
75 // change, active knots first (does.go).
76 Knots []knotRef `json:"knots"`
77}
78
79type jsonVersion struct {
80 N int `json:"n"`
81 Head string `json:"head"`
82 Title string `json:"title"`
83 Branch string `json:"branch"`
84 Uploader string `json:"uploader"`
85 Landing string `json:"landing"`
86 LandedCommit *string `json:"landed_commit"`
87 Request *jsonRequest `json:"request"`
88 Outcome *versionOutcome `json:"outcome"`
89}
90
91// versionOutcome is an outcome record about a version. Its head is the
92// version's head; its tip is given only when it is an object ID.
93type versionOutcome struct {
94 Decision string `json:"decision"`
95 Head string `json:"head"`
96 Tip *string `json:"tip"`
97}
98
99type jsonBranch struct {
100 Branch string `json:"branch"`
101 Head string `json:"head"`
102}
103
104// listing holds the flags parsed for changes or pending. verbose warns on
105// stderr when a repository's plan graph is missing or unreadable.
106type listing struct {
107 asJSON, all, checks, verbose bool
108 repo string
109}
110
111func parseListing(verb string, args []string, checks bool) (listing, error) {
112 var l listing
113 for i := 0; i < len(args); i++ {
114 switch a := args[i]; {
115 case a == "--json":
116 l.asJSON = true
117 case a == "--all":
118 l.all = true
119 case a == "--checks" && checks:
120 l.checks = true
121 case a == "-v":
122 l.verbose = true
123 case a == "--repo" && i+1 < len(args):
124 i++
125 l.repo = args[i]
126 case strings.HasPrefix(a, "--repo="):
127 l.repo = strings.TrimPrefix(a, "--repo=")
128 default:
129 return l, failure(fmt.Sprintf("%s does not take %s", verb, a))
130 }
131 }
132 if l.repo != "" && !change.ValidPrincipal(l.repo) {
133 return l, failure(fmt.Sprintf("--repo %s: not a project name", l.repo))
134 }
135 return l, nil
136}
137
138// source is one repository to list: its name, its URL, and where it is
139// read, or why it could not be.
140type source struct {
141 name, url string
142 g git
143 err error
144}
145
146// sources are the repositories a listing covers, in name order, and the
147// host they are served from.
148func sources(g git, l listing, stderr io.Writer) ([]source, string, error) {
149 if !g.succeeds(true, "rev-parse", "--git-dir") {
150 return nil, "", failure("not a git repository")
151 }
152 originURL, err := g.output(true, "remote", "get-url", "origin")
153 if err != nil {
154 return nil, "", failure("this repository has no origin to read")
155 }
156 here := source{name: project(g), url: originURL, g: g}
157 if (!l.all && l.repo == "") || l.repo == here.name {
158 return []source{here}, hostOf(originURL), nil
159 }
160 instance, names, err := discover(g)
161 if err != nil && (l.repo == "" || instance == "") {
162 if l.repo != "" {
163 return nil, "", failure(fmt.Sprintf("cannot find %s: discovery is unavailable: %v", l.repo, err))
164 }
165 fmt.Fprintf(stderr, "valley: discovery is unavailable: %v; listing %s only\n", err, here.name)
166 return []source{here}, hostOf(originURL), nil
167 }
168 if l.repo != "" {
169 if names != nil && !contains(names, l.repo) {
170 return nil, "", failure(fmt.Sprintf("the host lists no project %s at %s", l.repo, projectsRef))
171 }
172 names = []string{l.repo}
173 }
174 var list []source
175 for _, name := range names {
176 if name == here.name {
177 list = append(list, here)
178 continue
179 }
180 url, err := projectURL(instance, name)
181 s := source{name: name, url: url, err: err}
182 if err == nil {
183 s.g, s.err = cacheRepo(g, url, name)
184 }
185 list = append(list, s)
186 }
187 return list, hostOf(instance), nil
188}
189
190func contains(list []string, s string) bool {
191 for _, x := range list {
192 if x == s {
193 return true
194 }
195 }
196 return false
197}
198
199// discover finds the serving host's instance repository and the projects
200// it publishes. The instance is named at policy/valley on main's tip on
201// origin, which is read fresh; a repository whose main carries
202// policy/instance is its own instance. On an error the instance is still
203// returned when it was found, with names nil.
204func discover(g git) (instance string, names []string, err error) {
205 tip, err := remoteRef(g, "origin", "refs/heads/"+recordTarget)
206 if err != nil {
207 return "", nil, errors.New("could not read origin")
208 }
209 if tip == "" {
210 return "", nil, errors.New("origin has no main branch to read policy/valley from")
211 }
212 if err := fetch(g, tip); err != nil {
213 return "", nil, err
214 }
215 if pointer, err := g.output(true, "cat-file", "blob", tip+":"+valleyPointer); err == nil {
216 instance = pointerURL(pointer)
217 if instance == "" {
218 return "", nil, fmt.Errorf("%s on main names no repository", valleyPointer)
219 }
220 } else if g.succeeds(true, "cat-file", "-e", tip+":"+instanceLayer) {
221 instance, _ = g.output(true, "remote", "get-url", "origin")
222 } else {
223 return "", nil, fmt.Errorf("main on origin names no owning valley at %s", valleyPointer)
224 }
225 if err := checkURL(instance); err != nil {
226 return "", nil, err
227 }
228 g = g.restricted()
229 oid, err := remoteRef(g, instance, projectsRef)
230 if err != nil {
231 return instance, nil, fmt.Errorf("could not read the instance repository %s", instance)
232 }
233 if oid == "" {
234 return instance, nil, fmt.Errorf("the instance repository %s publishes no %s", instance, projectsRef)
235 }
236 if !g.succeeds(true, "cat-file", "-e", oid) {
237 // The project and the instance share no history, so git warns
238 // "no common commits". The warning is kept for the error alone.
239 var diag bytes.Buffer
240 quiet := g
241 quiet.stderr = &diag
242 if _, err := quiet.output(false, "fetch", "--quiet", "--no-tags", "--no-write-fetch-head", "--end-of-options", instance, oid); err != nil {
243 msg := fmt.Sprintf("could not fetch %s from %s", projectsRef, instance)
244 if d := strings.TrimSpace(diag.String()); d != "" {
245 msg += ": " + d
246 }
247 return instance, nil, errors.New(msg)
248 }
249 }
250 list, err := g.output(true, "cat-file", "blob", oid)
251 if err != nil {
252 return instance, nil, fmt.Errorf("%s in %s is not a list of projects", projectsRef, instance)
253 }
254 for _, name := range strings.Split(list, "\n") {
255 if name == "" {
256 continue
257 }
258 if !change.ValidPrincipal(name) {
259 return instance, nil, fmt.Errorf("%s in %s lists %q, which is not a project name", projectsRef, instance, name)
260 }
261 names = append(names, name)
262 }
263 sort.Strings(names)
264 return instance, names, nil
265}
266
267// remoteRef is the object a remote's ref names, or "" when it has no such
268// ref. ls-remote matches a pattern against the tail of a ref name, so a
269// pushed refs/heads/x/refs/heads/main would match refs/heads/main too.
270// Each ref listed is compared whole.
271func remoteRef(g git, remote, ref string) (string, error) {
272 out, err := g.output(false, "ls-remote", "--end-of-options", remote, ref)
273 if err != nil {
274 return "", err
275 }
276 for _, line := range strings.Split(out, "\n") {
277 if oid, name, ok := strings.Cut(line, "\t"); ok && name == ref {
278 return oid, nil
279 }
280 }
281 return "", nil
282}
283
284// allowedProtocols are the transports git may use for a URL this command
285// derives from data: ssh, git, https, and file, which covers local paths.
286// GIT_ALLOW_PROTOCOL overrides any protocol.*.allow the caller's
287// configuration sets.
288const allowedProtocols = "ssh:git:https:file"
289
290// restricted is g with git held to allowedProtocols.
291func (g git) restricted() git {
292 g.env = append(append([]string(nil), g.env...), "GIT_ALLOW_PROTOCOL="+allowedProtocols)
293 return g
294}
295
296// checkURL refuses a URL that is unsafe to hand git when it comes from data
297// (policy/valley, or a name the host lists): one that opens with a dash,
298// which git would read as an option; a <transport>::<address> form, such
299// as ext::, which runs a remote helper or a command; and a URL with a
300// scheme other than ssh, git, https or file. A scp-like [user@]host:path
301// and a local path are allowed, but not with a host that opens with a
302// dash, which ssh would read as an option.
303func checkURL(u string) error {
304 switch {
305 case u == "":
306 return errors.New("no URL")
307 case strings.HasPrefix(u, "-"):
308 return fmt.Errorf("the URL %q opens with a dash, which git would read as an option", u)
309 case strings.ContainsFunc(u, func(r rune) bool { return r < 0x20 || r == 0x7f }):
310 return fmt.Errorf("the URL %q holds a control character", u)
311 case strings.HasPrefix(hostOf(u), "-"):
312 return fmt.Errorf("the URL %q names a host that opens with a dash", u)
313 }
314 if helper, _, ok := strings.Cut(u, "::"); ok && transportName.MatchString(helper) {
315 return fmt.Errorf("the URL %q names the transport %s::, and only ssh, git, https, file, scp-like and local URLs are read", u, helper)
316 }
317 if scheme, _, ok := strings.Cut(u, "://"); ok {
318 switch scheme {
319 case "ssh", "git", "https", "file":
320 default:
321 return fmt.Errorf("the URL %q has the scheme %s, and only ssh, git, https, file, scp-like and local URLs are read", u, scheme)
322 }
323 }
324 return nil
325}
326
327// transportName is the shape of the transport in git's
328// <transport>::<address> form.
329var transportName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9+.-]*$`)
330
331// pointerURL is the first line of policy/valley that is neither blank nor
332// a comment, as bin/valley's pointer_url reads it.
333func pointerURL(pointer string) string {
334 for _, line := range strings.Split(pointer, "\n") {
335 line, _, _ = strings.Cut(line, "#")
336 if line = strings.TrimSpace(line); line != "" {
337 return line
338 }
339 }
340 return ""
341}
342
343// projectURL is the URL of a project served beside the instance
344// repository: the instance's URL with its last path segment replaced by
345// the project's name. A segment ending in .git gives a name ending in .git.
346// It reads every form git fetch takes: a URL with a scheme, the scp-like
347// [user@]host:path, and a local path.
348func projectURL(instance, name string) (string, error) {
349 u := strings.TrimRight(instance, "/")
350 start := 0 // where the path begins
351 if scheme := strings.Index(u, "://"); scheme >= 0 {
352 slash := strings.Index(u[scheme+3:], "/")
353 if slash < 0 {
354 return "", fmt.Errorf("the instance URL %s has no path to replace", instance)
355 }
356 start = scheme + 3 + slash
357 } else if colon := strings.Index(u, ":"); colon >= 0 && !strings.Contains(u[:colon], "/") {
358 start = colon + 1
359 }
360 cut := start + strings.LastIndex(u[start:], "/") + 1
361 segment := u[cut:]
362 if segment == "" || segment == ".git" {
363 return "", fmt.Errorf("the instance URL %s has no path to replace", instance)
364 }
365 if strings.HasSuffix(segment, ".git") {
366 name += ".git"
367 }
368 url := u[:cut] + name
369 return url, checkURL(url)
370}
371
372// hostOf is the host a URL reaches, with its port when one is given and
373// without its user. A local path reaches localhost.
374func hostOf(url string) string {
375 if scheme := strings.Index(url, "://"); scheme >= 0 {
376 rest := url[scheme+3:]
377 rest, _, _ = strings.Cut(rest, "/")
378 if at := strings.LastIndex(rest, "@"); at >= 0 {
379 rest = rest[at+1:]
380 }
381 if rest == "" {
382 return "localhost"
383 }
384 return rest
385 }
386 if colon := strings.Index(url, ":"); colon >= 0 && !strings.Contains(url[:colon], "/") {
387 host := url[:colon]
388 if at := strings.LastIndex(host, "@"); at >= 0 {
389 host = host[at+1:]
390 }
391 return host
392 }
393 return "localhost"
394}
395
396// cacheRepo is the clone a repository other than the current one is read
397// through: a repository under $XDG_CACHE_HOME/valley/repos, keyed by its
398// URL, with origin set to it. It holds no checkout. Only fetches by object
399// ID write to it, and main's tip is kept at refs/remotes/origin/main so
400// valley checks can be run inside it.
401func cacheRepo(g git, url, name string) (git, error) {
402 base := os.Getenv("XDG_CACHE_HOME")
403 if base == "" {
404 home, err := os.UserHomeDir()
405 if err != nil {
406 return git{}, errors.New("no cache directory to read other repositories through")
407 }
408 base = filepath.Join(home, ".cache")
409 }
410 sum := sha256.Sum256([]byte(url))
411 dir := filepath.Join(base, "valley", "repos", hex.EncodeToString(sum[:8])+"-"+name)
412 c := git{env: cacheEnvironment(g.env), stderr: g.stderr, dir: dir}
413 if _, err := os.Stat(filepath.Join(dir, ".git")); err != nil {
414 if err := os.MkdirAll(dir, 0o755); err != nil {
415 return git{}, fmt.Errorf("could not make the cache repository %s", dir)
416 }
417 if _, err := c.output(false, "init", "--quiet"); err != nil {
418 return git{}, fmt.Errorf("could not make the cache repository %s", dir)
419 }
420 if _, err := c.output(false, "remote", "add", "--end-of-options", "origin", url); err != nil {
421 return git{}, fmt.Errorf("could not set origin in %s", dir)
422 }
423 }
424 return c, nil
425}
426
427// cacheEnvironment is env without the variables that would point git at
428// another repository than the cache's, and with git held to
429// allowedProtocols.
430func cacheEnvironment(env []string) []string {
431 var kept []string
432 for _, kv := range env {
433 name, _, _ := strings.Cut(kv, "=")
434 switch name {
435 case "GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR", "GIT_INDEX_FILE", "GIT_PREFIX", "GIT_NAMESPACE":
436 continue
437 }
438 kept = append(kept, kv)
439 }
440 return append(kept, "GIT_ALLOW_PROTOCOL="+allowedProtocols)
441}
442
443// listed is one repository as read: its snapshot (or the error from reading
444// it) and the knots its plan graph links to its changes.
445type listed struct {
446 source
447 snap *snapshot
448 knots doers
449}
450
451// readSources reads every source. A repository that cannot be read is
452// listed with its error, and the rest are listed all the same.
453func readSources(list []source, v verifier) []listed {
454 var out []listed
455 for _, s := range list {
456 l := listed{source: s}
457 if s.err == nil {
458 l.snap, l.err = readSnapshot(s.g, v)
459 if l.err != nil && s.g.dir != "" {
460 l.err = fmt.Errorf("could not read %s", s.url)
461 }
462 }
463 if l.err == nil && l.snap.tip != "" && l.g.dir != "" {
464 // The clone's main, for valley checks to read the policy at.
465 _, _ = l.g.output(true, "update-ref", "refs/remotes/origin/"+recordTarget, l.snap.tip)
466 }
467 out = append(out, l)
468 }
469 return out
470}
471
472// readKnots reads the plan graph once for each readable repository in repos.
473func readKnots(repos []listed, verbose bool, stderr io.Writer) {
474 for i := range repos {
475 if repos[i].err == nil {
476 repos[i].knots = readDoers(repos[i].g, repos[i].name, verbose, stderr)
477 }
478 }
479}
480
481// handleKey names one change listed: changes are keyed by repository,
482// target and change ID.
483type handleKey struct{ repo, target, id string }
484
485// handleMap is the handle of each change listed.
486type handleMap map[handleKey]string
487
488// handles gives each change listed its handle among every change listed,
489// in every repository, so no two share one. Every record of a repository
490// is counted, listed or not, so a handle also names its change in that
491// repository alone. A change ID recorded in more than one repository
492// listed gets the handle <repo>:<prefix> in each, which every verb that
493// takes a handle reads in that repository. git refuses a colon in a ref
494// name, so a qualified handle is never also a branch's name.
495func handles(repos []listed) handleMap {
496 var ids []string
497 in := map[string]map[string]bool{} // change ID → the repositories recording it
498 for _, r := range repos {
499 if r.snap == nil {
500 continue
501 }
502 for _, n := range r.snap.all {
503 ids = append(ids, n.id)
504 if in[n.id] == nil {
505 in[n.id] = map[string]bool{}
506 }
507 in[n.id][r.name] = true
508 }
509 }
510 sort.Strings(ids)
511 h := handleMap{}
512 for _, r := range repos {
513 if r.snap == nil {
514 continue
515 }
516 for _, n := range r.snap.all {
517 handle := change.Handle(n.id, ids)
518 if len(in[n.id]) > 1 {
519 handle = r.name + ":" + handle
520 }
521 h[handleKey{r.name, n.record.Target, n.id}] = handle
522 }
523 }
524 return h
525}
526
527// changeView is a change as valley-changes/v1 writes it, with includes
528// among the candidates given.
529func (s *snapshot) changeView(n recorded, handle string, candidates []recorded) jsonChange {
530 r := n.record
531 c := jsonChange{
532 ChangeID: n.id, Handle: handle, Target: r.Target, Owner: r.Owner, State: r.State,
533 Record: n.commit, Seq: r.Seq, Active: r.Active, Includes: s.includes(n, candidates),
534 Restack: restackView(s.report(n.id)), Knots: []knotRef{},
535 }
536 for _, v := range r.Versions {
537 kind, commit := s.landing(n.id, v)
538 jv := jsonVersion{
539 N: v.N, Head: headOf(v), Title: v.Title, Branch: v.Branch, Uploader: v.Uploader,
540 Landing: kind, Request: s.request(n.id, v),
541 }
542 if commit != "" {
543 jv.LandedCommit = &commit
544 }
545 if _, m, ok := s.outcome(n.id, v); ok {
546 jv.Outcome = &versionOutcome{Decision: m.decision, Head: m.head}
547 if isObjectID(m.tip) {
548 tip := m.tip
549 jv.Outcome.Tip = &tip
550 }
551 }
552 c.Versions = append(c.Versions, jv)
553 }
554 return c
555}
556
557// repoView is a repository as valley-changes/v1 writes it, holding the
558// changes keep chooses, each with includes among those include chooses.
559func (l listed) repoView(h handleMap, keep, include func(*snapshot, recorded) bool) jsonRepo {
560 r := jsonRepo{Repo: l.name, URL: l.url, Changes: []jsonChange{}, Branches: []jsonBranch{}}
561 if l.err != nil {
562 msg := l.err.Error()
563 r.Error = &msg
564 return r
565 }
566 var candidates []recorded
567 for _, n := range l.snap.all {
568 if include(l.snap, n) {
569 candidates = append(candidates, n)
570 }
571 }
572 for _, n := range l.snap.all {
573 if keep(l.snap, n) {
574 c := l.snap.changeView(n, h[handleKey{l.name, n.record.Target, n.id}], candidates)
575 c.Knots = l.knots.of(n.id)
576 r.Changes = append(r.Changes, c)
577 }
578 }
579 r.Branches = l.snap.unrecorded()
580 return r
581}
582
583func everyChange(*snapshot, recorded) bool { return true }
584
585// writeDocument writes a listing document as one line of JSON. Every
586// string in it must be UTF-8: encoding/json would write any other bytes
587// as U+FFFD, which is another string.
588func writeDocument(w io.Writer, doc jsonChanges) error {
589 bad := false
590 walkStrings(doc, func(s string) { bad = bad || !utf8.ValidString(s) })
591 if bad {
592 return failure("a name in the listing is not UTF-8, so JSON cannot carry it")
593 }
594 var buf bytes.Buffer
595 enc := json.NewEncoder(&buf)
596 enc.SetEscapeHTML(false)
597 if err := enc.Encode(doc); err != nil {
598 return err
599 }
600 _, err := w.Write(buf.Bytes())
601 return err
602}
603
604// walkStrings calls f with every string a listing document holds.
605func walkStrings(doc any, f func(string)) {
606 switch d := doc.(type) {
607 case jsonChanges:
608 f(d.Schema)
609 f(d.Host)
610 for _, r := range d.Repos {
611 walkStrings(r, f)
612 }
613 case jsonRepo:
614 f(d.Repo)
615 f(d.URL)
616 if d.Error != nil {
617 f(*d.Error)
618 }
619 all := d.Changes
620 if d.Drafts != nil {
621 all = append(append([]jsonChange(nil), all...), *d.Drafts...)
622 }
623 for _, c := range all {
624 f(c.ChangeID)
625 f(c.Handle)
626 f(c.Target)
627 f(c.Owner)
628 f(c.State)
629 for _, k := range c.Knots {
630 f(k.ID)
631 f(k.Type)
632 f(k.Status)
633 f(k.Title)
634 }
635 for _, v := range c.Versions {
636 f(v.Title)
637 f(v.Branch)
638 f(v.Uploader)
639 }
640 }
641 for _, b := range d.Branches {
642 f(b.Branch)
643 }
644 }
645}
646
647// utf8Branches drops every branch whose name is not UTF-8 from a listing,
648// and says so on stderr: JSON cannot carry such a name exactly.
649func utf8Branches(r *jsonRepo, stderr io.Writer) {
650 kept := r.Branches[:0]
651 for _, b := range r.Branches {
652 if !utf8.ValidString(b.Branch) {
653 fmt.Fprintf(stderr, "valley: %s: left out the branch %s, whose name is not UTF-8\n", r.Repo, shellQuote(b.Branch))
654 continue
655 }
656 kept = append(kept, b)
657 }
658 r.Branches = kept
659}
660
661func runChanges(g git, args []string, stdout, stderr io.Writer) error {
662 l, err := parseListing("changes", args, false)
663 if err != nil {
664 return err
665 }
666 if !l.asJSON {
667 return failure("changes prints valley-changes/v1 alone; pass --json. valley pending is the view to read")
668 }
669 list, host, err := sources(g, l, stderr)
670 if err != nil {
671 return err
672 }
673 repos := readSources(list, verifierFromEnv())
674 readKnots(repos, l.verbose, stderr)
675 h := handles(repos)
676 writeHandleCache(g, repos, h)
677 doc := jsonChanges{Schema: changesSchema, Host: host, Repos: []jsonRepo{}}
678 for _, r := range repos {
679 view := r.repoView(h, everyChange, everyChange)
680 utf8Branches(&view, stderr)
681 doc.Repos = append(doc.Repos, view)
682 }
683 warnUnverified(repos, stderr)
684 return writeDocument(stdout, doc)
685}
686
687// warnUnverified says which repositories held a transfer statement that
688// could not be checked, so a landing there may be stronger than listed,
689// and which records did not read, so are not listed.
690func warnUnverified(repos []listed, stderr io.Writer) {
691 for _, r := range repos {
692 if r.snap != nil {
693 for _, u := range r.snap.unread {
694 fmt.Fprintf(stderr, "valley: warning: %s: the change record %s does not read, so it is not listed: %s. The hook refuses such a record, so origin's storage is corrupt\n", r.name, u.ref, u.why)
695 }
696 }
697 if r.snap != nil && r.snap.unverified() {
698 fmt.Fprintf(stderr, "valley: %s: a transfer statement could not be verified, so a change may have landed that is not listed so. %s\n", r.name, verifierHint)
699 }
700 }
701}