interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / tools / bring / src / 50patch.om
| 1 | note tools/bring/src/50patch.om: interplane patch [--base REF] [--title T] [--message-file F] [--yes] |
| 2 | note OWNER/REPO. Run inside a git work tree. It resolves the base (default: the merge base of HEAD |
| 3 | note and refs/remotes/origin/main), builds the mbox with /usr/bin/git format-patch (an argument list, |
| 4 | note no shell, an empty environment), shows what would be sent and sends only after --yes or the |
| 5 | note exact "yes" typed on /dev/tty: the key (made once, as bring makes it), the statement signed with |
| 6 | note namespace interplane-patch, the sign-in of bring, one POST to <base>/OWNER/REPO/patches/new. |
| 7 | note Exit 0 sent (the patch page is printed), 1 nothing sent, 2 the server refused it (its reason |
| 8 | note is printed). The key never leaves this computer; the forge never signs for anyone. |
| 9 | text tqprog "/usr/bin/git" |
| 10 | text tqrp "rev-parse" |
| 11 | text tqiw "--is-inside-work-tree" |
| 12 | text tqtrue "true" |
| 13 | text tqver "--verify" |
| 14 | text tqqt "--quiet" |
| 15 | text tqeoo "--end-of-options" |
| 16 | text tqcmt "^{commit}" |
| 17 | text tqhd "HEAD" |
| 18 | text tqmb "merge-base" |
| 19 | text tqorg "refs/remotes/origin/main" |
| 20 | text tqfp "format-patch" |
| 21 | text tqso "--stdout" |
| 22 | text tqo1 "--no-color" |
| 23 | text tqo2 "--no-ext-diff" |
| 24 | text tqo3 "--no-textconv" |
| 25 | text tqo4 "--no-attach" |
| 26 | text tqo5 "--no-thread" |
| 27 | text tqo6 "--no-cover-letter" |
| 28 | text tqo7 "--src-prefix=a/" |
| 29 | text tqo8 "--dst-prefix=b/" |
| 30 | text tqo9 "--no-signature" |
| 31 | text tqo10 "--no-relative" |
| 32 | text tqo11 "--no-notes" |
| 33 | text tqrl "rev-list" |
| 34 | text tqcnt "--count" |
| 35 | text tqdf "diff" |
| 36 | text tqnmo "--name-only" |
| 37 | text tqz "-z" |
| 38 | text tqlog "log" |
| 39 | text tqm1 "-1" |
| 40 | text tqfs "--format=%s" |
| 41 | text tqdots ".." |
| 42 | text tqmbox "mbox" |
| 43 | text tqgout "gout" |
| 44 | text tqfb "--base" |
| 45 | text tqft "--title" |
| 46 | text tqfm "--message-file" |
| 47 | text tqfy "--yes" |
| 48 | text tqns "interplane-patch" |
| 49 | text tqst1 "interplane-patch 1\n" |
| 50 | text tqslash "/" |
| 51 | text tqpnew "/patches/new" |
| 52 | text tqfrepo "&repo=" |
| 53 | text tqfbase "&base=" |
| 54 | text tqfttl "&title=" |
| 55 | text tqfdsc "&description=" |
| 56 | text tqfmbx "&mbox=" |
| 57 | text tqfsig "&sig=" |
| 58 | text tqpath "path " |
| 59 | text tqrefu "refused: " |
| 60 | text tqusage "usage: interplane patch [--base REF] [--title T] [--message-file F] [--yes] OWNER/REPO" |
| 61 | text tqnowt "this folder is not inside a git work tree" |
| 62 | text tqnohd "this work tree has no commit at HEAD" |
| 63 | text tqnobs "cannot find the remote's main (refs/remotes/origin/main); name the base with --base REF" |
| 64 | text tqbadb "the --base value does not name a commit here" |
| 65 | text tqnone "there is no commit between the base and HEAD: nothing to send" |
| 66 | text tqmany "more than 100 commits between the base and HEAD: a patch holds at most 100" |
| 67 | text tqbig "the patch is larger than 2097152 bytes: nothing sent" |
| 68 | text tqgit "git could not build the patch" |
| 69 | text tqttlb "the title must be 1 to 256 bytes on one line; give one with --title" |
| 70 | text tqdscb "the message file must hold at most 60000 bytes" |
| 71 | text tqdscf "cannot read the message file" |
| 72 | text tqs1 "Repository: " |
| 73 | text tqs2 "Base: " |
| 74 | text tqs3 "Commits: " |
| 75 | text tqs4 "Files changed: " |
| 76 | text tqs5 "Bytes: " |
| 77 | text tqs6 "Title: " |
| 78 | text tqs7 "Send to: " |
| 79 | text tqask "Type yes to send this patch, anything else to stop:\n" |
| 80 | text tqpage "Patch page: " |
| 81 | text tqhave "Interplane already has this patch.\n" |
| 82 | text tqref "Interplane refused the patch: " |
| 83 | text tqno "Nothing sent.\n" |
| 84 | text tqsetp "/settings" |
| 85 | global gqrepo uchar 256 |
| 86 | global gqrepol ulong 1 |
| 87 | global gqbref uchar 4096 |
| 88 | global gqbrefl ulong 1 |
| 89 | global gqmsgf uchar 4096 |
| 90 | global gqmsgfl ulong 1 |
| 91 | global gqbase uchar 40 |
| 92 | global gqttl uchar 256 |
| 93 | global gqttll ulong 1 |
| 94 | global gqdsc uchar 60000 |
| 95 | global gqdscl ulong 1 |
| 96 | global gqyes ulong 1 |
| 97 | global gqncm ulong 1 |
| 98 | global gqnfl ulong 1 |
| 99 | global gqbytes ulong 1 |
| 100 | note ---- arguments |
| 101 | fn ptrepoc c uchar to bool |
| 102 | if isaln c |
| 103 | ret true |
| 104 | end |
| 105 | ret or or eq c 45 eq c 46 eq c 95 |
| 106 | end |
| 107 | note ptrepo: OWNER/REPO: two names of letters, digits, '.', '-' and '_' around one slash |
| 108 | fn ptrepo a view uchar * to void |
| 109 | sl = ulong 0 |
| 110 | ns = ulong 0 |
| 111 | for i ulong len a bound 256 |
| 112 | c = get a i |
| 113 | if eq c 47 |
| 114 | ns = add ns 1 |
| 115 | sl = i |
| 116 | else |
| 117 | if not ptrepoc c |
| 118 | die tqusage |
| 119 | end |
| 120 | end |
| 121 | end |
| 122 | if or ne ns 1 eq sl 0 |
| 123 | die tqusage |
| 124 | end |
| 125 | if or eq add sl 1 len a eq get a 0 46 |
| 126 | die tqusage |
| 127 | end |
| 128 | if eq get a add sl 1 46 |
| 129 | die tqusage |
| 130 | end |
| 131 | for i ulong len a bound 256 |
| 132 | put gqrepo i get a i |
| 133 | end |
| 134 | put gqrepol 0 len a |
| 135 | end |
| 136 | fn ptflag a view uchar * t view uchar * to bool |
| 137 | ret beq a t |
| 138 | end |
| 139 | note ptval i ac w: the value of the flag at argument i (the next argument) into its global: w 0 |
| 140 | note --base (no leading '-'), 1 --title (1..256 bytes), 2 --message-file |
| 141 | fn ptval i ulong ac ulong w ulong to void |
| 142 | a = new uchar 4096 0 |
| 143 | if ge add i 1 ac |
| 144 | die tqusage |
| 145 | end |
| 146 | n = getarg add i 1 a |
| 147 | if eq n 0 |
| 148 | die tqusage |
| 149 | end |
| 150 | if eq w 0 |
| 151 | if eq get a 0 45 |
| 152 | die tqbadb |
| 153 | end |
| 154 | for k ulong n bound 4096 |
| 155 | put gqbref k get a k |
| 156 | end |
| 157 | put gqbrefl 0 n |
| 158 | end |
| 159 | if eq w 1 |
| 160 | if gt n 256 |
| 161 | die tqttlb |
| 162 | end |
| 163 | for k ulong n bound 256 |
| 164 | put gqttl k get a k |
| 165 | end |
| 166 | put gqttll 0 n |
| 167 | end |
| 168 | if eq w 2 |
| 169 | for k ulong n bound 4096 |
| 170 | put gqmsgf k get a k |
| 171 | end |
| 172 | put gqmsgfl 0 n |
| 173 | end |
| 174 | end |
| 175 | note ptargs: ac counts the program and "patch". The tool takes at most 8 arguments after "patch" |
| 176 | note (--base REF, --title T, --message-file F, --yes, OWNER/REPO): more is the usage line (exit 1), |
| 177 | note answered before the loop, so the loop runs at most 8 times whatever the argument count. |
| 178 | fn ptargs ac ulong to void |
| 179 | if gt ac 10 |
| 180 | die tqusage |
| 181 | end |
| 182 | a = new uchar 4096 0 |
| 183 | got = false |
| 184 | i = ulong 2 |
| 185 | while lt i ac bound 8 |
| 186 | n = getarg i a |
| 187 | w = ulong 9 |
| 188 | if ptflag part a 0 n tqfb |
| 189 | w = ulong 0 |
| 190 | end |
| 191 | if ptflag part a 0 n tqft |
| 192 | w = ulong 1 |
| 193 | end |
| 194 | if ptflag part a 0 n tqfm |
| 195 | w = ulong 2 |
| 196 | end |
| 197 | if ptflag part a 0 n tqfy |
| 198 | w = ulong 3 |
| 199 | end |
| 200 | if lt w 3 |
| 201 | ptval i ac w |
| 202 | i = add i 1 |
| 203 | end |
| 204 | if eq w 3 |
| 205 | put gqyes 0 1 |
| 206 | end |
| 207 | if eq w 9 |
| 208 | if or got eq n 0 |
| 209 | die tqusage |
| 210 | end |
| 211 | if or eq get a 0 45 gt n 200 |
| 212 | die tqusage |
| 213 | end |
| 214 | ptrepo part a 0 n |
| 215 | got = true |
| 216 | end |
| 217 | i = add i 1 |
| 218 | end |
| 219 | if not got |
| 220 | die tqusage |
| 221 | end |
| 222 | end |
| 223 | note ---- git: an argument list, standard output into the temp file gout (or mbox), no shell |
| 224 | note gitline: the first line of gout into o; its length |
| 225 | fn gitline o edit uchar 4096 to ulong |
| 226 | fd = topen tqgout 0 |
| 227 | n = read fd o 0 4096 |
| 228 | pl_close fd |
| 229 | if lt n 0 |
| 230 | die terrio |
| 231 | end |
| 232 | k = ulong 0 |
| 233 | while lt k ulong n bound 4096 |
| 234 | if eq get o k 10 |
| 235 | break |
| 236 | end |
| 237 | k = add k 1 |
| 238 | end |
| 239 | ret k |
| 240 | end |
| 241 | fn ishex40 o view uchar * to bool |
| 242 | if ne len o 40 |
| 243 | ret false |
| 244 | end |
| 245 | for i ulong 40 |
| 246 | c = get o i |
| 247 | h = or isdig c and ge c 97 le c 102 |
| 248 | if not h |
| 249 | ret false |
| 250 | end |
| 251 | end |
| 252 | ret true |
| 253 | end |
| 254 | note gitcommit ref eoo: rev-parse --verify --quiet [--end-of-options] <ref>^{commit}: the 40 hex |
| 255 | note digits into o; false when ref names no commit |
| 256 | fn gitcommit ref view uchar * eoo bool o edit uchar 40 to bool |
| 257 | a = new uchar 4096 0 |
| 258 | q = new uchar 4200 0 |
| 259 | l = new uchar 4096 0 |
| 260 | avinit a |
| 261 | avadd a tqprog |
| 262 | avadd a tqrp |
| 263 | avadd a tqver |
| 264 | avadd a tqqt |
| 265 | if eoo |
| 266 | avadd a tqeoo |
| 267 | end |
| 268 | n = cpy q 0 ref |
| 269 | n = cpy q n tqcmt |
| 270 | avadd a part q 0 n |
| 271 | if ne runprog a tqgout 0 |
| 272 | ret false |
| 273 | end |
| 274 | k = gitline l |
| 275 | if not ishex40 part l 0 k |
| 276 | ret false |
| 277 | end |
| 278 | for i ulong 40 |
| 279 | put o i get l i |
| 280 | end |
| 281 | ret true |
| 282 | end |
| 283 | note ptrange: "<base>..HEAD" into q; its length |
| 284 | fn ptrange q edit uchar 64 to ulong |
| 285 | for i ulong 40 |
| 286 | put q i get gqbase i |
| 287 | end |
| 288 | n = cpy q 40 tqdots |
| 289 | ret cpy q n tqhd |
| 290 | end |
| 291 | fn ptbase to void |
| 292 | b = new uchar 40 0 |
| 293 | a = new uchar 4096 0 |
| 294 | l = new uchar 4096 0 |
| 295 | r = new uchar 4096 0 |
| 296 | if gt get gqbrefl 0 0 |
| 297 | n = get gqbrefl 0 |
| 298 | for i ulong n bound 4096 |
| 299 | put r i get gqbref i |
| 300 | end |
| 301 | if not gitcommit part r 0 n true b |
| 302 | die tqbadb |
| 303 | end |
| 304 | else |
| 305 | avinit a |
| 306 | avadd a tqprog |
| 307 | avadd a tqmb |
| 308 | avadd a tqhd |
| 309 | avadd a tqorg |
| 310 | if ne runprog a tqgout 0 |
| 311 | die tqnobs |
| 312 | end |
| 313 | k = gitline l |
| 314 | if not ishex40 part l 0 k |
| 315 | die tqnobs |
| 316 | end |
| 317 | for i ulong 40 |
| 318 | put b i get l i |
| 319 | end |
| 320 | end |
| 321 | for i ulong 40 |
| 322 | put gqbase i get b i |
| 323 | end |
| 324 | end |
| 325 | note ptcount: the commits of base..HEAD (1..100) |
| 326 | fn ptcount to void |
| 327 | a = new uchar 4096 0 |
| 328 | l = new uchar 4096 0 |
| 329 | q = new uchar 64 0 |
| 330 | v = new ulong 1 0 |
| 331 | avinit a |
| 332 | avadd a tqprog |
| 333 | avadd a tqrl |
| 334 | avadd a tqcnt |
| 335 | n = ptrange q |
| 336 | avadd a part q 0 n |
| 337 | if ne runprog a tqgout 0 |
| 338 | die tqgit |
| 339 | end |
| 340 | k = gitline l |
| 341 | if not pdec part l 0 k v |
| 342 | die tqgit |
| 343 | end |
| 344 | if eq get v 0 0 |
| 345 | die tqnone |
| 346 | end |
| 347 | if gt get v 0 100 |
| 348 | die tqmany |
| 349 | end |
| 350 | put gqncm 0 get v 0 |
| 351 | end |
| 352 | note ptmbox: git format-patch --stdout base..HEAD into the temp file mbox; its size in gqbytes |
| 353 | fn ptmbox to void |
| 354 | a = new uchar 4096 0 |
| 355 | q = new uchar 64 0 |
| 356 | st = new uchar 256 0 |
| 357 | avinit a |
| 358 | avadd a tqprog |
| 359 | avadd a tqfp |
| 360 | avadd a tqso |
| 361 | avadd a tqo1 |
| 362 | avadd a tqo2 |
| 363 | avadd a tqo3 |
| 364 | avadd a tqo4 |
| 365 | avadd a tqo5 |
| 366 | avadd a tqo6 |
| 367 | avadd a tqo7 |
| 368 | avadd a tqo8 |
| 369 | avadd a tqo9 |
| 370 | avadd a tqo10 |
| 371 | avadd a tqo11 |
| 372 | n = ptrange q |
| 373 | avadd a part q 0 n |
| 374 | if ne runprog a tqmbox 0 |
| 375 | die tqgit |
| 376 | end |
| 377 | fd = topen tqmbox 0 |
| 378 | if lt pl_fstat fd st 0 |
| 379 | die terrio |
| 380 | end |
| 381 | pl_close fd |
| 382 | sz = pl_size st |
| 383 | if gt sz 2097152 |
| 384 | die tqbig |
| 385 | end |
| 386 | put gqbytes 0 sz |
| 387 | end |
| 388 | note ptfiles: the files base and HEAD differ in (the names of git diff --name-only -z, counted) |
| 389 | fn ptfiles to void |
| 390 | a = new uchar 4096 0 |
| 391 | b = new uchar 65536 0 |
| 392 | avinit a |
| 393 | avadd a tqprog |
| 394 | avadd a tqdf |
| 395 | avadd a tqnmo |
| 396 | avadd a tqz |
| 397 | for i ulong 40 |
| 398 | put b i get gqbase i |
| 399 | end |
| 400 | avadd a part b 0 40 |
| 401 | avadd a tqhd |
| 402 | if ne runprog a tqgout 0 |
| 403 | die tqgit |
| 404 | end |
| 405 | fd = topen tqgout 0 |
| 406 | c = ulong 0 |
| 407 | while true bound 9223372036854775807 |
| 408 | r = read fd b 0 65536 |
| 409 | if eq r -4 |
| 410 | continue |
| 411 | end |
| 412 | if lt r 0 |
| 413 | die terrio |
| 414 | end |
| 415 | if eq r 0 |
| 416 | break |
| 417 | end |
| 418 | for i ulong ulong r bound 65536 |
| 419 | if eq get b i 0 |
| 420 | c = add c 1 |
| 421 | end |
| 422 | end |
| 423 | end |
| 424 | pl_close fd |
| 425 | put gqnfl 0 c |
| 426 | end |
| 427 | note pttitle: the title: --title, else the subject of the HEAD commit; 1..256 bytes, no control byte |
| 428 | fn pttitle to void |
| 429 | a = new uchar 4096 0 |
| 430 | l = new uchar 4096 0 |
| 431 | if eq get gqttll 0 0 |
| 432 | avinit a |
| 433 | avadd a tqprog |
| 434 | avadd a tqlog |
| 435 | avadd a tqm1 |
| 436 | avadd a tqfs |
| 437 | avadd a tqhd |
| 438 | if ne runprog a tqgout 0 |
| 439 | die tqgit |
| 440 | end |
| 441 | k = gitline l |
| 442 | if or eq k 0 gt k 256 |
| 443 | die tqttlb |
| 444 | end |
| 445 | for i ulong k bound 256 |
| 446 | put gqttl i get l i |
| 447 | end |
| 448 | put gqttll 0 k |
| 449 | end |
| 450 | for i ulong get gqttll 0 bound 256 |
| 451 | c = get gqttl i |
| 452 | if or lt c 32 eq c 127 |
| 453 | die tqttlb |
| 454 | end |
| 455 | end |
| 456 | end |
| 457 | note ptdesc: the description from --message-file (none: empty): carriage returns dropped, blanks |
| 458 | note and line feeds at the end trimmed, at most 60000 bytes |
| 459 | fn ptdesc to void |
| 460 | p = new uchar 4096 0 |
| 461 | b = new uchar 65536 0 |
| 462 | put gqdscl 0 0 |
| 463 | n = get gqmsgfl 0 |
| 464 | if eq n 0 |
| 465 | ret |
| 466 | end |
| 467 | for i ulong n bound 4096 |
| 468 | put p i get gqmsgf i |
| 469 | end |
| 470 | fd = pl_open part p 0 n 4 0 |
| 471 | if lt fd 0 |
| 472 | die tqdscf |
| 473 | end |
| 474 | k = ulong 0 |
| 475 | while true bound 9223372036854775807 |
| 476 | r = read int fd b 0 65536 |
| 477 | if eq r -4 |
| 478 | continue |
| 479 | end |
| 480 | if lt r 0 |
| 481 | die tqdscf |
| 482 | end |
| 483 | if eq r 0 |
| 484 | break |
| 485 | end |
| 486 | for i ulong ulong r bound 65536 |
| 487 | c = get b i |
| 488 | if ne c 13 |
| 489 | if ge k 60000 |
| 490 | die tqdscb |
| 491 | end |
| 492 | put gqdsc k c |
| 493 | k = add k 1 |
| 494 | end |
| 495 | end |
| 496 | end |
| 497 | pl_close int fd |
| 498 | while gt k 0 bound 60000 |
| 499 | c = get gqdsc sub k 1 |
| 500 | if and and ne c 10 ne c 32 ne c 9 |
| 501 | break |
| 502 | end |
| 503 | k = sub k 1 |
| 504 | end |
| 505 | put gqdscl 0 k |
| 506 | end |
| 507 | note ---- what would be sent |
| 508 | fn ptshow to void |
| 509 | t = new uchar 4096 0 |
| 510 | n = get gqrepol 0 |
| 511 | for i ulong n bound 256 |
| 512 | put t i get gqrepo i |
| 513 | end |
| 514 | say tqs1 |
| 515 | say part t 0 n |
| 516 | say tnl |
| 517 | for i ulong 40 |
| 518 | put t i get gqbase i |
| 519 | end |
| 520 | say tqs2 |
| 521 | say part t 0 40 |
| 522 | say tnl |
| 523 | say tqs3 |
| 524 | sayd get gqncm 0 |
| 525 | say tnl |
| 526 | say tqs4 |
| 527 | sayd get gqnfl 0 |
| 528 | say tnl |
| 529 | say tqs5 |
| 530 | sayd get gqbytes 0 |
| 531 | say tnl |
| 532 | n = get gqttll 0 |
| 533 | for i ulong n bound 256 |
| 534 | put t i get gqttl i |
| 535 | end |
| 536 | say tqs6 |
| 537 | sayp part t 0 n |
| 538 | say tnl |
| 539 | n = gcopy 0 t |
| 540 | say tqs7 |
| 541 | say part t 0 n |
| 542 | say tnl |
| 543 | end |
| 544 | note ---- the statement: "interplane-patch 1\n<owner>/<repo>\n<base>\n<sha256 of the mbox>\n<sha256 of |
| 545 | note title, line feed, description>\n" into the temp file stmt |
| 546 | fn ptstmt to void |
| 547 | d = new uchar 32 0 |
| 548 | x = new uchar 64 0 |
| 549 | t = new uchar 60300 0 |
| 550 | fd = topen tqmbox 0 |
| 551 | shafd fd d |
| 552 | pl_close fd |
| 553 | k = hexw d x 0 |
| 554 | fd = tmpfd tstmt |
| 555 | mustwrite fd tqst1 |
| 556 | n = get gqrepol 0 |
| 557 | for i ulong n bound 256 |
| 558 | put t i get gqrepo i |
| 559 | end |
| 560 | mustwrite fd part t 0 n |
| 561 | mustwrite fd tnl |
| 562 | for i ulong 40 |
| 563 | put t i get gqbase i |
| 564 | end |
| 565 | mustwrite fd part t 0 40 |
| 566 | mustwrite fd tnl |
| 567 | mustwrite fd x |
| 568 | mustwrite fd tnl |
| 569 | n = get gqttll 0 |
| 570 | for i ulong n bound 256 |
| 571 | put t i get gqttl i |
| 572 | end |
| 573 | put t n 10 |
| 574 | m = get gqdscl 0 |
| 575 | for i ulong m bound 60000 |
| 576 | put t add add n 1 i get gqdsc i |
| 577 | end |
| 578 | y = sha2_digest 256 part t 0 add add n 1 m d |
| 579 | k = hexw d x 0 |
| 580 | mustwrite fd x |
| 581 | mustwrite fd tnl |
| 582 | pl_close fd |
| 583 | end |
| 584 | note ---- the form: csrf, repo, base, title, description, mbox (base64url, no padding), sig |
| 585 | fn ptfdesc fd int to void |
| 586 | b = new uchar 4096 0 |
| 587 | n = get gqdscl 0 |
| 588 | p = ulong 0 |
| 589 | while lt p n bound 60000 |
| 590 | k = sub n p |
| 591 | if gt k 4096 |
| 592 | k = ulong 4096 |
| 593 | end |
| 594 | for i ulong k bound 4096 |
| 595 | put b i get gqdsc add p i |
| 596 | end |
| 597 | formenc fd part b 0 k |
| 598 | p = add p k |
| 599 | end |
| 600 | end |
| 601 | fn ptfmbox fd int to void |
| 602 | b = new uchar 45000 0 |
| 603 | e = new uchar 60000 0 |
| 604 | src = topen tqmbox 0 |
| 605 | while true bound 9223372036854775807 |
| 606 | k = ulong 0 |
| 607 | while lt k 45000 bound 9223372036854775807 |
| 608 | r = read src b k sub 45000 k |
| 609 | if eq r -4 |
| 610 | continue |
| 611 | end |
| 612 | if lt r 0 |
| 613 | die terrio |
| 614 | end |
| 615 | if eq r 0 |
| 616 | break |
| 617 | end |
| 618 | k = add k ulong r |
| 619 | end |
| 620 | if eq k 0 |
| 621 | break |
| 622 | end |
| 623 | el = b64u part b 0 k e |
| 624 | mustwrite fd part e 0 el |
| 625 | if lt k 45000 |
| 626 | break |
| 627 | end |
| 628 | end |
| 629 | pl_close src |
| 630 | end |
| 631 | fn ptform to void |
| 632 | t = new uchar 4096 0 |
| 633 | fd = tmpfd tform |
| 634 | csrfform fd |
| 635 | mustwrite fd tqfrepo |
| 636 | n = get gqrepol 0 |
| 637 | for i ulong n bound 256 |
| 638 | put t i get gqrepo i |
| 639 | end |
| 640 | formenc fd part t 0 n |
| 641 | mustwrite fd tqfbase |
| 642 | for i ulong 40 |
| 643 | put t i get gqbase i |
| 644 | end |
| 645 | mustwrite fd part t 0 40 |
| 646 | mustwrite fd tqfttl |
| 647 | n = get gqttll 0 |
| 648 | for i ulong n bound 256 |
| 649 | put t i get gqttl i |
| 650 | end |
| 651 | formenc fd part t 0 n |
| 652 | mustwrite fd tqfdsc |
| 653 | ptfdesc fd |
| 654 | mustwrite fd tqfmbx |
| 655 | ptfmbox fd |
| 656 | mustwrite fd tqfsig |
| 657 | formsig fd tstsig |
| 658 | pl_close fd |
| 659 | end |
| 660 | note ptsend: POST the form. A 429 (the write gate: 30 writes a minute) sends the same form again at |
| 661 | note most 3 times, after 2, 4 and 8 seconds (4 POSTs and 14 seconds of waiting at most; the tool |
| 662 | note reads no Retry-After); a 429 after that is a refusal like any other code. 201 and 200 print the |
| 663 | note patch page and return; anything else prints the server's reason in one line and leaves with |
| 664 | note status 2. |
| 665 | fn ptsend to void |
| 666 | p = new uchar 4096 0 |
| 667 | v = new uchar 4096 0 |
| 668 | e = new uchar 24 0 |
| 669 | n = cpy p 0 tqslash |
| 670 | m = get gqrepol 0 |
| 671 | for i ulong m bound 256 |
| 672 | put p add n i get gqrepo i |
| 673 | end |
| 674 | n = cpy p add n m tqpnew |
| 675 | c = http part p 0 n true tbody |
| 676 | w = ulong 2 |
| 677 | while and eq c 429 le w 8 bound 3 |
| 678 | for i ulong w bound 8 |
| 679 | pl_sleep |
| 680 | end |
| 681 | c = http part p 0 n true tbody |
| 682 | w = mul w 2 |
| 683 | end |
| 684 | if or eq c 201 eq c 200 |
| 685 | k = mustval tqpath 10 v |
| 686 | if eq c 200 |
| 687 | say tqhave |
| 688 | end |
| 689 | say tqpage |
| 690 | m = gcopy 0 p |
| 691 | say part p 0 m |
| 692 | say part v 0 k |
| 693 | say tnl |
| 694 | ret |
| 695 | end |
| 696 | r = fval tbody tqrefu 10 |
| 697 | warn tpfx |
| 698 | if ge r 0 |
| 699 | for i ulong ulong r bound 4096 |
| 700 | put v i get gval i |
| 701 | end |
| 702 | warn tqref |
| 703 | warn part v 0 ulong r |
| 704 | else |
| 705 | k = decw c e 0 |
| 706 | warn thttpbad |
| 707 | warn part e 0 k |
| 708 | end |
| 709 | warn tnl |
| 710 | cleanup |
| 711 | exit 2 |
| 712 | end |
| 713 | note patchflow: the whole command; ac is the argument count. Returns the exit status 0 or 1. |
| 714 | fn patchflow ac ulong to int |
| 715 | pk = new uchar 32 0 |
| 716 | a = new uchar 4096 0 |
| 717 | l = new uchar 4096 0 |
| 718 | h = new uchar 40 0 |
| 719 | ptargs ac |
| 720 | tmpsetup |
| 721 | setbase |
| 722 | avinit a |
| 723 | avadd a tqprog |
| 724 | avadd a tqrp |
| 725 | avadd a tqiw |
| 726 | if ne runprog a tqgout 0 |
| 727 | die tqnowt |
| 728 | end |
| 729 | k = gitline l |
| 730 | if not beq part l 0 k tqtrue |
| 731 | die tqnowt |
| 732 | end |
| 733 | if not gitcommit tqhd false h |
| 734 | die tqnohd |
| 735 | end |
| 736 | ptbase |
| 737 | ptcount |
| 738 | ptmbox |
| 739 | ptfiles |
| 740 | pttitle |
| 741 | ptdesc |
| 742 | ptshow |
| 743 | if eq get gqyes 0 0 |
| 744 | if not consent tqask |
| 745 | say tqno |
| 746 | cleanup |
| 747 | ret 1 |
| 748 | end |
| 749 | end |
| 750 | makekey |
| 751 | readpk pk |
| 752 | ptstmt |
| 753 | sign tstmt tqns |
| 754 | signin0 pk |
| 755 | csrfof tqsetp |
| 756 | ptform |
| 757 | ptsend |
| 758 | cleanup |
| 759 | ret 0 |
| 760 | end |