@ref0/git 0.14.0 → 0.20.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 (351) hide show
  1. package/dist/auth/access-jwt.mjs +2 -2
  2. package/dist/auth/authorize.mjs +3 -3
  3. package/dist/auth/fences.d.mts +1 -2
  4. package/dist/auth/fences.mjs +3 -3
  5. package/dist/auth/grants.mjs +4 -4
  6. package/dist/auth/host-function.mjs +18 -1
  7. package/dist/auth/identify.d.mts +1 -1
  8. package/dist/auth/identify.mjs +3 -3
  9. package/dist/auth/token-cleanup.mjs +67 -0
  10. package/dist/auth/token-rows.mjs +1 -1
  11. package/dist/auth/token-text.mjs +9 -1
  12. package/dist/auth/tokens-base.d.mts +35 -0
  13. package/dist/auth/tokens-base.mjs +13 -0
  14. package/dist/auth/tokens-layer.d.mts +2 -27
  15. package/dist/auth/tokens-layer.mjs +6 -11
  16. package/dist/auth/tokens-public.d.mts +3 -3
  17. package/dist/auth/tokens.d.mts +7 -10
  18. package/dist/auth/tokens.mjs +9 -80
  19. package/dist/client/answer.mjs +21 -42
  20. package/dist/client/client.d.mts +2 -4
  21. package/dist/client/git-http.mjs +17 -7
  22. package/dist/client/local.mjs +14 -13
  23. package/dist/client/push-upload.mjs +9 -8
  24. package/dist/client/remote.mjs +8 -10
  25. package/dist/client/run-remote-helper.d.mts +1 -0
  26. package/dist/client/run-remote-helper.mjs +58 -24
  27. package/dist/client/slice-push.d.mts +1 -1
  28. package/dist/client/transport.mjs +105 -46
  29. package/dist/contracts/blobs.d.mts +55 -8
  30. package/dist/contracts/blobs.mjs +16 -2
  31. package/dist/contracts/call-allowance.d.mts +13 -0
  32. package/dist/contracts/call-allowance.mjs +44 -0
  33. package/dist/contracts/calls-spent.mjs +8 -3
  34. package/dist/contracts/client.d.mts +15 -16
  35. package/dist/contracts/commits.d.mts +24 -24
  36. package/dist/contracts/engine.d.mts +6 -1
  37. package/dist/contracts/engine.mjs +10 -1
  38. package/dist/contracts/files.d.mts +10 -10
  39. package/dist/contracts/forks.d.mts +17 -17
  40. package/dist/contracts/git-events.d.mts +29 -1
  41. package/dist/contracts/git-hooks.d.mts +1 -1
  42. package/dist/contracts/git.d.mts +21 -0
  43. package/dist/contracts/grants.d.mts +24 -4
  44. package/dist/contracts/handlers.d.mts +1 -1
  45. package/dist/contracts/lfs.d.mts +28 -2
  46. package/dist/contracts/merges.d.mts +3 -2
  47. package/dist/contracts/objects.d.mts +23 -25
  48. package/dist/contracts/queue.d.mts +40 -12
  49. package/dist/contracts/queue.mjs +3 -4
  50. package/dist/contracts/refs.d.mts +26 -23
  51. package/dist/contracts/remote.d.mts +6 -7
  52. package/dist/contracts/remote.mjs +4 -1
  53. package/dist/contracts/repos.d.mts +29 -138
  54. package/dist/contracts/repos.mjs +5 -3
  55. package/dist/contracts/result.d.mts +35 -16
  56. package/dist/contracts/result.mjs +35 -7
  57. package/dist/contracts/server.d.mts +25 -50
  58. package/dist/contracts/services.d.mts +1 -1
  59. package/dist/contracts/store.d.mts +6 -5
  60. package/dist/contracts/sync.d.mts +11 -7
  61. package/dist/contracts/sync.mjs +12 -2
  62. package/dist/contracts/tags.d.mts +10 -10
  63. package/dist/contracts/time.d.mts +3 -0
  64. package/dist/contracts/{promises.mjs → time.mjs} +1 -1
  65. package/dist/contracts/tokens.d.mts +15 -17
  66. package/dist/contracts/tokens.mjs +3 -2
  67. package/dist/contracts/topics.d.mts +1 -1
  68. package/dist/contracts/trees.d.mts +12 -12
  69. package/dist/contracts/work.d.mts +24 -13
  70. package/dist/core/access.d.mts +1 -2
  71. package/dist/core/access.mjs +20 -9
  72. package/dist/core/ancestry.d.mts +1 -0
  73. package/dist/core/asked.mjs +1 -1
  74. package/dist/core/call-names.mjs +6 -1
  75. package/dist/core/call-services.mjs +11 -3
  76. package/dist/core/events/deliver.d.mts +1 -2
  77. package/dist/core/events/deliver.mjs +43 -36
  78. package/dist/core/events/retired.mjs +119 -0
  79. package/dist/core/forks.mjs +928 -432
  80. package/dist/core/hooks/groups.mjs +1 -1
  81. package/dist/core/imports.mjs +29 -23
  82. package/dist/core/index-job.mjs +122 -34
  83. package/dist/core/index-lost.d.mts +1 -2
  84. package/dist/core/index-lost.mjs +2 -2
  85. package/dist/core/loose-tally.mjs +1 -1
  86. package/dist/core/objects/blobs.mjs +129 -3
  87. package/dist/core/objects/lines.mjs +2 -2
  88. package/dist/core/objects/merges.mjs +4 -1
  89. package/dist/core/objects/objects-layer.d.mts +1 -1
  90. package/dist/core/objects/objects-layer.mjs +3 -3
  91. package/dist/core/objects/reading.mjs +24 -13
  92. package/dist/core/objects/tags.mjs +4 -1
  93. package/dist/core/objects/trees.mjs +2 -2
  94. package/dist/core/objects/writing.mjs +2 -2
  95. package/dist/core/own-writes.mjs +1 -1
  96. package/dist/core/parts.d.mts +4 -5
  97. package/dist/core/parts.mjs +3 -8
  98. package/dist/core/promise.mjs +9 -12
  99. package/dist/core/purge.mjs +287 -83
  100. package/dist/core/push-decide.mjs +2 -0
  101. package/dist/core/push-files.d.mts +1 -1
  102. package/dist/core/push.mjs +58 -47
  103. package/dist/core/receipts.mjs +8 -3
  104. package/dist/core/ref-index-job.mjs +4 -4
  105. package/dist/core/ref-view.mjs +2 -2
  106. package/dist/core/refs.mjs +5 -5
  107. package/dist/core/registered-rows.mjs +2 -2
  108. package/dist/core/repack.mjs +36 -21
  109. package/dist/core/repo-info.mjs +3 -3
  110. package/dist/core/repos.mjs +21 -9
  111. package/dist/core/rules/commit-changes.d.mts +0 -1
  112. package/dist/core/saved-caller-views.d.mts +7 -2
  113. package/dist/core/saved-caller-views.mjs +2 -2
  114. package/dist/core/saved-callers.d.mts +19 -2
  115. package/dist/core/seam.d.mts +16 -26
  116. package/dist/core/seam.mjs +7 -28
  117. package/dist/core/tokens.mjs +1 -1
  118. package/dist/core/view.mjs +7 -15
  119. package/dist/core/work.mjs +59 -14
  120. package/dist/effect.d.mts +3 -12
  121. package/dist/effect.mjs +1 -10
  122. package/dist/engine/failures.mjs +2 -1
  123. package/dist/engine/reads.mjs +4 -4
  124. package/dist/event-streams/stream.d.mts +2 -2
  125. package/dist/event-streams/stream.mjs +37 -14
  126. package/dist/extend.d.mts +2 -3
  127. package/dist/extend.mjs +2 -1
  128. package/dist/http/answers.mjs +8 -5
  129. package/dist/http/core-parts.mjs +95 -79
  130. package/dist/http/handler.mjs +34 -7
  131. package/dist/http/node.d.mts +14 -1
  132. package/dist/http/node.mjs +56 -27
  133. package/dist/http/parts.d.mts +1 -0
  134. package/dist/http/push-upload-job.mjs +30 -26
  135. package/dist/http/push-uploads.mjs +36 -21
  136. package/dist/http/upload-pack.mjs +3 -3
  137. package/dist/index.d.mts +14 -14
  138. package/dist/index.mjs +2 -2
  139. package/dist/lfs/answer.mjs +37 -0
  140. package/dist/lfs/base.d.mts +2 -0
  141. package/dist/lfs/base.mjs +25 -1
  142. package/dist/lfs/copy.d.mts +21 -7
  143. package/dist/lfs/copy.mjs +89 -6
  144. package/dist/lfs/layer.d.mts +15 -1
  145. package/dist/lfs/layer.mjs +24 -11
  146. package/dist/lfs/locks.mjs +2 -2
  147. package/dist/lfs/objects.d.mts +1 -0
  148. package/dist/lfs/objects.mjs +87 -17
  149. package/dist/lfs/pointers.mjs +2 -2
  150. package/dist/lfs/rows.mjs +42 -8
  151. package/dist/lfs/upkeep.mjs +48 -14
  152. package/dist/lfs/wire.mjs +6 -31
  153. package/dist/merges/merges.mjs +2 -2
  154. package/dist/node.d.mts +2 -2
  155. package/dist/protocol/bytes/buffers.mjs +13 -5
  156. package/dist/protocol/bytes/reader.mjs +6 -1
  157. package/dist/protocol/bytes/streams.mjs +27 -1
  158. package/dist/protocol/diff/read.d.mts +4 -3
  159. package/dist/protocol/diff/read.mjs +8 -3
  160. package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
  161. package/dist/protocol/objects/lfs-pointer.mjs +1 -3
  162. package/dist/protocol/objects/links-raw.mjs +24 -10
  163. package/dist/protocol/objects/tag.d.mts +1 -1
  164. package/dist/protocol/objects/tree.mjs +23 -6
  165. package/dist/protocol/packs/delta.d.mts +6 -3
  166. package/dist/protocol/packs/delta.mjs +96 -32
  167. package/dist/protocol/packs/idx.d.mts +2 -1
  168. package/dist/protocol/packs/idx.mjs +22 -3
  169. package/dist/protocol/packs/parts.d.mts +4 -1
  170. package/dist/protocol/packs/parts.mjs +10 -7
  171. package/dist/protocol/packs/reader.d.mts +5 -0
  172. package/dist/protocol/packs/reader.mjs +3 -2
  173. package/dist/protocol/packs/writer.mjs +26 -8
  174. package/dist/queue/advance.mjs +21 -24
  175. package/dist/queue/base.d.mts +55 -0
  176. package/dist/queue/base.mjs +44 -0
  177. package/dist/queue/calls.mjs +51 -54
  178. package/dist/queue/commit.mjs +1 -1
  179. package/dist/queue/host.d.mts +1 -15
  180. package/dist/queue/host.mjs +2 -7
  181. package/dist/queue/layer.d.mts +2 -1
  182. package/dist/queue/layer.mjs +10 -3
  183. package/dist/queue/limits.mjs +2 -0
  184. package/dist/queue/push-option.mjs +9 -24
  185. package/dist/queue/schedule.mjs +1 -1
  186. package/dist/queue/state.mjs +2 -10
  187. package/dist/queue/trim.mjs +5 -3
  188. package/dist/rest/blobs.mjs +29 -5
  189. package/dist/rest/caller.d.mts +4 -4271
  190. package/dist/rest/caller.mjs +4 -0
  191. package/dist/rest/client.d.mts +8 -5
  192. package/dist/rest/client.mjs +19 -2
  193. package/dist/rest/handlers.mjs +50 -5
  194. package/dist/rest/layer.d.mts +2 -2
  195. package/dist/rest/layer.mjs +5 -12
  196. package/dist/rest/me.d.mts +3 -432
  197. package/dist/server/check-fetch.mjs +3 -3
  198. package/dist/server/edge-node.d.mts +11 -8
  199. package/dist/server/edge-node.mjs +9 -6
  200. package/dist/server/edge.d.mts +21 -7
  201. package/dist/server/edge.mjs +32 -11
  202. package/dist/server/extension.mjs +1 -1
  203. package/dist/server/git-layer.d.mts +5 -5
  204. package/dist/server/git-layer.mjs +28 -22
  205. package/dist/server/git-namespace.d.mts +4 -3
  206. package/dist/server/git-namespace.mjs +3 -2
  207. package/dist/server/joined.d.mts +6 -18
  208. package/dist/server/joined.mjs +9 -36
  209. package/dist/server/lifecycle.mjs +18 -106
  210. package/dist/server/registry.mjs +24 -7
  211. package/dist/server/server.mjs +205 -346
  212. package/dist/signin/context.d.mts +1 -2
  213. package/dist/signin/layer.d.mts +1 -1
  214. package/dist/signin/layer.mjs +1 -1
  215. package/dist/storage/allotted.mjs +18 -3
  216. package/dist/storage/batch-upkeep.mjs +274 -0
  217. package/dist/storage/batches.d.mts +8 -0
  218. package/dist/storage/batches.mjs +344 -0
  219. package/dist/storage/calls.d.mts +1 -2
  220. package/dist/storage/calls.mjs +144 -158
  221. package/dist/storage/chunks.d.mts +9 -0
  222. package/dist/storage/chunks.mjs +297 -0
  223. package/dist/storage/clean-up.mjs +72 -9
  224. package/dist/storage/counted-bucket.mjs +4 -4
  225. package/dist/storage/fetch.d.mts +1 -0
  226. package/dist/storage/fetch.mjs +287 -210
  227. package/dist/storage/host-bucket.mjs +1 -2
  228. package/dist/storage/id-mix.mjs +19 -5
  229. package/dist/storage/index-bitmaps.mjs +9 -2
  230. package/dist/storage/index-build.d.mts +0 -1
  231. package/dist/storage/index-build.mjs +80 -23
  232. package/dist/storage/index-fetch.mjs +113 -72
  233. package/dist/storage/index-files.d.mts +3 -0
  234. package/dist/storage/index-files.mjs +10 -5
  235. package/dist/storage/index-graph.mjs +72 -22
  236. package/dist/storage/index-remap.mjs +200 -64
  237. package/dist/storage/index-whole.mjs +127 -0
  238. package/dist/storage/largest-files.mjs +1 -1
  239. package/dist/storage/layout.mjs +23 -0
  240. package/dist/storage/loose.d.mts +7 -4
  241. package/dist/storage/loose.mjs +212 -67
  242. package/dist/storage/memory-budget.mjs +16 -4
  243. package/dist/storage/merge-plan.mjs +3 -2
  244. package/dist/storage/merge-row.mjs +7 -1
  245. package/dist/storage/merge-stream.mjs +164 -25
  246. package/dist/storage/merge-walk.mjs +8 -4
  247. package/dist/storage/merge-write.mjs +1 -1
  248. package/dist/storage/merge.d.mts +1 -1
  249. package/dist/storage/merge.mjs +1 -1
  250. package/dist/storage/object-rows.d.mts +1 -0
  251. package/dist/storage/object-rows.mjs +385 -65
  252. package/dist/storage/oid-table.mjs +171 -0
  253. package/dist/storage/pack-order.mjs +8 -4
  254. package/dist/storage/pack-ranges.d.mts +1 -2
  255. package/dist/storage/pack-ranges.mjs +4 -5
  256. package/dist/storage/pack-reads.d.mts +2 -1
  257. package/dist/storage/pack-reads.mjs +158 -42
  258. package/dist/storage/pack-receive.d.mts +1 -1
  259. package/dist/storage/pack-receive.mjs +2 -2
  260. package/dist/storage/packs.d.mts +1 -1
  261. package/dist/storage/packs.mjs +136 -66
  262. package/dist/storage/placed-reads.mjs +1 -1
  263. package/dist/storage/plan-columns.d.mts +4 -0
  264. package/dist/storage/plan-columns.mjs +238 -0
  265. package/dist/storage/prune-keep.mjs +134 -41
  266. package/dist/storage/prune-walk.mjs +202 -62
  267. package/dist/storage/prune.mjs +194 -91
  268. package/dist/storage/push-allotment.mjs +91 -12
  269. package/dist/storage/push-uploads.mjs +4 -4
  270. package/dist/storage/pushed-commits.mjs +4 -2
  271. package/dist/storage/quarantine.d.mts +1 -1
  272. package/dist/storage/range-cache.mjs +125 -8
  273. package/dist/storage/ready.d.mts +1 -1
  274. package/dist/storage/ready.mjs +8 -6
  275. package/dist/storage/receive-bounds.mjs +23 -8
  276. package/dist/storage/repack-backlog.mjs +6 -3
  277. package/dist/storage/repack.d.mts +1 -1
  278. package/dist/storage/rows.d.mts +1 -1
  279. package/dist/storage/rows.mjs +1 -1
  280. package/dist/storage/runs.mjs +195 -43
  281. package/dist/storage/send-list.d.mts +1 -0
  282. package/dist/storage/send-list.mjs +54 -10
  283. package/dist/storage/single-flight.mjs +13 -7
  284. package/dist/storage/stream-whole.mjs +127 -26
  285. package/dist/storage/unpack.mjs +371 -79
  286. package/dist/storage/visible.mjs +2 -2
  287. package/dist/storage/walk.mjs +192 -38
  288. package/dist/storage/wants.mjs +5 -5
  289. package/dist/store/bodies.mjs +38 -0
  290. package/dist/store/call-count.d.mts +8 -12
  291. package/dist/store/call-count.mjs +34 -46
  292. package/dist/store/catalogue.d.mts +2 -2
  293. package/dist/store/catalogue.mjs +145 -35
  294. package/dist/store/crossing.mjs +1 -3
  295. package/dist/store/cursor-seal.d.mts +1 -2
  296. package/dist/store/cursor-seal.mjs +16 -6
  297. package/dist/store/door.mjs +183 -0
  298. package/dist/store/errors.d.mts +3 -4
  299. package/dist/store/errors.mjs +15 -33
  300. package/dist/store/git-store.mjs +25 -7
  301. package/dist/store/job-try.mjs +9 -32
  302. package/dist/store/list-job.mjs +44 -8
  303. package/dist/store/records.d.mts +3 -0
  304. package/dist/store/records.mjs +3 -0
  305. package/dist/store/repo-record.d.mts +1 -2
  306. package/dist/store/repo-record.mjs +32 -20
  307. package/dist/store/reservations.mjs +1 -1
  308. package/dist/store/scopes.mjs +11 -0
  309. package/dist/store/settle.mjs +4 -4
  310. package/dist/sync/github.mjs +3 -3
  311. package/dist/sync/import.mjs +31 -18
  312. package/dist/sync/lfs-batch.mjs +4 -5
  313. package/dist/sync/lfs-copy.mjs +17 -6
  314. package/dist/sync/mirror.mjs +34 -31
  315. package/dist/sync/said.mjs +16 -37
  316. package/dist/sync/step.mjs +33 -25
  317. package/dist/sync/tries.mjs +9 -9
  318. package/dist/topics/advance.mjs +10 -11
  319. package/dist/topics/base.d.mts +15 -0
  320. package/dist/topics/base.mjs +8 -0
  321. package/dist/topics/host.mjs +1 -1
  322. package/dist/topics/layer.d.mts +4 -9
  323. package/dist/topics/layer.mjs +2 -3
  324. package/dist/topics/members.mjs +4 -4
  325. package/dist/topics/public.d.mts +2 -1
  326. package/dist/topics/topic.mjs +2 -2
  327. package/package.json +5 -4
  328. package/dist/contracts/promises.d.mts +0 -39
  329. package/dist/core/call-names.d.mts +0 -3
  330. package/dist/core/clock.mjs +0 -18
  331. package/dist/lfs/calls.mjs +0 -26
  332. package/dist/rest/api.d.mts +0 -23
  333. package/dist/rest/blobs.d.mts +0 -833
  334. package/dist/rest/commits.d.mts +0 -3543
  335. package/dist/rest/errors.d.mts +0 -2124
  336. package/dist/rest/events.d.mts +0 -426
  337. package/dist/rest/files.d.mts +0 -1342
  338. package/dist/rest/forks.d.mts +0 -2160
  339. package/dist/rest/handlers.d.mts +0 -8
  340. package/dist/rest/merges.d.mts +0 -477
  341. package/dist/rest/queue.d.mts +0 -5917
  342. package/dist/rest/refs.d.mts +0 -2988
  343. package/dist/rest/repos.d.mts +0 -2567
  344. package/dist/rest/tags.d.mts +0 -1316
  345. package/dist/rest/tokens.d.mts +0 -2614
  346. package/dist/rest/topics.d.mts +0 -2224
  347. package/dist/rest/trees.d.mts +0 -1709
  348. package/dist/rest/work.d.mts +0 -1695
  349. package/dist/server/lifecycle.d.mts +0 -2
  350. package/dist/store/promises.d.mts +0 -11
  351. package/dist/store/promises.mjs +0 -327
