@ref0/git 0.2.0 → 0.3.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 (113) hide show
  1. package/dist/auth/authorize.d.mts +1 -1
  2. package/dist/auth/fences.d.mts +1 -1
  3. package/dist/auth/host-function.mjs +2 -2
  4. package/dist/auth/identify.d.mts +1 -1
  5. package/dist/auth/tokens.d.mts +1 -1
  6. package/dist/client/client.mjs +2 -3
  7. package/dist/client/local.mjs +13 -3
  8. package/dist/contracts/calls-spent.mjs +3 -2
  9. package/dist/contracts/client.d.mts +2 -2
  10. package/dist/contracts/handlers.d.mts +2 -1
  11. package/dist/contracts/objects.d.mts +2 -2
  12. package/dist/contracts/promises.d.mts +13 -38
  13. package/dist/contracts/promises.mjs +13 -0
  14. package/dist/contracts/queue.d.mts +2 -1
  15. package/dist/contracts/result.d.mts +7 -0
  16. package/dist/contracts/server.d.mts +67 -40
  17. package/dist/contracts/sync.d.mts +1 -1
  18. package/dist/contracts/topics.d.mts +7 -1
  19. package/dist/core/access.d.mts +1 -1
  20. package/dist/core/call-names.d.mts +1 -0
  21. package/dist/core/call-names.mjs +93 -0
  22. package/dist/core/events/deliver.mjs +14 -7
  23. package/dist/core/events/stream.d.mts +1 -1
  24. package/dist/core/events/stream.mjs +8 -1
  25. package/dist/core/hooks/post-receive.mjs +15 -7
  26. package/dist/core/promise.mjs +28 -10
  27. package/dist/core/push.mjs +2 -1
  28. package/dist/core/seam.d.mts +2 -0
  29. package/dist/core/seam.mjs +19 -6
  30. package/dist/extend.d.mts +2 -1
  31. package/dist/extend.mjs +3 -1
  32. package/dist/index.d.mts +2 -2
  33. package/dist/lfs/objects.mjs +1 -1
  34. package/dist/lfs/rows.mjs +1 -1
  35. package/dist/queue/advance.mjs +2 -1
  36. package/dist/queue/host.d.mts +1 -1
  37. package/dist/queue/host.mjs +1 -1
  38. package/dist/queue/schedule.mjs +1 -1
  39. package/dist/rest/blobs.d.mts +15 -15
  40. package/dist/rest/client.mjs +2 -2
  41. package/dist/rest/commits.d.mts +91 -91
  42. package/dist/rest/errors.d.mts +2 -2
  43. package/dist/rest/errors.mjs +2 -2
  44. package/dist/rest/files.d.mts +81 -81
  45. package/dist/rest/handler.d.mts +1 -0
  46. package/dist/rest/handler.mjs +39 -16
  47. package/dist/rest/handlers.mjs +6 -6
  48. package/dist/rest/repos.d.mts +38 -38
  49. package/dist/rest/tags.d.mts +41 -41
  50. package/dist/rest/tokens.d.mts +145 -145
  51. package/dist/rest/work.d.mts +43 -43
  52. package/dist/server/extension.d.mts +6 -3
  53. package/dist/server/extension.mjs +39 -31
  54. package/dist/server/lifecycle.d.mts +3 -0
  55. package/dist/server/lifecycle.mjs +89 -0
  56. package/dist/server/routes.d.mts +7 -4
  57. package/dist/server/routes.mjs +12 -19
  58. package/dist/server/server.d.mts +8 -2
  59. package/dist/server/server.mjs +280 -104
  60. package/dist/signin/context.d.mts +1 -1
  61. package/dist/signin/grants.d.mts +1 -1
  62. package/dist/storage/bits.mjs +41 -0
  63. package/dist/storage/calls.d.mts +1 -1
  64. package/dist/storage/calls.mjs +2 -2
  65. package/dist/storage/fetch.d.mts +3 -1
  66. package/dist/storage/fetch.mjs +230 -24
  67. package/dist/storage/index-bitmaps.d.mts +1 -1
  68. package/dist/storage/index-build.d.mts +1 -1
  69. package/dist/storage/index-build.mjs +27 -13
  70. package/dist/storage/index-fetch.d.mts +1 -0
  71. package/dist/storage/index-fetch.mjs +103 -182
  72. package/dist/storage/index-graph.d.mts +1 -1
  73. package/dist/storage/loose.mjs +3 -2
  74. package/dist/storage/pack-order.d.mts +1 -1
  75. package/dist/storage/pack-order.mjs +3 -1
  76. package/dist/storage/pack-ranges.d.mts +1 -1
  77. package/dist/storage/pack-reads.d.mts +1 -1
  78. package/dist/storage/pack-reads.mjs +17 -0
  79. package/dist/storage/pack-receive.d.mts +2 -2
  80. package/dist/storage/pack-receive.mjs +1 -1
  81. package/dist/storage/packs.d.mts +2 -2
  82. package/dist/storage/packs.mjs +10 -7
  83. package/dist/storage/push-uploads.mjs +2 -1
  84. package/dist/storage/ready.d.mts +2 -2
  85. package/dist/storage/receive-links.mjs +1 -1
  86. package/dist/storage/repack.d.mts +2 -2
  87. package/dist/storage/rows.d.mts +2 -1
  88. package/dist/storage/rows.mjs +1 -1
  89. package/dist/storage/send-list.d.mts +8 -0
  90. package/dist/storage/send-list.mjs +319 -0
  91. package/dist/storage/shallow.d.mts +1 -2
  92. package/dist/storage/unpack.mjs +5 -3
  93. package/dist/storage/walk.d.mts +2 -1
  94. package/dist/storage/walk.mjs +14 -8
  95. package/dist/store/catalogue.d.mts +1 -1
  96. package/dist/store/closed.d.mts +21 -0
  97. package/dist/store/closed.mjs +34 -0
  98. package/dist/store/crossing.mjs +9 -6
  99. package/dist/store/cursor-seal.mjs +4 -1
  100. package/dist/store/errors.mjs +13 -7
  101. package/dist/store/outbox.mjs +4 -2
  102. package/dist/store/promises.d.mts +5 -0
  103. package/dist/store/promises.mjs +258 -0
  104. package/dist/sync/bound.mjs +9 -4
  105. package/dist/sync/jobs.d.mts +3 -3
  106. package/dist/sync/jobs.mjs +28 -25
  107. package/dist/sync/tries.mjs +2 -2
  108. package/dist/topics/advance.mjs +2 -1
  109. package/dist/topics/calls.mjs +3 -3
  110. package/dist/topics/host.d.mts +1 -1
  111. package/dist/topics/host.mjs +1 -1
  112. package/dist/topics/topic.mjs +22 -7
  113. package/package.json +2 -2
