@ref0/git 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/access/private-refs.mjs +5 -4
  2. package/dist/contracts/forks.d.mts +3 -2
  3. package/dist/contracts/git.d.mts +23 -5
  4. package/dist/contracts/result.d.mts +7 -5
  5. package/dist/contracts/result.mjs +7 -5
  6. package/dist/contracts/sync.d.mts +11 -0
  7. package/dist/core/access.d.mts +1 -0
  8. package/dist/core/access.mjs +10 -11
  9. package/dist/core/asked.mjs +30 -0
  10. package/dist/core/events/deliver.d.mts +1 -0
  11. package/dist/core/events/deliver.mjs +5 -1
  12. package/dist/core/forks.mjs +39 -13
  13. package/dist/core/imports.mjs +9 -4
  14. package/dist/core/objects/reading.mjs +17 -9
  15. package/dist/core/parts.d.mts +2 -1
  16. package/dist/core/push.mjs +11 -8
  17. package/dist/core/refs.mjs +6 -3
  18. package/dist/core/registered-rows.d.mts +1 -0
  19. package/dist/core/registered-rows.mjs +7 -5
  20. package/dist/core/repack.mjs +5 -3
  21. package/dist/core/saved-caller-views.d.mts +18 -0
  22. package/dist/core/saved-caller-views.mjs +17 -4
  23. package/dist/core/saved-callers-public.d.mts +3 -3
  24. package/dist/core/saved-callers-public.mjs +3 -2
  25. package/dist/core/saved-callers.d.mts +7 -0
  26. package/dist/extend.d.mts +2 -1
  27. package/dist/extend.mjs +2 -1
  28. package/dist/http/push-uploads.mjs +6 -3
  29. package/dist/lfs/locks.mjs +14 -9
  30. package/dist/lfs/objects.mjs +27 -20
  31. package/dist/queue/calls.mjs +21 -1
  32. package/dist/rest/blobs.d.mts +15 -15
  33. package/dist/rest/commits.d.mts +191 -191
  34. package/dist/rest/files.d.mts +70 -70
  35. package/dist/rest/forks.d.mts +72 -72
  36. package/dist/rest/layer.mjs +8 -1
  37. package/dist/rest/queue.d.mts +212 -212
  38. package/dist/rest/refs.d.mts +148 -148
  39. package/dist/rest/repos.d.mts +47 -47
  40. package/dist/rest/tags.d.mts +76 -76
  41. package/dist/rest/tokens.d.mts +101 -101
  42. package/dist/rest/topics.d.mts +112 -112
  43. package/dist/rest/trees.d.mts +73 -73
  44. package/dist/rest/work.d.mts +39 -39
  45. package/dist/server/git-namespace.d.mts +3 -3
  46. package/dist/server/server.mjs +6 -4
  47. package/dist/storage/memory-budget.mjs +128 -6
  48. package/dist/storage/merge-cut.mjs +5 -4
  49. package/dist/storage/pack-reads.mjs +239 -27
  50. package/dist/storage/prune-seen.mjs +11 -6
  51. package/dist/storage/prune-walk.mjs +168 -68
  52. package/dist/storage/quarantine.mjs +2 -0
  53. package/dist/store/repo-record.d.mts +25 -0
  54. package/dist/store/repo-record.mjs +55 -1
  55. package/dist/sync/github.mjs +10 -1
  56. package/dist/sync/import.mjs +3 -2
  57. package/dist/sync/mirror.mjs +24 -17
  58. package/dist/sync/said.mjs +204 -0
  59. package/dist/sync/step.mjs +8 -8
  60. package/dist/sync/tries.mjs +34 -18
  61. package/dist/topics/advance.mjs +10 -3
  62. package/package.json +3 -3
