GitHubivarvong

ply

main
ply6 git calls44 ms22 KiB5 cachedprotocol v2
92 lines6.0 KiBRaw
1// The full client as one object: every wire operation (ls-refs, fetch, negotiate, push, advertisements) over one
2// transport. Convenience for scripts and tests; bundles that care about size import the free functions directly
3// (transport.js, lsrefs.js, fetch.js, push.js...) — a class cannot be tree-shaken, a function can.
4import type { CheckedLimits } from './limits.js';
5import type { Span, Tracer } from './otel.js';
6import type { Transport } from './transport.js';
7import type { HttpOptions } from './http.js';
8import type { FetchOpts, ObjectWant, FetchedObject, PackFetch } from './fetch.js';
9import type { FetchPackExtra, FetchPackResult } from './fetchpack.js';
10import type { NegotiateOpts, NegotiateResult } from './negotiate.js';
11import type { LsRefsResult } from './lsrefs.js';
12import type { DiscoverInfo } from './discover.js';
13import { createTransport } from './http.js';
14import { lsRefs as lsRefsWire, parseUnbornLine } from './lsrefs.js';
15import { packStream, fetchObject } from './fetch.js';
16import { fetchPack } from './fetchpack.js';
17import { negotiate } from './negotiate.js';
18import type { PushResult as PushOk } from './push.js';
19// oxlint-disable-next-line import/max-dependencies -- the one module that gathers every wire operation
20import { receiveCaps, pushWithOptions, pushPack } from './receivecaps.js';
21import type { CheckedPackPushOptions, CheckedPushOptions } from './receivecaps.js';
22import { discover } from './discover.js';
23import type { Input } from './absent.js';
24import { withDefaults } from './absent.js';
25import type { PlyError } from './errors.js';
26import { ok } from './result.js';
27import type { Result } from './result.js';
29// A3: the audit deletes the unused re-exports below; they are public API until then.
30export { createTransport, redactUrl } from './http.js';
31export { UA, withParent, forgetQuirks } from './transport.js';
32export { lsRefsBody, parseUnbornLine } from './lsrefs.js';
33export type { LsRef, LsRefsResult, LsRefsUnborn, ListedName } from './lsrefs.js';
34export { fetchBody, v2Init, v2Step, v2Attrs, packStream, fetchObject, spInit, spStep, spFinish, isFilterRejection, isFilterRefusal } from './fetch.js';
35export { fetchPack, fetchPackFiltered, packAttrs } from './fetchpack.js';
36export { negotiate } from './negotiate.js';
37export { ZERO_OID, pushBody, classifyReport, decideOutcome, push } from './push.js';
38export { receiveCaps, capsProblem, checkPushCaps, pushWithOptions, pushPack } from './receivecaps.js';
39export { discover, parseCapabilitiesV2, capLookup } from './discover.js';
41// lsRefs options. unborn: ask for the unborn HEAD (an empty repository's `HEAD -> refs/heads/main`), as git's clone does:
42// the argument is sent only when the server's advertisement lists `ls-refs=unborn` (connect.c: server_supports_feature),
43// so asking costs one advertisement round trip unless `info` (a discover() result already in hand) answers it. A server
44// that does not advertise it gets no argument, and `unborn` is null. `info: null` is no advertisement in hand.
45export type LsRefsConfig = { readonly unborn: boolean; readonly info: Pick<DiscoverInfo, 'lsRefsUnborn'> | null };
46export type LsRefsOptions = Input<LsRefsConfig>;
48// ls-refs over `t`. The edit and read paths call the wire exchange (lsrefs.ts) directly: they never ask for the unborn
49// HEAD, so the advertisement parser stays out of their bundles.
50export async function lsRefs(t: Transport, prefixes: readonly string[] = [], options: LsRefsOptions = {}): Promise<Result<LsRefsResult, PlyError>> {
51 const { unborn, info } = withDefaults<LsRefsConfig>(options, { unborn: false, info: null });
52 let ask = false;
53 if (unborn) {
54 if (info === null) {
55 const found = await discover(t);
56 if (!found.ok) return found;
57 ask = found.value.lsRefsUnborn;
58 } else ask = info.lsRefsUnborn;
59 }
60 return lsRefsWire(t, prefixes, ask ? { unborn: parseUnbornLine } : {});
63// push options as GitHttp.push takes them: atomic and push options are checked against the advertisement (receivecaps.ts).
64export type PushOpts = CheckedPushOptions;
65type Answer<T> = Promise<Result<T, PlyError>>;
67/* oxlint-disable typescript/promise-function-async -- pass-throughs: each returns the free function's own promise (an argument that throws synchronously still does) */
68export class GitHttp {
69 declare public readonly t: Transport;
70 private constructor(t: Transport) { this.t = t; }
71 // The client for `url`: createTransport's Err (a bad URL, an unusable credential) when there is no transport to build.
72 public static create(url: string, opts: HttpOptions = {}): Result<GitHttp, PlyError> {
73 const t = createTransport(url, opts);
74 return t.ok ? ok(new GitHttp(t.value)) : t;
75 }
76 public get url(): string { return this.t.url; }
77 public get limits(): CheckedLimits { return this.t.limits; }
78 public get tracer(): Tracer { return this.t.tracer; }
79 public get parent(): Span | null { return this.t.parent; }
80 // Each omitted argument is the free function's own default; each answer is the free function's Result.
81 public lsRefs(prefixes: readonly string[] = [], opts: LsRefsOptions = {}): Answer<LsRefsResult> { return lsRefs(this.t, prefixes, opts); }
82 public packStream(opts: FetchOpts, span: Span): PackFetch { return packStream(this.t, opts, span); }
83 public fetchObject(opts: ObjectWant): Answer<FetchedObject> { return fetchObject(this.t, opts); }
84 public fetchPack(opts: FetchOpts, extra: FetchPackExtra = {}): Answer<FetchPackResult> { return fetchPack(this.t, opts, extra); }
85 public negotiate(opts: NegotiateOpts, extra: Pick<FetchPackExtra, 'external' | 'resolve'> = {}): Answer<NegotiateResult> { return negotiate(this.t, opts, extra); }
86 // pushWithOptions reads the advertisement only when the push asks for atomic or push options
87 public push(opts: PushOpts): Answer<PushOk> { return pushWithOptions(this.t, opts); }
88 public pushPack(opts: CheckedPackPushOptions): Answer<PushOk> { return pushPack(this.t, opts); }
89 public receiveCaps(): Answer<Set<string>> { return receiveCaps(this.t); }
90 public discover(): Answer<DiscoverInfo> { return discover(this.t); }
92/* oxlint-enable typescript/promise-function-async */
Diagnostics6 git calls · 44 ms
CallStatusSizeTime044 ms
discover200191 B2 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 KiB · 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=11990
git.response.cache=HIT
git.response.duration_ms=2
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 · 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=4347
git.response.cache=HIT
git.response.duration_ms=2
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:02002.4 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=35
git.response.bytes=2507
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=8f720d29ff85ce682ffdad9c393b04a3834c3203
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=2507
git.pkt.payload.max=2480
git.sideband.band1.bytes=2480
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=2480
git.pack.trailer=723b6bf1d4d6021fe5eb940c622b9ff00ee4a381
Open pack map
fetch2002.2 KiB · hit35 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2235
git.response.cache=HIT
git.response.duration_ms=35
git.fetch.wants=f571c33a261cabcb3c04f9cae3003b82ae6d0dd0
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=2235
git.pkt.payload.max=2208
git.sideband.band1.bytes=2208
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
a5e0fb9f28a1332c
Request
25afaed1…
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