main
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 } : {});
61}
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); }
91}
92/* oxlint-enable typescript/promise-function-async */
Diagnostics4 git calls · 35 ms
CallStatusSizeTime035 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 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 · hit3 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=145 git.response.cache=HIT git.response.duration_ms=3 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 · 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=38434 git.response.cache=HIT git.response.duration_ms=2 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
fetch2002.2 KiB · hit30 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=30 git.response.bytes=2214 git.response.cache=HIT git.response.duration_ms=30 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=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2214 git.pkt.payload.max=2193 git.sideband.band1.bytes=2192 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
- a5e2c6bb7df54afc
- Request
- 5e135604…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format