just-git 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -60
- package/dist/hooks-jTfqkfs1.d.ts +480 -0
- package/dist/index.d.ts +22 -407
- package/dist/index.js +398 -398
- package/dist/repo/index.d.ts +261 -0
- package/dist/repo/index.js +18 -0
- package/dist/server/index.d.ts +284 -0
- package/dist/server/index.js +42 -0
- package/package.json +9 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { _ as ObjectId, $ as Commit, a0 as Identity, c as GitContext, f as GitRepo, F as FileSystem, a1 as TreeDiffEntry, V as RefEntry, O as ObjectStore, a2 as ObjectType, a3 as RawObject, a as RefStore, a4 as Ref } from '../hooks-jTfqkfs1.js';
|
|
2
|
+
|
|
3
|
+
interface CommitEntry {
|
|
4
|
+
hash: ObjectId;
|
|
5
|
+
commit: Commit;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface MergeConflict {
|
|
9
|
+
path: string;
|
|
10
|
+
reason: "content" | "delete-modify" | "add-add" | "rename-delete" | "rename-rename" | "directory-rename";
|
|
11
|
+
/** For delete-modify / rename-delete: which side deleted the file. */
|
|
12
|
+
deletedBy?: "ours" | "theirs";
|
|
13
|
+
/** For rename conflicts: the old (base) path. */
|
|
14
|
+
oldPath?: string;
|
|
15
|
+
/** For rename/rename: the path ours renamed to. */
|
|
16
|
+
oursPath?: string;
|
|
17
|
+
/** For rename/rename: the path theirs renamed to. */
|
|
18
|
+
theirsPath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* For content conflicts arising from renames: the path where ours' version
|
|
21
|
+
* was before the merge. If different from `path`, indicates ours had the
|
|
22
|
+
* file at a different location.
|
|
23
|
+
*/
|
|
24
|
+
oursOrigPath?: string;
|
|
25
|
+
/**
|
|
26
|
+
* For content conflicts arising from renames: the path where theirs'
|
|
27
|
+
* version was before the merge.
|
|
28
|
+
*/
|
|
29
|
+
theirsOrigPath?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A flattened file entry from walking a tree recursively. */
|
|
33
|
+
interface FlatTreeEntry {
|
|
34
|
+
path: string;
|
|
35
|
+
mode: string;
|
|
36
|
+
hash: ObjectId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Standalone helper functions for working with GitRepo.
|
|
41
|
+
*
|
|
42
|
+
* Thin wrappers over lib/ primitives. Useful inside server hooks
|
|
43
|
+
* and equally useful outside the server for direct repo inspection.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Walk commits introduced by a ref update (newHash excluding oldHash).
|
|
48
|
+
* If oldHash is null (new ref), walks all ancestors of newHash.
|
|
49
|
+
*/
|
|
50
|
+
declare function getNewCommits(repo: GitRepo, oldHash: string | null, newHash: string): AsyncGenerator<CommitEntry>;
|
|
51
|
+
/**
|
|
52
|
+
* Get the files changed between two commits.
|
|
53
|
+
* Reads the tree hash from each commit and diffs them.
|
|
54
|
+
* If oldHash is null (new ref), diffs against an empty tree.
|
|
55
|
+
*/
|
|
56
|
+
declare function getChangedFiles(repo: GitRepo, oldHash: string | null, newHash: string): Promise<TreeDiffEntry[]>;
|
|
57
|
+
declare function isAncestor(repo: GitRepo, candidate: string, descendant: string): Promise<boolean>;
|
|
58
|
+
declare function resolveRef(repo: GitRepo, name: string): Promise<string | null>;
|
|
59
|
+
declare function listBranches(repo: GitRepo): Promise<RefEntry[]>;
|
|
60
|
+
declare function listTags(repo: GitRepo): Promise<RefEntry[]>;
|
|
61
|
+
declare function readCommit(repo: GitRepo, hash: string): Promise<Commit>;
|
|
62
|
+
declare function readBlob(repo: GitRepo, hash: string): Promise<Uint8Array>;
|
|
63
|
+
declare function readBlobText(repo: GitRepo, hash: string): Promise<string>;
|
|
64
|
+
declare function flattenTree(repo: GitRepo, treeHash: string): Promise<FlatTreeEntry[]>;
|
|
65
|
+
declare function diffTrees(repo: GitRepo, treeA: string | null, treeB: string | null): Promise<TreeDiffEntry[]>;
|
|
66
|
+
declare function findMergeBases(repo: GitRepo, commitA: string, commitB: string): Promise<string[]>;
|
|
67
|
+
interface MergeTreesResult {
|
|
68
|
+
treeHash: string;
|
|
69
|
+
clean: boolean;
|
|
70
|
+
conflicts: MergeConflict[];
|
|
71
|
+
messages: string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Three-way tree merge using merge-ort. Operates purely on the object
|
|
75
|
+
* store — no filesystem or worktree needed.
|
|
76
|
+
*
|
|
77
|
+
* Takes two commit hashes, finds their merge base(s) automatically
|
|
78
|
+
* (handling criss-cross merges via recursive base merging), and produces
|
|
79
|
+
* a result tree with conflict-marker blobs embedded for any conflicts.
|
|
80
|
+
*
|
|
81
|
+
* Use `mergeTreesFromTreeHashes` if you already have tree hashes and a
|
|
82
|
+
* known base tree.
|
|
83
|
+
*/
|
|
84
|
+
declare function mergeTrees(repo: GitRepo, oursCommit: string, theirsCommit: string, labels?: {
|
|
85
|
+
ours?: string;
|
|
86
|
+
theirs?: string;
|
|
87
|
+
}): Promise<MergeTreesResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Three-way tree merge from raw tree hashes. Useful when you already
|
|
90
|
+
* have the base/ours/theirs trees and don't want automatic merge-base
|
|
91
|
+
* computation.
|
|
92
|
+
*/
|
|
93
|
+
declare function mergeTreesFromTreeHashes(repo: GitRepo, baseTree: string | null, oursTree: string, theirsTree: string, labels?: {
|
|
94
|
+
ours?: string;
|
|
95
|
+
theirs?: string;
|
|
96
|
+
}): Promise<MergeTreesResult>;
|
|
97
|
+
interface CreateCommitOptions {
|
|
98
|
+
tree: string;
|
|
99
|
+
parents: string[];
|
|
100
|
+
author: Identity;
|
|
101
|
+
committer: Identity;
|
|
102
|
+
message: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a commit object directly in the object store.
|
|
106
|
+
* Returns the new commit's hash.
|
|
107
|
+
*
|
|
108
|
+
* This does not update any refs — call `repo.refStore.writeRef()`
|
|
109
|
+
* separately to advance a branch.
|
|
110
|
+
*/
|
|
111
|
+
declare function createCommit(repo: GitRepo, options: CreateCommitOptions): Promise<string>;
|
|
112
|
+
interface TreeEntryInput {
|
|
113
|
+
name: string;
|
|
114
|
+
hash: string;
|
|
115
|
+
mode?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Build a tree object from a flat list of entries and write it to the
|
|
119
|
+
* object store. Entries default to mode "100644" (regular file).
|
|
120
|
+
*
|
|
121
|
+
* For creating blobs to reference in the tree, write content directly
|
|
122
|
+
* via `repo.objectStore.write("blob", content)`.
|
|
123
|
+
*/
|
|
124
|
+
declare function writeTree(repo: GitRepo, entries: TreeEntryInput[]): Promise<string>;
|
|
125
|
+
/**
|
|
126
|
+
* Write a UTF-8 string as a blob to the object store.
|
|
127
|
+
* Returns the blob's hash.
|
|
128
|
+
*/
|
|
129
|
+
declare function writeBlob(repo: GitRepo, content: string): Promise<string>;
|
|
130
|
+
/**
|
|
131
|
+
* Read a file's content at a specific commit.
|
|
132
|
+
* Returns null if the file doesn't exist at that commit.
|
|
133
|
+
*/
|
|
134
|
+
declare function readFileAtCommit(repo: GitRepo, commitHash: string, filePath: string): Promise<string | null>;
|
|
135
|
+
interface CheckoutToResult {
|
|
136
|
+
commitHash: string;
|
|
137
|
+
treeHash: string;
|
|
138
|
+
filesWritten: number;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Materialize the worktree of a commit onto an arbitrary filesystem.
|
|
142
|
+
*
|
|
143
|
+
* Accepts a ref name ("HEAD", "refs/heads/main") or a raw commit hash.
|
|
144
|
+
* Writes all tracked files under `targetDir` (default "/"). No `.git`
|
|
145
|
+
* directory is created — just the working tree.
|
|
146
|
+
*
|
|
147
|
+
* Useful inside server hooks and platform callbacks to inspect, build,
|
|
148
|
+
* or lint the code at a given commit without affecting the repo itself.
|
|
149
|
+
*/
|
|
150
|
+
declare function checkoutTo(repo: GitRepo, refOrHash: string, fs: FileSystem, targetDir?: string): Promise<CheckoutToResult>;
|
|
151
|
+
interface CreateWorktreeOptions {
|
|
152
|
+
/** Ref name or commit hash to check out (default: "HEAD"). */
|
|
153
|
+
ref?: string;
|
|
154
|
+
/** Root of the working tree on the VFS (default: "/"). */
|
|
155
|
+
workTree?: string;
|
|
156
|
+
/** Path to the `.git` directory on the VFS (default: `<workTree>/.git`). */
|
|
157
|
+
gitDir?: string;
|
|
158
|
+
}
|
|
159
|
+
interface WorktreeResult {
|
|
160
|
+
ctx: GitContext;
|
|
161
|
+
commitHash: string;
|
|
162
|
+
treeHash: string;
|
|
163
|
+
filesWritten: number;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Create a full `GitContext` backed by a repo's abstract stores.
|
|
167
|
+
*
|
|
168
|
+
* Populates the worktree and index on the provided filesystem from
|
|
169
|
+
* a commit, then returns a `GitContext` whose `objectStore` and
|
|
170
|
+
* `refStore` point at the repo's backing stores (e.g. SQLite) while
|
|
171
|
+
* worktree, index, config, and reflog live on the VFS.
|
|
172
|
+
*
|
|
173
|
+
* The returned context can be used directly with lib/ functions.
|
|
174
|
+
* To use it with `createGit()` + `Bash`, pass the repo's stores
|
|
175
|
+
* through `GitOptions.objectStore` / `GitOptions.refStore` so that
|
|
176
|
+
* command handlers use the shared stores instead of the VFS:
|
|
177
|
+
*
|
|
178
|
+
* ```ts
|
|
179
|
+
* const repo = storage.repo("my-repo");
|
|
180
|
+
* const fs = new InMemoryFs();
|
|
181
|
+
* const { ctx } = await createWorktree(repo, fs);
|
|
182
|
+
* const git = createGit({
|
|
183
|
+
* objectStore: repo.objectStore,
|
|
184
|
+
* refStore: repo.refStore,
|
|
185
|
+
* });
|
|
186
|
+
* const bash = new Bash({ fs, cwd: ctx.workTree!, customCommands: [git] });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
declare function createWorktree(repo: GitRepo, fs: FileSystem, options?: CreateWorktreeOptions): Promise<WorktreeResult>;
|
|
190
|
+
/**
|
|
191
|
+
* Wrap a `GitRepo` so all write operations throw.
|
|
192
|
+
*
|
|
193
|
+
* Read operations (readRef, read, exists, listRefs, findByPrefix)
|
|
194
|
+
* pass through to the underlying stores. Write operations (write,
|
|
195
|
+
* writeRef, deleteRef, ingestPack, compareAndSwapRef) throw with
|
|
196
|
+
* a descriptive error.
|
|
197
|
+
*
|
|
198
|
+
* Use with `createWorktree` and/or `GitOptions.objectStore` /
|
|
199
|
+
* `GitOptions.refStore` to enforce read-only access:
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* const ro = readonlyRepo(storage.repo("my-repo"));
|
|
203
|
+
* const { ctx } = await createWorktree(ro, fs, { workTree: "/repo" });
|
|
204
|
+
* const git = createGit({
|
|
205
|
+
* objectStore: ro.objectStore,
|
|
206
|
+
* refStore: ro.refStore,
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
declare function readonlyRepo(repo: GitRepo): GitRepo;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Git object storage: compressed loose objects for new writes, with
|
|
214
|
+
* retained packfiles from fetch/clone. Pack indices are loaded eagerly
|
|
215
|
+
* during discovery for fast hash lookups; pack data is loaded lazily
|
|
216
|
+
* on first read from each pack.
|
|
217
|
+
*/
|
|
218
|
+
declare class PackedObjectStore implements ObjectStore {
|
|
219
|
+
private fs;
|
|
220
|
+
private gitDir;
|
|
221
|
+
private packs;
|
|
222
|
+
private loadedPackNames;
|
|
223
|
+
private discoverPromise;
|
|
224
|
+
private cache;
|
|
225
|
+
private packDir;
|
|
226
|
+
constructor(fs: FileSystem, gitDir: string, cacheMaxBytes?: number);
|
|
227
|
+
write(type: ObjectType, content: Uint8Array): Promise<ObjectId>;
|
|
228
|
+
read(hash: ObjectId): Promise<RawObject>;
|
|
229
|
+
exists(hash: ObjectId): Promise<boolean>;
|
|
230
|
+
ingestPack(packData: Uint8Array): Promise<number>;
|
|
231
|
+
invalidatePacks(): void;
|
|
232
|
+
findByPrefix(prefix: string): Promise<ObjectId[]>;
|
|
233
|
+
/** Load the pack data for a slot on demand. */
|
|
234
|
+
private ensureReader;
|
|
235
|
+
/** Scan `.git/objects/pack/` for existing pack/idx pairs. */
|
|
236
|
+
private discover;
|
|
237
|
+
private doDiscover;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Default filesystem-backed ref storage. Reads/writes loose ref files
|
|
242
|
+
* under `.git/`, with `packed-refs` as fallback for reads and listings.
|
|
243
|
+
*/
|
|
244
|
+
declare class FileSystemRefStore implements RefStore {
|
|
245
|
+
private fs;
|
|
246
|
+
private gitDir;
|
|
247
|
+
private casLocks;
|
|
248
|
+
constructor(fs: FileSystem, gitDir: string);
|
|
249
|
+
readRef(name: string): Promise<Ref | null>;
|
|
250
|
+
writeRef(name: string, ref: Ref): Promise<void>;
|
|
251
|
+
deleteRef(name: string): Promise<void>;
|
|
252
|
+
listRefs(prefix?: string): Promise<RefEntry[]>;
|
|
253
|
+
compareAndSwapRef(name: string, expectedOldHash: string | null, newRef: Ref | null): Promise<boolean>;
|
|
254
|
+
private compareAndSwapUnsafe;
|
|
255
|
+
private resolveRefInternal;
|
|
256
|
+
private readPackedRefs;
|
|
257
|
+
private removePackedRef;
|
|
258
|
+
private walkRefs;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export { type CheckoutToResult, type CommitEntry, type CreateCommitOptions, type CreateWorktreeOptions, FileSystemRefStore, GitRepo, Identity, type MergeConflict, type MergeTreesResult, PackedObjectStore, type TreeEntryInput, type WorktreeResult, checkoutTo, createCommit, createWorktree, diffTrees, findMergeBases, flattenTree, getChangedFiles, getNewCommits, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, readBlob, readBlobText, readCommit, readFileAtCommit, readonlyRepo, resolveRef, writeBlob, writeTree };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var ye=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});function tn(n){if(n==="")return".";if(n==="/")return"/";let e=n.charCodeAt(0)===47,t=n.charCodeAt(n.length-1)===47,r=n.split("/"),s=[];for(let o of r)o===""||o==="."||(o===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(o));let i=s.join("/");return e&&(i=`/${i}`),t&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":t?"./":".")}function v(...n){if(n.length===0)return".";let e=n.filter(t=>t!=="").join("/");return e===""?".":tn(e)}function ve(n){if(n==="")return".";if(n==="/")return"/";let e=n.length;for(;e>1&&n.charCodeAt(e-1)===47;)e--;let t=n.slice(0,e),r=t.lastIndexOf("/");return r===-1?".":r===0?"/":t.slice(0,r)}var ut=(()=>{let n=new Array(256);for(let e=0;e<256;e++)n[e]=(e>>4).toString(16)+(e&15).toString(16);return n})();function se(n){let e="";for(let t=0;t<20;t++)e+=ut[n[t]];return e}function we(n,e){let t="";for(let r=0;r<20;r++)t+=ut[n[e+r]];return t}function q(n){let e=new Uint8Array(20);for(let t=0;t<20;t++)e[t]=parseInt(n.slice(t*2,t*2+2),16);return e}var nn=new TextEncoder;function Le(n){return typeof n=="string"?nn.encode(n):n}function rn(){if(typeof globalThis.Bun<"u")return()=>{let n=new Bun.CryptoHasher("sha1"),e={update(t){return n.update(Le(t)),e},hex:()=>Promise.resolve(n.digest("hex"))};return e};try{let n=ye(["node","crypto"].join(":"));if(typeof n.createHash=="function")return()=>{let e=n.createHash("sha1"),t={update(r){return e.update(Le(r)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let n=[],e={update(t){return n.push(Le(t)),e},async hex(){let t=0;for(let o of n)t+=o.byteLength;let r=new Uint8Array(t),s=0;for(let o of n)r.set(o,s),s+=o.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return se(new Uint8Array(i))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var ht=rn(),xe=ht;async function Ie(n){return ht().update(n).hex()}var sn=1145655875,on=2;async function Ue(n,e){let t=v(n.gitDir,"index"),r=await an(e);await n.fs.writeFile(t,r)}function dt(n){let e=[...n].sort(mt);return{version:on,entries:e}}function ee(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function an(n){let e=[...n.entries].sort(mt),t=12;for(let l of e){let u=62+l.path.length+1;t+=Math.ceil(u/8)*8}t+=20;let r=new ArrayBuffer(t),s=new Uint8Array(r),i=new DataView(r),o=0;i.setUint32(o,sn),o+=4,i.setUint32(o,n.version),o+=4,i.setUint32(o,e.length),o+=4;for(let l of e){let u=o;i.setUint32(o,l.stat.ctimeSeconds),i.setUint32(o+4,l.stat.ctimeNanoseconds),i.setUint32(o+8,l.stat.mtimeSeconds),i.setUint32(o+12,l.stat.mtimeNanoseconds),i.setUint32(o+16,l.stat.dev),i.setUint32(o+20,l.stat.ino),i.setUint32(o+24,l.mode),i.setUint32(o+28,l.stat.uid),i.setUint32(o+32,l.stat.gid),i.setUint32(o+36,l.stat.size),o+=40;let d=q(l.hash);s.set(d,o),o+=20;let h=Math.min(l.path.length,4095),m=(l.stage&3)<<12|h;i.setUint16(o,m),o+=2;let b=new TextEncoder().encode(l.path);s.set(b,o),o+=b.byteLength,s[o]=0,o+=1;let g=62+b.byteLength+1,w=Math.ceil(g/8)*8;o=u+w}let a=s.subarray(0,o),c=await Ie(a),f=q(c);return s.set(f,o),s}function mt(n,e){return n.path<e.path?-1:n.path>e.path?1:n.stage-e.stage}var cn=new Set(["tree","commit","tag"]),Oe=class{map=new Map;currentBytes=0;maxBytes;constructor(e=16*1024*1024){this.maxBytes=e}get(e){return this.map.get(e)}set(e,t){if(!cn.has(t.type))return;let r=t.content.byteLength;if(!(r>this.maxBytes/2)&&!this.map.has(e)){for(;this.currentBytes+r>this.maxBytes&&this.map.size>0;){let s=this.map.keys().next().value;this.currentBytes-=this.map.get(s).content.byteLength,this.map.delete(s)}this.map.set(e,t),this.currentBytes+=r}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}};var pt=new Uint32Array(256);for(let n=0;n<256;n++){let e=n;for(let t=0;t<8;t++)e=e&1?3988292384^e>>>1:e>>>1;pt[n]=e}function gt(n){let e=4294967295;for(let t=0;t<n.byteLength;t++)e=pt[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function fn(){try{let n=ye(["node","zlib"].join(":"));if(typeof n.deflateSync=="function"&&typeof n.inflateSync=="function"){let e;try{let t=n.inflateSync(n.deflateSync(Buffer.from("x")),{info:!0});t?.engine&&typeof t.engine.bytesWritten=="number"&&(e=r=>{let s=n.inflateSync(r,{info:!0});return Promise.resolve({result:new Uint8Array(s.buffer),bytesConsumed:s.engine.bytesWritten})})}catch{}return{deflate:t=>Promise.resolve(new Uint8Array(n.deflateSync(t))),inflate:t=>Promise.resolve(new Uint8Array(n.inflateSync(t))),inflateWithConsumed:e}}}catch{}if(typeof globalThis.CompressionStream=="function"&&typeof globalThis.DecompressionStream=="function")return{async deflate(n){let e=new CompressionStream("deflate"),t=e.writable.getWriter();return t.write(n),t.close(),new Uint8Array(await new Response(e.readable).arrayBuffer())},async inflate(n){let e=new DecompressionStream("deflate"),t=e.writable.getWriter();return t.write(n),t.close(),new Uint8Array(await new Response(e.readable).arrayBuffer())}};throw new Error("No zlib implementation available. Requires Bun, Node.js, Deno, or a browser with CompressionStream.")}var Be=fn(),De=Be.deflate,J=Be.inflate,He=Be.inflateWithConsumed;var bt=1346454347,ln=2,un=1,hn=2,dn=3,mn=4,Pe=6,Fe=7,pn={[un]:"commit",[hn]:"tree",[dn]:"blob",[mn]:"tag"};async function wt(n,e){let t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=t.getUint32(0);if(r!==bt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${bt.toString(16)})`);let s=t.getUint32(4);if(s!==ln)throw new Error(`Unsupported pack version: ${s}`);let i=t.getUint32(8),o=[],a=12;for(let f=0;f<i;f++){let l=await gn(n,a);o.push(l),a=l.nextOffset}return(await bn(o,e)).map((f,l)=>({...f,offset:o[l].headerOffset,nextOffset:o[l].nextOffset}))}async function gn(n,e){let t=e,r=n[e++],s=r>>4&7,i=r&15,o=4;for(;r&128;)r=n[e++],i|=(r&127)<<o,o+=7;let a,c;if(s===Pe){let u=n[e++];for(a=u&127;u&128;)a+=1,u=n[e++],a=(a<<7)+(u&127);a=t-a}else s===Fe&&(c=we(n,e),e+=20);let{result:f,bytesConsumed:l}=await wn(n,e,i);return{headerOffset:t,typeNum:s,inflated:f,baseOffset:a,baseHash:c,nextOffset:e+l}}async function bn(n,e){let t=new Map;for(let i=0;i<n.length;i++)t.set(n[i].headerOffset,i);let r=new Array(n.length).fill(null);async function s(i){let o=r[i];if(o)return o;let a=n[i];if(a.typeNum!==Pe&&a.typeNum!==Fe){let d=pn[a.typeNum];if(!d)throw new Error(`Unknown object type: ${a.typeNum}`);let h={type:d,content:a.inflated,hash:await Ne(d,a.inflated)};return r[i]=h,h}if(a.typeNum===Pe){let d=t.get(a.baseOffset);if(d===void 0)throw new Error(`OFS_DELTA base not found at offset ${a.baseOffset}`);let h=await s(d),m=he(h.content,a.inflated),b={type:h.type,content:m,hash:await Ne(h.type,m)};return r[i]=b,b}let c=await yn(n,r,a.baseHash,s),f;if(c!==void 0)f=await s(c);else if(e){let d=await e(a.baseHash);d&&(f=d)}if(!f)throw new Error(`REF_DELTA base not found for hash ${a.baseHash}`);let l=he(f.content,a.inflated),u={type:f.type,content:l,hash:await Ne(f.type,l)};return r[i]=u,u}for(let i=0;i<n.length;i++)await s(i);return r}async function yn(n,e,t,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===t)return s;for(let s=0;s<n.length;s++){let i=n[s];if(i.typeNum!==Pe&&i.typeNum!==Fe&&(await r(s)).hash===t)return s}}function he(n,e){let t=0,{value:r,newPos:s}=yt(e,t);if(t=s,r!==n.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${n.byteLength}`);let{value:i,newPos:o}=yt(e,t);t=o;let a=new Uint8Array(i),c=0;for(;t<e.byteLength;){let f=e[t++];if(f&128){let l=0,u=0;f&1&&(l=e[t++]),f&2&&(l|=e[t++]<<8),f&4&&(l|=e[t++]<<16),f&8&&(l|=e[t++]<<24),f&16&&(u=e[t++]),f&32&&(u|=e[t++]<<8),f&64&&(u|=e[t++]<<16),u===0&&(u=65536),a.set(n.subarray(l,l+u),c),c+=u}else if(f>0)a.set(e.subarray(t,t+f),c),c+=f,t+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return a}function yt(n,e){let t=0,r=0,s;do s=n[e++],t|=(s&127)<<r,r+=7;while(s&128);return{value:t,newPos:e}}async function wn(n,e,t){let r=n.subarray(e);if(He){let{result:a,bytesConsumed:c}=await He(r);if(a.byteLength!==t)throw new Error(`Inflate size mismatch: got ${a.byteLength}, expected ${t}`);return{result:a,bytesConsumed:c}}let s=await J(r);if(s.byteLength!==t)throw new Error(`Inflate size mismatch: got ${s.byteLength}, expected ${t}`);let i=2,o=r.byteLength;for(;i<o;){let a=i+o>>>1;try{(await J(r.subarray(0,a))).byteLength===t?o=a:i=a+1}catch{i=a+1}}return{result:s,bytesConsumed:i}}var xn=new TextEncoder;async function Ne(n,e){let t=xn.encode(`${n} ${e.byteLength}\0`),r=xe();return r.update(t),r.update(e),r.hex()}var xt=4285812579,It=2,te=class{fanout;hashes;offsets;largeOffsets;count;constructor(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0)!==xt)throw new Error("Invalid pack index: bad magic");if(t.getUint32(4)!==It)throw new Error(`Unsupported pack index version: ${t.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let i=0;i<256;i++)this.fanout[i]=t.getUint32(r),r+=4;this.count=this.fanout[255],this.hashes=new Uint8Array(e.buffer,e.byteOffset+r,this.count*20),r+=this.count*20,r+=this.count*4,this.offsets=new Uint32Array(this.count);for(let i=0;i<this.count;i++)this.offsets[i]=t.getUint32(r),r+=4;let s=!1;for(let i=0;i<this.count;i++)if(this.offsets[i]&2147483648){s=!0;break}this.largeOffsets=s?new DataView(e.buffer,e.byteOffset+r):null}lookup(e){let t=q(e),r=t[0],s=r===0?0:this.fanout[r-1],i=this.fanout[r],o=s,a=i;for(;o<a;){let c=o+a>>>1,f=this.compareAt(c,t);if(f<0)o=c+1;else if(f>0)a=c;else return this.getOffset(c)}return null}has(e){return this.lookup(e)!==null}get objectCount(){return this.count}allHashes(){let e=[];for(let t=0;t<this.count;t++)e.push(this.hashAtSlot(t));return e}findByPrefix(e){if(e.length<2)return[];let t=parseInt(e.slice(0,2),16),r=t===0?0:this.fanout[t-1],s=this.fanout[t],i=q(e.padEnd(40,"0")),o=e.length,a=[];for(let c=r;c<s;c++){let f=c*20,l=!0;for(let u=0;u<o;u++){let d=u%2===0?this.hashes[f+(u>>1)]>>4&15:this.hashes[f+(u>>1)]&15,h=u%2===0?i[u>>1]>>4&15:i[u>>1]&15;if(d!==h){l=!1;break}}l&&a.push(this.hashAtSlot(c))}return a}hashAtSlot(e){let t="",r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s];t+=(i>>4).toString(16)+(i&15).toString(16)}return t}compareAt(e,t){let r=e*20;for(let s=0;s<20;s++){let i=this.hashes[r+s],o=t[s];if(i<o)return-1;if(i>o)return 1}return 0}getOffset(e){let t=this.offsets[e];if(t&2147483648){let r=t&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return t}};async function In(n,e){let t=[...n].sort((h,m)=>h.hash<m.hash?-1:h.hash>m.hash?1:0),r=t.length,s=[];for(let h of t)h.offset>=2147483648&&s.push(BigInt(h.offset));let i=8+256*4+r*20+r*4+r*4+s.length*8+20+20,o=new Uint8Array(i),a=new DataView(o.buffer),c=0;a.setUint32(c,xt),c+=4,a.setUint32(c,It),c+=4;let f=new Uint32Array(256);for(let h of t){let m=parseInt(h.hash.slice(0,2),16);for(let b=m;b<256;b++)f[b]++}for(let h=0;h<256;h++)a.setUint32(c,f[h]),c+=4;for(let h of t)o.set(q(h.hash),c),c+=20;for(let h of t)a.setUint32(c,h.crc),c+=4;let l=0;for(let h of t)h.offset>=2147483648?a.setUint32(c,2147483648|l++):a.setUint32(c,h.offset),c+=4;for(let h of s)a.setBigUint64(c,h),c+=8;o.set(e,c),c+=20;let u=xe();u.update(o.subarray(0,c));let d=await u.hex();return o.set(q(d),c),o}async function Ot(n){let t=(await wt(n)).map(s=>({hash:s.hash,offset:s.offset,crc:gt(n.subarray(s.offset,s.nextOffset))})),r=n.subarray(n.byteLength-20);return In(t,r)}var On=6,Pn=7,Rn={1:"commit",2:"tree",3:"blob",4:"tag"},de=class{constructor(e,t){this.data=e;this.index=t instanceof te?t:new te(t)}index;hasObject(e){return this.index.has(e)}findByPrefix(e){return this.index.findByPrefix(e)}async readObject(e){let t=this.index.lookup(e);return t===null?null:this.readAt(t)}get objectCount(){return this.index.objectCount}async readAt(e){let t=this.data,r=e,s=t[r++],i=s>>4&7,o=s&15,a=4;for(;s&128;)s=t[r++],o|=(s&127)<<a,a+=7;if(i===On){let l=t[r++],u=l&127;for(;l&128;)u+=1,l=t[r++],u=(u<<7)+(l&127);let d=await J(t.subarray(r)),h=await this.readAt(e-u);return{type:h.type,content:he(h.content,d)}}if(i===Pn){let l=we(t,r);r+=20;let u=await J(t.subarray(r)),d=this.index.lookup(l);if(d===null)throw new Error(`REF_DELTA base ${l} not found in pack`);let h=await this.readAt(d);return{type:h.type,content:he(h.content,u)}}let c=Rn[i];if(!c)throw new Error(`Unknown pack object type: ${i}`);let f=await J(t.subarray(r));if(f.byteLength!==o)throw new Error(`Pack inflate size mismatch at offset ${e}: got ${f.byteLength}, expected ${o}`);return{type:c,content:f}}};var kn=new TextEncoder,En=new TextDecoder;function Tn(n,e){let t=kn.encode(`${n} ${e.byteLength}\0`),r=new Uint8Array(t.byteLength+e.byteLength);return r.set(t),r.set(e,t.byteLength),r}function Sn(n,e){let t=e.indexOf(0);if(t===-1)throw new Error(`Corrupt object ${n}: no null byte in header`);let r=En.decode(e.subarray(0,t)),s=r.indexOf(" ");if(s===-1)throw new Error(`Corrupt object ${n}: malformed header "${r}"`);let i=r.slice(0,s),o=parseInt(r.slice(s+1),10),a=e.subarray(t+1);if(a.byteLength!==o)throw new Error(`Corrupt object ${n}: expected ${o} bytes, got ${a.byteLength}`);return{type:i,content:a}}function Ge(n,e){return v(n,"objects",e.slice(0,2),e.slice(2))}var _e=class{constructor(e,t,r){this.fs=e;this.gitDir=t;this.cache=new Oe(r),this.packDir=v(t,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(e,t){let r=Tn(e,t),s=await Ie(r),i=Ge(this.gitDir,s);if(await this.fs.exists(i))return s;let o=v(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(o,{recursive:!0}),await this.fs.writeFile(i,await De(r)),s}async read(e){let t=this.cache.get(e);if(t)return t;let r=Ge(this.gitDir,e);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),i=await J(s),o=Sn(e,i);return this.cache.set(e,o),o}await this.discover();for(let s of this.packs){if(!s.index.has(e))continue;let o=await(await this.ensureReader(s)).readObject(e);if(o)return this.cache.set(e,o),o}throw new Error(`object ${e} not found`)}async exists(e){if(await this.fs.exists(Ge(this.gitDir,e)))return!0;await this.discover();for(let t of this.packs)if(t.index.has(e))return!0;return!1}async ingestPack(e){if(e.byteLength<32)return 0;let r=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8);if(r===0)return 0;let s=e.subarray(e.byteLength-20),i=se(s);await this.fs.mkdir(this.packDir,{recursive:!0});let o=`pack-${i}`,a=v(this.packDir,`${o}.pack`);await this.fs.writeFile(a,e);let c=await Ot(e),f=v(this.packDir,`${o}.idx`);await this.fs.writeFile(f,c),this.loadedPackNames.add(o);let l=new te(c);return this.packs.push({name:o,index:l,reader:new de(e,l)}),r}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(e){if(e.length<4)return[];let t=e.slice(0,2),r=e.slice(2),s=v(this.gitDir,"objects",t),i=[];if(await this.fs.exists(s)){let o=await this.fs.readdir(s);for(let a of o)a.startsWith(r)&&i.push(`${t}${a}`)}await this.discover();for(let o of this.packs)for(let a of o.index.findByPrefix(e))i.includes(a)||i.push(a);return i}async ensureReader(e){if(e.reader)return e.reader;let t=v(this.packDir,`${e.name}.pack`),r=await this.fs.readFileBuffer(t);return e.reader=new de(r,e.index),e.reader}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){if(!await this.fs.exists(this.packDir))return;let e=await this.fs.readdir(this.packDir);for(let t of e){if(!t.endsWith(".idx"))continue;let r=t.slice(0,-4);if(this.loadedPackNames.has(r))continue;let s=v(this.packDir,`${r}.pack`);if(!await this.fs.exists(s))continue;let i=await this.fs.readFileBuffer(v(this.packDir,t));this.loadedPackNames.add(r),this.packs.push({name:r,index:new te(i),reader:null})}}};function We(n){let e=n.indexOf("<"),t=n.indexOf(">");if(e===-1||t===-1)throw new Error(`Malformed identity line: "${n}"`);let r=n.slice(0,e).trimEnd(),s=n.slice(e+1,t),i=n.slice(t+2),[o="0",a="+0000"]=i.split(" "),c=parseInt(o,10);return{name:r,email:s,timestamp:c,timezone:a}}function ze(n){return`${n.name} <${n.email}> ${n.timestamp} ${n.timezone}`}var jn=new TextEncoder,Cn=new TextDecoder;function Pt(n){let e=Cn.decode(n),t=e.indexOf(`
|
|
2
|
+
|
|
3
|
+
`),r=t===-1?e:e.slice(0,t),s=t===-1?"":e.slice(t+2),i="",o=[],a,c;for(let f of r.split(`
|
|
4
|
+
`)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),d=f.slice(l+1);switch(u){case"tree":i=d;break;case"parent":o.push(d);break;case"author":a=We(d);break;case"committer":c=We(d);break}}if(!i)throw new Error("Commit missing tree field");if(!a)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:o,author:a,committer:c,message:s}}function Re(n){let e=[];e.push(`tree ${n.tree}`);for(let t of n.parents)e.push(`parent ${t}`);return e.push(`author ${ze(n.author)}`),e.push(`committer ${ze(n.committer)}`),e.push(""),e.push(n.message),jn.encode(e.join(`
|
|
5
|
+
`))}async function N(n,e,t){let r=await n.objectStore.write(e,t);return n.hooks?.onObjectWrite?.({repo:n,type:e,hash:r}),r}async function V(n,e){return n.objectStore.read(e)}function Z(n){let e=Math.min(n.length,8e3);for(let t=0;t<e;t++)if(n.charCodeAt(t)===0)return!0;return!1}var An=new TextDecoder;async function F(n,e){let t=await V(n,e);if(t.type!=="blob")throw new Error(`Expected blob for ${e}, got ${t.type}`);return An.decode(t.content)}async function Q(n,e){let t=await V(n,e);if(t.type!=="blob")throw new Error(`Expected blob for ${e}, got ${t.type}`);return t.content}async function U(n,e){let t=await V(n,e);if(t.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${t.type}`);return Pt(t.content)}var Ve="ref: ",Rt=10,Ke=class{constructor(e,t){this.fs=e;this.gitDir=t}casLocks=new Map;async readRef(e){let t=v(this.gitDir,e);if(await this.fs.exists(t)){let i=(await this.fs.readFile(t)).trim();return i.startsWith(Ve)?{type:"symbolic",target:i.slice(Ve.length)}:{type:"direct",hash:i}}let s=(await this.readPackedRefs()).get(e);return s?{type:"direct",hash:s}:null}async writeRef(e,t){let r=v(this.gitDir,e);await kt(this.fs,r),t.type==="symbolic"?await this.fs.writeFile(r,`${Ve}${t.target}
|
|
6
|
+
`):await this.fs.writeFile(r,`${t.hash}
|
|
7
|
+
`)}async deleteRef(e){let t=v(this.gitDir,e);await this.fs.exists(t)&&await this.fs.rm(t),await this.removePackedRef(e)}async listRefs(e="refs"){let t=[],r=v(this.gitDir,e);await this.fs.exists(r)&&await this.walkRefs(r,e,t);let s=await this.readPackedRefs();if(s.size>0){let i=new Set(t.map(a=>a.name)),o=`${e}/`;for(let[a,c]of s)a.startsWith(o)&&!i.has(a)&&t.push({name:a,hash:c})}return t.sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async compareAndSwapRef(e,t,r){let i=(this.casLocks.get(e)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(e,t,r),()=>this.compareAndSwapUnsafe(e,t,r));this.casLocks.set(e,i);try{return await i}finally{this.casLocks.get(e)===i&&this.casLocks.delete(e)}}async compareAndSwapUnsafe(e,t,r){let s=await this.resolveRefInternal(e);if(t===null){if(await this.readRef(e)!==null)return!1}else if(s!==t)return!1;return r===null?await this.deleteRef(e):await this.writeRef(e,r),!0}async resolveRefInternal(e){let t=e;for(let r=0;r<Rt;r++){let s=await this.readRef(t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async readPackedRefs(){let e=v(this.gitDir,"packed-refs");if(!await this.fs.exists(e))return new Map;let t=await this.fs.readFile(e),r=new Map;for(let s of t.split(`
|
|
8
|
+
`)){if(!s||s.startsWith("#")||s.startsWith("^"))continue;let i=s.indexOf(" ");if(i===-1)continue;let o=s.slice(0,i),a=s.slice(i+1).trim();o.length===40&&a&&r.set(a,o)}return r}async removePackedRef(e){let t=v(this.gitDir,"packed-refs");if(!await this.fs.exists(t))return;let s=(await this.fs.readFile(t)).split(`
|
|
9
|
+
`),i=[],o=!1;for(let c of s){if(o&&c.startsWith("^")){o=!1;continue}if(o=!1,!c||c.startsWith("#")){i.push(c);continue}let f=c.indexOf(" ");if(f!==-1&&c.slice(f+1).trim()===e){o=!0;continue}i.push(c)}i.some(c=>c&&!c.startsWith("#")&&!c.startsWith("^"))?await this.fs.writeFile(t,i.join(`
|
|
10
|
+
`)):await this.fs.rm(t)}async walkRefs(e,t,r){let s=await this.fs.readdir(e);for(let i of s){let o=v(e,i),a=`${t}/${i}`,c=await this.fs.stat(o);if(c.isDirectory)await this.walkRefs(o,a,r);else if(c.isFile){let f=await this.resolveRefInternal(a);f&&r.push({name:a,hash:f})}}}};async function $n(n,e){return n.refStore.readRef(e)}async function ke(n,e){let t=e;for(let r=0;r<Rt;r++){let s=await $n(n,t);if(!s)return null;if(s.type==="direct")return s.hash;t=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function qe(n,e="refs"){return n.refStore.listRefs(e)}async function kt(n,e){let t=e.lastIndexOf("/");if(t>0){let r=e.slice(0,t);await n.mkdir(r,{recursive:!0})}}var vs=new TextEncoder;function Y(n){return typeof n=="string"?n==="120000":n===40960}var Mn=new TextEncoder,Et=new TextDecoder;function Tt(n){let e=[],t=0;for(;t<n.byteLength;){let r=n.indexOf(32,t);if(r===-1)break;let s=Et.decode(n.subarray(t,r)),i=n.indexOf(0,r+1);if(i===-1)break;let o=Et.decode(n.subarray(r+1,i)),a=n.subarray(i+1,i+21),c=se(a),f=s.padStart(6,"0");e.push({mode:f,name:o,hash:c}),t=i+21}return{type:"tree",entries:e}}function Ee(n){let e=[];for(let i of n.entries){let o=i.mode.replace(/^0+/,""),a=Mn.encode(`${o} ${i.name}\0`),c=q(i.hash);e.push(a),e.push(c)}let t=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(t),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}var me={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};async function Ye(n,e){return St(n,e,"")}async function St(n,e,t){let r=[],s=new Map;for(let o of e){let a=t?o.path.slice(t.length+1):o.path,c=a.indexOf("/");if(c===-1)r.push({mode:vn(o.mode),name:a,hash:o.hash});else{let f=a.slice(0,c),l=s.get(f);l||(l=[],s.set(f,l)),l.push(o)}}for(let[o,a]of s){let c=t?`${t}/${o}`:o,f=await St(n,a,c);r.push({mode:me.DIRECTORY,name:o,hash:f})}r.sort((o,a)=>{let c=o.mode===me.DIRECTORY?`${o.name}/`:o.name,f=a.mode===me.DIRECTORY?`${a.name}/`:a.name;return c<f?-1:c>f?1:0});let i=Ee({type:"tree",entries:r});return N(n,"tree",i)}async function ie(n,e,t=""){let r=await V(n,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=Tt(r.content),i=[];for(let o of s.entries){let a=t?`${t}/${o.name}`:o.name;if(o.mode===me.DIRECTORY){let c=await ie(n,o.hash,a);i.push(...c)}else i.push({path:a,mode:o.mode,hash:o.hash})}return i}async function ae(n,e){if(!e)return new Map;let t=await ie(n,e);return new Map(t.map(r=>[r.path,r]))}async function Xe(n,e,t){let r=await ae(n,e),s=await ae(n,t),i=[];for(let[o,a]of r){let c=s.get(o);c?(a.hash!==c.hash||a.mode!==c.mode)&&i.push({path:o,status:"modified",oldHash:a.hash,newHash:c.hash,oldMode:a.mode,newMode:c.mode}):i.push({path:o,status:"deleted",oldHash:a.hash,oldMode:a.mode})}for(let[o,a]of s)r.has(o)||i.push({path:o,status:"added",newHash:a.hash,newMode:a.mode});return i.sort((o,a)=>pe(o.path,a.path))}function vn(n){return n.toString(8).padStart(6,"0")}function jt(n){return{stdout:"",stderr:`fatal: ${n}
|
|
11
|
+
`,exitCode:128}}var Ws=jt("not a git repository (or any of the parent directories): .git"),zs=jt("this operation must be run in a work tree");function pe(n,e){return n<e?-1:n>e?1:0}var Je=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let t=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),t.entry}higher(e,t){let r=e.entry.commit.committer.timestamp,s=t.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<t.epoch}siftUp(e){let{heap:t}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(t[e],t[r]))break;[t[r],t[e]]=[t[e],t[r]],e=r}}siftDown(e){let{heap:t}=this,r=t.length;for(;;){let s=e,i=2*e+1,o=2*e+2;if(i<r&&this.higher(t[i],t[s])&&(s=i),o<r&&this.higher(t[o],t[s])&&(s=o),s===e)break;[t[e],t[s]]=[t[s],t[e]],e=s}}};async function*Ze(n,e,t){let r=await Ln(n,t?.exclude),s=new Set(r),i=new Je,o=Array.isArray(e)?e:[e];for(let a of o)s.has(a)||i.push(await Ct(n,a));for(;i.size>0;){let a=i.pop();if(!s.has(a.hash)){s.add(a.hash),yield a;for(let c of a.commit.parents)s.has(c)||i.push(await Ct(n,c))}}}async function Ln(n,e){if(!e||e.length===0)return new Set;let t=new Set;for await(let r of Ze(n,e))t.add(r.hash);return t}async function Ct(n,e){return{hash:e,commit:await U(n,e)}}var Un=4,At=1024,Te=100,Ce=0,Se=1,ce=2;function et(n){let e=1;for(;e*e<n;)e++;return e}function Bn(n,e){let t=new Map,r=[],s=new Array(n.length),i=new Array(e.length);for(let o=0;o<n.length;o++){let a=n[o],c=t.get(a);c===void 0&&(c=r.length,t.set(a,c),r.push({len1:0,len2:0})),r[c].len1++,s[o]=c}for(let o=0;o<e.length;o++){let a=e[o],c=t.get(a);c===void 0&&(c=r.length,t.set(a,c),r.push({len1:0,len2:0})),r[c].len2++,i[o]=c}return{classes1:s,classes2:i,classInfo:r}}function Dn(n,e,t,r){let s=0,i=Math.min(e,r);for(;s<i&&n[s]===t[s];)s++;let o=s,a=0,c=i-o;for(;a<c&&n[e-1-a]===t[r-1-a];)a++;return{dstart:o,dend1:e-a-1,dend2:r-a-1}}function $t(n,e,t,r){e-t>Te&&(t=e-Te),r-e>Te&&(r=e+Te);let s=0,i=1;for(let c=1;e-c>=t;c++){let f=n[e-c];if(f===Ce)s++;else if(f===ce)i++;else break}if(s===0)return!1;let o=0,a=1;for(let c=1;e+c<=r;c++){let f=n[e+c];if(f===Ce)o++;else if(f===ce)a++;else break}return o===0?!1:(o+=s,a+=i,a*Un<a+o)}function Hn(n,e,t,r,s,i,o,a,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),d=Math.min(et(e),At);for(let g=i;g<=o;g++){let w=s[n[g]].len2;w===0?l[g]=Ce:w>=d?l[g]=ce:l[g]=Se}let h=Math.min(et(r),At);for(let g=i;g<=a;g++){let w=s[t[g]].len1;w===0?u[g]=Ce:w>=h?u[g]=ce:u[g]=Se}let m=[];for(let g=i;g<=o;g++)l[g]===Se||l[g]===ce&&!$t(l,g,i,o)?m.push(g):c[g]=1;let b=[];for(let g=i;g<=a;g++)u[g]===Se||u[g]===ce&&!$t(u,g,i,a)?b.push(g):f[g]=1;return{refIndex1:m,nreff1:m.length,refIndex2:b,nreff2:b.length}}var ne=20,Mt=4,Nn=256,Fn=256,je=2147483647;function G(n,e){return n[e]??0}function Gn(n,e,t,r,s,i,o,a,c,f){let l=e-i,u=t-s,d=e-s,h=t-i,m=d-h&1,b=d,g=d,w=h,R=h;o[d]=e,a[h]=t;for(let j=1;;j++){let C=!1;b>l?o[--b-1]=-1:++b,g<u?o[++g+1]=-1:--g;for(let I=g;I>=b;I-=2){let x;G(o,I-1)>=G(o,I+1)?x=G(o,I-1)+1:x=G(o,I+1);let T=x,L=x-I;for(;x<t&&L<i&&n[x]===r[L];)x++,L++;if(x-T>ne&&(C=!0),o[I]=x,m&&w<=I&&I<=R&&G(a,I)<=x)return{i1:x,i2:L,minLo:!0,minHi:!0}}w>l?a[--w-1]=je:++w,R<u?a[++R+1]=je:--R;for(let I=R;I>=w;I-=2){let x;G(a,I-1)<G(a,I+1)?x=G(a,I-1):x=G(a,I+1)-1;let T=x,L=x-I;for(;x>e&&L>s&&n[x-1]===r[L-1];)x--,L--;if(T-x>ne&&(C=!0),a[I]=x,!m&&b<=I&&I<=g&&x<=G(o,I))return{i1:x,i2:L,minLo:!0,minHi:!0}}if(!c){if(C&&j>Nn){let I=0,x=null;for(let T=g;T>=b;T-=2){let L=T>d?T-d:d-T,A=G(o,T),E=A-T,$=A-e+(E-s)-L;if($>Mt*j&&$>I&&e+ne<=A&&A<t&&s+ne<=E&&E<i){let X=!0;for(let K=1;K<=ne;K++)if(n[A-K]!==r[E-K]){X=!1;break}X&&(I=$,x={i1:A,i2:E,minLo:!0,minHi:!1})}}if(x)return x;I=0,x=null;for(let T=R;T>=w;T-=2){let L=T>h?T-h:h-T,A=G(a,T),E=A-T,$=t-A+(i-E)-L;if($>Mt*j&&$>I&&e<A&&A<=t-ne&&s<E&&E<=i-ne){let X=!0;for(let K=0;K<ne;K++)if(n[A+K]!==r[E+K]){X=!1;break}X&&(I=$,x={i1:A,i2:E,minLo:!1,minHi:!0})}}if(x)return x}if(j>=f){let I=-1,x=-1;for(let A=g;A>=b;A-=2){let E=Math.min(G(o,A),t),$=E-A;i<$&&(E=i+A,$=i),I<E+$&&(I=E+$,x=E)}let T=je,L=je;for(let A=R;A>=w;A-=2){let E=Math.max(e,G(a,A)),$=E-A;$<s&&(E=s+A,$=s),E+$<T&&(T=E+$,L=E)}return t+i-T<I-(e+s)?{i1:x,i2:I-x,minLo:!0,minHi:!1}:{i1:L,i2:T-L,minLo:!1,minHi:!0}}}}}function tt(n,e,t,r,s,i,o,a,c,f,l,u,d,h){for(;e<t&&s<i&&n[e]===r[s];)e++,s++;for(;e<t&&s<i&&n[t-1]===r[i-1];)t--,i--;if(e===t)for(let m=s;m<i;m++)a[f[m]]=1;else if(s===i)for(let m=e;m<t;m++)o[c[m]]=1;else{let m=Gn(n,e,t,r,s,i,l,u,d,h);tt(n,e,m.i1,r,s,m.i2,o,a,c,f,l,u,m.minLo,h),tt(n,m.i1,t,r,m.i2,i,o,a,c,f,l,u,m.minHi,h)}}var vt=200,Lt=20,Ut=100,_n=1,Wn=21,zn=-30,Vn=6,Kn=-4,qn=10,Yn=24,Xn=17,Jn=23,Zn=17,Qn=60;function Qe(n){let e=0;for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);if(r===32)e+=1;else if(r===9)e+=8-e%8;else if(!(r===10||r===13||r===11||r===12))return e;if(e>=vt)return vt}return-1}function Bt(n,e,t){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};t>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=Qe(n[t]));for(let s=t-1;s>=0&&(r.preIndent=Qe(n[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===Lt){r.preIndent=0;break}for(let s=t+1;s<e&&(r.postIndent=Qe(n[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===Lt){r.postIndent=0;break}return r}function Dt(n,e){n.preIndent===-1&&n.preBlank===0&&(e.penalty+=_n),n.endOfFile&&(e.penalty+=Wn);let t=n.indent===-1?1+n.postBlank:0,r=n.preBlank+t;e.penalty+=zn*r,e.penalty+=Vn*t;let s=n.indent!==-1?n.indent:n.postIndent,i=r!==0;e.effectiveIndent+=s,s===-1||n.preIndent===-1||(s>n.preIndent?e.penalty+=i?qn:Kn:s===n.preIndent||(n.postIndent!==-1&&n.postIndent>s?e.penalty+=i?Xn:Yn:e.penalty+=i?Zn:Jn))}function er(n,e){let t=(n.effectiveIndent>e.effectiveIndent?1:0)-(n.effectiveIndent<e.effectiveIndent?1:0);return Qn*t+(n.penalty-e.penalty)}function Ht(n,e,t,r,s,i){let o=0,a=0;for(;n[a];)a++;let c=0,f=0;for(;s[f];)f++;let l=(u,d)=>e[u]===e[d];for(;;){if(a!==o){let u,d,h;do{for(u=a-o,d=-1;o>0&&l(o-1,a-1);){for(n[--o]=1,n[--a]=0;n[o-1];)o--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(h=a,f>c&&(d=a);!(a>=r||!l(o,a));){for(n[o++]=0,n[a++]=1;n[a];)a++;if(f>=i)break;for(c=f+1,f=c;s[f];f++);f>c&&(d=a)}}while(u!==a-o);if(a!==h)if(d!==-1)for(;f===c;){for(n[--a]=0,n[--o]=1;n[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}else{let m=-1,b={effectiveIndent:0,penalty:0},g=h;for(a-u-1>g&&(g=a-u-1),a-Ut>g&&(g=a-Ut);g<=a;g++){let w={effectiveIndent:0,penalty:0},R=Bt(t,r,g);Dt(R,w);let j=Bt(t,r,g-u);Dt(j,w),(m===-1||er(w,b)<=0)&&(b={effectiveIndent:w.effectiveIndent,penalty:w.penalty},m=g)}for(;a>m;){for(n[--a]=0,n[--o]=1;n[o-1];)o--;for(f=c-1,c=f;s[c-1];c--);}}}if(a>=r)break;for(o=a+1,a=o;n[a];a++);if(f>=i)break;for(c=f+1,f=c;s[f];f++);}}function Nt(n,e){let t=n.length,r=e.length,s=new Uint8Array(t),i=new Uint8Array(r);if(t>0&&r>0){let{classes1:o,classes2:a,classInfo:c}=Bn(n,e),{dstart:f,dend1:l,dend2:u}=Dn(o,t,a,r);if(f>l)for(let d=f;d<r-(t-1-l);d++)i[d]=1;else if(f>u)for(let d=f;d<t-(r-1-u);d++)s[d]=1;else{let{refIndex1:d,nreff1:h,refIndex2:m,nreff2:b}=Hn(o,t,a,r,c,f,l,u,s,i);if(h>0&&b>0){let g=new Array(h);for(let x=0;x<h;x++)g[x]=o[d[x]];let w=new Array(b);for(let x=0;x<b;x++)w[x]=a[m[x]];let R={},j={},C=h+b+3,I=Math.max(Fn,et(C));tt(g,0,h,w,0,b,s,i,d,m,R,j,!1,I)}else if(h===0)for(let g=0;g<b;g++)i[m[g]]=1;else for(let g=0;g<h;g++)s[d[g]]=1;Ht(s,o,n,t,i,r),Ht(i,a,e,r,s,t)}}else t===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function fe(n){let e=n.lastIndexOf("/");return e>=0?n.slice(e+1):n}function tr(n,e){if(n.length===0)return;if(n.length===1)return n.shift();let t=fe(e),r=0;for(let s=0;s<n.length;s++){let i=n[s];if(i&&fe(i.path)===t){r=s;break}}return n.splice(r,1)[0]}var nr=50;async function nt(n,e,t=nr){let r=new Map,s=[],i=[],o=[];for(let l of e)if(l.status==="deleted"&&l.oldHash){let u=r.get(l.oldHash)??[];u.push(l),r.set(l.oldHash,u),s.push(l)}else l.status==="added"&&l.newHash?i.push(l):o.push(l);let a=[],c=[];for(let l of i){let u=l.newHash;if(!u){c.push(l);continue}let d=r.get(u);if(d&&d.length>0){let h=tr(d,l.path);h&&a.push({oldPath:h.path,newPath:l.path,oldHash:h.oldHash??u,newHash:u,similarity:100,oldMode:h.oldMode,newMode:l.newMode})}else c.push(l)}let f=[...r.values()].flat();if(f.length>0&&c.length>0){let l=await rr(n,f,c,t);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}if(f.length>0&&c.length>0){let l=await or(n,f,c,t);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),d=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!d.has(h.path)),a.push(...l)}}return{remaining:[...o,...f,...c],renames:a}}async function rr(n,e,t,r){let s=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c)continue;let f=fe(c.path);s.has(f)?s.set(f,-1):s.set(f,a)}let i=new Map;for(let a=0;a<t.length;a++){let c=t[a];if(!c)continue;let f=fe(c.path);i.has(f)?i.set(f,-1):i.set(f,a)}let o=[];for(let[a,c]of s){if(c===-1)continue;let f=i.get(a);if(f===void 0||f===-1)continue;let l=e[c],u=t[f];if(!l?.oldHash||!u?.newHash||l.oldHash===u.newHash)continue;let d=await Q(n,l.oldHash),h=await Q(n,u.newHash),m=ir(d,h);m<r||o.push({oldPath:l.path,newPath:u.path,oldHash:l.oldHash,newHash:u.newHash,similarity:m,oldMode:l.oldMode,newMode:u.newMode})}return o}var Ft=107927;function Ae(n){let e=new Map,t=0,r=0,s=0;for(let o=0;o<n.length;o++){let a=n[o],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,t++,t<64&&a!==10)continue;let f=(r+Math.imul(s,97))%Ft;e.set(f,(e.get(f)??0)+t),t=0,r=0,s=0}if(t>0){let o=(r+Math.imul(s,97))%Ft;e.set(o,(e.get(o)??0)+t)}let i=[];for(let[o,a]of e)i.push({hash:o,count:a});return i.sort((o,a)=>o.hash-a.hash),i}function sr(n,e){let t=0,r=0,s=0,i=0;for(;s<n.length;){let o=n[s];if(!o)break;for(;i<e.length;){let f=e[i];if(!f||f.hash>=o.hash)break;r+=f.count,i++}let a=o.count,c=0;if(i<e.length){let f=e[i];f&&f.hash===o.hash&&(c=f.count,i++)}a<c?(r+=c-a,t+=a):t+=c,s++}for(;i<e.length;){let o=e[i];o&&(r+=o.count),i++}return{srcCopied:t,literalAdded:r}}function ir(n,e){return n.length===0&&e.length===0?100:n.length===0||e.length===0?0:Gt(n.length,Ae(n),e.length,Ae(e))}function Gt(n,e,t,r){let s=Math.max(n,t),i=Math.min(n,t);if(i<s-i)return 0;let{srcCopied:o}=sr(e,r);return Math.floor(o*100/s)}async function or(n,e,t,r){let s=[];for(let l of e)if(l.oldHash){let u=await Q(n,l.oldHash);s.push({size:u.length,chunks:Ae(u)})}else s.push(null);let i=[];for(let l of t)if(l.newHash){let u=await Q(n,l.newHash);i.push({size:u.length,chunks:Ae(u)})}else i.push(null);let o=[];for(let l=0;l<e.length;l++){let u=e[l],d=s[l];if(!(!u||!d))for(let h=0;h<t.length;h++){let m=t[h],b=i[h];if(!m||!b)continue;let g=Gt(d.size,d.chunks,b.size,b.chunks);if(g>=r){let w=fe(u.path)===fe(m.path)?1:0;o.push({similarity:g,nameScore:w,delIdx:l,addIdx:h})}}}o.sort((l,u)=>u.similarity-l.similarity||u.nameScore-l.nameScore);let a=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:u,addIdx:d}of o){if(a.has(u)||c.has(d))continue;a.add(u),c.add(d);let h=e[u],m=t[d];!h||!m||f.push({oldPath:h.path,newPath:m.path,oldHash:h.oldHash??"",newHash:m.newHash??"",similarity:l,oldMode:h.oldMode,newMode:m.newMode})}return f}async function ar(n,e){let t=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(t.has(i))continue;t.add(i);let o=await U(n,i);for(let a of o.parents)t.has(a)||r.push(a)}return t}async function rt(n,e,t){if(e===t)return!0;let r=new Set,s=[t],i=0;for(;i<s.length;){let o=s[i++];if(o===e)return!0;if(r.has(o))continue;r.add(o);let a=await U(n,o);for(let c of a.parents)r.has(c)||s.push(c)}return!1}async function ge(n,e,t){if(e===t)return[e];let r=await ar(n,e),s=[],i=new Set,o=[t],a=0;for(;a<o.length;){let f=o[a++];if(i.has(f))continue;if(i.add(f),r.has(f)){s.push(f);continue}let l=await U(n,f);for(let u of l.parents)i.has(u)||o.push(u)}if(s.length<=1)return s;let c=[];for(let f of s){let l=!1;for(let u of s)if(u!==f&&await rt(n,f,u)){l=!0;break}l||c.push(f)}return c.length<=1?c:cr(n,e,t,c)}async function cr(n,e,t,r){let s=new Set(r),i=new Set,o=[],a=new Map,c=new Map,f=0,l=[{hash:e,mask:1,seq:f++},{hash:t,mask:2,seq:f++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await U(n,d)).committer.timestamp;return c.set(d,m),m}for(;l.length>0;){let d=0,h=await u(l[0].hash);for(let R=1;R<l.length;R++){let j=l[R],C=await u(j.hash),I=l[d];(C>h||C===h&&j.seq<I.seq)&&(d=R,h=C)}let m=l.splice(d,1)[0],b=a.get(m.hash)??0,g=b|m.mask;if(g===b)continue;if(a.set(m.hash,g),g===3&&s.has(m.hash)&&!i.has(m.hash)&&(o.push(m.hash),i.add(m.hash),i.size===s.size))break;let w=await U(n,m.hash);for(let R of w.parents)l.push({hash:R,mask:g,seq:f++})}for(let d of r)i.has(d)||o.push(d);return o}function st(n,e){let t=n.length,r=e.length;if(t===0&&r===0)return[];if(t===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,t],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=Nt(n,e);return fr(s,t,i,r)}function fr(n,e,t,r){let s=[],i=0,o=0;for(;i<e||o<r;){for(;i<e&&o<r&&!n[i]&&!t[o];)i++,o++;if(i>=e&&o>=r)break;let a=i,c=o;for(;i<e&&n[i];)i++;for(;o<r&&t[o];)o++;(i>a||o>c)&&s.push({buffer1:[a,i-a],buffer2:[c,o-c]})}return s}function lr(n,e,t){let r=[];for(let c of st(e,n))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of st(e,t))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,f)=>c.oStart-f.oStart);let s=[],i=0;function o(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let a=0;for(;a<r.length;){let c=r[a++],f=c.oStart,l=c.oStart+c.oLength,u=[c];for(o(f);a<r.length;){let d=r[a];if(d.oStart>l)break;l=Math.max(l,d.oStart+d.oLength),u.push(d),a++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?n:t;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:d.slice(c.abStart,c.abStart+c.abLength)})}}else{let d={a:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1}};for(let w of u){let R=w.oStart,j=R+w.oLength,C=w.abStart,I=C+w.abLength,x=d[w.ab];x.abMin=Math.min(C,x.abMin),x.abMax=Math.max(I,x.abMax),x.oMin=Math.min(R,x.oMin),x.oMax=Math.max(j,x.oMax)}let h=d.a.abMin+(f-d.a.oMin),m=d.a.abMax+(l-d.a.oMax),b=d.b.abMin+(f-d.b.oMin),g=d.b.abMax+(l-d.b.oMax);s.push({stable:!1,a:n.slice(h,m),o:e.slice(f,l),b:t.slice(b,g)})}i=l}return o(e.length),s}function ur(n,e,t,r){let s=r?.excludeFalseConflicts??!0,i=lr(n,e,t),o=[],a=[];function c(){a.length&&(o.push({type:"ok",lines:a}),a=[])}for(let f of i)f.stable?a.push(...f.content):s&&_t(f.a,f.b)?a.push(...f.a):(c(),o.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),mr(hr(o))}function be(n,e,t,r){let s=r?.markerSize??7,i=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,o="=".repeat(s),a=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,c=ur(n,e,t),f=!1,l=[];for(let u of c)u.type==="ok"?l.push(...u.lines):(f=!0,l.push(i,...u.a,o,...u.b,a));return{conflict:f,result:l}}function hr(n){let e=[];for(let t of n)t.type==="ok"?e.push(t):e.push(...dr(t));return e}function dr(n){let{a:e,b:t}=n;if(e.length===0||t.length===0)return[n];if(_t(e,t))return[n];let r=st(e,t);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let a of r){let c=a.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let l=c+a.buffer1[1],u=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:e.slice(c,l),o:[],b:t.slice(a.buffer2[0],u)}),i=l}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[n]:s}function mr(n){if(n.length<3)return n;let e=[n[0]];for(let r=1;r<n.length;r++){let s=e[e.length-1],i=n[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let t=[e[0]];for(let r=1;r<e.length;r++){let s=t[t.length-1],i=e[r];if(s.type==="conflict"&&i.type==="ok"&&i.lines.length<=3&&r+1<e.length&&e[r+1].type==="conflict"){let o=e[r+1],a=s;a.a=[...s.a,...i.lines,...o.a],a.b=[...s.b,...i.lines,...o.b],a.o=[...s.o,...i.lines,...o.o],r++}else t.push(i)}return t}function oe(n,e,t,r){let s=be(W(n),W(e),W(t),{a:r.a,b:r.b,markerSize:r.markerSize}),o=(s.result[s.result.length-1]??"").endsWith("\0"),a=s.result.map(it);return(a[a.length-1]??"").startsWith(">>>>>>>")||!o?`${a.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`:a.join(`
|
|
14
|
+
`)}function W(n){if(n==="")return[];let e=n.split(`
|
|
15
|
+
`);if(e[e.length-1]==="")e.pop();else{let t=e[e.length-1]??"";e[e.length-1]=`${t}\0`}return e}function it(n){return n.endsWith("\0")?n.slice(0,-1):n}function _t(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}var le=new TextDecoder,re=new TextEncoder,Wt={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function ue(n,e,t,r,s){let{paths:i,baseMap:o,oursMap:a,theirsMap:c}=await pr(n,e,t,r),f=await br(n,i,o,a,c,s);return yr(n,i,s,f)}async function Jt(n,e,t,r){let s=await ge(n,e,t),i=await U(n,e),o=await U(n,t);if(s.length===0)return{...await ue(n,null,i.tree,o.tree,r),baseTree:null};if(s.length===1){let f=await U(n,s[0]);return{...await ue(n,f.tree,i.tree,o.tree,r),baseTree:f.tree}}let a=await Qt(n,e,t,s,1);return{...await ue(n,a,i.tree,o.tree,r),baseTree:a}}async function pr(n,e,t,r){let s=await ae(n,e),i=await ae(n,t),o=await ae(n,r),a=new Set;for(let f of s.keys())a.add(f);for(let f of i.keys())a.add(f);for(let f of o.keys())a.add(f);let c=new Map;for(let f of a){let l=s.get(f)??null,u=i.get(f)??null,d=o.get(f)??null,h=l?{hash:l.hash,mode:l.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,b=d?{hash:d.hash,mode:d.mode}:null,g=(l?1:0)|(u?2:0)|(d?4:0),w=l?.hash??null,R=u?.hash??null,j=d?.hash??null,C=0;w!==null&&w===R&&(C|=3),w!==null&&w===j&&(C|=5),R!==null&&R===j&&(C|=6);let I={path:f,stages:[h,m,b],pathnames:[f,f,f],filemask:g,matchMask:C,merged:{result:null,clean:!1},pathConflict:!1};if(gr(I)){c.set(f,I);continue}c.set(f,I)}return{paths:c,baseMap:s,oursMap:i,theirsMap:o}}function gr(n){let[e,t,r]=n.stages,s=e?.hash??null,i=t?.hash??null,o=r?.hash??null;return i===s&&o===s?(t?n.merged={result:{hash:i,mode:t.mode},clean:!0}:n.merged={result:null,clean:!0},!0):i===o&&i!==null?(n.merged={result:{hash:i,mode:t.mode},clean:!0},!0):i===null&&o===null?(n.merged={result:null,clean:!0},!0):o===s&&i!==s?(t?n.merged={result:{hash:i,mode:t.mode},clean:!0}:n.merged={result:null,clean:!0},!0):i===s&&o!==s?(r?n.merged={result:{hash:o,mode:r.mode},clean:!0}:n.merged={result:null,clean:!0},!0):!1}async function br(n,e,t,r,s,i){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},a=[],c=[];for(let[y,p]of t)r.has(y)||a.push({path:y,status:"deleted",oldHash:p.hash,oldMode:p.mode}),s.has(y)||c.push({path:y,status:"deleted",oldHash:p.hash,oldMode:p.mode});for(let[y,p]of r)t.has(y)||a.push({path:y,status:"added",newHash:p.hash,newMode:p.mode});for(let[y,p]of s)t.has(y)||c.push({path:y,status:"added",newHash:p.hash,newMode:p.mode});let f=await nt(n,a),l=await nt(n,c);if(f.renames.length===0&&l.renames.length===0)return o;let u=new Map,d=new Map;for(let y of f.renames)u.set(y.oldPath,y);for(let y of l.renames)d.set(y.oldPath,y);let h=new Set;for(let[y]of r)!t.has(y)&&s.has(y)&&h.add(y);let m=new Set,b=i?.a??"HEAD",g=i?.b??"theirs";function w(y,p,O=0){o.msgBuf.push({sortKey:y,subOrder:O,text:p})}for(let y of[...t.keys()].sort()){let p=u.get(y),O=d.get(y);if(!p&&!O)continue;let S=t.get(y);if(m.add(y),p&&O)if(m.add(p.newPath),m.add(O.newPath),p.newPath===O.newPath){let k=r.get(p.newPath),P=s.get(O.newPath);if(k.hash===P.hash)o.entries.push(_(p.newPath,k));else{let B=ot(e,p.newPath);B.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],B.pathnames=[y,p.newPath,O.newPath],B.filemask=7,B.merged={result:null,clean:!1}}}else{let k=r.get(p.newPath),P=s.get(O.newPath),B=await Zt(n,S,k,P,i);B.conflict&&w(y,`Auto-merging ${y}`,-1),o.conflicts.push({path:y,reason:"rename-rename",oursPath:p.newPath,theirsPath:O.newPath}),w(y,`CONFLICT (rename/rename): ${y} renamed to ${p.newPath} in ${b} and to ${O.newPath} in ${g}.`),o.entries.push(_(y,S,1)),o.entries.push(H(p.newPath,k.mode,B.hash,2)),o.entries.push(H(O.newPath,P.mode,B.hash,3)),o.worktreeBlobs.set(p.newPath,{hash:B.hash,mode:k.mode}),o.worktreeBlobs.set(O.newPath,{hash:B.hash,mode:P.mode})}else if(p){m.add(p.newPath);let k=s.get(y),P=r.get(p.newPath),B=h.has(p.newPath);if(k)if(B)await Xt(n,o,p.newPath,y,S,P,k,r,s,!1,i);else if(k.hash===S.hash&&P.hash===S.hash)o.entries.push(_(p.newPath,P));else if(k.hash===S.hash)o.entries.push(_(p.newPath,P));else if(P.hash===S.hash)o.entries.push(H(p.newPath,P.mode,k.hash));else{let D=ot(e,p.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:P.hash,mode:P.mode},{hash:k.hash,mode:k.mode}],D.pathnames=[y,p.newPath,y],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=s.get(p.newPath);if(o.conflicts.push({path:p.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:y}),w(p.newPath,`CONFLICT (rename/delete): ${y} renamed to ${p.newPath} in ${b}, but deleted in ${g}.`),D){o.conflicts.push({path:p.newPath,reason:"add-add"}),w(p.newPath,`Auto-merging ${p.newPath}`,0),w(p.newPath,`CONFLICT (add/add): Merge conflict in ${p.newPath}`,1),o.entries.push(_(p.newPath,P,2)),o.entries.push(_(p.newPath,D,3));let Me=await $e(n,P.hash,D.hash,P.mode,i);o.worktreeBlobs.set(p.newPath,{hash:Me,mode:P.mode})}else o.entries.push(H(p.newPath,S.mode,S.hash,1)),o.entries.push(_(p.newPath,P,2)),o.worktreeBlobs.set(p.newPath,{hash:P.hash,mode:P.mode}),P.hash!==S.hash&&w(p.newPath,`CONFLICT (modify/delete): ${p.newPath} deleted in ${g} and modified in ${b}. Version ${b} of ${p.newPath} left in tree.`,1)}}else if(O){m.add(O.newPath);let k=r.get(y),P=s.get(O.newPath),B=h.has(O.newPath);if(k)if(B)await Xt(n,o,O.newPath,y,S,k,P,r,s,!0,i);else if(k.hash===S.hash&&P.hash===S.hash)o.entries.push(_(O.newPath,P));else if(k.hash===S.hash)o.entries.push(_(O.newPath,P));else if(P.hash===S.hash)o.entries.push(H(O.newPath,P.mode,k.hash));else{let D=ot(e,O.newPath);D.stages=[{hash:S.hash,mode:S.mode},{hash:k.hash,mode:k.mode},{hash:P.hash,mode:P.mode}],D.pathnames=[y,y,O.newPath],D.filemask=7,D.merged={result:null,clean:!1}}else{let D=r.get(O.newPath);if(o.conflicts.push({path:O.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:y}),w(O.newPath,`CONFLICT (rename/delete): ${y} renamed to ${O.newPath} in ${g}, but deleted in ${b}.`),D){o.conflicts.push({path:O.newPath,reason:"add-add"}),w(O.newPath,`Auto-merging ${O.newPath}`,0),w(O.newPath,`CONFLICT (add/add): Merge conflict in ${O.newPath}`,1),o.entries.push(_(O.newPath,D,2)),o.entries.push(_(O.newPath,P,3));let Me=await $e(n,D.hash,P.hash,D.mode,i);o.worktreeBlobs.set(O.newPath,{hash:Me,mode:D.mode})}else o.entries.push(H(O.newPath,S.mode,S.hash,1)),o.entries.push(_(O.newPath,P,3)),o.worktreeBlobs.set(O.newPath,{hash:P.hash,mode:P.mode}),P.hash!==S.hash&&w(O.newPath,`CONFLICT (modify/delete): ${O.newPath} deleted in ${b} and modified in ${g}. Version ${g} of ${O.newPath} left in tree.`,1)}}}let R=new Set(f.renames.map(y=>y.newPath)),j=new Set(l.renames.map(y=>y.newPath)),C=zt(t,r),I=zt(t,s),x=Vt(C,s,t),T=Vt(I,r,t),L=Kt(f.renames,x),A=Kt(l.renames,T),E=qt(L),$=qt(A);for(let y of[...E.keys()])$.has(y)&&(E.delete(y),$.delete(y));let X=new Set(E.keys()),K=new Set($.keys());if($.size>0)for(let y of a){if(y.status!=="added"||R.has(y.path))continue;let p=Yt(y.path,$,X);if(!p)continue;if(e.has(p)||t.has(p)||r.has(p)||s.has(p)){if(r.has(p)){w(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${y.path}.`,1);continue}let k=r.get(y.path),P=s.get(p)??t.get(p);o.entries.push(H(p,k.mode,k.hash,2)),P&&o.entries.push(H(p,P.mode,P.hash,3)),o.worktreeBlobs.set(p,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:p,reason:"add-add"}),w(p,`CONFLICT (file location): ${y.path} added in ${b} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,1);let B=e.get(y.path);B&&(B.merged={result:null,clean:!0}),m.add(y.path);continue}let O=r.get(y.path);o.entries.push(H(p,O.mode,O.hash,2)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),w(p,`CONFLICT (file location): ${y.path} added in ${b} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${p}.`,1);let S=e.get(y.path);S&&(S.merged={result:null,clean:!0}),m.add(y.path)}if(E.size>0)for(let y of c){if(y.status!=="added"||j.has(y.path))continue;let p=Yt(y.path,E,K);if(!p)continue;if(e.has(p)||t.has(p)||r.has(p)||s.has(p)){if(s.has(p)){w(p,`CONFLICT (implicit dir rename): Existing file/dir at ${p} in the way of implicit directory rename(s) putting the following path(s) there: ${y.path}.`,1);continue}let k=s.get(y.path),P=r.get(p)??t.get(p);P&&o.entries.push(H(p,P.mode,P.hash,2)),o.entries.push(H(p,k.mode,k.hash,3)),o.worktreeBlobs.set(p,{hash:k.hash,mode:k.mode}),o.conflicts.push({path:p,reason:"add-add"}),w(p,`CONFLICT (file location): ${y.path} added in ${g} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${p}.`,1);let B=e.get(y.path);B&&(B.merged={result:null,clean:!0}),m.add(y.path);continue}let O=s.get(y.path);o.entries.push(H(p,O.mode,O.hash,3)),o.worktreeBlobs.set(p,{hash:O.hash,mode:O.mode}),o.conflicts.push({path:p,reason:"directory-rename"}),w(p,`CONFLICT (file location): ${y.path} added in ${g} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${p}.`,1);let S=e.get(y.path);S&&(S.merged={result:null,clean:!0}),m.add(y.path)}let lt=new Set(o.entries.map(y=>y.path));for(let y of lt){let p=e.get(y);p&&(p.merged={result:null,clean:!0})}for(let y of m){if(lt.has(y))continue;let p=e.get(y);if(!p||p.merged.clean)continue;p.filemask===7&&!p.pathConflict||(p.merged={result:null,clean:!0})}return o}function zt(n,e){let t=new Set;for(let i of n.keys()){let o=z(i);for(;o;)t.add(o),o=z(o)}let r=new Set;for(let i of e.keys()){let o=z(i);for(;o;)r.add(o),o=z(o)}let s=new Set;for(let i of t)r.has(i)||s.add(i);return s}function Vt(n,e,t){if(n.size===0)return n;let r=new Set;for(let s of e.keys()){if(t.has(s))continue;let i=z(s)??"";n.has(i)&&r.add(i)}for(let s of[...r]){let i=z(s);for(;i;)n.has(i)&&!r.has(i)&&r.add(i),i=z(i)}return r}function Kt(n,e){let t=new Map;for(let r of n){let s=z(r.oldPath),i=z(r.newPath),o=!0;for(;;){if(!o){let a=s.length+(s?1:0),c=i.length+(i?1:0),f=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(e.has(s)){let a=t.get(s);a||(a=new Map,t.set(s,a)),a.set(i,(a.get(i)??0)+1)}if(o=!1,!s||!i)break;s=z(s),i=z(i)}}return t}function qt(n){let e=new Map;for(let[t,r]of n){let s=0,i=0,o=null;for(let[a,c]of r)c===s?i=s:c>s&&(s=c,o=a);s>0&&i!==s&&o!==null&&e.set(t,o)}return e}function Yt(n,e,t){let r=z(n);for(;r;){let i=e.get(r);if(i!==void 0){if(t.has(i))return null;let o=n.slice(r.length+1);return i?`${i}/${o}`:o}r=z(r)}let s=e.get("");return s!==void 0&&!t.has(s)?`${s}/${n}`:null}function z(n){let e=n.lastIndexOf("/");return e===-1?"":n.slice(0,e)}async function Xt(n,e,t,r,s,i,o,a,c,f=!1,l){let u=f?a.get(t):c.get(t),d=f?o:i;if(u.hash===d.hash){e.entries.push(H(t,u.mode,u.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let m=await Zt(n,s,i,o,l,f?{oursPath:r,theirsPath:t}:{oursPath:t,theirsPath:r},8);if(u.hash===m.hash)e.entries.push(H(t,u.mode,m.hash));else if(e.conflicts.push({path:t,reason:"add-add"}),e.msgBuf.push({sortKey:t,subOrder:0,text:`Auto-merging ${t}`}),e.msgBuf.push({sortKey:t,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${t}`}),f){e.entries.push(_(t,u,2)),e.entries.push(H(t,o.mode,m.hash,3));let b=await $e(n,u.hash,m.hash,u.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:u.mode})}else{e.entries.push(H(t,i.mode,m.hash,2)),e.entries.push(_(t,u,3));let b=await $e(n,m.hash,u.hash,i.mode,l);e.worktreeBlobs.set(t,{hash:b,mode:i.mode})}}async function Zt(n,e,t,r,s,i,o){if(t.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:t.hash,conflict:!1};if(t.hash===r.hash)return{hash:t.hash,conflict:!1};if(Y(e.mode)||Y(t.mode)||Y(r.mode))return{hash:t.hash,conflict:!0};let a=await F(n,e.hash),c=await F(n,t.hash),f=await F(n,r.hash);if(Z(c)||Z(f)||Z(a))return{hash:t.hash,conflict:!0};let l=W(a),u=W(c),d=W(f),h=be(u,l,d);if(!h.conflict)return{hash:await at(n,h.result),conflict:!1};let m=s?.a??"HEAD",b=s?.b??"theirs",g=i?.oursPath?`${m}:${i.oursPath}`:m,w=i?.theirsPath?`${b}:${i.theirsPath}`:b,R=oe(c,a,f,{a:g,b:w,markerSize:o??7});return{hash:await N(n,"blob",re.encode(R)),conflict:!0}}async function $e(n,e,t,r,s){let i=await F(n,e),o=await F(n,t),a=oe(i,"",o,{a:s?.a??"HEAD",b:s?.b??"theirs"});return N(n,"blob",re.encode(a))}function _(n,e,t=0){return H(n,e.mode,e.hash,t)}function H(n,e,t,r=0){return{path:n,mode:parseInt(e,8),hash:t,stage:r,stat:ee()}}async function yr(n,e,t,r){let s=[...r.entries],i=[...r.conflicts],o=[...r.msgBuf],a=new Map(r.worktreeBlobs);function c(h,m,b=0){o.push({sortKey:h,subOrder:b,text:m})}for(let h of[...e.keys()].sort()){let m=e.get(h);if(m.merged.clean){m.merged.result?.hash&&s.push(M(h,m.merged.result.hash,m.merged.result.mode));continue}await wr(n,m,t,s,i,c,a)}o.sort((h,m)=>(h.sortKey<m.sortKey?-1:h.sortKey>m.sortKey?1:0)||h.subOrder-m.subOrder);let f=o.map(h=>h.text),l=[],u=new Set;for(let h of s)h.stage===0&&(l.push(h),u.add(h.path));for(let[h,m]of a)u.has(h)||l.push(M(h,m.hash,m.mode));l.sort((h,m)=>pe(h.path,m.path));let d=await Ye(n,l);return{entries:s,conflicts:i,messages:f,resultTree:d}}async function wr(n,e,t,r,s,i,o){let a=e.path,[c,f,l]=e.stages,u=c?.hash??null,d=f?.hash??null,h=l?.hash??null;if(d===null&&h!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"ours"});let m=t?.a??"HEAD",b=t?.b??"theirs";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${b}. Version ${b} of ${a} left in tree.`),c&&r.push(M(a,u,c.mode,1)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:h,mode:l.mode});return}if(h===null&&d!==null&&u!==null){s.push({path:a,reason:"delete-modify",deletedBy:"theirs"});let m=t?.b??"theirs",b=t?.a??"HEAD";i(a,`CONFLICT (modify/delete): ${a} deleted in ${m} and modified in ${b}. Version ${b} of ${a} left in tree.`),c&&r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),o.set(a,{hash:d,mode:f.mode});return}if(u===null&&d!==null&&h!==null){if(d===h){r.push(M(a,d,f.mode));return}i(a,`Auto-merging ${a}`,0);let m=await F(n,d),b=await F(n,h);if(Z(m)||Z(b)){s.push({path:a,reason:"add-add"}),i(a,`warning: Cannot merge binary files: ${a} (${t?.a??"HEAD"} vs. ${t?.b??"theirs"})`,-1),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let g=W(""),w=W(m),R=W(b),j=be(w,g,R,t);if(!j.conflict){let x=await at(n,j.result);r.push(M(a,x,f.mode));return}s.push({path:a,reason:"add-add"}),i(a,`CONFLICT (add/add): Merge conflict in ${a}`,1),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3));let C=oe(m,"",b,{a:t?.a??"HEAD",b:t?.b??"theirs"}),I=await N(n,"blob",re.encode(C));o.set(a,{hash:I,mode:f.mode});return}if(u!==null&&d!==null&&h!==null){if(d===u){r.push(M(a,h,l.mode));return}if(h===u){r.push(M(a,d,f.mode));return}if(d===h){r.push(M(a,d,f.mode));return}if(i(a,`Auto-merging ${a}`,0),Y(c.mode)||Y(f.mode)||Y(l.mode)){s.push({path:a,reason:"content"}),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let m=await F(n,u),b=await F(n,d),g=await F(n,h);if(Z(b)||Z(g)||Z(m)){s.push({path:a,reason:"content"}),i(a,`warning: Cannot merge binary files: ${a} (${t?.a??"HEAD"} vs. ${t?.b??"theirs"})`,-1),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3)),o.set(a,{hash:d,mode:f.mode});return}let w=W(m),R=W(b),j=W(g),C=be(R,w,j,t);if(C.conflict){let I=e.pathnames[1],x=e.pathnames[2],T=I!==a||x!==a,L={path:a,reason:"content"};T&&(I!==a&&(L.oursOrigPath=I),x!==a&&(L.theirsOrigPath=x)),s.push(L),i(a,`CONFLICT (content): Merge conflict in ${a}`,1),r.push(M(a,u,c.mode,1)),r.push(M(a,d,f.mode,2)),r.push(M(a,h,l.mode,3));let A=T?`${t?.a??"HEAD"}:${I}`:t?.a??"HEAD",E=T?`${t?.b??"theirs"}:${x}`:t?.b??"theirs",$=oe(b,m,g,{a:A,b:E}),X=await N(n,"blob",re.encode($));o.set(a,{hash:X,mode:f.mode})}else{let I=await at(n,C.result);r.push(M(a,I,f.mode))}return}}var xr=200;async function Qt(n,e,t,r,s){let i=await Promise.all(r.map(async l=>({hash:l,timestamp:(await U(n,l)).committer.timestamp})));i.sort((l,u)=>l.timestamp-u.timestamp);let o=i.map(l=>l.hash),a=o[0],c=a,f=(await U(n,a)).tree;for(let l=1;l<o.length;l++){let u=o[l],d=(await U(n,u)).tree,h=null;if(s>=xr)h=f;else{let g=await ge(n,c,u);g.length===0?h=null:g.length===1?h=(await U(n,g[0])).tree:h=await Qt(n,c,u,g,s+1)}let m=await ue(n,h,f,d);f=await Ir(n,m,s);let b=Re({type:"commit",tree:f,parents:[c,u],author:Wt,committer:Wt,message:"merged common ancestors"});c=await N(n,"commit",b)}return f}async function Ir(n,e,t){let r=e.entries.filter(a=>a.stage===0),s=new Map;for(let a of e.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let i=(a,c)=>s.get(`${a}\0${c}`),o={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+t*2};for(let a of e.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let l=i(a.path,1);if(l){r.push({...l,stage:0});continue}}if(a.reason==="rename-rename"){let l=a.oursPath??a.path,u=a.theirsPath??a.path,d=i(a.path,1),h=i(l,2),m=i(u,3);if(h&&m){let b=le.decode((await V(n,h.hash)).content),g=le.decode((await V(n,m.hash)).content),w=d?le.decode((await V(n,d.hash)).content):"",R=8+t*2,j=o.a??"Temporary merge branch 1",C=o.b??"Temporary merge branch 2",I=oe(b,w,g,{a:`${j}:${l}`,o:o.o,b:`${C}:${u}`,markerSize:R}),x=await N(n,"blob",re.encode(I));r.push({path:l,mode:h.mode,hash:x,stage:0,stat:ee()}),r.push({path:u,mode:m.mode,hash:x,stage:0,stat:ee()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(a.path,2),f=i(a.path,3);if(c&&f&&(a.reason==="content"||a.reason==="add-add")){let l=le.decode((await V(n,c.hash)).content),u=le.decode((await V(n,f.hash)).content),d=a.reason==="content"?i(a.path,1):null,h=d?le.decode((await V(n,d.hash)).content):"",m=a.oursOrigPath||a.theirsOrigPath,b=o.a??"Temporary merge branch 1",g=o.b??"Temporary merge branch 2",w=m?`${b}:${a.oursOrigPath??a.path}`:b,R=m?`${g}:${a.theirsOrigPath??a.path}`:g,j=oe(l,h,u,{a:w,o:o.o,b:R,markerSize:o.markerSize}),C=await N(n,"blob",re.encode(j));r.push({path:a.path,mode:c.mode,hash:C,stage:0,stat:ee()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>pe(a.path,c.path)),Ye(n,r)}async function at(n,e){let t=e.map(it);if(t.length===0)return N(n,"blob",re.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?t.join(`
|
|
16
|
+
`):`${t.join(`
|
|
17
|
+
`)}
|
|
18
|
+
`;return N(n,"blob",re.encode(i))}function M(n,e,t,r=0){let s=typeof t=="string"?parseInt(t,8):t;return{path:n,mode:s,hash:e,stage:r,stat:ee()}}function ot(n,e){let t=n.get(e);return t||(t={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},n.set(e,t)),t}async function*Or(n,e,t){yield*Ze(n,t,{exclude:e?[e]:[]})}async function Pr(n,e,t){let r=await U(n,t),s=null;return e&&(s=(await U(n,e)).tree),Xe(n,s,r.tree)}async function Rr(n,e,t){return rt(n,e,t)}async function kr(n,e){return ke(n,e)}async function Er(n){return qe(n,"refs/heads")}async function Tr(n){return qe(n,"refs/tags")}async function Sr(n,e){return U(n,e)}async function jr(n,e){return Q(n,e)}async function Cr(n,e){return F(n,e)}async function Ar(n,e){return ie(n,e)}async function $r(n,e,t){return Xe(n,e,t)}async function Mr(n,e,t){return ge(n,e,t)}async function vr(n,e,t,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await Jt(n,e,t,s);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function Lr(n,e,t,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,o=await ue(n,e,t,r,i);return{treeHash:o.resultTree,clean:o.conflicts.length===0,conflicts:o.conflicts,messages:o.messages}}async function Ur(n,e){let t=Re({type:"commit",tree:e.tree,parents:e.parents,author:e.author,committer:e.committer,message:e.message});return N(n,"commit",t)}async function Br(n,e){let t=[...e].sort((s,i)=>s.name.localeCompare(i.name)),r=Ee({type:"tree",entries:t.map(s=>({mode:s.mode??"100644",name:s.name,hash:s.hash}))});return N(n,"tree",r)}async function Dr(n,e){return N(n,"blob",new TextEncoder().encode(e))}async function Hr(n,e,t){let r=await U(n,e),i=(await ie(n,r.tree)).find(o=>o.path===t);return i?F(n,i.hash):null}var en=/^[0-9a-f]{40}$/;async function Nr(n,e,t,r="/"){let s=await ke(n,e);if(!s)if(en.test(e)&&await n.objectStore.exists(e))s=e;else throw new Error(`ref or commit '${e}' not found`);let i=await U(n,s),o=await ie(n,i.tree),a=new Set,c=0;for(let f of o){let l=v(r,f.path),u=ve(l);if(u!==r&&!a.has(u)&&(await t.mkdir(u,{recursive:!0}),a.add(u)),Y(f.mode)){let d=await F(n,f.hash);t.symlink?await t.symlink(d,l):await t.writeFile(l,d)}else{let d=await Q(n,f.hash);await t.writeFile(l,d)}c++}return{commitHash:s,treeHash:i.tree,filesWritten:c}}async function Fr(n,e,t){let r=t?.workTree??"/",s=t?.gitDir??v(r,".git"),i=t?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let o=await ke(n,i);if(!o)if(en.test(i)&&await n.objectStore.exists(i))o=i;else throw new Error(`ref or commit '${i}' not found`);let a=await U(n,o),c=await ie(n,a.tree),f={...n,fs:e,gitDir:s,workTree:r},l=new Set,u=0;for(let h of c){let m=v(r,h.path),b=ve(m);if(b!==r&&!l.has(b)&&(await e.mkdir(b,{recursive:!0}),l.add(b)),Y(h.mode)){let g=await F(n,h.hash);e.symlink?await e.symlink(g,m):await e.writeFile(m,g)}else{let g=await Q(n,h.hash);await e.writeFile(m,g)}u++}let d=dt(c.map(h=>({path:h.path,mode:parseInt(h.mode,8),hash:h.hash,stage:0,stat:ee()})));return await Ue(f,d),{ctx:f,commitHash:o,treeHash:a.tree,filesWritten:u}}var ct=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,t){throw new Error("cannot write: object store is read-only")}exists(e){return this.inner.exists(e)}ingestPack(e){throw new Error("cannot ingest pack: object store is read-only")}findByPrefix(e){return this.inner.findByPrefix(e)}},ft=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,t){throw new Error("cannot write ref: ref store is read-only")}deleteRef(e){throw new Error("cannot delete ref: ref store is read-only")}listRefs(e){return this.inner.listRefs(e)}compareAndSwapRef(e,t,r){throw new Error("cannot update ref: ref store is read-only")}};function Gr(n){return{objectStore:new ct(n.objectStore),refStore:new ft(n.refStore),hooks:n.hooks}}export{Ke as FileSystemRefStore,_e as PackedObjectStore,Nr as checkoutTo,Ur as createCommit,Fr as createWorktree,$r as diffTrees,Mr as findMergeBases,Ar as flattenTree,Pr as getChangedFiles,Or as getNewCommits,Rr as isAncestor,Er as listBranches,Tr as listTags,vr as mergeTrees,Lr as mergeTreesFromTreeHashes,jr as readBlob,Cr as readBlobText,Sr as readCommit,Hr as readFileAtCommit,Gr as readonlyRepo,kr as resolveRef,Dr as writeBlob,Br as writeTree};
|