just-git 1.2.0 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { O as ObjectId, a0 as Identity, G as GitContext, a as GitRepo, F as FileSystem, a1 as TreeDiffEntry, X as RefEntry, a2 as Commit, c as ObjectStore, a3 as ObjectType, a4 as RawObject, d as RefStore, a5 as Ref } from '../hooks-Boa35Qx_.js';
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
3
  interface MergeConflict {
4
4
  path: string;
@@ -38,6 +38,7 @@ interface FlatTreeEntry {
38
38
  * and equally useful outside the server for direct repo inspection.
39
39
  */
40
40
 
41
+ /** Commit metadata returned by {@link getNewCommits}. */
41
42
  interface CommitInfo {
42
43
  hash: string;
43
44
  message: string;
@@ -57,20 +58,35 @@ declare function getNewCommits(repo: GitRepo, oldHash: string | null, newHash: s
57
58
  * If oldHash is null (new ref), diffs against an empty tree.
58
59
  */
59
60
  declare function getChangedFiles(repo: GitRepo, oldHash: string | null, newHash: string): Promise<TreeDiffEntry[]>;
61
+ /** Check whether `candidate` is an ancestor of `descendant` in the commit graph. */
60
62
  declare function isAncestor(repo: GitRepo, candidate: string, descendant: string): Promise<boolean>;
63
+ /** Resolve a ref name (e.g. "HEAD", "refs/heads/main") to a commit hash. Returns null if not found. */
61
64
  declare function resolveRef(repo: GitRepo, name: string): Promise<string | null>;
65
+ /** List all local branches (`refs/heads/*`). */
62
66
  declare function listBranches(repo: GitRepo): Promise<RefEntry[]>;
67
+ /** List all tags (`refs/tags/*`). */
63
68
  declare function listTags(repo: GitRepo): Promise<RefEntry[]>;
69
+ /** Read and parse a commit object by its hash. */
64
70
  declare function readCommit(repo: GitRepo, hash: string): Promise<Commit>;
71
+ /** Read a blob's raw bytes by its hash. */
65
72
  declare function readBlob(repo: GitRepo, hash: string): Promise<Uint8Array>;
73
+ /** Read a blob as a UTF-8 string by its hash. */
66
74
  declare function readBlobText(repo: GitRepo, hash: string): Promise<string>;
75
+ /** Recursively walk a tree object and return all file entries with their full paths. */
67
76
  declare function flattenTree(repo: GitRepo, treeHash: string): Promise<FlatTreeEntry[]>;
77
+ /** Diff two tree objects and return the list of added/deleted/modified entries. Pass null for an empty tree. */
68
78
  declare function diffTrees(repo: GitRepo, treeA: string | null, treeB: string | null): Promise<TreeDiffEntry[]>;
79
+ /** Find the merge base(s) of two commits. Returns one hash for most cases, multiple for criss-cross merges. */
69
80
  declare function findMergeBases(repo: GitRepo, commitA: string, commitB: string): Promise<string[]>;
81
+ /** Result of a tree-level merge via {@link mergeTrees} or {@link mergeTreesFromTreeHashes}. */
70
82
  interface MergeTreesResult {
83
+ /** Hash of the result tree (may contain conflict-marker blobs). */
71
84
  treeHash: string;
85
+ /** True if the merge completed without conflicts. */
72
86
  clean: boolean;
87
+ /** Details of each conflict, if any. */
73
88
  conflicts: MergeConflict[];
89
+ /** Informational messages from the merge engine. */
74
90
  messages: string[];
75
91
  }
76
92
  /**
@@ -97,8 +113,11 @@ declare function mergeTreesFromTreeHashes(repo: GitRepo, baseTree: string | null
97
113
  ours?: string;
98
114
  theirs?: string;
99
115
  }): Promise<MergeTreesResult>;
116
+ /** Options for {@link createCommit}. */
100
117
  interface CreateCommitOptions {
118
+ /** Hash of the tree object for this commit. */
101
119
  tree: string;
120
+ /** Parent commit hashes (empty for root commits). */
102
121
  parents: string[];
103
122
  author: Identity;
104
123
  committer: Identity;
@@ -119,9 +138,13 @@ interface CreateCommitOptions {
119
138
  * Without `branch`, no refs are updated.
120
139
  */
121
140
  declare function createCommit(repo: GitRepo, options: CreateCommitOptions): Promise<string>;
141
+ /** An entry to include in a tree built by {@link writeTree}. */
122
142
  interface TreeEntryInput {
143
+ /** Filename (not a path — nesting is achieved by including tree entries). */
123
144
  name: string;
145
+ /** Hash of the blob or tree object. */
124
146
  hash: string;
147
+ /** File mode (e.g. "100644"). Auto-detected from the object store when omitted. */
125
148
  mode?: string;
126
149
  }
127
150
  /**
@@ -143,6 +166,7 @@ declare function writeBlob(repo: GitRepo, content: string): Promise<string>;
143
166
  * Returns null if the file doesn't exist at that commit.
144
167
  */
145
168
  declare function readFileAtCommit(repo: GitRepo, commitHash: string, filePath: string): Promise<string | null>;
169
+ /** Result of {@link checkoutTo}. */
146
170
  interface CheckoutToResult {
147
171
  commitHash: string;
148
172
  treeHash: string;
@@ -167,7 +191,9 @@ interface CreateWorktreeOptions {
167
191
  /** Path to the `.git` directory on the VFS (default: `<workTree>/.git`). */
168
192
  gitDir?: string;
169
193
  }
194
+ /** Result of {@link createWorktree}. */
170
195
  interface WorktreeResult {
196
+ /** The fully-wired GitContext, ready for use with lib/ functions. */
171
197
  ctx: GitContext;
172
198
  commitHash: string;
173
199
  treeHash: string;
@@ -1,4 +1,4 @@
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 o of r)o===""||o==="."||(o===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(o));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function 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 o of t)n+=o.byteLength;let r=new Uint8Array(n),s=0;for(let o of t)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return 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=[...t.entries].sort(Rt),n=12;for(let l of e){let u=62+l.path.length+1;n+=Math.ceil(u/8)*8}n+=20;let r=new ArrayBuffer(n),s=new Uint8Array(r),i=new DataView(r),o=0;i.setUint32(o,Sn),o+=4,i.setUint32(o,t.version),o+=4,i.setUint32(o,e.length),o+=4;for(let l of e){let u=o;i.setUint32(o,l.stat.ctimeSeconds),i.setUint32(o+4,l.stat.ctimeNanoseconds),i.setUint32(o+8,l.stat.mtimeSeconds),i.setUint32(o+12,l.stat.mtimeNanoseconds),i.setUint32(o+16,l.stat.dev),i.setUint32(o+20,l.stat.ino),i.setUint32(o+24,l.mode),i.setUint32(o+28,l.stat.uid),i.setUint32(o+32,l.stat.gid),i.setUint32(o+36,l.stat.size),o+=40;let d=Y(l.hash);s.set(d,o),o+=20;let h=Math.min(l.path.length,4095),m=(l.stage&3)<<12|h;i.setUint16(o,m),o+=2;let y=new TextEncoder().encode(l.path);s.set(y,o),o+=y.byteLength,s[o]=0,o+=1;let g=62+y.byteLength+1,x=Math.ceil(g/8)*8;o=u+x}let a=s.subarray(0,o),c=await Te(a),f=Y(c);return s.set(f,o),s}function Rt(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}var Cn=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(!Cn.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,An=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 An(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:Ct}=jt(St,2);Ct[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 o=new fe(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;let a;if(n){a=new fe(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let f=s<<4|t[s],l=e-t[s],u=o[t[s]-1]++<<l;for(let d=u|(1<<l)-1;u<=d;++u)a[qe[u]>>c]=f}}else for(a=new fe(r),s=0;s<r;++s)t[s]&&(a[s]=qe[o[t[s]-1]++]>>15-t[s]);return a},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 At=new J(32);for(let t=0;t<32;++t)At[t]=5;var vn=ye(be,9,1),Ln=ye(At,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 o=!n,a=o||e.i!=2,c=e.i;o&&(n=new J(s*3));let f=R=>{let A=n.length;if(R>A){let j=new J(Math.max(A*2,R));j.set(n),n=j}},l=e.f||0,u=e.p||0,d=e.b||0,h=e.l,m=e.d,y=e.m,g=e.n,x=s*8;do{if(!h){l=X(t,u,1);let I=X(t,u+1,3);if(u+=3,I)if(I==1)h=vn,m=Ln,y=9,g=5;else if(I==2){let w=X(t,u,31)+257,E=X(t,u+10,15)+4,$=w+X(t,u+5,31)+1;u+=14;let S=new J($),k=new J(19);for(let p=0;p<E;++p)k[$n[p]]=X(t,u+p*3,7);u+=E*3;let M=Ve(k),B=(1<<M)-1,N=ye(k,M,1);for(let p=0;p<$;){let O=N[X(t,u,B)];u+=O&15;let C=O>>4;if(C<16)S[p++]=C;else{let T=0,P=0;for(C==16?(P=3+X(t,u,3),u+=2,T=S[p-1]):C==17?(P=3+X(t,u,7),u+=3):C==18&&(P=11+X(t,u,127),u+=7);P--;)S[p++]=T}}let ge=S.subarray(0,w),b=S.subarray(w);y=Ve(ge),g=Ve(b),h=ye(ge,y,1),m=ye(b,g,1)}else Z(1);else{let w=$t(u)+4,E=t[w-4]|t[w-3]<<8,$=w+E;if($>s){c&&Z(0);break}a&&f(d+E),n.set(t.subarray(w,$),d),e.b=d+=E,e.p=u=$*8,e.f=l;continue}if(u>x){c&&Z(0);break}}a&&f(d+131072);let R=(1<<y)-1,A=(1<<g)-1,j=u;for(;;j=u){let I=h[Ke(t,u)&R],w=I>>4;if(u+=I&15,u>x){c&&Z(0);break}if(I||Z(2),w<256)n[d++]=w;else if(w==256){j=u,h=null;break}else{let E=w-254;if(w>264){let B=w-257,N=St[B];E=X(t,u,(1<<N)-1)+Ct[B],u+=N}let $=m[Ke(t,u)&A],S=$>>4;$||Z(3),u+=$&15;let k=Mn[S];if(S>3){let B=Tt[S];k+=Ke(t,u)&(1<<B)-1,u+=B}if(u>x){c&&Z(0);break}a&&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=h,e.p=j,e.b=d,e.f=l,h&&(l=1,e.m=y,e.d=m,e.n=g)}while(!l);return d!=n.length&&o?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 o=t.inflateSync(i,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??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,Ce=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),o=[],a=12;for(let f=0;f<i;f++){let l=await zn(t,a);o.push(l),a=l.nextOffset}return(await Vn(o,e)).map((f,l)=>({...f,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function zn(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=t[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Ce){let u=t[e++];for(a=u&127;u&128;)a+=1,u=t[e++],a=(a<<7)+(u&127);a=n-a}else s===Qe&&(c=Ee(t,e),e+=20);let{result:f,bytesConsumed:l}=await Ut(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+l}}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 o=r[i];if(o)return o;let a=t[i];if(a.typeNum!==Ce&&a.typeNum!==Qe){let d=Wn[a.typeNum];if(!d)throw new Error(`Unknown object type: ${a.typeNum}`);let h={type:d,content:a.inflated,hash:await Ze(d,a.inflated)};return r[i]=h,h}if(a.typeNum===Ce){let d=n.get(a.baseOffset);if(d===void 0)throw new Error(`OFS_DELTA base not found at offset ${a.baseOffset}`);let h=await s(d),m=we(h.content,a.inflated),y={type:h.type,content:m,hash:await Ze(h.type,m)};return r[i]=y,y}let c=await Kn(t,r,a.baseHash,s),f;if(c!==void 0)f=await s(c);else if(e){let d=await e(a.baseHash);d&&(f=d)}if(!f)throw new Error(`REF_DELTA base not found for hash ${a.baseHash}`);let l=we(f.content,a.inflated),u={type:f.type,content:l,hash:await Ze(f.type,l)};return r[i]=u,u}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!==Ce&&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:o}=Dt(e,n);n=o;let a=new Uint8Array(i),c=0;for(;n<e.byteLength;){let f=e[n++];if(f&128){let l=0,u=0;f&1&&(l=e[n++]),f&2&&(l|=e[n++]<<8),f&4&&(l|=e[n++]<<16),f&8&&(l|=e[n++]<<24),f&16&&(u=e[n++]),f&32&&(u|=e[n++]<<8),f&64&&(u|=e[n++]<<16),u===0&&(u=65536),a.set(t.subarray(l,l+u),c),c+=u}else if(f>0)a.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 a}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],o=s,a=i;for(;o<a;){let c=o+a>>>1,f=this.compareAt(c,n);if(f<0)o=c+1;else if(f>0)a=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")),o=e.length,a=[];for(let c=r;c<s;c++){let f=c*20,l=!0;for(let u=0;u<o;u++){let d=u%2===0?this.hashes[f+(u>>1)]>>4&15:this.hashes[f+(u>>1)]&15,h=u%2===0?i[u>>1]>>4&15:i[u>>1]&15;if(d!==h){l=!1;break}}l&&a.push(this.hashAtSlot(c))}return a}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],o=n[s];if(i<o)return-1;if(i>o)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((h,m)=>h.hash<m.hash?-1:h.hash>m.hash?1:0),r=n.length,s=[];for(let h of n)h.offset>=2147483648&&s.push(BigInt(h.offset));let i=8+256*4+r*20+r*4+r*4+s.length*8+20+20,o=new Uint8Array(i),a=new DataView(o.buffer),c=0;a.setUint32(c,Nt),c+=4,a.setUint32(c,Ft),c+=4;let f=new Uint32Array(256);for(let h of n){let m=parseInt(h.hash.slice(0,2),16);for(let y=m;y<256;y++)f[y]++}for(let h=0;h<256;h++)a.setUint32(c,f[h]),c+=4;for(let h of n)o.set(Y(h.hash),c),c+=20;for(let h of n)a.setUint32(c,h.crc),c+=4;let l=0;for(let h of n)h.offset>=2147483648?a.setUint32(c,2147483648|l++):a.setUint32(c,h.offset),c+=4;for(let h of s)a.setBigUint64(c,h),c+=8;o.set(e,c),c+=20;let u=Se();u.update(o.subarray(0,c));let d=await u.hex();return o.set(Y(d),c),o}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,o=s&15,a=4;for(;s&128;)s=n[r++],o|=(s&127)<<a,a+=7;if(i===Xn){let l=n[r++],u=l&127;for(;l&128;)u+=1,l=n[r++],u=(u<<7)+(l&127);let d=await le(n.subarray(r)),h=await this.readAt(e-u);return{type:h.type,content:we(h.content,d)}}if(i===Jn){let l=Ee(n,r);r+=20;let u=await le(n.subarray(r)),d=this.index.lookup(l);if(d===null)throw new Error(`REF_DELTA base ${l} not found in pack`);let h=await this.readAt(d);return{type:h.type,content:we(h.content,u)}}let c=Zn[i];if(!c)throw new Error(`Unknown pack object type: ${i}`);let f=await le(n.subarray(r));if(f.byteLength!==o)throw new Error(`Pack inflate size mismatch at offset ${e}: got ${f.byteLength}, expected ${o}`);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),o=parseInt(r.slice(s+1),10),a=e.subarray(n+1);if(a.byteLength!==o)throw new Error(`Corrupt object ${t}: expected ${o} bytes, got ${a.byteLength}`);return{type:i,content:a}}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 o=L(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(o,{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),o=nr(e,i);return this.cache.set(e,o),o}await this.discover();for(let s of this.packs){if(!s.index.has(e))continue;let o=await(await this.ensureReader(s)).readObject(e);if(o)return this.cache.set(e,o),o}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 o=`pack-${i}`,a=L(this.packDir,`${o}.pack`);await this.fs.writeFile(a,e);let c=await Gt(e),f=L(this.packDir,`${o}.idx`);await this.fs.writeFile(f,c),this.loadedPackNames.add(o);let l=new re(c);return this.packs.push({name:o,index:l,reader:new xe(e,l)}),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 o=await this.fs.readdir(s);for(let a of o)a.startsWith(r)&&i.push(`${n}${a}`)}await this.discover();for(let o of this.packs)for(let a of o.index.findByPrefix(e))i.includes(a)||i.push(a);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),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}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 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 o of r)o===""||o==="."||(o===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(o));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function 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 o of t)n+=o.byteLength;let r=new Uint8Array(n),s=0;for(let o of t)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return 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=[...t.entries].sort(Rt),n=12;for(let l of e){let u=62+l.path.length+1;n+=Math.ceil(u/8)*8}n+=20;let r=new ArrayBuffer(n),s=new Uint8Array(r),i=new DataView(r),o=0;i.setUint32(o,Sn),o+=4,i.setUint32(o,t.version),o+=4,i.setUint32(o,e.length),o+=4;for(let l of e){let u=o;i.setUint32(o,l.stat.ctimeSeconds),i.setUint32(o+4,l.stat.ctimeNanoseconds),i.setUint32(o+8,l.stat.mtimeSeconds),i.setUint32(o+12,l.stat.mtimeNanoseconds),i.setUint32(o+16,l.stat.dev),i.setUint32(o+20,l.stat.ino),i.setUint32(o+24,l.mode),i.setUint32(o+28,l.stat.uid),i.setUint32(o+32,l.stat.gid),i.setUint32(o+36,l.stat.size),o+=40;let d=Y(l.hash);s.set(d,o),o+=20;let h=Math.min(l.path.length,4095),m=(l.stage&3)<<12|h;i.setUint16(o,m),o+=2;let y=new TextEncoder().encode(l.path);s.set(y,o),o+=y.byteLength,s[o]=0,o+=1;let p=62+y.byteLength+1,x=Math.ceil(p/8)*8;o=u+x}let a=s.subarray(0,o),c=await Te(a),f=Y(c);return s.set(f,o),s}function Rt(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}var Cn=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(!Cn.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,An=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 An(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:Ct}=jt(St,2);Ct[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 o=new fe(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;let a;if(n){a=new fe(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let f=s<<4|t[s],l=e-t[s],u=o[t[s]-1]++<<l;for(let d=u|(1<<l)-1;u<=d;++u)a[qe[u]>>c]=f}}else for(a=new fe(r),s=0;s<r;++s)t[s]&&(a[s]=qe[o[t[s]-1]++]>>15-t[s]);return a},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 At=new J(32);for(let t=0;t<32;++t)At[t]=5;var vn=ye(be,9,1),Ln=ye(At,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 o=!n,a=o||e.i!=2,c=e.i;o&&(n=new J(s*3));let f=R=>{let A=n.length;if(R>A){let j=new J(Math.max(A*2,R));j.set(n),n=j}},l=e.f||0,u=e.p||0,d=e.b||0,h=e.l,m=e.d,y=e.m,p=e.n,x=s*8;do{if(!h){l=X(t,u,1);let I=X(t,u+1,3);if(u+=3,I)if(I==1)h=vn,m=Ln,y=9,p=5;else if(I==2){let w=X(t,u,31)+257,E=X(t,u+10,15)+4,$=w+X(t,u+5,31)+1;u+=14;let S=new J($),k=new J(19);for(let g=0;g<E;++g)k[$n[g]]=X(t,u+g*3,7);u+=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,u,B)];u+=O&15;let C=O>>4;if(C<16)S[g++]=C;else{let T=0,P=0;for(C==16?(P=3+X(t,u,3),u+=2,T=S[g-1]):C==17?(P=3+X(t,u,7),u+=3):C==18&&(P=11+X(t,u,127),u+=7);P--;)S[g++]=T}}let ge=S.subarray(0,w),b=S.subarray(w);y=Ve(ge),p=Ve(b),h=ye(ge,y,1),m=ye(b,p,1)}else Z(1);else{let w=$t(u)+4,E=t[w-4]|t[w-3]<<8,$=w+E;if($>s){c&&Z(0);break}a&&f(d+E),n.set(t.subarray(w,$),d),e.b=d+=E,e.p=u=$*8,e.f=l;continue}if(u>x){c&&Z(0);break}}a&&f(d+131072);let R=(1<<y)-1,A=(1<<p)-1,j=u;for(;;j=u){let I=h[Ke(t,u)&R],w=I>>4;if(u+=I&15,u>x){c&&Z(0);break}if(I||Z(2),w<256)n[d++]=w;else if(w==256){j=u,h=null;break}else{let E=w-254;if(w>264){let B=w-257,N=St[B];E=X(t,u,(1<<N)-1)+Ct[B],u+=N}let $=m[Ke(t,u)&A],S=$>>4;$||Z(3),u+=$&15;let k=Mn[S];if(S>3){let B=Tt[S];k+=Ke(t,u)&(1<<B)-1,u+=B}if(u>x){c&&Z(0);break}a&&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=h,e.p=j,e.b=d,e.f=l,h&&(l=1,e.m=y,e.d=m,e.n=p)}while(!l);return d!=n.length&&o?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 o=t.inflateSync(i,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??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,Ce=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),o=[],a=12;for(let f=0;f<i;f++){let l=await zn(t,a);o.push(l),a=l.nextOffset}return(await Vn(o,e)).map((f,l)=>({...f,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function zn(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=t[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Ce){let u=t[e++];for(a=u&127;u&128;)a+=1,u=t[e++],a=(a<<7)+(u&127);a=n-a}else s===Qe&&(c=Ee(t,e),e+=20);let{result:f,bytesConsumed:l}=await Ut(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+l}}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 o=r[i];if(o)return o;let a=t[i];if(a.typeNum!==Ce&&a.typeNum!==Qe){let d=Wn[a.typeNum];if(!d)throw new Error(`Unknown object type: ${a.typeNum}`);let h={type:d,content:a.inflated,hash:await Ze(d,a.inflated)};return r[i]=h,h}if(a.typeNum===Ce){let d=n.get(a.baseOffset);if(d===void 0)throw new Error(`OFS_DELTA base not found at offset ${a.baseOffset}`);let h=await s(d),m=we(h.content,a.inflated),y={type:h.type,content:m,hash:await Ze(h.type,m)};return r[i]=y,y}let c=await Kn(t,r,a.baseHash,s),f;if(c!==void 0)f=await s(c);else if(e){let d=await e(a.baseHash);d&&(f=d)}if(!f)throw new Error(`REF_DELTA base not found for hash ${a.baseHash}`);let l=we(f.content,a.inflated),u={type:f.type,content:l,hash:await Ze(f.type,l)};return r[i]=u,u}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!==Ce&&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:o}=Dt(e,n);n=o;let a=new Uint8Array(i),c=0;for(;n<e.byteLength;){let f=e[n++];if(f&128){let l=0,u=0;f&1&&(l=e[n++]),f&2&&(l|=e[n++]<<8),f&4&&(l|=e[n++]<<16),f&8&&(l|=e[n++]<<24),f&16&&(u=e[n++]),f&32&&(u|=e[n++]<<8),f&64&&(u|=e[n++]<<16),u===0&&(u=65536),a.set(t.subarray(l,l+u),c),c+=u}else if(f>0)a.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 a}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],o=s,a=i;for(;o<a;){let c=o+a>>>1,f=this.compareAt(c,n);if(f<0)o=c+1;else if(f>0)a=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")),o=e.length,a=[];for(let c=r;c<s;c++){let f=c*20,l=!0;for(let u=0;u<o;u++){let d=u%2===0?this.hashes[f+(u>>1)]>>4&15:this.hashes[f+(u>>1)]&15,h=u%2===0?i[u>>1]>>4&15:i[u>>1]&15;if(d!==h){l=!1;break}}l&&a.push(this.hashAtSlot(c))}return a}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],o=n[s];if(i<o)return-1;if(i>o)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((h,m)=>h.hash<m.hash?-1:h.hash>m.hash?1:0),r=n.length,s=[];for(let h of n)h.offset>=2147483648&&s.push(BigInt(h.offset));let i=8+256*4+r*20+r*4+r*4+s.length*8+20+20,o=new Uint8Array(i),a=new DataView(o.buffer),c=0;a.setUint32(c,Nt),c+=4,a.setUint32(c,Ft),c+=4;let f=new Uint32Array(256);for(let h of n){let m=parseInt(h.hash.slice(0,2),16);for(let y=m;y<256;y++)f[y]++}for(let h=0;h<256;h++)a.setUint32(c,f[h]),c+=4;for(let h of n)o.set(Y(h.hash),c),c+=20;for(let h of n)a.setUint32(c,h.crc),c+=4;let l=0;for(let h of n)h.offset>=2147483648?a.setUint32(c,2147483648|l++):a.setUint32(c,h.offset),c+=4;for(let h of s)a.setBigUint64(c,h),c+=8;o.set(e,c),c+=20;let u=Se();u.update(o.subarray(0,c));let d=await u.hex();return o.set(Y(d),c),o}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,o=s&15,a=4;for(;s&128;)s=n[r++],o|=(s&127)<<a,a+=7;if(i===Xn){let l=n[r++],u=l&127;for(;l&128;)u+=1,l=n[r++],u=(u<<7)+(l&127);let d=await le(n.subarray(r)),h=await this.readAt(e-u);return{type:h.type,content:we(h.content,d)}}if(i===Jn){let l=Ee(n,r);r+=20;let u=await le(n.subarray(r)),d=this.index.lookup(l);if(d===null)throw new Error(`REF_DELTA base ${l} not found in pack`);let h=await this.readAt(d);return{type:h.type,content:we(h.content,u)}}let c=Zn[i];if(!c)throw new Error(`Unknown pack object type: ${i}`);let f=await le(n.subarray(r));if(f.byteLength!==o)throw new Error(`Pack inflate size mismatch at offset ${e}: got ${f.byteLength}, expected ${o}`);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),o=parseInt(r.slice(s+1),10),a=e.subarray(n+1);if(a.byteLength!==o)throw new Error(`Corrupt object ${t}: expected ${o} bytes, got ${a.byteLength}`);return{type:i,content:a}}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 o=L(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(o,{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),o=nr(e,i);return this.cache.set(e,o),o}await this.discover();for(let s of this.packs){if(!s.index.has(e))continue;let o=await(await this.ensureReader(s)).readObject(e);if(o)return this.cache.set(e,o),o}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 o=`pack-${i}`,a=L(this.packDir,`${o}.pack`);await this.fs.writeFile(a,e);let c=await Gt(e),f=L(this.packDir,`${o}.idx`);await this.fs.writeFile(f,c),this.loadedPackNames.add(o);let l=new re(c);return this.packs.push({name:o,index:l,reader:new xe(e,l)}),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 o=await this.fs.readdir(s);for(let a of o)a.startsWith(r)&&i.push(`${n}${a}`)}await this.discover();for(let o of this.packs)for(let a of o.index.findByPrefix(e))i.includes(a)||i.push(a);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),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}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(`
2
2
 
3
3
  `),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",o=[],a,c;for(let f of r.split(`
4
4
  `)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),d=f.slice(l+1);switch(u){case"tree":i=d;break;case"parent":o.push(d);break;case"author":a=nt(d);break;case"committer":c=nt(d);break}}if(!i)throw new Error("Commit missing tree field");if(!a)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:o,author:a,committer:c,message:s}}function Ae(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${rt(t.author)}`),e.push(`committer ${rt(t.committer)}`),e.push(""),e.push(t.message),rr.encode(e.join(`
@@ -8,11 +8,11 @@ var ke=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(
8
8
  `)){if(!s||s.startsWith("#")||s.startsWith("^"))continue;let i=s.indexOf(" ");if(i===-1)continue;let o=s.slice(0,i),a=s.slice(i+1).trim();o.length===40&&a&&r.set(a,o)}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(`
9
9
  `),i=[],o=!1;for(let c of s){if(o&&c.startsWith("^")){o=!1;continue}if(o=!1,!c||c.startsWith("#")){i.push(c);continue}let f=c.indexOf(" ");if(f!==-1&&c.slice(f+1).trim()===e){o=!0;continue}i.push(c)}i.some(c=>c&&!c.startsWith("#")&&!c.startsWith("^"))?await this.fs.writeFile(n,i.join(`
10
10
  `)):await this.fs.rm(n)}async walkRefs(e,n,r){let s=await this.fs.readdir(e);for(let i of s){let o=L(e,i),a=`${n}/${i}`,c=await this.fs.stat(o);if(c.isDirectory)await this.walkRefs(o,a,r);else if(c.isFile){let f=await this.resolveRefInternal(a);f&&r.push({name:a,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 o=Kt.decode(t.subarray(r+1,i)),a=t.subarray(i+1,i+21),c=oe(a),f=s.padStart(6,"0");e.push({mode:f,name:o,hash:c}),n=i+21}return{type:"tree",entries:e}}function Me(t){let e=[];for(let i of t.entries){let o=i.mode.replace(/^0+/,""),a=ar.encode(`${o} ${i.name}\0`),c=Y(i.hash);e.push(a),e.push(c)}let n=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}async function at(t,e){return Yt(t,e,"")}async function Yt(t,e,n){let r=[],s=new Map;for(let o of e){let a=n?o.path.slice(n.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:cr(o.mode),name:a,hash:o.hash});else{let f=a.slice(0,c),l=s.get(f);l||(l=[],s.set(f,l)),l.push(o)}}for(let[o,a]of s){let c=n?`${n}/${o}`:o,f=await Yt(t,a,c);r.push({mode:Ie.DIRECTORY,name:o,hash:f})}r.sort((o,a)=>{let c=o.mode===Ie.DIRECTORY?`${o.name}/`:o.name,f=a.mode===Ie.DIRECTORY?`${a.name}/`:a.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 o of s.entries){let a=n?`${n}/${o.name}`:o.name;if(o.mode===Ie.DIRECTORY){let c=await ae(t,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.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[o,a]of r){let c=s.get(o);c?(a.hash!==c.hash||a.mode!==c.mode)&&i.push({path:o,status:"modified",oldHash:a.hash,newHash:c.hash,oldMode:a.mode,newMode:c.mode}):i.push({path:o,status:"deleted",oldHash:a.hash,oldMode:a.mode})}for(let[o,a]of s)r.has(o)||i.push({path:o,status:"added",newHash:a.hash,newMode:a.mode});return i.sort((o,a)=>Oe(o.path,a.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,o=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),o<r&&this.higher(n[o],n[s])&&(s=o),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*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,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let c of a)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,!o?.has(c.hash))){for(let f of c.commit.parents)if(!s.has(f))try{i.push(await Le(t,f))}catch{}}}}async function*fr(t,e,n){let r=await Jt(t,n?.exclude),s=new Set(r),i=new ve,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let h of a)s.has(h)||i.push(await Le(t,h));let c=[],f=new Map;for(;i.size>0;){let h=i.pop();if(!s.has(h.hash)&&(s.add(h.hash),f.set(h.hash,c.length),c.push(h),!o?.has(h.hash))){for(let m of h.commit.parents)if(!s.has(m))try{i.push(await Le(t,m))}catch{}}}let l=c.length;if(l===0)return;let u=new Int32Array(l);for(let h of c)for(let m of h.commit.parents){let y=f.get(m);y!==void 0&&(u[y]=(u[y]??0)+1)}let d=[];for(let h=l-1;h>=0;h--)u[h]===0&&d.push(h);for(;d.length>0;){let h=d.pop();yield c[h];for(let m of c[h].commit.parents){let y=f.get(m);if(y!==void 0){let g=(u[y]??0)-1;u[y]=g,g===0&&d.push(y)}}}}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 o=0;o<t.length;o++){let a=t[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len1++,s[o]=c}for(let o=0;o<e.length;o++){let a=e[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function hr(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&t[e-1-a]===n[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function 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 o=0,a=1;for(let c=1;e+c<=r;c++){let f=t[e+c];if(f===He)o++;else if(f===he)a++;else break}return o===0?!1:(o+=s,a+=i,a*lr<a+o)}function dr(t,e,n,r,s,i,o,a,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(ut(e),Zt);for(let g=i;g<=o;g++){let x=s[t[g]].len2;x===0?l[g]=He:x>=d?l[g]=he:l[g]=Be}let h=Math.min(ut(r),Zt);for(let g=i;g<=a;g++){let x=s[n[g]].len1;x===0?u[g]=He:x>=h?u[g]=he:u[g]=Be}let m=[];for(let g=i;g<=o;g++)l[g]===Be||l[g]===he&&!Qt(l,g,i,o)?m.push(g):c[g]=1;let y=[];for(let g=i;g<=a;g++)u[g]===Be||u[g]===he&&!Qt(u,g,i,a)?y.push(g):f[g]=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,o,a,c,f){let l=e-i,u=n-s,d=e-s,h=n-i,m=d-h&1,y=d,g=d,x=h,R=h;o[d]=e,a[h]=n;for(let A=1;;A++){let j=!1;y>l?o[--y-1]=-1:++y,g<u?o[++g+1]=-1:--g;for(let I=g;I>=y;I-=2){let w;W(o,I-1)>=W(o,I+1)?w=W(o,I-1)+1:w=W(o,I+1);let E=w,$=w-I;for(;w<n&&$<i&&t[w]===r[$];)w++,$++;if(w-E>se&&(j=!0),o[I]=w,m&&x<=I&&I<=R&&W(a,I)<=w)return{i1:w,i2:$,minLo:!0,minHi:!0}}x>l?a[--x-1]=De:++x,R<u?a[++R+1]=De:--R;for(let I=R;I>=x;I-=2){let w;W(a,I-1)<W(a,I+1)?w=W(a,I-1):w=W(a,I+1)-1;let E=w,$=w-I;for(;w>e&&$>s&&t[w-1]===r[$-1];)w--,$--;if(E-w>se&&(j=!0),a[I]=w,!m&&y<=I&&I<=g&&w<=W(o,I))return{i1:w,i2:$,minLo:!0,minHi:!0}}if(!c){if(j&&A>mr){let I=0,w=null;for(let E=g;E>=y;E-=2){let $=E>d?E-d:d-E,S=W(o,E),k=S-E,M=S-e+(k-s)-$;if(M>en*A&&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>h?E-h:h-E,S=W(a,E),k=S-E,M=n-S+(i-k)-$;if(M>en*A&&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(A>=f){let I=-1,w=-1;for(let S=g;S>=y;S-=2){let k=Math.min(W(o,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(a,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,o,a,c,f,l,u,d,h){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let m=s;m<i;m++)a[f[m]]=1;else if(s===i)for(let m=e;m<n;m++)o[c[m]]=1;else{let m=gr(t,e,n,r,s,i,l,u,d,h);ht(t,e,m.i1,r,s,m.i2,o,a,c,f,l,u,m.minLo,h),ht(t,m.i1,n,r,m.i2,i,o,a,c,f,l,u,m.minHi,h)}}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 o=0,a=0;for(;t[a];)a++;let c=0,f=0;for(;s[f];)f++;let l=(u,d)=>e[u]===e[d];for(;;){if(a!==o){let u,d,h;do{for(u=a-o,d=-1;o>0&&l(o-1,a-1);){for(t[--o]=1,t[--a]=0;t[o-1];)o--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(h=a,f>c&&(d=a);!(a>=r||!l(o,a));){for(t[o++]=0,t[a++]=1;t[a];)a++;if(f>=i)break;for(c=f+1,f=c;s[f];f++);f>c&&(d=a)}}while(u!==a-o);if(a!==h)if(d!==-1)for(;f===c;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,y={effectiveIndent:0,penalty:0},g=h;for(a-u-1>g&&(g=a-u-1),a-rn>g&&(g=a-rn);g<=a;g++){let x={effectiveIndent:0,penalty:0},R=sn(n,r,g);on(R,x);let A=sn(n,r,g-u);on(A,x),(m===-1||Tr(x,y)<=0)&&(y={effectiveIndent:x.effectiveIndent,penalty:x.penalty},m=g)}for(;a>m;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;t[a];a++);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:o,classes2:a,classInfo:c}=ur(t,e),{dstart:f,dend1:l,dend2:u}=hr(o,n,a,r);if(f>l)for(let d=f;d<r-(n-1-l);d++)i[d]=1;else if(f>u)for(let d=f;d<n-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:y}=dr(o,n,a,r,c,f,l,u,s,i);if(h>0&&y>0){let g=new Array(h);for(let w=0;w<h;w++)g[w]=o[d[w]];let x=new Array(y);for(let w=0;w<y;w++)x[w]=a[m[w]];let R={},A={},j=h+y+3,I=Math.max(pr,ut(j));ht(g,0,h,x,0,y,s,i,d,m,R,A,!1,I)}else if(h===0)for(let g=0;g<y;g++)i[m[g]]=1;else for(let g=0;g<h;g++)s[d[g]]=1;an(s,o,t,n,i,r),an(i,a,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 Cr=50;async function dt(t,e,n=Cr){let r=new Map,s=[],i=[],o=[];for(let l of e)if(l.status==="deleted"&&l.oldHash){let u=r.get(l.oldHash)??[];u.push(l),r.set(l.oldHash,u),s.push(l)}else l.status==="added"&&l.newHash?i.push(l):o.push(l);let a=[],c=[];for(let l of i){let u=l.newHash;if(!u){c.push(l);continue}let d=r.get(u);if(d&&d.length>0){let h=jr(d,l.path);h&&a.push({oldPath:h.path,newPath:l.path,oldHash:h.oldHash??u,newHash:u,similarity:100,oldMode:h.oldMode,newMode:l.newMode})}else c.push(l)}let f=[...r.values()].flat();if(f.length>0&&c.length>0){let l=await Ar(t,f,c,n);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}if(f.length>0&&c.length>0){let l=await vr(t,f,c,n);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}return{remaining:[...o,...f,...c],renames:a}}async function Ar(t,e,n,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let f=de(c.path);s.has(f)?s.set(f,-1):s.set(f,a)}let i=new Map;for(let a=0;a<n.length;a++){let c=n[a];if(!c)continue;let f=de(c.path);i.has(f)?i.set(f,-1):i.set(f,a)}let o=[];for(let[a,c]of s){if(c===-1)continue;let f=i.get(a);if(f===void 0||f===-1)continue;let l=e[c],u=n[f];if(!l?.oldHash||!u?.newHash||l.oldHash===u.newHash)continue;let d=await te(t,l.oldHash),h=await te(t,u.newHash),m=Mr(d,h);m<r||o.push({oldPath:l.path,newPath:u.path,oldHash:l.oldHash,newHash:u.newHash,similarity:m,oldMode:l.oldMode,newMode:u.newMode})}return o}var fn=107927;function Ne(t){let e=new Map,n=0,r=0,s=0;for(let o=0;o<t.length;o++){let a=t[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let 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 o=(r+Math.imul(s,97))%fn;e.set(o,(e.get(o)??0)+n)}let i=[];for(let[o,a]of e)i.push({hash:o,count:a});return i.sort((o,a)=>o.hash-a.hash),i}function $r(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let o=t[s];if(!o)break;for(;i<e.length;){let f=e[i];if(!f||f.hash>=o.hash)break;r+=f.count,i++}let a=o.count,c=0;if(i<e.length){let f=e[i];f&&f.hash===o.hash&&(c=f.count,i++)}a<c?(r+=c-a,n+=a):n+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:n,literalAdded:r}}function 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:o}=$r(e,r);return Math.floor(o*100/s)}async function vr(t,e,n,r){let s=[];for(let l of e)if(l.oldHash){let u=await te(t,l.oldHash);s.push({size:u.length,chunks:Ne(u)})}else s.push(null);let i=[];for(let l of n)if(l.newHash){let u=await te(t,l.newHash);i.push({size:u.length,chunks:Ne(u)})}else i.push(null);let o=[];for(let l=0;l<e.length;l++){let u=e[l],d=s[l];if(!(!u||!d))for(let h=0;h<n.length;h++){let m=n[h],y=i[h];if(!m||!y)continue;let g=ln(d.size,d.chunks,y.size,y.chunks);if(g>=r){let x=de(u.path)===de(m.path)?1:0;o.push({similarity:g,nameScore:x,delIdx:l,addIdx:h})}}}o.sort((l,u)=>u.similarity-l.similarity||u.nameScore-l.nameScore);let a=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:u,addIdx:d}of o){if(a.has(u)||c.has(d))continue;a.add(u),c.add(d);let h=e[u],m=n[d];!h||!m||f.push({oldPath:h.path,newPath:m.path,oldHash:h.oldHash??"",newHash:m.newHash??"",similarity:l,oldMode:h.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 o;try{o=await U(t,i)}catch{continue}for(let a of o.parents)n.has(a)||r.push(a)}return n}async function mt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let o=s[i++];if(o===e)return!0;if(r.has(o))continue;r.add(o);let a;try{a=await U(t,o)}catch{continue}for(let c of a.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,o=[n],a=0;for(;a<o.length;){let f=o[a++];if(i.has(f))continue;if(i.add(f),r.has(f)){s.push(f);continue}let l;try{l=await U(t,f)}catch{continue}for(let u of l.parents)i.has(u)||o.push(u)}if(s.length<=1)return s;let c=[];for(let f of s){let l=!1;for(let u of s)if(u!==f&&await mt(t,f,u)){l=!0;break}l||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,o=[],a=new Map,c=new Map,f=0,l=[{hash:e,mask:1,seq:f++},{hash:n,mask:2,seq:f++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await U(t,d)).committer.timestamp;return c.set(d,m),m}for(;l.length>0;){let d=0,h=await u(l[0].hash);for(let R=1;R<l.length;R++){let A=l[R],j=await u(A.hash),I=l[d];(j>h||j===h&&A.seq<I.seq)&&(d=R,h=j)}let m=l.splice(d,1)[0],y=a.get(m.hash)??0,g=y|m.mask;if(g===y)continue;if(a.set(m.hash,g),g===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.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)l.push({hash:R,mask:g,seq:f++})}for(let d of r)i.has(d)||o.push(d);return o}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,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!t[i]&&!n[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&t[i];)i++;for(;o<r&&n[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function 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 o(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let a=0;for(;a<r.length;){let c=r[a++],f=c.oStart,l=c.oStart+c.oLength,u=[c];for(o(f);a<r.length;){let d=r[a];if(d.oStart>l)break;l=Math.max(l,d.oStart+d.oLength),u.push(d),a++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?t:n;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:d.slice(c.abStart,c.abStart+c.abLength)})}}else{let d={a:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let x of u){let R=x.oStart,A=R+x.oLength,j=x.abStart,I=j+x.abLength,w=d[x.ab];w.abMin=Math.min(j,w.abMin),w.abMax=Math.max(I,w.abMax),w.oMin=Math.min(R,w.oMin),w.oMax=Math.max(A,w.oMax)}let h=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(l-d.a.oMax),y=d.b.abMin+(f-d.b.oMin),g=d.b.abMax+(l-d.b.oMax);s.push({stable:!1,a:t.slice(h,m),o:e.slice(f,l),b:n.slice(y,g)})}i=l}return o(e.length),s}function Hr(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=Dr(t,e,n),o=[],a=[];function c(){a.length&&(o.push({type:"ok",lines:a}),a=[])}for(let f of i)f.stable?a.push(...f.content):s&&hn(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?un(o):un(Nr(o))}function Re(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",o=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),f=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,l=Hr(t,e,n,{conflictStyle:i}),u=!1,d=[];for(let h of l)h.type==="ok"?d.push(...h.lines):(u=!0,i==="diff3"?d.push(o,...h.a,a,...h.o,c,...h.b,f):d.push(o,...h.a,c,...h.b,f));return{conflict:u,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 a of r){let c=a.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let l=c+a.buffer1[1],u=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:e.slice(c,l),o:[],b:n.slice(a.buffer2[0],u)}),i=l}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[t]:s}function 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 o=e[r+1],a=s;a.a=[...s.a,...i.lines,...o.a],a.b=[...s.b,...i.lines,...o.b],a.o=[...s.o,...i.lines,...o.o],r++}else n.push(i)}return n}function 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}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(gt);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
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,o=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),o<r&&this.higher(n[o],n[s])&&(s=o),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*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,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let c of a)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,o?.has(c.hash)))continue;let f=n?.firstParent?c.commit.parents.slice(0,1):c.commit.parents;for(let l of f)if(!s.has(l))try{i.push(await Le(t,l))}catch{}}}async function*fr(t,e,n){let r=await Jt(t,n?.exclude),s=new Set(r),i=new ve,o=n?.shallowBoundary,a=Array.isArray(e)?e:[e];for(let h of a)s.has(h)||i.push(await Le(t,h));let c=[],f=new Map;for(;i.size>0;){let h=i.pop();if(s.has(h.hash)||(s.add(h.hash),f.set(h.hash,c.length),c.push(h),o?.has(h.hash)))continue;let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let y of m)if(!s.has(y))try{i.push(await Le(t,y))}catch{}}let l=c.length;if(l===0)return;let u=new Int32Array(l);for(let h of c){let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let y of m){let p=f.get(y);p!==void 0&&(u[p]=(u[p]??0)+1)}}let d=[];for(let h=l-1;h>=0;h--)u[h]===0&&d.push(h);for(;d.length>0;){let h=d.pop();yield c[h];let m=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let y of m){let p=f.get(y);if(p!==void 0){let x=(u[p]??0)-1;u[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 o=0;o<t.length;o++){let a=t[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len1++,s[o]=c}for(let o=0;o<e.length;o++){let a=e[o],c=n.get(a);c===void 0&&(c=r.length,n.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function hr(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&t[e-1-a]===n[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function 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 o=0,a=1;for(let c=1;e+c<=r;c++){let f=t[e+c];if(f===He)o++;else if(f===he)a++;else break}return o===0?!1:(o+=s,a+=i,a*lr<a+o)}function dr(t,e,n,r,s,i,o,a,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(ut(e),Zt);for(let p=i;p<=o;p++){let x=s[t[p]].len2;x===0?l[p]=He:x>=d?l[p]=he:l[p]=Be}let h=Math.min(ut(r),Zt);for(let p=i;p<=a;p++){let x=s[n[p]].len1;x===0?u[p]=He:x>=h?u[p]=he:u[p]=Be}let m=[];for(let p=i;p<=o;p++)l[p]===Be||l[p]===he&&!Qt(l,p,i,o)?m.push(p):c[p]=1;let y=[];for(let p=i;p<=a;p++)u[p]===Be||u[p]===he&&!Qt(u,p,i,a)?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,o,a,c,f){let l=e-i,u=n-s,d=e-s,h=n-i,m=d-h&1,y=d,p=d,x=h,R=h;o[d]=e,a[h]=n;for(let A=1;;A++){let j=!1;y>l?o[--y-1]=-1:++y,p<u?o[++p+1]=-1:--p;for(let I=p;I>=y;I-=2){let w;W(o,I-1)>=W(o,I+1)?w=W(o,I-1)+1:w=W(o,I+1);let E=w,$=w-I;for(;w<n&&$<i&&t[w]===r[$];)w++,$++;if(w-E>se&&(j=!0),o[I]=w,m&&x<=I&&I<=R&&W(a,I)<=w)return{i1:w,i2:$,minLo:!0,minHi:!0}}x>l?a[--x-1]=De:++x,R<u?a[++R+1]=De:--R;for(let I=R;I>=x;I-=2){let w;W(a,I-1)<W(a,I+1)?w=W(a,I-1):w=W(a,I+1)-1;let E=w,$=w-I;for(;w>e&&$>s&&t[w-1]===r[$-1];)w--,$--;if(E-w>se&&(j=!0),a[I]=w,!m&&y<=I&&I<=p&&w<=W(o,I))return{i1:w,i2:$,minLo:!0,minHi:!0}}if(!c){if(j&&A>mr){let I=0,w=null;for(let E=p;E>=y;E-=2){let $=E>d?E-d:d-E,S=W(o,E),k=S-E,M=S-e+(k-s)-$;if(M>en*A&&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>h?E-h:h-E,S=W(a,E),k=S-E,M=n-S+(i-k)-$;if(M>en*A&&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(A>=f){let I=-1,w=-1;for(let S=p;S>=y;S-=2){let k=Math.min(W(o,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(a,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,o,a,c,f,l,u,d,h){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let m=s;m<i;m++)a[f[m]]=1;else if(s===i)for(let m=e;m<n;m++)o[c[m]]=1;else{let m=gr(t,e,n,r,s,i,l,u,d,h);ht(t,e,m.i1,r,s,m.i2,o,a,c,f,l,u,m.minLo,h),ht(t,m.i1,n,r,m.i2,i,o,a,c,f,l,u,m.minHi,h)}}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 o=0,a=0;for(;t[a];)a++;let c=0,f=0;for(;s[f];)f++;let l=(u,d)=>e[u]===e[d];for(;;){if(a!==o){let u,d,h;do{for(u=a-o,d=-1;o>0&&l(o-1,a-1);){for(t[--o]=1,t[--a]=0;t[o-1];)o--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(h=a,f>c&&(d=a);!(a>=r||!l(o,a));){for(t[o++]=0,t[a++]=1;t[a];)a++;if(f>=i)break;for(c=f+1,f=c;s[f];f++);f>c&&(d=a)}}while(u!==a-o);if(a!==h)if(d!==-1)for(;f===c;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,y={effectiveIndent:0,penalty:0},p=h;for(a-u-1>p&&(p=a-u-1),a-rn>p&&(p=a-rn);p<=a;p++){let x={effectiveIndent:0,penalty:0},R=sn(n,r,p);on(R,x);let A=sn(n,r,p-u);on(A,x),(m===-1||Tr(x,y)<=0)&&(y={effectiveIndent:x.effectiveIndent,penalty:x.penalty},m=p)}for(;a>m;){for(t[--a]=0,t[--o]=1;t[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;t[a];a++);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:o,classes2:a,classInfo:c}=ur(t,e),{dstart:f,dend1:l,dend2:u}=hr(o,n,a,r);if(f>l)for(let d=f;d<r-(n-1-l);d++)i[d]=1;else if(f>u)for(let d=f;d<n-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:y}=dr(o,n,a,r,c,f,l,u,s,i);if(h>0&&y>0){let p=new Array(h);for(let w=0;w<h;w++)p[w]=o[d[w]];let x=new Array(y);for(let w=0;w<y;w++)x[w]=a[m[w]];let R={},A={},j=h+y+3,I=Math.max(pr,ut(j));ht(p,0,h,x,0,y,s,i,d,m,R,A,!1,I)}else if(h===0)for(let p=0;p<y;p++)i[m[p]]=1;else for(let p=0;p<h;p++)s[d[p]]=1;an(s,o,t,n,i,r),an(i,a,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 Cr=50;async function dt(t,e,n=Cr){let r=new Map,s=[],i=[],o=[];for(let l of e)if(l.status==="deleted"&&l.oldHash){let u=r.get(l.oldHash)??[];u.push(l),r.set(l.oldHash,u),s.push(l)}else l.status==="added"&&l.newHash?i.push(l):o.push(l);let a=[],c=[];for(let l of i){let u=l.newHash;if(!u){c.push(l);continue}let d=r.get(u);if(d&&d.length>0){let h=jr(d,l.path);h&&a.push({oldPath:h.path,newPath:l.path,oldHash:h.oldHash??u,newHash:u,similarity:100,oldMode:h.oldMode,newMode:l.newMode})}else c.push(l)}let f=[...r.values()].flat();if(f.length>0&&c.length>0){let l=await Ar(t,f,c,n);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}if(f.length>0&&c.length>0){let l=await vr(t,f,c,n);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}return{remaining:[...o,...f,...c],renames:a}}async function Ar(t,e,n,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let f=de(c.path);s.has(f)?s.set(f,-1):s.set(f,a)}let i=new Map;for(let a=0;a<n.length;a++){let c=n[a];if(!c)continue;let f=de(c.path);i.has(f)?i.set(f,-1):i.set(f,a)}let o=[];for(let[a,c]of s){if(c===-1)continue;let f=i.get(a);if(f===void 0||f===-1)continue;let l=e[c],u=n[f];if(!l?.oldHash||!u?.newHash||l.oldHash===u.newHash)continue;let d=await te(t,l.oldHash),h=await te(t,u.newHash),m=Mr(d,h);m<r||o.push({oldPath:l.path,newPath:u.path,oldHash:l.oldHash,newHash:u.newHash,similarity:m,oldMode:l.oldMode,newMode:u.newMode})}return o}var fn=107927;function Ne(t){let e=new Map,n=0,r=0,s=0;for(let o=0;o<t.length;o++){let a=t[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let 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 o=(r+Math.imul(s,97))%fn;e.set(o,(e.get(o)??0)+n)}let i=[];for(let[o,a]of e)i.push({hash:o,count:a});return i.sort((o,a)=>o.hash-a.hash),i}function $r(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let o=t[s];if(!o)break;for(;i<e.length;){let f=e[i];if(!f||f.hash>=o.hash)break;r+=f.count,i++}let a=o.count,c=0;if(i<e.length){let f=e[i];f&&f.hash===o.hash&&(c=f.count,i++)}a<c?(r+=c-a,n+=a):n+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:n,literalAdded:r}}function 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:o}=$r(e,r);return Math.floor(o*100/s)}async function vr(t,e,n,r){let s=[];for(let l of e)if(l.oldHash){let u=await te(t,l.oldHash);s.push({size:u.length,chunks:Ne(u)})}else s.push(null);let i=[];for(let l of n)if(l.newHash){let u=await te(t,l.newHash);i.push({size:u.length,chunks:Ne(u)})}else i.push(null);let o=[];for(let l=0;l<e.length;l++){let u=e[l],d=s[l];if(!(!u||!d))for(let h=0;h<n.length;h++){let m=n[h],y=i[h];if(!m||!y)continue;let p=ln(d.size,d.chunks,y.size,y.chunks);if(p>=r){let x=de(u.path)===de(m.path)?1:0;o.push({similarity:p,nameScore:x,delIdx:l,addIdx:h})}}}o.sort((l,u)=>u.similarity-l.similarity||u.nameScore-l.nameScore);let a=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:u,addIdx:d}of o){if(a.has(u)||c.has(d))continue;a.add(u),c.add(d);let h=e[u],m=n[d];!h||!m||f.push({oldPath:h.path,newPath:m.path,oldHash:h.oldHash??"",newHash:m.newHash??"",similarity:l,oldMode:h.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 o;try{o=await U(t,i)}catch{continue}for(let a of o.parents)n.has(a)||r.push(a)}return n}async function mt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let o=s[i++];if(o===e)return!0;if(r.has(o))continue;r.add(o);let a;try{a=await U(t,o)}catch{continue}for(let c of a.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,o=[n],a=0;for(;a<o.length;){let f=o[a++];if(i.has(f))continue;if(i.add(f),r.has(f)){s.push(f);continue}let l;try{l=await U(t,f)}catch{continue}for(let u of l.parents)i.has(u)||o.push(u)}if(s.length<=1)return s;let c=[];for(let f of s){let l=!1;for(let u of s)if(u!==f&&await mt(t,f,u)){l=!0;break}l||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,o=[],a=new Map,c=new Map,f=0,l=[{hash:e,mask:1,seq:f++},{hash:n,mask:2,seq:f++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await U(t,d)).committer.timestamp;return c.set(d,m),m}for(;l.length>0;){let d=0,h=await u(l[0].hash);for(let R=1;R<l.length;R++){let A=l[R],j=await u(A.hash),I=l[d];(j>h||j===h&&A.seq<I.seq)&&(d=R,h=j)}let m=l.splice(d,1)[0],y=a.get(m.hash)??0,p=y|m.mask;if(p===y)continue;if(a.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let x=await U(t,m.hash);for(let R of x.parents)l.push({hash:R,mask:p,seq:f++})}for(let d of r)i.has(d)||o.push(d);return o}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,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!t[i]&&!n[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&t[i];)i++;for(;o<r&&n[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function 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 o(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let a=0;for(;a<r.length;){let c=r[a++],f=c.oStart,l=c.oStart+c.oLength,u=[c];for(o(f);a<r.length;){let d=r[a];if(d.oStart>l)break;l=Math.max(l,d.oStart+d.oLength),u.push(d),a++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?t:n;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:d.slice(c.abStart,c.abStart+c.abLength)})}}else{let d={a:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let x of u){let R=x.oStart,A=R+x.oLength,j=x.abStart,I=j+x.abLength,w=d[x.ab];w.abMin=Math.min(j,w.abMin),w.abMax=Math.max(I,w.abMax),w.oMin=Math.min(R,w.oMin),w.oMax=Math.max(A,w.oMax)}let h=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(l-d.a.oMax),y=d.b.abMin+(f-d.b.oMin),p=d.b.abMax+(l-d.b.oMax);s.push({stable:!1,a:t.slice(h,m),o:e.slice(f,l),b:n.slice(y,p)})}i=l}return o(e.length),s}function Hr(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=Dr(t,e,n),o=[],a=[];function c(){a.length&&(o.push({type:"ok",lines:a}),a=[])}for(let f of i)f.stable?a.push(...f.content):s&&hn(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?un(o):un(Nr(o))}function Re(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",o=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),f=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,l=Hr(t,e,n,{conflictStyle:i}),u=!1,d=[];for(let h of l)h.type==="ok"?d.push(...h.lines):(u=!0,i==="diff3"?d.push(o,...h.a,a,...h.o,c,...h.b,f):d.push(o,...h.a,c,...h.b,f));return{conflict:u,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 a of r){let c=a.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let l=c+a.buffer1[1],u=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:e.slice(c,l),o:[],b:n.slice(a.buffer2[0],u)}),i=l}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[t]:s}function 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 o=e[r+1],a=s;a.a=[...s.a,...i.lines,...o.a],a.b=[...s.b,...i.lines,...o.b],a.o=[...s.o,...i.lines,...o.o],r++}else n.push(i)}return n}function 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}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(gt);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
12
12
  `)}
13
13
  `:a.join(`
14
14
  `)}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:o,oursMap:a,theirsMap:c}=await Gr(t,e,n,r),f=await Wr(t,i,o,a,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),o=await U(t,n);if(s.length===0)return{...await pe(t,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let f=await U(t,s[0]);return{...await pe(t,f.tree,i.tree,o.tree,r),baseTree:f.tree}}let a=await On(t,e,n,s,1);return{...await pe(t,a,i.tree,o.tree,r),baseTree:a}}async function Gr(t,e,n,r){let s=await ue(t,e),i=await ue(t,n),o=await ue(t,r),a=new Set;for(let f of s.keys())a.add(f);for(let f of i.keys())a.add(f);for(let f of o.keys())a.add(f);let c=new Map;for(let f of a){let l=s.get(f)??null,u=i.get(f)??null,d=o.get(f)??null,h=l?{hash:l.hash,mode:l.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,y=d?{hash:d.hash,mode:d.mode}:null,g=(l?1:0)|(u?2:0)|(d?4:0),x=l?.hash??null,R=u?.hash??null,A=d?.hash??null,j=0;x!==null&&x===R&&(j|=3),x!==null&&x===A&&(j|=5),R!==null&&R===A&&(j|=6);let I={path:f,stages:[h,m,y],pathnames:[f,f,f],filemask:g,matchMask:j,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:o}}function _r(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,o=r?.hash??null;return i===s&&o===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===o&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&o===null?(t.merged={result:null,clean:!0},!0):o===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?t.merged={result:{hash:o,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function Wr(t,e,n,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[b,p]of n)r.has(b)||a.push({path:b,status:"deleted",oldHash:p.hash,oldMode:p.mode}),s.has(b)||c.push({path:b,status:"deleted",oldHash:p.hash,oldMode:p.mode});for(let[b,p]of r)n.has(b)||a.push({path:b,status:"added",newHash:p.hash,newMode:p.mode});for(let[b,p]of s)n.has(b)||c.push({path:b,status:"added",newHash:p.hash,newMode:p.mode});let f=await dt(t,a),l=await dt(t,c);if(f.renames.length===0&&l.renames.length===0)return o;let u=new Map,d=new Map;for(let b of f.renames)u.set(b.oldPath,b);for(let b of l.renames)d.set(b.oldPath,b);let h=new Set;for(let[b]of r)!n.has(b)&&s.has(b)&&h.add(b);let m=new Set,y=i?.a??"HEAD",g=i?.b??"theirs";function x(b,p,O=0){o.msgBuf.push({sortKey:b,subOrder:O,text:p})}for(let b of[...n.keys()].sort()){let p=u.get(b),O=d.get(b);if(!p&&!O)continue;let C=n.get(b);if(m.add(b),p&&O)if(m.add(p.newPath),m.add(O.newPath),p.newPath===O.newPath){let T=r.get(p.newPath),P=s.get(O.newPath);if(T.hash===P.hash)o.entries.push(z(p.newPath,T));else{let D=yt(e,p.newPath);D.stages=[{hash:C.hash,mode:C.mode},{hash:T.hash,mode:T.mode},{hash:P.hash,mode:P.mode}],D.pathnames=[b,p.newPath,O.newPath],D.filemask=7,D.merged={result:null,clean:!1}}}else{let T=r.get(p.newPath),P=s.get(O.newPath),D=await In(t,C,T,P,i);D.conflict&&x(b,`Auto-merging ${b}`,-1),o.conflicts.push({path:b,reason:"rename-rename",oursPath:p.newPath,theirsPath:O.newPath}),x(b,`CONFLICT (rename/rename): ${b} renamed to ${p.newPath} in ${y} and to ${O.newPath} in ${g}.`),o.entries.push(z(b,C,1)),o.entries.push(F(p.newPath,T.mode,D.hash,2)),o.entries.push(F(O.newPath,P.mode,D.hash,3)),o.worktreeBlobs.set(p.newPath,{hash:D.hash,mode:T.mode}),o.worktreeBlobs.set(O.newPath,{hash:D.hash,mode:P.mode})}else if(p){m.add(p.newPath);let T=s.get(b),P=r.get(p.newPath),D=h.has(p.newPath);if(T)if(D)await wn(t,o,p.newPath,b,C,P,T,r,s,!1,i);else if(T.hash===C.hash&&P.hash===C.hash)o.entries.push(z(p.newPath,P));else if(T.hash===C.hash)o.entries.push(z(p.newPath,P));else if(P.hash===C.hash)o.entries.push(F(p.newPath,P.mode,T.hash));else{let H=yt(e,p.newPath);H.stages=[{hash:C.hash,mode:C.mode},{hash:P.hash,mode:P.mode},{hash:T.hash,mode:T.mode}],H.pathnames=[b,p.newPath,b],H.filemask=7,H.merged={result:null,clean:!1}}else{let H=s.get(p.newPath);if(o.conflicts.push({path:p.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:b}),x(p.newPath,`CONFLICT (rename/delete): ${b} renamed to ${p.newPath} in ${y}, but deleted in ${g}.`),H){o.conflicts.push({path:p.newPath,reason:"add-add"}),x(p.newPath,`Auto-merging ${p.newPath}`,0),x(p.newPath,`CONFLICT (add/add): Merge conflict in ${p.newPath}`,1),o.entries.push(z(p.newPath,P,2)),o.entries.push(z(p.newPath,H,3));let Ge=await Fe(t,P.hash,H.hash,P.mode,i);o.worktreeBlobs.set(p.newPath,{hash:Ge,mode:P.mode})}else o.entries.push(F(p.newPath,C.mode,C.hash,1)),o.entries.push(z(p.newPath,P,2)),o.worktreeBlobs.set(p.newPath,{hash:P.hash,mode:P.mode}),P.hash!==C.hash&&x(p.newPath,`CONFLICT (modify/delete): ${p.newPath} deleted in ${g} and modified in ${y}. Version ${y} of ${p.newPath} left in tree.`,1)}}else if(O){m.add(O.newPath);let T=r.get(b),P=s.get(O.newPath),D=h.has(O.newPath);if(T)if(D)await wn(t,o,O.newPath,b,C,T,P,r,s,!0,i);else if(T.hash===C.hash&&P.hash===C.hash)o.entries.push(z(O.newPath,P));else if(T.hash===C.hash)o.entries.push(z(O.newPath,P));else if(P.hash===C.hash)o.entries.push(F(O.newPath,P.mode,T.hash));else{let H=yt(e,O.newPath);H.stages=[{hash:C.hash,mode:C.mode},{hash:T.hash,mode:T.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(o.conflicts.push({path:O.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:b}),x(O.newPath,`CONFLICT (rename/delete): ${b} renamed to ${O.newPath} in ${g}, but deleted in ${y}.`),H){o.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),o.entries.push(z(O.newPath,H,2)),o.entries.push(z(O.newPath,P,3));let Ge=await Fe(t,H.hash,P.hash,H.mode,i);o.worktreeBlobs.set(O.newPath,{hash:Ge,mode:H.mode})}else o.entries.push(F(O.newPath,C.mode,C.hash,1)),o.entries.push(z(O.newPath,P,3)),o.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 ${g}. Version ${g} of ${O.newPath} left in tree.`,1)}}}let R=new Set(f.renames.map(b=>b.newPath)),A=new Set(l.renames.map(b=>b.newPath)),j=mn(n,r),I=mn(n,s),w=pn(j,s,n),E=pn(I,r,n),$=gn(f.renames,w),S=gn(l.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 a){if(b.status!=="added"||R.has(b.path))continue;let p=bn(b.path,M,B);if(!p)continue;if(e.has(p)||n.has(p)||r.has(p)||s.has(p)){if(r.has(p)){x(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${b.path}.`,1);continue}let T=r.get(b.path),P=s.get(p)??n.get(p);o.entries.push(F(p,T.mode,T.hash,2)),P&&o.entries.push(F(p,P.mode,P.hash,3)),o.worktreeBlobs.set(p,{hash:T.hash,mode:T.mode}),o.conflicts.push({path:p,reason:"add-add"}),x(p,`CONFLICT (file location): ${b.path} added in ${y} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,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);o.entries.push(F(p,O.mode,O.hash,2)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),x(p,`CONFLICT (file location): ${b.path} added in ${y} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,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"||A.has(b.path))continue;let p=bn(b.path,k,N);if(!p)continue;if(e.has(p)||n.has(p)||r.has(p)||s.has(p)){if(s.has(p)){x(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${b.path}.`,1);continue}let T=s.get(b.path),P=r.get(p)??n.get(p);P&&o.entries.push(F(p,P.mode,P.hash,2)),o.entries.push(F(p,T.mode,T.hash,3)),o.worktreeBlobs.set(p,{hash:T.hash,mode:T.mode}),o.conflicts.push({path:p,reason:"add-add"}),x(p,`CONFLICT (file location): ${b.path} added in ${g} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${p}.`,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);o.entries.push(F(p,O.mode,O.hash,3)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),x(p,`CONFLICT (file location): ${b.path} added in ${g} inside a directory that was renamed in ${y}, suggesting it should perhaps be moved to ${p}.`,1);let C=e.get(b.path);C&&(C.merged={result:null,clean:!0}),m.add(b.path)}let ge=new Set(o.entries.map(b=>b.path));for(let b of ge){let p=e.get(b);p&&(p.merged={result:null,clean:!0})}for(let b of m){if(ge.has(b))continue;let p=e.get(b);if(!p||p.merged.clean)continue;p.filemask===7&&!p.pathConflict||(p.merged={result:null,clean:!0})}return o}function mn(t,e){let n=new Set;for(let i of t.keys()){let o=K(i);for(;o;)n.add(o),o=K(o)}let r=new Set;for(let i of e.keys()){let o=K(i);for(;o;)r.add(o),o=K(o)}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),o=!0;for(;;){if(!o){let a=s.length+(s?1:0),c=i.length+(i?1:0),f=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(e.has(s)){let a=n.get(s);a||(a=new Map,n.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=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,o=null;for(let[a,c]of r)c===s?i=s:c>s&&(s=c,o=a);s>0&&i!==s&&o!==null&&e.set(n,o)}return e}function bn(t,e,n){let r=K(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let o=t.slice(r.length+1);return i?`${i}/${o}`:o}r=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,o,a,c,f=!1,l){let u=f?a.get(n):c.get(n),d=f?o:i;if(u.hash===d.hash){e.entries.push(F(n,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await In(t,s,i,o,l,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(F(n,u.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){e.entries.push(z(n,u,2)),e.entries.push(F(n,o.mode,m.hash,3));let y=await Fe(t,u.hash,m.hash,u.mode,l);e.worktreeBlobs.set(n,{hash:y,mode:u.mode})}else{e.entries.push(F(n,i.mode,m.hash,2)),e.entries.push(z(n,u,3));let y=await Fe(t,m.hash,u.hash,i.mode,l);e.worktreeBlobs.set(n,{hash:y,mode:i.mode})}}async function In(t,e,n,r,s,i,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(Q(e.mode)||Q(n.mode)||Q(r.mode))return{hash:n.hash,conflict:!0};let a=await _(t,e.hash),c=await _(t,n.hash),f=await _(t,r.hash);if(ee(c)||ee(f)||ee(a))return{hash:n.hash,conflict:!0};let l=V(a),u=V(c),d=V(f),h=s?.conflictStyle,m=Re(u,l,d,{conflictStyle:h});if(!m.conflict)return{hash:await bt(t,m.result),conflict:!1};let y=s?.a??"HEAD",g=s?.b??"theirs",x=i?.oursPath?`${y}:${i.oursPath}`:y,R=i?.theirsPath?`${g}:${i.theirsPath}`:g,A=ce(c,a,f,{a:x,b:R,markerSize:o??7,conflictStyle:h});return{hash:await G(t,"blob",ie.encode(A)),conflict:!0}}async function Fe(t,e,n,r,s){let i=await _(t,e),o=await _(t,n),a=ce(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return G(t,"blob",ie.encode(a))}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],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,y=0){o.push({sortKey:h,subOrder:y,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(v(h,m.merged.result.hash,m.merged.result.mode));continue}await Vr(t,m,n,s,i,c,a)}o.sort((h,m)=>(h.sortKey<m.sortKey?-1:h.sortKey>m.sortKey?1:0)||h.subOrder-m.subOrder);let f=o.map(h=>h.text),l=[],u=new Set;for(let h of s)h.stage===0&&(l.push(h),u.add(h.path));for(let[h,m]of a)u.has(h)||l.push(v(h,m.hash,m.mode));l.sort((h,m)=>Oe(h.path,m.path));let d=await at(t,l);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function Vr(t,e,n,r,s,i,o){let a=e.path,[c,f,l]=e.stages,u=c?.hash??null,d=f?.hash??null,h=l?.hash??null;if(d===null&&h!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=n?.a??"HEAD",y=n?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(v(a,u,c.mode,1)),r.push(v(a,h,l.mode,3)),o.set(a,{hash:h,mode:l.mode});return}if(h===null&&d!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=n?.b??"theirs",y=n?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(v(a,u,c.mode,1)),r.push(v(a,d,f.mode,2)),o.set(a,{hash:d,mode:f.mode});return}if(u===null&&d!==null&&h!==null){if(d===h){r.push(v(a,d,f.mode));return}i(a,`Auto-merging ${a}`,0);let m=await _(t,d),y=await _(t,h);if(ee(m)||ee(y)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let g=V(""),x=V(m),R=V(y),A=Re(x,g,R,{conflictStyle:n?.conflictStyle});if(!A.conflict){let w=await bt(t,A.result);r.push(v(a,w,f.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.mode,3));let j=ce(m,"",y,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),I=await G(t,"blob",ie.encode(j));o.set(a,{hash:I,mode:f.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(v(a,h,l.mode));return}if(h===u){r.push(v(a,d,f.mode));return}if(d===h){r.push(v(a,d,f.mode));return}if(i(a,`Auto-merging ${a}`,0),Q(c.mode)||Q(f.mode)||Q(l.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(v(a,u,c.mode,1)),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let m=await _(t,u),y=await _(t,d),g=await _(t,h);if(ee(y)||ee(g)||ee(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(v(a,u,c.mode,1)),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let x=V(m),R=V(y),A=V(g),j=Re(R,x,A,{conflictStyle:n?.conflictStyle});if(j.conflict){let I=e.pathnames[1],w=e.pathnames[2],E=I!==a||w!==a,$={path:a,reason:"content"};E&&(I!==a&&($.oursOrigPath=I),w!==a&&($.theirsOrigPath=w)),s.push($),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(v(a,u,c.mode,1)),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.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,g,{a:S,b:k,conflictStyle:n?.conflictStyle}),B=await G(t,"blob",ie.encode(M));o.set(a,{hash:B,mode:f.mode})}else{let I=await bt(t,j.result);r.push(v(a,I,f.mode))}return}}var Kr=200;async function On(t,e,n,r,s){let i=await Promise.all(r.map(async l=>({hash:l,timestamp:(await U(t,l)).committer.timestamp})));i.sort((l,u)=>l.timestamp-u.timestamp);let o=i.map(l=>l.hash),a=o[0],c=a,f=(await U(t,a)).tree;for(let l=1;l<o.length;l++){let u=o[l],d=(await U(t,u)).tree,h=null;if(s>=Kr)h=f;else{let g=await Pe(t,c,u);g.length===0?h=null:g.length===1?h=(await U(t,g[0])).tree:h=await On(t,c,u,g,s+1)}let m=await pe(t,h,f,d);f=await qr(t,m,s);let y=Ae({type:"commit",tree:f,parents:[c,u],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(a=>a.stage===0),s=new Map;for(let a of e.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let i=(a,c)=>s.get(`${a}\0${c}`),o={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let l=i(a.path,1);if(l){r.push({...l,stage:0});continue}}if(a.reason==="rename-rename"){let l=a.oursPath??a.path,u=a.theirsPath??a.path,d=i(a.path,1),h=i(l,2),m=i(u,3);if(h&&m){let y=me.decode((await q(t,h.hash)).content),g=me.decode((await q(t,m.hash)).content),x=d?me.decode((await q(t,d.hash)).content):"",R=8+n*2,A=o.a??"Temporary merge branch 1",j=o.b??"Temporary merge branch 2",I=ce(y,x,g,{a:`${A}:${l}`,o:o.o,b:`${j}:${u}`,markerSize:R}),w=await G(t,"blob",ie.encode(I));r.push({path:l,mode:h.mode,hash:w,stage:0,stat:ne()}),r.push({path:u,mode:m.mode,hash:w,stage:0,stat:ne()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(a.path,2),f=i(a.path,3);if(c&&f&&(a.reason==="content"||a.reason==="add-add")){let l=me.decode((await q(t,c.hash)).content),u=me.decode((await q(t,f.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?me.decode((await q(t,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,y=o.a??"Temporary merge branch 1",g=o.b??"Temporary merge branch 2",x=m?`${y}:${a.oursOrigPath??a.path}`:y,R=m?`${g}:${a.theirsOrigPath??a.path}`:g,A=ce(l,h,u,{a:x,o:o.o,b:R,markerSize:o.markerSize}),j=await G(t,"blob",ie.encode(A));r.push({path:a.path,mode:c.mode,hash:j,stage:0,stat:ne()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>Oe(a.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(`
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:o,oursMap:a,theirsMap:c}=await Gr(t,e,n,r),f=await Wr(t,i,o,a,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),o=await U(t,n);if(s.length===0)return{...await pe(t,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let f=await U(t,s[0]);return{...await pe(t,f.tree,i.tree,o.tree,r),baseTree:f.tree}}let a=await On(t,e,n,s,1);return{...await pe(t,a,i.tree,o.tree,r),baseTree:a}}async function Gr(t,e,n,r){let s=await ue(t,e),i=await ue(t,n),o=await ue(t,r),a=new Set;for(let f of s.keys())a.add(f);for(let f of i.keys())a.add(f);for(let f of o.keys())a.add(f);let c=new Map;for(let f of a){let l=s.get(f)??null,u=i.get(f)??null,d=o.get(f)??null,h=l?{hash:l.hash,mode:l.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,y=d?{hash:d.hash,mode:d.mode}:null,p=(l?1:0)|(u?2:0)|(d?4:0),x=l?.hash??null,R=u?.hash??null,A=d?.hash??null,j=0;x!==null&&x===R&&(j|=3),x!==null&&x===A&&(j|=5),R!==null&&R===A&&(j|=6);let I={path:f,stages:[h,m,y],pathnames:[f,f,f],filemask:p,matchMask:j,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:o}}function _r(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,o=r?.hash??null;return i===s&&o===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===o&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&o===null?(t.merged={result:null,clean:!0},!0):o===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?t.merged={result:{hash:o,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function Wr(t,e,n,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[b,g]of n)r.has(b)||a.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)||a.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,a),l=await dt(t,c);if(f.renames.length===0&&l.renames.length===0)return o;let u=new Map,d=new Map;for(let b of f.renames)u.set(b.oldPath,b);for(let b of l.renames)d.set(b.oldPath,b);let h=new Set;for(let[b]of r)!n.has(b)&&s.has(b)&&h.add(b);let m=new Set,y=i?.a??"HEAD",p=i?.b??"theirs";function x(b,g,O=0){o.msgBuf.push({sortKey:b,subOrder:O,text:g})}for(let b of[...n.keys()].sort()){let g=u.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 T=r.get(g.newPath),P=s.get(O.newPath);if(T.hash===P.hash)o.entries.push(z(g.newPath,T));else{let D=yt(e,g.newPath);D.stages=[{hash:C.hash,mode:C.mode},{hash:T.hash,mode:T.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 T=r.get(g.newPath),P=s.get(O.newPath),D=await In(t,C,T,P,i);D.conflict&&x(b,`Auto-merging ${b}`,-1),o.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}.`),o.entries.push(z(b,C,1)),o.entries.push(F(g.newPath,T.mode,D.hash,2)),o.entries.push(F(O.newPath,P.mode,D.hash,3)),o.worktreeBlobs.set(g.newPath,{hash:D.hash,mode:T.mode}),o.worktreeBlobs.set(O.newPath,{hash:D.hash,mode:P.mode})}else if(g){m.add(g.newPath);let T=s.get(b),P=r.get(g.newPath),D=h.has(g.newPath);if(T)if(D)await wn(t,o,g.newPath,b,C,P,T,r,s,!1,i);else if(T.hash===C.hash&&P.hash===C.hash)o.entries.push(z(g.newPath,P));else if(T.hash===C.hash)o.entries.push(z(g.newPath,P));else if(P.hash===C.hash)o.entries.push(F(g.newPath,P.mode,T.hash));else{let H=yt(e,g.newPath);H.stages=[{hash:C.hash,mode:C.mode},{hash:P.hash,mode:P.mode},{hash:T.hash,mode:T.mode}],H.pathnames=[b,g.newPath,b],H.filemask=7,H.merged={result:null,clean:!1}}else{let H=s.get(g.newPath);if(o.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){o.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),o.entries.push(z(g.newPath,P,2)),o.entries.push(z(g.newPath,H,3));let Ge=await Fe(t,P.hash,H.hash,P.mode,i);o.worktreeBlobs.set(g.newPath,{hash:Ge,mode:P.mode})}else o.entries.push(F(g.newPath,C.mode,C.hash,1)),o.entries.push(z(g.newPath,P,2)),o.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 T=r.get(b),P=s.get(O.newPath),D=h.has(O.newPath);if(T)if(D)await wn(t,o,O.newPath,b,C,T,P,r,s,!0,i);else if(T.hash===C.hash&&P.hash===C.hash)o.entries.push(z(O.newPath,P));else if(T.hash===C.hash)o.entries.push(z(O.newPath,P));else if(P.hash===C.hash)o.entries.push(F(O.newPath,P.mode,T.hash));else{let H=yt(e,O.newPath);H.stages=[{hash:C.hash,mode:C.mode},{hash:T.hash,mode:T.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(o.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){o.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),o.entries.push(z(O.newPath,H,2)),o.entries.push(z(O.newPath,P,3));let Ge=await Fe(t,H.hash,P.hash,H.mode,i);o.worktreeBlobs.set(O.newPath,{hash:Ge,mode:H.mode})}else o.entries.push(F(O.newPath,C.mode,C.hash,1)),o.entries.push(z(O.newPath,P,3)),o.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)),A=new Set(l.renames.map(b=>b.newPath)),j=mn(n,r),I=mn(n,s),w=pn(j,s,n),E=pn(I,r,n),$=gn(f.renames,w),S=gn(l.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 a){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 T=r.get(b.path),P=s.get(g)??n.get(g);o.entries.push(F(g,T.mode,T.hash,2)),P&&o.entries.push(F(g,P.mode,P.hash,3)),o.worktreeBlobs.set(g,{hash:T.hash,mode:T.mode}),o.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);o.entries.push(F(g,O.mode,O.hash,2)),o.worktreeBlobs.set(g,{hash:O.hash,mode:O.mode}),o.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"||A.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 T=s.get(b.path),P=r.get(g)??n.get(g);P&&o.entries.push(F(g,P.mode,P.hash,2)),o.entries.push(F(g,T.mode,T.hash,3)),o.worktreeBlobs.set(g,{hash:T.hash,mode:T.mode}),o.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);o.entries.push(F(g,O.mode,O.hash,3)),o.worktreeBlobs.set(g,{hash:O.hash,mode:O.mode}),o.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(o.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 o}function mn(t,e){let n=new Set;for(let i of t.keys()){let o=K(i);for(;o;)n.add(o),o=K(o)}let r=new Set;for(let i of e.keys()){let o=K(i);for(;o;)r.add(o),o=K(o)}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),o=!0;for(;;){if(!o){let a=s.length+(s?1:0),c=i.length+(i?1:0),f=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(e.has(s)){let a=n.get(s);a||(a=new Map,n.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=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,o=null;for(let[a,c]of r)c===s?i=s:c>s&&(s=c,o=a);s>0&&i!==s&&o!==null&&e.set(n,o)}return e}function bn(t,e,n){let r=K(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let o=t.slice(r.length+1);return i?`${i}/${o}`:o}r=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,o,a,c,f=!1,l){let u=f?a.get(n):c.get(n),d=f?o:i;if(u.hash===d.hash){e.entries.push(F(n,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await In(t,s,i,o,l,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(F(n,u.mode,m.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){e.entries.push(z(n,u,2)),e.entries.push(F(n,o.mode,m.hash,3));let y=await Fe(t,u.hash,m.hash,u.mode,l);e.worktreeBlobs.set(n,{hash:y,mode:u.mode})}else{e.entries.push(F(n,i.mode,m.hash,2)),e.entries.push(z(n,u,3));let y=await Fe(t,m.hash,u.hash,i.mode,l);e.worktreeBlobs.set(n,{hash:y,mode:i.mode})}}async function In(t,e,n,r,s,i,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(Q(e.mode)||Q(n.mode)||Q(r.mode))return{hash:n.hash,conflict:!0};let a=await _(t,e.hash),c=await _(t,n.hash),f=await _(t,r.hash);if(ee(c)||ee(f)||ee(a))return{hash:n.hash,conflict:!0};let l=V(a),u=V(c),d=V(f),h=s?.conflictStyle,m=Re(u,l,d,{conflictStyle:h});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,A=ce(c,a,f,{a:x,b:R,markerSize:o??7,conflictStyle:h});return{hash:await G(t,"blob",ie.encode(A)),conflict:!0}}async function Fe(t,e,n,r,s){let i=await _(t,e),o=await _(t,n),a=ce(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return G(t,"blob",ie.encode(a))}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],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,y=0){o.push({sortKey:h,subOrder:y,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(v(h,m.merged.result.hash,m.merged.result.mode));continue}await Vr(t,m,n,s,i,c,a)}o.sort((h,m)=>(h.sortKey<m.sortKey?-1:h.sortKey>m.sortKey?1:0)||h.subOrder-m.subOrder);let f=o.map(h=>h.text),l=[],u=new Set;for(let h of s)h.stage===0&&(l.push(h),u.add(h.path));for(let[h,m]of a)u.has(h)||l.push(v(h,m.hash,m.mode));l.sort((h,m)=>Oe(h.path,m.path));let d=await at(t,l);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function Vr(t,e,n,r,s,i,o){let a=e.path,[c,f,l]=e.stages,u=c?.hash??null,d=f?.hash??null,h=l?.hash??null;if(d===null&&h!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=n?.a??"HEAD",y=n?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(v(a,u,c.mode,1)),r.push(v(a,h,l.mode,3)),o.set(a,{hash:h,mode:l.mode});return}if(h===null&&d!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=n?.b??"theirs",y=n?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${y}. Version ${y} of ${a} left in tree.`),c&&r.push(v(a,u,c.mode,1)),r.push(v(a,d,f.mode,2)),o.set(a,{hash:d,mode:f.mode});return}if(u===null&&d!==null&&h!==null){if(d===h){r.push(v(a,d,f.mode));return}i(a,`Auto-merging ${a}`,0);let m=await _(t,d),y=await _(t,h);if(ee(m)||ee(y)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let p=V(""),x=V(m),R=V(y),A=Re(x,p,R,{conflictStyle:n?.conflictStyle});if(!A.conflict){let w=await bt(t,A.result);r.push(v(a,w,f.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.mode,3));let j=ce(m,"",y,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),I=await G(t,"blob",ie.encode(j));o.set(a,{hash:I,mode:f.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(v(a,h,l.mode));return}if(h===u){r.push(v(a,d,f.mode));return}if(d===h){r.push(v(a,d,f.mode));return}if(i(a,`Auto-merging ${a}`,0),Q(c.mode)||Q(f.mode)||Q(l.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(v(a,u,c.mode,1)),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let m=await _(t,u),y=await _(t,d),p=await _(t,h);if(ee(y)||ee(p)||ee(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(v(a,u,c.mode,1)),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let x=V(m),R=V(y),A=V(p),j=Re(R,x,A,{conflictStyle:n?.conflictStyle});if(j.conflict){let I=e.pathnames[1],w=e.pathnames[2],E=I!==a||w!==a,$={path:a,reason:"content"};E&&(I!==a&&($.oursOrigPath=I),w!==a&&($.theirsOrigPath=w)),s.push($),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(v(a,u,c.mode,1)),r.push(v(a,d,f.mode,2)),r.push(v(a,h,l.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));o.set(a,{hash:B,mode:f.mode})}else{let I=await bt(t,j.result);r.push(v(a,I,f.mode))}return}}var Kr=200;async function On(t,e,n,r,s){let i=await Promise.all(r.map(async l=>({hash:l,timestamp:(await U(t,l)).committer.timestamp})));i.sort((l,u)=>l.timestamp-u.timestamp);let o=i.map(l=>l.hash),a=o[0],c=a,f=(await U(t,a)).tree;for(let l=1;l<o.length;l++){let u=o[l],d=(await U(t,u)).tree,h=null;if(s>=Kr)h=f;else{let p=await Pe(t,c,u);p.length===0?h=null:p.length===1?h=(await U(t,p[0])).tree:h=await On(t,c,u,p,s+1)}let m=await pe(t,h,f,d);f=await qr(t,m,s);let y=Ae({type:"commit",tree:f,parents:[c,u],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(a=>a.stage===0),s=new Map;for(let a of e.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let i=(a,c)=>s.get(`${a}\0${c}`),o={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let l=i(a.path,1);if(l){r.push({...l,stage:0});continue}}if(a.reason==="rename-rename"){let l=a.oursPath??a.path,u=a.theirsPath??a.path,d=i(a.path,1),h=i(l,2),m=i(u,3);if(h&&m){let y=me.decode((await q(t,h.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,A=o.a??"Temporary merge branch 1",j=o.b??"Temporary merge branch 2",I=ce(y,x,p,{a:`${A}:${l}`,o:o.o,b:`${j}:${u}`,markerSize:R}),w=await G(t,"blob",ie.encode(I));r.push({path:l,mode:h.mode,hash:w,stage:0,stat:ne()}),r.push({path:u,mode:m.mode,hash:w,stage:0,stat:ne()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(a.path,2),f=i(a.path,3);if(c&&f&&(a.reason==="content"||a.reason==="add-add")){let l=me.decode((await q(t,c.hash)).content),u=me.decode((await q(t,f.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?me.decode((await q(t,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,y=o.a??"Temporary merge branch 1",p=o.b??"Temporary merge branch 2",x=m?`${y}:${a.oursOrigPath??a.path}`:y,R=m?`${p}:${a.theirsOrigPath??a.path}`:p,A=ce(l,h,u,{a:x,o:o.o,b:R,markerSize:o.markerSize}),j=await G(t,"blob",ie.encode(A));r.push({path:a.path,mode:c.mode,hash:j,stage:0,stat:ne()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>Oe(a.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(`
16
16
  `):`${n.join(`
17
17
  `)}
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,o=await pe(t,e,n,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}async function fs(t,e){let n=Ae({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,o)=>i.name.localeCompare(o.name)),r=await Promise.all(n.map(async i=>{let o=i.mode;return o||(o=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:o,name:i.name,hash:i.hash}})),s=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(o=>o.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),o=await ae(t,i.tree),a=new Set,c=0;for(let f of o){let l=L(r,f.path),u=_e(l);if(u!==r&&!a.has(u)&&(await n.mkdir(u,{recursive:!0}),a.add(u)),Q(f.mode)){let d=await _(t,f.hash);n.symlink?await n.symlink(d,l):await n.writeFile(l,d)}else{let d=await te(t,f.hash);await n.writeFile(l,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 o=await $e(t,i);if(!o)if(Pn.test(i)&&await t.objectStore.exists(i))o=i;else throw new Error(`ref or commit '${i}' not found`);let a=await U(t,o),c=await ae(t,a.tree),f={...t,fs:e,gitDir:s,workTree:r},l=new Set,u=0;for(let h of c){let m=L(r,h.path),y=_e(m);if(y!==r&&!l.has(y)&&(await e.mkdir(y,{recursive:!0}),l.add(y)),Q(h.mode)){let g=await _(t,h.hash);e.symlink?await e.symlink(g,m):await e.writeFile(m,g)}else{let g=await te(t,h.hash);await e.writeFile(m,g)}u++}let d=Pt(c.map(h=>({path:h.path,mode:parseInt(h.mode,8),hash:h.hash,stage:0,stat:ne()})));return await ze(f,d),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:u}}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};
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,o=await pe(t,e,n,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}async function fs(t,e){let n=Ae({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,o)=>i.name.localeCompare(o.name)),r=await Promise.all(n.map(async i=>{let o=i.mode;return o||(o=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:o,name:i.name,hash:i.hash}})),s=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(o=>o.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),o=await ae(t,i.tree),a=new Set,c=0;for(let f of o){let l=L(r,f.path),u=_e(l);if(u!==r&&!a.has(u)&&(await n.mkdir(u,{recursive:!0}),a.add(u)),Q(f.mode)){let d=await _(t,f.hash);n.symlink?await n.symlink(d,l):await n.writeFile(l,d)}else{let d=await te(t,f.hash);await n.writeFile(l,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 o=await $e(t,i);if(!o)if(Pn.test(i)&&await t.objectStore.exists(i))o=i;else throw new Error(`ref or commit '${i}' not found`);let a=await U(t,o),c=await ae(t,a.tree),f={...t,fs:e,gitDir:s,workTree:r},l=new Set,u=0;for(let h of c){let m=L(r,h.path),y=_e(m);if(y!==r&&!l.has(y)&&(await e.mkdir(y,{recursive:!0}),l.add(y)),Q(h.mode)){let p=await _(t,h.hash);e.symlink?await e.symlink(p,m):await e.writeFile(m,p)}else{let p=await te(t,h.hash);await e.writeFile(m,p)}u++}let d=Pt(c.map(h=>({path:h.path,mode:parseInt(h.mode,8),hash:h.hash,stage:0,stat:ne()})));return await ze(f,d),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:u}}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};