gitoria
All repositories: gitoria
4.2 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, cwd } from 'hl:proc'import { exists, mkDir } from 'hl:fs'import { envOr } from './util.hl'import { safeName } from './git-helpers.hl'// where the bare repositories live: GITORIA_GIT, else ./storage/git under the launch directorystatic gitRoot = envOr('GITORIA_GIT', cwd() + '/storage/git', false)static repoDir = (slug) => { return gitRoot + '/' + slug + '.git' }// the hooks folder of receive-pack (docker/sshd/hooks: pre-receive refuses a direct push to the protected branch, gitoria#50); the app runs in its own folderstatic hooksDir = cwd() + '/docker/sshd/hooks'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
Latest commits
- 01b71c2edocs: neutral wording in missions, reports and logmre
- 3eeea733log: 2026-11-09 PR flow plan and membersmre
- e7c2ff1fdocs: neutral name for the apps-api reviewmre
- 120b7abdlog: step 3 queuedmre
- 358474bflog: P50 livemre
- 477d7bdcMerge branch 'p50'mre
- 00efc06fP50 reportmre
- e3f85afblog: commit mention slipmre
- 4d1a4cf4log: #25 numbersmre
- 1af0a60ddocs: H25 run() correctionmre
- eefa2dbcRepo setting: refuse direct pushes to the main branch (pre-receive over HTTPS and ssh)mre
- 8c8ba2f1log: PR flow announcedmre
- fa00cd35log: Kunibert pings provenmre
- 3a68cfaclog: components decisionmre
- 87de8e31log: Kunibert connected to 9 app reposmre
- c22aff69log: PR-only rollout startedmre
- 25309981log: STOP and paused workers 2026-11-08mre
- 5286803alog: worker briefs and reports of 2026-11-08mre
- 85c86605log: 2026-11-08 Arachne on list shapemre
- cb634512log: 2026-11-08 keyed lists livemre