just-git 1.1.11 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -16
- package/dist/{hooks-OMCbhUGB.d.ts → hooks-Boa35Qx_.d.ts} +19 -2
- package/dist/index.d.ts +91 -3
- package/dist/index.js +401 -370
- package/dist/repo/index.d.ts +1 -1
- package/dist/repo/index.js +13 -13
- package/dist/server/index.d.ts +26 -2
- package/dist/server/index.js +31 -25
- package/package.json +1 -1
package/dist/repo/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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';
|
|
2
2
|
|
|
3
3
|
interface MergeConflict {
|
|
4
4
|
path: string;
|
package/dist/repo/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var ye=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});function rn(n){if(n==="")return".";if(n==="/")return"/";let e=n.charCodeAt(0)===47,t=n.charCodeAt(n.length-1)===47,r=n.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}`),t&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":t?"./":".")}function v(...n){if(n.length===0)return".";let e=n.filter(t=>t!=="").join("/");return e===""?".":rn(e)}function Ue(n){if(n==="")return".";if(n==="/")return"/";let e=n.length;for(;e>1&&n.charCodeAt(e-1)===47;)e--;let t=n.slice(0,e),r=t.lastIndexOf("/");return r===-1?".":r===0?"/":t.slice(0,r)}var ut=(()=>{let n=new Array(256);for(let e=0;e<256;e++)n[e]=(e>>4).toString(16)+(e&15).toString(16);return n})();function re(n){let e="";for(let t=0;t<20;t++)e+=ut[n[t]];return e}function we(n,e){let t="";for(let r=0;r<20;r++)t+=ut[n[e+r]];return t}function q(n){let e=new Uint8Array(20);for(let t=0;t<20;t++)e[t]=parseInt(n.slice(t*2,t*2+2),16);return e}var sn=new TextEncoder;function De(n){return typeof n=="string"?sn.encode(n):n}function on(){if(typeof globalThis.Bun<"u")return()=>{let n=new Bun.CryptoHasher("sha1"),e={update(t){return n.update(De(t)),e},hex:()=>Promise.resolve(n.digest("hex"))};return e};try{let n=ye(["node","crypto"].join(":"));if(typeof n.createHash=="function")return()=>{let e=n.createHash("sha1"),t={update(r){return e.update(De(r)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let n=[],e={update(t){return n.push(De(t)),e},async hex(){let t=0;for(let o of n)t+=o.byteLength;let r=new Uint8Array(t),s=0;for(let o of n)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return re(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 ht=on(),Ie=ht;async function xe(n){return ht().update(n).hex()}var an=1145655875,cn=2;async function Be(n,e){let t=v(n.gitDir,"index"),r=await fn(e);await n.fs.writeFile(t,r)}function dt(n){let e=[...n].sort(mt);return{version:cn,entries:e}}function Q(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function fn(n){let e=[...n.entries].sort(mt),t=12;for(let l of e){let u=62+l.path.length+1;t+=Math.ceil(u/8)*8}t+=20;let r=new ArrayBuffer(t),s=new Uint8Array(r),i=new DataView(r),o=0;i.setUint32(o,an),o+=4,i.setUint32(o,n.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=q(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 b=new TextEncoder().encode(l.path);s.set(b,o),o+=b.byteLength,s[o]=0,o+=1;let g=62+b.byteLength+1,w=Math.ceil(g/8)*8;o=u+w}let a=s.subarray(0,o),c=await xe(a),f=q(c);return s.set(f,o),s}function mt(n,e){return n.path<e.path?-1:n.path>e.path?1:n.stage-e.stage}var ln=new Set(["tree","commit","tag"]),Oe=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,t){if(!ln.has(t.type))return;let r=t.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,t),this.currentBytes+=r}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var pt=new Uint32Array(256);for(let n=0;n<256;n++){let e=n;for(let t=0;t<8;t++)e=e&1?3988292384^e>>>1:e>>>1;pt[n]=e}function gt(n){let e=4294967295;for(let t=0;t<n.byteLength;t++)e=pt[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}async function un(){let n;try{n=ye(["node","zlib"].join(":"))}catch{try{n=await import(["node","zlib"].join(":"))}catch{}}if(n&&typeof n.deflateSync=="function"&&typeof n.inflateSync=="function"){let e;try{let t=n.inflateSync(n.deflateSync(Buffer.from("x")),{info:!0});t?.engine&&typeof t.engine.bytesWritten=="number"&&(e=r=>{let s=n.inflateSync(r,{info:!0});return{result:new Uint8Array(s.buffer),bytesConsumed:s.engine.bytesWritten}})}catch{}return{deflateSync:t=>new Uint8Array(n.deflateSync(t)),inflateSync:t=>new Uint8Array(n.inflateSync(t)),inflateWithConsumed:e}}if(typeof globalThis.CompressionStream=="function"&&typeof globalThis.DecompressionStream=="function")return{async deflateSync(e){let t=new CompressionStream("deflate"),r=t.writable.getWriter();return r.write(e),r.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())},async inflateSync(e){let t=new DecompressionStream("deflate"),r=t.writable.getWriter();return r.write(e),r.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())}};throw new Error("No zlib implementation available. Requires Bun, Node.js, Deno, or a browser with CompressionStream.")}var hn=null;function He(){return hn??=un()}async function Ne(n){return await(await He()).deflateSync(n)}async function oe(n){return await(await He()).inflateSync(n)}async function bt(n,e){let t=await He();if(t.inflateWithConsumed){let{result:o,bytesConsumed:a}=t.inflateWithConsumed(n);if(o.byteLength!==e)throw new Error(`Inflate size mismatch: got ${o.byteLength}, expected ${e}`);return{result:o,bytesConsumed:a}}let r=await t.inflateSync(n);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);let s=2,i=n.byteLength;for(;s<i;){let o=s+i>>>1;try{(await t.inflateSync(n.subarray(0,o))).byteLength===e?i=o:s=o+1}catch{s=o+1}}return{result:r,bytesConsumed:s}}var yt=1346454347,dn=2,mn=1,pn=2,gn=3,bn=4,Pe=6,Ge=7,yn={[mn]:"commit",[pn]:"tree",[gn]:"blob",[bn]:"tag"};async function It(n,e){let t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=t.getUint32(0);if(r!==yt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${yt.toString(16)})`);let s=t.getUint32(4);if(s!==dn)throw new Error(`Unsupported pack version: ${s}`);let i=t.getUint32(8),o=[],a=12;for(let f=0;f<i;f++){let l=await wn(n,a);o.push(l),a=l.nextOffset}return(await In(o,e)).map((f,l)=>({...f,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function wn(n,e){let t=e,r=n[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=n[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Pe){let u=n[e++];for(a=u&127;u&128;)a+=1,u=n[e++],a=(a<<7)+(u&127);a=t-a}else s===Ge&&(c=we(n,e),e+=20);let{result:f,bytesConsumed:l}=await bt(n.subarray(e),i);return{headerOffset:t,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+l}}async function In(n,e){let t=new Map;for(let i=0;i<n.length;i++)t.set(n[i].headerOffset,i);let r=new Array(n.length).fill(null);async function s(i){let o=r[i];if(o)return o;let a=n[i];if(a.typeNum!==Pe&&a.typeNum!==Ge){let d=yn[a.typeNum];if(!d)throw new Error(`Unknown object type: ${a.typeNum}`);let h={type:d,content:a.inflated,hash:await Fe(d,a.inflated)};return r[i]=h,h}if(a.typeNum===Pe){let d=t.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=he(h.content,a.inflated),b={type:h.type,content:m,hash:await Fe(h.type,m)};return r[i]=b,b}let c=await xn(n,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=he(f.content,a.inflated),u={type:f.type,content:l,hash:await Fe(f.type,l)};return r[i]=u,u}for(let i=0;i<n.length;i++)await s(i);return r}async function xn(n,e,t,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===t)return s;for(let s=0;s<n.length;s++){let i=n[s];if(i.typeNum!==Pe&&i.typeNum!==Ge&&(await r(s)).hash===t)return s}}function he(n,e){let t=0,{value:r,newPos:s}=wt(e,t);if(t=s,r!==n.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${n.byteLength}`);let{value:i,newPos:o}=wt(e,t);t=o;let a=new Uint8Array(i),c=0;for(;t<e.byteLength;){let f=e[t++];if(f&128){let l=0,u=0;f&1&&(l=e[t++]),f&2&&(l|=e[t++]<<8),f&4&&(l|=e[t++]<<16),f&8&&(l|=e[t++]<<24),f&16&&(u=e[t++]),f&32&&(u|=e[t++]<<8),f&64&&(u|=e[t++]<<16),u===0&&(u=65536),a.set(n.subarray(l,l+u),c),c+=u}else if(f>0)a.set(e.subarray(t,t+f),c),c+=f,t+=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 wt(n,e){let t=0,r=0,s;do s=n[e++],t|=(s&127)<<r,r+=7;while(s&128);return{value:t,newPos:e}}var On=new TextEncoder;async function Fe(n,e){let t=On.encode(`${n} ${e.byteLength}\0`),r=Ie();return r.update(t),r.update(e),r.hex()}var xt=4285812579,Ot=2,ee=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0)!==xt)throw new Error("Invalid pack index: bad magic");if(t.getUint32(4)!==Ot)throw new Error(`Unsupported pack index version: ${t.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let i=0;i<256;i++)this.fanout[i]=t.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]=t.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 t=q(e),r=t[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,t);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 t=0;t<this.count;t++)e.push(this.hashAtSlot(t));return e}findByPrefix(e){if(e.length<2)return[];let t=parseInt(e.slice(0,2),16),r=t===0?0:this.fanout[t-1],s=this.fanout[t],i=q(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 t="",r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s];t+=(i>>4).toString(16)+(i&15).toString(16)}return t}compareAt(e,t){let r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s],o=t[s];if(i<o)return-1;if(i>o)return 1}return 0}getOffset(e){let t=this.offsets[e];if(t&2147483648){let r=t&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return t}};async function Pn(n,e){let t=[...n].sort((h,m)=>h.hash<m.hash?-1:h.hash>m.hash?1:0),r=t.length,s=[];for(let h of t)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,xt),c+=4,a.setUint32(c,Ot),c+=4;let f=new Uint32Array(256);for(let h of t){let m=parseInt(h.hash.slice(0,2),16);for(let b=m;b<256;b++)f[b]++}for(let h=0;h<256;h++)a.setUint32(c,f[h]),c+=4;for(let h of t)o.set(q(h.hash),c),c+=20;for(let h of t)a.setUint32(c,h.crc),c+=4;let l=0;for(let h of t)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=Ie();u.update(o.subarray(0,c));let d=await u.hex();return o.set(q(d),c),o}async function Pt(n){let t=(await It(n)).map(s=>({hash:s.hash,offset:s.offset,crc:gt(n.subarray(s.offset,s.nextOffset))})),r=n.subarray(n.byteLength-20);return Pn(t,r)}var Rn=6,kn=7,En={1:"commit",2:"tree",3:"blob",4:"tag"},de=class{constructor(e,t){this.data=e;this.index=t instanceof ee?t:new ee(t)}index;hasObject(e){return this.index.has(e)}findByPrefix(e){return this.index.findByPrefix(e)}async readObject(e){let t=this.index.lookup(e);return t===null?null:this.readAt(t)}get objectCount(){return this.index.objectCount}async readAt(e){let t=this.data,r=e,s=t[r++],i=s>>4&7,o=s&15,a=4;for(;s&128;)s=t[r++],o|=(s&127)<<a,a+=7;if(i===Rn){let l=t[r++],u=l&127;for(;l&128;)u+=1,l=t[r++],u=(u<<7)+(l&127);let d=await oe(t.subarray(r)),h=await this.readAt(e-u);return{type:h.type,content:he(h.content,d)}}if(i===kn){let l=we(t,r);r+=20;let u=await oe(t.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:he(h.content,u)}}let c=En[i];if(!c)throw new Error(`Unknown pack object type: ${i}`);let f=await oe(t.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 Tn=new TextEncoder,Sn=new TextDecoder;function jn(n,e){let t=Tn.encode(`${n} ${e.byteLength}\0`),r=new Uint8Array(t.byteLength+e.byteLength);return r.set(t),r.set(e,t.byteLength),r}function Cn(n,e){let t=e.indexOf(0);if(t===-1)throw new Error(`Corrupt object ${n}: no null byte in header`);let r=Sn.decode(e.subarray(0,t)),s=r.indexOf(" ");if(s===-1)throw new Error(`Corrupt object ${n}: malformed header "${r}"`);let i=r.slice(0,s),o=parseInt(r.slice(s+1),10),a=e.subarray(t+1);if(a.byteLength!==o)throw new Error(`Corrupt object ${n}: expected ${o} bytes, got ${a.byteLength}`);return{type:i,content:a}}function _e(n,e){return v(n,"objects",e.slice(0,2),e.slice(2))}var We=class{constructor(e,t,r){this.fs=e;this.gitDir=t;this.cache=new Oe(r),this.packDir=v(t,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(e,t){let r=jn(e,t),s=await xe(r),i=_e(this.gitDir,s);if(await this.fs.exists(i))return s;let o=v(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(o,{recursive:!0}),await this.fs.writeFile(i,await Ne(r)),s}async read(e){let t=this.cache.get(e);if(t)return t;let r=_e(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await oe(s),o=Cn(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(_e(this.gitDir,e)))return!0;await this.discover();for(let t of this.packs)if(t.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=re(s);await this.fs.mkdir(this.packDir,{recursive:!0});let o=`pack-${i}`,a=v(this.packDir,`${o}.pack`);await this.fs.writeFile(a,e);let c=await Pt(e),f=v(this.packDir,`${o}.idx`);await this.fs.writeFile(f,c),this.loadedPackNames.add(o);let l=new ee(c);return this.packs.push({name:o,index:l,reader:new de(e,l)}),r}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(e){if(e.length<4)return[];let t=e.slice(0,2),r=e.slice(2),s=v(this.gitDir,"objects",t),i=[];if(await this.fs.exists(s)){let o=await this.fs.readdir(s);for(let a of o)a.startsWith(r)&&i.push(`${t}${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 t=v(this.packDir,`${e.name}.pack`),r=await this.fs.readFileBuffer(t);return e.reader=new de(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 t of e){if(!t.endsWith(".idx"))continue;let r=t.slice(0,-4);if(this.loadedPackNames.has(r))continue;let s=v(this.packDir,`${r}.pack`);if(!await this.fs.exists(s))continue;let i=await this.fs.readFileBuffer(v(this.packDir,t));this.loadedPackNames.add(r),this.packs.push({name:r,index:new ee(i),reader:null})}}};function ze(n){let e=n.indexOf("<"),t=n.indexOf(">");if(e===-1||t===-1)throw new Error(`Malformed identity line: "${n}"`);let r=n.slice(0,e).trimEnd(),s=n.slice(e+1,t),i=n.slice(t+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function Ve(n){return`${n.name} <${n.email}> ${n.timestamp} ${n.timezone}`}var An=new TextEncoder,$n=new TextDecoder;function Rt(n){let e=$n.decode(n),t=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 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(`
|
|
2
2
|
|
|
3
|
-
`),r=
|
|
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=
|
|
5
|
-
`))}async function
|
|
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
|
+
`)){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(`
|
|
5
|
+
`))}async function G(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function q(t,e){return t.objectStore.read(e)}function ee(t){let e=Math.min(t.length,8e3);for(let n=0;n<e;n++)if(t.charCodeAt(n)===0)return!0;return!1}var ir=new TextDecoder;async function _(t,e){let n=await q(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return ir.decode(n.content)}async function te(t,e){let n=await q(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function U(t,e){let n=await q(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return _t(n.content)}var Ie={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function Wt(t){return typeof t=="string"?{type:"direct",hash:t}:t}var st="ref: ",zt=10,it=class{constructor(e,n){this.fs=e;this.gitDir=n}casLocks=new Map;async readRef(e){let n=L(this.gitDir,e);if(await this.fs.exists(n)){let i=(await this.fs.readFile(n)).trim();return i.startsWith(st)?{type:"symbolic",target:i.slice(st.length)}:{type:"direct",hash:i}}let s=(await this.readPackedRefs()).get(e);return s?{type:"direct",hash:s}:null}async writeRef(e,n){let r=Wt(n),s=L(this.gitDir,e);await Vt(this.fs,s),r.type==="symbolic"?await this.fs.writeFile(s,`${st}${r.target}
|
|
6
6
|
`):await this.fs.writeFile(s,`${r.hash}
|
|
7
|
-
`)}async deleteRef(e){let
|
|
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
|
|
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(
|
|
10
|
-
`)):await this.fs.rm(
|
|
11
|
-
`,exitCode:128}}var Ks=At("not a git repository (or any of the parent directories): .git"),qs=At("this operation must be run in a work tree");function pe(n,e){return n<e?-1:n>e?1:0}var Te=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 t=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),t.entry}higher(e,t){let r=e.entry.commit.committer.timestamp,s=t.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<t.epoch}siftUp(e){let{heap:t}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(t[e],t[r]))break;[t[r],t[e]]=[t[e],t[r]],e=r}}siftDown(e){let{heap:t}=this,r=t.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(t[i],t[s])&&(s=i),o<r&&this.higher(t[o],t[s])&&(s=o),s===e)break;[t[e],t[s]]=[t[s],t[e]],e=s}}};async function*Ze(n,e,t){if(t?.topoOrder){yield*Dn(n,e,t);return}let r=await $t(n,t?.exclude),s=new Set(r),i=new Te,o=Array.isArray(e)?e:[e];for(let a of o)s.has(a)||i.push(await Se(n,a));for(;i.size>0;){let a=i.pop();if(!s.has(a.hash)){s.add(a.hash),yield a;for(let c of a.commit.parents)s.has(c)||i.push(await Se(n,c))}}}async function*Dn(n,e,t){let r=await $t(n,t?.exclude),s=new Set(r),i=new Te,o=Array.isArray(e)?e:[e];for(let d of o)s.has(d)||i.push(await Se(n,d));let a=[],c=new Map;for(;i.size>0;){let d=i.pop();if(!s.has(d.hash)){s.add(d.hash),c.set(d.hash,a.length),a.push(d);for(let h of d.commit.parents)s.has(h)||i.push(await Se(n,h))}}let f=a.length;if(f===0)return;let l=new Int32Array(f);for(let d of a)for(let h of d.commit.parents){let m=c.get(h);m!==void 0&&(l[m]=(l[m]??0)+1)}let u=[];for(let d=f-1;d>=0;d--)l[d]===0&&u.push(d);for(;u.length>0;){let d=u.pop();yield a[d];for(let h of a[d].commit.parents){let m=c.get(h);if(m!==void 0){let b=(l[m]??0)-1;l[m]=b,b===0&&u.push(m)}}}}async function $t(n,e){if(!e||e.length===0)return new Set;let t=new Set;for await(let r of Ze(n,e))t.add(r.hash);return t}async function Se(n,e){return{hash:e,commit:await U(n,e)}}var Bn=4,Mt=1024,je=100,$e=0,Ce=1,ce=2;function et(n){let e=1;for(;e*e<n;)e++;return e}function Hn(n,e){let t=new Map,r=[],s=new Array(n.length),i=new Array(e.length);for(let o=0;o<n.length;o++){let a=n[o],c=t.get(a);c===void 0&&(c=r.length,t.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=t.get(a);c===void 0&&(c=r.length,t.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function Nn(n,e,t,r){let s=0,i=Math.min(e,r);for(;s<i&&n[s]===t[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&n[e-1-a]===t[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function vt(n,e,t,r){e-t>je&&(t=e-je),r-e>je&&(r=e+je);let s=0,i=1;for(let c=1;e-c>=t;c++){let f=n[e-c];if(f===$e)s++;else if(f===ce)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let f=n[e+c];if(f===$e)o++;else if(f===ce)a++;else break}return o===0?!1:(o+=s,a+=i,a*Bn<a+o)}function Fn(n,e,t,r,s,i,o,a,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(et(e),Mt);for(let g=i;g<=o;g++){let w=s[n[g]].len2;w===0?l[g]=$e:w>=d?l[g]=ce:l[g]=Ce}let h=Math.min(et(r),Mt);for(let g=i;g<=a;g++){let w=s[t[g]].len1;w===0?u[g]=$e:w>=h?u[g]=ce:u[g]=Ce}let m=[];for(let g=i;g<=o;g++)l[g]===Ce||l[g]===ce&&!vt(l,g,i,o)?m.push(g):c[g]=1;let b=[];for(let g=i;g<=a;g++)u[g]===Ce||u[g]===ce&&!vt(u,g,i,a)?b.push(g):f[g]=1;return{refIndex1:m,nreff1:m.length,refIndex2:b,nreff2:b.length}}var te=20,Lt=4,Gn=256,_n=256,Ae=2147483647;function G(n,e){return n[e]??0}function Wn(n,e,t,r,s,i,o,a,c,f){let l=e-i,u=t-s,d=e-s,h=t-i,m=d-h&1,b=d,g=d,w=h,R=h;o[d]=e,a[h]=t;for(let j=1;;j++){let C=!1;b>l?o[--b-1]=-1:++b,g<u?o[++g+1]=-1:--g;for(let x=g;x>=b;x-=2){let I;G(o,x-1)>=G(o,x+1)?I=G(o,x-1)+1:I=G(o,x+1);let T=I,L=I-x;for(;I<t&&L<i&&n[I]===r[L];)I++,L++;if(I-T>te&&(C=!0),o[x]=I,m&&w<=x&&x<=R&&G(a,x)<=I)return{i1:I,i2:L,minLo:!0,minHi:!0}}w>l?a[--w-1]=Ae:++w,R<u?a[++R+1]=Ae:--R;for(let x=R;x>=w;x-=2){let I;G(a,x-1)<G(a,x+1)?I=G(a,x-1):I=G(a,x+1)-1;let T=I,L=I-x;for(;I>e&&L>s&&n[I-1]===r[L-1];)I--,L--;if(T-I>te&&(C=!0),a[x]=I,!m&&b<=x&&x<=g&&I<=G(o,x))return{i1:I,i2:L,minLo:!0,minHi:!0}}if(!c){if(C&&j>Gn){let x=0,I=null;for(let T=g;T>=b;T-=2){let L=T>d?T-d:d-T,A=G(o,T),E=A-T,$=A-e+(E-s)-L;if($>Lt*j&&$>x&&e+te<=A&&A<t&&s+te<=E&&E<i){let X=!0;for(let K=1;K<=te;K++)if(n[A-K]!==r[E-K]){X=!1;break}X&&(x=$,I={i1:A,i2:E,minLo:!0,minHi:!1})}}if(I)return I;x=0,I=null;for(let T=R;T>=w;T-=2){let L=T>h?T-h:h-T,A=G(a,T),E=A-T,$=t-A+(i-E)-L;if($>Lt*j&&$>x&&e<A&&A<=t-te&&s<E&&E<=i-te){let X=!0;for(let K=0;K<te;K++)if(n[A+K]!==r[E+K]){X=!1;break}X&&(x=$,I={i1:A,i2:E,minLo:!1,minHi:!0})}}if(I)return I}if(j>=f){let x=-1,I=-1;for(let A=g;A>=b;A-=2){let E=Math.min(G(o,A),t),$=E-A;i<$&&(E=i+A,$=i),x<E+$&&(x=E+$,I=E)}let T=Ae,L=Ae;for(let A=R;A>=w;A-=2){let E=Math.max(e,G(a,A)),$=E-A;$<s&&(E=s+A,$=s),E+$<T&&(T=E+$,L=E)}return t+i-T<x-(e+s)?{i1:I,i2:x-I,minLo:!0,minHi:!1}:{i1:L,i2:T-L,minLo:!1,minHi:!0}}}}}function tt(n,e,t,r,s,i,o,a,c,f,l,u,d,h){for(;e<t&&s<i&&n[e]===r[s];)e++,s++;for(;e<t&&s<i&&n[t-1]===r[i-1];)t--,i--;if(e===t)for(let m=s;m<i;m++)a[f[m]]=1;else if(s===i)for(let m=e;m<t;m++)o[c[m]]=1;else{let m=Wn(n,e,t,r,s,i,l,u,d,h);tt(n,e,m.i1,r,s,m.i2,o,a,c,f,l,u,m.minLo,h),tt(n,m.i1,t,r,m.i2,i,o,a,c,f,l,u,m.minHi,h)}}var Ut=200,Dt=20,Bt=100,zn=1,Vn=21,Kn=-30,qn=6,Yn=-4,Xn=10,Jn=24,Zn=17,Qn=23,er=17,tr=60;function Qe(n){let e=0;for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);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>=Ut)return Ut}return-1}function Ht(n,e,t){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};t>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=Qe(n[t]));for(let s=t-1;s>=0&&(r.preIndent=Qe(n[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===Dt){r.preIndent=0;break}for(let s=t+1;s<e&&(r.postIndent=Qe(n[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===Dt){r.postIndent=0;break}return r}function Nt(n,e){n.preIndent===-1&&n.preBlank===0&&(e.penalty+=zn),n.endOfFile&&(e.penalty+=Vn);let t=n.indent===-1?1+n.postBlank:0,r=n.preBlank+t;e.penalty+=Kn*r,e.penalty+=qn*t;let s=n.indent!==-1?n.indent:n.postIndent,i=r!==0;e.effectiveIndent+=s,s===-1||n.preIndent===-1||(s>n.preIndent?e.penalty+=i?Xn:Yn:s===n.preIndent||(n.postIndent!==-1&&n.postIndent>s?e.penalty+=i?Zn:Jn:e.penalty+=i?er:Qn))}function nr(n,e){let t=(n.effectiveIndent>e.effectiveIndent?1:0)-(n.effectiveIndent<e.effectiveIndent?1:0);return tr*t+(n.penalty-e.penalty)}function Ft(n,e,t,r,s,i){let o=0,a=0;for(;n[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(n[--o]=1,n[--a]=0;n[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(n[o++]=0,n[a++]=1;n[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(n[--a]=0,n[--o]=1;n[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,b={effectiveIndent:0,penalty:0},g=h;for(a-u-1>g&&(g=a-u-1),a-Bt>g&&(g=a-Bt);g<=a;g++){let w={effectiveIndent:0,penalty:0},R=Ht(t,r,g);Nt(R,w);let j=Ht(t,r,g-u);Nt(j,w),(m===-1||nr(w,b)<=0)&&(b={effectiveIndent:w.effectiveIndent,penalty:w.penalty},m=g)}for(;a>m;){for(n[--a]=0,n[--o]=1;n[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;n[a];a++);if(f>=i)break;for(c=f+1,f=c;s[f];f++);}}function Gt(n,e){let t=n.length,r=e.length,s=new Uint8Array(t),i=new Uint8Array(r);if(t>0&&r>0){let{classes1:o,classes2:a,classInfo:c}=Hn(n,e),{dstart:f,dend1:l,dend2:u}=Nn(o,t,a,r);if(f>l)for(let d=f;d<r-(t-1-l);d++)i[d]=1;else if(f>u)for(let d=f;d<t-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:b}=Fn(o,t,a,r,c,f,l,u,s,i);if(h>0&&b>0){let g=new Array(h);for(let I=0;I<h;I++)g[I]=o[d[I]];let w=new Array(b);for(let I=0;I<b;I++)w[I]=a[m[I]];let R={},j={},C=h+b+3,x=Math.max(_n,et(C));tt(g,0,h,w,0,b,s,i,d,m,R,j,!1,x)}else if(h===0)for(let g=0;g<b;g++)i[m[g]]=1;else for(let g=0;g<h;g++)s[d[g]]=1;Ft(s,o,n,t,i,r),Ft(i,a,e,r,s,t)}}else t===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function fe(n){let e=n.lastIndexOf("/");return e>=0?n.slice(e+1):n}function rr(n,e){if(n.length===0)return;if(n.length===1)return n.shift();let t=fe(e),r=0;for(let s=0;s<n.length;s++){let i=n[s];if(i&&fe(i.path)===t){r=s;break}}return n.splice(r,1)[0]}var sr=50;async function nt(n,e,t=sr){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=rr(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 ir(n,f,c,t);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 cr(n,f,c,t);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 ir(n,e,t,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let f=fe(c.path);s.has(f)?s.set(f,-1):s.set(f,a)}let i=new Map;for(let a=0;a<t.length;a++){let c=t[a];if(!c)continue;let f=fe(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=t[f];if(!l?.oldHash||!u?.newHash||l.oldHash===u.newHash)continue;let d=await Z(n,l.oldHash),h=await Z(n,u.newHash),m=ar(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 _t=107927;function Me(n){let e=new Map,t=0,r=0,s=0;for(let o=0;o<n.length;o++){let a=n[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,t++,t<64&&a!==10)continue;let f=(r+Math.imul(s,97))%_t;e.set(f,(e.get(f)??0)+t),t=0,r=0,s=0}if(t>0){let o=(r+Math.imul(s,97))%_t;e.set(o,(e.get(o)??0)+t)}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 or(n,e){let t=0,r=0,s=0,i=0;for(;s<n.length;){let o=n[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,t+=a):t+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:t,literalAdded:r}}function ar(n,e){return n.length===0&&e.length===0?100:n.length===0||e.length===0?0:Wt(n.length,Me(n),e.length,Me(e))}function Wt(n,e,t,r){let s=Math.max(n,t),i=Math.min(n,t);if(i<s-i)return 0;let{srcCopied:o}=or(e,r);return Math.floor(o*100/s)}async function cr(n,e,t,r){let s=[];for(let l of e)if(l.oldHash){let u=await Z(n,l.oldHash);s.push({size:u.length,chunks:Me(u)})}else s.push(null);let i=[];for(let l of t)if(l.newHash){let u=await Z(n,l.newHash);i.push({size:u.length,chunks:Me(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<t.length;h++){let m=t[h],b=i[h];if(!m||!b)continue;let g=Wt(d.size,d.chunks,b.size,b.chunks);if(g>=r){let w=fe(u.path)===fe(m.path)?1:0;o.push({similarity:g,nameScore:w,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=t[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 fr(n,e){let t=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(t.has(i))continue;t.add(i);let o=await U(n,i);for(let a of o.parents)t.has(a)||r.push(a)}return t}async function rt(n,e,t){if(e===t)return!0;let r=new Set,s=[t],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=await U(n,o);for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function ge(n,e,t){if(e===t)return[e];let r=await fr(n,e),s=[],i=new Set,o=[t],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=await U(n,f);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 rt(n,f,u)){l=!0;break}l||c.push(f)}return c.length<=1?c:lr(n,e,t,c)}async function lr(n,e,t,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:t,mask:2,seq:f++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await U(n,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 j=l[R],C=await u(j.hash),x=l[d];(C>h||C===h&&j.seq<x.seq)&&(d=R,h=C)}let m=l.splice(d,1)[0],b=a.get(m.hash)??0,g=b|m.mask;if(g===b)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 w=await U(n,m.hash);for(let R of w.parents)l.push({hash:R,mask:g,seq:f++})}for(let d of r)i.has(d)||o.push(d);return o}function st(n,e){let t=n.length,r=e.length;if(t===0&&r===0)return[];if(t===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,t],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=Gt(n,e);return ur(s,t,i,r)}function ur(n,e,t,r){let s=[],i=0,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!n[i]&&!t[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&n[i];)i++;for(;o<r&&t[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function hr(n,e,t){let r=[];for(let c of st(e,n))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of st(e,t))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"?n:t;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:n.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1}};for(let w of u){let R=w.oStart,j=R+w.oLength,C=w.abStart,x=C+w.abLength,I=d[w.ab];I.abMin=Math.min(C,I.abMin),I.abMax=Math.max(x,I.abMax),I.oMin=Math.min(R,I.oMin),I.oMax=Math.max(j,I.oMax)}let h=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(l-d.a.oMax),b=d.b.abMin+(f-d.b.oMin),g=d.b.abMax+(l-d.b.oMax);s.push({stable:!1,a:n.slice(h,m),o:e.slice(f,l),b:t.slice(b,g)})}i=l}return o(e.length),s}function dr(n,e,t,r){let s=r?.excludeFalseConflicts??!0,i=hr(n,e,t),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&&zt(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),gr(mr(o))}function be(n,e,t,r){let s=r?.markerSize??7,i=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,o="=".repeat(s),a=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,c=dr(n,e,t),f=!1,l=[];for(let u of c)u.type==="ok"?l.push(...u.lines):(f=!0,l.push(i,...u.a,o,...u.b,a));return{conflict:f,result:l}}function mr(n){let e=[];for(let t of n)t.type==="ok"?e.push(t):e.push(...pr(t));return e}function pr(n){let{a:e,b:t}=n;if(e.length===0||t.length===0)return[n];if(zt(e,t))return[n];let r=st(e,t);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:t.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"?[n]:s}function gr(n){if(n.length<3)return n;let e=[n[0]];for(let r=1;r<n.length;r++){let s=e[e.length-1],i=n[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let t=[e[0]];for(let r=1;r<e.length;r++){let s=t[t.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 t.push(i)}return t}function ie(n,e,t,r){let s=be(W(n),W(e),W(t),{a:r.a,b:r.b,markerSize:r.markerSize}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(it);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
|
|
7
|
+
`)}async deleteRef(e){let n=L(this.gitDir,e);await this.fs.exists(n)&&await this.fs.rm(n),await this.removePackedRef(e)}async listRefs(e="refs"){let n=[],r=L(this.gitDir,e);await this.fs.exists(r)&&await this.walkRefs(r,e,n);let s=await this.readPackedRefs();if(s.size>0){let i=new Set(n.map(a=>a.name)),o=`${e}/`;for(let[a,c]of s)a.startsWith(o)&&!i.has(a)&&n.push({name:a,hash:c})}return n.sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async compareAndSwapRef(e,n,r){let i=(this.casLocks.get(e)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(e,n,r),()=>this.compareAndSwapUnsafe(e,n,r));this.casLocks.set(e,i);try{return await i}finally{this.casLocks.get(e)===i&&this.casLocks.delete(e)}}async compareAndSwapUnsafe(e,n,r){let s=await this.resolveRefInternal(e);if(n===null){if(await this.readRef(e)!==null)return!1}else if(s!==n)return!1;return r===null?await this.deleteRef(e):await this.writeRef(e,r),!0}async resolveRefInternal(e){let n=e;for(let r=0;r<zt;r++){let s=await this.readRef(n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async readPackedRefs(){let e=L(this.gitDir,"packed-refs");if(!await this.fs.exists(e))return new Map;let n=await this.fs.readFile(e),r=new Map;for(let s of n.split(`
|
|
8
|
+
`)){if(!s||s.startsWith("#")||s.startsWith("^"))continue;let i=s.indexOf(" ");if(i===-1)continue;let 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
|
+
`),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
|
+
`)):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(`
|
|
12
12
|
`)}
|
|
13
13
|
`:a.join(`
|
|
14
|
-
`)}function
|
|
15
|
-
`);if(e[e.length-1]==="")e.pop();else{let t=e[e.length-1]??"";e[e.length-1]=`${t}\0`}return e}function it(n){return n.endsWith("\0")?n.slice(0,-1):n}function zt(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}var le=new TextDecoder,ne=new TextEncoder,Vt={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function ue(n,e,t,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await br(n,e,t,r),f=await wr(n,i,o,a,c,s);return Ir(n,i,s,f)}async function Qt(n,e,t,r){let s=await ge(n,e,t),i=await U(n,e),o=await U(n,t);if(s.length===0)return{...await ue(n,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let f=await U(n,s[0]);return{...await ue(n,f.tree,i.tree,o.tree,r),baseTree:f.tree}}let a=await tn(n,e,t,s,1);return{...await ue(n,a,i.tree,o.tree,r),baseTree:a}}async function br(n,e,t,r){let s=await ae(n,e),i=await ae(n,t),o=await ae(n,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,b=d?{hash:d.hash,mode:d.mode}:null,g=(l?1:0)|(u?2:0)|(d?4:0),w=l?.hash??null,R=u?.hash??null,j=d?.hash??null,C=0;w!==null&&w===R&&(C|=3),w!==null&&w===j&&(C|=5),R!==null&&R===j&&(C|=6);let x={path:f,stages:[h,m,b],pathnames:[f,f,f],filemask:g,matchMask:C,merged:{result:null,clean:!1},pathConflict:!1};if(yr(x)){c.set(f,x);continue}c.set(f,x)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function yr(n){let[e,t,r]=n.stages,s=e?.hash??null,i=t?.hash??null,o=r?.hash??null;return i===s&&o===s?(t?n.merged={result:{hash:i,mode:t.mode},clean:!0}:n.merged={result:null,clean:!0},!0):i===o&&i!==null?(n.merged={result:{hash:i,mode:t.mode},clean:!0},!0):i===null&&o===null?(n.merged={result:null,clean:!0},!0):o===s&&i!==s?(t?n.merged={result:{hash:i,mode:t.mode},clean:!0}:n.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?n.merged={result:{hash:o,mode:r.mode},clean:!0}:n.merged={result:null,clean:!0},!0):!1}async function wr(n,e,t,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[y,p]of t)r.has(y)||a.push({path:y,status:"deleted",oldHash:p.hash,oldMode:p.mode}),s.has(y)||c.push({path:y,status:"deleted",oldHash:p.hash,oldMode:p.mode});for(let[y,p]of r)t.has(y)||a.push({path:y,status:"added",newHash:p.hash,newMode:p.mode});for(let[y,p]of s)t.has(y)||c.push({path:y,status:"added",newHash:p.hash,newMode:p.mode});let f=await nt(n,a),l=await nt(n,c);if(f.renames.length===0&&l.renames.length===0)return o;let u=new Map,d=new Map;for(let y of f.renames)u.set(y.oldPath,y);for(let y of l.renames)d.set(y.oldPath,y);let h=new Set;for(let[y]of r)!t.has(y)&&s.has(y)&&h.add(y);let m=new Set,b=i?.a??"HEAD",g=i?.b??"theirs";function w(y,p,O=0){o.msgBuf.push({sortKey:y,subOrder:O,text:p})}for(let y of[...t.keys()].sort()){let p=u.get(y),O=d.get(y);if(!p&&!O)continue;let S=t.get(y);if(m.add(y),p&&O)if(m.add(p.newPath),m.add(O.newPath),p.newPath===O.newPath){let k=r.get(p.newPath),P=s.get(O.newPath);if(k.hash===P.hash)o.entries.push(_(p.newPath,k));else{let D=ot(e,p.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],D.pathnames=[y,p.newPath,O.newPath],D.filemask=7,D.merged={result:null,clean:!1}}}else{let k=r.get(p.newPath),P=s.get(O.newPath),D=await en(n,S,k,P,i);D.conflict&&w(y,`Auto-merging ${y}`,-1),o.conflicts.push({path:y,reason:"rename-rename",oursPath:p.newPath,theirsPath:O.newPath}),w(y,`CONFLICT (rename/rename): ${y} renamed to ${p.newPath} in ${b} and to ${O.newPath} in ${g}.`),o.entries.push(_(y,S,1)),o.entries.push(H(p.newPath,k.mode,D.hash,2)),o.entries.push(H(O.newPath,P.mode,D.hash,3)),o.worktreeBlobs.set(p.newPath,{hash:D.hash,mode:k.mode}),o.worktreeBlobs.set(O.newPath,{hash:D.hash,mode:P.mode})}else if(p){m.add(p.newPath);let k=s.get(y),P=r.get(p.newPath),D=h.has(p.newPath);if(k)if(D)await Zt(n,o,p.newPath,y,S,P,k,r,s,!1,i);else if(k.hash===S.hash&&P.hash===S.hash)o.entries.push(_(p.newPath,P));else if(k.hash===S.hash)o.entries.push(_(p.newPath,P));else if(P.hash===S.hash)o.entries.push(H(p.newPath,P.mode,k.hash));else{let B=ot(e,p.newPath);B.stages=[{hash:S.hash,mode:S.mode},{hash:P.hash,mode:P.mode},{hash:k.hash,mode:k.mode}],B.pathnames=[y,p.newPath,y],B.filemask=7,B.merged={result:null,clean:!1}}else{let B=s.get(p.newPath);if(o.conflicts.push({path:p.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:y}),w(p.newPath,`CONFLICT (rename/delete): ${y} renamed to ${p.newPath} in ${b}, but deleted in ${g}.`),B){o.conflicts.push({path:p.newPath,reason:"add-add"}),w(p.newPath,`Auto-merging ${p.newPath}`,0),w(p.newPath,`CONFLICT (add/add): Merge conflict in ${p.newPath}`,1),o.entries.push(_(p.newPath,P,2)),o.entries.push(_(p.newPath,B,3));let Le=await ve(n,P.hash,B.hash,P.mode,i);o.worktreeBlobs.set(p.newPath,{hash:Le,mode:P.mode})}else o.entries.push(H(p.newPath,S.mode,S.hash,1)),o.entries.push(_(p.newPath,P,2)),o.worktreeBlobs.set(p.newPath,{hash:P.hash,mode:P.mode}),P.hash!==S.hash&&w(p.newPath,`CONFLICT (modify/delete): ${p.newPath} deleted in ${g} and modified in ${b}. Version ${b} of ${p.newPath} left in tree.`,1)}}else if(O){m.add(O.newPath);let k=r.get(y),P=s.get(O.newPath),D=h.has(O.newPath);if(k)if(D)await Zt(n,o,O.newPath,y,S,k,P,r,s,!0,i);else if(k.hash===S.hash&&P.hash===S.hash)o.entries.push(_(O.newPath,P));else if(k.hash===S.hash)o.entries.push(_(O.newPath,P));else if(P.hash===S.hash)o.entries.push(H(O.newPath,P.mode,k.hash));else{let B=ot(e,O.newPath);B.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],B.pathnames=[y,y,O.newPath],B.filemask=7,B.merged={result:null,clean:!1}}else{let B=r.get(O.newPath);if(o.conflicts.push({path:O.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:y}),w(O.newPath,`CONFLICT (rename/delete): ${y} renamed to ${O.newPath} in ${g}, but deleted in ${b}.`),B){o.conflicts.push({path:O.newPath,reason:"add-add"}),w(O.newPath,`Auto-merging ${O.newPath}`,0),w(O.newPath,`CONFLICT (add/add): Merge conflict in ${O.newPath}`,1),o.entries.push(_(O.newPath,B,2)),o.entries.push(_(O.newPath,P,3));let Le=await ve(n,B.hash,P.hash,B.mode,i);o.worktreeBlobs.set(O.newPath,{hash:Le,mode:B.mode})}else o.entries.push(H(O.newPath,S.mode,S.hash,1)),o.entries.push(_(O.newPath,P,3)),o.worktreeBlobs.set(O.newPath,{hash:P.hash,mode:P.mode}),P.hash!==S.hash&&w(O.newPath,`CONFLICT (modify/delete): ${O.newPath} deleted in ${b} and modified in ${g}. Version ${g} of ${O.newPath} left in tree.`,1)}}}let R=new Set(f.renames.map(y=>y.newPath)),j=new Set(l.renames.map(y=>y.newPath)),C=Kt(t,r),x=Kt(t,s),I=qt(C,s,t),T=qt(x,r,t),L=Yt(f.renames,I),A=Yt(l.renames,T),E=Xt(L),$=Xt(A);for(let y of[...E.keys()])$.has(y)&&(E.delete(y),$.delete(y));let X=new Set(E.keys()),K=new Set($.keys());if($.size>0)for(let y of a){if(y.status!=="added"||R.has(y.path))continue;let p=Jt(y.path,$,X);if(!p)continue;if(e.has(p)||t.has(p)||r.has(p)||s.has(p)){if(r.has(p)){w(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${y.path}.`,1);continue}let k=r.get(y.path),P=s.get(p)??t.get(p);o.entries.push(H(p,k.mode,k.hash,2)),P&&o.entries.push(H(p,P.mode,P.hash,3)),o.worktreeBlobs.set(p,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:p,reason:"add-add"}),w(p,`CONFLICT (file location): ${y.path} added in ${b} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,1);let D=e.get(y.path);D&&(D.merged={result:null,clean:!0}),m.add(y.path);continue}let O=r.get(y.path);o.entries.push(H(p,O.mode,O.hash,2)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),w(p,`CONFLICT (file location): ${y.path} added in ${b} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,1);let S=e.get(y.path);S&&(S.merged={result:null,clean:!0}),m.add(y.path)}if(E.size>0)for(let y of c){if(y.status!=="added"||j.has(y.path))continue;let p=Jt(y.path,E,K);if(!p)continue;if(e.has(p)||t.has(p)||r.has(p)||s.has(p)){if(s.has(p)){w(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${y.path}.`,1);continue}let k=s.get(y.path),P=r.get(p)??t.get(p);P&&o.entries.push(H(p,P.mode,P.hash,2)),o.entries.push(H(p,k.mode,k.hash,3)),o.worktreeBlobs.set(p,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:p,reason:"add-add"}),w(p,`CONFLICT (file location): ${y.path} added in ${g} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${p}.`,1);let D=e.get(y.path);D&&(D.merged={result:null,clean:!0}),m.add(y.path);continue}let O=s.get(y.path);o.entries.push(H(p,O.mode,O.hash,3)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),w(p,`CONFLICT (file location): ${y.path} added in ${g} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${p}.`,1);let S=e.get(y.path);S&&(S.merged={result:null,clean:!0}),m.add(y.path)}let lt=new Set(o.entries.map(y=>y.path));for(let y of lt){let p=e.get(y);p&&(p.merged={result:null,clean:!0})}for(let y of m){if(lt.has(y))continue;let p=e.get(y);if(!p||p.merged.clean)continue;p.filemask===7&&!p.pathConflict||(p.merged={result:null,clean:!0})}return o}function Kt(n,e){let t=new Set;for(let i of n.keys()){let o=z(i);for(;o;)t.add(o),o=z(o)}let r=new Set;for(let i of e.keys()){let o=z(i);for(;o;)r.add(o),o=z(o)}let s=new Set;for(let i of t)r.has(i)||s.add(i);return s}function qt(n,e,t){if(n.size===0)return n;let r=new Set;for(let s of e.keys()){if(t.has(s))continue;let i=z(s)??"";n.has(i)&&r.add(i)}for(let s of[...r]){let i=z(s);for(;i;)n.has(i)&&!r.has(i)&&r.add(i),i=z(i)}return r}function Yt(n,e){let t=new Map;for(let r of n){let s=z(r.oldPath),i=z(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=t.get(s);a||(a=new Map,t.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=z(s),i=z(i)}}return t}function Xt(n){let e=new Map;for(let[t,r]of n){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(t,o)}return e}function Jt(n,e,t){let r=z(n);for(;r;){let i=e.get(r);if(i!==void 0){if(t.has(i))return null;let o=n.slice(r.length+1);return i?`${i}/${o}`:o}r=z(r)}let s=e.get("");return s!==void 0&&!t.has(s)?`${s}/${n}`:null}function z(n){let e=n.lastIndexOf("/");return e===-1?"":n.slice(0,e)}async function Zt(n,e,t,r,s,i,o,a,c,f=!1,l){let u=f?a.get(t):c.get(t),d=f?o:i;if(u.hash===d.hash){e.entries.push(H(t,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await en(n,s,i,o,l,f?{oursPath:r,theirsPath:t}:{oursPath:t,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(H(t,u.mode,m.hash));else if(e.conflicts.push({path:t,reason:"add-add"}),e.msgBuf.push({sortKey:t,subOrder:0,text:`Auto-merging ${t}`}),e.msgBuf.push({sortKey:t,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${t}`}),f){e.entries.push(_(t,u,2)),e.entries.push(H(t,o.mode,m.hash,3));let b=await ve(n,u.hash,m.hash,u.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:u.mode})}else{e.entries.push(H(t,i.mode,m.hash,2)),e.entries.push(_(t,u,3));let b=await ve(n,m.hash,u.hash,i.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:i.mode})}}async function en(n,e,t,r,s,i,o){if(t.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:t.hash,conflict:!1};if(t.hash===r.hash)return{hash:t.hash,conflict:!1};if(Y(e.mode)||Y(t.mode)||Y(r.mode))return{hash:t.hash,conflict:!0};let a=await F(n,e.hash),c=await F(n,t.hash),f=await F(n,r.hash);if(J(c)||J(f)||J(a))return{hash:t.hash,conflict:!0};let l=W(a),u=W(c),d=W(f),h=be(u,l,d);if(!h.conflict)return{hash:await at(n,h.result),conflict:!1};let m=s?.a??"HEAD",b=s?.b??"theirs",g=i?.oursPath?`${m}:${i.oursPath}`:m,w=i?.theirsPath?`${b}:${i.theirsPath}`:b,R=ie(c,a,f,{a:g,b:w,markerSize:o??7});return{hash:await N(n,"blob",ne.encode(R)),conflict:!0}}async function ve(n,e,t,r,s){let i=await F(n,e),o=await F(n,t),a=ie(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs"});return N(n,"blob",ne.encode(a))}function _(n,e,t=0){return H(n,e.mode,e.hash,t)}function H(n,e,t,r=0){return{path:n,mode:parseInt(e,8),hash:t,stage:r,stat:Q()}}async function Ir(n,e,t,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,b=0){o.push({sortKey:h,subOrder:b,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(M(h,m.merged.result.hash,m.merged.result.mode));continue}await xr(n,m,t,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(M(h,m.hash,m.mode));l.sort((h,m)=>pe(h.path,m.path));let d=await Xe(n,l);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function xr(n,e,t,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=t?.a??"HEAD",b=t?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${b}. Version ${b} of ${a} left in tree.`),c&&r.push(M(a,u,c.mode,1)),r.push(M(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=t?.b??"theirs",b=t?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${b}. Version ${b} of ${a} left in tree.`),c&&r.push(M(a,u,c.mode,1)),r.push(M(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(M(a,d,f.mode));return}i(a,`Auto-merging ${a}`,0);let m=await F(n,d),b=await F(n,h);if(J(m)||J(b)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${t?.a??"HEAD"} vs. ${t?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let g=W(""),w=W(m),R=W(b),j=be(w,g,R,t);if(!j.conflict){let I=await at(n,j.result);r.push(M(a,I,f.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3));let C=ie(m,"",b,{a:t?.a??"HEAD",b:t?.b??"theirs"}),x=await N(n,"blob",ne.encode(C));o.set(a,{hash:x,mode:f.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(M(a,h,l.mode));return}if(h===u){r.push(M(a,d,f.mode));return}if(d===h){r.push(M(a,d,f.mode));return}if(i(a,`Auto-merging ${a}`,0),Y(c.mode)||Y(f.mode)||Y(l.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let m=await F(n,u),b=await F(n,d),g=await F(n,h);if(J(b)||J(g)||J(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${t?.a??"HEAD"} vs. ${t?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let w=W(m),R=W(b),j=W(g),C=be(R,w,j,t);if(C.conflict){let x=e.pathnames[1],I=e.pathnames[2],T=x!==a||I!==a,L={path:a,reason:"content"};T&&(x!==a&&(L.oursOrigPath=x),I!==a&&(L.theirsOrigPath=I)),s.push(L),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3));let A=T?`${t?.a??"HEAD"}:${x}`:t?.a??"HEAD",E=T?`${t?.b??"theirs"}:${I}`:t?.b??"theirs",$=ie(b,m,g,{a:A,b:E}),X=await N(n,"blob",ne.encode($));o.set(a,{hash:X,mode:f.mode})}else{let x=await at(n,C.result);r.push(M(a,x,f.mode))}return}}var Or=200;async function tn(n,e,t,r,s){let i=await Promise.all(r.map(async l=>({hash:l,timestamp:(await U(n,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(n,a)).tree;for(let l=1;l<o.length;l++){let u=o[l],d=(await U(n,u)).tree,h=null;if(s>=Or)h=f;else{let g=await ge(n,c,u);g.length===0?h=null:g.length===1?h=(await U(n,g[0])).tree:h=await tn(n,c,u,g,s+1)}let m=await ue(n,h,f,d);f=await Pr(n,m,s);let b=Re({type:"commit",tree:f,parents:[c,u],author:Vt,committer:Vt,message:"merged common ancestors"});c=await N(n,"commit",b)}return f}async function Pr(n,e,t){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+t*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 b=le.decode((await V(n,h.hash)).content),g=le.decode((await V(n,m.hash)).content),w=d?le.decode((await V(n,d.hash)).content):"",R=8+t*2,j=o.a??"Temporary merge branch 1",C=o.b??"Temporary merge branch 2",x=ie(b,w,g,{a:`${j}:${l}`,o:o.o,b:`${C}:${u}`,markerSize:R}),I=await N(n,"blob",ne.encode(x));r.push({path:l,mode:h.mode,hash:I,stage:0,stat:Q()}),r.push({path:u,mode:m.mode,hash:I,stage:0,stat:Q()});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=le.decode((await V(n,c.hash)).content),u=le.decode((await V(n,f.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?le.decode((await V(n,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,b=o.a??"Temporary merge branch 1",g=o.b??"Temporary merge branch 2",w=m?`${b}:${a.oursOrigPath??a.path}`:b,R=m?`${g}:${a.theirsOrigPath??a.path}`:g,j=ie(l,h,u,{a:w,o:o.o,b:R,markerSize:o.markerSize}),C=await N(n,"blob",ne.encode(j));r.push({path:a.path,mode:c.mode,hash:C,stage:0,stat:Q()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>pe(a.path,c.path)),Xe(n,r)}async function at(n,e){let t=e.map(it);if(t.length===0)return N(n,"blob",ne.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?t.join(`
|
|
16
|
-
`):`${
|
|
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(`
|
|
16
|
+
`):`${n.join(`
|
|
17
17
|
`)}
|
|
18
|
-
`;return
|
|
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};
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as GitRepo, Z as Rejection } from '../hooks-Boa35Qx_.js';
|
|
2
2
|
|
|
3
3
|
interface GitServerConfig {
|
|
4
4
|
/**
|
|
@@ -249,6 +249,30 @@ declare function ingestReceivePack(repo: GitRepo, requestBody: Uint8Array): Prom
|
|
|
249
249
|
* Opinionated hook presets built on top of the minimal ServerHooks interface.
|
|
250
250
|
*/
|
|
251
251
|
|
|
252
|
+
type ResolveRepo = GitServerConfig["resolveRepo"];
|
|
253
|
+
/**
|
|
254
|
+
* Wrap a `resolveRepo` function with an authorization check that
|
|
255
|
+
* gates **all** access (clone, fetch, and push).
|
|
256
|
+
*
|
|
257
|
+
* The `authorize` callback receives the raw `Request` and returns:
|
|
258
|
+
* - `true` — request is allowed, delegate to the inner `resolveRepo`
|
|
259
|
+
* - `false` — respond with 403 Forbidden
|
|
260
|
+
* - `Response` — send as-is (e.g. 401 with `WWW-Authenticate` header)
|
|
261
|
+
*
|
|
262
|
+
* For push-only authorization, use `createStandardHooks({ authorizePush })`.
|
|
263
|
+
* The two compose naturally:
|
|
264
|
+
*
|
|
265
|
+
* ```ts
|
|
266
|
+
* const server = createGitServer({
|
|
267
|
+
* resolveRepo: withAuth(
|
|
268
|
+
* (req) => req.headers.get("Authorization") === `Bearer ${token}`,
|
|
269
|
+
* (repoPath) => storage.repo(repoPath),
|
|
270
|
+
* ),
|
|
271
|
+
* hooks: createStandardHooks({ protectedBranches: ["main"] }),
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
declare function withAuth(authorize: (request: Request) => boolean | Response | Promise<boolean | Response>, resolveRepo: ResolveRepo): ResolveRepo;
|
|
252
276
|
interface StandardHooksConfig {
|
|
253
277
|
/** Branches that cannot be force-pushed to or deleted. */
|
|
254
278
|
protectedBranches?: string[];
|
|
@@ -421,4 +445,4 @@ declare class PgStorage implements Storage {
|
|
|
421
445
|
deleteRepo(repoId: string): Promise<void>;
|
|
422
446
|
}
|
|
423
447
|
|
|
424
|
-
export { type AdvertiseRefsEvent, type BetterSqlite3Database, type BetterSqlite3Statement, type GitServer, type GitServerConfig, MemoryStorage, type NodeHttpRequest, type NodeHttpResponse, PackCache, type PgDatabase, type PgPool, type PgPoolClient, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type ReceivePackResult, type RefAdvertisement, type RefUpdate, type RefsData, Rejection, type ServerHooks, type SqliteDatabase, type SqliteStatement, SqliteStorage, type StandardHooksConfig, type Storage, type UpdateEvent, type UploadPackOptions, buildRefAdvertisementBytes, collectRefs, composeHooks, createGitServer, createStandardHooks, handleUploadPack, ingestReceivePack, toNodeHandler, wrapBetterSqlite3, wrapPgPool };
|
|
448
|
+
export { type AdvertiseRefsEvent, type BetterSqlite3Database, type BetterSqlite3Statement, type GitServer, type GitServerConfig, MemoryStorage, type NodeHttpRequest, type NodeHttpResponse, PackCache, type PgDatabase, type PgPool, type PgPoolClient, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type ReceivePackResult, type RefAdvertisement, type RefUpdate, type RefsData, Rejection, type ServerHooks, type SqliteDatabase, type SqliteStatement, SqliteStorage, type StandardHooksConfig, type Storage, type UpdateEvent, type UploadPackOptions, buildRefAdvertisementBytes, collectRefs, composeHooks, createGitServer, createStandardHooks, handleUploadPack, ingestReceivePack, toNodeHandler, withAuth, wrapBetterSqlite3, wrapPgPool };
|