GitHubivarvong

ply

main
ply7 git calls211 ms26 KiB5 cachedprotocol v2
116 lines7.1 KiBRaw
1// Parse once (#156): what the parsers return is branded, and the brand is still a string to a reader. `tsc --noEmit`
2// must pass; every @ts-expect-error must still be an error.
3import type { Oid } from '../../src/oid.js';
4import { hashObject, parseTree, type ObjType, type TreeEntry } from '../../src/objects.js';
5import { parseLsRefLine, type LsRef } from '../../src/lsrefs.js';
6import { readObjHeader, parsePack, resolvePack, parseDelta, describePack, type ObjBase, type ObjSize, type DeltaProgram, type PackObjectInput, type ResolvedObjType, type PackBase } from '../../src/packresolve.js';
7import { validateWire, type WireField } from '../../src/validate.js';
8import { fetchBody, fetchRequest, type FetchRequest } from '../../src/fetch.js';
9import { Sha1 } from '../../src/sha1.js';
11// object ids made from bytes in hand
12const hashed: Oid = hashObject('blob', new Uint8Array(0));
13const digest: Oid = new Sha1().hex();
14const text: string = hashed;
15void digest; void text;
16const tree = parseTree(new Uint8Array(0));
17if (tree.ok) for (const e of tree.value) { const entry: TreeEntry = e; const id: Oid = entry.oid; void id; }
18const line = parseLsRefLine('');
19if (line.ok && line.value !== null) { const r: LsRef = line.value; const id: Oid = r.oid; const peeled: Oid | null = r.peeled; void id; void peeled; }
21// a pack header's type is one of the six, and a parsed REF base is an Oid
22const header = readObjHeader(new Uint8Array(0), 0);
23if (header.ok) { const t: ObjType = header.value.type; void t; }
24if (header.ok) { const size: ObjSize = header.value.size; const n: number = size; void n; }
25// @ts-expect-error a plain number is not a checked object size
26const forgedSize: ObjSize = 3;
27void forgedSize;
28const pack = parsePack(new Uint8Array(0));
29if (pack.ok) {
30 for (const o of pack.value.objects) {
31 const t: ObjType = o.type;
32 const base: ObjBase = o.base;
33 if (base.tag === 'ref') { const id: Oid = base.oid; void id; }
34 if (base.tag === 'ofs') { const at: number = base.offset; void at; }
35 void t;
36 }
37 // a parsed pack is resolvePack's input as it is
38 void resolvePack(pack.value);
40// resolvePack also takes objects built by hand with plain values (parsed at its edge: an invalid one is bad_request)
41const handBuilt: PackObjectInput[] = [
42 { offset: 12, type: 3, data: new Uint8Array(0) },
43 { offset: 30, type: 6, data: new Uint8Array(0), base: { tag: 'ofs', offset: 12 } },
44 { offset: 40, type: 7, data: new Uint8Array(0), base: { tag: 'ref', oid: 'a'.repeat(40) } },
45];
46const resolved = resolvePack({ objects: handBuilt }, oid => (oid === 'a'.repeat(40) ? { type: 3, data: new Uint8Array(0) } : null));
47if (resolved.ok) for (const r of resolved.value.objects.values()) { const t: ResolvedObjType = r.type; const id: Oid = r.oid; void t; void id; }
48// @ts-expect-error a ref base is not a plain number
49const badBase: PackObjectInput = { offset: 1, type: 7, data: new Uint8Array(0), base: { tag: 'ref', oid: 1 } };
50void badBase;
51// a delta is parsed once into a program; only parseDelta makes one
52const program = parseDelta(new Uint8Array(0));
53if (program.ok) { const p: DeltaProgram = program.value; const n: number = p.dstSize; void n; }
54// @ts-expect-error a DeltaProgram is not built by hand
55const forgedProgram: DeltaProgram = { srcSize: 0, dstSize: 0, ops: { copy: 0, insert: 0, copyBytes: 0, insertBytes: 0 }, code: new Uint8Array(0), start: 0 };
56void forgedProgram;
57// describePack's rows: wire type, resolved type, ids and a tagged base
58const layout = describePack(new Uint8Array(0));
59if (layout.ok) for (const o of layout.value.objects) { const b: PackBase = o.base; const id: Oid | null = o.oid; const w: ObjType = o.wireType; void b; void id; void w; }
61// a wire field is made only by validateWire
62// @ts-expect-error a plain string is not a WireField
63const forged: WireField = 'x';
64void forged;
65const wire = validateWire('x', 'field');
66if (wire.ok) { const w: WireField = wire.value; const s: string = w; void s; }
68// FetchOpts stays plain strings in; the parsed request's wants, haves and shallows are Oids, the other tokens wire fields
69void fetchBody({ wants: ['a'.repeat(40)], haves: ['b'.repeat(40)], shallows: ['c'.repeat(40)], filter: 'blob:none', deepen: 1 });
70const req = fetchRequest({ wants: ['a'.repeat(40)] });
71if (req.ok) {
72 const r: FetchRequest = req.value;
73 for (const w of r.wants) { const want: Oid = w; void want; }
74 for (const h of r.haves) { const have: Oid = h; void have; }
75 for (const s of r.shallows) { const shallow: Oid = s; void shallow; }
76 for (const n of r.deepenNot) { const not: WireField = n; void not; }
78declare const someField: WireField;
79// @ts-expect-error a parsed have is an Oid, not just a wire field
80const haveField: FetchRequest['haves'][number] = someField;
81void haveField;
82// @ts-expect-error a FetchRequest is not built from plain strings
83const forgedReq: FetchRequest = { wants: ['x'], haves: [], shallows: [], deepenNot: [], filter: null, deepen: 0, deepenSince: 0, deepenRelative: false, thinPack: false, ofsDelta: true, includeTag: false, noProgress: true, done: true };
84void forgedReq;
86// part 2: listed names, parsed commits, tree entries, ids at the entries, the edit plan
87import type { ListedName } from '../../src/lsrefs.js';
88import { parseCommit, treeEntryOf, encodeEntries, type EntryOf, type Mode } from '../../src/objects.js';
89import { mergeBaseOf, type MergeBase } from '../../src/merge.js';
90import { objectAt } from '../../src/fetch.js';
91import { commitById } from '../../src/commit.js';
92import { validateSpec, type EditBase } from '../../src/edit.js';
93import type { Transport } from '../../src/transport.js';
94import { DEFAULT_LIMITS } from '../../src/limits.js';
95declare const tr: Transport;
96if (line.ok && line.value !== null) { const n: ListedName = line.value.name; const s: string = n; void s; }
97// @ts-expect-error a plain string is not a listed name
98const forgedName: ListedName = 'HEAD';
99void forgedName;
100const commit = parseCommit(new Uint8Array(0));
101if (commit.ok) { const tree: Oid = commit.value.tree; const parents: readonly Oid[] = commit.value.parents; void tree; void parents; }
102const entry = treeEntryOf({ mode: '100644', name: 'f', oid: 'a'.repeat(40) });
103if (entry.ok) { const e: EntryOf = entry.value; const m: Mode = e.mode; const id: Oid = e.oid; void m; void id; void encodeEntries([e]); }
104// @ts-expect-error encodeEntries takes parsed entries, not plain strings
105void encodeEntries([{ mode: '100644', name: 'f', oid: 'a'.repeat(40) }]);
106// @ts-expect-error the internals take an Oid
107void objectAt(tr, 'a'.repeat(40));
108// @ts-expect-error the internals take an Oid
109void commitById(tr, 'a'.repeat(40));
110// @ts-expect-error the internals take an Oid
111void mergeBaseOf(tr, 'a'.repeat(40), 'a'.repeat(40));
112if (header.ok) { void objectAt(tr, hashed); void commitById(tr, hashed); }
113const mb = await mergeBaseOf(tr, hashed, hashed);
114if (mb.ok) { const r: MergeBase = mb.value; const base: Oid | null = r.base; void base; for (const [k] of r.commits) { const id: Oid = k; void id; } }
115const plan = validateSpec({ path: 'a', find: 'x', replace: 'y', author: { name: 'n', email: 'e' }, message: 'm' }, DEFAULT_LIMITS);
116if (plan.ok) { const b: EditBase = plan.value.base; if (b.kind === 'commit') { const id: Oid = b.oid; void id; } const h: Oid | null = plan.value.head; void h; }
Diagnostics7 git calls · 211 ms
CallStatusSizeTime0211 ms
discover200191 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=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 KiB159 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=103
git.response.bytes=11990
git.response.cache=EXPIRED
git.response.duration_ms=159
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 · hit2 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=2
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 · 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=5724
git.response.cache=HIT
git.response.duration_ms=3
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:0200746 B · 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=746
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=1a4f84aea08d080a229290d401e77da8415108a0
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=746
git.pkt.payload.max=719
git.sideband.band1.bytes=719
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=719
git.pack.trailer=fd3904a205b94cd1bbf03c591c9acea7ca5dd5a7
Open pack map
fetch2002.4 KiB · hit40 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=40
git.response.bytes=2422
git.response.cache=HIT
git.response.duration_ms=40
git.fetch.wants=337d683c36421f199f6b938d8dd207a80f22654d
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=2422
git.pkt.payload.max=2395
git.sideband.band1.bytes=2395
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
a5e1c98cfa4dc6f8
Request
eadd9fae…
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