@@ -135,10 +135,11 @@ const wholeView = (all) => ({
135
135
  * Until private branches are whole, it hides less than its name says:
136
136
  * - **Objects by ID:** an object no ref the caller sees reaches answers as one the repo lacks,
137
137
  * on every surface that takes an ID, and so does a Git LFS object none points at.
138
- * - **Jobs:** the server's jobs and host calls read every ref, so a pull request, a webhook
139
- * payload or an import can copy a hidden ref's name or commits where its readers see them,
140
- * until piece 3. A fork copies only the refs its caller sees, and a mirror's every try asks the
141
- * caller who saved it again, pausing `unseen` once they no longer see its ref.
138
+ * - **Host calls:** they read every ref, so a host's job that copies a ref's name or commits for
139
+ * someone asks their view itself, through `SavedCallers`. The server's own jobs do: a mirror,
140
+ * an import and the queue's publish each ask the caller who saved them again on every try, and
141
+ * a mirror pauses `unseen` once they no longer see its ref. A fork copies only the refs its
142
+ * caller sees.
142
143
  * - **Name conflicts:** a write may not create a ref a hidden one would conflict with, whatever
143
144
  * the repo holds, such as `private` beside `private/**`.
144
145
  *
@@ -41,8 +41,9 @@ export declare const ForkFetched: Schema.Struct<{
41
41
  }>;
42
42
  export type ForkFetched = typeof ForkFetched.Type;
43
43
  /**
44
- * A fork is a complete repo of its own, made from what its source lists when it's made: every ref,
45
- * and the source's packs, shared without copying a byte. Later pushes to either reach only the
44
+ * A fork is a complete repo of its own, made from what its source lists when it's made: every ref
45
+ * but those under a prefix a registration publishes, such as `refs/pull/`, which the host writes
46
+ * from rows the fork doesn't copy, and the source's packs, shared without copying a byte. Later pushes to either reach only the
46
47
  * repo they're sent to, and deleting either leaves the other whole.
47
48
  */
48
49
  export interface ForkCalls {
@@ -127,28 +127,46 @@ export interface RegisteredWrites {
127
127
  /** When the repo's upkeep runs next, in `git.repack`: the registration's upkeep steps then. */
128
128
  readonly wake?: Moment;
129
129
  }
130
+ /**
131
+ * A repo as `authorize` was asked of it: the name asked, and the name and visibility its record held
132
+ * when the open read it. A read given one holds the repo to it, as the open's confirm would have.
133
+ */
134
+ export interface AskedRepo {
135
+ readonly name: RepoName;
136
+ readonly record: {
137
+ readonly name: RepoName;
138
+ readonly public: boolean;
139
+ };
140
+ }
130
141
  /**
131
142
  * A registration's rows in each repo's scope: collections under `<registration name>/`, and nothing else. A read
132
143
  * or a write of another collection, the repo's own record, refs, objects or another registration's, is a
133
144
  * defect.
134
145
  */
135
146
  export interface RegisteredRows {
136
- /** `reads` at one version of `repo`'s scope. */
137
- readonly read: (repo: InternalRepoId, reads: readonly Read[]) => Effect.Effect<RegisteredSnapshot, GitError>;
147
+ /**
148
+ * `reads` at one version of `repo`'s scope. With `asked`, the repo's record is read with them and
149
+ * held to it: a repo deleted, renamed or made public or private since it opened is `NOT_FOUND`.
150
+ */
151
+ readonly read: (repo: InternalRepoId, reads: readonly Read[], asked?: AskedRepo) => Effect.Effect<RegisteredSnapshot, GitError>;
138
152
  /**
139
153
  * `reads` for `caller`'s write to `repo`, read with its record and the caller's grant fence at
140
154
  * one version, so a commit at that version fails once the repo's deleted or the grant revoked.
141
- * A deleted repo is `NOT_FOUND`, and a revoked grant the fence's refusal.
155
+ * A deleted repo is `NOT_FOUND`, and a revoked grant the fence's refusal. With `asked`, the record
156
+ * is held to it too, as `read` says.
142
157
  */
143
158
  readonly readFenced: (caller: Caller, repo: {
144
159
  readonly internalId: InternalRepoId;
145
160
  readonly name: RepoName;
146
- }, reads: readonly Read[]) => Effect.Effect<RegisteredSnapshot, GitError>;
161
+ }, reads: readonly Read[], asked?: AskedRepo) => Effect.Effect<RegisteredSnapshot, GitError>;
147
162
  /** The repo `repo` was forked from, by its record, while it's kept: `undefined` for none. */
148
163
  readonly source: (repo: InternalRepoId) => Effect.Effect<InternalRepoId | undefined, GitError>;
149
164
  /** One commit at `at`, a version read: one since moved it fails, `ok: false`. */
150
165
  readonly commit: (repo: InternalRepoId, at: number, writes: RegisteredWrites) => Effect.Effect<Committed, GitError>;
151
- /** Rows at keys none holds, outside the version: a key held fails `ALREADY_EXISTS`. */
166
+ /**
167
+ * Rows at keys none holds, outside the version: a key held fails `ALREADY_EXISTS`, and a repo
168
+ * with no record, or a deleted one, `NOT_FOUND`, so an add never makes a purged scope again.
169
+ */
152
170
  readonly add: (repo: InternalRepoId, writes: Omit<RegisteredWrites, 'delete'>) => Effect.Effect<void, GitError>;
153
171
  }
154
172
  /** What a route's handler is given: the request, and the path's `:name` parts, decoded. */
@@ -98,11 +98,13 @@ export type PreconditionContext = typeof PreconditionContext.Type;
98
98
  * add or hold may fit once one leaves. `queue-targets-full` is a write onto a new target once the
99
99
  * repo's queues hold as many targets as they may, which no leave mends: queue onto one it holds.
100
100
  *
101
- * `prune-walk-too-large` is upkeep's prune pass, refused at one of two bounds its message names:
102
- * - its walk's charge past the step's allotment, its packs' indexes whole beside its seen set of a
103
- * bit an object: past about 1,600,000 objects in packs under 2 GiB at the default memory. Raise
104
- * `packs()`' `memory` past its default of 128,000,000 bytes, on a host with the room, such as
105
- * Node; a Worker's isolate has no more;
101
+ * `prune-walk-too-large` is upkeep's prune pass, refused at one of the bounds its message names:
102
+ * - its walk's charge past the step's allotment, its seen set of a bit an object beside a fixed
103
+ * room for its packs' indexes, `pruneIndexFloor`'s 32 MiB: past about 141,500,000 objects at
104
+ * the default memory. Raise `packs()`' `memory` past its default of 128,000,000 bytes, on a
105
+ * host with the room, such as Node; a Worker's isolate has no more;
106
+ * - a listed pack whose index alone passes that room, past about 1,048,000 objects: a push's,
107
+ * since a merge cuts each pack it writes to fit;
106
108
  * - one step of the walk past a try's calls: raise the adapter's `callLimits`, on Cloudflare its
107
109
  * `subrequests` up to the Worker's own `limits.subrequests`, and `packs()`' `callLimits` where
108
110
  * it sets lower ones.
@@ -179,11 +179,13 @@ const PreconditionContext = contextOf({
179
179
  * add or hold may fit once one leaves. `queue-targets-full` is a write onto a new target once the
180
180
  * repo's queues hold as many targets as they may, which no leave mends: queue onto one it holds.
181
181
  *
182
- * `prune-walk-too-large` is upkeep's prune pass, refused at one of two bounds its message names:
183
- * - its walk's charge past the step's allotment, its packs' indexes whole beside its seen set of a
184
- * bit an object: past about 1,600,000 objects in packs under 2 GiB at the default memory. Raise
185
- * `packs()`' `memory` past its default of 128,000,000 bytes, on a host with the room, such as
186
- * Node; a Worker's isolate has no more;
182
+ * `prune-walk-too-large` is upkeep's prune pass, refused at one of the bounds its message names:
183
+ * - its walk's charge past the step's allotment, its seen set of a bit an object beside a fixed
184
+ * room for its packs' indexes, `pruneIndexFloor`'s 32 MiB: past about 141,500,000 objects at
185
+ * the default memory. Raise `packs()`' `memory` past its default of 128,000,000 bytes, on a
186
+ * host with the room, such as Node; a Worker's isolate has no more;
187
+ * - a listed pack whose index alone passes that room, past about 1,048,000 objects: a push's,
188
+ * since a merge cuts each pack it writes to fit;
187
189
  * - one step of the walk past a try's calls: raise the adapter's `callLimits`, on Cloudflare its
188
190
  * `subrequests` up to the Worker's own `limits.subrequests`, and `packs()`' `callLimits` where
189
191
  * it sets lower ones.
@@ -40,6 +40,17 @@ export type SyncTrigger = typeof SyncTrigger.Type;
40
40
  export interface SyncProvider {
41
41
  readonly name: string;
42
42
  readonly remote: (repo: string, access: 'read' | 'write', signal?: AbortSignal) => Promise<SyncRemote>;
43
+ /**
44
+ * The top-level string fields of its remote's JSON refusal, status 400 or more, that a sync
45
+ * error may keep, such as `['message']`: each one the remote never fills with the request's
46
+ * credential. Their text is kept in the error's message as one line of at most 256 UTF-16
47
+ * units, every credential-shaped string redacted first: the request's own credential and its
48
+ * parts as they are, JSON-escaped, in base64 and in any percent-encoding's spelling, then token
49
+ * prefixes, authorization values, URL userinfo and any run of 32 or more base64 or hex
50
+ * characters, a commit's ID too. The rest of the body, `ERR` lines and fatal bands are dropped,
51
+ * as they are with none. A body is read only until the try stops.
52
+ */
53
+ readonly keptFields?: readonly string[];
43
54
  /**
44
55
  * Checks a webhook's request: the push it signed, `undefined` for a request the remote didn't
45
56
  * send or no push, and `RESOURCE_EXHAUSTED` for a body longer than the remote sends. It reads the
@@ -1,5 +1,6 @@
1
1
  import "../contracts/promises.mjs";
2
2
  import "../contracts/actors.mjs";
3
+ import "../contracts/git.mjs";
3
4
  import "../contracts/ids.mjs";
4
5
  import "../contracts/objects.mjs";
5
6
  import "../contracts/operations.mjs";
@@ -1,5 +1,6 @@
1
1
  import { fail, gitError } from "../contracts/result.mjs";
2
2
  import { check } from "../contracts/authorize.mjs";
3
+ import { asAsked } from "./asked.mjs";
3
4
  import { entryOf, nameOf, namedRecordOf, redirectOf, resolveRepo } from "../store/catalogue.mjs";
4
5
  import { afterWrites, isLimitRefusal } from "../store/errors.mjs";
5
6
  import { readRecord } from "../store/repo-record.mjs";
@@ -66,17 +67,17 @@ const openRepo = /* @__PURE__ */ Effect.fnUntraced(function* (caller, operation,
66
67
  * its code, is told only to a caller that may read the repo, as receive's is. With `internalId`,
67
68
  * a name that holds another repo is as one with none, as `openRepo` says (Q705).
68
69
  */
69
- const openFor = (caller, repo, writing, internalId) => writing ? openRepo(caller, {
70
+ const openFor = (caller, repo, writing, internalId, confirm = "read") => writing ? openRepo(caller, {
70
71
  kind: "push",
71
72
  repo,
72
73
  updates: []
73
- }, [], internalId).pipe(Effect.catch((refused) => Effect.andThen(openRepo(caller, {
74
+ }, [], internalId, confirm).pipe(Effect.catch((refused) => Effect.andThen(openRepo(caller, {
74
75
  kind: "read",
75
76
  repo
76
77
  }, [], internalId), Effect.fail(refused)))) : openRepo(caller, {
77
78
  kind: "fetch",
78
79
  repo
79
- }, [], internalId);
80
+ }, [], internalId, confirm);
80
81
  /**
81
82
  * `read`, refused for size only once `check` passes: a caller `check` refuses gets its refusal
82
83
  * instead, so a repo too large for one read tells its size to no one who may not read it.
@@ -138,20 +139,18 @@ const authorized = /* @__PURE__ */ Effect.fnUntraced(function* (caller, operatio
138
139
  operation,
139
140
  repo: repoAccess(resolved)
140
141
  });
141
- if (confirm === "skip") return resolved;
142
+ if (confirm !== "read") return resolved;
142
143
  yield* confirmed(resolved);
143
144
  return resolved;
144
145
  });
145
146
  /**
146
- * Succeeds when `repo`'s `self`, read after `authorize` answered, still holds what it was asked of: the
147
- * record live, with the name and the visibility the record read before held, as git-services' core
148
- * confirm says. A host's `authorize` may take long enough for a rename, a delete or a visibility
149
- * change to land, so nothing is answered from a record the repo no longer has. It compares records,
150
- * never the catalogue's name, which a rename's entry gives a moment after its record. One that moved
151
- * is `NOT_FOUND` for the name, as for a name that was never there, and isn't tried again.
147
+ * Succeeds when `repo`'s `self`, read in a call of its own after `authorize` answered, still holds
148
+ * what it was asked of, as `asAsked` says.
152
149
  */
153
150
  const confirmed = /* @__PURE__ */ Effect.fnUntraced(function* (repo) {
154
- if ((yield* liveAsAsked(repo))?.name !== repo.record.name) return yield* fail("NOT_FOUND", `No repo '${repo.name}'`);
151
+ const { store } = yield* CoreParts;
152
+ const { record } = yield* readRecord(store, repo.internalId);
153
+ return yield* asAsked(repo, record);
155
154
  });
156
155
  /**
157
156
  * `repo`'s record, read again once `authorize` answered, while it's live with the visibility the
@@ -0,0 +1,30 @@
1
+ import { fail } from "../contracts/result.mjs";
2
+ import { storeCall } from "../store/errors.mjs";
3
+ import { readRecord } from "../store/repo-record.mjs";
4
+ import { repoScope } from "../store/scopes.mjs";
5
+ import * as Effect from "effect/Effect";
6
+ // src/core/asked.ts
7
+ /**
8
+ * Succeeds when `record`, read after `authorize` answered, still holds what `repo` was asked of:
9
+ * live, with the name and the visibility the record read before held, as git-services' core
10
+ * confirm says. A host's `authorize` may take long enough for a rename, a delete or a visibility
11
+ * change to land, so nothing is answered from a record the repo no longer has. It compares records,
12
+ * never the catalogue's name, which a rename's entry gives a moment after its record. One that
13
+ * moved is `NOT_FOUND` for the name, as for a name that was never there, and isn't tried again.
14
+ */
15
+ const asAsked = (repo, record) => record !== void 0 && record.deleted !== true && record.public === repo.record.public && record.name === repo.record.name ? Effect.void : fail("NOT_FOUND", `No repo '${repo.name}'`);
16
+ /**
17
+ * `reads` and `counts` of `internalId`'s scope at one version. With `asked`, its `self` is read in
18
+ * the same call and held to it, as `asAsked` says: the open that skipped its own confirm for
19
+ * `'first-read'` confirms on this read, with no call of its own. The snapshot is of `reads` alone.
20
+ */
21
+ const readAsked = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, reads, counts = [], asked) {
22
+ if (asked === void 0) return yield* storeCall(() => store.read(repoScope(internalId), [...reads], [...counts]));
23
+ const { record, snapshot } = yield* readRecord(store, internalId, reads, counts);
24
+ yield* asAsked(asked, record);
25
+ return {
26
+ ...snapshot,
27
+ results: snapshot.results.slice(1)
28
+ };
29
+ });
30
+ export { asAsked, readAsked };
@@ -1,4 +1,5 @@
1
1
  import "../../contracts/events.mjs";
2
+ import "../../contracts/objects.mjs";
2
3
  import "../../contracts/promises.mjs";
3
4
  import "../../contracts/git-events.mjs";
4
5
  import { GitError } from "../../contracts/result.mjs";
@@ -5,6 +5,7 @@ import { pushRefLimit } from "../push-decide.mjs";
5
5
  import { fail, gitError } from "../../contracts/result.mjs";
6
6
  import { isWellFormed, utf8 } from "../../protocol/bytes/text.mjs";
7
7
  import { decodeRecord } from "../../store/catalogue.mjs";
8
+ import { heldAdd, heldStore } from "../../store/repo-record.mjs";
8
9
  import { settleName } from "../../store/settle.mjs";
9
10
  import { decodeRow, storeCall } from "../../store/errors.mjs";
10
11
  import { Delivered, FailedTry, Follower, appendEvents, cursorId, cursorRead, decodeLeading, decodeOutbox, decodeStamps, deliveryCursorId, eventBytes, eventId, eventLimits, failedKeyOf, failedPrefix, headKey, outboxCollections, outboxReads, repoEnvelope, rowBytes, shownEvent } from "../../store/outbox.mjs";
@@ -217,7 +218,10 @@ const wakeFollowers = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
217
218
  const { id } = row;
218
219
  const { seq } = yield* decodeRow(Follower, row, `The follower '${id}'`);
219
220
  if (seq > delivered.seq) continue;
220
- if (isInternalId(id)) yield* storeCall(() => parts.store.add(repoScope(id), { jobs: [...parts.wake()] }));
221
+ if (isInternalId(id)) {
222
+ const wake = { jobs: [...parts.wake()] };
223
+ yield* heldAdd(heldStore(parts.store), id, parts.fetchLimits, wake).pipe(Effect.catchTag("RepoGone", () => Effect.void));
224
+ }
221
225
  woken.push({
222
226
  collection: row.collection,
223
227
  id
@@ -15,7 +15,7 @@ import { appendEvents, decodeOutbox, dropUnconfirmed, emptyOutbox, outboxReads,
15
15
  import { keptKey } from "../store/records.mjs";
16
16
  import { WholeRepo, refBytesOf, storesPeel, wholeRef, wholeRefs } from "../store/ref-rows.mjs";
17
17
  import { peeledAll } from "../storage/wants.mjs";
18
- import { commitRecord, decodeStats, looseRows, readRecord, timeRow, writeRecord } from "../store/repo-record.mjs";
18
+ import { commitRecord, decodeStats, heldAdd, heldStore, looseRows, readRecord, timeRow, writeRecord } from "../store/repo-record.mjs";
19
19
  import { afterCommit } from "../store/call-count.mjs";
20
20
  import { listBound } from "../store/cursor-seal.mjs";
21
21
  import { settleName } from "../store/settle.mjs";
@@ -95,6 +95,16 @@ const forkRead = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId)
95
95
  });
96
96
  const isAlreadyThere = (error) => error.code === "ALREADY_EXISTS";
97
97
  /**
98
+ * A cover add to `into`'s scope: a create's goes plainly, its record with it or after it, and an
99
+ * existing fork's sync's, with `held`, is a held add, refused NOT_FOUND once the fork is gone, so a
100
+ * sync that waited on its source past the fork's purge never makes its scope again (#1911).
101
+ */
102
+ const coverAdd = /* @__PURE__ */ Effect.fnUntraced(function* (into, addition, held) {
103
+ const core = yield* CoreParts;
104
+ if (held === void 0) return yield* storeCall(() => core.store.add(repoScope(into), addition));
105
+ return yield* heldAdd(heldStore(core.store), into, held.fetchLimits, addition).pipe(Effect.catchTag("RepoGone", () => fail("NOT_FOUND", `No repo '${held.fork}'`)));
106
+ });
107
+ /**
98
108
  * Adds, outside the version, a `leaving` row in `into`'s scope for each of `packs`, due at
99
109
  * `removeAt`, with `git.repack` due then, before their markers are put: so a marker no commit of
100
110
  * the fork claims, one a call that lost, gave up or stopped left, goes with the fork's clean-up
@@ -102,7 +112,7 @@ const isAlreadyThere = (error) => error.code === "ALREADY_EXISTS";
102
112
  * commits has upkeep to take its rows. The commit that lists a pack deletes its row. A row
103
113
  * another call of the fork's added first covers its marker as well, so each is added alone then.
104
114
  */
105
- const coverMarks = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs, removeAt, first = []) {
115
+ const coverMarks = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs, removeAt, first, held) {
106
116
  const core = yield* CoreParts;
107
117
  const leaving = packs.flatMap(({ id, ...size }) => isPackId(id) ? [leavingRow({
108
118
  id,
@@ -110,12 +120,11 @@ const coverMarks = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs, rem
110
120
  }, removeAt)] : []);
111
121
  const put = [...first, ...leaving];
112
122
  if (put.length === 0) return;
113
- const scope = repoScope(into);
114
123
  const jobs = [core.repackJobRow(removeAt)];
115
- const add = (rows) => storeCall(() => core.store.add(scope, {
124
+ const add = (rows) => coverAdd(into, {
116
125
  put: rows,
117
126
  jobs
118
- }));
127
+ }, held);
119
128
  if (yield* add(put).pipe(Effect.as(true), Effect.catchIf(isAlreadyThere, () => Effect.succeed(false)))) return;
120
129
  const alone = (row) => add([row]).pipe(Effect.catchIf(isAlreadyThere, () => Effect.void));
121
130
  yield* Effect.forEach(put, alone, { discard: true });
@@ -126,7 +135,7 @@ const coverMarks = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs, rem
126
135
  * which the fork's clean-up then lets go as a `leaving` row's (#1582). The row holds the marker,
127
136
  * never the try, so the try never deletes it.
128
137
  */
129
- const coverLost = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs, removeAt) {
138
+ const coverLost = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs, removeAt, held) {
130
139
  const core = yield* CoreParts;
131
140
  const tried = newChangeId();
132
141
  const put = packs.flatMap(({ id, ...size }) => isPackId(id) ? [coverRow({
@@ -135,10 +144,10 @@ const coverLost = /* @__PURE__ */ Effect.fnUntraced(function* (into, packs, remo
135
144
  }, tried, removeAt)] : []);
136
145
  if (put.length === 0) return;
137
146
  const jobs = [core.repackJobRow(removeAt)];
138
- yield* storeCall(() => core.store.add(repoScope(into), {
147
+ yield* coverAdd(into, {
139
148
  put,
140
149
  jobs
141
- }));
150
+ }, held);
142
151
  });
143
152
  /**
144
153
  * Of `packs`, just marked for `into`, those whose marker no row of `into` holds now: the fork
@@ -357,6 +366,19 @@ const diverged = (repo) => fail("FAILED_PRECONDITION", `'${repo}' has commits it
357
366
  /** `<holder>/<the source's last segment>`, as GitHub names a fork (Q327). */
358
367
  const longDefaultName = (id) => fail("INVALID_ARGUMENT", `The fork's default name '${id}' is longer than 200 characters`, { hint: "Give the fork a shorter 'name', or use a shorter holder" });
359
368
  const defaultId = (source, holder) => `${holder}/${source.split("/").at(-1) ?? source}`;
369
+ /**
370
+ * `read` without its refs under a prefix a registration publishes, such as a pull request's
371
+ * `refs/pull/` and the merge queue's `gh-readonly-queue/`: the host writes them from rows of the
372
+ * source's own, which a fork doesn't copy, so nothing would ever settle the copies (#2324).
373
+ */
374
+ const unpublished = (published, read) => {
375
+ const prefixes = published.map(({ prefix }) => prefix);
376
+ const refs = read.refs.filter(({ id }) => !prefixes.some((prefix) => id.startsWith(prefix)));
377
+ return {
378
+ ...read,
379
+ refs
380
+ };
381
+ };
360
382
  /** The fork's rows, from the read its commit takes: refs, packs and the object rows it copies. */
361
383
  const forkRows = (index, read, objects) => [
362
384
  ...refCopies(index, read.refs),
@@ -618,9 +640,9 @@ const forkCalls = (bound) => {
618
640
  value: aside
619
641
  }] : [];
620
642
  asideFirst = false;
621
- return coverMarks(internalId, packs, removeAt, first);
643
+ return coverMarks(internalId, packs, removeAt, first, void 0);
622
644
  },
623
- lost: (packs) => Effect.andThen(coverLost(internalId, packs, removeAt), () => cleaningUp(repo))
645
+ lost: (packs) => Effect.andThen(coverLost(internalId, packs, removeAt, void 0), () => cleaningUp(repo))
624
646
  });
625
647
  for (let attempt = 0; taken === void 0 && attempt < 5; attempt += 1) {
626
648
  const first = yield* sourceSized(forkRead(store, source), caller, source, forkingName, gone);
@@ -638,7 +660,7 @@ const forkCalls = (bound) => {
638
660
  }
639
661
  if (taken === void 0) return yield* contended();
640
662
  const { objects } = taken;
641
- const read = yield* seenSource(caller, taken.read);
663
+ const read = unpublished(core.publishedRefs(), yield* seenSource(caller, taken.read));
642
664
  const record = forkRecord(read, id, revision, holder, at, core.refIndex);
643
665
  const listing = new Set(read.listed.packs.map((pack) => pack.id));
644
666
  const covered = read.listed.packs.flatMap(({ id }) => isPackId(id) ? [leavingKey(id)] : []);
@@ -945,9 +967,13 @@ const forkCalls = (bound) => {
945
967
  const addedRows = first.packs.filter(({ id }) => !listing.has(id));
946
968
  yield* checkCopy(first.name, [...firstRows, ...addedRows]);
947
969
  const removeAt = into.at + Math.max(pruneFloor, fetchLimits.milliseconds);
970
+ const syncHeld = {
971
+ fetchLimits,
972
+ fork
973
+ };
948
974
  const cover = {
949
- add: (packs) => coverMarks(into.internalId, packs, removeAt),
950
- lost: (packs) => Effect.andThen(coverLost(into.internalId, packs, removeAt), () => cleaningUp(fork))
975
+ add: (packs) => coverMarks(into.internalId, packs, removeAt, [], syncHeld),
976
+ lost: (packs) => Effect.andThen(coverLost(into.internalId, packs, removeAt, syncHeld), () => cleaningUp(fork))
951
977
  };
952
978
  const readingName = (name) => ({
953
979
  kind: "read",
@@ -1,4 +1,5 @@
1
1
  import { SyncSource } from "../contracts/sync.mjs";
2
+ import { readAsked } from "./asked.mjs";
2
3
  import { KeptError, keptError } from "./receipts.mjs";
3
4
  import { SavedCaller } from "./saved-callers.mjs";
4
5
  import { hexOf } from "../protocol/bytes/hex.mjs";
@@ -229,13 +230,17 @@ const failedRow = (row, error) => ({
229
230
  /** What a failed import's error says to do: no try comes after the last, whatever it said. */
230
231
  const failedHint = "Delete the repo, then import it again";
231
232
  const stoppedTry = keptError(gitError("UNAVAILABLE", "The import's last try stopped", { hint: failedHint }));
232
- /** The repo's import row, cancel row and cut, in one read. */
233
- const readImport = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId) {
234
- const snapshot = yield* storeCall(() => store.read(repoScope(internalId), [
233
+ /**
234
+ * The repo's import row, cancel row and cut, in one read: with `asked`, its record too, held to it
235
+ * as `asAsked` says.
236
+ */
237
+ const readImport = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, asked) {
238
+ const reads = [
235
239
  { ...importKey },
236
240
  { ...cancelKey },
237
241
  { ...cutKey }
238
- ]));
242
+ ];
243
+ const snapshot = yield* readAsked(store, internalId, reads, [], asked);
239
244
  const [[own] = [], [cancel] = [], [held] = []] = snapshot.results;
240
245
  const row = own === void 0 ? void 0 : yield* decodeRow(ImportRow, own, "Import");
241
246
  const cut = held === void 0 ? {} : yield* cutOf(held, row?.roots ?? []);
@@ -13,7 +13,8 @@ import { objectsFace, objectsOnce, readOnce, scopedReader, startingOnce } from "
13
13
  import { callScope } from "../../store/call-count.mjs";
14
14
  import { resultIn } from "../../store/crossing.mjs";
15
15
  import { allotmentWithin } from "../../contracts/object-values.mjs";
16
- import { openKeyed, openRepo } from "../access.mjs";
16
+ import { confirmed, openKeyed, openRepo } from "../access.mjs";
17
+ import { asAsked } from "../asked.mjs";
17
18
  import { isRefName } from "../names.mjs";
18
19
  import { SealedObjects, viewOf } from "../view.mjs";
19
20
  import { answerFailed } from "../../contracts/calls-spent.mjs";
@@ -60,18 +61,19 @@ const openReads = [packsRead, repoRootsKey];
60
61
  * The repo `repo` names, opened for `caller` to read, with `revisions` resolved: each a full ID as
61
62
  * it is, `HEAD` the default branch's tip, and a ref name the first of its refs held. A revision
62
63
  * no ref answers is `NOT_FOUND`. `HEAD` reads the repo again, its default branch with it, so its
63
- * packs and refs are read at that later version.
64
+ * packs and refs are read at that later version. The open confirms on that read, as `readOpened`
65
+ * says.
64
66
  */
65
67
  const openRead = /* @__PURE__ */ Effect.fnUntraced(function* (caller, repo, revisions = [], internalId) {
66
68
  const { asked, reads } = yield* readsOf(revisions);
67
69
  const opened = yield* openRepo(caller, {
68
70
  kind: "read",
69
71
  repo
70
- }, reads, internalId);
72
+ }, reads, internalId, "first-read");
71
73
  return yield* readOpened(caller, repo, revisions, {
72
74
  asked,
73
75
  reads
74
- }, opened);
76
+ }, opened, "first-read");
75
77
  });
76
78
  /**
77
79
  * `openRead` for a write `keyed` by a key: `undefined`, with nothing asked of `authorize`, once
@@ -88,7 +90,7 @@ const openKeyedRead = /* @__PURE__ */ Effect.fnUntraced(function* (caller, repo,
88
90
  return yield* readOpened(caller, repo, revisions, {
89
91
  asked,
90
92
  reads
91
- }, opened);
93
+ }, opened, "skip");
92
94
  });
93
95
  /** The refs each revision may name, and the reads of them, the packs and roots a repo opens with. */
94
96
  const readsOf = (revisions) => Effect.map(askedOf(revisions), (asked) => ({
@@ -105,15 +107,20 @@ const oneShotRead = (seen, listed, scope) => {
105
107
  const objects = objectsFace(seen);
106
108
  return (input) => resultIn(readOnce(objects, listed, input), scope, input.signal);
107
109
  };
108
- /** A repo resolved with `reads`, its revisions resolved too, as `openRead` says. */
109
- const readOpened = /* @__PURE__ */ Effect.fnUntraced(function* (caller, repo, revisions, { asked, reads }, opened) {
110
+ /**
111
+ * A repo resolved with `reads`, its revisions resolved too, as `openRead` says. With `first-read`,
112
+ * the open read nothing after `authorize` answered: the read again for `HEAD` or a narrowed view
113
+ * holds the repo to what was asked, as `asAsked` says, and a read that needs neither confirms in a
114
+ * call of its own, before anything is read from the open's record.
115
+ */
116
+ const readOpened = /* @__PURE__ */ Effect.fnUntraced(function* (caller, repo, revisions, { asked, reads }, opened, confirm) {
110
117
  const core = yield* CoreParts;
111
118
  let { record } = opened;
112
119
  let results = opened.snapshot.results.slice(1);
113
120
  let version = opened.snapshot.version;
114
121
  let index;
115
122
  const view = yield* viewOf(caller, opened);
116
- const every = yield* view.narrowed;
123
+ const every = yield* view.narrowed.pipe(Effect.catch((error) => confirm === "first-read" ? Effect.andThen(confirmed(opened), Effect.fail(error)) : Effect.fail(error)));
117
124
  const roots = yield* rootsOf(results[1]);
118
125
  let refsAt = openReads.length;
119
126
  if (revisions.includes("HEAD") || every) {
@@ -126,6 +133,7 @@ const readOpened = /* @__PURE__ */ Effect.fnUntraced(function* (caller, repo, re
126
133
  ...reads.slice(openReads.length),
127
134
  ...refReads([record.defaultBranch])
128
135
  ]);
136
+ if (confirm === "first-read") yield* asAsked(opened, again.record);
129
137
  if (again.record === void 0 || again.record.deleted === true) return yield* fail("NOT_FOUND", `No repo '${repo}'`);
130
138
  record = again.record;
131
139
  results = again.snapshot.results.slice(1);
@@ -135,7 +143,7 @@ const readOpened = /* @__PURE__ */ Effect.fnUntraced(function* (caller, repo, re
135
143
  index = results[2]?.[0]?.value;
136
144
  results = results.slice(0, 2);
137
145
  }
138
- }
146
+ } else if (confirm === "first-read") yield* confirmed(opened);
139
147
  const packs = yield* decodePacks(results[0] ?? []);
140
148
  const held = yield* view.refs(results.slice(refsAt).flat());
141
149
  const listed = {
@@ -19,7 +19,8 @@ import { JobDefinition, JobInput, Moment } from "@ref0/infra";
19
19
  import * as Context from "effect/Context";
20
20
  /**
21
21
  * A prefix a registration publishes, `RegisterInput.publishes`: refs `Git.host` writes under it on
22
- * someone's behalf, `refs.update`'s `onBehalfOf`, which every reader of the repo sees.
22
+ * someone's behalf, `refs.update`'s `onBehalfOf`, which every reader of the repo sees. A new fork
23
+ * copies none of them: the host writes them from rows of the source's, which the fork doesn't copy.
23
24
  */
24
25
  export interface PublishedRefs {
25
26
  readonly prefix: `refs/${string}/`;
@@ -27,7 +27,7 @@ import { appendEvents, decodeOutbox, firstSeq, outboxReads, repoEnvelope } from
27
27
  import { rowsAtCommit } from "./loose-tally.mjs";
28
28
  import { MirrorRow } from "./mirror-rows.mjs";
29
29
  import { PrunedMark, mirrorJobName } from "../store/records.mjs";
30
- import { decodeStats, looseRows, readRecord, repoStats, rootsOf, timeRow } from "../store/repo-record.mjs";
30
+ import { HeldBy, decodeStats, heldUntil, looseRows, readRecord, repoStats, rootsOf, timeRow } from "../store/repo-record.mjs";
31
31
  import { advanceRow } from "../store/queue-jobs.mjs";
32
32
  import { liveReservations, reservedTarget } from "../store/reservations.mjs";
33
33
  import { settleName } from "../store/settle.mjs";
@@ -216,7 +216,7 @@ const keyedRead = (caller, operation, missed, internalId) => openKeyed(caller, {
216
216
  * received against, its default branch, whose move rebuilds the ready shallow pack, and its
217
217
  * `pruned` mark.
218
218
  */
219
- const listedFor = /* @__PURE__ */ Effect.fnUntraced(function* (request, operation, resolved) {
219
+ const listedFor = /* @__PURE__ */ Effect.fnUntraced(function* (request, operation, resolved, heldAt) {
220
220
  const { caller } = request;
221
221
  const repo = repoAccess(resolved);
222
222
  if (request.queued === void 0) yield* check({
@@ -241,7 +241,8 @@ const listedFor = /* @__PURE__ */ Effect.fnUntraced(function* (request, operatio
241
241
  roots,
242
242
  repo,
243
243
  view,
244
- views
244
+ views,
245
+ heldAt
245
246
  };
246
247
  });
247
248
  /**
@@ -839,9 +840,9 @@ const lists = (body, pack) => body.delete.some((key) => key.collection === objec
839
840
  * only, refused as the commit would be, its `writes` or none, and answered before it, for
840
841
  * `checkPush`: nothing before that point writes, reserves or enqueues, with no pack.
841
842
  */
842
- const pushOnto = (request, { listed, defaultBranch, mark, roots, repo: checkedRepo, view, views }, key, answers, checking = false) => Effect.scoped(Effect.gen(function* () {
843
+ const pushOnto = (request, { listed, defaultBranch, mark, roots, repo: checkedRepo, view, views, heldAt }, key, answers, checking = false) => Effect.scoped(Effect.gen(function* () {
843
844
  const core = yield* CoreParts;
844
- const { objects: sealed } = yield* ObjectsParts;
845
+ const { objects: sealed, fetchLimits } = yield* ObjectsParts;
845
846
  const authorize = yield* Authorize;
846
847
  const { store } = core;
847
848
  const { caller, repo, signal } = request;
@@ -850,7 +851,7 @@ const pushOnto = (request, { listed, defaultBranch, mark, roots, repo: checkedRe
850
851
  const { received, rooted } = yield* receive(yield* read({
851
852
  view,
852
853
  at: seen
853
- }), listed, request).pipe(Effect.tapError((error) => isAwaitingRepack(error) ? bestEffort(ensureRepack(core, core.jobs, repoScope(listed.repo))) : Effect.void), Effect.mapError(asPushCheck));
854
+ }), listed, request).pipe(Effect.provideService(HeldBy, heldUntil(heldAt, fetchLimits)), Effect.tapError((error) => isAwaitingRepack(error) ? bestEffort(ensureRepack(core, core.jobs, listed.repo, fetchLimits)) : Effect.void), Effect.mapError(asPushCheck));
854
855
  const ownedPack = ownPack(request, received);
855
856
  let listing = false;
856
857
  if (ownedPack !== void 0) yield* Effect.addFinalizer((exit) => listing || Exit.hasInterrupts(exit) ? Effect.void : Effect.flatMap(Clock$1.currentTimeMillis, (at) => abandonOwn({
@@ -1205,8 +1206,9 @@ const pushWith = (request, answers, key) => pushThrough(request, answers, key, f
1205
1206
  /** `pushWith`, or with `checking`, its checks alone, as `pushOnto` says. */
1206
1207
  const pushThrough = /* @__PURE__ */ Effect.fnUntraced(function* (request, answers, key, checking) {
1207
1208
  const operation = operationOf(request);
1209
+ const heldAt = yield* Clock$1.currentTimeMillis;
1208
1210
  const resolved = yield* firstRead(request.caller, operation, request.internalId).pipe(Effect.tapError((error) => retriedCodes.has(error.code) ? Effect.void : refuseQueued(request, [error], "access")));
1209
- const opened = yield* listedFor(request, operation, resolved);
1211
+ const opened = yield* listedFor(request, operation, resolved, heldAt);
1210
1212
  return yield* pushOnto(request, opened, key, answers, checking);
1211
1213
  });
1212
1214
  /** A push or an unkeyed `refs.update`, answering the decide's ref answer. */
@@ -1245,9 +1247,10 @@ const pushFetched = (request) => pushWith(request, {
1245
1247
  */
1246
1248
  const keyedPushWith = /* @__PURE__ */ Effect.fnUntraced(function* (request, answers, keyed) {
1247
1249
  const operation = operationOf(request);
1250
+ const heldAt = yield* Clock$1.currentTimeMillis;
1248
1251
  const resolved = yield* keyedRead(request.caller, operation, keyed.missed, request.internalId);
1249
1252
  if (resolved === void 0) return void 0;
1250
- const opened = yield* listedFor(request, operation, resolved);
1253
+ const opened = yield* listedFor(request, operation, resolved, heldAt);
1251
1254
  return yield* pushOnto(request, opened, keyed.key, answers);
1252
1255
  });
1253
1256
  /** `keyedPushWith` for `refs.update`, answering the decide's ref answer. */
@@ -4,6 +4,7 @@ import "../contracts/ids.mjs";
4
4
  import { badCursor } from "../engine/reads.mjs";
5
5
  import { listBound } from "../store/cursor-seal.mjs";
6
6
  import { storeCall } from "../store/errors.mjs";
7
+ import { heldAdd, heldStore } from "../store/repo-record.mjs";
7
8
  import { keptKey } from "../store/records.mjs";
8
9
  import { refRowBytes } from "../store/ref-rows.mjs";
9
10
  import { collections, repoScope } from "../store/scopes.mjs";
@@ -19,7 +20,7 @@ import { plainClass, refIndexId } from "./ref-index.mjs";
19
20
  import { pushRulesFor } from "./rules/check.mjs";
20
21
  import { refProtection } from "./rules/protect.mjs";
21
22
  import { fail } from "../contracts/result.mjs";
22
- import { CoreParts, acting } from "./parts.mjs";
23
+ import { CoreParts, ObjectsParts, acting } from "./parts.mjs";
23
24
  import { bypassKinds, hostAuthorize } from "../auth/authorize.mjs";
24
25
  import { Authorize, check } from "../contracts/authorize.mjs";
25
26
  import * as Clock$1 from "effect/Clock";
@@ -282,8 +283,10 @@ const refCalls = (bound) => {
282
283
  const core = yield* CoreParts;
283
284
  const jobs = refIndexJobs(core, view.resolved.record);
284
285
  if (jobs.length === 0) return;
285
- yield* storeCall(() => core.store.add(repoScope(view.resolved.internalId), { jobs }));
286
- const scope = repoScope(view.resolved.internalId);
286
+ const { internalId } = view.resolved;
287
+ const { fetchLimits } = yield* ObjectsParts;
288
+ if (!(yield* heldAdd(heldStore(core.store), internalId, fetchLimits, { jobs }).pipe(Effect.as(true), Effect.catchTag("RepoGone", () => Effect.succeed(false))))) return;
289
+ const scope = repoScope(internalId);
287
290
  for (const { name, key } of jobs) yield* storeCall(() => core.jobs.retry(scope, {
288
291
  name,
289
292
  key
@@ -1,4 +1,5 @@
1
1
  import "../contracts/git.mjs";
2
+ import "../contracts/objects.mjs";
2
3
  import "../contracts/promises.mjs";
3
4
  import "../auth/fences.mjs";
4
5
  import { JobInput, Moment } from "@ref0/infra";