main
1// Abbreviated commit ids on read requests. A full object walk is not cheap, so a short oid resolves
2// only against refs the server already advertised (branch tips, tag tips, peeled tag commits). Anything
3// else is a bad_request that tells the caller to send the full oid.
5import { chainGet } from './absent.ts';
7/** Shortest abbreviation this API will try. Shorter hex stays a ref name. */
8export const MIN_ABBREV_HEX = 7;
9/** SHA-1 object ids. ply reads only sha1 repositories. */
10export const FULL_OID_HEX = 40;
12const ABBREV_OID = new RegExp(`^[0-9a-f]{${MIN_ABBREV_HEX},${FULL_OID_HEX - 1}}$`);
13const FULL_OID = new RegExp(`^[0-9a-f]{${FULL_OID_HEX}}$`);
15/** Prefixes that name the refs a cheap disambiguation may see. One ls-refs, no object walk. */
16export const ADVERTISED_REF_PREFIXES = ['HEAD', 'refs/heads/', 'refs/tags/'] as const;
18/** A ref the server already advertised. A peeled commit, when the record has one, is read at the boundary. */
19export type AdvertisedRef = { readonly oid: string };
21export type AbbrevMatch =
22 | { kind: 'unique'; oid: string }
23 | { kind: 'none' | 'ambiguous'; message: string };
25export function isAbbreviatedOid(ref: string): boolean {
26 return ABBREV_OID.test(ref);
27}
29export function isFullOid(ref: string): boolean {
30 return FULL_OID.test(ref);
31}
33function fullOidRequired(prefix: string, why: string): string {
34 return `abbreviated oid ${prefix} ${why}; pass a full ${FULL_OID_HEX}-hex oid`;
35}
37/** Unique advertised oid (the ref oid or its peeled commit) for `prefix`, or a bad_request message. */
38export function matchAbbreviatedOid(prefix: string, refs: Iterable<readonly [string, AdvertisedRef]>): AbbrevMatch {
39 const hits = new Set<string>();
40 for (const [, rec] of refs) {
41 const oid = rec.oid.toLowerCase();
42 if (oid.startsWith(prefix)) hits.add(oid);
43 const peeled = chainGet(rec, 'peeled');
44 if (peeled.tag === 'some' && typeof peeled.value === 'string' && peeled.value.length > 0) {
45 const lower = peeled.value.toLowerCase();
46 if (lower.startsWith(prefix)) hits.add(lower);
47 }
48 }
49 if (hits.size === 1) {
50 const oid = hits.values().next().value;
51 if (oid) return { kind: 'unique', oid };
52 }
53 if (hits.size > 1) return { kind: 'ambiguous', message: fullOidRequired(prefix, `matches ${hits.size} advertised commits`) };
54 return { kind: 'none', message: fullOidRequired(prefix, 'matches no advertised ref') };
55}
Diagnostics4 git calls · 467 ms
CallStatusSizeTime0467 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 B2 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=UPDATING 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 1020040 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=41349 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=526b305930b8ef382f2d7a1f9c0238730a585921 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=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2001.1 KiB463 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=463 git.response.bytes=1116 git.response.cache=MISS git.response.duration_ms=463 git.fetch.wants=93f0573fa42b1378313a3ab9d0b43ab7e113f0d6 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=1116 git.pkt.payload.max=1095 git.sideband.band1.bytes=1094 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-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e30e559a6d8a31
- Request
- f10c0690…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format