GitHubivarvong

ply

main
ply7 git calls109 ms25 KiB4 cachedprotocol v2
86 lines4.3 KiBRaw
1// The sweep operations that only need fetch: shared by the node cell (cell.mjs) and the workerd worker
2// (test/workerd/worker.mjs), so a workerd cell runs the same code path as its node twin. No node: imports here.
3import { readFile, listTree } from '../../src/read.js';
4import { readLog } from '../../src/log.js';
5import { editFile } from '../../src/edit.js';
6import { pushTree } from '../../src/tree.js';
7import { mergeBranch } from '../../src/merge.js';
8import { rebaseBranch } from '../../src/rebase.js';
9import { GitHttp } from '../../src/client.js';
10import { unwrap, unwrapAsync } from '../unwrap.js';
12const author = { name: 'sweep', email: 'sweep@example.com' };
13const when = 1700000000;
15/** The consumer holds the first chunk for holdMs before reading on (#273 heldTimeoutMs). @param {ReadableStream<Uint8Array>} stream @param {number} holdMs */
16async function drain(stream, holdMs = 0) {
17 let len = 0;
18 for await (const chunk of stream) {
19 if (len === 0 && holdMs > 0) await new Promise(r => setTimeout(r, holdMs));
20 len += chunk.byteLength;
21 }
22 return len;
25/** @param {any} cell @param {any} opts @returns {Record<string, () => Promise<Record<string, unknown>>>} */
26export function fetchOps(cell, opts) {
27 return {
28 async readFile() {
29 const r = await unwrapAsync(readFile(cell.url, { ref: cell.ref ?? null, path: cell.path }, opts));
30 const len = await drain(r.stream, cell.holdMs ?? 0);
31 return { blob: r.blob, size: r.size, len };
32 },
33 async listTree() {
34 const r = await unwrapAsync(listTree(cell.url, { ref: cell.ref ?? null, path: cell.path ?? '' }, opts));
35 return { tree: r.tree, n: r.entries.length };
36 },
37 async readLog() {
38 const r = await unwrapAsync(readLog(cell.url, { ref: cell.ref ?? 'main', limit: cell.limit }, opts));
39 return { n: r.commits.length, truncated: r.truncated };
40 },
41 async lsRefs() {
42 const r = await unwrapAsync(unwrap(GitHttp.create(cell.url, opts)).lsRefs(cell.prefixes ?? []));
43 return { n: r.refs.size, head: r.head };
44 },
45 async editFile() {
46 const r = await unwrapAsync(editFile(cell.url, { path: cell.path, find: cell.find, replace: cell.replace, author, message: 'sweep', time: when }, opts));
47 return { commit: r.newCommit };
48 },
49 async pushTree() {
50 /** @type {Record<string, Uint8Array>} */
51 const files = {};
52 for (let i = 0; i < cell.nfiles; i++) files[`f/${String(i).padStart(7, '0')}.bin`] = new Uint8Array(cell.size).fill((i + 1) & 255);
53 const r = await unwrapAsync(pushTree(cell.url, { ref: 'refs/heads/main', files, author, message: 'sweep', time: when }, opts));
54 return { commit: r.newCommit, noop: r.noop };
55 },
56 async merge() {
57 const r = await unwrapAsync(mergeBranch(cell.url, { ref: 'refs/heads/main', from: cell.from, author, message: 'sweep merge', time: when }, opts));
58 return { outcome: r.outcome, base: r.base };
59 },
60 async rebase() {
61 const r = await unwrapAsync(rebaseBranch(cell.url, { ref: cell.ref, onto: cell.onto, committer: author, time: when }, opts));
62 return { outcome: r.outcome, oid: r.oid, commits: r.commits ?? null };
63 },
64 // One v2 fetch with the cell's wants, haves and deepen; the counts are what ply read from the section lines.
65 async fetchPack() {
66 const c = unwrap(GitHttp.create(cell.url, opts));
67 const r = await unwrapAsync(c.fetchPack({ wants: cell.wants, haves: cell.haves ?? [], deepen: cell.deepen ?? 0, done: cell.done ?? true, filter: cell.filter ?? '' }));
68 return { acks: r.acks.length, ready: r.ready, shallow: r.shallow.length, n: r.parsed?.stats.count ?? 0 };
69 },
70 };
73/** A typed refusal (a ply error with a code) or a crash, as one JSON-able record. @param {unknown} e */
74export function failure(e) {
75 const err = /** @type {{ code?: unknown, name?: string, message?: string, got?: unknown, max?: unknown, what?: unknown }} */ (e);
76 const typed = !!err && typeof err.code === 'string' && err.name !== 'TypeError' && err.name !== 'RangeError';
77 return {
78 status: typed ? 'refused' : 'crash',
79 code: typeof err?.code === 'string' ? err.code : null,
80 name: err?.name ?? null,
81 what: typeof err?.what === 'string' ? err.what : null,
82 got: typeof err?.got === 'number' ? err.got : null,
83 max: typeof err?.max === 'number' ? err.max : null,
84 msg: String(err?.message ?? e).slice(0, 300),
85 };
Diagnostics7 git calls · 109 ms
CallStatusSizeTime0109 ms
discover200191 B4 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=191
git.server.agent=git/github-9922ec520325-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=191
git.pkt.payload.max=36
ls-refs20012 KiB3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=11990
git.response.cache=UPDATING
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=152
git.pkt.data=151
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=11990
git.pkt.payload.max=122
git.ls_refs.count=151
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=4347
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
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=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4347
git.pkt.payload.max=4247
git.sideband.band1.bytes=4247
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=10
git.pack.bytes=4247
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400
git.pack.full=10
Open pack map
fetchtree:0200919 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=919
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=919
git.pkt.payload.max=892
git.sideband.band1.bytes=892
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=892
git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76e
Open pack map
fetchtree:02005.6 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=5724
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=58fabb6768b3f737ee9cd8bac647bdc27405fb4d
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=5724
git.pkt.payload.max=5697
git.sideband.band1.bytes=5697
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=5697
git.pack.trailer=be7e0453974a5fe832f9065a33bb7e3434c10e9b
Open pack map
fetchtree:0200381 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=94
git.response.bytes=381
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=294ee88709910bdf98d58eeb6898cd838de94a3a
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=381
git.pkt.payload.max=354
git.sideband.band1.bytes=354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=354
git.pack.trailer=2c7127c2c53a7ca2957296d420246ab2358e3775
Open pack map
fetch2001.6 KiB94 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1634
git.response.cache=MISS
git.response.duration_ms=94
git.fetch.wants=a223ef8df727538e37cdf6a73990bcd6d96e9c7c
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1634
git.pkt.payload.max=1607
git.sideband.band1.bytes=1607
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://github.com/ivarvong/ply
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e192e479a9ddf0
Request
8788ed23…
Protocol
v2 · sha1
Agent
git/github-9922ec520325-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format