@@ -3,16 +3,16 @@ import "../protocol/objects/object.mjs";
3
3
  import { oidBytes } from "../protocol/packs/idx.mjs";
4
4
  import { gitError } from "../store/errors.mjs";
5
5
  import { repoScope } from "../store/scopes.mjs";
6
+ import { anySet, bitCount, clearBit, isSet, nextSet, setBit } from "./bits.mjs";
6
7
  import { bitmapWords } from "./ewah.mjs";
7
8
  import { ewahMostWords } from "./index-bitmaps.mjs";
8
9
  import { builtIndexOf, coversAll, decodeIndexValue } from "./index-build.mjs";
9
10
  import { openTypes, typeOfCode } from "./index-files.mjs";
11
+ import { listOf } from "./send-list.mjs";
10
12
  import { ByGeneration, graphChunk, graphRows, openGraphLayers, openIndexGraph } from "./index-graph.mjs";
11
13
  import { lookupCalls, openLayerBitmaps, openLayout, orWords } from "./index-layers.mjs";
12
- import { indexFiles, indexRowKey, packFiles } from "./layout.mjs";
14
+ import { indexFiles, indexRowKey } from "./layout.mjs";
13
15
  import { joinBytes, missing } from "./link-join.mjs";
14
- import { readWhole } from "./pack-reads.mjs";
15
- import { rangeRanks } from "./pack-ranges.mjs";
16
16
  import { lost } from "./walk.mjs";
17
17
  import * as Effect from "effect/Effect";
18
18
  import * as Data from "effect/Data";
@@ -43,11 +43,10 @@ const rangeEntriesBytes = 64 * keptEntryBytes;
43
43
  /** The most a fetch keeps of its packs' `.idx` and `.pos` ranges across the walk's levels. */
44
44
  const rangeCacheMost = 16777216;
45
45
  /**
46
- * What a rank takes of a pack's `.idx` and `.pos` as the walk keeps them: its ID and its place, 24
47
- * B, twice, as a search's range and a join's chunk may both hold it. With a reader's `.idx`, its
48
- * place alone, 4 B, twice.
46
+ * What a rank takes of a pack's `.pos` as the walk keeps it, the reader holding its `.idx`: its
47
+ * place, 4 B, twice, as a search's range and a join's chunk may both hold it.
49
48
  */
50
- const rankBytes = (indexed) => indexed ? 8 : 48;
49
+ const rankBytes = 8;
51
50
  /**
52
51
  * `bucket`, its `.idx` and `.pos` range reads kept up to `most` bytes, the least recently used let
53
52
  * go first, and replayed from memory: what the caller charged for them. Every other read goes
@@ -56,14 +55,15 @@ const rankBytes = (indexed) => indexed ? 8 : 48;
56
55
  const rangeCached = (bucket, most) => {
57
56
  const kept = /* @__PURE__ */ new Map();
58
57
  let held = 0;
58
+ let closed = false;
59
59
  const streamOf = (bytes) => new Blob([bytes.slice()]).stream();
