just-git 1.3.9 → 1.4.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/README.md +3 -3
- package/dist/index.js +1 -1
- package/dist/server/index.d.ts +58 -58
- package/dist/server/index.js +21 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -83,8 +83,8 @@ const server = createServer({
|
|
|
83
83
|
autoCreate: true,
|
|
84
84
|
policy: { protectedBranches: ["main"] },
|
|
85
85
|
hooks: {
|
|
86
|
-
preReceive: ({
|
|
87
|
-
if (!
|
|
86
|
+
preReceive: ({ auth }) => {
|
|
87
|
+
if (!auth.request?.headers.has("Authorization"))
|
|
88
88
|
return { reject: true, message: "unauthorized" };
|
|
89
89
|
},
|
|
90
90
|
postReceive: async ({ repo, repoId, updates }) => {
|
|
@@ -134,7 +134,7 @@ See [REPO.md](docs/REPO.md) for the full API, the `GitRepo` interface, and the h
|
|
|
134
134
|
- **Local paths**: direct filesystem transfer between repositories.
|
|
135
135
|
- **Cross-VFS**: clone, fetch, and push between isolated in-memory filesystems via `resolveRemote`. See [CLIENT.md](docs/CLIENT.md#multi-agent-collaboration).
|
|
136
136
|
- **Smart HTTP**: clone, fetch, and push against real Git servers (e.g. GitHub) via Git Smart HTTP protocol. Auth via `credentials` option or `GIT_HTTP_BEARER_TOKEN` / `GIT_HTTP_USER` + `GIT_HTTP_PASSWORD` env vars.
|
|
137
|
-
- **In-process server**: connect a git client to a `GitServer` without any network stack via `server.asNetwork()`. All server hooks,
|
|
137
|
+
- **In-process server**: connect a git client to a `GitServer` without any network stack via `server.asNetwork()`. All server hooks, auth, and policy enforcement work identically to real HTTP. See [CLIENT.md](docs/CLIENT.md#in-process-server).
|
|
138
138
|
|
|
139
139
|
### Internals
|
|
140
140
|
|
package/dist/index.js
CHANGED
|
@@ -776,7 +776,7 @@ ${m}`,exitCode:0}}oe();ae();Cr();ge();ss();function Cd(e,t){e.command("tag",{des
|
|
|
776
776
|
`)}if(n.list)return xd(s,n.name||void 0);if(n.name){if(!Ic(n.name))return O(`'${n.name}' is not a valid tag name`);let i=n.commit,a;if(i){let d=await wt(s,i,`Failed to resolve '${i}' as a valid ref.`);if(M(d))return d;a=d}else if(a=await Y(s),!a)return O("Failed to resolve 'HEAD' as a valid ref.");let c=`refs/tags/${n.name}`;if(await B(s,c)&&!n.force)return O(`tag '${n.name}' already exists`);if(n.annotate||n.message){if(!n.message)return O("no tag message specified (use -m)");let d=await nt(s,r.env);if(M(d))return d;let m=Mt(n.message),u=Cc({type:"tag",object:a,objectType:"commit",name:n.name,tagger:d,message:m}),h=await He(s,"tag",u);await Z(s,c,h)}else await Z(s,c,a);return{stdout:"",stderr:"",exitCode:0}}return xd(s)}})}async function xd(e,t){let n=await pe(e,"refs/tags");if(n.length===0)return{stdout:"",stderr:"",exitCode:0};let r=n.map(o=>o.name.replace("refs/tags/",""));return t&&(r=r.filter(o=>on(t,o,0)===0)),r.length===0?{stdout:"",stderr:"",exitCode:0}:{stdout:`${r.join(`
|
|
777
777
|
`)}
|
|
778
778
|
`,stderr:"",exitCode:0}}var Pd=new Set(["am","annotate","apply","archive","bugreport","bundle","cat-file","check-ignore","check-mailmap","check-ref-format","checkout-index","cherry","commit-tree","count-objects","credential","daemon","diff-files","diff-index","diff-tree","difftool","fast-export","fast-import","filter-branch","for-each-ref","format-patch","fsck","hash-object","instaweb","interpret-trailers","log--hierarchical","ls-remote","ls-tree","maintenance","merge-base","merge-tree","mergetool","multi-pack-index","name-rev","notes","pack-objects","pack-refs","patch-id","prune","range-diff","read-tree","receive-pack","replace","request-pull","rerere","rev-list","send-email","send-pack","shortlog","show-branch","show-ref","sparse-checkout","stash--helper","stripspace","submodule","symbolic-ref","unpack-objects","update-index","update-ref","upload-pack","var","verify-commit","verify-pack","verify-tag","whatchanged","worktree","write-tree"]),Ow={init:(e,t)=>Ml(e,t),clone:(e,t)=>cl(e,t),describe:(e,t)=>ll(e,t),fetch:(e,t)=>$l(e,t),pull:(e,t)=>ed(e,t),push:(e,t)=>td(e,t),add:(e,t)=>Vc(e,t),blame:(e,t)=>Sf(e,t),commit:(e,t)=>dl(e,t),status:(e,t)=>yd(e,t),log:(e,t)=>ql(e,t),branch:(e,t)=>vf(e,t),tag:(e,t)=>Cd(e,t),checkout:(e,t)=>Hf(e,t),diff:(e,t)=>kl(e,t),reset:(e,t)=>od(e,t),merge:(e,t)=>Vl(e,t),"cherry-pick":(e,t)=>Kf(e,t),revert:(e,t)=>fd(e,t),rebase:(e,t)=>Ql(e,t),mv:(e,t)=>Yl(e,t),rm:(e,t)=>ld(e,t),remote:(e,t)=>rd(e,t),config:(e,t)=>pl(e,t),show:(e,t)=>dd(e,t),stash:(e,t)=>bd(e,t),"rev-parse":(e,t)=>cd(e,t),"ls-files":(e,t)=>Kl(e,t),clean:(e,t)=>Vf(e,t),switch:(e,t)=>kd(e,t),restore:(e,t)=>ad(e,t),reflog:(e,t)=>nd(e,t),repack:(e,t)=>Sl(e,t),gc:(e,t)=>Tl(e,t),bisect:(e,t)=>pf(e,t),grep:(e,t)=>Dl(e,t)};function $d(e){let t=Vo("git",{description:"Git command"});for(let n of Object.values(Ow))n(t,e);return t.command("help",{description:"Display help information",args:[q.string().name("command").describe("Command to get help for").optional()],handler:async n=>{let r=n.command;if(!r)return{stdout:br(t),stderr:"",exitCode:0};let o=t.children.get(r);return o?{stdout:br(o),stderr:"",exitCode:0}:{stdout:"",stderr:`git: no help available for '${r}'
|
|
779
|
-
`,exitCode:1}}}),t}var Iw="1.
|
|
779
|
+
`,exitCode:1}}}),t}var Iw="1.4.1";function Sw(e,t){if(!e)return t;let n=e.locked?"locked":"defaults",r={"user.name":e.name,"user.email":e.email};return t?{...t,[n]:{...r,...t[n]}}:{[n]:r}}var Bo=class{name="git";defaultFs;defaultCwd;blocked;hooks;inner;locks=new WeakMap;async withLock(t,n){let r=this.locks.get(t)??Promise.resolve(),o,s=new Promise(i=>{o=i});this.locks.set(t,s),await r;try{return await n()}finally{o()}}constructor(t){this.defaultFs=t?.fs,this.defaultCwd=t?.cwd??"/",this.hooks=t?.hooks,this.blocked=t?.disabled?.length?new Set(t.disabled):null;let n=t?.network,r=Sw(t?.identity,t?.config),o={hooks:t?.hooks,credentialProvider:t?.credentials,identityOverride:t?.identity,fetchFn:typeof n=="object"?n.fetch:void 0,networkPolicy:n,resolveRemote:t?.resolveRemote,...t?.objectStore?{objectStore:t.objectStore}:{},...t?.refStore?{refStore:t.refStore}:{},...t?.gitDir?{gitDir:t.gitDir,workTree:this.defaultCwd}:{},...r?{configOverrides:r}:{}};this.inner=$d(o).toCommand()}exec=async(t,n)=>{let r=n?.fs??this.defaultFs;if(!r)throw new Error("No filesystem: pass `fs` in exec() options or in createGit()");let o=n?.cwd??this.defaultCwd,s=Tw(t),i=new Map;if(n?.env)for(let[a,c]of Object.entries(n.env))i.set(a,c);return this.execute(s,{fs:r,cwd:o,env:i,stdin:n?.stdin??""})};execute=(t,n)=>this.withLock(n.fs,async()=>{let r=t[0]??"";if(r==="--version"||r==="version")return{stdout:`just-git version ${Iw} (virtual git implementation)
|
|
780
780
|
`,stderr:"",exitCode:0};if(this.blocked?.has(r))return{stdout:"",stderr:`git: '${r}' is not available in this environment
|
|
781
781
|
`,exitCode:1};if(r&&Pd.has(r))return{stdout:"",stderr:`git: '${r}' is not implemented. Run 'git help' for available commands.
|
|
782
782
|
`,exitCode:1};if(this.hooks?.beforeCommand){let s=await this.hooks.beforeCommand({command:r,args:t.slice(1),fs:n.fs,cwd:n.cwd,env:n.env});if(le(s))return{stdout:"",stderr:s.message??"",exitCode:1}}let o=await this.inner.execute(t,n);return this.hooks?.afterCommand&&await this.hooks.afterCommand({command:r,args:t.slice(1),result:o}),o})};function Tw(e){let t=[],n="",r=0;for(;r<e.length;){let o=e[r];if(o==='"'){for(r++;r<e.length&&e[r]!=='"';){if(e[r]==="\\"&&r+1<e.length){let s=e[r+1];if(s==='"'||s==="\\"){n+=s,r+=2;continue}}n+=e[r],r++}r++}else if(o==="'"){for(r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r++}else o===" "||o===" "?(n.length>0&&(t.push(n),n=""),r++):(n+=o,r++)}return n.length>0&&t.push(n),t.length>0&&t[0]==="git"&&t.shift(),t}function vw(e){return new Bo(e)}var Od=new TextEncoder,Aw=new TextDecoder;function hn(e){let t=[];for(let n of e.split("/"))n==="."||n===""||(n===".."?t.pop():t.push(n));return"/"+t.join("/")}function Wo(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}var Ra=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:16877,mtime:new Date}),t)for(let[n,r]of Object.entries(t)){let o=hn(n);this.ensureParents(o),this.data.set(o,{type:"file",content:typeof r=="string"?Od.encode(r):r,mode:33188,mtime:new Date})}}ensureParents(t){let n=Wo(t);n!=="/"&&(this.data.has(n)||(this.ensureParents(n),this.data.set(n,{type:"directory",mode:16877,mtime:new Date})))}resolve(t){let n="",r=new Set;for(let o of hn(t).slice(1).split("/")){n=`${n}/${o}`;let s=0,i=this.data.get(n);for(;i?.type==="symlink"&&s<40;){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`);r.add(n);let a=i.target;n=a.startsWith("/")?hn(a):hn(Wo(n)+"/"+a),i=this.data.get(n),s++}if(s>=40)throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`)}return n}resolveParent(t){let n=hn(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let o="",s=new Set;for(let i=0;i<r.length-1;i++){o=`${o}/${r[i]}`;let a=this.data.get(o),c=0;for(;a?.type==="symlink"&&c<40;){if(s.has(o))throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`);s.add(o);let f=a.target;o=f.startsWith("/")?hn(f):hn(Wo(o)+"/"+f),a=this.data.get(o),c++}}return`${o}/${r[r.length-1]}`}async readFile(t){return Aw.decode(await this.readFileBuffer(t))}async readFileBuffer(t){let n=this.data.get(this.resolve(t));if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content}async writeFile(t,n){let r=this.resolve(t);this.ensureParents(r),this.data.set(r,{type:"file",content:typeof n=="string"?Od.encode(n):n,mode:33188,mtime:new Date})}async exists(t){try{return this.data.has(this.resolve(t))}catch{return!1}}async stat(t){let n=this.data.get(this.resolve(t));if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);return{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:n.type==="file"?n.content.byteLength:0,mtime:n.mtime}}async lstat(t){let n=this.resolveParent(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:r.type==="symlink",mode:r.mode,size:r.type==="file"?r.content.byteLength:r.type==="symlink"?r.target.length:0,mtime:r.mtime}}async mkdir(t,n){let r=hn(t);if(this.data.has(r)){if(this.data.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let o=Wo(r);if(o!=="/"&&!this.data.has(o))if(n?.recursive)await this.mkdir(o,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:16877,mtime:new Date})}async readdir(t){let n=this.resolve(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let o=n==="/"?"/":`${n}/`,s=new Set;for(let i of this.data.keys())if(i!==n&&i.startsWith(o)){let c=i.slice(o.length).split("/")[0];c&&s.add(c)}return[...s].sort()}async rm(t,n){let r=hn(t),o=this.data.get(r);if(!o){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(o.type==="directory"){if(!n?.recursive&&(await this.readdir(r)).length>0)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);let s=r==="/"?"/":`${r}/`;for(let i of[...this.data.keys()])i.startsWith(s)&&this.data.delete(i)}this.data.delete(r)}async readlink(t){let n=this.resolveParent(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async symlink(t,n){let r=hn(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParents(r),this.data.set(r,{type:"symlink",target:t,mode:40960,mtime:new Date})}};Gn();export{Bo as Git,Ra as MemoryFileSystem,Th as composeGitHooks,vw as createGit,tr as findRepo,le as isRejection};
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as ObjectId, W as RawObject, X as Ref, g as GitRepo, $ as Rejection, N as NetworkPolicy } from '../hooks-C7c_BLqp.js';
|
|
2
|
-
import { b as CommitOptions } from '../writing-CnM1ufDP.js';
|
|
2
|
+
import { b as CommitOptions, c as CommitResult } from '../writing-CnM1ufDP.js';
|
|
3
3
|
|
|
4
4
|
/** Shallow boundary delta: what to add/remove from `.git/shallow`. */
|
|
5
5
|
interface ShallowUpdate {
|
|
@@ -144,13 +144,13 @@ interface GcResult {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
* Default
|
|
148
|
-
* no custom `
|
|
147
|
+
* Default auth context type, produced by the built-in auth provider when
|
|
148
|
+
* no custom `auth` config is provided to `createServer`.
|
|
149
149
|
*
|
|
150
150
|
* HTTP requests produce `{ transport: "http", request }`.
|
|
151
151
|
* SSH sessions produce `{ transport: "ssh", username }`.
|
|
152
152
|
*/
|
|
153
|
-
interface
|
|
153
|
+
interface Auth {
|
|
154
154
|
transport: "http" | "ssh";
|
|
155
155
|
/** Authenticated username, when available. */
|
|
156
156
|
username?: string;
|
|
@@ -158,53 +158,53 @@ interface Session {
|
|
|
158
158
|
request?: Request;
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
161
|
+
* Auth provider that transforms raw transport input into a typed
|
|
162
|
+
* auth context threaded through all hooks.
|
|
163
163
|
*
|
|
164
164
|
* Both properties are optional — provide only the transports you use.
|
|
165
|
-
* TypeScript infers `
|
|
165
|
+
* TypeScript infers `A` from whichever callbacks are present.
|
|
166
166
|
*
|
|
167
|
-
* If a transport is used at runtime but its
|
|
167
|
+
* If a transport is used at runtime but its callback is missing, the
|
|
168
168
|
* server returns an error (HTTP 501 / SSH exit 128).
|
|
169
169
|
*
|
|
170
170
|
* ```ts
|
|
171
171
|
* // HTTP-only — no need to provide ssh
|
|
172
172
|
* const server = createServer({
|
|
173
173
|
* storage: new BunSqliteStorage(db),
|
|
174
|
-
*
|
|
174
|
+
* auth: {
|
|
175
175
|
* http: (req) => ({
|
|
176
176
|
* userId: parseJwt(req).sub,
|
|
177
177
|
* roles: parseJwt(req).roles,
|
|
178
178
|
* }),
|
|
179
179
|
* },
|
|
180
180
|
* hooks: {
|
|
181
|
-
* preReceive: ({
|
|
182
|
-
* //
|
|
183
|
-
* if (!
|
|
181
|
+
* preReceive: ({ auth }) => {
|
|
182
|
+
* // auth is { userId: string, roles: string[] } — inferred!
|
|
183
|
+
* if (!auth.roles.includes("push"))
|
|
184
184
|
* return { reject: true, message: "forbidden" };
|
|
185
185
|
* },
|
|
186
186
|
* },
|
|
187
187
|
* });
|
|
188
188
|
* ```
|
|
189
189
|
*/
|
|
190
|
-
interface
|
|
190
|
+
interface AuthProvider<A> {
|
|
191
191
|
/**
|
|
192
|
-
*
|
|
192
|
+
* Authenticate an HTTP request.
|
|
193
193
|
*
|
|
194
|
-
* Return `
|
|
194
|
+
* Return `A` to proceed, or return a `Response` to short-circuit
|
|
195
195
|
* the request (e.g. 401 with `WWW-Authenticate` header). This is
|
|
196
196
|
* the primary mechanism for HTTP auth — no separate middleware needed.
|
|
197
197
|
*
|
|
198
198
|
* When omitted, HTTP requests receive a 501 response.
|
|
199
199
|
*/
|
|
200
|
-
http?: (request: Request) =>
|
|
200
|
+
http?: (request: Request) => A | Response | Promise<A | Response>;
|
|
201
201
|
/**
|
|
202
|
-
*
|
|
202
|
+
* Authenticate an SSH session.
|
|
203
203
|
*
|
|
204
204
|
* When omitted, SSH sessions receive exit code 128 with a
|
|
205
205
|
* diagnostic message.
|
|
206
206
|
*/
|
|
207
|
-
ssh?: (info: SshSessionInfo) =>
|
|
207
|
+
ssh?: (info: SshSessionInfo) => A | Promise<A>;
|
|
208
208
|
}
|
|
209
209
|
/** Information about the SSH session passed to `handleSession`. */
|
|
210
210
|
interface SshSessionInfo {
|
|
@@ -213,7 +213,7 @@ interface SshSessionInfo {
|
|
|
213
213
|
/**
|
|
214
214
|
* Arbitrary metadata from the SSH auth layer.
|
|
215
215
|
* Stash key fingerprints, client IPs, roles, etc. here —
|
|
216
|
-
* the
|
|
216
|
+
* the auth provider can extract and type them.
|
|
217
217
|
*/
|
|
218
218
|
metadata?: Record<string, unknown>;
|
|
219
219
|
}
|
|
@@ -252,8 +252,8 @@ interface NodeHttpResponse {
|
|
|
252
252
|
/**
|
|
253
253
|
* Declarative push rules applied before user-provided hooks.
|
|
254
254
|
*
|
|
255
|
-
* These are git-level constraints that don't depend on the
|
|
256
|
-
* For
|
|
255
|
+
* These are git-level constraints that don't depend on the caller's
|
|
256
|
+
* identity. For auth-dependent logic, use hooks directly.
|
|
257
257
|
*/
|
|
258
258
|
interface ServerPolicy {
|
|
259
259
|
/** Branches that cannot be force-pushed to or deleted. */
|
|
@@ -265,7 +265,7 @@ interface ServerPolicy {
|
|
|
265
265
|
/** Tags are immutable — no deletion, no overwrite once created. */
|
|
266
266
|
immutableTags?: boolean;
|
|
267
267
|
}
|
|
268
|
-
interface GitServerConfig<
|
|
268
|
+
interface GitServerConfig<A = Auth> {
|
|
269
269
|
/**
|
|
270
270
|
* Storage backend for git object and ref persistence.
|
|
271
271
|
*
|
|
@@ -296,22 +296,22 @@ interface GitServerConfig<S = Session> {
|
|
|
296
296
|
defaultBranch?: string;
|
|
297
297
|
};
|
|
298
298
|
/** Server-side hooks. All optional. */
|
|
299
|
-
hooks?: ServerHooks<
|
|
299
|
+
hooks?: ServerHooks<A>;
|
|
300
300
|
/**
|
|
301
301
|
* Declarative push policy. Rules run before user-provided hooks.
|
|
302
302
|
*
|
|
303
|
-
* For
|
|
303
|
+
* For auth-dependent logic (permissions, post-push actions), use `hooks`.
|
|
304
304
|
*/
|
|
305
305
|
policy?: ServerPolicy;
|
|
306
306
|
/**
|
|
307
|
-
*
|
|
307
|
+
* Auth provider. Provide `http`, `ssh`, or both —
|
|
308
308
|
* the server calls whichever is present for that transport.
|
|
309
|
-
* If a transport is used but its
|
|
309
|
+
* If a transport is used but its callback is missing, the server
|
|
310
310
|
* returns an error (HTTP 501 / SSH exit 128).
|
|
311
311
|
*
|
|
312
|
-
* When omitted entirely, the built-in `
|
|
312
|
+
* When omitted entirely, the built-in `Auth` type is used.
|
|
313
313
|
*/
|
|
314
|
-
|
|
314
|
+
auth?: AuthProvider<A>;
|
|
315
315
|
/** Base path prefix to strip from HTTP URLs (e.g. "/git"). */
|
|
316
316
|
basePath?: string;
|
|
317
317
|
/**
|
|
@@ -343,7 +343,7 @@ interface GitServerConfig<S = Session> {
|
|
|
343
343
|
* Override to integrate with your own logging, or set to `false` to
|
|
344
344
|
* suppress all error output.
|
|
345
345
|
*/
|
|
346
|
-
onError?: false | ((err: unknown,
|
|
346
|
+
onError?: false | ((err: unknown, auth?: A) => void);
|
|
347
347
|
}
|
|
348
348
|
/**
|
|
349
349
|
* A ref update request for {@link GitServer.updateRefs}.
|
|
@@ -443,7 +443,7 @@ interface GitServer {
|
|
|
443
443
|
* {@link asNetwork} instead.
|
|
444
444
|
*
|
|
445
445
|
* ```ts
|
|
446
|
-
* const hash = await server.commit("my-repo", {
|
|
446
|
+
* const { hash } = await server.commit("my-repo", {
|
|
447
447
|
* files: { "README.md": "# Hello\n" },
|
|
448
448
|
* message: "auto-fix",
|
|
449
449
|
* author: { name: "Bot", email: "bot@example.com" },
|
|
@@ -454,11 +454,11 @@ interface GitServer {
|
|
|
454
454
|
* For lower-level control (e.g. constructing trees manually, multi-ref
|
|
455
455
|
* updates), use `buildCommit()` + {@link updateRefs} directly.
|
|
456
456
|
*
|
|
457
|
-
* @returns The new commit's hash.
|
|
457
|
+
* @returns The new commit's hash and parent hash.
|
|
458
458
|
* @throws If the repo does not exist, the server is shutting down,
|
|
459
459
|
* or a concurrent write moved the branch.
|
|
460
460
|
*/
|
|
461
|
-
commit(repoId: string, options: CommitOptions): Promise<
|
|
461
|
+
commit(repoId: string, options: CommitOptions): Promise<CommitResult>;
|
|
462
462
|
/**
|
|
463
463
|
* Node.js `http.createServer` compatible handler.
|
|
464
464
|
*
|
|
@@ -521,31 +521,31 @@ interface GitServer {
|
|
|
521
521
|
*/
|
|
522
522
|
asNetwork(baseUrl?: string): NetworkPolicy;
|
|
523
523
|
}
|
|
524
|
-
interface ServerHooks<
|
|
524
|
+
interface ServerHooks<A = Auth> {
|
|
525
525
|
/**
|
|
526
526
|
* Called after objects are unpacked but before any refs update.
|
|
527
527
|
* Receives ALL ref updates as a batch. Return a Rejection to abort
|
|
528
528
|
* the entire push. Auth, branch protection, and repo-wide policy
|
|
529
529
|
* belong here.
|
|
530
530
|
*/
|
|
531
|
-
preReceive?: (event: PreReceiveEvent<
|
|
531
|
+
preReceive?: (event: PreReceiveEvent<A>) => void | Rejection | Promise<void | Rejection>;
|
|
532
532
|
/**
|
|
533
533
|
* Called per-ref, after preReceive passes.
|
|
534
534
|
* Return a Rejection to block this specific ref update while
|
|
535
535
|
* allowing others. Per-branch rules belong here.
|
|
536
536
|
*/
|
|
537
|
-
update?: (event: UpdateEvent<
|
|
537
|
+
update?: (event: UpdateEvent<A>) => void | Rejection | Promise<void | Rejection>;
|
|
538
538
|
/**
|
|
539
539
|
* Called after all ref updates succeed. Cannot reject.
|
|
540
540
|
* CI triggers, webhooks, notifications belong here.
|
|
541
541
|
*/
|
|
542
|
-
postReceive?: (event: PostReceiveEvent<
|
|
542
|
+
postReceive?: (event: PostReceiveEvent<A>) => void | Promise<void>;
|
|
543
543
|
/**
|
|
544
544
|
* Called when a client wants to fetch or push (during ref advertisement).
|
|
545
545
|
* Return a filtered ref list to hide branches, a Rejection to deny
|
|
546
546
|
* access entirely, or void to advertise all refs.
|
|
547
547
|
*/
|
|
548
|
-
advertiseRefs?: (event: AdvertiseRefsEvent<
|
|
548
|
+
advertiseRefs?: (event: AdvertiseRefsEvent<A>) => RefAdvertisement[] | void | Rejection | Promise<RefAdvertisement[] | void | Rejection>;
|
|
549
549
|
}
|
|
550
550
|
/** A single ref update within a push. */
|
|
551
551
|
interface RefUpdate {
|
|
@@ -563,41 +563,41 @@ interface RefUpdate {
|
|
|
563
563
|
isDelete: boolean;
|
|
564
564
|
}
|
|
565
565
|
/** Fired after objects are unpacked but before refs are updated. */
|
|
566
|
-
interface PreReceiveEvent<
|
|
566
|
+
interface PreReceiveEvent<A = Auth> {
|
|
567
567
|
repo: GitRepo;
|
|
568
568
|
/** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
|
|
569
569
|
repoId: string;
|
|
570
570
|
updates: readonly RefUpdate[];
|
|
571
|
-
/**
|
|
572
|
-
|
|
571
|
+
/** Auth context from the transport's auth provider. Always present — hooks only fire from HTTP/SSH transport. */
|
|
572
|
+
auth: A;
|
|
573
573
|
}
|
|
574
574
|
/** Fired per-ref after preReceive passes. */
|
|
575
|
-
interface UpdateEvent<
|
|
575
|
+
interface UpdateEvent<A = Auth> {
|
|
576
576
|
repo: GitRepo;
|
|
577
577
|
/** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
|
|
578
578
|
repoId: string;
|
|
579
579
|
update: RefUpdate;
|
|
580
|
-
/**
|
|
581
|
-
|
|
580
|
+
/** Auth context from the transport's auth provider. Always present — hooks only fire from HTTP/SSH transport. */
|
|
581
|
+
auth: A;
|
|
582
582
|
}
|
|
583
583
|
/** Fired after all ref updates succeed. */
|
|
584
|
-
interface PostReceiveEvent<
|
|
584
|
+
interface PostReceiveEvent<A = Auth> {
|
|
585
585
|
repo: GitRepo;
|
|
586
586
|
/** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
|
|
587
587
|
repoId: string;
|
|
588
588
|
updates: readonly RefUpdate[];
|
|
589
|
-
/**
|
|
590
|
-
|
|
589
|
+
/** Auth context from the transport's auth provider. Always present — hooks only fire from HTTP/SSH transport. */
|
|
590
|
+
auth: A;
|
|
591
591
|
}
|
|
592
592
|
/** Fired during ref advertisement (info/refs). */
|
|
593
|
-
interface AdvertiseRefsEvent<
|
|
593
|
+
interface AdvertiseRefsEvent<A = Auth> {
|
|
594
594
|
repo: GitRepo;
|
|
595
595
|
/** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
|
|
596
596
|
repoId: string;
|
|
597
597
|
refs: RefAdvertisement[];
|
|
598
598
|
service: "git-upload-pack" | "git-receive-pack";
|
|
599
|
-
/**
|
|
600
|
-
|
|
599
|
+
/** Auth context from the transport's auth provider. Always present — hooks only fire from HTTP/SSH transport. */
|
|
600
|
+
auth: A;
|
|
601
601
|
}
|
|
602
602
|
/** A ref name and hash advertised to clients during fetch/push discovery. */
|
|
603
603
|
interface RefAdvertisement {
|
|
@@ -649,7 +649,7 @@ interface RefUpdateResult {
|
|
|
649
649
|
* server.handleSession(command, channel, { username });
|
|
650
650
|
* ```
|
|
651
651
|
*/
|
|
652
|
-
declare function createServer<
|
|
652
|
+
declare function createServer<A = Auth>(config?: GitServerConfig<A>): GitServer;
|
|
653
653
|
/**
|
|
654
654
|
* Compose multiple hook sets into a single `ServerHooks` object.
|
|
655
655
|
*
|
|
@@ -661,7 +661,7 @@ declare function createServer<S = Session>(config?: GitServerConfig<S>): GitServ
|
|
|
661
661
|
* refs returned by the previous one. Short-circuits on `Rejection`.
|
|
662
662
|
* Returning void passes through unchanged.
|
|
663
663
|
*/
|
|
664
|
-
declare function composeHooks<
|
|
664
|
+
declare function composeHooks<A = Auth>(...hookSets: (ServerHooks<A> | undefined)[]): ServerHooks<A>;
|
|
665
665
|
|
|
666
666
|
/**
|
|
667
667
|
* Server-side Git protocol helpers.
|
|
@@ -845,7 +845,7 @@ interface AdvertiseResult {
|
|
|
845
845
|
* Both HTTP and SSH code paths use this — the caller handles the
|
|
846
846
|
* transport-specific response (HTTP 403 vs SSH exit 128).
|
|
847
847
|
*/
|
|
848
|
-
declare function advertiseRefsWithHooks<
|
|
848
|
+
declare function advertiseRefsWithHooks<A>(repo: GitRepo, repoId: string, service: "git-upload-pack" | "git-receive-pack", hooks: ServerHooks<A> | undefined, auth: A): Promise<AdvertiseResult | Rejection>;
|
|
849
849
|
interface UploadPackOptions {
|
|
850
850
|
/** Pack cache instance. When provided, full clones (no haves) are cached. */
|
|
851
851
|
cache?: PackCache;
|
|
@@ -896,12 +896,12 @@ declare function ingestReceivePackFromStream(repo: GitRepo, commands: PushComman
|
|
|
896
896
|
* {@link applyReceivePack} for the transport path.
|
|
897
897
|
*/
|
|
898
898
|
declare function applyCasRefUpdates(repo: GitRepo, updates: readonly RefUpdate[]): Promise<RefUpdateResult>;
|
|
899
|
-
interface ApplyReceivePackOptions<
|
|
899
|
+
interface ApplyReceivePackOptions<A = unknown> {
|
|
900
900
|
repo: GitRepo;
|
|
901
901
|
repoId: string;
|
|
902
902
|
ingestResult: ReceivePackResult;
|
|
903
|
-
hooks?: ServerHooks<
|
|
904
|
-
|
|
903
|
+
hooks?: ServerHooks<A>;
|
|
904
|
+
auth: A;
|
|
905
905
|
}
|
|
906
906
|
/**
|
|
907
907
|
* Run the full receive-pack lifecycle: preReceive hook, per-ref update
|
|
@@ -912,7 +912,7 @@ interface ApplyReceivePackOptions<S = unknown> {
|
|
|
912
912
|
* Does NOT handle unpack failures — the caller should check
|
|
913
913
|
* `ingestResult.unpackOk` and short-circuit before calling this.
|
|
914
914
|
*/
|
|
915
|
-
declare function applyReceivePack<
|
|
915
|
+
declare function applyReceivePack<A = unknown>(options: ApplyReceivePackOptions<A>): Promise<RefUpdateResult>;
|
|
916
916
|
/**
|
|
917
917
|
* Resolve `RefUpdateRequest[]` into fully computed `RefUpdate[]`.
|
|
918
918
|
*
|
|
@@ -926,7 +926,7 @@ declare function buildV2CapabilityAdvertisementBytes(): Uint8Array;
|
|
|
926
926
|
* then builds a v2 ls-refs response respecting the client's requested
|
|
927
927
|
* attributes (symrefs, peel, ref-prefix, unborn).
|
|
928
928
|
*/
|
|
929
|
-
declare function handleLsRefs<
|
|
929
|
+
declare function handleLsRefs<A>(repo: GitRepo, repoId: string, args: string[], hooks: ServerHooks<A> | undefined, auth: A): Promise<Uint8Array | Rejection>;
|
|
930
930
|
/**
|
|
931
931
|
* Handle a v2 `fetch` command. Parses fetch args, performs object
|
|
932
932
|
* enumeration and pack building via the shared pipeline, then
|
|
@@ -1119,4 +1119,4 @@ declare class PgStorage implements Storage {
|
|
|
1119
1119
|
atomicRefUpdate<T>(repoId: string, fn: (ops: RefOps) => Promise<T> | T): Promise<T>;
|
|
1120
1120
|
}
|
|
1121
1121
|
|
|
1122
|
-
export { type AdvertiseRefsEvent, type AdvertiseResult, type ApplyReceivePackOptions, type BetterSqlite3Database, BetterSqlite3Storage, type BunSqliteDatabase, BunSqliteStorage, type CreateRepoOptions, type GcOptions, type GcResult, GitRepo, type GitServer, type GitServerConfig, type MaybeAsync, MemoryStorage, type NodeHttpRequest, type NodeHttpResponse, type PgPool, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type PushCommand, RawObject, type RawRefEntry, type ReceivePackResult, Ref, type RefAdvertisement, type RefOps, type RefResult, type RefUpdate, type RefUpdateRequest, type RefUpdateResult, Rejection, type ServerHooks, type ServerPolicy, type
|
|
1122
|
+
export { type AdvertiseRefsEvent, type AdvertiseResult, type ApplyReceivePackOptions, type Auth, type AuthProvider, type BetterSqlite3Database, BetterSqlite3Storage, type BunSqliteDatabase, BunSqliteStorage, type CreateRepoOptions, type GcOptions, type GcResult, GitRepo, type GitServer, type GitServerConfig, type MaybeAsync, MemoryStorage, type NodeHttpRequest, type NodeHttpResponse, type PgPool, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type PushCommand, RawObject, type RawRefEntry, type ReceivePackResult, Ref, type RefAdvertisement, type RefOps, type RefResult, type RefUpdate, type RefUpdateRequest, type RefUpdateResult, Rejection, type ServerHooks, type ServerPolicy, type SshChannel, type SshSessionInfo, type Storage, type UpdateEvent, type V2CommandRequest, type V2FetchRequest, type V2FetchResponseOptions, type V2LsRefsRef, advertiseRefsWithHooks, applyCasRefUpdates, applyReceivePack, buildRefAdvertisementBytes, buildRefListBytes, buildRefListPktLines, buildV2CapabilityAdvertisement, buildV2CapabilityAdvertisementBytes, buildV2FetchResponse, buildV2LsRefsResponse, collectRefs, composeHooks, createServer, handleLsRefs, handleUploadPack, handleV2Fetch, ingestReceivePack, ingestReceivePackFromStream, parseV2CommandRequest, parseV2FetchArgs, resolveRefUpdates };
|
package/dist/server/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var ve=(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 ne="0000000000000000000000000000000000000000",At=(()=>{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 je(r){let e="";for(let t=0;t<20;t++)e+=At[r[t]];return e}function se(r,e){let t="";for(let n=0;n<20;n++)t+=At[r[e+n]];return t}function ae(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 Br=new Set(["tree","commit","tag"]),Ie=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(!Br.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 Nr=new TextEncoder;function Fe(r){return typeof r=="string"?Nr.encode(r):r}function Mr(){if(typeof globalThis.Bun<"u")return()=>{let r=new Bun.CryptoHasher("sha1"),e={update(t){return r.update(Fe(t)),e},hex:()=>Promise.resolve(r.digest("hex"))};return e};try{let r=ve(["node","crypto"].join(":"));if(typeof r.createHash=="function")return()=>{let e=r.createHash("sha1"),t={update(n){return e.update(Fe(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(Fe(t)),e},async hex(){let t=0;for(let o of r)t+=o.byteLength;let n=new Uint8Array(t),s=0;for(let o of r)n.set(o,s),s+=o.byteLength;let a=await crypto.subtle.digest("SHA-1",n);return je(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 St=Mr(),z=St;async function vt(r){return St().update(r).hex()}var B=Uint8Array,K=Uint16Array,$r=Int32Array,jt=new B([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]),It=new B([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]),Wr=new B([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Tt=(r,e)=>{let t=new K(31);for(let s=0;s<31;++s)t[s]=e+=1<<r[s-1];let n=new $r(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:Ut}=Tt(jt,2);Ut[28]=258;var{b:_r}=Tt(It,0),Ve=new K(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,Ve[r]=((e&65280)>>8|(e&255)<<8)>>1}var ie=(r,e,t)=>{let n=r.length,s=0,a=new K(e);for(;s<n;++s)r[s]&&++a[r[s]-1];let o=new K(e);for(s=1;s<e;++s)o[s]=o[s-1]+a[s-1]<<1;let i;if(t){i=new K(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=o[r[s]-1]++<<l;for(let p=d|(1<<l)-1;d<=p;++d)i[Ve[d]>>f]=c}}else for(i=new K(n),s=0;s<n;++s)r[s]&&(i[s]=Ve[o[r[s]-1]++]>>15-r[s]);return i},oe=new B(288);for(let r=0;r<144;++r)oe[r]=8;for(let r=144;r<256;++r)oe[r]=9;for(let r=256;r<280;++r)oe[r]=7;for(let r=280;r<288;++r)oe[r]=8;var Lt=new B(32);for(let r=0;r<32;++r)Lt[r]=5;var Fr=ie(oe,9,1),Gr=ie(Lt,5,1),Ge=r=>{let e=r[0];for(let t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},D=(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)},Ct=r=>(r+7)/8|0,qr=(r,e,t)=>((e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new B(r.subarray(e,t))),N=(r,e)=>{let t=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||t[r]||"unknown inflate error")},Ht=(r,e,t,n)=>{let s=r.length,a=n?n.length:0;if(!s||e.f&&!e.l)return t||new B(0);let o=!t,i=o||e.i!=2,f=e.i;o&&(t=new B(s*3));let c=y=>{let b=t.length;if(y>b){let O=new B(Math.max(b*2,y));O.set(t),t=O}},l=e.f||0,d=e.p||0,p=e.b||0,h=e.l,u=e.d,m=e.m,R=e.n,k=s*8;do{if(!h){l=D(r,d,1);let w=D(r,d+1,3);if(d+=3,w)if(w==1)h=Fr,u=Gr,m=9,R=5;else if(w==2){let g=D(r,d,31)+257,E=D(r,d+10,15)+4,P=g+D(r,d+5,31)+1;d+=14;let S=new B(P),A=new B(19);for(let M=0;M<E;++M)A[Wr[M]]=D(r,d+M*3,7);d+=E*3;let j=Ge(A),I=(1<<j)-1,T=ie(A,j,1);for(let M=0;M<P;){let kt=T[D(r,d,I)];d+=kt&15;let re=kt>>4;if(re<16)S[M++]=re;else{let Pt=0,Se=0;for(re==16?(Se=3+D(r,d,3),d+=2,Pt=S[M-1]):re==17?(Se=3+D(r,d,7),d+=3):re==18&&(Se=11+D(r,d,127),d+=7);Se--;)S[M++]=Pt}}let $=S.subarray(0,g),W=S.subarray(g);m=Ge($),R=Ge(W),h=ie($,m,1),u=ie(W,R,1)}else N(1);else{let g=Ct(d)+4,E=r[g-4]|r[g-3]<<8,P=g+E;if(P>s){f&&N(0);break}i&&c(p+E),t.set(r.subarray(g,P),p),e.b=p+=E,e.p=d=P*8,e.f=l;continue}if(d>k){f&&N(0);break}}i&&c(p+131072);let y=(1<<m)-1,b=(1<<R)-1,O=d;for(;;O=d){let w=h[qe(r,d)&y],g=w>>4;if(d+=w&15,d>k){f&&N(0);break}if(w||N(2),g<256)t[p++]=g;else if(g==256){O=d,h=null;break}else{let E=g-254;if(g>264){let I=g-257,T=jt[I];E=D(r,d,(1<<T)-1)+Ut[I],d+=T}let P=u[qe(r,d)&b],S=P>>4;P||N(3),d+=P&15;let A=_r[S];if(S>3){let I=It[S];A+=qe(r,d)&(1<<I)-1,d+=I}if(d>k){f&&N(0);break}i&&c(p+131072);let j=p+E;if(p<A){let I=a-A,T=Math.min(A,j);for(I+p<0&&N(3);p<T;++p)t[p]=n[I+p]}for(;p<j;++p)t[p]=t[p-A]}}e.l=h,e.p=O,e.b=p,e.f=l,h&&(l=1,e.m=m,e.d=u,e.n=R)}while(!l);return p!=t.length&&o?qr(t,0,p):t.subarray(0,p)},Dt=r=>(((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&N(0,"invalid zlib data"),r[1]&32&&N(0,"zlib dictionaries are not supported"),2);function Bt(r){let e=Dt(r);return Ht(r.subarray(e,-4),{i:2})}function ze(r){let e=Dt(r),t={i:2},n=Ht(r.subarray(e),t),s=Ct(t.p);return{result:n,bytesConsumed:e+s+4}}async function Vr(){let r;if(!(typeof document<"u"))try{r=ve(["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 o=r.inflateSync(a,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(r.deflateSync(s)),inflateSync:s=>new Uint8Array(r.inflateSync(s)),inflateWithConsumed:n??ze}}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:Bt,inflateWithConsumed:ze}}var zr=null;function Nt(){return zr??=Vr()}async function Te(r){return await(await Nt()).deflateSync(r)}async function Ke(r,e){let t=await Nt(),{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 Y=1346454347,Le=2,Wt=1,_t=2,Ft=3,Gt=4,_=6,ce=7,qt={[Wt]:"commit",[_t]:"tree",[Ft]:"blob",[Gt]:"tag"},Vt={commit:Wt,tree:_t,blob:Ft,tag:Gt};async function zt(r,e){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.getUint32(0);if(n!==Y)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${Y.toString(16)})`);let s=t.getUint32(4);if(s!==Le)throw new Error(`Unsupported pack version: ${s}`);if(r.byteLength>=32){let c=se(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),o=[],i=12;for(let c=0;c<a;c++){let l=await Kr(r,i);o.push(l),i=l.nextOffset}return(await Xr(o,e)).map((c,l)=>({...c,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function Kr(r,e){let t=e,n=r[e++],s=n>>4&7,a=n&15,o=4;for(;n&128;)n=r[e++],a|=(n&127)<<o,o+=7;let i,f;if(s===_){let d=r[e++];for(i=d&127;d&128;)i+=1,d=r[e++],i=(i<<7)+(d&127);i=t-i}else s===ce&&(f=se(r,e),e+=20);let{result:c,bytesConsumed:l}=await Ke(r.subarray(e),a);return{headerOffset:t,typeNum:s,inflated:c,baseOffset:i,baseHash:f,nextOffset:e+l}}var Mt=50;async function Xr(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,o=0){if(o>Mt)throw new Error(`delta chain depth ${o} exceeds limit of ${Mt}`);let i=n[a];if(i)return i;let f=r[a];if(f.typeNum!==_&&f.typeNum!==ce){let h=qt[f.typeNum];if(!h)throw new Error(`Unknown object type: ${f.typeNum}`);let u={type:h,content:f.inflated,hash:await X(h,f.inflated)};return n[a]=u,u}if(f.typeNum===_){let h=t.get(f.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${f.baseOffset}`);let u=await s(h,o+1),m=Ue(u.content,f.inflated),R={type:u.type,content:m,hash:await X(u.type,m)};return n[a]=R,R}let c=await Yr(r,n,f.baseHash,s),l;if(c!==void 0)l=await s(c,o+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=Ue(l.content,f.inflated),p={type:l.type,content:d,hash:await X(l.type,d)};return n[a]=p,p}for(let a=0;a<r.length;a++)await s(a);return n}async function Yr(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!==_&&a.typeNum!==ce&&(await n(s)).hash===t)return s}}var Xe=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 Ke(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*Kt(r,e){let t=new Xe(r,!0),n=await t.readExact(12),s=new DataView(n.buffer,n.byteOffset,n.byteLength),a=s.getUint32(0);if(a!==Y)throw new Error(`Invalid pack signature: 0x${a.toString(16)} (expected 0x${Y.toString(16)})`);let o=s.getUint32(4);if(o!==Le)throw new Error(`Unsupported pack version: ${o}`);let i=s.getUint32(8),f=new Map,c=new Map;for(let p=0;p<i;p++){let h=t.bytesRead,u=await t.readByte(),m=u>>4&7,R=u&15,k=4;for(;u&128;)u=await t.readByte(),R|=(u&127)<<k,k+=7;let y,b;if(m===_){let g=await t.readByte();for(y=g&127;g&128;)y+=1,g=await t.readByte(),y=(y<<7)+(g&127);y=h-y}else if(m===ce){let g=await t.readExact(20);b=se(g,0)}let O=await t.inflateNext(R),w;if(m!==_&&m!==ce){let g=qt[m];if(!g)throw new Error(`Unknown object type: ${m}`);w={type:g,content:O,hash:await X(g,O)}}else if(m===_){let g=f.get(y);if(!g)throw new Error(`OFS_DELTA base not found at offset ${y}`);let E=Ue(g.content,O);w={type:g.type,content:E,hash:await X(g.type,E)}}else{let g=c.get(b);if(!g&&e&&(g=await e(b)??void 0),!g)throw new Error(`REF_DELTA base not found for hash ${b}`);let E=Ue(g.content,O);w={type:g.type,content:E,hash:await X(g.type,E)}}f.set(h,w),c.set(w.hash,w),yield w}let l=se(await t.readRaw(20),0),d=await t.hashHex();if(d!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${d}`)}function Ue(r,e){let t=0,{value:n,newPos:s}=$t(e,t);if(t=s,n!==r.byteLength)throw new Error(`Delta base size mismatch: expected ${n}, got ${r.byteLength}`);let{value:a,newPos:o}=$t(e,t);t=o;let i=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),i.set(r.subarray(l,l+d),f),f+=d}else if(c>0)i.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 i}async function Z(r){let e=[],t=new Map,n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,Y),s.setUint32(4,Le),s.setUint32(8,r.length),e.push(n);let a=12,o=[];for(let i of r){let f=a;t.set(i.hash,a);let c=i.delta&&i.deltaBaseHash?t.get(i.deltaBaseHash):void 0;if(i.delta&&c!==void 0){let l=Ye(_,i.delta.byteLength),d=Jr(a-c),p=await Te(i.delta);e.push(l,d,p),a+=l.byteLength+d.byteLength+p.byteLength}else{let l=Vt[i.type],d=Ye(l,i.content.byteLength),p=await Te(i.content);e.push(d,p),a+=d.byteLength+p.byteLength}o.push({hash:i.hash,offset:f,nextOffset:a})}return{data:await Zr(e),entries:o}}async function*Xt(r,e){let t=z(),n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,Y),s.setUint32(4,Le),s.setUint32(8,r),t.update(n),yield n;for await(let a of e){let o=Vt[a.type],i=Ye(o,a.content.byteLength),f=await Te(a.content);t.update(i),t.update(f),yield Qr(i,f)}yield ae(await t.hex())}async function Zr(r){let e=0;for(let o of r)e+=o.byteLength;e+=20;let t=new Uint8Array(e),n=0;for(let o of r)t.set(o,n),n+=o.byteLength;let s=z();s.update(t.subarray(0,n));let a=await s.hex();return t.set(ae(a),n),t}function Jr(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 Ye(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 $t(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 Qr(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(r,0),t.set(e,r.byteLength),t}var en=new TextEncoder;async function X(r,e){let t=en.encode(`${r} ${e.byteLength}\0`),n=z();return n.update(t),n.update(e),n.hex()}var tn=new TextEncoder,ps=new TextDecoder;function Yt(r,e){let t=tn.encode(`${r} ${e.byteLength}\0`),n=new Uint8Array(t.byteLength+e.byteLength);return n.set(t),n.set(e,t.byteLength),n}function fe(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),[o="0",i="+0000"]=a.split(" "),f=parseInt(o,10);return{name:n,email:s,timestamp:f,timezone:i}}function Ce(r){return`${r.name} <${r.email}> ${r.timestamp} ${r.timezone}`}var rn=new TextEncoder,nn=new TextDecoder;function le(r){let e=nn.decode(r),t=e.indexOf(`
|
|
1
|
+
var je=(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 ne="0000000000000000000000000000000000000000",Pt=(()=>{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 Se(r){let e="";for(let t=0;t<20;t++)e+=Pt[r[t]];return e}function se(r,e){let t="";for(let n=0;n<20;n++)t+=Pt[r[e+n]];return t}function ae(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 Nr=new Set(["tree","commit","tag"]),Ie=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(!Nr.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 Br=new TextEncoder;function Fe(r){return typeof r=="string"?Br.encode(r):r}function Mr(){if(typeof globalThis.Bun<"u")return()=>{let r=new Bun.CryptoHasher("sha1"),e={update(t){return r.update(Fe(t)),e},hex:()=>Promise.resolve(r.digest("hex"))};return e};try{let r=je(["node","crypto"].join(":"));if(typeof r.createHash=="function")return()=>{let e=r.createHash("sha1"),t={update(n){return e.update(Fe(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(Fe(t)),e},async hex(){let t=0;for(let o of r)t+=o.byteLength;let n=new Uint8Array(t),s=0;for(let o of r)n.set(o,s),s+=o.byteLength;let a=await crypto.subtle.digest("SHA-1",n);return Se(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 vt=Mr(),z=vt;async function jt(r){return vt().update(r).hex()}var N=Uint8Array,K=Uint16Array,$r=Int32Array,St=new N([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]),It=new N([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]),Wr=new N([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Tt=(r,e)=>{let t=new K(31);for(let s=0;s<31;++s)t[s]=e+=1<<r[s-1];let n=new $r(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:Ut}=Tt(St,2);Ut[28]=258;var{b:_r}=Tt(It,0),Ve=new K(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,Ve[r]=((e&65280)>>8|(e&255)<<8)>>1}var ie=(r,e,t)=>{let n=r.length,s=0,a=new K(e);for(;s<n;++s)r[s]&&++a[r[s]-1];let o=new K(e);for(s=1;s<e;++s)o[s]=o[s-1]+a[s-1]<<1;let i;if(t){i=new K(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=o[r[s]-1]++<<l;for(let u=d|(1<<l)-1;d<=u;++d)i[Ve[d]>>f]=c}}else for(i=new K(n),s=0;s<n;++s)r[s]&&(i[s]=Ve[o[r[s]-1]++]>>15-r[s]);return i},oe=new N(288);for(let r=0;r<144;++r)oe[r]=8;for(let r=144;r<256;++r)oe[r]=9;for(let r=256;r<280;++r)oe[r]=7;for(let r=280;r<288;++r)oe[r]=8;var Lt=new N(32);for(let r=0;r<32;++r)Lt[r]=5;var Fr=ie(oe,9,1),Gr=ie(Lt,5,1),Ge=r=>{let e=r[0];for(let t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},D=(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)},Ct=r=>(r+7)/8|0,qr=(r,e,t)=>((e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new N(r.subarray(e,t))),B=(r,e)=>{let t=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||t[r]||"unknown inflate error")},Ht=(r,e,t,n)=>{let s=r.length,a=n?n.length:0;if(!s||e.f&&!e.l)return t||new N(0);let o=!t,i=o||e.i!=2,f=e.i;o&&(t=new N(s*3));let c=y=>{let b=t.length;if(y>b){let A=new N(Math.max(b*2,y));A.set(t),t=A}},l=e.f||0,d=e.p||0,u=e.b||0,h=e.l,p=e.d,m=e.m,R=e.n,E=s*8;do{if(!h){l=D(r,d,1);let w=D(r,d+1,3);if(d+=3,w)if(w==1)h=Fr,p=Gr,m=9,R=5;else if(w==2){let g=D(r,d,31)+257,O=D(r,d+10,15)+4,k=g+D(r,d+5,31)+1;d+=14;let P=new N(k),j=new N(19);for(let M=0;M<O;++M)j[Wr[M]]=D(r,d+M*3,7);d+=O*3;let S=Ge(j),I=(1<<S)-1,T=ie(j,S,1);for(let M=0;M<k;){let Et=T[D(r,d,I)];d+=Et&15;let re=Et>>4;if(re<16)P[M++]=re;else{let kt=0,ve=0;for(re==16?(ve=3+D(r,d,3),d+=2,kt=P[M-1]):re==17?(ve=3+D(r,d,7),d+=3):re==18&&(ve=11+D(r,d,127),d+=7);ve--;)P[M++]=kt}}let $=P.subarray(0,g),W=P.subarray(g);m=Ge($),R=Ge(W),h=ie($,m,1),p=ie(W,R,1)}else B(1);else{let g=Ct(d)+4,O=r[g-4]|r[g-3]<<8,k=g+O;if(k>s){f&&B(0);break}i&&c(u+O),t.set(r.subarray(g,k),u),e.b=u+=O,e.p=d=k*8,e.f=l;continue}if(d>E){f&&B(0);break}}i&&c(u+131072);let y=(1<<m)-1,b=(1<<R)-1,A=d;for(;;A=d){let w=h[qe(r,d)&y],g=w>>4;if(d+=w&15,d>E){f&&B(0);break}if(w||B(2),g<256)t[u++]=g;else if(g==256){A=d,h=null;break}else{let O=g-254;if(g>264){let I=g-257,T=St[I];O=D(r,d,(1<<T)-1)+Ut[I],d+=T}let k=p[qe(r,d)&b],P=k>>4;k||B(3),d+=k&15;let j=_r[P];if(P>3){let I=It[P];j+=qe(r,d)&(1<<I)-1,d+=I}if(d>E){f&&B(0);break}i&&c(u+131072);let S=u+O;if(u<j){let I=a-j,T=Math.min(j,S);for(I+u<0&&B(3);u<T;++u)t[u]=n[I+u]}for(;u<S;++u)t[u]=t[u-j]}}e.l=h,e.p=A,e.b=u,e.f=l,h&&(l=1,e.m=m,e.d=p,e.n=R)}while(!l);return u!=t.length&&o?qr(t,0,u):t.subarray(0,u)},Dt=r=>(((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&B(0,"invalid zlib data"),r[1]&32&&B(0,"zlib dictionaries are not supported"),2);function Nt(r){let e=Dt(r);return Ht(r.subarray(e,-4),{i:2})}function ze(r){let e=Dt(r),t={i:2},n=Ht(r.subarray(e),t),s=Ct(t.p);return{result:n,bytesConsumed:e+s+4}}async function Vr(){let r;if(!(typeof document<"u"))try{r=je(["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 o=r.inflateSync(a,{info:!0});return{result:new Uint8Array(o.buffer),bytesConsumed:o.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(r.deflateSync(s)),inflateSync:s=>new Uint8Array(r.inflateSync(s)),inflateWithConsumed:n??ze}}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:Nt,inflateWithConsumed:ze}}var zr=null;function Bt(){return zr??=Vr()}async function Te(r){return await(await Bt()).deflateSync(r)}async function Ke(r,e){let t=await Bt(),{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 Y=1346454347,Le=2,Wt=1,_t=2,Ft=3,Gt=4,_=6,ce=7,qt={[Wt]:"commit",[_t]:"tree",[Ft]:"blob",[Gt]:"tag"},Vt={commit:Wt,tree:_t,blob:Ft,tag:Gt};async function zt(r,e){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.getUint32(0);if(n!==Y)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${Y.toString(16)})`);let s=t.getUint32(4);if(s!==Le)throw new Error(`Unsupported pack version: ${s}`);if(r.byteLength>=32){let c=se(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),o=[],i=12;for(let c=0;c<a;c++){let l=await Kr(r,i);o.push(l),i=l.nextOffset}return(await Xr(o,e)).map((c,l)=>({...c,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function Kr(r,e){let t=e,n=r[e++],s=n>>4&7,a=n&15,o=4;for(;n&128;)n=r[e++],a|=(n&127)<<o,o+=7;let i,f;if(s===_){let d=r[e++];for(i=d&127;d&128;)i+=1,d=r[e++],i=(i<<7)+(d&127);i=t-i}else s===ce&&(f=se(r,e),e+=20);let{result:c,bytesConsumed:l}=await Ke(r.subarray(e),a);return{headerOffset:t,typeNum:s,inflated:c,baseOffset:i,baseHash:f,nextOffset:e+l}}var Mt=50;async function Xr(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,o=0){if(o>Mt)throw new Error(`delta chain depth ${o} exceeds limit of ${Mt}`);let i=n[a];if(i)return i;let f=r[a];if(f.typeNum!==_&&f.typeNum!==ce){let h=qt[f.typeNum];if(!h)throw new Error(`Unknown object type: ${f.typeNum}`);let p={type:h,content:f.inflated,hash:await X(h,f.inflated)};return n[a]=p,p}if(f.typeNum===_){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,o+1),m=Ue(p.content,f.inflated),R={type:p.type,content:m,hash:await X(p.type,m)};return n[a]=R,R}let c=await Yr(r,n,f.baseHash,s),l;if(c!==void 0)l=await s(c,o+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=Ue(l.content,f.inflated),u={type:l.type,content:d,hash:await X(l.type,d)};return n[a]=u,u}for(let a=0;a<r.length;a++)await s(a);return n}async function Yr(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!==_&&a.typeNum!==ce&&(await n(s)).hash===t)return s}}var Xe=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 Ke(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*Kt(r,e){let t=new Xe(r,!0),n=await t.readExact(12),s=new DataView(n.buffer,n.byteOffset,n.byteLength),a=s.getUint32(0);if(a!==Y)throw new Error(`Invalid pack signature: 0x${a.toString(16)} (expected 0x${Y.toString(16)})`);let o=s.getUint32(4);if(o!==Le)throw new Error(`Unsupported pack version: ${o}`);let i=s.getUint32(8),f=new Map,c=new Map;for(let u=0;u<i;u++){let h=t.bytesRead,p=await t.readByte(),m=p>>4&7,R=p&15,E=4;for(;p&128;)p=await t.readByte(),R|=(p&127)<<E,E+=7;let y,b;if(m===_){let g=await t.readByte();for(y=g&127;g&128;)y+=1,g=await t.readByte(),y=(y<<7)+(g&127);y=h-y}else if(m===ce){let g=await t.readExact(20);b=se(g,0)}let A=await t.inflateNext(R),w;if(m!==_&&m!==ce){let g=qt[m];if(!g)throw new Error(`Unknown object type: ${m}`);w={type:g,content:A,hash:await X(g,A)}}else if(m===_){let g=f.get(y);if(!g)throw new Error(`OFS_DELTA base not found at offset ${y}`);let O=Ue(g.content,A);w={type:g.type,content:O,hash:await X(g.type,O)}}else{let g=c.get(b);if(!g&&e&&(g=await e(b)??void 0),!g)throw new Error(`REF_DELTA base not found for hash ${b}`);let O=Ue(g.content,A);w={type:g.type,content:O,hash:await X(g.type,O)}}f.set(h,w),c.set(w.hash,w),yield w}let l=se(await t.readRaw(20),0),d=await t.hashHex();if(d!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${d}`)}function Ue(r,e){let t=0,{value:n,newPos:s}=$t(e,t);if(t=s,n!==r.byteLength)throw new Error(`Delta base size mismatch: expected ${n}, got ${r.byteLength}`);let{value:a,newPos:o}=$t(e,t);t=o;let i=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),i.set(r.subarray(l,l+d),f),f+=d}else if(c>0)i.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 i}async function Z(r){let e=[],t=new Map,n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,Y),s.setUint32(4,Le),s.setUint32(8,r.length),e.push(n);let a=12,o=[];for(let i of r){let f=a;t.set(i.hash,a);let c=i.delta&&i.deltaBaseHash?t.get(i.deltaBaseHash):void 0;if(i.delta&&c!==void 0){let l=Ye(_,i.delta.byteLength),d=Jr(a-c),u=await Te(i.delta);e.push(l,d,u),a+=l.byteLength+d.byteLength+u.byteLength}else{let l=Vt[i.type],d=Ye(l,i.content.byteLength),u=await Te(i.content);e.push(d,u),a+=d.byteLength+u.byteLength}o.push({hash:i.hash,offset:f,nextOffset:a})}return{data:await Zr(e),entries:o}}async function*Xt(r,e){let t=z(),n=new Uint8Array(12),s=new DataView(n.buffer);s.setUint32(0,Y),s.setUint32(4,Le),s.setUint32(8,r),t.update(n),yield n;for await(let a of e){let o=Vt[a.type],i=Ye(o,a.content.byteLength),f=await Te(a.content);t.update(i),t.update(f),yield Qr(i,f)}yield ae(await t.hex())}async function Zr(r){let e=0;for(let o of r)e+=o.byteLength;e+=20;let t=new Uint8Array(e),n=0;for(let o of r)t.set(o,n),n+=o.byteLength;let s=z();s.update(t.subarray(0,n));let a=await s.hex();return t.set(ae(a),n),t}function Jr(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 Ye(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 $t(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 Qr(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(r,0),t.set(e,r.byteLength),t}var en=new TextEncoder;async function X(r,e){let t=en.encode(`${r} ${e.byteLength}\0`),n=z();return n.update(t),n.update(e),n.hex()}var tn=new TextEncoder,us=new TextDecoder;function Yt(r,e){let t=tn.encode(`${r} ${e.byteLength}\0`),n=new Uint8Array(t.byteLength+e.byteLength);return n.set(t),n.set(e,t.byteLength),n}function fe(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),[o="0",i="+0000"]=a.split(" "),f=parseInt(o,10);return{name:n,email:s,timestamp:f,timezone:i}}function Ce(r){return`${r.name} <${r.email}> ${r.timestamp} ${r.timezone}`}var rn=new TextEncoder,nn=new TextDecoder;function le(r){let e=nn.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="",o=[],i,f;for(let c of n.split(`
|
|
4
|
-
`)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),
|
|
4
|
+
`)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),u=c.slice(l+1);switch(d){case"tree":a=u;break;case"parent":o.push(u);break;case"author":i=fe(u);break;case"committer":f=fe(u);break}}if(!a)throw new Error("Commit missing tree field");if(!i)throw new Error("Commit missing author field");if(!f)throw new Error("Commit missing committer field");return{type:"commit",tree:a,parents:o,author:i,committer:f,message:s}}function Zt(r){let e=[];e.push(`tree ${r.tree}`);for(let t of r.parents)e.push(`parent ${t}`);return e.push(`author ${Ce(r.author)}`),e.push(`committer ${Ce(r.committer)}`),e.push(""),e.push(r.message),rn.encode(e.join(`
|
|
5
5
|
`))}var gs=new TextEncoder,sn=new TextDecoder;function J(r){let e=sn.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="",o="commit",i="",f;for(let c of n.split(`
|
|
8
|
-
`)){let l=c.indexOf(" ");if(l===-1)continue;let d=c.slice(0,l),p=c.slice(l+1);switch(d){case"object":a=p;break;case"type":o=p;break;case"tag":i=p;break;case"tagger":f=fe(p);break}}if(!a)throw new Error("Tag missing object field");if(!i)throw new Error("Tag missing tag name field");if(!f)throw new Error("Tag missing tagger field");return{type:"tag",object:a,objectType:o,name:i,tagger:f,message:s}}async function He(r,e,t){let n=await r.objectStore.write(e,t);return r.hooks?.onObjectWrite?.({repo:r,type:e,hash:n}),n}async function q(r,e){return r.objectStore.read(e)}async function de(r,e){return r.objectStore.exists(e)}var xs=new TextDecoder;async function F(r,e){let t=await q(r,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return le(t.content)}var an=new TextEncoder,Jt=new TextDecoder,on=new Set(["100644","100755","040000","120000","160000"]);function cn(r){return r.length===4&&r.toLowerCase()===".git"}function fn(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(cn(r))throw new Error(`invalid tree entry: '${r}'`);if(!on.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${r}'`)}function pe(r){let e=[],t=0;for(;t<r.byteLength;){let n=r.indexOf(32,t);if(n===-1)break;let s=Jt.decode(r.subarray(t,n)),a=r.indexOf(0,n+1);if(a===-1)break;let o=Jt.decode(r.subarray(n+1,a)),i=r.subarray(a+1,a+21),f=je(i),c=s.padStart(6,"0");fn(o,c),e.push({mode:c,name:o,hash:f}),t=a+21}return{type:"tree",entries:e}}function Qt(r){let e=[];for(let a of r.entries){let o=a.mode.replace(/^0+/,""),i=an.encode(`${o} ${a.name}\0`),f=ae(a.hash);e.push(i),e.push(f)}let t=e.reduce((a,o)=>a+o.byteLength,0),n=new Uint8Array(t),s=0;for(let a of e)n.set(a,s),s+=a.byteLength;return n}function er(r){return typeof r=="string"?{type:"direct",hash:r}:r}var Ze=".lock";var ln=[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 dn(r,e,t){let n=0,s=!1,a=e;for(;a<r.length;a++){let i=r.charCodeAt(a);switch(i<128?ln[i]:0){case 1:break;case 2:if(n===46)return{len:-1,starConsumed:s};n=i;continue;case 3:if(n===64)return{len:-1,starConsumed:s};n=i;continue;case 4:return{len:-1,starConsumed:s};case 5:if(!t)return{len:-1,starConsumed:s};s=!0,n=i;continue;default:n=i;continue}break}let o=a-e;return o===0?{len:0,starConsumed:s}:r.charCodeAt(e)===46?{len:-1,starConsumed:s}:o>=Ze.length&&r.slice(a-Ze.length,a)===Ze?{len:-1,starConsumed:s}:{len:o,starConsumed:s}}function Je(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:o}=dn(r,t,s);if(a<0||a===0)return!1;o&&(s=!1),n++,t+=a+1}return!(r.charCodeAt(r.length-1)===46||!(e&1)&&n<2)}var pn=10;async function un(r,e){return r.refStore.readRef(e)}async function ue(r,e){let t=e;for(let n=0;n<pn;n++){let s=await un(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 hn(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 tr(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:hn(e.getTimezoneOffset())}}async function nr(r,e){let t=e.branch?`refs/heads/${e.branch}`:null,n=t?await ue(r,t):null,s=null;n&&(s=(await F(r,n)).tree);let a=[];for(let[p,h]of Object.entries(e.files))if(h===null)a.push({path:p,hash:null});else{let u=typeof h=="string"?new TextEncoder().encode(h):h,m=await He(r,"blob",u);a.push({path:p,hash:m})}let o;s?o=await yn(r,s,a):o=await et(r,null,Qe(a));let i=tr(e.author),f=e.committer?tr(e.committer):i,l=Zt({type:"commit",tree:o,parents:n?[n]:[],author:i,committer:f,message:e.message});return{hash:await He(r,"commit",l),parentHash:n}}async function yn(r,e,t){return et(r,e,Qe(t))}function Qe(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),o=n.path.slice(s+1),i=t.get(a);i||(i=[],t.set(a,i)),i.push({...n,path:o})}}return{files:e,dirs:t}}async function rr(r,e){let t=await q(r,e);if(t.type!=="tree")throw new Error(`Expected tree object, got ${t.type}`);return pe(t.content).entries}async function et(r,e,t){let n=new Map;if(e)for(let o of await rr(r,e))n.set(o.name,o);for(let[o,{hash:i,mode:f}]of t.files)i===null?n.delete(o):n.set(o,{name:o,hash:i,mode:f});for(let[o,i]of t.dirs){let f=n.get(o),c=f?.mode==="040000"?f.hash:null,l=Qe(i),d=await et(r,c,l);(await rr(r,d)).length===0?n.delete(o):n.set(o,{name:o,hash:d,mode:"040000"})}let s=[...n.values()].sort((o,i)=>{let f=o.mode==="040000"?`${o.name}/`:o.name,c=i.mode==="040000"?`${i.name}/`:i.name;return f<c?-1:f>c?1:0}),a=Qt({type:"tree",entries:s});return He(r,"tree",a)}async function tt(r,e,t){if(e===t)return!0;let n=new Set,s=[t],a=0;for(;a<s.length;){let o=s[a++];if(o===e)return!0;if(n.has(o))continue;n.add(o);let i;try{i=await F(r,o)}catch{continue}for(let f of i.parents)n.has(f)||s.push(f)}return!1}var Be=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]),mn=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]),De=64,bn=4,rt=4096,sr=65536,gn=127;function wn(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=xn(n);let s=n-1,a=new Uint32Array(n),o=[],i=-1>>>0;for(let p=t*16-16;p>=0;p-=16){let h=0;for(let u=1;u<=16;u++)h=(h<<8|r[p+u])^Be[h>>>23];if(h=h>>>0,h===i)o[o.length-1].ptr=p+16;else{i=h;let u=h&s;o.push({ptr:p+16,val:h}),a[u]++}}let f=new Map;for(let p of o){let h=p.val&s,u=f.get(h);u||(u=[],f.set(h,u)),u.push(p)}for(let[p,h]of f){if(h.length<=De)continue;let u=[],m=h.length/De;for(let R=0;R<De;R++)u.push(h[Math.floor(R*m)]);f.set(p,u),a[p]=De}let c=new Uint32Array(n+1),l=[],d=0;for(let p=0;p<n;p++){c[p]=d;let h=f.get(p);if(h){for(let u of h)l.push(u);d+=h.length}}return c[n]=d,{src:r,hashMask:s,buckets:c,entries:l}}function Rn(r,e,t){if(!r||e.byteLength===0)return null;let n=r.src.byteLength,s=e.byteLength,a=r.src,o=new Uint8Array(Math.max(s,1024)),i=0;function f(m){for(;i+m>o.length;){let R=new Uint8Array(o.length*2);R.set(o),o=R}}i=ir(o,i,n),i=ir(o,i,s),f(18),i++;let c=0,l=0,d=Math.min(16,s);for(let m=0;m<d;m++)o[i++]=e[m],c=(c<<8|e[m])^Be[c>>>23],l++;c=c>>>0;let p=d,h=0,u=0;for(;p<s;){if(u<rt){c^=mn[e[p-16]],c=((c<<8|e[p])^Be[c>>>23])>>>0;let m=c&r.hashMask,R=r.buckets[m],k=r.buckets[m+1];for(let y=R;y<k;y++){let b=r.entries[y];if(b.val!==c)continue;let O=b.ptr,w=a.byteLength-O,g=s-p;if(w>g&&(w=g),w<=u)break;let E=0;for(;E<w&&a[O+E]===e[p+E];)E++;if(E>u&&(u=E,h=O,u>=rt))break}}if(u<bn)f(2),l===0&&i++,o[i++]=e[p++],l++,l===gn&&(o[i-l-1]=l,l=0),u=0;else{if(l>0){for(;h>0&&a[h-1]===e[p-1];)if(u++,h--,p--,i--,!(--l>0)){i--,l=-1;break}l>0&&(o[i-l-1]=l),l=0}let m=u>sr?u-sr:0;u-=m,f(8);let R=i++,k=128;if(h&255&&(o[i++]=h&255,k|=1),h&65280&&(o[i++]=h>>>8&255,k|=2),h&16711680&&(o[i++]=h>>>16&255,k|=4),h&4278190080&&(o[i++]=h>>>24&255,k|=8),u&255&&(o[i++]=u&255,k|=16),u&65280&&(o[i++]=u>>>8&255,k|=32),o[R]=k,p+=u,h+=u,u=m,h>4294967295&&(u=0),u<rt){c=0;for(let y=-16;y<0;y++)c=(c<<8|e[p+y])^Be[c>>>23];c=c>>>0}}if(t&&i>t)return null}return l>0&&(o[i-l-1]=l),t&&i>t?null:o.subarray(0,i)}var ar={blob:0,tree:1,commit:2,tag:3};function or(r,e){let t=e?.window??10,n=e?.depth??50,s=r.slice().sort((c,l)=>{let d=ar[c.type]??99,p=ar[l.type]??99;return d!==p?d-p:l.content.byteLength-c.content.byteLength}),a=new Map,o=[],i=[],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},p=null,h=null,u=Math.max(0,c-t);for(let m=c-1;m>=u;m--){let R=s[m];if(R.type!==l.type||(a.get(R.hash)?.depth??0)>=n||l.content.byteLength<R.content.byteLength>>>5)continue;let b=i[m-u]??null;if(!b)continue;let O=p?p.byteLength:l.content.byteLength/2|0;if(O<16)continue;let w=Rn(b,l.content,O);w&&(!p||w.byteLength<p.byteLength)&&(p=w,h=R.hash)}if(p&&h){d.delta=p,d.deltaBase=h;let m=a.get(h);d.depth=(m?.depth??0)+1}a.set(l.hash,d),o.push(d),i.length>=t&&(i.shift(),f.shift()),i.push(wn(l.content)),f.push(l.hash)}return o}function xn(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 ir(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 On=2147483647;async function nt(r,e,t,n){if(t>=On)return{shallow:[],unshallow:[...n]};let s=new Map,a=[];for(let c of e)!s.has(c)&&await de(r,c)&&(s.set(c,1),a.push({hash:c,level:1}));let o=new Set,i=0;for(;i<a.length;){let{hash:c,level:l}=a[i++];if(l>=t){o.add(c);continue}let d;try{d=await F(r,c)}catch{continue}for(let p of d.parents)!s.has(p)&&await de(r,p)&&(s.set(p,l+1),a.push({hash:p,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:[...o],unshallow:f}}async function me(r,e,t,n,s){let a=s??n,o=new Set;for(let l of t)await he(r,l,o,a);let i=[...e];if(s&&n)for(let l of s)try{let d=await F(r,l);for(let p of d.parents)o.has(p)||i.push(p)}catch{}let f=[],c=new Set;for(let l of i)await ye(r,l,o,c,f,n);return{count:f.length,objects:En(f)}}async function cr(r,e,t,n,s){let{count:a,objects:o}=await me(r,e,t,n,s);return{count:a,objects:kn(r,o)}}async function*En(r){for(let e of r)yield e}async function*kn(r,e){for await(let t of e){let n=await q(r,t.hash);yield{hash:t.hash,type:t.type,content:n.content}}}async function fr(r){let e=[];for await(let t of r.objects)e.push(t);return e}async function he(r,e,t,n){if(t.has(e)||(t.add(e),!await de(r,e)))return;let s=await q(r,e);switch(s.type){case"commit":{let a=le(s.content);if(await he(r,a.tree,t,n),!n?.has(e))for(let o of a.parents)await he(r,o,t,n);break}case"tree":{let a=pe(s.content);for(let o of a.entries)await he(r,o.hash,t,n);break}case"tag":{let a=J(s.content);await he(r,a.object,t,n);break}case"blob":break}}async function ye(r,e,t,n,s,a){if(n.has(e)||t.has(e))return;n.add(e);let o=await q(r,e);switch(s.push({hash:e,type:o.type}),o.type){case"commit":{let i=le(o.content);if(await ye(r,i.tree,t,n,s,a),!a?.has(e))for(let f of i.parents)await ye(r,f,t,n,s,a);break}case"tree":{let i=pe(o.content);for(let f of i.entries)await ye(r,f.hash,t,n,s,a);break}case"tag":{let i=J(o.content);await ye(r,i.object,t,n,s,a);break}case"blob":break}}var Pn=new TextEncoder,dr=new TextDecoder,lr=65520,An=new Uint8Array([48,48,48,48]),Sn=new Uint8Array([48,48,48,49]),Fs=new Uint8Array([48,48,48,50]);function x(r){let e=typeof r=="string"?Pn.encode(r):r,t=4+e.byteLength;if(t>lr)throw new Error(`pkt-line too long: ${t} bytes (max ${lr})`);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 H(){return An.slice()}function V(){return Sn.slice()}function L(...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 st(r){let e=[],t=0;for(;t<r.byteLength;){if(t+4>r.byteLength)throw new Error("Truncated pkt-line header");let n=dr.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 at(r){if(r.type!=="data")return"";let e=dr.decode(r.data);return e.endsWith(`
|
|
9
|
-
`)?e.slice(0,-1):e}var
|
|
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":o=u;break;case"tag":i=u;break;case"tagger":f=fe(u);break}}if(!a)throw new Error("Tag missing object field");if(!i)throw new Error("Tag missing tag name field");if(!f)throw new Error("Tag missing tagger field");return{type:"tag",object:a,objectType:o,name:i,tagger:f,message:s}}async function He(r,e,t){let n=await r.objectStore.write(e,t);return r.hooks?.onObjectWrite?.({repo:r,type:e,hash:n}),n}async function q(r,e){return r.objectStore.read(e)}async function de(r,e){return r.objectStore.exists(e)}var xs=new TextDecoder;async function F(r,e){let t=await q(r,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return le(t.content)}var an=new TextEncoder,Jt=new TextDecoder,on=new Set(["100644","100755","040000","120000","160000"]);function cn(r){return r.length===4&&r.toLowerCase()===".git"}function fn(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(cn(r))throw new Error(`invalid tree entry: '${r}'`);if(!on.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${r}'`)}function ue(r){let e=[],t=0;for(;t<r.byteLength;){let n=r.indexOf(32,t);if(n===-1)break;let s=Jt.decode(r.subarray(t,n)),a=r.indexOf(0,n+1);if(a===-1)break;let o=Jt.decode(r.subarray(n+1,a)),i=r.subarray(a+1,a+21),f=Se(i),c=s.padStart(6,"0");fn(o,c),e.push({mode:c,name:o,hash:f}),t=a+21}return{type:"tree",entries:e}}function Qt(r){let e=[];for(let a of r.entries){let o=a.mode.replace(/^0+/,""),i=an.encode(`${o} ${a.name}\0`),f=ae(a.hash);e.push(i),e.push(f)}let t=e.reduce((a,o)=>a+o.byteLength,0),n=new Uint8Array(t),s=0;for(let a of e)n.set(a,s),s+=a.byteLength;return n}function er(r){return typeof r=="string"?{type:"direct",hash:r}:r}var Ze=".lock";var ln=[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 dn(r,e,t){let n=0,s=!1,a=e;for(;a<r.length;a++){let i=r.charCodeAt(a);switch(i<128?ln[i]:0){case 1:break;case 2:if(n===46)return{len:-1,starConsumed:s};n=i;continue;case 3:if(n===64)return{len:-1,starConsumed:s};n=i;continue;case 4:return{len:-1,starConsumed:s};case 5:if(!t)return{len:-1,starConsumed:s};s=!0,n=i;continue;default:n=i;continue}break}let o=a-e;return o===0?{len:0,starConsumed:s}:r.charCodeAt(e)===46?{len:-1,starConsumed:s}:o>=Ze.length&&r.slice(a-Ze.length,a)===Ze?{len:-1,starConsumed:s}:{len:o,starConsumed:s}}function Je(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:o}=dn(r,t,s);if(a<0||a===0)return!1;o&&(s=!1),n++,t+=a+1}return!(r.charCodeAt(r.length-1)===46||!(e&1)&&n<2)}var un=10;async function pn(r,e){return r.refStore.readRef(e)}async function pe(r,e){let t=e;for(let n=0;n<un;n++){let s=await pn(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 hn(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 tr(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:hn(e.getTimezoneOffset())}}async function nr(r,e){let t=e.branch?`refs/heads/${e.branch}`:null,n=t?await pe(r,t):null,s=null;n&&(s=(await F(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,m=await He(r,"blob",p);a.push({path:u,hash:m})}let o;s?o=await yn(r,s,a):o=await et(r,null,Qe(a));let i=tr(e.author),f=e.committer?tr(e.committer):i,l=Zt({type:"commit",tree:o,parents:n?[n]:[],author:i,committer:f,message:e.message});return{hash:await He(r,"commit",l),parentHash:n}}async function yn(r,e,t){return et(r,e,Qe(t))}function Qe(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),o=n.path.slice(s+1),i=t.get(a);i||(i=[],t.set(a,i)),i.push({...n,path:o})}}return{files:e,dirs:t}}async function rr(r,e){let t=await q(r,e);if(t.type!=="tree")throw new Error(`Expected tree object, got ${t.type}`);return ue(t.content).entries}async function et(r,e,t){let n=new Map;if(e)for(let o of await rr(r,e))n.set(o.name,o);for(let[o,{hash:i,mode:f}]of t.files)i===null?n.delete(o):n.set(o,{name:o,hash:i,mode:f});for(let[o,i]of t.dirs){let f=n.get(o),c=f?.mode==="040000"?f.hash:null,l=Qe(i),d=await et(r,c,l);(await rr(r,d)).length===0?n.delete(o):n.set(o,{name:o,hash:d,mode:"040000"})}let s=[...n.values()].sort((o,i)=>{let f=o.mode==="040000"?`${o.name}/`:o.name,c=i.mode==="040000"?`${i.name}/`:i.name;return f<c?-1:f>c?1:0}),a=Qt({type:"tree",entries:s});return He(r,"tree",a)}async function tt(r,e,t){if(e===t)return!0;let n=new Set,s=[t],a=0;for(;a<s.length;){let o=s[a++];if(o===e)return!0;if(n.has(o))continue;n.add(o);let i;try{i=await F(r,o)}catch{continue}for(let f of i.parents)n.has(f)||s.push(f)}return!1}var Ne=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]),mn=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]),De=64,bn=4,rt=4096,sr=65536,gn=127;function wn(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=xn(n);let s=n-1,a=new Uint32Array(n),o=[],i=-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])^Ne[h>>>23];if(h=h>>>0,h===i)o[o.length-1].ptr=u+16;else{i=h;let p=h&s;o.push({ptr:u+16,val:h}),a[p]++}}let f=new Map;for(let u of o){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<=De)continue;let p=[],m=h.length/De;for(let R=0;R<De;R++)p.push(h[Math.floor(R*m)]);f.set(u,p),a[u]=De}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 Rn(r,e,t){if(!r||e.byteLength===0)return null;let n=r.src.byteLength,s=e.byteLength,a=r.src,o=new Uint8Array(Math.max(s,1024)),i=0;function f(m){for(;i+m>o.length;){let R=new Uint8Array(o.length*2);R.set(o),o=R}}i=ir(o,i,n),i=ir(o,i,s),f(18),i++;let c=0,l=0,d=Math.min(16,s);for(let m=0;m<d;m++)o[i++]=e[m],c=(c<<8|e[m])^Ne[c>>>23],l++;c=c>>>0;let u=d,h=0,p=0;for(;u<s;){if(p<rt){c^=mn[e[u-16]],c=((c<<8|e[u])^Ne[c>>>23])>>>0;let m=c&r.hashMask,R=r.buckets[m],E=r.buckets[m+1];for(let y=R;y<E;y++){let b=r.entries[y];if(b.val!==c)continue;let A=b.ptr,w=a.byteLength-A,g=s-u;if(w>g&&(w=g),w<=p)break;let O=0;for(;O<w&&a[A+O]===e[u+O];)O++;if(O>p&&(p=O,h=A,p>=rt))break}}if(p<bn)f(2),l===0&&i++,o[i++]=e[u++],l++,l===gn&&(o[i-l-1]=l,l=0),p=0;else{if(l>0){for(;h>0&&a[h-1]===e[u-1];)if(p++,h--,u--,i--,!(--l>0)){i--,l=-1;break}l>0&&(o[i-l-1]=l),l=0}let m=p>sr?p-sr:0;p-=m,f(8);let R=i++,E=128;if(h&255&&(o[i++]=h&255,E|=1),h&65280&&(o[i++]=h>>>8&255,E|=2),h&16711680&&(o[i++]=h>>>16&255,E|=4),h&4278190080&&(o[i++]=h>>>24&255,E|=8),p&255&&(o[i++]=p&255,E|=16),p&65280&&(o[i++]=p>>>8&255,E|=32),o[R]=E,u+=p,h+=p,p=m,h>4294967295&&(p=0),p<rt){c=0;for(let y=-16;y<0;y++)c=(c<<8|e[u+y])^Ne[c>>>23];c=c>>>0}}if(t&&i>t)return null}return l>0&&(o[i-l-1]=l),t&&i>t?null:o.subarray(0,i)}var ar={blob:0,tree:1,commit:2,tag:3};function or(r,e){let t=e?.window??10,n=e?.depth??50,s=r.slice().sort((c,l)=>{let d=ar[c.type]??99,u=ar[l.type]??99;return d!==u?d-u:l.content.byteLength-c.content.byteLength}),a=new Map,o=[],i=[],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 m=c-1;m>=p;m--){let R=s[m];if(R.type!==l.type||(a.get(R.hash)?.depth??0)>=n||l.content.byteLength<R.content.byteLength>>>5)continue;let b=i[m-p]??null;if(!b)continue;let A=u?u.byteLength:l.content.byteLength/2|0;if(A<16)continue;let w=Rn(b,l.content,A);w&&(!u||w.byteLength<u.byteLength)&&(u=w,h=R.hash)}if(u&&h){d.delta=u,d.deltaBase=h;let m=a.get(h);d.depth=(m?.depth??0)+1}a.set(l.hash,d),o.push(d),i.length>=t&&(i.shift(),f.shift()),i.push(wn(l.content)),f.push(l.hash)}return o}function xn(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 ir(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 An=2147483647;async function nt(r,e,t,n){if(t>=An)return{shallow:[],unshallow:[...n]};let s=new Map,a=[];for(let c of e)!s.has(c)&&await de(r,c)&&(s.set(c,1),a.push({hash:c,level:1}));let o=new Set,i=0;for(;i<a.length;){let{hash:c,level:l}=a[i++];if(l>=t){o.add(c);continue}let d;try{d=await F(r,c)}catch{continue}for(let u of d.parents)!s.has(u)&&await de(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:[...o],unshallow:f}}async function me(r,e,t,n,s){let a=s??n,o=new Set;for(let l of t)await he(r,l,o,a);let i=[...e];if(s&&n)for(let l of s)try{let d=await F(r,l);for(let u of d.parents)o.has(u)||i.push(u)}catch{}let f=[],c=new Set;for(let l of i)await ye(r,l,o,c,f,n);return{count:f.length,objects:On(f)}}async function cr(r,e,t,n,s){let{count:a,objects:o}=await me(r,e,t,n,s);return{count:a,objects:En(r,o)}}async function*On(r){for(let e of r)yield e}async function*En(r,e){for await(let t of e){let n=await q(r,t.hash);yield{hash:t.hash,type:t.type,content:n.content}}}async function fr(r){let e=[];for await(let t of r.objects)e.push(t);return e}async function he(r,e,t,n){if(t.has(e)||(t.add(e),!await de(r,e)))return;let s=await q(r,e);switch(s.type){case"commit":{let a=le(s.content);if(await he(r,a.tree,t,n),!n?.has(e))for(let o of a.parents)await he(r,o,t,n);break}case"tree":{let a=ue(s.content);for(let o of a.entries)await he(r,o.hash,t,n);break}case"tag":{let a=J(s.content);await he(r,a.object,t,n);break}case"blob":break}}async function ye(r,e,t,n,s,a){if(n.has(e)||t.has(e))return;n.add(e);let o=await q(r,e);switch(s.push({hash:e,type:o.type}),o.type){case"commit":{let i=le(o.content);if(await ye(r,i.tree,t,n,s,a),!a?.has(e))for(let f of i.parents)await ye(r,f,t,n,s,a);break}case"tree":{let i=ue(o.content);for(let f of i.entries)await ye(r,f.hash,t,n,s,a);break}case"tag":{let i=J(o.content);await ye(r,i.object,t,n,s,a);break}case"blob":break}}var kn=new TextEncoder,dr=new TextDecoder,lr=65520,Pn=new Uint8Array([48,48,48,48]),vn=new Uint8Array([48,48,48,49]),Fs=new Uint8Array([48,48,48,50]);function x(r){let e=typeof r=="string"?kn.encode(r):r,t=4+e.byteLength;if(t>lr)throw new Error(`pkt-line too long: ${t} bytes (max ${lr})`);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 H(){return Pn.slice()}function V(){return vn.slice()}function L(...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 st(r){let e=[],t=0;for(;t<r.byteLength;){if(t+4>r.byteLength)throw new Error("Truncated pkt-line header");let n=dr.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 at(r){if(r.type!=="data")return"";let e=dr.decode(r.data);return e.endsWith(`
|
|
9
|
+
`)?e.slice(0,-1):e}var Be=65515;function Me(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(x(`0000000000000000000000000000000000000000 capabilities^{}\0${a}
|
|
10
10
|
`));else for(let o=0;o<r.length;o++){let i=r[o];o===0?n.push(x(`${i.hash} ${i.name}\0${a}
|
|
11
11
|
`)):n.push(x(`${i.hash} ${i.name}
|
|
12
|
-
`))}return n.push(H()),L(...n)}function
|
|
13
|
-
`),H()),a=Me(r,t,n),o=new Uint8Array(s.byteLength+a.byteLength);return o.set(s,0),o.set(a,s.byteLength),o}function
|
|
12
|
+
`))}return n.push(H()),L(...n)}function ur(r,e,t,n){let s=L(x(`# service=${e}
|
|
13
|
+
`),H()),a=Me(r,t,n),o=new Uint8Array(s.byteLength+a.byteLength);return o.set(s,0),o.set(a,s.byteLength),o}function pr(r){let e=st(r),t=[],n=[],s=[],a=[],o,i=!1;for(let f of e){if(f.type==="flush")continue;let c=at(f);if(c.startsWith("want ")){let l=c.slice(5);if(t.length===0){let d=l.indexOf(" ");d!==-1?(t.push(l.slice(0,d)),a=l.slice(d+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 ")?(o=parseInt(c.slice(7),10),Number.isNaN(o)&&(o=void 0)):c==="done"&&(i=!0)}return{wants:t,haves:n,capabilities:a,clientShallows:s,depth:o,done:i}}function be(r,e,t,n){let s=[];if(n){for(let a of n.shallow)s.push(x(`shallow ${a}
|
|
14
14
|
`));for(let a of n.unshallow)s.push(x(`unshallow ${a}
|
|
15
15
|
`));s.push(H())}if(t&&t.length>0){for(let o of t)s.push(x(`ACK ${o} common
|
|
16
16
|
`));let a=t[t.length-1];s.push(x(`ACK ${a} ready
|
|
17
17
|
`)),s.push(x(`ACK ${a}
|
|
18
18
|
`))}else s.push(x(`NAK
|
|
19
|
-
`));if(e){let a=0;for(;a<r.byteLength;){let o=Math.min(
|
|
19
|
+
`));if(e){let a=0;for(;a<r.byteLength;){let o=Math.min(Be,r.byteLength-a);s.push(ge(1,r.subarray(a,a+o))),a+=o}s.push(H())}else{let a=new Uint8Array(r.byteLength);a.set(r),s.push(a)}return L(...s)}function hr(r){let e=[];for(let t of r.shallow)e.push(x(`shallow ${t}
|
|
20
20
|
`));for(let t of r.unshallow)e.push(x(`unshallow ${t}
|
|
21
21
|
`));return e.push(H()),L(...e)}async function*yr(r,e,t,n){if(n){let a=[];for(let o of n.shallow)a.push(x(`shallow ${o}
|
|
22
22
|
`));for(let o of n.unshallow)a.push(x(`unshallow ${o}
|
|
@@ -24,8 +24,8 @@ var ve=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(
|
|
|
24
24
|
`));let a=t[t.length-1];s.push(x(`ACK ${a} ready
|
|
25
25
|
`)),s.push(x(`ACK ${a}
|
|
26
26
|
`))}else s.push(x(`NAK
|
|
27
|
-
`));if(yield L(...s),e){for await(let a of r){let o=0;for(;o<a.byteLength;){let i=Math.min(
|
|
28
|
-
`)?h.slice(0,-1):h}let
|
|
27
|
+
`));if(yield L(...s),e){for await(let a of r){let o=0;for(;o<a.byteLength;){let i=Math.min(Be,a.byteLength-o);yield ge(1,a.subarray(o,o+i)),o+=i}}yield H()}else for await(let a of r)yield a}function mr(r){let e=new TextDecoder,t=[],n=[],s=0,a=!1;for(;s<r.byteLength&&!(s+4>r.byteLength);){let i=e.decode(r.subarray(s,s+4)),f=parseInt(i,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),d;if(l!==-1)d=e.decode(c.subarray(0,l)),n=e.decode(c.subarray(l+1)).replace(/\n$/,"").split(" ").filter(Boolean);else{let h=e.decode(c);d=h.endsWith(`
|
|
28
|
+
`)?h.slice(0,-1):h}let u=d.split(" ");u.length>=3&&t.push({oldHash:u[0],newHash:u[1],refName:u[2]})}let o=s<r.byteLength?r.subarray(s):new Uint8Array(0);return{commands:t,packData:o,capabilities:n,sawFlush:a}}function Q(r,e,t){let n=[];n.push(x(r?`unpack ok
|
|
29
29
|
`:`unpack error
|
|
30
30
|
`));for(let a of e)a.ok?n.push(x(`ok ${a.name}
|
|
31
31
|
`)):n.push(x(`ng ${a.name} ${a.error??"failed"}
|
|
@@ -41,7 +41,7 @@ var ve=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(
|
|
|
41
41
|
`));t.push(V())}if(a&&a.length>0){t.push(x(`wanted-refs
|
|
42
42
|
`));for(let i of a)t.push(x(`${i.hash} ${i.name}
|
|
43
43
|
`));t.push(V())}t.push(x(`packfile
|
|
44
|
-
`));let o=0;for(;o<r.byteLength;){let i=Math.min(
|
|
44
|
+
`));let o=0;for(;o<r.byteLength;){let i=Math.min(Be,r.byteLength-o);t.push(ge(1,r.subarray(o,o+i))),o+=i}return t.push(H()),L(...t)}function br(r,e){let t=[];if(t.push(x(`acknowledgments
|
|
45
45
|
`)),r.length>0)for(let n of r)t.push(x(`ACK ${n}
|
|
46
46
|
`));else t.push(x(`NAK
|
|
47
47
|
`));return e&&t.push(x(`ready
|
|
@@ -54,16 +54,16 @@ var ve=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(
|
|
|
54
54
|
`));a.push(V()),yield L(...a)}if(s&&s.length>0){let a=[];a.push(x(`wanted-refs
|
|
55
55
|
`));for(let o of s)a.push(x(`${o.hash} ${o.name}
|
|
56
56
|
`));a.push(V()),yield L(...a)}yield x(`packfile
|
|
57
|
-
`);for await(let a of r){let o=0;for(;o<a.byteLength;){let i=Math.min(
|
|
58
|
-
`),128;let{service:l,repoPath:d}=c,
|
|
59
|
-
`),128;let{repo:h,repoId:
|
|
60
|
-
`),128;await f.write(xe());let y=new _e(e.readable);try{await Dn(y,f,h,
|
|
61
|
-
`),128;await f.write(dt(m.refs,l,m.headTarget));let R=new _e(e.readable);try{if(l==="git-upload-pack"){let
|
|
62
|
-
`),128}finally{try{await f.close()}catch{}}}async function Ln(r){let{writer:e,repo:t,repoId:n,commands:s,capabilities:a,packStream:o,hooks:i,
|
|
63
|
-
`)&&(a=a.slice(0,-1)),n){let i=a.indexOf("\0");i!==-1&&(t=a.slice(i+1).split(" ").filter(Boolean),a=a.slice(0,i)),n=!1}let o=a.split(" ");o.length>=3&&e.push({oldHash:o[0],newHash:o[1],refName:o[2]})}return{commands:e,capabilities:t}}async function Dn(r,e,t,n,s){let{hooks:a,packCache:o,packOptions:i,
|
|
64
|
-
`)&&(i=i.slice(0,-1)),s?n.push(i):i.startsWith("command=")?e=i.slice(8):t.push(i)}return e?{command:e,capabilities:t,args:n}:null}function
|
|
65
|
-
`)),128;try{if(!f.ssh)return b.writeStderr?.(new TextEncoder().encode(`fatal: SSH
|
|
66
|
-
`)),128;let w=await f.ssh(
|
|
57
|
+
`);for await(let a of r){let o=0;for(;o<a.byteLength;){let i=Math.min(Be,a.byteLength-o);yield ge(1,a.subarray(o,o+i)),o+=i}}yield H()}var te=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}}},wr=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag","allow-reachable-sha1-in-want","shallow"],Rr=["report-status","side-band-64k","ofs-delta","delete-refs"];async function xr(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 i=await r.refStore.readRef(t.target);i?.type==="direct"&&(s=i.hash)}else s=t.hash;let o=e.slice().sort((i,f)=>i.name<f.name?-1:i.name>f.name?1:0);if(!s&&o.length>0){let i=Sn(o);i&&(s=i.hash,a=i.name)}s&&n.push({name:"HEAD",hash:s});for(let i of o)if(n.push({name:i.name,hash:i.hash}),i.name.startsWith("refs/tags/"))try{let f=await r.objectStore.read(i.hash);if(f.type==="tag"){let c=J(f.content);n.push({name:`${i.name}^{}`,hash:c.object})}}catch{}return{refs:n,headTarget:a}}var jn=["refs/heads/main","refs/heads/master"];function Sn(r){for(let t of jn){let n=r.find(s=>s.name===t);if(n)return n}return r.find(t=>t.name.startsWith("refs/heads/"))??null}function lt(r,e,t){return ur(r,e,e==="git-upload-pack"?wr:Rr,t)}function dt(r,e,t){return Me(r,e==="git-upload-pack"?wr:Rr,t)}async function G(r,e,t,n,s){let{refs:a,headTarget:o}=await xr(r),i=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&&(i=f)}return{refs:i,headTarget:o}}async function we(r,e,t){let{wants:n,haves:s,capabilities:a,clientShallows:o,depth:i,done:f}=pr(e);if(n.length===0)return be(new Uint8Array(0),!1);let c=a.includes("multi_ack_detailed"),l=a.includes("side-band-64k"),d,u,h;if(o.length>0&&(h=new Set(o)),i!==void 0){let b=await nt(r,n,i,h??new Set);d=b,u=new Set(b.shallow)}if(d&&!f)return hr(d);let p;if(c&&s.length>0){p=[];for(let b of s)await r.objectStore.exists(b)&&p.push(b);p.length===0&&(p=void 0)}let m=!u&&t?.cache&&t.cacheKey?te.key(t.cacheKey,n,s):null;if(m&&t?.cache){let b=t.cache.get(m);if(b)return be(b.packData,l,p)}let R=a.includes("include-tag"),E={repo:r,wants:n,haves:s,includeTag:R,shallowBoundary:u,clientShallowBoundary:h,cache:t?.cache,cacheKey:m,deltaWindow:t?.deltaWindow};if(t?.noDelta){let b=await Er(E);if(!b){let{data:A}=await Z([]);return be(A,l,p,d)}return kr(yr(b,l,p,d))}let y=await Or(E);return be(y,l,p,d)}async function Ar(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 o=J(a.content);e.has(o.object)&&(t.push({hash:s.hash,type:"tag",content:a.content}),e.add(s.hash))}}catch{}return t}async function Or(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:o}=r,i=await cr(e,t,n,a,o);if(i.count===0){let{data:p}=await Z([]);return p}let f=await fr(i),c=new Set(f.map(p=>p.hash));if(s){let p=await Ar(e,c);f.push(...p)}let l=r.deltaWindow?{window:r.deltaWindow}:void 0,d=or(f,l),u=d.map(p=>({hash:p.hash,type:p.type,content:p.content,delta:p.delta,deltaBaseHash:p.deltaBase})),{data:h}=await Z(u);if(r.cacheKey&&r.cache){let p=d.filter(m=>m.delta).length;r.cache.set(r.cacheKey,{packData:h,objectCount:f.length,deltaCount:p})}return h}async function Er(r){let{repo:e,wants:t,haves:n,includeTag:s,shallowBoundary:a,clientShallowBoundary:o}=r,{count:i,objects:f}=await me(e,t,n,a,o);if(i===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 Ar(e,l):[],u=c.length+d.length;async function*h(){for(let p of c){let m=await e.objectStore.read(p.hash);yield{type:m.type,content:m.content}}for(let p of d)yield{type:p.type,content:p.content}}return Xt(u,h())}function kr(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 ut(r,e){let{commands:t,packData:n,capabilities:s,sawFlush:a}=mr(e),o=!0;if(n.byteLength>0)try{await r.objectStore.ingestPack(n)}catch{o=!1}return{updates:await Pr(r,t,o),unpackOk:o,capabilities:s,sawFlush:a}}async function pt(r,e,t,n,s=!0){let a=!0;if(e.some(f=>f.newHash!==ne))try{let c=Kt(n,async l=>{try{return await r.objectStore.read(l)}catch{return null}});await r.objectStore.ingestPackStream(c)}catch{a=!1}return{updates:await Pr(r,e,a),unpackOk:a,capabilities:t,sawFlush:s}}async function Pr(r,e,t){let n=[];for(let s of e){let a=s.oldHash===ne,o=s.newHash===ne,i=!1;if(!a&&!o&&t)try{i=await tt(r,s.oldHash,s.newHash)}catch{}n.push({ref:s.refName,oldHash:a?null:s.oldHash,newHash:s.newHash,isFF:i,isCreate:a,isDelete:o})}return n}async function $e(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&&!Je(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,o=s.isDelete?null:{type:"direct",hash:s.newHash};if(!await r.refStore.compareAndSwapRef(s.ref,a,o)){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 Re(r){let{repo:e,repoId:t,ingestResult:n,hooks:s,auth:a}=r,{updates:o}=n;if(s?.preReceive){let c=await s.preReceive({repo:e,repoId:t,updates:o,auth:a});if(U(c)){let l=c.message??"pre-receive hook declined";return{refResults:o.map(d=>({ref:d.ref,ok:!1,error:l})),applied:[]}}}let i=[],f=[];for(let c of o){if(c.ref==="HEAD"){i.push({ref:c.ref,ok:!1,error:"HEAD cannot be updated via push"});continue}if(!c.isDelete&&!Je(c.ref)){i.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)){i.push({ref:c.ref,ok:!1,error:l.message??"update hook declined"});continue}}if(!c.isDelete&&!await e.objectStore.exists(c.newHash)){i.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)){i.push({ref:c.ref,ok:!1,error:"failed to lock"});continue}i.push({ref:c.ref,ok:!0}),f.push(c)}catch(l){i.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:i,applied:f}}async function We(r,e){let t=[];for(let n of e){let s;n.oldHash!==void 0?s=n.oldHash:s=await pe(r,n.ref);let a=s===null,o=n.newHash===null,i=n.newHash??ne,f=!1;if(!a&&!o)try{f=await tt(r,s,i)}catch{}t.push({ref:n.ref,oldHash:s,newHash:i,isFF:f,isCreate:a,isDelete:o})}return t}var In=["agent=just-git/1.0","ls-refs=unborn","fetch=shallow","server-option","object-format=sha1"];function xe(){return it(In)}async function Ae(r,e,t,n,s){let a=t.includes("symrefs"),o=t.includes("peel"),i=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(m=>h.name.startsWith(m)))continue;let p={hash:h.hash,name:h.name};if(a&&h.name==="HEAD"&&d&&(p.symrefTarget=d),o&&h.name.startsWith("refs/tags/")){let m=l.find(R=>R.name===`${h.name}^{}`);m&&(p.peeledHash=m.hash)}u.push(p)}return i&&!u.some(h=>h.name==="HEAD")&&d&&(f.length===0||f.some(p=>"HEAD".startsWith(p)))&&u.unshift({hash:"unborn",name:"HEAD",symrefTarget:d}),ct(u)}async function Oe(r,e,t){let{wants:n,haves:s,done:a,clientShallows:o,depth:i,includeTag:f,wantRefs:c}=ft(e);if(n.length===0&&c.length===0){let{data:w}=await Z([]);return ee(w)}let l=[],d=[...n];for(let w of c){let g=await pe(r,w);g&&(l.push({hash:g,name:w}),d.includes(g)||d.push(g))}let u,h,p;if(o.length>0&&(p=new Set(o)),i!==void 0){let w=await nt(r,d,i,p??new Set);u=w,h=new Set(w.shallow)}let m;if(s.length>0){m=[];for(let w of s)await r.objectStore.exists(w)&&m.push(w);m.length===0&&(m=void 0)}let R=m&&m.length>0;if(!a&&!R)return br(m??[]);let E=!h&&t?.cache&&t.cacheKey?te.key(t.cacheKey,d,s):null,y={commonHashes:m,shallowInfo:u,wantedRefs:l.length>0?l:void 0};if(E&&t?.cache){let w=t.cache.get(E);if(w)return ee(w.packData,y)}let b={repo:r,wants:d,haves:s,includeTag:f,shallowBoundary:h,clientShallowBoundary:p,cache:t?.cache,cacheKey:E,deltaWindow:t?.deltaWindow};if(t?.noDelta){let w=await Er(b);if(!w){let{data:g}=await Z([]);return ee(g,y)}return kr(gr(w,y))}let A=await Or(b);return ee(A,y)}function Tn(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 Un=new TextEncoder;async function jr(r,e,t){let{resolveRepo:n,hooks:s,packCache:a,packOptions:o,auth:i}=t,f=e.writable.getWriter();try{let c=Tn(r);if(!c)return Ee(e,`fatal: unrecognized command '${r}'
|
|
58
|
+
`),128;let{service:l,repoPath:d}=c,u=await n(d);if(!u)return Ee(e,`fatal: '${d}' does not appear to be a git repository
|
|
59
|
+
`),128;let{repo:h,repoId:p}=u;if(c.protocolV2&&l==="git-upload-pack"){let E=await G(h,p,l,s,i);if(U(E))return Ee(e,`fatal: ${E.message??"access denied"}
|
|
60
|
+
`),128;await f.write(xe());let y=new _e(e.readable);try{await Dn(y,f,h,p,{hooks:s,packCache:a,packOptions:o,auth:i})}finally{y.release()}return 0}let m=await G(h,p,l,s,i);if(U(m))return Ee(e,`fatal: ${m.message??"access denied"}
|
|
61
|
+
`),128;await f.write(dt(m.refs,l,m.headTarget));let R=new _e(e.readable);try{if(l==="git-upload-pack"){let E=await Cn(R),y=await we(h,E,{cache:a,cacheKey:p,noDelta:o?.noDelta,deltaWindow:o?.deltaWindow});await Sr(f,y)}else{let{commands:E,capabilities:y}=await Hn(R),b=R.streamRemaining();await Ln({writer:f,repo:h,repoId:p,commands:E,capabilities:y,packStream:b,hooks:s,auth:i})}}finally{R.release()}return 0}catch(c){return t.onError?.(c),Ee(e,`fatal: internal error
|
|
62
|
+
`),128}finally{try{await f.close()}catch{}}}async function Ln(r){let{writer:e,repo:t,repoId:n,commands:s,capabilities:a,packStream:o,hooks:i,auth:f}=r,c=await pt(t,s,a,o);if(c.updates.length===0)return;let l=c.capabilities.includes("side-band-64k"),d=c.capabilities.includes("report-status");if(!c.unpackOk){if(d){let h=c.updates.map(p=>({name:p.ref,ok:!1,error:"unpack failed"}));await e.write(Q(!1,h,l))}return}let{refResults:u}=await Re({repo:t,repoId:n,ingestResult:c,hooks:i,auth:f});if(d){let h=u.map(p=>({name:p.ref,ok:p.ok,error:p.error}));await e.write(Q(!0,h,l))}}function Ee(r,e){r.writeStderr?.(Un.encode(e))}var vr=new TextDecoder,_e=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=vr.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:vr.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 Cn(r){let e=[];for(;;){let t=await r.readPktLine();if(!t||(e.push(t.raw),t.type==="data"&&t.text.trimEnd()==="done"))break}return Bn(e)}async function Hn(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 i=a.indexOf("\0");i!==-1&&(t=a.slice(i+1).split(" ").filter(Boolean),a=a.slice(0,i)),n=!1}let o=a.split(" ");o.length>=3&&e.push({oldHash:o[0],newHash:o[1],refName:o[2]})}return{commands:e,capabilities:t}}async function Dn(r,e,t,n,s){let{hooks:a,packCache:o,packOptions:i,auth:f}=s;for(;;){let c=await Nn(r);if(!c)break;if(c.command==="ls-refs"){let l=await Ae(t,n,c.args,a,f);if(U(l))break;await e.write(l)}else if(c.command==="fetch"){let l=await Oe(t,c.args,{cache:o,cacheKey:n,noDelta:i?.noDelta,deltaWindow:i?.deltaWindow});await Sr(e,l)}else break}}async function Nn(r){let e="",t=[],n=[],s=!1,a=!1;for(;;){let o=await r.readPktLine();if(!o)return a?{command:e,capabilities:t,args:n}:null;if(o.type==="flush"){if(!a)return null;break}if(o.type==="response-end")break;if(o.type==="delim"){s=!0;continue}a=!0;let i=o.text;i.endsWith(`
|
|
64
|
+
`)&&(i=i.slice(0,-1)),s?n.push(i):i.startsWith("command=")?e=i.slice(8):t.push(i)}return e?{command:e,capabilities:t,args:n}:null}function Bn(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 Sr(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 Tr(r,e,t,n){let s=n?.dryRun??!1,a=await Ir(r),o=Mn(a);if(o.length===0)return{deleted:0,retained:0};let i=await me(r,o,[]),f=new Set;for await(let h of i.objects)f.add(h.hash);let c=await e.listObjectHashes(t),l=[];for(let h of c)f.has(h)||l.push(h);let d=await Ir(r);return $n(a,d)?s||l.length===0?{deleted:l.length,retained:f.size}:{deleted:await e.deleteObjects(t,l),retained:f.size}:{deleted:0,retained:f.size,aborted:!0}}async function Ir(r){return r.refStore.listRefs()}function Mn(r){let e=new Set;for(let t of r)e.add(t.hash);return Array.from(e)}function $n(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}function Ur(r){function e(t){return{objectStore:new ht(r,t),refStore:new yt(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){await r.deleteRepo(t)}}}var ht=class{constructor(e,t){this.driver=e;this.repoId=t}cache=new Ie;async write(e,t){let n=Yt(e,t),s=await jt(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)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)}async ingestPack(e){if(e.byteLength<32)return 0;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 0;let o=this.driver,i=this.repoId,f=await zt(e,async c=>{let l=await o.getObject(i,c);return l?{type:l.type,content:new Uint8Array(l.content)}:null});return await o.putObjects(i,f.map(c=>({hash:c.hash,type:c.type,content:c.content}))),f.length}async ingestPackStream(e){let t=[];for await(let n of e)t.push({hash:n.hash,type:n.type,content:n.content});return t.length===0?0:(await this.driver.putObjects(this.repoId,t),t.length)}async findByPrefix(e){return e.length<4?[]:Array.from(await this.driver.findObjectsByPrefix(this.repoId,e))}},yt=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,er(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 mt(o=>this.driver.getRef(this.repoId,o),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=>ke(s.getRef(e),a=>{let o=a?a.type==="direct"?a.hash:mt(i=>s.getRef(i),a.target):null;return ke(o,i=>{if(t===null){if(a!==null)return!1}else if(i!==t)return!1;return n===null?ke(s.removeRef(e),()=>!0):ke(s.putRef(e,n),()=>!0)})}))}};function ke(r,e){return r instanceof Promise?r.then(e):e(r)}function mt(r,e,t=0){return t>10?null:ke(r(e),n=>n?n.type==="direct"?n.hash:n.type==="symbolic"?mt(r,n.target,t+1):null:null)}var Pe=class{repos=new Set;objects=new Map;refs=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)}getObject(e,t){let n=this.getObjMap(e).get(t);return n?{type:n.type,content:new Uint8Array(n.content)}:null}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);for(let s of t)n.has(s.hash)||n.set(s.hash,{type:s.type,content:new Uint8Array(s.content)})}hasObject(e,t){return this.getObjMap(e).has(t)}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)}})}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 Wn={http:r=>({transport:"http",request:r}),ssh:r=>({transport:"ssh",username:r.username})};function Lr(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 _n(r={}){let e=r.storage??new Pe,t=Ur(e),n=r.resolve??(y=>y),s=r.autoCreate,{basePath:a}=r;async function o(y){if(!Lr(y))return null;let b=await n(y);if(b==null||b!==y&&!Lr(b))return null;let A=await t.repo(b);if(A)return{repo:A,repoId:b};if(!s)return null;let w=typeof s=="object"?{defaultBranch:s.defaultBranch}:void 0;return{repo:await t.createRepo(b,w),repoId:b}}let i=qn(r.policy,r.hooks),f=r.auth??Wn,c=r.packCache===!1?void 0:new te(r.packCache?.maxBytes),l=r.onError===!1?void 0:r.onError??(y=>{let b=y instanceof Error?y.message:String(y);console.error(`[server] Internal error: ${b}`)}),d=!1,u=0,h=null,p=null;function m(){return d?!1:(u++,!0)}function R(){u--,d&&u===0&&h?.()}let E={async fetch(y){if(!m())return new Response("Service Unavailable",{status:503});let b;try{if(!f.http)return new Response("HTTP auth provider not configured",{status:501});let A=await f.http(y);if(A instanceof Response)return A;b=A;let w=new URL(y.url),g=decodeURIComponent(w.pathname);if(a){let O=a.replace(/\/+$/,"");if(!g.startsWith(O))return new Response("Not Found",{status:404});g=g.slice(O.length)}if(g.startsWith("/")||(g=`/${g}`),g.endsWith("/info/refs")&&y.method==="GET"){let O=w.searchParams.get("service");if(O!=="git-upload-pack"&&O!=="git-receive-pack")return new Response("Unsupported service",{status:403});let k=bt(g,"/info/refs"),P=await o(k);if(!P)return new Response("Not Found",{status:404});if(Cr(y)&&O==="git-upload-pack"){let T=await G(P.repo,P.repoId,O,i,b);if(U(T))return new Response(T.message??"Forbidden",{status:403});let $=xe();return new Response($,{headers:{"Content-Type":`application/x-${O}-advertisement`,"Cache-Control":"no-cache"}})}let S=await G(P.repo,P.repoId,O,i,b);if(U(S))return new Response(S.message??"Forbidden",{status:403});let I=lt(S.refs,O,S.headTarget);return new Response(I,{headers:{"Content-Type":`application/x-${O}-advertisement`,"Cache-Control":"no-cache"}})}if(g.endsWith("/git-upload-pack")&&y.method==="POST"){let O=bt(g,"/git-upload-pack"),k=await o(O);if(!k)return new Response("Not Found",{status:404});let P=await Hr(y);if(Cr(y)){let S=ot(P),I="application/x-git-upload-pack-result";if(S.command==="ls-refs"){let T=await Ae(k.repo,k.repoId,S.args,i,b);return U(T)?new Response(T.message??"Forbidden",{status:403}):new Response(T,{headers:{"Content-Type":I}})}if(S.command==="fetch"){let T=await Oe(k.repo,S.args,{cache:c,cacheKey:k.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow});return new Response(T,{headers:{"Content-Type":I}})}return new Response(`unknown command: ${S.command}`,{status:400})}let j=await we(k.repo,P,{cache:c,cacheKey:k.repoId,noDelta:r.packOptions?.noDelta,deltaWindow:r.packOptions?.deltaWindow});return new Response(j,{headers:{"Content-Type":"application/x-git-upload-pack-result"}})}if(g.endsWith("/git-receive-pack")&&y.method==="POST"){let O=bt(g,"/git-receive-pack"),k=await o(O);if(!k)return new Response("Not Found",{status:404});let P=await Hr(y),j=await ut(k.repo,P);if(!j.sawFlush&&j.updates.length===0)return new Response("Bad Request",{status:400});let S=j.capabilities.includes("side-band-64k"),I=j.capabilities.includes("report-status");if(!j.unpackOk){if(I){let $=j.updates.map(W=>({name:W.ref,ok:!1,error:"unpack failed"}));return new Response(Q(!1,$,S),{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:T}=await Re({repo:k.repo,repoId:k.repoId,ingestResult:j,hooks:i,auth:b});if(I){let $=T.map(W=>({name:W.ref,ok:W.ok,error:W.error}));return new Response(Q(!0,$,S),{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(A){return l?.(A,b),new Response("Internal Server Error",{status:500})}finally{R()}},async handleSession(y,b,A){if(!m())return b.writeStderr?.(new TextEncoder().encode(`fatal: server shutting down
|
|
65
|
+
`)),128;try{if(!f.ssh)return b.writeStderr?.(new TextEncoder().encode(`fatal: SSH auth provider not configured
|
|
66
|
+
`)),128;let w=await f.ssh(A??{});return await jr(y,b,{resolveRepo:o,hooks:i,packCache:c,packOptions:r.packOptions,auth:w,onError:l?g=>l(g,w):void 0})}finally{R()}},async updateRefs(y,b){if(!m())throw new Error("Server is shutting down");try{let A=await E.requireRepo(y),w=await We(A,b);return $e(A,w)}finally{R()}},async commit(y,b){if(!m())throw new Error("Server is shutting down");try{let A=await E.requireRepo(y),w=await nr(A,b),g=`refs/heads/${b.branch}`,O=await We(A,[{ref:g,newHash:w.hash,oldHash:w.parentHash}]),P=(await $e(A,O)).refResults[0];if(!P?.ok)throw new Error(P?.error??"ref update failed");return w}finally{R()}},nodeHandler(y,b){let A=[];y.on("data",w=>A.push(new Uint8Array(w))),y.on("error",()=>{b.writeHead(500),b.end("Internal Server Error")}),y.on("end",()=>{Fn(E,y,A,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 gc(y,b){if(!m())throw new Error("Server is shutting down");try{let A=await E.requireRepo(y);return Tr(A,e,y,b)}finally{R()}},get closed(){return d},asNetwork(y="http://git"){return{allowed:[y.endsWith("/")?y:`${y}/`],fetch:(A,w)=>E.fetch(new Request(A,w))}},async close(y){if(d)return p??Promise.resolve();if(d=!0,c?.clear(),u!==0){if(p=new Promise(b=>{h=b}),y?.signal){if(y.signal.aborted){h();return}let b=()=>h?.();y.signal.addEventListener("abort",b,{once:!0}),p.then(()=>y.signal.removeEventListener("abort",b))}return p}}};return E}function Cr(r){let e=r.headers.get("git-protocol");return e!==null&&e.includes("version=2")}function bt(r,e){let t=r.slice(0,-e.length);return t.startsWith("/")&&(t=t.slice(1)),t}async function Hr(r){let e=new Uint8Array(await r.arrayBuffer()),t=r.headers.get("content-encoding");if(t==="gzip"||t==="x-gzip"){let n=new DecompressionStream("gzip"),s=n.writable.getWriter();return s.write(e),s.close(),new Uint8Array(await new Response(n.readable).arrayBuffer())}return e}async function Fn(r,e,t,n){let s=typeof e.headers.host=="string"?e.headers.host:"localhost",a=new URL(e.url??"/",`http://${s}`),o=new Headers;for(let[h,p]of Object.entries(e.headers))if(p!==void 0)if(Array.isArray(p))for(let m of p)o.append(h,m);else o.set(h,p);let i=e.method??"GET",f;if(i!=="GET"&&i!=="HEAD"){let h=0;for(let R of t)h+=R.byteLength;let p=new Uint8Array(h),m=0;for(let R of t)p.set(R,m),m+=R.byteLength;f=p}let c=new Request(a.href,{method:i,headers:o,body:f}),l=await r.fetch(c),d={};l.headers.forEach((h,p)=>{d[p]=h}),n.writeHead(l.status,d);let u=new Uint8Array(await l.arrayBuffer());u.byteLength>0&&n.write(u),n.end()}function Gn(r){let{protectedBranches:e=[],denyNonFastForward:t=!1,denyDeletes:n=!1,immutableTags:s=!1}=r,a=new Set(e.map(i=>i.startsWith("refs/")?i:`refs/heads/${i}`)),o={};return a.size>0&&(o.preReceive=async i=>{for(let f of i.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)&&(o.update=async i=>{if(n&&i.update.isDelete)return{reject:!0,message:"ref deletion denied"};if(s&&i.update.ref.startsWith("refs/tags/")){if(i.update.isDelete)return{reject:!0,message:"tag deletion denied"};if(!i.update.isCreate)return{reject:!0,message:"tag overwrite denied"}}if(t&&!i.update.isCreate&&!i.update.isDelete&&!i.update.isFF)return{reject:!0,message:"non-fast-forward"}}),o}function qn(r,e){let t=r?Gn(r):void 0;return t&&e?Dr(t,e):t??e}function Dr(...r){let e=r.filter(i=>i!=null);if(e.length===0)return{};if(e.length===1)return e[0];let t={},n=e.filter(i=>i.preReceive).map(i=>i.preReceive);n.length>0&&(t.preReceive=async i=>{for(let f of n){let c=await f(i);if(U(c))return c}});let s=e.filter(i=>i.update).map(i=>i.update);s.length>0&&(t.update=async i=>{for(let f of s){let c=await f(i);if(U(c))return c}});let a=e.filter(i=>i.postReceive).map(i=>i.postReceive);a.length>0&&(t.postReceive=async i=>{for(let f of a)try{await f(i)}catch{}});let o=e.filter(i=>i.advertiseRefs).map(i=>i.advertiseRefs);return o.length>0&&(t.advertiseRefs=async i=>{let f=i.refs;for(let c of o){let l=await c({...i,refs:f});if(U(l))return l;l&&(f=l)}return f}),t}var Vn=`
|
|
67
67
|
CREATE TABLE IF NOT EXISTS git_repos (
|
|
68
68
|
id TEXT PRIMARY KEY
|
|
69
69
|
);
|
|
@@ -127,4 +127,4 @@ CREATE TABLE IF NOT EXISTS git_refs (
|
|
|
127
127
|
PRIMARY KEY (repo_id, name)
|
|
128
128
|
);
|
|
129
129
|
`,v={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",objRead:"SELECT type, content FROM git_objects WHERE repo_id = $1 AND hash = $2",objExists:"SELECT 1 FROM git_objects WHERE repo_id = $1 AND hash = $2 LIMIT 1",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)
|
|
130
|
-
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"},
|
|
130
|
+
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"},Ot=class r{constructor(e){this.pool=e}static async create(e){return await e.query(Yn),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(v.repoExists,[e]);return t.length>0}async insertRepo(e){await this.pool.query(v.repoInsert,[e])}async deleteRepo(e){await this.pool.query(v.repoDelete,[e]),await this.pool.query(v.objDeleteAll,[e]),await this.pool.query(v.refDeleteAll,[e])}async getObject(e,t){let{rows:n}=await this.pool.query(v.objRead,[e,t]),s=n[0];return s?{type:s.type,content:new Uint8Array(s.content)}:null}async putObject(e,t,n,s){await this.pool.query(v.objInsert,[e,t,n,s])}async putObjects(e,t){await this.transaction(async n=>{for(let s of t)await n(v.objInsert,[e,s.hash,s.type,s.content])})}async hasObject(e,t){let{rows:n}=await this.pool.query(v.objExists,[e,t]);return n.length>0}async findObjectsByPrefix(e,t){let{rows:n}=await this.pool.query(v.objPrefix,[e,`${t}%`]);return n.map(s=>s.hash)}async listObjectHashes(e){let{rows:t}=await this.pool.query(v.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(v.refRead,[e,t]);return At(n[0]??null)}async putRef(e,t,n){n.type==="symbolic"?await this.pool.query(v.refWrite,[e,t,"symbolic",null,n.target]):await this.pool.query(v.refWrite,[e,t,"direct",n.hash,null])}async removeRef(e,t){await this.pool.query(v.refDelete,[e,t])}async listRefs(e,t){let n;return t?{rows:n}=await this.pool.query(v.refList,[e,`${t}%`]):{rows:n}=await this.pool.query(v.refListAll,[e]),n.flatMap(s=>{let a=At(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(v.refReadForUpdate,[e,s]);return At(a[0]??null)},putRef:async(s,a)=>{a.type==="symbolic"?await n(v.refWrite,[e,s,"symbolic",null,a.target]):await n(v.refWrite,[e,s,"direct",a.hash,null])},removeRef:async s=>{await n(v.refDelete,[e,s])}}))}};function At(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}export{xt as BetterSqlite3Storage,wt as BunSqliteStorage,Pe as MemoryStorage,Ot as PgStorage,G as advertiseRefsWithHooks,$e as applyCasRefUpdates,Re as applyReceivePack,lt as buildRefAdvertisementBytes,dt as buildRefListBytes,Me as buildRefListPktLines,it as buildV2CapabilityAdvertisement,xe as buildV2CapabilityAdvertisementBytes,ee as buildV2FetchResponse,ct as buildV2LsRefsResponse,xr as collectRefs,Dr as composeHooks,_n as createServer,Ae as handleLsRefs,we as handleUploadPack,Oe as handleV2Fetch,ut as ingestReceivePack,pt as ingestReceivePackFromStream,ot as parseV2CommandRequest,ft as parseV2FetchArgs,We as resolveRefUpdates};
|