just-git 1.5.3 → 1.5.5

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
@@ -59,7 +59,7 @@ Use '--' to separate paths from revisions, like this:
59
59
  `)+`
60
60
  `}function Mt(e){return e.endsWith(`
61
61
  `)?e:`${e}
62
- `}var am,cm,oe=Re(()=>{"use strict";Tn();Ce();ae();gn();me();ze();ge();Gn();sn();fn();am=I("not a git repository (or any of the parent directories): .git"),cm=I("this operation must be run in a work tree")});var Zc={};Hd(Zc,{CommitHeap:()=>Wn,countAheadBehind:()=>Hi,findOrphanedCommits:()=>Di,walkCommits:()=>jt});async function*jt(e,t,n){if(n?.topoOrder){yield*hm(e,t,n);return}let r=await Xc(e,n?.exclude),o=new Set(r),s=new Wn,i=n?.shallowBoundary,a=Array.isArray(t)?t:[t];for(let c of a)o.has(c)||s.push(await Or(e,c));for(;s.size>0;){let c=s.pop();if(o.has(c.hash)||(o.add(c.hash),yield c,i?.has(c.hash)))continue;let f=n?.firstParent?c.commit.parents.slice(0,1):c.commit.parents;for(let l of f)if(!o.has(l))try{s.push(await Or(e,l))}catch{}}}async function*hm(e,t,n){let r=await Xc(e,n?.exclude),o=new Set(r),s=new Wn,i=n?.shallowBoundary,a=Array.isArray(t)?t:[t];for(let m of a)o.has(m)||s.push(await Or(e,m));let c=[],f=new Map;for(;s.size>0;){let m=s.pop();if(o.has(m.hash)||(o.add(m.hash),f.set(m.hash,c.length),c.push(m),i?.has(m.hash)))continue;let h=n?.firstParent?m.commit.parents.slice(0,1):m.commit.parents;for(let p of h)if(!o.has(p))try{s.push(await Or(e,p))}catch{}}let l=c.length;if(l===0)return;let d=new Int32Array(l);for(let m of c){let h=n?.firstParent?m.commit.parents.slice(0,1):m.commit.parents;for(let p of h){let g=f.get(p);g!==void 0&&(d[g]=(d[g]??0)+1)}}let u=[];for(let m=l-1;m>=0;m--)d[m]===0&&u.push(m);for(;u.length>0;){let m=u.pop();yield c[m];let h=n?.firstParent?c[m].commit.parents.slice(0,1):c[m].commit.parents;for(let p of h){let g=f.get(p);if(g!==void 0){let w=(d[g]??0)-1;d[g]=w,w===0&&u.push(g)}}}}async function Hi(e,t,n){if(t===n)return{ahead:0,behind:0};let r=new Set;for await(let a of jt(e,t))r.add(a.hash);let o=new Set;for await(let a of jt(e,n))o.add(a.hash);let s=0;for(let a of r)o.has(a)||s++;let i=0;for(let a of o)r.has(a)||i++;return{ahead:s,behind:i}}async function Di(e,t,n){let r=n?.maxCount??25,o=await pe(e,"refs"),s=[];for(let l of o)try{s.push(await ve(e,l.hash))}catch{}n?.targetHash&&s.push(n.targetHash);let i=new Set;if(s.length>0)for await(let l of jt(e,s))i.add(l.hash);if(i.has(t))return[];let a=[],c=new Set,f=new Wn;for(f.push(await Or(e,t));f.size>0&&a.length<r;){let l=f.pop();if(!c.has(l.hash)&&(c.add(l.hash),!i.has(l.hash))){a.push({hash:l.hash,subject:ue(l.commit.message)});for(let d of l.commit.parents)c.has(d)||f.push(await Or(e,d))}}return a}async function Xc(e,t){if(!t||t.length===0)return new Set;let n=new Set;for await(let r of jt(e,t))n.add(r.hash);return n}async function Or(e,t){return{hash:t,commit:await j(e,t)}}var Wn,ar=Re(()=>{"use strict";oe();ae();ge();Wn=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(t){this.heap.push({entry:t,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:t}=this;if(t.length===0)return;let n=t[0],r=t.pop();return t.length>0&&(t[0]=r,this.siftDown(0)),n.entry}higher(t,n){let r=t.entry.commit.committer.timestamp,o=n.entry.commit.committer.timestamp;return r>o||r===o&&t.epoch<n.epoch}siftUp(t){let{heap:n}=this;for(;t>0;){let r=t-1>>1;if(!this.higher(n[t],n[r]))break;[n[r],n[t]]=[n[t],n[r]],t=r}}siftDown(t){let{heap:n}=this,r=n.length;for(;;){let o=t,s=2*t+1,i=2*t+2;if(s<r&&this.higher(n[s],n[o])&&(o=s),i<r&&this.higher(n[i],n[o])&&(o=i),o===t)break;[n[t],n[o]]=[n[o],n[t]],t=o}}}});var Ko=class e{_def;constructor(t){this._def=t}name(t){return new e({...this._def,name:t})}describe(t){return new e({...this._def,description:t})}optional(){return new e({...this._def,required:!1})}variadic(){return new e({...this._def,variadic:!0})}default(t){return new e({...this._def,required:!1,default:t})}};function Ia(e){return new Ko({_kind:"arg",type:e,required:!0})}function Sa(){return Ia("string")}function Ta(){return Ia("number")}var Ss=class e{_def;constructor(t={_kind:"flag"}){this._def=t}describe(t){return new e({...this._def,description:t})}alias(t){return new e({...this._def,short:t})}default(t){return new e({...this._def,default:t})}count(){return new e({...this._def,counted:!0})}};var Vo=class e{_def;constructor(t){this._def=t}describe(t){return new e({...this._def,description:t})}alias(t){return new e({...this._def,short:t})}env(t){return new e({...this._def,env:t})}required(){return new e({...this._def,required:!0})}default(t){return new e({...this._def,default:t})}repeatable(){return new e({...this._def,repeatable:!0,default:[]})}};function va(e){return new Vo({_kind:"option",type:e})}function Aa(){return va("string")}function Ha(){return va("number")}var V={string:Aa,number:Ha};function $(){return new Ss}var q={string:Sa,number:Ta};function Dd(e){switch(e.type){case"unknown_option":{let t=`Unknown option "${e.name}".`;return e.suggestions.length>0&&(t+=` Did you mean ${e.suggestions.map(n=>`"${n}"`).join(" or ")}?`),t+=`
62
+ `}var am,cm,oe=Re(()=>{"use strict";Tn();Ce();ae();gn();me();ze();ge();Gn();sn();fn();am=I("not a git repository (or any of the parent directories): .git"),cm=I("this operation must be run in a work tree")});var Zc={};Hd(Zc,{CommitHeap:()=>Wn,countAheadBehind:()=>Hi,findOrphanedCommits:()=>Di,walkCommits:()=>jt});async function*jt(e,t,n){if(n?.topoOrder){yield*hm(e,t,n);return}let r=await Xc(e,n?.exclude),o=new Set(r),s=new Wn,i=n?.shallowBoundary,a=n?.limit,c=0,f=Array.isArray(t)?t:[t];for(let l of f)o.has(l)||s.push(await Or(e,l));for(;s.size>0;){let l=s.pop();if(o.has(l.hash))continue;if(o.add(l.hash),yield l,a!==void 0&&++c>=a)return;if(i?.has(l.hash))continue;let d=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let u of d)if(!o.has(u))try{s.push(await Or(e,u))}catch{}}}async function*hm(e,t,n){let r=await Xc(e,n?.exclude),o=new Set(r),s=new Wn,i=n?.shallowBoundary,a=Array.isArray(t)?t:[t];for(let m of a)o.has(m)||s.push(await Or(e,m));let c=[],f=new Map;for(;s.size>0;){let m=s.pop();if(o.has(m.hash)||(o.add(m.hash),f.set(m.hash,c.length),c.push(m),i?.has(m.hash)))continue;let h=n?.firstParent?m.commit.parents.slice(0,1):m.commit.parents;for(let p of h)if(!o.has(p))try{s.push(await Or(e,p))}catch{}}let l=c.length;if(l===0)return;let d=new Int32Array(l);for(let m of c){let h=n?.firstParent?m.commit.parents.slice(0,1):m.commit.parents;for(let p of h){let g=f.get(p);g!==void 0&&(d[g]=(d[g]??0)+1)}}let u=[];for(let m=l-1;m>=0;m--)d[m]===0&&u.push(m);for(;u.length>0;){let m=u.pop();yield c[m];let h=n?.firstParent?c[m].commit.parents.slice(0,1):c[m].commit.parents;for(let p of h){let g=f.get(p);if(g!==void 0){let w=(d[g]??0)-1;d[g]=w,w===0&&u.push(g)}}}}async function Hi(e,t,n){if(t===n)return{ahead:0,behind:0};let r=new Set;for await(let a of jt(e,t))r.add(a.hash);let o=new Set;for await(let a of jt(e,n))o.add(a.hash);let s=0;for(let a of r)o.has(a)||s++;let i=0;for(let a of o)r.has(a)||i++;return{ahead:s,behind:i}}async function Di(e,t,n){let r=n?.maxCount??25,o=await pe(e,"refs"),s=[];for(let l of o)try{s.push(await ve(e,l.hash))}catch{}n?.targetHash&&s.push(n.targetHash);let i=new Set;if(s.length>0)for await(let l of jt(e,s))i.add(l.hash);if(i.has(t))return[];let a=[],c=new Set,f=new Wn;for(f.push(await Or(e,t));f.size>0&&a.length<r;){let l=f.pop();if(!c.has(l.hash)&&(c.add(l.hash),!i.has(l.hash))){a.push({hash:l.hash,subject:ue(l.commit.message)});for(let d of l.commit.parents)c.has(d)||f.push(await Or(e,d))}}return a}async function Xc(e,t){if(!t||t.length===0)return new Set;let n=new Set;for await(let r of jt(e,t))n.add(r.hash);return n}async function Or(e,t){return{hash:t,commit:await j(e,t)}}var Wn,ar=Re(()=>{"use strict";oe();ae();ge();Wn=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(t){this.heap.push({entry:t,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:t}=this;if(t.length===0)return;let n=t[0],r=t.pop();return t.length>0&&(t[0]=r,this.siftDown(0)),n.entry}higher(t,n){let r=t.entry.commit.committer.timestamp,o=n.entry.commit.committer.timestamp;return r>o||r===o&&t.epoch<n.epoch}siftUp(t){let{heap:n}=this;for(;t>0;){let r=t-1>>1;if(!this.higher(n[t],n[r]))break;[n[r],n[t]]=[n[t],n[r]],t=r}}siftDown(t){let{heap:n}=this,r=n.length;for(;;){let o=t,s=2*t+1,i=2*t+2;if(s<r&&this.higher(n[s],n[o])&&(o=s),i<r&&this.higher(n[i],n[o])&&(o=i),o===t)break;[n[t],n[o]]=[n[o],n[t]],t=o}}}});var Ko=class e{_def;constructor(t){this._def=t}name(t){return new e({...this._def,name:t})}describe(t){return new e({...this._def,description:t})}optional(){return new e({...this._def,required:!1})}variadic(){return new e({...this._def,variadic:!0})}default(t){return new e({...this._def,required:!1,default:t})}};function Ia(e){return new Ko({_kind:"arg",type:e,required:!0})}function Sa(){return Ia("string")}function Ta(){return Ia("number")}var Ss=class e{_def;constructor(t={_kind:"flag"}){this._def=t}describe(t){return new e({...this._def,description:t})}alias(t){return new e({...this._def,short:t})}default(t){return new e({...this._def,default:t})}count(){return new e({...this._def,counted:!0})}};var Vo=class e{_def;constructor(t){this._def=t}describe(t){return new e({...this._def,description:t})}alias(t){return new e({...this._def,short:t})}env(t){return new e({...this._def,env:t})}required(){return new e({...this._def,required:!0})}default(t){return new e({...this._def,default:t})}repeatable(){return new e({...this._def,repeatable:!0,default:[]})}};function va(e){return new Vo({_kind:"option",type:e})}function Aa(){return va("string")}function Ha(){return va("number")}var V={string:Aa,number:Ha};function $(){return new Ss}var q={string:Sa,number:Ta};function Dd(e){switch(e.type){case"unknown_option":{let t=`Unknown option "${e.name}".`;return e.suggestions.length>0&&(t+=` Did you mean ${e.suggestions.map(n=>`"${n}"`).join(" or ")}?`),t+=`
63
63
  Not all git options are supported. Run 'git <command> --help' for available options.`,t}case"invalid_type":return`Invalid value for "${e.name}": expected ${e.expected}, got "${e.received}".`;case"missing_required":return e.kind==="option"?`Missing required option "--${e.name}".`:`Missing required argument <${e.name}>.`;case"unexpected_positional":return e.maxPositionals===0?`Unexpected argument "${e.value}". This command takes no positional arguments.`:`Unexpected argument "${e.value}". Expected at most ${e.maxPositionals} positional argument${e.maxPositionals===1?"":"s"}.`;case"missing_value":return`Option "--${e.name}" requires a value.`;case"unknown_command":{let t=`git: '${e.path.replace(/^git /,"")}' is not a git command.`;return e.suggestions.length>0&&(t+=` Did you mean ${e.suggestions.map(n=>`"${n}"`).join(" or ")}?`),t+=`
64
64
  Run 'git help' for available commands.`,t}}}function Yo(e){return e.map(Dd).join(`
65
65
  `)+`
@@ -776,7 +776,7 @@ ${u}`,exitCode:0}}oe();ae();Pr();ge();os();function Pd(e,t){e.command("tag",{des
776
776
  `)}if(n.list)return Cd(s,n.name||void 0);if(n.name){if(!Sc(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 Y(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 u=Mt(n.message),m=Pc({type:"tag",object:a,objectType:"commit",name:n.name,tagger:d,message:u}),h=await He(s,"tag",m);await Z(s,c,h)}else await Z(s,c,a);return{stdout:"",stderr:"",exitCode:0}}return Cd(s)}})}async function Cd(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 $d=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"]),Sw={init:(e,t)=>jl(e,t),clone:(e,t)=>fl(e,t),describe:(e,t)=>dl(e,t),fetch:(e,t)=>Ol(e,t),pull:(e,t)=>td(e,t),push:(e,t)=>nd(e,t),add:(e,t)=>Yc(e,t),blame:(e,t)=>Tf(e,t),commit:(e,t)=>ul(e,t),status:(e,t)=>Ed(e,t),log:(e,t)=>zl(e,t),branch:(e,t)=>Af(e,t),tag:(e,t)=>Pd(e,t),checkout:(e,t)=>Df(e,t),diff:(e,t)=>Rl(e,t),reset:(e,t)=>id(e,t),merge:(e,t)=>Yl(e,t),"cherry-pick":(e,t)=>Vf(e,t),revert:(e,t)=>ld(e,t),rebase:(e,t)=>ed(e,t),mv:(e,t)=>Xl(e,t),rm:(e,t)=>dd(e,t),remote:(e,t)=>sd(e,t),config:(e,t)=>gl(e,t),show:(e,t)=>ud(e,t),stash:(e,t)=>yd(e,t),"rev-parse":(e,t)=>fd(e,t),"ls-files":(e,t)=>Vl(e,t),clean:(e,t)=>Yf(e,t),switch:(e,t)=>Rd(e,t),restore:(e,t)=>cd(e,t),reflog:(e,t)=>rd(e,t),repack:(e,t)=>Tl(e,t),gc:(e,t)=>vl(e,t),bisect:(e,t)=>gf(e,t),grep:(e,t)=>Ml(e,t)};function Od(e){let t=Xo("git",{description:"Git command"});for(let n of Object.values(Sw))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:yr(t),stderr:"",exitCode:0};let o=t.children.get(r);return o?{stdout:yr(o),stderr:"",exitCode:0}:{stdout:"",stderr:`git: no help available for '${r}'
779
- `,exitCode:1}}}),t}var Tw="1.5.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,credentialCache:new Map,...t?.objectStore?{objectStore:t.objectStore}:{},...t?.refStore?{refStore:t.refStore}:{},...t?.gitDir?{gitDir:t.gitDir,workTree:this.defaultCwd}:{},...r?{configOverrides:r}:{}};this.inner=Od(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=Aw(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 ${Tw} (virtual git implementation)
779
+ `,exitCode:1}}}),t}var Tw="1.5.5";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,credentialCache:new Map,...t?.objectStore?{objectStore:t.objectStore}:{},...t?.refStore?{refStore:t.refStore}:{},...t?.gitDir?{gitDir:t.gitDir,workTree:this.defaultCwd}:{},...r?{configOverrides:r}:{}};this.inner=Od(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=Aw(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 ${Tw} (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&&$d.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(le(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 Aw(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 Id=new TextEncoder,Dw=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 xa=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"?Id.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 Dw.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"?Id.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,xa as MemoryFileSystem,vh as composeGitHooks,Hw as createGit,tr as findRepo,le as isRejection};
@@ -1,6 +1,11 @@
1
1
  import { g as GitRepo, Z as RefEntry, e as Commit, a3 as TreeEntry, i as ObjectId, h as Identity, a4 as TreeDiffEntry, d as GitContext, F as FileSystem } from '../hooks-CimfP56a.js';
2
2
  export { B as BuildCommitOptions, C as CommitAuthor, a as CommitIdentity, b as CommitOptions, c as CommitResult, d as CreateAnnotatedTagOptions, e as CreateCommitOptions, T as TreeEntryInput, f as TreeUpdate, g as buildCommit, h as commit, i as createAnnotatedTag, j as createCommit, u as updateTree, w as writeBlob, k as writeTree } from '../writing-IwfRRrts.js';
3
3
 
4
+ /** Extract the short branch name from a full ref path like "refs/heads/main" → "main". */
5
+ declare function branchNameFromRef(ref: string): string;
6
+ /** Extract the short tag name from a full ref path like "refs/tags/v1.0" → "v1.0". */
7
+ declare function tagNameFromRef(ref: string): string;
8
+
4
9
  /**
5
10
  * Core grep matching logic shared by the `git grep` command and the
6
11
  * repo-level `grep` helper.
@@ -16,6 +21,25 @@ declare function resolveRef(repo: GitRepo, name: string): Promise<string | null>
16
21
  declare function listBranches(repo: GitRepo): Promise<RefEntry[]>;
17
22
  /** List all tags (`refs/tags/*`). */
18
23
  declare function listTags(repo: GitRepo): Promise<RefEntry[]>;
24
+
25
+ /** Result of {@link readHead}. */
26
+ interface HeadInfo {
27
+ /** Short branch name (e.g. "main"), or null when HEAD is detached or unborn. */
28
+ branch: string | null;
29
+ /** Full ref path (e.g. "refs/heads/main"), or null when HEAD is detached or unborn. */
30
+ ref: string | null;
31
+ /** Commit hash HEAD resolves to, or null for an unborn branch. */
32
+ hash: string | null;
33
+ }
34
+ /**
35
+ * Read the current HEAD state of a repo.
36
+ *
37
+ * Returns the branch name, full ref path, and resolved commit hash.
38
+ * For detached HEAD, `branch` and `ref` are null but `hash` is set.
39
+ * For an unborn branch (empty repo), `hash` is null but `branch` and `ref` are set.
40
+ * When HEAD doesn't exist at all (bare server repos with no pushes), all fields are null.
41
+ */
42
+ declare function readHead(repo: GitRepo): Promise<HeadInfo>;
19
43
  /** Read and parse a commit object by its hash. */
20
44
  declare function readCommit(repo: GitRepo, hash: string): Promise<Commit>;
21
45
  /** Read a blob's raw bytes by its hash. */
@@ -204,8 +228,9 @@ declare function diffCommits(repo: GitRepo, base: string, head: string, options?
204
228
  /**
205
229
  * Walk the commit graph starting from one or more hashes, yielding
206
230
  * commits in reverse chronological order. Supports excluding commits
207
- * reachable from specified hashes, following only first parents, and
208
- * filtering to commits that touch specific paths.
231
+ * reachable from specified hashes, following only first parents,
232
+ * limiting the number of commits yielded, and filtering to commits
233
+ * that touch specific paths.
209
234
  *
210
235
  * When `paths` is provided, history simplification is applied: at
211
236
  * merge points, only TREESAME parents are followed (matching git's
@@ -215,6 +240,7 @@ declare function walkCommitHistory(repo: GitRepo, startHash: string | string[],
215
240
  exclude?: string[];
216
241
  firstParent?: boolean;
217
242
  paths?: string[];
243
+ limit?: number;
218
244
  }): AsyncGenerator<CommitInfo>;
219
245
 
220
246
  interface MergeConflict {
@@ -399,4 +425,4 @@ declare function readonlyRepo(repo: GitRepo): GitRepo;
399
425
  */
400
426
  declare function overlayRepo(repo: GitRepo): GitRepo;
401
427
 
402
- export { type BlameEntry, Commit, type CommitInfo, type CreateWorktreeOptions, type DiffHunk, type ExtractTreeResult, type FileDiff, type FlatTreeEntry, GitRepo, type GrepFileMatch, type GrepMatch, type GrepOptions, Identity, type MergeConflict, type MergeTreesResult, RefEntry, TreeDiffEntry, TreeEntry, type WorktreeResult, blame, countAheadBehind, createSandboxWorktree, createWorktree, diffCommits, diffTrees, extractTree, findMergeBases, flattenTree, getChangedFiles, getNewCommits, grep, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, overlayRepo, readBlob, readBlobText, readCommit, readFileAtCommit, readTree, readonlyRepo, resolveRef, walkCommitHistory };
428
+ export { type BlameEntry, Commit, type CommitInfo, type CreateWorktreeOptions, type DiffHunk, type ExtractTreeResult, type FileDiff, type FlatTreeEntry, GitRepo, type GrepFileMatch, type GrepMatch, type GrepOptions, type HeadInfo, Identity, type MergeConflict, type MergeTreesResult, RefEntry, TreeDiffEntry, TreeEntry, type WorktreeResult, blame, branchNameFromRef, countAheadBehind, createSandboxWorktree, createWorktree, diffCommits, diffTrees, extractTree, findMergeBases, flattenTree, getChangedFiles, getNewCommits, grep, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, overlayRepo, readBlob, readBlobText, readCommit, readFileAtCommit, readHead, readTree, readonlyRepo, resolveRef, tagNameFromRef, walkCommitHistory };
@@ -1,20 +1,20 @@
1
- var Ne=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ct=(()=>{let t=new Array(256);for(let e=0;e<256;e++)t[e]=(e>>4).toString(16)+(e&15).toString(16);return t})();function Te(t){let e="";for(let n=0;n<20;n++)e+=Ct[t[n]];return e}function Qe(t,e){let n="";for(let r=0;r<20;r++)n+=Ct[t[e+r]];return n}function ye(t){let e=new Uint8Array(20);for(let n=0;n<20;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}var Qn=new TextEncoder;function et(t){return typeof t=="string"?Qn.encode(t):t}function er(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(et(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=Ne(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(et(r)),n},hex:()=>Promise.resolve(e.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let t=[],e={update(n){return t.push(et(n)),e},async hex(){let n=0;for(let o of t)n+=o.byteLength;let r=new Uint8Array(n),s=0;for(let o of t)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return Te(new Uint8Array(i))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var jt=er(),tt=jt;async function Be(t){return jt().update(t).hex()}var Z=Uint8Array,be=Uint16Array,tr=Int32Array,vt=new Z([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),At=new Z([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),nr=new Z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),$t=(t,e)=>{let n=new be(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new tr(n[30]);for(let s=1;s<30;++s)for(let i=n[s];i<n[s+1];++i)r[i]=i-n[s]<<5|s;return{b:n,r}},{b:Lt}=$t(vt,2);Lt[28]=258;var{b:rr}=$t(At,0),st=new be(32768);for(let t=0;t<32768;++t){let e=(t&43690)>>1|(t&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,st[t]=((e&65280)>>8|(e&255)<<8)>>1}var Se=(t,e,n)=>{let r=t.length,s=0,i=new be(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let o=new be(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;let a;if(n){a=new be(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let l=s<<4|t[s],f=e-t[s],u=o[t[s]-1]++<<f;for(let d=u|(1<<f)-1;u<=d;++u)a[st[u]>>c]=l}}else for(a=new be(r),s=0;s<r;++s)t[s]&&(a[s]=st[o[t[s]-1]++]>>15-t[s]);return a},Ce=new Z(288);for(let t=0;t<144;++t)Ce[t]=8;for(let t=144;t<256;++t)Ce[t]=9;for(let t=256;t<280;++t)Ce[t]=7;for(let t=280;t<288;++t)Ce[t]=8;var Mt=new Z(32);for(let t=0;t<32;++t)Mt[t]=5;var sr=Se(Ce,9,1),ir=Se(Mt,5,1),nt=t=>{let e=t[0];for(let n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},X=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},rt=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},Dt=t=>(t+7)/8|0,or=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new Z(t.subarray(e,n))),ee=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},Ht=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new Z(0);let o=!n,a=o||e.i!=2,c=e.i;o&&(n=new Z(s*3));let l=R=>{let j=n.length;if(R>j){let A=new Z(Math.max(j*2,R));A.set(n),n=A}},f=e.f||0,u=e.p||0,d=e.b||0,h=e.l,m=e.d,g=e.m,p=e.n,b=s*8;do{if(!h){f=X(t,u,1);let O=X(t,u+1,3);if(u+=3,O)if(O==1)h=sr,m=ir,g=9,p=5;else if(O==2){let w=X(t,u,31)+257,x=X(t,u+10,15)+4,S=w+X(t,u+5,31)+1;u+=14;let E=new Z(S),P=new Z(19);for(let y=0;y<x;++y)P[nr[y]]=X(t,u+y*3,7);u+=x*3;let T=nt(P),$=(1<<T)-1,D=Se(P,T,1);for(let y=0;y<S;){let k=D[X(t,u,$)];u+=k&15;let M=k>>4;if(M<16)E[y++]=M;else{let L=0,C=0;for(M==16?(C=3+X(t,u,3),u+=2,L=E[y-1]):M==17?(C=3+X(t,u,7),u+=3):M==18&&(C=11+X(t,u,127),u+=7);C--;)E[y++]=L}}let ae=E.subarray(0,w),I=E.subarray(w);g=nt(ae),p=nt(I),h=Se(ae,g,1),m=Se(I,p,1)}else ee(1);else{let w=Dt(u)+4,x=t[w-4]|t[w-3]<<8,S=w+x;if(S>s){c&&ee(0);break}a&&l(d+x),n.set(t.subarray(w,S),d),e.b=d+=x,e.p=u=S*8,e.f=f;continue}if(u>b){c&&ee(0);break}}a&&l(d+131072);let R=(1<<g)-1,j=(1<<p)-1,A=u;for(;;A=u){let O=h[rt(t,u)&R],w=O>>4;if(u+=O&15,u>b){c&&ee(0);break}if(O||ee(2),w<256)n[d++]=w;else if(w==256){A=u,h=null;break}else{let x=w-254;if(w>264){let $=w-257,D=vt[$];x=X(t,u,(1<<D)-1)+Lt[$],u+=D}let S=m[rt(t,u)&j],E=S>>4;S||ee(3),u+=S&15;let P=rr[E];if(E>3){let $=At[E];P+=rt(t,u)&(1<<$)-1,u+=$}if(u>b){c&&ee(0);break}a&&l(d+131072);let T=d+x;if(d<P){let $=i-P,D=Math.min(P,T);for($+d<0&&ee(3);d<D;++d)n[d]=r[$+d]}for(;d<T;++d)n[d]=n[d-P]}}e.l=h,e.p=A,e.b=d,e.f=f,h&&(f=1,e.m=g,e.d=m,e.n=p)}while(!f);return d!=n.length&&o?or(n,0,d):n.subarray(0,d)},Ut=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&ee(0,"invalid zlib data"),t[1]&32&&ee(0,"zlib dictionaries are not supported"),2);function Nt(t){let e=Ut(t);return Ht(t.subarray(e,-4),{i:2})}function it(t){let e=Ut(t),n={i:2},r=Ht(t.subarray(e),n),s=Dt(n.p);return{result:r,bytesConsumed:e+s+4}}async function ar(){let t;if(!(typeof document<"u"))try{t=Ne(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let o=t.inflateSync(i,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??it}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let s=new CompressionStream("deflate"),i=s.writable.getWriter();return i.write(r),i.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:Nt,inflateWithConsumed:it}}var cr=null;function lr(){return cr??=ar()}async function Bt(t,e){let n=await lr(),{result:r,bytesConsumed:s}=n.inflateWithConsumed(t);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);return{result:r,bytesConsumed:s}}var Gt=1346454347,fr=2,ur=1,hr=2,dr=3,mr=4,Ge=6,at=7,pr={[ur]:"commit",[hr]:"tree",[dr]:"blob",[mr]:"tag"};async function zt(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==Gt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Gt.toString(16)})`);let s=n.getUint32(4);if(s!==fr)throw new Error(`Unsupported pack version: ${s}`);if(t.byteLength>=32){let l=Qe(t,t.byteLength-20),f=tt();f.update(t.subarray(0,t.byteLength-20));let u=await f.hex();if(u!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${u}`)}let i=n.getUint32(8),o=[],a=12;for(let l=0;l<i;l++){let f=await gr(t,a);o.push(f),a=f.nextOffset}return(await yr(o,e)).map((l,f)=>({...l,offset:o[f].headerOffset,nextOffset:o[f].nextOffset}))}async function gr(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=t[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Ge){let u=t[e++];for(a=u&127;u&128;)a+=1,u=t[e++],a=(a<<7)+(u&127);a=n-a}else s===at&&(c=Qe(t,e),e+=20);let{result:l,bytesConsumed:f}=await Bt(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:l,baseOffset:a,baseHash:c,nextOffset:e+f}}var Ft=50;async function yr(t,e){let n=new Map;for(let i=0;i<t.length;i++)n.set(t[i].headerOffset,i);let r=new Array(t.length).fill(null);async function s(i,o=0){if(o>Ft)throw new Error(`delta chain depth ${o} exceeds limit of ${Ft}`);let a=r[i];if(a)return a;let c=t[i];if(c.typeNum!==Ge&&c.typeNum!==at){let h=pr[c.typeNum];if(!h)throw new Error(`Unknown object type: ${c.typeNum}`);let m={type:h,content:c.inflated,hash:await ot(h,c.inflated)};return r[i]=m,m}if(c.typeNum===Ge){let h=n.get(c.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let m=await s(h,o+1),g=_t(m.content,c.inflated),p={type:m.type,content:g,hash:await ot(m.type,g)};return r[i]=p,p}let l=await br(t,r,c.baseHash,s),f;if(l!==void 0)f=await s(l,o+1);else if(e){let h=await e(c.baseHash);h&&(f=h)}if(!f)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let u=_t(f.content,c.inflated),d={type:f.type,content:u,hash:await ot(f.type,u)};return r[i]=d,d}for(let i=0;i<t.length;i++)await s(i);return r}async function br(t,e,n,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===n)return s;for(let s=0;s<t.length;s++){let i=t[s];if(i.typeNum!==Ge&&i.typeNum!==at&&(await r(s)).hash===n)return s}}function _t(t,e){let n=0,{value:r,newPos:s}=Wt(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:o}=Wt(e,n);n=o;let a=new Uint8Array(i),c=0;for(;n<e.byteLength;){let l=e[n++];if(l&128){let f=0,u=0;l&1&&(f=e[n++]),l&2&&(f|=e[n++]<<8),l&4&&(f|=e[n++]<<16),l&8&&(f|=e[n++]<<24),l&16&&(u=e[n++]),l&32&&(u|=e[n++]<<8),l&64&&(u|=e[n++]<<16),u===0&&(u=65536),a.set(t.subarray(f,f+u),c),c+=u}else if(l>0)a.set(e.subarray(n,n+l),c),c+=l,n+=l;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return a}function Wt(t,e){let n=0,r=0,s;do s=t[e++],n|=(s&127)<<r,r+=7;while(s&128);return{value:n,newPos:e}}var wr=new TextEncoder;async function ot(t,e){let n=wr.encode(`${t} ${e.byteLength}\0`),r=tt();return r.update(n),r.update(e),r.hex()}function Ir(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.split("/"),s=[];for(let o of r)o===""||o==="."||(o===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(o));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function we(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":Ir(e)}function Vt(t){if(t==="")return".";if(t==="/")return"/";let e=t.length;for(;e>1&&t.charCodeAt(e-1)===47;)e--;let n=t.slice(0,e),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}var Er=new TextEncoder,Li=new TextDecoder;function Kt(t,e){let n=Er.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function je(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function ve(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var xr=new TextEncoder,Or=new TextDecoder;function Yt(t){let e=Or.decode(t),n=e.indexOf(`
1
+ var Ne=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var jt=(()=>{let t=new Array(256);for(let e=0;e<256;e++)t[e]=(e>>4).toString(16)+(e&15).toString(16);return t})();function Te(t){let e="";for(let n=0;n<20;n++)e+=jt[t[n]];return e}function Qe(t,e){let n="";for(let r=0;r<20;r++)n+=jt[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 tr=new TextEncoder;function et(t){return typeof t=="string"?tr.encode(t):t}function nr(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(et(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=Ne(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(et(r)),n},hex:()=>Promise.resolve(e.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let t=[],e={update(n){return t.push(et(n)),e},async hex(){let n=0;for(let o of t)n+=o.byteLength;let r=new Uint8Array(n),s=0;for(let o of t)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return Te(new Uint8Array(i))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var vt=nr(),tt=vt;async function Be(t){return vt().update(t).hex()}var Z=Uint8Array,be=Uint16Array,rr=Int32Array,At=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]),$t=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]),sr=new Z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Lt=(t,e)=>{let n=new be(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new rr(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:Mt}=Lt(At,2);Mt[28]=258;var{b:ir}=Lt($t,0),st=new be(32768);for(let t=0;t<32768;++t){let e=(t&43690)>>1|(t&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,st[t]=((e&65280)>>8|(e&255)<<8)>>1}var Se=(t,e,n)=>{let r=t.length,s=0,i=new be(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let o=new be(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;let a;if(n){a=new be(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let l=s<<4|t[s],f=e-t[s],u=o[t[s]-1]++<<f;for(let d=u|(1<<f)-1;u<=d;++u)a[st[u]>>c]=l}}else for(a=new be(r),s=0;s<r;++s)t[s]&&(a[s]=st[o[t[s]-1]++]>>15-t[s]);return a},Ce=new Z(288);for(let t=0;t<144;++t)Ce[t]=8;for(let t=144;t<256;++t)Ce[t]=9;for(let t=256;t<280;++t)Ce[t]=7;for(let t=280;t<288;++t)Ce[t]=8;var Dt=new Z(32);for(let t=0;t<32;++t)Dt[t]=5;var or=Se(Ce,9,1),ar=Se(Dt,5,1),nt=t=>{let e=t[0];for(let n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},X=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},rt=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},Ht=t=>(t+7)/8|0,cr=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new Z(t.subarray(e,n))),ee=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},Ut=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new Z(0);let o=!n,a=o||e.i!=2,c=e.i;o&&(n=new Z(s*3));let l=R=>{let j=n.length;if(R>j){let A=new Z(Math.max(j*2,R));A.set(n),n=A}},f=e.f||0,u=e.p||0,d=e.b||0,h=e.l,m=e.d,g=e.m,p=e.n,b=s*8;do{if(!h){f=X(t,u,1);let O=X(t,u+1,3);if(u+=3,O)if(O==1)h=or,m=ar,g=9,p=5;else if(O==2){let w=X(t,u,31)+257,x=X(t,u+10,15)+4,S=w+X(t,u+5,31)+1;u+=14;let E=new Z(S),P=new Z(19);for(let y=0;y<x;++y)P[sr[y]]=X(t,u+y*3,7);u+=x*3;let T=nt(P),$=(1<<T)-1,D=Se(P,T,1);for(let y=0;y<S;){let k=D[X(t,u,$)];u+=k&15;let M=k>>4;if(M<16)E[y++]=M;else{let L=0,C=0;for(M==16?(C=3+X(t,u,3),u+=2,L=E[y-1]):M==17?(C=3+X(t,u,7),u+=3):M==18&&(C=11+X(t,u,127),u+=7);C--;)E[y++]=L}}let ae=E.subarray(0,w),I=E.subarray(w);g=nt(ae),p=nt(I),h=Se(ae,g,1),m=Se(I,p,1)}else ee(1);else{let w=Ht(u)+4,x=t[w-4]|t[w-3]<<8,S=w+x;if(S>s){c&&ee(0);break}a&&l(d+x),n.set(t.subarray(w,S),d),e.b=d+=x,e.p=u=S*8,e.f=f;continue}if(u>b){c&&ee(0);break}}a&&l(d+131072);let R=(1<<g)-1,j=(1<<p)-1,A=u;for(;;A=u){let O=h[rt(t,u)&R],w=O>>4;if(u+=O&15,u>b){c&&ee(0);break}if(O||ee(2),w<256)n[d++]=w;else if(w==256){A=u,h=null;break}else{let x=w-254;if(w>264){let $=w-257,D=At[$];x=X(t,u,(1<<D)-1)+Mt[$],u+=D}let S=m[rt(t,u)&j],E=S>>4;S||ee(3),u+=S&15;let P=ir[E];if(E>3){let $=$t[E];P+=rt(t,u)&(1<<$)-1,u+=$}if(u>b){c&&ee(0);break}a&&l(d+131072);let T=d+x;if(d<P){let $=i-P,D=Math.min(P,T);for($+d<0&&ee(3);d<D;++d)n[d]=r[$+d]}for(;d<T;++d)n[d]=n[d-P]}}e.l=h,e.p=A,e.b=d,e.f=f,h&&(f=1,e.m=g,e.d=m,e.n=p)}while(!f);return d!=n.length&&o?cr(n,0,d):n.subarray(0,d)},Nt=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&ee(0,"invalid zlib data"),t[1]&32&&ee(0,"zlib dictionaries are not supported"),2);function Bt(t){let e=Nt(t);return Ut(t.subarray(e,-4),{i:2})}function it(t){let e=Nt(t),n={i:2},r=Ut(t.subarray(e),n),s=Ht(n.p);return{result:r,bytesConsumed:e+s+4}}async function lr(){let t;if(!(typeof document<"u"))try{t=Ne(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let o=t.inflateSync(i,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??it}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let s=new CompressionStream("deflate"),i=s.writable.getWriter();return i.write(r),i.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:Bt,inflateWithConsumed:it}}var fr=null;function ur(){return fr??=lr()}async function Gt(t,e){let n=await ur(),{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 Ft=1346454347,hr=2,dr=1,mr=2,pr=3,gr=4,Ge=6,at=7,yr={[dr]:"commit",[mr]:"tree",[pr]:"blob",[gr]:"tag"};async function Vt(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==Ft)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Ft.toString(16)})`);let s=n.getUint32(4);if(s!==hr)throw new Error(`Unsupported pack version: ${s}`);if(t.byteLength>=32){let l=Qe(t,t.byteLength-20),f=tt();f.update(t.subarray(0,t.byteLength-20));let u=await f.hex();if(u!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${u}`)}let i=n.getUint32(8),o=[],a=12;for(let l=0;l<i;l++){let f=await br(t,a);o.push(f),a=f.nextOffset}return(await wr(o,e)).map((l,f)=>({...l,offset:o[f].headerOffset,nextOffset:o[f].nextOffset}))}async function br(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=t[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Ge){let u=t[e++];for(a=u&127;u&128;)a+=1,u=t[e++],a=(a<<7)+(u&127);a=n-a}else s===at&&(c=Qe(t,e),e+=20);let{result:l,bytesConsumed:f}=await Gt(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:l,baseOffset:a,baseHash:c,nextOffset:e+f}}var _t=50;async function wr(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>_t)throw new Error(`delta chain depth ${o} exceeds limit of ${_t}`);let a=r[i];if(a)return a;let c=t[i];if(c.typeNum!==Ge&&c.typeNum!==at){let h=yr[c.typeNum];if(!h)throw new Error(`Unknown object type: ${c.typeNum}`);let m={type:h,content:c.inflated,hash:await ot(h,c.inflated)};return r[i]=m,m}if(c.typeNum===Ge){let h=n.get(c.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let m=await s(h,o+1),g=Wt(m.content,c.inflated),p={type:m.type,content:g,hash:await ot(m.type,g)};return r[i]=p,p}let l=await Ir(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=Wt(f.content,c.inflated),d={type:f.type,content:u,hash:await ot(f.type,u)};return r[i]=d,d}for(let i=0;i<t.length;i++)await s(i);return r}async function Ir(t,e,n,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===n)return s;for(let s=0;s<t.length;s++){let i=t[s];if(i.typeNum!==Ge&&i.typeNum!==at&&(await r(s)).hash===n)return s}}function Wt(t,e){let n=0,{value:r,newPos:s}=zt(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:o}=zt(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 zt(t,e){let n=0,r=0,s;do s=t[e++],n|=(s&127)<<r,r+=7;while(s&128);return{value:n,newPos:e}}var Er=new TextEncoder;async function ot(t,e){let n=Er.encode(`${t} ${e.byteLength}\0`),r=tt();return r.update(n),r.update(e),r.hex()}function xr(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.split("/"),s=[];for(let o of r)o===""||o==="."||(o===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(o));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function we(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":xr(e)}function Kt(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 Or=new TextEncoder,Hi=new TextDecoder;function Yt(t,e){let n=Or.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function je(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function ve(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var Rr=new TextEncoder,Pr=new TextDecoder;function qt(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
- `)){let f=l.indexOf(" ");if(f===-1)continue;let u=l.slice(0,f),d=l.slice(f+1);switch(u){case"tree":i=d;break;case"parent":o.push(d);break;case"author":a=je(d);break;case"committer":c=je(d);break}}if(!i)throw new Error("Commit missing tree field");if(!a)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:o,author:a,committer:c,message:s}}function Ae(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${ve(t.author)}`),e.push(`committer ${ve(t.committer)}`),e.push(""),e.push(t.message),xr.encode(e.join(`
5
- `))}var Rr=new TextEncoder,Pr=new TextDecoder;function qt(t){let e=Pr.decode(t),n=e.indexOf(`
4
+ `)){let f=l.indexOf(" ");if(f===-1)continue;let u=l.slice(0,f),d=l.slice(f+1);switch(u){case"tree":i=d;break;case"parent":o.push(d);break;case"author":a=je(d);break;case"committer":c=je(d);break}}if(!i)throw new Error("Commit missing tree field");if(!a)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:o,author:a,committer:c,message:s}}function Ae(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${ve(t.author)}`),e.push(`committer ${ve(t.committer)}`),e.push(""),e.push(t.message),Rr.encode(e.join(`
5
+ `))}var kr=new TextEncoder,Tr=new TextDecoder;function Xt(t){let e=Tr.decode(t),n=e.indexOf(`
6
6
 
7
7
  `),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",o="commit",a="",c;for(let l of r.split(`
8
- `)){let f=l.indexOf(" ");if(f===-1)continue;let u=l.slice(0,f),d=l.slice(f+1);switch(u){case"object":i=d;break;case"type":o=d;break;case"tag":a=d;break;case"tagger":c=je(d);break}}if(!i)throw new Error("Tag missing object field");if(!a)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:i,objectType:o,name:a,tagger:c,message:s}}function Xt(t){let e=[];return e.push(`object ${t.object}`),e.push(`type ${t.objectType}`),e.push(`tag ${t.name}`),e.push(`tagger ${ve(t.tagger)}`),e.push(""),e.push(t.message),Rr.encode(e.join(`
9
- `))}async function B(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function F(t,e){return t.objectStore.read(e)}async function Zt(t,e){return t.objectStore.exists(e)}async function Jt(t,e){return t.objectStore.findByPrefix(e)}function ne(t){let e=Math.min(t.length,8e3);for(let n=0;n<e;n++)if(t.charCodeAt(n)===0)return!0;return!1}var kr=new TextDecoder;async function H(t,e){let n=await F(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return kr.decode(n.content)}async function re(t,e){let n=await F(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function v(t,e){let n=await F(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return Yt(n.content)}async function $e(t,e){let n=e;for(let r=0;r<100;r++){let s=await F(t,n);if(s.type==="commit")return n;if(s.type==="tag"){n=qt(s.content).object;continue}throw new Error(`Cannot peel ${s.type} object ${e} to commit`)}throw new Error(`Tag chain too deep for ${e}`)}var Tr=new TextEncoder,Qt=new TextDecoder,Sr=new Set(["100644","100755","040000","120000","160000"]);function Cr(t){return t.length===4&&t.toLowerCase()===".git"}function jr(t,e){if(t.length===0)throw new Error("invalid tree entry: empty name");if(t.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${t}'`);if(t.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(t==="."||t==="..")throw new Error(`invalid tree entry: '${t}'`);if(Cr(t))throw new Error(`invalid tree entry: '${t}'`);if(!Sr.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${t}'`)}function se(t){let e=[],n=0;for(;n<t.byteLength;){let r=t.indexOf(32,n);if(r===-1)break;let s=Qt.decode(t.subarray(n,r)),i=t.indexOf(0,r+1);if(i===-1)break;let o=Qt.decode(t.subarray(r+1,i)),a=t.subarray(i+1,i+21),c=Te(a),l=s.padStart(6,"0");jr(o,l),e.push({mode:l,name:o,hash:c}),n=i+21}return{type:"tree",entries:e}}function Le(t){let e=[];for(let i of t.entries){let o=i.mode.replace(/^0+/,""),a=Tr.encode(`${o} ${i.name}\0`),c=ye(i.hash);e.push(a),e.push(c)}let n=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}var _={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function en(t){return typeof t=="string"?{type:"direct",hash:t}:t}var vr=10;async function Ar(t,e){return t.refStore.readRef(e)}async function J(t,e){let n=e;for(let r=0;r<vr;r++){let s=await Ar(t,n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function ct(t,e="refs"){return t.refStore.listRefs(e)}function tn(t){return t.length===4&&t.toLowerCase()===".git"}function nn(t){if(t.length===0||t.includes("\0")||t.charCodeAt(0)===47||t.charCodeAt(t.length-1)===47)return!1;let e=t.split("/");for(let n of e)if(n.length===0||n==="."||n===".."||tn(n))return!1;return!0}function rn(t,e){return e===t?!1:t==="/"?e.startsWith("/")&&e.length>1:e.startsWith(t+"/")}function sn(t){if(t.length===0||t.charCodeAt(0)===47)return!1;let e=t.split("/");for(let n of e)if(n===".."||tn(n))return!1;return!0}var $r=1145655875,Lr=2;async function Fe(t,e){let n=we(t.gitDir,"index"),r=await Mr(e);await t.fs.writeFile(n,r)}function on(t){let e=[...t].sort(an);return{version:Lr,entries:e}}function ce(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function Mr(t){let e=new TextEncoder,n=[...t.entries].sort(an),r=[],s=12;for(let d of n){let h=e.encode(d.path);r.push(h);let m=62+h.byteLength+1;s+=Math.ceil(m/8)*8}s+=20;let i=new ArrayBuffer(s),o=new Uint8Array(i),a=new DataView(i),c=0;a.setUint32(c,$r),c+=4,a.setUint32(c,t.version),c+=4,a.setUint32(c,n.length),c+=4;for(let d=0;d<n.length;d++){let h=n[d],m=r[d],g=c;a.setUint32(c,h.stat.ctimeSeconds),a.setUint32(c+4,h.stat.ctimeNanoseconds),a.setUint32(c+8,h.stat.mtimeSeconds),a.setUint32(c+12,h.stat.mtimeNanoseconds),a.setUint32(c+16,h.stat.dev),a.setUint32(c+20,h.stat.ino),a.setUint32(c+24,h.mode),a.setUint32(c+28,h.stat.uid),a.setUint32(c+32,h.stat.gid),a.setUint32(c+36,h.stat.size),c+=40;let p=ye(h.hash);o.set(p,c),c+=20;let b=Math.min(m.byteLength,4095),R=(h.stage&3)<<12|b;a.setUint16(c,R),c+=2,o.set(m,c),c+=m.byteLength,o[c]=0,c+=1;let j=62+m.byteLength+1,A=Math.ceil(j/8)*8;c=g+A}let l=o.subarray(0,c),f=await Be(l),u=ye(f);return o.set(u,c),o}function an(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}function Dr(t){let e=[],n=t.length;for(;n>0;){let i=t.slice(0,n).match(/^(.+?)~(\d*)$/);if(i&&i[1]!==void 0&&i[2]!==void 0){let c=i[2]===""?1:parseInt(i[2],10);e.unshift({type:"tilde",n:c}),n=i[1].length;continue}let o=t.slice(0,n).match(/^(.+?)\^{([^}]*)}$/);if(o&&o[1]!==void 0&&o[2]!==void 0){e.unshift({type:"peel",target:o[2]}),n=o[1].length;continue}let a=t.slice(0,n).match(/^(.+?)\^(\d*)$/);if(a&&a[1]!==void 0&&a[2]!==void 0){let c=a[2]===""?1:parseInt(a[2],10);e.unshift({type:"caret",n:c}),n=a[1].length;continue}break}let r=t.slice(0,n),s=r.match(/^(.+?)@\{(\d+)\}$/);return s&&s[1]!==void 0&&s[2]!==void 0?{base:s[1],reflogIndex:parseInt(s[2],10),suffixes:e}:{base:r,suffixes:e}}var Hr=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];async function Ur(t,e){let n=await Jt(t,e);if(n.length===0)return null;if(n.length>1)throw new lt(e);return n[0]}var lt=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}};async function Nr(t,e){if(e==="HEAD"||e==="@")return J(t,"HEAD");if(Hr.includes(e))return J(t,e);if(/^[0-9a-f]{40}$/.test(e))return await Zt(t,e)?e:null;if(/^[0-9a-f]{4,39}$/.test(e)){let i=await Ur(t,e);if(i)return i}if(e.startsWith("refs/")){let i=await J(t,e);if(i)return i}let n=await J(t,`refs/heads/${e}`);if(n)return n;let r=await J(t,`refs/tags/${e}`);if(r)return r;let s=await J(t,`refs/remotes/${e}`);return s||null}async function Br(t,e,n){if(n===""||n==="commit")try{return await $e(t,e)}catch{return null}if(n==="tree"){let s;try{s=await $e(t,e)}catch{return null}return(await v(t,s)).tree}return(await F(t,e)).type!==n?null:e}async function Gr(t,e,n){let r=e;n.some(i=>i.type==="tilde"||i.type==="caret")&&(r=await $e(t,r));for(let i of n)if(i.type==="peel"){if(!r)return null;r=await Br(t,r,i.target)}else if(i.type==="tilde")for(let o=0;o<i.n;o++){if(!r)return null;let a=await v(t,r);if(a.parents.length===0||(r=a.parents[0]??null,!r))return null}else{if(i.n===0)continue;if(!r)return null;let o=await v(t,r);if(i.n>o.parents.length||(r=o.parents[i.n-1]??null,!r))return null}return r}async function _e(t,e){let{base:n,reflogIndex:r,suffixes:s}=Dr(e);if(r!==void 0)return null;let i=await Nr(t,n);return i?Gr(t,i,s):null}var no=new TextEncoder;function ie(t){return typeof t=="string"?t==="120000":t===40960}function cn(t){return{stdout:"",stderr:`fatal: ${t}
10
- `,exitCode:128}}var so=cn("not a git repository (or any of the parent directories): .git"),io=cn("this operation must be run in a work tree");function Me(t,e){return t<e?-1:t>e?1:0}async function ft(t,e){return ln(t,e,"")}async function ln(t,e,n){let r=[],s=new Map;for(let o of e){let a=n?o.path.slice(n.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:Fr(o.mode),name:a,hash:o.hash});else{let l=a.slice(0,c),f=s.get(l);f||(f=[],s.set(l,f)),f.push(o)}}for(let[o,a]of s){let c=n?`${n}/${o}`:o,l=await ln(t,a,c);r.push({mode:_.DIRECTORY,name:o,hash:l})}r.sort((o,a)=>{let c=o.mode===_.DIRECTORY?`${o.name}/`:o.name,l=a.mode===_.DIRECTORY?`${a.name}/`:a.name;return c<l?-1:c>l?1:0});let i=Le({type:"tree",entries:r});return B(t,"tree",i)}async function Q(t,e,n=""){let r=await F(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=se(r.content),i=[];for(let o of s.entries){let a=n?`${n}/${o.name}`:o.name;if(o.mode===_.DIRECTORY){let c=await Q(t,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function le(t,e){if(!e)return new Map;let n=await Q(t,e);return new Map(n.map(r=>[r.path,r]))}async function oe(t,e,n){let r=await le(t,e),s=await le(t,n),i=[];for(let[o,a]of r){let c=s.get(o);c?(a.hash!==c.hash||a.mode!==c.mode)&&i.push({path:o,status:"modified",oldHash:a.hash,newHash:c.hash,oldMode:a.mode,newMode:c.mode}):i.push({path:o,status:"deleted",oldHash:a.hash,oldMode:a.mode})}for(let[o,a]of s)r.has(o)||i.push({path:o,status:"added",newHash:a.hash,newMode:a.mode});return i.sort((o,a)=>Me(o.path,a.path))}function Fr(t){return t.toString(8).padStart(6,"0")}function _r(t){let e=Math.min(t.length,8e3),n=0;for(let r=0;r<e;r++)t.charCodeAt(r)===0&&n++;return n>e*.01}function fn(t,e,n,r){if(_r(t)){let o=e.some(a=>a.test(t));return{matches:[],binary:o}}let s=t.split(`
11
- `);if(s.length>0&&s[s.length-1]===""&&s.pop(),n&&e.length>1&&!e.every(a=>s.some(c=>a.test(c))))return{matches:[],binary:!1};let i=[];for(let o=0;o<s.length;o++){let a=s[o],c=e.some(l=>l.test(a));(r?!c:c)&&i.push({lineNo:o+1,line:a})}return{matches:i,binary:!1}}function Wr(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function un(t,e){let n=e?.fixed?Wr(t):t;e?.wordRegexp&&(n=`\\b${n}\\b`);let r=e?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}async function zr(t,e){return J(t,e)}async function Vr(t){return ct(t,"refs/heads")}async function Kr(t){return ct(t,"refs/tags")}async function Yr(t,e){return v(t,e)}async function qr(t,e){return re(t,e)}async function Xr(t,e){return H(t,e)}async function Zr(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return se(n.content).entries}async function Jr(t,e,n){let r=await v(t,e),i=(await Q(t,r.tree)).find(o=>o.path===n);return i?H(t,i.hash):null}function Qr(t){let e=0;for(let n=0;n<t.length;n++)t[n]==="/"&&e++;return e}function es(t,e){let n=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"\0").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]").replace(/\0/g,".*");return new RegExp(`^${n}$`).test(e)}async function ts(t,e,n,r){let s=[];for(let m of n)if(m instanceof RegExp)s.push(m);else{let g=un(m,{fixed:r?.fixed,ignoreCase:r?.ignoreCase,wordRegexp:r?.wordRegexp});if(!g)throw new Error(`Invalid pattern: ${m}`);s.push(g)}let i=await v(t,e),a=(await Q(t,i.tree)).filter(m=>!m.mode.startsWith("120")).sort((m,g)=>m.path<g.path?-1:m.path>g.path?1:0),c=r?.allMatch??!1,l=r?.invert??!1,f=r?.maxCount,u=r?.maxDepth,d=r?.paths,h=[];for(let m of a){if(u!==void 0&&Qr(m.path)>u||d&&!d.some(R=>es(R,m.path)))continue;let g=await H(t,m.hash),p=fn(g,s,c,l);if(p.binary){h.push({path:m.path,matches:[],binary:!0});continue}if(p.matches.length===0)continue;let b=f!==void 0?p.matches.slice(0,f):p.matches;h.push({path:m.path,matches:b,binary:!1})}return h}function te(t){if(t.length===0)return[];let e=t.split(`
12
- `);return e[e.length-1]===""&&e.pop(),e}var ns=4,hn=1024,We=100,Ke=0,ze=1,Ie=2;function ht(t){let e=1;for(;e*e<t;)e++;return e}function rs(t,e){let n=new Map,r=[],s=new Array(t.length),i=new Array(e.length);for(let o=0;o<t.length;o++){let a=t[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len1++,s[o]=c}for(let o=0;o<e.length;o++){let a=e[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function ss(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&t[e-1-a]===n[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function dn(t,e,n,r){e-n>We&&(n=e-We),r-e>We&&(r=e+We);let s=0,i=1;for(let c=1;e-c>=n;c++){let l=t[e-c];if(l===Ke)s++;else if(l===Ie)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let l=t[e+c];if(l===Ke)o++;else if(l===Ie)a++;else break}return o===0?!1:(o+=s,a+=i,a*ns<a+o)}function is(t,e,n,r,s,i,o,a,c,l){let f=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(ht(e),hn);for(let p=i;p<=o;p++){let b=s[t[p]].len2;b===0?f[p]=Ke:b>=d?f[p]=Ie:f[p]=ze}let h=Math.min(ht(r),hn);for(let p=i;p<=a;p++){let b=s[n[p]].len1;b===0?u[p]=Ke:b>=h?u[p]=Ie:u[p]=ze}let m=[];for(let p=i;p<=o;p++)f[p]===ze||f[p]===Ie&&!dn(f,p,i,o)?m.push(p):c[p]=1;let g=[];for(let p=i;p<=a;p++)u[p]===ze||u[p]===Ie&&!dn(u,p,i,a)?g.push(p):l[p]=1;return{refIndex1:m,nreff1:m.length,refIndex2:g,nreff2:g.length}}var fe=20,mn=4,os=256,as=256,Ve=2147483647;function z(t,e){return t[e]??0}function cs(t,e,n,r,s,i,o,a,c,l){let f=e-i,u=n-s,d=e-s,h=n-i,m=d-h&1,g=d,p=d,b=h,R=h;o[d]=e,a[h]=n;for(let j=1;;j++){let A=!1;g>f?o[--g-1]=-1:++g,p<u?o[++p+1]=-1:--p;for(let O=p;O>=g;O-=2){let w;z(o,O-1)>=z(o,O+1)?w=z(o,O-1)+1:w=z(o,O+1);let x=w,S=w-O;for(;w<n&&S<i&&t[w]===r[S];)w++,S++;if(w-x>fe&&(A=!0),o[O]=w,m&&b<=O&&O<=R&&z(a,O)<=w)return{i1:w,i2:S,minLo:!0,minHi:!0}}b>f?a[--b-1]=Ve:++b,R<u?a[++R+1]=Ve:--R;for(let O=R;O>=b;O-=2){let w;z(a,O-1)<z(a,O+1)?w=z(a,O-1):w=z(a,O+1)-1;let x=w,S=w-O;for(;w>e&&S>s&&t[w-1]===r[S-1];)w--,S--;if(x-w>fe&&(A=!0),a[O]=w,!m&&g<=O&&O<=p&&w<=z(o,O))return{i1:w,i2:S,minLo:!0,minHi:!0}}if(!c){if(A&&j>os){let O=0,w=null;for(let x=p;x>=g;x-=2){let S=x>d?x-d:d-x,E=z(o,x),P=E-x,T=E-e+(P-s)-S;if(T>mn*j&&T>O&&e+fe<=E&&E<n&&s+fe<=P&&P<i){let $=!0;for(let D=1;D<=fe;D++)if(t[E-D]!==r[P-D]){$=!1;break}$&&(O=T,w={i1:E,i2:P,minLo:!0,minHi:!1})}}if(w)return w;O=0,w=null;for(let x=R;x>=b;x-=2){let S=x>h?x-h:h-x,E=z(a,x),P=E-x,T=n-E+(i-P)-S;if(T>mn*j&&T>O&&e<E&&E<=n-fe&&s<P&&P<=i-fe){let $=!0;for(let D=0;D<fe;D++)if(t[E+D]!==r[P+D]){$=!1;break}$&&(O=T,w={i1:E,i2:P,minLo:!1,minHi:!0})}}if(w)return w}if(j>=l){let O=-1,w=-1;for(let E=p;E>=g;E-=2){let P=Math.min(z(o,E),n),T=P-E;i<T&&(P=i+E,T=i),O<P+T&&(O=P+T,w=P)}let x=Ve,S=Ve;for(let E=R;E>=b;E-=2){let P=Math.max(e,z(a,E)),T=P-E;T<s&&(P=s+E,T=s),P+T<x&&(x=P+T,S=P)}return n+i-x<O-(e+s)?{i1:w,i2:O-w,minLo:!0,minHi:!1}:{i1:S,i2:x-S,minLo:!1,minHi:!0}}}}}function dt(t,e,n,r,s,i,o,a,c,l,f,u,d,h){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let m=s;m<i;m++)a[l[m]]=1;else if(s===i)for(let m=e;m<n;m++)o[c[m]]=1;else{let m=cs(t,e,n,r,s,i,f,u,d,h);dt(t,e,m.i1,r,s,m.i2,o,a,c,l,f,u,m.minLo,h),dt(t,m.i1,n,r,m.i2,i,o,a,c,l,f,u,m.minHi,h)}}function ls(t,e,n,r){let s=[],i=0,o=0,a=1,c=1;for(;i<t.length||o<e.length;){if(i<t.length&&o<e.length&&!n[i]&&!r[o]){s.push({type:"keep",line:t[i]??"",oldLineNo:a++,newLineNo:c++}),i++,o++;continue}for(;i<t.length&&n[i];)s.push({type:"delete",line:t[i]??"",oldLineNo:a++,newLineNo:0}),i++;for(;o<e.length&&r[o];)s.push({type:"insert",line:e[o]??"",oldLineNo:0,newLineNo:c++}),o++}return s}var pn=200,gn=20,yn=100,fs=1,us=21,hs=-30,ds=6,ms=-4,ps=10,gs=24,ys=17,bs=23,ws=17,Is=60;function ut(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);if(r===32)e+=1;else if(r===9)e+=8-e%8;else if(!(r===10||r===13||r===11||r===12))return e;if(e>=pn)return pn}return-1}function bn(t,e,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=ut(t[n]));for(let s=n-1;s>=0&&(r.preIndent=ut(t[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===gn){r.preIndent=0;break}for(let s=n+1;s<e&&(r.postIndent=ut(t[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===gn){r.postIndent=0;break}return r}function wn(t,e){t.preIndent===-1&&t.preBlank===0&&(e.penalty+=fs),t.endOfFile&&(e.penalty+=us);let n=t.indent===-1?1+t.postBlank:0,r=t.preBlank+n;e.penalty+=hs*r,e.penalty+=ds*n;let s=t.indent!==-1?t.indent:t.postIndent,i=r!==0;e.effectiveIndent+=s,s===-1||t.preIndent===-1||(s>t.preIndent?e.penalty+=i?ps:ms:s===t.preIndent||(t.postIndent!==-1&&t.postIndent>s?e.penalty+=i?ys:gs:e.penalty+=i?ws:bs))}function Es(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndent<e.effectiveIndent?1:0);return Is*n+(t.penalty-e.penalty)}function In(t,e,n,r,s,i){let o=0,a=0;for(;t[a];)a++;let c=0,l=0;for(;s[l];)l++;let f=(u,d)=>e[u]===e[d];for(;;){if(a!==o){let u,d,h;do{for(u=a-o,d=-1;o>0&&f(o-1,a-1);){for(t[--o]=1,t[--a]=0;t[o-1];)o--;if(c===0)break;for(l=c-1,c=l;s[c-1];c--);}for(h=a,l>c&&(d=a);!(a>=r||!f(o,a));){for(t[o++]=0,t[a++]=1;t[a];)a++;if(l>=i)break;for(c=l+1,l=c;s[l];l++);l>c&&(d=a)}}while(u!==a-o);if(a!==h)if(d!==-1)for(;l===c;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(l=c-1,c=l;s[c-1];c--);}else{let m=-1,g={effectiveIndent:0,penalty:0},p=h;for(a-u-1>p&&(p=a-u-1),a-yn>p&&(p=a-yn);p<=a;p++){let b={effectiveIndent:0,penalty:0},R=bn(n,r,p);wn(R,b);let j=bn(n,r,p-u);wn(j,b),(m===-1||Es(b,g)<=0)&&(g={effectiveIndent:b.effectiveIndent,penalty:b.penalty},m=p)}for(;a>m;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(l=c-1,c=l;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;t[a];a++);if(l>=i)break;for(c=l+1,l=c;s[l];l++);}}function mt(t,e){let n=t.length,r=e.length,s=new Uint8Array(n),i=new Uint8Array(r);if(n>0&&r>0){let{classes1:o,classes2:a,classInfo:c}=rs(t,e),{dstart:l,dend1:f,dend2:u}=ss(o,n,a,r);if(l>f)for(let d=l;d<r-(n-1-f);d++)i[d]=1;else if(l>u)for(let d=l;d<n-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:g}=is(o,n,a,r,c,l,f,u,s,i);if(h>0&&g>0){let p=new Array(h);for(let w=0;w<h;w++)p[w]=o[d[w]];let b=new Array(g);for(let w=0;w<g;w++)b[w]=a[m[w]];let R={},j={},A=h+g+3,O=Math.max(as,ht(A));dt(p,0,h,b,0,g,s,i,d,m,R,j,!1,O)}else if(h===0)for(let p=0;p<g;p++)i[m[p]]=1;else for(let p=0;p<h;p++)s[d[p]]=1;In(s,o,t,n,i,r),In(i,a,e,r,s,n)}}else n===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function Ee(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return e.map((o,a)=>({type:"insert",line:o,oldLineNo:0,newLineNo:a+1}));if(r===0)return t.map((o,a)=>({type:"delete",line:o,oldLineNo:a+1,newLineNo:0}));let{changedOld:s,changedNew:i}=mt(t,e);return ls(t,e,s,i)}var xs=3;function En(t,e=xs){if(e=Math.max(0,e),t.length===0)return[];let n=[];for(let a=0;a<t.length;a++){let c=t[a];c&&c.type!=="keep"&&n.push(a)}if(n.length===0)return[];let r=n[0]??0,s=[],i=Math.max(0,r-e),o=Math.min(t.length-1,r+e);for(let a=1;a<n.length;a++){let c=n[a]??0,l=Math.max(0,c-e),f=Math.min(t.length-1,c+e);l<=o+1||(s.push({start:i,end:o}),i=l),o=f}return s.push({start:i,end:o}),s.map(a=>Os(t,a.start,a.end))}function Os(t,e,n){let r=0,s=0,i=0,o=0,a=[],c=!1,l=!1;for(let f=e;f<=n;f++){let u=t[f];if(u)switch(u.type){case"keep":c||(r=u.oldLineNo,c=!0),l||(i=u.newLineNo,l=!0),s++,o++,a.push({type:"context",content:u.line});break;case"delete":c||(r=u.oldLineNo,c=!0),s++,a.push({type:"delete",content:u.line});break;case"insert":l||(i=u.newLineNo,l=!0),o++,a.push({type:"insert",content:u.line});break}}if(c||(r=i>0?i:1),l||(i=r>0?r:1),s===0)for(let f=e;f<=n;f++){let u=t[f];if(u&&u.type==="insert"){r=u.newLineNo>1?u.newLineNo-1:0;break}}if(o===0)for(let f=e;f<=n;f++){let u=t[f];if(u&&u.type==="delete"){i=u.oldLineNo>1?u.oldLineNo-1:0;break}}return{oldStart:r,oldCount:s,newStart:i,newCount:o,lines:a}}function xe(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function Rs(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=xe(e),r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i&&xe(i.path)===n){r=s;break}}return t.splice(r,1)[0]}var Ps=50;async function me(t,e,n=Ps){let r=new Map,s=[],i=[],o=[];for(let f of e)if(f.status==="deleted"&&f.oldHash){let u=r.get(f.oldHash)??[];u.push(f),r.set(f.oldHash,u),s.push(f)}else f.status==="added"&&f.newHash?i.push(f):o.push(f);let a=[],c=[];for(let f of i){let u=f.newHash;if(!u){c.push(f);continue}let d=r.get(u);if(d&&d.length>0){let h=Rs(d,f.path);h&&a.push({oldPath:h.path,newPath:f.path,oldHash:h.oldHash??u,newHash:u,similarity:100,oldMode:h.oldMode,newMode:f.newMode})}else c.push(f)}let l=[...r.values()].flat();if(l.length>0&&c.length>0){let f=await ks(t,l,c,n);if(f.length>0){let u=new Set(f.map(h=>h.oldPath)),d=new Set(f.map(h=>h.newPath));l=l.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...f)}}if(l.length>0&&c.length>0){let f=await Cs(t,l,c,n);if(f.length>0){let u=new Set(f.map(h=>h.oldPath)),d=new Set(f.map(h=>h.newPath));l=l.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...f)}}return{remaining:[...o,...l,...c],renames:a}}async function ks(t,e,n,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let l=xe(c.path);s.has(l)?s.set(l,-1):s.set(l,a)}let i=new Map;for(let a=0;a<n.length;a++){let c=n[a];if(!c)continue;let l=xe(c.path);i.has(l)?i.set(l,-1):i.set(l,a)}let o=[];for(let[a,c]of s){if(c===-1)continue;let l=i.get(a);if(l===void 0||l===-1)continue;let f=e[c],u=n[l];if(!f?.oldHash||!u?.newHash||f.oldHash===u.newHash)continue;let d=await re(t,f.oldHash),h=await re(t,u.newHash),m=Ss(d,h);m<r||o.push({oldPath:f.path,newPath:u.path,oldHash:f.oldHash,newHash:u.newHash,similarity:m,oldMode:f.oldMode,newMode:u.newMode})}return o}var xn=107927;function Ye(t){let e=new Map,n=0,r=0,s=0;for(let o=0;o<t.length;o++){let a=t[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let l=(r+Math.imul(s,97))%xn;e.set(l,(e.get(l)??0)+n),n=0,r=0,s=0}if(n>0){let o=(r+Math.imul(s,97))%xn;e.set(o,(e.get(o)??0)+n)}let i=[];for(let[o,a]of e)i.push({hash:o,count:a});return i.sort((o,a)=>o.hash-a.hash),i}function Ts(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let o=t[s];if(!o)break;for(;i<e.length;){let l=e[i];if(!l||l.hash>=o.hash)break;r+=l.count,i++}let a=o.count,c=0;if(i<e.length){let l=e[i];l&&l.hash===o.hash&&(c=l.count,i++)}a<c?(r+=c-a,n+=a):n+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:n,literalAdded:r}}function Ss(t,e){return t.length===0&&e.length===0?100:t.length===0||e.length===0?0:On(t.length,Ye(t),e.length,Ye(e))}function On(t,e,n,r){let s=Math.max(t,n),i=Math.min(t,n);if(i<s-i)return 0;let{srcCopied:o}=Ts(e,r);return Math.floor(o*100/s)}async function Cs(t,e,n,r){let s=[];for(let f of e)if(f.oldHash){let u=await re(t,f.oldHash);s.push({size:u.length,chunks:Ye(u)})}else s.push(null);let i=[];for(let f of n)if(f.newHash){let u=await re(t,f.newHash);i.push({size:u.length,chunks:Ye(u)})}else i.push(null);let o=[];for(let f=0;f<e.length;f++){let u=e[f],d=s[f];if(!(!u||!d))for(let h=0;h<n.length;h++){let m=n[h],g=i[h];if(!m||!g)continue;let p=On(d.size,d.chunks,g.size,g.chunks);if(p>=r){let b=xe(u.path)===xe(m.path)?1:0;o.push({similarity:p,nameScore:b,delIdx:f,addIdx:h})}}}o.sort((f,u)=>u.similarity-f.similarity||u.nameScore-f.nameScore);let a=new Set,c=new Set,l=[];for(let{similarity:f,delIdx:u,addIdx:d}of o){if(a.has(u)||c.has(d))continue;a.add(u),c.add(d);let h=e[u],m=n[d];!h||!m||l.push({oldPath:h.path,newPath:m.path,oldHash:h.oldHash??"",newHash:m.newHash??"",similarity:f,oldMode:h.oldMode,newMode:m.newMode})}return l}async function ue(t,e,n){return(await le(t,e)).get(n)?.hash??null}async function Rn(t,e,n,r){let s=await oe(t,e,n);if(!s.find(c=>c.status==="added"&&c.path===r))return null;let{renames:o}=await me(t,s);return o.find(c=>c.newPath===r)?.oldPath??null}async function js(t,e,n,r,s,i){let o=await ue(t,(await v(t,e)).tree,n);if(!o){let g=new Map,p=await v(t,e);for(let b of r)g.set(b.finalIdx,he(e,n,b.currentLine,i+b.finalIdx,s[b.finalIdx],p,!1,void 0));return g}let a=await H(t,o),c=te(a),l=new Array(s.length),f=[...r],u=e,d=n,h=c;for(;f.length>0;){let g=await v(t,u);if(g.parents.length===0){for(let E of f)l[E.finalIdx]=he(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],g,!0,void 0);break}let p=await ue(t,g.tree,d),b=null,R=[];for(let E of g.parents){let P=await v(t,E),T=d,$=await ue(t,P.tree,T);if(!$){let D=await Rn(t,P.tree,g.tree,d);D&&(T=D,$=await ue(t,P.tree,T))}if($&&(R.push({hash:E,path:T,blobHash:$}),$===p)){b={hash:E,path:T};break}}if(b){u=b.hash,d=b.path;continue}if(R.length===0){for(let E of f)l[E.finalIdx]=he(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],g,!1,void 0);break}let j=R[0],A=await H(t,j.blobHash),O=te(A),w=Ee(O,h),x=new Map;for(let E of w)E.type==="keep"&&x.set(E.newLineNo,E.oldLineNo);let S=[];for(let E of f){let P=x.get(E.currentLine);P!==void 0?S.push({finalIdx:E.finalIdx,currentLine:P}):l[E.finalIdx]=he(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],g,!1,{hash:j.hash,path:j.path})}f=S,u=j.hash,d=j.path,h=O}let m=new Map;for(let g of r)l[g.finalIdx]&&m.set(g.finalIdx,l[g.finalIdx]);return m}async function Pn(t,e,n,r){let s=await v(t,e),i=await ue(t,s.tree,n);if(!i)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let o=await H(t,i),a=te(o),c=r?.startLine??1,l=r?.endLine??a.length,f=a.slice(c-1,l),u=new Array(f.length),d=f.map((p,b)=>({finalIdx:b,currentLine:c+b})),h=e,m=n,g=a;for(;d.length>0;){let p=await v(t,h);if(p.parents.length===0){for(let x of d)u[x.finalIdx]=he(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!0,void 0);break}let b=await ue(t,p.tree,m),R=[],j=null;for(let x of p.parents){let S=await v(t,x),E=m,P=await ue(t,S.tree,E);if(!P){let T=await Rn(t,S.tree,p.tree,m);T&&(E=T,P=await ue(t,S.tree,E))}if(P){let T={hash:x,path:E,blobHash:P};if(R.push(T),P===b){j=T;break}}}if(j){h=j.hash,m=j.path;continue}if(R.length===0){for(let x of d)u[x.finalIdx]=he(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!1,void 0);break}if(R.length===1){let x=R[0],S=await H(t,x.blobHash),E=te(S),P=Ee(E,g),T=new Map;for(let D of P)D.type==="keep"&&T.set(D.newLineNo,D.oldLineNo);let $=[];for(let D of d){let ae=T.get(D.currentLine);ae!==void 0?$.push({finalIdx:D.finalIdx,currentLine:ae}):u[D.finalIdx]=he(h,m,D.currentLine,c+D.finalIdx,f[D.finalIdx],p,!1,{hash:x.hash,path:x.path})}d=$,h=x.hash,m=x.path,g=E;continue}let A=[];for(let x of R){let S=await H(t,x.blobHash),E=te(S),P=Ee(E,g),T=new Map;for(let $ of P)$.type==="keep"&&T.set($.newLineNo,$.oldLineNo);A.push({info:x,newToOld:T})}let O=new Map;for(let x of d){let S=!1;for(let E=0;E<A.length;E++){let P=A[E],T=P.newToOld.get(x.currentLine);if(T!==void 0){let $=O.get(E);$||($={info:P.info,lines:[]},O.set(E,$)),$.lines.push({finalIdx:x.finalIdx,currentLine:T}),S=!0;break}}S||(u[x.finalIdx]=he(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!1,{hash:R[0].hash,path:R[0].path}))}let w=O.get(0);for(let[x,S]of O){if(x===0)continue;let E=await js(t,S.info.hash,S.info.path,S.lines,f,c);for(let[P,T]of E)u[P]=T}if(w&&w.lines.length>0){d=w.lines,h=w.info.hash,m=w.info.path;let x=await H(t,w.info.blobHash);g=te(x)}else break}return u}function he(t,e,n,r,s,i,o,a){return{hash:t,origPath:e,origLine:n,finalLine:r,content:s,author:i.author,committer:i.committer,summary:i.message.split(`
13
- `)[0],boundary:o,previous:a}}var Oe=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),o<r&&this.higher(n[o],n[s])&&(s=o),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*pe(t,e,n){if(n?.topoOrder){yield*vs(t,e,n);return}let r=await Tn(t,n?.exclude),s=new Set(r),i=new Oe,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let c of a)s.has(c)||i.push(await qe(t,c));for(;i.size>0;){let c=i.pop();if(s.has(c.hash)||(s.add(c.hash),yield c,o?.has(c.hash)))continue;let l=n?.firstParent?c.commit.parents.slice(0,1):c.commit.parents;for(let f of l)if(!s.has(f))try{i.push(await qe(t,f))}catch{}}}async function*vs(t,e,n){let r=await Tn(t,n?.exclude),s=new Set(r),i=new Oe,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let h of a)s.has(h)||i.push(await qe(t,h));let c=[],l=new Map;for(;i.size>0;){let h=i.pop();if(s.has(h.hash)||(s.add(h.hash),l.set(h.hash,c.length),c.push(h),o?.has(h.hash)))continue;let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of m)if(!s.has(g))try{i.push(await qe(t,g))}catch{}}let f=c.length;if(f===0)return;let u=new Int32Array(f);for(let h of c){let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of m){let p=l.get(g);p!==void 0&&(u[p]=(u[p]??0)+1)}}let d=[];for(let h=f-1;h>=0;h--)u[h]===0&&d.push(h);for(;d.length>0;){let h=d.pop();yield c[h];let m=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let g of m){let p=l.get(g);if(p!==void 0){let b=(u[p]??0)-1;u[p]=b,b===0&&d.push(p)}}}}async function kn(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let a of pe(t,e))r.add(a.hash);let s=new Set;for await(let a of pe(t,n))s.add(a.hash);let i=0;for(let a of r)s.has(a)||i++;let o=0;for(let a of s)r.has(a)||o++;return{ahead:i,behind:o}}async function Tn(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of pe(t,e))n.add(r.hash);return n}async function qe(t,e){return{hash:e,commit:await v(t,e)}}async function As(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let o;try{o=await v(t,i)}catch{continue}for(let a of o.parents)n.has(a)||r.push(a)}return n}async function pt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let o=s[i++];if(o===e)return!0;if(r.has(o))continue;r.add(o);let a;try{a=await v(t,o)}catch{continue}for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function De(t,e,n){if(e===n)return[e];let r=await As(t,e),s=[],i=new Set,o=[n],a=0;for(;a<o.length;){let l=o[a++];if(i.has(l))continue;if(i.add(l),r.has(l)){s.push(l);continue}let f;try{f=await v(t,l)}catch{continue}for(let u of f.parents)i.has(u)||o.push(u)}if(s.length<=1)return s;let c=[];for(let l of s){let f=!1;for(let u of s)if(u!==l&&await pt(t,l,u)){f=!0;break}f||c.push(l)}return c.length<=1?c:$s(t,e,n,c)}async function $s(t,e,n,r){let s=new Set(r),i=new Set,o=[],a=new Map,c=new Map,l=0,f=[{hash:e,mask:1,seq:l++},{hash:n,mask:2,seq:l++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await v(t,d)).committer.timestamp;return c.set(d,m),m}for(;f.length>0;){let d=0,h=await u(f[0].hash);for(let R=1;R<f.length;R++){let j=f[R],A=await u(j.hash),O=f[d];(A>h||A===h&&j.seq<O.seq)&&(d=R,h=A)}let m=f.splice(d,1)[0],g=a.get(m.hash)??0,p=g|m.mask;if(p===g)continue;if(a.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let b=await v(t,m.hash);for(let R of b.parents)f.push({hash:R,mask:p,seq:l++})}for(let d of r)i.has(d)||o.push(d);return o}async function Ls(t,e){return Q(t,e)}async function Ms(t,e,n){return oe(t,e,n)}async function Ds(t,e,n){let r=await v(t,n),s=null;return e&&(s=(await v(t,e)).tree),oe(t,s,r.tree)}async function*Hs(t,e,n){let r=e?[e]:[];for await(let s of pe(t,n,{exclude:r}))yield{hash:s.hash,message:s.commit.message,tree:s.commit.tree,parents:s.commit.parents,author:s.commit.author,committer:s.commit.committer}}async function Us(t,e,n){return pt(t,e,n)}async function Ns(t,e,n){return De(t,e,n)}async function Bs(t,e,n){return kn(t,e,n)}async function Gs(t,e,n,r){return Pn(t,e,n,r)}function Fs(t){return t==="insert"?"+":t==="delete"?"-":" "}function _s(t){return{oldStart:t.oldStart,oldCount:t.oldCount,newStart:t.newStart,newCount:t.newCount,lines:t.lines.map(e=>Fs(e.type)+e.content)}}function Sn(t,e,n){let r=te(t),s=te(e),i=Ee(r,s);return En(i,n).map(_s)}async function Cn(t,e){let n=await _e(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function Ws(t,e,n,r){let s=await Cn(t,e),i=await Cn(t,n),o=await v(t,s),a=await v(t,i),c=await oe(t,o.tree,a.tree),l=r?.renames!==!1,f=r?.contextLines,u=r?.paths,d=[];if(l){let m=await me(t,c);c=m.remaining,d=m.renames}let h=[];for(let m of c){if(u&&!u.some(R=>m.path.startsWith(R)))continue;let g=m.oldHash?await H(t,m.oldHash):"",p=m.newHash?await H(t,m.newHash):"",b=Sn(g,p,f);h.push({path:m.path,status:m.status,hunks:b})}for(let m of d){if(u&&!u.some(R=>m.newPath.startsWith(R)||m.oldPath.startsWith(R)))continue;let g=await H(t,m.oldHash),p=await H(t,m.newHash),b=Sn(g,p,f);h.push({path:m.newPath,status:"renamed",oldPath:m.oldPath,similarity:m.similarity,hunks:b})}return h.sort((m,g)=>m.path.localeCompare(g.path)),h}async function*zs(t,e,n){if(n?.paths&&n.paths.length>0){yield*Vs(t,e,n.paths,n);return}for await(let r of pe(t,e,n))yield{hash:r.hash,message:r.commit.message,tree:r.commit.tree,parents:r.commit.parents,author:r.commit.author,committer:r.commit.committer}}function gt(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("/")?n:n+"/"))}async function*Vs(t,e,n,r){let s=new Set;if(r?.exclude)for await(let l of pe(t,r.exclude))s.add(l.hash);let i=new Set(s),o=new Oe,a=async l=>{if(!i.has(l))try{let f=await v(t,l);o.push({hash:l,commit:f})}catch{}},c=Array.isArray(e)?e:[e];for(let l of c)await a(l);for(;o.size>0;){let l=o.pop();if(i.has(l.hash))continue;i.add(l.hash);let{commit:f}=l,u=r?.firstParent?f.parents.slice(0,1):f.parents,d=()=>({hash:l.hash,message:f.message,tree:f.tree,parents:f.parents,author:f.author,committer:f.committer});if(u.length===0){(await oe(t,null,f.tree)).some(g=>gt(g.path,n))&&(yield d());continue}if(u.length===1){let m=u[0];try{let g=await v(t,m);(await oe(t,g.tree,f.tree)).some(b=>gt(b.path,n))&&(yield d())}catch{yield d()}await a(m);continue}let h=[];for(let m of u)try{let g=await v(t,m);(await oe(t,g.tree,f.tree)).some(b=>gt(b.path,n))||h.push(m)}catch{}if(h.length>0)await a(h[0]);else{yield d();for(let m of u)await a(m)}}}function Ks(t){let e=Math.abs(t),n=t<=0?"+":"-",r=String(Math.floor(e/60)).padStart(2,"0"),s=String(e%60).padStart(2,"0");return`${n}${r}${s}`}function He(t){if("timestamp"in t)return t;let e=t.date??new Date;return{name:t.name,email:t.email,timestamp:Math.floor(e.getTime()/1e3),timezone:Ks(e.getTimezoneOffset())}}async function Ys(t,e){let n=He(e.author),r=e.committer?He(e.committer):n,s=Ae({type:"commit",tree:e.tree,parents:e.parents,author:n,committer:r,message:e.message}),i=await B(t,"commit",s);return e.branch&&await An(t,e.branch,i),i}async function qs(t,e){let n=He(e.tagger),r=Xt({type:"tag",object:e.target,objectType:e.targetType??"commit",name:e.name,tagger:n,message:e.message}),s=await B(t,"tag",r);return await t.refStore.writeRef(`refs/tags/${e.name}`,{type:"direct",hash:s}),s}async function vn(t,e){let n=e.branch?`refs/heads/${e.branch}`:null,r=n?await J(t,n):null,s=null;r&&(s=(await v(t,r)).tree);let i=[];for(let[d,h]of Object.entries(e.files))if(h===null)i.push({path:d,hash:null});else{let m=typeof h=="string"?new TextEncoder().encode(h):h,g=await B(t,"blob",m);i.push({path:d,hash:g})}let o;s?o=await $n(t,s,i):o=await bt(t,null,yt(i));let a=He(e.author),c=e.committer?He(e.committer):a,f=Ae({type:"commit",tree:o,parents:r?[r]:[],author:a,committer:c,message:e.message});return{hash:await B(t,"commit",f),parentHash:r}}async function Xs(t,e){let{hash:n}=await vn(t,e);return await An(t,e.branch,n),n}async function An(t,e,n){let r=`refs/heads/${e}`;await t.refStore.writeRef(r,{type:"direct",hash:n}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:r})}async function Zs(t,e){let n=[...e].sort((i,o)=>i.name.localeCompare(o.name)),r=await Promise.all(n.map(async i=>{let o=i.mode;return o||(o=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:o,name:i.name,hash:i.hash}})),s=Le({type:"tree",entries:r});return B(t,"tree",s)}async function Js(t,e){return B(t,"blob",new TextEncoder().encode(e))}async function $n(t,e,n){return bt(t,e,yt(n))}function yt(t){let e=new Map,n=new Map;for(let r of t){let s=r.path.indexOf("/");if(s===-1)e.set(r.path,{hash:r.hash,mode:r.mode??"100644"});else{let i=r.path.slice(0,s),o=r.path.slice(s+1),a=n.get(i);a||(a=[],n.set(i,a)),a.push({...r,path:o})}}return{files:e,dirs:n}}async function jn(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return se(n.content).entries}async function bt(t,e,n){let r=new Map;if(e)for(let o of await jn(t,e))r.set(o.name,o);for(let[o,{hash:a,mode:c}]of n.files)a===null?r.delete(o):r.set(o,{name:o,hash:a,mode:c});for(let[o,a]of n.dirs){let c=r.get(o),l=c?.mode==="040000"?c.hash:null,f=yt(a),u=await bt(t,l,f);(await jn(t,u)).length===0?r.delete(o):r.set(o,{name:o,hash:u,mode:"040000"})}let s=[...r.values()].sort((o,a)=>{let c=o.mode==="040000"?`${o.name}/`:o.name,l=a.mode==="040000"?`${a.name}/`:a.name;return c<l?-1:c>l?1:0}),i=Le({type:"tree",entries:s});return B(t,"tree",i)}function wt(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=mt(t,e);return Qs(s,n,i,r)}function Qs(t,e,n,r){let s=[],i=0,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!t[i]&&!n[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&t[i];)i++;for(;o<r&&n[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function ei(t,e,n){let r=[];for(let c of wt(e,t))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of wt(e,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,l)=>c.oStart-l.oStart);let s=[],i=0;function o(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let a=0;for(;a<r.length;){let c=r[a++],l=c.oStart,f=c.oStart+c.oLength,u=[c];for(o(l);a<r.length;){let d=r[a];if(d.oStart>f)break;f=Math.max(f,d.oStart+d.oLength),u.push(d),a++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?t:n;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:d.slice(c.abStart,c.abStart+c.abLength)})}}else{let d={a:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let b of u){let R=b.oStart,j=R+b.oLength,A=b.abStart,O=A+b.abLength,w=d[b.ab];w.abMin=Math.min(A,w.abMin),w.abMax=Math.max(O,w.abMax),w.oMin=Math.min(R,w.oMin),w.oMax=Math.max(j,w.oMax)}let h=d.a.abMin+(l-d.a.oMin),m=d.a.abMax+(f-d.a.oMax),g=d.b.abMin+(l-d.b.oMin),p=d.b.abMax+(f-d.b.oMax);s.push({stable:!1,a:t.slice(h,m),o:e.slice(l,f),b:n.slice(g,p)})}i=f}return o(e.length),s}function ti(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=ei(t,e,n),o=[],a=[];function c(){a.length&&(o.push({type:"ok",lines:a}),a=[])}for(let l of i)l.stable?a.push(...l.content):s&&Mn(l.a,l.b)?a.push(...l.a):(c(),o.push({type:"conflict",a:l.a,o:l.o,b:l.b}));return c(),r?.conflictStyle==="diff3"?Ln(o):Ln(ni(o))}function Ue(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",o=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),l=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,f=ti(t,e,n,{conflictStyle:i}),u=!1,d=[];for(let h of f)h.type==="ok"?d.push(...h.lines):(u=!0,i==="diff3"?d.push(o,...h.a,a,...h.o,c,...h.b,l):d.push(o,...h.a,c,...h.b,l));return{conflict:u,result:d}}function ni(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...ri(n));return e}function ri(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(Mn(e,n))return[t];let r=wt(e,n);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let a of r){let c=a.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let f=c+a.buffer1[1],u=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:e.slice(c,f),o:[],b:n.slice(a.buffer2[0],u)}),i=f}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[t]:s}function Ln(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.length-1],i=e[r];if(s.type==="conflict"&&i.type==="ok"&&i.lines.length<=3&&r+1<e.length&&e[r+1].type==="conflict"){let o=e[r+1],a=s;a.a=[...s.a,...i.lines,...o.a],a.b=[...s.b,...i.lines,...o.b],a.o=[...s.o,...i.lines,...o.o],r++}else n.push(i)}return n}function ge(t,e,n,r){let s=Ue(Y(t),Y(e),Y(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(It);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
8
+ `)){let f=l.indexOf(" ");if(f===-1)continue;let u=l.slice(0,f),d=l.slice(f+1);switch(u){case"object":i=d;break;case"type":o=d;break;case"tag":a=d;break;case"tagger":c=je(d);break}}if(!i)throw new Error("Tag missing object field");if(!a)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:i,objectType:o,name:a,tagger:c,message:s}}function Zt(t){let e=[];return e.push(`object ${t.object}`),e.push(`type ${t.objectType}`),e.push(`tag ${t.name}`),e.push(`tagger ${ve(t.tagger)}`),e.push(""),e.push(t.message),kr.encode(e.join(`
9
+ `))}async function B(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function F(t,e){return t.objectStore.read(e)}async function Jt(t,e){return t.objectStore.exists(e)}async function Qt(t,e){return t.objectStore.findByPrefix(e)}function ne(t){let e=Math.min(t.length,8e3);for(let n=0;n<e;n++)if(t.charCodeAt(n)===0)return!0;return!1}var Sr=new TextDecoder;async function H(t,e){let n=await F(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return Sr.decode(n.content)}async function re(t,e){let n=await F(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function v(t,e){let n=await F(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return qt(n.content)}async function $e(t,e){let n=e;for(let r=0;r<100;r++){let s=await F(t,n);if(s.type==="commit")return n;if(s.type==="tag"){n=Xt(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 Cr=new TextEncoder,en=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 se(t){let e=[],n=0;for(;n<t.byteLength;){let r=t.indexOf(32,n);if(r===-1)break;let s=en.decode(t.subarray(n,r)),i=t.indexOf(0,r+1);if(i===-1)break;let o=en.decode(t.subarray(r+1,i)),a=t.subarray(i+1,i+21),c=Te(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 Le(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}var _={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function tn(t){return typeof t=="string"?{type:"direct",hash:t}:t}var $r=10;async function Lr(t,e){return t.refStore.readRef(e)}async function J(t,e){let n=e;for(let r=0;r<$r;r++){let s=await Lr(t,n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function ct(t,e="refs"){return t.refStore.listRefs(e)}function lt(t){return t.replace("refs/heads/","")}function nn(t){return t.replace("refs/tags/","")}function rn(t){return t.length===4&&t.toLowerCase()===".git"}function sn(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===".."||rn(n))return!1;return!0}function on(t,e){return e===t?!1:t==="/"?e.startsWith("/")&&e.length>1:e.startsWith(t+"/")}function an(t){if(t.length===0||t.charCodeAt(0)===47)return!1;let e=t.split("/");for(let n of e)if(n===".."||rn(n))return!1;return!0}var Mr=1145655875,Dr=2;async function Fe(t,e){let n=we(t.gitDir,"index"),r=await Hr(e);await t.fs.writeFile(n,r)}function cn(t){let e=[...t].sort(ln);return{version:Dr,entries:e}}function ce(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function Hr(t){let e=new TextEncoder,n=[...t.entries].sort(ln),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,Mr),c+=4,a.setUint32(c,t.version),c+=4,a.setUint32(c,n.length),c+=4;for(let d=0;d<n.length;d++){let h=n[d],m=r[d],g=c;a.setUint32(c,h.stat.ctimeSeconds),a.setUint32(c+4,h.stat.ctimeNanoseconds),a.setUint32(c+8,h.stat.mtimeSeconds),a.setUint32(c+12,h.stat.mtimeNanoseconds),a.setUint32(c+16,h.stat.dev),a.setUint32(c+20,h.stat.ino),a.setUint32(c+24,h.mode),a.setUint32(c+28,h.stat.uid),a.setUint32(c+32,h.stat.gid),a.setUint32(c+36,h.stat.size),c+=40;let p=ye(h.hash);o.set(p,c),c+=20;let b=Math.min(m.byteLength,4095),R=(h.stage&3)<<12|b;a.setUint16(c,R),c+=2,o.set(m,c),c+=m.byteLength,o[c]=0,c+=1;let j=62+m.byteLength+1,A=Math.ceil(j/8)*8;c=g+A}let l=o.subarray(0,c),f=await Be(l),u=ye(f);return o.set(u,c),o}function ln(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}function Ur(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 Nr=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];async function Br(t,e){let n=await Qt(t,e);if(n.length===0)return null;if(n.length>1)throw new ft(e);return n[0]}var ft=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}};async function Gr(t,e){if(e==="HEAD"||e==="@")return J(t,"HEAD");if(Nr.includes(e))return J(t,e);if(/^[0-9a-f]{40}$/.test(e))return await Jt(t,e)?e:null;if(/^[0-9a-f]{4,39}$/.test(e)){let i=await Br(t,e);if(i)return i}if(e.startsWith("refs/")){let i=await J(t,e);if(i)return i}let n=await J(t,`refs/heads/${e}`);if(n)return n;let r=await J(t,`refs/tags/${e}`);if(r)return r;let s=await J(t,`refs/remotes/${e}`);return s||null}async function Fr(t,e,n){if(n===""||n==="commit")try{return await $e(t,e)}catch{return null}if(n==="tree"){let s;try{s=await $e(t,e)}catch{return null}return(await v(t,s)).tree}return(await F(t,e)).type!==n?null:e}async function _r(t,e,n){let r=e;n.some(i=>i.type==="tilde"||i.type==="caret")&&(r=await $e(t,r));for(let i of n)if(i.type==="peel"){if(!r)return null;r=await Fr(t,r,i.target)}else if(i.type==="tilde")for(let o=0;o<i.n;o++){if(!r)return null;let a=await v(t,r);if(a.parents.length===0||(r=a.parents[0]??null,!r))return null}else{if(i.n===0)continue;if(!r)return null;let o=await v(t,r);if(i.n>o.parents.length||(r=o.parents[i.n-1]??null,!r))return null}return r}async function _e(t,e){let{base:n,reflogIndex:r,suffixes:s}=Ur(e);if(r!==void 0)return null;let i=await Gr(t,n);return i?_r(t,i,s):null}var io=new TextEncoder;function ie(t){return typeof t=="string"?t==="120000":t===40960}function fn(t){return{stdout:"",stderr:`fatal: ${t}
10
+ `,exitCode:128}}var ao=fn("not a git repository (or any of the parent directories): .git"),co=fn("this operation must be run in a work tree");function Me(t,e){return t<e?-1:t>e?1:0}async function ut(t,e){return un(t,e,"")}async function un(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:Wr(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 un(t,a,c);r.push({mode:_.DIRECTORY,name:o,hash:l})}r.sort((o,a)=>{let c=o.mode===_.DIRECTORY?`${o.name}/`:o.name,l=a.mode===_.DIRECTORY?`${a.name}/`:a.name;return c<l?-1:c>l?1:0});let i=Le({type:"tree",entries:r});return B(t,"tree",i)}async function Q(t,e,n=""){let r=await F(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=se(r.content),i=[];for(let o of s.entries){let a=n?`${n}/${o.name}`:o.name;if(o.mode===_.DIRECTORY){let c=await Q(t,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function le(t,e){if(!e)return new Map;let n=await Q(t,e);return new Map(n.map(r=>[r.path,r]))}async function oe(t,e,n){let r=await le(t,e),s=await le(t,n),i=[];for(let[o,a]of r){let c=s.get(o);c?(a.hash!==c.hash||a.mode!==c.mode)&&i.push({path:o,status:"modified",oldHash:a.hash,newHash:c.hash,oldMode:a.mode,newMode:c.mode}):i.push({path:o,status:"deleted",oldHash:a.hash,oldMode:a.mode})}for(let[o,a]of s)r.has(o)||i.push({path:o,status:"added",newHash:a.hash,newMode:a.mode});return i.sort((o,a)=>Me(o.path,a.path))}function Wr(t){return t.toString(8).padStart(6,"0")}function zr(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 hn(t,e,n,r){if(zr(t)){let o=e.some(a=>a.test(t));return{matches:[],binary:o}}let s=t.split(`
11
+ `);if(s.length>0&&s[s.length-1]===""&&s.pop(),n&&e.length>1&&!e.every(a=>s.some(c=>a.test(c))))return{matches:[],binary:!1};let i=[];for(let o=0;o<s.length;o++){let a=s[o],c=e.some(l=>l.test(a));(r?!c:c)&&i.push({lineNo:o+1,line:a})}return{matches:i,binary:!1}}function Vr(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function dn(t,e){let n=e?.fixed?Vr(t):t;e?.wordRegexp&&(n=`\\b${n}\\b`);let r=e?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}async function Kr(t,e){return J(t,e)}async function Yr(t){return ct(t,"refs/heads")}async function qr(t){return ct(t,"refs/tags")}async function Xr(t){let e=await t.refStore.readRef("HEAD");if(!e)return{branch:null,ref:null,hash:null};if(e.type==="symbolic"){let n=await t.refStore.readRef(e.target),r=n?.type==="direct"?n.hash:null;return{branch:e.target.startsWith("refs/heads/")?lt(e.target):null,ref:e.target,hash:r}}return{branch:null,ref:null,hash:e.hash}}async function Zr(t,e){return v(t,e)}async function Jr(t,e){return re(t,e)}async function Qr(t,e){return H(t,e)}async function es(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return se(n.content).entries}async function ts(t,e,n){let r=await v(t,e),i=(await Q(t,r.tree)).find(o=>o.path===n);return i?H(t,i.hash):null}function ns(t){let e=0;for(let n=0;n<t.length;n++)t[n]==="/"&&e++;return e}function rs(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 ss(t,e,n,r){let s=[];for(let m of n)if(m instanceof RegExp)s.push(m);else{let g=dn(m,{fixed:r?.fixed,ignoreCase:r?.ignoreCase,wordRegexp:r?.wordRegexp});if(!g)throw new Error(`Invalid pattern: ${m}`);s.push(g)}let i=await v(t,e),a=(await Q(t,i.tree)).filter(m=>!m.mode.startsWith("120")).sort((m,g)=>m.path<g.path?-1:m.path>g.path?1:0),c=r?.allMatch??!1,l=r?.invert??!1,f=r?.maxCount,u=r?.maxDepth,d=r?.paths,h=[];for(let m of a){if(u!==void 0&&ns(m.path)>u||d&&!d.some(R=>rs(R,m.path)))continue;let g=await H(t,m.hash),p=hn(g,s,c,l);if(p.binary){h.push({path:m.path,matches:[],binary:!0});continue}if(p.matches.length===0)continue;let b=f!==void 0?p.matches.slice(0,f):p.matches;h.push({path:m.path,matches:b,binary:!1})}return h}function te(t){if(t.length===0)return[];let e=t.split(`
12
+ `);return e[e.length-1]===""&&e.pop(),e}var is=4,mn=1024,We=100,Ke=0,ze=1,Ie=2;function dt(t){let e=1;for(;e*e<t;)e++;return e}function os(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 as(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 pn(t,e,n,r){e-n>We&&(n=e-We),r-e>We&&(r=e+We);let s=0,i=1;for(let c=1;e-c>=n;c++){let l=t[e-c];if(l===Ke)s++;else if(l===Ie)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let l=t[e+c];if(l===Ke)o++;else if(l===Ie)a++;else break}return o===0?!1:(o+=s,a+=i,a*is<a+o)}function cs(t,e,n,r,s,i,o,a,c,l){let f=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(dt(e),mn);for(let p=i;p<=o;p++){let b=s[t[p]].len2;b===0?f[p]=Ke:b>=d?f[p]=Ie:f[p]=ze}let h=Math.min(dt(r),mn);for(let p=i;p<=a;p++){let b=s[n[p]].len1;b===0?u[p]=Ke:b>=h?u[p]=Ie:u[p]=ze}let m=[];for(let p=i;p<=o;p++)f[p]===ze||f[p]===Ie&&!pn(f,p,i,o)?m.push(p):c[p]=1;let g=[];for(let p=i;p<=a;p++)u[p]===ze||u[p]===Ie&&!pn(u,p,i,a)?g.push(p):l[p]=1;return{refIndex1:m,nreff1:m.length,refIndex2:g,nreff2:g.length}}var fe=20,gn=4,ls=256,fs=256,Ve=2147483647;function z(t,e){return t[e]??0}function us(t,e,n,r,s,i,o,a,c,l){let f=e-i,u=n-s,d=e-s,h=n-i,m=d-h&1,g=d,p=d,b=h,R=h;o[d]=e,a[h]=n;for(let j=1;;j++){let A=!1;g>f?o[--g-1]=-1:++g,p<u?o[++p+1]=-1:--p;for(let O=p;O>=g;O-=2){let w;z(o,O-1)>=z(o,O+1)?w=z(o,O-1)+1:w=z(o,O+1);let x=w,S=w-O;for(;w<n&&S<i&&t[w]===r[S];)w++,S++;if(w-x>fe&&(A=!0),o[O]=w,m&&b<=O&&O<=R&&z(a,O)<=w)return{i1:w,i2:S,minLo:!0,minHi:!0}}b>f?a[--b-1]=Ve:++b,R<u?a[++R+1]=Ve:--R;for(let O=R;O>=b;O-=2){let w;z(a,O-1)<z(a,O+1)?w=z(a,O-1):w=z(a,O+1)-1;let x=w,S=w-O;for(;w>e&&S>s&&t[w-1]===r[S-1];)w--,S--;if(x-w>fe&&(A=!0),a[O]=w,!m&&g<=O&&O<=p&&w<=z(o,O))return{i1:w,i2:S,minLo:!0,minHi:!0}}if(!c){if(A&&j>ls){let O=0,w=null;for(let x=p;x>=g;x-=2){let S=x>d?x-d:d-x,E=z(o,x),P=E-x,T=E-e+(P-s)-S;if(T>gn*j&&T>O&&e+fe<=E&&E<n&&s+fe<=P&&P<i){let $=!0;for(let D=1;D<=fe;D++)if(t[E-D]!==r[P-D]){$=!1;break}$&&(O=T,w={i1:E,i2:P,minLo:!0,minHi:!1})}}if(w)return w;O=0,w=null;for(let x=R;x>=b;x-=2){let S=x>h?x-h:h-x,E=z(a,x),P=E-x,T=n-E+(i-P)-S;if(T>gn*j&&T>O&&e<E&&E<=n-fe&&s<P&&P<=i-fe){let $=!0;for(let D=0;D<fe;D++)if(t[E+D]!==r[P+D]){$=!1;break}$&&(O=T,w={i1:E,i2:P,minLo:!1,minHi:!0})}}if(w)return w}if(j>=l){let O=-1,w=-1;for(let E=p;E>=g;E-=2){let P=Math.min(z(o,E),n),T=P-E;i<T&&(P=i+E,T=i),O<P+T&&(O=P+T,w=P)}let x=Ve,S=Ve;for(let E=R;E>=b;E-=2){let P=Math.max(e,z(a,E)),T=P-E;T<s&&(P=s+E,T=s),P+T<x&&(x=P+T,S=P)}return n+i-x<O-(e+s)?{i1:w,i2:O-w,minLo:!0,minHi:!1}:{i1:S,i2:x-S,minLo:!1,minHi:!0}}}}}function mt(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=us(t,e,n,r,s,i,f,u,d,h);mt(t,e,m.i1,r,s,m.i2,o,a,c,l,f,u,m.minLo,h),mt(t,m.i1,n,r,m.i2,i,o,a,c,l,f,u,m.minHi,h)}}function hs(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 yn=200,bn=20,wn=100,ds=1,ms=21,ps=-30,gs=6,ys=-4,bs=10,ws=24,Is=17,Es=23,xs=17,Os=60;function ht(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>=yn)return yn}return-1}function In(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=ht(t[n]));for(let s=n-1;s>=0&&(r.preIndent=ht(t[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===bn){r.preIndent=0;break}for(let s=n+1;s<e&&(r.postIndent=ht(t[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===bn){r.postIndent=0;break}return r}function En(t,e){t.preIndent===-1&&t.preBlank===0&&(e.penalty+=ds),t.endOfFile&&(e.penalty+=ms);let n=t.indent===-1?1+t.postBlank:0,r=t.preBlank+n;e.penalty+=ps*r,e.penalty+=gs*n;let s=t.indent!==-1?t.indent:t.postIndent,i=r!==0;e.effectiveIndent+=s,s===-1||t.preIndent===-1||(s>t.preIndent?e.penalty+=i?bs:ys:s===t.preIndent||(t.postIndent!==-1&&t.postIndent>s?e.penalty+=i?Is:ws:e.penalty+=i?xs:Es))}function Rs(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndent<e.effectiveIndent?1:0);return Os*n+(t.penalty-e.penalty)}function xn(t,e,n,r,s,i){let o=0,a=0;for(;t[a];)a++;let c=0,l=0;for(;s[l];)l++;let f=(u,d)=>e[u]===e[d];for(;;){if(a!==o){let u,d,h;do{for(u=a-o,d=-1;o>0&&f(o-1,a-1);){for(t[--o]=1,t[--a]=0;t[o-1];)o--;if(c===0)break;for(l=c-1,c=l;s[c-1];c--);}for(h=a,l>c&&(d=a);!(a>=r||!f(o,a));){for(t[o++]=0,t[a++]=1;t[a];)a++;if(l>=i)break;for(c=l+1,l=c;s[l];l++);l>c&&(d=a)}}while(u!==a-o);if(a!==h)if(d!==-1)for(;l===c;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(l=c-1,c=l;s[c-1];c--);}else{let m=-1,g={effectiveIndent:0,penalty:0},p=h;for(a-u-1>p&&(p=a-u-1),a-wn>p&&(p=a-wn);p<=a;p++){let b={effectiveIndent:0,penalty:0},R=In(n,r,p);En(R,b);let j=In(n,r,p-u);En(j,b),(m===-1||Rs(b,g)<=0)&&(g={effectiveIndent:b.effectiveIndent,penalty:b.penalty},m=p)}for(;a>m;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(l=c-1,c=l;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;t[a];a++);if(l>=i)break;for(c=l+1,l=c;s[l];l++);}}function pt(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}=os(t,e),{dstart:l,dend1:f,dend2:u}=as(o,n,a,r);if(l>f)for(let d=l;d<r-(n-1-f);d++)i[d]=1;else if(l>u)for(let d=l;d<n-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:g}=cs(o,n,a,r,c,l,f,u,s,i);if(h>0&&g>0){let p=new Array(h);for(let w=0;w<h;w++)p[w]=o[d[w]];let b=new Array(g);for(let w=0;w<g;w++)b[w]=a[m[w]];let R={},j={},A=h+g+3,O=Math.max(fs,dt(A));mt(p,0,h,b,0,g,s,i,d,m,R,j,!1,O)}else if(h===0)for(let p=0;p<g;p++)i[m[p]]=1;else for(let p=0;p<h;p++)s[d[p]]=1;xn(s,o,t,n,i,r),xn(i,a,e,r,s,n)}}else n===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function Ee(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return e.map((o,a)=>({type:"insert",line:o,oldLineNo:0,newLineNo:a+1}));if(r===0)return t.map((o,a)=>({type:"delete",line:o,oldLineNo:a+1,newLineNo:0}));let{changedOld:s,changedNew:i}=pt(t,e);return hs(t,e,s,i)}var Ps=3;function On(t,e=Ps){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=>ks(t,a.start,a.end))}function ks(t,e,n){let r=0,s=0,i=0,o=0,a=[],c=!1,l=!1;for(let f=e;f<=n;f++){let u=t[f];if(u)switch(u.type){case"keep":c||(r=u.oldLineNo,c=!0),l||(i=u.newLineNo,l=!0),s++,o++,a.push({type:"context",content:u.line});break;case"delete":c||(r=u.oldLineNo,c=!0),s++,a.push({type:"delete",content:u.line});break;case"insert":l||(i=u.newLineNo,l=!0),o++,a.push({type:"insert",content:u.line});break}}if(c||(r=i>0?i:1),l||(i=r>0?r:1),s===0)for(let f=e;f<=n;f++){let u=t[f];if(u&&u.type==="insert"){r=u.newLineNo>1?u.newLineNo-1:0;break}}if(o===0)for(let f=e;f<=n;f++){let u=t[f];if(u&&u.type==="delete"){i=u.oldLineNo>1?u.oldLineNo-1:0;break}}return{oldStart:r,oldCount:s,newStart:i,newCount:o,lines:a}}function xe(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function Ts(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=xe(e),r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i&&xe(i.path)===n){r=s;break}}return t.splice(r,1)[0]}var Ss=50;async function me(t,e,n=Ss){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=Ts(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 Cs(t,l,c,n);if(f.length>0){let u=new Set(f.map(h=>h.oldPath)),d=new Set(f.map(h=>h.newPath));l=l.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...f)}}if(l.length>0&&c.length>0){let f=await As(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 Cs(t,e,n,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let l=xe(c.path);s.has(l)?s.set(l,-1):s.set(l,a)}let i=new Map;for(let a=0;a<n.length;a++){let c=n[a];if(!c)continue;let l=xe(c.path);i.has(l)?i.set(l,-1):i.set(l,a)}let o=[];for(let[a,c]of s){if(c===-1)continue;let l=i.get(a);if(l===void 0||l===-1)continue;let f=e[c],u=n[l];if(!f?.oldHash||!u?.newHash||f.oldHash===u.newHash)continue;let d=await re(t,f.oldHash),h=await re(t,u.newHash),m=vs(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 Rn=107927;function Ye(t){let e=new Map,n=0,r=0,s=0;for(let o=0;o<t.length;o++){let a=t[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let l=(r+Math.imul(s,97))%Rn;e.set(l,(e.get(l)??0)+n),n=0,r=0,s=0}if(n>0){let o=(r+Math.imul(s,97))%Rn;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 js(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 vs(t,e){return t.length===0&&e.length===0?100:t.length===0||e.length===0?0:Pn(t.length,Ye(t),e.length,Ye(e))}function Pn(t,e,n,r){let s=Math.max(t,n),i=Math.min(t,n);if(i<s-i)return 0;let{srcCopied:o}=js(e,r);return Math.floor(o*100/s)}async function As(t,e,n,r){let s=[];for(let f of e)if(f.oldHash){let u=await re(t,f.oldHash);s.push({size:u.length,chunks:Ye(u)})}else s.push(null);let i=[];for(let f of n)if(f.newHash){let u=await re(t,f.newHash);i.push({size:u.length,chunks:Ye(u)})}else i.push(null);let o=[];for(let f=0;f<e.length;f++){let u=e[f],d=s[f];if(!(!u||!d))for(let h=0;h<n.length;h++){let m=n[h],g=i[h];if(!m||!g)continue;let p=Pn(d.size,d.chunks,g.size,g.chunks);if(p>=r){let b=xe(u.path)===xe(m.path)?1:0;o.push({similarity:p,nameScore:b,delIdx:f,addIdx:h})}}}o.sort((f,u)=>u.similarity-f.similarity||u.nameScore-f.nameScore);let a=new Set,c=new Set,l=[];for(let{similarity:f,delIdx:u,addIdx:d}of o){if(a.has(u)||c.has(d))continue;a.add(u),c.add(d);let h=e[u],m=n[d];!h||!m||l.push({oldPath:h.path,newPath:m.path,oldHash:h.oldHash??"",newHash:m.newHash??"",similarity:f,oldMode:h.oldMode,newMode:m.newMode})}return l}async function ue(t,e,n){return(await le(t,e)).get(n)?.hash??null}async function kn(t,e,n,r){let s=await oe(t,e,n);if(!s.find(c=>c.status==="added"&&c.path===r))return null;let{renames:o}=await me(t,s);return o.find(c=>c.newPath===r)?.oldPath??null}async function $s(t,e,n,r,s,i){let o=await ue(t,(await v(t,e)).tree,n);if(!o){let g=new Map,p=await v(t,e);for(let b of r)g.set(b.finalIdx,he(e,n,b.currentLine,i+b.finalIdx,s[b.finalIdx],p,!1,void 0));return g}let a=await H(t,o),c=te(a),l=new Array(s.length),f=[...r],u=e,d=n,h=c;for(;f.length>0;){let g=await v(t,u);if(g.parents.length===0){for(let E of f)l[E.finalIdx]=he(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],g,!0,void 0);break}let p=await ue(t,g.tree,d),b=null,R=[];for(let E of g.parents){let P=await v(t,E),T=d,$=await ue(t,P.tree,T);if(!$){let D=await kn(t,P.tree,g.tree,d);D&&(T=D,$=await ue(t,P.tree,T))}if($&&(R.push({hash:E,path:T,blobHash:$}),$===p)){b={hash:E,path:T};break}}if(b){u=b.hash,d=b.path;continue}if(R.length===0){for(let E of f)l[E.finalIdx]=he(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],g,!1,void 0);break}let j=R[0],A=await H(t,j.blobHash),O=te(A),w=Ee(O,h),x=new Map;for(let E of w)E.type==="keep"&&x.set(E.newLineNo,E.oldLineNo);let S=[];for(let E of f){let P=x.get(E.currentLine);P!==void 0?S.push({finalIdx:E.finalIdx,currentLine:P}):l[E.finalIdx]=he(u,d,E.currentLine,i+E.finalIdx,s[E.finalIdx],g,!1,{hash:j.hash,path:j.path})}f=S,u=j.hash,d=j.path,h=O}let m=new Map;for(let g of r)l[g.finalIdx]&&m.set(g.finalIdx,l[g.finalIdx]);return m}async function Tn(t,e,n,r){let s=await v(t,e),i=await ue(t,s.tree,n);if(!i)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let o=await H(t,i),a=te(o),c=r?.startLine??1,l=r?.endLine??a.length,f=a.slice(c-1,l),u=new Array(f.length),d=f.map((p,b)=>({finalIdx:b,currentLine:c+b})),h=e,m=n,g=a;for(;d.length>0;){let p=await v(t,h);if(p.parents.length===0){for(let x of d)u[x.finalIdx]=he(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!0,void 0);break}let b=await ue(t,p.tree,m),R=[],j=null;for(let x of p.parents){let S=await v(t,x),E=m,P=await ue(t,S.tree,E);if(!P){let T=await kn(t,S.tree,p.tree,m);T&&(E=T,P=await ue(t,S.tree,E))}if(P){let T={hash:x,path:E,blobHash:P};if(R.push(T),P===b){j=T;break}}}if(j){h=j.hash,m=j.path;continue}if(R.length===0){for(let x of d)u[x.finalIdx]=he(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!1,void 0);break}if(R.length===1){let x=R[0],S=await H(t,x.blobHash),E=te(S),P=Ee(E,g),T=new Map;for(let D of P)D.type==="keep"&&T.set(D.newLineNo,D.oldLineNo);let $=[];for(let D of d){let ae=T.get(D.currentLine);ae!==void 0?$.push({finalIdx:D.finalIdx,currentLine:ae}):u[D.finalIdx]=he(h,m,D.currentLine,c+D.finalIdx,f[D.finalIdx],p,!1,{hash:x.hash,path:x.path})}d=$,h=x.hash,m=x.path,g=E;continue}let A=[];for(let x of R){let S=await H(t,x.blobHash),E=te(S),P=Ee(E,g),T=new Map;for(let $ of P)$.type==="keep"&&T.set($.newLineNo,$.oldLineNo);A.push({info:x,newToOld:T})}let O=new Map;for(let x of d){let S=!1;for(let E=0;E<A.length;E++){let P=A[E],T=P.newToOld.get(x.currentLine);if(T!==void 0){let $=O.get(E);$||($={info:P.info,lines:[]},O.set(E,$)),$.lines.push({finalIdx:x.finalIdx,currentLine:T}),S=!0;break}}S||(u[x.finalIdx]=he(h,m,x.currentLine,c+x.finalIdx,f[x.finalIdx],p,!1,{hash:R[0].hash,path:R[0].path}))}let w=O.get(0);for(let[x,S]of O){if(x===0)continue;let E=await $s(t,S.info.hash,S.info.path,S.lines,f,c);for(let[P,T]of E)u[P]=T}if(w&&w.lines.length>0){d=w.lines,h=w.info.hash,m=w.info.path;let x=await H(t,w.info.blobHash);g=te(x)}else break}return u}function he(t,e,n,r,s,i,o,a){return{hash:t,origPath:e,origLine:n,finalLine:r,content:s,author:i.author,committer:i.committer,summary:i.message.split(`
13
+ `)[0],boundary:o,previous:a}}var Oe=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),o<r&&this.higher(n[o],n[s])&&(s=o),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*pe(t,e,n){if(n?.topoOrder){yield*Ls(t,e,n);return}let r=await Cn(t,n?.exclude),s=new Set(r),i=new Oe,o=n?.shallowBoundary,a=n?.limit,c=0,l=Array.isArray(e)?e:[e];for(let f of l)s.has(f)||i.push(await qe(t,f));for(;i.size>0;){let f=i.pop();if(s.has(f.hash))continue;if(s.add(f.hash),yield f,a!==void 0&&++c>=a)return;if(o?.has(f.hash))continue;let u=n?.firstParent?f.commit.parents.slice(0,1):f.commit.parents;for(let d of u)if(!s.has(d))try{i.push(await qe(t,d))}catch{}}}async function*Ls(t,e,n){let r=await Cn(t,n?.exclude),s=new Set(r),i=new Oe,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let h of a)s.has(h)||i.push(await qe(t,h));let c=[],l=new Map;for(;i.size>0;){let h=i.pop();if(s.has(h.hash)||(s.add(h.hash),l.set(h.hash,c.length),c.push(h),o?.has(h.hash)))continue;let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of m)if(!s.has(g))try{i.push(await qe(t,g))}catch{}}let f=c.length;if(f===0)return;let u=new Int32Array(f);for(let h of c){let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of m){let p=l.get(g);p!==void 0&&(u[p]=(u[p]??0)+1)}}let d=[];for(let h=f-1;h>=0;h--)u[h]===0&&d.push(h);for(;d.length>0;){let h=d.pop();yield c[h];let m=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let g of m){let p=l.get(g);if(p!==void 0){let b=(u[p]??0)-1;u[p]=b,b===0&&d.push(p)}}}}async function Sn(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let a of pe(t,e))r.add(a.hash);let s=new Set;for await(let a of pe(t,n))s.add(a.hash);let i=0;for(let a of r)s.has(a)||i++;let o=0;for(let a of s)r.has(a)||o++;return{ahead:i,behind:o}}async function Cn(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of pe(t,e))n.add(r.hash);return n}async function qe(t,e){return{hash:e,commit:await v(t,e)}}async function Ms(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let o;try{o=await v(t,i)}catch{continue}for(let a of o.parents)n.has(a)||r.push(a)}return n}async function gt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let o=s[i++];if(o===e)return!0;if(r.has(o))continue;r.add(o);let a;try{a=await v(t,o)}catch{continue}for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function De(t,e,n){if(e===n)return[e];let r=await Ms(t,e),s=[],i=new Set,o=[n],a=0;for(;a<o.length;){let l=o[a++];if(i.has(l))continue;if(i.add(l),r.has(l)){s.push(l);continue}let f;try{f=await v(t,l)}catch{continue}for(let u of f.parents)i.has(u)||o.push(u)}if(s.length<=1)return s;let c=[];for(let l of s){let f=!1;for(let u of s)if(u!==l&&await gt(t,l,u)){f=!0;break}f||c.push(l)}return c.length<=1?c:Ds(t,e,n,c)}async function Ds(t,e,n,r){let s=new Set(r),i=new Set,o=[],a=new Map,c=new Map,l=0,f=[{hash:e,mask:1,seq:l++},{hash:n,mask:2,seq:l++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await v(t,d)).committer.timestamp;return c.set(d,m),m}for(;f.length>0;){let d=0,h=await u(f[0].hash);for(let R=1;R<f.length;R++){let j=f[R],A=await u(j.hash),O=f[d];(A>h||A===h&&j.seq<O.seq)&&(d=R,h=A)}let m=f.splice(d,1)[0],g=a.get(m.hash)??0,p=g|m.mask;if(p===g)continue;if(a.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let b=await v(t,m.hash);for(let R of b.parents)f.push({hash:R,mask:p,seq:l++})}for(let d of r)i.has(d)||o.push(d);return o}async function Hs(t,e){return Q(t,e)}async function Us(t,e,n){return oe(t,e,n)}async function Ns(t,e,n){let r=await v(t,n),s=null;return e&&(s=(await v(t,e)).tree),oe(t,s,r.tree)}async function*Bs(t,e,n){let r=e?[e]:[];for await(let s of pe(t,n,{exclude:r}))yield{hash:s.hash,message:s.commit.message,tree:s.commit.tree,parents:s.commit.parents,author:s.commit.author,committer:s.commit.committer}}async function Gs(t,e,n){return gt(t,e,n)}async function Fs(t,e,n){return De(t,e,n)}async function _s(t,e,n){return Sn(t,e,n)}async function Ws(t,e,n,r){return Tn(t,e,n,r)}function zs(t){return t==="insert"?"+":t==="delete"?"-":" "}function Vs(t){return{oldStart:t.oldStart,oldCount:t.oldCount,newStart:t.newStart,newCount:t.newCount,lines:t.lines.map(e=>zs(e.type)+e.content)}}function jn(t,e,n){let r=te(t),s=te(e),i=Ee(r,s);return On(i,n).map(Vs)}async function vn(t,e){let n=await _e(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function Ks(t,e,n,r){let s=await vn(t,e),i=await vn(t,n),o=await v(t,s),a=await v(t,i),c=await oe(t,o.tree,a.tree),l=r?.renames!==!1,f=r?.contextLines,u=r?.paths,d=[];if(l){let m=await me(t,c);c=m.remaining,d=m.renames}let h=[];for(let m of c){if(u&&!u.some(R=>m.path.startsWith(R)))continue;let g=m.oldHash?await H(t,m.oldHash):"",p=m.newHash?await H(t,m.newHash):"",b=jn(g,p,f);h.push({path:m.path,status:m.status,hunks:b})}for(let m of d){if(u&&!u.some(R=>m.newPath.startsWith(R)||m.oldPath.startsWith(R)))continue;let g=await H(t,m.oldHash),p=await H(t,m.newHash),b=jn(g,p,f);h.push({path:m.newPath,status:"renamed",oldPath:m.oldPath,similarity:m.similarity,hunks:b})}return h.sort((m,g)=>m.path.localeCompare(g.path)),h}async function*Ys(t,e,n){if(n?.paths&&n.paths.length>0){let r=n?.limit,s=0;for await(let i of qs(t,e,n.paths,n))if(yield i,r!==void 0&&++s>=r)return;return}for await(let r of pe(t,e,n))yield{hash:r.hash,message:r.commit.message,tree:r.commit.tree,parents:r.commit.parents,author:r.commit.author,committer:r.commit.committer}}function yt(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("/")?n:n+"/"))}async function*qs(t,e,n,r){let s=new Set;if(r?.exclude)for await(let l of pe(t,r.exclude))s.add(l.hash);let i=new Set(s),o=new Oe,a=async l=>{if(!i.has(l))try{let f=await v(t,l);o.push({hash:l,commit:f})}catch{}},c=Array.isArray(e)?e:[e];for(let l of c)await a(l);for(;o.size>0;){let l=o.pop();if(i.has(l.hash))continue;i.add(l.hash);let{commit:f}=l,u=r?.firstParent?f.parents.slice(0,1):f.parents,d=()=>({hash:l.hash,message:f.message,tree:f.tree,parents:f.parents,author:f.author,committer:f.committer});if(u.length===0){(await oe(t,null,f.tree)).some(g=>yt(g.path,n))&&(yield d());continue}if(u.length===1){let m=u[0];try{let g=await v(t,m);(await oe(t,g.tree,f.tree)).some(b=>yt(b.path,n))&&(yield d())}catch{yield d()}await a(m);continue}let h=[];for(let m of u)try{let g=await v(t,m);(await oe(t,g.tree,f.tree)).some(b=>yt(b.path,n))||h.push(m)}catch{}if(h.length>0)await a(h[0]);else{yield d();for(let m of u)await a(m)}}}function Xs(t){let e=Math.abs(t),n=t<=0?"+":"-",r=String(Math.floor(e/60)).padStart(2,"0"),s=String(e%60).padStart(2,"0");return`${n}${r}${s}`}function He(t){if("timestamp"in t)return t;let e=t.date??new Date;return{name:t.name,email:t.email,timestamp:Math.floor(e.getTime()/1e3),timezone:Xs(e.getTimezoneOffset())}}async function Zs(t,e){let n=He(e.author),r=e.committer?He(e.committer):n,s=Ae({type:"commit",tree:e.tree,parents:e.parents,author:n,committer:r,message:e.message}),i=await B(t,"commit",s);return e.branch&&await Ln(t,e.branch,i),i}async function Js(t,e){let n=He(e.tagger),r=Zt({type:"tag",object:e.target,objectType:e.targetType??"commit",name:e.name,tagger:n,message:e.message}),s=await B(t,"tag",r);return await t.refStore.writeRef(`refs/tags/${e.name}`,{type:"direct",hash:s}),s}async function $n(t,e){let n=e.branch?`refs/heads/${e.branch}`:null,r=n?await J(t,n):null,s=null;r&&(s=(await v(t,r)).tree);let i=[];for(let[d,h]of Object.entries(e.files))if(h===null)i.push({path:d,hash:null});else{let m=typeof h=="string"?new TextEncoder().encode(h):h,g=await B(t,"blob",m);i.push({path:d,hash:g})}let o;s?o=await Mn(t,s,i):o=await wt(t,null,bt(i));let a=He(e.author),c=e.committer?He(e.committer):a,f=Ae({type:"commit",tree:o,parents:r?[r]:[],author:a,committer:c,message:e.message});return{hash:await B(t,"commit",f),parentHash:r}}async function Qs(t,e){let{hash:n}=await $n(t,e);return await Ln(t,e.branch,n),n}async function Ln(t,e,n){let r=`refs/heads/${e}`;await t.refStore.writeRef(r,{type:"direct",hash:n}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:r})}async function ei(t,e){let n=[...e].sort((i,o)=>i.name.localeCompare(o.name)),r=await Promise.all(n.map(async i=>{let o=i.mode;return o||(o=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:o,name:i.name,hash:i.hash}})),s=Le({type:"tree",entries:r});return B(t,"tree",s)}async function ti(t,e){return B(t,"blob",new TextEncoder().encode(e))}async function Mn(t,e,n){return wt(t,e,bt(n))}function bt(t){let e=new Map,n=new Map;for(let r of t){let s=r.path.indexOf("/");if(s===-1)e.set(r.path,{hash:r.hash,mode:r.mode??"100644"});else{let i=r.path.slice(0,s),o=r.path.slice(s+1),a=n.get(i);a||(a=[],n.set(i,a)),a.push({...r,path:o})}}return{files:e,dirs:n}}async function An(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return se(n.content).entries}async function wt(t,e,n){let r=new Map;if(e)for(let o of await An(t,e))r.set(o.name,o);for(let[o,{hash:a,mode:c}]of n.files)a===null?r.delete(o):r.set(o,{name:o,hash:a,mode:c});for(let[o,a]of n.dirs){let c=r.get(o),l=c?.mode==="040000"?c.hash:null,f=bt(a),u=await wt(t,l,f);(await An(t,u)).length===0?r.delete(o):r.set(o,{name:o,hash:u,mode:"040000"})}let s=[...r.values()].sort((o,a)=>{let c=o.mode==="040000"?`${o.name}/`:o.name,l=a.mode==="040000"?`${a.name}/`:a.name;return c<l?-1:c>l?1:0}),i=Le({type:"tree",entries:s});return B(t,"tree",i)}function It(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}=pt(t,e);return ni(s,n,i,r)}function ni(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 ri(t,e,n){let r=[];for(let c of It(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 It(e,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,l)=>c.oStart-l.oStart);let s=[],i=0;function o(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let a=0;for(;a<r.length;){let c=r[a++],l=c.oStart,f=c.oStart+c.oLength,u=[c];for(o(l);a<r.length;){let d=r[a];if(d.oStart>f)break;f=Math.max(f,d.oStart+d.oLength),u.push(d),a++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?t:n;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:d.slice(c.abStart,c.abStart+c.abLength)})}}else{let d={a:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let b of u){let R=b.oStart,j=R+b.oLength,A=b.abStart,O=A+b.abLength,w=d[b.ab];w.abMin=Math.min(A,w.abMin),w.abMax=Math.max(O,w.abMax),w.oMin=Math.min(R,w.oMin),w.oMax=Math.max(j,w.oMax)}let h=d.a.abMin+(l-d.a.oMin),m=d.a.abMax+(f-d.a.oMax),g=d.b.abMin+(l-d.b.oMin),p=d.b.abMax+(f-d.b.oMax);s.push({stable:!1,a:t.slice(h,m),o:e.slice(l,f),b:n.slice(g,p)})}i=f}return o(e.length),s}function si(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=ri(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&&Hn(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"?Dn(o):Dn(ii(o))}function Ue(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",o=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),l=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,f=si(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 ii(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...oi(n));return e}function oi(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(Hn(e,n))return[t];let r=It(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 Dn(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.length-1],i=e[r];if(s.type==="conflict"&&i.type==="ok"&&i.lines.length<=3&&r+1<e.length&&e[r+1].type==="conflict"){let o=e[r+1],a=s;a.a=[...s.a,...i.lines,...o.a],a.b=[...s.b,...i.lines,...o.b],a.o=[...s.o,...i.lines,...o.o],r++}else n.push(i)}return n}function ge(t,e,n,r){let s=Ue(Y(t),Y(e),Y(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(Et);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
14
14
  `)}
15
15
  `:a.join(`
16
16
  `)}function Y(t){if(t==="")return[];let e=t.split(`
17
- `);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function It(t){return t.endsWith("\0")?t.slice(0,-1):t}function Mn(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}var Re=new TextDecoder,de=new TextEncoder,Dn={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function Pe(t,e,n,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await si(t,e,n,r),l=await oi(t,i,o,a,c,s);return ai(t,i,s,l)}async function _n(t,e,n,r){let s=await De(t,e,n),i=await v(t,e),o=await v(t,n);if(s.length===0)return{...await Pe(t,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let l=await v(t,s[0]);return{...await Pe(t,l.tree,i.tree,o.tree,r),baseTree:l.tree}}let a=await zn(t,e,n,s,1);return{...await Pe(t,a,i.tree,o.tree,r),baseTree:a}}async function si(t,e,n,r){let s=await le(t,e),i=await le(t,n),o=await le(t,r),a=new Set;for(let l of s.keys())a.add(l);for(let l of i.keys())a.add(l);for(let l of o.keys())a.add(l);let c=new Map;for(let l of a){let f=s.get(l)??null,u=i.get(l)??null,d=o.get(l)??null,h=f?{hash:f.hash,mode:f.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,g=d?{hash:d.hash,mode:d.mode}:null,p=(f?1:0)|(u?2:0)|(d?4:0),b=f?.hash??null,R=u?.hash??null,j=d?.hash??null,A=0;b!==null&&b===R&&(A|=3),b!==null&&b===j&&(A|=5),R!==null&&R===j&&(A|=6);let O={path:l,stages:[h,m,g],pathnames:[l,l,l],filemask:p,matchMask:A,merged:{result:null,clean:!1},pathConflict:!1};if(ii(O)){c.set(l,O);continue}c.set(l,O)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function ii(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,o=r?.hash??null;return i===s&&o===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===o&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&o===null?(t.merged={result:null,clean:!0},!0):o===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?t.merged={result:{hash:o,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function oi(t,e,n,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[I,y]of n)r.has(I)||a.push({path:I,status:"deleted",oldHash:y.hash,oldMode:y.mode}),s.has(I)||c.push({path:I,status:"deleted",oldHash:y.hash,oldMode:y.mode});for(let[I,y]of r)n.has(I)||a.push({path:I,status:"added",newHash:y.hash,newMode:y.mode});for(let[I,y]of s)n.has(I)||c.push({path:I,status:"added",newHash:y.hash,newMode:y.mode});let l=await me(t,a),f=await me(t,c);if(l.renames.length===0&&f.renames.length===0)return o;let u=new Map,d=new Map;for(let I of l.renames)u.set(I.oldPath,I);for(let I of f.renames)d.set(I.oldPath,I);let h=new Set;for(let[I]of r)!n.has(I)&&s.has(I)&&h.add(I);let m=new Set,g=i?.a??"HEAD",p=i?.b??"theirs";function b(I,y,k=0){o.msgBuf.push({sortKey:I,subOrder:k,text:y})}for(let I of[...n.keys()].sort()){let y=u.get(I),k=d.get(I);if(!y&&!k)continue;let M=n.get(I);if(m.add(I),y&&k)if(m.add(y.newPath),m.add(k.newPath),y.newPath===k.newPath){let L=r.get(y.newPath),C=s.get(k.newPath);if(L.hash===C.hash)o.entries.push(V(y.newPath,L));else{let N=Et(e,y.newPath);N.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],N.pathnames=[I,y.newPath,k.newPath],N.filemask=7,N.merged={result:null,clean:!1}}}else{let L=r.get(y.newPath),C=s.get(k.newPath),N=await Wn(t,M,L,C,i);N.conflict&&b(I,`Auto-merging ${I}`,-1),o.conflicts.push({path:I,reason:"rename-rename",oursPath:y.newPath,theirsPath:k.newPath}),b(I,`CONFLICT (rename/rename): ${I} renamed to ${y.newPath} in ${g} and to ${k.newPath} in ${p}.`),o.entries.push(V(I,M,1)),o.entries.push(W(y.newPath,L.mode,N.hash,2)),o.entries.push(W(k.newPath,C.mode,N.hash,3)),o.worktreeBlobs.set(y.newPath,{hash:N.hash,mode:L.mode}),o.worktreeBlobs.set(k.newPath,{hash:N.hash,mode:C.mode})}else if(y){m.add(y.newPath);let L=s.get(I),C=r.get(y.newPath),N=h.has(y.newPath);if(L)if(N)await Fn(t,o,y.newPath,I,M,C,L,r,s,!1,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(V(y.newPath,C));else if(L.hash===M.hash)o.entries.push(V(y.newPath,C));else if(C.hash===M.hash)o.entries.push(W(y.newPath,C.mode,L.hash));else{let G=Et(e,y.newPath);G.stages=[{hash:M.hash,mode:M.mode},{hash:C.hash,mode:C.mode},{hash:L.hash,mode:L.mode}],G.pathnames=[I,y.newPath,I],G.filemask=7,G.merged={result:null,clean:!1}}else{let G=s.get(y.newPath);if(o.conflicts.push({path:y.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:I}),b(y.newPath,`CONFLICT (rename/delete): ${I} renamed to ${y.newPath} in ${g}, but deleted in ${p}.`),G){o.conflicts.push({path:y.newPath,reason:"add-add"}),b(y.newPath,`Auto-merging ${y.newPath}`,0),b(y.newPath,`CONFLICT (add/add): Merge conflict in ${y.newPath}`,1),o.entries.push(V(y.newPath,C,2)),o.entries.push(V(y.newPath,G,3));let Je=await Xe(t,C.hash,G.hash,C.mode,i);o.worktreeBlobs.set(y.newPath,{hash:Je,mode:C.mode})}else o.entries.push(W(y.newPath,M.mode,M.hash,1)),o.entries.push(V(y.newPath,C,2)),o.worktreeBlobs.set(y.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&b(y.newPath,`CONFLICT (modify/delete): ${y.newPath} deleted in ${p} and modified in ${g}. Version ${g} of ${y.newPath} left in tree.`,1)}}else if(k){m.add(k.newPath);let L=r.get(I),C=s.get(k.newPath),N=h.has(k.newPath);if(L)if(N)await Fn(t,o,k.newPath,I,M,L,C,r,s,!0,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(V(k.newPath,C));else if(L.hash===M.hash)o.entries.push(V(k.newPath,C));else if(C.hash===M.hash)o.entries.push(W(k.newPath,C.mode,L.hash));else{let G=Et(e,k.newPath);G.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],G.pathnames=[I,I,k.newPath],G.filemask=7,G.merged={result:null,clean:!1}}else{let G=r.get(k.newPath);if(o.conflicts.push({path:k.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:I}),b(k.newPath,`CONFLICT (rename/delete): ${I} renamed to ${k.newPath} in ${p}, but deleted in ${g}.`),G){o.conflicts.push({path:k.newPath,reason:"add-add"}),b(k.newPath,`Auto-merging ${k.newPath}`,0),b(k.newPath,`CONFLICT (add/add): Merge conflict in ${k.newPath}`,1),o.entries.push(V(k.newPath,G,2)),o.entries.push(V(k.newPath,C,3));let Je=await Xe(t,G.hash,C.hash,G.mode,i);o.worktreeBlobs.set(k.newPath,{hash:Je,mode:G.mode})}else o.entries.push(W(k.newPath,M.mode,M.hash,1)),o.entries.push(V(k.newPath,C,3)),o.worktreeBlobs.set(k.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&b(k.newPath,`CONFLICT (modify/delete): ${k.newPath} deleted in ${g} and modified in ${p}. Version ${p} of ${k.newPath} left in tree.`,1)}}}let R=new Set(l.renames.map(I=>I.newPath)),j=new Set(f.renames.map(I=>I.newPath)),A=Hn(n,r),O=Hn(n,s),w=Un(A,s,n),x=Un(O,r,n),S=Nn(l.renames,w),E=Nn(f.renames,x),P=Bn(S),T=Bn(E);for(let I of[...P.keys()])T.has(I)&&(P.delete(I),T.delete(I));let $=new Set(P.keys()),D=new Set(T.keys());if(T.size>0)for(let I of a){if(I.status!=="added"||R.has(I.path))continue;let y=Gn(I.path,T,$);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||s.has(y)){if(r.has(y)){b(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let L=r.get(I.path),C=s.get(y)??n.get(y);o.entries.push(W(y,L.mode,L.hash,2)),C&&o.entries.push(W(y,C.mode,C.hash,3)),o.worktreeBlobs.set(y,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:y,reason:"add-add"}),b(y,`CONFLICT (file location): ${I.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${y}.`,1);let N=e.get(I.path);N&&(N.merged={result:null,clean:!0}),m.add(I.path);continue}let k=r.get(I.path);o.entries.push(W(y,k.mode,k.hash,2)),o.worktreeBlobs.set(y,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),b(y,`CONFLICT (file location): ${I.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${y}.`,1);let M=e.get(I.path);M&&(M.merged={result:null,clean:!0}),m.add(I.path)}if(P.size>0)for(let I of c){if(I.status!=="added"||j.has(I.path))continue;let y=Gn(I.path,P,D);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||s.has(y)){if(s.has(y)){b(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let L=s.get(I.path),C=r.get(y)??n.get(y);C&&o.entries.push(W(y,C.mode,C.hash,2)),o.entries.push(W(y,L.mode,L.hash,3)),o.worktreeBlobs.set(y,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:y,reason:"add-add"}),b(y,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${y}.`,1);let N=e.get(I.path);N&&(N.merged={result:null,clean:!0}),m.add(I.path);continue}let k=s.get(I.path);o.entries.push(W(y,k.mode,k.hash,3)),o.worktreeBlobs.set(y,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),b(y,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${y}.`,1);let M=e.get(I.path);M&&(M.merged={result:null,clean:!0}),m.add(I.path)}let ae=new Set(o.entries.map(I=>I.path));for(let I of ae){let y=e.get(I);y&&(y.merged={result:null,clean:!0})}for(let I of m){if(ae.has(I))continue;let y=e.get(I);if(!y||y.merged.clean)continue;y.filemask===7&&!y.pathConflict||(y.merged={result:null,clean:!0})}return o}function Hn(t,e){let n=new Set;for(let i of t.keys()){let o=q(i);for(;o;)n.add(o),o=q(o)}let r=new Set;for(let i of e.keys()){let o=q(i);for(;o;)r.add(o),o=q(o)}let s=new Set;for(let i of n)r.has(i)||s.add(i);return s}function Un(t,e,n){if(t.size===0)return t;let r=new Set;for(let s of e.keys()){if(n.has(s))continue;let i=q(s)??"";t.has(i)&&r.add(i)}for(let s of[...r]){let i=q(s);for(;i;)t.has(i)&&!r.has(i)&&r.add(i),i=q(i)}return r}function Nn(t,e){let n=new Map;for(let r of t){let s=q(r.oldPath),i=q(r.newPath),o=!0;for(;;){if(!o){let a=s.length+(s?1:0),c=i.length+(i?1:0),l=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),f=r.newPath.slice(c,r.newPath.indexOf("/",c));if(l!==f)break}if(e.has(s)){let a=n.get(s);a||(a=new Map,n.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=q(s),i=q(i)}}return n}function Bn(t){let e=new Map;for(let[n,r]of t){let s=0,i=0,o=null;for(let[a,c]of r)c===s?i=s:c>s&&(s=c,o=a);s>0&&i!==s&&o!==null&&e.set(n,o)}return e}function Gn(t,e,n){let r=q(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let o=t.slice(r.length+1);return i?`${i}/${o}`:o}r=q(r)}let s=e.get("");return s!==void 0&&!n.has(s)?`${s}/${t}`:null}function q(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function Fn(t,e,n,r,s,i,o,a,c,l=!1,f){let u=l?a.get(n):c.get(n),d=l?o:i;if(u.hash===d.hash){e.entries.push(W(n,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await Wn(t,s,i,o,f,l?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(W(n,u.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),l){e.entries.push(V(n,u,2)),e.entries.push(W(n,o.mode,m.hash,3));let g=await Xe(t,u.hash,m.hash,u.mode,f);e.worktreeBlobs.set(n,{hash:g,mode:u.mode})}else{e.entries.push(W(n,i.mode,m.hash,2)),e.entries.push(V(n,u,3));let g=await Xe(t,m.hash,u.hash,i.mode,f);e.worktreeBlobs.set(n,{hash:g,mode:i.mode})}}async function Wn(t,e,n,r,s,i,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(ie(e.mode)||ie(n.mode)||ie(r.mode))return{hash:n.hash,conflict:!0};let a=await H(t,e.hash),c=await H(t,n.hash),l=await H(t,r.hash);if(ne(c)||ne(l)||ne(a))return{hash:n.hash,conflict:!0};let f=Y(a),u=Y(c),d=Y(l),h=s?.conflictStyle,m=Ue(u,f,d,{conflictStyle:h});if(!m.conflict)return{hash:await xt(t,m.result),conflict:!1};let g=s?.a??"HEAD",p=s?.b??"theirs",b=i?.oursPath?`${g}:${i.oursPath}`:g,R=i?.theirsPath?`${p}:${i.theirsPath}`:p,j=ge(c,a,l,{a:b,b:R,markerSize:o??7,conflictStyle:h});return{hash:await B(t,"blob",de.encode(j)),conflict:!0}}async function Xe(t,e,n,r,s){let i=await H(t,e),o=await H(t,n),a=ge(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return B(t,"blob",de.encode(a))}function V(t,e,n=0){return W(t,e.mode,e.hash,n)}function W(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:ce()}}async function ai(t,e,n,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,g=0){o.push({sortKey:h,subOrder:g,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(U(h,m.merged.result.hash,m.merged.result.mode));continue}await ci(t,m,n,s,i,c,a)}o.sort((h,m)=>(h.sortKey<m.sortKey?-1:h.sortKey>m.sortKey?1:0)||h.subOrder-m.subOrder);let l=o.map(h=>h.text),f=[],u=new Set;for(let h of s)h.stage===0&&(f.push(h),u.add(h.path));for(let[h,m]of a)u.has(h)||f.push(U(h,m.hash,m.mode));f.sort((h,m)=>Me(h.path,m.path));let d=await ft(t,f);return{entries:s,conflicts:i,messages:l,resultTree:d}}async function ci(t,e,n,r,s,i,o){let a=e.path,[c,l,f]=e.stages,u=c?.hash??null,d=l?.hash??null,h=f?.hash??null;if(d===null&&h!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=n?.a??"HEAD",g=n?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${g}. Version ${g} of ${a} left in tree.`),c&&r.push(U(a,u,c.mode,1)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:h,mode:f.mode});return}if(h===null&&d!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=n?.b??"theirs",g=n?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${g}. Version ${g} of ${a} left in tree.`),c&&r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),o.set(a,{hash:d,mode:l.mode});return}if(u===null&&d!==null&&h!==null){if(d===h){r.push(U(a,d,l.mode));return}i(a,`Auto-merging ${a}`,0);let m=await H(t,d),g=await H(t,h);if(ne(m)||ne(g)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let p=Y(""),b=Y(m),R=Y(g),j=Ue(b,p,R,{conflictStyle:n?.conflictStyle});if(!j.conflict){let w=await xt(t,j.result);r.push(U(a,w,l.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3));let A=ge(m,"",g,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),O=await B(t,"blob",de.encode(A));o.set(a,{hash:O,mode:l.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(U(a,h,f.mode));return}if(h===u){r.push(U(a,d,l.mode));return}if(d===h){r.push(U(a,d,l.mode));return}if(i(a,`Auto-merging ${a}`,0),ie(c.mode)||ie(l.mode)||ie(f.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let m=await H(t,u),g=await H(t,d),p=await H(t,h);if(ne(g)||ne(p)||ne(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let b=Y(m),R=Y(g),j=Y(p),A=Ue(R,b,j,{conflictStyle:n?.conflictStyle});if(A.conflict){let O=e.pathnames[1],w=e.pathnames[2],x=O!==a||w!==a,S={path:a,reason:"content"};x&&(O!==a&&(S.oursOrigPath=O),w!==a&&(S.theirsOrigPath=w)),s.push(S),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3));let E=x?`${n?.a??"HEAD"}:${O}`:n?.a??"HEAD",P=x?`${n?.b??"theirs"}:${w}`:n?.b??"theirs",T=ge(g,m,p,{a:E,b:P,conflictStyle:n?.conflictStyle}),$=await B(t,"blob",de.encode(T));o.set(a,{hash:$,mode:l.mode})}else{let O=await xt(t,A.result);r.push(U(a,O,l.mode))}return}}var li=200;async function zn(t,e,n,r,s){let i=await Promise.all(r.map(async f=>({hash:f,timestamp:(await v(t,f)).committer.timestamp})));i.sort((f,u)=>f.timestamp-u.timestamp);let o=i.map(f=>f.hash),a=o[0],c=a,l=(await v(t,a)).tree;for(let f=1;f<o.length;f++){let u=o[f],d=(await v(t,u)).tree,h=null;if(s>=li)h=l;else{let p=await De(t,c,u);p.length===0?h=null:p.length===1?h=(await v(t,p[0])).tree:h=await zn(t,c,u,p,s+1)}let m=await Pe(t,h,l,d);l=await fi(t,m,s);let g=Ae({type:"commit",tree:l,parents:[c,u],author:Dn,committer:Dn,message:"merged common ancestors"});c=await B(t,"commit",g)}return l}async function fi(t,e,n){let r=e.entries.filter(a=>a.stage===0),s=new Map;for(let a of e.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let i=(a,c)=>s.get(`${a}\0${c}`),o={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let f=i(a.path,1);if(f){r.push({...f,stage:0});continue}}if(a.reason==="rename-rename"){let f=a.oursPath??a.path,u=a.theirsPath??a.path,d=i(a.path,1),h=i(f,2),m=i(u,3);if(h&&m){let g=Re.decode((await F(t,h.hash)).content),p=Re.decode((await F(t,m.hash)).content),b=d?Re.decode((await F(t,d.hash)).content):"",R=8+n*2,j=o.a??"Temporary merge branch 1",A=o.b??"Temporary merge branch 2",O=ge(g,b,p,{a:`${j}:${f}`,o:o.o,b:`${A}:${u}`,markerSize:R}),w=await B(t,"blob",de.encode(O));r.push({path:f,mode:h.mode,hash:w,stage:0,stat:ce()}),r.push({path:u,mode:m.mode,hash:w,stage:0,stat:ce()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(a.path,2),l=i(a.path,3);if(c&&l&&(a.reason==="content"||a.reason==="add-add")){let f=Re.decode((await F(t,c.hash)).content),u=Re.decode((await F(t,l.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?Re.decode((await F(t,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,g=o.a??"Temporary merge branch 1",p=o.b??"Temporary merge branch 2",b=m?`${g}:${a.oursOrigPath??a.path}`:g,R=m?`${p}:${a.theirsOrigPath??a.path}`:p,j=ge(f,h,u,{a:b,o:o.o,b:R,markerSize:o.markerSize}),A=await B(t,"blob",de.encode(j));r.push({path:a.path,mode:c.mode,hash:A,stage:0,stat:ce()})}else c?r.push({...c,stage:0}):l&&r.push({...l,stage:0})}return r.sort((a,c)=>Me(a.path,c.path)),ft(t,r)}async function xt(t,e){let n=e.map(It);if(n.length===0)return B(t,"blob",de.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?n.join(`
17
+ `);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function Et(t){return t.endsWith("\0")?t.slice(0,-1):t}function Hn(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}var Re=new TextDecoder,de=new TextEncoder,Un={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function Pe(t,e,n,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await ai(t,e,n,r),l=await li(t,i,o,a,c,s);return fi(t,i,s,l)}async function zn(t,e,n,r){let s=await De(t,e,n),i=await v(t,e),o=await v(t,n);if(s.length===0)return{...await Pe(t,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let l=await v(t,s[0]);return{...await Pe(t,l.tree,i.tree,o.tree,r),baseTree:l.tree}}let a=await Kn(t,e,n,s,1);return{...await Pe(t,a,i.tree,o.tree,r),baseTree:a}}async function ai(t,e,n,r){let s=await le(t,e),i=await le(t,n),o=await le(t,r),a=new Set;for(let l of s.keys())a.add(l);for(let l of i.keys())a.add(l);for(let l of o.keys())a.add(l);let c=new Map;for(let l of a){let f=s.get(l)??null,u=i.get(l)??null,d=o.get(l)??null,h=f?{hash:f.hash,mode:f.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,g=d?{hash:d.hash,mode:d.mode}:null,p=(f?1:0)|(u?2:0)|(d?4:0),b=f?.hash??null,R=u?.hash??null,j=d?.hash??null,A=0;b!==null&&b===R&&(A|=3),b!==null&&b===j&&(A|=5),R!==null&&R===j&&(A|=6);let O={path:l,stages:[h,m,g],pathnames:[l,l,l],filemask:p,matchMask:A,merged:{result:null,clean:!1},pathConflict:!1};if(ci(O)){c.set(l,O);continue}c.set(l,O)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function ci(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 li(t,e,n,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[I,y]of n)r.has(I)||a.push({path:I,status:"deleted",oldHash:y.hash,oldMode:y.mode}),s.has(I)||c.push({path:I,status:"deleted",oldHash:y.hash,oldMode:y.mode});for(let[I,y]of r)n.has(I)||a.push({path:I,status:"added",newHash:y.hash,newMode:y.mode});for(let[I,y]of s)n.has(I)||c.push({path:I,status:"added",newHash:y.hash,newMode:y.mode});let l=await me(t,a),f=await me(t,c);if(l.renames.length===0&&f.renames.length===0)return o;let u=new Map,d=new Map;for(let I of l.renames)u.set(I.oldPath,I);for(let I of f.renames)d.set(I.oldPath,I);let h=new Set;for(let[I]of r)!n.has(I)&&s.has(I)&&h.add(I);let m=new Set,g=i?.a??"HEAD",p=i?.b??"theirs";function b(I,y,k=0){o.msgBuf.push({sortKey:I,subOrder:k,text:y})}for(let I of[...n.keys()].sort()){let y=u.get(I),k=d.get(I);if(!y&&!k)continue;let M=n.get(I);if(m.add(I),y&&k)if(m.add(y.newPath),m.add(k.newPath),y.newPath===k.newPath){let L=r.get(y.newPath),C=s.get(k.newPath);if(L.hash===C.hash)o.entries.push(V(y.newPath,L));else{let N=xt(e,y.newPath);N.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],N.pathnames=[I,y.newPath,k.newPath],N.filemask=7,N.merged={result:null,clean:!1}}}else{let L=r.get(y.newPath),C=s.get(k.newPath),N=await Vn(t,M,L,C,i);N.conflict&&b(I,`Auto-merging ${I}`,-1),o.conflicts.push({path:I,reason:"rename-rename",oursPath:y.newPath,theirsPath:k.newPath}),b(I,`CONFLICT (rename/rename): ${I} renamed to ${y.newPath} in ${g} and to ${k.newPath} in ${p}.`),o.entries.push(V(I,M,1)),o.entries.push(W(y.newPath,L.mode,N.hash,2)),o.entries.push(W(k.newPath,C.mode,N.hash,3)),o.worktreeBlobs.set(y.newPath,{hash:N.hash,mode:L.mode}),o.worktreeBlobs.set(k.newPath,{hash:N.hash,mode:C.mode})}else if(y){m.add(y.newPath);let L=s.get(I),C=r.get(y.newPath),N=h.has(y.newPath);if(L)if(N)await Wn(t,o,y.newPath,I,M,C,L,r,s,!1,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(V(y.newPath,C));else if(L.hash===M.hash)o.entries.push(V(y.newPath,C));else if(C.hash===M.hash)o.entries.push(W(y.newPath,C.mode,L.hash));else{let G=xt(e,y.newPath);G.stages=[{hash:M.hash,mode:M.mode},{hash:C.hash,mode:C.mode},{hash:L.hash,mode:L.mode}],G.pathnames=[I,y.newPath,I],G.filemask=7,G.merged={result:null,clean:!1}}else{let G=s.get(y.newPath);if(o.conflicts.push({path:y.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:I}),b(y.newPath,`CONFLICT (rename/delete): ${I} renamed to ${y.newPath} in ${g}, but deleted in ${p}.`),G){o.conflicts.push({path:y.newPath,reason:"add-add"}),b(y.newPath,`Auto-merging ${y.newPath}`,0),b(y.newPath,`CONFLICT (add/add): Merge conflict in ${y.newPath}`,1),o.entries.push(V(y.newPath,C,2)),o.entries.push(V(y.newPath,G,3));let Je=await Xe(t,C.hash,G.hash,C.mode,i);o.worktreeBlobs.set(y.newPath,{hash:Je,mode:C.mode})}else o.entries.push(W(y.newPath,M.mode,M.hash,1)),o.entries.push(V(y.newPath,C,2)),o.worktreeBlobs.set(y.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&b(y.newPath,`CONFLICT (modify/delete): ${y.newPath} deleted in ${p} and modified in ${g}. Version ${g} of ${y.newPath} left in tree.`,1)}}else if(k){m.add(k.newPath);let L=r.get(I),C=s.get(k.newPath),N=h.has(k.newPath);if(L)if(N)await Wn(t,o,k.newPath,I,M,L,C,r,s,!0,i);else if(L.hash===M.hash&&C.hash===M.hash)o.entries.push(V(k.newPath,C));else if(L.hash===M.hash)o.entries.push(V(k.newPath,C));else if(C.hash===M.hash)o.entries.push(W(k.newPath,C.mode,L.hash));else{let G=xt(e,k.newPath);G.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:C.hash,mode:C.mode}],G.pathnames=[I,I,k.newPath],G.filemask=7,G.merged={result:null,clean:!1}}else{let G=r.get(k.newPath);if(o.conflicts.push({path:k.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:I}),b(k.newPath,`CONFLICT (rename/delete): ${I} renamed to ${k.newPath} in ${p}, but deleted in ${g}.`),G){o.conflicts.push({path:k.newPath,reason:"add-add"}),b(k.newPath,`Auto-merging ${k.newPath}`,0),b(k.newPath,`CONFLICT (add/add): Merge conflict in ${k.newPath}`,1),o.entries.push(V(k.newPath,G,2)),o.entries.push(V(k.newPath,C,3));let Je=await Xe(t,G.hash,C.hash,G.mode,i);o.worktreeBlobs.set(k.newPath,{hash:Je,mode:G.mode})}else o.entries.push(W(k.newPath,M.mode,M.hash,1)),o.entries.push(V(k.newPath,C,3)),o.worktreeBlobs.set(k.newPath,{hash:C.hash,mode:C.mode}),C.hash!==M.hash&&b(k.newPath,`CONFLICT (modify/delete): ${k.newPath} deleted in ${g} and modified in ${p}. Version ${p} of ${k.newPath} left in tree.`,1)}}}let R=new Set(l.renames.map(I=>I.newPath)),j=new Set(f.renames.map(I=>I.newPath)),A=Nn(n,r),O=Nn(n,s),w=Bn(A,s,n),x=Bn(O,r,n),S=Gn(l.renames,w),E=Gn(f.renames,x),P=Fn(S),T=Fn(E);for(let I of[...P.keys()])T.has(I)&&(P.delete(I),T.delete(I));let $=new Set(P.keys()),D=new Set(T.keys());if(T.size>0)for(let I of a){if(I.status!=="added"||R.has(I.path))continue;let y=_n(I.path,T,$);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||s.has(y)){if(r.has(y)){b(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let L=r.get(I.path),C=s.get(y)??n.get(y);o.entries.push(W(y,L.mode,L.hash,2)),C&&o.entries.push(W(y,C.mode,C.hash,3)),o.worktreeBlobs.set(y,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:y,reason:"add-add"}),b(y,`CONFLICT (file location): ${I.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${y}.`,1);let N=e.get(I.path);N&&(N.merged={result:null,clean:!0}),m.add(I.path);continue}let k=r.get(I.path);o.entries.push(W(y,k.mode,k.hash,2)),o.worktreeBlobs.set(y,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),b(y,`CONFLICT (file location): ${I.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${y}.`,1);let M=e.get(I.path);M&&(M.merged={result:null,clean:!0}),m.add(I.path)}if(P.size>0)for(let I of c){if(I.status!=="added"||j.has(I.path))continue;let y=_n(I.path,P,D);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||s.has(y)){if(s.has(y)){b(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let L=s.get(I.path),C=r.get(y)??n.get(y);C&&o.entries.push(W(y,C.mode,C.hash,2)),o.entries.push(W(y,L.mode,L.hash,3)),o.worktreeBlobs.set(y,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:y,reason:"add-add"}),b(y,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${y}.`,1);let N=e.get(I.path);N&&(N.merged={result:null,clean:!0}),m.add(I.path);continue}let k=s.get(I.path);o.entries.push(W(y,k.mode,k.hash,3)),o.worktreeBlobs.set(y,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),b(y,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${y}.`,1);let M=e.get(I.path);M&&(M.merged={result:null,clean:!0}),m.add(I.path)}let ae=new Set(o.entries.map(I=>I.path));for(let I of ae){let y=e.get(I);y&&(y.merged={result:null,clean:!0})}for(let I of m){if(ae.has(I))continue;let y=e.get(I);if(!y||y.merged.clean)continue;y.filemask===7&&!y.pathConflict||(y.merged={result:null,clean:!0})}return o}function Nn(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 Bn(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 Gn(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 Fn(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 Wn(t,e,n,r,s,i,o,a,c,l=!1,f){let u=l?a.get(n):c.get(n),d=l?o:i;if(u.hash===d.hash){e.entries.push(W(n,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await Vn(t,s,i,o,f,l?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(W(n,u.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),l){e.entries.push(V(n,u,2)),e.entries.push(W(n,o.mode,m.hash,3));let g=await Xe(t,u.hash,m.hash,u.mode,f);e.worktreeBlobs.set(n,{hash:g,mode:u.mode})}else{e.entries.push(W(n,i.mode,m.hash,2)),e.entries.push(V(n,u,3));let g=await Xe(t,m.hash,u.hash,i.mode,f);e.worktreeBlobs.set(n,{hash:g,mode:i.mode})}}async function Vn(t,e,n,r,s,i,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(ie(e.mode)||ie(n.mode)||ie(r.mode))return{hash:n.hash,conflict:!0};let a=await H(t,e.hash),c=await H(t,n.hash),l=await H(t,r.hash);if(ne(c)||ne(l)||ne(a))return{hash:n.hash,conflict:!0};let f=Y(a),u=Y(c),d=Y(l),h=s?.conflictStyle,m=Ue(u,f,d,{conflictStyle:h});if(!m.conflict)return{hash:await Ot(t,m.result),conflict:!1};let g=s?.a??"HEAD",p=s?.b??"theirs",b=i?.oursPath?`${g}:${i.oursPath}`:g,R=i?.theirsPath?`${p}:${i.theirsPath}`:p,j=ge(c,a,l,{a:b,b:R,markerSize:o??7,conflictStyle:h});return{hash:await B(t,"blob",de.encode(j)),conflict:!0}}async function Xe(t,e,n,r,s){let i=await H(t,e),o=await H(t,n),a=ge(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return B(t,"blob",de.encode(a))}function V(t,e,n=0){return W(t,e.mode,e.hash,n)}function W(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:ce()}}async function fi(t,e,n,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,g=0){o.push({sortKey:h,subOrder:g,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(U(h,m.merged.result.hash,m.merged.result.mode));continue}await ui(t,m,n,s,i,c,a)}o.sort((h,m)=>(h.sortKey<m.sortKey?-1:h.sortKey>m.sortKey?1:0)||h.subOrder-m.subOrder);let l=o.map(h=>h.text),f=[],u=new Set;for(let h of s)h.stage===0&&(f.push(h),u.add(h.path));for(let[h,m]of a)u.has(h)||f.push(U(h,m.hash,m.mode));f.sort((h,m)=>Me(h.path,m.path));let d=await ut(t,f);return{entries:s,conflicts:i,messages:l,resultTree:d}}async function ui(t,e,n,r,s,i,o){let a=e.path,[c,l,f]=e.stages,u=c?.hash??null,d=l?.hash??null,h=f?.hash??null;if(d===null&&h!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=n?.a??"HEAD",g=n?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${g}. Version ${g} of ${a} left in tree.`),c&&r.push(U(a,u,c.mode,1)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:h,mode:f.mode});return}if(h===null&&d!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=n?.b??"theirs",g=n?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${g}. Version ${g} of ${a} left in tree.`),c&&r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),o.set(a,{hash:d,mode:l.mode});return}if(u===null&&d!==null&&h!==null){if(d===h){r.push(U(a,d,l.mode));return}i(a,`Auto-merging ${a}`,0);let m=await H(t,d),g=await H(t,h);if(ne(m)||ne(g)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let p=Y(""),b=Y(m),R=Y(g),j=Ue(b,p,R,{conflictStyle:n?.conflictStyle});if(!j.conflict){let w=await Ot(t,j.result);r.push(U(a,w,l.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3));let A=ge(m,"",g,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),O=await B(t,"blob",de.encode(A));o.set(a,{hash:O,mode:l.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(U(a,h,f.mode));return}if(h===u){r.push(U(a,d,l.mode));return}if(d===h){r.push(U(a,d,l.mode));return}if(i(a,`Auto-merging ${a}`,0),ie(c.mode)||ie(l.mode)||ie(f.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let m=await H(t,u),g=await H(t,d),p=await H(t,h);if(ne(g)||ne(p)||ne(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3)),o.set(a,{hash:d,mode:l.mode});return}let b=Y(m),R=Y(g),j=Y(p),A=Ue(R,b,j,{conflictStyle:n?.conflictStyle});if(A.conflict){let O=e.pathnames[1],w=e.pathnames[2],x=O!==a||w!==a,S={path:a,reason:"content"};x&&(O!==a&&(S.oursOrigPath=O),w!==a&&(S.theirsOrigPath=w)),s.push(S),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(U(a,u,c.mode,1)),r.push(U(a,d,l.mode,2)),r.push(U(a,h,f.mode,3));let E=x?`${n?.a??"HEAD"}:${O}`:n?.a??"HEAD",P=x?`${n?.b??"theirs"}:${w}`:n?.b??"theirs",T=ge(g,m,p,{a:E,b:P,conflictStyle:n?.conflictStyle}),$=await B(t,"blob",de.encode(T));o.set(a,{hash:$,mode:l.mode})}else{let O=await Ot(t,A.result);r.push(U(a,O,l.mode))}return}}var hi=200;async function Kn(t,e,n,r,s){let i=await Promise.all(r.map(async f=>({hash:f,timestamp:(await v(t,f)).committer.timestamp})));i.sort((f,u)=>f.timestamp-u.timestamp);let o=i.map(f=>f.hash),a=o[0],c=a,l=(await v(t,a)).tree;for(let f=1;f<o.length;f++){let u=o[f],d=(await v(t,u)).tree,h=null;if(s>=hi)h=l;else{let p=await De(t,c,u);p.length===0?h=null:p.length===1?h=(await v(t,p[0])).tree:h=await Kn(t,c,u,p,s+1)}let m=await Pe(t,h,l,d);l=await di(t,m,s);let g=Ae({type:"commit",tree:l,parents:[c,u],author:Un,committer:Un,message:"merged common ancestors"});c=await B(t,"commit",g)}return l}async function di(t,e,n){let r=e.entries.filter(a=>a.stage===0),s=new Map;for(let a of e.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let i=(a,c)=>s.get(`${a}\0${c}`),o={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let f=i(a.path,1);if(f){r.push({...f,stage:0});continue}}if(a.reason==="rename-rename"){let f=a.oursPath??a.path,u=a.theirsPath??a.path,d=i(a.path,1),h=i(f,2),m=i(u,3);if(h&&m){let g=Re.decode((await F(t,h.hash)).content),p=Re.decode((await F(t,m.hash)).content),b=d?Re.decode((await F(t,d.hash)).content):"",R=8+n*2,j=o.a??"Temporary merge branch 1",A=o.b??"Temporary merge branch 2",O=ge(g,b,p,{a:`${j}:${f}`,o:o.o,b:`${A}:${u}`,markerSize:R}),w=await B(t,"blob",de.encode(O));r.push({path:f,mode:h.mode,hash:w,stage:0,stat:ce()}),r.push({path:u,mode:m.mode,hash:w,stage:0,stat:ce()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(a.path,2),l=i(a.path,3);if(c&&l&&(a.reason==="content"||a.reason==="add-add")){let f=Re.decode((await F(t,c.hash)).content),u=Re.decode((await F(t,l.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?Re.decode((await F(t,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,g=o.a??"Temporary merge branch 1",p=o.b??"Temporary merge branch 2",b=m?`${g}:${a.oursOrigPath??a.path}`:g,R=m?`${p}:${a.theirsOrigPath??a.path}`:p,j=ge(f,h,u,{a:b,o:o.o,b:R,markerSize:o.markerSize}),A=await B(t,"blob",de.encode(j));r.push({path:a.path,mode:c.mode,hash:A,stage:0,stat:ce()})}else c?r.push({...c,stage:0}):l&&r.push({...l,stage:0})}return r.sort((a,c)=>Me(a.path,c.path)),ut(t,r)}async function Ot(t,e){let n=e.map(Et);if(n.length===0)return B(t,"blob",de.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?n.join(`
18
18
  `):`${n.join(`
19
19
  `)}
20
- `;return B(t,"blob",de.encode(i))}function U(t,e,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:s,hash:e,stage:r,stat:ce()}}function Et(t,e){let n=t.get(e);return n||(n={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},t.set(e,n)),n}async function ui(t,e,n,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await _n(t,e,n,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function hi(t,e,n,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await Pe(t,e,n,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}var di=new TextEncoder,Vn=new TextDecoder,ke=16877,qn=33188,mi=33261,Xn=40960;function K(t){let e=[];for(let n of t.split("/"))n==="."||n===""||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}function Kn(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function Yn(t){switch(t){case _.EXECUTABLE:return mi;case _.SYMLINK:return Xn;case _.DIRECTORY:return ke;default:return qn}}var Ze=class{constructor(e,n,r="/"){this.objectStore=e;this.rootTreeHash=n;this.rootPath=r;let s=K(r);this.overlay.set(s,{type:"directory",mode:ke,mtime:this.epoch})}treeCache=new Map;overlay=new Map;removals=new Set;epoch=new Date(0);toRelative(e){let n=K(e),r=K(this.rootPath);if(n===r)return"";let s=r==="/"?"/":`${r}/`;return n.startsWith(s)?n.slice(s.length):null}async loadTreeDir(e){let n=this.treeCache.get(e);if(n)return n;if(e===""){let o=await this.objectStore.read(this.rootTreeHash);if(o.type!=="tree")return null;let a=se(o.content);return this.treeCache.set("",a.entries),a.entries}let r=e.split("/"),s=await this.loadTreeDir("");if(!s)return null;let i="";for(let o of r){let a=s.find(u=>u.name===o);if(!a||a.mode!==_.DIRECTORY)return null;i=i?`${i}/${o}`:o;let c=this.treeCache.get(i);if(c){s=c;continue}let l=await this.objectStore.read(a.hash);if(l.type!=="tree")return null;let f=se(l.content);this.treeCache.set(i,f.entries),s=f.entries}return s}async lookupTreeEntry(e){if(e==="")return null;let n=e.lastIndexOf("/"),r=n===-1?"":e.slice(0,n),s=n===-1?e:e.slice(n+1),i=await this.loadTreeDir(r);if(!i)return null;let o=i.find(a=>a.name===s);return o?{entry:o,dirEntries:i}:null}async isTreeDirectory(e){return e===""?!0:(await this.lookupTreeEntry(e))?.entry.mode===_.DIRECTORY}ensureOverlayParents(e){let n=Kn(e);n===K(this.rootPath)||n==="/"||this.overlay.has(n)||(this.ensureOverlayParents(n),this.overlay.set(n,{type:"directory",mode:ke,mtime:new Date}))}async readFile(e){return Vn.decode(await this.readFileBuffer(e))}async readFileBuffer(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`ENOENT: no such file or directory, open '${e}'`);let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(i.entry.mode===_.DIRECTORY)throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let o=await this.objectStore.read(i.entry.hash);if(o.type!=="blob")throw new Error(`ENOENT: no such file or directory, open '${e}'`);return o.content}async writeFile(e,n){let r=K(e);this.removals.delete(r),this.ensureOverlayParents(r),this.overlay.set(r,{type:"file",content:typeof n=="string"?di.encode(n):new Uint8Array(n),mode:qn,mtime:new Date})}async exists(e){let n=K(e);if(this.removals.has(n))return!1;if(this.overlay.has(n))return!0;let r=this.toRelative(n);return r===null?!1:r===""||await this.isTreeDirectory(r)?!0:await this.lookupTreeEntry(r)!==null}async stat(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:r.type==="file"?r.content.byteLength:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:ke,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let{entry:o}=i,a=o.mode===_.DIRECTORY,c=o.mode===_.SYMLINK,l=0;return a||(l=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:!1,mode:Yn(o.mode),size:l,mtime:this.epoch}}async lstat(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:r.type==="symlink",mode:r.mode,size:r.type==="file"?r.content.byteLength:r.type==="symlink"?r.target.length:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:ke,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let{entry:o}=i,a=o.mode===_.DIRECTORY,c=o.mode===_.SYMLINK,l=0;return a||(l=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:c,mode:Yn(o.mode),size:l,mtime:this.epoch}}async mkdir(e,n){let r=K(e);if(this.overlay.has(r)){if(this.overlay.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.toRelative(r);if(s!==null&&!this.removals.has(r)&&(s===""||await this.isTreeDirectory(s))){if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let i=Kn(r);if(!(this.overlay.has(i)||await this.exists(i)))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.removals.delete(r),this.overlay.set(r,{type:"directory",mode:ke,mtime:new Date})}async readdir(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,s=this.toRelative(n);if(s!==null){let o=await this.loadTreeDir(s);if(o)for(let a of o){let c=n==="/"?`/${a.name}`:`${n}/${a.name}`;this.removals.has(c)||r.add(a.name)}}let i=n==="/"?"/":`${n}/`;for(let o of this.overlay.keys())if(o!==n&&o.startsWith(i)){let c=o.slice(i.length).split("/")[0];c&&!this.removals.has(n==="/"?`/${c}`:`${n}/${c}`)&&r.add(c)}if(r.size===0){if(this.overlay.get(n)?.type==="directory")return[];if(s!==null&&(s===""||await this.isTreeDirectory(s)))return[];throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}return[...r].sort()}async rm(e,n){let r=K(e);if(!await this.exists(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}let i=r==="/"?"/":`${r}/`;if(n?.recursive)for(let o of[...this.overlay.keys()])o.startsWith(i)&&(this.overlay.delete(o),this.removals.add(o));if(this.overlay.delete(r),this.removals.add(r),n?.recursive){let o=this.toRelative(r);o!==null&&await this.markTreeChildrenRemoved(o,r)}}async markTreeChildrenRemoved(e,n){let r=await this.loadTreeDir(e);if(r)for(let s of r){let i=n==="/"?`/${s.name}`:`${n}/${s.name}`;if(this.removals.add(i),s.mode===_.DIRECTORY){let o=e?`${e}/${s.name}`:s.name;await this.markTreeChildrenRemoved(o,i)}}}async readlink(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let i=await this.lookupTreeEntry(s);if(!i||i.entry.mode!==_.SYMLINK)throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let o=await this.objectStore.read(i.entry.hash);return Vn.decode(o.content)}async symlink(e,n){let r=K(n);if(await this.exists(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureOverlayParents(r),this.removals.delete(r),this.overlay.set(r,{type:"symlink",target:e,mode:Xn,mtime:new Date})}};var Ot=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,n){throw new Error("cannot write: object store is read-only")}exists(e){return this.inner.exists(e)}ingestPack(e){throw new Error("cannot ingest pack: object store is read-only")}ingestPackStream(e){throw new Error("cannot ingest pack: object store is read-only")}findByPrefix(e){return this.inner.findByPrefix(e)}},Rt=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,n){throw new Error("cannot write ref: ref store is read-only")}deleteRef(e){throw new Error("cannot delete ref: ref store is read-only")}listRefs(e){return this.inner.listRefs(e)}compareAndSwapRef(e,n,r){throw new Error("cannot update ref: ref store is read-only")}};function pi(t){return{objectStore:new Ot(t.objectStore),refStore:new Rt(t.refStore),hooks:t.hooks}}var Pt=class{constructor(e){this.inner=e}overlay=new Map;async read(e){let n=this.overlay.get(e);return n?{type:n.type,content:new Uint8Array(n.content)}:this.inner.read(e)}async write(e,n){let r=await Be(Kt(e,n));return this.overlay.has(r)||await this.inner.exists(r).catch(()=>!1)||this.overlay.set(r,{type:e,content:new Uint8Array(n)}),r}async exists(e){return this.overlay.has(e)?!0:this.inner.exists(e)}async ingestPack(e){if(e.byteLength<32)return 0;let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0);if(r!==1346454347)throw new Error(`invalid pack signature: 0x${r.toString(16)} (expected 0x5041434b)`);let s=n.getUint32(4);if(s!==2)throw new Error(`unsupported pack version: ${s}`);if(n.getUint32(8)===0)return 0;let o=this.overlay,a=this.inner,c=await zt(e,async l=>{let f=o.get(l);if(f)return{type:f.type,content:new Uint8Array(f.content)};try{return await a.read(l)}catch{return null}});for(let l of c)o.has(l.hash)||o.set(l.hash,{type:l.type,content:l.content});return c.length}async ingestPackStream(e){let n=this.overlay,r=0;for await(let s of e)n.has(s.hash)||n.set(s.hash,{type:s.type,content:s.content}),r++;return r}async findByPrefix(e){let n=await this.inner.findByPrefix(e),r=[];for(let i of this.overlay.keys())i.startsWith(e)&&r.push(i);return[...new Set([...n,...r])]}},kt=class{constructor(e){this.inner=e}overlay=new Map;deleted=new Set;async readRef(e){if(this.deleted.has(e))return null;let n=this.overlay.get(e);return n||this.inner.readRef(e)}async writeRef(e,n){this.deleted.delete(e),this.overlay.set(e,en(n))}async deleteRef(e){this.overlay.delete(e),this.deleted.add(e)}async listRefs(e){let n=await this.inner.listRefs(e),r=new Map;for(let s of n)this.deleted.has(s.name)||r.set(s.name,s);for(let[s,i]of this.overlay)if(!(e&&!s.startsWith(e))){if(i.type==="direct")r.set(s,{name:s,hash:i.hash});else if(i.type==="symbolic"){let o=await this.resolveSymbolic(i.target);o&&r.set(s,{name:s,hash:o})}}return[...r.values()]}async compareAndSwapRef(e,n,r){let s=await this.readRef(e),i=null;if(s&&(s.type==="direct"?i=s.hash:s.type==="symbolic"&&(i=await this.resolveSymbolic(s.target))),n===null){if(s!==null)return!1}else if(i!==n)return!1;return r===null?(this.overlay.delete(e),this.deleted.add(e)):(this.deleted.delete(e),this.overlay.set(e,r)),!0}async resolveSymbolic(e,n=0){if(n>10)return null;let r=await this.readRef(e);return r?r.type==="direct"?r.hash:r.type==="symbolic"?this.resolveSymbolic(r.target,n+1):null:null}};function Tt(t){return{objectStore:new Pt(t.objectStore),refStore:new kt(t.refStore),hooks:t.hooks}}async function St(t,e){let n=await _e(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function Zn(t,e,n,r){let s=new Set,i=0;for(let o of e){if(!nn(o.path))throw new Error(`refusing to check out unsafe path '${o.path}'`);let a=we(r,o.path);if(!rn(r,a))throw new Error(`refusing to check out path outside target directory: '${o.path}'`);let c=Vt(a);if(c!==r&&!s.has(c)&&(await n.mkdir(c,{recursive:!0}),s.add(c)),ie(o.mode)){let l=await H(t,o.hash);if(!sn(l))throw new Error(`refusing to create symlink with unsafe target '${l}'`);n.symlink?await n.symlink(l,a):await n.writeFile(a,l)}else{let l=await re(t,o.hash);await n.writeFile(a,l)}i++}return i}function Jn(t){return on(t.map(e=>({path:e.path,mode:parseInt(e.mode,8),hash:e.hash,stage:0,stat:ce()})))}async function gi(t,e,n,r="/"){let s=await St(t,e),i=await v(t,s),o=await Q(t,i.tree),a=await Zn(t,o,n,r);return{commitHash:s,treeHash:i.tree,filesWritten:a}}async function yi(t,e,n){let r=n?.workTree??"/",s=n?.gitDir??we(r,".git"),i=n?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await St(t,i),a=await v(t,o),c=await Q(t,a.tree),l={...t,fs:e,gitDir:s,workTree:r},f=await Zn(t,c,e,r);return await Fe(l,Jn(c)),{ctx:l,commitHash:o,treeHash:a.tree,filesWritten:f}}async function bi(t,e){let n=Tt(t),r=e?.workTree??"/",s=e?.gitDir??we(r,".git"),i=e?.ref??"HEAD",o=await St(n,i),a=await v(n,o),c=new Ze(n.objectStore,a.tree,r),l="refs/heads/main";await n.refStore.writeRef("HEAD",{type:"symbolic",target:l}),await n.refStore.writeRef(l,{type:"direct",hash:o});let f={...n,fs:c,gitDir:s,workTree:r},u=await Q(n,a.tree);return await Fe(f,Jn(u)),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:0}}export{Gs as blame,vn as buildCommit,Xs as commit,Bs as countAheadBehind,qs as createAnnotatedTag,Ys as createCommit,bi as createSandboxWorktree,yi as createWorktree,Ws as diffCommits,Ms as diffTrees,gi as extractTree,Ns as findMergeBases,Ls as flattenTree,Ds as getChangedFiles,Hs as getNewCommits,ts as grep,Us as isAncestor,Vr as listBranches,Kr as listTags,ui as mergeTrees,hi as mergeTreesFromTreeHashes,Tt as overlayRepo,qr as readBlob,Xr as readBlobText,Yr as readCommit,Jr as readFileAtCommit,Zr as readTree,pi as readonlyRepo,zr as resolveRef,$n as updateTree,zs as walkCommitHistory,Js as writeBlob,Zs as writeTree};
20
+ `;return B(t,"blob",de.encode(i))}function U(t,e,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:s,hash:e,stage:r,stat:ce()}}function xt(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 mi(t,e,n,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await zn(t,e,n,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function pi(t,e,n,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await Pe(t,e,n,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}var gi=new TextEncoder,Yn=new TextDecoder,ke=16877,Zn=33188,yi=33261,Jn=40960;function K(t){let e=[];for(let n of t.split("/"))n==="."||n===""||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}function qn(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function Xn(t){switch(t){case _.EXECUTABLE:return yi;case _.SYMLINK:return Jn;case _.DIRECTORY:return ke;default:return Zn}}var Ze=class{constructor(e,n,r="/"){this.objectStore=e;this.rootTreeHash=n;this.rootPath=r;let s=K(r);this.overlay.set(s,{type:"directory",mode:ke,mtime:this.epoch})}treeCache=new Map;overlay=new Map;removals=new Set;epoch=new Date(0);toRelative(e){let n=K(e),r=K(this.rootPath);if(n===r)return"";let s=r==="/"?"/":`${r}/`;return n.startsWith(s)?n.slice(s.length):null}async loadTreeDir(e){let n=this.treeCache.get(e);if(n)return n;if(e===""){let o=await this.objectStore.read(this.rootTreeHash);if(o.type!=="tree")return null;let a=se(o.content);return this.treeCache.set("",a.entries),a.entries}let r=e.split("/"),s=await this.loadTreeDir("");if(!s)return null;let i="";for(let o of r){let a=s.find(u=>u.name===o);if(!a||a.mode!==_.DIRECTORY)return null;i=i?`${i}/${o}`:o;let c=this.treeCache.get(i);if(c){s=c;continue}let l=await this.objectStore.read(a.hash);if(l.type!=="tree")return null;let f=se(l.content);this.treeCache.set(i,f.entries),s=f.entries}return s}async lookupTreeEntry(e){if(e==="")return null;let n=e.lastIndexOf("/"),r=n===-1?"":e.slice(0,n),s=n===-1?e:e.slice(n+1),i=await this.loadTreeDir(r);if(!i)return null;let o=i.find(a=>a.name===s);return o?{entry:o,dirEntries:i}:null}async isTreeDirectory(e){return e===""?!0:(await this.lookupTreeEntry(e))?.entry.mode===_.DIRECTORY}ensureOverlayParents(e){let n=qn(e);n===K(this.rootPath)||n==="/"||this.overlay.has(n)||(this.ensureOverlayParents(n),this.overlay.set(n,{type:"directory",mode:ke,mtime:new Date}))}async readFile(e){return Yn.decode(await this.readFileBuffer(e))}async readFileBuffer(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`ENOENT: no such file or directory, open '${e}'`);let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(i.entry.mode===_.DIRECTORY)throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let o=await this.objectStore.read(i.entry.hash);if(o.type!=="blob")throw new Error(`ENOENT: no such file or directory, open '${e}'`);return o.content}async writeFile(e,n){let r=K(e);this.removals.delete(r),this.ensureOverlayParents(r),this.overlay.set(r,{type:"file",content:typeof n=="string"?gi.encode(n):new Uint8Array(n),mode:Zn,mtime:new Date})}async exists(e){let n=K(e);if(this.removals.has(n))return!1;if(this.overlay.has(n))return!0;let r=this.toRelative(n);return r===null?!1:r===""||await this.isTreeDirectory(r)?!0:await this.lookupTreeEntry(r)!==null}async stat(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:r.type==="file"?r.content.byteLength:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:ke,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let{entry:o}=i,a=o.mode===_.DIRECTORY,c=o.mode===_.SYMLINK,l=0;return a||(l=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:!1,mode:Xn(o.mode),size:l,mtime:this.epoch}}async lstat(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:r.type==="symlink",mode:r.mode,size:r.type==="file"?r.content.byteLength:r.type==="symlink"?r.target.length:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:ke,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let{entry:o}=i,a=o.mode===_.DIRECTORY,c=o.mode===_.SYMLINK,l=0;return a||(l=(await this.objectStore.read(o.hash)).content.byteLength),{isFile:!a&&!c,isDirectory:a,isSymbolicLink:c,mode:Xn(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=qn(r);if(!(this.overlay.has(i)||await this.exists(i)))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.removals.delete(r),this.overlay.set(r,{type:"directory",mode:ke,mtime:new Date})}async readdir(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,s=this.toRelative(n);if(s!==null){let o=await this.loadTreeDir(s);if(o)for(let a of o){let c=n==="/"?`/${a.name}`:`${n}/${a.name}`;this.removals.has(c)||r.add(a.name)}}let i=n==="/"?"/":`${n}/`;for(let o of this.overlay.keys())if(o!==n&&o.startsWith(i)){let c=o.slice(i.length).split("/")[0];c&&!this.removals.has(n==="/"?`/${c}`:`${n}/${c}`)&&r.add(c)}if(r.size===0){if(this.overlay.get(n)?.type==="directory")return[];if(s!==null&&(s===""||await this.isTreeDirectory(s)))return[];throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}return[...r].sort()}async rm(e,n){let r=K(e);if(!await this.exists(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}let i=r==="/"?"/":`${r}/`;if(n?.recursive)for(let o of[...this.overlay.keys()])o.startsWith(i)&&(this.overlay.delete(o),this.removals.add(o));if(this.overlay.delete(r),this.removals.add(r),n?.recursive){let o=this.toRelative(r);o!==null&&await this.markTreeChildrenRemoved(o,r)}}async markTreeChildrenRemoved(e,n){let r=await this.loadTreeDir(e);if(r)for(let s of r){let i=n==="/"?`/${s.name}`:`${n}/${s.name}`;if(this.removals.add(i),s.mode===_.DIRECTORY){let o=e?`${e}/${s.name}`:s.name;await this.markTreeChildrenRemoved(o,i)}}}async readlink(e){let n=K(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let i=await this.lookupTreeEntry(s);if(!i||i.entry.mode!==_.SYMLINK)throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let o=await this.objectStore.read(i.entry.hash);return Yn.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:Jn,mtime:new Date})}};var Rt=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)}},Pt=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 bi(t){return{objectStore:new Rt(t.objectStore),refStore:new Pt(t.refStore),hooks:t.hooks}}var kt=class{constructor(e){this.inner=e}overlay=new Map;async read(e){let n=this.overlay.get(e);return n?{type:n.type,content:new Uint8Array(n.content)}:this.inner.read(e)}async write(e,n){let r=await Be(Yt(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 Vt(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])]}},Tt=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,tn(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 St(t){return{objectStore:new kt(t.objectStore),refStore:new Tt(t.refStore),hooks:t.hooks}}async function Ct(t,e){let n=await _e(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function Qn(t,e,n,r){let s=new Set,i=0;for(let o of e){if(!sn(o.path))throw new Error(`refusing to check out unsafe path '${o.path}'`);let a=we(r,o.path);if(!on(r,a))throw new Error(`refusing to check out path outside target directory: '${o.path}'`);let c=Kt(a);if(c!==r&&!s.has(c)&&(await n.mkdir(c,{recursive:!0}),s.add(c)),ie(o.mode)){let l=await H(t,o.hash);if(!an(l))throw new Error(`refusing to create symlink with unsafe target '${l}'`);n.symlink?await n.symlink(l,a):await n.writeFile(a,l)}else{let l=await re(t,o.hash);await n.writeFile(a,l)}i++}return i}function er(t){return cn(t.map(e=>({path:e.path,mode:parseInt(e.mode,8),hash:e.hash,stage:0,stat:ce()})))}async function wi(t,e,n,r="/"){let s=await Ct(t,e),i=await v(t,s),o=await Q(t,i.tree),a=await Qn(t,o,n,r);return{commitHash:s,treeHash:i.tree,filesWritten:a}}async function Ii(t,e,n){let r=n?.workTree??"/",s=n?.gitDir??we(r,".git"),i=n?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await Ct(t,i),a=await v(t,o),c=await Q(t,a.tree),l={...t,fs:e,gitDir:s,workTree:r},f=await Qn(t,c,e,r);return await Fe(l,er(c)),{ctx:l,commitHash:o,treeHash:a.tree,filesWritten:f}}async function Ei(t,e){let n=St(t),r=e?.workTree??"/",s=e?.gitDir??we(r,".git"),i=e?.ref??"HEAD",o=await Ct(n,i),a=await v(n,o),c=new Ze(n.objectStore,a.tree,r),l="refs/heads/main";await n.refStore.writeRef("HEAD",{type:"symbolic",target:l}),await n.refStore.writeRef(l,{type:"direct",hash:o});let f={...n,fs:c,gitDir:s,workTree:r},u=await Q(n,a.tree);return await Fe(f,er(u)),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:0}}export{Ws as blame,lt as branchNameFromRef,$n as buildCommit,Qs as commit,_s as countAheadBehind,Js as createAnnotatedTag,Zs as createCommit,Ei as createSandboxWorktree,Ii as createWorktree,Ks as diffCommits,Us as diffTrees,wi as extractTree,Fs as findMergeBases,Hs as flattenTree,Ns as getChangedFiles,Bs as getNewCommits,ss as grep,Gs as isAncestor,Yr as listBranches,qr as listTags,mi as mergeTrees,pi as mergeTreesFromTreeHashes,St as overlayRepo,Jr as readBlob,Qr as readBlobText,Zr as readCommit,ts as readFileAtCommit,Xr as readHead,es as readTree,bi as readonlyRepo,Kr as resolveRef,nn as tagNameFromRef,Mn as updateTree,Ys as walkCommitHistory,ti as writeBlob,ei as writeTree};
@@ -635,20 +635,42 @@ interface ServerHooks<A = Auth> {
635
635
  */
636
636
  advertiseRefs?: (event: AdvertiseRefsEvent<A>) => RefAdvertisement[] | void | Rejection | Promise<RefAdvertisement[] | void | Rejection>;
637
637
  }
638
- /** A single ref update within a push. */
639
- interface RefUpdate {
638
+ /** A single ref update within a push. Discriminated union on `isCreate`/`isDelete`. */
639
+ type RefUpdate = RefUpdateCreate | RefUpdateDelete | RefUpdateModify;
640
+ interface RefUpdateBase {
640
641
  /** Full ref name, e.g. "refs/heads/main". */
641
642
  ref: string;
642
- /** Previous hash, or null if creating a new ref. */
643
- oldHash: string | null;
643
+ }
644
+ /** A new ref being created. */
645
+ interface RefUpdateCreate extends RefUpdateBase {
646
+ /** Always `null` for creates — the ref didn't exist before. */
647
+ oldHash: null;
648
+ /** Hash of the new ref target. */
649
+ newHash: string;
650
+ isFF: false;
651
+ isCreate: true;
652
+ isDelete: false;
653
+ }
654
+ /** An existing ref being deleted. */
655
+ interface RefUpdateDelete extends RefUpdateBase {
656
+ /** Hash the ref pointed to before deletion. */
657
+ oldHash: string;
658
+ /** Wire-protocol zero hash (`ZERO_HASH`). Not meaningful — use `isDelete` to detect deletions. */
659
+ newHash: string;
660
+ isFF: false;
661
+ isCreate: false;
662
+ isDelete: true;
663
+ }
664
+ /** A regular ref update (fast-forward or forced). */
665
+ interface RefUpdateModify extends RefUpdateBase {
666
+ /** Previous hash the ref pointed to. */
667
+ oldHash: string;
644
668
  /** New hash being pushed. */
645
669
  newHash: string;
646
- /** Whether the update is a fast-forward. */
670
+ /** Whether the update is a fast-forward (new hash is a descendant of old). */
647
671
  isFF: boolean;
648
- /** Whether this creates a new ref. */
649
- isCreate: boolean;
650
- /** Whether this deletes an existing ref. */
651
- isDelete: boolean;
672
+ isCreate: false;
673
+ isDelete: false;
652
674
  }
653
675
  /** Fired after objects are unpacked but before refs are updated. */
654
676
  interface PreReceiveEvent<A = Auth> {
@@ -1237,4 +1259,4 @@ declare class PgStorage implements Storage {
1237
1259
  listForks(repoId: string): Promise<string[]>;
1238
1260
  }
1239
1261
 
1240
- export { type AdvertiseRefsEvent, type AdvertiseResult, type ApplyReceivePackOptions, type Auth, type AuthProvider, 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 PgPool, 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 SshChannel, type SshSessionInfo, type Storage, type UpdateEvent, type V2CommandRequest, type V2FetchRequest, type V2FetchResponseOptions, type V2LsRefsRef, advertiseRefsWithHooks, applyCasRefUpdates, applyReceivePack, buildRefAdvertisementBytes, buildRefListBytes, buildRefListPktLines, buildV2CapabilityAdvertisement, buildV2CapabilityAdvertisementBytes, buildV2FetchResponse, buildV2LsRefsResponse, collectRefs, composeHooks, createServer, handleLsRefs, handleUploadPack, handleV2Fetch, ingestReceivePack, ingestReceivePackFromStream, parseV2CommandRequest, parseV2FetchArgs, resolveRefUpdates };
1262
+ export { type AdvertiseRefsEvent, type AdvertiseResult, type ApplyReceivePackOptions, type Auth, type AuthProvider, 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 PgPool, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type PushCommand, RawObject, type RawRefEntry, type ReceivePackResult, Ref, type RefAdvertisement, type RefOps, type RefResult, type RefUpdate, type RefUpdateCreate, type RefUpdateDelete, type RefUpdateModify, type RefUpdateRequest, type RefUpdateResult, Rejection, type ServerHooks, type ServerPolicy, type SshChannel, type SshSessionInfo, type Storage, type UpdateEvent, type V2CommandRequest, type V2FetchRequest, type V2FetchResponseOptions, type V2LsRefsRef, advertiseRefsWithHooks, applyCasRefUpdates, applyReceivePack, buildRefAdvertisementBytes, buildRefListBytes, buildRefListPktLines, buildV2CapabilityAdvertisement, buildV2CapabilityAdvertisementBytes, buildV2FetchResponse, buildV2LsRefsResponse, collectRefs, composeHooks, createServer, handleLsRefs, handleUploadPack, handleV2Fetch, ingestReceivePack, ingestReceivePackFromStream, parseV2CommandRequest, parseV2FetchArgs, resolveRefUpdates };
@@ -1,11 +1,11 @@
1
- var Le=(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 U(r){return r!=null&&typeof r=="object"&&"reject"in r&&r.reject===!0}var oe="0000000000000000000000000000000000000000",Tt=(()=>{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 Ce(r){let e="";for(let t=0;t<20;t++)e+=Tt[r[t]];return e}function ce(r,e){let t="";for(let n=0;n<20;n++)t+=Tt[r[e+n]];return t}function fe(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 qr=new Set(["tree","commit","tag"]),He=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(!qr.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 Vr=new TextEncoder;function Xe(r){return typeof r=="string"?Vr.encode(r):r}function zr(){if(typeof globalThis.Bun<"u")return()=>{let r=new Bun.CryptoHasher("sha1"),e={update(t){return r.update(Xe(t)),e},hex:()=>Promise.resolve(r.digest("hex"))};return e};try{let r=Le(["node","crypto"].join(":"));if(typeof r.createHash=="function")return()=>{let e=r.createHash("sha1"),t={update(n){return e.update(Xe(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(Xe(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 Ce(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 Ut=zr(),X=Ut;async function Lt(r){return Ut().update(r).hex()}var M=Uint8Array,Y=Uint16Array,Kr=Int32Array,Ct=new M([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]),Ht=new M([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]),Xr=new M([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 Y(31);for(let s=0;s<31;++s)t[s]=e+=1<<r[s-1];let n=new Kr(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:Bt}=Dt(Ct,2);Bt[28]=258;var{b:Yr}=Dt(Ht,0),Je=new Y(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,Je[r]=((e&65280)>>8|(e&255)<<8)>>1}var le=(r,e,t)=>{let n=r.length,s=0,a=new Y(e);for(;s<n;++s)r[s]&&++a[r[s]-1];let i=new Y(e);for(s=1;s<e;++s)i[s]=i[s-1]+a[s-1]<<1;let o;if(t){o=new Y(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 u=d|(1<<l)-1;d<=u;++d)o[Je[d]>>f]=c}}else for(o=new Y(n),s=0;s<n;++s)r[s]&&(o[s]=Je[i[r[s]-1]++]>>15-r[s]);return o},de=new M(288);for(let r=0;r<144;++r)de[r]=8;for(let r=144;r<256;++r)de[r]=9;for(let r=256;r<280;++r)de[r]=7;for(let r=280;r<288;++r)de[r]=8;var _t=new M(32);for(let r=0;r<32;++r)_t[r]=5;var Zr=le(de,9,1),Jr=le(_t,5,1),Ye=r=>{let e=r[0];for(let t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},N=(r,e,t)=>{let n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},Ze=(r,e)=>{let t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},Nt=r=>(r+7)/8|0,Qr=(r,e,t)=>((e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new M(r.subarray(e,t))),$=(r,e)=>{let t=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||t[r]||"unknown inflate error")},Mt=(r,e,t,n)=>{let s=r.length,a=n?n.length:0;if(!s||e.f&&!e.l)return t||new M(0);let i=!t,o=i||e.i!=2,f=e.i;i&&(t=new M(s*3));let c=A=>{let x=t.length;if(A>x){let m=new M(Math.max(x*2,A));m.set(t),t=m}},l=e.f||0,d=e.p||0,u=e.b||0,h=e.l,p=e.d,g=e.m,R=e.n,P=s*8;do{if(!h){l=N(r,d,1);let b=N(r,d+1,3);if(d+=3,b)if(b==1)h=Zr,p=Jr,g=9,R=5;else if(b==2){let y=N(r,d,31)+257,w=N(r,d+10,15)+4,O=y+N(r,d+5,31)+1;d+=14;let E=new M(O),S=new M(19);for(let T=0;T<w;++T)S[Xr[T]]=N(r,d+T*3,7);d+=w*3;let j=Ye(S),v=(1<<j)-1,L=le(S,j,1);for(let T=0;T<O;){let G=L[N(r,d,v)];d+=G&15;let ie=G>>4;if(ie<16)E[T++]=ie;else{let It=0,Ue=0;for(ie==16?(Ue=3+N(r,d,3),d+=2,It=E[T-1]):ie==17?(Ue=3+N(r,d,7),d+=3):ie==18&&(Ue=11+N(r,d,127),d+=7);Ue--;)E[T++]=It}}let H=E.subarray(0,y),F=E.subarray(y);g=Ye(H),R=Ye(F),h=le(H,g,1),p=le(F,R,1)}else $(1);else{let y=Nt(d)+4,w=r[y-4]|r[y-3]<<8,O=y+w;if(O>s){f&&$(0);break}o&&c(u+w),t.set(r.subarray(y,O),u),e.b=u+=w,e.p=d=O*8,e.f=l;continue}if(d>P){f&&$(0);break}}o&&c(u+131072);let A=(1<<g)-1,x=(1<<R)-1,m=d;for(;;m=d){let b=h[Ze(r,d)&A],y=b>>4;if(d+=b&15,d>P){f&&$(0);break}if(b||$(2),y<256)t[u++]=y;else if(y==256){m=d,h=null;break}else{let w=y-254;if(y>264){let v=y-257,L=Ct[v];w=N(r,d,(1<<L)-1)+Bt[v],d+=L}let O=p[Ze(r,d)&x],E=O>>4;O||$(3),d+=O&15;let S=Yr[E];if(E>3){let v=Ht[E];S+=Ze(r,d)&(1<<v)-1,d+=v}if(d>P){f&&$(0);break}o&&c(u+131072);let j=u+w;if(u<S){let v=a-S,L=Math.min(S,j);for(v+u<0&&$(3);u<L;++u)t[u]=n[v+u]}for(;u<j;++u)t[u]=t[u-S]}}e.l=h,e.p=m,e.b=u,e.f=l,h&&(l=1,e.m=g,e.d=p,e.n=R)}while(!l);return u!=t.length&&i?Qr(t,0,u):t.subarray(0,u)},Ft=r=>(((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&$(0,"invalid zlib data"),r[1]&32&&$(0,"zlib dictionaries are not supported"),2);function $t(r){let e=Ft(r);return Mt(r.subarray(e,-4),{i:2})}function Qe(r){let e=Ft(r),t={i:2},n=Mt(r.subarray(e),t),s=Nt(t.p);return{result:n,bytesConsumed:e+s+4}}async function en(){let r;if(!(typeof document<"u"))try{r=Le(["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??Qe}}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:$t,inflateWithConsumed:Qe}}var tn=null;function Wt(){return tn??=en()}async function De(r){return await(await Wt()).deflateSync(r)}async function et(r,e){let t=await Wt(),{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 J=1346454347,_e=2,Vt=1,zt=2,Kt=3,Xt=4,q=6,ue=7,Yt={[Vt]:"commit",[zt]:"tree",[Kt]:"blob",[Xt]:"tag"},Zt={commit:Vt,tree:zt,blob:Kt,tag:Xt};async function Jt(r,e){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.getUint32(0);if(n!==J)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${J.toString(16)})`);let s=t.getUint32(4);if(s!==_e)throw new Error(`Unsupported pack version: ${s}`);if(r.byteLength>=32){let c=ce(r,r.byteLength-20),l=X();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 rn(r,o);i.push(l),o=l.nextOffset}return(await nn(i,e)).map((c,l)=>({...c,offset:i[l].headerOffset,nextOffset:i[l].nextOffset}))}async function rn(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===q){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===ue&&(f=ce(r,e),e+=20);let{result:c,bytesConsumed:l}=await et(r.subarray(e),a);return{headerOffset:t,typeNum:s,inflated:c,baseOffset:o,baseHash:f,nextOffset:e+l}}var Gt=50;async function nn(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>Gt)throw new Error(`delta chain depth ${i} exceeds limit of ${Gt}`);let o=n[a];if(o)return o;let f=r[a];if(f.typeNum!==q&&f.typeNum!==ue){let h=Yt[f.typeNum];if(!h)throw new Error(`Unknown object type: ${f.typeNum}`);let p={type:h,content:f.inflated,hash:await Z(h,f.inflated)};return n[a]=p,p}if(f.typeNum===q){let h=t.get(f.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${f.baseOffset}`);let p=await s(h,i+1),g=Be(p.content,f.inflated),R={type:p.type,content:g,hash:await Z(p.type,g)};return n[a]=R,R}let c=await sn(r,n,f.baseHash,s),l;if(c!==void 0)l=await s(c,i+1);else if(e){let h=await e(f.baseHash);h&&(l=h)}if(!l)throw new Error(`REF_DELTA base not found for hash ${f.baseHash}`);let d=Be(l.content,f.inflated),u={type:l.type,content:d,hash:await Z(l.type,d)};return n[a]=u,u}for(let a=0;a<r.length;a++)await s(a);return n}async function sn(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!==q&&a.typeNum!==ue&&(await n(s)).hash===t)return s}}var tt=class{buf=new Uint8Array(0);iter;eof=!1;_bytesRead=0;hasher;constructor(e,t=!1){this.iter=e[Symbol.asyncIterator](),this.hasher=t?X():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 et(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*Qt(r,e){let t=new tt(r,!0),n=await t.readExact(12),s=new DataView(n.buffer,n.byteOffset,n.byteLength),a=s.getUint32(0);if(a!==J)throw new Error(`Invalid pack signature: 0x${a.toString(16)} (expected 0x${J.toString(16)})`);let i=s.getUint32(4);if(i!==_e)throw new Error(`Unsupported pack version: ${i}`);let o=s.getUint32(8),f=new Map,c=new Map;for(let u=0;u<o;u++){let h=t.bytesRead,p=await t.readByte(),g=p>>4&7,R=p&15,P=4;for(;p&128;)p=await t.readByte(),R|=(p&127)<<P,P+=7;let A,x;if(g===q){let y=await t.readByte();for(A=y&127;y&128;)A+=1,y=await t.readByte(),A=(A<<7)+(y&127);A=h-A}else if(g===ue){let y=await t.readExact(20);x=ce(y,0)}let m=await t.inflateNext(R),b;if(g!==q&&g!==ue){let y=Yt[g];if(!y)throw new Error(`Unknown object type: ${g}`);b={type:y,content:m,hash:await Z(y,m)}}else if(g===q){let y=f.get(A);if(!y)throw new Error(`OFS_DELTA base not found at offset ${A}`);let w=Be(y.content,m);b={type:y.type,content:w,hash:await Z(y.type,w)}}else{let y=c.get(x);if(!y&&e&&(y=await e(x)??void 0),!y)throw new Error(`REF_DELTA base not found for hash ${x}`);let w=Be(y.content,m);b={type:y.type,content:w,hash:await Z(y.type,w)}}f.set(h,b),c.set(b.hash,b),yield b}let l=ce(await t.readRaw(20),0),d=await t.hashHex();if(d!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${d}`)}function Be(r,e){let t=0,{value:n,newPos:s}=qt(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}=qt(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 Q(r){let e=[],t=new Map,n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,J),s.setUint32(4,_e),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=rt(q,o.delta.byteLength),d=on(a-c),u=await De(o.delta);e.push(l,d,u),a+=l.byteLength+d.byteLength+u.byteLength}else{let l=Zt[o.type],d=rt(l,o.content.byteLength),u=await De(o.content);e.push(d,u),a+=d.byteLength+u.byteLength}i.push({hash:o.hash,offset:f,nextOffset:a})}return{data:await an(e),entries:i}}async function*er(r,e){let t=X(),n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,J),s.setUint32(4,_e),s.setUint32(8,r),t.update(n),yield n;for await(let a of e){let i=Zt[a.type],o=rt(i,a.content.byteLength),f=await De(a.content);t.update(o),t.update(f),yield cn(o,f)}yield fe(await t.hex())}async function an(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=X();s.update(t.subarray(0,n));let a=await s.hex();return t.set(fe(a),n),t}function on(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 rt(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 qt(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 cn(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(r,0),t.set(e,r.byteLength),t}var fn=new TextEncoder;async function Z(r,e){let t=fn.encode(`${r} ${e.byteLength}\0`),n=X();return n.update(t),n.update(e),n.hex()}var ln=new TextEncoder,As=new TextDecoder;function tr(r,e){let t=ln.encode(`${r} ${e.byteLength}\0`),n=new Uint8Array(t.byteLength+e.byteLength);return n.set(t),n.set(e,t.byteLength),n}function pe(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}}function Ne(r){return`${r.name} <${r.email}> ${r.timestamp} ${r.timezone}`}var dn=new TextEncoder,un=new TextDecoder;function he(r){let e=un.decode(r),t=e.indexOf(`
1
+ var Le=(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 U(r){return r!=null&&typeof r=="object"&&"reject"in r&&r.reject===!0}var X="0000000000000000000000000000000000000000",Tt=(()=>{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 Ce(r){let e="";for(let t=0;t<20;t++)e+=Tt[r[t]];return e}function ce(r,e){let t="";for(let n=0;n<20;n++)t+=Tt[r[e+n]];return t}function fe(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 qr=new Set(["tree","commit","tag"]),He=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(!qr.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 Vr=new TextEncoder;function Xe(r){return typeof r=="string"?Vr.encode(r):r}function zr(){if(typeof globalThis.Bun<"u")return()=>{let r=new Bun.CryptoHasher("sha1"),e={update(t){return r.update(Xe(t)),e},hex:()=>Promise.resolve(r.digest("hex"))};return e};try{let r=Le(["node","crypto"].join(":"));if(typeof r.createHash=="function")return()=>{let e=r.createHash("sha1"),t={update(n){return e.update(Xe(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(Xe(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 Ce(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 Ut=zr(),Y=Ut;async function Lt(r){return Ut().update(r).hex()}var M=Uint8Array,Z=Uint16Array,Kr=Int32Array,Ct=new M([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]),Ht=new M([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]),Xr=new M([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 Z(31);for(let s=0;s<31;++s)t[s]=e+=1<<r[s-1];let n=new Kr(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:Bt}=Dt(Ct,2);Bt[28]=258;var{b:Yr}=Dt(Ht,0),Je=new Z(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,Je[r]=((e&65280)>>8|(e&255)<<8)>>1}var le=(r,e,t)=>{let n=r.length,s=0,a=new Z(e);for(;s<n;++s)r[s]&&++a[r[s]-1];let i=new Z(e);for(s=1;s<e;++s)i[s]=i[s-1]+a[s-1]<<1;let o;if(t){o=new Z(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 u=d|(1<<l)-1;d<=u;++d)o[Je[d]>>f]=c}}else for(o=new Z(n),s=0;s<n;++s)r[s]&&(o[s]=Je[i[r[s]-1]++]>>15-r[s]);return o},de=new M(288);for(let r=0;r<144;++r)de[r]=8;for(let r=144;r<256;++r)de[r]=9;for(let r=256;r<280;++r)de[r]=7;for(let r=280;r<288;++r)de[r]=8;var _t=new M(32);for(let r=0;r<32;++r)_t[r]=5;var Zr=le(de,9,1),Jr=le(_t,5,1),Ye=r=>{let e=r[0];for(let t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},N=(r,e,t)=>{let n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},Ze=(r,e)=>{let t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},Nt=r=>(r+7)/8|0,Qr=(r,e,t)=>((e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new M(r.subarray(e,t))),$=(r,e)=>{let t=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||t[r]||"unknown inflate error")},Mt=(r,e,t,n)=>{let s=r.length,a=n?n.length:0;if(!s||e.f&&!e.l)return t||new M(0);let i=!t,o=i||e.i!=2,f=e.i;i&&(t=new M(s*3));let c=A=>{let x=t.length;if(A>x){let m=new M(Math.max(x*2,A));m.set(t),t=m}},l=e.f||0,d=e.p||0,u=e.b||0,h=e.l,p=e.d,g=e.m,R=e.n,P=s*8;do{if(!h){l=N(r,d,1);let b=N(r,d+1,3);if(d+=3,b)if(b==1)h=Zr,p=Jr,g=9,R=5;else if(b==2){let y=N(r,d,31)+257,w=N(r,d+10,15)+4,O=y+N(r,d+5,31)+1;d+=14;let E=new M(O),S=new M(19);for(let T=0;T<w;++T)S[Xr[T]]=N(r,d+T*3,7);d+=w*3;let j=Ye(S),v=(1<<j)-1,L=le(S,j,1);for(let T=0;T<O;){let G=L[N(r,d,v)];d+=G&15;let oe=G>>4;if(oe<16)E[T++]=oe;else{let It=0,Ue=0;for(oe==16?(Ue=3+N(r,d,3),d+=2,It=E[T-1]):oe==17?(Ue=3+N(r,d,7),d+=3):oe==18&&(Ue=11+N(r,d,127),d+=7);Ue--;)E[T++]=It}}let H=E.subarray(0,y),F=E.subarray(y);g=Ye(H),R=Ye(F),h=le(H,g,1),p=le(F,R,1)}else $(1);else{let y=Nt(d)+4,w=r[y-4]|r[y-3]<<8,O=y+w;if(O>s){f&&$(0);break}o&&c(u+w),t.set(r.subarray(y,O),u),e.b=u+=w,e.p=d=O*8,e.f=l;continue}if(d>P){f&&$(0);break}}o&&c(u+131072);let A=(1<<g)-1,x=(1<<R)-1,m=d;for(;;m=d){let b=h[Ze(r,d)&A],y=b>>4;if(d+=b&15,d>P){f&&$(0);break}if(b||$(2),y<256)t[u++]=y;else if(y==256){m=d,h=null;break}else{let w=y-254;if(y>264){let v=y-257,L=Ct[v];w=N(r,d,(1<<L)-1)+Bt[v],d+=L}let O=p[Ze(r,d)&x],E=O>>4;O||$(3),d+=O&15;let S=Yr[E];if(E>3){let v=Ht[E];S+=Ze(r,d)&(1<<v)-1,d+=v}if(d>P){f&&$(0);break}o&&c(u+131072);let j=u+w;if(u<S){let v=a-S,L=Math.min(S,j);for(v+u<0&&$(3);u<L;++u)t[u]=n[v+u]}for(;u<j;++u)t[u]=t[u-S]}}e.l=h,e.p=m,e.b=u,e.f=l,h&&(l=1,e.m=g,e.d=p,e.n=R)}while(!l);return u!=t.length&&i?Qr(t,0,u):t.subarray(0,u)},Ft=r=>(((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&$(0,"invalid zlib data"),r[1]&32&&$(0,"zlib dictionaries are not supported"),2);function $t(r){let e=Ft(r);return Mt(r.subarray(e,-4),{i:2})}function Qe(r){let e=Ft(r),t={i:2},n=Mt(r.subarray(e),t),s=Nt(t.p);return{result:n,bytesConsumed:e+s+4}}async function en(){let r;if(!(typeof document<"u"))try{r=Le(["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??Qe}}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:$t,inflateWithConsumed:Qe}}var tn=null;function Wt(){return tn??=en()}async function De(r){return await(await Wt()).deflateSync(r)}async function et(r,e){let t=await Wt(),{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 Q=1346454347,_e=2,Vt=1,zt=2,Kt=3,Xt=4,q=6,ue=7,Yt={[Vt]:"commit",[zt]:"tree",[Kt]:"blob",[Xt]:"tag"},Zt={commit:Vt,tree:zt,blob:Kt,tag:Xt};async function Jt(r,e){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.getUint32(0);if(n!==Q)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${Q.toString(16)})`);let s=t.getUint32(4);if(s!==_e)throw new Error(`Unsupported pack version: ${s}`);if(r.byteLength>=32){let c=ce(r,r.byteLength-20),l=Y();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 rn(r,o);i.push(l),o=l.nextOffset}return(await nn(i,e)).map((c,l)=>({...c,offset:i[l].headerOffset,nextOffset:i[l].nextOffset}))}async function rn(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===q){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===ue&&(f=ce(r,e),e+=20);let{result:c,bytesConsumed:l}=await et(r.subarray(e),a);return{headerOffset:t,typeNum:s,inflated:c,baseOffset:o,baseHash:f,nextOffset:e+l}}var Gt=50;async function nn(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>Gt)throw new Error(`delta chain depth ${i} exceeds limit of ${Gt}`);let o=n[a];if(o)return o;let f=r[a];if(f.typeNum!==q&&f.typeNum!==ue){let h=Yt[f.typeNum];if(!h)throw new Error(`Unknown object type: ${f.typeNum}`);let p={type:h,content:f.inflated,hash:await J(h,f.inflated)};return n[a]=p,p}if(f.typeNum===q){let h=t.get(f.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${f.baseOffset}`);let p=await s(h,i+1),g=Be(p.content,f.inflated),R={type:p.type,content:g,hash:await J(p.type,g)};return n[a]=R,R}let c=await sn(r,n,f.baseHash,s),l;if(c!==void 0)l=await s(c,i+1);else if(e){let h=await e(f.baseHash);h&&(l=h)}if(!l)throw new Error(`REF_DELTA base not found for hash ${f.baseHash}`);let d=Be(l.content,f.inflated),u={type:l.type,content:d,hash:await J(l.type,d)};return n[a]=u,u}for(let a=0;a<r.length;a++)await s(a);return n}async function sn(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!==q&&a.typeNum!==ue&&(await n(s)).hash===t)return s}}var tt=class{buf=new Uint8Array(0);iter;eof=!1;_bytesRead=0;hasher;constructor(e,t=!1){this.iter=e[Symbol.asyncIterator](),this.hasher=t?Y():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 et(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*Qt(r,e){let t=new tt(r,!0),n=await t.readExact(12),s=new DataView(n.buffer,n.byteOffset,n.byteLength),a=s.getUint32(0);if(a!==Q)throw new Error(`Invalid pack signature: 0x${a.toString(16)} (expected 0x${Q.toString(16)})`);let i=s.getUint32(4);if(i!==_e)throw new Error(`Unsupported pack version: ${i}`);let o=s.getUint32(8),f=new Map,c=new Map;for(let u=0;u<o;u++){let h=t.bytesRead,p=await t.readByte(),g=p>>4&7,R=p&15,P=4;for(;p&128;)p=await t.readByte(),R|=(p&127)<<P,P+=7;let A,x;if(g===q){let y=await t.readByte();for(A=y&127;y&128;)A+=1,y=await t.readByte(),A=(A<<7)+(y&127);A=h-A}else if(g===ue){let y=await t.readExact(20);x=ce(y,0)}let m=await t.inflateNext(R),b;if(g!==q&&g!==ue){let y=Yt[g];if(!y)throw new Error(`Unknown object type: ${g}`);b={type:y,content:m,hash:await J(y,m)}}else if(g===q){let y=f.get(A);if(!y)throw new Error(`OFS_DELTA base not found at offset ${A}`);let w=Be(y.content,m);b={type:y.type,content:w,hash:await J(y.type,w)}}else{let y=c.get(x);if(!y&&e&&(y=await e(x)??void 0),!y)throw new Error(`REF_DELTA base not found for hash ${x}`);let w=Be(y.content,m);b={type:y.type,content:w,hash:await J(y.type,w)}}f.set(h,b),c.set(b.hash,b),yield b}let l=ce(await t.readRaw(20),0),d=await t.hashHex();if(d!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${d}`)}function Be(r,e){let t=0,{value:n,newPos:s}=qt(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}=qt(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,Q),s.setUint32(4,_e),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=rt(q,o.delta.byteLength),d=on(a-c),u=await De(o.delta);e.push(l,d,u),a+=l.byteLength+d.byteLength+u.byteLength}else{let l=Zt[o.type],d=rt(l,o.content.byteLength),u=await De(o.content);e.push(d,u),a+=d.byteLength+u.byteLength}i.push({hash:o.hash,offset:f,nextOffset:a})}return{data:await an(e),entries:i}}async function*er(r,e){let t=Y(),n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,Q),s.setUint32(4,_e),s.setUint32(8,r),t.update(n),yield n;for await(let a of e){let i=Zt[a.type],o=rt(i,a.content.byteLength),f=await De(a.content);t.update(o),t.update(f),yield cn(o,f)}yield fe(await t.hex())}async function an(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=Y();s.update(t.subarray(0,n));let a=await s.hex();return t.set(fe(a),n),t}function on(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 rt(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 qt(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 cn(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(r,0),t.set(e,r.byteLength),t}var fn=new TextEncoder;async function J(r,e){let t=fn.encode(`${r} ${e.byteLength}\0`),n=Y();return n.update(t),n.update(e),n.hex()}var ln=new TextEncoder,As=new TextDecoder;function tr(r,e){let t=ln.encode(`${r} ${e.byteLength}\0`),n=new Uint8Array(t.byteLength+e.byteLength);return n.set(t),n.set(e,t.byteLength),n}function pe(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}}function Ne(r){return`${r.name} <${r.email}> ${r.timestamp} ${r.timezone}`}var dn=new TextEncoder,un=new TextDecoder;function he(r){let e=un.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
4
  `)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),u=c.slice(l+1);switch(d){case"tree":a=u;break;case"parent":i.push(u);break;case"author":o=pe(u);break;case"committer":f=pe(u);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}}function rr(r){let e=[];e.push(`tree ${r.tree}`);for(let t of r.parents)e.push(`parent ${t}`);return e.push(`author ${Ne(r.author)}`),e.push(`committer ${Ne(r.committer)}`),e.push(""),e.push(r.message),dn.encode(e.join(`
5
- `))}var js=new TextEncoder,pn=new TextDecoder;function ee(r){let e=pn.decode(r),t=e.indexOf(`
5
+ `))}var js=new TextEncoder,pn=new TextDecoder;function te(r){let e=pn.decode(r),t=e.indexOf(`
6
6
 
7
7
  `),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(`
8
- `)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),u=c.slice(l+1);switch(d){case"object":a=u;break;case"type":i=u;break;case"tag":o=u;break;case"tagger":f=pe(u);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 Me(r,e,t){let n=await r.objectStore.write(e,t);return r.hooks?.onObjectWrite?.({repo:r,type:e,hash:n}),n}async function z(r,e){return r.objectStore.read(e)}async function ye(r,e){return r.objectStore.exists(e)}var Us=new TextDecoder;async function V(r,e){let t=await z(r,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return he(t.content)}var hn=new TextEncoder,nr=new TextDecoder,yn=new Set(["100644","100755","040000","120000","160000"]);function mn(r){return r.length===4&&r.toLowerCase()===".git"}function bn(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(mn(r))throw new Error(`invalid tree entry: '${r}'`);if(!yn.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${r}'`)}function me(r){let e=[],t=0;for(;t<r.byteLength;){let n=r.indexOf(32,t);if(n===-1)break;let s=nr.decode(r.subarray(t,n)),a=r.indexOf(0,n+1);if(a===-1)break;let i=nr.decode(r.subarray(n+1,a)),o=r.subarray(a+1,a+21),f=Ce(o),c=s.padStart(6,"0");bn(i,c),e.push({mode:c,name:i,hash:f}),t=a+21}return{type:"tree",entries:e}}function sr(r){let e=[];for(let a of r.entries){let i=a.mode.replace(/^0+/,""),o=hn.encode(`${i} ${a.name}\0`),f=fe(a.hash);e.push(o),e.push(f)}let t=e.reduce((a,i)=>a+i.byteLength,0),n=new Uint8Array(t),s=0;for(let a of e)n.set(a,s),s+=a.byteLength;return n}function ar(r){return typeof r=="string"?{type:"direct",hash:r}:r}var nt=".lock";var gn=[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 wn(r,e,t){let n=0,s=!1,a=e;for(;a<r.length;a++){let o=r.charCodeAt(a);switch(o<128?gn[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>=nt.length&&r.slice(a-nt.length,a)===nt?{len:-1,starConsumed:s}:{len:i,starConsumed:s}}function st(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}=wn(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 Rn=10;async function xn(r,e){return r.refStore.readRef(e)}async function be(r,e){let t=e;for(let n=0;n<Rn;n++){let s=await xn(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}"`)}function kn(r){let e=Math.abs(r),t=r<=0?"+":"-",n=String(Math.floor(e/60)).padStart(2,"0"),s=String(e%60).padStart(2,"0");return`${t}${n}${s}`}function ir(r){if("timestamp"in r)return r;let e=r.date??new Date;return{name:r.name,email:r.email,timestamp:Math.floor(e.getTime()/1e3),timezone:kn(e.getTimezoneOffset())}}async function cr(r,e){let t=e.branch?`refs/heads/${e.branch}`:null,n=t?await be(r,t):null,s=null;n&&(s=(await V(r,n)).tree);let a=[];for(let[u,h]of Object.entries(e.files))if(h===null)a.push({path:u,hash:null});else{let p=typeof h=="string"?new TextEncoder().encode(h):h,g=await Me(r,"blob",p);a.push({path:u,hash:g})}let i;s?i=await An(r,s,a):i=await it(r,null,at(a));let o=ir(e.author),f=e.committer?ir(e.committer):o,l=rr({type:"commit",tree:i,parents:n?[n]:[],author:o,committer:f,message:e.message});return{hash:await Me(r,"commit",l),parentHash:n}}async function An(r,e,t){return it(r,e,at(t))}function at(r){let e=new Map,t=new Map;for(let n of r){let s=n.path.indexOf("/");if(s===-1)e.set(n.path,{hash:n.hash,mode:n.mode??"100644"});else{let a=n.path.slice(0,s),i=n.path.slice(s+1),o=t.get(a);o||(o=[],t.set(a,o)),o.push({...n,path:i})}}return{files:e,dirs:t}}async function or(r,e){let t=await z(r,e);if(t.type!=="tree")throw new Error(`Expected tree object, got ${t.type}`);return me(t.content).entries}async function it(r,e,t){let n=new Map;if(e)for(let i of await or(r,e))n.set(i.name,i);for(let[i,{hash:o,mode:f}]of t.files)o===null?n.delete(i):n.set(i,{name:i,hash:o,mode:f});for(let[i,o]of t.dirs){let f=n.get(i),c=f?.mode==="040000"?f.hash:null,l=at(o),d=await it(r,c,l);(await or(r,d)).length===0?n.delete(i):n.set(i,{name:i,hash:d,mode:"040000"})}let s=[...n.values()].sort((i,o)=>{let f=i.mode==="040000"?`${i.name}/`:i.name,c=o.mode==="040000"?`${o.name}/`:o.name;return f<c?-1:f>c?1:0}),a=sr({type:"tree",entries:s});return Me(r,"tree",a)}async function ot(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 V(r,i)}catch{continue}for(let f of o.parents)n.has(f)||s.push(f)}return!1}var $e=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]),En=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]),Fe=64,Pn=4,ct=4096,fr=65536,On=127;function Sn(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=jn(n);let s=n-1,a=new Uint32Array(n),i=[],o=-1>>>0;for(let u=t*16-16;u>=0;u-=16){let h=0;for(let p=1;p<=16;p++)h=(h<<8|r[u+p])^$e[h>>>23];if(h=h>>>0,h===o)i[i.length-1].ptr=u+16;else{o=h;let p=h&s;i.push({ptr:u+16,val:h}),a[p]++}}let f=new Map;for(let u of i){let h=u.val&s,p=f.get(h);p||(p=[],f.set(h,p)),p.push(u)}for(let[u,h]of f){if(h.length<=Fe)continue;let p=[],g=h.length/Fe;for(let R=0;R<Fe;R++)p.push(h[Math.floor(R*g)]);f.set(u,p),a[u]=Fe}let c=new Uint32Array(n+1),l=[],d=0;for(let u=0;u<n;u++){c[u]=d;let h=f.get(u);if(h){for(let p of h)l.push(p);d+=h.length}}return c[n]=d,{src:r,hashMask:s,buckets:c,entries:l}}function vn(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(g){for(;o+g>i.length;){let R=new Uint8Array(i.length*2);R.set(i),i=R}}o=dr(i,o,n),o=dr(i,o,s),f(18),o++;let c=0,l=0,d=Math.min(16,s);for(let g=0;g<d;g++)i[o++]=e[g],c=(c<<8|e[g])^$e[c>>>23],l++;c=c>>>0;let u=d,h=0,p=0;for(;u<s;){if(p<ct){c^=En[e[u-16]],c=((c<<8|e[u])^$e[c>>>23])>>>0;let g=c&r.hashMask,R=r.buckets[g],P=r.buckets[g+1];for(let A=R;A<P;A++){let x=r.entries[A];if(x.val!==c)continue;let m=x.ptr,b=a.byteLength-m,y=s-u;if(b>y&&(b=y),b<=p)break;let w=0;for(;w<b&&a[m+w]===e[u+w];)w++;if(w>p&&(p=w,h=m,p>=ct))break}}if(p<Pn)f(2),l===0&&o++,i[o++]=e[u++],l++,l===On&&(i[o-l-1]=l,l=0),p=0;else{if(l>0){for(;h>0&&a[h-1]===e[u-1];)if(p++,h--,u--,o--,!(--l>0)){o--,l=-1;break}l>0&&(i[o-l-1]=l),l=0}let g=p>fr?p-fr:0;p-=g,f(8);let R=o++,P=128;if(h&255&&(i[o++]=h&255,P|=1),h&65280&&(i[o++]=h>>>8&255,P|=2),h&16711680&&(i[o++]=h>>>16&255,P|=4),h&4278190080&&(i[o++]=h>>>24&255,P|=8),p&255&&(i[o++]=p&255,P|=16),p&65280&&(i[o++]=p>>>8&255,P|=32),i[R]=P,u+=p,h+=p,p=g,h>4294967295&&(p=0),p<ct){c=0;for(let A=-16;A<0;A++)c=(c<<8|e[u+A])^$e[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 lr={blob:0,tree:1,commit:2,tag:3};function ur(r,e){let t=e?.window??10,n=e?.depth??50,s=r.slice().sort((c,l)=>{let d=lr[c.type]??99,u=lr[l.type]??99;return d!==u?d-u: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},u=null,h=null,p=Math.max(0,c-t);for(let g=c-1;g>=p;g--){let R=s[g];if(R.type!==l.type||(a.get(R.hash)?.depth??0)>=n||l.content.byteLength<R.content.byteLength>>>5)continue;let x=o[g-p]??null;if(!x)continue;let m=u?u.byteLength:l.content.byteLength/2|0;if(m<16)continue;let b=vn(x,l.content,m);b&&(!u||b.byteLength<u.byteLength)&&(u=b,h=R.hash)}if(u&&h){d.delta=u,d.deltaBase=h;let g=a.get(h);d.depth=(g?.depth??0)+1}a.set(l.hash,d),i.push(d),o.length>=t&&(o.shift(),f.shift()),o.push(Sn(l.content)),f.push(l.hash)}return i}function jn(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 dr(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 In=2147483647;async function ft(r,e,t,n){if(t>=In)return{shallow:[],unshallow:[...n]};let s=new Map,a=[];for(let c of e)!s.has(c)&&await ye(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 V(r,c)}catch{continue}for(let u of d.parents)!s.has(u)&&await ye(r,u)&&(s.set(u,l+1),a.push({hash:u,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 Re(r,e,t,n,s){let a=s??n,i=new Set;for(let l of t)await ge(r,l,i,a);let o=[...e];if(s&&n)for(let l of s)try{let d=await V(r,l);for(let u of d.parents)i.has(u)||o.push(u)}catch{}let f=[],c=new Set;for(let l of o)await we(r,l,i,c,f,n);return{count:f.length,objects:Tn(f)}}async function pr(r,e,t,n,s){let{count:a,objects:i}=await Re(r,e,t,n,s);return{count:a,objects:Un(r,i)}}async function*Tn(r){for(let e of r)yield e}async function*Un(r,e){for await(let t of e){let n=await z(r,t.hash);yield{hash:t.hash,type:t.type,content:n.content}}}async function hr(r){let e=[];for await(let t of r.objects)e.push(t);return e}async function ge(r,e,t,n){if(t.has(e)||(t.add(e),!await ye(r,e)))return;let s=await z(r,e);switch(s.type){case"commit":{let a=he(s.content);if(await ge(r,a.tree,t,n),!n?.has(e))for(let i of a.parents)await ge(r,i,t,n);break}case"tree":{let a=me(s.content);for(let i of a.entries)await ge(r,i.hash,t,n);break}case"tag":{let a=ee(s.content);await ge(r,a.object,t,n);break}case"blob":break}}async function we(r,e,t,n,s,a){if(n.has(e)||t.has(e))return;n.add(e);let i=await z(r,e);switch(s.push({hash:e,type:i.type}),i.type){case"commit":{let o=he(i.content);if(await we(r,o.tree,t,n,s,a),!a?.has(e))for(let f of o.parents)await we(r,f,t,n,s,a);break}case"tree":{let o=me(i.content);for(let f of o.entries)await we(r,f.hash,t,n,s,a);break}case"tag":{let o=ee(i.content);await we(r,o.object,t,n,s,a);break}case"blob":break}}var Ln=new TextEncoder,mr=new TextDecoder,yr=65520,Cn=new Uint8Array([48,48,48,48]),Hn=new Uint8Array([48,48,48,49]),ea=new Uint8Array([48,48,48,50]);function k(r){let e=typeof r=="string"?Ln.encode(r):r,t=4+e.byteLength;if(t>yr)throw new Error(`pkt-line too long: ${t} bytes (max ${yr})`);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 _(){return Cn.slice()}function K(){return Hn.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 lt(r){let e=[],t=0;for(;t<r.byteLength;){if(t+4>r.byteLength)throw new Error("Truncated pkt-line header");let n=mr.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===1){e.push({type:"delim"}),t+=4;continue}if(s===2){e.push({type:"response-end"}),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 dt(r){if(r.type!=="data")return"";let e=mr.decode(r.data);return e.endsWith(`
8
+ `)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),u=c.slice(l+1);switch(d){case"object":a=u;break;case"type":i=u;break;case"tag":o=u;break;case"tagger":f=pe(u);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 Me(r,e,t){let n=await r.objectStore.write(e,t);return r.hooks?.onObjectWrite?.({repo:r,type:e,hash:n}),n}async function z(r,e){return r.objectStore.read(e)}async function ye(r,e){return r.objectStore.exists(e)}var Us=new TextDecoder;async function V(r,e){let t=await z(r,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return he(t.content)}var hn=new TextEncoder,nr=new TextDecoder,yn=new Set(["100644","100755","040000","120000","160000"]);function mn(r){return r.length===4&&r.toLowerCase()===".git"}function bn(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(mn(r))throw new Error(`invalid tree entry: '${r}'`);if(!yn.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${r}'`)}function me(r){let e=[],t=0;for(;t<r.byteLength;){let n=r.indexOf(32,t);if(n===-1)break;let s=nr.decode(r.subarray(t,n)),a=r.indexOf(0,n+1);if(a===-1)break;let i=nr.decode(r.subarray(n+1,a)),o=r.subarray(a+1,a+21),f=Ce(o),c=s.padStart(6,"0");bn(i,c),e.push({mode:c,name:i,hash:f}),t=a+21}return{type:"tree",entries:e}}function sr(r){let e=[];for(let a of r.entries){let i=a.mode.replace(/^0+/,""),o=hn.encode(`${i} ${a.name}\0`),f=fe(a.hash);e.push(o),e.push(f)}let t=e.reduce((a,i)=>a+i.byteLength,0),n=new Uint8Array(t),s=0;for(let a of e)n.set(a,s),s+=a.byteLength;return n}function ar(r){return typeof r=="string"?{type:"direct",hash:r}:r}var nt=".lock";var gn=[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 wn(r,e,t){let n=0,s=!1,a=e;for(;a<r.length;a++){let o=r.charCodeAt(a);switch(o<128?gn[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>=nt.length&&r.slice(a-nt.length,a)===nt?{len:-1,starConsumed:s}:{len:i,starConsumed:s}}function st(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}=wn(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 Rn=10;async function xn(r,e){return r.refStore.readRef(e)}async function be(r,e){let t=e;for(let n=0;n<Rn;n++){let s=await xn(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}"`)}function kn(r){let e=Math.abs(r),t=r<=0?"+":"-",n=String(Math.floor(e/60)).padStart(2,"0"),s=String(e%60).padStart(2,"0");return`${t}${n}${s}`}function ir(r){if("timestamp"in r)return r;let e=r.date??new Date;return{name:r.name,email:r.email,timestamp:Math.floor(e.getTime()/1e3),timezone:kn(e.getTimezoneOffset())}}async function cr(r,e){let t=e.branch?`refs/heads/${e.branch}`:null,n=t?await be(r,t):null,s=null;n&&(s=(await V(r,n)).tree);let a=[];for(let[u,h]of Object.entries(e.files))if(h===null)a.push({path:u,hash:null});else{let p=typeof h=="string"?new TextEncoder().encode(h):h,g=await Me(r,"blob",p);a.push({path:u,hash:g})}let i;s?i=await An(r,s,a):i=await it(r,null,at(a));let o=ir(e.author),f=e.committer?ir(e.committer):o,l=rr({type:"commit",tree:i,parents:n?[n]:[],author:o,committer:f,message:e.message});return{hash:await Me(r,"commit",l),parentHash:n}}async function An(r,e,t){return it(r,e,at(t))}function at(r){let e=new Map,t=new Map;for(let n of r){let s=n.path.indexOf("/");if(s===-1)e.set(n.path,{hash:n.hash,mode:n.mode??"100644"});else{let a=n.path.slice(0,s),i=n.path.slice(s+1),o=t.get(a);o||(o=[],t.set(a,o)),o.push({...n,path:i})}}return{files:e,dirs:t}}async function or(r,e){let t=await z(r,e);if(t.type!=="tree")throw new Error(`Expected tree object, got ${t.type}`);return me(t.content).entries}async function it(r,e,t){let n=new Map;if(e)for(let i of await or(r,e))n.set(i.name,i);for(let[i,{hash:o,mode:f}]of t.files)o===null?n.delete(i):n.set(i,{name:i,hash:o,mode:f});for(let[i,o]of t.dirs){let f=n.get(i),c=f?.mode==="040000"?f.hash:null,l=at(o),d=await it(r,c,l);(await or(r,d)).length===0?n.delete(i):n.set(i,{name:i,hash:d,mode:"040000"})}let s=[...n.values()].sort((i,o)=>{let f=i.mode==="040000"?`${i.name}/`:i.name,c=o.mode==="040000"?`${o.name}/`:o.name;return f<c?-1:f>c?1:0}),a=sr({type:"tree",entries:s});return Me(r,"tree",a)}async function ot(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 V(r,i)}catch{continue}for(let f of o.parents)n.has(f)||s.push(f)}return!1}var $e=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]),En=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]),Fe=64,Pn=4,ct=4096,fr=65536,On=127;function Sn(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=jn(n);let s=n-1,a=new Uint32Array(n),i=[],o=-1>>>0;for(let u=t*16-16;u>=0;u-=16){let h=0;for(let p=1;p<=16;p++)h=(h<<8|r[u+p])^$e[h>>>23];if(h=h>>>0,h===o)i[i.length-1].ptr=u+16;else{o=h;let p=h&s;i.push({ptr:u+16,val:h}),a[p]++}}let f=new Map;for(let u of i){let h=u.val&s,p=f.get(h);p||(p=[],f.set(h,p)),p.push(u)}for(let[u,h]of f){if(h.length<=Fe)continue;let p=[],g=h.length/Fe;for(let R=0;R<Fe;R++)p.push(h[Math.floor(R*g)]);f.set(u,p),a[u]=Fe}let c=new Uint32Array(n+1),l=[],d=0;for(let u=0;u<n;u++){c[u]=d;let h=f.get(u);if(h){for(let p of h)l.push(p);d+=h.length}}return c[n]=d,{src:r,hashMask:s,buckets:c,entries:l}}function vn(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(g){for(;o+g>i.length;){let R=new Uint8Array(i.length*2);R.set(i),i=R}}o=dr(i,o,n),o=dr(i,o,s),f(18),o++;let c=0,l=0,d=Math.min(16,s);for(let g=0;g<d;g++)i[o++]=e[g],c=(c<<8|e[g])^$e[c>>>23],l++;c=c>>>0;let u=d,h=0,p=0;for(;u<s;){if(p<ct){c^=En[e[u-16]],c=((c<<8|e[u])^$e[c>>>23])>>>0;let g=c&r.hashMask,R=r.buckets[g],P=r.buckets[g+1];for(let A=R;A<P;A++){let x=r.entries[A];if(x.val!==c)continue;let m=x.ptr,b=a.byteLength-m,y=s-u;if(b>y&&(b=y),b<=p)break;let w=0;for(;w<b&&a[m+w]===e[u+w];)w++;if(w>p&&(p=w,h=m,p>=ct))break}}if(p<Pn)f(2),l===0&&o++,i[o++]=e[u++],l++,l===On&&(i[o-l-1]=l,l=0),p=0;else{if(l>0){for(;h>0&&a[h-1]===e[u-1];)if(p++,h--,u--,o--,!(--l>0)){o--,l=-1;break}l>0&&(i[o-l-1]=l),l=0}let g=p>fr?p-fr:0;p-=g,f(8);let R=o++,P=128;if(h&255&&(i[o++]=h&255,P|=1),h&65280&&(i[o++]=h>>>8&255,P|=2),h&16711680&&(i[o++]=h>>>16&255,P|=4),h&4278190080&&(i[o++]=h>>>24&255,P|=8),p&255&&(i[o++]=p&255,P|=16),p&65280&&(i[o++]=p>>>8&255,P|=32),i[R]=P,u+=p,h+=p,p=g,h>4294967295&&(p=0),p<ct){c=0;for(let A=-16;A<0;A++)c=(c<<8|e[u+A])^$e[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 lr={blob:0,tree:1,commit:2,tag:3};function ur(r,e){let t=e?.window??10,n=e?.depth??50,s=r.slice().sort((c,l)=>{let d=lr[c.type]??99,u=lr[l.type]??99;return d!==u?d-u: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},u=null,h=null,p=Math.max(0,c-t);for(let g=c-1;g>=p;g--){let R=s[g];if(R.type!==l.type||(a.get(R.hash)?.depth??0)>=n||l.content.byteLength<R.content.byteLength>>>5)continue;let x=o[g-p]??null;if(!x)continue;let m=u?u.byteLength:l.content.byteLength/2|0;if(m<16)continue;let b=vn(x,l.content,m);b&&(!u||b.byteLength<u.byteLength)&&(u=b,h=R.hash)}if(u&&h){d.delta=u,d.deltaBase=h;let g=a.get(h);d.depth=(g?.depth??0)+1}a.set(l.hash,d),i.push(d),o.length>=t&&(o.shift(),f.shift()),o.push(Sn(l.content)),f.push(l.hash)}return i}function jn(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 dr(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 In=2147483647;async function ft(r,e,t,n){if(t>=In)return{shallow:[],unshallow:[...n]};let s=new Map,a=[];for(let c of e)!s.has(c)&&await ye(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 V(r,c)}catch{continue}for(let u of d.parents)!s.has(u)&&await ye(r,u)&&(s.set(u,l+1),a.push({hash:u,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 Re(r,e,t,n,s){let a=s??n,i=new Set;for(let l of t)await ge(r,l,i,a);let o=[...e];if(s&&n)for(let l of s)try{let d=await V(r,l);for(let u of d.parents)i.has(u)||o.push(u)}catch{}let f=[],c=new Set;for(let l of o)await we(r,l,i,c,f,n);return{count:f.length,objects:Tn(f)}}async function pr(r,e,t,n,s){let{count:a,objects:i}=await Re(r,e,t,n,s);return{count:a,objects:Un(r,i)}}async function*Tn(r){for(let e of r)yield e}async function*Un(r,e){for await(let t of e){let n=await z(r,t.hash);yield{hash:t.hash,type:t.type,content:n.content}}}async function hr(r){let e=[];for await(let t of r.objects)e.push(t);return e}async function ge(r,e,t,n){if(t.has(e)||(t.add(e),!await ye(r,e)))return;let s=await z(r,e);switch(s.type){case"commit":{let a=he(s.content);if(await ge(r,a.tree,t,n),!n?.has(e))for(let i of a.parents)await ge(r,i,t,n);break}case"tree":{let a=me(s.content);for(let i of a.entries)await ge(r,i.hash,t,n);break}case"tag":{let a=te(s.content);await ge(r,a.object,t,n);break}case"blob":break}}async function we(r,e,t,n,s,a){if(n.has(e)||t.has(e))return;n.add(e);let i=await z(r,e);switch(s.push({hash:e,type:i.type}),i.type){case"commit":{let o=he(i.content);if(await we(r,o.tree,t,n,s,a),!a?.has(e))for(let f of o.parents)await we(r,f,t,n,s,a);break}case"tree":{let o=me(i.content);for(let f of o.entries)await we(r,f.hash,t,n,s,a);break}case"tag":{let o=te(i.content);await we(r,o.object,t,n,s,a);break}case"blob":break}}var Ln=new TextEncoder,mr=new TextDecoder,yr=65520,Cn=new Uint8Array([48,48,48,48]),Hn=new Uint8Array([48,48,48,49]),ea=new Uint8Array([48,48,48,50]);function k(r){let e=typeof r=="string"?Ln.encode(r):r,t=4+e.byteLength;if(t>yr)throw new Error(`pkt-line too long: ${t} bytes (max ${yr})`);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 _(){return Cn.slice()}function K(){return Hn.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 lt(r){let e=[],t=0;for(;t<r.byteLength;){if(t+4>r.byteLength)throw new Error("Truncated pkt-line header");let n=mr.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===1){e.push({type:"delim"}),t+=4;continue}if(s===2){e.push({type:"response-end"}),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 dt(r){if(r.type!=="data")return"";let e=mr.decode(r.data);return e.endsWith(`
9
9
  `)?e.slice(0,-1):e}var We=65515;function Ge(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}
10
10
  `));else for(let i=0;i<r.length;i++){let o=r[i];i===0?n.push(k(`${o.hash} ${o.name}\0${a}
11
11
  `)):n.push(k(`${o.hash} ${o.name}
@@ -25,14 +25,14 @@ var Le=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(
25
25
  `)),s.push(k(`ACK ${a}
26
26
  `))}else s.push(k(`NAK
27
27
  `));if(yield B(...s),e){for await(let a of r){let i=0;for(;i<a.byteLength;){let o=Math.min(We,a.byteLength-i);yield ke(1,a.subarray(i,i+o)),i+=o}}yield _()}else for await(let a of r)yield a}function xr(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 h=e.decode(c);d=h.endsWith(`
28
- `)?h.slice(0,-1):h}let u=d.split(" ");u.length>=3&&t.push({oldHash:u[0],newHash:u[1],refName:u[2]})}let i=s<r.byteLength?r.subarray(s):new Uint8Array(0);return{commands:t,packData:i,capabilities:n,sawFlush:a}}function te(r,e,t){let n=[];n.push(k(r?`unpack ok
28
+ `)?h.slice(0,-1):h}let u=d.split(" ");u.length>=3&&t.push({oldHash:u[0],newHash:u[1],refName:u[2]})}let i=s<r.byteLength?r.subarray(s):new Uint8Array(0);return{commands:t,packData:i,capabilities:n,sawFlush:a}}function re(r,e,t){let n=[];n.push(k(r?`unpack ok
29
29
  `:`unpack error
30
30
  `));for(let a of e)a.ok?n.push(k(`ok ${a.name}
31
31
  `)):n.push(k(`ng ${a.name} ${a.error??"failed"}
32
32
  `));n.push(_());let s=B(...n);if(t){let a=[];return a.push(ke(1,s)),a.push(_()),B(...a)}return s}function ke(r,e){let t=new Uint8Array(1+e.byteLength);return t[0]=r,t.set(e,1),k(t)}function ut(r){let e=[];e.push(k(`version 2
33
33
  `));for(let t of r)e.push(k(`${t}
34
34
  `));return e.push(_()),B(...e)}function pt(r){let e=lt(r),t="",n=[],s=[],a=!1;for(let i of e){if(i.type==="flush"||i.type==="response-end")break;if(i.type==="delim"){a=!0;continue}let o=dt(i);o&&(a?s.push(o):o.startsWith("command=")?t=o.slice(8):n.push(o))}return{command:t,capabilities:n,args:s}}function ht(r){let e=[];for(let t of r){let n=`${t.hash} ${t.name}`;t.symrefTarget&&(n+=` symref-target:${t.symrefTarget}`),t.peeledHash&&(n+=` peeled:${t.peeledHash}`),e.push(k(`${n}
35
- `))}return e.push(_()),B(...e)}function yt(r){let e=[],t=[],n=[],s=[],a=!1,i,o=!1,f=!1;for(let c of r)c.startsWith("want ")?e.push(c.slice(5)):c.startsWith("have ")?t.push(c.slice(5)):c.startsWith("shallow ")?n.push(c.slice(8)):c.startsWith("deepen ")?(i=parseInt(c.slice(7),10),Number.isNaN(i)&&(i=void 0)):c.startsWith("want-ref ")?s.push(c.slice(9)):c==="done"?a=!0:c==="include-tag"?o=!0:c==="ofs-delta"&&(f=!0);return{wants:e,haves:t,done:a,clientShallows:n,depth:i,includeTag:o,ofsDeltas:f,wantRefs:s}}function re(r,e){let t=[],{commonHashes:n,shallowInfo:s,wantedRefs:a}=e??{};if(n&&n.length>0){t.push(k(`acknowledgments
35
+ `))}return e.push(_()),B(...e)}function yt(r){let e=[],t=[],n=[],s=[],a=!1,i,o=!1,f=!1;for(let c of r)c.startsWith("want ")?e.push(c.slice(5)):c.startsWith("have ")?t.push(c.slice(5)):c.startsWith("shallow ")?n.push(c.slice(8)):c.startsWith("deepen ")?(i=parseInt(c.slice(7),10),Number.isNaN(i)&&(i=void 0)):c.startsWith("want-ref ")?s.push(c.slice(9)):c==="done"?a=!0:c==="include-tag"?o=!0:c==="ofs-delta"&&(f=!0);return{wants:e,haves:t,done:a,clientShallows:n,depth:i,includeTag:o,ofsDeltas:f,wantRefs:s}}function ne(r,e){let t=[],{commonHashes:n,shallowInfo:s,wantedRefs:a}=e??{};if(n&&n.length>0){t.push(k(`acknowledgments
36
36
  `));for(let o of n)t.push(k(`ACK ${o}
37
37
  `));t.push(k(`ready
38
38
  `)),t.push(K())}if(s&&(s.shallow.length>0||s.unshallow.length>0)){t.push(k(`shallow-info
@@ -54,16 +54,16 @@ var Le=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(
54
54
  `));a.push(K()),yield B(...a)}if(s&&s.length>0){let a=[];a.push(k(`wanted-refs
55
55
  `));for(let i of s)a.push(k(`${i.hash} ${i.name}
56
56
  `));a.push(K()),yield B(...a)}yield k(`packfile
57
- `);for await(let a of r){let i=0;for(;i<a.byteLength;){let o=Math.min(We,a.byteLength-i);yield ke(1,a.subarray(i,i+o)),i+=o}}yield _()}var D=class extends Error{status=413;constructor(e){super(e),this.name="RequestLimitError"}};function Er(r){async function e(t){let n=r.getForkParent?await r.getForkParent(t):null;return{objectStore:new mt(r,t,n),refStore:new bt(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){if(r.listForks){let n=await r.listForks(t);if(n.length>0)throw new Error(`cannot delete repo '${t}': has ${n.length} active fork(s)`)}await r.deleteRepo(t)},async forkRepo(t,n,s){if(!r.forkRepo||!r.getForkParent||!r.listForks)throw new Error("storage backend does not support forks");if(!await r.hasRepo(t))throw new Error(`source repo '${t}' not found`);if(await r.hasRepo(n))throw new Error(`repo '${n}' already exists`);let f=await r.getForkParent(t)??t;await r.insertRepo(n),await r.forkRepo(f,n);let c=await r.listRefs(t);for(let d of c)await r.putRef(n,d.name,d.ref);let l=await r.getRef(t,"HEAD");if(l)await r.putRef(n,"HEAD",l);else{let d=s?.defaultBranch??"main";await r.putRef(n,"HEAD",{type:"symbolic",target:`refs/heads/${d}`})}return e(n)}}}function qe(r){return typeof r=="object"&&r!==null&&typeof r.preparePack=="function"&&typeof r.commitPack=="function"&&typeof r.deleteObjects=="function"}var mt=class{constructor(e,t,n=null){this.driver=e;this.repoId=t;this.parentId=n}cache=new He;async write(e,t){let n=tr(e,t),s=await Lt(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&&this.parentId&&(n=await this.driver.getObject(this.parentId,e)),!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)?!0:this.parentId?!!await this.driver.hasObject(this.parentId,e):!1}async preparePack(e){if(e.byteLength<32)return[];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[];let i=this.driver,o=this.repoId,f=this.parentId;return(await Jt(e,async l=>{let d=await i.getObject(o,l);return!d&&f&&(d=await i.getObject(f,l)),d?{type:d.type,content:new Uint8Array(d.content)}:null})).map(l=>({hash:l.hash,type:l.type,content:l.content}))}async preparePackStream(e){let t=[];for await(let n of e)t.push({hash:n.hash,type:n.type,content:n.content});return t}async commitPack(e){return e.length===0?0:(await this.driver.putObjects(this.repoId,e),e.length)}async ingestPack(e){let t=await this.preparePack(e);return this.commitPack(t)}async ingestPackStream(e){let t=await this.preparePackStream(e);return this.commitPack(t)}async deleteObjects(e){return e.length===0?0:this.driver.deleteObjects(this.repoId,e)}async findByPrefix(e){if(e.length<4)return[];let t=await this.driver.findObjectsByPrefix(this.repoId,e);if(!this.parentId)return Array.from(t);let n=await this.driver.findObjectsByPrefix(this.parentId,e),s=new Set(t);for(let a of n)s.add(a);return Array.from(s)}},bt=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,ar(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 gt(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=>Ae(s.getRef(e),a=>{let i=a?a.type==="direct"?a.hash:gt(o=>s.getRef(o),a.target):null;return Ae(i,o=>{if(t===null){if(a!==null)return!1}else if(o!==t)return!1;return n===null?Ae(s.removeRef(e),()=>!0):Ae(s.putRef(e,n),()=>!0)})}))}};function Ae(r,e){return r instanceof Promise?r.then(e):e(r)}function gt(r,e,t=0){return t>10?null:Ae(r(e),n=>n?n.type==="direct"?n.hash:n.type==="symbolic"?gt(r,n.target,t+1):null:null)}var ne=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}}},Pr=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag","shallow"],Or=["report-status","side-band-64k","ofs-delta","delete-refs"];async function Sr(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=Bn(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=ee(f.content);n.push({name:`${o.name}^{}`,hash:c.object})}}catch{}return{refs:n,headTarget:a}}var Dn=["refs/heads/main","refs/heads/master"];function Bn(r){for(let t of Dn){let n=r.find(s=>s.name===t);if(n)return n}return r.find(t=>t.name.startsWith("refs/heads/"))??null}function wt(r,e,t){return br(r,e,e==="git-upload-pack"?Pr:Or,t)}function Rt(r,e,t){return Ge(r,e==="git-upload-pack"?Pr:Or,t)}async function W(r,e,t,n,s){let{refs:a,headTarget:i}=await Sr(r),o=a;if(n?.advertiseRefs){let f=await n.advertiseRefs({repo:r,repoId:e,refs:a,service:t,auth:s});if(U(f))return f;f&&(o=f)}return{refs:o,headTarget:i}}function Ee(r){let e=new Map,t=new Set;for(let n of r.refs)e.set(n.name,n.hash),t.add(n.hash);return{allowedRefHashes:e,allowedWantHashes:t}}async function Pe(r,e,t){let{wants:n,haves:s,capabilities:a,clientShallows:i,depth:o,done:f}=gr(e);if(n.length===0)return xe(new Uint8Array(0),!1);if(t?.authorizedFetchSet){for(let x of n)if(!t.authorizedFetchSet.allowedWantHashes.has(x))return{reject:!0,message:`forbidden want ${x}`}}let c=a.includes("multi_ack_detailed"),l=a.includes("side-band-64k"),d,u,h;if(i.length>0&&(h=new Set(i)),o!==void 0){let x=await ft(r,n,o,h??new Set);d=x,u=new Set(x.shallow)}if(d&&!f)return wr(d);let p;if(c&&s.length>0){p=[];for(let x of s)await r.objectStore.exists(x)&&p.push(x);p.length===0&&(p=void 0)}let g=!u&&t?.cache&&t.cacheKey?ne.key(t.cacheKey,n,s):null;if(g&&t?.cache){let x=t.cache.get(g);if(x)return xe(x.packData,l,p)}let R=a.includes("include-tag"),P={repo:r,wants:n,haves:s,includeTag:R,shallowBoundary:u,clientShallowBoundary:h,cache:t?.cache,cacheKey:g,deltaWindow:t?.deltaWindow};if(t?.noDelta){let x=await Ir(P);if(!x){let{data:m}=await Q([]);return xe(m,l,p,d)}return Tr(Rr(x,l,p,d))}let A=await jr(P);return xe(A,l,p,d)}async function vr(r,e){let t=[],n=await r.refStore.listRefs("refs/tags");for(let s of n)if(!e.has(s.hash))try{let a=await r.objectStore.read(s.hash);if(a.type==="tag"){let i=ee(a.content);e.has(i.object)&&(t.push({hash:s.hash,type:"tag",content:a.content}),e.add(s.hash))}}catch{}return t}async function jr(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:i}=r,o=await pr(e,t,n,a,i);if(o.count===0){let{data:p}=await Q([]);return p}let f=await hr(o),c=new Set(f.map(p=>p.hash));if(s){let p=await vr(e,c);f.push(...p)}let l=r.deltaWindow?{window:r.deltaWindow}:void 0,d=ur(f,l),u=d.map(p=>({hash:p.hash,type:p.type,content:p.content,delta:p.delta,deltaBaseHash:p.deltaBase})),{data:h}=await Q(u);if(r.cacheKey&&r.cache){let p=d.filter(g=>g.delta).length;r.cache.set(r.cacheKey,{packData:h,objectCount:f.length,deltaCount:p})}return h}async function Ir(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:i}=r,{count:o,objects:f}=await Re(e,t,n,a,i);if(o===0)return null;let c=[];for await(let p of f)c.push(p);let l=new Set(c.map(p=>p.hash)),d=s?await vr(e,l):[],u=c.length+d.length;async function*h(){for(let p of c){let g=await e.objectStore.read(p.hash);yield{type:g.type,content:g.content}}for(let p of d)yield{type:p.type,content:p.content}}return er(u,h())}function Tr(r){let e=r[Symbol.asyncIterator]();return new ReadableStream({async pull(t){let{value:n,done:s}=await e.next();s?t.close():t.enqueue(n)}})}async function Ur(r,e){return await r.commitPack(e),e.map(t=>t.hash)}async function _n(r,e){qe(r.objectStore)&&await r.objectStore.deleteObjects(e)}async function xt(r,e,t){let{commands:n,packData:s,capabilities:a,sawFlush:i}=xr(e),o=!0,f;if(s.byteLength>0)try{if(Mn(s,t),qe(r.objectStore)){let l=await r.objectStore.preparePack(s);f=await Ur(r.objectStore,l)}else await r.objectStore.ingestPack(s)}catch(l){if(l instanceof D)throw l;o=!1}return{updates:await Lr(r,n,o),unpackOk:o,capabilities:a,sawFlush:i,ingestedHashes:f}}async function kt(r,e,t,n,s=!0,a){let i=!0,o;if(e.some(l=>l.newHash!==oe))try{let l=async u=>{try{return await r.objectStore.read(u)}catch{return null}},d=Qt(Fn(n,a),l);if(qe(r.objectStore)){let u=await r.objectStore.preparePackStream(d);o=await Ur(r.objectStore,u)}else await r.objectStore.ingestPackStream(d)}catch(l){if(l instanceof D)throw l;i=!1}return{updates:await Lr(r,e,i),unpackOk:i,capabilities:t,sawFlush:s,ingestedHashes:o}}async function Lr(r,e,t){let n=[];for(let s of e){let a=s.oldHash===oe,i=s.newHash===oe,o=!1;if(!a&&!i&&t)try{o=await ot(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 Ve(r,e){let t=[],n=[];for(let s of e){if(s.ref==="HEAD"){t.push({ref:s.ref,ok:!1,error:"HEAD cannot be updated via push"});continue}if(!s.isDelete&&!st(s.ref)){t.push({ref:s.ref,ok:!1,error:"invalid refname"});continue}if(!s.isDelete&&!await r.objectStore.exists(s.newHash)){t.push({ref:s.ref,ok:!1,error:"missing objects"});continue}try{let a=s.isCreate?null:s.oldHash,i=s.isDelete?null:{type:"direct",hash:s.newHash};if(!await r.refStore.compareAndSwapRef(s.ref,a,i)){t.push({ref:s.ref,ok:!1,error:"failed to lock"});continue}t.push({ref:s.ref,ok:!0}),n.push(s)}catch(a){t.push({ref:s.ref,ok:!1,error:a instanceof Error?a.message:String(a)})}}return{refResults:t,applied:n}}async function Oe(r){let{repo:e,repoId:t,ingestResult:n,hooks:s,auth:a}=r,{updates:i}=n;if(s?.preReceive){let c=await s.preReceive({repo:e,repoId:t,updates:i,auth:a});if(U(c)){n.ingestedHashes?.length&&await _n(e,n.ingestedHashes);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&&!st(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,auth:a});if(U(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,auth:a})}catch{}return{refResults:o,applied:f}}async function ze(r,e){let t=[];for(let n of e){let s;n.oldHash!==void 0?s=n.oldHash:s=await be(r,n.ref);let a=s===null,i=n.newHash===null,o=n.newHash??oe,f=!1;if(!a&&!i)try{f=await ot(r,s,o)}catch{}t.push({ref:n.ref,oldHash:s,newHash:o,isFF:f,isCreate:a,isDelete:i})}return t}var Nn=["agent=just-git/1.0","ls-refs=unborn","fetch=shallow","server-option","object-format=sha1"];function Se(){return ut(Nn)}async function ve(r,e,t,n,s){let a=t.includes("symrefs"),i=t.includes("peel"),o=t.includes("unborn"),f=t.filter(h=>h.startsWith("ref-prefix ")).map(h=>h.slice(11)),c=await W(r,e,"git-upload-pack",n,s);if(U(c))return c;let{refs:l,headTarget:d}=c,u=[];for(let h of l){if(h.name.endsWith("^{}")||f.length>0&&!f.some(g=>h.name.startsWith(g)))continue;let p={hash:h.hash,name:h.name};if(a&&h.name==="HEAD"&&d&&(p.symrefTarget=d),i&&h.name.startsWith("refs/tags/")){let g=l.find(R=>R.name===`${h.name}^{}`);g&&(p.peeledHash=g.hash)}u.push(p)}return o&&!u.some(h=>h.name==="HEAD")&&d&&(f.length===0||f.some(p=>"HEAD".startsWith(p)))&&u.unshift({hash:"unborn",name:"HEAD",symrefTarget:d}),ht(u)}async function je(r,e,t){let{wants:n,haves:s,done:a,clientShallows:i,depth:o,includeTag:f,wantRefs:c}=yt(e);if(n.length===0&&c.length===0){let{data:y}=await Q([]);return re(y)}let l=t?.authorizedFetchSet,d=[],u=[...n];for(let y of c)if(l){let w=l.allowedRefHashes.get(y);if(!w)return{reject:!0,message:`forbidden want-ref ${y}`};d.push({hash:w,name:y}),u.includes(w)||u.push(w)}else{let w=await be(r,y);w&&(d.push({hash:w,name:y}),u.includes(w)||u.push(w))}if(l){for(let y of n)if(!l.allowedWantHashes.has(y))return{reject:!0,message:`forbidden want ${y}`}}let h,p,g;if(i.length>0&&(g=new Set(i)),o!==void 0){let y=await ft(r,u,o,g??new Set);h=y,p=new Set(y.shallow)}let R;if(s.length>0){R=[];for(let y of s)await r.objectStore.exists(y)&&R.push(y);R.length===0&&(R=void 0)}let P=R&&R.length>0;if(!a&&!P)return kr(R??[]);let A=!p&&t?.cache&&t.cacheKey?ne.key(t.cacheKey,u,s):null,x={commonHashes:R,shallowInfo:h,wantedRefs:d.length>0?d:void 0};if(A&&t?.cache){let y=t.cache.get(A);if(y)return re(y.packData,x)}let m={repo:r,wants:u,haves:s,includeTag:f,shallowBoundary:p,clientShallowBoundary:g,cache:t?.cache,cacheKey:A,deltaWindow:t?.deltaWindow};if(t?.noDelta){let y=await Ir(m);if(!y){let{data:w}=await Q([]);return re(w,x)}return Tr(Ar(y,x))}let b=await jr(m);return re(b,x)}function Mn(r,e){if(e){if(e.maxPackBytes!==void 0&&r.byteLength>e.maxPackBytes)throw new D("Pack payload too large");if(e.maxPackObjects!==void 0&&r.byteLength>=12&&new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(8)>e.maxPackObjects)throw new D("Pack contains too many objects")}}async function*Fn(r,e){if(!e){for await(let a of r)yield a;return}let t=0,n=new Uint8Array(12),s=0;for await(let a of r){if(t+=a.byteLength,e.maxPackBytes!==void 0&&t>e.maxPackBytes)throw new D("Pack payload too large");if(s<12){let i=Math.min(12-s,a.byteLength);if(n.set(a.subarray(0,i),s),s+=i,s===12&&e.maxPackObjects!==void 0&&new DataView(n.buffer).getUint32(8)>e.maxPackObjects)throw new D("Pack contains too many objects")}yield a}}function $n(r){let e=/--protocol=version=2/.test(r),n=r.replace(/\s*--protocol=version=\d+/g,"").match(/^git[\s-](upload-pack|receive-pack)\s+'?([^']+?)'?\s*$/);if(!n)return null;let s=`git-${n[1]}`,a=n[2];return a.startsWith("/")&&(a=a.slice(1)),e?{service:s,repoPath:a,protocolV2:e}:{service:s,repoPath:a}}var Wn=new TextEncoder;async function Hr(r,e,t){let{resolveRepo:n,hooks:s,packCache:a,packOptions:i,receiveLimits:o,fetchLimits:f,auth:c}=t,l=e.writable.getWriter();try{let d=$n(r);if(!d)return Ie(e,`fatal: unrecognized command '${r}'
57
+ `);for await(let a of r){let i=0;for(;i<a.byteLength;){let o=Math.min(We,a.byteLength-i);yield ke(1,a.subarray(i,i+o)),i+=o}}yield _()}var D=class extends Error{status=413;constructor(e){super(e),this.name="RequestLimitError"}};function Er(r){async function e(t){let n=r.getForkParent?await r.getForkParent(t):null;return{objectStore:new mt(r,t,n),refStore:new bt(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){if(r.listForks){let n=await r.listForks(t);if(n.length>0)throw new Error(`cannot delete repo '${t}': has ${n.length} active fork(s)`)}await r.deleteRepo(t)},async forkRepo(t,n,s){if(!r.forkRepo||!r.getForkParent||!r.listForks)throw new Error("storage backend does not support forks");if(!await r.hasRepo(t))throw new Error(`source repo '${t}' not found`);if(await r.hasRepo(n))throw new Error(`repo '${n}' already exists`);let f=await r.getForkParent(t)??t;await r.insertRepo(n),await r.forkRepo(f,n);let c=await r.listRefs(t);for(let d of c)await r.putRef(n,d.name,d.ref);let l=await r.getRef(t,"HEAD");if(l)await r.putRef(n,"HEAD",l);else{let d=s?.defaultBranch??"main";await r.putRef(n,"HEAD",{type:"symbolic",target:`refs/heads/${d}`})}return e(n)}}}function qe(r){return typeof r=="object"&&r!==null&&typeof r.preparePack=="function"&&typeof r.commitPack=="function"&&typeof r.deleteObjects=="function"}var mt=class{constructor(e,t,n=null){this.driver=e;this.repoId=t;this.parentId=n}cache=new He;async write(e,t){let n=tr(e,t),s=await Lt(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&&this.parentId&&(n=await this.driver.getObject(this.parentId,e)),!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)?!0:this.parentId?!!await this.driver.hasObject(this.parentId,e):!1}async preparePack(e){if(e.byteLength<32)return[];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[];let i=this.driver,o=this.repoId,f=this.parentId;return(await Jt(e,async l=>{let d=await i.getObject(o,l);return!d&&f&&(d=await i.getObject(f,l)),d?{type:d.type,content:new Uint8Array(d.content)}:null})).map(l=>({hash:l.hash,type:l.type,content:l.content}))}async preparePackStream(e){let t=[];for await(let n of e)t.push({hash:n.hash,type:n.type,content:n.content});return t}async commitPack(e){return e.length===0?0:(await this.driver.putObjects(this.repoId,e),e.length)}async ingestPack(e){let t=await this.preparePack(e);return this.commitPack(t)}async ingestPackStream(e){let t=await this.preparePackStream(e);return this.commitPack(t)}async deleteObjects(e){return e.length===0?0:this.driver.deleteObjects(this.repoId,e)}async findByPrefix(e){if(e.length<4)return[];let t=await this.driver.findObjectsByPrefix(this.repoId,e);if(!this.parentId)return Array.from(t);let n=await this.driver.findObjectsByPrefix(this.parentId,e),s=new Set(t);for(let a of n)s.add(a);return Array.from(s)}},bt=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,ar(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 gt(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=>Ae(s.getRef(e),a=>{let i=a?a.type==="direct"?a.hash:gt(o=>s.getRef(o),a.target):null;return Ae(i,o=>{if(t===null){if(a!==null)return!1}else if(o!==t)return!1;return n===null?Ae(s.removeRef(e),()=>!0):Ae(s.putRef(e,n),()=>!0)})}))}};function Ae(r,e){return r instanceof Promise?r.then(e):e(r)}function gt(r,e,t=0){return t>10?null:Ae(r(e),n=>n?n.type==="direct"?n.hash:n.type==="symbolic"?gt(r,n.target,t+1):null:null)}var se=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}}},Pr=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag","shallow"],Or=["report-status","side-band-64k","ofs-delta","delete-refs"];async function Sr(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=Bn(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=te(f.content);n.push({name:`${o.name}^{}`,hash:c.object})}}catch{}return{refs:n,headTarget:a}}var Dn=["refs/heads/main","refs/heads/master"];function Bn(r){for(let t of Dn){let n=r.find(s=>s.name===t);if(n)return n}return r.find(t=>t.name.startsWith("refs/heads/"))??null}function wt(r,e,t){return br(r,e,e==="git-upload-pack"?Pr:Or,t)}function Rt(r,e,t){return Ge(r,e==="git-upload-pack"?Pr:Or,t)}async function W(r,e,t,n,s){let{refs:a,headTarget:i}=await Sr(r),o=a;if(n?.advertiseRefs){let f=await n.advertiseRefs({repo:r,repoId:e,refs:a,service:t,auth:s});if(U(f))return f;f&&(o=f)}return{refs:o,headTarget:i}}function Ee(r){let e=new Map,t=new Set;for(let n of r.refs)e.set(n.name,n.hash),t.add(n.hash);return{allowedRefHashes:e,allowedWantHashes:t}}async function Pe(r,e,t){let{wants:n,haves:s,capabilities:a,clientShallows:i,depth:o,done:f}=gr(e);if(n.length===0)return xe(new Uint8Array(0),!1);if(t?.authorizedFetchSet){for(let x of n)if(!t.authorizedFetchSet.allowedWantHashes.has(x))return{reject:!0,message:`forbidden want ${x}`}}let c=a.includes("multi_ack_detailed"),l=a.includes("side-band-64k"),d,u,h;if(i.length>0&&(h=new Set(i)),o!==void 0){let x=await ft(r,n,o,h??new Set);d=x,u=new Set(x.shallow)}if(d&&!f)return wr(d);let p;if(c&&s.length>0){p=[];for(let x of s)await r.objectStore.exists(x)&&p.push(x);p.length===0&&(p=void 0)}let g=!u&&t?.cache&&t.cacheKey?se.key(t.cacheKey,n,s):null;if(g&&t?.cache){let x=t.cache.get(g);if(x)return xe(x.packData,l,p)}let R=a.includes("include-tag"),P={repo:r,wants:n,haves:s,includeTag:R,shallowBoundary:u,clientShallowBoundary:h,cache:t?.cache,cacheKey:g,deltaWindow:t?.deltaWindow};if(t?.noDelta){let x=await Ir(P);if(!x){let{data:m}=await ee([]);return xe(m,l,p,d)}return Tr(Rr(x,l,p,d))}let A=await jr(P);return xe(A,l,p,d)}async function vr(r,e){let t=[],n=await r.refStore.listRefs("refs/tags");for(let s of n)if(!e.has(s.hash))try{let a=await r.objectStore.read(s.hash);if(a.type==="tag"){let i=te(a.content);e.has(i.object)&&(t.push({hash:s.hash,type:"tag",content:a.content}),e.add(s.hash))}}catch{}return t}async function jr(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:i}=r,o=await pr(e,t,n,a,i);if(o.count===0){let{data:p}=await ee([]);return p}let f=await hr(o),c=new Set(f.map(p=>p.hash));if(s){let p=await vr(e,c);f.push(...p)}let l=r.deltaWindow?{window:r.deltaWindow}:void 0,d=ur(f,l),u=d.map(p=>({hash:p.hash,type:p.type,content:p.content,delta:p.delta,deltaBaseHash:p.deltaBase})),{data:h}=await ee(u);if(r.cacheKey&&r.cache){let p=d.filter(g=>g.delta).length;r.cache.set(r.cacheKey,{packData:h,objectCount:f.length,deltaCount:p})}return h}async function Ir(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:i}=r,{count:o,objects:f}=await Re(e,t,n,a,i);if(o===0)return null;let c=[];for await(let p of f)c.push(p);let l=new Set(c.map(p=>p.hash)),d=s?await vr(e,l):[],u=c.length+d.length;async function*h(){for(let p of c){let g=await e.objectStore.read(p.hash);yield{type:g.type,content:g.content}}for(let p of d)yield{type:p.type,content:p.content}}return er(u,h())}function Tr(r){let e=r[Symbol.asyncIterator]();return new ReadableStream({async pull(t){let{value:n,done:s}=await e.next();s?t.close():t.enqueue(n)}})}async function Ur(r,e){return await r.commitPack(e),e.map(t=>t.hash)}async function _n(r,e){qe(r.objectStore)&&await r.objectStore.deleteObjects(e)}async function xt(r,e,t){let{commands:n,packData:s,capabilities:a,sawFlush:i}=xr(e),o=!0,f;if(s.byteLength>0)try{if(Mn(s,t),qe(r.objectStore)){let l=await r.objectStore.preparePack(s);f=await Ur(r.objectStore,l)}else await r.objectStore.ingestPack(s)}catch(l){if(l instanceof D)throw l;o=!1}return{updates:await Lr(r,n,o),unpackOk:o,capabilities:a,sawFlush:i,ingestedHashes:f}}async function kt(r,e,t,n,s=!0,a){let i=!0,o;if(e.some(l=>l.newHash!==X))try{let l=async u=>{try{return await r.objectStore.read(u)}catch{return null}},d=Qt(Fn(n,a),l);if(qe(r.objectStore)){let u=await r.objectStore.preparePackStream(d);o=await Ur(r.objectStore,u)}else await r.objectStore.ingestPackStream(d)}catch(l){if(l instanceof D)throw l;i=!1}return{updates:await Lr(r,e,i),unpackOk:i,capabilities:t,sawFlush:s,ingestedHashes:o}}async function Lr(r,e,t){let n=[];for(let s of e){let a=s.oldHash===X,i=s.newHash===X;if(a)n.push({ref:s.refName,oldHash:null,newHash:s.newHash,isFF:!1,isCreate:!0,isDelete:!1});else if(i)n.push({ref:s.refName,oldHash:s.oldHash,newHash:s.newHash,isFF:!1,isCreate:!1,isDelete:!0});else{let o=!1;if(t)try{o=await ot(r,s.oldHash,s.newHash)}catch{}n.push({ref:s.refName,oldHash:s.oldHash,newHash:s.newHash,isFF:o,isCreate:!1,isDelete:!1})}}return n}async function Ve(r,e){let t=[],n=[];for(let s of e){if(s.ref==="HEAD"){t.push({ref:s.ref,ok:!1,error:"HEAD cannot be updated via push"});continue}if(!s.isDelete&&!st(s.ref)){t.push({ref:s.ref,ok:!1,error:"invalid refname"});continue}if(!s.isDelete&&!await r.objectStore.exists(s.newHash)){t.push({ref:s.ref,ok:!1,error:"missing objects"});continue}try{let a=s.isCreate?null:s.oldHash,i=s.isDelete?null:{type:"direct",hash:s.newHash};if(!await r.refStore.compareAndSwapRef(s.ref,a,i)){t.push({ref:s.ref,ok:!1,error:"failed to lock"});continue}t.push({ref:s.ref,ok:!0}),n.push(s)}catch(a){t.push({ref:s.ref,ok:!1,error:a instanceof Error?a.message:String(a)})}}return{refResults:t,applied:n}}async function Oe(r){let{repo:e,repoId:t,ingestResult:n,hooks:s,auth:a}=r,{updates:i}=n;if(s?.preReceive){let c=await s.preReceive({repo:e,repoId:t,updates:i,auth:a});if(U(c)){n.ingestedHashes?.length&&await _n(e,n.ingestedHashes);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&&!st(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,auth:a});if(U(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,auth:a})}catch{}return{refResults:o,applied:f}}async function ze(r,e){let t=[];for(let n of e){let s=n.oldHash!==void 0?n.oldHash:await be(r,n.ref);if(s===null)t.push({ref:n.ref,oldHash:null,newHash:n.newHash??X,isFF:!1,isCreate:!0,isDelete:!1});else if(n.newHash===null)t.push({ref:n.ref,oldHash:s,newHash:X,isFF:!1,isCreate:!1,isDelete:!0});else{let a=!1;try{a=await ot(r,s,n.newHash)}catch{}t.push({ref:n.ref,oldHash:s,newHash:n.newHash,isFF:a,isCreate:!1,isDelete:!1})}}return t}var Nn=["agent=just-git/1.0","ls-refs=unborn","fetch=shallow","server-option","object-format=sha1"];function Se(){return ut(Nn)}async function ve(r,e,t,n,s){let a=t.includes("symrefs"),i=t.includes("peel"),o=t.includes("unborn"),f=t.filter(h=>h.startsWith("ref-prefix ")).map(h=>h.slice(11)),c=await W(r,e,"git-upload-pack",n,s);if(U(c))return c;let{refs:l,headTarget:d}=c,u=[];for(let h of l){if(h.name.endsWith("^{}")||f.length>0&&!f.some(g=>h.name.startsWith(g)))continue;let p={hash:h.hash,name:h.name};if(a&&h.name==="HEAD"&&d&&(p.symrefTarget=d),i&&h.name.startsWith("refs/tags/")){let g=l.find(R=>R.name===`${h.name}^{}`);g&&(p.peeledHash=g.hash)}u.push(p)}return o&&!u.some(h=>h.name==="HEAD")&&d&&(f.length===0||f.some(p=>"HEAD".startsWith(p)))&&u.unshift({hash:"unborn",name:"HEAD",symrefTarget:d}),ht(u)}async function je(r,e,t){let{wants:n,haves:s,done:a,clientShallows:i,depth:o,includeTag:f,wantRefs:c}=yt(e);if(n.length===0&&c.length===0){let{data:y}=await ee([]);return ne(y)}let l=t?.authorizedFetchSet,d=[],u=[...n];for(let y of c)if(l){let w=l.allowedRefHashes.get(y);if(!w)return{reject:!0,message:`forbidden want-ref ${y}`};d.push({hash:w,name:y}),u.includes(w)||u.push(w)}else{let w=await be(r,y);w&&(d.push({hash:w,name:y}),u.includes(w)||u.push(w))}if(l){for(let y of n)if(!l.allowedWantHashes.has(y))return{reject:!0,message:`forbidden want ${y}`}}let h,p,g;if(i.length>0&&(g=new Set(i)),o!==void 0){let y=await ft(r,u,o,g??new Set);h=y,p=new Set(y.shallow)}let R;if(s.length>0){R=[];for(let y of s)await r.objectStore.exists(y)&&R.push(y);R.length===0&&(R=void 0)}let P=R&&R.length>0;if(!a&&!P)return kr(R??[]);let A=!p&&t?.cache&&t.cacheKey?se.key(t.cacheKey,u,s):null,x={commonHashes:R,shallowInfo:h,wantedRefs:d.length>0?d:void 0};if(A&&t?.cache){let y=t.cache.get(A);if(y)return ne(y.packData,x)}let m={repo:r,wants:u,haves:s,includeTag:f,shallowBoundary:p,clientShallowBoundary:g,cache:t?.cache,cacheKey:A,deltaWindow:t?.deltaWindow};if(t?.noDelta){let y=await Ir(m);if(!y){let{data:w}=await ee([]);return ne(w,x)}return Tr(Ar(y,x))}let b=await jr(m);return ne(b,x)}function Mn(r,e){if(e){if(e.maxPackBytes!==void 0&&r.byteLength>e.maxPackBytes)throw new D("Pack payload too large");if(e.maxPackObjects!==void 0&&r.byteLength>=12&&new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(8)>e.maxPackObjects)throw new D("Pack contains too many objects")}}async function*Fn(r,e){if(!e){for await(let a of r)yield a;return}let t=0,n=new Uint8Array(12),s=0;for await(let a of r){if(t+=a.byteLength,e.maxPackBytes!==void 0&&t>e.maxPackBytes)throw new D("Pack payload too large");if(s<12){let i=Math.min(12-s,a.byteLength);if(n.set(a.subarray(0,i),s),s+=i,s===12&&e.maxPackObjects!==void 0&&new DataView(n.buffer).getUint32(8)>e.maxPackObjects)throw new D("Pack contains too many objects")}yield a}}function $n(r){let e=/--protocol=version=2/.test(r),n=r.replace(/\s*--protocol=version=\d+/g,"").match(/^git[\s-](upload-pack|receive-pack)\s+'?([^']+?)'?\s*$/);if(!n)return null;let s=`git-${n[1]}`,a=n[2];return a.startsWith("/")&&(a=a.slice(1)),e?{service:s,repoPath:a,protocolV2:e}:{service:s,repoPath:a}}var Wn=new TextEncoder;async function Hr(r,e,t){let{resolveRepo:n,hooks:s,packCache:a,packOptions:i,receiveLimits:o,fetchLimits:f,auth:c}=t,l=e.writable.getWriter();try{let d=$n(r);if(!d)return Ie(e,`fatal: unrecognized command '${r}'
58
58
  `),128;let{service:u,repoPath:h}=d,p=await n(h);if(!p)return Ie(e,`fatal: '${h}' does not appear to be a git repository
59
- `),128;let{repo:g,repoId:R}=p;if(d.protocolV2&&u==="git-upload-pack"){let x=await W(g,R,u,s,c);if(U(x))return se(e,x);await l.write(Se());let m=new Ke(e.readable);try{return await zn(m,l,g,R,e,{hooks:s,packCache:a,packOptions:i,receiveLimits:o,fetchLimits:f,auth:c})}finally{m.release()}}let P=await W(g,R,u,s,c);if(U(P))return se(e,P);await l.write(Rt(P.refs,u,P.headTarget));let A=new Ke(e.readable);try{if(u==="git-upload-pack"){let x=s?.advertiseRefs?Ee(P):void 0,m=await qn(A,f?.maxRequestBytes),b=await Pe(g,m,{cache:a,cacheKey:R,noDelta:i?.noDelta,deltaWindow:i?.deltaWindow,authorizedFetchSet:x});if(U(b))return se(e,b);await Dr(l,b)}else{let{commands:x,capabilities:m}=await Vn(A),b=A.streamRemaining();await Gn({writer:l,repo:g,repoId:R,commands:x,capabilities:m,packStream:b,hooks:s,receiveLimits:o,auth:c})}}finally{A.release()}return 0}catch(d){return d instanceof D?(Ie(e,`fatal: ${d.message}
59
+ `),128;let{repo:g,repoId:R}=p;if(d.protocolV2&&u==="git-upload-pack"){let x=await W(g,R,u,s,c);if(U(x))return ae(e,x);await l.write(Se());let m=new Ke(e.readable);try{return await zn(m,l,g,R,e,{hooks:s,packCache:a,packOptions:i,receiveLimits:o,fetchLimits:f,auth:c})}finally{m.release()}}let P=await W(g,R,u,s,c);if(U(P))return ae(e,P);await l.write(Rt(P.refs,u,P.headTarget));let A=new Ke(e.readable);try{if(u==="git-upload-pack"){let x=s?.advertiseRefs?Ee(P):void 0,m=await qn(A,f?.maxRequestBytes),b=await Pe(g,m,{cache:a,cacheKey:R,noDelta:i?.noDelta,deltaWindow:i?.deltaWindow,authorizedFetchSet:x});if(U(b))return ae(e,b);await Dr(l,b)}else{let{commands:x,capabilities:m}=await Vn(A),b=A.streamRemaining();await Gn({writer:l,repo:g,repoId:R,commands:x,capabilities:m,packStream:b,hooks:s,receiveLimits:o,auth:c})}}finally{A.release()}return 0}catch(d){return d instanceof D?(Ie(e,`fatal: ${d.message}
60
60
  `),128):(t.onError?.(d),Ie(e,`fatal: internal error
61
- `),128)}finally{try{await l.close()}catch{}}}async function Gn(r){let{writer:e,repo:t,repoId:n,commands:s,capabilities:a,packStream:i,hooks:o,receiveLimits:f,auth:c}=r,l=await kt(t,s,a,i,!0,f);if(l.updates.length===0)return;let d=l.capabilities.includes("side-band-64k"),u=l.capabilities.includes("report-status");if(!l.unpackOk){if(u){let p=l.updates.map(g=>({name:g.ref,ok:!1,error:"unpack failed"}));await e.write(te(!1,p,d))}return}let{refResults:h}=await Oe({repo:t,repoId:n,ingestResult:l,hooks:o,auth:c});if(u){let p=h.map(g=>({name:g.ref,ok:g.ok,error:g.error}));await e.write(te(!0,p,d))}}function Ie(r,e){r.writeStderr?.(Wn.encode(e))}function se(r,e){return Ie(r,`fatal: ${e.message??"access denied"}
61
+ `),128)}finally{try{await l.close()}catch{}}}async function Gn(r){let{writer:e,repo:t,repoId:n,commands:s,capabilities:a,packStream:i,hooks:o,receiveLimits:f,auth:c}=r,l=await kt(t,s,a,i,!0,f);if(l.updates.length===0)return;let d=l.capabilities.includes("side-band-64k"),u=l.capabilities.includes("report-status");if(!l.unpackOk){if(u){let p=l.updates.map(g=>({name:g.ref,ok:!1,error:"unpack failed"}));await e.write(re(!1,p,d))}return}let{refResults:h}=await Oe({repo:t,repoId:n,ingestResult:l,hooks:o,auth:c});if(u){let p=h.map(g=>({name:g.ref,ok:g.ok,error:g.error}));await e.write(re(!0,p,d))}}function Ie(r,e){r.writeStderr?.(Wn.encode(e))}function ae(r,e){return Ie(r,`fatal: ${e.message??"access denied"}
62
62
  `),128}var Cr=new TextDecoder,Ke=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=Cr.decode(this.buf.subarray(0,4)),t=parseInt(e,16);if(t===0)return{type:"flush",raw:this.consume(4)};if(t===1)return{type:"delim",raw:this.consume(4)};if(t===2)return{type:"response-end",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:Cr.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 qn(r,e){let t=[],n=0;for(;;){let s=await r.readPktLine();if(!s)break;if(n+=s.raw.byteLength,e!==void 0&&n>e)throw new D("Request body too large");if(t.push(s.raw),s.type==="data"&&s.text.trimEnd()==="done")break}return Xn(t)}async function Vn(r){let e=[],t=[],n=!0;for(;;){let s=await r.readPktLine();if(!s||s.type==="flush")break;if(s.type!=="data")continue;let a=s.text;if(a.endsWith(`
63
- `)&&(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}}async function zn(r,e,t,n,s,a){let{hooks:i,packCache:o,packOptions:f,fetchLimits:c,auth:l}=a;for(;;){let d=await Kn(r,c?.maxRequestBytes);if(!d)break;if(d.command==="ls-refs"){let u=await ve(t,n,d.args,i,l);if(U(u))return se(s,u);await e.write(u)}else if(d.command==="fetch"){let u;if(i?.advertiseRefs){let p=await W(t,n,"git-upload-pack",i,l);if(U(p))return se(s,p);u=Ee(p)}let h=await je(t,d.args,{cache:o,cacheKey:n,noDelta:f?.noDelta,deltaWindow:f?.deltaWindow,authorizedFetchSet:u});if(U(h))return se(s,h);await Dr(e,h)}else break}return 0}async function Kn(r,e){let t="",n=[],s=[],a=!1,i=!1,o=0;for(;;){let f=await r.readPktLine();if(!f)return i?{command:t,capabilities:n,args:s}:null;if(f.type==="flush"){if(!i)return null;break}if(f.type==="response-end")break;if(o+=f.raw.byteLength,e!==void 0&&o>e)throw new D("Request body too large");if(f.type==="delim"){a=!0;continue}i=!0;let c=f.text;c.endsWith(`
64
- `)&&(c=c.slice(0,-1)),a?s.push(c):c.startsWith("command=")?t=c.slice(8):n.push(c)}return t?{command:t,capabilities:n,args:s}:null}function Xn(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 Dr(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 _r(r,e,t,n,s){let a=n?.dryRun??!1,i=await Br(r),o=Yn(i);if(s)for(let p of s)o.push(p);if(o.length===0)return{deleted:0,retained:0};let f=await Re(r,o,[]),c=new Set;for await(let p of f.objects)c.add(p.hash);let l=await e.listObjectHashes(t),d=[];for(let p of l)c.has(p)||d.push(p);let u=await Br(r);return Zn(i,u)?a||d.length===0?{deleted:d.length,retained:c.size}:{deleted:await e.deleteObjects(t,d),retained:c.size}:{deleted:0,retained:c.size,aborted:!0}}async function Br(r){return r.refStore.listRefs()}function Yn(r){let e=new Set;for(let t of r)e.add(t.hash);return Array.from(e)}function Zn(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}var Te=class{repos=new Set;objects=new Map;refs=new Map;forks=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),this.forks.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)}})}forkRepo(e,t){this.forks.set(t,e)}getForkParent(e){return this.forks.get(e)??null}listForks(e){let t=[];for(let[n,s]of this.forks)s===e&&t.push(n);return t}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 Nr=new WeakMap,Jn={http:r=>({transport:"http",request:r}),ssh:r=>({transport:"ssh",username:r.username})};function Mr(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 Qn(r={}){let e=r.storage??new Te,t=Er(e),n=r.resolve??(m=>m),s=r.autoCreate,{basePath:a}=r,i={maxRequestBytes:128*1024*1024,maxInflatedBytes:256*1024*1024,maxPackBytes:128*1024*1024,maxPackObjects:25e4,...r.receiveLimits},o={maxRequestBytes:10*1024*1024,maxInflatedBytes:20*1024*1024,...r.fetchLimits};async function f(m){if(!Mr(m))return null;let b=await n(m);if(b==null||b!==m&&!Mr(b))return null;let y=await t.repo(b);if(y)return{repo:y,repoId:b};if(!s)return null;let w=typeof s=="object"?{defaultBranch:s.defaultBranch}:void 0;return{repo:await t.createRepo(b,w),repoId:b}}let c=rs(r.policy,r.hooks),l=r.auth??Jn,d=r.packCache===!1?void 0:new ne(r.packCache?.maxBytes),u=r.onError===!1?void 0:r.onError??(m=>{let b=m instanceof Error?m.message:String(m);console.error(`[server] Internal error: ${b}`)}),h=!1,p=0,g=null,R=null;function P(){return h?!1:(p++,!0)}function A(){p--,h&&p===0&&g?.()}let x={async fetch(m){if(!P())return new Response("Service Unavailable",{status:503});let b;try{let y=Nr.get(m);if(y!==void 0)b=y;else{if(!l.http)return new Response("HTTP auth provider not configured",{status:501});let E=await l.http(m);if(E instanceof Response)return E;b=E}let w=new URL(m.url),O=decodeURIComponent(w.pathname);if(a){let E=a.replace(/\/+$/,"");if(!O.startsWith(E))return new Response("Not Found",{status:404});O=O.slice(E.length)}if(O.startsWith("/")||(O=`/${O}`),O.endsWith("/info/refs")&&m.method==="GET"){let E=w.searchParams.get("service");if(E!=="git-upload-pack"&&E!=="git-receive-pack")return new Response("Unsupported service",{status:403});let S=At(O,"/info/refs"),j=await f(S);if(!j)return new Response("Not Found",{status:404});if(Fr(m)&&E==="git-upload-pack"){let F=await W(j.repo,j.repoId,E,c,b);if(U(F))return ae(F);let T=Se();return new Response(T,{headers:{"Content-Type":`application/x-${E}-advertisement`,"Cache-Control":"no-cache"}})}let L=await W(j.repo,j.repoId,E,c,b);if(U(L))return ae(L);let H=wt(L.refs,E,L.headTarget);return new Response(H,{headers:{"Content-Type":`application/x-${E}-advertisement`,"Cache-Control":"no-cache"}})}if(O.endsWith("/git-upload-pack")&&m.method==="POST"){let E=At(O,"/git-upload-pack"),S=await f(E);if(!S)return new Response("Not Found",{status:404});let j;if(c?.advertiseRefs){let H=await W(S.repo,S.repoId,"git-upload-pack",c,b);if(U(H))return ae(H);j=Ee(H)}let v=await $r(m,o);if(Fr(m)){let H=pt(v),F="application/x-git-upload-pack-result";if(H.command==="ls-refs"){let T=await ve(S.repo,S.repoId,H.args,c,b);return U(T)?ae(T):new Response(T,{headers:{"Content-Type":F}})}if(H.command==="fetch"){let T=await je(S.repo,H.args,{cache:d,cacheKey:S.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow,authorizedFetchSet:j});return U(T)?ae(T):new Response(T,{headers:{"Content-Type":F}})}return new Response(`unknown command: ${H.command}`,{status:400})}let L=await Pe(S.repo,v,{cache:d,cacheKey:S.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow,authorizedFetchSet:j});return U(L)?ae(L):new Response(L,{headers:{"Content-Type":"application/x-git-upload-pack-result"}})}if(O.endsWith("/git-receive-pack")&&m.method==="POST"){let E=At(O,"/git-receive-pack"),S=await f(E);if(!S)return new Response("Not Found",{status:404});let j=await $r(m,i),v=await xt(S.repo,j,i);if(!v.sawFlush&&v.updates.length===0)return new Response("Bad Request",{status:400});let L=v.capabilities.includes("side-band-64k"),H=v.capabilities.includes("report-status");if(!v.unpackOk){if(H){let T=v.updates.map(G=>({name:G.ref,ok:!1,error:"unpack failed"}));return new Response(te(!1,T,L),{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:F}=await Oe({repo:S.repo,repoId:S.repoId,ingestResult:v,hooks:c,auth:b});if(H){let T=F.map(G=>({name:G.ref,ok:G.ok,error:G.error}));return new Response(te(!0,T,L),{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(y){return y instanceof D?new Response(y.message,{status:y.status}):(u?.(y,b),new Response("Internal Server Error",{status:500}))}finally{A()}},async handleSession(m,b,y){if(!P())return b.writeStderr?.(new TextEncoder().encode(`fatal: server shutting down
63
+ `)&&(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}}async function zn(r,e,t,n,s,a){let{hooks:i,packCache:o,packOptions:f,fetchLimits:c,auth:l}=a;for(;;){let d=await Kn(r,c?.maxRequestBytes);if(!d)break;if(d.command==="ls-refs"){let u=await ve(t,n,d.args,i,l);if(U(u))return ae(s,u);await e.write(u)}else if(d.command==="fetch"){let u;if(i?.advertiseRefs){let p=await W(t,n,"git-upload-pack",i,l);if(U(p))return ae(s,p);u=Ee(p)}let h=await je(t,d.args,{cache:o,cacheKey:n,noDelta:f?.noDelta,deltaWindow:f?.deltaWindow,authorizedFetchSet:u});if(U(h))return ae(s,h);await Dr(e,h)}else break}return 0}async function Kn(r,e){let t="",n=[],s=[],a=!1,i=!1,o=0;for(;;){let f=await r.readPktLine();if(!f)return i?{command:t,capabilities:n,args:s}:null;if(f.type==="flush"){if(!i)return null;break}if(f.type==="response-end")break;if(o+=f.raw.byteLength,e!==void 0&&o>e)throw new D("Request body too large");if(f.type==="delim"){a=!0;continue}i=!0;let c=f.text;c.endsWith(`
64
+ `)&&(c=c.slice(0,-1)),a?s.push(c):c.startsWith("command=")?t=c.slice(8):n.push(c)}return t?{command:t,capabilities:n,args:s}:null}function Xn(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 Dr(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 _r(r,e,t,n,s){let a=n?.dryRun??!1,i=await Br(r),o=Yn(i);if(s)for(let p of s)o.push(p);if(o.length===0)return{deleted:0,retained:0};let f=await Re(r,o,[]),c=new Set;for await(let p of f.objects)c.add(p.hash);let l=await e.listObjectHashes(t),d=[];for(let p of l)c.has(p)||d.push(p);let u=await Br(r);return Zn(i,u)?a||d.length===0?{deleted:d.length,retained:c.size}:{deleted:await e.deleteObjects(t,d),retained:c.size}:{deleted:0,retained:c.size,aborted:!0}}async function Br(r){return r.refStore.listRefs()}function Yn(r){let e=new Set;for(let t of r)e.add(t.hash);return Array.from(e)}function Zn(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}var Te=class{repos=new Set;objects=new Map;refs=new Map;forks=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),this.forks.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)}})}forkRepo(e,t){this.forks.set(t,e)}getForkParent(e){return this.forks.get(e)??null}listForks(e){let t=[];for(let[n,s]of this.forks)s===e&&t.push(n);return t}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 Nr=new WeakMap,Jn={http:r=>({transport:"http",request:r}),ssh:r=>({transport:"ssh",username:r.username})};function Mr(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 Qn(r={}){let e=r.storage??new Te,t=Er(e),n=r.resolve??(m=>m),s=r.autoCreate,{basePath:a}=r,i={maxRequestBytes:128*1024*1024,maxInflatedBytes:256*1024*1024,maxPackBytes:128*1024*1024,maxPackObjects:25e4,...r.receiveLimits},o={maxRequestBytes:10*1024*1024,maxInflatedBytes:20*1024*1024,...r.fetchLimits};async function f(m){if(!Mr(m))return null;let b=await n(m);if(b==null||b!==m&&!Mr(b))return null;let y=await t.repo(b);if(y)return{repo:y,repoId:b};if(!s)return null;let w=typeof s=="object"?{defaultBranch:s.defaultBranch}:void 0;return{repo:await t.createRepo(b,w),repoId:b}}let c=rs(r.policy,r.hooks),l=r.auth??Jn,d=r.packCache===!1?void 0:new se(r.packCache?.maxBytes),u=r.onError===!1?void 0:r.onError??(m=>{let b=m instanceof Error?m.message:String(m);console.error(`[server] Internal error: ${b}`)}),h=!1,p=0,g=null,R=null;function P(){return h?!1:(p++,!0)}function A(){p--,h&&p===0&&g?.()}let x={async fetch(m){if(!P())return new Response("Service Unavailable",{status:503});let b;try{let y=Nr.get(m);if(y!==void 0)b=y;else{if(!l.http)return new Response("HTTP auth provider not configured",{status:501});let E=await l.http(m);if(E instanceof Response)return E;b=E}let w=new URL(m.url),O=decodeURIComponent(w.pathname);if(a){let E=a.replace(/\/+$/,"");if(!O.startsWith(E))return new Response("Not Found",{status:404});O=O.slice(E.length)}if(O.startsWith("/")||(O=`/${O}`),O.endsWith("/info/refs")&&m.method==="GET"){let E=w.searchParams.get("service");if(E!=="git-upload-pack"&&E!=="git-receive-pack")return new Response("Unsupported service",{status:403});let S=At(O,"/info/refs"),j=await f(S);if(!j)return new Response("Not Found",{status:404});if(Fr(m)&&E==="git-upload-pack"){let F=await W(j.repo,j.repoId,E,c,b);if(U(F))return ie(F);let T=Se();return new Response(T,{headers:{"Content-Type":`application/x-${E}-advertisement`,"Cache-Control":"no-cache"}})}let L=await W(j.repo,j.repoId,E,c,b);if(U(L))return ie(L);let H=wt(L.refs,E,L.headTarget);return new Response(H,{headers:{"Content-Type":`application/x-${E}-advertisement`,"Cache-Control":"no-cache"}})}if(O.endsWith("/git-upload-pack")&&m.method==="POST"){let E=At(O,"/git-upload-pack"),S=await f(E);if(!S)return new Response("Not Found",{status:404});let j;if(c?.advertiseRefs){let H=await W(S.repo,S.repoId,"git-upload-pack",c,b);if(U(H))return ie(H);j=Ee(H)}let v=await $r(m,o);if(Fr(m)){let H=pt(v),F="application/x-git-upload-pack-result";if(H.command==="ls-refs"){let T=await ve(S.repo,S.repoId,H.args,c,b);return U(T)?ie(T):new Response(T,{headers:{"Content-Type":F}})}if(H.command==="fetch"){let T=await je(S.repo,H.args,{cache:d,cacheKey:S.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow,authorizedFetchSet:j});return U(T)?ie(T):new Response(T,{headers:{"Content-Type":F}})}return new Response(`unknown command: ${H.command}`,{status:400})}let L=await Pe(S.repo,v,{cache:d,cacheKey:S.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow,authorizedFetchSet:j});return U(L)?ie(L):new Response(L,{headers:{"Content-Type":"application/x-git-upload-pack-result"}})}if(O.endsWith("/git-receive-pack")&&m.method==="POST"){let E=At(O,"/git-receive-pack"),S=await f(E);if(!S)return new Response("Not Found",{status:404});let j=await $r(m,i),v=await xt(S.repo,j,i);if(!v.sawFlush&&v.updates.length===0)return new Response("Bad Request",{status:400});let L=v.capabilities.includes("side-band-64k"),H=v.capabilities.includes("report-status");if(!v.unpackOk){if(H){let T=v.updates.map(G=>({name:G.ref,ok:!1,error:"unpack failed"}));return new Response(re(!1,T,L),{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:F}=await Oe({repo:S.repo,repoId:S.repoId,ingestResult:v,hooks:c,auth:b});if(H){let T=F.map(G=>({name:G.ref,ok:G.ok,error:G.error}));return new Response(re(!0,T,L),{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(y){return y instanceof D?new Response(y.message,{status:y.status}):(u?.(y,b),new Response("Internal Server Error",{status:500}))}finally{A()}},async handleSession(m,b,y){if(!P())return b.writeStderr?.(new TextEncoder().encode(`fatal: server shutting down
65
65
  `)),128;try{if(!l.ssh)return b.writeStderr?.(new TextEncoder().encode(`fatal: SSH auth provider not configured
66
- `)),128;let w=await l.ssh(y??{});return await Hr(m,b,{resolveRepo:f,hooks:c,packCache:d,packOptions:r.packOptions,receiveLimits:i,fetchLimits:o,auth:w,onError:u?O=>u(O,w):void 0})}finally{A()}},async updateRefs(m,b){if(!P())throw new Error("Server is shutting down");try{let y=await x.requireRepo(m),w=await ze(y,b);return Ve(y,w)}finally{A()}},async commit(m,b){if(!P())throw new Error("Server is shutting down");try{let y=await x.requireRepo(m),w=await cr(y,b),O=`refs/heads/${b.branch}`,E=await ze(y,[{ref:O,newHash:w.hash,oldHash:w.parentHash}]),j=(await Ve(y,E)).refResults[0];if(!j?.ok)throw new Error(j?.error??"ref update failed");return w}finally{A()}},nodeHandler(m,b){let y=[],w=0,O=!1,j=new URL(m.url??"/","http://localhost").pathname.endsWith("/git-upload-pack")?o.maxRequestBytes:i.maxRequestBytes;m.on("data",v=>{if(!O){if(w+=v.byteLength,m.method!=="GET"&&m.method!=="HEAD"&&j!==void 0&&w>j){O=!0,y.length=0,b.writeHead(413),b.end("Request body too large");try{m.destroy?.()}catch{}return}y.push(new Uint8Array(v))}}),m.on("error",()=>{b.writeHead(500),b.end("Internal Server Error")}),m.on("end",()=>{O||es(x,m,y,b).catch(()=>{try{b.writeHead(500),b.end("Internal Server Error")}catch{}})})},createRepo:(m,b)=>t.createRepo(m,b),repo:m=>t.repo(m),async requireRepo(m){let b=await t.repo(m);if(!b)throw new Error(`Repository "${m}" not found`);return b},deleteRepo:m=>t.deleteRepo(m),async forkRepo(m,b,y){if(!P())throw new Error("Server is shutting down");try{return await t.forkRepo(m,b,y)}finally{A()}},async gc(m,b){if(!P())throw new Error("Server is shutting down");try{let y=await x.requireRepo(m),w;if(e.listForks&&e.getForkParent&&!await e.getForkParent(m)){let E=await e.listForks(m);if(E.length>0){w=[];for(let S of E){let j=await t.repo(S);if(!j)continue;let v=await j.refStore.listRefs();for(let L of v)w.push(L.hash)}}}return _r(y,e,m,b,w)}finally{A()}},get closed(){return h},asNetwork(m="http://git",b){return{allowed:[m.endsWith("/")?m:`${m}/`],fetch:(w,O)=>{let E=new Request(w,O);return b!==void 0&&Nr.set(E,b),x.fetch(E)}}},async close(m){if(h)return R??Promise.resolve();if(h=!0,d?.clear(),p!==0){if(R=new Promise(b=>{g=b}),m?.signal){if(m.signal.aborted){g();return}let b=()=>g?.();m.signal.addEventListener("abort",b,{once:!0}),R.then(()=>m.signal.removeEventListener("abort",b))}return R}}};return x}function ae(r){return new Response(r.message??"Forbidden",{status:403})}function Fr(r){let e=r.headers.get("git-protocol");return e!==null&&e.includes("version=2")}function At(r,e){let t=r.slice(0,-e.length);return t.startsWith("/")&&(t=t.slice(1)),t}async function $r(r,e){let t=r.headers.get("content-length");if(t){let a=Number(t);if(Number.isFinite(a)&&e.maxRequestBytes!==void 0&&a>e.maxRequestBytes)throw new D("Request body too large")}let n=await Wr(r.body,e.maxRequestBytes,"Request body too large"),s=r.headers.get("content-encoding");if(s==="gzip"||s==="x-gzip"){let a=new DecompressionStream("gzip"),i=a.writable.getWriter(),o=new Uint8Array(n.byteLength);return o.set(n),await i.write(o),await i.close(),Wr(a.readable,e.maxInflatedBytes,"Decompressed body too large")}return n}async function Wr(r,e,t){if(!r)return new Uint8Array(0);let n=r.getReader(),s=[],a=0;try{for(;;){let{value:f,done:c}=await n.read();if(c)break;if(f){if(a+=f.byteLength,e!==void 0&&a>e)throw new D(t);s.push(f)}}}finally{n.releaseLock()}if(s.length===0)return new Uint8Array(0);let i=new Uint8Array(a),o=0;for(let f of s)i.set(f,o),o+=f.byteLength;return i}async function es(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[h,p]of Object.entries(e.headers))if(p!==void 0)if(Array.isArray(p))for(let g of p)i.append(h,g);else i.set(h,p);let o=e.method??"GET",f;if(o!=="GET"&&o!=="HEAD"){let h=0;for(let R of t)h+=R.byteLength;let p=new Uint8Array(h),g=0;for(let R of t)p.set(R,g),g+=R.byteLength;f=p}let c=new Request(a.href,{method:o,headers:i,body:f}),l=await r.fetch(c),d={};l.headers.forEach((h,p)=>{d[p]=h}),n.writeHead(l.status,d);let u=new Uint8Array(await l.arrayBuffer());u.byteLength>0&&n.write(u),n.end()}function ts(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 rs(r,e){let t=r?ts(r):void 0;return t&&e?Gr(t,e):t??e}function Gr(...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(U(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(U(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(U(l))return l;l&&(f=l)}return f}),t}var ns=`
66
+ `)),128;let w=await l.ssh(y??{});return await Hr(m,b,{resolveRepo:f,hooks:c,packCache:d,packOptions:r.packOptions,receiveLimits:i,fetchLimits:o,auth:w,onError:u?O=>u(O,w):void 0})}finally{A()}},async updateRefs(m,b){if(!P())throw new Error("Server is shutting down");try{let y=await x.requireRepo(m),w=await ze(y,b);return Ve(y,w)}finally{A()}},async commit(m,b){if(!P())throw new Error("Server is shutting down");try{let y=await x.requireRepo(m),w=await cr(y,b),O=`refs/heads/${b.branch}`,E=await ze(y,[{ref:O,newHash:w.hash,oldHash:w.parentHash}]),j=(await Ve(y,E)).refResults[0];if(!j?.ok)throw new Error(j?.error??"ref update failed");return w}finally{A()}},nodeHandler(m,b){let y=[],w=0,O=!1,j=new URL(m.url??"/","http://localhost").pathname.endsWith("/git-upload-pack")?o.maxRequestBytes:i.maxRequestBytes;m.on("data",v=>{if(!O){if(w+=v.byteLength,m.method!=="GET"&&m.method!=="HEAD"&&j!==void 0&&w>j){O=!0,y.length=0,b.writeHead(413),b.end("Request body too large");try{m.destroy?.()}catch{}return}y.push(new Uint8Array(v))}}),m.on("error",()=>{b.writeHead(500),b.end("Internal Server Error")}),m.on("end",()=>{O||es(x,m,y,b).catch(()=>{try{b.writeHead(500),b.end("Internal Server Error")}catch{}})})},createRepo:(m,b)=>t.createRepo(m,b),repo:m=>t.repo(m),async requireRepo(m){let b=await t.repo(m);if(!b)throw new Error(`Repository "${m}" not found`);return b},deleteRepo:m=>t.deleteRepo(m),async forkRepo(m,b,y){if(!P())throw new Error("Server is shutting down");try{return await t.forkRepo(m,b,y)}finally{A()}},async gc(m,b){if(!P())throw new Error("Server is shutting down");try{let y=await x.requireRepo(m),w;if(e.listForks&&e.getForkParent&&!await e.getForkParent(m)){let E=await e.listForks(m);if(E.length>0){w=[];for(let S of E){let j=await t.repo(S);if(!j)continue;let v=await j.refStore.listRefs();for(let L of v)w.push(L.hash)}}}return _r(y,e,m,b,w)}finally{A()}},get closed(){return h},asNetwork(m="http://git",b){return{allowed:[m.endsWith("/")?m:`${m}/`],fetch:(w,O)=>{let E=new Request(w,O);return b!==void 0&&Nr.set(E,b),x.fetch(E)}}},async close(m){if(h)return R??Promise.resolve();if(h=!0,d?.clear(),p!==0){if(R=new Promise(b=>{g=b}),m?.signal){if(m.signal.aborted){g();return}let b=()=>g?.();m.signal.addEventListener("abort",b,{once:!0}),R.then(()=>m.signal.removeEventListener("abort",b))}return R}}};return x}function ie(r){return new Response(r.message??"Forbidden",{status:403})}function Fr(r){let e=r.headers.get("git-protocol");return e!==null&&e.includes("version=2")}function At(r,e){let t=r.slice(0,-e.length);return t.startsWith("/")&&(t=t.slice(1)),t}async function $r(r,e){let t=r.headers.get("content-length");if(t){let a=Number(t);if(Number.isFinite(a)&&e.maxRequestBytes!==void 0&&a>e.maxRequestBytes)throw new D("Request body too large")}let n=await Wr(r.body,e.maxRequestBytes,"Request body too large"),s=r.headers.get("content-encoding");if(s==="gzip"||s==="x-gzip"){let a=new DecompressionStream("gzip"),i=a.writable.getWriter(),o=new Uint8Array(n.byteLength);return o.set(n),await i.write(o),await i.close(),Wr(a.readable,e.maxInflatedBytes,"Decompressed body too large")}return n}async function Wr(r,e,t){if(!r)return new Uint8Array(0);let n=r.getReader(),s=[],a=0;try{for(;;){let{value:f,done:c}=await n.read();if(c)break;if(f){if(a+=f.byteLength,e!==void 0&&a>e)throw new D(t);s.push(f)}}}finally{n.releaseLock()}if(s.length===0)return new Uint8Array(0);let i=new Uint8Array(a),o=0;for(let f of s)i.set(f,o),o+=f.byteLength;return i}async function es(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[h,p]of Object.entries(e.headers))if(p!==void 0)if(Array.isArray(p))for(let g of p)i.append(h,g);else i.set(h,p);let o=e.method??"GET",f;if(o!=="GET"&&o!=="HEAD"){let h=0;for(let R of t)h+=R.byteLength;let p=new Uint8Array(h),g=0;for(let R of t)p.set(R,g),g+=R.byteLength;f=p}let c=new Request(a.href,{method:o,headers:i,body:f}),l=await r.fetch(c),d={};l.headers.forEach((h,p)=>{d[p]=h}),n.writeHead(l.status,d);let u=new Uint8Array(await l.arrayBuffer());u.byteLength>0&&n.write(u),n.end()}function ts(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 rs(r,e){let t=r?ts(r):void 0;return t&&e?Gr(t,e):t??e}function Gr(...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(U(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(U(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(U(l))return l;l&&(f=l)}return f}),t}var ns=`
67
67
  CREATE TABLE IF NOT EXISTS git_repos (
68
68
  id TEXT PRIMARY KEY
69
69
  );
@@ -142,4 +142,4 @@ CREATE TABLE IF NOT EXISTS git_forks (
142
142
  parent_id TEXT NOT NULL
143
143
  );
144
144
  `,I={repoInsert:"INSERT INTO git_repos (id) VALUES ($1)",repoExists:"SELECT 1 FROM git_repos WHERE id = $1 LIMIT 1",repoDelete:"DELETE FROM git_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)
145
- 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",forkInsert:"INSERT INTO git_forks (repo_id, parent_id) VALUES ($1, $2)",forkGetParent:"SELECT parent_id FROM git_forks WHERE repo_id = $1",forkListChildren:"SELECT repo_id FROM git_forks WHERE parent_id = $1",forkDelete:"DELETE FROM git_forks WHERE repo_id = $1"},jt=class r{constructor(e){this.pool=e}static async create(e){return await e.query(os),new r(e)}async transaction(e){let t=await this.pool.connect();try{await t.query("BEGIN");let n=await e((s,a)=>t.query(s,a));return await t.query("COMMIT"),n}catch(n){throw await t.query("ROLLBACK"),n}finally{t.release()}}async hasRepo(e){let{rows:t}=await this.pool.query(I.repoExists,[e]);return t.length>0}async insertRepo(e){await this.pool.query(I.repoInsert,[e])}async deleteRepo(e){await this.pool.query(I.repoDelete,[e]),await this.pool.query(I.objDeleteAll,[e]),await this.pool.query(I.refDeleteAll,[e]),await this.pool.query(I.forkDelete,[e])}async getObject(e,t){let{rows:n}=await this.pool.query(I.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.pool.query(I.objInsert,[e,t,n,s])}async putObjects(e,t){await this.transaction(async n=>{for(let s of t)await n(I.objInsert,[e,s.hash,s.type,s.content])})}async hasObject(e,t){let{rows:n}=await this.pool.query(I.objExists,[e,t]);return n.length>0}async findObjectsByPrefix(e,t){let{rows:n}=await this.pool.query(I.objPrefix,[e,`${t}%`]);return n.map(s=>s.hash)}async listObjectHashes(e){let{rows:t}=await this.pool.query(I.objListHashes,[e]);return t.map(n=>n.hash)}async deleteObjects(e,t){if(t.length===0)return 0;let{rows:n}=await this.pool.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.pool.query(I.refRead,[e,t]);return vt(n[0]??null)}async putRef(e,t,n){n.type==="symbolic"?await this.pool.query(I.refWrite,[e,t,"symbolic",null,n.target]):await this.pool.query(I.refWrite,[e,t,"direct",n.hash,null])}async removeRef(e,t){await this.pool.query(I.refDelete,[e,t])}async listRefs(e,t){let n;return t?{rows:n}=await this.pool.query(I.refList,[e,`${t}%`]):{rows:n}=await this.pool.query(I.refListAll,[e]),n.flatMap(s=>{let a=vt(s);return a?[{name:s.name,ref:a}]:[]})}async atomicRefUpdate(e,t){return this.transaction(async n=>t({getRef:async s=>{let{rows:a}=await n(I.refReadForUpdate,[e,s]);return vt(a[0]??null)},putRef:async(s,a)=>{a.type==="symbolic"?await n(I.refWrite,[e,s,"symbolic",null,a.target]):await n(I.refWrite,[e,s,"direct",a.hash,null])},removeRef:async s=>{await n(I.refDelete,[e,s])}}))}async forkRepo(e,t){await this.pool.query(I.forkInsert,[t,e])}async getForkParent(e){let{rows:t}=await this.pool.query(I.forkGetParent,[e]);return t[0]?.parent_id??null}async listForks(e){let{rows:t}=await this.pool.query(I.forkListChildren,[e]);return t.map(n=>n.repo_id)}};function vt(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{St as BetterSqlite3Storage,Pt as BunSqliteStorage,Te as MemoryStorage,jt as PgStorage,W as advertiseRefsWithHooks,Ve as applyCasRefUpdates,Oe as applyReceivePack,wt as buildRefAdvertisementBytes,Rt as buildRefListBytes,Ge as buildRefListPktLines,ut as buildV2CapabilityAdvertisement,Se as buildV2CapabilityAdvertisementBytes,re as buildV2FetchResponse,ht as buildV2LsRefsResponse,Sr as collectRefs,Gr as composeHooks,Qn as createServer,ve as handleLsRefs,Pe as handleUploadPack,je as handleV2Fetch,xt as ingestReceivePack,kt as ingestReceivePackFromStream,pt as parseV2CommandRequest,yt as parseV2FetchArgs,ze as resolveRefUpdates};
145
+ 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",forkInsert:"INSERT INTO git_forks (repo_id, parent_id) VALUES ($1, $2)",forkGetParent:"SELECT parent_id FROM git_forks WHERE repo_id = $1",forkListChildren:"SELECT repo_id FROM git_forks WHERE parent_id = $1",forkDelete:"DELETE FROM git_forks WHERE repo_id = $1"},jt=class r{constructor(e){this.pool=e}static async create(e){return await e.query(os),new r(e)}async transaction(e){let t=await this.pool.connect();try{await t.query("BEGIN");let n=await e((s,a)=>t.query(s,a));return await t.query("COMMIT"),n}catch(n){throw await t.query("ROLLBACK"),n}finally{t.release()}}async hasRepo(e){let{rows:t}=await this.pool.query(I.repoExists,[e]);return t.length>0}async insertRepo(e){await this.pool.query(I.repoInsert,[e])}async deleteRepo(e){await this.pool.query(I.repoDelete,[e]),await this.pool.query(I.objDeleteAll,[e]),await this.pool.query(I.refDeleteAll,[e]),await this.pool.query(I.forkDelete,[e])}async getObject(e,t){let{rows:n}=await this.pool.query(I.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.pool.query(I.objInsert,[e,t,n,s])}async putObjects(e,t){await this.transaction(async n=>{for(let s of t)await n(I.objInsert,[e,s.hash,s.type,s.content])})}async hasObject(e,t){let{rows:n}=await this.pool.query(I.objExists,[e,t]);return n.length>0}async findObjectsByPrefix(e,t){let{rows:n}=await this.pool.query(I.objPrefix,[e,`${t}%`]);return n.map(s=>s.hash)}async listObjectHashes(e){let{rows:t}=await this.pool.query(I.objListHashes,[e]);return t.map(n=>n.hash)}async deleteObjects(e,t){if(t.length===0)return 0;let{rows:n}=await this.pool.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.pool.query(I.refRead,[e,t]);return vt(n[0]??null)}async putRef(e,t,n){n.type==="symbolic"?await this.pool.query(I.refWrite,[e,t,"symbolic",null,n.target]):await this.pool.query(I.refWrite,[e,t,"direct",n.hash,null])}async removeRef(e,t){await this.pool.query(I.refDelete,[e,t])}async listRefs(e,t){let n;return t?{rows:n}=await this.pool.query(I.refList,[e,`${t}%`]):{rows:n}=await this.pool.query(I.refListAll,[e]),n.flatMap(s=>{let a=vt(s);return a?[{name:s.name,ref:a}]:[]})}async atomicRefUpdate(e,t){return this.transaction(async n=>t({getRef:async s=>{let{rows:a}=await n(I.refReadForUpdate,[e,s]);return vt(a[0]??null)},putRef:async(s,a)=>{a.type==="symbolic"?await n(I.refWrite,[e,s,"symbolic",null,a.target]):await n(I.refWrite,[e,s,"direct",a.hash,null])},removeRef:async s=>{await n(I.refDelete,[e,s])}}))}async forkRepo(e,t){await this.pool.query(I.forkInsert,[t,e])}async getForkParent(e){let{rows:t}=await this.pool.query(I.forkGetParent,[e]);return t[0]?.parent_id??null}async listForks(e){let{rows:t}=await this.pool.query(I.forkListChildren,[e]);return t.map(n=>n.repo_id)}};function vt(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{St as BetterSqlite3Storage,Pt as BunSqliteStorage,Te as MemoryStorage,jt as PgStorage,W as advertiseRefsWithHooks,Ve as applyCasRefUpdates,Oe as applyReceivePack,wt as buildRefAdvertisementBytes,Rt as buildRefListBytes,Ge as buildRefListPktLines,ut as buildV2CapabilityAdvertisement,Se as buildV2CapabilityAdvertisementBytes,ne as buildV2FetchResponse,ht as buildV2LsRefsResponse,Sr as collectRefs,Gr as composeHooks,Qn as createServer,ve as handleLsRefs,Pe as handleUploadPack,je as handleV2Fetch,xt as ingestReceivePack,kt as ingestReceivePackFromStream,pt as parseV2CommandRequest,yt as parseV2FetchArgs,ze as resolveRefUpdates};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-git",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "description": "Pure TypeScript git implementation: virtual filesystem client and embeddable server.",
5
5
  "keywords": [
6
6
  "agent",