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 / patch / p5imp.om

1281 lines · 23363 bytes Raw Blame History
1note patch/p5imp.om: imported proposals (SPEC prstore/r1 extension, written only by tools/ghimport):
2note reading an imported item back, its list row and page, and the diff of a bundle-backed item.
3note Every imported byte goes out through fescc (HTML) or fjtc (JSON); a GitHub login is text. Each
4note reader checks a length against its buffer before it reads, so a malformed or oversized file
5note ends in "not an item", a cut value or a sentence on the page, never in a trap.
6note ---- loading
7note pafrd t cap: the file <t> of item gpid into fxo; its length cut to cap, 0 when it cannot be read
8fn pafrd t view uchar * cap ulong to ulong
9pafp t
10n = frdall
11if lt n 0
12ret 0
13end
14ret hmin ulong n cap
15end
16note pasjat s t: gpsrc holds t at s (the caller keeps s + len t inside gpsrc)
17fn pasjat s ulong t view uchar * to bool
18for i ulong len t bound 64
19if ne get gpsrc add s i get t i
20ret false
21end
22end
23ret true
24end
25note pasjf t: the offset in gpsrc of the first t, the length of gpsrc when it is not there
26fn pasjf t view uchar * to ulong
27n = get gpsrcl 0
28k = len t
29if gt k n
30ret n
31end
32for s ulong add sub n k 1 bound 4097
33if pasjat s t
34ret s
35end
36end
37ret n
38end
39note pasjv t: the string value after the key text t in gpsrc: its offset; its length in gpr 15, and gpr
40note 14 is 1 when the key is there (0 and length 0 when it is not). The value ends at its closing
41note quote; a backslash ends it too (the value is cut there, never decoded), and so does the end of
42note the buffer
43fn pasjv t view uchar * to ulong
44n = get gpsrcl 0
45s = pasjf t
46put gpr 15 0
47put gpr 14 0
48if ge s n
49ret 0
50end
51put gpr 14 1
52p = add s len t
53q = p
54while lt q n bound 4097
55c = get gpsrc q
56if or eq c 34 eq c 92
57break
58end
59q = add q 1
60end
61put gpr 15 sub q p
62ret p
63end
64note pasjnum: the number of source.json ("number":N, 1..18 digits), 0 when it has none
65fn pasjnum to ulong
66n = get gpsrcl 0
67s = pasjf tpsjnum
68if ge s n
69ret 0
70end
71p = add s len tpsjnum
72v = ulong 0
73k = ulong 0
74while lt p n bound 19
75c = get gpsrc p
76if not fisdig c
77break
78end
79if ge k 18
80ret 0
81end
82v = add mul v 10 ulong sub c 48
83k = add k 1
84p = add p 1
85end
86ret v
87end
88note paghat s e t: the gh line gpgh[s, e) starts with t
89fn paghat s ulong e ulong t view uchar * to bool
90if lt sub e s len t
91ret false
92end
93for i ulong len t bound 16
94if ne get gpgh add s i get t i
95ret false
96end
97end
98ret true
99end
100note paghv t: the value of the gh line "<t><value>\n" in gpgh: its offset; its length in gpr 15 (0
101note when there is no such whole line)
102fn paghv t view uchar * to ulong
103n = get gpghl 0
104s = ulong 0
105for i ulong n bound 2048
106if eq get gpgh i 10
107if paghat s i t
108put gpr 15 sub sub i s len t
109ret add s len t
110end
111s = add i 1
112end
113end
114put gpr 15 0
115ret 0
116end
117note paghnum: the GitHub number of the gh file ("number N", 1..18 digits), 0 when it has none
118fn paghnum to ulong
119o = paghv tpghn
120k = get gpr 15
121if or eq k 0 gt k 18
122ret 0
123end
124v = ulong 0
125for i ulong k bound 18
126c = get gpgh add o i
127if not fisdig c
128ret 0
129end
130v = add mul v 10 ulong sub c 48
131end
132ret v
133end
134note paiload2: the optional files of the imported item: title (cut to 1024 bytes), base (40 hex and
135note a line feed, else the item has no base), gh (cut to 2048 bytes), and the code file: mbox, else
136note head.bundle, else none (its size in gpmby)
137fn paiload2 to bool
138n = pafrd tpftt 1024
139for i ulong n bound 1024
140put gpttl i get fxo i
141end
142put gpttll 0 n
143put gpihb 0 0
144papid tpfbase
145r = pards
146if pal40
147put gpihb 0 1
148for i ulong 40
149put gpbase i get gpln i
150end
151end
152n = pafrd tpfgh 2048
153for i ulong n bound 2048
154put gpgh i get fxo i
155end
156put gpghl 0 n
157put gpnum 0 paghnum
158if eq get gpnum 0 0
159put gpnum 0 pasjnum
160end
161put gpicode 0 0
162put gpmby 0 0
163papid tpfbn
164e = paexist
165if e
166put gpicode 0 2
167put gpmby 0 pastsz
168end
169papid tpfmb
170e = paexist
171if e
172put gpicode 0 1
173put gpmby 0 pastsz
174end
175put gpmcm 0 0
176put gpmfl 0 0
177put gpmdidl 0 0
178put gpmts 0 0
179ret true
180end
181note paiload: the imported item gpid into the globals (SPEC section 1): false unless source.json
182note starts with the import prefix, status is one of the three words and head is 40 hex and a line
183note feed. source.json is kept up to 4096 bytes.
184fn paiload to bool
185put gpimp 0 1
186n = pafrd tpfsj 4096
187if lt n len tpsjpre
188ret false
189end
190for i ulong len tpsjpre bound 64
191if ne get fxo i get tpsjpre i
192ret false
193end
194end
195for i ulong n bound 4096
196put gpsrc i get fxo i
197end
198put gpsrcl 0 n
199put gpider 0 0
200if lt pasjf tpsjder n
201put gpider 0 1
202end
203s = pastrd
204if gt s 2
205ret false
206end
207put gpist 0 s
208papid tpfhd
209r = pards
210if not pal40
211ret false
212end
213for i ulong 40
214put gphead i get gpln i
215end
216ret paiload2
217end
218note ---- the thread: records "comment <time> <login> <len>\n<body>\n", "review <time> <login>
219note <STATE|-> <len>\n<body>\n" and "review-comment <time> <login> <line> <pathlen> <len>\n<path>\n
220note <body>\n" (time: 20 bytes, or "-")
221note pathld: the thread file of item gpid into gpth; gpthc is set when the file is larger than gpth
222fn pathld to void
223put gpthl 0 0
224put gpthc 0 0
225pafp tpfth
226n = frdall
227if le n 0
228ret
229end
230if ne get fxotr 0 0
231put gpthc 0 1
232end
233for i ulong ulong n bound 16777216
234put gpth i get fxo i
235end
236put gpthl 0 ulong n
237end
238note patword a: the word at gpcur (1..256 bytes above 32) up to its space: offset in gpr a, length in
239note gpr a+1; gpcur moves past the space. gpbad is set (length 0) when it is not such a word; with
240note gpbad set nothing is read. At most 257 passes: the pass that sees 256 bytes returns.
241fn patword a ulong to void
242put gpr add a 1 0
243if ne get gpbad 0 0
244ret
245end
246p = get gpcur 0
247n = get gpthl 0
248q = p
249while lt q n bound 257
250if le get gpth q 32
251break
252end
253if ge sub q p 256
254put gpbad 0 1
255ret
256end
257q = add q 1
258end
259if or ge q n eq q p
260put gpbad 0 1
261ret
262end
263if ne get gpth q 32
264put gpbad 0 1
265ret
266end
267put gpr a p
268put gpr add a 1 sub q p
269put gpcur 0 add q 1
270end
271note patnum t: the decimal at gpcur (1..18 digits) ended by the byte t; gpcur moves past t. gpbad is
272note set when it is not one. At most 19 passes: the pass that sees an 19th digit returns.
273fn patnum t uchar to ulong
274if ne get gpbad 0 0
275ret 0
276end
277p = get gpcur 0
278n = get gpthl 0
279v = ulong 0
280k = ulong 0
281while lt p n bound 19
282c = get gpth p
283if not fisdig c
284break
285end
286if ge k 18
287put gpbad 0 1
288ret 0
289end
290v = add mul v 10 ulong sub c 48
291k = add k 1
292p = add p 1
293end
294if or eq k 0 ge p n
295put gpbad 0 1
296ret 0
297end
298if ne get gpth p t
299put gpbad 0 1
300ret 0
301end
302put gpcur 0 add p 1
303ret v
304end
305note patis a t: the word of gpr a, a+1 is t
306fn patis a ulong t view uchar * to bool
307if ne get gpr add a 1 len t
308ret false
309end
310o = get gpr a
311for i ulong len t bound 16
312if ne get gpth add o i get t i
313ret false
314end
315end
316ret true
317end
318note patkind: the record kind of the word in gpr 12, 13: 1 comment, 2 review, 3 review-comment, else 0
319fn patkind to ulong
320if patis 12 tprcom
321ret 1
322end
323if patis 12 tprrev
324ret 2
325end
326if patis 12 tprrc
327ret 3
328end
329ret 0
330end
331note pattok: the time word (gpr 1, 2) is 20 bytes or "-"
332fn pattok to bool
333k = get gpr 2
334if eq k 20
335ret true
336end
337if ne k 1
338ret false
339end
340ret eq get gpth get gpr 1 45
341end
342note patrec p: parse the record at p into gpr (0 kind, 1-2 time, 3-4 login, 5-6 state, 7 line, 8-9
343note path, 10-11 body); the index after it. A malformed record leaves kind 0 and returns the thread's
344note length, which stops the caller: every length is checked against the thread before the bytes it
345note names are read (a path is at most 4096 bytes).
346fn patrec p ulong to ulong
347n = get gpthl 0
348put gpr 0 0
349put gpr 6 0
350put gpr 7 0
351put gpr 9 0
352put gpbad 0 0
353put gpcur 0 p
354patword 12
355k = patkind
356if eq k 0
357ret n
358end
359patword 1
360patword 3
361if eq k 2
362patword 5
363end
364if eq k 3
365put gpr 7 patnum 32
366put gpr 9 patnum 32
367end
368b = patnum 10
369if ne get gpbad 0 0
370ret n
371end
372if not pattok
373ret n
374end
375q = get gpcur 0
376if eq k 3
377m = get gpr 9
378if or gt m 4096 ge add q m n
379ret n
380end
381if ne get gpth add q m 10
382ret n
383end
384put gpr 8 q
385q = add add q m 1
386end
387if ge add q b n
388ret n
389end
390if ne get gpth add q b 10
391ret n
392end
393put gpr 10 q
394put gpr 11 b
395put gpr 0 k
396ret add add q b 1
397end
398note patcnt: the records of the loaded thread up to its end or its first malformed record. A record
399note is at least 15 bytes, so the passes stay far under the bound.
400fn patcnt to ulong
401p = ulong 0
402c = ulong 0
403n = get gpthl 0
404while lt p n bound 16777216
405p = patrec p
406if ne get gpr 0 0
407c = add c 1
408end
409end
410ret c
411end
412note ---- pieces of the HTML pages
413note patraw a: gpth[gpr a, + gpr a+1), HTML-escaped
414fn patraw a ulong to void
415o = get gpr a
416for i ulong get gpr add a 1 bound 16777216
417fescc get gpth add o i
418end
419end
420note pattime: the record's time as YYYY-MM-DD HH:MM UTC, escaped ("-" when it has none)
421fn pattime to void
422if ne get gpr 2 20
423fputc 45
424ret
425end
426o = get gpr 1
427for i ulong 10
428fescc get gpth add o i
429end
430fputc 32
431for i ulong 5
432fescc get gpth add add o 11 i
433end
434fput tputc
435end
436note paghhas t: the gh file has a 20-byte time under t
437fn paghhas t view uchar * to bool
438o = paghv t
439ret eq get gpr 15 20
440end
441note paghtm t: the gh time under t as YYYY-MM-DD HH:MM UTC, escaped ("-" when it is not 20 bytes)
442fn paghtm t view uchar * to void
443o = paghv t
444if ne get gpr 15 20
445fputc 45
446ret
447end
448for i ulong 10
449fescc get gpgh add o i
450end
451fputc 32
452for i ulong 5
453fescc get gpgh add add o 11 i
454end
455fput tputc
456end
457note paghp t: the gh value under t, HTML-escaped
458fn paghp t view uchar * to void
459o = paghv t
460for i ulong get gpr 15 bound 2048
461fescc get gpgh add o i
462end
463end
464note pasjp t: the source.json string after the key text t, HTML-escaped
465fn pasjp t view uchar * to void
466o = pasjv t
467for i ulong get gpr 15 bound 4096
468fescc get gpsrc add o i
469end
470end
471note paprov: the provenance text: Imported from GitHub <gho>/<ghr>#<n>, by <login>; a code-only item
472note (no GitHub metadata) has no login: Imported from GitHub <gho>/<ghr>#<n> (code only)
473note An item with metadata whose gh file names no login ends after the number: no ", by ".
474fn paprov to void
475fput tpimp1
476pasjp tpsjow
477fputc 47
478pasjp tpsjrp
479fputc 35
480fnum get gpnum 0
481if ne get gpider 0 0
482fput tpimp3
483ret
484end
485o = paghv tpghl
486if eq get gpr 15 0
487ret
488end
489fput tpimp2
490paghp tpghl
491end
492note pabadge: the status word as a badge, and the word "derived" when the state is derived
493fn pabadge to void
494s = get gpist 0
495if eq s 0
496fput tpbok
497fput tpwopn
498end
499if eq s 1
500fput tpbbad
501fput tpwclo
502end
503if eq s 2
504fput tpbmut
505fput tpwmrg
506end
507fput tpboff
508if ne get gpider 0 0
509fput tpbder
510end
511end
512note paitl: the title, escaped; "(untitled)" when the item has none
513fn paitl to void
514if eq get gpttll 0 0
515fput tpnotl
516ret
517end
518paesct
519end
520note paiwhen: " opened YYYY-MM-DD" (gh opened); a code-only item: " imported <date of imported_utc>"
521fn paiwhen to void
522if ne get gpider 0 0
523fput tpiwi
524o = pasjv tpsjutc
525if ge get gpr 15 10
526for i ulong 10
527fescc get gpsrc add o i
528end
529else
530fputc 45
531end
532ret
533end
534fput tpiwo
535o = paghv tpgho
536if eq get gpr 15 20
537for i ulong 10
538fescc get gpgh add o i
539end
540else
541fputc 45
542end
543end
544note pairow: the list row of an imported item: title link, badge, id, date, provenance; no counts
545fn pairow to void
546fput tphli
547papath
548fput tphq
549paitl
550fput tphae
551fput tpir1
552pabadge
553fput tpir2
554paputid
555fput tphcodz
556paiwhen
557fput tphm3
558paprov
559fput tphm4
560end
561note ---- the page of an imported item
562note paitms: the opened, closed and merged times of the gh file (none for a code-only item)
563fn paitms to void
564if ne get gpider 0 0
565ret
566end
567fput tpito
568paghtm tpgho
569if paghhas tpghc
570fput tpitc
571paghtm tpghc
572end
573if paghhas tpghm
574fput tpitm
575paghtm tpghm
576end
577end
578note pailabs: "Labels: a, b" from the labels file (one per line; its first 65536 bytes)
579fn pailabs to void
580n = pafrd tpflb 65536
581if eq n 0
582ret
583end
584fput tpipm
585fput tpilab
586for i ulong n bound 65536
587c = get fxo i
588if eq c 10
589if lt add i 1 n
590fputc 44
591fputc 32
592end
593else
594fescc c
595end
596end
597fput tpipe
598end
599note parchsp s n: the index of the first space of gpln at or after s, n when there is none (n is at
600note most 255)
601fn parchsp s ulong n ulong to ulong
602q = s
603while lt q n bound 257
604if eq get gpln q 32
605break
606end
607q = add q 1
608end
609ret q
610end
611note parchw a t: gpln[0, a) is t
612fn parchw a ulong t view uchar * to bool
613if ne a len t
614ret false
615end
616for i ulong a bound 16
617if ne get gpln i get t i
618ret false
619end
620end
621ret true
622end
623note parchld: the reach file of item gpid ("<reachable|not-reachable|unknown> <main sha|-> <utc>\n")
624note into gpln: 1 reachable, 2 not-reachable, 3 unknown, 0 when there is none or it is not that
625note line. The main sha is at gpr 12 (length gpr 13: 40, or 0 for "-"), the observation time at
626note gpr 14 (length gpr 15: 1..32 bytes).
627fn parchld to ulong
628papid tpfrc
629r = pards
630if or lt r 5 gt r 255
631ret 0
632end
633n = get gplnl 0
634if ne get gpln sub n 1 10
635ret 0
636end
637a = parchsp 0 n
638if ge a n
639ret 0
640end
641b = parchsp add a 1 n
642if ge b n
643ret 0
644end
645w = ulong 0
646if parchw a tprch1
647w = 1
648end
649if parchw a tprch2
650w = 2
651end
652if parchw a tprch3
653w = 3
654end
655if eq w 0
656ret 0
657end
658m = sub sub b a 1
659put gpr 12 add a 1
660put gpr 13 0
661if eq m 40
662for i ulong 40
663if lt sohexv get gpln add add a 1 i 0
664ret 0
665end
666end
667put gpr 13 40
668else
669if ne m 1
670ret 0
671end
672if ne get gpln add a 1 45
673ret 0
674end
675end
676u = sub sub n b 2
677if or lt u 1 gt u 32
678ret 0
679end
680put gpr 14 add b 1
681put gpr 15 u
682ret w
683end
684note paimrg: a merged item with GitHub metadata: the merge commit (the merged file) and what the
685note importer observed about this project's main (the reach file)
686fn paimrg to void
687papid tpfmg
688r = pards
689if not pal40
690ret
691end
692fput tpipm
693fput tpimg1
694for i ulong 40
695fputc get gpln i
696end
697fput tphcodz
698w = parchld
699if or eq w 1 eq w 2
700if eq w 1
701fput tpimr1
702else
703fput tpimr2
704end
705o = get gpr 12
706for i ulong get gpr 13 bound 40
707fputc get gpln add o i
708end
709fput tphcodz
710end
711if eq w 3
712fput tpimr3
713end
714if ne w 0
715fput tpimro
716o = get gpr 14
717for i ulong get gpr 15 bound 32
718fescc get gpln add o i
719end
720fputc 41
721end
722fput tpipe
723end
724note paishas: the base and head commits, and the merge line of a merged item
725fn paishas to void
726fput tpipm
727if ne get gpihb 0 0
728fput tpisb
729paput40 0
730fput tpisb2
731else
732fput tpisnb
733end
734fput tpish
735paput40 1
736fput tphcodz
737fput tpipe
738if eq get gpist 0 2
739paimrg
740end
741end
742note pamd n: render fxo[0, n) using the browse renderer at the project root on its default branch
743fn pamd n ulong to void
744repo = get fridx 0
745branch = get fabo repo
746size = get fabl repo
747for i ulong size bound 64
748put gbref i get fabr add branch i
749end
750put gbrefl 0 size
751put gbmdl 0 0
752fput tbart1
753brmd 0 n
754fput tbart2
755end
756note papgfit f0 t0: true while the page is at most PAPGMX bytes and no byte was dropped; else the
757note output goes back to f0 (and the cut flag to t0), so the caller writes one sentence in place of
758note what it rendered and the rest of the page still fits fob
759fn papgfit f0 ulong t0 ulong to bool
760if and le get fobl 0 PAPGMX eq get fobtr 0 t0
761ret true
762end
763put fobl 0 f0
764put fobtr 0 t0
765ret false
766end
767note paidesc: the description as Markdown under "<login> wrote on <time>"; nothing when there is
768note none; one sentence when it is over fxo or takes the page over PAPGMX
769fn paidesc to void
770pafp tpfds
771n = frdall
772if le n 0
773ret
774end
775huge = ne get fxotr 0 0
776f0 = get fobl 0
777t0 = get fobtr 0
778fput tpibox
779if eq get gpider 0 0
780paghp tpghl
781fput tpiwr
782paghtm tpgho
783else
784fput tpidsc
785end
786fput tpipe
787if huge
788fput tpidbig
789else
790pamd ulong n
791end
792fput tphdv
793if not papgfit f0 t0
794fput tpidbig
795end
796end
797note paibox: the parsed record (gpr) as a box: login (text), what it is, time, the body as Markdown
798fn paibox to void
799k = get gpr 0
800fput tpibox
801patraw 3
802if eq k 1
803fput tpiwr
804end
805if eq k 2
806fput tpirv1
807patraw 5
808fput tpirv2
809end
810if eq k 3
811fput tpirc1
812patraw 8
813fput tpirc2
814fnum get gpr 7
815fput tpion
816end
817pattime
818fput tpipe
819o = get gpr 10
820b = get gpr 11
821if gt b 0
822for i ulong b bound 16777216
823put fxo i get gpth add o i
824end
825pamd b
826end
827fput tphdv
828end
829note paithr: the thread, one box per record. It stops at the first malformed record (one sentence),
830note and when a box takes the page over PAPGMX (that box is taken back, one sentence).
831fn paithr to void
832pathld
833p = ulong 0
834n = get gpthl 0
835while lt p n bound 16777216
836p = patrec p
837if eq get gpr 0 0
838if eq get gpthc 0 0
839fput tpitbad
840end
841break
842end
843f0 = get fobl 0
844t0 = get fobtr 0
845paibox
846if not papgfit f0 t0
847fput tpitcut
848break
849end
850end
851if ne get gpthc 0 0
852fput tpitbig
853end
854end
855note paiapply: the code box of an mbox-backed item: the "Apply it" lines and raw links of a signed
856note patch (no Signature box)
857fn paiapply to void
858fput tphap1
859paputid
860if ne get gpihb 0 0
861fputc 32
862paput40 0
863end
864fput tphap2
865paorig
866papath
867fput tpsfxp
868fput tphap3
869papath
870fput tpsfxp
871fput tphap4
872papath
873fput tpsfxd
874fput tphap5
875end
876note paibund: the code box of a bundle-backed item: size, the fetch lines, the raw link, and the
877note diff link when the diff exists (gpbd 0)
878fn paibund to void
879fput tpibd1
880fnum get gpmby 0
881fput tpibd2
882paorig
883papath
884fput tpsfxb
885fput tpibd3
886paputid
887fput tpsfxb
888fput tpibd4
889paputid
890fput tpsfxb
891fput tpibd4b
892fnum get gpnum 0
893fput tpibd5
894papath
895fput tpsfxb
896fput tpibd6
897if eq get gpbd 0 0
898fput tpibd7
899papath
900fput tpsfxd
901fput tphap5
902ret
903end
904fput tpibd9
905end
906note paonmn: the loaded imported item is the importer's on-main route: a code-only item (derived
907note state) whose state is merged and whose base file names its head commit
908fn paonmn to bool
909if eq get gpider 0 0
910ret false
911end
912if ne get gpist 0 2
913ret false
914end
915if eq get gpihb 0 0
916ret false
917end
918for i ulong 40
919if ne get gpbase i get gphead i
920ret false
921end
922end
923ret true
924end
925note paicode: the Code box. Without a code file only the on-main route says the head is on main (with
926note the link to its commit page); any other item says that it holds no code file.
927fn paicode to void
928k = get gpicode 0
929if eq k 1
930paiapply
931ret
932end
933if eq k 2
934paibund
935ret
936end
937if not paonmn
938fput tpicx
939ret
940end
941fput tpicn1
942fputrl
943fput tphcm
944paput40 1
945fput tphq
946fput tphcode
947paput40 1
948fput tpicn2
949end
950note paiprov: the Provenance box: imported, not signed; the statement and source.json, escaped
951fn paiprov to void
952fput tpipv1
953n = pafrd tpfst 65536
954fxesc 0 n
955fput tphpre
956fput tphsg3
957for i ulong get gpsrcl 0 bound 4096
958fescc get gpsrc i
959end
960fput tphpre
961fput tphdv
962end
963note paichn t: the Changes heading with one sentence in place of a diff
964fn paichn t view uchar * to void
965fput tpich
966fput t
967fput tpipe
968end
969note pafpp: fpth = gpp, for frdall
970fn pafpp to void
971fpb
972for i ulong get gppl 0 bound 4096
973fpc get gpp i
974end
975end
976note paichg: Changes: the stored diff of an mbox, the cached diff of a bundle with a base (gpbd is
977note pabdiff's answer), else the sentence that says why there is none
978fn paichg to void
979k = get gpicode 0
980if eq k 1
981n = pardf tpfdf
982if gt n 0
983pashdn n
984ret
985end
986paichn tpicg1
987ret
988end
989if eq k 0
990if paonmn
991paichn tpicg0
992else
993paichn tpicg7
994end
995ret
996end
997if eq get gpihb 0 0
998paichn tpicg2
999ret
1000end
1001w = get gpbd 0
1002if eq w 1
1003paichn tpicg3
1004ret
1005end
1006if eq w 2
1007paichn tpicg4
1008ret
1009end
1010if eq w 4
1011paichn tpicg8
1012ret
1013end
1014if ne w 0
1015paichn tpicg5
1016ret
1017end
1018papdf
1019pafpp
1020r = frdall
1021if lt r 0
1022paichn tpicg5
1023ret
1024end
1025if eq r 0
1026paichn tpicg6
1027ret
1028end
1029pashdn ulong r
1030end
1031note paishow: the page of the loaded imported item
1032fn paishow to long
1033put gpbd 0 9
1034if eq get gpicode 0 2
1035if ne get gpihb 0 0
1036put gpbd 0 pabdiff
1037end
1038end
1039fyalt
1040if eq get gpttll 0 0
1041fsetti tptlist
1042else
1043patitl
1044end
1045frepohd 5
1046fput tphp1
1047paitl
1048fput tpip2
1049pabadge
1050fput tpir2
1051paputid
1052fput tphcodz
1053fput tpipn
1054fnum get gpnum 0
1055paitms
1056fput tpipe
1057fput tpipm
1058paprov
1059fput tpipe
1060if ne get gpider 0 0
1061fput tpider
1062end
1063pailabs
1064paishas
1065fput tphdv
1066paidesc
1067paithr
1068paicode
1069paiprov
1070paichg
1071ret 200
1072end
1073note ---- the diff of a bundle-backed item (SPEC section 4), made once and kept as the cache file
1074note <data>pdiff/<owner>/<repo>/<id>: derived data outside the item folder, safe to delete
1075note pabcat: git --git-dir=<store> cat-file -e <base>^{commit} for the loaded item's base (gpbase),
1076note fexec's answer: 0 the project's git store holds the base commit, above 0 it does not, below 0
1077note git did not run. One check for the diff (pabdiff) and for the JSON documents (pajdun)
1078fn pabcat to long
1079pakst
1080fka tpcatf
1081fka tpde
1082fkopen
1083pakbase
1084fkt tpcmt
1085ret fexec PATMO
1086end
1087note pabbig: leave the marker <data>pdiff/<owner>/<repo>/<id>.big, an empty file created exclusively
1088note (one that is there stays; a failure leaves none and the next attempt tries again): the bundle
1089note diff of item gpid was cut at 16 MiB. Derived data like the cache file, safe to delete
1090fn pabbig to void
1091if not pamkpd
1092ret
1093end
1094papdfg
1095x = pawf 6 0
1096end
1097note pabst: what the cache folder says of the loaded bundle-backed item, without running git: 0 the
1098note cache file is there, 2 the marker is there, 9 neither
1099fn pabst to ulong
1100papdf
1101if paexist
1102ret 0
1103end
1104papdfg
1105if paexist
1106ret 2
1107end
1108ret 9
1109end
1110note pabkeep: fxo[0, fxol) -> this request's staging file -> the cache file (rename over it; the
1111note staging file is removed when the write or the rename fails): 0 kept, 3 failed
1112fn pabkeep to ulong
1113if not pamkpd
1114ret 3
1115end
1116papdfn
1117if not pawf 6 get fxol 0
1118x = unlink gpp 0 get gppl 0
1119ret 3
1120end
1121soavb
1122papdfn
1123paavp
1124papdf
1125paavp
1126r = renames gspk 0 get gspkl 0 0
1127if lt r 0
1128papdfn
1129x = unlink gpp 0 get gppl 0
1130ret 3
1131end
1132ret 0
1133end
1134note pabrun: in the work folder: git bundle unbundle <item>/head.bundle, then git diff --no-color
1135note --no-ext-diff --no-textconv <base>...<head> (the importer's own diff form), both with pakwt's
1136note settings through fexec (argv only): 0 the output is kept as the cache file, 2 it is over fxo
1137note (not kept), 3 git or the disk failed
1138fn pabrun to ulong
1139pakwt
1140fka tpbund
1141fka tpunb
1142fkopen
1143papid tpfbn
1144pakp
1145r = fexec PATMO
1146if ne r 0
1147ret 3
1148end
1149pakwt
1150fka tpdiff
1151fka tpnocol
1152fka tpnoext
1153fka tpnotc
1154fkopen
1155pakbase
1156fkt tpdots3
1157for i ulong 40
1158fkc get gphead i
1159end
1160r = fexec PATMO
1161if ne r 0
1162ret 3
1163end
1164if ne get fxotr 0 0
1165ret 2
1166end
1167ret pabkeep
1168end
1169note Cache failed diff work briefly without changing imported data.
1170global gpbkeys uchar 1024
1171global gpbexp ulong 64
1172global gpbslot ulong 1
1173fn pabbad to bool
1174now = ulong monons
1175for slot ulong 64
1176if gt get gpbexp slot now
1177same = true
1178for i ulong 16
1179if ne get gpbkeys add mul slot 16 i get gpid i
1180same = false
1181break
1182end
1183end
1184if same
1185ret true
1186end
1187end
1188end
1189ret false
1190end
1191fn pabbset to void
1192slot = get gpbslot 0
1193for i ulong 16
1194put gpbkeys add mul slot 16 i get gpid i
1195end
1196put gpbexp slot add ulong monons 120000000000
1197put gpbslot 0 rem add slot 1 64
1198end
1199note Skip synchronous diff generation for large bundles. The bundle download stays available.
1200fn pabbcap to bool
1201papid tpfbn
1202if not paexist
1203ret false
1204end
1205ret gt pastsz 134217728
1206end
1207note pabdiff: the cache file of the loaded bundle-backed item (gpid, gpbase, gphead) exists, making
1208note it when it does not: 0 it is there, 1 the base commit is not in the project's git store, 2 the
1209note diff is over fxo (the marker is left beside the cache, pabbig; with the marker there git is not
1210note run again: the page and the raw route answer from it), 3 git, the disk or the work folder
1211note failed. The work folder is removed whatever happened.
1212fn pabdiff to ulong
1213papdf
1214e = paexist
1215if e
1216ret 0
1217end
1218papdfg
1219if paexist
1220ret 2
1221end
1222if pabbcap
1223ret 4
1224end
1225if pabbad
1226ret 3
1227end
1228r = pabcat
1229if lt r 0
1230pabbset
1231ret 3
1232end
1233if ne r 0
1234ret 1
1235end
1236if not pastem
1237ret 3
1238end
1239w = ulong 3
1240if pawinit
1241w = pabrun
1242end
1243if not parmtree
1244flog tplrm
1245end
1246if eq w 2
1247pabbig
1248end
1249if eq w 3
1250pabbset
1251end
1252ret w
1253end
1254note pabraw: GET <id>.diff of an item that stores no diff file: 0 with gpp = the cache file of the
1255note bundle diff (made now when it is not there), else the status: 404 (not an item, no bundle, no
1256note base, the base is not in the git store, the diff is over fxo), 500 (the diff could not be made)
1257fn pabraw to long
1258if not paany
1259ret 404
1260end
1261if eq get gpimp 0 0
1262ret 404
1263end
1264if ne get gpicode 0 2
1265ret 404
1266end
1267if eq get gpihb 0 0
1268ret 404
1269end
1270w = pabdiff
1271if eq w 0
1272papdf
1273ret 0
1274end
1275if eq w 3
1276patext
1277fput tpmdint
1278ret 500
1279end
1280ret 404
1281end