GitHubivarvong
ply
main
1// The push-ng space: every rejection reason git's receive-pack can write, as code. The reason axis is git v2.50.0's
2// list itself (test/space/git-manifest.json, kind "reject": builtin/receive-pack.c's ng and unpack strings, extracted by
3// scripts/git-manifest.mjs on the spaces branch). Each reason carries, as data: the stage of receive-pack that writes it
4// (which decides what the other commands of the push get), the commands it can answer, and its class in ply's error
5// taxonomy with the reason for it: what a caller can safely do next. The product is generic; the report git writes for a
6// cell is derived from receive-pack.c (gitReport), checked against real git where git can be made to write it
7// (push-ng.observed.js), and ply's outcome for every cell is checked against the class table (push-ng.test.js).
8//
9// git sources are v2.50.0 builtin/receive-pack.c: update(), execute_commands(), execute_commands_non_atomic(),
10// execute_commands_atomic(), check_aliased_update_internal(), set_connectivity_errors(), reject_updates_to_hidden(),
11// update_shallow_info(), read_proc_receive_report(), run_proc_receive_hook(), push_to_deploy(), unpack(), cmd_receive_pack().
12import { readFileSync } from 'node:fs';
13import { pkt, FLUSH } from '../../src/pktline.js';
14import { concat, te } from '../../src/bytes.js';
15import { unwrap } from '../unwrap.js';
17const MANIFEST = JSON.parse(readFileSync(new URL('./git-manifest.json', import.meta.url), 'utf8'));
18export const GIT_SOURCE = MANIFEST.git;
19export const MANIFEST_REJECTS = MANIFEST.entries.filter(e => e.kind === 'reject');
21export const ZERO = '0'.repeat(40);
22// symbolic oids of the rendered (no-network) cells; the observed cells use real commits with the same roles
23export const OID = { A: '4'.repeat(40), B: '1'.repeat(40), C: '2'.repeat(40), X: '3'.repeat(40), U: '5'.repeat(40), zero: ZERO };
25// ---- the class table: what a caller can safely do next ----
26// cas cas_conflict (retry 'fresh'): nothing moved, and re-reading the ref can change the answer
27// nff not_fast_forward (retry 'no'): nothing moved; the server refuses this history whatever the ref's value
28// rejected push_rejected (retry 'no'): nothing moved; the same request is refused again until a person changes something
29// ambiguous ambiguous (retry 'read'): a proc-receive hook took the command and did not answer for it; it may have acted
30// innocent an atomic push's other members: the culprit's class decides
31// unpack an unpack failure: every command is "unpacker error"; nothing moved (push_rejected)
32export const CLASSES = ['cas', 'nff', 'rejected', 'ambiguous', 'innocent', 'unpack'];
33export const CODE = { cas: 'cas_conflict', nff: 'not_fast_forward', rejected: 'push_rejected', ambiguous: 'ambiguous', unpack: 'push_rejected' };
35// ---- the stages: where in receive-pack the reason is written, and what that does to the other commands ----
36// pre per command, before the ref transaction (connectivity, hidden refs, aliases, shallow): the others go on, even
37// in an atomic push (git's atomic push splits)
38// update inside update(), per command: non-atomic, the others go on; atomic, the first failure stops the transaction
39// and every other command is "atomic push failure"
40// commit the per-ref transaction's commit (non-atomic): the others go on
41// all every command still without an error gets it (pre-receive, migrate, a failed atomic commit, push options)
42// proc a proc-receive hook's answer for its own command: the others go on; atomic, every other command still
43// without an error is "fail to run proc-receive hook" (run_proc_receive_hook returns -1 after any ng)
44// procRun the proc-receive hook could not be run or did not finish: non-atomic, its own commands; atomic, all
45// unpack unpack() failed: the unpack line carries the reason and every command is "unpacker error"
46// none never a command's own failure (the two consequences: "atomic push failure", "unpacker error")
47export const STAGES = ['pre', 'update', 'commit', 'all', 'proc', 'procRun', 'unpack', 'none'];
49const NON_DELETE = ['create', 'createExists', 'update', 'nonFF', 'stale', 'unknownOld'];
50const ALL = [...NON_DELETE, 'delete'];
51const EXISTING = ['createExists', 'update', 'nonFF', 'stale', 'unknownOld', 'delete'];
52const ONE_CURRENT = 'a repository has one HEAD: one current branch per push';
53const DERIVED_BEGIN = 'ref_store_transaction_begin() cannot fail in git v2.50.0 (refs.c: it only allocates)';
55// One entry per manifest "reject" id. `commands`: the command shapes for which git writes this reason (others are
56// impossible cells, see IMPOSSIBLE). `three`: true, or why three commands cannot all carry it. `pair`: the reason also
57// marks the command its culprit aliases. `names`: ref names the reason needs instead of refs/heads/r<i>. `derived`: why
58// no observed cell exists (otherwise push-ng.observed.js has a recipe for it). `next`: the justification of `cls`.
59export const REASONS = [
60 // --- unpack(): the unpack line; every command is "unpacker error" ---
61 ...[
62 ['eof before pack header was fully read', null],
63 ['protocol error (pack signature mismatch detected)', null],
64 ['protocol error (pack version unsupported)', null],
65 ['unknown error in parse_pack_header', 'parse_pack_header() returns only the three errors above for a header it read; the default case is unreachable'],
66 ['unable to create temporary object directory', null],
67 ['unpack-objects abnormal exit', null],
68 ['index-pack fork failed', 'start_command() failing to fork index-pack cannot be arranged from a request'],
69 ['index-pack abnormal exit', null],
70 ].map(([text, derived]) => ({ id: `receive-pack.c:reject:${text}`, stage: 'unpack', cls: 'unpack', commands: ALL, three: true, ...(derived ? { derived } : {}),
71 next: 'the pack never entered the repository and no ref was touched: resending the same pack fails the same way; the caller needs a different pack or a repaired server' })),
72 { id: 'receive-pack.c:reject:unpacker error', stage: 'none', cls: 'unpack', commands: [], three: true,
73 next: 'written on every command exactly when unpack failed (execute_commands): the unpack line carries the cause; nothing moved' },
75 // --- per command, before the transaction ---
76 { id: 'receive-pack.c:reject:missing necessary objects', stage: 'pre', cls: 'rejected', commands: NON_DELETE, three: true,
77 next: 'the pack does not complete the new commit\'s history (set_connectivity_errors); the same pack is refused again, so retrying it is futile; a fresh read does not repair a pack' },
78 { id: 'receive-pack.c:reject:deny updating a hidden ref', stage: 'pre', cls: 'rejected', commands: NON_DELETE, three: true,
79 next: 'receive.hideRefs covers the ref: the server never lets a client write it, whatever its value' },
80 { id: 'receive-pack.c:reject:deny deleting a hidden ref', stage: 'pre', cls: 'rejected', commands: ['delete'], three: true,
81 next: 'receive.hideRefs covers the ref: the server never lets a client delete it, whatever its value' },
82 { id: 'receive-pack.c:reject:broken symref', stage: 'pre', cls: 'rejected', commands: EXISTING, three: true,
83 next: 'the ref is a symbolic ref the server cannot resolve (a loop): no value of the old oid makes it writable; the repository needs repair' },
84 { id: 'receive-pack.c:reject:inconsistent aliased update', stage: 'pre', cls: 'rejected', pair: true, commands: ['createExists', 'nonFF', 'stale', 'unknownOld', 'delete'], three: true,
85 next: 'one push names a symbolic ref and its target with different updates: the request contradicts itself, and resending it is refused again' },
86 { id: 'receive-pack.c:reject:shallow update not allowed', stage: 'pre', cls: 'rejected', commands: NON_DELETE, three: true,
87 next: 'the pushed history ends at a shallow boundary the server lacks and receive.shallowUpdate is off: the same history is refused again (ply never sends shallow lines; a git client from a shallow clone does)' },
89 // --- inside update() ---
90 { id: 'receive-pack.c:reject:funny refname', stage: 'update', cls: 'rejected', commands: ['create', 'delete'], three: { delete: 'refs/@ is the one name validateRef accepts that check_refname_format refuses even with REFNAME_ALLOW_ONELEVEL (deletes)' },
91 names: (i, cmd) => (cmd === 'delete' ? 'refs/@' : `refs/funny${i}`), preSend: 'bad_request',
92 next: 'the server refuses the ref name itself (check_refname_format(name + 5), one level allowed only for a delete): no retry can succeed, so ply refuses the push before sending a byte (validatePushRef, #73; every name checked against git in test/space/refname.test.js); git\'s report is still observed byte for byte' },
93 { id: 'receive-pack.c:reject:branch is currently checked out', stage: 'update', cls: 'rejected', commands: ALL, three: ONE_CURRENT,
94 next: 'receive.denyCurrentBranch refuses the non-bare repository\'s checked-out branch, whatever its value' },
95 { id: 'receive-pack.c:reject:bad pack', stage: 'update', cls: 'rejected', commands: NON_DELETE, three: true,
96 next: 'the new object is not in the repository after unpack (only with the connectivity check skipped): the same pack fails again' },
97 { id: 'receive-pack.c:reject:deletion prohibited', stage: 'update', cls: 'rejected', commands: ['delete'], three: true,
98 next: 'receive.denyDeletes: branch deletion is off on this server' },
99 { id: 'receive-pack.c:reject:deletion of the current branch prohibited', stage: 'update', cls: 'rejected', commands: ['delete'], three: ONE_CURRENT,
100 next: 'receive.denyDeleteCurrent refuses deleting HEAD\'s branch, whatever its value' },
101 { id: 'receive-pack.c:reject:Invalid denyDeleteCurrent setting', stage: 'update', cls: 'rejected', commands: ['delete'], three: ONE_CURRENT,
102 derived: 'parse_deny_action() maps every config value to a handled deny_action, so the switch\'s default is unreachable',
103 next: 'a server misconfiguration: nothing a client resends can change it' },
104 { id: 'receive-pack.c:reject:bad ref', stage: 'update', cls: 'cas', commands: ['unknownOld'], three: true,
105 next: 'receive.denyNonFastForwards could not parse the old oid the command named: the server does not have it, so the ref is not at it (a stale read of a ref that has since been rewritten): a fresh read names an old oid it has (SAFETY.md I31)' },
106 { id: 'receive-pack.c:reject:non-fast-forward', stage: 'update', cls: 'nff', commands: ['nonFF'], three: true,
107 next: 'receive.denyNonFastForwards and the new commit does not descend from the old oid the command itself named: that is true of the request whatever the ref\'s value, so a fresh read of the ref cannot help; only a new commit that descends from it can (it was cas_conflict: rebase\'s non-fast-forward push looped on it)' },
108 { id: 'receive-pack.c:reject:hook declined', stage: 'update', cls: 'rejected', commands: ALL, three: true,
109 next: 'the update hook refused the ref: server policy, not a race' },
110 { id: 'receive-pack.c:reject:failed to delete', stage: 'update', cls: 'rejected', commands: ['delete'], three: true,
111 derived: 'ref_transaction_delete() queues a deletion and fails only on a name refname_is_safe() refuses, which check_refname_format (funny refname) refused first',
112 next: 'the ref store would not queue the deletion: deterministic for this name' },
113 { id: 'receive-pack.c:reject:shallow error', stage: 'update', cls: 'rejected', commands: NON_DELETE, three: true,
114 derived: 'not arranged: with receive.shallowUpdate=true, a shallow line and a pack lacking a blob above the boundary, git v2.50.0 answered "ok" for one command (the ref moved to a commit whose tree lacks the blob) and, for three, "shallow error" on the first command, then a report without the others\' statuses (ply: ambiguous, a missing status)',
115 next: 'receive.shallowUpdate is on and the history above the shallow boundary is incomplete (update_shallow_ref): the same pack fails again' },
116 { id: 'receive-pack.c:reject:failed to update ref', stage: 'update', cls: 'cas', commands: NON_DELETE, three: true,
117 derived: 'ref_transaction_update() queues an update and fails only on a name check_refname_format refuses, which funny refname refused first',
118 next: 'the same text as the commit failure below, so the same class (the report cannot tell them apart)' },
119 ...[
120 // an unborn branch's empty index needs no refresh, so update-index takes no lock and read-tree is the first to fail (observed)
121 ['Up-to-date check failed', EXISTING.filter(c => c !== 'delete'), 'update-index --refresh failed in the server\'s worktree (its index is locked)'],
122 ['Working directory has unstaged changes', EXISTING.filter(c => c !== 'delete'), 'the server\'s worktree has unstaged changes'],
123 ['Working directory has staged changes', NON_DELETE, 'the server\'s worktree has staged changes'],
124 ['Could not update working tree to new HEAD', NON_DELETE, 'read-tree -u -m could not check out the new commit (an untracked file is in the way)'],
125 ['push-to-checkout hook declined', NON_DELETE, 'the push-to-checkout hook refused'],
126 ].map(([text, commands, why]) => ({ id: `receive-pack.c:reject:${text}`, stage: 'update', cls: 'rejected', commands, three: ONE_CURRENT,
127 next: `receive.denyCurrentBranch=updateInstead: ${why}; the push is refused until someone changes the server's worktree` })),
128 { id: 'receive-pack.c:reject:denyCurrentBranch = updateInstead needs a worktree', stage: 'update', cls: 'rejected', commands: NON_DELETE, three: ONE_CURRENT,
129 derived: 'update() sets do_update_worktree only for a worktree that is not bare, so update_worktree() never sees a bare one',
130 next: 'a server misconfiguration: nothing a client resends can change it' },
132 // --- the transaction ---
133 { id: 'receive-pack.c:reject:failed to update ref#2', stage: 'commit', cls: 'cas', atomic: 'off', commands: ['create', 'createExists', 'stale', 'unknownOld', 'gone'], three: true,
134 names: (i, cmd) => (cmd === 'create' ? `refs/heads/r${i}/sub` : null),
135 next: 'the ref is not at the old oid the command named (a stale read, a create over an existing ref, a concurrent writer holding the lock): a fresh read and a redo can land. Also written for a D/F conflict (create refs/heads/r0/sub beside refs/heads/r0, observed): a fresh retry is safe but cannot land there, and a caller\'s retry budget bounds it' },
136 { id: 'receive-pack.c:reject:atomic transaction failed', stage: 'all', cls: 'cas', atomic: 'on', commands: ['create', 'createExists', 'stale', 'unknownOld', 'gone'], three: true,
137 names: (i, cmd) => (cmd === 'create' ? `refs/heads/r${i}/sub` : null),
138 next: 'an atomic push\'s single commit failed, which for a stale old oid is git v2.50.0\'s only report (every ref gets this text, none gets "failed to update ref", observed): the same lost race as above, so a fresh read and a redo can land (it was push_rejected: an atomic CAS loss was never retried)' },
139 { id: 'receive-pack.c:reject:atomic push failure', stage: 'none', cls: 'innocent', commands: [], three: true,
140 next: 'an atomic push\'s other members after one command failed inside update(): nothing moved, and the culprit\'s reason decides the class' },
141 { id: 'receive-pack.c:reject:transaction failed to start', stage: 'commit', cls: 'rejected', atomic: 'off', commands: ALL, three: true, derived: DERIVED_BEGIN,
142 next: 'the server could not open a ref transaction: a server fault, and nothing moved' },
143 { id: 'receive-pack.c:reject:transaction failed to start#2', stage: 'all', cls: 'rejected', atomic: 'on', commands: ALL, three: true, derived: DERIVED_BEGIN,
144 next: 'the server could not open a ref transaction: a server fault, and nothing moved' },
146 // --- every pending command ---
147 { id: 'receive-pack.c:reject:pre-receive hook declined', stage: 'all', cls: 'rejected', commands: ALL, three: true,
148 next: 'the pre-receive hook refused the push: server policy, not a race' },
149 { id: 'receive-pack.c:reject:unable to migrate objects to permanent storage', stage: 'all', cls: 'rejected', needsPack: true, commands: ALL, three: true,
150 next: 'the server could not move the received objects out of quarantine (a storage fault): nothing moved, and a retry needs the server repaired' },
151 { id: 'receive-pack.c:reject:inconsistent push options', stage: 'all', cls: 'rejected', commands: ALL, three: true,
152 derived: 'needs a signed push (push-cert) whose push options differ from the request\'s; ply never sends a push certificate',
153 next: 'the request contradicts its own certificate: resending it is refused again' },
155 // --- proc-receive (receive.procReceiveRefs): a hook takes the command instead of receive-pack ---
156 { id: 'receive-pack.c:reject:fail to run proc-receive hook', stage: 'procRun', cls: 'ambiguous', commands: ['create'], three: true,
157 names: i => `refs/for/r${i}`,
158 next: 'the hook could not be run, or did not finish after it was handed the command: it may have acted on the command (a review created) without saying, and the report cannot tell which; read before redoing' },
159 { id: 'receive-pack.c:reject:proc-receive failed to report status', stage: 'proc', cls: 'ambiguous', commands: ['create'], three: true,
160 names: i => `refs/for/r${i}`,
161 next: 'the hook was handed the command and gave no status for it: it may have acted; read before redoing' },
162 { id: 'receive-pack.c:reject:failed', stage: 'proc', cls: 'rejected', commands: ['create'], three: true,
163 names: i => `refs/for/r${i}`,
164 next: 'the proc-receive hook answered "ng <ref>" with no message: it refused the command, as an update hook does' },
165];
167// git >= 2.51 (the era axis): execute_commands_non_atomic() runs one batched transaction with REF_TRANSACTION_ALLOW_FAILURE
168// and reports each rejected ref by ref_transaction_error_msg() (refs.c on git master, 2026-10; CI runs git 2.56). The
169// commit failure of "failed to update ref#2" becomes one of these texts, by cause; every other reason is unchanged.
170export const BATCHED = [
171 { text: 'incorrect old value provided', cls: 'cas', commands: ['stale', 'unknownOld'], next: 'REF_TRANSACTION_ERROR_INCORRECT_OLD_VALUE: the ref is not at the old oid the command named: a fresh read and a redo can land' },
172 { text: 'reference already exists', cls: 'cas', commands: ['createExists'], next: 'REF_TRANSACTION_ERROR_CREATE_EXISTS: a create lost to another writer\'s create: a fresh read finds the ref and the redo is an update' },
173 { text: 'reference does not exist', cls: 'cas', commands: ['gone'], next: 'REF_TRANSACTION_ERROR_NONEXISTENT_REF: the ref was deleted since the read: a fresh read finds it absent (it was push_rejected: git >= 2.51\'s stale update of a deleted ref was never re-read)' },
174 { text: 'refname conflict', cls: 'rejected', commands: ['create'], next: 'REF_TRANSACTION_ERROR_NAME_CONFLICT: a D/F conflict (refs/heads/r0/sub beside refs/heads/r0): no value of the old oid makes the name free; git >= 2.51 tells it apart from a lost race, so ply need not retry it' },
175 ...['invalid new value provided', 'expected symref but found regular ref', 'reference conflict due to case-insensitive filesystem', 'unknown failure'].map(text => ({ text, cls: 'rejected', commands: [], next: 'a batched rejection that is not a lost race (a bad new value, a symref expectation, a case-only clash, an unclassified failure): resending is refused again' })),
176];
177export const batchedText = cmd => BATCHED.find(b => b.commands.includes(cmd))?.text;
179// the manifest's text, line and function for each reason
180const byId = new Map(MANIFEST_REJECTS.map(e => [e.id, e]));
181for (const r of REASONS) { const e = byId.get(r.id); if (e) Object.assign(r, { text: e.text, line: e.line, fn: e.fn }); }
182export const reasonByText = text => REASONS.filter(r => r.text === text);
184// ---- the axes ----
185// reason: the 42 reasons a command can fail with on its own (the two consequences ride along: "atomic push failure" on
186// the atomic axis, "unpacker error" on the unpack reasons)
187const REASON = { name: 'reason', doc: 'the reason git writes (git-manifest.json "reject")', variants: REASONS.filter(r => r.stage !== 'none').map(r => ({ tag: r.id.replace('receive-pack.c:reject:', ''), reason: r, why: `receive-pack.c:${r.line} ${r.fn}()` })) };
188const COMMAND = { name: 'command', doc: 'the failing command\'s shape (old → new, and the ref on the server: at B, B a child of A, C a child of B, X a child of A)', variants: [
189 { tag: 'create', old: 'zero', new: 'C', why: 'old = zeros, the ref absent' },
190 { tag: 'createExists', old: 'zero', new: 'C', why: 'old = zeros, the ref at B: a create over an existing ref' },
191 { tag: 'update', old: 'B', new: 'C', why: 'a fast-forward from the ref\'s value' },
192 { tag: 'nonFF', old: 'B', new: 'X', why: 'from the ref\'s value to a commit that does not descend from it (rebase\'s push)' },
193 { tag: 'stale', old: 'A', new: 'C', why: 'a stale old oid the server has: the ref moved from A to B since the read' },
194 { tag: 'unknownOld', old: 'U', new: 'C', why: 'an old oid the server does not have (the ref was rewritten and the old commit is gone)' },
195 { tag: 'delete', old: 'B', new: 'zero', why: 'new = zeros: a deletion (no pack when every command deletes)' },
196 { tag: 'gone', old: 'B', new: 'C', why: 'a fast-forward from B, but the ref was deleted since the read (enumerated with the transaction\'s own failures, where it changes the text)' },
197] };
198const ATOMIC = { name: 'atomic', doc: 'the atomic capability', variants: [
199 { tag: 'off', why: 'execute_commands_non_atomic(): one transaction per command' },
200 { tag: 'on', why: 'execute_commands_atomic(): one transaction; a failure in update() makes every other command "atomic push failure"' },
201] };
202const REFS = { name: 'refs', doc: 'how many commands, and which fail', variants: [
203 { tag: 'one', n: 1, why: 'one command, the culprit' },
204 { tag: 'three', n: 3, why: 'three commands, every one a culprit' },
205 { tag: 'mixed', n: 3, why: 'three commands: the middle one is the culprit, its neighbours fast-forward updates that would land alone' },
206] };
207const ERA = { name: 'era', doc: 'the git whose receive-pack answers', variants: [
208 { tag: 'v2.50', why: 'git <= 2.50 (the manifest\'s v2.50.0): one ref transaction per command; a failed commit is "failed to update ref"' },
209 { tag: 'v2.51+', why: 'git >= 2.51: one batched transaction with per-ref rejections, reported by ref_transaction_error_msg() (BATCHED)' },
210] };
211export const AXES = [REASON, COMMAND, ATOMIC, REFS, ERA];
212export const axis = name => AXES.find(a => a.name === name);
214// ---- impossible cells ----
215const threeWhy = (r, cmd) => (r.three === true ? null : typeof r.three === 'string' ? r.three : r.three[cmd] ?? null);
216export const IMPOSSIBLE = [
217 { why: 'the reason is written only by the other execute_commands_* (atomic-only or non-atomic-only)', test: c => (c.reason.reason.atomic === 'off' && c.atomic.tag === 'on') || (c.reason.reason.atomic === 'on' && c.atomic.tag === 'off') },
218 { why: 'git does not write the reason for this command shape (REASONS[].commands; `gone` is enumerated only with the transaction\'s own failures, where it changes the text)', test: c => !c.reason.reason.commands.includes(c.command.tag) },
219 { why: 'three commands cannot all carry the reason (REASONS[].three)', test: c => c.refs.tag === 'three' && threeWhy(c.reason.reason, c.command.tag) !== null },
220 { why: 'an aliased update needs a second command (the symref\'s target)', test: c => c.refs.tag === 'one' && c.reason.reason.pair },
221 { why: 'a push whose every command deletes sends no pack: no unpack, nothing to migrate', test: c => c.refs.tag !== 'mixed' && c.command.tag === 'delete' && (c.reason.reason.stage === 'unpack' || c.reason.reason.needsPack) },
222 { why: 'the batched transaction changes only the non-atomic commit failure: every other report is the same on both eras, enumerated once (v2.50)', test: c => c.era.tag === 'v2.51+' && c.reason.reason.id !== 'receive-pack.c:reject:failed to update ref#2' },
223];
225export function walk(visit = () => {}) {
226 const census = { raw: AXES.reduce((n, a) => n * a.variants.length, 1), cells: 0, impossible: IMPOSSIBLE.map(() => 0) };
227 const go = (i, cell) => {
228 if (i === AXES.length) {
229 const bad = IMPOSSIBLE.findIndex(r => r.test(cell));
230 if (bad >= 0) { census.impossible[bad]++; return; }
231 census.cells++; visit({ ...cell }); return;
232 }
233 for (const v of AXES[i].variants) go(i + 1, { ...cell, [AXES[i].name]: v });
234 };
235 go(0, {});
236 return census;
237}
238export const cells = () => { const all = []; walk(c => all.push(c)); return all; };
239export const cellId = c => `${c.reason.tag}/${c.command.tag}/atomic ${c.atomic.tag}/${c.refs.tag}/${c.era.tag}`;
241// ---- the commands of a cell ----
242// culprits: the commands that fail on their own. A pair reason's culprits alias command 0 (their symref's target).
243export function culprits(c) {
244 const pair = c.reason.reason.pair;
245 return { one: [0], three: pair ? [1, 2] : [0, 1, 2], mixed: [1] }[c.refs.tag];
246}
247export function refNames(c) {
248 const r = c.reason.reason, bad = new Set(culprits(c));
249 return Array.from({ length: c.refs.n }, (_, i) => (bad.has(i) && r.names?.(i, c.command.tag)) || `refs/heads/r${i}`);
250}
251// commands as { ref, old, new } with symbolic oids (A B C X U zero); the innocents are fast-forwards B → C
252export function commandsOf(c) {
253 const bad = new Set(culprits(c)), names = refNames(c);
254 return names.map((ref, i) => (bad.has(i) ? { ref, old: c.command.old, new: c.command.new } : { ref, old: 'B', new: 'C' }));
255}
257// ---- the report git writes for a cell (derived from receive-pack.c; push-ng.observed.js checks it against git) ----
258// { unpack: 'ok' | <unpack reason>, refs: [{ ref, ok, reason }] }
259export function gitReport(c) {
260 const r = c.reason.reason, names = refNames(c), n = names.length, atomic = c.atomic.tag === 'on';
261 const bad = new Set([...culprits(c), ...(r.pair ? [0] : [])]);
262 const err = Array.from({ length: n }, () => null);
263 const own = () => { for (const i of bad) err[i] = r.text; };
264 const rest = text => { for (let i = 0; i < n; i++) if (err[i] === null) err[i] = text; };
265 switch (r.stage) {
266 case 'unpack': return { unpack: r.text, refs: names.map(ref => ({ ref, ok: false, reason: 'unpacker error' })) };
267 case 'pre': own(); break;
268 case 'commit': if (c.era.tag === 'v2.50') own(); else for (const i of bad) err[i] = batchedText(c.command.tag); break;
269 case 'all': rest(r.text); break;
270 case 'update':
271 if (!atomic) own();
272 else { err[Math.min(...bad)] = r.text; rest('atomic push failure'); }
273 break;
274 case 'proc': own(); if (atomic) rest('fail to run proc-receive hook'); break;
275 case 'procRun': if (atomic) rest(r.text); else own(); break;
276 default: throw new Error(`gitReport: stage ${r.stage} has no case`);
277 }
278 return { unpack: 'ok', refs: names.map((ref, i) => (err[i] === null ? { ref, ok: true } : { ref, ok: false, reason: err[i] })) };
279}
280export const reportLines = rep => [`unpack ${rep.unpack}\n`, ...rep.refs.map(x => (x.ok ? `ok ${x.ref}\n` : `ng ${x.ref} ${x.reason}\n`))];
281// report-status without side-band: receive-pack's report() — one pkt per line, then a flush
282export const reportBytes = rep => concat([...reportLines(rep).map(l => unwrap(pkt(te.encode(l)))), FLUSH]);
284// ---- the expected outcome: from the class table only ----
285// { tag: 'landed', refs } | { tag: 'rejected', code } | { tag: 'partial', landed, rejected } | { tag: 'ambiguous' }
286const CLASS_OF = new Map();
287for (const r of [...REASONS, ...BATCHED]) {
288 if (CLASS_OF.has(r.text) && CLASS_OF.get(r.text) !== r.cls) throw new Error(`two classes for one text: ${r.text}`);
289 CLASS_OF.set(r.text, r.cls);
290}
291export const classOf = text => { if (!CLASS_OF.has(text)) throw new Error(`no class for reason ${text}`); return CLASS_OF.get(text); };
292export function outcomeOf(rep, { atomic }) {
293 if (rep.unpack !== 'ok') return { tag: 'rejected', code: 'push_rejected' };
294 const ok = rep.refs.filter(x => x.ok).map(x => x.ref), ng = rep.refs.filter(x => !x.ok);
295 if (!ng.length) return { tag: 'landed', refs: ok };
296 const cls = ng.map(x => classOf(x.reason));
297 if (cls.includes('ambiguous')) return { tag: 'ambiguous' };
298 if (ok.length) return atomic ? { tag: 'ambiguous' } : { tag: 'partial', landed: ok, rejected: ng.map(x => x.ref) };
299 const code = cls.some(k => k === 'rejected' || k === 'unpack') ? 'push_rejected' : cls.includes('nff') ? 'not_fast_forward' : cls.includes('cas') ? 'cas_conflict' : 'push_rejected';
300 return { tag: 'rejected', code };
301}
302// a reason ply refuses before sending (preSend: the request names what git would refuse): nothing is sent, whatever git would write
303export const expected = c => (c.reason.reason.preSend ? { tag: 'preSend', code: c.reason.reason.preSend, what: 'ref' } : outcomeOf(gitReport(c), { atomic: c.atomic.tag === 'on' }));
305// ---- rendering for push() over the fake transport (test/space/harness.js) ----
306export function render(c) {
307 const commands = commandsOf(c).map(x => ({ ref: x.ref, oldOid: OID[x.old], newOid: OID[x.new] }));
308 return {
309 commands,
310 opts: { sideband: false, reportV2: false, atomic: c.atomic.tag === 'on', pushOptions: [] },
311 limits: { maxRefs: 8, maxReportLines: 16, maxPackBytes: 1 << 20 },
312 response: { bytes: reportBytes(gitReport(c)), end: 'eof' },
313 };
314}
Diagnostics7 git calls · 125 ms
CallStatusSizeTime0125 ms
discover200191 B16 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=16 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 KiB93 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=93 git.response.bytes=11990 git.response.cache=EXPIRED git.response.duration_ms=93 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 · 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=4347 git.response.cache=HIT git.response.duration_ms=3 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 · 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:02001.4 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=1428 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=74d7bb09987bbe78a9c0ea8f43a1b5a4e079f538 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=1428 git.pkt.payload.max=1401 git.sideband.band1.bytes=1401 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1401 git.pack.trailer=65ea1a3aeef333a80a2dfa3f441e629d90497e8eOpen pack map
fetch2008.9 KiB · hit21 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=21 git.response.bytes=9156 git.response.cache=HIT git.response.duration_ms=21 git.fetch.wants=6c51c3f2c9a09c3da10ffc5e12d3b33497be66f5 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=5 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=9156 git.pkt.payload.max=8192 git.sideband.band1.bytes=9124 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
- a5e2dad93da8c125
- Request
- 01cc8cd6…
- 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