GitHubivarvong
ply
main
1// The tree-entry name checks ply had before #207 made them allocation-free (src/validate.ts at c91c9cf, isHfsDot,
2// isNtfsDotGit, isNtfsDot, isDotGitName, isDotFileName, verbatim but for the imports): kept in test/ as the oracle.
3// test/dotnames.test.js and test/fuzz/dotnames.mjs hold src/validate.ts to it byte string by byte string, so a change
4// to the src side cannot pass by changing both sides of the comparison. No test holds this file to git (it was, on
5// c91c9cf, when it was src): agreement with it is refactor equivalence only. git judges src/validate.ts itself in
6// test/space/fsck-tree.test.js (an enumerated space) and in test/fuzz/dotnames.mjs --stage git (git fsck --strict).
7import { te } from '../../src/bytes.js';
8import { atOr } from '../../src/absent.js';
10const at = (b: Uint8Array, i: number): number => atOr(b, i, 0);
11const lower = (c: number): number => (c >= 0x41 && c <= 0x5a ? c + 0x20 : c);
12const ascii = (s: string): Uint8Array => te.encode(s);
14type Utf8Char = readonly [codePoint: number, length: number];
15const cont = (c: number): boolean => (c & 0xc0) === 0x80;
16export function utf8AtRef(b: Uint8Array, i: number): Utf8Char | null {
17 const s0 = at(b, i), s1 = at(b, i + 1), s2 = at(b, i + 2), s3 = at(b, i + 3);
18 if (s0 < 0x80) return [s0, 1];
19 if ((s0 & 0xe0) === 0xc0) return !cont(s1) || (s0 & 0xfe) === 0xc0 ? null : [((s0 & 0x1f) << 6) | (s1 & 0x3f), 2];
20 if ((s0 & 0xf0) === 0xe0) {
21 if (!cont(s1) || !cont(s2) || (s0 === 0xe0 && (s1 & 0xe0) === 0x80) || (s0 === 0xed && (s1 & 0xe0) === 0xa0) || (s0 === 0xef && s1 === 0xbf && (s2 & 0xfe) === 0xbe)) return null;
22 return [((s0 & 0x0f) << 12) | ((s1 & 0x3f) << 6) | (s2 & 0x3f), 3];
23 }
24 if ((s0 & 0xf8) === 0xf0) {
25 if (!cont(s1) || !cont(s2) || !cont(s3) || (s0 === 0xf0 && (s1 & 0xf0) === 0x80) || (s0 === 0xf4 && s1 > 0x8f) || s0 > 0xf4) return null;
26 return [((s0 & 0x07) << 18) | ((s1 & 0x3f) << 12) | ((s2 & 0x3f) << 6) | (s3 & 0x3f), 4];
27 }
28 return null;
29}
30const HFS_IGNORED = new Set([0x20_0c, 0x20_0d, 0x20_0e, 0x20_0f, 0x20_2a, 0x20_2b, 0x20_2c, 0x20_2d, 0x20_2e, 0x20_6a, 0x20_6b, 0x20_6c, 0x20_6d, 0x20_6e, 0x20_6f, 0xfe_ff]);
31export function isHfsDotRef(b: Uint8Array, needle: string): boolean {
32 let i = 0;
33 const next = (): number => {
34 for (;;) {
35 if (i < 0) return 0;
36 const r = utf8AtRef(b, i);
37 if (r === null) { i = -1; return 0; }
38 i += r[1];
39 if (!HFS_IGNORED.has(r[0])) return r[0];
40 }
41 };
42 if (next() !== 0x2e) return false;
43 for (const n of ascii(needle)) { const c = next(); if (c > 127 || lower(c) !== n) return false; }
44 const c = next();
45 return c === 0 || c === 0x2f;
46}
47export function isNtfsDotGitRef(b: Uint8Array, o: number): boolean {
48 let i = o;
49 const c0 = at(b, i++);
50 if (c0 !== 0x2e && lower(c0) !== 0x67) return false;
51 const want = c0 === 0x2e ? 'git' : 'it~1';
52 for (const [k, n] of ascii(want).entries()) { const c = at(b, i++); if ((k < 2 || c0 === 0x2e ? lower(c) : c) !== n) return false; }
53 for (;;) {
54 const c = at(b, i++);
55 if (c === 0 || c === 0x2f || c === 0x5c || c === 0x3a) return true;
56 if (c !== 0x2e && c !== 0x20) return false;
57 }
58}
59export function isNtfsDotRef(b: Uint8Array, o: number, name: string, prefix: string): boolean {
60 const c = (k: number): number => at(b, o + k), n = ascii(name), p = ascii(prefix);
61 const rest = (from: number): boolean => { for (let i = from; ; i++) { const x = c(i); if (x === 0 || x === 0x3a) return true; if (x !== 0x20 && x !== 0x2e) return false; } };
62 if (c(0) === 0x2e && n.every((x, k) => lower(c(k + 1)) === x)) return rest(n.length + 1);
63 if (n.slice(0, 6).every((x, k) => lower(c(k)) === x) && c(6) === 0x7e && c(7) >= 0x31 && c(7) <= 0x34) return rest(8);
64 let sawTilde = false;
65 for (let i = 0; i < 8; i++) {
66 const x = c(i);
67 if (x === 0) return false;
68 if (sawTilde) { if (x < 0x30 || x > 0x39) return false; }
69 else if (x === 0x7e) { const d = c(++i); if (d < 0x31 || d > 0x39) return false; sawTilde = true; }
70 else if (i >= 6 || x & 0x80 || lower(x) !== p[i]) return false;
71 }
72 return rest(8);
73}
74export type DotFile = 'gitmodules' | 'gitignore' | 'gitattributes' | 'mailmap';
75export const DOTFILES: Readonly<Record<DotFile, readonly [name: string, prefix: string]>> = {
76 gitmodules: ['gitmodules', 'gi7eba'], gitignore: ['gitignore', 'gi250a'], gitattributes: ['gitattributes', 'gi7d29'], mailmap: ['mailmap', 'maba30'],
77};
78const backslashTails = (b: Uint8Array): number[] => { const out: number[] = []; for (let i = 0; i < b.length; i++) if (b[i] === 0x5c) out.push(i + 1); return out; };
80export const isDotGitNameRef = (b: Uint8Array): boolean => isHfsDotRef(b, 'git') || isNtfsDotGitRef(b, 0) || backslashTails(b).some(o => isNtfsDotGitRef(b, o));
81export const isDotFileNameRef = (b: Uint8Array, file: DotFile): boolean => {
82 const [name, prefix] = DOTFILES[file];
83 return isHfsDotRef(b, name) || isNtfsDotRef(b, 0, name, prefix) || (file === 'gitmodules' && backslashTails(b).some(o => isNtfsDotRef(b, o, name, prefix)));
84};
Diagnostics7 git calls · 177 ms
CallStatusSizeTime0177 ms
discover200191 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=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 KiB75 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=75 git.response.bytes=11990 git.response.cache=EXPIRED git.response.duration_ms=75 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=2 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=10Open 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=3 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=5323b9266eea5ded637285d1c5320699f12be76eOpen 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=be7e0453974a5fe832f9065a33bb7e3434c10e9bOpen pack map
fetchtree:0200206 B · 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=206 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=79746bc0bc9f5b3555b6da67e6b1d6b7cb99951f 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=206 git.pkt.payload.max=179 git.sideband.band1.bytes=179 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=179 git.pack.trailer=3c6a6357503904c9fad32605f187878604ad7c03Open pack map
fetch2001.9 KiB91 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=91 git.response.bytes=1912 git.response.cache=MISS git.response.duration_ms=91 git.fetch.wants=1b2df078cdcbcc0a0756f425b196a0c8ca741bb3 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=1912 git.pkt.payload.max=1885 git.sideband.band1.bytes=1885 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
- a5e2d1ebcd9acf3a
- Request
- 9d4406ae…
- 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