@@ -2,7 +2,7 @@ import { gitError } from "../contracts/result.mjs";
2
2
  import { hexOf } from "../protocol/bytes/hex.mjs";
3
3
  import { Sha1 } from "../protocol/bytes/sha1.mjs";
4
4
  import { answerSpent, pastCallLimit } from "../store/errors.mjs";
5
- import { copyHeldBytes, isMergeIncomplete, mergeIncomplete } from "./index-bitmaps.mjs";
5
+ import { copyHeldBytes, isKeepUnclosed, isMergeIncomplete, mergeIncomplete } from "./index-bitmaps.mjs";
6
6
  import { belowGraphs, copyMergedBitmaps, coveredPacks, indexRowOf, mergeCallsAfterOpen, mergeChunk, newBuildId, putOnce, wordsOf } from "./index-build.mjs";
7
7
  import { BasesWriter, TypesWriter, indexBasesBytes, indexTypesBytes, openBases, openTypes, typeCodes } from "./index-files.mjs";
8
8
  import { mergeHeldBytes, mergeIndexGraphs } from "./index-graph.mjs";
@@ -14,13 +14,15 @@ import { spentIn } from "../contracts/calls-spent.mjs";
14
14
  import { startPut } from "./merge.mjs";
15
15
  import { writeOrder } from "./merge-choose.mjs";
