@ref0/git 0.11.0 → 0.14.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 (262) hide show
  1. package/dist/access/private-refs.mjs +8 -7
  2. package/dist/auth/auth.d.mts +2 -2
  3. package/dist/auth/auth.mjs +3 -6
  4. package/dist/auth/authorize.mjs +1 -17
  5. package/dist/auth/helpers.mjs +3 -11
  6. package/dist/auth/host-services.mjs +11 -0
  7. package/dist/auth/policy.d.mts +27 -7
  8. package/dist/auth/policy.mjs +8 -4
  9. package/dist/auth/tokens-layer.d.mts +1 -2
  10. package/dist/auth/tokens-layer.mjs +2 -3
  11. package/dist/auth/tokens-public.d.mts +3 -3
  12. package/dist/auth/tokens.d.mts +1 -8
  13. package/dist/auth/tokens.mjs +1 -8
  14. package/dist/auth.d.mts +1 -4
  15. package/dist/auth.mjs +1 -3
  16. package/dist/client/git-http.mjs +18 -4
  17. package/dist/client/push-upload.mjs +33 -7
  18. package/dist/client/remote.mjs +94 -28
  19. package/dist/client/slice-push.d.mts +1 -1
  20. package/dist/contracts/access.d.mts +8 -8
  21. package/dist/contracts/actors.d.mts +2 -34
  22. package/dist/contracts/blobs.d.mts +2 -2
  23. package/dist/contracts/client.d.mts +8 -3
  24. package/dist/contracts/commits.d.mts +10 -2
  25. package/dist/contracts/commits.mjs +9 -1
  26. package/dist/contracts/files.d.mts +2 -2
  27. package/dist/contracts/forks.d.mts +14 -3
  28. package/dist/contracts/git.d.mts +41 -12
  29. package/dist/contracts/git.mjs +3 -2
  30. package/dist/contracts/lfs.d.mts +0 -7
  31. package/dist/contracts/objects.d.mts +80 -10
  32. package/dist/contracts/operations.d.mts +3 -0
  33. package/dist/contracts/operations.mjs +12 -2
  34. package/dist/contracts/push-uploads.d.mts +44 -5
  35. package/dist/contracts/push-uploads.mjs +7 -3
  36. package/dist/contracts/refs.d.mts +28 -6
  37. package/dist/contracts/remote.mjs +1 -3
  38. package/dist/contracts/repo-records.d.mts +1 -0
  39. package/dist/contracts/repos.d.mts +90 -2
  40. package/dist/contracts/repos.mjs +29 -2
  41. package/dist/contracts/result.d.mts +30 -23
  42. package/dist/contracts/result.mjs +24 -9
  43. package/dist/contracts/rules.d.mts +22 -22
  44. package/dist/contracts/server.d.mts +28 -77
  45. package/dist/contracts/signin.d.mts +1 -1
  46. package/dist/contracts/sync.d.mts +90 -19
  47. package/dist/contracts/sync.mjs +34 -10
  48. package/dist/contracts/tokens.d.mts +1 -6
  49. package/dist/contracts/tokens.mjs +1 -2
  50. package/dist/contracts/topics.d.mts +0 -5
  51. package/dist/contracts/work.d.mts +66 -2
  52. package/dist/contracts/work.mjs +8 -1
  53. package/dist/core/access.d.mts +1 -0
  54. package/dist/core/access.mjs +34 -13
  55. package/dist/core/ancestry.d.mts +9 -0
  56. package/dist/core/ancestry.mjs +6 -6
  57. package/dist/core/asked.mjs +68 -0
  58. package/dist/core/call-names.mjs +1 -0
  59. package/dist/core/call-services.mjs +2 -1
  60. package/dist/core/events/deliver.d.mts +1 -0
  61. package/dist/core/events/deliver.mjs +15 -3
  62. package/dist/core/forks.mjs +42 -16
  63. package/dist/core/imports.mjs +156 -13
  64. package/dist/core/index-job.mjs +9 -6
  65. package/dist/core/job-view.mjs +8 -9
  66. package/dist/core/mirror-rows.mjs +19 -4
  67. package/dist/core/objects/commits.mjs +16 -6
  68. package/dist/core/objects/reading.mjs +17 -9
  69. package/dist/core/parts.d.mts +8 -2
  70. package/dist/core/parts.mjs +1 -4
  71. package/dist/core/purge.mjs +76 -6
  72. package/dist/core/push-decide.mjs +1 -1
  73. package/dist/core/push-files.d.mts +12 -0
  74. package/dist/core/push-files.mjs +225 -0
  75. package/dist/core/push-repo.d.mts +8 -0
  76. package/dist/core/push-repo.mjs +56 -0
  77. package/dist/core/push.d.mts +17 -0
  78. package/dist/core/push.mjs +107 -32
  79. package/dist/core/receipts.mjs +26 -10
  80. package/dist/core/ref-view.mjs +59 -5
  81. package/dist/core/refs.mjs +18 -10
  82. package/dist/core/registered-rows.mjs +7 -5
  83. package/dist/core/repack.mjs +16 -11
  84. package/dist/core/repo-info.mjs +16 -9
  85. package/dist/core/repos.mjs +30 -14
  86. package/dist/core/saved-caller-views.d.mts +18 -0
  87. package/dist/core/saved-caller-views.mjs +17 -4
  88. package/dist/core/saved-callers-public.d.mts +3 -3
  89. package/dist/core/saved-callers-public.mjs +3 -2
  90. package/dist/core/saved-callers.d.mts +7 -0
  91. package/dist/core/seam.mjs +2 -2
  92. package/dist/core/view.d.mts +6 -0
  93. package/dist/core/view.mjs +45 -12
  94. package/dist/core/work.mjs +47 -22
  95. package/dist/effect.d.mts +3 -1
  96. package/dist/effect.mjs +3 -1
  97. package/dist/engine/reads.mjs +13 -6
  98. package/dist/engine/walk.mjs +4 -4
  99. package/dist/event-streams/event-streams.d.mts +1 -1
  100. package/dist/event-streams/event-streams.mjs +1 -1
  101. package/dist/event-streams/stream.d.mts +1 -1
  102. package/dist/event-streams/stream.mjs +1 -1
  103. package/dist/extend.d.mts +4 -3
  104. package/dist/extend.mjs +3 -2
  105. package/dist/http/answers.mjs +4 -2
  106. package/dist/http/core-parts.mjs +64 -15
  107. package/dist/http/handler.mjs +2 -2
  108. package/dist/http/node.mjs +5 -4
  109. package/dist/http/parts.d.mts +1 -0
  110. package/dist/http/push-upload-job.mjs +503 -0
  111. package/dist/http/push-uploads.d.mts +1 -0
  112. package/dist/http/push-uploads.mjs +120 -59
  113. package/dist/http/upload-pack.mjs +7 -6
  114. package/dist/index.d.mts +23 -24
  115. package/dist/index.mjs +4 -7
  116. package/dist/lfs/base.d.mts +7 -3
  117. package/dist/lfs/base.mjs +2 -1
  118. package/dist/lfs/copy.d.mts +46 -0
  119. package/dist/lfs/copy.mjs +26 -0
  120. package/dist/lfs/layer.mjs +4 -2
  121. package/dist/lfs/locks.mjs +14 -9
  122. package/dist/lfs/objects.d.mts +6 -0
  123. package/dist/lfs/objects.mjs +95 -61
  124. package/dist/lfs/rows.d.mts +13 -0
  125. package/dist/lfs/service.d.mts +1 -7
  126. package/dist/lfs/service.mjs +1 -9
  127. package/dist/lfs/upload-most.mjs +5 -5
  128. package/dist/node.d.mts +2 -2
  129. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  130. package/dist/protocol/bytes/sha256.d.mts +32 -0
  131. package/dist/protocol/bytes/sha256.mjs +105 -49
  132. package/dist/protocol/wire/advertisement.mjs +9 -4
  133. package/dist/protocol/wire/lines.d.mts +4 -2
  134. package/dist/protocol/wire/lines.mjs +11 -5
  135. package/dist/protocol/wire/push-uploads.mjs +13 -1
  136. package/dist/protocol/wire/v2.mjs +2 -2
  137. package/dist/protocol.d.mts +3 -1
  138. package/dist/protocol.mjs +3 -1
  139. package/dist/queue/advance.mjs +1 -1
  140. package/dist/queue/calls.mjs +21 -1
  141. package/dist/queue/host.d.mts +1 -7
  142. package/dist/queue/host.mjs +1 -7
  143. package/dist/queue/layer.mjs +1 -1
  144. package/dist/queue/trim.mjs +1 -1
  145. package/dist/rest/blobs.d.mts +16 -8
  146. package/dist/rest/blobs.mjs +1 -1
  147. package/dist/rest/caller.d.mts +49 -9
  148. package/dist/rest/caller.mjs +1 -1
  149. package/dist/rest/client.d.mts +10 -3
  150. package/dist/rest/client.mjs +4 -0
  151. package/dist/rest/commits.d.mts +272 -239
  152. package/dist/rest/errors.d.mts +24 -4
  153. package/dist/rest/events.d.mts +9 -6
  154. package/dist/rest/events.mjs +1 -2
  155. package/dist/rest/files.d.mts +112 -100
  156. package/dist/rest/forks.d.mts +146 -122
  157. package/dist/rest/handler.mjs +4 -57
  158. package/dist/rest/handlers.d.mts +1 -1
  159. package/dist/rest/handlers.mjs +18 -4
  160. package/dist/rest/layer.mjs +10 -2
  161. package/dist/rest/me.d.mts +8 -4
  162. package/dist/rest/merges.d.mts +8 -4
  163. package/dist/rest/paths.mjs +1 -0
  164. package/dist/rest/queue.d.mts +292 -236
  165. package/dist/rest/refs.d.mts +98 -69
  166. package/dist/rest/repos.d.mts +133 -105
  167. package/dist/rest/tags.d.mts +100 -88
  168. package/dist/rest/tokens.d.mts +192 -168
  169. package/dist/rest/topics.d.mts +154 -134
  170. package/dist/rest/trees.d.mts +32 -16
  171. package/dist/rest/work.d.mts +467 -20
  172. package/dist/rest/work.mjs +8 -0
  173. package/dist/server/edge-node.d.mts +9 -13
  174. package/dist/server/edge-node.mjs +9 -12
  175. package/dist/server/git-layer.d.mts +1 -6
  176. package/dist/server/git-layer.mjs +2 -2
  177. package/dist/server/git-namespace.d.mts +4 -4
  178. package/dist/server/joined.d.mts +15 -22
  179. package/dist/server/joined.mjs +5 -29
  180. package/dist/server/lifecycle.mjs +107 -23
  181. package/dist/server/registry.mjs +9 -1
  182. package/dist/server/server.mjs +139 -216
  183. package/dist/storage/budget.mjs +2 -2
  184. package/dist/storage/clean-up.mjs +13 -10
  185. package/dist/storage/fetch.mjs +13 -8
  186. package/dist/storage/file-limits.mjs +24 -0
  187. package/dist/storage/index-build.d.mts +1 -0
  188. package/dist/storage/index-build.mjs +106 -62
  189. package/dist/storage/index-fetch.mjs +16 -3
  190. package/dist/storage/index-reach.mjs +33 -5
  191. package/dist/storage/index-remap.mjs +8 -1
  192. package/dist/storage/index-shallow.mjs +5 -3
  193. package/dist/storage/largest-files.mjs +48 -0
  194. package/dist/storage/lfs-pointers.mjs +10 -1
  195. package/dist/storage/loose.mjs +3 -1
  196. package/dist/storage/memory-budget.mjs +154 -8
  197. package/dist/storage/merge-cut.mjs +5 -4
  198. package/dist/storage/pack-reads.mjs +246 -34
  199. package/dist/storage/pack-receive.mjs +83 -25
  200. package/dist/storage/packs.mjs +37 -21
  201. package/dist/storage/prune-keep.mjs +203 -34
  202. package/dist/storage/prune-seen.mjs +11 -6
  203. package/dist/storage/prune-walk.mjs +219 -81
  204. package/dist/storage/prune.mjs +629 -196
  205. package/dist/storage/push-uploads.mjs +36 -12
  206. package/dist/storage/quarantine.mjs +9 -7
  207. package/dist/storage/ready.mjs +47 -19
  208. package/dist/storage/receive-bounds.mjs +29 -8
  209. package/dist/storage/receive-state.mjs +8 -0
  210. package/dist/storage/receive-steps.mjs +71 -18
  211. package/dist/storage/repack.d.mts +1 -1
  212. package/dist/storage/repack.mjs +1 -8
  213. package/dist/storage/rows.mjs +12 -1
  214. package/dist/storage/shallow.d.mts +1 -0
  215. package/dist/storage/shallow.mjs +26 -4
  216. package/dist/storage/stream-whole.mjs +5 -2
  217. package/dist/storage/visible.mjs +29 -1
  218. package/dist/storage/walk.mjs +2 -1
  219. package/dist/store/catalogue.mjs +1 -0
  220. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  221. package/dist/store/cursor-seal-public.d.mts +5 -0
  222. package/dist/store/cursor-seal-public.mjs +5 -0
  223. package/dist/store/cursor-seal.d.mts +16 -2
  224. package/dist/store/cursor-seal.mjs +26 -14
  225. package/dist/store/errors.mjs +9 -1
  226. package/dist/store/records.d.mts +2 -0
  227. package/dist/store/records.mjs +9 -6
  228. package/dist/store/repo-record.d.mts +27 -0
  229. package/dist/store/repo-record.mjs +141 -4
  230. package/dist/store/scopes.mjs +10 -2
  231. package/dist/sync/bound.d.mts +2 -0
  232. package/dist/sync/bound.mjs +11 -2
  233. package/dist/sync/github.d.mts +6 -1
  234. package/dist/sync/github.mjs +63 -42
  235. package/dist/sync/http.mjs +36 -1
  236. package/dist/sync/import.mjs +4 -2
  237. package/dist/sync/layer.mjs +6 -2
  238. package/dist/sync/lfs-batch.mjs +119 -0
  239. package/dist/sync/lfs-copy.mjs +251 -0
  240. package/dist/sync/mirror.mjs +227 -147
  241. package/dist/sync/said.mjs +204 -0
  242. package/dist/sync/smart-http.mjs +4 -2
  243. package/dist/sync/step.mjs +33 -13
  244. package/dist/sync/tries.mjs +71 -24
  245. package/dist/sync.d.mts +2 -2
  246. package/dist/topics/advance.mjs +10 -3
  247. package/dist/topics/host.mjs +1 -19
  248. package/dist/topics/layer.mjs +1 -1
  249. package/package.json +3 -8
  250. package/dist/auth/bridge.mjs +0 -30
  251. package/dist/auth/helpers.d.mts +0 -17
  252. package/dist/core/purge.d.mts +0 -8
  253. package/dist/core/registered-rows.d.mts +0 -4
  254. package/dist/core/repack.d.mts +0 -11
  255. package/dist/http/handler.d.mts +0 -2
  256. package/dist/rest/handler.d.mts +0 -21
  257. package/dist/rest.d.mts +0 -2
  258. package/dist/rest.mjs +0 -1
  259. package/dist/server/registry.d.mts +0 -16
  260. package/dist/server/server.d.mts +0 -36
  261. package/dist/storage/repack-job.d.mts +0 -3
  262. package/dist/topics/host.d.mts +0 -7
