GitHubivarvong
ply
main
1// Run `git pack-objects` exactly as upload-pack does for a v2 fetch, and return the
2// object set it produced. This is the exact-set oracle; the model gives the bound.
3import { execFileSync } from 'node:child_process';
4import { gitBuf } from '../server.js';
5import { parsePack, resolvePack } from '../../src/pack.js';
6import { effectiveHaves } from './dag.js';
7import { unwrap } from '../unwrap.js';
9// Git 2.56 moved the argv out of upload-pack.c create_pack_file into
10// odb/source-files.c odb_source_files_generate_pack. --thin follows --stdout, and
11// progress-none (ply sends no-progress by default) is spelled --quiet. Through 2.55
12// --thin precedes --stdout and a quiet client adds no flag.
13export const PACK_ARGV_QUIET = Object.freeze([2, 56, 0]);
15const atLeast = (version, floor) => version[0] > floor[0] || (version[0] === floor[0] && (version[1] > floor[1] || (version[1] === floor[1] && version[2] >= floor[2])));
17export function installedGitVersion() {
18 const s = execFileSync('git', ['--version'], { encoding: 'utf8' });
19 const m = /git version (\d+)\.(\d+)\.(\d+)/.exec(s);
20 if (!m) throw new Error(`unrecognized git version: ${s}`);
21 return [Number(m[1]), Number(m[2]), Number(m[3])];
22}
24const INSTALLED_GIT = installedGitVersion();
26export function packObjectsOracle(bare, model, req, { shallowSet, unshallowed = [], inDepth = new Map(), external }) {
27 const { haves = [], filter, thinPack, ofsDelta = true } = req;
28 // send_unshallow(): an unshallowed client commit's parents become wants, the commit itself an extra edge.
29 // It sets object->parsed = 0 and re-parses, which appends the parents to the already-parsed list: each parent twice.
30 const wants = [...req.wants, ...unshallowed.flatMap(u => { const ps = model.commits.get(u).parents; return [...ps, ...ps]; })];
31 const peel = o => (model.tags.has(o) ? model.tags.get(o) : o);
32 const known = effectiveHaves(model, haves);
33 const shallows = [...shallowSet];
34 const extraEdges = new Set(unshallowed);
35 const { args, stdin } = reconstructInvocation({ wants, known, shallows, extraEdges, thinPack, ofsDelta, filter });
36 const pack = new Uint8Array(gitBuf(bare, ['pack-objects', ...args, '-q'], stdin));
37 if (pack.length === 0) return { objects: new Map(), count: 0 };
38 const parsed = unwrap(parsePack(pack));
39 const r = unwrap(resolvePack(parsed, external));
40 return { objects: r.objects, count: parsed.stats.count, parsed };
41}
43// Argv in the order the installed git's upload-pack passes to pack-objects.
44export function packObjectsArgs({ thinPack, shallows, ofsDelta, includeTag, filter, version = INSTALLED_GIT }) {
45 const quiet = atLeast(version, PACK_ARGV_QUIET);
46 const args = ['--revs'];
47 if (thinPack && !quiet) args.push('--thin');
48 args.push('--stdout');
49 if (thinPack && quiet) args.push('--thin');
50 if (shallows.length) args.push('--shallow');
51 if (ofsDelta) args.push('--delta-base-offset');
52 if (includeTag) args.push('--include-tag');
53 if (quiet) args.push('--quiet');
54 if (filter) args.push(`--filter=${filter}`);
55 return args;
56}
58export function reconstructInvocation({ wants, known, shallows, extraEdges, thinPack, ofsDelta, includeTag, filter, version }) {
59 const args = packObjectsArgs({ thinPack, shallows, ofsDelta, includeTag, filter, version });
60 // grafts are written in oid order (for_each_commit_graft walks a sorted list)
61 const stdin = [...[...shallows].sort().map(s => `--shallow ${s}`), ...wants, '--not', ...known, ...extraEdges, ''].join('\n') + '\n';
62 return { args, stdin };
63}
64export function reconstructFor(model, req, { shallowSet, unshallowed = [] }) {
65 const wants = [...req.wants, ...unshallowed.flatMap(u => { const ps = model.commits.get(u).parents; return [...ps, ...ps]; })];
66 return reconstructInvocation({ wants, known: effectiveHaves(model, req.haves ?? []), shallows: [...shallowSet], extraEdges: unshallowed, thinPack: req.thinPack, ofsDelta: req.ofsDelta !== false, filter: req.filter });
67}
Diagnostics9 git calls · 229 ms
CallStatusSizeTime0229 ms
discover200191 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=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 KiB91 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=91 git.response.bytes=11990 git.response.cache=EXPIRED git.response.duration_ms=91 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 1200347 B · hit4 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=347 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=1 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=347 git.pkt.payload.max=247 git.sideband.band1.bytes=247 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=247 git.pack.trailer=4b72f39b5ea57c5ae3009f90b53e3a6a155093e7Open pack map
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=106 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
fetchcombine:blob:none+tree:2 · deepen 1200—106 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.cache=BYPASS git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 error.type=remote_error error=remote: filter 'combine' not supported
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=3 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 · hit3 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=3 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=3 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.6 KiB · hit23 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=23 git.response.bytes=1630 git.response.cache=HIT git.response.duration_ms=23 git.fetch.wants=69ea04e077f7825ed2966ec68e4a721d43cfcf07 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=1630 git.pkt.payload.max=1603 git.sideband.band1.bytes=1603 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
- a5e21bf74e7eecd4
- Request
- b99791a5…
- 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