@ref0/git 0.8.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 (94) hide show
  1. package/dist/contracts/calls-spent.d.mts +2 -12
  2. package/dist/contracts/calls-spent.mjs +4 -5
  3. package/dist/contracts/events.d.mts +70 -4
  4. package/dist/contracts/events.mjs +27 -3
  5. package/dist/contracts/git.d.mts +13 -3
  6. package/dist/contracts/objects.d.mts +18 -0
  7. package/dist/contracts/queue.d.mts +3 -2
  8. package/dist/contracts/queue.mjs +4 -2
  9. package/dist/core/ancestry.mjs +5 -4
  10. package/dist/core/index-job.mjs +23 -1
  11. package/dist/core/index-lost.d.mts +11 -0
  12. package/dist/core/index-lost.mjs +55 -0
  13. package/dist/core/objects/commit-writes.mjs +1 -1
  14. package/dist/core/objects/commits.mjs +10 -9
  15. package/dist/core/objects/merges.mjs +1 -1
  16. package/dist/core/objects/reading.mjs +28 -13
  17. package/dist/core/objects/trees.mjs +1 -1
  18. package/dist/core/parts.d.mts +7 -0
  19. package/dist/core/publish.mjs +9 -5
  20. package/dist/core/purge.mjs +16 -3
  21. package/dist/core/push.mjs +27 -11
  22. package/dist/core/repack.mjs +36 -14
  23. package/dist/core/view.d.mts +10 -1
  24. package/dist/core/view.mjs +15 -6
  25. package/dist/effect.d.mts +2 -3
  26. package/dist/effect.mjs +2 -3
  27. package/dist/engine/commits.mjs +4 -3
  28. package/dist/engine/merge-bases.mjs +5 -3
  29. package/dist/engine/merge.mjs +4 -3
  30. package/dist/engine/parts.d.mts +1 -0
  31. package/dist/engine/parts.mjs +1 -1
  32. package/dist/engine/walk.mjs +15 -11
  33. package/dist/http/core-parts.mjs +17 -8
  34. package/dist/index.d.mts +2 -2
  35. package/dist/lfs/objects.mjs +7 -4
  36. package/dist/lfs/upkeep.mjs +6 -5
  37. package/dist/lfs/upload-most.mjs +7 -1
  38. package/dist/protocol/bytes/streams.mjs +84 -2
  39. package/dist/protocol/diff/read.d.mts +1 -0
  40. package/dist/protocol/diff/read.mjs +5 -2
  41. package/dist/protocol/objects/commit.d.mts +7 -0
  42. package/dist/protocol/objects/commit.mjs +5 -1
  43. package/dist/queue/advance.mjs +39 -10
  44. package/dist/queue/host.d.mts +4 -0
  45. package/dist/queue/layer.mjs +4 -2
  46. package/dist/queue/limits.mjs +18 -2
  47. package/dist/queue/rows.mjs +2 -1
  48. package/dist/queue/trim.mjs +2 -2
  49. package/dist/rest/commits.d.mts +238 -238
  50. package/dist/rest/forks.d.mts +71 -71
  51. package/dist/rest/refs.d.mts +143 -143
  52. package/dist/rest/repos.d.mts +81 -81
  53. package/dist/rest/topics.d.mts +112 -112
  54. package/dist/rest/trees.d.mts +77 -77
  55. package/dist/rest/wire.d.mts +19 -1
  56. package/dist/rest/work.d.mts +39 -39
  57. package/dist/server/joined.d.mts +11 -5
  58. package/dist/server/joined.mjs +3 -2
  59. package/dist/server/registry.mjs +11 -5
  60. package/dist/server/server.mjs +16 -4
  61. package/dist/storage/index-bitmaps.mjs +16 -10
  62. package/dist/storage/index-build.mjs +61 -13
  63. package/dist/storage/index-graph.d.mts +1 -0
  64. package/dist/storage/index-graph.mjs +29 -5
  65. package/dist/storage/index-layers.d.mts +1 -0
  66. package/dist/storage/index-layers.mjs +5 -2
  67. package/dist/storage/index-reach.mjs +7 -5
  68. package/dist/storage/index-remap.mjs +5 -5
  69. package/dist/storage/index-visible.mjs +16 -5
  70. package/dist/storage/links.mjs +3 -3
  71. package/dist/storage/pack-order.d.mts +1 -0
  72. package/dist/storage/pack-order.mjs +18 -1
  73. package/dist/storage/prune-walk.mjs +5 -2
  74. package/dist/storage/prune.mjs +107 -37
  75. package/dist/storage/receive-bounds.mjs +3 -2
  76. package/dist/storage/visible.mjs +3 -2
  77. package/dist/storage/walk.d.mts +1 -0
  78. package/dist/storage/walk.mjs +9 -5
  79. package/dist/storage/wants.mjs +17 -11
  80. package/dist/store/call-count.d.mts +8 -0
  81. package/dist/store/call-count.mjs +15 -7
  82. package/dist/store/errors.d.mts +7 -1
  83. package/dist/store/errors.mjs +7 -1
  84. package/dist/store/job-try.mjs +3 -1
  85. package/dist/store/records.mjs +17 -2
  86. package/dist/store/repo-record.mjs +9 -2
  87. package/dist/store/scopes.mjs +10 -2
  88. package/dist/sync/bound.d.mts +1 -1
  89. package/dist/sync/import.mjs +1 -1
  90. package/dist/sync/layer.mjs +4 -7
  91. package/dist/sync/mirror.mjs +1 -1
  92. package/dist/topics/advance.mjs +4 -4
  93. package/dist/topics/layer.mjs +1 -1
  94. package/package.json +3 -3
