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
- e5385075Expect 401 for POST /api/repos without a tokenmre
- 1a76055cDocument repository creation APImre
- 4d779b3bAdd create-api gatemre
- 88563122Add POST /api/repos for user tokensmre
- b00860e3Create repositories with member checks in createRepoInmre
- 0a38f236Report repository creation API blockermre
- b5f72187Record malformed JSON blocker for repository creationmre
- a2ae8302logmre
- 6947cd58logmre
- 2175e48clogmre
- 40eb3ca1gitoria#38: review package, logmre
- 06a5a50egitoria#38: deploy b8252ca, logmre
- b8252ca0gitoria#46: W46b report, logmre
- 50093aafgitoria#46: statuses keyed by app + context (merge w46b-keyed)mre
- dd0267edgitoria#46: fix a label in the keyed gatemre
- b1dcb580gitoria#46: statuses keyed by app + context, required = app + context, old rows still readmre
- 2287363egitoria#47: W47 report, logmre
- 9f502db1gitoria#46: W46b briefmre
- 9678a8f3gitoria#46: contract v1.4, statuses keyed by app + contextmre
- bdcbbaa9gitoria#47: rate limits, status read route, statuses + required on the pull (merge w47-limits)mre