interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / native / issue.om

878 lines · 14941 bytes Raw Blame History
1note collab/co5iss.om: issues from the native issue store (GitHub import contract r1 G3; docs/API.md
2note forge/issues/1, forge/issue/1). The store is <data>issues/<owner>/<repo>/: an index file of lines
3note "<id>\n" (16 lowercase hex) and one folder per issue with title, description, status ("open\n" or
4note "closed\n"), labels (one per line), gh (number, login, opened, closed, reason lines), thread and
5note source.json for imports, or native metadata for web writes. Nothing here reads Radicle storage.
6note A native-comment record holds the author DID and form token before the length.
7note A thread is a run of records "<kind> <time> <login> [<state> | <line> <pathlen>] <len>\n" then
8note [<path>\n] <body>\n with kind comment, review or review-comment.
9note An imported issue names its GitHub author as plain text, "Imported from GitHub <owner>/<repo>#<n>,
10note by <login>": never a link, an account of this forge or a DID (G1).
11note Prefixes: functions ni*, globals gn*, texts tn*.
12text tniwnat "native"
13text tniwdid "did "
14text tniwncom "native-comment"
15text tniss "issues/"
16text tnindex "index"
17text tnfttl "title"
18text tnfdsc "description"
19text tnfsts "status"
20text tnfgh "gh"
21text tnfthr "thread"
22text tnflab "labels"
23text tnfsrc "source.json"
24text tnghn "number "
25text tnghl "login "
26text tnghop "opened "
27text tnghcl "closed "
28text tnghre "reason "
29text tnjow "\"owner\":\""
30text tnjrp "\"repo\":\""
31text tnrcom "comment"
32text tnrrev "review"
33text tnrrc "review-comment"
34text tnimp1 "Imported from GitHub "
35text tnimp2 ", by "
36text tnmeta "<p class=\"meta\">"
37text tnmetae "</p>\n"
38text tnli3 "<p class=\"meta\"><code>#"
39text tnli4 "</code> &#183; opened "
40text tnli5 " comment"
41text tnph1 "<section class=\"rhead\"><h1>"
42text tnph2 "</h1>\n"
43text tnclo " &#183; closed "
44text tnreas " (reason "
45text tnlab "Labels: "
46text tnbox "<section class=\"box\"><p class=\"meta\">"
47text tnwrote " wrote on "
48text tnrevd " reviewed ("
49text tnrevd2 ") on "
50text tnrcon " commented on <code>"
51text tnline "</code> line "
52text tnon " on "
53text tnsece "</section>\n"
54text tnnocm "<p class=\"muted\">No comments.</p>\n"
55text tnutc " UTC"
56text tntiss " - issue - "
57text tnmd1 "<article class=\"md\">\n"
58text tnmd2 "</article>\n"
59text tnpkey "page"
60text tnpp "per_page"
61text tnnext "next"
62text tnprev "prev"
63text tnpage "&amp;page="
64text tnpjson "&page="
65text tnnava "<nav aria-label=\"Issue pages\">"
66text tnnavz "</nav>\n"
67text tnpnext "Next"
68text tnpprev "Previous"
69const NIPAGE ulong 30
70const NIROWS ulong 262144
71const NILEG ulong 200
72global gnpage ulong 1
73global gnmatch ulong 1
74global gnpaged ulong 1
75note the index of the repository's store (17 bytes per id line) and its count
76global gnix uchar 4456448
77global gnn ulong 1
78note one issue's thread file, a small file (title, gh, status, source.json) and its length
79global gnth uchar 16777216
80global gnthl ulong 1
81global gnf uchar 65536
82global gnfl ulong 1
83global gngh uchar 65536
84global gnghl ulong 1
85global gnative ulong 1
86note a parsed thread record: kind (1 comment 2 review 3 review comment), time, login, state, line,
87note path and body as offsets and lengths into gnth
88global gnr ulong 16
89
90note ---- paths and reads
91fn nipath to void
92fpb
93fpt tfdata
94fpt tniss
95fpt tfowner
96fpc 47
97r = get fridx 0
98for i ulong get fanl r bound 128
99fpc frnbyte r i
100end
101fpc 47
102end
103fn nipf k ulong t view uchar * to void
104nipath
105for i ulong 16
106fpc get gnix add mul k 17 i
107end
108fpc 47
109fpt t
110end
111note niidx: the ids of the index into gnix (lines that are not 16 lowercase hex and a line feed are
112note left out); a missing index is an empty store. false when the index does not fit the table.
113fn niidx to bool
114put gnn 0 0
115nipath
116fpt tnindex
117r = frdall
118if lt r 0
119ret true
120end
121if ne get fxotr 0 0
122fincut
123ret false
124end
125n = div ulong r 17
126if gt n 262144
127fincut
128ret false
129end
130m = ulong 0
131for j ulong n bound 262144
132if niidok mul j 17
133nicp mul j 17 mul m 17
134m = add m 1
135end
136end
137put gnn 0 m
138ret true
139end
140fn nicp a ulong b ulong to void
141for i ulong 17
142put gnix add b i get fxo add a i
143end
144end
145fn niidok o ulong to bool
146for i ulong 16
147c = get fxo add o i
148if not or and ge c 48 le c 57 and ge c 97 le c 102
149ret false
150end
151end
152ret eq get fxo add o 16 10
153end
154note nismall k t: the file t of issue k into gnf (at most 65536 bytes are kept); its length
155fn nismall k ulong t view uchar * to ulong
156put gnfl 0 0
157nipf k t
158r = frdall
159if lt r 0
160ret 0
161end
162n = ulong r
163if gt n 65536
164n = ulong 65536
165end
166for i ulong n bound 65536
167put gnf i get fxo i
168end
169put gnfl 0 n
170ret n
171end
172note nistate k: 0 open, 2 closed (the states of costbadge 2)
173fn nistate k ulong to ulong
174n = nismall k tnfsts
175if and eq n 5 eq get gnf 0 111
176ret 0
177end
178ret 2
179end
180note nigh k: the gh file of issue k into gngh
181fn nigh k ulong to void
182n = nismall k tniwnat
183put gnative 0 0
184if eq n 0
185n = nismall k tnfgh
186else
187put gnative 0 1
188end
189for i ulong n bound 65536
190put gngh i get gnf i
191end
192put gnghl 0 n
193end
194note nighv t: the value of the gh line "<t><value>\n": its offset in gngh; its length in gnr 15
195fn nighv t view uchar * to ulong
196n = get gnghl 0
197s = ulong 0
198for i ulong n bound 65536
199if eq get gngh i 10
200if nighat s i t
201put gnr 15 sub sub i s len t
202ret add s len t
203end
204s = add i 1
205end
206end
207put gnr 15 0
208ret 0
209end
210fn nighat s ulong e ulong t view uchar * to bool
211if lt sub e s len t
212ret false
213end
214for i ulong len t bound 16
215if ne get gngh add s i get t i
216ret false
217end
218end
219ret true
220end
221note nighp t: the gh value t, HTML-escaped
222fn nighp t view uchar * to void
223o = nighv t
224for i ulong get gnr 15 bound 65536
225fescc get gngh add o i
226end
227end
228note nijv t: in gnf (a source.json), the string value after t (plain names), HTML-escaped
229fn nijv t view uchar * to void
230n = get gnfl 0
231for s ulong n bound 65536
232if nijat s t
233p = add s len t
234while lt p n bound 65536
235c = get gnf p
236if eq c 34
237ret
238end
239fescc c
240p = add p 1
241end
242ret
243end
244end
245end
246fn nijat s ulong t view uchar * to bool
247if gt add s len t get gnfl 0
248ret false
249end
250for i ulong len t bound 16
251if ne get gnf add s i get t i
252ret false
253end
254end
255ret true
256end
257note nithr k: the thread of issue k into gnth; false when it does not fit
258fn nithr k ulong to bool
259put gnthl 0 0
260nipf k tnfthr
261r = frdall
262if lt r 0
263ret true
264end
265if ne get fxotr 0 0
266ret false
267end
268for i ulong ulong r bound 16777216
269put gnth i get fxo i
270end
271put gnthl 0 ulong r
272ret true
273end
274
275note ---- thread records
276global gnbad ulong 1
277global gncur ulong 1
278fn niword a ulong to void
279put gnr add a 1 0
280if ne get gnbad 0 0
281ret
282end
283p = get gncur 0
284n = get gnthl 0
285q = p
286while lt q n bound 257
287if le get gnth q 32
288break
289end
290if ge sub q p 256
291put gnbad 0 1
292ret
293end
294q = add q 1
295end
296if or ge q n eq q p
297put gnbad 0 1
298ret
299end
300if ne get gnth q 32
301put gnbad 0 1
302ret
303end
304put gnr a p
305put gnr add a 1 sub q p
306put gncur 0 add q 1
307end
308note nidec t: the decimal at gncur (1..18 digits) ended by the byte t; gncur moves past t. gnbad is
309note set when it is not one. At most 19 passes: the pass that sees an 19th digit returns.
310fn nidec t uchar to ulong
311if ne get gnbad 0 0
312ret 0
313end
314p = get gncur 0
315n = get gnthl 0
316v = ulong 0
317k = ulong 0
318while lt p n bound 19
319c = get gnth p
320if not fisdig c
321break
322end
323if ge k 18
324put gnbad 0 1
325ret 0
326end
327v = add mul v 10 ulong sub c 48
328k = add k 1
329p = add p 1
330end
331if or eq k 0 ge p n
332put gnbad 0 1
333ret 0
334end
335if ne get gnth p t
336put gnbad 0 1
337ret 0
338end
339put gncur 0 add p 1
340ret v
341end
342note niwordis a t: the word of gnr a, a+1 is t
343fn niwordis a ulong t view uchar * to bool
344if ne get gnr add a 1 len t
345ret false
346end
347o = get gnr a
348for i ulong len t bound 16
349if ne get gnth add o i get t i
350ret false
351end
352end
353ret true
354end
355note nikind: the record kind of the word in gnr 12, 13: 1 comment, 2 review, 3 review-comment, else 0
356fn nikind to ulong
357if niwordis 12 tnrcom
358ret 1
359end
360if niwordis 12 tniwncom
361ret 4
362end
363if niwordis 12 tnrrev
364ret 2
365end
366if niwordis 12 tnrrc
367ret 3
368end
369ret 0
370end
371note nitok: the time word (gnr 1, 2) is 20 bytes or "-"
372fn nitok to bool
373k = get gnr 2
374if eq k 20
375ret true
376end
377if ne k 1
378ret false
379end
380ret eq get gnth get gnr 1 45
381end
382note nirec p: parse the record at p into gnr (0 kind, 1-2 time, 3-4 login, 5-6 state, 7 line, 8-9
383note path, 10-11 body); the index after it. A malformed record leaves kind 0 and returns the thread's
384note length, which stops the caller: every length is checked against the thread before the bytes it
385note names are read (a path is at most 4096 bytes).
386fn nirec p ulong to ulong
387n = get gnthl 0
388put gnr 0 0
389put gnr 6 0
390put gnr 7 0
391put gnr 9 0
392put gnbad 0 0
393put gncur 0 p
394niword 12
395k = nikind
396if eq k 0
397ret n
398end
399niword 1
400niword 3
401if or eq k 2 eq k 4
402niword 5
403end
404if eq k 3
405put gnr 7 nidec 32
406put gnr 9 nidec 32
407end
408b = nidec 10
409if ne get gnbad 0 0
410ret n
411end
412if not nitok
413ret n
414end
415q = get gncur 0
416if eq k 3
417m = get gnr 9
418if or gt m 4096 ge add q m n
419ret n
420end
421if ne get gnth add q m 10
422ret n
423end
424put gnr 8 q
425q = add add q m 1
426end
427if ge add q b n
428ret n
429end
430if ne get gnth add q b 10
431ret n
432end
433put gnr 10 q
434put gnr 11 b
435put gnr 0 k
436ret add add q b 1
437end
438note nicount: the records of the loaded thread
439fn nicount to ulong
440p = ulong 0
441c = ulong 0
442n = get gnthl 0
443while lt p n bound 16777216
444p = nirec p
445if ne get gnr 0 0
446c = add c 1
447end
448end
449ret c
450end
451note nitime o: the ISO time gnth[o, o+20) as YYYY-MM-DD HH:MM UTC
452fn nitime o ulong to void
453for i ulong 10
454fescc get gnth add o i
455end
456fputc 32
457for i ulong 5
458fescc get gnth add add o 11 i
459end
460fput tnutc
461end
462note nighte t: the gh time value t as YYYY-MM-DD HH:MM UTC ("-" stays "-")
463fn nighte t view uchar * to void
464o = nighv t
465if ne get gnr 15 20
466fputc 45
467ret
468end
469for i ulong 10
470fescc get gngh add o i
471end
472fputc 32
473for i ulong 5
474fescc get gngh add add o 11 i
475end
476fput tnutc
477end
478
479note ---- the provenance line: Imported from GitHub <owner>/<repo>#<n>, by <login> (plain text)
480fn niprov k ulong to void
481x = nismall k tnfsrc
482fput tnimp1
483nijv tnjow
484fputc 47
485nijv tnjrp
486fputc 35
487nighp tnghn
488fput tnimp2
489nighp tnghl
490end
491fn niwho to void
492if eq get gnative 0 1
493nighp tniwdid
494else
495nighp tnghl
496end
497end
498fn niorigin k ulong to void
499if eq get gnative 0 1
500niwho
501else
502niprov k
503end
504end
505note niref: the request's id prefix (gcrq, 4..16 hex) names exactly one issue: its index, else gnn
506fn niref to ulong
507n = get gnn 0
508q = get gcrql 0
509if gt q 16
510ret n
511end
512w = n
513c = ulong 0
514for k ulong n bound 262144
515if nipre k q
516w = k
517c = add c 1
518end
519end
520if ne c 1
521ret n
522end
523ret w
524end
525fn nipre k ulong q ulong to bool
526for i ulong q bound 16
527if ne get gnix add mul k 17 i get gcrq i
528ret false
529end
530end
531ret true
532end
533fn nilink k ulong to void
534fputrl
535fput tcissp
536for i ulong 16
537fputc get gnix add mul k 17 i
538end
539end
540
541note ---- the list page
542note nifilt: the ?state= filter (0 open, 2 closed, 9 all; anything else open) and the tab counts in
543note gccnt and gcsn (cotabs reads them)
544fn nifilt to ulong
545f = coqstate 2
546if and ne f 2 ne f 9
547f = ulong 0
548end
549for s ulong 8
550put gccnt s 0
551end
552for k ulong get gnn 0 bound 262144
553s = nistate k
554put gccnt s add get gccnt s 1
555end
556put gcsn 0 get gnn 0
557put gcm 9 2
558ret f
559end
560note Keep list thread reads to one page. The status scan also supplies the filter counts.
561fn nipagen f ulong to void
562n = fqget tnpkey
563put gnpaged 0 0
564if ge n 0
565put gnpaged 0 1
566end
567v = ulong 0
568if and gt n 0 le n 6
569for i ulong ulong n bound 6
570c = get fval i
571if not fisdig c
572v = ulong 0
573break
574end
575v = add mul v 10 ulong sub c 48
576end
577end
578if eq v 0
579v = ulong 1
580end
581put gnpage 0 v
582put gnmatch 0 cotabnval f
583end
584fn cotabnval s ulong to ulong
585if eq s 9
586ret get gcsn 0
587end
588ret get gccnt s
589end
590fn nipageurl f ulong p ulong html bool to void
591fputrl
592fput tcisss
593fput tcstq
594cojsv 2 f
595if html
596fput tnpage
597else
598fput tnpjson
599end
600fnum p
601end
602fn nilnav f ulong to void
603p = get gnpage 0
604if and eq p 1 le get gnmatch 0 NIPAGE
605ret
606end
607fput tnnava
608if gt p 1
609fput tcah
610nipageurl f sub p 1 true
611fput tcqg
612fput tnpprev
613fput tcae
614cosp
615end
616if gt get gnmatch 0 mul p NIPAGE
617fput tcah
618nipageurl f add p 1 true
619fput tcqg
620fput tnpnext
621fput tcae
622end
623fput tnnavz
624end
625fn nilist to long
626if not niidx
627ret 500
628end
629f = nifilt
630nipagen f
631fsetti tciss
632frepohd 6
633ftic 32
634ftirepo
635fput tclh1
636costname 2 f
637fput tclh2
638cotabs 2 f
639fput tclh3
640niwlink
641m = ulong 0
642fput tclul
643skip = mul sub get gnpage 0 1 NIPAGE
644for j ulong get gnn 0 bound 262144
645k = sub sub get gnn 0 1 j
646s = nistate k
647if or eq f 9 eq f s
648if ge m skip
649if not nirow k s
650ret 500
651end
652end
653m = add m 1
654if eq m add skip NIPAGE
655break
656end
657end
658end
659fput tcluln
660if le m skip
661fput tclnone
662end
663nilnav f
664ret 200
665end
666fn nirow k ulong s ulong to bool
667fput tcli1
668nilink k
669fput tcqg
670n = nismall k tnfttl
671if eq n 0
672fput tcnot
673end
674for i ulong n bound 65536
675fescc get gnf i
676end
677fput tcli2
678costbadge 2 s
679nigh k
680if eq get gnative 0 0
681fput tnli3
682nighp tnghn
683fput tnli4
684nighte tnghop
685else
686fput tnmeta
687fput tcopen
688cosp
689nighte tnghop
690end
691fput tcmidd
692if not nithr k
693ret false
694end
695c = nicount
696fnum c
697fput tnli5
698if ne c 1
699fputc 115
700end
701fput tcli7
702fput tnmeta
703niorigin k
704fput tnmetae
705fput tcli10
706ret true
707end
708
709note ---- one issue page
710fn nipage to long
711if not niidx
712ret 500
713end
714k = niref
715if ge k get gnn 0
716ret 404
717end
718s = nistate k
719n = nismall k tnfttl
720put ftil 0 0
721for i ulong hmin n 256 bound 256
722ftic get gnf i
723end
724for i ulong len tntiss
725ftic get tntiss i
726end
727ftirepo
728frepohd 6
729fput tnph1
730if eq n 0
731fput tcnot
732end
733for i ulong n bound 65536
734fescc get gnf i
735end
736fput tnph2
737nigh k
738fput tnmeta
739costbadge 2 s
740fput tcmidd
741if eq get gnative 0 0
742fputc 35
743nighp tnghn
744fput tcmidd
745end
746fput tcopen
747cosp
748nighte tnghop
749if eq s 2
750fput tnclo
751nighte tnghcl
752x = nighv tnghre
753if gt get gnr 15 1
754fput tnreas
755nighp tnghre
756fputc 41
757end
758end
759fput tnmetae
760fput tnmeta
761niorigin k
762fput tnmetae
763nilabs k
764fput tnsece
765if not nibody k
766ret 500
767end
768if not nithr k
769ret 500
770end
771nicoms
772niwform k false
773ret 200
774end
775fn nilabs k ulong to void
776n = nismall k tnflab
777if eq n 0
778ret
779end
780fput tnmeta
781fput tnlab
782for i ulong n bound 65536
783c = get gnf i
784if eq c 10
785if lt add i 1 n
786fputc 44
787fputc 32
788end
789else
790fescc c
791end
792end
793fput tnmetae
794end
795note nibody k: the description as Markdown (the default branch for relative links)
796fn nibody k ulong to bool
797nipf k tnfdsc
798r = frdall
799if le r 0
800ret true
801end
802if ne get fxotr 0 0
803ret false
804end
805codrefb
806fput tnbox
807niwho
808fput tnwrote
809nighte tnghop
810fput tnmetae
811put gbmdl 0 0
812fput tnmd1
813brmd 0 ulong r
814fput tnmd2
815fput tnsece
816ret true
817end
818fn nicoms to void
819p = ulong 0
820c = ulong 0
821n = get gnthl 0
822while lt p n bound 16777216
823p = nirec p
824if ne get gnr 0 0
825nicom
826c = add c 1
827end
828end
829if eq c 0
830fput tnnocm
831end
832end
833note nicom: the parsed record (gnr) as a comment box; the login is text, the body Markdown
834fn nicom to void
835k = get gnr 0
836fput tnbox
837niraw 3
838if or eq k 1 eq k 4
839fput tnwrote
840end
841if eq k 2
842fput tnrevd
843niraw 5
844fput tnrevd2
845end
846if eq k 3
847fput tnrcon
848niraw 8
849fput tnline
850fnum get gnr 7
851fput tnon
852end
853if eq get gnr 2 20
854nitime get gnr 1
855else
856fputc 45
857end
858fput tnmetae
859o = get gnr 10
860b = get gnr 11
861if gt b 0
862for i ulong b bound 16777216
863put fxo i get gnth add o i
864end
865put gbmdl 0 0
866fput tnmd1
867brmd 0 b
868fput tnmd2
869end
870fput tnsece
871end
872note niraw a: the bytes gnth[gnr a, + gnr a+1), HTML-escaped
873fn niraw a ulong to void
874o = get gnr a
875for i ulong get gnr add a 1 bound 16777216
876fescc get gnth add o i
877end
878end