@@ -6,6 +6,8 @@ import { writeCommitGraph } from "../protocol/packs/graph.mjs";
6
6
  import { IndexerCache } from "../protocol/packs/indexer.mjs";
7
7
  import { oidBytes } from "../protocol/packs/idx.mjs";
8
8
  import { rawLinks } from "../protocol/objects/links-raw.mjs";
9
+ import { rootsOf } from "../store/repo-record.mjs";
10
+ import { repoRootsKey, repoScope } from "../store/scopes.mjs";
9
11
  import { randomText } from "../store/random.mjs";
10
12
  import { allottableOf, uploadPartBytes } from "./budget.mjs";
11
13
  import { bucketDo, bucketPut, joined, readWhole, sizedPutCalls, streamedPutCalls } from "./calls.mjs";
@@ -173,13 +175,17 @@ const IndexRefusal = /* @__PURE__ */ Schema.Struct({
173
175
  * builds it replaced, still in prune's grace. A reader takes every layer from this one row, so
174
176
  * it never mixes layers of two versions. Each layer's region IDs are its `.region` file, so a
175
177
  * row that leaves after the build changes nothing. `rounds` is how many rounds of tries the repo
176
- * had used once it was built, or once its update's were spent, as a refused row's.
178
+ * had used once it was built, or once its update's were spent, as a refused row's. `lost` marks
179
+ * a row whose files a read found failing their own checks (`lostIndexRow`): no read answers from
180
+ * it, and the next try builds whole, its row unmarked (Q839 (5)). A refusal over its layers keeps
181
+ * the mark, and so does every other row that keeps them: only a whole build's row drops it.
177
182
  */
178
183
  const BuiltIndex = /* @__PURE__ */ Schema.Struct({
179
184
  rounds: Count,
180
185
  layers: Schema.Array(IndexLayer),
181
186
  replaced: Schema.Array(ReplacedBuild),
182
- refusal: Schema.optionalKey(IndexRefusal)
187
+ refusal: Schema.optionalKey(IndexRefusal),
188
+ lost: Schema.optionalKey(Schema.Literal(true))
183
189
  });
184
190
  /** How long a repo waits after its first refusal for spent tries before a push saves more. */
185
191
  const triesWait = 864e5;
@@ -233,8 +239,30 @@ const decodeRowOption = /* @__PURE__ */ Schema.decodeUnknownOption(IndexRow);
233
239
  const builtOf = (row) => row === void 0 || "refused" in row || row.layers.length === 0 ? void 0 : row;
234
240
  /** An `index` row's value decoded, at the read's boundary: none for one unreadable. */
235
241
  const decodeIndexValue = decodeRowOption;
236
- /** A decoded `index` row as a built index, or `undefined` for none, a refusal or no layers. */
237
- const builtIndexOf = (row) => builtOf(Option.getOrUndefined(row));
242
+ /**
243
+ * A decoded `index` row as a built index a read answers from, or `undefined` for none, a refusal,
244
+ * no layers, or one marked `lost`, which covers nothing until it's built again.
245
+ */
246
+ const builtIndexOf = (row) => {
247
+ const built = builtOf(Option.getOrUndefined(row));
248
+ return built?.lost === true ? void 0 : built;
249
+ };
250
+ /**
251
+ * The `index` row `row` marked lost, for a read that found its files failing their own checks to
252
+ * commit with the row's `git.index` round, or `undefined` when it's no built index or one marked
253
+ * already. Its readers then cover nothing, and the try builds whole, as over a `.bitmaps` gone,
254
+ * which a payload that fails its checks under a sound table never shows the try.
255
+ */
256
+ const lostIndexRow = (row) => {
257
+ const built = builtOf(indexRowOf(row));
258
+ return built === void 0 || built.lost === true ? void 0 : {
259
+ ...row,
260
+ value: {
261
+ ...built,
262
+ lost: true
263
+ }
264
+ };
265
+ };
238
266
  /** A prune's end, with when the next file it kept is due. */
239
267
  const prunedAt = (due) => due === void 0 ? { kind: "pruned" } : {
240
268
  kind: "pruned",
@@ -612,9 +640,11 @@ const regionStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, d
612
640
  const files = indexFiles(listed.repo, data.build);
613
641
  const { layout, first, packed } = yield* layoutOf(bucket, listed, data);
614
642
  const held = data.below.length === 0 ? void 0 : yield* heldBelow(parts, listed, layout, first);
643
+ const roots = yield* rootsAt(parts, listed);
615
644
  const links = new SliceLinks((bytes) => allotment.tryGrow(bytes));
616
645
  const types = [];
617
646
  const commits = [];
647
+ const rootPositions = /* @__PURE__ */ new Set();
618
648
  const parsed = Effect.fnUntraced(function* (object, at) {
619
649
  types.push(typeCodes[object.type]);
620
650
  if (object.type === "blob") return;
@@ -631,6 +661,7 @@ const regionStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, d
631
661
  oid: object.oid,
632
662
  parents: named.slice(1)
633
663
  });
664
+ if (roots.has(object.oid)) rootPositions.add(packed + at);
634
665
  }
635
666
  });
