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}
Diagnostics4 git calls · 176 ms
CallStatusSizeTime0176 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 1020038 KiB · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 git.response.bytes=38434 git.response.cache=HIT git.response.duration_ms=1 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.8 KiB172 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=171 git.response.bytes=1831 git.response.cache=MISS git.response.duration_ms=172 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=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1831 git.pkt.payload.max=1810 git.sideband.band1.bytes=1809 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
- a5e2d274fc02cf3a
- Request
- e5148d5e…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format