@ref0/git 0.26.0 → 0.29.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 (90) hide show
  1. package/dist/client/git-http.mjs +29 -12
  2. package/dist/client/push-upload.mjs +13 -12
  3. package/dist/client/remote-helper.mjs +1 -1
  4. package/dist/client/remote.mjs +1 -1
  5. package/dist/client/run-remote-helper.mjs +7 -14
  6. package/dist/client/slice-push.d.mts +13 -9
  7. package/dist/client/slice-push.mjs +16 -5
  8. package/dist/client/slice-report.mjs +6 -8
  9. package/dist/client/transport.mjs +27 -5
  10. package/dist/contracts/git.d.mts +17 -2
  11. package/dist/contracts/store.d.mts +1 -1
  12. package/dist/core/forks.mjs +1 -1
  13. package/dist/core/purge.mjs +1 -1
  14. package/dist/http/push-uploads.mjs +10 -15
  15. package/dist/lfs/copy.d.mts +4 -1
  16. package/dist/lfs/copy.mjs +7 -6
  17. package/dist/lfs/layer.mjs +1 -1
  18. package/dist/lfs/objects.mjs +127 -8
  19. package/dist/lfs/upload-most.mjs +19 -3
  20. package/dist/merges/merges.d.mts +3 -2
  21. package/dist/protocol/bytes/buffers.mjs +26 -1
  22. package/dist/protocol/bytes/crc32.mjs +39 -6
  23. package/dist/protocol/bytes/deflate.d.mts +11 -31
  24. package/dist/protocol/bytes/deflate.mjs +133 -72
  25. package/dist/protocol/bytes/inflate.d.mts +11 -6
  26. package/dist/protocol/bytes/inflate.mjs +184 -119
  27. package/dist/protocol/bytes/sha1-hasher.mjs +12 -12
  28. package/dist/protocol/bytes/zlib-ng/LICENSE.md +19 -0
  29. package/dist/protocol/bytes/zlib-ng/README.md +132 -0
  30. package/dist/protocol/bytes/zlib-ng/bundled.d.mts +5 -0
  31. package/dist/protocol/bytes/zlib-ng/bundled.mjs +8 -0
  32. package/dist/protocol/bytes/zlib-ng/compile.d.mts +9 -0
  33. package/dist/protocol/bytes/zlib-ng/compile.mjs +19 -0
  34. package/dist/protocol/bytes/zlib-ng/embedded.mjs +4 -0
  35. package/dist/protocol/bytes/zlib-ng/instance.d.mts +1 -0
  36. package/dist/protocol/bytes/zlib-ng/instance.mjs +111 -0
  37. package/dist/protocol/bytes/zlib-ng/zlib-ng.wasm +0 -0
  38. package/dist/protocol/objects/fsck-names.mjs +27 -7
  39. package/dist/protocol/objects/fsck.mjs +100 -88
  40. package/dist/protocol/objects/object-rules.d.mts +1 -0
  41. package/dist/protocol/objects/tree.d.mts +1 -0
  42. package/dist/protocol/objects/tree.mjs +55 -6
  43. package/dist/protocol/packs/reader.mjs +35 -30
  44. package/dist/protocol/wire/push-uploads.mjs +12 -1
  45. package/dist/server/registry.mjs +12 -0
  46. package/dist/server/server.mjs +7 -1
  47. package/dist/storage/budget.d.mts +2 -0
  48. package/dist/storage/budget.mjs +26 -24
  49. package/dist/storage/calls.d.mts +1 -1
  50. package/dist/storage/calls.mjs +4 -2
  51. package/dist/storage/host-bucket.mjs +15 -5
  52. package/dist/storage/index-bitmaps.d.mts +1 -0
  53. package/dist/storage/index-bitmaps.mjs +15 -14
  54. package/dist/storage/index-build.d.mts +2 -1
  55. package/dist/storage/index-build.mjs +14 -15
  56. package/dist/storage/index-files.mjs +3 -3
  57. package/dist/storage/index-graph.mjs +3 -3
  58. package/dist/storage/index-remap.mjs +6 -7
  59. package/dist/storage/links.mjs +34 -2
  60. package/dist/storage/loose.mjs +2 -1
  61. package/dist/storage/memory-budget.d.mts +1 -0
  62. package/dist/storage/memory-budget.mjs +12 -3
  63. package/dist/storage/merge-most.mjs +2 -1
  64. package/dist/storage/merge-stream.mjs +4 -3
  65. package/dist/storage/merge-write.mjs +2 -2
  66. package/dist/storage/pack-reads.mjs +1 -1
  67. package/dist/storage/pack-receive.mjs +24 -8
  68. package/dist/storage/packs-memory.mjs +2 -1
  69. package/dist/storage/packs.d.mts +3 -1
  70. package/dist/storage/packs.mjs +34 -11
  71. package/dist/storage/put-holds.d.mts +1 -0
  72. package/dist/storage/put-holds.mjs +20 -0
  73. package/dist/storage/ready.mjs +4 -2
  74. package/dist/storage/receive-bounds.d.mts +1 -1
  75. package/dist/storage/receive-bounds.mjs +4 -4
  76. package/dist/storage/receive-links.mjs +31 -15
  77. package/dist/storage/receive-steps.mjs +21 -1
  78. package/dist/storage/runs.d.mts +1 -1
  79. package/dist/storage/runs.mjs +7 -5
  80. package/dist/store/door.mjs +9 -1
  81. package/dist/store/job-try.mjs +5 -5
  82. package/dist/store/repo-record.mjs +1 -1
  83. package/dist/sync/step.mjs +3 -4
  84. package/package.json +12 -9
  85. package/dist/http/node.d.mts +0 -62
  86. package/dist/http/node.mjs +0 -212
  87. package/dist/node.d.mts +0 -3
  88. package/dist/node.mjs +0 -1
  89. package/dist/server/edge-node.d.mts +0 -19
  90. package/dist/server/edge-node.mjs +0 -20