636
667
  const read = yield* readRegion(parts, listed, (row, at) => Effect.gen(function* () {
@@ -650,7 +681,7 @@ const regionStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, d
650
681
  const targets = yield* joinCharged(links, layout.ranges, region, allotment);
651
682
  const slice = data.slices.length;
652
683
  yield* allotment.grow(edgesMostOf(links) + read.rows + graphFileBytes(commits));
653
- const edges = edgesFileOf(files.edges(slice, read.rows), packed, read.rows, links, targets);
684
+ const edges = edgesFileOf(files.edges(slice, read.rows), packed, read.rows, links, targets, rootPositions);
654
685
  yield* putOnce(bucket, edges.slice.key, edges.bytes);
655
686
  yield* putOnce(bucket, files.typesPart(slice, read.rows), Uint8Array.from(types));
656
687
  yield* putOnce(bucket, files.basesPart(slice, read.rows), /* @__PURE__ */ new Uint8Array(0));
@@ -677,6 +708,15 @@ const heldBelow = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, la
677
708
  return held;
678
709
  });
679
710
  /**
711
+ * The repo's roots, which a build writes with no parents in its graph and no parent edges, so
712
+ * neither its bitmaps nor its generations pass one. Read on their own: an index try's own reads
713
+ * are of its objects, and roots change only at the import's landing, before any ref names them.
714
+ */
715
+ const rootsAt = (parts, listed) => Effect.flatMap(parts.store.read({
716
+ scope: repoScope(listed.repo),
717
+ reads: [repoRootsKey]
718
+ }), (snapshot) => rootsOf(snapshot.results[0]));
719
+ /**
680
720
  * What the region holds of each row past its links: its ID, twice while the IDs grow, its type,
681
721
  * and a commit's entry and its ID as text, rounded up.
682
722
  */
@@ -695,7 +735,8 @@ const graphStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, da
695
735
  graphs,
696
736
  key: files.graph,
697
737
  allotment,
698
- most: parts.graphMost
738
+ most: parts.graphMost,
739
+ roots: yield* rootsAt(parts, listed)
699
740
  };
700
741
  if (below !== void 0) graphInput.below = below;
701
742
  const written = (yield* storedSize(parts.bucket, files.graph)) === void 0 ? yield* writeIndexGraph(graphInput) : {
@@ -744,6 +785,7 @@ const storedTypesOf = (bucket, files, slices, base) => Effect.fnUntraced(functio
744
785
  */
745
786
  const readStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, data, allotment) {
746
787
  const { counted } = parts;
788
+ const roots = yield* rootsAt(parts, listed);
747
789
  const counts = data.packs.map((id) => listed.packs.find((each) => each.id === id)?.objects ?? 0);
748
790
  const bounds = parts.bounds ?? sliceBounds;
749
791
  const entries = data.narrowed?.entries ?? bounds.entries ?? 65536;
@@ -804,7 +846,8 @@ const readStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, dat
804
846
  calls: counted === void 0 ? void 0 : {
805
847
  made: () => counted.made().bucket,
806
848
  most: counted.most.bucket - reserve.bucket
807
- }
849
+ },
850
+ roots
808
851
  });
809
852
  through = parts.bucket;
