@ref0/git 0.7.0 → 0.9.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 (245) hide show
  1. package/dist/access/private-refs.mjs +0 -2
  2. package/dist/auth/authorize.mjs +31 -24
  3. package/dist/auth/bridge.mjs +8 -8
  4. package/dist/auth/fences.d.mts +0 -1
  5. package/dist/auth/fences.mjs +1 -1
  6. package/dist/auth/grants.d.mts +0 -1
  7. package/dist/auth/grants.mjs +2 -2
  8. package/dist/auth/host-function.d.mts +1 -7
  9. package/dist/auth/host-function.mjs +38 -38
  10. package/dist/auth/identify.d.mts +0 -1
  11. package/dist/auth/identify.mjs +1 -1
  12. package/dist/auth/policy.d.mts +7 -4
  13. package/dist/auth/policy.mjs +13 -10
  14. package/dist/auth/token-rows.mjs +2 -5
  15. package/dist/auth/tokens-layer.d.mts +0 -2
  16. package/dist/auth/tokens-public.d.mts +3 -3
  17. package/dist/auth/tokens-public.mjs +4 -2
  18. package/dist/auth/tokens.d.mts +6 -1
  19. package/dist/auth/tokens.mjs +7 -1
  20. package/dist/client/client.d.mts +22 -15
  21. package/dist/client/client.mjs +31 -27
  22. package/dist/client/git-http.mjs +22 -5
  23. package/dist/client/local.mjs +1 -1
  24. package/dist/client/namespace.d.mts +2 -0
  25. package/dist/client/push-upload.d.mts +1 -0
  26. package/dist/client/push-upload.mjs +169 -2
  27. package/dist/client/remote-helper.mjs +2 -4
  28. package/dist/client/remote.mjs +37 -15
  29. package/dist/client/run-remote-helper.mjs +4 -4
  30. package/dist/client/transport.mjs +26 -19
  31. package/dist/contracts/actors.d.mts +57 -28
  32. package/dist/contracts/actors.mjs +38 -2
  33. package/dist/contracts/authorize.d.mts +21 -15
  34. package/dist/contracts/callers.mjs +40 -0
  35. package/dist/contracts/calls-spent.d.mts +2 -12
  36. package/dist/contracts/calls-spent.mjs +4 -5
  37. package/dist/contracts/client.d.mts +16 -9
  38. package/dist/contracts/events.d.mts +82 -14
  39. package/dist/contracts/events.mjs +35 -9
  40. package/dist/contracts/files.d.mts +42 -42
  41. package/dist/contracts/forks.d.mts +0 -24
  42. package/dist/contracts/git-hooks.d.mts +217 -0
  43. package/dist/contracts/git-hooks.mjs +3 -1
  44. package/dist/contracts/git.d.mts +13 -3
  45. package/dist/contracts/grants.d.mts +46 -27
  46. package/dist/contracts/lfs.d.mts +17 -4
  47. package/dist/contracts/merges.d.mts +7 -7
  48. package/dist/contracts/objects.d.mts +38 -4
  49. package/dist/contracts/opaque.mjs +19 -1
  50. package/dist/contracts/operations.d.mts +8 -1
  51. package/dist/contracts/operations.mjs +209 -0
  52. package/dist/contracts/queue.d.mts +6 -5
  53. package/dist/contracts/queue.mjs +9 -20
  54. package/dist/contracts/remote.d.mts +13 -4
  55. package/dist/contracts/remote.mjs +3 -3
  56. package/dist/contracts/repos.d.mts +11 -40
  57. package/dist/contracts/repos.mjs +11 -10
  58. package/dist/contracts/result.d.mts +28 -11
  59. package/dist/contracts/result.mjs +32 -2
  60. package/dist/contracts/rules.d.mts +706 -46
  61. package/dist/contracts/rules.mjs +81 -2
  62. package/dist/contracts/server.d.mts +5 -275
  63. package/dist/contracts/services.d.mts +0 -3
  64. package/dist/contracts/services.mjs +1 -3
  65. package/dist/contracts/signin.d.mts +2 -2
  66. package/dist/contracts/signin.mjs +4 -5
  67. package/dist/contracts/sync.d.mts +1 -4
  68. package/dist/contracts/tokens.d.mts +29 -17
  69. package/dist/contracts/tokens.mjs +14 -3
  70. package/dist/contracts/topics.d.mts +38 -11
  71. package/dist/contracts/topics.mjs +8 -2
  72. package/dist/core/access.d.mts +0 -2
  73. package/dist/core/access.mjs +15 -4
  74. package/dist/core/ancestry.mjs +5 -4
  75. package/dist/core/events/deliver.mjs +19 -1
  76. package/dist/core/forks.mjs +30 -11
  77. package/dist/core/hooks/groups.d.mts +0 -1
  78. package/dist/core/hooks/groups.mjs +8 -9
  79. package/dist/core/index-job.mjs +23 -1
  80. package/dist/core/index-lost.d.mts +11 -0
  81. package/dist/core/index-lost.mjs +55 -0
  82. package/dist/core/loose-tally.mjs +46 -0
  83. package/dist/core/objects/commit-writes.mjs +1 -1
  84. package/dist/core/objects/commits.mjs +10 -9
  85. package/dist/core/objects/merges.mjs +1 -1
  86. package/dist/core/objects/reading.mjs +28 -13
  87. package/dist/core/objects/trees.mjs +1 -1
  88. package/dist/core/objects/writing.mjs +1 -0
  89. package/dist/core/parts.d.mts +7 -0
  90. package/dist/core/promise.mjs +1 -15
  91. package/dist/core/publish.mjs +9 -5
  92. package/dist/core/purge.mjs +30 -12
  93. package/dist/core/push.mjs +39 -16
  94. package/dist/core/ref-view.mjs +14 -6
  95. package/dist/core/repack.mjs +54 -27
  96. package/dist/core/repo-info.mjs +8 -6
  97. package/dist/core/repos.mjs +1 -0
  98. package/dist/core/rules/check.mjs +10 -10
  99. package/dist/core/rules/context.d.mts +3 -1
  100. package/dist/core/rules/context.mjs +16 -13
  101. package/dist/core/rules/fetch.mjs +17 -23
  102. package/dist/core/tokens.mjs +2 -1
  103. package/dist/core/view.d.mts +10 -1
  104. package/dist/core/view.mjs +15 -6
  105. package/dist/effect.d.mts +3 -6
  106. package/dist/effect.mjs +3 -6
  107. package/dist/engine/commits.mjs +23 -50
  108. package/dist/engine/failures.d.mts +1 -2
  109. package/dist/engine/failures.mjs +1 -3
  110. package/dist/engine/merge-base-walk.mjs +57 -142
  111. package/dist/engine/merge-bases.mjs +9 -7
  112. package/dist/engine/merge.mjs +20 -17
  113. package/dist/engine/parts.d.mts +1 -0
  114. package/dist/engine/parts.mjs +1 -1
  115. package/dist/engine/walk.mjs +15 -11
  116. package/dist/extend.d.mts +1 -2
  117. package/dist/extend.mjs +1 -2
  118. package/dist/http/core-parts.mjs +18 -10
  119. package/dist/http/handler.mjs +11 -31
  120. package/dist/http/parts.d.mts +0 -1
  121. package/dist/index.d.mts +29 -22
  122. package/dist/index.mjs +5 -2
  123. package/dist/lfs/base.d.mts +6 -3
  124. package/dist/lfs/base.mjs +2 -1
  125. package/dist/lfs/layer.d.mts +4 -3
  126. package/dist/lfs/layer.mjs +23 -9
  127. package/dist/lfs/objects.mjs +93 -41
  128. package/dist/lfs/pointers.mjs +69 -18
  129. package/dist/lfs/purge.mjs +6 -2
  130. package/dist/lfs/rows.mjs +24 -7
  131. package/dist/lfs/service.d.mts +6 -3
  132. package/dist/lfs/service.mjs +8 -2
  133. package/dist/lfs/upkeep.mjs +47 -28
  134. package/dist/lfs/upload-most.mjs +47 -0
  135. package/dist/lfs/uploaded.mjs +59 -0
  136. package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
  137. package/dist/protocol/bytes/streams.mjs +84 -2
  138. package/dist/protocol/bytes/text.mjs +6 -1
  139. package/dist/protocol/diff/read.d.mts +1 -0
  140. package/dist/protocol/diff/read.mjs +5 -2
  141. package/dist/protocol/objects/commit.d.mts +7 -0
  142. package/dist/protocol/objects/commit.mjs +5 -1
  143. package/dist/protocol/objects/fsck.mjs +6 -3
  144. package/dist/queue/advance.mjs +77 -18
  145. package/dist/queue/calls.mjs +4 -14
  146. package/dist/queue/host.d.mts +4 -0
  147. package/dist/queue/lanes.mjs +1 -1
  148. package/dist/queue/layer.mjs +4 -2
  149. package/dist/queue/limits.mjs +18 -2
  150. package/dist/queue/rows.mjs +10 -1
  151. package/dist/queue/schedule.mjs +1 -1
  152. package/dist/queue/search.mjs +3 -4
  153. package/dist/queue/trim.mjs +2 -2
  154. package/dist/rest/client-namespace.d.mts +2 -0
  155. package/dist/rest/client.d.mts +32 -8
  156. package/dist/rest/client.mjs +308 -382
  157. package/dist/rest/commits.d.mts +150 -150
  158. package/dist/rest/files.d.mts +18 -18
  159. package/dist/rest/forks.d.mts +77 -89
  160. package/dist/rest/handlers.mjs +2 -1
  161. package/dist/rest/listen.d.mts +8 -6
  162. package/dist/rest/listen.mjs +31 -75
  163. package/dist/rest/me.d.mts +2 -2
  164. package/dist/rest/merges.d.mts +7 -7
  165. package/dist/rest/refs.d.mts +27 -27
  166. package/dist/rest/repos.d.mts +40 -52
  167. package/dist/rest/tokens.d.mts +12 -12
  168. package/dist/rest/topics.d.mts +13 -13
  169. package/dist/rest/trees.d.mts +66 -66
  170. package/dist/rest/wire.d.mts +20 -2
  171. package/dist/rest/work.d.mts +39 -39
  172. package/dist/rest.d.mts +1 -7
  173. package/dist/rest.mjs +1 -5
  174. package/dist/server/git-layer.d.mts +10 -2
  175. package/dist/server/git-layer.mjs +29 -10
  176. package/dist/server/joined.d.mts +12 -6
  177. package/dist/server/joined.mjs +3 -2
  178. package/dist/server/registry.mjs +11 -5
  179. package/dist/server/server.d.mts +0 -1
  180. package/dist/server/server.mjs +42 -49
  181. package/dist/signin/context.d.mts +0 -1
  182. package/dist/signin/context.mjs +5 -9
  183. package/dist/storage/clean-up.mjs +3 -1
  184. package/dist/storage/fsck.mjs +12 -2
  185. package/dist/storage/graph-rebuild.mjs +262 -0
  186. package/dist/storage/index-bitmaps.mjs +16 -10
  187. package/dist/storage/index-build.mjs +160 -24
  188. package/dist/storage/index-graph.d.mts +1 -0
  189. package/dist/storage/index-graph.mjs +29 -5
  190. package/dist/storage/index-layers.d.mts +1 -0
  191. package/dist/storage/index-layers.mjs +5 -2
  192. package/dist/storage/index-reach.mjs +7 -5
  193. package/dist/storage/index-remap.mjs +5 -5
  194. package/dist/storage/index-visible.mjs +16 -5
  195. package/dist/storage/lfs-pointers.d.mts +5 -5
  196. package/dist/storage/lfs-pointers.mjs +37 -11
  197. package/dist/storage/links.mjs +3 -3
  198. package/dist/storage/loose.mjs +4 -1
  199. package/dist/storage/memory-budget.mjs +1 -1
  200. package/dist/storage/merge-fence.mjs +81 -19
  201. package/dist/storage/merge-most.mjs +1 -0
  202. package/dist/storage/merge-row.mjs +16 -4
  203. package/dist/storage/merge-stream.mjs +9 -6
  204. package/dist/storage/object-rows.mjs +17 -1
  205. package/dist/storage/pack-order.d.mts +1 -0
  206. package/dist/storage/pack-order.mjs +18 -1
  207. package/dist/storage/pack-receive.mjs +10 -6
  208. package/dist/storage/packs.mjs +58 -27
  209. package/dist/storage/prune-walk.mjs +5 -2
  210. package/dist/storage/prune.mjs +168 -70
  211. package/dist/storage/ready.d.mts +1 -1
  212. package/dist/storage/ready.mjs +12 -3
  213. package/dist/storage/receive-bounds.mjs +3 -2
  214. package/dist/storage/receive-state.mjs +1 -1
  215. package/dist/storage/repack-contained.mjs +22 -14
  216. package/dist/storage/repack.d.mts +1 -1
  217. package/dist/storage/repack.mjs +3 -2
  218. package/dist/storage/unpack.mjs +7 -0
  219. package/dist/storage/visible.mjs +3 -2
  220. package/dist/storage/walk.d.mts +1 -0
  221. package/dist/storage/walk.mjs +9 -5
  222. package/dist/storage/wants.mjs +17 -11
  223. package/dist/store/call-count.d.mts +31 -3
  224. package/dist/store/call-count.mjs +51 -20
  225. package/dist/store/errors.d.mts +7 -1
  226. package/dist/store/errors.mjs +7 -1
  227. package/dist/store/job-try.mjs +3 -1
  228. package/dist/store/records.mjs +26 -5
  229. package/dist/store/repo-record.mjs +36 -12
  230. package/dist/store/scopes.mjs +15 -2
  231. package/dist/sync/bound.d.mts +1 -1
  232. package/dist/sync/import.mjs +15 -3
  233. package/dist/sync/layer.d.mts +5 -1
  234. package/dist/sync/layer.mjs +11 -9
  235. package/dist/sync/mirror.mjs +1 -1
  236. package/dist/sync/step.mjs +15 -15
  237. package/dist/topics/advance.mjs +11 -10
  238. package/dist/topics/layer.mjs +1 -1
  239. package/dist/topics/members.mjs +38 -9
  240. package/package.json +3 -3
  241. package/dist/engine/merge-base-walk.d.mts +0 -3
  242. package/dist/server/routes.d.mts +0 -32
  243. package/dist/server/routes.mjs +0 -69
  244. package/dist/sync/bridge.d.mts +0 -6
  245. package/dist/sync/bridge.mjs +0 -29
