@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
@@ -8,11 +8,11 @@ import { outboxCollections } from "../store/outbox.mjs";
8
8
  import { keyKept } from "../store/records.mjs";
9
9
  import { readRecord } from "../store/repo-record.mjs";
10
10
  import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
11
- import { isDeliverJob, sentThrough } from "./events/deliver.mjs";
11
+ import { isDeliverJob, isStrayDelivery, sentThrough } from "./events/deliver.mjs";
12
12
  import { indexJobName } from "./index-job.mjs";
13
13
  import * as Effect from "effect/Effect";
14
14
  import * as Schema from "effect/Schema";
15
- import { Job, limits } from "@ref0/infra";
15
+ import { Job, defineJob, limits } from "@ref0/infra";
16
16
  // src/core/purge.ts
17
17
  /**
18
18
  * `git.purge`, a deleted repo's last job (L61, L130). Not before its delete's `fetchLimits` has
@@ -39,6 +39,11 @@ const purgeBackstop = 6e5;
39
39
  */
40
40
  const purgeRunningRelook = 6e4;
41
41
  /**
42
+ * The lease a purge claims a stray delivery's waiting job under, only to settle it done in the
43
+ * same try: no handler runs under it.
44
+ */
45
+ const strayLease = "1 minute";
46
+ /**
42
47
  * A step's page where its rows passed one read's `limits.answerBytes`, as object rows can: rows
43
48
  * of `limits.valueBytes` each fill half an answer.
44
49
  */
@@ -49,7 +54,9 @@ const purgeLargePage = /* @__PURE__ */ Math.floor(limits.answerBytes / limits.va
49
54
  * deletes its index's files, and each delivery's, `git.deliver.<name>`, sends `repo.deleted`. A
50
55
  * failed one holds the purge until a host retries or discards it. A delivery's waiting job that
51
56
  * has sent `repo.deleted` holds it no longer, since it waits only to trim events the purge
52
- * deletes itself. A new job that deletes a repo's bytes joins this list, or its check below.
57
+ * deletes itself. A stray's, a delivery the server no longer runs, holds it only `purgeBackstop`
58
+ * past its own time, while an instance that still runs it, in a deploy, may claim it; then the
59
+ * purge ends it. A new job that deletes a repo's bytes joins this list, or its check below.
53
60
  * Every other job ends on the record the purge deletes last: git.list's projection the purge runs
54
61
  * itself before it.
55
62
  */
@@ -122,11 +129,24 @@ const relookFor = (item, at) => {
122
129
  return item.state === "waiting" ? Math.max(item.due, at + purgeRunningRelook) : at + purgeRunningRelook;
123
130
  };
124
131
  /**
132
+ * When a stray delivery's job, one the server no longer runs, stops holding the purge:
133
+ * `purgeBackstop` past its due, or past its failure, by which an instance that still runs it would
134
+ * have claimed it.
135
+ *
136
+ * Which delivery is stray is this instance's own list, and the time is the row's, not the
137
+ * deploy's. In a rolling deploy that drops a delivery, a new instance purges at once a repo already
138
+ * deleted whose job of it is overdue or failed past `purgeBackstop`, within seconds of starting, and
139
+ * an old instance that still runs the delivery loses that repo's `repo.deleted`. So can one whose
140
+ * claim, or a host's retry, lands between a step's read and its deletes, which no store call fences.
141
+ */
142
+ const strayEnd = (item) => (item.state === "failed" ? item.failedAt ?? item.due : item.due) + purgeBackstop;
143
+ /**
125
144
  * When a purge at `at` looks again for the drain jobs and deliveries waiting, running or failed in
126
145
  * `scope`, the soonest of theirs: none when none is left. A page of its jobs at a time. `deleted`
127
146
  * is `repo.deleted`'s `seq`, past which a waiting delivery holds nothing; with none, each holds.
147
+ * A stray delivery's job holds only till its `strayEnd`, unless it runs.
128
148
  */
129
- const draining = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at, deleted) {
149
+ const draining = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at, deleted, deliveries) {
130
150
  let after;
131
151
  let soonest;
132
152
  for (;;) {
@@ -136,7 +156,9 @@ const draining = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at,
136
156
  const delivery = isDeliverJob(item);
137
157
  if (!drainJobs.has(item.name) && !delivery) continue;
138
158
  if (delivery && item.state === "waiting" && deleted !== void 0 && (yield* sentThrough(store, scope, item, deleted))) continue;
139
- const relook = relookFor(item, at);
159
+ const ends = item.state !== "running" && isStrayDelivery(item, deliveries) ? strayEnd(item) : void 0;
160
+ if (ends !== void 0 && ends <= at) continue;
161
+ const relook = ends ?? relookFor(item, at);
140
162
  soonest = soonest === void 0 ? relook : Math.min(soonest, relook);
141
163
  }
142
164
  if (listing.next === void 0) return soonest;
@@ -216,6 +238,53 @@ const dropScopes = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, in
216
238
  for (const scope of [...named, repoScope(internalId)]) yield* storeCall(() => store.drop(scope));
217
239
  });
