GitHubivarvong
ply
main
1// #217: a fetched, resolved pack relayed straight into push (a mirror). fetchPack({ resolve: true }) objects are whole
2// objects; where each sat in the source pack is `packBase`, never `base`, which push reads as its own delta input. Before
3// the rename an OFS_DELTA's `{ tag: 'ofs', offset }` was refused ("an ofs base must name an earlier object") and a
4// REF_DELTA's `{ tag: 'ref', oid }` would have sent a whole object as a delta. git is the oracle: fsck and the refs.
5import { test, beforeAll as before, afterAll as after } from 'vitest';
6import assert from 'node:assert/strict';
7import { join } from 'node:path';
8import { mkdirSync } from 'node:fs';
9import { git, tmpRoot, makeBareRepo, startGitServer, commitFiles, fsckProblems, initRepo } from './server.js';
10import { GitHttp, ZERO_OID } from '../src/client.js';
11import { unwrap, unwrapAsync } from './unwrap.js';
12import { resolvePack, makeDelta } from '../src/packresolve.js';
13import { TYPE } from '../src/objects.js';
15let root, cleanup, srv;
16before(async () => { ({ root, cleanup } = tmpRoot()); srv = await startGitServer(root); });
17after(async () => { await srv.close(); cleanup(); });
19test('fetchPack({ resolve: true }) objects push as they are: ofs and ref deltas in the source pack, git fsck clean', async () => {
20 const src = makeBareRepo(root, 'relay-src');
21 const dst = makeBareRepo(root, 'relay-dst');
22 const work = join(root, 'relay-w');
23 mkdirSync(work);
24 initRepo(work);
25 // many versions of one large-ish file: pack-objects deltas them (OFS_DELTA in a fresh pack)
26 const line = i => `line ${i} ${'x'.repeat(40)}\n`;
27 let body = Array.from({ length: 200 }, (_, i) => line(i)).join('');
28 for (let v = 0; v < 6; v++) { body += line(1000 + v); commitFiles(work, src, { 'big.txt': body, [`f${v}.txt`]: `${v}\n` }, `v${v}`); }
29 git(src, ['repack', '-adf', '-q']);
30 const head = git(src, ['rev-parse', 'main']).trim();
31 const from = unwrap(GitHttp.create(`${srv.url}/relay-src.git`));
32 const to = unwrap(GitHttp.create(`${srv.url}/relay-dst.git`));
33 const fetched = await unwrapAsync(from.fetchPack({ wants: [head], ofsDelta: true, thinPack: false, done: true }, { resolve: true }));
34 const objects = [...fetched.objects.values()];
35 assert.ok(objects.some(o => o.packBase.tag === 'ofs'), 'the source pack carried an OFS_DELTA');
36 assert.ok(objects.every(o => !('base' in o)), 'no resolved object has a `base` push would read');
37 await unwrapAsync(to.push({ commands: [{ ref: 'refs/heads/main', oldOid: ZERO_OID, newOid: head }], objects }));
38 assert.equal(git(dst, ['rev-parse', 'main']).trim(), head);
39 assert.deepEqual(fsckProblems(dst), []);
40 // A REF_DELTA source (a thin pack's object against one the receiver holds): resolved, it is whole and pushes as such.
41 const baseOid = git(src, ['rev-parse', 'main:big.txt']).trim();
42 const baseData = Buffer.from(git(src, ['cat-file', 'blob', baseOid]), 'latin1');
43 const target = Buffer.concat([baseData, Buffer.from('one more line\n')]);
44 const resolved = unwrap(resolvePack({ objects: [{ offset: 12, type: TYPE.REF_DELTA, data: makeDelta(baseData, target).delta, base: { tag: 'ref', oid: baseOid } }] }, oid => (oid === baseOid ? { type: TYPE.BLOB, data: baseData } : null)));
45 const thin = [...resolved.objects.values()];
46 assert.deepEqual(thin.map(o => [o.type, o.packBase]), [[TYPE.BLOB, { tag: 'ref', oid: baseOid }]]);
47 assert.deepEqual(Buffer.from(thin[0].data), target);
48 await unwrapAsync(to.push({ commands: [{ ref: 'refs/tags/grown', oldOid: ZERO_OID, newOid: thin[0].oid }], objects: thin }));
49 assert.deepEqual(Buffer.from(git(dst, ['cat-file', 'blob', 'refs/tags/grown']), 'latin1'), target);
50 assert.deepEqual(fsckProblems(dst), []);
51});
Diagnostics6 git calls · 248 ms
CallStatusSizeTime0248 ms
discover200191 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=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 KiB74 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=72 git.response.bytes=11990 git.response.cache=EXPIRED git.response.duration_ms=74 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 · hit5 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=5 git.response.bytes=4347 git.response.cache=HIT git.response.duration_ms=5 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 · 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=919 git.response.cache=HIT git.response.duration_ms=2 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 · 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=5724 git.response.cache=HIT git.response.duration_ms=2 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
fetch2001.6 KiB165 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=165 git.response.bytes=1609 git.response.cache=MISS git.response.duration_ms=165 git.fetch.wants=e186b8a612beb8d7e68f54a996bdb8df8ebf761c 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=1609 git.pkt.payload.max=1582 git.sideband.band1.bytes=1582 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
- a5e14ce66fafa140
- Request
- 77fdb490…
- 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