just-git 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,23 @@
1
1
  import { _ as ObjectId, $ as Identity, d as GitContext, f as GitRepo, F as FileSystem, a0 as TreeDiffEntry, V as RefEntry, a1 as Commit, O as ObjectStore, a2 as ObjectType, a3 as RawObject, a as RefStore, a4 as Ref } from '../hooks-4DvkF2xT.js';
2
2
 
3
+ interface BlameEntry {
4
+ hash: ObjectId;
5
+ origPath: string;
6
+ /** 1-based line number in the originating commit's version. */
7
+ origLine: number;
8
+ /** 1-based line number in the final file. */
9
+ finalLine: number;
10
+ content: string;
11
+ author: Identity;
12
+ committer: Identity;
13
+ summary: string;
14
+ boundary: boolean;
15
+ previous?: {
16
+ hash: ObjectId;
17
+ path: string;
18
+ };
19
+ }
20
+
3
21
  interface MergeConflict {
4
22
  path: string;
5
23
  reason: "content" | "delete-modify" | "add-add" | "rename-delete" | "rename-rename" | "directory-rename";
@@ -224,6 +242,33 @@ interface WorktreeResult {
224
242
  * ```
225
243
  */
226
244
  declare function createWorktree(repo: GitRepo, fs: FileSystem, options?: CreateWorktreeOptions): Promise<WorktreeResult>;
245
+ /**
246
+ * Count how many commits `localHash` is ahead of and behind `upstreamHash`.
247
+ * Useful for tracking info display and branch comparison.
248
+ */
249
+ declare function countAheadBehind(repo: GitRepo, localHash: string, upstreamHash: string): Promise<{
250
+ ahead: number;
251
+ behind: number;
252
+ }>;
253
+
254
+ /**
255
+ * Compute line-by-line blame for a file at a given commit.
256
+ * Returns one entry per line with the originating commit, author, and content.
257
+ * Optionally restrict to a line range with `startLine` / `endLine` (1-based).
258
+ */
259
+ declare function blame(repo: GitRepo, commitHash: string, path: string, opts?: {
260
+ startLine?: number;
261
+ endLine?: number;
262
+ }): Promise<BlameEntry[]>;
263
+ /**
264
+ * Walk the commit graph starting from one or more hashes, yielding
265
+ * commits in reverse chronological order. Supports excluding commits
266
+ * reachable from specified hashes and following only first parents.
267
+ */
268
+ declare function walkCommitHistory(repo: GitRepo, startHash: string | string[], opts?: {
269
+ exclude?: string[];
270
+ firstParent?: boolean;
271
+ }): AsyncGenerator<CommitInfo>;
227
272
  /**
228
273
  * Wrap a `GitRepo` so all write operations throw.
229
274
  *
@@ -295,4 +340,4 @@ declare class FileSystemRefStore implements RefStore {
295
340
  private walkRefs;
296
341
  }
297
342
 
298
- export { type CheckoutToResult, type CommitInfo, type CreateCommitOptions, type CreateWorktreeOptions, FileSystemRefStore, GitRepo, Identity, type MergeConflict, type MergeTreesResult, PackedObjectStore, type TreeEntryInput, type WorktreeResult, checkoutTo, createCommit, createWorktree, diffTrees, findMergeBases, flattenTree, getChangedFiles, getNewCommits, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, readBlob, readBlobText, readCommit, readFileAtCommit, readonlyRepo, resolveRef, writeBlob, writeTree };
343
+ export { type BlameEntry, type CheckoutToResult, type CommitInfo, type CreateCommitOptions, type CreateWorktreeOptions, FileSystemRefStore, GitRepo, Identity, type MergeConflict, type MergeTreesResult, PackedObjectStore, type TreeEntryInput, type WorktreeResult, blame, checkoutTo, countAheadBehind, createCommit, createWorktree, diffTrees, findMergeBases, flattenTree, getChangedFiles, getNewCommits, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, readBlob, readBlobText, readCommit, readFileAtCommit, readonlyRepo, resolveRef, walkCommitHistory, writeBlob, writeTree };
@@ -1,18 +1,20 @@
1
- var ke=(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')});function Rn(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.split("/"),s=[];for(let a of r)a===""||a==="."||(a===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(a));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function L(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":Rn(e)}function _e(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 It=(()=>{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 oe(t){let e="";for(let n=0;n<20;n++)e+=It[t[n]];return e}function Ee(t,e){let n="";for(let r=0;r<20;r++)n+=It[t[e+r]];return n}function Y(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 kn=new TextEncoder;function We(t){return typeof t=="string"?kn.encode(t):t}function En(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(We(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=ke(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(We(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(We(n)),e},async hex(){let n=0;for(let a of t)n+=a.byteLength;let r=new Uint8Array(n),s=0;for(let a of t)r.set(a,s),s+=a.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return oe(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 Ot=En(),Se=Ot;async function Te(t){return Ot().update(t).hex()}var Sn=1145655875,Tn=2;async function ze(t,e){let n=L(t.gitDir,"index"),r=await jn(e);await t.fs.writeFile(n,r)}function Pt(t){let e=[...t].sort(Rt);return{version:Tn,entries:e}}function ne(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function jn(t){let e=new TextEncoder,n=[...t.entries].sort(Rt),r=[],s=12;for(let d of n){let l=e.encode(d.path);r.push(l);let m=62+l.byteLength+1;s+=Math.ceil(m/8)*8}s+=20;let i=new ArrayBuffer(s),a=new Uint8Array(i),o=new DataView(i),c=0;o.setUint32(c,Sn),c+=4,o.setUint32(c,t.version),c+=4,o.setUint32(c,n.length),c+=4;for(let d=0;d<n.length;d++){let l=n[d],m=r[d],y=c;o.setUint32(c,l.stat.ctimeSeconds),o.setUint32(c+4,l.stat.ctimeNanoseconds),o.setUint32(c+8,l.stat.mtimeSeconds),o.setUint32(c+12,l.stat.mtimeNanoseconds),o.setUint32(c+16,l.stat.dev),o.setUint32(c+20,l.stat.ino),o.setUint32(c+24,l.mode),o.setUint32(c+28,l.stat.uid),o.setUint32(c+32,l.stat.gid),o.setUint32(c+36,l.stat.size),c+=40;let p=Y(l.hash);a.set(p,c),c+=20;let x=Math.min(m.byteLength,4095),R=(l.stage&3)<<12|x;o.setUint16(c,R),c+=2,a.set(m,c),c+=m.byteLength,a[c]=0,c+=1;let j=62+m.byteLength+1,T=Math.ceil(j/8)*8;c=y+T}let f=a.subarray(0,c),u=await Te(f),h=Y(u);return a.set(h,c),a}function Rt(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}var An=new Set(["tree","commit","tag"]),je=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,n){if(!An.has(n.type))return;let r=n.content.byteLength;if(!(r>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+r>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,n),this.currentBytes+=r}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var kt=new Uint32Array(256);for(let t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;kt[t]=e}function Et(t){let e=4294967295;for(let n=0;n<t.byteLength;n++)e=kt[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}var J=Uint8Array,fe=Uint16Array,Cn=Int32Array,St=new J([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]),Tt=new J([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]),$n=new J([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),jt=(t,e)=>{let n=new fe(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new Cn(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:At}=jt(St,2);At[28]=258;var{b:Mn}=jt(Tt,0),qe=new fe(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,qe[t]=((e&65280)>>8|(e&255)<<8)>>1}var ye=(t,e,n)=>{let r=t.length,s=0,i=new fe(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let a=new fe(e);for(s=1;s<e;++s)a[s]=a[s-1]+i[s-1]<<1;let o;if(n){o=new fe(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let f=s<<4|t[s],u=e-t[s],h=a[t[s]-1]++<<u;for(let d=h|(1<<u)-1;h<=d;++h)o[qe[h]>>c]=f}}else for(o=new fe(r),s=0;s<r;++s)t[s]&&(o[s]=qe[a[t[s]-1]++]>>15-t[s]);return o},be=new J(288);for(let t=0;t<144;++t)be[t]=8;for(let t=144;t<256;++t)be[t]=9;for(let t=256;t<280;++t)be[t]=7;for(let t=280;t<288;++t)be[t]=8;var Ct=new J(32);for(let t=0;t<32;++t)Ct[t]=5;var vn=ye(be,9,1),Ln=ye(Ct,5,1),Ve=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},Ke=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},$t=t=>(t+7)/8|0,Un=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new J(t.subarray(e,n))),Z=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},Mt=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new J(0);let a=!n,o=a||e.i!=2,c=e.i;a&&(n=new J(s*3));let f=R=>{let j=n.length;if(R>j){let T=new J(Math.max(j*2,R));T.set(n),n=T}},u=e.f||0,h=e.p||0,d=e.b||0,l=e.l,m=e.d,y=e.m,p=e.n,x=s*8;do{if(!l){u=X(t,h,1);let I=X(t,h+1,3);if(h+=3,I)if(I==1)l=vn,m=Ln,y=9,p=5;else if(I==2){let w=X(t,h,31)+257,E=X(t,h+10,15)+4,$=w+X(t,h+5,31)+1;h+=14;let S=new J($),k=new J(19);for(let g=0;g<E;++g)k[$n[g]]=X(t,h+g*3,7);h+=E*3;let M=Ve(k),B=(1<<M)-1,N=ye(k,M,1);for(let g=0;g<$;){let O=N[X(t,h,B)];h+=O&15;let C=O>>4;if(C<16)S[g++]=C;else{let A=0,P=0;for(C==16?(P=3+X(t,h,3),h+=2,A=S[g-1]):C==17?(P=3+X(t,h,7),h+=3):C==18&&(P=11+X(t,h,127),h+=7);P--;)S[g++]=A}}let ge=S.subarray(0,w),b=S.subarray(w);y=Ve(ge),p=Ve(b),l=ye(ge,y,1),m=ye(b,p,1)}else Z(1);else{let w=$t(h)+4,E=t[w-4]|t[w-3]<<8,$=w+E;if($>s){c&&Z(0);break}o&&f(d+E),n.set(t.subarray(w,$),d),e.b=d+=E,e.p=h=$*8,e.f=u;continue}if(h>x){c&&Z(0);break}}o&&f(d+131072);let R=(1<<y)-1,j=(1<<p)-1,T=h;for(;;T=h){let I=l[Ke(t,h)&R],w=I>>4;if(h+=I&15,h>x){c&&Z(0);break}if(I||Z(2),w<256)n[d++]=w;else if(w==256){T=h,l=null;break}else{let E=w-254;if(w>264){let B=w-257,N=St[B];E=X(t,h,(1<<N)-1)+At[B],h+=N}let $=m[Ke(t,h)&j],S=$>>4;$||Z(3),h+=$&15;let k=Mn[S];if(S>3){let B=Tt[S];k+=Ke(t,h)&(1<<B)-1,h+=B}if(h>x){c&&Z(0);break}o&&f(d+131072);let M=d+E;if(d<k){let B=i-k,N=Math.min(k,M);for(B+d<0&&Z(3);d<N;++d)n[d]=r[B+d]}for(;d<M;++d)n[d]=n[d-k]}}e.l=l,e.p=T,e.b=d,e.f=u,l&&(u=1,e.m=y,e.d=m,e.n=p)}while(!u);return d!=n.length&&a?Un(n,0,d):n.subarray(0,d)},vt=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&Z(0,"invalid zlib data"),t[1]&32&&Z(0,"zlib dictionaries are not supported"),2);function Lt(t){let e=vt(t);return Mt(t.subarray(e,-4),{i:2})}function Ye(t){let e=vt(t),n={i:2},r=Mt(t.subarray(e),n),s=$t(n.p);return{result:r,bytesConsumed:e+s+4}}async function Bn(){let t;if(!(typeof document<"u"))try{t=ke(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let a=t.inflateSync(i,{info:!0});return{result:new Uint8Array(a.buffer),bytesConsumed:a.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??Ye}}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:Lt,inflateWithConsumed:Ye}}var Dn=null;function Xe(){return Dn??=Bn()}async function Je(t){return await(await Xe()).deflateSync(t)}async function le(t){return await(await Xe()).inflateSync(t)}async function Ut(t,e){let n=await Xe(),{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 Bt=1346454347,Hn=2,Nn=1,Fn=2,Gn=3,_n=4,Ae=6,Qe=7,Wn={[Nn]:"commit",[Fn]:"tree",[Gn]:"blob",[_n]:"tag"};async function Ht(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==Bt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Bt.toString(16)})`);let s=n.getUint32(4);if(s!==Hn)throw new Error(`Unsupported pack version: ${s}`);let i=n.getUint32(8),a=[],o=12;for(let f=0;f<i;f++){let u=await zn(t,o);a.push(u),o=u.nextOffset}return(await Vn(a,e)).map((f,u)=>({...f,offset:a[u].headerOffset,nextOffset:a[u].nextOffset}))}async function zn(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,a=4;for(;r&128;)r=t[e++],i|=(r&127)<<a,a+=7;let o,c;if(s===Ae){let h=t[e++];for(o=h&127;h&128;)o+=1,h=t[e++],o=(o<<7)+(h&127);o=n-o}else s===Qe&&(c=Ee(t,e),e+=20);let{result:f,bytesConsumed:u}=await Ut(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:f,baseOffset:o,baseHash:c,nextOffset:e+u}}async function Vn(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){let a=r[i];if(a)return a;let o=t[i];if(o.typeNum!==Ae&&o.typeNum!==Qe){let d=Wn[o.typeNum];if(!d)throw new Error(`Unknown object type: ${o.typeNum}`);let l={type:d,content:o.inflated,hash:await Ze(d,o.inflated)};return r[i]=l,l}if(o.typeNum===Ae){let d=n.get(o.baseOffset);if(d===void 0)throw new Error(`OFS_DELTA base not found at offset ${o.baseOffset}`);let l=await s(d),m=we(l.content,o.inflated),y={type:l.type,content:m,hash:await Ze(l.type,m)};return r[i]=y,y}let c=await Kn(t,r,o.baseHash,s),f;if(c!==void 0)f=await s(c);else if(e){let d=await e(o.baseHash);d&&(f=d)}if(!f)throw new Error(`REF_DELTA base not found for hash ${o.baseHash}`);let u=we(f.content,o.inflated),h={type:f.type,content:u,hash:await Ze(f.type,u)};return r[i]=h,h}for(let i=0;i<t.length;i++)await s(i);return r}async function Kn(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!==Ae&&i.typeNum!==Qe&&(await r(s)).hash===n)return s}}function we(t,e){let n=0,{value:r,newPos:s}=Dt(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:a}=Dt(e,n);n=a;let o=new Uint8Array(i),c=0;for(;n<e.byteLength;){let f=e[n++];if(f&128){let u=0,h=0;f&1&&(u=e[n++]),f&2&&(u|=e[n++]<<8),f&4&&(u|=e[n++]<<16),f&8&&(u|=e[n++]<<24),f&16&&(h=e[n++]),f&32&&(h|=e[n++]<<8),f&64&&(h|=e[n++]<<16),h===0&&(h=65536),o.set(t.subarray(u,u+h),c),c+=h}else if(f>0)o.set(e.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return o}function Dt(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 qn=new TextEncoder;async function Ze(t,e){let n=qn.encode(`${t} ${e.byteLength}\0`),r=Se();return r.update(n),r.update(e),r.hex()}var Nt=4285812579,Ft=2,re=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(0)!==Nt)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==Ft)throw new Error(`Unsupported pack index version: ${n.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let i=0;i<256;i++)this.fanout[i]=n.getUint32(r),r+=4;this.count=this.fanout[255],this.hashes=new Uint8Array(e.buffer,e.byteOffset+r,this.count*20),r+=this.count*20,r+=this.count*4,this.offsets=new Uint32Array(this.count);for(let i=0;i<this.count;i++)this.offsets[i]=n.getUint32(r),r+=4;let s=!1;for(let i=0;i<this.count;i++)if(this.offsets[i]&2147483648){s=!0;break}this.largeOffsets=s?new DataView(e.buffer,e.byteOffset+r):null}lookup(e){let n=Y(e),r=n[0],s=r===0?0:this.fanout[r-1],i=this.fanout[r],a=s,o=i;for(;a<o;){let c=a+o>>>1,f=this.compareAt(c,n);if(f<0)a=c+1;else if(f>0)o=c;else return this.getOffset(c)}return null}has(e){return this.lookup(e)!==null}get objectCount(){return this.count}allHashes(){let e=[];for(let n=0;n<this.count;n++)e.push(this.hashAtSlot(n));return e}findByPrefix(e){if(e.length<2)return[];let n=parseInt(e.slice(0,2),16),r=n===0?0:this.fanout[n-1],s=this.fanout[n],i=Y(e.padEnd(40,"0")),a=e.length,o=[];for(let c=r;c<s;c++){let f=c*20,u=!0;for(let h=0;h<a;h++){let d=h%2===0?this.hashes[f+(h>>1)]>>4&15:this.hashes[f+(h>>1)]&15,l=h%2===0?i[h>>1]>>4&15:i[h>>1]&15;if(d!==l){u=!1;break}}u&&o.push(this.hashAtSlot(c))}return o}hashAtSlot(e){let n="",r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s];n+=(i>>4).toString(16)+(i&15).toString(16)}return n}compareAt(e,n){let r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s],a=n[s];if(i<a)return-1;if(i>a)return 1}return 0}getOffset(e){let n=this.offsets[e];if(n&2147483648){let r=n&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return n}};async function Yn(t,e){let n=[...t].sort((l,m)=>l.hash<m.hash?-1:l.hash>m.hash?1:0),r=n.length,s=[];for(let l of n)l.offset>=2147483648&&s.push(BigInt(l.offset));let i=8+256*4+r*20+r*4+r*4+s.length*8+20+20,a=new Uint8Array(i),o=new DataView(a.buffer),c=0;o.setUint32(c,Nt),c+=4,o.setUint32(c,Ft),c+=4;let f=new Uint32Array(256);for(let l of n){let m=parseInt(l.hash.slice(0,2),16);for(let y=m;y<256;y++)f[y]++}for(let l=0;l<256;l++)o.setUint32(c,f[l]),c+=4;for(let l of n)a.set(Y(l.hash),c),c+=20;for(let l of n)o.setUint32(c,l.crc),c+=4;let u=0;for(let l of n)l.offset>=2147483648?o.setUint32(c,2147483648|u++):o.setUint32(c,l.offset),c+=4;for(let l of s)o.setBigUint64(c,l),c+=8;a.set(e,c),c+=20;let h=Se();h.update(a.subarray(0,c));let d=await h.hex();return a.set(Y(d),c),a}async function Gt(t){let n=(await Ht(t)).map(s=>({hash:s.hash,offset:s.offset,crc:Et(t.subarray(s.offset,s.nextOffset))})),r=t.subarray(t.byteLength-20);return Yn(n,r)}var Xn=6,Jn=7,Zn={1:"commit",2:"tree",3:"blob",4:"tag"},xe=class{constructor(e,n){this.data=e;this.index=n instanceof re?n:new re(n)}index;hasObject(e){return this.index.has(e)}findByPrefix(e){return this.index.findByPrefix(e)}async readObject(e){let n=this.index.lookup(e);return n===null?null:this.readAt(n)}get objectCount(){return this.index.objectCount}async readAt(e){let n=this.data,r=e,s=n[r++],i=s>>4&7,a=s&15,o=4;for(;s&128;)s=n[r++],a|=(s&127)<<o,o+=7;if(i===Xn){let u=n[r++],h=u&127;for(;u&128;)h+=1,u=n[r++],h=(h<<7)+(u&127);let d=await le(n.subarray(r)),l=await this.readAt(e-h);return{type:l.type,content:we(l.content,d)}}if(i===Jn){let u=Ee(n,r);r+=20;let h=await le(n.subarray(r)),d=this.index.lookup(u);if(d===null)throw new Error(`REF_DELTA base ${u} not found in pack`);let l=await this.readAt(d);return{type:l.type,content:we(l.content,h)}}let c=Zn[i];if(!c)throw new Error(`Unknown pack object type: ${i}`);let f=await le(n.subarray(r));if(f.byteLength!==a)throw new Error(`Pack inflate size mismatch at offset ${e}: got ${f.byteLength}, expected ${a}`);return{type:c,content:f}}};var Qn=new TextEncoder,er=new TextDecoder;function tr(t,e){let n=Qn.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function nr(t,e){let n=e.indexOf(0);if(n===-1)throw new Error(`Corrupt object ${t}: no null byte in header`);let r=er.decode(e.subarray(0,n)),s=r.indexOf(" ");if(s===-1)throw new Error(`Corrupt object ${t}: malformed header "${r}"`);let i=r.slice(0,s),a=parseInt(r.slice(s+1),10),o=e.subarray(n+1);if(o.byteLength!==a)throw new Error(`Corrupt object ${t}: expected ${a} bytes, got ${o.byteLength}`);return{type:i,content:o}}function et(t,e){return L(t,"objects",e.slice(0,2),e.slice(2))}var tt=class{constructor(e,n,r){this.fs=e;this.gitDir=n;this.cache=new je(r),this.packDir=L(n,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(e,n){let r=tr(e,n),s=await Te(r),i=et(this.gitDir,s);if(await this.fs.exists(i))return s;let a=L(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(a,{recursive:!0}),await this.fs.writeFile(i,await Je(r)),s}async read(e){let n=this.cache.get(e);if(n)return n;let r=et(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await le(s),a=nr(e,i);return this.cache.set(e,a),a}await this.discover();for(let s of this.packs){if(!s.index.has(e))continue;let a=await(await this.ensureReader(s)).readObject(e);if(a)return this.cache.set(e,a),a}throw new Error(`object ${e} not found`)}async exists(e){if(await this.fs.exists(et(this.gitDir,e)))return!0;await this.discover();for(let n of this.packs)if(n.index.has(e))return!0;return!1}async ingestPack(e){if(e.byteLength<32)return 0;let r=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8);if(r===0)return 0;let s=e.subarray(e.byteLength-20),i=oe(s);await this.fs.mkdir(this.packDir,{recursive:!0});let a=`pack-${i}`,o=L(this.packDir,`${a}.pack`);await this.fs.writeFile(o,e);let c=await Gt(e),f=L(this.packDir,`${a}.idx`);await this.fs.writeFile(f,c),this.loadedPackNames.add(a);let u=new re(c);return this.packs.push({name:a,index:u,reader:new xe(e,u)}),r}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(e){if(e.length<4)return[];let n=e.slice(0,2),r=e.slice(2),s=L(this.gitDir,"objects",n),i=[];if(await this.fs.exists(s)){let a=await this.fs.readdir(s);for(let o of a)o.startsWith(r)&&i.push(`${n}${o}`)}await this.discover();for(let a of this.packs)for(let o of a.index.findByPrefix(e))i.includes(o)||i.push(o);return i}async ensureReader(e){if(e.reader)return e.reader;let n=L(this.packDir,`${e.name}.pack`),r=await this.fs.readFileBuffer(n);return e.reader=new xe(r,e.index),e.reader}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){if(!await this.fs.exists(this.packDir))return;let e=await this.fs.readdir(this.packDir);for(let n of e){if(!n.endsWith(".idx"))continue;let r=n.slice(0,-4);if(this.loadedPackNames.has(r))continue;let s=L(this.packDir,`${r}.pack`);if(!await this.fs.exists(s))continue;let i=await this.fs.readFileBuffer(L(this.packDir,n));this.loadedPackNames.add(r),this.packs.push({name:r,index:new re(i),reader:null})}}};function nt(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[a="0",o="+0000"]=i.split(" "),c=parseInt(a,10);return{name:r,email:s,timestamp:c,timezone:o}}function rt(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var rr=new TextEncoder,sr=new TextDecoder;function _t(t){let e=sr.decode(t),n=e.indexOf(`
1
+ var Ae=(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')});function An(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.split("/"),s=[];for(let a of r)a===""||a==="."||(a===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(a));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function D(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":An(e)}function Xe(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 Et=(()=>{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 le(t){let e="";for(let n=0;n<20;n++)e+=Et[t[n]];return e}function $e(t,e){let n="";for(let r=0;r<20;r++)n+=Et[t[e+r]];return n}function Y(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 $n=new TextEncoder;function Je(t){return typeof t=="string"?$n.encode(t):t}function Ln(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(Je(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=Ae(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(Je(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(Je(n)),e},async hex(){let n=0;for(let a of t)n+=a.byteLength;let r=new Uint8Array(n),s=0;for(let a of t)r.set(a,s),s+=a.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return le(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 St=Ln(),Le=St;async function Me(t){return St().update(t).hex()}var Mn=1145655875,vn=2;async function Ze(t,e){let n=D(t.gitDir,"index"),r=await Un(e);await t.fs.writeFile(n,r)}function Tt(t){let e=[...t].sort(jt);return{version:vn,entries:e}}function re(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function Un(t){let e=new TextEncoder,n=[...t.entries].sort(jt),r=[],s=12;for(let d of n){let l=e.encode(d.path);r.push(l);let m=62+l.byteLength+1;s+=Math.ceil(m/8)*8}s+=20;let i=new ArrayBuffer(s),a=new Uint8Array(i),o=new DataView(i),c=0;o.setUint32(c,Mn),c+=4,o.setUint32(c,t.version),c+=4,o.setUint32(c,n.length),c+=4;for(let d=0;d<n.length;d++){let l=n[d],m=r[d],g=c;o.setUint32(c,l.stat.ctimeSeconds),o.setUint32(c+4,l.stat.ctimeNanoseconds),o.setUint32(c+8,l.stat.mtimeSeconds),o.setUint32(c+12,l.stat.mtimeNanoseconds),o.setUint32(c+16,l.stat.dev),o.setUint32(c+20,l.stat.ino),o.setUint32(c+24,l.mode),o.setUint32(c+28,l.stat.uid),o.setUint32(c+32,l.stat.gid),o.setUint32(c+36,l.stat.size),c+=40;let p=Y(l.hash);a.set(p,c),c+=20;let I=Math.min(m.byteLength,4095),k=(l.stage&3)<<12|I;o.setUint16(c,k),c+=2,a.set(m,c),c+=m.byteLength,a[c]=0,c+=1;let C=62+m.byteLength+1,A=Math.ceil(C/8)*8;c=g+A}let f=a.subarray(0,c),u=await Me(f),h=Y(u);return a.set(h,c),a}function jt(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}var Bn=new Set(["tree","commit","tag"]),ve=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,n){if(!Bn.has(n.type))return;let r=n.content.byteLength;if(!(r>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+r>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,n),this.currentBytes+=r}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var Ct=new Uint32Array(256);for(let t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;Ct[t]=e}function At(t){let e=4294967295;for(let n=0;n<t.byteLength;n++)e=Ct[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}var J=Uint8Array,me=Uint16Array,Dn=Int32Array,$t=new J([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Lt=new J([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]),Hn=new J([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Mt=(t,e)=>{let n=new me(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new Dn(n[30]);for(let s=1;s<30;++s)for(let i=n[s];i<n[s+1];++i)r[i]=i-n[s]<<5|s;return{b:n,r}},{b:vt}=Mt($t,2);vt[28]=258;var{b:Nn}=Mt(Lt,0),tt=new me(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,tt[t]=((e&65280)>>8|(e&255)<<8)>>1}var xe=(t,e,n)=>{let r=t.length,s=0,i=new me(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let a=new me(e);for(s=1;s<e;++s)a[s]=a[s-1]+i[s-1]<<1;let o;if(n){o=new me(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let f=s<<4|t[s],u=e-t[s],h=a[t[s]-1]++<<u;for(let d=h|(1<<u)-1;h<=d;++h)o[tt[h]>>c]=f}}else for(o=new me(r),s=0;s<r;++s)t[s]&&(o[s]=tt[a[t[s]-1]++]>>15-t[s]);return o},Oe=new J(288);for(let t=0;t<144;++t)Oe[t]=8;for(let t=144;t<256;++t)Oe[t]=9;for(let t=256;t<280;++t)Oe[t]=7;for(let t=280;t<288;++t)Oe[t]=8;var Ut=new J(32);for(let t=0;t<32;++t)Ut[t]=5;var Fn=xe(Oe,9,1),Gn=xe(Ut,5,1),Qe=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},et=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},Bt=t=>(t+7)/8|0,_n=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new J(t.subarray(e,n))),Z=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},Dt=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new J(0);let a=!n,o=a||e.i!=2,c=e.i;a&&(n=new J(s*3));let f=k=>{let C=n.length;if(k>C){let A=new J(Math.max(C*2,k));A.set(n),n=A}},u=e.f||0,h=e.p||0,d=e.b||0,l=e.l,m=e.d,g=e.m,p=e.n,I=s*8;do{if(!l){u=X(t,h,1);let P=X(t,h+1,3);if(h+=3,P)if(P==1)l=Fn,m=Gn,g=9,p=5;else if(P==2){let y=X(t,h,31)+257,O=X(t,h+10,15)+4,T=y+X(t,h+5,31)+1;h+=14;let x=new J(T),R=new J(19);for(let b=0;b<O;++b)R[Hn[b]]=X(t,h+b*3,7);h+=O*3;let S=Qe(R),$=(1<<S)-1,v=xe(R,S,1);for(let b=0;b<T;){let E=v[X(t,h,$)];h+=E&15;let M=E>>4;if(M<16)x[b++]=M;else{let L=0,j=0;for(M==16?(j=3+X(t,h,3),h+=2,L=x[b-1]):M==17?(j=3+X(t,h,7),h+=3):M==18&&(j=11+X(t,h,127),h+=7);j--;)x[b++]=L}}let ne=x.subarray(0,y),w=x.subarray(y);g=Qe(ne),p=Qe(w),l=xe(ne,g,1),m=xe(w,p,1)}else Z(1);else{let y=Bt(h)+4,O=t[y-4]|t[y-3]<<8,T=y+O;if(T>s){c&&Z(0);break}o&&f(d+O),n.set(t.subarray(y,T),d),e.b=d+=O,e.p=h=T*8,e.f=u;continue}if(h>I){c&&Z(0);break}}o&&f(d+131072);let k=(1<<g)-1,C=(1<<p)-1,A=h;for(;;A=h){let P=l[et(t,h)&k],y=P>>4;if(h+=P&15,h>I){c&&Z(0);break}if(P||Z(2),y<256)n[d++]=y;else if(y==256){A=h,l=null;break}else{let O=y-254;if(y>264){let $=y-257,v=$t[$];O=X(t,h,(1<<v)-1)+vt[$],h+=v}let T=m[et(t,h)&C],x=T>>4;T||Z(3),h+=T&15;let R=Nn[x];if(x>3){let $=Lt[x];R+=et(t,h)&(1<<$)-1,h+=$}if(h>I){c&&Z(0);break}o&&f(d+131072);let S=d+O;if(d<R){let $=i-R,v=Math.min(R,S);for($+d<0&&Z(3);d<v;++d)n[d]=r[$+d]}for(;d<S;++d)n[d]=n[d-R]}}e.l=l,e.p=A,e.b=d,e.f=u,l&&(u=1,e.m=g,e.d=m,e.n=p)}while(!u);return d!=n.length&&a?_n(n,0,d):n.subarray(0,d)},Ht=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&Z(0,"invalid zlib data"),t[1]&32&&Z(0,"zlib dictionaries are not supported"),2);function Nt(t){let e=Ht(t);return Dt(t.subarray(e,-4),{i:2})}function nt(t){let e=Ht(t),n={i:2},r=Dt(t.subarray(e),n),s=Bt(n.p);return{result:r,bytesConsumed:e+s+4}}async function Wn(){let t;if(!(typeof document<"u"))try{t=Ae(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let a=t.inflateSync(i,{info:!0});return{result:new Uint8Array(a.buffer),bytesConsumed:a.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??nt}}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:nt}}var zn=null;function rt(){return zn??=Wn()}async function st(t){return await(await rt()).deflateSync(t)}async function pe(t){return await(await rt()).inflateSync(t)}async function Ft(t,e){let n=await rt(),{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,Vn=2,Kn=1,qn=2,Yn=3,Xn=4,Ue=6,ot=7,Jn={[Kn]:"commit",[qn]:"tree",[Yn]:"blob",[Xn]:"tag"};async function Wt(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!==Vn)throw new Error(`Unsupported pack version: ${s}`);let i=n.getUint32(8),a=[],o=12;for(let f=0;f<i;f++){let u=await Zn(t,o);a.push(u),o=u.nextOffset}return(await Qn(a,e)).map((f,u)=>({...f,offset:a[u].headerOffset,nextOffset:a[u].nextOffset}))}async function Zn(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,a=4;for(;r&128;)r=t[e++],i|=(r&127)<<a,a+=7;let o,c;if(s===Ue){let h=t[e++];for(o=h&127;h&128;)o+=1,h=t[e++],o=(o<<7)+(h&127);o=n-o}else s===ot&&(c=$e(t,e),e+=20);let{result:f,bytesConsumed:u}=await Ft(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:f,baseOffset:o,baseHash:c,nextOffset:e+u}}async function Qn(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){let a=r[i];if(a)return a;let o=t[i];if(o.typeNum!==Ue&&o.typeNum!==ot){let d=Jn[o.typeNum];if(!d)throw new Error(`Unknown object type: ${o.typeNum}`);let l={type:d,content:o.inflated,hash:await it(d,o.inflated)};return r[i]=l,l}if(o.typeNum===Ue){let d=n.get(o.baseOffset);if(d===void 0)throw new Error(`OFS_DELTA base not found at offset ${o.baseOffset}`);let l=await s(d),m=Pe(l.content,o.inflated),g={type:l.type,content:m,hash:await it(l.type,m)};return r[i]=g,g}let c=await er(t,r,o.baseHash,s),f;if(c!==void 0)f=await s(c);else if(e){let d=await e(o.baseHash);d&&(f=d)}if(!f)throw new Error(`REF_DELTA base not found for hash ${o.baseHash}`);let u=Pe(f.content,o.inflated),h={type:f.type,content:u,hash:await it(f.type,u)};return r[i]=h,h}for(let i=0;i<t.length;i++)await s(i);return r}async function er(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!==Ue&&i.typeNum!==ot&&(await r(s)).hash===n)return s}}function Pe(t,e){let n=0,{value:r,newPos:s}=_t(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:a}=_t(e,n);n=a;let o=new Uint8Array(i),c=0;for(;n<e.byteLength;){let f=e[n++];if(f&128){let u=0,h=0;f&1&&(u=e[n++]),f&2&&(u|=e[n++]<<8),f&4&&(u|=e[n++]<<16),f&8&&(u|=e[n++]<<24),f&16&&(h=e[n++]),f&32&&(h|=e[n++]<<8),f&64&&(h|=e[n++]<<16),h===0&&(h=65536),o.set(t.subarray(u,u+h),c),c+=h}else if(f>0)o.set(e.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return o}function _t(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 tr=new TextEncoder;async function it(t,e){let n=tr.encode(`${t} ${e.byteLength}\0`),r=Le();return r.update(n),r.update(e),r.hex()}var zt=4285812579,Vt=2,se=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(0)!==zt)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==Vt)throw new Error(`Unsupported pack index version: ${n.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let i=0;i<256;i++)this.fanout[i]=n.getUint32(r),r+=4;this.count=this.fanout[255],this.hashes=new Uint8Array(e.buffer,e.byteOffset+r,this.count*20),r+=this.count*20,r+=this.count*4,this.offsets=new Uint32Array(this.count);for(let i=0;i<this.count;i++)this.offsets[i]=n.getUint32(r),r+=4;let s=!1;for(let i=0;i<this.count;i++)if(this.offsets[i]&2147483648){s=!0;break}this.largeOffsets=s?new DataView(e.buffer,e.byteOffset+r):null}lookup(e){let n=Y(e),r=n[0],s=r===0?0:this.fanout[r-1],i=this.fanout[r],a=s,o=i;for(;a<o;){let c=a+o>>>1,f=this.compareAt(c,n);if(f<0)a=c+1;else if(f>0)o=c;else return this.getOffset(c)}return null}has(e){return this.lookup(e)!==null}get objectCount(){return this.count}allHashes(){let e=[];for(let n=0;n<this.count;n++)e.push(this.hashAtSlot(n));return e}findByPrefix(e){if(e.length<2)return[];let n=parseInt(e.slice(0,2),16),r=n===0?0:this.fanout[n-1],s=this.fanout[n],i=Y(e.padEnd(40,"0")),a=e.length,o=[];for(let c=r;c<s;c++){let f=c*20,u=!0;for(let h=0;h<a;h++){let d=h%2===0?this.hashes[f+(h>>1)]>>4&15:this.hashes[f+(h>>1)]&15,l=h%2===0?i[h>>1]>>4&15:i[h>>1]&15;if(d!==l){u=!1;break}}u&&o.push(this.hashAtSlot(c))}return o}hashAtSlot(e){let n="",r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s];n+=(i>>4).toString(16)+(i&15).toString(16)}return n}compareAt(e,n){let r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s],a=n[s];if(i<a)return-1;if(i>a)return 1}return 0}getOffset(e){let n=this.offsets[e];if(n&2147483648){let r=n&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return n}};async function nr(t,e){let n=[...t].sort((l,m)=>l.hash<m.hash?-1:l.hash>m.hash?1:0),r=n.length,s=[];for(let l of n)l.offset>=2147483648&&s.push(BigInt(l.offset));let i=8+256*4+r*20+r*4+r*4+s.length*8+20+20,a=new Uint8Array(i),o=new DataView(a.buffer),c=0;o.setUint32(c,zt),c+=4,o.setUint32(c,Vt),c+=4;let f=new Uint32Array(256);for(let l of n){let m=parseInt(l.hash.slice(0,2),16);for(let g=m;g<256;g++)f[g]++}for(let l=0;l<256;l++)o.setUint32(c,f[l]),c+=4;for(let l of n)a.set(Y(l.hash),c),c+=20;for(let l of n)o.setUint32(c,l.crc),c+=4;let u=0;for(let l of n)l.offset>=2147483648?o.setUint32(c,2147483648|u++):o.setUint32(c,l.offset),c+=4;for(let l of s)o.setBigUint64(c,l),c+=8;a.set(e,c),c+=20;let h=Le();h.update(a.subarray(0,c));let d=await h.hex();return a.set(Y(d),c),a}async function Kt(t){let n=(await Wt(t)).map(s=>({hash:s.hash,offset:s.offset,crc:At(t.subarray(s.offset,s.nextOffset))})),r=t.subarray(t.byteLength-20);return nr(n,r)}var rr=6,sr=7,ir={1:"commit",2:"tree",3:"blob",4:"tag"},Re=class{constructor(e,n){this.data=e;this.index=n instanceof se?n:new se(n)}index;hasObject(e){return this.index.has(e)}findByPrefix(e){return this.index.findByPrefix(e)}async readObject(e){let n=this.index.lookup(e);return n===null?null:this.readAt(n)}get objectCount(){return this.index.objectCount}async readAt(e){let n=this.data,r=e,s=n[r++],i=s>>4&7,a=s&15,o=4;for(;s&128;)s=n[r++],a|=(s&127)<<o,o+=7;if(i===rr){let u=n[r++],h=u&127;for(;u&128;)h+=1,u=n[r++],h=(h<<7)+(u&127);let d=await pe(n.subarray(r)),l=await this.readAt(e-h);return{type:l.type,content:Pe(l.content,d)}}if(i===sr){let u=$e(n,r);r+=20;let h=await pe(n.subarray(r)),d=this.index.lookup(u);if(d===null)throw new Error(`REF_DELTA base ${u} not found in pack`);let l=await this.readAt(d);return{type:l.type,content:Pe(l.content,h)}}let c=ir[i];if(!c)throw new Error(`Unknown pack object type: ${i}`);let f=await pe(n.subarray(r));if(f.byteLength!==a)throw new Error(`Pack inflate size mismatch at offset ${e}: got ${f.byteLength}, expected ${a}`);return{type:c,content:f}}};var or=new TextEncoder,ar=new TextDecoder;function cr(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 fr(t,e){let n=e.indexOf(0);if(n===-1)throw new Error(`Corrupt object ${t}: no null byte in header`);let r=ar.decode(e.subarray(0,n)),s=r.indexOf(" ");if(s===-1)throw new Error(`Corrupt object ${t}: malformed header "${r}"`);let i=r.slice(0,s),a=parseInt(r.slice(s+1),10),o=e.subarray(n+1);if(o.byteLength!==a)throw new Error(`Corrupt object ${t}: expected ${a} bytes, got ${o.byteLength}`);return{type:i,content:o}}function at(t,e){return D(t,"objects",e.slice(0,2),e.slice(2))}var ct=class{constructor(e,n,r){this.fs=e;this.gitDir=n;this.cache=new ve(r),this.packDir=D(n,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(e,n){let r=cr(e,n),s=await Me(r),i=at(this.gitDir,s);if(await this.fs.exists(i))return s;let a=D(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(a,{recursive:!0}),await this.fs.writeFile(i,await st(r)),s}async read(e){let n=this.cache.get(e);if(n)return n;let r=at(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await pe(s),a=fr(e,i);return this.cache.set(e,a),a}await this.discover();for(let s of this.packs){if(!s.index.has(e))continue;let a=await(await this.ensureReader(s)).readObject(e);if(a)return this.cache.set(e,a),a}throw new Error(`object ${e} not found`)}async exists(e){if(await this.fs.exists(at(this.gitDir,e)))return!0;await this.discover();for(let n of this.packs)if(n.index.has(e))return!0;return!1}async ingestPack(e){if(e.byteLength<32)return 0;let r=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8);if(r===0)return 0;let s=e.subarray(e.byteLength-20),i=le(s);await this.fs.mkdir(this.packDir,{recursive:!0});let a=`pack-${i}`,o=D(this.packDir,`${a}.pack`);await this.fs.writeFile(o,e);let c=await Kt(e),f=D(this.packDir,`${a}.idx`);await this.fs.writeFile(f,c),this.loadedPackNames.add(a);let u=new se(c);return this.packs.push({name:a,index:u,reader:new Re(e,u)}),r}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(e){if(e.length<4)return[];let n=e.slice(0,2),r=e.slice(2),s=D(this.gitDir,"objects",n),i=[];if(await this.fs.exists(s)){let a=await this.fs.readdir(s);for(let o of a)o.startsWith(r)&&i.push(`${n}${o}`)}await this.discover();for(let a of this.packs)for(let o of a.index.findByPrefix(e))i.includes(o)||i.push(o);return i}async ensureReader(e){if(e.reader)return e.reader;let n=D(this.packDir,`${e.name}.pack`),r=await this.fs.readFileBuffer(n);return e.reader=new Re(r,e.index),e.reader}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){if(!await this.fs.exists(this.packDir))return;let e=await this.fs.readdir(this.packDir);for(let n of e){if(!n.endsWith(".idx"))continue;let r=n.slice(0,-4);if(this.loadedPackNames.has(r))continue;let s=D(this.packDir,`${r}.pack`);if(!await this.fs.exists(s))continue;let i=await this.fs.readFileBuffer(D(this.packDir,n));this.loadedPackNames.add(r),this.packs.push({name:r,index:new se(i),reader:null})}}};function ft(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[a="0",o="+0000"]=i.split(" "),c=parseInt(a,10);return{name:r,email:s,timestamp:c,timezone:o}}function lt(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var lr=new TextEncoder,ur=new TextDecoder;function qt(t){let e=ur.decode(t),n=e.indexOf(`
2
2
 
3
3
  `),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",a=[],o,c;for(let f of r.split(`
4
- `)){let u=f.indexOf(" ");if(u===-1)continue;let h=f.slice(0,u),d=f.slice(u+1);switch(h){case"tree":i=d;break;case"parent":a.push(d);break;case"author":o=nt(d);break;case"committer":c=nt(d);break}}if(!i)throw new Error("Commit missing tree field");if(!o)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:a,author:o,committer:c,message:s}}function Ce(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${rt(t.author)}`),e.push(`committer ${rt(t.committer)}`),e.push(""),e.push(t.message),rr.encode(e.join(`
5
- `))}async function G(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function q(t,e){return t.objectStore.read(e)}function ee(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 ir=new TextDecoder;async function _(t,e){let n=await q(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return ir.decode(n.content)}async function te(t,e){let n=await q(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function U(t,e){let n=await q(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return _t(n.content)}var Ie={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function Wt(t){return typeof t=="string"?{type:"direct",hash:t}:t}var st="ref: ",zt=10,it=class{constructor(e,n){this.fs=e;this.gitDir=n}casLocks=new Map;async readRef(e){let n=L(this.gitDir,e);if(await this.fs.exists(n)){let i=(await this.fs.readFile(n)).trim();return i.startsWith(st)?{type:"symbolic",target:i.slice(st.length)}:{type:"direct",hash:i}}let s=(await this.readPackedRefs()).get(e);return s?{type:"direct",hash:s}:null}async writeRef(e,n){let r=Wt(n),s=L(this.gitDir,e);await Vt(this.fs,s),r.type==="symbolic"?await this.fs.writeFile(s,`${st}${r.target}
4
+ `)){let u=f.indexOf(" ");if(u===-1)continue;let h=f.slice(0,u),d=f.slice(u+1);switch(h){case"tree":i=d;break;case"parent":a.push(d);break;case"author":o=ft(d);break;case"committer":c=ft(d);break}}if(!i)throw new Error("Commit missing tree field");if(!o)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:a,author:o,committer:c,message:s}}function Be(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${lt(t.author)}`),e.push(`committer ${lt(t.committer)}`),e.push(""),e.push(t.message),lr.encode(e.join(`
5
+ `))}async function _(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function q(t,e){return t.objectStore.read(e)}function ee(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 hr=new TextDecoder;async function H(t,e){let n=await q(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return hr.decode(n.content)}async function te(t,e){let n=await q(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function U(t,e){let n=await q(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return qt(n.content)}var ke={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function Yt(t){return typeof t=="string"?{type:"direct",hash:t}:t}var ut="ref: ",Xt=10,ht=class{constructor(e,n){this.fs=e;this.gitDir=n}casLocks=new Map;async readRef(e){let n=D(this.gitDir,e);if(await this.fs.exists(n)){let i=(await this.fs.readFile(n)).trim();return i.startsWith(ut)?{type:"symbolic",target:i.slice(ut.length)}:{type:"direct",hash:i}}let s=(await this.readPackedRefs()).get(e);return s?{type:"direct",hash:s}:null}async writeRef(e,n){let r=Yt(n),s=D(this.gitDir,e);await Jt(this.fs,s),r.type==="symbolic"?await this.fs.writeFile(s,`${ut}${r.target}
6
6
  `):await this.fs.writeFile(s,`${r.hash}
7
- `)}async deleteRef(e){let n=L(this.gitDir,e);await this.fs.exists(n)&&await this.fs.rm(n),await this.removePackedRef(e)}async listRefs(e="refs"){let n=[],r=L(this.gitDir,e);await this.fs.exists(r)&&await this.walkRefs(r,e,n);let s=await this.readPackedRefs();if(s.size>0){let i=new Set(n.map(o=>o.name)),a=`${e}/`;for(let[o,c]of s)o.startsWith(a)&&!i.has(o)&&n.push({name:o,hash:c})}return n.sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async compareAndSwapRef(e,n,r){let i=(this.casLocks.get(e)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(e,n,r),()=>this.compareAndSwapUnsafe(e,n,r));this.casLocks.set(e,i);try{return await i}finally{this.casLocks.get(e)===i&&this.casLocks.delete(e)}}async compareAndSwapUnsafe(e,n,r){let s=await this.resolveRefInternal(e);if(n===null){if(await this.readRef(e)!==null)return!1}else if(s!==n)return!1;return r===null?await this.deleteRef(e):await this.writeRef(e,r),!0}async resolveRefInternal(e){let n=e;for(let r=0;r<zt;r++){let s=await this.readRef(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 readPackedRefs(){let e=L(this.gitDir,"packed-refs");if(!await this.fs.exists(e))return new Map;let n=await this.fs.readFile(e),r=new Map;for(let s of n.split(`
8
- `)){if(!s||s.startsWith("#")||s.startsWith("^"))continue;let i=s.indexOf(" ");if(i===-1)continue;let a=s.slice(0,i),o=s.slice(i+1).trim();a.length===40&&o&&r.set(o,a)}return r}async removePackedRef(e){let n=L(this.gitDir,"packed-refs");if(!await this.fs.exists(n))return;let s=(await this.fs.readFile(n)).split(`
7
+ `)}async deleteRef(e){let n=D(this.gitDir,e);await this.fs.exists(n)&&await this.fs.rm(n),await this.removePackedRef(e)}async listRefs(e="refs"){let n=[],r=D(this.gitDir,e);await this.fs.exists(r)&&await this.walkRefs(r,e,n);let s=await this.readPackedRefs();if(s.size>0){let i=new Set(n.map(o=>o.name)),a=`${e}/`;for(let[o,c]of s)o.startsWith(a)&&!i.has(o)&&n.push({name:o,hash:c})}return n.sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async compareAndSwapRef(e,n,r){let i=(this.casLocks.get(e)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(e,n,r),()=>this.compareAndSwapUnsafe(e,n,r));this.casLocks.set(e,i);try{return await i}finally{this.casLocks.get(e)===i&&this.casLocks.delete(e)}}async compareAndSwapUnsafe(e,n,r){let s=await this.resolveRefInternal(e);if(n===null){if(await this.readRef(e)!==null)return!1}else if(s!==n)return!1;return r===null?await this.deleteRef(e):await this.writeRef(e,r),!0}async resolveRefInternal(e){let n=e;for(let r=0;r<Xt;r++){let s=await this.readRef(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 readPackedRefs(){let e=D(this.gitDir,"packed-refs");if(!await this.fs.exists(e))return new Map;let n=await this.fs.readFile(e),r=new Map;for(let s of n.split(`
8
+ `)){if(!s||s.startsWith("#")||s.startsWith("^"))continue;let i=s.indexOf(" ");if(i===-1)continue;let a=s.slice(0,i),o=s.slice(i+1).trim();a.length===40&&o&&r.set(o,a)}return r}async removePackedRef(e){let n=D(this.gitDir,"packed-refs");if(!await this.fs.exists(n))return;let s=(await this.fs.readFile(n)).split(`
9
9
  `),i=[],a=!1;for(let c of s){if(a&&c.startsWith("^")){a=!1;continue}if(a=!1,!c||c.startsWith("#")){i.push(c);continue}let f=c.indexOf(" ");if(f!==-1&&c.slice(f+1).trim()===e){a=!0;continue}i.push(c)}i.some(c=>c&&!c.startsWith("#")&&!c.startsWith("^"))?await this.fs.writeFile(n,i.join(`
10
- `)):await this.fs.rm(n)}async walkRefs(e,n,r){let s=await this.fs.readdir(e);for(let i of s){let a=L(e,i),o=`${n}/${i}`,c=await this.fs.stat(a);if(c.isDirectory)await this.walkRefs(a,o,r);else if(c.isFile){let f=await this.resolveRefInternal(o);f&&r.push({name:o,hash:f})}}}};async function or(t,e){return t.refStore.readRef(e)}async function $e(t,e){let n=e;for(let r=0;r<zt;r++){let s=await or(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 ot(t,e="refs"){return t.refStore.listRefs(e)}async function Vt(t,e){let n=e.lastIndexOf("/");if(n>0){let r=e.slice(0,n);await t.mkdir(r,{recursive:!0})}}var ui=new TextEncoder;function Q(t){return typeof t=="string"?t==="120000":t===40960}var ar=new TextEncoder,Kt=new TextDecoder;function qt(t){let e=[],n=0;for(;n<t.byteLength;){let r=t.indexOf(32,n);if(r===-1)break;let s=Kt.decode(t.subarray(n,r)),i=t.indexOf(0,r+1);if(i===-1)break;let a=Kt.decode(t.subarray(r+1,i)),o=t.subarray(i+1,i+21),c=oe(o),f=s.padStart(6,"0");e.push({mode:f,name:a,hash:c}),n=i+21}return{type:"tree",entries:e}}function Me(t){let e=[];for(let i of t.entries){let a=i.mode.replace(/^0+/,""),o=ar.encode(`${a} ${i.name}\0`),c=Y(i.hash);e.push(o),e.push(c)}let n=e.reduce((i,a)=>i+a.byteLength,0),r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}async function at(t,e){return Yt(t,e,"")}async function Yt(t,e,n){let r=[],s=new Map;for(let a of e){let o=n?a.path.slice(n.length+1):a.path,c=o.indexOf("/");if(c===-1)r.push({mode:cr(a.mode),name:o,hash:a.hash});else{let f=o.slice(0,c),u=s.get(f);u||(u=[],s.set(f,u)),u.push(a)}}for(let[a,o]of s){let c=n?`${n}/${a}`:a,f=await Yt(t,o,c);r.push({mode:Ie.DIRECTORY,name:a,hash:f})}r.sort((a,o)=>{let c=a.mode===Ie.DIRECTORY?`${a.name}/`:a.name,f=o.mode===Ie.DIRECTORY?`${o.name}/`:o.name;return c<f?-1:c>f?1:0});let i=Me({type:"tree",entries:r});return G(t,"tree",i)}async function ae(t,e,n=""){let r=await q(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=qt(r.content),i=[];for(let a of s.entries){let o=n?`${n}/${a.name}`:a.name;if(a.mode===Ie.DIRECTORY){let c=await ae(t,a.hash,o);i.push(...c)}else i.push({path:o,mode:a.mode,hash:a.hash})}return i}async function ue(t,e){if(!e)return new Map;let n=await ae(t,e);return new Map(n.map(r=>[r.path,r]))}async function ct(t,e,n){let r=await ue(t,e),s=await ue(t,n),i=[];for(let[a,o]of r){let c=s.get(a);c?(o.hash!==c.hash||o.mode!==c.mode)&&i.push({path:a,status:"modified",oldHash:o.hash,newHash:c.hash,oldMode:o.mode,newMode:c.mode}):i.push({path:a,status:"deleted",oldHash:o.hash,oldMode:o.mode})}for(let[a,o]of s)r.has(a)||i.push({path:a,status:"added",newHash:o.hash,newMode:o.mode});return i.sort((a,o)=>Oe(a.path,o.path))}function cr(t){return t.toString(8).padStart(6,"0")}function Xt(t){return{stdout:"",stderr:`fatal: ${t}
11
- `,exitCode:128}}var xi=Xt("not a git repository (or any of the parent directories): .git"),Ii=Xt("this operation must be run in a work tree");function Oe(t,e){return t<e?-1:t>e?1:0}var ve=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,a=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),a<r&&this.higher(n[a],n[s])&&(s=a),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*ft(t,e,n){if(n?.topoOrder){yield*fr(t,e,n);return}let r=await Jt(t,n?.exclude),s=new Set(r),i=new ve,a=n?.shallowBoundary,o=Array.isArray(e)?e:[e];for(let c of o)s.has(c)||i.push(await Le(t,c));for(;i.size>0;){let c=i.pop();if(s.has(c.hash)||(s.add(c.hash),yield c,a?.has(c.hash)))continue;let f=n?.firstParent?c.commit.parents.slice(0,1):c.commit.parents;for(let u of f)if(!s.has(u))try{i.push(await Le(t,u))}catch{}}}async function*fr(t,e,n){let r=await Jt(t,n?.exclude),s=new Set(r),i=new ve,a=n?.shallowBoundary,o=Array.isArray(e)?e:[e];for(let l of o)s.has(l)||i.push(await Le(t,l));let c=[],f=new Map;for(;i.size>0;){let l=i.pop();if(s.has(l.hash)||(s.add(l.hash),f.set(l.hash,c.length),c.push(l),a?.has(l.hash)))continue;let m=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let y of m)if(!s.has(y))try{i.push(await Le(t,y))}catch{}}let u=c.length;if(u===0)return;let h=new Int32Array(u);for(let l of c){let m=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let y of m){let p=f.get(y);p!==void 0&&(h[p]=(h[p]??0)+1)}}let d=[];for(let l=u-1;l>=0;l--)h[l]===0&&d.push(l);for(;d.length>0;){let l=d.pop();yield c[l];let m=n?.firstParent?c[l].commit.parents.slice(0,1):c[l].commit.parents;for(let y of m){let p=f.get(y);if(p!==void 0){let x=(h[p]??0)-1;h[p]=x,x===0&&d.push(p)}}}}async function Jt(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of ft(t,e))n.add(r.hash);return n}async function Le(t,e){return{hash:e,commit:await U(t,e)}}var lr=4,Zt=1024,Ue=100,He=0,Be=1,he=2;function ut(t){let e=1;for(;e*e<t;)e++;return e}function ur(t,e){let n=new Map,r=[],s=new Array(t.length),i=new Array(e.length);for(let a=0;a<t.length;a++){let o=t[a],c=n.get(o);c===void 0&&(c=r.length,n.set(o,c),r.push({len1:0,len2:0})),r[c].len1++,s[a]=c}for(let a=0;a<e.length;a++){let o=e[a],c=n.get(o);c===void 0&&(c=r.length,n.set(o,c),r.push({len1:0,len2:0})),r[c].len2++,i[a]=c}return{classes1:s,classes2:i,classInfo:r}}function hr(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let a=s,o=0,c=i-a;for(;o<c&&t[e-1-o]===n[r-1-o];)o++;return{dstart:a,dend1:e-o-1,dend2:r-o-1}}function Qt(t,e,n,r){e-n>Ue&&(n=e-Ue),r-e>Ue&&(r=e+Ue);let s=0,i=1;for(let c=1;e-c>=n;c++){let f=t[e-c];if(f===He)s++;else if(f===he)i++;else break}if(s===0)return!1;let a=0,o=1;for(let c=1;e+c<=r;c++){let f=t[e+c];if(f===He)a++;else if(f===he)o++;else break}return a===0?!1:(a+=s,o+=i,o*lr<o+a)}function dr(t,e,n,r,s,i,a,o,c,f){let u=new Uint8Array(e),h=new Uint8Array(r),d=Math.min(ut(e),Zt);for(let p=i;p<=a;p++){let x=s[t[p]].len2;x===0?u[p]=He:x>=d?u[p]=he:u[p]=Be}let l=Math.min(ut(r),Zt);for(let p=i;p<=o;p++){let x=s[n[p]].len1;x===0?h[p]=He:x>=l?h[p]=he:h[p]=Be}let m=[];for(let p=i;p<=a;p++)u[p]===Be||u[p]===he&&!Qt(u,p,i,a)?m.push(p):c[p]=1;let y=[];for(let p=i;p<=o;p++)h[p]===Be||h[p]===he&&!Qt(h,p,i,o)?y.push(p):f[p]=1;return{refIndex1:m,nreff1:m.length,refIndex2:y,nreff2:y.length}}var se=20,en=4,mr=256,pr=256,De=2147483647;function W(t,e){return t[e]??0}function gr(t,e,n,r,s,i,a,o,c,f){let u=e-i,h=n-s,d=e-s,l=n-i,m=d-l&1,y=d,p=d,x=l,R=l;a[d]=e,o[l]=n;for(let j=1;;j++){let T=!1;y>u?a[--y-1]=-1:++y,p<h?a[++p+1]=-1:--p;for(let I=p;I>=y;I-=2){let w;W(a,I-1)>=W(a,I+1)?w=W(a,I-1)+1:w=W(a,I+1);let E=w,$=w-I;for(;w<n&&$<i&&t[w]===r[$];)w++,$++;if(w-E>se&&(T=!0),a[I]=w,m&&x<=I&&I<=R&&W(o,I)<=w)return{i1:w,i2:$,minLo:!0,minHi:!0}}x>u?o[--x-1]=De:++x,R<h?o[++R+1]=De:--R;for(let I=R;I>=x;I-=2){let w;W(o,I-1)<W(o,I+1)?w=W(o,I-1):w=W(o,I+1)-1;let E=w,$=w-I;for(;w>e&&$>s&&t[w-1]===r[$-1];)w--,$--;if(E-w>se&&(T=!0),o[I]=w,!m&&y<=I&&I<=p&&w<=W(a,I))return{i1:w,i2:$,minLo:!0,minHi:!0}}if(!c){if(T&&j>mr){let I=0,w=null;for(let E=p;E>=y;E-=2){let $=E>d?E-d:d-E,S=W(a,E),k=S-E,M=S-e+(k-s)-$;if(M>en*j&&M>I&&e+se<=S&&S<n&&s+se<=k&&k<i){let B=!0;for(let N=1;N<=se;N++)if(t[S-N]!==r[k-N]){B=!1;break}B&&(I=M,w={i1:S,i2:k,minLo:!0,minHi:!1})}}if(w)return w;I=0,w=null;for(let E=R;E>=x;E-=2){let $=E>l?E-l:l-E,S=W(o,E),k=S-E,M=n-S+(i-k)-$;if(M>en*j&&M>I&&e<S&&S<=n-se&&s<k&&k<=i-se){let B=!0;for(let N=0;N<se;N++)if(t[S+N]!==r[k+N]){B=!1;break}B&&(I=M,w={i1:S,i2:k,minLo:!1,minHi:!0})}}if(w)return w}if(j>=f){let I=-1,w=-1;for(let S=p;S>=y;S-=2){let k=Math.min(W(a,S),n),M=k-S;i<M&&(k=i+S,M=i),I<k+M&&(I=k+M,w=k)}let E=De,$=De;for(let S=R;S>=x;S-=2){let k=Math.max(e,W(o,S)),M=k-S;M<s&&(k=s+S,M=s),k+M<E&&(E=k+M,$=k)}return n+i-E<I-(e+s)?{i1:w,i2:I-w,minLo:!0,minHi:!1}:{i1:$,i2:E-$,minLo:!1,minHi:!0}}}}}function ht(t,e,n,r,s,i,a,o,c,f,u,h,d,l){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let m=s;m<i;m++)o[f[m]]=1;else if(s===i)for(let m=e;m<n;m++)a[c[m]]=1;else{let m=gr(t,e,n,r,s,i,u,h,d,l);ht(t,e,m.i1,r,s,m.i2,a,o,c,f,u,h,m.minLo,l),ht(t,m.i1,n,r,m.i2,i,a,o,c,f,u,h,m.minHi,l)}}var tn=200,nn=20,rn=100,yr=1,br=21,wr=-30,xr=6,Ir=-4,Or=10,Pr=24,Rr=17,kr=23,Er=17,Sr=60;function lt(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>=tn)return tn}return-1}function sn(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=lt(t[n]));for(let s=n-1;s>=0&&(r.preIndent=lt(t[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===nn){r.preIndent=0;break}for(let s=n+1;s<e&&(r.postIndent=lt(t[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===nn){r.postIndent=0;break}return r}function on(t,e){t.preIndent===-1&&t.preBlank===0&&(e.penalty+=yr),t.endOfFile&&(e.penalty+=br);let n=t.indent===-1?1+t.postBlank:0,r=t.preBlank+n;e.penalty+=wr*r,e.penalty+=xr*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?Or:Ir:s===t.preIndent||(t.postIndent!==-1&&t.postIndent>s?e.penalty+=i?Rr:Pr:e.penalty+=i?Er:kr))}function Tr(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndent<e.effectiveIndent?1:0);return Sr*n+(t.penalty-e.penalty)}function an(t,e,n,r,s,i){let a=0,o=0;for(;t[o];)o++;let c=0,f=0;for(;s[f];)f++;let u=(h,d)=>e[h]===e[d];for(;;){if(o!==a){let h,d,l;do{for(h=o-a,d=-1;a>0&&u(a-1,o-1);){for(t[--a]=1,t[--o]=0;t[a-1];)a--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(l=o,f>c&&(d=o);!(o>=r||!u(a,o));){for(t[a++]=0,t[o++]=1;t[o];)o++;if(f>=i)break;for(c=f+1,f=c;s[f];f++);f>c&&(d=o)}}while(h!==o-a);if(o!==l)if(d!==-1)for(;f===c;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,y={effectiveIndent:0,penalty:0},p=l;for(o-h-1>p&&(p=o-h-1),o-rn>p&&(p=o-rn);p<=o;p++){let x={effectiveIndent:0,penalty:0},R=sn(n,r,p);on(R,x);let j=sn(n,r,p-h);on(j,x),(m===-1||Tr(x,y)<=0)&&(y={effectiveIndent:x.effectiveIndent,penalty:x.penalty},m=p)}for(;o>m;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;s[c-1];c--);}}}if(o>=r)break;for(a=o+1,o=a;t[o];o++);if(f>=i)break;for(c=f+1,f=c;s[f];f++);}}function cn(t,e){let n=t.length,r=e.length,s=new Uint8Array(n),i=new Uint8Array(r);if(n>0&&r>0){let{classes1:a,classes2:o,classInfo:c}=ur(t,e),{dstart:f,dend1:u,dend2:h}=hr(a,n,o,r);if(f>u)for(let d=f;d<r-(n-1-u);d++)i[d]=1;else if(f>h)for(let d=f;d<n-(r-1-h);d++)s[d]=1;else{let{refIndex1:d,nreff1:l,refIndex2:m,nreff2:y}=dr(a,n,o,r,c,f,u,h,s,i);if(l>0&&y>0){let p=new Array(l);for(let w=0;w<l;w++)p[w]=a[d[w]];let x=new Array(y);for(let w=0;w<y;w++)x[w]=o[m[w]];let R={},j={},T=l+y+3,I=Math.max(pr,ut(T));ht(p,0,l,x,0,y,s,i,d,m,R,j,!1,I)}else if(l===0)for(let p=0;p<y;p++)i[m[p]]=1;else for(let p=0;p<l;p++)s[d[p]]=1;an(s,a,t,n,i,r),an(i,o,e,r,s,n)}}else n===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function de(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function jr(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=de(e),r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i&&de(i.path)===n){r=s;break}}return t.splice(r,1)[0]}var Ar=50;async function dt(t,e,n=Ar){let r=new Map,s=[],i=[],a=[];for(let u of e)if(u.status==="deleted"&&u.oldHash){let h=r.get(u.oldHash)??[];h.push(u),r.set(u.oldHash,h),s.push(u)}else u.status==="added"&&u.newHash?i.push(u):a.push(u);let o=[],c=[];for(let u of i){let h=u.newHash;if(!h){c.push(u);continue}let d=r.get(h);if(d&&d.length>0){let l=jr(d,u.path);l&&o.push({oldPath:l.path,newPath:u.path,oldHash:l.oldHash??h,newHash:h,similarity:100,oldMode:l.oldMode,newMode:u.newMode})}else c.push(u)}let f=[...r.values()].flat();if(f.length>0&&c.length>0){let u=await Cr(t,f,c,n);if(u.length>0){let h=new Set(u.map(l=>l.oldPath)),d=new Set(u.map(l=>l.newPath));f=f.filter(l=>!h.has(l.path)),c=c.filter(l=>!d.has(l.path)),o.push(...u)}}if(f.length>0&&c.length>0){let u=await vr(t,f,c,n);if(u.length>0){let h=new Set(u.map(l=>l.oldPath)),d=new Set(u.map(l=>l.newPath));f=f.filter(l=>!h.has(l.path)),c=c.filter(l=>!d.has(l.path)),o.push(...u)}}return{remaining:[...a,...f,...c],renames:o}}async function Cr(t,e,n,r){let s=new Map;for(let o=0;o<e.length;o++){let c=e[o];if(!c)continue;let f=de(c.path);s.has(f)?s.set(f,-1):s.set(f,o)}let i=new Map;for(let o=0;o<n.length;o++){let c=n[o];if(!c)continue;let f=de(c.path);i.has(f)?i.set(f,-1):i.set(f,o)}let a=[];for(let[o,c]of s){if(c===-1)continue;let f=i.get(o);if(f===void 0||f===-1)continue;let u=e[c],h=n[f];if(!u?.oldHash||!h?.newHash||u.oldHash===h.newHash)continue;let d=await te(t,u.oldHash),l=await te(t,h.newHash),m=Mr(d,l);m<r||a.push({oldPath:u.path,newPath:h.path,oldHash:u.oldHash,newHash:h.newHash,similarity:m,oldMode:u.oldMode,newMode:h.newMode})}return a}var fn=107927;function Ne(t){let e=new Map,n=0,r=0,s=0;for(let a=0;a<t.length;a++){let o=t[a],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+o>>>0,n++,n<64&&o!==10)continue;let f=(r+Math.imul(s,97))%fn;e.set(f,(e.get(f)??0)+n),n=0,r=0,s=0}if(n>0){let a=(r+Math.imul(s,97))%fn;e.set(a,(e.get(a)??0)+n)}let i=[];for(let[a,o]of e)i.push({hash:a,count:o});return i.sort((a,o)=>a.hash-o.hash),i}function $r(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let a=t[s];if(!a)break;for(;i<e.length;){let f=e[i];if(!f||f.hash>=a.hash)break;r+=f.count,i++}let o=a.count,c=0;if(i<e.length){let f=e[i];f&&f.hash===a.hash&&(c=f.count,i++)}o<c?(r+=c-o,n+=o):n+=c,s++}for(;i<e.length;){let a=e[i];a&&(r+=a.count),i++}return{srcCopied:n,literalAdded:r}}function Mr(t,e){return t.length===0&&e.length===0?100:t.length===0||e.length===0?0:ln(t.length,Ne(t),e.length,Ne(e))}function ln(t,e,n,r){let s=Math.max(t,n),i=Math.min(t,n);if(i<s-i)return 0;let{srcCopied:a}=$r(e,r);return Math.floor(a*100/s)}async function vr(t,e,n,r){let s=[];for(let u of e)if(u.oldHash){let h=await te(t,u.oldHash);s.push({size:h.length,chunks:Ne(h)})}else s.push(null);let i=[];for(let u of n)if(u.newHash){let h=await te(t,u.newHash);i.push({size:h.length,chunks:Ne(h)})}else i.push(null);let a=[];for(let u=0;u<e.length;u++){let h=e[u],d=s[u];if(!(!h||!d))for(let l=0;l<n.length;l++){let m=n[l],y=i[l];if(!m||!y)continue;let p=ln(d.size,d.chunks,y.size,y.chunks);if(p>=r){let x=de(h.path)===de(m.path)?1:0;a.push({similarity:p,nameScore:x,delIdx:u,addIdx:l})}}}a.sort((u,h)=>h.similarity-u.similarity||h.nameScore-u.nameScore);let o=new Set,c=new Set,f=[];for(let{similarity:u,delIdx:h,addIdx:d}of a){if(o.has(h)||c.has(d))continue;o.add(h),c.add(d);let l=e[h],m=n[d];!l||!m||f.push({oldPath:l.path,newPath:m.path,oldHash:l.oldHash??"",newHash:m.newHash??"",similarity:u,oldMode:l.oldMode,newMode:m.newMode})}return f}async function Lr(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let a;try{a=await U(t,i)}catch{continue}for(let o of a.parents)n.has(o)||r.push(o)}return n}async function mt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let a=s[i++];if(a===e)return!0;if(r.has(a))continue;r.add(a);let o;try{o=await U(t,a)}catch{continue}for(let c of o.parents)r.has(c)||s.push(c)}return!1}async function Pe(t,e,n){if(e===n)return[e];let r=await Lr(t,e),s=[],i=new Set,a=[n],o=0;for(;o<a.length;){let f=a[o++];if(i.has(f))continue;if(i.add(f),r.has(f)){s.push(f);continue}let u;try{u=await U(t,f)}catch{continue}for(let h of u.parents)i.has(h)||a.push(h)}if(s.length<=1)return s;let c=[];for(let f of s){let u=!1;for(let h of s)if(h!==f&&await mt(t,f,h)){u=!0;break}u||c.push(f)}return c.length<=1?c:Ur(t,e,n,c)}async function Ur(t,e,n,r){let s=new Set(r),i=new Set,a=[],o=new Map,c=new Map,f=0,u=[{hash:e,mask:1,seq:f++},{hash:n,mask:2,seq:f++}];async function h(d){let l=c.get(d);if(l!==void 0)return l;let m=(await U(t,d)).committer.timestamp;return c.set(d,m),m}for(;u.length>0;){let d=0,l=await h(u[0].hash);for(let R=1;R<u.length;R++){let j=u[R],T=await h(j.hash),I=u[d];(T>l||T===l&&j.seq<I.seq)&&(d=R,l=T)}let m=u.splice(d,1)[0],y=o.get(m.hash)??0,p=y|m.mask;if(p===y)continue;if(o.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(a.push(m.hash),i.add(m.hash),i.size===s.size))break;let x=await U(t,m.hash);for(let R of x.parents)u.push({hash:R,mask:p,seq:f++})}for(let d of r)i.has(d)||a.push(d);return a}function pt(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=cn(t,e);return Br(s,n,i,r)}function Br(t,e,n,r){let s=[],i=0,a=0;for(;i<e||a<r;){for(;i<e&&a<r&&!t[i]&&!n[a];)i++,a++;if(i>=e&&a>=r)break;let o=i,c=a;for(;i<e&&t[i];)i++;for(;a<r&&n[a];)a++;(i>o||a>c)&&s.push({buffer1:[o,i-o],buffer2:[c,a-c]})}return s}function Dr(t,e,n){let r=[];for(let c of pt(e,t))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of pt(e,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,f)=>c.oStart-f.oStart);let s=[],i=0;function a(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let o=0;for(;o<r.length;){let c=r[o++],f=c.oStart,u=c.oStart+c.oLength,h=[c];for(a(f);o<r.length;){let d=r[o];if(d.oStart>u)break;u=Math.max(u,d.oStart+d.oLength),h.push(d),o++}if(h.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 x of h){let R=x.oStart,j=R+x.oLength,T=x.abStart,I=T+x.abLength,w=d[x.ab];w.abMin=Math.min(T,w.abMin),w.abMax=Math.max(I,w.abMax),w.oMin=Math.min(R,w.oMin),w.oMax=Math.max(j,w.oMax)}let l=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(u-d.a.oMax),y=d.b.abMin+(f-d.b.oMin),p=d.b.abMax+(u-d.b.oMax);s.push({stable:!1,a:t.slice(l,m),o:e.slice(f,u),b:n.slice(y,p)})}i=u}return a(e.length),s}function Hr(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=Dr(t,e,n),a=[],o=[];function c(){o.length&&(a.push({type:"ok",lines:o}),o=[])}for(let f of i)f.stable?o.push(...f.content):s&&hn(f.a,f.b)?o.push(...f.a):(c(),a.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?un(a):un(Nr(a))}function Re(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",a=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,o=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),f=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,u=Hr(t,e,n,{conflictStyle:i}),h=!1,d=[];for(let l of u)l.type==="ok"?d.push(...l.lines):(h=!0,i==="diff3"?d.push(a,...l.a,o,...l.o,c,...l.b,f):d.push(a,...l.a,c,...l.b,f));return{conflict:h,result:d}}function Nr(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...Fr(n));return e}function Fr(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(hn(e,n))return[t];let r=pt(e,n);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let o of r){let c=o.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let u=c+o.buffer1[1],h=o.buffer2[0]+o.buffer2[1];s.push({type:"conflict",a:e.slice(c,u),o:[],b:n.slice(o.buffer2[0],h)}),i=u}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[t]:s}function un(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.length-1],i=e[r];if(s.type==="conflict"&&i.type==="ok"&&i.lines.length<=3&&r+1<e.length&&e[r+1].type==="conflict"){let a=e[r+1],o=s;o.a=[...s.a,...i.lines,...a.a],o.b=[...s.b,...i.lines,...a.b],o.o=[...s.o,...i.lines,...a.o],r++}else n.push(i)}return n}function ce(t,e,n,r){let s=Re(V(t),V(e),V(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),a=(s.result[s.result.length-1]??"").endsWith("\0"),o=s.result.map(gt);return(o[o.length-1]??"").startsWith(">>>>>>>")||!a?`${o.join(`
10
+ `)):await this.fs.rm(n)}async walkRefs(e,n,r){let s=await this.fs.readdir(e);for(let i of s){let a=D(e,i),o=`${n}/${i}`,c=await this.fs.stat(a);if(c.isDirectory)await this.walkRefs(a,o,r);else if(c.isFile){let f=await this.resolveRefInternal(o);f&&r.push({name:o,hash:f})}}}};async function dr(t,e){return t.refStore.readRef(e)}async function De(t,e){let n=e;for(let r=0;r<Xt;r++){let s=await dr(t,n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function dt(t,e="refs"){return t.refStore.listRefs(e)}async function Jt(t,e){let n=e.lastIndexOf("/");if(n>0){let r=e.slice(0,n);await t.mkdir(r,{recursive:!0})}}var Pi=new TextEncoder;function Q(t){return typeof t=="string"?t==="120000":t===40960}var mr=new TextEncoder,Zt=new TextDecoder;function Qt(t){let e=[],n=0;for(;n<t.byteLength;){let r=t.indexOf(32,n);if(r===-1)break;let s=Zt.decode(t.subarray(n,r)),i=t.indexOf(0,r+1);if(i===-1)break;let a=Zt.decode(t.subarray(r+1,i)),o=t.subarray(i+1,i+21),c=le(o),f=s.padStart(6,"0");e.push({mode:f,name:a,hash:c}),n=i+21}return{type:"tree",entries:e}}function He(t){let e=[];for(let i of t.entries){let a=i.mode.replace(/^0+/,""),o=mr.encode(`${a} ${i.name}\0`),c=Y(i.hash);e.push(o),e.push(c)}let n=e.reduce((i,a)=>i+a.byteLength,0),r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}async function mt(t,e){return en(t,e,"")}async function en(t,e,n){let r=[],s=new Map;for(let a of e){let o=n?a.path.slice(n.length+1):a.path,c=o.indexOf("/");if(c===-1)r.push({mode:pr(a.mode),name:o,hash:a.hash});else{let f=o.slice(0,c),u=s.get(f);u||(u=[],s.set(f,u)),u.push(a)}}for(let[a,o]of s){let c=n?`${n}/${a}`:a,f=await en(t,o,c);r.push({mode:ke.DIRECTORY,name:a,hash:f})}r.sort((a,o)=>{let c=a.mode===ke.DIRECTORY?`${a.name}/`:a.name,f=o.mode===ke.DIRECTORY?`${o.name}/`:o.name;return c<f?-1:c>f?1:0});let i=He({type:"tree",entries:r});return _(t,"tree",i)}async function ue(t,e,n=""){let r=await q(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=Qt(r.content),i=[];for(let a of s.entries){let o=n?`${n}/${a.name}`:a.name;if(a.mode===ke.DIRECTORY){let c=await ue(t,a.hash,o);i.push(...c)}else i.push({path:o,mode:a.mode,hash:a.hash})}return i}async function ie(t,e){if(!e)return new Map;let n=await ue(t,e);return new Map(n.map(r=>[r.path,r]))}async function Ee(t,e,n){let r=await ie(t,e),s=await ie(t,n),i=[];for(let[a,o]of r){let c=s.get(a);c?(o.hash!==c.hash||o.mode!==c.mode)&&i.push({path:a,status:"modified",oldHash:o.hash,newHash:c.hash,oldMode:o.mode,newMode:c.mode}):i.push({path:a,status:"deleted",oldHash:o.hash,oldMode:o.mode})}for(let[a,o]of s)r.has(a)||i.push({path:a,status:"added",newHash:o.hash,newMode:o.mode});return i.sort((a,o)=>Se(a.path,o.path))}function pr(t){return t.toString(8).padStart(6,"0")}function tn(t){return{stdout:"",stderr:`fatal: ${t}
11
+ `,exitCode:128}}var $i=tn("not a git repository (or any of the parent directories): .git"),Li=tn("this operation must be run in a work tree");function Se(t,e){return t<e?-1:t>e?1:0}function he(t){if(t.length===0)return[];let e=t.split(`
12
+ `);return e[e.length-1]===""&&e.pop(),e}var gr=4,nn=1024,Ne=100,_e=0,Fe=1,ge=2;function gt(t){let e=1;for(;e*e<t;)e++;return e}function br(t,e){let n=new Map,r=[],s=new Array(t.length),i=new Array(e.length);for(let a=0;a<t.length;a++){let o=t[a],c=n.get(o);c===void 0&&(c=r.length,n.set(o,c),r.push({len1:0,len2:0})),r[c].len1++,s[a]=c}for(let a=0;a<e.length;a++){let o=e[a],c=n.get(o);c===void 0&&(c=r.length,n.set(o,c),r.push({len1:0,len2:0})),r[c].len2++,i[a]=c}return{classes1:s,classes2:i,classInfo:r}}function yr(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let a=s,o=0,c=i-a;for(;o<c&&t[e-1-o]===n[r-1-o];)o++;return{dstart:a,dend1:e-o-1,dend2:r-o-1}}function rn(t,e,n,r){e-n>Ne&&(n=e-Ne),r-e>Ne&&(r=e+Ne);let s=0,i=1;for(let c=1;e-c>=n;c++){let f=t[e-c];if(f===_e)s++;else if(f===ge)i++;else break}if(s===0)return!1;let a=0,o=1;for(let c=1;e+c<=r;c++){let f=t[e+c];if(f===_e)a++;else if(f===ge)o++;else break}return a===0?!1:(a+=s,o+=i,o*gr<o+a)}function wr(t,e,n,r,s,i,a,o,c,f){let u=new Uint8Array(e),h=new Uint8Array(r),d=Math.min(gt(e),nn);for(let p=i;p<=a;p++){let I=s[t[p]].len2;I===0?u[p]=_e:I>=d?u[p]=ge:u[p]=Fe}let l=Math.min(gt(r),nn);for(let p=i;p<=o;p++){let I=s[n[p]].len1;I===0?h[p]=_e:I>=l?h[p]=ge:h[p]=Fe}let m=[];for(let p=i;p<=a;p++)u[p]===Fe||u[p]===ge&&!rn(u,p,i,a)?m.push(p):c[p]=1;let g=[];for(let p=i;p<=o;p++)h[p]===Fe||h[p]===ge&&!rn(h,p,i,o)?g.push(p):f[p]=1;return{refIndex1:m,nreff1:m.length,refIndex2:g,nreff2:g.length}}var oe=20,sn=4,Ir=256,xr=256,Ge=2147483647;function W(t,e){return t[e]??0}function Or(t,e,n,r,s,i,a,o,c,f){let u=e-i,h=n-s,d=e-s,l=n-i,m=d-l&1,g=d,p=d,I=l,k=l;a[d]=e,o[l]=n;for(let C=1;;C++){let A=!1;g>u?a[--g-1]=-1:++g,p<h?a[++p+1]=-1:--p;for(let P=p;P>=g;P-=2){let y;W(a,P-1)>=W(a,P+1)?y=W(a,P-1)+1:y=W(a,P+1);let O=y,T=y-P;for(;y<n&&T<i&&t[y]===r[T];)y++,T++;if(y-O>oe&&(A=!0),a[P]=y,m&&I<=P&&P<=k&&W(o,P)<=y)return{i1:y,i2:T,minLo:!0,minHi:!0}}I>u?o[--I-1]=Ge:++I,k<h?o[++k+1]=Ge:--k;for(let P=k;P>=I;P-=2){let y;W(o,P-1)<W(o,P+1)?y=W(o,P-1):y=W(o,P+1)-1;let O=y,T=y-P;for(;y>e&&T>s&&t[y-1]===r[T-1];)y--,T--;if(O-y>oe&&(A=!0),o[P]=y,!m&&g<=P&&P<=p&&y<=W(a,P))return{i1:y,i2:T,minLo:!0,minHi:!0}}if(!c){if(A&&C>Ir){let P=0,y=null;for(let O=p;O>=g;O-=2){let T=O>d?O-d:d-O,x=W(a,O),R=x-O,S=x-e+(R-s)-T;if(S>sn*C&&S>P&&e+oe<=x&&x<n&&s+oe<=R&&R<i){let $=!0;for(let v=1;v<=oe;v++)if(t[x-v]!==r[R-v]){$=!1;break}$&&(P=S,y={i1:x,i2:R,minLo:!0,minHi:!1})}}if(y)return y;P=0,y=null;for(let O=k;O>=I;O-=2){let T=O>l?O-l:l-O,x=W(o,O),R=x-O,S=n-x+(i-R)-T;if(S>sn*C&&S>P&&e<x&&x<=n-oe&&s<R&&R<=i-oe){let $=!0;for(let v=0;v<oe;v++)if(t[x+v]!==r[R+v]){$=!1;break}$&&(P=S,y={i1:x,i2:R,minLo:!1,minHi:!0})}}if(y)return y}if(C>=f){let P=-1,y=-1;for(let x=p;x>=g;x-=2){let R=Math.min(W(a,x),n),S=R-x;i<S&&(R=i+x,S=i),P<R+S&&(P=R+S,y=R)}let O=Ge,T=Ge;for(let x=k;x>=I;x-=2){let R=Math.max(e,W(o,x)),S=R-x;S<s&&(R=s+x,S=s),R+S<O&&(O=R+S,T=R)}return n+i-O<P-(e+s)?{i1:y,i2:P-y,minLo:!0,minHi:!1}:{i1:T,i2:O-T,minLo:!1,minHi:!0}}}}}function bt(t,e,n,r,s,i,a,o,c,f,u,h,d,l){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let m=s;m<i;m++)o[f[m]]=1;else if(s===i)for(let m=e;m<n;m++)a[c[m]]=1;else{let m=Or(t,e,n,r,s,i,u,h,d,l);bt(t,e,m.i1,r,s,m.i2,a,o,c,f,u,h,m.minLo,l),bt(t,m.i1,n,r,m.i2,i,a,o,c,f,u,h,m.minHi,l)}}function Pr(t,e,n,r){let s=[],i=0,a=0,o=1,c=1;for(;i<t.length||a<e.length;){if(i<t.length&&a<e.length&&!n[i]&&!r[a]){s.push({type:"keep",line:t[i]??"",oldLineNo:o++,newLineNo:c++}),i++,a++;continue}for(;i<t.length&&n[i];)s.push({type:"delete",line:t[i]??"",oldLineNo:o++,newLineNo:0}),i++;for(;a<e.length&&r[a];)s.push({type:"insert",line:e[a]??"",oldLineNo:0,newLineNo:c++}),a++}return s}var on=200,an=20,cn=100,Rr=1,kr=21,Er=-30,Sr=6,Tr=-4,jr=10,Cr=24,Ar=17,$r=23,Lr=17,Mr=60;function pt(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>=on)return on}return-1}function fn(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=pt(t[n]));for(let s=n-1;s>=0&&(r.preIndent=pt(t[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===an){r.preIndent=0;break}for(let s=n+1;s<e&&(r.postIndent=pt(t[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===an){r.postIndent=0;break}return r}function ln(t,e){t.preIndent===-1&&t.preBlank===0&&(e.penalty+=Rr),t.endOfFile&&(e.penalty+=kr);let n=t.indent===-1?1+t.postBlank:0,r=t.preBlank+n;e.penalty+=Er*r,e.penalty+=Sr*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?jr:Tr:s===t.preIndent||(t.postIndent!==-1&&t.postIndent>s?e.penalty+=i?Ar:Cr:e.penalty+=i?Lr:$r))}function vr(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndent<e.effectiveIndent?1:0);return Mr*n+(t.penalty-e.penalty)}function un(t,e,n,r,s,i){let a=0,o=0;for(;t[o];)o++;let c=0,f=0;for(;s[f];)f++;let u=(h,d)=>e[h]===e[d];for(;;){if(o!==a){let h,d,l;do{for(h=o-a,d=-1;a>0&&u(a-1,o-1);){for(t[--a]=1,t[--o]=0;t[a-1];)a--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(l=o,f>c&&(d=o);!(o>=r||!u(a,o));){for(t[a++]=0,t[o++]=1;t[o];)o++;if(f>=i)break;for(c=f+1,f=c;s[f];f++);f>c&&(d=o)}}while(h!==o-a);if(o!==l)if(d!==-1)for(;f===c;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,g={effectiveIndent:0,penalty:0},p=l;for(o-h-1>p&&(p=o-h-1),o-cn>p&&(p=o-cn);p<=o;p++){let I={effectiveIndent:0,penalty:0},k=fn(n,r,p);ln(k,I);let C=fn(n,r,p-h);ln(C,I),(m===-1||vr(I,g)<=0)&&(g={effectiveIndent:I.effectiveIndent,penalty:I.penalty},m=p)}for(;o>m;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;s[c-1];c--);}}}if(o>=r)break;for(a=o+1,o=a;t[o];o++);if(f>=i)break;for(c=f+1,f=c;s[f];f++);}}function yt(t,e){let n=t.length,r=e.length,s=new Uint8Array(n),i=new Uint8Array(r);if(n>0&&r>0){let{classes1:a,classes2:o,classInfo:c}=br(t,e),{dstart:f,dend1:u,dend2:h}=yr(a,n,o,r);if(f>u)for(let d=f;d<r-(n-1-u);d++)i[d]=1;else if(f>h)for(let d=f;d<n-(r-1-h);d++)s[d]=1;else{let{refIndex1:d,nreff1:l,refIndex2:m,nreff2:g}=wr(a,n,o,r,c,f,u,h,s,i);if(l>0&&g>0){let p=new Array(l);for(let y=0;y<l;y++)p[y]=a[d[y]];let I=new Array(g);for(let y=0;y<g;y++)I[y]=o[m[y]];let k={},C={},A=l+g+3,P=Math.max(xr,gt(A));bt(p,0,l,I,0,g,s,i,d,m,k,C,!1,P)}else if(l===0)for(let p=0;p<g;p++)i[m[p]]=1;else for(let p=0;p<l;p++)s[d[p]]=1;un(s,a,t,n,i,r),un(i,o,e,r,s,n)}}else n===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function We(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return e.map((a,o)=>({type:"insert",line:a,oldLineNo:0,newLineNo:o+1}));if(r===0)return t.map((a,o)=>({type:"delete",line:a,oldLineNo:o+1,newLineNo:0}));let{changedOld:s,changedNew:i}=yt(t,e);return Pr(t,e,s,i)}function be(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function Ur(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=be(e),r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i&&be(i.path)===n){r=s;break}}return t.splice(r,1)[0]}var Br=50;async function Te(t,e,n=Br){let r=new Map,s=[],i=[],a=[];for(let u of e)if(u.status==="deleted"&&u.oldHash){let h=r.get(u.oldHash)??[];h.push(u),r.set(u.oldHash,h),s.push(u)}else u.status==="added"&&u.newHash?i.push(u):a.push(u);let o=[],c=[];for(let u of i){let h=u.newHash;if(!h){c.push(u);continue}let d=r.get(h);if(d&&d.length>0){let l=Ur(d,u.path);l&&o.push({oldPath:l.path,newPath:u.path,oldHash:l.oldHash??h,newHash:h,similarity:100,oldMode:l.oldMode,newMode:u.newMode})}else c.push(u)}let f=[...r.values()].flat();if(f.length>0&&c.length>0){let u=await Dr(t,f,c,n);if(u.length>0){let h=new Set(u.map(l=>l.oldPath)),d=new Set(u.map(l=>l.newPath));f=f.filter(l=>!h.has(l.path)),c=c.filter(l=>!d.has(l.path)),o.push(...u)}}if(f.length>0&&c.length>0){let u=await Fr(t,f,c,n);if(u.length>0){let h=new Set(u.map(l=>l.oldPath)),d=new Set(u.map(l=>l.newPath));f=f.filter(l=>!h.has(l.path)),c=c.filter(l=>!d.has(l.path)),o.push(...u)}}return{remaining:[...a,...f,...c],renames:o}}async function Dr(t,e,n,r){let s=new Map;for(let o=0;o<e.length;o++){let c=e[o];if(!c)continue;let f=be(c.path);s.has(f)?s.set(f,-1):s.set(f,o)}let i=new Map;for(let o=0;o<n.length;o++){let c=n[o];if(!c)continue;let f=be(c.path);i.has(f)?i.set(f,-1):i.set(f,o)}let a=[];for(let[o,c]of s){if(c===-1)continue;let f=i.get(o);if(f===void 0||f===-1)continue;let u=e[c],h=n[f];if(!u?.oldHash||!h?.newHash||u.oldHash===h.newHash)continue;let d=await te(t,u.oldHash),l=await te(t,h.newHash),m=Nr(d,l);m<r||a.push({oldPath:u.path,newPath:h.path,oldHash:u.oldHash,newHash:h.newHash,similarity:m,oldMode:u.oldMode,newMode:h.newMode})}return a}var hn=107927;function ze(t){let e=new Map,n=0,r=0,s=0;for(let a=0;a<t.length;a++){let o=t[a],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+o>>>0,n++,n<64&&o!==10)continue;let f=(r+Math.imul(s,97))%hn;e.set(f,(e.get(f)??0)+n),n=0,r=0,s=0}if(n>0){let a=(r+Math.imul(s,97))%hn;e.set(a,(e.get(a)??0)+n)}let i=[];for(let[a,o]of e)i.push({hash:a,count:o});return i.sort((a,o)=>a.hash-o.hash),i}function Hr(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let a=t[s];if(!a)break;for(;i<e.length;){let f=e[i];if(!f||f.hash>=a.hash)break;r+=f.count,i++}let o=a.count,c=0;if(i<e.length){let f=e[i];f&&f.hash===a.hash&&(c=f.count,i++)}o<c?(r+=c-o,n+=o):n+=c,s++}for(;i<e.length;){let a=e[i];a&&(r+=a.count),i++}return{srcCopied:n,literalAdded:r}}function Nr(t,e){return t.length===0&&e.length===0?100:t.length===0||e.length===0?0:dn(t.length,ze(t),e.length,ze(e))}function dn(t,e,n,r){let s=Math.max(t,n),i=Math.min(t,n);if(i<s-i)return 0;let{srcCopied:a}=Hr(e,r);return Math.floor(a*100/s)}async function Fr(t,e,n,r){let s=[];for(let u of e)if(u.oldHash){let h=await te(t,u.oldHash);s.push({size:h.length,chunks:ze(h)})}else s.push(null);let i=[];for(let u of n)if(u.newHash){let h=await te(t,u.newHash);i.push({size:h.length,chunks:ze(h)})}else i.push(null);let a=[];for(let u=0;u<e.length;u++){let h=e[u],d=s[u];if(!(!h||!d))for(let l=0;l<n.length;l++){let m=n[l],g=i[l];if(!m||!g)continue;let p=dn(d.size,d.chunks,g.size,g.chunks);if(p>=r){let I=be(h.path)===be(m.path)?1:0;a.push({similarity:p,nameScore:I,delIdx:u,addIdx:l})}}}a.sort((u,h)=>h.similarity-u.similarity||h.nameScore-u.nameScore);let o=new Set,c=new Set,f=[];for(let{similarity:u,delIdx:h,addIdx:d}of a){if(o.has(h)||c.has(d))continue;o.add(h),c.add(d);let l=e[h],m=n[d];!l||!m||f.push({oldPath:l.path,newPath:m.path,oldHash:l.oldHash??"",newHash:m.newHash??"",similarity:u,oldMode:l.oldMode,newMode:m.newMode})}return f}async function ae(t,e,n){return(await ie(t,e)).get(n)?.hash??null}async function mn(t,e,n,r){let s=await Ee(t,e,n);if(!s.find(c=>c.status==="added"&&c.path===r))return null;let{renames:a}=await Te(t,s);return a.find(c=>c.newPath===r)?.oldPath??null}async function Gr(t,e,n,r,s,i){let a=await ae(t,(await U(t,e)).tree,n);if(!a){let g=new Map,p=await U(t,e);for(let I of r)g.set(I.finalIdx,ce(e,n,I.currentLine,i+I.finalIdx,s[I.finalIdx],p,!1,void 0));return g}let o=await H(t,a),c=he(o),f=new Array(s.length),u=[...r],h=e,d=n,l=c;for(;u.length>0;){let g=await U(t,h);if(g.parents.length===0){for(let x of u)f[x.finalIdx]=ce(h,d,x.currentLine,i+x.finalIdx,s[x.finalIdx],g,!0,void 0);break}let p=await ae(t,g.tree,d),I=null,k=[];for(let x of g.parents){let R=await U(t,x),S=d,$=await ae(t,R.tree,S);if(!$){let v=await mn(t,R.tree,g.tree,d);v&&(S=v,$=await ae(t,R.tree,S))}if($&&(k.push({hash:x,path:S,blobHash:$}),$===p)){I={hash:x,path:S};break}}if(I){h=I.hash,d=I.path;continue}if(k.length===0){for(let x of u)f[x.finalIdx]=ce(h,d,x.currentLine,i+x.finalIdx,s[x.finalIdx],g,!1,void 0);break}let C=k[0],A=await H(t,C.blobHash),P=he(A),y=We(P,l),O=new Map;for(let x of y)x.type==="keep"&&O.set(x.newLineNo,x.oldLineNo);let T=[];for(let x of u){let R=O.get(x.currentLine);R!==void 0?T.push({finalIdx:x.finalIdx,currentLine:R}):f[x.finalIdx]=ce(h,d,x.currentLine,i+x.finalIdx,s[x.finalIdx],g,!1,{hash:C.hash,path:C.path})}u=T,h=C.hash,d=C.path,l=P}let m=new Map;for(let g of r)f[g.finalIdx]&&m.set(g.finalIdx,f[g.finalIdx]);return m}async function pn(t,e,n,r){let s=await U(t,e),i=await ae(t,s.tree,n);if(!i)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let a=await H(t,i),o=he(a),c=r?.startLine??1,f=r?.endLine??o.length,u=o.slice(c-1,f),h=new Array(u.length),d=u.map((p,I)=>({finalIdx:I,currentLine:c+I})),l=e,m=n,g=o;for(;d.length>0;){let p=await U(t,l);if(p.parents.length===0){for(let O of d)h[O.finalIdx]=ce(l,m,O.currentLine,c+O.finalIdx,u[O.finalIdx],p,!0,void 0);break}let I=await ae(t,p.tree,m),k=[],C=null;for(let O of p.parents){let T=await U(t,O),x=m,R=await ae(t,T.tree,x);if(!R){let S=await mn(t,T.tree,p.tree,m);S&&(x=S,R=await ae(t,T.tree,x))}if(R){let S={hash:O,path:x,blobHash:R};if(k.push(S),R===I){C=S;break}}}if(C){l=C.hash,m=C.path;continue}if(k.length===0){for(let O of d)h[O.finalIdx]=ce(l,m,O.currentLine,c+O.finalIdx,u[O.finalIdx],p,!1,void 0);break}if(k.length===1){let O=k[0],T=await H(t,O.blobHash),x=he(T),R=We(x,g),S=new Map;for(let v of R)v.type==="keep"&&S.set(v.newLineNo,v.oldLineNo);let $=[];for(let v of d){let ne=S.get(v.currentLine);ne!==void 0?$.push({finalIdx:v.finalIdx,currentLine:ne}):h[v.finalIdx]=ce(l,m,v.currentLine,c+v.finalIdx,u[v.finalIdx],p,!1,{hash:O.hash,path:O.path})}d=$,l=O.hash,m=O.path,g=x;continue}let A=[];for(let O of k){let T=await H(t,O.blobHash),x=he(T),R=We(x,g),S=new Map;for(let $ of R)$.type==="keep"&&S.set($.newLineNo,$.oldLineNo);A.push({info:O,newToOld:S})}let P=new Map;for(let O of d){let T=!1;for(let x=0;x<A.length;x++){let R=A[x],S=R.newToOld.get(O.currentLine);if(S!==void 0){let $=P.get(x);$||($={info:R.info,lines:[]},P.set(x,$)),$.lines.push({finalIdx:O.finalIdx,currentLine:S}),T=!0;break}}T||(h[O.finalIdx]=ce(l,m,O.currentLine,c+O.finalIdx,u[O.finalIdx],p,!1,{hash:k[0].hash,path:k[0].path}))}let y=P.get(0);for(let[O,T]of P){if(O===0)continue;let x=await Gr(t,T.info.hash,T.info.path,T.lines,u,c);for(let[R,S]of x)h[R]=S}if(y&&y.lines.length>0){d=y.lines,l=y.info.hash,m=y.info.path;let O=await H(t,y.info.blobHash);g=he(O)}else break}return h}function ce(t,e,n,r,s,i,a,o){return{hash:t,origPath:e,origLine:n,finalLine:r,content:s,author:i.author,committer:i.committer,summary:i.message.split(`
13
+ `)[0],boundary:a,previous:o}}var Ve=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,a=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),a<r&&this.higher(n[a],n[s])&&(s=a),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*ye(t,e,n){if(n?.topoOrder){yield*_r(t,e,n);return}let r=await bn(t,n?.exclude),s=new Set(r),i=new Ve,a=n?.shallowBoundary,o=Array.isArray(e)?e:[e];for(let c of o)s.has(c)||i.push(await Ke(t,c));for(;i.size>0;){let c=i.pop();if(s.has(c.hash)||(s.add(c.hash),yield c,a?.has(c.hash)))continue;let f=n?.firstParent?c.commit.parents.slice(0,1):c.commit.parents;for(let u of f)if(!s.has(u))try{i.push(await Ke(t,u))}catch{}}}async function*_r(t,e,n){let r=await bn(t,n?.exclude),s=new Set(r),i=new Ve,a=n?.shallowBoundary,o=Array.isArray(e)?e:[e];for(let l of o)s.has(l)||i.push(await Ke(t,l));let c=[],f=new Map;for(;i.size>0;){let l=i.pop();if(s.has(l.hash)||(s.add(l.hash),f.set(l.hash,c.length),c.push(l),a?.has(l.hash)))continue;let m=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let g of m)if(!s.has(g))try{i.push(await Ke(t,g))}catch{}}let u=c.length;if(u===0)return;let h=new Int32Array(u);for(let l of c){let m=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let g of m){let p=f.get(g);p!==void 0&&(h[p]=(h[p]??0)+1)}}let d=[];for(let l=u-1;l>=0;l--)h[l]===0&&d.push(l);for(;d.length>0;){let l=d.pop();yield c[l];let m=n?.firstParent?c[l].commit.parents.slice(0,1):c[l].commit.parents;for(let g of m){let p=f.get(g);if(p!==void 0){let I=(h[p]??0)-1;h[p]=I,I===0&&d.push(p)}}}}async function gn(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let o of ye(t,e))r.add(o.hash);let s=new Set;for await(let o of ye(t,n))s.add(o.hash);let i=0;for(let o of r)s.has(o)||i++;let a=0;for(let o of s)r.has(o)||a++;return{ahead:i,behind:a}}async function bn(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of ye(t,e))n.add(r.hash);return n}async function Ke(t,e){return{hash:e,commit:await U(t,e)}}async function Wr(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let a;try{a=await U(t,i)}catch{continue}for(let o of a.parents)n.has(o)||r.push(o)}return n}async function wt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let a=s[i++];if(a===e)return!0;if(r.has(a))continue;r.add(a);let o;try{o=await U(t,a)}catch{continue}for(let c of o.parents)r.has(c)||s.push(c)}return!1}async function je(t,e,n){if(e===n)return[e];let r=await Wr(t,e),s=[],i=new Set,a=[n],o=0;for(;o<a.length;){let f=a[o++];if(i.has(f))continue;if(i.add(f),r.has(f)){s.push(f);continue}let u;try{u=await U(t,f)}catch{continue}for(let h of u.parents)i.has(h)||a.push(h)}if(s.length<=1)return s;let c=[];for(let f of s){let u=!1;for(let h of s)if(h!==f&&await wt(t,f,h)){u=!0;break}u||c.push(f)}return c.length<=1?c:zr(t,e,n,c)}async function zr(t,e,n,r){let s=new Set(r),i=new Set,a=[],o=new Map,c=new Map,f=0,u=[{hash:e,mask:1,seq:f++},{hash:n,mask:2,seq:f++}];async function h(d){let l=c.get(d);if(l!==void 0)return l;let m=(await U(t,d)).committer.timestamp;return c.set(d,m),m}for(;u.length>0;){let d=0,l=await h(u[0].hash);for(let k=1;k<u.length;k++){let C=u[k],A=await h(C.hash),P=u[d];(A>l||A===l&&C.seq<P.seq)&&(d=k,l=A)}let m=u.splice(d,1)[0],g=o.get(m.hash)??0,p=g|m.mask;if(p===g)continue;if(o.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(a.push(m.hash),i.add(m.hash),i.size===s.size))break;let I=await U(t,m.hash);for(let k of I.parents)u.push({hash:k,mask:p,seq:f++})}for(let d of r)i.has(d)||a.push(d);return a}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}=yt(t,e);return Vr(s,n,i,r)}function Vr(t,e,n,r){let s=[],i=0,a=0;for(;i<e||a<r;){for(;i<e&&a<r&&!t[i]&&!n[a];)i++,a++;if(i>=e&&a>=r)break;let o=i,c=a;for(;i<e&&t[i];)i++;for(;a<r&&n[a];)a++;(i>o||a>c)&&s.push({buffer1:[o,i-o],buffer2:[c,a-c]})}return s}function Kr(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,f)=>c.oStart-f.oStart);let s=[],i=0;function a(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let o=0;for(;o<r.length;){let c=r[o++],f=c.oStart,u=c.oStart+c.oLength,h=[c];for(a(f);o<r.length;){let d=r[o];if(d.oStart>u)break;u=Math.max(u,d.oStart+d.oLength),h.push(d),o++}if(h.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 I of h){let k=I.oStart,C=k+I.oLength,A=I.abStart,P=A+I.abLength,y=d[I.ab];y.abMin=Math.min(A,y.abMin),y.abMax=Math.max(P,y.abMax),y.oMin=Math.min(k,y.oMin),y.oMax=Math.max(C,y.oMax)}let l=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(u-d.a.oMax),g=d.b.abMin+(f-d.b.oMin),p=d.b.abMax+(u-d.b.oMax);s.push({stable:!1,a:t.slice(l,m),o:e.slice(f,u),b:n.slice(g,p)})}i=u}return a(e.length),s}function qr(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=Kr(t,e,n),a=[],o=[];function c(){o.length&&(a.push({type:"ok",lines:o}),o=[])}for(let f of i)f.stable?o.push(...f.content):s&&wn(f.a,f.b)?o.push(...f.a):(c(),a.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?yn(a):yn(Yr(a))}function Ce(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",a=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,o=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),f=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,u=qr(t,e,n,{conflictStyle:i}),h=!1,d=[];for(let l of u)l.type==="ok"?d.push(...l.lines):(h=!0,i==="diff3"?d.push(a,...l.a,o,...l.o,c,...l.b,f):d.push(a,...l.a,c,...l.b,f));return{conflict:h,result:d}}function Yr(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...Xr(n));return e}function Xr(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(wn(e,n))return[t];let r=It(e,n);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let o of r){let c=o.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let u=c+o.buffer1[1],h=o.buffer2[0]+o.buffer2[1];s.push({type:"conflict",a:e.slice(c,u),o:[],b:n.slice(o.buffer2[0],h)}),i=u}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[t]:s}function yn(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.length-1],i=e[r];if(s.type==="conflict"&&i.type==="ok"&&i.lines.length<=3&&r+1<e.length&&e[r+1].type==="conflict"){let a=e[r+1],o=s;o.a=[...s.a,...i.lines,...a.a],o.b=[...s.b,...i.lines,...a.b],o.o=[...s.o,...i.lines,...a.o],r++}else n.push(i)}return n}function de(t,e,n,r){let s=Ce(V(t),V(e),V(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),a=(s.result[s.result.length-1]??"").endsWith("\0"),o=s.result.map(xt);return(o[o.length-1]??"").startsWith(">>>>>>>")||!a?`${o.join(`
12
14
  `)}
13
15
  `:o.join(`
14
16
  `)}function V(t){if(t==="")return[];let e=t.split(`
15
- `);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function gt(t){return t.endsWith("\0")?t.slice(0,-1):t}function 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 me=new TextDecoder,ie=new TextEncoder,dn={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function pe(t,e,n,r,s){let{paths:i,baseMap:a,oursMap:o,theirsMap:c}=await Gr(t,e,n,r),f=await Wr(t,i,a,o,c,s);return zr(t,i,s,f)}async function xn(t,e,n,r){let s=await Pe(t,e,n),i=await U(t,e),a=await U(t,n);if(s.length===0)return{...await pe(t,null,i.tree,a.tree,r),baseTree:null};if(s.length===1){let f=await U(t,s[0]);return{...await pe(t,f.tree,i.tree,a.tree,r),baseTree:f.tree}}let o=await On(t,e,n,s,1);return{...await pe(t,o,i.tree,a.tree,r),baseTree:o}}async function Gr(t,e,n,r){let s=await ue(t,e),i=await ue(t,n),a=await ue(t,r),o=new Set;for(let f of s.keys())o.add(f);for(let f of i.keys())o.add(f);for(let f of a.keys())o.add(f);let c=new Map;for(let f of o){let u=s.get(f)??null,h=i.get(f)??null,d=a.get(f)??null,l=u?{hash:u.hash,mode:u.mode}:null,m=h?{hash:h.hash,mode:h.mode}:null,y=d?{hash:d.hash,mode:d.mode}:null,p=(u?1:0)|(h?2:0)|(d?4:0),x=u?.hash??null,R=h?.hash??null,j=d?.hash??null,T=0;x!==null&&x===R&&(T|=3),x!==null&&x===j&&(T|=5),R!==null&&R===j&&(T|=6);let I={path:f,stages:[l,m,y],pathnames:[f,f,f],filemask:p,matchMask:T,merged:{result:null,clean:!1},pathConflict:!1};if(_r(I)){c.set(f,I);continue}c.set(f,I)}return{paths:c,baseMap:s,oursMap:i,theirsMap:a}}function _r(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,a=r?.hash??null;return i===s&&a===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===a&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&a===null?(t.merged={result:null,clean:!0},!0):a===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&a!==s?(r?t.merged={result:{hash:a,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function Wr(t,e,n,r,s,i){let a={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},o=[],c=[];for(let[b,g]of n)r.has(b)||o.push({path:b,status:"deleted",oldHash:g.hash,oldMode:g.mode}),s.has(b)||c.push({path:b,status:"deleted",oldHash:g.hash,oldMode:g.mode});for(let[b,g]of r)n.has(b)||o.push({path:b,status:"added",newHash:g.hash,newMode:g.mode});for(let[b,g]of s)n.has(b)||c.push({path:b,status:"added",newHash:g.hash,newMode:g.mode});let f=await dt(t,o),u=await dt(t,c);if(f.renames.length===0&&u.renames.length===0)return a;let h=new Map,d=new Map;for(let b of f.renames)h.set(b.oldPath,b);for(let b of u.renames)d.set(b.oldPath,b);let l=new Set;for(let[b]of r)!n.has(b)&&s.has(b)&&l.add(b);let m=new Set,y=i?.a??"HEAD",p=i?.b??"theirs";function x(b,g,O=0){a.msgBuf.push({sortKey:b,subOrder:O,text:g})}for(let b of[...n.keys()].sort()){let g=h.get(b),O=d.get(b);if(!g&&!O)continue;let C=n.get(b);if(m.add(b),g&&O)if(m.add(g.newPath),m.add(O.newPath),g.newPath===O.newPath){let A=r.get(g.newPath),P=s.get(O.newPath);if(A.hash===P.hash)a.entries.push(z(g.newPath,A));else{let D=yt(e,g.newPath);D.stages=[{hash:C.hash,mode:C.mode},{hash:A.hash,mode:A.mode},{hash:P.hash,mode:P.mode}],D.pathnames=[b,g.newPath,O.newPath],D.filemask=7,D.merged={result:null,clean:!1}}}else{let A=r.get(g.newPath),P=s.get(O.newPath),D=await In(t,C,A,P,i);D.conflict&&x(b,`Auto-merging ${b}`,-1),a.conflicts.push({path:b,reason:"rename-rename",oursPath:g.newPath,theirsPath:O.newPath}),x(b,`CONFLICT (rename/rename): ${b} renamed to ${g.newPath} in ${y} and to ${O.newPath} in ${p}.`),a.entries.push(z(b,C,1)),a.entries.push(F(g.newPath,A.mode,D.hash,2)),a.entries.push(F(O.newPath,P.mode,D.hash,3)),a.worktreeBlobs.set(g.newPath,{hash:D.hash,mode:A.mode}),a.worktreeBlobs.set(O.newPath,{hash:D.hash,mode:P.mode})}else if(g){m.add(g.newPath);let A=s.get(b),P=r.get(g.newPath),D=l.has(g.newPath);if(A)if(D)await wn(t,a,g.newPath,b,C,P,A,r,s,!1,i);else if(A.hash===C.hash&&P.hash===C.hash)a.entries.push(z(g.newPath,P));else if(A.hash===C.hash)a.entries.push(z(g.newPath,P));else if(P.hash===C.hash)a.entries.push(F(g.newPath,P.mode,A.hash));else{let H=yt(e,g.newPath);H.stages=[{hash:C.hash,mode:C.mode},{hash:P.hash,mode:P.mode},{hash:A.hash,mode:A.mode}],H.pathnames=[b,g.newPath,b],H.filemask=7,H.merged={result:null,clean:!1}}else{let H=s.get(g.newPath);if(a.conflicts.push({path:g.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:b}),x(g.newPath,`CONFLICT (rename/delete): ${b} renamed to ${g.newPath} in ${y}, but deleted in ${p}.`),H){a.conflicts.push({path:g.newPath,reason:"add-add"}),x(g.newPath,`Auto-merging ${g.newPath}`,0),x(g.newPath,`CONFLICT (add/add): Merge conflict in ${g.newPath}`,1),a.entries.push(z(g.newPath,P,2)),a.entries.push(z(g.newPath,H,3));let Ge=await Fe(t,P.hash,H.hash,P.mode,i);a.worktreeBlobs.set(g.newPath,{hash:Ge,mode:P.mode})}else a.entries.push(F(g.newPath,C.mode,C.hash,1)),a.entries.push(z(g.newPath,P,2)),a.worktreeBlobs.set(g.newPath,{hash:P.hash,mode:P.mode}),P.hash!==C.hash&&x(g.newPath,`CONFLICT (modify/delete): ${g.newPath} deleted in ${p} and modified in ${y}. Version ${y} of ${g.newPath} left in tree.`,1)}}else if(O){m.add(O.newPath);let A=r.get(b),P=s.get(O.newPath),D=l.has(O.newPath);if(A)if(D)await wn(t,a,O.newPath,b,C,A,P,r,s,!0,i);else if(A.hash===C.hash&&P.hash===C.hash)a.entries.push(z(O.newPath,P));else if(A.hash===C.hash)a.entries.push(z(O.newPath,P));else if(P.hash===C.hash)a.entries.push(F(O.newPath,P.mode,A.hash));else{let H=yt(e,O.newPath);H.stages=[{hash:C.hash,mode:C.mode},{hash:A.hash,mode:A.mode},{hash:P.hash,mode:P.mode}],H.pathnames=[b,b,O.newPath],H.filemask=7,H.merged={result:null,clean:!1}}else{let H=r.get(O.newPath);if(a.conflicts.push({path:O.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:b}),x(O.newPath,`CONFLICT (rename/delete): ${b} renamed to ${O.newPath} in ${p}, but deleted in ${y}.`),H){a.conflicts.push({path:O.newPath,reason:"add-add"}),x(O.newPath,`Auto-merging ${O.newPath}`,0),x(O.newPath,`CONFLICT (add/add): Merge conflict in ${O.newPath}`,1),a.entries.push(z(O.newPath,H,2)),a.entries.push(z(O.newPath,P,3));let Ge=await Fe(t,H.hash,P.hash,H.mode,i);a.worktreeBlobs.set(O.newPath,{hash:Ge,mode:H.mode})}else a.entries.push(F(O.newPath,C.mode,C.hash,1)),a.entries.push(z(O.newPath,P,3)),a.worktreeBlobs.set(O.newPath,{hash:P.hash,mode:P.mode}),P.hash!==C.hash&&x(O.newPath,`CONFLICT (modify/delete): ${O.newPath} deleted in ${y} and modified in ${p}. Version ${p} of ${O.newPath} left in tree.`,1)}}}let R=new Set(f.renames.map(b=>b.newPath)),j=new Set(u.renames.map(b=>b.newPath)),T=mn(n,r),I=mn(n,s),w=pn(T,s,n),E=pn(I,r,n),$=gn(f.renames,w),S=gn(u.renames,E),k=yn($),M=yn(S);for(let b of[...k.keys()])M.has(b)&&(k.delete(b),M.delete(b));let B=new Set(k.keys()),N=new Set(M.keys());if(M.size>0)for(let b of o){if(b.status!=="added"||R.has(b.path))continue;let g=bn(b.path,M,B);if(!g)continue;if(e.has(g)||n.has(g)||r.has(g)||s.has(g)){if(r.has(g)){x(g,`CONFLICT (implicit dir rename): Existing file/dir at ${g} in the way of implicit directory rename(s) putting the following path(s) there: ${b.path}.`,1);continue}let A=r.get(b.path),P=s.get(g)??n.get(g);a.entries.push(F(g,A.mode,A.hash,2)),P&&a.entries.push(F(g,P.mode,P.hash,3)),a.worktreeBlobs.set(g,{hash:A.hash,mode:A.mode}),a.conflicts.push({path:g,reason:"add-add"}),x(g,`CONFLICT (file location): ${b.path} added in ${y} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${g}.`,1);let D=e.get(b.path);D&&(D.merged={result:null,clean:!0}),m.add(b.path);continue}let O=r.get(b.path);a.entries.push(F(g,O.mode,O.hash,2)),a.worktreeBlobs.set(g,{hash:O.hash,mode:O.mode}),a.conflicts.push({path:g,reason:"directory-rename"}),x(g,`CONFLICT (file location): ${b.path} added in ${y} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${g}.`,1);let C=e.get(b.path);C&&(C.merged={result:null,clean:!0}),m.add(b.path)}if(k.size>0)for(let b of c){if(b.status!=="added"||j.has(b.path))continue;let g=bn(b.path,k,N);if(!g)continue;if(e.has(g)||n.has(g)||r.has(g)||s.has(g)){if(s.has(g)){x(g,`CONFLICT (implicit dir rename): Existing file/dir at ${g} in the way of implicit directory rename(s) putting the following path(s) there: ${b.path}.`,1);continue}let A=s.get(b.path),P=r.get(g)??n.get(g);P&&a.entries.push(F(g,P.mode,P.hash,2)),a.entries.push(F(g,A.mode,A.hash,3)),a.worktreeBlobs.set(g,{hash:A.hash,mode:A.mode}),a.conflicts.push({path:g,reason:"add-add"}),x(g,`CONFLICT (file location): ${b.path} added in ${p} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${g}.`,1);let D=e.get(b.path);D&&(D.merged={result:null,clean:!0}),m.add(b.path);continue}let O=s.get(b.path);a.entries.push(F(g,O.mode,O.hash,3)),a.worktreeBlobs.set(g,{hash:O.hash,mode:O.mode}),a.conflicts.push({path:g,reason:"directory-rename"}),x(g,`CONFLICT (file location): ${b.path} added in ${p} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${g}.`,1);let C=e.get(b.path);C&&(C.merged={result:null,clean:!0}),m.add(b.path)}let ge=new Set(a.entries.map(b=>b.path));for(let b of ge){let g=e.get(b);g&&(g.merged={result:null,clean:!0})}for(let b of m){if(ge.has(b))continue;let g=e.get(b);if(!g||g.merged.clean)continue;g.filemask===7&&!g.pathConflict||(g.merged={result:null,clean:!0})}return a}function mn(t,e){let n=new Set;for(let i of t.keys()){let a=K(i);for(;a;)n.add(a),a=K(a)}let r=new Set;for(let i of e.keys()){let a=K(i);for(;a;)r.add(a),a=K(a)}let s=new Set;for(let i of n)r.has(i)||s.add(i);return s}function pn(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=K(s)??"";t.has(i)&&r.add(i)}for(let s of[...r]){let i=K(s);for(;i;)t.has(i)&&!r.has(i)&&r.add(i),i=K(i)}return r}function gn(t,e){let n=new Map;for(let r of t){let s=K(r.oldPath),i=K(r.newPath),a=!0;for(;;){if(!a){let o=s.length+(s?1:0),c=i.length+(i?1:0),f=r.oldPath.slice(o,r.oldPath.indexOf("/",o)),u=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==u)break}if(e.has(s)){let o=n.get(s);o||(o=new Map,n.set(s,o)),o.set(i,(o.get(i)??0)+1)}if(a=!1,!s||!i)break;s=K(s),i=K(i)}}return n}function yn(t){let e=new Map;for(let[n,r]of t){let s=0,i=0,a=null;for(let[o,c]of r)c===s?i=s:c>s&&(s=c,a=o);s>0&&i!==s&&a!==null&&e.set(n,a)}return e}function bn(t,e,n){let r=K(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let a=t.slice(r.length+1);return i?`${i}/${a}`:a}r=K(r)}let s=e.get("");return s!==void 0&&!n.has(s)?`${s}/${t}`:null}function K(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function wn(t,e,n,r,s,i,a,o,c,f=!1,u){let h=f?o.get(n):c.get(n),d=f?a:i;if(h.hash===d.hash){e.entries.push(F(n,h.mode,h.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await In(t,s,i,a,u,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(h.hash===m.hash)e.entries.push(F(n,h.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){e.entries.push(z(n,h,2)),e.entries.push(F(n,a.mode,m.hash,3));let y=await Fe(t,h.hash,m.hash,h.mode,u);e.worktreeBlobs.set(n,{hash:y,mode:h.mode})}else{e.entries.push(F(n,i.mode,m.hash,2)),e.entries.push(z(n,h,3));let y=await Fe(t,m.hash,h.hash,i.mode,u);e.worktreeBlobs.set(n,{hash:y,mode:i.mode})}}async function In(t,e,n,r,s,i,a){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(Q(e.mode)||Q(n.mode)||Q(r.mode))return{hash:n.hash,conflict:!0};let o=await _(t,e.hash),c=await _(t,n.hash),f=await _(t,r.hash);if(ee(c)||ee(f)||ee(o))return{hash:n.hash,conflict:!0};let u=V(o),h=V(c),d=V(f),l=s?.conflictStyle,m=Re(h,u,d,{conflictStyle:l});if(!m.conflict)return{hash:await bt(t,m.result),conflict:!1};let y=s?.a??"HEAD",p=s?.b??"theirs",x=i?.oursPath?`${y}:${i.oursPath}`:y,R=i?.theirsPath?`${p}:${i.theirsPath}`:p,j=ce(c,o,f,{a:x,b:R,markerSize:a??7,conflictStyle:l});return{hash:await G(t,"blob",ie.encode(j)),conflict:!0}}async function Fe(t,e,n,r,s){let i=await _(t,e),a=await _(t,n),o=ce(i,"",a,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return G(t,"blob",ie.encode(o))}function z(t,e,n=0){return F(t,e.mode,e.hash,n)}function F(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:ne()}}async function zr(t,e,n,r){let s=[...r.entries],i=[...r.conflicts],a=[...r.msgBuf],o=new Map(r.worktreeBlobs);function c(l,m,y=0){a.push({sortKey:l,subOrder:y,text:m})}for(let l of[...e.keys()].sort()){let m=e.get(l);if(m.merged.clean){m.merged.result?.hash&&s.push(v(l,m.merged.result.hash,m.merged.result.mode));continue}await Vr(t,m,n,s,i,c,o)}a.sort((l,m)=>(l.sortKey<m.sortKey?-1:l.sortKey>m.sortKey?1:0)||l.subOrder-m.subOrder);let f=a.map(l=>l.text),u=[],h=new Set;for(let l of s)l.stage===0&&(u.push(l),h.add(l.path));for(let[l,m]of o)h.has(l)||u.push(v(l,m.hash,m.mode));u.sort((l,m)=>Oe(l.path,m.path));let d=await at(t,u);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function Vr(t,e,n,r,s,i,a){let o=e.path,[c,f,u]=e.stages,h=c?.hash??null,d=f?.hash??null,l=u?.hash??null;if(d===null&&l!==null&&h!==null){s.push({path:o,reason:"delete-modify",deletedBy:"ours"});let m=n?.a??"HEAD",y=n?.b??"theirs";i(o,`CONFLICT (modify/delete): ${o} deleted in ${m} and modified in ${y}. Version ${y} of ${o} left in tree.`),c&&r.push(v(o,h,c.mode,1)),r.push(v(o,l,u.mode,3)),a.set(o,{hash:l,mode:u.mode});return}if(l===null&&d!==null&&h!==null){s.push({path:o,reason:"delete-modify",deletedBy:"theirs"});let m=n?.b??"theirs",y=n?.a??"HEAD";i(o,`CONFLICT (modify/delete): ${o} deleted in ${m} and modified in ${y}. Version ${y} of ${o} left in tree.`),c&&r.push(v(o,h,c.mode,1)),r.push(v(o,d,f.mode,2)),a.set(o,{hash:d,mode:f.mode});return}if(h===null&&d!==null&&l!==null){if(d===l){r.push(v(o,d,f.mode));return}i(o,`Auto-merging ${o}`,0);let m=await _(t,d),y=await _(t,l);if(ee(m)||ee(y)){s.push({path:o,reason:"add-add"}),i(o,`warning: Cannot merge binary files: ${o} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(o,`CONFLICT (add/add): Merge conflict in ${o}`,1),r.push(v(o,d,f.mode,2)),r.push(v(o,l,u.mode,3)),a.set(o,{hash:d,mode:f.mode});return}let p=V(""),x=V(m),R=V(y),j=Re(x,p,R,{conflictStyle:n?.conflictStyle});if(!j.conflict){let w=await bt(t,j.result);r.push(v(o,w,f.mode));return}s.push({path:o,reason:"add-add"}),i(o,`CONFLICT (add/add): Merge conflict in ${o}`,1),r.push(v(o,d,f.mode,2)),r.push(v(o,l,u.mode,3));let T=ce(m,"",y,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),I=await G(t,"blob",ie.encode(T));a.set(o,{hash:I,mode:f.mode});return}if(h!==null&&d!==null&&l!==null){if(d===h){r.push(v(o,l,u.mode));return}if(l===h){r.push(v(o,d,f.mode));return}if(d===l){r.push(v(o,d,f.mode));return}if(i(o,`Auto-merging ${o}`,0),Q(c.mode)||Q(f.mode)||Q(u.mode)){s.push({path:o,reason:"content"}),i(o,`CONFLICT (content): Merge conflict in ${o}`,1),r.push(v(o,h,c.mode,1)),r.push(v(o,d,f.mode,2)),r.push(v(o,l,u.mode,3)),a.set(o,{hash:d,mode:f.mode});return}let m=await _(t,h),y=await _(t,d),p=await _(t,l);if(ee(y)||ee(p)||ee(m)){s.push({path:o,reason:"content"}),i(o,`warning: Cannot merge binary files: ${o} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(o,`CONFLICT (content): Merge conflict in ${o}`,1),r.push(v(o,h,c.mode,1)),r.push(v(o,d,f.mode,2)),r.push(v(o,l,u.mode,3)),a.set(o,{hash:d,mode:f.mode});return}let x=V(m),R=V(y),j=V(p),T=Re(R,x,j,{conflictStyle:n?.conflictStyle});if(T.conflict){let I=e.pathnames[1],w=e.pathnames[2],E=I!==o||w!==o,$={path:o,reason:"content"};E&&(I!==o&&($.oursOrigPath=I),w!==o&&($.theirsOrigPath=w)),s.push($),i(o,`CONFLICT (content): Merge conflict in ${o}`,1),r.push(v(o,h,c.mode,1)),r.push(v(o,d,f.mode,2)),r.push(v(o,l,u.mode,3));let S=E?`${n?.a??"HEAD"}:${I}`:n?.a??"HEAD",k=E?`${n?.b??"theirs"}:${w}`:n?.b??"theirs",M=ce(y,m,p,{a:S,b:k,conflictStyle:n?.conflictStyle}),B=await G(t,"blob",ie.encode(M));a.set(o,{hash:B,mode:f.mode})}else{let I=await bt(t,T.result);r.push(v(o,I,f.mode))}return}}var Kr=200;async function On(t,e,n,r,s){let i=await Promise.all(r.map(async u=>({hash:u,timestamp:(await U(t,u)).committer.timestamp})));i.sort((u,h)=>u.timestamp-h.timestamp);let a=i.map(u=>u.hash),o=a[0],c=o,f=(await U(t,o)).tree;for(let u=1;u<a.length;u++){let h=a[u],d=(await U(t,h)).tree,l=null;if(s>=Kr)l=f;else{let p=await Pe(t,c,h);p.length===0?l=null:p.length===1?l=(await U(t,p[0])).tree:l=await On(t,c,h,p,s+1)}let m=await pe(t,l,f,d);f=await qr(t,m,s);let y=Ce({type:"commit",tree:f,parents:[c,h],author:dn,committer:dn,message:"merged common ancestors"});c=await G(t,"commit",y)}return f}async function qr(t,e,n){let r=e.entries.filter(o=>o.stage===0),s=new Map;for(let o of e.entries)o.stage>0&&s.set(`${o.path}\0${o.stage}`,o);let i=(o,c)=>s.get(`${o}\0${c}`),a={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let o of e.conflicts){if(o.reason==="delete-modify"||o.reason==="rename-delete"){let u=i(o.path,1);if(u){r.push({...u,stage:0});continue}}if(o.reason==="rename-rename"){let u=o.oursPath??o.path,h=o.theirsPath??o.path,d=i(o.path,1),l=i(u,2),m=i(h,3);if(l&&m){let y=me.decode((await q(t,l.hash)).content),p=me.decode((await q(t,m.hash)).content),x=d?me.decode((await q(t,d.hash)).content):"",R=8+n*2,j=a.a??"Temporary merge branch 1",T=a.b??"Temporary merge branch 2",I=ce(y,x,p,{a:`${j}:${u}`,o:a.o,b:`${T}:${h}`,markerSize:R}),w=await G(t,"blob",ie.encode(I));r.push({path:u,mode:l.mode,hash:w,stage:0,stat:ne()}),r.push({path:h,mode:m.mode,hash:w,stage:0,stat:ne()});continue}else if(l){r.push({...l,stage:0});continue}}let c=i(o.path,2),f=i(o.path,3);if(c&&f&&(o.reason==="content"||o.reason==="add-add")){let u=me.decode((await q(t,c.hash)).content),h=me.decode((await q(t,f.hash)).content),d=o.reason==="content"?i(o.path,1):null,l=d?me.decode((await q(t,d.hash)).content):"",m=o.oursOrigPath||o.theirsOrigPath,y=a.a??"Temporary merge branch 1",p=a.b??"Temporary merge branch 2",x=m?`${y}:${o.oursOrigPath??o.path}`:y,R=m?`${p}:${o.theirsOrigPath??o.path}`:p,j=ce(u,l,h,{a:x,o:a.o,b:R,markerSize:a.markerSize}),T=await G(t,"blob",ie.encode(j));r.push({path:o.path,mode:c.mode,hash:T,stage:0,stat:ne()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((o,c)=>Oe(o.path,c.path)),at(t,r)}async function bt(t,e){let n=e.map(gt);if(n.length===0)return G(t,"blob",ie.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 xt(t){return t.endsWith("\0")?t.slice(0,-1):t}function wn(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 we=new TextDecoder,fe=new TextEncoder,In={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function Ie(t,e,n,r,s){let{paths:i,baseMap:a,oursMap:o,theirsMap:c}=await Jr(t,e,n,r),f=await Qr(t,i,a,o,c,s);return es(t,i,s,f)}async function Sn(t,e,n,r){let s=await je(t,e,n),i=await U(t,e),a=await U(t,n);if(s.length===0)return{...await Ie(t,null,i.tree,a.tree,r),baseTree:null};if(s.length===1){let f=await U(t,s[0]);return{...await Ie(t,f.tree,i.tree,a.tree,r),baseTree:f.tree}}let o=await jn(t,e,n,s,1);return{...await Ie(t,o,i.tree,a.tree,r),baseTree:o}}async function Jr(t,e,n,r){let s=await ie(t,e),i=await ie(t,n),a=await ie(t,r),o=new Set;for(let f of s.keys())o.add(f);for(let f of i.keys())o.add(f);for(let f of a.keys())o.add(f);let c=new Map;for(let f of o){let u=s.get(f)??null,h=i.get(f)??null,d=a.get(f)??null,l=u?{hash:u.hash,mode:u.mode}:null,m=h?{hash:h.hash,mode:h.mode}:null,g=d?{hash:d.hash,mode:d.mode}:null,p=(u?1:0)|(h?2:0)|(d?4:0),I=u?.hash??null,k=h?.hash??null,C=d?.hash??null,A=0;I!==null&&I===k&&(A|=3),I!==null&&I===C&&(A|=5),k!==null&&k===C&&(A|=6);let P={path:f,stages:[l,m,g],pathnames:[f,f,f],filemask:p,matchMask:A,merged:{result:null,clean:!1},pathConflict:!1};if(Zr(P)){c.set(f,P);continue}c.set(f,P)}return{paths:c,baseMap:s,oursMap:i,theirsMap:a}}function Zr(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,a=r?.hash??null;return i===s&&a===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===a&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&a===null?(t.merged={result:null,clean:!0},!0):a===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&a!==s?(r?t.merged={result:{hash:a,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function Qr(t,e,n,r,s,i){let a={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},o=[],c=[];for(let[w,b]of n)r.has(w)||o.push({path:w,status:"deleted",oldHash:b.hash,oldMode:b.mode}),s.has(w)||c.push({path:w,status:"deleted",oldHash:b.hash,oldMode:b.mode});for(let[w,b]of r)n.has(w)||o.push({path:w,status:"added",newHash:b.hash,newMode:b.mode});for(let[w,b]of s)n.has(w)||c.push({path:w,status:"added",newHash:b.hash,newMode:b.mode});let f=await Te(t,o),u=await Te(t,c);if(f.renames.length===0&&u.renames.length===0)return a;let h=new Map,d=new Map;for(let w of f.renames)h.set(w.oldPath,w);for(let w of u.renames)d.set(w.oldPath,w);let l=new Set;for(let[w]of r)!n.has(w)&&s.has(w)&&l.add(w);let m=new Set,g=i?.a??"HEAD",p=i?.b??"theirs";function I(w,b,E=0){a.msgBuf.push({sortKey:w,subOrder:E,text:b})}for(let w of[...n.keys()].sort()){let b=h.get(w),E=d.get(w);if(!b&&!E)continue;let M=n.get(w);if(m.add(w),b&&E)if(m.add(b.newPath),m.add(E.newPath),b.newPath===E.newPath){let L=r.get(b.newPath),j=s.get(E.newPath);if(L.hash===j.hash)a.entries.push(z(b.newPath,L));else{let N=Ot(e,b.newPath);N.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:j.hash,mode:j.mode}],N.pathnames=[w,b.newPath,E.newPath],N.filemask=7,N.merged={result:null,clean:!1}}}else{let L=r.get(b.newPath),j=s.get(E.newPath),N=await Tn(t,M,L,j,i);N.conflict&&I(w,`Auto-merging ${w}`,-1),a.conflicts.push({path:w,reason:"rename-rename",oursPath:b.newPath,theirsPath:E.newPath}),I(w,`CONFLICT (rename/rename): ${w} renamed to ${b.newPath} in ${g} and to ${E.newPath} in ${p}.`),a.entries.push(z(w,M,1)),a.entries.push(G(b.newPath,L.mode,N.hash,2)),a.entries.push(G(E.newPath,j.mode,N.hash,3)),a.worktreeBlobs.set(b.newPath,{hash:N.hash,mode:L.mode}),a.worktreeBlobs.set(E.newPath,{hash:N.hash,mode:j.mode})}else if(b){m.add(b.newPath);let L=s.get(w),j=r.get(b.newPath),N=l.has(b.newPath);if(L)if(N)await En(t,a,b.newPath,w,M,j,L,r,s,!1,i);else if(L.hash===M.hash&&j.hash===M.hash)a.entries.push(z(b.newPath,j));else if(L.hash===M.hash)a.entries.push(z(b.newPath,j));else if(j.hash===M.hash)a.entries.push(G(b.newPath,j.mode,L.hash));else{let F=Ot(e,b.newPath);F.stages=[{hash:M.hash,mode:M.mode},{hash:j.hash,mode:j.mode},{hash:L.hash,mode:L.mode}],F.pathnames=[w,b.newPath,w],F.filemask=7,F.merged={result:null,clean:!1}}else{let F=s.get(b.newPath);if(a.conflicts.push({path:b.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:w}),I(b.newPath,`CONFLICT (rename/delete): ${w} renamed to ${b.newPath} in ${g}, but deleted in ${p}.`),F){a.conflicts.push({path:b.newPath,reason:"add-add"}),I(b.newPath,`Auto-merging ${b.newPath}`,0),I(b.newPath,`CONFLICT (add/add): Merge conflict in ${b.newPath}`,1),a.entries.push(z(b.newPath,j,2)),a.entries.push(z(b.newPath,F,3));let Ye=await qe(t,j.hash,F.hash,j.mode,i);a.worktreeBlobs.set(b.newPath,{hash:Ye,mode:j.mode})}else a.entries.push(G(b.newPath,M.mode,M.hash,1)),a.entries.push(z(b.newPath,j,2)),a.worktreeBlobs.set(b.newPath,{hash:j.hash,mode:j.mode}),j.hash!==M.hash&&I(b.newPath,`CONFLICT (modify/delete): ${b.newPath} deleted in ${p} and modified in ${g}. Version ${g} of ${b.newPath} left in tree.`,1)}}else if(E){m.add(E.newPath);let L=r.get(w),j=s.get(E.newPath),N=l.has(E.newPath);if(L)if(N)await En(t,a,E.newPath,w,M,L,j,r,s,!0,i);else if(L.hash===M.hash&&j.hash===M.hash)a.entries.push(z(E.newPath,j));else if(L.hash===M.hash)a.entries.push(z(E.newPath,j));else if(j.hash===M.hash)a.entries.push(G(E.newPath,j.mode,L.hash));else{let F=Ot(e,E.newPath);F.stages=[{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode},{hash:j.hash,mode:j.mode}],F.pathnames=[w,w,E.newPath],F.filemask=7,F.merged={result:null,clean:!1}}else{let F=r.get(E.newPath);if(a.conflicts.push({path:E.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:w}),I(E.newPath,`CONFLICT (rename/delete): ${w} renamed to ${E.newPath} in ${p}, but deleted in ${g}.`),F){a.conflicts.push({path:E.newPath,reason:"add-add"}),I(E.newPath,`Auto-merging ${E.newPath}`,0),I(E.newPath,`CONFLICT (add/add): Merge conflict in ${E.newPath}`,1),a.entries.push(z(E.newPath,F,2)),a.entries.push(z(E.newPath,j,3));let Ye=await qe(t,F.hash,j.hash,F.mode,i);a.worktreeBlobs.set(E.newPath,{hash:Ye,mode:F.mode})}else a.entries.push(G(E.newPath,M.mode,M.hash,1)),a.entries.push(z(E.newPath,j,3)),a.worktreeBlobs.set(E.newPath,{hash:j.hash,mode:j.mode}),j.hash!==M.hash&&I(E.newPath,`CONFLICT (modify/delete): ${E.newPath} deleted in ${g} and modified in ${p}. Version ${p} of ${E.newPath} left in tree.`,1)}}}let k=new Set(f.renames.map(w=>w.newPath)),C=new Set(u.renames.map(w=>w.newPath)),A=xn(n,r),P=xn(n,s),y=On(A,s,n),O=On(P,r,n),T=Pn(f.renames,y),x=Pn(u.renames,O),R=Rn(T),S=Rn(x);for(let w of[...R.keys()])S.has(w)&&(R.delete(w),S.delete(w));let $=new Set(R.keys()),v=new Set(S.keys());if(S.size>0)for(let w of o){if(w.status!=="added"||k.has(w.path))continue;let b=kn(w.path,S,$);if(!b)continue;if(e.has(b)||n.has(b)||r.has(b)||s.has(b)){if(r.has(b)){I(b,`CONFLICT (implicit dir rename): Existing file/dir at ${b} in the way of implicit directory rename(s) putting the following path(s) there: ${w.path}.`,1);continue}let L=r.get(w.path),j=s.get(b)??n.get(b);a.entries.push(G(b,L.mode,L.hash,2)),j&&a.entries.push(G(b,j.mode,j.hash,3)),a.worktreeBlobs.set(b,{hash:L.hash,mode:L.mode}),a.conflicts.push({path:b,reason:"add-add"}),I(b,`CONFLICT (file location): ${w.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${b}.`,1);let N=e.get(w.path);N&&(N.merged={result:null,clean:!0}),m.add(w.path);continue}let E=r.get(w.path);a.entries.push(G(b,E.mode,E.hash,2)),a.worktreeBlobs.set(b,{hash:E.hash,mode:E.mode}),a.conflicts.push({path:b,reason:"directory-rename"}),I(b,`CONFLICT (file location): ${w.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${b}.`,1);let M=e.get(w.path);M&&(M.merged={result:null,clean:!0}),m.add(w.path)}if(R.size>0)for(let w of c){if(w.status!=="added"||C.has(w.path))continue;let b=kn(w.path,R,v);if(!b)continue;if(e.has(b)||n.has(b)||r.has(b)||s.has(b)){if(s.has(b)){I(b,`CONFLICT (implicit dir rename): Existing file/dir at ${b} in the way of implicit directory rename(s) putting the following path(s) there: ${w.path}.`,1);continue}let L=s.get(w.path),j=r.get(b)??n.get(b);j&&a.entries.push(G(b,j.mode,j.hash,2)),a.entries.push(G(b,L.mode,L.hash,3)),a.worktreeBlobs.set(b,{hash:L.hash,mode:L.mode}),a.conflicts.push({path:b,reason:"add-add"}),I(b,`CONFLICT (file location): ${w.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${b}.`,1);let N=e.get(w.path);N&&(N.merged={result:null,clean:!0}),m.add(w.path);continue}let E=s.get(w.path);a.entries.push(G(b,E.mode,E.hash,3)),a.worktreeBlobs.set(b,{hash:E.hash,mode:E.mode}),a.conflicts.push({path:b,reason:"directory-rename"}),I(b,`CONFLICT (file location): ${w.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${b}.`,1);let M=e.get(w.path);M&&(M.merged={result:null,clean:!0}),m.add(w.path)}let ne=new Set(a.entries.map(w=>w.path));for(let w of ne){let b=e.get(w);b&&(b.merged={result:null,clean:!0})}for(let w of m){if(ne.has(w))continue;let b=e.get(w);if(!b||b.merged.clean)continue;b.filemask===7&&!b.pathConflict||(b.merged={result:null,clean:!0})}return a}function xn(t,e){let n=new Set;for(let i of t.keys()){let a=K(i);for(;a;)n.add(a),a=K(a)}let r=new Set;for(let i of e.keys()){let a=K(i);for(;a;)r.add(a),a=K(a)}let s=new Set;for(let i of n)r.has(i)||s.add(i);return s}function On(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=K(s)??"";t.has(i)&&r.add(i)}for(let s of[...r]){let i=K(s);for(;i;)t.has(i)&&!r.has(i)&&r.add(i),i=K(i)}return r}function Pn(t,e){let n=new Map;for(let r of t){let s=K(r.oldPath),i=K(r.newPath),a=!0;for(;;){if(!a){let o=s.length+(s?1:0),c=i.length+(i?1:0),f=r.oldPath.slice(o,r.oldPath.indexOf("/",o)),u=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==u)break}if(e.has(s)){let o=n.get(s);o||(o=new Map,n.set(s,o)),o.set(i,(o.get(i)??0)+1)}if(a=!1,!s||!i)break;s=K(s),i=K(i)}}return n}function Rn(t){let e=new Map;for(let[n,r]of t){let s=0,i=0,a=null;for(let[o,c]of r)c===s?i=s:c>s&&(s=c,a=o);s>0&&i!==s&&a!==null&&e.set(n,a)}return e}function kn(t,e,n){let r=K(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let a=t.slice(r.length+1);return i?`${i}/${a}`:a}r=K(r)}let s=e.get("");return s!==void 0&&!n.has(s)?`${s}/${t}`:null}function K(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function En(t,e,n,r,s,i,a,o,c,f=!1,u){let h=f?o.get(n):c.get(n),d=f?a:i;if(h.hash===d.hash){e.entries.push(G(n,h.mode,h.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await Tn(t,s,i,a,u,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(h.hash===m.hash)e.entries.push(G(n,h.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){e.entries.push(z(n,h,2)),e.entries.push(G(n,a.mode,m.hash,3));let g=await qe(t,h.hash,m.hash,h.mode,u);e.worktreeBlobs.set(n,{hash:g,mode:h.mode})}else{e.entries.push(G(n,i.mode,m.hash,2)),e.entries.push(z(n,h,3));let g=await qe(t,m.hash,h.hash,i.mode,u);e.worktreeBlobs.set(n,{hash:g,mode:i.mode})}}async function Tn(t,e,n,r,s,i,a){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(Q(e.mode)||Q(n.mode)||Q(r.mode))return{hash:n.hash,conflict:!0};let o=await H(t,e.hash),c=await H(t,n.hash),f=await H(t,r.hash);if(ee(c)||ee(f)||ee(o))return{hash:n.hash,conflict:!0};let u=V(o),h=V(c),d=V(f),l=s?.conflictStyle,m=Ce(h,u,d,{conflictStyle:l});if(!m.conflict)return{hash:await Pt(t,m.result),conflict:!1};let g=s?.a??"HEAD",p=s?.b??"theirs",I=i?.oursPath?`${g}:${i.oursPath}`:g,k=i?.theirsPath?`${p}:${i.theirsPath}`:p,C=de(c,o,f,{a:I,b:k,markerSize:a??7,conflictStyle:l});return{hash:await _(t,"blob",fe.encode(C)),conflict:!0}}async function qe(t,e,n,r,s){let i=await H(t,e),a=await H(t,n),o=de(i,"",a,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return _(t,"blob",fe.encode(o))}function z(t,e,n=0){return G(t,e.mode,e.hash,n)}function G(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:re()}}async function es(t,e,n,r){let s=[...r.entries],i=[...r.conflicts],a=[...r.msgBuf],o=new Map(r.worktreeBlobs);function c(l,m,g=0){a.push({sortKey:l,subOrder:g,text:m})}for(let l of[...e.keys()].sort()){let m=e.get(l);if(m.merged.clean){m.merged.result?.hash&&s.push(B(l,m.merged.result.hash,m.merged.result.mode));continue}await ts(t,m,n,s,i,c,o)}a.sort((l,m)=>(l.sortKey<m.sortKey?-1:l.sortKey>m.sortKey?1:0)||l.subOrder-m.subOrder);let f=a.map(l=>l.text),u=[],h=new Set;for(let l of s)l.stage===0&&(u.push(l),h.add(l.path));for(let[l,m]of o)h.has(l)||u.push(B(l,m.hash,m.mode));u.sort((l,m)=>Se(l.path,m.path));let d=await mt(t,u);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function ts(t,e,n,r,s,i,a){let o=e.path,[c,f,u]=e.stages,h=c?.hash??null,d=f?.hash??null,l=u?.hash??null;if(d===null&&l!==null&&h!==null){s.push({path:o,reason:"delete-modify",deletedBy:"ours"});let m=n?.a??"HEAD",g=n?.b??"theirs";i(o,`CONFLICT (modify/delete): ${o} deleted in ${m} and modified in ${g}. Version ${g} of ${o} left in tree.`),c&&r.push(B(o,h,c.mode,1)),r.push(B(o,l,u.mode,3)),a.set(o,{hash:l,mode:u.mode});return}if(l===null&&d!==null&&h!==null){s.push({path:o,reason:"delete-modify",deletedBy:"theirs"});let m=n?.b??"theirs",g=n?.a??"HEAD";i(o,`CONFLICT (modify/delete): ${o} deleted in ${m} and modified in ${g}. Version ${g} of ${o} left in tree.`),c&&r.push(B(o,h,c.mode,1)),r.push(B(o,d,f.mode,2)),a.set(o,{hash:d,mode:f.mode});return}if(h===null&&d!==null&&l!==null){if(d===l){r.push(B(o,d,f.mode));return}i(o,`Auto-merging ${o}`,0);let m=await H(t,d),g=await H(t,l);if(ee(m)||ee(g)){s.push({path:o,reason:"add-add"}),i(o,`warning: Cannot merge binary files: ${o} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(o,`CONFLICT (add/add): Merge conflict in ${o}`,1),r.push(B(o,d,f.mode,2)),r.push(B(o,l,u.mode,3)),a.set(o,{hash:d,mode:f.mode});return}let p=V(""),I=V(m),k=V(g),C=Ce(I,p,k,{conflictStyle:n?.conflictStyle});if(!C.conflict){let y=await Pt(t,C.result);r.push(B(o,y,f.mode));return}s.push({path:o,reason:"add-add"}),i(o,`CONFLICT (add/add): Merge conflict in ${o}`,1),r.push(B(o,d,f.mode,2)),r.push(B(o,l,u.mode,3));let A=de(m,"",g,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),P=await _(t,"blob",fe.encode(A));a.set(o,{hash:P,mode:f.mode});return}if(h!==null&&d!==null&&l!==null){if(d===h){r.push(B(o,l,u.mode));return}if(l===h){r.push(B(o,d,f.mode));return}if(d===l){r.push(B(o,d,f.mode));return}if(i(o,`Auto-merging ${o}`,0),Q(c.mode)||Q(f.mode)||Q(u.mode)){s.push({path:o,reason:"content"}),i(o,`CONFLICT (content): Merge conflict in ${o}`,1),r.push(B(o,h,c.mode,1)),r.push(B(o,d,f.mode,2)),r.push(B(o,l,u.mode,3)),a.set(o,{hash:d,mode:f.mode});return}let m=await H(t,h),g=await H(t,d),p=await H(t,l);if(ee(g)||ee(p)||ee(m)){s.push({path:o,reason:"content"}),i(o,`warning: Cannot merge binary files: ${o} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(o,`CONFLICT (content): Merge conflict in ${o}`,1),r.push(B(o,h,c.mode,1)),r.push(B(o,d,f.mode,2)),r.push(B(o,l,u.mode,3)),a.set(o,{hash:d,mode:f.mode});return}let I=V(m),k=V(g),C=V(p),A=Ce(k,I,C,{conflictStyle:n?.conflictStyle});if(A.conflict){let P=e.pathnames[1],y=e.pathnames[2],O=P!==o||y!==o,T={path:o,reason:"content"};O&&(P!==o&&(T.oursOrigPath=P),y!==o&&(T.theirsOrigPath=y)),s.push(T),i(o,`CONFLICT (content): Merge conflict in ${o}`,1),r.push(B(o,h,c.mode,1)),r.push(B(o,d,f.mode,2)),r.push(B(o,l,u.mode,3));let x=O?`${n?.a??"HEAD"}:${P}`:n?.a??"HEAD",R=O?`${n?.b??"theirs"}:${y}`:n?.b??"theirs",S=de(g,m,p,{a:x,b:R,conflictStyle:n?.conflictStyle}),$=await _(t,"blob",fe.encode(S));a.set(o,{hash:$,mode:f.mode})}else{let P=await Pt(t,A.result);r.push(B(o,P,f.mode))}return}}var ns=200;async function jn(t,e,n,r,s){let i=await Promise.all(r.map(async u=>({hash:u,timestamp:(await U(t,u)).committer.timestamp})));i.sort((u,h)=>u.timestamp-h.timestamp);let a=i.map(u=>u.hash),o=a[0],c=o,f=(await U(t,o)).tree;for(let u=1;u<a.length;u++){let h=a[u],d=(await U(t,h)).tree,l=null;if(s>=ns)l=f;else{let p=await je(t,c,h);p.length===0?l=null:p.length===1?l=(await U(t,p[0])).tree:l=await jn(t,c,h,p,s+1)}let m=await Ie(t,l,f,d);f=await rs(t,m,s);let g=Be({type:"commit",tree:f,parents:[c,h],author:In,committer:In,message:"merged common ancestors"});c=await _(t,"commit",g)}return f}async function rs(t,e,n){let r=e.entries.filter(o=>o.stage===0),s=new Map;for(let o of e.entries)o.stage>0&&s.set(`${o.path}\0${o.stage}`,o);let i=(o,c)=>s.get(`${o}\0${c}`),a={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let o of e.conflicts){if(o.reason==="delete-modify"||o.reason==="rename-delete"){let u=i(o.path,1);if(u){r.push({...u,stage:0});continue}}if(o.reason==="rename-rename"){let u=o.oursPath??o.path,h=o.theirsPath??o.path,d=i(o.path,1),l=i(u,2),m=i(h,3);if(l&&m){let g=we.decode((await q(t,l.hash)).content),p=we.decode((await q(t,m.hash)).content),I=d?we.decode((await q(t,d.hash)).content):"",k=8+n*2,C=a.a??"Temporary merge branch 1",A=a.b??"Temporary merge branch 2",P=de(g,I,p,{a:`${C}:${u}`,o:a.o,b:`${A}:${h}`,markerSize:k}),y=await _(t,"blob",fe.encode(P));r.push({path:u,mode:l.mode,hash:y,stage:0,stat:re()}),r.push({path:h,mode:m.mode,hash:y,stage:0,stat:re()});continue}else if(l){r.push({...l,stage:0});continue}}let c=i(o.path,2),f=i(o.path,3);if(c&&f&&(o.reason==="content"||o.reason==="add-add")){let u=we.decode((await q(t,c.hash)).content),h=we.decode((await q(t,f.hash)).content),d=o.reason==="content"?i(o.path,1):null,l=d?we.decode((await q(t,d.hash)).content):"",m=o.oursOrigPath||o.theirsOrigPath,g=a.a??"Temporary merge branch 1",p=a.b??"Temporary merge branch 2",I=m?`${g}:${o.oursOrigPath??o.path}`:g,k=m?`${p}:${o.theirsOrigPath??o.path}`:p,C=de(u,l,h,{a:I,o:a.o,b:k,markerSize:a.markerSize}),A=await _(t,"blob",fe.encode(C));r.push({path:o.path,mode:c.mode,hash:A,stage:0,stat:re()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((o,c)=>Se(o.path,c.path)),mt(t,r)}async function Pt(t,e){let n=e.map(xt);if(n.length===0)return _(t,"blob",fe.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?n.join(`
16
18
  `):`${n.join(`
17
19
  `)}
18
- `;return G(t,"blob",ie.encode(i))}function v(t,e,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:s,hash:e,stage:r,stat:ne()}}function yt(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*Yr(t,e,n){let r=e?[e]:[];for await(let s of ft(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 Xr(t,e,n){let r=await U(t,n),s=null;return e&&(s=(await U(t,e)).tree),ct(t,s,r.tree)}async function Jr(t,e,n){return mt(t,e,n)}async function Zr(t,e){return $e(t,e)}async function Qr(t){return ot(t,"refs/heads")}async function es(t){return ot(t,"refs/tags")}async function ts(t,e){return U(t,e)}async function ns(t,e){return te(t,e)}async function rs(t,e){return _(t,e)}async function ss(t,e){return ae(t,e)}async function is(t,e,n){return ct(t,e,n)}async function os(t,e,n){return Pe(t,e,n)}async function as(t,e,n,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await xn(t,e,n,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function cs(t,e,n,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,a=await pe(t,e,n,r,i);return{treeHash:a.resultTree,clean:a.conflicts.length===0,conflicts:a.conflicts,messages:a.messages}}async function fs(t,e){let n=Ce({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message}),r=await G(t,"commit",n);if(e.branch){let s=`refs/heads/${e.branch}`;await t.refStore.writeRef(s,{type:"direct",hash:r}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:s})}return r}async function ls(t,e){let n=[...e].sort((i,a)=>i.name.localeCompare(a.name)),r=await Promise.all(n.map(async i=>{let a=i.mode;return a||(a=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:a,name:i.name,hash:i.hash}})),s=Me({type:"tree",entries:r});return G(t,"tree",s)}async function us(t,e){return G(t,"blob",new TextEncoder().encode(e))}async function hs(t,e,n){let r=await U(t,e),i=(await ae(t,r.tree)).find(a=>a.path===n);return i?_(t,i.hash):null}var Pn=/^[0-9a-f]{40}$/;async function ds(t,e,n,r="/"){let s=await $e(t,e);if(!s)if(Pn.test(e)&&await t.objectStore.exists(e))s=e;else throw new Error(`ref or commit '${e}' not found`);let i=await U(t,s),a=await ae(t,i.tree),o=new Set,c=0;for(let f of a){let u=L(r,f.path),h=_e(u);if(h!==r&&!o.has(h)&&(await n.mkdir(h,{recursive:!0}),o.add(h)),Q(f.mode)){let d=await _(t,f.hash);n.symlink?await n.symlink(d,u):await n.writeFile(u,d)}else{let d=await te(t,f.hash);await n.writeFile(u,d)}c++}return{commitHash:s,treeHash:i.tree,filesWritten:c}}async function ms(t,e,n){let r=n?.workTree??"/",s=n?.gitDir??L(r,".git"),i=n?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let a=await $e(t,i);if(!a)if(Pn.test(i)&&await t.objectStore.exists(i))a=i;else throw new Error(`ref or commit '${i}' not found`);let o=await U(t,a),c=await ae(t,o.tree),f={...t,fs:e,gitDir:s,workTree:r},u=new Set,h=0;for(let l of c){let m=L(r,l.path),y=_e(m);if(y!==r&&!u.has(y)&&(await e.mkdir(y,{recursive:!0}),u.add(y)),Q(l.mode)){let p=await _(t,l.hash);e.symlink?await e.symlink(p,m):await e.writeFile(m,p)}else{let p=await te(t,l.hash);await e.writeFile(m,p)}h++}let d=Pt(c.map(l=>({path:l.path,mode:parseInt(l.mode,8),hash:l.hash,stage:0,stat:ne()})));return await ze(f,d),{ctx:f,commitHash:a,treeHash:o.tree,filesWritten:h}}var wt=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")}findByPrefix(e){return this.inner.findByPrefix(e)}},xt=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 ps(t){return{objectStore:new wt(t.objectStore),refStore:new xt(t.refStore),hooks:t.hooks}}export{it as FileSystemRefStore,tt as PackedObjectStore,ds as checkoutTo,fs as createCommit,ms as createWorktree,is as diffTrees,os as findMergeBases,ss as flattenTree,Xr as getChangedFiles,Yr as getNewCommits,Jr as isAncestor,Qr as listBranches,es as listTags,as as mergeTrees,cs as mergeTreesFromTreeHashes,ns as readBlob,rs as readBlobText,ts as readCommit,hs as readFileAtCommit,ps as readonlyRepo,Zr as resolveRef,us as writeBlob,ls as writeTree};
20
+ `;return _(t,"blob",fe.encode(i))}function B(t,e,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:s,hash:e,stage:r,stat:re()}}function Ot(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*ss(t,e,n){let r=e?[e]:[];for await(let s of ye(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 is(t,e,n){let r=await U(t,n),s=null;return e&&(s=(await U(t,e)).tree),Ee(t,s,r.tree)}async function os(t,e,n){return wt(t,e,n)}async function as(t,e){return De(t,e)}async function cs(t){return dt(t,"refs/heads")}async function fs(t){return dt(t,"refs/tags")}async function ls(t,e){return U(t,e)}async function us(t,e){return te(t,e)}async function hs(t,e){return H(t,e)}async function ds(t,e){return ue(t,e)}async function ms(t,e,n){return Ee(t,e,n)}async function ps(t,e,n){return je(t,e,n)}async function gs(t,e,n,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await Sn(t,e,n,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function bs(t,e,n,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,a=await Ie(t,e,n,r,i);return{treeHash:a.resultTree,clean:a.conflicts.length===0,conflicts:a.conflicts,messages:a.messages}}async function ys(t,e){let n=Be({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message}),r=await _(t,"commit",n);if(e.branch){let s=`refs/heads/${e.branch}`;await t.refStore.writeRef(s,{type:"direct",hash:r}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:s})}return r}async function ws(t,e){let n=[...e].sort((i,a)=>i.name.localeCompare(a.name)),r=await Promise.all(n.map(async i=>{let a=i.mode;return a||(a=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:a,name:i.name,hash:i.hash}})),s=He({type:"tree",entries:r});return _(t,"tree",s)}async function Is(t,e){return _(t,"blob",new TextEncoder().encode(e))}async function xs(t,e,n){let r=await U(t,e),i=(await ue(t,r.tree)).find(a=>a.path===n);return i?H(t,i.hash):null}var Cn=/^[0-9a-f]{40}$/;async function Os(t,e,n,r="/"){let s=await De(t,e);if(!s)if(Cn.test(e)&&await t.objectStore.exists(e))s=e;else throw new Error(`ref or commit '${e}' not found`);let i=await U(t,s),a=await ue(t,i.tree),o=new Set,c=0;for(let f of a){let u=D(r,f.path),h=Xe(u);if(h!==r&&!o.has(h)&&(await n.mkdir(h,{recursive:!0}),o.add(h)),Q(f.mode)){let d=await H(t,f.hash);n.symlink?await n.symlink(d,u):await n.writeFile(u,d)}else{let d=await te(t,f.hash);await n.writeFile(u,d)}c++}return{commitHash:s,treeHash:i.tree,filesWritten:c}}async function Ps(t,e,n){let r=n?.workTree??"/",s=n?.gitDir??D(r,".git"),i=n?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let a=await De(t,i);if(!a)if(Cn.test(i)&&await t.objectStore.exists(i))a=i;else throw new Error(`ref or commit '${i}' not found`);let o=await U(t,a),c=await ue(t,o.tree),f={...t,fs:e,gitDir:s,workTree:r},u=new Set,h=0;for(let l of c){let m=D(r,l.path),g=Xe(m);if(g!==r&&!u.has(g)&&(await e.mkdir(g,{recursive:!0}),u.add(g)),Q(l.mode)){let p=await H(t,l.hash);e.symlink?await e.symlink(p,m):await e.writeFile(m,p)}else{let p=await te(t,l.hash);await e.writeFile(m,p)}h++}let d=Tt(c.map(l=>({path:l.path,mode:parseInt(l.mode,8),hash:l.hash,stage:0,stat:re()})));return await Ze(f,d),{ctx:f,commitHash:a,treeHash:o.tree,filesWritten:h}}async function Rs(t,e,n){return gn(t,e,n)}async function ks(t,e,n,r){return pn(t,e,n,r)}async function*Es(t,e,n){for await(let r of ye(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}}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")}findByPrefix(e){return this.inner.findByPrefix(e)}},kt=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 Ss(t){return{objectStore:new Rt(t.objectStore),refStore:new kt(t.refStore),hooks:t.hooks}}export{ht as FileSystemRefStore,ct as PackedObjectStore,ks as blame,Os as checkoutTo,Rs as countAheadBehind,ys as createCommit,Ps as createWorktree,ms as diffTrees,ps as findMergeBases,ds as flattenTree,is as getChangedFiles,ss as getNewCommits,os as isAncestor,cs as listBranches,fs as listTags,gs as mergeTrees,bs as mergeTreesFromTreeHashes,us as readBlob,hs as readBlobText,ls as readCommit,xs as readFileAtCommit,Ss as readonlyRepo,as as resolveRef,Es as walkCommitHistory,Is as writeBlob,ws as writeTree};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-git",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "Pure TypeScript git implementation: virtual filesystem client and embeddable server.",
5
5
  "keywords": [
6
6
  "agent",