810
853
  if (slice.spent !== void 0) return withNarrowed(data, narrowedAfter(data.narrowed, at.position, {
@@ -817,7 +860,7 @@ const readStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, dat
817
860
  const targets = yield* joinCharged(links, ranges, region, allotment);
818
861
  yield* allotment.grow(edgesMostOf(links) + slice.bases.length * 4);
819
862
  const positions = slice.types.length;
820
- const made = edgesFileOf(files.edges(number, positions), first, positions, links, targets);
863
+ const made = edgesFileOf(files.edges(number, positions), first, positions, links, targets, slice.roots);
821
864
  yield* putOnce(bucket, made.slice.key, made.bytes);
822
865
  yield* putOnce(bucket, files.typesPart(number, positions), slice.types);
823
866
  yield* putOnce(bucket, files.basesPart(number, positions), wordsBytes(slice.bases));
@@ -1171,6 +1214,7 @@ const bitmapsWritten = /* @__PURE__ */ Effect.fnUntraced(function* (parts, lower
1171
1214
  allotment,
1172
1215
  bits: walking
1173
1216
  };
1217
+ const rootsOnce = yield* Effect.cached(rootsAt(parts, listed));
1174
1218
  const below = data.below.length === 0 ? void 0 : {
1175
1219
  first,
1176
1220
  entries: entriesBelow,
@@ -1185,7 +1229,10 @@ const bitmapsWritten = /* @__PURE__ */ Effect.fnUntraced(function* (parts, lower
1185
1229
  };
1186
1230
  } };
1187
1231
  if (walks.carried?.position === position) carry.from = walks.carried.walk;
1188
- const walked = yield* reachOf(reach, [{ position }], carry);
1232
+ const walked = yield* reachOf({
1233
+ ...reach,
1234
+ roots: yield* rootsOnce
1235
+ }, [{ position }], carry);
1189
1236
  if (walked === void 0) return void 0;
1190
1237
  const most = ewahMostWords(walked.length) * 4;
1191
1238
  yield* allotment.grow(8 + most);
@@ -1884,7 +1931,8 @@ const indexStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, in
1884
1931
  refusal: {
1885
1932
  reason,
1886
1933
  ...held
1887
- }
1934
+ },
1935
+ ...kept.lost === true && { lost: true }
1888
1936
  }
1889
1937
  };
1890
1938
  return {
@@ -1921,14 +1969,14 @@ const indexStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, in
1921
1969
  if (input.failed !== void 0) return waiting(input.failed.reason);
1922
1970
  if (input.data === void 0 && row !== void 0 && !indexSaves(indexStatus(row, limits, input.at, listedIds(listed)))) return prunedAt(yield* prune());
1923
1971
  const built = builtOf(row);
1924
- const current = input.data === void 0 && built !== void 0 && coversAll(built.layers, listed) ? yield* upToDate(parts, listed, built, input.tips).pipe(Effect.catchIf(isLost, (error) => Effect.as(layersLost(listed, error), "lost"))) : false;
1972
+ const current = input.data === void 0 && built?.lost === true ? "lost" : input.data === void 0 && built !== void 0 && coversAll(built.layers, listed) ? yield* upToDate(parts, listed, built, input.tips).pipe(Effect.catchIf(isLost, (error) => Effect.as(layersLost(listed, error), "lost"))) : false;
1925
1973
  if (current === true) return prunedAt(yield* prune());
1926
1974
  if (current === "moved" && input.lastCheck !== true) return { kind: "moved" };
1927
1975
  const fresh = () => built === void 0 || current === "lost" || !coversAll(built.layers, listed) ? started(listed) : built.layers.length < 8 ? startedUpdate(listed, built) : startedMerge(listed, built);
1928
1976
  const kept = input.data;
1929
1977
  const sameBelow = kept !== void 0 && (kept.below.length === 0 || kept.below.map((layer) => layer.build).join() === (built?.layers ?? []).map((layer) => layer.build).join());
1930
1978
  const again = (from) => from.below.length === 0 && from.merge !== true ? started(listed) : fresh();
1931
- const data = kept === void 0 || !covers(kept, listed) || !sameBelow ? fresh() : kept.step === "region" ? again(kept) : kept;
1979
+ const data = kept !== void 0 && built?.lost === true && kept.below.length > 0 ? started(listed) : kept === void 0 || !covers(kept, listed) || !sameBelow ? fresh() : kept.step === "region" ? again(kept) : kept;
1932
1980
  const more = (next) => ({
1933
1981
  kind: "more",
1934
1982
  data: next
@@ -2018,4 +2066,4 @@ const indexTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, limits, lis
2018
2066
  data: ended.data
2019
2067
  };
2020
2068
  });
2021
- export { BitmapsCut, BuiltIndex, IndexBounds, IndexData, IndexGroup, IndexLayer, IndexRefusal, IndexRow, IndexSlice, IndexTries, Narrowed, RefusedIndex, ReplacedBuild, belowGraphs, bitmapsJoinHeld, bitmapsJoinMost, boundsOf, builtIndexOf, chooseCommits, copyMergedBitmaps, coveredPacks, coversAll, decodeIndexValue, denseBelow, denseBelowReads, edgesMost, entriesHeld, floors, graphMostOf, indexBitmapsCallsAfter, indexReadCallsAfter, indexRowOf, indexSaves, indexStatus, indexStep, indexSteps, indexTry, limitsOf, madeMost, mergeCallsAfterOpen, mergeChunk, mergeHeldMost, narrowedAfter, newBuildId, positionOrder, pruneBuilds, putOnce, reachesBytes, reachesOf, readFurther, rowsOfLayer, sliceBounds, storedTypesOf, triesWait, triesWaitMost, triesWaitOf, wordsOf };
2069
+ export { BitmapsCut, BuiltIndex, IndexBounds, IndexData, IndexGroup, IndexLayer, IndexRefusal, IndexRow, IndexSlice, IndexTries, Narrowed, RefusedIndex, ReplacedBuild, belowGraphs, bitmapsJoinHeld, bitmapsJoinMost, boundsOf, builtIndexOf, chooseCommits, copyMergedBitmaps, coveredPacks, coversAll, decodeIndexValue, denseBelow, denseBelowReads, edgesMost, entriesHeld, floors, graphMostOf, indexBitmapsCallsAfter, indexReadCallsAfter, indexRowOf, indexSaves, indexStatus, indexStep, indexSteps, indexTry, limitsOf, lostIndexRow, madeMost, mergeCallsAfterOpen, mergeChunk, mergeHeldMost, narrowedAfter, newBuildId, positionOrder, pruneBuilds, putOnce, reachesBytes, reachesOf, readFurther, rowsOfLayer, sliceBounds, storedTypesOf, triesWait, triesWaitMost, triesWaitOf, wordsOf };
@@ -1,4 +1,5 @@
1
1
  import "../contracts/objects.mjs";
2
2
  import "../contracts/result.mjs";
3
+ import "../protocol/objects/commit.mjs";
3
4
  import "./memory-budget.mjs";
4
5
  import "effect/Effect";
@@ -1,6 +1,7 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
2
  import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
3
3
  import { hexOf } from "../protocol/bytes/hex.mjs";
4
+ import { noRepoRoots } from "../protocol/objects/commit.mjs";
4
5
  import { mostParents } from "../protocol/objects/object-rules.mjs";
5
6
  import { Sha1 } from "../protocol/bytes/sha1.mjs";
6
7
  import { graphMagic } from "../protocol/packs/graph.mjs";
@@ -8,7 +9,7 @@ import { PackTransportError, boundedSource, packReadBytes } from "../protocol/pa
8
9
  import { bucketStream } from "./calls.mjs";
9
10
  import { startPut } from "./merge.mjs";
10
11
  import { readExactly } from "./pack-ranges.mjs";
11
- import { compareIds, orderById } from "./raw-ids.mjs";
12
+ import { compareIds, idsBytes, orderById } from "./raw-ids.mjs";
12
13
  import * as Effect from "effect/Effect";
13
14
  import * as Result from "effect/Result";
14
15
  import { limits } from "@ref0/infra";
@@ -240,14 +241,36 @@ const heldBelow = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, graphs, b
240
241
  bytes: refs * 24 + held.length * 4
241
242
  };
