GitHubivarvong
ply
main
1// git's own verdict on tree-entry names, for test/fuzz/dotnames.mjs. ply is not asked anything here.
2// Each name becomes a one-entry tree `120000 <name>\0<oid of the empty blob>`, written as a loose object (node:crypto
3// SHA-1, node:zlib deflate) into a fresh bare repository, and one `git fsck --strict --no-dangling` judges them all.
4// A symlink entry makes fsck_tree (git fsck.c) name every check a name can trip, each from git's own is_hfs_* / is_ntfs_*:
5// hasDotgit name is .git, or is_hfs_dotgit / is_ntfs_dotgit says so (any backslash-separated component too)
6// gitmodulesSymlink is_hfs_dotgitmodules || is_ntfs_dotgitmodules (any backslash-separated component too)
7// gitignoreSymlink is_hfs_dotgitignore || is_ntfs_dotgitignore
8// gitattributesSymlink is_hfs_dotgitattributes || is_ntfs_dotgitattributes
9// mailmapSymlink is_hfs_dotmailmap || is_ntfs_dotmailmap
10// The verdict is those five as a 0/1 string, the order of dotnames-corpus.js's verdicts(). A name git cannot hold as
11// one tree entry (empty, or with a NUL: the name ends at the first NUL) is not judged: its verdict is null.
12import { spawnSync } from 'node:child_process';
13import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
14import { tmpdir } from 'node:os';
15import { join } from 'node:path';
16import { createHash } from 'node:crypto';
17import { deflateSync } from 'node:zlib';
19export const MSG_IDS = ['hasDotgit', 'gitmodulesSymlink', 'gitignoreSymlink', 'gitattributesSymlink', 'mailmapSymlink'];
20const ENV = { PATH: process.env.PATH, HOME: tmpdir(), GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null', LC_ALL: 'C' };
22function writeLoose(dir, type, body) {
23 const raw = Buffer.concat([Buffer.from(`${type} ${body.length}\0`), body]);
24 const oid = createHash('sha1').update(raw).digest('hex');
25 const d = join(dir, 'objects', oid.slice(0, 2));
26 mkdirSync(d, { recursive: true });
27 writeFileSync(join(d, oid.slice(2)), deflateSync(raw, { level: 1 }));
28 return oid;
29}
31// names: Uint8Array[] → (string | null)[], one verdict per name in order
32export function gitNameVerdicts(names) {
33 const dir = mkdtempSync(join(tmpdir(), 'ply-git-names-'));
34 try {
35 const init = spawnSync('git', ['init', '-q', '--bare', dir], { env: ENV, encoding: 'utf8' });
36 if (init.status !== 0) throw new Error(`git init failed: ${init.stderr}`);
37 const blob = Buffer.from(writeLoose(dir, 'blob', Buffer.alloc(0)), 'hex');
38 const oids = names.map(b => (b.length === 0 || b.includes(0) ? null : writeLoose(dir, 'tree', Buffer.concat([Buffer.from('120000 '), Buffer.from(b), Buffer.of(0), blob]))));
39 const r = spawnSync('git', ['fsck', '--strict', '--no-dangling'], { cwd: dir, env: ENV, encoding: 'latin1', maxBuffer: 1 << 30 });
40 if (r.status === null || r.error) throw new Error(`git fsck did not finish: ${r.error ?? r.signal}`);
41 const found = new Map();
42 for (const line of `${r.stdout}\n${r.stderr}`.split('\n')) {
43 const m = /^(?:error|warning) in tree ([0-9a-f]{40}): (\w+):/.exec(line);
44 if (!m) continue;
45 let s = found.get(m[1]);
46 if (!s) found.set(m[1], s = new Set());
47 s.add(m[2]);
48 }
49 // every tree written is one git sees: `git count-objects` counts the loose objects fsck walked
50 const count = spawnSync('git', ['count-objects'], { cwd: dir, env: ENV, encoding: 'utf8' });
51 const loose = Number(/^(\d+) objects/.exec(count.stdout)?.[1]);
52 const want = new Set(oids.filter(o => o !== null)).size + 1;
53 if (loose !== want) throw new Error(`git counts ${loose} loose objects, ${want} written`);
54 return oids.map(o => (o === null ? null : MSG_IDS.map(id => +(found.get(o)?.has(id) ?? false)).join('')));
55 } finally {
56 rmSync(dir, { recursive: true, force: true });
57 }
58}
Diagnostics7 git calls · 210 ms
CallStatusSizeTime0210 ms
discover200191 B4 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 KiB3 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=11990 git.response.cache=UPDATING git.response.duration_ms=3 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=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=4 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 · hit4 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=4 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:0200853 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=194 git.response.bytes=853 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=fb781d4e4fd58ededa1f1078d937de6f4b1316a2 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=853 git.pkt.payload.max=826 git.sideband.band1.bytes=826 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=826 git.pack.trailer=c89bc485f6ad08d875fc515f3fdd69897096847bOpen pack map
fetch2001.7 KiB194 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1779 git.response.cache=MISS git.response.duration_ms=194 git.fetch.wants=a2da7617934cf7864e6bc5fb54947580798368b2 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=1779 git.pkt.payload.max=1752 git.sideband.band1.bytes=1752 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
- a5e14a753a12a140
- Request
- 348b72b6…
- 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