@@ -1,5 +1,7 @@
1
- import { fail, gitError } from "../contracts/result.mjs";
1
+ import { isHost } from "../contracts/git.mjs";
2
+ import { fail, gitError, isGitError } from "../contracts/result.mjs";
2
3
  import { check } from "../contracts/authorize.mjs";
4
+ import { asAsked, askedBy, takeMove } from "./asked.mjs";
3
5
  import { entryOf, nameOf, namedRecordOf, redirectOf, resolveRepo } from "../store/catalogue.mjs";
4
6
  import { afterWrites, isLimitRefusal } from "../store/errors.mjs";
5
7
  import { readRecord } from "../store/repo-record.mjs";
@@ -7,7 +9,7 @@ import { collections } from "../store/scopes.mjs";
7
9
  import { readyKey } from "../storage/ready.mjs";
8
10
  import { liveReceipt, matchedReceipt, receiptReads } from "./receipts.mjs";
9
11
  import { rebuildDue } from "./ref-index.mjs";
10
- import { CoreParts } from "./parts.mjs";
12
+ import { CoreParts, asHost } from "./parts.mjs";
11
13
  import * as Effect from "effect/Effect";
12
14
  // src/core/access.ts
13
15
  /**
@@ -66,17 +68,17 @@ const openRepo = /* @__PURE__ */ Effect.fnUntraced(function* (caller, operation,
66
68
  * its code, is told only to a caller that may read the repo, as receive's is. With `internalId`,
67
69
  * a name that holds another repo is as one with none, as `openRepo` says (Q705).
68
70
  */
69
- const openFor = (caller, repo, writing, internalId) => writing ? openRepo(caller, {
71
+ const openFor = (caller, repo, writing, internalId, confirm = "read") => writing ? openRepo(caller, {
70
72
  kind: "push",
71
73
  repo,
72
74
  updates: []
73
- }, [], internalId).pipe(Effect.catch((refused) => Effect.andThen(openRepo(caller, {
75
+ }, [], internalId, confirm).pipe(Effect.catch((refused) => Effect.andThen(openRepo(caller, {
74
76
  kind: "read",
75
77
  repo
76
78
  }, [], internalId), Effect.fail(refused)))) : openRepo(caller, {
77
79
  kind: "fetch",
78
80
  repo
79
- }, [], internalId);
81
+ }, [], internalId, confirm);
80
82
  /**
81
83
  * `read`, refused for size only once `check` passes: a caller `check` refuses gets its refusal
82
84
  * instead, so a repo too large for one read tells its size to no one who may not read it.
@@ -139,19 +141,19 @@ const authorized = /* @__PURE__ */ Effect.fnUntraced(function* (caller, operatio
139
141
  repo: repoAccess(resolved)
140
142
  });
141
143
  if (confirm === "skip") return resolved;
144
+ askedBy(resolved, caller);
145
+ if (confirm === "first-read") return resolved;
142
146
  yield* confirmed(resolved);
143
147
  return resolved;
144
148
  });
145
149
  /**
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.
150
+ * Succeeds when `repo`'s `self`, read in a call of its own after `authorize` answered, still holds
151
+ * what it was asked of, as `asAsked` says.
152
152
  */
153
153
  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}'`);
154
+ const { store } = yield* CoreParts;
155
+ const { record } = yield* readRecord(store, repo.internalId);
156
+ return yield* asAsked(repo, record);
155
157
  });
