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 / contrib / forge-contribute.om

808 lines · 11792 bytes Raw Blame History
1note forge-contribute: clone, branch, commit, receipt, Radicle patch, review request, digest.
2note Twelve arguments after the program name. See docs/ANNOYANCES.md.
3note The receipt is attached by rad patch edit. git refuses a newline in a push option.
4note hmin: the smaller of two counts. server/util.om fputlc calls it (since the JSON repo summary);
5note forged gets it from seed/net/http.om, which this tool does not compose, so the same five lines
6note stand here. Copied from omega-mv seed/net/http.om fn hmin.
7fn hmin a ulong b ulong to ulong
8if lt a b
9ret a
10end
11ret b
12end
13global fcbig uchar 3840
14global fcal ulong 12
15global qnid uchar 40
16global fccd ulong 1
17text tcenv "/usr/bin/env"
18text tcdash "-i"
19text tchome "HOME="
20text tcpath "PATH="
21text tclbin "/.local/bin:/usr/bin:/bin"
22text tcradh "RAD_HOME="
23text tcradp "/.radicle"
24text tcradx "/.local/bin/rad"
25text tcg1 "GIT_AUTHOR_NAME=forge-contribute"
26text tcg2 "GIT_AUTHOR_EMAIL=forge@localhost"
27text tcg3 "GIT_COMMITTER_NAME=forge-contribute"
28text tcg4 "GIT_COMMITTER_EMAIL=forge@localhost"
29text tcgit "/usr/bin/git"
30text tcc "-C"
31text tcadd "add"
32text tcdd "--"
33text tccmt "commit"
34text tcm "-m"
35text tccfg "-c"
36text tcgp "commit.gpgsign=false"
37text tcun "user.name=forge-contribute"
38text tcum "user.email=forge@localhost"
39text tcco "checkout"
40text tcb "-b"
41text tcpush "push"
42text tco "-o"
43text tcpm "patch.message="
44text tcref "HEAD:refs/patches"
45text tcrad "rad"
46text tcrp "rev-parse"
47text tchead "HEAD"
48text tctree "HEAD^{tree}"
49text tcclone "clone"
50text tcradp2 "rad:"
51text tcped "patch"
52text tcedit "edit"
53text tcrev "review"
54text tcrepo "--repo"
55text tcna "--no-announce"
56text tcmsg "--message"
57text tcreq "review requested"
58text tcok1 "patch "
59text tcok2 "commit "
60text tcnl "\n"
61text tcpass "RAD_PASSPHRASE="
62text tcfail "forge-contribute: a step failed; its output follows\n"
63fn fcgit to void
64fka tcgit
65fka tcc
66fcnew 1
67end
68fn fcoff i ulong to ulong
69ret mul i ulong 320
70end
71fn fcarg i ulong to void
72o = mul i 320
73n = get fcal i
74for k ulong n bound 320
75fkc get fcbig add o k
76end
77end
78note fcnew: argument i as a record of its own (fcarg appends to the open record)
79fn fcnew i ulong to void
80fkopen
81fcarg i
82end
83fn fcload to long
84buf = new uchar 320 0
85if ne argcnt 13
86ret 2
87end
88for i ulong 12
89r = argread add i 1 buf 0 319
90if or lt r 1 gt r 319
91ret 2
92end
93put fcal i ulong r
94o = mul i 320
95for k ulong ulong r bound 320
96put fcbig add o k get buf k
97end
98end
99ret 0
100end
101fn fcbad i ulong to bool
102o = mul i 320
103n = get fcal i
104for k ulong n bound 320
105c = get fcbig add o k
106if or lt c 32 eq c 127
107ret true
108end
109end
110ret false
111end
112fn fcabs i ulong to bool
113if eq get fcbig mul i 320 47
114ret true
115end
116ret false
117end
118note fcdots: argument i holds a ".." path segment (start or "/" before it, end or "/" after it)
119fn fcdots i ulong to bool
120o = mul i 320
121n = get fcal i
122for k ulong n bound 320
123if fcdotat o n k
124ret true
125end
126end
127ret false
128end
129fn fcdotat o ulong n ulong k ulong to bool
130if ge add k 1 n
131ret false
132end
133if ne get fcbig add o k 46
134ret false
135end
136if ne get fcbig add o add k 1 46
137ret false
138end
139if gt k 0
140if ne get fcbig add o sub k 1 47
141ret false
142end
143end
144if lt add k 2 n
145if ne get fcbig add o add k 2 47
146ret false
147end
148end
149ret true
150end
151note fcpdots: a ".." segment in DIR, CMD, FILE, BODY, DATA or HOME
152fn fcpdots to bool
153if fcdots 1
154ret true
155end
156if fcdots 4
157ret true
158end
159if fcdots 8
160ret true
161end
162if fcdots 9
163ret true
164end
165if fcdots 10
166ret true
167end
168ret fcdots 11
169end
170note fcdpath: fpth = DIR (argument 1)
171fn fcdpath to void
172put fpthl 0 0
173o = mul ulong 1 320
174for k ulong get fcal 1 bound 320
175fpc get fcbig add o k
176end
177end
178note fcexist: DIR already exists (any file type)
179fn fcexist to bool
180fcdpath
181r = lstat fpth 0 get fpthl 0 fstb 0 128
182ret ge r 0
183end
184fn fctok i ulong to bool
185o = mul i 320
186n = get fcal i
187if or eq n 0 gt n 39
188ret false
189end
190for k ulong n bound 39
191c = get fcbig add o k
192ok = false
193if and ge c 48 le c 57
194ok = true
195end
196if and ge c 97 le c 122
197ok = true
198end
199if eq c 45
200ok = true
201end
202if not ok
203ret false
204end
205end
206ret true
207end
208fn fchex c uchar to bool
209if and ge c 48 le c 57
210ret true
211end
212ret and ge c 97 le c 102
213end
214fn fcvalid to bool
215for i ulong 12
216if fcbad i
217ret false
218end
219end
220if fcpdots
221ret false
222end
223if not fcabs 1
224ret false
225end
226if not fcabs 4
227ret false
228end
229if not fcabs 9
230ret false
231end
232if not fcabs 10
233ret false
234end
235if not fcabs 11
236ret false
237end
238if ne get fcbig add fcoff 10 sub get fcal 10 1 47
239ret false
240end
241if eq get fcbig add fcoff 11 sub get fcal 11 1 47
242ret false
243end
244if ne get fcbig 0 122
245ret false
246end
247if or lt get fcal 0 20 gt get fcal 0 40
248ret false
249end
250if eq get fcbig fcoff 2 45
251ret false
252end
253if or eq get fcal 2 0 gt get fcal 2 64
254ret false
255end
256if or eq get fcal 3 0 gt get fcal 3 120
257ret false
258end
259for k ulong get fcal 3 bound 120
260if eq get fcbig add fcoff 3 k 10
261ret false
262end
263end
264if or eq get fcal 8 0 gt get fcal 8 64
265ret false
266end
267for k ulong get fcal 8 bound 64
268if eq get fcbig add fcoff 8 k 47
269ret false
270end
271end
272if not fctok 5
273ret false
274end
275if not fctok 6
276ret false
277end
278if not fctok 7
279ret false
280end
281if fcexist
282ret false
283end
284ret true
285end
286note fcchild: when fccd is 1 the program runs in DIR, the clone at the receipt's commit
287fn fcchild wfd int to void
288nul = fopen tfdevnul 0 len tfdevnul 2 0
289if lt nul 0
290exit 126
291end
292if eq get fccd 0 1
293fcdpath
294c = chdir fpth 0 get fpthl 0
295if lt c 0
296exit 126
297end
298end
299x = dupfd int nul 0 0
300x = dupfd wfd 1 0
301x = dupfd wfd 2 0
302x = execprog fpk 0 get fpkl 0
303exit 127
304end
305fn fcrun to long
306put fxol 0 0
307put fxotr 0 0
308r = pipefds fpfd 0 8 524288
309if lt r 0
310ret -2
311end
312rfd = fpfdv 0
313wfd = fpfdv 1
314dl = add long monons 60000000000
315pid = fork
316if lt pid 0
317x = fclose rfd
318x = fclose wfd
319ret -2
320end
321if eq pid 0
322fcchild wfd
323exit 127
324end
325x = fclose wfd
326ok = fdrain rfd dl
327x = fclose rfd
328if not ok
329x = killpid int pid 9
330end
331st = freap int pid dl
332if not ok
333ret -1
334end
335ret st
336end
337fn fcenv to void
338fkb
339fka tcenv
340fka tcdash
341fkopen
342fkt tchome
343fcarg 11
344fkopen
345fkt tcpath
346fcarg 11
347fkt tclbin
348fkopen
349fkt tcradh
350fcarg 11
351fkt tcradp
352fka tcg1
353fka tcg2
354fka tcg3
355fka tcg4
356fcpass
357end
358fn fcpenv i ulong to void
359buf = new uchar 80 0
360r = envread i buf 0 80
361if lt r 16
362ret
363end
364for k ulong len tcpass
365if ne get buf k get tcpass k
366ret
367end
368end
369fkopen
370m = ulong r
371for k ulong m bound 80
372fkc get buf k
373end
374end
375fn fcpass to void
376n = envcnt
377if lt n 1
378ret
379end
380u = ulong n
381if gt u 4096
382u = ulong 4096
383end
384i = ulong 0
385while lt i u bound 4096
386fcpenv i
387i = add i 1
388end
389end
390fn fcrad to void
391fkopen
392fcarg 11
393fkt tcradx
394end
395fn fcclone to long
396fcenv
397fcrad
398fka tcclone
399fkopen
400fkt tcradp2
401fcarg 0
402fcnew 1
403ret fcrun
404end
405fn fccopy to long
406put fpthl 0 0
407o = fcoff 1
408for k ulong get fcal 1 bound 320
409fpc get fcbig add o k
410end
411fpc 47
412o = fcoff 8
413for k ulong get fcal 8 bound 64
414fpc get fcbig add o k
415end
416ofd = fopen fpth 0 get fpthl 0 524865 384
417if lt ofd 0
418ret 4
419end
420put fpthl 0 0
421o = fcoff 9
422for k ulong get fcal 9 bound 320
423fpc get fcbig add o k
424end
425inn = fopen fpth 0 get fpthl 0 524288 0
426if lt inn 0
427x = fclose int ofd
428ret 4
429end
430buf = new uchar 4096 0
431left = ulong 65536
432ok = true
433while gt left 0 bound 65536
434k = read int inn buf 0 4096
435if lt k 0
436ok = false
437left = ulong 0
438end
439if eq k 0
440left = ulong 0
441end
442if gt k 0
443w = write int ofd buf 0 ulong k
444if ne w k
445ok = false
446left = ulong 0
447end
448left = sub left ulong k
449end
450end
451x = fsync int ofd
452x = fclose int ofd
453x = fclose int inn
454if not ok
455ret 4
456end
457ret 0
458end
459fn fcbranch to long
460fcenv
461fcgit
462fka tcco
463fka tcb
464fcnew 2
465ret fcrun
466end
467fn fcadd to long
468fcenv
469fcgit
470fka tcadd
471fka tcdd
472fcnew 8
473ret fcrun
474end
475fn fccommit to long
476fcenv
477fcgit
478fka tccfg
479fka tcgp
480fka tccfg
481fka tcun
482fka tccfg
483fka tcum
484fka tccmt
485fka tcm
486fcnew 3
487ret fcrun
488end
489fn fcsha to bool
490if lt get fxol 0 40
491ret false
492end
493for i ulong 40
494if not fchex get fxo i
495ret false
496end
497end
498ret true
499end
500fn fchead to long
501fcenv
502fcgit
503fka tcrp
504fka tchead
505r = fcrun
506if ne r 0
507ret r
508end
509if not fcsha
510ret 5
511end
512for i ulong 40
513put qncm i get fxo i
514end
515fcenv
516fcgit
517fka tcrp
518fka tctree
519r = fcrun
520if ne r 0
521ret r
522end
523if not fcsha
524ret 5
525end
526for i ulong 40
527put qntr i get fxo i
528end
529ret 0
530end
531fn fcevid to long
532fcenv
533fcnew 4
534put fccd 0 1
535r = fcrun
536put fccd 0 0
537put qnrcn 0 0
538if and ge r 0 le r 255
539put qnrcn 0 ulong r
540end
541if lt r 0
542ret 6
543end
544h = new uchar 32 0
545b = new uchar 4096 0
546n = get fxol 0
547if gt n 4096
548n = ulong 4096
549end
550for i ulong n bound 4096
551put b i get fxo i
552end
553k = sha2_digest 256 view part b 0 n h
554for i ulong 32
555v = get h i
556put qnout64 mul i 2 qnhxb shr v 4
557put qnout64 add mul i 2 1 qnhxb and v 15
558end
559o = fcoff 4
560n = get fcal 4
561if gt n 200
562ret 6
563end
564for i ulong n bound 200
565put qncmd i get fcbig add o i
566end
567put qncmdl 0 n
568o = fcoff 6
569n = get fcal 6
570for i ulong n bound 39
571put qnag i get fcbig add o i
572end
573put qnagl 0 n
574if not qnseal
575ret 6
576end
577ret 0
578end
579fn fcid to bool
580n = get fxol 0
581p = ulong 0
582got = false
583while lt p n bound 16777216
584if and le add p 40 n fcis p
585same = true
586for i ulong 40
587if ne get fxo add p i get qncm i
588same = false
589end
590end
591if not same
592for i ulong 40
593put qnid i get fxo add p i
594end
595got = true
596end
597p = add p 40
598end
599if not fcis p
600p = add p 1
601end
602end
603ret got
604end
605fn fcis p ulong to bool
606if gt add p 40 get fxol 0
607ret false
608end
609for i ulong 40
610if not fchex get fxo add p i
611ret false
612end
613end
614if lt add p 40 get fxol 0
615if fchex get fxo add p 40
616ret false
617end
618end
619ret true
620end
621fn fcpush to long
622fcenv
623fcgit
624fka tcpush
625fka tco
626fkopen
627fkt tcpm
628fcarg 3
629fka tcrad
630fka tcref
631r = fcrun
632if ne r 0
633ret 7
634end
635if not fcid
636ret 7
637end
638fcenv
639fcrad
640fka tcped
641fka tcedit
642fkopen
643for i ulong 40
644fkc get qnid i
645end
646fka tcrepo
647fkopen
648fkt tcradp2
649fcarg 0
650fka tcna
651fka tcmsg
652fcnew 3
653fka tcmsg
654fkopen
655for i ulong get qnrcl 0 bound 1024
656fkc get qnrc i
657end
658r = fcrun
659if ne r 0
660ret 7
661end
662ret 0
663end
664fn fcreview to long
665fcenv
666fcrad
667fka tcped
668fka tcrev
669fkopen
670for i ulong 40
671fkc get qnid i
672end
673fka tcrepo
674fkopen
675fkt tcradp2
676fcarg 0
677fka tcna
678fka tcmsg
679fka tcreq
680ret fcrun
681end
682fn fcdata to void
683buf = new uchar 320 0
684o = fcoff 10
685n = get fcal 10
686for i ulong n bound 320
687put buf i get fcbig add o i
688end
689qnsetd buf n
690end
691fn fcdigest to long
692fcdata
693o = fcoff 7
694put qnlinel 0 0
695for i ulong len tcped
696put qnline i get tcped i
697end
698put qnlinel 0 len tcped
699put qnline get qnlinel 0 32
700put qnlinel 0 add get qnlinel 0 1
701o = fcoff 7
702for i ulong get fcal 7 bound 39
703put qnline add get qnlinel 0 i get fcbig add o i
704end
705put qnlinel 0 add get qnlinel 0 get fcal 7
706put qnline get qnlinel 0 32
707put qnlinel 0 add get qnlinel 0 1
708o = fcoff 6
709for i ulong get fcal 6 bound 39
710put qnline add get qnlinel 0 i get fcbig add o i
711end
712put qnlinel 0 add get qnlinel 0 get fcal 6
713put qnline get qnlinel 0 32
714put qnlinel 0 add get qnlinel 0 1
715for i ulong 40
716put qnline add get qnlinel 0 i get qnid i
717end
718put qnlinel 0 add get qnlinel 0 40
719put qnline get qnlinel 0 32
720put qnlinel 0 add get qnlinel 0 1
721for i ulong 40
722put qnline add get qnlinel 0 i get qncm i
723end
724put qnlinel 0 add get qnlinel 0 40
725put qnline get qnlinel 0 10
726put qnlinel 0 add get qnlinel 0 1
727if not qnapp
728ret 9
729end
730if not qnregen
731ret 9
732end
733ret 0
734end
735fn fcprint to void
736k = write 1 tcok1 0 len tcok1
737for i ulong 40
738k = write 1 qnid i 1
739end
740k = write 1 tcnl 0 1
741k = write 1 tcok2 0 len tcok2
742for i ulong 40
743k = write 1 qncm i 1
744end
745k = write 1 tcnl 0 1
746end
747note fcfail: print the failing step's captured output (up to 4096 bytes) on stderr, return its exit code
748fn fcfail code int to int
749k = write 2 tcfail 0 len tcfail
750n = get fxol 0
751if gt n 4096
752n = ulong 4096
753end
754k = write 2 fxo 0 n
755k = write 2 tcnl 0 1
756ret code
757end
758fn main to int
759r = fcload
760if ne r 0
761ret int r
762end
763if not fcvalid
764ret 2
765end
766r = fcclone
767if ne r 0
768ret fcfail 3
769end
770r = fcbranch
771if ne r 0
772ret fcfail 3
773end
774r = fccopy
775if ne r 0
776ret int r
777end
778r = fcadd
779if ne r 0
780ret fcfail 5
781end
782r = fccommit
783if ne r 0
784ret fcfail 5
785end
786r = fchead
787if ne r 0
788ret fcfail int r
789end
790r = fcevid
791if ne r 0
792ret int r
793end
794r = fcpush
795if ne r 0
796ret fcfail int r
797end
798r = fcreview
799if ne r 0
800ret fcfail 8
801end
802r = fcdigest
803if ne r 0
804ret int r
805end
806fcprint
807ret 0
808end