@@ -0,0 +1,262 @@
1
+ import { gitError } from "../contracts/result.mjs";
2
+ import { hexOf } from "../protocol/bytes/hex.mjs";
3
+ import { graphBytes, sortedGraph } from "../protocol/packs/graph.mjs";
4
+ import { mostParents } from "../protocol/objects/object-rules.mjs";
5
+ import { oidBytes } from "../protocol/packs/idx.mjs";
6
+ import { typeOfByte } from "../protocol/packs/types-file.mjs";
7
+ import { packRow } from "../store/git-store.mjs";
8
+ import { bucketDeleteMany, bucketPut, deleteCharge, readWhole, sizedPutCalls } from "./calls.mjs";
9
+ import { openTypes } from "./held-types.mjs";
10
+ import { isPackId, packFiles, runKey } from "./layout.mjs";
11
+ import { linksOf } from "./links.mjs";
12
+ import { noRows } from "./object-rows.mjs";
13
+ import { upkeepTooLarge } from "./memory-budget.mjs";
14
+ import { refusedKey } from "./merge-fence.mjs";
15
+ import { readersOf } from "./merge-stream.mjs";
16
+ import { openIndexRanges, readExactly } from "./pack-ranges.mjs";
17
+ import { dropRunsCalls } from "./receive-bounds.mjs";
18
+ import { dropRuns } from "./runs.mjs";
19
+ import * as Effect from "effect/Effect";
20
+ // src/storage/graph-rebuild.ts
21
+ /**
22
+ * The rebuild of a graph-fenced pack's `.graph` (#2227): a merge that found the file broken, or not
23
+ * the size its row records, fenced the pack, and nothing else writes a `.graph` from a pack alone.
24
+ *
25
+ * The `.idx` lists the pack's objects in ID order, the order the `.graph` holds its commits in, so
26
+ * each step reads the commits of the ranks from its cursor, as far as its calls go, and puts their
27
+ * part of the file's body as a run, `graph-<n>`, under the pack's runs. The `refused` row carries
28
+ * the cursor. The last step joins the parts into the `.graph`, puts it, then commits the pack's row
29
+ * with the file's size beside the `refused` row's delete. A step that crashes first commits
30
+ * nothing, and the next does its work again: a part put again over itself, or the file put again.
31
+ * A part found missing, as when the last step dropped the runs and crashed before its commit,
32
+ * starts the rebuild over. While the `refused` row stands, no merge reads the pack's `.graph`.
33
+ *
34
+ * Its parts stay within `rebuildPartsMost`: a step that finds that many puts them again as one,
35
+ * under the next number, and the next step deletes the ones it replaced. So the last step's calls,
36
+ * its reads of the parts, the `.graph`'s put and the runs' drop, are forecast before it starts,
37
+ * and a step whose calls don't fit them marks the pack failed. A job's try runs one step, each
38
+ * after the same reads, so a step that doesn't fit now would fit no later try either.
39
+ */
40
+ /** The ranks a step reads at a time: one get of IDs, one of offsets and one of types. */
41
+ const rebuildWindowRanks = 4096;
42
+ /** A commit's head in a part: its ID and its parents' count, as the `.graph` lays it. */
43
+ const headBytes = 24;
44
+ const started = {
45
+ rank: 0,
46
+ commits: 0,
47
+ parents: 0,
48
+ first: 0,
49
+ parts: 0,
50
+ swept: 0
51
+ };
52
+ /** Whether `made` and `extra` more calls leave the reserve within `most`. */
53
+ const within = (made, extra, most) => made.bucket + extra + 64 < most.bucket && made.subrequests + extra + 64 < most.subrequests;
54
+ /** Whether a step with `calls` has room for `extra` calls, and one more commit's read. */
55
+ const roomFor = (calls, extra = 0) => calls === void 0 || within(calls.made(), extra, calls.most);
56
+ /** The first listed pack, by ID, whose `.graph` a merge refused and no rebuild failed on. */
57
+ const rebuildable = (packs, refused) => packs.filter((pack) => {
58
+ const row = refused.get(pack.id);
59
+ return row !== void 0 && (row.reason === "graph-length" || row.reason === "graph-broken") && row.rebuilt === void 0;
60
+ }).toSorted((a, b) => a.id < b.id ? -1 : 1)[0];
61
+ /** The `refused` row of `pack`, as `row` but with `fields`. */
62
+ const rowOf = (pack, row, fields) => {
63
+ const { rebuild: _, ...rest } = row;
64
+ return {
65
+ ...refusedKey(pack),
66
+ value: {
67
+ ...rest,
68
+ ...fields
69
+ }
70
+ };
71
+ };
72
+ /** The keys of `pack`'s parts from `from` up to `to`. */
73
+ const partKeys = (pack, from, to) => Array.from({ length: Math.max(0, to - from) }, (_, at) => runKey(pack, "graph", from + at));
74
+ /** Each commit of `pack` from `cursor`'s rank, as a part's bytes, till the window or the calls end. */
75
+ const readPart = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, cursor, calls) {
76
+ const chunks = [];
77
+ let { rank, commits, parents } = cursor;
78
+ const stored = {
79
+ id: pack.id,
80
+ bytes: pack.bytes
81
+ };
82
+ const ranges = yield* openIndexRanges(input.bucket, stored, pack.objects);
83
+ const checksum = hexOf(yield* readExactly(input.bucket, packFiles(pack.id).pack, pack.bytes - 20, 20));
84
+ const typed = yield* openTypes(input.bucket, stored, ranges.count, checksum);
85
+ const reader = readersOf(input)();
86
+ while (rank < ranges.count && roomFor(calls, 3)) {
87
+ const length = Math.min(rebuildWindowRanks, ranges.count - rank);
88
+ const ids = yield* ranges.ids(rank, length);
89
+ const offsets = yield* ranges.offsets(rank, length);
90
+ const types = yield* typed.types(rank, length);
91
+ let at = 0;
92
+ for (; at < length; at += 1) {
93
+ if (typeOfByte(types[at] ?? 0) !== "commit") continue;
94
+ if (!roomFor(calls)) break;
95
+ const oid = hexOf(ids.subarray(at * 20, at * 20 + 20));
96
+ const object = yield* reader.wholeAt.inRanges(oid, ranges, offsets[at] ?? 0);
97
+ const ofCommit = (yield* Effect.fromResult(linksOf(object))).slice(1);
98
+ if (ofCommit.length > 4096) return yield* Effect.fail(gitError("DATA_LOSS", `Commit ${oid} has ${ofCommit.length} parents, past ${mostParents}`));
99
+ const chunk = new Uint8Array(headBytes + ofCommit.length * 20);
100
+ chunk.set(ids.subarray(at * 20, at * 20 + 20), 0);
101
+ new DataView(chunk.buffer).setUint32(20, ofCommit.length);
102
+ for (const [place, link] of ofCommit.entries()) chunk.set(oidBytes(link.oid), headBytes + place * 20);
103
+ chunks.push(chunk);
104
+ commits += 1;
105
+ parents += ofCommit.length;
106
+ }
107
+ rank += at;
108
+ if (at < length) break;
109
+ }
110
+ return {
111
+ chunks,
112
+ cursor: {
113
+ ...cursor,
114
+ rank,
115
+ commits,
116
+ parents
117
+ }
118
+ };
119
+ });
120
+ /** Each of `cursor`'s parts, read back in order, or `undefined` when one is missing. */
121
+ const readParts = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, cursor) {
122
+ const parts = [];
123
+ for (const key of partKeys(pack, cursor.first, cursor.first + cursor.parts)) {
124
+ const bytes = yield* readWhole(input.bucket, key);
125
+ if (bytes === void 0) return void 0;
126
+ parts.push(bytes);
127
+ }
128
+ return parts;
129
+ });
130
+ /** The `.graph` of `cursor`'s parts, read back in order, or `undefined` when one is missing. */
131
+ const joinedGraph = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, cursor) {
132
+ const graph = sortedGraph(cursor.commits, cursor.parents);
133
+ for (const key of partKeys(pack, cursor.first, cursor.first + cursor.parts)) {
134
+ const bytes = yield* readWhole(input.bucket, key);
135
+ if (bytes === void 0) return void 0;
136
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
137
+ let at = 0;
138
+ while (at < bytes.byteLength) {
139
+ const count = view.getUint32(at + 20);
140
+ graph.commit(bytes, at);
141
+ at += headBytes;
142
+ for (let each = 0; each < count; each += 1, at += 20) graph.parent(bytes, at);
143
+ }
144
+ }
145
+ return graph.finish();
146
+ });
147
+ /**
148
+ * Whether a step that reads all of `cursor`'s parts, deletes `swept` keys, then deletes and puts
149
+ * `bytes` bytes and drops `dropped` keys, fits `calls`, past the reserve.
150
+ */
151
+ const finishing = (input, cursor, calls, swept, bytes, dropped) => {
152
+ const { multipart, deleteBatch } = input.bucket;
153
+ const forecast = swept + cursor.parts + deleteCharge(deleteBatch, 1) + sizedPutCalls(multipart, bytes) + (dropped === 0 ? 0 : dropRunsCalls(dropped, deleteBatch));
154
+ return roomFor(calls, forecast);
155
+ };
156
+ /** The step that marks `pack`'s rebuild failed, so it stays fenced and none runs again. */
157
+ const failed = (pack, row, why) => Effect.as(Effect.logWarning(`pack ${pack} stays fenced: its .graph can't be rebuilt (${why})`), {
158
+ change: {
159
+ put: [rowOf(pack, row, { rebuilt: "failed" })],
160
+ rows: noRows
161
+ },
162
+ more: true
163
+ });
164
+ /**
165
+ * One step of the rebuild of the first graph-fenced pack of `packs`, or `undefined` when there's
166
+ * none: its part put and its cursor saved; with
167
+ * `rebuildPartsMost` parts, those put again as one; or at its end the `.graph` put and its pack's
168
+ * row committed with the `refused` row's delete. A pack whose commits can't be read, or whose step
169
+ * has no room for its reads, stays fenced, marked so none rebuilds it again.
170
+ */
171
+ const rebuildStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, refused, calls) {
172
+ const pack = rebuildable(input.listed.packs, refused);
173
+ if (pack === void 0 || !isPackId(pack.id)) return void 0;
174
+ const id = pack.id;
175
+ const row = refused.get(id);
176
+ const cursor = row.rebuild ?? started;
177
+ const stale = partKeys(id, cursor.swept, cursor.first);
178
+ const sweep = deleteCharge(input.bucket.deleteBatch, stale.length);
179
+ const held = headBytes * cursor.commits + 20 * cursor.parents;
180
+ if (cursor.rank < pack.objects && cursor.parts < 16) {
181
+ if (!roomFor(calls, sweep + 4 + 3)) return yield* failed(id, row, `its step has no room to open it`);
182
+ yield* bucketDeleteMany(input.bucket, stale);
183
+ const read = yield* readPart(input, {
184
+ ...pack,
185
+ id
186
+ }, cursor, calls).pipe(Effect.map((part) => ({ part })), Effect.catchIf((error) => error.code === "DATA_LOSS", (error) => Effect.succeed({ lost: error.message })));
187
+ if ("lost" in read) return yield* failed(id, row, read.lost);
188
+ const { chunks, cursor: next } = read.part;
189
+ if (next.rank === cursor.rank) return yield* failed(id, row, `its step's calls read no window past opening it`);
190
+ const swept = {
191
+ ...next,
192
+ swept: cursor.first
193
+ };
194
+ if (chunks.length === 0) return {
195
+ change: {
196
+ put: [rowOf(id, row, { rebuild: swept })],
197
+ rows: noRows
198
+ },
199
+ more: true
200
+ };
201
+ const part = runKey(id, "graph", cursor.first + cursor.parts);
202
+ yield* bucketDeleteMany(input.bucket, [part]);
203
+ yield* bucketPut(input.bucket, part, chunks);
204
+ return {
205
+ change: {
206
+ put: [rowOf(id, row, { rebuild: {
207
+ ...swept,
208
+ parts: cursor.parts + 1
209
+ } })],
210
+ rows: noRows
211
+ },
212
+ more: true
213
+ };
214
+ }
215
+ if (cursor.rank < pack.objects) {
216
+ if (!finishing(input, cursor, calls, sweep, held, 0)) return yield* failed(id, row, `its parts take past a step's calls`);
217
+ yield* bucketDeleteMany(input.bucket, stale);
218
+ const rebuild = (yield* Effect.acquireUseRelease(input.allotment.grow(held, upkeepTooLarge), () => Effect.flatMap(readParts(input, id, cursor), (read) => {
219
+ if (read === void 0) return Effect.succeed(false);
220
+ const one = runKey(id, "graph", cursor.first + cursor.parts);
221
+ return Effect.as(Effect.andThen(bucketDeleteMany(input.bucket, [one]), bucketPut(input.bucket, one, read)), true);
222
+ }), () => Effect.sync(() => input.allotment.shrink(held)))) ? {
223
+ ...cursor,
224
+ first: cursor.first + cursor.parts,
225
+ parts: 1,
226
+ swept: cursor.first
227
+ } : started;
228
+ return {
229
+ change: {
230
+ put: [rowOf(id, row, { rebuild })],
231
+ rows: noRows
232
+ },
233
+ more: true
234
+ };
235
+ }
236
+ const bytes = graphBytes(cursor.commits, cursor.parents);
237
+ const dropped = cursor.first + cursor.parts - cursor.swept;
238
+ if (!finishing(input, cursor, calls, 0, bytes, dropped)) return yield* failed(id, row, `its .graph takes past a step's calls`);
239
+ const graph = yield* Effect.acquireUseRelease(input.allotment.grow(bytes + held, upkeepTooLarge), () => joinedGraph(input, id, cursor), () => Effect.sync(() => input.allotment.shrink(bytes + held)));
240
+ if (graph === void 0) return {
241
+ change: {
242
+ put: [rowOf(id, row, { rebuild: started })],
243
+ rows: noRows
244
+ },
245
+ more: true
246
+ };
247
+ yield* bucketDeleteMany(input.bucket, [packFiles(id).graph]);
248
+ yield* bucketPut(input.bucket, packFiles(id).graph, graph);
249
+ yield* dropRuns(input.bucket, id);
250
+ return {
251
+ change: {
252
+ put: [packRow({
253
+ ...pack,
254
+ graphBytes: graph.byteLength
255
+ })],
256
+ delete: [refusedKey(id)],
257
+ rows: noRows
258
+ },
259
+ more: true
260
+ };
261
+ });
262
+ export { rebuildStep, rebuildWindowRanks, rebuildable };
@@ -58,22 +58,29 @@ const edgesHeaderBytes = 24;
58
58
  const noNumber = 4294967295;