156
158
  /**
157
159
  * `repo`'s record, read again once `authorize` answered, while it's live with the visibility the
@@ -183,6 +185,25 @@ const readableRedirect = (caller, to) => openRepo(caller, {
183
185
  repo: to
184
186
  }).pipe(Effect.as(to), Effect.catch((error) => error.code === "UNAVAILABLE" ? Effect.fail(error) : Effect.succeed(void 0)));
185
187
  /**
188
+ * `effect`, whose confirm's refusal of a repo renamed while `authorize` decided answers as a call
189
+ * after the rename would: `NOT_FOUND` with `renamedTo`, to a caller `readableRedirect` tells, and
190
+ * nothing more to anyone else. Nothing runs again (#2184). One redirect per refusal: the boundary
191
+ * that takes the move answers it, so one around it, refused or not, asks no second time, and the
192
+ * redirect's own open, whose confirm may refuse a second move, answers its caller nothing, never
193
+ * another redirect, as `readableRedirect` catches it. Any other failure is as it came.
194
+ */
195
+ const answerMoved = (effect) => Effect.catch(effect, (error) => {
196
+ if (!isGitError(error)) return Effect.fail(error);
197
+ const moved = takeMove(error);
198
+ if (moved === void 0) return Effect.fail(error);
199
+ return Effect.flatMap(readableRedirect(moved.caller, moved.to), (to) => Effect.fail(to === void 0 ? error : gitError("NOT_FOUND", error.message, { context: { renamedTo: to } })));
200
+ });
201
+ /**
202
+ * `effect` as `by` makes it: host code's, as `asHost` says, when `by` is `Git.host`. A repo it
203
+ * opened that moved while `authorize` decided is answered as `answerMoved` says.
204
+ */
205
+ const acting = (by, effect) => isHost(by) ? asHost(answerMoved(effect)) : answerMoved(effect);
206
+ /**
186
207
  * A missing name's `NOT_FOUND`, naming where it went only to a caller `readableRedirect` tells: the
187
208
  * repo `internalId` names, by its name now, when the call named one, as a rename took it away.
188
209
  */
