interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / collab / co2cob.om

1956 lines · 37763 bytes Raw Blame History
1note collab/co2cob.om (ForgePatches): load one Radicle patch or issue COB from git storage and replay it.
2note Layout (heartwood, rad 1.10.3 on spark): refs/namespaces/<nid>/refs/cobs/xyz.radicle.patch/<id>
3note (and xyz.radicle.issue) point at the newest change commit. A change commit's tree holds the
4note blobs 0, 1, ... (one JSON action each) and manifest. The COB id is the root change commit, and
5note a revision id is the id of the change that created it. Parents of a change are earlier changes,
6note then related repo commits and the identity root; only changes descend from the root change, so
7note `git log --ancestry-path <tips> ^<root>` lists exactly the later changes, oldest first with
8note --reverse --topo-order. `git grep -a -z -e ^ <changes>` prints every action blob as one line
9note `<change>:<n>\0<json>`. Read only, argv execs only (fkgit + fexec), never the rad CLI.
10note Limits: every ref of one kind that fxo carries (16 MiB of 82-byte lines; a longer list is the whole
11note 500 of fincut), 8,192 changes, 8,192 comments, 64 revisions, 16 merges and 64 reviews per COB, a
12note 4 MiB string pool. Past a limit the object is not whole (gcov) and its page, JSON, raw diff and
13note every write to it are the whole 500 of fincut: nothing is shown or written from a cut copy.
14note Concurrent changes replay in git topological order.
15const CORFMAX ulong 262144
16const COCHMAX ulong 8192
17const COCMMAX ulong 8192
18text tcfer "for-each-ref"
19text tcsort "--sort=-committerdate"
20text tcfmtr "--format=%(objectname) %(refname:lstrip=-1)"
21text tcpatref "refs/namespaces/*/refs/cobs/xyz.radicle.patch/*"
22text tcissref "refs/namespaces/*/refs/cobs/xyz.radicle.issue/*"
23text tclog "log"
24text tcnowalk "--no-walk"
25text tcfmtl "--format=%H %at %ae"
26text tcanc "--ancestry-path"
27text tctopo "--topo-order"
28text tcrevers "--reverse"
29text tcgrep "grep"
30text tcopta "-a"
31text tcoptz "-z"
32text tcnocol "--no-color"
33text tcnoln "--no-line-number"
34text tcopte "-e"
35text tccaret "^"
36text tcdd "--"
37text tcty "type"
38text tcrevis "revision"
39text tcedit "edit"
40text tclife "lifecycle"
41text tcmerge "merge"
42text tcreview "review"
43text tcrcom "revision.comment"
44text tcredit "revision.edit"
45text tcrred "revision.redact"
46text tclabel "label"
47text tcassign "assign"
48text tccomm "comment"
49text tccedit "comment.edit"
50text tccred "comment.redact"
51text tcbase "base"
52text tcoid "oid"
53text tcdesc "description"
54text tctitle "title"
55text tcstate "state"
56text tcstatus "status"
57text tcreason "reason"
58text tccommit "commit"
59text tcverd "verdict"
60text tcsumm "summary"
61text tcbody "body"
62text tclabels "labels"
63text tcassn "assignees"
64text tcid "id"
65text tcdraft "draft"
66text tcvv1 "VERDICT "
67text tcvv2 "MERGE_AFTER_FIX head="
68text tcvv3 "MERGE head="
69text tcvv4 "REJECT head="
70text tcarch "archived"
71text tcclosed "closed"
72text tcaccept "accept"
73text tcreject "reject"
74text tcrevd "/home/drakestapleton/handoffs/hive/manager/reviews/"
75text tcvsuf ".verdict.txt"
76note refs of the current repo: tip and COB id per ref; gcui lists the first ref of each distinct id
77global gcfo uchar 10485760
78global gcfi uchar 10485760
79global gcfn ulong 1
80global gcui ulong 262144
81global gcun ulong 1
82note gcuh: open-addressing set of the distinct ids (ref index + 1), for coseen
83global gcuh ulong 524288
84note gcxfull: the action index of the current chunk was full (cogrep retries a smaller chunk)
85global gcxfull ulong 1
86note the COB being loaded, and a requested id prefix
87global gcid uchar 40
88global gcrq uchar 40
89global gcrql ulong 1
90note changes: id, author time, author NID (the part of the author email after @)
91global gcch uchar 327680
92global gccts ulong 8192
93global gccau uchar 524288
94global gccal ulong 8192
95global gccn ulong 1
96note model slots gcm: 0,1 title (pool off,len) 2 lifecycle (0 open 1 draft 2 archived/closed)
97note 3,4 labels 5,6 assignees 7,8 close reason 9 kind (1 patch 2 issue) 10 actions not understood
98global gcm ulong 16
99note gclfc: the change whose lifecycle action was applied last (the event stream, door/, names it)
100global gclfc ulong 1
101note revisions: id, base, head oid, creating change, description (off,len), redacted, verdict line
102global gcrv uchar 2560
103global gcrb uchar 2560
104global gcro uchar 2560
105global gcrt ulong 64
106global gcrd ulong 128
107global gcrx ulong 64
108global gcrvd uchar 16384
109global gcrvl ulong 64
110global gcrn ulong 1
111note merges: revision index, merge commit, change
112global gcmr ulong 16
113global gcmc uchar 640
114global gcmt ulong 16
115global gcmn ulong 1
116note reviews: revision index, verdict (0 none 1 accept 2 reject), summary (off,len), change
117global gcwr ulong 64
118global gcwv ulong 64
119global gcws ulong 128
120global gcwt ulong 64
121global gcwn ulong 1
122note comments: revision index (9999 = none: an issue comment), body (off,len), change, redacted
123global gcqr ulong 8192
124global gcqs ulong 16384
125global gcqt ulong 8192
126global gcqx ulong 8192
127global gcqn ulong 1
128note one git grep chunk: per output line the content range, change index and blob number
129global gcxa ulong 4096
130global gcxb ulong 4096
131global gcxc ulong 4096
132global gcxk ulong 4096
133global gcxn ulong 1
134note verdict file path and first bytes
135global gcvp uchar 512
136global gcvpl ulong 1
137global gcvb uchar 512
138note ---- small scanners over fxo
139fn coeol p ulong n ulong to ulong
140q = p
141while lt q n bound 16777216
142if eq get fxo q 10
143ret q
144end
145q = add q 1
146end
147ret n
148end
149fn cofindb a ulong b ulong c uchar to ulong
150q = a
151while lt q b bound 16777216
152if eq get fxo q c
153ret q
154end
155q = add q 1
156end
157ret b
158end
159fn cohexr a ulong n ulong to bool
160for i ulong n
161if cohexc get fxo add a i
162continue
163end
164ret false
165end
166ret true
167end
168fn codec a ulong b ulong to ulong
169v = ulong 0
170for i ulong sub b a
171c = get fxo add a i
172if and ge c 48 le c 57
173v = add mul v 10 sub ulong c 48
174end
175end
176ret v
177end
178note conum: fxo[a,b) as a decimal of 1..4 digits, 9999 otherwise (the manifest blob)
179fn conum a ulong b ulong to ulong
180if or le b a gt sub b a 4
181ret ulong 9999
182end
183v = ulong 0
184for i ulong sub b a
185c = get fxo add a i
186if or lt c 48 gt c 57
187ret ulong 9999
188end
189v = add mul v 10 sub ulong c 48
190end
191ret v
192end
193note coisnum: fxo[a,b) is a decimal number, the name of an action blob. The other entries of a change
194note (manifest, embeds/<name>) also come out of git grep and are not actions.
195fn coisnum a ulong b ulong to bool
196if le b a
197ret false
198end
199for i ulong sub b a bound 16777216
200c = get fxo add a i
201if or lt c 48 gt c 57
202ret false
203end
204end
205ret true
206end
207note ---- refs: corefs kd (1 patch, 2 issue) fills gcfo/gcfi and the distinct ids gcui
208fn corefs kd ulong to bool
209put gcfn 0 0
210put gcun 0 0
211fkgit
212fka tcfer
213fka tcsort
214fka tcfmtr
215if eq kd 1
216fka tcpatref
217else
218fka tcissref
219end
220x = fexec 10000000000
221if ne x 0
222ret false
223end
224note a ref list longer than fxo is not read as the whole list (an object past the cut would be a 404)
225if ne get fxotr 0 0
226fincut
227ret false
228end
229for i ulong len gcuh
230put gcuh i 0
231end
232n = get fxol 0
233p = ulong 0
234while lt p n bound 16777216
235q = coeol p n
236corefln p q
237p = add q 1
238end
239ret true
240end
241fn corefln a ulong b ulong to void
242if ne sub b a 81
243ret
244end
245if ne get fxo add a 40 32
246ret
247end
248if eq cohexr a 40 false
249ret
250end
251if eq cohexr add a 41 40 false
252ret
253end
254i = get gcfn 0
255note CORFMAX is more lines than fxo holds, so this is not reached; it stays a refusal, not a cut
256if ge i CORFMAX
257fincut
258ret
259end
260for k ulong 40
261put gcfo add mul i 40 k get fxo add a k
262put gcfi add mul i 40 k get fxo add a add 41 k
263end
264put gcfn 0 add i 1
265if eq coseen i false
266u = get gcun 0
267put gcui u i
268put gcun 0 add u 1
269end
270end
271note coseen: ref i carries an id already listed in gcui (true); else its id joins the set gcuh
272fn coseen i ulong to bool
273m = sub len gcuh 1
274h = ulong 14695981039346656037
275for k ulong 40
276c = ulong get gcfi add mul i 40 k
277h = mul xor h c 1099511628211
278end
279j = and h m
280for it ulong len gcuh
281v = get gcuh j
282if eq v 0
283put gcuh j add i 1
284ret false
285end
286if cofieq sub v 1 i
287ret true
288end
289j = and add j 1 m
290end
291ret true
292end
293fn cofieq x ulong y ulong to bool
294for k ulong 40
295if ne get gcfi add mul x 40 k get gcfi add mul y 40 k
296ret false
297end
298end
299ret true
300end
301note coresolve: the distinct id that starts with gcrq[0,gcrql) (4..40 hex), into gcid; false when none or ambiguous
302fn coresolve to bool
303m = ulong 0
304w = ulong 0
305for j ulong get gcun 0
306if corqpre get gcui j
307m = add m 1
308w = get gcui j
309end
310end
311if ne m 1
312ret false
313end
314for k ulong 40
315put gcid k get gcfi add mul w 40 k
316end
317ret true
318end
319fn corqpre i ulong to bool
320n = get gcrql 0
321if or lt n 4 gt n 40
322ret false
323end
324for k ulong n
325if ne get gcfi add mul i 40 k get gcrq k
326ret false
327end
328end
329ret true
330end
331note coidref: copy the id of ref i into gcid
332fn coidref i ulong to void
333for k ulong 40
334put gcid k get gcfi add mul i 40 k
335end
336end
337note ---- argv pieces
338fn cokid ng bool to void
339fkopen
340if ng
341fkc 94
342end
343for k ulong 40
344fkc get gcid k
345end
346end
347fn cokch ci ulong to void
348fkopen
349for k ulong 40
350fkc get gcch add mul ci 40 k
351end
352end
353fn cokpos to void
354for j ulong get gcfn 0
355if cotipis j
356fkopen
357for k ulong 40
358fkc get gcfo add mul j 40 k
359end
360end
361end
362end
363fn cotipis j ulong to bool
364for k ulong 40
365if ne get gcfi add mul j 40 k get gcid k
366ret false
367end
368end
369ret true
370end
371note ---- change list from `git log --format=%H %at %ae`
372fn colog to void
373note a change list longer than fxo would lose changes: the object is not whole
374if ne get fxotr 0 0
375put gcov 0 1
376end
377n = get fxol 0
378p = ulong 0
379while lt p n bound 16777216
380q = coeol p n
381coline p q
382p = add q 1
383end
384end
385fn coline a ulong b ulong to void
386if lt sub b a 44
387ret
388end
389if ne get fxo add a 40 32
390ret
391end
392if eq cohexr a 40 false
393ret
394end
395ci = get gccn 0
396if ge ci COCHMAX
397put gcov 0 1
398ret
399end
400for k ulong 40
401put gcch add mul ci 40 k get fxo add a k
402end
403sp = cofindb add a 41 b 32
404put gccts ci codec add a 41 sp
405coauset ci add sp 1 b
406put gccn 0 add ci 1
407end
408fn coauat a ulong b ulong to ulong
409s = a
410k = a
411while lt k b bound 16777216
412if eq get fxo k 64
413s = add k 1
414end
415k = add k 1
416end
417ret s
418end
419fn coauset ci ulong a ulong b ulong to void
420s = coauat a b
421m = ulong 0
422if gt b s
423m = sub b s
424end
425if gt m 64
426m = ulong 64
427end
428o = mul ci 64
429for i ulong m
430put gccau add o i get fxo add s i
431end
432put gccal ci m
433end
434note ---- change signer: Radicle signs every change commit with the author's node key (SSHSIG,
435note ssh-ed25519). That key, as did:key multibase (z + base58btc of 0xed 0x01 + key), is the author
436note NID; the email after @ is only a fallback when a commit has no well-formed signature. This
437note reads the key; it does not verify the signature (the node verified it when it fetched the change).
438text tcrevl "rev-list"
439text tcnwu "--no-walk=unsorted"
440text tchdr "--header"
441text tcsigm "SSH SIGNATURE-----"
442text tcssig "SSHSIG"
443text tced "ssh-ed25519"
444text tcb58 "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
445global gcsg uchar 72
446global gcbn uchar 64
447note cosig s e: set the author NID of changes s..e-1 from `git rev-list --header` (raw commits,
448note NUL-separated); false when that output did not fit fxo (coreplay retries a smaller chunk)
449fn cosig s ulong e ulong to bool
450fkgit
451fka tcrevl
452fka tcnwu
453fka tchdr
454for i ulong sub e s
455cokch add s i
456end
457x = fexec 10000000000
458if ne get fxotr 0 0
459ret false
460end
461if ne x 0
462ret true
463end
464n = get fxol 0
465p = ulong 0
466while lt p n bound 16777216
467q = cofindb p n 0
468cosigrec p q s e
469p = add q 1
470end
471ret true
472end
473fn cosigrec a ulong b ulong s ulong e ulong to void
474if lt sub b a 41
475ret
476end
477ci = cochin a s e
478if ge ci e
479ret
480end
481m = cofindt a b
482if ge m b
483ret
484end
485if eq cob64d m b false
486ret
487end
488if eq cosigok false
489ret
490end
491cob58 ci
492end
493note cofindt a b: the index just past the first "SSH SIGNATURE-----" in fxo[a,b), else b
494fn cofindt a ulong b ulong to ulong
495l = len tcsigm
496k = a
497while le add k l b bound 16777216
498if coraweq k add k l tcsigm
499ret add k l
500end
501k = add k 1
502end
503ret b
504end
505note cob64v c: the base64 value of c, 64 for a line break or space (skipped), 99 for anything else
506fn cob64v c uchar to ulong
507v = ulong c
508if and ge c 65 le c 90
509ret sub v 65
510end
511if and ge c 97 le c 122
512ret sub v 71
513end
514if and ge c 48 le c 57
515ret add v 4
516end
517if eq c 43
518ret 62
519end
520if eq c 47
521ret 63
522end
523if or eq c 10 eq c 32
524ret 64
525end
526ret 99
527end
528note cob64d a b: decode the first 66 bytes of the base64 text at fxo[a,b) into gcsg
529note The scan reads at most 4096 bytes past the marker. A real signature gives its 66 bytes within
530note about 92 (88 base64 bytes and the line breaks); b is the end of the raw commit and can be far
531note past a, so a marker followed by more than 4096 spaces or line breaks used to pass the bound
532note (trap 4, exit 104).
533fn cob64d a ulong b ulong to bool
534acc = ulong 0
535nb = ulong 0
536o = ulong 0
537e = b
538if gt sub b a 4096
539e = add a 4096
540end
541k = a
542while lt k e bound 4096
543v = cob64v get fxo k
544if gt v 64
545ret false
546end
547if lt v 64
548acc = or shl acc 6 v
549nb = add nb 6
550if ge nb 8
551nb = sub nb 8
552put gcsg o uchar and shr acc nb 255
553acc = and acc 255
554o = add o 1
555if ge o 66
556ret true
557end
558end
559end
560k = add k 1
561end
562ret false
563end
564note cosigok: gcsg starts SSHSIG, version, then the public key string "ssh-ed25519" + 32-byte key
565fn cosigok to bool
566for i ulong 6
567if ne get gcsg i get tcssig i
568ret false
569end
570end
571if ne get gcsg 17 11
572ret false
573end
574for i ulong 11
575if ne get gcsg add 18 i get tced i
576ret false
577end
578end
579if ne get gcsg 32 32
580ret false
581end
582ret true
583end
584note cob58 ci: gccau[ci] = z + base58btc(0xed 0x01 key) (48 bytes for an ed25519 key)
585fn cob58 ci ulong to void
586nd = ulong 0
587for i ulong 34
588c = cob58in i
589for j ulong nd
590c = add c mul ulong get gcbn j 256
591put gcbn j uchar rem c 58
592c = div c 58
593end
594while gt c 0 bound 64
595put gcbn nd uchar rem c 58
596nd = add nd 1
597c = div c 58
598end
599end
600o = mul ci 64
601put gccau o 122
602for j ulong nd
603put gccau add o add j 1 get tcb58 get gcbn sub sub nd 1 j
604end
605put gccal ci add nd 1
606end
607fn cob58in i ulong to ulong
608if eq i 0
609ret 237
610end
611if eq i 1
612ret 1
613end
614ret ulong get gcsg add 31 i
615end
616note cochid: change ci is the requested COB id
617fn cochid ci ulong to bool
618for k ulong 40
619if ne get gcch add mul ci 40 k get gcid k
620ret false
621end
622end
623ret true
624end
625note ---- load and replay
626fn coreset to void
627put gcov 0 0
628put gclfc 0 0
629put gccn 0 0
630put gcpl 0 0
631put gcrn 0 0
632put gcmn 0 0
633put gcwn 0 0
634put gcqn 0 0
635put gcxn 0 0
636for i ulong 16
637put gcm i 0
638end
639end
640note coload kd: load the COB gcid (kind 1 patch, 2 issue; corefs kd must have run); false when absent
641fn coload kd ulong to bool
642coreset
643put gcm 9 kd
644fkgit
645fka tclog
646fka tcnowalk
647fka tcfmtl
648cokid false
649x = fexec 10000000000
650if ne x 0
651ret false
652end
653colog
654if ne get gccn 0 1
655ret false
656end
657if eq cochid 0 false
658ret false
659end
660fkgit
661fka tclog
662fka tcanc
663fka tctopo
664fka tcrevers
665fka tcfmtl
666cokpos
667cokid true
668x = fexec 10000000000
669if ne x 0
670ret false
671end
672colog
673coreplay
674for r ulong get gcrn 0
675covlook r
676end
677ret true
678end
679note coreplay: changes in chunks of up to 32 (one rev-list and one git grep each). A chunk whose
680note output does not fit fxo, or whose action lines do not fit the index, is read again in halves, so
681note no number of changes is cut by those buffers; one change that does not fit alone makes the object
682note not whole (gcov), and it is never shown as if it were.
683fn coreplay to void
684n = get gccn 0
685s = ulong 0
686c = ulong 32
687while lt s n bound 1048576
688e = add s c
689if gt e n
690e = n
691end
692if coplay s e
693s = e
694c = 32
695else
696if gt sub e s 1
697c = div sub e s 2
698else
699put gcov 0 1
700s = e
701end
702end
703end
704end
705note coplay s e: the signatures and actions of changes [s, e); false when their output did not fit, and
706note then no action of the chunk was applied
707fn coplay s ulong e ulong to bool
708if not cosig s e
709ret false
710end
711ret cogrep s e
712end
713note cogrep s e: git grep of the action blobs of changes [s, e), indexed, then applied in change order;
714note false (nothing applied) when the output did not fit fxo or the index. Exit 1 is git grep's "no
715note line": nothing to apply. Any other failure makes the object not whole.
716fn cogrep s ulong e ulong to bool
717fkgit
718fka tcgrep
719fka tcopta
720fka tcoptz
721fka tcnocol
722fka tcnoln
723fka tcopte
724fka tccaret
725for i ulong sub e s
726cokch add s i
727end
728fka tcdd
729x = fexec 10000000000
730if ne get fxotr 0 0
731ret false
732end
733if eq x 1
734ret true
735end
736if ne x 0
737put gcov 0 1
738ret true
739end
740coidx s e
741if ne get gcxfull 0 0
742ret false
743end
744for i ulong sub e s
745coapch add s i
746end
747ret true
748end
749fn coidx s ulong e ulong to void
750put gcxn 0 0
751put gcxfull 0 0
752n = get fxol 0
753p = ulong 0
754while lt p n bound 16777216
755q = coeol p n
756coxln p q s e
757p = add q 1
758end
759end
760fn coxln a ulong b ulong s ulong e ulong to void
761z = cofindb a b 0
762if ge z b
763ret
764end
765if lt sub z a 42
766ret
767end
768if ne get fxo add a 40 58
769ret
770end
771ci = cochin a s e
772if ge ci e
773ret
774end
775note every change of a Radicle COB holds a manifest beside its action blobs: a line of a name that is not
776note a number is skipped, as before (it is not an action and nothing of the object is lost). Marking it
777note made every real patch and issue the whole 500 (735a01c, caught by the collab suites).
778if not coisnum add a 41 z
779ret
780end
781k = conum add a 41 z
782note an action blob past number 4095 cannot be indexed: the change is not read whole
783if gt k 4095
784put gcov 0 1
785ret
786end
787j = get gcxn 0
788if ge j 4096
789put gcxfull 0 1
790ret
791end
792put gcxa j add z 1
793put gcxb j b
794put gcxc j ci
795put gcxk j k
796put gcxn 0 add j 1
797end
798note cochin: the change in [s,e) whose id is fxo[a,a+40), else e
799fn cochin a ulong s ulong e ulong to ulong
800for i ulong sub e s
801if cochat add s i a
802ret add s i
803end
804end
805ret e
806end
807fn cochat ci ulong a ulong to bool
808for k ulong 40
809if ne get gcch add mul ci 40 k get fxo add a k
810ret false
811end
812end
813ret true
814end
815note coapch: apply the action blobs 0, 1, 2, ... of change ci in order
816fn coapch ci ulong to void
817for k ulong 4096
818j = cofindx ci k
819if ge j 4096
820ret
821end
822coap ci get gcxa j get gcxb j
823end
824end
825fn cofindx ci ulong k ulong to ulong
826for j ulong get gcxn 0
827if and eq get gcxc j ci eq get gcxk j k
828ret j
829end
830end
831ret ulong 4096
832end
833fn coap ci ulong a ulong e ulong to void
834t = cokey a e tcty
835if ge t e
836ret
837end
838if eq get gcm 9 1
839copatap ci a e t
840ret
841end
842coissap ci a e t
843end
844fn coskip to void
845put gcm 10 add get gcm 10 1
846end
847fn copatap ci ulong a ulong e ulong t ulong to void
848if coseq t e tcrevis
849coarev ci a e
850ret
851end
852if coseq t e tcedit
853coatitle a e
854ret
855end
856if coseq t e tclife
857put gclfc 0 ci
858coalife a e
859ret
860end
861if coseq t e tcmerge
862coamerge ci a e
863ret
864end
865if coseq t e tcreview
866coareview ci a e
867ret
868end
869if coseq t e tcrcom
870coarcom ci a e
871ret
872end
873copatap2 ci a e t
874end
875fn copatap2 ci ulong a ulong e ulong t ulong to void
876if coseq t e tcredit
877coaredit a e
878ret
879end
880if coseq t e tcrred
881coarred a e
882ret
883end
884if coseq t e tclabel
885coalabel a e
886ret
887end
888if coseq t e tcassign
889coassign a e
890ret
891end
892coskip
893end
894fn coissap ci ulong a ulong e ulong t ulong to void
895if coseq t e tccomm
896coacom ci a e 9999
897ret
898end
899if coseq t e tcedit
900coatitle a e
901ret
902end
903if coseq t e tclife
904put gclfc 0 ci
905coalife a e
906ret
907end
908if coseq t e tccedit
909coacedit a e
910ret
911end
912if coseq t e tccred
913coacred a e
914ret
915end
916if coseq t e tclabel
917coalabel a e
918ret
919end
920if coseq t e tcassign
921coassign a e
922ret
923end
924coskip
925end
926note ---- actions
927fn coarev ci ulong a ulong e ulong to void
928r = get gcrn 0
929if ge r 64
930put gcov 0 1
931ret
932end
933p = cokey a e tcoid
934b = cokey a e tcbase
935if eq cohexat p e false
936coskip
937ret
938end
939if eq cohexat b e false
940coskip
941ret
942end
943corevcp mul r 40 add p 1 add b 1 mul ci 40
944put gcrt r ci
945put gcrx r 0
946put gcrvl r 0
947codescset r a e
948put gcrn 0 add r 1
949end
950note corevcp: copy head, base and change id of a new revision (o = r*40, p/b at the hex, c = ci*40)
951fn corevcp o ulong p ulong b ulong c ulong to void
952for k ulong 40
953put gcro add o k get fxo add p k
954put gcrb add o k get fxo add b k
955put gcrv add o k get gcch add c k
956end
957end
958fn codescset r ulong a ulong e ulong to void
959d = cokey a e tcdesc
960s = get gcpl 0
961l = cospool d e
962put gcrd mul r 2 s
963put gcrd add mul r 2 1 l
964end
965fn coatitle a ulong e ulong to void
966p = cokey a e tctitle
967if ge p e
968ret
969end
970s = get gcpl 0
971l = cospool p e
972put gcm 0 s
973put gcm 1 l
974end
975fn coalife a ulong e ulong to void
976st = cokey a e tcstate
977if ge st e
978ret
979end
980q = cokey st e tcstatus
981if coseq q e tcdraft
982put gcm 2 1
983ret
984end
985if or coseq q e tcarch coseq q e tcclosed
986put gcm 2 2
987r = cokey st e tcreason
988s = get gcpl 0
989l = cospool r e
990put gcm 7 s
991put gcm 8 l
992ret
993end
994put gcm 2 0
995end
996note corevix: the revision whose id is the string at p, 9999 when unknown
997fn corevix p ulong e ulong to ulong
998if eq cohexat p e false
999ret ulong 9999
1000end
1001for r ulong get gcrn 0
1002if corevat r add p 1
1003ret r
1004end
1005end
1006ret ulong 9999
1007end
1008fn corevat r ulong a ulong to bool
1009for k ulong 40
1010if ne get gcrv add mul r 40 k get fxo add a k
1011ret false
1012end
1013end
1014ret true
1015end
1016fn coamerge ci ulong a ulong e ulong to void
1017m = get gcmn 0
1018if ge m 16
1019put gcov 0 1
1020ret
1021end
1022ri = corevix cokey a e tcrevis e
1023c = cokey a e tccommit
1024if or gt ri 63 eq cohexat c e false
1025coskip
1026ret
1027end
1028for k ulong 40
1029put gcmc add mul m 40 k get fxo add c add k 1
1030end
1031put gcmr m ri
1032put gcmt m ci
1033put gcmn 0 add m 1
1034end
1035fn coareview ci ulong a ulong e ulong to void
1036w = get gcwn 0
1037if ge w 64
1038put gcov 0 1
1039ret
1040end
1041put gcwr w corevix cokey a e tcrevis e
1042v = cokey a e tcverd
1043put gcwv w 0
1044if coseq v e tcaccept
1045put gcwv w 1
1046end
1047if coseq v e tcreject
1048put gcwv w 2
1049end
1050p = cokey a e tcsumm
1051s = get gcpl 0
1052l = cospool p e
1053put gcws mul w 2 s
1054put gcws add mul w 2 1 l
1055put gcwt w ci
1056put gcwn 0 add w 1
1057end
1058fn coarcom ci ulong a ulong e ulong to void
1059coacom ci a e corevix cokey a e tcrevis e
1060end
1061fn coacom ci ulong a ulong e ulong ri ulong to void
1062q = get gcqn 0
1063if ge q COCMMAX
1064put gcov 0 1
1065ret
1066end
1067p = cokey a e tcbody
1068s = get gcpl 0
1069l = cospool p e
1070put gcqr q ri
1071put gcqs mul q 2 s
1072put gcqs add mul q 2 1 l
1073put gcqt q ci
1074put gcqx q 0
1075put gcqn 0 add q 1
1076end
1077fn coaredit a ulong e ulong to void
1078ri = corevix cokey a e tcrevis e
1079if gt ri 63
1080coskip
1081ret
1082end
1083codescset ri a e
1084end
1085fn coarred a ulong e ulong to void
1086ri = corevix cokey a e tcrevis e
1087if lt ri 64
1088put gcrx ri 1
1089end
1090end
1091fn coalabel a ulong e ulong to void
1092p = cokey a e tclabels
1093s = get gcpl 0
1094l = coslist p e
1095put gcm 3 s
1096put gcm 4 l
1097end
1098fn coassign a ulong e ulong to void
1099p = cokey a e tcassn
1100s = get gcpl 0
1101l = coslist p e
1102put gcm 5 s
1103put gcm 6 l
1104end
1105note cocomix: the comment created by the change whose id is the string at p, 9999 when unknown
1106fn cocomix p ulong e ulong to ulong
1107if eq cohexat p e false
1108ret ulong 9999
1109end
1110for q ulong get gcqn 0
1111if cochat get gcqt q add p 1
1112ret q
1113end
1114end
1115ret ulong 9999
1116end
1117fn coacedit a ulong e ulong to void
1118q = cocomix cokey a e tcid e
1119if ge q COCMMAX
1120coskip
1121ret
1122end
1123p = cokey a e tcbody
1124s = get gcpl 0
1125l = cospool p e
1126put gcqs mul q 2 s
1127put gcqs add mul q 2 1 l
1128end
1129fn coacred a ulong e ulong to void
1130q = cocomix cokey a e tcid e
1131if lt q COCMMAX
1132put gcqx q 1
1133end
1134end
1135note costate: 0 open 1 draft 2 closed (archived) 3 merged
1136fn costate to ulong
1137if gt get gcmn 0 0
1138ret ulong 3
1139end
1140ret get gcm 2
1141end
1142note ---- linked verdicts: ~/handoffs/hive/manager/reviews/<repo>-<head sha8>.verdict.txt, first line
1143fn covpc c uchar to void
1144n = get gcvpl 0
1145if lt n 511
1146put gcvp n c
1147put gcvpl 0 add n 1
1148end
1149end
1150fn covpt t view uchar * to void
1151for i ulong len t
1152covpc get t i
1153end
1154end
1155note corepok: the repo name is a plain file-name word ([A-Za-z0-9._-], not starting with a dot)
1156fn corepok to bool
1157n = get frepol 0
1158if or eq n 0 gt n 100
1159ret false
1160end
1161if eq get frepo 0 46
1162ret false
1163end
1164for i ulong n
1165if eq coname get frepo i false
1166ret false
1167end
1168end
1169ret true
1170end
1171fn coname c uchar to bool
1172if or and ge c 48 le c 57 and ge c 97 le c 122
1173ret true
1174end
1175if and ge c 65 le c 90
1176ret true
1177end
1178ret or or eq c 46 eq c 45 eq c 95
1179end
1180fn covlook r ulong to void
1181put gcrvl r 0
1182if eq corepok false
1183ret
1184end
1185put gcvpl 0 0
1186covpt tcrevd
1187for i ulong get frepol 0
1188covpc get frepo i
1189end
1190covpc 45
1191for k ulong 8
1192covpc get gcro add mul r 40 k
1193end
1194covpt tcvsuf
1195fd = fopen gcvp 0 get gcvpl 0 557056 0
1196if lt fd 0
1197ret
1198end
1199nr = read int fd gcvb 0 512
1200x = fclose int fd
1201if le nr 0
1202ret
1203end
1204covcopy r ulong nr
1205end
1206fn covcopy r ulong n ulong to void
1207m = ulong 0
1208for i ulong n
1209c = get gcvb i
1210if or eq c 10 eq c 13
1211break
1212end
1213if lt m 256
1214put gcrvd add mul r 256 m c
1215m = add m 1
1216end
1217end
1218put gcrvl r m
1219if eq covok r false
1220put gcrvl r 0
1221end
1222end
1223note covok r: line 1 of the verdict file is exactly VERDICT (MERGE|MERGE_AFTER_FIX|REJECT) head=<the
1224note revision's 40-hex head>; any other line is not shown, and nothing else of the file (sec P3-1)
1225fn covok r ulong to bool
1226b = mul r 256
1227lim = add b get gcrvl r
1228if eq covat b lim tcvv1 false
1229ret false
1230end
1231p = add b 8
1232w = ulong 0
1233if covat p lim tcvv2
1234w = ulong 21
1235end
1236if covat p lim tcvv3
1237w = ulong 11
1238end
1239if covat p lim tcvv4
1240w = ulong 12
1241end
1242if eq w 0
1243ret false
1244end
1245p = add p w
1246if ne sub lim p 40
1247ret false
1248end
1249for k ulong 40
1250if ne get gcrvd add p k get gcro add mul r 40 k
1251ret false
1252end
1253end
1254ret true
1255end
1256note covat o lim t: gcrvd[o, o + len t) is t and ends by lim
1257fn covat o ulong lim ulong t view uchar * to bool
1258if gt add o len t lim
1259ret false
1260end
1261for i ulong len t
1262if ne get gcrvd add o i get t i
1263ret false
1264end
1265end
1266ret true
1267end
1268note ---- gate receipts and the forge decide word (patch page only, read-only). For revision r the
1269note receipt is ~/handoffs/hive/forge/receipts/<repo>-<head sha8>.receipt.txt (FORGE-RECEIPT v1, as
1270note interplane-mv forge/README.md defines it) and the decision follows forge decide (interplane-mv
1271note forge/forge.om, fn decide) check for check: the verdict is this page's file <repo>-<head8>.verdict.txt
1272note read whole (65536 bytes or more: VERDICT_UNREADABLE); two or more names *-<head8>.receipt.txt in
1273note the receipts folder are RECEIPT_AMBIGUOUS; files of 4096 bytes or more are RECEIPT_UNREADABLE.
1274note Unlike forge, a symlink is never followed (O_NOFOLLOW): it reads as unreadable. A receipt is shown
1275note (gate_rc, negctl_rc, author) only when it is well formed and names this head as its clone.
1276text tcrcpd "/home/drakestapleton/handoffs/hive/forge/receipts/"
1277text tcrsuf ".receipt.txt"
1278text tcrch "FORGE-RECEIPT v1\n"
1279text tcrrid "rid="
1280text tcrcl "clone="
1281text tcrtree "tree="
1282text tcromc "omc="
1283text tcrnone "none"
1284text tcrgc "gate_cmd="
1285text tcrgr "gate_rc="
1286text tcrnc "negctl_cmd="
1287text tcrnr "negctl_rc="
1288text tcrau "author="
1289text tcrst "started="
1290text tcrfi "finished="
1291text tcrls "log_sha256="
1292text tcrnl "negctl_log_sha256="
1293text tcriso "0000-00-00T00:00:00Z"
1294text tcrrad "rad:"
1295text tcrvw "VERDICT"
1296text tcrrev "reviewer="
1297text tcrhd "head="
1298text tcrmaf "MERGE_AFTER_FIX "
1299text tcrmrg "MERGE "
1300text tcrrej "REJECT "
1301note gcdm: verdict [0,65536), receipt [65536,69632), normalized reviewer [69632,135168), normalized
1302note author [135168,139264), getdents64 records [139264,147456), path [147456,147968)
1303global gcdm uchar 147968
1304note gcdg: 1 verdict length, 2 receipt length, 3 verdict kind (1 MERGE 2 MERGE_AFTER_FIX 3 REJECT),
1305note 4 verdict head offset, 5 and 6 reviewer offset and length, 7 clone offset, 8 gate_rc,
1306note 9 negctl_rc, 10 and 11 author offset and length, 12 receipt keys seen
1307global gcdg ulong 16
1308note per revision: decision (0 MERGE OK, forge decide's HOLD code 3..17, 100 nothing to decide),
1309note receipt shown (1), its gate_rc, negctl_rc and author (at most 256 bytes)
1310global gcdw ulong 64
1311global gcrsh ulong 64
1312global gcrgc ulong 64
1313global gcrnc ulong 64
1314global gcrau uchar 16384
1315global gcral ulong 64
1316note cdlook r: read the verdict and receipt of revision r and decide (corepok must hold)
1317fn cdlook r ulong to void
1318put gcdw r 100
1319put gcrsh r 0
1320if eq corepok false
1321ret
1322end
1323pl = cdpath r tcrevd tcvsuf
1324vr = cdload pl 0 65536
1325k = cdscan r
1326rr = long -2
1327if lt k 2
1328pl = cdpath r tcrcpd tcrsuf
1329rr = cdload pl 65536 4096
1330end
1331if and and lt vr 0 eq k 0 eq get gcrvl r 0
1332ret
1333end
1334rc = cdrcode r rr
1335if eq rc 0
1336cdrkeep r
1337end
1338d = cdvcode r vr
1339if eq d 0
1340d = rc
1341end
1342if eq d 0
1343d = cdlast
1344end
1345put gcdw r d
1346end
1347note cdrcode r rr: 17 ambiguous, 9 unreadable, else the receipt check (10 11) then CLONE_MISMATCH (12)
1348fn cdrcode r ulong rr long to ulong
1349if eq rr long -2
1350ret ulong 17
1351end
1352if le rr 0
1353ret ulong 9
1354end
1355put gcdg 2 ulong rr
1356c = cdrcpt
1357if ne c 0
1358ret c
1359end
1360if eq cdhed r get gcdg 7 false
1361ret ulong 12
1362end
1363ret ulong 0
1364end
1365note cdvcode r vr: the verdict checks in forge order (3 4 5 6 7 8), 0 when they pass
1366fn cdvcode r ulong vr long to ulong
1367if le vr 0
1368ret ulong 3
1369end
1370c = cdverd ulong vr
1371if ne c 0
1372ret c
1373end
1374k = get gcdg 3
1375if eq k 2
1376ret ulong 5
1377end
1378if eq k 3
1379ret ulong 6
1380end
1381if eq cdhed r get gcdg 4 false
1382ret ulong 7
1383end
1384if eq get gcdg 6 0
1385ret ulong 8
1386end
1387ret ulong 0
1388end
1389note cdlast: the checks after a valid verdict and receipt: GATE_FAIL, NEGCTL_PASSED, SELF_REVIEW
1390fn cdlast to ulong
1391if ne get gcdg 8 0
1392ret ulong 13
1393end
1394if eq get gcdg 9 0
1395ret ulong 14
1396end
1397if cdauth
1398ret ulong 15
1399end
1400ret ulong 0
1401end
1402fn cdrkeep r ulong to void
1403put gcrsh r 1
1404put gcrgc r get gcdg 8
1405put gcrnc r get gcdg 9
1406n = get gcdg 11
1407if gt n 256
1408n = ulong 256
1409end
1410a = get gcdg 10
1411for i ulong n
1412put gcrau add mul r 256 i get gcdm add a i
1413end
1414put gcral r n
1415end
1416note ---- paths and files
1417fn cdpc n ulong c uchar to ulong
1418if lt n 511
1419put gcdm add 147456 n c
1420ret add n 1
1421end
1422ret n
1423end
1424fn cdpt n ulong t view uchar * to ulong
1425m = n
1426for i ulong len t
1427m = cdpc m get t i
1428end
1429ret m
1430end
1431note cdpath r d s: gcdm[147456,..) = d <repo> - <head sha8 of r> s; the length
1432fn cdpath r ulong d view uchar * s view uchar * to ulong
1433n = cdpt 0 d
1434for i ulong get frepol 0
1435n = cdpc n get frepo i
1436end
1437n = cdpc n 45
1438for k ulong 8
1439n = cdpc n get gcro add mul r 40 k
1440end
1441ret cdpt n s
1442end
1443note cdload pl o cap: read the path into gcdm[o,o+cap); -1 when it cannot be opened (a symlink:
1444note O_RDONLY|O_NONBLOCK|O_NOFOLLOW|O_CLOEXEC 559104) or read, or holds cap bytes or more
1445fn cdload pl ulong o ulong cap ulong to long
1446fl = fopen gcdm 147456 pl 559104 0
1447if lt fl 0
1448ret long -1
1449end
1450fd = int fl
1451n = ulong 0
1452r = long 0
1453note cap + 1 passes at most (cap is 65536 at most): each pass reads 1 byte or more or ends the
1454note loop, and the pass that finds n at cap ends it. The bound was 65536, one short of that for a
1455note file that gives one byte per read; a regular file gives all of it in one read.
1456c = true
1457while c bound 65537
1458if ge n cap
1459c = false
1460else
1461r = read fd gcdm add o n sub cap n
1462if le r 0
1463c = false
1464else
1465n = add n ulong r
1466end
1467end
1468end
1469x = fclose fd
1470if lt r 0
1471ret long -1
1472end
1473if ge n cap
1474ret long -1
1475end
1476ret long n
1477end
1478note cdscan r: the number of names *-<head sha8 of r>.receipt.txt in the receipts folder
1479fn cdscan r ulong to ulong
1480pl = cdpt 0 tcrcpd
1481fl = fopen gcdm 147456 pl 524288 0
1482if lt fl 0
1483ret ulong 0
1484end
1485fd = int fl
1486k = ulong 0
1487c = true
1488while c bound 65536
1489x = getdnts fd gcdm 139264 8192
1490if le x 0
1491c = false
1492else
1493k = add k cddsc r ulong x
1494end
1495end
1496y = fclose fd
1497ret k
1498end
1499fn cddsc r ulong n ulong to ulong
1500k = ulong 0
1501o = ulong 0
1502while lt o n bound 8192
1503b = add 139264 o
1504rl = or ulong get gcdm add b 16 shl ulong get gcdm add b 17 8
1505if cdsuf r add b 19
1506k = add k 1
1507end
1508if eq rl 0
1509o = n
1510else
1511o = add o rl
1512end
1513end
1514ret k
1515end
1516fn cdnlen a ulong to ulong
1517n = ulong 0
1518while and lt n 255 ne get gcdm add a n 0 bound 256
1519n = add n 1
1520end
1521ret n
1522end
1523note cdsuf r a: the entry name at gcdm[a,..) is <one or more bytes>-<head sha8 of r>.receipt.txt
1524fn cdsuf r ulong a ulong to bool
1525nl = cdnlen a
1526t = len tcrsuf
1527if lt nl add t 10
1528ret false
1529end
1530b = sub add a nl add t 9
1531if ne get gcdm b 45
1532ret false
1533end
1534if eq cdhedn r add b 1 8 false
1535ret false
1536end
1537ret cdmat add b 9 add a nl tcrsuf
1538end
1539note ---- scanners over gcdm
1540fn cdmat a ulong lim ulong t view uchar * to bool
1541if gt add a len t lim
1542ret false
1543end
1544for i ulong len t
1545if ne get gcdm add a i get t i
1546ret false
1547end
1548end
1549ret true
1550end
1551fn cdhex a ulong n ulong to bool
1552for i ulong n bound 64
1553if eq cohexc get gcdm add a i false
1554ret false
1555end
1556end
1557ret true
1558end
1559fn cdeol p ulong lim ulong to ulong
1560q = p
1561while lt q lim bound 65536
1562if eq get gcdm q 10
1563ret q
1564end
1565q = add q 1
1566end
1567ret lim
1568end
1569note cdhed r p: gcdm[p,p+40) is the head of revision r
1570fn cdhed r ulong p ulong to bool
1571ret cdhedn r p 40
1572end
1573note cdhedn r p n: gcdm[p,p+n) is the first n hex digits of the head of revision r
1574fn cdhedn r ulong p ulong n ulong to bool
1575o = mul r 40
1576for k ulong n bound 40
1577x = get gcro add o k
1578if ne get gcdm add p k x
1579ret false
1580end
1581end
1582ret true
1583end
1584fn cdeqr a ulong b ulong n ulong to bool
1585for i ulong n bound 65536
1586if ne get gcdm add a i get gcdm add b i
1587ret false
1588end
1589end
1590ret true
1591end
1592note cdtxt v e: 0 when gcdm[v,e) holds a byte in 33..126 and no control byte (below 32 but tab,
1593note or 127), 2 when it holds a control byte, 1 otherwise
1594fn cdtxt v ulong e ulong to ulong
1595vis = false
1596for i ulong sub e v bound 65536
1597c = get gcdm add v i
1598if and lt c 32 ne c 9
1599ret ulong 2
1600end
1601if eq c 127
1602ret ulong 2
1603end
1604if and gt c 32 lt c 127
1605vis = true
1606end
1607end
1608if vis
1609ret ulong 0
1610end
1611ret ulong 1
1612end
1613note ---- the verdict file (forge pverd and scanv): 0, or 4 VERDICT_MALFORMED
1614fn cdverd n ulong to ulong
1615if eq cdmat 0 n tcvv1 false
1616ret ulong 4
1617end
1618p = ulong 8
1619k = ulong 0
1620if cdmat p n tcrmaf
1621k = ulong 2
1622p = add p 16
1623else
1624if cdmat p n tcrmrg
1625k = ulong 1
1626p = add p 6
1627else
1628if cdmat p n tcrrej
1629k = ulong 3
1630p = add p 7
1631end
1632end
1633end
1634if eq k 0
1635ret ulong 4
1636end
1637if eq cdmat p n tcrhd false
1638ret ulong 4
1639end
1640p = add p 5
1641if gt add p 40 n
1642ret ulong 4
1643end
1644if eq cdhex p 40 false
1645ret ulong 4
1646end
1647q = add p 40
1648if lt q n
1649if ne get gcdm q 10
1650ret ulong 4
1651end
1652end
1653put gcdg 3 k
1654put gcdg 4 p
1655ret cdscanv n
1656end
1657note cdscanv: no later line starts with VERDICT, at most one starts with reviewer=
1658fn cdscanv n ulong to ulong
1659p = add cdeol 0 n 1
1660put gcdg 5 0
1661put gcdg 6 0
1662seen = false
1663while lt p n bound 65536
1664e = cdeol p n
1665if cdmat p e tcrvw
1666ret ulong 4
1667end
1668if cdmat p e tcrrev
1669if seen
1670ret ulong 4
1671end
1672seen = true
1673t = cdtxt add p 9 e
1674if eq t 2
1675ret ulong 4
1676end
1677if eq t 0
1678put gcdg 5 add p 9
1679put gcdg 6 sub e add p 9
1680end
1681end
1682p = add e 1
1683end
1684ret ulong 0
1685end
1686note ---- the receipt (forge prcpt and rkey): 0, 10 RECEIPT_MALFORMED or 11 NO_NEGCTL. Keys seen:
1687note 1 clone 2 gate_rc 4 negctl_rc 8 author 16 gate_cmd 32 negctl_cmd 64 tree 128 rid 256 omc
1688note 512 started 1024 finished 2048 log_sha256 4096 negctl_log_sha256
1689fn cdrcpt to ulong
1690b = ulong 65536
1691n = add b get gcdg 2
1692if eq cdmat b n tcrch false
1693ret ulong 10
1694end
1695p = add b 17
1696put gcdg 12 0
1697while lt p n bound 4096
1698e = cdeol p n
1699r = cdrkey p e
1700if ne r 0
1701ret r
1702end
1703p = add e 1
1704end
1705s = get gcdg 12
1706if ne and s 11 11
1707ret ulong 10
1708end
1709if eq and s 4 0
1710ret ulong 11
1711end
1712ret ulong 0
1713end
1714fn cdonce bit ulong to ulong
1715s = get gcdg 12
1716if ne and s bit 0
1717ret ulong 10
1718end
1719put gcdg 12 or s bit
1720ret ulong 0
1721end
1722fn cdrhex p ulong e ulong t view uchar * bit ulong n ulong to ulong
1723v = add p len t
1724if ne sub e v n
1725ret ulong 10
1726end
1727if eq cdhex v n false
1728ret ulong 10
1729end
1730ret cdonce bit
1731end
1732fn cdrkey p ulong e ulong to ulong
1733if cdmat p e tcrcl
1734put gcdg 7 add p 6
1735ret cdrhex p e tcrcl 1 40
1736end
1737if cdmat p e tcrgr
1738d = cdnum add p 8 e
1739if eq d 1000
1740ret ulong 10
1741end
1742put gcdg 8 d
1743ret cdonce 2
1744end
1745if cdmat p e tcrnr
1746d = cdnum add p 10 e
1747if eq d 1000
1748ret ulong 10
1749end
1750put gcdg 9 d
1751ret cdonce 4
1752end
1753if cdmat p e tcrau
1754v = add p 7
1755if ne cdtxt v e 0
1756ret ulong 10
1757end
1758put gcdg 10 v
1759put gcdg 11 sub e v
1760ret cdonce 8
1761end
1762if cdmat p e tcrgc
1763ret cdonce 16
1764end
1765if cdmat p e tcrnc
1766ret cdonce 32
1767end
1768ret cdrkey2 p e
1769end
1770fn cdrkey2 p ulong e ulong to ulong
1771if cdmat p e tcrtree
1772ret cdrhex p e tcrtree 64 40
1773end
1774if cdmat p e tcrrid
1775if eq cdrid add p 4 e false
1776ret ulong 10
1777end
1778ret cdonce 128
1779end
1780if cdmat p e tcromc
1781if and eq sub e p 8 cdmat add p 4 e tcrnone
1782ret cdonce 256
1783end
1784ret cdrhex p e tcromc 256 64
1785end
1786if cdmat p e tcrst
1787if eq cdiso add p 8 e false
1788ret ulong 10
1789end
1790ret cdonce 512
1791end
1792if cdmat p e tcrfi
1793if eq cdiso add p 9 e false
1794ret ulong 10
1795end
1796ret cdonce 1024
1797end
1798if cdmat p e tcrls
1799ret cdrhex p e tcrls 2048 64
1800end
1801if cdmat p e tcrnl
1802ret cdrhex p e tcrnl 4096 64
1803end
1804ret ulong 10
1805end
1806note cdnum v e: 1 to 3 decimal digits, at most 255; 1000 otherwise
1807fn cdnum v ulong e ulong to ulong
1808n = sub e v
1809if or eq n 0 gt n 3
1810ret ulong 1000
1811end
1812x = ulong 0
1813for i ulong n bound 3
1814c = get gcdm add v i
1815if or lt c 48 gt c 57
1816ret ulong 1000
1817end
1818x = add mul x 10 sub ulong c 48
1819end
1820if gt x 255
1821ret ulong 1000
1822end
1823ret x
1824end
1825note cdrid v e: rad: then 1 to 60 ASCII letters and digits
1826fn cdrid v ulong e ulong to bool
1827n = sub e v
1828if or lt n 5 gt n 64
1829ret false
1830end
1831if eq cdmat v e tcrrad false
1832ret false
1833end
1834for i ulong sub n 4 bound 64
1835c = get gcdm add v add 4 i
1836if eq coname c false
1837ret false
1838end
1839if or eq c 46 or eq c 45 eq c 95
1840ret false
1841end
1842end
1843ret true
1844end
1845note cdiso v e: YYYY-MM-DDTHH:MM:SSZ (a digit where tcriso holds 0)
1846fn cdiso v ulong e ulong to bool
1847if ne sub e v 20
1848ret false
1849end
1850for i ulong 20
1851c = get gcdm add v i
1852w = get tcriso i
1853if eq w 48
1854if or lt c 48 gt c 57
1855ret false
1856end
1857else
1858if ne c w
1859ret false
1860end
1861end
1862end
1863ret true
1864end
1865note ---- SELF_REVIEW (forge hasauth): the normalized reviewer text contains the normalized author;
1866note an author that normalizes to nothing counts as self-review
1867fn cdauth to bool
1868rn = cdnorm get gcdg 5 get gcdg 6 69632
1869an = cdnorm get gcdg 10 get gcdg 11 135168
1870if eq an 0
1871ret true
1872end
1873if gt an rn
1874ret false
1875end
1876lim = sub rn an
1877i = ulong 0
1878while le i lim bound 65536
1879if cdeqr add 69632 i 135168 an
1880ret true
1881end
1882i = add i 1
1883end
1884ret false
1885end
1886note cdnorm s n d: copy gcdm[s,s+n) to d folded to ASCII lower case, each run of space, tab, _ and -
1887note as one space, then spaces and ASCII punctuation stripped from both ends; the length
1888fn cdnorm s ulong n ulong d ulong to ulong
1889o = ulong 0
1890last = ulong 32
1891for i ulong n bound 65536
1892c = ulong get gcdm add s i
1893if or or eq c 32 eq c 9 or eq c 95 eq c 45
1894if ne last 32
1895put gcdm add d o 32
1896o = add o 1
1897last = ulong 32
1898end
1899else
1900if and ge c 65 le c 90
1901c = add c 32
1902end
1903put gcdm add d o uchar c
1904o = add o 1
1905last = c
1906end
1907end
1908ret cdstrip d o
1909end
1910fn cdstrip d ulong n ulong to ulong
1911e = n
1912c = true
1913while c bound 65536
1914if eq e 0
1915c = false
1916else
1917if cdpun get gcdm add d sub e 1
1918e = sub e 1
1919else
1920c = false
1921end
1922end
1923end
1924s = ulong 0
1925c = true
1926while c bound 65536
1927if ge s e
1928c = false
1929else
1930if cdpun get gcdm add d s
1931s = add s 1
1932else
1933c = false
1934end
1935end
1936end
1937for i ulong sub e s bound 65536
1938put gcdm add d i get gcdm add d add s i
1939end
1940ret sub e s
1941end
1942fn cdpun c uchar to bool
1943if eq c 32
1944ret true
1945end
1946if and ge c 33 le c 47
1947ret true
1948end
1949if and ge c 58 le c 64
1950ret true
1951end
1952if and ge c 91 le c 96
1953ret true
1954end
1955ret and ge c 123 le c 126
1956end