just-git 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -69
- package/dist/index.d.ts +26 -1
- package/dist/index.js +197 -197
- package/dist/repo/index.js +7 -7
- package/dist/server/index.js +22 -22
- package/package.json +2 -2
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 tn(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===""?".":tn(e)}function ve(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 se(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 nn=new TextEncoder;function Le(n){return typeof n=="string"?nn.encode(n):n}function rn(){if(typeof globalThis.Bun<"u")return()=>{let n=new Bun.CryptoHasher("sha1"),e={update(t){return n.update(Le(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(Le(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(Le(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 se(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=rn(),Ie=ht;async function xe(n){return ht().update(n).hex()}var sn=1145655875,on=2;async function Ue(n,e){let t=v(n.gitDir,"index"),r=await an(e);await n.fs.writeFile(t,r)}function dt(n){let e=[...n].sort(mt);return{version:on,entries:e}}function ee(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function an(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,sn),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 cn=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(!cn.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}function fn(){try{let n=ye(["node","zlib"].join(":"));if(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 Promise.resolve({result:new Uint8Array(s.buffer),bytesConsumed:s.engine.bytesWritten})})}catch{}return{deflate:t=>Promise.resolve(new Uint8Array(n.deflateSync(t))),inflate:t=>Promise.resolve(new Uint8Array(n.inflateSync(t))),inflateWithConsumed:e}}}catch{}if(typeof globalThis.CompressionStream=="function"&&typeof globalThis.DecompressionStream=="function")return{async deflate(n){let e=new CompressionStream("deflate"),t=e.writable.getWriter();return t.write(n),t.close(),new Uint8Array(await new Response(e.readable).arrayBuffer())},async inflate(n){let e=new DecompressionStream("deflate"),t=e.writable.getWriter();return t.write(n),t.close(),new Uint8Array(await new Response(e.readable).arrayBuffer())}};throw new Error("No zlib implementation available. Requires Bun, Node.js, Deno, or a browser with CompressionStream.")}var Be=fn(),De=Be.deflate,J=Be.inflate,He=Be.inflateWithConsumed;var bt=1346454347,ln=2,un=1,hn=2,dn=3,mn=4,Pe=6,Fe=7,pn={[un]:"commit",[hn]:"tree",[dn]:"blob",[mn]:"tag"};async function wt(n,e){let t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=t.getUint32(0);if(r!==bt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${bt.toString(16)})`);let s=t.getUint32(4);if(s!==ln)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 gn(n,a);o.push(l),a=l.nextOffset}return(await bn(o,e)).map((f,l)=>({...f,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function gn(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===Fe&&(c=we(n,e),e+=20);let{result:f,bytesConsumed:l}=await wn(n,e,i);return{headerOffset:t,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+l}}async function bn(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!==Fe){let d=pn[a.typeNum];if(!d)throw new Error(`Unknown object type: ${a.typeNum}`);let h={type:d,content:a.inflated,hash:await Ne(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 Ne(h.type,m)};return r[i]=b,b}let c=await yn(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 Ne(f.type,l)};return r[i]=u,u}for(let i=0;i<n.length;i++)await s(i);return r}async function yn(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!==Fe&&(await r(s)).hash===t)return s}}function he(n,e){let t=0,{value:r,newPos:s}=yt(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}=yt(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 yt(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}}async function wn(n,e,t){let r=n.subarray(e);if(He){let{result:a,bytesConsumed:c}=await He(r);if(a.byteLength!==t)throw new Error(`Inflate size mismatch: got ${a.byteLength}, expected ${t}`);return{result:a,bytesConsumed:c}}let s=await J(r);if(s.byteLength!==t)throw new Error(`Inflate size mismatch: got ${s.byteLength}, expected ${t}`);let i=2,o=r.byteLength;for(;i<o;){let a=i+o>>>1;try{(await J(r.subarray(0,a))).byteLength===t?o=a:i=a+1}catch{i=a+1}}return{result:s,bytesConsumed:i}}var In=new TextEncoder;async function Ne(n,e){let t=In.encode(`${n} ${e.byteLength}\0`),r=Ie();return r.update(t),r.update(e),r.hex()}var It=4285812579,xt=2,te=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0)!==It)throw new Error("Invalid pack index: bad magic");if(t.getUint32(4)!==xt)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 xn(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,It),c+=4,a.setUint32(c,xt),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 Ot(n){let t=(await wt(n)).map(s=>({hash:s.hash,offset:s.offset,crc:gt(n.subarray(s.offset,s.nextOffset))})),r=n.subarray(n.byteLength-20);return xn(t,r)}var On=6,Pn=7,Rn={1:"commit",2:"tree",3:"blob",4:"tag"},de=class{constructor(e,t){this.data=e;this.index=t instanceof te?t:new te(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===On){let l=t[r++],u=l&127;for(;l&128;)u+=1,l=t[r++],u=(u<<7)+(l&127);let d=await J(t.subarray(r)),h=await this.readAt(e-u);return{type:h.type,content:he(h.content,d)}}if(i===Pn){let l=we(t,r);r+=20;let u=await J(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=Rn[i];if(!c)throw new Error(`Unknown pack object type: ${i}`);let f=await J(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 kn=new TextEncoder,En=new TextDecoder;function Tn(n,e){let t=kn.encode(`${n} ${e.byteLength}\0`),r=new Uint8Array(t.byteLength+e.byteLength);return r.set(t),r.set(e,t.byteLength),r}function Sn(n,e){let t=e.indexOf(0);if(t===-1)throw new Error(`Corrupt object ${n}: no null byte in header`);let r=En.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 Ge(n,e){return v(n,"objects",e.slice(0,2),e.slice(2))}var _e=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=Tn(e,t),s=await xe(r),i=Ge(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 De(r)),s}async read(e){let t=this.cache.get(e);if(t)return t;let r=Ge(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await J(s),o=Sn(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(Ge(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=se(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 Ot(e),f=v(this.packDir,`${o}.idx`);await this.fs.writeFile(f,c),this.loadedPackNames.add(o);let l=new te(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 te(i),reader:null})}}};function We(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 ze(n){return`${n.name} <${n.email}> ${n.timestamp} ${n.timezone}`}var jn=new TextEncoder,Cn=new TextDecoder;function Pt(n){let e=Cn.decode(n),t=e.indexOf(`
|
|
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 tn(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===""?".":tn(e)}function ve(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 lt=(()=>{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+=lt[n[t]];return e}function we(n,e){let t="";for(let r=0;r<20;r++)t+=lt[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 nn=new TextEncoder;function Le(n){return typeof n=="string"?nn.encode(n):n}function rn(){if(typeof globalThis.Bun<"u")return()=>{let n=new Bun.CryptoHasher("sha1"),e={update(t){return n.update(Le(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(Le(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(Le(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 ut=rn(),Ie=ut;async function xe(n){return ut().update(n).hex()}var sn=1145655875,on=2;async function Ue(n,e){let t=v(n.gitDir,"index"),r=await an(e);await n.fs.writeFile(t,r)}function ht(n){let e=[...n].sort(dt);return{version:on,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 an(n){let e=[...n.entries].sort(dt),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,sn),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 dt(n,e){return n.path<e.path?-1:n.path>e.path?1:n.stage-e.stage}var cn=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(!cn.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 mt=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;mt[n]=e}function pt(n){let e=4294967295;for(let t=0;t<n.byteLength;t++)e=mt[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}async function fn(){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 ln=null;function Be(){return ln??=fn()}async function De(n){return await(await Be()).deflateSync(n)}async function oe(n){return await(await Be()).inflateSync(n)}async function gt(n,e){let t=await Be();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 bt=1346454347,un=2,hn=1,dn=2,mn=3,pn=4,Pe=6,Ne=7,gn={[hn]:"commit",[dn]:"tree",[mn]:"blob",[pn]:"tag"};async function wt(n,e){let t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=t.getUint32(0);if(r!==bt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${bt.toString(16)})`);let s=t.getUint32(4);if(s!==un)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 bn(n,a);o.push(l),a=l.nextOffset}return(await yn(o,e)).map((f,l)=>({...f,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function bn(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===Ne&&(c=we(n,e),e+=20);let{result:f,bytesConsumed:l}=await gt(n.subarray(e),i);return{headerOffset:t,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+l}}async function yn(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!==Ne){let d=gn[a.typeNum];if(!d)throw new Error(`Unknown object type: ${a.typeNum}`);let h={type:d,content:a.inflated,hash:await He(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 He(h.type,m)};return r[i]=b,b}let c=await wn(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 He(f.type,l)};return r[i]=u,u}for(let i=0;i<n.length;i++)await s(i);return r}async function wn(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!==Ne&&(await r(s)).hash===t)return s}}function he(n,e){let t=0,{value:r,newPos:s}=yt(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}=yt(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 yt(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 In=new TextEncoder;async function He(n,e){let t=In.encode(`${n} ${e.byteLength}\0`),r=Ie();return r.update(t),r.update(e),r.hex()}var It=4285812579,xt=2,ee=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0)!==It)throw new Error("Invalid pack index: bad magic");if(t.getUint32(4)!==xt)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 xn(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,It),c+=4,a.setUint32(c,xt),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 Ot(n){let t=(await wt(n)).map(s=>({hash:s.hash,offset:s.offset,crc:pt(n.subarray(s.offset,s.nextOffset))})),r=n.subarray(n.byteLength-20);return xn(t,r)}var On=6,Pn=7,Rn={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===On){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===Pn){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=Rn[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 kn=new TextEncoder,En=new TextDecoder;function Tn(n,e){let t=kn.encode(`${n} ${e.byteLength}\0`),r=new Uint8Array(t.byteLength+e.byteLength);return r.set(t),r.set(e,t.byteLength),r}function Sn(n,e){let t=e.indexOf(0);if(t===-1)throw new Error(`Corrupt object ${n}: no null byte in header`);let r=En.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 Fe(n,e){return v(n,"objects",e.slice(0,2),e.slice(2))}var Ge=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=Tn(e,t),s=await xe(r),i=Fe(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 De(r)),s}async read(e){let t=this.cache.get(e);if(t)return t;let r=Fe(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await oe(s),o=Sn(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(Fe(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 Ot(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 _e(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 We(n){return`${n.name} <${n.email}> ${n.timestamp} ${n.timezone}`}var jn=new TextEncoder,Cn=new TextDecoder;function Pt(n){let e=Cn.decode(n),t=e.indexOf(`
|
|
2
2
|
|
|
3
3
|
`),r=t===-1?e:e.slice(0,t),s=t===-1?"":e.slice(t+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=
|
|
5
|
-
`))}async function N(n,e,t){let r=await n.objectStore.write(e,t);return n.hooks?.onObjectWrite?.({repo:n,type:e,hash:r}),r}async function V(n,e){return n.objectStore.read(e)}function
|
|
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=_e(d);break;case"committer":c=_e(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 Re(n){let e=[];e.push(`tree ${n.tree}`);for(let t of n.parents)e.push(`parent ${t}`);return e.push(`author ${We(n.author)}`),e.push(`committer ${We(n.committer)}`),e.push(""),e.push(n.message),jn.encode(e.join(`
|
|
5
|
+
`))}async function N(n,e,t){let r=await n.objectStore.write(e,t);return n.hooks?.onObjectWrite?.({repo:n,type:e,hash:r}),r}async function V(n,e){return n.objectStore.read(e)}function J(n){let e=Math.min(n.length,8e3);for(let t=0;t<e;t++)if(n.charCodeAt(t)===0)return!0;return!1}var An=new TextDecoder;async function F(n,e){let t=await V(n,e);if(t.type!=="blob")throw new Error(`Expected blob for ${e}, got ${t.type}`);return An.decode(t.content)}async function Z(n,e){let t=await V(n,e);if(t.type!=="blob")throw new Error(`Expected blob for ${e}, got ${t.type}`);return t.content}async function U(n,e){let t=await V(n,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return Pt(t.content)}var ze="ref: ",Rt=10,Ve=class{constructor(e,t){this.fs=e;this.gitDir=t}casLocks=new Map;async readRef(e){let t=v(this.gitDir,e);if(await this.fs.exists(t)){let i=(await this.fs.readFile(t)).trim();return i.startsWith(ze)?{type:"symbolic",target:i.slice(ze.length)}:{type:"direct",hash:i}}let s=(await this.readPackedRefs()).get(e);return s?{type:"direct",hash:s}:null}async writeRef(e,t){let r=v(this.gitDir,e);await kt(this.fs,r),t.type==="symbolic"?await this.fs.writeFile(r,`${ze}${t.target}
|
|
6
6
|
`):await this.fs.writeFile(r,`${t.hash}
|
|
7
7
|
`)}async deleteRef(e){let t=v(this.gitDir,e);await this.fs.exists(t)&&await this.fs.rm(t),await this.removePackedRef(e)}async listRefs(e="refs"){let t=[],r=v(this.gitDir,e);await this.fs.exists(r)&&await this.walkRefs(r,e,t);let s=await this.readPackedRefs();if(s.size>0){let i=new Set(t.map(a=>a.name)),o=`${e}/`;for(let[a,c]of s)a.startsWith(o)&&!i.has(a)&&t.push({name:a,hash:c})}return t.sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async compareAndSwapRef(e,t,r){let i=(this.casLocks.get(e)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(e,t,r),()=>this.compareAndSwapUnsafe(e,t,r));this.casLocks.set(e,i);try{return await i}finally{this.casLocks.get(e)===i&&this.casLocks.delete(e)}}async compareAndSwapUnsafe(e,t,r){let s=await this.resolveRefInternal(e);if(t===null){if(await this.readRef(e)!==null)return!1}else if(s!==t)return!1;return r===null?await this.deleteRef(e):await this.writeRef(e,r),!0}async resolveRefInternal(e){let t=e;for(let r=0;r<Rt;r++){let s=await this.readRef(t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async readPackedRefs(){let e=v(this.gitDir,"packed-refs");if(!await this.fs.exists(e))return new Map;let t=await this.fs.readFile(e),r=new Map;for(let s of t.split(`
|
|
8
8
|
`)){if(!s||s.startsWith("#")||s.startsWith("^"))continue;let i=s.indexOf(" ");if(i===-1)continue;let o=s.slice(0,i),a=s.slice(i+1).trim();o.length===40&&a&&r.set(a,o)}return r}async removePackedRef(e){let t=v(this.gitDir,"packed-refs");if(!await this.fs.exists(t))return;let s=(await this.fs.readFile(t)).split(`
|
|
9
9
|
`),i=[],o=!1;for(let c of s){if(o&&c.startsWith("^")){o=!1;continue}if(o=!1,!c||c.startsWith("#")){i.push(c);continue}let f=c.indexOf(" ");if(f!==-1&&c.slice(f+1).trim()===e){o=!0;continue}i.push(c)}i.some(c=>c&&!c.startsWith("#")&&!c.startsWith("^"))?await this.fs.writeFile(t,i.join(`
|
|
10
|
-
`)):await this.fs.rm(t)}async walkRefs(e,t,r){let s=await this.fs.readdir(e);for(let i of s){let o=v(e,i),a=`${t}/${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 $n(n,e){return n.refStore.readRef(e)}async function ke(n,e){let t=e;for(let r=0;r<Rt;r++){let s=await $n(n,t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function
|
|
11
|
-
`,exitCode:128}}var Ws=jt("not a git repository (or any of the parent directories): .git"),zs=jt("this operation must be run in a work tree");function pe(n,e){return n<e?-1:n>e?1:0}var Je=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){let r=await Ln(n,t?.exclude),s=new Set(r),i=new Je,o=Array.isArray(e)?e:[e];for(let a of o)s.has(a)||i.push(await Ct(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 Ct(n,c))}}}async function Ln(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 Ct(n,e){return{hash:e,commit:await U(n,e)}}var Un=4,At=1024,Te=100,Ce=0,Se=1,ce=2;function et(n){let e=1;for(;e*e<n;)e++;return e}function Bn(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 Dn(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 $t(n,e,t,r){e-t>Te&&(t=e-Te),r-e>Te&&(r=e+Te);let s=0,i=1;for(let c=1;e-c>=t;c++){let f=n[e-c];if(f===Ce)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===Ce)o++;else if(f===ce)a++;else break}return o===0?!1:(o+=s,a+=i,a*Un<a+o)}function Hn(n,e,t,r,s,i,o,a,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(et(e),At);for(let g=i;g<=o;g++){let w=s[n[g]].len2;w===0?l[g]=Ce:w>=d?l[g]=ce:l[g]=Se}let h=Math.min(et(r),At);for(let g=i;g<=a;g++){let w=s[t[g]].len1;w===0?u[g]=Ce:w>=h?u[g]=ce:u[g]=Se}let m=[];for(let g=i;g<=o;g++)l[g]===Se||l[g]===ce&&!$t(l,g,i,o)?m.push(g):c[g]=1;let b=[];for(let g=i;g<=a;g++)u[g]===Se||u[g]===ce&&!$t(u,g,i,a)?b.push(g):f[g]=1;return{refIndex1:m,nreff1:m.length,refIndex2:b,nreff2:b.length}}var ne=20,Mt=4,Nn=256,Fn=256,je=2147483647;function G(n,e){return n[e]??0}function Gn(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>ne&&(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]=je:++w,R<u?a[++R+1]=je:--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>ne&&(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>Nn){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($>Mt*j&&$>x&&e+ne<=A&&A<t&&s+ne<=E&&E<i){let X=!0;for(let K=1;K<=ne;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($>Mt*j&&$>x&&e<A&&A<=t-ne&&s<E&&E<=i-ne){let X=!0;for(let K=0;K<ne;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=je,L=je;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=Gn(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 vt=200,Lt=20,Ut=100,_n=1,Wn=21,zn=-30,Vn=6,Kn=-4,qn=10,Yn=24,Xn=17,Jn=23,Zn=17,Qn=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>=vt)return vt}return-1}function Bt(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===Lt){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===Lt){r.postIndent=0;break}return r}function Dt(n,e){n.preIndent===-1&&n.preBlank===0&&(e.penalty+=_n),n.endOfFile&&(e.penalty+=Wn);let t=n.indent===-1?1+n.postBlank:0,r=n.preBlank+t;e.penalty+=zn*r,e.penalty+=Vn*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?qn:Kn:s===n.preIndent||(n.postIndent!==-1&&n.postIndent>s?e.penalty+=i?Xn:Yn:e.penalty+=i?Zn:Jn))}function er(n,e){let t=(n.effectiveIndent>e.effectiveIndent?1:0)-(n.effectiveIndent<e.effectiveIndent?1:0);return Qn*t+(n.penalty-e.penalty)}function Ht(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-Ut>g&&(g=a-Ut);g<=a;g++){let w={effectiveIndent:0,penalty:0},R=Bt(t,r,g);Dt(R,w);let j=Bt(t,r,g-u);Dt(j,w),(m===-1||er(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 Nt(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}=Bn(n,e),{dstart:f,dend1:l,dend2:u}=Dn(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}=Hn(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(Fn,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;Ht(s,o,n,t,i,r),Ht(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 tr(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 nr=50;async function nt(n,e,t=nr){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=tr(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 rr(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 or(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 rr(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 Q(n,l.oldHash),h=await Q(n,u.newHash),m=ir(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 Ft=107927;function Ae(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))%Ft;e.set(f,(e.get(f)??0)+t),t=0,r=0,s=0}if(t>0){let o=(r+Math.imul(s,97))%Ft;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 sr(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 ir(n,e){return n.length===0&&e.length===0?100:n.length===0||e.length===0?0:Gt(n.length,Ae(n),e.length,Ae(e))}function Gt(n,e,t,r){let s=Math.max(n,t),i=Math.min(n,t);if(i<s-i)return 0;let{srcCopied:o}=sr(e,r);return Math.floor(o*100/s)}async function or(n,e,t,r){let s=[];for(let l of e)if(l.oldHash){let u=await Q(n,l.oldHash);s.push({size:u.length,chunks:Ae(u)})}else s.push(null);let i=[];for(let l of t)if(l.newHash){let u=await Q(n,l.newHash);i.push({size:u.length,chunks:Ae(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=Gt(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 ar(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 ar(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:cr(n,e,t,c)}async function cr(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}=Nt(n,e);return fr(s,t,i,r)}function fr(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 lr(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 ur(n,e,t,r){let s=r?.excludeFalseConflicts??!0,i=lr(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&&_t(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),mr(hr(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=ur(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 hr(n){let e=[];for(let t of n)t.type==="ok"?e.push(t):e.push(...dr(t));return e}function dr(n){let{a:e,b:t}=n;if(e.length===0||t.length===0)return[n];if(_t(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 mr(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 oe(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(`
|
|
10
|
+
`)):await this.fs.rm(t)}async walkRefs(e,t,r){let s=await this.fs.readdir(e);for(let i of s){let o=v(e,i),a=`${t}/${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 $n(n,e){return n.refStore.readRef(e)}async function ke(n,e){let t=e;for(let r=0;r<Rt;r++){let s=await $n(n,t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function Ke(n,e="refs"){return n.refStore.listRefs(e)}async function kt(n,e){let t=e.lastIndexOf("/");if(t>0){let r=e.slice(0,t);await n.mkdir(r,{recursive:!0})}}var vs=new TextEncoder;function Y(n){return typeof n=="string"?n==="120000":n===40960}var Mn=new TextEncoder,Et=new TextDecoder;function Tt(n){let e=[],t=0;for(;t<n.byteLength;){let r=n.indexOf(32,t);if(r===-1)break;let s=Et.decode(n.subarray(t,r)),i=n.indexOf(0,r+1);if(i===-1)break;let o=Et.decode(n.subarray(r+1,i)),a=n.subarray(i+1,i+21),c=re(a),f=s.padStart(6,"0");e.push({mode:f,name:o,hash:c}),t=i+21}return{type:"tree",entries:e}}function Ee(n){let e=[];for(let i of n.entries){let o=i.mode.replace(/^0+/,""),a=Mn.encode(`${o} ${i.name}\0`),c=q(i.hash);e.push(a),e.push(c)}let t=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(t),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}var me={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};async function qe(n,e){return St(n,e,"")}async function St(n,e,t){let r=[],s=new Map;for(let o of e){let a=t?o.path.slice(t.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:vn(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=t?`${t}/${o}`:o,f=await St(n,a,c);r.push({mode:me.DIRECTORY,name:o,hash:f})}r.sort((o,a)=>{let c=o.mode===me.DIRECTORY?`${o.name}/`:o.name,f=a.mode===me.DIRECTORY?`${a.name}/`:a.name;return c<f?-1:c>f?1:0});let i=Ee({type:"tree",entries:r});return N(n,"tree",i)}async function se(n,e,t=""){let r=await V(n,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=Tt(r.content),i=[];for(let o of s.entries){let a=t?`${t}/${o.name}`:o.name;if(o.mode===me.DIRECTORY){let c=await se(n,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function ae(n,e){if(!e)return new Map;let t=await se(n,e);return new Map(t.map(r=>[r.path,r]))}async function Ye(n,e,t){let r=await ae(n,e),s=await ae(n,t),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)=>pe(o.path,a.path))}function vn(n){return n.toString(8).padStart(6,"0")}function jt(n){return{stdout:"",stderr:`fatal: ${n}
|
|
11
|
+
`,exitCode:128}}var Ws=jt("not a git repository (or any of the parent directories): .git"),zs=jt("this operation must be run in a work tree");function pe(n,e){return n<e?-1:n>e?1:0}var Xe=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let 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*Je(n,e,t){let r=await Ln(n,t?.exclude),s=new Set(r),i=new Xe,o=Array.isArray(e)?e:[e];for(let a of o)s.has(a)||i.push(await Ct(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 Ct(n,c))}}}async function Ln(n,e){if(!e||e.length===0)return new Set;let t=new Set;for await(let r of Je(n,e))t.add(r.hash);return t}async function Ct(n,e){return{hash:e,commit:await U(n,e)}}var Un=4,At=1024,Te=100,Ce=0,Se=1,ce=2;function Qe(n){let e=1;for(;e*e<n;)e++;return e}function Bn(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 Dn(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 $t(n,e,t,r){e-t>Te&&(t=e-Te),r-e>Te&&(r=e+Te);let s=0,i=1;for(let c=1;e-c>=t;c++){let f=n[e-c];if(f===Ce)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===Ce)o++;else if(f===ce)a++;else break}return o===0?!1:(o+=s,a+=i,a*Un<a+o)}function Hn(n,e,t,r,s,i,o,a,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(Qe(e),At);for(let g=i;g<=o;g++){let w=s[n[g]].len2;w===0?l[g]=Ce:w>=d?l[g]=ce:l[g]=Se}let h=Math.min(Qe(r),At);for(let g=i;g<=a;g++){let w=s[t[g]].len1;w===0?u[g]=Ce:w>=h?u[g]=ce:u[g]=Se}let m=[];for(let g=i;g<=o;g++)l[g]===Se||l[g]===ce&&!$t(l,g,i,o)?m.push(g):c[g]=1;let b=[];for(let g=i;g<=a;g++)u[g]===Se||u[g]===ce&&!$t(u,g,i,a)?b.push(g):f[g]=1;return{refIndex1:m,nreff1:m.length,refIndex2:b,nreff2:b.length}}var te=20,Mt=4,Nn=256,Fn=256,je=2147483647;function G(n,e){return n[e]??0}function Gn(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]=je:++w,R<u?a[++R+1]=je:--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>Nn){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($>Mt*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($>Mt*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=je,L=je;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 et(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=Gn(n,e,t,r,s,i,l,u,d,h);et(n,e,m.i1,r,s,m.i2,o,a,c,f,l,u,m.minLo,h),et(n,m.i1,t,r,m.i2,i,o,a,c,f,l,u,m.minHi,h)}}var vt=200,Lt=20,Ut=100,_n=1,Wn=21,zn=-30,Vn=6,Kn=-4,qn=10,Yn=24,Xn=17,Jn=23,Zn=17,Qn=60;function Ze(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>=vt)return vt}return-1}function Bt(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=Ze(n[t]));for(let s=t-1;s>=0&&(r.preIndent=Ze(n[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===Lt){r.preIndent=0;break}for(let s=t+1;s<e&&(r.postIndent=Ze(n[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===Lt){r.postIndent=0;break}return r}function Dt(n,e){n.preIndent===-1&&n.preBlank===0&&(e.penalty+=_n),n.endOfFile&&(e.penalty+=Wn);let t=n.indent===-1?1+n.postBlank:0,r=n.preBlank+t;e.penalty+=zn*r,e.penalty+=Vn*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?qn:Kn:s===n.preIndent||(n.postIndent!==-1&&n.postIndent>s?e.penalty+=i?Xn:Yn:e.penalty+=i?Zn:Jn))}function er(n,e){let t=(n.effectiveIndent>e.effectiveIndent?1:0)-(n.effectiveIndent<e.effectiveIndent?1:0);return Qn*t+(n.penalty-e.penalty)}function Ht(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-Ut>g&&(g=a-Ut);g<=a;g++){let w={effectiveIndent:0,penalty:0},R=Bt(t,r,g);Dt(R,w);let j=Bt(t,r,g-u);Dt(j,w),(m===-1||er(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 Nt(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}=Bn(n,e),{dstart:f,dend1:l,dend2:u}=Dn(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}=Hn(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(Fn,Qe(C));et(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;Ht(s,o,n,t,i,r),Ht(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 tr(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 nr=50;async function tt(n,e,t=nr){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=tr(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 rr(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 or(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 rr(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=ir(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 Ft=107927;function Ae(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))%Ft;e.set(f,(e.get(f)??0)+t),t=0,r=0,s=0}if(t>0){let o=(r+Math.imul(s,97))%Ft;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 sr(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 ir(n,e){return n.length===0&&e.length===0?100:n.length===0||e.length===0?0:Gt(n.length,Ae(n),e.length,Ae(e))}function Gt(n,e,t,r){let s=Math.max(n,t),i=Math.min(n,t);if(i<s-i)return 0;let{srcCopied:o}=sr(e,r);return Math.floor(o*100/s)}async function or(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:Ae(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:Ae(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=Gt(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 ar(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 nt(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 ar(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 nt(n,f,u)){l=!0;break}l||c.push(f)}return c.length<=1?c:cr(n,e,t,c)}async function cr(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 rt(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}=Nt(n,e);return fr(s,t,i,r)}function fr(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 lr(n,e,t){let r=[];for(let c of rt(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 rt(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 ur(n,e,t,r){let s=r?.excludeFalseConflicts??!0,i=lr(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&&_t(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),mr(hr(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=ur(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 hr(n){let e=[];for(let t of n)t.type==="ok"?e.push(t):e.push(...dr(t));return e}function dr(n){let{a:e,b:t}=n;if(e.length===0||t.length===0)return[n];if(_t(e,t))return[n];let r=rt(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 mr(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(st);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
|
|
12
12
|
`)}
|
|
13
13
|
`:a.join(`
|
|
14
14
|
`)}function W(n){if(n==="")return[];let e=n.split(`
|
|
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 _t(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,re=new TextEncoder,Wt={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 pr(n,e,t,r),f=await br(n,i,o,a,c,s);return yr(n,i,s,f)}async function Jt(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 Qt(n,e,t,s,1);return{...await ue(n,a,i.tree,o.tree,r),baseTree:a}}async function pr(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(gr(x)){c.set(f,x);continue}c.set(f,x)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function gr(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 br(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 B=ot(e,p.newPath);B.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],B.pathnames=[y,p.newPath,O.newPath],B.filemask=7,B.merged={result:null,clean:!1}}}else{let k=r.get(p.newPath),P=s.get(O.newPath),B=await Zt(n,S,k,P,i);B.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,B.hash,2)),o.entries.push(H(O.newPath,P.mode,B.hash,3)),o.worktreeBlobs.set(p.newPath,{hash:B.hash,mode:k.mode}),o.worktreeBlobs.set(O.newPath,{hash:B.hash,mode:P.mode})}else if(p){m.add(p.newPath);let k=s.get(y),P=r.get(p.newPath),B=h.has(p.newPath);if(k)if(B)await Xt(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 D=ot(e,p.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:P.hash,mode:P.mode},{hash:k.hash,mode:k.mode}],D.pathnames=[y,p.newPath,y],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=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}.`),D){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,D,3));let Me=await $e(n,P.hash,D.hash,P.mode,i);o.worktreeBlobs.set(p.newPath,{hash:Me,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),B=h.has(O.newPath);if(k)if(B)await Xt(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 D=ot(e,O.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],D.pathnames=[y,y,O.newPath],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=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}.`),D){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,D,2)),o.entries.push(_(O.newPath,P,3));let Me=await $e(n,D.hash,P.hash,D.mode,i);o.worktreeBlobs.set(O.newPath,{hash:Me,mode:D.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=zt(t,r),x=zt(t,s),I=Vt(C,s,t),T=Vt(x,r,t),L=Kt(f.renames,I),A=Kt(l.renames,T),E=qt(L),$=qt(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=Yt(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 B=e.get(y.path);B&&(B.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=Yt(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 B=e.get(y.path);B&&(B.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 zt(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 Vt(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 Kt(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 qt(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 Yt(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 Xt(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 Zt(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 $e(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 $e(n,m.hash,u.hash,i.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:i.mode})}}async function Zt(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(Z(c)||Z(f)||Z(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=oe(c,a,f,{a:g,b:w,markerSize:o??7});return{hash:await N(n,"blob",re.encode(R)),conflict:!0}}async function $e(n,e,t,r,s){let i=await F(n,e),o=await F(n,t),a=oe(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs"});return N(n,"blob",re.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:ee()}}async function yr(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 wr(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 Ye(n,l);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function wr(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(Z(m)||Z(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=oe(m,"",b,{a:t?.a??"HEAD",b:t?.b??"theirs"}),x=await N(n,"blob",re.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(Z(b)||Z(g)||Z(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",$=oe(b,m,g,{a:A,b:E}),X=await N(n,"blob",re.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 Ir=200;async function Qt(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>=Ir)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 Qt(n,c,u,g,s+1)}let m=await ue(n,h,f,d);f=await xr(n,m,s);let b=Re({type:"commit",tree:f,parents:[c,u],author:Wt,committer:Wt,message:"merged common ancestors"});c=await N(n,"commit",b)}return f}async function xr(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=oe(b,w,g,{a:`${j}:${l}`,o:o.o,b:`${C}:${u}`,markerSize:R}),I=await N(n,"blob",re.encode(x));r.push({path:l,mode:h.mode,hash:I,stage:0,stat:ee()}),r.push({path:u,mode:m.mode,hash:I,stage:0,stat:ee()});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=oe(l,h,u,{a:w,o:o.o,b:R,markerSize:o.markerSize}),C=await N(n,"blob",re.encode(j));r.push({path:a.path,mode:c.mode,hash:C,stage:0,stat:ee()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>pe(a.path,c.path)),Ye(n,r)}async function at(n,e){let t=e.map(it);if(t.length===0)return N(n,"blob",re.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?t.join(`
|
|
15
|
+
`);if(e[e.length-1]==="")e.pop();else{let t=e[e.length-1]??"";e[e.length-1]=`${t}\0`}return e}function st(n){return n.endsWith("\0")?n.slice(0,-1):n}function _t(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,Wt={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 pr(n,e,t,r),f=await br(n,i,o,a,c,s);return yr(n,i,s,f)}async function Jt(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 Qt(n,e,t,s,1);return{...await ue(n,a,i.tree,o.tree,r),baseTree:a}}async function pr(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(gr(x)){c.set(f,x);continue}c.set(f,x)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function gr(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 br(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 tt(n,a),l=await tt(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 B=it(e,p.newPath);B.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],B.pathnames=[y,p.newPath,O.newPath],B.filemask=7,B.merged={result:null,clean:!1}}}else{let k=r.get(p.newPath),P=s.get(O.newPath),B=await Zt(n,S,k,P,i);B.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,B.hash,2)),o.entries.push(H(O.newPath,P.mode,B.hash,3)),o.worktreeBlobs.set(p.newPath,{hash:B.hash,mode:k.mode}),o.worktreeBlobs.set(O.newPath,{hash:B.hash,mode:P.mode})}else if(p){m.add(p.newPath);let k=s.get(y),P=r.get(p.newPath),B=h.has(p.newPath);if(k)if(B)await Xt(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 D=it(e,p.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:P.hash,mode:P.mode},{hash:k.hash,mode:k.mode}],D.pathnames=[y,p.newPath,y],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=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}.`),D){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,D,3));let Me=await $e(n,P.hash,D.hash,P.mode,i);o.worktreeBlobs.set(p.newPath,{hash:Me,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),B=h.has(O.newPath);if(k)if(B)await Xt(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 D=it(e,O.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],D.pathnames=[y,y,O.newPath],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=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}.`),D){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,D,2)),o.entries.push(_(O.newPath,P,3));let Me=await $e(n,D.hash,P.hash,D.mode,i);o.worktreeBlobs.set(O.newPath,{hash:Me,mode:D.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=zt(t,r),x=zt(t,s),I=Vt(C,s,t),T=Vt(x,r,t),L=Kt(f.renames,I),A=Kt(l.renames,T),E=qt(L),$=qt(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=Yt(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 B=e.get(y.path);B&&(B.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=Yt(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 B=e.get(y.path);B&&(B.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 ft=new Set(o.entries.map(y=>y.path));for(let y of ft){let p=e.get(y);p&&(p.merged={result:null,clean:!0})}for(let y of m){if(ft.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 zt(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 Vt(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 Kt(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 qt(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 Yt(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 Xt(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 Zt(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 $e(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 $e(n,m.hash,u.hash,i.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:i.mode})}}async function Zt(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 ot(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 $e(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 yr(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 wr(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 qe(n,l);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function wr(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 ot(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 ot(n,C.result);r.push(M(a,x,f.mode))}return}}var Ir=200;async function Qt(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>=Ir)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 Qt(n,c,u,g,s+1)}let m=await ue(n,h,f,d);f=await xr(n,m,s);let b=Re({type:"commit",tree:f,parents:[c,u],author:Wt,committer:Wt,message:"merged common ancestors"});c=await N(n,"commit",b)}return f}async function xr(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)),qe(n,r)}async function ot(n,e){let t=e.map(st);if(t.length===0)return N(n,"blob",ne.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?t.join(`
|
|
16
16
|
`):`${t.join(`
|
|
17
17
|
`)}
|
|
18
|
-
`;return N(n,"blob",
|
|
18
|
+
`;return N(n,"blob",ne.encode(i))}function M(n,e,t,r=0){let s=typeof t=="string"?parseInt(t,8):t;return{path:n,mode:s,hash:e,stage:r,stat:Q()}}function it(n,e){let t=n.get(e);return t||(t={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},n.set(e,t)),t}async function*Or(n,e,t){let r=e?[e]:[];for await(let s of Je(n,t,{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 Pr(n,e,t){let r=await U(n,t),s=null;return e&&(s=(await U(n,e)).tree),Ye(n,s,r.tree)}async function Rr(n,e,t){return nt(n,e,t)}async function kr(n,e){return ke(n,e)}async function Er(n){return Ke(n,"refs/heads")}async function Tr(n){return Ke(n,"refs/tags")}async function Sr(n,e){return U(n,e)}async function jr(n,e){return Z(n,e)}async function Cr(n,e){return F(n,e)}async function Ar(n,e){return se(n,e)}async function $r(n,e,t){return Ye(n,e,t)}async function Mr(n,e,t){return ge(n,e,t)}async function vr(n,e,t,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await Jt(n,e,t,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function Lr(n,e,t,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await ue(n,e,t,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}async function Ur(n,e){let t=Re({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message});return N(n,"commit",t)}async function Br(n,e){let t=[...e].sort((s,i)=>s.name.localeCompare(i.name)),r=Ee({type:"tree",entries:t.map(s=>({mode:s.mode??"100644",name:s.name,hash:s.hash}))});return N(n,"tree",r)}async function Dr(n,e){return N(n,"blob",new TextEncoder().encode(e))}async function Hr(n,e,t){let r=await U(n,e),i=(await se(n,r.tree)).find(o=>o.path===t);return i?F(n,i.hash):null}var en=/^[0-9a-f]{40}$/;async function Nr(n,e,t,r="/"){let s=await ke(n,e);if(!s)if(en.test(e)&&await n.objectStore.exists(e))s=e;else throw new Error(`ref or commit '${e}' not found`);let i=await U(n,s),o=await se(n,i.tree),a=new Set,c=0;for(let f of o){let l=v(r,f.path),u=ve(l);if(u!==r&&!a.has(u)&&(await t.mkdir(u,{recursive:!0}),a.add(u)),Y(f.mode)){let d=await F(n,f.hash);t.symlink?await t.symlink(d,l):await t.writeFile(l,d)}else{let d=await Z(n,f.hash);await t.writeFile(l,d)}c++}return{commitHash:s,treeHash:i.tree,filesWritten:c}}async function Fr(n,e,t){let r=t?.workTree??"/",s=t?.gitDir??v(r,".git"),i=t?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await ke(n,i);if(!o)if(en.test(i)&&await n.objectStore.exists(i))o=i;else throw new Error(`ref or commit '${i}' not found`);let a=await U(n,o),c=await se(n,a.tree),f={...n,fs:e,gitDir:s,workTree:r},l=new Set,u=0;for(let h of c){let m=v(r,h.path),b=ve(m);if(b!==r&&!l.has(b)&&(await e.mkdir(b,{recursive:!0}),l.add(b)),Y(h.mode)){let g=await F(n,h.hash);e.symlink?await e.symlink(g,m):await e.writeFile(m,g)}else{let g=await Z(n,h.hash);await e.writeFile(m,g)}u++}let d=ht(c.map(h=>({path:h.path,mode:parseInt(h.mode,8),hash:h.hash,stage:0,stat:Q()})));return await Ue(f,d),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:u}}var at=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,t){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)}},ct=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,t){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,t,r){throw new Error("cannot update ref: ref store is read-only")}};function Gr(n){return{objectStore:new at(n.objectStore),refStore:new ct(n.refStore),hooks:n.hooks}}export{Ve as FileSystemRefStore,Ge as PackedObjectStore,Nr as checkoutTo,Ur as createCommit,Fr as createWorktree,$r as diffTrees,Mr as findMergeBases,Ar as flattenTree,Pr as getChangedFiles,Or as getNewCommits,Rr as isAncestor,Er as listBranches,Tr as listTags,vr as mergeTrees,Lr as mergeTreesFromTreeHashes,jr as readBlob,Cr as readBlobText,Sr as readCommit,Hr as readFileAtCommit,Gr as readonlyRepo,kr as resolveRef,Dr as writeBlob,Br as writeTree};
|
package/dist/server/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
var B=(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 S(n){return n!=null&&typeof n=="object"&&"reject"in n&&n.reject===!0}var K="0000000000000000000000000000000000000000",
|
|
1
|
+
var B=(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 S(n){return n!=null&&typeof n=="object"&&"reject"in n&&n.reject===!0}var K="0000000000000000000000000000000000000000",pe=(()=>{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 N(n){let e="";for(let t=0;t<20;t++)e+=pe[n[t]];return e}function ue(n,e){let t="";for(let o=0;o<20;o++)t+=pe[n[e+o]];return t}function W(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 Ve=new TextEncoder;function Y(n){return typeof n=="string"?Ve.encode(n):n}function Xe(){if(typeof globalThis.Bun<"u")return()=>{let n=new Bun.CryptoHasher("sha1"),e={update(t){return n.update(Y(t)),e},hex:()=>Promise.resolve(n.digest("hex"))};return e};try{let n=B(["node","crypto"].join(":"));if(typeof n.createHash=="function")return()=>{let e=n.createHash("sha1"),t={update(o){return e.update(Y(o)),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(Y(t)),e},async hex(){let t=0;for(let i of n)t+=i.byteLength;let o=new Uint8Array(t),r=0;for(let i of n)o.set(i,r),r+=i.byteLength;let a=await crypto.subtle.digest("SHA-1",o);return N(new Uint8Array(a))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var he=Xe(),$=he;async function be(n){return he().update(n).hex()}var Ze=new Set(["tree","commit","tag"]),_=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(!Ze.has(t.type))return;let o=t.content.byteLength;if(!(o>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+o>this.maxBytes&&this.map.size>0;){let r=this.map.keys().next().value;this.currentBytes-=this.map.get(r).content.byteLength,this.map.delete(r)}this.map.set(e,t),this.currentBytes+=o}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};async function Je(){let n;try{n=B(["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=o=>{let r=n.inflateSync(o,{info:!0});return{result:new Uint8Array(r.buffer),bytesConsumed:r.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"),o=t.writable.getWriter();return o.write(e),o.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())},async inflateSync(e){let t=new DecompressionStream("deflate"),o=t.writable.getWriter();return o.write(e),o.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 Qe=null;function ye(){return Qe??=Je()}async function G(n){return await(await ye()).deflateSync(n)}async function xe(n,e){let t=await ye();if(t.inflateWithConsumed){let{result:i,bytesConsumed:s}=t.inflateWithConsumed(n);if(i.byteLength!==e)throw new Error(`Inflate size mismatch: got ${i.byteLength}, expected ${e}`);return{result:i,bytesConsumed:s}}let o=await t.inflateSync(n);if(o.byteLength!==e)throw new Error(`Inflate size mismatch: got ${o.byteLength}, expected ${e}`);let r=2,a=n.byteLength;for(;r<a;){let i=r+a>>>1;try{(await t.inflateSync(n.subarray(0,i))).byteLength===e?a=i:r=i+1}catch{r=i+1}}return{result:o,bytesConsumed:r}}var M=1346454347,Z=2,we=1,Re=2,ke=3,Pe=4,U=6,J=7,et={[we]:"commit",[Re]:"tree",[ke]:"blob",[Pe]:"tag"},Oe={commit:we,tree:Re,blob:ke,tag:Pe};async function je(n,e){let t=new DataView(n.buffer,n.byteOffset,n.byteLength),o=t.getUint32(0);if(o!==M)throw new Error(`Invalid pack signature: 0x${o.toString(16)} (expected 0x${M.toString(16)})`);let r=t.getUint32(4);if(r!==Z)throw new Error(`Unsupported pack version: ${r}`);let a=t.getUint32(8),i=[],s=12;for(let c=0;c<a;c++){let d=await tt(n,s);i.push(d),s=d.nextOffset}return(await nt(i,e)).map((c,d)=>({...c,offset:i[d].headerOffset,nextOffset:i[d].nextOffset}))}async function tt(n,e){let t=e,o=n[e++],r=o>>4&7,a=o&15,i=4;for(;o&128;)o=n[e++],a|=(o&127)<<i,i+=7;let s,f;if(r===U){let u=n[e++];for(s=u&127;u&128;)s+=1,u=n[e++],s=(s<<7)+(u&127);s=t-s}else r===J&&(f=ue(n,e),e+=20);let{result:c,bytesConsumed:d}=await xe(n.subarray(e),a);return{headerOffset:t,typeNum:r,inflated:c,baseOffset:s,baseHash:f,nextOffset:e+d}}async function nt(n,e){let t=new Map;for(let a=0;a<n.length;a++)t.set(n[a].headerOffset,a);let o=new Array(n.length).fill(null);async function r(a){let i=o[a];if(i)return i;let s=n[a];if(s.typeNum!==U&&s.typeNum!==J){let l=et[s.typeNum];if(!l)throw new Error(`Unknown object type: ${s.typeNum}`);let h={type:l,content:s.inflated,hash:await V(l,s.inflated)};return o[a]=h,h}if(s.typeNum===U){let l=t.get(s.baseOffset);if(l===void 0)throw new Error(`OFS_DELTA base not found at offset ${s.baseOffset}`);let h=await r(l),b=me(h.content,s.inflated),p={type:h.type,content:b,hash:await V(h.type,b)};return o[a]=p,p}let f=await rt(n,o,s.baseHash,r),c;if(f!==void 0)c=await r(f);else if(e){let l=await e(s.baseHash);l&&(c=l)}if(!c)throw new Error(`REF_DELTA base not found for hash ${s.baseHash}`);let d=me(c.content,s.inflated),u={type:c.type,content:d,hash:await V(c.type,d)};return o[a]=u,u}for(let a=0;a<n.length;a++)await r(a);return o}async function rt(n,e,t,o){for(let r=0;r<e.length;r++)if(e[r]?.hash===t)return r;for(let r=0;r<n.length;r++){let a=n[r];if(a.typeNum!==U&&a.typeNum!==J&&(await o(r)).hash===t)return r}}function me(n,e){let t=0,{value:o,newPos:r}=ge(e,t);if(t=r,o!==n.byteLength)throw new Error(`Delta base size mismatch: expected ${o}, got ${n.byteLength}`);let{value:a,newPos:i}=ge(e,t);t=i;let s=new Uint8Array(a),f=0;for(;t<e.byteLength;){let c=e[t++];if(c&128){let d=0,u=0;c&1&&(d=e[t++]),c&2&&(d|=e[t++]<<8),c&4&&(d|=e[t++]<<16),c&8&&(d|=e[t++]<<24),c&16&&(u=e[t++]),c&32&&(u|=e[t++]<<8),c&64&&(u|=e[t++]<<16),u===0&&(u=65536),s.set(n.subarray(d,d+u),f),f+=u}else if(c>0)s.set(e.subarray(t,t+c),f),f+=c,t+=c;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(f!==a)throw new Error(`Delta produced ${f} bytes, expected ${a}`);return s}async function ve(n){let e=[],t=new Map,o=new Uint8Array(12),r=new DataView(o.buffer);r.setUint32(0,M),r.setUint32(4,Z),r.setUint32(8,n.length),e.push(o);let a=12,i=[];for(let s of n){let f=a;t.set(s.hash,a);let c=s.delta&&s.deltaBaseHash?t.get(s.deltaBaseHash):void 0;if(s.delta&&c!==void 0){let d=X(U,s.delta.byteLength),u=st(a-c),l=await G(s.delta);e.push(d,u,l),a+=d.byteLength+u.byteLength+l.byteLength}else{let d=Oe[s.type],u=X(d,s.content.byteLength),l=await G(s.content);e.push(u,l),a+=u.byteLength+l.byteLength}i.push({hash:s.hash,offset:f,nextOffset:a})}return{data:await ot(e),entries:i}}async function*Ie(n,e){let t=$(),o=new Uint8Array(12),r=new DataView(o.buffer);r.setUint32(0,M),r.setUint32(4,Z),r.setUint32(8,n),t.update(o),yield o;for await(let a of e){let i=Oe[a.type],s=X(i,a.content.byteLength),f=await G(a.content);t.update(s),t.update(f),yield at(s,f)}yield W(await t.hex())}async function ot(n){let e=0;for(let i of n)e+=i.byteLength;e+=20;let t=new Uint8Array(e),o=0;for(let i of n)t.set(i,o),o+=i.byteLength;let r=$();r.update(t.subarray(0,o));let a=await r.hex();return t.set(W(a),o),t}function st(n){let e=[];e.push(n&127);let t=n>>>7;for(;t>0;)e.unshift(128|--t&127),t>>>=7;return new Uint8Array(e)}function X(n,e){let t=[],o=n<<4|e&15;for(e>>=4;e>0;)t.push(o|128),o=e&127,e>>=7;return t.push(o),new Uint8Array(t)}function ge(n,e){let t=0,o=0,r;do r=n[e++],t|=(r&127)<<o,o+=7;while(r&128);return{value:t,newPos:e}}function at(n,e){let t=new Uint8Array(n.byteLength+e.byteLength);return t.set(n,0),t.set(e,n.byteLength),t}var it=new TextEncoder;async function V(n,e){let t=it.encode(`${n} ${e.byteLength}\0`),o=$();return o.update(t),o.update(e),o.hex()}var ct=new TextEncoder,Ft=new TextDecoder;function Ae(n,e){let t=ct.encode(`${n} ${e.byteLength}\0`),o=new Uint8Array(t.byteLength+e.byteLength);return o.set(t),o.set(e,t.byteLength),o}function T(n){let e=n.indexOf("<"),t=n.indexOf(">");if(e===-1||t===-1)throw new Error(`Malformed identity line: "${n}"`);let o=n.slice(0,e).trimEnd(),r=n.slice(e+1,t),a=n.slice(t+2),[i="0",s="+0000"]=a.split(" "),f=parseInt(i,10);return{name:o,email:r,timestamp:f,timezone:s}}var Yt=new TextEncoder,dt=new TextDecoder;function C(n){let e=dt.decode(n),t=e.indexOf(`
|
|
2
2
|
|
|
3
|
-
`),
|
|
4
|
-
`)){let d=c.indexOf(" ");if(d===-1)continue;let u=c.slice(0,d),l=c.slice(d+1);switch(u){case"tree":a=l;break;case"parent":i.push(l);break;case"author":
|
|
3
|
+
`),o=t===-1?e:e.slice(0,t),r=t===-1?"":e.slice(t+2),a="",i=[],s,f;for(let c of o.split(`
|
|
4
|
+
`)){let d=c.indexOf(" ");if(d===-1)continue;let u=c.slice(0,d),l=c.slice(d+1);switch(u){case"tree":a=l;break;case"parent":i.push(l);break;case"author":s=T(l);break;case"committer":f=T(l);break}}if(!a)throw new Error("Commit missing tree field");if(!s)throw new Error("Commit missing author field");if(!f)throw new Error("Commit missing committer field");return{type:"commit",tree:a,parents:i,author:s,committer:f,message:r}}var Zt=new TextEncoder,lt=new TextDecoder;function P(n){let e=lt.decode(n),t=e.indexOf(`
|
|
5
5
|
|
|
6
|
-
`),
|
|
7
|
-
`)){let d=c.indexOf(" ");if(d===-1)continue;let u=c.slice(0,d),l=c.slice(d+1);switch(u){case"object":a=l;break;case"type":i=l;break;case"tag":o=l;break;case"tagger":f=T(l);break}}if(!a)throw new Error("Tag missing object field");if(!o)throw new Error("Tag missing tag name field");if(!f)throw new Error("Tag missing tagger field");return{type:"tag",object:a,objectType:i,name:o,tagger:f,message:r}}async function H(n,e){return n.objectStore.read(e)}async function Se(n,e){return n.objectStore.exists(e)}var tn=new TextDecoder;async function Ue(n,e){let t=await H(n,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return C(t.content)}var sn=new TextEncoder,Te=new TextDecoder;function ne(n){let e=[],t=0;for(;t<n.byteLength;){let s=n.indexOf(32,t);if(s===-1)break;let r=Te.decode(n.subarray(t,s)),a=n.indexOf(0,s+1);if(a===-1)break;let i=Te.decode(n.subarray(s+1,a)),o=n.subarray(a+1,a+21),f=N(o),c=r.padStart(6,"0");e.push({mode:c,name:i,hash:f}),t=a+21}return{type:"tree",entries:e}}async function Ce(n,e,t){if(e===t)return!0;let s=new Set,r=[t],a=0;for(;a<r.length;){let i=r[a++];if(i===e)return!0;if(s.has(i))continue;s.add(i);let o=await Ue(n,i);for(let f of o.parents)s.has(f)||r.push(f)}return!1}var q=new Uint32Array([0,2874782929,1454598562,4260027763,104818581,2909197124,1351355959,4225088230,209637162,2804382715,1523426952,4053013081,172075199,2702711918,1559413021,4155209164,419274324,3013880453,1313798134,3843506983,516094401,3046853904,1215402083,3811058866,344150398,3218793903,1110456540,3916008461,314324715,3118826042,1141858121,4015451032,838548648,2594343033,1732793610,3423723995,935615293,2627596268,1635201695,3392046670,1032188802,2531018579,1798740512,3228511985,1002083351,2430804166,1829371317,3327150436,688300796,2187269677,2142620510,3572268943,792315241,2220913080,2039131339,3537049626,628649430,2384582919,1942684788,3633492133,591858243,2283716242,1978950625,3735934768,1677097296,3366964609,893718770,2652677155,1707679429,3465587220,863663975,2552480694,1871230586,3302032043,960225240,2455923465,1773654511,3270403390,1057273933,2489126044,2064377604,3495056341,767069862,2262907511,2100592785,3597481024,730327347,2162056674,2004166702,3693911295,566641036,2325738845,1900695483,3658742634,670639641,2359333576,1376601592,4183093545,79572058,2951190667,1412571757,4285241020,42027983,2849570590,1584630482,4113186307,146858864,2744735649,1481436487,4078262678,251626725,2779131956,1257298860,3785977725,474198542,3071936223,1288682553,3885369576,444388763,2972016970,1183716486,3990331479,272465188,3143944693,1085371155,3957901250,369236657,3176902240,1823819377,3354194592,973483987,2438961922,1787437540,3251868981,1010387014,2539715735,1623951707,3415358858,913891577,2636207144,1727327950,3450690079,809994092,2602447805,1950930981,3742461172,586920327,2309096790,1920450480,3643673441,616879634,2409456323,2016810767,3547309022,780500653,2245839484,2114547866,3578840139,683284792,2212736489,1565424345,4128755208,201134971,2695145386,1534139724,4029196701,230847726,2795225151,1362146803,4201185570,126082129,2899994752,1460654694,4233520823,29146052,2867138325,1169417357,4008333404,318803247,3092855294,1133282072,3906287561,356510394,3194379883,1238182823,3801390966,528368133,3022517972,1341279282,3836475619,423699856,2987954497,256065313,2753203184,1508923011,4071219794,159144116,2720394341,1607414038,4103505351,54390795,2825143514,1435408809,4275514744,84055966,2925208399,1404173884,4175973101,398369141,3169260964,1091422423,3931405318,293717728,3134747185,1194504002,3966442387,465595999,2962872974,1299384317,3861558060,503253450,3064380699,1263296616,3759527097,1052246921,2514597720,1745578539,3276988154,948397084,2480853197,1848905150,3312302447,851889315,2577365106,1685431553,3475771856,888777526,2678071271,1649066644,3373495877,642096605,2367432972,1895232639,3685695662,544930376,2334346905,1992922090,3717211963,708530935,2170742310,2089302869,3620835204,738473314,2271052211,2058837184,3522095121]),ut=new Uint32Array([0,2125799437,1446245579,679924934,121527623,2039184714,1359849868,800622977,243055246,1892260483,1481592389,653946440,155379657,2012727236,1601245954,566506255,486110492,1649169681,1254785495,880779738,466036827,1701972054,1307892880,859962525,310759314,1815146399,1152793433,973282132,364614357,1796125400,1133012510,1027425811,972220984,1195887157,1874927347,292830974,1053603711,1081710450,1761559476,373973945,932073654,1228632251,1639818365,520651888,816844273,1308962300,1719925050,406247735,621518628,1539227433,1933077487,227363810,573948515,1551950446,1946564264,179508901,729228714,1438778791,2101662049,66187628,743012589,1392269536,2054851622,80718891,1944441968,223409277,634790075,1533214902,1960544567,175024442,585661948,1549622769,2107207422,53235443,732600885,1428142648,2057778105,68293556,747947890,1377953663,1864147308,296321377,959403431,1201305002,1747123243,379051046,1041303776,1084500205,1633688546,534068207,928247593,1239863076,1717454501,418080424,812495470,1322816099,1243037256,883039813,472173187,1653729934,1294557967,865878786,454727620,1706014665,1147897030,987669707,307785741,1827491840,1129699713,1038154124,359017802,1808993607,1458457428,677079897,14532511,2120785810,1372591635,795162142,132375256,2035729109,1486025178,640143831,245433617,1880368412,1605151901,555322512,161437782,1999272027,1284643889,841432124,446818554,1679083767,1269580150,890855803,497006013,1663735216,1122936511,1012631218,350048884,1785229945,1171323896,996531189,333647667,1834364734,1349216557,786319648,106470886,2028846571,1465201770,702551143,23511201,2144592044,1578619811,547550126,136587112,1989216101,1495895780,664579817,253393455,1907317282,1969288713,198563332,592642754,1575363279,1918806862,216763203,611147653,1524137864,2065452167,94989450,758102092,1402640449,2082607552,43463117,705815819,1420084486,1771668245,388801304,1068136414,1092573139,1856495186,269680223,949234329,1176570516,1743075739,424679830,836160848,1331948893,1624990940,510543057,921210903,1214099482,1064814657,1103292492,1766079626,401677447,944346374,1190966539,1853514189,282018240,822833871,1337873090,1731757572,428713481,909455240,1216352133,1611062083,515111758,596557149,1564187984,1975339414,185100699,615571482,1510326295,1921193169,204879068,770836435,1397172190,2076308248,91542293,718035604,1417247385,2097131103,38440530,109388409,2016412276,1354159794,772011711,29065022,2131648307,1468566517,691907576,150575351,1984739578,1590324284,545213489,264750512,1903355325,1509175675,658575734,444356453,1690924904,1280287662,855278499,490867234,1677142575,1265762025,902094564,335605227,1790299622,1110645024,1015429421,322875564,1837863073,1158497383,1001940074]),F=64,ht=4,re=4096,He=65536,bt=127;function yt(n){let e=n.byteLength;if(e===0)return null;let t=(e-1)/16|0;if(t===0)return null;let s=t>>>2;s<16&&(s=16),s=mt(s);let r=s-1,a=new Uint32Array(s),i=[],o=-1>>>0;for(let l=t*16-16;l>=0;l-=16){let h=0;for(let b=1;b<=16;b++)h=(h<<8|n[l+b])^q[h>>>23];if(h=h>>>0,h===o)i[i.length-1].ptr=l+16;else{o=h;let b=h&r;i.push({ptr:l+16,val:h}),a[b]++}}let f=new Map;for(let l of i){let h=l.val&r,b=f.get(h);b||(b=[],f.set(h,b)),b.push(l)}for(let[l,h]of f){if(h.length<=F)continue;let b=[],p=h.length/F;for(let y=0;y<F;y++)b.push(h[Math.floor(y*p)]);f.set(l,b),a[l]=F}let c=new Uint32Array(s+1),d=[],u=0;for(let l=0;l<s;l++){c[l]=u;let h=f.get(l);if(h){for(let b of h)d.push(b);u+=h.length}}return c[s]=u,{src:n,hashMask:r,buckets:c,entries:d}}function xt(n,e,t){if(!n||e.byteLength===0)return null;let s=n.src.byteLength,r=e.byteLength,a=n.src,i=new Uint8Array(Math.max(r,1024)),o=0;function f(p){for(;o+p>i.length;){let y=new Uint8Array(i.length*2);y.set(i),i=y}}o=De(i,o,s),o=De(i,o,r),f(18),o++;let c=0,d=0,u=Math.min(16,r);for(let p=0;p<u;p++)i[o++]=e[p],c=(c<<8|e[p])^q[c>>>23],d++;c=c>>>0;let l=u,h=0,b=0;for(;l<r;){if(b<re){c^=ut[e[l-16]],c=((c<<8|e[l])^q[c>>>23])>>>0;let p=c&n.hashMask,y=n.buckets[p],x=n.buckets[p+1];for(let R=y;R<x;R++){let m=n.entries[R];if(m.val!==c)continue;let g=m.ptr,k=a.byteLength-g,E=r-l;if(k>E&&(k=E),k<=b)break;let j=0;for(;j<k&&a[g+j]===e[l+j];)j++;if(j>b&&(b=j,h=g,b>=re))break}}if(b<ht)f(2),d===0&&o++,i[o++]=e[l++],d++,d===bt&&(i[o-d-1]=d,d=0),b=0;else{if(d>0){for(;h>0&&a[h-1]===e[l-1];)if(b++,h--,l--,o--,!(--d>0)){o--,d=-1;break}d>0&&(i[o-d-1]=d),d=0}let p=b>He?b-He:0;b-=p,f(8);let y=o++,x=128;if(h&255&&(i[o++]=h&255,x|=1),h&65280&&(i[o++]=h>>>8&255,x|=2),h&16711680&&(i[o++]=h>>>16&255,x|=4),h&4278190080&&(i[o++]=h>>>24&255,x|=8),b&255&&(i[o++]=b&255,x|=16),b&65280&&(i[o++]=b>>>8&255,x|=32),i[y]=x,l+=b,h+=b,b=p,h>4294967295&&(b=0),b<re){c=0;for(let R=-16;R<0;R++)c=(c<<8|e[l+R])^q[c>>>23];c=c>>>0}}if(t&&o>t)return null}return d>0&&(i[o-d-1]=d),t&&o>t?null:i.subarray(0,o)}var Le={blob:0,tree:1,commit:2,tag:3};function Be(n,e){let t=e?.window??10,s=e?.depth??50,r=n.slice().sort((c,d)=>{let u=Le[c.type]??99,l=Le[d.type]??99;return u!==l?u-l:d.content.byteLength-c.content.byteLength}),a=new Map,i=[],o=[],f=[];for(let c=0;c<r.length;c++){let d=r[c],u={hash:d.hash,type:d.type,content:d.content,depth:0},l=null,h=null,b=Math.max(0,c-t);for(let p=c-1;p>=b;p--){let y=r[p];if(y.type!==d.type||(a.get(y.hash)?.depth??0)>=s||d.content.byteLength<y.content.byteLength>>>5)continue;let m=o[p-b]??null;if(!m)continue;let g=l?l.byteLength:d.content.byteLength/2|0;if(g<16)continue;let k=xt(m,d.content,g);k&&(!l||k.byteLength<l.byteLength)&&(l=k,h=y.hash)}if(l&&h){u.delta=l,u.deltaBase=h;let p=a.get(h);u.depth=(p?.depth??0)+1}a.set(d.hash,u),i.push(u),o.length>=t&&(o.shift(),f.shift()),o.push(yt(d.content)),f.push(d.hash)}return i}function mt(n){let e=n;return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e<16?16:e}function De(n,e,t){let s=t;do{let r=s&127;s>>>=7,s>0&&(r|=128),n[e++]=r}while(s>0);return e}async function se(n,e,t){let s=new Set;for(let i of t)await L(n,i,s);let r=[],a=new Set;for(let i of e)await D(n,i,s,a,r);return{count:r.length,objects:gt(r)}}async function Ne(n,e,t){let{count:s,objects:r}=await se(n,e,t);return{count:s,objects:wt(n,r)}}async function*gt(n){for(let e of n)yield e}async function*wt(n,e){for await(let t of e){let s=await H(n,t.hash);yield{hash:t.hash,type:t.type,content:s.content}}}async function We(n){let e=[];for await(let t of n.objects)e.push(t);return e}async function L(n,e,t){if(t.has(e)||(t.add(e),!await Se(n,e)))return;let s=await H(n,e);switch(s.type){case"commit":{let r=C(s.content);await L(n,r.tree,t);for(let a of r.parents)await L(n,a,t);break}case"tree":{let r=ne(s.content);for(let a of r.entries)await L(n,a.hash,t);break}case"tag":{let r=P(s.content);await L(n,r.object,t);break}case"blob":break}}async function D(n,e,t,s,r){if(s.has(e)||t.has(e))return;s.add(e);let a=await H(n,e);switch(r.push({hash:e,type:a.type}),a.type){case"commit":{let i=C(a.content);await D(n,i.tree,t,s,r);for(let o of i.parents)await D(n,o,t,s,r);break}case"tree":{let i=ne(a.content);for(let o of i.entries)await D(n,o.hash,t,s,r);break}case"tag":{let i=P(a.content);await D(n,i.object,t,s,r);break}case"blob":break}}var Rt=new TextEncoder,_e=new TextDecoder,$e=65520,kt=new Uint8Array([48,48,48,48]);function w(n){let e=typeof n=="string"?Rt.encode(n):n,t=4+e.byteLength;if(t>$e)throw new Error(`pkt-line too long: ${t} bytes (max ${$e})`);let s=t.toString(16).padStart(4,"0"),r=new Uint8Array(t);return r[0]=s.charCodeAt(0),r[1]=s.charCodeAt(1),r[2]=s.charCodeAt(2),r[3]=s.charCodeAt(3),r.set(e,4),r}function O(){return kt.slice()}function v(...n){let e=0;for(let r of n)e+=r.byteLength;let t=new Uint8Array(e),s=0;for(let r of n)t.set(r,s),s+=r.byteLength;return t}function Ge(n){let e=[],t=0;for(;t<n.byteLength;){if(t+4>n.byteLength)throw new Error("Truncated pkt-line header");let s=_e.decode(n.subarray(t,t+4)),r=parseInt(s,16);if(Number.isNaN(r))throw new Error(`Invalid pkt-line length: ${s}`);if(r===0){e.push({type:"flush"}),t+=4;continue}if(r<4)throw new Error(`Invalid pkt-line length: ${r}`);if(t+r>n.byteLength)throw new Error(`Truncated pkt-line: need ${r} bytes at offset ${t}, have ${n.byteLength-t}`);e.push({type:"data",data:n.subarray(t+4,t+r)}),t+=r}return e}function Me(n){if(n.type==="flush")return"";let e=_e.decode(n.data);return e.endsWith(`
|
|
8
|
-
`)?e.slice(0,-1):e}var
|
|
9
|
-
`)),r.push(O());let a=[...t];
|
|
10
|
-
`));else for(let
|
|
6
|
+
`),o=t===-1?e:e.slice(0,t),r=t===-1?"":e.slice(t+2),a="",i="commit",s="",f;for(let c of o.split(`
|
|
7
|
+
`)){let d=c.indexOf(" ");if(d===-1)continue;let u=c.slice(0,d),l=c.slice(d+1);switch(u){case"object":a=l;break;case"type":i=l;break;case"tag":s=l;break;case"tagger":f=T(l);break}}if(!a)throw new Error("Tag missing object field");if(!s)throw new Error("Tag missing tag name field");if(!f)throw new Error("Tag missing tagger field");return{type:"tag",object:a,objectType:i,name:s,tagger:f,message:r}}async function H(n,e){return n.objectStore.read(e)}async function Ee(n,e){return n.objectStore.exists(e)}var en=new TextDecoder;async function Se(n,e){let t=await H(n,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return C(t.content)}var rn=new TextEncoder,Ue=new TextDecoder;function Q(n){let e=[],t=0;for(;t<n.byteLength;){let o=n.indexOf(32,t);if(o===-1)break;let r=Ue.decode(n.subarray(t,o)),a=n.indexOf(0,o+1);if(a===-1)break;let i=Ue.decode(n.subarray(o+1,a)),s=n.subarray(a+1,a+21),f=N(s),c=r.padStart(6,"0");e.push({mode:c,name:i,hash:f}),t=a+21}return{type:"tree",entries:e}}async function Te(n,e,t){if(e===t)return!0;let o=new Set,r=[t],a=0;for(;a<r.length;){let i=r[a++];if(i===e)return!0;if(o.has(i))continue;o.add(i);let s=await Se(n,i);for(let f of s.parents)o.has(f)||r.push(f)}return!1}var q=new Uint32Array([0,2874782929,1454598562,4260027763,104818581,2909197124,1351355959,4225088230,209637162,2804382715,1523426952,4053013081,172075199,2702711918,1559413021,4155209164,419274324,3013880453,1313798134,3843506983,516094401,3046853904,1215402083,3811058866,344150398,3218793903,1110456540,3916008461,314324715,3118826042,1141858121,4015451032,838548648,2594343033,1732793610,3423723995,935615293,2627596268,1635201695,3392046670,1032188802,2531018579,1798740512,3228511985,1002083351,2430804166,1829371317,3327150436,688300796,2187269677,2142620510,3572268943,792315241,2220913080,2039131339,3537049626,628649430,2384582919,1942684788,3633492133,591858243,2283716242,1978950625,3735934768,1677097296,3366964609,893718770,2652677155,1707679429,3465587220,863663975,2552480694,1871230586,3302032043,960225240,2455923465,1773654511,3270403390,1057273933,2489126044,2064377604,3495056341,767069862,2262907511,2100592785,3597481024,730327347,2162056674,2004166702,3693911295,566641036,2325738845,1900695483,3658742634,670639641,2359333576,1376601592,4183093545,79572058,2951190667,1412571757,4285241020,42027983,2849570590,1584630482,4113186307,146858864,2744735649,1481436487,4078262678,251626725,2779131956,1257298860,3785977725,474198542,3071936223,1288682553,3885369576,444388763,2972016970,1183716486,3990331479,272465188,3143944693,1085371155,3957901250,369236657,3176902240,1823819377,3354194592,973483987,2438961922,1787437540,3251868981,1010387014,2539715735,1623951707,3415358858,913891577,2636207144,1727327950,3450690079,809994092,2602447805,1950930981,3742461172,586920327,2309096790,1920450480,3643673441,616879634,2409456323,2016810767,3547309022,780500653,2245839484,2114547866,3578840139,683284792,2212736489,1565424345,4128755208,201134971,2695145386,1534139724,4029196701,230847726,2795225151,1362146803,4201185570,126082129,2899994752,1460654694,4233520823,29146052,2867138325,1169417357,4008333404,318803247,3092855294,1133282072,3906287561,356510394,3194379883,1238182823,3801390966,528368133,3022517972,1341279282,3836475619,423699856,2987954497,256065313,2753203184,1508923011,4071219794,159144116,2720394341,1607414038,4103505351,54390795,2825143514,1435408809,4275514744,84055966,2925208399,1404173884,4175973101,398369141,3169260964,1091422423,3931405318,293717728,3134747185,1194504002,3966442387,465595999,2962872974,1299384317,3861558060,503253450,3064380699,1263296616,3759527097,1052246921,2514597720,1745578539,3276988154,948397084,2480853197,1848905150,3312302447,851889315,2577365106,1685431553,3475771856,888777526,2678071271,1649066644,3373495877,642096605,2367432972,1895232639,3685695662,544930376,2334346905,1992922090,3717211963,708530935,2170742310,2089302869,3620835204,738473314,2271052211,2058837184,3522095121]),pt=new Uint32Array([0,2125799437,1446245579,679924934,121527623,2039184714,1359849868,800622977,243055246,1892260483,1481592389,653946440,155379657,2012727236,1601245954,566506255,486110492,1649169681,1254785495,880779738,466036827,1701972054,1307892880,859962525,310759314,1815146399,1152793433,973282132,364614357,1796125400,1133012510,1027425811,972220984,1195887157,1874927347,292830974,1053603711,1081710450,1761559476,373973945,932073654,1228632251,1639818365,520651888,816844273,1308962300,1719925050,406247735,621518628,1539227433,1933077487,227363810,573948515,1551950446,1946564264,179508901,729228714,1438778791,2101662049,66187628,743012589,1392269536,2054851622,80718891,1944441968,223409277,634790075,1533214902,1960544567,175024442,585661948,1549622769,2107207422,53235443,732600885,1428142648,2057778105,68293556,747947890,1377953663,1864147308,296321377,959403431,1201305002,1747123243,379051046,1041303776,1084500205,1633688546,534068207,928247593,1239863076,1717454501,418080424,812495470,1322816099,1243037256,883039813,472173187,1653729934,1294557967,865878786,454727620,1706014665,1147897030,987669707,307785741,1827491840,1129699713,1038154124,359017802,1808993607,1458457428,677079897,14532511,2120785810,1372591635,795162142,132375256,2035729109,1486025178,640143831,245433617,1880368412,1605151901,555322512,161437782,1999272027,1284643889,841432124,446818554,1679083767,1269580150,890855803,497006013,1663735216,1122936511,1012631218,350048884,1785229945,1171323896,996531189,333647667,1834364734,1349216557,786319648,106470886,2028846571,1465201770,702551143,23511201,2144592044,1578619811,547550126,136587112,1989216101,1495895780,664579817,253393455,1907317282,1969288713,198563332,592642754,1575363279,1918806862,216763203,611147653,1524137864,2065452167,94989450,758102092,1402640449,2082607552,43463117,705815819,1420084486,1771668245,388801304,1068136414,1092573139,1856495186,269680223,949234329,1176570516,1743075739,424679830,836160848,1331948893,1624990940,510543057,921210903,1214099482,1064814657,1103292492,1766079626,401677447,944346374,1190966539,1853514189,282018240,822833871,1337873090,1731757572,428713481,909455240,1216352133,1611062083,515111758,596557149,1564187984,1975339414,185100699,615571482,1510326295,1921193169,204879068,770836435,1397172190,2076308248,91542293,718035604,1417247385,2097131103,38440530,109388409,2016412276,1354159794,772011711,29065022,2131648307,1468566517,691907576,150575351,1984739578,1590324284,545213489,264750512,1903355325,1509175675,658575734,444356453,1690924904,1280287662,855278499,490867234,1677142575,1265762025,902094564,335605227,1790299622,1110645024,1015429421,322875564,1837863073,1158497383,1001940074]),F=64,ut=4,ee=4096,Ce=65536,ht=127;function bt(n){let e=n.byteLength;if(e===0)return null;let t=(e-1)/16|0;if(t===0)return null;let o=t>>>2;o<16&&(o=16),o=xt(o);let r=o-1,a=new Uint32Array(o),i=[],s=-1>>>0;for(let l=t*16-16;l>=0;l-=16){let h=0;for(let b=1;b<=16;b++)h=(h<<8|n[l+b])^q[h>>>23];if(h=h>>>0,h===s)i[i.length-1].ptr=l+16;else{s=h;let b=h&r;i.push({ptr:l+16,val:h}),a[b]++}}let f=new Map;for(let l of i){let h=l.val&r,b=f.get(h);b||(b=[],f.set(h,b)),b.push(l)}for(let[l,h]of f){if(h.length<=F)continue;let b=[],p=h.length/F;for(let y=0;y<F;y++)b.push(h[Math.floor(y*p)]);f.set(l,b),a[l]=F}let c=new Uint32Array(o+1),d=[],u=0;for(let l=0;l<o;l++){c[l]=u;let h=f.get(l);if(h){for(let b of h)d.push(b);u+=h.length}}return c[o]=u,{src:n,hashMask:r,buckets:c,entries:d}}function yt(n,e,t){if(!n||e.byteLength===0)return null;let o=n.src.byteLength,r=e.byteLength,a=n.src,i=new Uint8Array(Math.max(r,1024)),s=0;function f(p){for(;s+p>i.length;){let y=new Uint8Array(i.length*2);y.set(i),i=y}}s=Le(i,s,o),s=Le(i,s,r),f(18),s++;let c=0,d=0,u=Math.min(16,r);for(let p=0;p<u;p++)i[s++]=e[p],c=(c<<8|e[p])^q[c>>>23],d++;c=c>>>0;let l=u,h=0,b=0;for(;l<r;){if(b<ee){c^=pt[e[l-16]],c=((c<<8|e[l])^q[c>>>23])>>>0;let p=c&n.hashMask,y=n.buckets[p],x=n.buckets[p+1];for(let R=y;R<x;R++){let m=n.entries[R];if(m.val!==c)continue;let g=m.ptr,k=a.byteLength-g,E=r-l;if(k>E&&(k=E),k<=b)break;let j=0;for(;j<k&&a[g+j]===e[l+j];)j++;if(j>b&&(b=j,h=g,b>=ee))break}}if(b<ut)f(2),d===0&&s++,i[s++]=e[l++],d++,d===ht&&(i[s-d-1]=d,d=0),b=0;else{if(d>0){for(;h>0&&a[h-1]===e[l-1];)if(b++,h--,l--,s--,!(--d>0)){s--,d=-1;break}d>0&&(i[s-d-1]=d),d=0}let p=b>Ce?b-Ce:0;b-=p,f(8);let y=s++,x=128;if(h&255&&(i[s++]=h&255,x|=1),h&65280&&(i[s++]=h>>>8&255,x|=2),h&16711680&&(i[s++]=h>>>16&255,x|=4),h&4278190080&&(i[s++]=h>>>24&255,x|=8),b&255&&(i[s++]=b&255,x|=16),b&65280&&(i[s++]=b>>>8&255,x|=32),i[y]=x,l+=b,h+=b,b=p,h>4294967295&&(b=0),b<ee){c=0;for(let R=-16;R<0;R++)c=(c<<8|e[l+R])^q[c>>>23];c=c>>>0}}if(t&&s>t)return null}return d>0&&(i[s-d-1]=d),t&&s>t?null:i.subarray(0,s)}var He={blob:0,tree:1,commit:2,tag:3};function De(n,e){let t=e?.window??10,o=e?.depth??50,r=n.slice().sort((c,d)=>{let u=He[c.type]??99,l=He[d.type]??99;return u!==l?u-l:d.content.byteLength-c.content.byteLength}),a=new Map,i=[],s=[],f=[];for(let c=0;c<r.length;c++){let d=r[c],u={hash:d.hash,type:d.type,content:d.content,depth:0},l=null,h=null,b=Math.max(0,c-t);for(let p=c-1;p>=b;p--){let y=r[p];if(y.type!==d.type||(a.get(y.hash)?.depth??0)>=o||d.content.byteLength<y.content.byteLength>>>5)continue;let m=s[p-b]??null;if(!m)continue;let g=l?l.byteLength:d.content.byteLength/2|0;if(g<16)continue;let k=yt(m,d.content,g);k&&(!l||k.byteLength<l.byteLength)&&(l=k,h=y.hash)}if(l&&h){u.delta=l,u.deltaBase=h;let p=a.get(h);u.depth=(p?.depth??0)+1}a.set(d.hash,u),i.push(u),s.length>=t&&(s.shift(),f.shift()),s.push(bt(d.content)),f.push(d.hash)}return i}function xt(n){let e=n;return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e<16?16:e}function Le(n,e,t){let o=t;do{let r=o&127;o>>>=7,o>0&&(r|=128),n[e++]=r}while(o>0);return e}async function te(n,e,t){let o=new Set;for(let i of t)await L(n,i,o);let r=[],a=new Set;for(let i of e)await D(n,i,o,a,r);return{count:r.length,objects:mt(r)}}async function Be(n,e,t){let{count:o,objects:r}=await te(n,e,t);return{count:o,objects:gt(n,r)}}async function*mt(n){for(let e of n)yield e}async function*gt(n,e){for await(let t of e){let o=await H(n,t.hash);yield{hash:t.hash,type:t.type,content:o.content}}}async function Ne(n){let e=[];for await(let t of n.objects)e.push(t);return e}async function L(n,e,t){if(t.has(e)||(t.add(e),!await Ee(n,e)))return;let o=await H(n,e);switch(o.type){case"commit":{let r=C(o.content);await L(n,r.tree,t);for(let a of r.parents)await L(n,a,t);break}case"tree":{let r=Q(o.content);for(let a of r.entries)await L(n,a.hash,t);break}case"tag":{let r=P(o.content);await L(n,r.object,t);break}case"blob":break}}async function D(n,e,t,o,r){if(o.has(e)||t.has(e))return;o.add(e);let a=await H(n,e);switch(r.push({hash:e,type:a.type}),a.type){case"commit":{let i=C(a.content);await D(n,i.tree,t,o,r);for(let s of i.parents)await D(n,s,t,o,r);break}case"tree":{let i=Q(a.content);for(let s of i.entries)await D(n,s.hash,t,o,r);break}case"tag":{let i=P(a.content);await D(n,i.object,t,o,r);break}case"blob":break}}var wt=new TextEncoder,$e=new TextDecoder,We=65520,Rt=new Uint8Array([48,48,48,48]);function w(n){let e=typeof n=="string"?wt.encode(n):n,t=4+e.byteLength;if(t>We)throw new Error(`pkt-line too long: ${t} bytes (max ${We})`);let o=t.toString(16).padStart(4,"0"),r=new Uint8Array(t);return r[0]=o.charCodeAt(0),r[1]=o.charCodeAt(1),r[2]=o.charCodeAt(2),r[3]=o.charCodeAt(3),r.set(e,4),r}function O(){return Rt.slice()}function v(...n){let e=0;for(let r of n)e+=r.byteLength;let t=new Uint8Array(e),o=0;for(let r of n)t.set(r,o),o+=r.byteLength;return t}function _e(n){let e=[],t=0;for(;t<n.byteLength;){if(t+4>n.byteLength)throw new Error("Truncated pkt-line header");let o=$e.decode(n.subarray(t,t+4)),r=parseInt(o,16);if(Number.isNaN(r))throw new Error(`Invalid pkt-line length: ${o}`);if(r===0){e.push({type:"flush"}),t+=4;continue}if(r<4)throw new Error(`Invalid pkt-line length: ${r}`);if(t+r>n.byteLength)throw new Error(`Truncated pkt-line: need ${r} bytes at offset ${t}, have ${n.byteLength-t}`);e.push({type:"data",data:n.subarray(t+4,t+r)}),t+=r}return e}function Ge(n){if(n.type==="flush")return"";let e=$e.decode(n.data);return e.endsWith(`
|
|
8
|
+
`)?e.slice(0,-1):e}var Me=65514;function Fe(n,e,t,o){let r=[];r.push(w(`# service=${e}
|
|
9
|
+
`)),r.push(O());let a=[...t];o&&a.push(`symref=HEAD:${o}`),a.push("agent=just-git/1.0");let i=a.join(" ");if(n.length===0)r.push(w(`0000000000000000000000000000000000000000 capabilities^{}\0${i}
|
|
10
|
+
`));else for(let s=0;s<n.length;s++){let f=n[s];s===0?r.push(w(`${f.hash} ${f.name}\0${i}
|
|
11
11
|
`)):r.push(w(`${f.hash} ${f.name}
|
|
12
|
-
`))}return r.push(O()),v(...r)}function
|
|
13
|
-
`));let r=t[t.length-1];
|
|
14
|
-
`)),
|
|
15
|
-
`))}else
|
|
16
|
-
`));if(e){let r=0;for(;r<n.byteLength;){let a=Math.min(
|
|
17
|
-
`));let r=t[t.length-1];
|
|
18
|
-
`)),
|
|
19
|
-
`))}else
|
|
20
|
-
`));if(yield v(...
|
|
21
|
-
`)?l.slice(0,-1):l}let u=d.split(" ");u.length>=3&&t.push({oldHash:u[0],newHash:u[1],refName:u[2]})}let a=r<n.byteLength?n.subarray(r):new Uint8Array(0);return{commands:t,packData:a,capabilities:
|
|
12
|
+
`))}return r.push(O()),v(...r)}function qe(n){let e=_e(n),t=[],o=[],r=[];for(let a of e){if(a.type==="flush")continue;let i=Ge(a);if(i.startsWith("want ")){let s=i.slice(5);if(t.length===0){let f=s.indexOf(" ");f!==-1?(t.push(s.slice(0,f)),r=s.slice(f+1).split(" ").filter(Boolean)):t.push(s)}else t.push(s)}else i.startsWith("have ")&&o.push(i.slice(5))}return{wants:t,haves:o,capabilities:r}}function I(n,e,t){let o=[];if(t&&t.length>0){for(let a of t)o.push(w(`ACK ${a} common
|
|
13
|
+
`));let r=t[t.length-1];o.push(w(`ACK ${r} ready
|
|
14
|
+
`)),o.push(w(`ACK ${r}
|
|
15
|
+
`))}else o.push(w(`NAK
|
|
16
|
+
`));if(e){let r=0;for(;r<n.byteLength;){let a=Math.min(Me,n.byteLength-r);o.push(ne(1,n.subarray(r,r+a))),r+=a}o.push(O())}else{let r=new Uint8Array(n.byteLength);r.set(n),o.push(r)}return v(...o)}async function*ze(n,e,t){let o=[];if(t&&t.length>0){for(let a of t)o.push(w(`ACK ${a} common
|
|
17
|
+
`));let r=t[t.length-1];o.push(w(`ACK ${r} ready
|
|
18
|
+
`)),o.push(w(`ACK ${r}
|
|
19
|
+
`))}else o.push(w(`NAK
|
|
20
|
+
`));if(yield v(...o),e){for await(let r of n){let a=0;for(;a<r.byteLength;){let i=Math.min(Me,r.byteLength-a);yield ne(1,r.subarray(a,a+i)),a+=i}}yield O()}else for await(let r of n)yield r}function Ke(n){let e=new TextDecoder,t=[],o=[],r=0;for(;r<n.byteLength&&!(r+4>n.byteLength);){let i=e.decode(n.subarray(r,r+4)),s=parseInt(i,16);if(Number.isNaN(s))break;if(s===0){r+=4;break}if(s<4||r+s>n.byteLength)break;let f=n.subarray(r+4,r+s);r+=s;let c=f.indexOf(0),d;if(c!==-1)d=e.decode(f.subarray(0,c)),o=e.decode(f.subarray(c+1)).replace(/\n$/,"").split(" ").filter(Boolean);else{let l=e.decode(f);d=l.endsWith(`
|
|
21
|
+
`)?l.slice(0,-1):l}let u=d.split(" ");u.length>=3&&t.push({oldHash:u[0],newHash:u[1],refName:u[2]})}let a=r<n.byteLength?n.subarray(r):new Uint8Array(0);return{commands:t,packData:a,capabilities:o}}function z(n,e,t){let o=[];o.push(w(n?`unpack ok
|
|
22
22
|
`:`unpack error
|
|
23
|
-
`));for(let a of e)a.ok?
|
|
24
|
-
`)):
|
|
25
|
-
`));
|
|
23
|
+
`));for(let a of e)a.ok?o.push(w(`ok ${a.name}
|
|
24
|
+
`)):o.push(w(`ng ${a.name} ${a.error??"failed"}
|
|
25
|
+
`));o.push(O());let r=v(...o);if(t){let a=[];return a.push(ne(1,r)),a.push(O()),v(...a)}return r}function ne(n,e){let t=new Uint8Array(1+e.byteLength);return t[0]=n,t.set(e,1),w(t)}var A=class{entries=new Map;currentBytes=0;maxBytes;hits=0;misses=0;constructor(e=256*1024*1024){this.maxBytes=e}static key(e,t,o){if(o.length>0)return null;let r=t.slice().sort();return`${e}\0${r.join(",")}`}get(e){let t=this.entries.get(e);return t?this.hits++:this.misses++,t}set(e,t){if(this.entries.has(e))return;let o=t.packData.byteLength;if(!(o>this.maxBytes)){for(;this.currentBytes+o>this.maxBytes&&this.entries.size>0;){let r=this.entries.keys().next().value;this.currentBytes-=this.entries.get(r).packData.byteLength,this.entries.delete(r)}this.entries.set(e,t),this.currentBytes+=o}}get stats(){return{entries:this.entries.size,bytes:this.currentBytes,hits:this.hits,misses:this.misses}}},kt=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag"],Pt=["report-status","side-band-64k","ofs-delta","delete-refs"];async function re(n){let e=await n.refStore.listRefs("refs"),t=await n.refStore.readRef("HEAD"),o=[],r=null,a;if(t)if(t.type==="symbolic"){a=t.target;let i=await n.refStore.readRef(t.target);i?.type==="direct"&&(r=i.hash)}else r=t.hash;r&&o.push({name:"HEAD",hash:r});for(let i of e)if(o.push({name:i.name,hash:i.hash}),i.name.startsWith("refs/tags/"))try{let s=await n.objectStore.read(i.hash);if(s.type==="tag"){let f=P(s.content);o.push({name:`${i.name}^{}`,hash:f.object})}}catch{}return{refs:o,headTarget:a}}function oe(n,e,t){return Fe(n,e,e==="git-upload-pack"?kt:Pt,t)}async function se(n,e,t){let{wants:o,haves:r,capabilities:a}=qe(e);if(o.length===0)return I(new Uint8Array(0),!1);let i=a.includes("multi_ack_detailed"),s=a.includes("side-band-64k"),f;if(i&&r.length>0){f=[];for(let d of r)await n.objectStore.exists(d)&&f.push(d);f.length===0&&(f=void 0)}let c=t?.cache&&t.cacheKey?A.key(t.cacheKey,o,r):null;if(c&&t?.cache){let d=t.cache.get(c);if(d)return I(d.packData,s,f)}return t?.noDelta?Ot(n,o,r,a,s,f):jt(n,o,r,a,s,f,t,c)}async function Ot(n,e,t,o,r,a){let{count:i,objects:s}=await te(n,e,t);if(i===0){let p=I(new Uint8Array(0),r,a);return new ReadableStream({start(y){y.enqueue(p),y.close()}})}let f=[];for await(let p of s)f.push(p);let c=new Set(f.map(p=>p.hash)),d=[];if(o.includes("include-tag")){let p=await n.refStore.listRefs("refs/tags");for(let y of p)if(!c.has(y.hash))try{let x=await n.objectStore.read(y.hash);if(x.type==="tag"){let R=P(x.content);c.has(R.object)&&d.push({hash:y.hash,type:"tag",content:x.content})}}catch{}}let u=f.length+d.length;async function*l(){for(let p of f){let y=await n.objectStore.read(p.hash);yield{type:y.type,content:y.content}}for(let p of d)yield{type:p.type,content:p.content}}let h=Ie(u,l()),b=ze(h,r,a);return new ReadableStream({async pull(p){let{value:y,done:x}=await b.next();x?p.close():p.enqueue(y)}})}async function jt(n,e,t,o,r,a,i,s){let f=await Be(n,e,t);if(f.count===0)return I(new Uint8Array(0),r,a);let c=await Ne(f),d=new Set(c.map(p=>p.hash));if(o.includes("include-tag")){let p=await n.refStore.listRefs("refs/tags");for(let y of p)if(!d.has(y.hash))try{let x=await n.objectStore.read(y.hash);if(x.type==="tag"){let R=P(x.content);d.has(R.object)&&(c.push({hash:y.hash,type:"tag",content:x.content}),d.add(y.hash))}}catch{}}let u=i?.deltaWindow?{window:i.deltaWindow}:void 0,l=De(c,u),h=l.map(p=>({hash:p.hash,type:p.type,content:p.content,delta:p.delta,deltaBaseHash:p.deltaBase})),{data:b}=await ve(h);if(s&&i?.cache){let p=l.filter(y=>y.delta).length;i.cache.set(s,{packData:b,objectCount:c.length,deltaCount:p})}return I(b,r,a)}async function ae(n,e){let{commands:t,packData:o,capabilities:r}=Ke(e),a=!0;if(o.byteLength>0)try{await n.objectStore.ingestPack(o)}catch{a=!1}let i=[];for(let s of t){let f=s.oldHash===K,c=s.newHash===K,d=!1;if(!f&&!c&&a)try{d=await Te(n,s.oldHash,s.newHash)}catch{}i.push({ref:s.refName,oldHash:f?null:s.oldHash,newHash:s.newHash,isFF:d,isCreate:f,isDelete:c})}return{updates:i,unpackOk:a,capabilities:r}}function vt(n){let{resolveRepo:e,hooks:t,basePath:o}=n,r=n.packCache===!1?void 0:new A(n.packCache?.maxBytes);return{async fetch(a){try{let i=new URL(a.url),s=decodeURIComponent(i.pathname);if(o){let f=o.replace(/\/+$/,"");if(!s.startsWith(f))return new Response("Not Found",{status:404});s=s.slice(f.length)}if(s.startsWith("/")||(s=`/${s}`),s.endsWith("/info/refs")&&a.method==="GET"){let f=i.searchParams.get("service");if(f!=="git-upload-pack"&&f!=="git-receive-pack")return new Response("Unsupported service",{status:403});let c=ie(s,"/info/refs"),d=await e(c,a);if(d instanceof Response)return d;if(!d)return new Response("Not Found",{status:404});let u=d,{refs:l,headTarget:h}=await re(u),b=l;if(t?.advertiseRefs){let y=await t.advertiseRefs({repo:u,repoPath:c,refs:l,service:f,request:a});y&&(b=y)}let p=oe(b,f,h);return new Response(p,{headers:{"Content-Type":`application/x-${f}-advertisement`,"Cache-Control":"no-cache"}})}if(s.endsWith("/git-upload-pack")&&a.method==="POST"){let f=ie(s,"/git-upload-pack"),c=await e(f,a);if(c instanceof Response)return c;if(!c)return new Response("Not Found",{status:404});let d=c,u=await Ye(a),l=await se(d,u,{cache:r,cacheKey:f,noDelta:n.packOptions?.noDelta,deltaWindow:n.packOptions?.deltaWindow});return new Response(l,{headers:{"Content-Type":"application/x-git-upload-pack-result"}})}if(s.endsWith("/git-receive-pack")&&a.method==="POST"){let f=ie(s,"/git-receive-pack"),c=await e(f,a);if(c instanceof Response)return c;if(!c)return new Response("Not Found",{status:404});let d=c,u=await Ye(a),{updates:l,unpackOk:h,capabilities:b}=await ae(d,u),p=b.includes("side-band-64k"),y=b.includes("report-status");if(!h){if(y){let m=l.map(g=>({name:g.ref,ok:!1,error:"unpack failed"}));return new Response(z(!1,m,p),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response(new Uint8Array(0),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}if(t?.preReceive){let m=await t.preReceive({repo:d,repoPath:f,updates:l,request:a});if(S(m)){if(y){let g=m.message??"pre-receive hook declined",k=l.map(E=>({name:E.ref,ok:!1,error:g}));return new Response(z(!0,k,p),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response(new Uint8Array(0),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}}let x=[],R=[];for(let m of l){if(t?.update){let g=await t.update({repo:d,repoPath:f,update:m,request:a});if(S(g)){x.push({ref:m.ref,ok:!1,error:g.message??"update hook declined"});continue}}try{let g=m.isCreate?null:m.oldHash,k=m.isDelete?null:{type:"direct",hash:m.newHash};if(!await d.refStore.compareAndSwapRef(m.ref,g,k)){x.push({ref:m.ref,ok:!1,error:"failed to lock"});continue}x.push({ref:m.ref,ok:!0}),R.push(m)}catch(g){x.push({ref:m.ref,ok:!1,error:g instanceof Error?g.message:String(g)})}}if(t?.postReceive&&R.length>0)try{await t.postReceive({repo:d,repoPath:f,updates:R,request:a})}catch{}if(y){let m=x.map(g=>({name:g.ref,ok:g.ok,error:g.error}));return new Response(z(!0,m,p),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response(new Uint8Array(0),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response("Not Found",{status:404})}catch(i){return console.error(" [server] Internal error:",i),new Response("Internal Server Error",{status:500})}}}}function ie(n,e){let t=n.slice(0,-e.length);return t.startsWith("/")&&(t=t.slice(1)),t}async function Ye(n){let e=new Uint8Array(await n.arrayBuffer()),t=n.headers.get("content-encoding");if(t==="gzip"||t==="x-gzip"){let o=new DecompressionStream("gzip"),r=o.writable.getWriter();return r.write(e),r.close(),new Uint8Array(await new Response(o.readable).arrayBuffer())}return e}function It(...n){let e=n.filter(s=>s!=null);if(e.length===0)return{};if(e.length===1)return e[0];let t={},o=e.filter(s=>s.preReceive).map(s=>s.preReceive);o.length>0&&(t.preReceive=async s=>{for(let f of o){let c=await f(s);if(S(c))return c}});let r=e.filter(s=>s.update).map(s=>s.update);r.length>0&&(t.update=async s=>{for(let f of r){let c=await f(s);if(S(c))return c}});let a=e.filter(s=>s.postReceive).map(s=>s.postReceive);a.length>0&&(t.postReceive=async s=>{for(let f of a)try{await f(s)}catch{}});let i=e.filter(s=>s.advertiseRefs).map(s=>s.advertiseRefs);return i.length>0&&(t.advertiseRefs=async s=>{let f=s.refs;for(let c of i){let d=await c({...s,refs:f});d&&(f=d)}return f}),t}function At(n){let{protectedBranches:e=[],denyNonFastForward:t=!1,denyDeletes:o=!1,denyDeleteTags:r=!1,authorize:a,onPush:i}=n,s=new Set(e.map(c=>c.startsWith("refs/")?c:`refs/heads/${c}`)),f={};return(a||s.size>0)&&(f.preReceive=async c=>{if(a&&!await a(c.request))return{reject:!0,message:"unauthorized"};for(let d of c.updates)if(s.has(d.ref)){if(d.isDelete)return{reject:!0,message:`cannot delete protected branch ${d.ref}`};if(!d.isCreate&&!d.isFF)return{reject:!0,message:`non-fast-forward push to protected branch ${d.ref}`}}}),(t||o||r)&&(f.update=async c=>{if(o&&c.update.isDelete)return{reject:!0,message:"ref deletion denied"};if(r&&c.update.ref.startsWith("refs/tags/")){if(c.update.isDelete)return{reject:!0,message:"tag deletion denied"};if(!c.update.isCreate)return{reject:!0,message:"tag overwrite denied"}}if(t&&!c.update.isCreate&&!c.update.isDelete&&!c.update.isFF)return{reject:!0,message:"non-fast-forward"}}),i&&(f.postReceive=i),f}var Et=`
|
|
26
26
|
CREATE TABLE IF NOT EXISTS git_objects (
|
|
27
27
|
repo_id TEXT NOT NULL,
|
|
28
28
|
hash TEXT NOT NULL,
|
|
@@ -39,4 +39,4 @@ CREATE TABLE IF NOT EXISTS git_refs (
|
|
|
39
39
|
target TEXT,
|
|
40
40
|
PRIMARY KEY (repo_id, name)
|
|
41
41
|
) WITHOUT ROWID;
|
|
42
|
-
`;function
|
|
42
|
+
`;function St(n){return{objInsert:n.prepare("INSERT OR IGNORE INTO git_objects (repo_id, hash, type, content) VALUES (?, ?, ?, ?)"),objRead:n.prepare("SELECT type, content FROM git_objects WHERE repo_id = ? AND hash = ?"),objExists:n.prepare("SELECT 1 FROM git_objects WHERE repo_id = ? AND hash = ? LIMIT 1"),objPrefix:n.prepare("SELECT hash FROM git_objects WHERE repo_id = ? AND hash GLOB ?"),objDeleteAll:n.prepare("DELETE FROM git_objects WHERE repo_id = ?"),refRead:n.prepare("SELECT type, hash, target FROM git_refs WHERE repo_id = ? AND name = ?"),refWrite:n.prepare("INSERT OR REPLACE INTO git_refs (repo_id, name, type, hash, target) VALUES (?, ?, ?, ?, ?)"),refDelete:n.prepare("DELETE FROM git_refs WHERE repo_id = ? AND name = ?"),refList:n.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ? AND name GLOB ?"),refListAll:n.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ?"),refDeleteAll:n.prepare("DELETE FROM git_refs WHERE repo_id = ?")}}var ce=class{db;stmts;ingestTx;constructor(e){this.db=e,e.run(Et),this.stmts=St(e),this.ingestTx=e.transaction(t=>{for(let o of t)this.stmts.objInsert.run(o.repoId,o.hash,o.type,o.content)})}repo(e){return{objectStore:new fe(this.stmts,this.ingestTx,e),refStore:new de(this.stmts,this.db,e)}}deleteRepo(e){this.stmts.objDeleteAll.run(e),this.stmts.refDeleteAll.run(e)}},fe=class{constructor(e,t,o){this.stmts=e;this.ingestTx=t;this.repoId=o;this.cache=new _}cache;async write(e,t){let o=Ae(e,t),r=await be(o);return this.stmts.objInsert.run(this.repoId,r,e,t),r}async read(e){let t=this.cache.get(e);if(t)return t;let o=this.stmts.objRead.get(this.repoId,e);if(!o)throw new Error(`object ${e} not found`);let r={type:o.type,content:new Uint8Array(o.content)};return this.cache.set(e,r),r}async exists(e){return this.stmts.objExists.get(this.repoId,e)!==null}async ingestPack(e){if(e.byteLength<32||new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8)===0)return 0;let r=await je(e,async i=>{let s=this.stmts.objRead.get(this.repoId,i);return s?{type:s.type,content:new Uint8Array(s.content)}:null}),a=r.map(i=>({repoId:this.repoId,hash:i.hash,type:i.type,content:i.content}));return this.ingestTx(a),r.length}async findByPrefix(e){return e.length<4?[]:this.stmts.objPrefix.all(this.repoId,`${e}*`).map(o=>o.hash)}},de=class{constructor(e,t,o){this.stmts=e;this.repoId=o;let r=e,a=o;this.casTx=t.transaction((i,s,f)=>{let c=r.refRead.get(a,i),d=null;if(c&&(c.type==="direct"?d=c.hash:c.type==="symbolic"&&c.target&&(d=le(r,a,c.target))),s===null){if(c!==null)return!1}else if(d!==s)return!1;return f===null?r.refDelete.run(a,i):f.type==="symbolic"?r.refWrite.run(a,i,"symbolic",null,f.target):r.refWrite.run(a,i,"direct",f.hash,null),!0})}casTx;async readRef(e){let t=this.stmts.refRead.get(this.repoId,e);return t?t.type==="symbolic"?{type:"symbolic",target:t.target}:{type:"direct",hash:t.hash}:null}async writeRef(e,t){t.type==="symbolic"?this.stmts.refWrite.run(this.repoId,e,"symbolic",null,t.target):this.stmts.refWrite.run(this.repoId,e,"direct",t.hash,null)}async deleteRef(e){this.stmts.refDelete.run(this.repoId,e)}async compareAndSwapRef(e,t,o){return this.casTx(e,t,o)}async listRefs(e){let t;e?t=this.stmts.refList.all(this.repoId,`${e}*`):t=this.stmts.refListAll.all(this.repoId);let o=[];for(let r of t)if(r.type==="direct"&&r.hash)o.push({name:r.name,hash:r.hash});else if(r.type==="symbolic"&&r.target){let a=le(this.stmts,this.repoId,r.target);a&&o.push({name:r.name,hash:a})}return o}};function le(n,e,t,o=0){if(o>10)return null;let r=n.refRead.get(e,t);return r?r.type==="direct"?r.hash:r.type==="symbolic"&&r.target?le(n,e,r.target,o+1):null:null}export{A as PackCache,ce as SqliteStorage,oe as buildRefAdvertisementBytes,re as collectRefs,It as composeHooks,vt as createGitServer,At as createStandardHooks,se as handleUploadPack,ae as ingestReceivePack};
|