GitHubivarvong
ply
main
1// A seeded generator of three-way cases around renames: base / ours / theirs as { path: content }. ply does not detect
2// renames, so every shape here is one where git's rename detection may or may not change the merge; its caller
3// (test/merge-renames.test.js) holds ply to `git merge-tree --write-tree`.
4//
5// Operations, applied to a side or to both ("shared": the changed subtree is then the same tree on both sides):
6// move a file to another directory, same bytes
7// move+edit the same, a few lines changed (similar enough for git to pair)
8// delete a file
9// edit a file in place
10// add an unrelated new file
11// file→dir a file replaced by a directory of its name holding its bytes (or unrelated bytes)
12// dir→file a directory replaced by a file of its name holding one of its files' bytes (or unrelated bytes)
13// dir-rename every file of a directory moved to a new directory
14// No node: imports: the generator is pure.
16// mulberry32
17const rng = seed => { let a = seed >>> 0; return () => { a = (a + 0x6D2B79F5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; };
19const text = (tag, n = 24) => `${Array.from({ length: n }, (_, i) => `${tag} line ${i}`).join('\n')}\n`;
20// a few lines changed: git pairs it with the original (well over 50% similar)
21const edited = (s, k) => s.split('\n').map((l, i) => (i % 6 === k % 6 && l !== '' ? `${l} edited${k}` : l)).join('\n');
22const DIRS = ['', 'a/', 'b/', 'a/s/', 'c/'];
24// a tree cannot hold a file and a directory of one name
25const valid = files => { const paths = Object.keys(files); const dirs = new Set(); for (const p of paths) { const parts = p.split('/'); for (let i = 1; i < parts.length; i++) dirs.add(parts.slice(0, i).join('/')); } return paths.every(p => !dirs.has(p)); };
27export function generateCase(seed, index) {
28 const r = rng(seed * 1_000_003 + index);
29 const int = n => Math.floor(r() * n);
30 const pick = l => l[int(l.length)];
31 let fresh = 0;
32 const base = {};
33 const count = 3 + int(4);
34 for (let i = 0; i < count; i++) base[`${pick(DIRS)}f${i}`] = text(`base${i}`);
35 base.keep = 'keep\n';
36 const ops = [];
37 // one operation on `files` (a copy is returned; an operation that would make an invalid tree is skipped)
38 const apply = (files, who) => {
39 const paths = Object.keys(files).filter(p => p !== 'keep');
40 if (paths.length === 0) return files;
41 const p = pick(paths); const out = { ...files }; const kind = int(9); const id = fresh++;
42 const leaf = p.slice(p.lastIndexOf('/') + 1); const dir = p.slice(0, p.length - leaf.length);
43 let what = '';
44 if (kind === 0) { const to = `${pick(DIRS.filter(d => d !== dir))}${leaf}`; delete out[p]; out[to] = files[p]; what = `move ${p}→${to}`; }
45 else if (kind === 1) { const to = `${pick(DIRS.filter(d => d !== dir))}m${id}`; delete out[p]; out[to] = edited(files[p], id); what = `move+edit ${p}→${to}`; }
46 else if (kind === 2) { delete out[p]; what = `delete ${p}`; }
47 else if (kind === 3) { out[p] = edited(files[p], id); what = `edit ${p}`; }
48 else if (kind === 4) { const to = `${pick(DIRS)}n${id}`; out[to] = text(`new${id}`); what = `add ${to}`; }
49 else if (kind === 5) { delete out[p]; out[`${p}/x${int(2)}`] = int(4) === 0 ? text(`new${id}`) : files[p]; what = `file→dir ${p}`; }
50 else if (kind === 6 && dir !== '') { const d = dir.slice(0, -1); for (const q of Object.keys(out)) if (q.startsWith(dir)) delete out[q]; out[d] = int(4) === 0 ? text(`new${id}`) : files[p]; what = `dir→file ${d}`; }
51 else if (kind === 7 && dir !== '') { const to = `r${int(2)}/`; for (const q of Object.keys(files)) if (q.startsWith(dir)) { delete out[q]; out[to + q.slice(dir.length)] = files[q]; } what = `dir-rename ${dir}→${to}`; }
52 else { delete out[p]; what = `delete ${p}`; }
53 if (!valid(out)) return files;
54 ops.push(`${who}: ${what}`);
55 return out;
56 };
57 // shared operations first: both sides hold the same change, so the subtree is the same tree on both sides
58 let shared = base;
59 for (let n = int(3); n > 0; n--) shared = apply(shared, 'both');
60 let ours = shared; let theirs = shared;
61 for (let n = int(3); n > 0; n--) ours = apply(ours, 'ours');
62 for (let n = 1 + int(2); n > 0; n--) theirs = apply(theirs, 'theirs');
63 return { base, ours, theirs, ops };
64}
Diagnostics7 git calls · 142 ms
CallStatusSizeTime0142 ms
discover200191 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 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 · 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=4347 git.response.cache=HIT git.response.duration_ms=4 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=125 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.8 KiB125 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1838 git.response.cache=MISS git.response.duration_ms=125 git.fetch.wants=2045bd490c6da4f89ca6a7dc69d8bc49c7c507f8 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=1838 git.pkt.payload.max=1811 git.sideband.band1.bytes=1811 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
- a5e2b9a00f72cf33
- Request
- fdc11d66…
- 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