@@ -278,4 +299,4 @@ const contended = () => fail("UNAVAILABLE", "Too many writes reached this repo a
278
299
  * it back before it sends the same call again (#1462).
279
300
  */
280
301
  const contendedAfterWrites = () => Effect.fail(afterWrites(gitError("UNAVAILABLE", "Too many writes reached this repo at once")));
281
- export { alreadyExists, callerFor, confirmed, contended, contendedAfterWrites, headOf, hiddenCodes, indexDeleteJobs, indexJobs, keyedRecord, liveAsAsked, nameMoved, openFor, openKeyed, openRepo, purgeJobs, readableRedirect, refIndexJobs, repoAccess, resolvedAs, sizedRead, statsReads, unlessHidden };
302
+ export { acting, alreadyExists, callerFor, confirmed, contended, contendedAfterWrites, headOf, hiddenCodes, indexDeleteJobs, indexJobs, keyedRecord, liveAsAsked, nameMoved, openFor, openKeyed, openRepo, purgeJobs, readableRedirect, refIndexJobs, repoAccess, resolvedAs, sizedRead, statsReads, unlessHidden };
@@ -0,0 +1,9 @@
1
+ import "../contracts/ids.mjs";
2
+ import "../contracts/objects.mjs";
3
+ import "../contracts/refs.mjs";
4
+ import "../contracts/result.mjs";
5
+ import "../contracts/store.mjs";
6
+ import "../storage/calls.mjs";
7
+ import "../protocol/objects/commit.mjs";
8
+ import "../store/call-count.mjs";
9
+ import "effect/Effect";
@@ -71,15 +71,15 @@ const callsPast = (spent, ref) => {
71
71
  });
72
72
  };
