openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.41 kB
JavaScript
import{i as isMissingPathError}from"./errno-DUBt6SQQ.mjs";import"./errors-D37BJTfI.mjs";import path from"node:path";import fs from"node:fs/promises";
//!src/agents/worktrees/git-path-inventory.ts
function splitNullBuffer(e){const t=Buffer.from(e.buffer,e.byteOffset,e.byteLength);const n=[];let r=0;for(let e=t.indexOf(0,r);e!==-1;e=t.indexOf(0,r)){if(e>r)n.push(t.subarray(r,e));r=e+1}if(r<t.length)n.push(t.subarray(r));return n}function*gitPathspecBatches(e){let t=0;while(t<e.length){const n=[];let r=0;while(t<e.length&&(n.length===0||n.length<128&&r<16384)){const i=e[t++];n.push(i);r+=Buffer.byteLength(i)+1}yield n}}function checkoutPathFromGitBytes(e,t){if(process.platform===`win32`)return path.join(e,...t.toString(`utf8`).split(`/`));return Buffer.concat([Buffer.from(e),Buffer.from(path.sep),t])}async function rawPathStat(e){try{return await fs.lstat(e)}catch(e){if(isMissingPathError(e))return;throw e}}async function rawPathExists(e){return await rawPathStat(e)!==void 0}function parseGitTreePaths(e){return splitNullBuffer(e).map(e=>{const t=e.indexOf(9);if(t<0)throw new Error(`Git tree inventory contains an invalid entry`);return{path:e.subarray(t+1),mode:e.subarray(0,6).toString(`ascii`),oid:e.subarray(e.indexOf(32,7)+1,t).toString(`ascii`)}})}export{rawPathStat as a,rawPathExists as i,gitPathspecBatches as n,splitNullBuffer as o,parseGitTreePaths as r,checkoutPathFromGitBytes as t};