(
refs: Array<{ oldOid: string; newOid: string; refName: string }>,
packfileBytes: Uint8Array
)
| 10 | // --------------------------------------------------------------------------- |
| 11 | |
| 12 | function buildPushRequest( |
| 13 | refs: Array<{ oldOid: string; newOid: string; refName: string }>, |
| 14 | packfileBytes: Uint8Array |
| 15 | ): Uint8Array { |
| 16 | const encoder = new TextEncoder(); |
| 17 | const chunks: Uint8Array[] = []; |
| 18 | |
| 19 | for (let i = 0; i < refs.length; i++) { |
| 20 | const { oldOid, newOid, refName } = refs[i]; |
| 21 | let line = `${oldOid} ${newOid} ${refName}`; |
| 22 | if (i === 0) { |
| 23 | line += '\0 report-status'; |
| 24 | } |
| 25 | line += '\n'; |
| 26 | const lengthHex = (line.length + 4).toString(16).padStart(4, '0'); |
| 27 | chunks.push(encoder.encode(lengthHex + line)); |
| 28 | } |
| 29 | |
| 30 | chunks.push(encoder.encode('0000')); |
| 31 | chunks.push(packfileBytes); |
| 32 | |
| 33 | const totalLength = chunks.reduce((sum, c) => sum + c.length, 0); |
| 34 | const result = new Uint8Array(totalLength); |
| 35 | let offset = 0; |
| 36 | for (const chunk of chunks) { |
| 37 | result.set(chunk, offset); |
| 38 | offset += chunk.length; |
| 39 | } |
| 40 | return result; |
| 41 | } |
| 42 | |
| 43 | const zeroOid = '0'.repeat(40); |
| 44 |
no test coverage detected