Artifactspublic-v0

ply

main
ply4 git calls248 ms41 KiB2 cachedprotocol v2
122 lines8.1 KiBRaw
1// Cherry-pick of a rename, decided by git (#103 item 3). The picked commit P renames old.txt → new.txt, edits line 5 of
2// it and line 2 of a.txt (optionally making new.txt executable). The target branch made its own changes from the same
3// base; every cell of the product
4//
5// R what the target did to old.txt same (→ new.txt) | other (→ other.txt) | delete | keep
6// | same+copy (same, and adds copy.txt = old.txt's base bytes: git can pair old → copy)
7// | same+drop (same, and deletes x.txt = P's new.txt bytes: git can pair x → new)
8// C its content on the target same (P's edits) | none (untouched) | different (line 8) | further (line 5 past P's)
9// M the executable bit none | both (P and the target chmod +x) | ours (the target only)
10//
11// is cherry-picked with `git cherry-pick` in a clone and with pickCommit against the same bare repository. git's
12// outcome class (clean with a tree, empty, conflict) is the expectation; ply may conflict where git is clean only with a
13// rename-guard reason (its documented superset: ply does not detect renames), never the other way, and every clean pick
14// must be git's tree.
15import { test, beforeAll as before, afterAll as after } from 'vitest';
16import assert from 'node:assert/strict';
17import { join } from 'node:path';
18import { mkdirSync, writeFileSync, rmSync, mkdtempSync, chmodSync, renameSync } from 'node:fs';
19import { spawnSync } from 'node:child_process';
20import { tmpdir } from 'node:os';
21import { git, tmpRoot, makeBareRepo, startGitServer, initRepo } from './server.js';
22import { oracleRediff } from './gitversion.js';
23import { cherryPick } from '../src/rebase.js';
24import { Tracer } from '../src/otel.js';
25import { unwrapAsync } from './unwrap.js';
27const rediff = oracleRediff();
28const ENV = { ...process.env, GIT_AUTHOR_NAME: 'w', GIT_AUTHOR_EMAIL: 'w@x', GIT_COMMITTER_NAME: 'w', GIT_COMMITTER_EMAIL: 'w@x', GIT_AUTHOR_DATE: '1700000000 +0000', GIT_COMMITTER_DATE: '1700000000 +0000', GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'commit.gpgsign', GIT_CONFIG_VALUE_0: 'false' };
29const sh = (cwd, args) => spawnSync('git', ['-C', cwd, ...args], { encoding: 'utf8', env: ENV });
30const ok = (cwd, args) => { const r = sh(cwd, args); assert.equal(r.status, 0, `git ${args.join(' ')}: ${r.stderr}`); return r.stdout.trim(); };
32export const R = ['same', 'other', 'delete', 'keep', 'same+copy', 'same+drop'];
33export const C = ['same', 'none', 'different', 'further'];
34export const M = ['none', 'both', 'ours'];
36const lines = (p, edits = {}) => Array.from({ length: 10 }, (_, i) => `${edits[i + 1] ?? `${p}${i + 1}`}\n`).join('');
37const OLD = lines('o');
38const A = lines('a');
40let root, cleanup, srv, n = 0;
41before(async () => { ({ root, cleanup } = tmpRoot()); srv = await startGitServer(root); });
42after(async () => { await srv?.close(); cleanup?.(); });
44// One cell's repository: base, the picked commit P on `src`, the target on `dst`. Returns the bare repo and P.
45function build(r, c, m) {
46 const name = `cp${n++}`; const bare = makeBareRepo(root, name); const w = join(root, `w${name}`); mkdirSync(w);
47 initRepo(w);
48 const put = (p, v) => writeFileSync(join(w, p), v);
49 const commit = msg => { ok(w, ['add', '-A']); ok(w, ['commit', '-q', '--allow-empty', '-m', msg]); return ok(w, ['rev-parse', 'HEAD']); };
50 put('a.txt', A); put('old.txt', OLD); put('x.txt', lines('o', { 5: 'P5' })); const base = commit('base');
51 // P: rename + edit line 5, a.txt line 2, optionally +x
52 ok(w, ['checkout', '-q', '-b', 'src', base]);
53 renameSync(join(w, 'old.txt'), join(w, 'new.txt')); put('new.txt', lines('o', { 5: 'P5' })); put('a.txt', lines('a', { 2: 'A2' }));
54 if (m === 'both') chmodSync(join(w, 'new.txt'), 0o755);
55 const p = commit('P');
56 // the target
57 ok(w, ['checkout', '-q', '-b', 'dst', base]);
58 const to = { same: 'new.txt', other: 'other.txt', delete: null, keep: 'old.txt', 'same+copy': 'new.txt', 'same+drop': 'new.txt' }[r];
59 if (r === 'same+copy') put('copy.txt', OLD);
60 if (r === 'same+drop') rmSync(join(w, 'x.txt'));
61 if (to !== 'old.txt') rmSync(join(w, 'old.txt'));
62 const content = { same: lines('o', { 5: 'P5' }), none: OLD, different: lines('o', { 8: 'O8' }), further: lines('o', { 5: 'P5' }) }[c];
63 if (to) { put(to, content); if (m !== 'none') chmodSync(join(w, to), 0o755); }
64 if (c !== 'none') put('a.txt', lines('a', { 2: 'A2' }));
65 commit('target');
66 if (c === 'further' && to) { put(to, lines('o', { 5: 'Q5' })); commit('target further'); }
67 ok(w, ['push', '-q', bare, 'refs/heads/src', 'refs/heads/dst']);
68 rmSync(w, { recursive: true, force: true });
69 return { name, bare, p };
72// git's answer: clean (tree), empty, or conflict
73function gitPick(bare, p) {
74 const d = mkdtempSync(join(tmpdir(), 'cp-'));
75 try {
76 ok(d, ['clone', '-q', '-b', 'dst', bare, '.']);
77 const before = ok(d, ['rev-parse', 'HEAD']);
78 const r = sh(d, ['cherry-pick', p]);
79 const said = r.stdout + r.stderr;
80 if (r.status === 0) { const head = ok(d, ['rev-parse', 'HEAD']); return head === before ? { cls: 'empty' } : { cls: 'clean', tree: ok(d, ['rev-parse', 'HEAD^{tree}']) }; }
81 if (/is now empty|nothing to commit/u.test(said)) return { cls: 'empty' };
82 return { cls: 'conflict', said: said.split('\n').filter(l => l.startsWith('CONFLICT')).join('; ') };
83 } finally { rmSync(d, { recursive: true, force: true }); }
86async function plyPick(url, p) {
87 try {
88 const res = await unwrapAsync(cherryPick(url, { ref: 'refs/heads/dst', commit: p, committer: { name: 'w', email: 'w@x' }, time: 1700000000 }, { tracer: new Tracer(), rediff }));
89 return res.outcome === 'empty' ? { cls: 'empty' } : { cls: 'clean', tree: res.tree };
90 } catch (e) {
91 if (e.code !== 'merge_conflict') throw e;
92 return { cls: 'conflict', reasons: Object.values(e.reasons ?? {}) };
93 }
96const GUARD = /^possible (rename|directory rename)/u;
97// Where git and ply part, by name and why. The target made the rename executable and P did not: git follows the rename on
98// both sides, merges the modes (one side changed it) and the pick is empty; rename-blind, the two sides add new.txt with
99// different modes, an add/add ply cannot resolve without rename detection.
100export const KNOWN = { 'same/same/ours': 'git empty, ply conflict: add/add of new.txt with different modes (rename-blind)' };
101test('cherry-pick of a rename: R × C × M, each cell against git cherry-pick', { timeout: 10 * 60_000 }, async () => {
102 const tally = new Map(); const bad = []; const superset = []; const known = [];
103 for (const r of R) for (const c of C) for (const m of M) {
104 const cell = `${r}/${c}/${m}`;
105 const { name, bare, p } = build(r, c, m);
106 const g = gitPick(bare, p);
107 const y = await plyPick(`${srv.url}/${name}.git`, p);
108 const key = `git ${g.cls} / ply ${y.cls}`; tally.set(key, (tally.get(key) ?? 0) + 1);
109 if (g.cls === y.cls) { if (g.cls === 'clean' && g.tree !== y.tree) bad.push(`${cell}: tree ${y.tree} != git ${g.tree}`); continue; }
110 // ply's documented superset (merge.ts): a conflict git does not have, because ply does not detect renames — the
111 // rename guard, or the modify/delete a rename-blind merge sees. Recorded with its reasons; never an empty pick.
112 if (g.cls === 'clean' && y.cls === 'conflict' && y.reasons.length > 0) { superset.push(`${cell} (${[...new Set(y.reasons.map(x => (GUARD.test(x) ? 'guard' : x)))].join(', ')})`); continue; }
113 if (KNOWN[cell] && g.cls === 'empty' && y.cls === 'conflict') { known.push(cell); continue; }
114 bad.push(`${cell}: git ${g.cls}${g.said ? ` (${g.said})` : ''}, ply ${y.cls}${y.reasons ? ` (${[...new Set(y.reasons)].join('; ')})` : ''}`);
115 }
116 console.log(`# cherry-pick rename space: ${R.length * C.length * M.length} cells`);
117 console.log([...tally].sort().map(([k, v]) => `# ${String(v).padStart(3)} ${k}`).join('\n'));
118 console.log(`# ply's superset (git clean, ply conflict), ${superset.length}: ${superset.join('; ') || 'none'}`);
119 console.log(`# known disagreements: ${known.map(k => `${k} (${KNOWN[k]})`).join('; ') || 'none'}`);
120 assert.deepEqual(bad, []);
121 assert.deepEqual(known, Object.keys(KNOWN), 'every known disagreement still happens (else drop it from KNOWN)');
122});
Diagnostics4 git calls · 248 ms
CallStatusSizeTime0248 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
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 · hit6 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=238
git.response.bytes=38434
git.response.cache=HIT
git.response.duration_ms=6
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=55
Open pack map
fetch2003.3 KiB239 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3393
git.response.cache=MISS
git.response.duration_ms=239
git.fetch.wants=44e51ac6ee95ef8681717f849ddae466f2fbe9ba
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=3393
git.pkt.payload.max=3372
git.sideband.band1.bytes=3371
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
a5e308a12d1e15db
Request
71b44f1f…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format