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 / dl / dl.om

2127 lines · 38561 bytes Raw Blame History
1note dl/dl.om: ForgeDownloads unit of forged (fns dl*, globals gd*, texts td*). Contract v1.
2note Routes under /<owner>/<repo> (fridx set by the server, GET and HEAD only):
3note /archive/refs/heads/<b>.zip|.tar.gz /archive/refs/tags/<t>.zip|.tar.gz
4note /archive/<sha-or-ref>.zip|.tar.gz (7..40 hex: a commit reachable from a canonical ref)
5note /releases /releases/latest /releases/tag/<t> /releases/download/<t>/<asset>
6note Refs resolve at the storage root first (refs/heads, refs/tags), then in the delegate namespace
7note refs/namespaces/<tfnid>/refs/... . git runs as an argv exec (fkgit), never through a shell.
8note Archives: git archive into ~/forge-data/archives/<rid>/<sha>-<h16>.<ext>, h16 = the first 16 hex
9note of sha256(prefix), because the prefix <repo>-<ref>/ is inside the bytes. Total cache cap 5 GiB
10note (5368709120 bytes), one file at most 512 MiB (536870912); eviction is least recently used by
11note ctime (a cache hit chmods the file, which sets its ctime). Release assets (files in the tag's
12note release-assets/ dir) are cached as <blob>.blob the same way. Every cached file gets a sidecar
13note <file>.sha256 (64 hex) computed in Omega by om/tls/sha2.om.
14note dlclone (dl/dlclone.om) appends the clone panel (no public Git URL yet, archive links) for the
15note repo header; the store-reading build composes store/clone.om in its place (run.sh units).
16global gdp uchar 4096
17global gdpl ulong 1
18global gdf uchar 4096
19global gdfl ulong 1
20global gdref uchar 256
21global gdrefl ulong 1
22global gdkind ulong 1
23global gdfmt ulong 1
24global gdsha uchar 40
25global gdh16 uchar 16
26global gdpre uchar 512
27global gdprel ulong 1
28global gdst uchar 128
29global gdsize ulong 1
30global gdws uchar 4
31global gdent uchar 16384
32global gdent2 uchar 16384
33global gdold uchar 4096
34global gdoldl ulong 1
35global gdoldc ulong 1
36global gdtot ulong 1
37global gdsub uchar 256
38global gdsubl ulong 1
39global gdhex uchar 64
40note the tag list (dltags): every tag, no message text (dlmsg reads the subject and notes of one tag on
41note its own), so no tag message cuts the list. 16 MiB of records is about 150,000 tags; a longer list
42note is the whole 500 of fincut, never a shorter list. Record tables hold 262,144 records, more than
43note 16 MiB of records can hold (a record is at least 64 bytes).
44global gdtl uchar 16777216
45global gdtll ulong 1
46global gdrec ulong 262144
47global gdrend ulong 262144
48global gdrn ulong 1
49global gdso ulong 262144
50global gdsl ulong 262144
51global gdco ulong 262144
52global gdkeep ulong 262144
53global gdkn ulong 1
54global gdlat ulong 1
55global gdfa ulong 1
56global gdfn ulong 1
57note release-assets/ listing (dllsa): offsets into fxo (sha, name), name length and size per asset, and
58note the count of entries that are not offered (gdaskip)
59global gdan ulong 1
60global gdabo ulong 131072
61global gdasz ulong 131072
62global gdano ulong 131072
63global gdanl ulong 131072
64global gdaskip ulong 1
65global gdasn uchar 128
66global gdasnl ulong 1
67global gdwant uchar 128
68global gdwantl ulong 1
69global gdcold ulong 2
70note gdht: open-addressing set of kept tag records (record + 1) keyed by the short name, for dlkeep1
71global gdht ulong 524288
72note dlmsg: subject fxo[gdmsa, +gdmsn) and notes fxo[gdmba, +gdmbn) of one tag
73global gdmsa ulong 1
74global gdmsn ulong 1
75global gdmba ulong 1
76global gdmbn ulong 1
77note DLNONE: no record / no asset (larger than any index of the tables above)
78const DLNONE ulong 16777216
79text tdarch "/archive/"
80text tdheads "refs/heads/"
81text tdtags "refs/tags/"
82text tdns "refs/namespaces/"
83text tdsrh "/refs/heads/"
84text tdsrt "/refs/tags/"
85text tdrh0 "refs/heads"
86text tdrt0 "refs/tags"
87text tdsrh0 "/refs/heads"
88text tdsrt0 "/refs/tags"
89text tdzip ".zip"
90text tdtgz ".tar.gz"
91text tdezip "zip"
92text tdetgz "tar.gz"
93text tdeblob "blob"
94text tdrel "/releases"
95text tdrel2 "/releases/"
96text tdlat "/releases/latest"
97text tdrtag "/releases/tag/"
98text tdrdl "/releases/download/"
99text tdrevp "rev-parse"
100text tdverif "--verify"
101text tdquiet "--quiet"
102text tdcomm "^{commit}"
103text tdarcw "archive"
104text tdfzip "--format=zip"
105text tdftgz "--format=tar.gz"
106text tdpref "--prefix="
107text tdfer "for-each-ref"
108text tdcnt1 "--count=1"
109text tdcont "--contains"
110text tdpts "--points-at"
111text tdfmtr "--format=%(refname)"
112text tdfmtx "--format=x"
113text tdsortd "--sort=-creatordate"
114text tdtfmt "--format=%(refname)%1f%(objecttype)%1f%(objectname)%1f%(*objecttype)%1f%(*objectname)%1f%(creatordate:short)%1f%(creatordate:unix)%1e"
115text tdmfmt "--format=%(contents:subject)%1f%(contents:body)%1e"
116text tdcatf "cat-file"
117text tdlstr "ls-tree"
118text tdlopt "-l"
119text tdzopt "-z"
120text tddd "--"
121text tdradir "release-assets/"
122text tdmain "main"
123text tdcommit "commit"
124text tdtag "tag"
125text tdnull "/dev/null"
126text tdadir "archives"
127text tdtmp ".tmp-"
128text tdsum ".sha256"
129text tdctz "application/zip"
130text tdctg "application/gzip"
131text tdcto "application/octet-stream"
132text tdatt "attachment; filename="
133text tdcc "public, max-age=300"
134text tdpage "page"
135text tdrc "-rc"
136text tdalpha "-alpha"
137text tdbeta "-beta"
138text tdprer "-pre"
139text tddev "-dev"
140text tdtrel "Releases: "
141text tdtrel1 "Release "
142text tdsec1 "<section class=\"releases\"><h2>Releases</h2>\n"
143text tdsecx "</section>\n"
144text tdnorel "<p class=\"empty\">No releases yet. Every tag pushed to this repository is listed here as a release, with its source archives.</p>\n"
145text tdart1 "<article class=\"release\"><h3><a href=\""
146text tdq2 "\">"
147text tdax "</a>"
148text tdlpre " <span class=\"label\">pre-release</span>"
149text tdllat " <span class=\"label\">latest</span>"
150text tdmeta "</h3>\n<p class=\"meta\">"
151text tdcmt1 " &middot; commit <a href=\""
152text tdcommp "/commit/"
153text tdcode "<code>"
154text tdcodex "</code>"
155text tdcmtx "</code></a></p>\n"
156text tdsubj "<p class=\"subject\">"
157text tdpx "</p>\n"
158text tdnotes "<pre class=\"notes\">"
159text tdprex "</pre>\n"
160text tdtbl "<table class=\"assets\"><thead><tr><th>Download</th><th>Bytes</th><th>SHA-256</th></tr></thead><tbody>\n"
161text tdtblx "</tbody></table></article>\n"
162text tdtr1 "<tr><td><a href=\""
163text tdtd "</td><td>"
164text tdtdc "</td><td><code>"
165text tdtrx "</code></td></tr>\n"
166text tdnb "</td><td>-</td><td>checksum computed on first download</td></tr>\n"
167text tdask1 "<tr><td colspan=\"3\" class=\"muted\">"
168text tdask2 " more entries in release-assets/ are not offered for download: a name over 120 bytes, a byte other than A-Z a-z 0-9 . _ - +, a leading dot, or not a plain file. They are in the repository: read them with git or rad.</td></tr>\n"
169text tdsrc " source"
170text tdarht "/archive/refs/tags/"
171text tdarhh "/archive/refs/heads/"
172text tdpg1 "<nav class=\"pager\">"
173text tdpgn "<a href=\"?page="
174text tdpgnew "\">Newer</a> "
175text tdpgold "\">Older</a>"
176text tdnavx "</nav>\n"
177note ---- byte classes and hex
178fn dlhx v uchar to uchar
179if lt v 10
180ret add v 48
181end
182ret add v 87
183end
184fn dlishex c uchar to bool
185if and ge c 48 le c 57
186ret true
187end
188ret and ge c 97 le c 102
189end
190fn dldig c uchar to bool
191ret and ge c 48 le c 57
192end
193note dlrch: a byte allowed in a ref name in a URL: A-Z a-z 0-9 . _ - / +
194fn dlrch c uchar to bool
195if and ge c 97 le c 122
196ret true
197end
198if and ge c 65 le c 90
199ret true
200end
201if dldig c
202ret true
203end
204ret or or or eq c 46 eq c 95 or eq c 45 eq c 47 eq c 43
205end
206note dlrefok: gdref[0, gdrefl) is 1..200 allowed bytes, no leading - / ., no trailing / ., no .. // /.
207fn dlrefok to bool
208n = get gdrefl 0
209if or eq n 0 gt n 200
210ret false
211end
212c0 = get gdref 0
213if or or eq c0 45 eq c0 47 eq c0 46
214ret false
215end
216cl = get gdref sub n 1
217if or eq cl 47 eq cl 46
218ret false
219end
220p = get gdref 0
221for i ulong n
222c = get gdref i
223if not dlrch c
224ret false
225end
226if gt i 0
227if and eq c 46 or eq p 46 eq p 47
228ret false
229end
230if and eq c 47 eq p 47
231ret false
232end
233end
234p = c
235end
236ret true
237end
238note dlasok: gdasn[0, gdasnl) is one file name: 1..120 bytes of A-Z a-z 0-9 . _ - +, not starting with .
239fn dlasok to bool
240n = get gdasnl 0
241if or eq n 0 gt n 120
242ret false
243end
244if eq get gdasn 0 46
245ret false
246end
247for i ulong n
248c = get gdasn i
249if or eq c 47 not dlrch c
250ret false
251end
252end
253ret true
254end
255note ---- frest matching (the path after /<owner>/<repo>)
256fn dlrat o ulong t view uchar * to bool
257n = get frestl 0
258if gt add o len t n
259ret false
260end
261for i ulong len t
262if ne get frest add o i get t i
263ret false
264end
265end
266ret true
267end
268fn dlrst t view uchar * to bool
269ret dlrat 0 t
270end
271fn dlreq t view uchar * to bool
272if ne len t get frestl 0
273ret false
274end
275ret dlrat 0 t
276end
277fn dlrend t view uchar * to bool
278n = get frestl 0
279if lt n len t
280ret false
281end
282ret dlrat sub n len t t
283end
284note dlrcopy: frest[a, e) into gdref; false when longer than 200
285fn dlrcopy a ulong e ulong to bool
286put gdrefl 0 0
287if or ge a e gt sub e a 200
288ret false
289end
290for i ulong sub e a
291put gdref i get frest add a i
292end
293put gdrefl 0 sub e a
294ret true
295end
296note ---- path builder gdp (and the final path gdf)
297fn dlpb to void
298put gdpl 0 0
299end
300fn dlpc c uchar to void
301n = get gdpl 0
302if lt n 4095
303put gdp n c
304put gdpl 0 add n 1
305end
306end
307fn dlpt t view uchar * to void
308for i ulong len t
309dlpc get t i
310end
311end
312fn dlpd v ulong to void
313d = new uchar 20 0
314i = ulong 20
315x = v
316for it ulong 20
317i = sub i 1
318put d i uchar add rem x 10 48
319x = div x 10
320if eq x 0
321break
322end
323end
324for k ulong sub 20 i
325dlpc get d add i k
326end
327end
328fn dlpf to void
329for i ulong get gdfl 0
330dlpc get gdf i
331end
332end
333fn dlp2f to void
334n = get gdpl 0
335for i ulong n
336put gdf i get gdp i
337end
338put gdfl 0 n
339end
340note dlparc: <tfdata>archives
341fn dlparc to void
342dlpb
343dlpt tfdata
344dlpt tdadir
345end
346note dlpdir: <tfdata>archives/<rid>
347fn dlpdir to void
348dlparc
349dlpc 47
350for i ulong get fridl 0
351dlpc get frid i
352end
353end
354fn dlmkdir to bool
355dlpb
356dlpt tfdata
357r = makedir gdp 0 get gdpl 0 448
358dlparc
359r = makedir gdp 0 get gdpl 0 448
360dlpdir
361r = makedir gdp 0 get gdpl 0 448
362ret or eq r 0 eq r -17
363end
364note dlfinal: gdf = <dir>/<sha>-<h16>.<ext>
365fn dlfinal ext view uchar * to void
366dlpdir
367dlpc 47
368for i ulong 40
369dlpc get gdsha i
370end
371dlpc 45
372for i ulong 16
373dlpc get gdh16 i
374end
375dlpc 46
376dlpt ext
377dlp2f
378end
379note dlfblob: gdf = <dir>/<blob sha in gdsha>.blob
380fn dlfblob to void
381dlpdir
382dlpc 47
383for i ulong 40
384dlpc get gdsha i
385end
386dlpc 46
387dlpt tdeblob
388dlp2f
389end
390note ---- stat helpers (Linux arm64 stat: mode +16, size +48, ctime +104 s, +112 ns)
391fn dlst64 o ulong to ulong
392v = ulong 0
393for i ulong 8
394b = ulong get gdst add o i
395v = or v shl b mul i 8
396end
397ret v
398end
399fn dlst32 o ulong to ulong
400v = ulong 0
401for i ulong 4
402b = ulong get gdst add o i
403v = or v shl b mul i 8
404end
405ret v
406end
407note dlexists: gdf is a nonempty regular file; its size in gdsize
408fn dlexists to bool
409r = stat gdf 0 get gdfl 0 gdst 0 128
410if lt r 0
411ret false
412end
413if ne and dlst32 16 61440 32768
414ret false
415end
416put gdsize 0 dlst64 48
417ret gt get gdsize 0 0
418end
419note ---- argv helpers on the contract's fpk builder
420fn dlkt t view uchar * to void
421for i ulong len t
422fkc get t i
423end
424end
425fn dlksha to void
426fkopen
427for i ulong 40
428fkc get gdsha i
429end
430end
431note dlkns: start an arg "refs/namespaces/<nid>" + t
432fn dlkns t view uchar * to void
433fkopen
434dlkt tdns
435dlkt tfnid
436dlkt t
437end
438note ---- running git with stdout into an open file (archives can pass fxo's 16 MiB)
439fn dlchild ofd int to void
440nul = fopen tdnull 0 len tdnull 2 0
441if lt nul 0
442exit 126
443end
444x = dupfd int nul 0 0
445x = dupfd ofd 1 0
446x = dupfd int nul 2 0
447x = execprog fpk 0 get fpkl 0
448exit 127
449end
450note dlrunf: run argv fpk, stdout into ofd, 120 s deadline, file cap 512 MiB. Exit status 0..255,
451note -1 killed (deadline or cap), -2 cannot start, -3 signalled, -4 wait failure
452fn dlrunf ofd int to long
453pid = fork
454if lt pid 0
455ret -2
456end
457if eq pid 0
458dlchild ofd
459exit 127
460end
461dl = add monons 120000000000
462for it ulong 200000
463w = waitpid int pid gdws 0 4 1
464if eq w pid
465s = or ulong get gdws 0 shl ulong get gdws 1 8
466if eq and s 127 0
467ret long and shr s 8 255
468end
469ret -3
470end
471if and lt w 0 ne w -4
472ret -4
473end
474r = fstat ofd gdst 0 128
475toob = false
476if ge r 0
477toob = gt dlst64 48 536870912
478end
479if or toob gt monons dl
480x = killpid int pid 9
481w = waitpid int pid gdws 0 4 0
482ret -1
483end
484x = sleepns 2000000
485end
486ret -4
487end
488note dlgenx: run the argv already in fpk into <dir>/.tmp-<pid>.<n>, then rename it to gdf
489fn dlgenx to long
490dlpdir
491dlpc 47
492dlpt tdtmp
493dlpd ulong getpid
494fd = fopen gdp 0 get gdpl 0 524865 384
495if lt fd 0
496ret -2
497end
498r = dlrunf int fd
499x = fclose int fd
500if ne r 0
501x = unlink gdp 0 get gdpl 0
502ret -1
503end
504fkb
505fkopen
506for i ulong get gdpl 0
507fkc get gdp i
508end
509fkopen
510for i ulong get gdfl 0
511fkc get gdf i
512end
513r = renames fpk 0 get fpkl 0 0
514if ne r 0
515x = unlink gdp 0 get gdpl 0
516ret r
517end
518ret 0
519end
520note dlkarch: argv git archive --format=zip|tar.gz --prefix=<gdpre>/ <gdsha>
521fn dlkarch to void
522fksource
523fka tdarcw
524if eq get gdfmt 0 1
525fka tdfzip
526else
527fka tdftgz
528end
529fkopen
530dlkt tdpref
531for i ulong get gdprel 0
532fkc get gdpre i
533end
534fkc 47
535dlksha
536end
537note dlkblob: argv git cat-file blob <gdsha>
538fn dlkblob to void
539fksource
540fka tdcatf
541fka tdeblob
542dlksha
543end
544note dlensure: gdf exists (a hit touches its ctime) or is generated now (what 1 archive, 2 blob);
545note either way its .sha256 sidecar is written once; -7 = the site-wide cold-build cap is full
546fn dlensure what ulong to long
547if dlexists
548x = chmod gdf 0 get gdfl 0 384
549hs = dlsum
550ret 0
551end
552if not dlmkdir
553ret -2
554end
555if not dlcold
556ret -7
557end
558if eq what 1
559dlkarch
560else
561dlkblob
562end
563r = dlgenx
564if lt r 0
565ret r
566end
567gs = dlsum
568dlevict
569if not dlexists
570ret -5
571end
572ret 0
573end
574note dlcold: take a cold-build slot; at most 2 builds start in any 60 s, site-wide (gdcold: start times)
575fn dlcold to bool
576t = ulong monons
577for i ulong 2
578s = get gdcold i
579if or eq s 0 ge sub t s 60000000000
580put gdcold i t
581ret true
582end
583end
584ret false
585end
586note dlretry: whole seconds until the older slot frees, at least 1
587fn dlretry to ulong
588t = ulong monons
589a = get gdcold 0
590b = get gdcold 1
591if lt b a
592a = b
593end
594e = sub t a
595if ge e 60000000000
596ret 1
597end
598ret add div sub 60000000000 e 1000000000 1
599end
600note dlbusy: 503 with Retry-After (the server's error page; fretry is the contract's header field)
601fn dlbusy to long
602put fretry 0 dlretry
603ret 503
604end
605note ---- LRU eviction over <tfdata>archives/*/*
606fn dlevict to void
607for round ulong 64
608dlscan
609if le get gdtot 0 5368709120
610ret
611end
612if eq get gdoldl 0 0
613ret
614end
615x = unlink gdold 0 get gdoldl 0
616n = get gdoldl 0
617if lt add n 8 4096
618for i ulong len tdsum
619put gdold add n i get tdsum i
620end
621x = unlink gdold 0 add n len tdsum
622end
623end
624end
625fn dlscan to void
626put gdtot 0 0
627put gdoldl 0 0
628dlparc
629fd = fopen gdp 0 get gdpl 0 540672 0
630if lt fd 0
631ret
632end
633for it ulong 4096
634n = getdnts int fd gdent 0 16384
635if le n 0
636break
637end
638dlscan1 ulong n
639end
640x = fclose int fd
641end
642fn dlscan1 n ulong to void
643p = ulong 0
644for it ulong 16384
645if ge add p 19 n
646break
647end
648rl = or ulong get gdent add p 16 shl ulong get gdent add p 17 8
649if eq rl 0
650break
651end
652if and eq get gdent add p 18 4 ne get gdent add p 19 46
653put gdsubl 0 0
654for i ulong 255
655c = get gdent add add p 19 i
656if eq c 0
657break
658end
659put gdsub i c
660put gdsubl 0 add i 1
661end
662dlscand
663end
664p = add p rl
665end
666end
667fn dlpsub to void
668dlparc
669dlpc 47
670for i ulong get gdsubl 0
671dlpc get gdsub i
672end
673end
674fn dlscand to void
675dlpsub
676fd = fopen gdp 0 get gdpl 0 540672 0
677if lt fd 0
678ret
679end
680for it ulong 4096
681n = getdnts int fd gdent2 0 16384
682if le n 0
683break
684end
685dlscanf ulong n
686end
687x = fclose int fd
688end
689fn dlscanf n ulong to void
690p = ulong 0
691for it ulong 16384
692if ge add p 19 n
693break
694end
695rl = or ulong get gdent2 add p 16 shl ulong get gdent2 add p 17 8
696if eq rl 0
697break
698end
699if eq get gdent2 add p 18 8
700dlpsub
701dlpc 47
702for i ulong 255
703c = get gdent2 add add p 19 i
704if eq c 0
705break
706end
707dlpc c
708end
709dlscanf1
710end
711p = add p rl
712end
713end
714note dlscanf1: count the file in gdp, keep it as the eviction candidate when its ctime is oldest
715fn dlscanf1 to void
716r = stat gdp 0 get gdpl 0 gdst 0 128
717if lt r 0
718ret
719end
720put gdtot 0 add get gdtot 0 dlst64 48
721ct = add mul dlst64 104 1000000000 dlst64 112
722if and ne get gdoldl 0 0 ge ct get gdoldc 0
723ret
724end
725n = get gdpl 0
726for i ulong n
727put gdold i get gdp i
728end
729put gdoldl 0 n
730put gdoldc 0 ct
731end
732note ---- SHA-256 of the file gdf into gdhex, cached in the sidecar <gdf>.sha256
733fn dlsha256f to bool
734c = new ulong 40 0
735b = new uchar 65536 0
736o = new uchar 32 0
737fd = fopen gdf 0 get gdfl 0 524288 0
738if lt fd 0
739ret false
740end
741sha256_init c
742for it ulong 16384
743r = read int fd b 0 65536
744if lt r 0
745x = fclose int fd
746ret false
747end
748if eq r 0
749break
750end
751sha256_update c view part b 0 ulong r
752end
753x = fclose int fd
754sha256_final c o
755for i ulong 32
756v = get o i
757put gdhex mul i 2 dlhx shr v 4
758put gdhex add mul i 2 1 dlhx and v 15
759end
760ret true
761end
762fn dlhex64 to bool
763for i ulong 64
764if not dlishex get gdhex i
765ret false
766end
767end
768ret true
769end
770note dlsumrd: the SHA-256 of gdf from its .sha256 sidecar into gdhex, never computed (gdp = sidecar)
771fn dlsumrd to bool
772dlpb
773dlpf
774dlpt tdsum
775fd = fopen gdp 0 get gdpl 0 524288 0
776if lt fd 0
777ret false
778end
779r = read int fd gdhex 0 64
780x = fclose int fd
781if ne r 64
782ret false
783end
784ret dlhex64
785end
786note dlsum: the sidecar's SHA-256, or compute it over gdf in Omega and write the sidecar
787fn dlsum to bool
788if dlsumrd
789ret true
790end
791if not dlsha256f
792ret false
793end
794fd = fopen gdp 0 get gdpl 0 524865 384
795if ge fd 0
796w = write int fd gdhex 0 64
797x = fclose int fd
798end
799ret true
800end
801note ---- ref resolution
802note dlsha40: fxo starts with 40 lowercase hex; copied into gdsha
803fn dlsha40 to bool
804if lt get fxol 0 40
805ret false
806end
807for i ulong 40
808c = get fxo i
809if not dlishex c
810ret false
811end
812put gdsha i c
813end
814ret true
815end
816note dlrevp: rev-parse one candidate for gdref: 0 as given, 1 refs/heads/, 2 delegate heads,
817note 3 refs/tags/, 4 delegate tags; the commit sha into gdsha
818fn dlrevp mode ulong to bool
819fksource
820fka tdrevp
821fka tdverif
822fka tdquiet
823if eq mode 0
824fkopen
825end
826if eq mode 1
827fkopen
828dlkt tdheads
829end
830if eq mode 2
831dlkns tdsrh
832end
833if eq mode 3
834fkopen
835dlkt tdtags
836end
837if eq mode 4
838dlkns tdsrt
839end
840for i ulong get gdrefl 0
841fkc get gdref i
842end
843dlkt tdcomm
844r = fexec 10000000000
845if ne r 0
846ret false
847end
848ret dlsha40
849end
850note dlrch0 / dlrch1: reachability from a canonical head or tag (root or delegate namespace):
851note dlrch0 starts the for-each-ref --contains argv, the caller adds one commit id, dlrch1 adds the
852note ref patterns and runs it; shared with browse (brreach)
853fn dlrch0 to void
854fksource
855fka tdfer
856fka tdcnt1
857fka tdfmtx
858fka tdcont
859end
860fn dlrch1 to bool
861fka tdrh0
862fka tdrt0
863dlkns tdsrh0
864dlkns tdsrt0
865r = fexec 20000000000
866ret and eq r 0 gt get fxol 0 0
867end
868fn dlallhex to bool
869n = get gdrefl 0
870if or lt n 7 gt n 40
871ret false
872end
873for i ulong n
874if not dlishex get gdref i
875ret false
876end
877end
878ret true
879end
880note dlresolve: gdref of kind gdkind (1 head, 2 tag, 3 any head or tag name) to a commit in gdsha
881fn dlresolve to bool
882k = get gdkind 0
883if eq k 1
884if dlrevp 1
885ret true
886end
887ret dlrevp 2
888end
889if eq k 2
890if dlrevp 3
891ret true
892end
893ret dlrevp 4
894end
895if dlrevp 1
896ret true
897end
898if dlrevp 2
899ret true
900end
901if dlrevp 3
902ret true
903end
904ret dlrevp 4
905end
906note ---- archive names
907note dlprefix: gdpre = <repo>-<ref> with / as -, a tag's leading v before a digit dropped; gdh16
908fn dlprefix to void
909put gdprel 0 0
910for i ulong get frepol 0
911dlprc get frepo i
912end
913dlprc 45
914s = ulong 0
915if and eq get gdkind 0 2 gt get gdrefl 0 1
916if and eq get gdref 0 118 dldig get gdref 1
917s = 1
918end
919end
920for i ulong sub get gdrefl 0 s
921c = get gdref add i s
922if eq c 47
923c = 45
924end
925dlprc c
926end
927dlh16
928end
929fn dlprc c uchar to void
930n = get gdprel 0
931if lt n 511
932put gdpre n c
933put gdprel 0 add n 1
934end
935end
936fn dlh16 to void
937b = new uchar 512 0
938o = new uchar 32 0
939n = get gdprel 0
940for i ulong n
941put b i get gdpre i
942end
943k = sha2_digest 256 view part b 0 n o
944for i ulong 8
945v = get o i
946put gdh16 mul i 2 dlhx shr v 4
947put gdh16 add mul i 2 1 dlhx and v 15
948end
949end
950note ---- response fields
951fn dlsetetag to void
952put fetag 0 34
953for i ulong 40
954put fetag add i 1 get gdsha i
955end
956put fetag 41 34
957put fetagl 0 42
958end
959fn dlsetcc to void
960for i ulong len tdcc
961put fcc i get tdcc i
962end
963put fccl 0 len tdcc
964end
965fn dlsetfile to void
966n = get gdfl 0
967for i ulong n
968put ffile i get gdf i
969end
970put ffilel 0 n
971end
972note dlinm: If-None-Match holds "<gdsha>"
973fn dlinm to bool
974n = get finml 0
975if lt n 42
976ret false
977end
978for s ulong add sub n 42 1
979if eq get finm s 34
980if dlinm1 s
981ret true
982end
983end
984end
985ret false
986end
987fn dlinm1 s ulong to bool
988for i ulong 40
989j = add add s 1 i
990if ne get finm j get gdsha i
991ret false
992end
993end
994ret eq get finm add s 41 34
995end
996note ---- /archive/...
997note dlparse: frest = /archive/[refs/heads/|refs/tags/]<name>.zip|.tar.gz into gdkind gdref gdfmt;
998note 0 ok, 404 not an archive name, 400 a refused ref
999fn dlparse to ulong
1000n = get frestl 0
1001e = n
1002fmt = ulong 0
1003if dlrend tdtgz
1004fmt = 2
1005e = sub n len tdtgz
1006end
1007if and eq fmt 0 dlrend tdzip
1008fmt = 1
1009e = sub n len tdzip
1010end
1011if eq fmt 0
1012ret 404
1013end
1014put gdfmt 0 fmt
1015a = len tdarch
1016k = ulong 3
1017if dlrat a tdheads
1018k = 1
1019a = add a len tdheads
1020end
1021if and eq k 3 dlrat a tdtags
1022k = 2
1023a = add a len tdtags
1024end
1025put gdkind 0 k
1026if le e a
1027ret 404
1028end
1029if not dlrcopy a e
1030ret 400
1031end
1032if not dlrefok
1033ret 400
1034end
1035ret 0
1036end
1037fn dlarch to long
1038c = dlparse
1039if ne c 0
1040ret long c
1041end
1042if eq get gdkind 0 3
1043if dlallhex
1044ret dlarsha
1045end
1046end
1047if not dlresolve
1048ret 404
1049end
1050if eq get gdfmt 0 1
1051ret dlarch2 tdezip tdctz
1052end
1053ret dlarch2 tdetgz tdctg
1054end
1055note dlarsha: /archive/<7..40 hex>: 302 to the archive of a head or tag at exactly that commit, else
1056note 404 (no archive is built for any other commit)
1057fn dlarsha to long
1058if not dlrevp 0
1059ret 404
1060end
1061if not dlpts
1062ret 404
1063end
1064put fkind 0 2
1065flocb
1066for i ulong get fownl 0
1067flocc get fown i
1068end
1069flocc 47
1070for i ulong get frepol 0
1071flocc get frepo i
1072end
1073if eq get gdkind 0 1
1074floct tdarhh
1075else
1076floct tdarht
1077end
1078for i ulong get gdrefl 0
1079flocc get gdref i
1080end
1081if eq get gdfmt 0 1
1082floct tdzip
1083else
1084floct tdtgz
1085end
1086ret 302
1087end
1088note dlpts: the first canonical head (else tag) that points at gdsha, peeled, into gdkind / gdref
1089note (refname order puts refs/heads and refs/namespaces/<nid>/refs/heads before any tag)
1090fn dlpts to bool
1091fksource
1092fka tdfer
1093fka tdcnt1
1094fka tdfmtr
1095fka tdpts
1096dlksha
1097fka tdrh0
1098fka tdrt0
1099dlkns tdsrh0
1100dlkns tdsrt0
1101r = fexec 20000000000
1102if ne r 0
1103ret false
1104end
1105a = ulong 0
1106if dlxat 0 tdns
1107if not dlxat len tdns tfnid
1108ret false
1109end
1110a = add len tdns len tfnid
1111put gdkind 0 1
1112if dlxat a tdsrh
1113ret dlptsn add a len tdsrh
1114end
1115put gdkind 0 2
1116if dlxat a tdsrt
1117ret dlptsn add a len tdsrt
1118end
1119ret false
1120end
1121put gdkind 0 1
1122if dlxat 0 tdheads
1123ret dlptsn len tdheads
1124end
1125put gdkind 0 2
1126if dlxat 0 tdtags
1127ret dlptsn len tdtags
1128end
1129ret false
1130end
1131note dlptsn: the ref name in fxo from a to the newline into gdref, checked by dlrefok
1132fn dlptsn a ulong to bool
1133n = get fxol 0
1134e = a
1135for i ulong sub n a bound 16777216
1136if eq get fxo add a i 10
1137break
1138end
1139e = add e 1
1140end
1141if or le e a gt sub e a 200
1142ret false
1143end
1144for i ulong sub e a
1145put gdref i get fxo add a i
1146end
1147put gdrefl 0 sub e a
1148ret dlrefok
1149end
1150fn dlarch2 ext view uchar * ct view uchar * to long
1151dlprefix
1152dlfinal ext
1153dlsetetag
1154dlsetcc
1155if dlinm
1156put fkind 0 1
1157ret 304
1158end
1159r = dlensure 1
1160if eq r -7
1161ret dlbusy
1162end
1163if lt r 0
1164ret 500
1165end
1166put fkind 0 3
1167fsetct ct
1168fsetcd tdatt
1169for i ulong get gdprel 0
1170fcdc get gdpre i
1171end
1172fcdc 46
1173for i ulong len ext
1174fcdc get ext i
1175end
1176dlsetfile
1177ret 200
1178end
1179note ---- tags (releases)
1180note dltags: the whole tag list (no --count: an older tag is a release like the newest) into gdtl,
1181note records split, short names, dedup and validity into gdkeep
1182fn dltags to bool
1183fksource
1184fka tdfer
1185fka tdsortd
1186fka tdtfmt
1187fka tdrt0
1188dlkns tdsrt0
1189r = fexec 20000000000
1190if ne r 0
1191ret false
1192end
1193note a list longer than gdtl (or than fxo) is not parsed: its cut copy would be taken for the whole list
1194note (no releases, or only the newest ones, with status 200). Every caller answers the whole 500 of fincut.
1195if or gt get fxol 0 len gdtl ne get fxotr 0 0
1196fincut
1197ret false
1198end
1199note the loops over gdtl carry its size as their bound: a `for` with a smaller bound stops the server
1200note (trap 4, exit 104) when the list is longer, and the tag list can be 16,777,216 bytes
1201n = hmin get fxol 0 len gdtl
1202for i ulong n bound 16777216
1203put gdtl i get fxo i
1204end
1205put gdtll 0 n
1206if not dlsplit
1207fincut
1208ret false
1209end
1210put gdkn 0 0
1211put gdlat 0 DLNONE
1212for i ulong len gdht
1213put gdht i 0
1214end
1215for r2 ulong get gdrn 0 bound 262144
1216dlkeep1 r2
1217end
1218ret true
1219end
1220note dlsplit: records of gdtl into gdrec / gdrend; false when there are more than the tables hold
1221fn dlsplit to bool
1222put gdrn 0 0
1223s = ulong 0
1224n = get gdtll 0
1225for i ulong n bound 16777216
1226if eq get gdtl i 30
1227k = get gdrn 0
1228if ge k len gdrec
1229ret false
1230end
1231put gdrec k s
1232put gdrend k i
1233put gdrn 0 add k 1
1234s = add i 1
1235if lt s n
1236if eq get gdtl s 10
1237s = add s 1
1238end
1239end
1240end
1241end
1242ret true
1243end
1244note dlfld: field k of record r into gdfa / gdfn (fields split by 0x1f)
1245fn dlfld r ulong k ulong to void
1246a = get gdrec r
1247e = get gdrend r
1248f = ulong 0
1249s = a
1250for i ulong sub e a bound 16777216
1251j = add a i
1252if eq get gdtl j 31
1253if eq f k
1254put gdfa 0 s
1255put gdfn 0 sub j s
1256ret
1257end
1258f = add f 1
1259s = add j 1
1260end
1261end
1262if eq f k
1263put gdfa 0 s
1264put gdfn 0 sub e s
1265ret
1266end
1267put gdfa 0 e
1268put gdfn 0 0
1269end
1270note dlgat: gdtl[a, a + n) starts at o with t
1271fn dlgat o ulong e ulong t view uchar * to bool
1272if gt add o len t e
1273ret false
1274end
1275for i ulong len t
1276if ne get gdtl add o i get t i
1277ret false
1278end
1279end
1280ret true
1281end
1282fn dlfeq t view uchar * to bool
1283if ne get gdfn 0 len t
1284ret false
1285end
1286a = get gdfa 0
1287ret dlgat a add a len t t
1288end
1289note dlshort: the short tag name of record r (after refs/tags/ or the delegate prefix); false if neither
1290fn dlshort r ulong to bool
1291dlfld r 0
1292a = get gdfa 0
1293e = add a get gdfn 0
1294if dlgat a e tdtags
1295put gdso r add a len tdtags
1296put gdsl r sub e add a len tdtags
1297ret true
1298end
1299if not dlgat a e tdns
1300ret false
1301end
1302o = add a len tdns
1303if not dlgat o e tfnid
1304ret false
1305end
1306o = add o len tfnid
1307if not dlgat o e tdsrt
1308ret false
1309end
1310o = add o len tdsrt
1311put gdso r o
1312put gdsl r sub e o
1313ret true
1314end
1315fn dlsn2ref r ulong to void
1316n = hmin get gdsl r 255
1317a = get gdso r
1318for i ulong n
1319put gdref i get gdtl add a i
1320end
1321put gdrefl 0 n
1322put gdkind 0 2
1323end
1324fn dlsneq r ulong q ulong to bool
1325n = get gdsl r
1326if ne n get gdsl q
1327ret false
1328end
1329a = get gdso r
1330b = get gdso q
1331for i ulong n bound 16777216
1332if ne get gdtl add a i get gdtl add b i
1333ret false
1334end
1335end
1336ret true
1337end
1338note dlcommit: the peeled commit of record r (offset into gdtl in gdco); false for non-commits
1339fn dlcmof r ulong to bool
1340dlfld r 1
1341if dlfeq tdcommit
1342dlfld r 2
1343put gdco r get gdfa 0
1344ret eq get gdfn 0 40
1345end
1346dlfld r 3
1347if dlfeq tdcommit
1348dlfld r 4
1349put gdco r get gdfa 0
1350ret eq get gdfn 0 40
1351end
1352ret false
1353end
1354fn dlkeep1 r ulong to void
1355if not dlshort r
1356ret
1357end
1358dlsn2ref r
1359if not dlrefok
1360ret
1361end
1362if not dlcmof r
1363ret
1364end
1365if dldup r
1366ret
1367end
1368note gdkn stays below len gdkeep: it counts kept records, at most gdrn, at most len gdrec
1369k = get gdkn 0
1370put gdkeep k r
1371put gdkn 0 add k 1
1372if eq get gdlat 0 DLNONE
1373if not dlpre
1374put gdlat 0 r
1375end
1376end
1377end
1378note dldup r: a kept record has the short name of record r (true), else r joins the set (gdht)
1379fn dldup r ulong to bool
1380m = sub len gdht 1
1381j = and dlhash r m
1382for it ulong len gdht
1383v = get gdht j
1384if eq v 0
1385put gdht j add r 1
1386ret false
1387end
1388if dlsneq r sub v 1
1389ret true
1390end
1391j = and add j 1 m
1392end
1393ret true
1394end
1395note dlhash r: FNV-1a 64 of the short name of record r
1396fn dlhash r ulong to ulong
1397h = ulong 14695981039346656037
1398a = get gdso r
1399for i ulong get gdsl r bound 16777216
1400c = ulong get gdtl add a i
1401h = mul xor h c 1099511628211
1402end
1403ret h
1404end
1405note dlpre: gdref looks like a pre-release (-rc -alpha -beta -pre -dev)
1406fn dlpre to bool
1407if dlrhas tdrc
1408ret true
1409end
1410if dlrhas tdalpha
1411ret true
1412end
1413if dlrhas tdbeta
1414ret true
1415end
1416if dlrhas tdprer
1417ret true
1418end
1419ret dlrhas tddev
1420end
1421fn dlrhas t view uchar * to bool
1422n = get gdrefl 0
1423if lt n len t
1424ret false
1425end
1426for s ulong add sub n len t 1
1427if dlrhas1 s t
1428ret true
1429end
1430end
1431ret false
1432end
1433fn dlrhas1 s ulong t view uchar * to bool
1434for i ulong len t
1435if ne get gdref add s i get t i
1436ret false
1437end
1438end
1439ret true
1440end
1441fn dlsetsha r ulong to void
1442a = get gdco r
1443for i ulong 40
1444put gdsha i get gdtl add a i
1445end
1446end
1447note ---- HTML pieces
1448fn dlescref to void
1449for i ulong get gdrefl 0
1450fescc get gdref i
1451end
1452end
1453fn dlescf to void
1454a = get gdfa 0
1455for i ulong get gdfn 0 bound 16777216
1456fescc get gdtl add a i
1457end
1458end
1459fn dlrepol to void
1460fputb
1461fputrepo
1462end
1463note dlrel1: one release article for kept record r; full adds the release-assets/ files
1464fn dlrel1 r ulong full bool to void
1465dlsn2ref r
1466dlsetsha r
1467fput tdart1
1468dlrepol
1469fput tdrtag
1470dlescref
1471fput tdq2
1472dlescref
1473fput tdax
1474if dlpre
1475fput tdlpre
1476end
1477if eq get gdlat 0 r
1478fput tdllat
1479end
1480fput tdmeta
1481dlfld r 5
1482dlescf
1483fput tdcmt1
1484dlrepol
1485fput tdcommp
1486for i ulong 40
1487fputc get gdsha i
1488end
1489fput tdq2
1490fput tdcode
1491for i ulong 7
1492fputc get gdsha i
1493end
1494fput tdcmtx
1495dlnotes r
1496fput tdtbl
1497dlarow 1
1498dlarow 2
1499if full
1500dlassets
1501end
1502fput tdtblx
1503end
1504fn dlnotes r ulong to void
1505dlfld r 1
1506if not dlfeq tdtag
1507ret
1508end
1509if not dlmsg r
1510ret
1511end
1512if gt get gdmsn 0 0
1513fput tdsubj
1514fxesc get gdmsa 0 get gdmsn 0
1515fput tdpx
1516end
1517if gt get gdmbn 0 0
1518fput tdnotes
1519fxesc get gdmba 0 get gdmbn 0
1520fput tdprex
1521end
1522end
1523note dlmsg r: the subject and notes of the tag of record r, read on their own into fxo (gdmsa / gdmsn,
1524note gdmba / gdmbn) and shown before the next git call. false when git fails (the whole 500 of fovfl)
1525note or the message is longer than fxo (the whole 500 of fincut): a message is never shown cut.
1526fn dlmsg r ulong to bool
1527put gdmsn 0 0
1528put gdmbn 0 0
1529dlfld r 0
1530fksource
1531fka tdfer
1532fka tdcnt1
1533fka tdmfmt
1534fkopen
1535a = get gdfa 0
1536for i ulong get gdfn 0 bound 8192
1537fkc get gdtl add a i
1538end
1539x = fexec 20000000000
1540if ne get fxotr 0 0
1541fincut
1542ret false
1543end
1544if ne x 0
1545put fobtr 0 1
1546ret false
1547end
1548n = get fxol 0
1549e = n
1550k = n
1551while gt k 0 bound 16777216
1552k = sub k 1
1553if eq get fxo k 30
1554e = k
1555break
1556end
1557end
1558s = ulong 0
1559while lt s e bound 16777216
1560if eq get fxo s 31
1561break
1562end
1563s = add s 1
1564end
1565put gdmsa 0 0
1566put gdmsn 0 s
1567if lt s e
1568put gdmba 0 add s 1
1569put gdmbn 0 sub e add s 1
1570end
1571ret true
1572end
1573note dlarow: the source archive row (fmt 1 zip, 2 tar.gz) of the release in gdref / gdsha
1574fn dlarow fmt ulong to void
1575put gdfmt 0 fmt
1576dlprefix
1577if eq fmt 1
1578dlfinal tdezip
1579else
1580dlfinal tdetgz
1581end
1582fput tdtr1
1583dlrepol
1584fput tdarht
1585dlescref
1586if eq fmt 1
1587fput tdzip
1588else
1589fput tdtgz
1590end
1591fput tdq2
1592for i ulong get gdprel 0
1593fescc get gdpre i
1594end
1595if eq fmt 1
1596fput tdzip
1597else
1598fput tdtgz
1599end
1600fput tdsrc
1601fput tdax
1602dlsumcells
1603end
1604note dlsumcells: the size and SHA-256 cells of gdf (archive or blob) only when it is already built
1605note with its sidecar; rendering a page never builds or hashes anything
1606fn dlsumcells to void
1607if dlexists
1608if dlsumrd
1609fput tdtd
1610fnum get gdsize 0
1611fput tdtdc
1612for i ulong 64
1613fputc get gdhex i
1614end
1615fput tdtrx
1616ret
1617end
1618end
1619fput tdnb
1620end
1621note ---- release-assets/ of a tag (the commit in gdsha)
1622note dllsa: git ls-tree -l -z <commit> -- release-assets/ into fxo, one row per asset in gdabo / gdano /
1623note gdanl / gdasz (offsets into fxo: the rows are shown, or the download found, before the next git
1624note call), and the count of entries not offered in gdaskip
1625fn dllsa to void
1626put gdan 0 0
1627put gdaskip 0 0
1628fksource
1629fka tdlstr
1630fka tdlopt
1631fka tdzopt
1632dlksha
1633fka tddd
1634fka tdradir
1635r = fexec 20000000000
1636if ne r 0
1637ret
1638end
1639if ne get fxotr 0 0
1640fincut
1641ret
1642end
1643n = get fxol 0
1644note the listing can be longer than 1,000,000 bytes (many assets): the bound is the size of fxo
1645s = ulong 0
1646for i ulong n bound 16777216
1647if eq get fxo i 0
1648dllsa1 s i
1649s = add i 1
1650end
1651end
1652end
1653note dllsa1: one entry fxo[s, e) "<mode> blob <sha> <size>\t<path>"
1654fn dllsa1 s ulong e ulong to void
1655note the table holds 131,072 assets: more rows than one page can carry (the response is at most 8 MiB
1656note and a row is over 100 bytes). One more entry is not dropped in silence: the whole 500 of fincut.
1657k = get gdan 0
1658if ge k len gdabo
1659fincut
1660ret
1661end
1662t = s
1663for i ulong sub e s bound 16777216
1664if eq get fxo add s i 9
1665t = add s i
1666break
1667end
1668end
1669if or le t s lt sub t s 53
1670dlaskip
1671ret
1672end
1673p = s
1674for i ulong 8
1675if eq get fxo add s i 32
1676p = add add s i 1
1677break
1678end
1679end
1680if ne get fxo p 98
1681dlaskip
1682ret
1683end
1684q = add p 4
1685if ne get fxo q 32
1686dlaskip
1687ret
1688end
1689q = add p 45
1690if ne get fxo q 32
1691dlaskip
1692ret
1693end
1694dllsa2 k add p 5 add p 46 t e
1695end
1696note dlaskip: one entry of release-assets/ that is not offered (the page and the JSON say how many)
1697fn dlaskip to void
1698put gdaskip 0 add get gdaskip 0 1
1699end
1700fn dllsa2 k ulong h ulong z ulong t ulong e ulong to void
1701a = add t 1
1702if not dlxat a tdradir
1703ret
1704end
1705a = add a len tdradir
1706nl = sub e a
1707if or eq nl 0 gt nl 120
1708dlaskip
1709ret
1710end
1711for i ulong nl
1712put gdasn i get fxo add a i
1713end
1714put gdasnl 0 nl
1715if not dlasok
1716dlaskip
1717ret
1718end
1719dllsa3 k h a nl dlszp z t
1720end
1721fn dlszp z ulong t ulong to ulong
1722sz = ulong 0
1723for i ulong sub t z bound 16777216
1724c = get fxo add z i
1725if dldig c
1726sz = add mul sz 10 ulong sub c 48
1727end
1728end
1729ret sz
1730end
1731fn dllsa3 k ulong h ulong a ulong nl ulong sz ulong to void
1732put gdabo k h
1733put gdano k a
1734put gdanl k nl
1735put gdasz k sz
1736put gdan 0 add k 1
1737end
1738fn dlxat o ulong t view uchar * to bool
1739if gt add o len t get fxol 0
1740ret false
1741end
1742for i ulong len t
1743if ne get fxo add o i get t i
1744ret false
1745end
1746end
1747ret true
1748end
1749fn dlassets to void
1750dllsa
1751c = new uchar 40 0
1752for i ulong 40
1753put c i get gdsha i
1754end
1755for k ulong get gdan 0 bound 131072
1756dlasrow k
1757end
1758if gt get gdaskip 0 0
1759fput tdask1
1760fnum get gdaskip 0
1761fput tdask2
1762end
1763for i ulong 40
1764put gdsha i get c i
1765end
1766end
1767fn dlabsha k ulong to void
1768b = get gdabo k
1769for i ulong 40
1770put gdsha i get fxo add b i
1771end
1772end
1773fn dlasrow k ulong to void
1774fput tdtr1
1775dlrepol
1776fput tdrdl
1777dlescref
1778fputc 47
1779n = get gdanl k
1780b = get gdano k
1781fxesc b n
1782fput tdq2
1783fxesc b n
1784fput tdax
1785dlabsha k
1786dlfblob
1787dlsumcells
1788end
1789note dlblobf: (browse /raw/ over 8 MiB) blob id s[0,40) into the blob cache and ffile; 0 ok, -1 not a
1790note lowercase hex id, else dlensure's code (-7 = cold-build cap full: answer with dlbusy)
1791fn dlblobf s view uchar * to long
1792if lt len s 40
1793ret -1
1794end
1795for i ulong 40
1796c = get s i
1797if not dlishex c
1798ret -1
1799end
1800put gdsha i c
1801end
1802dlfblob
1803r = dlensure 2
1804if lt r 0
1805ret r
1806end
1807dlsetfile
1808ret 0
1809end
1810note ---- /releases pages
1811fn dlrtitle t view uchar * to void
1812fsetti t
1813for i ulong get frepol 0
1814ftic get frepo i
1815end
1816end
1817note dlpageq: ?page=N of /releases, /branches and /tags; 1 when absent or not a decimal number. No
1818note digit cap: 150,000 tags are 15,000 pages of 10, and with a 4-digit cap page 10000 and later
1819note were page 1 again (a 200 of the wrong rows; the older link of page 9999 led back to page 1). A
1820note number over DLPGMAX is DLPGMAX, which is past the end of every list: the 404 of a page past the
1821note last row.
1822const DLPGMAX ulong 1000000000
1823fn dlpageq to ulong
1824n = fqget tdpage
1825if le n 0
1826ret 1
1827end
1828v = ulong 0
1829for i ulong ulong n bound 4096
1830c = get fval i
1831if not dldig c
1832ret 1
1833end
1834v = add mul v 10 ulong sub c 48
1835if gt v DLPGMAX
1836v = DLPGMAX
1837end
1838end
1839if eq v 0
1840ret 1
1841end
1842ret v
1843end
1844fn dlrels to long
1845if not dltags
1846ret 500
1847end
1848p = dlpageq
1849s = mul sub p 1 10
1850kn = get gdkn 0
1851if and gt p 1 ge s kn
1852ret 404
1853end
1854dlrtitle tdtrel
1855frepohd 4
1856fput tdsec1
1857if eq kn 0
1858fput tdnorel
1859fput tdsecx
1860ret 200
1861end
1862for i ulong 10
1863k = add s i
1864if ge k kn
1865break
1866end
1867dlrel1 get gdkeep k false
1868end
1869dlpager p kn
1870fput tdsecx
1871ret 200
1872end
1873fn dlpager p ulong kn ulong to void
1874more = lt mul p 10 kn
1875if and eq p 1 not more
1876ret
1877end
1878fput tdpg1
1879if gt p 1
1880fput tdpgn
1881fnum sub p 1
1882fput tdpgnew
1883end
1884if more
1885fput tdpgn
1886fnum add p 1
1887fput tdpgold
1888end
1889fput tdnavx
1890end
1891fn dlrlat to long
1892if not dltags
1893ret 500
1894end
1895r = get gdlat 0
1896if eq r DLNONE
1897ret 404
1898end
1899dlsn2ref r
1900put fkind 0 2
1901flocb
1902for i ulong get fownl 0
1903flocc get fown i
1904end
1905flocc 47
1906for i ulong get frepol 0
1907flocc get frepo i
1908end
1909floct tdrtag
1910for i ulong get gdrefl 0
1911flocc get gdref i
1912end
1913ret 302
1914end
1915note dlrfind: the kept record whose short name is gdref, or DLNONE
1916fn dlrfind to ulong
1917n = get gdrefl 0
1918for i ulong get gdkn 0 bound 262144
1919r = get gdkeep i
1920if eq get gdsl r n
1921if dlrfind1 r
1922ret r
1923end
1924end
1925end
1926ret DLNONE
1927end
1928fn dlrfind1 r ulong to bool
1929a = get gdso r
1930for i ulong get gdrefl 0
1931if ne get gdtl add a i get gdref i
1932ret false
1933end
1934end
1935ret true
1936end
1937note dltags reuses gdref per record, so the requested tag is copied in only after it
1938fn dlrtag to long
1939if not dltags
1940ret 500
1941end
1942if not dlrcopy len tdrtag get frestl 0
1943ret 404
1944end
1945if not dlrefok
1946ret 400
1947end
1948r = dlrfind
1949if eq r DLNONE
1950ret 404
1951end
1952dlrtitle tdtrel1
1953frepohd 4
1954fput tdsec1
1955dlrel1 r true
1956fput tdsecx
1957ret 200
1958end
1959note dlrdl: /releases/download/<tag>/<asset>, the asset from release-assets/ of the tag's commit
1960fn dlrdl to long
1961a = len tdrdl
1962e = get frestl 0
1963m = e
1964for i ulong sub e a
1965j = sub sub e 1 i
1966if eq get frest j 47
1967m = j
1968break
1969end
1970end
1971if or ge m e le m a
1972ret 404
1973end
1974put gdasnl 0 0
1975if gt sub e add m 1 120
1976ret 400
1977end
1978for i ulong sub e add m 1
1979put gdasn i get frest add add m 1 i
1980end
1981put gdasnl 0 sub e add m 1
1982if not dlasok
1983ret 400
1984end
1985for i ulong get gdasnl 0
1986put gdwant i get gdasn i
1987end
1988put gdwantl 0 get gdasnl 0
1989if not dlrcopy a m
1990ret 400
1991end
1992if not dlrefok
1993ret 400
1994end
1995put gdkind 0 2
1996if not dlresolve
1997ret 404
1998end
1999ret dlrdl2
2000end
2001fn dlrdl2 to long
2002dllsa
2003k = dlasfind
2004if eq k DLNONE
2005ret 404
2006end
2007dlabsha k
2008dlfblob
2009dlsetetag
2010dlsetcc
2011if dlinm
2012put fkind 0 1
2013ret 304
2014end
2015r = dlensure 2
2016if eq r -7
2017ret dlbusy
2018end
2019if lt r 0
2020ret 500
2021end
2022put fkind 0 3
2023fsetct tdcto
2024fsetcd tdatt
2025for i ulong get gdwantl 0
2026fcdc get gdwant i
2027end
2028dlsetfile
2029ret 200
2030end
2031note dlasfind: the listed asset named gdwant (dllsa reuses gdasn while it scans), or DLNONE
2032fn dlasfind to ulong
2033n = get gdwantl 0
2034for k ulong get gdan 0 bound 131072
2035if eq get gdanl k n
2036if dlasfind1 k n
2037ret k
2038end
2039end
2040end
2041ret DLNONE
2042end
2043fn dlasfind1 k ulong n ulong to bool
2044b = get gdano k
2045for i ulong n
2046if ne get fxo add b i get gdwant i
2047ret false
2048end
2049end
2050ret true
2051end
2052fn dlrelr to long
2053if or dlreq tdrel dlreq tdrel2
2054if fjwant
2055ret dljrels
2056end
2057fyalt
2058ret dlrels
2059end
2060if dlreq tdlat
2061ret dlrlat
2062end
2063if dlrst tdrtag
2064if fjwant
2065ret dljrtag
2066end
2067fyalt
2068ret dlrtag
2069end
2070if dlrst tdrdl
2071ret dlrdl
2072end
2073ret 404
2074end
2075note dlanytag: the current repo has at least one tag where the releases page looks for them (the
2076note storage root, then the delegate namespace), so /releases lists a release. One for-each-ref with
2077note --count=1: the project page's "Get it" button (server/pages.om fpjget) reads only this, never the
2078note whole tag list (a list too long for gdtl is the whole 500 of dltags; the button must not be).
2079fn dlanytag to bool
2080fksource
2081fka tdfer
2082fka tdcnt1
2083fka tdfmtx
2084fka tdrt0
2085dlkns tdsrt0
2086r = fexec 5000000000
2087if ne r 0
2088ret false
2089end
2090ret gt get fxol 0 0
2091end
2092note ---- clone panel for the repo header (current repo: frid, frepo); default branch from nodes/head.om
2093fn dldefbr to void
2094if nshead
2095put gdrefl 0 0
2096for i ulong get nshbl 0 bound 256
2097put gdref i get nshb i
2098end
2099put gdrefl 0 get nshbl 0
2100if dlrefok
2101ret
2102end
2103end
2104for i ulong len tdmain
2105put gdref i get tdmain i
2106end
2107put gdrefl 0 len tdmain
2108end
2109note ---- dispatch
2110fn dlroute to long
2111if ge get fridx 0 get fan 0
2112ret 0
2113end
2114arch = dlrst tdarch
2115rel = or dlreq tdrel dlrst tdrel2
2116if and not arch not rel
2117ret 0
2118end
2119m = get fmeth 0
2120if and ne m 1 ne m 2
2121ret 405
2122end
2123if arch
2124ret dlarch
2125end
2126ret dlrelr
2127end