218
240
  /**
241
+ * A stray delivery's waiting job made due at `at`: a save moves a waiting job's due only earlier,
242
+ * so a claim takes it. Its handler never runs, since no queue of this server runs its delivery.
243
+ */
244
+ const strayDueAt = (item, at) => defineJob({
245
+ name: item.name,
246
+ schema: Schema.toStandardSchemaV1(Schema.Unknown),
247
+ handler: () => {
248
+ throw new TypeError(`${item.name} is a delivery this server doesn't run`);
249
+ }
250
+ }).job({
251
+ key: item.key,
252
+ data: item.data,
253
+ at
254
+ });
255
+ /**
256
+ * The waiting jobs left in `scope` of deliveries the server doesn't run, each claimed and settled
257
+ * done, a page of them at a time: no queue of this server claims one, and their repo is gone.
258
+ * `draining` let each go past its `strayEnd`, or once it had sent `repo.deleted`, when it may
259
+ * wait for a trim due long after `at`: such a job is made due at `at` first, so the claim takes
260
+ * it, as `sqlite()`'s and `postgres()`'s drop would leave it.
261
+ */
262
+ const endStrays = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at, deliveries) {
263
+ let after;
264
+ for (;;) {
265
+ const page = after === void 0 ? {} : { page: { after } };
266
+ const listing = yield* storeCall(() => store.list(scope, {
267
+ state: "waiting",
268
+ ...page
269
+ }));
270
+ const strays = listing.items.filter((item) => isStrayDelivery(item, deliveries));
271
+ const names = strays.map((item) => item.name);
272
+ const later = strays.flatMap((item) => item.due > at ? [strayDueAt(item, at)] : []);
273
+ if (later.length > 0) yield* storeCall(() => store.add(scope, { jobs: later }));
274
+ if (names.length > 0) {
275
+ const request = {
276
+ lease: strayLease,
277
+ names,
278
+ limit: names.length
279
+ };
280
+ const { claims } = yield* storeCall(() => store.claim(scope, request));
281
+ yield* Effect.forEach(claims, (claim) => storeCall(() => store.settle(claim, { kind: "done" })), { discard: true });
282
+ }
283
+ if (listing.next === void 0) return;
284
+ after = listing.next;
285
+ }
286
+ });
287
+ /**
219
288
  * One step in the repo's scope: none for a repo that isn't deleted. It waits until its delete's
220
289
  * `fetchLimits` has passed, nor while a receipt it holds still answers, `keyKept` past the delete;
221
290
  * then while a drain job or a drained row stands, or a fork holds the
@@ -255,7 +324,7 @@ const purgeStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, int
255
324
  at: at + purgeBackstop
256
325
  };
257
326
  const deleted = record.nextSeq === void 0 ? void 0 : record.nextSeq - 1;
258
- const drain = yield* draining(store, scope, at, deleted);
327
+ const drain = yield* draining(store, scope, at, deleted, parts.deliveries);
259
328
  if (drain !== void 0) return {
260
329
  ...again,
261
330
  at: drain
@@ -280,6 +349,7 @@ const purgeStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, int
280
349
  yield* reconcile(store, internalId);
281
350
  if (!(yield* releaseHold(store, internalId, record))) return again;
282
351
  yield* discardFailed(store, scope);
352
+ yield* endStrays(store, scope, at, parts.deliveries);
283
353
  const own = yield* pageOf(store, scope, collections.repo);
284
354
  if (own.version !== version) return again;
285
355
  if (!(yield* storeCall(() => store.commit(scope, {
@@ -11,7 +11,7 @@ import { jsonBytes, limits } from "@ref0/infra";
11
11
  const pushRefLimit = 4e3;
12
12
  /**
13
13
  * What a push at `pushRefLimit` leaves of a commit's writes for its other rows: 2,000. Its mirror
14
- * jobs, `mirrorLimits.mirrors` at most, its `git.queue.advance` jobs, one a moved target and
14
+ * jobs, one a destination and `mirrorLimits.mirrors` at most, its `git.queue.advance` jobs, one a moved target and
15
15
  * `queueLimits.targets` at most, its delivery jobs, one a delivery and `deliveryLimit` at most,
16
16
  * and its fixed rows stay within it by construction.
17
17
  */
