| 1 | import { runGit, runGitBuffer } from '../exec/run-git.js'; |
| 2 | |
| 3 | /** The spec caps a pointer file at 1024 bytes, so anything larger is never one. */ |
| 4 | export const LFS_POINTER_MAX_BYTES = |
| 5 | |
| 6 | /** The object a pointer file names, or null when `content` is not a pointer. */ |
| 7 | export function parseLfsPointer(content |
| 8 | if (content.length |
| 9 | const text = |
| 10 | if (!text.startsWith |
| 11 | return null; |
| 12 | } |
| 13 | const oid = |
| 14 | const size = |
| 15 | return oid && |
| 16 | } |
| 17 | |
| 18 | /** Oids of the LFS objects named by pointer files that `include` reaches and `exclude` does not. */ |
| 19 | export async function lfsPointersIn |
| 20 | gitDir, |
| 21 | include, |
| 22 | exclude, |
| 23 | }: { |
| 24 | gitDir: string |
| 25 | include: string |
| 26 | exclude: string |
| 27 | }) { |
| 28 | const listed = |
| 29 | gitDir, |
| 30 | args: [ |
| 31 | 'rev-list', |
| 32 | '--objects', |
| 33 | '--no-object-names', |
| 34 | `--filter=blob:limit=${LFS_POINTER_MAX_BYTES + |
| 35 | ...include, |
| 36 | '--not', |
| 37 | ...exclude, |
| 38 | ], |
| 39 | }); |
| 40 | const blobs = |
| 41 | await runGit({ |
| 42 | gitDir, |
| 43 | args: ['cat-file', |
| 44 | input: Buffer.from |
| 45 | }) |
| 46 | ) |
| 47 | .split('\n') |
| 48 | .filter((line) |
| 49 | .map((line) |
| 50 | if (blobs.length |
| 51 | |
| 52 | // "<oid> blob <size>\n<content>\n" per blob |
| 53 | const output = |
| 54 | gitDir, |
| 55 | args: ['cat-file', |
| 56 | input: Buffer.from |
| 57 | }); |
| 58 | const oids = |
| 59 | for (let offset |
| 60 | const headerEnd = |
| 61 | const size = |
| 62 | output.subarray(offset |
| 63 | ); |
| 64 | const pointer = |
| 65 | output.subarray(headerEnd |
| 66 | ); |
| 67 | if (pointer) oids |
| 68 | offset = headerEnd |
| 69 | } |
| 70 | return [...oids |
| 71 | } |