d608636 / repository.mjs
diff --cc repository.mjs
index 0cabe34,93e73db..a3f12ca
--- a/repository.mjs
+++ b/repository.mjs
@@@ -2,10 -2,9 +2,10 @@@ import { execFileSync } from 'node:chil
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import {
- parseJson, persist, readOptional, readRecord, recordPath, recoverBundle,
- requireThat, storeBundle, writeRecord
+ parseJson, persist, readOptional, readRecord, readRecordAuthor, recordPath,
+ recoverBundle, requireThat, storeBundle, writeRecord
} from './storage.mjs'
+import { verifyPushAnnouncement } from './social.mjs'
export const gitEnv = Object.fromEntries(
Object.entries(process.env).filter(([name]) => !name.startsWith('GIT_'))
@@@ -119,10 -120,10 +121,10 @@@ export async function publish(root, ide
const updateId = await writeRecord(root, identity, {
anbot: 1, type: 'git-update', repo: { format: 'anproto', id: repoId },
ref, objectFormat: 'sha1', commit, bundle: { format: 'andfs-v1', id: bundleId },
- previousUpdate: previous?.updateId, push
- previous: previous?.updateId ?? null
++ previous: previous?.updateId ?? null, push
})
const selection = { repoId, ref, updateId }
- await materialize(root, identity, selection, work)
+ await materialize(root, selection, work)
requireThat(!expectedUpdate || readState(root, 'selected.json')?.updateId === expectedUpdate,
'Selected update changed. Fetch and retry.')
const installed = persist(root, 'selected.json', JSON.stringify(selection), Boolean(previous))
@@@ -135,8 -136,8 +137,8 @@@
export async function stageReceive(root, identity, directory) {
const selection = readState(root, 'selected.json')
- const bare = await materialize(root, identity, selection, directory)
+ const bare = await materialize(root, selection, directory)
- const { ref, updateId } = selection
+ const { ref, updateId, repoId } = selection
const before = git(bare, 'rev-parse', ref)
const hooks = join(bare, 'hooks')
mkdirSync(hooks, { recursive: true })
@@@ -166,28 -159,7 +168,29 @@@ don
}
}
- export async function readPushAnnouncements(root, identity) {
++export async function readPushAnnouncements(root) {
+ const { repoId, updateId } = readState(root, 'selected.json')
++ const publisher = await readRecordAuthor(root, repoId)
+ const seen = new Set()
+ const posts = []
- for (let id = updateId; id !== undefined;) {
++ for (let id = updateId; id != null;) {
+ requireThat(!seen.has(id), 'Cyclic Git update history')
+ seen.add(id)
- const update = await readRecord(root, identity.author, id)
++ const update = await readRecord(root, publisher, id)
+ requireThat(update?.type === 'git-update' && update.repo?.id === repoId, 'Invalid Git update history')
+ if (update.push) {
+ const { announcement, count, commits } = update.push
+ const author = announcement.signature.slice(0, 44)
+ const post = await verifyPushAnnouncement(announcement, author, repoId)
+ requireThat(post.ref === update.ref && post.commit === update.commit, 'Mismatched Git announcement')
+ posts.push({ ...post, updateId: id, count, commits })
+ }
- id = update.previousUpdate
++ id = update.previous ?? update.previousUpdate
+ }
+ return posts
+}
+
- export async function selectedRepository(root, identity, verified) {
+ export async function selectedRepository(root, verified) {
const selection = readState(root, 'selected.json')
requireThat(selection, 'Publish a repository before serving it')
const { repoId, updateId } = selection
Git ยท Social feed