just-git 1.5.13 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -4
- package/dist/{hooks-B50z7ycn.d.ts → hooks-pZgz2y6k.d.ts} +2 -0
- package/dist/index.d.ts +14 -3
- package/dist/index.js +359 -361
- package/dist/merge-ort-BYMritNd.d.ts +40 -0
- package/dist/repo/index.d.ts +30 -67
- package/dist/repo/index.js +12 -12
- package/dist/server/index.d.ts +85 -22
- package/dist/server/index.js +37 -37
- package/dist/{writing-BYrXF-yM.d.ts → writing-O7uuLVT_.d.ts} +1 -1
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
var He=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});function U(r){return r!=null&&typeof r=="object"&&"reject"in r&&r.reject===!0}var Y="0000000000000000000000000000000000000000",Ht=(()=>{let r=new Array(256);for(let e=0;e<256;e++)r[e]=(e>>4).toString(16)+(e&15).toString(16);return r})();function De(r){let e="";for(let t=0;t<20;t++)e+=Ht[r[t]];return e}function le(r,e){let t="";for(let n=0;n<20;n++)t+=Ht[r[e+n]];return t}function de(r){let e=new Uint8Array(20);for(let t=0;t<20;t++)e[t]=parseInt(r.slice(t*2,t*2+2),16);return e}var Kr=new Set(["tree","commit","tag"]),_e=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(!Kr.has(t.type))return;let n=t.content.byteLength;if(!(n>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+n>this.maxBytes&&this.map.size>0;){let s=this.map.keys().next().value;this.currentBytes-=this.map.get(s).content.byteLength,this.map.delete(s)}this.map.set(e,t),this.currentBytes+=n}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var Yr=new TextEncoder;function Ze(r){return typeof r=="string"?Yr.encode(r):r}function Zr(){if(typeof globalThis.Bun<"u")return()=>{let r=new Bun.CryptoHasher("sha1"),e={update(t){return r.update(Ze(t)),e},hex:()=>Promise.resolve(r.digest("hex"))};return e};try{let r=He(["node","crypto"].join(":"));if(typeof r.createHash=="function")return()=>{let e=r.createHash("sha1"),t={update(n){return e.update(Ze(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let r=[],e={update(t){return r.push(Ze(t)),e},async hex(){let t=0;for(let i of r)t+=i.byteLength;let n=new Uint8Array(t),s=0;for(let i of r)n.set(i,s),s+=i.byteLength;let a=await crypto.subtle.digest("SHA-1",n);return De(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 Dt=Zr(),Z=Dt;async function _t(r){return Dt().update(r).hex()}var M=Uint8Array,J=Uint16Array,Jr=Int32Array,Nt=new M([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Bt=new M([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Qr=new M([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ft=(r,e)=>{let t=new J(31);for(let s=0;s<31;++s)t[s]=e+=1<<r[s-1];let n=new Jr(t[30]);for(let s=1;s<30;++s)for(let a=t[s];a<t[s+1];++a)n[a]=a-t[s]<<5|s;return{b:t,r:n}},{b:Mt}=Ft(Nt,2);Mt[28]=258;var{b:en}=Ft(Bt,0),et=new J(32768);for(let r=0;r<32768;++r){let e=(r&43690)>>1|(r&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,et[r]=((e&65280)>>8|(e&255)<<8)>>1}var ue=(r,e,t)=>{let n=r.length,s=0,a=new J(e);for(;s<n;++s)r[s]&&++a[r[s]-1];let i=new J(e);for(s=1;s<e;++s)i[s]=i[s-1]+a[s-1]<<1;let o;if(t){o=new J(1<<e);let f=15-e;for(s=0;s<n;++s)if(r[s]){let c=s<<4|r[s],l=e-r[s],d=i[r[s]-1]++<<l;for(let u=d|(1<<l)-1;d<=u;++d)o[et[d]>>f]=c}}else for(o=new J(n),s=0;s<n;++s)r[s]&&(o[s]=et[i[r[s]-1]++]>>15-r[s]);return o},pe=new M(288);for(let r=0;r<144;++r)pe[r]=8;for(let r=144;r<256;++r)pe[r]=9;for(let r=256;r<280;++r)pe[r]=7;for(let r=280;r<288;++r)pe[r]=8;var Wt=new M(32);for(let r=0;r<32;++r)Wt[r]=5;var tn=ue(pe,9,1),rn=ue(Wt,5,1),Je=r=>{let e=r[0];for(let t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},F=(r,e,t)=>{let n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},Qe=(r,e)=>{let t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},$t=r=>(r+7)/8|0,nn=(r,e,t)=>((e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new M(r.subarray(e,t))),$=(r,e)=>{let t=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||t[r]||"unknown inflate error")},Gt=(r,e,t,n)=>{let s=r.length,a=n?n.length:0;if(!s||e.f&&!e.l)return t||new M(0);let i=!t,o=i||e.i!=2,f=e.i;i&&(t=new M(s*3));let c=k=>{let x=t.length;if(k>x){let m=new M(Math.max(x*2,k));m.set(t),t=m}},l=e.f||0,d=e.p||0,u=e.b||0,h=e.l,p=e.d,g=e.m,w=e.n,O=s*8;do{if(!h){l=F(r,d,1);let b=F(r,d+1,3);if(d+=3,b)if(b==1)h=tn,p=rn,g=9,w=5;else if(b==2){let y=F(r,d,31)+257,R=F(r,d+10,15)+4,P=y+F(r,d+5,31)+1;d+=14;let A=new M(P),S=new M(19);for(let L=0;L<R;++L)S[Qr[L]]=F(r,d+L*3,7);d+=R*3;let v=Je(S),j=(1<<v)-1,C=ue(S,v,1);for(let L=0;L<P;){let q=C[F(r,d,j)];d+=q&15;let fe=q>>4;if(fe<16)A[L++]=fe;else{let Ct=0,Ce=0;for(fe==16?(Ce=3+F(r,d,3),d+=2,Ct=A[L-1]):fe==17?(Ce=3+F(r,d,7),d+=3):fe==18&&(Ce=11+F(r,d,127),d+=7);Ce--;)A[L++]=Ct}}let D=A.subarray(0,y),W=A.subarray(y);g=Je(D),w=Je(W),h=ue(D,g,1),p=ue(W,w,1)}else $(1);else{let y=$t(d)+4,R=r[y-4]|r[y-3]<<8,P=y+R;if(P>s){f&&$(0);break}o&&c(u+R),t.set(r.subarray(y,P),u),e.b=u+=R,e.p=d=P*8,e.f=l;continue}if(d>O){f&&$(0);break}}o&&c(u+131072);let k=(1<<g)-1,x=(1<<w)-1,m=d;for(;;m=d){let b=h[Qe(r,d)&k],y=b>>4;if(d+=b&15,d>O){f&&$(0);break}if(b||$(2),y<256)t[u++]=y;else if(y==256){m=d,h=null;break}else{let R=y-254;if(y>264){let j=y-257,C=Nt[j];R=F(r,d,(1<<C)-1)+Mt[j],d+=C}let P=p[Qe(r,d)&x],A=P>>4;P||$(3),d+=P&15;let S=en[A];if(A>3){let j=Bt[A];S+=Qe(r,d)&(1<<j)-1,d+=j}if(d>O){f&&$(0);break}o&&c(u+131072);let v=u+R;if(u<S){let j=a-S,C=Math.min(S,v);for(j+u<0&&$(3);u<C;++u)t[u]=n[j+u]}for(;u<v;++u)t[u]=t[u-S]}}e.l=h,e.p=m,e.b=u,e.f=l,h&&(l=1,e.m=g,e.d=p,e.n=w)}while(!l);return u!=t.length&&i?nn(t,0,u):t.subarray(0,u)},qt=r=>(((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&$(0,"invalid zlib data"),r[1]&32&&$(0,"zlib dictionaries are not supported"),2);function Vt(r){let e=qt(r);return Gt(r.subarray(e,-4),{i:2})}function tt(r){let e=qt(r),t={i:2},n=Gt(r.subarray(e),t),s=$t(t.p);return{result:n,bytesConsumed:e+s+4}}async function sn(){let r;if(!(typeof document<"u"))try{r=He(["node","zlib"].join(":"))}catch{try{r=await import(["node","zlib"].join(":"))}catch{}}if(r&&typeof r.deflateSync=="function"&&typeof r.inflateSync=="function"){let n=null;try{let s=r.inflateSync(r.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(n=a=>{let i=r.inflateSync(a,{info:!0});return{result:new Uint8Array(i.buffer),bytesConsumed:i.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(r.deflateSync(s)),inflateSync:s=>new Uint8Array(r.inflateSync(s)),inflateWithConsumed:n??tt}}let t;return typeof globalThis.CompressionStream=="function"?t=async n=>{let s=new CompressionStream("deflate"),a=s.writable.getWriter();return a.write(n),a.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:t=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:t,inflateSync:Vt,inflateWithConsumed:tt}}var an=null;function zt(){return an??=sn()}async function Ne(r){return await(await zt()).deflateSync(r)}async function rt(r,e){let t=await zt(),{result:n,bytesConsumed:s}=t.inflateWithConsumed(r);if(n.byteLength!==e)throw new Error(`Inflate size mismatch: got ${n.byteLength}, expected ${e}`);return{result:n,bytesConsumed:s}}var ee=1346454347,Fe=2,Yt=1,Zt=2,Jt=3,Qt=4,V=6,he=7,er={[Yt]:"commit",[Zt]:"tree",[Jt]:"blob",[Qt]:"tag"},tr={commit:Yt,tree:Zt,blob:Jt,tag:Qt};async function rr(r,e){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.getUint32(0);if(n!==ee)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${ee.toString(16)})`);let s=t.getUint32(4);if(s!==Fe)throw new Error(`Unsupported pack version: ${s}`);if(r.byteLength>=32){let c=le(r,r.byteLength-20),l=Z();l.update(r.subarray(0,r.byteLength-20));let d=await l.hex();if(d!==c)throw new Error(`pack checksum mismatch: expected ${c}, computed ${d}`)}let a=t.getUint32(8),i=[],o=12;for(let c=0;c<a;c++){let l=await on(r,o);i.push(l),o=l.nextOffset}return(await cn(i,e)).map((c,l)=>({...c,offset:i[l].headerOffset,nextOffset:i[l].nextOffset}))}async function on(r,e){let t=e,n=r[e++],s=n>>4&7,a=n&15,i=4;for(;n&128;)n=r[e++],a|=(n&127)<<i,i+=7;let o,f;if(s===V){let d=r[e++];for(o=d&127;d&128;)o+=1,d=r[e++],o=(o<<7)+(d&127);o=t-o}else s===he&&(f=le(r,e),e+=20);let{result:c,bytesConsumed:l}=await rt(r.subarray(e),a);return{headerOffset:t,typeNum:s,inflated:c,baseOffset:o,baseHash:f,nextOffset:e+l}}var Xt=50;async function cn(r,e){let t=new Map;for(let a=0;a<r.length;a++)t.set(r[a].headerOffset,a);let n=new Array(r.length).fill(null);async function s(a,i=0){if(i>Xt)throw new Error(`delta chain depth ${i} exceeds limit of ${Xt}`);let o=n[a];if(o)return o;let f=r[a];if(f.typeNum!==V&&f.typeNum!==he){let h=er[f.typeNum];if(!h)throw new Error(`Unknown object type: ${f.typeNum}`);let p={type:h,content:f.inflated,hash:await Q(h,f.inflated)};return n[a]=p,p}if(f.typeNum===V){let h=t.get(f.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${f.baseOffset}`);let p=await s(h,i+1),g=Be(p.content,f.inflated),w={type:p.type,content:g,hash:await Q(p.type,g)};return n[a]=w,w}let c=await fn(r,n,f.baseHash,s),l;if(c!==void 0)l=await s(c,i+1);else if(e){let h=await e(f.baseHash);h&&(l=h)}if(!l)throw new Error(`REF_DELTA base not found for hash ${f.baseHash}`);let d=Be(l.content,f.inflated),u={type:l.type,content:d,hash:await Q(l.type,d)};return n[a]=u,u}for(let a=0;a<r.length;a++)await s(a);return n}async function fn(r,e,t,n){for(let s=0;s<e.length;s++)if(e[s]?.hash===t)return s;for(let s=0;s<r.length;s++){let a=r[s];if(a.typeNum!==V&&a.typeNum!==he&&(await n(s)).hash===t)return s}}var nt=class{buf=new Uint8Array(0);iter;eof=!1;_bytesRead=0;hasher;constructor(e,t=!1){this.iter=e[Symbol.asyncIterator](),this.hasher=t?Z():null}get bytesRead(){return this._bytesRead}async pullMore(){if(this.eof)return!1;let{value:e,done:t}=await this.iter.next();if(t||!e)return this.eof=!0,!1;if(this.buf.byteLength===0)this.buf=new Uint8Array(e);else{let n=new Uint8Array(this.buf.byteLength+e.byteLength);n.set(this.buf),n.set(e,this.buf.byteLength),this.buf=n}return!0}async ensure(e){for(;this.buf.byteLength<e;)if(!await this.pullMore())throw new Error(`Unexpected end of pack data: needed ${e} bytes, have ${this.buf.byteLength}`)}consume(e){let t=new Uint8Array(this.buf.subarray(0,e));return this.hasher?.update(t),this.buf=this.buf.subarray(e),this._bytesRead+=e,t}async readByte(){return await this.ensure(1),this.consume(1)[0]}async readExact(e){return await this.ensure(e),this.consume(e)}async readRaw(e){await this.ensure(e);let t=new Uint8Array(this.buf.subarray(0,e));return this.buf=this.buf.subarray(e),this._bytesRead+=e,t}async inflateNext(e){for(this.buf.byteLength===0&&!this.eof&&await this.pullMore();;)try{let{result:t,bytesConsumed:n}=await rt(this.buf,e);return this.consume(n),t}catch{if(!this.eof&&await this.pullMore())continue;throw new Error(`Failed to inflate pack entry at byte ${this._bytesRead} (expected ${e} bytes)`)}}async hashHex(){if(!this.hasher)throw new Error("Hashing not enabled");return this.hasher.hex()}};async function*nr(r,e){let t=new nt(r,!0),n=await t.readExact(12),s=new DataView(n.buffer,n.byteOffset,n.byteLength),a=s.getUint32(0);if(a!==ee)throw new Error(`Invalid pack signature: 0x${a.toString(16)} (expected 0x${ee.toString(16)})`);let i=s.getUint32(4);if(i!==Fe)throw new Error(`Unsupported pack version: ${i}`);let o=s.getUint32(8),f=new Map,c=new Map;for(let u=0;u<o;u++){let h=t.bytesRead,p=await t.readByte(),g=p>>4&7,w=p&15,O=4;for(;p&128;)p=await t.readByte(),w|=(p&127)<<O,O+=7;let k,x;if(g===V){let y=await t.readByte();for(k=y&127;y&128;)k+=1,y=await t.readByte(),k=(k<<7)+(y&127);k=h-k}else if(g===he){let y=await t.readExact(20);x=le(y,0)}let m=await t.inflateNext(w),b;if(g!==V&&g!==he){let y=er[g];if(!y)throw new Error(`Unknown object type: ${g}`);b={type:y,content:m,hash:await Q(y,m)}}else if(g===V){let y=f.get(k);if(!y)throw new Error(`OFS_DELTA base not found at offset ${k}`);let R=Be(y.content,m);b={type:y.type,content:R,hash:await Q(y.type,R)}}else{let y=c.get(x);if(!y&&e&&(y=await e(x)??void 0),!y)throw new Error(`REF_DELTA base not found for hash ${x}`);let R=Be(y.content,m);b={type:y.type,content:R,hash:await Q(y.type,R)}}f.set(h,b),c.set(b.hash,b),yield b}let l=le(await t.readRaw(20),0),d=await t.hashHex();if(d!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${d}`)}function Be(r,e){let t=0,{value:n,newPos:s}=Kt(e,t);if(t=s,n!==r.byteLength)throw new Error(`Delta base size mismatch: expected ${n}, got ${r.byteLength}`);let{value:a,newPos:i}=Kt(e,t);t=i;let o=new Uint8Array(a),f=0;for(;t<e.byteLength;){let c=e[t++];if(c&128){let l=0,d=0;c&1&&(l=e[t++]),c&2&&(l|=e[t++]<<8),c&4&&(l|=e[t++]<<16),c&8&&(l|=e[t++]<<24),c&16&&(d=e[t++]),c&32&&(d|=e[t++]<<8),c&64&&(d|=e[t++]<<16),d===0&&(d=65536),o.set(r.subarray(l,l+d),f),f+=d}else if(c>0)o.set(e.subarray(t,t+c),f),f+=c,t+=c;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(f!==a)throw new Error(`Delta produced ${f} bytes, expected ${a}`);return o}async function te(r){let e=[],t=new Map,n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,ee),s.setUint32(4,Fe),s.setUint32(8,r.length),e.push(n);let a=12,i=[];for(let o of r){let f=a;t.set(o.hash,a);let c=o.delta&&o.deltaBaseHash?t.get(o.deltaBaseHash):void 0;if(o.delta&&c!==void 0){let l=st(V,o.delta.byteLength),d=dn(a-c),u=await Ne(o.delta);e.push(l,d,u),a+=l.byteLength+d.byteLength+u.byteLength}else{let l=tr[o.type],d=st(l,o.content.byteLength),u=await Ne(o.content);e.push(d,u),a+=d.byteLength+u.byteLength}i.push({hash:o.hash,offset:f,nextOffset:a})}return{data:await ln(e),entries:i}}async function*sr(r,e){let t=Z(),n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,ee),s.setUint32(4,Fe),s.setUint32(8,r),t.update(n),yield n;for await(let a of e){let i=tr[a.type],o=st(i,a.content.byteLength),f=await Ne(a.content);t.update(o),t.update(f),yield un(o,f)}yield de(await t.hex())}async function ln(r){let e=0;for(let i of r)e+=i.byteLength;e+=20;let t=new Uint8Array(e),n=0;for(let i of r)t.set(i,n),n+=i.byteLength;let s=Z();s.update(t.subarray(0,n));let a=await s.hex();return t.set(de(a),n),t}function dn(r){let e=[];e.push(r&127);let t=r>>>7;for(;t>0;)e.unshift(128|--t&127),t>>>=7;return new Uint8Array(e)}function st(r,e){let t=[],n=r<<4|e&15;for(e>>=4;e>0;)t.push(n|128),n=e&127,e>>=7;return t.push(n),new Uint8Array(t)}function Kt(r,e){let t=0,n=0,s;do s=r[e++],t|=(s&127)<<n,n+=7;while(s&128);return{value:t,newPos:e}}function un(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(r,0),t.set(e,r.byteLength),t}var pn=new TextEncoder;async function Q(r,e){let t=pn.encode(`${r} ${e.byteLength}\0`),n=Z();return n.update(t),n.update(e),n.hex()}var hn=new TextEncoder,js=new TextDecoder;function ar(r,e){let t=hn.encode(`${r} ${e.byteLength}\0`),n=new Uint8Array(t.byteLength+e.byteLength);return n.set(t),n.set(e,t.byteLength),n}function ye(r){let e=r.indexOf("<"),t=r.indexOf(">");if(e===-1||t===-1)throw new Error(`Malformed identity line: "${r}"`);let n=r.slice(0,e).trimEnd(),s=r.slice(e+1,t),a=r.slice(t+2),[i="0",o="+0000"]=a.split(" "),f=parseInt(i,10);return{name:n,email:s,timestamp:f,timezone:o}}function Me(r){return`${r.name} <${r.email}> ${r.timestamp} ${r.timezone}`}var yn=new TextEncoder,mn=new TextDecoder;function me(r){let e=mn.decode(r),t=e.indexOf(`
|
|
1
|
+
var Ce=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});function U(r){return r!=null&&typeof r=="object"&&"reject"in r&&r.reject===!0}var Q="0000000000000000000000000000000000000000",Dt=(()=>{let r=new Array(256);for(let e=0;e<256;e++)r[e]=(e>>4).toString(16)+(e&15).toString(16);return r})();function He(r){let e="";for(let t=0;t<20;t++)e+=Dt[r[t]];return e}function he(r,e){let t="";for(let n=0;n<20;n++)t+=Dt[r[e+n]];return t}function pe(r){let e=new Uint8Array(20);for(let t=0;t<20;t++)e[t]=parseInt(r.slice(t*2,t*2+2),16);return e}var rn=new Set(["tree","commit","tag"]),De=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(!rn.has(t.type))return;let n=t.content.byteLength;if(!(n>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+n>this.maxBytes&&this.map.size>0;){let s=this.map.keys().next().value;this.currentBytes-=this.map.get(s).content.byteLength,this.map.delete(s)}this.map.set(e,t),this.currentBytes+=n}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var nn=new TextEncoder;function Ze(r){return typeof r=="string"?nn.encode(r):r}function sn(){if(typeof globalThis.Bun<"u")return()=>{let r=new Bun.CryptoHasher("sha1"),e={update(t){return r.update(Ze(t)),e},hex:()=>Promise.resolve(r.digest("hex"))};return e};try{let r=Ce(["node","crypto"].join(":"));if(typeof r.createHash=="function")return()=>{let e=r.createHash("sha1"),t={update(n){return e.update(Ze(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let r=[],e={update(t){return r.push(Ze(t)),e},async hex(){let t=0;for(let i of r)t+=i.byteLength;let n=new Uint8Array(t),s=0;for(let i of r)n.set(i,s),s+=i.byteLength;let a=await crypto.subtle.digest("SHA-1",n);return He(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 Mt=sn(),ee=Mt;async function _t(r){return Mt().update(r).hex()}var F=Uint8Array,te=Uint16Array,an=Int32Array,Nt=new F([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Bt=new F([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),on=new F([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ft=(r,e)=>{let t=new te(31);for(let s=0;s<31;++s)t[s]=e+=1<<r[s-1];let n=new an(t[30]);for(let s=1;s<30;++s)for(let a=t[s];a<t[s+1];++a)n[a]=a-t[s]<<5|s;return{b:t,r:n}},{b:$t}=Ft(Nt,2);$t[28]=258;var{b:cn}=Ft(Bt,0),et=new te(32768);for(let r=0;r<32768;++r){let e=(r&43690)>>1|(r&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,et[r]=((e&65280)>>8|(e&255)<<8)>>1}var ye=(r,e,t)=>{let n=r.length,s=0,a=new te(e);for(;s<n;++s)r[s]&&++a[r[s]-1];let i=new te(e);for(s=1;s<e;++s)i[s]=i[s-1]+a[s-1]<<1;let o;if(t){o=new te(1<<e);let f=15-e;for(s=0;s<n;++s)if(r[s]){let c=s<<4|r[s],l=e-r[s],u=i[r[s]-1]++<<l;for(let d=u|(1<<l)-1;u<=d;++u)o[et[u]>>f]=c}}else for(o=new te(n),s=0;s<n;++s)r[s]&&(o[s]=et[i[r[s]-1]++]>>15-r[s]);return o},me=new F(288);for(let r=0;r<144;++r)me[r]=8;for(let r=144;r<256;++r)me[r]=9;for(let r=256;r<280;++r)me[r]=7;for(let r=280;r<288;++r)me[r]=8;var Wt=new F(32);for(let r=0;r<32;++r)Wt[r]=5;var fn=ye(me,9,1),ln=ye(Wt,5,1),Je=r=>{let e=r[0];for(let t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},B=(r,e,t)=>{let n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},Qe=(r,e)=>{let t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},Gt=r=>(r+7)/8|0,un=(r,e,t)=>((e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new F(r.subarray(e,t))),G=(r,e)=>{let t=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||t[r]||"unknown inflate error")},qt=(r,e,t,n)=>{let s=r.length,a=n?n.length:0;if(!s||e.f&&!e.l)return t||new F(0);let i=!t,o=i||e.i!=2,f=e.i;i&&(t=new F(s*3));let c=O=>{let x=t.length;if(O>x){let y=new F(Math.max(x*2,O));y.set(t),t=y}},l=e.f||0,u=e.p||0,d=e.b||0,p=e.l,h=e.d,g=e.m,w=e.n,A=s*8;do{if(!p){l=B(r,u,1);let b=B(r,u+1,3);if(u+=3,b)if(b==1)p=fn,h=ln,g=9,w=5;else if(b==2){let m=B(r,u,31)+257,R=B(r,u+10,15)+4,S=m+B(r,u+5,31)+1;u+=14;let k=new F(S),j=new F(19);for(let I=0;I<R;++I)j[on[I]]=B(r,u+I*3,7);u+=R*3;let v=Je(j),P=(1<<v)-1,H=ye(j,v,1);for(let I=0;I<S;){let V=H[B(r,u,P)];u+=V&15;let de=V>>4;if(de<16)k[I++]=de;else{let Ht=0,Ue=0;for(de==16?(Ue=3+B(r,u,3),u+=2,Ht=k[I-1]):de==17?(Ue=3+B(r,u,7),u+=3):de==18&&(Ue=11+B(r,u,127),u+=7);Ue--;)k[I++]=Ht}}let D=k.subarray(0,m),W=k.subarray(m);g=Je(D),w=Je(W),p=ye(D,g,1),h=ye(W,w,1)}else G(1);else{let m=Gt(u)+4,R=r[m-4]|r[m-3]<<8,S=m+R;if(S>s){f&&G(0);break}o&&c(d+R),t.set(r.subarray(m,S),d),e.b=d+=R,e.p=u=S*8,e.f=l;continue}if(u>A){f&&G(0);break}}o&&c(d+131072);let O=(1<<g)-1,x=(1<<w)-1,y=u;for(;;y=u){let b=p[Qe(r,u)&O],m=b>>4;if(u+=b&15,u>A){f&&G(0);break}if(b||G(2),m<256)t[d++]=m;else if(m==256){y=u,p=null;break}else{let R=m-254;if(m>264){let P=m-257,H=Nt[P];R=B(r,u,(1<<H)-1)+$t[P],u+=H}let S=h[Qe(r,u)&x],k=S>>4;S||G(3),u+=S&15;let j=cn[k];if(k>3){let P=Bt[k];j+=Qe(r,u)&(1<<P)-1,u+=P}if(u>A){f&&G(0);break}o&&c(d+131072);let v=d+R;if(d<j){let P=a-j,H=Math.min(j,v);for(P+d<0&&G(3);d<H;++d)t[d]=n[P+d]}for(;d<v;++d)t[d]=t[d-j]}}e.l=p,e.p=y,e.b=d,e.f=l,p&&(l=1,e.m=g,e.d=h,e.n=w)}while(!l);return d!=t.length&&i?un(t,0,d):t.subarray(0,d)},Vt=r=>(((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&G(0,"invalid zlib data"),r[1]&32&&G(0,"zlib dictionaries are not supported"),2);function zt(r){let e=Vt(r);return qt(r.subarray(e,-4),{i:2})}function tt(r){let e=Vt(r),t={i:2},n=qt(r.subarray(e),t),s=Gt(t.p);return{result:n,bytesConsumed:e+s+4}}async function dn(){let r;if(!(typeof document<"u"))try{r=Ce(["node","zlib"].join(":"))}catch{try{r=await import(["node","zlib"].join(":"))}catch{}}if(r&&typeof r.deflateSync=="function"&&typeof r.inflateSync=="function"){let n=null;try{let s=r.inflateSync(r.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(n=a=>{let i=r.inflateSync(a,{info:!0});return{result:new Uint8Array(i.buffer),bytesConsumed:i.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(r.deflateSync(s)),inflateSync:s=>new Uint8Array(r.inflateSync(s)),inflateWithConsumed:n??tt}}let t;return typeof globalThis.CompressionStream=="function"?t=async n=>{let s=new CompressionStream("deflate"),a=s.writable.getWriter();return a.write(n),a.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:t=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:t,inflateSync:zt,inflateWithConsumed:tt}}var hn=null;function Xt(){return hn??=dn()}async function Me(r){return await(await Xt()).deflateSync(r)}async function rt(r,e){let t=await Xt(),{result:n,bytesConsumed:s}=t.inflateWithConsumed(r);if(n.byteLength!==e)throw new Error(`Inflate size mismatch: got ${n.byteLength}, expected ${e}`);return{result:n,bytesConsumed:s}}var ne=1346454347,Ne=2,Zt=1,Jt=2,Qt=3,er=4,z=6,be=7,tr={[Zt]:"commit",[Jt]:"tree",[Qt]:"blob",[er]:"tag"},rr={commit:Zt,tree:Jt,blob:Qt,tag:er};async function nr(r,e){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.getUint32(0);if(n!==ne)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${ne.toString(16)})`);let s=t.getUint32(4);if(s!==Ne)throw new Error(`Unsupported pack version: ${s}`);if(r.byteLength>=32){let c=he(r,r.byteLength-20),l=ee();l.update(r.subarray(0,r.byteLength-20));let u=await l.hex();if(u!==c)throw new Error(`pack checksum mismatch: expected ${c}, computed ${u}`)}let a=t.getUint32(8),i=[],o=12;for(let c=0;c<a;c++){let l=await pn(r,o);i.push(l),o=l.nextOffset}return(await yn(i,e)).map((c,l)=>({...c,offset:i[l].headerOffset,nextOffset:i[l].nextOffset}))}async function pn(r,e){let t=e,n=r[e++],s=n>>4&7,a=n&15,i=4;for(;n&128;)n=r[e++],a|=(n&127)<<i,i+=7;let o,f;if(s===z){let u=r[e++];for(o=u&127;u&128;)o+=1,u=r[e++],o=(o<<7)+(u&127);o=t-o}else s===be&&(f=he(r,e),e+=20);let{result:c,bytesConsumed:l}=await rt(r.subarray(e),a);return{headerOffset:t,typeNum:s,inflated:c,baseOffset:o,baseHash:f,nextOffset:e+l}}var Kt=50;async function yn(r,e){let t=new Map;for(let a=0;a<r.length;a++)t.set(r[a].headerOffset,a);let n=new Array(r.length).fill(null);async function s(a,i=0){if(i>Kt)throw new Error(`delta chain depth ${i} exceeds limit of ${Kt}`);let o=n[a];if(o)return o;let f=r[a];if(f.typeNum!==z&&f.typeNum!==be){let p=tr[f.typeNum];if(!p)throw new Error(`Unknown object type: ${f.typeNum}`);let h={type:p,content:f.inflated,hash:await re(p,f.inflated)};return n[a]=h,h}if(f.typeNum===z){let p=t.get(f.baseOffset);if(p===void 0)throw new Error(`OFS_DELTA base not found at offset ${f.baseOffset}`);let h=await s(p,i+1),g=_e(h.content,f.inflated),w={type:h.type,content:g,hash:await re(h.type,g)};return n[a]=w,w}let c=await mn(r,n,f.baseHash,s),l;if(c!==void 0)l=await s(c,i+1);else if(e){let p=await e(f.baseHash);p&&(l=p)}if(!l)throw new Error(`REF_DELTA base not found for hash ${f.baseHash}`);let u=_e(l.content,f.inflated),d={type:l.type,content:u,hash:await re(l.type,u)};return n[a]=d,d}for(let a=0;a<r.length;a++)await s(a);return n}async function mn(r,e,t,n){for(let s=0;s<e.length;s++)if(e[s]?.hash===t)return s;for(let s=0;s<r.length;s++){let a=r[s];if(a.typeNum!==z&&a.typeNum!==be&&(await n(s)).hash===t)return s}}var nt=class{buf=new Uint8Array(0);iter;eof=!1;_bytesRead=0;hasher;constructor(e,t=!1){this.iter=e[Symbol.asyncIterator](),this.hasher=t?ee():null}get bytesRead(){return this._bytesRead}async pullMore(){if(this.eof)return!1;let{value:e,done:t}=await this.iter.next();if(t||!e)return this.eof=!0,!1;if(this.buf.byteLength===0)this.buf=new Uint8Array(e);else{let n=new Uint8Array(this.buf.byteLength+e.byteLength);n.set(this.buf),n.set(e,this.buf.byteLength),this.buf=n}return!0}async ensure(e){for(;this.buf.byteLength<e;)if(!await this.pullMore())throw new Error(`Unexpected end of pack data: needed ${e} bytes, have ${this.buf.byteLength}`)}consume(e){let t=new Uint8Array(this.buf.subarray(0,e));return this.hasher?.update(t),this.buf=this.buf.subarray(e),this._bytesRead+=e,t}async readByte(){return await this.ensure(1),this.consume(1)[0]}async readExact(e){return await this.ensure(e),this.consume(e)}async readRaw(e){await this.ensure(e);let t=new Uint8Array(this.buf.subarray(0,e));return this.buf=this.buf.subarray(e),this._bytesRead+=e,t}async inflateNext(e){for(this.buf.byteLength===0&&!this.eof&&await this.pullMore();;)try{let{result:t,bytesConsumed:n}=await rt(this.buf,e);return this.consume(n),t}catch{if(!this.eof&&await this.pullMore())continue;throw new Error(`Failed to inflate pack entry at byte ${this._bytesRead} (expected ${e} bytes)`)}}async hashHex(){if(!this.hasher)throw new Error("Hashing not enabled");return this.hasher.hex()}};async function*sr(r,e){let t=new nt(r,!0),n=await t.readExact(12),s=new DataView(n.buffer,n.byteOffset,n.byteLength),a=s.getUint32(0);if(a!==ne)throw new Error(`Invalid pack signature: 0x${a.toString(16)} (expected 0x${ne.toString(16)})`);let i=s.getUint32(4);if(i!==Ne)throw new Error(`Unsupported pack version: ${i}`);let o=s.getUint32(8),f=new Map,c=new Map;for(let d=0;d<o;d++){let p=t.bytesRead,h=await t.readByte(),g=h>>4&7,w=h&15,A=4;for(;h&128;)h=await t.readByte(),w|=(h&127)<<A,A+=7;let O,x;if(g===z){let m=await t.readByte();for(O=m&127;m&128;)O+=1,m=await t.readByte(),O=(O<<7)+(m&127);O=p-O}else if(g===be){let m=await t.readExact(20);x=he(m,0)}let y=await t.inflateNext(w),b;if(g!==z&&g!==be){let m=tr[g];if(!m)throw new Error(`Unknown object type: ${g}`);b={type:m,content:y,hash:await re(m,y)}}else if(g===z){let m=f.get(O);if(!m)throw new Error(`OFS_DELTA base not found at offset ${O}`);let R=_e(m.content,y);b={type:m.type,content:R,hash:await re(m.type,R)}}else{let m=c.get(x);if(!m&&e&&(m=await e(x)??void 0),!m)throw new Error(`REF_DELTA base not found for hash ${x}`);let R=_e(m.content,y);b={type:m.type,content:R,hash:await re(m.type,R)}}f.set(p,b),c.set(b.hash,b),yield b}let l=he(await t.readRaw(20),0),u=await t.hashHex();if(u!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${u}`)}function _e(r,e){let t=0,{value:n,newPos:s}=Yt(e,t);if(t=s,n!==r.byteLength)throw new Error(`Delta base size mismatch: expected ${n}, got ${r.byteLength}`);let{value:a,newPos:i}=Yt(e,t);t=i;let o=new Uint8Array(a),f=0;for(;t<e.byteLength;){let c=e[t++];if(c&128){let l=0,u=0;c&1&&(l=e[t++]),c&2&&(l|=e[t++]<<8),c&4&&(l|=e[t++]<<16),c&8&&(l|=e[t++]<<24),c&16&&(u=e[t++]),c&32&&(u|=e[t++]<<8),c&64&&(u|=e[t++]<<16),u===0&&(u=65536),o.set(r.subarray(l,l+u),f),f+=u}else if(c>0)o.set(e.subarray(t,t+c),f),f+=c,t+=c;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(f!==a)throw new Error(`Delta produced ${f} bytes, expected ${a}`);return o}async function se(r){let e=[],t=new Map,n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,ne),s.setUint32(4,Ne),s.setUint32(8,r.length),e.push(n);let a=12,i=[];for(let o of r){let f=a;t.set(o.hash,a);let c=o.delta&&o.deltaBaseHash?t.get(o.deltaBaseHash):void 0;if(o.delta&&c!==void 0){let l=st(z,o.delta.byteLength),u=gn(a-c),d=await Me(o.delta);e.push(l,u,d),a+=l.byteLength+u.byteLength+d.byteLength}else{let l=rr[o.type],u=st(l,o.content.byteLength),d=await Me(o.content);e.push(u,d),a+=u.byteLength+d.byteLength}i.push({hash:o.hash,offset:f,nextOffset:a})}return{data:await bn(e),entries:i}}async function*ar(r,e){let t=ee(),n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,ne),s.setUint32(4,Ne),s.setUint32(8,r),t.update(n),yield n;for await(let a of e){let i=rr[a.type],o=st(i,a.content.byteLength),f=await Me(a.content);t.update(o),t.update(f),yield wn(o,f)}yield pe(await t.hex())}async function bn(r){let e=0;for(let i of r)e+=i.byteLength;e+=20;let t=new Uint8Array(e),n=0;for(let i of r)t.set(i,n),n+=i.byteLength;let s=ee();s.update(t.subarray(0,n));let a=await s.hex();return t.set(pe(a),n),t}function gn(r){let e=[];e.push(r&127);let t=r>>>7;for(;t>0;)e.unshift(128|--t&127),t>>>=7;return new Uint8Array(e)}function st(r,e){let t=[],n=r<<4|e&15;for(e>>=4;e>0;)t.push(n|128),n=e&127,e>>=7;return t.push(n),new Uint8Array(t)}function Yt(r,e){let t=0,n=0,s;do s=r[e++],t|=(s&127)<<n,n+=7;while(s&128);return{value:t,newPos:e}}function wn(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(r,0),t.set(e,r.byteLength),t}var Rn=new TextEncoder;async function re(r,e){let t=Rn.encode(`${r} ${e.byteLength}\0`),n=ee();return n.update(t),n.update(e),n.hex()}var xn=new TextEncoder,Ns=new TextDecoder;function ir(r,e){let t=xn.encode(`${r} ${e.byteLength}\0`),n=new Uint8Array(t.byteLength+e.byteLength);return n.set(t),n.set(e,t.byteLength),n}function ge(r){let e=r.indexOf("<"),t=r.indexOf(">");if(e===-1||t===-1)throw new Error(`Malformed identity line: "${r}"`);let n=r.slice(0,e).trimEnd(),s=r.slice(e+1,t),a=r.slice(t+2),[i="0",o="+0000"]=a.split(" "),f=parseInt(i,10);return{name:n,email:s,timestamp:f,timezone:o}}function Be(r){return`${r.name} <${r.email}> ${r.timestamp} ${r.timezone}`}var En=new TextEncoder,On=new TextDecoder;function ae(r){let e=On.decode(r),t=e.indexOf(`
|
|
2
2
|
|
|
3
3
|
`),n=t===-1?e:e.slice(0,t),s=t===-1?"":e.slice(t+2),a="",i=[],o,f;for(let c of n.split(`
|
|
4
|
-
`)){let l=c.indexOf(" ");if(l===-1)continue;let
|
|
5
|
-
`))}var
|
|
4
|
+
`)){let l=c.indexOf(" ");if(l===-1)continue;let u=c.slice(0,l),d=c.slice(l+1);switch(u){case"tree":a=d;break;case"parent":i.push(d);break;case"author":o=ge(d);break;case"committer":f=ge(d);break}}if(!a)throw new Error("Commit missing tree field");if(!o)throw new Error("Commit missing author field");if(!f)throw new Error("Commit missing committer field");return{type:"commit",tree:a,parents:i,author:o,committer:f,message:s}}function or(r){let e=[];e.push(`tree ${r.tree}`);for(let t of r.parents)e.push(`parent ${t}`);return e.push(`author ${Be(r.author)}`),e.push(`committer ${Be(r.committer)}`),e.push(""),e.push(r.message),En.encode(e.join(`
|
|
5
|
+
`))}var qs=new TextEncoder,An=new TextDecoder;function X(r){let e=An.decode(r),t=e.indexOf(`
|
|
6
6
|
|
|
7
7
|
`),n=t===-1?e:e.slice(0,t),s=t===-1?"":e.slice(t+2),a="",i="commit",o="",f;for(let c of n.split(`
|
|
8
|
-
`)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),u=c.slice(l+1);switch(d){case"object":a=u;break;case"type":i=u;break;case"tag":o=u;break;case"tagger":f=ye(u);break}}if(!a)throw new Error("Tag missing object field");if(!o)throw new Error("Tag missing tag name field");if(!f)throw new Error("Tag missing tagger field");return{type:"tag",object:a,objectType:i,name:o,tagger:f,message:s}}async function We(r,e,t){let n=await r.objectStore.write(e,t);return r.hooks?.onObjectWrite?.({repo:r,type:e,hash:n}),n}async function X(r,e){return r.objectStore.read(e)}async function be(r,e){return r.objectStore.exists(e)}var _s=new TextDecoder;async function z(r,e){let t=await X(r,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return me(t.content)}var gn=new TextEncoder,or=new TextDecoder,Rn=new Set(["100644","100755","040000","120000","160000"]);function wn(r){return r.length===4&&r.toLowerCase()===".git"}function xn(r,e){if(r.length===0)throw new Error("invalid tree entry: empty name");if(r.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${r}'`);if(r.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(r==="."||r==="..")throw new Error(`invalid tree entry: '${r}'`);if(wn(r))throw new Error(`invalid tree entry: '${r}'`);if(!Rn.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${r}'`)}function ge(r){let e=[],t=0;for(;t<r.byteLength;){let n=r.indexOf(32,t);if(n===-1)break;let s=or.decode(r.subarray(t,n)),a=r.indexOf(0,n+1);if(a===-1)break;let i=or.decode(r.subarray(n+1,a)),o=r.subarray(a+1,a+21),f=De(o),c=s.padStart(6,"0");xn(i,c),e.push({mode:c,name:i,hash:f}),t=a+21}return{type:"tree",entries:e}}function cr(r){let e=[];for(let a of r.entries){let i=a.mode.replace(/^0+/,""),o=gn.encode(`${i} ${a.name}\0`),f=de(a.hash);e.push(o),e.push(f)}let t=e.reduce((a,i)=>a+i.byteLength,0),n=new Uint8Array(t),s=0;for(let a of e)n.set(a,s),s+=a.byteLength;return n}function fr(r){return typeof r=="string"?{type:"direct",hash:r}:r}var at=".lock";var En=[1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,5,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,4,4];function kn(r,e,t){let n=0,s=!1,a=e;for(;a<r.length;a++){let o=r.charCodeAt(a);switch(o<128?En[o]:0){case 1:break;case 2:if(n===46)return{len:-1,starConsumed:s};n=o;continue;case 3:if(n===64)return{len:-1,starConsumed:s};n=o;continue;case 4:return{len:-1,starConsumed:s};case 5:if(!t)return{len:-1,starConsumed:s};s=!0,n=o;continue;default:n=o;continue}break}let i=a-e;return i===0?{len:0,starConsumed:s}:r.charCodeAt(e)===46?{len:-1,starConsumed:s}:i>=at.length&&r.slice(a-at.length,a)===at?{len:-1,starConsumed:s}:{len:i,starConsumed:s}}function it(r,e=0){if(r==="@"||r.length===0)return!1;let t=0,n=0,s=!!(e&2);for(;t<=r.length;){let{len:a,starConsumed:i}=kn(r,t,s);if(a<0||a===0)return!1;i&&(s=!1),n++,t+=a+1}return!(r.charCodeAt(r.length-1)===46||!(e&1)&&n<2)}var An=10;async function On(r,e){return r.refStore.readRef(e)}async function Re(r,e){let t=e;for(let n=0;n<An;n++){let s=await On(r,t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}function Pn(r){let e=Math.abs(r),t=r<=0?"+":"-",n=String(Math.floor(e/60)).padStart(2,"0"),s=String(e%60).padStart(2,"0");return`${t}${n}${s}`}function lr(r){if("timestamp"in r)return r;let e=r.date??new Date;return{name:r.name,email:r.email,timestamp:Math.floor(e.getTime()/1e3),timezone:Pn(e.getTimezoneOffset())}}async function ur(r,e){let t=e.branch?`refs/heads/${e.branch}`:null,n=t?await Re(r,t):null,s=null;n&&(s=(await z(r,n)).tree);let a=[];for(let[u,h]of Object.entries(e.files))if(h===null)a.push({path:u,hash:null});else{let p=typeof h=="string"?new TextEncoder().encode(h):h,g=await We(r,"blob",p);a.push({path:u,hash:g})}let i;s?i=await Sn(r,s,a):i=await ct(r,null,ot(a));let o=lr(e.author),f=e.committer?lr(e.committer):o,l=ir({type:"commit",tree:i,parents:n?[n]:[],author:o,committer:f,message:e.message});return{hash:await We(r,"commit",l),parentHash:n}}async function Sn(r,e,t){return ct(r,e,ot(t))}function ot(r){let e=new Map,t=new Map;for(let n of r){let s=n.path.indexOf("/");if(s===-1)e.set(n.path,{hash:n.hash,mode:n.mode??"100644"});else{let a=n.path.slice(0,s),i=n.path.slice(s+1),o=t.get(a);o||(o=[],t.set(a,o)),o.push({...n,path:i})}}return{files:e,dirs:t}}async function dr(r,e){let t=await X(r,e);if(t.type!=="tree")throw new Error(`Expected tree object, got ${t.type}`);return ge(t.content).entries}async function ct(r,e,t){let n=new Map;if(e)for(let i of await dr(r,e))n.set(i.name,i);for(let[i,{hash:o,mode:f}]of t.files)o===null?n.delete(i):n.set(i,{name:i,hash:o,mode:f});for(let[i,o]of t.dirs){let f=n.get(i),c=f?.mode==="040000"?f.hash:null,l=ot(o),d=await ct(r,c,l);(await dr(r,d)).length===0?n.delete(i):n.set(i,{name:i,hash:d,mode:"040000"})}let s=[...n.values()].sort((i,o)=>{let f=i.mode==="040000"?`${i.name}/`:i.name,c=o.mode==="040000"?`${o.name}/`:o.name;return f<c?-1:f>c?1:0}),a=cr({type:"tree",entries:s});return We(r,"tree",a)}async function ft(r,e,t){if(e===t)return!0;let n=new Set,s=[t],a=0;for(;a<s.length;){let i=s[a++];if(i===e)return!0;if(n.has(i))continue;n.add(i);let o;try{o=await z(r,i)}catch{continue}for(let f of o.parents)n.has(f)||s.push(f)}return!1}var Ge=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]),jn=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]),$e=64,vn=4,lt=4096,pr=65536,Tn=127;function In(r){let e=r.byteLength;if(e===0)return null;let t=(e-1)/16|0;if(t===0)return null;let n=t>>>2;n<16&&(n=16),n=Un(n);let s=n-1,a=new Uint32Array(n),i=[],o=-1>>>0;for(let u=t*16-16;u>=0;u-=16){let h=0;for(let p=1;p<=16;p++)h=(h<<8|r[u+p])^Ge[h>>>23];if(h=h>>>0,h===o)i[i.length-1].ptr=u+16;else{o=h;let p=h&s;i.push({ptr:u+16,val:h}),a[p]++}}let f=new Map;for(let u of i){let h=u.val&s,p=f.get(h);p||(p=[],f.set(h,p)),p.push(u)}for(let[u,h]of f){if(h.length<=$e)continue;let p=[],g=h.length/$e;for(let w=0;w<$e;w++)p.push(h[Math.floor(w*g)]);f.set(u,p),a[u]=$e}let c=new Uint32Array(n+1),l=[],d=0;for(let u=0;u<n;u++){c[u]=d;let h=f.get(u);if(h){for(let p of h)l.push(p);d+=h.length}}return c[n]=d,{src:r,hashMask:s,buckets:c,entries:l}}function Ln(r,e,t){if(!r||e.byteLength===0)return null;let n=r.src.byteLength,s=e.byteLength,a=r.src,i=new Uint8Array(Math.max(s,1024)),o=0;function f(g){for(;o+g>i.length;){let w=new Uint8Array(i.length*2);w.set(i),i=w}}o=yr(i,o,n),o=yr(i,o,s),f(18),o++;let c=0,l=0,d=Math.min(16,s);for(let g=0;g<d;g++)i[o++]=e[g],c=(c<<8|e[g])^Ge[c>>>23],l++;c=c>>>0;let u=d,h=0,p=0;for(;u<s;){if(p<lt){c^=jn[e[u-16]],c=((c<<8|e[u])^Ge[c>>>23])>>>0;let g=c&r.hashMask,w=r.buckets[g],O=r.buckets[g+1];for(let k=w;k<O;k++){let x=r.entries[k];if(x.val!==c)continue;let m=x.ptr,b=a.byteLength-m,y=s-u;if(b>y&&(b=y),b<=p)break;let R=0;for(;R<b&&a[m+R]===e[u+R];)R++;if(R>p&&(p=R,h=m,p>=lt))break}}if(p<vn)f(2),l===0&&o++,i[o++]=e[u++],l++,l===Tn&&(i[o-l-1]=l,l=0),p=0;else{if(l>0){for(;h>0&&a[h-1]===e[u-1];)if(p++,h--,u--,o--,!(--l>0)){o--,l=-1;break}l>0&&(i[o-l-1]=l),l=0}let g=p>pr?p-pr:0;p-=g,f(8);let w=o++,O=128;if(h&255&&(i[o++]=h&255,O|=1),h&65280&&(i[o++]=h>>>8&255,O|=2),h&16711680&&(i[o++]=h>>>16&255,O|=4),h&4278190080&&(i[o++]=h>>>24&255,O|=8),p&255&&(i[o++]=p&255,O|=16),p&65280&&(i[o++]=p>>>8&255,O|=32),i[w]=O,u+=p,h+=p,p=g,h>4294967295&&(p=0),p<lt){c=0;for(let k=-16;k<0;k++)c=(c<<8|e[u+k])^Ge[c>>>23];c=c>>>0}}if(t&&o>t)return null}return l>0&&(i[o-l-1]=l),t&&o>t?null:i.subarray(0,o)}var hr={blob:0,tree:1,commit:2,tag:3};function mr(r,e){let t=e?.window??10,n=e?.depth??50,s=r.slice().sort((c,l)=>{let d=hr[c.type]??99,u=hr[l.type]??99;return d!==u?d-u:l.content.byteLength-c.content.byteLength}),a=new Map,i=[],o=[],f=[];for(let c=0;c<s.length;c++){let l=s[c],d={hash:l.hash,type:l.type,content:l.content,depth:0},u=null,h=null,p=Math.max(0,c-t);for(let g=c-1;g>=p;g--){let w=s[g];if(w.type!==l.type||(a.get(w.hash)?.depth??0)>=n||l.content.byteLength<w.content.byteLength>>>5)continue;let x=o[g-p]??null;if(!x)continue;let m=u?u.byteLength:l.content.byteLength/2|0;if(m<16)continue;let b=Ln(x,l.content,m);b&&(!u||b.byteLength<u.byteLength)&&(u=b,h=w.hash)}if(u&&h){d.delta=u,d.deltaBase=h;let g=a.get(h);d.depth=(g?.depth??0)+1}a.set(l.hash,d),i.push(d),o.length>=t&&(o.shift(),f.shift()),o.push(In(l.content)),f.push(l.hash)}return i}function Un(r){let e=r;return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e<16?16:e}function yr(r,e,t){let n=t;do{let s=n&127;n>>>=7,n>0&&(s|=128),r[e++]=s}while(n>0);return e}var Cn=2147483647;async function dt(r,e,t,n){if(t>=Cn)return{shallow:[],unshallow:[...n]};let s=new Map,a=[];for(let c of e)!s.has(c)&&await be(r,c)&&(s.set(c,1),a.push({hash:c,level:1}));let i=new Set,o=0;for(;o<a.length;){let{hash:c,level:l}=a[o++];if(l>=t){i.add(c);continue}let d;try{d=await z(r,c)}catch{continue}for(let u of d.parents)!s.has(u)&&await be(r,u)&&(s.set(u,l+1),a.push({hash:u,level:l+1}))}let f=[];for(let c of n){let l=s.get(c);l!==void 0&&l<t&&f.push(c)}return{shallow:[...i],unshallow:f}}async function Ee(r,e,t,n,s){let a=s??n,i=new Set;for(let l of t)await we(r,l,i,a);let o=[...e];if(s&&n)for(let l of s)try{let d=await z(r,l);for(let u of d.parents)i.has(u)||o.push(u)}catch{}let f=[],c=new Set;for(let l of o)await xe(r,l,i,c,f,n);return{count:f.length,objects:Hn(f)}}async function br(r,e,t,n,s){let{count:a,objects:i}=await Ee(r,e,t,n,s);return{count:a,objects:Dn(r,i)}}async function*Hn(r){for(let e of r)yield e}async function*Dn(r,e){for await(let t of e){let n=await X(r,t.hash);yield{hash:t.hash,type:t.type,content:n.content}}}async function gr(r){let e=[];for await(let t of r.objects)e.push(t);return e}async function we(r,e,t,n){if(t.has(e)||(t.add(e),!await be(r,e)))return;let s=await X(r,e);switch(s.type){case"commit":{let a=me(s.content);if(await we(r,a.tree,t,n),!n?.has(e))for(let i of a.parents)await we(r,i,t,n);break}case"tree":{let a=ge(s.content);for(let i of a.entries)await we(r,i.hash,t,n);break}case"tag":{let a=re(s.content);await we(r,a.object,t,n);break}case"blob":break}}async function xe(r,e,t,n,s,a){if(n.has(e)||t.has(e))return;n.add(e);let i=await X(r,e);switch(s.push({hash:e,type:i.type}),i.type){case"commit":{let o=me(i.content);if(await xe(r,o.tree,t,n,s,a),!a?.has(e))for(let f of o.parents)await xe(r,f,t,n,s,a);break}case"tree":{let o=ge(i.content);for(let f of o.entries)await xe(r,f.hash,t,n,s,a);break}case"tag":{let o=re(i.content);await xe(r,o.object,t,n,s,a);break}case"blob":break}}var _n=new TextEncoder,wr=new TextDecoder,Rr=65520,Nn=new Uint8Array([48,48,48,48]),Bn=new Uint8Array([48,48,48,49]),aa=new Uint8Array([48,48,48,50]);function E(r){let e=typeof r=="string"?_n.encode(r):r,t=4+e.byteLength;if(t>Rr)throw new Error(`pkt-line too long: ${t} bytes (max ${Rr})`);let n=t.toString(16).padStart(4,"0"),s=new Uint8Array(t);return s[0]=n.charCodeAt(0),s[1]=n.charCodeAt(1),s[2]=n.charCodeAt(2),s[3]=n.charCodeAt(3),s.set(e,4),s}function B(){return Nn.slice()}function K(){return Bn.slice()}function N(...r){let e=0;for(let s of r)e+=s.byteLength;let t=new Uint8Array(e),n=0;for(let s of r)t.set(s,n),n+=s.byteLength;return t}function ut(r){let e=[],t=0;for(;t<r.byteLength;){if(t+4>r.byteLength)throw new Error("Truncated pkt-line header");let n=wr.decode(r.subarray(t,t+4)),s=parseInt(n,16);if(Number.isNaN(s))throw new Error(`Invalid pkt-line length: ${n}`);if(s===0){e.push({type:"flush"}),t+=4;continue}if(s===1){e.push({type:"delim"}),t+=4;continue}if(s===2){e.push({type:"response-end"}),t+=4;continue}if(s<4)throw new Error(`Invalid pkt-line length: ${s}`);if(t+s>r.byteLength)throw new Error(`Truncated pkt-line: need ${s} bytes at offset ${t}, have ${r.byteLength-t}`);e.push({type:"data",data:r.subarray(t+4,t+s)}),t+=s}return e}function pt(r){if(r.type!=="data")return"";let e=wr.decode(r.data);return e.endsWith(`
|
|
8
|
+
`)){let l=c.indexOf(" ");if(l===-1)continue;let u=c.slice(0,l),d=c.slice(l+1);switch(u){case"object":a=d;break;case"type":i=d;break;case"tag":o=d;break;case"tagger":f=ge(d);break}}if(!a)throw new Error("Tag missing object field");if(!o)throw new Error("Tag missing tag name field");if(!f)throw new Error("Tag missing tagger field");return{type:"tag",object:a,objectType:i,name:o,tagger:f,message:s}}async function Fe(r,e,t){let n=await r.objectStore.write(e,t);return r.hooks?.onObjectWrite?.({repo:r,type:e,hash:n}),n}async function K(r,e){return r.objectStore.read(e)}async function at(r,e){return r.objectStore.exists(e)}var Xs=new TextDecoder;async function q(r,e){let t=await K(r,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return ae(t.content)}var kn=new TextEncoder,cr=new TextDecoder,Sn=new Set(["100644","100755","040000","120000","160000"]);function jn(r){return r.length===4&&r.toLowerCase()===".git"}function Pn(r,e){if(r.length===0)throw new Error("invalid tree entry: empty name");if(r.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${r}'`);if(r.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(r==="."||r==="..")throw new Error(`invalid tree entry: '${r}'`);if(jn(r))throw new Error(`invalid tree entry: '${r}'`);if(!Sn.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${r}'`)}function ie(r){let e=[],t=0;for(;t<r.byteLength;){let n=r.indexOf(32,t);if(n===-1)break;let s=cr.decode(r.subarray(t,n)),a=r.indexOf(0,n+1);if(a===-1)break;let i=cr.decode(r.subarray(n+1,a)),o=r.subarray(a+1,a+21),f=He(o),c=s.padStart(6,"0");Pn(i,c),e.push({mode:c,name:i,hash:f}),t=a+21}return{type:"tree",entries:e}}function fr(r){let e=[];for(let a of r.entries){let i=a.mode.replace(/^0+/,""),o=kn.encode(`${i} ${a.name}\0`),f=pe(a.hash);e.push(o),e.push(f)}let t=e.reduce((a,i)=>a+i.byteLength,0),n=new Uint8Array(t),s=0;for(let a of e)n.set(a,s),s+=a.byteLength;return n}function lr(r){return typeof r=="string"?{type:"direct",hash:r}:r}var it=".lock";var vn=[1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,5,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,4,4];function In(r,e,t){let n=0,s=!1,a=e;for(;a<r.length;a++){let o=r.charCodeAt(a);switch(o<128?vn[o]:0){case 1:break;case 2:if(n===46)return{len:-1,starConsumed:s};n=o;continue;case 3:if(n===64)return{len:-1,starConsumed:s};n=o;continue;case 4:return{len:-1,starConsumed:s};case 5:if(!t)return{len:-1,starConsumed:s};s=!0,n=o;continue;default:n=o;continue}break}let i=a-e;return i===0?{len:0,starConsumed:s}:r.charCodeAt(e)===46?{len:-1,starConsumed:s}:i>=it.length&&r.slice(a-it.length,a)===it?{len:-1,starConsumed:s}:{len:i,starConsumed:s}}function ot(r,e=0){if(r==="@"||r.length===0)return!1;let t=0,n=0,s=!!(e&2);for(;t<=r.length;){let{len:a,starConsumed:i}=In(r,t,s);if(a<0||a===0)return!1;i&&(s=!1),n++,t+=a+1}return!(r.charCodeAt(r.length-1)===46||!(e&1)&&n<2)}var Tn=10;async function Ln(r,e){return r.refStore.readRef(e)}async function we(r,e){let t=e;for(let n=0;n<Tn;n++){let s=await Ln(r,t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}function Un(r){let e=Math.abs(r),t=r<=0?"+":"-",n=String(Math.floor(e/60)).padStart(2,"0"),s=String(e%60).padStart(2,"0");return`${t}${n}${s}`}function ur(r){if("timestamp"in r)return r;let e=r.date??new Date;return{name:r.name,email:r.email,timestamp:Math.floor(e.getTime()/1e3),timezone:Un(e.getTimezoneOffset())}}async function hr(r,e){let t=e.branch?`refs/heads/${e.branch}`:null,n=t?await we(r,t):null,s=null;n&&(s=(await q(r,n)).tree);let a=[];for(let[d,p]of Object.entries(e.files))if(p===null)a.push({path:d,hash:null});else{let h=typeof p=="string"?new TextEncoder().encode(p):p,g=await Fe(r,"blob",h);a.push({path:d,hash:g})}let i;s?i=await Cn(r,s,a):i=await ft(r,null,ct(a));let o=ur(e.author),f=e.committer?ur(e.committer):o,l=or({type:"commit",tree:i,parents:n?[n]:[],author:o,committer:f,message:e.message});return{hash:await Fe(r,"commit",l),parentHash:n}}async function Cn(r,e,t){return ft(r,e,ct(t))}function ct(r){let e=new Map,t=new Map;for(let n of r){let s=n.path.indexOf("/");if(s===-1)e.set(n.path,{hash:n.hash,mode:n.mode??"100644"});else{let a=n.path.slice(0,s),i=n.path.slice(s+1),o=t.get(a);o||(o=[],t.set(a,o)),o.push({...n,path:i})}}return{files:e,dirs:t}}async function dr(r,e){let t=await K(r,e);if(t.type!=="tree")throw new Error(`Expected tree object, got ${t.type}`);return ie(t.content).entries}async function ft(r,e,t){let n=new Map;if(e)for(let i of await dr(r,e))n.set(i.name,i);for(let[i,{hash:o,mode:f}]of t.files)o===null?n.delete(i):n.set(i,{name:i,hash:o,mode:f});for(let[i,o]of t.dirs){let f=n.get(i),c=f?.mode==="040000"?f.hash:null,l=ct(o),u=await ft(r,c,l);(await dr(r,u)).length===0?n.delete(i):n.set(i,{name:i,hash:u,mode:"040000"})}let s=[...n.values()].sort((i,o)=>{let f=i.mode==="040000"?`${i.name}/`:i.name,c=o.mode==="040000"?`${o.name}/`:o.name;return f<c?-1:f>c?1:0}),a=fr({type:"tree",entries:s});return Fe(r,"tree",a)}async function lt(r,e,t){if(e===t)return!0;let n=new Set,s=[t],a=0;for(;a<s.length;){let i=s[a++];if(i===e)return!0;if(n.has(i))continue;n.add(i);let o;try{o=await q(r,i)}catch{continue}for(let f of o.parents)n.has(f)||s.push(f)}return!1}var We=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]),Hn=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]),$e=64,Dn=4,ut=4096,pr=65536,Mn=127;function _n(r){let e=r.byteLength;if(e===0)return null;let t=(e-1)/16|0;if(t===0)return null;let n=t>>>2;n<16&&(n=16),n=Bn(n);let s=n-1,a=new Uint32Array(n),i=[],o=-1>>>0;for(let d=t*16-16;d>=0;d-=16){let p=0;for(let h=1;h<=16;h++)p=(p<<8|r[d+h])^We[p>>>23];if(p=p>>>0,p===o)i[i.length-1].ptr=d+16;else{o=p;let h=p&s;i.push({ptr:d+16,val:p}),a[h]++}}let f=new Map;for(let d of i){let p=d.val&s,h=f.get(p);h||(h=[],f.set(p,h)),h.push(d)}for(let[d,p]of f){if(p.length<=$e)continue;let h=[],g=p.length/$e;for(let w=0;w<$e;w++)h.push(p[Math.floor(w*g)]);f.set(d,h),a[d]=$e}let c=new Uint32Array(n+1),l=[],u=0;for(let d=0;d<n;d++){c[d]=u;let p=f.get(d);if(p){for(let h of p)l.push(h);u+=p.length}}return c[n]=u,{src:r,hashMask:s,buckets:c,entries:l}}function Nn(r,e,t){if(!r||e.byteLength===0)return null;let n=r.src.byteLength,s=e.byteLength,a=r.src,i=new Uint8Array(Math.max(s,1024)),o=0;function f(g){for(;o+g>i.length;){let w=new Uint8Array(i.length*2);w.set(i),i=w}}o=mr(i,o,n),o=mr(i,o,s),f(18),o++;let c=0,l=0,u=Math.min(16,s);for(let g=0;g<u;g++)i[o++]=e[g],c=(c<<8|e[g])^We[c>>>23],l++;c=c>>>0;let d=u,p=0,h=0;for(;d<s;){if(h<ut){c^=Hn[e[d-16]],c=((c<<8|e[d])^We[c>>>23])>>>0;let g=c&r.hashMask,w=r.buckets[g],A=r.buckets[g+1];for(let O=w;O<A;O++){let x=r.entries[O];if(x.val!==c)continue;let y=x.ptr,b=a.byteLength-y,m=s-d;if(b>m&&(b=m),b<=h)break;let R=0;for(;R<b&&a[y+R]===e[d+R];)R++;if(R>h&&(h=R,p=y,h>=ut))break}}if(h<Dn)f(2),l===0&&o++,i[o++]=e[d++],l++,l===Mn&&(i[o-l-1]=l,l=0),h=0;else{if(l>0){for(;p>0&&a[p-1]===e[d-1];)if(h++,p--,d--,o--,!(--l>0)){o--,l=-1;break}l>0&&(i[o-l-1]=l),l=0}let g=h>pr?h-pr:0;h-=g,f(8);let w=o++,A=128;if(p&255&&(i[o++]=p&255,A|=1),p&65280&&(i[o++]=p>>>8&255,A|=2),p&16711680&&(i[o++]=p>>>16&255,A|=4),p&4278190080&&(i[o++]=p>>>24&255,A|=8),h&255&&(i[o++]=h&255,A|=16),h&65280&&(i[o++]=h>>>8&255,A|=32),i[w]=A,d+=h,p+=h,h=g,p>4294967295&&(h=0),h<ut){c=0;for(let O=-16;O<0;O++)c=(c<<8|e[d+O])^We[c>>>23];c=c>>>0}}if(t&&o>t)return null}return l>0&&(i[o-l-1]=l),t&&o>t?null:i.subarray(0,o)}var yr={blob:0,tree:1,commit:2,tag:3};function br(r,e){let t=e?.window??10,n=e?.depth??50,s=r.slice().sort((c,l)=>{let u=yr[c.type]??99,d=yr[l.type]??99;return u!==d?u-d:l.content.byteLength-c.content.byteLength}),a=new Map,i=[],o=[],f=[];for(let c=0;c<s.length;c++){let l=s[c],u={hash:l.hash,type:l.type,content:l.content,depth:0},d=null,p=null,h=Math.max(0,c-t);for(let g=c-1;g>=h;g--){let w=s[g];if(w.type!==l.type||(a.get(w.hash)?.depth??0)>=n||l.content.byteLength<w.content.byteLength>>>5)continue;let x=o[g-h]??null;if(!x)continue;let y=d?d.byteLength:l.content.byteLength/2|0;if(y<16)continue;let b=Nn(x,l.content,y);b&&(!d||b.byteLength<d.byteLength)&&(d=b,p=w.hash)}if(d&&p){u.delta=d,u.deltaBase=p;let g=a.get(p);u.depth=(g?.depth??0)+1}a.set(l.hash,u),i.push(u),o.length>=t&&(o.shift(),f.shift()),o.push(_n(l.content)),f.push(l.hash)}return i}function Bn(r){let e=r;return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e<16?16:e}function mr(r,e,t){let n=t;do{let s=n&127;n>>>=7,n>0&&(s|=128),r[e++]=s}while(n>0);return e}var Fn=2147483647;async function dt(r,e,t,n){if(t>=Fn)return{shallow:[],unshallow:[...n]};let s=new Map,a=[];for(let c of e)!s.has(c)&&await at(r,c)&&(s.set(c,1),a.push({hash:c,level:1}));let i=new Set,o=0;for(;o<a.length;){let{hash:c,level:l}=a[o++];if(l>=t){i.add(c);continue}let u;try{u=await q(r,c)}catch{continue}for(let d of u.parents)!s.has(d)&&await at(r,d)&&(s.set(d,l+1),a.push({hash:d,level:l+1}))}let f=[];for(let c of n){let l=s.get(c);l!==void 0&&l<t&&f.push(c)}return{shallow:[...i],unshallow:f}}async function Ge(r,e,t,n,s){let a=s??n,i=new Set;for(let l of t)await oe(r,l,i,a);let o=[...e];if(s&&n)for(let l of s)try{let u=await q(r,l);for(let d of u.parents)i.has(d)||o.push(d)}catch{}let f=[],c=new Set;for(let l of o)await xe(r,l,i,c,f,n);return{count:f.length,objects:wr(f)}}async function gr(r,e,t,n,s){let a=s??n,i=new Set;for(let l of t)await oe(r,l,i,a);let o=[...e];if(s&&n)for(let l of s)try{let u=await q(r,l);for(let d of u.parents)i.has(d)||o.push(d)}catch{}let f=[],c=new Set;for(let l of o)await Re(r,l,i,c,f,n);return{count:f.length,objects:wr(f)}}async function*wr(r){for(let e of r)yield e}async function Rr(r){let e=[];for await(let t of r.objects)e.push(t);return e}async function oe(r,e,t,n){if(t.has(e))return;t.add(e);let s=await $n(r,e);if(s)switch(s.type){case"commit":{let a=ae(s.content);if(await oe(r,a.tree,t,n),!n?.has(e))for(let i of a.parents)await oe(r,i,t,n);break}case"tree":{let a=ie(s.content);for(let i of a.entries)await oe(r,i.hash,t,n);break}case"tag":{let a=X(s.content);await oe(r,a.object,t,n);break}case"blob":break}}async function Re(r,e,t,n,s,a){if(n.has(e)||t.has(e))return;n.add(e);let i=await K(r,e);switch(s.push({hash:e,type:i.type,content:i.content}),i.type){case"commit":{let o=ae(i.content);if(await Re(r,o.tree,t,n,s,a),!a?.has(e))for(let f of o.parents)await Re(r,f,t,n,s,a);break}case"tree":{let o=ie(i.content);for(let f of o.entries)await Re(r,f.hash,t,n,s,a);break}case"tag":{let o=X(i.content);await Re(r,o.object,t,n,s,a);break}case"blob":break}}async function $n(r,e){try{return await K(r,e)}catch(t){if(t instanceof Error&&t.message===`object ${e} not found`)return null;throw t}}async function xe(r,e,t,n,s,a){if(n.has(e)||t.has(e))return;n.add(e);let i=await K(r,e);switch(s.push({hash:e,type:i.type}),i.type){case"commit":{let o=ae(i.content);if(await xe(r,o.tree,t,n,s,a),!a?.has(e))for(let f of o.parents)await xe(r,f,t,n,s,a);break}case"tree":{let o=ie(i.content);for(let f of o.entries)await xe(r,f.hash,t,n,s,a);break}case"tag":{let o=X(i.content);await xe(r,o.object,t,n,s,a);break}case"blob":break}}var Wn=new TextEncoder,Er=new TextDecoder,xr=65520,Gn=new Uint8Array([48,48,48,48]),qn=new Uint8Array([48,48,48,49]),ma=new Uint8Array([48,48,48,50]);function E(r){let e=typeof r=="string"?Wn.encode(r):r,t=4+e.byteLength;if(t>xr)throw new Error(`pkt-line too long: ${t} bytes (max ${xr})`);let n=t.toString(16).padStart(4,"0"),s=new Uint8Array(t);return s[0]=n.charCodeAt(0),s[1]=n.charCodeAt(1),s[2]=n.charCodeAt(2),s[3]=n.charCodeAt(3),s.set(e,4),s}function N(){return Gn.slice()}function Y(){return qn.slice()}function _(...r){let e=0;for(let s of r)e+=s.byteLength;let t=new Uint8Array(e),n=0;for(let s of r)t.set(s,n),n+=s.byteLength;return t}function ht(r){let e=[],t=0;for(;t<r.byteLength;){if(t+4>r.byteLength)throw new Error("Truncated pkt-line header");let n=Er.decode(r.subarray(t,t+4)),s=parseInt(n,16);if(Number.isNaN(s))throw new Error(`Invalid pkt-line length: ${n}`);if(s===0){e.push({type:"flush"}),t+=4;continue}if(s===1){e.push({type:"delim"}),t+=4;continue}if(s===2){e.push({type:"response-end"}),t+=4;continue}if(s<4)throw new Error(`Invalid pkt-line length: ${s}`);if(t+s>r.byteLength)throw new Error(`Truncated pkt-line: need ${s} bytes at offset ${t}, have ${r.byteLength-t}`);e.push({type:"data",data:r.subarray(t+4,t+s)}),t+=s}return e}function pt(r){if(r.type!=="data")return"";let e=Er.decode(r.data);return e.endsWith(`
|
|
9
9
|
`)?e.slice(0,-1):e}var qe=65515;function Ve(r,e,t){let n=[],s=[...e];t&&s.push(`symref=HEAD:${t}`),s.push("agent=just-git/1.0");let a=s.join(" ");if(r.length===0)n.push(E(`0000000000000000000000000000000000000000 capabilities^{}\0${a}
|
|
10
10
|
`));else for(let i=0;i<r.length;i++){let o=r[i];i===0?n.push(E(`${o.hash} ${o.name}\0${a}
|
|
11
11
|
`)):n.push(E(`${o.hash} ${o.name}
|
|
12
|
-
`))}return n.push(
|
|
13
|
-
`),
|
|
12
|
+
`))}return n.push(N()),_(...n)}function Or(r,e,t,n){let s=_(E(`# service=${e}
|
|
13
|
+
`),N()),a=Ve(r,t,n),i=new Uint8Array(s.byteLength+a.byteLength);return i.set(s,0),i.set(a,s.byteLength),i}function Ar(r){let e=ht(r),t=[],n=[],s=[],a=[],i,o=!1;for(let f of e){if(f.type==="flush")continue;let c=pt(f);if(c.startsWith("want ")){let l=c.slice(5);if(t.length===0){let u=l.indexOf(" ");u!==-1?(t.push(l.slice(0,u)),a=l.slice(u+1).split(" ").filter(Boolean)):t.push(l)}else t.push(l)}else c.startsWith("have ")?n.push(c.slice(5)):c.startsWith("shallow ")?s.push(c.slice(8)):c.startsWith("deepen ")?(i=parseInt(c.slice(7),10),Number.isNaN(i)&&(i=void 0)):c==="done"&&(o=!0)}return{wants:t,haves:n,capabilities:a,clientShallows:s,depth:i,done:o}}function Ee(r,e,t,n){let s=[];if(n){for(let a of n.shallow)s.push(E(`shallow ${a}
|
|
14
14
|
`));for(let a of n.unshallow)s.push(E(`unshallow ${a}
|
|
15
|
-
`));s.push(
|
|
15
|
+
`));s.push(N())}if(t&&t.length>0){for(let i of t)s.push(E(`ACK ${i} common
|
|
16
16
|
`));let a=t[t.length-1];s.push(E(`ACK ${a} ready
|
|
17
17
|
`)),s.push(E(`ACK ${a}
|
|
18
18
|
`))}else s.push(E(`NAK
|
|
19
|
-
`));if(e){let a=0;for(;a<r.byteLength;){let i=Math.min(qe,r.byteLength-a);s.push(
|
|
19
|
+
`));if(e){let a=0;for(;a<r.byteLength;){let i=Math.min(qe,r.byteLength-a);s.push(Oe(1,r.subarray(a,a+i))),a+=i}s.push(N())}else{let a=new Uint8Array(r.byteLength);a.set(r),s.push(a)}return _(...s)}function kr(r){let e=[];for(let t of r.shallow)e.push(E(`shallow ${t}
|
|
20
20
|
`));for(let t of r.unshallow)e.push(E(`unshallow ${t}
|
|
21
|
-
`));return e.push(
|
|
21
|
+
`));return e.push(N()),_(...e)}async function*Sr(r,e,t,n){if(n){let a=[];for(let i of n.shallow)a.push(E(`shallow ${i}
|
|
22
22
|
`));for(let i of n.unshallow)a.push(E(`unshallow ${i}
|
|
23
|
-
`));a.push(
|
|
23
|
+
`));a.push(N()),yield _(...a)}let s=[];if(t&&t.length>0){for(let i of t)s.push(E(`ACK ${i} common
|
|
24
24
|
`));let a=t[t.length-1];s.push(E(`ACK ${a} ready
|
|
25
25
|
`)),s.push(E(`ACK ${a}
|
|
26
26
|
`))}else s.push(E(`NAK
|
|
27
|
-
`));if(yield
|
|
28
|
-
`)?
|
|
27
|
+
`));if(yield _(...s),e){for await(let a of r){let i=0;for(;i<a.byteLength;){let o=Math.min(qe,a.byteLength-i);yield Oe(1,a.subarray(i,i+o)),i+=o}}yield N()}else for await(let a of r)yield a}function jr(r){let e=new TextDecoder,t=[],n=[],s=0,a=!1;for(;s<r.byteLength&&!(s+4>r.byteLength);){let o=e.decode(r.subarray(s,s+4)),f=parseInt(o,16);if(Number.isNaN(f))break;if(f===0){a=!0,s+=4;break}if(f<4||s+f>r.byteLength)break;let c=r.subarray(s+4,s+f);s+=f;let l=c.indexOf(0),u;if(l!==-1)u=e.decode(c.subarray(0,l)),n=e.decode(c.subarray(l+1)).replace(/\n$/,"").split(" ").filter(Boolean);else{let p=e.decode(c);u=p.endsWith(`
|
|
28
|
+
`)?p.slice(0,-1):p}let d=u.split(" ");d.length>=3&&t.push({oldHash:d[0],newHash:d[1],refName:d[2]})}let i=s<r.byteLength?r.subarray(s):new Uint8Array(0);return{commands:t,packData:i,capabilities:n,sawFlush:a}}function ce(r,e,t){let n=[];n.push(E(r?`unpack ok
|
|
29
29
|
`:`unpack error
|
|
30
30
|
`));for(let a of e)a.ok?n.push(E(`ok ${a.name}
|
|
31
31
|
`)):n.push(E(`ng ${a.name} ${a.error??"failed"}
|
|
32
|
-
`));n.push(
|
|
32
|
+
`));n.push(N());let s=_(...n);if(t){let a=[];return a.push(Oe(1,s)),a.push(N()),_(...a)}return s}function Oe(r,e){let t=new Uint8Array(1+e.byteLength);return t[0]=r,t.set(e,1),E(t)}function yt(r){let e=[];e.push(E(`version 2
|
|
33
33
|
`));for(let t of r)e.push(E(`${t}
|
|
34
|
-
`));return e.push(
|
|
35
|
-
`))}return e.push(
|
|
34
|
+
`));return e.push(N()),_(...e)}function mt(r){let e=ht(r),t="",n=[],s=[],a=!1;for(let i of e){if(i.type==="flush"||i.type==="response-end")break;if(i.type==="delim"){a=!0;continue}let o=pt(i);o&&(a?s.push(o):o.startsWith("command=")?t=o.slice(8):n.push(o))}return{command:t,capabilities:n,args:s}}function bt(r){let e=[];for(let t of r){let n=`${t.hash} ${t.name}`;t.symrefTarget&&(n+=` symref-target:${t.symrefTarget}`),t.peeledHash&&(n+=` peeled:${t.peeledHash}`),e.push(E(`${n}
|
|
35
|
+
`))}return e.push(N()),_(...e)}function gt(r){let e=[],t=[],n=[],s=[],a=!1,i,o=!1,f=!1;for(let c of r)c.startsWith("want ")?e.push(c.slice(5)):c.startsWith("have ")?t.push(c.slice(5)):c.startsWith("shallow ")?n.push(c.slice(8)):c.startsWith("deepen ")?(i=parseInt(c.slice(7),10),Number.isNaN(i)&&(i=void 0)):c.startsWith("want-ref ")?s.push(c.slice(9)):c==="done"?a=!0:c==="include-tag"?o=!0:c==="ofs-delta"&&(f=!0);return{wants:e,haves:t,done:a,clientShallows:n,depth:i,includeTag:o,ofsDeltas:f,wantRefs:s}}function fe(r,e){let t=[],{commonHashes:n,shallowInfo:s,wantedRefs:a}=e??{};if(n&&n.length>0){t.push(E(`acknowledgments
|
|
36
36
|
`));for(let o of n)t.push(E(`ACK ${o}
|
|
37
37
|
`));t.push(E(`ready
|
|
38
|
-
`)),t.push(
|
|
38
|
+
`)),t.push(Y())}if(s&&(s.shallow.length>0||s.unshallow.length>0)){t.push(E(`shallow-info
|
|
39
39
|
`));for(let o of s.shallow)t.push(E(`shallow ${o}
|
|
40
40
|
`));for(let o of s.unshallow)t.push(E(`unshallow ${o}
|
|
41
|
-
`));t.push(
|
|
41
|
+
`));t.push(Y())}if(a&&a.length>0){t.push(E(`wanted-refs
|
|
42
42
|
`));for(let o of a)t.push(E(`${o.hash} ${o.name}
|
|
43
|
-
`));t.push(
|
|
44
|
-
`));let i=0;for(;i<r.byteLength;){let o=Math.min(qe,r.byteLength-i);t.push(
|
|
43
|
+
`));t.push(Y())}t.push(E(`packfile
|
|
44
|
+
`));let i=0;for(;i<r.byteLength;){let o=Math.min(qe,r.byteLength-i);t.push(Oe(1,r.subarray(i,i+o))),i+=o}return t.push(N()),_(...t)}function Pr(r,e){let t=[];if(t.push(E(`acknowledgments
|
|
45
45
|
`)),r.length>0)for(let n of r)t.push(E(`ACK ${n}
|
|
46
46
|
`));else t.push(E(`NAK
|
|
47
47
|
`));return e&&t.push(E(`ready
|
|
48
|
-
`)),t.push(
|
|
48
|
+
`)),t.push(N()),_(...t)}async function*vr(r,e){let{commonHashes:t,shallowInfo:n,wantedRefs:s}=e??{};if(t&&t.length>0){let a=[];a.push(E(`acknowledgments
|
|
49
49
|
`));for(let i of t)a.push(E(`ACK ${i}
|
|
50
50
|
`));a.push(E(`ready
|
|
51
|
-
`)),a.push(
|
|
51
|
+
`)),a.push(Y()),yield _(...a)}if(n&&(n.shallow.length>0||n.unshallow.length>0)){let a=[];a.push(E(`shallow-info
|
|
52
52
|
`));for(let i of n.shallow)a.push(E(`shallow ${i}
|
|
53
53
|
`));for(let i of n.unshallow)a.push(E(`unshallow ${i}
|
|
54
|
-
`));a.push(
|
|
54
|
+
`));a.push(Y()),yield _(...a)}if(s&&s.length>0){let a=[];a.push(E(`wanted-refs
|
|
55
55
|
`));for(let i of s)a.push(E(`${i.hash} ${i.name}
|
|
56
|
-
`));a.push(
|
|
57
|
-
`);for await(let a of r){let i=0;for(;i<a.byteLength;){let o=Math.min(qe,a.byteLength-i);yield Ae(1,a.subarray(i,i+o)),i+=o}}yield B()}var _=class extends Error{status=413;constructor(e){super(e),this.name="RequestLimitError"}};function jr(r){async function e(t){let n=r.getForkParent?await r.getForkParent(t):null;return{objectStore:new gt(r,t,n),refStore:new Rt(r,t)}}return{async createRepo(t,n){if(await r.hasRepo(t))throw new Error(`repo '${t}' already exists`);let a=n?.defaultBranch??"main";return await r.insertRepo(t),await r.putRef(t,"HEAD",{type:"symbolic",target:`refs/heads/${a}`}),e(t)},async repo(t){return await r.hasRepo(t)?e(t):null},async deleteRepo(t){if(r.listForks){let n=await r.listForks(t);if(n.length>0)throw new Error(`cannot delete repo '${t}': has ${n.length} active fork(s)`)}await r.deleteRepo(t)},async forkRepo(t,n,s){if(!r.forkRepo||!r.getForkParent||!r.listForks)throw new Error("storage backend does not support forks");if(!await r.hasRepo(t))throw new Error(`source repo '${t}' not found`);if(await r.hasRepo(n))throw new Error(`repo '${n}' already exists`);let f=await r.getForkParent(t)??t;await r.insertRepo(n),await r.forkRepo(f,n);let c=await r.listRefs(t);for(let d of c)await r.putRef(n,d.name,d.ref);let l=await r.getRef(t,"HEAD");if(l)await r.putRef(n,"HEAD",l);else{let d=s?.defaultBranch??"main";await r.putRef(n,"HEAD",{type:"symbolic",target:`refs/heads/${d}`})}return e(n)}}}function ze(r){return typeof r=="object"&&r!==null&&typeof r.preparePack=="function"&&typeof r.commitPack=="function"&&typeof r.deleteObjects=="function"}var gt=class{constructor(e,t,n=null){this.driver=e;this.repoId=t;this.parentId=n}cache=new _e;async write(e,t){let n=ar(e,t),s=await _t(n);return await this.driver.putObject(this.repoId,s,e,t),s}async read(e){let t=this.cache.get(e);if(t)return t;let n=await this.driver.getObject(this.repoId,e);if(!n&&this.parentId&&(n=await this.driver.getObject(this.parentId,e)),!n)throw new Error(`object ${e} not found`);return this.cache.set(e,n),n}async exists(e){return await this.driver.hasObject(this.repoId,e)?!0:this.parentId?!!await this.driver.hasObject(this.parentId,e):!1}async preparePack(e){if(e.byteLength<32)return[];let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0);if(n!==1346454347)throw new Error(`invalid pack signature: 0x${n.toString(16)} (expected 0x5041434b)`);let s=t.getUint32(4);if(s!==2)throw new Error(`unsupported pack version: ${s}`);if(t.getUint32(8)===0)return[];let i=this.driver,o=this.repoId,f=this.parentId;return(await rr(e,async l=>{let d=await i.getObject(o,l);return!d&&f&&(d=await i.getObject(f,l)),d?{type:d.type,content:new Uint8Array(d.content)}:null})).map(l=>({hash:l.hash,type:l.type,content:l.content}))}async preparePackStream(e){let t=[];for await(let n of e)t.push({hash:n.hash,type:n.type,content:n.content});return t}async commitPack(e){return e.length===0?0:(await this.driver.putObjects(this.repoId,e),e.length)}async ingestPack(e){let t=await this.preparePack(e);return this.commitPack(t)}async ingestPackStream(e){let t=await this.preparePackStream(e);return this.commitPack(t)}async deleteObjects(e){return e.length===0?0:this.driver.deleteObjects(this.repoId,e)}async findByPrefix(e){if(e.length<4)return[];let t=await this.driver.findObjectsByPrefix(this.repoId,e);if(!this.parentId)return Array.from(t);let n=await this.driver.findObjectsByPrefix(this.parentId,e),s=new Set(t);for(let a of n)s.add(a);return Array.from(s)}},Rt=class{constructor(e,t){this.driver=e;this.repoId=t}async readRef(e){return await this.driver.getRef(this.repoId,e)??null}async writeRef(e,t){await this.driver.putRef(this.repoId,e,fr(t))}async deleteRef(e){await this.driver.removeRef(this.repoId,e)}async listRefs(e){let t=await this.driver.listRefs(this.repoId,e),n=[];for(let s of t)if(s.ref.type==="direct")n.push({name:s.name,hash:s.ref.hash});else if(s.ref.type==="symbolic"){let a=await wt(i=>this.driver.getRef(this.repoId,i),s.ref.target);a&&n.push({name:s.name,hash:a})}return n}async compareAndSwapRef(e,t,n){return!!await this.driver.atomicRefUpdate(this.repoId,s=>Oe(s.getRef(e),a=>{let i=a?a.type==="direct"?a.hash:wt(o=>s.getRef(o),a.target):null;return Oe(i,o=>{if(t===null){if(a!==null)return!1}else if(o!==t)return!1;return n===null?Oe(s.removeRef(e),()=>!0):Oe(s.putRef(e,n),()=>!0)})}))}};function Oe(r,e){return r instanceof Promise?r.then(e):e(r)}function wt(r,e,t=0){return t>10?null:Oe(r(e),n=>n?n.type==="direct"?n.hash:n.type==="symbolic"?wt(r,n.target,t+1):null:null)}var ae=class{entries=new Map;currentBytes=0;maxBytes;hits=0;misses=0;constructor(e=256*1024*1024){this.maxBytes=e}static key(e,t,n){if(n.length>0)return null;let s=t.slice().sort();return`${e}\0${s.join(",")}`}get(e){let t=this.entries.get(e);return t?this.hits++:this.misses++,t}set(e,t){if(this.entries.has(e))return;let n=t.packData.byteLength;if(!(n>this.maxBytes)){for(;this.currentBytes+n>this.maxBytes&&this.entries.size>0;){let s=this.entries.keys().next().value;this.currentBytes-=this.entries.get(s).packData.byteLength,this.entries.delete(s)}this.entries.set(e,t),this.currentBytes+=n}}clear(){this.entries.clear(),this.currentBytes=0}get stats(){return{entries:this.entries.size,bytes:this.currentBytes,hits:this.hits,misses:this.misses}}},vr=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag","shallow"],Tr=["report-status","side-band-64k","ofs-delta","delete-refs"];async function Ir(r){let e=await r.refStore.listRefs("refs"),t=await r.refStore.readRef("HEAD"),n=[],s=null,a;if(t)if(t.type==="symbolic"){a=t.target;let o=await r.refStore.readRef(t.target);o?.type==="direct"&&(s=o.hash)}else s=t.hash;let i=e.slice().sort((o,f)=>o.name<f.name?-1:o.name>f.name?1:0);if(!s&&i.length>0){let o=Mn(i);o&&(s=o.hash,a=o.name)}s&&n.push({name:"HEAD",hash:s});for(let o of i)if(n.push({name:o.name,hash:o.hash}),o.name.startsWith("refs/tags/"))try{let f=await r.objectStore.read(o.hash);if(f.type==="tag"){let c=re(f.content);n.push({name:`${o.name}^{}`,hash:c.object})}}catch{}return{refs:n,headTarget:a}}var Fn=["refs/heads/main","refs/heads/master"];function Mn(r){for(let t of Fn){let n=r.find(s=>s.name===t);if(n)return n}return r.find(t=>t.name.startsWith("refs/heads/"))??null}function xt(r,e,t){return xr(r,e,e==="git-upload-pack"?vr:Tr,t)}function Et(r,e,t){return Ve(r,e==="git-upload-pack"?vr:Tr,t)}async function G(r,e,t,n,s){let{refs:a,headTarget:i}=await Ir(r),o=a;if(n?.advertiseRefs){let f=await n.advertiseRefs({repo:r,repoId:e,refs:a,service:t,auth:s});if(U(f))return f;f&&(o=f)}return{refs:o,headTarget:i}}function Pe(r){let e=new Map,t=new Set;for(let n of r.refs)e.set(n.name,n.hash),t.add(n.hash);return{allowedRefHashes:e,allowedWantHashes:t}}async function Se(r,e,t){let{wants:n,haves:s,capabilities:a,clientShallows:i,depth:o,done:f}=Er(e);if(n.length===0)return ke(new Uint8Array(0),!1);if(t?.authorizedFetchSet){for(let x of n)if(!t.authorizedFetchSet.allowedWantHashes.has(x))return{reject:!0,message:`forbidden want ${x}`}}let c=a.includes("multi_ack_detailed"),l=a.includes("side-band-64k"),d,u,h;if(i.length>0&&(h=new Set(i)),o!==void 0){let x=await dt(r,n,o,h??new Set);d=x,u=new Set(x.shallow)}if(d&&!f)return kr(d);let p;if(c&&s.length>0){p=[];for(let x of s)await r.objectStore.exists(x)&&p.push(x);p.length===0&&(p=void 0)}let g=!u&&t?.cache&&t.cacheKey?ae.key(t.cacheKey,n,s):null;if(g&&t?.cache){let x=t.cache.get(g);if(x)return ke(x.packData,l,p)}let w=a.includes("include-tag"),O={repo:r,wants:n,haves:s,includeTag:w,shallowBoundary:u,clientShallowBoundary:h,cache:t?.cache,cacheKey:g,deltaWindow:t?.deltaWindow};if(t?.noDelta){let x=await Cr(O);if(!x){let{data:m}=await te([]);return ke(m,l,p,d)}return Hr(Ar(x,l,p,d))}let k=await Ur(O);return ke(k,l,p,d)}async function Lr(r,e){let t=[],n=await r.refStore.listRefs("refs/tags");for(let s of n)if(!e.has(s.hash))try{let a=await r.objectStore.read(s.hash);if(a.type==="tag"){let i=re(a.content);e.has(i.object)&&(t.push({hash:s.hash,type:"tag",content:a.content}),e.add(s.hash))}}catch{}return t}async function Ur(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:i}=r,o=await br(e,t,n,a,i);if(o.count===0){let{data:p}=await te([]);return p}let f=await gr(o),c=new Set(f.map(p=>p.hash));if(s){let p=await Lr(e,c);f.push(...p)}let l=r.deltaWindow?{window:r.deltaWindow}:void 0,d=mr(f,l),u=d.map(p=>({hash:p.hash,type:p.type,content:p.content,delta:p.delta,deltaBaseHash:p.deltaBase})),{data:h}=await te(u);if(r.cacheKey&&r.cache){let p=d.filter(g=>g.delta).length;r.cache.set(r.cacheKey,{packData:h,objectCount:f.length,deltaCount:p})}return h}async function Cr(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:i}=r,{count:o,objects:f}=await Ee(e,t,n,a,i);if(o===0)return null;let c=[];for await(let p of f)c.push(p);let l=new Set(c.map(p=>p.hash)),d=s?await Lr(e,l):[],u=c.length+d.length;async function*h(){for(let p of c){let g=await e.objectStore.read(p.hash);yield{type:g.type,content:g.content}}for(let p of d)yield{type:p.type,content:p.content}}return sr(u,h())}function Hr(r){let e=r[Symbol.asyncIterator]();return new ReadableStream({async pull(t){let{value:n,done:s}=await e.next();s?t.close():t.enqueue(n)}})}async function Dr(r,e){return await r.commitPack(e),e.map(t=>t.hash)}async function Wn(r,e){ze(r.objectStore)&&await r.objectStore.deleteObjects(e)}async function kt(r,e,t){let{commands:n,packData:s,capabilities:a,sawFlush:i}=Or(e),o=!0,f;if(s.byteLength>0)try{if(Gn(s,t),ze(r.objectStore)){let l=await r.objectStore.preparePack(s);f=await Dr(r.objectStore,l)}else await r.objectStore.ingestPack(s)}catch(l){if(l instanceof _)throw l;o=!1}return{updates:await _r(r,n,o),unpackOk:o,capabilities:a,sawFlush:i,ingestedHashes:f}}async function At(r,e,t,n,s=!0,a){let i=!0,o;if(e.some(l=>l.newHash!==Y))try{let l=async u=>{try{return await r.objectStore.read(u)}catch{return null}},d=nr(qn(n,a),l);if(ze(r.objectStore)){let u=await r.objectStore.preparePackStream(d);o=await Dr(r.objectStore,u)}else await r.objectStore.ingestPackStream(d)}catch(l){if(l instanceof _)throw l;i=!1}return{updates:await _r(r,e,i),unpackOk:i,capabilities:t,sawFlush:s,ingestedHashes:o}}async function _r(r,e,t){let n=[];for(let s of e){let a=s.oldHash===Y,i=s.newHash===Y;if(a)n.push({ref:s.refName,oldHash:null,newHash:s.newHash,isFF:!1,isCreate:!0,isDelete:!1});else if(i)n.push({ref:s.refName,oldHash:s.oldHash,newHash:s.newHash,isFF:!1,isCreate:!1,isDelete:!0});else{let o=!1;if(t)try{o=await ft(r,s.oldHash,s.newHash)}catch{}n.push({ref:s.refName,oldHash:s.oldHash,newHash:s.newHash,isFF:o,isCreate:!1,isDelete:!1})}}return n}async function Xe(r,e){let t=[],n=[];for(let s of e){if(s.ref==="HEAD"){t.push({ref:s.ref,ok:!1,error:"HEAD cannot be updated via push"});continue}if(!s.isDelete&&!it(s.ref)){t.push({ref:s.ref,ok:!1,error:"invalid refname"});continue}if(!s.isDelete&&!await r.objectStore.exists(s.newHash)){t.push({ref:s.ref,ok:!1,error:"missing objects"});continue}try{let a=s.isCreate?null:s.oldHash,i=s.isDelete?null:{type:"direct",hash:s.newHash};if(!await r.refStore.compareAndSwapRef(s.ref,a,i)){t.push({ref:s.ref,ok:!1,error:"failed to lock"});continue}t.push({ref:s.ref,ok:!0}),n.push(s)}catch(a){t.push({ref:s.ref,ok:!1,error:a instanceof Error?a.message:String(a)})}}return{refResults:t,applied:n}}async function je(r){let{repo:e,repoId:t,ingestResult:n,hooks:s,auth:a}=r,{updates:i}=n;if(s?.preReceive){let c=await s.preReceive({repo:e,repoId:t,updates:i,auth:a});if(U(c)){n.ingestedHashes?.length&&await Wn(e,n.ingestedHashes);let l=c.message??"pre-receive hook declined";return{refResults:i.map(d=>({ref:d.ref,ok:!1,error:l})),applied:[]}}}let o=[],f=[];for(let c of i){if(c.ref==="HEAD"){o.push({ref:c.ref,ok:!1,error:"HEAD cannot be updated via push"});continue}if(!c.isDelete&&!it(c.ref)){o.push({ref:c.ref,ok:!1,error:"invalid refname"});continue}if(s?.update){let l=await s.update({repo:e,repoId:t,update:c,auth:a});if(U(l)){o.push({ref:c.ref,ok:!1,error:l.message??"update hook declined"});continue}}if(!c.isDelete&&!await e.objectStore.exists(c.newHash)){o.push({ref:c.ref,ok:!1,error:"missing objects"});continue}try{let l=c.isCreate?null:c.oldHash,d=c.isDelete?null:{type:"direct",hash:c.newHash};if(!await e.refStore.compareAndSwapRef(c.ref,l,d)){o.push({ref:c.ref,ok:!1,error:"failed to lock"});continue}o.push({ref:c.ref,ok:!0}),f.push(c)}catch(l){o.push({ref:c.ref,ok:!1,error:l instanceof Error?l.message:String(l)})}}if(s?.postReceive&&f.length>0)try{await s.postReceive({repo:e,repoId:t,updates:f,auth:a})}catch{}return{refResults:o,applied:f}}async function Ke(r,e){let t=[];for(let n of e){let s=n.oldHash!==void 0?n.oldHash:await Re(r,n.ref);if(s===null)t.push({ref:n.ref,oldHash:null,newHash:n.newHash??Y,isFF:!1,isCreate:!0,isDelete:!1});else if(n.newHash===null)t.push({ref:n.ref,oldHash:s,newHash:Y,isFF:!1,isCreate:!1,isDelete:!0});else{let a=!1;try{a=await ft(r,s,n.newHash)}catch{}t.push({ref:n.ref,oldHash:s,newHash:n.newHash,isFF:a,isCreate:!1,isDelete:!1})}}return t}var $n=["agent=just-git/1.0","ls-refs=unborn","fetch=shallow","server-option","object-format=sha1"];function ve(){return ht($n)}async function Te(r,e,t,n,s){let a=t.includes("symrefs"),i=t.includes("peel"),o=t.includes("unborn"),f=t.filter(h=>h.startsWith("ref-prefix ")).map(h=>h.slice(11)),c=await G(r,e,"git-upload-pack",n,s);if(U(c))return c;let{refs:l,headTarget:d}=c,u=[];for(let h of l){if(h.name.endsWith("^{}")||f.length>0&&!f.some(g=>h.name.startsWith(g)))continue;let p={hash:h.hash,name:h.name};if(a&&h.name==="HEAD"&&d&&(p.symrefTarget=d),i&&h.name.startsWith("refs/tags/")){let g=l.find(w=>w.name===`${h.name}^{}`);g&&(p.peeledHash=g.hash)}u.push(p)}return o&&!u.some(h=>h.name==="HEAD")&&d&&(f.length===0||f.some(p=>"HEAD".startsWith(p)))&&u.unshift({hash:"unborn",name:"HEAD",symrefTarget:d}),mt(u)}async function Ie(r,e,t){let{wants:n,haves:s,done:a,clientShallows:i,depth:o,includeTag:f,wantRefs:c}=bt(e);if(n.length===0&&c.length===0){let{data:y}=await te([]);return se(y)}let l=t?.authorizedFetchSet,d=[],u=[...n];for(let y of c)if(l){let R=l.allowedRefHashes.get(y);if(!R)return{reject:!0,message:`forbidden want-ref ${y}`};d.push({hash:R,name:y}),u.includes(R)||u.push(R)}else{let R=await Re(r,y);R&&(d.push({hash:R,name:y}),u.includes(R)||u.push(R))}if(l){for(let y of n)if(!l.allowedWantHashes.has(y))return{reject:!0,message:`forbidden want ${y}`}}let h,p,g;if(i.length>0&&(g=new Set(i)),o!==void 0){let y=await dt(r,u,o,g??new Set);h=y,p=new Set(y.shallow)}let w;if(s.length>0){w=[];for(let y of s)await r.objectStore.exists(y)&&w.push(y);w.length===0&&(w=void 0)}let O=w&&w.length>0;if(!a&&!O)return Pr(w??[]);let k=!p&&t?.cache&&t.cacheKey?ae.key(t.cacheKey,u,s):null,x={commonHashes:w,shallowInfo:h,wantedRefs:d.length>0?d:void 0};if(k&&t?.cache){let y=t.cache.get(k);if(y)return se(y.packData,x)}let m={repo:r,wants:u,haves:s,includeTag:f,shallowBoundary:p,clientShallowBoundary:g,cache:t?.cache,cacheKey:k,deltaWindow:t?.deltaWindow};if(t?.noDelta){let y=await Cr(m);if(!y){let{data:R}=await te([]);return se(R,x)}return Hr(Sr(y,x))}let b=await Ur(m);return se(b,x)}function Gn(r,e){if(e){if(e.maxPackBytes!==void 0&&r.byteLength>e.maxPackBytes)throw new _("Pack payload too large");if(e.maxPackObjects!==void 0&&r.byteLength>=12&&new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(8)>e.maxPackObjects)throw new _("Pack contains too many objects")}}async function*qn(r,e){if(!e){for await(let a of r)yield a;return}let t=0,n=new Uint8Array(12),s=0;for await(let a of r){if(t+=a.byteLength,e.maxPackBytes!==void 0&&t>e.maxPackBytes)throw new _("Pack payload too large");if(s<12){let i=Math.min(12-s,a.byteLength);if(n.set(a.subarray(0,i),s),s+=i,s===12&&e.maxPackObjects!==void 0&&new DataView(n.buffer).getUint32(8)>e.maxPackObjects)throw new _("Pack contains too many objects")}yield a}}function Vn(r){let e=/--protocol=version=2/.test(r),n=r.replace(/\s*--protocol=version=\d+/g,"").match(/^git[\s-](upload-pack|receive-pack)\s+'?([^']+?)'?\s*$/);if(!n)return null;let s=`git-${n[1]}`,a=n[2];return a.startsWith("/")&&(a=a.slice(1)),e?{service:s,repoPath:a,protocolV2:e}:{service:s,repoPath:a}}var zn=new TextEncoder;async function Br(r,e,t){let{resolveRepo:n,hooks:s,packCache:a,packOptions:i,receiveLimits:o,fetchLimits:f,auth:c}=t,l=e.writable.getWriter();try{let d=Vn(r);if(!d)return Le(e,`fatal: unrecognized command '${r}'
|
|
58
|
-
`),128;let{service:
|
|
59
|
-
`),128;let{repo:g,repoId:w}=
|
|
60
|
-
`),128):(t.onError?.(
|
|
61
|
-
`),128)}finally{try{await l.close()}catch{}}}async function
|
|
62
|
-
`),128}var
|
|
63
|
-
`)&&(a=a.slice(0,-1)),n){let o=a.indexOf("\0");o!==-1&&(t=a.slice(o+1).split(" ").filter(Boolean),a=a.slice(0,o)),n=!1}let i=a.split(" ");i.length>=3&&e.push({oldHash:i[0],newHash:i[1],refName:i[2]})}return{commands:e,capabilities:t}}async function
|
|
64
|
-
`)&&(c=c.slice(0,-1)),a?s.push(c):c.startsWith("command=")?t=c.slice(8):n.push(c)}return t?{command:t,capabilities:n,args:s}:null}function
|
|
56
|
+
`));a.push(Y()),yield _(...a)}yield E(`packfile
|
|
57
|
+
`);for await(let a of r){let i=0;for(;i<a.byteLength;){let o=Math.min(qe,a.byteLength-i);yield Oe(1,a.subarray(i,i+o)),i+=o}}yield N()}var M=class extends Error{status=413;constructor(e){super(e),this.name="RequestLimitError"}};function Tr(r){async function e(t){let n=r.getForkParent?await r.getForkParent(t):null;return{objectStore:new wt(r,t,n),refStore:new Rt(r,t)}}return{async createRepo(t,n){if(await r.hasRepo(t))throw new Error(`repo '${t}' already exists`);let a=n?.defaultBranch??"main";return await r.insertRepo(t),await r.putRef(t,"HEAD",{type:"symbolic",target:`refs/heads/${a}`}),e(t)},async repo(t){return await r.hasRepo(t)?e(t):null},async deleteRepo(t){if(r.listForks){let n=await r.listForks(t);if(n.length>0)throw new Error(`cannot delete repo '${t}': has ${n.length} active fork(s)`)}await r.deleteRepo(t)},async forkRepo(t,n,s){if(!r.forkRepo||!r.getForkParent||!r.listForks)throw new Error("storage backend does not support forks");if(!await r.hasRepo(t))throw new Error(`source repo '${t}' not found`);if(await r.hasRepo(n))throw new Error(`repo '${n}' already exists`);let f=await r.getForkParent(t)??t;await r.insertRepo(n),await r.forkRepo(f,n);let c=await r.listRefs(t);for(let u of c)await r.putRef(n,u.name,u.ref);let l=await r.getRef(t,"HEAD");if(l)await r.putRef(n,"HEAD",l);else{let u=s?.defaultBranch??"main";await r.putRef(n,"HEAD",{type:"symbolic",target:`refs/heads/${u}`})}return e(n)}}}function ze(r){return typeof r=="object"&&r!==null&&typeof r.preparePack=="function"&&typeof r.commitPack=="function"&&typeof r.deleteObjects=="function"}var wt=class{constructor(e,t,n=null){this.driver=e;this.repoId=t;this.parentId=n}cache=new De;async write(e,t){let n=ir(e,t),s=await _t(n);return await this.driver.putObject(this.repoId,s,e,t),s}async read(e){let t=this.cache.get(e);if(t)return t;let n=await this.driver.getObject(this.repoId,e);if(!n&&this.parentId&&(n=await this.driver.getObject(this.parentId,e)),!n)throw new Error(`object ${e} not found`);return this.cache.set(e,n),n}async readMany(e){let t=Ir(e),n=new Map,s=[];for(let a of t){let i=this.cache.get(a);i?n.set(a,i):s.push(a)}if(s.length>0){let a=await this.loadObjects(this.repoId,s);for(let[i,o]of a)this.cache.set(i,o),n.set(i,o)}if(this.parentId){let a=s.filter(i=>!n.has(i));if(a.length>0){let i=await this.loadObjects(this.parentId,a);for(let[o,f]of i)this.cache.set(o,f),n.set(o,f)}}return n}async exists(e){return await this.driver.hasObject(this.repoId,e)?!0:this.parentId?!!await this.driver.hasObject(this.parentId,e):!1}async existsMany(e){let t=Ir(e),n=new Set,s=[];for(let a of t)this.cache.get(a)?n.add(a):s.push(a);if(s.length>0){let a=await this.checkObjects(this.repoId,s);for(let i of a)n.add(i)}if(this.parentId){let a=s.filter(i=>!n.has(i));if(a.length>0){let i=await this.checkObjects(this.parentId,a);for(let o of i)n.add(o)}}return n}async preparePack(e){if(e.byteLength<32)return[];let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0);if(n!==1346454347)throw new Error(`invalid pack signature: 0x${n.toString(16)} (expected 0x5041434b)`);let s=t.getUint32(4);if(s!==2)throw new Error(`unsupported pack version: ${s}`);if(t.getUint32(8)===0)return[];let i=this.driver,o=this.repoId,f=this.parentId;return(await nr(e,async l=>{let u=await i.getObject(o,l);return!u&&f&&(u=await i.getObject(f,l)),u?{type:u.type,content:new Uint8Array(u.content)}:null})).map(l=>({hash:l.hash,type:l.type,content:l.content}))}async preparePackStream(e){let t=[];for await(let n of e)t.push({hash:n.hash,type:n.type,content:n.content});return t}async commitPack(e){return e.length===0?[]:await this.driver.putObjects(this.repoId,e)}async ingestPack(e){let t=await this.preparePack(e);return(await this.commitPack(t)).length}async ingestPackStream(e){let t=await this.preparePackStream(e);return(await this.commitPack(t)).length}async deleteObjects(e){return e.length===0?0:this.driver.deleteObjects(this.repoId,e)}async findByPrefix(e){if(e.length<4)return[];let t=await this.driver.findObjectsByPrefix(this.repoId,e);if(!this.parentId)return Array.from(t);let n=await this.driver.findObjectsByPrefix(this.parentId,e),s=new Set(t);for(let a of n)s.add(a);return Array.from(s)}async loadObjects(e,t){if(t.length===0)return new Map;if(this.driver.getObjects){let s=await this.driver.getObjects(e,t);return new Map(s)}let n=new Map;for(let s of t){let a=await this.driver.getObject(e,s);a&&n.set(s,a)}return n}async checkObjects(e,t){if(t.length===0)return new Set;if(this.driver.hasObjects){let s=await this.driver.hasObjects(e,t);return new Set(s)}let n=new Set;for(let s of t)await this.driver.hasObject(e,s)&&n.add(s);return n}},Rt=class{constructor(e,t){this.driver=e;this.repoId=t}async readRef(e){return await this.driver.getRef(this.repoId,e)??null}async writeRef(e,t){await this.driver.putRef(this.repoId,e,lr(t))}async deleteRef(e){await this.driver.removeRef(this.repoId,e)}async listRefs(e){let t=await this.driver.listRefs(this.repoId,e),n=[];for(let s of t)if(s.ref.type==="direct")n.push({name:s.name,hash:s.ref.hash});else if(s.ref.type==="symbolic"){let a=await xt(i=>this.driver.getRef(this.repoId,i),s.ref.target);a&&n.push({name:s.name,hash:a})}return n}async compareAndSwapRef(e,t,n){return!!await this.driver.atomicRefUpdate(this.repoId,s=>Ae(s.getRef(e),a=>{let i=a?a.type==="direct"?a.hash:xt(o=>s.getRef(o),a.target):null;return Ae(i,o=>{if(t===null){if(a!==null)return!1}else if(o!==t)return!1;return n===null?Ae(s.removeRef(e),()=>!0):Ae(s.putRef(e,n),()=>!0)})}))}};function Ae(r,e){return r instanceof Promise?r.then(e):e(r)}function xt(r,e,t=0){return t>10?null:Ae(r(e),n=>n?n.type==="direct"?n.hash:n.type==="symbolic"?xt(r,n.target,t+1):null:null)}function Ir(r){return Array.from(new Set(r))}var le=class{entries=new Map;currentBytes=0;maxBytes;hits=0;misses=0;constructor(e=256*1024*1024){this.maxBytes=e}static key(e,t,n){if(n.length>0)return null;let s=t.slice().sort();return`${e}\0${s.join(",")}`}get(e){let t=this.entries.get(e);return t?this.hits++:this.misses++,t}set(e,t){if(this.entries.has(e))return;let n=t.packData.byteLength;if(!(n>this.maxBytes)){for(;this.currentBytes+n>this.maxBytes&&this.entries.size>0;){let s=this.entries.keys().next().value;this.currentBytes-=this.entries.get(s).packData.byteLength,this.entries.delete(s)}this.entries.set(e,t),this.currentBytes+=n}}clear(){this.entries.clear(),this.currentBytes=0}get stats(){return{entries:this.entries.size,bytes:this.currentBytes,hits:this.hits,misses:this.misses}}},Ur=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag","shallow"],Cr=["report-status","side-band-64k","ofs-delta","delete-refs"];async function Hr(r){let e=await r.refStore.listRefs("refs"),t=await r.refStore.readRef("HEAD"),n=[],s=null,a;if(t)if(t.type==="symbolic"){a=t.target;let o=await r.refStore.readRef(t.target);o?.type==="direct"&&(s=o.hash)}else s=t.hash;let i=e.slice().sort((o,f)=>o.name<f.name?-1:o.name>f.name?1:0);if(!s&&i.length>0){let o=zn(i);o&&(s=o.hash,a=o.name)}s&&n.push({name:"HEAD",hash:s});for(let o of i)if(n.push({name:o.name,hash:o.hash}),o.name.startsWith("refs/tags/"))try{let f=await r.objectStore.read(o.hash);if(f.type==="tag"){let c=X(f.content);n.push({name:`${o.name}^{}`,hash:c.object})}}catch{}return{refs:n,headTarget:a}}var Vn=["refs/heads/main","refs/heads/master"];function zn(r){for(let t of Vn){let n=r.find(s=>s.name===t);if(n)return n}return r.find(t=>t.name.startsWith("refs/heads/"))??null}function Et(r,e,t){return Or(r,e,e==="git-upload-pack"?Ur:Cr,t)}function Ot(r,e,t){return Ve(r,e==="git-upload-pack"?Ur:Cr,t)}async function $(r,e,t,n,s){let{refs:a,headTarget:i}=await Hr(r),o=a;if(n?.advertiseRefs){let c=await n.advertiseRefs({repo:r,repoId:e,refs:a,service:t,auth:s});if(U(c))return c;c&&(o=c)}let f=i&&o.some(c=>c.name==="HEAD")&&o.some(c=>c.name===i)?i:void 0;return{refs:o,headTarget:f}}function ke(r){let e=new Map,t=new Set;for(let n of r.refs)e.set(n.name,n.hash),t.add(n.hash);return{allowedRefHashes:e,allowedWantHashes:t}}async function Se(r,e,t){let{wants:n,haves:s,capabilities:a,clientShallows:i,depth:o,done:f}=Ar(e);if(n.length===0)return Ee(new Uint8Array(0),!1);if(t?.authorizedFetchSet){for(let x of n)if(!t.authorizedFetchSet.allowedWantHashes.has(x))return{reject:!0,message:`forbidden want ${x}`}}let c=a.includes("multi_ack_detailed"),l=a.includes("side-band-64k"),u,d,p;if(i.length>0&&(p=new Set(i)),o!==void 0){let x=await dt(r,n,o,p??new Set);u=x,d=new Set(x.shallow)}if(u&&!f)return kr(u);let h;if(c&&s.length>0){let x=r.objectStore.existsMany?await r.objectStore.existsMany(s):await Kn(r.objectStore,s);h=s.filter(y=>x.has(y)),h.length===0&&(h=void 0)}let g=!d&&t?.cache&&t.cacheKey?le.key(t.cacheKey,n,s):null;if(g&&t?.cache){let x=t.cache.get(g);if(x)return Ee(x.packData,l,h)}let w=a.includes("include-tag"),A={repo:r,wants:n,haves:s,includeTag:w,shallowBoundary:d,clientShallowBoundary:p,cache:t?.cache,cacheKey:g,deltaWindow:t?.deltaWindow};if(t?.noDelta){let x=await _r(A);if(!x){let{data:y}=await se([]);return Ee(y,l,h,u)}return Nr(Sr(x,l,h,u))}let O=await Mr(A);return Ee(O,l,h,u)}var Xn=128;async function Dr(r,e){let t=[],n=await r.refStore.listRefs("refs/tags");for(let s of n)if(!e.has(s.hash))try{let a=await r.objectStore.read(s.hash);if(a.type==="tag"){let i=X(a.content);e.has(i.object)&&(t.push({hash:s.hash,type:"tag",content:a.content}),e.add(s.hash))}}catch{}return t}async function Mr(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:i}=r,o=await gr(e,t,n,a,i);if(o.count===0){let{data:h}=await se([]);return h}let f=await Rr(o),c=new Set(f.map(h=>h.hash));if(s){let h=await Dr(e,c);f.push(...h)}let l=r.deltaWindow?{window:r.deltaWindow}:void 0,u=br(f,l),d=u.map(h=>({hash:h.hash,type:h.type,content:h.content,delta:h.delta,deltaBaseHash:h.deltaBase})),{data:p}=await se(d);if(r.cacheKey&&r.cache){let h=u.filter(g=>g.delta).length;r.cache.set(r.cacheKey,{packData:p,objectCount:f.length,deltaCount:h})}return p}async function _r(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:i}=r,{count:o,objects:f}=await Ge(e,t,n,a,i);if(o===0)return null;let c=[];for await(let h of f)c.push(h);let l=new Set(c.map(h=>h.hash)),u=s?await Dr(e,l):[],d=c.length+u.length;async function*p(){for(let h of Yn(c,Xn)){let g=e.objectStore.readMany?await e.objectStore.readMany(h.map(w=>w.hash)):null;for(let w of h){let A=g?.get(w.hash)??await e.objectStore.read(w.hash);yield{type:A.type,content:A.content}}}for(let h of u)yield{type:h.type,content:h.content}}return ar(d,p())}function Nr(r){let e=r[Symbol.asyncIterator]();return new ReadableStream({async pull(t){let{value:n,done:s}=await e.next();s?t.close():t.enqueue(n)}})}async function Kn(r,e){let t=new Set;for(let n of e)await r.exists(n)&&t.add(n);return t}function Yn(r,e){let t=[];for(let n=0;n<r.length;n+=e)t.push(r.slice(n,n+e));return t}async function Br(r,e){return await r.commitPack(e)}async function Lr(r,e){ze(r.objectStore)&&await r.objectStore.deleteObjects(e)}async function At(r,e,t){let{commands:n,packData:s,capabilities:a,sawFlush:i}=jr(e),o=!0,f;if(s.byteLength>0)try{if(Jn(s,t),ze(r.objectStore)){let l=await r.objectStore.preparePack(s);f=await Br(r.objectStore,l)}else await r.objectStore.ingestPack(s)}catch(l){if(l instanceof M)throw l;o=!1}return{updates:await Fr(r,n,o),unpackOk:o,capabilities:a,sawFlush:i,ingestedHashes:f}}async function kt(r,e,t,n,s=!0,a){let i=!0,o;if(e.some(l=>l.newHash!==Q))try{let l=async d=>{try{return await r.objectStore.read(d)}catch{return null}},u=sr(Qn(n,a),l);if(ze(r.objectStore)){let d=await r.objectStore.preparePackStream(u);o=await Br(r.objectStore,d)}else await r.objectStore.ingestPackStream(u)}catch(l){if(l instanceof M)throw l;i=!1}return{updates:await Fr(r,e,i),unpackOk:i,capabilities:t,sawFlush:s,ingestedHashes:o}}async function Fr(r,e,t){let n=[];for(let s of e){let a=s.oldHash===Q,i=s.newHash===Q;if(a)n.push({ref:s.refName,oldHash:null,newHash:s.newHash,isFF:!1,isCreate:!0,isDelete:!1});else if(i)n.push({ref:s.refName,oldHash:s.oldHash,newHash:s.newHash,isFF:!1,isCreate:!1,isDelete:!0});else{let o=!1;if(t)try{o=await lt(r,s.oldHash,s.newHash)}catch{}n.push({ref:s.refName,oldHash:s.oldHash,newHash:s.newHash,isFF:o,isCreate:!1,isDelete:!1})}}return n}async function Xe(r,e){let t=[],n=[];for(let s of e){if(s.ref==="HEAD"){t.push({ref:s.ref,ok:!1,error:"HEAD cannot be updated via push"});continue}if(!s.isDelete&&!ot(s.ref)){t.push({ref:s.ref,ok:!1,error:"invalid refname"});continue}if(!s.isDelete&&!await r.objectStore.exists(s.newHash)){t.push({ref:s.ref,ok:!1,error:"missing objects"});continue}try{let a=s.isCreate?null:s.oldHash,i=s.isDelete?null:{type:"direct",hash:s.newHash};if(!await r.refStore.compareAndSwapRef(s.ref,a,i)){t.push({ref:s.ref,ok:!1,error:"failed to lock"});continue}t.push({ref:s.ref,ok:!0}),n.push(s)}catch(a){t.push({ref:s.ref,ok:!1,error:a instanceof Error?a.message:String(a)})}}return{refResults:t,applied:n}}async function je(r){let{repo:e,repoId:t,ingestResult:n,hooks:s,auth:a}=r,{updates:i}=n;if(s?.preReceive){let c=await s.preReceive({repo:e,repoId:t,updates:i,auth:a});if(U(c)){n.ingestedHashes?.length&&await Lr(e,n.ingestedHashes);let l=c.message??"pre-receive hook declined";return{refResults:i.map(u=>({ref:u.ref,ok:!1,error:l})),applied:[]}}}let o=[],f=[];for(let c of i){if(c.ref==="HEAD"){o.push({ref:c.ref,ok:!1,error:"HEAD cannot be updated via push"});continue}if(!c.isDelete&&!ot(c.ref)){o.push({ref:c.ref,ok:!1,error:"invalid refname"});continue}if(s?.update){let l=await s.update({repo:e,repoId:t,update:c,auth:a});if(U(l)){o.push({ref:c.ref,ok:!1,error:l.message??"update hook declined"});continue}}if(!c.isDelete&&!await e.objectStore.exists(c.newHash)){o.push({ref:c.ref,ok:!1,error:"missing objects"});continue}try{let l=c.isCreate?null:c.oldHash,u=c.isDelete?null:{type:"direct",hash:c.newHash};if(!await e.refStore.compareAndSwapRef(c.ref,l,u)){o.push({ref:c.ref,ok:!1,error:"failed to lock"});continue}o.push({ref:c.ref,ok:!0}),f.push(c)}catch(l){o.push({ref:c.ref,ok:!1,error:l instanceof Error?l.message:String(l)})}}if(f.length===0&&n.ingestedHashes?.length&&await Lr(e,n.ingestedHashes),s?.postReceive&&f.length>0)try{await s.postReceive({repo:e,repoId:t,updates:f,auth:a})}catch{}return{refResults:o,applied:f}}async function Ke(r,e){let t=[];for(let n of e){let s=n.oldHash!==void 0?n.oldHash:await we(r,n.ref);if(s===null)t.push({ref:n.ref,oldHash:null,newHash:n.newHash??Q,isFF:!1,isCreate:!0,isDelete:!1});else if(n.newHash===null)t.push({ref:n.ref,oldHash:s,newHash:Q,isFF:!1,isCreate:!1,isDelete:!0});else{let a=!1;try{a=await lt(r,s,n.newHash)}catch{}t.push({ref:n.ref,oldHash:s,newHash:n.newHash,isFF:a,isCreate:!1,isDelete:!1})}}return t}var Zn=["agent=just-git/1.0","ls-refs=unborn","fetch=shallow","server-option","object-format=sha1"];function Pe(){return yt(Zn)}async function ve(r,e,t,n,s){let a=t.includes("symrefs"),i=t.includes("peel"),o=t.includes("unborn"),f=t.filter(p=>p.startsWith("ref-prefix ")).map(p=>p.slice(11)),c=await $(r,e,"git-upload-pack",n,s);if(U(c))return c;let{refs:l,headTarget:u}=c,d=[];for(let p of l){if(p.name.endsWith("^{}")||f.length>0&&!f.some(g=>p.name.startsWith(g)))continue;let h={hash:p.hash,name:p.name};if(a&&p.name==="HEAD"&&u&&(h.symrefTarget=u),i&&p.name.startsWith("refs/tags/")){let g=l.find(w=>w.name===`${p.name}^{}`);g&&(h.peeledHash=g.hash)}d.push(h)}return o&&!d.some(p=>p.name==="HEAD")&&u&&(f.length===0||f.some(h=>"HEAD".startsWith(h)))&&d.unshift({hash:"unborn",name:"HEAD",symrefTarget:u}),bt(d)}async function Ie(r,e,t){let{wants:n,haves:s,done:a,clientShallows:i,depth:o,includeTag:f,wantRefs:c}=gt(e);if(n.length===0&&c.length===0){let{data:m}=await se([]);return fe(m)}let l=t?.authorizedFetchSet,u=[],d=[...n];for(let m of c)if(l){let R=l.allowedRefHashes.get(m);if(!R)return{reject:!0,message:`forbidden want-ref ${m}`};u.push({hash:R,name:m}),d.includes(R)||d.push(R)}else{let R=await we(r,m);R&&(u.push({hash:R,name:m}),d.includes(R)||d.push(R))}if(l){for(let m of n)if(!l.allowedWantHashes.has(m))return{reject:!0,message:`forbidden want ${m}`}}let p,h,g;if(i.length>0&&(g=new Set(i)),o!==void 0){let m=await dt(r,d,o,g??new Set);p=m,h=new Set(m.shallow)}let w;if(s.length>0){w=[];for(let m of s)await r.objectStore.exists(m)&&w.push(m);w.length===0&&(w=void 0)}let A=w&&w.length>0;if(!a&&!A)return Pr(w??[]);let O=!h&&t?.cache&&t.cacheKey?le.key(t.cacheKey,d,s):null,x={commonHashes:w,shallowInfo:p,wantedRefs:u.length>0?u:void 0};if(O&&t?.cache){let m=t.cache.get(O);if(m)return fe(m.packData,x)}let y={repo:r,wants:d,haves:s,includeTag:f,shallowBoundary:h,clientShallowBoundary:g,cache:t?.cache,cacheKey:O,deltaWindow:t?.deltaWindow};if(t?.noDelta){let m=await _r(y);if(!m){let{data:R}=await se([]);return fe(R,x)}return Nr(vr(m,x))}let b=await Mr(y);return fe(b,x)}function Jn(r,e){if(e){if(e.maxPackBytes!==void 0&&r.byteLength>e.maxPackBytes)throw new M("Pack payload too large");if(e.maxPackObjects!==void 0&&r.byteLength>=12&&new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(8)>e.maxPackObjects)throw new M("Pack contains too many objects")}}async function*Qn(r,e){if(!e){for await(let a of r)yield a;return}let t=0,n=new Uint8Array(12),s=0;for await(let a of r){if(t+=a.byteLength,e.maxPackBytes!==void 0&&t>e.maxPackBytes)throw new M("Pack payload too large");if(s<12){let i=Math.min(12-s,a.byteLength);if(n.set(a.subarray(0,i),s),s+=i,s===12&&e.maxPackObjects!==void 0&&new DataView(n.buffer).getUint32(8)>e.maxPackObjects)throw new M("Pack contains too many objects")}yield a}}function es(r){let e=/--protocol=version=2/.test(r),n=r.replace(/\s*--protocol=version=\d+/g,"").match(/^git[\s-](upload-pack|receive-pack)\s+'?([^']+?)'?\s*$/);if(!n)return null;let s=`git-${n[1]}`,a=n[2];return a.startsWith("/")&&(a=a.slice(1)),e?{service:s,repoPath:a,protocolV2:e}:{service:s,repoPath:a}}var ts=new TextEncoder;async function Wr(r,e,t){let{resolveRepo:n,hooks:s,packCache:a,packOptions:i,receiveLimits:o,fetchLimits:f,auth:c}=t,l=e.writable.getWriter();try{let u=es(r);if(!u)return Te(e,`fatal: unrecognized command '${r}'
|
|
58
|
+
`),128;let{service:d,repoPath:p}=u,h=await n(p);if(!h)return Te(e,`fatal: '${p}' does not appear to be a git repository
|
|
59
|
+
`),128;let{repo:g,repoId:w}=h;if(u.protocolV2&&d==="git-upload-pack"){let x=await $(g,w,d,s,c);if(U(x))return ue(e,x);await l.write(Pe());let y=new Ye(e.readable);try{return await as(y,l,g,w,e,{hooks:s,packCache:a,packOptions:i,receiveLimits:o,fetchLimits:f,auth:c})}finally{y.release()}}let A=await $(g,w,d,s,c);if(U(A))return ue(e,A);await l.write(Ot(A.refs,d,A.headTarget));let O=new Ye(e.readable);try{if(d==="git-upload-pack"){let x=s?.advertiseRefs?ke(A):void 0,y=await ns(O,f?.maxRequestBytes),b=await Se(g,y,{cache:a,cacheKey:w,noDelta:i?.noDelta,deltaWindow:i?.deltaWindow,authorizedFetchSet:x});if(U(b))return ue(e,b);await Gr(l,b)}else{let{commands:x,capabilities:y}=await ss(O),b=O.streamRemaining();await rs({writer:l,repo:g,repoId:w,commands:x,capabilities:y,packStream:b,hooks:s,receiveLimits:o,auth:c})}}finally{O.release()}return 0}catch(u){return u instanceof M?(Te(e,`fatal: ${u.message}
|
|
60
|
+
`),128):(t.onError?.(u),Te(e,`fatal: internal error
|
|
61
|
+
`),128)}finally{try{await l.close()}catch{}}}async function rs(r){let{writer:e,repo:t,repoId:n,commands:s,capabilities:a,packStream:i,hooks:o,receiveLimits:f,auth:c}=r,l=await kt(t,s,a,i,!0,f);if(l.updates.length===0)return;let u=l.capabilities.includes("side-band-64k"),d=l.capabilities.includes("report-status");if(!l.unpackOk){if(d){let h=l.updates.map(g=>({name:g.ref,ok:!1,error:"unpack failed"}));await e.write(ce(!1,h,u))}return}let{refResults:p}=await je({repo:t,repoId:n,ingestResult:l,hooks:o,auth:c});if(d){let h=p.map(g=>({name:g.ref,ok:g.ok,error:g.error}));await e.write(ce(!0,h,u))}}function Te(r,e){r.writeStderr?.(ts.encode(e))}function ue(r,e){return Te(r,`fatal: ${e.message??"access denied"}
|
|
62
|
+
`),128}var $r=new TextDecoder,Ye=class{buf=new Uint8Array(0);byteReader;eof=!1;constructor(e){this.byteReader=e.getReader()}async fill(e){for(;this.buf.byteLength<e&&!this.eof;){let t=await this.byteReader.read();if(t.done||!t.value){this.eof=!0;break}let n=t.value,s=new Uint8Array(this.buf.byteLength+n.byteLength);s.set(this.buf),s.set(n,this.buf.byteLength),this.buf=s}return this.buf.byteLength>=e}consume(e){let t=this.buf.subarray(0,e);return this.buf=this.buf.subarray(e),t}async readPktLine(){if(!await this.fill(4))return null;let e=$r.decode(this.buf.subarray(0,4)),t=parseInt(e,16);if(t===0)return{type:"flush",raw:this.consume(4)};if(t===1)return{type:"delim",raw:this.consume(4)};if(t===2)return{type:"response-end",raw:this.consume(4)};if(t<4||!await this.fill(t))return null;let n=new Uint8Array(this.consume(t));return{type:"data",raw:n,text:$r.decode(n.subarray(4))}}async*streamRemaining(){for(this.buf.byteLength>0&&(yield this.consume(this.buf.byteLength));!this.eof;){let e=await this.byteReader.read();if(e.done||!e.value){this.eof=!0;break}yield e.value}}release(){this.byteReader.releaseLock()}};async function ns(r,e){let t=[],n=0;for(;;){let s=await r.readPktLine();if(!s)break;if(n+=s.raw.byteLength,e!==void 0&&n>e)throw new M("Request body too large");if(t.push(s.raw),s.type==="data"&&s.text.trimEnd()==="done")break}return os(t)}async function ss(r){let e=[],t=[],n=!0;for(;;){let s=await r.readPktLine();if(!s||s.type==="flush")break;if(s.type!=="data")continue;let a=s.text;if(a.endsWith(`
|
|
63
|
+
`)&&(a=a.slice(0,-1)),n){let o=a.indexOf("\0");o!==-1&&(t=a.slice(o+1).split(" ").filter(Boolean),a=a.slice(0,o)),n=!1}let i=a.split(" ");i.length>=3&&e.push({oldHash:i[0],newHash:i[1],refName:i[2]})}return{commands:e,capabilities:t}}async function as(r,e,t,n,s,a){let{hooks:i,packCache:o,packOptions:f,fetchLimits:c,auth:l}=a;for(;;){let u=await is(r,c?.maxRequestBytes);if(!u)break;if(u.command==="ls-refs"){let d=await ve(t,n,u.args,i,l);if(U(d))return ue(s,d);await e.write(d)}else if(u.command==="fetch"){let d;if(i?.advertiseRefs){let h=await $(t,n,"git-upload-pack",i,l);if(U(h))return ue(s,h);d=ke(h)}let p=await Ie(t,u.args,{cache:o,cacheKey:n,noDelta:f?.noDelta,deltaWindow:f?.deltaWindow,authorizedFetchSet:d});if(U(p))return ue(s,p);await Gr(e,p)}else break}return 0}async function is(r,e){let t="",n=[],s=[],a=!1,i=!1,o=0;for(;;){let f=await r.readPktLine();if(!f)return i?{command:t,capabilities:n,args:s}:null;if(f.type==="flush"){if(!i)return null;break}if(f.type==="response-end")break;if(o+=f.raw.byteLength,e!==void 0&&o>e)throw new M("Request body too large");if(f.type==="delim"){a=!0;continue}i=!0;let c=f.text;c.endsWith(`
|
|
64
|
+
`)&&(c=c.slice(0,-1)),a?s.push(c):c.startsWith("command=")?t=c.slice(8):n.push(c)}return t?{command:t,capabilities:n,args:s}:null}function os(r){if(r.length===0)return new Uint8Array(0);if(r.length===1)return r[0];let e=0;for(let s of r)e+=s.byteLength;let t=new Uint8Array(e),n=0;for(let s of r)t.set(s,n),n+=s.byteLength;return t}async function Gr(r,e){if(e instanceof ReadableStream){let t=e.getReader();try{for(;;){let{value:n,done:s}=await t.read();if(s)break;await r.write(n)}}finally{t.releaseLock()}}else await r.write(e)}async function Vr(r,e,t,n,s){let a=n?.dryRun??!1,i=await qr(r),o=cs(i);if(s)for(let h of s)o.push(h);if(o.length===0)return{deleted:0,retained:0};let f=await Ge(r,o,[]),c=new Set;for await(let h of f.objects)c.add(h.hash);let l=await e.listObjectHashes(t),u=[];for(let h of l)c.has(h)||u.push(h);let d=await qr(r);return fs(i,d)?a||u.length===0?{deleted:u.length,retained:c.size}:{deleted:await e.deleteObjects(t,u),retained:c.size}:{deleted:0,retained:c.size,aborted:!0}}async function qr(r){return r.refStore.listRefs()}function cs(r){let e=new Set;for(let t of r)e.add(t.hash);return Array.from(e)}function fs(r,e){if(r.length!==e.length)return!1;let t=new Map;for(let n of r)t.set(n.name,n.hash);for(let n of e)if(t.get(n.name)!==n.hash)return!1;return!0}var Le=class{repos=new Set;objects=new Map;refs=new Map;forks=new Map;hasRepo(e){return this.repos.has(e)}insertRepo(e){this.repos.add(e)}deleteRepo(e){this.repos.delete(e),this.objects.get(e)?.clear(),this.objects.delete(e),this.refs.get(e)?.clear(),this.refs.delete(e),this.forks.delete(e)}getObject(e,t){let n=this.getObjMap(e).get(t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}getObjects(e,t){let n=this.getObjMap(e),s=new Map;for(let a of new Set(t)){let i=n.get(a);i&&s.set(a,{type:i.type,content:new Uint8Array(i.content)})}return s}putObject(e,t,n,s){let a=this.getObjMap(e);a.has(t)||a.set(t,{type:n,content:new Uint8Array(s)})}putObjects(e,t){let n=this.getObjMap(e),s=[];for(let a of t)n.has(a.hash)||(n.set(a.hash,{type:a.type,content:new Uint8Array(a.content)}),s.push(a.hash));return s}hasObject(e,t){return this.getObjMap(e).has(t)}hasObjects(e,t){let n=this.getObjMap(e),s=new Set;for(let a of new Set(t))n.has(a)&&s.add(a);return s}findObjectsByPrefix(e,t){let n=[];for(let s of this.getObjMap(e).keys())s.startsWith(t)&&n.push(s);return n}listObjectHashes(e){return Array.from(this.getObjMap(e).keys())}deleteObjects(e,t){let n=this.getObjMap(e),s=0;for(let a of t)n.delete(a)&&s++;return s}getRef(e,t){return this.getRefMap(e).get(t)??null}putRef(e,t,n){this.getRefMap(e).set(t,n)}removeRef(e,t){this.getRefMap(e).delete(t)}listRefs(e,t){let n=[];for(let[s,a]of this.getRefMap(e))t&&!s.startsWith(t)||n.push({name:s,ref:a});return n}atomicRefUpdate(e,t){let n=this.getRefMap(e);return t({getRef:s=>n.get(s)??null,putRef:(s,a)=>{n.set(s,a)},removeRef:s=>{n.delete(s)}})}forkRepo(e,t){this.forks.set(t,e)}getForkParent(e){return this.forks.get(e)??null}listForks(e){let t=[];for(let[n,s]of this.forks)s===e&&t.push(n);return t}repoIds(){return Array.from(this.repos)}getObjMap(e){let t=this.objects.get(e);return t||(t=new Map,this.objects.set(e,t)),t}getRefMap(e){let t=this.refs.get(e);return t||(t=new Map,this.refs.set(e,t)),t}};var zr=new WeakMap,ls={http:r=>({transport:"http",request:r}),ssh:r=>({transport:"ssh",username:r.username})};function Xr(r){if(r.length===0)return!1;for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);if(n===0||n<32||n===127||n===92)return!1}let e=r.split("/");for(let t of e)if(t.length===0||t.charCodeAt(0)===46)return!1;return!0}function us(r={}){let e=r.storage??new Le,t=Tr(e),n=r.resolve??(y=>y),s=r.autoCreate,{basePath:a}=r,i={maxRequestBytes:128*1024*1024,maxInflatedBytes:256*1024*1024,maxPackBytes:128*1024*1024,maxPackObjects:25e4,...r.receiveLimits},o={maxRequestBytes:10*1024*1024,maxInflatedBytes:20*1024*1024,...r.fetchLimits};async function f(y){if(!Xr(y))return null;let b=await n(y);if(b==null||b!==y&&!Xr(b))return null;let m=await t.repo(b);if(m)return{repo:m,repoId:b};if(!s)return null;let R=typeof s=="object"?{defaultBranch:s.defaultBranch}:void 0;return{repo:await t.createRepo(b,R),repoId:b}}let c=ps(r.policy,r.hooks),l=r.auth??ls,u=r.packCache===!1?void 0:new le(r.packCache?.maxBytes),d=r.onError===!1?void 0:r.onError??(y=>{let b=y instanceof Error?y.message:String(y);console.error(`[server] Internal error: ${b}`)}),p=!1,h=0,g=null,w=null;function A(){return p?!1:(h++,!0)}function O(){h--,p&&h===0&&g?.()}let x={async fetch(y){if(!A())return new Response("Service Unavailable",{status:503});let b;try{let m=zr.get(y);if(m!==void 0)b=m;else{if(!l.http)return new Response("HTTP auth provider not configured",{status:501});let k=await l.http(y);if(k instanceof Response)return k;b=k}let R=new URL(y.url),S=decodeURIComponent(R.pathname);if(a){let k=a.replace(/\/+$/,"");if(!S.startsWith(k))return new Response("Not Found",{status:404});S=S.slice(k.length)}if(S.startsWith("/")||(S=`/${S}`),S.endsWith("/info/refs")&&y.method==="GET"){let k=R.searchParams.get("service");if(k!=="git-upload-pack"&&k!=="git-receive-pack")return new Response("Unsupported service",{status:403});let j=St(S,"/info/refs"),v=await f(j);if(!v)return new Response("Not Found",{status:404});if(Kr(y)&&k==="git-upload-pack"){let W=await $(v.repo,v.repoId,k,c,b);if(U(W))return Z(W);let I=Pe();return new Response(I,{headers:{"Content-Type":`application/x-${k}-advertisement`,"Cache-Control":"no-cache"}})}let H=await $(v.repo,v.repoId,k,c,b);if(U(H))return Z(H);let D=Et(H.refs,k,H.headTarget);return new Response(D,{headers:{"Content-Type":`application/x-${k}-advertisement`,"Cache-Control":"no-cache"}})}if(S.endsWith("/git-upload-pack")&&y.method==="POST"){let k=St(S,"/git-upload-pack"),j=await f(k);if(!j)return new Response("Not Found",{status:404});let v;if(c?.advertiseRefs){let D=await $(j.repo,j.repoId,"git-upload-pack",c,b);if(U(D))return Z(D);v=ke(D)}let P=await Yr(y,o);if(Kr(y)){let D=mt(P),W="application/x-git-upload-pack-result";if(D.command==="ls-refs"){let I=await ve(j.repo,j.repoId,D.args,c,b);return U(I)?Z(I):new Response(I,{headers:{"Content-Type":W}})}if(D.command==="fetch"){let I=await Ie(j.repo,D.args,{cache:u,cacheKey:j.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow,authorizedFetchSet:v});return U(I)?Z(I):new Response(I,{headers:{"Content-Type":W}})}return new Response(`unknown command: ${D.command}`,{status:400})}let H=await Se(j.repo,P,{cache:u,cacheKey:j.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow,authorizedFetchSet:v});return U(H)?Z(H):new Response(H,{headers:{"Content-Type":"application/x-git-upload-pack-result"}})}if(S.endsWith("/git-receive-pack")&&y.method==="POST"){let k=St(S,"/git-receive-pack"),j=await f(k);if(!j)return new Response("Not Found",{status:404});if(c?.advertiseRefs){let I=await $(j.repo,j.repoId,"git-receive-pack",c,b);if(U(I))return Z(I)}let v=await Yr(y,i),P=await At(j.repo,v,i);if(!P.sawFlush&&P.updates.length===0)return new Response("Bad Request",{status:400});let H=P.capabilities.includes("side-band-64k"),D=P.capabilities.includes("report-status");if(!P.unpackOk){if(D){let I=P.updates.map(V=>({name:V.ref,ok:!1,error:"unpack failed"}));return new Response(ce(!1,I,H),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}return new Response(new Uint8Array(0),{headers:{"Content-Type":"application/x-git-receive-pack-result"}})}let{refResults:W}=await je({repo:j.repo,repoId:j.repoId,ingestResult:P,hooks:c,auth:b});if(D){let I=W.map(V=>({name:V.ref,ok:V.ok,error:V.error}));return new Response(ce(!0,I,H),{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(m){return m instanceof M?new Response(m.message,{status:m.status}):(d?.(m,b),new Response("Internal Server Error",{status:500}))}finally{O()}},async handleSession(y,b,m){if(!A())return b.writeStderr?.(new TextEncoder().encode(`fatal: server shutting down
|
|
65
65
|
`)),128;try{if(!l.ssh)return b.writeStderr?.(new TextEncoder().encode(`fatal: SSH auth provider not configured
|
|
66
|
-
`)),128;let R=await l.ssh(
|
|
66
|
+
`)),128;let R=await l.ssh(m??{});return await Wr(y,b,{resolveRepo:f,hooks:c,packCache:u,packOptions:r.packOptions,receiveLimits:i,fetchLimits:o,auth:R,onError:d?S=>d(S,R):void 0})}finally{O()}},async updateRefs(y,b){if(!A())throw new Error("Server is shutting down");try{let m=await x.requireRepo(y),R=await Ke(m,b);return Xe(m,R)}finally{O()}},async commit(y,b){if(!A())throw new Error("Server is shutting down");try{let m=await x.requireRepo(y),R=await hr(m,b),S=`refs/heads/${b.branch}`,k=await Ke(m,[{ref:S,newHash:R.hash,oldHash:R.parentHash}]),v=(await Xe(m,k)).refResults[0];if(!v?.ok)throw new Error(v?.error??"ref update failed");return R}finally{O()}},nodeHandler(y,b){let m=[],R=0,S=!1,v=new URL(y.url??"/","http://localhost").pathname.endsWith("/git-upload-pack")?o.maxRequestBytes:i.maxRequestBytes;y.on("data",P=>{if(!S){if(R+=P.byteLength,y.method!=="GET"&&y.method!=="HEAD"&&v!==void 0&&R>v){S=!0,m.length=0,b.writeHead(413),b.end("Request body too large");try{y.destroy?.()}catch{}return}m.push(new Uint8Array(P))}}),y.on("error",()=>{b.writeHead(500),b.end("Internal Server Error")}),y.on("end",()=>{S||ds(x,y,m,b).catch(()=>{try{b.writeHead(500),b.end("Internal Server Error")}catch{}})})},createRepo:(y,b)=>t.createRepo(y,b),repo:y=>t.repo(y),async requireRepo(y){let b=await t.repo(y);if(!b)throw new Error(`Repository "${y}" not found`);return b},deleteRepo:y=>t.deleteRepo(y),async forkRepo(y,b,m){if(!A())throw new Error("Server is shutting down");try{return await t.forkRepo(y,b,m)}finally{O()}},async gc(y,b){if(!A())throw new Error("Server is shutting down");try{let m=await x.requireRepo(y),R;if(e.listForks&&e.getForkParent&&!await e.getForkParent(y)){let k=await e.listForks(y);if(k.length>0){R=[];for(let j of k){let v=await t.repo(j);if(!v)continue;let P=await v.refStore.listRefs();for(let H of P)R.push(H.hash)}}}return Vr(m,e,y,b,R)}finally{O()}},get closed(){return p},asNetwork(y="http://git",b){return{allowed:[y.endsWith("/")?y:`${y}/`],fetch:(R,S)=>{let k=new Request(R,S);return b!==void 0&&zr.set(k,b),x.fetch(k)}}},async close(y){if(p)return w??Promise.resolve();if(p=!0,u?.clear(),h!==0){if(w=new Promise(b=>{g=b}),y?.signal){if(y.signal.aborted){g();return}let b=()=>g?.();y.signal.addEventListener("abort",b,{once:!0}),w.then(()=>y.signal.removeEventListener("abort",b))}return w}}};return x}function Z(r){return new Response(r.message??"Forbidden",{status:403})}function Kr(r){let e=r.headers.get("git-protocol");return e!==null&&e.includes("version=2")}function St(r,e){let t=r.slice(0,-e.length);return t.startsWith("/")&&(t=t.slice(1)),t}async function Yr(r,e){let t=r.headers.get("content-length");if(t){let a=Number(t);if(Number.isFinite(a)&&e.maxRequestBytes!==void 0&&a>e.maxRequestBytes)throw new M("Request body too large")}let n=await Zr(r.body,e.maxRequestBytes,"Request body too large"),s=r.headers.get("content-encoding");if(s==="gzip"||s==="x-gzip"){let a=new DecompressionStream("gzip"),i=a.writable.getWriter(),o=new Uint8Array(n.byteLength);return o.set(n),await i.write(o),await i.close(),Zr(a.readable,e.maxInflatedBytes,"Decompressed body too large")}return n}async function Zr(r,e,t){if(!r)return new Uint8Array(0);let n=r.getReader(),s=[],a=0;try{for(;;){let{value:f,done:c}=await n.read();if(c)break;if(f){if(a+=f.byteLength,e!==void 0&&a>e)throw new M(t);s.push(f)}}}finally{n.releaseLock()}if(s.length===0)return new Uint8Array(0);let i=new Uint8Array(a),o=0;for(let f of s)i.set(f,o),o+=f.byteLength;return i}async function ds(r,e,t,n){let s=typeof e.headers.host=="string"?e.headers.host:"localhost",a=new URL(e.url??"/",`http://${s}`),i=new Headers;for(let[p,h]of Object.entries(e.headers))if(h!==void 0)if(Array.isArray(h))for(let g of h)i.append(p,g);else i.set(p,h);let o=e.method??"GET",f;if(o!=="GET"&&o!=="HEAD"){let p=0;for(let w of t)p+=w.byteLength;let h=new Uint8Array(p),g=0;for(let w of t)h.set(w,g),g+=w.byteLength;f=h}let c=new Request(a.href,{method:o,headers:i,body:f}),l=await r.fetch(c),u={};l.headers.forEach((p,h)=>{u[h]=p}),n.writeHead(l.status,u);let d=new Uint8Array(await l.arrayBuffer());d.byteLength>0&&n.write(d),n.end()}function hs(r){let{protectedBranches:e=[],denyNonFastForward:t=!1,denyDeletes:n=!1,immutableTags:s=!1}=r,a=new Set(e.map(o=>o.startsWith("refs/")?o:`refs/heads/${o}`)),i={};return a.size>0&&(i.preReceive=async o=>{for(let f of o.updates)if(a.has(f.ref)){if(f.isDelete)return{reject:!0,message:`cannot delete protected branch ${f.ref}`};if(!f.isCreate&&!f.isFF)return{reject:!0,message:`non-fast-forward push to protected branch ${f.ref}`}}}),(t||n||s)&&(i.update=async o=>{if(n&&o.update.isDelete)return{reject:!0,message:"ref deletion denied"};if(s&&o.update.ref.startsWith("refs/tags/")){if(o.update.isDelete)return{reject:!0,message:"tag deletion denied"};if(!o.update.isCreate)return{reject:!0,message:"tag overwrite denied"}}if(t&&!o.update.isCreate&&!o.update.isDelete&&!o.update.isFF)return{reject:!0,message:"non-fast-forward"}}),i}function ps(r,e){let t=r?hs(r):void 0;return t&&e?Jr(t,e):t??e}function Jr(...r){let e=r.filter(o=>o!=null);if(e.length===0)return{};if(e.length===1)return e[0];let t={},n=e.filter(o=>o.preReceive).map(o=>o.preReceive);n.length>0&&(t.preReceive=async o=>{for(let f of n){let c=await f(o);if(U(c))return c}});let s=e.filter(o=>o.update).map(o=>o.update);s.length>0&&(t.update=async o=>{for(let f of s){let c=await f(o);if(U(c))return c}});let a=e.filter(o=>o.postReceive).map(o=>o.postReceive);a.length>0&&(t.postReceive=async o=>{for(let f of a)try{await f(o)}catch{}});let i=e.filter(o=>o.advertiseRefs).map(o=>o.advertiseRefs);return i.length>0&&(t.advertiseRefs=async o=>{let f=o.refs;for(let c of i){let l=await c({...o,refs:f});if(U(l))return l;l&&(f=l)}return f}),t}var ys=`
|
|
67
67
|
CREATE TABLE IF NOT EXISTS git_repos (
|
|
68
68
|
id TEXT PRIMARY KEY
|
|
69
69
|
);
|
|
@@ -89,7 +89,7 @@ CREATE TABLE IF NOT EXISTS git_forks (
|
|
|
89
89
|
repo_id TEXT PRIMARY KEY,
|
|
90
90
|
parent_id TEXT NOT NULL
|
|
91
91
|
);
|
|
92
|
-
`;function
|
|
92
|
+
`;function ms(r){return{repoInsert:r.prepare("INSERT INTO git_repos (id) VALUES (?)"),repoExists:r.prepare("SELECT 1 FROM git_repos WHERE id = ? LIMIT 1"),repoDelete:r.prepare("DELETE FROM git_repos WHERE id = ?"),objInsert:r.prepare("INSERT OR IGNORE INTO git_objects (repo_id, hash, type, content) VALUES (?, ?, ?, ?) RETURNING hash"),objRead:r.prepare("SELECT type, content FROM git_objects WHERE repo_id = ? AND hash = ?"),objExists:r.prepare("SELECT 1 FROM git_objects WHERE repo_id = ? AND hash = ? LIMIT 1"),objPrefix:r.prepare("SELECT hash FROM git_objects WHERE repo_id = ? AND hash GLOB ?"),objDeleteAll:r.prepare("DELETE FROM git_objects WHERE repo_id = ?"),objListHashes:r.prepare("SELECT hash FROM git_objects WHERE repo_id = ?"),objDelete:r.prepare("DELETE FROM git_objects WHERE repo_id = ? AND hash = ?"),refRead:r.prepare("SELECT type, hash, target FROM git_refs WHERE repo_id = ? AND name = ?"),refWrite:r.prepare("INSERT OR REPLACE INTO git_refs (repo_id, name, type, hash, target) VALUES (?, ?, ?, ?, ?)"),refDelete:r.prepare("DELETE FROM git_refs WHERE repo_id = ? AND name = ?"),refList:r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ? AND name GLOB ?"),refListAll:r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ?"),refDeleteAll:r.prepare("DELETE FROM git_refs WHERE repo_id = ?"),forkInsert:r.prepare("INSERT INTO git_forks (repo_id, parent_id) VALUES (?, ?)"),forkGetParent:r.prepare("SELECT parent_id FROM git_forks WHERE repo_id = ?"),forkListChildren:r.prepare("SELECT repo_id FROM git_forks WHERE parent_id = ?"),forkDelete:r.prepare("DELETE FROM git_forks WHERE repo_id = ?")}}var Pt=class{constructor(e){this.db=e;e.run(ys),this.stmts=ms(e),this.batchInsertTx=e.transaction(t=>{let n=[];for(let s of t){let a=this.stmts.objInsert.get(s.repoId,s.hash,s.type,s.content);a&&n.push(a.hash)}return n}),this.batchDeleteTx=e.transaction((t,n,s)=>{let a=0;for(let i of n)this.stmts.objDelete.run(t,i),a++;s(a)})}stmts;objectReadManyStatements=new Map;objectExistsManyStatements=new Map;batchInsertTx;batchDeleteTx;hasRepo(e){return this.stmts.repoExists.get(e)!==null}insertRepo(e){this.stmts.repoInsert.run(e)}deleteRepo(e){this.stmts.repoDelete.run(e),this.stmts.objDeleteAll.run(e),this.stmts.refDeleteAll.run(e),this.stmts.forkDelete.run(e)}getObject(e,t){let n=this.stmts.objRead.get(e,t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}getObjects(e,t){let n=Array.from(new Set(t));if(n.length===0)return new Map;if(n.length===1){let o=this.getObject(e,n[0]);return o?new Map([[n[0],o]]):new Map}let a=this.getObjectReadManyStatement(n.length).all(e,...n),i=new Map;for(let o of a)i.set(o.hash,{type:o.type,content:new Uint8Array(o.content)});return i}putObject(e,t,n,s){this.stmts.objInsert.run(e,t,n,s)}putObjects(e,t){return this.batchInsertTx(t.map(n=>({repoId:e,...n})))}hasObject(e,t){return this.stmts.objExists.get(e,t)!==null}hasObjects(e,t){let n=Array.from(new Set(t));if(n.length===0)return new Set;if(n.length===1)return this.hasObject(e,n[0])?new Set(n):new Set;let a=this.getObjectExistsManyStatement(n.length).all(e,...n);return new Set(a.map(i=>i.hash))}findObjectsByPrefix(e,t){return this.stmts.objPrefix.all(e,`${t}*`).map(s=>s.hash)}listObjectHashes(e){return this.stmts.objListHashes.all(e).map(n=>n.hash)}deleteObjects(e,t){if(t.length===0)return 0;let n=Array.from(new Set(t)),s=this.hasObjects(e,n);if(s.size===0)return 0;let a=0;return this.batchDeleteTx(e,Array.from(s),i=>{a+=i}),a}getObjectReadManyStatement(e){return this.getCachedStatement(this.objectReadManyStatements,e,`SELECT hash, type, content FROM git_objects WHERE repo_id = ? AND hash IN (${Qr(e)})`)}getObjectExistsManyStatement(e){return this.getCachedStatement(this.objectExistsManyStatements,e,`SELECT hash FROM git_objects WHERE repo_id = ? AND hash IN (${Qr(e)})`)}getCachedStatement(e,t,n){let s=e.get(t);return s||(s=this.db.prepare(n),e.set(t,s)),s}getRef(e,t){let n=this.stmts.refRead.get(e,t);return jt(n)}putRef(e,t,n){n.type==="symbolic"?this.stmts.refWrite.run(e,t,"symbolic",null,n.target):this.stmts.refWrite.run(e,t,"direct",n.hash,null)}removeRef(e,t){this.stmts.refDelete.run(e,t)}listRefs(e,t){return(t?this.stmts.refList.all(e,`${t}*`):this.stmts.refListAll.all(e)).flatMap(s=>{let a=jt(s);return a?[{name:s.name,ref:a}]:[]})}atomicRefUpdate(e,t){let n=this.stmts;return this.db.transaction(()=>t({getRef:a=>jt(n.refRead.get(e,a)),putRef:(a,i)=>{i.type==="symbolic"?n.refWrite.run(e,a,"symbolic",null,i.target):n.refWrite.run(e,a,"direct",i.hash,null)},removeRef:a=>{n.refDelete.run(e,a)}}))()}forkRepo(e,t){this.stmts.forkInsert.run(t,e)}getForkParent(e){return this.stmts.forkGetParent.get(e)?.parent_id??null}listForks(e){return this.stmts.forkListChildren.all(e).map(n=>n.repo_id)}};function jt(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}function Qr(r){return Array(r).fill("?").join(", ")}var bs=`
|
|
93
93
|
CREATE TABLE IF NOT EXISTS git_repos (
|
|
94
94
|
id TEXT PRIMARY KEY
|
|
95
95
|
);
|
|
@@ -115,7 +115,7 @@ CREATE TABLE IF NOT EXISTS git_forks (
|
|
|
115
115
|
repo_id TEXT PRIMARY KEY,
|
|
116
116
|
parent_id TEXT NOT NULL
|
|
117
117
|
);
|
|
118
|
-
`;function
|
|
118
|
+
`;function C(r){return{run:(...e)=>{r.run(...e)},get:(...e)=>r.get(...e)??null,all:(...e)=>r.all(...e)}}function gs(r){return{repoInsert:C(r.prepare("INSERT INTO git_repos (id) VALUES (?)")),repoExists:C(r.prepare("SELECT 1 FROM git_repos WHERE id = ? LIMIT 1")),repoDelete:C(r.prepare("DELETE FROM git_repos WHERE id = ?")),objInsert:C(r.prepare("INSERT OR IGNORE INTO git_objects (repo_id, hash, type, content) VALUES (?, ?, ?, ?)")),objInsertReturning:C(r.prepare("INSERT OR IGNORE INTO git_objects (repo_id, hash, type, content) VALUES (?, ?, ?, ?) RETURNING hash")),objRead:C(r.prepare("SELECT type, content FROM git_objects WHERE repo_id = ? AND hash = ?")),objExists:C(r.prepare("SELECT 1 FROM git_objects WHERE repo_id = ? AND hash = ? LIMIT 1")),objPrefix:C(r.prepare("SELECT hash FROM git_objects WHERE repo_id = ? AND hash GLOB ?")),objDeleteAll:C(r.prepare("DELETE FROM git_objects WHERE repo_id = ?")),objListHashes:C(r.prepare("SELECT hash FROM git_objects WHERE repo_id = ?")),objDelete:C(r.prepare("DELETE FROM git_objects WHERE repo_id = ? AND hash = ?")),refRead:C(r.prepare("SELECT type, hash, target FROM git_refs WHERE repo_id = ? AND name = ?")),refWrite:C(r.prepare("INSERT OR REPLACE INTO git_refs (repo_id, name, type, hash, target) VALUES (?, ?, ?, ?, ?)")),refDelete:C(r.prepare("DELETE FROM git_refs WHERE repo_id = ? AND name = ?")),refList:C(r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ? AND name GLOB ?")),refListAll:C(r.prepare("SELECT name, type, hash, target FROM git_refs WHERE repo_id = ?")),refDeleteAll:C(r.prepare("DELETE FROM git_refs WHERE repo_id = ?")),forkInsert:C(r.prepare("INSERT INTO git_forks (repo_id, parent_id) VALUES (?, ?)")),forkGetParent:C(r.prepare("SELECT parent_id FROM git_forks WHERE repo_id = ?")),forkListChildren:C(r.prepare("SELECT repo_id FROM git_forks WHERE parent_id = ?")),forkDelete:C(r.prepare("DELETE FROM git_forks WHERE repo_id = ?"))}}var It=class{constructor(e){this.db=e;e.exec(bs),this.stmts=gs(e),this.batchInsertTx=e.transaction(t=>{let n=[];for(let s of t){let a=this.stmts.objInsertReturning.get(s.repoId,s.hash,s.type,s.content);a&&n.push(a.hash)}return n}),this.batchDeleteTx=e.transaction((t,n,s)=>{let a=0;for(let i of n)this.stmts.objDelete.run(t,i),a++;s(a)})}stmts;objectReadManyStatements=new Map;objectExistsManyStatements=new Map;batchInsertTx;batchDeleteTx;hasRepo(e){return this.stmts.repoExists.get(e)!==null}insertRepo(e){this.stmts.repoInsert.run(e)}deleteRepo(e){this.stmts.repoDelete.run(e),this.stmts.objDeleteAll.run(e),this.stmts.refDeleteAll.run(e),this.stmts.forkDelete.run(e)}getObject(e,t){let n=this.stmts.objRead.get(e,t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}getObjects(e,t){let n=Array.from(new Set(t));if(n.length===0)return new Map;if(n.length===1){let o=this.getObject(e,n[0]);return o?new Map([[n[0],o]]):new Map}let a=this.getObjectReadManyStatement(n.length).all(e,...n),i=new Map;for(let o of a)i.set(o.hash,{type:o.type,content:new Uint8Array(o.content)});return i}putObject(e,t,n,s){this.stmts.objInsert.run(e,t,n,s)}putObjects(e,t){return this.batchInsertTx(t.map(n=>({repoId:e,...n})))}hasObject(e,t){return this.stmts.objExists.get(e,t)!==null}hasObjects(e,t){let n=Array.from(new Set(t));if(n.length===0)return new Set;if(n.length===1)return this.hasObject(e,n[0])?new Set(n):new Set;let a=this.getObjectExistsManyStatement(n.length).all(e,...n);return new Set(a.map(i=>i.hash))}findObjectsByPrefix(e,t){return this.stmts.objPrefix.all(e,`${t}*`).map(s=>s.hash)}listObjectHashes(e){return this.stmts.objListHashes.all(e).map(n=>n.hash)}deleteObjects(e,t){if(t.length===0)return 0;let n=Array.from(new Set(t)),s=this.hasObjects(e,n);if(s.size===0)return 0;let a=0;return this.batchDeleteTx(e,Array.from(s),i=>{a+=i}),a}getObjectReadManyStatement(e){return this.getCachedStatement(this.objectReadManyStatements,e,`SELECT hash, type, content FROM git_objects WHERE repo_id = ? AND hash IN (${en(e)})`)}getObjectExistsManyStatement(e){return this.getCachedStatement(this.objectExistsManyStatements,e,`SELECT hash FROM git_objects WHERE repo_id = ? AND hash IN (${en(e)})`)}getCachedStatement(e,t,n){let s=e.get(t);return s||(s=C(this.db.prepare(n)),e.set(t,s)),s}getRef(e,t){let n=this.stmts.refRead.get(e,t);return vt(n)}putRef(e,t,n){n.type==="symbolic"?this.stmts.refWrite.run(e,t,"symbolic",null,n.target):this.stmts.refWrite.run(e,t,"direct",n.hash,null)}removeRef(e,t){this.stmts.refDelete.run(e,t)}listRefs(e,t){return(t?this.stmts.refList.all(e,`${t}*`):this.stmts.refListAll.all(e)).flatMap(s=>{let a=vt(s);return a?[{name:s.name,ref:a}]:[]})}atomicRefUpdate(e,t){let n=this.stmts;return this.db.transaction(()=>t({getRef:a=>vt(n.refRead.get(e,a)),putRef:(a,i)=>{i.type==="symbolic"?n.refWrite.run(e,a,"symbolic",null,i.target):n.refWrite.run(e,a,"direct",i.hash,null)},removeRef:a=>{n.refDelete.run(e,a)}}))()}forkRepo(e,t){this.stmts.forkInsert.run(t,e)}getForkParent(e){return this.stmts.forkGetParent.get(e)?.parent_id??null}listForks(e){return this.stmts.forkListChildren.all(e).map(n=>n.repo_id)}};function vt(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}function en(r){return Array(r).fill("?").join(", ")}var ws=`
|
|
119
119
|
CREATE TABLE IF NOT EXISTS git_repos (
|
|
120
120
|
id TEXT PRIMARY KEY
|
|
121
121
|
);
|
|
@@ -141,8 +141,8 @@ CREATE TABLE IF NOT EXISTS git_forks (
|
|
|
141
141
|
repo_id TEXT PRIMARY KEY,
|
|
142
142
|
parent_id TEXT NOT NULL
|
|
143
143
|
);
|
|
144
|
-
`,
|
|
145
|
-
ON CONFLICT (repo_id, name) DO UPDATE SET type = EXCLUDED.type, hash = EXCLUDED.hash, target = EXCLUDED.target`,refDelete:"DELETE FROM git_refs WHERE repo_id = $1 AND name = $2",refList:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = $1 AND name LIKE $2",refListAll:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = $1",refDeleteAll:"DELETE FROM git_refs WHERE repo_id = $1",forkInsert:"INSERT INTO git_forks (repo_id, parent_id) VALUES ($1, $2)",forkGetParent:"SELECT parent_id FROM git_forks WHERE repo_id = $1",forkListChildren:"SELECT repo_id FROM git_forks WHERE parent_id = $1",forkDelete:"DELETE FROM git_forks WHERE repo_id = $1"},
|
|
144
|
+
`,T={repoInsert:"INSERT INTO git_repos (id) VALUES ($1)",repoExists:"SELECT 1 FROM git_repos WHERE id = $1 LIMIT 1",repoDelete:"DELETE FROM git_repos WHERE id = $1",objInsert:"INSERT INTO git_objects (repo_id, hash, type, content) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING RETURNING hash",objRead:"SELECT type, content FROM git_objects WHERE repo_id = $1 AND hash = $2",objReadMany:"SELECT hash, type, content FROM git_objects WHERE repo_id = $1 AND hash = ANY($2::text[])",objExists:"SELECT 1 FROM git_objects WHERE repo_id = $1 AND hash = $2 LIMIT 1",objExistsMany:"SELECT hash FROM git_objects WHERE repo_id = $1 AND hash = ANY($2::text[])",objPrefix:"SELECT hash FROM git_objects WHERE repo_id = $1 AND hash LIKE $2",objDeleteAll:"DELETE FROM git_objects WHERE repo_id = $1",objListHashes:"SELECT hash FROM git_objects WHERE repo_id = $1",refRead:"SELECT type, hash, target FROM git_refs WHERE repo_id = $1 AND name = $2",refReadForUpdate:"SELECT type, hash, target FROM git_refs WHERE repo_id = $1 AND name = $2 FOR UPDATE",refWrite:`INSERT INTO git_refs (repo_id, name, type, hash, target) VALUES ($1, $2, $3, $4, $5)
|
|
145
|
+
ON CONFLICT (repo_id, name) DO UPDATE SET type = EXCLUDED.type, hash = EXCLUDED.hash, target = EXCLUDED.target`,refDelete:"DELETE FROM git_refs WHERE repo_id = $1 AND name = $2",refList:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = $1 AND name LIKE $2",refListAll:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = $1",refDeleteAll:"DELETE FROM git_refs WHERE repo_id = $1",forkInsert:"INSERT INTO git_forks (repo_id, parent_id) VALUES ($1, $2)",forkGetParent:"SELECT parent_id FROM git_forks WHERE repo_id = $1",forkListChildren:"SELECT repo_id FROM git_forks WHERE parent_id = $1",forkDelete:"DELETE FROM git_forks WHERE repo_id = $1"},Rs=256,Lt=class r{constructor(e){this.pool=e}static async create(e){return await e.query(ws),new r(e)}async transaction(e){let t=await this.pool.connect();try{await t.query("BEGIN");let n=await e((s,a)=>t.query(s,a));return await t.query("COMMIT"),n}catch(n){throw await t.query("ROLLBACK"),n}finally{t.release()}}async hasRepo(e){let{rows:t}=await this.pool.query(T.repoExists,[e]);return t.length>0}async insertRepo(e){await this.pool.query(T.repoInsert,[e])}async deleteRepo(e){await this.pool.query(T.repoDelete,[e]),await this.pool.query(T.objDeleteAll,[e]),await this.pool.query(T.refDeleteAll,[e]),await this.pool.query(T.forkDelete,[e])}async getObject(e,t){let{rows:n}=await this.pool.query(T.objRead,[e,t]),s=n[0];return s?{type:s.type,content:new Uint8Array(s.content)}:null}async getObjects(e,t){if(t.length===0)return new Map;let{rows:n}=await this.pool.query(T.objReadMany,[e,Array.from(new Set(t))]),s=new Map;for(let a of n)s.set(a.hash,{type:a.type,content:new Uint8Array(a.content)});return s}async putObject(e,t,n,s){await this.pool.query(T.objInsert,[e,t,n,s])}async putObjects(e,t){return t.length===0?[]:await this.transaction(async n=>{let s=[];for(let a of Es(t,Rs)){let{text:i,values:o}=xs(e,a),{rows:f}=await n(i,o);for(let c of f)s.push(c.hash)}return s})}async hasObject(e,t){let{rows:n}=await this.pool.query(T.objExists,[e,t]);return n.length>0}async hasObjects(e,t){if(t.length===0)return new Set;let{rows:n}=await this.pool.query(T.objExistsMany,[e,Array.from(new Set(t))]);return new Set(n.map(s=>s.hash))}async findObjectsByPrefix(e,t){let{rows:n}=await this.pool.query(T.objPrefix,[e,`${t}%`]);return n.map(s=>s.hash)}async listObjectHashes(e){let{rows:t}=await this.pool.query(T.objListHashes,[e]);return t.map(n=>n.hash)}async deleteObjects(e,t){if(t.length===0)return 0;let{rows:n}=await this.pool.query("DELETE FROM git_objects WHERE repo_id = $1 AND hash = ANY($2::text[]) RETURNING hash",[e,Array.from(t)]);return n.length}async getRef(e,t){let{rows:n}=await this.pool.query(T.refRead,[e,t]);return Tt(n[0]??null)}async putRef(e,t,n){n.type==="symbolic"?await this.pool.query(T.refWrite,[e,t,"symbolic",null,n.target]):await this.pool.query(T.refWrite,[e,t,"direct",n.hash,null])}async removeRef(e,t){await this.pool.query(T.refDelete,[e,t])}async listRefs(e,t){let n;return t?{rows:n}=await this.pool.query(T.refList,[e,`${t}%`]):{rows:n}=await this.pool.query(T.refListAll,[e]),n.flatMap(s=>{let a=Tt(s);return a?[{name:s.name,ref:a}]:[]})}async atomicRefUpdate(e,t){return this.transaction(async n=>t({getRef:async s=>{let{rows:a}=await n(T.refReadForUpdate,[e,s]);return Tt(a[0]??null)},putRef:async(s,a)=>{a.type==="symbolic"?await n(T.refWrite,[e,s,"symbolic",null,a.target]):await n(T.refWrite,[e,s,"direct",a.hash,null])},removeRef:async s=>{await n(T.refDelete,[e,s])}}))}async forkRepo(e,t){await this.pool.query(T.forkInsert,[t,e])}async getForkParent(e){let{rows:t}=await this.pool.query(T.forkGetParent,[e]);return t[0]?.parent_id??null}async listForks(e){let{rows:t}=await this.pool.query(T.forkListChildren,[e]);return t.map(n=>n.repo_id)}};function Tt(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}function xs(r,e){let t=[],n=[];for(let s=0;s<e.length;s++){let a=s*4,i=e[s];t.push(r,i.hash,i.type,i.content),n.push(`($${a+1}, $${a+2}, $${a+3}, $${a+4})`)}return{text:`INSERT INTO git_objects (repo_id, hash, type, content) VALUES ${n.join(", ")} ON CONFLICT DO NOTHING RETURNING hash`,values:t}}function Es(r,e){let t=[];for(let n=0;n<r.length;n+=e)t.push(r.slice(n,n+e));return t}var Os=`
|
|
146
146
|
CREATE TABLE IF NOT EXISTS git_repos (
|
|
147
147
|
id TEXT PRIMARY KEY
|
|
148
148
|
);
|
|
@@ -168,4 +168,4 @@ CREATE TABLE IF NOT EXISTS git_forks (
|
|
|
168
168
|
repo_id TEXT PRIMARY KEY,
|
|
169
169
|
parent_id TEXT NOT NULL
|
|
170
170
|
);
|
|
171
|
-
`,
|
|
171
|
+
`,L={repoInsert:"INSERT INTO git_repos (id) VALUES (?)",repoExists:"SELECT 1 FROM git_repos WHERE id = ? LIMIT 1",repoDelete:"DELETE FROM git_repos WHERE id = ?",objInsert:"INSERT OR IGNORE INTO git_objects (repo_id, hash, type, content) VALUES (?, ?, ?, ?) RETURNING hash",objRead:"SELECT type, content FROM git_objects WHERE repo_id = ? AND hash = ?",objExists:"SELECT 1 FROM git_objects WHERE repo_id = ? AND hash = ? LIMIT 1",objPrefix:"SELECT hash FROM git_objects WHERE repo_id = ? AND hash GLOB ?",objDeleteAll:"DELETE FROM git_objects WHERE repo_id = ?",objListHashes:"SELECT hash FROM git_objects WHERE repo_id = ?",objDelete:"DELETE FROM git_objects WHERE repo_id = ? AND hash = ?",refRead:"SELECT type, hash, target FROM git_refs WHERE repo_id = ? AND name = ?",refWrite:"INSERT OR REPLACE INTO git_refs (repo_id, name, type, hash, target) VALUES (?, ?, ?, ?, ?)",refDelete:"DELETE FROM git_refs WHERE repo_id = ? AND name = ?",refList:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = ? AND name GLOB ?",refListAll:"SELECT name, type, hash, target FROM git_refs WHERE repo_id = ?",refDeleteAll:"DELETE FROM git_refs WHERE repo_id = ?",forkInsert:"INSERT INTO git_forks (repo_id, parent_id) VALUES (?, ?)",forkGetParent:"SELECT parent_id FROM git_forks WHERE repo_id = ?",forkListChildren:"SELECT repo_id FROM git_forks WHERE parent_id = ?",forkDelete:"DELETE FROM git_forks WHERE repo_id = ?"};function J(r){let e=r.next();return e.done?null:e.value}var Ct=class{constructor(e){this.storage=e;this.sql=e.sql,this.sql.exec(Os)}sql;hasRepo(e){return J(this.sql.exec(L.repoExists,e))!==null}insertRepo(e){this.sql.exec(L.repoInsert,e)}deleteRepo(e){this.sql.exec(L.repoDelete,e),this.sql.exec(L.objDeleteAll,e),this.sql.exec(L.refDeleteAll,e),this.sql.exec(L.forkDelete,e)}getObject(e,t){let n=J(this.sql.exec(L.objRead,e,t));return n?{type:n.type,content:new Uint8Array(n.content)}:null}getObjects(e,t){let n=Array.from(new Set(t));if(n.length===0)return new Map;if(n.length===1){let i=this.getObject(e,n[0]);return i?new Map([[n[0],i]]):new Map}let s=this.sql.exec(`SELECT hash, type, content FROM git_objects WHERE repo_id = ? AND hash IN (${tn(n.length)})`,e,...n).toArray(),a=new Map;for(let i of s)a.set(i.hash,{type:i.type,content:new Uint8Array(i.content)});return a}putObject(e,t,n,s){this.sql.exec(L.objInsert,e,t,n,s)}putObjects(e,t){let n=[];return this.storage.transactionSync(()=>{for(let s of t){let a=J(this.sql.exec(L.objInsert,e,s.hash,s.type,s.content));a&&n.push(a.hash)}}),n}hasObject(e,t){return J(this.sql.exec(L.objExists,e,t))!==null}hasObjects(e,t){let n=Array.from(new Set(t));if(n.length===0)return new Set;if(n.length===1)return this.hasObject(e,n[0])?new Set(n):new Set;let s=this.sql.exec(`SELECT hash FROM git_objects WHERE repo_id = ? AND hash IN (${tn(n.length)})`,e,...n).toArray();return new Set(s.map(a=>a.hash))}findObjectsByPrefix(e,t){return this.sql.exec(L.objPrefix,e,`${t}*`).toArray().map(n=>n.hash)}listObjectHashes(e){return this.sql.exec(L.objListHashes,e).toArray().map(t=>t.hash)}deleteObjects(e,t){if(t.length===0)return 0;let n=Array.from(new Set(t)),s=this.hasObjects(e,n);if(s.size===0)return 0;let a=0;return this.storage.transactionSync(()=>{for(let i of s)this.sql.exec(L.objDelete,e,i),a++}),a}getRef(e,t){return Ut(J(this.sql.exec(L.refRead,e,t)))}putRef(e,t,n){n.type==="symbolic"?this.sql.exec(L.refWrite,e,t,"symbolic",null,n.target):this.sql.exec(L.refWrite,e,t,"direct",n.hash,null)}removeRef(e,t){this.sql.exec(L.refDelete,e,t)}listRefs(e,t){return(t?this.sql.exec(L.refList,e,`${t}*`).toArray():this.sql.exec(L.refListAll,e).toArray()).flatMap(s=>{let a=Ut(s);return a?[{name:s.name,ref:a}]:[]})}atomicRefUpdate(e,t){return this.storage.transactionSync(()=>t({getRef:n=>Ut(J(this.sql.exec(L.refRead,e,n))),putRef:(n,s)=>{s.type==="symbolic"?this.sql.exec(L.refWrite,e,n,"symbolic",null,s.target):this.sql.exec(L.refWrite,e,n,"direct",s.hash,null)},removeRef:n=>{this.sql.exec(L.refDelete,e,n)}}))}forkRepo(e,t){this.sql.exec(L.forkInsert,t,e)}getForkParent(e){return J(this.sql.exec(L.forkGetParent,e))?.parent_id??null}listForks(e){return this.sql.exec(L.forkListChildren,e).toArray().map(t=>t.repo_id)}};function Ut(r){return r?r.type==="symbolic"&&r.target?{type:"symbolic",target:r.target}:r.type==="direct"&&r.hash?{type:"direct",hash:r.hash}:null:null}function tn(r){return Array(r).fill("?").join(", ")}export{It as BetterSqlite3Storage,Pt as BunSqliteStorage,Ct as DurableObjectSqliteStorage,Le as MemoryStorage,Lt as PgStorage,$ as advertiseRefsWithHooks,Xe as applyCasRefUpdates,je as applyReceivePack,Et as buildRefAdvertisementBytes,Ot as buildRefListBytes,Ve as buildRefListPktLines,yt as buildV2CapabilityAdvertisement,Pe as buildV2CapabilityAdvertisementBytes,fe as buildV2FetchResponse,bt as buildV2LsRefsResponse,Hr as collectRefs,Jr as composeHooks,us as createServer,ve as handleLsRefs,Se as handleUploadPack,Ie as handleV2Fetch,At as ingestReceivePack,kt as ingestReceivePackFromStream,mt as parseV2CommandRequest,gt as parseV2FetchArgs,Ke as resolveRefUpdates};
|