import{spawn as w}from"child_process";import h from"path";async function v(a,l){if(!l)return new Map;let i,c;try{const t=await l.revparse(["--show-toplevel"]);i=new Set((await l.raw("ls-files",a)).split(`
`).map(s=>s.trim()));const e=t&&h.relative(t,a);c=e&&e.length&&e.length+1||0}catch(t){if(t.message.includes("not a git repository"))return new Map;throw t}return new Promise(t=>{const e=new Map;let s=0;const o=w("git",["log","--raw","--no-merges","--pretty=%at","--",a],{stdio:"pipe"});let p="";function m(f){p+=String(f);const u=p.split(`
`);p=u.pop()||"",u.forEach(r=>{if(r=r.trim(),!!r){if(r.startsWith(":")){const n=r.split("	").slice(-1)[0].slice(c);if(e.has(n))return;i.has(n)&&i.delete(n),e.set(n,new Date(s*1e3).toISOString())}else s=Number(r);i.size===0&&(o.kill(),t(e))}})}o.stdout.on("data",f=>{m(f)}),o.stdout.on("end",()=>{m(""),o.kill(),t(e)})})}export{v as fastMtime};