16
16
  import { openRanges, rangeRanks, readExactly } from "./pack-ranges.mjs";
17
- import { compareIds } from "./raw-ids.mjs";
17
+ import { hasBit, setBit } from "./prune-keep.mjs";
18
+ import { compareIds, orderById } from "./raw-ids.mjs";
18
19
  import * as Effect from "effect/Effect";
19
20
  // src/storage/index-remap.ts
20
21
  /**
21
22
  * The plan of a remap of `layers` once a merge takes `merged`'s packs, of `objects` objects in
22
- * all: `undefined` when it can't remap, as when a merged pack isn't one the row covers, or a
23
- * covered pack isn't listed. `listed` is the listing before the merge.
23
+ * all, 0 for packs a prune step empties with no merge: `undefined` when it can't remap, as when a
24
+ * merged pack isn't one the row covers, or a covered pack isn't listed. `listed` is the listing
25
+ * before the merge.
24
26
  */
25
27
  const remapPlan = (layers, listed, merged, objects) => {
26
28
  const counts = new Map(listed.packs.map((pack) => [pack.id, pack.objects]));
@@ -87,24 +89,38 @@ const keptRowBytes = 64;
87
89
  * planned: the map, 4 bytes a tail position, with the tail's IDs, the rows kept and their join;
88
90
  * then the map through the graph merge's and the copy's, with every bitmap's entry,
89
91
  * `mergeEntryBytes`; or `.bases`' rows, the old and the new, with each row's code and a chunk of
90
- * `.types`.
92
+ * `.types`. A merge that `keeps` adds a bit a tail position, the IDs it dropped as they're built
93
+ * beside the tail's and then beside the graph merge's, and the bitmaps' copy beside both, since
94
+ * it runs before the graph's file finishes.
91
95
  */
92
- const remapHeldMost = (plan, layers, objects) => {
96
+ const remapHeldMost = (plan, layers, objects, keeps = false) => {
93
97
  const tail = plan.positions - plan.prefix;
94
98
  const positions = plan.prefix + tail + objects;
95
99
  const commits = layers.reduce((sum, layer) => sum + layer.commits, 0);
96
100
  const bitmaps = layers.reduce((sum, layer) => sum + layer.bitmaps, 0);
97
101
  const deltas = layers.reduce((sum, layer) => sum + layer.deltas, 0);
98
102
  const files = layers.map((layer) => layer.first + layer.positions);
99
- const map = tail * 4;
103
+ const map = tail * 4 + (keeps ? Math.ceil(tail / 8) : 0);
104
+ const taken = plan.tail.reduce((sum, pack) => sum + (pack.next === void 0 ? pack.objects : 0), 0);
105
+ const dropped = keeps ? Math.max(0, taken - objects) : 0;
106
+ const ids = map + tail * 20 + joinBytes(tail) + plan.rows * keptRowBytes;
107
+ const graph = commits * 4 + mergeHeldBytes(layers.length);
108
+ const copy = bitmaps * 640 + copyHeldBytes(positions, bitmaps, files);
100
109
  const phases = [
101
- map + tail * 20 + joinBytes(tail) + plan.rows * keptRowBytes,
102
- map + commits * 4 + mergeHeldBytes(layers.length),
103
- map + bitmaps * 640 + copyHeldBytes(positions, bitmaps, files),
110
+ ids + goneBuildBytes(dropped),
111
+ map + goneHeldBytes(dropped) + graph,
112
+ map + (keeps ? goneHeldBytes(dropped) + graph : 0) + copy,
104
113
  map + bitmaps * 640 + deltas * 16 + objects * 8 + plan.rows * 112 + mergeChunk * 9
105
114
  ];
106
115
  return Math.max(...phases);
107
116
  };
117
+ /**
118
+ * What `goneIds` holds as it builds `count` dropped IDs: theirs twice, gathered then sorted, their
119
+ * order, and `orderById`'s two tables of counts.
120
+ */
121
+ const goneBuildBytes = (count) => count === 0 ? 0 : count * 44 + 524292;
122
+ /** What the sorted dropped IDs hold once built, through the graph merge. */
123
+ const goneHeldBytes = (count) => count * 20;
108
124
  /** Where `layers` hold an old position: its layer and its place there. */
109
125
  const layerAt = (layers, position) => layers.find((layer) => position >= layer.first && position < layer.first + layer.positions);
110
126
  /** The `.types` parts `oldTypes` reads over old positions `[from, to)`: one a layer or chunk. */
@@ -152,6 +168,8 @@ const defaultRemapCpuMost = 3e4;
152
168
  const remapUnits = (plan, layers) => layers.reduce((sum, layer) => sum + layer.bitmaps, 0) * (plan.positions - plan.prefix);
153
169
  /** Whether a remap's CPU, its units at `remapNsPerUnit`, would pass `cpuMost` ms. */
154
170
  const remapCpuPast = (units, cpuMost) => units * 26 > Math.round(cpuMost * 1e6);
171
+ /** The objects `merged` lays in the tail: its pack's, or none for packs emptied. */
172
+ const mergedObjects = (merged) => merged.kind === "pack" ? merged.pack.objects : 0;
155
173
  /**
156
174
  * The calls a remap makes past its graphs' heads: `remapCalls` with a layer merge's reads of
157
175
  * graphs of `octopus` table entries each, its `.bitmaps` over the merged pack's positions too, in
@@ -201,17 +219,31 @@ const remapPast = (input) => {
201
219
  const layers = row.layers;
202
220
  if (remapCpuPast(remapUnits(plan, layers), input.cpuMost)) return "cpu";
203
221
  if (input.lease !== void 0 && input.lease >= input.grace) return "lease";
204
- if (pastCallsLeft(input.calls, remapCallsMost(plan, layers, merged.pack.objects, input.bucket.multipart))) return "calls";
205
- const held = remapHeldMost(plan, layers, merged.pack.objects);
222
+ if (pastCallsLeft(input.calls, remapCallsMost(plan, layers, mergedObjects(merged), input.bucket.multipart))) return "calls";
223
+ const held = remapHeldMost(plan, layers, mergedObjects(merged), input.keeps !== void 0);
206
224
  if (!input.allotment.tryGrow(held)) return "memory";
207
225
  input.allotment.shrink(held);
208
226
  };
227
+ /**
228
+ * Whether a remap fits, from its plan and the merge alone, before any read: `'cpu'` when its CPU
229
+ * passes `cpuMost`, which no try changes, and `'calls'` when `before`, its own calls at most and
230
+ * the listing's commit pass what the try has left, as `remapPast` weighs them. A resumed merge
231
+ * whose remap fits a fresh try, but not what its last try has left, saves for the next (#2196).
232
+ */
233
+ const remapFits = (fit) => {
234
+ const { plan, layers } = fit;
235
+ if (remapCpuPast(remapUnits(plan, layers), fit.cpuMost)) return "cpu";
236
+ const needs = (fit.before ?? 0) + remapCallsMost(plan, layers, fit.objects, fit.multipart);
237
+ return pastCallsLeft(fit.calls, needs) ? "calls" : void 0;
238
+ };
209
239
  const lost = (message) => gitError("DATA_LOSS", message);
210
240
  /**
211
241
  * A remap's decline, one line in the log with its cause, so a bound it always passes shows as a
212
242
  * pattern: then the merge commits alone, and the next `git.index` builds again.
213
243
  */
214
244
  const declined = (repo, cause) => Effect.logWarning(`git.repack's remap of repo ${repo} declined, ${cause}`).pipe(Effect.as(void 0));
245
+ /** A remap's decline past a bound `remapPast` weighs, as `remapIndex` logs it. */
246
+ const declinedPast = (repo, past) => declined(repo, `past its ${past} bound`);
215
247
  /** A remap's allotment's refusal to grow, its own, so `remapFailure` tells it from another's. */
216
248
  const remapBusy = /* @__PURE__ */ gitError("UNAVAILABLE", "A repack's remap couldn't grow its allotment", { context: { reason: "busy" } });
217
249
  /**
@@ -257,20 +289,26 @@ const mergedRanges = (bucket, pack, base) => Effect.map(mergedOwn(rangesOf(bucke
257
289
  });
258
290
  /**
259
291
  * Each tail position's ID, by its old position, and the rows the merge left: theirs from each
260
- * run's region, by ID, each with its old position. `undefined` when a folded row isn't one the
261
- * row held.
292
+ * run's region, by ID, each with its old position. With `input.keeps`, the tail positions the
293
+ * merge dropped too, a bit each. `undefined` when a folded row isn't one the row held.
262
294
  */
263
295
  const tailIds = /* @__PURE__ */ Effect.fnUntraced(function* (input, old) {
264
296
  const { bucket, listed, plan } = input;
265
297
  const tail = plan.positions - plan.prefix;
266
298
  const ids = new Uint8Array(tail * 20);
267
- for (const ranges of old) for (let rank = 0; rank < ranges.count; rank += rangeRanks) {
268
- const count = Math.min(rangeRanks, ranges.count - rank);
269
- const chunk = yield* ranges.ids(rank, count);
270
- const positions = yield* ranges.positions(rank, count);
271
- for (let at = 0; at < count; at += 1) {
272
- const place = ranges.base + (positions[at] ?? 0) - plan.prefix;
273
- ids.set(chunk.subarray(at * 20, at * 20 + 20), place * 20);
299
+ const dropped = input.keeps === void 0 ? void 0 : new Uint8Array(Math.ceil(tail / 8));
300
+ for (const [index, ranges] of old.entries()) {
301
+ const pack = plan.tail[index];
302
+ const keeps = pack?.next === void 0 ? input.keeps : void 0;
303
+ for (let rank = 0; rank < ranges.count; rank += rangeRanks) {
304
+ const count = Math.min(rangeRanks, ranges.count - rank);
305
+ const chunk = yield* ranges.ids(rank, count);
306
+ const positions = yield* ranges.positions(rank, count);
307
+ for (let at = 0; at < count; at += 1) {
308
+ const place = ranges.base + (positions[at] ?? 0) - plan.prefix;
309
+ ids.set(chunk.subarray(at * 20, at * 20 + 20), place * 20);
310
+ if (dropped !== void 0 && keeps?.(pack?.id ?? "", rank + at) === false) setBit(dropped, place);
311
+ }
274
312
  }
275
313
  }
276
314
  const folded = new Set(input.folded);
@@ -293,13 +331,52 @@ const tailIds = /* @__PURE__ */ Effect.fnUntraced(function* (input, old) {
293
331
  kept.sort((a, b) => compareIds(a.id, 0, b.id, 0));
294
332
  return {
295
333
  ids,
296
- kept
334
+ kept,
335
+ dropped
297
336
  };
298
337
  });
299
- /** A bitmap's bits moved: the prefix's words as they were, each tail bit through `map`. */
338
+ /** How many tail positions `map` leaves `missing`: the objects the merge dropped. */
339
+ const goneCount = (map) => {
340
+ let count = 0;
341
+ for (const to of map) if (to === 4294967295) count += 1;
342
+ return count;
343
+ };
344
+ /**
345
+ * The IDs of the `count` tail positions `map` leaves `missing`, the ones the merge dropped, in ID
346
+ * order, for the graph merge to leave out.
347
+ */
348
+ const goneIds = (ids, map, count) => {
349
+ const gone = new Uint8Array(count * 20);
350
+ let at = 0;
351
+ for (const [place, to] of map.entries()) if (to === 4294967295) {
352
+ gone.set(ids.subarray(place * 20, place * 20 + 20), at * 20);
353
+ at += 1;
354
+ }
355
+ const sorted = new Uint8Array(count * 20);
356
+ for (const [to, from] of orderById(gone, count).entries()) sorted.set(gone.subarray(from * 20, from * 20 + 20), to * 20);
357
+ return sorted;
358
+ };
359
+ /** Whether `sorted`, IDs in order, holds the one at `offset` of `ids`. */
360
+ const holdsId = (sorted, ids, offset) => {
361
+ let low = 0;
362
+ let high = sorted.length / 20;
363
+ while (low < high) {
364
+ const middle = low + high >>> 1;
365
+ const order = compareIds(sorted, middle * 20, ids, offset);
366
+ if (order === 0) return true;
367
+ if (order < 0) low = middle + 1;
368
+ else high = middle;
369
+ }
370
+ return false;
371
+ };
372
+ /**
373
+ * A bitmap's bits moved: the prefix's words as they were, each tail bit through `map`. `false`
374
+ * when a bit is at a position `map` leaves `missing`, one the merge dropped.
375
+ */
300
376
  const movedBits = (prefix, map) => (bits, into) => {
301
377
  const whole = prefix >>> 5;
302
378
  into.set(bits.subarray(0, Math.min(whole, into.length)));
379
+ let placed = true;
303
380
  for (let word = whole; word < bits.length; word += 1) {
304
381
  let left = bits[word] ?? 0;
305
382
  while (left !== 0) {
@@ -307,9 +384,11 @@ const movedBits = (prefix, map) => (bits, into) => {
307
384
  left ^= low;
308
385
  const position = word * 32 + (31 - Math.clz32(low));
309
386
  const to = position < prefix ? position : map[position - prefix] ?? 4294967295;
310
- if (to !== 4294967295) into[to >>> 5] = (into[to >>> 5] ?? 0) | 1 << (to & 31);
387
+ if (to === 4294967295) placed = false;
388
+ else into[to >>> 5] = (into[to >>> 5] ?? 0) | 1 << (to & 31);
311
389
  }
312
390
  }
391
+ return placed;
313
392
  };
314
393
  /** Each layer's `.types`, its header read and checked once a remap, as a layer merge opens it. */
315
394
  const layerTypes = (input) => {
@@ -356,11 +435,12 @@ const oldBases = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
356
435
  /**
357
436
  * The remapped `.bases` rows: the prefix's as they were; the merged pack's, from its own plan,
358
437
  * past the prefix; and each other tail pack's, moved as its pack is. A row of a merged pack is
359
- * gone, its pack's objects the merged pack's now.
438
+ * gone, its pack's objects the merged pack's now, or gone with them when they're emptied.
360
439
  */
361
440
  const remappedBases = (input, old) => {
362
441
  const { plan, merged } = input;
363
- const out = new Uint32Array(old.length + merged.bases.length);
442
+ const own = merged.kind === "pack" ? merged.bases : /* @__PURE__ */ new Uint32Array(0);
443
+ const out = new Uint32Array(old.length + own.length);
364
444
  let length = 0;
365
445
  const push = (position, base) => {
366
446
  out[length] = position;
@@ -368,7 +448,7 @@ const remappedBases = (input, old) => {
368
448
  length += 2;
369
449
  };
370
450
  for (let at = 0; at < old.length && (old[at] ?? 0) < plan.prefix; at += 2) push(old[at] ?? 0, old[at + 1] ?? 0);
371
- for (let at = 0; at < merged.bases.length; at += 2) push((merged.bases[at] ?? 0) + plan.prefix, (merged.bases[at + 1] ?? 0) + plan.prefix);
451
+ for (let at = 0; at < own.length; at += 2) push((own[at] ?? 0) + plan.prefix, (own[at + 1] ?? 0) + plan.prefix);
372
452
  for (let at = 0; at < old.length; at += 2) {
373
453
  const position = old[at] ?? 0;
374
454
  const pack = plan.tail.find((each) => position >= each.old && position < each.old + each.objects);
@@ -393,25 +473,26 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
393
473
  if (past !== void 0) return yield* declined(listed.repo, `past its ${past} bound`);
394
474
  const graphs = yield* belowGraphs(bucket, listed.repo, layers);
395
475
  const octopus = graphs.map((graph) => graph.octopus);
396
- if (pastCallsLeft(input.calls, callsAfterHeads(plan, layers, merged.pack.objects, octopus, bucket.multipart))) return yield* declined(listed.repo, "past its calls bound, with its graphs' octopus tables");
476
+ if (pastCallsLeft(input.calls, callsAfterHeads(plan, layers, mergedObjects(merged), octopus, bucket.multipart))) return yield* declined(listed.repo, "past its calls bound, with its graphs' octopus tables");
397
477
  const build = newBuildId();
398
478
  const files = indexFiles(listed.repo, build);
399
- const objects = merged.pack.objects;
479
+ const objects = mergedObjects(merged);
400
480
  const positions = plan.prefix + tailOf(plan, objects, input.folded.length);
401
481
  const tail = plan.positions - plan.prefix;
402
482
  const bytesOf = new Map(listed.packs.map((pack) => [pack.id, pack.bytes]));
403
- yield* allotment.grow(tail * 4);
483
+ const map4 = tail * 4 + (input.keeps === void 0 ? 0 : Math.ceil(tail / 8));
484
+ yield* allotment.grow(map4);
404
485
  yield* allotment.grow(tail * 20 + joinBytes(tail));
405
486
  const old = yield* Effect.forEach(plan.tail, (pack) => rangesOf(bucket, pack.id, pack.objects, bytesOf.get(pack.id) ?? 0, pack.old));
406
487
  const read = yield* tailIds(input, old);
407
488
  if (read === void 0) {
408
- allotment.shrink(tail * 24 + joinBytes(tail));
489
+ allotment.shrink(map4 + tail * 20 + joinBytes(tail));
409
490
  return yield* declined(listed.repo, "a row the merge folded isn't one the row held");
410
491
  }
411
492
  const rowsFirst = positions - read.kept.length;
412
493
  const regionIds = new Uint8Array(read.kept.length * 20);
413
494
  for (const [at, each] of read.kept.entries()) regionIds.set(each.id, at * 20);
414
- const next = [yield* mergedRanges(bucket, merged.pack, plan.prefix), ...plan.tail.flatMap((pack, at) => {
495
+ const next = [...merged.kind === "pack" ? [yield* mergedRanges(bucket, merged.pack, plan.prefix)] : [], ...plan.tail.flatMap((pack, at) => {
415
496
  const ranges = old[at];
416
497
  return pack.next === void 0 || ranges === void 0 ? [] : [{
417
498
  ...ranges,
@@ -423,17 +504,12 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
423
504
  positions: Uint32Array.from(read.kept, (_, at) => rowsFirst + at)
424
505
  };
425
506
  const map = yield* joinIds(read.ids, tail, next, region);
426
- allotment.shrink(tail * 20 + joinBytes(tail));
427
- if (map.includes(4294967295)) return yield* Effect.fail(mergeIncomplete("The merge left a tail object out"));
428
- const { commits } = yield* mergeIndexGraphs({
429
- bucket,
430
- graphs,
431
- key: files.graph,
432
- allotment
433
- });
434
- const entries = layers.reduce((sum, layer) => sum + layer.bitmaps, 0) * 640;
435
- yield* allotment.grow(entries);
436
- const stored = yield* openLayerBitmaps(bucket, listed.repo, layers);
507
+ const { dropped } = read;
508
+ if (map.some((to, at) => to === 4294967295 && (dropped === void 0 || !hasBit(dropped, at)))) return yield* Effect.fail(mergeIncomplete("The merge left a tail object out"));
509
+ const count = goneCount(map);
510
+ yield* allotment.grow(goneBuildBytes(count));
511
+ const gone = count === 0 ? void 0 : goneIds(read.ids, map, count);
512
+ allotment.shrink(tail * 20 + joinBytes(tail) + goneBuildBytes(count) - goneHeldBytes(count));
437
513
  const move = {
438
514
  bits: movedBits(plan.prefix, map),
439
515
  position: (at) => {
@@ -441,15 +517,46 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
441
517
  return to === 4294967295 ? void 0 : to;
442
518
  }
443
519
  };
444
- const bitmaps = yield* copyMergedBitmaps({
445
- bucket,
446
- graphs,
447
- files,
448
- positions,
449
- kept: stored.entries,
450
- allotment,
451
- move
520
+ const copy = Effect.fnUntraced(function* (renumbered) {
521
+ const entries = layers.reduce((sum, layer) => sum + layer.bitmaps, 0) * 640;
522
+ yield* allotment.grow(entries);
523
+ const stored = yield* openLayerBitmaps(bucket, listed.repo, layers);
524
+ return {
525
+ entries,
526
+ bitmaps: yield* copyMergedBitmaps({
527
+ bucket,
528
+ graphs,
529
+ files,
530
+ positions,
531
+ kept: stored.entries.filter(({ entry }) => move.position(entry.position) !== void 0),
532
+ allotment,
533
+ move,
534
+ renumbered
535
+ })
536
+ };
452
537
  });
538
+ const copied = yield* Effect.gen(function* () {
539
+ const early = [];
540
+ const { commits } = yield* mergeIndexGraphs({
541
+ bucket,
542
+ graphs,
543
+ key: files.graph,
544
+ allotment,
545
+ drops: gone === void 0 ? void 0 : (ids, offset) => holdsId(gone, ids, offset),
546
+ beforeFinish: gone === void 0 ? void 0 : (renumbered) => Effect.map(copy(renumbered), (each) => {
547
+ early.push(each);
548
+ })
549
+ });
550
+ allotment.shrink(goneHeldBytes(count));
551
+ const { entries, bitmaps } = early[0] ?? (yield* copy());
552
+ return {
553
+ commits,
554
+ entries,
555
+ bitmaps
556
+ };
557
+ }).pipe(Effect.catchIf(isKeepUnclosed, (error) => Effect.logError(`git.repack's remap of repo ${listed.repo} declined, its merge's keep isn't closed: ${error.message}`).pipe(Effect.as(void 0))));
558
+ if (copied === void 0) return void 0;
559
+ const { commits, entries, bitmaps } = copied;
453
560
  const filesBytes = layers.reduce((sum, layer) => sum + layer.deltas, 0) * 16 + objects * 8 + plan.rows * 112 + mergeChunk * 9;
454
561
  yield* allotment.grow(filesBytes);
455
562
  const types = Effect.gen(function* () {
@@ -459,7 +566,7 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
459
566
  yield* put.write(writer.head());
460
567
  const typesOf = layerTypes(input);
461
568
  yield* oldTypes(input, typesOf, 0, plan.prefix, write);
462
- for (const kind of writeOrder) for (let left = merged.kinds[kind]; left > 0; left -= mergeChunk) yield* write(new Uint8Array(Math.min(left, mergeChunk)).fill(typeCodes[kind]));
569
+ for (const kind of writeOrder) for (let left = merged.kind === "pack" ? merged.kinds[kind] : 0; left > 0; left -= mergeChunk) yield* write(new Uint8Array(Math.min(left, mergeChunk)).fill(typeCodes[kind]));
463
570
  for (const pack of plan.tail) if (pack.next !== void 0) yield* oldTypes(input, typesOf, pack.old, pack.old + pack.objects, write);
464
571
  const rowCodes = /* @__PURE__ */ new Map();
465
572
  for (const run of plan.runs) yield* oldTypes(input, typesOf, run.first, run.first + run.rows, (codes, first) => Effect.sync(() => {
@@ -481,7 +588,7 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
481
588
  });
482
589
  yield* Effect.scoped(types);
483
590
  yield* Effect.scoped(bases);
484
- allotment.shrink(filesBytes + entries + tail * 4);
591
+ allotment.shrink(filesBytes + entries + map4);
485
592
  const sha = new Sha1();
486
593
  sha.update(regionIds);
487
594
  if (regionIds.byteLength > 0) yield* putOnce(bucket, files.region, regionIds);
@@ -490,7 +597,7 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
490
597
  groups: [{
491
598
  packs: [
492
599
  ...plan.prefixPacks,
493
- merged.pack.id,
600
+ ...merged.kind === "pack" ? [merged.pack.id] : [],
494
601
  ...plan.tail.flatMap((pack) => pack.next === void 0 ? [] : [pack.id])
495
602
  ],
496
603
  rows: read.kept.length
@@ -521,7 +628,29 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
521
628
  return rebuilt;
522
629
  });
523
630
  /**
524
- * The `index` row a geometric step's merge leaves, laid again over its pack, or `undefined` when
631
+ * The row a merge's remap lays again, and its plan, from the row and the merge alone, as `remapRow`
632
+ * weighs them before any read: `undefined` when the row isn't built, is a refusal for spent tries,
633
+ * is marked lost, or doesn't cover the listing before the merge, but what `parts` holds; or the
634
+ * merge, `taken`, of `objects` objects, took a pack it doesn't cover.
635
+ */
636
+ const remapDue = (parts, listed, taken, objects) => {
637
+ const row = indexRowOf({
638
+ ...indexRowKey,
639
+ value: parts.row
640
+ });
641
+ if (row === void 0 || "refused" in row || row.refusal !== void 0 || row.lost === true) return void 0;
642
+ const held = parts.holdsUncovered === true ? pruneRemapHeld(row.layers, listed, taken) : parts.holds?.packs;
643
+ if (!coversListing(row.layers, listed, held)) return void 0;
644
+ const plan = remapPlan(row.layers, listed, taken, objects);
645
+ return plan === void 0 ? void 0 : {
646
+ row,
647
+ plan
648
+ };
649
+ };
650
+ /**
651
+ * The `index` row a geometric step's or a prune rewrite's merge leaves, laid again over its pack,
652
+ * the rewrite's dropped objects left out, or the row a prune step leaves when it empties packs
653
+ * with no merge, their positions gone, or `undefined` when
525
654
  * it can't be: the row isn't built, is a refusal for spent tries, is marked lost, or doesn't
526
655
  * cover the listing before the merge; the merge took a pack it doesn't cover; the remap
527
656
  * declines, as `remapIndex` says; or it fails of its own, its calls run out, its allotment can't
@@ -531,14 +660,9 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
531
660
  * any other failure.
532
661
  */
533
662
  const remapRow = (parts, input) => Effect.scoped(Effect.gen(function* () {
534
- const row = indexRowOf({
535
- ...indexRowKey,
536
- value: parts.row
537
- });
538
- if (row === void 0 || "refused" in row || row.refusal !== void 0 || row.lost === true) return void 0;
539
- if (!coversListing(row.layers, input.listed, parts.holds?.packs)) return void 0;
540
- const plan = remapPlan(row.layers, input.listed, input.taken, input.merged.pack.objects);
541
- if (plan === void 0) return void 0;
663
+ const due = remapDue(parts, input.listed, input.taken, mergedObjects(input.merged));
664
+ if (due === void 0) return void 0;
665
+ const { row, plan } = due;
542
666
  const { calls } = parts;
543
667
  const built = yield* remapIndex({
544
668
  bucket: calls === void 0 ? input.bucket : calls.within(remapCallsBound(calls.most)).bucket,
@@ -547,6 +671,7 @@ const remapRow = (parts, input) => Effect.scoped(Effect.gen(function* () {
547
671
  plan,
548
672
  merged: input.merged,
549
673
  folded: input.folded,
674
+ keeps: input.keeps,
550
675
  allotment: yield* parts.budget.upkeep(0, remapBusy),
551
676
  at: input.at,
552
677
  grace: parts.grace,
@@ -597,6 +722,17 @@ const coversListing = (layers, listed, held = /* @__PURE__ */ new Set()) => {
597
722
  const ids = new Set(listed.packs.map((pack) => pack.id));
598
723
  return [...covered].every((id) => ids.has(id)) && listed.packs.every((pack) => covered.has(pack.id) || held.has(pack.id));
599
724
  };
725
+ /**
726
+ * What a prune rewrite's remap holds: each listed pack `layers` don't cover that the merge doesn't
727
+ * take, `taken`, as a push's pack waits for git.index's update. A cruft step's pack, listed before
728
+ * the rewrite's step and not yet covered, so stays out of the row it lays, and a merge never waits
729
+ * on git.index to drop what it drops. A pack the merge takes that the row doesn't cover still
730
+ * declines the remap, in `remapPlan`.
731
+ */
732
+ const pruneRemapHeld = (layers, listed, taken) => {
733
+ const covered = coveredPacks(layers);
734
+ return new Set(listed.packs.flatMap((pack) => covered.has(pack.id) || taken.has(pack.id) ? [] : [pack.id]));
735
+ };
600
736
  /** The object rows `layers` cover: each group's rows, as git.index read them. */
601
737
  const rowsCovered = (layers) => layers.reduce((sum, layer) => sum + layer.groups.reduce((each, group) => each + group.rows, 0), 0);
602
738
  /**
@@ -638,4 +774,4 @@ const liftsHolds = (old, now, listed) => {
638
774
  const is = coveredPacks(now.layers);
639
775
  return listed.packs.some((pack) => is.has(pack.id) && !was.has(pack.id)) || rowsCovered(now.layers) > rowsCovered(old.layers);
640
776
  };
641
- export { coversListing, defaultRemapCpuMost, indexHolds, liftsHolds, movedBits, remapCalls, remapCallsBound, remapCallsMost, remapCpuPast, remapHeldMost, remapIndex, remapPast, remapPlan, remapRow, remapUnits, replacedAtCommit };
777
+ export { coversListing, declinedPast, defaultRemapCpuMost, goneBuildBytes, indexHolds, liftsHolds, movedBits, pruneRemapHeld, remapCalls, remapCallsBound, remapCallsMost, remapCpuPast, remapDue, remapFits, remapHeldMost, remapIndex, remapPast, remapPlan, remapRow, remapUnits, replacedAtCommit };
@@ -0,0 +1,127 @@
1
+ import { packIndexBytes } from "../protocol/packs/idx.mjs";
2
+ import { packPositionsBytes } from "../protocol/packs/pos.mjs";
3
+ import { bodyOfBytes, bucketDo, readEach } from "./calls.mjs";
4
+ import { indexBasesBytes, indexTypesBytes } from "./index-files.mjs";
5
+ import { indexGraphBytes } from "./index-graph.mjs";
6
+ import { indexFiles, isPackId, packFiles } from "./layout.mjs";
7
+ import * as Effect from "effect/Effect";
8
+ // src/storage/index-whole.ts
9
+ /**
10
+ * The most a fetch reads of a small index's files whole, all at once, before its walk: 1 MiB, the
11
+ * writer's meter. Its files are read in turn by range otherwise, one wait each (#2523): about 23
12
+ * for a small fetch, at about 70 ms a get on R2. Past it, they're read by range as before.
13
+ */
14
+ const wholeIndexMost = 1048576;
15
+ /**
16
+ * The files read at once, as the bitmaps' reads are: a small index's 6 in one round, and one over
17
+ * many packs in rounds of 16, never one get a file all open together.
18
+ */
19
+ const filesAtOnce = 16;
20
+ /** The packs whose `.idx` holds no 8-byte offsets: under 2 GiB. */
21
+ const smallPackBytes = 2 ** 31;
22
+ /**
23
+ * The files a fetch's walk and send list read of an index of `layers` over `packs`: each layer's
24
+ * `.graph`, `.bitmaps` when it has any, `.types` and `.bases` when it has deltas, and each pack's
25
+ * `.idx` and `.pos`, with the least each can be from the row and the listing, no call made: a
26
+ * graph's octopus rows aren't in the row, so its least counts none. An index with a region's rows
27
+ * or a pack past 2 GiB is none of these: `undefined`, so it's read by range.
28
+ */
29
+ const indexFilesOf = (repo, layers, packs) => {
30
+ const files = [];
31
+ for (const layer of layers) {
32
+ if (layer.groups.some((group) => group.rows > 0)) return void 0;
33
+ const at = indexFiles(repo, layer.build);
34
+ const positions = layer.first + layer.positions;
35
+ files.push({
36
+ key: at.graph,
37
+ least: indexGraphBytes(layer.commits, 0)
38
+ });
39
+ files.push({
40
+ key: at.types,
41
+ least: indexTypesBytes(layer.positions)
42
+ });
43
+ if (layer.bitmaps > 0) files.push({
44
+ key: at.bitmaps,
45
+ least: layer.table + layer.bitmaps * 20 + 20
46
+ });
47
+ if (layer.deltas > 0) files.push({
48
+ key: at.bases,
49
+ least: indexBasesBytes(positions, layer.deltas)
50
+ });
51
+ }
52
+ for (const pack of packs) {
53
+ if (pack.bytes >= smallPackBytes || !isPackId(pack.id)) return void 0;
54
+ const at = packFiles(pack.id);
55
+ files.push({
56
+ key: at.idx,
57
+ least: packIndexBytes(pack.objects, 0)
58
+ });
59
+ files.push({
60
+ key: at.pos,
61
+ least: packPositionsBytes(pack.objects)
62
+ });
63
+ }
64
+ return files;
65
+ };
66
+ /** A file read whole past what was left of the bound. */
67
+ var PastBound = class {
68
+ _tag = "PastBound";
69
+ };
70
+ /**
71
+ * Each of `files` read whole, `filesAtOnce` at a time, their buffers together at most `most`:
72
+ * `undefined` when they pass it, so the caller reads by range, as before. Each file's chunks are
73
+ * copied as they come into one buffer, the file's least to start, charged before it's made, so
74
+ * no chunk is kept and nothing live goes uncharged: one too small for a chunk is made again, at
75
+ * twice its size or the chunk's need, both charged while the copy runs, and the old one given
76
+ * back after. An empty chunk is skipped. A read's failure is the fetch's, as one by range is.
77
+ */
78
+ const wholeFiles = (bucket, files, most) => Effect.suspend(() => {
79
+ let left = most;
80
+ const read = (file) => Effect.suspend(() => {
81
+ let held = /* @__PURE__ */ new Uint8Array(0);
82
+ let length = 0;
83
+ /** `held` made again with room for `need`, charged first: false past the bound. */
84
+ const grow = (need) => {
85
+ const size = Math.max(need, Math.min(held.byteLength * 2, left));
86
+ if (size > left) return false;
87
+ left -= size;
88
+ const next = new Uint8Array(size);
89
+ next.set(held.subarray(0, length));
90
+ left += held.byteLength;
91
+ held = next;
92
+ return true;
93
+ };
94
+ const take = (chunk) => {
95
+ if (chunk.byteLength === 0) return Effect.void;
96
+ if (length + chunk.byteLength > held.byteLength && !grow(length + chunk.byteLength)) return Effect.fail(new PastBound());
97
+ held.set(chunk, length);
98
+ length += chunk.byteLength;
99
+ return Effect.void;
100
+ };
101
+ if (!grow(file.least)) return Effect.succeed(void 0);
102
+ return bucketDo(readEach(bucket, file.key, void 0, take).pipe(Effect.map(() => [file.key, held.subarray(0, length)]), Effect.catchTag("PastBound", () => Effect.succeed(void 0))));
103
+ });
104
+ return Effect.map(Effect.forEach(files, read, { concurrency: filesAtOnce }), (read) => {
105
+ const held = read.filter((file) => file !== void 0);
106
+ return held.length === files.length ? {
107
+ files: new Map(held),
108
+ bytes: most - left
109
+ } : void 0;
110
+ });
111
+ });
112
+ /**
113
+ * `bucket`, each of `files` read from the bytes held, with no call: a range as the bucket answers
114
+ * it, cut at the file's end, and the whole file without one. Every other key reads through.
115
+ */
116
+ const heldFiles = (bucket, files) => ({
117
+ ...bucket,
118
+ read: (key, range) => {
119
+ const whole = files.get(key);
120
+ if (whole === void 0) return bucket.read(key, range);
121
+ if (range === void 0) return bodyOfBytes(whole);
122
+ const from = Math.min(range.offset, whole.byteLength);
123
+ const to = Math.max(from, Math.min(range.offset + range.length, whole.byteLength));
124
+ return bodyOfBytes(whole.subarray(from, to));
125
+ }
126
+ });
127
+ export { heldFiles, indexFilesOf, wholeFiles, wholeIndexMost };
@@ -42,7 +42,7 @@ var LargestFiles = class {
42
42
  /** The largest of `objects`' blobs, as `LargestFiles` keeps them: a receive kept as rows. */
43
43
  const largestOf = (objects) => {
44
44
  const largest = new LargestFiles();
45
- for (const object of objects) if (object.type === "blob") largest.add(object.oid, object.bytes.byteLength);
45
+ for (const object of objects) if (object.type === "blob") largest.add(object.oid, "size" in object ? object.size : object.bytes.byteLength);
46
46
  return largest.finish();
47
47
  };
48
48
  export { LargestFiles, largestOf };
@@ -15,6 +15,29 @@ const objectCollections = {
15
15
  cover: "cover",
16
16
  /** One object as a row, by its ID: every object `loose()` holds, and a small push's. */
17
17
  objects: "objects",
18
+ /**
19
+ * A large push's object rows, staged apart before its commit, by `<batch>/<oid>`: an `ObjectRow`,
20
+ * read beside `objects` once its batch is published, until upkeep promotes it there.
21
+ */
22
+ stagedObjects: "stagedObjects",
23
+ /**
24
+ * The value size in bytes of each staged object row, by `<batch>/<oid>`: `{ bytes }`, written in
25
+ * the same staging add as its row and deleted with it by promotion or sweep, so readers pack body
26
+ * reads by size without reading duplicate copies (#2521).
27
+ */
28
+ stagedSizes: "stagedSizes",
29
+ /**
30
+ * A chunked object's bytes, by `<batch>/<part>/<nnnn>`: `{ data }`, `chunkRawBytes` of them as
31
+ * base64, named by the object's `ChunkedRow`. They stay under the batch that staged them.
32
+ */
33
+ objectChunks: "objectChunks",
34
+ /** A published staged batch, by its ID: `BatchRow`, deleted once upkeep has promoted its rows. */
35
+ batches: "batches",
36
+ /**
37
+ * A staged batch being received, by its ID, added before its first row: a `QuarantineRow`, ended
38
+ * by the commit that publishes the batch, or abandoned and, once its rows are swept, deleted.
39
+ */
40
+ batchQuarantine: "batchQuarantine",
18
41
  /** A cruft pack, by its ID: when a prune pass found its objects unreached, `CruftRow`. */
19
42
  cruft: "cruft",
20
43
  /** The last prune pass, `pass`: when it ran, `PrunePass`. */
@@ -1,22 +1,25 @@
1
1
  import { ObjectsFactory } from "../contracts/objects.mjs";
2
2
  /**
3
- * What one push may carry into `loose()` storage: its `objects`, and the `bytes` of its rows as
4
- * JSON, which its commit holds.
3
+ * What one push may carry into `loose()` storage: its `objects`, the `bytes` of its rows as JSON,
4
+ * which its commit holds, and the bytes of each object, `fileBytes`, one past a row kept as chunks.
5
5
  */
6
6
  export declare const looseLimits: {
7
7
  readonly objects: 10000;
8
8
  readonly bytes: number;
9
+ readonly fileBytes: number;
9
10
  };
10
11
  /** What one push may carry into `loose()` storage, each at most `looseLimits`' own. */
11
12
  export interface LooseLimits {
12
13
  readonly objects?: number;
13
14
  readonly bytes?: number;
15
+ readonly fileBytes?: number;
14
16
  }
15
17
  /**
16
18
  * `loose()`: each object a row of the repo's scope, with no bucket. A push of more than
17
19
  * `options.objects` objects, 10,000 by default, is refused whole, and so is one whose rows pass
18
- * `options.bytes`, one commit's 8 MiB by default, or with an object whose row passes one row's
19
- * 1 MiB, as `object-too-large`. A whole push names its roots and the rows it links to, so it can
20
+ * `options.bytes`, one commit's 8 MiB by default, of rows within one row's 1 MiB. An object past
21
+ * one row is kept as chunk rows, to `options.fileBytes`, 32 MiB by default, and one past that is
22
+ * refused as `object-too-large`. A whole push names its roots and the rows it links to, so it can
20
23
  * keep a repo's whole-clone mark. The client's default.
21
24
  */
22
25
  export declare const loose: (options?: LooseLimits) => ObjectsFactory<false>;