@@ -13,6 +13,7 @@ import { catchSpent, ownSpentOf } from "../contracts/calls-spent.mjs";
13
13
  import { bestEffort } from "../store/errors.mjs";
14
14
  import { CallBudget, requestCount, spentBudget } from "../store/call-count.mjs";
15
15
  import { newChangeId } from "../store/scopes.mjs";
16
+ import { putHeldBytes } from "./put-holds.mjs";
16
17
  import { bucketPut, bucketReading, bucketStreamScoped, bucketTry } from "./calls.mjs";
17
18
  import { packPutOptions, startPut } from "./merge.mjs";
18
19
  import { repoTypes } from "./held-types.mjs";
@@ -21,7 +22,7 @@ import { packFiles } from "./layout.mjs";
21
22
  import { fileBytesMost, fileRefuseBytes } from "./file-limits.mjs";
22
23
  import { LargestFiles } from "./largest-files.mjs";
23
24
  import { ReceivedPointers, pointersRecords } from "./lfs-pointers.mjs";
24
- import { boundaryNotInPack, linkReader, segmentCut, segmentTooLarge, tagTargetMissing, wrongType } from "./links.mjs";
25
+ import { TreeLinks, boundaryNotInPack, linkReader, segmentCut, segmentTooLarge, tagTargetMissing, wrongType } from "./links.mjs";
25
26
  import { noRows } from "./object-rows.mjs";
26
27
  import { receiveWriters } from "./receive-admission.mjs";
27
28
  import { receiveLinkLimits, receiveLinks } from "./receive-links.mjs";
@@ -530,6 +531,16 @@ const storePack = /* @__PURE__ */ Effect.fnUntraced(function* (input, opened, st
530
531
  }
531
532
  };
532
533
  /**
534
+ * A checked tree's links, from where `tree` is, each put by its ID's bytes: a partial pack's
535
+ * trees name objects it may leave out, so it puts none.
536
+ */
537
+ const linkTree = (tree) => {
538
+ while (tree.next()) {
539
+ const put = links.linkAt(tree.bytes, tree.idAt, tree.type);
540
+ if (put !== void 0) return Effect.flatMap(put, () => stepEffect(linkTree(tree)));
541
+ }
542
+ };
543
+ /**
533
544
  * An object's fsck, its links, and a commit's parents for the `.graph`, from its `bytes`: every
534
545
  * object but a blob's. A tree's `.gitmodules` and `.gitattributes` go in `checked`.
535
546
  */
