just-git 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
- var ye=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});function tn(n){if(n==="")return".";if(n==="/")return"/";let e=n.charCodeAt(0)===47,t=n.charCodeAt(n.length-1)===47,r=n.split("/"),s=[];for(let o of r)o===""||o==="."||(o===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(o));let i=s.join("/");return e&&(i=`/${i}`),t&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":t?"./":".")}function v(...n){if(n.length===0)return".";let e=n.filter(t=>t!=="").join("/");return e===""?".":tn(e)}function ve(n){if(n==="")return".";if(n==="/")return"/";let e=n.length;for(;e>1&&n.charCodeAt(e-1)===47;)e--;let t=n.slice(0,e),r=t.lastIndexOf("/");return r===-1?".":r===0?"/":t.slice(0,r)}var lt=(()=>{let n=new Array(256);for(let e=0;e<256;e++)n[e]=(e>>4).toString(16)+(e&15).toString(16);return n})();function re(n){let e="";for(let t=0;t<20;t++)e+=lt[n[t]];return e}function we(n,e){let t="";for(let r=0;r<20;r++)t+=lt[n[e+r]];return t}function q(n){let e=new Uint8Array(20);for(let t=0;t<20;t++)e[t]=parseInt(n.slice(t*2,t*2+2),16);return e}var nn=new TextEncoder;function Le(n){return typeof n=="string"?nn.encode(n):n}function rn(){if(typeof globalThis.Bun<"u")return()=>{let n=new Bun.CryptoHasher("sha1"),e={update(t){return n.update(Le(t)),e},hex:()=>Promise.resolve(n.digest("hex"))};return e};try{let n=ye(["node","crypto"].join(":"));if(typeof n.createHash=="function")return()=>{let e=n.createHash("sha1"),t={update(r){return e.update(Le(r)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let n=[],e={update(t){return n.push(Le(t)),e},async hex(){let t=0;for(let o of n)t+=o.byteLength;let r=new Uint8Array(t),s=0;for(let o of n)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return re(new Uint8Array(i))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var ut=rn(),Ie=ut;async function xe(n){return ut().update(n).hex()}var sn=1145655875,on=2;async function Ue(n,e){let t=v(n.gitDir,"index"),r=await an(e);await n.fs.writeFile(t,r)}function ht(n){let e=[...n].sort(dt);return{version:on,entries:e}}function Q(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function an(n){let e=[...n.entries].sort(dt),t=12;for(let l of e){let u=62+l.path.length+1;t+=Math.ceil(u/8)*8}t+=20;let r=new ArrayBuffer(t),s=new Uint8Array(r),i=new DataView(r),o=0;i.setUint32(o,sn),o+=4,i.setUint32(o,n.version),o+=4,i.setUint32(o,e.length),o+=4;for(let l of e){let u=o;i.setUint32(o,l.stat.ctimeSeconds),i.setUint32(o+4,l.stat.ctimeNanoseconds),i.setUint32(o+8,l.stat.mtimeSeconds),i.setUint32(o+12,l.stat.mtimeNanoseconds),i.setUint32(o+16,l.stat.dev),i.setUint32(o+20,l.stat.ino),i.setUint32(o+24,l.mode),i.setUint32(o+28,l.stat.uid),i.setUint32(o+32,l.stat.gid),i.setUint32(o+36,l.stat.size),o+=40;let d=q(l.hash);s.set(d,o),o+=20;let h=Math.min(l.path.length,4095),m=(l.stage&3)<<12|h;i.setUint16(o,m),o+=2;let b=new TextEncoder().encode(l.path);s.set(b,o),o+=b.byteLength,s[o]=0,o+=1;let g=62+b.byteLength+1,w=Math.ceil(g/8)*8;o=u+w}let a=s.subarray(0,o),c=await xe(a),f=q(c);return s.set(f,o),s}function dt(n,e){return n.path<e.path?-1:n.path>e.path?1:n.stage-e.stage}var cn=new Set(["tree","commit","tag"]),Oe=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,t){if(!cn.has(t.type))return;let r=t.content.byteLength;if(!(r>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+r>this.maxBytes&&this.map.size>0;){let s=this.map.keys().next().value;this.currentBytes-=this.map.get(s).content.byteLength,this.map.delete(s)}this.map.set(e,t),this.currentBytes+=r}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var mt=new Uint32Array(256);for(let n=0;n<256;n++){let e=n;for(let t=0;t<8;t++)e=e&1?3988292384^e>>>1:e>>>1;mt[n]=e}function pt(n){let e=4294967295;for(let t=0;t<n.byteLength;t++)e=mt[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}async function fn(){let n;try{n=ye(["node","zlib"].join(":"))}catch{try{n=await import(["node","zlib"].join(":"))}catch{}}if(n&&typeof n.deflateSync=="function"&&typeof n.inflateSync=="function"){let e;try{let t=n.inflateSync(n.deflateSync(Buffer.from("x")),{info:!0});t?.engine&&typeof t.engine.bytesWritten=="number"&&(e=r=>{let s=n.inflateSync(r,{info:!0});return{result:new Uint8Array(s.buffer),bytesConsumed:s.engine.bytesWritten}})}catch{}return{deflateSync:t=>new Uint8Array(n.deflateSync(t)),inflateSync:t=>new Uint8Array(n.inflateSync(t)),inflateWithConsumed:e}}if(typeof globalThis.CompressionStream=="function"&&typeof globalThis.DecompressionStream=="function")return{async deflateSync(e){let t=new CompressionStream("deflate"),r=t.writable.getWriter();return r.write(e),r.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())},async inflateSync(e){let t=new DecompressionStream("deflate"),r=t.writable.getWriter();return r.write(e),r.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())}};throw new Error("No zlib implementation available. Requires Bun, Node.js, Deno, or a browser with CompressionStream.")}var ln=null;function Be(){return ln??=fn()}async function De(n){return await(await Be()).deflateSync(n)}async function oe(n){return await(await Be()).inflateSync(n)}async function gt(n,e){let t=await Be();if(t.inflateWithConsumed){let{result:o,bytesConsumed:a}=t.inflateWithConsumed(n);if(o.byteLength!==e)throw new Error(`Inflate size mismatch: got ${o.byteLength}, expected ${e}`);return{result:o,bytesConsumed:a}}let r=await t.inflateSync(n);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);let s=2,i=n.byteLength;for(;s<i;){let o=s+i>>>1;try{(await t.inflateSync(n.subarray(0,o))).byteLength===e?i=o:s=o+1}catch{s=o+1}}return{result:r,bytesConsumed:s}}var bt=1346454347,un=2,hn=1,dn=2,mn=3,pn=4,Pe=6,Ne=7,gn={[hn]:"commit",[dn]:"tree",[mn]:"blob",[pn]:"tag"};async function wt(n,e){let t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=t.getUint32(0);if(r!==bt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${bt.toString(16)})`);let s=t.getUint32(4);if(s!==un)throw new Error(`Unsupported pack version: ${s}`);let i=t.getUint32(8),o=[],a=12;for(let f=0;f<i;f++){let l=await bn(n,a);o.push(l),a=l.nextOffset}return(await yn(o,e)).map((f,l)=>({...f,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function bn(n,e){let t=e,r=n[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=n[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Pe){let u=n[e++];for(a=u&127;u&128;)a+=1,u=n[e++],a=(a<<7)+(u&127);a=t-a}else s===Ne&&(c=we(n,e),e+=20);let{result:f,bytesConsumed:l}=await gt(n.subarray(e),i);return{headerOffset:t,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+l}}async function yn(n,e){let t=new Map;for(let i=0;i<n.length;i++)t.set(n[i].headerOffset,i);let r=new Array(n.length).fill(null);async function s(i){let o=r[i];if(o)return o;let a=n[i];if(a.typeNum!==Pe&&a.typeNum!==Ne){let d=gn[a.typeNum];if(!d)throw new Error(`Unknown object type: ${a.typeNum}`);let h={type:d,content:a.inflated,hash:await He(d,a.inflated)};return r[i]=h,h}if(a.typeNum===Pe){let d=t.get(a.baseOffset);if(d===void 0)throw new Error(`OFS_DELTA base not found at offset ${a.baseOffset}`);let h=await s(d),m=he(h.content,a.inflated),b={type:h.type,content:m,hash:await He(h.type,m)};return r[i]=b,b}let c=await wn(n,r,a.baseHash,s),f;if(c!==void 0)f=await s(c);else if(e){let d=await e(a.baseHash);d&&(f=d)}if(!f)throw new Error(`REF_DELTA base not found for hash ${a.baseHash}`);let l=he(f.content,a.inflated),u={type:f.type,content:l,hash:await He(f.type,l)};return r[i]=u,u}for(let i=0;i<n.length;i++)await s(i);return r}async function wn(n,e,t,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===t)return s;for(let s=0;s<n.length;s++){let i=n[s];if(i.typeNum!==Pe&&i.typeNum!==Ne&&(await r(s)).hash===t)return s}}function he(n,e){let t=0,{value:r,newPos:s}=yt(e,t);if(t=s,r!==n.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${n.byteLength}`);let{value:i,newPos:o}=yt(e,t);t=o;let a=new Uint8Array(i),c=0;for(;t<e.byteLength;){let f=e[t++];if(f&128){let l=0,u=0;f&1&&(l=e[t++]),f&2&&(l|=e[t++]<<8),f&4&&(l|=e[t++]<<16),f&8&&(l|=e[t++]<<24),f&16&&(u=e[t++]),f&32&&(u|=e[t++]<<8),f&64&&(u|=e[t++]<<16),u===0&&(u=65536),a.set(n.subarray(l,l+u),c),c+=u}else if(f>0)a.set(e.subarray(t,t+f),c),c+=f,t+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return a}function yt(n,e){let t=0,r=0,s;do s=n[e++],t|=(s&127)<<r,r+=7;while(s&128);return{value:t,newPos:e}}var In=new TextEncoder;async function He(n,e){let t=In.encode(`${n} ${e.byteLength}\0`),r=Ie();return r.update(t),r.update(e),r.hex()}var It=4285812579,xt=2,ee=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0)!==It)throw new Error("Invalid pack index: bad magic");if(t.getUint32(4)!==xt)throw new Error(`Unsupported pack index version: ${t.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let i=0;i<256;i++)this.fanout[i]=t.getUint32(r),r+=4;this.count=this.fanout[255],this.hashes=new Uint8Array(e.buffer,e.byteOffset+r,this.count*20),r+=this.count*20,r+=this.count*4,this.offsets=new Uint32Array(this.count);for(let i=0;i<this.count;i++)this.offsets[i]=t.getUint32(r),r+=4;let s=!1;for(let i=0;i<this.count;i++)if(this.offsets[i]&2147483648){s=!0;break}this.largeOffsets=s?new DataView(e.buffer,e.byteOffset+r):null}lookup(e){let t=q(e),r=t[0],s=r===0?0:this.fanout[r-1],i=this.fanout[r],o=s,a=i;for(;o<a;){let c=o+a>>>1,f=this.compareAt(c,t);if(f<0)o=c+1;else if(f>0)a=c;else return this.getOffset(c)}return null}has(e){return this.lookup(e)!==null}get objectCount(){return this.count}allHashes(){let e=[];for(let t=0;t<this.count;t++)e.push(this.hashAtSlot(t));return e}findByPrefix(e){if(e.length<2)return[];let t=parseInt(e.slice(0,2),16),r=t===0?0:this.fanout[t-1],s=this.fanout[t],i=q(e.padEnd(40,"0")),o=e.length,a=[];for(let c=r;c<s;c++){let f=c*20,l=!0;for(let u=0;u<o;u++){let d=u%2===0?this.hashes[f+(u>>1)]>>4&15:this.hashes[f+(u>>1)]&15,h=u%2===0?i[u>>1]>>4&15:i[u>>1]&15;if(d!==h){l=!1;break}}l&&a.push(this.hashAtSlot(c))}return a}hashAtSlot(e){let t="",r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s];t+=(i>>4).toString(16)+(i&15).toString(16)}return t}compareAt(e,t){let r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s],o=t[s];if(i<o)return-1;if(i>o)return 1}return 0}getOffset(e){let t=this.offsets[e];if(t&2147483648){let r=t&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return t}};async function xn(n,e){let t=[...n].sort((h,m)=>h.hash<m.hash?-1:h.hash>m.hash?1:0),r=t.length,s=[];for(let h of t)h.offset>=2147483648&&s.push(BigInt(h.offset));let i=8+256*4+r*20+r*4+r*4+s.length*8+20+20,o=new Uint8Array(i),a=new DataView(o.buffer),c=0;a.setUint32(c,It),c+=4,a.setUint32(c,xt),c+=4;let f=new Uint32Array(256);for(let h of t){let m=parseInt(h.hash.slice(0,2),16);for(let b=m;b<256;b++)f[b]++}for(let h=0;h<256;h++)a.setUint32(c,f[h]),c+=4;for(let h of t)o.set(q(h.hash),c),c+=20;for(let h of t)a.setUint32(c,h.crc),c+=4;let l=0;for(let h of t)h.offset>=2147483648?a.setUint32(c,2147483648|l++):a.setUint32(c,h.offset),c+=4;for(let h of s)a.setBigUint64(c,h),c+=8;o.set(e,c),c+=20;let u=Ie();u.update(o.subarray(0,c));let d=await u.hex();return o.set(q(d),c),o}async function Ot(n){let t=(await wt(n)).map(s=>({hash:s.hash,offset:s.offset,crc:pt(n.subarray(s.offset,s.nextOffset))})),r=n.subarray(n.byteLength-20);return xn(t,r)}var On=6,Pn=7,Rn={1:"commit",2:"tree",3:"blob",4:"tag"},de=class{constructor(e,t){this.data=e;this.index=t instanceof ee?t:new ee(t)}index;hasObject(e){return this.index.has(e)}findByPrefix(e){return this.index.findByPrefix(e)}async readObject(e){let t=this.index.lookup(e);return t===null?null:this.readAt(t)}get objectCount(){return this.index.objectCount}async readAt(e){let t=this.data,r=e,s=t[r++],i=s>>4&7,o=s&15,a=4;for(;s&128;)s=t[r++],o|=(s&127)<<a,a+=7;if(i===On){let l=t[r++],u=l&127;for(;l&128;)u+=1,l=t[r++],u=(u<<7)+(l&127);let d=await oe(t.subarray(r)),h=await this.readAt(e-u);return{type:h.type,content:he(h.content,d)}}if(i===Pn){let l=we(t,r);r+=20;let u=await oe(t.subarray(r)),d=this.index.lookup(l);if(d===null)throw new Error(`REF_DELTA base ${l} not found in pack`);let h=await this.readAt(d);return{type:h.type,content:he(h.content,u)}}let c=Rn[i];if(!c)throw new Error(`Unknown pack object type: ${i}`);let f=await oe(t.subarray(r));if(f.byteLength!==o)throw new Error(`Pack inflate size mismatch at offset ${e}: got ${f.byteLength}, expected ${o}`);return{type:c,content:f}}};var kn=new TextEncoder,En=new TextDecoder;function Tn(n,e){let t=kn.encode(`${n} ${e.byteLength}\0`),r=new Uint8Array(t.byteLength+e.byteLength);return r.set(t),r.set(e,t.byteLength),r}function Sn(n,e){let t=e.indexOf(0);if(t===-1)throw new Error(`Corrupt object ${n}: no null byte in header`);let r=En.decode(e.subarray(0,t)),s=r.indexOf(" ");if(s===-1)throw new Error(`Corrupt object ${n}: malformed header "${r}"`);let i=r.slice(0,s),o=parseInt(r.slice(s+1),10),a=e.subarray(t+1);if(a.byteLength!==o)throw new Error(`Corrupt object ${n}: expected ${o} bytes, got ${a.byteLength}`);return{type:i,content:a}}function Fe(n,e){return v(n,"objects",e.slice(0,2),e.slice(2))}var Ge=class{constructor(e,t,r){this.fs=e;this.gitDir=t;this.cache=new Oe(r),this.packDir=v(t,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(e,t){let r=Tn(e,t),s=await xe(r),i=Fe(this.gitDir,s);if(await this.fs.exists(i))return s;let o=v(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(o,{recursive:!0}),await this.fs.writeFile(i,await De(r)),s}async read(e){let t=this.cache.get(e);if(t)return t;let r=Fe(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await oe(s),o=Sn(e,i);return this.cache.set(e,o),o}await this.discover();for(let s of this.packs){if(!s.index.has(e))continue;let o=await(await this.ensureReader(s)).readObject(e);if(o)return this.cache.set(e,o),o}throw new Error(`object ${e} not found`)}async exists(e){if(await this.fs.exists(Fe(this.gitDir,e)))return!0;await this.discover();for(let t of this.packs)if(t.index.has(e))return!0;return!1}async ingestPack(e){if(e.byteLength<32)return 0;let r=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8);if(r===0)return 0;let s=e.subarray(e.byteLength-20),i=re(s);await this.fs.mkdir(this.packDir,{recursive:!0});let o=`pack-${i}`,a=v(this.packDir,`${o}.pack`);await this.fs.writeFile(a,e);let c=await Ot(e),f=v(this.packDir,`${o}.idx`);await this.fs.writeFile(f,c),this.loadedPackNames.add(o);let l=new ee(c);return this.packs.push({name:o,index:l,reader:new de(e,l)}),r}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(e){if(e.length<4)return[];let t=e.slice(0,2),r=e.slice(2),s=v(this.gitDir,"objects",t),i=[];if(await this.fs.exists(s)){let o=await this.fs.readdir(s);for(let a of o)a.startsWith(r)&&i.push(`${t}${a}`)}await this.discover();for(let o of this.packs)for(let a of o.index.findByPrefix(e))i.includes(a)||i.push(a);return i}async ensureReader(e){if(e.reader)return e.reader;let t=v(this.packDir,`${e.name}.pack`),r=await this.fs.readFileBuffer(t);return e.reader=new de(r,e.index),e.reader}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){if(!await this.fs.exists(this.packDir))return;let e=await this.fs.readdir(this.packDir);for(let t of e){if(!t.endsWith(".idx"))continue;let r=t.slice(0,-4);if(this.loadedPackNames.has(r))continue;let s=v(this.packDir,`${r}.pack`);if(!await this.fs.exists(s))continue;let i=await this.fs.readFileBuffer(v(this.packDir,t));this.loadedPackNames.add(r),this.packs.push({name:r,index:new ee(i),reader:null})}}};function _e(n){let e=n.indexOf("<"),t=n.indexOf(">");if(e===-1||t===-1)throw new Error(`Malformed identity line: "${n}"`);let r=n.slice(0,e).trimEnd(),s=n.slice(e+1,t),i=n.slice(t+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function We(n){return`${n.name} <${n.email}> ${n.timestamp} ${n.timezone}`}var jn=new TextEncoder,Cn=new TextDecoder;function Pt(n){let e=Cn.decode(n),t=e.indexOf(`
1
+ var ye=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});function nn(n){if(n==="")return".";if(n==="/")return"/";let e=n.charCodeAt(0)===47,t=n.charCodeAt(n.length-1)===47,r=n.split("/"),s=[];for(let o of r)o===""||o==="."||(o===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(o));let i=s.join("/");return e&&(i=`/${i}`),t&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":t?"./":".")}function v(...n){if(n.length===0)return".";let e=n.filter(t=>t!=="").join("/");return e===""?".":nn(e)}function Ue(n){if(n==="")return".";if(n==="/")return"/";let e=n.length;for(;e>1&&n.charCodeAt(e-1)===47;)e--;let t=n.slice(0,e),r=t.lastIndexOf("/");return r===-1?".":r===0?"/":t.slice(0,r)}var ut=(()=>{let n=new Array(256);for(let e=0;e<256;e++)n[e]=(e>>4).toString(16)+(e&15).toString(16);return n})();function re(n){let e="";for(let t=0;t<20;t++)e+=ut[n[t]];return e}function we(n,e){let t="";for(let r=0;r<20;r++)t+=ut[n[e+r]];return t}function q(n){let e=new Uint8Array(20);for(let t=0;t<20;t++)e[t]=parseInt(n.slice(t*2,t*2+2),16);return e}var rn=new TextEncoder;function Be(n){return typeof n=="string"?rn.encode(n):n}function sn(){if(typeof globalThis.Bun<"u")return()=>{let n=new Bun.CryptoHasher("sha1"),e={update(t){return n.update(Be(t)),e},hex:()=>Promise.resolve(n.digest("hex"))};return e};try{let n=ye(["node","crypto"].join(":"));if(typeof n.createHash=="function")return()=>{let e=n.createHash("sha1"),t={update(r){return e.update(Be(r)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let n=[],e={update(t){return n.push(Be(t)),e},async hex(){let t=0;for(let o of n)t+=o.byteLength;let r=new Uint8Array(t),s=0;for(let o of n)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return re(new Uint8Array(i))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var ht=sn(),Ie=ht;async function xe(n){return ht().update(n).hex()}var on=1145655875,an=2;async function De(n,e){let t=v(n.gitDir,"index"),r=await cn(e);await n.fs.writeFile(t,r)}function dt(n){let e=[...n].sort(mt);return{version:an,entries:e}}function Q(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function cn(n){let e=[...n.entries].sort(mt),t=12;for(let l of e){let u=62+l.path.length+1;t+=Math.ceil(u/8)*8}t+=20;let r=new ArrayBuffer(t),s=new Uint8Array(r),i=new DataView(r),o=0;i.setUint32(o,on),o+=4,i.setUint32(o,n.version),o+=4,i.setUint32(o,e.length),o+=4;for(let l of e){let u=o;i.setUint32(o,l.stat.ctimeSeconds),i.setUint32(o+4,l.stat.ctimeNanoseconds),i.setUint32(o+8,l.stat.mtimeSeconds),i.setUint32(o+12,l.stat.mtimeNanoseconds),i.setUint32(o+16,l.stat.dev),i.setUint32(o+20,l.stat.ino),i.setUint32(o+24,l.mode),i.setUint32(o+28,l.stat.uid),i.setUint32(o+32,l.stat.gid),i.setUint32(o+36,l.stat.size),o+=40;let d=q(l.hash);s.set(d,o),o+=20;let h=Math.min(l.path.length,4095),m=(l.stage&3)<<12|h;i.setUint16(o,m),o+=2;let b=new TextEncoder().encode(l.path);s.set(b,o),o+=b.byteLength,s[o]=0,o+=1;let g=62+b.byteLength+1,w=Math.ceil(g/8)*8;o=u+w}let a=s.subarray(0,o),c=await xe(a),f=q(c);return s.set(f,o),s}function mt(n,e){return n.path<e.path?-1:n.path>e.path?1:n.stage-e.stage}var fn=new Set(["tree","commit","tag"]),Oe=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,t){if(!fn.has(t.type))return;let r=t.content.byteLength;if(!(r>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+r>this.maxBytes&&this.map.size>0;){let s=this.map.keys().next().value;this.currentBytes-=this.map.get(s).content.byteLength,this.map.delete(s)}this.map.set(e,t),this.currentBytes+=r}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var pt=new Uint32Array(256);for(let n=0;n<256;n++){let e=n;for(let t=0;t<8;t++)e=e&1?3988292384^e>>>1:e>>>1;pt[n]=e}function gt(n){let e=4294967295;for(let t=0;t<n.byteLength;t++)e=pt[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}async function ln(){let n;try{n=ye(["node","zlib"].join(":"))}catch{try{n=await import(["node","zlib"].join(":"))}catch{}}if(n&&typeof n.deflateSync=="function"&&typeof n.inflateSync=="function"){let e;try{let t=n.inflateSync(n.deflateSync(Buffer.from("x")),{info:!0});t?.engine&&typeof t.engine.bytesWritten=="number"&&(e=r=>{let s=n.inflateSync(r,{info:!0});return{result:new Uint8Array(s.buffer),bytesConsumed:s.engine.bytesWritten}})}catch{}return{deflateSync:t=>new Uint8Array(n.deflateSync(t)),inflateSync:t=>new Uint8Array(n.inflateSync(t)),inflateWithConsumed:e}}if(typeof globalThis.CompressionStream=="function"&&typeof globalThis.DecompressionStream=="function")return{async deflateSync(e){let t=new CompressionStream("deflate"),r=t.writable.getWriter();return r.write(e),r.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())},async inflateSync(e){let t=new DecompressionStream("deflate"),r=t.writable.getWriter();return r.write(e),r.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())}};throw new Error("No zlib implementation available. Requires Bun, Node.js, Deno, or a browser with CompressionStream.")}var un=null;function He(){return un??=ln()}async function Ne(n){return await(await He()).deflateSync(n)}async function oe(n){return await(await He()).inflateSync(n)}async function bt(n,e){let t=await He();if(t.inflateWithConsumed){let{result:o,bytesConsumed:a}=t.inflateWithConsumed(n);if(o.byteLength!==e)throw new Error(`Inflate size mismatch: got ${o.byteLength}, expected ${e}`);return{result:o,bytesConsumed:a}}let r=await t.inflateSync(n);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);let s=2,i=n.byteLength;for(;s<i;){let o=s+i>>>1;try{(await t.inflateSync(n.subarray(0,o))).byteLength===e?i=o:s=o+1}catch{s=o+1}}return{result:r,bytesConsumed:s}}var yt=1346454347,hn=2,dn=1,mn=2,pn=3,gn=4,Pe=6,Ge=7,bn={[dn]:"commit",[mn]:"tree",[pn]:"blob",[gn]:"tag"};async function It(n,e){let t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=t.getUint32(0);if(r!==yt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${yt.toString(16)})`);let s=t.getUint32(4);if(s!==hn)throw new Error(`Unsupported pack version: ${s}`);let i=t.getUint32(8),o=[],a=12;for(let f=0;f<i;f++){let l=await yn(n,a);o.push(l),a=l.nextOffset}return(await wn(o,e)).map((f,l)=>({...f,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function yn(n,e){let t=e,r=n[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=n[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Pe){let u=n[e++];for(a=u&127;u&128;)a+=1,u=n[e++],a=(a<<7)+(u&127);a=t-a}else s===Ge&&(c=we(n,e),e+=20);let{result:f,bytesConsumed:l}=await bt(n.subarray(e),i);return{headerOffset:t,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+l}}async function wn(n,e){let t=new Map;for(let i=0;i<n.length;i++)t.set(n[i].headerOffset,i);let r=new Array(n.length).fill(null);async function s(i){let o=r[i];if(o)return o;let a=n[i];if(a.typeNum!==Pe&&a.typeNum!==Ge){let d=bn[a.typeNum];if(!d)throw new Error(`Unknown object type: ${a.typeNum}`);let h={type:d,content:a.inflated,hash:await Fe(d,a.inflated)};return r[i]=h,h}if(a.typeNum===Pe){let d=t.get(a.baseOffset);if(d===void 0)throw new Error(`OFS_DELTA base not found at offset ${a.baseOffset}`);let h=await s(d),m=he(h.content,a.inflated),b={type:h.type,content:m,hash:await Fe(h.type,m)};return r[i]=b,b}let c=await In(n,r,a.baseHash,s),f;if(c!==void 0)f=await s(c);else if(e){let d=await e(a.baseHash);d&&(f=d)}if(!f)throw new Error(`REF_DELTA base not found for hash ${a.baseHash}`);let l=he(f.content,a.inflated),u={type:f.type,content:l,hash:await Fe(f.type,l)};return r[i]=u,u}for(let i=0;i<n.length;i++)await s(i);return r}async function In(n,e,t,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===t)return s;for(let s=0;s<n.length;s++){let i=n[s];if(i.typeNum!==Pe&&i.typeNum!==Ge&&(await r(s)).hash===t)return s}}function he(n,e){let t=0,{value:r,newPos:s}=wt(e,t);if(t=s,r!==n.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${n.byteLength}`);let{value:i,newPos:o}=wt(e,t);t=o;let a=new Uint8Array(i),c=0;for(;t<e.byteLength;){let f=e[t++];if(f&128){let l=0,u=0;f&1&&(l=e[t++]),f&2&&(l|=e[t++]<<8),f&4&&(l|=e[t++]<<16),f&8&&(l|=e[t++]<<24),f&16&&(u=e[t++]),f&32&&(u|=e[t++]<<8),f&64&&(u|=e[t++]<<16),u===0&&(u=65536),a.set(n.subarray(l,l+u),c),c+=u}else if(f>0)a.set(e.subarray(t,t+f),c),c+=f,t+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return a}function wt(n,e){let t=0,r=0,s;do s=n[e++],t|=(s&127)<<r,r+=7;while(s&128);return{value:t,newPos:e}}var xn=new TextEncoder;async function Fe(n,e){let t=xn.encode(`${n} ${e.byteLength}\0`),r=Ie();return r.update(t),r.update(e),r.hex()}var xt=4285812579,Ot=2,ee=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0)!==xt)throw new Error("Invalid pack index: bad magic");if(t.getUint32(4)!==Ot)throw new Error(`Unsupported pack index version: ${t.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let i=0;i<256;i++)this.fanout[i]=t.getUint32(r),r+=4;this.count=this.fanout[255],this.hashes=new Uint8Array(e.buffer,e.byteOffset+r,this.count*20),r+=this.count*20,r+=this.count*4,this.offsets=new Uint32Array(this.count);for(let i=0;i<this.count;i++)this.offsets[i]=t.getUint32(r),r+=4;let s=!1;for(let i=0;i<this.count;i++)if(this.offsets[i]&2147483648){s=!0;break}this.largeOffsets=s?new DataView(e.buffer,e.byteOffset+r):null}lookup(e){let t=q(e),r=t[0],s=r===0?0:this.fanout[r-1],i=this.fanout[r],o=s,a=i;for(;o<a;){let c=o+a>>>1,f=this.compareAt(c,t);if(f<0)o=c+1;else if(f>0)a=c;else return this.getOffset(c)}return null}has(e){return this.lookup(e)!==null}get objectCount(){return this.count}allHashes(){let e=[];for(let t=0;t<this.count;t++)e.push(this.hashAtSlot(t));return e}findByPrefix(e){if(e.length<2)return[];let t=parseInt(e.slice(0,2),16),r=t===0?0:this.fanout[t-1],s=this.fanout[t],i=q(e.padEnd(40,"0")),o=e.length,a=[];for(let c=r;c<s;c++){let f=c*20,l=!0;for(let u=0;u<o;u++){let d=u%2===0?this.hashes[f+(u>>1)]>>4&15:this.hashes[f+(u>>1)]&15,h=u%2===0?i[u>>1]>>4&15:i[u>>1]&15;if(d!==h){l=!1;break}}l&&a.push(this.hashAtSlot(c))}return a}hashAtSlot(e){let t="",r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s];t+=(i>>4).toString(16)+(i&15).toString(16)}return t}compareAt(e,t){let r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s],o=t[s];if(i<o)return-1;if(i>o)return 1}return 0}getOffset(e){let t=this.offsets[e];if(t&2147483648){let r=t&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return t}};async function On(n,e){let t=[...n].sort((h,m)=>h.hash<m.hash?-1:h.hash>m.hash?1:0),r=t.length,s=[];for(let h of t)h.offset>=2147483648&&s.push(BigInt(h.offset));let i=8+256*4+r*20+r*4+r*4+s.length*8+20+20,o=new Uint8Array(i),a=new DataView(o.buffer),c=0;a.setUint32(c,xt),c+=4,a.setUint32(c,Ot),c+=4;let f=new Uint32Array(256);for(let h of t){let m=parseInt(h.hash.slice(0,2),16);for(let b=m;b<256;b++)f[b]++}for(let h=0;h<256;h++)a.setUint32(c,f[h]),c+=4;for(let h of t)o.set(q(h.hash),c),c+=20;for(let h of t)a.setUint32(c,h.crc),c+=4;let l=0;for(let h of t)h.offset>=2147483648?a.setUint32(c,2147483648|l++):a.setUint32(c,h.offset),c+=4;for(let h of s)a.setBigUint64(c,h),c+=8;o.set(e,c),c+=20;let u=Ie();u.update(o.subarray(0,c));let d=await u.hex();return o.set(q(d),c),o}async function Pt(n){let t=(await It(n)).map(s=>({hash:s.hash,offset:s.offset,crc:gt(n.subarray(s.offset,s.nextOffset))})),r=n.subarray(n.byteLength-20);return On(t,r)}var Pn=6,Rn=7,kn={1:"commit",2:"tree",3:"blob",4:"tag"},de=class{constructor(e,t){this.data=e;this.index=t instanceof ee?t:new ee(t)}index;hasObject(e){return this.index.has(e)}findByPrefix(e){return this.index.findByPrefix(e)}async readObject(e){let t=this.index.lookup(e);return t===null?null:this.readAt(t)}get objectCount(){return this.index.objectCount}async readAt(e){let t=this.data,r=e,s=t[r++],i=s>>4&7,o=s&15,a=4;for(;s&128;)s=t[r++],o|=(s&127)<<a,a+=7;if(i===Pn){let l=t[r++],u=l&127;for(;l&128;)u+=1,l=t[r++],u=(u<<7)+(l&127);let d=await oe(t.subarray(r)),h=await this.readAt(e-u);return{type:h.type,content:he(h.content,d)}}if(i===Rn){let l=we(t,r);r+=20;let u=await oe(t.subarray(r)),d=this.index.lookup(l);if(d===null)throw new Error(`REF_DELTA base ${l} not found in pack`);let h=await this.readAt(d);return{type:h.type,content:he(h.content,u)}}let c=kn[i];if(!c)throw new Error(`Unknown pack object type: ${i}`);let f=await oe(t.subarray(r));if(f.byteLength!==o)throw new Error(`Pack inflate size mismatch at offset ${e}: got ${f.byteLength}, expected ${o}`);return{type:c,content:f}}};var En=new TextEncoder,Tn=new TextDecoder;function Sn(n,e){let t=En.encode(`${n} ${e.byteLength}\0`),r=new Uint8Array(t.byteLength+e.byteLength);return r.set(t),r.set(e,t.byteLength),r}function jn(n,e){let t=e.indexOf(0);if(t===-1)throw new Error(`Corrupt object ${n}: no null byte in header`);let r=Tn.decode(e.subarray(0,t)),s=r.indexOf(" ");if(s===-1)throw new Error(`Corrupt object ${n}: malformed header "${r}"`);let i=r.slice(0,s),o=parseInt(r.slice(s+1),10),a=e.subarray(t+1);if(a.byteLength!==o)throw new Error(`Corrupt object ${n}: expected ${o} bytes, got ${a.byteLength}`);return{type:i,content:a}}function _e(n,e){return v(n,"objects",e.slice(0,2),e.slice(2))}var We=class{constructor(e,t,r){this.fs=e;this.gitDir=t;this.cache=new Oe(r),this.packDir=v(t,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(e,t){let r=Sn(e,t),s=await xe(r),i=_e(this.gitDir,s);if(await this.fs.exists(i))return s;let o=v(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(o,{recursive:!0}),await this.fs.writeFile(i,await Ne(r)),s}async read(e){let t=this.cache.get(e);if(t)return t;let r=_e(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await oe(s),o=jn(e,i);return this.cache.set(e,o),o}await this.discover();for(let s of this.packs){if(!s.index.has(e))continue;let o=await(await this.ensureReader(s)).readObject(e);if(o)return this.cache.set(e,o),o}throw new Error(`object ${e} not found`)}async exists(e){if(await this.fs.exists(_e(this.gitDir,e)))return!0;await this.discover();for(let t of this.packs)if(t.index.has(e))return!0;return!1}async ingestPack(e){if(e.byteLength<32)return 0;let r=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8);if(r===0)return 0;let s=e.subarray(e.byteLength-20),i=re(s);await this.fs.mkdir(this.packDir,{recursive:!0});let o=`pack-${i}`,a=v(this.packDir,`${o}.pack`);await this.fs.writeFile(a,e);let c=await Pt(e),f=v(this.packDir,`${o}.idx`);await this.fs.writeFile(f,c),this.loadedPackNames.add(o);let l=new ee(c);return this.packs.push({name:o,index:l,reader:new de(e,l)}),r}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(e){if(e.length<4)return[];let t=e.slice(0,2),r=e.slice(2),s=v(this.gitDir,"objects",t),i=[];if(await this.fs.exists(s)){let o=await this.fs.readdir(s);for(let a of o)a.startsWith(r)&&i.push(`${t}${a}`)}await this.discover();for(let o of this.packs)for(let a of o.index.findByPrefix(e))i.includes(a)||i.push(a);return i}async ensureReader(e){if(e.reader)return e.reader;let t=v(this.packDir,`${e.name}.pack`),r=await this.fs.readFileBuffer(t);return e.reader=new de(r,e.index),e.reader}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){if(!await this.fs.exists(this.packDir))return;let e=await this.fs.readdir(this.packDir);for(let t of e){if(!t.endsWith(".idx"))continue;let r=t.slice(0,-4);if(this.loadedPackNames.has(r))continue;let s=v(this.packDir,`${r}.pack`);if(!await this.fs.exists(s))continue;let i=await this.fs.readFileBuffer(v(this.packDir,t));this.loadedPackNames.add(r),this.packs.push({name:r,index:new ee(i),reader:null})}}};function ze(n){let e=n.indexOf("<"),t=n.indexOf(">");if(e===-1||t===-1)throw new Error(`Malformed identity line: "${n}"`);let r=n.slice(0,e).trimEnd(),s=n.slice(e+1,t),i=n.slice(t+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function Ve(n){return`${n.name} <${n.email}> ${n.timestamp} ${n.timezone}`}var Cn=new TextEncoder,An=new TextDecoder;function Rt(n){let e=An.decode(n),t=e.indexOf(`
2
2
 
3
3
  `),r=t===-1?e:e.slice(0,t),s=t===-1?"":e.slice(t+2),i="",o=[],a,c;for(let f of r.split(`
4
- `)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),d=f.slice(l+1);switch(u){case"tree":i=d;break;case"parent":o.push(d);break;case"author":a=_e(d);break;case"committer":c=_e(d);break}}if(!i)throw new Error("Commit missing tree field");if(!a)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:o,author:a,committer:c,message:s}}function Re(n){let e=[];e.push(`tree ${n.tree}`);for(let t of n.parents)e.push(`parent ${t}`);return e.push(`author ${We(n.author)}`),e.push(`committer ${We(n.committer)}`),e.push(""),e.push(n.message),jn.encode(e.join(`
5
- `))}async function N(n,e,t){let r=await n.objectStore.write(e,t);return n.hooks?.onObjectWrite?.({repo:n,type:e,hash:r}),r}async function V(n,e){return n.objectStore.read(e)}function J(n){let e=Math.min(n.length,8e3);for(let t=0;t<e;t++)if(n.charCodeAt(t)===0)return!0;return!1}var An=new TextDecoder;async function F(n,e){let t=await V(n,e);if(t.type!=="blob")throw new Error(`Expected blob for ${e}, got ${t.type}`);return An.decode(t.content)}async function Z(n,e){let t=await V(n,e);if(t.type!=="blob")throw new Error(`Expected blob for ${e}, got ${t.type}`);return t.content}async function U(n,e){let t=await V(n,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return Pt(t.content)}var ze="ref: ",Rt=10,Ve=class{constructor(e,t){this.fs=e;this.gitDir=t}casLocks=new Map;async readRef(e){let t=v(this.gitDir,e);if(await this.fs.exists(t)){let i=(await this.fs.readFile(t)).trim();return i.startsWith(ze)?{type:"symbolic",target:i.slice(ze.length)}:{type:"direct",hash:i}}let s=(await this.readPackedRefs()).get(e);return s?{type:"direct",hash:s}:null}async writeRef(e,t){let r=v(this.gitDir,e);await kt(this.fs,r),t.type==="symbolic"?await this.fs.writeFile(r,`${ze}${t.target}
4
+ `)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),d=f.slice(l+1);switch(u){case"tree":i=d;break;case"parent":o.push(d);break;case"author":a=ze(d);break;case"committer":c=ze(d);break}}if(!i)throw new Error("Commit missing tree field");if(!a)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:o,author:a,committer:c,message:s}}function Re(n){let e=[];e.push(`tree ${n.tree}`);for(let t of n.parents)e.push(`parent ${t}`);return e.push(`author ${Ve(n.author)}`),e.push(`committer ${Ve(n.committer)}`),e.push(""),e.push(n.message),Cn.encode(e.join(`
5
+ `))}async function N(n,e,t){let r=await n.objectStore.write(e,t);return n.hooks?.onObjectWrite?.({repo:n,type:e,hash:r}),r}async function V(n,e){return n.objectStore.read(e)}function J(n){let e=Math.min(n.length,8e3);for(let t=0;t<e;t++)if(n.charCodeAt(t)===0)return!0;return!1}var $n=new TextDecoder;async function F(n,e){let t=await V(n,e);if(t.type!=="blob")throw new Error(`Expected blob for ${e}, got ${t.type}`);return $n.decode(t.content)}async function Z(n,e){let t=await V(n,e);if(t.type!=="blob")throw new Error(`Expected blob for ${e}, got ${t.type}`);return t.content}async function U(n,e){let t=await V(n,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return Rt(t.content)}var Ke="ref: ",kt=10,qe=class{constructor(e,t){this.fs=e;this.gitDir=t}casLocks=new Map;async readRef(e){let t=v(this.gitDir,e);if(await this.fs.exists(t)){let i=(await this.fs.readFile(t)).trim();return i.startsWith(Ke)?{type:"symbolic",target:i.slice(Ke.length)}:{type:"direct",hash:i}}let s=(await this.readPackedRefs()).get(e);return s?{type:"direct",hash:s}:null}async writeRef(e,t){let r=v(this.gitDir,e);await Et(this.fs,r),t.type==="symbolic"?await this.fs.writeFile(r,`${Ke}${t.target}
6
6
  `):await this.fs.writeFile(r,`${t.hash}
7
- `)}async deleteRef(e){let t=v(this.gitDir,e);await this.fs.exists(t)&&await this.fs.rm(t),await this.removePackedRef(e)}async listRefs(e="refs"){let t=[],r=v(this.gitDir,e);await this.fs.exists(r)&&await this.walkRefs(r,e,t);let s=await this.readPackedRefs();if(s.size>0){let i=new Set(t.map(a=>a.name)),o=`${e}/`;for(let[a,c]of s)a.startsWith(o)&&!i.has(a)&&t.push({name:a,hash:c})}return t.sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async compareAndSwapRef(e,t,r){let i=(this.casLocks.get(e)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(e,t,r),()=>this.compareAndSwapUnsafe(e,t,r));this.casLocks.set(e,i);try{return await i}finally{this.casLocks.get(e)===i&&this.casLocks.delete(e)}}async compareAndSwapUnsafe(e,t,r){let s=await this.resolveRefInternal(e);if(t===null){if(await this.readRef(e)!==null)return!1}else if(s!==t)return!1;return r===null?await this.deleteRef(e):await this.writeRef(e,r),!0}async resolveRefInternal(e){let t=e;for(let r=0;r<Rt;r++){let s=await this.readRef(t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async readPackedRefs(){let e=v(this.gitDir,"packed-refs");if(!await this.fs.exists(e))return new Map;let t=await this.fs.readFile(e),r=new Map;for(let s of t.split(`
7
+ `)}async deleteRef(e){let t=v(this.gitDir,e);await this.fs.exists(t)&&await this.fs.rm(t),await this.removePackedRef(e)}async listRefs(e="refs"){let t=[],r=v(this.gitDir,e);await this.fs.exists(r)&&await this.walkRefs(r,e,t);let s=await this.readPackedRefs();if(s.size>0){let i=new Set(t.map(a=>a.name)),o=`${e}/`;for(let[a,c]of s)a.startsWith(o)&&!i.has(a)&&t.push({name:a,hash:c})}return t.sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async compareAndSwapRef(e,t,r){let i=(this.casLocks.get(e)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(e,t,r),()=>this.compareAndSwapUnsafe(e,t,r));this.casLocks.set(e,i);try{return await i}finally{this.casLocks.get(e)===i&&this.casLocks.delete(e)}}async compareAndSwapUnsafe(e,t,r){let s=await this.resolveRefInternal(e);if(t===null){if(await this.readRef(e)!==null)return!1}else if(s!==t)return!1;return r===null?await this.deleteRef(e):await this.writeRef(e,r),!0}async resolveRefInternal(e){let t=e;for(let r=0;r<kt;r++){let s=await this.readRef(t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async readPackedRefs(){let e=v(this.gitDir,"packed-refs");if(!await this.fs.exists(e))return new Map;let t=await this.fs.readFile(e),r=new Map;for(let s of t.split(`
8
8
  `)){if(!s||s.startsWith("#")||s.startsWith("^"))continue;let i=s.indexOf(" ");if(i===-1)continue;let o=s.slice(0,i),a=s.slice(i+1).trim();o.length===40&&a&&r.set(a,o)}return r}async removePackedRef(e){let t=v(this.gitDir,"packed-refs");if(!await this.fs.exists(t))return;let s=(await this.fs.readFile(t)).split(`
9
9
  `),i=[],o=!1;for(let c of s){if(o&&c.startsWith("^")){o=!1;continue}if(o=!1,!c||c.startsWith("#")){i.push(c);continue}let f=c.indexOf(" ");if(f!==-1&&c.slice(f+1).trim()===e){o=!0;continue}i.push(c)}i.some(c=>c&&!c.startsWith("#")&&!c.startsWith("^"))?await this.fs.writeFile(t,i.join(`
10
- `)):await this.fs.rm(t)}async walkRefs(e,t,r){let s=await this.fs.readdir(e);for(let i of s){let o=v(e,i),a=`${t}/${i}`,c=await this.fs.stat(o);if(c.isDirectory)await this.walkRefs(o,a,r);else if(c.isFile){let f=await this.resolveRefInternal(a);f&&r.push({name:a,hash:f})}}}};async function $n(n,e){return n.refStore.readRef(e)}async function ke(n,e){let t=e;for(let r=0;r<Rt;r++){let s=await $n(n,t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function Ke(n,e="refs"){return n.refStore.listRefs(e)}async function kt(n,e){let t=e.lastIndexOf("/");if(t>0){let r=e.slice(0,t);await n.mkdir(r,{recursive:!0})}}var vs=new TextEncoder;function Y(n){return typeof n=="string"?n==="120000":n===40960}var Mn=new TextEncoder,Et=new TextDecoder;function Tt(n){let e=[],t=0;for(;t<n.byteLength;){let r=n.indexOf(32,t);if(r===-1)break;let s=Et.decode(n.subarray(t,r)),i=n.indexOf(0,r+1);if(i===-1)break;let o=Et.decode(n.subarray(r+1,i)),a=n.subarray(i+1,i+21),c=re(a),f=s.padStart(6,"0");e.push({mode:f,name:o,hash:c}),t=i+21}return{type:"tree",entries:e}}function Ee(n){let e=[];for(let i of n.entries){let o=i.mode.replace(/^0+/,""),a=Mn.encode(`${o} ${i.name}\0`),c=q(i.hash);e.push(a),e.push(c)}let t=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(t),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}var me={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};async function qe(n,e){return St(n,e,"")}async function St(n,e,t){let r=[],s=new Map;for(let o of e){let a=t?o.path.slice(t.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:vn(o.mode),name:a,hash:o.hash});else{let f=a.slice(0,c),l=s.get(f);l||(l=[],s.set(f,l)),l.push(o)}}for(let[o,a]of s){let c=t?`${t}/${o}`:o,f=await St(n,a,c);r.push({mode:me.DIRECTORY,name:o,hash:f})}r.sort((o,a)=>{let c=o.mode===me.DIRECTORY?`${o.name}/`:o.name,f=a.mode===me.DIRECTORY?`${a.name}/`:a.name;return c<f?-1:c>f?1:0});let i=Ee({type:"tree",entries:r});return N(n,"tree",i)}async function se(n,e,t=""){let r=await V(n,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=Tt(r.content),i=[];for(let o of s.entries){let a=t?`${t}/${o.name}`:o.name;if(o.mode===me.DIRECTORY){let c=await se(n,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function ae(n,e){if(!e)return new Map;let t=await se(n,e);return new Map(t.map(r=>[r.path,r]))}async function Ye(n,e,t){let r=await ae(n,e),s=await ae(n,t),i=[];for(let[o,a]of r){let c=s.get(o);c?(a.hash!==c.hash||a.mode!==c.mode)&&i.push({path:o,status:"modified",oldHash:a.hash,newHash:c.hash,oldMode:a.mode,newMode:c.mode}):i.push({path:o,status:"deleted",oldHash:a.hash,oldMode:a.mode})}for(let[o,a]of s)r.has(o)||i.push({path:o,status:"added",newHash:a.hash,newMode:a.mode});return i.sort((o,a)=>pe(o.path,a.path))}function vn(n){return n.toString(8).padStart(6,"0")}function jt(n){return{stdout:"",stderr:`fatal: ${n}
11
- `,exitCode:128}}var Ws=jt("not a git repository (or any of the parent directories): .git"),zs=jt("this operation must be run in a work tree");function pe(n,e){return n<e?-1:n>e?1:0}var Xe=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let t=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),t.entry}higher(e,t){let r=e.entry.commit.committer.timestamp,s=t.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<t.epoch}siftUp(e){let{heap:t}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(t[e],t[r]))break;[t[r],t[e]]=[t[e],t[r]],e=r}}siftDown(e){let{heap:t}=this,r=t.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(t[i],t[s])&&(s=i),o<r&&this.higher(t[o],t[s])&&(s=o),s===e)break;[t[e],t[s]]=[t[s],t[e]],e=s}}};async function*Je(n,e,t){let r=await Ln(n,t?.exclude),s=new Set(r),i=new Xe,o=Array.isArray(e)?e:[e];for(let a of o)s.has(a)||i.push(await Ct(n,a));for(;i.size>0;){let a=i.pop();if(!s.has(a.hash)){s.add(a.hash),yield a;for(let c of a.commit.parents)s.has(c)||i.push(await Ct(n,c))}}}async function Ln(n,e){if(!e||e.length===0)return new Set;let t=new Set;for await(let r of Je(n,e))t.add(r.hash);return t}async function Ct(n,e){return{hash:e,commit:await U(n,e)}}var Un=4,At=1024,Te=100,Ce=0,Se=1,ce=2;function Qe(n){let e=1;for(;e*e<n;)e++;return e}function Bn(n,e){let t=new Map,r=[],s=new Array(n.length),i=new Array(e.length);for(let o=0;o<n.length;o++){let a=n[o],c=t.get(a);c===void 0&&(c=r.length,t.set(a,c),r.push({len1:0,len2:0})),r[c].len1++,s[o]=c}for(let o=0;o<e.length;o++){let a=e[o],c=t.get(a);c===void 0&&(c=r.length,t.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function Dn(n,e,t,r){let s=0,i=Math.min(e,r);for(;s<i&&n[s]===t[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&n[e-1-a]===t[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function $t(n,e,t,r){e-t>Te&&(t=e-Te),r-e>Te&&(r=e+Te);let s=0,i=1;for(let c=1;e-c>=t;c++){let f=n[e-c];if(f===Ce)s++;else if(f===ce)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let f=n[e+c];if(f===Ce)o++;else if(f===ce)a++;else break}return o===0?!1:(o+=s,a+=i,a*Un<a+o)}function Hn(n,e,t,r,s,i,o,a,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(Qe(e),At);for(let g=i;g<=o;g++){let w=s[n[g]].len2;w===0?l[g]=Ce:w>=d?l[g]=ce:l[g]=Se}let h=Math.min(Qe(r),At);for(let g=i;g<=a;g++){let w=s[t[g]].len1;w===0?u[g]=Ce:w>=h?u[g]=ce:u[g]=Se}let m=[];for(let g=i;g<=o;g++)l[g]===Se||l[g]===ce&&!$t(l,g,i,o)?m.push(g):c[g]=1;let b=[];for(let g=i;g<=a;g++)u[g]===Se||u[g]===ce&&!$t(u,g,i,a)?b.push(g):f[g]=1;return{refIndex1:m,nreff1:m.length,refIndex2:b,nreff2:b.length}}var te=20,Mt=4,Nn=256,Fn=256,je=2147483647;function G(n,e){return n[e]??0}function Gn(n,e,t,r,s,i,o,a,c,f){let l=e-i,u=t-s,d=e-s,h=t-i,m=d-h&1,b=d,g=d,w=h,R=h;o[d]=e,a[h]=t;for(let j=1;;j++){let C=!1;b>l?o[--b-1]=-1:++b,g<u?o[++g+1]=-1:--g;for(let x=g;x>=b;x-=2){let I;G(o,x-1)>=G(o,x+1)?I=G(o,x-1)+1:I=G(o,x+1);let T=I,L=I-x;for(;I<t&&L<i&&n[I]===r[L];)I++,L++;if(I-T>te&&(C=!0),o[x]=I,m&&w<=x&&x<=R&&G(a,x)<=I)return{i1:I,i2:L,minLo:!0,minHi:!0}}w>l?a[--w-1]=je:++w,R<u?a[++R+1]=je:--R;for(let x=R;x>=w;x-=2){let I;G(a,x-1)<G(a,x+1)?I=G(a,x-1):I=G(a,x+1)-1;let T=I,L=I-x;for(;I>e&&L>s&&n[I-1]===r[L-1];)I--,L--;if(T-I>te&&(C=!0),a[x]=I,!m&&b<=x&&x<=g&&I<=G(o,x))return{i1:I,i2:L,minLo:!0,minHi:!0}}if(!c){if(C&&j>Nn){let x=0,I=null;for(let T=g;T>=b;T-=2){let L=T>d?T-d:d-T,A=G(o,T),E=A-T,$=A-e+(E-s)-L;if($>Mt*j&&$>x&&e+te<=A&&A<t&&s+te<=E&&E<i){let X=!0;for(let K=1;K<=te;K++)if(n[A-K]!==r[E-K]){X=!1;break}X&&(x=$,I={i1:A,i2:E,minLo:!0,minHi:!1})}}if(I)return I;x=0,I=null;for(let T=R;T>=w;T-=2){let L=T>h?T-h:h-T,A=G(a,T),E=A-T,$=t-A+(i-E)-L;if($>Mt*j&&$>x&&e<A&&A<=t-te&&s<E&&E<=i-te){let X=!0;for(let K=0;K<te;K++)if(n[A+K]!==r[E+K]){X=!1;break}X&&(x=$,I={i1:A,i2:E,minLo:!1,minHi:!0})}}if(I)return I}if(j>=f){let x=-1,I=-1;for(let A=g;A>=b;A-=2){let E=Math.min(G(o,A),t),$=E-A;i<$&&(E=i+A,$=i),x<E+$&&(x=E+$,I=E)}let T=je,L=je;for(let A=R;A>=w;A-=2){let E=Math.max(e,G(a,A)),$=E-A;$<s&&(E=s+A,$=s),E+$<T&&(T=E+$,L=E)}return t+i-T<x-(e+s)?{i1:I,i2:x-I,minLo:!0,minHi:!1}:{i1:L,i2:T-L,minLo:!1,minHi:!0}}}}}function et(n,e,t,r,s,i,o,a,c,f,l,u,d,h){for(;e<t&&s<i&&n[e]===r[s];)e++,s++;for(;e<t&&s<i&&n[t-1]===r[i-1];)t--,i--;if(e===t)for(let m=s;m<i;m++)a[f[m]]=1;else if(s===i)for(let m=e;m<t;m++)o[c[m]]=1;else{let m=Gn(n,e,t,r,s,i,l,u,d,h);et(n,e,m.i1,r,s,m.i2,o,a,c,f,l,u,m.minLo,h),et(n,m.i1,t,r,m.i2,i,o,a,c,f,l,u,m.minHi,h)}}var vt=200,Lt=20,Ut=100,_n=1,Wn=21,zn=-30,Vn=6,Kn=-4,qn=10,Yn=24,Xn=17,Jn=23,Zn=17,Qn=60;function Ze(n){let e=0;for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);if(r===32)e+=1;else if(r===9)e+=8-e%8;else if(!(r===10||r===13||r===11||r===12))return e;if(e>=vt)return vt}return-1}function Bt(n,e,t){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};t>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=Ze(n[t]));for(let s=t-1;s>=0&&(r.preIndent=Ze(n[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===Lt){r.preIndent=0;break}for(let s=t+1;s<e&&(r.postIndent=Ze(n[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===Lt){r.postIndent=0;break}return r}function Dt(n,e){n.preIndent===-1&&n.preBlank===0&&(e.penalty+=_n),n.endOfFile&&(e.penalty+=Wn);let t=n.indent===-1?1+n.postBlank:0,r=n.preBlank+t;e.penalty+=zn*r,e.penalty+=Vn*t;let s=n.indent!==-1?n.indent:n.postIndent,i=r!==0;e.effectiveIndent+=s,s===-1||n.preIndent===-1||(s>n.preIndent?e.penalty+=i?qn:Kn:s===n.preIndent||(n.postIndent!==-1&&n.postIndent>s?e.penalty+=i?Xn:Yn:e.penalty+=i?Zn:Jn))}function er(n,e){let t=(n.effectiveIndent>e.effectiveIndent?1:0)-(n.effectiveIndent<e.effectiveIndent?1:0);return Qn*t+(n.penalty-e.penalty)}function Ht(n,e,t,r,s,i){let o=0,a=0;for(;n[a];)a++;let c=0,f=0;for(;s[f];)f++;let l=(u,d)=>e[u]===e[d];for(;;){if(a!==o){let u,d,h;do{for(u=a-o,d=-1;o>0&&l(o-1,a-1);){for(n[--o]=1,n[--a]=0;n[o-1];)o--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(h=a,f>c&&(d=a);!(a>=r||!l(o,a));){for(n[o++]=0,n[a++]=1;n[a];)a++;if(f>=i)break;for(c=f+1,f=c;s[f];f++);f>c&&(d=a)}}while(u!==a-o);if(a!==h)if(d!==-1)for(;f===c;){for(n[--a]=0,n[--o]=1;n[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,b={effectiveIndent:0,penalty:0},g=h;for(a-u-1>g&&(g=a-u-1),a-Ut>g&&(g=a-Ut);g<=a;g++){let w={effectiveIndent:0,penalty:0},R=Bt(t,r,g);Dt(R,w);let j=Bt(t,r,g-u);Dt(j,w),(m===-1||er(w,b)<=0)&&(b={effectiveIndent:w.effectiveIndent,penalty:w.penalty},m=g)}for(;a>m;){for(n[--a]=0,n[--o]=1;n[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;n[a];a++);if(f>=i)break;for(c=f+1,f=c;s[f];f++);}}function Nt(n,e){let t=n.length,r=e.length,s=new Uint8Array(t),i=new Uint8Array(r);if(t>0&&r>0){let{classes1:o,classes2:a,classInfo:c}=Bn(n,e),{dstart:f,dend1:l,dend2:u}=Dn(o,t,a,r);if(f>l)for(let d=f;d<r-(t-1-l);d++)i[d]=1;else if(f>u)for(let d=f;d<t-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:b}=Hn(o,t,a,r,c,f,l,u,s,i);if(h>0&&b>0){let g=new Array(h);for(let I=0;I<h;I++)g[I]=o[d[I]];let w=new Array(b);for(let I=0;I<b;I++)w[I]=a[m[I]];let R={},j={},C=h+b+3,x=Math.max(Fn,Qe(C));et(g,0,h,w,0,b,s,i,d,m,R,j,!1,x)}else if(h===0)for(let g=0;g<b;g++)i[m[g]]=1;else for(let g=0;g<h;g++)s[d[g]]=1;Ht(s,o,n,t,i,r),Ht(i,a,e,r,s,t)}}else t===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function fe(n){let e=n.lastIndexOf("/");return e>=0?n.slice(e+1):n}function tr(n,e){if(n.length===0)return;if(n.length===1)return n.shift();let t=fe(e),r=0;for(let s=0;s<n.length;s++){let i=n[s];if(i&&fe(i.path)===t){r=s;break}}return n.splice(r,1)[0]}var nr=50;async function tt(n,e,t=nr){let r=new Map,s=[],i=[],o=[];for(let l of e)if(l.status==="deleted"&&l.oldHash){let u=r.get(l.oldHash)??[];u.push(l),r.set(l.oldHash,u),s.push(l)}else l.status==="added"&&l.newHash?i.push(l):o.push(l);let a=[],c=[];for(let l of i){let u=l.newHash;if(!u){c.push(l);continue}let d=r.get(u);if(d&&d.length>0){let h=tr(d,l.path);h&&a.push({oldPath:h.path,newPath:l.path,oldHash:h.oldHash??u,newHash:u,similarity:100,oldMode:h.oldMode,newMode:l.newMode})}else c.push(l)}let f=[...r.values()].flat();if(f.length>0&&c.length>0){let l=await rr(n,f,c,t);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}if(f.length>0&&c.length>0){let l=await or(n,f,c,t);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}return{remaining:[...o,...f,...c],renames:a}}async function rr(n,e,t,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let f=fe(c.path);s.has(f)?s.set(f,-1):s.set(f,a)}let i=new Map;for(let a=0;a<t.length;a++){let c=t[a];if(!c)continue;let f=fe(c.path);i.has(f)?i.set(f,-1):i.set(f,a)}let o=[];for(let[a,c]of s){if(c===-1)continue;let f=i.get(a);if(f===void 0||f===-1)continue;let l=e[c],u=t[f];if(!l?.oldHash||!u?.newHash||l.oldHash===u.newHash)continue;let d=await Z(n,l.oldHash),h=await Z(n,u.newHash),m=ir(d,h);m<r||o.push({oldPath:l.path,newPath:u.path,oldHash:l.oldHash,newHash:u.newHash,similarity:m,oldMode:l.oldMode,newMode:u.newMode})}return o}var Ft=107927;function Ae(n){let e=new Map,t=0,r=0,s=0;for(let o=0;o<n.length;o++){let a=n[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,t++,t<64&&a!==10)continue;let f=(r+Math.imul(s,97))%Ft;e.set(f,(e.get(f)??0)+t),t=0,r=0,s=0}if(t>0){let o=(r+Math.imul(s,97))%Ft;e.set(o,(e.get(o)??0)+t)}let i=[];for(let[o,a]of e)i.push({hash:o,count:a});return i.sort((o,a)=>o.hash-a.hash),i}function sr(n,e){let t=0,r=0,s=0,i=0;for(;s<n.length;){let o=n[s];if(!o)break;for(;i<e.length;){let f=e[i];if(!f||f.hash>=o.hash)break;r+=f.count,i++}let a=o.count,c=0;if(i<e.length){let f=e[i];f&&f.hash===o.hash&&(c=f.count,i++)}a<c?(r+=c-a,t+=a):t+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:t,literalAdded:r}}function ir(n,e){return n.length===0&&e.length===0?100:n.length===0||e.length===0?0:Gt(n.length,Ae(n),e.length,Ae(e))}function Gt(n,e,t,r){let s=Math.max(n,t),i=Math.min(n,t);if(i<s-i)return 0;let{srcCopied:o}=sr(e,r);return Math.floor(o*100/s)}async function or(n,e,t,r){let s=[];for(let l of e)if(l.oldHash){let u=await Z(n,l.oldHash);s.push({size:u.length,chunks:Ae(u)})}else s.push(null);let i=[];for(let l of t)if(l.newHash){let u=await Z(n,l.newHash);i.push({size:u.length,chunks:Ae(u)})}else i.push(null);let o=[];for(let l=0;l<e.length;l++){let u=e[l],d=s[l];if(!(!u||!d))for(let h=0;h<t.length;h++){let m=t[h],b=i[h];if(!m||!b)continue;let g=Gt(d.size,d.chunks,b.size,b.chunks);if(g>=r){let w=fe(u.path)===fe(m.path)?1:0;o.push({similarity:g,nameScore:w,delIdx:l,addIdx:h})}}}o.sort((l,u)=>u.similarity-l.similarity||u.nameScore-l.nameScore);let a=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:u,addIdx:d}of o){if(a.has(u)||c.has(d))continue;a.add(u),c.add(d);let h=e[u],m=t[d];!h||!m||f.push({oldPath:h.path,newPath:m.path,oldHash:h.oldHash??"",newHash:m.newHash??"",similarity:l,oldMode:h.oldMode,newMode:m.newMode})}return f}async function ar(n,e){let t=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(t.has(i))continue;t.add(i);let o=await U(n,i);for(let a of o.parents)t.has(a)||r.push(a)}return t}async function nt(n,e,t){if(e===t)return!0;let r=new Set,s=[t],i=0;for(;i<s.length;){let o=s[i++];if(o===e)return!0;if(r.has(o))continue;r.add(o);let a=await U(n,o);for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function ge(n,e,t){if(e===t)return[e];let r=await ar(n,e),s=[],i=new Set,o=[t],a=0;for(;a<o.length;){let f=o[a++];if(i.has(f))continue;if(i.add(f),r.has(f)){s.push(f);continue}let l=await U(n,f);for(let u of l.parents)i.has(u)||o.push(u)}if(s.length<=1)return s;let c=[];for(let f of s){let l=!1;for(let u of s)if(u!==f&&await nt(n,f,u)){l=!0;break}l||c.push(f)}return c.length<=1?c:cr(n,e,t,c)}async function cr(n,e,t,r){let s=new Set(r),i=new Set,o=[],a=new Map,c=new Map,f=0,l=[{hash:e,mask:1,seq:f++},{hash:t,mask:2,seq:f++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await U(n,d)).committer.timestamp;return c.set(d,m),m}for(;l.length>0;){let d=0,h=await u(l[0].hash);for(let R=1;R<l.length;R++){let j=l[R],C=await u(j.hash),x=l[d];(C>h||C===h&&j.seq<x.seq)&&(d=R,h=C)}let m=l.splice(d,1)[0],b=a.get(m.hash)??0,g=b|m.mask;if(g===b)continue;if(a.set(m.hash,g),g===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let w=await U(n,m.hash);for(let R of w.parents)l.push({hash:R,mask:g,seq:f++})}for(let d of r)i.has(d)||o.push(d);return o}function rt(n,e){let t=n.length,r=e.length;if(t===0&&r===0)return[];if(t===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,t],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=Nt(n,e);return fr(s,t,i,r)}function fr(n,e,t,r){let s=[],i=0,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!n[i]&&!t[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&n[i];)i++;for(;o<r&&t[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function lr(n,e,t){let r=[];for(let c of rt(e,n))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of rt(e,t))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,f)=>c.oStart-f.oStart);let s=[],i=0;function o(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let a=0;for(;a<r.length;){let c=r[a++],f=c.oStart,l=c.oStart+c.oLength,u=[c];for(o(f);a<r.length;){let d=r[a];if(d.oStart>l)break;l=Math.max(l,d.oStart+d.oLength),u.push(d),a++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?n:t;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:d.slice(c.abStart,c.abStart+c.abLength)})}}else{let d={a:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1}};for(let w of u){let R=w.oStart,j=R+w.oLength,C=w.abStart,x=C+w.abLength,I=d[w.ab];I.abMin=Math.min(C,I.abMin),I.abMax=Math.max(x,I.abMax),I.oMin=Math.min(R,I.oMin),I.oMax=Math.max(j,I.oMax)}let h=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(l-d.a.oMax),b=d.b.abMin+(f-d.b.oMin),g=d.b.abMax+(l-d.b.oMax);s.push({stable:!1,a:n.slice(h,m),o:e.slice(f,l),b:t.slice(b,g)})}i=l}return o(e.length),s}function ur(n,e,t,r){let s=r?.excludeFalseConflicts??!0,i=lr(n,e,t),o=[],a=[];function c(){a.length&&(o.push({type:"ok",lines:a}),a=[])}for(let f of i)f.stable?a.push(...f.content):s&&_t(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),mr(hr(o))}function be(n,e,t,r){let s=r?.markerSize??7,i=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,o="=".repeat(s),a=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,c=ur(n,e,t),f=!1,l=[];for(let u of c)u.type==="ok"?l.push(...u.lines):(f=!0,l.push(i,...u.a,o,...u.b,a));return{conflict:f,result:l}}function hr(n){let e=[];for(let t of n)t.type==="ok"?e.push(t):e.push(...dr(t));return e}function dr(n){let{a:e,b:t}=n;if(e.length===0||t.length===0)return[n];if(_t(e,t))return[n];let r=rt(e,t);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let a of r){let c=a.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let l=c+a.buffer1[1],u=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:e.slice(c,l),o:[],b:t.slice(a.buffer2[0],u)}),i=l}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[n]:s}function mr(n){if(n.length<3)return n;let e=[n[0]];for(let r=1;r<n.length;r++){let s=e[e.length-1],i=n[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let t=[e[0]];for(let r=1;r<e.length;r++){let s=t[t.length-1],i=e[r];if(s.type==="conflict"&&i.type==="ok"&&i.lines.length<=3&&r+1<e.length&&e[r+1].type==="conflict"){let o=e[r+1],a=s;a.a=[...s.a,...i.lines,...o.a],a.b=[...s.b,...i.lines,...o.b],a.o=[...s.o,...i.lines,...o.o],r++}else t.push(i)}return t}function ie(n,e,t,r){let s=be(W(n),W(e),W(t),{a:r.a,b:r.b,markerSize:r.markerSize}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(st);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
10
+ `)):await this.fs.rm(t)}async walkRefs(e,t,r){let s=await this.fs.readdir(e);for(let i of s){let o=v(e,i),a=`${t}/${i}`,c=await this.fs.stat(o);if(c.isDirectory)await this.walkRefs(o,a,r);else if(c.isFile){let f=await this.resolveRefInternal(a);f&&r.push({name:a,hash:f})}}}};async function Mn(n,e){return n.refStore.readRef(e)}async function ke(n,e){let t=e;for(let r=0;r<kt;r++){let s=await Mn(n,t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function Ye(n,e="refs"){return n.refStore.listRefs(e)}async function Et(n,e){let t=e.lastIndexOf("/");if(t>0){let r=e.slice(0,t);await n.mkdir(r,{recursive:!0})}}var Ls=new TextEncoder;function Y(n){return typeof n=="string"?n==="120000":n===40960}var vn=new TextEncoder,Tt=new TextDecoder;function St(n){let e=[],t=0;for(;t<n.byteLength;){let r=n.indexOf(32,t);if(r===-1)break;let s=Tt.decode(n.subarray(t,r)),i=n.indexOf(0,r+1);if(i===-1)break;let o=Tt.decode(n.subarray(r+1,i)),a=n.subarray(i+1,i+21),c=re(a),f=s.padStart(6,"0");e.push({mode:f,name:o,hash:c}),t=i+21}return{type:"tree",entries:e}}function Ee(n){let e=[];for(let i of n.entries){let o=i.mode.replace(/^0+/,""),a=vn.encode(`${o} ${i.name}\0`),c=q(i.hash);e.push(a),e.push(c)}let t=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(t),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}var me={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};async function Xe(n,e){return jt(n,e,"")}async function jt(n,e,t){let r=[],s=new Map;for(let o of e){let a=t?o.path.slice(t.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:Ln(o.mode),name:a,hash:o.hash});else{let f=a.slice(0,c),l=s.get(f);l||(l=[],s.set(f,l)),l.push(o)}}for(let[o,a]of s){let c=t?`${t}/${o}`:o,f=await jt(n,a,c);r.push({mode:me.DIRECTORY,name:o,hash:f})}r.sort((o,a)=>{let c=o.mode===me.DIRECTORY?`${o.name}/`:o.name,f=a.mode===me.DIRECTORY?`${a.name}/`:a.name;return c<f?-1:c>f?1:0});let i=Ee({type:"tree",entries:r});return N(n,"tree",i)}async function se(n,e,t=""){let r=await V(n,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=St(r.content),i=[];for(let o of s.entries){let a=t?`${t}/${o.name}`:o.name;if(o.mode===me.DIRECTORY){let c=await se(n,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function ae(n,e){if(!e)return new Map;let t=await se(n,e);return new Map(t.map(r=>[r.path,r]))}async function Je(n,e,t){let r=await ae(n,e),s=await ae(n,t),i=[];for(let[o,a]of r){let c=s.get(o);c?(a.hash!==c.hash||a.mode!==c.mode)&&i.push({path:o,status:"modified",oldHash:a.hash,newHash:c.hash,oldMode:a.mode,newMode:c.mode}):i.push({path:o,status:"deleted",oldHash:a.hash,oldMode:a.mode})}for(let[o,a]of s)r.has(o)||i.push({path:o,status:"added",newHash:a.hash,newMode:a.mode});return i.sort((o,a)=>pe(o.path,a.path))}function Ln(n){return n.toString(8).padStart(6,"0")}function Ct(n){return{stdout:"",stderr:`fatal: ${n}
11
+ `,exitCode:128}}var zs=Ct("not a git repository (or any of the parent directories): .git"),Vs=Ct("this operation must be run in a work tree");function pe(n,e){return n<e?-1:n>e?1:0}var Te=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let t=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),t.entry}higher(e,t){let r=e.entry.commit.committer.timestamp,s=t.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<t.epoch}siftUp(e){let{heap:t}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(t[e],t[r]))break;[t[r],t[e]]=[t[e],t[r]],e=r}}siftDown(e){let{heap:t}=this,r=t.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(t[i],t[s])&&(s=i),o<r&&this.higher(t[o],t[s])&&(s=o),s===e)break;[t[e],t[s]]=[t[s],t[e]],e=s}}};async function*Ze(n,e,t){if(t?.topoOrder){yield*Un(n,e,t);return}let r=await At(n,t?.exclude),s=new Set(r),i=new Te,o=Array.isArray(e)?e:[e];for(let a of o)s.has(a)||i.push(await Se(n,a));for(;i.size>0;){let a=i.pop();if(!s.has(a.hash)){s.add(a.hash),yield a;for(let c of a.commit.parents)s.has(c)||i.push(await Se(n,c))}}}async function*Un(n,e,t){let r=await At(n,t?.exclude),s=new Set(r),i=new Te,o=Array.isArray(e)?e:[e];for(let d of o)s.has(d)||i.push(await Se(n,d));let a=[],c=new Map;for(;i.size>0;){let d=i.pop();if(!s.has(d.hash)){s.add(d.hash),c.set(d.hash,a.length),a.push(d);for(let h of d.commit.parents)s.has(h)||i.push(await Se(n,h))}}let f=a.length;if(f===0)return;let l=new Int32Array(f);for(let d of a)for(let h of d.commit.parents){let m=c.get(h);m!==void 0&&(l[m]=(l[m]??0)+1)}let u=[];for(let d=f-1;d>=0;d--)l[d]===0&&u.push(d);for(;u.length>0;){let d=u.pop();yield a[d];for(let h of a[d].commit.parents){let m=c.get(h);if(m!==void 0){let b=(l[m]??0)-1;l[m]=b,b===0&&u.push(m)}}}}async function At(n,e){if(!e||e.length===0)return new Set;let t=new Set;for await(let r of Ze(n,e))t.add(r.hash);return t}async function Se(n,e){return{hash:e,commit:await U(n,e)}}var Bn=4,$t=1024,je=100,$e=0,Ce=1,ce=2;function et(n){let e=1;for(;e*e<n;)e++;return e}function Dn(n,e){let t=new Map,r=[],s=new Array(n.length),i=new Array(e.length);for(let o=0;o<n.length;o++){let a=n[o],c=t.get(a);c===void 0&&(c=r.length,t.set(a,c),r.push({len1:0,len2:0})),r[c].len1++,s[o]=c}for(let o=0;o<e.length;o++){let a=e[o],c=t.get(a);c===void 0&&(c=r.length,t.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function Hn(n,e,t,r){let s=0,i=Math.min(e,r);for(;s<i&&n[s]===t[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&n[e-1-a]===t[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function Mt(n,e,t,r){e-t>je&&(t=e-je),r-e>je&&(r=e+je);let s=0,i=1;for(let c=1;e-c>=t;c++){let f=n[e-c];if(f===$e)s++;else if(f===ce)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let f=n[e+c];if(f===$e)o++;else if(f===ce)a++;else break}return o===0?!1:(o+=s,a+=i,a*Bn<a+o)}function Nn(n,e,t,r,s,i,o,a,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(et(e),$t);for(let g=i;g<=o;g++){let w=s[n[g]].len2;w===0?l[g]=$e:w>=d?l[g]=ce:l[g]=Ce}let h=Math.min(et(r),$t);for(let g=i;g<=a;g++){let w=s[t[g]].len1;w===0?u[g]=$e:w>=h?u[g]=ce:u[g]=Ce}let m=[];for(let g=i;g<=o;g++)l[g]===Ce||l[g]===ce&&!Mt(l,g,i,o)?m.push(g):c[g]=1;let b=[];for(let g=i;g<=a;g++)u[g]===Ce||u[g]===ce&&!Mt(u,g,i,a)?b.push(g):f[g]=1;return{refIndex1:m,nreff1:m.length,refIndex2:b,nreff2:b.length}}var te=20,vt=4,Fn=256,Gn=256,Ae=2147483647;function G(n,e){return n[e]??0}function _n(n,e,t,r,s,i,o,a,c,f){let l=e-i,u=t-s,d=e-s,h=t-i,m=d-h&1,b=d,g=d,w=h,R=h;o[d]=e,a[h]=t;for(let j=1;;j++){let C=!1;b>l?o[--b-1]=-1:++b,g<u?o[++g+1]=-1:--g;for(let x=g;x>=b;x-=2){let I;G(o,x-1)>=G(o,x+1)?I=G(o,x-1)+1:I=G(o,x+1);let T=I,L=I-x;for(;I<t&&L<i&&n[I]===r[L];)I++,L++;if(I-T>te&&(C=!0),o[x]=I,m&&w<=x&&x<=R&&G(a,x)<=I)return{i1:I,i2:L,minLo:!0,minHi:!0}}w>l?a[--w-1]=Ae:++w,R<u?a[++R+1]=Ae:--R;for(let x=R;x>=w;x-=2){let I;G(a,x-1)<G(a,x+1)?I=G(a,x-1):I=G(a,x+1)-1;let T=I,L=I-x;for(;I>e&&L>s&&n[I-1]===r[L-1];)I--,L--;if(T-I>te&&(C=!0),a[x]=I,!m&&b<=x&&x<=g&&I<=G(o,x))return{i1:I,i2:L,minLo:!0,minHi:!0}}if(!c){if(C&&j>Fn){let x=0,I=null;for(let T=g;T>=b;T-=2){let L=T>d?T-d:d-T,A=G(o,T),E=A-T,$=A-e+(E-s)-L;if($>vt*j&&$>x&&e+te<=A&&A<t&&s+te<=E&&E<i){let X=!0;for(let K=1;K<=te;K++)if(n[A-K]!==r[E-K]){X=!1;break}X&&(x=$,I={i1:A,i2:E,minLo:!0,minHi:!1})}}if(I)return I;x=0,I=null;for(let T=R;T>=w;T-=2){let L=T>h?T-h:h-T,A=G(a,T),E=A-T,$=t-A+(i-E)-L;if($>vt*j&&$>x&&e<A&&A<=t-te&&s<E&&E<=i-te){let X=!0;for(let K=0;K<te;K++)if(n[A+K]!==r[E+K]){X=!1;break}X&&(x=$,I={i1:A,i2:E,minLo:!1,minHi:!0})}}if(I)return I}if(j>=f){let x=-1,I=-1;for(let A=g;A>=b;A-=2){let E=Math.min(G(o,A),t),$=E-A;i<$&&(E=i+A,$=i),x<E+$&&(x=E+$,I=E)}let T=Ae,L=Ae;for(let A=R;A>=w;A-=2){let E=Math.max(e,G(a,A)),$=E-A;$<s&&(E=s+A,$=s),E+$<T&&(T=E+$,L=E)}return t+i-T<x-(e+s)?{i1:I,i2:x-I,minLo:!0,minHi:!1}:{i1:L,i2:T-L,minLo:!1,minHi:!0}}}}}function tt(n,e,t,r,s,i,o,a,c,f,l,u,d,h){for(;e<t&&s<i&&n[e]===r[s];)e++,s++;for(;e<t&&s<i&&n[t-1]===r[i-1];)t--,i--;if(e===t)for(let m=s;m<i;m++)a[f[m]]=1;else if(s===i)for(let m=e;m<t;m++)o[c[m]]=1;else{let m=_n(n,e,t,r,s,i,l,u,d,h);tt(n,e,m.i1,r,s,m.i2,o,a,c,f,l,u,m.minLo,h),tt(n,m.i1,t,r,m.i2,i,o,a,c,f,l,u,m.minHi,h)}}var Lt=200,Ut=20,Bt=100,Wn=1,zn=21,Vn=-30,Kn=6,qn=-4,Yn=10,Xn=24,Jn=17,Zn=23,Qn=17,er=60;function Qe(n){let e=0;for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);if(r===32)e+=1;else if(r===9)e+=8-e%8;else if(!(r===10||r===13||r===11||r===12))return e;if(e>=Lt)return Lt}return-1}function Dt(n,e,t){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};t>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=Qe(n[t]));for(let s=t-1;s>=0&&(r.preIndent=Qe(n[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===Ut){r.preIndent=0;break}for(let s=t+1;s<e&&(r.postIndent=Qe(n[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===Ut){r.postIndent=0;break}return r}function Ht(n,e){n.preIndent===-1&&n.preBlank===0&&(e.penalty+=Wn),n.endOfFile&&(e.penalty+=zn);let t=n.indent===-1?1+n.postBlank:0,r=n.preBlank+t;e.penalty+=Vn*r,e.penalty+=Kn*t;let s=n.indent!==-1?n.indent:n.postIndent,i=r!==0;e.effectiveIndent+=s,s===-1||n.preIndent===-1||(s>n.preIndent?e.penalty+=i?Yn:qn:s===n.preIndent||(n.postIndent!==-1&&n.postIndent>s?e.penalty+=i?Jn:Xn:e.penalty+=i?Qn:Zn))}function tr(n,e){let t=(n.effectiveIndent>e.effectiveIndent?1:0)-(n.effectiveIndent<e.effectiveIndent?1:0);return er*t+(n.penalty-e.penalty)}function Nt(n,e,t,r,s,i){let o=0,a=0;for(;n[a];)a++;let c=0,f=0;for(;s[f];)f++;let l=(u,d)=>e[u]===e[d];for(;;){if(a!==o){let u,d,h;do{for(u=a-o,d=-1;o>0&&l(o-1,a-1);){for(n[--o]=1,n[--a]=0;n[o-1];)o--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(h=a,f>c&&(d=a);!(a>=r||!l(o,a));){for(n[o++]=0,n[a++]=1;n[a];)a++;if(f>=i)break;for(c=f+1,f=c;s[f];f++);f>c&&(d=a)}}while(u!==a-o);if(a!==h)if(d!==-1)for(;f===c;){for(n[--a]=0,n[--o]=1;n[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,b={effectiveIndent:0,penalty:0},g=h;for(a-u-1>g&&(g=a-u-1),a-Bt>g&&(g=a-Bt);g<=a;g++){let w={effectiveIndent:0,penalty:0},R=Dt(t,r,g);Ht(R,w);let j=Dt(t,r,g-u);Ht(j,w),(m===-1||tr(w,b)<=0)&&(b={effectiveIndent:w.effectiveIndent,penalty:w.penalty},m=g)}for(;a>m;){for(n[--a]=0,n[--o]=1;n[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;n[a];a++);if(f>=i)break;for(c=f+1,f=c;s[f];f++);}}function Ft(n,e){let t=n.length,r=e.length,s=new Uint8Array(t),i=new Uint8Array(r);if(t>0&&r>0){let{classes1:o,classes2:a,classInfo:c}=Dn(n,e),{dstart:f,dend1:l,dend2:u}=Hn(o,t,a,r);if(f>l)for(let d=f;d<r-(t-1-l);d++)i[d]=1;else if(f>u)for(let d=f;d<t-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:b}=Nn(o,t,a,r,c,f,l,u,s,i);if(h>0&&b>0){let g=new Array(h);for(let I=0;I<h;I++)g[I]=o[d[I]];let w=new Array(b);for(let I=0;I<b;I++)w[I]=a[m[I]];let R={},j={},C=h+b+3,x=Math.max(Gn,et(C));tt(g,0,h,w,0,b,s,i,d,m,R,j,!1,x)}else if(h===0)for(let g=0;g<b;g++)i[m[g]]=1;else for(let g=0;g<h;g++)s[d[g]]=1;Nt(s,o,n,t,i,r),Nt(i,a,e,r,s,t)}}else t===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function fe(n){let e=n.lastIndexOf("/");return e>=0?n.slice(e+1):n}function nr(n,e){if(n.length===0)return;if(n.length===1)return n.shift();let t=fe(e),r=0;for(let s=0;s<n.length;s++){let i=n[s];if(i&&fe(i.path)===t){r=s;break}}return n.splice(r,1)[0]}var rr=50;async function nt(n,e,t=rr){let r=new Map,s=[],i=[],o=[];for(let l of e)if(l.status==="deleted"&&l.oldHash){let u=r.get(l.oldHash)??[];u.push(l),r.set(l.oldHash,u),s.push(l)}else l.status==="added"&&l.newHash?i.push(l):o.push(l);let a=[],c=[];for(let l of i){let u=l.newHash;if(!u){c.push(l);continue}let d=r.get(u);if(d&&d.length>0){let h=nr(d,l.path);h&&a.push({oldPath:h.path,newPath:l.path,oldHash:h.oldHash??u,newHash:u,similarity:100,oldMode:h.oldMode,newMode:l.newMode})}else c.push(l)}let f=[...r.values()].flat();if(f.length>0&&c.length>0){let l=await sr(n,f,c,t);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}if(f.length>0&&c.length>0){let l=await ar(n,f,c,t);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}return{remaining:[...o,...f,...c],renames:a}}async function sr(n,e,t,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let f=fe(c.path);s.has(f)?s.set(f,-1):s.set(f,a)}let i=new Map;for(let a=0;a<t.length;a++){let c=t[a];if(!c)continue;let f=fe(c.path);i.has(f)?i.set(f,-1):i.set(f,a)}let o=[];for(let[a,c]of s){if(c===-1)continue;let f=i.get(a);if(f===void 0||f===-1)continue;let l=e[c],u=t[f];if(!l?.oldHash||!u?.newHash||l.oldHash===u.newHash)continue;let d=await Z(n,l.oldHash),h=await Z(n,u.newHash),m=or(d,h);m<r||o.push({oldPath:l.path,newPath:u.path,oldHash:l.oldHash,newHash:u.newHash,similarity:m,oldMode:l.oldMode,newMode:u.newMode})}return o}var Gt=107927;function Me(n){let e=new Map,t=0,r=0,s=0;for(let o=0;o<n.length;o++){let a=n[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,t++,t<64&&a!==10)continue;let f=(r+Math.imul(s,97))%Gt;e.set(f,(e.get(f)??0)+t),t=0,r=0,s=0}if(t>0){let o=(r+Math.imul(s,97))%Gt;e.set(o,(e.get(o)??0)+t)}let i=[];for(let[o,a]of e)i.push({hash:o,count:a});return i.sort((o,a)=>o.hash-a.hash),i}function ir(n,e){let t=0,r=0,s=0,i=0;for(;s<n.length;){let o=n[s];if(!o)break;for(;i<e.length;){let f=e[i];if(!f||f.hash>=o.hash)break;r+=f.count,i++}let a=o.count,c=0;if(i<e.length){let f=e[i];f&&f.hash===o.hash&&(c=f.count,i++)}a<c?(r+=c-a,t+=a):t+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:t,literalAdded:r}}function or(n,e){return n.length===0&&e.length===0?100:n.length===0||e.length===0?0:_t(n.length,Me(n),e.length,Me(e))}function _t(n,e,t,r){let s=Math.max(n,t),i=Math.min(n,t);if(i<s-i)return 0;let{srcCopied:o}=ir(e,r);return Math.floor(o*100/s)}async function ar(n,e,t,r){let s=[];for(let l of e)if(l.oldHash){let u=await Z(n,l.oldHash);s.push({size:u.length,chunks:Me(u)})}else s.push(null);let i=[];for(let l of t)if(l.newHash){let u=await Z(n,l.newHash);i.push({size:u.length,chunks:Me(u)})}else i.push(null);let o=[];for(let l=0;l<e.length;l++){let u=e[l],d=s[l];if(!(!u||!d))for(let h=0;h<t.length;h++){let m=t[h],b=i[h];if(!m||!b)continue;let g=_t(d.size,d.chunks,b.size,b.chunks);if(g>=r){let w=fe(u.path)===fe(m.path)?1:0;o.push({similarity:g,nameScore:w,delIdx:l,addIdx:h})}}}o.sort((l,u)=>u.similarity-l.similarity||u.nameScore-l.nameScore);let a=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:u,addIdx:d}of o){if(a.has(u)||c.has(d))continue;a.add(u),c.add(d);let h=e[u],m=t[d];!h||!m||f.push({oldPath:h.path,newPath:m.path,oldHash:h.oldHash??"",newHash:m.newHash??"",similarity:l,oldMode:h.oldMode,newMode:m.newMode})}return f}async function cr(n,e){let t=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(t.has(i))continue;t.add(i);let o=await U(n,i);for(let a of o.parents)t.has(a)||r.push(a)}return t}async function rt(n,e,t){if(e===t)return!0;let r=new Set,s=[t],i=0;for(;i<s.length;){let o=s[i++];if(o===e)return!0;if(r.has(o))continue;r.add(o);let a=await U(n,o);for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function ge(n,e,t){if(e===t)return[e];let r=await cr(n,e),s=[],i=new Set,o=[t],a=0;for(;a<o.length;){let f=o[a++];if(i.has(f))continue;if(i.add(f),r.has(f)){s.push(f);continue}let l=await U(n,f);for(let u of l.parents)i.has(u)||o.push(u)}if(s.length<=1)return s;let c=[];for(let f of s){let l=!1;for(let u of s)if(u!==f&&await rt(n,f,u)){l=!0;break}l||c.push(f)}return c.length<=1?c:fr(n,e,t,c)}async function fr(n,e,t,r){let s=new Set(r),i=new Set,o=[],a=new Map,c=new Map,f=0,l=[{hash:e,mask:1,seq:f++},{hash:t,mask:2,seq:f++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await U(n,d)).committer.timestamp;return c.set(d,m),m}for(;l.length>0;){let d=0,h=await u(l[0].hash);for(let R=1;R<l.length;R++){let j=l[R],C=await u(j.hash),x=l[d];(C>h||C===h&&j.seq<x.seq)&&(d=R,h=C)}let m=l.splice(d,1)[0],b=a.get(m.hash)??0,g=b|m.mask;if(g===b)continue;if(a.set(m.hash,g),g===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let w=await U(n,m.hash);for(let R of w.parents)l.push({hash:R,mask:g,seq:f++})}for(let d of r)i.has(d)||o.push(d);return o}function st(n,e){let t=n.length,r=e.length;if(t===0&&r===0)return[];if(t===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,t],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=Ft(n,e);return lr(s,t,i,r)}function lr(n,e,t,r){let s=[],i=0,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!n[i]&&!t[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&n[i];)i++;for(;o<r&&t[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function ur(n,e,t){let r=[];for(let c of st(e,n))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of st(e,t))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,f)=>c.oStart-f.oStart);let s=[],i=0;function o(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let a=0;for(;a<r.length;){let c=r[a++],f=c.oStart,l=c.oStart+c.oLength,u=[c];for(o(f);a<r.length;){let d=r[a];if(d.oStart>l)break;l=Math.max(l,d.oStart+d.oLength),u.push(d),a++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?n:t;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:d.slice(c.abStart,c.abStart+c.abLength)})}}else{let d={a:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1}};for(let w of u){let R=w.oStart,j=R+w.oLength,C=w.abStart,x=C+w.abLength,I=d[w.ab];I.abMin=Math.min(C,I.abMin),I.abMax=Math.max(x,I.abMax),I.oMin=Math.min(R,I.oMin),I.oMax=Math.max(j,I.oMax)}let h=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(l-d.a.oMax),b=d.b.abMin+(f-d.b.oMin),g=d.b.abMax+(l-d.b.oMax);s.push({stable:!1,a:n.slice(h,m),o:e.slice(f,l),b:t.slice(b,g)})}i=l}return o(e.length),s}function hr(n,e,t,r){let s=r?.excludeFalseConflicts??!0,i=ur(n,e,t),o=[],a=[];function c(){a.length&&(o.push({type:"ok",lines:a}),a=[])}for(let f of i)f.stable?a.push(...f.content):s&&Wt(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),pr(dr(o))}function be(n,e,t,r){let s=r?.markerSize??7,i=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,o="=".repeat(s),a=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,c=hr(n,e,t),f=!1,l=[];for(let u of c)u.type==="ok"?l.push(...u.lines):(f=!0,l.push(i,...u.a,o,...u.b,a));return{conflict:f,result:l}}function dr(n){let e=[];for(let t of n)t.type==="ok"?e.push(t):e.push(...mr(t));return e}function mr(n){let{a:e,b:t}=n;if(e.length===0||t.length===0)return[n];if(Wt(e,t))return[n];let r=st(e,t);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let a of r){let c=a.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let l=c+a.buffer1[1],u=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:e.slice(c,l),o:[],b:t.slice(a.buffer2[0],u)}),i=l}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[n]:s}function pr(n){if(n.length<3)return n;let e=[n[0]];for(let r=1;r<n.length;r++){let s=e[e.length-1],i=n[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let t=[e[0]];for(let r=1;r<e.length;r++){let s=t[t.length-1],i=e[r];if(s.type==="conflict"&&i.type==="ok"&&i.lines.length<=3&&r+1<e.length&&e[r+1].type==="conflict"){let o=e[r+1],a=s;a.a=[...s.a,...i.lines,...o.a],a.b=[...s.b,...i.lines,...o.b],a.o=[...s.o,...i.lines,...o.o],r++}else t.push(i)}return t}function ie(n,e,t,r){let s=be(W(n),W(e),W(t),{a:r.a,b:r.b,markerSize:r.markerSize}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(it);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
12
12
  `)}
13
13
  `:a.join(`
14
14
  `)}function W(n){if(n==="")return[];let e=n.split(`
15
- `);if(e[e.length-1]==="")e.pop();else{let t=e[e.length-1]??"";e[e.length-1]=`${t}\0`}return e}function st(n){return n.endsWith("\0")?n.slice(0,-1):n}function _t(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}var le=new TextDecoder,ne=new TextEncoder,Wt={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function ue(n,e,t,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await pr(n,e,t,r),f=await br(n,i,o,a,c,s);return yr(n,i,s,f)}async function Jt(n,e,t,r){let s=await ge(n,e,t),i=await U(n,e),o=await U(n,t);if(s.length===0)return{...await ue(n,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let f=await U(n,s[0]);return{...await ue(n,f.tree,i.tree,o.tree,r),baseTree:f.tree}}let a=await Qt(n,e,t,s,1);return{...await ue(n,a,i.tree,o.tree,r),baseTree:a}}async function pr(n,e,t,r){let s=await ae(n,e),i=await ae(n,t),o=await ae(n,r),a=new Set;for(let f of s.keys())a.add(f);for(let f of i.keys())a.add(f);for(let f of o.keys())a.add(f);let c=new Map;for(let f of a){let l=s.get(f)??null,u=i.get(f)??null,d=o.get(f)??null,h=l?{hash:l.hash,mode:l.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,b=d?{hash:d.hash,mode:d.mode}:null,g=(l?1:0)|(u?2:0)|(d?4:0),w=l?.hash??null,R=u?.hash??null,j=d?.hash??null,C=0;w!==null&&w===R&&(C|=3),w!==null&&w===j&&(C|=5),R!==null&&R===j&&(C|=6);let x={path:f,stages:[h,m,b],pathnames:[f,f,f],filemask:g,matchMask:C,merged:{result:null,clean:!1},pathConflict:!1};if(gr(x)){c.set(f,x);continue}c.set(f,x)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function gr(n){let[e,t,r]=n.stages,s=e?.hash??null,i=t?.hash??null,o=r?.hash??null;return i===s&&o===s?(t?n.merged={result:{hash:i,mode:t.mode},clean:!0}:n.merged={result:null,clean:!0},!0):i===o&&i!==null?(n.merged={result:{hash:i,mode:t.mode},clean:!0},!0):i===null&&o===null?(n.merged={result:null,clean:!0},!0):o===s&&i!==s?(t?n.merged={result:{hash:i,mode:t.mode},clean:!0}:n.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?n.merged={result:{hash:o,mode:r.mode},clean:!0}:n.merged={result:null,clean:!0},!0):!1}async function br(n,e,t,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[y,p]of t)r.has(y)||a.push({path:y,status:"deleted",oldHash:p.hash,oldMode:p.mode}),s.has(y)||c.push({path:y,status:"deleted",oldHash:p.hash,oldMode:p.mode});for(let[y,p]of r)t.has(y)||a.push({path:y,status:"added",newHash:p.hash,newMode:p.mode});for(let[y,p]of s)t.has(y)||c.push({path:y,status:"added",newHash:p.hash,newMode:p.mode});let f=await tt(n,a),l=await tt(n,c);if(f.renames.length===0&&l.renames.length===0)return o;let u=new Map,d=new Map;for(let y of f.renames)u.set(y.oldPath,y);for(let y of l.renames)d.set(y.oldPath,y);let h=new Set;for(let[y]of r)!t.has(y)&&s.has(y)&&h.add(y);let m=new Set,b=i?.a??"HEAD",g=i?.b??"theirs";function w(y,p,O=0){o.msgBuf.push({sortKey:y,subOrder:O,text:p})}for(let y of[...t.keys()].sort()){let p=u.get(y),O=d.get(y);if(!p&&!O)continue;let S=t.get(y);if(m.add(y),p&&O)if(m.add(p.newPath),m.add(O.newPath),p.newPath===O.newPath){let k=r.get(p.newPath),P=s.get(O.newPath);if(k.hash===P.hash)o.entries.push(_(p.newPath,k));else{let B=it(e,p.newPath);B.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],B.pathnames=[y,p.newPath,O.newPath],B.filemask=7,B.merged={result:null,clean:!1}}}else{let k=r.get(p.newPath),P=s.get(O.newPath),B=await Zt(n,S,k,P,i);B.conflict&&w(y,`Auto-merging ${y}`,-1),o.conflicts.push({path:y,reason:"rename-rename",oursPath:p.newPath,theirsPath:O.newPath}),w(y,`CONFLICT (rename/rename): ${y} renamed to ${p.newPath} in ${b} and to ${O.newPath} in ${g}.`),o.entries.push(_(y,S,1)),o.entries.push(H(p.newPath,k.mode,B.hash,2)),o.entries.push(H(O.newPath,P.mode,B.hash,3)),o.worktreeBlobs.set(p.newPath,{hash:B.hash,mode:k.mode}),o.worktreeBlobs.set(O.newPath,{hash:B.hash,mode:P.mode})}else if(p){m.add(p.newPath);let k=s.get(y),P=r.get(p.newPath),B=h.has(p.newPath);if(k)if(B)await Xt(n,o,p.newPath,y,S,P,k,r,s,!1,i);else if(k.hash===S.hash&&P.hash===S.hash)o.entries.push(_(p.newPath,P));else if(k.hash===S.hash)o.entries.push(_(p.newPath,P));else if(P.hash===S.hash)o.entries.push(H(p.newPath,P.mode,k.hash));else{let D=it(e,p.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:P.hash,mode:P.mode},{hash:k.hash,mode:k.mode}],D.pathnames=[y,p.newPath,y],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=s.get(p.newPath);if(o.conflicts.push({path:p.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:y}),w(p.newPath,`CONFLICT (rename/delete): ${y} renamed to ${p.newPath} in ${b}, but deleted in ${g}.`),D){o.conflicts.push({path:p.newPath,reason:"add-add"}),w(p.newPath,`Auto-merging ${p.newPath}`,0),w(p.newPath,`CONFLICT (add/add): Merge conflict in ${p.newPath}`,1),o.entries.push(_(p.newPath,P,2)),o.entries.push(_(p.newPath,D,3));let Me=await $e(n,P.hash,D.hash,P.mode,i);o.worktreeBlobs.set(p.newPath,{hash:Me,mode:P.mode})}else o.entries.push(H(p.newPath,S.mode,S.hash,1)),o.entries.push(_(p.newPath,P,2)),o.worktreeBlobs.set(p.newPath,{hash:P.hash,mode:P.mode}),P.hash!==S.hash&&w(p.newPath,`CONFLICT (modify/delete): ${p.newPath} deleted in ${g} and modified in ${b}. Version ${b} of ${p.newPath} left in tree.`,1)}}else if(O){m.add(O.newPath);let k=r.get(y),P=s.get(O.newPath),B=h.has(O.newPath);if(k)if(B)await Xt(n,o,O.newPath,y,S,k,P,r,s,!0,i);else if(k.hash===S.hash&&P.hash===S.hash)o.entries.push(_(O.newPath,P));else if(k.hash===S.hash)o.entries.push(_(O.newPath,P));else if(P.hash===S.hash)o.entries.push(H(O.newPath,P.mode,k.hash));else{let D=it(e,O.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],D.pathnames=[y,y,O.newPath],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=r.get(O.newPath);if(o.conflicts.push({path:O.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:y}),w(O.newPath,`CONFLICT (rename/delete): ${y} renamed to ${O.newPath} in ${g}, but deleted in ${b}.`),D){o.conflicts.push({path:O.newPath,reason:"add-add"}),w(O.newPath,`Auto-merging ${O.newPath}`,0),w(O.newPath,`CONFLICT (add/add): Merge conflict in ${O.newPath}`,1),o.entries.push(_(O.newPath,D,2)),o.entries.push(_(O.newPath,P,3));let Me=await $e(n,D.hash,P.hash,D.mode,i);o.worktreeBlobs.set(O.newPath,{hash:Me,mode:D.mode})}else o.entries.push(H(O.newPath,S.mode,S.hash,1)),o.entries.push(_(O.newPath,P,3)),o.worktreeBlobs.set(O.newPath,{hash:P.hash,mode:P.mode}),P.hash!==S.hash&&w(O.newPath,`CONFLICT (modify/delete): ${O.newPath} deleted in ${b} and modified in ${g}. Version ${g} of ${O.newPath} left in tree.`,1)}}}let R=new Set(f.renames.map(y=>y.newPath)),j=new Set(l.renames.map(y=>y.newPath)),C=zt(t,r),x=zt(t,s),I=Vt(C,s,t),T=Vt(x,r,t),L=Kt(f.renames,I),A=Kt(l.renames,T),E=qt(L),$=qt(A);for(let y of[...E.keys()])$.has(y)&&(E.delete(y),$.delete(y));let X=new Set(E.keys()),K=new Set($.keys());if($.size>0)for(let y of a){if(y.status!=="added"||R.has(y.path))continue;let p=Yt(y.path,$,X);if(!p)continue;if(e.has(p)||t.has(p)||r.has(p)||s.has(p)){if(r.has(p)){w(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${y.path}.`,1);continue}let k=r.get(y.path),P=s.get(p)??t.get(p);o.entries.push(H(p,k.mode,k.hash,2)),P&&o.entries.push(H(p,P.mode,P.hash,3)),o.worktreeBlobs.set(p,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:p,reason:"add-add"}),w(p,`CONFLICT (file location): ${y.path} added in ${b} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,1);let B=e.get(y.path);B&&(B.merged={result:null,clean:!0}),m.add(y.path);continue}let O=r.get(y.path);o.entries.push(H(p,O.mode,O.hash,2)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),w(p,`CONFLICT (file location): ${y.path} added in ${b} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,1);let S=e.get(y.path);S&&(S.merged={result:null,clean:!0}),m.add(y.path)}if(E.size>0)for(let y of c){if(y.status!=="added"||j.has(y.path))continue;let p=Yt(y.path,E,K);if(!p)continue;if(e.has(p)||t.has(p)||r.has(p)||s.has(p)){if(s.has(p)){w(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${y.path}.`,1);continue}let k=s.get(y.path),P=r.get(p)??t.get(p);P&&o.entries.push(H(p,P.mode,P.hash,2)),o.entries.push(H(p,k.mode,k.hash,3)),o.worktreeBlobs.set(p,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:p,reason:"add-add"}),w(p,`CONFLICT (file location): ${y.path} added in ${g} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${p}.`,1);let B=e.get(y.path);B&&(B.merged={result:null,clean:!0}),m.add(y.path);continue}let O=s.get(y.path);o.entries.push(H(p,O.mode,O.hash,3)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),w(p,`CONFLICT (file location): ${y.path} added in ${g} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${p}.`,1);let S=e.get(y.path);S&&(S.merged={result:null,clean:!0}),m.add(y.path)}let ft=new Set(o.entries.map(y=>y.path));for(let y of ft){let p=e.get(y);p&&(p.merged={result:null,clean:!0})}for(let y of m){if(ft.has(y))continue;let p=e.get(y);if(!p||p.merged.clean)continue;p.filemask===7&&!p.pathConflict||(p.merged={result:null,clean:!0})}return o}function zt(n,e){let t=new Set;for(let i of n.keys()){let o=z(i);for(;o;)t.add(o),o=z(o)}let r=new Set;for(let i of e.keys()){let o=z(i);for(;o;)r.add(o),o=z(o)}let s=new Set;for(let i of t)r.has(i)||s.add(i);return s}function Vt(n,e,t){if(n.size===0)return n;let r=new Set;for(let s of e.keys()){if(t.has(s))continue;let i=z(s)??"";n.has(i)&&r.add(i)}for(let s of[...r]){let i=z(s);for(;i;)n.has(i)&&!r.has(i)&&r.add(i),i=z(i)}return r}function Kt(n,e){let t=new Map;for(let r of n){let s=z(r.oldPath),i=z(r.newPath),o=!0;for(;;){if(!o){let a=s.length+(s?1:0),c=i.length+(i?1:0),f=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(e.has(s)){let a=t.get(s);a||(a=new Map,t.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=z(s),i=z(i)}}return t}function qt(n){let e=new Map;for(let[t,r]of n){let s=0,i=0,o=null;for(let[a,c]of r)c===s?i=s:c>s&&(s=c,o=a);s>0&&i!==s&&o!==null&&e.set(t,o)}return e}function Yt(n,e,t){let r=z(n);for(;r;){let i=e.get(r);if(i!==void 0){if(t.has(i))return null;let o=n.slice(r.length+1);return i?`${i}/${o}`:o}r=z(r)}let s=e.get("");return s!==void 0&&!t.has(s)?`${s}/${n}`:null}function z(n){let e=n.lastIndexOf("/");return e===-1?"":n.slice(0,e)}async function Xt(n,e,t,r,s,i,o,a,c,f=!1,l){let u=f?a.get(t):c.get(t),d=f?o:i;if(u.hash===d.hash){e.entries.push(H(t,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await Zt(n,s,i,o,l,f?{oursPath:r,theirsPath:t}:{oursPath:t,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(H(t,u.mode,m.hash));else if(e.conflicts.push({path:t,reason:"add-add"}),e.msgBuf.push({sortKey:t,subOrder:0,text:`Auto-merging ${t}`}),e.msgBuf.push({sortKey:t,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${t}`}),f){e.entries.push(_(t,u,2)),e.entries.push(H(t,o.mode,m.hash,3));let b=await $e(n,u.hash,m.hash,u.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:u.mode})}else{e.entries.push(H(t,i.mode,m.hash,2)),e.entries.push(_(t,u,3));let b=await $e(n,m.hash,u.hash,i.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:i.mode})}}async function Zt(n,e,t,r,s,i,o){if(t.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:t.hash,conflict:!1};if(t.hash===r.hash)return{hash:t.hash,conflict:!1};if(Y(e.mode)||Y(t.mode)||Y(r.mode))return{hash:t.hash,conflict:!0};let a=await F(n,e.hash),c=await F(n,t.hash),f=await F(n,r.hash);if(J(c)||J(f)||J(a))return{hash:t.hash,conflict:!0};let l=W(a),u=W(c),d=W(f),h=be(u,l,d);if(!h.conflict)return{hash:await ot(n,h.result),conflict:!1};let m=s?.a??"HEAD",b=s?.b??"theirs",g=i?.oursPath?`${m}:${i.oursPath}`:m,w=i?.theirsPath?`${b}:${i.theirsPath}`:b,R=ie(c,a,f,{a:g,b:w,markerSize:o??7});return{hash:await N(n,"blob",ne.encode(R)),conflict:!0}}async function $e(n,e,t,r,s){let i=await F(n,e),o=await F(n,t),a=ie(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs"});return N(n,"blob",ne.encode(a))}function _(n,e,t=0){return H(n,e.mode,e.hash,t)}function H(n,e,t,r=0){return{path:n,mode:parseInt(e,8),hash:t,stage:r,stat:Q()}}async function yr(n,e,t,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,b=0){o.push({sortKey:h,subOrder:b,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(M(h,m.merged.result.hash,m.merged.result.mode));continue}await wr(n,m,t,s,i,c,a)}o.sort((h,m)=>(h.sortKey<m.sortKey?-1:h.sortKey>m.sortKey?1:0)||h.subOrder-m.subOrder);let f=o.map(h=>h.text),l=[],u=new Set;for(let h of s)h.stage===0&&(l.push(h),u.add(h.path));for(let[h,m]of a)u.has(h)||l.push(M(h,m.hash,m.mode));l.sort((h,m)=>pe(h.path,m.path));let d=await qe(n,l);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function wr(n,e,t,r,s,i,o){let a=e.path,[c,f,l]=e.stages,u=c?.hash??null,d=f?.hash??null,h=l?.hash??null;if(d===null&&h!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=t?.a??"HEAD",b=t?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${b}. Version ${b} of ${a} left in tree.`),c&&r.push(M(a,u,c.mode,1)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:h,mode:l.mode});return}if(h===null&&d!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=t?.b??"theirs",b=t?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${b}. Version ${b} of ${a} left in tree.`),c&&r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),o.set(a,{hash:d,mode:f.mode});return}if(u===null&&d!==null&&h!==null){if(d===h){r.push(M(a,d,f.mode));return}i(a,`Auto-merging ${a}`,0);let m=await F(n,d),b=await F(n,h);if(J(m)||J(b)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${t?.a??"HEAD"} vs. ${t?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let g=W(""),w=W(m),R=W(b),j=be(w,g,R,t);if(!j.conflict){let I=await ot(n,j.result);r.push(M(a,I,f.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3));let C=ie(m,"",b,{a:t?.a??"HEAD",b:t?.b??"theirs"}),x=await N(n,"blob",ne.encode(C));o.set(a,{hash:x,mode:f.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(M(a,h,l.mode));return}if(h===u){r.push(M(a,d,f.mode));return}if(d===h){r.push(M(a,d,f.mode));return}if(i(a,`Auto-merging ${a}`,0),Y(c.mode)||Y(f.mode)||Y(l.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let m=await F(n,u),b=await F(n,d),g=await F(n,h);if(J(b)||J(g)||J(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${t?.a??"HEAD"} vs. ${t?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let w=W(m),R=W(b),j=W(g),C=be(R,w,j,t);if(C.conflict){let x=e.pathnames[1],I=e.pathnames[2],T=x!==a||I!==a,L={path:a,reason:"content"};T&&(x!==a&&(L.oursOrigPath=x),I!==a&&(L.theirsOrigPath=I)),s.push(L),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3));let A=T?`${t?.a??"HEAD"}:${x}`:t?.a??"HEAD",E=T?`${t?.b??"theirs"}:${I}`:t?.b??"theirs",$=ie(b,m,g,{a:A,b:E}),X=await N(n,"blob",ne.encode($));o.set(a,{hash:X,mode:f.mode})}else{let x=await ot(n,C.result);r.push(M(a,x,f.mode))}return}}var Ir=200;async function Qt(n,e,t,r,s){let i=await Promise.all(r.map(async l=>({hash:l,timestamp:(await U(n,l)).committer.timestamp})));i.sort((l,u)=>l.timestamp-u.timestamp);let o=i.map(l=>l.hash),a=o[0],c=a,f=(await U(n,a)).tree;for(let l=1;l<o.length;l++){let u=o[l],d=(await U(n,u)).tree,h=null;if(s>=Ir)h=f;else{let g=await ge(n,c,u);g.length===0?h=null:g.length===1?h=(await U(n,g[0])).tree:h=await Qt(n,c,u,g,s+1)}let m=await ue(n,h,f,d);f=await xr(n,m,s);let b=Re({type:"commit",tree:f,parents:[c,u],author:Wt,committer:Wt,message:"merged common ancestors"});c=await N(n,"commit",b)}return f}async function xr(n,e,t){let r=e.entries.filter(a=>a.stage===0),s=new Map;for(let a of e.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let i=(a,c)=>s.get(`${a}\0${c}`),o={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+t*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let l=i(a.path,1);if(l){r.push({...l,stage:0});continue}}if(a.reason==="rename-rename"){let l=a.oursPath??a.path,u=a.theirsPath??a.path,d=i(a.path,1),h=i(l,2),m=i(u,3);if(h&&m){let b=le.decode((await V(n,h.hash)).content),g=le.decode((await V(n,m.hash)).content),w=d?le.decode((await V(n,d.hash)).content):"",R=8+t*2,j=o.a??"Temporary merge branch 1",C=o.b??"Temporary merge branch 2",x=ie(b,w,g,{a:`${j}:${l}`,o:o.o,b:`${C}:${u}`,markerSize:R}),I=await N(n,"blob",ne.encode(x));r.push({path:l,mode:h.mode,hash:I,stage:0,stat:Q()}),r.push({path:u,mode:m.mode,hash:I,stage:0,stat:Q()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(a.path,2),f=i(a.path,3);if(c&&f&&(a.reason==="content"||a.reason==="add-add")){let l=le.decode((await V(n,c.hash)).content),u=le.decode((await V(n,f.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?le.decode((await V(n,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,b=o.a??"Temporary merge branch 1",g=o.b??"Temporary merge branch 2",w=m?`${b}:${a.oursOrigPath??a.path}`:b,R=m?`${g}:${a.theirsOrigPath??a.path}`:g,j=ie(l,h,u,{a:w,o:o.o,b:R,markerSize:o.markerSize}),C=await N(n,"blob",ne.encode(j));r.push({path:a.path,mode:c.mode,hash:C,stage:0,stat:Q()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>pe(a.path,c.path)),qe(n,r)}async function ot(n,e){let t=e.map(st);if(t.length===0)return N(n,"blob",ne.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?t.join(`
15
+ `);if(e[e.length-1]==="")e.pop();else{let t=e[e.length-1]??"";e[e.length-1]=`${t}\0`}return e}function it(n){return n.endsWith("\0")?n.slice(0,-1):n}function Wt(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}var le=new TextDecoder,ne=new TextEncoder,zt={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function ue(n,e,t,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await gr(n,e,t,r),f=await yr(n,i,o,a,c,s);return wr(n,i,s,f)}async function Zt(n,e,t,r){let s=await ge(n,e,t),i=await U(n,e),o=await U(n,t);if(s.length===0)return{...await ue(n,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let f=await U(n,s[0]);return{...await ue(n,f.tree,i.tree,o.tree,r),baseTree:f.tree}}let a=await en(n,e,t,s,1);return{...await ue(n,a,i.tree,o.tree,r),baseTree:a}}async function gr(n,e,t,r){let s=await ae(n,e),i=await ae(n,t),o=await ae(n,r),a=new Set;for(let f of s.keys())a.add(f);for(let f of i.keys())a.add(f);for(let f of o.keys())a.add(f);let c=new Map;for(let f of a){let l=s.get(f)??null,u=i.get(f)??null,d=o.get(f)??null,h=l?{hash:l.hash,mode:l.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,b=d?{hash:d.hash,mode:d.mode}:null,g=(l?1:0)|(u?2:0)|(d?4:0),w=l?.hash??null,R=u?.hash??null,j=d?.hash??null,C=0;w!==null&&w===R&&(C|=3),w!==null&&w===j&&(C|=5),R!==null&&R===j&&(C|=6);let x={path:f,stages:[h,m,b],pathnames:[f,f,f],filemask:g,matchMask:C,merged:{result:null,clean:!1},pathConflict:!1};if(br(x)){c.set(f,x);continue}c.set(f,x)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function br(n){let[e,t,r]=n.stages,s=e?.hash??null,i=t?.hash??null,o=r?.hash??null;return i===s&&o===s?(t?n.merged={result:{hash:i,mode:t.mode},clean:!0}:n.merged={result:null,clean:!0},!0):i===o&&i!==null?(n.merged={result:{hash:i,mode:t.mode},clean:!0},!0):i===null&&o===null?(n.merged={result:null,clean:!0},!0):o===s&&i!==s?(t?n.merged={result:{hash:i,mode:t.mode},clean:!0}:n.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?n.merged={result:{hash:o,mode:r.mode},clean:!0}:n.merged={result:null,clean:!0},!0):!1}async function yr(n,e,t,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[y,p]of t)r.has(y)||a.push({path:y,status:"deleted",oldHash:p.hash,oldMode:p.mode}),s.has(y)||c.push({path:y,status:"deleted",oldHash:p.hash,oldMode:p.mode});for(let[y,p]of r)t.has(y)||a.push({path:y,status:"added",newHash:p.hash,newMode:p.mode});for(let[y,p]of s)t.has(y)||c.push({path:y,status:"added",newHash:p.hash,newMode:p.mode});let f=await nt(n,a),l=await nt(n,c);if(f.renames.length===0&&l.renames.length===0)return o;let u=new Map,d=new Map;for(let y of f.renames)u.set(y.oldPath,y);for(let y of l.renames)d.set(y.oldPath,y);let h=new Set;for(let[y]of r)!t.has(y)&&s.has(y)&&h.add(y);let m=new Set,b=i?.a??"HEAD",g=i?.b??"theirs";function w(y,p,O=0){o.msgBuf.push({sortKey:y,subOrder:O,text:p})}for(let y of[...t.keys()].sort()){let p=u.get(y),O=d.get(y);if(!p&&!O)continue;let S=t.get(y);if(m.add(y),p&&O)if(m.add(p.newPath),m.add(O.newPath),p.newPath===O.newPath){let k=r.get(p.newPath),P=s.get(O.newPath);if(k.hash===P.hash)o.entries.push(_(p.newPath,k));else{let B=ot(e,p.newPath);B.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],B.pathnames=[y,p.newPath,O.newPath],B.filemask=7,B.merged={result:null,clean:!1}}}else{let k=r.get(p.newPath),P=s.get(O.newPath),B=await Qt(n,S,k,P,i);B.conflict&&w(y,`Auto-merging ${y}`,-1),o.conflicts.push({path:y,reason:"rename-rename",oursPath:p.newPath,theirsPath:O.newPath}),w(y,`CONFLICT (rename/rename): ${y} renamed to ${p.newPath} in ${b} and to ${O.newPath} in ${g}.`),o.entries.push(_(y,S,1)),o.entries.push(H(p.newPath,k.mode,B.hash,2)),o.entries.push(H(O.newPath,P.mode,B.hash,3)),o.worktreeBlobs.set(p.newPath,{hash:B.hash,mode:k.mode}),o.worktreeBlobs.set(O.newPath,{hash:B.hash,mode:P.mode})}else if(p){m.add(p.newPath);let k=s.get(y),P=r.get(p.newPath),B=h.has(p.newPath);if(k)if(B)await Jt(n,o,p.newPath,y,S,P,k,r,s,!1,i);else if(k.hash===S.hash&&P.hash===S.hash)o.entries.push(_(p.newPath,P));else if(k.hash===S.hash)o.entries.push(_(p.newPath,P));else if(P.hash===S.hash)o.entries.push(H(p.newPath,P.mode,k.hash));else{let D=ot(e,p.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:P.hash,mode:P.mode},{hash:k.hash,mode:k.mode}],D.pathnames=[y,p.newPath,y],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=s.get(p.newPath);if(o.conflicts.push({path:p.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:y}),w(p.newPath,`CONFLICT (rename/delete): ${y} renamed to ${p.newPath} in ${b}, but deleted in ${g}.`),D){o.conflicts.push({path:p.newPath,reason:"add-add"}),w(p.newPath,`Auto-merging ${p.newPath}`,0),w(p.newPath,`CONFLICT (add/add): Merge conflict in ${p.newPath}`,1),o.entries.push(_(p.newPath,P,2)),o.entries.push(_(p.newPath,D,3));let Le=await ve(n,P.hash,D.hash,P.mode,i);o.worktreeBlobs.set(p.newPath,{hash:Le,mode:P.mode})}else o.entries.push(H(p.newPath,S.mode,S.hash,1)),o.entries.push(_(p.newPath,P,2)),o.worktreeBlobs.set(p.newPath,{hash:P.hash,mode:P.mode}),P.hash!==S.hash&&w(p.newPath,`CONFLICT (modify/delete): ${p.newPath} deleted in ${g} and modified in ${b}. Version ${b} of ${p.newPath} left in tree.`,1)}}else if(O){m.add(O.newPath);let k=r.get(y),P=s.get(O.newPath),B=h.has(O.newPath);if(k)if(B)await Jt(n,o,O.newPath,y,S,k,P,r,s,!0,i);else if(k.hash===S.hash&&P.hash===S.hash)o.entries.push(_(O.newPath,P));else if(k.hash===S.hash)o.entries.push(_(O.newPath,P));else if(P.hash===S.hash)o.entries.push(H(O.newPath,P.mode,k.hash));else{let D=ot(e,O.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],D.pathnames=[y,y,O.newPath],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=r.get(O.newPath);if(o.conflicts.push({path:O.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:y}),w(O.newPath,`CONFLICT (rename/delete): ${y} renamed to ${O.newPath} in ${g}, but deleted in ${b}.`),D){o.conflicts.push({path:O.newPath,reason:"add-add"}),w(O.newPath,`Auto-merging ${O.newPath}`,0),w(O.newPath,`CONFLICT (add/add): Merge conflict in ${O.newPath}`,1),o.entries.push(_(O.newPath,D,2)),o.entries.push(_(O.newPath,P,3));let Le=await ve(n,D.hash,P.hash,D.mode,i);o.worktreeBlobs.set(O.newPath,{hash:Le,mode:D.mode})}else o.entries.push(H(O.newPath,S.mode,S.hash,1)),o.entries.push(_(O.newPath,P,3)),o.worktreeBlobs.set(O.newPath,{hash:P.hash,mode:P.mode}),P.hash!==S.hash&&w(O.newPath,`CONFLICT (modify/delete): ${O.newPath} deleted in ${b} and modified in ${g}. Version ${g} of ${O.newPath} left in tree.`,1)}}}let R=new Set(f.renames.map(y=>y.newPath)),j=new Set(l.renames.map(y=>y.newPath)),C=Vt(t,r),x=Vt(t,s),I=Kt(C,s,t),T=Kt(x,r,t),L=qt(f.renames,I),A=qt(l.renames,T),E=Yt(L),$=Yt(A);for(let y of[...E.keys()])$.has(y)&&(E.delete(y),$.delete(y));let X=new Set(E.keys()),K=new Set($.keys());if($.size>0)for(let y of a){if(y.status!=="added"||R.has(y.path))continue;let p=Xt(y.path,$,X);if(!p)continue;if(e.has(p)||t.has(p)||r.has(p)||s.has(p)){if(r.has(p)){w(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${y.path}.`,1);continue}let k=r.get(y.path),P=s.get(p)??t.get(p);o.entries.push(H(p,k.mode,k.hash,2)),P&&o.entries.push(H(p,P.mode,P.hash,3)),o.worktreeBlobs.set(p,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:p,reason:"add-add"}),w(p,`CONFLICT (file location): ${y.path} added in ${b} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,1);let B=e.get(y.path);B&&(B.merged={result:null,clean:!0}),m.add(y.path);continue}let O=r.get(y.path);o.entries.push(H(p,O.mode,O.hash,2)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),w(p,`CONFLICT (file location): ${y.path} added in ${b} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,1);let S=e.get(y.path);S&&(S.merged={result:null,clean:!0}),m.add(y.path)}if(E.size>0)for(let y of c){if(y.status!=="added"||j.has(y.path))continue;let p=Xt(y.path,E,K);if(!p)continue;if(e.has(p)||t.has(p)||r.has(p)||s.has(p)){if(s.has(p)){w(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${y.path}.`,1);continue}let k=s.get(y.path),P=r.get(p)??t.get(p);P&&o.entries.push(H(p,P.mode,P.hash,2)),o.entries.push(H(p,k.mode,k.hash,3)),o.worktreeBlobs.set(p,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:p,reason:"add-add"}),w(p,`CONFLICT (file location): ${y.path} added in ${g} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${p}.`,1);let B=e.get(y.path);B&&(B.merged={result:null,clean:!0}),m.add(y.path);continue}let O=s.get(y.path);o.entries.push(H(p,O.mode,O.hash,3)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),w(p,`CONFLICT (file location): ${y.path} added in ${g} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${p}.`,1);let S=e.get(y.path);S&&(S.merged={result:null,clean:!0}),m.add(y.path)}let lt=new Set(o.entries.map(y=>y.path));for(let y of lt){let p=e.get(y);p&&(p.merged={result:null,clean:!0})}for(let y of m){if(lt.has(y))continue;let p=e.get(y);if(!p||p.merged.clean)continue;p.filemask===7&&!p.pathConflict||(p.merged={result:null,clean:!0})}return o}function Vt(n,e){let t=new Set;for(let i of n.keys()){let o=z(i);for(;o;)t.add(o),o=z(o)}let r=new Set;for(let i of e.keys()){let o=z(i);for(;o;)r.add(o),o=z(o)}let s=new Set;for(let i of t)r.has(i)||s.add(i);return s}function Kt(n,e,t){if(n.size===0)return n;let r=new Set;for(let s of e.keys()){if(t.has(s))continue;let i=z(s)??"";n.has(i)&&r.add(i)}for(let s of[...r]){let i=z(s);for(;i;)n.has(i)&&!r.has(i)&&r.add(i),i=z(i)}return r}function qt(n,e){let t=new Map;for(let r of n){let s=z(r.oldPath),i=z(r.newPath),o=!0;for(;;){if(!o){let a=s.length+(s?1:0),c=i.length+(i?1:0),f=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(e.has(s)){let a=t.get(s);a||(a=new Map,t.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=z(s),i=z(i)}}return t}function Yt(n){let e=new Map;for(let[t,r]of n){let s=0,i=0,o=null;for(let[a,c]of r)c===s?i=s:c>s&&(s=c,o=a);s>0&&i!==s&&o!==null&&e.set(t,o)}return e}function Xt(n,e,t){let r=z(n);for(;r;){let i=e.get(r);if(i!==void 0){if(t.has(i))return null;let o=n.slice(r.length+1);return i?`${i}/${o}`:o}r=z(r)}let s=e.get("");return s!==void 0&&!t.has(s)?`${s}/${n}`:null}function z(n){let e=n.lastIndexOf("/");return e===-1?"":n.slice(0,e)}async function Jt(n,e,t,r,s,i,o,a,c,f=!1,l){let u=f?a.get(t):c.get(t),d=f?o:i;if(u.hash===d.hash){e.entries.push(H(t,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await Qt(n,s,i,o,l,f?{oursPath:r,theirsPath:t}:{oursPath:t,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(H(t,u.mode,m.hash));else if(e.conflicts.push({path:t,reason:"add-add"}),e.msgBuf.push({sortKey:t,subOrder:0,text:`Auto-merging ${t}`}),e.msgBuf.push({sortKey:t,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${t}`}),f){e.entries.push(_(t,u,2)),e.entries.push(H(t,o.mode,m.hash,3));let b=await ve(n,u.hash,m.hash,u.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:u.mode})}else{e.entries.push(H(t,i.mode,m.hash,2)),e.entries.push(_(t,u,3));let b=await ve(n,m.hash,u.hash,i.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:i.mode})}}async function Qt(n,e,t,r,s,i,o){if(t.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:t.hash,conflict:!1};if(t.hash===r.hash)return{hash:t.hash,conflict:!1};if(Y(e.mode)||Y(t.mode)||Y(r.mode))return{hash:t.hash,conflict:!0};let a=await F(n,e.hash),c=await F(n,t.hash),f=await F(n,r.hash);if(J(c)||J(f)||J(a))return{hash:t.hash,conflict:!0};let l=W(a),u=W(c),d=W(f),h=be(u,l,d);if(!h.conflict)return{hash:await at(n,h.result),conflict:!1};let m=s?.a??"HEAD",b=s?.b??"theirs",g=i?.oursPath?`${m}:${i.oursPath}`:m,w=i?.theirsPath?`${b}:${i.theirsPath}`:b,R=ie(c,a,f,{a:g,b:w,markerSize:o??7});return{hash:await N(n,"blob",ne.encode(R)),conflict:!0}}async function ve(n,e,t,r,s){let i=await F(n,e),o=await F(n,t),a=ie(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs"});return N(n,"blob",ne.encode(a))}function _(n,e,t=0){return H(n,e.mode,e.hash,t)}function H(n,e,t,r=0){return{path:n,mode:parseInt(e,8),hash:t,stage:r,stat:Q()}}async function wr(n,e,t,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,b=0){o.push({sortKey:h,subOrder:b,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(M(h,m.merged.result.hash,m.merged.result.mode));continue}await Ir(n,m,t,s,i,c,a)}o.sort((h,m)=>(h.sortKey<m.sortKey?-1:h.sortKey>m.sortKey?1:0)||h.subOrder-m.subOrder);let f=o.map(h=>h.text),l=[],u=new Set;for(let h of s)h.stage===0&&(l.push(h),u.add(h.path));for(let[h,m]of a)u.has(h)||l.push(M(h,m.hash,m.mode));l.sort((h,m)=>pe(h.path,m.path));let d=await Xe(n,l);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function Ir(n,e,t,r,s,i,o){let a=e.path,[c,f,l]=e.stages,u=c?.hash??null,d=f?.hash??null,h=l?.hash??null;if(d===null&&h!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=t?.a??"HEAD",b=t?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${b}. Version ${b} of ${a} left in tree.`),c&&r.push(M(a,u,c.mode,1)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:h,mode:l.mode});return}if(h===null&&d!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=t?.b??"theirs",b=t?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${b}. Version ${b} of ${a} left in tree.`),c&&r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),o.set(a,{hash:d,mode:f.mode});return}if(u===null&&d!==null&&h!==null){if(d===h){r.push(M(a,d,f.mode));return}i(a,`Auto-merging ${a}`,0);let m=await F(n,d),b=await F(n,h);if(J(m)||J(b)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${t?.a??"HEAD"} vs. ${t?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let g=W(""),w=W(m),R=W(b),j=be(w,g,R,t);if(!j.conflict){let I=await at(n,j.result);r.push(M(a,I,f.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3));let C=ie(m,"",b,{a:t?.a??"HEAD",b:t?.b??"theirs"}),x=await N(n,"blob",ne.encode(C));o.set(a,{hash:x,mode:f.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(M(a,h,l.mode));return}if(h===u){r.push(M(a,d,f.mode));return}if(d===h){r.push(M(a,d,f.mode));return}if(i(a,`Auto-merging ${a}`,0),Y(c.mode)||Y(f.mode)||Y(l.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let m=await F(n,u),b=await F(n,d),g=await F(n,h);if(J(b)||J(g)||J(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${t?.a??"HEAD"} vs. ${t?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let w=W(m),R=W(b),j=W(g),C=be(R,w,j,t);if(C.conflict){let x=e.pathnames[1],I=e.pathnames[2],T=x!==a||I!==a,L={path:a,reason:"content"};T&&(x!==a&&(L.oursOrigPath=x),I!==a&&(L.theirsOrigPath=I)),s.push(L),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3));let A=T?`${t?.a??"HEAD"}:${x}`:t?.a??"HEAD",E=T?`${t?.b??"theirs"}:${I}`:t?.b??"theirs",$=ie(b,m,g,{a:A,b:E}),X=await N(n,"blob",ne.encode($));o.set(a,{hash:X,mode:f.mode})}else{let x=await at(n,C.result);r.push(M(a,x,f.mode))}return}}var xr=200;async function en(n,e,t,r,s){let i=await Promise.all(r.map(async l=>({hash:l,timestamp:(await U(n,l)).committer.timestamp})));i.sort((l,u)=>l.timestamp-u.timestamp);let o=i.map(l=>l.hash),a=o[0],c=a,f=(await U(n,a)).tree;for(let l=1;l<o.length;l++){let u=o[l],d=(await U(n,u)).tree,h=null;if(s>=xr)h=f;else{let g=await ge(n,c,u);g.length===0?h=null:g.length===1?h=(await U(n,g[0])).tree:h=await en(n,c,u,g,s+1)}let m=await ue(n,h,f,d);f=await Or(n,m,s);let b=Re({type:"commit",tree:f,parents:[c,u],author:zt,committer:zt,message:"merged common ancestors"});c=await N(n,"commit",b)}return f}async function Or(n,e,t){let r=e.entries.filter(a=>a.stage===0),s=new Map;for(let a of e.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let i=(a,c)=>s.get(`${a}\0${c}`),o={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+t*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let l=i(a.path,1);if(l){r.push({...l,stage:0});continue}}if(a.reason==="rename-rename"){let l=a.oursPath??a.path,u=a.theirsPath??a.path,d=i(a.path,1),h=i(l,2),m=i(u,3);if(h&&m){let b=le.decode((await V(n,h.hash)).content),g=le.decode((await V(n,m.hash)).content),w=d?le.decode((await V(n,d.hash)).content):"",R=8+t*2,j=o.a??"Temporary merge branch 1",C=o.b??"Temporary merge branch 2",x=ie(b,w,g,{a:`${j}:${l}`,o:o.o,b:`${C}:${u}`,markerSize:R}),I=await N(n,"blob",ne.encode(x));r.push({path:l,mode:h.mode,hash:I,stage:0,stat:Q()}),r.push({path:u,mode:m.mode,hash:I,stage:0,stat:Q()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(a.path,2),f=i(a.path,3);if(c&&f&&(a.reason==="content"||a.reason==="add-add")){let l=le.decode((await V(n,c.hash)).content),u=le.decode((await V(n,f.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?le.decode((await V(n,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,b=o.a??"Temporary merge branch 1",g=o.b??"Temporary merge branch 2",w=m?`${b}:${a.oursOrigPath??a.path}`:b,R=m?`${g}:${a.theirsOrigPath??a.path}`:g,j=ie(l,h,u,{a:w,o:o.o,b:R,markerSize:o.markerSize}),C=await N(n,"blob",ne.encode(j));r.push({path:a.path,mode:c.mode,hash:C,stage:0,stat:Q()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>pe(a.path,c.path)),Xe(n,r)}async function at(n,e){let t=e.map(it);if(t.length===0)return N(n,"blob",ne.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?t.join(`
16
16
  `):`${t.join(`
17
17
  `)}
18
- `;return N(n,"blob",ne.encode(i))}function M(n,e,t,r=0){let s=typeof t=="string"?parseInt(t,8):t;return{path:n,mode:s,hash:e,stage:r,stat:Q()}}function it(n,e){let t=n.get(e);return t||(t={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},n.set(e,t)),t}async function*Or(n,e,t){let r=e?[e]:[];for await(let s of Je(n,t,{exclude:r}))yield{hash:s.hash,message:s.commit.message,tree:s.commit.tree,parents:s.commit.parents,author:s.commit.author,committer:s.commit.committer}}async function Pr(n,e,t){let r=await U(n,t),s=null;return e&&(s=(await U(n,e)).tree),Ye(n,s,r.tree)}async function Rr(n,e,t){return nt(n,e,t)}async function kr(n,e){return ke(n,e)}async function Er(n){return Ke(n,"refs/heads")}async function Tr(n){return Ke(n,"refs/tags")}async function Sr(n,e){return U(n,e)}async function jr(n,e){return Z(n,e)}async function Cr(n,e){return F(n,e)}async function Ar(n,e){return se(n,e)}async function $r(n,e,t){return Ye(n,e,t)}async function Mr(n,e,t){return ge(n,e,t)}async function vr(n,e,t,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await Jt(n,e,t,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function Lr(n,e,t,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await ue(n,e,t,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}async function Ur(n,e){let t=Re({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message});return N(n,"commit",t)}async function Br(n,e){let t=[...e].sort((s,i)=>s.name.localeCompare(i.name)),r=Ee({type:"tree",entries:t.map(s=>({mode:s.mode??"100644",name:s.name,hash:s.hash}))});return N(n,"tree",r)}async function Dr(n,e){return N(n,"blob",new TextEncoder().encode(e))}async function Hr(n,e,t){let r=await U(n,e),i=(await se(n,r.tree)).find(o=>o.path===t);return i?F(n,i.hash):null}var en=/^[0-9a-f]{40}$/;async function Nr(n,e,t,r="/"){let s=await ke(n,e);if(!s)if(en.test(e)&&await n.objectStore.exists(e))s=e;else throw new Error(`ref or commit '${e}' not found`);let i=await U(n,s),o=await se(n,i.tree),a=new Set,c=0;for(let f of o){let l=v(r,f.path),u=ve(l);if(u!==r&&!a.has(u)&&(await t.mkdir(u,{recursive:!0}),a.add(u)),Y(f.mode)){let d=await F(n,f.hash);t.symlink?await t.symlink(d,l):await t.writeFile(l,d)}else{let d=await Z(n,f.hash);await t.writeFile(l,d)}c++}return{commitHash:s,treeHash:i.tree,filesWritten:c}}async function Fr(n,e,t){let r=t?.workTree??"/",s=t?.gitDir??v(r,".git"),i=t?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await ke(n,i);if(!o)if(en.test(i)&&await n.objectStore.exists(i))o=i;else throw new Error(`ref or commit '${i}' not found`);let a=await U(n,o),c=await se(n,a.tree),f={...n,fs:e,gitDir:s,workTree:r},l=new Set,u=0;for(let h of c){let m=v(r,h.path),b=ve(m);if(b!==r&&!l.has(b)&&(await e.mkdir(b,{recursive:!0}),l.add(b)),Y(h.mode)){let g=await F(n,h.hash);e.symlink?await e.symlink(g,m):await e.writeFile(m,g)}else{let g=await Z(n,h.hash);await e.writeFile(m,g)}u++}let d=ht(c.map(h=>({path:h.path,mode:parseInt(h.mode,8),hash:h.hash,stage:0,stat:Q()})));return await Ue(f,d),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:u}}var at=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,t){throw new Error("cannot write: object store is read-only")}exists(e){return this.inner.exists(e)}ingestPack(e){throw new Error("cannot ingest pack: object store is read-only")}findByPrefix(e){return this.inner.findByPrefix(e)}},ct=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,t){throw new Error("cannot write ref: ref store is read-only")}deleteRef(e){throw new Error("cannot delete ref: ref store is read-only")}listRefs(e){return this.inner.listRefs(e)}compareAndSwapRef(e,t,r){throw new Error("cannot update ref: ref store is read-only")}};function Gr(n){return{objectStore:new at(n.objectStore),refStore:new ct(n.refStore),hooks:n.hooks}}export{Ve as FileSystemRefStore,Ge as PackedObjectStore,Nr as checkoutTo,Ur as createCommit,Fr as createWorktree,$r as diffTrees,Mr as findMergeBases,Ar as flattenTree,Pr as getChangedFiles,Or as getNewCommits,Rr as isAncestor,Er as listBranches,Tr as listTags,vr as mergeTrees,Lr as mergeTreesFromTreeHashes,jr as readBlob,Cr as readBlobText,Sr as readCommit,Hr as readFileAtCommit,Gr as readonlyRepo,kr as resolveRef,Dr as writeBlob,Br as writeTree};
18
+ `;return N(n,"blob",ne.encode(i))}function M(n,e,t,r=0){let s=typeof t=="string"?parseInt(t,8):t;return{path:n,mode:s,hash:e,stage:r,stat:Q()}}function ot(n,e){let t=n.get(e);return t||(t={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},n.set(e,t)),t}async function*Pr(n,e,t){let r=e?[e]:[];for await(let s of Ze(n,t,{exclude:r}))yield{hash:s.hash,message:s.commit.message,tree:s.commit.tree,parents:s.commit.parents,author:s.commit.author,committer:s.commit.committer}}async function Rr(n,e,t){let r=await U(n,t),s=null;return e&&(s=(await U(n,e)).tree),Je(n,s,r.tree)}async function kr(n,e,t){return rt(n,e,t)}async function Er(n,e){return ke(n,e)}async function Tr(n){return Ye(n,"refs/heads")}async function Sr(n){return Ye(n,"refs/tags")}async function jr(n,e){return U(n,e)}async function Cr(n,e){return Z(n,e)}async function Ar(n,e){return F(n,e)}async function $r(n,e){return se(n,e)}async function Mr(n,e,t){return Je(n,e,t)}async function vr(n,e,t){return ge(n,e,t)}async function Lr(n,e,t,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await Zt(n,e,t,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function Ur(n,e,t,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await ue(n,e,t,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}async function Br(n,e){let t=Re({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message});return N(n,"commit",t)}async function Dr(n,e){let t=[...e].sort((s,i)=>s.name.localeCompare(i.name)),r=Ee({type:"tree",entries:t.map(s=>({mode:s.mode??"100644",name:s.name,hash:s.hash}))});return N(n,"tree",r)}async function Hr(n,e){return N(n,"blob",new TextEncoder().encode(e))}async function Nr(n,e,t){let r=await U(n,e),i=(await se(n,r.tree)).find(o=>o.path===t);return i?F(n,i.hash):null}var tn=/^[0-9a-f]{40}$/;async function Fr(n,e,t,r="/"){let s=await ke(n,e);if(!s)if(tn.test(e)&&await n.objectStore.exists(e))s=e;else throw new Error(`ref or commit '${e}' not found`);let i=await U(n,s),o=await se(n,i.tree),a=new Set,c=0;for(let f of o){let l=v(r,f.path),u=Ue(l);if(u!==r&&!a.has(u)&&(await t.mkdir(u,{recursive:!0}),a.add(u)),Y(f.mode)){let d=await F(n,f.hash);t.symlink?await t.symlink(d,l):await t.writeFile(l,d)}else{let d=await Z(n,f.hash);await t.writeFile(l,d)}c++}return{commitHash:s,treeHash:i.tree,filesWritten:c}}async function Gr(n,e,t){let r=t?.workTree??"/",s=t?.gitDir??v(r,".git"),i=t?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await ke(n,i);if(!o)if(tn.test(i)&&await n.objectStore.exists(i))o=i;else throw new Error(`ref or commit '${i}' not found`);let a=await U(n,o),c=await se(n,a.tree),f={...n,fs:e,gitDir:s,workTree:r},l=new Set,u=0;for(let h of c){let m=v(r,h.path),b=Ue(m);if(b!==r&&!l.has(b)&&(await e.mkdir(b,{recursive:!0}),l.add(b)),Y(h.mode)){let g=await F(n,h.hash);e.symlink?await e.symlink(g,m):await e.writeFile(m,g)}else{let g=await Z(n,h.hash);await e.writeFile(m,g)}u++}let d=dt(c.map(h=>({path:h.path,mode:parseInt(h.mode,8),hash:h.hash,stage:0,stat:Q()})));return await De(f,d),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:u}}var ct=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,t){throw new Error("cannot write: object store is read-only")}exists(e){return this.inner.exists(e)}ingestPack(e){throw new Error("cannot ingest pack: object store is read-only")}findByPrefix(e){return this.inner.findByPrefix(e)}},ft=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,t){throw new Error("cannot write ref: ref store is read-only")}deleteRef(e){throw new Error("cannot delete ref: ref store is read-only")}listRefs(e){return this.inner.listRefs(e)}compareAndSwapRef(e,t,r){throw new Error("cannot update ref: ref store is read-only")}};function _r(n){return{objectStore:new ct(n.objectStore),refStore:new ft(n.refStore),hooks:n.hooks}}export{qe as FileSystemRefStore,We as PackedObjectStore,Fr as checkoutTo,Br as createCommit,Gr as createWorktree,Mr as diffTrees,vr as findMergeBases,$r as flattenTree,Rr as getChangedFiles,Pr as getNewCommits,kr as isAncestor,Tr as listBranches,Sr as listTags,Lr as mergeTrees,Ur as mergeTreesFromTreeHashes,Cr as readBlob,Ar as readBlobText,jr as readCommit,Nr as readFileAtCommit,_r as readonlyRepo,Er as resolveRef,Hr as writeBlob,Dr as writeTree};
@@ -123,6 +123,30 @@ interface RefAdvertisement {
123
123
  * ```
124
124
  */
125
125
  declare function createGitServer(config: GitServerConfig): GitServer;
126
+ interface NodeHttpRequest {
127
+ method?: string;
128
+ url?: string;
129
+ headers: Record<string, string | string[] | undefined>;
130
+ on(event: string, listener: (...args: any[]) => void): any;
131
+ }
132
+ interface NodeHttpResponse {
133
+ writeHead(statusCode: number, headers?: Record<string, string | string[]>): any;
134
+ write(chunk: any): any;
135
+ end(data?: string): any;
136
+ }
137
+ /**
138
+ * Adapt a `GitServer` to Node.js's `http.createServer` callback.
139
+ *
140
+ * Converts between Node's `IncomingMessage`/`ServerResponse` and the
141
+ * web-standard `Request`/`Response` used by the server handler.
142
+ *
143
+ * ```ts
144
+ * import http from "node:http";
145
+ * const httpServer = http.createServer(toNodeHandler(server));
146
+ * httpServer.listen(4280);
147
+ * ```
148
+ */
149
+ declare function toNodeHandler(server: GitServer): (req: NodeHttpRequest, res: NodeHttpResponse) => void;
126
150
  /**
127
151
  * Compose multiple hook sets into a single `ServerHooks` object.
128
152
  *
@@ -292,6 +316,29 @@ interface SqliteDatabase {
292
316
  prepare(sql: string): SqliteStatement;
293
317
  transaction<F extends (...args: any[]) => any>(fn: F): (...args: Parameters<F>) => ReturnType<F>;
294
318
  }
319
+ interface BetterSqlite3Statement {
320
+ run(...params: any[]): any;
321
+ get(...params: any[]): any;
322
+ all(...params: any[]): any[];
323
+ }
324
+ interface BetterSqlite3Database {
325
+ exec(sql: string): any;
326
+ prepare(sql: string): BetterSqlite3Statement;
327
+ transaction<F extends (...args: any[]) => any>(fn: F): (...args: Parameters<F>) => ReturnType<F>;
328
+ }
329
+ /**
330
+ * Wrap a `better-sqlite3` database into a `SqliteDatabase`.
331
+ *
332
+ * Adapts `exec` → `run` and coerces `get` results from `undefined`
333
+ * to `null` to match the `bun:sqlite` convention.
334
+ *
335
+ * ```ts
336
+ * import Database from "better-sqlite3";
337
+ * const db = wrapBetterSqlite3(new Database("repos.sqlite"));
338
+ * const storage = new SqliteStorage(db);
339
+ * ```
340
+ */
341
+ declare function wrapBetterSqlite3(raw: BetterSqlite3Database): SqliteDatabase;
295
342
  /**
296
343
  * SQLite-backed git storage with multi-repo support.
297
344
  *
@@ -374,4 +421,4 @@ declare class PgStorage implements Storage {
374
421
  deleteRepo(repoId: string): Promise<void>;
375
422
  }
376
423
 
377
- export { type AdvertiseRefsEvent, type GitServer, type GitServerConfig, MemoryStorage, PackCache, type PgDatabase, type PgPool, type PgPoolClient, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type ReceivePackResult, type RefAdvertisement, type RefUpdate, type RefsData, Rejection, type ServerHooks, type SqliteDatabase, type SqliteStatement, SqliteStorage, type StandardHooksConfig, type Storage, type UpdateEvent, type UploadPackOptions, buildRefAdvertisementBytes, collectRefs, composeHooks, createGitServer, createStandardHooks, handleUploadPack, ingestReceivePack, wrapPgPool };
424
+ export { type AdvertiseRefsEvent, type BetterSqlite3Database, type BetterSqlite3Statement, type GitServer, type GitServerConfig, MemoryStorage, type NodeHttpRequest, type NodeHttpResponse, PackCache, type PgDatabase, type PgPool, type PgPoolClient, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type ReceivePackResult, type RefAdvertisement, type RefUpdate, type RefsData, Rejection, type ServerHooks, type SqliteDatabase, type SqliteStatement, SqliteStorage, type StandardHooksConfig, type Storage, type UpdateEvent, type UploadPackOptions, buildRefAdvertisementBytes, collectRefs, composeHooks, createGitServer, createStandardHooks, handleUploadPack, ingestReceivePack, toNodeHandler, wrapBetterSqlite3, wrapPgPool };