gitoria
All repositories: gitoria
4.0 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' }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
- bf568e14log: V48 mergedmre
- 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
- f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
- 5d0834e7log: Apollo model rulemre
- fe8e5bd5log: #25 sample, V48 missionmre
- 8580c5d9log: theme fix from Atlasmre
- 46823d93log: Apollo budget correctionmre
- f6d32341log: Apollo on budget and #25 nextmre
- d7184f53log: batch live, #25 evidencemre
- 5e25e816log: W61 mergedmre
- aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
- aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
- 03cb650blog: W61 theme decisionmre
- 248bce85Report final style gates, CSS mappings and 136 whole-image comparisonsmre
- 153c344bRestore organization metadata exposed by the whole-image comparisonmre
- 917a1465Update status gate assertions for the referenced state rulemre
- 3cdb02c6Own settings feedback styles and explain connection-state classesmre
- 00d5d6c4Reference code-entry styles and nest code-browser media and pseudosmre
- 3c425eddReference PR content styles and explain dynamic state classesmre
- e46fa222Own shell feedback styles and retain documented selector formsmre