@@ -542,6 +553,7 @@ const storePack = /* @__PURE__ */ Effect.fnUntraced(function* (input, opened, st
542
553
  if (fault !== void 0) return Effect.fail(fsckRefusal(oid, fault));
543
554
  const overflow = checkedOverflow(checked);
544
555
  if (overflow !== void 0) return Effect.fail(overflow);
556
+ if (type === "tree") return partial ? void 0 : linkTree(new TreeLinks(bytes));
545
557
  const shallowCommit = type === "commit" && shallow.has(oid);
546
558
  const boundaryCommit = type === "commit" && boundary.has(oid);
547
559
  const graphed = [];
@@ -1017,16 +1029,20 @@ const storePack = /* @__PURE__ */ Effect.fnUntraced(function* (input, opened, st
1017
1029
  const put = bucketPut(bucket, key, bytes);
1018
1030
  return step === void 0 ? put : putAgain(bucket, key, bytes, put);
1019
1031
  };
1020
- yield* Effect.all([
1021
- putFile(files.idx, written.index),
1022
- putFile(files.rev, written.reverse),
1023
- putFile(files.pos, written.positions),
1024
- putFile(files.graph, graph),
1025
- putFile(files.types, written.types)
1026
- ], {
1032
+ const putting = [
1033
+ [files.idx, written.index],
1034
+ [files.rev, written.reverse],
1035
+ [files.pos, written.positions],
1036
+ [files.graph, graph],
1037
+ [files.types, written.types]
1038
+ ];
1039
+ const putsHeld = putting.reduce((sum, [, bytes]) => sum + putHeldBytes(bucket.multipart, { size: bytes.byteLength }), 0);
1040
+ yield* room.take(putsHeld) ?? Effect.void;
1041
+ yield* Effect.all(putting.map(([key, bytes]) => putFile(key, bytes)), {
1027
1042
  concurrency: 5,
1028
1043
  discard: true
1029
1044
  });
1045
+ room.give(putsHeld);
1030
1046
  if (step === void 0 && (received.spilled() || ended.spilled || links.spilled())) yield* dropRuns(bucket, opened.pack);
1031
1047
  yield* stillOpen({
1032
1048
  store,
@@ -1,4 +1,5 @@
1
- import { allottableOf, defaultMemory, readReserveBytes } from "./budget.mjs";
1
+ import { allottableOf, defaultMemory } from "../protocol/bytes/buffers.mjs";
2
+ import { readReserveBytes } from "./budget.mjs";
2
3
  import { MemoryBudget } from "./memory-budget.mjs";
3
4
  // src/storage/packs-memory.ts
4
5
  let budgetOf;
@@ -43,7 +43,9 @@ export interface PacksOptions {
43
43
  * it can't give back fits, or waits, and caches grow into what's free and shrink when another
44
44
  * needs it. The `.idx` and `.rev` kept across repos shrink first. A host with more, such as
45
45
  * Node, raises it. One under `packsMemoryLeast` is a `RangeError`: upkeep couldn't hold a merge,
46
- * so pushes would wait on `git.repack` for good. Raise it to at least that.
46
+ * so pushes would wait on `git.repack` for good. Raise it to at least that, and at `open()`, to
47
+ * that and the parts its bucket's put of a merge's pack holds: Blob's 32 MiB, R2's none. A
48
+ * server refuses objects whose upkeep can't hold one put to its bucket, `putMemoryLeast`.
47
49
  * A number gives each `open()` a budget of its own, so two servers in one isolate each count
48
50
  * only theirs. A `PacksMemory` from `packsMemory()` is one budget every `open()` given it shares.
49
51
  */
@@ -8,6 +8,7 @@ import { decodeStats, repoStats } from "../store/repo-record.mjs";
8
8
  import { collections, newChangeId, repoScope, selfKey } from "../store/scopes.mjs";
9
9
  import { CallBudget, RequestCalls, callScope, checkedLimits, countInto, countedAs, heldCall, inCallScope, noScope, readScope, requestCount, stepBudget, withBound } from "../store/call-count.mjs";
10
10
  import { forkIn, noCall } from "../store/crossing.mjs";
11
+ import { headroomBytes, idleHeapBytes } from "../protocol/bytes/buffers.mjs";
11
12
  import { jobCallLimitsOf } from "../store/job-try.mjs";
12
13
  import { RequestSnapshot } from "../store/request-snapshot.mjs";
13
14
  import { bestEffort } from "../store/errors.mjs";
@@ -20,6 +21,7 @@ import { graphMostOf, indexRowOf, indexSaves, indexStatus, indexTry } from "./in
20
21
  import { indexEligible, indexPath } from "./index-fetch.mjs";
21
22
  import { listedIds } from "./listed-ids.mjs";
22
23
  import { defaultRemapCpuMost, indexHolds } from "./index-remap.mjs";
24
+ import { putHeldBytes } from "./put-holds.mjs";
23
25
  import { indexRowKey, isPackId, packFiles, prunePassKey } from "./layout.mjs";
24
26
  import { ReachCache, indexReach, reachCacheBytes, reachedRoots } from "./index-reach.mjs";
25
27
  import { indexedVisible, setReachOf } from "./index-visible.mjs";
@@ -35,7 +37,7 @@ import { receivePack, tooMany } from "./pack-receive.mjs";
35
37
  import { mergesAlone, passAlone, passDue, passScratch, pruneStartedKey, pruneStep, readPrune } from "./prune.mjs";
36
38
  import { rebuildStep } from "./graph-rebuild.mjs";
37
39
  import { liftedFences, unfenced } from "./merge-fence.mjs";
38
- import { freshCalls, geometricStep, groupedPacks, membersOf, opensWithin, resumeMerge, streamHeld } from "./merge-stream.mjs";
40
+ import { freshCalls, geometricStep, groupedPacks, membersOf, opensWithin, putPartHeld, resumeMerge, streamHeld } from "./merge-stream.mjs";
39
41
  import { droppedStep, mergeKey } from "./merge-row.mjs";
40
42
  import { parksPass, repackJobRow } from "./repack-job.mjs";
41
43
  import { dropRefused, sharePacks } from "./quarantine.mjs";
@@ -47,7 +49,7 @@ import { defaultPrune, deletedLeaveAt, pruneWait, quarantineKey } from "./rows.m
47
49
  import { openStageReceive, readAnswer, receiveStep, stageReceive, stageReceiveStep, stageStepKey } from "./receive-steps.mjs";
48
50
  import { memoryOf, openBudget } from "./packs-memory.mjs";
49
51
  import { receiveRoomAdmitted } from "./receive-admission.mjs";
50
- import { fetchFloorBytes, fetchRowCacheBytes, headroomBytes, idleHeapBytes, pushAdmissionOf, pushFloorsOf, pushPartBytes, pushRulesOf, readReserveBytes, readerFloorBytes, readerMost, unpackInflatedMost } from "./budget.mjs";
52
+ import { fetchFloorBytes, fetchRowCacheBytes, pushAdmissionOf, pushFloorsOf, pushPartBytes, pushRulesOf, readReserveBytes, readerFloorBytes, readerMost, stagedPuts, unpackInflatedMost } from "./budget.mjs";
51
53
  import { chargedCache } from "./charged-cache.mjs";
52
54
  import { serverRequestBudget } from "./request-cache.mjs";
53
55
  import { AllottedPointers, allotmentCacheCharge, allottedWithin, cacheRoomCharge, fetchBusy, growWaitMs, instanceRoomOf, pushMemoryOf, pushObjectsMostOf, pushTooLarge, readBusy, readerMemoryOf, requestBudgetOf, rowCacheRoomOf, upkeepMemoryOf, upkeepTooLarge, withMemoryBudget } from "./memory-budget.mjs";
@@ -505,7 +507,11 @@ const packs = (options = {}) => packsWith(options);
505
507
  */
506
508
  const packsWith = (options = {}, inner = {}) => {
507
509
  const memoryTotal = memoryOf(options.memory);
508
- if (options.repack !== false && memoryTotal < packsMemoryLeast) throw new RangeError(`packs()' memory of ${memoryTotal} bytes leaves upkeep no room for a merge: raise it to at least ${packsMemoryLeast}`);
510
+ /** Refuses a memory under `least` where upkeep merges: it would hold no merge. */
511
+ const mergesIn = (least) => {
512
+ if (options.repack !== false && memoryTotal < least) throw new RangeError(`packs()' memory of ${memoryTotal} bytes leaves upkeep no room for a merge: raise it to at least ${least}`);
513
+ };
514
+ mergesIn(packsMemoryLeast);
509
515
  const optionsFor = (stats) => {
510
516
  const prune = optionFor(options.prune, defaultPrune, stats);
511
517
  return {
@@ -521,6 +527,7 @@ const packsWith = (options = {}, inner = {}) => {
521
527
  needsBucket: true,
522
528
  indexed: true,
523
529
  open: ({ store: calls, bucket: hosts, clock, fetchLimits, callLimits }) => {
530
+ mergesIn(packsMemoryLeast + putPartHeld(hosts.multipart));
524
531
  const bucket = countedBucket(hostFailures(hosts));
525
532
  const callsMost = fetchCallsMost(callLimits, options.callLimits);
526
533
  const stepMost = callLimits === void 0 ? callsMost : fetchCallsMost(jobCallLimitsOf(callLimits), options.callLimits);
@@ -629,6 +636,11 @@ const packsWith = (options = {}, inner = {}) => {
629
636
  objects: (listed) => objectsAt(listed, { read: true }),
630
637
  indexes
631
638
  };
639
+ /** A push's or a step's size as its put to this bucket holds it: with the bucket's `multipart`. */
640
+ const sizedFor = (input) => ({
641
+ ...input,
642
+ multipart: bucket.multipart
643
+ });
632
644
  const asPack = (listed, input, prune, memory, visible) => {
633
645
  const packed = {
634
646
  store: calls,
@@ -639,7 +651,7 @@ const packsWith = (options = {}, inner = {}) => {
639
651
  prune,
640
652
  receive: input,
641
653
  memory,
642
- objectsMost: pushObjectsMostOf(memoryTotal, input)
654
+ objectsMost: pushObjectsMostOf(memoryTotal, sizedFor(input))
643
655
  };
644
656
  if (visible !== void 0) packed.visible = visible;
645
657
  return receivePack(packed);
@@ -652,7 +664,8 @@ const packsWith = (options = {}, inner = {}) => {
652
664
  * it returns, which lets it go if the answer never reaches the core; the rest goes back as
653
665
  * the scope ends. A push with no pack keeps no allotment.
654
666
  */
655
- const receive = Effect.fnUntraced(function* (listed, input, answered, made, visible) {
667
+ const receive = Effect.fnUntraced(function* (listed, pushed, answered, made, visible) {
668
+ const input = sizedFor(pushed);
656
669
  const most = pushObjectsMostOf(memoryTotal, input);
657
670
  if (input.objects > most) return yield* Effect.fail(tooMany(input.objects, most));
658
671
  const past = segmentTooLarge(input);
@@ -727,7 +740,12 @@ const packsWith = (options = {}, inner = {}) => {
727
740
  if (past !== void 0) return yield* Effect.fail(past);
728
741
  const { quarantine: prune } = optionsFor(chosen ? yield* statsOf(calls, listed.repo) : void 0);
729
742
  const { boundary = [], needs = [], cutMost, length, atMost, shallow = [] } = input;
730
- return yield* stageReceive({
743
+ const held = putHeldBytes(bucket.multipart, {
744
+ size: length,
745
+ atMost
746
+ });
747
+ const admitted = held === 0 ? Effect.void : budget.admit(held);
748
+ const staging = stageReceive({
731
749
  store: calls,
732
750
  bucket,
733
751
  indexes,
@@ -744,6 +762,7 @@ const packsWith = (options = {}, inner = {}) => {
744
762
  ...shallow.length > 0 && { shallow }
745
763
  }
746
764
  });
765
+ return yield* Effect.scoped(Effect.andThen(admitted, staging));
747
766
  });
748
767
  /** Stepped multipart staging for push uploads (#1931), internal to `packs()`. */
749
768
  const stageStep = {
@@ -793,14 +812,18 @@ const packsWith = (options = {}, inner = {}) => {
793
812
  * `receive`'s is. A try whose commit another try's beat is `UNAVAILABLE`, to be tried again.
794
813
  */
795
814
  const step = Effect.fnUntraced(function* (listed, input, answered, made, visible) {
796
- const most = pushObjectsMostOf(memoryTotal, input);
815
+ const sized = {
816
+ ...input,
817
+ multipart: stagedPuts
818
+ };
819
+ const most = pushObjectsMostOf(memoryTotal, sized);
797
820
  if (input.objects > most) return yield* Effect.fail(tooMany(input.objects, most));
798
821
  const { pack } = input;
799
822
  if (!isPackId(pack)) return yield* fail("INVALID_ARGUMENT", `No pack is staged as ${pack}`);
800
823
  if (input.objects > 0) yield* refuseBacklog(listed);
801
824
  const answer = yield* readAnswer(bucket, pack);
802
825
  const size = {
803
- ...input,
826
+ ...sized,
804
827
  length: answer.bytes
805
828
  };
806
829
  const allotment = yield* budget.admit(pushAdmissionOf(size));
@@ -829,7 +852,7 @@ const packsWith = (options = {}, inner = {}) => {
829
852
  ...needs !== void 0 && { needs }
830
853
  },
831
854
  memory,
832
- objectsMost: pushObjectsMostOf(memoryTotal, input)
855
+ objectsMost: pushObjectsMostOf(memoryTotal, sized)
833
856
  };
834
857
  if (visible !== void 0) receiving.visible = visible;
835
858
  const opened = {
@@ -882,7 +905,7 @@ const packsWith = (options = {}, inner = {}) => {
882
905
  bases: void 0
883
906
  };
884
907
  }
885
- const read = yield* readPast(input.pack, unpack.maxBytes, memory.allotment, pushPartBytes(input));
908
+ const read = yield* readPast(input.pack, unpack.maxBytes, memory.allotment, pushPartBytes(sizedFor(input)));
886
909
  if (!read.ended) {
887
910
  yield* dropPushPreload;
888
911
  const whole = {
@@ -1396,7 +1419,7 @@ const packsWith = (options = {}, inner = {}) => {
1396
1419
  reach: face.index.reach
1397
1420
  },
1398
1421
  readyShallow: shallow !== false,
1399
- pushObjectsMost: pushObjectsMostOf(memoryTotal),
1422
+ pushObjectsMost: pushObjectsMostOf(memoryTotal, { multipart: bucket.multipart }),
1400
1423
  ...visible === void 0 && { [stageStepKey]: stageStep }
1401
1424
  };
1402
1425
  };
@@ -0,0 +1 @@
1
+ import { Multipart } from "@ref0/infra";
@@ -0,0 +1,20 @@
1
+ // src/storage/put-holds.ts
2
+ /** The part a bucket's upload holds, R2's for a push of unknown size: 8 MiB. */
3
+ const uploadPartBytes = 8388608;
4
+ /**
5
+ * What a put to a bucket of `multipart` holds in memory, its body told its `size`, or at most
6
+ * `atMost` bytes, or neither: none for a body told a size the bucket sends whole, within its
7
+ * `wholeMost`; else `buffersMost` buffers, each of `partSize` or of the body when it fits in one, all
8
+ * a put holds whatever its body's length. A body within a part is one part, cut in a buffer of
9
+ * its size, and the copies a store's sends hold of it, which `buffersMost` bounds. A bucket that
10
+ * cuts no parts, the memory store's, is charged as one of R2's, `uploadPartBytes`. Every put Git
11
+ * charges is charged this. It's apart from `budget.ts`, which reads it beside its other bounds, so
12
+ * `runs.ts`, below `budget.ts`, charges its run puts with it too.
13
+ */
14
+ const putHeldBytes = (multipart, body = {}) => {
15
+ if (body.size !== void 0 && body.size <= multipart.wholeMost) return 0;
16
+ const part = Number.isFinite(multipart.partSize) ? multipart.partSize : uploadPartBytes;
17
+ const most = body.atMost ?? body.size;
18
+ return Math.min(most ?? part, part) * multipart.buffersMost;
19
+ };
20
+ export { putHeldBytes, uploadPartBytes };
@@ -7,6 +7,7 @@ import { repoRootsKey, repoScope } from "../store/scopes.mjs";
7
7
  import { bucketBody, bucketTry } from "./calls.mjs";
8
8
  import { startPut } from "./merge.mjs";
9
9
  import { readBusy, upkeepTooLarge } from "./memory-budget.mjs";
10
+ import { putHeldBytes } from "./put-holds.mjs";
10
11
  import { callsAhead, packOfPlan, planFetchWithin, planTooSlow, timeLeft, unreadPackMs } from "./fetch.mjs";
11
12
  import { isPackId, objectCollections, packFiles } from "./layout.mjs";
12
13
  import { noRows } from "./object-rows.mjs";
@@ -373,7 +374,7 @@ const putWhole = (bucket, key, body) => Effect.scoped(Effect.gen(function* () {
373
374
  /**
374
375
  * A plan's pack written to the bucket under a new `quarantine` row and marker, as a push's is, in
375
376
  * what's left of the build's time from `started`: a step cut before its commit, or past that time,
376
- * leaves the pack for clean-up.
377
+ * leaves the pack for clean-up. Its put's parts are charged to the step's allotment while it runs.
377
378
  */
378
379
  const keepPack = /* @__PURE__ */ Effect.fnUntraced(function* (input, shallow, plan, started) {
379
380
  const { store, bucket, listed, at, prune } = input;
@@ -387,7 +388,8 @@ const keepPack = /* @__PURE__ */ Effect.fnUntraced(function* (input, shallow, pl
387
388
  const limits = readyLimits(shallow);
388
389
  const left = yield* timeLeft(limits, started);
389
390
  const answer = yield* handingOn(packOfPlan(input.reads, plan, limits, { left }));
390
- yield* putWhole(bucket, packFiles(opened.pack).pack, answer.pack);
391
+ const held = putHeldBytes(bucket.multipart, { atMost: readyBytesMost });
392
+ yield* Effect.acquireUseRelease(input.charge(held), () => putWhole(bucket, packFiles(opened.pack).pack, answer.pack), () => input.release(held));
391
393
  const { columns } = plan;
392
394
  let followed = 0;
393
395
  for (let ordinal = 0; ordinal < columns.count; ordinal += 1) if (columns.kindAt(ordinal) === "tag") followed += 1;
@@ -1 +1 @@
1
- import "@ref0/infra";
1
+ import { Multipart } from "@ref0/infra";
@@ -92,7 +92,7 @@ const receiveBoundaryMost = repoRootsMost;
92
92
  const receiveCutParentsMost = 2 * receiveBoundaryMost;
93
93
  /**
94
94
  * The runs a receive's listing deletes a page at a time, in one `deleteMany`: a store's batch of
95
- * 1,000 keys, R2's, S3's and Vercel's, so a page is one batch.
95
+ * 1,000 keys, R2's and Vercel's, so a page is one batch.
96
96
  */
97
97
  const receiveDropPage = 1e3;
98
98
  /**
@@ -113,11 +113,11 @@ const importTryTimeout = "13 minutes";
113
113
  * - On Cloudflare, an alarm's `alarmWallTime`, 15 minutes from before the claim. R2's calls
114
114
  * through its binding take no signal, so one started before the try's timeout runs on, but
115
115
  * the alarm's end stops it.
116
- * - On Node, Bun or Deno, `importTryTimeout`: at it the signal aborts, `bucketCall` starts no
117
- * call, and a call under way ends at once. S3's and Vercel Blob's take it, so a request
116
+ * - On Node, as on Vercel, `importTryTimeout`: at it the signal aborts, `bucketCall` starts no
117
+ * call, and a call under way ends at once. Vercel Blob's take it, so a request
118
118
  * already sent can only commit within its own trip. The disk bucket's calls take no signal: the
119
119
  * bound assumes its local writes, an fsync then a link, end within the grace. A queue on
120
- * `Node.workerThreads()` caps any call: a second past the abort, it ends the handler's thread.
120
+ * `Runner.workerThreads()` caps any call: a second past the abort, it ends the handler's thread.
121
121
  * Then `jobLeaseMargin`, the queue's own room past a try's end, covers that last call's commit.
122
122
  * So 15.5 minutes, on every bucket and host Git ships, given that local I/O. A call that outlasts
123
123
  * it on a queue run in-process, the disk bucket's on a disk that stalls, or a host's own bucket's
@@ -1,6 +1,6 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
- import { writeOidBytes } from "../protocol/packs/idx.mjs";
3
- import "../protocol/objects/object.mjs";
2
+ import { oidBytes, writeOidBytes } from "../protocol/packs/idx.mjs";
3
+ import { emptyTree } from "../protocol/objects/object.mjs";
4
4
  import { stepEffect } from "../protocol/packs/step.mjs";
5
5
  import { hexOf } from "../protocol/bytes/hex.mjs";
6
6
  import { compareIds } from "./raw-ids.mjs";
@@ -22,6 +22,7 @@ const types = [
22
22
  "commit",
23
23
  "tag"
24
24
  ];
25
+ const emptyTreeId = oidBytes(emptyTree);
25
26
  /**
26
27
  * The refusal of a push whose links need more of the server than `receiveLinkSpillBytes`: the
27
28
  * bytes they need, and those left.
@@ -188,22 +189,36 @@ const receiveLinks = (bucket, pack, reads, limits = receiveLinkLimits, writing =
188
189
  judged(linked.oid, linked.first, actual, true);
189
190
  if (linked.other !== void 0) judged(linked.oid, linked.other, actual, false);
190
191
  };
191
- /** One link, as it's read: a row of its runs, or the put a full buffer makes. */
192
- const link = (named) => {
193
- if (seq === 8e7) return Effect.fail(linksTooMany());
194
- const seen = {
192
+ /** A link to the empty tree, which every repo holds: judged as it's read, and put in no run. */
193
+ const emptyLink = (type) => {
194
+ judged(emptyTree, {
195
195
  seq: seq++,
196
- type: named.type
197
- };
198
- if (named.oid === "4b825dc642cb6eb9a060e54bf8d69288fbee4904") {
199
- judged(named.oid, seen, "tree", !emptyLinked);
200
- emptyLinked = true;
201
- return;
202
- }
203
- writeOidBytes(named.oid, row, 0);
204
- view.setUint32(20, (types.indexOf(named.type) << 30 | seen.seq) >>> 0);
196
+ type
197
+ }, "tree", !emptyLinked);
198
+ emptyLinked = true;
199
+ };
200
+ /**
201
+ * A link whose ID is written, unless it's the empty tree's: past `receiveLinksMost` refused, then
202
+ * its row's type and place, and the put a full buffer makes.
203
+ */
204
+ const put = (type, empty) => {
205
+ if (seq === 8e7) return Effect.fail(linksTooMany());
206
+ if (empty) return emptyLink(type);
207
+ view.setUint32(20, (types.indexOf(type) << 30 | seq++) >>> 0);
205
208
  return writer.add(row);
206
209
  };
210
+ /** One link, as it's read: a row of its runs, or the put a full buffer makes. */
211
+ const link = (named) => {
212
+ const empty = named.oid === emptyTree;
213
+ if (!empty) writeOidBytes(named.oid, row, 0);
214
+ return put(named.type, empty);
215
+ };
216
+ /** `link` of the 20-byte ID `bytes` hold at `at`, as a tree's are read, with no text of it. */
217
+ const linkAt = (bytes, at, type) => {
218
+ const empty = compareIds(bytes, at, emptyTreeId, 0) === 0;
219
+ if (!empty) for (let index = 0; index < 20; index += 1) row[index] = bytes[at + index] ?? 0;
220
+ return put(type, empty);
221
+ };
207
222
  /**
208
223
  * Once the pack is read: refused as `receiveLinks` says. `own` is the type of the pack's object
209
224
  * `oid`, checked when it isn't `said`, or `undefined` when the pack brought none; `parents` are a
@@ -319,6 +334,7 @@ const receiveLinks = (bucket, pack, reads, limits = receiveLinkLimits, writing =
319
334
  const putRuns = () => spilled;
320
335
  return {
321
336
  link,
337
+ linkAt,
322
338
  finish,
323
339
  carry: Effect.map(writer.finish, (runs) => ({
324
340
  runs,
@@ -559,6 +559,26 @@ const stepInflatedMostOf = (share) => share * inflatedSharesMost;
559
559
  */
560
560
  const streamStepsMost = (bytes, share) => share === void 0 ? 8 : Math.max(1, Math.ceil(bytes / share));
561
561
  /**
562
+ * A receive's quarantine as its last step hands it on: the commit that lands its pack, a push
563
+ * upload's push or an import's, deletes its record too and puts its `staged` row, landed, so
564
+ * clean-up deletes the keys under its prefix once no step of an earlier try can put more. That
565
+ * commit comes within the try's own bound, under `receiveStepGrace` past the step's start at `at`,
566
+ * and a step that read the quarantine open before it puts its last key within `receiveStepGrace`
567
+ * of its own start, so the row is due `receiveStepGrace` twice past `at`. A pack that never lands
568
+ * leaves both to clean-up's end of its quarantine.
569
+ */
570
+ const landing = (received, pack, at) => {
571
+ const { change } = received;
572
+ return {
573
+ ...received,
574
+ change: {
575
+ ...change,
576
+ put: [...change.put ?? [], stagedRow(pack, at + receiveStepGrace, true)],
577
+ delete: [...change.delete ?? [], receiveKey(pack)]
578
+ }
579
+ };
580
+ };
581
+ /**
562
582
  * A step whose quarantine isn't open, its stage over (#1502): what it and clean-up left deleted now,
563
583
  * not only at its `staged` row's sweep, every key under its prefix but its markers, and its pack's
564
584
  * files once no marker holds it. A pack gone with a marker left landed, by another try, so its
@@ -649,7 +669,7 @@ const receiveStep = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
649
669
  ...carried && { carried },
650
670
  ...input.largest === true && { largest: { entryMost: stepEntryMostOf(share) } }
651
671
  });
652
- if (!("paused" in stored)) return { received: stored };
672
+ if (!("paused" in stored)) return { received: landing(stored, opened.pack, at) };
653
673
  const { state, table } = stored.paused;
654
674
  yield* putStepState(bucket, keys, state, table, stored.paused.pointers, stored.paused.checked);
655
675
  const inflated = (read.row?.inflated ?? 0) + (pausedInflated ? 1 : 0);
@@ -3,6 +3,6 @@ import "../contracts/result.mjs";
3
3
  import "../protocol/packs/step.mjs";
4
4
  import "./layout.mjs";
5
5
  import "./receive-bounds.mjs";
6
- import { Page } from "@ref0/infra";
6
+ import { Multipart, Page } from "@ref0/infra";
7
7
  import "effect/Schema";
8
8
  import "effect/Effect";
@@ -3,6 +3,7 @@ import { bucketDeleteMany, bucketDo, sizedPutCalls } from "./calls.mjs";
3
3
  import { runKey, runsPrefix } from "./layout.mjs";
4
4
  import { startPut } from "./merge.mjs";
5
5
  import { readExactly } from "./pack-ranges.mjs";
6
+ import { putHeldBytes } from "./put-holds.mjs";
6
7
  import { receiveDropPage, receiveMergeReadBytes, receiveRunBytes } from "./receive-bounds.mjs";
7
8
  import * as Schema from "effect/Schema";
8
9
  import * as Effect from "effect/Effect";
@@ -697,9 +698,9 @@ const eachRow = /* @__PURE__ */ Effect.fnUntraced(function* (cursor, places, eac
697
698
  const mergeFew = (bucket, runs, each, bounds, room, starts) => Effect.flatMap(fewCursor(bucket, runs, bounds, room, starts), ({ next, places }) => eachRow(next, places, each));
698
699
  /**
699
700
  * `runs` merged `bounds.ways` chains at a time into fewer, longer runs under `pack`, until no more
700
- * than that many chains are left: each pass reads and puts every row once, its reads and its chunk
701
- * taken from `room` as it merges. Each run it puts is a chain of its own. A caller merging the
702
- * same runs more than once narrows them once first.
701
+ * than that many chains are left: each pass reads and puts every row once, its reads, its chunk
702
+ * and what its put holds taken from `room` as it merges. Each run it puts is a chain of its own. A
703
+ * caller merging the same runs more than once narrows them once first.
703
704
  */
704
705
  const narrowed = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, runs, bounds, room) {
705
706
  const { ways } = bounds;
@@ -720,7 +721,8 @@ const narrowed = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, runs
720
721
  const length = group.lengths.reduce((sum, each) => sum + each, 0);
721
722
  const key = runKey(pack, `${runs.kind}.${pass}`, keys.length);
722
723
  const chunkBytes = Math.max(1, Math.floor(writeBytes / runs.width)) * runs.width;
723
- const taking = room?.take(chunkBytes);
724
+ const held = chunkBytes + putHeldBytes(bucket.multipart, { size: length });
725
+ const taking = room?.take(held);
724
726
  if (taking !== void 0) yield* taking;
725
727
  yield* Effect.scoped(Effect.gen(function* () {
726
728
  const put = yield* startPut(bucket, key, { size: length });
@@ -741,7 +743,7 @@ const narrowed = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, runs
741
743
  yield* put.finish;
742
744
  }).pipe(Effect.onError(() => put.abort));
743
745
  }));
744
- room?.give(chunkBytes);
746
+ room?.give(held);
745
747
  keys.push(key);
746
748
  lengths.push(length);
747
749
  }
@@ -127,11 +127,19 @@ const untilClosed = (body, door) => bodyUntilAborted(body, door.closing, closedE
127
127
  /** `links`, built on `context`, each call through `door` on the caller's context, as `doorBucket`'s. */
128
128
  const doorLinks = (links, context, door) => {
129
129
  const { call } = doorOf(context, door);
130
- return {
130
+ const calls = {
131
131
  url: (key, options) => call(links.url(key, options)),
132
132
  putUrl: (key, options) => call(links.putUrl(key, options)),
133
133
  head: (key) => call(links.head(key))
134
134
  };
135
+ return links.puts === "checked" ? {
136
+ puts: "checked",
137
+ ...calls
138
+ } : {
139
+ puts: "unchecked",
140
+ ...calls,
141
+ copy: (from, to) => call(links.copy(from, to))
142
+ };
135
143
  };
136
144
  /** `uploads`, built on `context`, each call through `door` on the caller's context, as `doorBucket`'s. */
137
145
  const doorUploads = (uploads, context, door) => {
@@ -13,18 +13,18 @@ import * as Scheduler from "effect/Scheduler";
13
13
  * The longest a try of Git's long jobs runs: `git.index`'s, `git.repack`'s, `git.ref-index`'s and
14
14
  * a push upload's, 3.5 minutes. An import's and a mirror's is `importTryTimeout`, longer until
15
15
  * their transfers resume across tries. With the minute a host's `onFailure` may
16
- * take, that's 270 s, which leaves 30 s of a Vercel Hobby function's 300 s for the run's own
17
- * claim and settle (#2900). A step is cut at `jobBucketCallsDefault`'s 1,000 bucket calls, about
16
+ * take, that's 270 s: a try cut short, as a Vercel Daemon's is when a deploy replaces it 30 s after
17
+ * `SIGTERM`, runs again once its lease lapses, so a short try bounds what a cut loses (#2900). A step is cut at `jobBucketCallsDefault`'s 1,000 bucket calls, about
18
18
  * 100 s at 100 ms a call, and no step is cut by CPU: s1m's heaviest, `git.index`'s bitmaps, took
19
19
  * 35,138 ms of CPU in one try (s1m-upkeep run 46099393357), so its try fits with 75 s to spare. A
20
20
  * Worker's alarm, 15 minutes, holds it on every platform, so it's one number everywhere.
21
21
  */
22
22
  const jobTryTimeout = "210 seconds";
23
23
  /**
24
- * The bucket calls a try may make where the adapter bounds none, as Node's and Vercel's stores
25
- * don't: Workers' 1,000, so a step that stops at a Worker's bound and goes on in its next try stops
24
+ * The bucket calls a try may make where the adapter bounds none, as Postgres's store doesn't:
25
+ * Workers' 1,000, so a step that stops at a Worker's bound and goes on in its next try stops
26
26
  * there on every platform. Without it, on Vercel, a step such as `git.index`'s `bitmaps`, 999
27
- * calls a try on Workers for a million objects (#1132), ran on past a function's 300 s on calls
27
+ * calls a try on Workers for a million objects (#1132), ran on past its try's timeout on calls
28
28
  * alone (#2900). A request's calls stay the adapter's, unbounded where it gives none.
29
29
  */
30
30
  const jobBucketCallsDefault = 1e3;
@@ -145,7 +145,7 @@ const heldStore = (store) => ({
145
145
  /**
146
146
  * `addition` to `repo`'s scope, an add at no version, only while the repo is live: it reads the
147
147
  * record first and fails `RepoGone` when there's none or it's deleted, so a late write, a wake or
148
- * a job after the delete never makes a purged scope again, nor on Turso its database. One whose
148
+ * a job after the delete never makes a purged scope again. One whose
149
149
  * read stalled past `heldUntil` is `UNAVAILABLE`, for a try that reads again, and so is one whose
150
150
  * add the store found past it as it landed, `heldUntil` being the add's `by`. A wake, a job, an
151
151
  * upload or a sync's cover made apart from the repo's own read goes through here, and a push's
@@ -13,7 +13,7 @@ import { discover, fetchTerms, remoteRefsAndHeadOf } from "../client/remote.mjs"
13
13
  import { heldOnce, oneShotReads, scopedReader, scopedReceiveStep } from "../storage/calls.mjs";
14
14
  import { isPackId } from "../storage/layout.mjs";
15
15
  import { receiveCutParentsMost } from "../storage/receive-bounds.mjs";
16
- import { ReceiveRow, receiveKey, stagedRow } from "../storage/receive-steps.mjs";
16
+ import { ReceiveRow, receiveKey } from "../storage/receive-steps.mjs";
17
17
  import { decodeHeld } from "../storage/rows.mjs";
18
18
  import { infiniteDepth } from "../storage/shallow.mjs";
19
19
  import { decodeRow, storeCall, storeCommit } from "../store/errors.mjs";
@@ -740,17 +740,16 @@ const resumedIn = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row, rec
740
740
  edits: [],
741
741
  atomic: false,
742
742
  pack: { received: answer.received },
743
- also: (at, received) => {
743
+ also: (_at, received) => {
744
744
  const written = cutAfter(lands.roots, kept, received);
745
745
  const paged = withLfsPages(landed(row, lands), received?.lfsPointers, copying);
746
746
  return {
747
747
  put: [
748
748
  importRow(paged.row),
749
- stagedRow(pack, at, true),
750
749
  ...written.put,
751
750
  ...paged.put
752
751
  ],
753
- delete: [...written.delete, receiveKey(pack)],
752
+ delete: written.delete,
754
753
  jobs: []
755
754
  };
756
755
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ref0/git",
3
- "version": "0.26.0",
3
+ "version": "0.29.0",
4
4
  "private": false,
5
5
  "description": "Git hosting as a library: a server, a client and their merges",
6
6
  "license": "Apache-2.0",
@@ -14,6 +14,15 @@
14
14
  ],
15
15
  "type": "module",
16
16
  "sideEffects": false,
17
+ "imports": {
18
+ "#zlib-ng": {
19
+ "workerd": "./dist/protocol/bytes/zlib-ng/bundled.mjs",
20
+ "default": "./dist/protocol/bytes/zlib-ng/compile.mjs"
21
+ },
22
+ "#zlib-ng/zlib-ng.wasm": {
23
+ "default": "./dist/protocol/bytes/zlib-ng/zlib-ng.wasm"
24
+ }
25
+ },
17
26
  "exports": {
18
27
  ".": {
19
28
  "types": "./dist/index.d.mts",
@@ -25,11 +34,6 @@
25
34
  "import": "./dist/extend.mjs",
26
35
  "default": "./dist/extend.mjs"
27
36
  },
28
- "./node": {
29
- "types": "./dist/node.d.mts",
30
- "import": "./dist/node.mjs",
31
- "default": "./dist/node.mjs"
32
- },
33
37
  "./protocol": {
34
38
  "types": "./dist/protocol.d.mts",
35
39
  "import": "./dist/protocol.mjs",
@@ -47,12 +51,11 @@
47
51
  }
48
52
  },
49
53
  "dependencies": {
50
- "@ref0/infra": "0.26.0",
51
- "pako": "2.1.0"
54
+ "@ref0/infra": "0.29.0"
52
55
  },
53
56
  "devDependencies": {
54
57
  "@effect/vitest": "4.1.7",
55
- "@ref0/xdiff-wasm": "0.26.0",
58
+ "@ref0/xdiff-wasm": "0.29.0",
56
59
  "effect": "4.1.7",
57
60
  "vite-plus": "1.8.0",
58
61
  "vitest": "5.1.1",