gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit81f0a0bb81f0a0bbREADME: two caches were restored by 90b4f72; log W62mre81f0a0bb/lib/git.hl

4.0 KB

  1. // lib/git.hl — GIT ON THE SERVER: where the bare repositories live and how git is called. Each repo is one BARE git
  2. // repository, <gitRoot>/<slug>.git (created with the repo: repos.hl createRepo → initRepo). Reads go through the
  3. // `git` binary with hl:proc (docs/git-backend.md): an argv list, never a shell, the slug is
  4. // validated by the caller (repos-helpers.hl slugError), a path only ever comes from git itself.
  5. // Every read calls git with hl:proc run() (hybriel#80: it waits), so the readers answer through their callback
  6. // before they return; the page components use the `...Now` forms at construction (server-rendered, gitoria#16).
  7. // What is read: the homepage (homepage.hl), the code browser (code.hl), pull requests (pulls.hl), releases (releases.hl).
  8. import { run, cwd } from 'hl:proc'
  9. import { exists, mkDir } from 'hl:fs'
  10. import { envOr } from './util.hl'
  11. import { safeName } from './git-helpers.hl'
  12. // where the bare repositories live: GITORIA_GIT, else ./storage/git under the launch directory
  13. static gitRoot = envOr('GITORIA_GIT', cwd() + '/storage/git', false)
  14. static repoDir = (slug) => { return gitRoot + '/' + slug + '.git' }
  15. static maxTree = 20000 // paths looked at
  16. static seconds = 15 // one git call
  17. // one git call: argv (after `git --git-dir=<dir>`), `done({ ok, lines })` exactly once — BEFORE git() returns:
  18. // hl:proc run() waits for the program (hybriel#80), so a page's root can read git while it is built on the server
  19. // and the callback style of the readers is synchronous. Past `seconds` git is killed; run() is then an Error
  20. // (absorbed by project.hl `on Error`) and yields null → ok = false.
  21. static git = (slug, rest, limit, done) => {
  22. argv = ['git', '--git-dir=' + repoDir(slug), '-c', 'core.quotePath=false']
  23. for (a of rest) { argv.push(a) }
  24. r = run(argv, { timeout = seconds })
  25. let lines = []
  26. if (r != null) {
  27. for (l of r.lines) { if (lines.length < limit) { lines.push(l) } }
  28. }
  29. done({ ok = r != null && r.exit == 0 lines = lines })
  30. return null
  31. }
  32. // one git call answered directly: run()'s result ({ exit, lines }) or null
  33. static gitRaw = (slug, rest) => {
  34. argv = ['git', '--git-dir=' + repoDir(slug), '-c', 'core.quotePath=false']
  35. for (a of rest) { argv.push(a) }
  36. return run(argv, { timeout = seconds })
  37. }
  38. // the branch names of a repo → done([name])
  39. static branchNames = (slug, done) => {
  40. git(slug, ['for-each-ref', '--format=%(refname:short)', 'refs/heads'], 500, (r) => {
  41. out = []
  42. if (r.ok) { for (l of r.lines) { if (safeName(l)) { out.push(l) } } }
  43. done(out)
  44. return null
  45. })
  46. }
  47. // which branch is "main" for a repo: the setting if it exists, else `main`, else the first one; null = no branch
  48. static pickDefault = (names, setting) => {
  49. if (setting != null && setting != '' && names.includes(setting)) { return setting }
  50. if (names.includes('main')) { return 'main' }
  51. return names.length > 0 ? names[0] : null
  52. }
  53. static defaultBranch = (slug, setting, done) => {
  54. branchNames(slug, (names) => {
  55. done(pickDefault(names, setting))
  56. return null
  57. })
  58. }
  59. // a new empty bare repository for a repo (a failure is not fatal: a repo without one just has no files)
  60. static initRepo = (slug) => {
  61. i = slug.indexOf('/')
  62. if (i > 0 && !exists(gitRoot + '/' + slug.slice(0, i))) { mkDir(gitRoot + '/' + slug.slice(0, i), 493) }
  63. r = run(['git', 'init', '--bare', '-q', '-b', 'main', repoDir(slug)], { timeout = seconds })
  64. // refs/pull/* is gitoria's (pullsync.hl): a push to it is refused (HTTPS also says it per call, transport.hl)
  65. run(['git', '--git-dir=' + repoDir(slug), 'config', 'receive.hideRefs', 'refs/pull'], { timeout = seconds })
  66. return r
  67. }
  68. // does the repo have no branch yet (nothing pushed)? — the "how to add code" box opens itself then (gitoria#7)
  69. static isEmptyNow = (slug) => {
  70. let empty = true
  71. git(slug, ['for-each-ref', '--count=1', 'refs/heads'], 1, (r) => {
  72. empty = !r.ok || r.lines.length == 0
  73. return null
  74. })
  75. return empty
  76. }
  77. // the folder for temp files beside the repositories (the push / fetch bodies of transport.hl, a key for ssh-keygen in sshkeys.hl)
  78. static tmpDir = () => {
  79. d = gitRoot + '/.tmp'
  80. if (!exists(d)) { mkDir(d, 448) }
  81. return d
  82. }

Branches

Latest commits

  • 81f0a0bbREADME: two caches were restored by 90b4f72; log W62mre
  • ab12a257Merge W62: #25 commit page measurements and proc repromre
  • 41323e49gitoria#25: measure commit request costs and reproduce blocking process waitsmre
  • 53ca42b2log: W60 merged, W61 W62 startedmre
  • 80870a33mission W61: style passmre
  • 560fd208Merge W60: helpers, bound forms, login in topics, two form fixes (gitoria#28 #32 #33)mre
  • ac5ba6a4log: W60, #25 measuredmre
  • 220f6342W60: record corrected form proof, full AE and remaining gapsmre
  • 7e31cac5gitoria#28: restrict reply form layout to reply formsmre
  • ae373cfdgitoria#28: keep each reply draft in its thread componentmre
  • eeeebd5agitoria: insert a newly created organization oncemre
  • 34d2d5cagitoria: clear the bound public-key textarea after creationmre
  • 119e54c0W60: restore conductor-owned tracking filesmre
  • 24b479e7W60: record final gates, Chrome failures and AE evidencemre
  • 5e11184cW60: record partial validation, framework gaps and cleanupmre
  • 20fe13fagitoria#33: centralize login and tickets connection statemre
  • 859754c0gitoria#29: retain the offline note and record the framework gapmre
  • d140bc04gitoria#30: reproduce the upsert ordering constraintmre
  • 6960e8f8gitoria#28: keep form values in bound component membersmre
  • 0db27200gitoria#32: share character checks and environment lookupmre