242
243
  });
243
- /** `graphs`' commits as `eachCommit` gives them, less the merge numbers `held` names, numbered without them. */
244
- const ownCommits = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, graphs, held, each) {
244
+ /**
245
+ * `graphs`' commits as `eachCommit` gives them, less the merge numbers `held` names, numbered
246
+ * without them, each of `roots`, sorted raw IDs, with no parents.
247
+ */
248
+ const ownCommits = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, graphs, held, roots, each) {
245
249
  let skipped = 0;
246
250
  return (yield* eachCommit(bucket, graphs, (number, commit) => {
247
- if (held[skipped] !== number) return each(number - skipped, commit);
251
+ if (held[skipped] !== number) return each(number - skipped, rootedOf(roots, commit));
248
252
  skipped += 1;
249
253
  })) - skipped;
250
254
  });
255
+ /** Whether `id`'s 20 bytes are among `roots`, sorted raw IDs: a search, with no string made. */
256
+ const isRoot = (roots, id) => {
257
+ let low = 0;
258
+ let high = roots.length / 20;
259
+ while (low < high) {
260
+ const middle = low + high >>> 1;
261
+ const compared = compareIds(roots, middle * 20, id, 0);
262
+ if (compared === 0) return true;
263
+ if (compared < 0) low = middle + 1;
264
+ else high = middle;
265
+ }
266
+ return false;
267
+ };
268
+ /** `commit` as a repo with `roots`, sorted raw IDs, sees it: one of them with no parents. */
269
+ const rootedOf = (roots, commit) => roots.length > 0 && isRoot(roots, commit.id) ? {
270
+ id: commit.id,
271
+ parents: commit.parents.subarray(0, 0),
272
+ count: 0
273
+ } : commit;
251
274
  /** Parents still to number: each one's ID, and where its number goes. */
