(data: Uint8Array)
| 560 | |
| 561 | // Parse a tree object: entries of "mode<space>name\0<20-byte sha>" |
| 562 | function 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. |
| 584 | export function walkTree(parsed: ParsedPack, commitSha: string): TreeFile[] { |
no test coverage detected