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