interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / store / evcol.om

863 lines · 16853 bytes Raw Blame History
1note store/evcol.om: the collector of door/ (docs/AGENT-DOOR.md) in the store-reading build, in place
2note of door/ev3col.om (which reads Radicle refs and COBs). run.sh composes it between door/ev2log.om
3note and door/ev4json.om when FORGE_STORE is set. One collection pass is change-triggered, never on a
4note clock: before a page of the stream is answered, evcollect compares cheap fingerprints with the
5note last pass of this process and reads only what moved:
6note social log its size; the new bytes are read with social's own line parser (stars, follows)
7note store nothing of its own: the table follows ROOT/catalog.tsv (store/repos.om); the
8note catalog file's stat is not read here (see evrepochk)
9note project i its catalog line (id, branch, head), the change times and sizes of
10note repo.git/refs/heads, repo.git/refs/tags,
11note repo.git/packed-refs and chain.tsv; then one for-each-ref of the default branch
12note and the tags, compared line by line with the snapshot <data>events/r/<key>
13note Kinds: branch_moved (10) and release (9, a tag created or moved) from the store, star (11) and
14note follow (12) from the social log. The open builds shelf and patches and issues are not part of this
15note build (their slices are seams), so those kinds never occur. Sources name the store object:
16note "chain.tsv:<N>" for a default-branch move recorded by record N of the project's chain (the LAND or
17note IMPORT record of that branch whose payload says "new <head>"; its time is the record's time),
18note "repo.git:<sha>" for a tag, or for a move no record of the chain names (the commit time), and
19note "social.log:<seq>" for stars and follows.
20text tevfh1 "<section class=\"box\"><h1>Feed</h1>\n<p class=\"muted\">What happened on this forge, newest first: releases, new commits on default branches, stars and follows. Only public repositories. Agents read the same list as <a href=\""
21text tevschn "/chain.tsv"
22text tevsrec "/records/"
23text tevsland "LAND"
24text tevsimp "IMPORT"
25text tevsnew "new "
26text tevscsrc "chain.tsv:"
27text tevsgsrc "repo.git:"
28const EVNO ulong 99999999
29note the chain record found for a branch move: its number (decimal digits) and its time
30global gevchn uchar 24
31global gevchnl ulong 1
32global gevcht ulong 1
33fn evcollect to void
34if eq get gevok 0 0
35evload
36end
37if ne get gevok 0 1
38ret
39end
40t0 = monons
41put gevpr 0 0
42put gevpe 0 0
43put gevbn 0 0
44put gevbatl 0 0
45evsocial
46for i ulong get fan 0 bound FAMAX
47evrepochk i
48end
49if gt get gevbn 0 0
50evflush
51end
52put ficut 0 0
53put fobtr 0 0
54put fobl 0 0
55if gt get gevpr 0 0
56dt = div ulong sub monons t0 1000
57evgb
58evgt tevlpas
59evgn dt
60evgt tevlpus
61evgn get gevpr 0
62evgt tevlpev
63evgn get gevpe 0
64evgout
65end
66end
67note ---- the social log (social/30store.om writes it; soload has verified it)
68fn evsocial to void
69if eq get gsok 0 0
70ret
71end
72sopdd
73sopt tslog
74fpb
75for i ulong get gspthl 0 bound 1024
76fpc get gspth i
77end
78if eq evstat 0
79ret
80end
81sz = evst64 48
82off = get gevsoff 0
83if eq sz off
84ret
85end
86if lt sz off
87off = ulong 0
88end
89fd = fopen fpth 0 get fpthl 0 524288 0
90if lt fd 0
91ret
92end
93put gevpr 0 add get gevpr 0 1
94for it ulong 100000
95r = pread int fd gevrb 0 len gevrb long off
96if le r 0
97break
98end
99u = evsocscan ulong r
100if eq u 0
101break
102end
103off = add off u
104end
105x = fclose int fd
106put gevsoff 0 off
107end
108fn evsocscan n ulong to ulong
109ln = new uchar 1024 0
110p = ulong 0
111for it ulong 2097152
112e = evrbeol p n
113if ge e n
114break
115end
116l = sub e p
117if lt l 1024
118for i ulong l bound 1024
119put ln i get gevrb add p i
120end
121evsocln part ln 0 l
122end
123p = add e 1
124end
125ret p
126end
127fn evrbeol p ulong n ulong to ulong
128e = p
129for k ulong 2097152
130if ge e n
131ret n
132end
133if eq get gevrb e 10
134ret e
135end
136e = add e 1
137end
138ret n
139end
140note evsocln: one social line; only star (1) and follow (7) are events. fav, unfav, watch, unwatch,
141note unstar, unfollow, account, name, session and logout are never read past their action word.
142fn evsocln ln view uchar * to void
143put gspc 0 0
144put gsbad 0 0
145solit ln tsl1
146seq = sonum ln
147solit ln tsl2
148ts = sonum ln
149solit ln tsl3
150sokclr
151sokt tsdidp
152dl = sostr ln
153evclr
154for i ulong get gskbl 0 bound 128
155evactc get gskb i
156end
157solit ln tsl4
158a = soact ln
159solit ln tsl5
160sokclr
161tl = sostr ln
162if ne get gsbad 0 0
163ret
164end
165put gevt 0 ts
166evsrct tevsocs
167evsrcnum seq
168if eq a 1
169evsstar
170end
171if eq a 7
172evsfoll
173end
174end
175note evsstar: gskb holds rad:<key>; an event only for a repository that is served now
176fn evsstar to void
177if not sokpre tsradp
178ret
179end
180for i ulong sub get gskbl 0 len tsradp bound 64
181evridc get gskb add len tsradp i
182end
183r = evridpub
184if eq r 9999
185ret
186end
187put gevk 0 11
188evpthrepo r
189evjsame
190evjst tevjsx
191for k ulong frnlen r bound 128
192evsubc frnbyte r k
193end
194evemit
195end
196note evsfoll: gskb holds the followed account's did:key; its page is found when the stream is read
197fn evsfoll to void
198if not sokpre tsdidp
199ret
200end
201put gevk 0 12
202for i ulong get gskbl 0 bound 128
203evxc get gskb i
204evsubc get gskb i
205end
206evemit
207end
208note ---- projects of the store
209note evsp i t: fpth = ROOT/projects/<name of i>/repo.git<t>
210fn evsp i ulong t view uchar * to void
211xspproj i
212fpt tfsrg
213fpt t
214end
215note evrepochk i: the fingerprint of project i (its key; its own catalog line: id, branch and head;
216note the change times and sizes of its ref folders, packed-refs and chain); a project whose
217note fingerprint moved is read (evrepo). The catalog file's own stat is not part of it (it was before
218note 2026-11-14): ipl rewrites catalog.tsv on every landing in any project, which moved every
219note fingerprint and made each landing read every served project. What the catalog stat guarded
220note stays guarded by the line: a project added, removed or replaced, or rows shifted after a
221note reload, give row i another key or id, so it is read; a landing changes its own line's head (and
222note its refs). A catalog rewritten with the same lines reads no project.
223fn evrepochk i ulong to void
224h = ulong 14695981039346656037
225for k ulong fridlen i bound 64
226h = evfnv h fridbyte i k
227end
228for k ulong 64
229h = evfnv h get xsgid add mul i 64 k
230end
231h = evfnv h uchar 47
232for k ulong get fabl i bound 64
233h = evfnv h get fabr add get fabo i k
234end
235h = evfnv h uchar 47
236h = evfnv h uchar get xshn i
237for k ulong mul get xshn i 40 bound 40
238h = evfnv h get xshead add mul i 40 k
239end
240evsp i tevsrh
241h = add h mul evstat 3
242evsp i tevsrt
243h = add h mul evstat 5
244evsp i tevspk
245h = add h mul evstat 7
246xspproj i
247fpt tevschn
248h = add h mul evstat 11
249if eq h get gevfp i
250ret
251end
252if evrepo i
253put gevfp i h
254end
255end
256note evsnapp i: fpth = <data>events/r/<key of i>
257fn evsnapp i ulong to void
258evpath tevrp
259for k ulong fridlen i bound 64
260fpc fridbyte i k
261end
262end
263note evrepo i: read project i; false when git did not answer (the next pass tries again)
264fn evrepo i ulong to bool
265fkgiti i
266fka tevfer
267fka tevfmt
268fkopen
269fkt tevrh
270for k ulong get fabl i bound 64
271fkc get fabr add get fabo i k
272end
273fka tevrt
274x = fexec 10000000000
275if ne x 0
276ret false
277end
278put gevpr 0 add get gevpr 0 1
279if or ne get fxotr 0 0 gt get fxol 0 len gevnew
280evgb
281evgt tevlcut
282for k ulong fridlen i bound 64
283evgc fridbyte i k
284end
285evgout
286ret true
287end
288n = get fxol 0
289for k ulong n bound 4194304
290put gevnew k get fxo k
291end
292put gevnewl 0 n
293first = evoldld i
294p = ulong 0
295for it ulong 4194304
296if ge p n
297break
298end
299e = p
300for k ulong 4194304
301if ge e n
302break
303end
304if eq get gevnew e 10
305break
306end
307e = add e 1
308end
309evrefln i p e first
310p = add e 1
311end
312evsnapw i
313ret true
314end
315note evoldld i: the snapshot of the last read into gevold; true when there is none (first sight)
316fn evoldld i ulong to bool
317put gevoldl 0 0
318evsnapp i
319r = frdall
320if lt r 0
321ret true
322end
323if or ne get fxotr 0 0 gt get fxol 0 len gevold
324ret true
325end
326n = get fxol 0
327for k ulong n bound 4194304
328put gevold k get fxo k
329end
330put gevoldl 0 n
331ret false
332end
333note evsnapw i: gevnew becomes the snapshot (written to .tmp, then renamed over it)
334fn evsnapw i ulong to void
335evsnapp i
336fpt tevtmp
337fd = fopen fpth 0 get fpthl 0 524865 384
338if lt fd 0
339ret
340end
341n = get gevnewl 0
342off = ulong 0
343for it ulong 4096
344if ge off n
345break
346end
347w = write int fd gevnew off sub n off
348if le w 0
349break
350end
351off = add off ulong w
352end
353x = fsync int fd
354y = fclose int fd
355if ne off n
356ret
357end
358pk = new uchar 8200 0
359put pk 0 2
360o = evpkadd pk 2
361evsnapp i
362o = evpkadd pk o
363r = renames pk 0 o 0
364end
365fn evpkadd pk edit uchar * o ulong to ulong
366n = get fpthl 0
367put pk o uchar and n 255
368put pk add o 1 uchar shr n 8
369for k ulong n bound 4096
370put pk add add o 2 k get fpth k
371end
372ret add add o 2 n
373end
374note ---- one ref line of gevnew: "<sha> <time> <refname>"
375fn evrefln i ulong a ulong e ulong first bool to void
376if lt sub e a 44
377ret
378end
379if ne get gevnew add a 40 32
380ret
381end
382r = add a 41
383t = ulong 0
384for k ulong 20
385if ge r e
386ret
387end
388c = get gevnew r
389r = add r 1
390if eq c 32
391break
392end
393if not evdig c
394ret
395end
396t = add mul t 10 ulong sub c 48
397end
398o = ulong EVNO
399if not first
400o = evoldsha r e
401end
402if ne o EVNO
403if evsame o a
404ret
405end
406end
407note the default branch moved (seen before) or a tag appeared or moved
408if evnat r e tevrh
409if evnbr i add r len tevrh e
410if ne o EVNO
411evbranch i o a t
412end
413end
414ret
415end
416if evnat r e tevrtp
417evtag i a t add r len tevrtp e
418end
419end
420fn evsame o ulong a ulong to bool
421for k ulong 40
422if ne get gevold add o k get gevnew add a k
423ret false
424end
425end
426ret true
427end
428note evnat p e t: gevnew[p, e) starts with t
429fn evnat p ulong e ulong t view uchar * to bool
430if lt sub e p len t
431ret false
432end
433for k ulong len t bound 128
434if ne get gevnew add p k get t k
435ret false
436end
437end
438ret true
439end
440note evnbr i p e: gevnew[p, e) is exactly the default branch of project i
441fn evnbr i ulong p ulong e ulong to bool
442if ne sub e p get fabl i
443ret false
444end
445o = get fabo i
446for k ulong get fabl i bound 64
447if ne get gevnew add p k get fabr add o k
448ret false
449end
450end
451ret true
452end
453note evoldsha r e: the offset of the sha of the gevold line whose refname equals gevnew[r, e), else EVNO
454fn evoldsha r ulong e ulong to ulong
455n = get gevoldl 0
456l = sub e r
457p = ulong 0
458for it ulong 4194304
459if ge p n
460break
461end
462q = p
463for k ulong 4194304
464if ge q n
465break
466end
467if eq get gevold q 10
468break
469end
470q = add q 1
471end
472s = evoldref p q
473if ne s EVNO
474if eq sub q s l
475if evrefeq s r l
476ret p
477end
478end
479end
480p = add q 1
481end
482ret EVNO
483end
484note evoldref p q: start of the refname of the gevold line [p, q) (after the second space), else EVNO
485fn evoldref p ulong q ulong to ulong
486if lt sub q p 44
487ret EVNO
488end
489s = add p 41
490for k ulong 21
491if ge s q
492ret EVNO
493end
494if eq get gevold s 32
495ret add s 1
496end
497s = add s 1
498end
499ret EVNO
500end
501fn evrefeq s ulong r ulong l ulong to bool
502for k ulong l bound 4096
503if ne get gevold add s k get gevnew add r k
504ret false
505end
506end
507ret true
508end
509note ---- events of one project
510fn evtag i ulong a ulong t ulong s ulong e ulong to void
511evclr
512put gevk 0 9
513put gevt 0 t
514evowndid
515evridi i
516evsrct tevsgsrc
517for k ulong 40
518evsrcc get gevnew add a k
519end
520evpthrepo i
521evptht tevrelp
522for k ulong sub e s bound 1024
523c = get gevnew add s k
524evpthc c
525evsubc c
526end
527evjsame
528evemit
529end
530fn evbranch i ulong o ulong a ulong t ulong to void
531fkgiti i
532fka tevrl
533fka tevcnt
534fkopen
535for k ulong 40
536fkc get gevold add o k
537end
538fkt tevdots
539for k ulong 40
540fkc get gevnew add a k
541end
542x = fexec 10000000000
543known = false
544cnt = ulong 0
545if eq x 0
546for k ulong get fxol 0 bound 21
547c = get fxo k
548if not evdig c
549break
550end
551cnt = add mul cnt 10 ulong sub c 48
552known = true
553end
554end
555rec = evchain i a
556evclr
557put gevk 0 10
558put gevt 0 t
559if and rec ne get gevcht 0 0
560put gevt 0 get gevcht 0
561end
562evowndid
563evridi i
564if rec
565evsrct tevscsrc
566for k ulong get gevchnl 0 bound 24
567evsrcc get gevchn k
568end
569else
570evsrct tevsgsrc
571for k ulong 40
572evsrcc get gevnew add a k
573end
574end
575for k ulong 40
576evxc get gevold add o k
577end
578evxc 32
579evpthrepo i
580evptht tevcmpp
581for k ulong 40
582evpthr get gevold add o k
583end
584evptht tevtdot
585for k ulong 40
586evpthr get gevnew add a k
587end
588evjsame
589evbrsub i known cnt
590evemit
591end
592note evbrsub: "<n> new commit(s) on <branch>", or "<branch> moved" when the count is not known
593fn evbrsub i ulong known bool cnt ulong to void
594o = get fabo i
595if not known
596evxc 45
597for k ulong get fabl i bound 64
598evsubc get fabr add o k
599end
600evsubt tevmovd
601ret
602end
603d = new uchar 24 0
604n = evdec cnt d
605for k ulong n bound 24
606evxc get d k
607evsubc get d k
608end
609evsubt tevncom
610if ne cnt 1
611evsubt tevncs
612end
613evsubt tevon
614for k ulong get fabl i bound 64
615evsubc get fabr add o k
616end
617end
618note ---- the chain record of a branch move
619note evchain i a: the last LAND or IMPORT record of project i's chain for its default branch, when its
620note payload (records/N) says "new <gevnew[a, a+40)>": gevchn / gevchnl hold N and gevcht its time;
621note false otherwise (no such record, or a chain or record that cannot be read whole)
622fn evchain i ulong a ulong to bool
623put gevchnl 0 0
624put gevcht 0 0
625xspproj i
626fpt tevschn
627r = frdall
628if or lt r 0 ne get fxotr 0 0
629ret false
630end
631n = get fxol 0
632p = ulong 0
633for it ulong n bound 16777216
634if ge p n
635break
636end
637e = p
638for k ulong sub n p bound 16777216
639if eq get fxo e 10
640break
641end
642e = add e 1
643end
644evchln i p e
645p = add e 1
646end
647if eq get gevchnl 0 0
648ret false
649end
650xspproj i
651fpt tevsrec
652for k ulong get gevchnl 0 bound 24
653fpc get gevchn k
654end
655r2 = frdall
656if or lt r2 0 ne get fxotr 0 0
657put gevchnl 0 0
658ret false
659end
660if evhasnew a
661ret true
662end
663put gevchnl 0 0
664ret false
665end
666note evchln i p e: chain line fxo[p, e) "N TAB time TAB KIND TAB actor TAB branch TAB ...": when KIND is
667note LAND or IMPORT and branch is i's default branch, N and the time are kept
668fn evchln i ulong p ulong e ulong to void
669tb = new ulong 5 0
670k = ulong 0
671for j ulong sub e p bound 16777216
672if eq get fxo add p j 9
673if lt k 5
674put tb k add p j
675end
676k = add k 1
677end
678end
679if lt k 5
680ret
681end
682if not evchkk get tb 1 get tb 2
683ret
684end
685if not evchkb i add get tb 3 1 get tb 4
686ret
687end
688evchkn p get tb 0 get tb 1
689end
690note evchkk t1 t2: KIND, fxo(t1, t2), is LAND or IMPORT
691fn evchkk t1 ulong t2 ulong to bool
692ks = add t1 1
693ret or evcfx ks t2 tevsland evcfx ks t2 tevsimp
694end
695note evchkb i bs be: fxo[bs, be) is i's default branch
696fn evchkb i ulong bs ulong be ulong to bool
697if ne sub be bs get fabl i
698ret false
699end
700o = get fabo i
701n = sub be bs
702for j ulong n bound 64
703if ne get fxo add bs j get fabr add o j
704ret false
705end
706end
707ret true
708end
709note evchkn p t0 t1: keep the record number fxo[p, t0) (1..20 digits) and the time fxo(t0, t1)
710fn evchkn p ulong t0 ulong t1 ulong to void
711nl = sub t0 p
712if or eq nl 0 gt nl 20
713ret
714end
715for j ulong nl bound 20
716if not evdig get fxo add p j
717ret
718end
719end
720for j ulong nl bound 20
721put gevchn j get fxo add p j
722end
723put gevchnl 0 nl
724ts = add t0 1
725put gevcht 0 0
726if eq sub t1 ts 20
727put gevcht 0 evisot ts
728end
729end
730fn evcfx a ulong e ulong t view uchar * to bool
731if ne sub e a len t
732ret false
733end
734for i ulong len t bound 64
735if ne get fxo add a i get t i
736ret false
737end
738end
739ret true
740end
741note evhasnew a: the record payload in fxo has the line "new <gevnew[a, a+40)>"
742fn evhasnew a ulong to bool
743n = get fxol 0
744p = ulong 0
745for it ulong n bound 16777216
746if ge p n
747break
748end
749e = p
750for k ulong sub n p bound 16777216
751if eq get fxo e 10
752break
753end
754e = add e 1
755end
756if evnewln p e a
757ret true
758end
759p = add e 1
760end
761ret false
762end
763note evnewln p e a: fxo[p, e) is exactly "new " and gevnew[a, a+40)
764fn evnewln p ulong e ulong a ulong to bool
765if ne sub e p add len tevsnew 40
766ret false
767end
768q = add p len tevsnew
769if not evcfx p q tevsnew
770ret false
771end
772for k ulong 40
773if ne get fxo add q k get gevnew add a k
774ret false
775end
776end
777ret true
778end
779note evisot p: fxo[p, p+20) "YYYY-MM-DDTHH:MM:SSZ" as epoch seconds (UTC); 0 when it is not that shape
780fn evisot p ulong to ulong
781for k ulong 20
782c = get fxo add p k
783if or eq k 4 eq k 7
784if ne c 45
785ret 0
786end
787continue
788end
789if eq k 10
790if ne c 84
791ret 0
792end
793continue
794end
795if or eq k 13 eq k 16
796if ne c 58
797ret 0
798end
799continue
800end
801if eq k 19
802if ne c 90
803ret 0
804end
805continue
806end
807if not evdig c
808ret 0
809end
810end
811days = evisod p
812if eq days 0
813ret 0
814end
815hh = evcnum add p 11 2
816mi = evcnum add p 14 2
817ss = evcnum add p 17 2
818if or or gt hh 23 gt mi 59 gt ss 60
819ret 0
820end
821s = add mul hh 3600 add mul mi 60 ss
822ret add mul days 86400 s
823end
824note evisod p: the date fxo[p, p+10) as days since 1970-01-01, 0 when out of range
825fn evisod p ulong to ulong
826y = evcnum p 4
827mo = evcnum add p 5 2
828d = evcnum add p 8 2
829if or lt y 1970 or lt mo 1 gt mo 12
830ret 0
831end
832if or lt d 1 gt d 31
833ret 0
834end
835ret evcdays y mo d
836end
837fn evcnum p ulong n ulong to ulong
838v = ulong 0
839for k ulong n bound 8
840v = add mul v 10 ulong sub get fxo add p k 48
841end
842ret v
843end
844note evcdays y m d: days from 1970-01-01 to the proleptic Gregorian date (y >= 1970)
845fn evcdays y ulong m ulong d ulong to ulong
846mp = add m 9
847yy = sub y 1
848if gt m 2
849mp = sub m 3
850yy = y
851end
852doy = add div add mul 153 mp 2 5 sub d 1
853ret evcdz yy doy
854end
855note evcdz yy doy: days since 1970-01-01 of day doy (0 = 1 March) of the March-based year yy
856fn evcdz yy ulong doy ulong to ulong
857era = div yy 400
858yoe = sub yy mul era 400
859doe = add mul yoe 365 div yoe 4
860doe = add doe doy
861doe = sub doe div yoe 100
862ret sub add mul era 146097 doe 719468
863end