main
ply4 git calls27 ms42 KiB3 cachedprotocol v2
89 lines3.7 KiBRaw
1// Which part of a viewer URL failed, and the sentence the error page leads with.
2import { captureGroup } from '../absent.ts'
3import { unwrapOr } from '../option.ts'
4import { repoIdentity } from './identity.ts'
6export type FailurePart = 'repo' | 'ref' | 'path' | 'request';
8export type FailureView = {
9 /** HTTP status the page and the response use. GitHub's 401 for a missing repo is shown as 404. */
10 status: number;
11 part: FailurePart;
12 summary: string;
13};
15const NOT_FOUND = 404;
16const UNAUTHORIZED = 401;
18export function repoLabel(host: string, repoPath: string): string {
19 const id = repoIdentity(host, repoPath);
20 return id.scope ? `${id.scope}/${id.name}` : id.name;
23function captured(match: RegExpExecArray | null): string {
24 return unwrapOr(captureGroup(match, 1), '');
27function refNamed(message: string, ref: string | null): string {
28 const missing = captured(/^ref (.+) not found/.exec(message));
29 if (missing !== '') return missing;
30 const abbrev = captured(/^abbreviated oid ([0-9a-f]+)/.exec(message));
31 if (abbrev !== '') return abbrev;
32 if (ref && ref.length > 0) return ref;
33 return 'HEAD';
36function pathNamed(message: string, path: string): string {
37 if (path) return path;
38 const component = captured(/path component (\S+) not found/.exec(message));
39 if (component !== '') return component;
40 const directory = captured(/^(\S+) is not a directory/.exec(message));
41 if (directory !== '') return directory;
42 return 'that path';
45function failurePart(code: string, message: string, ref: string | null, path: string, missingOrPrivate: boolean): FailurePart {
46 if (missingOrPrivate) return 'repo';
47 if (/^ref .+ not found/.test(message) || /^abbreviated oid /.test(message) || /remote HEAD is unborn/.test(message)) return 'ref';
48 if (/path component \S+ not found/.test(message) || / is not a directory/.test(message) || / is not a directory \(mode /.test(message)) return 'path';
49 if (/no repository |not a repository|not a git|advertisement/.test(message)) return 'repo';
50 if (code === 'not_found' && path) return 'path';
51 if (code === 'not_found' && ref) return 'ref';
52 if (code === 'not_found') return 'repo';
53 return 'request';
56/** "no repository x …" → "No repository x …", like every other headline. */
57function sentenceCase(message: string): string {
58 return message.charAt(0).toUpperCase() + message.slice(1);
61function inRepo(label: string): string {
62 return label ? ` in ${label}` : '';
65/**
66 * GitHub answers 401 for a missing repository and a private one. The page says which, keeps that
67 * explanation, and uses 404 so a client does not treat "no such public repo" as an auth challenge.
68 */
69export function describeFailure(input: {
70 code: string;
71 status: number;
72 message: string;
73 host: string;
74 repoPath: string;
75 ref: string | null;
76 path: string;
77}): FailureView {
78 const missingOrPrivate = input.code === 'auth' && input.status === UNAUTHORIZED;
79 const status = missingOrPrivate ? NOT_FOUND : input.status;
80 const part = failurePart(input.code, input.message, input.ref, input.path, missingOrPrivate);
81 const label = input.host && input.repoPath ? repoLabel(input.host, input.repoPath) : '';
82 let summary = input.message;
83 if (part === 'repo' && missingOrPrivate) summary = label ? `Repository ${label} not found, or private` : 'Repository not found, or private';
84 else if (part === 'repo' && /no repository (\S+)/.exec(input.message)) summary = sentenceCase(input.message);
85 else if (part === 'ref') summary = `No ref ${refNamed(input.message, input.ref)}${inRepo(label)}`;
86 else if (part === 'path') summary = `No path ${pathNamed(input.message, input.path)}${inRepo(label)}`;
87 else if (part === 'repo' && label) summary = `Repository ${label} not found`;
88 return { status, part, summary };
Diagnostics4 git calls · 27 ms
CallStatusSizeTime027 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 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 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=61
Open pack map
fetch2001.3 KiB · hit22 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=22
git.response.bytes=1380
git.response.cache=HIT
git.response.duration_ms=22
git.fetch.wants=834f847e8ace32a09e045d10ede42e45e90251ee
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=1380
git.pkt.payload.max=1359
git.sideband.band1.bytes=1358
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
a5e306fe0f4b15db
Request
aab8e00c…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format