@@ -0,0 +1,12 @@
1
+ import "../contracts/ids.mjs";
2
+ import "../contracts/objects.mjs";
3
+ import "../contracts/push-uploads.mjs";
4
+ import "../contracts/result.mjs";
5
+ import "../store/call-count.mjs";
6
+ import "./ancestry.mjs";
7
+ import "effect/Effect";
8
+ /** A server's sizes for a pushed file, `pushes.files` resolved: a warning only when there's one. */
9
+ export interface PushFiles {
10
+ readonly warnAbove: number | undefined;
11
+ readonly refuseAbove: number;
12
+ }
@@ -0,0 +1,225 @@
1
+ import { gitError } from "../contracts/result.mjs";
2
+ import { drained } from "../protocol/diff/read.mjs";
3
+ import { readCommit } from "../protocol/objects/commit.mjs";
4
+ import { readTagTarget } from "../protocol/objects/tag.mjs";
5
+ import { treeReader } from "../protocol/objects/tree.mjs";
6
+ import { catchSpent, ownSpentOf } from "../contracts/calls-spent.mjs";
7
+ import { budgetedOn, callScope, spentBudget } from "../store/call-count.mjs";
8
+ import { fileBytesMost, fileRefuseBytes, fileWarnBytes } from "../storage/file-limits.mjs";
9
+ import { packObjectBytes } from "../storage/pack-reads.mjs";
10
+ import { walkBudgetOf } from "./ancestry.mjs";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Result from "effect/Result";
13
+ // src/core/push-files.ts
14
+ /** GitHub's: a warning past 50 MiB and a refusal past 100 MiB, as `storage/file-limits.ts` cites. */
15
+ const defaultPushFiles = {
16
+ warnAbove: fileWarnBytes,
17
+ refuseAbove: fileRefuseBytes
18
+ };
19
+ /**
20
+ * The most commits and trees a push's walk for its large files' paths reads: past it, a file not
21
+ * yet found is named by its ID. Only a push carrying a file past `warnAbove` walks at all.
22
+ */
23
+ const pathWalkMost = 1e5;
24
+ /**
25
+ * The walk for paths' share of the calls its request has left of each kind, after the history
26
+ * walks took theirs: past it, a file not yet found is named by its ID, and the rest stays for the
27
+ * push's rules, its publication and its answer. A name never costs a push that fits its calls.
28
+ */
29
+ const pathCallsShare = .25;
30
+ /**
31
+ * `pushes.files`, or a `TypeError` naming what's wrong: each size a whole number above 0,
32
+ * `refuseAbove` at most `fileBytesMost`, and `warnAbove` below it.
33
+ */
34
+ const pushFilesOf = (given) => {
35
+ const refuseAbove = given?.refuseAbove ?? 104857600;
36
+ const warning = given?.warnAbove ?? 52428800;
37
+ const warnAbove = warning === false ? void 0 : warning;
38
+ for (const [name, value] of [["refuseAbove", refuseAbove], ["warnAbove", warnAbove]]) if (value !== void 0 && (!Number.isSafeInteger(value) || value <= 0)) throw new TypeError(`pushes.files.${name} must be a whole number above 0: got ${value}`);
39
+ if (refuseAbove > fileBytesMost) throw new TypeError(`pushes.files.refuseAbove must be at most ${fileBytesMost}, a push's pack's own bound: got ${refuseAbove}`);
40
+ if (warnAbove !== void 0 && warnAbove >= refuseAbove) throw new TypeError(`pushes.files.warnAbove must be below refuseAbove, ${refuseAbove}: got ${warnAbove}`);
41
+ return {
42
+ warnAbove,
43
+ refuseAbove
44
+ };
45
+ };
46
+ const kib = 1024;
47
+ const mib = 1024 * kib;
48
+ const gib = 1024 * mib;
49
+ /** A size as `150.0 MiB (157,286,400 bytes)`, in KiB below 1 MiB and in GiB from 1 GiB. */
50
+ const sized = (bytes) => {
51
+ const [unit, name] = bytes < mib ? [kib, "KiB"] : bytes < gib ? [mib, "MiB"] : [gib, "GiB"];
52
+ return `${(bytes / unit).toFixed(1)} ${name} (${bytes.toLocaleString("en-US")} bytes)`;
53
+ };
54
+ const named = (file) => `File ${file.place?.named ?? file.oid}`;
55
+ /** `text` as one word for a POSIX shell: in single quotes, each of its own as `'\''`. */
56
+ const shellWord = (text) => `'${text.replaceAll("'", "'\\''")}'`;
57
+ const pathOf = (file) => file.place?.path;
58
+ /**
59
+ * `told`'s lines, `filesToldMost` of them, then how many more. `partial`: they're the push's
60
+ * largest files, and others no larger may be past the limit too, so the count says so.
61
+ */
62
+ const listed = (told, partial, line) => {
63
+ const shown = told.slice(0, 20).map(line);
64
+ const more = told.length - shown.length;
65
+ const rest = partial ? `and ${more} more of the largest ${told.length}` : `and ${more} more`;
66
+ return more > 0 ? [...shown, rest] : shown;
67
+ };
68
+ /**
69
+ * The refusal of a push carrying `files`, each past `refuseAbove`. `partial`: they're the push's
70
+ * largest `largestFilesMost`, all past it, so more may be, and the refusal says it names only these.
71
+ */
72
+ const filesRefused = (files, refuseAbove, partial = false) => {
73
+ const limit = `this server's limit of ${sized(refuseAbove)} for a file`;
74
+ const paths = files.flatMap((file) => pathOf(file) ?? []);
75
+ const them = paths.length === 1 ? "it" : "them";
76
+ const commands = paths.length === 0 ? "Track large files with Git LFS, then rewrite them out of history and push again" : `Track ${them} with Git LFS: git lfs track ${paths.map(shellWord).join(" ")}, then rewrite ${them} out of history with git lfs migrate import --include=${shellWord(paths.join(","))} and push again`;
77
+ const others = partial ? [`These are the push's largest ${files.length} files: others may be past the limit too`] : [];
78
+ const [first] = files;
79
+ const message = files.length === 1 && first !== void 0 ? `${named(first)} is ${sized(first.size)}, past ${limit}` : `${partial ? "At least " : ""}${files.length} files are past ${limit}`;
80
+ const each = files.length === 1 ? [] : listed(files, partial, (file) => `${named(file)} is ${sized(file.size)}`);
81
+ return gitError("RESOURCE_EXHAUSTED", message, {
82
+ hint: [
83
+ ...each,
84
+ ...others,
85
+ commands
86
+ ].join("\n"),
87
+ context: { reason: "object-too-large" }
88
+ });
89
+ };
90
+ /**
91
+ * The warnings for `files`, each past `warnAbove` and within the refusal: a line each, and one
92
+ * more when they're `partial`, the push's largest, all past it.
93
+ */
94
+ const filesWarned = (files, warnAbove, partial = false) => {
95
+ const lines = listed(files, partial, (file) => {
96
+ const path = pathOf(file);
97
+ const advice = path === void 0 ? "consider Git LFS" : `consider git lfs track ${shellWord(path)}`;
98
+ return `warning: ${named(file)} is ${sized(file.size)}, past the ${sized(warnAbove)} this server advises for a file; ${advice}`;
99
+ });
100
+ const others = `warning: these are the push's largest ${files.length} files; others may be past ${sized(warnAbove)} too`;
101
+ return partial ? [...lines, others] : lines;
102
+ };
103
+ const utf8 = new TextDecoder("utf-8", {
104
+ fatal: true,
105
+ ignoreBOM: true
106
+ });
107
+ /** A name's bytes as Git's `core.quotePath` writes them, unquoted: each not printable ASCII in octal. */
108
+ const escaped = (bytes) => Array.from(bytes, (byte) => byte === 34 || byte === 92 ? `\\${String.fromCharCode(byte)}` : byte >= 32 && byte < 127 ? String.fromCharCode(byte) : `\\${byte.toString(8).padStart(3, "0")}`).join("");
109
+ /** A tree entry's name as text: UTF-8, or `undefined` when it isn't. */
110
+ const utf8Of = (bytes) => {
111
+ try {
112
+ return utf8.decode(bytes);
113
+ } catch {
114
+ return;
115
+ }
116
+ };
117
+ /**
118
+ * An object's bytes, read whole within `packObjectBytes`: a commit, a tag or a tree. One past it is
119
+ * passed over, so a file only it reaches is named by its ID; any other failure to read it fails.
120
+ * Read within `walk`, the walk's own calls, it's `'spent'` once those run out and nothing else
121
+ * failed it; any other spent bound goes on whole, for its edge to answer.
122
+ */
123
+ const whole = (pushed, oid, walk) => {
124
+ const read = Effect.flatMap(pushed(walk === void 0 ? { oid } : budgetedOn({ oid }, walk)), (object) => object === void 0 ? Effect.succeed(void 0) : drained(object, packObjectBytes).pipe(Effect.map((bytes) => ({
125
+ type: object.type,
126
+ bytes
127
+ })), Effect.catchTag("DiffError", (error) => error.reason === "object-too-large" ? Effect.succeed(void 0) : Effect.fail(gitError("DATA_LOSS", error.message)))));
128
+ if (walk === void 0) return read;
129
+ return catchSpent(read, (_, cause) => ownSpentOf(cause, (each) => spentBudget(each) === walk) === void 0 ? Effect.failCause(cause) : Effect.succeed("spent"));
130
+ };
131
+ /**
132
+ * The path of each of `wanted`, walked from `tips` through the push's own objects alone: each
133
+ * commit it brings, its parents it brings, and their trees it brings, so no tree the repo held
134
+ * before is read, since none of those can hold a blob the push brought. A tag is followed to what
135
+ * it names, a tree included, so a blob reached only through a tree is found there; a blob a ref
136
+ * or a tag names is named by the ref, unread. It stops once every one is found, past
137
+ * `pathWalkMost` reads, or once `walk`, its own share of the calls, is spent.
138
+ */
139
+ const pathsOf = /* @__PURE__ */ Effect.fnUntraced(function* (pushed, tips, wanted, walk) {
140
+ const paths = /* @__PURE__ */ new Map();
141
+ const seen = /* @__PURE__ */ new Set();
142
+ const stack = tips.map((tip) => ({
143
+ oid: tip.oid,
144
+ path: "",
145
+ plain: true,
146
+ ref: tip.ref
147
+ }));
148
+ while (stack.length > 0 && paths.size < wanted.size && seen.size < 1e5) {
149
+ const next = stack.pop();
150
+ if (next === void 0 || seen.has(next.oid)) continue;
151
+ seen.add(next.oid);
152
+ if (wanted.has(next.oid)) {
153
+ if (!paths.has(next.oid)) paths.set(next.oid, { named: `(the blob ${next.ref} names)` });
154
+ continue;
155
+ }
156
+ const read = yield* whole(pushed, next.oid, walk);
157
+ if (read === "spent") break;
158
+ if (read === void 0) continue;
159
+ if (read.type === "commit") {
160
+ const commit = readCommit(read.bytes);
161
+ if (Result.isFailure(commit)) continue;
162
+ for (const parent of commit.success.parents) stack.push({
163
+ ...next,
164
+ oid: parent
165
+ });
166
+ stack.push({
167
+ ...next,
168
+ oid: commit.success.tree,
169
+ path: "",
170
+ plain: true
171
+ });
172
+ } else if (read.type === "tag") {
173
+ const target = readTagTarget(read.bytes);
174
+ if (Result.isFailure(target)) continue;
175
+ stack.push({
176
+ ...next,
177
+ oid: target.success.object
178
+ });
179
+ } else if (read.type === "tree") {
180
+ const entries = treeReader(read.bytes);
181
+ for (let entry = entries(); Result.isSuccess(entry); entry = entries()) {
182
+ const one = entry.success;
183
+ if (one === void 0) break;
184
+ const text = utf8Of(one.name);
185
+ const plain = next.plain && text !== void 0;
186
+ const path = `${next.path}${text ?? escaped(one.name)}`;
187
+ if (one.mode === "040000") stack.push({
188
+ ...next,
189
+ oid: one.oid,
190
+ path: `${path}/`,
191
+ plain
192
+ });
193
+ else if (wanted.has(one.oid) && !paths.has(one.oid)) paths.set(one.oid, plain ? {
194
+ named: path,
195
+ path
196
+ } : { named: `"${path}"` });
197
+ }
198
+ }
199
+ }
200
+ return paths;
201
+ });
202
+ /**
203
+ * A push held to its file sizes, from the files it `received`: the refusal when it carries a file
204
+ * past `refuseAbove`, else the warning lines for each past `warnAbove`, none when there's none. Only
205
+ * the received files are held to them: one the repo holds already, which a pushed tree names, isn't.
206
+ * Only a push carrying a file past `warnAbove`, or `refuseAbove` with no warning, walks for paths,
207
+ * within `pathCallsShare` of its request's calls; any other reads nothing. The sizes alone decide.
208
+ */
209
+ const filesChecked = /* @__PURE__ */ Effect.fnUntraced(function* (files, received, pushed, tips) {
210
+ const largest = received?.largest ?? [];
211
+ const floor = files.warnAbove ?? files.refuseAbove;
212
+ const large = largest.filter((file) => file.size > floor);
213
+ if (large.length === 0) return [];
214
+ const partialAt = (told) => received?.largestPartial === true && told.length === largest.length;
215
+ const walk = yield* walkBudgetOf((yield* callScope).calls, pathCallsShare);
216
+ const paths = yield* pathsOf(pushed, tips, new Set(large.map((file) => file.oid)), walk);
217
+ const found = large.map((file) => ({
218
+ ...file,
219
+ place: paths.get(file.oid)
220
+ }));
221
+ const refused = found.filter((file) => file.size > files.refuseAbove);
222
+ if (refused.length > 0) return yield* Effect.fail(filesRefused(refused, files.refuseAbove, partialAt(refused)));
223
+ return files.warnAbove === void 0 ? [] : filesWarned(found, files.warnAbove, partialAt(found));
224
+ });
225
+ export { defaultPushFiles, filesChecked, filesRefused, filesWarned, pathCallsShare, pathWalkMost, pathsOf, pushFilesOf, shellWord, sized };
@@ -0,0 +1,8 @@
1
+ import "../contracts/objects.mjs";
2
+ import "../contracts/push-uploads.mjs";
3
+ import "../contracts/result.mjs";
4
+ /** A server's sizes for a repo a push lands in, `pushes.repo` resolved: each only when there's one. */
5
+ export interface PushRepo {
6
+ readonly warnAbove: number | undefined;
7
+ readonly refuseAbove: number | undefined;
8
+ }
@@ -0,0 +1,56 @@
1
+ import { gitError } from "../contracts/result.mjs";
2
+ import { sized } from "./push-files.mjs";
3
+ // src/core/push-repo.ts
4
+ /**
5
+ * Past it, a push is told on band 2 that its repo is large: `pushes.repo.warnAbove`'s default, 5 GiB
6
+ * (#2395). GitHub's, read 2026-11-30 at
7
+ * https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-large-files-on-github:
8
+ * "We recommend repositories remain small, ideally less than 1 GB, and less than 5 GB is strongly
9
+ * recommended." Its repository limits page measures a repo's size on disk as "the size of the
10
+ * `.git` folder", and neither page says whether Git LFS counts. `RepoStats.ownBytes` leaves it
11
+ * out. GitLab.com counts it: "Repository size including LFS - Free | 10 GiB". The wiki's
12
+ * `operations.md` quotes these, and changes with them.
13
+ */
14
+ const repoWarnBytes = 5 * 1024 ** 3;
15
+ /** GitHub's: a warning past 5 GiB, and no refusal. */
16
+ const defaultPushRepo = {
17
+ warnAbove: repoWarnBytes,
18
+ refuseAbove: void 0
19
+ };
20
+ /**
21
+ * `pushes.repo`, or a `TypeError` naming what's wrong: each size a whole number above 0, and
22
+ * `warnAbove` below `refuseAbove` when both are set.
23
+ */
24
+ const pushRepoOf = (given) => {
25
+ const warning = given?.warnAbove ?? repoWarnBytes;
26
+ const warnAbove = warning === false ? void 0 : warning;
27
+ const refuseAbove = given?.refuseAbove;
28
+ for (const [name, value] of [["warnAbove", warnAbove], ["refuseAbove", refuseAbove]]) if (value !== void 0 && (!Number.isSafeInteger(value) || value <= 0)) throw new TypeError(`pushes.repo.${name} must be a whole number above 0: got ${value}`);
29
+ if (warnAbove !== void 0 && refuseAbove !== void 0 && warnAbove >= refuseAbove) throw new TypeError(`pushes.repo.warnAbove must be below refuseAbove, ${refuseAbove}: got ${warnAbove}`);
30
+ return {
31
+ warnAbove,
32
+ refuseAbove
33
+ };
34
+ };
35
+ /**
36
+ * The bytes `change` adds to its repo's `ownBytes`: its packs', and `rows`, its object rows less
37
+ * those the repo holds already, as `rowsAtCommit` counts them, which a small push keeps as rows.
38
+ */
39
+ const addedBytes = (change, rows) => (change?.add ?? []).reduce((sum, pack) => sum + pack.bytes, rows.bytes);
40
+ /**
41
+ * A push to a repo of `ownBytes` that adds `added`, held to `repo`. Past `refuseAbove`, a push that
42
+ * adds bytes is refused, so one that only deletes or moves refs still lands. Past `warnAbove`,
43
+ * every push that lands is told, not only the one that crosses it.
44
+ */
45
+ const repoChecked = (repo, ownBytes, added) => {
46
+ const after = ownBytes + added;
47
+ if (repo.refuseAbove !== void 0 && added > 0 && after > repo.refuseAbove) return { refused: repoRefused(after, repo.refuseAbove) };
48
+ if (repo.warnAbove !== void 0 && after > repo.warnAbove) return { warned: [repoWarned(after, repo.warnAbove)] };
49
+ return { warned: [] };
50
+ };
51
+ const repoWarned = (after, warnAbove) => `warning: This repository is ${sized(after)}, past the ${sized(warnAbove)} this server recommends: track large files with Git LFS and keep history small`;
52
+ const repoRefused = (after, refuseAbove) => gitError("RESOURCE_EXHAUSTED", `This push would make the repository ${sized(after)}, past this server's limit of ${sized(refuseAbove)} for a repository`, {
53
+ hint: "Track large files with Git LFS, rewrite them out of history with git lfs migrate import, and push again",
54
+ context: { reason: "repo-too-large" }
55
+ });
56
+ export { addedBytes, defaultPushRepo, pushRepoOf, repoChecked, repoWarnBytes };
@@ -0,0 +1,17 @@
1
+ import "./parts.mjs";
2
+ import "../contracts/actors.mjs";
3
+ import "../contracts/events.mjs";
4
+ import "../contracts/ids.mjs";
5
+ import "../contracts/objects.mjs";
6
+ import "../contracts/client.mjs";
7
+ import "../contracts/git.mjs";
8
+ import "../contracts/refs.mjs";
9
+ import "../contracts/result.mjs";
10
+ import "../auth/fences.mjs";
11
+ import "../store/outbox.mjs";
12
+ import "../store/records.mjs";
13
+ import "../store/repo-record.mjs";
14
+ import "./access.mjs";
15
+ import "./receipts.mjs";
16
+ import "effect/Effect";
17
+ import { JobInput, Key, Row } from "@ref0/infra";