openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 1.4 kB
JavaScript
import { i as isMissingPathError } from "./errno-DFcoqIT9.mjs";
import "./errors-BKzCeTYb.mjs";
import path from "node:path";
import fs from "node:fs/promises";
//#region 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 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")
};
});
}
//#endregion
export { splitNullBuffer as a, rawPathStat as i, parseGitTreePaths as n, rawPathExists as r, checkoutPathFromGitBytes as t };