just-git 1.5.10 → 1.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -873,7 +873,7 @@ ${h}`,exitCode:0}}oe();ie();Ir();we();ds();function _d(e,t){e.command("tag",{des
|
|
|
873
873
|
`)}if(n.list)return Nd(s,n.name||void 0);if(n.name){if(!Uc(n.name))return S(`'${n.name}' is not a valid tag name`);let i=n.commit,a;if(i){let d=await bt(s,i,`Failed to resolve '${i}' as a valid ref.`);if(j(d))return d;a=d}else if(a=await X(s),!a)return S("Failed to resolve 'HEAD' as a valid ref.");let c=`refs/tags/${n.name}`;if(await B(s,c)&&!n.force)return S(`tag '${n.name}' already exists`);if(n.annotate||n.message){if(!n.message)return S("no tag message specified (use -m)");let d=await tt(s,r.env);if(j(d))return d;let h=Nt(n.message),u=Lc({type:"tag",object:a,objectType:"commit",name:n.name,tagger:d,message:h}),m=await Se(s,"tag",u);await J(s,c,m)}else await J(s,c,a);return{stdout:"",stderr:"",exitCode:0}}return Nd(s)}})}async function Nd(e,t){let n=await ge(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=>fn(t,o,0)===0)),r.length===0?{stdout:"",stderr:"",exitCode:0}:{stdout:`${r.join(`
|
|
874
874
|
`)}
|
|
875
875
|
`,stderr:"",exitCode:0}}var Fd=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"]),Kw={init:(e,t)=>Xl(e,t),clone:(e,t)=>xl(e,t),describe:(e,t)=>Pl(e,t),fetch:(e,t)=>Fl(e,t),pull:(e,t)=>pd(e,t),push:(e,t)=>wd(e,t),add:(e,t)=>df(e,t),blame:(e,t)=>Wf(e,t),commit:(e,t)=>$l(e,t),status:(e,t)=>Md(e,t),log:(e,t)=>id(e,t),branch:(e,t)=>Kf(e,t),tag:(e,t)=>_d(e,t),checkout:(e,t)=>Vf(e,t),diff:(e,t)=>jl(e,t),reset:(e,t)=>kd(e,t),merge:(e,t)=>fd(e,t),"cherry-pick":(e,t)=>cl(e,t),revert:(e,t)=>Pd(e,t),rebase:(e,t)=>md(e,t),mv:(e,t)=>ld(e,t),rm:(e,t)=>$d(e,t),remote:(e,t)=>yd(e,t),config:(e,t)=>Tl(e,t),show:(e,t)=>Od(e,t),stash:(e,t)=>Dd(e,t),"rev-parse":(e,t)=>Cd(e,t),"ls-files":(e,t)=>cd(e,t),clean:(e,t)=>fl(e,t),switch:(e,t)=>Gd(e,t),restore:(e,t)=>xd(e,t),reflog:(e,t)=>bd(e,t),repack:(e,t)=>Wl(e,t),gc:(e,t)=>ql(e,t),bisect:(e,t)=>Tf(e,t),grep:(e,t)=>Yl(e,t)};function Ud(e){let t=ai("git",{description:"Git command"});for(let n of Object.values(Kw))n(t,e);return t.command("help",{description:"Display help information",args:[K.string().name("command").describe("Command to get help for").optional()],handler:async n=>{let r=n.command;if(!r)return{stdout:Rr(t),stderr:"",exitCode:0};let o=t.children.get(r);return o?{stdout:Rr(o),stderr:"",exitCode:0}:{stdout:"",stderr:`git: no help available for '${r}'
|
|
876
|
-
`,exitCode:1}}}),t}var zw="1.5.
|
|
876
|
+
`,exitCode:1}}}),t}var zw="1.5.11";function Vw(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 ei=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=Vw(t?.identity,t?.config),o=t?.gitDir?{gitDir:t.gitDir,workTree:this.defaultCwd}:{},s={hooks:t?.hooks,credentialProvider:t?.credentials,identityOverride:t?.identity,fetchFn:typeof n=="object"?n.fetch:void 0,networkPolicy:n,resolveRemote:t?.resolveRemote,credentialCache:new Map,...t?.objectStore?{objectStore:t.objectStore}:{},...t?.refStore?{refStore:t.refStore}:{},...o,...r?{configOverrides:r}:{}};this.inner=Ud(s).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=Yw(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 ${zw} (virtual git implementation)
|
|
877
877
|
`,stderr:"",exitCode:0};if(this.blocked?.has(r))return{stdout:"",stderr:`git: '${r}' is not available in this environment
|
|
878
878
|
`,exitCode:1};if(r&&Fd.has(r))return{stdout:"",stderr:`git: '${r}' is not implemented. Run 'git help' for available commands.
|
|
879
879
|
`,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(fe(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 Yw(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 Xw(e){return new ei(e)}var Bd=new TextEncoder,Zw=new TextDecoder;function gn(e){let t=[];for(let n of e.split("/"))n==="."||n===""||(n===".."?t.pop():t.push(n));return"/"+t.join("/")}function ti(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}var Da=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=gn(n);this.ensureParents(o),this.data.set(o,{type:"file",content:typeof r=="string"?Bd.encode(r):r,mode:33188,mtime:new Date})}}ensureParents(t){let n=ti(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 gn(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("/")?gn(a):gn(ti(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=gn(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("/")?gn(f):gn(ti(o)+"/"+f),a=this.data.get(o),c++}}return`${o}/${r[r.length-1]}`}async readFile(t){return Zw.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"?Bd.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=gn(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=ti(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=gn(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=gn(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})}};Nn();export{ei as Git,Da as MemoryFileSystem,qm as composeGitHooks,Xw as createGit,or as findRepo,fe as isRejection};
|
package/dist/repo/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { g as GitRepo, Z as RefEntry, e as Commit, a3 as TreeEntry, i as ObjectId, h as Identity, a4 as TreeDiffEntry, d as GitContext, F as FileSystem } from '../hooks-CimfP56a.js';
|
|
2
|
-
|
|
2
|
+
import { C as CommitIdentity } from '../writing-CEP3N60d.js';
|
|
3
|
+
export { B as BuildCommitOptions, a as CommitAuthor, b as CommitOptions, c as CommitResult, d as CreateAnnotatedTagOptions, e as CreateCommitOptions, T as TreeEntryInput, f as TreeUpdate, g as buildCommit, h as commit, i as createAnnotatedTag, j as createCommit, u as updateTree, w as writeBlob, k as writeTree } from '../writing-CEP3N60d.js';
|
|
3
4
|
|
|
4
5
|
/** Extract the short branch name from a full ref path like "refs/heads/main" → "main". */
|
|
5
6
|
declare function branchNameFromRef(ref: string): string;
|
|
@@ -17,6 +18,19 @@ interface GrepMatch {
|
|
|
17
18
|
|
|
18
19
|
/** Resolve a ref name (e.g. "HEAD", "refs/heads/main") to a commit hash. Returns null if not found. */
|
|
19
20
|
declare function resolveRef(repo: GitRepo, name: string): Promise<string | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a revision expression to an object hash.
|
|
23
|
+
*
|
|
24
|
+
* Supports branch names, tag names, `HEAD`, short hashes, special refs
|
|
25
|
+
* (`ORIG_HEAD`, `MERGE_HEAD`, etc.), remote tracking refs (`origin/main`),
|
|
26
|
+
* `~N`/`^N` suffixes, `^{commit}`/`^{tree}` peel syntax, and arbitrary
|
|
27
|
+
* chaining (`main~2^2`, `v1.0^{commit}~3`).
|
|
28
|
+
*
|
|
29
|
+
* Returns null if the revision cannot be resolved. Reflog syntax
|
|
30
|
+
* (`@{N}`) is not supported — reflog entries require filesystem access
|
|
31
|
+
* and are not available through `GitRepo`.
|
|
32
|
+
*/
|
|
33
|
+
declare function revParse(repo: GitRepo, rev: string): Promise<string | null>;
|
|
20
34
|
/** List all local branches (`refs/heads/*`). */
|
|
21
35
|
declare function listBranches(repo: GitRepo): Promise<RefEntry[]>;
|
|
22
36
|
/** List all tags (`refs/tags/*`). */
|
|
@@ -580,6 +594,135 @@ type BisectSearchResult = {
|
|
|
580
594
|
* ```
|
|
581
595
|
*/
|
|
582
596
|
declare function bisect(repo: GitRepo, options: BisectOptions): Promise<BisectSearchResult>;
|
|
597
|
+
/** Options for {@link cherryPick}. */
|
|
598
|
+
interface CherryPickOptions {
|
|
599
|
+
/** The commit to cherry-pick (hash, branch, tag, or any rev-parse expression). */
|
|
600
|
+
commit: string;
|
|
601
|
+
/** The commit to apply on top of (hash, branch, tag, or any rev-parse expression). */
|
|
602
|
+
onto: string;
|
|
603
|
+
/** Branch to advance on clean result. No ref update when omitted. Ignored when `noCommit` is true. */
|
|
604
|
+
branch?: string;
|
|
605
|
+
/** Committer identity. Defaults to the original commit's author when omitted, so both author and committer will reflect the original — pass explicitly to record who performed the cherry-pick. */
|
|
606
|
+
committer?: CommitIdentity;
|
|
607
|
+
/** Parent number for merge commits (1-based). Required when cherry-picking a merge. */
|
|
608
|
+
mainline?: number;
|
|
609
|
+
/** Append "(cherry picked from commit ...)" trailer to the message. */
|
|
610
|
+
recordOrigin?: boolean;
|
|
611
|
+
/** Override the commit message. Defaults to the original commit's message. */
|
|
612
|
+
message?: string;
|
|
613
|
+
/** When true, perform the merge but don't create a commit. `hash` will be `null` in the result. */
|
|
614
|
+
noCommit?: boolean;
|
|
615
|
+
/** Custom merge driver for content conflicts. */
|
|
616
|
+
mergeDriver?: MergeDriver;
|
|
617
|
+
}
|
|
618
|
+
/** Clean result when a commit was created. */
|
|
619
|
+
interface CleanPickCommitted {
|
|
620
|
+
clean: true;
|
|
621
|
+
hash: string;
|
|
622
|
+
treeHash: string;
|
|
623
|
+
}
|
|
624
|
+
/** Clean result when `noCommit` was set — no commit created. */
|
|
625
|
+
interface CleanPickNoCommit {
|
|
626
|
+
clean: true;
|
|
627
|
+
treeHash: string;
|
|
628
|
+
}
|
|
629
|
+
/** Conflict result — no commit was created. */
|
|
630
|
+
interface PickConflict {
|
|
631
|
+
clean: false;
|
|
632
|
+
treeHash: string;
|
|
633
|
+
conflicts: MergeConflict[];
|
|
634
|
+
messages: string[];
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Result of {@link cherryPick} or {@link revert}.
|
|
638
|
+
*
|
|
639
|
+
* - `clean: true` with `hash` — commit was created.
|
|
640
|
+
* - `clean: true` without `hash` — `noCommit` was set, merge succeeded
|
|
641
|
+
* but no commit was created.
|
|
642
|
+
* - `clean: false` — conflicts were found, no commit was created.
|
|
643
|
+
*/
|
|
644
|
+
type CherryPickResult = CleanPickCommitted | PickConflict;
|
|
645
|
+
/** Result of {@link cherryPick} or {@link revert} when `noCommit` is true. */
|
|
646
|
+
type NoCommitPickResult = CleanPickNoCommit | PickConflict;
|
|
647
|
+
/**
|
|
648
|
+
* Cherry-pick a commit onto another commit.
|
|
649
|
+
*
|
|
650
|
+
* Applies the changes introduced by `commit` on top of `onto` using a
|
|
651
|
+
* three-way merge (base = parent of `commit`, ours = `onto`, theirs = `commit`).
|
|
652
|
+
* Operates purely on the object store — no filesystem, index, or working tree.
|
|
653
|
+
*
|
|
654
|
+
* On a clean result, creates a new commit preserving the original author.
|
|
655
|
+
* When `branch` is provided, the branch ref is advanced to the new commit.
|
|
656
|
+
*
|
|
657
|
+
* ```ts
|
|
658
|
+
* const result = await cherryPick(repo, {
|
|
659
|
+
* commit: "feature~2",
|
|
660
|
+
* onto: "main",
|
|
661
|
+
* branch: "main",
|
|
662
|
+
* committer: { name: "Bot", email: "bot@example.com" },
|
|
663
|
+
* });
|
|
664
|
+
* if (result.clean) {
|
|
665
|
+
* console.log(`Cherry-picked as ${result.hash}`);
|
|
666
|
+
* } else {
|
|
667
|
+
* console.log(`Conflicts: ${result.conflicts.length}`);
|
|
668
|
+
* }
|
|
669
|
+
* ```
|
|
670
|
+
*/
|
|
671
|
+
declare function cherryPick(repo: GitRepo, options: CherryPickOptions & {
|
|
672
|
+
noCommit: true;
|
|
673
|
+
}): Promise<NoCommitPickResult>;
|
|
674
|
+
declare function cherryPick(repo: GitRepo, options: CherryPickOptions): Promise<CherryPickResult>;
|
|
675
|
+
/** Options for {@link revert}. */
|
|
676
|
+
interface RevertOptions {
|
|
677
|
+
/** The commit to revert (hash, branch, tag, or any rev-parse expression). */
|
|
678
|
+
commit: string;
|
|
679
|
+
/** The commit to apply the revert on top of (hash, branch, tag, or any rev-parse expression). */
|
|
680
|
+
onto: string;
|
|
681
|
+
/** Branch to advance on clean result. No ref update when omitted. Ignored when `noCommit` is true. */
|
|
682
|
+
branch?: string;
|
|
683
|
+
/** Committer identity. Defaults to the caller's identity. When omitted, uses `author` as both author and committer. */
|
|
684
|
+
committer?: CommitIdentity;
|
|
685
|
+
/** Author identity for the revert commit. When omitted, uses `committer`. At least one of `author` or `committer` must be provided (unless `noCommit` is true). */
|
|
686
|
+
author?: CommitIdentity;
|
|
687
|
+
/** Parent number for merge commits (1-based). Required when reverting a merge. */
|
|
688
|
+
mainline?: number;
|
|
689
|
+
/** Override the commit message. Defaults to the auto-generated "Revert ..." message. */
|
|
690
|
+
message?: string;
|
|
691
|
+
/** When true, perform the merge but don't create a commit. `hash` will be `null` in the result. */
|
|
692
|
+
noCommit?: boolean;
|
|
693
|
+
/** Custom merge driver for content conflicts. */
|
|
694
|
+
mergeDriver?: MergeDriver;
|
|
695
|
+
}
|
|
696
|
+
/** Result of {@link revert}. Same shape as {@link CherryPickResult}. */
|
|
697
|
+
type RevertResult = CherryPickResult;
|
|
698
|
+
/** Result of {@link revert} when `noCommit` is true. */
|
|
699
|
+
type NoCommitRevertResult = NoCommitPickResult;
|
|
700
|
+
/**
|
|
701
|
+
* Revert a commit on top of another commit.
|
|
702
|
+
*
|
|
703
|
+
* Applies the inverse of the changes introduced by `commit` on top of
|
|
704
|
+
* `onto` using a three-way merge (base = `commit`, ours = `onto`,
|
|
705
|
+
* theirs = parent of `commit`). Operates purely on the object store.
|
|
706
|
+
*
|
|
707
|
+
* On a clean result, creates a new commit with a "Revert ..." message.
|
|
708
|
+
* When `branch` is provided, the branch ref is advanced.
|
|
709
|
+
*
|
|
710
|
+
* ```ts
|
|
711
|
+
* const result = await revert(repo, {
|
|
712
|
+
* commit: "abc1234",
|
|
713
|
+
* onto: "main",
|
|
714
|
+
* branch: "main",
|
|
715
|
+
* committer: { name: "Bot", email: "bot@example.com" },
|
|
716
|
+
* });
|
|
717
|
+
* if (result.clean) {
|
|
718
|
+
* console.log(`Reverted as ${result.hash}`);
|
|
719
|
+
* }
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
722
|
+
declare function revert(repo: GitRepo, options: RevertOptions & {
|
|
723
|
+
noCommit: true;
|
|
724
|
+
}): Promise<NoCommitRevertResult>;
|
|
725
|
+
declare function revert(repo: GitRepo, options: RevertOptions): Promise<RevertResult>;
|
|
583
726
|
|
|
584
727
|
/**
|
|
585
728
|
* Wrap a `GitRepo` so all write operations throw.
|
|
@@ -615,4 +758,4 @@ declare function readonlyRepo(repo: GitRepo): GitRepo;
|
|
|
615
758
|
*/
|
|
616
759
|
declare function overlayRepo(repo: GitRepo): GitRepo;
|
|
617
760
|
|
|
618
|
-
export { type BisectOptions, type BisectSearchResult, type BisectStepInfo, type BlameEntry, Commit, type CommitInfo, type CreateWorktreeOptions, type DiffHunk, type DiffOptions, type ExtractTreeResult, type FileDiff, type FlatTreeEntry, GitRepo, type GrepFileMatch, type GrepMatch, type GrepOptions, type HeadInfo, Identity, type MaterializeTarget, type MergeConflict, type MergeDriver, type MergeDriverResult, type MergeTreesResult, RefEntry, type TreeAccessor, TreeDiffEntry, TreeEntry, type WorktreeResult, bisect, blame, branchNameFromRef, countAheadBehind, createSandboxWorktree, createTreeAccessor, createWorktree, diffCommits, diffTrees, extractTree, findMergeBases, flattenTree, formatDiff, getChangedFiles, getNewCommits, grep, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, overlayRepo, readBlob, readBlobText, readCommit, readFileAtCommit, readHead, readTree, readonlyRepo, resolveRef, tagNameFromRef, walkCommitHistory };
|
|
761
|
+
export { type BisectOptions, type BisectSearchResult, type BisectStepInfo, type BlameEntry, type CherryPickOptions, type CherryPickResult, type CleanPickCommitted, type CleanPickNoCommit, Commit, CommitIdentity, type CommitInfo, type CreateWorktreeOptions, type DiffHunk, type DiffOptions, type ExtractTreeResult, type FileDiff, type FlatTreeEntry, GitRepo, type GrepFileMatch, type GrepMatch, type GrepOptions, type HeadInfo, Identity, type MaterializeTarget, type MergeConflict, type MergeDriver, type MergeDriverResult, type MergeTreesResult, type NoCommitPickResult, type NoCommitRevertResult, type PickConflict, RefEntry, type RevertOptions, type RevertResult, type TreeAccessor, TreeDiffEntry, TreeEntry, type WorktreeResult, bisect, blame, branchNameFromRef, cherryPick, countAheadBehind, createSandboxWorktree, createTreeAccessor, createWorktree, diffCommits, diffTrees, extractTree, findMergeBases, flattenTree, formatDiff, getChangedFiles, getNewCommits, grep, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, overlayRepo, readBlob, readBlobText, readCommit, readFileAtCommit, readHead, readTree, readonlyRepo, resolveRef, revParse, revert, tagNameFromRef, walkCommitHistory };
|
package/dist/repo/index.js
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
|
-
var We=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Dt=(()=>{let t=new Array(256);for(let e=0;e<256;e++)t[e]=(e>>4).toString(16)+(e&15).toString(16);return t})();function ve(t){let e="";for(let n=0;n<20;n++)e+=Dt[t[n]];return e}function st(t,e){let n="";for(let r=0;r<20;r++)n+=Dt[t[e+r]];return n}function we(t){let e=new Uint8Array(20);for(let n=0;n<20;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}var mr=new TextEncoder;function it(t){return typeof t=="string"?mr.encode(t):t}function pr(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(it(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=We(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(it(r)),n},hex:()=>Promise.resolve(e.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let t=[],e={update(n){return t.push(it(n)),e},async hex(){let n=0;for(let a of t)n+=a.byteLength;let r=new Uint8Array(n),s=0;for(let a of t)r.set(a,s),s+=a.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return ve(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=pr(),ot=Ht;async function ze(t){return Ht().update(t).hex()}var ee=Uint8Array,Ee=Uint16Array,gr=Int32Array,Bt=new ee([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]),Ut=new ee([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]),yr=new ee([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Nt=(t,e)=>{let n=new Ee(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new gr(n[30]);for(let s=1;s<30;++s)for(let i=n[s];i<n[s+1];++i)r[i]=i-n[s]<<5|s;return{b:n,r}},{b:Gt}=Nt(Bt,2);Gt[28]=258;var{b:br}=Nt(Ut,0),ft=new Ee(32768);for(let t=0;t<32768;++t){let e=(t&43690)>>1|(t&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,ft[t]=((e&65280)>>8|(e&255)<<8)>>1}var je=(t,e,n)=>{let r=t.length,s=0,i=new Ee(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let a=new Ee(e);for(s=1;s<e;++s)a[s]=a[s-1]+i[s-1]<<1;let o;if(n){o=new Ee(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let l=s<<4|t[s],f=e-t[s],u=a[t[s]-1]++<<f;for(let d=u|(1<<f)-1;u<=d;++u)o[ft[u]>>c]=l}}else for(o=new Ee(r),s=0;s<r;++s)t[s]&&(o[s]=ft[a[t[s]-1]++]>>15-t[s]);return o},$e=new ee(288);for(let t=0;t<144;++t)$e[t]=8;for(let t=144;t<256;++t)$e[t]=9;for(let t=256;t<280;++t)$e[t]=7;for(let t=280;t<288;++t)$e[t]=8;var Ft=new ee(32);for(let t=0;t<32;++t)Ft[t]=5;var wr=je($e,9,1),Er=je(Ft,5,1),at=t=>{let e=t[0];for(let n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},Q=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},ct=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},_t=t=>(t+7)/8|0,Ir=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new ee(t.subarray(e,n))),se=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},Wt=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new ee(0);let a=!n,o=a||e.i!=2,c=e.i;a&&(n=new ee(s*3));let l=x=>{let v=n.length;if(x>v){let C=new ee(Math.max(v*2,x));C.set(n),n=C}},f=e.f||0,u=e.p||0,d=e.b||0,h=e.l,m=e.d,g=e.m,p=e.n,b=s*8;do{if(!h){f=Q(t,u,1);let T=Q(t,u+1,3);if(u+=3,T)if(T==1)h=wr,m=Er,g=9,p=5;else if(T==2){let w=Q(t,u,31)+257,E=Q(t,u+10,15)+4,k=w+Q(t,u+5,31)+1;u+=14;let R=new ee(k),S=new ee(19);for(let I=0;I<E;++I)S[yr[I]]=Q(t,u+I*3,7);u+=E*3;let O=at(S),j=(1<<O)-1,D=je(S,O,1);for(let I=0;I<k;){let y=D[Q(t,u,j)];u+=y&15;let P=y>>4;if(P<16)R[I++]=P;else{let L=0,M=0;for(P==16?(M=3+Q(t,u,3),u+=2,L=R[I-1]):P==17?(M=3+Q(t,u,7),u+=3):P==18&&(M=11+Q(t,u,127),u+=7);M--;)R[I++]=L}}let re=R.subarray(0,w),me=R.subarray(w);g=at(re),p=at(me),h=je(re,g,1),m=je(me,p,1)}else se(1);else{let w=_t(u)+4,E=t[w-4]|t[w-3]<<8,k=w+E;if(k>s){c&&se(0);break}o&&l(d+E),n.set(t.subarray(w,k),d),e.b=d+=E,e.p=u=k*8,e.f=f;continue}if(u>b){c&&se(0);break}}o&&l(d+131072);let x=(1<<g)-1,v=(1<<p)-1,C=u;for(;;C=u){let T=h[ct(t,u)&x],w=T>>4;if(u+=T&15,u>b){c&&se(0);break}if(T||se(2),w<256)n[d++]=w;else if(w==256){C=u,h=null;break}else{let E=w-254;if(w>264){let j=w-257,D=Bt[j];E=Q(t,u,(1<<D)-1)+Gt[j],u+=D}let k=m[ct(t,u)&v],R=k>>4;k||se(3),u+=k&15;let S=br[R];if(R>3){let j=Ut[R];S+=ct(t,u)&(1<<j)-1,u+=j}if(u>b){c&&se(0);break}o&&l(d+131072);let O=d+E;if(d<S){let j=i-S,D=Math.min(S,O);for(j+d<0&&se(3);d<D;++d)n[d]=r[j+d]}for(;d<O;++d)n[d]=n[d-S]}}e.l=h,e.p=C,e.b=d,e.f=f,h&&(f=1,e.m=g,e.d=m,e.n=p)}while(!f);return d!=n.length&&a?Ir(n,0,d):n.subarray(0,d)},zt=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&se(0,"invalid zlib data"),t[1]&32&&se(0,"zlib dictionaries are not supported"),2);function Vt(t){let e=zt(t);return Wt(t.subarray(e,-4),{i:2})}function lt(t){let e=zt(t),n={i:2},r=Wt(t.subarray(e),n),s=_t(n.p);return{result:r,bytesConsumed:e+s+4}}async function Rr(){let t;if(!(typeof document<"u"))try{t=We(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let a=t.inflateSync(i,{info:!0});return{result:new Uint8Array(a.buffer),bytesConsumed:a.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??lt}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let s=new CompressionStream("deflate"),i=s.writable.getWriter();return i.write(r),i.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:Vt,inflateWithConsumed:lt}}var xr=null;function Or(){return xr??=Rr()}async function Kt(t,e){let n=await Or(),{result:r,bytesConsumed:s}=n.inflateWithConsumed(t);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);return{result:r,bytesConsumed:s}}var Yt=1346454347,Tr=2,Pr=1,kr=2,Sr=3,Cr=4,Ve=6,ht=7,vr={[Pr]:"commit",[kr]:"tree",[Sr]:"blob",[Cr]:"tag"};async function Jt(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==Yt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Yt.toString(16)})`);let s=n.getUint32(4);if(s!==Tr)throw new Error(`Unsupported pack version: ${s}`);if(t.byteLength>=32){let l=st(t,t.byteLength-20),f=ot();f.update(t.subarray(0,t.byteLength-20));let u=await f.hex();if(u!==l)throw new Error(`pack checksum mismatch: expected ${l}, computed ${u}`)}let i=n.getUint32(8),a=[],o=12;for(let l=0;l<i;l++){let f=await jr(t,o);a.push(f),o=f.nextOffset}return(await $r(a,e)).map((l,f)=>({...l,offset:a[f].headerOffset,nextOffset:a[f].nextOffset}))}async function jr(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,a=4;for(;r&128;)r=t[e++],i|=(r&127)<<a,a+=7;let o,c;if(s===Ve){let u=t[e++];for(o=u&127;u&128;)o+=1,u=t[e++],o=(o<<7)+(u&127);o=n-o}else s===ht&&(c=st(t,e),e+=20);let{result:l,bytesConsumed:f}=await Kt(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:l,baseOffset:o,baseHash:c,nextOffset:e+f}}var qt=50;async function $r(t,e){let n=new Map;for(let i=0;i<t.length;i++)n.set(t[i].headerOffset,i);let r=new Array(t.length).fill(null);async function s(i,a=0){if(a>qt)throw new Error(`delta chain depth ${a} exceeds limit of ${qt}`);let o=r[i];if(o)return o;let c=t[i];if(c.typeNum!==Ve&&c.typeNum!==ht){let h=vr[c.typeNum];if(!h)throw new Error(`Unknown object type: ${c.typeNum}`);let m={type:h,content:c.inflated,hash:await ut(h,c.inflated)};return r[i]=m,m}if(c.typeNum===Ve){let h=n.get(c.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let m=await s(h,a+1),g=Xt(m.content,c.inflated),p={type:m.type,content:g,hash:await ut(m.type,g)};return r[i]=p,p}let l=await Ar(t,r,c.baseHash,s),f;if(l!==void 0)f=await s(l,a+1);else if(e){let h=await e(c.baseHash);h&&(f=h)}if(!f)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let u=Xt(f.content,c.inflated),d={type:f.type,content:u,hash:await ut(f.type,u)};return r[i]=d,d}for(let i=0;i<t.length;i++)await s(i);return r}async function Ar(t,e,n,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===n)return s;for(let s=0;s<t.length;s++){let i=t[s];if(i.typeNum!==Ve&&i.typeNum!==ht&&(await r(s)).hash===n)return s}}function Xt(t,e){let n=0,{value:r,newPos:s}=Zt(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:a}=Zt(e,n);n=a;let o=new Uint8Array(i),c=0;for(;n<e.byteLength;){let l=e[n++];if(l&128){let f=0,u=0;l&1&&(f=e[n++]),l&2&&(f|=e[n++]<<8),l&4&&(f|=e[n++]<<16),l&8&&(f|=e[n++]<<24),l&16&&(u=e[n++]),l&32&&(u|=e[n++]<<8),l&64&&(u|=e[n++]<<16),u===0&&(u=65536),o.set(t.subarray(f,f+u),c),c+=u}else if(l>0)o.set(e.subarray(n,n+l),c),c+=l,n+=l;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return o}function Zt(t,e){let n=0,r=0,s;do s=t[e++],n|=(s&127)<<r,r+=7;while(s&128);return{value:n,newPos:e}}var Mr=new TextEncoder;async function ut(t,e){let n=Mr.encode(`${t} ${e.byteLength}\0`),r=ot();return r.update(n),r.update(e),r.hex()}function Lr(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.split("/"),s=[];for(let a of r)a===""||a==="."||(a===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(a));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function pe(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":Lr(e)}function Qt(t){if(t==="")return".";if(t==="/")return"/";let e=t.length;for(;e>1&&t.charCodeAt(e-1)===47;)e--;let n=t.slice(0,e),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}var Dr=new TextEncoder,no=new TextDecoder;function en(t,e){let n=Dr.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function Ae(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[a="0",o="+0000"]=i.split(" "),c=parseInt(a,10);return{name:r,email:s,timestamp:c,timezone:o}}function Me(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var Hr=new TextEncoder,Br=new TextDecoder;function tn(t){let e=Br.decode(t),n=e.indexOf(`
|
|
1
|
+
var ze=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Nt=(()=>{let t=new Array(256);for(let e=0;e<256;e++)t[e]=(e>>4).toString(16)+(e&15).toString(16);return t})();function $e(t){let e="";for(let n=0;n<20;n++)e+=Nt[t[n]];return e}function it(t,e){let n="";for(let r=0;r<20;r++)n+=Nt[t[e+r]];return n}function Ie(t){let e=new Uint8Array(20);for(let n=0;n<20;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}var wr=new TextEncoder;function ot(t){return typeof t=="string"?wr.encode(t):t}function Rr(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(ot(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=ze(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(ot(r)),n},hex:()=>Promise.resolve(e.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let t=[],e={update(n){return t.push(ot(n)),e},async hex(){let n=0;for(let a of t)n+=a.byteLength;let r=new Uint8Array(n),s=0;for(let a of t)r.set(a,s),s+=a.byteLength;let i=await crypto.subtle.digest("SHA-1",r);return $e(new Uint8Array(i))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var Ut=Rr(),at=Ut;async function Ve(t){return Ut().update(t).hex()}var ee=Uint8Array,Ee=Uint16Array,Ir=Int32Array,Gt=new ee([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]),Ft=new ee([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]),Er=new ee([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),_t=(t,e)=>{let n=new Ee(31);for(let s=0;s<31;++s)n[s]=e+=1<<t[s-1];let r=new Ir(n[30]);for(let s=1;s<30;++s)for(let i=n[s];i<n[s+1];++i)r[i]=i-n[s]<<5|s;return{b:n,r}},{b:Wt}=_t(Gt,2);Wt[28]=258;var{b:xr}=_t(Ft,0),ft=new Ee(32768);for(let t=0;t<32768;++t){let e=(t&43690)>>1|(t&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,ft[t]=((e&65280)>>8|(e&255)<<8)>>1}var Ae=(t,e,n)=>{let r=t.length,s=0,i=new Ee(e);for(;s<r;++s)t[s]&&++i[t[s]-1];let a=new Ee(e);for(s=1;s<e;++s)a[s]=a[s-1]+i[s-1]<<1;let o;if(n){o=new Ee(1<<e);let c=15-e;for(s=0;s<r;++s)if(t[s]){let f=s<<4|t[s],l=e-t[s],u=a[t[s]-1]++<<l;for(let m=u|(1<<l)-1;u<=m;++u)o[ft[u]>>c]=f}}else for(o=new Ee(r),s=0;s<r;++s)t[s]&&(o[s]=ft[a[t[s]-1]++]>>15-t[s]);return o},Me=new ee(288);for(let t=0;t<144;++t)Me[t]=8;for(let t=144;t<256;++t)Me[t]=9;for(let t=256;t<280;++t)Me[t]=7;for(let t=280;t<288;++t)Me[t]=8;var zt=new ee(32);for(let t=0;t<32;++t)zt[t]=5;var Or=Ae(Me,9,1),Pr=Ae(zt,5,1),ct=t=>{let e=t[0];for(let n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},Q=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},lt=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},Vt=t=>(t+7)/8|0,Tr=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new ee(t.subarray(e,n))),se=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},Kt=(t,e,n,r)=>{let s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new ee(0);let a=!n,o=a||e.i!=2,c=e.i;a&&(n=new ee(s*3));let f=x=>{let j=n.length;if(x>j){let S=new ee(Math.max(j*2,x));S.set(n),n=S}},l=e.f||0,u=e.p||0,m=e.b||0,h=e.l,d=e.d,g=e.m,p=e.n,b=s*8;do{if(!h){l=Q(t,u,1);let P=Q(t,u+1,3);if(u+=3,P)if(P==1)h=Or,d=Pr,g=9,p=5;else if(P==2){let w=Q(t,u,31)+257,R=Q(t,u+10,15)+4,k=w+Q(t,u+5,31)+1;u+=14;let E=new ee(k),C=new ee(19);for(let I=0;I<R;++I)C[Er[I]]=Q(t,u+I*3,7);u+=R*3;let O=ct(C),$=(1<<O)-1,D=Ae(C,O,1);for(let I=0;I<k;){let y=D[Q(t,u,$)];u+=y&15;let T=y>>4;if(T<16)E[I++]=T;else{let L=0,M=0;for(T==16?(M=3+Q(t,u,3),u+=2,L=E[I-1]):T==17?(M=3+Q(t,u,7),u+=3):T==18&&(M=11+Q(t,u,127),u+=7);M--;)E[I++]=L}}let re=E.subarray(0,w),de=E.subarray(w);g=ct(re),p=ct(de),h=Ae(re,g,1),d=Ae(de,p,1)}else se(1);else{let w=Vt(u)+4,R=t[w-4]|t[w-3]<<8,k=w+R;if(k>s){c&&se(0);break}o&&f(m+R),n.set(t.subarray(w,k),m),e.b=m+=R,e.p=u=k*8,e.f=l;continue}if(u>b){c&&se(0);break}}o&&f(m+131072);let x=(1<<g)-1,j=(1<<p)-1,S=u;for(;;S=u){let P=h[lt(t,u)&x],w=P>>4;if(u+=P&15,u>b){c&&se(0);break}if(P||se(2),w<256)n[m++]=w;else if(w==256){S=u,h=null;break}else{let R=w-254;if(w>264){let $=w-257,D=Gt[$];R=Q(t,u,(1<<D)-1)+Wt[$],u+=D}let k=d[lt(t,u)&j],E=k>>4;k||se(3),u+=k&15;let C=xr[E];if(E>3){let $=Ft[E];C+=lt(t,u)&(1<<$)-1,u+=$}if(u>b){c&&se(0);break}o&&f(m+131072);let O=m+R;if(m<C){let $=i-C,D=Math.min(C,O);for($+m<0&&se(3);m<D;++m)n[m]=r[$+m]}for(;m<O;++m)n[m]=n[m-C]}}e.l=h,e.p=S,e.b=m,e.f=l,h&&(l=1,e.m=g,e.d=d,e.n=p)}while(!l);return m!=n.length&&a?Tr(n,0,m):n.subarray(0,m)},Yt=t=>(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&se(0,"invalid zlib data"),t[1]&32&&se(0,"zlib dictionaries are not supported"),2);function qt(t){let e=Yt(t);return Kt(t.subarray(e,-4),{i:2})}function ut(t){let e=Yt(t),n={i:2},r=Kt(t.subarray(e),n),s=Vt(n.p);return{result:r,bytesConsumed:e+s+4}}async function kr(){let t;if(!(typeof document<"u"))try{t=ze(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let s=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=i=>{let a=t.inflateSync(i,{info:!0});return{result:new Uint8Array(a.buffer),bytesConsumed:a.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(t.deflateSync(s)),inflateSync:s=>new Uint8Array(t.inflateSync(s)),inflateWithConsumed:r??ut}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let s=new CompressionStream("deflate"),i=s.writable.getWriter();return i.write(r),i.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:qt,inflateWithConsumed:ut}}var Cr=null;function Sr(){return Cr??=kr()}async function Xt(t,e){let n=await Sr(),{result:r,bytesConsumed:s}=n.inflateWithConsumed(t);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);return{result:r,bytesConsumed:s}}var Zt=1346454347,vr=2,jr=1,$r=2,Ar=3,Mr=4,Ke=6,mt=7,Lr={[jr]:"commit",[$r]:"tree",[Ar]:"blob",[Mr]:"tag"};async function tn(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==Zt)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Zt.toString(16)})`);let s=n.getUint32(4);if(s!==vr)throw new Error(`Unsupported pack version: ${s}`);if(t.byteLength>=32){let f=it(t,t.byteLength-20),l=at();l.update(t.subarray(0,t.byteLength-20));let u=await l.hex();if(u!==f)throw new Error(`pack checksum mismatch: expected ${f}, computed ${u}`)}let i=n.getUint32(8),a=[],o=12;for(let f=0;f<i;f++){let l=await Dr(t,o);a.push(l),o=l.nextOffset}return(await Hr(a,e)).map((f,l)=>({...f,offset:a[l].headerOffset,nextOffset:a[l].nextOffset}))}async function Dr(t,e){let n=e,r=t[e++],s=r>>4&7,i=r&15,a=4;for(;r&128;)r=t[e++],i|=(r&127)<<a,a+=7;let o,c;if(s===Ke){let u=t[e++];for(o=u&127;u&128;)o+=1,u=t[e++],o=(o<<7)+(u&127);o=n-o}else s===mt&&(c=it(t,e),e+=20);let{result:f,bytesConsumed:l}=await Xt(t.subarray(e),i);return{headerOffset:n,typeNum:s,inflated:f,baseOffset:o,baseHash:c,nextOffset:e+l}}var Jt=50;async function Hr(t,e){let n=new Map;for(let i=0;i<t.length;i++)n.set(t[i].headerOffset,i);let r=new Array(t.length).fill(null);async function s(i,a=0){if(a>Jt)throw new Error(`delta chain depth ${a} exceeds limit of ${Jt}`);let o=r[i];if(o)return o;let c=t[i];if(c.typeNum!==Ke&&c.typeNum!==mt){let h=Lr[c.typeNum];if(!h)throw new Error(`Unknown object type: ${c.typeNum}`);let d={type:h,content:c.inflated,hash:await ht(h,c.inflated)};return r[i]=d,d}if(c.typeNum===Ke){let h=n.get(c.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let d=await s(h,a+1),g=Qt(d.content,c.inflated),p={type:d.type,content:g,hash:await ht(d.type,g)};return r[i]=p,p}let f=await Br(t,r,c.baseHash,s),l;if(f!==void 0)l=await s(f,a+1);else if(e){let h=await e(c.baseHash);h&&(l=h)}if(!l)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let u=Qt(l.content,c.inflated),m={type:l.type,content:u,hash:await ht(l.type,u)};return r[i]=m,m}for(let i=0;i<t.length;i++)await s(i);return r}async function Br(t,e,n,r){for(let s=0;s<e.length;s++)if(e[s]?.hash===n)return s;for(let s=0;s<t.length;s++){let i=t[s];if(i.typeNum!==Ke&&i.typeNum!==mt&&(await r(s)).hash===n)return s}}function Qt(t,e){let n=0,{value:r,newPos:s}=en(e,n);if(n=s,r!==t.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${t.byteLength}`);let{value:i,newPos:a}=en(e,n);n=a;let o=new Uint8Array(i),c=0;for(;n<e.byteLength;){let f=e[n++];if(f&128){let l=0,u=0;f&1&&(l=e[n++]),f&2&&(l|=e[n++]<<8),f&4&&(l|=e[n++]<<16),f&8&&(l|=e[n++]<<24),f&16&&(u=e[n++]),f&32&&(u|=e[n++]<<8),f&64&&(u|=e[n++]<<16),u===0&&(u=65536),o.set(t.subarray(l,l+u),c),c+=u}else if(f>0)o.set(e.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==i)throw new Error(`Delta produced ${c} bytes, expected ${i}`);return o}function en(t,e){let n=0,r=0,s;do s=t[e++],n|=(s&127)<<r,r+=7;while(s&128);return{value:n,newPos:e}}var Nr=new TextEncoder;async function ht(t,e){let n=Nr.encode(`${t} ${e.byteLength}\0`),r=at();return r.update(n),r.update(e),r.hex()}function Ur(t){if(t==="")return".";if(t==="/")return"/";let e=t.charCodeAt(0)===47,n=t.charCodeAt(t.length-1)===47,r=t.split("/"),s=[];for(let a of r)a===""||a==="."||(a===".."?e||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(a));let i=s.join("/");return e&&(i=`/${i}`),n&&i.length>1&&!i.endsWith("/")&&(i+="/"),i||(e?"/":n?"./":".")}function pe(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":Ur(e)}function nn(t){if(t==="")return".";if(t==="/")return"/";let e=t.length;for(;e>1&&t.charCodeAt(e-1)===47;)e--;let n=t.slice(0,e),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}var Gr=new TextEncoder,lo=new TextDecoder;function rn(t,e){let n=Gr.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function Le(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),s=t.slice(e+1,n),i=t.slice(n+2),[a="0",o="+0000"]=i.split(" "),c=parseInt(a,10);return{name:r,email:s,timestamp:c,timezone:o}}function De(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var Fr=new TextEncoder,_r=new TextDecoder;function sn(t){let e=_r.decode(t),n=e.indexOf(`
|
|
2
2
|
|
|
3
|
-
`),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",a=[],o,c;for(let
|
|
4
|
-
`)){let f
|
|
5
|
-
`))}var
|
|
3
|
+
`),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",a=[],o,c;for(let f of r.split(`
|
|
4
|
+
`)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),m=f.slice(l+1);switch(u){case"tree":i=m;break;case"parent":a.push(m);break;case"author":o=Le(m);break;case"committer":c=Le(m);break}}if(!i)throw new Error("Commit missing tree field");if(!o)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:i,parents:a,author:o,committer:c,message:s}}function He(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${De(t.author)}`),e.push(`committer ${De(t.committer)}`),e.push(""),e.push(t.message),Fr.encode(e.join(`
|
|
5
|
+
`))}var Wr=new TextEncoder,zr=new TextDecoder;function on(t){let e=zr.decode(t),n=e.indexOf(`
|
|
6
6
|
|
|
7
|
-
`),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",a="commit",o="",c;for(let
|
|
8
|
-
`)){let f
|
|
9
|
-
`))}async function
|
|
10
|
-
`,exitCode:128}}var
|
|
11
|
-
`);return e===-1?t:t.slice(0,e)}async function
|
|
12
|
-
`);if(s.length>0&&s[s.length-1]===""&&s.pop(),n&&e.length>1&&!e.every(o=>s.some(c=>o.test(c))))return{matches:[],binary:!1};let i=[];for(let a=0;a<s.length;a++){let o=s[a],c=e.some(l=>l.test(o));(r?!c:c)&&i.push({lineNo:a+1,line:o})}return{matches:i,binary:!1}}function is(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function On(t,e){let n=e?.fixed?is(t):t;e?.wordRegexp&&(n=`\\b${n}\\b`);let r=e?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}var os=new TextEncoder,Tn=new TextDecoder,xe=16877,Sn=33188,as=33261,Cn=40960;function V(t){let e=[];for(let n of t.split("/"))n==="."||n===""||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}function Pn(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function kn(t){switch(t){case N.EXECUTABLE:return as;case N.SYMLINK:return Cn;case N.DIRECTORY:return xe;default:return Sn}}var Oe=class{constructor(e,n,r="/"){this.objectStore=e;this.rootTreeHash=n;this.rootPath=r;let s=V(r);this.overlay.set(s,{type:"directory",mode:xe,mtime:this.epoch})}treeCache=new Map;overlay=new Map;removals=new Set;epoch=new Date(0);toRelative(e){let n=V(e),r=V(this.rootPath);if(n===r)return"";let s=r==="/"?"/":`${r}/`;return n.startsWith(s)?n.slice(s.length):null}async loadTreeDir(e){let n=this.treeCache.get(e);if(n)return n;if(e===""){let a=await this.objectStore.read(this.rootTreeHash);if(a.type!=="tree")return null;let o=ie(a.content);return this.treeCache.set("",o.entries),o.entries}let r=e.split("/"),s=await this.loadTreeDir("");if(!s)return null;let i="";for(let a of r){let o=s.find(u=>u.name===a);if(!o||o.mode!==N.DIRECTORY)return null;i=i?`${i}/${a}`:a;let c=this.treeCache.get(i);if(c){s=c;continue}let l=await this.objectStore.read(o.hash);if(l.type!=="tree")return null;let f=ie(l.content);this.treeCache.set(i,f.entries),s=f.entries}return s}async lookupTreeEntry(e){if(e==="")return null;let n=e.lastIndexOf("/"),r=n===-1?"":e.slice(0,n),s=n===-1?e:e.slice(n+1),i=await this.loadTreeDir(r);if(!i)return null;let a=i.find(o=>o.name===s);return a?{entry:a,dirEntries:i}:null}async isTreeDirectory(e){return e===""?!0:(await this.lookupTreeEntry(e))?.entry.mode===N.DIRECTORY}ensureOverlayParents(e){let n=Pn(e);n===V(this.rootPath)||n==="/"||this.overlay.has(n)||(this.ensureOverlayParents(n),this.overlay.set(n,{type:"directory",mode:xe,mtime:new Date}))}async readFile(e){return Tn.decode(await this.readFileBuffer(e))}async readFileBuffer(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`ENOENT: no such file or directory, open '${e}'`);let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(i.entry.mode===N.DIRECTORY)throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let a=await this.objectStore.read(i.entry.hash);if(a.type!=="blob")throw new Error(`ENOENT: no such file or directory, open '${e}'`);return a.content}async writeFile(e,n){let r=V(e);this.removals.delete(r),this.ensureOverlayParents(r),this.overlay.set(r,{type:"file",content:typeof n=="string"?os.encode(n):new Uint8Array(n),mode:Sn,mtime:new Date})}async exists(e){let n=V(e);if(this.removals.has(n))return!1;if(this.overlay.has(n))return!0;let r=this.toRelative(n);return r===null?!1:r===""||await this.isTreeDirectory(r)?!0:await this.lookupTreeEntry(r)!==null}async stat(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:r.type==="file"?r.content.byteLength:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:xe,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let{entry:a}=i,o=a.mode===N.DIRECTORY,c=a.mode===N.SYMLINK,l=0;return o||(l=(await this.objectStore.read(a.hash)).content.byteLength),{isFile:!o&&!c,isDirectory:o,isSymbolicLink:!1,mode:kn(a.mode),size:l,mtime:this.epoch}}async lstat(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.overlay.get(n);if(r)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};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:xe,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let{entry:a}=i,o=a.mode===N.DIRECTORY,c=a.mode===N.SYMLINK,l=0;return o||(l=(await this.objectStore.read(a.hash)).content.byteLength),{isFile:!o&&!c,isDirectory:o,isSymbolicLink:c,mode:kn(a.mode),size:l,mtime:this.epoch}}async mkdir(e,n){let r=V(e);if(this.overlay.has(r)){if(this.overlay.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.toRelative(r);if(s!==null&&!this.removals.has(r)&&(s===""||await this.isTreeDirectory(s))){if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let i=Pn(r);if(!(this.overlay.has(i)||await this.exists(i)))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.removals.delete(r),this.overlay.set(r,{type:"directory",mode:xe,mtime:new Date})}async readdir(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,s=this.toRelative(n);if(s!==null){let a=await this.loadTreeDir(s);if(a)for(let o of a){let c=n==="/"?`/${o.name}`:`${n}/${o.name}`;this.removals.has(c)||r.add(o.name)}}let i=n==="/"?"/":`${n}/`;for(let a of this.overlay.keys())if(a!==n&&a.startsWith(i)){let c=a.slice(i.length).split("/")[0];c&&!this.removals.has(n==="/"?`/${c}`:`${n}/${c}`)&&r.add(c)}if(r.size===0){if(this.overlay.get(n)?.type==="directory")return[];if(s!==null&&(s===""||await this.isTreeDirectory(s)))return[];throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}return[...r].sort()}async rm(e,n){let r=V(e);if(!await this.exists(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}let i=r==="/"?"/":`${r}/`;if(n?.recursive)for(let a of[...this.overlay.keys()])a.startsWith(i)&&(this.overlay.delete(a),this.removals.add(a));if(this.overlay.delete(r),this.removals.add(r),n?.recursive){let a=this.toRelative(r);a!==null&&await this.markTreeChildrenRemoved(a,r)}}async markTreeChildrenRemoved(e,n){let r=await this.loadTreeDir(e);if(r)for(let s of r){let i=n==="/"?`/${s.name}`:`${n}/${s.name}`;if(this.removals.add(i),s.mode===N.DIRECTORY){let a=e?`${e}/${s.name}`:s.name;await this.markTreeChildrenRemoved(a,i)}}}async readlink(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let i=await this.lookupTreeEntry(s);if(!i||i.entry.mode!==N.SYMLINK)throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let a=await this.objectStore.read(i.entry.hash);return Tn.decode(a.content)}async symlink(e,n){let r=V(n);if(await this.exists(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureOverlayParents(r),this.removals.delete(r),this.overlay.set(r,{type:"symlink",target:e,mode:Cn,mtime:new Date})}};async function Ue(t,e,n,r){let s=new Set,i=0;for(let a of e){if(!un(a.path))throw new Error(`refusing to check out unsafe path '${a.path}'`);let o=pe(r,a.path);if(!hn(r,o))throw new Error(`refusing to check out path outside target directory: '${a.path}'`);let c=Qt(o);if(c!==r&&!s.has(c)&&(await n.mkdir(c,{recursive:!0}),s.add(c)),gn(a.mode))await n.mkdir(o,{recursive:!0});else if(ae(a.mode)){let l=await B(t,a.hash);if(!dn(l))throw new Error(`refusing to create symlink with unsafe target '${l}'`);n.symlink?await n.symlink(l,o):await n.writeFile(o,l)}else{let l=await oe(t,a.hash);await n.writeFile(o,l)}i++}return i}function Ne(t,e){let n=null,r;function s(i="/"){return n&&r===i||(n=new Oe(t.objectStore,e,i),r=i),n}return{treeHash:e,async readFile(i){let a=s(),o=i.startsWith("/")?i:"/"+i;return await a.exists(o)?a.readFile(o):null},async readFileBytes(i){let a=s(),o=i.startsWith("/")?i:"/"+i;return await a.exists(o)?a.readFileBuffer(o):null},async files(){return(await z(t,e)).map(a=>a.path)},fs(i="/"){return s(i)},async materialize(i,a="/"){let o=await z(t,e);return Ue(t,o,i,a)}}}async function cs(t,e){return te(t,e)}async function fs(t){return dt(t,"refs/heads")}async function ls(t){return dt(t,"refs/tags")}async function us(t){let e=await t.refStore.readRef("HEAD");if(!e)return{branch:null,ref:null,hash:null};if(e.type==="symbolic"){let n=await t.refStore.readRef(e.target),r=n?.type==="direct"?n.hash:null;return{branch:e.target.startsWith("refs/heads/")?mt(e.target):null,ref:e.target,hash:r}}return{branch:null,ref:null,hash:e.hash}}async function hs(t,e){return $(t,e)}async function ds(t,e){return oe(t,e)}async function ms(t,e){return B(t,e)}async function ps(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ie(n.content).entries}async function gs(t,e,n){let r=await $(t,e);return Ne(t,r.tree).readFile(n)}function ys(t){let e=0;for(let n=0;n<t.length;n++)t[n]==="/"&&e++;return e}function bs(t,e){let n=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"\0").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]").replace(/\0/g,".*");return new RegExp(`^${n}$`).test(e)}async function ws(t,e,n,r){let s=[];for(let m of n)if(m instanceof RegExp)s.push(m);else{let g=On(m,{fixed:r?.fixed,ignoreCase:r?.ignoreCase,wordRegexp:r?.wordRegexp});if(!g)throw new Error(`Invalid pattern: ${m}`);s.push(g)}let i=await $(t,e),o=(await z(t,i.tree)).filter(m=>!m.mode.startsWith("120")).sort((m,g)=>m.path<g.path?-1:m.path>g.path?1:0),c=r?.allMatch??!1,l=r?.invert??!1,f=r?.maxCount,u=r?.maxDepth,d=r?.paths,h=[];for(let m of o){if(u!==void 0&&ys(m.path)>u||d&&!d.some(x=>bs(x,m.path)))continue;let g=await B(t,m.hash),p=xn(g,s,c,l);if(p.binary){h.push({path:m.path,matches:[],binary:!0});continue}if(p.matches.length===0)continue;let b=f!==void 0?p.matches.slice(0,f):p.matches;h.push({path:m.path,matches:b,binary:!1})}return h}function J(t){if(t.length===0)return[];let e=t.split(`
|
|
13
|
-
`);return e[e.length-1]===""&&e.pop(),e}var
|
|
7
|
+
`),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n+2),i="",a="commit",o="",c;for(let f of r.split(`
|
|
8
|
+
`)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),m=f.slice(l+1);switch(u){case"object":i=m;break;case"type":a=m;break;case"tag":o=m;break;case"tagger":c=Le(m);break}}if(!i)throw new Error("Tag missing object field");if(!o)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:i,objectType:a,name:o,tagger:c,message:s}}function an(t){let e=[];return e.push(`object ${t.object}`),e.push(`type ${t.objectType}`),e.push(`tag ${t.name}`),e.push(`tagger ${De(t.tagger)}`),e.push(""),e.push(t.message),Wr.encode(e.join(`
|
|
9
|
+
`))}async function N(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function F(t,e){return t.objectStore.read(e)}async function cn(t,e){return t.objectStore.exists(e)}async function ln(t,e){return t.objectStore.findByPrefix(e)}function Z(t){let e=Math.min(t.length,8e3);for(let n=0;n<e;n++)if(t.charCodeAt(n)===0)return!0;return!1}var Vr=new TextDecoder;async function B(t,e){let n=await F(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return Vr.decode(n.content)}async function oe(t,e){let n=await F(t,e);if(n.type!=="blob")throw new Error(`Expected blob for ${e}, got ${n.type}`);return n.content}async function v(t,e){let n=await F(t,e);if(n.type!=="commit")throw new Error(`Expected commit object for ${e}, got ${n.type}`);return sn(n.content)}async function Be(t,e){let n=e;for(let r=0;r<100;r++){let s=await F(t,n);if(s.type==="commit")return n;if(s.type==="tag"){n=on(s.content).object;continue}throw new Error(`Cannot peel ${s.type} object ${e} to commit`)}throw new Error(`Tag chain too deep for ${e}`)}var Kr=new TextEncoder,fn=new TextDecoder,Yr=new Set(["100644","100755","040000","120000","160000"]);function qr(t){return t.length===4&&t.toLowerCase()===".git"}function Xr(t,e){if(t.length===0)throw new Error("invalid tree entry: empty name");if(t.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${t}'`);if(t.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(t==="."||t==="..")throw new Error(`invalid tree entry: '${t}'`);if(qr(t))throw new Error(`invalid tree entry: '${t}'`);if(!Yr.has(e))throw new Error(`invalid tree entry mode: '${e}' for '${t}'`)}function ie(t){let e=[],n=0;for(;n<t.byteLength;){let r=t.indexOf(32,n);if(r===-1)break;let s=fn.decode(t.subarray(n,r)),i=t.indexOf(0,r+1);if(i===-1)break;let a=fn.decode(t.subarray(r+1,i)),o=t.subarray(i+1,i+21),c=$e(o),f=s.padStart(6,"0");Xr(a,f),e.push({mode:f,name:a,hash:c}),n=i+21}return{type:"tree",entries:e}}function ge(t){let e=[];for(let i of t.entries){let a=i.mode.replace(/^0+/,""),o=Kr.encode(`${a} ${i.name}\0`),c=Ie(i.hash);e.push(o),e.push(c)}let n=e.reduce((i,a)=>i+a.byteLength,0),r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;return r}var U={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};function un(t){return typeof t=="string"?{type:"direct",hash:t}:t}var Zr=10;async function Jr(t,e){return t.refStore.readRef(e)}async function te(t,e){let n=e;for(let r=0;r<Zr;r++){let s=await Jr(t,n);if(!s)return null;if(s.type==="direct")return s.hash;n=s.target}throw new Error(`Symbolic ref loop detected resolving "${e}"`)}async function dt(t,e="refs"){return t.refStore.listRefs(e)}function pt(t){return t.replace("refs/heads/","")}function hn(t){return t.replace("refs/tags/","")}function Qr(t){let e=[],n=t.length;for(;n>0;){let i=t.slice(0,n).match(/^(.+?)~(\d*)$/);if(i&&i[1]!==void 0&&i[2]!==void 0){let c=i[2]===""?1:parseInt(i[2],10);e.unshift({type:"tilde",n:c}),n=i[1].length;continue}let a=t.slice(0,n).match(/^(.+?)\^{([^}]*)}$/);if(a&&a[1]!==void 0&&a[2]!==void 0){e.unshift({type:"peel",target:a[2]}),n=a[1].length;continue}let o=t.slice(0,n).match(/^(.+?)\^(\d*)$/);if(o&&o[1]!==void 0&&o[2]!==void 0){let c=o[2]===""?1:parseInt(o[2],10);e.unshift({type:"caret",n:c}),n=o[1].length;continue}break}let r=t.slice(0,n),s=r.match(/^(.+?)@\{(\d+)\}$/);return s&&s[1]!==void 0&&s[2]!==void 0?{base:s[1],reflogIndex:parseInt(s[2],10),suffixes:e}:{base:r,suffixes:e}}var es=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];async function ts(t,e){let n=await ln(t,e);if(n.length===0)return null;if(n.length>1)throw new gt(e);return n[0]}var gt=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}};async function ns(t,e){if(e==="HEAD"||e==="@")return te(t,"HEAD");if(es.includes(e))return te(t,e);if(/^[0-9a-f]{40}$/.test(e))return await cn(t,e)?e:null;if(/^[0-9a-f]{4,39}$/.test(e)){let i=await ts(t,e);if(i)return i}if(e.startsWith("refs/")){let i=await te(t,e);if(i)return i}let n=await te(t,`refs/heads/${e}`);if(n)return n;let r=await te(t,`refs/tags/${e}`);if(r)return r;let s=await te(t,`refs/remotes/${e}`);return s||null}async function rs(t,e,n){if(n===""||n==="commit")try{return await Be(t,e)}catch{return null}if(n==="tree"){let s;try{s=await Be(t,e)}catch{return null}return(await v(t,s)).tree}return(await F(t,e)).type!==n?null:e}async function ss(t,e,n){let r=e;n.some(i=>i.type==="tilde"||i.type==="caret")&&(r=await Be(t,r));for(let i of n)if(i.type==="peel"){if(!r)return null;r=await rs(t,r,i.target)}else if(i.type==="tilde")for(let a=0;a<i.n;a++){if(!r)return null;let o=await v(t,r);if(o.parents.length===0||(r=o.parents[0]??null,!r))return null}else{if(i.n===0)continue;if(!r)return null;let a=await v(t,r);if(i.n>a.parents.length||(r=a.parents[i.n-1]??null,!r))return null}return r}async function mn(t,e){let{base:n,reflogIndex:r,suffixes:s}=Qr(e);if(r!==void 0)return null;let i=await ns(t,n);return i?ss(t,i,s):null}function dn(t){return t.length===4&&t.toLowerCase()===".git"}function pn(t){if(t.length===0||t.includes("\0")||t.charCodeAt(0)===47||t.charCodeAt(t.length-1)===47)return!1;let e=t.split("/");for(let n of e)if(n.length===0||n==="."||n===".."||dn(n))return!1;return!0}function gn(t,e){return e===t?!1:t==="/"?e.startsWith("/")&&e.length>1:e.startsWith(t+"/")}function yn(t){if(t.length===0||t.charCodeAt(0)===47)return!1;let e=t.split("/");for(let n of e)if(n===".."||dn(n))return!1;return!0}var is=1145655875,os=2;async function Ye(t,e){let n=pe(t.gitDir,"index"),r=await as(e);await t.fs.writeFile(n,r)}function bn(t){let e=[...t].sort(wn);return{version:os,entries:e}}function fe(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}async function as(t){let e=new TextEncoder,n=[...t.entries].sort(wn),r=[],s=12;for(let m of n){let h=e.encode(m.path);r.push(h);let d=62+h.byteLength+1;s+=Math.ceil(d/8)*8}s+=20;let i=new ArrayBuffer(s),a=new Uint8Array(i),o=new DataView(i),c=0;o.setUint32(c,is),c+=4,o.setUint32(c,t.version),c+=4,o.setUint32(c,n.length),c+=4;for(let m=0;m<n.length;m++){let h=n[m],d=r[m],g=c;o.setUint32(c,h.stat.ctimeSeconds),o.setUint32(c+4,h.stat.ctimeNanoseconds),o.setUint32(c+8,h.stat.mtimeSeconds),o.setUint32(c+12,h.stat.mtimeNanoseconds),o.setUint32(c+16,h.stat.dev),o.setUint32(c+20,h.stat.ino),o.setUint32(c+24,h.mode),o.setUint32(c+28,h.stat.uid),o.setUint32(c+32,h.stat.gid),o.setUint32(c+36,h.stat.size),c+=40;let p=Ie(h.hash);a.set(p,c),c+=20;let b=Math.min(d.byteLength,4095),x=(h.stage&3)<<12|b;o.setUint16(c,x),c+=2,a.set(d,c),c+=d.byteLength,a[c]=0,c+=1;let j=62+d.byteLength+1,S=Math.ceil(j/8)*8;c=g+S}let f=a.subarray(0,c),l=await Ve(f),u=Ie(l);return a.set(u,c),a}function wn(t,e){return t.path<e.path?-1:t.path>e.path?1:t.stage-e.stage}var $o=new TextEncoder;function ae(t){return typeof t=="string"?t==="120000":t===40960}function Rn(t){return typeof t=="string"?t==="160000":t===57344}function In(t){return{stdout:"",stderr:`fatal: ${t}
|
|
10
|
+
`,exitCode:128}}var Mo=In("not a git repository (or any of the parent directories): .git"),Lo=In("this operation must be run in a work tree");function Ne(t,e){return t<e?-1:t>e?1:0}function En(t){return t.slice(0,7)}function xn(t){let e=t.indexOf(`
|
|
11
|
+
`);return e===-1?t:t.slice(0,e)}async function yt(t,e){return Pn(t,e,"")}async function Pn(t,e,n){let r=[],s=new Map;for(let a of e){let o=n?a.path.slice(n.length+1):a.path,c=o.indexOf("/");if(c===-1)r.push({mode:cs(a.mode),name:o,hash:a.hash});else{let f=o.slice(0,c),l=s.get(f);l||(l=[],s.set(f,l)),l.push(a)}}for(let[a,o]of s){let c=n?`${n}/${a}`:a,f=await Pn(t,o,c);r.push({mode:U.DIRECTORY,name:a,hash:f})}r.sort((a,o)=>{let c=a.mode===U.DIRECTORY?`${a.name}/`:a.name,f=o.mode===U.DIRECTORY?`${o.name}/`:o.name;return c<f?-1:c>f?1:0});let i=ge({type:"tree",entries:r});return N(t,"tree",i)}async function z(t,e,n=""){let r=await F(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=ie(r.content),i=[];for(let a of s.entries){let o=n?`${n}/${a.name}`:a.name;if(a.mode===U.DIRECTORY){let c=await z(t,a.hash,o);i.push(...c)}else i.push({path:o,mode:a.mode,hash:a.hash})}return i}async function xe(t,e){if(!e)return new Map;let n=await z(t,e);return new Map(n.map(r=>[r.path,r]))}async function ce(t,e,n){if(e===n)return[];let r=[];return await Tn(t,e,n,"",r),r.sort((s,i)=>Ne(s.path,i.path))}async function On(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ie(n.content).entries}async function Tn(t,e,n,r,s){if(e===n)return;let i=e?await On(t,e):[],a=n?await On(t,n):[],o=new Map;for(let l of i)o.set(l.name,l);let c=new Map;for(let l of a)c.set(l.name,l);let f=new Set;for(let l of i)f.add(l.name);for(let l of a)f.add(l.name);for(let l of f){let u=o.get(l),m=c.get(l),h=r?`${r}/${l}`:l;if(u&&m){if(u.hash===m.hash&&u.mode===m.mode)continue;let d=u.mode===U.DIRECTORY,g=m.mode===U.DIRECTORY;d&&g?await Tn(t,u.hash,m.hash,h,s):d?(await qe(t,u.hash,h,"deleted",s),s.push({path:h,status:"added",newHash:m.hash,newMode:m.mode})):g?(s.push({path:h,status:"deleted",oldHash:u.hash,oldMode:u.mode}),await qe(t,m.hash,h,"added",s)):s.push({path:h,status:"modified",oldHash:u.hash,newHash:m.hash,oldMode:u.mode,newMode:m.mode})}else if(u)u.mode===U.DIRECTORY?await qe(t,u.hash,h,"deleted",s):s.push({path:h,status:"deleted",oldHash:u.hash,oldMode:u.mode});else{let d=m;d.mode===U.DIRECTORY?await qe(t,d.hash,h,"added",s):s.push({path:h,status:"added",newHash:d.hash,newMode:d.mode})}}}async function qe(t,e,n,r,s){let i=await z(t,e,n);for(let a of i)r==="added"?s.push({path:a.path,status:"added",newHash:a.hash,newMode:a.mode}):s.push({path:a.path,status:"deleted",oldHash:a.hash,oldMode:a.mode})}function cs(t){return t.toString(8).padStart(6,"0")}function ls(t){let e=Math.min(t.length,8e3),n=0;for(let r=0;r<e;r++)t.charCodeAt(r)===0&&n++;return n>e*.01}function kn(t,e,n,r){if(ls(t)){let a=e.some(o=>o.test(t));return{matches:[],binary:a}}let s=t.split(`
|
|
12
|
+
`);if(s.length>0&&s[s.length-1]===""&&s.pop(),n&&e.length>1&&!e.every(o=>s.some(c=>o.test(c))))return{matches:[],binary:!1};let i=[];for(let a=0;a<s.length;a++){let o=s[a],c=e.some(f=>f.test(o));(r?!c:c)&&i.push({lineNo:a+1,line:o})}return{matches:i,binary:!1}}function fs(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Cn(t,e){let n=e?.fixed?fs(t):t;e?.wordRegexp&&(n=`\\b${n}\\b`);let r=e?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}var us=new TextEncoder,Sn=new TextDecoder,Oe=16877,$n=33188,hs=33261,An=40960;function V(t){let e=[];for(let n of t.split("/"))n==="."||n===""||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}function vn(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function jn(t){switch(t){case U.EXECUTABLE:return hs;case U.SYMLINK:return An;case U.DIRECTORY:return Oe;default:return $n}}var Pe=class{constructor(e,n,r="/"){this.objectStore=e;this.rootTreeHash=n;this.rootPath=r;let s=V(r);this.overlay.set(s,{type:"directory",mode:Oe,mtime:this.epoch})}treeCache=new Map;overlay=new Map;removals=new Set;epoch=new Date(0);toRelative(e){let n=V(e),r=V(this.rootPath);if(n===r)return"";let s=r==="/"?"/":`${r}/`;return n.startsWith(s)?n.slice(s.length):null}async loadTreeDir(e){let n=this.treeCache.get(e);if(n)return n;if(e===""){let a=await this.objectStore.read(this.rootTreeHash);if(a.type!=="tree")return null;let o=ie(a.content);return this.treeCache.set("",o.entries),o.entries}let r=e.split("/"),s=await this.loadTreeDir("");if(!s)return null;let i="";for(let a of r){let o=s.find(u=>u.name===a);if(!o||o.mode!==U.DIRECTORY)return null;i=i?`${i}/${a}`:a;let c=this.treeCache.get(i);if(c){s=c;continue}let f=await this.objectStore.read(o.hash);if(f.type!=="tree")return null;let l=ie(f.content);this.treeCache.set(i,l.entries),s=l.entries}return s}async lookupTreeEntry(e){if(e==="")return null;let n=e.lastIndexOf("/"),r=n===-1?"":e.slice(0,n),s=n===-1?e:e.slice(n+1),i=await this.loadTreeDir(r);if(!i)return null;let a=i.find(o=>o.name===s);return a?{entry:a,dirEntries:i}:null}async isTreeDirectory(e){return e===""?!0:(await this.lookupTreeEntry(e))?.entry.mode===U.DIRECTORY}ensureOverlayParents(e){let n=vn(e);n===V(this.rootPath)||n==="/"||this.overlay.has(n)||(this.ensureOverlayParents(n),this.overlay.set(n,{type:"directory",mode:Oe,mtime:new Date}))}async readFile(e){return Sn.decode(await this.readFileBuffer(e))}async readFileBuffer(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`ENOENT: no such file or directory, open '${e}'`);let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(i.entry.mode===U.DIRECTORY)throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let a=await this.objectStore.read(i.entry.hash);if(a.type!=="blob")throw new Error(`ENOENT: no such file or directory, open '${e}'`);return a.content}async writeFile(e,n){let r=V(e);this.removals.delete(r),this.ensureOverlayParents(r),this.overlay.set(r,{type:"file",content:typeof n=="string"?us.encode(n):new Uint8Array(n),mode:$n,mtime:new Date})}async exists(e){let n=V(e);if(this.removals.has(n))return!1;if(this.overlay.has(n))return!0;let r=this.toRelative(n);return r===null?!1:r===""||await this.isTreeDirectory(r)?!0:await this.lookupTreeEntry(r)!==null}async stat(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:r.type==="file"?r.content.byteLength:0,mtime:r.mtime};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:Oe,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let{entry:a}=i,o=a.mode===U.DIRECTORY,c=a.mode===U.SYMLINK,f=0;return o||(f=(await this.objectStore.read(a.hash)).content.byteLength),{isFile:!o&&!c,isDirectory:o,isSymbolicLink:!1,mode:jn(a.mode),size:f,mtime:this.epoch}}async lstat(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.overlay.get(n);if(r)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};let s=this.toRelative(n);if(s===null)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(s==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:Oe,size:0,mtime:this.epoch};let i=await this.lookupTreeEntry(s);if(!i)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let{entry:a}=i,o=a.mode===U.DIRECTORY,c=a.mode===U.SYMLINK,f=0;return o||(f=(await this.objectStore.read(a.hash)).content.byteLength),{isFile:!o&&!c,isDirectory:o,isSymbolicLink:c,mode:jn(a.mode),size:f,mtime:this.epoch}}async mkdir(e,n){let r=V(e);if(this.overlay.has(r)){if(this.overlay.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.toRelative(r);if(s!==null&&!this.removals.has(r)&&(s===""||await this.isTreeDirectory(s))){if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let i=vn(r);if(!(this.overlay.has(i)||await this.exists(i)))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.removals.delete(r),this.overlay.set(r,{type:"directory",mode:Oe,mtime:new Date})}async readdir(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,s=this.toRelative(n);if(s!==null){let a=await this.loadTreeDir(s);if(a)for(let o of a){let c=n==="/"?`/${o.name}`:`${n}/${o.name}`;this.removals.has(c)||r.add(o.name)}}let i=n==="/"?"/":`${n}/`;for(let a of this.overlay.keys())if(a!==n&&a.startsWith(i)){let c=a.slice(i.length).split("/")[0];c&&!this.removals.has(n==="/"?`/${c}`:`${n}/${c}`)&&r.add(c)}if(r.size===0){if(this.overlay.get(n)?.type==="directory")return[];if(s!==null&&(s===""||await this.isTreeDirectory(s)))return[];throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}return[...r].sort()}async rm(e,n){let r=V(e);if(!await this.exists(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}let i=r==="/"?"/":`${r}/`;if(n?.recursive)for(let a of[...this.overlay.keys()])a.startsWith(i)&&(this.overlay.delete(a),this.removals.add(a));if(this.overlay.delete(r),this.removals.add(r),n?.recursive){let a=this.toRelative(r);a!==null&&await this.markTreeChildrenRemoved(a,r)}}async markTreeChildrenRemoved(e,n){let r=await this.loadTreeDir(e);if(r)for(let s of r){let i=n==="/"?`/${s.name}`:`${n}/${s.name}`;if(this.removals.add(i),s.mode===U.DIRECTORY){let a=e?`${e}/${s.name}`:s.name;await this.markTreeChildrenRemoved(a,i)}}}async readlink(e){let n=V(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRelative(n);if(s===null||s==="")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let i=await this.lookupTreeEntry(s);if(!i||i.entry.mode!==U.SYMLINK)throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let a=await this.objectStore.read(i.entry.hash);return Sn.decode(a.content)}async symlink(e,n){let r=V(n);if(await this.exists(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureOverlayParents(r),this.removals.delete(r),this.overlay.set(r,{type:"symlink",target:e,mode:An,mtime:new Date})}};async function Ue(t,e,n,r){let s=new Set,i=0;for(let a of e){if(!pn(a.path))throw new Error(`refusing to check out unsafe path '${a.path}'`);let o=pe(r,a.path);if(!gn(r,o))throw new Error(`refusing to check out path outside target directory: '${a.path}'`);let c=nn(o);if(c!==r&&!s.has(c)&&(await n.mkdir(c,{recursive:!0}),s.add(c)),Rn(a.mode))await n.mkdir(o,{recursive:!0});else if(ae(a.mode)){let f=await B(t,a.hash);if(!yn(f))throw new Error(`refusing to create symlink with unsafe target '${f}'`);n.symlink?await n.symlink(f,o):await n.writeFile(o,f)}else{let f=await oe(t,a.hash);await n.writeFile(o,f)}i++}return i}function Ge(t,e){let n=null,r;function s(i="/"){return n&&r===i||(n=new Pe(t.objectStore,e,i),r=i),n}return{treeHash:e,async readFile(i){let a=s(),o=i.startsWith("/")?i:"/"+i;return await a.exists(o)?a.readFile(o):null},async readFileBytes(i){let a=s(),o=i.startsWith("/")?i:"/"+i;return await a.exists(o)?a.readFileBuffer(o):null},async files(){return(await z(t,e)).map(a=>a.path)},fs(i="/"){return s(i)},async materialize(i,a="/"){let o=await z(t,e);return Ue(t,o,i,a)}}}async function ms(t,e){return te(t,e)}async function ye(t,e){return mn(t,e)}async function ds(t){return dt(t,"refs/heads")}async function ps(t){return dt(t,"refs/tags")}async function gs(t){let e=await t.refStore.readRef("HEAD");if(!e)return{branch:null,ref:null,hash:null};if(e.type==="symbolic"){let n=await t.refStore.readRef(e.target),r=n?.type==="direct"?n.hash:null;return{branch:e.target.startsWith("refs/heads/")?pt(e.target):null,ref:e.target,hash:r}}return{branch:null,ref:null,hash:e.hash}}async function ys(t,e){return v(t,e)}async function bs(t,e){return oe(t,e)}async function ws(t,e){return B(t,e)}async function Rs(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ie(n.content).entries}async function Is(t,e,n){let r=await v(t,e);return Ge(t,r.tree).readFile(n)}function Es(t){let e=0;for(let n=0;n<t.length;n++)t[n]==="/"&&e++;return e}function xs(t,e){let n=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"\0").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]").replace(/\0/g,".*");return new RegExp(`^${n}$`).test(e)}async function Os(t,e,n,r){let s=[];for(let d of n)if(d instanceof RegExp)s.push(d);else{let g=Cn(d,{fixed:r?.fixed,ignoreCase:r?.ignoreCase,wordRegexp:r?.wordRegexp});if(!g)throw new Error(`Invalid pattern: ${d}`);s.push(g)}let i=await v(t,e),o=(await z(t,i.tree)).filter(d=>!d.mode.startsWith("120")).sort((d,g)=>d.path<g.path?-1:d.path>g.path?1:0),c=r?.allMatch??!1,f=r?.invert??!1,l=r?.maxCount,u=r?.maxDepth,m=r?.paths,h=[];for(let d of o){if(u!==void 0&&Es(d.path)>u||m&&!m.some(x=>xs(x,d.path)))continue;let g=await B(t,d.hash),p=kn(g,s,c,f);if(p.binary){h.push({path:d.path,matches:[],binary:!0});continue}if(p.matches.length===0)continue;let b=l!==void 0?p.matches.slice(0,l):p.matches;h.push({path:d.path,matches:b,binary:!1})}return h}function J(t){if(t.length===0)return[];let e=t.split(`
|
|
13
|
+
`);return e[e.length-1]===""&&e.pop(),e}var Ps=4,Mn=1024,Xe=100,Qe=0,Ze=1,Te=2;function wt(t){let e=1;for(;e*e<t;)e++;return e}function Ts(t,e){let n=new Map,r=[],s=new Array(t.length),i=new Array(e.length);for(let a=0;a<t.length;a++){let o=t[a],c=n.get(o);c===void 0&&(c=r.length,n.set(o,c),r.push({len1:0,len2:0})),r[c].len1++,s[a]=c}for(let a=0;a<e.length;a++){let o=e[a],c=n.get(o);c===void 0&&(c=r.length,n.set(o,c),r.push({len1:0,len2:0})),r[c].len2++,i[a]=c}return{classes1:s,classes2:i,classInfo:r}}function ks(t,e,n,r){let s=0,i=Math.min(e,r);for(;s<i&&t[s]===n[s];)s++;let a=s,o=0,c=i-a;for(;o<c&&t[e-1-o]===n[r-1-o];)o++;return{dstart:a,dend1:e-o-1,dend2:r-o-1}}function Ln(t,e,n,r){e-n>Xe&&(n=e-Xe),r-e>Xe&&(r=e+Xe);let s=0,i=1;for(let c=1;e-c>=n;c++){let f=t[e-c];if(f===Qe)s++;else if(f===Te)i++;else break}if(s===0)return!1;let a=0,o=1;for(let c=1;e+c<=r;c++){let f=t[e+c];if(f===Qe)a++;else if(f===Te)o++;else break}return a===0?!1:(a+=s,o+=i,o*Ps<o+a)}function Cs(t,e,n,r,s,i,a,o,c,f){let l=new Uint8Array(e),u=new Uint8Array(r),m=Math.min(wt(e),Mn);for(let p=i;p<=a;p++){let b=s[t[p]].len2;b===0?l[p]=Qe:b>=m?l[p]=Te:l[p]=Ze}let h=Math.min(wt(r),Mn);for(let p=i;p<=o;p++){let b=s[n[p]].len1;b===0?u[p]=Qe:b>=h?u[p]=Te:u[p]=Ze}let d=[];for(let p=i;p<=a;p++)l[p]===Ze||l[p]===Te&&!Ln(l,p,i,a)?d.push(p):c[p]=1;let g=[];for(let p=i;p<=o;p++)u[p]===Ze||u[p]===Te&&!Ln(u,p,i,o)?g.push(p):f[p]=1;return{refIndex1:d,nreff1:d.length,refIndex2:g,nreff2:g.length}}var ue=20,Dn=4,Ss=256,vs=256,Je=2147483647;function K(t,e){return t[e]??0}function js(t,e,n,r,s,i,a,o,c,f){let l=e-i,u=n-s,m=e-s,h=n-i,d=m-h&1,g=m,p=m,b=h,x=h;a[m]=e,o[h]=n;for(let j=1;;j++){let S=!1;g>l?a[--g-1]=-1:++g,p<u?a[++p+1]=-1:--p;for(let P=p;P>=g;P-=2){let w;K(a,P-1)>=K(a,P+1)?w=K(a,P-1)+1:w=K(a,P+1);let R=w,k=w-P;for(;w<n&&k<i&&t[w]===r[k];)w++,k++;if(w-R>ue&&(S=!0),a[P]=w,d&&b<=P&&P<=x&&K(o,P)<=w)return{i1:w,i2:k,minLo:!0,minHi:!0}}b>l?o[--b-1]=Je:++b,x<u?o[++x+1]=Je:--x;for(let P=x;P>=b;P-=2){let w;K(o,P-1)<K(o,P+1)?w=K(o,P-1):w=K(o,P+1)-1;let R=w,k=w-P;for(;w>e&&k>s&&t[w-1]===r[k-1];)w--,k--;if(R-w>ue&&(S=!0),o[P]=w,!d&&g<=P&&P<=p&&w<=K(a,P))return{i1:w,i2:k,minLo:!0,minHi:!0}}if(!c){if(S&&j>Ss){let P=0,w=null;for(let R=p;R>=g;R-=2){let k=R>m?R-m:m-R,E=K(a,R),C=E-R,O=E-e+(C-s)-k;if(O>Dn*j&&O>P&&e+ue<=E&&E<n&&s+ue<=C&&C<i){let $=!0;for(let D=1;D<=ue;D++)if(t[E-D]!==r[C-D]){$=!1;break}$&&(P=O,w={i1:E,i2:C,minLo:!0,minHi:!1})}}if(w)return w;P=0,w=null;for(let R=x;R>=b;R-=2){let k=R>h?R-h:h-R,E=K(o,R),C=E-R,O=n-E+(i-C)-k;if(O>Dn*j&&O>P&&e<E&&E<=n-ue&&s<C&&C<=i-ue){let $=!0;for(let D=0;D<ue;D++)if(t[E+D]!==r[C+D]){$=!1;break}$&&(P=O,w={i1:E,i2:C,minLo:!1,minHi:!0})}}if(w)return w}if(j>=f){let P=-1,w=-1;for(let E=p;E>=g;E-=2){let C=Math.min(K(a,E),n),O=C-E;i<O&&(C=i+E,O=i),P<C+O&&(P=C+O,w=C)}let R=Je,k=Je;for(let E=x;E>=b;E-=2){let C=Math.max(e,K(o,E)),O=C-E;O<s&&(C=s+E,O=s),C+O<R&&(R=C+O,k=C)}return n+i-R<P-(e+s)?{i1:w,i2:P-w,minLo:!0,minHi:!1}:{i1:k,i2:R-k,minLo:!1,minHi:!0}}}}}function Rt(t,e,n,r,s,i,a,o,c,f,l,u,m,h){for(;e<n&&s<i&&t[e]===r[s];)e++,s++;for(;e<n&&s<i&&t[n-1]===r[i-1];)n--,i--;if(e===n)for(let d=s;d<i;d++)o[f[d]]=1;else if(s===i)for(let d=e;d<n;d++)a[c[d]]=1;else{let d=js(t,e,n,r,s,i,l,u,m,h);Rt(t,e,d.i1,r,s,d.i2,a,o,c,f,l,u,d.minLo,h),Rt(t,d.i1,n,r,d.i2,i,a,o,c,f,l,u,d.minHi,h)}}function $s(t,e,n,r){let s=[],i=0,a=0,o=1,c=1;for(;i<t.length||a<e.length;){if(i<t.length&&a<e.length&&!n[i]&&!r[a]){s.push({type:"keep",line:t[i]??"",oldLineNo:o++,newLineNo:c++}),i++,a++;continue}for(;i<t.length&&n[i];)s.push({type:"delete",line:t[i]??"",oldLineNo:o++,newLineNo:0}),i++;for(;a<e.length&&r[a];)s.push({type:"insert",line:e[a]??"",oldLineNo:0,newLineNo:c++}),a++}return s}var Hn=200,Bn=20,Nn=100,As=1,Ms=21,Ls=-30,Ds=6,Hs=-4,Bs=10,Ns=24,Us=17,Gs=23,Fs=17,_s=60;function bt(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);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>=Hn)return Hn}return-1}function Un(t,e,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=bt(t[n]));for(let s=n-1;s>=0&&(r.preIndent=bt(t[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===Bn){r.preIndent=0;break}for(let s=n+1;s<e&&(r.postIndent=bt(t[s]),r.postIndent===-1);s++)if(r.postBlank+=1,r.postBlank===Bn){r.postIndent=0;break}return r}function Gn(t,e){t.preIndent===-1&&t.preBlank===0&&(e.penalty+=As),t.endOfFile&&(e.penalty+=Ms);let n=t.indent===-1?1+t.postBlank:0,r=t.preBlank+n;e.penalty+=Ls*r,e.penalty+=Ds*n;let s=t.indent!==-1?t.indent:t.postIndent,i=r!==0;e.effectiveIndent+=s,s===-1||t.preIndent===-1||(s>t.preIndent?e.penalty+=i?Bs:Hs:s===t.preIndent||(t.postIndent!==-1&&t.postIndent>s?e.penalty+=i?Us:Ns:e.penalty+=i?Fs:Gs))}function Ws(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndent<e.effectiveIndent?1:0);return _s*n+(t.penalty-e.penalty)}function Fn(t,e,n,r,s,i){let a=0,o=0;for(;t[o];)o++;let c=0,f=0;for(;s[f];)f++;let l=(u,m)=>e[u]===e[m];for(;;){if(o!==a){let u,m,h;do{for(u=o-a,m=-1;a>0&&l(a-1,o-1);){for(t[--a]=1,t[--o]=0;t[a-1];)a--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(h=o,f>c&&(m=o);!(o>=r||!l(a,o));){for(t[a++]=0,t[o++]=1;t[o];)o++;if(f>=i)break;for(c=f+1,f=c;s[f];f++);f>c&&(m=o)}}while(u!==o-a);if(o!==h)if(m!==-1)for(;f===c;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;s[c-1];c--);}else{let d=-1,g={effectiveIndent:0,penalty:0},p=h;for(o-u-1>p&&(p=o-u-1),o-Nn>p&&(p=o-Nn);p<=o;p++){let b={effectiveIndent:0,penalty:0},x=Un(n,r,p);Gn(x,b);let j=Un(n,r,p-u);Gn(j,b),(d===-1||Ws(b,g)<=0)&&(g={effectiveIndent:b.effectiveIndent,penalty:b.penalty},d=p)}for(;o>d;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;s[c-1];c--);}}}if(o>=r)break;for(a=o+1,o=a;t[o];o++);if(f>=i)break;for(c=f+1,f=c;s[f];f++);}}function It(t,e){let n=t.length,r=e.length,s=new Uint8Array(n),i=new Uint8Array(r);if(n>0&&r>0){let{classes1:a,classes2:o,classInfo:c}=Ts(t,e),{dstart:f,dend1:l,dend2:u}=ks(a,n,o,r);if(f>l)for(let m=f;m<r-(n-1-l);m++)i[m]=1;else if(f>u)for(let m=f;m<n-(r-1-u);m++)s[m]=1;else{let{refIndex1:m,nreff1:h,refIndex2:d,nreff2:g}=Cs(a,n,o,r,c,f,l,u,s,i);if(h>0&&g>0){let p=new Array(h);for(let w=0;w<h;w++)p[w]=a[m[w]];let b=new Array(g);for(let w=0;w<g;w++)b[w]=o[d[w]];let x={},j={},S=h+g+3,P=Math.max(vs,wt(S));Rt(p,0,h,b,0,g,s,i,m,d,x,j,!1,P)}else if(h===0)for(let p=0;p<g;p++)i[d[p]]=1;else for(let p=0;p<h;p++)s[m[p]]=1;Fn(s,a,t,n,i,r),Fn(i,o,e,r,s,n)}}else n===0?i.fill(1):s.fill(1);return{changedOld:s,changedNew:i}}function be(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return e.map((a,o)=>({type:"insert",line:a,oldLineNo:0,newLineNo:o+1}));if(r===0)return t.map((a,o)=>({type:"delete",line:a,oldLineNo:o+1,newLineNo:0}));let{changedOld:s,changedNew:i}=It(t,e);return $s(t,e,s,i)}var zs=3;function Et(t,e=zs){if(e=Math.max(0,e),t.length===0)return[];let n=[];for(let o=0;o<t.length;o++){let c=t[o];c&&c.type!=="keep"&&n.push(o)}if(n.length===0)return[];let r=n[0]??0,s=[],i=Math.max(0,r-e),a=Math.min(t.length-1,r+e);for(let o=1;o<n.length;o++){let c=n[o]??0,f=Math.max(0,c-e),l=Math.min(t.length-1,c+e);f<=a+1||(s.push({start:i,end:a}),i=f),a=l}return s.push({start:i,end:a}),s.map(o=>Vs(t,o.start,o.end))}function Vs(t,e,n){let r=0,s=0,i=0,a=0,o=[],c=!1,f=!1;for(let l=e;l<=n;l++){let u=t[l];if(u)switch(u.type){case"keep":c||(r=u.oldLineNo,c=!0),f||(i=u.newLineNo,f=!0),s++,a++,o.push({type:"context",content:u.line});break;case"delete":c||(r=u.oldLineNo,c=!0),s++,o.push({type:"delete",content:u.line});break;case"insert":f||(i=u.newLineNo,f=!0),a++,o.push({type:"insert",content:u.line});break}}if(c||(r=i>0?i:1),f||(i=r>0?r:1),s===0)for(let l=e;l<=n;l++){let u=t[l];if(u&&u.type==="insert"){r=u.newLineNo>1?u.newLineNo-1:0;break}}if(a===0)for(let l=e;l<=n;l++){let u=t[l];if(u&&u.type==="delete"){i=u.oldLineNo>1?u.oldLineNo-1:0;break}}return{oldStart:r,oldCount:s,newStart:i,newCount:a,lines:o}}function et(t){return t?t.length<40?t:En(t):"0000000"}function _n(t,e,n,r,s,i){let{path:a,oldMode:o,newMode:c}=e;t.push(`diff --git a/${a} b/${n}`),i?(t.push(`similarity index ${e.similarity??100}%`),t.push(`rename from ${a}`),t.push(`rename to ${n}`)):r?t.push(`new file mode ${c||"100644"}`):s?t.push(`deleted file mode ${o||"100644"}`):o&&c&&o!==c&&(t.push(`old mode ${o}`),t.push(`new mode ${c}`))}function Ks(t,e,n){let{path:r,oldContent:s,newContent:i,oldMode:a,oldHash:o,newHash:c}=t,f=t.renameTo!==void 0,l=t.renameTo??r,u=t.isNew??s==="",m=t.isDeleted??i==="";if(s===i&&!f)return"";let h=[];if(_n(h,t,l,u,m,f),s!==i){if(o||c){let d=et(o),g=et(c);u||m||f?h.push(`index ${d}..${g}`):h.push(`index ${d}..${g} ${a||"100644"}`)}e&&n?h.push(`Binary files a/${r} and b/${l} differ`):u?h.push(`Binary files /dev/null and b/${l} differ`):m?h.push(`Binary files a/${r} and /dev/null differ`):h.push(`Binary files a/${r} and b/${l} differ`)}return`${h.join(`
|
|
14
14
|
`)}
|
|
15
|
-
`}function
|
|
15
|
+
`}function Wn(t){let{path:e,oldContent:n,newContent:r,oldMode:s,newMode:i,oldHash:a,newHash:o}=t,c=t.renameTo!==void 0,f=t.renameTo??e,l=Z(n),u=Z(r);if(l||u)return Ks(t,l,u);let m=J(n),h=J(r),d=n.length>0&&n.endsWith(`
|
|
16
16
|
`),g=r.length>0&&r.endsWith(`
|
|
17
|
-
`),p="\0NOEOL",b=d
|
|
17
|
+
`),p="\0NOEOL",b=m;!d&&m.length>0&&(b=m.slice(),b[b.length-1]+=p);let x=h;!g&&h.length>0&&(x=h.slice(),x[x.length-1]+=p);let j=be(b,x);if(!d||!g)for(let O of j)O.line.includes(p)&&(O.line=O.line.replace(p,""));let S=Et(j,t.contextLines);if(S.length===0&&!c)return"";let P=t.isNew??n==="",w=t.isDeleted??r==="",R=[];if(_n(R,t,f,P,w,c),S.length===0)return`${R.join(`
|
|
18
18
|
`)}
|
|
19
|
-
`;if(a||o){let O=
|
|
19
|
+
`;if(a||o){let O=et(a),$=et(o);P||w?R.push(`index ${O}..${$}`):c?R.push(`index ${O}..${$} ${s||"100644"}`):s&&i&&s!==i?R.push(`index ${O}..${$}`):R.push(`index ${O}..${$} ${s||"100644"}`)}let k=O=>O.includes(" ")?" ":"";P?(R.push("--- /dev/null"),R.push(`+++ b/${f}${k(f)}`)):w?(R.push(`--- a/${e}${k(e)}`),R.push("+++ /dev/null")):(R.push(`--- a/${e}${k(e)}`),R.push(`+++ b/${f}${k(f)}`));let E=m.length,C=h.length;for(let O of S){let $=O.oldCount===1?`${O.oldStart}`:`${O.oldStart},${O.oldCount}`,D=O.newCount===1?`${O.newStart}`:`${O.newStart},${O.newCount}`,re="",de=O.oldCount===0?O.oldStart-1:O.oldStart-2;for(let T=de;T>=0;T--){let L=m[T];if(L&&/^[a-zA-Z$_]/.test(L)){re=` ${L.trimEnd().slice(0,79)}`;break}}R.push(`@@ -${$} +${D} @@${re}`);let I=O.oldStart,y=O.newStart;for(let T of O.lines)switch(T.type){case"context":R.push(` ${T.content}`),(!d&&I===E||!g&&y===C)&&R.push("\"),I++,y++;break;case"delete":R.push(`-${T.content}`),!d&&I===E&&R.push("\"),I++;break;case"insert":R.push(`+${T.content}`),!g&&y===C&&R.push("\"),y++;break}}return`${R.join(`
|
|
20
20
|
`)}
|
|
21
|
-
`}function
|
|
22
|
-
`)[0],boundary:a,previous:o}}var ke=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 n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,a=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),a<r&&this.higher(n[a],n[s])&&(s=a),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*fe(t,e,n){if(n?.topoOrder){yield*Xs(t,e,n);return}let r=await Vn(t,n?.exclude),s=new Set(r),i=new ke,a=n?.shallowBoundary,o=n?.limit,c=0,l=Array.isArray(e)?e:[e];for(let f of l)s.has(f)||i.push(await tt(t,f));for(;i.size>0;){let f=i.pop();if(s.has(f.hash))continue;if(s.add(f.hash),yield f,o!==void 0&&++c>=o)return;if(a?.has(f.hash))continue;let u=n?.firstParent?f.commit.parents.slice(0,1):f.commit.parents;for(let d of u)if(!s.has(d))try{i.push(await tt(t,d))}catch{}}}async function*Xs(t,e,n){let r=await Vn(t,n?.exclude),s=new Set(r),i=new ke,a=n?.shallowBoundary,o=Array.isArray(e)?e:[e];for(let h of o)s.has(h)||i.push(await tt(t,h));let c=[],l=new Map;for(;i.size>0;){let h=i.pop();if(s.has(h.hash)||(s.add(h.hash),l.set(h.hash,c.length),c.push(h),a?.has(h.hash)))continue;let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of m)if(!s.has(g))try{i.push(await tt(t,g))}catch{}}let f=c.length;if(f===0)return;let u=new Int32Array(f);for(let h of c){let m=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of m){let p=l.get(g);p!==void 0&&(u[p]=(u[p]??0)+1)}}let d=[];for(let h=f-1;h>=0;h--)u[h]===0&&d.push(h);for(;d.length>0;){let h=d.pop();yield c[h];let m=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let g of m){let p=l.get(g);if(p!==void 0){let b=(u[p]??0)-1;u[p]=b,b===0&&d.push(p)}}}}async function zn(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let o of fe(t,e))r.add(o.hash);let s=new Set;for await(let o of fe(t,n))s.add(o.hash);let i=0;for(let o of r)s.has(o)||i++;let a=0;for(let o of s)r.has(o)||a++;return{ahead:i,behind:a}}async function Vn(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of fe(t,e))n.add(r.hash);return n}async function tt(t,e){return{hash:e,commit:await $(t,e)}}async function Zs(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let a;try{a=await $(t,i)}catch{continue}for(let o of a.parents)n.has(o)||r.push(o)}return n}async function Rt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let a=s[i++];if(a===e)return!0;if(r.has(a))continue;r.add(a);let o;try{o=await $(t,a)}catch{continue}for(let c of o.parents)r.has(c)||s.push(c)}return!1}async function Ge(t,e,n){if(e===n)return[e];let r=await Zs(t,e),s=[],i=new Set,a=[n],o=0;for(;o<a.length;){let l=a[o++];if(i.has(l))continue;if(i.add(l),r.has(l)){s.push(l);continue}let f;try{f=await $(t,l)}catch{continue}for(let u of f.parents)i.has(u)||a.push(u)}if(s.length<=1)return s;let c=[];for(let l of s){let f=!1;for(let u of s)if(u!==l&&await Rt(t,l,u)){f=!0;break}f||c.push(l)}return c.length<=1?c:Js(t,e,n,c)}async function Js(t,e,n,r){let s=new Set(r),i=new Set,a=[],o=new Map,c=new Map,l=0,f=[{hash:e,mask:1,seq:l++},{hash:n,mask:2,seq:l++}];async function u(d){let h=c.get(d);if(h!==void 0)return h;let m=(await $(t,d)).committer.timestamp;return c.set(d,m),m}for(;f.length>0;){let d=0,h=await u(f[0].hash);for(let x=1;x<f.length;x++){let v=f[x],C=await u(v.hash),T=f[d];(C>h||C===h&&v.seq<T.seq)&&(d=x,h=C)}let m=f.splice(d,1)[0],g=o.get(m.hash)??0,p=g|m.mask;if(p===g)continue;if(o.set(m.hash,p),p===3&&s.has(m.hash)&&!i.has(m.hash)&&(a.push(m.hash),i.add(m.hash),i.size===s.size))break;let b=await $(t,m.hash);for(let x of b.parents)f.push({hash:x,mask:p,seq:l++})}for(let d of r)i.has(d)||a.push(d);return a}async function Qs(t,e){return z(t,e)}async function ei(t,e,n){return ce(t,e,n)}async function ti(t,e,n){let r=await $(t,n),s=null;return e&&(s=(await $(t,e)).tree),ce(t,s,r.tree)}async function*ni(t,e,n){let r=e?[e]:[];for await(let s of fe(t,n,{exclude:r}))yield{hash:s.hash,message:s.commit.message,tree:s.commit.tree,parents:s.commit.parents,author:s.commit.author,committer:s.commit.committer}}async function ri(t,e,n){return Rt(t,e,n)}async function si(t,e,n){return Ge(t,e,n)}async function ii(t,e,n){return zn(t,e,n)}async function oi(t,e,n,r){return Wn(t,e,n,r)}function ai(t){return t==="insert"?"+":t==="delete"?"-":" "}function ci(t){return{oldStart:t.oldStart,oldCount:t.oldCount,newStart:t.newStart,newCount:t.newCount,lines:t.lines.map(e=>ai(e.type)+e.content)}}function fi(t,e,n){let r=J(t),s=J(e),i=ge(r,s);return It(i,n).map(ci)}async function Kn(t,e){let n=await Ie(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function Yn(t,e,n,r){let s=await Kn(t,e),i=await Kn(t,n),a=await $(t,s),o=await $(t,i),c=await ce(t,a.tree,o.tree),l=r?.renames!==!1,f=r?.paths,u=[];if(l){let h=await ye(t,c);c=h.remaining,u=h.renames}let d=[];for(let h of c)f&&!f.some(m=>h.path.startsWith(m))||d.push({path:h.path,status:h.status,oldContent:h.oldHash?await B(t,h.oldHash):"",newContent:h.newHash?await B(t,h.newHash):"",oldHash:h.oldHash??void 0,newHash:h.newHash??void 0,oldMode:h.oldMode,newMode:h.newMode});for(let h of u)f&&!f.some(m=>h.newPath.startsWith(m)||h.oldPath.startsWith(m))||d.push({path:h.newPath,oldPath:h.oldPath,status:"renamed",oldContent:await B(t,h.oldHash),newContent:await B(t,h.newHash),oldHash:h.oldHash,newHash:h.newHash,oldMode:h.oldMode,newMode:h.newMode,similarity:h.similarity});return d.sort((h,m)=>h.path.localeCompare(m.path)),d}async function li(t,e,n,r){let s=await Yn(t,e,n,r),i=r?.contextLines;return s.map(a=>({path:a.path,status:a.status,oldPath:a.oldPath,similarity:a.similarity,hunks:fi(a.oldContent,a.newContent,i)}))}async function ui(t,e,n,r){let s=await Yn(t,e,n,r),i=r?.contextLines,a="";for(let o of s)a+=Nn({path:o.oldPath??o.path,oldContent:o.oldContent,newContent:o.newContent,oldHash:o.oldHash,newHash:o.newHash,oldMode:o.oldMode,newMode:o.newMode,isNew:o.status==="added",isDeleted:o.status==="deleted",renameTo:o.status==="renamed"?o.path:void 0,similarity:o.similarity,contextLines:i});return a}async function*hi(t,e,n){if(n?.paths&&n.paths.length>0){let r=n?.limit,s=0;for await(let i of di(t,e,n.paths,n))if(yield i,r!==void 0&&++s>=r)return;return}for await(let r of fe(t,e,n))yield{hash:r.hash,message:r.commit.message,tree:r.commit.tree,parents:r.commit.parents,author:r.commit.author,committer:r.commit.committer}}function xt(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("/")?n:n+"/"))}async function*di(t,e,n,r){let s=new Set;if(r?.exclude)for await(let l of fe(t,r.exclude))s.add(l.hash);let i=new Set(s),a=new ke,o=async l=>{if(!i.has(l))try{let f=await $(t,l);a.push({hash:l,commit:f})}catch{}},c=Array.isArray(e)?e:[e];for(let l of c)await o(l);for(;a.size>0;){let l=a.pop();if(i.has(l.hash))continue;i.add(l.hash);let{commit:f}=l,u=r?.firstParent?f.parents.slice(0,1):f.parents,d=()=>({hash:l.hash,message:f.message,tree:f.tree,parents:f.parents,author:f.author,committer:f.committer});if(u.length===0){(await ce(t,null,f.tree)).some(g=>xt(g.path,n))&&(yield d());continue}if(u.length===1){let m=u[0];try{let g=await $(t,m);(await ce(t,g.tree,f.tree)).some(b=>xt(b.path,n))&&(yield d())}catch{yield d()}await o(m);continue}let h=[];for(let m of u)try{let g=await $(t,m);(await ce(t,g.tree,f.tree)).some(b=>xt(b.path,n))||h.push(m)}catch{}if(h.length>0)await o(h[0]);else{yield d();for(let m of u)await o(m)}}}function mi(t){let e=Math.abs(t),n=t<=0?"+":"-",r=String(Math.floor(e/60)).padStart(2,"0"),s=String(e%60).padStart(2,"0");return`${n}${r}${s}`}function Fe(t){if("timestamp"in t)return t;let e=t.date??new Date;return{name:t.name,email:t.email,timestamp:Math.floor(e.getTime()/1e3),timezone:mi(e.getTimezoneOffset())}}async function pi(t,e){let n=Fe(e.author),r=e.committer?Fe(e.committer):n,s=Le({type:"commit",tree:e.tree,parents:e.parents,author:n,committer:r,message:e.message}),i=await U(t,"commit",s);return e.branch&&await Zn(t,e.branch,i),i}async function gi(t,e){let n=Fe(e.tagger),r=rn({type:"tag",object:e.target,objectType:e.targetType??"commit",name:e.name,tagger:n,message:e.message}),s=await U(t,"tag",r);return await t.refStore.writeRef(`refs/tags/${e.name}`,{type:"direct",hash:s}),s}async function Xn(t,e){let n=e.branch?`refs/heads/${e.branch}`:null,r=n?await te(t,n):null,s=null;r&&(s=(await $(t,r)).tree);let i=[];for(let[d,h]of Object.entries(e.files))if(h===null)i.push({path:d,hash:null});else{let m=typeof h=="string"?new TextEncoder().encode(h):h,g=await U(t,"blob",m);i.push({path:d,hash:g})}let a;s?a=await Jn(t,s,i):a=await Tt(t,null,Ot(i));let o=Fe(e.author),c=e.committer?Fe(e.committer):o,f=Le({type:"commit",tree:a,parents:r?[r]:[],author:o,committer:c,message:e.message});return{hash:await U(t,"commit",f),parentHash:r}}async function yi(t,e){let{hash:n}=await Xn(t,e);return await Zn(t,e.branch,n),n}async function Zn(t,e,n){let r=`refs/heads/${e}`;await t.refStore.writeRef(r,{type:"direct",hash:n}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:r})}async function bi(t,e){let n=[...e].sort((i,a)=>i.name.localeCompare(a.name)),r=await Promise.all(n.map(async i=>{let a=i.mode;return a||(a=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:a,name:i.name,hash:i.hash}})),s=He({type:"tree",entries:r});return U(t,"tree",s)}async function wi(t,e){return U(t,"blob",new TextEncoder().encode(e))}async function Jn(t,e,n){return Tt(t,e,Ot(n))}function Ot(t){let e=new Map,n=new Map;for(let r of t){let s=r.path.indexOf("/");if(s===-1)e.set(r.path,{hash:r.hash,mode:r.mode??"100644"});else{let i=r.path.slice(0,s),a=r.path.slice(s+1),o=n.get(i);o||(o=[],n.set(i,o)),o.push({...r,path:a})}}return{files:e,dirs:n}}async function qn(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ie(n.content).entries}async function Tt(t,e,n){let r=new Map;if(e)for(let a of await qn(t,e))r.set(a.name,a);for(let[a,{hash:o,mode:c}]of n.files)o===null?r.delete(a):r.set(a,{name:a,hash:o,mode:c});for(let[a,o]of n.dirs){let c=r.get(a),l=c?.mode==="040000"?c.hash:null,f=Ot(o),u=await Tt(t,l,f);(await qn(t,u)).length===0?r.delete(a):r.set(a,{name:a,hash:u,mode:"040000"})}let s=[...r.values()].sort((a,o)=>{let c=a.mode==="040000"?`${a.name}/`:a.name,l=o.mode==="040000"?`${o.name}/`:o.name;return c<l?-1:c>l?1:0}),i=He({type:"tree",entries:s});return U(t,"tree",i)}function Pt(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=Et(t,e);return Ei(s,n,i,r)}function Ei(t,e,n,r){let s=[],i=0,a=0;for(;i<e||a<r;){for(;i<e&&a<r&&!t[i]&&!n[a];)i++,a++;if(i>=e&&a>=r)break;let o=i,c=a;for(;i<e&&t[i];)i++;for(;a<r&&n[a];)a++;(i>o||a>c)&&s.push({buffer1:[o,i-o],buffer2:[c,a-c]})}return s}function Ii(t,e,n){let r=[];for(let c of Pt(e,t))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of Pt(e,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,l)=>c.oStart-l.oStart);let s=[],i=0;function a(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let o=0;for(;o<r.length;){let c=r[o++],l=c.oStart,f=c.oStart+c.oLength,u=[c];for(a(l);o<r.length;){let d=r[o];if(d.oStart>f)break;f=Math.max(f,d.oStart+d.oLength),u.push(d),o++}if(u.length===1){if(c.abLength>0){let d=c.ab==="a"?t:n;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:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let b of u){let x=b.oStart,v=x+b.oLength,C=b.abStart,T=C+b.abLength,w=d[b.ab];w.abMin=Math.min(C,w.abMin),w.abMax=Math.max(T,w.abMax),w.oMin=Math.min(x,w.oMin),w.oMax=Math.max(v,w.oMax)}let h=d.a.abMin+(l-d.a.oMin),m=d.a.abMax+(f-d.a.oMax),g=d.b.abMin+(l-d.b.oMin),p=d.b.abMax+(f-d.b.oMax);s.push({stable:!1,a:t.slice(h,m),o:e.slice(l,f),b:n.slice(g,p)})}i=f}return a(e.length),s}function Ri(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=Ii(t,e,n),a=[],o=[];function c(){o.length&&(a.push({type:"ok",lines:o}),o=[])}for(let l of i)l.stable?o.push(...l.content):s&&er(l.a,l.b)?o.push(...l.a):(c(),a.push({type:"conflict",a:l.a,o:l.o,b:l.b}));return c(),r?.conflictStyle==="diff3"?Qn(a):Qn(xi(a))}function _e(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",a=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,o=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),l=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,f=Ri(t,e,n,{conflictStyle:i}),u=!1,d=[];for(let h of f)h.type==="ok"?d.push(...h.lines):(u=!0,i==="diff3"?d.push(a,...h.a,o,...h.o,c,...h.b,l):d.push(a,...h.a,c,...h.b,l));return{conflict:u,result:d}}function xi(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...Oi(n));return e}function Oi(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(er(e,n))return[t];let r=Pt(e,n);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let o of r){let c=o.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let f=c+o.buffer1[1],u=o.buffer2[0]+o.buffer2[1];s.push({type:"conflict",a:e.slice(c,f),o:[],b:n.slice(o.buffer2[0],u)}),i=f}return e.length-i>0&&s.push({type:"ok",lines:e.slice(i)}),s.length===1&&s[0].type==="conflict"?[t]:s}function Qn(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.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 a=e[r+1],o=s;o.a=[...s.a,...i.lines,...a.a],o.b=[...s.b,...i.lines,...a.b],o.o=[...s.o,...i.lines,...a.o],r++}else n.push(i)}return n}function be(t,e,n,r){let s=_e(q(t),q(e),q(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),a=(s.result[s.result.length-1]??"").endsWith("\0"),o=s.result.map(kt);return(o[o.length-1]??"").startsWith(">>>>>>>")||!a?`${o.join(`
|
|
21
|
+
`}function ke(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function Ys(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=ke(e),r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i&&ke(i.path)===n){r=s;break}}return t.splice(r,1)[0]}var qs=50;async function we(t,e,n=qs){let r=new Map,s=[],i=[],a=[];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):a.push(l);let o=[],c=[];for(let l of i){let u=l.newHash;if(!u){c.push(l);continue}let m=r.get(u);if(m&&m.length>0){let h=Ys(m,l.path);h&&o.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 Xs(t,f,c,n);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),m=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!m.has(h.path)),o.push(...l)}}if(f.length>0&&c.length>0){let l=await Qs(t,f,c,n);if(l.length>0){let u=new Set(l.map(h=>h.oldPath)),m=new Set(l.map(h=>h.newPath));f=f.filter(h=>!u.has(h.path)),c=c.filter(h=>!m.has(h.path)),o.push(...l)}}return{remaining:[...a,...f,...c],renames:o}}async function Xs(t,e,n,r){let s=new Map;for(let o=0;o<e.length;o++){let c=e[o];if(!c)continue;let f=ke(c.path);s.has(f)?s.set(f,-1):s.set(f,o)}let i=new Map;for(let o=0;o<n.length;o++){let c=n[o];if(!c)continue;let f=ke(c.path);i.has(f)?i.set(f,-1):i.set(f,o)}let a=[];for(let[o,c]of s){if(c===-1)continue;let f=i.get(o);if(f===void 0||f===-1)continue;let l=e[c],u=n[f];if(!l?.oldHash||!u?.newHash||l.oldHash===u.newHash)continue;let m=await oe(t,l.oldHash),h=await oe(t,u.newHash),d=Js(m,h);d<r||a.push({oldPath:l.path,newPath:u.path,oldHash:l.oldHash,newHash:u.newHash,similarity:d,oldMode:l.oldMode,newMode:u.newMode})}return a}var zn=107927;function tt(t){let e=new Map,n=0,r=0,s=0;for(let a=0;a<t.length;a++){let o=t[a],c=r;if(r=(r<<7^s>>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+o>>>0,n++,n<64&&o!==10)continue;let f=(r+Math.imul(s,97))%zn;e.set(f,(e.get(f)??0)+n),n=0,r=0,s=0}if(n>0){let a=(r+Math.imul(s,97))%zn;e.set(a,(e.get(a)??0)+n)}let i=[];for(let[a,o]of e)i.push({hash:a,count:o});return i.sort((a,o)=>a.hash-o.hash),i}function Zs(t,e){let n=0,r=0,s=0,i=0;for(;s<t.length;){let a=t[s];if(!a)break;for(;i<e.length;){let f=e[i];if(!f||f.hash>=a.hash)break;r+=f.count,i++}let o=a.count,c=0;if(i<e.length){let f=e[i];f&&f.hash===a.hash&&(c=f.count,i++)}o<c?(r+=c-o,n+=o):n+=c,s++}for(;i<e.length;){let a=e[i];a&&(r+=a.count),i++}return{srcCopied:n,literalAdded:r}}function Js(t,e){return t.length===0&&e.length===0?100:t.length===0||e.length===0?0:Vn(t.length,tt(t),e.length,tt(e))}function Vn(t,e,n,r){let s=Math.max(t,n),i=Math.min(t,n);if(i<s-i)return 0;let{srcCopied:a}=Zs(e,r);return Math.floor(a*100/s)}async function Qs(t,e,n,r){let s=[];for(let l of e)if(l.oldHash){let u=await oe(t,l.oldHash);s.push({size:u.length,chunks:tt(u)})}else s.push(null);let i=[];for(let l of n)if(l.newHash){let u=await oe(t,l.newHash);i.push({size:u.length,chunks:tt(u)})}else i.push(null);let a=[];for(let l=0;l<e.length;l++){let u=e[l],m=s[l];if(!(!u||!m))for(let h=0;h<n.length;h++){let d=n[h],g=i[h];if(!d||!g)continue;let p=Vn(m.size,m.chunks,g.size,g.chunks);if(p>=r){let b=ke(u.path)===ke(d.path)?1:0;a.push({similarity:p,nameScore:b,delIdx:l,addIdx:h})}}}a.sort((l,u)=>u.similarity-l.similarity||u.nameScore-l.nameScore);let o=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:u,addIdx:m}of a){if(o.has(u)||c.has(m))continue;o.add(u),c.add(m);let h=e[u],d=n[m];!h||!d||f.push({oldPath:h.path,newPath:d.path,oldHash:h.oldHash??"",newHash:d.newHash??"",similarity:l,oldMode:h.oldMode,newMode:d.newMode})}return f}async function he(t,e,n){return(await xe(t,e)).get(n)?.hash??null}async function Kn(t,e,n,r){let s=await ce(t,e,n);if(!s.find(c=>c.status==="added"&&c.path===r))return null;let{renames:a}=await we(t,s);return a.find(c=>c.newPath===r)?.oldPath??null}async function ei(t,e,n,r,s,i){let a=await he(t,(await v(t,e)).tree,n);if(!a){let g=new Map,p=await v(t,e);for(let b of r)g.set(b.finalIdx,me(e,n,b.currentLine,i+b.finalIdx,s[b.finalIdx],p,!1,void 0));return g}let o=await B(t,a),c=J(o),f=new Array(s.length),l=[...r],u=e,m=n,h=c;for(;l.length>0;){let g=await v(t,u);if(g.parents.length===0){for(let E of l)f[E.finalIdx]=me(u,m,E.currentLine,i+E.finalIdx,s[E.finalIdx],g,!0,void 0);break}let p=await he(t,g.tree,m),b=null,x=[];for(let E of g.parents){let C=await v(t,E),O=m,$=await he(t,C.tree,O);if(!$){let D=await Kn(t,C.tree,g.tree,m);D&&(O=D,$=await he(t,C.tree,O))}if($&&(x.push({hash:E,path:O,blobHash:$}),$===p)){b={hash:E,path:O};break}}if(b){u=b.hash,m=b.path;continue}if(x.length===0){for(let E of l)f[E.finalIdx]=me(u,m,E.currentLine,i+E.finalIdx,s[E.finalIdx],g,!1,void 0);break}let j=x[0],S=await B(t,j.blobHash),P=J(S),w=be(P,h),R=new Map;for(let E of w)E.type==="keep"&&R.set(E.newLineNo,E.oldLineNo);let k=[];for(let E of l){let C=R.get(E.currentLine);C!==void 0?k.push({finalIdx:E.finalIdx,currentLine:C}):f[E.finalIdx]=me(u,m,E.currentLine,i+E.finalIdx,s[E.finalIdx],g,!1,{hash:j.hash,path:j.path})}l=k,u=j.hash,m=j.path,h=P}let d=new Map;for(let g of r)f[g.finalIdx]&&d.set(g.finalIdx,f[g.finalIdx]);return d}async function Yn(t,e,n,r){let s=await v(t,e),i=await he(t,s.tree,n);if(!i)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let a=await B(t,i),o=J(a),c=r?.startLine??1,f=r?.endLine??o.length,l=o.slice(c-1,f),u=new Array(l.length),m=l.map((p,b)=>({finalIdx:b,currentLine:c+b})),h=e,d=n,g=o;for(;m.length>0;){let p=await v(t,h);if(p.parents.length===0){for(let R of m)u[R.finalIdx]=me(h,d,R.currentLine,c+R.finalIdx,l[R.finalIdx],p,!0,void 0);break}let b=await he(t,p.tree,d),x=[],j=null;for(let R of p.parents){let k=await v(t,R),E=d,C=await he(t,k.tree,E);if(!C){let O=await Kn(t,k.tree,p.tree,d);O&&(E=O,C=await he(t,k.tree,E))}if(C){let O={hash:R,path:E,blobHash:C};if(x.push(O),C===b){j=O;break}}}if(j){h=j.hash,d=j.path;continue}if(x.length===0){for(let R of m)u[R.finalIdx]=me(h,d,R.currentLine,c+R.finalIdx,l[R.finalIdx],p,!1,void 0);break}if(x.length===1){let R=x[0],k=await B(t,R.blobHash),E=J(k),C=be(E,g),O=new Map;for(let D of C)D.type==="keep"&&O.set(D.newLineNo,D.oldLineNo);let $=[];for(let D of m){let re=O.get(D.currentLine);re!==void 0?$.push({finalIdx:D.finalIdx,currentLine:re}):u[D.finalIdx]=me(h,d,D.currentLine,c+D.finalIdx,l[D.finalIdx],p,!1,{hash:R.hash,path:R.path})}m=$,h=R.hash,d=R.path,g=E;continue}let S=[];for(let R of x){let k=await B(t,R.blobHash),E=J(k),C=be(E,g),O=new Map;for(let $ of C)$.type==="keep"&&O.set($.newLineNo,$.oldLineNo);S.push({info:R,newToOld:O})}let P=new Map;for(let R of m){let k=!1;for(let E=0;E<S.length;E++){let C=S[E],O=C.newToOld.get(R.currentLine);if(O!==void 0){let $=P.get(E);$||($={info:C.info,lines:[]},P.set(E,$)),$.lines.push({finalIdx:R.finalIdx,currentLine:O}),k=!0;break}}k||(u[R.finalIdx]=me(h,d,R.currentLine,c+R.finalIdx,l[R.finalIdx],p,!1,{hash:x[0].hash,path:x[0].path}))}let w=P.get(0);for(let[R,k]of P){if(R===0)continue;let E=await ei(t,k.info.hash,k.info.path,k.lines,l,c);for(let[C,O]of E)u[C]=O}if(w&&w.lines.length>0){m=w.lines,h=w.info.hash,d=w.info.path;let R=await B(t,w.info.blobHash);g=J(R)}else break}return u}function me(t,e,n,r,s,i,a,o){return{hash:t,origPath:e,origLine:n,finalLine:r,content:s,author:i.author,committer:i.committer,summary:i.message.split(`
|
|
22
|
+
`)[0],boundary:a,previous:o}}var Ce=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 n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&e.epoch<n.epoch}siftUp(e){let{heap:n}=this;for(;e>0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let s=e,i=2*e+1,a=2*e+2;if(i<r&&this.higher(n[i],n[s])&&(s=i),a<r&&this.higher(n[a],n[s])&&(s=a),s===e)break;[n[e],n[s]]=[n[s],n[e]],e=s}}};async function*le(t,e,n){if(n?.topoOrder){yield*ti(t,e,n);return}let r=await Xn(t,n?.exclude),s=new Set(r),i=new Ce,a=n?.shallowBoundary,o=n?.limit,c=0,f=Array.isArray(e)?e:[e];for(let l of f)s.has(l)||i.push(await nt(t,l));for(;i.size>0;){let l=i.pop();if(s.has(l.hash))continue;if(s.add(l.hash),yield l,o!==void 0&&++c>=o)return;if(a?.has(l.hash))continue;let u=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let m of u)if(!s.has(m))try{i.push(await nt(t,m))}catch{}}}async function*ti(t,e,n){let r=await Xn(t,n?.exclude),s=new Set(r),i=new Ce,a=n?.shallowBoundary,o=Array.isArray(e)?e:[e];for(let h of o)s.has(h)||i.push(await nt(t,h));let c=[],f=new Map;for(;i.size>0;){let h=i.pop();if(s.has(h.hash)||(s.add(h.hash),f.set(h.hash,c.length),c.push(h),a?.has(h.hash)))continue;let d=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of d)if(!s.has(g))try{i.push(await nt(t,g))}catch{}}let l=c.length;if(l===0)return;let u=new Int32Array(l);for(let h of c){let d=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of d){let p=f.get(g);p!==void 0&&(u[p]=(u[p]??0)+1)}}let m=[];for(let h=l-1;h>=0;h--)u[h]===0&&m.push(h);for(;m.length>0;){let h=m.pop();yield c[h];let d=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let g of d){let p=f.get(g);if(p!==void 0){let b=(u[p]??0)-1;u[p]=b,b===0&&m.push(p)}}}}async function qn(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let o of le(t,e))r.add(o.hash);let s=new Set;for await(let o of le(t,n))s.add(o.hash);let i=0;for(let o of r)s.has(o)||i++;let a=0;for(let o of s)r.has(o)||a++;return{ahead:i,behind:a}}async function Xn(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of le(t,e))n.add(r.hash);return n}async function nt(t,e){return{hash:e,commit:await v(t,e)}}async function ni(t,e){let n=new Set,r=[e],s=0;for(;s<r.length;){let i=r[s++];if(n.has(i))continue;n.add(i);let a;try{a=await v(t,i)}catch{continue}for(let o of a.parents)n.has(o)||r.push(o)}return n}async function xt(t,e,n){if(e===n)return!0;let r=new Set,s=[n],i=0;for(;i<s.length;){let a=s[i++];if(a===e)return!0;if(r.has(a))continue;r.add(a);let o;try{o=await v(t,a)}catch{continue}for(let c of o.parents)r.has(c)||s.push(c)}return!1}async function Fe(t,e,n){if(e===n)return[e];let r=await ni(t,e),s=[],i=new Set,a=[n],o=0;for(;o<a.length;){let f=a[o++];if(i.has(f))continue;if(i.add(f),r.has(f)){s.push(f);continue}let l;try{l=await v(t,f)}catch{continue}for(let u of l.parents)i.has(u)||a.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 xt(t,f,u)){l=!0;break}l||c.push(f)}return c.length<=1?c:ri(t,e,n,c)}async function ri(t,e,n,r){let s=new Set(r),i=new Set,a=[],o=new Map,c=new Map,f=0,l=[{hash:e,mask:1,seq:f++},{hash:n,mask:2,seq:f++}];async function u(m){let h=c.get(m);if(h!==void 0)return h;let d=(await v(t,m)).committer.timestamp;return c.set(m,d),d}for(;l.length>0;){let m=0,h=await u(l[0].hash);for(let x=1;x<l.length;x++){let j=l[x],S=await u(j.hash),P=l[m];(S>h||S===h&&j.seq<P.seq)&&(m=x,h=S)}let d=l.splice(m,1)[0],g=o.get(d.hash)??0,p=g|d.mask;if(p===g)continue;if(o.set(d.hash,p),p===3&&s.has(d.hash)&&!i.has(d.hash)&&(a.push(d.hash),i.add(d.hash),i.size===s.size))break;let b=await v(t,d.hash);for(let x of b.parents)l.push({hash:x,mask:p,seq:f++})}for(let m of r)i.has(m)||a.push(m);return a}async function si(t,e){return z(t,e)}async function ii(t,e,n){return ce(t,e,n)}async function oi(t,e,n){let r=await v(t,n),s=null;return e&&(s=(await v(t,e)).tree),ce(t,s,r.tree)}async function*ai(t,e,n){let r=e?[e]:[];for await(let s of le(t,n,{exclude:r}))yield{hash:s.hash,message:s.commit.message,tree:s.commit.tree,parents:s.commit.parents,author:s.commit.author,committer:s.commit.committer}}async function ci(t,e,n){return xt(t,e,n)}async function li(t,e,n){return Fe(t,e,n)}async function fi(t,e,n){return qn(t,e,n)}async function ui(t,e,n,r){return Yn(t,e,n,r)}function hi(t){return t==="insert"?"+":t==="delete"?"-":" "}function mi(t){return{oldStart:t.oldStart,oldCount:t.oldCount,newStart:t.newStart,newCount:t.newCount,lines:t.lines.map(e=>hi(e.type)+e.content)}}function di(t,e,n){let r=J(t),s=J(e),i=be(r,s);return Et(i,n).map(mi)}async function Zn(t,e){let n=await ye(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function Jn(t,e,n,r){let s=await Zn(t,e),i=await Zn(t,n),a=await v(t,s),o=await v(t,i),c=await ce(t,a.tree,o.tree),f=r?.renames!==!1,l=r?.paths,u=[];if(f){let h=await we(t,c);c=h.remaining,u=h.renames}let m=[];for(let h of c)l&&!l.some(d=>h.path.startsWith(d))||m.push({path:h.path,status:h.status,oldContent:h.oldHash?await B(t,h.oldHash):"",newContent:h.newHash?await B(t,h.newHash):"",oldHash:h.oldHash??void 0,newHash:h.newHash??void 0,oldMode:h.oldMode,newMode:h.newMode});for(let h of u)l&&!l.some(d=>h.newPath.startsWith(d)||h.oldPath.startsWith(d))||m.push({path:h.newPath,oldPath:h.oldPath,status:"renamed",oldContent:await B(t,h.oldHash),newContent:await B(t,h.newHash),oldHash:h.oldHash,newHash:h.newHash,oldMode:h.oldMode,newMode:h.newMode,similarity:h.similarity});return m.sort((h,d)=>h.path.localeCompare(d.path)),m}async function pi(t,e,n,r){let s=await Jn(t,e,n,r),i=r?.contextLines;return s.map(a=>({path:a.path,status:a.status,oldPath:a.oldPath,similarity:a.similarity,hunks:di(a.oldContent,a.newContent,i)}))}async function gi(t,e,n,r){let s=await Jn(t,e,n,r),i=r?.contextLines,a="";for(let o of s)a+=Wn({path:o.oldPath??o.path,oldContent:o.oldContent,newContent:o.newContent,oldHash:o.oldHash,newHash:o.newHash,oldMode:o.oldMode,newMode:o.newMode,isNew:o.status==="added",isDeleted:o.status==="deleted",renameTo:o.status==="renamed"?o.path:void 0,similarity:o.similarity,contextLines:i});return a}async function*yi(t,e,n){if(n?.paths&&n.paths.length>0){let r=n?.limit,s=0;for await(let i of bi(t,e,n.paths,n))if(yield i,r!==void 0&&++s>=r)return;return}for await(let r of le(t,e,n))yield{hash:r.hash,message:r.commit.message,tree:r.commit.tree,parents:r.commit.parents,author:r.commit.author,committer:r.commit.committer}}function Ot(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("/")?n:n+"/"))}async function*bi(t,e,n,r){let s=new Set;if(r?.exclude)for await(let f of le(t,r.exclude))s.add(f.hash);let i=new Set(s),a=new Ce,o=async f=>{if(!i.has(f))try{let l=await v(t,f);a.push({hash:f,commit:l})}catch{}},c=Array.isArray(e)?e:[e];for(let f of c)await o(f);for(;a.size>0;){let f=a.pop();if(i.has(f.hash))continue;i.add(f.hash);let{commit:l}=f,u=r?.firstParent?l.parents.slice(0,1):l.parents,m=()=>({hash:f.hash,message:l.message,tree:l.tree,parents:l.parents,author:l.author,committer:l.committer});if(u.length===0){(await ce(t,null,l.tree)).some(g=>Ot(g.path,n))&&(yield m());continue}if(u.length===1){let d=u[0];try{let g=await v(t,d);(await ce(t,g.tree,l.tree)).some(b=>Ot(b.path,n))&&(yield m())}catch{yield m()}await o(d);continue}let h=[];for(let d of u)try{let g=await v(t,d);(await ce(t,g.tree,l.tree)).some(b=>Ot(b.path,n))||h.push(d)}catch{}if(h.length>0)await o(h[0]);else{yield m();for(let d of u)await o(d)}}}function wi(t){let e=Math.abs(t),n=t<=0?"+":"-",r=String(Math.floor(e/60)).padStart(2,"0"),s=String(e%60).padStart(2,"0");return`${n}${r}${s}`}function _e(t){if("timestamp"in t)return t;let e=t.date??new Date;return{name:t.name,email:t.email,timestamp:Math.floor(e.getTime()/1e3),timezone:wi(e.getTimezoneOffset())}}async function Pt(t,e){let n=_e(e.author),r=e.committer?_e(e.committer):n,s=He({type:"commit",tree:e.tree,parents:e.parents,author:n,committer:r,message:e.message}),i=await N(t,"commit",s);return e.branch&&await tr(t,e.branch,i),i}async function Ri(t,e){let n=_e(e.tagger),r=an({type:"tag",object:e.target,objectType:e.targetType??"commit",name:e.name,tagger:n,message:e.message}),s=await N(t,"tag",r);return await t.refStore.writeRef(`refs/tags/${e.name}`,{type:"direct",hash:s}),s}async function er(t,e){let n=e.branch?`refs/heads/${e.branch}`:null,r=n?await te(t,n):null,s=null;r&&(s=(await v(t,r)).tree);let i=[];for(let[m,h]of Object.entries(e.files))if(h===null)i.push({path:m,hash:null});else{let d=typeof h=="string"?new TextEncoder().encode(h):h,g=await N(t,"blob",d);i.push({path:m,hash:g})}let a;s?a=await nr(t,s,i):a=await kt(t,null,Tt(i));let o=_e(e.author),c=e.committer?_e(e.committer):o,l=He({type:"commit",tree:a,parents:r?[r]:[],author:o,committer:c,message:e.message});return{hash:await N(t,"commit",l),parentHash:r}}async function Ii(t,e){let{hash:n}=await er(t,e);return await tr(t,e.branch,n),n}async function tr(t,e,n){let r=`refs/heads/${e}`;await t.refStore.writeRef(r,{type:"direct",hash:n}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:r})}async function Ei(t,e){let n=[...e].sort((i,a)=>i.name.localeCompare(a.name)),r=await Promise.all(n.map(async i=>{let a=i.mode;return a||(a=(await t.objectStore.read(i.hash)).type==="tree"?"040000":"100644"),{mode:a,name:i.name,hash:i.hash}})),s=ge({type:"tree",entries:r});return N(t,"tree",s)}async function xi(t,e){return N(t,"blob",new TextEncoder().encode(e))}async function nr(t,e,n){return kt(t,e,Tt(n))}function Tt(t){let e=new Map,n=new Map;for(let r of t){let s=r.path.indexOf("/");if(s===-1)e.set(r.path,{hash:r.hash,mode:r.mode??"100644"});else{let i=r.path.slice(0,s),a=r.path.slice(s+1),o=n.get(i);o||(o=[],n.set(i,o)),o.push({...r,path:a})}}return{files:e,dirs:n}}async function Qn(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ie(n.content).entries}async function kt(t,e,n){let r=new Map;if(e)for(let a of await Qn(t,e))r.set(a.name,a);for(let[a,{hash:o,mode:c}]of n.files)o===null?r.delete(a):r.set(a,{name:a,hash:o,mode:c});for(let[a,o]of n.dirs){let c=r.get(a),f=c?.mode==="040000"?c.hash:null,l=Tt(o),u=await kt(t,f,l);(await Qn(t,u)).length===0?r.delete(a):r.set(a,{name:a,hash:u,mode:"040000"})}let s=[...r.values()].sort((a,o)=>{let c=a.mode==="040000"?`${a.name}/`:a.name,f=o.mode==="040000"?`${o.name}/`:o.name;return c<f?-1:c>f?1:0}),i=ge({type:"tree",entries:s});return N(t,"tree",i)}function Ct(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:s,changedNew:i}=It(t,e);return Oi(s,n,i,r)}function Oi(t,e,n,r){let s=[],i=0,a=0;for(;i<e||a<r;){for(;i<e&&a<r&&!t[i]&&!n[a];)i++,a++;if(i>=e&&a>=r)break;let o=i,c=a;for(;i<e&&t[i];)i++;for(;a<r&&n[a];)a++;(i>o||a>c)&&s.push({buffer1:[o,i-o],buffer2:[c,a-c]})}return s}function Pi(t,e,n){let r=[];for(let c of Ct(e,t))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of Ct(e,n))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 a(c){c>i&&(s.push({stable:!0,buffer:"o",bufferStart:i,bufferLength:c-i,content:e.slice(i,c)}),i=c)}let o=0;for(;o<r.length;){let c=r[o++],f=c.oStart,l=c.oStart+c.oLength,u=[c];for(a(f);o<r.length;){let m=r[o];if(m.oStart>l)break;l=Math.max(l,m.oStart+m.oLength),u.push(m),o++}if(u.length===1){if(c.abLength>0){let m=c.ab==="a"?t:n;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:m.slice(c.abStart,c.abStart+c.abLength)})}}else{let m={a:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let b of u){let x=b.oStart,j=x+b.oLength,S=b.abStart,P=S+b.abLength,w=m[b.ab];w.abMin=Math.min(S,w.abMin),w.abMax=Math.max(P,w.abMax),w.oMin=Math.min(x,w.oMin),w.oMax=Math.max(j,w.oMax)}let h=m.a.abMin+(f-m.a.oMin),d=m.a.abMax+(l-m.a.oMax),g=m.b.abMin+(f-m.b.oMin),p=m.b.abMax+(l-m.b.oMax);s.push({stable:!1,a:t.slice(h,d),o:e.slice(f,l),b:n.slice(g,p)})}i=l}return a(e.length),s}function Ti(t,e,n,r){let s=r?.excludeFalseConflicts??!0,i=Pi(t,e,n),a=[],o=[];function c(){o.length&&(a.push({type:"ok",lines:o}),o=[])}for(let f of i)f.stable?o.push(...f.content):s&&sr(f.a,f.b)?o.push(...f.a):(c(),a.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?rr(a):rr(ki(a))}function We(t,e,n,r){let s=r?.markerSize??7,i=r?.conflictStyle??"merge",a=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,o=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),f=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,l=Ti(t,e,n,{conflictStyle:i}),u=!1,m=[];for(let h of l)h.type==="ok"?m.push(...h.lines):(u=!0,i==="diff3"?m.push(a,...h.a,o,...h.o,c,...h.b,f):m.push(a,...h.a,c,...h.b,f));return{conflict:u,result:m}}function ki(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...Ci(n));return e}function Ci(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(sr(e,n))return[t];let r=Ct(e,n);if(r.length===0)return[{type:"ok",lines:e}];let s=[],i=0;for(let o of r){let c=o.buffer1[0];c-i>0&&s.push({type:"ok",lines:e.slice(i,c)});let l=c+o.buffer1[1],u=o.buffer2[0]+o.buffer2[1];s.push({type:"conflict",a:e.slice(c,l),o:[],b:n.slice(o.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"?[t]:s}function rr(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r<t.length;r++){let s=e[e.length-1],i=t[r];s.type==="ok"&&i.type==="ok"?s.lines=[...s.lines,...i.lines]:e.push(i)}if(e.length<3)return e;let n=[e[0]];for(let r=1;r<e.length;r++){let s=n[n.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 a=e[r+1],o=s;o.a=[...s.a,...i.lines,...a.a],o.b=[...s.b,...i.lines,...a.b],o.o=[...s.o,...i.lines,...a.o],r++}else n.push(i)}return n}function Re(t,e,n,r){let s=We(q(t),q(e),q(n),{a:r.a,o:r.o,b:r.b,markerSize:r.markerSize,conflictStyle:r.conflictStyle}),a=(s.result[s.result.length-1]??"").endsWith("\0"),o=s.result.map(St);return(o[o.length-1]??"").startsWith(">>>>>>>")||!a?`${o.join(`
|
|
23
23
|
`)}
|
|
24
24
|
`:o.join(`
|
|
25
25
|
`)}function q(t){if(t==="")return[];let e=t.split(`
|
|
26
|
-
`);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function kt(t){return t.endsWith("\0")?t.slice(0,-1):t}function er(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}var Se=new TextDecoder,ne=new TextEncoder,tr={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function Ce(t,e,n,r,s,i){let{paths:a,baseMap:o,oursMap:c,theirsMap:l}=await Ti(t,e,n,r),f=await ki(t,a,o,c,l,s,i);return Si(t,a,s,f,i)}async function cr(t,e,n,r,s){let i=await Ge(t,e,n),a=await $(t,e),o=await $(t,n);if(i.length===0)return{...await Ce(t,null,a.tree,o.tree,r,s),baseTree:null};if(i.length===1){let f=await $(t,i[0]);return{...await Ce(t,f.tree,a.tree,o.tree,r,s),baseTree:f.tree}}let c=await lr(t,e,n,i,1,s);return{...await Ce(t,c,a.tree,o.tree,r,s),baseTree:c}}async function Ti(t,e,n,r){let s=await Re(t,e),i=await Re(t,n),a=await Re(t,r),o=new Set;for(let l of s.keys())o.add(l);for(let l of i.keys())o.add(l);for(let l of a.keys())o.add(l);let c=new Map;for(let l of o){let f=s.get(l)??null,u=i.get(l)??null,d=a.get(l)??null,h=f?{hash:f.hash,mode:f.mode}:null,m=u?{hash:u.hash,mode:u.mode}:null,g=d?{hash:d.hash,mode:d.mode}:null,p=(f?1:0)|(u?2:0)|(d?4:0),b=f?.hash??null,x=u?.hash??null,v=d?.hash??null,C=0;b!==null&&b===x&&(C|=3),b!==null&&b===v&&(C|=5),x!==null&&x===v&&(C|=6);let T={path:l,stages:[h,m,g],pathnames:[l,l,l],filemask:p,matchMask:C,merged:{result:null,clean:!1},pathConflict:!1};if(Pi(T)){c.set(l,T);continue}c.set(l,T)}return{paths:c,baseMap:s,oursMap:i,theirsMap:a}}function Pi(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,a=r?.hash??null;return i===s&&a===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===a&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&a===null?(t.merged={result:null,clean:!0},!0):a===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&a!==s?(r?t.merged={result:{hash:a,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function ki(t,e,n,r,s,i,a){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},c=[],l=[];for(let[I,y]of n)r.has(I)||c.push({path:I,status:"deleted",oldHash:y.hash,oldMode:y.mode}),s.has(I)||l.push({path:I,status:"deleted",oldHash:y.hash,oldMode:y.mode});for(let[I,y]of r)n.has(I)||c.push({path:I,status:"added",newHash:y.hash,newMode:y.mode});for(let[I,y]of s)n.has(I)||l.push({path:I,status:"added",newHash:y.hash,newMode:y.mode});let f=await ye(t,c),u=await ye(t,l);if(f.renames.length===0&&u.renames.length===0)return o;let d=new Map,h=new Map;for(let I of f.renames)d.set(I.oldPath,I);for(let I of u.renames)h.set(I.oldPath,I);let m=new Set;for(let[I]of r)!n.has(I)&&s.has(I)&&m.add(I);let g=new Set,p=i?.a??"HEAD",b=i?.b??"theirs";function x(I,y,P=0){o.msgBuf.push({sortKey:I,subOrder:P,text:y})}for(let I of[...n.keys()].sort()){let y=d.get(I),P=h.get(I);if(!y&&!P)continue;let L=n.get(I);if(g.add(I),y&&P)if(g.add(y.newPath),g.add(P.newPath),y.newPath===P.newPath){let M=r.get(y.newPath),A=s.get(P.newPath);if(M.hash===A.hash)o.entries.push(Y(y.newPath,M));else{let G=St(e,y.newPath);G.stages=[{hash:L.hash,mode:L.mode},{hash:M.hash,mode:M.mode},{hash:A.hash,mode:A.mode}],G.pathnames=[I,y.newPath,P.newPath],G.filemask=7,G.merged={result:null,clean:!1}}}else{let M=r.get(y.newPath),A=s.get(P.newPath),G=await fr(t,L,M,A,i,void 0,void 0,a);G.conflict&&x(I,`Auto-merging ${I}`,-1),o.conflicts.push({path:I,reason:"rename-rename",oursPath:y.newPath,theirsPath:P.newPath}),x(I,`CONFLICT (rename/rename): ${I} renamed to ${y.newPath} in ${p} and to ${P.newPath} in ${b}.`),o.entries.push(Y(I,L,1)),o.entries.push(W(y.newPath,M.mode,G.hash,2)),o.entries.push(W(P.newPath,A.mode,G.hash,3)),o.worktreeBlobs.set(y.newPath,{hash:G.hash,mode:M.mode}),o.worktreeBlobs.set(P.newPath,{hash:G.hash,mode:A.mode})}else if(y){g.add(y.newPath);let M=s.get(I),A=r.get(y.newPath),G=m.has(y.newPath);if(M)if(G)await ar(t,o,y.newPath,I,L,A,M,r,s,!1,i,a);else if(M.hash===L.hash&&A.hash===L.hash)o.entries.push(Y(y.newPath,A));else if(M.hash===L.hash)o.entries.push(Y(y.newPath,A));else if(A.hash===L.hash)o.entries.push(W(y.newPath,A.mode,M.hash));else{let _=St(e,y.newPath);_.stages=[{hash:L.hash,mode:L.mode},{hash:A.hash,mode:A.mode},{hash:M.hash,mode:M.mode}],_.pathnames=[I,y.newPath,I],_.filemask=7,_.merged={result:null,clean:!1}}else{let _=s.get(y.newPath);if(o.conflicts.push({path:y.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:I}),x(y.newPath,`CONFLICT (rename/delete): ${I} renamed to ${y.newPath} in ${p}, but deleted in ${b}.`),_){o.conflicts.push({path:y.newPath,reason:"add-add"}),x(y.newPath,`Auto-merging ${y.newPath}`,0),x(y.newPath,`CONFLICT (add/add): Merge conflict in ${y.newPath}`,1),o.entries.push(Y(y.newPath,A,2)),o.entries.push(Y(y.newPath,_,3));let rt=await nt(t,A.hash,_.hash,A.mode,i);o.worktreeBlobs.set(y.newPath,{hash:rt,mode:A.mode})}else o.entries.push(W(y.newPath,L.mode,L.hash,1)),o.entries.push(Y(y.newPath,A,2)),o.worktreeBlobs.set(y.newPath,{hash:A.hash,mode:A.mode}),A.hash!==L.hash&&x(y.newPath,`CONFLICT (modify/delete): ${y.newPath} deleted in ${b} and modified in ${p}. Version ${p} of ${y.newPath} left in tree.`,1)}}else if(P){g.add(P.newPath);let M=r.get(I),A=s.get(P.newPath),G=m.has(P.newPath);if(M)if(G)await ar(t,o,P.newPath,I,L,M,A,r,s,!0,i,a);else if(M.hash===L.hash&&A.hash===L.hash)o.entries.push(Y(P.newPath,A));else if(M.hash===L.hash)o.entries.push(Y(P.newPath,A));else if(A.hash===L.hash)o.entries.push(W(P.newPath,A.mode,M.hash));else{let _=St(e,P.newPath);_.stages=[{hash:L.hash,mode:L.mode},{hash:M.hash,mode:M.mode},{hash:A.hash,mode:A.mode}],_.pathnames=[I,I,P.newPath],_.filemask=7,_.merged={result:null,clean:!1}}else{let _=r.get(P.newPath);if(o.conflicts.push({path:P.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:I}),x(P.newPath,`CONFLICT (rename/delete): ${I} renamed to ${P.newPath} in ${b}, but deleted in ${p}.`),_){o.conflicts.push({path:P.newPath,reason:"add-add"}),x(P.newPath,`Auto-merging ${P.newPath}`,0),x(P.newPath,`CONFLICT (add/add): Merge conflict in ${P.newPath}`,1),o.entries.push(Y(P.newPath,_,2)),o.entries.push(Y(P.newPath,A,3));let rt=await nt(t,_.hash,A.hash,_.mode,i);o.worktreeBlobs.set(P.newPath,{hash:rt,mode:_.mode})}else o.entries.push(W(P.newPath,L.mode,L.hash,1)),o.entries.push(Y(P.newPath,A,3)),o.worktreeBlobs.set(P.newPath,{hash:A.hash,mode:A.mode}),A.hash!==L.hash&&x(P.newPath,`CONFLICT (modify/delete): ${P.newPath} deleted in ${p} and modified in ${b}. Version ${b} of ${P.newPath} left in tree.`,1)}}}let v=new Set(f.renames.map(I=>I.newPath)),C=new Set(u.renames.map(I=>I.newPath)),T=nr(n,r),w=nr(n,s),E=rr(T,s,n),k=rr(w,r,n),R=sr(f.renames,E),S=sr(u.renames,k),O=ir(R),j=ir(S);for(let I of[...O.keys()])j.has(I)&&(O.delete(I),j.delete(I));let D=new Set(O.keys()),re=new Set(j.keys());if(j.size>0)for(let I of c){if(I.status!=="added"||v.has(I.path))continue;let y=or(I.path,j,D);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||s.has(y)){if(r.has(y)){x(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let M=r.get(I.path),A=s.get(y)??n.get(y);o.entries.push(W(y,M.mode,M.hash,2)),A&&o.entries.push(W(y,A.mode,A.hash,3)),o.worktreeBlobs.set(y,{hash:M.hash,mode:M.mode}),o.conflicts.push({path:y,reason:"add-add"}),x(y,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${y}.`,1);let G=e.get(I.path);G&&(G.merged={result:null,clean:!0}),g.add(I.path);continue}let P=r.get(I.path);o.entries.push(W(y,P.mode,P.hash,2)),o.worktreeBlobs.set(y,{hash:P.hash,mode:P.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),x(y,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${y}.`,1);let L=e.get(I.path);L&&(L.merged={result:null,clean:!0}),g.add(I.path)}if(O.size>0)for(let I of l){if(I.status!=="added"||C.has(I.path))continue;let y=or(I.path,O,re);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||s.has(y)){if(s.has(y)){x(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let M=s.get(I.path),A=r.get(y)??n.get(y);A&&o.entries.push(W(y,A.mode,A.hash,2)),o.entries.push(W(y,M.mode,M.hash,3)),o.worktreeBlobs.set(y,{hash:M.hash,mode:M.mode}),o.conflicts.push({path:y,reason:"add-add"}),x(y,`CONFLICT (file location): ${I.path} added in ${b} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${y}.`,1);let G=e.get(I.path);G&&(G.merged={result:null,clean:!0}),g.add(I.path);continue}let P=s.get(I.path);o.entries.push(W(y,P.mode,P.hash,3)),o.worktreeBlobs.set(y,{hash:P.hash,mode:P.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),x(y,`CONFLICT (file location): ${I.path} added in ${b} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${y}.`,1);let L=e.get(I.path);L&&(L.merged={result:null,clean:!0}),g.add(I.path)}let me=new Set(o.entries.map(I=>I.path));for(let I of me){let y=e.get(I);y&&(y.merged={result:null,clean:!0})}for(let I of g){if(me.has(I))continue;let y=e.get(I);if(!y||y.merged.clean)continue;y.filemask===7&&!y.pathConflict||(y.merged={result:null,clean:!0})}return o}function nr(t,e){let n=new Set;for(let i of t.keys()){let a=X(i);for(;a;)n.add(a),a=X(a)}let r=new Set;for(let i of e.keys()){let a=X(i);for(;a;)r.add(a),a=X(a)}let s=new Set;for(let i of n)r.has(i)||s.add(i);return s}function rr(t,e,n){if(t.size===0)return t;let r=new Set;for(let s of e.keys()){if(n.has(s))continue;let i=X(s)??"";t.has(i)&&r.add(i)}for(let s of[...r]){let i=X(s);for(;i;)t.has(i)&&!r.has(i)&&r.add(i),i=X(i)}return r}function sr(t,e){let n=new Map;for(let r of t){let s=X(r.oldPath),i=X(r.newPath),a=!0;for(;;){if(!a){let o=s.length+(s?1:0),c=i.length+(i?1:0),l=r.oldPath.slice(o,r.oldPath.indexOf("/",o)),f=r.newPath.slice(c,r.newPath.indexOf("/",c));if(l!==f)break}if(e.has(s)){let o=n.get(s);o||(o=new Map,n.set(s,o)),o.set(i,(o.get(i)??0)+1)}if(a=!1,!s||!i)break;s=X(s),i=X(i)}}return n}function ir(t){let e=new Map;for(let[n,r]of t){let s=0,i=0,a=null;for(let[o,c]of r)c===s?i=s:c>s&&(s=c,a=o);s>0&&i!==s&&a!==null&&e.set(n,a)}return e}function or(t,e,n){let r=X(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let a=t.slice(r.length+1);return i?`${i}/${a}`:a}r=X(r)}let s=e.get("");return s!==void 0&&!n.has(s)?`${s}/${t}`:null}function X(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function ar(t,e,n,r,s,i,a,o,c,l=!1,f,u){let d=l?o.get(n):c.get(n),h=l?a:i;if(d.hash===h.hash){e.entries.push(W(n,d.mode,d.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let g=await fr(t,s,i,a,f,l?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8,u);if(d.hash===g.hash)e.entries.push(W(n,d.mode,g.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),l){e.entries.push(Y(n,d,2)),e.entries.push(W(n,a.mode,g.hash,3));let p=await nt(t,d.hash,g.hash,d.mode,f);e.worktreeBlobs.set(n,{hash:p,mode:d.mode})}else{e.entries.push(W(n,i.mode,g.hash,2)),e.entries.push(Y(n,d,3));let p=await nt(t,g.hash,d.hash,i.mode,f);e.worktreeBlobs.set(n,{hash:p,mode:i.mode})}}async function fr(t,e,n,r,s,i,a,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(ae(e.mode)||ae(n.mode)||ae(r.mode))return{hash:n.hash,conflict:!0};let c=await B(t,e.hash),l=await B(t,n.hash),f=await B(t,r.hash);if(Z(l)||Z(f)||Z(c))return{hash:n.hash,conflict:!0};if(o){let w=await o({path:e.path??n.path??r.path??"",base:c,ours:l,theirs:f});if(w!==null)return{hash:await U(t,"blob",ne.encode(w.content)),conflict:w.conflict}}let u=q(c),d=q(l),h=q(f),m=s?.conflictStyle,g=_e(d,u,h,{conflictStyle:m});if(!g.conflict)return{hash:await Ct(t,g.result),conflict:!1};let p=s?.a??"HEAD",b=s?.b??"theirs",x=i?.oursPath?`${p}:${i.oursPath}`:p,v=i?.theirsPath?`${b}:${i.theirsPath}`:b,C=be(l,c,f,{a:x,b:v,markerSize:a??7,conflictStyle:m});return{hash:await U(t,"blob",ne.encode(C)),conflict:!0}}async function nt(t,e,n,r,s){let i=await B(t,e),a=await B(t,n),o=be(i,"",a,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return U(t,"blob",ne.encode(o))}function Y(t,e,n=0){return W(t,e.mode,e.hash,n)}function W(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:le()}}async function Si(t,e,n,r,s){let i=[...r.entries],a=[...r.conflicts],o=[...r.msgBuf],c=new Map(r.worktreeBlobs);function l(m,g,p=0){o.push({sortKey:m,subOrder:p,text:g})}for(let m of[...e.keys()].sort()){let g=e.get(m);if(g.merged.clean){g.merged.result?.hash&&i.push(H(m,g.merged.result.hash,g.merged.result.mode));continue}await Ci(t,g,n,i,a,l,c,s)}o.sort((m,g)=>(m.sortKey<g.sortKey?-1:m.sortKey>g.sortKey?1:0)||m.subOrder-g.subOrder);let f=o.map(m=>m.text),u=[],d=new Set;for(let m of i)m.stage===0&&(u.push(m),d.add(m.path));for(let[m,g]of c)d.has(m)||u.push(H(m,g.hash,g.mode));u.sort((m,g)=>Be(m.path,g.path));let h=await gt(t,u);return{entries:i,conflicts:a,messages:f,resultTree:h}}async function Ci(t,e,n,r,s,i,a,o){let c=e.path,[l,f,u]=e.stages,d=l?.hash??null,h=f?.hash??null,m=u?.hash??null;if(h===null&&m!==null&&d!==null){s.push({path:c,reason:"delete-modify",deletedBy:"ours"});let g=n?.a??"HEAD",p=n?.b??"theirs";i(c,`CONFLICT (modify/delete): ${c} deleted in ${g} and modified in ${p}. Version ${p} of ${c} left in tree.`),l&&r.push(H(c,d,l.mode,1)),r.push(H(c,m,u.mode,3)),a.set(c,{hash:m,mode:u.mode});return}if(m===null&&h!==null&&d!==null){s.push({path:c,reason:"delete-modify",deletedBy:"theirs"});let g=n?.b??"theirs",p=n?.a??"HEAD";i(c,`CONFLICT (modify/delete): ${c} deleted in ${g} and modified in ${p}. Version ${p} of ${c} left in tree.`),l&&r.push(H(c,d,l.mode,1)),r.push(H(c,h,f.mode,2)),a.set(c,{hash:h,mode:f.mode});return}if(d===null&&h!==null&&m!==null){if(h===m){r.push(H(c,h,f.mode));return}i(c,`Auto-merging ${c}`,0);let g=await B(t,h),p=await B(t,m);if(Z(g)||Z(p)){s.push({path:c,reason:"add-add"}),i(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(H(c,h,f.mode,2)),r.push(H(c,m,u.mode,3)),a.set(c,{hash:h,mode:f.mode});return}if(o){let E=await o({path:c,base:null,ours:g,theirs:p});if(E!==null){let k=await U(t,"blob",ne.encode(E.content));if(!E.conflict){r.push(H(c,k,f.mode));return}s.push({path:c,reason:"add-add"}),i(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(H(c,h,f.mode,2)),r.push(H(c,m,u.mode,3)),a.set(c,{hash:k,mode:f.mode});return}}let b=q(""),x=q(g),v=q(p),C=_e(x,b,v,{conflictStyle:n?.conflictStyle});if(!C.conflict){let E=await Ct(t,C.result);r.push(H(c,E,f.mode));return}s.push({path:c,reason:"add-add"}),i(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(H(c,h,f.mode,2)),r.push(H(c,m,u.mode,3));let T=be(g,"",p,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),w=await U(t,"blob",ne.encode(T));a.set(c,{hash:w,mode:f.mode});return}if(d!==null&&h!==null&&m!==null){if(h===d){r.push(H(c,m,u.mode));return}if(m===d){r.push(H(c,h,f.mode));return}if(h===m){r.push(H(c,h,f.mode));return}if(i(c,`Auto-merging ${c}`,0),ae(l.mode)||ae(f.mode)||ae(u.mode)){s.push({path:c,reason:"content"}),i(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,d,l.mode,1)),r.push(H(c,h,f.mode,2)),r.push(H(c,m,u.mode,3)),a.set(c,{hash:h,mode:f.mode});return}let g=await B(t,d),p=await B(t,h),b=await B(t,m);if(Z(p)||Z(b)||Z(g)){s.push({path:c,reason:"content"}),i(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,d,l.mode,1)),r.push(H(c,h,f.mode,2)),r.push(H(c,m,u.mode,3)),a.set(c,{hash:h,mode:f.mode});return}if(o){let w=await o({path:c,base:g,ours:p,theirs:b});if(w!==null){let E=await U(t,"blob",ne.encode(w.content));if(!w.conflict){r.push(H(c,E,f.mode));return}let k=e.pathnames[1],R=e.pathnames[2],S=k!==c||R!==c,O={path:c,reason:"content"};S&&(k!==c&&(O.oursOrigPath=k),R!==c&&(O.theirsOrigPath=R)),s.push(O),i(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,d,l.mode,1)),r.push(H(c,h,f.mode,2)),r.push(H(c,m,u.mode,3)),a.set(c,{hash:E,mode:f.mode});return}}let x=q(g),v=q(p),C=q(b),T=_e(v,x,C,{conflictStyle:n?.conflictStyle});if(T.conflict){let w=e.pathnames[1],E=e.pathnames[2],k=w!==c||E!==c,R={path:c,reason:"content"};k&&(w!==c&&(R.oursOrigPath=w),E!==c&&(R.theirsOrigPath=E)),s.push(R),i(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,d,l.mode,1)),r.push(H(c,h,f.mode,2)),r.push(H(c,m,u.mode,3));let S=k?`${n?.a??"HEAD"}:${w}`:n?.a??"HEAD",O=k?`${n?.b??"theirs"}:${E}`:n?.b??"theirs",j=be(p,g,b,{a:S,b:O,conflictStyle:n?.conflictStyle}),D=await U(t,"blob",ne.encode(j));a.set(c,{hash:D,mode:f.mode})}else{let w=await Ct(t,T.result);r.push(H(c,w,f.mode))}return}}var vi=200;async function lr(t,e,n,r,s,i){let a=await Promise.all(r.map(async u=>({hash:u,timestamp:(await $(t,u)).committer.timestamp})));a.sort((u,d)=>u.timestamp-d.timestamp);let o=a.map(u=>u.hash),c=o[0],l=c,f=(await $(t,c)).tree;for(let u=1;u<o.length;u++){let d=o[u],h=(await $(t,d)).tree,m=null;if(s>=vi)m=f;else{let b=await Ge(t,l,d);b.length===0?m=null:b.length===1?m=(await $(t,b[0])).tree:m=await lr(t,l,d,b,s+1,i)}let g=await Ce(t,m,f,h,void 0,i);f=await ji(t,g,s);let p=Le({type:"commit",tree:f,parents:[l,d],author:tr,committer:tr,message:"merged common ancestors"});l=await U(t,"commit",p)}return f}async function ji(t,e,n){let r=e.entries.filter(o=>o.stage===0),s=new Map;for(let o of e.entries)o.stage>0&&s.set(`${o.path}\0${o.stage}`,o);let i=(o,c)=>s.get(`${o}\0${c}`),a={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let o of e.conflicts){if(o.reason==="delete-modify"||o.reason==="rename-delete"){let f=i(o.path,1);if(f){r.push({...f,stage:0});continue}}if(o.reason==="rename-rename"){let f=o.oursPath??o.path,u=o.theirsPath??o.path,d=i(o.path,1),h=i(f,2),m=i(u,3);if(h&&m){let g=Se.decode((await F(t,h.hash)).content),p=Se.decode((await F(t,m.hash)).content),b=d?Se.decode((await F(t,d.hash)).content):"",x=8+n*2,v=a.a??"Temporary merge branch 1",C=a.b??"Temporary merge branch 2",T=be(g,b,p,{a:`${v}:${f}`,o:a.o,b:`${C}:${u}`,markerSize:x}),w=await U(t,"blob",ne.encode(T));r.push({path:f,mode:h.mode,hash:w,stage:0,stat:le()}),r.push({path:u,mode:m.mode,hash:w,stage:0,stat:le()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(o.path,2),l=i(o.path,3);if(c&&l&&(o.reason==="content"||o.reason==="add-add")){let f=Se.decode((await F(t,c.hash)).content),u=Se.decode((await F(t,l.hash)).content),d=o.reason==="content"?i(o.path,1):null,h=d?Se.decode((await F(t,d.hash)).content):"",m=o.oursOrigPath||o.theirsOrigPath,g=a.a??"Temporary merge branch 1",p=a.b??"Temporary merge branch 2",b=m?`${g}:${o.oursOrigPath??o.path}`:g,x=m?`${p}:${o.theirsOrigPath??o.path}`:p,v=be(f,h,u,{a:b,o:a.o,b:x,markerSize:a.markerSize}),C=await U(t,"blob",ne.encode(v));r.push({path:o.path,mode:c.mode,hash:C,stage:0,stat:le()})}else c?r.push({...c,stage:0}):l&&r.push({...l,stage:0})}return r.sort((o,c)=>Be(o.path,c.path)),gt(t,r)}async function Ct(t,e){let n=e.map(kt);if(n.length===0)return U(t,"blob",ne.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?n.join(`
|
|
26
|
+
`);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function St(t){return t.endsWith("\0")?t.slice(0,-1):t}function sr(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}var Se=new TextDecoder,ne=new TextEncoder,ir={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function ve(t,e,n,r,s,i){let{paths:a,baseMap:o,oursMap:c,theirsMap:f}=await Si(t,e,n,r),l=await ji(t,a,o,c,f,s,i);return $i(t,a,s,l,i)}async function hr(t,e,n,r,s){let i=await Fe(t,e,n),a=await v(t,e),o=await v(t,n);if(i.length===0)return{...await ve(t,null,a.tree,o.tree,r,s),baseTree:null};if(i.length===1){let l=await v(t,i[0]);return{...await ve(t,l.tree,a.tree,o.tree,r,s),baseTree:l.tree}}let c=await dr(t,e,n,i,1,s);return{...await ve(t,c,a.tree,o.tree,r,s),baseTree:c}}async function Si(t,e,n,r){let s=await xe(t,e),i=await xe(t,n),a=await xe(t,r),o=new Set;for(let f of s.keys())o.add(f);for(let f of i.keys())o.add(f);for(let f of a.keys())o.add(f);let c=new Map;for(let f of o){let l=s.get(f)??null,u=i.get(f)??null,m=a.get(f)??null,h=l?{hash:l.hash,mode:l.mode}:null,d=u?{hash:u.hash,mode:u.mode}:null,g=m?{hash:m.hash,mode:m.mode}:null,p=(l?1:0)|(u?2:0)|(m?4:0),b=l?.hash??null,x=u?.hash??null,j=m?.hash??null,S=0;b!==null&&b===x&&(S|=3),b!==null&&b===j&&(S|=5),x!==null&&x===j&&(S|=6);let P={path:f,stages:[h,d,g],pathnames:[f,f,f],filemask:p,matchMask:S,merged:{result:null,clean:!1},pathConflict:!1};if(vi(P)){c.set(f,P);continue}c.set(f,P)}return{paths:c,baseMap:s,oursMap:i,theirsMap:a}}function vi(t){let[e,n,r]=t.stages,s=e?.hash??null,i=n?.hash??null,a=r?.hash??null;return i===s&&a===s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===a&&i!==null?(t.merged={result:{hash:i,mode:n.mode},clean:!0},!0):i===null&&a===null?(t.merged={result:null,clean:!0},!0):a===s&&i!==s?(n?t.merged={result:{hash:i,mode:n.mode},clean:!0}:t.merged={result:null,clean:!0},!0):i===s&&a!==s?(r?t.merged={result:{hash:a,mode:r.mode},clean:!0}:t.merged={result:null,clean:!0},!0):!1}async function ji(t,e,n,r,s,i,a){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},c=[],f=[];for(let[I,y]of n)r.has(I)||c.push({path:I,status:"deleted",oldHash:y.hash,oldMode:y.mode}),s.has(I)||f.push({path:I,status:"deleted",oldHash:y.hash,oldMode:y.mode});for(let[I,y]of r)n.has(I)||c.push({path:I,status:"added",newHash:y.hash,newMode:y.mode});for(let[I,y]of s)n.has(I)||f.push({path:I,status:"added",newHash:y.hash,newMode:y.mode});let l=await we(t,c),u=await we(t,f);if(l.renames.length===0&&u.renames.length===0)return o;let m=new Map,h=new Map;for(let I of l.renames)m.set(I.oldPath,I);for(let I of u.renames)h.set(I.oldPath,I);let d=new Set;for(let[I]of r)!n.has(I)&&s.has(I)&&d.add(I);let g=new Set,p=i?.a??"HEAD",b=i?.b??"theirs";function x(I,y,T=0){o.msgBuf.push({sortKey:I,subOrder:T,text:y})}for(let I of[...n.keys()].sort()){let y=m.get(I),T=h.get(I);if(!y&&!T)continue;let L=n.get(I);if(g.add(I),y&&T)if(g.add(y.newPath),g.add(T.newPath),y.newPath===T.newPath){let M=r.get(y.newPath),A=s.get(T.newPath);if(M.hash===A.hash)o.entries.push(Y(y.newPath,M));else{let G=vt(e,y.newPath);G.stages=[{hash:L.hash,mode:L.mode},{hash:M.hash,mode:M.mode},{hash:A.hash,mode:A.mode}],G.pathnames=[I,y.newPath,T.newPath],G.filemask=7,G.merged={result:null,clean:!1}}}else{let M=r.get(y.newPath),A=s.get(T.newPath),G=await mr(t,L,M,A,i,void 0,void 0,a);G.conflict&&x(I,`Auto-merging ${I}`,-1),o.conflicts.push({path:I,reason:"rename-rename",oursPath:y.newPath,theirsPath:T.newPath}),x(I,`CONFLICT (rename/rename): ${I} renamed to ${y.newPath} in ${p} and to ${T.newPath} in ${b}.`),o.entries.push(Y(I,L,1)),o.entries.push(W(y.newPath,M.mode,G.hash,2)),o.entries.push(W(T.newPath,A.mode,G.hash,3)),o.worktreeBlobs.set(y.newPath,{hash:G.hash,mode:M.mode}),o.worktreeBlobs.set(T.newPath,{hash:G.hash,mode:A.mode})}else if(y){g.add(y.newPath);let M=s.get(I),A=r.get(y.newPath),G=d.has(y.newPath);if(M)if(G)await ur(t,o,y.newPath,I,L,A,M,r,s,!1,i,a);else if(M.hash===L.hash&&A.hash===L.hash)o.entries.push(Y(y.newPath,A));else if(M.hash===L.hash)o.entries.push(Y(y.newPath,A));else if(A.hash===L.hash)o.entries.push(W(y.newPath,A.mode,M.hash));else{let _=vt(e,y.newPath);_.stages=[{hash:L.hash,mode:L.mode},{hash:A.hash,mode:A.mode},{hash:M.hash,mode:M.mode}],_.pathnames=[I,y.newPath,I],_.filemask=7,_.merged={result:null,clean:!1}}else{let _=s.get(y.newPath);if(o.conflicts.push({path:y.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:I}),x(y.newPath,`CONFLICT (rename/delete): ${I} renamed to ${y.newPath} in ${p}, but deleted in ${b}.`),_){o.conflicts.push({path:y.newPath,reason:"add-add"}),x(y.newPath,`Auto-merging ${y.newPath}`,0),x(y.newPath,`CONFLICT (add/add): Merge conflict in ${y.newPath}`,1),o.entries.push(Y(y.newPath,A,2)),o.entries.push(Y(y.newPath,_,3));let st=await rt(t,A.hash,_.hash,A.mode,i);o.worktreeBlobs.set(y.newPath,{hash:st,mode:A.mode})}else o.entries.push(W(y.newPath,L.mode,L.hash,1)),o.entries.push(Y(y.newPath,A,2)),o.worktreeBlobs.set(y.newPath,{hash:A.hash,mode:A.mode}),A.hash!==L.hash&&x(y.newPath,`CONFLICT (modify/delete): ${y.newPath} deleted in ${b} and modified in ${p}. Version ${p} of ${y.newPath} left in tree.`,1)}}else if(T){g.add(T.newPath);let M=r.get(I),A=s.get(T.newPath),G=d.has(T.newPath);if(M)if(G)await ur(t,o,T.newPath,I,L,M,A,r,s,!0,i,a);else if(M.hash===L.hash&&A.hash===L.hash)o.entries.push(Y(T.newPath,A));else if(M.hash===L.hash)o.entries.push(Y(T.newPath,A));else if(A.hash===L.hash)o.entries.push(W(T.newPath,A.mode,M.hash));else{let _=vt(e,T.newPath);_.stages=[{hash:L.hash,mode:L.mode},{hash:M.hash,mode:M.mode},{hash:A.hash,mode:A.mode}],_.pathnames=[I,I,T.newPath],_.filemask=7,_.merged={result:null,clean:!1}}else{let _=r.get(T.newPath);if(o.conflicts.push({path:T.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:I}),x(T.newPath,`CONFLICT (rename/delete): ${I} renamed to ${T.newPath} in ${b}, but deleted in ${p}.`),_){o.conflicts.push({path:T.newPath,reason:"add-add"}),x(T.newPath,`Auto-merging ${T.newPath}`,0),x(T.newPath,`CONFLICT (add/add): Merge conflict in ${T.newPath}`,1),o.entries.push(Y(T.newPath,_,2)),o.entries.push(Y(T.newPath,A,3));let st=await rt(t,_.hash,A.hash,_.mode,i);o.worktreeBlobs.set(T.newPath,{hash:st,mode:_.mode})}else o.entries.push(W(T.newPath,L.mode,L.hash,1)),o.entries.push(Y(T.newPath,A,3)),o.worktreeBlobs.set(T.newPath,{hash:A.hash,mode:A.mode}),A.hash!==L.hash&&x(T.newPath,`CONFLICT (modify/delete): ${T.newPath} deleted in ${p} and modified in ${b}. Version ${b} of ${T.newPath} left in tree.`,1)}}}let j=new Set(l.renames.map(I=>I.newPath)),S=new Set(u.renames.map(I=>I.newPath)),P=or(n,r),w=or(n,s),R=ar(P,s,n),k=ar(w,r,n),E=cr(l.renames,R),C=cr(u.renames,k),O=lr(E),$=lr(C);for(let I of[...O.keys()])$.has(I)&&(O.delete(I),$.delete(I));let D=new Set(O.keys()),re=new Set($.keys());if($.size>0)for(let I of c){if(I.status!=="added"||j.has(I.path))continue;let y=fr(I.path,$,D);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||s.has(y)){if(r.has(y)){x(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let M=r.get(I.path),A=s.get(y)??n.get(y);o.entries.push(W(y,M.mode,M.hash,2)),A&&o.entries.push(W(y,A.mode,A.hash,3)),o.worktreeBlobs.set(y,{hash:M.hash,mode:M.mode}),o.conflicts.push({path:y,reason:"add-add"}),x(y,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${y}.`,1);let G=e.get(I.path);G&&(G.merged={result:null,clean:!0}),g.add(I.path);continue}let T=r.get(I.path);o.entries.push(W(y,T.mode,T.hash,2)),o.worktreeBlobs.set(y,{hash:T.hash,mode:T.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),x(y,`CONFLICT (file location): ${I.path} added in ${p} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${y}.`,1);let L=e.get(I.path);L&&(L.merged={result:null,clean:!0}),g.add(I.path)}if(O.size>0)for(let I of f){if(I.status!=="added"||S.has(I.path))continue;let y=fr(I.path,O,re);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||s.has(y)){if(s.has(y)){x(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${I.path}.`,1);continue}let M=s.get(I.path),A=r.get(y)??n.get(y);A&&o.entries.push(W(y,A.mode,A.hash,2)),o.entries.push(W(y,M.mode,M.hash,3)),o.worktreeBlobs.set(y,{hash:M.hash,mode:M.mode}),o.conflicts.push({path:y,reason:"add-add"}),x(y,`CONFLICT (file location): ${I.path} added in ${b} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${y}.`,1);let G=e.get(I.path);G&&(G.merged={result:null,clean:!0}),g.add(I.path);continue}let T=s.get(I.path);o.entries.push(W(y,T.mode,T.hash,3)),o.worktreeBlobs.set(y,{hash:T.hash,mode:T.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),x(y,`CONFLICT (file location): ${I.path} added in ${b} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${y}.`,1);let L=e.get(I.path);L&&(L.merged={result:null,clean:!0}),g.add(I.path)}let de=new Set(o.entries.map(I=>I.path));for(let I of de){let y=e.get(I);y&&(y.merged={result:null,clean:!0})}for(let I of g){if(de.has(I))continue;let y=e.get(I);if(!y||y.merged.clean)continue;y.filemask===7&&!y.pathConflict||(y.merged={result:null,clean:!0})}return o}function or(t,e){let n=new Set;for(let i of t.keys()){let a=X(i);for(;a;)n.add(a),a=X(a)}let r=new Set;for(let i of e.keys()){let a=X(i);for(;a;)r.add(a),a=X(a)}let s=new Set;for(let i of n)r.has(i)||s.add(i);return s}function ar(t,e,n){if(t.size===0)return t;let r=new Set;for(let s of e.keys()){if(n.has(s))continue;let i=X(s)??"";t.has(i)&&r.add(i)}for(let s of[...r]){let i=X(s);for(;i;)t.has(i)&&!r.has(i)&&r.add(i),i=X(i)}return r}function cr(t,e){let n=new Map;for(let r of t){let s=X(r.oldPath),i=X(r.newPath),a=!0;for(;;){if(!a){let o=s.length+(s?1:0),c=i.length+(i?1:0),f=r.oldPath.slice(o,r.oldPath.indexOf("/",o)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(e.has(s)){let o=n.get(s);o||(o=new Map,n.set(s,o)),o.set(i,(o.get(i)??0)+1)}if(a=!1,!s||!i)break;s=X(s),i=X(i)}}return n}function lr(t){let e=new Map;for(let[n,r]of t){let s=0,i=0,a=null;for(let[o,c]of r)c===s?i=s:c>s&&(s=c,a=o);s>0&&i!==s&&a!==null&&e.set(n,a)}return e}function fr(t,e,n){let r=X(t);for(;r;){let i=e.get(r);if(i!==void 0){if(n.has(i))return null;let a=t.slice(r.length+1);return i?`${i}/${a}`:a}r=X(r)}let s=e.get("");return s!==void 0&&!n.has(s)?`${s}/${t}`:null}function X(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function ur(t,e,n,r,s,i,a,o,c,f=!1,l,u){let m=f?o.get(n):c.get(n),h=f?a:i;if(m.hash===h.hash){e.entries.push(W(n,m.mode,m.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let g=await mr(t,s,i,a,l,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8,u);if(m.hash===g.hash)e.entries.push(W(n,m.mode,g.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){e.entries.push(Y(n,m,2)),e.entries.push(W(n,a.mode,g.hash,3));let p=await rt(t,m.hash,g.hash,m.mode,l);e.worktreeBlobs.set(n,{hash:p,mode:m.mode})}else{e.entries.push(W(n,i.mode,g.hash,2)),e.entries.push(Y(n,m,3));let p=await rt(t,g.hash,m.hash,i.mode,l);e.worktreeBlobs.set(n,{hash:p,mode:i.mode})}}async function mr(t,e,n,r,s,i,a,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(ae(e.mode)||ae(n.mode)||ae(r.mode))return{hash:n.hash,conflict:!0};let c=await B(t,e.hash),f=await B(t,n.hash),l=await B(t,r.hash);if(Z(f)||Z(l)||Z(c))return{hash:n.hash,conflict:!0};if(o){let w=await o({path:e.path??n.path??r.path??"",base:c,ours:f,theirs:l});if(w!==null)return{hash:await N(t,"blob",ne.encode(w.content)),conflict:w.conflict}}let u=q(c),m=q(f),h=q(l),d=s?.conflictStyle,g=We(m,u,h,{conflictStyle:d});if(!g.conflict)return{hash:await jt(t,g.result),conflict:!1};let p=s?.a??"HEAD",b=s?.b??"theirs",x=i?.oursPath?`${p}:${i.oursPath}`:p,j=i?.theirsPath?`${b}:${i.theirsPath}`:b,S=Re(f,c,l,{a:x,b:j,markerSize:a??7,conflictStyle:d});return{hash:await N(t,"blob",ne.encode(S)),conflict:!0}}async function rt(t,e,n,r,s){let i=await B(t,e),a=await B(t,n),o=Re(i,"",a,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return N(t,"blob",ne.encode(o))}function Y(t,e,n=0){return W(t,e.mode,e.hash,n)}function W(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:fe()}}async function $i(t,e,n,r,s){let i=[...r.entries],a=[...r.conflicts],o=[...r.msgBuf],c=new Map(r.worktreeBlobs);function f(d,g,p=0){o.push({sortKey:d,subOrder:p,text:g})}for(let d of[...e.keys()].sort()){let g=e.get(d);if(g.merged.clean){g.merged.result?.hash&&i.push(H(d,g.merged.result.hash,g.merged.result.mode));continue}await Ai(t,g,n,i,a,f,c,s)}o.sort((d,g)=>(d.sortKey<g.sortKey?-1:d.sortKey>g.sortKey?1:0)||d.subOrder-g.subOrder);let l=o.map(d=>d.text),u=[],m=new Set;for(let d of i)d.stage===0&&(u.push(d),m.add(d.path));for(let[d,g]of c)m.has(d)||u.push(H(d,g.hash,g.mode));u.sort((d,g)=>Ne(d.path,g.path));let h=await yt(t,u);return{entries:i,conflicts:a,messages:l,resultTree:h}}async function Ai(t,e,n,r,s,i,a,o){let c=e.path,[f,l,u]=e.stages,m=f?.hash??null,h=l?.hash??null,d=u?.hash??null;if(h===null&&d!==null&&m!==null){s.push({path:c,reason:"delete-modify",deletedBy:"ours"});let g=n?.a??"HEAD",p=n?.b??"theirs";i(c,`CONFLICT (modify/delete): ${c} deleted in ${g} and modified in ${p}. Version ${p} of ${c} left in tree.`),f&&r.push(H(c,m,f.mode,1)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:d,mode:u.mode});return}if(d===null&&h!==null&&m!==null){s.push({path:c,reason:"delete-modify",deletedBy:"theirs"});let g=n?.b??"theirs",p=n?.a??"HEAD";i(c,`CONFLICT (modify/delete): ${c} deleted in ${g} and modified in ${p}. Version ${p} of ${c} left in tree.`),f&&r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),a.set(c,{hash:h,mode:l.mode});return}if(m===null&&h!==null&&d!==null){if(h===d){r.push(H(c,h,l.mode));return}i(c,`Auto-merging ${c}`,0);let g=await B(t,h),p=await B(t,d);if(Z(g)||Z(p)){s.push({path:c,reason:"add-add"}),i(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:h,mode:l.mode});return}if(o){let R=await o({path:c,base:null,ours:g,theirs:p});if(R!==null){let k=await N(t,"blob",ne.encode(R.content));if(!R.conflict){r.push(H(c,k,l.mode));return}s.push({path:c,reason:"add-add"}),i(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:k,mode:l.mode});return}}let b=q(""),x=q(g),j=q(p),S=We(x,b,j,{conflictStyle:n?.conflictStyle});if(!S.conflict){let R=await jt(t,S.result);r.push(H(c,R,l.mode));return}s.push({path:c,reason:"add-add"}),i(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3));let P=Re(g,"",p,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),w=await N(t,"blob",ne.encode(P));a.set(c,{hash:w,mode:l.mode});return}if(m!==null&&h!==null&&d!==null){if(h===m){r.push(H(c,d,u.mode));return}if(d===m){r.push(H(c,h,l.mode));return}if(h===d){r.push(H(c,h,l.mode));return}if(i(c,`Auto-merging ${c}`,0),ae(f.mode)||ae(l.mode)||ae(u.mode)){s.push({path:c,reason:"content"}),i(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:h,mode:l.mode});return}let g=await B(t,m),p=await B(t,h),b=await B(t,d);if(Z(p)||Z(b)||Z(g)){s.push({path:c,reason:"content"}),i(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),i(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:h,mode:l.mode});return}if(o){let w=await o({path:c,base:g,ours:p,theirs:b});if(w!==null){let R=await N(t,"blob",ne.encode(w.content));if(!w.conflict){r.push(H(c,R,l.mode));return}let k=e.pathnames[1],E=e.pathnames[2],C=k!==c||E!==c,O={path:c,reason:"content"};C&&(k!==c&&(O.oursOrigPath=k),E!==c&&(O.theirsOrigPath=E)),s.push(O),i(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:R,mode:l.mode});return}}let x=q(g),j=q(p),S=q(b),P=We(j,x,S,{conflictStyle:n?.conflictStyle});if(P.conflict){let w=e.pathnames[1],R=e.pathnames[2],k=w!==c||R!==c,E={path:c,reason:"content"};k&&(w!==c&&(E.oursOrigPath=w),R!==c&&(E.theirsOrigPath=R)),s.push(E),i(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3));let C=k?`${n?.a??"HEAD"}:${w}`:n?.a??"HEAD",O=k?`${n?.b??"theirs"}:${R}`:n?.b??"theirs",$=Re(p,g,b,{a:C,b:O,conflictStyle:n?.conflictStyle}),D=await N(t,"blob",ne.encode($));a.set(c,{hash:D,mode:l.mode})}else{let w=await jt(t,P.result);r.push(H(c,w,l.mode))}return}}var Mi=200;async function dr(t,e,n,r,s,i){let a=await Promise.all(r.map(async u=>({hash:u,timestamp:(await v(t,u)).committer.timestamp})));a.sort((u,m)=>u.timestamp-m.timestamp);let o=a.map(u=>u.hash),c=o[0],f=c,l=(await v(t,c)).tree;for(let u=1;u<o.length;u++){let m=o[u],h=(await v(t,m)).tree,d=null;if(s>=Mi)d=l;else{let b=await Fe(t,f,m);b.length===0?d=null:b.length===1?d=(await v(t,b[0])).tree:d=await dr(t,f,m,b,s+1,i)}let g=await ve(t,d,l,h,void 0,i);l=await Li(t,g,s);let p=He({type:"commit",tree:l,parents:[f,m],author:ir,committer:ir,message:"merged common ancestors"});f=await N(t,"commit",p)}return l}async function Li(t,e,n){let r=e.entries.filter(o=>o.stage===0),s=new Map;for(let o of e.entries)o.stage>0&&s.set(`${o.path}\0${o.stage}`,o);let i=(o,c)=>s.get(`${o}\0${c}`),a={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let o of e.conflicts){if(o.reason==="delete-modify"||o.reason==="rename-delete"){let l=i(o.path,1);if(l){r.push({...l,stage:0});continue}}if(o.reason==="rename-rename"){let l=o.oursPath??o.path,u=o.theirsPath??o.path,m=i(o.path,1),h=i(l,2),d=i(u,3);if(h&&d){let g=Se.decode((await F(t,h.hash)).content),p=Se.decode((await F(t,d.hash)).content),b=m?Se.decode((await F(t,m.hash)).content):"",x=8+n*2,j=a.a??"Temporary merge branch 1",S=a.b??"Temporary merge branch 2",P=Re(g,b,p,{a:`${j}:${l}`,o:a.o,b:`${S}:${u}`,markerSize:x}),w=await N(t,"blob",ne.encode(P));r.push({path:l,mode:h.mode,hash:w,stage:0,stat:fe()}),r.push({path:u,mode:d.mode,hash:w,stage:0,stat:fe()});continue}else if(h){r.push({...h,stage:0});continue}}let c=i(o.path,2),f=i(o.path,3);if(c&&f&&(o.reason==="content"||o.reason==="add-add")){let l=Se.decode((await F(t,c.hash)).content),u=Se.decode((await F(t,f.hash)).content),m=o.reason==="content"?i(o.path,1):null,h=m?Se.decode((await F(t,m.hash)).content):"",d=o.oursOrigPath||o.theirsOrigPath,g=a.a??"Temporary merge branch 1",p=a.b??"Temporary merge branch 2",b=d?`${g}:${o.oursOrigPath??o.path}`:g,x=d?`${p}:${o.theirsOrigPath??o.path}`:p,j=Re(l,h,u,{a:b,o:a.o,b:x,markerSize:a.markerSize}),S=await N(t,"blob",ne.encode(j));r.push({path:o.path,mode:c.mode,hash:S,stage:0,stat:fe()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((o,c)=>Ne(o.path,c.path)),yt(t,r)}async function jt(t,e){let n=e.map(St);if(n.length===0)return N(t,"blob",ne.encode(""));let i=(e[e.length-1]??"").endsWith("\0")?n.join(`
|
|
27
27
|
`):`${n.join(`
|
|
28
28
|
`)}
|
|
29
|
-
`;return
|
|
29
|
+
`;return N(t,"blob",ne.encode(i))}function H(t,e,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:s,hash:e,stage:r,stat:fe()}}function vt(t,e){let n=t.get(e);return n||(n={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},t.set(e,n)),n}async function Di(t,e,n,r){let s=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,i=await hr(t,e,n,s,r?.mergeDriver);return{treeHash:i.resultTree,clean:i.conflicts.length===0,conflicts:i.conflicts,messages:i.messages}}async function $t(t,e,n,r,s){let i=s?{a:s.ours??"ours",b:s.theirs??"theirs"}:void 0,a=await ve(t,e,n,r,i,s?.mergeDriver);return{treeHash:a.resultTree,clean:a.conflicts.length===0,conflicts:a.conflicts,messages:a.messages}}var At=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,n){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")}ingestPackStream(e){throw new Error("cannot ingest pack: object store is read-only")}findByPrefix(e){return this.inner.findByPrefix(e)}},Mt=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,n){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,n,r){throw new Error("cannot update ref: ref store is read-only")}};function Hi(t){return{objectStore:new At(t.objectStore),refStore:new Mt(t.refStore),hooks:t.hooks}}var Lt=class{constructor(e){this.inner=e}overlay=new Map;async read(e){let n=this.overlay.get(e);return n?{type:n.type,content:new Uint8Array(n.content)}:this.inner.read(e)}async write(e,n){let r=await Ve(rn(e,n));return this.overlay.has(r)||await this.inner.exists(r).catch(()=>!1)||this.overlay.set(r,{type:e,content:new Uint8Array(n)}),r}async exists(e){return this.overlay.has(e)?!0:this.inner.exists(e)}async ingestPack(e){if(e.byteLength<32)return 0;let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0);if(r!==1346454347)throw new Error(`invalid pack signature: 0x${r.toString(16)} (expected 0x5041434b)`);let s=n.getUint32(4);if(s!==2)throw new Error(`unsupported pack version: ${s}`);if(n.getUint32(8)===0)return 0;let a=this.overlay,o=this.inner,c=await tn(e,async f=>{let l=a.get(f);if(l)return{type:l.type,content:new Uint8Array(l.content)};try{return await o.read(f)}catch{return null}});for(let f of c)a.has(f.hash)||a.set(f.hash,{type:f.type,content:f.content});return c.length}async ingestPackStream(e){let n=this.overlay,r=0;for await(let s of e)n.has(s.hash)||n.set(s.hash,{type:s.type,content:s.content}),r++;return r}async findByPrefix(e){let n=await this.inner.findByPrefix(e),r=[];for(let i of this.overlay.keys())i.startsWith(e)&&r.push(i);return[...new Set([...n,...r])]}},Dt=class{constructor(e){this.inner=e}overlay=new Map;deleted=new Set;async readRef(e){if(this.deleted.has(e))return null;let n=this.overlay.get(e);return n||this.inner.readRef(e)}async writeRef(e,n){this.deleted.delete(e),this.overlay.set(e,un(n))}async deleteRef(e){this.overlay.delete(e),this.deleted.add(e)}async listRefs(e){let n=await this.inner.listRefs(e),r=new Map;for(let s of n)this.deleted.has(s.name)||r.set(s.name,s);for(let[s,i]of this.overlay)if(!(e&&!s.startsWith(e))){if(i.type==="direct")r.set(s,{name:s,hash:i.hash});else if(i.type==="symbolic"){let a=await this.resolveSymbolic(i.target);a&&r.set(s,{name:s,hash:a})}}return[...r.values()]}async compareAndSwapRef(e,n,r){let s=await this.readRef(e),i=null;if(s&&(s.type==="direct"?i=s.hash:s.type==="symbolic"&&(i=await this.resolveSymbolic(s.target))),n===null){if(s!==null)return!1}else if(i!==n)return!1;return r===null?(this.overlay.delete(e),this.deleted.add(e)):(this.deleted.delete(e),this.overlay.set(e,r)),!0}async resolveSymbolic(e,n=0){if(n>10)return null;let r=await this.readRef(e);return r?r.type==="direct"?r.hash:r.type==="symbolic"?this.resolveSymbolic(r.target,n+1):null:null}};function Ht(t){return{objectStore:new Lt(t.objectStore),refStore:new Dt(t.refStore),hooks:t.hooks}}async function Bt(t,e){let n=await ye(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}function pr(t){return bn(t.map(e=>({path:e.path,mode:parseInt(e.mode,8),hash:e.hash,stage:0,stat:fe()})))}async function Bi(t,e,n,r="/"){let s=await Bt(t,e),i=await v(t,s),a=await z(t,i.tree),o=await Ue(t,a,n,r);return{commitHash:s,treeHash:i.tree,filesWritten:o}}async function Ni(t,e,n){let r=n?.workTree??"/",s=n?.gitDir??pe(r,".git"),i=n?.ref??"HEAD";await e.mkdir(s,{recursive:!0});let a=await Bt(t,i),o=await v(t,a),c=await z(t,o.tree),f={...t,fs:e,gitDir:s,workTree:r},l=await Ue(t,c,e,r);return await Ye(f,pr(c)),{ctx:f,commitHash:a,treeHash:o.tree,filesWritten:l}}async function Ui(t,e){let n=Ht(t),r=e?.workTree??"/",s=e?.gitDir??pe(r,".git"),i=e?.ref??"HEAD",a=await Bt(n,i),o=await v(n,a),c=new Pe(n.objectStore,o.tree,r),f="refs/heads/main";await n.refStore.writeRef("HEAD",{type:"symbolic",target:f}),await n.refStore.writeRef(f,{type:"direct",hash:a});let l={...n,fs:c,gitDir:s,workTree:r},u=await z(n,o.tree);return await Ye(l,pr(u)),{ctx:l,commitHash:a,treeHash:o.tree,filesWritten:0}}async function gr(t,e,n,r,s){let i=[],a=new Map;for await(let p of le(t,e,{exclude:n})){let b=s?p.commit.parents.slice(0,1):p.commit.parents;i.push({hash:p.hash,subject:xn(p.commit.message)}),a.set(p.hash,b)}let o=i.length;if(o===0)return null;if(o===1)return{hash:i[0].hash,subject:i[0].subject,remaining:0,steps:0,found:!0,onlySkippedLeft:!1};let c=new Set(i.map(p=>p.hash)),f=new Map;for(let p of i){let b=new Set,x=[p.hash],j=0;for(;j<x.length;){let S=x[j++];if(b.has(S)||!c.has(S))continue;b.add(S);let P=a.get(S);if(P)for(let w of P)!b.has(w)&&c.has(w)&&x.push(w)}f.set(p.hash,b.size)}let l=i[0].hash,u=o;for(let p of i){if(r.has(p.hash))continue;let b=f.get(p.hash)??0,x=Math.abs(2*b-o);x<u&&(u=x,l=p.hash)}let m=!1;if(u===o){m=!0;for(let p of i){let b=f.get(p.hash)??0,x=Math.abs(2*b-o);x<u&&(u=x,l=p.hash)}}let h=i.find(p=>p.hash===l),d=Gi(o),g=Fi(o);return{hash:h.hash,subject:h.subject,remaining:d,steps:g,found:!1,onlySkippedLeft:m}}function Gi(t){return Math.floor((t-1)/2)}function Fi(t){return t<=1?0:Math.ceil(Math.log2(t))}async function je(t,e){let n=await ye(t,e);if(!n)throw new Error(`revision '${e}' not found`);return n}async function _i(t,e){let n=await je(t,e.bad),r=Array.isArray(e.good)?e.good:[e.good],s=[];for(let c of r)s.push(await je(t,c));let i=new Set,a=e.firstParent??!1,o=0;for(;;){let c=await gr(t,n,s,i,a);if(!c)return{found:!1,reason:"no-testable-commits"};if(c.found)return{found:!0,hash:c.hash,stepsTaken:o};if(c.onlySkippedLeft)return{found:!1,reason:"all-skipped",candidates:[...i,n]};let f=await v(t,c.hash),l=Ge(t,f.tree),u=await e.test(c.hash,l);o++;let m;u==="skip"?(m="skip",i.add(c.hash)):u===!0?(m="good",s.push(c.hash)):(m="bad",n=c.hash),e.onStep?.({hash:c.hash,subject:c.subject,verdict:m,remaining:c.remaining,estimatedSteps:c.steps,stepNumber:o})}}async function Wi(t,e){let n=await je(t,e.commit),r=await je(t,e.onto),s=await v(t,n),i=await v(t,r),a=await yr(t,s,n,e.mainline),o=e.message??s.message;return e.recordOrigin&&(o=Ki(o,n)),br(t,{baseTree:a,oursTree:i.tree,theirsTree:s.tree,ontoHash:r,author:s.author,committer:e.committer,message:o,noCommit:e.noCommit,branch:e.branch,mergeDriver:e.mergeDriver})}async function zi(t,e){let n=await je(t,e.commit),r=await je(t,e.onto),s=await v(t,n),i=await v(t,r),a=await yr(t,s,n,e.mainline),o=s.message.split(`
|
|
30
|
+
`)[0]??"",c=e.message??`Revert "${o}"
|
|
31
|
+
|
|
32
|
+
This reverts commit ${n}.
|
|
33
|
+
`,f=e.author??e.committer;if(!f&&!e.noCommit)throw new Error("revert requires at least one of `author` or `committer`");let l=a??await Vi(t);return br(t,{baseTree:s.tree,oursTree:i.tree,theirsTree:l,ontoHash:r,author:f,committer:e.committer??e.author,message:c,noCommit:e.noCommit,branch:e.branch,mergeDriver:e.mergeDriver})}async function yr(t,e,n,r){if(e.parents.length>1){if(r==null)throw new Error(`commit ${n} is a merge but no mainline option was given`);let i=r-1;if(i<0||i>=e.parents.length)throw new Error(`commit ${n} does not have parent ${r}`);return(await v(t,e.parents[i])).tree}if(r!=null)throw new Error("mainline was specified but commit is not a merge");return e.parents.length===0?null:(await v(t,e.parents[0])).tree}async function Vi(t){return N(t,"tree",ge({type:"tree",entries:[]}))}async function br(t,e){let n=await $t(t,e.baseTree,e.oursTree,e.theirsTree,{mergeDriver:e.mergeDriver});if(!n.clean)return{clean:!1,treeHash:n.treeHash,conflicts:n.conflicts,messages:n.messages};if(e.noCommit)return{clean:!0,treeHash:n.treeHash};if(!e.author)throw new Error("author is required when creating a commit");return{clean:!0,hash:await Pt(t,{tree:n.treeHash,parents:[e.ontoHash],author:e.author,committer:e.committer,message:e.message,branch:e.branch}),treeHash:n.treeHash}}function Ki(t,e){let n=`(cherry picked from commit ${e})`,r=t.replace(/\n+$/,""),s=r.lastIndexOf(`
|
|
34
|
+
`),i=s===-1?r:r.slice(s+1);return/^\(cherry picked from commit [0-9a-f]+\)$/.test(i)?`${r}
|
|
35
|
+
${n}
|
|
36
|
+
`:`${r}
|
|
37
|
+
|
|
38
|
+
${n}
|
|
39
|
+
`}export{_i as bisect,ui as blame,pt as branchNameFromRef,er as buildCommit,Wi as cherryPick,Ii as commit,fi as countAheadBehind,Ri as createAnnotatedTag,Pt as createCommit,Ui as createSandboxWorktree,Ge as createTreeAccessor,Ni as createWorktree,pi as diffCommits,ii as diffTrees,Bi as extractTree,li as findMergeBases,si as flattenTree,gi as formatDiff,oi as getChangedFiles,ai as getNewCommits,Os as grep,ci as isAncestor,ds as listBranches,ps as listTags,Di as mergeTrees,$t as mergeTreesFromTreeHashes,Ht as overlayRepo,bs as readBlob,ws as readBlobText,ys as readCommit,Is as readFileAtCommit,gs as readHead,Rs as readTree,Hi as readonlyRepo,ms as resolveRef,ye as revParse,zi as revert,hn as tagNameFromRef,nr as updateTree,yi as walkCommitHistory,xi as writeBlob,Ei as writeTree};
|
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-CimfP56a.js';
|
|
2
|
-
import { b as CommitOptions, c as CommitResult } from '../writing-
|
|
2
|
+
import { b as CommitOptions, c as CommitResult } from '../writing-CEP3N60d.js';
|
|
3
3
|
|
|
4
4
|
/** Shallow boundary delta: what to add/remove from `.git/shallow`. */
|
|
5
5
|
interface ShallowUpdate {
|
|
@@ -201,4 +201,4 @@ interface TreeUpdate {
|
|
|
201
201
|
*/
|
|
202
202
|
declare function updateTree(repo: GitRepo, treeHash: string, updates: TreeUpdate[]): Promise<string>;
|
|
203
203
|
|
|
204
|
-
export { type BuildCommitOptions as B, type
|
|
204
|
+
export { type BuildCommitOptions as B, type CommitIdentity as C, type TreeEntryInput as T, type CommitAuthor as a, type CommitOptions as b, type CommitResult as c, type CreateAnnotatedTagOptions as d, type CreateCommitOptions as e, type TreeUpdate as f, buildCommit as g, commit as h, createAnnotatedTag as i, createCommit as j, writeTree as k, updateTree as u, writeBlob as w };
|