252
275
  var ParentRefs = class {
253
276
  ids;
@@ -360,6 +383,7 @@ const graphTooWide = (id, parents) => gitError("RESOURCE_EXHAUSTED", `The repo's
360
383
  */
361
384
  const writeIndexGraph = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
362
385
  const { bucket, graphs, allotment, below } = input;
386
+ const roots = idsBytes([...input.roots ?? noRepoRoots]).bytes;
363
387
  const refs = input.refs ?? 65536;
364
388
  const base = below?.first ?? 0;
365
389
  const missBytes = below === void 0 ? 0 : (refs + mostParents) * 32;
@@ -421,7 +445,7 @@ const writeIndexGraph = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
421
445
  resolved += 1;
422
446
  }
423
447
  };
424
- const counted = yield* ownCommits(bucket, graphs, own.held, (number, commit) => {
448
+ const counted = yield* ownCommits(bucket, graphs, own.held, roots, (number, commit) => {
425
449
  const parents = commit.count;
426
450
  const start = octopusAt;
427
451
  if (parents > 2) octopusAt += parents - 1;
@@ -2,6 +2,7 @@ import "../contracts/ids.mjs";
2
2
  import "../contracts/objects.mjs";
3
3
  import "../contracts/result.mjs";
4
4
  import "../contracts/store.mjs";
5
+ import "../protocol/objects/commit.mjs";
5
6
  import "./index-bitmaps.mjs";
6
7
  import "./index-build.mjs";
7
8
  import "./link-join.mjs";
@@ -3,6 +3,7 @@ import { hexOf } from "../protocol/bytes/hex.mjs";
3
3
  import { rawLinks } from "../protocol/objects/links-raw.mjs";
4
4
  import { isTreeMode } from "../protocol/objects/object.mjs";
5
5
  import { parseTreeBytes } from "../protocol/objects/tree.mjs";
6
+ import { noRepoRoots } from "../protocol/objects/commit.mjs";
6
7
  import { oidBytes } from "../protocol/packs/idx.mjs";
7
8
  import { bitmapWords } from "./ewah.mjs";
8
9
  import { ewahMostWords, openBitmaps } from "./index-bitmaps.mjs";
@@ -369,7 +370,7 @@ const whileFollowed = (allotment, objects, follow) => {
369
370
  /**
370
371
  * The positions `starts` reach, as words over every position, or `undefined` when it can't say:
371
372
  * a walk past `most` reads, an object it can't find, or a link to an ID the index doesn't hold,
372
- * such as one listed after it. A position with a stored bitmap is ORed whole and not walked; any
373
+ * such as one listed after it. One of `input.roots` leads to its tree alone, never its parents. A position with a stored bitmap is ORed whole and not walked; any
373
374
  * other is read, and its links found by position, a few at a time. A blob is reached and never
374
375
  * read. It holds a word for each 32 positions, unless it's given `bits`, and at most `most` IDs
375
376
  * still to read, charged to `allotment`, and each batch it follows, charged by `whileFollowed`.
@@ -390,6 +391,7 @@ const whileFollowed = (allotment, objects, follow) => {
390
391
  const reachOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, starts, carry) {
391
392
  const { layout, bitmaps } = input;
392
393
  const most = input.most ?? 2e3;
394
+ const roots = input.roots ?? noRepoRoots;
393
395
  const words = bitmapWords(layout.positions);
394
396
  const held = (input.bits === void 0 ? words * 4 : 0) + most * 24;
395
397
  yield* Effect.acquireRelease(input.allotment.grow(held), () => Effect.sync(() => input.allotment.shrink(held)));
@@ -448,8 +450,9 @@ const reachOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, starts, carr
448
450
  continue;
449
451
  }
450
452
  let tree = object.type === "commit";
453
+ const rooted = tree && roots.has(object.oid);
451
454
  const malformed = rawLinks(object.type, bytes, (from, at) => {
452
- linked.push({
455
+ if (tree || !rooted) linked.push({
453
456
  id: from.slice(at, at + 20),
454
457
  links: true,
455
458
  to: tree ? "trees" : "commits"
@@ -91,7 +91,8 @@ const shrinkOnClose = (allotment, held) => () => Effect.sync(() => allotment.shr
91
91
  * What `tips`, none of which the index holds, reach before they meet it, through `onward`: each
92
92
  * object outside the index, read or not, counted, and each position met set in `met`, kept as a
93
93
  * bit, not walked. A blob is reached and never read, and an object the repo doesn't hold, as a
94
- * shallow repo's parent, is left out. Past `most` objects outside it, it stops, not closed. Each
94
+ * shallow repo's parent, is left out, and one of `input.roots` leads to its tree alone, never its
95
+ * parents, as the index's graph has it. Past `most` objects outside it, it stops, not closed. Each
95
96
  * batch it follows is charged by `whileFollowed`, and it holds at most `most` IDs between them.
96
97
  */
97
98
  const outsideOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, tips, most) {
@@ -116,7 +117,7 @@ const outsideOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, tips, most
116
117
  ids.delete(oid);
117
118
  continue;
118
119
  }
119
- const steps = yield* stepsOf(object, true);
120
+ const steps = yield* stepsOf(object, true, input.roots);
120
121
  for (const each of onward(steps)) if (!ids.has(each)) read.add(each);
121
122
  for (const each of steps.reached) if (!ids.has(each)) linked.add(each);
122
123
  }
@@ -157,8 +158,8 @@ const indexCovers = (input, listed) => {
157
158
  * doesn't cover `listed`, as after a repack took a covered pack out, for the caller's walk. A tip
158
159
  * whose reach won't close within `most` sets `pastLimit`. Where `unclosed`, so does one whose walk
159
160
  * meets an object past the bytes it may follow at once, which a fetch's want check refuses as
160
- * `levelTooLarge`: a visible set still shows its tips, and what their bitmaps reach. Its
161
- * allotment is the scope's.
161
+ * `levelTooLarge`: a visible set still shows its tips, and what their bitmaps reach. Its walks
162
+ * follow no parent of `input.roots`. Its allotment is the scope's.
162
163
  */
163
164
  const tipsReach = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, input, unclosed = false) {
164
165
  let tooLarge = false;
@@ -192,7 +193,8 @@ const tipsReach = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, in
192
193
  bitmaps,
193
194
  read,
194
195
  allotment,
195
- most
196
+ most,
197
+ roots: input.roots
196
198
  };
197
199
  let known = true;
198
200
  let walked = 0;
@@ -515,10 +515,10 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
515
515
  });
516
516
  /**
517
517
  * The `index` row a geometric step's merge leaves, laid again over its pack, or `undefined` when
518
- * it can't be: the row isn't built, is a refusal for spent tries, or doesn't cover the listing
519
- * before the merge; the merge took a pack it doesn't cover; the remap declines, as `remapIndex`
520
- * says; or it fails of its own, its calls run out, its allotment can't grow, or a stored file it
521
- * reads is lost or corrupt, each logged with its cause. Then the listing commits without it, and
518
+ * it can't be: the row isn't built, is a refusal for spent tries, is marked lost, or doesn't
519
+ * cover the listing before the merge; the merge took a pack it doesn't cover; the remap
520
+ * declines, as `remapIndex` says; or it fails of its own, its calls run out, its allotment can't
521
+ * grow, or a stored file it reads is lost or corrupt, each logged with its cause. Then the listing commits without it, and
522
522
  * the next `git.index` builds again. A merge it finds incomplete, the merged pack's own files lost
523
523
  * or corrupt among it, fails the step, an error in the log; so do an interruption, a defect and
524
524
  * any other failure.
@@ -528,7 +528,7 @@ const remapRow = (parts, input) => Effect.scoped(Effect.gen(function* () {
528
528
  ...indexRowKey,
529
529
  value: parts.row
530
530
  });
531
- if (row === void 0 || "refused" in row || row.refusal !== void 0) return void 0;
531
+ if (row === void 0 || "refused" in row || row.refusal !== void 0 || row.lost === true) return void 0;
532
532
  if (!coversListing(row.layers, input.listed, parts.holds?.packs)) return void 0;
533
533
  const plan = remapPlan(row.layers, input.listed, input.taken, input.merged.pack.objects);
534
534
  if (plan === void 0) return void 0;
@@ -33,6 +33,16 @@ const unindexedRead = () => gitError("RESOURCE_EXHAUSTED", readByIdText, {
33
33
  const isUnindexedRead = (error) => error.code === "RESOURCE_EXHAUSTED" && error.message === readByIdText;
34
34
  /** What each ID a set has answered adds to what it keeps: its hex and its place in the map. */
35
35
  const answerBytes = 160;
36
+ /**
37
+ * The core's ask for the rebuild of the `index` row a set's input names, once the index fails its
38
+ * own checks, kept off `VisibleInput`'s contract as a set's reach is.
39
+ */
40
+ const lostAsks = /* @__PURE__ */ new WeakMap();
41
+ /** `input`, whose set asks `lost` once the index its row names fails its own checks. */
42
+ const askingOnLost = (input, lost) => {
43
+ lostAsks.set(input, lost);
44
+ return input;
45
+ };
36
46
  /** Each set `indexedVisible` made, with its `SetReach`, kept off the set's contract. */
37
47
  const setReaches = /* @__PURE__ */ new WeakMap();
38
48
  /** The want check `set` answers by its own reach, if `indexedVisible` made it. */
@@ -47,20 +57,21 @@ const setReachOf = (set) => setReaches.get(set);
47
57
  * never on an ID, and a hidden ID and an absent one still read alike. Outside a request's hold, or
48
58
  * once it has closed, an ask builds the reach for itself and lets it go once answered. A tip
49
59
  * answers with no lookup, since its caller sees it. An index that fails its own checks,
50
- * `DATA_LOSS`, gives the set to `fallback` too, with its error in the log, so it never says an ID
51
- * is reached that it hasn't shown.
60
+ * `DATA_LOSS`, gives the set to `fallback` too, with its error in the log and the core's ask for
61
+ * the row's rebuild, `askingOnLost`, so it never says an ID is reached that it hasn't shown.
52
62
  */
53
63
  const indexedVisible = (parts, listed, input, fallback) => {
54
64
  if (!indexCovers(input, listed)) return fallback();
55
65
  const tips = {
56
66
  row: input.row,
57
- tips: input.tips
67
+ tips: input.tips,
68
+ roots: input.roots
58
69
  };
59
70
  const shownTips = new Set(input.tips);
60
71
  /** The tips as `tipsReach` walks them: each once, where it first comes. */
61
72
  const walkedTips = [...shownTips];
62
73
  /** An index that fails its own checks as `value`, its error in the log. */
63
- const lostAs = (value) => (effect) => effect.pipe(Effect.catchIf((error) => error.code === "DATA_LOSS", (error) => Effect.as(indexUnreadable(listed.repo, error), value)));
74
+ const lostAs = (value) => (effect) => effect.pipe(Effect.catchIf((error) => error.code === "DATA_LOSS", (error) => Effect.as(indexUnreadable(listed.repo, error, lostAsks.get(input)), value)));
64
75
  let fell;
65
76
  let held;
66
77
  let using = 0;
@@ -165,4 +176,4 @@ const indexedVisible = (parts, listed, input, fallback) => {
165
176
  setReaches.set(set, reach);
166
177
  return set;
167
178
  };
168
- export { indexedVisible, isUnindexedRead, setReachOf, unindexedRead };
179
+ export { askingOnLost, indexedVisible, isUnindexedRead, setReachOf, unindexedRead };
@@ -136,8 +136,8 @@ const segmentPast = (what, most) => gitError("RESOURCE_EXHAUSTED", `the segment'
136
136
  */
137
137
  const segmentTooLarge = (segment) => {
138
138
  const { boundary = [], needs = [] } = segment;
139
- if (boundary.length > 1e4) return segmentPast(`boundary names ${boundary.length.toLocaleString("en-US")} commits`, receiveBoundaryMost);
140
- return needs.length > 2e4 ? segmentPast(`answer needs ${needs.length.toLocaleString("en-US")} parents`, receiveCutParentsMost) : void 0;
139
+ if (boundary.length > receiveBoundaryMost) return segmentPast(`boundary names ${boundary.length.toLocaleString("en-US")} commits`, receiveBoundaryMost);
140
+ return needs.length > receiveCutParentsMost ? segmentPast(`answer needs ${needs.length.toLocaleString("en-US")} parents`, receiveCutParentsMost) : void 0;
141
141
  };
142
142
  /** What a segment's cut carries from one step to the next: the parents counted, by commit. */
143
143
  const CutCarry = /* @__PURE__ */ Schema.Struct({
@@ -151,7 +151,7 @@ const CutCarry = /* @__PURE__ */ Schema.Struct({
151
151
  * too: one goes on from the `carried` count and parents of the steps before it.
152
152
  */
153
153
  const segmentCut = (asked, carried) => {
154
- const most = Math.max(0, Math.min(asked ?? 2e4, receiveCutParentsMost));
154
+ const most = Math.max(0, Math.min(asked ?? receiveCutParentsMost, receiveCutParentsMost));
155
155
  const byCommit = new Map(carried?.byCommit.map(([commit, parents]) => [commit, [...parents]]));
156
156
  let count = carried?.count ?? 0;
157
157
  return {
@@ -2,6 +2,7 @@ import "../contracts/objects.mjs";
2
2
  import "../contracts/result.mjs";
3
3
  import "../protocol/packs/indexer.mjs";
4
4
  import "../protocol/packs/step.mjs";
5
+ import "../protocol/objects/commit.mjs";
5
6
  import "../contracts/calls-spent.mjs";
6
7
  import "./pack-reads.mjs";
7
8
  import "./pack-ranges.mjs";
@@ -344,6 +344,21 @@ const entryById = (entries, id) => {
344
344
  }
345
345
  return -1;
346
346
  };
347
+ /** No positions: a slice that read no root. */
348
+ const noRoots = /* @__PURE__ */ new Set();
349
+ /**
350
+ * The repo positions of the slice's first `kept` entries, the first at `first`, whose IDs are
351
+ * among `roots`: each root searched for in the slice's own IDs.
352
+ */
353
+ const rootsWithin = (entries, roots, kept, first) => {
354
+ if (roots === void 0 || roots.size === 0) return noRoots;
355
+ const found = /* @__PURE__ */ new Set();
356
+ for (const root of roots) {
357
+ const within = entryById(entries, oidBytes(root));
358
+ if (within >= 0 && within < kept) found.add(first + within);
359
+ }
360
+ return found;
361
+ };
347
362
  const unknown = 4;
348
363
  /** The code a pack entry's header gives a whole object, or `unknown` for a delta. */
349
364
  const knownOf = (kind) => kind === "ofs" || kind === "ref" ? unknown : typeCodes[kind];
@@ -535,6 +550,7 @@ const spentRead = (at, span) => ({
535
550
  read: 0,
536
551
  skipped: 0,
537
552
  rereads: 0,
553
+ roots: noRoots,
538
554
  spent: span
539
555
  });
540
556
  const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
@@ -773,7 +789,8 @@ const sliceRead = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
773
789
  bases: bases.subarray(0, based),
774
790
  read,
775
791
  skipped,
776
- rereads: indexer.rereads
792
+ rereads: indexer.rereads,
793
+ roots: rootsWithin(entries, input.roots, types.length, ranges.base + at.position)
777
794
  };
778
795
  });
779
796
  /** The first `count` words of `pairs`, two at a time, compacted to those whose first is below `limit`; their count. */
@@ -180,7 +180,7 @@ const droppedOnRefusal = (walk, input, pack, _start, _missing, options = {}) =>
180
180
  * A refused fresh walk drops its runs; one given `saved` or `known` keeps them. A test sets
181
181
  * `treesAtOnce` below its bound.
182
182
  */
183
- const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, start, missing, { rows = 0, treesAtOnce = pruneTreesAtOnce, calls, saved, known } = {}) {
183
+ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, start, missing, { rows = 0, treesAtOnce = pruneTreesAtOnce, calls, saved, known, roots } = {}) {
184
184
  const { allotment, listed } = input;
185
185
  const objects = listed.packs.reduce((sum, each) => sum + each.objects, 0) + rows;
186
186
  const blocks = listed.packs.reduce((sum, each) => sum + Math.ceil(each.bytes / blockBytes), 0);
@@ -214,7 +214,10 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
214
214
  held -= bytes;
215
215
  allotment.shrink(bytes);
216
216
  });
217
- const reads = countedReads(reader, objects + 1e6, charged, void 0, release);
217
+ const reads = countedReads(roots === void 0 ? reader : {
218
+ ...reader,
219
+ roots
220
+ }, objects + 1e6, charged, void 0, release);
218
221
  /** Where each of `oids` is for the seen set: its first listed pack and its rank there. */
219
222
  const ranksOf = Effect.fnUntraced(function* (oids) {
220
223
  const at = /* @__PURE__ */ new Map();