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