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}
Diagnostics4 git calls · 316 ms
CallStatusSizeTime0316 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 B5 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=UPDATING 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
fetch2001.7 KiB309 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=309 git.response.bytes=1776 git.response.cache=MISS git.response.duration_ms=309 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=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1776 git.pkt.payload.max=1755 git.sideband.band1.bytes=1754 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
- a5e269a5be4ff4e0
- Request
- 84d958d7…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format