60
- return {
60
+ const cached = {
61
61
  ...bucket,
62
62
  put: (key, body, options) => bucket.put(key, body, options),
63
63
  delete: (key, options) => bucket.delete(key, options),
64
64
  list: (prefix, page, options) => bucket.list(prefix, page, options),
65
65
  read: async (key, range, options) => {
66
- if (!(key.endsWith(".idx") || key.endsWith(".pos")) || range === void 0 || range.offset === 0) return bucket.read(key, range, options);
66
+ if (closed || !(key.endsWith(".idx") || key.endsWith(".pos")) || range === void 0 || range.offset === 0) return bucket.read(key, range, options);
67
67
  const at = `${key}@${range.offset}+${range.length}`;
68
68
  const found = kept.get(at);
69
69
  if (found !== void 0) {
@@ -87,6 +87,15 @@ const rangeCached = (bucket, most) => {
87
87
  return streamOf(bytes);
88
88
  }
89
89
  };
90
+ const clear = () => {
91
+ kept.clear();
92
+ held = 0;
93
+ closed = true;
94
+ };
95
+ return {
96
+ bucket: cached,
97
+ clear
98
+ };
90
99
  };
91
100
  /**
92
101
  * What one stored bitmap holds once its layer's bitmaps are open: its table row as read and its
@@ -131,12 +140,11 @@ const rowsOf = (layer) => layer.groups.reduce((sum, group) => sum + group.rows,
131
140
  * The most bucket calls opening an index's layers for a fetch makes: each layer's `.graph`'s two
132
141
  * (head and fanout, tail), its `.bitmaps`' three when it has any (head, table, tail), its
133
142
  * `.types` header's one, its region's one when it has rows, and each of its packs' `.pos` header.
134
- * With no reader's `.idx` to take (`indexed` false), each pack's `.idx` head and fanout too. A
135
- * reader's own load of a pack's `.idx` and `.rev` is the walk's cost, checked as the walk checks
143
+ * A reader's own load of a pack's `.idx` and `.rev` is the walk's cost, checked as the walk checks
136
144
  * its loads. The row's own read is the one store call before it (#522).
137
145
  */
138
- const fetchOpenCalls = (layers, indexed) => ({
139
- bucket: layers.reduce((sum, layer) => sum + 2 + (layer.bitmaps > 0 ? 3 : 0) + 1 + (rowsOf(layer) > 0 ? 1 : 0) + (indexed ? 1 : 2) * packsOf(layer), 0),
146
+ const fetchOpenCalls = (layers) => ({
147
+ bucket: layers.reduce((sum, layer) => sum + 2 + (layer.bitmaps > 0 ? 3 : 0) + 1 + (rowsOf(layer) > 0 ? 1 : 0) + packsOf(layer), 0),
140
148
  store: 0
141
149
  });
142
150
  /**
@@ -167,7 +175,7 @@ const openFetchIndex = Effect.fnUntraced(function* (source, ahead, read, graphCh
167
175
  });
168
176
  const row = builtIndexOf(decodeIndexValue(snapshot.results[0]?.[0]?.value));
169
177
  if (row === void 0 || !coversAll(row.layers, listed)) return void 0;
170
- yield* ahead(fetchOpenCalls(row.layers, indexed !== void 0));
178
+ yield* ahead(fetchOpenCalls(row.layers));
171
179
  yield* hold(regionBytes(row.layers));
172
180
  const graphs = [];
173
181
  let first = 0;
@@ -183,9 +191,11 @@ const openFetchIndex = Effect.fnUntraced(function* (source, ahead, read, graphCh
183
191
  const bitmaps = yield* openLayerBitmaps(bucket, listed.repo, row.layers);
184
192
  const types = yield* Effect.forEach(row.layers, (layer) => openTypes(bucket, indexFiles(listed.repo, layer.build).types, layer.positions));
185
193
  const covered = new Set(row.layers.flatMap((layer) => layer.groups.flatMap((group) => group.packs)));
186
- const rangeBytes = Math.min(rangeCacheMost, listed.packs.filter(({ id }) => covered.has(id)).reduce((sum, pack) => sum + pack.objects * rankBytes(indexed !== void 0) + rangeEntriesBytes, 0));
194
+ const rangeBytes = Math.min(rangeCacheMost, listed.packs.filter(({ id }) => covered.has(id)).reduce((sum, pack) => sum + pack.objects * rankBytes + rangeEntriesBytes, 0));
187
195
  yield* hold(rangeBytes);
188
- const layout = yield* openLayout(rangeCached(bucket, rangeBytes), listed, row.layers, indexed);
196
+ const ranges = rangeCached(bucket, rangeBytes);
197
+ const layout = yield* openLayout(ranges.bucket, listed, row.layers, indexed);
198
+ const letRangesGo = Effect.andThen(Effect.sync(ranges.clear), read.release(rangeBytes));
189
199
  const last = row.layers[row.layers.length - 1];
190
200
  const positions = last === void 0 ? 0 : last.first + last.positions;
191
201
  if (layout.positions !== positions) return yield* Effect.fail(loss(`The index's layers hold ${layout.positions} positions, its row ${positions}`));
@@ -198,7 +208,8 @@ const openFetchIndex = Effect.fnUntraced(function* (source, ahead, read, graphCh
198
208
  bitmaps,
199
209
  types,
200
210
  layout,
201
- numberAt
211
+ numberAt,
212
+ letRangesGo
202
213
  };
203
214
  });
204
215
  /** Commit `id`'s graph number among `graphs`, a get each layer until one holds it, or `undefined`. */
@@ -209,13 +220,6 @@ const numberIn = Effect.fnUntraced(function* (graphs, id, checked) {
209
220
  if (number !== void 0) return number;
210
221
  }
211
222
  });
212
- const isSet = (bits, at) => ((bits[at >>> 5] ?? 0) >>> (at & 31) & 1) === 1;
213
- const setBit = (bits, at) => {
214
- bits[at >>> 5] = ((bits[at >>> 5] ?? 0) | 1 << (at & 31)) >>> 0;
215
- };
216
- const clearBit = (bits, at) => {
217
- bits[at >>> 5] = ((bits[at >>> 5] ?? 0) & ~(1 << (at & 31))) >>> 0;
218
- };
219
223
  /** IDs, 20 bytes each, and a kind for each, grown as a level's trees name them. */
220
224
  var Frontier = class {
221
225
  ids = /* @__PURE__ */ new Uint8Array(1280);
@@ -248,9 +252,15 @@ const blobKind = 2;
248
252
  const indexSendSet = (input) => indexSendSetOrNot(input).pipe(Effect.catchTag("Unindexed", () => Effect.succeed(void 0)));
249
253
  const indexSendSetOrNot = Effect.fnUntraced(function* (input) {
250
254
  const { source, read, request, ahead } = input;
251
- if (!indexEligible(request)) return void 0;
255
+ const { indexed, sizesAt, heldAt } = read;
256
+ if (!indexEligible(request) || indexed === void 0 || sizesAt === void 0 || heldAt === void 0) return void 0;
252
257
  const checked = ahead(noCalls);
253
- const index = yield* openFetchIndex(source, ahead, read, (graphs) => wantsChecked(graphs, read, request.wants, checked));
258
+ const opening = {
259
+ hold: read.hold,
260
+ release: read.release,
261
+ indexed
262
+ };
263
+ const index = yield* openFetchIndex(source, ahead, opening, (graphs) => wantsChecked(graphs, read, request.wants, checked));
254
264
  if (index === void 0) return void 0;
255
265
  const { graph, graphs, bitmaps, layout, numberAt, row } = index;
256
266
  const words = bitmapWords(layout.positions);
@@ -261,7 +271,6 @@ const indexSendSetOrNot = Effect.fnUntraced(function* (input) {
261
271
  const heldNumbers = new Uint32Array(commitWords);
262
272
  const heldExtras = /* @__PURE__ */ new Set();
263
273
  const sentExtras = /* @__PURE__ */ new Map();
264
- const sizeAt = /* @__PURE__ */ new Map();
265
274
  let decodePaid = false;
266
275
  let levelPaid = 0;
267
276
  const bitsOf = (side) => side === "held" ? held : wanted;
@@ -354,18 +363,15 @@ const indexSendSetOrNot = Effect.fnUntraced(function* (input) {
354
363
  return yield* Effect.fail(lost(oid));
355
364
  }
356
365
  if (tree.type !== "tree" || tree.entries === void 0) return yield* Effect.fail(loss(`${oid}, named as a tree, is a ${tree.type}`));
357
- if (side === "wanted") {
358
- if (position === 4294967295) {
359
- const extra = sentExtras.get(oid);
360
- if (extra !== void 0) extra.size = tree.size;
361
- } else sizeAt.set(position, tree.size);
362
- }
366
+ const extra = side === "wanted" && position === 4294967295 ? sentExtras.get(oid) : void 0;
367
+ if (extra !== void 0) extra.size = tree.size;
363
368
  const growing = next.count + tree.entries.trees.length + tree.entries.blobs.length;
364
369
  yield* holdStep(Frontier.bytes(frontier.count) + frontier.count * 4 + Frontier.bytes(growing));
365
370
  for (const entry of tree.entries.trees) next.add(oidBytes(entry), treeKind);
366
371
  for (const entry of tree.entries.blobs) next.add(oidBytes(entry), blobKind);
367
372
  read.letGo(tree);
368
373
  }
374
+ yield* read.letGoReads(asked.length);
369
375
  }
370
376
  frontier = next;
371
377
  }
@@ -457,7 +463,6 @@ const indexSendSetOrNot = Effect.fnUntraced(function* (input) {
457
463
  continue;
458
464
  }
459
465
  setBit(bits, position);
460
- if (side === "wanted") sizeAt.set(position, object.size);
461
466
  follow(object);
462
467
  }
463
468
  for (const oid of unplaced) {
@@ -502,24 +507,22 @@ const indexSendSetOrNot = Effect.fnUntraced(function* (input) {
502
507
  const ids = yield* graph.idsAt(walked);
503
508
  const positions = yield* joined(ids, walked.length);
504
509
  const reading = [];
505
- const placed = [];
506
510
  for (let at = 0; at < walked.length; at += 1) {
507
511
  const position = positions[at] ?? 4294967295;
508
512
  if (position === 4294967295) return yield* Effect.fail(loss(`Commit ${walked[at]} of the graph has no position`));
509
513
  if (blocked(side, position)) continue;
510
514
  setBit(bits, position);
511
515
  reading.push(hexOf(ids.subarray(at * 20, at * 20 + 20)));
512
- placed.push(position);
513
516
  }
514
517
  for (let from = 0; from < reading.length; from += treesAtOnce) {
515
518
  const asked = reading.slice(from, from + treesAtOnce);
516
519
  const found = yield* read(asked);
517
- for (const [at, oid] of asked.entries()) {
520
+ for (const oid of asked) {
518
521
  const commit = found.get(oid);
519
522
  if (commit?.type !== "commit") return yield* Effect.fail(lost(oid));
520
- if (side === "wanted") sizeAt.set(placed[from + at] ?? 0, commit.size);
521
523
  if (commit.tree !== void 0) roots.push(commit.tree);
522
524
  }
525
+ yield* read.letGoReads(asked.length);
523
526
  }
524
527
  }
525
528
  yield* levels(side, roots);
@@ -532,6 +535,17 @@ const indexSendSetOrNot = Effect.fnUntraced(function* (input) {
532
535
  const dropsTrees = filter?.kind === "tree";
533
536
  const dropsBlobs = dropsTrees || filter?.kind === "blob:none";
534
537
  for (const [oid, extra] of sentExtras) if (extra.kind === "tree" && dropsTrees || extra.kind === "blob" && dropsBlobs) sentExtras.delete(oid);
538
+ const had = new Set(request.haves);
539
+ if (input.tags.length > 0) {
540
+ const tagIds = new Uint8Array(input.tags.length * 20);
541
+ for (const [at, tag] of input.tags.entries()) tagIds.set(oidBytes(tag), at * 20);
542
+ const positions = yield* joined(tagIds, input.tags.length);
543
+ for (const [at, tag] of input.tags.entries()) {
544
+ const position = positions[at] ?? 4294967295;
545
+ if (position === 4294967295 ? heldExtras.has(tag) : isSet(held, position)) had.add(tag);
546
+ }
547
+ }
548
+ yield* index.letRangesGo;
535
549
  const windows = [];
536
550
  for (const [at, layer] of row.layers.entries()) {
537
551
  const types = index.types[at];
@@ -547,55 +561,65 @@ const indexSendSetOrNot = Effect.fnUntraced(function* (input) {
547
561
  });
548
562
  }
549
563
  }
550
- let idGets = 0;
551
- for (const ranges of layout.ranges) {
552
- if (ranges.reverse !== void 0) continue;
553
- const chunks = Math.ceil(ranges.count / rangeRanks);
554
- let revWindows = 0;
555
- for (let place = 0; place < ranges.count; place += rangeRanks) if (anySet(send, ranges.base + place, ranges.base + Math.min(ranges.count, place + 32768))) revWindows += 1;
556
- if (revWindows > 0) idGets += revWindows + Math.min(chunks, countSet(send, ranges.base, ranges.base + ranges.count));
557
- }
558
564
  yield* ahead({
559
- bucket: windows.length + idGets,
565
+ bucket: windows.length,
560
566
  store: 0
561
567
  });
562
568
  let sending = 0;
563
569
  for (let at = 0; at < words; at += 1) sending += bitCount(send[at] ?? 0);
564
- yield* read.hold(sending * 5);
565
- const sent = new Uint32Array(sending);
570
+ yield* read.hold(sending * 10);
566
571
  const kinds = new Uint8Array(sending);
572
+ const regionRows = [];
573
+ const { ranges } = layout;
567
574
  let count = 0;
575
+ let range = 0;
568
576
  for (const { types, first, from, to } of windows) {
569
577
  const codes = yield* types.codesOf(from - first, to - first);
570
- for (let at = from; at < to; at += 1) {
571
- if (!isSet(send, at)) continue;
578
+ for (let at = nextSet(send, from, to); at < to; at = nextSet(send, at + 1, to)) {
572
579
  const code = codes[at - from] ?? 0;
573
- if (code === 1 && dropsTrees || code === 2 && dropsBlobs) {
580
+ while (range < ranges.length && at >= (ranges[range]?.base ?? 0) + (ranges[range]?.count ?? 0)) range += 1;
581
+ const dropped = code === 1 && dropsTrees || code === 2 && dropsBlobs;
582
+ const inPack = at >= (ranges[range]?.base ?? Number.POSITIVE_INFINITY);
583
+ if (dropped || !inPack) {
574
584
  clearBit(send, at);
585
+ if (!dropped) regionRows.push({
586
+ position: at,
587
+ code
588
+ });
575
589
  continue;
576
590
  }
577
- sent[count] = at;
578
591
  kinds[count] = code;
579
592
  count += 1;
580
593
  }
581
594
  }
582
- if (filter?.kind !== "blob:limit" && count + sentExtras.size > input.objectsMost) return yield* Effect.fail(input.tooMany);
583
- const ids = yield* sentIdsOf(source.bucket, layout, sent.subarray(0, count), read.hold);
584
- const oids = Array.from({ length: count }, (_, at) => hexOf(ids.subarray(at * 20, at * 20 + 20)));
585
- const unsized = [];
586
- for (const [at, oid] of oids.entries()) if (!sizeAt.has(sent[at] ?? 0)) unsized.push(oid);
587
- for (const [oid, extra] of sentExtras) if (extra.size === void 0) unsized.push(oid);
595
+ if (filter?.kind !== "blob:limit" && count + regionRows.length + sentExtras.size > input.objectsMost) return yield* Effect.fail(input.tooMany);
596
+ const listInput = {
597
+ send,
598
+ count,
599
+ kinds,
600
+ ranges,
601
+ layers: row.layers,
602
+ listed: source.listed,
603
+ bucket: source.bucket,
604
+ read,
605
+ ahead
606
+ };
607
+ if (filter?.kind === "blob:limit") listInput.blobsUnder = filter.bytes;
608
+ const list = yield* listOf(listInput);
609
+ const rowIds = [];
610
+ for (const { position } of regionRows) rowIds.push(hexOf(yield* layout.idAt(position)));
611
+ const unsized = [...rowIds, ...[...sentExtras].flatMap(([oid, extra]) => extra.size === void 0 ? [oid] : [])];
588
612
  const sizes = unsized.length === 0 ? /* @__PURE__ */ new Map() : yield* read.sizes(unsized);
589
613
  const sizeOf = (oid, known) => {
590
614
  const size = known ?? sizes.get(oid);
591
615
  return size === void 0 ? Effect.fail(lost(oid)) : Effect.succeed(size);
592
616
  };
593
617
  const keeps = (kind, size) => filter?.kind !== "blob:limit" || kind !== "blob" || size < filter.bytes;
594
- const objects = [];
595
- for (const [at, oid] of oids.entries()) {
596
- const kind = typeOfCode[kinds[at] ?? 0] ?? "blob";
597
- const size = yield* sizeOf(oid, sizeAt.get(sent[at] ?? 0));
598
- if (keeps(kind, size)) objects.push({
618
+ const rest = [];
619
+ for (const [at, oid] of rowIds.entries()) {
620
+ const kind = typeOfCode[regionRows[at]?.code ?? 0] ?? "blob";
621
+ const size = yield* sizeOf(oid, void 0);
622
+ if (keeps(kind, size)) rest.push({
599
623
  oid,
600
624
  kind,
601
625
  size
@@ -603,26 +627,27 @@ const indexSendSetOrNot = Effect.fnUntraced(function* (input) {
603
627
  }
604
628
  for (const [oid, extra] of sentExtras) {
605
629
  const size = yield* sizeOf(oid, extra.size);
606
- if (keeps(extra.kind, size)) objects.push({
630
+ if (keeps(extra.kind, size)) rest.push({
607
631
  oid,
608
632
  kind: extra.kind,
609
633
  size
610
634
  });
611
635
  }
612
- if (objects.length > input.objectsMost) return yield* Effect.fail(input.tooMany);
613
- const had = new Set(request.haves);
614
- if (input.tags.length > 0) {
615
- const tagIds = new Uint8Array(input.tags.length * 20);
616
- for (const [at, tag] of input.tags.entries()) tagIds.set(oidBytes(tag), at * 20);
617
- const positions = yield* joined(tagIds, input.tags.length);
618
- for (const [at, tag] of input.tags.entries()) {
619
- const position = positions[at] ?? 4294967295;
620
- if (position === 4294967295 ? heldExtras.has(tag) : isSet(held, position)) had.add(tag);
621
- }
622
- }
636
+ if (list.count + rest.length > input.objectsMost) return yield* Effect.fail(input.tooMany);
637
+ const restIds = new Set(rest.map((object) => object.oid));
623
638
  return {
624
- objects,
625
- had
639
+ list,
640
+ rest,
641
+ had,
642
+ sentOf: Effect.fnUntraced(function* (oids) {
643
+ const ids = new Uint8Array(oids.length * 20);
644
+ for (const [at, oid] of oids.entries()) ids.set(oidBytes(oid), at * 20);
645
+ const positions = yield* joined(ids, oids.length);
646
+ return new Set(oids.filter((oid, at) => {
647
+ const position = positions[at] ?? 4294967295;
648
+ return restIds.has(oid) || position !== 4294967295 && isSet(send, position);
649
+ }));
650
+ })
626
651
  };
627
652
  });
628
653
  /**
@@ -649,108 +674,4 @@ const wantsChecked = Effect.fnUntraced(function* (graphs, read, wants, checked)
649
674
  for (const link of new Set(next)) if ((yield* numberIn(graphs, oidBytes(link), checked)) === void 0) reading.push(link);
650
675
  }
651
676
  });
652
- const bitCount = (word) => {
653
- let bits = word - (word >>> 1 & 1431655765);
654
- bits = (bits & 858993459) + (bits >>> 2 & 858993459);
655
- return (bits + (bits >>> 4) & 252645135) * 16843009 >>> 24;
656
- };
657
- /** How many bits of `bits` in `[from, to)` are set. */
658
- const countSet = (bits, from, to) => {
659
- let count = 0;
660
- for (let at = from; at < to && at < bits.length * 32;) {
661
- if ((at & 31) === 0 && at + 32 <= to) {
662
- count += bitCount(bits[at >>> 5] ?? 0);
663
- at += 32;
664
- continue;
665
- }
666
- if (isSet(bits, at)) count += 1;
667
- at += 1;
668
- }
669
- return count;
670
- };
671
- /** Whether any bit of `bits` in `[from, to)` is set. */
672
- const anySet = (bits, from, to) => {
673
- if (from >= to) return false;
674
- const first = from >>> 5;
675
- const last = to - 1 >>> 5;
676
- for (let at = first; at <= last; at += 1) {
677
- let word = bits[at] ?? 0;
678
- if (at === first) word &= -1 << (from & 31);
679
- if (at === last && (to & 31) !== 0) word &= (1 << (to & 31)) - 1;
680
- if (word !== 0) return true;
681
- }
682
- return false;
683
- };
684
- const word = (bytes, at) => (bytes[at] ?? 0) * 2 ** 24 + ((bytes[at + 1] ?? 0) << 16) + ((bytes[at + 2] ?? 0) << 8) + (bytes[at + 3] ?? 0) >>> 0;
685
- /** A `.rev`'s header: `RIDX`, its version and its hash function. */
686
- const revHeaderBytes = 12;
687
- /**
688
- * The IDs of `positions`, ascending, 20 bytes each in their order: a pack's through its `.rev`,
689
- * read by range for the places it sends, a `rangeRanks` window at most a read, then its `.idx` IDs
690
- * by rank; a layer's rows from the `.region` IDs the layout holds. A pack's `.rev` is stored before
691
- * the pack is listed, so a miss fails.
692
- * Its memory is the IDs, a rank and a slot each sent object, and one window.
693
- */
694
- const sentIdsOf = Effect.fnUntraced(function* (bucket, layout, positions, hold) {
695
- yield* hold(positions.length * 28 + rangeRanks * 20);
696
- const out = new Uint8Array(positions.length * 20);
697
- let at = 0;
698
- const rowsBefore = (end) => Effect.gen(function* () {
699
- for (; at < positions.length && (positions[at] ?? 0) < end; at += 1) out.set(yield* layout.idAt(positions[at] ?? 0), at * 20);
700
- });
701
- for (const ranges of layout.ranges) {
702
- yield* rowsBefore(ranges.base);
703
- const end = ranges.base + ranges.count;
704
- const from = at;
705
- while (at < positions.length && (positions[at] ?? 0) < end) at += 1;
706
- if (at > from) yield* packIds(bucket, ranges, positions.subarray(from, at), out.subarray(from * 20));
707
- }
708
- yield* rowsBefore(Number.POSITIVE_INFINITY);
709
- return out;
710
- });
711
- /** One pack's IDs of `positions`, all in it, ascending, into `out` in their order. */
712
- const packIds = Effect.fnUntraced(function* (bucket, ranges, positions, out) {
713
- const key = packFiles(ranges.pack.id).rev;
714
- const ranks = new Uint32Array(positions.length);
715
- const { reverse } = ranges;
716
- if (reverse !== void 0) for (const [at, position] of positions.entries()) {
717
- const rank = reverse.rankAt(position - ranges.base);
718
- if (rank >= ranges.count) return yield* Effect.fail(loss(`${key} names rank ${rank}`));
719
- ranks[at] = rank;
720
- }
721
- for (let from = 0; reverse === void 0 && from < positions.length;) {
722
- const window = Math.floor(((positions[from] ?? 0) - ranges.base) / rangeRanks);
723
- let to = from;
724
- while (to < positions.length && Math.floor(((positions[to] ?? 0) - ranges.base) / 32768) === window) to += 1;
725
- const first = (positions[from] ?? 0) - ranges.base;
726
- const last = (positions[to - 1] ?? 0) - ranges.base;
727
- const bytes = yield* readWhole(bucket, key, {
728
- offset: revHeaderBytes + first * 4,
729
- length: (last - first + 1) * 4
730
- });
731
- if (bytes === void 0) return yield* Effect.fail(loss(`Pack ${ranges.pack.id} has no reverse index`));
732
- if (bytes.byteLength !== (last - first + 1) * 4) return yield* Effect.fail(loss(`${key} is missing its bytes from ${first}`));
733
- for (let each = from; each < to; each += 1) {
734
- const rank = word(bytes, ((positions[each] ?? 0) - ranges.base - first) * 4);
735
- if (rank >= ranges.count) return yield* Effect.fail(loss(`${key} names rank ${rank}`));
736
- ranks[each] = rank;
737
- }
738
- from = to;
739
- }
740
- const order = Uint32Array.from(ranks.keys()).sort((a, b) => (ranks[a] ?? 0) - (ranks[b] ?? 0));
741
- for (let from = 0; from < order.length;) {
742
- const window = Math.floor((ranks[order[from] ?? 0] ?? 0) / rangeRanks);
743
- let to = from;
744
- while (to < order.length && Math.floor((ranks[order[to] ?? 0] ?? 0) / 32768) === window) to += 1;
745
- const first = ranks[order[from] ?? 0] ?? 0;
746
- const last = ranks[order[to - 1] ?? 0] ?? 0;
747
- const ids = yield* ranges.ids(first, last - first + 1);
748
- for (let each = from; each < to; each += 1) {
749
- const slot = order[each] ?? 0;
750
- const rank = (ranks[slot] ?? 0) - first;
751
- out.set(ids.subarray(rank * 20, rank * 20 + 20), slot * 20);
752
- }
753
- from = to;
754
- }
755
- });
756
677
  export { fetchOpenCalls, indexSendSet };
@@ -1,3 +1,3 @@
1
- import "./memory-budget.mjs";
2
1
  import "../contracts/promises.mjs";
2
+ import "./memory-budget.mjs";
3
3
  import "effect/Effect";
@@ -21,8 +21,9 @@ const looseLimits = {
21
21
  objects: looseObjectsMost,
22
22
  bytes: commitBytes
23
23
  };
24
- const tooMany = (count) => gitError("RESOURCE_EXHAUSTED", `push has ${count.toLocaleString("en-US")} objects; loose() storage takes ${looseObjectsMost.toLocaleString("en-US")} per push`, {
25
- hint: "Use packs() storage, or push fewer commits at a time",
24
+ const tooMany = (count) => gitError("RESOURCE_EXHAUSTED", `push has ${count.toLocaleString("en-US")} objects; this server takes ${looseObjectsMost.toLocaleString("en-US")} per push`, {
25
+ hint: "Push fewer commits at a time",
26
+ hostHint: "Use packs() storage, which keeps a push's objects in the bucket",
26
27
  context: {
27
28
  reason: "too-large",
28
29
  total: count
@@ -1,8 +1,8 @@
1
+ import "../contracts/promises.mjs";
1
2
  import "../contracts/objects.mjs";
2
3
  import "../protocol/packs/indexer.mjs";
3
4
  import "../protocol/packs/step.mjs";
4
5
  import "../contracts/calls-spent.mjs";
5
6
  import "./pack-reads.mjs";
6
7
  import "./pack-ranges.mjs";
7
- import "../contracts/promises.mjs";
8
8
  import "effect/Effect";
@@ -53,6 +53,8 @@ const nothingSettled = (pack, position, most) => {
53
53
  };
54
54
  /** Whether `error` is a slice's refusal for settling nothing within its calls. */
55
55
  const isSliceRefused = (error) => error.cause instanceof SliceRefused;
56
+ /** A slice's refusal as its index row keeps it: the whole text, the host's `hostHint` in it. */
57
+ const sliceRefusal = (error) => error.cause instanceof SliceRefused ? error.cause.message : error.message;
56
58
  /** A source's kind as `SliceLinks` keeps it. */
57
59
  const sourceKinds = {
58
60
  tree: 0,
@@ -776,4 +778,4 @@ const sortPairs = (pairs, count) => {
776
778
  const sorted = Uint32Array.from(order.flatMap((each) => [pairs[each * 2] ?? 0, pairs[each * 2 + 1] ?? 0]));
777
779
  pairs.set(sorted);
778
780
  };
779
- export { SliceLinks, SliceRefused, cutAtSpent, deferredBytesMost, deferredMost, headsBytes, isSliceRefused, linksPastMemory, nothingSettled, readSlice, sliceEntriesMost, sliceReaderBytes, sliceWorkBytes, spentOf };
781
+ export { SliceLinks, SliceRefused, cutAtSpent, deferredBytesMost, deferredMost, headsBytes, isSliceRefused, linksPastMemory, nothingSettled, readSlice, sliceEntriesMost, sliceReaderBytes, sliceRefusal, sliceWorkBytes, spentOf };
@@ -1,5 +1,5 @@
1
+ import "../contracts/promises.mjs";
1
2
  import "../protocol/packs/idx.mjs";
2
3
  import "../protocol/packs/rev.mjs";
3
4
  import "./pack-reads.mjs";
4
- import "../contracts/promises.mjs";
5
5
  import "effect/Effect";
@@ -1,3 +1,4 @@
1
+ import "../contracts/promises.mjs";
1
2
  import "../contracts/objects.mjs";
2
3
  import "../contracts/services.mjs";
3
4
  import "../contracts/store.mjs";
@@ -7,5 +8,4 @@ import "../protocol/packs/indexer.mjs";
7
8
  import "../protocol/packs/step.mjs";
8
9
  import "../protocol/packs/reader.mjs";
9
10
  import "./object-rows.mjs";
10
- import "../contracts/promises.mjs";
11
11
  import "effect/Effect";
@@ -653,6 +653,12 @@ const packReader = (input) => {
653
653
  yield* each(oids, (object) => Effect.sync(() => void objects.set(object.oid, object)));
654
654
  return objects;
655
655
  });
656
+ /** Each of `entries` read whole where the index placed it, as `held` reads one it found. */
657
+ const heldAt = Effect.fnUntraced(function* (entries) {
658
+ const objects = /* @__PURE__ */ new Map();
659
+ for (const { oid, indexed, offset } of entries) objects.set(oid, yield* wholeAt(oid, indexed, offset));
660
+ return objects;
661
+ });
656
662
  /**
657
663
  * The size of the object an entry holds, from its header, or a delta's from its instructions'
658
664
  * header, its base never read; an entry whose header won't say is resolved whole.
@@ -680,6 +686,15 @@ const packReader = (input) => {
680
686
  return sized;
681
687
  });
682
688
  /**
689
+ * The size of each of `at`'s entries of `pack`, in its order, as `sizes` sizes them, with no
690
+ * look-up by ID: a fetch's send list knows each entry's place from the index (#522).
691
+ */
692
+ const sizesAt = Effect.fnUntraced(function* (pack, at) {
693
+ const sized = new Float64Array(at.length);
694
+ for (const [slot, { oid, offset }] of at.entries()) sized[slot] = yield* sizeAt(oid, pack, offset);
695
+ return sized;
696
+ });
697
+ /**
683
698
  * The type an entry holds, by headers alone: its own, or a delta's base's, followed through
684
699
  * offset and ID bases to the first entry that isn't a delta, at most `chainReads` entries deep,
685
700
  * the deepest a stored pack holds. An ID base is looked for in the delta's own pack first, then
@@ -952,11 +967,13 @@ const packReader = (input) => {
952
967
  return loaded;
953
968
  }),
954
969
  held,
970
+ heldAt,
955
971
  each,
956
972
  has,
957
973
  heldIn,
958
974
  headers,
959
975
  sizes,
976
+ sizesAt,
960
977
  stored,
961
978
  blocks,
962
979
  object,
@@ -1,3 +1,4 @@
1
+ import "../contracts/promises.mjs";
1
2
  import "../contracts/objects.mjs";
2
3
  import "../contracts/services.mjs";
3
4
  import "../contracts/store.mjs";
@@ -5,7 +6,6 @@ import "../protocol/packs/indexer.mjs";
5
6
  import "../protocol/packs/step.mjs";
6
7
  import "./lfs-pointers.mjs";
7
8
  import "./pack-reads.mjs";
8
- import "../contracts/promises.mjs";
9
- import { Duration, Moment } from "@ref0/infra";
9
+ import { Moment } from "@ref0/infra";
10
10
  import "effect/Effect";
11
11
  import "effect/Types";
@@ -49,7 +49,7 @@ const deferral = new Deferred();
49
49
  const deferring = Effect.fail(deferral);
50
50
  const isDeferred = (error) => error === deferral;
51
51
  /** The refusal of a push whose header counts past `receiveObjectsMost`. */
52
- const tooMany = (count) => gitError("RESOURCE_EXHAUSTED", `push has ${count.toLocaleString("en-US")} objects; packs() storage takes ${receiveObjectsMost.toLocaleString("en-US")} per push`, {
52
+ const tooMany = (count) => gitError("RESOURCE_EXHAUSTED", `push has ${count.toLocaleString("en-US")} objects; this server takes ${receiveObjectsMost.toLocaleString("en-US")} per push`, {
53
53
  hint: "Push fewer commits at a time",
54
54
  context: {
55
55
  reason: "too-large",
@@ -1,3 +1,4 @@
1
+ import { Duration } from "../contracts/promises.mjs";
1
2
  import { IndexedObjectsFactory } from "../contracts/objects.mjs";
2
3
  import "../contracts/services.mjs";
3
4
  import "../contracts/store.mjs";
@@ -5,8 +6,7 @@ import "../store/call-count.mjs";
5
6
  import "./pack-reads.mjs";
6
7
  import { Option, RepackOptions } from "./repack.mjs";
7
8
  import { ShallowOptions } from "./ready.mjs";
8
- import "../contracts/promises.mjs";
9
- import { CallLimits, Duration } from "@ref0/infra";
9
+ import { CallLimits } from "@ref0/infra";
10
10
  import "effect/Effect";
11
11
  /** A push small enough to keep as rows in its own commit, with no pack: both limits hold. */
12
12
  export interface UnpackOptions {
@@ -29,10 +29,10 @@ import { wholeAnswer, wholePlan, wholeStream } from "./stream-whole.mjs";
29
29
  import { commitBytes, readFailure, unpackObjects } from "./unpack.mjs";
30
30
  import { seenFetch, visibleOf, walkedVisible } from "./visible.mjs";
31
31
  import * as Effect from "effect/Effect";
32
- import * as Exit from "effect/Exit";
33
32
  import * as Predicate from "effect/Predicate";
34
- import * as Clock from "effect/Clock";
33
+ import * as Exit from "effect/Exit";
35
34
  import * as Scope from "effect/Scope";
35
+ import * as Clock from "effect/Clock";
36
36
  // src/storage/packs.ts
37
37
  /** A push at or under 100 objects and 1 MiB is kept as rows. */
38
38
  const defaultUnpack = {
@@ -437,15 +437,18 @@ const packs = (options = {}) => {
437
437
  const reader = readerOf(listed, memory, void 0, void 0, counted.handles);
438
438
  const charge = (bytes) => allotment.grow(bytes, fetchTooLarge);
439
439
  const { store, bucket: read } = counted.handles;
440
+ const index = {
441
+ store,
442
+ bucket: read,
443
+ listed
444
+ };
445
+ const release = (bytes) => Effect.sync(() => allotment.shrink(bytes));
440
446
  const held = {
441
447
  started,
442
448
  ended,
443
449
  charge,
444
- index: {
445
- store,
446
- bucket: read,
447
- listed
448
- }
450
+ index,
451
+ release
449
452
  };
450
453
  if (counted.calls !== void 0) held.calls = counted.calls;
451
454
  return yield* fetchPack(reader, input, fetchLimits, held);