just-git 1.3.2 → 1.3.3

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/dist/index.js CHANGED
@@ -776,7 +776,7 @@ ${m}`,exitCode:0}}ie();ce();$r();ge();is();function $d(e,t){e.command("tag",{des
776
776
  `)}if(n.list)return Pd(s,n.name||void 0);if(n.name){if(!vc(n.name))return I(`'${n.name}' is not a valid tag name`);let i=n.commit,a;if(i){let d=await wt(s,i,`Failed to resolve '${i}' as a valid ref.`);if(M(d))return d;a=d}else if(a=await Z(s),!a)return I("Failed to resolve 'HEAD' as a valid ref.");let c=`refs/tags/${n.name}`;if(await B(s,c)&&!n.force)return I(`tag '${n.name}' already exists`);if(n.annotate||n.message){if(!n.message)return I("no tag message specified (use -m)");let d=await nt(s,r.env);if(M(d))return d;let m=Mt(n.message),u=$c({type:"tag",object:a,objectType:"commit",name:n.name,tagger:d,message:m}),h=await Ae(s,"tag",u);await X(s,c,h)}else await X(s,c,a);return{stdout:"",stderr:"",exitCode:0}}return Pd(s)}})}async function Pd(e,t){let n=await pe(e,"refs/tags");if(n.length===0)return{stdout:"",stderr:"",exitCode:0};let r=n.map(o=>o.name.replace("refs/tags/",""));return t&&(r=r.filter(o=>on(t,o,0)===0)),r.length===0?{stdout:"",stderr:"",exitCode:0}:{stdout:`${r.join(`
777
777
  `)}
778
778
  `,stderr:"",exitCode:0}}var Od=new Set(["am","annotate","apply","archive","bugreport","bundle","cat-file","check-ignore","check-mailmap","check-ref-format","checkout-index","cherry","commit-tree","count-objects","credential","daemon","diff-files","diff-index","diff-tree","difftool","fast-export","fast-import","filter-branch","for-each-ref","format-patch","fsck","hash-object","instaweb","interpret-trailers","log--hierarchical","ls-remote","ls-tree","maintenance","merge-base","merge-tree","mergetool","multi-pack-index","name-rev","notes","pack-objects","pack-refs","patch-id","prune","range-diff","read-tree","receive-pack","replace","request-pull","rerere","rev-list","send-email","send-pack","shortlog","show-branch","show-ref","sparse-checkout","stash--helper","stripspace","submodule","symbolic-ref","unpack-objects","update-index","update-ref","upload-pack","var","verify-commit","verify-pack","verify-tag","whatchanged","worktree","write-tree"]),Iw={init:(e,t)=>Gl(e,t),clone:(e,t)=>ll(e,t),describe:(e,t)=>ul(e,t),fetch:(e,t)=>Il(e,t),pull:(e,t)=>nd(e,t),push:(e,t)=>rd(e,t),add:(e,t)=>Xc(e,t),blame:(e,t)=>Tf(e,t),commit:(e,t)=>ml(e,t),status:(e,t)=>kd(e,t),log:(e,t)=>Kl(e,t),branch:(e,t)=>Af(e,t),tag:(e,t)=>$d(e,t),checkout:(e,t)=>Mf(e,t),diff:(e,t)=>xl(e,t),reset:(e,t)=>ad(e,t),merge:(e,t)=>Xl(e,t),"cherry-pick":(e,t)=>Yf(e,t),revert:(e,t)=>dd(e,t),rebase:(e,t)=>td(e,t),mv:(e,t)=>Zl(e,t),rm:(e,t)=>ud(e,t),remote:(e,t)=>od(e,t),config:(e,t)=>wl(e,t),show:(e,t)=>md(e,t),stash:(e,t)=>Ed(e,t),"rev-parse":(e,t)=>ld(e,t),"ls-files":(e,t)=>Yl(e,t),clean:(e,t)=>Xf(e,t),switch:(e,t)=>xd(e,t),restore:(e,t)=>fd(e,t),reflog:(e,t)=>sd(e,t),repack:(e,t)=>Tl(e,t),gc:(e,t)=>Hl(e,t),bisect:(e,t)=>wf(e,t),grep:(e,t)=>jl(e,t)};function Id(e){let t=Xo("git",{description:"Git command"});for(let n of Object.values(Iw))n(t,e);return t.command("help",{description:"Display help information",args:[q.string().name("command").describe("Command to get help for").optional()],handler:async n=>{let r=n.command;if(!r)return{stdout:Er(t),stderr:"",exitCode:0};let o=t.children.get(r);return o?{stdout:Er(o),stderr:"",exitCode:0}:{stdout:"",stderr:`git: no help available for '${r}'
779
- `,exitCode:1}}}),t}var Sw="1.3.2";function vw(e,t){if(!e)return t;let n=e.locked?"locked":"defaults",r={"user.name":e.name,"user.email":e.email};return t?{...t,[n]:{...r,...t[n]}}:{[n]:r}}var qo=class{name="git";defaultFs;defaultCwd;blocked;hooks;inner;locks=new WeakMap;async withLock(t,n){let r=this.locks.get(t)??Promise.resolve(),o,s=new Promise(i=>{o=i});this.locks.set(t,s),await r;try{return await n()}finally{o()}}constructor(t){this.defaultFs=t?.fs,this.defaultCwd=t?.cwd??"/",this.hooks=t?.hooks,this.blocked=t?.disabled?.length?new Set(t.disabled):null;let n=t?.network,r=vw(t?.identity,t?.config),o={hooks:t?.hooks,credentialProvider:t?.credentials,identityOverride:t?.identity,fetchFn:typeof n=="object"?n.fetch:void 0,networkPolicy:n,resolveRemote:t?.resolveRemote,...t?.objectStore?{objectStore:t.objectStore}:{},...t?.refStore?{refStore:t.refStore}:{},...t?.gitDir?{gitDir:t.gitDir,workTree:this.defaultCwd}:{},...r?{configOverrides:r}:{}};this.inner=Id(o).toCommand()}exec=async(t,n)=>{let r=n?.fs??this.defaultFs;if(!r)throw new Error("No filesystem: pass `fs` in exec() options or in createGit()");let o=n?.cwd??this.defaultCwd,s=Tw(t),i=new Map;if(n?.env)for(let[a,c]of Object.entries(n.env))i.set(a,c);return this.execute(s,{fs:r,cwd:o,env:i,stdin:n?.stdin??""})};execute=(t,n)=>this.withLock(n.fs,async()=>{let r=t[0]??"";if(r==="--version"||r==="version")return{stdout:`just-git version ${Sw} (virtual git implementation)
779
+ `,exitCode:1}}}),t}var Sw="1.3.3";function vw(e,t){if(!e)return t;let n=e.locked?"locked":"defaults",r={"user.name":e.name,"user.email":e.email};return t?{...t,[n]:{...r,...t[n]}}:{[n]:r}}var qo=class{name="git";defaultFs;defaultCwd;blocked;hooks;inner;locks=new WeakMap;async withLock(t,n){let r=this.locks.get(t)??Promise.resolve(),o,s=new Promise(i=>{o=i});this.locks.set(t,s),await r;try{return await n()}finally{o()}}constructor(t){this.defaultFs=t?.fs,this.defaultCwd=t?.cwd??"/",this.hooks=t?.hooks,this.blocked=t?.disabled?.length?new Set(t.disabled):null;let n=t?.network,r=vw(t?.identity,t?.config),o={hooks:t?.hooks,credentialProvider:t?.credentials,identityOverride:t?.identity,fetchFn:typeof n=="object"?n.fetch:void 0,networkPolicy:n,resolveRemote:t?.resolveRemote,...t?.objectStore?{objectStore:t.objectStore}:{},...t?.refStore?{refStore:t.refStore}:{},...t?.gitDir?{gitDir:t.gitDir,workTree:this.defaultCwd}:{},...r?{configOverrides:r}:{}};this.inner=Id(o).toCommand()}exec=async(t,n)=>{let r=n?.fs??this.defaultFs;if(!r)throw new Error("No filesystem: pass `fs` in exec() options or in createGit()");let o=n?.cwd??this.defaultCwd,s=Tw(t),i=new Map;if(n?.env)for(let[a,c]of Object.entries(n.env))i.set(a,c);return this.execute(s,{fs:r,cwd:o,env:i,stdin:n?.stdin??""})};execute=(t,n)=>this.withLock(n.fs,async()=>{let r=t[0]??"";if(r==="--version"||r==="version")return{stdout:`just-git version ${Sw} (virtual git implementation)
780
780
  `,stderr:"",exitCode:0};if(this.blocked?.has(r))return{stdout:"",stderr:`git: '${r}' is not available in this environment
781
781
  `,exitCode:1};if(r&&Od.has(r))return{stdout:"",stderr:`git: '${r}' is not implemented. Run 'git help' for available commands.
782
782
  `,exitCode:1};if(this.hooks?.beforeCommand){let s=await this.hooks.beforeCommand({command:r,args:t.slice(1),fs:n.fs,cwd:n.cwd,env:n.env});if(ee(s))return{stdout:"",stderr:s.message??"",exitCode:1}}let o=await this.inner.execute(t,n);return this.hooks?.afterCommand&&await this.hooks.afterCommand({command:r,args:t.slice(1),result:o}),o})};function Tw(e){let t=[],n="",r=0;for(;r<e.length;){let o=e[r];if(o==='"'){for(r++;r<e.length&&e[r]!=='"';){if(e[r]==="\\"&&r+1<e.length){let s=e[r+1];if(s==='"'||s==="\\"){n+=s,r+=2;continue}}n+=e[r],r++}r++}else if(o==="'"){for(r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r++}else o===" "||o===" "?(n.length>0&&(t.push(n),n=""),r++):(n+=o,r++)}return n.length>0&&t.push(n),t.length>0&&t[0]==="git"&&t.shift(),t}function Hw(e){return new qo(e)}var Sd=new TextEncoder,Aw=new TextDecoder;function hn(e){let t=[];for(let n of e.split("/"))n==="."||n===""||(n===".."?t.pop():t.push(n));return"/"+t.join("/")}function zo(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}var Ca=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:16877,mtime:new Date}),t)for(let[n,r]of Object.entries(t)){let o=hn(n);this.ensureParents(o),this.data.set(o,{type:"file",content:typeof r=="string"?Sd.encode(r):r,mode:33188,mtime:new Date})}}ensureParents(t){let n=zo(t);n!=="/"&&(this.data.has(n)||(this.ensureParents(n),this.data.set(n,{type:"directory",mode:16877,mtime:new Date})))}resolve(t){let n="",r=new Set;for(let o of hn(t).slice(1).split("/")){n=`${n}/${o}`;let s=0,i=this.data.get(n);for(;i?.type==="symlink"&&s<40;){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`);r.add(n);let a=i.target;n=a.startsWith("/")?hn(a):hn(zo(n)+"/"+a),i=this.data.get(n),s++}if(s>=40)throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`)}return n}resolveParent(t){let n=hn(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let o="",s=new Set;for(let i=0;i<r.length-1;i++){o=`${o}/${r[i]}`;let a=this.data.get(o),c=0;for(;a?.type==="symlink"&&c<40;){if(s.has(o))throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`);s.add(o);let f=a.target;o=f.startsWith("/")?hn(f):hn(zo(o)+"/"+f),a=this.data.get(o),c++}}return`${o}/${r[r.length-1]}`}async readFile(t){return Aw.decode(await this.readFileBuffer(t))}async readFileBuffer(t){let n=this.data.get(this.resolve(t));if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content}async writeFile(t,n){let r=this.resolve(t);this.ensureParents(r),this.data.set(r,{type:"file",content:typeof n=="string"?Sd.encode(n):n,mode:33188,mtime:new Date})}async exists(t){try{return this.data.has(this.resolve(t))}catch{return!1}}async stat(t){let n=this.data.get(this.resolve(t));if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);return{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:n.type==="file"?n.content.byteLength:0,mtime:n.mtime}}async lstat(t){let n=this.resolveParent(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);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}}async mkdir(t,n){let r=hn(t);if(this.data.has(r)){if(this.data.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let o=zo(r);if(o!=="/"&&!this.data.has(o))if(n?.recursive)await this.mkdir(o,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:16877,mtime:new Date})}async readdir(t){let n=this.resolve(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let o=n==="/"?"/":`${n}/`,s=new Set;for(let i of this.data.keys())if(i!==n&&i.startsWith(o)){let c=i.slice(o.length).split("/")[0];c&&s.add(c)}return[...s].sort()}async rm(t,n){let r=hn(t),o=this.data.get(r);if(!o){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(o.type==="directory"){if(!n?.recursive&&(await this.readdir(r)).length>0)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);let s=r==="/"?"/":`${r}/`;for(let i of[...this.data.keys()])i.startsWith(s)&&this.data.delete(i)}this.data.delete(r)}async readlink(t){let n=this.resolveParent(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async symlink(t,n){let r=hn(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParents(r),this.data.set(r,{type:"symlink",target:t,mode:40960,mtime:new Date})}};Gn();export{qo as Git,Ca as MemoryFileSystem,Th as composeGitHooks,Hw as createGit,rr as findRepo,ee as isRejection};
@@ -1,19 +1,19 @@
1
- var Me=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var kt=(()=>{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 ke(t){let e="";for(let n=0;n<20;n++)e+=kt[t[n]];return e}function Je(t,e){let n="";for(let r=0;r<20;r++)n+=kt[t[e+r]];return n}function ye(t){let e=new Uint8Array(20);for(let n=0;n<20;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}var zn=new TextEncoder;function Qe(t){return typeof t=="string"?zn.encode(t):t}function Vn(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(Qe(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=Me(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(Qe(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(Qe(n)),e},async hex(){let n=0;for(let o of t)n+=o.byteLength;let r=new Uint8Array(n),s=0;for(let o of t)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return ke(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 Tt=Vn(),et=Tt;async function De(t){return Tt().update(t).hex()}var Z=Uint8Array,ge=Uint16Array,Kn=Int32Array,St=new Z([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Ct=new Z([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Yn=new Z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),jt=(t,e)=>{let n=new ge(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new Kn(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:vt}=jt(St,2);vt[28]=258;var{b:qn}=jt(Ct,0),rt=new ge(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,rt[t]=((e&65280)>>8|(e&255)<<8)>>1}var Te=(t,e,n)=>{let r=t.length,s=0,i=new ge(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let o=new ge(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;let a;if(n){a=new ge(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let l=s<<4|t[s],f=e-t[s],u=o[t[s]-1]++<<f;for(let d=u|(1<<f)-1;u<=d;++u)a[rt[u]>>c]=l}}else for(a=new ge(r),s=0;s<r;++s)t[s]&&(a[s]=rt[o[t[s]-1]++]>>15-t[s]);return a},Se=new Z(288);for(let t=0;t<144;++t)Se[t]=8;for(let t=144;t<256;++t)Se[t]=9;for(let t=256;t<280;++t)Se[t]=7;for(let t=280;t<288;++t)Se[t]=8;var At=new Z(32);for(let t=0;t<32;++t)At[t]=5;var Xn=Te(Se,9,1),Zn=Te(At,5,1),tt=t=>{let e=t[0];for(let n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},X=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},nt=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},$t=t=>(t+7)/8|0,Jn=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new Z(t.subarray(e,n))),Q=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},Lt=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new Z(0);let o=!n,a=o||e.i!=2,c=e.i;o&&(n=new Z(s*3));let l=R=>{let j=n.length;if(R>j){let v=new Z(Math.max(j*2,R));v.set(n),n=v}},f=e.f||0,u=e.p||0,d=e.b||0,h=e.l,m=e.d,y=e.m,p=e.n,b=s*8;do{if(!h){f=X(t,u,1);let O=X(t,u+1,3);if(u+=3,O)if(O==1)h=Xn,m=Zn,y=9,p=5;else if(O==2){let w=X(t,u,31)+257,x=X(t,u+10,15)+4,S=w+X(t,u+5,31)+1;u+=14;let E=new Z(S),P=new Z(19);for(let g=0;g<x;++g)P[Yn[g]]=X(t,u+g*3,7);u+=x*3;let T=tt(P),$=(1<<T)-1,D=Te(P,T,1);for(let g=0;g<S;){let k=D[X(t,u,$)];u+=k&15;let M=k>>4;if(M<16)E[g++]=M;else{let L=0,C=0;for(M==16?(C=3+X(t,u,3),u+=2,L=E[g-1]):M==17?(C=3+X(t,u,7),u+=3):M==18&&(C=11+X(t,u,127),u+=7);C--;)E[g++]=L}}let oe=E.subarray(0,w),I=E.subarray(w);y=tt(oe),p=tt(I),h=Te(oe,y,1),m=Te(I,p,1)}else Q(1);else{let w=$t(u)+4,x=t[w-4]|t[w-3]<<8,S=w+x;if(S>s){c&&Q(0);break}a&&l(d+x),n.set(t.subarray(w,S),d),e.b=d+=x,e.p=u=S*8,e.f=f;continue}if(u>b){c&&Q(0);break}}a&&l(d+131072);let R=(1<<y)-1,j=(1<<p)-1,v=u;for(;;v=u){let O=h[nt(t,u)&R],w=O>>4;if(u+=O&15,u>b){c&&Q(0);break}if(O||Q(2),w<256)n[d++]=w;else if(w==256){v=u,h=null;break}else{let x=w-254;if(w>264){let $=w-257,D=St[$];x=X(t,u,(1<<D)-1)+vt[$],u+=D}let S=m[nt(t,u)&j],E=S>>4;S||Q(3),u+=S&15;let P=qn[E];if(E>3){let $=Ct[E];P+=nt(t,u)&(1<<$)-1,u+=$}if(u>b){c&&Q(0);break}a&&l(d+131072);let T=d+x;if(d<P){let $=i-P,D=Math.min(P,T);for($+d<0&&Q(3);d<D;++d)n[d]=r[$+d]}for(;d<T;++d)n[d]=n[d-P]}}e.l=h,e.p=v,e.b=d,e.f=f,h&&(f=1,e.m=y,e.d=m,e.n=p)}while(!f);return d!=n.length&&o?Jn(n,0,d):n.subarray(0,d)},Mt=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&Q(0,"invalid zlib data"),t[1]&32&&Q(0,"zlib dictionaries are not supported"),2);function Dt(t){let e=Mt(t);return Lt(t.subarray(e,-4),{i:2})}function st(t){let e=Mt(t),n={i:2},r=Lt(t.subarray(e),n),s=$t(n.p);return{result:r,bytesConsumed:e+s+4}}async function Qn(){let t;if(!(typeof document<"u"))try{t=Me(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let o=t.inflateSync(i,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??st}}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:Dt,inflateWithConsumed:st}}var er=null;function tr(){return er??=Qn()}async function Ht(t,e){let n=await tr(),{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 Ut=1346454347,nr=2,rr=1,sr=2,ir=3,or=4,He=6,ot=7,ar={[rr]:"commit",[sr]:"tree",[ir]:"blob",[or]:"tag"};async function Gt(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==Ut)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Ut.toString(16)})`);let s=n.getUint32(4);if(s!==nr)throw new Error(`Unsupported pack version: ${s}`);if(t.byteLength>=32){let l=Je(t,t.byteLength-20),f=et();f.update(t.subarray(0,t.byteLength-20));let u=await f.hex();if(u!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${u}`)}let i=n.getUint32(8),o=[],a=12;for(let l=0;l<i;l++){let f=await cr(t,a);o.push(f),a=f.nextOffset}return(await lr(o,e)).map((l,f)=>({...l,offset:o[f].headerOffset,nextOffset:o[f].nextOffset}))}async function cr(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=t[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===He){let u=t[e++];for(a=u&127;u&128;)a+=1,u=t[e++],a=(a<<7)+(u&127);a=n-a}else s===ot&&(c=Je(t,e),e+=20);let{result:l,bytesConsumed:f}=await Ht(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:l,baseOffset:a,baseHash:c,nextOffset:e+f}}var Nt=50;async function lr(t,e){let n=new Map;for(let i=0;i<t.length;i++)n.set(t[i].headerOffset,i);let r=new Array(t.length).fill(null);async function s(i,o=0){if(o>Nt)throw new Error(`delta chain depth ${o} exceeds limit of ${Nt}`);let a=r[i];if(a)return a;let c=t[i];if(c.typeNum!==He&&c.typeNum!==ot){let h=ar[c.typeNum];if(!h)throw new Error(`Unknown object type: ${c.typeNum}`);let m={type:h,content:c.inflated,hash:await it(h,c.inflated)};return r[i]=m,m}if(c.typeNum===He){let h=n.get(c.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let m=await s(h,o+1),y=Bt(m.content,c.inflated),p={type:m.type,content:y,hash:await it(m.type,y)};return r[i]=p,p}let l=await fr(t,r,c.baseHash,s),f;if(l!==void 0)f=await s(l,o+1);else if(e){let h=await e(c.baseHash);h&&(f=h)}if(!f)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let u=Bt(f.content,c.inflated),d={type:f.type,content:u,hash:await it(f.type,u)};return r[i]=d,d}for(let i=0;i<t.length;i++)await s(i);return r}async function fr(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!==He&&i.typeNum!==ot&&(await r(s)).hash===n)return s}}function Bt(t,e){let n=0,{value:r,newPos:s}=Ft(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:o}=Ft(e,n);n=o;let a=new Uint8Array(i),c=0;for(;n<e.byteLength;){let l=e[n++];if(l&128){let f=0,u=0;l&1&&(f=e[n++]),l&2&&(f|=e[n++]<<8),l&4&&(f|=e[n++]<<16),l&8&&(f|=e[n++]<<24),l&16&&(u=e[n++]),l&32&&(u|=e[n++]<<8),l&64&&(u|=e[n++]<<16),u===0&&(u=65536),a.set(t.subarray(f,f+u),c),c+=u}else if(l>0)a.set(e.subarray(n,n+l),c),c+=l,n+=l;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return a}function Ft(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 ur=new TextEncoder;async function it(t,e){let n=ur.encode(`${t} ${e.byteLength}\0`),r=et();return r.update(n),r.update(e),r.hex()}function hr(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.split("/"),s=[];for(let o of r)o===""||o==="."||(o===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(o));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function be(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":hr(e)}function _t(t){if(t==="")return".";if(t==="/")return"/";let e=t.length;for(;e>1&&t.charCodeAt(e-1)===47;)e--;let n=t.slice(0,e),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}var dr=new TextEncoder,Ei=new TextDecoder;function Wt(t,e){let n=dr.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function Ce(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function Ue(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var mr=new TextEncoder,pr=new TextDecoder;function zt(t){let e=pr.decode(t),n=e.indexOf(`
1
+ var Me=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var kt=(()=>{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 ke(t){let e="";for(let n=0;n<20;n++)e+=kt[t[n]];return e}function Je(t,e){let n="";for(let r=0;r<20;r++)n+=kt[t[e+r]];return n}function ye(t){let e=new Uint8Array(20);for(let n=0;n<20;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}var zn=new TextEncoder;function Qe(t){return typeof t=="string"?zn.encode(t):t}function Vn(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(Qe(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=Me(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(Qe(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(Qe(n)),e},async hex(){let n=0;for(let o of t)n+=o.byteLength;let r=new Uint8Array(n),s=0;for(let o of t)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return ke(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 Tt=Vn(),et=Tt;async function De(t){return Tt().update(t).hex()}var Z=Uint8Array,ge=Uint16Array,Kn=Int32Array,St=new Z([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Ct=new Z([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Yn=new Z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),vt=(t,e)=>{let n=new ge(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new Kn(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:jt}=vt(St,2);jt[28]=258;var{b:qn}=vt(Ct,0),rt=new ge(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,rt[t]=((e&65280)>>8|(e&255)<<8)>>1}var Te=(t,e,n)=>{let r=t.length,s=0,i=new ge(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let o=new ge(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;let a;if(n){a=new ge(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let l=s<<4|t[s],f=e-t[s],u=o[t[s]-1]++<<f;for(let d=u|(1<<f)-1;u<=d;++u)a[rt[u]>>c]=l}}else for(a=new ge(r),s=0;s<r;++s)t[s]&&(a[s]=rt[o[t[s]-1]++]>>15-t[s]);return a},Se=new Z(288);for(let t=0;t<144;++t)Se[t]=8;for(let t=144;t<256;++t)Se[t]=9;for(let t=256;t<280;++t)Se[t]=7;for(let t=280;t<288;++t)Se[t]=8;var At=new Z(32);for(let t=0;t<32;++t)At[t]=5;var Xn=Te(Se,9,1),Zn=Te(At,5,1),tt=t=>{let e=t[0];for(let n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},X=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},nt=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},$t=t=>(t+7)/8|0,Jn=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new Z(t.subarray(e,n))),Q=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},Lt=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new Z(0);let o=!n,a=o||e.i!=2,c=e.i;o&&(n=new Z(s*3));let l=R=>{let v=n.length;if(R>v){let j=new Z(Math.max(v*2,R));j.set(n),n=j}},f=e.f||0,u=e.p||0,d=e.b||0,h=e.l,m=e.d,y=e.m,p=e.n,b=s*8;do{if(!h){f=X(t,u,1);let O=X(t,u+1,3);if(u+=3,O)if(O==1)h=Xn,m=Zn,y=9,p=5;else if(O==2){let w=X(t,u,31)+257,x=X(t,u+10,15)+4,S=w+X(t,u+5,31)+1;u+=14;let E=new Z(S),P=new Z(19);for(let g=0;g<x;++g)P[Yn[g]]=X(t,u+g*3,7);u+=x*3;let T=tt(P),$=(1<<T)-1,D=Te(P,T,1);for(let g=0;g<S;){let k=D[X(t,u,$)];u+=k&15;let M=k>>4;if(M<16)E[g++]=M;else{let L=0,C=0;for(M==16?(C=3+X(t,u,3),u+=2,L=E[g-1]):M==17?(C=3+X(t,u,7),u+=3):M==18&&(C=11+X(t,u,127),u+=7);C--;)E[g++]=L}}let oe=E.subarray(0,w),I=E.subarray(w);y=tt(oe),p=tt(I),h=Te(oe,y,1),m=Te(I,p,1)}else Q(1);else{let w=$t(u)+4,x=t[w-4]|t[w-3]<<8,S=w+x;if(S>s){c&&Q(0);break}a&&l(d+x),n.set(t.subarray(w,S),d),e.b=d+=x,e.p=u=S*8,e.f=f;continue}if(u>b){c&&Q(0);break}}a&&l(d+131072);let R=(1<<y)-1,v=(1<<p)-1,j=u;for(;;j=u){let O=h[nt(t,u)&R],w=O>>4;if(u+=O&15,u>b){c&&Q(0);break}if(O||Q(2),w<256)n[d++]=w;else if(w==256){j=u,h=null;break}else{let x=w-254;if(w>264){let $=w-257,D=St[$];x=X(t,u,(1<<D)-1)+jt[$],u+=D}let S=m[nt(t,u)&v],E=S>>4;S||Q(3),u+=S&15;let P=qn[E];if(E>3){let $=Ct[E];P+=nt(t,u)&(1<<$)-1,u+=$}if(u>b){c&&Q(0);break}a&&l(d+131072);let T=d+x;if(d<P){let $=i-P,D=Math.min(P,T);for($+d<0&&Q(3);d<D;++d)n[d]=r[$+d]}for(;d<T;++d)n[d]=n[d-P]}}e.l=h,e.p=j,e.b=d,e.f=f,h&&(f=1,e.m=y,e.d=m,e.n=p)}while(!f);return d!=n.length&&o?Jn(n,0,d):n.subarray(0,d)},Mt=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&Q(0,"invalid zlib data"),t[1]&32&&Q(0,"zlib dictionaries are not supported"),2);function Dt(t){let e=Mt(t);return Lt(t.subarray(e,-4),{i:2})}function st(t){let e=Mt(t),n={i:2},r=Lt(t.subarray(e),n),s=$t(n.p);return{result:r,bytesConsumed:e+s+4}}async function Qn(){let t;if(!(typeof document<"u"))try{t=Me(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let o=t.inflateSync(i,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??st}}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:Dt,inflateWithConsumed:st}}var er=null;function tr(){return er??=Qn()}async function Ht(t,e){let n=await tr(),{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 Ut=1346454347,nr=2,rr=1,sr=2,ir=3,or=4,He=6,ot=7,ar={[rr]:"commit",[sr]:"tree",[ir]:"blob",[or]:"tag"};async function Gt(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==Ut)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Ut.toString(16)})`);let s=n.getUint32(4);if(s!==nr)throw new Error(`Unsupported pack version: ${s}`);if(t.byteLength>=32){let l=Je(t,t.byteLength-20),f=et();f.update(t.subarray(0,t.byteLength-20));let u=await f.hex();if(u!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${u}`)}let i=n.getUint32(8),o=[],a=12;for(let l=0;l<i;l++){let f=await cr(t,a);o.push(f),a=f.nextOffset}return(await lr(o,e)).map((l,f)=>({...l,offset:o[f].headerOffset,nextOffset:o[f].nextOffset}))}async function cr(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=t[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===He){let u=t[e++];for(a=u&127;u&128;)a+=1,u=t[e++],a=(a<<7)+(u&127);a=n-a}else s===ot&&(c=Je(t,e),e+=20);let{result:l,bytesConsumed:f}=await Ht(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:l,baseOffset:a,baseHash:c,nextOffset:e+f}}var Nt=50;async function lr(t,e){let n=new Map;for(let i=0;i<t.length;i++)n.set(t[i].headerOffset,i);let r=new Array(t.length).fill(null);async function s(i,o=0){if(o>Nt)throw new Error(`delta chain depth ${o} exceeds limit of ${Nt}`);let a=r[i];if(a)return a;let c=t[i];if(c.typeNum!==He&&c.typeNum!==ot){let h=ar[c.typeNum];if(!h)throw new Error(`Unknown object type: ${c.typeNum}`);let m={type:h,content:c.inflated,hash:await it(h,c.inflated)};return r[i]=m,m}if(c.typeNum===He){let h=n.get(c.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let m=await s(h,o+1),y=Bt(m.content,c.inflated),p={type:m.type,content:y,hash:await it(m.type,y)};return r[i]=p,p}let l=await fr(t,r,c.baseHash,s),f;if(l!==void 0)f=await s(l,o+1);else if(e){let h=await e(c.baseHash);h&&(f=h)}if(!f)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let u=Bt(f.content,c.inflated),d={type:f.type,content:u,hash:await it(f.type,u)};return r[i]=d,d}for(let i=0;i<t.length;i++)await s(i);return r}async function fr(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!==He&&i.typeNum!==ot&&(await r(s)).hash===n)return s}}function Bt(t,e){let n=0,{value:r,newPos:s}=Ft(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:o}=Ft(e,n);n=o;let a=new Uint8Array(i),c=0;for(;n<e.byteLength;){let l=e[n++];if(l&128){let f=0,u=0;l&1&&(f=e[n++]),l&2&&(f|=e[n++]<<8),l&4&&(f|=e[n++]<<16),l&8&&(f|=e[n++]<<24),l&16&&(u=e[n++]),l&32&&(u|=e[n++]<<8),l&64&&(u|=e[n++]<<16),u===0&&(u=65536),a.set(t.subarray(f,f+u),c),c+=u}else if(l>0)a.set(e.subarray(n,n+l),c),c+=l,n+=l;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return a}function Ft(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 ur=new TextEncoder;async function it(t,e){let n=ur.encode(`${t} ${e.byteLength}\0`),r=et();return r.update(n),r.update(e),r.hex()}function hr(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.split("/"),s=[];for(let o of r)o===""||o==="."||(o===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(o));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function be(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":hr(e)}function _t(t){if(t==="")return".";if(t==="/")return"/";let e=t.length;for(;e>1&&t.charCodeAt(e-1)===47;)e--;let n=t.slice(0,e),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}var dr=new TextEncoder,Ei=new TextDecoder;function Wt(t,e){let n=dr.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function Ce(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function Ue(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var mr=new TextEncoder,pr=new TextDecoder;function zt(t){let e=pr.decode(t),n=e.indexOf(`
2
2
 
3
3
  `),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",o=[],a,c;for(let l of r.split(`
4
4
  `)){let f=l.indexOf(" ");if(f===-1)continue;let u=l.slice(0,f),d=l.slice(f+1);switch(u){case"tree":i=d;break;case"parent":o.push(d);break;case"author":a=Ce(d);break;case"committer":c=Ce(d);break}}if(!i)throw new Error("Commit missing tree field");if(!a)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:o,author:a,committer:c,message:s}}function Ne(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${Ue(t.author)}`),e.push(`committer ${Ue(t.committer)}`),e.push(""),e.push(t.message),mr.encode(e.join(`
5
5
  `))}var Ti=new TextEncoder,yr=new TextDecoder;function Vt(t){let e=yr.decode(t),n=e.indexOf(`
6
6
 
7
7
  `),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",o="commit",a="",c;for(let l of r.split(`
8
- `)){let f=l.indexOf(" ");if(f===-1)continue;let u=l.slice(0,f),d=l.slice(f+1);switch(u){case"object":i=d;break;case"type":o=d;break;case"tag":a=d;break;case"tagger":c=Ce(d);break}}if(!i)throw new Error("Tag missing object field");if(!a)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:i,objectType:o,name:a,tagger:c,message:s}}async function _(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function W(t,e){return t.objectStore.read(e)}async function Kt(t,e){return t.objectStore.exists(e)}async function Yt(t,e){return t.objectStore.findByPrefix(e)}function te(t){let e=Math.min(t.length,8e3);for(let n=0;n<e;n++)if(t.charCodeAt(n)===0)return!0;return!1}var gr=new TextDecoder;async function H(t,e){let n=await W(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return gr.decode(n.content)}async function ne(t,e){let n=await W(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function A(t,e){let n=await W(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return zt(n.content)}async function je(t,e){let n=e;for(let r=0;r<100;r++){let s=await W(t,n);if(s.type==="commit")return n;if(s.type==="tag"){n=Vt(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 F={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function qt(t){return typeof t=="string"?{type:"direct",hash:t}:t}var br=10;async function wr(t,e){return t.refStore.readRef(e)}async function re(t,e){let n=e;for(let r=0;r<br;r++){let s=await wr(t,n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function at(t,e="refs"){return t.refStore.listRefs(e)}function Xt(t){return t.length===4&&t.toLowerCase()===".git"}function Zt(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===".."||Xt(n))return!1;return!0}function Jt(t,e){return e===t?!1:t==="/"?e.startsWith("/")&&e.length>1:e.startsWith(t+"/")}function Qt(t){if(t.length===0||t.charCodeAt(0)===47)return!1;let e=t.split("/");for(let n of e)if(n===".."||Xt(n))return!1;return!0}var Ir=1145655875,Er=2;async function Be(t,e){let n=be(t.gitDir,"index"),r=await xr(e);await t.fs.writeFile(n,r)}function en(t){let e=[...t].sort(tn);return{version:Er,entries:e}}function ae(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function xr(t){let e=new TextEncoder,n=[...t.entries].sort(tn),r=[],s=12;for(let d of n){let h=e.encode(d.path);r.push(h);let m=62+h.byteLength+1;s+=Math.ceil(m/8)*8}s+=20;let i=new ArrayBuffer(s),o=new Uint8Array(i),a=new DataView(i),c=0;a.setUint32(c,Ir),c+=4,a.setUint32(c,t.version),c+=4,a.setUint32(c,n.length),c+=4;for(let d=0;d<n.length;d++){let h=n[d],m=r[d],y=c;a.setUint32(c,h.stat.ctimeSeconds),a.setUint32(c+4,h.stat.ctimeNanoseconds),a.setUint32(c+8,h.stat.mtimeSeconds),a.setUint32(c+12,h.stat.mtimeNanoseconds),a.setUint32(c+16,h.stat.dev),a.setUint32(c+20,h.stat.ino),a.setUint32(c+24,h.mode),a.setUint32(c+28,h.stat.uid),a.setUint32(c+32,h.stat.gid),a.setUint32(c+36,h.stat.size),c+=40;let p=ye(h.hash);o.set(p,c),c+=20;let b=Math.min(m.byteLength,4095),R=(h.stage&3)<<12|b;a.setUint16(c,R),c+=2,o.set(m,c),c+=m.byteLength,o[c]=0,c+=1;let j=62+m.byteLength+1,v=Math.ceil(j/8)*8;c=y+v}let l=o.subarray(0,c),f=await De(l),u=ye(f);return o.set(u,c),o}function tn(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}function Or(t){let e=[],n=t.length;for(;n>0;){let i=t.slice(0,n).match(/^(.+?)~(\d*)$/);if(i&&i[1]!==void 0&&i[2]!==void 0){let c=i[2]===""?1:parseInt(i[2],10);e.unshift({type:"tilde",n:c}),n=i[1].length;continue}let o=t.slice(0,n).match(/^(.+?)\^{([^}]*)}$/);if(o&&o[1]!==void 0&&o[2]!==void 0){e.unshift({type:"peel",target:o[2]}),n=o[1].length;continue}let a=t.slice(0,n).match(/^(.+?)\^(\d*)$/);if(a&&a[1]!==void 0&&a[2]!==void 0){let c=a[2]===""?1:parseInt(a[2],10);e.unshift({type:"caret",n:c}),n=a[1].length;continue}break}let r=t.slice(0,n),s=r.match(/^(.+?)@\{(\d+)\}$/);return s&&s[1]!==void 0&&s[2]!==void 0?{base:s[1],reflogIndex:parseInt(s[2],10),suffixes:e}:{base:r,suffixes:e}}var Rr=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];async function Pr(t,e){let n=await Yt(t,e);if(n.length===0)return null;if(n.length>1)throw new ct(e);return n[0]}var ct=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}};async function kr(t,e){if(e==="HEAD"||e==="@")return re(t,"HEAD");if(Rr.includes(e))return re(t,e);if(/^[0-9a-f]{40}$/.test(e))return await Kt(t,e)?e:null;if(/^[0-9a-f]{4,39}$/.test(e)){let i=await Pr(t,e);if(i)return i}if(e.startsWith("refs/")){let i=await re(t,e);if(i)return i}let n=await re(t,`refs/heads/${e}`);if(n)return n;let r=await re(t,`refs/tags/${e}`);if(r)return r;let s=await re(t,`refs/remotes/${e}`);return s||null}async function Tr(t,e,n){if(n===""||n==="commit")try{return await je(t,e)}catch{return null}if(n==="tree"){let s;try{s=await je(t,e)}catch{return null}return(await A(t,s)).tree}return(await W(t,e)).type!==n?null:e}async function Sr(t,e,n){let r=e;n.some(i=>i.type==="tilde"||i.type==="caret")&&(r=await je(t,r));for(let i of n)if(i.type==="peel"){if(!r)return null;r=await Tr(t,r,i.target)}else if(i.type==="tilde")for(let o=0;o<i.n;o++){if(!r)return null;let a=await A(t,r);if(a.parents.length===0||(r=a.parents[0]??null,!r))return null}else{if(i.n===0)continue;if(!r)return null;let o=await A(t,r);if(i.n>o.parents.length||(r=o.parents[i.n-1]??null,!r))return null}return r}async function Fe(t,e){let{base:n,reflogIndex:r,suffixes:s}=Or(e);if(r!==void 0)return null;let i=await kr(t,n);return i?Sr(t,i,s):null}var Gi=new TextEncoder;function se(t){return typeof t=="string"?t==="120000":t===40960}function nn(t){return{stdout:"",stderr:`fatal: ${t}
9
- `,exitCode:128}}var Wi=nn("not a git repository (or any of the parent directories): .git"),zi=nn("this operation must be run in a work tree");function ve(t,e){return t<e?-1:t>e?1:0}var Cr=new TextEncoder,rn=new TextDecoder,jr=new Set(["100644","100755","040000","120000","160000"]);function vr(t){return t.length===4&&t.toLowerCase()===".git"}function Ar(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(vr(t))throw new Error(`invalid tree entry: '${t}'`);if(!jr.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${t}'`)}function Ae(t){let e=[],n=0;for(;n<t.byteLength;){let r=t.indexOf(32,n);if(r===-1)break;let s=rn.decode(t.subarray(n,r)),i=t.indexOf(0,r+1);if(i===-1)break;let o=rn.decode(t.subarray(r+1,i)),a=t.subarray(i+1,i+21),c=ke(a),l=s.padStart(6,"0");Ar(o,l),e.push({mode:l,name:o,hash:c}),n=i+21}return{type:"tree",entries:e}}function Ge(t){let e=[];for(let i of t.entries){let o=i.mode.replace(/^0+/,""),a=Cr.encode(`${o} ${i.name}\0`),c=ye(i.hash);e.push(a),e.push(c)}let n=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}async function lt(t,e){return sn(t,e,"")}async function sn(t,e,n){let r=[],s=new Map;for(let o of e){let a=n?o.path.slice(n.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:$r(o.mode),name:a,hash:o.hash});else{let l=a.slice(0,c),f=s.get(l);f||(f=[],s.set(l,f)),f.push(o)}}for(let[o,a]of s){let c=n?`${n}/${o}`:o,l=await sn(t,a,c);r.push({mode:F.DIRECTORY,name:o,hash:l})}r.sort((o,a)=>{let c=o.mode===F.DIRECTORY?`${o.name}/`:o.name,l=a.mode===F.DIRECTORY?`${a.name}/`:a.name;return c<l?-1:c>l?1:0});let i=Ge({type:"tree",entries:r});return _(t,"tree",i)}async function J(t,e,n=""){let r=await W(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=Ae(r.content),i=[];for(let o of s.entries){let a=n?`${n}/${o.name}`:o.name;if(o.mode===F.DIRECTORY){let c=await J(t,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function ce(t,e){if(!e)return new Map;let n=await J(t,e);return new Map(n.map(r=>[r.path,r]))}async function ie(t,e,n){let r=await ce(t,e),s=await ce(t,n),i=[];for(let[o,a]of r){let c=s.get(o);c?(a.hash!==c.hash||a.mode!==c.mode)&&i.push({path:o,status:"modified",oldHash:a.hash,newHash:c.hash,oldMode:a.mode,newMode:c.mode}):i.push({path:o,status:"deleted",oldHash:a.hash,oldMode:a.mode})}for(let[o,a]of s)r.has(o)||i.push({path:o,status:"added",newHash:a.hash,newMode:a.mode});return i.sort((o,a)=>ve(o.path,a.path))}function $r(t){return t.toString(8).padStart(6,"0")}function Lr(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 on(t,e,n,r){if(Lr(t)){let o=e.some(a=>a.test(t));return{matches:[],binary:o}}let s=t.split(`
8
+ `)){let f=l.indexOf(" ");if(f===-1)continue;let u=l.slice(0,f),d=l.slice(f+1);switch(u){case"object":i=d;break;case"type":o=d;break;case"tag":a=d;break;case"tagger":c=Ce(d);break}}if(!i)throw new Error("Tag missing object field");if(!a)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:i,objectType:o,name:a,tagger:c,message:s}}async function _(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function W(t,e){return t.objectStore.read(e)}async function Kt(t,e){return t.objectStore.exists(e)}async function Yt(t,e){return t.objectStore.findByPrefix(e)}function te(t){let e=Math.min(t.length,8e3);for(let n=0;n<e;n++)if(t.charCodeAt(n)===0)return!0;return!1}var gr=new TextDecoder;async function H(t,e){let n=await W(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return gr.decode(n.content)}async function ne(t,e){let n=await W(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function A(t,e){let n=await W(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return zt(n.content)}async function ve(t,e){let n=e;for(let r=0;r<100;r++){let s=await W(t,n);if(s.type==="commit")return n;if(s.type==="tag"){n=Vt(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 F={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function qt(t){return typeof t=="string"?{type:"direct",hash:t}:t}var br=10;async function wr(t,e){return t.refStore.readRef(e)}async function re(t,e){let n=e;for(let r=0;r<br;r++){let s=await wr(t,n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function at(t,e="refs"){return t.refStore.listRefs(e)}function Xt(t){return t.length===4&&t.toLowerCase()===".git"}function Zt(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===".."||Xt(n))return!1;return!0}function Jt(t,e){return e===t?!1:t==="/"?e.startsWith("/")&&e.length>1:e.startsWith(t+"/")}function Qt(t){if(t.length===0||t.charCodeAt(0)===47)return!1;let e=t.split("/");for(let n of e)if(n===".."||Xt(n))return!1;return!0}var Ir=1145655875,Er=2;async function Be(t,e){let n=be(t.gitDir,"index"),r=await xr(e);await t.fs.writeFile(n,r)}function en(t){let e=[...t].sort(tn);return{version:Er,entries:e}}function ae(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function xr(t){let e=new TextEncoder,n=[...t.entries].sort(tn),r=[],s=12;for(let d of n){let h=e.encode(d.path);r.push(h);let m=62+h.byteLength+1;s+=Math.ceil(m/8)*8}s+=20;let i=new ArrayBuffer(s),o=new Uint8Array(i),a=new DataView(i),c=0;a.setUint32(c,Ir),c+=4,a.setUint32(c,t.version),c+=4,a.setUint32(c,n.length),c+=4;for(let d=0;d<n.length;d++){let h=n[d],m=r[d],y=c;a.setUint32(c,h.stat.ctimeSeconds),a.setUint32(c+4,h.stat.ctimeNanoseconds),a.setUint32(c+8,h.stat.mtimeSeconds),a.setUint32(c+12,h.stat.mtimeNanoseconds),a.setUint32(c+16,h.stat.dev),a.setUint32(c+20,h.stat.ino),a.setUint32(c+24,h.mode),a.setUint32(c+28,h.stat.uid),a.setUint32(c+32,h.stat.gid),a.setUint32(c+36,h.stat.size),c+=40;let p=ye(h.hash);o.set(p,c),c+=20;let b=Math.min(m.byteLength,4095),R=(h.stage&3)<<12|b;a.setUint16(c,R),c+=2,o.set(m,c),c+=m.byteLength,o[c]=0,c+=1;let v=62+m.byteLength+1,j=Math.ceil(v/8)*8;c=y+j}let l=o.subarray(0,c),f=await De(l),u=ye(f);return o.set(u,c),o}function tn(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}function Or(t){let e=[],n=t.length;for(;n>0;){let i=t.slice(0,n).match(/^(.+?)~(\d*)$/);if(i&&i[1]!==void 0&&i[2]!==void 0){let c=i[2]===""?1:parseInt(i[2],10);e.unshift({type:"tilde",n:c}),n=i[1].length;continue}let o=t.slice(0,n).match(/^(.+?)\^{([^}]*)}$/);if(o&&o[1]!==void 0&&o[2]!==void 0){e.unshift({type:"peel",target:o[2]}),n=o[1].length;continue}let a=t.slice(0,n).match(/^(.+?)\^(\d*)$/);if(a&&a[1]!==void 0&&a[2]!==void 0){let c=a[2]===""?1:parseInt(a[2],10);e.unshift({type:"caret",n:c}),n=a[1].length;continue}break}let r=t.slice(0,n),s=r.match(/^(.+?)@\{(\d+)\}$/);return s&&s[1]!==void 0&&s[2]!==void 0?{base:s[1],reflogIndex:parseInt(s[2],10),suffixes:e}:{base:r,suffixes:e}}var Rr=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];async function Pr(t,e){let n=await Yt(t,e);if(n.length===0)return null;if(n.length>1)throw new ct(e);return n[0]}var ct=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}};async function kr(t,e){if(e==="HEAD"||e==="@")return re(t,"HEAD");if(Rr.includes(e))return re(t,e);if(/^[0-9a-f]{40}$/.test(e))return await Kt(t,e)?e:null;if(/^[0-9a-f]{4,39}$/.test(e)){let i=await Pr(t,e);if(i)return i}if(e.startsWith("refs/")){let i=await re(t,e);if(i)return i}let n=await re(t,`refs/heads/${e}`);if(n)return n;let r=await re(t,`refs/tags/${e}`);if(r)return r;let s=await re(t,`refs/remotes/${e}`);return s||null}async function Tr(t,e,n){if(n===""||n==="commit")try{return await ve(t,e)}catch{return null}if(n==="tree"){let s;try{s=await ve(t,e)}catch{return null}return(await A(t,s)).tree}return(await W(t,e)).type!==n?null:e}async function Sr(t,e,n){let r=e;n.some(i=>i.type==="tilde"||i.type==="caret")&&(r=await ve(t,r));for(let i of n)if(i.type==="peel"){if(!r)return null;r=await Tr(t,r,i.target)}else if(i.type==="tilde")for(let o=0;o<i.n;o++){if(!r)return null;let a=await A(t,r);if(a.parents.length===0||(r=a.parents[0]??null,!r))return null}else{if(i.n===0)continue;if(!r)return null;let o=await A(t,r);if(i.n>o.parents.length||(r=o.parents[i.n-1]??null,!r))return null}return r}async function Fe(t,e){let{base:n,reflogIndex:r,suffixes:s}=Or(e);if(r!==void 0)return null;let i=await kr(t,n);return i?Sr(t,i,s):null}var Gi=new TextEncoder;function se(t){return typeof t=="string"?t==="120000":t===40960}function nn(t){return{stdout:"",stderr:`fatal: ${t}
9
+ `,exitCode:128}}var Wi=nn("not a git repository (or any of the parent directories): .git"),zi=nn("this operation must be run in a work tree");function je(t,e){return t<e?-1:t>e?1:0}var Cr=new TextEncoder,rn=new TextDecoder,vr=new Set(["100644","100755","040000","120000","160000"]);function jr(t){return t.length===4&&t.toLowerCase()===".git"}function Ar(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(jr(t))throw new Error(`invalid tree entry: '${t}'`);if(!vr.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${t}'`)}function Ae(t){let e=[],n=0;for(;n<t.byteLength;){let r=t.indexOf(32,n);if(r===-1)break;let s=rn.decode(t.subarray(n,r)),i=t.indexOf(0,r+1);if(i===-1)break;let o=rn.decode(t.subarray(r+1,i)),a=t.subarray(i+1,i+21),c=ke(a),l=s.padStart(6,"0");Ar(o,l),e.push({mode:l,name:o,hash:c}),n=i+21}return{type:"tree",entries:e}}function Ge(t){let e=[];for(let i of t.entries){let o=i.mode.replace(/^0+/,""),a=Cr.encode(`${o} ${i.name}\0`),c=ye(i.hash);e.push(a),e.push(c)}let n=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}async function lt(t,e){return sn(t,e,"")}async function sn(t,e,n){let r=[],s=new Map;for(let o of e){let a=n?o.path.slice(n.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:$r(o.mode),name:a,hash:o.hash});else{let l=a.slice(0,c),f=s.get(l);f||(f=[],s.set(l,f)),f.push(o)}}for(let[o,a]of s){let c=n?`${n}/${o}`:o,l=await sn(t,a,c);r.push({mode:F.DIRECTORY,name:o,hash:l})}r.sort((o,a)=>{let c=o.mode===F.DIRECTORY?`${o.name}/`:o.name,l=a.mode===F.DIRECTORY?`${a.name}/`:a.name;return c<l?-1:c>l?1:0});let i=Ge({type:"tree",entries:r});return _(t,"tree",i)}async function J(t,e,n=""){let r=await W(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=Ae(r.content),i=[];for(let o of s.entries){let a=n?`${n}/${o.name}`:o.name;if(o.mode===F.DIRECTORY){let c=await J(t,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function ce(t,e){if(!e)return new Map;let n=await J(t,e);return new Map(n.map(r=>[r.path,r]))}async function ie(t,e,n){let r=await ce(t,e),s=await ce(t,n),i=[];for(let[o,a]of r){let c=s.get(o);c?(a.hash!==c.hash||a.mode!==c.mode)&&i.push({path:o,status:"modified",oldHash:a.hash,newHash:c.hash,oldMode:a.mode,newMode:c.mode}):i.push({path:o,status:"deleted",oldHash:a.hash,oldMode:a.mode})}for(let[o,a]of s)r.has(o)||i.push({path:o,status:"added",newHash:a.hash,newMode:a.mode});return i.sort((o,a)=>je(o.path,a.path))}function $r(t){return t.toString(8).padStart(6,"0")}function Lr(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 on(t,e,n,r){if(Lr(t)){let o=e.some(a=>a.test(t));return{matches:[],binary:o}}let s=t.split(`
10
10
  `);if(s.length>0&&s[s.length-1]===""&&s.pop(),n&&e.length>1&&!e.every(a=>s.some(c=>a.test(c))))return{matches:[],binary:!1};let i=[];for(let o=0;o<s.length;o++){let a=s[o],c=e.some(l=>l.test(a));(r?!c:c)&&i.push({lineNo:o+1,line:a})}return{matches:i,binary:!1}}function Mr(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function an(t,e){let n=e?.fixed?Mr(t):t;e?.wordRegexp&&(n=`\\b${n}\\b`);let r=e?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}async function Dr(t,e){return re(t,e)}async function Hr(t){return at(t,"refs/heads")}async function Ur(t){return at(t,"refs/tags")}async function Nr(t,e){return A(t,e)}async function Br(t,e){return ne(t,e)}async function Fr(t,e){return H(t,e)}async function Gr(t,e,n){let r=await A(t,e),i=(await J(t,r.tree)).find(o=>o.path===n);return i?H(t,i.hash):null}function _r(t){let e=0;for(let n=0;n<t.length;n++)t[n]==="/"&&e++;return e}function Wr(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 zr(t,e,n,r){let s=[];for(let m of n)if(m instanceof RegExp)s.push(m);else{let y=an(m,{fixed:r?.fixed,ignoreCase:r?.ignoreCase,wordRegexp:r?.wordRegexp});if(!y)throw new Error(`Invalid pattern: ${m}`);s.push(y)}let i=await A(t,e),a=(await J(t,i.tree)).filter(m=>!m.mode.startsWith("120")).sort((m,y)=>m.path<y.path?-1:m.path>y.path?1:0),c=r?.allMatch??!1,l=r?.invert??!1,f=r?.maxCount,u=r?.maxDepth,d=r?.paths,h=[];for(let m of a){if(u!==void 0&&_r(m.path)>u||d&&!d.some(R=>Wr(R,m.path)))continue;let y=await H(t,m.hash),p=on(y,s,c,l);if(p.binary){h.push({path:m.path,matches:[],binary:!0});continue}if(p.matches.length===0)continue;let b=f!==void 0?p.matches.slice(0,f):p.matches;h.push({path:m.path,matches:b,binary:!1})}return h}function ee(t){if(t.length===0)return[];let e=t.split(`
11
- `);return e[e.length-1]===""&&e.pop(),e}var Vr=4,cn=1024,_e=100,Ve=0,We=1,we=2;function ut(t){let e=1;for(;e*e<t;)e++;return e}function Kr(t,e){let n=new Map,r=[],s=new Array(t.length),i=new Array(e.length);for(let o=0;o<t.length;o++){let a=t[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len1++,s[o]=c}for(let o=0;o<e.length;o++){let a=e[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function Yr(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&t[e-1-a]===n[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function ln(t,e,n,r){e-n>_e&&(n=e-_e),r-e>_e&&(r=e+_e);let s=0,i=1;for(let c=1;e-c>=n;c++){let l=t[e-c];if(l===Ve)s++;else if(l===we)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let l=t[e+c];if(l===Ve)o++;else if(l===we)a++;else break}return o===0?!1:(o+=s,a+=i,a*Vr<a+o)}function qr(t,e,n,r,s,i,o,a,c,l){let f=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(ut(e),cn);for(let p=i;p<=o;p++){let b=s[t[p]].len2;b===0?f[p]=Ve:b>=d?f[p]=we:f[p]=We}let h=Math.min(ut(r),cn);for(let p=i;p<=a;p++){let b=s[n[p]].len1;b===0?u[p]=Ve:b>=h?u[p]=we:u[p]=We}let m=[];for(let p=i;p<=o;p++)f[p]===We||f[p]===we&&!ln(f,p,i,o)?m.push(p):c[p]=1;let y=[];for(let p=i;p<=a;p++)u[p]===We||u[p]===we&&!ln(u,p,i,a)?y.push(p):l[p]=1;return{refIndex1:m,nreff1:m.length,refIndex2:y,nreff2:y.length}}var le=20,fn=4,Xr=256,Zr=256,ze=2147483647;function z(t,e){return t[e]??0}function Jr(t,e,n,r,s,i,o,a,c,l){let f=e-i,u=n-s,d=e-s,h=n-i,m=d-h&1,y=d,p=d,b=h,R=h;o[d]=e,a[h]=n;for(let j=1;;j++){let v=!1;y>f?o[--y-1]=-1:++y,p<u?o[++p+1]=-1:--p;for(let O=p;O>=y;O-=2){let w;z(o,O-1)>=z(o,O+1)?w=z(o,O-1)+1:w=z(o,O+1);let x=w,S=w-O;for(;w<n&&S<i&&t[w]===r[S];)w++,S++;if(w-x>le&&(v=!0),o[O]=w,m&&b<=O&&O<=R&&z(a,O)<=w)return{i1:w,i2:S,minLo:!0,minHi:!0}}b>f?a[--b-1]=ze:++b,R<u?a[++R+1]=ze:--R;for(let O=R;O>=b;O-=2){let w;z(a,O-1)<z(a,O+1)?w=z(a,O-1):w=z(a,O+1)-1;let x=w,S=w-O;for(;w>e&&S>s&&t[w-1]===r[S-1];)w--,S--;if(x-w>le&&(v=!0),a[O]=w,!m&&y<=O&&O<=p&&w<=z(o,O))return{i1:w,i2:S,minLo:!0,minHi:!0}}if(!c){if(v&&j>Xr){let O=0,w=null;for(let x=p;x>=y;x-=2){let S=x>d?x-d:d-x,E=z(o,x),P=E-x,T=E-e+(P-s)-S;if(T>fn*j&&T>O&&e+le<=E&&E<n&&s+le<=P&&P<i){let $=!0;for(let D=1;D<=le;D++)if(t[E-D]!==r[P-D]){$=!1;break}$&&(O=T,w={i1:E,i2:P,minLo:!0,minHi:!1})}}if(w)return w;O=0,w=null;for(let x=R;x>=b;x-=2){let S=x>h?x-h:h-x,E=z(a,x),P=E-x,T=n-E+(i-P)-S;if(T>fn*j&&T>O&&e<E&&E<=n-le&&s<P&&P<=i-le){let $=!0;for(let D=0;D<le;D++)if(t[E+D]!==r[P+D]){$=!1;break}$&&(O=T,w={i1:E,i2:P,minLo:!1,minHi:!0})}}if(w)return w}if(j>=l){let O=-1,w=-1;for(let E=p;E>=y;E-=2){let P=Math.min(z(o,E),n),T=P-E;i<T&&(P=i+E,T=i),O<P+T&&(O=P+T,w=P)}let x=ze,S=ze;for(let E=R;E>=b;E-=2){let P=Math.max(e,z(a,E)),T=P-E;T<s&&(P=s+E,T=s),P+T<x&&(x=P+T,S=P)}return n+i-x<O-(e+s)?{i1:w,i2:O-w,minLo:!0,minHi:!1}:{i1:S,i2:x-S,minLo:!1,minHi:!0}}}}}function ht(t,e,n,r,s,i,o,a,c,l,f,u,d,h){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let m=s;m<i;m++)a[l[m]]=1;else if(s===i)for(let m=e;m<n;m++)o[c[m]]=1;else{let m=Jr(t,e,n,r,s,i,f,u,d,h);ht(t,e,m.i1,r,s,m.i2,o,a,c,l,f,u,m.minLo,h),ht(t,m.i1,n,r,m.i2,i,o,a,c,l,f,u,m.minHi,h)}}function Qr(t,e,n,r){let s=[],i=0,o=0,a=1,c=1;for(;i<t.length||o<e.length;){if(i<t.length&&o<e.length&&!n[i]&&!r[o]){s.push({type:"keep",line:t[i]??"",oldLineNo:a++,newLineNo:c++}),i++,o++;continue}for(;i<t.length&&n[i];)s.push({type:"delete",line:t[i]??"",oldLineNo:a++,newLineNo:0}),i++;for(;o<e.length&&r[o];)s.push({type:"insert",line:e[o]??"",oldLineNo:0,newLineNo:c++}),o++}return s}var un=200,hn=20,dn=100,es=1,ts=21,ns=-30,rs=6,ss=-4,is=10,os=24,as=17,cs=23,ls=17,fs=60;function ft(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>=un)return un}return-1}function mn(t,e,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=ft(t[n]));for(let s=n-1;s>=0&&(r.preIndent=ft(t[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===hn){r.preIndent=0;break}for(let s=n+1;s<e&&(r.postIndent=ft(t[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===hn){r.postIndent=0;break}return r}function pn(t,e){t.preIndent===-1&&t.preBlank===0&&(e.penalty+=es),t.endOfFile&&(e.penalty+=ts);let n=t.indent===-1?1+t.postBlank:0,r=t.preBlank+n;e.penalty+=ns*r,e.penalty+=rs*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?is:ss:s===t.preIndent||(t.postIndent!==-1&&t.postIndent>s?e.penalty+=i?as:os:e.penalty+=i?ls:cs))}function us(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndent<e.effectiveIndent?1:0);return fs*n+(t.penalty-e.penalty)}function yn(t,e,n,r,s,i){let o=0,a=0;for(;t[a];)a++;let c=0,l=0;for(;s[l];)l++;let f=(u,d)=>e[u]===e[d];for(;;){if(a!==o){let u,d,h;do{for(u=a-o,d=-1;o>0&&f(o-1,a-1);){for(t[--o]=1,t[--a]=0;t[o-1];)o--;if(c===0)break;for(l=c-1,c=l;s[c-1];c--);}for(h=a,l>c&&(d=a);!(a>=r||!f(o,a));){for(t[o++]=0,t[a++]=1;t[a];)a++;if(l>=i)break;for(c=l+1,l=c;s[l];l++);l>c&&(d=a)}}while(u!==a-o);if(a!==h)if(d!==-1)for(;l===c;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(l=c-1,c=l;s[c-1];c--);}else{let m=-1,y={effectiveIndent:0,penalty:0},p=h;for(a-u-1>p&&(p=a-u-1),a-dn>p&&(p=a-dn);p<=a;p++){let b={effectiveIndent:0,penalty:0},R=mn(n,r,p);pn(R,b);let j=mn(n,r,p-u);pn(j,b),(m===-1||us(b,y)<=0)&&(y={effectiveIndent:b.effectiveIndent,penalty:b.penalty},m=p)}for(;a>m;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(l=c-1,c=l;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;t[a];a++);if(l>=i)break;for(c=l+1,l=c;s[l];l++);}}function dt(t,e){let n=t.length,r=e.length,s=new Uint8Array(n),i=new Uint8Array(r);if(n>0&&r>0){let{classes1:o,classes2:a,classInfo:c}=Kr(t,e),{dstart:l,dend1:f,dend2:u}=Yr(o,n,a,r);if(l>f)for(let d=l;d<r-(n-1-f);d++)i[d]=1;else if(l>u)for(let d=l;d<n-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:y}=qr(o,n,a,r,c,l,f,u,s,i);if(h>0&&y>0){let p=new Array(h);for(let w=0;w<h;w++)p[w]=o[d[w]];let b=new Array(y);for(let w=0;w<y;w++)b[w]=a[m[w]];let R={},j={},v=h+y+3,O=Math.max(Zr,ut(v));ht(p,0,h,b,0,y,s,i,d,m,R,j,!1,O)}else if(h===0)for(let p=0;p<y;p++)i[m[p]]=1;else for(let p=0;p<h;p++)s[d[p]]=1;yn(s,o,t,n,i,r),yn(i,a,e,r,s,n)}}else n===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function Ie(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return e.map((o,a)=>({type:"insert",line:o,oldLineNo:0,newLineNo:a+1}));if(r===0)return t.map((o,a)=>({type:"delete",line:o,oldLineNo:a+1,newLineNo:0}));let{changedOld:s,changedNew:i}=dt(t,e);return Qr(t,e,s,i)}var hs=3;function gn(t,e=hs){if(e=Math.max(0,e),t.length===0)return[];let n=[];for(let a=0;a<t.length;a++){let c=t[a];c&&c.type!=="keep"&&n.push(a)}if(n.length===0)return[];let r=n[0]??0,s=[],i=Math.max(0,r-e),o=Math.min(t.length-1,r+e);for(let a=1;a<n.length;a++){let c=n[a]??0,l=Math.max(0,c-e),f=Math.min(t.length-1,c+e);l<=o+1||(s.push({start:i,end:o}),i=l),o=f}return s.push({start:i,end:o}),s.map(a=>ds(t,a.start,a.end))}function ds(t,e,n){let r=0,s=0,i=0,o=0,a=[],c=!1,l=!1;for(let f=e;f<=n;f++){let u=t[f];if(u)switch(u.type){case"keep":c||(r=u.oldLineNo,c=!0),l||(i=u.newLineNo,l=!0),s++,o++,a.push({type:"context",content:u.line});break;case"delete":c||(r=u.oldLineNo,c=!0),s++,a.push({type:"delete",content:u.line});break;case"insert":l||(i=u.newLineNo,l=!0),o++,a.push({type:"insert",content:u.line});break}}if(c||(r=i>0?i:1),l||(i=r>0?r:1),s===0)for(let f=e;f<=n;f++){let u=t[f];if(u&&u.type==="insert"){r=u.newLineNo>1?u.newLineNo-1:0;break}}if(o===0)for(let f=e;f<=n;f++){let u=t[f];if(u&&u.type==="delete"){i=u.oldLineNo>1?u.oldLineNo-1:0;break}}return{oldStart:r,oldCount:s,newStart:i,newCount:o,lines:a}}function Ee(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function ms(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=Ee(e),r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i&&Ee(i.path)===n){r=s;break}}return t.splice(r,1)[0]}var ps=50;async function de(t,e,n=ps){let r=new Map,s=[],i=[],o=[];for(let f of e)if(f.status==="deleted"&&f.oldHash){let u=r.get(f.oldHash)??[];u.push(f),r.set(f.oldHash,u),s.push(f)}else f.status==="added"&&f.newHash?i.push(f):o.push(f);let a=[],c=[];for(let f of i){let u=f.newHash;if(!u){c.push(f);continue}let d=r.get(u);if(d&&d.length>0){let h=ms(d,f.path);h&&a.push({oldPath:h.path,newPath:f.path,oldHash:h.oldHash??u,newHash:u,similarity:100,oldMode:h.oldMode,newMode:f.newMode})}else c.push(f)}let l=[...r.values()].flat();if(l.length>0&&c.length>0){let f=await ys(t,l,c,n);if(f.length>0){let u=new Set(f.map(h=>h.oldPath)),d=new Set(f.map(h=>h.newPath));l=l.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...f)}}if(l.length>0&&c.length>0){let f=await ws(t,l,c,n);if(f.length>0){let u=new Set(f.map(h=>h.oldPath)),d=new Set(f.map(h=>h.newPath));l=l.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...f)}}return{remaining:[...o,...l,...c],renames:a}}async function ys(t,e,n,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let l=Ee(c.path);s.has(l)?s.set(l,-1):s.set(l,a)}let i=new Map;for(let a=0;a<n.length;a++){let c=n[a];if(!c)continue;let l=Ee(c.path);i.has(l)?i.set(l,-1):i.set(l,a)}let o=[];for(let[a,c]of s){if(c===-1)continue;let l=i.get(a);if(l===void 0||l===-1)continue;let f=e[c],u=n[l];if(!f?.oldHash||!u?.newHash||f.oldHash===u.newHash)continue;let d=await ne(t,f.oldHash),h=await ne(t,u.newHash),m=bs(d,h);m<r||o.push({oldPath:f.path,newPath:u.path,oldHash:f.oldHash,newHash:u.newHash,similarity:m,oldMode:f.oldMode,newMode:u.newMode})}return o}var bn=107927;function Ke(t){let e=new Map,n=0,r=0,s=0;for(let o=0;o<t.length;o++){let a=t[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let l=(r+Math.imul(s,97))%bn;e.set(l,(e.get(l)??0)+n),n=0,r=0,s=0}if(n>0){let o=(r+Math.imul(s,97))%bn;e.set(o,(e.get(o)??0)+n)}let i=[];for(let[o,a]of e)i.push({hash:o,count:a});return i.sort((o,a)=>o.hash-a.hash),i}function gs(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let o=t[s];if(!o)break;for(;i<e.length;){let l=e[i];if(!l||l.hash>=o.hash)break;r+=l.count,i++}let a=o.count,c=0;if(i<e.length){let l=e[i];l&&l.hash===o.hash&&(c=l.count,i++)}a<c?(r+=c-a,n+=a):n+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:n,literalAdded:r}}function bs(t,e){return t.length===0&&e.length===0?100:t.length===0||e.length===0?0:wn(t.length,Ke(t),e.length,Ke(e))}function wn(t,e,n,r){let s=Math.max(t,n),i=Math.min(t,n);if(i<s-i)return 0;let{srcCopied:o}=gs(e,r);return Math.floor(o*100/s)}async function ws(t,e,n,r){let s=[];for(let f of e)if(f.oldHash){let u=await ne(t,f.oldHash);s.push({size:u.length,chunks:Ke(u)})}else s.push(null);let i=[];for(let f of n)if(f.newHash){let u=await ne(t,f.newHash);i.push({size:u.length,chunks:Ke(u)})}else i.push(null);let o=[];for(let f=0;f<e.length;f++){let u=e[f],d=s[f];if(!(!u||!d))for(let h=0;h<n.length;h++){let m=n[h],y=i[h];if(!m||!y)continue;let p=wn(d.size,d.chunks,y.size,y.chunks);if(p>=r){let b=Ee(u.path)===Ee(m.path)?1:0;o.push({similarity:p,nameScore:b,delIdx:f,addIdx:h})}}}o.sort((f,u)=>u.similarity-f.similarity||u.nameScore-f.nameScore);let a=new Set,c=new Set,l=[];for(let{similarity:f,delIdx:u,addIdx:d}of o){if(a.has(u)||c.has(d))continue;a.add(u),c.add(d);let h=e[u],m=n[d];!h||!m||l.push({oldPath:h.path,newPath:m.path,oldHash:h.oldHash??"",newHash:m.newHash??"",similarity:f,oldMode:h.oldMode,newMode:m.newMode})}return l}async function fe(t,e,n){return(await ce(t,e)).get(n)?.hash??null}async function In(t,e,n,r){let s=await ie(t,e,n);if(!s.find(c=>c.status==="added"&&c.path===r))return null;let{renames:o}=await de(t,s);return o.find(c=>c.newPath===r)?.oldPath??null}async function Is(t,e,n,r,s,i){let o=await fe(t,(await A(t,e)).tree,n);if(!o){let y=new Map,p=await A(t,e);for(let b of r)y.set(b.finalIdx,ue(e,n,b.currentLine,i+b.finalIdx,s[b.finalIdx],p,!1,void 0));return y}let a=await H(t,o),c=ee(a),l=new Array(s.length),f=[...r],u=e,d=n,h=c;for(;f.length>0;){let y=await A(t,u);if(y.parents.length===0){for(let E of f)l[E.finalIdx]=ue(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],y,!0,void 0);break}let p=await fe(t,y.tree,d),b=null,R=[];for(let E of y.parents){let P=await A(t,E),T=d,$=await fe(t,P.tree,T);if(!$){let D=await In(t,P.tree,y.tree,d);D&&(T=D,$=await fe(t,P.tree,T))}if($&&(R.push({hash:E,path:T,blobHash:$}),$===p)){b={hash:E,path:T};break}}if(b){u=b.hash,d=b.path;continue}if(R.length===0){for(let E of f)l[E.finalIdx]=ue(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],y,!1,void 0);break}let j=R[0],v=await H(t,j.blobHash),O=ee(v),w=Ie(O,h),x=new Map;for(let E of w)E.type==="keep"&&x.set(E.newLineNo,E.oldLineNo);let S=[];for(let E of f){let P=x.get(E.currentLine);P!==void 0?S.push({finalIdx:E.finalIdx,currentLine:P}):l[E.finalIdx]=ue(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],y,!1,{hash:j.hash,path:j.path})}f=S,u=j.hash,d=j.path,h=O}let m=new Map;for(let y of r)l[y.finalIdx]&&m.set(y.finalIdx,l[y.finalIdx]);return m}async function En(t,e,n,r){let s=await A(t,e),i=await fe(t,s.tree,n);if(!i)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let o=await H(t,i),a=ee(o),c=r?.startLine??1,l=r?.endLine??a.length,f=a.slice(c-1,l),u=new Array(f.length),d=f.map((p,b)=>({finalIdx:b,currentLine:c+b})),h=e,m=n,y=a;for(;d.length>0;){let p=await A(t,h);if(p.parents.length===0){for(let x of d)u[x.finalIdx]=ue(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!0,void 0);break}let b=await fe(t,p.tree,m),R=[],j=null;for(let x of p.parents){let S=await A(t,x),E=m,P=await fe(t,S.tree,E);if(!P){let T=await In(t,S.tree,p.tree,m);T&&(E=T,P=await fe(t,S.tree,E))}if(P){let T={hash:x,path:E,blobHash:P};if(R.push(T),P===b){j=T;break}}}if(j){h=j.hash,m=j.path;continue}if(R.length===0){for(let x of d)u[x.finalIdx]=ue(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!1,void 0);break}if(R.length===1){let x=R[0],S=await H(t,x.blobHash),E=ee(S),P=Ie(E,y),T=new Map;for(let D of P)D.type==="keep"&&T.set(D.newLineNo,D.oldLineNo);let $=[];for(let D of d){let oe=T.get(D.currentLine);oe!==void 0?$.push({finalIdx:D.finalIdx,currentLine:oe}):u[D.finalIdx]=ue(h,m,D.currentLine,c+D.finalIdx,f[D.finalIdx],p,!1,{hash:x.hash,path:x.path})}d=$,h=x.hash,m=x.path,y=E;continue}let v=[];for(let x of R){let S=await H(t,x.blobHash),E=ee(S),P=Ie(E,y),T=new Map;for(let $ of P)$.type==="keep"&&T.set($.newLineNo,$.oldLineNo);v.push({info:x,newToOld:T})}let O=new Map;for(let x of d){let S=!1;for(let E=0;E<v.length;E++){let P=v[E],T=P.newToOld.get(x.currentLine);if(T!==void 0){let $=O.get(E);$||($={info:P.info,lines:[]},O.set(E,$)),$.lines.push({finalIdx:x.finalIdx,currentLine:T}),S=!0;break}}S||(u[x.finalIdx]=ue(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!1,{hash:R[0].hash,path:R[0].path}))}let w=O.get(0);for(let[x,S]of O){if(x===0)continue;let E=await Is(t,S.info.hash,S.info.path,S.lines,f,c);for(let[P,T]of E)u[P]=T}if(w&&w.lines.length>0){d=w.lines,h=w.info.hash,m=w.info.path;let x=await H(t,w.info.blobHash);y=ee(x)}else break}return u}function ue(t,e,n,r,s,i,o,a){return{hash:t,origPath:e,origLine:n,finalLine:r,content:s,author:i.author,committer:i.committer,summary:i.message.split(`
12
- `)[0],boundary:o,previous:a}}var xe=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),o<r&&this.higher(n[o],n[s])&&(s=o),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*me(t,e,n){if(n?.topoOrder){yield*Es(t,e,n);return}let r=await On(t,n?.exclude),s=new Set(r),i=new xe,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let c of a)s.has(c)||i.push(await Ye(t,c));for(;i.size>0;){let c=i.pop();if(s.has(c.hash)||(s.add(c.hash),yield c,o?.has(c.hash)))continue;let l=n?.firstParent?c.commit.parents.slice(0,1):c.commit.parents;for(let f of l)if(!s.has(f))try{i.push(await Ye(t,f))}catch{}}}async function*Es(t,e,n){let r=await On(t,n?.exclude),s=new Set(r),i=new xe,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let h of a)s.has(h)||i.push(await Ye(t,h));let c=[],l=new Map;for(;i.size>0;){let h=i.pop();if(s.has(h.hash)||(s.add(h.hash),l.set(h.hash,c.length),c.push(h),o?.has(h.hash)))continue;let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let y of m)if(!s.has(y))try{i.push(await Ye(t,y))}catch{}}let f=c.length;if(f===0)return;let u=new Int32Array(f);for(let h of c){let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let y of m){let p=l.get(y);p!==void 0&&(u[p]=(u[p]??0)+1)}}let d=[];for(let h=f-1;h>=0;h--)u[h]===0&&d.push(h);for(;d.length>0;){let h=d.pop();yield c[h];let m=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let y of m){let p=l.get(y);if(p!==void 0){let b=(u[p]??0)-1;u[p]=b,b===0&&d.push(p)}}}}async function xn(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let a of me(t,e))r.add(a.hash);let s=new Set;for await(let a of me(t,n))s.add(a.hash);let i=0;for(let a of r)s.has(a)||i++;let o=0;for(let a of s)r.has(a)||o++;return{ahead:i,behind:o}}async function On(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of me(t,e))n.add(r.hash);return n}async function Ye(t,e){return{hash:e,commit:await A(t,e)}}async function xs(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let o;try{o=await A(t,i)}catch{continue}for(let a of o.parents)n.has(a)||r.push(a)}return n}async function mt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let o=s[i++];if(o===e)return!0;if(r.has(o))continue;r.add(o);let a;try{a=await A(t,o)}catch{continue}for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function $e(t,e,n){if(e===n)return[e];let r=await xs(t,e),s=[],i=new Set,o=[n],a=0;for(;a<o.length;){let l=o[a++];if(i.has(l))continue;if(i.add(l),r.has(l)){s.push(l);continue}let f;try{f=await A(t,l)}catch{continue}for(let u of f.parents)i.has(u)||o.push(u)}if(s.length<=1)return s;let c=[];for(let l of s){let f=!1;for(let u of s)if(u!==l&&await mt(t,l,u)){f=!0;break}f||c.push(l)}return c.length<=1?c:Os(t,e,n,c)}async function Os(t,e,n,r){let s=new Set(r),i=new Set,o=[],a=new Map,c=new Map,l=0,f=[{hash:e,mask:1,seq:l++},{hash:n,mask:2,seq:l++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await A(t,d)).committer.timestamp;return c.set(d,m),m}for(;f.length>0;){let d=0,h=await u(f[0].hash);for(let R=1;R<f.length;R++){let j=f[R],v=await u(j.hash),O=f[d];(v>h||v===h&&j.seq<O.seq)&&(d=R,h=v)}let m=f.splice(d,1)[0],y=a.get(m.hash)??0,p=y|m.mask;if(p===y)continue;if(a.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let b=await A(t,m.hash);for(let R of b.parents)f.push({hash:R,mask:p,seq:l++})}for(let d of r)i.has(d)||o.push(d);return o}async function Rs(t,e){return J(t,e)}async function Ps(t,e,n){return ie(t,e,n)}async function ks(t,e,n){let r=await A(t,n),s=null;return e&&(s=(await A(t,e)).tree),ie(t,s,r.tree)}async function*Ts(t,e,n){let r=e?[e]:[];for await(let s of me(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 Ss(t,e,n){return mt(t,e,n)}async function Cs(t,e,n){return $e(t,e,n)}async function js(t,e,n){return xn(t,e,n)}async function vs(t,e,n,r){return En(t,e,n,r)}function As(t){return t==="insert"?"+":t==="delete"?"-":" "}function $s(t){return{oldStart:t.oldStart,oldCount:t.oldCount,newStart:t.newStart,newCount:t.newCount,lines:t.lines.map(e=>As(e.type)+e.content)}}function Rn(t,e,n){let r=ee(t),s=ee(e),i=Ie(r,s);return gn(i,n).map($s)}async function Pn(t,e){let n=await Fe(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function Ls(t,e,n,r){let s=await Pn(t,e),i=await Pn(t,n),o=await A(t,s),a=await A(t,i),c=await ie(t,o.tree,a.tree),l=r?.renames!==!1,f=r?.contextLines,u=r?.paths,d=[];if(l){let m=await de(t,c);c=m.remaining,d=m.renames}let h=[];for(let m of c){if(u&&!u.some(R=>m.path.startsWith(R)))continue;let y=m.oldHash?await H(t,m.oldHash):"",p=m.newHash?await H(t,m.newHash):"",b=Rn(y,p,f);h.push({path:m.path,status:m.status,hunks:b})}for(let m of d){if(u&&!u.some(R=>m.newPath.startsWith(R)||m.oldPath.startsWith(R)))continue;let y=await H(t,m.oldHash),p=await H(t,m.newHash),b=Rn(y,p,f);h.push({path:m.newPath,status:"renamed",oldPath:m.oldPath,similarity:m.similarity,hunks:b})}return h.sort((m,y)=>m.path.localeCompare(y.path)),h}async function*Ms(t,e,n){if(n?.paths&&n.paths.length>0){yield*Ds(t,e,n.paths,n);return}for await(let r of me(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*Ds(t,e,n,r){let s=new Set;if(r?.exclude)for await(let l of me(t,r.exclude))s.add(l.hash);let i=new Set(s),o=new xe,a=async l=>{if(!i.has(l))try{let f=await A(t,l);o.push({hash:l,commit:f})}catch{}},c=Array.isArray(e)?e:[e];for(let l of c)await a(l);for(;o.size>0;){let l=o.pop();if(i.has(l.hash))continue;i.add(l.hash);let{commit:f}=l,u=r?.firstParent?f.parents.slice(0,1):f.parents,d=()=>({hash:l.hash,message:f.message,tree:f.tree,parents:f.parents,author:f.author,committer:f.committer});if(u.length===0){(await ie(t,null,f.tree)).some(y=>pt(y.path,n))&&(yield d());continue}if(u.length===1){let m=u[0];try{let y=await A(t,m);(await ie(t,y.tree,f.tree)).some(b=>pt(b.path,n))&&(yield d())}catch{yield d()}await a(m);continue}let h=[];for(let m of u)try{let y=await A(t,m);(await ie(t,y.tree,f.tree)).some(b=>pt(b.path,n))||h.push(m)}catch{}if(h.length>0)await a(h[0]);else{yield d();for(let m of u)await a(m)}}}async function Hs(t,e){let n=Ne({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message}),r=await _(t,"commit",n);if(e.branch){let s=`refs/heads/${e.branch}`;await t.refStore.writeRef(s,{type:"direct",hash:r}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:s})}return r}async function Us(t,e){let n=[...e].sort((i,o)=>i.name.localeCompare(o.name)),r=await Promise.all(n.map(async i=>{let o=i.mode;return o||(o=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:o,name:i.name,hash:i.hash}})),s=Ge({type:"tree",entries:r});return _(t,"tree",s)}async function Ns(t,e){return _(t,"blob",new TextEncoder().encode(e))}function yt(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}=dt(t,e);return Bs(s,n,i,r)}function Bs(t,e,n,r){let s=[],i=0,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!t[i]&&!n[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&t[i];)i++;for(;o<r&&n[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function Fs(t,e,n){let r=[];for(let c of yt(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 yt(e,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,l)=>c.oStart-l.oStart);let s=[],i=0;function o(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let a=0;for(;a<r.length;){let c=r[a++],l=c.oStart,f=c.oStart+c.oLength,u=[c];for(o(l);a<r.length;){let d=r[a];if(d.oStart>f)break;f=Math.max(f,d.oStart+d.oLength),u.push(d),a++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?t:n;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:d.slice(c.abStart,c.abStart+c.abLength)})}}else{let d={a:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let b of u){let R=b.oStart,j=R+b.oLength,v=b.abStart,O=v+b.abLength,w=d[b.ab];w.abMin=Math.min(v,w.abMin),w.abMax=Math.max(O,w.abMax),w.oMin=Math.min(R,w.oMin),w.oMax=Math.max(j,w.oMax)}let h=d.a.abMin+(l-d.a.oMin),m=d.a.abMax+(f-d.a.oMax),y=d.b.abMin+(l-d.b.oMin),p=d.b.abMax+(f-d.b.oMax);s.push({stable:!1,a:t.slice(h,m),o:e.slice(l,f),b:n.slice(y,p)})}i=f}return o(e.length),s}function Gs(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=Fs(t,e,n),o=[],a=[];function c(){a.length&&(o.push({type:"ok",lines:a}),a=[])}for(let l of i)l.stable?a.push(...l.content):s&&Tn(l.a,l.b)?a.push(...l.a):(c(),o.push({type:"conflict",a:l.a,o:l.o,b:l.b}));return c(),r?.conflictStyle==="diff3"?kn(o):kn(_s(o))}function Le(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",o=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),l=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,f=Gs(t,e,n,{conflictStyle:i}),u=!1,d=[];for(let h of f)h.type==="ok"?d.push(...h.lines):(u=!0,i==="diff3"?d.push(o,...h.a,a,...h.o,c,...h.b,l):d.push(o,...h.a,c,...h.b,l));return{conflict:u,result:d}}function _s(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...Ws(n));return e}function Ws(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(Tn(e,n))return[t];let r=yt(e,n);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let a of r){let c=a.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let f=c+a.buffer1[1],u=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:e.slice(c,f),o:[],b:n.slice(a.buffer2[0],u)}),i=f}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[t]:s}function kn(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.length-1],i=e[r];if(s.type==="conflict"&&i.type==="ok"&&i.lines.length<=3&&r+1<e.length&&e[r+1].type==="conflict"){let o=e[r+1],a=s;a.a=[...s.a,...i.lines,...o.a],a.b=[...s.b,...i.lines,...o.b],a.o=[...s.o,...i.lines,...o.o],r++}else n.push(i)}return n}function pe(t,e,n,r){let s=Le(Y(t),Y(e),Y(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(gt);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
11
+ `);return e[e.length-1]===""&&e.pop(),e}var Vr=4,cn=1024,_e=100,Ve=0,We=1,we=2;function ut(t){let e=1;for(;e*e<t;)e++;return e}function Kr(t,e){let n=new Map,r=[],s=new Array(t.length),i=new Array(e.length);for(let o=0;o<t.length;o++){let a=t[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len1++,s[o]=c}for(let o=0;o<e.length;o++){let a=e[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function Yr(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&t[e-1-a]===n[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function ln(t,e,n,r){e-n>_e&&(n=e-_e),r-e>_e&&(r=e+_e);let s=0,i=1;for(let c=1;e-c>=n;c++){let l=t[e-c];if(l===Ve)s++;else if(l===we)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let l=t[e+c];if(l===Ve)o++;else if(l===we)a++;else break}return o===0?!1:(o+=s,a+=i,a*Vr<a+o)}function qr(t,e,n,r,s,i,o,a,c,l){let f=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(ut(e),cn);for(let p=i;p<=o;p++){let b=s[t[p]].len2;b===0?f[p]=Ve:b>=d?f[p]=we:f[p]=We}let h=Math.min(ut(r),cn);for(let p=i;p<=a;p++){let b=s[n[p]].len1;b===0?u[p]=Ve:b>=h?u[p]=we:u[p]=We}let m=[];for(let p=i;p<=o;p++)f[p]===We||f[p]===we&&!ln(f,p,i,o)?m.push(p):c[p]=1;let y=[];for(let p=i;p<=a;p++)u[p]===We||u[p]===we&&!ln(u,p,i,a)?y.push(p):l[p]=1;return{refIndex1:m,nreff1:m.length,refIndex2:y,nreff2:y.length}}var le=20,fn=4,Xr=256,Zr=256,ze=2147483647;function z(t,e){return t[e]??0}function Jr(t,e,n,r,s,i,o,a,c,l){let f=e-i,u=n-s,d=e-s,h=n-i,m=d-h&1,y=d,p=d,b=h,R=h;o[d]=e,a[h]=n;for(let v=1;;v++){let j=!1;y>f?o[--y-1]=-1:++y,p<u?o[++p+1]=-1:--p;for(let O=p;O>=y;O-=2){let w;z(o,O-1)>=z(o,O+1)?w=z(o,O-1)+1:w=z(o,O+1);let x=w,S=w-O;for(;w<n&&S<i&&t[w]===r[S];)w++,S++;if(w-x>le&&(j=!0),o[O]=w,m&&b<=O&&O<=R&&z(a,O)<=w)return{i1:w,i2:S,minLo:!0,minHi:!0}}b>f?a[--b-1]=ze:++b,R<u?a[++R+1]=ze:--R;for(let O=R;O>=b;O-=2){let w;z(a,O-1)<z(a,O+1)?w=z(a,O-1):w=z(a,O+1)-1;let x=w,S=w-O;for(;w>e&&S>s&&t[w-1]===r[S-1];)w--,S--;if(x-w>le&&(j=!0),a[O]=w,!m&&y<=O&&O<=p&&w<=z(o,O))return{i1:w,i2:S,minLo:!0,minHi:!0}}if(!c){if(j&&v>Xr){let O=0,w=null;for(let x=p;x>=y;x-=2){let S=x>d?x-d:d-x,E=z(o,x),P=E-x,T=E-e+(P-s)-S;if(T>fn*v&&T>O&&e+le<=E&&E<n&&s+le<=P&&P<i){let $=!0;for(let D=1;D<=le;D++)if(t[E-D]!==r[P-D]){$=!1;break}$&&(O=T,w={i1:E,i2:P,minLo:!0,minHi:!1})}}if(w)return w;O=0,w=null;for(let x=R;x>=b;x-=2){let S=x>h?x-h:h-x,E=z(a,x),P=E-x,T=n-E+(i-P)-S;if(T>fn*v&&T>O&&e<E&&E<=n-le&&s<P&&P<=i-le){let $=!0;for(let D=0;D<le;D++)if(t[E+D]!==r[P+D]){$=!1;break}$&&(O=T,w={i1:E,i2:P,minLo:!1,minHi:!0})}}if(w)return w}if(v>=l){let O=-1,w=-1;for(let E=p;E>=y;E-=2){let P=Math.min(z(o,E),n),T=P-E;i<T&&(P=i+E,T=i),O<P+T&&(O=P+T,w=P)}let x=ze,S=ze;for(let E=R;E>=b;E-=2){let P=Math.max(e,z(a,E)),T=P-E;T<s&&(P=s+E,T=s),P+T<x&&(x=P+T,S=P)}return n+i-x<O-(e+s)?{i1:w,i2:O-w,minLo:!0,minHi:!1}:{i1:S,i2:x-S,minLo:!1,minHi:!0}}}}}function ht(t,e,n,r,s,i,o,a,c,l,f,u,d,h){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let m=s;m<i;m++)a[l[m]]=1;else if(s===i)for(let m=e;m<n;m++)o[c[m]]=1;else{let m=Jr(t,e,n,r,s,i,f,u,d,h);ht(t,e,m.i1,r,s,m.i2,o,a,c,l,f,u,m.minLo,h),ht(t,m.i1,n,r,m.i2,i,o,a,c,l,f,u,m.minHi,h)}}function Qr(t,e,n,r){let s=[],i=0,o=0,a=1,c=1;for(;i<t.length||o<e.length;){if(i<t.length&&o<e.length&&!n[i]&&!r[o]){s.push({type:"keep",line:t[i]??"",oldLineNo:a++,newLineNo:c++}),i++,o++;continue}for(;i<t.length&&n[i];)s.push({type:"delete",line:t[i]??"",oldLineNo:a++,newLineNo:0}),i++;for(;o<e.length&&r[o];)s.push({type:"insert",line:e[o]??"",oldLineNo:0,newLineNo:c++}),o++}return s}var un=200,hn=20,dn=100,es=1,ts=21,ns=-30,rs=6,ss=-4,is=10,os=24,as=17,cs=23,ls=17,fs=60;function ft(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>=un)return un}return-1}function mn(t,e,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=ft(t[n]));for(let s=n-1;s>=0&&(r.preIndent=ft(t[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===hn){r.preIndent=0;break}for(let s=n+1;s<e&&(r.postIndent=ft(t[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===hn){r.postIndent=0;break}return r}function pn(t,e){t.preIndent===-1&&t.preBlank===0&&(e.penalty+=es),t.endOfFile&&(e.penalty+=ts);let n=t.indent===-1?1+t.postBlank:0,r=t.preBlank+n;e.penalty+=ns*r,e.penalty+=rs*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?is:ss:s===t.preIndent||(t.postIndent!==-1&&t.postIndent>s?e.penalty+=i?as:os:e.penalty+=i?ls:cs))}function us(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndent<e.effectiveIndent?1:0);return fs*n+(t.penalty-e.penalty)}function yn(t,e,n,r,s,i){let o=0,a=0;for(;t[a];)a++;let c=0,l=0;for(;s[l];)l++;let f=(u,d)=>e[u]===e[d];for(;;){if(a!==o){let u,d,h;do{for(u=a-o,d=-1;o>0&&f(o-1,a-1);){for(t[--o]=1,t[--a]=0;t[o-1];)o--;if(c===0)break;for(l=c-1,c=l;s[c-1];c--);}for(h=a,l>c&&(d=a);!(a>=r||!f(o,a));){for(t[o++]=0,t[a++]=1;t[a];)a++;if(l>=i)break;for(c=l+1,l=c;s[l];l++);l>c&&(d=a)}}while(u!==a-o);if(a!==h)if(d!==-1)for(;l===c;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(l=c-1,c=l;s[c-1];c--);}else{let m=-1,y={effectiveIndent:0,penalty:0},p=h;for(a-u-1>p&&(p=a-u-1),a-dn>p&&(p=a-dn);p<=a;p++){let b={effectiveIndent:0,penalty:0},R=mn(n,r,p);pn(R,b);let v=mn(n,r,p-u);pn(v,b),(m===-1||us(b,y)<=0)&&(y={effectiveIndent:b.effectiveIndent,penalty:b.penalty},m=p)}for(;a>m;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(l=c-1,c=l;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;t[a];a++);if(l>=i)break;for(c=l+1,l=c;s[l];l++);}}function dt(t,e){let n=t.length,r=e.length,s=new Uint8Array(n),i=new Uint8Array(r);if(n>0&&r>0){let{classes1:o,classes2:a,classInfo:c}=Kr(t,e),{dstart:l,dend1:f,dend2:u}=Yr(o,n,a,r);if(l>f)for(let d=l;d<r-(n-1-f);d++)i[d]=1;else if(l>u)for(let d=l;d<n-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:y}=qr(o,n,a,r,c,l,f,u,s,i);if(h>0&&y>0){let p=new Array(h);for(let w=0;w<h;w++)p[w]=o[d[w]];let b=new Array(y);for(let w=0;w<y;w++)b[w]=a[m[w]];let R={},v={},j=h+y+3,O=Math.max(Zr,ut(j));ht(p,0,h,b,0,y,s,i,d,m,R,v,!1,O)}else if(h===0)for(let p=0;p<y;p++)i[m[p]]=1;else for(let p=0;p<h;p++)s[d[p]]=1;yn(s,o,t,n,i,r),yn(i,a,e,r,s,n)}}else n===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function Ie(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return e.map((o,a)=>({type:"insert",line:o,oldLineNo:0,newLineNo:a+1}));if(r===0)return t.map((o,a)=>({type:"delete",line:o,oldLineNo:a+1,newLineNo:0}));let{changedOld:s,changedNew:i}=dt(t,e);return Qr(t,e,s,i)}var hs=3;function gn(t,e=hs){if(e=Math.max(0,e),t.length===0)return[];let n=[];for(let a=0;a<t.length;a++){let c=t[a];c&&c.type!=="keep"&&n.push(a)}if(n.length===0)return[];let r=n[0]??0,s=[],i=Math.max(0,r-e),o=Math.min(t.length-1,r+e);for(let a=1;a<n.length;a++){let c=n[a]??0,l=Math.max(0,c-e),f=Math.min(t.length-1,c+e);l<=o+1||(s.push({start:i,end:o}),i=l),o=f}return s.push({start:i,end:o}),s.map(a=>ds(t,a.start,a.end))}function ds(t,e,n){let r=0,s=0,i=0,o=0,a=[],c=!1,l=!1;for(let f=e;f<=n;f++){let u=t[f];if(u)switch(u.type){case"keep":c||(r=u.oldLineNo,c=!0),l||(i=u.newLineNo,l=!0),s++,o++,a.push({type:"context",content:u.line});break;case"delete":c||(r=u.oldLineNo,c=!0),s++,a.push({type:"delete",content:u.line});break;case"insert":l||(i=u.newLineNo,l=!0),o++,a.push({type:"insert",content:u.line});break}}if(c||(r=i>0?i:1),l||(i=r>0?r:1),s===0)for(let f=e;f<=n;f++){let u=t[f];if(u&&u.type==="insert"){r=u.newLineNo>1?u.newLineNo-1:0;break}}if(o===0)for(let f=e;f<=n;f++){let u=t[f];if(u&&u.type==="delete"){i=u.oldLineNo>1?u.oldLineNo-1:0;break}}return{oldStart:r,oldCount:s,newStart:i,newCount:o,lines:a}}function Ee(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function ms(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=Ee(e),r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i&&Ee(i.path)===n){r=s;break}}return t.splice(r,1)[0]}var ps=50;async function de(t,e,n=ps){let r=new Map,s=[],i=[],o=[];for(let f of e)if(f.status==="deleted"&&f.oldHash){let u=r.get(f.oldHash)??[];u.push(f),r.set(f.oldHash,u),s.push(f)}else f.status==="added"&&f.newHash?i.push(f):o.push(f);let a=[],c=[];for(let f of i){let u=f.newHash;if(!u){c.push(f);continue}let d=r.get(u);if(d&&d.length>0){let h=ms(d,f.path);h&&a.push({oldPath:h.path,newPath:f.path,oldHash:h.oldHash??u,newHash:u,similarity:100,oldMode:h.oldMode,newMode:f.newMode})}else c.push(f)}let l=[...r.values()].flat();if(l.length>0&&c.length>0){let f=await ys(t,l,c,n);if(f.length>0){let u=new Set(f.map(h=>h.oldPath)),d=new Set(f.map(h=>h.newPath));l=l.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...f)}}if(l.length>0&&c.length>0){let f=await ws(t,l,c,n);if(f.length>0){let u=new Set(f.map(h=>h.oldPath)),d=new Set(f.map(h=>h.newPath));l=l.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...f)}}return{remaining:[...o,...l,...c],renames:a}}async function ys(t,e,n,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let l=Ee(c.path);s.has(l)?s.set(l,-1):s.set(l,a)}let i=new Map;for(let a=0;a<n.length;a++){let c=n[a];if(!c)continue;let l=Ee(c.path);i.has(l)?i.set(l,-1):i.set(l,a)}let o=[];for(let[a,c]of s){if(c===-1)continue;let l=i.get(a);if(l===void 0||l===-1)continue;let f=e[c],u=n[l];if(!f?.oldHash||!u?.newHash||f.oldHash===u.newHash)continue;let d=await ne(t,f.oldHash),h=await ne(t,u.newHash),m=bs(d,h);m<r||o.push({oldPath:f.path,newPath:u.path,oldHash:f.oldHash,newHash:u.newHash,similarity:m,oldMode:f.oldMode,newMode:u.newMode})}return o}var bn=107927;function Ke(t){let e=new Map,n=0,r=0,s=0;for(let o=0;o<t.length;o++){let a=t[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let l=(r+Math.imul(s,97))%bn;e.set(l,(e.get(l)??0)+n),n=0,r=0,s=0}if(n>0){let o=(r+Math.imul(s,97))%bn;e.set(o,(e.get(o)??0)+n)}let i=[];for(let[o,a]of e)i.push({hash:o,count:a});return i.sort((o,a)=>o.hash-a.hash),i}function gs(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let o=t[s];if(!o)break;for(;i<e.length;){let l=e[i];if(!l||l.hash>=o.hash)break;r+=l.count,i++}let a=o.count,c=0;if(i<e.length){let l=e[i];l&&l.hash===o.hash&&(c=l.count,i++)}a<c?(r+=c-a,n+=a):n+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:n,literalAdded:r}}function bs(t,e){return t.length===0&&e.length===0?100:t.length===0||e.length===0?0:wn(t.length,Ke(t),e.length,Ke(e))}function wn(t,e,n,r){let s=Math.max(t,n),i=Math.min(t,n);if(i<s-i)return 0;let{srcCopied:o}=gs(e,r);return Math.floor(o*100/s)}async function ws(t,e,n,r){let s=[];for(let f of e)if(f.oldHash){let u=await ne(t,f.oldHash);s.push({size:u.length,chunks:Ke(u)})}else s.push(null);let i=[];for(let f of n)if(f.newHash){let u=await ne(t,f.newHash);i.push({size:u.length,chunks:Ke(u)})}else i.push(null);let o=[];for(let f=0;f<e.length;f++){let u=e[f],d=s[f];if(!(!u||!d))for(let h=0;h<n.length;h++){let m=n[h],y=i[h];if(!m||!y)continue;let p=wn(d.size,d.chunks,y.size,y.chunks);if(p>=r){let b=Ee(u.path)===Ee(m.path)?1:0;o.push({similarity:p,nameScore:b,delIdx:f,addIdx:h})}}}o.sort((f,u)=>u.similarity-f.similarity||u.nameScore-f.nameScore);let a=new Set,c=new Set,l=[];for(let{similarity:f,delIdx:u,addIdx:d}of o){if(a.has(u)||c.has(d))continue;a.add(u),c.add(d);let h=e[u],m=n[d];!h||!m||l.push({oldPath:h.path,newPath:m.path,oldHash:h.oldHash??"",newHash:m.newHash??"",similarity:f,oldMode:h.oldMode,newMode:m.newMode})}return l}async function fe(t,e,n){return(await ce(t,e)).get(n)?.hash??null}async function In(t,e,n,r){let s=await ie(t,e,n);if(!s.find(c=>c.status==="added"&&c.path===r))return null;let{renames:o}=await de(t,s);return o.find(c=>c.newPath===r)?.oldPath??null}async function Is(t,e,n,r,s,i){let o=await fe(t,(await A(t,e)).tree,n);if(!o){let y=new Map,p=await A(t,e);for(let b of r)y.set(b.finalIdx,ue(e,n,b.currentLine,i+b.finalIdx,s[b.finalIdx],p,!1,void 0));return y}let a=await H(t,o),c=ee(a),l=new Array(s.length),f=[...r],u=e,d=n,h=c;for(;f.length>0;){let y=await A(t,u);if(y.parents.length===0){for(let E of f)l[E.finalIdx]=ue(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],y,!0,void 0);break}let p=await fe(t,y.tree,d),b=null,R=[];for(let E of y.parents){let P=await A(t,E),T=d,$=await fe(t,P.tree,T);if(!$){let D=await In(t,P.tree,y.tree,d);D&&(T=D,$=await fe(t,P.tree,T))}if($&&(R.push({hash:E,path:T,blobHash:$}),$===p)){b={hash:E,path:T};break}}if(b){u=b.hash,d=b.path;continue}if(R.length===0){for(let E of f)l[E.finalIdx]=ue(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],y,!1,void 0);break}let v=R[0],j=await H(t,v.blobHash),O=ee(j),w=Ie(O,h),x=new Map;for(let E of w)E.type==="keep"&&x.set(E.newLineNo,E.oldLineNo);let S=[];for(let E of f){let P=x.get(E.currentLine);P!==void 0?S.push({finalIdx:E.finalIdx,currentLine:P}):l[E.finalIdx]=ue(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],y,!1,{hash:v.hash,path:v.path})}f=S,u=v.hash,d=v.path,h=O}let m=new Map;for(let y of r)l[y.finalIdx]&&m.set(y.finalIdx,l[y.finalIdx]);return m}async function En(t,e,n,r){let s=await A(t,e),i=await fe(t,s.tree,n);if(!i)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let o=await H(t,i),a=ee(o),c=r?.startLine??1,l=r?.endLine??a.length,f=a.slice(c-1,l),u=new Array(f.length),d=f.map((p,b)=>({finalIdx:b,currentLine:c+b})),h=e,m=n,y=a;for(;d.length>0;){let p=await A(t,h);if(p.parents.length===0){for(let x of d)u[x.finalIdx]=ue(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!0,void 0);break}let b=await fe(t,p.tree,m),R=[],v=null;for(let x of p.parents){let S=await A(t,x),E=m,P=await fe(t,S.tree,E);if(!P){let T=await In(t,S.tree,p.tree,m);T&&(E=T,P=await fe(t,S.tree,E))}if(P){let T={hash:x,path:E,blobHash:P};if(R.push(T),P===b){v=T;break}}}if(v){h=v.hash,m=v.path;continue}if(R.length===0){for(let x of d)u[x.finalIdx]=ue(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!1,void 0);break}if(R.length===1){let x=R[0],S=await H(t,x.blobHash),E=ee(S),P=Ie(E,y),T=new Map;for(let D of P)D.type==="keep"&&T.set(D.newLineNo,D.oldLineNo);let $=[];for(let D of d){let oe=T.get(D.currentLine);oe!==void 0?$.push({finalIdx:D.finalIdx,currentLine:oe}):u[D.finalIdx]=ue(h,m,D.currentLine,c+D.finalIdx,f[D.finalIdx],p,!1,{hash:x.hash,path:x.path})}d=$,h=x.hash,m=x.path,y=E;continue}let j=[];for(let x of R){let S=await H(t,x.blobHash),E=ee(S),P=Ie(E,y),T=new Map;for(let $ of P)$.type==="keep"&&T.set($.newLineNo,$.oldLineNo);j.push({info:x,newToOld:T})}let O=new Map;for(let x of d){let S=!1;for(let E=0;E<j.length;E++){let P=j[E],T=P.newToOld.get(x.currentLine);if(T!==void 0){let $=O.get(E);$||($={info:P.info,lines:[]},O.set(E,$)),$.lines.push({finalIdx:x.finalIdx,currentLine:T}),S=!0;break}}S||(u[x.finalIdx]=ue(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!1,{hash:R[0].hash,path:R[0].path}))}let w=O.get(0);for(let[x,S]of O){if(x===0)continue;let E=await Is(t,S.info.hash,S.info.path,S.lines,f,c);for(let[P,T]of E)u[P]=T}if(w&&w.lines.length>0){d=w.lines,h=w.info.hash,m=w.info.path;let x=await H(t,w.info.blobHash);y=ee(x)}else break}return u}function ue(t,e,n,r,s,i,o,a){return{hash:t,origPath:e,origLine:n,finalLine:r,content:s,author:i.author,committer:i.committer,summary:i.message.split(`
12
+ `)[0],boundary:o,previous:a}}var xe=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),o<r&&this.higher(n[o],n[s])&&(s=o),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*me(t,e,n){if(n?.topoOrder){yield*Es(t,e,n);return}let r=await On(t,n?.exclude),s=new Set(r),i=new xe,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let c of a)s.has(c)||i.push(await Ye(t,c));for(;i.size>0;){let c=i.pop();if(s.has(c.hash)||(s.add(c.hash),yield c,o?.has(c.hash)))continue;let l=n?.firstParent?c.commit.parents.slice(0,1):c.commit.parents;for(let f of l)if(!s.has(f))try{i.push(await Ye(t,f))}catch{}}}async function*Es(t,e,n){let r=await On(t,n?.exclude),s=new Set(r),i=new xe,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let h of a)s.has(h)||i.push(await Ye(t,h));let c=[],l=new Map;for(;i.size>0;){let h=i.pop();if(s.has(h.hash)||(s.add(h.hash),l.set(h.hash,c.length),c.push(h),o?.has(h.hash)))continue;let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let y of m)if(!s.has(y))try{i.push(await Ye(t,y))}catch{}}let f=c.length;if(f===0)return;let u=new Int32Array(f);for(let h of c){let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let y of m){let p=l.get(y);p!==void 0&&(u[p]=(u[p]??0)+1)}}let d=[];for(let h=f-1;h>=0;h--)u[h]===0&&d.push(h);for(;d.length>0;){let h=d.pop();yield c[h];let m=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let y of m){let p=l.get(y);if(p!==void 0){let b=(u[p]??0)-1;u[p]=b,b===0&&d.push(p)}}}}async function xn(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let a of me(t,e))r.add(a.hash);let s=new Set;for await(let a of me(t,n))s.add(a.hash);let i=0;for(let a of r)s.has(a)||i++;let o=0;for(let a of s)r.has(a)||o++;return{ahead:i,behind:o}}async function On(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of me(t,e))n.add(r.hash);return n}async function Ye(t,e){return{hash:e,commit:await A(t,e)}}async function xs(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let o;try{o=await A(t,i)}catch{continue}for(let a of o.parents)n.has(a)||r.push(a)}return n}async function mt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let o=s[i++];if(o===e)return!0;if(r.has(o))continue;r.add(o);let a;try{a=await A(t,o)}catch{continue}for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function $e(t,e,n){if(e===n)return[e];let r=await xs(t,e),s=[],i=new Set,o=[n],a=0;for(;a<o.length;){let l=o[a++];if(i.has(l))continue;if(i.add(l),r.has(l)){s.push(l);continue}let f;try{f=await A(t,l)}catch{continue}for(let u of f.parents)i.has(u)||o.push(u)}if(s.length<=1)return s;let c=[];for(let l of s){let f=!1;for(let u of s)if(u!==l&&await mt(t,l,u)){f=!0;break}f||c.push(l)}return c.length<=1?c:Os(t,e,n,c)}async function Os(t,e,n,r){let s=new Set(r),i=new Set,o=[],a=new Map,c=new Map,l=0,f=[{hash:e,mask:1,seq:l++},{hash:n,mask:2,seq:l++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await A(t,d)).committer.timestamp;return c.set(d,m),m}for(;f.length>0;){let d=0,h=await u(f[0].hash);for(let R=1;R<f.length;R++){let v=f[R],j=await u(v.hash),O=f[d];(j>h||j===h&&v.seq<O.seq)&&(d=R,h=j)}let m=f.splice(d,1)[0],y=a.get(m.hash)??0,p=y|m.mask;if(p===y)continue;if(a.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let b=await A(t,m.hash);for(let R of b.parents)f.push({hash:R,mask:p,seq:l++})}for(let d of r)i.has(d)||o.push(d);return o}async function Rs(t,e){return J(t,e)}async function Ps(t,e,n){return ie(t,e,n)}async function ks(t,e,n){let r=await A(t,n),s=null;return e&&(s=(await A(t,e)).tree),ie(t,s,r.tree)}async function*Ts(t,e,n){let r=e?[e]:[];for await(let s of me(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 Ss(t,e,n){return mt(t,e,n)}async function Cs(t,e,n){return $e(t,e,n)}async function vs(t,e,n){return xn(t,e,n)}async function js(t,e,n,r){return En(t,e,n,r)}function As(t){return t==="insert"?"+":t==="delete"?"-":" "}function $s(t){return{oldStart:t.oldStart,oldCount:t.oldCount,newStart:t.newStart,newCount:t.newCount,lines:t.lines.map(e=>As(e.type)+e.content)}}function Rn(t,e,n){let r=ee(t),s=ee(e),i=Ie(r,s);return gn(i,n).map($s)}async function Pn(t,e){let n=await Fe(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function Ls(t,e,n,r){let s=await Pn(t,e),i=await Pn(t,n),o=await A(t,s),a=await A(t,i),c=await ie(t,o.tree,a.tree),l=r?.renames!==!1,f=r?.contextLines,u=r?.paths,d=[];if(l){let m=await de(t,c);c=m.remaining,d=m.renames}let h=[];for(let m of c){if(u&&!u.some(R=>m.path.startsWith(R)))continue;let y=m.oldHash?await H(t,m.oldHash):"",p=m.newHash?await H(t,m.newHash):"",b=Rn(y,p,f);h.push({path:m.path,status:m.status,hunks:b})}for(let m of d){if(u&&!u.some(R=>m.newPath.startsWith(R)||m.oldPath.startsWith(R)))continue;let y=await H(t,m.oldHash),p=await H(t,m.newHash),b=Rn(y,p,f);h.push({path:m.newPath,status:"renamed",oldPath:m.oldPath,similarity:m.similarity,hunks:b})}return h.sort((m,y)=>m.path.localeCompare(y.path)),h}async function*Ms(t,e,n){if(n?.paths&&n.paths.length>0){yield*Ds(t,e,n.paths,n);return}for await(let r of me(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*Ds(t,e,n,r){let s=new Set;if(r?.exclude)for await(let l of me(t,r.exclude))s.add(l.hash);let i=new Set(s),o=new xe,a=async l=>{if(!i.has(l))try{let f=await A(t,l);o.push({hash:l,commit:f})}catch{}},c=Array.isArray(e)?e:[e];for(let l of c)await a(l);for(;o.size>0;){let l=o.pop();if(i.has(l.hash))continue;i.add(l.hash);let{commit:f}=l,u=r?.firstParent?f.parents.slice(0,1):f.parents,d=()=>({hash:l.hash,message:f.message,tree:f.tree,parents:f.parents,author:f.author,committer:f.committer});if(u.length===0){(await ie(t,null,f.tree)).some(y=>pt(y.path,n))&&(yield d());continue}if(u.length===1){let m=u[0];try{let y=await A(t,m);(await ie(t,y.tree,f.tree)).some(b=>pt(b.path,n))&&(yield d())}catch{yield d()}await a(m);continue}let h=[];for(let m of u)try{let y=await A(t,m);(await ie(t,y.tree,f.tree)).some(b=>pt(b.path,n))||h.push(m)}catch{}if(h.length>0)await a(h[0]);else{yield d();for(let m of u)await a(m)}}}async function Hs(t,e){let n=Ne({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message}),r=await _(t,"commit",n);if(e.branch){let s=`refs/heads/${e.branch}`;await t.refStore.writeRef(s,{type:"direct",hash:r}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:s})}return r}async function Us(t,e){let n=[...e].sort((i,o)=>i.name.localeCompare(o.name)),r=await Promise.all(n.map(async i=>{let o=i.mode;return o||(o=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:o,name:i.name,hash:i.hash}})),s=Ge({type:"tree",entries:r});return _(t,"tree",s)}async function Ns(t,e){return _(t,"blob",new TextEncoder().encode(e))}function yt(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}=dt(t,e);return Bs(s,n,i,r)}function Bs(t,e,n,r){let s=[],i=0,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!t[i]&&!n[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&t[i];)i++;for(;o<r&&n[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function Fs(t,e,n){let r=[];for(let c of yt(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 yt(e,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,l)=>c.oStart-l.oStart);let s=[],i=0;function o(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let a=0;for(;a<r.length;){let c=r[a++],l=c.oStart,f=c.oStart+c.oLength,u=[c];for(o(l);a<r.length;){let d=r[a];if(d.oStart>f)break;f=Math.max(f,d.oStart+d.oLength),u.push(d),a++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?t:n;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:d.slice(c.abStart,c.abStart+c.abLength)})}}else{let d={a:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let b of u){let R=b.oStart,v=R+b.oLength,j=b.abStart,O=j+b.abLength,w=d[b.ab];w.abMin=Math.min(j,w.abMin),w.abMax=Math.max(O,w.abMax),w.oMin=Math.min(R,w.oMin),w.oMax=Math.max(v,w.oMax)}let h=d.a.abMin+(l-d.a.oMin),m=d.a.abMax+(f-d.a.oMax),y=d.b.abMin+(l-d.b.oMin),p=d.b.abMax+(f-d.b.oMax);s.push({stable:!1,a:t.slice(h,m),o:e.slice(l,f),b:n.slice(y,p)})}i=f}return o(e.length),s}function Gs(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=Fs(t,e,n),o=[],a=[];function c(){a.length&&(o.push({type:"ok",lines:a}),a=[])}for(let l of i)l.stable?a.push(...l.content):s&&Tn(l.a,l.b)?a.push(...l.a):(c(),o.push({type:"conflict",a:l.a,o:l.o,b:l.b}));return c(),r?.conflictStyle==="diff3"?kn(o):kn(_s(o))}function Le(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",o=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),l=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,f=Gs(t,e,n,{conflictStyle:i}),u=!1,d=[];for(let h of f)h.type==="ok"?d.push(...h.lines):(u=!0,i==="diff3"?d.push(o,...h.a,a,...h.o,c,...h.b,l):d.push(o,...h.a,c,...h.b,l));return{conflict:u,result:d}}function _s(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...Ws(n));return e}function Ws(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(Tn(e,n))return[t];let r=yt(e,n);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let a of r){let c=a.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let f=c+a.buffer1[1],u=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:e.slice(c,f),o:[],b:n.slice(a.buffer2[0],u)}),i=f}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[t]:s}function kn(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.length-1],i=e[r];if(s.type==="conflict"&&i.type==="ok"&&i.lines.length<=3&&r+1<e.length&&e[r+1].type==="conflict"){let o=e[r+1],a=s;a.a=[...s.a,...i.lines,...o.a],a.b=[...s.b,...i.lines,...o.b],a.o=[...s.o,...i.lines,...o.o],r++}else n.push(i)}return n}function pe(t,e,n,r){let s=Le(Y(t),Y(e),Y(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(gt);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
13
13
  `)}
14
14
  `:a.join(`
15
15
  `)}function Y(t){if(t==="")return[];let e=t.split(`
16
- `);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function gt(t){return t.endsWith("\0")?t.slice(0,-1):t}function Tn(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 Oe=new TextDecoder,he=new TextEncoder,Sn={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function Re(t,e,n,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await zs(t,e,n,r),l=await Ks(t,i,o,a,c,s);return Ys(t,i,s,l)}async function Mn(t,e,n,r){let s=await $e(t,e,n),i=await A(t,e),o=await A(t,n);if(s.length===0)return{...await Re(t,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let l=await A(t,s[0]);return{...await Re(t,l.tree,i.tree,o.tree,r),baseTree:l.tree}}let a=await Hn(t,e,n,s,1);return{...await Re(t,a,i.tree,o.tree,r),baseTree:a}}async function zs(t,e,n,r){let s=await ce(t,e),i=await ce(t,n),o=await ce(t,r),a=new Set;for(let l of s.keys())a.add(l);for(let l of i.keys())a.add(l);for(let l of o.keys())a.add(l);let c=new Map;for(let l of a){let f=s.get(l)??null,u=i.get(l)??null,d=o.get(l)??null,h=f?{hash:f.hash,mode:f.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,y=d?{hash:d.hash,mode:d.mode}:null,p=(f?1:0)|(u?2:0)|(d?4:0),b=f?.hash??null,R=u?.hash??null,j=d?.hash??null,v=0;b!==null&&b===R&&(v|=3),b!==null&&b===j&&(v|=5),R!==null&&R===j&&(v|=6);let O={path:l,stages:[h,m,y],pathnames:[l,l,l],filemask:p,matchMask:v,merged:{result:null,clean:!1},pathConflict:!1};if(Vs(O)){c.set(l,O);continue}c.set(l,O)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function Vs(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,o=r?.hash??null;return i===s&&o===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===o&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&o===null?(t.merged={result:null,clean:!0},!0):o===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?t.merged={result:{hash:o,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function Ks(t,e,n,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[I,g]of n)r.has(I)||a.push({path:I,status:"deleted",oldHash:g.hash,oldMode:g.mode}),s.has(I)||c.push({path:I,status:"deleted",oldHash:g.hash,oldMode:g.mode});for(let[I,g]of r)n.has(I)||a.push({path:I,status:"added",newHash:g.hash,newMode:g.mode});for(let[I,g]of s)n.has(I)||c.push({path:I,status:"added",newHash:g.hash,newMode:g.mode});let l=await de(t,a),f=await de(t,c);if(l.renames.length===0&&f.renames.length===0)return o;let u=new Map,d=new Map;for(let I of l.renames)u.set(I.oldPath,I);for(let I of f.renames)d.set(I.oldPath,I);let h=new Set;for(let[I]of r)!n.has(I)&&s.has(I)&&h.add(I);let m=new Set,y=i?.a??"HEAD",p=i?.b??"theirs";function b(I,g,k=0){o.msgBuf.push({sortKey:I,subOrder:k,text:g})}for(let I of[...n.keys()].sort()){let g=u.get(I),k=d.get(I);if(!g&&!k)continue;let M=n.get(I);if(m.add(I),g&&k)if(m.add(g.newPath),m.add(k.newPath),g.newPath===k.newPath){let L=r.get(g.newPath),C=s.get(k.newPath);if(L.hash===C.hash)o.entries.push(V(g.newPath,L));else{let N=bt(e,g.newPath);N.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],N.pathnames=[I,g.newPath,k.newPath],N.filemask=7,N.merged={result:null,clean:!1}}}else{let L=r.get(g.newPath),C=s.get(k.newPath),N=await Dn(t,M,L,C,i);N.conflict&&b(I,`Auto-merging ${I}`,-1),o.conflicts.push({path:I,reason:"rename-rename",oursPath:g.newPath,theirsPath:k.newPath}),b(I,`CONFLICT (rename/rename): ${I} renamed to ${g.newPath} in ${y} and to ${k.newPath} in ${p}.`),o.entries.push(V(I,M,1)),o.entries.push(G(g.newPath,L.mode,N.hash,2)),o.entries.push(G(k.newPath,C.mode,N.hash,3)),o.worktreeBlobs.set(g.newPath,{hash:N.hash,mode:L.mode}),o.worktreeBlobs.set(k.newPath,{hash:N.hash,mode:C.mode})}else if(g){m.add(g.newPath);let L=s.get(I),C=r.get(g.newPath),N=h.has(g.newPath);if(L)if(N)await Ln(t,o,g.newPath,I,M,C,L,r,s,!1,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(V(g.newPath,C));else if(L.hash===M.hash)o.entries.push(V(g.newPath,C));else if(C.hash===M.hash)o.entries.push(G(g.newPath,C.mode,L.hash));else{let B=bt(e,g.newPath);B.stages=[{hash:M.hash,mode:M.mode},{hash:C.hash,mode:C.mode},{hash:L.hash,mode:L.mode}],B.pathnames=[I,g.newPath,I],B.filemask=7,B.merged={result:null,clean:!1}}else{let B=s.get(g.newPath);if(o.conflicts.push({path:g.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:I}),b(g.newPath,`CONFLICT (rename/delete): ${I} renamed to ${g.newPath} in ${y}, but deleted in ${p}.`),B){o.conflicts.push({path:g.newPath,reason:"add-add"}),b(g.newPath,`Auto-merging ${g.newPath}`,0),b(g.newPath,`CONFLICT (add/add): Merge conflict in ${g.newPath}`,1),o.entries.push(V(g.newPath,C,2)),o.entries.push(V(g.newPath,B,3));let Ze=await qe(t,C.hash,B.hash,C.mode,i);o.worktreeBlobs.set(g.newPath,{hash:Ze,mode:C.mode})}else o.entries.push(G(g.newPath,M.mode,M.hash,1)),o.entries.push(V(g.newPath,C,2)),o.worktreeBlobs.set(g.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&b(g.newPath,`CONFLICT (modify/delete): ${g.newPath} deleted in ${p} and modified in ${y}. Version ${y} of ${g.newPath} left in tree.`,1)}}else if(k){m.add(k.newPath);let L=r.get(I),C=s.get(k.newPath),N=h.has(k.newPath);if(L)if(N)await Ln(t,o,k.newPath,I,M,L,C,r,s,!0,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(V(k.newPath,C));else if(L.hash===M.hash)o.entries.push(V(k.newPath,C));else if(C.hash===M.hash)o.entries.push(G(k.newPath,C.mode,L.hash));else{let B=bt(e,k.newPath);B.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],B.pathnames=[I,I,k.newPath],B.filemask=7,B.merged={result:null,clean:!1}}else{let B=r.get(k.newPath);if(o.conflicts.push({path:k.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:I}),b(k.newPath,`CONFLICT (rename/delete): ${I} renamed to ${k.newPath} in ${p}, but deleted in ${y}.`),B){o.conflicts.push({path:k.newPath,reason:"add-add"}),b(k.newPath,`Auto-merging ${k.newPath}`,0),b(k.newPath,`CONFLICT (add/add): Merge conflict in ${k.newPath}`,1),o.entries.push(V(k.newPath,B,2)),o.entries.push(V(k.newPath,C,3));let Ze=await qe(t,B.hash,C.hash,B.mode,i);o.worktreeBlobs.set(k.newPath,{hash:Ze,mode:B.mode})}else o.entries.push(G(k.newPath,M.mode,M.hash,1)),o.entries.push(V(k.newPath,C,3)),o.worktreeBlobs.set(k.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&b(k.newPath,`CONFLICT (modify/delete): ${k.newPath} deleted in ${y} and modified in ${p}. Version ${p} of ${k.newPath} left in tree.`,1)}}}let R=new Set(l.renames.map(I=>I.newPath)),j=new Set(f.renames.map(I=>I.newPath)),v=Cn(n,r),O=Cn(n,s),w=jn(v,s,n),x=jn(O,r,n),S=vn(l.renames,w),E=vn(f.renames,x),P=An(S),T=An(E);for(let I of[...P.keys()])T.has(I)&&(P.delete(I),T.delete(I));let $=new Set(P.keys()),D=new Set(T.keys());if(T.size>0)for(let I of a){if(I.status!=="added"||R.has(I.path))continue;let g=$n(I.path,T,$);if(!g)continue;if(e.has(g)||n.has(g)||r.has(g)||s.has(g)){if(r.has(g)){b(g,`CONFLICT (implicit dir rename): Existing file/dir at ${g} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let L=r.get(I.path),C=s.get(g)??n.get(g);o.entries.push(G(g,L.mode,L.hash,2)),C&&o.entries.push(G(g,C.mode,C.hash,3)),o.worktreeBlobs.set(g,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:g,reason:"add-add"}),b(g,`CONFLICT (file location): ${I.path} added in ${y} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${g}.`,1);let N=e.get(I.path);N&&(N.merged={result:null,clean:!0}),m.add(I.path);continue}let k=r.get(I.path);o.entries.push(G(g,k.mode,k.hash,2)),o.worktreeBlobs.set(g,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:g,reason:"directory-rename"}),b(g,`CONFLICT (file location): ${I.path} added in ${y} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${g}.`,1);let M=e.get(I.path);M&&(M.merged={result:null,clean:!0}),m.add(I.path)}if(P.size>0)for(let I of c){if(I.status!=="added"||j.has(I.path))continue;let g=$n(I.path,P,D);if(!g)continue;if(e.has(g)||n.has(g)||r.has(g)||s.has(g)){if(s.has(g)){b(g,`CONFLICT (implicit dir rename): Existing file/dir at ${g} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let L=s.get(I.path),C=r.get(g)??n.get(g);C&&o.entries.push(G(g,C.mode,C.hash,2)),o.entries.push(G(g,L.mode,L.hash,3)),o.worktreeBlobs.set(g,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:g,reason:"add-add"}),b(g,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${g}.`,1);let N=e.get(I.path);N&&(N.merged={result:null,clean:!0}),m.add(I.path);continue}let k=s.get(I.path);o.entries.push(G(g,k.mode,k.hash,3)),o.worktreeBlobs.set(g,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:g,reason:"directory-rename"}),b(g,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${g}.`,1);let M=e.get(I.path);M&&(M.merged={result:null,clean:!0}),m.add(I.path)}let oe=new Set(o.entries.map(I=>I.path));for(let I of oe){let g=e.get(I);g&&(g.merged={result:null,clean:!0})}for(let I of m){if(oe.has(I))continue;let g=e.get(I);if(!g||g.merged.clean)continue;g.filemask===7&&!g.pathConflict||(g.merged={result:null,clean:!0})}return o}function Cn(t,e){let n=new Set;for(let i of t.keys()){let o=q(i);for(;o;)n.add(o),o=q(o)}let r=new Set;for(let i of e.keys()){let o=q(i);for(;o;)r.add(o),o=q(o)}let s=new Set;for(let i of n)r.has(i)||s.add(i);return s}function jn(t,e,n){if(t.size===0)return t;let r=new Set;for(let s of e.keys()){if(n.has(s))continue;let i=q(s)??"";t.has(i)&&r.add(i)}for(let s of[...r]){let i=q(s);for(;i;)t.has(i)&&!r.has(i)&&r.add(i),i=q(i)}return r}function vn(t,e){let n=new Map;for(let r of t){let s=q(r.oldPath),i=q(r.newPath),o=!0;for(;;){if(!o){let a=s.length+(s?1:0),c=i.length+(i?1:0),l=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),f=r.newPath.slice(c,r.newPath.indexOf("/",c));if(l!==f)break}if(e.has(s)){let a=n.get(s);a||(a=new Map,n.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=q(s),i=q(i)}}return n}function An(t){let e=new Map;for(let[n,r]of t){let s=0,i=0,o=null;for(let[a,c]of r)c===s?i=s:c>s&&(s=c,o=a);s>0&&i!==s&&o!==null&&e.set(n,o)}return e}function $n(t,e,n){let r=q(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let o=t.slice(r.length+1);return i?`${i}/${o}`:o}r=q(r)}let s=e.get("");return s!==void 0&&!n.has(s)?`${s}/${t}`:null}function q(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function Ln(t,e,n,r,s,i,o,a,c,l=!1,f){let u=l?a.get(n):c.get(n),d=l?o:i;if(u.hash===d.hash){e.entries.push(G(n,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await Dn(t,s,i,o,f,l?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(G(n,u.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),l){e.entries.push(V(n,u,2)),e.entries.push(G(n,o.mode,m.hash,3));let y=await qe(t,u.hash,m.hash,u.mode,f);e.worktreeBlobs.set(n,{hash:y,mode:u.mode})}else{e.entries.push(G(n,i.mode,m.hash,2)),e.entries.push(V(n,u,3));let y=await qe(t,m.hash,u.hash,i.mode,f);e.worktreeBlobs.set(n,{hash:y,mode:i.mode})}}async function Dn(t,e,n,r,s,i,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(se(e.mode)||se(n.mode)||se(r.mode))return{hash:n.hash,conflict:!0};let a=await H(t,e.hash),c=await H(t,n.hash),l=await H(t,r.hash);if(te(c)||te(l)||te(a))return{hash:n.hash,conflict:!0};let f=Y(a),u=Y(c),d=Y(l),h=s?.conflictStyle,m=Le(u,f,d,{conflictStyle:h});if(!m.conflict)return{hash:await wt(t,m.result),conflict:!1};let y=s?.a??"HEAD",p=s?.b??"theirs",b=i?.oursPath?`${y}:${i.oursPath}`:y,R=i?.theirsPath?`${p}:${i.theirsPath}`:p,j=pe(c,a,l,{a:b,b:R,markerSize:o??7,conflictStyle:h});return{hash:await _(t,"blob",he.encode(j)),conflict:!0}}async function qe(t,e,n,r,s){let i=await H(t,e),o=await H(t,n),a=pe(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return _(t,"blob",he.encode(a))}function V(t,e,n=0){return G(t,e.mode,e.hash,n)}function G(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:ae()}}async function Ys(t,e,n,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,y=0){o.push({sortKey:h,subOrder:y,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(U(h,m.merged.result.hash,m.merged.result.mode));continue}await qs(t,m,n,s,i,c,a)}o.sort((h,m)=>(h.sortKey<m.sortKey?-1:h.sortKey>m.sortKey?1:0)||h.subOrder-m.subOrder);let l=o.map(h=>h.text),f=[],u=new Set;for(let h of s)h.stage===0&&(f.push(h),u.add(h.path));for(let[h,m]of a)u.has(h)||f.push(U(h,m.hash,m.mode));f.sort((h,m)=>ve(h.path,m.path));let d=await lt(t,f);return{entries:s,conflicts:i,messages:l,resultTree:d}}async function qs(t,e,n,r,s,i,o){let a=e.path,[c,l,f]=e.stages,u=c?.hash??null,d=l?.hash??null,h=f?.hash??null;if(d===null&&h!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=n?.a??"HEAD",y=n?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(U(a,u,c.mode,1)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:h,mode:f.mode});return}if(h===null&&d!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=n?.b??"theirs",y=n?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),o.set(a,{hash:d,mode:l.mode});return}if(u===null&&d!==null&&h!==null){if(d===h){r.push(U(a,d,l.mode));return}i(a,`Auto-merging ${a}`,0);let m=await H(t,d),y=await H(t,h);if(te(m)||te(y)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let p=Y(""),b=Y(m),R=Y(y),j=Le(b,p,R,{conflictStyle:n?.conflictStyle});if(!j.conflict){let w=await wt(t,j.result);r.push(U(a,w,l.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3));let v=pe(m,"",y,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),O=await _(t,"blob",he.encode(v));o.set(a,{hash:O,mode:l.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(U(a,h,f.mode));return}if(h===u){r.push(U(a,d,l.mode));return}if(d===h){r.push(U(a,d,l.mode));return}if(i(a,`Auto-merging ${a}`,0),se(c.mode)||se(l.mode)||se(f.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let m=await H(t,u),y=await H(t,d),p=await H(t,h);if(te(y)||te(p)||te(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let b=Y(m),R=Y(y),j=Y(p),v=Le(R,b,j,{conflictStyle:n?.conflictStyle});if(v.conflict){let O=e.pathnames[1],w=e.pathnames[2],x=O!==a||w!==a,S={path:a,reason:"content"};x&&(O!==a&&(S.oursOrigPath=O),w!==a&&(S.theirsOrigPath=w)),s.push(S),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3));let E=x?`${n?.a??"HEAD"}:${O}`:n?.a??"HEAD",P=x?`${n?.b??"theirs"}:${w}`:n?.b??"theirs",T=pe(y,m,p,{a:E,b:P,conflictStyle:n?.conflictStyle}),$=await _(t,"blob",he.encode(T));o.set(a,{hash:$,mode:l.mode})}else{let O=await wt(t,v.result);r.push(U(a,O,l.mode))}return}}var Xs=200;async function Hn(t,e,n,r,s){let i=await Promise.all(r.map(async f=>({hash:f,timestamp:(await A(t,f)).committer.timestamp})));i.sort((f,u)=>f.timestamp-u.timestamp);let o=i.map(f=>f.hash),a=o[0],c=a,l=(await A(t,a)).tree;for(let f=1;f<o.length;f++){let u=o[f],d=(await A(t,u)).tree,h=null;if(s>=Xs)h=l;else{let p=await $e(t,c,u);p.length===0?h=null:p.length===1?h=(await A(t,p[0])).tree:h=await Hn(t,c,u,p,s+1)}let m=await Re(t,h,l,d);l=await Zs(t,m,s);let y=Ne({type:"commit",tree:l,parents:[c,u],author:Sn,committer:Sn,message:"merged common ancestors"});c=await _(t,"commit",y)}return l}async function Zs(t,e,n){let r=e.entries.filter(a=>a.stage===0),s=new Map;for(let a of e.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let i=(a,c)=>s.get(`${a}\0${c}`),o={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let f=i(a.path,1);if(f){r.push({...f,stage:0});continue}}if(a.reason==="rename-rename"){let f=a.oursPath??a.path,u=a.theirsPath??a.path,d=i(a.path,1),h=i(f,2),m=i(u,3);if(h&&m){let y=Oe.decode((await W(t,h.hash)).content),p=Oe.decode((await W(t,m.hash)).content),b=d?Oe.decode((await W(t,d.hash)).content):"",R=8+n*2,j=o.a??"Temporary merge branch 1",v=o.b??"Temporary merge branch 2",O=pe(y,b,p,{a:`${j}:${f}`,o:o.o,b:`${v}:${u}`,markerSize:R}),w=await _(t,"blob",he.encode(O));r.push({path:f,mode:h.mode,hash:w,stage:0,stat:ae()}),r.push({path:u,mode:m.mode,hash:w,stage:0,stat:ae()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(a.path,2),l=i(a.path,3);if(c&&l&&(a.reason==="content"||a.reason==="add-add")){let f=Oe.decode((await W(t,c.hash)).content),u=Oe.decode((await W(t,l.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?Oe.decode((await W(t,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,y=o.a??"Temporary merge branch 1",p=o.b??"Temporary merge branch 2",b=m?`${y}:${a.oursOrigPath??a.path}`:y,R=m?`${p}:${a.theirsOrigPath??a.path}`:p,j=pe(f,h,u,{a:b,o:o.o,b:R,markerSize:o.markerSize}),v=await _(t,"blob",he.encode(j));r.push({path:a.path,mode:c.mode,hash:v,stage:0,stat:ae()})}else c?r.push({...c,stage:0}):l&&r.push({...l,stage:0})}return r.sort((a,c)=>ve(a.path,c.path)),lt(t,r)}async function wt(t,e){let n=e.map(gt);if(n.length===0)return _(t,"blob",he.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?n.join(`
16
+ `);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function gt(t){return t.endsWith("\0")?t.slice(0,-1):t}function Tn(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 Oe=new TextDecoder,he=new TextEncoder,Sn={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function Re(t,e,n,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await zs(t,e,n,r),l=await Ks(t,i,o,a,c,s);return Ys(t,i,s,l)}async function Mn(t,e,n,r){let s=await $e(t,e,n),i=await A(t,e),o=await A(t,n);if(s.length===0)return{...await Re(t,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let l=await A(t,s[0]);return{...await Re(t,l.tree,i.tree,o.tree,r),baseTree:l.tree}}let a=await Hn(t,e,n,s,1);return{...await Re(t,a,i.tree,o.tree,r),baseTree:a}}async function zs(t,e,n,r){let s=await ce(t,e),i=await ce(t,n),o=await ce(t,r),a=new Set;for(let l of s.keys())a.add(l);for(let l of i.keys())a.add(l);for(let l of o.keys())a.add(l);let c=new Map;for(let l of a){let f=s.get(l)??null,u=i.get(l)??null,d=o.get(l)??null,h=f?{hash:f.hash,mode:f.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,y=d?{hash:d.hash,mode:d.mode}:null,p=(f?1:0)|(u?2:0)|(d?4:0),b=f?.hash??null,R=u?.hash??null,v=d?.hash??null,j=0;b!==null&&b===R&&(j|=3),b!==null&&b===v&&(j|=5),R!==null&&R===v&&(j|=6);let O={path:l,stages:[h,m,y],pathnames:[l,l,l],filemask:p,matchMask:j,merged:{result:null,clean:!1},pathConflict:!1};if(Vs(O)){c.set(l,O);continue}c.set(l,O)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function Vs(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,o=r?.hash??null;return i===s&&o===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===o&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&o===null?(t.merged={result:null,clean:!0},!0):o===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?t.merged={result:{hash:o,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function Ks(t,e,n,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[I,g]of n)r.has(I)||a.push({path:I,status:"deleted",oldHash:g.hash,oldMode:g.mode}),s.has(I)||c.push({path:I,status:"deleted",oldHash:g.hash,oldMode:g.mode});for(let[I,g]of r)n.has(I)||a.push({path:I,status:"added",newHash:g.hash,newMode:g.mode});for(let[I,g]of s)n.has(I)||c.push({path:I,status:"added",newHash:g.hash,newMode:g.mode});let l=await de(t,a),f=await de(t,c);if(l.renames.length===0&&f.renames.length===0)return o;let u=new Map,d=new Map;for(let I of l.renames)u.set(I.oldPath,I);for(let I of f.renames)d.set(I.oldPath,I);let h=new Set;for(let[I]of r)!n.has(I)&&s.has(I)&&h.add(I);let m=new Set,y=i?.a??"HEAD",p=i?.b??"theirs";function b(I,g,k=0){o.msgBuf.push({sortKey:I,subOrder:k,text:g})}for(let I of[...n.keys()].sort()){let g=u.get(I),k=d.get(I);if(!g&&!k)continue;let M=n.get(I);if(m.add(I),g&&k)if(m.add(g.newPath),m.add(k.newPath),g.newPath===k.newPath){let L=r.get(g.newPath),C=s.get(k.newPath);if(L.hash===C.hash)o.entries.push(V(g.newPath,L));else{let N=bt(e,g.newPath);N.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],N.pathnames=[I,g.newPath,k.newPath],N.filemask=7,N.merged={result:null,clean:!1}}}else{let L=r.get(g.newPath),C=s.get(k.newPath),N=await Dn(t,M,L,C,i);N.conflict&&b(I,`Auto-merging ${I}`,-1),o.conflicts.push({path:I,reason:"rename-rename",oursPath:g.newPath,theirsPath:k.newPath}),b(I,`CONFLICT (rename/rename): ${I} renamed to ${g.newPath} in ${y} and to ${k.newPath} in ${p}.`),o.entries.push(V(I,M,1)),o.entries.push(G(g.newPath,L.mode,N.hash,2)),o.entries.push(G(k.newPath,C.mode,N.hash,3)),o.worktreeBlobs.set(g.newPath,{hash:N.hash,mode:L.mode}),o.worktreeBlobs.set(k.newPath,{hash:N.hash,mode:C.mode})}else if(g){m.add(g.newPath);let L=s.get(I),C=r.get(g.newPath),N=h.has(g.newPath);if(L)if(N)await Ln(t,o,g.newPath,I,M,C,L,r,s,!1,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(V(g.newPath,C));else if(L.hash===M.hash)o.entries.push(V(g.newPath,C));else if(C.hash===M.hash)o.entries.push(G(g.newPath,C.mode,L.hash));else{let B=bt(e,g.newPath);B.stages=[{hash:M.hash,mode:M.mode},{hash:C.hash,mode:C.mode},{hash:L.hash,mode:L.mode}],B.pathnames=[I,g.newPath,I],B.filemask=7,B.merged={result:null,clean:!1}}else{let B=s.get(g.newPath);if(o.conflicts.push({path:g.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:I}),b(g.newPath,`CONFLICT (rename/delete): ${I} renamed to ${g.newPath} in ${y}, but deleted in ${p}.`),B){o.conflicts.push({path:g.newPath,reason:"add-add"}),b(g.newPath,`Auto-merging ${g.newPath}`,0),b(g.newPath,`CONFLICT (add/add): Merge conflict in ${g.newPath}`,1),o.entries.push(V(g.newPath,C,2)),o.entries.push(V(g.newPath,B,3));let Ze=await qe(t,C.hash,B.hash,C.mode,i);o.worktreeBlobs.set(g.newPath,{hash:Ze,mode:C.mode})}else o.entries.push(G(g.newPath,M.mode,M.hash,1)),o.entries.push(V(g.newPath,C,2)),o.worktreeBlobs.set(g.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&b(g.newPath,`CONFLICT (modify/delete): ${g.newPath} deleted in ${p} and modified in ${y}. Version ${y} of ${g.newPath} left in tree.`,1)}}else if(k){m.add(k.newPath);let L=r.get(I),C=s.get(k.newPath),N=h.has(k.newPath);if(L)if(N)await Ln(t,o,k.newPath,I,M,L,C,r,s,!0,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(V(k.newPath,C));else if(L.hash===M.hash)o.entries.push(V(k.newPath,C));else if(C.hash===M.hash)o.entries.push(G(k.newPath,C.mode,L.hash));else{let B=bt(e,k.newPath);B.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],B.pathnames=[I,I,k.newPath],B.filemask=7,B.merged={result:null,clean:!1}}else{let B=r.get(k.newPath);if(o.conflicts.push({path:k.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:I}),b(k.newPath,`CONFLICT (rename/delete): ${I} renamed to ${k.newPath} in ${p}, but deleted in ${y}.`),B){o.conflicts.push({path:k.newPath,reason:"add-add"}),b(k.newPath,`Auto-merging ${k.newPath}`,0),b(k.newPath,`CONFLICT (add/add): Merge conflict in ${k.newPath}`,1),o.entries.push(V(k.newPath,B,2)),o.entries.push(V(k.newPath,C,3));let Ze=await qe(t,B.hash,C.hash,B.mode,i);o.worktreeBlobs.set(k.newPath,{hash:Ze,mode:B.mode})}else o.entries.push(G(k.newPath,M.mode,M.hash,1)),o.entries.push(V(k.newPath,C,3)),o.worktreeBlobs.set(k.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&b(k.newPath,`CONFLICT (modify/delete): ${k.newPath} deleted in ${y} and modified in ${p}. Version ${p} of ${k.newPath} left in tree.`,1)}}}let R=new Set(l.renames.map(I=>I.newPath)),v=new Set(f.renames.map(I=>I.newPath)),j=Cn(n,r),O=Cn(n,s),w=vn(j,s,n),x=vn(O,r,n),S=jn(l.renames,w),E=jn(f.renames,x),P=An(S),T=An(E);for(let I of[...P.keys()])T.has(I)&&(P.delete(I),T.delete(I));let $=new Set(P.keys()),D=new Set(T.keys());if(T.size>0)for(let I of a){if(I.status!=="added"||R.has(I.path))continue;let g=$n(I.path,T,$);if(!g)continue;if(e.has(g)||n.has(g)||r.has(g)||s.has(g)){if(r.has(g)){b(g,`CONFLICT (implicit dir rename): Existing file/dir at ${g} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let L=r.get(I.path),C=s.get(g)??n.get(g);o.entries.push(G(g,L.mode,L.hash,2)),C&&o.entries.push(G(g,C.mode,C.hash,3)),o.worktreeBlobs.set(g,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:g,reason:"add-add"}),b(g,`CONFLICT (file location): ${I.path} added in ${y} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${g}.`,1);let N=e.get(I.path);N&&(N.merged={result:null,clean:!0}),m.add(I.path);continue}let k=r.get(I.path);o.entries.push(G(g,k.mode,k.hash,2)),o.worktreeBlobs.set(g,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:g,reason:"directory-rename"}),b(g,`CONFLICT (file location): ${I.path} added in ${y} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${g}.`,1);let M=e.get(I.path);M&&(M.merged={result:null,clean:!0}),m.add(I.path)}if(P.size>0)for(let I of c){if(I.status!=="added"||v.has(I.path))continue;let g=$n(I.path,P,D);if(!g)continue;if(e.has(g)||n.has(g)||r.has(g)||s.has(g)){if(s.has(g)){b(g,`CONFLICT (implicit dir rename): Existing file/dir at ${g} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let L=s.get(I.path),C=r.get(g)??n.get(g);C&&o.entries.push(G(g,C.mode,C.hash,2)),o.entries.push(G(g,L.mode,L.hash,3)),o.worktreeBlobs.set(g,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:g,reason:"add-add"}),b(g,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${g}.`,1);let N=e.get(I.path);N&&(N.merged={result:null,clean:!0}),m.add(I.path);continue}let k=s.get(I.path);o.entries.push(G(g,k.mode,k.hash,3)),o.worktreeBlobs.set(g,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:g,reason:"directory-rename"}),b(g,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${g}.`,1);let M=e.get(I.path);M&&(M.merged={result:null,clean:!0}),m.add(I.path)}let oe=new Set(o.entries.map(I=>I.path));for(let I of oe){let g=e.get(I);g&&(g.merged={result:null,clean:!0})}for(let I of m){if(oe.has(I))continue;let g=e.get(I);if(!g||g.merged.clean)continue;g.filemask===7&&!g.pathConflict||(g.merged={result:null,clean:!0})}return o}function Cn(t,e){let n=new Set;for(let i of t.keys()){let o=q(i);for(;o;)n.add(o),o=q(o)}let r=new Set;for(let i of e.keys()){let o=q(i);for(;o;)r.add(o),o=q(o)}let s=new Set;for(let i of n)r.has(i)||s.add(i);return s}function vn(t,e,n){if(t.size===0)return t;let r=new Set;for(let s of e.keys()){if(n.has(s))continue;let i=q(s)??"";t.has(i)&&r.add(i)}for(let s of[...r]){let i=q(s);for(;i;)t.has(i)&&!r.has(i)&&r.add(i),i=q(i)}return r}function jn(t,e){let n=new Map;for(let r of t){let s=q(r.oldPath),i=q(r.newPath),o=!0;for(;;){if(!o){let a=s.length+(s?1:0),c=i.length+(i?1:0),l=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),f=r.newPath.slice(c,r.newPath.indexOf("/",c));if(l!==f)break}if(e.has(s)){let a=n.get(s);a||(a=new Map,n.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=q(s),i=q(i)}}return n}function An(t){let e=new Map;for(let[n,r]of t){let s=0,i=0,o=null;for(let[a,c]of r)c===s?i=s:c>s&&(s=c,o=a);s>0&&i!==s&&o!==null&&e.set(n,o)}return e}function $n(t,e,n){let r=q(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let o=t.slice(r.length+1);return i?`${i}/${o}`:o}r=q(r)}let s=e.get("");return s!==void 0&&!n.has(s)?`${s}/${t}`:null}function q(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function Ln(t,e,n,r,s,i,o,a,c,l=!1,f){let u=l?a.get(n):c.get(n),d=l?o:i;if(u.hash===d.hash){e.entries.push(G(n,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await Dn(t,s,i,o,f,l?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(G(n,u.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),l){e.entries.push(V(n,u,2)),e.entries.push(G(n,o.mode,m.hash,3));let y=await qe(t,u.hash,m.hash,u.mode,f);e.worktreeBlobs.set(n,{hash:y,mode:u.mode})}else{e.entries.push(G(n,i.mode,m.hash,2)),e.entries.push(V(n,u,3));let y=await qe(t,m.hash,u.hash,i.mode,f);e.worktreeBlobs.set(n,{hash:y,mode:i.mode})}}async function Dn(t,e,n,r,s,i,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(se(e.mode)||se(n.mode)||se(r.mode))return{hash:n.hash,conflict:!0};let a=await H(t,e.hash),c=await H(t,n.hash),l=await H(t,r.hash);if(te(c)||te(l)||te(a))return{hash:n.hash,conflict:!0};let f=Y(a),u=Y(c),d=Y(l),h=s?.conflictStyle,m=Le(u,f,d,{conflictStyle:h});if(!m.conflict)return{hash:await wt(t,m.result),conflict:!1};let y=s?.a??"HEAD",p=s?.b??"theirs",b=i?.oursPath?`${y}:${i.oursPath}`:y,R=i?.theirsPath?`${p}:${i.theirsPath}`:p,v=pe(c,a,l,{a:b,b:R,markerSize:o??7,conflictStyle:h});return{hash:await _(t,"blob",he.encode(v)),conflict:!0}}async function qe(t,e,n,r,s){let i=await H(t,e),o=await H(t,n),a=pe(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return _(t,"blob",he.encode(a))}function V(t,e,n=0){return G(t,e.mode,e.hash,n)}function G(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:ae()}}async function Ys(t,e,n,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,y=0){o.push({sortKey:h,subOrder:y,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(U(h,m.merged.result.hash,m.merged.result.mode));continue}await qs(t,m,n,s,i,c,a)}o.sort((h,m)=>(h.sortKey<m.sortKey?-1:h.sortKey>m.sortKey?1:0)||h.subOrder-m.subOrder);let l=o.map(h=>h.text),f=[],u=new Set;for(let h of s)h.stage===0&&(f.push(h),u.add(h.path));for(let[h,m]of a)u.has(h)||f.push(U(h,m.hash,m.mode));f.sort((h,m)=>je(h.path,m.path));let d=await lt(t,f);return{entries:s,conflicts:i,messages:l,resultTree:d}}async function qs(t,e,n,r,s,i,o){let a=e.path,[c,l,f]=e.stages,u=c?.hash??null,d=l?.hash??null,h=f?.hash??null;if(d===null&&h!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=n?.a??"HEAD",y=n?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(U(a,u,c.mode,1)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:h,mode:f.mode});return}if(h===null&&d!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=n?.b??"theirs",y=n?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),o.set(a,{hash:d,mode:l.mode});return}if(u===null&&d!==null&&h!==null){if(d===h){r.push(U(a,d,l.mode));return}i(a,`Auto-merging ${a}`,0);let m=await H(t,d),y=await H(t,h);if(te(m)||te(y)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let p=Y(""),b=Y(m),R=Y(y),v=Le(b,p,R,{conflictStyle:n?.conflictStyle});if(!v.conflict){let w=await wt(t,v.result);r.push(U(a,w,l.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3));let j=pe(m,"",y,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),O=await _(t,"blob",he.encode(j));o.set(a,{hash:O,mode:l.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(U(a,h,f.mode));return}if(h===u){r.push(U(a,d,l.mode));return}if(d===h){r.push(U(a,d,l.mode));return}if(i(a,`Auto-merging ${a}`,0),se(c.mode)||se(l.mode)||se(f.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let m=await H(t,u),y=await H(t,d),p=await H(t,h);if(te(y)||te(p)||te(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let b=Y(m),R=Y(y),v=Y(p),j=Le(R,b,v,{conflictStyle:n?.conflictStyle});if(j.conflict){let O=e.pathnames[1],w=e.pathnames[2],x=O!==a||w!==a,S={path:a,reason:"content"};x&&(O!==a&&(S.oursOrigPath=O),w!==a&&(S.theirsOrigPath=w)),s.push(S),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3));let E=x?`${n?.a??"HEAD"}:${O}`:n?.a??"HEAD",P=x?`${n?.b??"theirs"}:${w}`:n?.b??"theirs",T=pe(y,m,p,{a:E,b:P,conflictStyle:n?.conflictStyle}),$=await _(t,"blob",he.encode(T));o.set(a,{hash:$,mode:l.mode})}else{let O=await wt(t,j.result);r.push(U(a,O,l.mode))}return}}var Xs=200;async function Hn(t,e,n,r,s){let i=await Promise.all(r.map(async f=>({hash:f,timestamp:(await A(t,f)).committer.timestamp})));i.sort((f,u)=>f.timestamp-u.timestamp);let o=i.map(f=>f.hash),a=o[0],c=a,l=(await A(t,a)).tree;for(let f=1;f<o.length;f++){let u=o[f],d=(await A(t,u)).tree,h=null;if(s>=Xs)h=l;else{let p=await $e(t,c,u);p.length===0?h=null:p.length===1?h=(await A(t,p[0])).tree:h=await Hn(t,c,u,p,s+1)}let m=await Re(t,h,l,d);l=await Zs(t,m,s);let y=Ne({type:"commit",tree:l,parents:[c,u],author:Sn,committer:Sn,message:"merged common ancestors"});c=await _(t,"commit",y)}return l}async function Zs(t,e,n){let r=e.entries.filter(a=>a.stage===0),s=new Map;for(let a of e.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let i=(a,c)=>s.get(`${a}\0${c}`),o={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let f=i(a.path,1);if(f){r.push({...f,stage:0});continue}}if(a.reason==="rename-rename"){let f=a.oursPath??a.path,u=a.theirsPath??a.path,d=i(a.path,1),h=i(f,2),m=i(u,3);if(h&&m){let y=Oe.decode((await W(t,h.hash)).content),p=Oe.decode((await W(t,m.hash)).content),b=d?Oe.decode((await W(t,d.hash)).content):"",R=8+n*2,v=o.a??"Temporary merge branch 1",j=o.b??"Temporary merge branch 2",O=pe(y,b,p,{a:`${v}:${f}`,o:o.o,b:`${j}:${u}`,markerSize:R}),w=await _(t,"blob",he.encode(O));r.push({path:f,mode:h.mode,hash:w,stage:0,stat:ae()}),r.push({path:u,mode:m.mode,hash:w,stage:0,stat:ae()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(a.path,2),l=i(a.path,3);if(c&&l&&(a.reason==="content"||a.reason==="add-add")){let f=Oe.decode((await W(t,c.hash)).content),u=Oe.decode((await W(t,l.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?Oe.decode((await W(t,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,y=o.a??"Temporary merge branch 1",p=o.b??"Temporary merge branch 2",b=m?`${y}:${a.oursOrigPath??a.path}`:y,R=m?`${p}:${a.theirsOrigPath??a.path}`:p,v=pe(f,h,u,{a:b,o:o.o,b:R,markerSize:o.markerSize}),j=await _(t,"blob",he.encode(v));r.push({path:a.path,mode:c.mode,hash:j,stage:0,stat:ae()})}else c?r.push({...c,stage:0}):l&&r.push({...l,stage:0})}return r.sort((a,c)=>je(a.path,c.path)),lt(t,r)}async function wt(t,e){let n=e.map(gt);if(n.length===0)return _(t,"blob",he.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?n.join(`
17
17
  `):`${n.join(`
18
18
  `)}
19
- `;return _(t,"blob",he.encode(i))}function U(t,e,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:s,hash:e,stage:r,stat:ae()}}function bt(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 Js(t,e,n,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await Mn(t,e,n,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function Qs(t,e,n,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await Re(t,e,n,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}var ei=new TextEncoder,Un=new TextDecoder,Pe=16877,Fn=33188,ti=33261,Gn=40960;function K(t){let e=[];for(let n of t.split("/"))n==="."||n===""||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}function Nn(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function Bn(t){switch(t){case F.EXECUTABLE:return ti;case F.SYMLINK:return Gn;case F.DIRECTORY:return Pe;default:return Fn}}var Xe=class{constructor(e,n,r="/"){this.objectStore=e;this.rootTreeHash=n;this.rootPath=r;let s=K(r);this.overlay.set(s,{type:"directory",mode:Pe,mtime:this.epoch})}treeCache=new Map;overlay=new Map;removals=new Set;epoch=new Date(0);toRelative(e){let n=K(e),r=K(this.rootPath);if(n===r)return"";let s=r==="/"?"/":`${r}/`;return n.startsWith(s)?n.slice(s.length):null}async loadTreeDir(e){let n=this.treeCache.get(e);if(n)return n;if(e===""){let o=await this.objectStore.read(this.rootTreeHash);if(o.type!=="tree")return null;let a=Ae(o.content);return this.treeCache.set("",a.entries),a.entries}let r=e.split("/"),s=await this.loadTreeDir("");if(!s)return null;let i="";for(let o of r){let a=s.find(u=>u.name===o);if(!a||a.mode!==F.DIRECTORY)return null;i=i?`${i}/${o}`:o;let c=this.treeCache.get(i);if(c){s=c;continue}let l=await this.objectStore.read(a.hash);if(l.type!=="tree")return null;let f=Ae(l.content);this.treeCache.set(i,f.entries),s=f.entries}return s}async lookupTreeEntry(e){if(e==="")return null;let n=e.lastIndexOf("/"),r=n===-1?"":e.slice(0,n),s=n===-1?e:e.slice(n+1),i=await this.loadTreeDir(r);if(!i)return null;let o=i.find(a=>a.name===s);return o?{entry:o,dirEntries:i}:null}async isTreeDirectory(e){return e===""?!0:(await this.lookupTreeEntry(e))?.entry.mode===F.DIRECTORY}ensureOverlayParents(e){let n=Nn(e);n===K(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 Un.decode(await this.readFileBuffer(e))}async readFileBuffer(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`ENOENT: no such file or directory, open '${e}'`);let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(i.entry.mode===F.DIRECTORY)throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let o=await this.objectStore.read(i.entry.hash);if(o.type!=="blob")throw new Error(`ENOENT: no such file or directory, open '${e}'`);return o.content}async writeFile(e,n){let r=K(e);this.removals.delete(r),this.ensureOverlayParents(r),this.overlay.set(r,{type:"file",content:typeof n=="string"?ei.encode(n):new Uint8Array(n),mode:Fn,mtime:new Date})}async exists(e){let n=K(e);if(this.removals.has(n))return!1;if(this.overlay.has(n))return!0;let r=this.toRelative(n);return r===null?!1:r===""||await this.isTreeDirectory(r)?!0:await this.lookupTreeEntry(r)!==null}async stat(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:r.type==="file"?r.content.byteLength:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode: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:o}=i,a=o.mode===F.DIRECTORY,c=o.mode===F.SYMLINK,l=0;return a||(l=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:!1,mode:Bn(o.mode),size:l,mtime:this.epoch}}async lstat(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:r.type==="symlink",mode:r.mode,size:r.type==="file"?r.content.byteLength:r.type==="symlink"?r.target.length:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode: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:o}=i,a=o.mode===F.DIRECTORY,c=o.mode===F.SYMLINK,l=0;return a||(l=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:c,mode:Bn(o.mode),size:l,mtime:this.epoch}}async mkdir(e,n){let r=K(e);if(this.overlay.has(r)){if(this.overlay.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.toRelative(r);if(s!==null&&!this.removals.has(r)&&(s===""||await this.isTreeDirectory(s))){if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let i=Nn(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=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,s=this.toRelative(n);if(s!==null){let o=await this.loadTreeDir(s);if(o)for(let a of o){let c=n==="/"?`/${a.name}`:`${n}/${a.name}`;this.removals.has(c)||r.add(a.name)}}let i=n==="/"?"/":`${n}/`;for(let o of this.overlay.keys())if(o!==n&&o.startsWith(i)){let c=o.slice(i.length).split("/")[0];c&&!this.removals.has(n==="/"?`/${c}`:`${n}/${c}`)&&r.add(c)}if(r.size===0){if(this.overlay.get(n)?.type==="directory")return[];if(s!==null&&(s===""||await this.isTreeDirectory(s)))return[];throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}return[...r].sort()}async rm(e,n){let r=K(e);if(!await this.exists(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}let i=r==="/"?"/":`${r}/`;if(n?.recursive)for(let o of[...this.overlay.keys()])o.startsWith(i)&&(this.overlay.delete(o),this.removals.add(o));if(this.overlay.delete(r),this.removals.add(r),n?.recursive){let o=this.toRelative(r);o!==null&&await this.markTreeChildrenRemoved(o,r)}}async markTreeChildrenRemoved(e,n){let r=await this.loadTreeDir(e);if(r)for(let s of r){let i=n==="/"?`/${s.name}`:`${n}/${s.name}`;if(this.removals.add(i),s.mode===F.DIRECTORY){let o=e?`${e}/${s.name}`:s.name;await this.markTreeChildrenRemoved(o,i)}}}async readlink(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let i=await this.lookupTreeEntry(s);if(!i||i.entry.mode!==F.SYMLINK)throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let o=await this.objectStore.read(i.entry.hash);return Un.decode(o.content)}async symlink(e,n){let r=K(n);if(await this.exists(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureOverlayParents(r),this.removals.delete(r),this.overlay.set(r,{type:"symlink",target:e,mode:Gn,mtime:new Date})}};var It=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)}},Et=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 ni(t){return{objectStore:new It(t.objectStore),refStore:new Et(t.refStore),hooks:t.hooks}}var xt=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 De(Wt(e,n));return this.overlay.has(r)||await this.inner.exists(r).catch(()=>!1)||this.overlay.set(r,{type:e,content:new Uint8Array(n)}),r}async exists(e){return this.overlay.has(e)?!0:this.inner.exists(e)}async ingestPack(e){if(e.byteLength<32||new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8)===0)return 0;let s=this.overlay,i=this.inner,o=await Gt(e,async a=>{let c=s.get(a);if(c)return{type:c.type,content:new Uint8Array(c.content)};try{return await i.read(a)}catch{return null}});for(let a of o)s.has(a.hash)||s.set(a.hash,{type:a.type,content:a.content});return o.length}async ingestPackStream(e){let n=this.overlay,r=0;for await(let s of e)n.has(s.hash)||n.set(s.hash,{type:s.type,content:s.content}),r++;return r}async findByPrefix(e){let n=await this.inner.findByPrefix(e),r=[];for(let i of this.overlay.keys())i.startsWith(e)&&r.push(i);return[...new Set([...n,...r])]}},Ot=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,qt(n))}async deleteRef(e){this.overlay.delete(e),this.deleted.add(e)}async listRefs(e){let n=await this.inner.listRefs(e),r=new Map;for(let s of n)this.deleted.has(s.name)||r.set(s.name,s);for(let[s,i]of this.overlay)if(!(e&&!s.startsWith(e))){if(i.type==="direct")r.set(s,{name:s,hash:i.hash});else if(i.type==="symbolic"){let o=await this.resolveSymbolic(i.target);o&&r.set(s,{name:s,hash:o})}}return[...r.values()]}async compareAndSwapRef(e,n,r){let s=await this.readRef(e),i=null;if(s&&(s.type==="direct"?i=s.hash:s.type==="symbolic"&&(i=await this.resolveSymbolic(s.target))),n===null){if(s!==null)return!1}else if(i!==n)return!1;return r===null?(this.overlay.delete(e),this.deleted.add(e)):(this.deleted.delete(e),this.overlay.set(e,r)),!0}async resolveSymbolic(e,n=0){if(n>10)return null;let r=await this.readRef(e);return r?r.type==="direct"?r.hash:r.type==="symbolic"?this.resolveSymbolic(r.target,n+1):null:null}};function Rt(t){return{objectStore:new xt(t.objectStore),refStore:new Ot(t.refStore),hooks:t.hooks}}async function Pt(t,e){let n=await Fe(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function _n(t,e,n,r){let s=new Set,i=0;for(let o of e){if(!Zt(o.path))throw new Error(`refusing to check out unsafe path '${o.path}'`);let a=be(r,o.path);if(!Jt(r,a))throw new Error(`refusing to check out path outside target directory: '${o.path}'`);let c=_t(a);if(c!==r&&!s.has(c)&&(await n.mkdir(c,{recursive:!0}),s.add(c)),se(o.mode)){let l=await H(t,o.hash);if(!Qt(l))throw new Error(`refusing to create symlink with unsafe target '${l}'`);n.symlink?await n.symlink(l,a):await n.writeFile(a,l)}else{let l=await ne(t,o.hash);await n.writeFile(a,l)}i++}return i}function Wn(t){return en(t.map(e=>({path:e.path,mode:parseInt(e.mode,8),hash:e.hash,stage:0,stat:ae()})))}async function ri(t,e,n,r="/"){let s=await Pt(t,e),i=await A(t,s),o=await J(t,i.tree),a=await _n(t,o,n,r);return{commitHash:s,treeHash:i.tree,filesWritten:a}}async function si(t,e,n){let r=n?.workTree??"/",s=n?.gitDir??be(r,".git"),i=n?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await Pt(t,i),a=await A(t,o),c=await J(t,a.tree),l={...t,fs:e,gitDir:s,workTree:r},f=await _n(t,c,e,r);return await Be(l,Wn(c)),{ctx:l,commitHash:o,treeHash:a.tree,filesWritten:f}}async function ii(t,e){let n=Rt(t),r=e?.workTree??"/",s=e?.gitDir??be(r,".git"),i=e?.ref??"HEAD",o=await Pt(n,i),a=await A(n,o),c=new Xe(n.objectStore,a.tree,r),l="refs/heads/main";await n.refStore.writeRef("HEAD",{type:"symbolic",target:l}),await n.refStore.writeRef(l,{type:"direct",hash:o});let f={...n,fs:c,gitDir:s,workTree:r},u=await J(n,a.tree);return await Be(f,Wn(u)),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:0}}export{vs as blame,js as countAheadBehind,Hs as createCommit,ii as createSandboxWorktree,si as createWorktree,Ls as diffCommits,Ps as diffTrees,ri as extractTree,Cs as findMergeBases,Rs as flattenTree,ks as getChangedFiles,Ts as getNewCommits,zr as grep,Ss as isAncestor,Hr as listBranches,Ur as listTags,Js as mergeTrees,Qs as mergeTreesFromTreeHashes,Rt as overlayRepo,Br as readBlob,Fr as readBlobText,Nr as readCommit,Gr as readFileAtCommit,ni as readonlyRepo,Dr as resolveRef,Ms as walkCommitHistory,Ns as writeBlob,Us as writeTree};
19
+ `;return _(t,"blob",he.encode(i))}function U(t,e,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:s,hash:e,stage:r,stat:ae()}}function bt(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 Js(t,e,n,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await Mn(t,e,n,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function Qs(t,e,n,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await Re(t,e,n,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}var ei=new TextEncoder,Un=new TextDecoder,Pe=16877,Fn=33188,ti=33261,Gn=40960;function K(t){let e=[];for(let n of t.split("/"))n==="."||n===""||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}function Nn(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function Bn(t){switch(t){case F.EXECUTABLE:return ti;case F.SYMLINK:return Gn;case F.DIRECTORY:return Pe;default:return Fn}}var Xe=class{constructor(e,n,r="/"){this.objectStore=e;this.rootTreeHash=n;this.rootPath=r;let s=K(r);this.overlay.set(s,{type:"directory",mode:Pe,mtime:this.epoch})}treeCache=new Map;overlay=new Map;removals=new Set;epoch=new Date(0);toRelative(e){let n=K(e),r=K(this.rootPath);if(n===r)return"";let s=r==="/"?"/":`${r}/`;return n.startsWith(s)?n.slice(s.length):null}async loadTreeDir(e){let n=this.treeCache.get(e);if(n)return n;if(e===""){let o=await this.objectStore.read(this.rootTreeHash);if(o.type!=="tree")return null;let a=Ae(o.content);return this.treeCache.set("",a.entries),a.entries}let r=e.split("/"),s=await this.loadTreeDir("");if(!s)return null;let i="";for(let o of r){let a=s.find(u=>u.name===o);if(!a||a.mode!==F.DIRECTORY)return null;i=i?`${i}/${o}`:o;let c=this.treeCache.get(i);if(c){s=c;continue}let l=await this.objectStore.read(a.hash);if(l.type!=="tree")return null;let f=Ae(l.content);this.treeCache.set(i,f.entries),s=f.entries}return s}async lookupTreeEntry(e){if(e==="")return null;let n=e.lastIndexOf("/"),r=n===-1?"":e.slice(0,n),s=n===-1?e:e.slice(n+1),i=await this.loadTreeDir(r);if(!i)return null;let o=i.find(a=>a.name===s);return o?{entry:o,dirEntries:i}:null}async isTreeDirectory(e){return e===""?!0:(await this.lookupTreeEntry(e))?.entry.mode===F.DIRECTORY}ensureOverlayParents(e){let n=Nn(e);n===K(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 Un.decode(await this.readFileBuffer(e))}async readFileBuffer(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`ENOENT: no such file or directory, open '${e}'`);let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(i.entry.mode===F.DIRECTORY)throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let o=await this.objectStore.read(i.entry.hash);if(o.type!=="blob")throw new Error(`ENOENT: no such file or directory, open '${e}'`);return o.content}async writeFile(e,n){let r=K(e);this.removals.delete(r),this.ensureOverlayParents(r),this.overlay.set(r,{type:"file",content:typeof n=="string"?ei.encode(n):new Uint8Array(n),mode:Fn,mtime:new Date})}async exists(e){let n=K(e);if(this.removals.has(n))return!1;if(this.overlay.has(n))return!0;let r=this.toRelative(n);return r===null?!1:r===""||await this.isTreeDirectory(r)?!0:await this.lookupTreeEntry(r)!==null}async stat(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:r.type==="file"?r.content.byteLength:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode: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:o}=i,a=o.mode===F.DIRECTORY,c=o.mode===F.SYMLINK,l=0;return a||(l=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:!1,mode:Bn(o.mode),size:l,mtime:this.epoch}}async lstat(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:r.type==="symlink",mode:r.mode,size:r.type==="file"?r.content.byteLength:r.type==="symlink"?r.target.length:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode: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:o}=i,a=o.mode===F.DIRECTORY,c=o.mode===F.SYMLINK,l=0;return a||(l=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:c,mode:Bn(o.mode),size:l,mtime:this.epoch}}async mkdir(e,n){let r=K(e);if(this.overlay.has(r)){if(this.overlay.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.toRelative(r);if(s!==null&&!this.removals.has(r)&&(s===""||await this.isTreeDirectory(s))){if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let i=Nn(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=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,s=this.toRelative(n);if(s!==null){let o=await this.loadTreeDir(s);if(o)for(let a of o){let c=n==="/"?`/${a.name}`:`${n}/${a.name}`;this.removals.has(c)||r.add(a.name)}}let i=n==="/"?"/":`${n}/`;for(let o of this.overlay.keys())if(o!==n&&o.startsWith(i)){let c=o.slice(i.length).split("/")[0];c&&!this.removals.has(n==="/"?`/${c}`:`${n}/${c}`)&&r.add(c)}if(r.size===0){if(this.overlay.get(n)?.type==="directory")return[];if(s!==null&&(s===""||await this.isTreeDirectory(s)))return[];throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}return[...r].sort()}async rm(e,n){let r=K(e);if(!await this.exists(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}let i=r==="/"?"/":`${r}/`;if(n?.recursive)for(let o of[...this.overlay.keys()])o.startsWith(i)&&(this.overlay.delete(o),this.removals.add(o));if(this.overlay.delete(r),this.removals.add(r),n?.recursive){let o=this.toRelative(r);o!==null&&await this.markTreeChildrenRemoved(o,r)}}async markTreeChildrenRemoved(e,n){let r=await this.loadTreeDir(e);if(r)for(let s of r){let i=n==="/"?`/${s.name}`:`${n}/${s.name}`;if(this.removals.add(i),s.mode===F.DIRECTORY){let o=e?`${e}/${s.name}`:s.name;await this.markTreeChildrenRemoved(o,i)}}}async readlink(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let i=await this.lookupTreeEntry(s);if(!i||i.entry.mode!==F.SYMLINK)throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let o=await this.objectStore.read(i.entry.hash);return Un.decode(o.content)}async symlink(e,n){let r=K(n);if(await this.exists(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureOverlayParents(r),this.removals.delete(r),this.overlay.set(r,{type:"symlink",target:e,mode:Gn,mtime:new Date})}};var It=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)}},Et=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 ni(t){return{objectStore:new It(t.objectStore),refStore:new Et(t.refStore),hooks:t.hooks}}var xt=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 De(Wt(e,n));return this.overlay.has(r)||await this.inner.exists(r).catch(()=>!1)||this.overlay.set(r,{type:e,content:new Uint8Array(n)}),r}async exists(e){return this.overlay.has(e)?!0:this.inner.exists(e)}async ingestPack(e){if(e.byteLength<32)return 0;let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0);if(r!==1346454347)throw new Error(`invalid pack signature: 0x${r.toString(16)} (expected 0x5041434b)`);let s=n.getUint32(4);if(s!==2)throw new Error(`unsupported pack version: ${s}`);if(n.getUint32(8)===0)return 0;let o=this.overlay,a=this.inner,c=await Gt(e,async l=>{let f=o.get(l);if(f)return{type:f.type,content:new Uint8Array(f.content)};try{return await a.read(l)}catch{return null}});for(let l of c)o.has(l.hash)||o.set(l.hash,{type:l.type,content:l.content});return c.length}async ingestPackStream(e){let n=this.overlay,r=0;for await(let s of e)n.has(s.hash)||n.set(s.hash,{type:s.type,content:s.content}),r++;return r}async findByPrefix(e){let n=await this.inner.findByPrefix(e),r=[];for(let i of this.overlay.keys())i.startsWith(e)&&r.push(i);return[...new Set([...n,...r])]}},Ot=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,qt(n))}async deleteRef(e){this.overlay.delete(e),this.deleted.add(e)}async listRefs(e){let n=await this.inner.listRefs(e),r=new Map;for(let s of n)this.deleted.has(s.name)||r.set(s.name,s);for(let[s,i]of this.overlay)if(!(e&&!s.startsWith(e))){if(i.type==="direct")r.set(s,{name:s,hash:i.hash});else if(i.type==="symbolic"){let o=await this.resolveSymbolic(i.target);o&&r.set(s,{name:s,hash:o})}}return[...r.values()]}async compareAndSwapRef(e,n,r){let s=await this.readRef(e),i=null;if(s&&(s.type==="direct"?i=s.hash:s.type==="symbolic"&&(i=await this.resolveSymbolic(s.target))),n===null){if(s!==null)return!1}else if(i!==n)return!1;return r===null?(this.overlay.delete(e),this.deleted.add(e)):(this.deleted.delete(e),this.overlay.set(e,r)),!0}async resolveSymbolic(e,n=0){if(n>10)return null;let r=await this.readRef(e);return r?r.type==="direct"?r.hash:r.type==="symbolic"?this.resolveSymbolic(r.target,n+1):null:null}};function Rt(t){return{objectStore:new xt(t.objectStore),refStore:new Ot(t.refStore),hooks:t.hooks}}async function Pt(t,e){let n=await Fe(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function _n(t,e,n,r){let s=new Set,i=0;for(let o of e){if(!Zt(o.path))throw new Error(`refusing to check out unsafe path '${o.path}'`);let a=be(r,o.path);if(!Jt(r,a))throw new Error(`refusing to check out path outside target directory: '${o.path}'`);let c=_t(a);if(c!==r&&!s.has(c)&&(await n.mkdir(c,{recursive:!0}),s.add(c)),se(o.mode)){let l=await H(t,o.hash);if(!Qt(l))throw new Error(`refusing to create symlink with unsafe target '${l}'`);n.symlink?await n.symlink(l,a):await n.writeFile(a,l)}else{let l=await ne(t,o.hash);await n.writeFile(a,l)}i++}return i}function Wn(t){return en(t.map(e=>({path:e.path,mode:parseInt(e.mode,8),hash:e.hash,stage:0,stat:ae()})))}async function ri(t,e,n,r="/"){let s=await Pt(t,e),i=await A(t,s),o=await J(t,i.tree),a=await _n(t,o,n,r);return{commitHash:s,treeHash:i.tree,filesWritten:a}}async function si(t,e,n){let r=n?.workTree??"/",s=n?.gitDir??be(r,".git"),i=n?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await Pt(t,i),a=await A(t,o),c=await J(t,a.tree),l={...t,fs:e,gitDir:s,workTree:r},f=await _n(t,c,e,r);return await Be(l,Wn(c)),{ctx:l,commitHash:o,treeHash:a.tree,filesWritten:f}}async function ii(t,e){let n=Rt(t),r=e?.workTree??"/",s=e?.gitDir??be(r,".git"),i=e?.ref??"HEAD",o=await Pt(n,i),a=await A(n,o),c=new Xe(n.objectStore,a.tree,r),l="refs/heads/main";await n.refStore.writeRef("HEAD",{type:"symbolic",target:l}),await n.refStore.writeRef(l,{type:"direct",hash:o});let f={...n,fs:c,gitDir:s,workTree:r},u=await J(n,a.tree);return await Be(f,Wn(u)),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:0}}export{js as blame,vs as countAheadBehind,Hs as createCommit,ii as createSandboxWorktree,si as createWorktree,Ls as diffCommits,Ps as diffTrees,ri as extractTree,Cs as findMergeBases,Rs as flattenTree,ks as getChangedFiles,Ts as getNewCommits,zr as grep,Ss as isAncestor,Hr as listBranches,Ur as listTags,Js as mergeTrees,Qs as mergeTreesFromTreeHashes,Rt as overlayRepo,Br as readBlob,Fr as readBlobText,Nr as readCommit,Gr as readFileAtCommit,ni as readonlyRepo,Dr as resolveRef,Ms as walkCommitHistory,Ns as writeBlob,Us as writeTree};
@@ -87,6 +87,13 @@ interface Storage {
87
87
  * `prefix` is at least 4 hex characters.
88
88
  */
89
89
  findObjectsByPrefix(repoId: string, prefix: string): MaybeAsync<string[]>;
90
+ /** Return all object hashes stored for a repo. */
91
+ listObjectHashes(repoId: string): MaybeAsync<string[]>;
92
+ /**
93
+ * Delete specific objects by hash.
94
+ * Returns the number of objects actually deleted.
95
+ */
96
+ deleteObjects(repoId: string, hashes: ReadonlyArray<string>): MaybeAsync<number>;
90
97
  /**
91
98
  * Read a single ref. Returns the stored {@link Ref} value (direct hash
92
99
  * or symbolic pointer) without following symrefs — the adapter handles
@@ -112,6 +119,21 @@ interface Storage {
112
119
  atomicRefUpdate<T>(repoId: string, fn: (ops: RefOps) => MaybeAsync<T>): MaybeAsync<T>;
113
120
  }
114
121
 
122
+ /** Options for {@link gcRepo}. */
123
+ interface GcOptions {
124
+ /** Report what would be deleted without actually deleting. Default: false. */
125
+ dryRun?: boolean;
126
+ }
127
+ /** Result of a {@link gcRepo} call. */
128
+ interface GcResult {
129
+ /** Number of unreachable objects deleted (or that would be deleted in dry-run mode). */
130
+ deleted: number;
131
+ /** Number of reachable objects retained. */
132
+ retained: number;
133
+ /** True if GC was aborted because refs changed during the walk (concurrent modification detected). */
134
+ aborted?: boolean;
135
+ }
136
+
115
137
  /**
116
138
  * Default session type, produced by the built-in session builder when
117
139
  * no custom `session` config is provided to `createServer`.
@@ -130,10 +152,14 @@ interface Session {
130
152
  * User-provided session builder that transforms raw transport input
131
153
  * into a typed session object threaded through all hooks.
132
154
  *
133
- * TypeScript infers `S` from the return types of the builder functions,
134
- * so hooks receive the custom type without explicit generic annotations.
155
+ * Both properties are optional provide only the transports you use.
156
+ * TypeScript infers `S` from whichever builders are present.
157
+ *
158
+ * If a transport is used at runtime but its builder is missing, the
159
+ * server returns an error (HTTP 501 / SSH exit 128).
135
160
  *
136
161
  * ```ts
162
+ * // HTTP-only — no need to provide ssh
137
163
  * const server = createServer({
138
164
  * storage: new BunSqliteStorage(db),
139
165
  * session: {
@@ -141,10 +167,6 @@ interface Session {
141
167
  * userId: parseJwt(req).sub,
142
168
  * roles: parseJwt(req).roles,
143
169
  * }),
144
- * ssh: (info) => ({
145
- * userId: info.username ?? "anonymous",
146
- * roles: (info.metadata?.roles as string[]) ?? [],
147
- * }),
148
170
  * },
149
171
  * hooks: {
150
172
  * preReceive: ({ session }) => {
@@ -163,10 +185,17 @@ interface SessionBuilder<S> {
163
185
  * Return `S` to proceed, or return a `Response` to short-circuit
164
186
  * the request (e.g. 401 with `WWW-Authenticate` header). This is
165
187
  * the primary mechanism for HTTP auth — no separate middleware needed.
188
+ *
189
+ * When omitted, HTTP requests receive a 501 response.
166
190
  */
167
- http: (request: Request) => S | Response | Promise<S | Response>;
168
- /** Build a session from SSH session info. */
169
- ssh: (info: SshSessionInfo) => S | Promise<S>;
191
+ http?: (request: Request) => S | Response | Promise<S | Response>;
192
+ /**
193
+ * Build a session from SSH session info.
194
+ *
195
+ * When omitted, SSH sessions receive exit code 128 with a
196
+ * diagnostic message.
197
+ */
198
+ ssh?: (info: SshSessionInfo) => S | Promise<S>;
170
199
  }
171
200
  /** Information about the SSH session passed to `handleSession`. */
172
201
  interface SshSessionInfo {
@@ -264,11 +293,12 @@ interface GitServerConfig<S = Session> {
264
293
  */
265
294
  policy?: ServerPolicy;
266
295
  /**
267
- * Custom session builder. When provided, the server calls
268
- * `session.http(request)` for HTTP and `session.ssh(info)` for SSH
269
- * to produce the session object threaded through all hooks.
296
+ * Custom session builder. Provide `http`, `ssh`, or both —
297
+ * the server calls whichever is present for that transport.
298
+ * If a transport is used but its builder is missing, the server
299
+ * returns an error (HTTP 501 / SSH exit 128).
270
300
  *
271
- * When omitted, the built-in `Session` type is used.
301
+ * When omitted entirely, the built-in `Session` type is used.
272
302
  */
273
303
  session?: SessionBuilder<S>;
274
304
  /** Base path prefix to strip from HTTP URLs (e.g. "/git"). */
@@ -304,7 +334,29 @@ interface GitServerConfig<S = Session> {
304
334
  */
305
335
  onError?: false | ((err: unknown, session?: S) => void);
306
336
  }
307
- interface GitServer {
337
+ /**
338
+ * A ref update request for {@link GitServer.updateRefs}.
339
+ *
340
+ * In-process equivalent of a push command — updates a ref with CAS
341
+ * protection and hook enforcement, without transport overhead.
342
+ */
343
+ interface RefUpdateRequest {
344
+ /** Full ref name (e.g. `"refs/heads/main"`, `"refs/tags/v1.0"`). */
345
+ ref: string;
346
+ /** New commit hash, or `null` to delete the ref. */
347
+ newHash: string | null;
348
+ /**
349
+ * Expected current hash for compare-and-swap.
350
+ *
351
+ * - `undefined` (default) — the server reads the current ref state
352
+ * automatically. Still CAS-protected against concurrent updates.
353
+ * - `null` — assert the ref does not exist (create-only).
354
+ * - `string` — explicit CAS: the update fails if the ref's current
355
+ * hash doesn't match.
356
+ */
357
+ oldHash?: string | null;
358
+ }
359
+ interface GitServer<S = Session> {
308
360
  /** Standard fetch-API handler for HTTP: (Request) => Response */
309
361
  fetch(request: Request): Promise<Response>;
310
362
  /**
@@ -340,6 +392,32 @@ interface GitServer {
340
392
  * ```
341
393
  */
342
394
  handleSession(command: string, channel: SshChannel, session?: SshSessionInfo): Promise<number>;
395
+ /**
396
+ * Update refs in-process with hook enforcement and CAS protection.
397
+ *
398
+ * Equivalent to a push, but without transport overhead — no pack
399
+ * negotiation, no object transfer. Objects must already exist in
400
+ * the repo's object store (e.g. via `createCommit` from `just-git/repo`).
401
+ *
402
+ * Runs the full hook lifecycle: `preReceive` → per-ref `update` →
403
+ * CAS application → `postReceive`. Returns per-ref results.
404
+ *
405
+ * ```ts
406
+ * import { createCommit, writeBlob, writeTree } from "just-git/repo";
407
+ *
408
+ * const repo = await server.repo("my-repo");
409
+ * const blob = await writeBlob(repo, "content");
410
+ * const tree = await writeTree(repo, [{ name: "file.txt", hash: blob }]);
411
+ * const commit = await createCommit(repo, { tree, parents: [head], ... });
412
+ *
413
+ * await server.updateRefs("my-repo", [
414
+ * { ref: "refs/heads/auto-fix", newHash: commit },
415
+ * ]);
416
+ * ```
417
+ *
418
+ * @throws If the repo does not exist or the server is shutting down.
419
+ */
420
+ updateRefs(repoId: string, refs: RefUpdateRequest[], session?: S): Promise<RefUpdateResult>;
343
421
  /**
344
422
  * Node.js `http.createServer` compatible handler.
345
423
  *
@@ -355,6 +433,19 @@ interface GitServer {
355
433
  repo(id: string): Promise<GitRepo | null>;
356
434
  /** Delete a repo and all its data. */
357
435
  deleteRepo(id: string): Promise<void>;
436
+ /**
437
+ * Remove unreachable objects from a repo's storage.
438
+ *
439
+ * Walks all objects reachable from the repo's refs, compares against
440
+ * the full set of stored objects, and deletes the difference.
441
+ *
442
+ * If refs change during the walk (e.g. a concurrent push completes),
443
+ * GC aborts and returns `{ aborted: true }` to prevent deleting
444
+ * newly-reachable objects. Callers can retry.
445
+ *
446
+ * @throws If the repo does not exist or the server is shutting down.
447
+ */
448
+ gc(repoId: string, options?: GcOptions): Promise<GcResult>;
358
449
  /**
359
450
  * Graceful shutdown. After calling, new HTTP requests receive 503
360
451
  * and new SSH sessions get exit 128. Resolves when all in-flight
@@ -470,6 +561,17 @@ interface RefAdvertisement {
470
561
  name: string;
471
562
  hash: string;
472
563
  }
564
+ /** Per-ref result from a push or {@link GitServer.updateRefs} call. */
565
+ interface RefResult {
566
+ ref: string;
567
+ ok: boolean;
568
+ error?: string;
569
+ }
570
+ /** Result of a push or {@link GitServer.updateRefs} call. */
571
+ interface RefUpdateResult {
572
+ refResults: RefResult[];
573
+ applied: RefUpdate[];
574
+ }
473
575
 
474
576
  /**
475
577
  * Unified Git server: Smart HTTP + SSH session handling.
@@ -508,7 +610,7 @@ interface RefAdvertisement {
508
610
  * server.handleSession(command, channel, { username });
509
611
  * ```
510
612
  */
511
- declare function createServer<S = Session>(config: GitServerConfig<S>): GitServer;
613
+ declare function createServer<S = Session>(config: GitServerConfig<S>): GitServer<S>;
512
614
  /**
513
615
  * Compose multiple hook sets into a single `ServerHooks` object.
514
616
  *
@@ -674,15 +776,6 @@ interface ApplyReceivePackOptions<S = unknown> {
674
776
  /** Session info threaded through to hooks. */
675
777
  session?: S;
676
778
  }
677
- interface RefResult {
678
- ref: string;
679
- ok: boolean;
680
- error?: string;
681
- }
682
- interface ApplyReceivePackResult {
683
- refResults: RefResult[];
684
- applied: RefUpdate[];
685
- }
686
779
  /**
687
780
  * Run the full receive-pack lifecycle: preReceive hook, per-ref update
688
781
  * hook with ref format validation, CAS ref application, and postReceive
@@ -692,7 +785,14 @@ interface ApplyReceivePackResult {
692
785
  * Does NOT handle unpack failures — the caller should check
693
786
  * `ingestResult.unpackOk` and short-circuit before calling this.
694
787
  */
695
- declare function applyReceivePack<S = unknown>(options: ApplyReceivePackOptions<S>): Promise<ApplyReceivePackResult>;
788
+ declare function applyReceivePack<S = unknown>(options: ApplyReceivePackOptions<S>): Promise<RefUpdateResult>;
789
+ /**
790
+ * Resolve `RefUpdateRequest[]` into fully computed `RefUpdate[]`.
791
+ *
792
+ * Reads current ref state when `oldHash` is not provided, and computes
793
+ * `isFF`/`isCreate`/`isDelete` for each entry.
794
+ */
795
+ declare function resolveRefUpdates(repo: GitRepo, requests: RefUpdateRequest[]): Promise<RefUpdate[]>;
696
796
 
697
797
  /**
698
798
  * In-memory storage backend with multi-repo support.
@@ -723,6 +823,8 @@ declare class MemoryStorage implements Storage {
723
823
  }>): void;
724
824
  hasObject(repoId: string, hash: string): boolean;
725
825
  findObjectsByPrefix(repoId: string, prefix: string): string[];
826
+ listObjectHashes(repoId: string): string[];
827
+ deleteObjects(repoId: string, hashes: ReadonlyArray<string>): number;
726
828
  getRef(repoId: string, name: string): Ref | null;
727
829
  putRef(repoId: string, name: string, ref: Ref): void;
728
830
  removeRef(repoId: string, name: string): void;
@@ -757,6 +859,7 @@ declare class BunSqliteStorage implements Storage {
757
859
  private db;
758
860
  private stmts;
759
861
  private batchInsertTx;
862
+ private batchDeleteTx;
760
863
  constructor(db: BunSqliteDatabase);
761
864
  hasRepo(repoId: string): boolean;
762
865
  insertRepo(repoId: string): void;
@@ -770,6 +873,8 @@ declare class BunSqliteStorage implements Storage {
770
873
  }>): void;
771
874
  hasObject(repoId: string, hash: string): boolean;
772
875
  findObjectsByPrefix(repoId: string, prefix: string): string[];
876
+ listObjectHashes(repoId: string): string[];
877
+ deleteObjects(repoId: string, hashes: ReadonlyArray<string>): number;
773
878
  getRef(repoId: string, name: string): Ref | null;
774
879
  putRef(repoId: string, name: string, ref: Ref): void;
775
880
  removeRef(repoId: string, name: string): void;
@@ -801,6 +906,7 @@ declare class BetterSqlite3Storage implements Storage {
801
906
  private db;
802
907
  private stmts;
803
908
  private batchInsertTx;
909
+ private batchDeleteTx;
804
910
  constructor(db: BetterSqlite3Database);
805
911
  hasRepo(repoId: string): boolean;
806
912
  insertRepo(repoId: string): void;
@@ -814,6 +920,8 @@ declare class BetterSqlite3Storage implements Storage {
814
920
  }>): void;
815
921
  hasObject(repoId: string, hash: string): boolean;
816
922
  findObjectsByPrefix(repoId: string, prefix: string): string[];
923
+ listObjectHashes(repoId: string): string[];
924
+ deleteObjects(repoId: string, hashes: ReadonlyArray<string>): number;
817
925
  getRef(repoId: string, name: string): Ref | null;
818
926
  putRef(repoId: string, name: string, ref: Ref): void;
819
927
  removeRef(repoId: string, name: string): void;
@@ -881,6 +989,8 @@ declare class PgStorage implements Storage {
881
989
  }>): Promise<void>;
882
990
  hasObject(repoId: string, hash: string): Promise<boolean>;
883
991
  findObjectsByPrefix(repoId: string, prefix: string): Promise<string[]>;
992
+ listObjectHashes(repoId: string): Promise<string[]>;
993
+ deleteObjects(repoId: string, hashes: ReadonlyArray<string>): Promise<number>;
884
994
  getRef(repoId: string, name: string): Promise<Ref | null>;
885
995
  putRef(repoId: string, name: string, ref: Ref): Promise<void>;
886
996
  removeRef(repoId: string, name: string): Promise<void>;
@@ -888,4 +998,4 @@ declare class PgStorage implements Storage {
888
998
  atomicRefUpdate<T>(repoId: string, fn: (ops: RefOps) => Promise<T> | T): Promise<T>;
889
999
  }
890
1000
 
891
- export { type AdvertiseRefsEvent, type AdvertiseResult, type ApplyReceivePackOptions, type ApplyReceivePackResult, type BetterSqlite3Database, BetterSqlite3Storage, type BunSqliteDatabase, BunSqliteStorage, type CreateRepoOptions, GitRepo, type GitServer, type GitServerConfig, type MaybeAsync, MemoryStorage, type NodeHttpRequest, type NodeHttpResponse, type PgDatabase, type PgPool, type PgPoolClient, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type PushCommand, RawObject, type RawRefEntry, type ReceivePackResult, Ref, type RefAdvertisement, type RefOps, type RefResult, type RefUpdate, Rejection, type ServerHooks, type ServerPolicy, type Session, type SessionBuilder, type SshChannel, type SshSessionInfo, type Storage, type UpdateEvent, advertiseRefsWithHooks, applyReceivePack, buildRefAdvertisementBytes, buildRefListBytes, buildRefListPktLines, collectRefs, composeHooks, createServer, handleUploadPack, ingestReceivePack, ingestReceivePackFromStream, wrapPgPool };
1001
+ export { type AdvertiseRefsEvent, type AdvertiseResult, type ApplyReceivePackOptions, type BetterSqlite3Database, BetterSqlite3Storage, type BunSqliteDatabase, BunSqliteStorage, type CreateRepoOptions, type GcOptions, type GcResult, GitRepo, type GitServer, type GitServerConfig, type MaybeAsync, MemoryStorage, type NodeHttpRequest, type NodeHttpResponse, type PgDatabase, type PgPool, type PgPoolClient, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type PushCommand, RawObject, type RawRefEntry, type ReceivePackResult, Ref, type RefAdvertisement, type RefOps, type RefResult, type RefUpdate, type RefUpdateRequest, type RefUpdateResult, Rejection, type ServerHooks, type ServerPolicy, type Session, type SessionBuilder, type SshChannel, type SshSessionInfo, type Storage, type UpdateEvent, advertiseRefsWithHooks, applyReceivePack, buildRefAdvertisementBytes, buildRefListBytes, buildRefListPktLines, collectRefs, composeHooks, createServer, handleUploadPack, ingestReceivePack, ingestReceivePackFromStream, resolveRefUpdates, wrapPgPool };
@@ -1,40 +1,41 @@
1
- var ue=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});function T(r){return r!=null&&typeof r=="object"&&"reject"in r&&r.reject===!0}var ke="0000000000000000000000000000000000000000",st=(()=>{let r=new Array(256);for(let e=0;e<256;e++)r[e]=(e>>4).toString(16)+(e&15).toString(16);return r})();function he(r){let e="";for(let t=0;t<20;t++)e+=st[r[t]];return e}function Z(r,e){let t="";for(let n=0;n<20;n++)t+=st[r[e+n]];return t}function ye(r){let e=new Uint8Array(20);for(let t=0;t<20;t++)e[t]=parseInt(r.slice(t*2,t*2+2),16);return e}var ar=new TextEncoder;function ve(r){return typeof r=="string"?ar.encode(r):r}function or(){if(typeof globalThis.Bun<"u")return()=>{let r=new Bun.CryptoHasher("sha1"),e={update(t){return r.update(ve(t)),e},hex:()=>Promise.resolve(r.digest("hex"))};return e};try{let r=ue(["node","crypto"].join(":"));if(typeof r.createHash=="function")return()=>{let e=r.createHash("sha1"),t={update(n){return e.update(ve(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let r=[],e={update(t){return r.push(ve(t)),e},async hex(){let t=0;for(let i of r)t+=i.byteLength;let n=new Uint8Array(t),s=0;for(let i of r)n.set(i,s),s+=i.byteLength;let a=await crypto.subtle.digest("SHA-1",n);return he(new Uint8Array(a))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var at=or(),G=at;async function ot(r){return at().update(r).hex()}var ir=new Set(["tree","commit","tag"]),be=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,t){if(!ir.has(t.type))return;let n=t.content.byteLength;if(!(n>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+n>this.maxBytes&&this.map.size>0;){let s=this.map.keys().next().value;this.currentBytes-=this.map.get(s).content.byteLength,this.map.delete(s)}this.map.set(e,t),this.currentBytes+=n}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var L=Uint8Array,F=Uint16Array,cr=Int32Array,it=new L([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]),ct=new L([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]),fr=new L([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ft=(r,e)=>{let t=new F(31);for(let s=0;s<31;++s)t[s]=e+=1<<r[s-1];let n=new cr(t[30]);for(let s=1;s<30;++s)for(let a=t[s];a<t[s+1];++a)n[a]=a-t[s]<<5|s;return{b:t,r:n}},{b:lt}=ft(it,2);lt[28]=258;var{b:lr}=ft(ct,0),Ae=new F(32768);for(let r=0;r<32768;++r){let e=(r&43690)>>1|(r&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,Ae[r]=((e&65280)>>8|(e&255)<<8)>>1}var J=(r,e,t)=>{let n=r.length,s=0,a=new F(e);for(;s<n;++s)r[s]&&++a[r[s]-1];let i=new F(e);for(s=1;s<e;++s)i[s]=i[s-1]+a[s-1]<<1;let o;if(t){o=new F(1<<e);let f=15-e;for(s=0;s<n;++s)if(r[s]){let c=s<<4|r[s],l=e-r[s],d=i[r[s]-1]++<<l;for(let p=d|(1<<l)-1;d<=p;++d)o[Ae[d]>>f]=c}}else for(o=new F(n),s=0;s<n;++s)r[s]&&(o[s]=Ae[i[r[s]-1]++]>>15-r[s]);return o},Q=new L(288);for(let r=0;r<144;++r)Q[r]=8;for(let r=144;r<256;++r)Q[r]=9;for(let r=256;r<280;++r)Q[r]=7;for(let r=280;r<288;++r)Q[r]=8;var dt=new L(32);for(let r=0;r<32;++r)dt[r]=5;var dr=J(Q,9,1),pr=J(dt,5,1),Se=r=>{let e=r[0];for(let t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},U=(r,e,t)=>{let n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},je=(r,e)=>{let t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},pt=r=>(r+7)/8|0,ur=(r,e,t)=>((e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new L(r.subarray(e,t))),H=(r,e)=>{let t=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||t[r]||"unknown inflate error")},ut=(r,e,t,n)=>{let s=r.length,a=n?n.length:0;if(!s||e.f&&!e.l)return t||new L(0);let i=!t,o=i||e.i!=2,f=e.i;i&&(t=new L(s*3));let c=y=>{let R=t.length;if(y>R){let w=new L(Math.max(R*2,y));w.set(t),t=w}},l=e.f||0,d=e.p||0,p=e.b||0,u=e.l,h=e.d,m=e.m,g=e.n,b=s*8;do{if(!u){l=U(r,d,1);let P=U(r,d+1,3);if(d+=3,P)if(P==1)u=dr,h=pr,m=9,g=5;else if(P==2){let x=U(r,d,31)+257,O=U(r,d+10,15)+4,S=x+U(r,d+5,31)+1;d+=14;let E=new L(S),j=new L(19);for(let N=0;N<O;++N)j[fr[N]]=U(r,d+N*3,7);d+=O*3;let M=Se(j),I=(1<<M)-1,C=J(j,M,1);for(let N=0;N<S;){let rt=C[U(r,d,I)];d+=rt&15;let V=rt>>4;if(V<16)E[N++]=V;else{let nt=0,pe=0;for(V==16?(pe=3+U(r,d,3),d+=2,nt=E[N-1]):V==17?(pe=3+U(r,d,7),d+=3):V==18&&(pe=11+U(r,d,127),d+=7);pe--;)E[N++]=nt}}let $=E.subarray(0,x),tt=E.subarray(x);m=Se($),g=Se(tt),u=J($,m,1),h=J(tt,g,1)}else H(1);else{let x=pt(d)+4,O=r[x-4]|r[x-3]<<8,S=x+O;if(S>s){f&&H(0);break}o&&c(p+O),t.set(r.subarray(x,S),p),e.b=p+=O,e.p=d=S*8,e.f=l;continue}if(d>b){f&&H(0);break}}o&&c(p+131072);let y=(1<<m)-1,R=(1<<g)-1,w=d;for(;;w=d){let P=u[je(r,d)&y],x=P>>4;if(d+=P&15,d>b){f&&H(0);break}if(P||H(2),x<256)t[p++]=x;else if(x==256){w=d,u=null;break}else{let O=x-254;if(x>264){let I=x-257,C=it[I];O=U(r,d,(1<<C)-1)+lt[I],d+=C}let S=h[je(r,d)&R],E=S>>4;S||H(3),d+=S&15;let j=lr[E];if(E>3){let I=ct[E];j+=je(r,d)&(1<<I)-1,d+=I}if(d>b){f&&H(0);break}o&&c(p+131072);let M=p+O;if(p<j){let I=a-j,C=Math.min(j,M);for(I+p<0&&H(3);p<C;++p)t[p]=n[I+p]}for(;p<M;++p)t[p]=t[p-j]}}e.l=u,e.p=w,e.b=p,e.f=l,u&&(l=1,e.m=m,e.d=h,e.n=g)}while(!l);return p!=t.length&&i?ur(t,0,p):t.subarray(0,p)},ht=r=>(((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&H(0,"invalid zlib data"),r[1]&32&&H(0,"zlib dictionaries are not supported"),2);function yt(r){let e=ht(r);return ut(r.subarray(e,-4),{i:2})}function Ie(r){let e=ht(r),t={i:2},n=ut(r.subarray(e),t),s=pt(t.p);return{result:n,bytesConsumed:e+s+4}}async function hr(){let r;if(!(typeof document<"u"))try{r=ue(["node","zlib"].join(":"))}catch{try{r=await import(["node","zlib"].join(":"))}catch{}}if(r&&typeof r.deflateSync=="function"&&typeof r.inflateSync=="function"){let n=null;try{let s=r.inflateSync(r.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(n=a=>{let i=r.inflateSync(a,{info:!0});return{result:new Uint8Array(i.buffer),bytesConsumed:i.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(r.deflateSync(s)),inflateSync:s=>new Uint8Array(r.inflateSync(s)),inflateWithConsumed:n??Ie}}let t;return typeof globalThis.CompressionStream=="function"?t=async n=>{let s=new CompressionStream("deflate"),a=s.writable.getWriter();return a.write(n),a.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:t=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:t,inflateSync:yt,inflateWithConsumed:Ie}}var yr=null;function bt(){return yr??=hr()}async function me(r){return await(await bt()).deflateSync(r)}async function Te(r,e){let t=await bt(),{result:n,bytesConsumed:s}=t.inflateWithConsumed(r);if(n.byteLength!==e)throw new Error(`Inflate size mismatch: got ${n.byteLength}, expected ${e}`);return{result:n,bytesConsumed:s}}var z=1346454347,xe=2,xt=1,Rt=2,wt=3,Pt=4,W=6,ee=7,Ot={[xt]:"commit",[Rt]:"tree",[wt]:"blob",[Pt]:"tag"},Et={commit:xt,tree:Rt,blob:wt,tag:Pt};async function kt(r,e){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.getUint32(0);if(n!==z)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${z.toString(16)})`);let s=t.getUint32(4);if(s!==xe)throw new Error(`Unsupported pack version: ${s}`);if(r.byteLength>=32){let c=Z(r,r.byteLength-20),l=G();l.update(r.subarray(0,r.byteLength-20));let d=await l.hex();if(d!==c)throw new Error(`pack checksum mismatch: expected ${c}, computed ${d}`)}let a=t.getUint32(8),i=[],o=12;for(let c=0;c<a;c++){let l=await br(r,o);i.push(l),o=l.nextOffset}return(await mr(i,e)).map((c,l)=>({...c,offset:i[l].headerOffset,nextOffset:i[l].nextOffset}))}async function br(r,e){let t=e,n=r[e++],s=n>>4&7,a=n&15,i=4;for(;n&128;)n=r[e++],a|=(n&127)<<i,i+=7;let o,f;if(s===W){let d=r[e++];for(o=d&127;d&128;)o+=1,d=r[e++],o=(o<<7)+(d&127);o=t-o}else s===ee&&(f=Z(r,e),e+=20);let{result:c,bytesConsumed:l}=await Te(r.subarray(e),a);return{headerOffset:t,typeNum:s,inflated:c,baseOffset:o,baseHash:f,nextOffset:e+l}}var mt=50;async function mr(r,e){let t=new Map;for(let a=0;a<r.length;a++)t.set(r[a].headerOffset,a);let n=new Array(r.length).fill(null);async function s(a,i=0){if(i>mt)throw new Error(`delta chain depth ${i} exceeds limit of ${mt}`);let o=n[a];if(o)return o;let f=r[a];if(f.typeNum!==W&&f.typeNum!==ee){let u=Ot[f.typeNum];if(!u)throw new Error(`Unknown object type: ${f.typeNum}`);let h={type:u,content:f.inflated,hash:await q(u,f.inflated)};return n[a]=h,h}if(f.typeNum===W){let u=t.get(f.baseOffset);if(u===void 0)throw new Error(`OFS_DELTA base not found at offset ${f.baseOffset}`);let h=await s(u,i+1),m=ge(h.content,f.inflated),g={type:h.type,content:m,hash:await q(h.type,m)};return n[a]=g,g}let c=await gr(r,n,f.baseHash,s),l;if(c!==void 0)l=await s(c,i+1);else if(e){let u=await e(f.baseHash);u&&(l=u)}if(!l)throw new Error(`REF_DELTA base not found for hash ${f.baseHash}`);let d=ge(l.content,f.inflated),p={type:l.type,content:d,hash:await q(l.type,d)};return n[a]=p,p}for(let a=0;a<r.length;a++)await s(a);return n}async function gr(r,e,t,n){for(let s=0;s<e.length;s++)if(e[s]?.hash===t)return s;for(let s=0;s<r.length;s++){let a=r[s];if(a.typeNum!==W&&a.typeNum!==ee&&(await n(s)).hash===t)return s}}var Ue=class{buf=new Uint8Array(0);iter;eof=!1;_bytesRead=0;hasher;constructor(e,t=!1){this.iter=e[Symbol.asyncIterator](),this.hasher=t?G():null}get bytesRead(){return this._bytesRead}async pullMore(){if(this.eof)return!1;let{value:e,done:t}=await this.iter.next();if(t||!e)return this.eof=!0,!1;if(this.buf.byteLength===0)this.buf=new Uint8Array(e);else{let n=new Uint8Array(this.buf.byteLength+e.byteLength);n.set(this.buf),n.set(e,this.buf.byteLength),this.buf=n}return!0}async ensure(e){for(;this.buf.byteLength<e;)if(!await this.pullMore())throw new Error(`Unexpected end of pack data: needed ${e} bytes, have ${this.buf.byteLength}`)}consume(e){let t=new Uint8Array(this.buf.subarray(0,e));return this.hasher?.update(t),this.buf=this.buf.subarray(e),this._bytesRead+=e,t}async readByte(){return await this.ensure(1),this.consume(1)[0]}async readExact(e){return await this.ensure(e),this.consume(e)}async readRaw(e){await this.ensure(e);let t=new Uint8Array(this.buf.subarray(0,e));return this.buf=this.buf.subarray(e),this._bytesRead+=e,t}async inflateNext(e){for(this.buf.byteLength===0&&!this.eof&&await this.pullMore();;)try{let{result:t,bytesConsumed:n}=await Te(this.buf,e);return this.consume(n),t}catch{if(!this.eof&&await this.pullMore())continue;throw new Error(`Failed to inflate pack entry at byte ${this._bytesRead} (expected ${e} bytes)`)}}async hashHex(){if(!this.hasher)throw new Error("Hashing not enabled");return this.hasher.hex()}};async function*vt(r,e){let t=new Ue(r,!0),n=await t.readExact(12),s=new DataView(n.buffer,n.byteOffset,n.byteLength),a=s.getUint32(0);if(a!==z)throw new Error(`Invalid pack signature: 0x${a.toString(16)} (expected 0x${z.toString(16)})`);let i=s.getUint32(4);if(i!==xe)throw new Error(`Unsupported pack version: ${i}`);let o=s.getUint32(8),f=new Map,c=new Map;for(let p=0;p<o;p++){let u=t.bytesRead,h=await t.readByte(),m=h>>4&7,g=h&15,b=4;for(;h&128;)h=await t.readByte(),g|=(h&127)<<b,b+=7;let y,R;if(m===W){let x=await t.readByte();for(y=x&127;x&128;)y+=1,x=await t.readByte(),y=(y<<7)+(x&127);y=u-y}else if(m===ee){let x=await t.readExact(20);R=Z(x,0)}let w=await t.inflateNext(g),P;if(m!==W&&m!==ee){let x=Ot[m];if(!x)throw new Error(`Unknown object type: ${m}`);P={type:x,content:w,hash:await q(x,w)}}else if(m===W){let x=f.get(y);if(!x)throw new Error(`OFS_DELTA base not found at offset ${y}`);let O=ge(x.content,w);P={type:x.type,content:O,hash:await q(x.type,O)}}else{let x=c.get(R);if(!x&&e&&(x=await e(R)??void 0),!x)throw new Error(`REF_DELTA base not found for hash ${R}`);let O=ge(x.content,w);P={type:x.type,content:O,hash:await q(x.type,O)}}f.set(u,P),c.set(P.hash,P),yield P}let l=Z(await t.readRaw(20),0),d=await t.hashHex();if(d!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${d}`)}function ge(r,e){let t=0,{value:n,newPos:s}=gt(e,t);if(t=s,n!==r.byteLength)throw new Error(`Delta base size mismatch: expected ${n}, got ${r.byteLength}`);let{value:a,newPos:i}=gt(e,t);t=i;let o=new Uint8Array(a),f=0;for(;t<e.byteLength;){let c=e[t++];if(c&128){let l=0,d=0;c&1&&(l=e[t++]),c&2&&(l|=e[t++]<<8),c&4&&(l|=e[t++]<<16),c&8&&(l|=e[t++]<<24),c&16&&(d=e[t++]),c&32&&(d|=e[t++]<<8),c&64&&(d|=e[t++]<<16),d===0&&(d=65536),o.set(r.subarray(l,l+d),f),f+=d}else if(c>0)o.set(e.subarray(t,t+c),f),f+=c,t+=c;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(f!==a)throw new Error(`Delta produced ${f} bytes, expected ${a}`);return o}async function Re(r){let e=[],t=new Map,n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,z),s.setUint32(4,xe),s.setUint32(8,r.length),e.push(n);let a=12,i=[];for(let o of r){let f=a;t.set(o.hash,a);let c=o.delta&&o.deltaBaseHash?t.get(o.deltaBaseHash):void 0;if(o.delta&&c!==void 0){let l=Le(W,o.delta.byteLength),d=Rr(a-c),p=await me(o.delta);e.push(l,d,p),a+=l.byteLength+d.byteLength+p.byteLength}else{let l=Et[o.type],d=Le(l,o.content.byteLength),p=await me(o.content);e.push(d,p),a+=d.byteLength+p.byteLength}i.push({hash:o.hash,offset:f,nextOffset:a})}return{data:await xr(e),entries:i}}async function*St(r,e){let t=G(),n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,z),s.setUint32(4,xe),s.setUint32(8,r),t.update(n),yield n;for await(let a of e){let i=Et[a.type],o=Le(i,a.content.byteLength),f=await me(a.content);t.update(o),t.update(f),yield wr(o,f)}yield ye(await t.hex())}async function xr(r){let e=0;for(let i of r)e+=i.byteLength;e+=20;let t=new Uint8Array(e),n=0;for(let i of r)t.set(i,n),n+=i.byteLength;let s=G();s.update(t.subarray(0,n));let a=await s.hex();return t.set(ye(a),n),t}function Rr(r){let e=[];e.push(r&127);let t=r>>>7;for(;t>0;)e.unshift(128|--t&127),t>>>=7;return new Uint8Array(e)}function Le(r,e){let t=[],n=r<<4|e&15;for(e>>=4;e>0;)t.push(n|128),n=e&127,e>>=7;return t.push(n),new Uint8Array(t)}function gt(r,e){let t=0,n=0,s;do s=r[e++],t|=(s&127)<<n,n+=7;while(s&128);return{value:t,newPos:e}}function wr(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(r,0),t.set(e,r.byteLength),t}var Pr=new TextEncoder;async function q(r,e){let t=Pr.encode(`${r} ${e.byteLength}\0`),n=G();return n.update(t),n.update(e),n.hex()}var Or=new TextEncoder,Sn=new TextDecoder;function jt(r,e){let t=Or.encode(`${r} ${e.byteLength}\0`),n=new Uint8Array(t.byteLength+e.byteLength);return n.set(t),n.set(e,t.byteLength),n}function te(r){let e=r.indexOf("<"),t=r.indexOf(">");if(e===-1||t===-1)throw new Error(`Malformed identity line: "${r}"`);let n=r.slice(0,e).trimEnd(),s=r.slice(e+1,t),a=r.slice(t+2),[i="0",o="+0000"]=a.split(" "),f=parseInt(i,10);return{name:n,email:s,timestamp:f,timezone:o}}var Tn=new TextEncoder,kr=new TextDecoder;function re(r){let e=kr.decode(r),t=e.indexOf(`
1
+ var he=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});function T(r){return r!=null&&typeof r=="object"&&"reject"in r&&r.reject===!0}var ye="0000000000000000000000000000000000000000",ot=(()=>{let r=new Array(256);for(let e=0;e<256;e++)r[e]=(e>>4).toString(16)+(e&15).toString(16);return r})();function be(r){let e="";for(let t=0;t<20;t++)e+=ot[r[t]];return e}function J(r,e){let t="";for(let n=0;n<20;n++)t+=ot[r[e+n]];return t}function me(r){let e=new Uint8Array(20);for(let t=0;t<20;t++)e[t]=parseInt(r.slice(t*2,t*2+2),16);return e}var lr=new TextEncoder;function je(r){return typeof r=="string"?lr.encode(r):r}function dr(){if(typeof globalThis.Bun<"u")return()=>{let r=new Bun.CryptoHasher("sha1"),e={update(t){return r.update(je(t)),e},hex:()=>Promise.resolve(r.digest("hex"))};return e};try{let r=he(["node","crypto"].join(":"));if(typeof r.createHash=="function")return()=>{let e=r.createHash("sha1"),t={update(n){return e.update(je(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let r=[],e={update(t){return r.push(je(t)),e},async hex(){let t=0;for(let i of r)t+=i.byteLength;let n=new Uint8Array(t),s=0;for(let i of r)n.set(i,s),s+=i.byteLength;let a=await crypto.subtle.digest("SHA-1",n);return be(new Uint8Array(a))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var it=dr(),G=it;async function ct(r){return it().update(r).hex()}var pr=new Set(["tree","commit","tag"]),ge=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,t){if(!pr.has(t.type))return;let n=t.content.byteLength;if(!(n>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+n>this.maxBytes&&this.map.size>0;){let s=this.map.keys().next().value;this.currentBytes-=this.map.get(s).content.byteLength,this.map.delete(s)}this.map.set(e,t),this.currentBytes+=n}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var L=Uint8Array,F=Uint16Array,ur=Int32Array,ft=new L([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]),lt=new L([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]),hr=new L([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),dt=(r,e)=>{let t=new F(31);for(let s=0;s<31;++s)t[s]=e+=1<<r[s-1];let n=new ur(t[30]);for(let s=1;s<30;++s)for(let a=t[s];a<t[s+1];++a)n[a]=a-t[s]<<5|s;return{b:t,r:n}},{b:pt}=dt(ft,2);pt[28]=258;var{b:yr}=dt(lt,0),Ie=new F(32768);for(let r=0;r<32768;++r){let e=(r&43690)>>1|(r&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,Ie[r]=((e&65280)>>8|(e&255)<<8)>>1}var Q=(r,e,t)=>{let n=r.length,s=0,a=new F(e);for(;s<n;++s)r[s]&&++a[r[s]-1];let i=new F(e);for(s=1;s<e;++s)i[s]=i[s-1]+a[s-1]<<1;let o;if(t){o=new F(1<<e);let f=15-e;for(s=0;s<n;++s)if(r[s]){let c=s<<4|r[s],l=e-r[s],d=i[r[s]-1]++<<l;for(let p=d|(1<<l)-1;d<=p;++d)o[Ie[d]>>f]=c}}else for(o=new F(n),s=0;s<n;++s)r[s]&&(o[s]=Ie[i[r[s]-1]++]>>15-r[s]);return o},ee=new L(288);for(let r=0;r<144;++r)ee[r]=8;for(let r=144;r<256;++r)ee[r]=9;for(let r=256;r<280;++r)ee[r]=7;for(let r=280;r<288;++r)ee[r]=8;var ut=new L(32);for(let r=0;r<32;++r)ut[r]=5;var br=Q(ee,9,1),mr=Q(ut,5,1),Se=r=>{let e=r[0];for(let t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},U=(r,e,t)=>{let n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},Ae=(r,e)=>{let t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},ht=r=>(r+7)/8|0,gr=(r,e,t)=>((e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new L(r.subarray(e,t))),H=(r,e)=>{let t=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||t[r]||"unknown inflate error")},yt=(r,e,t,n)=>{let s=r.length,a=n?n.length:0;if(!s||e.f&&!e.l)return t||new L(0);let i=!t,o=i||e.i!=2,f=e.i;i&&(t=new L(s*3));let c=y=>{let g=t.length;if(y>g){let w=new L(Math.max(g*2,y));w.set(t),t=w}},l=e.f||0,d=e.p||0,p=e.b||0,u=e.l,h=e.d,m=e.m,R=e.n,b=s*8;do{if(!u){l=U(r,d,1);let E=U(r,d+1,3);if(d+=3,E)if(E==1)u=br,h=mr,m=9,R=5;else if(E==2){let x=U(r,d,31)+257,O=U(r,d+10,15)+4,j=x+U(r,d+5,31)+1;d+=14;let P=new L(j),A=new L(19);for(let N=0;N<O;++N)A[hr[N]]=U(r,d+N*3,7);d+=O*3;let B=Se(A),I=(1<<B)-1,C=Q(A,B,1);for(let N=0;N<j;){let st=C[U(r,d,I)];d+=st&15;let Z=st>>4;if(Z<16)P[N++]=Z;else{let at=0,ue=0;for(Z==16?(ue=3+U(r,d,3),d+=2,at=P[N-1]):Z==17?(ue=3+U(r,d,7),d+=3):Z==18&&(ue=11+U(r,d,127),d+=7);ue--;)P[N++]=at}}let $=P.subarray(0,x),nt=P.subarray(x);m=Se($),R=Se(nt),u=Q($,m,1),h=Q(nt,R,1)}else H(1);else{let x=ht(d)+4,O=r[x-4]|r[x-3]<<8,j=x+O;if(j>s){f&&H(0);break}o&&c(p+O),t.set(r.subarray(x,j),p),e.b=p+=O,e.p=d=j*8,e.f=l;continue}if(d>b){f&&H(0);break}}o&&c(p+131072);let y=(1<<m)-1,g=(1<<R)-1,w=d;for(;;w=d){let E=u[Ae(r,d)&y],x=E>>4;if(d+=E&15,d>b){f&&H(0);break}if(E||H(2),x<256)t[p++]=x;else if(x==256){w=d,u=null;break}else{let O=x-254;if(x>264){let I=x-257,C=ft[I];O=U(r,d,(1<<C)-1)+pt[I],d+=C}let j=h[Ae(r,d)&g],P=j>>4;j||H(3),d+=j&15;let A=yr[P];if(P>3){let I=lt[P];A+=Ae(r,d)&(1<<I)-1,d+=I}if(d>b){f&&H(0);break}o&&c(p+131072);let B=p+O;if(p<A){let I=a-A,C=Math.min(A,B);for(I+p<0&&H(3);p<C;++p)t[p]=n[I+p]}for(;p<B;++p)t[p]=t[p-A]}}e.l=u,e.p=w,e.b=p,e.f=l,u&&(l=1,e.m=m,e.d=h,e.n=R)}while(!l);return p!=t.length&&i?gr(t,0,p):t.subarray(0,p)},bt=r=>(((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&H(0,"invalid zlib data"),r[1]&32&&H(0,"zlib dictionaries are not supported"),2);function mt(r){let e=bt(r);return yt(r.subarray(e,-4),{i:2})}function Te(r){let e=bt(r),t={i:2},n=yt(r.subarray(e),t),s=ht(t.p);return{result:n,bytesConsumed:e+s+4}}async function Rr(){let r;if(!(typeof document<"u"))try{r=he(["node","zlib"].join(":"))}catch{try{r=await import(["node","zlib"].join(":"))}catch{}}if(r&&typeof r.deflateSync=="function"&&typeof r.inflateSync=="function"){let n=null;try{let s=r.inflateSync(r.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(n=a=>{let i=r.inflateSync(a,{info:!0});return{result:new Uint8Array(i.buffer),bytesConsumed:i.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(r.deflateSync(s)),inflateSync:s=>new Uint8Array(r.inflateSync(s)),inflateWithConsumed:n??Te}}let t;return typeof globalThis.CompressionStream=="function"?t=async n=>{let s=new CompressionStream("deflate"),a=s.writable.getWriter();return a.write(n),a.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:t=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:t,inflateSync:mt,inflateWithConsumed:Te}}var xr=null;function gt(){return xr??=Rr()}async function Re(r){return await(await gt()).deflateSync(r)}async function Ue(r,e){let t=await gt(),{result:n,bytesConsumed:s}=t.inflateWithConsumed(r);if(n.byteLength!==e)throw new Error(`Inflate size mismatch: got ${n.byteLength}, expected ${e}`);return{result:n,bytesConsumed:s}}var z=1346454347,we=2,wt=1,Et=2,Ot=3,Pt=4,_=6,te=7,vt={[wt]:"commit",[Et]:"tree",[Ot]:"blob",[Pt]:"tag"},kt={commit:wt,tree:Et,blob:Ot,tag:Pt};async function jt(r,e){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.getUint32(0);if(n!==z)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${z.toString(16)})`);let s=t.getUint32(4);if(s!==we)throw new Error(`Unsupported pack version: ${s}`);if(r.byteLength>=32){let c=J(r,r.byteLength-20),l=G();l.update(r.subarray(0,r.byteLength-20));let d=await l.hex();if(d!==c)throw new Error(`pack checksum mismatch: expected ${c}, computed ${d}`)}let a=t.getUint32(8),i=[],o=12;for(let c=0;c<a;c++){let l=await wr(r,o);i.push(l),o=l.nextOffset}return(await Er(i,e)).map((c,l)=>({...c,offset:i[l].headerOffset,nextOffset:i[l].nextOffset}))}async function wr(r,e){let t=e,n=r[e++],s=n>>4&7,a=n&15,i=4;for(;n&128;)n=r[e++],a|=(n&127)<<i,i+=7;let o,f;if(s===_){let d=r[e++];for(o=d&127;d&128;)o+=1,d=r[e++],o=(o<<7)+(d&127);o=t-o}else s===te&&(f=J(r,e),e+=20);let{result:c,bytesConsumed:l}=await Ue(r.subarray(e),a);return{headerOffset:t,typeNum:s,inflated:c,baseOffset:o,baseHash:f,nextOffset:e+l}}var Rt=50;async function Er(r,e){let t=new Map;for(let a=0;a<r.length;a++)t.set(r[a].headerOffset,a);let n=new Array(r.length).fill(null);async function s(a,i=0){if(i>Rt)throw new Error(`delta chain depth ${i} exceeds limit of ${Rt}`);let o=n[a];if(o)return o;let f=r[a];if(f.typeNum!==_&&f.typeNum!==te){let u=vt[f.typeNum];if(!u)throw new Error(`Unknown object type: ${f.typeNum}`);let h={type:u,content:f.inflated,hash:await q(u,f.inflated)};return n[a]=h,h}if(f.typeNum===_){let u=t.get(f.baseOffset);if(u===void 0)throw new Error(`OFS_DELTA base not found at offset ${f.baseOffset}`);let h=await s(u,i+1),m=xe(h.content,f.inflated),R={type:h.type,content:m,hash:await q(h.type,m)};return n[a]=R,R}let c=await Or(r,n,f.baseHash,s),l;if(c!==void 0)l=await s(c,i+1);else if(e){let u=await e(f.baseHash);u&&(l=u)}if(!l)throw new Error(`REF_DELTA base not found for hash ${f.baseHash}`);let d=xe(l.content,f.inflated),p={type:l.type,content:d,hash:await q(l.type,d)};return n[a]=p,p}for(let a=0;a<r.length;a++)await s(a);return n}async function Or(r,e,t,n){for(let s=0;s<e.length;s++)if(e[s]?.hash===t)return s;for(let s=0;s<r.length;s++){let a=r[s];if(a.typeNum!==_&&a.typeNum!==te&&(await n(s)).hash===t)return s}}var Le=class{buf=new Uint8Array(0);iter;eof=!1;_bytesRead=0;hasher;constructor(e,t=!1){this.iter=e[Symbol.asyncIterator](),this.hasher=t?G():null}get bytesRead(){return this._bytesRead}async pullMore(){if(this.eof)return!1;let{value:e,done:t}=await this.iter.next();if(t||!e)return this.eof=!0,!1;if(this.buf.byteLength===0)this.buf=new Uint8Array(e);else{let n=new Uint8Array(this.buf.byteLength+e.byteLength);n.set(this.buf),n.set(e,this.buf.byteLength),this.buf=n}return!0}async ensure(e){for(;this.buf.byteLength<e;)if(!await this.pullMore())throw new Error(`Unexpected end of pack data: needed ${e} bytes, have ${this.buf.byteLength}`)}consume(e){let t=new Uint8Array(this.buf.subarray(0,e));return this.hasher?.update(t),this.buf=this.buf.subarray(e),this._bytesRead+=e,t}async readByte(){return await this.ensure(1),this.consume(1)[0]}async readExact(e){return await this.ensure(e),this.consume(e)}async readRaw(e){await this.ensure(e);let t=new Uint8Array(this.buf.subarray(0,e));return this.buf=this.buf.subarray(e),this._bytesRead+=e,t}async inflateNext(e){for(this.buf.byteLength===0&&!this.eof&&await this.pullMore();;)try{let{result:t,bytesConsumed:n}=await Ue(this.buf,e);return this.consume(n),t}catch{if(!this.eof&&await this.pullMore())continue;throw new Error(`Failed to inflate pack entry at byte ${this._bytesRead} (expected ${e} bytes)`)}}async hashHex(){if(!this.hasher)throw new Error("Hashing not enabled");return this.hasher.hex()}};async function*St(r,e){let t=new Le(r,!0),n=await t.readExact(12),s=new DataView(n.buffer,n.byteOffset,n.byteLength),a=s.getUint32(0);if(a!==z)throw new Error(`Invalid pack signature: 0x${a.toString(16)} (expected 0x${z.toString(16)})`);let i=s.getUint32(4);if(i!==we)throw new Error(`Unsupported pack version: ${i}`);let o=s.getUint32(8),f=new Map,c=new Map;for(let p=0;p<o;p++){let u=t.bytesRead,h=await t.readByte(),m=h>>4&7,R=h&15,b=4;for(;h&128;)h=await t.readByte(),R|=(h&127)<<b,b+=7;let y,g;if(m===_){let x=await t.readByte();for(y=x&127;x&128;)y+=1,x=await t.readByte(),y=(y<<7)+(x&127);y=u-y}else if(m===te){let x=await t.readExact(20);g=J(x,0)}let w=await t.inflateNext(R),E;if(m!==_&&m!==te){let x=vt[m];if(!x)throw new Error(`Unknown object type: ${m}`);E={type:x,content:w,hash:await q(x,w)}}else if(m===_){let x=f.get(y);if(!x)throw new Error(`OFS_DELTA base not found at offset ${y}`);let O=xe(x.content,w);E={type:x.type,content:O,hash:await q(x.type,O)}}else{let x=c.get(g);if(!x&&e&&(x=await e(g)??void 0),!x)throw new Error(`REF_DELTA base not found for hash ${g}`);let O=xe(x.content,w);E={type:x.type,content:O,hash:await q(x.type,O)}}f.set(u,E),c.set(E.hash,E),yield E}let l=J(await t.readRaw(20),0),d=await t.hashHex();if(d!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${d}`)}function xe(r,e){let t=0,{value:n,newPos:s}=xt(e,t);if(t=s,n!==r.byteLength)throw new Error(`Delta base size mismatch: expected ${n}, got ${r.byteLength}`);let{value:a,newPos:i}=xt(e,t);t=i;let o=new Uint8Array(a),f=0;for(;t<e.byteLength;){let c=e[t++];if(c&128){let l=0,d=0;c&1&&(l=e[t++]),c&2&&(l|=e[t++]<<8),c&4&&(l|=e[t++]<<16),c&8&&(l|=e[t++]<<24),c&16&&(d=e[t++]),c&32&&(d|=e[t++]<<8),c&64&&(d|=e[t++]<<16),d===0&&(d=65536),o.set(r.subarray(l,l+d),f),f+=d}else if(c>0)o.set(e.subarray(t,t+c),f),f+=c,t+=c;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(f!==a)throw new Error(`Delta produced ${f} bytes, expected ${a}`);return o}async function Ee(r){let e=[],t=new Map,n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,z),s.setUint32(4,we),s.setUint32(8,r.length),e.push(n);let a=12,i=[];for(let o of r){let f=a;t.set(o.hash,a);let c=o.delta&&o.deltaBaseHash?t.get(o.deltaBaseHash):void 0;if(o.delta&&c!==void 0){let l=Ce(_,o.delta.byteLength),d=vr(a-c),p=await Re(o.delta);e.push(l,d,p),a+=l.byteLength+d.byteLength+p.byteLength}else{let l=kt[o.type],d=Ce(l,o.content.byteLength),p=await Re(o.content);e.push(d,p),a+=d.byteLength+p.byteLength}i.push({hash:o.hash,offset:f,nextOffset:a})}return{data:await Pr(e),entries:i}}async function*At(r,e){let t=G(),n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,z),s.setUint32(4,we),s.setUint32(8,r),t.update(n),yield n;for await(let a of e){let i=kt[a.type],o=Ce(i,a.content.byteLength),f=await Re(a.content);t.update(o),t.update(f),yield kr(o,f)}yield me(await t.hex())}async function Pr(r){let e=0;for(let i of r)e+=i.byteLength;e+=20;let t=new Uint8Array(e),n=0;for(let i of r)t.set(i,n),n+=i.byteLength;let s=G();s.update(t.subarray(0,n));let a=await s.hex();return t.set(me(a),n),t}function vr(r){let e=[];e.push(r&127);let t=r>>>7;for(;t>0;)e.unshift(128|--t&127),t>>>=7;return new Uint8Array(e)}function Ce(r,e){let t=[],n=r<<4|e&15;for(e>>=4;e>0;)t.push(n|128),n=e&127,e>>=7;return t.push(n),new Uint8Array(t)}function xt(r,e){let t=0,n=0,s;do s=r[e++],t|=(s&127)<<n,n+=7;while(s&128);return{value:t,newPos:e}}function kr(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(r,0),t.set(e,r.byteLength),t}var jr=new TextEncoder;async function q(r,e){let t=jr.encode(`${r} ${e.byteLength}\0`),n=G();return n.update(t),n.update(e),n.hex()}var Sr=new TextEncoder,Dn=new TextDecoder;function It(r,e){let t=Sr.encode(`${r} ${e.byteLength}\0`),n=new Uint8Array(t.byteLength+e.byteLength);return n.set(t),n.set(e,t.byteLength),n}function re(r){let e=r.indexOf("<"),t=r.indexOf(">");if(e===-1||t===-1)throw new Error(`Malformed identity line: "${r}"`);let n=r.slice(0,e).trimEnd(),s=r.slice(e+1,t),a=r.slice(t+2),[i="0",o="+0000"]=a.split(" "),f=parseInt(i,10);return{name:n,email:s,timestamp:f,timezone:o}}var $n=new TextEncoder,Ir=new TextDecoder;function ne(r){let e=Ir.decode(r),t=e.indexOf(`
2
2
 
3
3
  `),n=t===-1?e:e.slice(0,t),s=t===-1?"":e.slice(t+2),a="",i=[],o,f;for(let c of n.split(`
4
- `)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),p=c.slice(l+1);switch(d){case"tree":a=p;break;case"parent":i.push(p);break;case"author":o=te(p);break;case"committer":f=te(p);break}}if(!a)throw new Error("Commit missing tree field");if(!o)throw new Error("Commit missing author field");if(!f)throw new Error("Commit missing committer field");return{type:"commit",tree:a,parents:i,author:o,committer:f,message:s}}var Cn=new TextEncoder,vr=new TextDecoder;function _(r){let e=vr.decode(r),t=e.indexOf(`
4
+ `)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),p=c.slice(l+1);switch(d){case"tree":a=p;break;case"parent":i.push(p);break;case"author":o=re(p);break;case"committer":f=re(p);break}}if(!a)throw new Error("Commit missing tree field");if(!o)throw new Error("Commit missing author field");if(!f)throw new Error("Commit missing committer field");return{type:"commit",tree:a,parents:i,author:o,committer:f,message:s}}var Gn=new TextEncoder,Tr=new TextDecoder;function W(r){let e=Tr.decode(r),t=e.indexOf(`
5
5
 
6
6
  `),n=t===-1?e:e.slice(0,t),s=t===-1?"":e.slice(t+2),a="",i="commit",o="",f;for(let c of n.split(`
7
- `)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),p=c.slice(l+1);switch(d){case"object":a=p;break;case"type":i=p;break;case"tag":o=p;break;case"tagger":f=te(p);break}}if(!a)throw new Error("Tag missing object field");if(!o)throw new Error("Tag missing tag name field");if(!f)throw new Error("Tag missing tagger field");return{type:"tag",object:a,objectType:i,name:o,tagger:f,message:s}}async function ne(r,e){return r.objectStore.read(e)}async function se(r,e){return r.objectStore.exists(e)}var Nn=new TextDecoder;async function X(r,e){let t=await ne(r,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return re(t.content)}function At(r){return typeof r=="string"?{type:"direct",hash:r}:r}var Ce=".lock";var Sr=[1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,5,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,4,4];function jr(r,e,t){let n=0,s=!1,a=e;for(;a<r.length;a++){let o=r.charCodeAt(a);switch(o<128?Sr[o]:0){case 1:break;case 2:if(n===46)return{len:-1,starConsumed:s};n=o;continue;case 3:if(n===64)return{len:-1,starConsumed:s};n=o;continue;case 4:return{len:-1,starConsumed:s};case 5:if(!t)return{len:-1,starConsumed:s};s=!0,n=o;continue;default:n=o;continue}break}let i=a-e;return i===0?{len:0,starConsumed:s}:r.charCodeAt(e)===46?{len:-1,starConsumed:s}:i>=Ce.length&&r.slice(a-Ce.length,a)===Ce?{len:-1,starConsumed:s}:{len:i,starConsumed:s}}function It(r,e=0){if(r==="@"||r.length===0)return!1;let t=0,n=0,s=!!(e&2);for(;t<=r.length;){let{len:a,starConsumed:i}=jr(r,t,s);if(a<0||a===0)return!1;i&&(s=!1),n++,t+=a+1}return!(r.charCodeAt(r.length-1)===46||!(e&1)&&n<2)}var _n=new TextEncoder,Tt=new TextDecoder,Ar=new Set(["100644","100755","040000","120000","160000"]);function Ir(r){return r.length===4&&r.toLowerCase()===".git"}function Tr(r,e){if(r.length===0)throw new Error("invalid tree entry: empty name");if(r.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${r}'`);if(r.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(r==="."||r==="..")throw new Error(`invalid tree entry: '${r}'`);if(Ir(r))throw new Error(`invalid tree entry: '${r}'`);if(!Ar.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${r}'`)}function He(r){let e=[],t=0;for(;t<r.byteLength;){let n=r.indexOf(32,t);if(n===-1)break;let s=Tt.decode(r.subarray(t,n)),a=r.indexOf(0,n+1);if(a===-1)break;let i=Tt.decode(r.subarray(n+1,a)),o=r.subarray(a+1,a+21),f=he(o),c=s.padStart(6,"0");Tr(i,c),e.push({mode:c,name:i,hash:f}),t=a+21}return{type:"tree",entries:e}}async function Ut(r,e,t){if(e===t)return!0;let n=new Set,s=[t],a=0;for(;a<s.length;){let i=s[a++];if(i===e)return!0;if(n.has(i))continue;n.add(i);let o;try{o=await X(r,i)}catch{continue}for(let f of o.parents)n.has(f)||s.push(f)}return!1}var Pe=new Uint32Array([0,2874782929,1454598562,4260027763,104818581,2909197124,1351355959,4225088230,209637162,2804382715,1523426952,4053013081,172075199,2702711918,1559413021,4155209164,419274324,3013880453,1313798134,3843506983,516094401,3046853904,1215402083,3811058866,344150398,3218793903,1110456540,3916008461,314324715,3118826042,1141858121,4015451032,838548648,2594343033,1732793610,3423723995,935615293,2627596268,1635201695,3392046670,1032188802,2531018579,1798740512,3228511985,1002083351,2430804166,1829371317,3327150436,688300796,2187269677,2142620510,3572268943,792315241,2220913080,2039131339,3537049626,628649430,2384582919,1942684788,3633492133,591858243,2283716242,1978950625,3735934768,1677097296,3366964609,893718770,2652677155,1707679429,3465587220,863663975,2552480694,1871230586,3302032043,960225240,2455923465,1773654511,3270403390,1057273933,2489126044,2064377604,3495056341,767069862,2262907511,2100592785,3597481024,730327347,2162056674,2004166702,3693911295,566641036,2325738845,1900695483,3658742634,670639641,2359333576,1376601592,4183093545,79572058,2951190667,1412571757,4285241020,42027983,2849570590,1584630482,4113186307,146858864,2744735649,1481436487,4078262678,251626725,2779131956,1257298860,3785977725,474198542,3071936223,1288682553,3885369576,444388763,2972016970,1183716486,3990331479,272465188,3143944693,1085371155,3957901250,369236657,3176902240,1823819377,3354194592,973483987,2438961922,1787437540,3251868981,1010387014,2539715735,1623951707,3415358858,913891577,2636207144,1727327950,3450690079,809994092,2602447805,1950930981,3742461172,586920327,2309096790,1920450480,3643673441,616879634,2409456323,2016810767,3547309022,780500653,2245839484,2114547866,3578840139,683284792,2212736489,1565424345,4128755208,201134971,2695145386,1534139724,4029196701,230847726,2795225151,1362146803,4201185570,126082129,2899994752,1460654694,4233520823,29146052,2867138325,1169417357,4008333404,318803247,3092855294,1133282072,3906287561,356510394,3194379883,1238182823,3801390966,528368133,3022517972,1341279282,3836475619,423699856,2987954497,256065313,2753203184,1508923011,4071219794,159144116,2720394341,1607414038,4103505351,54390795,2825143514,1435408809,4275514744,84055966,2925208399,1404173884,4175973101,398369141,3169260964,1091422423,3931405318,293717728,3134747185,1194504002,3966442387,465595999,2962872974,1299384317,3861558060,503253450,3064380699,1263296616,3759527097,1052246921,2514597720,1745578539,3276988154,948397084,2480853197,1848905150,3312302447,851889315,2577365106,1685431553,3475771856,888777526,2678071271,1649066644,3373495877,642096605,2367432972,1895232639,3685695662,544930376,2334346905,1992922090,3717211963,708530935,2170742310,2089302869,3620835204,738473314,2271052211,2058837184,3522095121]),Ur=new Uint32Array([0,2125799437,1446245579,679924934,121527623,2039184714,1359849868,800622977,243055246,1892260483,1481592389,653946440,155379657,2012727236,1601245954,566506255,486110492,1649169681,1254785495,880779738,466036827,1701972054,1307892880,859962525,310759314,1815146399,1152793433,973282132,364614357,1796125400,1133012510,1027425811,972220984,1195887157,1874927347,292830974,1053603711,1081710450,1761559476,373973945,932073654,1228632251,1639818365,520651888,816844273,1308962300,1719925050,406247735,621518628,1539227433,1933077487,227363810,573948515,1551950446,1946564264,179508901,729228714,1438778791,2101662049,66187628,743012589,1392269536,2054851622,80718891,1944441968,223409277,634790075,1533214902,1960544567,175024442,585661948,1549622769,2107207422,53235443,732600885,1428142648,2057778105,68293556,747947890,1377953663,1864147308,296321377,959403431,1201305002,1747123243,379051046,1041303776,1084500205,1633688546,534068207,928247593,1239863076,1717454501,418080424,812495470,1322816099,1243037256,883039813,472173187,1653729934,1294557967,865878786,454727620,1706014665,1147897030,987669707,307785741,1827491840,1129699713,1038154124,359017802,1808993607,1458457428,677079897,14532511,2120785810,1372591635,795162142,132375256,2035729109,1486025178,640143831,245433617,1880368412,1605151901,555322512,161437782,1999272027,1284643889,841432124,446818554,1679083767,1269580150,890855803,497006013,1663735216,1122936511,1012631218,350048884,1785229945,1171323896,996531189,333647667,1834364734,1349216557,786319648,106470886,2028846571,1465201770,702551143,23511201,2144592044,1578619811,547550126,136587112,1989216101,1495895780,664579817,253393455,1907317282,1969288713,198563332,592642754,1575363279,1918806862,216763203,611147653,1524137864,2065452167,94989450,758102092,1402640449,2082607552,43463117,705815819,1420084486,1771668245,388801304,1068136414,1092573139,1856495186,269680223,949234329,1176570516,1743075739,424679830,836160848,1331948893,1624990940,510543057,921210903,1214099482,1064814657,1103292492,1766079626,401677447,944346374,1190966539,1853514189,282018240,822833871,1337873090,1731757572,428713481,909455240,1216352133,1611062083,515111758,596557149,1564187984,1975339414,185100699,615571482,1510326295,1921193169,204879068,770836435,1397172190,2076308248,91542293,718035604,1417247385,2097131103,38440530,109388409,2016412276,1354159794,772011711,29065022,2131648307,1468566517,691907576,150575351,1984739578,1590324284,545213489,264750512,1903355325,1509175675,658575734,444356453,1690924904,1280287662,855278499,490867234,1677142575,1265762025,902094564,335605227,1790299622,1110645024,1015429421,322875564,1837863073,1158497383,1001940074]),we=64,Lr=4,De=4096,Lt=65536,Cr=127;function Hr(r){let e=r.byteLength;if(e===0)return null;let t=(e-1)/16|0;if(t===0)return null;let n=t>>>2;n<16&&(n=16),n=Nr(n);let s=n-1,a=new Uint32Array(n),i=[],o=-1>>>0;for(let p=t*16-16;p>=0;p-=16){let u=0;for(let h=1;h<=16;h++)u=(u<<8|r[p+h])^Pe[u>>>23];if(u=u>>>0,u===o)i[i.length-1].ptr=p+16;else{o=u;let h=u&s;i.push({ptr:p+16,val:u}),a[h]++}}let f=new Map;for(let p of i){let u=p.val&s,h=f.get(u);h||(h=[],f.set(u,h)),h.push(p)}for(let[p,u]of f){if(u.length<=we)continue;let h=[],m=u.length/we;for(let g=0;g<we;g++)h.push(u[Math.floor(g*m)]);f.set(p,h),a[p]=we}let c=new Uint32Array(n+1),l=[],d=0;for(let p=0;p<n;p++){c[p]=d;let u=f.get(p);if(u){for(let h of u)l.push(h);d+=u.length}}return c[n]=d,{src:r,hashMask:s,buckets:c,entries:l}}function Dr(r,e,t){if(!r||e.byteLength===0)return null;let n=r.src.byteLength,s=e.byteLength,a=r.src,i=new Uint8Array(Math.max(s,1024)),o=0;function f(m){for(;o+m>i.length;){let g=new Uint8Array(i.length*2);g.set(i),i=g}}o=Ht(i,o,n),o=Ht(i,o,s),f(18),o++;let c=0,l=0,d=Math.min(16,s);for(let m=0;m<d;m++)i[o++]=e[m],c=(c<<8|e[m])^Pe[c>>>23],l++;c=c>>>0;let p=d,u=0,h=0;for(;p<s;){if(h<De){c^=Ur[e[p-16]],c=((c<<8|e[p])^Pe[c>>>23])>>>0;let m=c&r.hashMask,g=r.buckets[m],b=r.buckets[m+1];for(let y=g;y<b;y++){let R=r.entries[y];if(R.val!==c)continue;let w=R.ptr,P=a.byteLength-w,x=s-p;if(P>x&&(P=x),P<=h)break;let O=0;for(;O<P&&a[w+O]===e[p+O];)O++;if(O>h&&(h=O,u=w,h>=De))break}}if(h<Lr)f(2),l===0&&o++,i[o++]=e[p++],l++,l===Cr&&(i[o-l-1]=l,l=0),h=0;else{if(l>0){for(;u>0&&a[u-1]===e[p-1];)if(h++,u--,p--,o--,!(--l>0)){o--,l=-1;break}l>0&&(i[o-l-1]=l),l=0}let m=h>Lt?h-Lt:0;h-=m,f(8);let g=o++,b=128;if(u&255&&(i[o++]=u&255,b|=1),u&65280&&(i[o++]=u>>>8&255,b|=2),u&16711680&&(i[o++]=u>>>16&255,b|=4),u&4278190080&&(i[o++]=u>>>24&255,b|=8),h&255&&(i[o++]=h&255,b|=16),h&65280&&(i[o++]=h>>>8&255,b|=32),i[g]=b,p+=h,u+=h,h=m,u>4294967295&&(h=0),h<De){c=0;for(let y=-16;y<0;y++)c=(c<<8|e[p+y])^Pe[c>>>23];c=c>>>0}}if(t&&o>t)return null}return l>0&&(i[o-l-1]=l),t&&o>t?null:i.subarray(0,o)}var Ct={blob:0,tree:1,commit:2,tag:3};function Dt(r,e){let t=e?.window??10,n=e?.depth??50,s=r.slice().sort((c,l)=>{let d=Ct[c.type]??99,p=Ct[l.type]??99;return d!==p?d-p:l.content.byteLength-c.content.byteLength}),a=new Map,i=[],o=[],f=[];for(let c=0;c<s.length;c++){let l=s[c],d={hash:l.hash,type:l.type,content:l.content,depth:0},p=null,u=null,h=Math.max(0,c-t);for(let m=c-1;m>=h;m--){let g=s[m];if(g.type!==l.type||(a.get(g.hash)?.depth??0)>=n||l.content.byteLength<g.content.byteLength>>>5)continue;let R=o[m-h]??null;if(!R)continue;let w=p?p.byteLength:l.content.byteLength/2|0;if(w<16)continue;let P=Dr(R,l.content,w);P&&(!p||P.byteLength<p.byteLength)&&(p=P,u=g.hash)}if(p&&u){d.delta=p,d.deltaBase=u;let m=a.get(u);d.depth=(m?.depth??0)+1}a.set(l.hash,d),i.push(d),o.length>=t&&(o.shift(),f.shift()),o.push(Hr(l.content)),f.push(l.hash)}return i}function Nr(r){let e=r;return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e<16?16:e}function Ht(r,e,t){let n=t;do{let s=n&127;n>>>=7,n>0&&(s|=128),r[e++]=s}while(n>0);return e}var Br=2147483647;async function Nt(r,e,t,n){if(t>=Br)return{shallow:[],unshallow:[...n]};let s=new Map,a=[];for(let c of e)!s.has(c)&&await se(r,c)&&(s.set(c,1),a.push({hash:c,level:1}));let i=new Set,o=0;for(;o<a.length;){let{hash:c,level:l}=a[o++];if(l>=t){i.add(c);continue}let d;try{d=await X(r,c)}catch{continue}for(let p of d.parents)!s.has(p)&&await se(r,p)&&(s.set(p,l+1),a.push({hash:p,level:l+1}))}let f=[];for(let c of n){let l=s.get(c);l!==void 0&&l<t&&f.push(c)}return{shallow:[...i],unshallow:f}}async function Ne(r,e,t,n,s){let a=s??n,i=new Set;for(let l of t)await ae(r,l,i,a);let o=[...e];if(s&&n)for(let l of s)try{let d=await X(r,l);for(let p of d.parents)i.has(p)||o.push(p)}catch{}let f=[],c=new Set;for(let l of o)await oe(r,l,i,c,f,n);return{count:f.length,objects:Mr(f)}}async function Bt(r,e,t,n,s){let{count:a,objects:i}=await Ne(r,e,t,n,s);return{count:a,objects:$r(r,i)}}async function*Mr(r){for(let e of r)yield e}async function*$r(r,e){for await(let t of e){let n=await ne(r,t.hash);yield{hash:t.hash,type:t.type,content:n.content}}}async function Mt(r){let e=[];for await(let t of r.objects)e.push(t);return e}async function ae(r,e,t,n){if(t.has(e)||(t.add(e),!await se(r,e)))return;let s=await ne(r,e);switch(s.type){case"commit":{let a=re(s.content);if(await ae(r,a.tree,t,n),!n?.has(e))for(let i of a.parents)await ae(r,i,t,n);break}case"tree":{let a=He(s.content);for(let i of a.entries)await ae(r,i.hash,t,n);break}case"tag":{let a=_(s.content);await ae(r,a.object,t,n);break}case"blob":break}}async function oe(r,e,t,n,s,a){if(n.has(e)||t.has(e))return;n.add(e);let i=await ne(r,e);switch(s.push({hash:e,type:i.type}),i.type){case"commit":{let o=re(i.content);if(await oe(r,o.tree,t,n,s,a),!a?.has(e))for(let f of o.parents)await oe(r,f,t,n,s,a);break}case"tree":{let o=He(i.content);for(let f of o.entries)await oe(r,f.hash,t,n,s,a);break}case"tag":{let o=_(i.content);await oe(r,o.object,t,n,s,a);break}case"blob":break}}var Wr=new TextEncoder,Wt=new TextDecoder,$t=65520,_r=new Uint8Array([48,48,48,48]);function k(r){let e=typeof r=="string"?Wr.encode(r):r,t=4+e.byteLength;if(t>$t)throw new Error(`pkt-line too long: ${t} bytes (max ${$t})`);let n=t.toString(16).padStart(4,"0"),s=new Uint8Array(t);return s[0]=n.charCodeAt(0),s[1]=n.charCodeAt(1),s[2]=n.charCodeAt(2),s[3]=n.charCodeAt(3),s.set(e,4),s}function D(){return _r.slice()}function B(...r){let e=0;for(let s of r)e+=s.byteLength;let t=new Uint8Array(e),n=0;for(let s of r)t.set(s,n),n+=s.byteLength;return t}function _t(r){let e=[],t=0;for(;t<r.byteLength;){if(t+4>r.byteLength)throw new Error("Truncated pkt-line header");let n=Wt.decode(r.subarray(t,t+4)),s=parseInt(n,16);if(Number.isNaN(s))throw new Error(`Invalid pkt-line length: ${n}`);if(s===0){e.push({type:"flush"}),t+=4;continue}if(s<4)throw new Error(`Invalid pkt-line length: ${s}`);if(t+s>r.byteLength)throw new Error(`Truncated pkt-line: need ${s} bytes at offset ${t}, have ${r.byteLength-t}`);e.push({type:"data",data:r.subarray(t+4,t+s)}),t+=s}return e}function Gt(r){if(r.type==="flush")return"";let e=Wt.decode(r.data);return e.endsWith(`
8
- `)?e.slice(0,-1):e}var Ft=65515;function Oe(r,e,t){let n=[],s=[...e];t&&s.push(`symref=HEAD:${t}`),s.push("agent=just-git/1.0");let a=s.join(" ");if(r.length===0)n.push(k(`0000000000000000000000000000000000000000 capabilities^{}\0${a}
9
- `));else for(let i=0;i<r.length;i++){let o=r[i];i===0?n.push(k(`${o.hash} ${o.name}\0${a}
10
- `)):n.push(k(`${o.hash} ${o.name}
11
- `))}return n.push(D()),B(...n)}function qt(r,e,t,n){let s=B(k(`# service=${e}
12
- `),D()),a=Oe(r,t,n),i=new Uint8Array(s.byteLength+a.byteLength);return i.set(s,0),i.set(a,s.byteLength),i}function zt(r){let e=_t(r),t=[],n=[],s=[],a=[],i,o=!1;for(let f of e){if(f.type==="flush")continue;let c=Gt(f);if(c.startsWith("want ")){let l=c.slice(5);if(t.length===0){let d=l.indexOf(" ");d!==-1?(t.push(l.slice(0,d)),a=l.slice(d+1).split(" ").filter(Boolean)):t.push(l)}else t.push(l)}else c.startsWith("have ")?n.push(c.slice(5)):c.startsWith("shallow ")?s.push(c.slice(8)):c.startsWith("deepen ")?(i=parseInt(c.slice(7),10),Number.isNaN(i)&&(i=void 0)):c==="done"&&(o=!0)}return{wants:t,haves:n,capabilities:a,clientShallows:s,depth:i,done:o}}function K(r,e,t,n){let s=[];if(n){for(let a of n.shallow)s.push(k(`shallow ${a}
13
- `));for(let a of n.unshallow)s.push(k(`unshallow ${a}
14
- `));s.push(D())}if(t&&t.length>0){for(let i of t)s.push(k(`ACK ${i} common
15
- `));let a=t[t.length-1];s.push(k(`ACK ${a} ready
16
- `)),s.push(k(`ACK ${a}
17
- `))}else s.push(k(`NAK
18
- `));if(e){let a=0;for(;a<r.byteLength;){let i=Math.min(Ft,r.byteLength-a);s.push(Be(1,r.subarray(a,a+i))),a+=i}s.push(D())}else{let a=new Uint8Array(r.byteLength);a.set(r),s.push(a)}return B(...s)}function Xt(r){let e=[];for(let t of r.shallow)e.push(k(`shallow ${t}
19
- `));for(let t of r.unshallow)e.push(k(`unshallow ${t}
20
- `));return e.push(D()),B(...e)}async function*Kt(r,e,t,n){if(n){let a=[];for(let i of n.shallow)a.push(k(`shallow ${i}
21
- `));for(let i of n.unshallow)a.push(k(`unshallow ${i}
22
- `));a.push(D()),yield B(...a)}let s=[];if(t&&t.length>0){for(let i of t)s.push(k(`ACK ${i} common
23
- `));let a=t[t.length-1];s.push(k(`ACK ${a} ready
24
- `)),s.push(k(`ACK ${a}
25
- `))}else s.push(k(`NAK
26
- `));if(yield B(...s),e){for await(let a of r){let i=0;for(;i<a.byteLength;){let o=Math.min(Ft,a.byteLength-i);yield Be(1,a.subarray(i,i+o)),i+=o}}yield D()}else for await(let a of r)yield a}function Yt(r){let e=new TextDecoder,t=[],n=[],s=0,a=!1;for(;s<r.byteLength&&!(s+4>r.byteLength);){let o=e.decode(r.subarray(s,s+4)),f=parseInt(o,16);if(Number.isNaN(f))break;if(f===0){a=!0,s+=4;break}if(f<4||s+f>r.byteLength)break;let c=r.subarray(s+4,s+f);s+=f;let l=c.indexOf(0),d;if(l!==-1)d=e.decode(c.subarray(0,l)),n=e.decode(c.subarray(l+1)).replace(/\n$/,"").split(" ").filter(Boolean);else{let u=e.decode(c);d=u.endsWith(`
27
- `)?u.slice(0,-1):u}let p=d.split(" ");p.length>=3&&t.push({oldHash:p[0],newHash:p[1],refName:p[2]})}let i=s<r.byteLength?r.subarray(s):new Uint8Array(0);return{commands:t,packData:i,capabilities:n,sawFlush:a}}function Y(r,e,t){let n=[];n.push(k(r?`unpack ok
7
+ `)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),p=c.slice(l+1);switch(d){case"object":a=p;break;case"type":i=p;break;case"tag":o=p;break;case"tagger":f=re(p);break}}if(!a)throw new Error("Tag missing object field");if(!o)throw new Error("Tag missing tag name field");if(!f)throw new Error("Tag missing tagger field");return{type:"tag",object:a,objectType:i,name:o,tagger:f,message:s}}async function se(r,e){return r.objectStore.read(e)}async function ae(r,e){return r.objectStore.exists(e)}var zn=new TextDecoder;async function X(r,e){let t=await se(r,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return ne(t.content)}function Tt(r){return typeof r=="string"?{type:"direct",hash:r}:r}var He=".lock";var Ur=[1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,5,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,4,4];function Lr(r,e,t){let n=0,s=!1,a=e;for(;a<r.length;a++){let o=r.charCodeAt(a);switch(o<128?Ur[o]:0){case 1:break;case 2:if(n===46)return{len:-1,starConsumed:s};n=o;continue;case 3:if(n===64)return{len:-1,starConsumed:s};n=o;continue;case 4:return{len:-1,starConsumed:s};case 5:if(!t)return{len:-1,starConsumed:s};s=!0,n=o;continue;default:n=o;continue}break}let i=a-e;return i===0?{len:0,starConsumed:s}:r.charCodeAt(e)===46?{len:-1,starConsumed:s}:i>=He.length&&r.slice(a-He.length,a)===He?{len:-1,starConsumed:s}:{len:i,starConsumed:s}}function Ut(r,e=0){if(r==="@"||r.length===0)return!1;let t=0,n=0,s=!!(e&2);for(;t<=r.length;){let{len:a,starConsumed:i}=Lr(r,t,s);if(a<0||a===0)return!1;i&&(s=!1),n++,t+=a+1}return!(r.charCodeAt(r.length-1)===46||!(e&1)&&n<2)}var Cr=10;async function Hr(r,e){return r.refStore.readRef(e)}async function Lt(r,e){let t=e;for(let n=0;n<Cr;n++){let s=await Hr(r,t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}var Zn=new TextEncoder,Ct=new TextDecoder,Dr=new Set(["100644","100755","040000","120000","160000"]);function Nr(r){return r.length===4&&r.toLowerCase()===".git"}function Mr(r,e){if(r.length===0)throw new Error("invalid tree entry: empty name");if(r.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${r}'`);if(r.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(r==="."||r==="..")throw new Error(`invalid tree entry: '${r}'`);if(Nr(r))throw new Error(`invalid tree entry: '${r}'`);if(!Dr.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${r}'`)}function De(r){let e=[],t=0;for(;t<r.byteLength;){let n=r.indexOf(32,t);if(n===-1)break;let s=Ct.decode(r.subarray(t,n)),a=r.indexOf(0,n+1);if(a===-1)break;let i=Ct.decode(r.subarray(n+1,a)),o=r.subarray(a+1,a+21),f=be(o),c=s.padStart(6,"0");Mr(i,c),e.push({mode:c,name:i,hash:f}),t=a+21}return{type:"tree",entries:e}}async function Ne(r,e,t){if(e===t)return!0;let n=new Set,s=[t],a=0;for(;a<s.length;){let i=s[a++];if(i===e)return!0;if(n.has(i))continue;n.add(i);let o;try{o=await X(r,i)}catch{continue}for(let f of o.parents)n.has(f)||s.push(f)}return!1}var Pe=new Uint32Array([0,2874782929,1454598562,4260027763,104818581,2909197124,1351355959,4225088230,209637162,2804382715,1523426952,4053013081,172075199,2702711918,1559413021,4155209164,419274324,3013880453,1313798134,3843506983,516094401,3046853904,1215402083,3811058866,344150398,3218793903,1110456540,3916008461,314324715,3118826042,1141858121,4015451032,838548648,2594343033,1732793610,3423723995,935615293,2627596268,1635201695,3392046670,1032188802,2531018579,1798740512,3228511985,1002083351,2430804166,1829371317,3327150436,688300796,2187269677,2142620510,3572268943,792315241,2220913080,2039131339,3537049626,628649430,2384582919,1942684788,3633492133,591858243,2283716242,1978950625,3735934768,1677097296,3366964609,893718770,2652677155,1707679429,3465587220,863663975,2552480694,1871230586,3302032043,960225240,2455923465,1773654511,3270403390,1057273933,2489126044,2064377604,3495056341,767069862,2262907511,2100592785,3597481024,730327347,2162056674,2004166702,3693911295,566641036,2325738845,1900695483,3658742634,670639641,2359333576,1376601592,4183093545,79572058,2951190667,1412571757,4285241020,42027983,2849570590,1584630482,4113186307,146858864,2744735649,1481436487,4078262678,251626725,2779131956,1257298860,3785977725,474198542,3071936223,1288682553,3885369576,444388763,2972016970,1183716486,3990331479,272465188,3143944693,1085371155,3957901250,369236657,3176902240,1823819377,3354194592,973483987,2438961922,1787437540,3251868981,1010387014,2539715735,1623951707,3415358858,913891577,2636207144,1727327950,3450690079,809994092,2602447805,1950930981,3742461172,586920327,2309096790,1920450480,3643673441,616879634,2409456323,2016810767,3547309022,780500653,2245839484,2114547866,3578840139,683284792,2212736489,1565424345,4128755208,201134971,2695145386,1534139724,4029196701,230847726,2795225151,1362146803,4201185570,126082129,2899994752,1460654694,4233520823,29146052,2867138325,1169417357,4008333404,318803247,3092855294,1133282072,3906287561,356510394,3194379883,1238182823,3801390966,528368133,3022517972,1341279282,3836475619,423699856,2987954497,256065313,2753203184,1508923011,4071219794,159144116,2720394341,1607414038,4103505351,54390795,2825143514,1435408809,4275514744,84055966,2925208399,1404173884,4175973101,398369141,3169260964,1091422423,3931405318,293717728,3134747185,1194504002,3966442387,465595999,2962872974,1299384317,3861558060,503253450,3064380699,1263296616,3759527097,1052246921,2514597720,1745578539,3276988154,948397084,2480853197,1848905150,3312302447,851889315,2577365106,1685431553,3475771856,888777526,2678071271,1649066644,3373495877,642096605,2367432972,1895232639,3685695662,544930376,2334346905,1992922090,3717211963,708530935,2170742310,2089302869,3620835204,738473314,2271052211,2058837184,3522095121]),Br=new Uint32Array([0,2125799437,1446245579,679924934,121527623,2039184714,1359849868,800622977,243055246,1892260483,1481592389,653946440,155379657,2012727236,1601245954,566506255,486110492,1649169681,1254785495,880779738,466036827,1701972054,1307892880,859962525,310759314,1815146399,1152793433,973282132,364614357,1796125400,1133012510,1027425811,972220984,1195887157,1874927347,292830974,1053603711,1081710450,1761559476,373973945,932073654,1228632251,1639818365,520651888,816844273,1308962300,1719925050,406247735,621518628,1539227433,1933077487,227363810,573948515,1551950446,1946564264,179508901,729228714,1438778791,2101662049,66187628,743012589,1392269536,2054851622,80718891,1944441968,223409277,634790075,1533214902,1960544567,175024442,585661948,1549622769,2107207422,53235443,732600885,1428142648,2057778105,68293556,747947890,1377953663,1864147308,296321377,959403431,1201305002,1747123243,379051046,1041303776,1084500205,1633688546,534068207,928247593,1239863076,1717454501,418080424,812495470,1322816099,1243037256,883039813,472173187,1653729934,1294557967,865878786,454727620,1706014665,1147897030,987669707,307785741,1827491840,1129699713,1038154124,359017802,1808993607,1458457428,677079897,14532511,2120785810,1372591635,795162142,132375256,2035729109,1486025178,640143831,245433617,1880368412,1605151901,555322512,161437782,1999272027,1284643889,841432124,446818554,1679083767,1269580150,890855803,497006013,1663735216,1122936511,1012631218,350048884,1785229945,1171323896,996531189,333647667,1834364734,1349216557,786319648,106470886,2028846571,1465201770,702551143,23511201,2144592044,1578619811,547550126,136587112,1989216101,1495895780,664579817,253393455,1907317282,1969288713,198563332,592642754,1575363279,1918806862,216763203,611147653,1524137864,2065452167,94989450,758102092,1402640449,2082607552,43463117,705815819,1420084486,1771668245,388801304,1068136414,1092573139,1856495186,269680223,949234329,1176570516,1743075739,424679830,836160848,1331948893,1624990940,510543057,921210903,1214099482,1064814657,1103292492,1766079626,401677447,944346374,1190966539,1853514189,282018240,822833871,1337873090,1731757572,428713481,909455240,1216352133,1611062083,515111758,596557149,1564187984,1975339414,185100699,615571482,1510326295,1921193169,204879068,770836435,1397172190,2076308248,91542293,718035604,1417247385,2097131103,38440530,109388409,2016412276,1354159794,772011711,29065022,2131648307,1468566517,691907576,150575351,1984739578,1590324284,545213489,264750512,1903355325,1509175675,658575734,444356453,1690924904,1280287662,855278499,490867234,1677142575,1265762025,902094564,335605227,1790299622,1110645024,1015429421,322875564,1837863073,1158497383,1001940074]),Oe=64,$r=4,Me=4096,Ht=65536,_r=127;function Wr(r){let e=r.byteLength;if(e===0)return null;let t=(e-1)/16|0;if(t===0)return null;let n=t>>>2;n<16&&(n=16),n=Fr(n);let s=n-1,a=new Uint32Array(n),i=[],o=-1>>>0;for(let p=t*16-16;p>=0;p-=16){let u=0;for(let h=1;h<=16;h++)u=(u<<8|r[p+h])^Pe[u>>>23];if(u=u>>>0,u===o)i[i.length-1].ptr=p+16;else{o=u;let h=u&s;i.push({ptr:p+16,val:u}),a[h]++}}let f=new Map;for(let p of i){let u=p.val&s,h=f.get(u);h||(h=[],f.set(u,h)),h.push(p)}for(let[p,u]of f){if(u.length<=Oe)continue;let h=[],m=u.length/Oe;for(let R=0;R<Oe;R++)h.push(u[Math.floor(R*m)]);f.set(p,h),a[p]=Oe}let c=new Uint32Array(n+1),l=[],d=0;for(let p=0;p<n;p++){c[p]=d;let u=f.get(p);if(u){for(let h of u)l.push(h);d+=u.length}}return c[n]=d,{src:r,hashMask:s,buckets:c,entries:l}}function Gr(r,e,t){if(!r||e.byteLength===0)return null;let n=r.src.byteLength,s=e.byteLength,a=r.src,i=new Uint8Array(Math.max(s,1024)),o=0;function f(m){for(;o+m>i.length;){let R=new Uint8Array(i.length*2);R.set(i),i=R}}o=Nt(i,o,n),o=Nt(i,o,s),f(18),o++;let c=0,l=0,d=Math.min(16,s);for(let m=0;m<d;m++)i[o++]=e[m],c=(c<<8|e[m])^Pe[c>>>23],l++;c=c>>>0;let p=d,u=0,h=0;for(;p<s;){if(h<Me){c^=Br[e[p-16]],c=((c<<8|e[p])^Pe[c>>>23])>>>0;let m=c&r.hashMask,R=r.buckets[m],b=r.buckets[m+1];for(let y=R;y<b;y++){let g=r.entries[y];if(g.val!==c)continue;let w=g.ptr,E=a.byteLength-w,x=s-p;if(E>x&&(E=x),E<=h)break;let O=0;for(;O<E&&a[w+O]===e[p+O];)O++;if(O>h&&(h=O,u=w,h>=Me))break}}if(h<$r)f(2),l===0&&o++,i[o++]=e[p++],l++,l===_r&&(i[o-l-1]=l,l=0),h=0;else{if(l>0){for(;u>0&&a[u-1]===e[p-1];)if(h++,u--,p--,o--,!(--l>0)){o--,l=-1;break}l>0&&(i[o-l-1]=l),l=0}let m=h>Ht?h-Ht:0;h-=m,f(8);let R=o++,b=128;if(u&255&&(i[o++]=u&255,b|=1),u&65280&&(i[o++]=u>>>8&255,b|=2),u&16711680&&(i[o++]=u>>>16&255,b|=4),u&4278190080&&(i[o++]=u>>>24&255,b|=8),h&255&&(i[o++]=h&255,b|=16),h&65280&&(i[o++]=h>>>8&255,b|=32),i[R]=b,p+=h,u+=h,h=m,u>4294967295&&(h=0),h<Me){c=0;for(let y=-16;y<0;y++)c=(c<<8|e[p+y])^Pe[c>>>23];c=c>>>0}}if(t&&o>t)return null}return l>0&&(i[o-l-1]=l),t&&o>t?null:i.subarray(0,o)}var Dt={blob:0,tree:1,commit:2,tag:3};function Mt(r,e){let t=e?.window??10,n=e?.depth??50,s=r.slice().sort((c,l)=>{let d=Dt[c.type]??99,p=Dt[l.type]??99;return d!==p?d-p:l.content.byteLength-c.content.byteLength}),a=new Map,i=[],o=[],f=[];for(let c=0;c<s.length;c++){let l=s[c],d={hash:l.hash,type:l.type,content:l.content,depth:0},p=null,u=null,h=Math.max(0,c-t);for(let m=c-1;m>=h;m--){let R=s[m];if(R.type!==l.type||(a.get(R.hash)?.depth??0)>=n||l.content.byteLength<R.content.byteLength>>>5)continue;let g=o[m-h]??null;if(!g)continue;let w=p?p.byteLength:l.content.byteLength/2|0;if(w<16)continue;let E=Gr(g,l.content,w);E&&(!p||E.byteLength<p.byteLength)&&(p=E,u=R.hash)}if(p&&u){d.delta=p,d.deltaBase=u;let m=a.get(u);d.depth=(m?.depth??0)+1}a.set(l.hash,d),i.push(d),o.length>=t&&(o.shift(),f.shift()),o.push(Wr(l.content)),f.push(l.hash)}return i}function Fr(r){let e=r;return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e<16?16:e}function Nt(r,e,t){let n=t;do{let s=n&127;n>>>=7,n>0&&(s|=128),r[e++]=s}while(n>0);return e}var qr=2147483647;async function Bt(r,e,t,n){if(t>=qr)return{shallow:[],unshallow:[...n]};let s=new Map,a=[];for(let c of e)!s.has(c)&&await ae(r,c)&&(s.set(c,1),a.push({hash:c,level:1}));let i=new Set,o=0;for(;o<a.length;){let{hash:c,level:l}=a[o++];if(l>=t){i.add(c);continue}let d;try{d=await X(r,c)}catch{continue}for(let p of d.parents)!s.has(p)&&await ae(r,p)&&(s.set(p,l+1),a.push({hash:p,level:l+1}))}let f=[];for(let c of n){let l=s.get(c);l!==void 0&&l<t&&f.push(c)}return{shallow:[...i],unshallow:f}}async function ce(r,e,t,n,s){let a=s??n,i=new Set;for(let l of t)await oe(r,l,i,a);let o=[...e];if(s&&n)for(let l of s)try{let d=await X(r,l);for(let p of d.parents)i.has(p)||o.push(p)}catch{}let f=[],c=new Set;for(let l of o)await ie(r,l,i,c,f,n);return{count:f.length,objects:zr(f)}}async function $t(r,e,t,n,s){let{count:a,objects:i}=await ce(r,e,t,n,s);return{count:a,objects:Xr(r,i)}}async function*zr(r){for(let e of r)yield e}async function*Xr(r,e){for await(let t of e){let n=await se(r,t.hash);yield{hash:t.hash,type:t.type,content:n.content}}}async function _t(r){let e=[];for await(let t of r.objects)e.push(t);return e}async function oe(r,e,t,n){if(t.has(e)||(t.add(e),!await ae(r,e)))return;let s=await se(r,e);switch(s.type){case"commit":{let a=ne(s.content);if(await oe(r,a.tree,t,n),!n?.has(e))for(let i of a.parents)await oe(r,i,t,n);break}case"tree":{let a=De(s.content);for(let i of a.entries)await oe(r,i.hash,t,n);break}case"tag":{let a=W(s.content);await oe(r,a.object,t,n);break}case"blob":break}}async function ie(r,e,t,n,s,a){if(n.has(e)||t.has(e))return;n.add(e);let i=await se(r,e);switch(s.push({hash:e,type:i.type}),i.type){case"commit":{let o=ne(i.content);if(await ie(r,o.tree,t,n,s,a),!a?.has(e))for(let f of o.parents)await ie(r,f,t,n,s,a);break}case"tree":{let o=De(i.content);for(let f of o.entries)await ie(r,f.hash,t,n,s,a);break}case"tag":{let o=W(i.content);await ie(r,o.object,t,n,s,a);break}case"blob":break}}var Kr=new TextEncoder,Gt=new TextDecoder,Wt=65520,Yr=new Uint8Array([48,48,48,48]);function v(r){let e=typeof r=="string"?Kr.encode(r):r,t=4+e.byteLength;if(t>Wt)throw new Error(`pkt-line too long: ${t} bytes (max ${Wt})`);let n=t.toString(16).padStart(4,"0"),s=new Uint8Array(t);return s[0]=n.charCodeAt(0),s[1]=n.charCodeAt(1),s[2]=n.charCodeAt(2),s[3]=n.charCodeAt(3),s.set(e,4),s}function D(){return Yr.slice()}function M(...r){let e=0;for(let s of r)e+=s.byteLength;let t=new Uint8Array(e),n=0;for(let s of r)t.set(s,n),n+=s.byteLength;return t}function Ft(r){let e=[],t=0;for(;t<r.byteLength;){if(t+4>r.byteLength)throw new Error("Truncated pkt-line header");let n=Gt.decode(r.subarray(t,t+4)),s=parseInt(n,16);if(Number.isNaN(s))throw new Error(`Invalid pkt-line length: ${n}`);if(s===0){e.push({type:"flush"}),t+=4;continue}if(s<4)throw new Error(`Invalid pkt-line length: ${s}`);if(t+s>r.byteLength)throw new Error(`Truncated pkt-line: need ${s} bytes at offset ${t}, have ${r.byteLength-t}`);e.push({type:"data",data:r.subarray(t+4,t+s)}),t+=s}return e}function qt(r){if(r.type==="flush")return"";let e=Gt.decode(r.data);return e.endsWith(`
8
+ `)?e.slice(0,-1):e}var zt=65515;function ve(r,e,t){let n=[],s=[...e];t&&s.push(`symref=HEAD:${t}`),s.push("agent=just-git/1.0");let a=s.join(" ");if(r.length===0)n.push(v(`0000000000000000000000000000000000000000 capabilities^{}\0${a}
9
+ `));else for(let i=0;i<r.length;i++){let o=r[i];i===0?n.push(v(`${o.hash} ${o.name}\0${a}
10
+ `)):n.push(v(`${o.hash} ${o.name}
11
+ `))}return n.push(D()),M(...n)}function Xt(r,e,t,n){let s=M(v(`# service=${e}
12
+ `),D()),a=ve(r,t,n),i=new Uint8Array(s.byteLength+a.byteLength);return i.set(s,0),i.set(a,s.byteLength),i}function Kt(r){let e=Ft(r),t=[],n=[],s=[],a=[],i,o=!1;for(let f of e){if(f.type==="flush")continue;let c=qt(f);if(c.startsWith("want ")){let l=c.slice(5);if(t.length===0){let d=l.indexOf(" ");d!==-1?(t.push(l.slice(0,d)),a=l.slice(d+1).split(" ").filter(Boolean)):t.push(l)}else t.push(l)}else c.startsWith("have ")?n.push(c.slice(5)):c.startsWith("shallow ")?s.push(c.slice(8)):c.startsWith("deepen ")?(i=parseInt(c.slice(7),10),Number.isNaN(i)&&(i=void 0)):c==="done"&&(o=!0)}return{wants:t,haves:n,capabilities:a,clientShallows:s,depth:i,done:o}}function K(r,e,t,n){let s=[];if(n){for(let a of n.shallow)s.push(v(`shallow ${a}
13
+ `));for(let a of n.unshallow)s.push(v(`unshallow ${a}
14
+ `));s.push(D())}if(t&&t.length>0){for(let i of t)s.push(v(`ACK ${i} common
15
+ `));let a=t[t.length-1];s.push(v(`ACK ${a} ready
16
+ `)),s.push(v(`ACK ${a}
17
+ `))}else s.push(v(`NAK
18
+ `));if(e){let a=0;for(;a<r.byteLength;){let i=Math.min(zt,r.byteLength-a);s.push(Be(1,r.subarray(a,a+i))),a+=i}s.push(D())}else{let a=new Uint8Array(r.byteLength);a.set(r),s.push(a)}return M(...s)}function Yt(r){let e=[];for(let t of r.shallow)e.push(v(`shallow ${t}
19
+ `));for(let t of r.unshallow)e.push(v(`unshallow ${t}
20
+ `));return e.push(D()),M(...e)}async function*Vt(r,e,t,n){if(n){let a=[];for(let i of n.shallow)a.push(v(`shallow ${i}
21
+ `));for(let i of n.unshallow)a.push(v(`unshallow ${i}
22
+ `));a.push(D()),yield M(...a)}let s=[];if(t&&t.length>0){for(let i of t)s.push(v(`ACK ${i} common
23
+ `));let a=t[t.length-1];s.push(v(`ACK ${a} ready
24
+ `)),s.push(v(`ACK ${a}
25
+ `))}else s.push(v(`NAK
26
+ `));if(yield M(...s),e){for await(let a of r){let i=0;for(;i<a.byteLength;){let o=Math.min(zt,a.byteLength-i);yield Be(1,a.subarray(i,i+o)),i+=o}}yield D()}else for await(let a of r)yield a}function Zt(r){let e=new TextDecoder,t=[],n=[],s=0,a=!1;for(;s<r.byteLength&&!(s+4>r.byteLength);){let o=e.decode(r.subarray(s,s+4)),f=parseInt(o,16);if(Number.isNaN(f))break;if(f===0){a=!0,s+=4;break}if(f<4||s+f>r.byteLength)break;let c=r.subarray(s+4,s+f);s+=f;let l=c.indexOf(0),d;if(l!==-1)d=e.decode(c.subarray(0,l)),n=e.decode(c.subarray(l+1)).replace(/\n$/,"").split(" ").filter(Boolean);else{let u=e.decode(c);d=u.endsWith(`
27
+ `)?u.slice(0,-1):u}let p=d.split(" ");p.length>=3&&t.push({oldHash:p[0],newHash:p[1],refName:p[2]})}let i=s<r.byteLength?r.subarray(s):new Uint8Array(0);return{commands:t,packData:i,capabilities:n,sawFlush:a}}function Y(r,e,t){let n=[];n.push(v(r?`unpack ok
28
28
  `:`unpack error
29
- `));for(let a of e)a.ok?n.push(k(`ok ${a.name}
30
- `)):n.push(k(`ng ${a.name} ${a.error??"failed"}
31
- `));n.push(D());let s=B(...n);if(t){let a=[];return a.push(Be(1,s)),a.push(D()),B(...a)}return s}function Be(r,e){let t=new Uint8Array(1+e.byteLength);return t[0]=r,t.set(e,1),k(t)}var ie=class{entries=new Map;currentBytes=0;maxBytes;hits=0;misses=0;constructor(e=256*1024*1024){this.maxBytes=e}static key(e,t,n){if(n.length>0)return null;let s=t.slice().sort();return`${e}\0${s.join(",")}`}get(e){let t=this.entries.get(e);return t?this.hits++:this.misses++,t}set(e,t){if(this.entries.has(e))return;let n=t.packData.byteLength;if(!(n>this.maxBytes)){for(;this.currentBytes+n>this.maxBytes&&this.entries.size>0;){let s=this.entries.keys().next().value;this.currentBytes-=this.entries.get(s).packData.byteLength,this.entries.delete(s)}this.entries.set(e,t),this.currentBytes+=n}}clear(){this.entries.clear(),this.currentBytes=0}get stats(){return{entries:this.entries.size,bytes:this.currentBytes,hits:this.hits,misses:this.misses}}},Vt=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag","allow-reachable-sha1-in-want","shallow"],Zt=["report-status","side-band-64k","ofs-delta","delete-refs"];async function Jt(r){let e=await r.refStore.listRefs("refs"),t=await r.refStore.readRef("HEAD"),n=[],s=null,a;if(t)if(t.type==="symbolic"){a=t.target;let o=await r.refStore.readRef(t.target);o?.type==="direct"&&(s=o.hash)}else s=t.hash;let i=e.slice().sort((o,f)=>o.name<f.name?-1:o.name>f.name?1:0);if(!s&&i.length>0){let o=Fr(i);o&&(s=o.hash,a=o.name)}s&&n.push({name:"HEAD",hash:s});for(let o of i)if(n.push({name:o.name,hash:o.hash}),o.name.startsWith("refs/tags/"))try{let f=await r.objectStore.read(o.hash);if(f.type==="tag"){let c=_(f.content);n.push({name:`${o.name}^{}`,hash:c.object})}}catch{}return{refs:n,headTarget:a}}var Gr=["refs/heads/main","refs/heads/master"];function Fr(r){for(let t of Gr){let n=r.find(s=>s.name===t);if(n)return n}return r.find(t=>t.name.startsWith("refs/heads/"))??null}function Me(r,e,t){return qt(r,e,e==="git-upload-pack"?Vt:Zt,t)}function $e(r,e,t){return Oe(r,e==="git-upload-pack"?Vt:Zt,t)}async function ce(r,e,t,n,s){let{refs:a,headTarget:i}=await Jt(r),o=a;if(n?.advertiseRefs){let f=await n.advertiseRefs({repo:r,repoId:e,refs:a,service:t,session:s});if(T(f))return f;f&&(o=f)}return{refs:o,headTarget:i}}async function fe(r,e,t){let{wants:n,haves:s,capabilities:a,clientShallows:i,depth:o,done:f}=zt(e);if(n.length===0)return K(new Uint8Array(0),!1);let c=a.includes("multi_ack_detailed"),l=a.includes("side-band-64k"),d,p,u;if(i.length>0&&(u=new Set(i)),o!==void 0){let g=await Nt(r,n,o,u??new Set);d=g,p=new Set(g.shallow)}if(d&&!f)return Xt(d);let h;if(c&&s.length>0){h=[];for(let g of s)await r.objectStore.exists(g)&&h.push(g);h.length===0&&(h=void 0)}let m=!p&&t?.cache&&t.cacheKey?ie.key(t.cacheKey,n,s):null;if(m&&t?.cache){let g=t.cache.get(m);if(g)return K(g.packData,l,h)}return t?.noDelta?qr(r,n,s,a,l,h,d,p,u):zr(r,n,s,a,l,h,t,m,d,p,u)}async function qr(r,e,t,n,s,a,i,o,f){let{count:c,objects:l}=await Ne(r,e,t,o,f);if(c===0){let{data:y}=await Re([]),R=K(y,s,a,i);return new ReadableStream({start(w){w.enqueue(R),w.close()}})}let d=[];for await(let y of l)d.push(y);let p=new Set(d.map(y=>y.hash)),u=[];if(n.includes("include-tag")){let y=await r.refStore.listRefs("refs/tags");for(let R of y)if(!p.has(R.hash))try{let w=await r.objectStore.read(R.hash);if(w.type==="tag"){let P=_(w.content);p.has(P.object)&&u.push({hash:R.hash,type:"tag",content:w.content})}}catch{}}let h=d.length+u.length;async function*m(){for(let y of d){let R=await r.objectStore.read(y.hash);yield{type:R.type,content:R.content}}for(let y of u)yield{type:y.type,content:y.content}}let g=St(h,m()),b=Kt(g,s,a,i);return new ReadableStream({async pull(y){let{value:R,done:w}=await b.next();w?y.close():y.enqueue(R)}})}async function zr(r,e,t,n,s,a,i,o,f,c,l){let d=await Bt(r,e,t,c,l);if(d.count===0){let{data:y}=await Re([]);return K(y,s,a,f)}let p=await Mt(d),u=new Set(p.map(y=>y.hash));if(n.includes("include-tag")){let y=await r.refStore.listRefs("refs/tags");for(let R of y)if(!u.has(R.hash))try{let w=await r.objectStore.read(R.hash);if(w.type==="tag"){let P=_(w.content);u.has(P.object)&&(p.push({hash:R.hash,type:"tag",content:w.content}),u.add(R.hash))}}catch{}}let h=i?.deltaWindow?{window:i.deltaWindow}:void 0,m=Dt(p,h),g=m.map(y=>({hash:y.hash,type:y.type,content:y.content,delta:y.delta,deltaBaseHash:y.deltaBase})),{data:b}=await Re(g);if(o&&i?.cache){let y=m.filter(R=>R.delta).length;i.cache.set(o,{packData:b,objectCount:p.length,deltaCount:y})}return K(b,s,a,f)}async function We(r,e){let{commands:t,packData:n,capabilities:s,sawFlush:a}=Yt(e),i=!0;if(n.byteLength>0)try{await r.objectStore.ingestPack(n)}catch{i=!1}return{updates:await Qt(r,t,i),unpackOk:i,capabilities:s,sawFlush:a}}async function _e(r,e,t,n,s=!0){let a=!0;try{let f=vt(n,async c=>{try{return await r.objectStore.read(c)}catch{return null}});await r.objectStore.ingestPackStream(f)}catch{a=!1}return{updates:await Qt(r,e,a),unpackOk:a,capabilities:t,sawFlush:s}}async function Qt(r,e,t){let n=[];for(let s of e){let a=s.oldHash===ke,i=s.newHash===ke,o=!1;if(!a&&!i&&t)try{o=await Ut(r,s.oldHash,s.newHash)}catch{}n.push({ref:s.refName,oldHash:a?null:s.oldHash,newHash:s.newHash,isFF:o,isCreate:a,isDelete:i})}return n}async function le(r){let{repo:e,repoId:t,ingestResult:n,hooks:s,session:a}=r,{updates:i}=n;if(s?.preReceive){let c=await s.preReceive({repo:e,repoId:t,updates:i,session:a});if(T(c)){let l=c.message??"pre-receive hook declined";return{refResults:i.map(d=>({ref:d.ref,ok:!1,error:l})),applied:[]}}}let o=[],f=[];for(let c of i){if(!c.isDelete&&!It(c.ref)){o.push({ref:c.ref,ok:!1,error:"invalid refname"});continue}if(s?.update){let l=await s.update({repo:e,repoId:t,update:c,session:a});if(T(l)){o.push({ref:c.ref,ok:!1,error:l.message??"update hook declined"});continue}}try{let l=c.isCreate?null:c.oldHash,d=c.isDelete?null:{type:"direct",hash:c.newHash};if(!await e.refStore.compareAndSwapRef(c.ref,l,d)){o.push({ref:c.ref,ok:!1,error:"failed to lock"});continue}o.push({ref:c.ref,ok:!0}),f.push(c)}catch(l){o.push({ref:c.ref,ok:!1,error:l instanceof Error?l.message:String(l)})}}if(s?.postReceive&&f.length>0)try{await s.postReceive({repo:e,repoId:t,updates:f,session:a})}catch{}return{refResults:o,applied:f}}function Xr(r){let e=r.match(/^git[\s-](upload-pack|receive-pack)\s+'?([^']+?)'?\s*$/);if(!e)return null;let t=`git-${e[1]}`,n=e[2];return n.startsWith("/")&&(n=n.slice(1)),{service:t,repoPath:n}}var Kr=new TextEncoder;async function tr(r,e,t){let{resolveRepo:n,hooks:s,packCache:a,packOptions:i,session:o}=t,f=e.writable.getWriter();try{let c=Xr(r);if(!c)return Ee(e,`fatal: unrecognized command '${r}'
32
- `),128;let{service:l,repoPath:d}=c,p=await n(d);if(!p)return Ee(e,`fatal: '${d}' does not appear to be a git repository
33
- `),128;let{repo:u,repoId:h}=p,m=await ce(u,h,l,s,o);if(T(m))return Ee(e,`fatal: ${m.message??"access denied"}
34
- `),128;await f.write($e(m.refs,l,m.headTarget));let g=new Ge(e.readable);try{if(l==="git-upload-pack"){let b=await Vr(g),y=await fe(u,b,{cache:a,cacheKey:h,noDelta:i?.noDelta,deltaWindow:i?.deltaWindow});await Qr(f,y)}else{let{commands:b,capabilities:y}=await Zr(g),R=g.streamRemaining();await Yr({writer:f,repo:u,repoId:h,commands:b,capabilities:y,packStream:R,hooks:s,session:o})}}finally{g.release()}return 0}catch(c){return t.onError?.(c),Ee(e,`fatal: internal error
35
- `),128}finally{try{await f.close()}catch{}}}async function Yr(r){let{writer:e,repo:t,repoId:n,commands:s,capabilities:a,packStream:i,hooks:o,session:f}=r,c=await _e(t,s,a,i);if(c.updates.length===0)return;let l=c.capabilities.includes("side-band-64k"),d=c.capabilities.includes("report-status");if(!c.unpackOk){if(d){let u=c.updates.map(h=>({name:h.ref,ok:!1,error:"unpack failed"}));await e.write(Y(!1,u,l))}return}let{refResults:p}=await le({repo:t,repoId:n,ingestResult:c,hooks:o,session:f});if(d){let u=p.map(h=>({name:h.ref,ok:h.ok,error:h.error}));await e.write(Y(!0,u,l))}}function Ee(r,e){r.writeStderr?.(Kr.encode(e))}var er=new TextDecoder,Ge=class{buf=new Uint8Array(0);byteReader;eof=!1;constructor(e){this.byteReader=e.getReader()}async fill(e){for(;this.buf.byteLength<e&&!this.eof;){let t=await this.byteReader.read();if(t.done||!t.value){this.eof=!0;break}let n=t.value,s=new Uint8Array(this.buf.byteLength+n.byteLength);s.set(this.buf),s.set(n,this.buf.byteLength),this.buf=s}return this.buf.byteLength>=e}consume(e){let t=this.buf.subarray(0,e);return this.buf=this.buf.subarray(e),t}async readPktLine(){if(!await this.fill(4))return null;let e=er.decode(this.buf.subarray(0,4)),t=parseInt(e,16);if(t===0)return{type:"flush",raw:this.consume(4)};if(t<4||!await this.fill(t))return null;let n=new Uint8Array(this.consume(t));return{type:"data",raw:n,text:er.decode(n.subarray(4))}}async*streamRemaining(){for(this.buf.byteLength>0&&(yield this.consume(this.buf.byteLength));!this.eof;){let e=await this.byteReader.read();if(e.done||!e.value){this.eof=!0;break}yield e.value}}release(){this.byteReader.releaseLock()}};async function Vr(r){let e=[];for(;;){let t=await r.readPktLine();if(!t||(e.push(t.raw),t.type==="data"&&t.text.trimEnd()==="done"))break}return Jr(e)}async function Zr(r){let e=[],t=[],n=!0;for(;;){let s=await r.readPktLine();if(!s||s.type==="flush")break;let a=s.text;if(a.endsWith(`
36
- `)&&(a=a.slice(0,-1)),n){let o=a.indexOf("\0");o!==-1&&(t=a.slice(o+1).split(" ").filter(Boolean),a=a.slice(0,o)),n=!1}let i=a.split(" ");i.length>=3&&e.push({oldHash:i[0],newHash:i[1],refName:i[2]})}return{commands:e,capabilities:t}}function Jr(r){if(r.length===0)return new Uint8Array(0);if(r.length===1)return r[0];let e=0;for(let s of r)e+=s.byteLength;let t=new Uint8Array(e),n=0;for(let s of r)t.set(s,n),n+=s.byteLength;return t}async function Qr(r,e){if(e instanceof ReadableStream){let t=e.getReader();try{for(;;){let{value:n,done:s}=await t.read();if(s)break;await r.write(n)}}finally{t.releaseLock()}}else await r.write(e)}function rr(r){function e(t){return{objectStore:new Fe(r,t),refStore:new qe(r,t)}}return{async createRepo(t,n){if(await r.hasRepo(t))throw new Error(`repo '${t}' already exists`);let a=n?.defaultBranch??"main";return await r.insertRepo(t),await r.putRef(t,"HEAD",{type:"symbolic",target:`refs/heads/${a}`}),e(t)},async repo(t){return await r.hasRepo(t)?e(t):null},async deleteRepo(t){await r.deleteRepo(t)}}}var Fe=class{constructor(e,t){this.driver=e;this.repoId=t}cache=new be;async write(e,t){let n=jt(e,t),s=await ot(n);return await this.driver.putObject(this.repoId,s,e,t),s}async read(e){let t=this.cache.get(e);if(t)return t;let n=await this.driver.getObject(this.repoId,e);if(!n)throw new Error(`object ${e} not found`);return this.cache.set(e,n),n}async exists(e){return!!await this.driver.hasObject(this.repoId,e)}async ingestPack(e){if(e.byteLength<32||new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8)===0)return 0;let s=this.driver,a=this.repoId,i=await kt(e,async o=>{let f=await s.getObject(a,o);return f?{type:f.type,content:new Uint8Array(f.content)}:null});return await s.putObjects(a,i.map(o=>({hash:o.hash,type:o.type,content:o.content}))),i.length}async ingestPackStream(e){let t=[];for await(let n of e)t.push({hash:n.hash,type:n.type,content:n.content});return t.length===0?0:(await this.driver.putObjects(this.repoId,t),t.length)}async findByPrefix(e){return e.length<4?[]:Array.from(await this.driver.findObjectsByPrefix(this.repoId,e))}},qe=class{constructor(e,t){this.driver=e;this.repoId=t}async readRef(e){return await this.driver.getRef(this.repoId,e)??null}async writeRef(e,t){await this.driver.putRef(this.repoId,e,At(t))}async deleteRef(e){await this.driver.removeRef(this.repoId,e)}async listRefs(e){let t=await this.driver.listRefs(this.repoId,e),n=[];for(let s of t)if(s.ref.type==="direct")n.push({name:s.name,hash:s.ref.hash});else if(s.ref.type==="symbolic"){let a=await ze(i=>this.driver.getRef(this.repoId,i),s.ref.target);a&&n.push({name:s.name,hash:a})}return n}async compareAndSwapRef(e,t,n){return!!await this.driver.atomicRefUpdate(this.repoId,s=>de(s.getRef(e),a=>{let i=a?a.type==="direct"?a.hash:ze(o=>s.getRef(o),a.target):null;return de(i,o=>{if(t===null){if(a!==null)return!1}else if(o!==t)return!1;return n===null?de(s.removeRef(e),()=>!0):de(s.putRef(e,n),()=>!0)})}))}};function de(r,e){return r instanceof Promise?r.then(e):e(r)}function ze(r,e,t=0){return t>10?null:de(r(e),n=>n?n.type==="direct"?n.hash:n.type==="symbolic"?ze(r,n.target,t+1):null:null)}var en={http:r=>({transport:"http",request:r}),ssh:r=>({transport:"ssh",username:r.username})};function tn(r){if(!r||!r.storage)throw new TypeError("createServer: config.storage is required. Example: createServer({ storage: new MemoryStorage() })");let e=rr(r.storage),t=r.resolve??(b=>b),n=r.autoCreate,{basePath:s}=r;async function a(b){let y=await t(b);if(y==null)return null;let R=await e.repo(y);if(R)return{repo:R,repoId:y};if(!n)return null;let w=typeof n=="object"?{defaultBranch:n.defaultBranch}:void 0;return{repo:await e.createRepo(y,w),repoId:y}}let i=sn(r.policy,r.hooks),o=r.session??en,f=r.packCache===!1?void 0:new ie(r.packCache?.maxBytes),c=r.onError===!1?void 0:r.onError??(b=>{let y=b instanceof Error?b.message:String(b);console.error(`[server] Internal error: ${y}`)}),l=!1,d=0,p=null,u=null;function h(){return l?!1:(d++,!0)}function m(){d--,l&&d===0&&p?.()}let g={async fetch(b){if(!h())return new Response("Service Unavailable",{status:503});let y;try{let R=await o.http(b);if(R instanceof Response)return R;y=R;let w=new URL(b.url),P=decodeURIComponent(w.pathname);if(s){let x=s.replace(/\/+$/,"");if(!P.startsWith(x))return new Response("Not Found",{status:404});P=P.slice(x.length)}if(P.startsWith("/")||(P=`/${P}`),P.endsWith("/info/refs")&&b.method==="GET"){let x=w.searchParams.get("service");if(x!=="git-upload-pack"&&x!=="git-receive-pack")return new Response("Unsupported service",{status:403});let O=Xe(P,"/info/refs"),S=await a(O);if(!S)return new Response("Not Found",{status:404});let E=await ce(S.repo,S.repoId,x,i,y);if(T(E))return new Response(E.message??"Forbidden",{status:403});let j=Me(E.refs,x,E.headTarget);return new Response(j,{headers:{"Content-Type":`application/x-${x}-advertisement`,"Cache-Control":"no-cache"}})}if(P.endsWith("/git-upload-pack")&&b.method==="POST"){let x=Xe(P,"/git-upload-pack"),O=await a(x);if(!O)return new Response("Not Found",{status:404});let S=await nr(b),E=await fe(O.repo,S,{cache:f,cacheKey:O.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow});return new Response(E,{headers:{"Content-Type":"application/x-git-upload-pack-result"}})}if(P.endsWith("/git-receive-pack")&&b.method==="POST"){let x=Xe(P,"/git-receive-pack"),O=await a(x);if(!O)return new Response("Not Found",{status:404});let S=await nr(b),E=await We(O.repo,S);if(!E.sawFlush&&E.updates.length===0)return new Response("Bad Request",{status:400});let j=E.capabilities.includes("side-band-64k"),M=E.capabilities.includes("report-status");if(!E.unpackOk){if(M){let C=E.updates.map($=>({name:$.ref,ok:!1,error:"unpack failed"}));return new Response(Y(!1,C,j),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response(new Uint8Array(0),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}let{refResults:I}=await le({repo:O.repo,repoId:O.repoId,ingestResult:E,hooks:i,session:y});if(M){let C=I.map($=>({name:$.ref,ok:$.ok,error:$.error}));return new Response(Y(!0,C,j),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response(new Uint8Array(0),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response("Not Found",{status:404})}catch(R){return c?.(R,y),new Response("Internal Server Error",{status:500})}finally{m()}},async handleSession(b,y,R){if(!h())return y.writeStderr?.(new TextEncoder().encode(`fatal: server shutting down
37
- `)),128;try{let w=await o.ssh(R??{});return await tr(b,y,{resolveRepo:a,hooks:i,packCache:f,packOptions:r.packOptions,session:w,onError:c?P=>c(P,w):void 0})}finally{m()}},nodeHandler(b,y){let R=[];b.on("data",w=>R.push(new Uint8Array(w))),b.on("error",()=>{y.writeHead(500),y.end("Internal Server Error")}),b.on("end",()=>{rn(g,b,R,y).catch(()=>{try{y.writeHead(500),y.end("Internal Server Error")}catch{}})})},createRepo:(b,y)=>e.createRepo(b,y),repo:b=>e.repo(b),deleteRepo:b=>e.deleteRepo(b),get closed(){return l},asNetwork(b="http://git"){return{allowed:[b.endsWith("/")?b:`${b}/`],fetch:(R,w)=>g.fetch(new Request(R,w))}},async close(b){if(l)return u??Promise.resolve();if(l=!0,f?.clear(),d!==0){if(u=new Promise(y=>{p=y}),b?.signal){if(b.signal.aborted){p();return}let y=()=>p?.();b.signal.addEventListener("abort",y,{once:!0}),u.then(()=>b.signal.removeEventListener("abort",y))}return u}}};return g}function Xe(r,e){let t=r.slice(0,-e.length);return t.startsWith("/")&&(t=t.slice(1)),t}async function nr(r){let e=new Uint8Array(await r.arrayBuffer()),t=r.headers.get("content-encoding");if(t==="gzip"||t==="x-gzip"){let n=new DecompressionStream("gzip"),s=n.writable.getWriter();return s.write(e),s.close(),new Uint8Array(await new Response(n.readable).arrayBuffer())}return e}async function rn(r,e,t,n){let s=typeof e.headers.host=="string"?e.headers.host:"localhost",a=new URL(e.url??"/",`http://${s}`),i=new Headers;for(let[u,h]of Object.entries(e.headers))if(h!==void 0)if(Array.isArray(h))for(let m of h)i.append(u,m);else i.set(u,h);let o=e.method??"GET",f;if(o!=="GET"&&o!=="HEAD"){let u=0;for(let g of t)u+=g.byteLength;let h=new Uint8Array(u),m=0;for(let g of t)h.set(g,m),m+=g.byteLength;f=h}let c=new Request(a.href,{method:o,headers:i,body:f}),l=await r.fetch(c),d={};l.headers.forEach((u,h)=>{d[h]=u}),n.writeHead(l.status,d);let p=new Uint8Array(await l.arrayBuffer());p.byteLength>0&&n.write(p),n.end()}function nn(r){let{protectedBranches:e=[],denyNonFastForward:t=!1,denyDeletes:n=!1,immutableTags:s=!1}=r,a=new Set(e.map(o=>o.startsWith("refs/")?o:`refs/heads/${o}`)),i={};return a.size>0&&(i.preReceive=async o=>{for(let f of o.updates)if(a.has(f.ref)){if(f.isDelete)return{reject:!0,message:`cannot delete protected branch ${f.ref}`};if(!f.isCreate&&!f.isFF)return{reject:!0,message:`non-fast-forward push to protected branch ${f.ref}`}}}),(t||n||s)&&(i.update=async o=>{if(n&&o.update.isDelete)return{reject:!0,message:"ref deletion denied"};if(s&&o.update.ref.startsWith("refs/tags/")){if(o.update.isDelete)return{reject:!0,message:"tag deletion denied"};if(!o.update.isCreate)return{reject:!0,message:"tag overwrite denied"}}if(t&&!o.update.isCreate&&!o.update.isDelete&&!o.update.isFF)return{reject:!0,message:"non-fast-forward"}}),i}function sn(r,e){let t=r?nn(r):void 0;return t&&e?sr(t,e):t??e}function sr(...r){let e=r.filter(o=>o!=null);if(e.length===0)return{};if(e.length===1)return e[0];let t={},n=e.filter(o=>o.preReceive).map(o=>o.preReceive);n.length>0&&(t.preReceive=async o=>{for(let f of n){let c=await f(o);if(T(c))return c}});let s=e.filter(o=>o.update).map(o=>o.update);s.length>0&&(t.update=async o=>{for(let f of s){let c=await f(o);if(T(c))return c}});let a=e.filter(o=>o.postReceive).map(o=>o.postReceive);a.length>0&&(t.postReceive=async o=>{for(let f of a)try{await f(o)}catch{}});let i=e.filter(o=>o.advertiseRefs).map(o=>o.advertiseRefs);return i.length>0&&(t.advertiseRefs=async o=>{let f=o.refs;for(let c of i){let l=await c({...o,refs:f});if(T(l))return l;l&&(f=l)}return f}),t}var Ke=class{repos=new Set;objects=new Map;refs=new Map;hasRepo(e){return this.repos.has(e)}insertRepo(e){this.repos.add(e)}deleteRepo(e){this.repos.delete(e),this.objects.get(e)?.clear(),this.objects.delete(e),this.refs.get(e)?.clear(),this.refs.delete(e)}getObject(e,t){let n=this.getObjMap(e).get(t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}putObject(e,t,n,s){let a=this.getObjMap(e);a.has(t)||a.set(t,{type:n,content:new Uint8Array(s)})}putObjects(e,t){let n=this.getObjMap(e);for(let s of t)n.has(s.hash)||n.set(s.hash,{type:s.type,content:new Uint8Array(s.content)})}hasObject(e,t){return this.getObjMap(e).has(t)}findObjectsByPrefix(e,t){let n=[];for(let s of this.getObjMap(e).keys())s.startsWith(t)&&n.push(s);return n}getRef(e,t){return this.getRefMap(e).get(t)??null}putRef(e,t,n){this.getRefMap(e).set(t,n)}removeRef(e,t){this.getRefMap(e).delete(t)}listRefs(e,t){let n=[];for(let[s,a]of this.getRefMap(e))t&&!s.startsWith(t)||n.push({name:s,ref:a});return n}atomicRefUpdate(e,t){let n=this.getRefMap(e);return t({getRef:s=>n.get(s)??null,putRef:(s,a)=>{n.set(s,a)},removeRef:s=>{n.delete(s)}})}repoIds(){return Array.from(this.repos)}getObjMap(e){let t=this.objects.get(e);return t||(t=new Map,this.objects.set(e,t)),t}getRefMap(e){let t=this.refs.get(e);return t||(t=new Map,this.refs.set(e,t)),t}};var an=`
29
+ `));for(let a of e)a.ok?n.push(v(`ok ${a.name}
30
+ `)):n.push(v(`ng ${a.name} ${a.error??"failed"}
31
+ `));n.push(D());let s=M(...n);if(t){let a=[];return a.push(Be(1,s)),a.push(D()),M(...a)}return s}function Be(r,e){let t=new Uint8Array(1+e.byteLength);return t[0]=r,t.set(e,1),v(t)}var fe=class{entries=new Map;currentBytes=0;maxBytes;hits=0;misses=0;constructor(e=256*1024*1024){this.maxBytes=e}static key(e,t,n){if(n.length>0)return null;let s=t.slice().sort();return`${e}\0${s.join(",")}`}get(e){let t=this.entries.get(e);return t?this.hits++:this.misses++,t}set(e,t){if(this.entries.has(e))return;let n=t.packData.byteLength;if(!(n>this.maxBytes)){for(;this.currentBytes+n>this.maxBytes&&this.entries.size>0;){let s=this.entries.keys().next().value;this.currentBytes-=this.entries.get(s).packData.byteLength,this.entries.delete(s)}this.entries.set(e,t),this.currentBytes+=n}}clear(){this.entries.clear(),this.currentBytes=0}get stats(){return{entries:this.entries.size,bytes:this.currentBytes,hits:this.hits,misses:this.misses}}},Jt=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag","allow-reachable-sha1-in-want","shallow"],Qt=["report-status","side-band-64k","ofs-delta","delete-refs"];async function er(r){let e=await r.refStore.listRefs("refs"),t=await r.refStore.readRef("HEAD"),n=[],s=null,a;if(t)if(t.type==="symbolic"){a=t.target;let o=await r.refStore.readRef(t.target);o?.type==="direct"&&(s=o.hash)}else s=t.hash;let i=e.slice().sort((o,f)=>o.name<f.name?-1:o.name>f.name?1:0);if(!s&&i.length>0){let o=Zr(i);o&&(s=o.hash,a=o.name)}s&&n.push({name:"HEAD",hash:s});for(let o of i)if(n.push({name:o.name,hash:o.hash}),o.name.startsWith("refs/tags/"))try{let f=await r.objectStore.read(o.hash);if(f.type==="tag"){let c=W(f.content);n.push({name:`${o.name}^{}`,hash:c.object})}}catch{}return{refs:n,headTarget:a}}var Vr=["refs/heads/main","refs/heads/master"];function Zr(r){for(let t of Vr){let n=r.find(s=>s.name===t);if(n)return n}return r.find(t=>t.name.startsWith("refs/heads/"))??null}function $e(r,e,t){return Xt(r,e,e==="git-upload-pack"?Jt:Qt,t)}function _e(r,e,t){return ve(r,e==="git-upload-pack"?Jt:Qt,t)}async function le(r,e,t,n,s){let{refs:a,headTarget:i}=await er(r),o=a;if(n?.advertiseRefs){let f=await n.advertiseRefs({repo:r,repoId:e,refs:a,service:t,session:s});if(T(f))return f;f&&(o=f)}return{refs:o,headTarget:i}}async function de(r,e,t){let{wants:n,haves:s,capabilities:a,clientShallows:i,depth:o,done:f}=Kt(e);if(n.length===0)return K(new Uint8Array(0),!1);let c=a.includes("multi_ack_detailed"),l=a.includes("side-band-64k"),d,p,u;if(i.length>0&&(u=new Set(i)),o!==void 0){let R=await Bt(r,n,o,u??new Set);d=R,p=new Set(R.shallow)}if(d&&!f)return Yt(d);let h;if(c&&s.length>0){h=[];for(let R of s)await r.objectStore.exists(R)&&h.push(R);h.length===0&&(h=void 0)}let m=!p&&t?.cache&&t.cacheKey?fe.key(t.cacheKey,n,s):null;if(m&&t?.cache){let R=t.cache.get(m);if(R)return K(R.packData,l,h)}return t?.noDelta?Jr(r,n,s,a,l,h,d,p,u):Qr(r,n,s,a,l,h,t,m,d,p,u)}async function Jr(r,e,t,n,s,a,i,o,f){let{count:c,objects:l}=await ce(r,e,t,o,f);if(c===0){let{data:y}=await Ee([]),g=K(y,s,a,i);return new ReadableStream({start(w){w.enqueue(g),w.close()}})}let d=[];for await(let y of l)d.push(y);let p=new Set(d.map(y=>y.hash)),u=[];if(n.includes("include-tag")){let y=await r.refStore.listRefs("refs/tags");for(let g of y)if(!p.has(g.hash))try{let w=await r.objectStore.read(g.hash);if(w.type==="tag"){let E=W(w.content);p.has(E.object)&&u.push({hash:g.hash,type:"tag",content:w.content})}}catch{}}let h=d.length+u.length;async function*m(){for(let y of d){let g=await r.objectStore.read(y.hash);yield{type:g.type,content:g.content}}for(let y of u)yield{type:y.type,content:y.content}}let R=At(h,m()),b=Vt(R,s,a,i);return new ReadableStream({async pull(y){let{value:g,done:w}=await b.next();w?y.close():y.enqueue(g)}})}async function Qr(r,e,t,n,s,a,i,o,f,c,l){let d=await $t(r,e,t,c,l);if(d.count===0){let{data:y}=await Ee([]);return K(y,s,a,f)}let p=await _t(d),u=new Set(p.map(y=>y.hash));if(n.includes("include-tag")){let y=await r.refStore.listRefs("refs/tags");for(let g of y)if(!u.has(g.hash))try{let w=await r.objectStore.read(g.hash);if(w.type==="tag"){let E=W(w.content);u.has(E.object)&&(p.push({hash:g.hash,type:"tag",content:w.content}),u.add(g.hash))}}catch{}}let h=i?.deltaWindow?{window:i.deltaWindow}:void 0,m=Mt(p,h),R=m.map(y=>({hash:y.hash,type:y.type,content:y.content,delta:y.delta,deltaBaseHash:y.deltaBase})),{data:b}=await Ee(R);if(o&&i?.cache){let y=m.filter(g=>g.delta).length;i.cache.set(o,{packData:b,objectCount:p.length,deltaCount:y})}return K(b,s,a,f)}async function We(r,e){let{commands:t,packData:n,capabilities:s,sawFlush:a}=Zt(e),i=!0;if(n.byteLength>0)try{await r.objectStore.ingestPack(n)}catch{i=!1}return{updates:await tr(r,t,i),unpackOk:i,capabilities:s,sawFlush:a}}async function Ge(r,e,t,n,s=!0){let a=!0;try{let f=St(n,async c=>{try{return await r.objectStore.read(c)}catch{return null}});await r.objectStore.ingestPackStream(f)}catch{a=!1}return{updates:await tr(r,e,a),unpackOk:a,capabilities:t,sawFlush:s}}async function tr(r,e,t){let n=[];for(let s of e){let a=s.oldHash===ye,i=s.newHash===ye,o=!1;if(!a&&!i&&t)try{o=await Ne(r,s.oldHash,s.newHash)}catch{}n.push({ref:s.refName,oldHash:a?null:s.oldHash,newHash:s.newHash,isFF:o,isCreate:a,isDelete:i})}return n}async function V(r){let{repo:e,repoId:t,ingestResult:n,hooks:s,session:a}=r,{updates:i}=n;if(s?.preReceive){let c=await s.preReceive({repo:e,repoId:t,updates:i,session:a});if(T(c)){let l=c.message??"pre-receive hook declined";return{refResults:i.map(d=>({ref:d.ref,ok:!1,error:l})),applied:[]}}}let o=[],f=[];for(let c of i){if(c.ref==="HEAD"){o.push({ref:c.ref,ok:!1,error:"HEAD cannot be updated via push"});continue}if(!c.isDelete&&!Ut(c.ref)){o.push({ref:c.ref,ok:!1,error:"invalid refname"});continue}if(s?.update){let l=await s.update({repo:e,repoId:t,update:c,session:a});if(T(l)){o.push({ref:c.ref,ok:!1,error:l.message??"update hook declined"});continue}}if(!c.isDelete&&!await e.objectStore.exists(c.newHash)){o.push({ref:c.ref,ok:!1,error:"missing objects"});continue}try{let l=c.isCreate?null:c.oldHash,d=c.isDelete?null:{type:"direct",hash:c.newHash};if(!await e.refStore.compareAndSwapRef(c.ref,l,d)){o.push({ref:c.ref,ok:!1,error:"failed to lock"});continue}o.push({ref:c.ref,ok:!0}),f.push(c)}catch(l){o.push({ref:c.ref,ok:!1,error:l instanceof Error?l.message:String(l)})}}if(s?.postReceive&&f.length>0)try{await s.postReceive({repo:e,repoId:t,updates:f,session:a})}catch{}return{refResults:o,applied:f}}async function Fe(r,e){let t=[];for(let n of e){let s;n.oldHash!==void 0?s=n.oldHash:s=await Lt(r,n.ref);let a=s===null,i=n.newHash===null,o=n.newHash??ye,f=!1;if(!a&&!i)try{f=await Ne(r,s,o)}catch{}t.push({ref:n.ref,oldHash:s,newHash:o,isFF:f,isCreate:a,isDelete:i})}return t}function en(r){let e=r.match(/^git[\s-](upload-pack|receive-pack)\s+'?([^']+?)'?\s*$/);if(!e)return null;let t=`git-${e[1]}`,n=e[2];return n.startsWith("/")&&(n=n.slice(1)),{service:t,repoPath:n}}var tn=new TextEncoder;async function nr(r,e,t){let{resolveRepo:n,hooks:s,packCache:a,packOptions:i,session:o}=t,f=e.writable.getWriter();try{let c=en(r);if(!c)return ke(e,`fatal: unrecognized command '${r}'
32
+ `),128;let{service:l,repoPath:d}=c,p=await n(d);if(!p)return ke(e,`fatal: '${d}' does not appear to be a git repository
33
+ `),128;let{repo:u,repoId:h}=p,m=await le(u,h,l,s,o);if(T(m))return ke(e,`fatal: ${m.message??"access denied"}
34
+ `),128;await f.write(_e(m.refs,l,m.headTarget));let R=new qe(e.readable);try{if(l==="git-upload-pack"){let b=await nn(R),y=await de(u,b,{cache:a,cacheKey:h,noDelta:i?.noDelta,deltaWindow:i?.deltaWindow});await on(f,y)}else{let{commands:b,capabilities:y}=await sn(R),g=R.streamRemaining();await rn({writer:f,repo:u,repoId:h,commands:b,capabilities:y,packStream:g,hooks:s,session:o})}}finally{R.release()}return 0}catch(c){return t.onError?.(c),ke(e,`fatal: internal error
35
+ `),128}finally{try{await f.close()}catch{}}}async function rn(r){let{writer:e,repo:t,repoId:n,commands:s,capabilities:a,packStream:i,hooks:o,session:f}=r,c=await Ge(t,s,a,i);if(c.updates.length===0)return;let l=c.capabilities.includes("side-band-64k"),d=c.capabilities.includes("report-status");if(!c.unpackOk){if(d){let u=c.updates.map(h=>({name:h.ref,ok:!1,error:"unpack failed"}));await e.write(Y(!1,u,l))}return}let{refResults:p}=await V({repo:t,repoId:n,ingestResult:c,hooks:o,session:f});if(d){let u=p.map(h=>({name:h.ref,ok:h.ok,error:h.error}));await e.write(Y(!0,u,l))}}function ke(r,e){r.writeStderr?.(tn.encode(e))}var rr=new TextDecoder,qe=class{buf=new Uint8Array(0);byteReader;eof=!1;constructor(e){this.byteReader=e.getReader()}async fill(e){for(;this.buf.byteLength<e&&!this.eof;){let t=await this.byteReader.read();if(t.done||!t.value){this.eof=!0;break}let n=t.value,s=new Uint8Array(this.buf.byteLength+n.byteLength);s.set(this.buf),s.set(n,this.buf.byteLength),this.buf=s}return this.buf.byteLength>=e}consume(e){let t=this.buf.subarray(0,e);return this.buf=this.buf.subarray(e),t}async readPktLine(){if(!await this.fill(4))return null;let e=rr.decode(this.buf.subarray(0,4)),t=parseInt(e,16);if(t===0)return{type:"flush",raw:this.consume(4)};if(t<4||!await this.fill(t))return null;let n=new Uint8Array(this.consume(t));return{type:"data",raw:n,text:rr.decode(n.subarray(4))}}async*streamRemaining(){for(this.buf.byteLength>0&&(yield this.consume(this.buf.byteLength));!this.eof;){let e=await this.byteReader.read();if(e.done||!e.value){this.eof=!0;break}yield e.value}}release(){this.byteReader.releaseLock()}};async function nn(r){let e=[];for(;;){let t=await r.readPktLine();if(!t||(e.push(t.raw),t.type==="data"&&t.text.trimEnd()==="done"))break}return an(e)}async function sn(r){let e=[],t=[],n=!0;for(;;){let s=await r.readPktLine();if(!s||s.type==="flush")break;let a=s.text;if(a.endsWith(`
36
+ `)&&(a=a.slice(0,-1)),n){let o=a.indexOf("\0");o!==-1&&(t=a.slice(o+1).split(" ").filter(Boolean),a=a.slice(0,o)),n=!1}let i=a.split(" ");i.length>=3&&e.push({oldHash:i[0],newHash:i[1],refName:i[2]})}return{commands:e,capabilities:t}}function an(r){if(r.length===0)return new Uint8Array(0);if(r.length===1)return r[0];let e=0;for(let s of r)e+=s.byteLength;let t=new Uint8Array(e),n=0;for(let s of r)t.set(s,n),n+=s.byteLength;return t}async function on(r,e){if(e instanceof ReadableStream){let t=e.getReader();try{for(;;){let{value:n,done:s}=await t.read();if(s)break;await r.write(n)}}finally{t.releaseLock()}}else await r.write(e)}async function ar(r,e,t,n){let s=n?.dryRun??!1,a=await sr(r),i=cn(a);if(i.length===0)return{deleted:0,retained:0};let o=await ce(r,i,[]),f=new Set;for await(let u of o.objects)f.add(u.hash);let c=await e.listObjectHashes(t),l=[];for(let u of c)f.has(u)||l.push(u);let d=await sr(r);return fn(a,d)?s||l.length===0?{deleted:l.length,retained:f.size}:{deleted:await e.deleteObjects(t,l),retained:f.size}:{deleted:0,retained:f.size,aborted:!0}}async function sr(r){return r.refStore.listRefs()}function cn(r){let e=new Set;for(let t of r)e.add(t.hash);return Array.from(e)}function fn(r,e){if(r.length!==e.length)return!1;let t=new Map;for(let n of r)t.set(n.name,n.hash);for(let n of e)if(t.get(n.name)!==n.hash)return!1;return!0}function or(r){function e(t){return{objectStore:new ze(r,t),refStore:new Xe(r,t)}}return{async createRepo(t,n){if(await r.hasRepo(t))throw new Error(`repo '${t}' already exists`);let a=n?.defaultBranch??"main";return await r.insertRepo(t),await r.putRef(t,"HEAD",{type:"symbolic",target:`refs/heads/${a}`}),e(t)},async repo(t){return await r.hasRepo(t)?e(t):null},async deleteRepo(t){await r.deleteRepo(t)}}}var ze=class{constructor(e,t){this.driver=e;this.repoId=t}cache=new ge;async write(e,t){let n=It(e,t),s=await ct(n);return await this.driver.putObject(this.repoId,s,e,t),s}async read(e){let t=this.cache.get(e);if(t)return t;let n=await this.driver.getObject(this.repoId,e);if(!n)throw new Error(`object ${e} not found`);return this.cache.set(e,n),n}async exists(e){return!!await this.driver.hasObject(this.repoId,e)}async ingestPack(e){if(e.byteLength<32)return 0;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0);if(n!==1346454347)throw new Error(`invalid pack signature: 0x${n.toString(16)} (expected 0x5041434b)`);let s=t.getUint32(4);if(s!==2)throw new Error(`unsupported pack version: ${s}`);if(t.getUint32(8)===0)return 0;let i=this.driver,o=this.repoId,f=await jt(e,async c=>{let l=await i.getObject(o,c);return l?{type:l.type,content:new Uint8Array(l.content)}:null});return await i.putObjects(o,f.map(c=>({hash:c.hash,type:c.type,content:c.content}))),f.length}async ingestPackStream(e){let t=[];for await(let n of e)t.push({hash:n.hash,type:n.type,content:n.content});return t.length===0?0:(await this.driver.putObjects(this.repoId,t),t.length)}async findByPrefix(e){return e.length<4?[]:Array.from(await this.driver.findObjectsByPrefix(this.repoId,e))}},Xe=class{constructor(e,t){this.driver=e;this.repoId=t}async readRef(e){return await this.driver.getRef(this.repoId,e)??null}async writeRef(e,t){await this.driver.putRef(this.repoId,e,Tt(t))}async deleteRef(e){await this.driver.removeRef(this.repoId,e)}async listRefs(e){let t=await this.driver.listRefs(this.repoId,e),n=[];for(let s of t)if(s.ref.type==="direct")n.push({name:s.name,hash:s.ref.hash});else if(s.ref.type==="symbolic"){let a=await Ke(i=>this.driver.getRef(this.repoId,i),s.ref.target);a&&n.push({name:s.name,hash:a})}return n}async compareAndSwapRef(e,t,n){return!!await this.driver.atomicRefUpdate(this.repoId,s=>pe(s.getRef(e),a=>{let i=a?a.type==="direct"?a.hash:Ke(o=>s.getRef(o),a.target):null;return pe(i,o=>{if(t===null){if(a!==null)return!1}else if(o!==t)return!1;return n===null?pe(s.removeRef(e),()=>!0):pe(s.putRef(e,n),()=>!0)})}))}};function pe(r,e){return r instanceof Promise?r.then(e):e(r)}function Ke(r,e,t=0){return t>10?null:pe(r(e),n=>n?n.type==="direct"?n.hash:n.type==="symbolic"?Ke(r,n.target,t+1):null:null)}var ln={http:r=>({transport:"http",request:r}),ssh:r=>({transport:"ssh",username:r.username})};function ir(r){if(r.length===0)return!1;for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);if(n===0||n<32||n===127||n===92)return!1}let e=r.split("/");for(let t of e)if(t.length===0||t.charCodeAt(0)===46)return!1;return!0}function dn(r){if(!r||!r.storage)throw new TypeError("createServer: config.storage is required. Example: createServer({ storage: new MemoryStorage() })");let e=or(r.storage),t=r.resolve??(b=>b),n=r.autoCreate,{basePath:s}=r;async function a(b){if(!ir(b))return null;let y=await t(b);if(y==null||y!==b&&!ir(y))return null;let g=await e.repo(y);if(g)return{repo:g,repoId:y};if(!n)return null;let w=typeof n=="object"?{defaultBranch:n.defaultBranch}:void 0;return{repo:await e.createRepo(y,w),repoId:y}}let i=hn(r.policy,r.hooks),o=r.session??ln,f=r.packCache===!1?void 0:new fe(r.packCache?.maxBytes),c=r.onError===!1?void 0:r.onError??(b=>{let y=b instanceof Error?b.message:String(b);console.error(`[server] Internal error: ${y}`)}),l=!1,d=0,p=null,u=null;function h(){return l?!1:(d++,!0)}function m(){d--,l&&d===0&&p?.()}let R={async fetch(b){if(!h())return new Response("Service Unavailable",{status:503});let y;try{if(!o.http)return new Response("HTTP session builder not configured",{status:501});let g=await o.http(b);if(g instanceof Response)return g;y=g;let w=new URL(b.url),E=decodeURIComponent(w.pathname);if(s){let x=s.replace(/\/+$/,"");if(!E.startsWith(x))return new Response("Not Found",{status:404});E=E.slice(x.length)}if(E.startsWith("/")||(E=`/${E}`),E.endsWith("/info/refs")&&b.method==="GET"){let x=w.searchParams.get("service");if(x!=="git-upload-pack"&&x!=="git-receive-pack")return new Response("Unsupported service",{status:403});let O=Ye(E,"/info/refs"),j=await a(O);if(!j)return new Response("Not Found",{status:404});let P=await le(j.repo,j.repoId,x,i,y);if(T(P))return new Response(P.message??"Forbidden",{status:403});let A=$e(P.refs,x,P.headTarget);return new Response(A,{headers:{"Content-Type":`application/x-${x}-advertisement`,"Cache-Control":"no-cache"}})}if(E.endsWith("/git-upload-pack")&&b.method==="POST"){let x=Ye(E,"/git-upload-pack"),O=await a(x);if(!O)return new Response("Not Found",{status:404});let j=await cr(b),P=await de(O.repo,j,{cache:f,cacheKey:O.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow});return new Response(P,{headers:{"Content-Type":"application/x-git-upload-pack-result"}})}if(E.endsWith("/git-receive-pack")&&b.method==="POST"){let x=Ye(E,"/git-receive-pack"),O=await a(x);if(!O)return new Response("Not Found",{status:404});let j=await cr(b),P=await We(O.repo,j);if(!P.sawFlush&&P.updates.length===0)return new Response("Bad Request",{status:400});let A=P.capabilities.includes("side-band-64k"),B=P.capabilities.includes("report-status");if(!P.unpackOk){if(B){let C=P.updates.map($=>({name:$.ref,ok:!1,error:"unpack failed"}));return new Response(Y(!1,C,A),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response(new Uint8Array(0),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}let{refResults:I}=await V({repo:O.repo,repoId:O.repoId,ingestResult:P,hooks:i,session:y});if(B){let C=I.map($=>({name:$.ref,ok:$.ok,error:$.error}));return new Response(Y(!0,C,A),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response(new Uint8Array(0),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response("Not Found",{status:404})}catch(g){return c?.(g,y),new Response("Internal Server Error",{status:500})}finally{m()}},async handleSession(b,y,g){if(!h())return y.writeStderr?.(new TextEncoder().encode(`fatal: server shutting down
37
+ `)),128;try{if(!o.ssh)return y.writeStderr?.(new TextEncoder().encode(`fatal: SSH session builder not configured
38
+ `)),128;let w=await o.ssh(g??{});return await nr(b,y,{resolveRepo:a,hooks:i,packCache:f,packOptions:r.packOptions,session:w,onError:c?E=>c(E,w):void 0})}finally{m()}},async updateRefs(b,y,g){if(!h())throw new Error("Server is shutting down");try{let w=await e.repo(b);if(!w)throw new Error(`Repository "${b}" not found`);let E=await Fe(w,y);return V({repo:w,repoId:b,ingestResult:{updates:E,unpackOk:!0,capabilities:[],sawFlush:!0},hooks:i,session:g})}finally{m()}},nodeHandler(b,y){let g=[];b.on("data",w=>g.push(new Uint8Array(w))),b.on("error",()=>{y.writeHead(500),y.end("Internal Server Error")}),b.on("end",()=>{pn(R,b,g,y).catch(()=>{try{y.writeHead(500),y.end("Internal Server Error")}catch{}})})},createRepo:(b,y)=>e.createRepo(b,y),repo:b=>e.repo(b),deleteRepo:b=>e.deleteRepo(b),async gc(b,y){if(!h())throw new Error("Server is shutting down");try{let g=await e.repo(b);if(!g)throw new Error(`Repository "${b}" not found`);return ar(g,r.storage,b,y)}finally{m()}},get closed(){return l},asNetwork(b="http://git"){return{allowed:[b.endsWith("/")?b:`${b}/`],fetch:(g,w)=>R.fetch(new Request(g,w))}},async close(b){if(l)return u??Promise.resolve();if(l=!0,f?.clear(),d!==0){if(u=new Promise(y=>{p=y}),b?.signal){if(b.signal.aborted){p();return}let y=()=>p?.();b.signal.addEventListener("abort",y,{once:!0}),u.then(()=>b.signal.removeEventListener("abort",y))}return u}}};return R}function Ye(r,e){let t=r.slice(0,-e.length);return t.startsWith("/")&&(t=t.slice(1)),t}async function cr(r){let e=new Uint8Array(await r.arrayBuffer()),t=r.headers.get("content-encoding");if(t==="gzip"||t==="x-gzip"){let n=new DecompressionStream("gzip"),s=n.writable.getWriter();return s.write(e),s.close(),new Uint8Array(await new Response(n.readable).arrayBuffer())}return e}async function pn(r,e,t,n){let s=typeof e.headers.host=="string"?e.headers.host:"localhost",a=new URL(e.url??"/",`http://${s}`),i=new Headers;for(let[u,h]of Object.entries(e.headers))if(h!==void 0)if(Array.isArray(h))for(let m of h)i.append(u,m);else i.set(u,h);let o=e.method??"GET",f;if(o!=="GET"&&o!=="HEAD"){let u=0;for(let R of t)u+=R.byteLength;let h=new Uint8Array(u),m=0;for(let R of t)h.set(R,m),m+=R.byteLength;f=h}let c=new Request(a.href,{method:o,headers:i,body:f}),l=await r.fetch(c),d={};l.headers.forEach((u,h)=>{d[h]=u}),n.writeHead(l.status,d);let p=new Uint8Array(await l.arrayBuffer());p.byteLength>0&&n.write(p),n.end()}function un(r){let{protectedBranches:e=[],denyNonFastForward:t=!1,denyDeletes:n=!1,immutableTags:s=!1}=r,a=new Set(e.map(o=>o.startsWith("refs/")?o:`refs/heads/${o}`)),i={};return a.size>0&&(i.preReceive=async o=>{for(let f of o.updates)if(a.has(f.ref)){if(f.isDelete)return{reject:!0,message:`cannot delete protected branch ${f.ref}`};if(!f.isCreate&&!f.isFF)return{reject:!0,message:`non-fast-forward push to protected branch ${f.ref}`}}}),(t||n||s)&&(i.update=async o=>{if(n&&o.update.isDelete)return{reject:!0,message:"ref deletion denied"};if(s&&o.update.ref.startsWith("refs/tags/")){if(o.update.isDelete)return{reject:!0,message:"tag deletion denied"};if(!o.update.isCreate)return{reject:!0,message:"tag overwrite denied"}}if(t&&!o.update.isCreate&&!o.update.isDelete&&!o.update.isFF)return{reject:!0,message:"non-fast-forward"}}),i}function hn(r,e){let t=r?un(r):void 0;return t&&e?fr(t,e):t??e}function fr(...r){let e=r.filter(o=>o!=null);if(e.length===0)return{};if(e.length===1)return e[0];let t={},n=e.filter(o=>o.preReceive).map(o=>o.preReceive);n.length>0&&(t.preReceive=async o=>{for(let f of n){let c=await f(o);if(T(c))return c}});let s=e.filter(o=>o.update).map(o=>o.update);s.length>0&&(t.update=async o=>{for(let f of s){let c=await f(o);if(T(c))return c}});let a=e.filter(o=>o.postReceive).map(o=>o.postReceive);a.length>0&&(t.postReceive=async o=>{for(let f of a)try{await f(o)}catch{}});let i=e.filter(o=>o.advertiseRefs).map(o=>o.advertiseRefs);return i.length>0&&(t.advertiseRefs=async o=>{let f=o.refs;for(let c of i){let l=await c({...o,refs:f});if(T(l))return l;l&&(f=l)}return f}),t}var Ve=class{repos=new Set;objects=new Map;refs=new Map;hasRepo(e){return this.repos.has(e)}insertRepo(e){this.repos.add(e)}deleteRepo(e){this.repos.delete(e),this.objects.get(e)?.clear(),this.objects.delete(e),this.refs.get(e)?.clear(),this.refs.delete(e)}getObject(e,t){let n=this.getObjMap(e).get(t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}putObject(e,t,n,s){let a=this.getObjMap(e);a.has(t)||a.set(t,{type:n,content:new Uint8Array(s)})}putObjects(e,t){let n=this.getObjMap(e);for(let s of t)n.has(s.hash)||n.set(s.hash,{type:s.type,content:new Uint8Array(s.content)})}hasObject(e,t){return this.getObjMap(e).has(t)}findObjectsByPrefix(e,t){let n=[];for(let s of this.getObjMap(e).keys())s.startsWith(t)&&n.push(s);return n}listObjectHashes(e){return Array.from(this.getObjMap(e).keys())}deleteObjects(e,t){let n=this.getObjMap(e),s=0;for(let a of t)n.delete(a)&&s++;return s}getRef(e,t){return this.getRefMap(e).get(t)??null}putRef(e,t,n){this.getRefMap(e).set(t,n)}removeRef(e,t){this.getRefMap(e).delete(t)}listRefs(e,t){let n=[];for(let[s,a]of this.getRefMap(e))t&&!s.startsWith(t)||n.push({name:s,ref:a});return n}atomicRefUpdate(e,t){let n=this.getRefMap(e);return t({getRef:s=>n.get(s)??null,putRef:(s,a)=>{n.set(s,a)},removeRef:s=>{n.delete(s)}})}repoIds(){return Array.from(this.repos)}getObjMap(e){let t=this.objects.get(e);return t||(t=new Map,this.objects.set(e,t)),t}getRefMap(e){let t=this.refs.get(e);return t||(t=new Map,this.refs.set(e,t)),t}};var yn=`
38
39
  CREATE TABLE IF NOT EXISTS repos (
39
40
  id TEXT PRIMARY KEY
40
41
  );
@@ -55,7 +56,7 @@ CREATE TABLE IF NOT EXISTS git_refs (
55
56
  target TEXT,
56
57
  PRIMARY KEY (repo_id, name)
57
58
  ) WITHOUT ROWID;
58
- `;function on(r){return{repoInsert:r.prepare("INSERT INTO repos (id) VALUES (?)"),repoExists:r.prepare("SELECT 1 FROM repos WHERE id = ? LIMIT 1"),repoDelete:r.prepare("DELETE FROM repos WHERE id = ?"),objInsert:r.prepare("INSERT OR IGNORE INTO git_objects (repo_id, hash, type, content) VALUES (?, ?, ?, ?)"),objRead:r.prepare("SELECT type, content FROM git_objects WHERE repo_id = ? AND hash = ?"),objExists:r.prepare("SELECT 1 FROM git_objects WHERE repo_id = ? AND hash = ? LIMIT 1"),objPrefix:r.prepare("SELECT hash FROM git_objects WHERE repo_id = ? AND hash GLOB ?"),objDeleteAll:r.prepare("DELETE FROM git_objects WHERE repo_id = ?"),refRead:r.prepare("SELECT type, hash, target FROM git_refs WHERE repo_id = ? AND name = ?"),refWrite:r.prepare("INSERT OR REPLACE INTO git_refs (repo_id, name, type, hash, target) VALUES (?, ?, ?, ?, ?)"),refDelete:r.prepare("DELETE FROM git_refs WHERE repo_id = ? AND name = ?"),refList:r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ? AND name GLOB ?"),refListAll:r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ?"),refDeleteAll:r.prepare("DELETE FROM git_refs WHERE repo_id = ?")}}var Ve=class{constructor(e){this.db=e;e.run(an),this.stmts=on(e),this.batchInsertTx=e.transaction(t=>{for(let n of t)this.stmts.objInsert.run(n.repoId,n.hash,n.type,n.content)})}stmts;batchInsertTx;hasRepo(e){return this.stmts.repoExists.get(e)!==null}insertRepo(e){this.stmts.repoInsert.run(e)}deleteRepo(e){this.stmts.repoDelete.run(e),this.stmts.objDeleteAll.run(e),this.stmts.refDeleteAll.run(e)}getObject(e,t){let n=this.stmts.objRead.get(e,t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}putObject(e,t,n,s){this.stmts.objInsert.run(e,t,n,s)}putObjects(e,t){this.batchInsertTx(t.map(n=>({repoId:e,...n})))}hasObject(e,t){return this.stmts.objExists.get(e,t)!==null}findObjectsByPrefix(e,t){return this.stmts.objPrefix.all(e,`${t}*`).map(s=>s.hash)}getRef(e,t){let n=this.stmts.refRead.get(e,t);return Ye(n)}putRef(e,t,n){n.type==="symbolic"?this.stmts.refWrite.run(e,t,"symbolic",null,n.target):this.stmts.refWrite.run(e,t,"direct",n.hash,null)}removeRef(e,t){this.stmts.refDelete.run(e,t)}listRefs(e,t){return(t?this.stmts.refList.all(e,`${t}*`):this.stmts.refListAll.all(e)).flatMap(s=>{let a=Ye(s);return a?[{name:s.name,ref:a}]:[]})}atomicRefUpdate(e,t){let n=this.stmts;return this.db.transaction(()=>t({getRef:a=>Ye(n.refRead.get(e,a)),putRef:(a,i)=>{i.type==="symbolic"?n.refWrite.run(e,a,"symbolic",null,i.target):n.refWrite.run(e,a,"direct",i.hash,null)},removeRef:a=>{n.refDelete.run(e,a)}}))()}};function Ye(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}var cn=`
59
+ `;function bn(r){return{repoInsert:r.prepare("INSERT INTO repos (id) VALUES (?)"),repoExists:r.prepare("SELECT 1 FROM repos WHERE id = ? LIMIT 1"),repoDelete:r.prepare("DELETE FROM repos WHERE id = ?"),objInsert:r.prepare("INSERT OR IGNORE INTO git_objects (repo_id, hash, type, content) VALUES (?, ?, ?, ?)"),objRead:r.prepare("SELECT type, content FROM git_objects WHERE repo_id = ? AND hash = ?"),objExists:r.prepare("SELECT 1 FROM git_objects WHERE repo_id = ? AND hash = ? LIMIT 1"),objPrefix:r.prepare("SELECT hash FROM git_objects WHERE repo_id = ? AND hash GLOB ?"),objDeleteAll:r.prepare("DELETE FROM git_objects WHERE repo_id = ?"),objListHashes:r.prepare("SELECT hash FROM git_objects WHERE repo_id = ?"),objDelete:r.prepare("DELETE FROM git_objects WHERE repo_id = ? AND hash = ?"),refRead:r.prepare("SELECT type, hash, target FROM git_refs WHERE repo_id = ? AND name = ?"),refWrite:r.prepare("INSERT OR REPLACE INTO git_refs (repo_id, name, type, hash, target) VALUES (?, ?, ?, ?, ?)"),refDelete:r.prepare("DELETE FROM git_refs WHERE repo_id = ? AND name = ?"),refList:r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ? AND name GLOB ?"),refListAll:r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ?"),refDeleteAll:r.prepare("DELETE FROM git_refs WHERE repo_id = ?")}}var Je=class{constructor(e){this.db=e;e.run(yn),this.stmts=bn(e),this.batchInsertTx=e.transaction(t=>{for(let n of t)this.stmts.objInsert.run(n.repoId,n.hash,n.type,n.content)}),this.batchDeleteTx=e.transaction((t,n,s)=>{let a=0;for(let i of n)this.stmts.objDelete.run(t,i),a++;s(a)})}stmts;batchInsertTx;batchDeleteTx;hasRepo(e){return this.stmts.repoExists.get(e)!==null}insertRepo(e){this.stmts.repoInsert.run(e)}deleteRepo(e){this.stmts.repoDelete.run(e),this.stmts.objDeleteAll.run(e),this.stmts.refDeleteAll.run(e)}getObject(e,t){let n=this.stmts.objRead.get(e,t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}putObject(e,t,n,s){this.stmts.objInsert.run(e,t,n,s)}putObjects(e,t){this.batchInsertTx(t.map(n=>({repoId:e,...n})))}hasObject(e,t){return this.stmts.objExists.get(e,t)!==null}findObjectsByPrefix(e,t){return this.stmts.objPrefix.all(e,`${t}*`).map(s=>s.hash)}listObjectHashes(e){return this.stmts.objListHashes.all(e).map(n=>n.hash)}deleteObjects(e,t){if(t.length===0)return 0;let n=0;return this.batchDeleteTx(e,t,s=>{n+=s}),n}getRef(e,t){let n=this.stmts.refRead.get(e,t);return Ze(n)}putRef(e,t,n){n.type==="symbolic"?this.stmts.refWrite.run(e,t,"symbolic",null,n.target):this.stmts.refWrite.run(e,t,"direct",n.hash,null)}removeRef(e,t){this.stmts.refDelete.run(e,t)}listRefs(e,t){return(t?this.stmts.refList.all(e,`${t}*`):this.stmts.refListAll.all(e)).flatMap(s=>{let a=Ze(s);return a?[{name:s.name,ref:a}]:[]})}atomicRefUpdate(e,t){let n=this.stmts;return this.db.transaction(()=>t({getRef:a=>Ze(n.refRead.get(e,a)),putRef:(a,i)=>{i.type==="symbolic"?n.refWrite.run(e,a,"symbolic",null,i.target):n.refWrite.run(e,a,"direct",i.hash,null)},removeRef:a=>{n.refDelete.run(e,a)}}))()}};function Ze(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}var mn=`
59
60
  CREATE TABLE IF NOT EXISTS repos (
60
61
  id TEXT PRIMARY KEY
61
62
  );
@@ -76,7 +77,7 @@ CREATE TABLE IF NOT EXISTS git_refs (
76
77
  target TEXT,
77
78
  PRIMARY KEY (repo_id, name)
78
79
  ) WITHOUT ROWID;
79
- `;function A(r){return{run:(...e)=>{r.run(...e)},get:(...e)=>r.get(...e)??null,all:(...e)=>r.all(...e)}}function fn(r){return{repoInsert:A(r.prepare("INSERT INTO repos (id) VALUES (?)")),repoExists:A(r.prepare("SELECT 1 FROM repos WHERE id = ? LIMIT 1")),repoDelete:A(r.prepare("DELETE FROM repos WHERE id = ?")),objInsert:A(r.prepare("INSERT OR IGNORE INTO git_objects (repo_id, hash, type, content) VALUES (?, ?, ?, ?)")),objRead:A(r.prepare("SELECT type, content FROM git_objects WHERE repo_id = ? AND hash = ?")),objExists:A(r.prepare("SELECT 1 FROM git_objects WHERE repo_id = ? AND hash = ? LIMIT 1")),objPrefix:A(r.prepare("SELECT hash FROM git_objects WHERE repo_id = ? AND hash GLOB ?")),objDeleteAll:A(r.prepare("DELETE FROM git_objects WHERE repo_id = ?")),refRead:A(r.prepare("SELECT type, hash, target FROM git_refs WHERE repo_id = ? AND name = ?")),refWrite:A(r.prepare("INSERT OR REPLACE INTO git_refs (repo_id, name, type, hash, target) VALUES (?, ?, ?, ?, ?)")),refDelete:A(r.prepare("DELETE FROM git_refs WHERE repo_id = ? AND name = ?")),refList:A(r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ? AND name GLOB ?")),refListAll:A(r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ?")),refDeleteAll:A(r.prepare("DELETE FROM git_refs WHERE repo_id = ?"))}}var Je=class{constructor(e){this.db=e;e.exec(cn),this.stmts=fn(e),this.batchInsertTx=e.transaction(t=>{for(let n of t)this.stmts.objInsert.run(n.repoId,n.hash,n.type,n.content)})}stmts;batchInsertTx;hasRepo(e){return this.stmts.repoExists.get(e)!==null}insertRepo(e){this.stmts.repoInsert.run(e)}deleteRepo(e){this.stmts.repoDelete.run(e),this.stmts.objDeleteAll.run(e),this.stmts.refDeleteAll.run(e)}getObject(e,t){let n=this.stmts.objRead.get(e,t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}putObject(e,t,n,s){this.stmts.objInsert.run(e,t,n,s)}putObjects(e,t){this.batchInsertTx(t.map(n=>({repoId:e,...n})))}hasObject(e,t){return this.stmts.objExists.get(e,t)!==null}findObjectsByPrefix(e,t){return this.stmts.objPrefix.all(e,`${t}*`).map(s=>s.hash)}getRef(e,t){let n=this.stmts.refRead.get(e,t);return Ze(n)}putRef(e,t,n){n.type==="symbolic"?this.stmts.refWrite.run(e,t,"symbolic",null,n.target):this.stmts.refWrite.run(e,t,"direct",n.hash,null)}removeRef(e,t){this.stmts.refDelete.run(e,t)}listRefs(e,t){return(t?this.stmts.refList.all(e,`${t}*`):this.stmts.refListAll.all(e)).flatMap(s=>{let a=Ze(s);return a?[{name:s.name,ref:a}]:[]})}atomicRefUpdate(e,t){let n=this.stmts;return this.db.transaction(()=>t({getRef:a=>Ze(n.refRead.get(e,a)),putRef:(a,i)=>{i.type==="symbolic"?n.refWrite.run(e,a,"symbolic",null,i.target):n.refWrite.run(e,a,"direct",i.hash,null)},removeRef:a=>{n.refDelete.run(e,a)}}))()}};function Ze(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}function ln(r){return{query:(e,t)=>r.query(e,t),async transaction(e){let t=await r.connect();try{await t.query("BEGIN");let s=await e({query:(a,i)=>t.query(a,i),transaction:()=>{throw new Error("nested transactions not supported")}});return await t.query("COMMIT"),s}catch(n){throw await t.query("ROLLBACK"),n}finally{t.release()}}}}var dn=`
80
+ `;function S(r){return{run:(...e)=>{r.run(...e)},get:(...e)=>r.get(...e)??null,all:(...e)=>r.all(...e)}}function gn(r){return{repoInsert:S(r.prepare("INSERT INTO repos (id) VALUES (?)")),repoExists:S(r.prepare("SELECT 1 FROM repos WHERE id = ? LIMIT 1")),repoDelete:S(r.prepare("DELETE FROM repos WHERE id = ?")),objInsert:S(r.prepare("INSERT OR IGNORE INTO git_objects (repo_id, hash, type, content) VALUES (?, ?, ?, ?)")),objRead:S(r.prepare("SELECT type, content FROM git_objects WHERE repo_id = ? AND hash = ?")),objExists:S(r.prepare("SELECT 1 FROM git_objects WHERE repo_id = ? AND hash = ? LIMIT 1")),objPrefix:S(r.prepare("SELECT hash FROM git_objects WHERE repo_id = ? AND hash GLOB ?")),objDeleteAll:S(r.prepare("DELETE FROM git_objects WHERE repo_id = ?")),objListHashes:S(r.prepare("SELECT hash FROM git_objects WHERE repo_id = ?")),objDelete:S(r.prepare("DELETE FROM git_objects WHERE repo_id = ? AND hash = ?")),refRead:S(r.prepare("SELECT type, hash, target FROM git_refs WHERE repo_id = ? AND name = ?")),refWrite:S(r.prepare("INSERT OR REPLACE INTO git_refs (repo_id, name, type, hash, target) VALUES (?, ?, ?, ?, ?)")),refDelete:S(r.prepare("DELETE FROM git_refs WHERE repo_id = ? AND name = ?")),refList:S(r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ? AND name GLOB ?")),refListAll:S(r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ?")),refDeleteAll:S(r.prepare("DELETE FROM git_refs WHERE repo_id = ?"))}}var et=class{constructor(e){this.db=e;e.exec(mn),this.stmts=gn(e),this.batchInsertTx=e.transaction(t=>{for(let n of t)this.stmts.objInsert.run(n.repoId,n.hash,n.type,n.content)}),this.batchDeleteTx=e.transaction((t,n,s)=>{let a=0;for(let i of n)this.stmts.objDelete.run(t,i),a++;s(a)})}stmts;batchInsertTx;batchDeleteTx;hasRepo(e){return this.stmts.repoExists.get(e)!==null}insertRepo(e){this.stmts.repoInsert.run(e)}deleteRepo(e){this.stmts.repoDelete.run(e),this.stmts.objDeleteAll.run(e),this.stmts.refDeleteAll.run(e)}getObject(e,t){let n=this.stmts.objRead.get(e,t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}putObject(e,t,n,s){this.stmts.objInsert.run(e,t,n,s)}putObjects(e,t){this.batchInsertTx(t.map(n=>({repoId:e,...n})))}hasObject(e,t){return this.stmts.objExists.get(e,t)!==null}findObjectsByPrefix(e,t){return this.stmts.objPrefix.all(e,`${t}*`).map(s=>s.hash)}listObjectHashes(e){return this.stmts.objListHashes.all(e).map(n=>n.hash)}deleteObjects(e,t){if(t.length===0)return 0;let n=0;return this.batchDeleteTx(e,t,s=>{n+=s}),n}getRef(e,t){let n=this.stmts.refRead.get(e,t);return Qe(n)}putRef(e,t,n){n.type==="symbolic"?this.stmts.refWrite.run(e,t,"symbolic",null,n.target):this.stmts.refWrite.run(e,t,"direct",n.hash,null)}removeRef(e,t){this.stmts.refDelete.run(e,t)}listRefs(e,t){return(t?this.stmts.refList.all(e,`${t}*`):this.stmts.refListAll.all(e)).flatMap(s=>{let a=Qe(s);return a?[{name:s.name,ref:a}]:[]})}atomicRefUpdate(e,t){let n=this.stmts;return this.db.transaction(()=>t({getRef:a=>Qe(n.refRead.get(e,a)),putRef:(a,i)=>{i.type==="symbolic"?n.refWrite.run(e,a,"symbolic",null,i.target):n.refWrite.run(e,a,"direct",i.hash,null)},removeRef:a=>{n.refDelete.run(e,a)}}))()}};function Qe(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}function Rn(r){return{query:(e,t)=>r.query(e,t),async transaction(e){let t=await r.connect();try{await t.query("BEGIN");let s=await e({query:(a,i)=>t.query(a,i),transaction:()=>{throw new Error("nested transactions not supported")}});return await t.query("COMMIT"),s}catch(n){throw await t.query("ROLLBACK"),n}finally{t.release()}}}}var xn=`
80
81
  CREATE TABLE IF NOT EXISTS repos (
81
82
  id TEXT PRIMARY KEY
82
83
  );
@@ -97,5 +98,5 @@ CREATE TABLE IF NOT EXISTS git_refs (
97
98
  target TEXT,
98
99
  PRIMARY KEY (repo_id, name)
99
100
  );
100
- `,v={repoInsert:"INSERT INTO repos (id) VALUES ($1)",repoExists:"SELECT 1 FROM repos WHERE id = $1 LIMIT 1",repoDelete:"DELETE FROM repos WHERE id = $1",objInsert:"INSERT INTO git_objects (repo_id, hash, type, content) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING",objRead:"SELECT type, content FROM git_objects WHERE repo_id = $1 AND hash = $2",objExists:"SELECT 1 FROM git_objects WHERE repo_id = $1 AND hash = $2 LIMIT 1",objPrefix:"SELECT hash FROM git_objects WHERE repo_id = $1 AND hash LIKE $2",objDeleteAll:"DELETE FROM git_objects WHERE repo_id = $1",refRead:"SELECT type, hash, target FROM git_refs WHERE repo_id = $1 AND name = $2",refReadForUpdate:"SELECT type, hash, target FROM git_refs WHERE repo_id = $1 AND name = $2 FOR UPDATE",refWrite:`INSERT INTO git_refs (repo_id, name, type, hash, target) VALUES ($1, $2, $3, $4, $5)
101
- ON CONFLICT (repo_id, name) DO UPDATE SET type = EXCLUDED.type, hash = EXCLUDED.hash, target = EXCLUDED.target`,refDelete:"DELETE FROM git_refs WHERE repo_id = $1 AND name = $2",refList:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = $1 AND name LIKE $2",refListAll:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = $1",refDeleteAll:"DELETE FROM git_refs WHERE repo_id = $1"},et=class r{constructor(e){this.db=e}static async create(e){return await e.query(dn),new r(e)}async hasRepo(e){let{rows:t}=await this.db.query(v.repoExists,[e]);return t.length>0}async insertRepo(e){await this.db.query(v.repoInsert,[e])}async deleteRepo(e){await this.db.query(v.repoDelete,[e]),await this.db.query(v.objDeleteAll,[e]),await this.db.query(v.refDeleteAll,[e])}async getObject(e,t){let{rows:n}=await this.db.query(v.objRead,[e,t]),s=n[0];return s?{type:s.type,content:new Uint8Array(s.content)}:null}async putObject(e,t,n,s){await this.db.query(v.objInsert,[e,t,n,s])}async putObjects(e,t){await this.db.transaction(async n=>{for(let s of t)await n.query(v.objInsert,[e,s.hash,s.type,s.content])})}async hasObject(e,t){let{rows:n}=await this.db.query(v.objExists,[e,t]);return n.length>0}async findObjectsByPrefix(e,t){let{rows:n}=await this.db.query(v.objPrefix,[e,`${t}%`]);return n.map(s=>s.hash)}async getRef(e,t){let{rows:n}=await this.db.query(v.refRead,[e,t]);return Qe(n[0]??null)}async putRef(e,t,n){n.type==="symbolic"?await this.db.query(v.refWrite,[e,t,"symbolic",null,n.target]):await this.db.query(v.refWrite,[e,t,"direct",n.hash,null])}async removeRef(e,t){await this.db.query(v.refDelete,[e,t])}async listRefs(e,t){let n;return t?{rows:n}=await this.db.query(v.refList,[e,`${t}%`]):{rows:n}=await this.db.query(v.refListAll,[e]),n.flatMap(s=>{let a=Qe(s);return a?[{name:s.name,ref:a}]:[]})}async atomicRefUpdate(e,t){return this.db.transaction(async n=>t({getRef:async s=>{let{rows:a}=await n.query(v.refReadForUpdate,[e,s]);return Qe(a[0]??null)},putRef:async(s,a)=>{a.type==="symbolic"?await n.query(v.refWrite,[e,s,"symbolic",null,a.target]):await n.query(v.refWrite,[e,s,"direct",a.hash,null])},removeRef:async s=>{await n.query(v.refDelete,[e,s])}}))}};function Qe(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}export{Je as BetterSqlite3Storage,Ve as BunSqliteStorage,Ke as MemoryStorage,et as PgStorage,ce as advertiseRefsWithHooks,le as applyReceivePack,Me as buildRefAdvertisementBytes,$e as buildRefListBytes,Oe as buildRefListPktLines,Jt as collectRefs,sr as composeHooks,tn as createServer,fe as handleUploadPack,We as ingestReceivePack,_e as ingestReceivePackFromStream,ln as wrapPgPool};
101
+ `,k={repoInsert:"INSERT INTO repos (id) VALUES ($1)",repoExists:"SELECT 1 FROM repos WHERE id = $1 LIMIT 1",repoDelete:"DELETE FROM repos WHERE id = $1",objInsert:"INSERT INTO git_objects (repo_id, hash, type, content) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING",objRead:"SELECT type, content FROM git_objects WHERE repo_id = $1 AND hash = $2",objExists:"SELECT 1 FROM git_objects WHERE repo_id = $1 AND hash = $2 LIMIT 1",objPrefix:"SELECT hash FROM git_objects WHERE repo_id = $1 AND hash LIKE $2",objDeleteAll:"DELETE FROM git_objects WHERE repo_id = $1",objListHashes:"SELECT hash FROM git_objects WHERE repo_id = $1",refRead:"SELECT type, hash, target FROM git_refs WHERE repo_id = $1 AND name = $2",refReadForUpdate:"SELECT type, hash, target FROM git_refs WHERE repo_id = $1 AND name = $2 FOR UPDATE",refWrite:`INSERT INTO git_refs (repo_id, name, type, hash, target) VALUES ($1, $2, $3, $4, $5)
102
+ ON CONFLICT (repo_id, name) DO UPDATE SET type = EXCLUDED.type, hash = EXCLUDED.hash, target = EXCLUDED.target`,refDelete:"DELETE FROM git_refs WHERE repo_id = $1 AND name = $2",refList:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = $1 AND name LIKE $2",refListAll:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = $1",refDeleteAll:"DELETE FROM git_refs WHERE repo_id = $1"},rt=class r{constructor(e){this.db=e}static async create(e){return await e.query(xn),new r(e)}async hasRepo(e){let{rows:t}=await this.db.query(k.repoExists,[e]);return t.length>0}async insertRepo(e){await this.db.query(k.repoInsert,[e])}async deleteRepo(e){await this.db.query(k.repoDelete,[e]),await this.db.query(k.objDeleteAll,[e]),await this.db.query(k.refDeleteAll,[e])}async getObject(e,t){let{rows:n}=await this.db.query(k.objRead,[e,t]),s=n[0];return s?{type:s.type,content:new Uint8Array(s.content)}:null}async putObject(e,t,n,s){await this.db.query(k.objInsert,[e,t,n,s])}async putObjects(e,t){await this.db.transaction(async n=>{for(let s of t)await n.query(k.objInsert,[e,s.hash,s.type,s.content])})}async hasObject(e,t){let{rows:n}=await this.db.query(k.objExists,[e,t]);return n.length>0}async findObjectsByPrefix(e,t){let{rows:n}=await this.db.query(k.objPrefix,[e,`${t}%`]);return n.map(s=>s.hash)}async listObjectHashes(e){let{rows:t}=await this.db.query(k.objListHashes,[e]);return t.map(n=>n.hash)}async deleteObjects(e,t){if(t.length===0)return 0;let{rows:n}=await this.db.query("DELETE FROM git_objects WHERE repo_id = $1 AND hash = ANY($2::text[]) RETURNING hash",[e,Array.from(t)]);return n.length}async getRef(e,t){let{rows:n}=await this.db.query(k.refRead,[e,t]);return tt(n[0]??null)}async putRef(e,t,n){n.type==="symbolic"?await this.db.query(k.refWrite,[e,t,"symbolic",null,n.target]):await this.db.query(k.refWrite,[e,t,"direct",n.hash,null])}async removeRef(e,t){await this.db.query(k.refDelete,[e,t])}async listRefs(e,t){let n;return t?{rows:n}=await this.db.query(k.refList,[e,`${t}%`]):{rows:n}=await this.db.query(k.refListAll,[e]),n.flatMap(s=>{let a=tt(s);return a?[{name:s.name,ref:a}]:[]})}async atomicRefUpdate(e,t){return this.db.transaction(async n=>t({getRef:async s=>{let{rows:a}=await n.query(k.refReadForUpdate,[e,s]);return tt(a[0]??null)},putRef:async(s,a)=>{a.type==="symbolic"?await n.query(k.refWrite,[e,s,"symbolic",null,a.target]):await n.query(k.refWrite,[e,s,"direct",a.hash,null])},removeRef:async s=>{await n.query(k.refDelete,[e,s])}}))}};function tt(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}export{et as BetterSqlite3Storage,Je as BunSqliteStorage,Ve as MemoryStorage,rt as PgStorage,le as advertiseRefsWithHooks,V as applyReceivePack,$e as buildRefAdvertisementBytes,_e as buildRefListBytes,ve as buildRefListPktLines,er as collectRefs,fr as composeHooks,dn as createServer,de as handleUploadPack,We as ingestReceivePack,Ge as ingestReceivePackFromStream,Fe as resolveRefUpdates,Rn as wrapPgPool};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-git",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Pure TypeScript git implementation: virtual filesystem client and embeddable server.",
5
5
  "keywords": [
6
6
  "agent",