just-git 0.1.0 → 0.1.1
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/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ Run
|
|
|
11
11
|
|
|
12
12
|
git config user.email "you@example.com"
|
|
13
13
|
git config user.name "Your Name"
|
|
14
|
-
`);return{name:s,email:a,timestamp:Zo(t.get(r.date)),timezone:"+0000"}}async function Ot(e,t){try{let n=await qn(e,t);return{name:n.name,email:n.email,timestamp:n.timestamp,tz:n.timezone}}catch{return{name:t.get("GIT_COMMITTER_NAME")??"",email:t.get("GIT_COMMITTER_EMAIL")??"",timestamp:Math.floor(Date.now()/1e3),tz:"+0000"}}}function Zo(e){if(e){let t=parseInt(e,10);if(!Number.isNaN(t))return t;let n=Date.parse(e);if(!Number.isNaN(n))return Math.floor(n/1e3)}return Math.floor(Date.now()/1e3)}var Z="0000000000000000000000000000000000000000",Qo=(()=>{let e=new Array(256);for(let t=0;t<256;t++)e[t]=(t>>4).toString(16)+(t&15).toString(16);return e})();function qt(e){let t="";for(let n=0;n<20;n++)t+=Qo[e[n]];return t}function Pr(e,t){let n="";for(let r=0;r<20;r++)n+=Qo[e[t+r]];return n}function ft(e){let t=new Uint8Array(20);for(let n=0;n<20;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}var lf=new TextEncoder;function Ds(e){return typeof e=="string"?lf.encode(e):e}function uf(){if(typeof globalThis.Bun<"u")return()=>{let e=new Bun.CryptoHasher("sha1"),t={update(n){return e.update(Ds(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t};try{let t=br("node:crypto");if(typeof t.createHash=="function")return()=>{let n=t.createHash("sha1"),r={update(o){return n.update(Ds(o)),r},hex:()=>Promise.resolve(n.digest("hex"))};return r}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let e=[],t={update(n){return e.push(Ds(n)),t},async hex(){let n=0;for(let a of e)n+=a.byteLength;let r=new Uint8Array(n),o=0;for(let a of e)r.set(a,o),o+=a.byteLength;let s=await crypto.subtle.digest("SHA-1",r);return qt(new Uint8Array(s))}};return t};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var ei=uf(),Kt=ei;async function On(e){return ei().update(e).hex()}var ti=1145655875,Ms=2;async function U(e){let t=v(e.gitDir,"index");if(!await e.fs.exists(t))return{version:Ms,entries:[]};let n=await e.fs.readFileBuffer(t);return mf(n)}async function re(e,t){let n=v(e.gitDir,"index"),r=await hf(t);await e.fs.writeFile(n,r)}function Xe(e,t){let n;return t.stage===0?n=e.entries.filter(r=>r.path!==t.path):n=e.entries.filter(r=>!(r.path===t.path&&r.stage===t.stage)),n.push(t),n.sort(js),{...e,entries:n}}function Ne(e,t){return{...e,entries:e.entries.filter(n=>n.path!==t)}}function Dt(e,t,n=0){return e.entries.find(r=>r.path===t&&r.stage===n)}function dt(e){return e.entries.some(t=>t.stage>0)}function Rt(e){return[...new Set(e.entries.filter(t=>t.stage>0).map(t=>t.path))]}function xe(e){return e.entries.filter(t=>t.stage===0)}function ni(){return{version:Ms,entries:[]}}function Or(e){let t=[...e].sort(js);return{version:Ms,entries:t}}function pe(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}function mf(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=0,r=t.getUint32(n);if(n+=4,r!==ti)throw new Error(`Invalid index signature: 0x${r.toString(16)}`);let o=t.getUint32(n);n+=4;let s=t.getUint32(n);n+=4;let a=[];for(let i=0;i<s;i++){let c=n,f={ctimeSeconds:t.getUint32(n),ctimeNanoseconds:t.getUint32(n+4),mtimeSeconds:t.getUint32(n+8),mtimeNanoseconds:t.getUint32(n+12),dev:t.getUint32(n+16),ino:t.getUint32(n+20),uid:t.getUint32(n+28),gid:t.getUint32(n+32),size:t.getUint32(n+36)},d=t.getUint32(n+24);n+=40;let u=e.subarray(n,n+20),l=qt(u);n+=20;let m=t.getUint16(n);n+=2;let h=m>>12&3,p=m&4095,g;if(p<4095)g=new TextDecoder().decode(e.subarray(n,n+p));else{let b=n;for(;b<e.byteLength&&e[b]!==0;)b++;g=new TextDecoder().decode(e.subarray(n,b))}let w=62+g.length+1,x=Math.ceil(w/8)*8;n=c+x,a.push({path:g,mode:d,hash:l,stage:h,stat:f})}return{version:o,entries:a}}async function hf(e){let t=[...e.entries].sort(js),n=12;for(let d of t){let u=62+d.path.length+1;n+=Math.ceil(u/8)*8}n+=20;let r=new ArrayBuffer(n),o=new Uint8Array(r),s=new DataView(r),a=0;s.setUint32(a,ti),a+=4,s.setUint32(a,e.version),a+=4,s.setUint32(a,t.length),a+=4;for(let d of t){let u=a;s.setUint32(a,d.stat.ctimeSeconds),s.setUint32(a+4,d.stat.ctimeNanoseconds),s.setUint32(a+8,d.stat.mtimeSeconds),s.setUint32(a+12,d.stat.mtimeNanoseconds),s.setUint32(a+16,d.stat.dev),s.setUint32(a+20,d.stat.ino),s.setUint32(a+24,d.mode),s.setUint32(a+28,d.stat.uid),s.setUint32(a+32,d.stat.gid),s.setUint32(a+36,d.stat.size),a+=40;let l=ft(d.hash);o.set(l,a),a+=20;let m=Math.min(d.path.length,4095),h=(d.stage&3)<<12|m;s.setUint16(a,h),a+=2;let p=new TextEncoder().encode(d.path);o.set(p,a),a+=p.byteLength,o[a]=0,a+=1;let g=62+p.byteLength+1,w=Math.ceil(g/8)*8;a=u+w}let i=o.subarray(0,a),c=await On(i),f=ft(c);return o.set(f,a),o}function js(e,t){return e.path<t.path?-1:e.path>t.path?1:e.stage-t.stage}var ri=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;ri[e]=t}function Ls(e){let t=4294967295;for(let n=0;n<e.byteLength;n++)t=ri[(t^e[n])&255]^t>>>8;return(t^4294967295)>>>0}function pf(){try{let t=br("node:zlib");if(typeof t.deflateSync=="function"&&typeof t.inflateSync=="function")return{deflate:n=>Promise.resolve(new Uint8Array(t.deflateSync(n))),inflate:n=>Promise.resolve(new Uint8Array(t.inflateSync(n)))}}catch{}if(typeof globalThis.CompressionStream=="function"&&typeof globalThis.DecompressionStream=="function")return{async deflate(e){let t=new CompressionStream("deflate"),n=t.writable.getWriter();return n.write(e),n.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())},async inflate(e){let t=new DecompressionStream("deflate"),n=t.writable.getWriter();return n.write(e),n.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())}};throw new Error("No zlib implementation available. Requires Bun, Node.js, Deno, or a browser with CompressionStream.")}var si=pf(),Rn=si.deflate,Mt=si.inflate;var Rr=1346454347,Ns=2,ai=1,ci=2,fi=3,di=4,Kn=6,_s=7,gf={[ai]:"commit",[ci]:"tree",[fi]:"blob",[di]:"tag"},li={commit:ai,tree:ci,blob:fi,tag:di};async function ui(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0);if(n!==Rr)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${Rr.toString(16)})`);let r=t.getUint32(4);if(r!==Ns)throw new Error(`Unsupported pack version: ${r}`);let o=t.getUint32(8),s=[],a=12;for(let c=0;c<o;c++){let f=await wf(e,a);s.push(f),a=f.nextOffset}return(await bf(s)).map((c,f)=>({...c,offset:s[f].headerOffset,nextOffset:s[f].nextOffset}))}async function wf(e,t){let n=t,r=e[t++],o=r>>4&7,s=r&15,a=4;for(;r&128;)r=e[t++],s|=(r&127)<<a,a+=7;let i,c;if(o===Kn){let u=e[t++];for(i=u&127;u&128;)i+=1,u=e[t++],i=(i<<7)+(u&127);i=n-i}else o===_s&&(c=Pr(e,t),t+=20);let{result:f,bytesConsumed:d}=await xf(e,t,s);return{headerOffset:n,typeNum:o,inflated:f,baseOffset:i,baseHash:c,nextOffset:t+d}}async function bf(e){let t=new Map;for(let o=0;o<e.length;o++)t.set(e[o].headerOffset,o);let n=new Array(e.length).fill(null);async function r(o){let s=n[o];if(s)return s;let a=e[o];if(a.typeNum!==Kn&&a.typeNum!==_s){let u=gf[a.typeNum];if(!u)throw new Error(`Unknown object type: ${a.typeNum}`);let l={type:u,content:a.inflated,hash:await ii(u,a.inflated)};return n[o]=l,l}let i;if(a.typeNum===Kn){if(i=t.get(a.baseOffset),i===void 0)throw new Error(`OFS_DELTA base not found at offset ${a.baseOffset}`)}else if(i=await yf(e,n,a.baseHash,r),i===void 0)throw new Error(`REF_DELTA base not found for hash ${a.baseHash}`);let c=await r(i),f=Ir(c.content,a.inflated),d={type:c.type,content:f,hash:await ii(c.type,f)};return n[o]=d,d}for(let o=0;o<e.length;o++)await r(o);return n}async function yf(e,t,n,r){for(let o=0;o<t.length;o++)if(t[o]?.hash===n)return o;for(let o=0;o<e.length;o++){let s=e[o];if(s.typeNum!==Kn&&s.typeNum!==_s&&(await r(o)).hash===n)return o}}function Ir(e,t){let n=0,{value:r,newPos:o}=oi(t,n);if(n=o,r!==e.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${e.byteLength}`);let{value:s,newPos:a}=oi(t,n);n=a;let i=new Uint8Array(s),c=0;for(;n<t.byteLength;){let f=t[n++];if(f&128){let d=0,u=0;f&1&&(d=t[n++]),f&2&&(d|=t[n++]<<8),f&4&&(d|=t[n++]<<16),f&8&&(d|=t[n++]<<24),f&16&&(u=t[n++]),f&32&&(u|=t[n++]<<8),f&64&&(u|=t[n++]<<16),u===0&&(u=65536),i.set(e.subarray(d,d+u),c),c+=u}else if(f>0)i.set(t.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==s)throw new Error(`Delta produced ${c} bytes, expected ${s}`);return i}async function $r(e){let t=[],n=new Uint8Array(12),r=new DataView(n.buffer);r.setUint32(0,Rr),r.setUint32(4,Ns),r.setUint32(8,e.length),t.push(n);for(let d of e){let u=li[d.type],l=await Rn(d.content),m=Gs(u,d.content.byteLength);t.push(m),t.push(l)}let o=0;for(let d of t)o+=d.byteLength;o+=20;let s=new Uint8Array(o),a=0;for(let d of t)s.set(d,a),a+=d.byteLength;let i=Kt();i.update(s.subarray(0,a));let c=await i.hex(),f=ft(c);return s.set(f,a),s}async function mi(e){let t=[],n=new Map,r=new Uint8Array(12),o=new DataView(r.buffer);o.setUint32(0,Rr),o.setUint32(4,Ns),o.setUint32(8,e.length),t.push(r);let s=12,a=[];for(let l of e){let m=s;n.set(l.hash,s);let h=l.delta&&l.deltaBaseHash?n.get(l.deltaBaseHash):void 0;if(l.delta&&h!==void 0){let p=Gs(Kn,l.delta.byteLength),g=Ef(s-h),w=await Rn(l.delta);t.push(p,g,w),s+=p.byteLength+g.byteLength+w.byteLength}else{let p=li[l.type],g=Gs(p,l.content.byteLength),w=await Rn(l.content);t.push(g,w),s+=g.byteLength+w.byteLength}a.push({hash:l.hash,offset:m,nextOffset:s})}let i=0;for(let l of t)i+=l.byteLength;i+=20;let c=new Uint8Array(i),f=0;for(let l of t)c.set(l,f),f+=l.byteLength;let d=Kt();d.update(c.subarray(0,f));let u=await d.hex();return c.set(ft(u),f),{data:c,entries:a}}function Ef(e){let t=[];t.push(e&127);let n=e>>>7;for(;n>0;)t.unshift(128|--n&127),n>>>=7;return new Uint8Array(t)}function Gs(e,t){let n=[],r=e<<4|t&15;for(t>>=4;t>0;)n.push(r|128),r=t&127,t>>=7;return n.push(r),new Uint8Array(n)}function oi(e,t){let n=0,r=0,o;do o=e[t++],n|=(o&127)<<r,r+=7;while(o&128);return{value:n,newPos:t}}async function xf(e,t,n){let r=e.subarray(t),o=await Mt(r);if(o.byteLength!==n)throw new Error(`Inflate size mismatch: got ${o.byteLength}, expected ${n}`);let s=2,a=r.byteLength;for(;s<a;){let i=s+a>>>1;try{(await Mt(r.subarray(0,i))).byteLength===n?a=i:s=i+1}catch{s=i+1}}return{result:o,bytesConsumed:s}}var kf=new TextEncoder;async function ii(e,t){let n=kf.encode(`${e} ${t.byteLength}\0`),r=Kt();return r.update(n),r.update(t),r.hex()}var hi=4285812579,pi=2,un=class{fanout;hashes;offsets;largeOffsets;count;constructor(t){let n=new DataView(t.buffer,t.byteOffset,t.byteLength);if(n.getUint32(0)!==hi)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==pi)throw new Error(`Unsupported pack index version: ${n.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let s=0;s<256;s++)this.fanout[s]=n.getUint32(r),r+=4;this.count=this.fanout[255],this.hashes=new Uint8Array(t.buffer,t.byteOffset+r,this.count*20),r+=this.count*20,r+=this.count*4,this.offsets=new Uint32Array(this.count);for(let s=0;s<this.count;s++)this.offsets[s]=n.getUint32(r),r+=4;let o=!1;for(let s=0;s<this.count;s++)if(this.offsets[s]&2147483648){o=!0;break}this.largeOffsets=o?new DataView(t.buffer,t.byteOffset+r):null}lookup(t){let n=ft(t),r=n[0],o=r===0?0:this.fanout[r-1],s=this.fanout[r],a=o,i=s;for(;a<i;){let c=a+i>>>1,f=this.compareAt(c,n);if(f<0)a=c+1;else if(f>0)i=c;else return this.getOffset(c)}return null}has(t){return this.lookup(t)!==null}get objectCount(){return this.count}allHashes(){let t=[];for(let n=0;n<this.count;n++){let r="",o=n*20;for(let s=0;s<20;s++){let a=this.hashes[o+s];r+=(a>>4).toString(16)+(a&15).toString(16)}t.push(r)}return t}compareAt(t,n){let r=t*20;for(let o=0;o<20;o++){let s=this.hashes[r+o],a=n[o];if(s<a)return-1;if(s>a)return 1}return 0}getOffset(t){let n=this.offsets[t];if(n&2147483648){let r=n&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return n}};async function gi(e,t){let n=[...e].sort((m,h)=>m.hash<h.hash?-1:m.hash>h.hash?1:0),r=n.length,o=[];for(let m of n)m.offset>=2147483648&&o.push(BigInt(m.offset));let s=8+256*4+r*20+r*4+r*4+o.length*8+20+20,a=new Uint8Array(s),i=new DataView(a.buffer),c=0;i.setUint32(c,hi),c+=4,i.setUint32(c,pi),c+=4;let f=new Uint32Array(256);for(let m of n){let h=parseInt(m.hash.slice(0,2),16);for(let p=h;p<256;p++)f[p]++}for(let m=0;m<256;m++)i.setUint32(c,f[m]),c+=4;for(let m of n)a.set(ft(m.hash),c),c+=20;for(let m of n)i.setUint32(c,m.crc),c+=4;let d=0;for(let m of n)m.offset>=2147483648?i.setUint32(c,2147483648|d++):i.setUint32(c,m.offset),c+=4;for(let m of o)i.setBigUint64(c,m),c+=8;a.set(t,c),c+=20;let u=Kt();u.update(a.subarray(0,c));let l=await u.hex();return a.set(ft(l),c),a}async function wi(e){let n=(await ui(e)).map(o=>({hash:o.hash,offset:o.offset,crc:Ls(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return gi(n,r)}async function bi(e,t){let n=t.map(o=>({hash:o.hash,offset:o.offset,crc:Ls(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return gi(n,r)}var Cf=6,Pf=7,Of={1:"commit",2:"tree",3:"blob",4:"tag"},zn=class{constructor(t,n){this.data=t;this.index=new un(n)}index;hasObject(t){return this.index.has(t)}async readObject(t){let n=this.index.lookup(t);return n===null?null:this.readAt(n)}get objectCount(){return this.index.objectCount}async readAt(t){let n=this.data,r=t,o=n[r++],s=o>>4&7,a=o&15,i=4;for(;o&128;)o=n[r++],a|=(o&127)<<i,i+=7;if(s===Cf){let d=n[r++],u=d&127;for(;d&128;)u+=1,d=n[r++],u=(u<<7)+(d&127);let l=await Mt(n.subarray(r)),m=await this.readAt(t-u);return{type:m.type,content:Ir(m.content,l)}}if(s===Pf){let d=Pr(n,r);r+=20;let u=await Mt(n.subarray(r)),l=this.index.lookup(d);if(l===null)throw new Error(`REF_DELTA base ${d} not found in pack`);let m=await this.readAt(l);return{type:m.type,content:Ir(m.content,u)}}let c=Of[s];if(!c)throw new Error(`Unknown pack object type: ${s}`);let f=await Mt(n.subarray(r));if(f.byteLength!==a)throw new Error(`Pack inflate size mismatch at offset ${t}: got ${f.byteLength}, expected ${a}`);return{type:c,content:f}}};var Rf=new TextEncoder,If=new TextDecoder;function Us(e,t){let n=Rf.encode(`${e} ${t.byteLength}\0`),r=new Uint8Array(n.byteLength+t.byteLength);return r.set(n),r.set(t,n.byteLength),r}function $f(e,t){let n=t.indexOf(0);if(n===-1)throw new Error(`Corrupt object ${e}: no null byte in header`);let r=If.decode(t.subarray(0,n)),o=r.indexOf(" ");if(o===-1)throw new Error(`Corrupt object ${e}: malformed header "${r}"`);let s=r.slice(0,o),a=parseInt(r.slice(o+1),10),i=t.subarray(n+1);if(i.byteLength!==a)throw new Error(`Corrupt object ${e}: expected ${a} bytes, got ${i.byteLength}`);return{type:s,content:i}}function Fs(e,t){return v(e,"objects",t.slice(0,2),t.slice(2))}var Tr=class{constructor(t,n,r){this.fs=t;this.gitDir=n;this.hooks=r}packs=[];loadedPackNames=new Set;discoverPromise=null;async write(t,n){let r=Us(t,n),o=await On(r),s=Fs(this.gitDir,o);if(await this.fs.exists(s))return o;let a=v(this.gitDir,"objects",o.slice(0,2));return await this.fs.mkdir(a,{recursive:!0}),await this.fs.writeFile(s,await Rn(r)),this.hooks?.emit("object:write",{type:t,hash:o}),o}async read(t){let n=Fs(this.gitDir,t);if(await this.fs.exists(n)){let r=await this.fs.readFileBuffer(n),o=await Mt(r);return $f(t,o)}await this.discover();for(let r of this.packs){let o=await r.readObject(t);if(o)return o}throw new Error(`object ${t} not found`)}async exists(t){if(await this.fs.exists(Fs(this.gitDir,t)))return!0;await this.discover();for(let n of this.packs)if(n.hasObject(t))return!0;return!1}async ingestPack(t){if(t.byteLength<32)return 0;let r=new DataView(t.buffer,t.byteOffset,t.byteLength).getUint32(8);if(r===0)return 0;let o=t.subarray(t.byteLength-20),s=qt(o),a=v(this.gitDir,"objects","pack");await this.fs.mkdir(a,{recursive:!0});let i=`pack-${s}`,c=v(a,`${i}.pack`);await this.fs.writeFile(c,t);let f=await wi(t),d=v(a,`${i}.idx`);return await this.fs.writeFile(d,f),this.loadedPackNames.add(i),this.packs.push(new zn(t,f)),r}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){let t=v(this.gitDir,"objects","pack");if(!await this.fs.exists(t))return;let n=await this.fs.readdir(t);for(let r of n){if(!r.endsWith(".idx"))continue;let o=r.slice(0,-4);if(this.loadedPackNames.has(o))continue;let s=v(t,`${o}.pack`);if(!await this.fs.exists(s))continue;let[a,i]=await Promise.all([this.fs.readFileBuffer(v(t,r)),this.fs.readFileBuffer(s)]);this.loadedPackNames.add(o),this.packs.push(new zn(i,a))}}};function Vn(e){let t=e.indexOf("<"),n=e.indexOf(">");if(t===-1||n===-1)throw new Error(`Malformed identity line: "${e}"`);let r=e.slice(0,t).trimEnd(),o=e.slice(t+1,n),s=e.slice(n+2),[a="0",i="+0000"]=s.split(" "),c=parseInt(a,10);return{name:r,email:o,timestamp:c,timezone:i}}function Yn(e){return`${e.name} <${e.email}> ${e.timestamp} ${e.timezone}`}var Tf=new TextEncoder,Hf=new TextDecoder;function It(e){let t=Hf.decode(e),n=t.indexOf(`
|
|
14
|
+
`);return{name:s,email:a,timestamp:Zo(t.get(r.date)),timezone:"+0000"}}async function Ot(e,t){try{let n=await qn(e,t);return{name:n.name,email:n.email,timestamp:n.timestamp,tz:n.timezone}}catch{return{name:t.get("GIT_COMMITTER_NAME")??"",email:t.get("GIT_COMMITTER_EMAIL")??"",timestamp:Math.floor(Date.now()/1e3),tz:"+0000"}}}function Zo(e){if(e){let t=parseInt(e,10);if(!Number.isNaN(t))return t;let n=Date.parse(e);if(!Number.isNaN(n))return Math.floor(n/1e3)}return Math.floor(Date.now()/1e3)}var Z="0000000000000000000000000000000000000000",Qo=(()=>{let e=new Array(256);for(let t=0;t<256;t++)e[t]=(t>>4).toString(16)+(t&15).toString(16);return e})();function qt(e){let t="";for(let n=0;n<20;n++)t+=Qo[e[n]];return t}function Pr(e,t){let n="";for(let r=0;r<20;r++)n+=Qo[e[t+r]];return n}function ft(e){let t=new Uint8Array(20);for(let n=0;n<20;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}var lf=new TextEncoder;function Ds(e){return typeof e=="string"?lf.encode(e):e}function uf(){if(typeof globalThis.Bun<"u")return()=>{let e=new Bun.CryptoHasher("sha1"),t={update(n){return e.update(Ds(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t};try{let e=br(["node","crypto"].join(":"));if(typeof e.createHash=="function")return()=>{let t=e.createHash("sha1"),n={update(r){return t.update(Ds(r)),n},hex:()=>Promise.resolve(t.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let e=[],t={update(n){return e.push(Ds(n)),t},async hex(){let n=0;for(let a of e)n+=a.byteLength;let r=new Uint8Array(n),o=0;for(let a of e)r.set(a,o),o+=a.byteLength;let s=await crypto.subtle.digest("SHA-1",r);return qt(new Uint8Array(s))}};return t};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var ei=uf(),Kt=ei;async function On(e){return ei().update(e).hex()}var ti=1145655875,Ms=2;async function U(e){let t=v(e.gitDir,"index");if(!await e.fs.exists(t))return{version:Ms,entries:[]};let n=await e.fs.readFileBuffer(t);return mf(n)}async function re(e,t){let n=v(e.gitDir,"index"),r=await hf(t);await e.fs.writeFile(n,r)}function Xe(e,t){let n;return t.stage===0?n=e.entries.filter(r=>r.path!==t.path):n=e.entries.filter(r=>!(r.path===t.path&&r.stage===t.stage)),n.push(t),n.sort(js),{...e,entries:n}}function Ne(e,t){return{...e,entries:e.entries.filter(n=>n.path!==t)}}function Dt(e,t,n=0){return e.entries.find(r=>r.path===t&&r.stage===n)}function dt(e){return e.entries.some(t=>t.stage>0)}function Rt(e){return[...new Set(e.entries.filter(t=>t.stage>0).map(t=>t.path))]}function xe(e){return e.entries.filter(t=>t.stage===0)}function ni(){return{version:Ms,entries:[]}}function Or(e){let t=[...e].sort(js);return{version:Ms,entries:t}}function pe(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}function mf(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=0,r=t.getUint32(n);if(n+=4,r!==ti)throw new Error(`Invalid index signature: 0x${r.toString(16)}`);let o=t.getUint32(n);n+=4;let s=t.getUint32(n);n+=4;let a=[];for(let i=0;i<s;i++){let c=n,f={ctimeSeconds:t.getUint32(n),ctimeNanoseconds:t.getUint32(n+4),mtimeSeconds:t.getUint32(n+8),mtimeNanoseconds:t.getUint32(n+12),dev:t.getUint32(n+16),ino:t.getUint32(n+20),uid:t.getUint32(n+28),gid:t.getUint32(n+32),size:t.getUint32(n+36)},d=t.getUint32(n+24);n+=40;let u=e.subarray(n,n+20),l=qt(u);n+=20;let m=t.getUint16(n);n+=2;let h=m>>12&3,p=m&4095,g;if(p<4095)g=new TextDecoder().decode(e.subarray(n,n+p));else{let b=n;for(;b<e.byteLength&&e[b]!==0;)b++;g=new TextDecoder().decode(e.subarray(n,b))}let w=62+g.length+1,x=Math.ceil(w/8)*8;n=c+x,a.push({path:g,mode:d,hash:l,stage:h,stat:f})}return{version:o,entries:a}}async function hf(e){let t=[...e.entries].sort(js),n=12;for(let d of t){let u=62+d.path.length+1;n+=Math.ceil(u/8)*8}n+=20;let r=new ArrayBuffer(n),o=new Uint8Array(r),s=new DataView(r),a=0;s.setUint32(a,ti),a+=4,s.setUint32(a,e.version),a+=4,s.setUint32(a,t.length),a+=4;for(let d of t){let u=a;s.setUint32(a,d.stat.ctimeSeconds),s.setUint32(a+4,d.stat.ctimeNanoseconds),s.setUint32(a+8,d.stat.mtimeSeconds),s.setUint32(a+12,d.stat.mtimeNanoseconds),s.setUint32(a+16,d.stat.dev),s.setUint32(a+20,d.stat.ino),s.setUint32(a+24,d.mode),s.setUint32(a+28,d.stat.uid),s.setUint32(a+32,d.stat.gid),s.setUint32(a+36,d.stat.size),a+=40;let l=ft(d.hash);o.set(l,a),a+=20;let m=Math.min(d.path.length,4095),h=(d.stage&3)<<12|m;s.setUint16(a,h),a+=2;let p=new TextEncoder().encode(d.path);o.set(p,a),a+=p.byteLength,o[a]=0,a+=1;let g=62+p.byteLength+1,w=Math.ceil(g/8)*8;a=u+w}let i=o.subarray(0,a),c=await On(i),f=ft(c);return o.set(f,a),o}function js(e,t){return e.path<t.path?-1:e.path>t.path?1:e.stage-t.stage}var ri=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;ri[e]=t}function Ls(e){let t=4294967295;for(let n=0;n<e.byteLength;n++)t=ri[(t^e[n])&255]^t>>>8;return(t^4294967295)>>>0}function pf(){try{let e=br(["node","zlib"].join(":"));if(typeof e.deflateSync=="function"&&typeof e.inflateSync=="function")return{deflate:t=>Promise.resolve(new Uint8Array(e.deflateSync(t))),inflate:t=>Promise.resolve(new Uint8Array(e.inflateSync(t)))}}catch{}if(typeof globalThis.CompressionStream=="function"&&typeof globalThis.DecompressionStream=="function")return{async deflate(e){let t=new CompressionStream("deflate"),n=t.writable.getWriter();return n.write(e),n.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())},async inflate(e){let t=new DecompressionStream("deflate"),n=t.writable.getWriter();return n.write(e),n.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())}};throw new Error("No zlib implementation available. Requires Bun, Node.js, Deno, or a browser with CompressionStream.")}var si=pf(),Rn=si.deflate,Mt=si.inflate;var Rr=1346454347,Ns=2,ai=1,ci=2,fi=3,di=4,Kn=6,_s=7,gf={[ai]:"commit",[ci]:"tree",[fi]:"blob",[di]:"tag"},li={commit:ai,tree:ci,blob:fi,tag:di};async function ui(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0);if(n!==Rr)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${Rr.toString(16)})`);let r=t.getUint32(4);if(r!==Ns)throw new Error(`Unsupported pack version: ${r}`);let o=t.getUint32(8),s=[],a=12;for(let c=0;c<o;c++){let f=await wf(e,a);s.push(f),a=f.nextOffset}return(await bf(s)).map((c,f)=>({...c,offset:s[f].headerOffset,nextOffset:s[f].nextOffset}))}async function wf(e,t){let n=t,r=e[t++],o=r>>4&7,s=r&15,a=4;for(;r&128;)r=e[t++],s|=(r&127)<<a,a+=7;let i,c;if(o===Kn){let u=e[t++];for(i=u&127;u&128;)i+=1,u=e[t++],i=(i<<7)+(u&127);i=n-i}else o===_s&&(c=Pr(e,t),t+=20);let{result:f,bytesConsumed:d}=await xf(e,t,s);return{headerOffset:n,typeNum:o,inflated:f,baseOffset:i,baseHash:c,nextOffset:t+d}}async function bf(e){let t=new Map;for(let o=0;o<e.length;o++)t.set(e[o].headerOffset,o);let n=new Array(e.length).fill(null);async function r(o){let s=n[o];if(s)return s;let a=e[o];if(a.typeNum!==Kn&&a.typeNum!==_s){let u=gf[a.typeNum];if(!u)throw new Error(`Unknown object type: ${a.typeNum}`);let l={type:u,content:a.inflated,hash:await ii(u,a.inflated)};return n[o]=l,l}let i;if(a.typeNum===Kn){if(i=t.get(a.baseOffset),i===void 0)throw new Error(`OFS_DELTA base not found at offset ${a.baseOffset}`)}else if(i=await yf(e,n,a.baseHash,r),i===void 0)throw new Error(`REF_DELTA base not found for hash ${a.baseHash}`);let c=await r(i),f=Ir(c.content,a.inflated),d={type:c.type,content:f,hash:await ii(c.type,f)};return n[o]=d,d}for(let o=0;o<e.length;o++)await r(o);return n}async function yf(e,t,n,r){for(let o=0;o<t.length;o++)if(t[o]?.hash===n)return o;for(let o=0;o<e.length;o++){let s=e[o];if(s.typeNum!==Kn&&s.typeNum!==_s&&(await r(o)).hash===n)return o}}function Ir(e,t){let n=0,{value:r,newPos:o}=oi(t,n);if(n=o,r!==e.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${e.byteLength}`);let{value:s,newPos:a}=oi(t,n);n=a;let i=new Uint8Array(s),c=0;for(;n<t.byteLength;){let f=t[n++];if(f&128){let d=0,u=0;f&1&&(d=t[n++]),f&2&&(d|=t[n++]<<8),f&4&&(d|=t[n++]<<16),f&8&&(d|=t[n++]<<24),f&16&&(u=t[n++]),f&32&&(u|=t[n++]<<8),f&64&&(u|=t[n++]<<16),u===0&&(u=65536),i.set(e.subarray(d,d+u),c),c+=u}else if(f>0)i.set(t.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==s)throw new Error(`Delta produced ${c} bytes, expected ${s}`);return i}async function $r(e){let t=[],n=new Uint8Array(12),r=new DataView(n.buffer);r.setUint32(0,Rr),r.setUint32(4,Ns),r.setUint32(8,e.length),t.push(n);for(let d of e){let u=li[d.type],l=await Rn(d.content),m=Gs(u,d.content.byteLength);t.push(m),t.push(l)}let o=0;for(let d of t)o+=d.byteLength;o+=20;let s=new Uint8Array(o),a=0;for(let d of t)s.set(d,a),a+=d.byteLength;let i=Kt();i.update(s.subarray(0,a));let c=await i.hex(),f=ft(c);return s.set(f,a),s}async function mi(e){let t=[],n=new Map,r=new Uint8Array(12),o=new DataView(r.buffer);o.setUint32(0,Rr),o.setUint32(4,Ns),o.setUint32(8,e.length),t.push(r);let s=12,a=[];for(let l of e){let m=s;n.set(l.hash,s);let h=l.delta&&l.deltaBaseHash?n.get(l.deltaBaseHash):void 0;if(l.delta&&h!==void 0){let p=Gs(Kn,l.delta.byteLength),g=Ef(s-h),w=await Rn(l.delta);t.push(p,g,w),s+=p.byteLength+g.byteLength+w.byteLength}else{let p=li[l.type],g=Gs(p,l.content.byteLength),w=await Rn(l.content);t.push(g,w),s+=g.byteLength+w.byteLength}a.push({hash:l.hash,offset:m,nextOffset:s})}let i=0;for(let l of t)i+=l.byteLength;i+=20;let c=new Uint8Array(i),f=0;for(let l of t)c.set(l,f),f+=l.byteLength;let d=Kt();d.update(c.subarray(0,f));let u=await d.hex();return c.set(ft(u),f),{data:c,entries:a}}function Ef(e){let t=[];t.push(e&127);let n=e>>>7;for(;n>0;)t.unshift(128|--n&127),n>>>=7;return new Uint8Array(t)}function Gs(e,t){let n=[],r=e<<4|t&15;for(t>>=4;t>0;)n.push(r|128),r=t&127,t>>=7;return n.push(r),new Uint8Array(n)}function oi(e,t){let n=0,r=0,o;do o=e[t++],n|=(o&127)<<r,r+=7;while(o&128);return{value:n,newPos:t}}async function xf(e,t,n){let r=e.subarray(t),o=await Mt(r);if(o.byteLength!==n)throw new Error(`Inflate size mismatch: got ${o.byteLength}, expected ${n}`);let s=2,a=r.byteLength;for(;s<a;){let i=s+a>>>1;try{(await Mt(r.subarray(0,i))).byteLength===n?a=i:s=i+1}catch{s=i+1}}return{result:o,bytesConsumed:s}}var kf=new TextEncoder;async function ii(e,t){let n=kf.encode(`${e} ${t.byteLength}\0`),r=Kt();return r.update(n),r.update(t),r.hex()}var hi=4285812579,pi=2,un=class{fanout;hashes;offsets;largeOffsets;count;constructor(t){let n=new DataView(t.buffer,t.byteOffset,t.byteLength);if(n.getUint32(0)!==hi)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==pi)throw new Error(`Unsupported pack index version: ${n.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let s=0;s<256;s++)this.fanout[s]=n.getUint32(r),r+=4;this.count=this.fanout[255],this.hashes=new Uint8Array(t.buffer,t.byteOffset+r,this.count*20),r+=this.count*20,r+=this.count*4,this.offsets=new Uint32Array(this.count);for(let s=0;s<this.count;s++)this.offsets[s]=n.getUint32(r),r+=4;let o=!1;for(let s=0;s<this.count;s++)if(this.offsets[s]&2147483648){o=!0;break}this.largeOffsets=o?new DataView(t.buffer,t.byteOffset+r):null}lookup(t){let n=ft(t),r=n[0],o=r===0?0:this.fanout[r-1],s=this.fanout[r],a=o,i=s;for(;a<i;){let c=a+i>>>1,f=this.compareAt(c,n);if(f<0)a=c+1;else if(f>0)i=c;else return this.getOffset(c)}return null}has(t){return this.lookup(t)!==null}get objectCount(){return this.count}allHashes(){let t=[];for(let n=0;n<this.count;n++){let r="",o=n*20;for(let s=0;s<20;s++){let a=this.hashes[o+s];r+=(a>>4).toString(16)+(a&15).toString(16)}t.push(r)}return t}compareAt(t,n){let r=t*20;for(let o=0;o<20;o++){let s=this.hashes[r+o],a=n[o];if(s<a)return-1;if(s>a)return 1}return 0}getOffset(t){let n=this.offsets[t];if(n&2147483648){let r=n&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return n}};async function gi(e,t){let n=[...e].sort((m,h)=>m.hash<h.hash?-1:m.hash>h.hash?1:0),r=n.length,o=[];for(let m of n)m.offset>=2147483648&&o.push(BigInt(m.offset));let s=8+256*4+r*20+r*4+r*4+o.length*8+20+20,a=new Uint8Array(s),i=new DataView(a.buffer),c=0;i.setUint32(c,hi),c+=4,i.setUint32(c,pi),c+=4;let f=new Uint32Array(256);for(let m of n){let h=parseInt(m.hash.slice(0,2),16);for(let p=h;p<256;p++)f[p]++}for(let m=0;m<256;m++)i.setUint32(c,f[m]),c+=4;for(let m of n)a.set(ft(m.hash),c),c+=20;for(let m of n)i.setUint32(c,m.crc),c+=4;let d=0;for(let m of n)m.offset>=2147483648?i.setUint32(c,2147483648|d++):i.setUint32(c,m.offset),c+=4;for(let m of o)i.setBigUint64(c,m),c+=8;a.set(t,c),c+=20;let u=Kt();u.update(a.subarray(0,c));let l=await u.hex();return a.set(ft(l),c),a}async function wi(e){let n=(await ui(e)).map(o=>({hash:o.hash,offset:o.offset,crc:Ls(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return gi(n,r)}async function bi(e,t){let n=t.map(o=>({hash:o.hash,offset:o.offset,crc:Ls(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return gi(n,r)}var Cf=6,Pf=7,Of={1:"commit",2:"tree",3:"blob",4:"tag"},zn=class{constructor(t,n){this.data=t;this.index=new un(n)}index;hasObject(t){return this.index.has(t)}async readObject(t){let n=this.index.lookup(t);return n===null?null:this.readAt(n)}get objectCount(){return this.index.objectCount}async readAt(t){let n=this.data,r=t,o=n[r++],s=o>>4&7,a=o&15,i=4;for(;o&128;)o=n[r++],a|=(o&127)<<i,i+=7;if(s===Cf){let d=n[r++],u=d&127;for(;d&128;)u+=1,d=n[r++],u=(u<<7)+(d&127);let l=await Mt(n.subarray(r)),m=await this.readAt(t-u);return{type:m.type,content:Ir(m.content,l)}}if(s===Pf){let d=Pr(n,r);r+=20;let u=await Mt(n.subarray(r)),l=this.index.lookup(d);if(l===null)throw new Error(`REF_DELTA base ${d} not found in pack`);let m=await this.readAt(l);return{type:m.type,content:Ir(m.content,u)}}let c=Of[s];if(!c)throw new Error(`Unknown pack object type: ${s}`);let f=await Mt(n.subarray(r));if(f.byteLength!==a)throw new Error(`Pack inflate size mismatch at offset ${t}: got ${f.byteLength}, expected ${a}`);return{type:c,content:f}}};var Rf=new TextEncoder,If=new TextDecoder;function Us(e,t){let n=Rf.encode(`${e} ${t.byteLength}\0`),r=new Uint8Array(n.byteLength+t.byteLength);return r.set(n),r.set(t,n.byteLength),r}function $f(e,t){let n=t.indexOf(0);if(n===-1)throw new Error(`Corrupt object ${e}: no null byte in header`);let r=If.decode(t.subarray(0,n)),o=r.indexOf(" ");if(o===-1)throw new Error(`Corrupt object ${e}: malformed header "${r}"`);let s=r.slice(0,o),a=parseInt(r.slice(o+1),10),i=t.subarray(n+1);if(i.byteLength!==a)throw new Error(`Corrupt object ${e}: expected ${a} bytes, got ${i.byteLength}`);return{type:s,content:i}}function Fs(e,t){return v(e,"objects",t.slice(0,2),t.slice(2))}var Tr=class{constructor(t,n,r){this.fs=t;this.gitDir=n;this.hooks=r}packs=[];loadedPackNames=new Set;discoverPromise=null;async write(t,n){let r=Us(t,n),o=await On(r),s=Fs(this.gitDir,o);if(await this.fs.exists(s))return o;let a=v(this.gitDir,"objects",o.slice(0,2));return await this.fs.mkdir(a,{recursive:!0}),await this.fs.writeFile(s,await Rn(r)),this.hooks?.emit("object:write",{type:t,hash:o}),o}async read(t){let n=Fs(this.gitDir,t);if(await this.fs.exists(n)){let r=await this.fs.readFileBuffer(n),o=await Mt(r);return $f(t,o)}await this.discover();for(let r of this.packs){let o=await r.readObject(t);if(o)return o}throw new Error(`object ${t} not found`)}async exists(t){if(await this.fs.exists(Fs(this.gitDir,t)))return!0;await this.discover();for(let n of this.packs)if(n.hasObject(t))return!0;return!1}async ingestPack(t){if(t.byteLength<32)return 0;let r=new DataView(t.buffer,t.byteOffset,t.byteLength).getUint32(8);if(r===0)return 0;let o=t.subarray(t.byteLength-20),s=qt(o),a=v(this.gitDir,"objects","pack");await this.fs.mkdir(a,{recursive:!0});let i=`pack-${s}`,c=v(a,`${i}.pack`);await this.fs.writeFile(c,t);let f=await wi(t),d=v(a,`${i}.idx`);return await this.fs.writeFile(d,f),this.loadedPackNames.add(i),this.packs.push(new zn(t,f)),r}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){let t=v(this.gitDir,"objects","pack");if(!await this.fs.exists(t))return;let n=await this.fs.readdir(t);for(let r of n){if(!r.endsWith(".idx"))continue;let o=r.slice(0,-4);if(this.loadedPackNames.has(o))continue;let s=v(t,`${o}.pack`);if(!await this.fs.exists(s))continue;let[a,i]=await Promise.all([this.fs.readFileBuffer(v(t,r)),this.fs.readFileBuffer(s)]);this.loadedPackNames.add(o),this.packs.push(new zn(i,a))}}};function Vn(e){let t=e.indexOf("<"),n=e.indexOf(">");if(t===-1||n===-1)throw new Error(`Malformed identity line: "${e}"`);let r=e.slice(0,t).trimEnd(),o=e.slice(t+1,n),s=e.slice(n+2),[a="0",i="+0000"]=s.split(" "),c=parseInt(a,10);return{name:r,email:o,timestamp:c,timezone:i}}function Yn(e){return`${e.name} <${e.email}> ${e.timestamp} ${e.timezone}`}var Tf=new TextEncoder,Hf=new TextDecoder;function It(e){let t=Hf.decode(e),n=t.indexOf(`
|
|
15
15
|
|
|
16
16
|
`),r=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n+2),s="",a=[],i,c;for(let f of r.split(`
|
|
17
17
|
`)){let d=f.indexOf(" ");if(d===-1)continue;let u=f.slice(0,d),l=f.slice(d+1);switch(u){case"tree":s=l;break;case"parent":a.push(l);break;case"author":i=Vn(l);break;case"committer":c=Vn(l);break}}if(!s)throw new Error("Commit missing tree field");if(!i)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:s,parents:a,author:i,committer:c,message:o}}function $t(e){let t=[];t.push(`tree ${e.tree}`);for(let n of e.parents)t.push(`parent ${n}`);return t.push(`author ${Yn(e.author)}`),t.push(`committer ${Yn(e.committer)}`),t.push(""),t.push(e.message),Tf.encode(t.join(`
|