just-git 1.5.8 → 1.5.9

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