main
1// Resumable transfer, the plan (#238): copy one commit's tree, read from a spooled pack, to another remote as a new
2// parentless commit, in pushes under a host's cap. Pure: everything here is data computed from the pack's index
3// (scanPackIndex, #236), its resolved ids and types (resolvePackRange, #248) and the source commit's bytes. The effects
4// (status, one push per step, the loop) are in transfer.ts.
5//
6// The plan is planPackBatches' (#237) plus what makes each push safe to retry and to resume from the destination alone:
7// - every batch but the last advances a temp ref (refs/ply/transfer/<key> by default) to a temp commit whose parent is
8// the previous one and whose tree lists that batch's objects by id. Everything pushed so far is reachable from the
9// temp ref at every moment, so nothing depends on how long a host keeps unreachable objects, and the server's
10// connectivity check passes on every push. The listing fans out into subtrees by the id's first two hex digits: a
11// flat tree was refused above about 16k entries on Cloudflare Artifacts (2026-11-09 spike); 256 subtrees passed at
12// 50,001 objects.
13// - the last batch (trees, with any blobs that fit) carries the new root commit and, in one atomic push, creates the
14// target ref (compare-and-swap on the zero id) and deletes the temp ref.
15// - every generated object (temp trees, temp commits, the new commit) has a deterministic id, written in the plan, so
16// the next step is found by reading the temp ref back (transferStatus), never by local state.
17//
18// Commit policy: the new commit keeps the source commit's author, committer, encoding, message and other headers, and
19// drops gpgsig, gpgsig-sha256 and mergetag (a signature over a different object would be false). Temp commits are
20// written by `ply transfer <ply-transfer@invalid> 0 +0000`, so the same plan always gives the same ids.
21import type { PlyError } from './errors.js';
22import { fail, argsError } from './errors.js';
23import type { Option, Result } from './result.js';
24import { ok, some, none, getOrElse } from './result.js';
25import { parseCommit, encodeCommitOf, encodeEntries, hashObject, TYPE } from './objects.js';
26import type { EntryOf } from './objects.js';
27import type { Input } from './absent.js';
28import { at, mapGet, withDefaults } from './absent.js';
29import type { PackPlan, PlannedBatch, PushBudget } from './packplan.js';
30import { planPackBatches, planHash, PLAN_VERSION } from './packplan.js';
31import type { ScannedPack, ScannedType } from './packscanindex.js';
32import type { ResolvedIndex } from './packrangeresolve.js';
33import type { Oid } from './sha1.js';
34import type { RangeSource } from './rangesource.js';
35import type { Refname, TempRef } from './transfernames.js';
36import { sha1Hex, targetRef, tempRefOf, isOid, isOptionOid, isList } from './transfernames.js';
38const OBJ_BLOB = TYPE.BLOB;
39const OBJ_COMMIT = TYPE.COMMIT;
40const OBJ_TREE = TYPE.TREE;
41const MODE_BLOB = '100644';
42const MODE_TREE = '40000';
44export const TRANSFER_VERSION = 1;
45export const TRANSFER_REF_PREFIX = 'refs/ply/transfer/';
46export { sweepPrefix, isTempKey } from './transfernames.js';
47export const TRANSFER_IDENT = 'ply transfer <ply-transfer@invalid> 0 +0000';
48// Generated objects per batch at most: 256 subtrees, the root tree, the temp commit.
49export const TRANSFER_GENERATED_OBJECTS = 258;
50// Bytes of generated objects per batch object at most: a subtree entry is `100644 ` + 38 hex + NUL + 20 bytes = 66,
51// deflated stored at worst (a 5-byte header per 16 KiB block); the fixed part covers the root tree, the commits,
52// object headers and the two commands' pkt-lines.
53const GEN_BYTES_PER_OBJECT = 68;
54const GEN_BYTES_FIXED = 32 * 1024;
55const SIGNATURE_HEADERS = ['gpgsig', 'gpgsig-sha256', 'mergetag'];
57export type { TempRef };
58// The pack, read through `source`, with its index and resolved columns: what a step reads its batch from.
59export type TransferPack = { readonly source: RangeSource; readonly pack: ScannedPack; readonly resolved: ResolvedIndex };
60export type TransferConfig = {
61 // the host's per-push limits, before ply's own reserve for generated objects (added here)
62 readonly budget: PushBudget;
63 // the ref to create on the destination; it must not exist there (any value: refused unless git would push it)
64 readonly ref: string;
65 // the source commit's bytes (scanPackIndex's content callback hands them over)
66 readonly commit: Uint8Array;
67 // where temp refs live (default refs/ply/transfer/); it ends in '/'
68 readonly tempPrefix: string;
69 // a delta whose base is pushed in an earlier batch, as REF_DELTA (packPlan crossBatchRef; default off)
70 readonly crossBatchRef: boolean;
71 // the last push creates the ref and deletes the temp ref atomically (default); false: one push, not atomic
72 readonly atomic: boolean;
73};
74export type TransferOpts = Pick<TransferConfig, 'budget' | 'ref' | 'commit'> & Input<Omit<TransferConfig, 'budget' | 'ref' | 'commit'>>;
75// A step: a batch moves the temp ref from `prev` (none: the temp ref does not exist yet) to its temp commit; the final
76// step creates the target ref from `prev` (the temp ref to delete, none when the transfer is one push). The plan is
77// stored as JSON between requests: an Option is plain JSON ({"tag":"none"} / {"tag":"some","value":...}).
78export type BatchStep = { readonly kind: 'batch'; readonly temp: Oid; readonly prev: Option<Oid> };
79export type FinalStep = { readonly kind: 'final'; readonly prev: Option<Oid> };
80export type TransferStepPlan = BatchStep | FinalStep;
81export type TransferPlan = {
82 readonly version: typeof TRANSFER_VERSION;
83 readonly source: Oid;
84 readonly tree: Oid;
85 // the new root commit the ref is created at
86 readonly head: Oid;
87 readonly ref: Refname;
88 readonly tempRef: TempRef;
89 readonly atomic: boolean;
90 readonly pack: PackPlan;
91 readonly steps: readonly TransferStepPlan[];
92 // SHA-1 hex of the canonical JSON of everything above
93 readonly hash: string;
94};
95export type GeneratedType = typeof TYPE.TREE | typeof TYPE.COMMIT;
96export type GeneratedObject = { readonly type: GeneratedType; readonly data: Uint8Array; readonly oid: Oid };
98const outOfRange = (i: number): Result<never, PlyError> => fail('bad_request', `transfer: entry ${i} is not in the resolved index`, { what: 'entry' });
99// The resolved id and type of entry `i`, read through the index's checked accessors. The index is the caller's object:
100// what its accessor throws is the cause of a refusal, never an exception out of a plan, a step or a run.
101function entryAt(r: ResolvedIndex, i: number): Result<{ readonly oid: Oid; readonly type: ScannedType }, PlyError> {
102 try {
103 const oid = r.oid(i);
104 const type = r.type(i);
105 return oid.tag === 'some' && type.tag === 'some' ? ok({ oid: oid.value, type: type.value }) : outOfRange(i);
106 } catch (cause) {
107 return fail('bad_request', `transfer: the resolved index threw reading entry ${i}`, { what: 'entry', cause });
108 }
109}
111// The temp tree for a batch: its objects by id, fanned out by the id's first two hex digits. The root tree is last.
112export function batchTrees(resolved: ResolvedIndex, entries: readonly number[]): Result<{ readonly subtrees: readonly GeneratedObject[]; readonly root: GeneratedObject }, PlyError> {
113 // by fan, then by name: an id the batch holds twice (a pack may) is listed once
114 const groups = new Map<string, Map<string, EntryOf>>();
115 for (const i of entries) {
116 const e = entryAt(resolved, i);
117 if (!e.ok) return e;
118 const { oid, type } = e.value;
119 const fan = oid.slice(0, 2);
120 const group = getOrElse(mapGet(groups, fan), new Map<string, EntryOf>());
121 group.set(oid.slice(2), { mode: type === OBJ_TREE ? MODE_TREE : MODE_BLOB, name: oid.slice(2), oid });
122 groups.set(fan, group);
123 }
124 const subtrees: GeneratedObject[] = [];
125 const top: EntryOf[] = [];
126 for (const [fan, group] of groups) {
127 const data = encodeEntries([...group.values()]);
128 if (!data.ok) return data;
129 const oid = hashObject('tree', data.value);
130 subtrees.push({ type: OBJ_TREE, data: data.value, oid });
131 top.push({ mode: MODE_TREE, name: fan, oid });
132 }
133 const rootData = encodeEntries(top);
134 if (!rootData.ok) return rootData;
135 return ok({ subtrees, root: { type: OBJ_TREE, data: rootData.value, oid: hashObject('tree', rootData.value) } });
136}
138// A commit object, encoded and hashed.
139function commitObject(fields: Parameters<typeof encodeCommitOf>[0]): Result<GeneratedObject, PlyError> {
140 const data = encodeCommitOf(fields);
141 return data.ok ? ok({ type: OBJ_COMMIT, data: data.value, oid: hashObject('commit', data.value) }) : data;
142}
144// A batch's temp commit over its temp root tree, its parent the previous temp commit.
145export function tempCommit(key: string, step: number, steps: number, tree: Oid, prev: Option<Oid>): Result<GeneratedObject, PlyError> {
146 return commitObject({ tree, parents: prev.tag === 'some' ? [prev.value] : [], author: TRANSFER_IDENT, committer: TRANSFER_IDENT, message: `ply transfer ${key} batch ${step + 1} of ${steps}\n` });
147}
149// The source commit's headers without signatures (a header line and its continuation lines).
150function unsigned(extra: readonly string[]): string[] {
151 const out: string[] = [];
152 let dropping = false;
153 for (const line of extra) {
154 if (line.startsWith(' ')) { if (!dropping) out.push(line); continue; }
155 dropping = SIGNATURE_HEADERS.some(h => line.startsWith(`${h} `));
156 if (!dropping) out.push(line);
157 }
158 return out;
159}
161// The new root commit: the source commit's tree and headers (see the commit policy above), no parents.
162export function rootCommit(source: Uint8Array): Result<{ readonly source: Oid; readonly tree: Oid; readonly commit: GeneratedObject }, PlyError> {
163 const c = parseCommit(source);
164 if (!c.ok) return c;
165 const v = c.value;
166 const made = commitObject({ tree: v.tree, parents: [], author: v.author, committer: v.committer, encoding: v.encoding, message: v.message, extra: unsigned(v.extra) });
167 return made.ok ? ok({ source: hashObject('commit', source), tree: v.tree, commit: made.value }) : made;
168}
170// The caller's budget with room for each batch's generated objects and the commands.
171function reserved(b: PushBudget): PushBudget {
172 return { ...b, reserveObjects: b.reserveObjects + TRANSFER_GENERATED_OBJECTS, reserveBytes: b.reserveBytes + b.maxObjects * GEN_BYTES_PER_OBJECT + GEN_BYTES_FIXED };
173}
175// A step as canonical JSON: the variant's tag first, an absent prev as null (never the same text as an id).
176const optionJson = (o: Option<Oid>): Oid | null => (o.tag === 'some' ? o.value : null);
177const stepJson = (s: TransferStepPlan): ReadonlyArray<string | null> => (s.kind === 'batch' ? ['batch', s.temp, optionJson(s.prev)] : ['final', optionJson(s.prev)]);
178function canonical(p: Omit<TransferPlan, 'hash'>): string {
179 return JSON.stringify([p.version, p.source, p.tree, p.head, p.ref, p.tempRef, p.atomic, p.pack.hash, p.steps.map(stepJson)]);
180}
181// The hash a plan should carry; a plan read back from storage is checked with it before a step uses it.
182export const transferPlanHash = (p: Omit<TransferPlan, 'hash'>): string => sha1Hex(canonical(p));
184// Only the commit's tree and blobs are copied: a commit or tag in the pack is left out (the new commit replaces it).
185function treeEntries(pack: ScannedPack, resolved: ResolvedIndex): Result<number[], PlyError> {
186 const out: number[] = [];
187 for (let i = 0; i < pack.count; i++) {
188 const e = entryAt(resolved, i);
189 if (!e.ok) return e;
190 if (e.value.type === OBJ_TREE || e.value.type === OBJ_BLOB) out.push(i);
191 }
192 return ok(out);
193}
195// A batch's generated objects: its temp trees and temp commit (the commit last).
196export function tempFor(resolved: ResolvedIndex, entries: readonly number[], place: { readonly key: string; readonly step: number; readonly steps: number; readonly prev: Option<Oid> }): Result<{ readonly objects: readonly GeneratedObject[]; readonly commit: GeneratedObject }, PlyError> {
197 const trees = batchTrees(resolved, entries);
198 if (!trees.ok) return trees;
199 const { subtrees, root } = trees.value;
200 const commit = tempCommit(place.key, place.step, place.steps, root.oid, place.prev);
201 if (!commit.ok) return commit;
202 return ok({ objects: [...subtrees, root, commit.value], commit: commit.value });
203}
205// The steps, one per batch: each batch's temp commit is the next one's prev.
206function planSteps(resolved: ResolvedIndex, planned: PackPlan, key: string): Result<TransferStepPlan[], PlyError> {
207 const steps: TransferStepPlan[] = [];
208 let prev: Option<Oid> = none;
209 const n = planned.batches.length;
210 for (const [i, b] of planned.batches.entries()) {
211 if (b.kind === 'final') { steps.push({ kind: 'final', prev }); continue; }
212 const made = tempFor(resolved, b.entries, { key, step: i, steps: n, prev });
213 if (!made.ok) return made;
214 const temp = made.value.commit.oid;
215 steps.push({ kind: 'batch', temp, prev });
216 prev = some(temp);
217 }
218 return ok(steps);
219}
221// Plan a transfer of `opts.commit`'s tree (see the top of this file). Refusals (a ref git would not push, a tree not in
222// the pack, a budget an object cannot fit, anything planPackBatches refuses) happen here, before anything is pushed.
223export function planTransfer(pack: ScannedPack, resolved: ResolvedIndex, input: TransferOpts): Result<TransferPlan, PlyError> {
224 const shape = argsError('planTransfer', [['pack', pack, 'object'], ['resolved', resolved, 'object'], ['options', input, 'object']]);
225 if (shape !== null) return shape;
226 const opts = withDefaults<TransferConfig>(input, { budget: input.budget, ref: input.ref, commit: input.commit, tempPrefix: TRANSFER_REF_PREFIX, crossBatchRef: false, atomic: true });
227 const ref = targetRef(opts.ref);
228 if (!ref.ok) return ref;
229 const root = rootCommit(opts.commit);
230 if (!root.ok) return root;
231 const { tree } = root.value;
232 // ResolvedIndex.find is a lookup by id, not Array#find
233 const lookup = resolved.find;
234 const treeAt = lookup(tree);
235 const treeType = treeAt.tag === 'some' ? resolved.type(treeAt.value) : none;
236 if (treeType.tag !== 'some' || treeType.value !== OBJ_TREE) {
237 return fail('bad_request', `transfer: the commit's tree ${tree} is not a tree in the pack`, { what: 'tree' });
238 }
239 const select = treeEntries(pack, resolved);
240 if (!select.ok) return select;
241 const planned = planPackBatches(pack, resolved, { budget: reserved(opts.budget), select: select.value, crossBatchRef: opts.crossBatchRef });
242 if (!planned.ok) return planned;
243 const head = root.value.commit.oid;
244 const key = sha1Hex(JSON.stringify([planned.value.hash, head, ref.value]));
245 const tempRef = tempRefOf(opts.tempPrefix, key);
246 if (!tempRef.ok) return tempRef;
247 const steps = planSteps(resolved, planned.value, key);
248 if (!steps.ok) return steps;
249 const body = { version: TRANSFER_VERSION, source: root.value.source, tree, head, ref: ref.value, tempRef: tempRef.value, atomic: opts.atomic, pack: planned.value, steps: steps.value } as const;
250 return ok({ ...body, hash: transferPlanHash(body) });
251}
253// The key a plan's temp commits and temp ref are named by.
254export const transferKey = (plan: TransferPlan): string => sha1Hex(JSON.stringify([plan.pack.hash, plan.head, plan.ref]));
256// What the caller of this call holds a plan read back to: the one ref this transfer may create, named on every call
257// (a stored plan is never trusted to choose it), and the prefix its temp ref was planned under (default
258// refs/ply/transfer/; a plan made with a custom tempPrefix is resumed by naming it again).
259export type PlanExpectConfig = { readonly tempPrefix: string; readonly ref: string };
260export type PlanExpect = Pick<PlanExpectConfig, 'ref'> & Input<Omit<PlanExpectConfig, 'ref'>>;
262const edited = (): Result<never, PlyError> => fail('bad_request', 'transfer: the plan does not match its hash', { what: 'plan' });
263// A step read back: one of the two variants, its ids well formed, its prev an Option of one.
264function wellFormedStep(s: TransferStepPlan): boolean {
265 if (typeof s !== 'object' || s === null || !isOptionOid(s.prev)) return false;
266 if (s.kind === 'batch') return isOid(s.temp);
267 return s.kind === 'final' && !Reflect.has(s, 'temp');
268}
270// A count or an entry index as JSON gives it back: a non-negative safe integer.
271const isCount = (v: unknown): boolean => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0;
272// Every element of a list read back passes, a hole included. Array#every skips a hole (an index below the length that
273// is not an element: a structured-clone store can hand one back, JSON cannot); for...of visits it, as a value that
274// is no number and no object, which no element check here passes. So a plan with a hole in its steps, batches,
275// selection or a batch's entries is not well formed, and nothing after the shape check meets one.
276function everyOf<T>(list: readonly T[], pass: (v: T, i: number) => boolean): boolean {
277 let i = 0;
278 for (const v of list) {
279 if (!pass(v, i)) return false;
280 i += 1;
281 }
282 return true;
283}
284// The plan's long lists (the selection, a batch's entries): the same walk, with no call per element but isCount.
285function isCounts(v: readonly number[]): boolean {
286 if (!isList(v)) return false;
287 for (const n of v) if (!isCount(n)) return false;
288 return true;
289}
290function wellFormedBatch(b: PlannedBatch): boolean {
291 if (typeof b !== 'object' || b === null || (b.kind !== 'blobs' && b.kind !== 'final')) return false;
292 return isCount(b.packBytes) && isCount(b.objects) && isCount(b.refRewrites) && isCounts(b.entries);
293}
294function wellFormedBudget(b: PushBudget): boolean {
295 if (typeof b !== 'object' || b === null) return false;
296 return [b.maxRequestBytes, b.maxObjects, b.maxObjectBytes, b.maxCompressedObjectBytes, b.reserveBytes, b.reserveObjects].every(n => isCount(n));
297}
298// The pack plan, every field planHash and a step read: one batch per step, a blobs batch for a batch step and the
299// final batch for the final step.
300function wellFormedPack(p: PackPlan, steps: readonly TransferStepPlan[]): boolean {
301 if (typeof p !== 'object' || p === null || p.version !== PLAN_VERSION || typeof p.hash !== 'string' || typeof p.trailer !== 'string') return false;
302 if (typeof p.crossBatchRef !== 'boolean' || !isCount(p.entries) || !wellFormedBudget(p.budget)) return false;
303 if (p.select !== null && !isCounts(p.select)) return false;
304 if (!isList(p.batches) || p.batches.length !== steps.length || !everyOf(p.batches, b => wellFormedBatch(b))) return false;
305 return everyOf(p.batches, (b, i) => {
306 const s = at(steps, i);
307 return s.tag === 'some' && (b.kind === 'final') === (s.value.kind === 'final');
308 });
309}
311// The batches partition the selection: the selection is entry indices in pack order (ascending, as planTransfer
312// selects them), every selected entry is in exactly one batch, no batch holds anything else, and each count is the
313// length it counts. A hash cannot hold this (whoever wrote the plan wrote the hash), so it is checked directly.
314// Memory: one set of the selection, which the plan already holds.
315function partitions(p: PackPlan): boolean {
316 const { select } = p;
317 if (select === null || p.entries !== select.length) return false;
318 let prev = -1;
319 for (const i of select) {
320 if (i <= prev) return false;
321 prev = i;
322 }
323 const left = new Set(select);
324 for (const b of p.batches) {
325 if (b.objects !== b.entries.length) return false;
326 for (const i of b.entries) if (!left.delete(i)) return false;
327 }
328 return left.size === 0;
329}
331// Every field the check, the key, the two hashes and a step read: ids, refs, the steps (each well formed before its
332// kind is read; the last the only final one), the pack plan.
333function wellFormedPlan(plan: TransferPlan): boolean {
334 if (typeof plan !== 'object' || plan === null || plan.version !== TRANSFER_VERSION) return false;
335 if (!isOid(plan.source) || !isOid(plan.tree) || !isOid(plan.head) || !isList(plan.steps)) return false;
336 if (!targetRef(plan.ref).ok || typeof plan.tempRef !== 'string' || typeof plan.atomic !== 'boolean' || typeof plan.hash !== 'string') return false;
337 const last = plan.steps.length - 1;
338 if (last < 0 || !everyOf(plan.steps, (s, i) => wellFormedStep(s) && (s.kind === 'final') === (i === last))) return false;
339 return wellFormedPack(plan.pack, plan.steps);
340}
342// A plan as read back (JSON, a store) is untrusted input. The check, which transferStatus, transferStep and
343// runTransfer all make before they act or answer:
344// - it is total: every field the check, a hash or a later step reads (ids, refs, steps, the pack plan's budget,
345// selection, batches and their entries) has its type and shape checked first, so a plan of any shape is answered
346// with bad_request, never a TypeError. A hole in any of its arrays is such a shape (everyOf): what 'plan';
347// - its temp ref is not a free field: it must be the name tempRefOf derives from the plan's key under the caller's
348// prefix, and never the target ref. So the only refs a plan can make a push create, move or delete are
349// refs/ply/transfer/<key> (or the caller's prefix) and the target ref;
350// - its target ref is not a free field: the caller names the ref on every call (`expect.ref`), the plan's must
351// equal it, and a call that names none is refused;
352// - both hashes are recomputed and match: the pack plan's own (planHash: trailer, budget, crossBatchRef, selection,
353// entry count, every batch and its entries) and the transfer's (ids, refs, atomic, the pack plan's hash, the
354// steps), so every field a step reads is under a hash. The hashes are unkeyed (both functions are public): they
355// are integrity against corruption and stale or partial writes, NOT authentication against whoever can write the
356// plan store. What bounds a hostile
357// plan is the temp ref rule above, the named target ref, the partition rule below and the destination's own
358// checks (every update is a compare-and-swap; the server checks connectivity);
359// - what the steps push is not a free field either: the batches partition the selection (every selected entry in
360// exactly one batch, nothing else in any), and transferStep and runTransfer, which hold the pack, check the
361// selection is exactly the pack's trees and blobs (planFitsPack) before any request.
362export function checkTransferPlan(plan: TransferPlan, expect: PlanExpect): Result<TransferPlan, PlyError> {
363 const want = withDefaults<PlanExpectConfig>(expect, { tempPrefix: TRANSFER_REF_PREFIX, ref: '' });
364 // the caller's own argument first: no ref named, nothing is read from the plan
365 if (typeof want.ref !== 'string' || want.ref === '') return fail('bad_request', 'transfer: name the ref this transfer creates (`ref`) on every call with a stored plan; the plan is not trusted to choose it', { what: 'ref' });
366 if (!wellFormedPlan(plan)) return edited();
367 const { hash, ...body } = plan;
368 // corruption first (an honest plan, damaged), then what holds whoever wrote the hash
369 const { hash: packHash, ...packBody } = plan.pack;
370 if (planHash(packBody) !== packHash || transferPlanHash(body) !== hash) return edited();
371 if (!partitions(plan.pack)) return fail('bad_request', 'transfer: the plan\'s batches are not its selection, each entry in one batch', { what: 'batches' });
372 const named = tempRefOf(want.tempPrefix, transferKey(plan));
373 if (!named.ok || plan.tempRef !== named.value || plan.tempRef === plan.ref) return fail('bad_request', 'transfer: the plan\'s temp ref is not the one its key names under this call\'s `tempPrefix` (a plan made with a custom tempPrefix is resumed by naming it)', { what: 'tempRef' });
374 if (plan.ref !== want.ref) return fail('bad_request', `transfer: the plan is for ${plan.ref}, not the ref this call names`, { what: 'ref' });
375 return ok(plan);
376}
378// The plan is for this pack: its trailer, and its selection exactly the pack's trees and blobs in pack order (what
379// planTransfer selects). With the partition checkTransferPlan makes, this holds what a run pushes to the pack's trees
380// and blobs, each once, whatever hashes the plan carries: transferStep and runTransfer make it before any request.
381// One pass over the index, nothing allocated.
382export function planFitsPack(plan: TransferPlan, pack: ScannedPack, resolved: ResolvedIndex): Result<TransferPlan, PlyError> {
383 if (pack.trailer !== plan.pack.trailer) return fail('bad_request', `transfer: the pack (trailer ${pack.trailer}) is not the planned one (${plan.pack.trailer})`, { what: 'pack' });
384 const select = getOrElse<readonly number[]>(plan.pack.select === null ? none : some(plan.pack.select), []);
385 let k = 0;
386 for (let i = 0; i < pack.count; i++) {
387 // the type column alone: no id is built per entry
388 const type = resolved.type(i);
389 if (type.tag !== 'some') return outOfRange(i);
390 if (type.value !== OBJ_TREE && type.value !== OBJ_BLOB) continue;
391 if (getOrElse(at(select, k), -1) !== i) return fail('bad_request', `transfer: the plan's selection is not the pack's trees and blobs (entry ${i}); the pack is not the one planned`, { what: 'pack' });
392 k++;
393 }
394 return k === select.length ? ok(plan) : fail('bad_request', 'transfer: the plan selects entries the pack does not hold as trees or blobs; the pack is not the one planned', { what: 'pack' });
395}
Diagnostics4 git calls · 445 ms
CallStatusSizeTime0445 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020038 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=38434 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=38434 git.pkt.payload.max=38339 git.sideband.band1.bytes=38338 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=63 git.pack.bytes=38338 git.pack.ofs_delta=0 git.pack.ref_delta=8 git.pack.chain.max=8 git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77 git.pack.full=55Open pack map
fetch2008.1 KiB439 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=439 git.response.bytes=8318 git.response.cache=MISS git.response.duration_ms=439 git.fetch.wants=a85b2cc813dd3355d535a75123396aa0445f18eb git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=8318 git.pkt.payload.max=8297 git.sideband.band1.bytes=8296 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply.git
- Ref
- refs/heads/main
- Commit
- 19912563f540228593df0c489082e5e2508e21e4
- cf-ray
- a5e2d28a9f83cf3a
- Request
- 8c855b37…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format