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
omega-mv / apps / interplane-forge / collab / co6route.om
| 1 | note collab/co6route.om (ForgePatches): coroute, the collab entry point. Returns 0 when the path is not ours. |
| 2 | note /<o>/<r>/patches[?state=] and /pulls (alias) list patches; /patches/<id> one patch; /patches/<id>.diff |
| 3 | note (POST, compose/<cid> and issues|patches/new: Phase A, collab/co9form.om) |
| 4 | note the raw diff; /pulls/<id> and /pull/<id> redirect (302) to /patches/<id>; /issues and /issues/<id>. |
| 5 | note <id> is 4..40 lowercase hex, a prefix of exactly one COB id of this repo; anything else is 404. |
| 6 | text tcpulls "/pulls" |
| 7 | text tcpull "/pull" |
| 8 | text tccompr "/compose" |
| 9 | text tcnwr "new" |
| 10 | global gcoff ulong 1 |
| 11 | fn coroute to long |
| 12 | if ge get fridx 0 get fan 0 |
| 13 | ret 0 |
| 14 | end |
| 15 | k = cosect |
| 16 | if eq k 0 |
| 17 | ret 0 |
| 18 | end |
| 19 | m = get fmeth 0 |
| 20 | if eq m 3 |
| 21 | ret copost k |
| 22 | end |
| 23 | if or eq m 1 eq m 2 |
| 24 | ret codisp k |
| 25 | end |
| 26 | ret 405 |
| 27 | end |
| 28 | note cosegis t: frest starts with the segment t, followed by its end or a slash |
| 29 | fn cosegis t view uchar * to bool |
| 30 | if eq frstpre t false |
| 31 | ret false |
| 32 | end |
| 33 | n = len t |
| 34 | if eq n get frestl 0 |
| 35 | ret true |
| 36 | end |
| 37 | ret eq get frest n 47 |
| 38 | end |
| 39 | note cosect: 1 /patches 2 /issues 3 /pulls 4 /pull, with the segment length in gcoff; 0 not ours |
| 40 | fn cosect to ulong |
| 41 | if cosegis tcpats |
| 42 | put gcoff 0 len tcpats |
| 43 | ret ulong 1 |
| 44 | end |
| 45 | if cosegis tcisss |
| 46 | put gcoff 0 len tcisss |
| 47 | ret ulong 2 |
| 48 | end |
| 49 | if cosegis tcpulls |
| 50 | put gcoff 0 len tcpulls |
| 51 | ret ulong 3 |
| 52 | end |
| 53 | if cosegis tcpull |
| 54 | put gcoff 0 len tcpull |
| 55 | ret ulong 4 |
| 56 | end |
| 57 | if cosegis tccompr |
| 58 | put gcoff 0 len tccompr |
| 59 | ret ulong 5 |
| 60 | end |
| 61 | ret ulong 0 |
| 62 | end |
| 63 | fn codisp k ulong to long |
| 64 | o = get gcoff 0 |
| 65 | n = get frestl 0 |
| 66 | if or eq o n eq add o 1 n |
| 67 | if eq k 4 |
| 68 | ret 404 |
| 69 | end |
| 70 | if eq k 2 |
| 71 | ret colistx 2 |
| 72 | end |
| 73 | ret colistx 1 |
| 74 | end |
| 75 | if eq k 5 |
| 76 | ret cocget |
| 77 | end |
| 78 | a = add o 1 |
| 79 | if and le k 2 coseqat a n tcnwr |
| 80 | if eq k 2 |
| 81 | ret conewpg 4 |
| 82 | end |
| 83 | ret conewpg 5 |
| 84 | end |
| 85 | if eq k 2 |
| 86 | if cocpid a n |
| 87 | ret coissx |
| 88 | end |
| 89 | ret 404 |
| 90 | end |
| 91 | if eq k 1 |
| 92 | ret codispp a n |
| 93 | end |
| 94 | if cocpid a n |
| 95 | ret copulls |
| 96 | end |
| 97 | ret 404 |
| 98 | end |
| 99 | note colistx kd, copatx, coissx: the JSON form (collab/coJjson.om) when the request asks for it, else |
| 100 | note the HTML page, which names its own URL as the JSON alternate (fyalt) |
| 101 | fn colistx kd ulong to long |
| 102 | if fjwant |
| 103 | ret cojlist kd |
| 104 | end |
| 105 | fyalt |
| 106 | ret colist kd |
| 107 | end |
| 108 | fn copatx to long |
| 109 | if fjwant |
| 110 | ret cojpat |
| 111 | end |
| 112 | fyalt |
| 113 | ret copatpg |
| 114 | end |
| 115 | fn coissx to long |
| 116 | if fjwant |
| 117 | ret cojiss |
| 118 | end |
| 119 | fyalt |
| 120 | ret coisspg |
| 121 | end |
| 122 | fn codispp a ulong n ulong to long |
| 123 | if qnends a n |
| 124 | if cocpid a sub n 8 |
| 125 | ret qnraw |
| 126 | end |
| 127 | ret 404 |
| 128 | end |
| 129 | if gt n add a len tcdsuf |
| 130 | if codsuf n |
| 131 | if cocpid a sub n len tcdsuf |
| 132 | ret copraw |
| 133 | end |
| 134 | ret 404 |
| 135 | end |
| 136 | end |
| 137 | if cocpid a n |
| 138 | ret copatx |
| 139 | end |
| 140 | ret 404 |
| 141 | end |
| 142 | fn codsuf n ulong to bool |
| 143 | s = sub n len tcdsuf |
| 144 | for i ulong len tcdsuf |
| 145 | if ne get frest add s i get tcdsuf i |
| 146 | ret false |
| 147 | end |
| 148 | end |
| 149 | ret true |
| 150 | end |
| 151 | note cocpid a b: frest[a,b) is 4..40 lowercase hex; copied into gcrq |
| 152 | fn cocpid a ulong b ulong to bool |
| 153 | if le b a |
| 154 | ret false |
| 155 | end |
| 156 | n = sub b a |
| 157 | if or lt n 4 gt n 40 |
| 158 | ret false |
| 159 | end |
| 160 | for i ulong n |
| 161 | if eq cohexc get frest add a i false |
| 162 | ret false |
| 163 | end |
| 164 | end |
| 165 | for i ulong n |
| 166 | put gcrq i get frest add a i |
| 167 | end |
| 168 | put gcrql 0 n |
| 169 | ret true |
| 170 | end |
| 171 | note copulls: /pulls/<id> and /pull/<id> name the same page as /patches/<id> |
| 172 | fn copulls to long |
| 173 | put fkind 0 2 |
| 174 | flocrepo |
| 175 | floct tcpatp |
| 176 | for i ulong get gcrql 0 bound 40 |
| 177 | flocc get gcrq i |
| 178 | end |
| 179 | ret 302 |
| 180 | end |