just-git 1.2.12 → 1.3.0

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,20 +1,24 @@
1
- var Me=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});function Bn(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.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}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function D(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":Bn(e)}function Xe(t){if(t==="")return".";if(t==="/")return"/";let e=t.length;for(;e>1&&t.charCodeAt(e-1)===47;)e--;let n=t.slice(0,e),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}var Ct=(()=>{let t=new Array(256);for(let e=0;e<256;e++)t[e]=(e>>4).toString(16)+(e&15).toString(16);return t})();function le(t){let e="";for(let n=0;n<20;n++)e+=Ct[t[n]];return e}function Oe(t,e){let n="";for(let r=0;r<20;r++)n+=Ct[t[e+r]];return n}function Y(t){let e=new Uint8Array(20);for(let n=0;n<20;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}function jt(t){return t.length===4&&t.toLowerCase()===".git"}function Je(t){if(t.length===0||t.includes("\0")||t.charCodeAt(0)===47||t.charCodeAt(t.length-1)===47)return!1;let e=t.split("/");for(let n of e)if(n.length===0||n==="."||n===".."||jt(n))return!1;return!0}function Ze(t,e){return e===t?!1:t==="/"?e.startsWith("/")&&e.length>1:e.startsWith(t+"/")}function Qe(t){if(t.length===0||t.charCodeAt(0)===47)return!1;let e=t.split("/");for(let n of e)if(n===".."||jt(n))return!1;return!0}var Dn=new TextEncoder;function et(t){return typeof t=="string"?Dn.encode(t):t}function Hn(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(et(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=Me(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(et(r)),n},hex:()=>Promise.resolve(e.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let t=[],e={update(n){return t.push(et(n)),e},async hex(){let n=0;for(let o of t)n+=o.byteLength;let r=new Uint8Array(n),s=0;for(let o of t)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return le(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 At=Hn(),Ee=At;async function me(t){return At().update(t).hex()}var Nn=1145655875,Fn=2;async function tt(t,e){let n=D(t.gitDir,"index"),r=await Gn(e);await t.fs.writeFile(n,r)}function $t(t){let e=[...t].sort(Lt);return{version:Fn,entries:e}}function re(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function Gn(t){let e=new TextEncoder,n=[...t.entries].sort(Lt),r=[],s=12;for(let d of n){let l=e.encode(d.path);r.push(l);let m=62+l.byteLength+1;s+=Math.ceil(m/8)*8}s+=20;let i=new ArrayBuffer(s),o=new Uint8Array(i),a=new DataView(i),c=0;a.setUint32(c,Nn),c+=4,a.setUint32(c,t.version),c+=4,a.setUint32(c,n.length),c+=4;for(let d=0;d<n.length;d++){let l=n[d],m=r[d],g=c;a.setUint32(c,l.stat.ctimeSeconds),a.setUint32(c+4,l.stat.ctimeNanoseconds),a.setUint32(c+8,l.stat.mtimeSeconds),a.setUint32(c+12,l.stat.mtimeNanoseconds),a.setUint32(c+16,l.stat.dev),a.setUint32(c+20,l.stat.ino),a.setUint32(c+24,l.mode),a.setUint32(c+28,l.stat.uid),a.setUint32(c+32,l.stat.gid),a.setUint32(c+36,l.stat.size),c+=40;let p=Y(l.hash);o.set(p,c),c+=20;let I=Math.min(m.byteLength,4095),k=(l.stage&3)<<12|I;a.setUint16(c,k),c+=2,o.set(m,c),c+=m.byteLength,o[c]=0,c+=1;let j=62+m.byteLength+1,A=Math.ceil(j/8)*8;c=g+A}let f=o.subarray(0,c),u=await me(f),h=Y(u);return o.set(h,c),o}function Lt(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}var _n=new Set(["tree","commit","tag"]),ve=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,n){if(!_n.has(n.type))return;let r=n.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,n),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 t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;Mt[t]=e}function vt(t){let e=4294967295;for(let n=0;n<t.byteLength;n++)e=Mt[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}var J=Uint8Array,pe=Uint16Array,Wn=Int32Array,Ut=new J([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Bt=new J([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),zn=new J([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Dt=(t,e)=>{let n=new pe(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new Wn(n[30]);for(let s=1;s<30;++s)for(let i=n[s];i<n[s+1];++i)r[i]=i-n[s]<<5|s;return{b:n,r}},{b:Ht}=Dt(Ut,2);Ht[28]=258;var{b:Vn}=Dt(Bt,0),st=new pe(32768);for(let t=0;t<32768;++t){let e=(t&43690)>>1|(t&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,st[t]=((e&65280)>>8|(e&255)<<8)>>1}var Pe=(t,e,n)=>{let r=t.length,s=0,i=new pe(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let o=new pe(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;let a;if(n){a=new pe(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let f=s<<4|t[s],u=e-t[s],h=o[t[s]-1]++<<u;for(let d=h|(1<<u)-1;h<=d;++h)a[st[h]>>c]=f}}else for(a=new pe(r),s=0;s<r;++s)t[s]&&(a[s]=st[o[t[s]-1]++]>>15-t[s]);return a},ke=new J(288);for(let t=0;t<144;++t)ke[t]=8;for(let t=144;t<256;++t)ke[t]=9;for(let t=256;t<280;++t)ke[t]=7;for(let t=280;t<288;++t)ke[t]=8;var Nt=new J(32);for(let t=0;t<32;++t)Nt[t]=5;var Kn=Pe(ke,9,1),qn=Pe(Nt,5,1),nt=t=>{let e=t[0];for(let n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},X=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},rt=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},Ft=t=>(t+7)/8|0,Yn=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new J(t.subarray(e,n))),Z=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},Gt=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new J(0);let o=!n,a=o||e.i!=2,c=e.i;o&&(n=new J(s*3));let f=k=>{let j=n.length;if(k>j){let A=new J(Math.max(j*2,k));A.set(n),n=A}},u=e.f||0,h=e.p||0,d=e.b||0,l=e.l,m=e.d,g=e.m,p=e.n,I=s*8;do{if(!l){u=X(t,h,1);let E=X(t,h+1,3);if(h+=3,E)if(E==1)l=Kn,m=qn,g=9,p=5;else if(E==2){let y=X(t,h,31)+257,O=X(t,h+10,15)+4,T=y+X(t,h+5,31)+1;h+=14;let x=new J(T),P=new J(19);for(let b=0;b<O;++b)P[zn[b]]=X(t,h+b*3,7);h+=O*3;let S=nt(P),$=(1<<S)-1,v=Pe(P,S,1);for(let b=0;b<T;){let R=v[X(t,h,$)];h+=R&15;let M=R>>4;if(M<16)x[b++]=M;else{let L=0,C=0;for(M==16?(C=3+X(t,h,3),h+=2,L=x[b-1]):M==17?(C=3+X(t,h,7),h+=3):M==18&&(C=11+X(t,h,127),h+=7);C--;)x[b++]=L}}let ne=x.subarray(0,y),w=x.subarray(y);g=nt(ne),p=nt(w),l=Pe(ne,g,1),m=Pe(w,p,1)}else Z(1);else{let y=Ft(h)+4,O=t[y-4]|t[y-3]<<8,T=y+O;if(T>s){c&&Z(0);break}a&&f(d+O),n.set(t.subarray(y,T),d),e.b=d+=O,e.p=h=T*8,e.f=u;continue}if(h>I){c&&Z(0);break}}a&&f(d+131072);let k=(1<<g)-1,j=(1<<p)-1,A=h;for(;;A=h){let E=l[rt(t,h)&k],y=E>>4;if(h+=E&15,h>I){c&&Z(0);break}if(E||Z(2),y<256)n[d++]=y;else if(y==256){A=h,l=null;break}else{let O=y-254;if(y>264){let $=y-257,v=Ut[$];O=X(t,h,(1<<v)-1)+Ht[$],h+=v}let T=m[rt(t,h)&j],x=T>>4;T||Z(3),h+=T&15;let P=Vn[x];if(x>3){let $=Bt[x];P+=rt(t,h)&(1<<$)-1,h+=$}if(h>I){c&&Z(0);break}a&&f(d+131072);let S=d+O;if(d<P){let $=i-P,v=Math.min(P,S);for($+d<0&&Z(3);d<v;++d)n[d]=r[$+d]}for(;d<S;++d)n[d]=n[d-P]}}e.l=l,e.p=A,e.b=d,e.f=u,l&&(u=1,e.m=g,e.d=m,e.n=p)}while(!u);return d!=n.length&&o?Yn(n,0,d):n.subarray(0,d)},_t=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&Z(0,"invalid zlib data"),t[1]&32&&Z(0,"zlib dictionaries are not supported"),2);function Wt(t){let e=_t(t);return Gt(t.subarray(e,-4),{i:2})}function it(t){let e=_t(t),n={i:2},r=Gt(t.subarray(e),n),s=Ft(n.p);return{result:r,bytesConsumed:e+s+4}}async function Xn(){let t;if(!(typeof document<"u"))try{t=Me(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let o=t.inflateSync(i,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??it}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let s=new CompressionStream("deflate"),i=s.writable.getWriter();return i.write(r),i.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:Wt,inflateWithConsumed:it}}var Jn=null;function ot(){return Jn??=Xn()}async function at(t){return await(await ot()).deflateSync(t)}async function ge(t){return await(await ot()).inflateSync(t)}async function zt(t,e){let n=await ot(),{result:r,bytesConsumed:s}=n.inflateWithConsumed(t);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);return{result:r,bytesConsumed:s}}var Vt=1346454347,Zn=2,Qn=1,er=2,tr=3,nr=4,Ue=6,ft=7,rr={[Qn]:"commit",[er]:"tree",[tr]:"blob",[nr]:"tag"};async function Yt(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==Vt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Vt.toString(16)})`);let s=n.getUint32(4);if(s!==Zn)throw new Error(`Unsupported pack version: ${s}`);if(t.byteLength>=32){let f=Oe(t,t.byteLength-20),u=Ee();u.update(t.subarray(0,t.byteLength-20));let h=await u.hex();if(h!==f)throw new Error(`pack checksum mismatch: expected ${f}, computed ${h}`)}let i=n.getUint32(8),o=[],a=12;for(let f=0;f<i;f++){let u=await sr(t,a);o.push(u),a=u.nextOffset}return(await ir(o,e)).map((f,u)=>({...f,offset:o[u].headerOffset,nextOffset:o[u].nextOffset}))}async function sr(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=t[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Ue){let h=t[e++];for(a=h&127;h&128;)a+=1,h=t[e++],a=(a<<7)+(h&127);a=n-a}else s===ft&&(c=Oe(t,e),e+=20);let{result:f,bytesConsumed:u}=await zt(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+u}}var Kt=50;async function ir(t,e){let n=new Map;for(let i=0;i<t.length;i++)n.set(t[i].headerOffset,i);let r=new Array(t.length).fill(null);async function s(i,o=0){if(o>Kt)throw new Error(`delta chain depth ${o} exceeds limit of ${Kt}`);let a=r[i];if(a)return a;let c=t[i];if(c.typeNum!==Ue&&c.typeNum!==ft){let l=rr[c.typeNum];if(!l)throw new Error(`Unknown object type: ${c.typeNum}`);let m={type:l,content:c.inflated,hash:await ct(l,c.inflated)};return r[i]=m,m}if(c.typeNum===Ue){let l=n.get(c.baseOffset);if(l===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let m=await s(l,o+1),g=Re(m.content,c.inflated),p={type:m.type,content:g,hash:await ct(m.type,g)};return r[i]=p,p}let f=await or(t,r,c.baseHash,s),u;if(f!==void 0)u=await s(f,o+1);else if(e){let l=await e(c.baseHash);l&&(u=l)}if(!u)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let h=Re(u.content,c.inflated),d={type:u.type,content:h,hash:await ct(u.type,h)};return r[i]=d,d}for(let i=0;i<t.length;i++)await s(i);return r}async function or(t,e,n,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===n)return s;for(let s=0;s<t.length;s++){let i=t[s];if(i.typeNum!==Ue&&i.typeNum!==ft&&(await r(s)).hash===n)return s}}function Re(t,e){let n=0,{value:r,newPos:s}=qt(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:o}=qt(e,n);n=o;let a=new Uint8Array(i),c=0;for(;n<e.byteLength;){let f=e[n++];if(f&128){let u=0,h=0;f&1&&(u=e[n++]),f&2&&(u|=e[n++]<<8),f&4&&(u|=e[n++]<<16),f&8&&(u|=e[n++]<<24),f&16&&(h=e[n++]),f&32&&(h|=e[n++]<<8),f&64&&(h|=e[n++]<<16),h===0&&(h=65536),a.set(t.subarray(u,u+h),c),c+=h}else if(f>0)a.set(e.subarray(n,n+f),c),c+=f,n+=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 qt(t,e){let n=0,r=0,s;do s=t[e++],n|=(s&127)<<r,r+=7;while(s&128);return{value:n,newPos:e}}var ar=new TextEncoder;async function ct(t,e){let n=ar.encode(`${t} ${e.byteLength}\0`),r=Ee();return r.update(n),r.update(e),r.hex()}var Xt=4285812579,Jt=2,se=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(0)!==Xt)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==Jt)throw new Error(`Unsupported pack index version: ${n.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let i=0;i<256;i++)this.fanout[i]=n.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]=n.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 n=Y(e),r=n[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,n);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 n=0;n<this.count;n++)e.push(this.hashAtSlot(n));return e}findByPrefix(e){if(e.length<2)return[];let n=parseInt(e.slice(0,2),16),r=n===0?0:this.fanout[n-1],s=this.fanout[n],i=Y(e.padEnd(40,"0")),o=e.length,a=[];for(let c=r;c<s;c++){let f=c*20,u=!0;for(let h=0;h<o;h++){let d=h%2===0?this.hashes[f+(h>>1)]>>4&15:this.hashes[f+(h>>1)]&15,l=h%2===0?i[h>>1]>>4&15:i[h>>1]&15;if(d!==l){u=!1;break}}u&&a.push(this.hashAtSlot(c))}return a}hashAtSlot(e){let n="",r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s];n+=(i>>4).toString(16)+(i&15).toString(16)}return n}compareAt(e,n){let r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s],o=n[s];if(i<o)return-1;if(i>o)return 1}return 0}getOffset(e){let n=this.offsets[e];if(n&2147483648){let r=n&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return n}};async function cr(t,e){let n=[...t].sort((l,m)=>l.hash<m.hash?-1:l.hash>m.hash?1:0),r=n.length,s=[];for(let l of n)l.offset>=2147483648&&s.push(BigInt(l.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,Jt),c+=4;let f=new Uint32Array(256);for(let l of n){let m=parseInt(l.hash.slice(0,2),16);for(let g=m;g<256;g++)f[g]++}for(let l=0;l<256;l++)a.setUint32(c,f[l]),c+=4;for(let l of n)o.set(Y(l.hash),c),c+=20;for(let l of n)a.setUint32(c,l.crc),c+=4;let u=0;for(let l of n)l.offset>=2147483648?a.setUint32(c,2147483648|u++):a.setUint32(c,l.offset),c+=4;for(let l of s)a.setBigUint64(c,l),c+=8;o.set(e,c),c+=20;let h=Ee();h.update(o.subarray(0,c));let d=await h.hex();return o.set(Y(d),c),o}async function Zt(t){let n=(await Yt(t)).map(s=>({hash:s.hash,offset:s.offset,crc:vt(t.subarray(s.offset,s.nextOffset))})),r=t.subarray(t.byteLength-20);return cr(n,r)}var fr=6,lr=7,ur={1:"commit",2:"tree",3:"blob",4:"tag"},Qt=50,Se=class{constructor(e,n){this.data=e;this.index=n instanceof se?n:new se(n)}index;hasObject(e){return this.index.has(e)}findByPrefix(e){return this.index.findByPrefix(e)}async readObject(e){let n=this.index.lookup(e);return n===null?null:this.readAt(n,0)}get objectCount(){return this.index.objectCount}async readAt(e,n){if(n>Qt)throw new Error(`delta chain depth ${n} exceeds limit of ${Qt}`);let r=this.data,s=e,i=r[s++],o=i>>4&7,a=i&15,c=4;for(;i&128;)i=r[s++],a|=(i&127)<<c,c+=7;if(o===fr){let h=r[s++],d=h&127;for(;h&128;)d+=1,h=r[s++],d=(d<<7)+(h&127);let l=await ge(r.subarray(s)),m=await this.readAt(e-d,n+1);return{type:m.type,content:Re(m.content,l)}}if(o===lr){let h=Oe(r,s);s+=20;let d=await ge(r.subarray(s)),l=this.index.lookup(h);if(l===null)throw new Error(`REF_DELTA base ${h} not found in pack`);let m=await this.readAt(l,n+1);return{type:m.type,content:Re(m.content,d)}}let f=ur[o];if(!f)throw new Error(`Unknown pack object type: ${o}`);let u=await ge(r.subarray(s));if(u.byteLength!==a)throw new Error(`Pack inflate size mismatch at offset ${e}: got ${u.byteLength}, expected ${a}`);return{type:f,content:u}}};var hr=new TextEncoder,dr=new TextDecoder;function mr(t,e){let n=hr.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function pr(t,e){let n=e.indexOf(0);if(n===-1)throw new Error(`Corrupt object ${t}: no null byte in header`);let r=dr.decode(e.subarray(0,n)),s=r.indexOf(" ");if(s===-1)throw new Error(`Corrupt object ${t}: malformed header "${r}"`);let i=r.slice(0,s),o=parseInt(r.slice(s+1),10),a=e.subarray(n+1);if(a.byteLength!==o)throw new Error(`Corrupt object ${t}: expected ${o} bytes, got ${a.byteLength}`);return{type:i,content:a}}function lt(t,e){return D(t,"objects",e.slice(0,2),e.slice(2))}var ut=class{constructor(e,n,r){this.fs=e;this.gitDir=n;this.cache=new ve(r),this.packDir=D(n,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(e,n){let r=mr(e,n),s=await me(r),i=lt(this.gitDir,s);if(await this.fs.exists(i))return s;let o=D(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(o,{recursive:!0}),await this.fs.writeFile(i,await at(r)),s}async read(e){let n=this.cache.get(e);if(n)return n;let r=lt(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await ge(s),o=await me(i);if(o!==e)throw new Error(`corrupt loose object ${e}: SHA-1 mismatch (computed ${o})`);let a=pr(e,i);return this.cache.set(e,a),a}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(lt(this.gitDir,e)))return!0;await this.discover();for(let n of this.packs)if(n.index.has(e))return!0;return!1}async ingestPack(e){if(e.byteLength<32)return 0;let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0);if(r!==1346454347)throw new Error(`invalid pack signature: 0x${r.toString(16)} (expected 0x5041434b)`);let s=n.getUint32(4);if(s!==2)throw new Error(`unsupported pack version: ${s}`);let i=n.getUint32(8);if(i===0)return 0;let o=e.subarray(e.byteLength-20),a=le(o),c=await me(e.subarray(0,e.byteLength-20));if(c!==a)throw new Error(`pack checksum mismatch: expected ${a}, computed ${c}`);await this.fs.mkdir(this.packDir,{recursive:!0});let f=`pack-${a}`,u=D(this.packDir,`${f}.pack`);await this.fs.writeFile(u,e);let h=await Zt(e),d=D(this.packDir,`${f}.idx`);await this.fs.writeFile(d,h),this.loadedPackNames.add(f);let l=new se(h);return this.packs.push({name:f,index:l,reader:new Se(e,l)}),i}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(e){if(e.length<4)return[];let n=e.slice(0,2),r=e.slice(2),s=D(this.gitDir,"objects",n),i=[];if(await this.fs.exists(s)){let o=await this.fs.readdir(s);for(let a of o)a.startsWith(r)&&i.push(`${n}${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 n=D(this.packDir,`${e.name}.pack`),r=await this.fs.readFileBuffer(n);return e.reader=new Se(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 n of e){if(!n.endsWith(".idx"))continue;let r=n.slice(0,-4);if(this.loadedPackNames.has(r))continue;let s=D(this.packDir,`${r}.pack`);if(!await this.fs.exists(s))continue;let i=await this.fs.readFileBuffer(D(this.packDir,n));this.loadedPackNames.add(r),this.packs.push({name:r,index:new se(i),reader:null})}}};function ht(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function dt(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var gr=new TextEncoder,br=new TextDecoder;function en(t){let e=br.decode(t),n=e.indexOf(`
1
+ var _e=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});function mr(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.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}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function B(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":mr(e)}function Bt(t){if(t==="")return".";if(t==="/")return"/";let e=t.length;for(;e>1&&t.charCodeAt(e-1)===47;)e--;let n=t.slice(0,e),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}var Nt=(()=>{let t=new Array(256);for(let e=0;e<256;e++)t[e]=(e>>4).toString(16)+(e&15).toString(16);return t})();function ge(t){let e="";for(let n=0;n<20;n++)e+=Nt[t[n]];return e}function Ce(t,e){let n="";for(let r=0;r<20;r++)n+=Nt[t[e+r]];return n}function J(t){let e=new Uint8Array(20);for(let n=0;n<20;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}function Ft(t){return t.length===4&&t.toLowerCase()===".git"}function Gt(t){if(t.length===0||t.includes("\0")||t.charCodeAt(0)===47||t.charCodeAt(t.length-1)===47)return!1;let e=t.split("/");for(let n of e)if(n.length===0||n==="."||n===".."||Ft(n))return!1;return!0}function _t(t,e){return e===t?!1:t==="/"?e.startsWith("/")&&e.length>1:e.startsWith(t+"/")}function Wt(t){if(t.length===0||t.charCodeAt(0)===47)return!1;let e=t.split("/");for(let n of e)if(n===".."||Ft(n))return!1;return!0}var pr=new TextEncoder;function ct(t){return typeof t=="string"?pr.encode(t):t}function yr(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(ct(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=_e(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(ct(r)),n},hex:()=>Promise.resolve(e.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let t=[],e={update(n){return t.push(ct(n)),e},async hex(){let n=0;for(let o of t)n+=o.byteLength;let r=new Uint8Array(n),s=0;for(let o of t)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return ge(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 zt=yr(),Ie=zt;async function ce(t){return zt().update(t).hex()}var gr=1145655875,br=2;async function We(t,e){let n=B(t.gitDir,"index"),r=await wr(e);await t.fs.writeFile(n,r)}function Vt(t){let e=[...t].sort(Kt);return{version:br,entries:e}}function fe(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function wr(t){let e=new TextEncoder,n=[...t.entries].sort(Kt),r=[],s=12;for(let d of n){let h=e.encode(d.path);r.push(h);let m=62+h.byteLength+1;s+=Math.ceil(m/8)*8}s+=20;let i=new ArrayBuffer(s),o=new Uint8Array(i),a=new DataView(i),c=0;a.setUint32(c,gr),c+=4,a.setUint32(c,t.version),c+=4,a.setUint32(c,n.length),c+=4;for(let d=0;d<n.length;d++){let h=n[d],m=r[d],y=c;a.setUint32(c,h.stat.ctimeSeconds),a.setUint32(c+4,h.stat.ctimeNanoseconds),a.setUint32(c+8,h.stat.mtimeSeconds),a.setUint32(c+12,h.stat.mtimeNanoseconds),a.setUint32(c+16,h.stat.dev),a.setUint32(c+20,h.stat.ino),a.setUint32(c+24,h.mode),a.setUint32(c+28,h.stat.uid),a.setUint32(c+32,h.stat.gid),a.setUint32(c+36,h.stat.size),c+=40;let p=J(h.hash);o.set(p,c),c+=20;let b=Math.min(m.byteLength,4095),R=(h.stage&3)<<12|b;a.setUint16(c,R),c+=2,o.set(m,c),c+=m.byteLength,o[c]=0,c+=1;let v=62+m.byteLength+1,C=Math.ceil(v/8)*8;c=y+C}let f=o.subarray(0,c),l=await ce(f),u=J(l);return o.set(u,c),o}function Kt(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}var xr=new Set(["tree","commit","tag"]),ze=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,n){if(!xr.has(n.type))return;let r=n.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,n),this.currentBytes+=r}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var Yt=new Uint32Array(256);for(let t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;Yt[t]=e}function qt(t){let e=4294967295;for(let n=0;n<t.byteLength;n++)e=Yt[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}var Q=Uint8Array,Ee=Uint16Array,Ir=Int32Array,Xt=new Q([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Jt=new Q([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Er=new Q([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Zt=(t,e)=>{let n=new Ee(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new Ir(n[30]);for(let s=1;s<30;++s)for(let i=n[s];i<n[s+1];++i)r[i]=i-n[s]<<5|s;return{b:n,r}},{b:Qt}=Zt(Xt,2);Qt[28]=258;var{b:Or}=Zt(Jt,0),ut=new Ee(32768);for(let t=0;t<32768;++t){let e=(t&43690)>>1|(t&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,ut[t]=((e&65280)>>8|(e&255)<<8)>>1}var Ae=(t,e,n)=>{let r=t.length,s=0,i=new Ee(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let o=new Ee(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;let a;if(n){a=new Ee(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let f=s<<4|t[s],l=e-t[s],u=o[t[s]-1]++<<l;for(let d=u|(1<<l)-1;u<=d;++u)a[ut[u]>>c]=f}}else for(a=new Ee(r),s=0;s<r;++s)t[s]&&(a[s]=ut[o[t[s]-1]++]>>15-t[s]);return a},$e=new Q(288);for(let t=0;t<144;++t)$e[t]=8;for(let t=144;t<256;++t)$e[t]=9;for(let t=256;t<280;++t)$e[t]=7;for(let t=280;t<288;++t)$e[t]=8;var en=new Q(32);for(let t=0;t<32;++t)en[t]=5;var Rr=Ae($e,9,1),Pr=Ae(en,5,1),ft=t=>{let e=t[0];for(let n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},Z=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},lt=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},tn=t=>(t+7)/8|0,kr=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new Q(t.subarray(e,n))),ee=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},nn=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new Q(0);let o=!n,a=o||e.i!=2,c=e.i;o&&(n=new Q(s*3));let f=R=>{let v=n.length;if(R>v){let C=new Q(Math.max(v*2,R));C.set(n),n=C}},l=e.f||0,u=e.p||0,d=e.b||0,h=e.l,m=e.d,y=e.m,p=e.n,b=s*8;do{if(!h){l=Z(t,u,1);let O=Z(t,u+1,3);if(u+=3,O)if(O==1)h=Rr,m=Pr,y=9,p=5;else if(O==2){let w=Z(t,u,31)+257,E=Z(t,u+10,15)+4,T=w+Z(t,u+5,31)+1;u+=14;let I=new Q(T),P=new Q(19);for(let g=0;g<E;++g)P[Er[g]]=Z(t,u+g*3,7);u+=E*3;let S=ft(P),$=(1<<S)-1,D=Ae(P,S,1);for(let g=0;g<T;){let k=D[Z(t,u,$)];u+=k&15;let M=k>>4;if(M<16)I[g++]=M;else{let L=0,j=0;for(M==16?(j=3+Z(t,u,3),u+=2,L=I[g-1]):M==17?(j=3+Z(t,u,7),u+=3):M==18&&(j=11+Z(t,u,127),u+=7);j--;)I[g++]=L}}let ae=I.subarray(0,w),x=I.subarray(w);y=ft(ae),p=ft(x),h=Ae(ae,y,1),m=Ae(x,p,1)}else ee(1);else{let w=tn(u)+4,E=t[w-4]|t[w-3]<<8,T=w+E;if(T>s){c&&ee(0);break}a&&f(d+E),n.set(t.subarray(w,T),d),e.b=d+=E,e.p=u=T*8,e.f=l;continue}if(u>b){c&&ee(0);break}}a&&f(d+131072);let R=(1<<y)-1,v=(1<<p)-1,C=u;for(;;C=u){let O=h[lt(t,u)&R],w=O>>4;if(u+=O&15,u>b){c&&ee(0);break}if(O||ee(2),w<256)n[d++]=w;else if(w==256){C=u,h=null;break}else{let E=w-254;if(w>264){let $=w-257,D=Xt[$];E=Z(t,u,(1<<D)-1)+Qt[$],u+=D}let T=m[lt(t,u)&v],I=T>>4;T||ee(3),u+=T&15;let P=Or[I];if(I>3){let $=Jt[I];P+=lt(t,u)&(1<<$)-1,u+=$}if(u>b){c&&ee(0);break}a&&f(d+131072);let S=d+E;if(d<P){let $=i-P,D=Math.min(P,S);for($+d<0&&ee(3);d<D;++d)n[d]=r[$+d]}for(;d<S;++d)n[d]=n[d-P]}}e.l=h,e.p=C,e.b=d,e.f=l,h&&(l=1,e.m=y,e.d=m,e.n=p)}while(!l);return d!=n.length&&o?kr(n,0,d):n.subarray(0,d)},rn=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&ee(0,"invalid zlib data"),t[1]&32&&ee(0,"zlib dictionaries are not supported"),2);function sn(t){let e=rn(t);return nn(t.subarray(e,-4),{i:2})}function ht(t){let e=rn(t),n={i:2},r=nn(t.subarray(e),n),s=tn(n.p);return{result:r,bytesConsumed:e+s+4}}async function Sr(){let t;if(!(typeof document<"u"))try{t=_e(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let o=t.inflateSync(i,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??ht}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let s=new CompressionStream("deflate"),i=s.writable.getWriter();return i.write(r),i.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:sn,inflateWithConsumed:ht}}var Tr=null;function dt(){return Tr??=Sr()}async function Ve(t){return await(await dt()).deflateSync(t)}async function Oe(t){return await(await dt()).inflateSync(t)}async function on(t,e){let n=await dt(),{result:r,bytesConsumed:s}=n.inflateWithConsumed(t);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);return{result:r,bytesConsumed:s}}var pt=1346454347,fn=2,ln=1,un=2,hn=3,dn=4,Ke=6,yt=7,jr={[ln]:"commit",[un]:"tree",[hn]:"blob",[dn]:"tag"},vr={commit:ln,tree:un,blob:hn,tag:dn};async function Ye(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==pt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${pt.toString(16)})`);let s=n.getUint32(4);if(s!==fn)throw new Error(`Unsupported pack version: ${s}`);if(t.byteLength>=32){let f=Ce(t,t.byteLength-20),l=Ie();l.update(t.subarray(0,t.byteLength-20));let u=await l.hex();if(u!==f)throw new Error(`pack checksum mismatch: expected ${f}, computed ${u}`)}let i=n.getUint32(8),o=[],a=12;for(let f=0;f<i;f++){let l=await Cr(t,a);o.push(l),a=l.nextOffset}return(await Ar(o,e)).map((f,l)=>({...f,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function Cr(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=t[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Ke){let u=t[e++];for(a=u&127;u&128;)a+=1,u=t[e++],a=(a<<7)+(u&127);a=n-a}else s===yt&&(c=Ce(t,e),e+=20);let{result:f,bytesConsumed:l}=await on(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+l}}var an=50;async function Ar(t,e){let n=new Map;for(let i=0;i<t.length;i++)n.set(t[i].headerOffset,i);let r=new Array(t.length).fill(null);async function s(i,o=0){if(o>an)throw new Error(`delta chain depth ${o} exceeds limit of ${an}`);let a=r[i];if(a)return a;let c=t[i];if(c.typeNum!==Ke&&c.typeNum!==yt){let h=jr[c.typeNum];if(!h)throw new Error(`Unknown object type: ${c.typeNum}`);let m={type:h,content:c.inflated,hash:await mt(h,c.inflated)};return r[i]=m,m}if(c.typeNum===Ke){let h=n.get(c.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let m=await s(h,o+1),y=Le(m.content,c.inflated),p={type:m.type,content:y,hash:await mt(m.type,y)};return r[i]=p,p}let f=await $r(t,r,c.baseHash,s),l;if(f!==void 0)l=await s(f,o+1);else if(e){let h=await e(c.baseHash);h&&(l=h)}if(!l)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let u=Le(l.content,c.inflated),d={type:l.type,content:u,hash:await mt(l.type,u)};return r[i]=d,d}for(let i=0;i<t.length;i++)await s(i);return r}async function $r(t,e,n,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===n)return s;for(let s=0;s<t.length;s++){let i=t[s];if(i.typeNum!==Ke&&i.typeNum!==yt&&(await r(s)).hash===n)return s}}function Le(t,e){let n=0,{value:r,newPos:s}=cn(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:o}=cn(e,n);n=o;let a=new Uint8Array(i),c=0;for(;n<e.byteLength;){let f=e[n++];if(f&128){let l=0,u=0;f&1&&(l=e[n++]),f&2&&(l|=e[n++]<<8),f&4&&(l|=e[n++]<<16),f&8&&(l|=e[n++]<<24),f&16&&(u=e[n++]),f&32&&(u|=e[n++]<<8),f&64&&(u|=e[n++]<<16),u===0&&(u=65536),a.set(t.subarray(l,l+u),c),c+=u}else if(f>0)a.set(e.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return a}async function mn(t){let e=[],n=new Uint8Array(12),r=new DataView(n.buffer);r.setUint32(0,pt),r.setUint32(4,fn),r.setUint32(8,t.length),e.push(n);for(let s of t){let i=vr[s.type],o=await Ve(s.content);e.push(Mr(i,s.content.byteLength)),e.push(o)}return Lr(e)}async function Lr(t){let e=0;for(let o of t)e+=o.byteLength;e+=20;let n=new Uint8Array(e),r=0;for(let o of t)n.set(o,r),r+=o.byteLength;let s=Ie();s.update(n.subarray(0,r));let i=await s.hex();return n.set(J(i),r),n}function Mr(t,e){let n=[],r=t<<4|e&15;for(e>>=4;e>0;)n.push(r|128),r=e&127,e>>=7;return n.push(r),new Uint8Array(n)}function cn(t,e){let n=0,r=0,s;do s=t[e++],n|=(s&127)<<r,r+=7;while(s&128);return{value:n,newPos:e}}var Dr=new TextEncoder;async function mt(t,e){let n=Dr.encode(`${t} ${e.byteLength}\0`),r=Ie();return r.update(n),r.update(e),r.hex()}var pn=4285812579,yn=2,le=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(0)!==pn)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==yn)throw new Error(`Unsupported pack index version: ${n.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let i=0;i<256;i++)this.fanout[i]=n.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]=n.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 n=J(e),r=n[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,n);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 n=0;n<this.count;n++)e.push(this.hashAtSlot(n));return e}findByPrefix(e){if(e.length<2)return[];let n=parseInt(e.slice(0,2),16),r=n===0?0:this.fanout[n-1],s=this.fanout[n],i=J(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 n="",r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s];n+=(i>>4).toString(16)+(i&15).toString(16)}return n}compareAt(e,n){let r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s],o=n[s];if(i<o)return-1;if(i>o)return 1}return 0}getOffset(e){let n=this.offsets[e];if(n&2147483648){let r=n&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return n}};async function Ur(t,e){let n=[...t].sort((h,m)=>h.hash<m.hash?-1:h.hash>m.hash?1:0),r=n.length,s=[];for(let h of n)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,pn),c+=4,a.setUint32(c,yn),c+=4;let f=new Uint32Array(256);for(let h of n){let m=parseInt(h.hash.slice(0,2),16);for(let y=m;y<256;y++)f[y]++}for(let h=0;h<256;h++)a.setUint32(c,f[h]),c+=4;for(let h of n)o.set(J(h.hash),c),c+=20;for(let h of n)a.setUint32(c,h.crc),c+=4;let l=0;for(let h of n)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(J(d),c),o}async function gn(t){let n=(await Ye(t)).map(s=>({hash:s.hash,offset:s.offset,crc:qt(t.subarray(s.offset,s.nextOffset))})),r=t.subarray(t.byteLength-20);return Ur(n,r)}var Hr=6,Br=7,Nr={1:"commit",2:"tree",3:"blob",4:"tag"},bn=50,Me=class{constructor(e,n){this.data=e;this.index=n instanceof le?n:new le(n)}index;hasObject(e){return this.index.has(e)}findByPrefix(e){return this.index.findByPrefix(e)}async readObject(e){let n=this.index.lookup(e);return n===null?null:this.readAt(n,0)}get objectCount(){return this.index.objectCount}async readAt(e,n){if(n>bn)throw new Error(`delta chain depth ${n} exceeds limit of ${bn}`);let r=this.data,s=e,i=r[s++],o=i>>4&7,a=i&15,c=4;for(;i&128;)i=r[s++],a|=(i&127)<<c,c+=7;if(o===Hr){let u=r[s++],d=u&127;for(;u&128;)d+=1,u=r[s++],d=(d<<7)+(u&127);let h=await Oe(r.subarray(s)),m=await this.readAt(e-d,n+1);return{type:m.type,content:Le(m.content,h)}}if(o===Br){let u=Ce(r,s);s+=20;let d=await Oe(r.subarray(s)),h=this.index.lookup(u);if(h===null)throw new Error(`REF_DELTA base ${u} not found in pack`);let m=await this.readAt(h,n+1);return{type:m.type,content:Le(m.content,d)}}let f=Nr[o];if(!f)throw new Error(`Unknown pack object type: ${o}`);let l=await Oe(r.subarray(s));if(l.byteLength!==a)throw new Error(`Pack inflate size mismatch at offset ${e}: got ${l.byteLength}, expected ${a}`);return{type:f,content:l}}};var Fr=new TextEncoder,Gr=new TextDecoder;function wt(t,e){let n=Fr.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function _r(t,e){let n=e.indexOf(0);if(n===-1)throw new Error(`Corrupt object ${t}: no null byte in header`);let r=Gr.decode(e.subarray(0,n)),s=r.indexOf(" ");if(s===-1)throw new Error(`Corrupt object ${t}: malformed header "${r}"`);let i=r.slice(0,s),o=parseInt(r.slice(s+1),10),a=e.subarray(n+1);if(a.byteLength!==o)throw new Error(`Corrupt object ${t}: expected ${o} bytes, got ${a.byteLength}`);return{type:i,content:a}}function gt(t,e){return B(t,"objects",e.slice(0,2),e.slice(2))}var bt=class{constructor(e,n,r){this.fs=e;this.gitDir=n;this.cache=new ze(r),this.packDir=B(n,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(e,n){let r=wt(e,n),s=await ce(r),i=gt(this.gitDir,s);if(await this.fs.exists(i))return s;let o=B(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(o,{recursive:!0}),await this.fs.writeFile(i,await Ve(r)),s}async read(e){let n=this.cache.get(e);if(n)return n;let r=gt(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await Oe(s),o=await ce(i);if(o!==e)throw new Error(`corrupt loose object ${e}: SHA-1 mismatch (computed ${o})`);let a=_r(e,i);return this.cache.set(e,a),a}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(gt(this.gitDir,e)))return!0;await this.discover();for(let n of this.packs)if(n.index.has(e))return!0;return!1}async ingestPack(e){if(e.byteLength<32)return 0;let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0);if(r!==1346454347)throw new Error(`invalid pack signature: 0x${r.toString(16)} (expected 0x5041434b)`);let s=n.getUint32(4);if(s!==2)throw new Error(`unsupported pack version: ${s}`);let i=n.getUint32(8);if(i===0)return 0;let o=e.subarray(e.byteLength-20),a=ge(o),c=await ce(e.subarray(0,e.byteLength-20));if(c!==a)throw new Error(`pack checksum mismatch: expected ${a}, computed ${c}`);await this.fs.mkdir(this.packDir,{recursive:!0});let f=`pack-${a}`,l=B(this.packDir,`${f}.pack`);await this.fs.writeFile(l,e);let u=await gn(e),d=B(this.packDir,`${f}.idx`);await this.fs.writeFile(d,u),this.loadedPackNames.add(f);let h=new le(u);return this.packs.push({name:f,index:h,reader:new Me(e,h)}),i}async ingestPackStream(e){let n=[];for await(let s of e)n.push(s);if(n.length===0)return 0;let r=await mn(n);return this.ingestPack(r)}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(e){if(e.length<4)return[];let n=e.slice(0,2),r=e.slice(2),s=B(this.gitDir,"objects",n),i=[];if(await this.fs.exists(s)){let o=await this.fs.readdir(s);for(let a of o)a.startsWith(r)&&i.push(`${n}${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 n=B(this.packDir,`${e.name}.pack`),r=await this.fs.readFileBuffer(n);return e.reader=new Me(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 n of e){if(!n.endsWith(".idx"))continue;let r=n.slice(0,-4);if(this.loadedPackNames.has(r))continue;let s=B(this.packDir,`${r}.pack`);if(!await this.fs.exists(s))continue;let i=await this.fs.readFileBuffer(B(this.packDir,n));this.loadedPackNames.add(r),this.packs.push({name:r,index:new le(i),reader:null})}}};function De(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function qe(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var Wr=new TextEncoder,zr=new TextDecoder;function wn(t){let e=zr.decode(t),n=e.indexOf(`
2
2
 
3
3
  `),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",o=[],a,c;for(let f of r.split(`
4
- `)){let u=f.indexOf(" ");if(u===-1)continue;let h=f.slice(0,u),d=f.slice(u+1);switch(h){case"tree":i=d;break;case"parent":o.push(d);break;case"author":a=ht(d);break;case"committer":c=ht(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 Be(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${dt(t.author)}`),e.push(`committer ${dt(t.committer)}`),e.push(""),e.push(t.message),gr.encode(e.join(`
5
- `))}async function _(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function q(t,e){return t.objectStore.read(e)}function ee(t){let e=Math.min(t.length,8e3);for(let n=0;n<e;n++)if(t.charCodeAt(n)===0)return!0;return!1}var yr=new TextDecoder;async function H(t,e){let n=await q(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return yr.decode(n.content)}async function te(t,e){let n=await q(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function U(t,e){let n=await q(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return en(n.content)}var Te={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function tn(t){return typeof t=="string"?{type:"direct",hash:t}:t}var mt="ref: ",nn=10,pt=class{constructor(e,n){this.fs=e;this.gitDir=n}casLocks=new Map;async readRef(e){let n=D(this.gitDir,e);if(await this.fs.exists(n)){let i=(await this.fs.readFile(n)).trim();return i.startsWith(mt)?{type:"symbolic",target:i.slice(mt.length)}:{type:"direct",hash:i}}let s=(await this.readPackedRefs()).get(e);return s?{type:"direct",hash:s}:null}async writeRef(e,n){let r=tn(n),s=D(this.gitDir,e);await rn(this.fs,s),r.type==="symbolic"?await this.fs.writeFile(s,`${mt}${r.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=De(d);break;case"committer":c=De(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 Xe(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${qe(t.author)}`),e.push(`committer ${qe(t.committer)}`),e.push(""),e.push(t.message),Wr.encode(e.join(`
5
+ `))}var Oo=new TextEncoder,Vr=new TextDecoder;function xn(t){let e=Vr.decode(t),n=e.indexOf(`
6
+
7
+ `),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",o="commit",a="",c;for(let f of r.split(`
8
+ `)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),d=f.slice(l+1);switch(u){case"object":i=d;break;case"type":o=d;break;case"tag":a=d;break;case"tagger":c=De(d);break}}if(!i)throw new Error("Tag missing object field");if(!a)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:i,objectType:o,name:a,tagger:c,message:s}}async function W(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function z(t,e){return t.objectStore.read(e)}async function In(t,e){return t.objectStore.exists(e)}async function En(t,e){return t.objectStore.findByPrefix(e)}function ne(t){let e=Math.min(t.length,8e3);for(let n=0;n<e;n++)if(t.charCodeAt(n)===0)return!0;return!1}var Kr=new TextDecoder;async function U(t,e){let n=await z(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return Kr.decode(n.content)}async function ue(t,e){let n=await z(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function A(t,e){let n=await z(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return wn(n.content)}async function Ue(t,e){let n=e;for(let r=0;r<100;r++){let s=await z(t,n);if(s.type==="commit")return n;if(s.type==="tag"){n=xn(s.content).object;continue}throw new Error(`Cannot peel ${s.type} object ${e} to commit`)}throw new Error(`Tag chain too deep for ${e}`)}var G={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function Je(t){return typeof t=="string"?{type:"direct",hash:t}:t}var xt="ref: ",On=10,It=class{constructor(e,n){this.fs=e;this.gitDir=n}casLocks=new Map;async readRef(e){let n=B(this.gitDir,e);if(await this.fs.exists(n)){let i=(await this.fs.readFile(n)).trim();return i.startsWith(xt)?{type:"symbolic",target:i.slice(xt.length)}:{type:"direct",hash:i}}let s=(await this.readPackedRefs()).get(e);return s?{type:"direct",hash:s}:null}async writeRef(e,n){let r=Je(n),s=B(this.gitDir,e);await Rn(this.fs,s),r.type==="symbolic"?await this.fs.writeFile(s,`${xt}${r.target}
6
9
  `):await this.fs.writeFile(s,`${r.hash}
7
- `)}async deleteRef(e){let n=D(this.gitDir,e);await this.fs.exists(n)&&await this.fs.rm(n),await this.removePackedRef(e)}async listRefs(e="refs"){let n=[],r=D(this.gitDir,e);await this.fs.exists(r)&&await this.walkRefs(r,e,n);let s=await this.readPackedRefs();if(s.size>0){let i=new Set(n.map(a=>a.name)),o=`${e}/`;for(let[a,c]of s)a.startsWith(o)&&!i.has(a)&&n.push({name:a,hash:c})}return n.sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async compareAndSwapRef(e,n,r){let i=(this.casLocks.get(e)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(e,n,r),()=>this.compareAndSwapUnsafe(e,n,r));this.casLocks.set(e,i);try{return await i}finally{this.casLocks.get(e)===i&&this.casLocks.delete(e)}}async compareAndSwapUnsafe(e,n,r){let s=await this.resolveRefInternal(e);if(n===null){if(await this.readRef(e)!==null)return!1}else if(s!==n)return!1;return r===null?await this.deleteRef(e):await this.writeRef(e,r),!0}async resolveRefInternal(e){let n=e;for(let r=0;r<nn;r++){let s=await this.readRef(n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async readPackedRefs(){let e=D(this.gitDir,"packed-refs");if(!await this.fs.exists(e))return new Map;let n=await this.fs.readFile(e),r=new Map;for(let s of n.split(`
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 n=D(this.gitDir,"packed-refs");if(!await this.fs.exists(n))return;let s=(await this.fs.readFile(n)).split(`
10
+ `)}async deleteRef(e){let n=B(this.gitDir,e);await this.fs.exists(n)&&await this.fs.rm(n),await this.removePackedRef(e)}async listRefs(e="refs"){let n=[],r=B(this.gitDir,e);await this.fs.exists(r)&&await this.walkRefs(r,e,n);let s=await this.readPackedRefs();if(s.size>0){let i=new Set(n.map(a=>a.name)),o=`${e}/`;for(let[a,c]of s)a.startsWith(o)&&!i.has(a)&&n.push({name:a,hash:c})}return n.sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async compareAndSwapRef(e,n,r){let i=(this.casLocks.get(e)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(e,n,r),()=>this.compareAndSwapUnsafe(e,n,r));this.casLocks.set(e,i);try{return await i}finally{this.casLocks.get(e)===i&&this.casLocks.delete(e)}}async compareAndSwapUnsafe(e,n,r){let s=await this.resolveRefInternal(e);if(n===null){if(await this.readRef(e)!==null)return!1}else if(s!==n)return!1;return r===null?await this.deleteRef(e):await this.writeRef(e,r),!0}async resolveRefInternal(e){let n=e;for(let r=0;r<On;r++){let s=await this.readRef(n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async readPackedRefs(){let e=B(this.gitDir,"packed-refs");if(!await this.fs.exists(e))return new Map;let n=await this.fs.readFile(e),r=new Map;for(let s of n.split(`
11
+ `)){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 n=B(this.gitDir,"packed-refs");if(!await this.fs.exists(n))return;let s=(await this.fs.readFile(n)).split(`
9
12
  `),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(n,i.join(`
10
- `)):await this.fs.rm(n)}async walkRefs(e,n,r){let s=await this.fs.readdir(e);for(let i of s){let o=D(e,i),a=`${n}/${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 wr(t,e){return t.refStore.readRef(e)}async function De(t,e){let n=e;for(let r=0;r<nn;r++){let s=await wr(t,n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function gt(t,e="refs"){return t.refStore.listRefs(e)}async function rn(t,e){let n=e.lastIndexOf("/");if(n>0){let r=e.slice(0,n);await t.mkdir(r,{recursive:!0})}}var Li=new TextEncoder;function Q(t){return typeof t=="string"?t==="120000":t===40960}var Ir=new TextEncoder,sn=new TextDecoder,xr=new Set(["100644","100755","040000","120000","160000"]);function Or(t){return t.length===4&&t.toLowerCase()===".git"}function Er(t,e){if(t.length===0)throw new Error("invalid tree entry: empty name");if(t.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${t}'`);if(t.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(t==="."||t==="..")throw new Error(`invalid tree entry: '${t}'`);if(Or(t))throw new Error(`invalid tree entry: '${t}'`);if(!xr.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${t}'`)}function on(t){let e=[],n=0;for(;n<t.byteLength;){let r=t.indexOf(32,n);if(r===-1)break;let s=sn.decode(t.subarray(n,r)),i=t.indexOf(0,r+1);if(i===-1)break;let o=sn.decode(t.subarray(r+1,i)),a=t.subarray(i+1,i+21),c=le(a),f=s.padStart(6,"0");Er(o,f),e.push({mode:f,name:o,hash:c}),n=i+21}return{type:"tree",entries:e}}function He(t){let e=[];for(let i of t.entries){let o=i.mode.replace(/^0+/,""),a=Ir.encode(`${o} ${i.name}\0`),c=Y(i.hash);e.push(a),e.push(c)}let n=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}async function bt(t,e){return an(t,e,"")}async function an(t,e,n){let r=[],s=new Map;for(let o of e){let a=n?o.path.slice(n.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:Pr(o.mode),name:a,hash:o.hash});else{let f=a.slice(0,c),u=s.get(f);u||(u=[],s.set(f,u)),u.push(o)}}for(let[o,a]of s){let c=n?`${n}/${o}`:o,f=await an(t,a,c);r.push({mode:Te.DIRECTORY,name:o,hash:f})}r.sort((o,a)=>{let c=o.mode===Te.DIRECTORY?`${o.name}/`:o.name,f=a.mode===Te.DIRECTORY?`${a.name}/`:a.name;return c<f?-1:c>f?1:0});let i=He({type:"tree",entries:r});return _(t,"tree",i)}async function ue(t,e,n=""){let r=await q(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=on(r.content),i=[];for(let o of s.entries){let a=n?`${n}/${o.name}`:o.name;if(o.mode===Te.DIRECTORY){let c=await ue(t,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function ie(t,e){if(!e)return new Map;let n=await ue(t,e);return new Map(n.map(r=>[r.path,r]))}async function Ce(t,e,n){let r=await ie(t,e),s=await ie(t,n),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)=>je(o.path,a.path))}function Pr(t){return t.toString(8).padStart(6,"0")}function cn(t){return{stdout:"",stderr:`fatal: ${t}
11
- `,exitCode:128}}var Gi=cn("not a git repository (or any of the parent directories): .git"),_i=cn("this operation must be run in a work tree");function je(t,e){return t<e?-1:t>e?1:0}function he(t){if(t.length===0)return[];let e=t.split(`
12
- `);return e[e.length-1]===""&&e.pop(),e}var kr=4,fn=1024,Ne=100,_e=0,Fe=1,be=2;function wt(t){let e=1;for(;e*e<t;)e++;return e}function Rr(t,e){let n=new Map,r=[],s=new Array(t.length),i=new Array(e.length);for(let o=0;o<t.length;o++){let a=t[o],c=n.get(a);c===void 0&&(c=r.length,n.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=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function Sr(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&t[e-1-a]===n[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function ln(t,e,n,r){e-n>Ne&&(n=e-Ne),r-e>Ne&&(r=e+Ne);let s=0,i=1;for(let c=1;e-c>=n;c++){let f=t[e-c];if(f===_e)s++;else if(f===be)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let f=t[e+c];if(f===_e)o++;else if(f===be)a++;else break}return o===0?!1:(o+=s,a+=i,a*kr<a+o)}function Tr(t,e,n,r,s,i,o,a,c,f){let u=new Uint8Array(e),h=new Uint8Array(r),d=Math.min(wt(e),fn);for(let p=i;p<=o;p++){let I=s[t[p]].len2;I===0?u[p]=_e:I>=d?u[p]=be:u[p]=Fe}let l=Math.min(wt(r),fn);for(let p=i;p<=a;p++){let I=s[n[p]].len1;I===0?h[p]=_e:I>=l?h[p]=be:h[p]=Fe}let m=[];for(let p=i;p<=o;p++)u[p]===Fe||u[p]===be&&!ln(u,p,i,o)?m.push(p):c[p]=1;let g=[];for(let p=i;p<=a;p++)h[p]===Fe||h[p]===be&&!ln(h,p,i,a)?g.push(p):f[p]=1;return{refIndex1:m,nreff1:m.length,refIndex2:g,nreff2:g.length}}var oe=20,un=4,Cr=256,jr=256,Ge=2147483647;function W(t,e){return t[e]??0}function Ar(t,e,n,r,s,i,o,a,c,f){let u=e-i,h=n-s,d=e-s,l=n-i,m=d-l&1,g=d,p=d,I=l,k=l;o[d]=e,a[l]=n;for(let j=1;;j++){let A=!1;g>u?o[--g-1]=-1:++g,p<h?o[++p+1]=-1:--p;for(let E=p;E>=g;E-=2){let y;W(o,E-1)>=W(o,E+1)?y=W(o,E-1)+1:y=W(o,E+1);let O=y,T=y-E;for(;y<n&&T<i&&t[y]===r[T];)y++,T++;if(y-O>oe&&(A=!0),o[E]=y,m&&I<=E&&E<=k&&W(a,E)<=y)return{i1:y,i2:T,minLo:!0,minHi:!0}}I>u?a[--I-1]=Ge:++I,k<h?a[++k+1]=Ge:--k;for(let E=k;E>=I;E-=2){let y;W(a,E-1)<W(a,E+1)?y=W(a,E-1):y=W(a,E+1)-1;let O=y,T=y-E;for(;y>e&&T>s&&t[y-1]===r[T-1];)y--,T--;if(O-y>oe&&(A=!0),a[E]=y,!m&&g<=E&&E<=p&&y<=W(o,E))return{i1:y,i2:T,minLo:!0,minHi:!0}}if(!c){if(A&&j>Cr){let E=0,y=null;for(let O=p;O>=g;O-=2){let T=O>d?O-d:d-O,x=W(o,O),P=x-O,S=x-e+(P-s)-T;if(S>un*j&&S>E&&e+oe<=x&&x<n&&s+oe<=P&&P<i){let $=!0;for(let v=1;v<=oe;v++)if(t[x-v]!==r[P-v]){$=!1;break}$&&(E=S,y={i1:x,i2:P,minLo:!0,minHi:!1})}}if(y)return y;E=0,y=null;for(let O=k;O>=I;O-=2){let T=O>l?O-l:l-O,x=W(a,O),P=x-O,S=n-x+(i-P)-T;if(S>un*j&&S>E&&e<x&&x<=n-oe&&s<P&&P<=i-oe){let $=!0;for(let v=0;v<oe;v++)if(t[x+v]!==r[P+v]){$=!1;break}$&&(E=S,y={i1:x,i2:P,minLo:!1,minHi:!0})}}if(y)return y}if(j>=f){let E=-1,y=-1;for(let x=p;x>=g;x-=2){let P=Math.min(W(o,x),n),S=P-x;i<S&&(P=i+x,S=i),E<P+S&&(E=P+S,y=P)}let O=Ge,T=Ge;for(let x=k;x>=I;x-=2){let P=Math.max(e,W(a,x)),S=P-x;S<s&&(P=s+x,S=s),P+S<O&&(O=P+S,T=P)}return n+i-O<E-(e+s)?{i1:y,i2:E-y,minLo:!0,minHi:!1}:{i1:T,i2:O-T,minLo:!1,minHi:!0}}}}}function It(t,e,n,r,s,i,o,a,c,f,u,h,d,l){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let m=s;m<i;m++)a[f[m]]=1;else if(s===i)for(let m=e;m<n;m++)o[c[m]]=1;else{let m=Ar(t,e,n,r,s,i,u,h,d,l);It(t,e,m.i1,r,s,m.i2,o,a,c,f,u,h,m.minLo,l),It(t,m.i1,n,r,m.i2,i,o,a,c,f,u,h,m.minHi,l)}}function $r(t,e,n,r){let s=[],i=0,o=0,a=1,c=1;for(;i<t.length||o<e.length;){if(i<t.length&&o<e.length&&!n[i]&&!r[o]){s.push({type:"keep",line:t[i]??"",oldLineNo:a++,newLineNo:c++}),i++,o++;continue}for(;i<t.length&&n[i];)s.push({type:"delete",line:t[i]??"",oldLineNo:a++,newLineNo:0}),i++;for(;o<e.length&&r[o];)s.push({type:"insert",line:e[o]??"",oldLineNo:0,newLineNo:c++}),o++}return s}var hn=200,dn=20,mn=100,Lr=1,Mr=21,vr=-30,Ur=6,Br=-4,Dr=10,Hr=24,Nr=17,Fr=23,Gr=17,_r=60;function yt(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);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>=hn)return hn}return-1}function pn(t,e,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=yt(t[n]));for(let s=n-1;s>=0&&(r.preIndent=yt(t[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===dn){r.preIndent=0;break}for(let s=n+1;s<e&&(r.postIndent=yt(t[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===dn){r.postIndent=0;break}return r}function gn(t,e){t.preIndent===-1&&t.preBlank===0&&(e.penalty+=Lr),t.endOfFile&&(e.penalty+=Mr);let n=t.indent===-1?1+t.postBlank:0,r=t.preBlank+n;e.penalty+=vr*r,e.penalty+=Ur*n;let s=t.indent!==-1?t.indent:t.postIndent,i=r!==0;e.effectiveIndent+=s,s===-1||t.preIndent===-1||(s>t.preIndent?e.penalty+=i?Dr:Br:s===t.preIndent||(t.postIndent!==-1&&t.postIndent>s?e.penalty+=i?Nr:Hr:e.penalty+=i?Gr:Fr))}function Wr(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndent<e.effectiveIndent?1:0);return _r*n+(t.penalty-e.penalty)}function bn(t,e,n,r,s,i){let o=0,a=0;for(;t[a];)a++;let c=0,f=0;for(;s[f];)f++;let u=(h,d)=>e[h]===e[d];for(;;){if(a!==o){let h,d,l;do{for(h=a-o,d=-1;o>0&&u(o-1,a-1);){for(t[--o]=1,t[--a]=0;t[o-1];)o--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(l=a,f>c&&(d=a);!(a>=r||!u(o,a));){for(t[o++]=0,t[a++]=1;t[a];)a++;if(f>=i)break;for(c=f+1,f=c;s[f];f++);f>c&&(d=a)}}while(h!==a-o);if(a!==l)if(d!==-1)for(;f===c;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,g={effectiveIndent:0,penalty:0},p=l;for(a-h-1>p&&(p=a-h-1),a-mn>p&&(p=a-mn);p<=a;p++){let I={effectiveIndent:0,penalty:0},k=pn(n,r,p);gn(k,I);let j=pn(n,r,p-h);gn(j,I),(m===-1||Wr(I,g)<=0)&&(g={effectiveIndent:I.effectiveIndent,penalty:I.penalty},m=p)}for(;a>m;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;t[a];a++);if(f>=i)break;for(c=f+1,f=c;s[f];f++);}}function xt(t,e){let n=t.length,r=e.length,s=new Uint8Array(n),i=new Uint8Array(r);if(n>0&&r>0){let{classes1:o,classes2:a,classInfo:c}=Rr(t,e),{dstart:f,dend1:u,dend2:h}=Sr(o,n,a,r);if(f>u)for(let d=f;d<r-(n-1-u);d++)i[d]=1;else if(f>h)for(let d=f;d<n-(r-1-h);d++)s[d]=1;else{let{refIndex1:d,nreff1:l,refIndex2:m,nreff2:g}=Tr(o,n,a,r,c,f,u,h,s,i);if(l>0&&g>0){let p=new Array(l);for(let y=0;y<l;y++)p[y]=o[d[y]];let I=new Array(g);for(let y=0;y<g;y++)I[y]=a[m[y]];let k={},j={},A=l+g+3,E=Math.max(jr,wt(A));It(p,0,l,I,0,g,s,i,d,m,k,j,!1,E)}else if(l===0)for(let p=0;p<g;p++)i[m[p]]=1;else for(let p=0;p<l;p++)s[d[p]]=1;bn(s,o,t,n,i,r),bn(i,a,e,r,s,n)}}else n===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function We(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return e.map((o,a)=>({type:"insert",line:o,oldLineNo:0,newLineNo:a+1}));if(r===0)return t.map((o,a)=>({type:"delete",line:o,oldLineNo:a+1,newLineNo:0}));let{changedOld:s,changedNew:i}=xt(t,e);return $r(t,e,s,i)}function ye(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function zr(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=ye(e),r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i&&ye(i.path)===n){r=s;break}}return t.splice(r,1)[0]}var Vr=50;async function Ae(t,e,n=Vr){let r=new Map,s=[],i=[],o=[];for(let u of e)if(u.status==="deleted"&&u.oldHash){let h=r.get(u.oldHash)??[];h.push(u),r.set(u.oldHash,h),s.push(u)}else u.status==="added"&&u.newHash?i.push(u):o.push(u);let a=[],c=[];for(let u of i){let h=u.newHash;if(!h){c.push(u);continue}let d=r.get(h);if(d&&d.length>0){let l=zr(d,u.path);l&&a.push({oldPath:l.path,newPath:u.path,oldHash:l.oldHash??h,newHash:h,similarity:100,oldMode:l.oldMode,newMode:u.newMode})}else c.push(u)}let f=[...r.values()].flat();if(f.length>0&&c.length>0){let u=await Kr(t,f,c,n);if(u.length>0){let h=new Set(u.map(l=>l.oldPath)),d=new Set(u.map(l=>l.newPath));f=f.filter(l=>!h.has(l.path)),c=c.filter(l=>!d.has(l.path)),a.push(...u)}}if(f.length>0&&c.length>0){let u=await Xr(t,f,c,n);if(u.length>0){let h=new Set(u.map(l=>l.oldPath)),d=new Set(u.map(l=>l.newPath));f=f.filter(l=>!h.has(l.path)),c=c.filter(l=>!d.has(l.path)),a.push(...u)}}return{remaining:[...o,...f,...c],renames:a}}async function Kr(t,e,n,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let f=ye(c.path);s.has(f)?s.set(f,-1):s.set(f,a)}let i=new Map;for(let a=0;a<n.length;a++){let c=n[a];if(!c)continue;let f=ye(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 u=e[c],h=n[f];if(!u?.oldHash||!h?.newHash||u.oldHash===h.newHash)continue;let d=await te(t,u.oldHash),l=await te(t,h.newHash),m=Yr(d,l);m<r||o.push({oldPath:u.path,newPath:h.path,oldHash:u.oldHash,newHash:h.newHash,similarity:m,oldMode:u.oldMode,newMode:h.newMode})}return o}var yn=107927;function ze(t){let e=new Map,n=0,r=0,s=0;for(let o=0;o<t.length;o++){let a=t[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let f=(r+Math.imul(s,97))%yn;e.set(f,(e.get(f)??0)+n),n=0,r=0,s=0}if(n>0){let o=(r+Math.imul(s,97))%yn;e.set(o,(e.get(o)??0)+n)}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 qr(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let o=t[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,n+=a):n+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:n,literalAdded:r}}function Yr(t,e){return t.length===0&&e.length===0?100:t.length===0||e.length===0?0:wn(t.length,ze(t),e.length,ze(e))}function wn(t,e,n,r){let s=Math.max(t,n),i=Math.min(t,n);if(i<s-i)return 0;let{srcCopied:o}=qr(e,r);return Math.floor(o*100/s)}async function Xr(t,e,n,r){let s=[];for(let u of e)if(u.oldHash){let h=await te(t,u.oldHash);s.push({size:h.length,chunks:ze(h)})}else s.push(null);let i=[];for(let u of n)if(u.newHash){let h=await te(t,u.newHash);i.push({size:h.length,chunks:ze(h)})}else i.push(null);let o=[];for(let u=0;u<e.length;u++){let h=e[u],d=s[u];if(!(!h||!d))for(let l=0;l<n.length;l++){let m=n[l],g=i[l];if(!m||!g)continue;let p=wn(d.size,d.chunks,g.size,g.chunks);if(p>=r){let I=ye(h.path)===ye(m.path)?1:0;o.push({similarity:p,nameScore:I,delIdx:u,addIdx:l})}}}o.sort((u,h)=>h.similarity-u.similarity||h.nameScore-u.nameScore);let a=new Set,c=new Set,f=[];for(let{similarity:u,delIdx:h,addIdx:d}of o){if(a.has(h)||c.has(d))continue;a.add(h),c.add(d);let l=e[h],m=n[d];!l||!m||f.push({oldPath:l.path,newPath:m.path,oldHash:l.oldHash??"",newHash:m.newHash??"",similarity:u,oldMode:l.oldMode,newMode:m.newMode})}return f}async function ae(t,e,n){return(await ie(t,e)).get(n)?.hash??null}async function In(t,e,n,r){let s=await Ce(t,e,n);if(!s.find(c=>c.status==="added"&&c.path===r))return null;let{renames:o}=await Ae(t,s);return o.find(c=>c.newPath===r)?.oldPath??null}async function Jr(t,e,n,r,s,i){let o=await ae(t,(await U(t,e)).tree,n);if(!o){let g=new Map,p=await U(t,e);for(let I of r)g.set(I.finalIdx,ce(e,n,I.currentLine,i+I.finalIdx,s[I.finalIdx],p,!1,void 0));return g}let a=await H(t,o),c=he(a),f=new Array(s.length),u=[...r],h=e,d=n,l=c;for(;u.length>0;){let g=await U(t,h);if(g.parents.length===0){for(let x of u)f[x.finalIdx]=ce(h,d,x.currentLine,i+x.finalIdx,s[x.finalIdx],g,!0,void 0);break}let p=await ae(t,g.tree,d),I=null,k=[];for(let x of g.parents){let P=await U(t,x),S=d,$=await ae(t,P.tree,S);if(!$){let v=await In(t,P.tree,g.tree,d);v&&(S=v,$=await ae(t,P.tree,S))}if($&&(k.push({hash:x,path:S,blobHash:$}),$===p)){I={hash:x,path:S};break}}if(I){h=I.hash,d=I.path;continue}if(k.length===0){for(let x of u)f[x.finalIdx]=ce(h,d,x.currentLine,i+x.finalIdx,s[x.finalIdx],g,!1,void 0);break}let j=k[0],A=await H(t,j.blobHash),E=he(A),y=We(E,l),O=new Map;for(let x of y)x.type==="keep"&&O.set(x.newLineNo,x.oldLineNo);let T=[];for(let x of u){let P=O.get(x.currentLine);P!==void 0?T.push({finalIdx:x.finalIdx,currentLine:P}):f[x.finalIdx]=ce(h,d,x.currentLine,i+x.finalIdx,s[x.finalIdx],g,!1,{hash:j.hash,path:j.path})}u=T,h=j.hash,d=j.path,l=E}let m=new Map;for(let g of r)f[g.finalIdx]&&m.set(g.finalIdx,f[g.finalIdx]);return m}async function xn(t,e,n,r){let s=await U(t,e),i=await ae(t,s.tree,n);if(!i)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let o=await H(t,i),a=he(o),c=r?.startLine??1,f=r?.endLine??a.length,u=a.slice(c-1,f),h=new Array(u.length),d=u.map((p,I)=>({finalIdx:I,currentLine:c+I})),l=e,m=n,g=a;for(;d.length>0;){let p=await U(t,l);if(p.parents.length===0){for(let O of d)h[O.finalIdx]=ce(l,m,O.currentLine,c+O.finalIdx,u[O.finalIdx],p,!0,void 0);break}let I=await ae(t,p.tree,m),k=[],j=null;for(let O of p.parents){let T=await U(t,O),x=m,P=await ae(t,T.tree,x);if(!P){let S=await In(t,T.tree,p.tree,m);S&&(x=S,P=await ae(t,T.tree,x))}if(P){let S={hash:O,path:x,blobHash:P};if(k.push(S),P===I){j=S;break}}}if(j){l=j.hash,m=j.path;continue}if(k.length===0){for(let O of d)h[O.finalIdx]=ce(l,m,O.currentLine,c+O.finalIdx,u[O.finalIdx],p,!1,void 0);break}if(k.length===1){let O=k[0],T=await H(t,O.blobHash),x=he(T),P=We(x,g),S=new Map;for(let v of P)v.type==="keep"&&S.set(v.newLineNo,v.oldLineNo);let $=[];for(let v of d){let ne=S.get(v.currentLine);ne!==void 0?$.push({finalIdx:v.finalIdx,currentLine:ne}):h[v.finalIdx]=ce(l,m,v.currentLine,c+v.finalIdx,u[v.finalIdx],p,!1,{hash:O.hash,path:O.path})}d=$,l=O.hash,m=O.path,g=x;continue}let A=[];for(let O of k){let T=await H(t,O.blobHash),x=he(T),P=We(x,g),S=new Map;for(let $ of P)$.type==="keep"&&S.set($.newLineNo,$.oldLineNo);A.push({info:O,newToOld:S})}let E=new Map;for(let O of d){let T=!1;for(let x=0;x<A.length;x++){let P=A[x],S=P.newToOld.get(O.currentLine);if(S!==void 0){let $=E.get(x);$||($={info:P.info,lines:[]},E.set(x,$)),$.lines.push({finalIdx:O.finalIdx,currentLine:S}),T=!0;break}}T||(h[O.finalIdx]=ce(l,m,O.currentLine,c+O.finalIdx,u[O.finalIdx],p,!1,{hash:k[0].hash,path:k[0].path}))}let y=E.get(0);for(let[O,T]of E){if(O===0)continue;let x=await Jr(t,T.info.hash,T.info.path,T.lines,u,c);for(let[P,S]of x)h[P]=S}if(y&&y.lines.length>0){d=y.lines,l=y.info.hash,m=y.info.path;let O=await H(t,y.info.blobHash);g=he(O)}else break}return h}function ce(t,e,n,r,s,i,o,a){return{hash:t,origPath:e,origLine:n,finalLine:r,content:s,author:i.author,committer:i.committer,summary:i.message.split(`
13
- `)[0],boundary:o,previous:a}}var Ve=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 n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),o<r&&this.higher(n[o],n[s])&&(s=o),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*we(t,e,n){if(n?.topoOrder){yield*Zr(t,e,n);return}let r=await En(t,n?.exclude),s=new Set(r),i=new Ve,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let c of a)s.has(c)||i.push(await Ke(t,c));for(;i.size>0;){let c=i.pop();if(s.has(c.hash)||(s.add(c.hash),yield c,o?.has(c.hash)))continue;let f=n?.firstParent?c.commit.parents.slice(0,1):c.commit.parents;for(let u of f)if(!s.has(u))try{i.push(await Ke(t,u))}catch{}}}async function*Zr(t,e,n){let r=await En(t,n?.exclude),s=new Set(r),i=new Ve,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let l of a)s.has(l)||i.push(await Ke(t,l));let c=[],f=new Map;for(;i.size>0;){let l=i.pop();if(s.has(l.hash)||(s.add(l.hash),f.set(l.hash,c.length),c.push(l),o?.has(l.hash)))continue;let m=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let g of m)if(!s.has(g))try{i.push(await Ke(t,g))}catch{}}let u=c.length;if(u===0)return;let h=new Int32Array(u);for(let l of c){let m=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let g of m){let p=f.get(g);p!==void 0&&(h[p]=(h[p]??0)+1)}}let d=[];for(let l=u-1;l>=0;l--)h[l]===0&&d.push(l);for(;d.length>0;){let l=d.pop();yield c[l];let m=n?.firstParent?c[l].commit.parents.slice(0,1):c[l].commit.parents;for(let g of m){let p=f.get(g);if(p!==void 0){let I=(h[p]??0)-1;h[p]=I,I===0&&d.push(p)}}}}async function On(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let a of we(t,e))r.add(a.hash);let s=new Set;for await(let a of we(t,n))s.add(a.hash);let i=0;for(let a of r)s.has(a)||i++;let o=0;for(let a of s)r.has(a)||o++;return{ahead:i,behind:o}}async function En(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of we(t,e))n.add(r.hash);return n}async function Ke(t,e){return{hash:e,commit:await U(t,e)}}async function Qr(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let o;try{o=await U(t,i)}catch{continue}for(let a of o.parents)n.has(a)||r.push(a)}return n}async function Ot(t,e,n){if(e===n)return!0;let r=new Set,s=[n],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;try{a=await U(t,o)}catch{continue}for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function $e(t,e,n){if(e===n)return[e];let r=await Qr(t,e),s=[],i=new Set,o=[n],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 u;try{u=await U(t,f)}catch{continue}for(let h of u.parents)i.has(h)||o.push(h)}if(s.length<=1)return s;let c=[];for(let f of s){let u=!1;for(let h of s)if(h!==f&&await Ot(t,f,h)){u=!0;break}u||c.push(f)}return c.length<=1?c:es(t,e,n,c)}async function es(t,e,n,r){let s=new Set(r),i=new Set,o=[],a=new Map,c=new Map,f=0,u=[{hash:e,mask:1,seq:f++},{hash:n,mask:2,seq:f++}];async function h(d){let l=c.get(d);if(l!==void 0)return l;let m=(await U(t,d)).committer.timestamp;return c.set(d,m),m}for(;u.length>0;){let d=0,l=await h(u[0].hash);for(let k=1;k<u.length;k++){let j=u[k],A=await h(j.hash),E=u[d];(A>l||A===l&&j.seq<E.seq)&&(d=k,l=A)}let m=u.splice(d,1)[0],g=a.get(m.hash)??0,p=g|m.mask;if(p===g)continue;if(a.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let I=await U(t,m.hash);for(let k of I.parents)u.push({hash:k,mask:p,seq:f++})}for(let d of r)i.has(d)||o.push(d);return o}function Et(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=xt(t,e);return ts(s,n,i,r)}function ts(t,e,n,r){let s=[],i=0,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!t[i]&&!n[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&t[i];)i++;for(;o<r&&n[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function ns(t,e,n){let r=[];for(let c of Et(e,t))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of Et(e,n))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,u=c.oStart+c.oLength,h=[c];for(o(f);a<r.length;){let d=r[a];if(d.oStart>u)break;u=Math.max(u,d.oStart+d.oLength),h.push(d),a++}if(h.length===1){if(c.abLength>0){let d=c.ab==="a"?t:n;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:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let I of h){let k=I.oStart,j=k+I.oLength,A=I.abStart,E=A+I.abLength,y=d[I.ab];y.abMin=Math.min(A,y.abMin),y.abMax=Math.max(E,y.abMax),y.oMin=Math.min(k,y.oMin),y.oMax=Math.max(j,y.oMax)}let l=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(u-d.a.oMax),g=d.b.abMin+(f-d.b.oMin),p=d.b.abMax+(u-d.b.oMax);s.push({stable:!1,a:t.slice(l,m),o:e.slice(f,u),b:n.slice(g,p)})}i=u}return o(e.length),s}function rs(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=ns(t,e,n),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&&kn(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?Pn(o):Pn(ss(o))}function Le(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",o=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),f=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,u=rs(t,e,n,{conflictStyle:i}),h=!1,d=[];for(let l of u)l.type==="ok"?d.push(...l.lines):(h=!0,i==="diff3"?d.push(o,...l.a,a,...l.o,c,...l.b,f):d.push(o,...l.a,c,...l.b,f));return{conflict:h,result:d}}function ss(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...is(n));return e}function is(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(kn(e,n))return[t];let r=Et(e,n);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 u=c+a.buffer1[1],h=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:e.slice(c,u),o:[],b:n.slice(a.buffer2[0],h)}),i=u}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[t]:s}function Pn(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.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 n.push(i)}return n}function de(t,e,n,r){let s=Le(V(t),V(e),V(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(Pt);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
13
+ `)):await this.fs.rm(n)}async walkRefs(e,n,r){let s=await this.fs.readdir(e);for(let i of s){let o=B(e,i),a=`${n}/${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 Yr(t,e){return t.refStore.readRef(e)}async function re(t,e){let n=e;for(let r=0;r<On;r++){let s=await Yr(t,n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function Et(t,e="refs"){return t.refStore.listRefs(e)}async function Rn(t,e){let n=e.lastIndexOf("/");if(n>0){let r=e.slice(0,n);await t.mkdir(r,{recursive:!0})}}function qr(t){let e=[],n=t.length;for(;n>0;){let i=t.slice(0,n).match(/^(.+?)~(\d*)$/);if(i&&i[1]!==void 0&&i[2]!==void 0){let c=i[2]===""?1:parseInt(i[2],10);e.unshift({type:"tilde",n:c}),n=i[1].length;continue}let o=t.slice(0,n).match(/^(.+?)\^{([^}]*)}$/);if(o&&o[1]!==void 0&&o[2]!==void 0){e.unshift({type:"peel",target:o[2]}),n=o[1].length;continue}let a=t.slice(0,n).match(/^(.+?)\^(\d*)$/);if(a&&a[1]!==void 0&&a[2]!==void 0){let c=a[2]===""?1:parseInt(a[2],10);e.unshift({type:"caret",n:c}),n=a[1].length;continue}break}let r=t.slice(0,n),s=r.match(/^(.+?)@\{(\d+)\}$/);return s&&s[1]!==void 0&&s[2]!==void 0?{base:s[1],reflogIndex:parseInt(s[2],10),suffixes:e}:{base:r,suffixes:e}}var Xr=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];async function Jr(t,e){let n=await En(t,e);if(n.length===0)return null;if(n.length>1)throw new Ot(e);return n[0]}var Ot=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}};async function Zr(t,e){if(e==="HEAD"||e==="@")return re(t,"HEAD");if(Xr.includes(e))return re(t,e);if(/^[0-9a-f]{40}$/.test(e))return await In(t,e)?e:null;if(/^[0-9a-f]{4,39}$/.test(e)){let i=await Jr(t,e);if(i)return i}if(e.startsWith("refs/")){let i=await re(t,e);if(i)return i}let n=await re(t,`refs/heads/${e}`);if(n)return n;let r=await re(t,`refs/tags/${e}`);if(r)return r;let s=await re(t,`refs/remotes/${e}`);return s||null}async function Qr(t,e,n){if(n===""||n==="commit")try{return await Ue(t,e)}catch{return null}if(n==="tree"){let s;try{s=await Ue(t,e)}catch{return null}return(await A(t,s)).tree}return(await z(t,e)).type!==n?null:e}async function es(t,e,n){let r=e;n.some(i=>i.type==="tilde"||i.type==="caret")&&(r=await Ue(t,r));for(let i of n)if(i.type==="peel"){if(!r)return null;r=await Qr(t,r,i.target)}else if(i.type==="tilde")for(let o=0;o<i.n;o++){if(!r)return null;let a=await A(t,r);if(a.parents.length===0||(r=a.parents[0]??null,!r))return null}else{if(i.n===0)continue;if(!r)return null;let o=await A(t,r);if(i.n>o.parents.length||(r=o.parents[i.n-1]??null,!r))return null}return r}async function Pn(t,e){let{base:n,reflogIndex:r,suffixes:s}=qr(e);if(r!==void 0)return null;let i=await Zr(t,n);return i?es(t,i,s):null}var Uo=new TextEncoder;function se(t){return typeof t=="string"?t==="120000":t===40960}var ts=new TextEncoder,kn=new TextDecoder,ns=new Set(["100644","100755","040000","120000","160000"]);function rs(t){return t.length===4&&t.toLowerCase()===".git"}function ss(t,e){if(t.length===0)throw new Error("invalid tree entry: empty name");if(t.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${t}'`);if(t.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(t==="."||t==="..")throw new Error(`invalid tree entry: '${t}'`);if(rs(t))throw new Error(`invalid tree entry: '${t}'`);if(!ns.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${t}'`)}function He(t){let e=[],n=0;for(;n<t.byteLength;){let r=t.indexOf(32,n);if(r===-1)break;let s=kn.decode(t.subarray(n,r)),i=t.indexOf(0,r+1);if(i===-1)break;let o=kn.decode(t.subarray(r+1,i)),a=t.subarray(i+1,i+21),c=ge(a),f=s.padStart(6,"0");ss(o,f),e.push({mode:f,name:o,hash:c}),n=i+21}return{type:"tree",entries:e}}function Ze(t){let e=[];for(let i of t.entries){let o=i.mode.replace(/^0+/,""),a=ts.encode(`${o} ${i.name}\0`),c=J(i.hash);e.push(a),e.push(c)}let n=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}async function Rt(t,e){return Sn(t,e,"")}async function Sn(t,e,n){let r=[],s=new Map;for(let o of e){let a=n?o.path.slice(n.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:is(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=n?`${n}/${o}`:o,f=await Sn(t,a,c);r.push({mode:G.DIRECTORY,name:o,hash:f})}r.sort((o,a)=>{let c=o.mode===G.DIRECTORY?`${o.name}/`:o.name,f=a.mode===G.DIRECTORY?`${a.name}/`:a.name;return c<f?-1:c>f?1:0});let i=Ze({type:"tree",entries:r});return W(t,"tree",i)}async function ie(t,e,n=""){let r=await z(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=He(r.content),i=[];for(let o of s.entries){let a=n?`${n}/${o.name}`:o.name;if(o.mode===G.DIRECTORY){let c=await ie(t,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function he(t,e){if(!e)return new Map;let n=await ie(t,e);return new Map(n.map(r=>[r.path,r]))}async function oe(t,e,n){let r=await he(t,e),s=await he(t,n),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)=>Be(o.path,a.path))}function is(t){return t.toString(8).padStart(6,"0")}function Tn(t){return{stdout:"",stderr:`fatal: ${t}
14
+ `,exitCode:128}}var Vo=Tn("not a git repository (or any of the parent directories): .git"),Ko=Tn("this operation must be run in a work tree");function Be(t,e){return t<e?-1:t>e?1:0}function te(t){if(t.length===0)return[];let e=t.split(`
15
+ `);return e[e.length-1]===""&&e.pop(),e}var os=4,jn=1024,Qe=100,nt=0,et=1,Re=2;function kt(t){let e=1;for(;e*e<t;)e++;return e}function as(t,e){let n=new Map,r=[],s=new Array(t.length),i=new Array(e.length);for(let o=0;o<t.length;o++){let a=t[o],c=n.get(a);c===void 0&&(c=r.length,n.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=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function cs(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&t[e-1-a]===n[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function vn(t,e,n,r){e-n>Qe&&(n=e-Qe),r-e>Qe&&(r=e+Qe);let s=0,i=1;for(let c=1;e-c>=n;c++){let f=t[e-c];if(f===nt)s++;else if(f===Re)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let f=t[e+c];if(f===nt)o++;else if(f===Re)a++;else break}return o===0?!1:(o+=s,a+=i,a*os<a+o)}function fs(t,e,n,r,s,i,o,a,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(kt(e),jn);for(let p=i;p<=o;p++){let b=s[t[p]].len2;b===0?l[p]=nt:b>=d?l[p]=Re:l[p]=et}let h=Math.min(kt(r),jn);for(let p=i;p<=a;p++){let b=s[n[p]].len1;b===0?u[p]=nt:b>=h?u[p]=Re:u[p]=et}let m=[];for(let p=i;p<=o;p++)l[p]===et||l[p]===Re&&!vn(l,p,i,o)?m.push(p):c[p]=1;let y=[];for(let p=i;p<=a;p++)u[p]===et||u[p]===Re&&!vn(u,p,i,a)?y.push(p):f[p]=1;return{refIndex1:m,nreff1:m.length,refIndex2:y,nreff2:y.length}}var de=20,Cn=4,ls=256,us=256,tt=2147483647;function V(t,e){return t[e]??0}function hs(t,e,n,r,s,i,o,a,c,f){let l=e-i,u=n-s,d=e-s,h=n-i,m=d-h&1,y=d,p=d,b=h,R=h;o[d]=e,a[h]=n;for(let v=1;;v++){let C=!1;y>l?o[--y-1]=-1:++y,p<u?o[++p+1]=-1:--p;for(let O=p;O>=y;O-=2){let w;V(o,O-1)>=V(o,O+1)?w=V(o,O-1)+1:w=V(o,O+1);let E=w,T=w-O;for(;w<n&&T<i&&t[w]===r[T];)w++,T++;if(w-E>de&&(C=!0),o[O]=w,m&&b<=O&&O<=R&&V(a,O)<=w)return{i1:w,i2:T,minLo:!0,minHi:!0}}b>l?a[--b-1]=tt:++b,R<u?a[++R+1]=tt:--R;for(let O=R;O>=b;O-=2){let w;V(a,O-1)<V(a,O+1)?w=V(a,O-1):w=V(a,O+1)-1;let E=w,T=w-O;for(;w>e&&T>s&&t[w-1]===r[T-1];)w--,T--;if(E-w>de&&(C=!0),a[O]=w,!m&&y<=O&&O<=p&&w<=V(o,O))return{i1:w,i2:T,minLo:!0,minHi:!0}}if(!c){if(C&&v>ls){let O=0,w=null;for(let E=p;E>=y;E-=2){let T=E>d?E-d:d-E,I=V(o,E),P=I-E,S=I-e+(P-s)-T;if(S>Cn*v&&S>O&&e+de<=I&&I<n&&s+de<=P&&P<i){let $=!0;for(let D=1;D<=de;D++)if(t[I-D]!==r[P-D]){$=!1;break}$&&(O=S,w={i1:I,i2:P,minLo:!0,minHi:!1})}}if(w)return w;O=0,w=null;for(let E=R;E>=b;E-=2){let T=E>h?E-h:h-E,I=V(a,E),P=I-E,S=n-I+(i-P)-T;if(S>Cn*v&&S>O&&e<I&&I<=n-de&&s<P&&P<=i-de){let $=!0;for(let D=0;D<de;D++)if(t[I+D]!==r[P+D]){$=!1;break}$&&(O=S,w={i1:I,i2:P,minLo:!1,minHi:!0})}}if(w)return w}if(v>=f){let O=-1,w=-1;for(let I=p;I>=y;I-=2){let P=Math.min(V(o,I),n),S=P-I;i<S&&(P=i+I,S=i),O<P+S&&(O=P+S,w=P)}let E=tt,T=tt;for(let I=R;I>=b;I-=2){let P=Math.max(e,V(a,I)),S=P-I;S<s&&(P=s+I,S=s),P+S<E&&(E=P+S,T=P)}return n+i-E<O-(e+s)?{i1:w,i2:O-w,minLo:!0,minHi:!1}:{i1:T,i2:E-T,minLo:!1,minHi:!0}}}}}function St(t,e,n,r,s,i,o,a,c,f,l,u,d,h){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let m=s;m<i;m++)a[f[m]]=1;else if(s===i)for(let m=e;m<n;m++)o[c[m]]=1;else{let m=hs(t,e,n,r,s,i,l,u,d,h);St(t,e,m.i1,r,s,m.i2,o,a,c,f,l,u,m.minLo,h),St(t,m.i1,n,r,m.i2,i,o,a,c,f,l,u,m.minHi,h)}}function ds(t,e,n,r){let s=[],i=0,o=0,a=1,c=1;for(;i<t.length||o<e.length;){if(i<t.length&&o<e.length&&!n[i]&&!r[o]){s.push({type:"keep",line:t[i]??"",oldLineNo:a++,newLineNo:c++}),i++,o++;continue}for(;i<t.length&&n[i];)s.push({type:"delete",line:t[i]??"",oldLineNo:a++,newLineNo:0}),i++;for(;o<e.length&&r[o];)s.push({type:"insert",line:e[o]??"",oldLineNo:0,newLineNo:c++}),o++}return s}var An=200,$n=20,Ln=100,ms=1,ps=21,ys=-30,gs=6,bs=-4,ws=10,xs=24,Is=17,Es=23,Os=17,Rs=60;function Pt(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);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>=An)return An}return-1}function Mn(t,e,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=Pt(t[n]));for(let s=n-1;s>=0&&(r.preIndent=Pt(t[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===$n){r.preIndent=0;break}for(let s=n+1;s<e&&(r.postIndent=Pt(t[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===$n){r.postIndent=0;break}return r}function Dn(t,e){t.preIndent===-1&&t.preBlank===0&&(e.penalty+=ms),t.endOfFile&&(e.penalty+=ps);let n=t.indent===-1?1+t.postBlank:0,r=t.preBlank+n;e.penalty+=ys*r,e.penalty+=gs*n;let s=t.indent!==-1?t.indent:t.postIndent,i=r!==0;e.effectiveIndent+=s,s===-1||t.preIndent===-1||(s>t.preIndent?e.penalty+=i?ws:bs:s===t.preIndent||(t.postIndent!==-1&&t.postIndent>s?e.penalty+=i?Is:xs:e.penalty+=i?Os:Es))}function Ps(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndent<e.effectiveIndent?1:0);return Rs*n+(t.penalty-e.penalty)}function Un(t,e,n,r,s,i){let o=0,a=0;for(;t[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(t[--o]=1,t[--a]=0;t[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(t[o++]=0,t[a++]=1;t[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(t[--a]=0,t[--o]=1;t[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,y={effectiveIndent:0,penalty:0},p=h;for(a-u-1>p&&(p=a-u-1),a-Ln>p&&(p=a-Ln);p<=a;p++){let b={effectiveIndent:0,penalty:0},R=Mn(n,r,p);Dn(R,b);let v=Mn(n,r,p-u);Dn(v,b),(m===-1||Ps(b,y)<=0)&&(y={effectiveIndent:b.effectiveIndent,penalty:b.penalty},m=p)}for(;a>m;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;t[a];a++);if(f>=i)break;for(c=f+1,f=c;s[f];f++);}}function Tt(t,e){let n=t.length,r=e.length,s=new Uint8Array(n),i=new Uint8Array(r);if(n>0&&r>0){let{classes1:o,classes2:a,classInfo:c}=as(t,e),{dstart:f,dend1:l,dend2:u}=cs(o,n,a,r);if(f>l)for(let d=f;d<r-(n-1-l);d++)i[d]=1;else if(f>u)for(let d=f;d<n-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:y}=fs(o,n,a,r,c,f,l,u,s,i);if(h>0&&y>0){let p=new Array(h);for(let w=0;w<h;w++)p[w]=o[d[w]];let b=new Array(y);for(let w=0;w<y;w++)b[w]=a[m[w]];let R={},v={},C=h+y+3,O=Math.max(us,kt(C));St(p,0,h,b,0,y,s,i,d,m,R,v,!1,O)}else if(h===0)for(let p=0;p<y;p++)i[m[p]]=1;else for(let p=0;p<h;p++)s[d[p]]=1;Un(s,o,t,n,i,r),Un(i,a,e,r,s,n)}}else n===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function Pe(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return e.map((o,a)=>({type:"insert",line:o,oldLineNo:0,newLineNo:a+1}));if(r===0)return t.map((o,a)=>({type:"delete",line:o,oldLineNo:a+1,newLineNo:0}));let{changedOld:s,changedNew:i}=Tt(t,e);return ds(t,e,s,i)}var ks=3;function Hn(t,e=ks){if(e=Math.max(0,e),t.length===0)return[];let n=[];for(let a=0;a<t.length;a++){let c=t[a];c&&c.type!=="keep"&&n.push(a)}if(n.length===0)return[];let r=n[0]??0,s=[],i=Math.max(0,r-e),o=Math.min(t.length-1,r+e);for(let a=1;a<n.length;a++){let c=n[a]??0,f=Math.max(0,c-e),l=Math.min(t.length-1,c+e);f<=o+1||(s.push({start:i,end:o}),i=f),o=l}return s.push({start:i,end:o}),s.map(a=>Ss(t,a.start,a.end))}function Ss(t,e,n){let r=0,s=0,i=0,o=0,a=[],c=!1,f=!1;for(let l=e;l<=n;l++){let u=t[l];if(u)switch(u.type){case"keep":c||(r=u.oldLineNo,c=!0),f||(i=u.newLineNo,f=!0),s++,o++,a.push({type:"context",content:u.line});break;case"delete":c||(r=u.oldLineNo,c=!0),s++,a.push({type:"delete",content:u.line});break;case"insert":f||(i=u.newLineNo,f=!0),o++,a.push({type:"insert",content:u.line});break}}if(c||(r=i>0?i:1),f||(i=r>0?r:1),s===0)for(let l=e;l<=n;l++){let u=t[l];if(u&&u.type==="insert"){r=u.newLineNo>1?u.newLineNo-1:0;break}}if(o===0)for(let l=e;l<=n;l++){let u=t[l];if(u&&u.type==="delete"){i=u.oldLineNo>1?u.oldLineNo-1:0;break}}return{oldStart:r,oldCount:s,newStart:i,newCount:o,lines:a}}function ke(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function Ts(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=ke(e),r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i&&ke(i.path)===n){r=s;break}}return t.splice(r,1)[0]}var js=50;async function be(t,e,n=js){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=Ts(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 vs(t,f,c,n);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 $s(t,f,c,n);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 vs(t,e,n,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let f=ke(c.path);s.has(f)?s.set(f,-1):s.set(f,a)}let i=new Map;for(let a=0;a<n.length;a++){let c=n[a];if(!c)continue;let f=ke(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=n[f];if(!l?.oldHash||!u?.newHash||l.oldHash===u.newHash)continue;let d=await ue(t,l.oldHash),h=await ue(t,u.newHash),m=As(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 Bn=107927;function rt(t){let e=new Map,n=0,r=0,s=0;for(let o=0;o<t.length;o++){let a=t[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let f=(r+Math.imul(s,97))%Bn;e.set(f,(e.get(f)??0)+n),n=0,r=0,s=0}if(n>0){let o=(r+Math.imul(s,97))%Bn;e.set(o,(e.get(o)??0)+n)}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 Cs(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let o=t[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,n+=a):n+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:n,literalAdded:r}}function As(t,e){return t.length===0&&e.length===0?100:t.length===0||e.length===0?0:Nn(t.length,rt(t),e.length,rt(e))}function Nn(t,e,n,r){let s=Math.max(t,n),i=Math.min(t,n);if(i<s-i)return 0;let{srcCopied:o}=Cs(e,r);return Math.floor(o*100/s)}async function $s(t,e,n,r){let s=[];for(let l of e)if(l.oldHash){let u=await ue(t,l.oldHash);s.push({size:u.length,chunks:rt(u)})}else s.push(null);let i=[];for(let l of n)if(l.newHash){let u=await ue(t,l.newHash);i.push({size:u.length,chunks:rt(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<n.length;h++){let m=n[h],y=i[h];if(!m||!y)continue;let p=Nn(d.size,d.chunks,y.size,y.chunks);if(p>=r){let b=ke(u.path)===ke(m.path)?1:0;o.push({similarity:p,nameScore:b,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=n[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 me(t,e,n){return(await he(t,e)).get(n)?.hash??null}async function Fn(t,e,n,r){let s=await oe(t,e,n);if(!s.find(c=>c.status==="added"&&c.path===r))return null;let{renames:o}=await be(t,s);return o.find(c=>c.newPath===r)?.oldPath??null}async function Ls(t,e,n,r,s,i){let o=await me(t,(await A(t,e)).tree,n);if(!o){let y=new Map,p=await A(t,e);for(let b of r)y.set(b.finalIdx,pe(e,n,b.currentLine,i+b.finalIdx,s[b.finalIdx],p,!1,void 0));return y}let a=await U(t,o),c=te(a),f=new Array(s.length),l=[...r],u=e,d=n,h=c;for(;l.length>0;){let y=await A(t,u);if(y.parents.length===0){for(let I of l)f[I.finalIdx]=pe(u,d,I.currentLine,i+I.finalIdx,s[I.finalIdx],y,!0,void 0);break}let p=await me(t,y.tree,d),b=null,R=[];for(let I of y.parents){let P=await A(t,I),S=d,$=await me(t,P.tree,S);if(!$){let D=await Fn(t,P.tree,y.tree,d);D&&(S=D,$=await me(t,P.tree,S))}if($&&(R.push({hash:I,path:S,blobHash:$}),$===p)){b={hash:I,path:S};break}}if(b){u=b.hash,d=b.path;continue}if(R.length===0){for(let I of l)f[I.finalIdx]=pe(u,d,I.currentLine,i+I.finalIdx,s[I.finalIdx],y,!1,void 0);break}let v=R[0],C=await U(t,v.blobHash),O=te(C),w=Pe(O,h),E=new Map;for(let I of w)I.type==="keep"&&E.set(I.newLineNo,I.oldLineNo);let T=[];for(let I of l){let P=E.get(I.currentLine);P!==void 0?T.push({finalIdx:I.finalIdx,currentLine:P}):f[I.finalIdx]=pe(u,d,I.currentLine,i+I.finalIdx,s[I.finalIdx],y,!1,{hash:v.hash,path:v.path})}l=T,u=v.hash,d=v.path,h=O}let m=new Map;for(let y of r)f[y.finalIdx]&&m.set(y.finalIdx,f[y.finalIdx]);return m}async function Gn(t,e,n,r){let s=await A(t,e),i=await me(t,s.tree,n);if(!i)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let o=await U(t,i),a=te(o),c=r?.startLine??1,f=r?.endLine??a.length,l=a.slice(c-1,f),u=new Array(l.length),d=l.map((p,b)=>({finalIdx:b,currentLine:c+b})),h=e,m=n,y=a;for(;d.length>0;){let p=await A(t,h);if(p.parents.length===0){for(let E of d)u[E.finalIdx]=pe(h,m,E.currentLine,c+E.finalIdx,l[E.finalIdx],p,!0,void 0);break}let b=await me(t,p.tree,m),R=[],v=null;for(let E of p.parents){let T=await A(t,E),I=m,P=await me(t,T.tree,I);if(!P){let S=await Fn(t,T.tree,p.tree,m);S&&(I=S,P=await me(t,T.tree,I))}if(P){let S={hash:E,path:I,blobHash:P};if(R.push(S),P===b){v=S;break}}}if(v){h=v.hash,m=v.path;continue}if(R.length===0){for(let E of d)u[E.finalIdx]=pe(h,m,E.currentLine,c+E.finalIdx,l[E.finalIdx],p,!1,void 0);break}if(R.length===1){let E=R[0],T=await U(t,E.blobHash),I=te(T),P=Pe(I,y),S=new Map;for(let D of P)D.type==="keep"&&S.set(D.newLineNo,D.oldLineNo);let $=[];for(let D of d){let ae=S.get(D.currentLine);ae!==void 0?$.push({finalIdx:D.finalIdx,currentLine:ae}):u[D.finalIdx]=pe(h,m,D.currentLine,c+D.finalIdx,l[D.finalIdx],p,!1,{hash:E.hash,path:E.path})}d=$,h=E.hash,m=E.path,y=I;continue}let C=[];for(let E of R){let T=await U(t,E.blobHash),I=te(T),P=Pe(I,y),S=new Map;for(let $ of P)$.type==="keep"&&S.set($.newLineNo,$.oldLineNo);C.push({info:E,newToOld:S})}let O=new Map;for(let E of d){let T=!1;for(let I=0;I<C.length;I++){let P=C[I],S=P.newToOld.get(E.currentLine);if(S!==void 0){let $=O.get(I);$||($={info:P.info,lines:[]},O.set(I,$)),$.lines.push({finalIdx:E.finalIdx,currentLine:S}),T=!0;break}}T||(u[E.finalIdx]=pe(h,m,E.currentLine,c+E.finalIdx,l[E.finalIdx],p,!1,{hash:R[0].hash,path:R[0].path}))}let w=O.get(0);for(let[E,T]of O){if(E===0)continue;let I=await Ls(t,T.info.hash,T.info.path,T.lines,l,c);for(let[P,S]of I)u[P]=S}if(w&&w.lines.length>0){d=w.lines,h=w.info.hash,m=w.info.path;let E=await U(t,w.info.blobHash);y=te(E)}else break}return u}function pe(t,e,n,r,s,i,o,a){return{hash:t,origPath:e,origLine:n,finalLine:r,content:s,author:i.author,committer:i.committer,summary:i.message.split(`
16
+ `)[0],boundary:o,previous:a}}var Se=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 n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),o<r&&this.higher(n[o],n[s])&&(s=o),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*we(t,e,n){if(n?.topoOrder){yield*Ms(t,e,n);return}let r=await Wn(t,n?.exclude),s=new Set(r),i=new Se,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let c of a)s.has(c)||i.push(await st(t,c));for(;i.size>0;){let c=i.pop();if(s.has(c.hash)||(s.add(c.hash),yield c,o?.has(c.hash)))continue;let f=n?.firstParent?c.commit.parents.slice(0,1):c.commit.parents;for(let l of f)if(!s.has(l))try{i.push(await st(t,l))}catch{}}}async function*Ms(t,e,n){let r=await Wn(t,n?.exclude),s=new Set(r),i=new Se,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let h of a)s.has(h)||i.push(await st(t,h));let c=[],f=new Map;for(;i.size>0;){let h=i.pop();if(s.has(h.hash)||(s.add(h.hash),f.set(h.hash,c.length),c.push(h),o?.has(h.hash)))continue;let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let y of m)if(!s.has(y))try{i.push(await st(t,y))}catch{}}let l=c.length;if(l===0)return;let u=new Int32Array(l);for(let h of c){let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let y of m){let p=f.get(y);p!==void 0&&(u[p]=(u[p]??0)+1)}}let d=[];for(let h=l-1;h>=0;h--)u[h]===0&&d.push(h);for(;d.length>0;){let h=d.pop();yield c[h];let m=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let y of m){let p=f.get(y);if(p!==void 0){let b=(u[p]??0)-1;u[p]=b,b===0&&d.push(p)}}}}async function _n(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let a of we(t,e))r.add(a.hash);let s=new Set;for await(let a of we(t,n))s.add(a.hash);let i=0;for(let a of r)s.has(a)||i++;let o=0;for(let a of s)r.has(a)||o++;return{ahead:i,behind:o}}async function Wn(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of we(t,e))n.add(r.hash);return n}async function st(t,e){return{hash:e,commit:await A(t,e)}}function Ds(t){let e=Math.min(t.length,8e3),n=0;for(let r=0;r<e;r++)t.charCodeAt(r)===0&&n++;return n>e*.01}function zn(t,e,n,r){if(Ds(t)){let o=e.some(a=>a.test(t));return{matches:[],binary:o}}let s=t.split(`
17
+ `);if(s.length>0&&s[s.length-1]===""&&s.pop(),n&&e.length>1&&!e.every(a=>s.some(c=>a.test(c))))return{matches:[],binary:!1};let i=[];for(let o=0;o<s.length;o++){let a=s[o],c=e.some(f=>f.test(a));(r?!c:c)&&i.push({lineNo:o+1,line:a})}return{matches:i,binary:!1}}function Us(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Vn(t,e){let n=e?.fixed?Us(t):t;e?.wordRegexp&&(n=`\\b${n}\\b`);let r=e?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}async function Hs(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let o;try{o=await A(t,i)}catch{continue}for(let a of o.parents)n.has(a)||r.push(a)}return n}async function jt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],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;try{a=await A(t,o)}catch{continue}for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function Ne(t,e,n){if(e===n)return[e];let r=await Hs(t,e),s=[],i=new Set,o=[n],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;try{l=await A(t,f)}catch{continue}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 jt(t,f,u)){l=!0;break}l||c.push(f)}return c.length<=1?c:Bs(t,e,n,c)}async function Bs(t,e,n,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:n,mask:2,seq:f++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await A(t,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 v=l[R],C=await u(v.hash),O=l[d];(C>h||C===h&&v.seq<O.seq)&&(d=R,h=C)}let m=l.splice(d,1)[0],y=a.get(m.hash)??0,p=y|m.mask;if(p===y)continue;if(a.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let b=await A(t,m.hash);for(let R of b.parents)l.push({hash:R,mask:p,seq:f++})}for(let d of r)i.has(d)||o.push(d);return o}function vt(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=Tt(t,e);return Ns(s,n,i,r)}function Ns(t,e,n,r){let s=[],i=0,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!t[i]&&!n[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&t[i];)i++;for(;o<r&&n[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function Fs(t,e,n){let r=[];for(let c of vt(e,t))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of vt(e,n))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"?t:n;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:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let b of u){let R=b.oStart,v=R+b.oLength,C=b.abStart,O=C+b.abLength,w=d[b.ab];w.abMin=Math.min(C,w.abMin),w.abMax=Math.max(O,w.abMax),w.oMin=Math.min(R,w.oMin),w.oMax=Math.max(v,w.oMax)}let h=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(l-d.a.oMax),y=d.b.abMin+(f-d.b.oMin),p=d.b.abMax+(l-d.b.oMax);s.push({stable:!1,a:t.slice(h,m),o:e.slice(f,l),b:n.slice(y,p)})}i=l}return o(e.length),s}function Gs(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=Fs(t,e,n),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&&Yn(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?Kn(o):Kn(_s(o))}function Fe(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",o=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),f=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,l=Gs(t,e,n,{conflictStyle:i}),u=!1,d=[];for(let h of l)h.type==="ok"?d.push(...h.lines):(u=!0,i==="diff3"?d.push(o,...h.a,a,...h.o,c,...h.b,f):d.push(o,...h.a,c,...h.b,f));return{conflict:u,result:d}}function _s(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...Ws(n));return e}function Ws(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(Yn(e,n))return[t];let r=vt(e,n);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:n.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"?[t]:s}function Kn(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.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 n.push(i)}return n}function xe(t,e,n,r){let s=Fe(q(t),q(e),q(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(Ct);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
14
18
  `)}
15
19
  `:a.join(`
16
- `)}function V(t){if(t==="")return[];let e=t.split(`
17
- `);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function Pt(t){return t.endsWith("\0")?t.slice(0,-1):t}function kn(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}var Ie=new TextDecoder,fe=new TextEncoder,Rn={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function xe(t,e,n,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await os(t,e,n,r),f=await cs(t,i,o,a,c,s);return fs(t,i,s,f)}async function Ln(t,e,n,r){let s=await $e(t,e,n),i=await U(t,e),o=await U(t,n);if(s.length===0)return{...await xe(t,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let f=await U(t,s[0]);return{...await xe(t,f.tree,i.tree,o.tree,r),baseTree:f.tree}}let a=await vn(t,e,n,s,1);return{...await xe(t,a,i.tree,o.tree,r),baseTree:a}}async function os(t,e,n,r){let s=await ie(t,e),i=await ie(t,n),o=await ie(t,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 u=s.get(f)??null,h=i.get(f)??null,d=o.get(f)??null,l=u?{hash:u.hash,mode:u.mode}:null,m=h?{hash:h.hash,mode:h.mode}:null,g=d?{hash:d.hash,mode:d.mode}:null,p=(u?1:0)|(h?2:0)|(d?4:0),I=u?.hash??null,k=h?.hash??null,j=d?.hash??null,A=0;I!==null&&I===k&&(A|=3),I!==null&&I===j&&(A|=5),k!==null&&k===j&&(A|=6);let E={path:f,stages:[l,m,g],pathnames:[f,f,f],filemask:p,matchMask:A,merged:{result:null,clean:!1},pathConflict:!1};if(as(E)){c.set(f,E);continue}c.set(f,E)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function as(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,o=r?.hash??null;return i===s&&o===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===o&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&o===null?(t.merged={result:null,clean:!0},!0):o===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?t.merged={result:{hash:o,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function cs(t,e,n,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[w,b]of n)r.has(w)||a.push({path:w,status:"deleted",oldHash:b.hash,oldMode:b.mode}),s.has(w)||c.push({path:w,status:"deleted",oldHash:b.hash,oldMode:b.mode});for(let[w,b]of r)n.has(w)||a.push({path:w,status:"added",newHash:b.hash,newMode:b.mode});for(let[w,b]of s)n.has(w)||c.push({path:w,status:"added",newHash:b.hash,newMode:b.mode});let f=await Ae(t,a),u=await Ae(t,c);if(f.renames.length===0&&u.renames.length===0)return o;let h=new Map,d=new Map;for(let w of f.renames)h.set(w.oldPath,w);for(let w of u.renames)d.set(w.oldPath,w);let l=new Set;for(let[w]of r)!n.has(w)&&s.has(w)&&l.add(w);let m=new Set,g=i?.a??"HEAD",p=i?.b??"theirs";function I(w,b,R=0){o.msgBuf.push({sortKey:w,subOrder:R,text:b})}for(let w of[...n.keys()].sort()){let b=h.get(w),R=d.get(w);if(!b&&!R)continue;let M=n.get(w);if(m.add(w),b&&R)if(m.add(b.newPath),m.add(R.newPath),b.newPath===R.newPath){let L=r.get(b.newPath),C=s.get(R.newPath);if(L.hash===C.hash)o.entries.push(z(b.newPath,L));else{let N=kt(e,b.newPath);N.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],N.pathnames=[w,b.newPath,R.newPath],N.filemask=7,N.merged={result:null,clean:!1}}}else{let L=r.get(b.newPath),C=s.get(R.newPath),N=await Mn(t,M,L,C,i);N.conflict&&I(w,`Auto-merging ${w}`,-1),o.conflicts.push({path:w,reason:"rename-rename",oursPath:b.newPath,theirsPath:R.newPath}),I(w,`CONFLICT (rename/rename): ${w} renamed to ${b.newPath} in ${g} and to ${R.newPath} in ${p}.`),o.entries.push(z(w,M,1)),o.entries.push(G(b.newPath,L.mode,N.hash,2)),o.entries.push(G(R.newPath,C.mode,N.hash,3)),o.worktreeBlobs.set(b.newPath,{hash:N.hash,mode:L.mode}),o.worktreeBlobs.set(R.newPath,{hash:N.hash,mode:C.mode})}else if(b){m.add(b.newPath);let L=s.get(w),C=r.get(b.newPath),N=l.has(b.newPath);if(L)if(N)await $n(t,o,b.newPath,w,M,C,L,r,s,!1,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(z(b.newPath,C));else if(L.hash===M.hash)o.entries.push(z(b.newPath,C));else if(C.hash===M.hash)o.entries.push(G(b.newPath,C.mode,L.hash));else{let F=kt(e,b.newPath);F.stages=[{hash:M.hash,mode:M.mode},{hash:C.hash,mode:C.mode},{hash:L.hash,mode:L.mode}],F.pathnames=[w,b.newPath,w],F.filemask=7,F.merged={result:null,clean:!1}}else{let F=s.get(b.newPath);if(o.conflicts.push({path:b.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:w}),I(b.newPath,`CONFLICT (rename/delete): ${w} renamed to ${b.newPath} in ${g}, but deleted in ${p}.`),F){o.conflicts.push({path:b.newPath,reason:"add-add"}),I(b.newPath,`Auto-merging ${b.newPath}`,0),I(b.newPath,`CONFLICT (add/add): Merge conflict in ${b.newPath}`,1),o.entries.push(z(b.newPath,C,2)),o.entries.push(z(b.newPath,F,3));let Ye=await qe(t,C.hash,F.hash,C.mode,i);o.worktreeBlobs.set(b.newPath,{hash:Ye,mode:C.mode})}else o.entries.push(G(b.newPath,M.mode,M.hash,1)),o.entries.push(z(b.newPath,C,2)),o.worktreeBlobs.set(b.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&I(b.newPath,`CONFLICT (modify/delete): ${b.newPath} deleted in ${p} and modified in ${g}. Version ${g} of ${b.newPath} left in tree.`,1)}}else if(R){m.add(R.newPath);let L=r.get(w),C=s.get(R.newPath),N=l.has(R.newPath);if(L)if(N)await $n(t,o,R.newPath,w,M,L,C,r,s,!0,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(z(R.newPath,C));else if(L.hash===M.hash)o.entries.push(z(R.newPath,C));else if(C.hash===M.hash)o.entries.push(G(R.newPath,C.mode,L.hash));else{let F=kt(e,R.newPath);F.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],F.pathnames=[w,w,R.newPath],F.filemask=7,F.merged={result:null,clean:!1}}else{let F=r.get(R.newPath);if(o.conflicts.push({path:R.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:w}),I(R.newPath,`CONFLICT (rename/delete): ${w} renamed to ${R.newPath} in ${p}, but deleted in ${g}.`),F){o.conflicts.push({path:R.newPath,reason:"add-add"}),I(R.newPath,`Auto-merging ${R.newPath}`,0),I(R.newPath,`CONFLICT (add/add): Merge conflict in ${R.newPath}`,1),o.entries.push(z(R.newPath,F,2)),o.entries.push(z(R.newPath,C,3));let Ye=await qe(t,F.hash,C.hash,F.mode,i);o.worktreeBlobs.set(R.newPath,{hash:Ye,mode:F.mode})}else o.entries.push(G(R.newPath,M.mode,M.hash,1)),o.entries.push(z(R.newPath,C,3)),o.worktreeBlobs.set(R.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&I(R.newPath,`CONFLICT (modify/delete): ${R.newPath} deleted in ${g} and modified in ${p}. Version ${p} of ${R.newPath} left in tree.`,1)}}}let k=new Set(f.renames.map(w=>w.newPath)),j=new Set(u.renames.map(w=>w.newPath)),A=Sn(n,r),E=Sn(n,s),y=Tn(A,s,n),O=Tn(E,r,n),T=Cn(f.renames,y),x=Cn(u.renames,O),P=jn(T),S=jn(x);for(let w of[...P.keys()])S.has(w)&&(P.delete(w),S.delete(w));let $=new Set(P.keys()),v=new Set(S.keys());if(S.size>0)for(let w of a){if(w.status!=="added"||k.has(w.path))continue;let b=An(w.path,S,$);if(!b)continue;if(e.has(b)||n.has(b)||r.has(b)||s.has(b)){if(r.has(b)){I(b,`CONFLICT (implicit dir rename): Existing file/dir at ${b} in the way of implicit directory rename(s) putting the following path(s) there: ${w.path}.`,1);continue}let L=r.get(w.path),C=s.get(b)??n.get(b);o.entries.push(G(b,L.mode,L.hash,2)),C&&o.entries.push(G(b,C.mode,C.hash,3)),o.worktreeBlobs.set(b,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:b,reason:"add-add"}),I(b,`CONFLICT (file location): ${w.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${b}.`,1);let N=e.get(w.path);N&&(N.merged={result:null,clean:!0}),m.add(w.path);continue}let R=r.get(w.path);o.entries.push(G(b,R.mode,R.hash,2)),o.worktreeBlobs.set(b,{hash:R.hash,mode:R.mode}),o.conflicts.push({path:b,reason:"directory-rename"}),I(b,`CONFLICT (file location): ${w.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${b}.`,1);let M=e.get(w.path);M&&(M.merged={result:null,clean:!0}),m.add(w.path)}if(P.size>0)for(let w of c){if(w.status!=="added"||j.has(w.path))continue;let b=An(w.path,P,v);if(!b)continue;if(e.has(b)||n.has(b)||r.has(b)||s.has(b)){if(s.has(b)){I(b,`CONFLICT (implicit dir rename): Existing file/dir at ${b} in the way of implicit directory rename(s) putting the following path(s) there: ${w.path}.`,1);continue}let L=s.get(w.path),C=r.get(b)??n.get(b);C&&o.entries.push(G(b,C.mode,C.hash,2)),o.entries.push(G(b,L.mode,L.hash,3)),o.worktreeBlobs.set(b,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:b,reason:"add-add"}),I(b,`CONFLICT (file location): ${w.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${b}.`,1);let N=e.get(w.path);N&&(N.merged={result:null,clean:!0}),m.add(w.path);continue}let R=s.get(w.path);o.entries.push(G(b,R.mode,R.hash,3)),o.worktreeBlobs.set(b,{hash:R.hash,mode:R.mode}),o.conflicts.push({path:b,reason:"directory-rename"}),I(b,`CONFLICT (file location): ${w.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${b}.`,1);let M=e.get(w.path);M&&(M.merged={result:null,clean:!0}),m.add(w.path)}let ne=new Set(o.entries.map(w=>w.path));for(let w of ne){let b=e.get(w);b&&(b.merged={result:null,clean:!0})}for(let w of m){if(ne.has(w))continue;let b=e.get(w);if(!b||b.merged.clean)continue;b.filemask===7&&!b.pathConflict||(b.merged={result:null,clean:!0})}return o}function Sn(t,e){let n=new Set;for(let i of t.keys()){let o=K(i);for(;o;)n.add(o),o=K(o)}let r=new Set;for(let i of e.keys()){let o=K(i);for(;o;)r.add(o),o=K(o)}let s=new Set;for(let i of n)r.has(i)||s.add(i);return s}function Tn(t,e,n){if(t.size===0)return t;let r=new Set;for(let s of e.keys()){if(n.has(s))continue;let i=K(s)??"";t.has(i)&&r.add(i)}for(let s of[...r]){let i=K(s);for(;i;)t.has(i)&&!r.has(i)&&r.add(i),i=K(i)}return r}function Cn(t,e){let n=new Map;for(let r of t){let s=K(r.oldPath),i=K(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)),u=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==u)break}if(e.has(s)){let a=n.get(s);a||(a=new Map,n.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=K(s),i=K(i)}}return n}function jn(t){let e=new Map;for(let[n,r]of t){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(n,o)}return e}function An(t,e,n){let r=K(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let o=t.slice(r.length+1);return i?`${i}/${o}`:o}r=K(r)}let s=e.get("");return s!==void 0&&!n.has(s)?`${s}/${t}`:null}function K(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function $n(t,e,n,r,s,i,o,a,c,f=!1,u){let h=f?a.get(n):c.get(n),d=f?o:i;if(h.hash===d.hash){e.entries.push(G(n,h.mode,h.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await Mn(t,s,i,o,u,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(h.hash===m.hash)e.entries.push(G(n,h.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){e.entries.push(z(n,h,2)),e.entries.push(G(n,o.mode,m.hash,3));let g=await qe(t,h.hash,m.hash,h.mode,u);e.worktreeBlobs.set(n,{hash:g,mode:h.mode})}else{e.entries.push(G(n,i.mode,m.hash,2)),e.entries.push(z(n,h,3));let g=await qe(t,m.hash,h.hash,i.mode,u);e.worktreeBlobs.set(n,{hash:g,mode:i.mode})}}async function Mn(t,e,n,r,s,i,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(Q(e.mode)||Q(n.mode)||Q(r.mode))return{hash:n.hash,conflict:!0};let a=await H(t,e.hash),c=await H(t,n.hash),f=await H(t,r.hash);if(ee(c)||ee(f)||ee(a))return{hash:n.hash,conflict:!0};let u=V(a),h=V(c),d=V(f),l=s?.conflictStyle,m=Le(h,u,d,{conflictStyle:l});if(!m.conflict)return{hash:await Rt(t,m.result),conflict:!1};let g=s?.a??"HEAD",p=s?.b??"theirs",I=i?.oursPath?`${g}:${i.oursPath}`:g,k=i?.theirsPath?`${p}:${i.theirsPath}`:p,j=de(c,a,f,{a:I,b:k,markerSize:o??7,conflictStyle:l});return{hash:await _(t,"blob",fe.encode(j)),conflict:!0}}async function qe(t,e,n,r,s){let i=await H(t,e),o=await H(t,n),a=de(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return _(t,"blob",fe.encode(a))}function z(t,e,n=0){return G(t,e.mode,e.hash,n)}function G(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:re()}}async function fs(t,e,n,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(l,m,g=0){o.push({sortKey:l,subOrder:g,text:m})}for(let l of[...e.keys()].sort()){let m=e.get(l);if(m.merged.clean){m.merged.result?.hash&&s.push(B(l,m.merged.result.hash,m.merged.result.mode));continue}await ls(t,m,n,s,i,c,a)}o.sort((l,m)=>(l.sortKey<m.sortKey?-1:l.sortKey>m.sortKey?1:0)||l.subOrder-m.subOrder);let f=o.map(l=>l.text),u=[],h=new Set;for(let l of s)l.stage===0&&(u.push(l),h.add(l.path));for(let[l,m]of a)h.has(l)||u.push(B(l,m.hash,m.mode));u.sort((l,m)=>je(l.path,m.path));let d=await bt(t,u);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function ls(t,e,n,r,s,i,o){let a=e.path,[c,f,u]=e.stages,h=c?.hash??null,d=f?.hash??null,l=u?.hash??null;if(d===null&&l!==null&&h!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=n?.a??"HEAD",g=n?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${g}. Version ${g} of ${a} left in tree.`),c&&r.push(B(a,h,c.mode,1)),r.push(B(a,l,u.mode,3)),o.set(a,{hash:l,mode:u.mode});return}if(l===null&&d!==null&&h!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=n?.b??"theirs",g=n?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${g}. Version ${g} of ${a} left in tree.`),c&&r.push(B(a,h,c.mode,1)),r.push(B(a,d,f.mode,2)),o.set(a,{hash:d,mode:f.mode});return}if(h===null&&d!==null&&l!==null){if(d===l){r.push(B(a,d,f.mode));return}i(a,`Auto-merging ${a}`,0);let m=await H(t,d),g=await H(t,l);if(ee(m)||ee(g)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(B(a,d,f.mode,2)),r.push(B(a,l,u.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let p=V(""),I=V(m),k=V(g),j=Le(I,p,k,{conflictStyle:n?.conflictStyle});if(!j.conflict){let y=await Rt(t,j.result);r.push(B(a,y,f.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(B(a,d,f.mode,2)),r.push(B(a,l,u.mode,3));let A=de(m,"",g,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),E=await _(t,"blob",fe.encode(A));o.set(a,{hash:E,mode:f.mode});return}if(h!==null&&d!==null&&l!==null){if(d===h){r.push(B(a,l,u.mode));return}if(l===h){r.push(B(a,d,f.mode));return}if(d===l){r.push(B(a,d,f.mode));return}if(i(a,`Auto-merging ${a}`,0),Q(c.mode)||Q(f.mode)||Q(u.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(B(a,h,c.mode,1)),r.push(B(a,d,f.mode,2)),r.push(B(a,l,u.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let m=await H(t,h),g=await H(t,d),p=await H(t,l);if(ee(g)||ee(p)||ee(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(B(a,h,c.mode,1)),r.push(B(a,d,f.mode,2)),r.push(B(a,l,u.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let I=V(m),k=V(g),j=V(p),A=Le(k,I,j,{conflictStyle:n?.conflictStyle});if(A.conflict){let E=e.pathnames[1],y=e.pathnames[2],O=E!==a||y!==a,T={path:a,reason:"content"};O&&(E!==a&&(T.oursOrigPath=E),y!==a&&(T.theirsOrigPath=y)),s.push(T),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(B(a,h,c.mode,1)),r.push(B(a,d,f.mode,2)),r.push(B(a,l,u.mode,3));let x=O?`${n?.a??"HEAD"}:${E}`:n?.a??"HEAD",P=O?`${n?.b??"theirs"}:${y}`:n?.b??"theirs",S=de(g,m,p,{a:x,b:P,conflictStyle:n?.conflictStyle}),$=await _(t,"blob",fe.encode(S));o.set(a,{hash:$,mode:f.mode})}else{let E=await Rt(t,A.result);r.push(B(a,E,f.mode))}return}}var us=200;async function vn(t,e,n,r,s){let i=await Promise.all(r.map(async u=>({hash:u,timestamp:(await U(t,u)).committer.timestamp})));i.sort((u,h)=>u.timestamp-h.timestamp);let o=i.map(u=>u.hash),a=o[0],c=a,f=(await U(t,a)).tree;for(let u=1;u<o.length;u++){let h=o[u],d=(await U(t,h)).tree,l=null;if(s>=us)l=f;else{let p=await $e(t,c,h);p.length===0?l=null:p.length===1?l=(await U(t,p[0])).tree:l=await vn(t,c,h,p,s+1)}let m=await xe(t,l,f,d);f=await hs(t,m,s);let g=Be({type:"commit",tree:f,parents:[c,h],author:Rn,committer:Rn,message:"merged common ancestors"});c=await _(t,"commit",g)}return f}async function hs(t,e,n){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+n*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let u=i(a.path,1);if(u){r.push({...u,stage:0});continue}}if(a.reason==="rename-rename"){let u=a.oursPath??a.path,h=a.theirsPath??a.path,d=i(a.path,1),l=i(u,2),m=i(h,3);if(l&&m){let g=Ie.decode((await q(t,l.hash)).content),p=Ie.decode((await q(t,m.hash)).content),I=d?Ie.decode((await q(t,d.hash)).content):"",k=8+n*2,j=o.a??"Temporary merge branch 1",A=o.b??"Temporary merge branch 2",E=de(g,I,p,{a:`${j}:${u}`,o:o.o,b:`${A}:${h}`,markerSize:k}),y=await _(t,"blob",fe.encode(E));r.push({path:u,mode:l.mode,hash:y,stage:0,stat:re()}),r.push({path:h,mode:m.mode,hash:y,stage:0,stat:re()});continue}else if(l){r.push({...l,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 u=Ie.decode((await q(t,c.hash)).content),h=Ie.decode((await q(t,f.hash)).content),d=a.reason==="content"?i(a.path,1):null,l=d?Ie.decode((await q(t,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,g=o.a??"Temporary merge branch 1",p=o.b??"Temporary merge branch 2",I=m?`${g}:${a.oursOrigPath??a.path}`:g,k=m?`${p}:${a.theirsOrigPath??a.path}`:p,j=de(u,l,h,{a:I,o:o.o,b:k,markerSize:o.markerSize}),A=await _(t,"blob",fe.encode(j));r.push({path:a.path,mode:c.mode,hash:A,stage:0,stat:re()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>je(a.path,c.path)),bt(t,r)}async function Rt(t,e){let n=e.map(Pt);if(n.length===0)return _(t,"blob",fe.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?n.join(`
20
+ `)}function q(t){if(t==="")return[];let e=t.split(`
21
+ `);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function Ct(t){return t.endsWith("\0")?t.slice(0,-1):t}function Yn(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}var Te=new TextDecoder,ye=new TextEncoder,qn={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function je(t,e,n,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await zs(t,e,n,r),f=await Ks(t,i,o,a,c,s);return Ys(t,i,s,f)}async function nr(t,e,n,r){let s=await Ne(t,e,n),i=await A(t,e),o=await A(t,n);if(s.length===0)return{...await je(t,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let f=await A(t,s[0]);return{...await je(t,f.tree,i.tree,o.tree,r),baseTree:f.tree}}let a=await sr(t,e,n,s,1);return{...await je(t,a,i.tree,o.tree,r),baseTree:a}}async function zs(t,e,n,r){let s=await he(t,e),i=await he(t,n),o=await he(t,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,y=d?{hash:d.hash,mode:d.mode}:null,p=(l?1:0)|(u?2:0)|(d?4:0),b=l?.hash??null,R=u?.hash??null,v=d?.hash??null,C=0;b!==null&&b===R&&(C|=3),b!==null&&b===v&&(C|=5),R!==null&&R===v&&(C|=6);let O={path:f,stages:[h,m,y],pathnames:[f,f,f],filemask:p,matchMask:C,merged:{result:null,clean:!1},pathConflict:!1};if(Vs(O)){c.set(f,O);continue}c.set(f,O)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function Vs(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,o=r?.hash??null;return i===s&&o===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===o&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&o===null?(t.merged={result:null,clean:!0},!0):o===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?t.merged={result:{hash:o,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function Ks(t,e,n,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[x,g]of n)r.has(x)||a.push({path:x,status:"deleted",oldHash:g.hash,oldMode:g.mode}),s.has(x)||c.push({path:x,status:"deleted",oldHash:g.hash,oldMode:g.mode});for(let[x,g]of r)n.has(x)||a.push({path:x,status:"added",newHash:g.hash,newMode:g.mode});for(let[x,g]of s)n.has(x)||c.push({path:x,status:"added",newHash:g.hash,newMode:g.mode});let f=await be(t,a),l=await be(t,c);if(f.renames.length===0&&l.renames.length===0)return o;let u=new Map,d=new Map;for(let x of f.renames)u.set(x.oldPath,x);for(let x of l.renames)d.set(x.oldPath,x);let h=new Set;for(let[x]of r)!n.has(x)&&s.has(x)&&h.add(x);let m=new Set,y=i?.a??"HEAD",p=i?.b??"theirs";function b(x,g,k=0){o.msgBuf.push({sortKey:x,subOrder:k,text:g})}for(let x of[...n.keys()].sort()){let g=u.get(x),k=d.get(x);if(!g&&!k)continue;let M=n.get(x);if(m.add(x),g&&k)if(m.add(g.newPath),m.add(k.newPath),g.newPath===k.newPath){let L=r.get(g.newPath),j=s.get(k.newPath);if(L.hash===j.hash)o.entries.push(K(g.newPath,L));else{let N=At(e,g.newPath);N.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:j.hash,mode:j.mode}],N.pathnames=[x,g.newPath,k.newPath],N.filemask=7,N.merged={result:null,clean:!1}}}else{let L=r.get(g.newPath),j=s.get(k.newPath),N=await rr(t,M,L,j,i);N.conflict&&b(x,`Auto-merging ${x}`,-1),o.conflicts.push({path:x,reason:"rename-rename",oursPath:g.newPath,theirsPath:k.newPath}),b(x,`CONFLICT (rename/rename): ${x} renamed to ${g.newPath} in ${y} and to ${k.newPath} in ${p}.`),o.entries.push(K(x,M,1)),o.entries.push(_(g.newPath,L.mode,N.hash,2)),o.entries.push(_(k.newPath,j.mode,N.hash,3)),o.worktreeBlobs.set(g.newPath,{hash:N.hash,mode:L.mode}),o.worktreeBlobs.set(k.newPath,{hash:N.hash,mode:j.mode})}else if(g){m.add(g.newPath);let L=s.get(x),j=r.get(g.newPath),N=h.has(g.newPath);if(L)if(N)await tr(t,o,g.newPath,x,M,j,L,r,s,!1,i);else if(L.hash===M.hash&&j.hash===M.hash)o.entries.push(K(g.newPath,j));else if(L.hash===M.hash)o.entries.push(K(g.newPath,j));else if(j.hash===M.hash)o.entries.push(_(g.newPath,j.mode,L.hash));else{let F=At(e,g.newPath);F.stages=[{hash:M.hash,mode:M.mode},{hash:j.hash,mode:j.mode},{hash:L.hash,mode:L.mode}],F.pathnames=[x,g.newPath,x],F.filemask=7,F.merged={result:null,clean:!1}}else{let F=s.get(g.newPath);if(o.conflicts.push({path:g.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:x}),b(g.newPath,`CONFLICT (rename/delete): ${x} renamed to ${g.newPath} in ${y}, but deleted in ${p}.`),F){o.conflicts.push({path:g.newPath,reason:"add-add"}),b(g.newPath,`Auto-merging ${g.newPath}`,0),b(g.newPath,`CONFLICT (add/add): Merge conflict in ${g.newPath}`,1),o.entries.push(K(g.newPath,j,2)),o.entries.push(K(g.newPath,F,3));let at=await it(t,j.hash,F.hash,j.mode,i);o.worktreeBlobs.set(g.newPath,{hash:at,mode:j.mode})}else o.entries.push(_(g.newPath,M.mode,M.hash,1)),o.entries.push(K(g.newPath,j,2)),o.worktreeBlobs.set(g.newPath,{hash:j.hash,mode:j.mode}),j.hash!==M.hash&&b(g.newPath,`CONFLICT (modify/delete): ${g.newPath} deleted in ${p} and modified in ${y}. Version ${y} of ${g.newPath} left in tree.`,1)}}else if(k){m.add(k.newPath);let L=r.get(x),j=s.get(k.newPath),N=h.has(k.newPath);if(L)if(N)await tr(t,o,k.newPath,x,M,L,j,r,s,!0,i);else if(L.hash===M.hash&&j.hash===M.hash)o.entries.push(K(k.newPath,j));else if(L.hash===M.hash)o.entries.push(K(k.newPath,j));else if(j.hash===M.hash)o.entries.push(_(k.newPath,j.mode,L.hash));else{let F=At(e,k.newPath);F.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:j.hash,mode:j.mode}],F.pathnames=[x,x,k.newPath],F.filemask=7,F.merged={result:null,clean:!1}}else{let F=r.get(k.newPath);if(o.conflicts.push({path:k.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:x}),b(k.newPath,`CONFLICT (rename/delete): ${x} renamed to ${k.newPath} in ${p}, but deleted in ${y}.`),F){o.conflicts.push({path:k.newPath,reason:"add-add"}),b(k.newPath,`Auto-merging ${k.newPath}`,0),b(k.newPath,`CONFLICT (add/add): Merge conflict in ${k.newPath}`,1),o.entries.push(K(k.newPath,F,2)),o.entries.push(K(k.newPath,j,3));let at=await it(t,F.hash,j.hash,F.mode,i);o.worktreeBlobs.set(k.newPath,{hash:at,mode:F.mode})}else o.entries.push(_(k.newPath,M.mode,M.hash,1)),o.entries.push(K(k.newPath,j,3)),o.worktreeBlobs.set(k.newPath,{hash:j.hash,mode:j.mode}),j.hash!==M.hash&&b(k.newPath,`CONFLICT (modify/delete): ${k.newPath} deleted in ${y} and modified in ${p}. Version ${p} of ${k.newPath} left in tree.`,1)}}}let R=new Set(f.renames.map(x=>x.newPath)),v=new Set(l.renames.map(x=>x.newPath)),C=Xn(n,r),O=Xn(n,s),w=Jn(C,s,n),E=Jn(O,r,n),T=Zn(f.renames,w),I=Zn(l.renames,E),P=Qn(T),S=Qn(I);for(let x of[...P.keys()])S.has(x)&&(P.delete(x),S.delete(x));let $=new Set(P.keys()),D=new Set(S.keys());if(S.size>0)for(let x of a){if(x.status!=="added"||R.has(x.path))continue;let g=er(x.path,S,$);if(!g)continue;if(e.has(g)||n.has(g)||r.has(g)||s.has(g)){if(r.has(g)){b(g,`CONFLICT (implicit dir rename): Existing file/dir at ${g} in the way of implicit directory rename(s) putting the following path(s) there: ${x.path}.`,1);continue}let L=r.get(x.path),j=s.get(g)??n.get(g);o.entries.push(_(g,L.mode,L.hash,2)),j&&o.entries.push(_(g,j.mode,j.hash,3)),o.worktreeBlobs.set(g,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:g,reason:"add-add"}),b(g,`CONFLICT (file location): ${x.path} added in ${y} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${g}.`,1);let N=e.get(x.path);N&&(N.merged={result:null,clean:!0}),m.add(x.path);continue}let k=r.get(x.path);o.entries.push(_(g,k.mode,k.hash,2)),o.worktreeBlobs.set(g,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:g,reason:"directory-rename"}),b(g,`CONFLICT (file location): ${x.path} added in ${y} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${g}.`,1);let M=e.get(x.path);M&&(M.merged={result:null,clean:!0}),m.add(x.path)}if(P.size>0)for(let x of c){if(x.status!=="added"||v.has(x.path))continue;let g=er(x.path,P,D);if(!g)continue;if(e.has(g)||n.has(g)||r.has(g)||s.has(g)){if(s.has(g)){b(g,`CONFLICT (implicit dir rename): Existing file/dir at ${g} in the way of implicit directory rename(s) putting the following path(s) there: ${x.path}.`,1);continue}let L=s.get(x.path),j=r.get(g)??n.get(g);j&&o.entries.push(_(g,j.mode,j.hash,2)),o.entries.push(_(g,L.mode,L.hash,3)),o.worktreeBlobs.set(g,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:g,reason:"add-add"}),b(g,`CONFLICT (file location): ${x.path} added in ${p} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${g}.`,1);let N=e.get(x.path);N&&(N.merged={result:null,clean:!0}),m.add(x.path);continue}let k=s.get(x.path);o.entries.push(_(g,k.mode,k.hash,3)),o.worktreeBlobs.set(g,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:g,reason:"directory-rename"}),b(g,`CONFLICT (file location): ${x.path} added in ${p} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${g}.`,1);let M=e.get(x.path);M&&(M.merged={result:null,clean:!0}),m.add(x.path)}let ae=new Set(o.entries.map(x=>x.path));for(let x of ae){let g=e.get(x);g&&(g.merged={result:null,clean:!0})}for(let x of m){if(ae.has(x))continue;let g=e.get(x);if(!g||g.merged.clean)continue;g.filemask===7&&!g.pathConflict||(g.merged={result:null,clean:!0})}return o}function Xn(t,e){let n=new Set;for(let i of t.keys()){let o=X(i);for(;o;)n.add(o),o=X(o)}let r=new Set;for(let i of e.keys()){let o=X(i);for(;o;)r.add(o),o=X(o)}let s=new Set;for(let i of n)r.has(i)||s.add(i);return s}function Jn(t,e,n){if(t.size===0)return t;let r=new Set;for(let s of e.keys()){if(n.has(s))continue;let i=X(s)??"";t.has(i)&&r.add(i)}for(let s of[...r]){let i=X(s);for(;i;)t.has(i)&&!r.has(i)&&r.add(i),i=X(i)}return r}function Zn(t,e){let n=new Map;for(let r of t){let s=X(r.oldPath),i=X(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=n.get(s);a||(a=new Map,n.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=X(s),i=X(i)}}return n}function Qn(t){let e=new Map;for(let[n,r]of t){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(n,o)}return e}function er(t,e,n){let r=X(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let o=t.slice(r.length+1);return i?`${i}/${o}`:o}r=X(r)}let s=e.get("");return s!==void 0&&!n.has(s)?`${s}/${t}`:null}function X(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function tr(t,e,n,r,s,i,o,a,c,f=!1,l){let u=f?a.get(n):c.get(n),d=f?o:i;if(u.hash===d.hash){e.entries.push(_(n,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await rr(t,s,i,o,l,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(_(n,u.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){e.entries.push(K(n,u,2)),e.entries.push(_(n,o.mode,m.hash,3));let y=await it(t,u.hash,m.hash,u.mode,l);e.worktreeBlobs.set(n,{hash:y,mode:u.mode})}else{e.entries.push(_(n,i.mode,m.hash,2)),e.entries.push(K(n,u,3));let y=await it(t,m.hash,u.hash,i.mode,l);e.worktreeBlobs.set(n,{hash:y,mode:i.mode})}}async function rr(t,e,n,r,s,i,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(se(e.mode)||se(n.mode)||se(r.mode))return{hash:n.hash,conflict:!0};let a=await U(t,e.hash),c=await U(t,n.hash),f=await U(t,r.hash);if(ne(c)||ne(f)||ne(a))return{hash:n.hash,conflict:!0};let l=q(a),u=q(c),d=q(f),h=s?.conflictStyle,m=Fe(u,l,d,{conflictStyle:h});if(!m.conflict)return{hash:await $t(t,m.result),conflict:!1};let y=s?.a??"HEAD",p=s?.b??"theirs",b=i?.oursPath?`${y}:${i.oursPath}`:y,R=i?.theirsPath?`${p}:${i.theirsPath}`:p,v=xe(c,a,f,{a:b,b:R,markerSize:o??7,conflictStyle:h});return{hash:await W(t,"blob",ye.encode(v)),conflict:!0}}async function it(t,e,n,r,s){let i=await U(t,e),o=await U(t,n),a=xe(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return W(t,"blob",ye.encode(a))}function K(t,e,n=0){return _(t,e.mode,e.hash,n)}function _(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:fe()}}async function Ys(t,e,n,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,y=0){o.push({sortKey:h,subOrder:y,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(H(h,m.merged.result.hash,m.merged.result.mode));continue}await qs(t,m,n,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(H(h,m.hash,m.mode));l.sort((h,m)=>Be(h.path,m.path));let d=await Rt(t,l);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function qs(t,e,n,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=n?.a??"HEAD",y=n?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(H(a,u,c.mode,1)),r.push(H(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=n?.b??"theirs",y=n?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(H(a,u,c.mode,1)),r.push(H(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(H(a,d,f.mode));return}i(a,`Auto-merging ${a}`,0);let m=await U(t,d),y=await U(t,h);if(ne(m)||ne(y)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(H(a,d,f.mode,2)),r.push(H(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let p=q(""),b=q(m),R=q(y),v=Fe(b,p,R,{conflictStyle:n?.conflictStyle});if(!v.conflict){let w=await $t(t,v.result);r.push(H(a,w,f.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(H(a,d,f.mode,2)),r.push(H(a,h,l.mode,3));let C=xe(m,"",y,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),O=await W(t,"blob",ye.encode(C));o.set(a,{hash:O,mode:f.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(H(a,h,l.mode));return}if(h===u){r.push(H(a,d,f.mode));return}if(d===h){r.push(H(a,d,f.mode));return}if(i(a,`Auto-merging ${a}`,0),se(c.mode)||se(f.mode)||se(l.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(H(a,u,c.mode,1)),r.push(H(a,d,f.mode,2)),r.push(H(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let m=await U(t,u),y=await U(t,d),p=await U(t,h);if(ne(y)||ne(p)||ne(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(H(a,u,c.mode,1)),r.push(H(a,d,f.mode,2)),r.push(H(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let b=q(m),R=q(y),v=q(p),C=Fe(R,b,v,{conflictStyle:n?.conflictStyle});if(C.conflict){let O=e.pathnames[1],w=e.pathnames[2],E=O!==a||w!==a,T={path:a,reason:"content"};E&&(O!==a&&(T.oursOrigPath=O),w!==a&&(T.theirsOrigPath=w)),s.push(T),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(H(a,u,c.mode,1)),r.push(H(a,d,f.mode,2)),r.push(H(a,h,l.mode,3));let I=E?`${n?.a??"HEAD"}:${O}`:n?.a??"HEAD",P=E?`${n?.b??"theirs"}:${w}`:n?.b??"theirs",S=xe(y,m,p,{a:I,b:P,conflictStyle:n?.conflictStyle}),$=await W(t,"blob",ye.encode(S));o.set(a,{hash:$,mode:f.mode})}else{let O=await $t(t,C.result);r.push(H(a,O,f.mode))}return}}var Xs=200;async function sr(t,e,n,r,s){let i=await Promise.all(r.map(async l=>({hash:l,timestamp:(await A(t,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 A(t,a)).tree;for(let l=1;l<o.length;l++){let u=o[l],d=(await A(t,u)).tree,h=null;if(s>=Xs)h=f;else{let p=await Ne(t,c,u);p.length===0?h=null:p.length===1?h=(await A(t,p[0])).tree:h=await sr(t,c,u,p,s+1)}let m=await je(t,h,f,d);f=await Js(t,m,s);let y=Xe({type:"commit",tree:f,parents:[c,u],author:qn,committer:qn,message:"merged common ancestors"});c=await W(t,"commit",y)}return f}async function Js(t,e,n){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+n*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 y=Te.decode((await z(t,h.hash)).content),p=Te.decode((await z(t,m.hash)).content),b=d?Te.decode((await z(t,d.hash)).content):"",R=8+n*2,v=o.a??"Temporary merge branch 1",C=o.b??"Temporary merge branch 2",O=xe(y,b,p,{a:`${v}:${l}`,o:o.o,b:`${C}:${u}`,markerSize:R}),w=await W(t,"blob",ye.encode(O));r.push({path:l,mode:h.mode,hash:w,stage:0,stat:fe()}),r.push({path:u,mode:m.mode,hash:w,stage:0,stat:fe()});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=Te.decode((await z(t,c.hash)).content),u=Te.decode((await z(t,f.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?Te.decode((await z(t,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,y=o.a??"Temporary merge branch 1",p=o.b??"Temporary merge branch 2",b=m?`${y}:${a.oursOrigPath??a.path}`:y,R=m?`${p}:${a.theirsOrigPath??a.path}`:p,v=xe(l,h,u,{a:b,o:o.o,b:R,markerSize:o.markerSize}),C=await W(t,"blob",ye.encode(v));r.push({path:a.path,mode:c.mode,hash:C,stage:0,stat:fe()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>Be(a.path,c.path)),Rt(t,r)}async function $t(t,e){let n=e.map(Ct);if(n.length===0)return W(t,"blob",ye.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?n.join(`
18
22
  `):`${n.join(`
19
23
  `)}
20
- `;return _(t,"blob",fe.encode(i))}function B(t,e,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:s,hash:e,stage:r,stat:re()}}function kt(t,e){let n=t.get(e);return n||(n={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},t.set(e,n)),n}async function*ds(t,e,n){let r=e?[e]:[];for await(let s of we(t,n,{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 ms(t,e,n){let r=await U(t,n),s=null;return e&&(s=(await U(t,e)).tree),Ce(t,s,r.tree)}async function ps(t,e,n){return Ot(t,e,n)}async function gs(t,e){return De(t,e)}async function bs(t){return gt(t,"refs/heads")}async function ys(t){return gt(t,"refs/tags")}async function ws(t,e){return U(t,e)}async function Is(t,e){return te(t,e)}async function xs(t,e){return H(t,e)}async function Os(t,e){return ue(t,e)}async function Es(t,e,n){return Ce(t,e,n)}async function Ps(t,e,n){return $e(t,e,n)}async function ks(t,e,n,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await Ln(t,e,n,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function Rs(t,e,n,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await xe(t,e,n,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}async function Ss(t,e){let n=Be({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message}),r=await _(t,"commit",n);if(e.branch){let s=`refs/heads/${e.branch}`;await t.refStore.writeRef(s,{type:"direct",hash:r}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:s})}return r}async function Ts(t,e){let n=[...e].sort((i,o)=>i.name.localeCompare(o.name)),r=await Promise.all(n.map(async i=>{let o=i.mode;return o||(o=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:o,name:i.name,hash:i.hash}})),s=He({type:"tree",entries:r});return _(t,"tree",s)}async function Cs(t,e){return _(t,"blob",new TextEncoder().encode(e))}async function js(t,e,n){let r=await U(t,e),i=(await ue(t,r.tree)).find(o=>o.path===n);return i?H(t,i.hash):null}var Un=/^[0-9a-f]{40}$/;async function As(t,e,n,r="/"){let s=await De(t,e);if(!s)if(Un.test(e)&&await t.objectStore.exists(e))s=e;else throw new Error(`ref or commit '${e}' not found`);let i=await U(t,s),o=await ue(t,i.tree),a=new Set,c=0;for(let f of o){if(!Je(f.path))throw new Error(`refusing to check out unsafe path '${f.path}'`);let u=D(r,f.path);if(!Ze(r,u))throw new Error(`refusing to check out path outside target directory: '${f.path}'`);let h=Xe(u);if(h!==r&&!a.has(h)&&(await n.mkdir(h,{recursive:!0}),a.add(h)),Q(f.mode)){let d=await H(t,f.hash);if(!Qe(d))throw new Error(`refusing to create symlink with unsafe target '${d}'`);n.symlink?await n.symlink(d,u):await n.writeFile(u,d)}else{let d=await te(t,f.hash);await n.writeFile(u,d)}c++}return{commitHash:s,treeHash:i.tree,filesWritten:c}}async function $s(t,e,n){let r=n?.workTree??"/",s=n?.gitDir??D(r,".git"),i=n?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await De(t,i);if(!o)if(Un.test(i)&&await t.objectStore.exists(i))o=i;else throw new Error(`ref or commit '${i}' not found`);let a=await U(t,o),c=await ue(t,a.tree),f={...t,fs:e,gitDir:s,workTree:r},u=new Set,h=0;for(let l of c){if(!Je(l.path))throw new Error(`refusing to check out unsafe path '${l.path}'`);let m=D(r,l.path);if(!Ze(r,m))throw new Error(`refusing to check out path outside worktree: '${l.path}'`);let g=Xe(m);if(g!==r&&!u.has(g)&&(await e.mkdir(g,{recursive:!0}),u.add(g)),Q(l.mode)){let p=await H(t,l.hash);if(!Qe(p))throw new Error(`refusing to create symlink with unsafe target '${p}'`);e.symlink?await e.symlink(p,m):await e.writeFile(m,p)}else{let p=await te(t,l.hash);await e.writeFile(m,p)}h++}let d=$t(c.map(l=>({path:l.path,mode:parseInt(l.mode,8),hash:l.hash,stage:0,stat:re()})));return await tt(f,d),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:h}}async function Ls(t,e,n){return On(t,e,n)}async function Ms(t,e,n,r){return xn(t,e,n,r)}async function*vs(t,e,n){for await(let r of we(t,e,n))yield{hash:r.hash,message:r.commit.message,tree:r.commit.tree,parents:r.commit.parents,author:r.commit.author,committer:r.commit.committer}}var St=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,n){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)}},Tt=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,n){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,n,r){throw new Error("cannot update ref: ref store is read-only")}};function Us(t){return{objectStore:new St(t.objectStore),refStore:new Tt(t.refStore),hooks:t.hooks}}export{pt as FileSystemRefStore,ut as PackedObjectStore,Ms as blame,As as checkoutTo,Ls as countAheadBehind,Ss as createCommit,$s as createWorktree,Es as diffTrees,Ps as findMergeBases,Os as flattenTree,ms as getChangedFiles,ds as getNewCommits,ps as isAncestor,bs as listBranches,ys as listTags,ks as mergeTrees,Rs as mergeTreesFromTreeHashes,Is as readBlob,xs as readBlobText,ws as readCommit,js as readFileAtCommit,Us as readonlyRepo,gs as resolveRef,vs as walkCommitHistory,Cs as writeBlob,Ts as writeTree};
24
+ `;return W(t,"blob",ye.encode(i))}function H(t,e,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:s,hash:e,stage:r,stat:fe()}}function At(t,e){let n=t.get(e);return n||(n={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},t.set(e,n)),n}var Zs=new TextEncoder,ir=new TextDecoder,ve=16877,cr=33188,Qs=33261,fr=40960;function Y(t){let e=[];for(let n of t.split("/"))n==="."||n===""||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}function or(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function ar(t){switch(t){case G.EXECUTABLE:return Qs;case G.SYMLINK:return fr;case G.DIRECTORY:return ve;default:return cr}}var ot=class{constructor(e,n,r="/"){this.objectStore=e;this.rootTreeHash=n;this.rootPath=r;let s=Y(r);this.overlay.set(s,{type:"directory",mode:ve,mtime:this.epoch})}treeCache=new Map;overlay=new Map;removals=new Set;epoch=new Date(0);toRelative(e){let n=Y(e),r=Y(this.rootPath);if(n===r)return"";let s=r==="/"?"/":`${r}/`;return n.startsWith(s)?n.slice(s.length):null}async loadTreeDir(e){let n=this.treeCache.get(e);if(n)return n;if(e===""){let o=await this.objectStore.read(this.rootTreeHash);if(o.type!=="tree")return null;let a=He(o.content);return this.treeCache.set("",a.entries),a.entries}let r=e.split("/"),s=await this.loadTreeDir("");if(!s)return null;let i="";for(let o of r){let a=s.find(u=>u.name===o);if(!a||a.mode!==G.DIRECTORY)return null;i=i?`${i}/${o}`:o;let c=this.treeCache.get(i);if(c){s=c;continue}let f=await this.objectStore.read(a.hash);if(f.type!=="tree")return null;let l=He(f.content);this.treeCache.set(i,l.entries),s=l.entries}return s}async lookupTreeEntry(e){if(e==="")return null;let n=e.lastIndexOf("/"),r=n===-1?"":e.slice(0,n),s=n===-1?e:e.slice(n+1),i=await this.loadTreeDir(r);if(!i)return null;let o=i.find(a=>a.name===s);return o?{entry:o,dirEntries:i}:null}async isTreeDirectory(e){return e===""?!0:(await this.lookupTreeEntry(e))?.entry.mode===G.DIRECTORY}ensureOverlayParents(e){let n=or(e);n===Y(this.rootPath)||n==="/"||this.overlay.has(n)||(this.ensureOverlayParents(n),this.overlay.set(n,{type:"directory",mode:ve,mtime:new Date}))}async readFile(e){return ir.decode(await this.readFileBuffer(e))}async readFileBuffer(e){let n=Y(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`ENOENT: no such file or directory, open '${e}'`);let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(i.entry.mode===G.DIRECTORY)throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let o=await this.objectStore.read(i.entry.hash);if(o.type!=="blob")throw new Error(`ENOENT: no such file or directory, open '${e}'`);return o.content}async writeFile(e,n){let r=Y(e);this.removals.delete(r),this.ensureOverlayParents(r),this.overlay.set(r,{type:"file",content:typeof n=="string"?Zs.encode(n):new Uint8Array(n),mode:cr,mtime:new Date})}async exists(e){let n=Y(e);if(this.removals.has(n))return!1;if(this.overlay.has(n))return!0;let r=this.toRelative(n);return r===null?!1:r===""||await this.isTreeDirectory(r)?!0:await this.lookupTreeEntry(r)!==null}async stat(e){let n=Y(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:r.type==="file"?r.content.byteLength:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:ve,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let{entry:o}=i,a=o.mode===G.DIRECTORY,c=o.mode===G.SYMLINK,f=0;return a||(f=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:!1,mode:ar(o.mode),size:f,mtime:this.epoch}}async lstat(e){let n=Y(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:r.type==="symlink",mode:r.mode,size:r.type==="file"?r.content.byteLength:r.type==="symlink"?r.target.length:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:ve,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let{entry:o}=i,a=o.mode===G.DIRECTORY,c=o.mode===G.SYMLINK,f=0;return a||(f=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:c,mode:ar(o.mode),size:f,mtime:this.epoch}}async mkdir(e,n){let r=Y(e);if(this.overlay.has(r)){if(this.overlay.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.toRelative(r);if(s!==null&&!this.removals.has(r)&&(s===""||await this.isTreeDirectory(s))){if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let i=or(r);if(!(this.overlay.has(i)||await this.exists(i)))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.removals.delete(r),this.overlay.set(r,{type:"directory",mode:ve,mtime:new Date})}async readdir(e){let n=Y(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,s=this.toRelative(n);if(s!==null){let o=await this.loadTreeDir(s);if(o)for(let a of o){let c=n==="/"?`/${a.name}`:`${n}/${a.name}`;this.removals.has(c)||r.add(a.name)}}let i=n==="/"?"/":`${n}/`;for(let o of this.overlay.keys())if(o!==n&&o.startsWith(i)){let c=o.slice(i.length).split("/")[0];c&&!this.removals.has(n==="/"?`/${c}`:`${n}/${c}`)&&r.add(c)}if(r.size===0){if(this.overlay.get(n)?.type==="directory")return[];if(s!==null&&(s===""||await this.isTreeDirectory(s)))return[];throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}return[...r].sort()}async rm(e,n){let r=Y(e);if(!await this.exists(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}let i=r==="/"?"/":`${r}/`;if(n?.recursive)for(let o of[...this.overlay.keys()])o.startsWith(i)&&(this.overlay.delete(o),this.removals.add(o));if(this.overlay.delete(r),this.removals.add(r),n?.recursive){let o=this.toRelative(r);o!==null&&await this.markTreeChildrenRemoved(o,r)}}async markTreeChildrenRemoved(e,n){let r=await this.loadTreeDir(e);if(r)for(let s of r){let i=n==="/"?`/${s.name}`:`${n}/${s.name}`;if(this.removals.add(i),s.mode===G.DIRECTORY){let o=e?`${e}/${s.name}`:s.name;await this.markTreeChildrenRemoved(o,i)}}}async readlink(e){let n=Y(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let i=await this.lookupTreeEntry(s);if(!i||i.entry.mode!==G.SYMLINK)throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let o=await this.objectStore.read(i.entry.hash);return ir.decode(o.content)}async symlink(e,n){let r=Y(n);if(await this.exists(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureOverlayParents(r),this.removals.delete(r),this.overlay.set(r,{type:"symlink",target:e,mode:fr,mtime:new Date})}};async function*ei(t,e,n){let r=e?[e]:[];for await(let s of we(t,n,{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 ti(t,e,n){let r=await A(t,n),s=null;return e&&(s=(await A(t,e)).tree),oe(t,s,r.tree)}async function ni(t,e,n){return jt(t,e,n)}async function ri(t,e){return re(t,e)}async function si(t){return Et(t,"refs/heads")}async function ii(t){return Et(t,"refs/tags")}async function oi(t,e){return A(t,e)}async function ai(t,e){return ue(t,e)}async function ci(t,e){return U(t,e)}async function fi(t,e){return ie(t,e)}async function li(t,e,n){return oe(t,e,n)}function ui(t){return t==="insert"?"+":t==="delete"?"-":" "}function hi(t){return{oldStart:t.oldStart,oldCount:t.oldCount,newStart:t.newStart,newCount:t.newCount,lines:t.lines.map(e=>ui(e.type)+e.content)}}function lr(t,e,n){let r=te(t),s=te(e),i=Pe(r,s);return Hn(i,n).map(hi)}async function di(t,e,n,r){let s=await Ge(t,e),i=await Ge(t,n),o=await A(t,s),a=await A(t,i),c=await oe(t,o.tree,a.tree),f=r?.renames!==!1,l=r?.contextLines,u=r?.paths,d=[];if(f){let m=await be(t,c);c=m.remaining,d=m.renames}let h=[];for(let m of c){if(u&&!u.some(R=>m.path.startsWith(R)))continue;let y=m.oldHash?await U(t,m.oldHash):"",p=m.newHash?await U(t,m.newHash):"",b=lr(y,p,l);h.push({path:m.path,status:m.status,hunks:b})}for(let m of d){if(u&&!u.some(R=>m.newPath.startsWith(R)||m.oldPath.startsWith(R)))continue;let y=await U(t,m.oldHash),p=await U(t,m.newHash),b=lr(y,p,l);h.push({path:m.newPath,status:"renamed",oldPath:m.oldPath,similarity:m.similarity,hunks:b})}return h.sort((m,y)=>m.path.localeCompare(y.path)),h}async function mi(t,e,n){return Ne(t,e,n)}async function pi(t,e,n,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await nr(t,e,n,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function yi(t,e,n,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await je(t,e,n,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}async function gi(t,e){let n=Xe({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message}),r=await W(t,"commit",n);if(e.branch){let s=`refs/heads/${e.branch}`;await t.refStore.writeRef(s,{type:"direct",hash:r}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:s})}return r}async function bi(t,e){let n=[...e].sort((i,o)=>i.name.localeCompare(o.name)),r=await Promise.all(n.map(async i=>{let o=i.mode;return o||(o=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:o,name:i.name,hash:i.hash}})),s=Ze({type:"tree",entries:r});return W(t,"tree",s)}async function wi(t,e){return W(t,"blob",new TextEncoder().encode(e))}async function xi(t,e,n){let r=await A(t,e),i=(await ie(t,r.tree)).find(o=>o.path===n);return i?U(t,i.hash):null}async function Ge(t,e){let n=await Pn(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function ur(t,e,n,r){let s=new Set,i=0;for(let o of e){if(!Gt(o.path))throw new Error(`refusing to check out unsafe path '${o.path}'`);let a=B(r,o.path);if(!_t(r,a))throw new Error(`refusing to check out path outside target directory: '${o.path}'`);let c=Bt(a);if(c!==r&&!s.has(c)&&(await n.mkdir(c,{recursive:!0}),s.add(c)),se(o.mode)){let f=await U(t,o.hash);if(!Wt(f))throw new Error(`refusing to create symlink with unsafe target '${f}'`);n.symlink?await n.symlink(f,a):await n.writeFile(a,f)}else{let f=await ue(t,o.hash);await n.writeFile(a,f)}i++}return i}function hr(t){return Vt(t.map(e=>({path:e.path,mode:parseInt(e.mode,8),hash:e.hash,stage:0,stat:fe()})))}async function Ii(t,e,n,r="/"){let s=await Ge(t,e),i=await A(t,s),o=await ie(t,i.tree),a=await ur(t,o,n,r);return{commitHash:s,treeHash:i.tree,filesWritten:a}}async function Ei(t,e,n){let r=n?.workTree??"/",s=n?.gitDir??B(r,".git"),i=n?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await Ge(t,i),a=await A(t,o),c=await ie(t,a.tree),f={...t,fs:e,gitDir:s,workTree:r},l=await ur(t,c,e,r);return await We(f,hr(c)),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:l}}async function Oi(t,e,n){return _n(t,e,n)}async function Ri(t,e,n,r){return Gn(t,e,n,r)}async function*Pi(t,e,n){if(n?.paths&&n.paths.length>0){yield*ki(t,e,n.paths,n);return}for await(let r of we(t,e,n))yield{hash:r.hash,message:r.commit.message,tree:r.commit.tree,parents:r.commit.parents,author:r.commit.author,committer:r.commit.committer}}function Lt(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("/")?n:n+"/"))}async function*ki(t,e,n,r){let s=new Set;if(r?.exclude)for await(let f of we(t,r.exclude))s.add(f.hash);let i=new Set(s),o=new Se,a=async f=>{if(!i.has(f))try{let l=await A(t,f);o.push({hash:f,commit:l})}catch{}},c=Array.isArray(e)?e:[e];for(let f of c)await a(f);for(;o.size>0;){let f=o.pop();if(i.has(f.hash))continue;i.add(f.hash);let{commit:l}=f,u=r?.firstParent?l.parents.slice(0,1):l.parents,d=()=>({hash:f.hash,message:l.message,tree:l.tree,parents:l.parents,author:l.author,committer:l.committer});if(u.length===0){(await oe(t,null,l.tree)).some(y=>Lt(y.path,n))&&(yield d());continue}if(u.length===1){let m=u[0];try{let y=await A(t,m);(await oe(t,y.tree,l.tree)).some(b=>Lt(b.path,n))&&(yield d())}catch{yield d()}await a(m);continue}let h=[];for(let m of u)try{let y=await A(t,m);(await oe(t,y.tree,l.tree)).some(b=>Lt(b.path,n))||h.push(m)}catch{}if(h.length>0)await a(h[0]);else{yield d();for(let m of u)await a(m)}}}var Mt=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,n){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")}ingestPackStream(e){throw new Error("cannot ingest pack: object store is read-only")}findByPrefix(e){return this.inner.findByPrefix(e)}},Dt=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,n){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,n,r){throw new Error("cannot update ref: ref store is read-only")}};function Si(t){let e=0;for(let n=0;n<t.length;n++)t[n]==="/"&&e++;return e}function Ti(t,e){let n=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"\0").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]").replace(/\0/g,".*");return new RegExp(`^${n}$`).test(e)}async function ji(t,e,n,r){let s=[];for(let m of n)if(m instanceof RegExp)s.push(m);else{let y=Vn(m,{fixed:r?.fixed,ignoreCase:r?.ignoreCase,wordRegexp:r?.wordRegexp});if(!y)throw new Error(`Invalid pattern: ${m}`);s.push(y)}let i=await A(t,e),a=(await ie(t,i.tree)).filter(m=>!m.mode.startsWith("120")).sort((m,y)=>m.path<y.path?-1:m.path>y.path?1:0),c=r?.allMatch??!1,f=r?.invert??!1,l=r?.maxCount,u=r?.maxDepth,d=r?.paths,h=[];for(let m of a){if(u!==void 0&&Si(m.path)>u||d&&!d.some(R=>Ti(R,m.path)))continue;let y=await U(t,m.hash),p=zn(y,s,c,f);if(p.binary){h.push({path:m.path,matches:[],binary:!0});continue}if(p.matches.length===0)continue;let b=l!==void 0?p.matches.slice(0,l):p.matches;h.push({path:m.path,matches:b,binary:!1})}return h}function vi(t){return{objectStore:new Mt(t.objectStore),refStore:new Dt(t.refStore),hooks:t.hooks}}var Ut=class{constructor(e){this.inner=e}overlay=new Map;async read(e){let n=this.overlay.get(e);return n?{type:n.type,content:new Uint8Array(n.content)}:this.inner.read(e)}async write(e,n){let r=await ce(wt(e,n));return this.overlay.has(r)||await this.inner.exists(r).catch(()=>!1)||this.overlay.set(r,{type:e,content:new Uint8Array(n)}),r}async exists(e){return this.overlay.has(e)?!0:this.inner.exists(e)}async ingestPack(e){if(e.byteLength<32||new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8)===0)return 0;let s=this.overlay,i=this.inner,o=await Ye(e,async a=>{let c=s.get(a);if(c)return{type:c.type,content:new Uint8Array(c.content)};try{return await i.read(a)}catch{return null}});for(let a of o)s.has(a.hash)||s.set(a.hash,{type:a.type,content:a.content});return o.length}async ingestPackStream(e){let n=this.overlay,r=0;for await(let s of e)n.has(s.hash)||n.set(s.hash,{type:s.type,content:s.content}),r++;return r}async findByPrefix(e){let n=await this.inner.findByPrefix(e),r=[];for(let i of this.overlay.keys())i.startsWith(e)&&r.push(i);return[...new Set([...n,...r])]}},Ht=class{constructor(e){this.inner=e}overlay=new Map;deleted=new Set;async readRef(e){if(this.deleted.has(e))return null;let n=this.overlay.get(e);return n||this.inner.readRef(e)}async writeRef(e,n){this.deleted.delete(e),this.overlay.set(e,Je(n))}async deleteRef(e){this.overlay.delete(e),this.deleted.add(e)}async listRefs(e){let n=await this.inner.listRefs(e),r=new Map;for(let s of n)this.deleted.has(s.name)||r.set(s.name,s);for(let[s,i]of this.overlay)if(!(e&&!s.startsWith(e))){if(i.type==="direct")r.set(s,{name:s,hash:i.hash});else if(i.type==="symbolic"){let o=await this.resolveSymbolic(i.target);o&&r.set(s,{name:s,hash:o})}}return[...r.values()]}async compareAndSwapRef(e,n,r){let s=await this.readRef(e),i=null;if(s&&(s.type==="direct"?i=s.hash:s.type==="symbolic"&&(i=await this.resolveSymbolic(s.target))),n===null){if(s!==null)return!1}else if(i!==n)return!1;return r===null?(this.overlay.delete(e),this.deleted.add(e)):(this.deleted.delete(e),this.overlay.set(e,r)),!0}async resolveSymbolic(e,n=0){if(n>10)return null;let r=await this.readRef(e);return r?r.type==="direct"?r.hash:r.type==="symbolic"?this.resolveSymbolic(r.target,n+1):null:null}};function dr(t){return{objectStore:new Ut(t.objectStore),refStore:new Ht(t.refStore),hooks:t.hooks}}async function Ci(t,e){let n=dr(t),r=e?.workTree??"/",s=e?.gitDir??B(r,".git"),i=e?.ref??"HEAD",o=await Ge(n,i),a=await A(n,o),c=new ot(n.objectStore,a.tree,r),f="refs/heads/main";await n.refStore.writeRef("HEAD",{type:"symbolic",target:f}),await n.refStore.writeRef(f,{type:"direct",hash:o});let l={...n,fs:c,gitDir:s,workTree:r},u=await ie(n,a.tree);return await We(l,hr(u)),{ctx:l,commitHash:o,treeHash:a.tree,filesWritten:0}}export{It as FileSystemRefStore,bt as PackedObjectStore,Ri as blame,Oi as countAheadBehind,gi as createCommit,Ci as createSandboxWorktree,Ei as createWorktree,di as diffCommits,li as diffTrees,Ii as extractTree,mi as findMergeBases,fi as flattenTree,ti as getChangedFiles,ei as getNewCommits,ji as grep,ni as isAncestor,si as listBranches,ii as listTags,pi as mergeTrees,yi as mergeTreesFromTreeHashes,dr as overlayRepo,ai as readBlob,ci as readBlobText,oi as readCommit,xi as readFileAtCommit,vi as readonlyRepo,ri as resolveRef,Pi as walkCommitHistory,wi as writeBlob,bi as writeTree};