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