59
59
  /** A bitmap kept whole, not as the XOR of another. */
60
60
  const noBase = 4294967295;
61
+ /** No root positions: a repo with no roots. */
62
+ const noRootPositions = /* @__PURE__ */ new Set();
61
63
  /**
62
64
  * A slice's edges file from its links and their joined `targets`, those a shallow commit lacks
63
- * left out: what it covers, and its bytes.
65
+ * left out, and the parents of each commit at one of `roots`, the repo's roots by position, so no
66
+ * reach passes a root: what it covers, and its bytes.
64
67
  */
65
- const edgesFileOf = (key, first, positions, links, targets) => {
66
- let kept = 0;
67
- for (const target of targets) if (target !== 4294967295) kept += 1;
68
+ const edgesFileOf = (key, first, positions, links, targets, roots = noRootPositions) => {
68
69
  const sources = links.sources;
69
- const bytes = new Uint8Array(edgesHeaderBytes + sources * 8 + 4 + kept * 4);
70
+ const kept = (source, at, from) => targets[at] !== void 0 && targets[at] !== 4294967295 && !(roots.has(links.positionOf(source)) && links.mayLack(source, at - from));
71
+ let count = 0;
72
+ for (let source = 0; source < sources; source += 1) {
73
+ const [from, to] = links.linksOf(source);
74
+ for (let at = from; at < to; at += 1) if (kept(source, at, from)) count += 1;
75
+ }
76
+ const bytes = new Uint8Array(edgesHeaderBytes + sources * 8 + 4 + count * 4);
70
77
  const view = new DataView(bytes.buffer);
71
78
  bytes.set(edgesMagic);
72
79
  view.setUint32(4, 1);
73
80
  view.setUint32(8, first);
74
81
  view.setUint32(12, positions);
75
82
  view.setUint32(16, sources);
76
- view.setUint32(20, kept);
83
+ view.setUint32(20, count);
77
84
  const starts = edgesHeaderBytes + sources * 4;
78
85
  const ends = starts + (sources + 1) * 4;
79
86
  let link = 0;
@@ -82,9 +89,8 @@ const edgesFileOf = (key, first, positions, links, targets) => {
82
89
  view.setUint32(starts + source * 4, link);
83
90
  const [from, to] = links.linksOf(source);
84
91
  for (let at = from; at < to; at += 1) {
85
- const target = targets[at] ?? 4294967295;
86
- if (target === 4294967295) continue;
87
- view.setUint32(ends + link * 4, target);
92
+ if (!kept(source, at, from)) continue;
93
+ view.setUint32(ends + link * 4, targets[at] ?? 4294967295);
88
94
  link += 1;
89
95
  }
90
96
  }
@@ -95,7 +101,7 @@ const edgesFileOf = (key, first, positions, links, targets) => {
95
101
  first,
96
102
  positions,
97
103
  sources,
98
- links: kept
104
+ links: count
99
105
  },
100
106
  bytes
101
107
  };