73
73
  /**
74
- * The walks' share of the request's calls, `ancestryCallsShare` of what it has left of each kind,
75
- * as a budget each of their stored reads is handed, nested in the budget in scope; or `undefined`
76
- * for a request with no bound, as on Node.
74
+ * A walk's share of the request's calls, `fraction` of what it has left of each kind,
75
+ * `ancestryCallsShare` for the history walks, as a budget each of its stored reads is handed,
76
+ * nested in the budget in scope; or `undefined` for a request with no bound, as on Node.
77
77
  */
78
- const walkBudgetOf = /* @__PURE__ */ Effect.fnUntraced(function* (request) {
78
+ const walkBudgetOf = /* @__PURE__ */ Effect.fnUntraced(function* (request, fraction = ancestryCallsShare) {
79
79
  const most = request?.most;
80
80
  if (request === void 0 || most === void 0) return void 0;
81
81
  const made = request.made();
82
- const share = (bound, spent) => Math.floor(Math.max(0, bound - spent) * ancestryCallsShare);
82
+ const share = (bound, spent) => Math.floor(Math.max(0, bound - spent) * fraction);
83
83
  return yield* CallBudget.make({
84
84
  bucket: share(most.bucket, made.bucket),
85
85
  subrequests: share(most.subrequests, made.subrequests)
@@ -301,4 +301,4 @@ const kindsOf = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
301
301
  exact: exactOf(seen, limit)
302
302
  };
303
303
  });
304
- export { ancestryBytes, ancestryCallsShare, ancestryLimit, kindsOf };
304
+ export { ancestryBytes, ancestryCallsShare, ancestryLimit, kindsOf, walkBudgetOf };
@@ -0,0 +1,68 @@
1
+ import { gitError } 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
+ /** The caller each open asked `authorize` for, by the repo it opened, as `askedBy` keeps it. */
8
+ const callers = /* @__PURE__ */ new WeakMap();
9
+ /** The repo each confirm's refusal held, where it went, as `asAsked` keeps it. */
10
+ const moves = /* @__PURE__ */ new WeakMap();
11
+ /**
12
+ * Keeps `caller` as the one `authorize` was asked for of `repo`, the open's own answer, so a
13
+ * confirm's refusal on it knows whom to tell where the repo went, as `takeMove` says. Keyed by the
14
+ * object, it leaves nothing for another call or another open: `repo` is the one `resolveRepo` built
15
+ * for this open alone, never cached, memoized or handed to another call, so two calls opening one
16
+ * repo at once keep two callers.
17
+ */
18
+ const askedBy = (repo, caller) => {
19
+ callers.set(repo, caller);
20
+ };
21
+ /**
22
+ * Where the repo whose confirm refused `error` went, and whom to tell: only for the very refusal
23
+ * `asAsked` failed with, so any other `NOT_FOUND`, a name with no repo or one a call made of its
24
+ * own, has none. It's taken once: the first to take it answers the move, and `error` keeps
25
+ * nothing, so a call boundary around another, as `refs.get`'s around `View.open`'s, asks of the
26
+ * new name no second time.
27
+ */
28
+ const takeMove = (error) => {
29
+ const move = moves.get(error);
30
+ moves.delete(error);
31
+ return move;
32
+ };
33
+ /**
34
+ * Succeeds when `record`, read after `authorize` answered, still holds what `repo` was asked of:
35
+ * live, with the name and the visibility the record read before held, as git-services' core
36
+ * confirm says. A host's `authorize` may take long enough for a rename, a delete or a visibility
37
+ * change to land, so nothing is answered from a record the repo no longer has. It compares records,
38
+ * never the catalogue's name, which a rename's entry gives a moment after its record. One that
39
+ * moved is `NOT_FOUND` for the name, as a call after the move would find it. A rename, live with
40
+ * the visibility asked of, keeps where it went for `answerMoved`, which the call answers with,
41
+ * told only to a caller who may read it there. A delete or a visibility change keeps nothing.
42
+ */
43
+ const asAsked = (repo, record) => {
44
+ const live = record !== void 0 && record.deleted !== true;
45
+ if (live && record.public === repo.record.public && record.name === repo.record.name) return Effect.void;
46
+ const refusal = gitError("NOT_FOUND", `No repo '${repo.name}'`);
47
+ const caller = callers.get(repo);
48
+ if (live && record.public === repo.record.public && caller !== void 0) moves.set(refusal, {
49
+ caller,
50
+ to: record.name
51
+ });
52
+ return Effect.fail(refusal);
53
+ };
54
+ /**
55
+ * `reads` and `counts` of `internalId`'s scope at one version. With `asked`, its `self` is read in
56
+ * the same call and held to it, as `asAsked` says: the open that skipped its own confirm for
57
+ * `'first-read'` confirms on this read, with no call of its own. The snapshot is of `reads` alone.
58
+ */
59
+ const readAsked = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, reads, counts = [], asked) {
60
+ if (asked === void 0) return yield* storeCall(() => store.read(repoScope(internalId), [...reads], [...counts]));
61
+ const { record, snapshot } = yield* readRecord(store, internalId, reads, counts);
62
+ yield* asAsked(asked, record);
63
+ return {
64
+ ...snapshot,
65
+ results: snapshot.results.slice(1)
66
+ };
67
+ });
68
+ export { asAsked, askedBy, readAsked, takeMove };
@@ -21,6 +21,7 @@ const callNames = {
21
21
  ],
22
22
  work: [
23
23
  "list",
24
+ "listById",
24
25
  "retry",
25
26
  "discard"
26
27
  ],
@@ -12,7 +12,7 @@ import { commitCalls } from "./objects/commits.mjs";
12
12
  import { fileCalls } from "./objects/files.mjs";
13
13
  import { tagCalls } from "./objects/tags.mjs";
14
14
  import { treeCalls } from "./objects/trees.mjs";
15
- import { acting } from "./parts.mjs";
15
+ import { acting } from "./access.mjs";
16
16
  import { providedCalls } from "./promise.mjs";
17
17
  import { repoCalls } from "./repos.mjs";
18
18
  import { workCalls } from "./work.mjs";
@@ -35,6 +35,7 @@ const forks = {
35
35
  };
36
36
  const work = {
37
37
  list: (repo, input, by) => acting(by, workCalls(by).list(repo, input)),
38
+ listById: (internalId, input, by) => acting(by, workCalls(by).listById(internalId, input)),
38
39
  retry: (repo, input, by) => acting(by, workCalls(by).retry(repo, input)),
39
40
  discard: (repo, input, by) => acting(by, workCalls(by).discard(repo, input))
40
41
  };
@@ -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
@@ -700,6 +704,14 @@ const sameJob = (a, b) => a.name === b.name && a.key === b.key;
700
704
  /** Whether `job` is a scope's job of a delivery, `git.deliver.<name>`. */
701
705
  const isDeliverJob = (job) => deliveryOf(job.name) !== void 0 && job.key === "deliver";
702
706
  /**
707
+ * Whether `job` is a delivery's job that none of `deliveries` names: a delivery the server no
708
+ * longer runs, whose queue leaves its jobs waiting and never claims them.
709
+ */
710
+ const isStrayDelivery = (job, deliveries) => {
711
+ const delivery = deliveryOf(job.name);
712
+ return delivery !== void 0 && job.key === "deliver" && !deliveries.includes(delivery);
713
+ };
714
+ /**
703
715
  * Whether `job`'s delivery has sent the event at `seq` in `scope`: its newest cursor row is at
704
716
  * `seq` or past it, or the event is gone, which a trim deletes only once every delivery has passed
705
717
  * it and a purge only once none holds it. Else one with no cursor row yet has sent none, and a
@@ -794,7 +806,7 @@ const skipFailed = /* @__PURE__ */ Effect.fnUntraced(function* (store, jobs, sco
794
806
  const longestDelivery = 78e4;
795
807
  /**
796
808
  * Throws an `INVALID_ARGUMENT` `GitError` for a delivery's `timeout` past a Git job's longest try,
797
- * as `createGitServer` checks its options before its runtime is built.
809
+ * as a server checks its deliveries before it serves.
798
810
  */
799
811
  const checkDeliveryTimeout = ({ timeout }) => {
800
812
  if (timeout === void 0 || millis(timeout) <= longestDelivery) return;
@@ -876,4 +888,4 @@ const deliveryJob = (parts, log, delivery) => {
876
888
  const onFailure = workFailed(log, parts.now, tried);
877
889
  return gitJob(DeliverJob, handler, { onFailure });
878
890
  };
879
- export { DeliverData, checkDeliveries, checkDeliveryTimeout, defaultDeliverRetry, deliverJobKey, deliverJobName, deliverTry, deliveryLog, drainCeiling, isDeliverJob, keptFor, notFailed, sentThrough, skipFailed, workFailed };
891
+ export { DeliverData, checkDeliveries, checkDeliveryTimeout, defaultDeliverRetry, deliverJobKey, deliverJobName, deliverTry, deliveryLog, drainCeiling, isDeliverJob, isStrayDelivery, keptFor, notFailed, sentThrough, skipFailed, workFailed };
@@ -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";
@@ -31,7 +31,7 @@ import { refCopies } from "./ref-index.mjs";
31
31
  import { forkKept, heldReceipt, receiptKeys, receiptReads, receiptWrites, repoAnswer, withJobs } from "./receipts.mjs";
32
32
  import { badRepoName, repoKept } from "./repos.mjs";
33
33
  import { pushCounts } from "./events/seen.mjs";
34
- import { refViewIn } from "./ref-view.mjs";
34
+ import { anyOwned, refViewIn } from "./ref-view.mjs";
35
35
  import { SealedObjects } from "./view.mjs";
36
36
  import { CoreParts, ObjectsParts } from "./parts.mjs";
37
37
  import { check } from "../contracts/authorize.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),
@@ -514,12 +536,12 @@ const forkCalls = (bound) => {
514
536
  /**
515
537
  * `read` with only the refs `caller` sees in the source, so a fork copies, fetches and syncs no
516
538
  * ref the caller couldn't read there: a private one it doesn't see is missing, as on every
517
- * other surface. A source's packs are still shared whole, and the fork's reads by ID follow its
539
+ * other surface, nor one under an `owned` prefix. A source's packs are still shared whole, and the fork's reads by ID follow its
518
540
  * own tips' reach (`objectsFollowRefs`), so no hidden commit is read through it.
519
541
  */
520
542
  const seenSource = Effect.fnUntraced(function* (caller, read) {
521
543
  const refView = yield* refViewIn(caller, repoAccess(read));
522
- if (refView.whole) return {
544
+ if (refView.whole && !anyOwned((yield* CoreParts).hiddenRefs())) return {
523
545
  ...read,
524
546
  headSeen: true
525
547
  };
@@ -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",