Artifactspublic-v0

ply

main
ply4 git calls48 ms45 KiB3 cachedprotocol v2
338 lines23 KiBRaw
1// The fsck tree-entry space (hole #4 of the spaces report, PR #63), as code. Every check git's fsck_tree makes on a
2// tree entry (git v2.50.0 fsck.c fsck_tree, fsck_finish/fsck_blobs for the dotfiles it collects; tree-walk.c
3// decode_tree_entry; object.h parse_mode; utf8.c is_hfs_dot*; path.c is_ntfs_dot*) is an axis below, as a tagged union
4// of the shapes that check sees. A cell is a tree of one or two entries: the cell's entry (`mode` × `name`) and the
5// entry carrying a `trigger`, in the order `position` says. `fsckModel` is git's fsck_tree ported from that source, and
6// test/space/fsck-tree.test.js holds it to `git fsck --strict` on every cell; `expected` is ply's outcome, derived from
7// the model through one rule plus a decision per warning-only msgId (WARN_DECISION).
8//
9// The rule: ply refuses (pack_corrupt) exactly the trees git reports an error for under --strict, and accepts the rest.
10// Severities under --strict (fsck.h; `--strict` turns WARN into an error, INFO stays a warning, fsck exits 0):
11// ERROR badTree duplicateEntries treeNotSorted gitmodulesSymlink gitmodulesBlob gitmodulesMissing
12// gitattributesBlob gitattributesMissing error
13// WARN nullSha1 fullPathname emptyName hasDot hasDotdot hasDotgit zeroPaddedFilemode largePathname error
14// INFO badFilemode gitattributesSymlink gitignoreSymlink mailmapSymlink warning
15// emptyName is never reported for a tree git can read: decode_tree_entry refuses an empty name first ("empty filename in
16// tree entry"), which fsck reports as badTree.
17import { createHash } from 'node:crypto';
19const bin = s => Buffer.from(s, 'latin1');
20const utf8 = s => Buffer.from(s, 'utf8');
22// ---- severities and ply's decision for each warning-only msgId ----
23export const SEVERITY = {
24 badTree: 'error', duplicateEntries: 'error', treeNotSorted: 'error', gitmodulesSymlink: 'error', gitmodulesBlob: 'error',
25 gitmodulesMissing: 'error', gitattributesBlob: 'error', gitattributesMissing: 'error',
26 nullSha1: 'error', fullPathname: 'error', emptyName: 'error', hasDot: 'error', hasDotdot: 'error', hasDotgit: 'error',
27 zeroPaddedFilemode: 'error', largePathname: 'error',
28 badFilemode: 'warning', gitattributesSymlink: 'warning', gitignoreSymlink: 'warning', mailmapSymlink: 'warning',
29};
30// A warning git prints under --strict and exits 0 on. Each is decided here; one without a decision fails the test.
31export const WARN_DECISION = {
32 badFilemode: { ply: 'accept', why: 'git reads every such mode through canon_mode (100664 → 100644, 40755 → a tree, an unknown type → a gitlink) and checks it out; real repositories carry 100664 from git\'s first weeks. ply returns the canonical mode, as `git ls-tree` prints it' },
33 gitattributesSymlink: { ply: 'accept', why: 'git reads a symlinked .gitattributes from a tree as the blob it is (attr.c read_attr_from_blob has no mode check) and only declines to follow one in a worktree; ply has no worktree, and merge reads it as git merge-tree does' },
34 gitignoreSymlink: { ply: 'accept', why: 'ply never reads .gitignore' },
35 mailmapSymlink: { ply: 'accept', why: 'ply never reads .mailmap' },
36};
38// ---- the axes ----
39// Each entry: { mode (raw bytes text), name (Buffer), oid: 'blob' | 'tree' | 'gitlink' | 'null' }. 'tree' is a subtree of
40// this cell's own and 'gitlink' an oid no object has, so fsck_finish's reports on them (gitmodulesBlob, ...Missing)
41// name this cell. 'blob' is the empty blob: empty content is a valid .gitmodules and .gitattributes, so no content
42// check fires on it.
43const S_IFMT = 0o170000, S_IFREG = 0o100000, S_IFLNK = 0o120000, S_IFDIR = 0o040000;
44const STANDARD = new Set([0o100755, 0o100644, 0o120000, 0o040000, 0o160000]);
45// parse_mode: octal digits up to the space, accumulated in an unsigned int, stored in a uint16_t
46export const parseMode = raw => {
47 if (raw.length === 0 || !/^[0-7]+$/.test(raw)) return null;
48 let m = 0;
49 for (const d of raw) m = ((m << 3) + Number(d)) >>> 0;
50 return m & 0xffff;
51};
52export const canon = m => ((m & S_IFMT) === S_IFREG ? (m & 0o100 ? '100755' : '100644') : (m & S_IFMT) === S_IFLNK ? '120000' : (m & S_IFMT) === S_IFDIR ? '40000' : '160000');
53const oidKindFor = raw => { const m = parseMode(raw); return m === null ? 'blob' : { '40000': 'tree', '160000': 'gitlink' }[canon(m)] ?? 'blob'; };
55const MODE = { name: 'mode', doc: 'the cell entry\'s mode bytes: every class fsck_tree\'s switch and parse_mode tell apart', variants: [
56 { tag: 'blob', raw: '100644', why: 'S_IFREG|0644: standard' },
57 { tag: 'exec', raw: '100755', why: 'S_IFREG|0755: standard' },
58 { tag: 'symlink', raw: '120000', why: 'S_IFLNK: standard' },
59 { tag: 'tree', raw: '40000', why: 'S_IFDIR: standard' },
60 { tag: 'gitlink', raw: '160000', why: 'S_IFGITLINK: standard' },
61 { tag: 'group', raw: '100664', why: 'S_IFREG|0664: "we had a few of these early on"; badFilemode only under --strict' },
62 { tag: 'private', raw: '100600', why: 'S_IFREG|0600: badFilemode (INFO); canon_mode 100644' },
63 { tag: 'dir755', raw: '40755', why: 'S_IFDIR|0755: badFilemode; S_ISDIR, so it sorts and reads as a tree' },
64 { tag: 'gitlinkPerm', raw: '160644', why: 'S_IFGITLINK|0644: badFilemode; canon_mode 160000' },
65 { tag: 'zeroPadded', raw: '0100644', why: 'a leading 0: zeroPaddedFilemode (WARN), and the value is still 100644' },
66 { tag: 'zeroPaddedTree', raw: '040000', why: 'the zero-padded tree mode old tools wrote: zeroPaddedFilemode' },
67 { tag: 'truncated', raw: '7100644', why: 'parse_mode keeps 16 bits: 07100644 & 0xffff is 0100644, a standard mode (no report at all)' },
68 { tag: 'unknownType', raw: '1', why: 'type bits 0: badFilemode; canon_mode makes it a gitlink' },
69 { tag: 'allBits', raw: '777777', why: '0177777: badFilemode; type 0170000 is no type git knows, so a gitlink' },
70] };
72const NAME = { name: 'name', doc: 'the cell entry\'s name bytes: every spelling fsck_tree and verify_path tell apart', variants: [
73 { tag: 'plain', bytes: utf8('a'), why: 'an ordinary name' },
74 { tag: 'dot', bytes: utf8('.'), why: 'hasDot' },
75 { tag: 'dotdot', bytes: utf8('..'), why: 'hasDotdot' },
76 { tag: 'empty', bytes: utf8(''), why: 'decode_tree_entry: "empty filename in tree entry", so badTree (emptyName is unreachable)' },
77 { tag: 'slash', bytes: utf8('a/b'), why: 'fullPathname' },
78 { tag: 'dotgit', bytes: utf8('.git'), why: 'hasDotgit' },
79 { tag: 'DOTGIT', bytes: utf8('.GIT'), why: 'is_ntfs_dotgit and is_hfs_dotgit fold ASCII case' },
80 { tag: 'DotGit', bytes: utf8('.Git'), why: 'mixed case' },
81 { tag: 'short1', bytes: utf8('git~1'), why: 'is_ntfs_dotgit: the 8.3 short name of .git' },
82 { tag: 'SHORT1', bytes: utf8('GIT~1'), why: 'the short name, upper case' },
83 { tag: 'short2', bytes: utf8('git~2'), why: 'not .git: git guarantees .git takes ~1 (path.c), so ~2 is an ordinary name' },
84 { tag: 'short10', bytes: utf8('git~10'), why: 'git~1 followed by a digit: an ordinary name' },
85 { tag: 'trailDot', bytes: utf8('.git.'), why: 'NTFS trims trailing dots' },
86 { tag: 'trailSpace', bytes: utf8('.git '), why: 'NTFS trims trailing spaces' },
87 { tag: 'trailMixed', bytes: utf8('.git. .'), why: 'dots and spaces, any mix' },
88 { tag: 'stream', bytes: utf8('.git:x'), why: 'an NTFS alternate data stream of .git' },
89 { tag: 'shortStream', bytes: utf8('git~1:x'), why: 'a stream of the short name' },
90 { tag: 'dotgitx', bytes: utf8('.gitx'), why: 'a longer name: ordinary' },
91 { tag: 'hfsZwnj', bytes: utf8('.g‌it'), why: 'HFS+ ignores U+200C' },
92 { tag: 'hfsBom', bytes: utf8('.git'), why: 'HFS+ ignores U+FEFF, also in front' },
93 { tag: 'hfsLrm', bytes: utf8('.git‎'), why: 'HFS+ ignores U+200E, also at the end' },
94 { tag: 'hfsBadTail', bytes: bin('.git\xff'), why: 'next_hfs_char reads an invalid sequence as the end of the name: .git' },
95 { tag: 'hfsSurrogate', bytes: bin('.git\xed\xa0\x80'), why: 'a UTF-8-encoded surrogate is invalid to pick_one_utf8_char: the end, so .git' },
96 { tag: 'badLead', bytes: bin('\xff.git'), why: 'invalid UTF-8 before the dot: not .git to HFS, not to NTFS' },
97 { tag: 'overlongDot', bytes: bin('\xc0\xaegit'), why: 'an overlong "." is invalid, never a dot' },
98 { tag: 'backslash', bytes: utf8('a\\.git'), why: 'fsck_tree reads a backslash as a separator (is_ntfs_dotgit after it) on every platform' },
99 { tag: 'backslashShort', bytes: utf8('a\\git~1'), why: 'the short name after a backslash' },
100 { tag: 'backslashDotdot', bytes: utf8('..\\x'), why: 'fsck checks only .git after a backslash: accepted, and `..` on Windows' },
101 { tag: 'gitmodules', bytes: utf8('.gitmodules'), why: 'gitmodulesSymlink as a symlink; collected for fsck_finish otherwise' },
102 { tag: 'GITMODULES', bytes: utf8('.GITMODULES'), why: 'case' },
103 { tag: 'gitmodulesTrail', bytes: utf8('.gitmodules .'), why: 'is_ntfs_dot_generic: trailing spaces and dots' },
104 { tag: 'gitmodulesStream', bytes: utf8('.gitmodules:x'), why: 'a stream' },
105 { tag: 'gitmodulesShort', bytes: utf8('gitmod~1'), why: 'the 6-character short name, ~1 to ~4' },
106 { tag: 'gitmodulesShort5', bytes: utf8('gitmod~5'), why: '~5 is past the regular short names, and gitmod is not the fallback prefix: ordinary' },
107 { tag: 'gitmodulesFallback', bytes: utf8('GI7EBA~1'), why: 'the fallback short name (hash prefix gi7eba)' },
108 { tag: 'gitmodulesFallback9', bytes: utf8('gi7eba~9'), why: 'the fallback allows ~1 to ~9' },
109 { tag: 'tildeDigits', bytes: utf8('~1234567'), why: 'is_ntfs_dot_generic\'s fallback loop takes a leading ~ and digits as every dotfile\'s short name' },
110 { tag: 'gitmodulesHfs', bytes: utf8('.gitmodu‍les'), why: 'HFS+ ignorable inside' },
111 { tag: 'gitmodulesBackslash', bytes: utf8('a\\.gitmodules'), why: 'is_ntfs_dotgitmodules after a backslash' },
112 { tag: 'gitattributes', bytes: utf8('.gitattributes'), why: 'gitattributesSymlink (INFO) as a symlink' },
113 { tag: 'gitattributesShort', bytes: utf8('gi7d29~1'), why: 'its fallback short name' },
114 { tag: 'gitattributesBackslash', bytes: utf8('a\\.gitattributes'), why: 'fsck_tree checks only .gitmodules after a backslash' },
115 { tag: 'gitignore', bytes: utf8('.gitignore'), why: 'gitignoreSymlink (INFO)' },
116 { tag: 'gitignoreShort', bytes: utf8('gi250a~1'), why: 'its fallback short name' },
117 { tag: 'mailmap', bytes: utf8('.mailmap'), why: 'mailmapSymlink (INFO)' },
118 { tag: 'mailmapShort', bytes: utf8('maba30~1'), why: 'its fallback short name' },
119 { tag: 'long4096', bytes: utf8('l'.repeat(4096)), why: 'max_tree_entry_len: 4096 bytes is allowed' },
120 { tag: 'long4097', bytes: utf8('l'.repeat(4097)), why: 'largePathname' },
121] };
123// The other entry: one per fsck_tree msgId trigger (or none), with the minimal defect that fires it.
124const e = (mode, name, oid = oidKindFor(mode)) => ({ mode, name: typeof name === 'string' ? utf8(name) : name, oid });
125const TRIGGER = { name: 'trigger', doc: 'the other entry in the tree, carrying one fsck_tree msgId\'s trigger', variants: [
126 { tag: 'alone', entry: null, why: 'a one-entry tree' },
127 { tag: 'plain', entry: e('100644', 'm'), why: 'an ordinary sibling' },
128 { tag: 'nullSha1', entry: e('100644', 'n', 'null'), why: 'is_null_oid' },
129 { tag: 'fullPathname', entry: e('100644', 'm/n'), why: 'strchr(name, \'/\')' },
130 { tag: 'emptyName', entry: e('100644', ''), why: 'an empty name: badTree (decode_tree_entry)' },
131 { tag: 'malformedMode', entry: e('10x644', 'm', 'blob'), why: 'parse_mode: a non-octal digit, "malformed mode in tree entry": badTree' },
132 { tag: 'hasDot', entry: e('100644', '.'), why: '"."' },
133 { tag: 'hasDotdot', entry: e('100644', '..'), why: '".."' },
134 { tag: 'hasDotgit', entry: e('100644', '.git'), why: 'is_hfs_dotgit || is_ntfs_dotgit' },
135 { tag: 'zeroPaddedFilemode', entry: e('0100644', 'm'), why: 'the mode\'s first byte is \'0\'' },
136 { tag: 'badFilemode', entry: e('100664', 'm'), why: 'S_IFREG|0664 under --strict' },
137 { tag: 'gitmodulesSymlink', entry: e('120000', '.gitmodules'), why: 'S_ISLNK on a .gitmodules' },
138 { tag: 'gitmodulesBlob', entry: e('40000', '.gitmodules'), why: 'a .gitmodules that is a tree: fsck_finish "non-blob found at .gitmodules"' },
139 { tag: 'gitattributesSymlink', entry: e('120000', '.gitattributes'), why: 'S_ISLNK on a .gitattributes (INFO)' },
140 { tag: 'gitattributesMissing', entry: e('160000', '.gitattributes'), why: 'a .gitattributes gitlink: fsck_finish cannot read the blob' },
141 { tag: 'gitignoreSymlink', entry: e('120000', '.gitignore'), why: 'S_ISLNK on a .gitignore (INFO)' },
142 { tag: 'mailmapSymlink', entry: e('120000', '.mailmap'), why: 'S_ISLNK on a .mailmap (INFO)' },
143 { tag: 'largePathname', entry: e('100644', 'm'.repeat(4097)), why: 'tree_entry_len > 4096' },
144 { tag: 'duplicateEntries', entry: 'same', why: 'the cell\'s own name again, as 100644: verify_ordered TREE_HAS_DUPS' },
145] };
147const POSITION = { name: 'position', doc: 'the order of the two entries in the tree bytes (the tree is sorted or not as the names fall)', variants: [
148 { tag: 'cellFirst', why: 'the cell entry, then the trigger entry' },
149 { tag: 'triggerFirst', why: 'the trigger entry, then the cell entry' },
150] };
152export const AXES = [TRIGGER, MODE, NAME, POSITION];
153// A one-entry tree has no order: its two positions are one tree.
154export const COLLAPSE = [{ when: c => c.trigger.tag === 'alone' && c.position.tag !== 'cellFirst', why: 'a one-entry tree has no order' }];
156// Generic product of the axes: every combination, each a cell { [axis.name]: variant }, minus the collapsed duplicates.
157export function product(axes = AXES) {
158 let cells = [{}];
159 for (const a of axes) cells = cells.flatMap(c => a.variants.map(v => ({ ...c, [a.name]: v })));
160 return cells.filter(c => !COLLAPSE.some(r => r.when(c)));
162export const cellId = c => AXES.map(a => c[a.name].tag).join('/');
164// The cell's entries in tree order: [{ mode, name, oid, role: 'cell' | 'trigger' }]
165export function entriesOf(c) {
166 const cell = { mode: c.mode.raw, name: c.name.bytes, oid: oidKindFor(c.mode.raw), role: 'cell' };
167 const t = c.trigger.entry === 'same' ? { mode: '100644', name: c.name.bytes, oid: 'blob' } : c.trigger.entry;
168 if (!t) return [cell];
169 const trig = { ...t, role: 'trigger' };
170 return c.position.tag === 'cellFirst' ? [cell, trig] : [trig, cell];
173// The oid an entry points at, given the store's fixtures (blob: the empty blob) and the cell's own objects.
174export const gitlinkOid = (id, role) => createHash('sha1').update(`gitlink ${role} ${id}`).digest('hex');
175export const subtreeBytes = (id, role, blob) => Buffer.concat([utf8(`100644 ${role}-${createHash('sha1').update(id).digest('hex').slice(0, 12)}\0`), Buffer.from(blob, 'hex')]);
177export function treeBytes(entries, oidOf) {
178 return Buffer.concat(entries.flatMap(x => [utf8(`${x.mode} `), x.name, Buffer.from([0]), Buffer.from(oidOf(x), 'hex')]));
181// ---- git's fsck_tree, ported (the model the test holds to `git fsck --strict`) ----
182// path.c / utf8.c predicates, written again here from the C (not imported from src/validate.js: the model must not
183// share code with what it judges).
184const at = (b, i) => (i < b.length ? b[i] : 0);
185const lc = c => (c >= 65 && c <= 90 ? c + 32 : c);
186function pick(b, i) { // utf8.c pick_one_utf8_char → [ch, incr] | null
187 const s = k => at(b, i + k);
188 if (s(0) < 0x80) return [s(0), 1];
189 if ((s(0) & 0xe0) === 0xc0) { if ((s(1) & 0xc0) !== 0x80 || (s(0) & 0xfe) === 0xc0) return null; return [((s(0) & 0x1f) << 6) | (s(1) & 0x3f), 2]; }
190 if ((s(0) & 0xf0) === 0xe0) {
191 if ((s(1) & 0xc0) !== 0x80 || (s(2) & 0xc0) !== 0x80 || (s(0) === 0xe0 && (s(1) & 0xe0) === 0x80) || (s(0) === 0xed && (s(1) & 0xe0) === 0xa0) || (s(0) === 0xef && s(1) === 0xbf && (s(2) & 0xfe) === 0xbe)) return null;
192 return [((s(0) & 0x0f) << 12) | ((s(1) & 0x3f) << 6) | (s(2) & 0x3f), 3];
193 }
194 if ((s(0) & 0xf8) === 0xf0) {
195 if ((s(1) & 0xc0) !== 0x80 || (s(2) & 0xc0) !== 0x80 || (s(3) & 0xc0) !== 0x80 || (s(0) === 0xf0 && (s(1) & 0xf0) === 0x80) || (s(0) === 0xf4 && s(1) > 0x8f) || s(0) > 0xf4) return null;
196 return [0x10000, 4]; // the value is never compared to an ASCII needle or an ignorable
197 }
198 return null;
200const IGNORABLE = [0x200c, 0x200d, 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e, 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff];
201function hfs(b, needle) {
202 let i = 0, dead = false;
203 const next = () => { while (!dead) { const r = pick(b, i); if (!r) { dead = true; break; } i += r[1]; if (!IGNORABLE.includes(r[0])) return r[0]; } return 0; };
204 if (next() !== 46) return false;
205 for (const ch of needle) { const c = next(); if (c > 127 || lc(c) !== ch.charCodeAt(0)) return false; }
206 const c = next();
207 return !c || c === 47;
209function ntfsGit(b, o) {
210 let i = o; let c = at(b, i++);
211 if (c === 46) { for (const ch of 'git') { c = at(b, i++); if (lc(c) !== ch.charCodeAt(0)) return false; } }
212 else if (lc(c) === 103) { for (const ch of 'it') { c = at(b, i++); if (lc(c) !== ch.charCodeAt(0)) return false; } if (at(b, i++) !== 126 || at(b, i++) !== 49) return false; }
213 else return false;
214 for (;;) { c = at(b, i++); if (!c || c === 47 || c === 92 || c === 58) return true; if (c !== 46 && c !== 32) return false; }
216function ntfsGeneric(b, o, dotname, prefix) {
217 const n = k => at(b, o + k);
218 const only = i => { for (;;) { const c = n(i++); if (!c || c === 58) return true; if (c !== 32 && c !== 46) return false; } };
219 let eq = n(0) === 46;
220 for (let k = 0; eq && k < dotname.length; k++) if (lc(n(k + 1)) !== dotname.charCodeAt(k)) eq = false;
221 if (eq) return only(dotname.length + 1);
222 let eq6 = true;
223 for (let k = 0; k < 6; k++) if (lc(n(k)) !== dotname.charCodeAt(k)) eq6 = false;
224 if (eq6 && n(6) === 126 && n(7) >= 49 && n(7) <= 52) return only(8);
225 let saw = false;
226 for (let i = 0; i < 8; i++) {
227 if (n(i) === 0) return false;
228 if (saw) { if (n(i) < 48 || n(i) > 57) return false; }
229 else if (n(i) === 126) { if (n(++i) < 49 || n(i) > 57) return false; saw = true; }
230 else if (i >= 6) return false;
231 else if (n(i) & 0x80) return false;
232 else if (lc(n(i)) !== prefix.charCodeAt(i)) return false;
233 }
234 return only(8);
236const DOT = { gitmodules: 'gi7eba', gitignore: 'gi250a', gitattributes: 'gi7d29', mailmap: 'maba30' };
237const isDot = (b, f) => hfs(b, f) || ntfsGeneric(b, 0, f, DOT[f]);
238const tails = b => [...b.keys()].filter(i => b[i] === 92).map(i => i + 1);
240// fsck.c verify_ordered with its name stack
241function verifyOrdered(m1, n1, m2, n2, stack) {
242 const len = Math.min(n1.length, n2.length);
243 const cmp = Buffer.compare(n1.subarray(0, len), n2.subarray(0, len));
244 if (cmp < 0) return 0;
245 if (cmp > 0) return 'unordered';
246 let c1 = at(n1, len), c2 = at(n2, len);
247 if (!c1 && !c2) return 'dups';
248 if (!c1 && (m1 & S_IFMT) === S_IFDIR) c1 = 47;
249 if (!c2 && (m2 & S_IFMT) === S_IFDIR) c2 = 47;
250 const lessThanSlash = c => c > 0 && c < 47;
251 if (!c1 && lessThanSlash(c2)) stack.push(n1);
252 else if (c2 === 47 && lessThanSlash(c1)) {
253 for (;;) {
254 const f = stack.pop();
255 if (!f) break;
256 if (!n2.subarray(0, f.length).equals(f) || n2.length < f.length) continue;
257 if (n2.length === f.length) return 'dups';
258 if (lessThanSlash(n2[f.length])) { stack.push(f); break; }
259 }
260 }
261 return c1 < c2 ? 0 : 'unordered';
264// → { tree: Set<msgId> (reported on the cell's tree), finish: [{ msgId, on: entry }] (fsck_finish, on the entry's object) }
265export function fsckModel(entries) {
266 const tree = new Set(), finish = [];
267 const decodable = x => parseMode(x.mode) !== null && x.name.length > 0;
268 if (entries.length && !decodable(entries[0])) return { tree: new Set(['badTree']), finish };
269 let o = null; const stack = [];
270 const flags = new Set();
271 for (let k = 0; k < entries.length; k++) {
272 const x = entries[k], m = parseMode(x.mode), name = x.name;
273 if (x.oid === 'null') flags.add('nullSha1');
274 if (name.includes(47)) flags.add('fullPathname');
275 if (name.length === 1 && name[0] === 46) flags.add('hasDot');
276 if (name.length === 2 && name[0] === 46 && name[1] === 46) flags.add('hasDotdot');
277 if (hfs(name, 'git') || ntfsGit(name, 0)) flags.add('hasDotgit');
278 if (x.mode[0] === '0') flags.add('zeroPaddedFilemode');
279 if (name.length > 4096) flags.add('largePathname');
280 const lnk = (m & S_IFMT) === S_IFLNK;
281 const collect = f => { if (x.oid === 'null' || x.oid === 'gitlink') finish.push({ msgId: `${f}Missing`, on: x }); else if (x.oid === 'tree') finish.push({ msgId: `${f}Blob`, on: x }); };
282 if (isDot(name, 'gitmodules')) { if (lnk) tree.add('gitmodulesSymlink'); else collect('gitmodules'); }
283 if (isDot(name, 'gitattributes')) { if (lnk) tree.add('gitattributesSymlink'); else collect('gitattributes'); }
284 if (lnk && isDot(name, 'gitignore')) tree.add('gitignoreSymlink');
285 if (lnk && isDot(name, 'mailmap')) tree.add('mailmapSymlink');
286 for (const t of tails(name)) {
287 if (ntfsGit(name, t)) flags.add('hasDotgit');
288 if (ntfsGeneric(name, t, 'gitmodules', DOT.gitmodules)) { if (lnk) tree.add('gitmodulesSymlink'); else collect('gitmodules'); }
289 }
290 if (k + 1 < entries.length && !decodable(entries[k + 1])) { tree.add('badTree'); break; }
291 if (!STANDARD.has(m)) flags.add('badFilemode');
292 if (o) { const r = verifyOrdered(o.m, o.name, m, name, stack); if (r === 'unordered') flags.add('treeNotSorted'); if (r === 'dups') flags.add('duplicateEntries'); }
293 o = { m, name };
294 }
295 for (const f of flags) tree.add(f);
296 return { tree, finish };
299// ply's outcome for a cell, from the model: refuse iff git reports an error-severity msgId (WARN_DECISION decides the
300// rest). Returns { ply: 'accept' | 'refuse', errors: [msgId], warnings: [msgId] }.
301export function expected(c) {
302 const { tree, finish } = fsckModel(entriesOf(c));
303 const all = [...tree, ...finish.map(f => f.msgId)];
304 const errors = [...new Set(all.filter(m => SEVERITY[m] === 'error'))].sort();
305 const warnings = [...new Set(all.filter(m => SEVERITY[m] === 'warning'))].sort();
306 for (const m of all) if (!SEVERITY[m]) throw new Error(`no severity for ${m}`);
307 for (const w of warnings) if (!WARN_DECISION[w]) throw new Error(`no decision for the warning ${w}`);
308 const ply = errors.length ? 'refuse' : warnings.every(w => WARN_DECISION[w].ply === 'accept') ? 'accept' : 'refuse';
309 return { ply, errors, warnings };
312// ply's refusal messages (src/objects.js parseTree) and the msgIds each stands for: a refusal must name one git reported
313export const PLY_MESSAGE = [
314 [/^tree: malformed entry$/, ['badTree']],
315 [/^tree: empty mode$/, ['badTree']],
316 [/^tree: malformed mode$/, ['badTree']],
317 [/^tree: empty name$/, ['badTree']],
318 [/^tree: zero-padded mode$/, ['zeroPaddedFilemode']],
319 [/^tree: full pathname$/, ['fullPathname']],
320 [/^tree: bad name$/, ['hasDot', 'hasDotdot', 'hasDotgit']],
321 [/^tree: large pathname$/, ['largePathname']],
322 [/^tree: null sha1$/, ['nullSha1']],
323 [/^tree: \.gitmodules is a symbolic link$/, ['gitmodulesSymlink']],
324 [/^tree: \.gitmodules is not a blob$/, ['gitmodulesBlob', 'gitmodulesMissing']],
325 [/^tree: \.gitattributes is not a blob$/, ['gitattributesBlob', 'gitattributesMissing']],
326 [/^tree: duplicate entry /, ['duplicateEntries']],
327 [/^tree: not strictly sorted$/, ['treeNotSorted']],
328];
329export const msgIdsOfPly = message => PLY_MESSAGE.find(([re]) => re.test(message))?.[1] ?? null;
331// The Windows checkout rules (compat/mingw.c is_valid_win32_path, read-cache.c verify_path under GIT_WINDOWS_NATIVE),
332// derived from the source: no git for Windows runs here. [name, refused?]
333export const WIN32 = [
334 ['a', false], ['..\\x', true], ['a\\b', true], ['con', true], ['CON.txt', true], ['con .txt', true], ['nul:x', true],
335 ['aux ', true], ['prn', true], ['com1', true], ['com0', false], ['lpt0', true], ['conin$', true], ['CONOUT$', true],
336 ['console', false], ['a.', true], ['a ', true], ['a:b', true], ['a<b', true], ['a>b', true], ['a"b', true],
337 ['a|b', true], ['a?b', true], ['a*b', true], ['a\x01b', true], ['a.b', false], ['.a', false], ['...', true],
338];
Diagnostics4 git calls · 48 ms
CallStatusSizeTime048 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=7
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 · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=2
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 · hit7 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=38
git.response.bytes=38434
git.response.cache=HIT
git.response.duration_ms=7
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
fetch2007.7 KiB · hit39 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=7843
git.response.cache=HIT
git.response.duration_ms=39
git.fetch.wants=ba82ef53a002b17ac07bf1892089cb3e53aed8f3
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=7843
git.pkt.payload.max=7822
git.sideband.band1.bytes=7821
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
a5e30bbbdea7ee28
Request
9b27a28e…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format