Artifactspublic-v0

ply

main
ply4 git calls29 ms40 KiB3 cachedprotocol v2
102 lines4.3 KiBRaw
1// The merge-base cap (#143). Every cell is a relation, a length, and a cap. When the search window reaches the
2// answer, ply's bases equal `git merge-base --all` and the depth is the first window that reaches it. When the
3// window is still truncated, the error names the attempted depth and the cap separately.
4import { test, beforeAll as before, afterAll as after } from 'vitest';
5import assert from 'node:assert/strict';
6import { execFileSync } from 'node:child_process';
7import { tmpRoot, makeBareRepo, startGitServer } from '../server.js';
8import { createTransport as createTransportR } from '../../src/http.js';
9import { mergeBase } from '../../src/merge.js';
10import { Tracer } from '../../src/otel.js';
11import { cells, expectCap } from './merge-depth.space.js';
12import { unwrapAsync } from '../unwrap.js';
14import { unwrap } from '../unwrap.js';
15// Throwing adapters over the Result API (0.2.0): the assertions below are about the throw.
16const createTransport = (...a) => unwrap(createTransportR(...a));
17const ENV = {
18 ...Object.fromEntries(Object.entries(process.env).filter(([k]) => !k.startsWith('GIT_'))),
19 GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null',
20 GIT_AUTHOR_NAME: 'a', GIT_AUTHOR_EMAIL: 'a@x', GIT_COMMITTER_NAME: 'a', GIT_COMMITTER_EMAIL: 'a@x',
21 GIT_AUTHOR_DATE: '1700000000 +0000', GIT_COMMITTER_DATE: '1700000000 +0000',
22};
24let root, cleanup, srv, bare;
25before(async () => { ({ root, cleanup } = tmpRoot()); srv = await startGitServer(root); bare = makeBareRepo(root, 'd'); });
26after(async () => { await srv.close(); cleanup(); });
28const git = (args, input) => execFileSync('git', ['-C', bare, ...args], { env: ENV, input, encoding: 'utf8' });
29const line = (args, input) => git(args, input).trim();
31function chain(n, parent, marker) {
32 const oids = [];
33 let p = parent;
34 for (let i = 1; i <= n; i++) {
35 const args = ['commit-tree', TREE, '-m', `${marker}-${i}`];
36 if (p) args.push('-p', p);
37 p = line(args);
38 oids.push(p);
39 }
40 return oids;
43let TREE;
44function build() {
45 const blob = line(['hash-object', '-w', '--stdin'], 'x\n');
46 TREE = line(['mktree'], `100644 blob ${blob}\tf\n`);
47 const rootOid = chain(1, undefined, 'root')[0];
48 const a = chain(15, rootOid, 'a');
49 const c = chain(15, rootOid, 'c');
50 const u = chain(15, undefined, 'u');
51 const v = chain(15, undefined, 'v');
52 return { rootOid, a, c, u, v };
55function gitBases(a, b) {
56 try {
57 const out = git(['merge-base', '--all', a, b]).trim();
58 return out === '' ? [] : out.split('\n').sort();
59 } catch (e) {
60 if (e.status === 1) return [];
61 throw e;
62 }
65const count = tip => Number(line(['rev-list', '--count', tip]));
67test('merge-base cap: every relation × length × cap against git merge-base --all', async () => {
68 const all = cells();
69 assert.equal(all.length, 3 * 5 * 8);
70 const g = build();
71 const url = `${srv.url}/d.git`;
72 const t = createTransport(url, { tracer: new Tracer() });
73 for (const c of all) {
74 const pair = c.relation === 'fork' ? [g.a[c.length - 1], g.c[c.length - 1]]
75 : c.relation === 'ancestor' ? [g.a[c.length - 1], g.rootOid]
76 : [g.u[c.length - 1], g.v[c.length - 1]];
77 const [a, b] = pair;
78 // fork and ancestor: the base's child is `length` behind the tip (rev-list counts the root too).
79 // unrelated: each root is `length` deep and must itself be fetched.
80 const behind = c.relation === 'unrelated' ? count(a) : count(a) - 1;
81 assert.equal(behind, c.length, `${c.id}: git rev-list`);
82 const want = expectCap(c.cap, behind);
83 const gitAnswer = gitBases(a, b);
84 let result = null;
85 let err = null;
86 try { result = await unwrapAsync(mergeBase(t, a, b, { maxDepth: c.cap })); }
87 catch (e) { err = e; }
88 if (want.tag === 'fit') {
89 assert.equal(err, null, `${c.id}: ${err?.code} ${err?.message}`);
90 assert.equal(result.depth, want.depth, c.id);
91 assert.deepEqual([...result.bases].sort(), gitAnswer, c.id);
92 assert.equal(result.base, gitAnswer.length === 1 ? gitAnswer[0] : null, c.id);
93 } else {
94 assert.equal(err?.code, 'limit_exceeded', `${c.id}: ${err?.code} ${result?.base}`);
95 assert.equal(err.what, 'merge-base search depth', c.id);
96 assert.equal(err.got, want.got, c.id);
97 assert.equal(err.max, want.max, c.id);
98 assert.notEqual(err.got, err.max, `${c.id}: the attempt and the cap are different numbers`);
99 }
100 }
101});
Diagnostics4 git calls · 29 ms
CallStatusSizeTime029 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
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 · 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=55
Open pack map
fetch2001.9 KiB · hit24 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=24
git.response.bytes=1917
git.response.cache=HIT
git.response.duration_ms=24
git.fetch.wants=72d034d34df15943311943e3c0ee2cad938d8bbf
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=1917
git.pkt.payload.max=1896
git.sideband.band1.bytes=1895
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
a5e310fe5b57bdc9
Request
253dd497…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format