gitoria
All repositories: gitoria
4.1 KB
// lib/git.hl — GIT ON THE SERVER: where the bare repositories live and how git is called. Each repo is one BARE git// repository, <gitRoot>/<slug>.git (created with the repo: repos.hl createRepo → initRepo). Reads go through the// `git` binary with hl:proc (docs/git-backend.md): an argv list, never a shell, the slug is// validated by the caller (repos-helpers.hl slugError), a path only ever comes from git itself.// Every read calls git with hl:proc run() (hybriel#80: it waits), so the readers answer through their callback// before they return; the page components use the `...Now` forms at construction (server-rendered, gitoria#16).// What is read: the homepage (homepage.hl), the code browser (code.hl), pull requests (pulls.hl), releases (releases.hl).import { run, env, cwd } from 'hl:proc'import { exists, mkDir } from 'hl:fs'import { safeName } from './git-helpers.hl'// where the bare repositories live: GITORIA_GIT, else ./storage/git under the launch directorystatic gitRoot = env('GITORIA_GIT') != null && env('GITORIA_GIT') != '' ? env('GITORIA_GIT') : cwd() + '/storage/git'static repoDir = (slug) => { return gitRoot + '/' + slug + '.git' }static maxTree = 20000 // paths looked atstatic seconds = 15 // one git call// one git call: argv (after `git --git-dir=<dir>`), `done({ ok, lines })` exactly once — BEFORE git() returns:// hl:proc run() waits for the program (hybriel#80), so a page's root can read git while it is built on the server// and the callback style of the readers is synchronous. Past `seconds` git is killed; run() is then an Error// (absorbed by project.hl `on Error`) and yields null → ok = false.static git = (slug, rest, limit, done) => {argv = ['git', '--git-dir=' + repoDir(slug), '-c', 'core.quotePath=false']for (a of rest) { argv.push(a) }r = run(argv, { timeout = seconds })let lines = []if (r != null) {for (l of r.lines) { if (lines.length < limit) { lines.push(l) } }}done({ ok = r != null && r.exit == 0 lines = lines })return null}// one git call answered directly: run()'s result ({ exit, lines }) or nullstatic gitRaw = (slug, rest) => {argv = ['git', '--git-dir=' + repoDir(slug), '-c', 'core.quotePath=false']for (a of rest) { argv.push(a) }return run(argv, { timeout = seconds })}// the branch names of a repo → done([name])static branchNames = (slug, done) => {git(slug, ['for-each-ref', '--format=%(refname:short)', 'refs/heads'], 500, (r) => {out = []if (r.ok) { for (l of r.lines) { if (safeName(l)) { out.push(l) } } }done(out)return null})}// which branch is "main" for a repo: the setting if it exists, else `main`, else the first one; null = no branchstatic pickDefault = (names, setting) => {if (setting != null && setting != '' && names.includes(setting)) { return setting }if (names.includes('main')) { return 'main' }return names.length > 0 ? names[0] : null}static defaultBranch = (slug, setting, done) => {branchNames(slug, (names) => {done(pickDefault(names, setting))return null})}// a new empty bare repository for a repo (a failure is not fatal: a repo without one just has no files)static initRepo = (slug) => {i = slug.indexOf('/')if (i > 0 && !exists(gitRoot + '/' + slug.slice(0, i))) { mkDir(gitRoot + '/' + slug.slice(0, i), 493) }r = run(['git', 'init', '--bare', '-q', '-b', 'main', repoDir(slug)], { timeout = seconds })// refs/pull/* is gitoria's (pullsync.hl): a push to it is refused (HTTPS also says it per call, transport.hl)run(['git', '--git-dir=' + repoDir(slug), 'config', 'receive.hideRefs', 'refs/pull'], { timeout = seconds })return r}// does the repo have no branch yet (nothing pushed)? — the "how to add code" box opens itself then (gitoria#7)static isEmptyNow = (slug) => {let empty = truegit(slug, ['for-each-ref', '--count=1', 'refs/heads'], 1, (r) => {empty = !r.ok || r.lines.length == 0return null})return empty}// the folder for temp files beside the repositories (the push / fetch bodies of transport.hl, a key for ssh-keygen in sshkeys.hl)static tmpDir = () => {d = gitRoot + '/.tmp'if (!exists(d)) { mkDir(d, 448) }return d}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- b9137ff0gitoria#40: pull requests are stored with a number, refs/pull/N/head, syncPulls and pullObject; /pulls shows #Nmre
- 06d622daown image tag gitoria-runtime:debian12 for gitoria and standby (shared tag lost git)mre
- 20caa33agitoria#37: media queries in the language's @media block (minWidth = '60rem') in list, codebrowser and repomre
- c4175e6dgitoria: a startup error prints its message before exit 1 (hybriel#247)mre
- c50d17efKeep function-route not-found style in shared stylesheetmre
- e42d78d3Preserve ticket state CSS and document function-route style gapmre
- c6b7154eWIP gitoria#26: move styles into nested component blocksmre
- 77a2c31cgitoria#31: plain declarations instead of needless let in lib/ and tools/ (103 let removed, 137 kept because reassigned); no other changemre
- 4b98ab62gitoria: an ident access key (idt_) works as the git password; read key clones only, bad key 401, ident down 503 (ident#27); gate tests/ident-access-gitoria.mjs in deploy.shmre
- 1185f686gitoria#36: a failed return from tickets shows a note on the settings page and leaves one log line per outcome; no code is exchangedmre
- 5d2c385agitoria: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 71+5 failing → 76 passed; deploy.sh runs tests/private.mjs toomre
- 241ef3f9deploy.sh: rebuild the sshd image before up -d (GO34c)mre
- 821cdbb1gitoria#34b: styles, create-repo tool, docs, push/ssh gates sign in through the selector, shots scriptmre
- a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre
- 17f031f0gitoria#34: private repos, organizations, members, move tool, gatemre
- 71b69343gitoria#23: the sidebar's Repositories link was a 404 after any in-page navigation (static menu re-evaluated publicUrl in the browser); the menu is an instance property now; gate taps it after a tab, folder, filemre
- 90b4f728gitoria#25: restore the homepage cache and the parsed-blocks cache (they store data under immutable keys, no HTML); the page key, the framework readme key and the textHash key stay removedmre
- a487248cgitoria#25: remove every cache that hid the page build (page key, Markdown render key, homepage cache, parsed-blocks cache) and the gate that only tested themmre
- 12f2f4fegitoria: re-vendor Hybriel set-day27b, a startup fault in on Error exits 1mre
- c21c084egitoria: write the standby service out in full so the boot gate can read the main servicemre