MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / parseTree

Function parseTree

packages/plugins/apps/src/git-client/packfile.ts:562–581  ·  view source on GitHub ↗
(data: Uint8Array)

Source from the content-addressed store, hash-verified

560
561// Parse a tree object: entries of "mode<space>name\0<20-byte sha>"
562function parseTree(data: Uint8Array): { mode: string; name: string; sha: string }[] {
563 const entries: { mode: string; name: string; sha: string }[] = [];
564 let p = 0;
565 while (p < data.length) {
566 let sp = p;
567 while (sp < data.length && data[sp] !== 0x20) sp++;
568 if (sp >= data.length) throw new PackParseError("malformed tree entry mode");
569 const mode = td.decode(data.subarray(p, sp));
570 let nul = sp + 1;
571 while (nul < data.length && data[nul] !== 0) nul++;
572 if (nul >= data.length) throw new PackParseError("malformed tree entry name");
573 requireAvailable(data, nul + 1, 20, "tree entry sha");
574 const name = td.decode(data.subarray(sp + 1, nul));
575 let sha = "";
576 for (let i = 0; i < 20; i++) sha += data[nul + 1 + i].toString(16).padStart(2, "0");
577 p = nul + 21;
578 entries.push({ mode, name, sha });
579 }
580 return entries;
581}
582
583// Walk from commit sha to a flat file list. Blobs must be present in pack.
584export function walkTree(parsed: ParsedPack, commitSha: string): TreeFile[] {

Callers 1

recurFunction · 0.85

Calls 3

requireAvailableFunction · 0.85
toStringMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected