@scolladon/tsgit 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/README.md +12 -0
  2. package/dist/cjs/adapters/browser/index.cjs +1 -2
  3. package/dist/cjs/adapters/memory/index.cjs +1 -2
  4. package/dist/cjs/adapters/node/index.cjs +1 -2
  5. package/dist/cjs/chunks/{adapter-detect-D7DFJtuk.cjs → adapter-detect-DW9fsw9d.cjs} +1 -2
  6. package/dist/cjs/chunks/browser-http-transport-DGwW5YL7.cjs +1 -0
  7. package/dist/cjs/chunks/context-BcoAzPuU.cjs +0 -1
  8. package/dist/cjs/chunks/error-CfLWDui_.cjs +1 -0
  9. package/dist/cjs/chunks/index-Cy44GVR6.cjs +1 -0
  10. package/dist/cjs/chunks/inflate-CmCtM4-w.cjs +1 -0
  11. package/dist/cjs/chunks/lru-cache-1OU7JhD8.cjs +0 -1
  12. package/dist/cjs/chunks/memory-http-transport-CGriODcQ.cjs +1 -0
  13. package/dist/cjs/chunks/node-ssh-transport-PFu3ijfp.cjs +1 -0
  14. package/dist/cjs/chunks/{progress-CjhUeyxd.cjs → progress-D8Dqbftk.cjs} +1 -2
  15. package/dist/cjs/chunks/readable-stream-MTA6D0Zh.cjs +0 -1
  16. package/dist/cjs/chunks/{repository-DJNNrfQr.cjs → repository-Ci-BBxk0.cjs} +1 -2
  17. package/dist/cjs/chunks/write-sparse-checkout-C1dsHCAD.cjs +1 -0
  18. package/dist/cjs/commands/index.cjs +1 -2
  19. package/dist/cjs/index.browser.cjs +1 -2
  20. package/dist/cjs/index.cjs +1 -2
  21. package/dist/cjs/index.default.cjs +1 -2
  22. package/dist/cjs/index.node.cjs +1 -2
  23. package/dist/cjs/operators/index.cjs +0 -1
  24. package/dist/cjs/primitives/index.cjs +1 -2
  25. package/dist/cjs/transport/index.cjs +0 -1
  26. package/dist/esm/adapters/browser/index.js +1 -2
  27. package/dist/esm/adapters/memory/index.js +1 -2
  28. package/dist/esm/adapters/node/index.js +1 -2
  29. package/dist/esm/chunks/{adapter-detect-CTTG6hpk.js → adapter-detect-BkCMnjrI.js} +1 -2
  30. package/dist/esm/chunks/browser-http-transport-CSxAte5h.js +1 -0
  31. package/dist/esm/chunks/context-CumKOV7K.js +0 -1
  32. package/dist/esm/chunks/error-BotOd-nD.js +1 -0
  33. package/dist/esm/chunks/index-DsvINN8n.js +1 -0
  34. package/dist/esm/chunks/inflate-BCIXqeeE.js +1 -0
  35. package/dist/esm/chunks/lru-cache-Cy7C7Lx2.js +0 -1
  36. package/dist/esm/chunks/memory-http-transport-caqmMGR1.js +1 -0
  37. package/dist/esm/chunks/node-ssh-transport-BgSv2IhT.js +1 -0
  38. package/dist/esm/chunks/{progress-CLPpgZJ6.js → progress-B_AJnOHx.js} +1 -2
  39. package/dist/esm/chunks/readable-stream-CGuf8k1J.js +0 -1
  40. package/dist/esm/chunks/repository-DyxknzvE.js +1 -0
  41. package/dist/esm/chunks/write-sparse-checkout-BwHbNKNS.js +1 -0
  42. package/dist/esm/commands/index.js +1 -2
  43. package/dist/esm/index.browser.js +1 -2
  44. package/dist/esm/index.default.js +1 -2
  45. package/dist/esm/index.js +1 -2
  46. package/dist/esm/index.node.js +1 -2
  47. package/dist/esm/operators/index.js +0 -1
  48. package/dist/esm/primitives/index.js +1 -2
  49. package/dist/esm/transport/index.js +0 -1
  50. package/dist/types/adapters/browser/index.d.cts +1 -1
  51. package/dist/types/adapters/browser/index.d.ts +1 -1
  52. package/dist/types/adapters/memory/index.d.cts +1 -1
  53. package/dist/types/adapters/memory/index.d.ts +1 -1
  54. package/dist/types/adapters/node/index.d.cts +94 -36
  55. package/dist/types/adapters/node/index.d.ts +94 -36
  56. package/dist/types/chunks/{context-D_A7-uau.d.cts → context-CF1YF2S8.d.cts} +48 -2
  57. package/dist/types/chunks/{context-CNtbFlwI.d.ts → context-sIhhtk2u.d.ts} +48 -2
  58. package/dist/types/chunks/{index-E_KapqW9.d.ts → index-B5Dps3fg.d.ts} +32 -3
  59. package/dist/types/chunks/{index-BJDekgCP.d.ts → index-B_A8VLaf.d.ts} +111 -12
  60. package/dist/types/chunks/{index-wwZiot4c.d.cts → index-Dfh8cvEs.d.cts} +32 -3
  61. package/dist/types/chunks/{index-CMLLVz9B.d.cts → index-Dqxddhav.d.cts} +111 -12
  62. package/dist/types/chunks/{progress-hcn9r2H3.d.ts → progress-BjAKfkam.d.ts} +51 -5
  63. package/dist/types/chunks/{progress-Cp-huK45.d.cts → progress-Ldnfb8st.d.cts} +51 -5
  64. package/dist/types/chunks/{reflog-entry-BGJr9VfU.d.cts → reflog-entry-Cqh3QrPH.d.ts} +12 -3
  65. package/dist/types/chunks/{reflog-entry-DecZqJna.d.ts → reflog-entry-Dy-O27Dd.d.cts} +12 -3
  66. package/dist/types/chunks/{repository-Dxhwpzd6.d.ts → repository-D8QBTkEz.d.ts} +5 -5
  67. package/dist/types/chunks/{repository-DASBgOb9.d.cts → repository-D9YrVhcH.d.cts} +5 -5
  68. package/dist/types/commands/index.d.cts +3 -3
  69. package/dist/types/commands/index.d.ts +3 -3
  70. package/dist/types/index.browser.d.cts +6 -6
  71. package/dist/types/index.browser.d.ts +6 -6
  72. package/dist/types/index.d.cts +8 -8
  73. package/dist/types/index.d.ts +8 -8
  74. package/dist/types/index.default.d.cts +6 -6
  75. package/dist/types/index.default.d.ts +6 -6
  76. package/dist/types/index.node.d.cts +6 -6
  77. package/dist/types/index.node.d.ts +6 -6
  78. package/dist/types/primitives/index.d.cts +3 -3
  79. package/dist/types/primitives/index.d.ts +3 -3
  80. package/package.json +90 -24
  81. package/dist/cjs/adapters/browser/index.cjs.map +0 -1
  82. package/dist/cjs/adapters/memory/index.cjs.map +0 -1
  83. package/dist/cjs/adapters/node/index.cjs.map +0 -1
  84. package/dist/cjs/chunks/adapter-detect-D7DFJtuk.cjs.map +0 -1
  85. package/dist/cjs/chunks/adler32-CrRRuL2P.cjs +0 -2
  86. package/dist/cjs/chunks/adler32-CrRRuL2P.cjs.map +0 -1
  87. package/dist/cjs/chunks/browser-http-transport-nGm6alox.cjs +0 -2
  88. package/dist/cjs/chunks/browser-http-transport-nGm6alox.cjs.map +0 -1
  89. package/dist/cjs/chunks/context-BcoAzPuU.cjs.map +0 -1
  90. package/dist/cjs/chunks/error-CA80UqXF.cjs +0 -2
  91. package/dist/cjs/chunks/error-CA80UqXF.cjs.map +0 -1
  92. package/dist/cjs/chunks/index-01WCH0eg.cjs +0 -2
  93. package/dist/cjs/chunks/index-01WCH0eg.cjs.map +0 -1
  94. package/dist/cjs/chunks/lru-cache-1OU7JhD8.cjs.map +0 -1
  95. package/dist/cjs/chunks/memory-http-transport-7hpDW8o3.cjs +0 -2
  96. package/dist/cjs/chunks/memory-http-transport-7hpDW8o3.cjs.map +0 -1
  97. package/dist/cjs/chunks/node-http-transport-CoqnAvIL.cjs +0 -2
  98. package/dist/cjs/chunks/node-http-transport-CoqnAvIL.cjs.map +0 -1
  99. package/dist/cjs/chunks/progress-CjhUeyxd.cjs.map +0 -1
  100. package/dist/cjs/chunks/readable-stream-MTA6D0Zh.cjs.map +0 -1
  101. package/dist/cjs/chunks/repository-DJNNrfQr.cjs.map +0 -1
  102. package/dist/cjs/chunks/write-sparse-checkout-DzVubBcI.cjs +0 -2
  103. package/dist/cjs/chunks/write-sparse-checkout-DzVubBcI.cjs.map +0 -1
  104. package/dist/cjs/commands/index.cjs.map +0 -1
  105. package/dist/cjs/index.browser.cjs.map +0 -1
  106. package/dist/cjs/index.cjs.map +0 -1
  107. package/dist/cjs/index.default.cjs.map +0 -1
  108. package/dist/cjs/index.node.cjs.map +0 -1
  109. package/dist/cjs/operators/index.cjs.map +0 -1
  110. package/dist/cjs/primitives/index.cjs.map +0 -1
  111. package/dist/cjs/transport/index.cjs.map +0 -1
  112. package/dist/esm/adapters/browser/index.js.map +0 -1
  113. package/dist/esm/adapters/memory/index.js.map +0 -1
  114. package/dist/esm/adapters/node/index.js.map +0 -1
  115. package/dist/esm/chunks/adapter-detect-CTTG6hpk.js.map +0 -1
  116. package/dist/esm/chunks/adler32-BfvKJOAO.js +0 -2
  117. package/dist/esm/chunks/adler32-BfvKJOAO.js.map +0 -1
  118. package/dist/esm/chunks/browser-http-transport-DD0YKmIW.js +0 -2
  119. package/dist/esm/chunks/browser-http-transport-DD0YKmIW.js.map +0 -1
  120. package/dist/esm/chunks/context-CumKOV7K.js.map +0 -1
  121. package/dist/esm/chunks/error-BD0nFV6t.js +0 -2
  122. package/dist/esm/chunks/error-BD0nFV6t.js.map +0 -1
  123. package/dist/esm/chunks/index-BEI7XKaV.js +0 -2
  124. package/dist/esm/chunks/index-BEI7XKaV.js.map +0 -1
  125. package/dist/esm/chunks/lru-cache-Cy7C7Lx2.js.map +0 -1
  126. package/dist/esm/chunks/memory-http-transport-D13LBPvu.js +0 -2
  127. package/dist/esm/chunks/memory-http-transport-D13LBPvu.js.map +0 -1
  128. package/dist/esm/chunks/node-http-transport-doU9Y8WN.js +0 -2
  129. package/dist/esm/chunks/node-http-transport-doU9Y8WN.js.map +0 -1
  130. package/dist/esm/chunks/progress-CLPpgZJ6.js.map +0 -1
  131. package/dist/esm/chunks/readable-stream-CGuf8k1J.js.map +0 -1
  132. package/dist/esm/chunks/repository-dCH3DdLQ.js +0 -2
  133. package/dist/esm/chunks/repository-dCH3DdLQ.js.map +0 -1
  134. package/dist/esm/chunks/write-sparse-checkout-D4tNUXOp.js +0 -2
  135. package/dist/esm/chunks/write-sparse-checkout-D4tNUXOp.js.map +0 -1
  136. package/dist/esm/commands/index.js.map +0 -1
  137. package/dist/esm/index.browser.js.map +0 -1
  138. package/dist/esm/index.default.js.map +0 -1
  139. package/dist/esm/index.js.map +0 -1
  140. package/dist/esm/index.node.js.map +0 -1
  141. package/dist/esm/operators/index.js.map +0 -1
  142. package/dist/esm/primitives/index.js.map +0 -1
  143. package/dist/esm/transport/index.js.map +0 -1
@@ -1,2 +0,0 @@
1
- "use strict";var e=require("./error-CA80UqXF.cjs"),t=require("./readable-stream-MTA6D0Zh.cjs");const n=t=>new e.TsgitError({code:"INVALID_OBJECT_ID",value:t}),r=t=>new e.TsgitError({code:"INVALID_OBJECT_HEADER",reason:t}),o=(t,n)=>new e.TsgitError({code:"INVALID_TREE_ENTRY",offset:t,reason:n}),s=t=>new e.TsgitError({code:"INVALID_COMMIT",reason:t}),i=t=>new e.TsgitError({code:"INVALID_TAG",reason:t}),a=(t,n)=>new e.TsgitError({code:"INVALID_IDENTITY",line:t,reason:n}),c=t=>new e.TsgitError({code:"OBJECT_NOT_FOUND",id:t}),d=(t,n)=>new e.TsgitError({code:"OBJECT_HASH_MISMATCH",expected:t,actual:n}),u=(t,n,r)=>new e.TsgitError({code:"UNEXPECTED_OBJECT_TYPE",expected:t,actual:n,id:r}),l=t=>new e.TsgitError({code:"TREE_DEPTH_EXCEEDED",depth:t}),f=(t,n)=>new e.TsgitError({code:"TREE_ENTRY_LIMIT_EXCEEDED",count:t,limit:n}),h=(t,n,r)=>new e.TsgitError({code:"OBJECT_TOO_LARGE",id:t,actualSize:n,limit:r}),p={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"40000",GITLINK:"160000"},w=new Set(Object.values(p)),g=new Map([["040000",p.DIRECTORY]]);function m(t){return function(t){if(!w.has(t))throw new e.TsgitError({code:"INVALID_FILE_MODE",value:t});return t}(g.get(t)??t)}function y(e){return e===p.DIRECTORY}function v(e){return e.isSymbolicLink?p.SYMLINK:73&e.mode?p.EXECUTABLE:p.REGULAR}const x=function(){const e=new Uint32Array(256);for(let t=0;t<256;t++){let n=t;for(let e=0;e<8;e++)n=1&n?3988292384^n>>>1:n>>>1;e[t]=n}return e}();function b(e){let t=4294967295;for(let n=0;n<e.length;n++)t=x[255&(t^e[n])]^t>>>8;return(4294967295^t)>>>0}const k=e=>/[a-zA-Z0-9-]/.test(e),E=e=>{if(!/[a-zA-Z]/.test(e[0]))return 0;for(let t=1;t<e.length;t+=1)if(!k(e[t]))return t},I=/[\n\0]/,T=t=>{const n=t.indexOf(".");if(-1===n)throw e.configKeyInvalid(t,"missing-name");const r=t.slice(0,n),o=t.lastIndexOf("."),s=t.slice(o+1),i=n===o?void 0:t.slice(n+1,o);if(0===r.length&&void 0===i)throw e.configKeyInvalid(t,"empty-section");if(0===s.length)throw e.configKeyInvalid(t,"missing-name");if(r.length>0){const n=E(r);if(void 0!==n)throw e.configKeyInvalid(t,"bad-character",n)}const a=E(s);if(void 0!==a)throw e.configKeyInvalid(t,"bad-character",o+1+a);if(void 0!==i&&I.test(i)){const r=i.search(I);throw e.configKeyInvalid(t,"bad-character",n+1+r)}return{section:r.toLowerCase(),subsection:i,name:s.toLowerCase()}},C=1e6,L=t=>new e.TsgitError({code:"INVALID_INDEX_HEADER",reason:t}),S=(t,n)=>new e.TsgitError({code:"INVALID_INDEX_ENTRY",offset:t,reason:n}),$={assumeValid:!1,stage:0,skipWorktree:!1,intentToAdd:!1},A=e=>({ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,mode:e.mode,uid:0,gid:0,fileSize:0,id:e.id,flags:{...$,skipWorktree:!0},path:e.path}),D=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function O(e){const t=new Array(e.length);for(let n=0;n<e.length;n++)t[n]=D[e[n]];return t.join("")}function _(e){if(e.length%2!=0)throw new Error("Hex string must have even length");const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2){const r=U(e.charCodeAt(n)),o=U(e.charCodeAt(n+1));if(-1===r||-1===o)throw new Error(`Invalid hex character at position ${n}`);t[n/2]=r<<4|o}return t}function U(e){return e>=48&&e<=57?e-48:e>=97&&e<=102?e-87:-1}function N(e,t){const n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return e[r]-t[r];return e.length-t.length}function M(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function R(e,t,n){for(let r=n;r<e.length;r++)if(e[r]===t)return r;return-1}const P=new TextEncoder,F=new TextDecoder;function B(e){return P.encode(e)}function W(e){return F.decode(e)}function j(e){const t=e.indexOf("\n\n");return-1===t?{headerPart:e,message:""}:{headerPart:e.slice(0,t),message:e.slice(t+2)}}function z(e,t){if(e.includes("\n")||e.includes(" ")||""===e)throw new Error(`invalid header key: ${e}`);const n=t.split("\n");return[`${e} ${n[0]}`,...n.slice(1).map(e=>` ${e}`)].join("\n")}function H(e){const t=e.indexOf(" ");return-1===t?{key:e,value:""}:{key:e.slice(0,t),value:e.slice(t+1)}}function V(e,t,n,r){let o;const s=[];let i=t;for(;i<e.length;){const{key:t,value:a}=H(e[i]);""===t&&n("unexpected continuation line without preceding header");const c=[a];let d=i;for(let t=i+1;t<e.length;t++){const n=e[t];if(!n.startsWith(" "))break;c.push(n.slice(1)),d=t}i=d+1;const u=c.join("\n");"gpgsig"===t?(void 0!==o&&r("duplicate gpgsig header"),o=u):s.push({key:t,value:u})}return{gpgSignature:o,extraHeaders:s}}function K(e){const t=e.lastIndexOf(">");if(-1===t)throw a(e,"missing closing angle bracket");const n=e.lastIndexOf("<",t);if(-1===n)throw a(e,"missing opening angle bracket");const r=e.slice(0,n),o=r.endsWith(" ")?r.slice(0,-1):r,s=e.slice(n+1,t),i=e.slice(t+1).trim().split(/\s+/);if(i.length<2)throw a(e,"missing timestamp or timezone");const c=Number(i[0]);if(!Number.isSafeInteger(c))throw a(e,"invalid timestamp");const d=i[1];if(!/^[+-]\d{4}$/.test(d))throw a(e,"invalid timezone offset");return{name:o,email:s,timestamp:c,timezoneOffset:d}}const G=/[\n\r\0]/;function Y(e){const t=`${e.name} <${e.email}>`;if(G.test(e.name))throw a(t,"name contains forbidden control character");if(G.test(e.email))throw a(t,"email contains forbidden control character");if(G.test(e.timezoneOffset))throw a(t,"timezoneOffset contains forbidden control character");if(e.name.includes("<")||e.name.includes(">"))throw a(t,"invalid identity fields");if(e.email.includes("<")||e.email.includes(">"))throw a(t,"invalid identity fields");if(!/^[+-]\d{4}$/.test(e.timezoneOffset))throw a(t,"invalid identity fields");return`${e.name} <${e.email}> ${e.timestamp} ${e.timezoneOffset}`}const q=/^[0-9a-f]{40}$/,X=/^[0-9a-f]{64}$/,J={from(e){if(!q.test(e)&&!X.test(e))throw n(e);return e},fromRaw(e){if(20!==e.length&&32!==e.length)throw n(`raw bytes length ${e.length} is not 20 or 32`);return J.from(O(e))}},Q=J.from("0000000000000000000000000000000000000000");J.from("4b825dc642cb6eb9a060e54bf8d69288fbee4904");const Z={from(e){if(""===e)throw new Error("RefName must not be empty");return e}},ee={from(e){if(""===e)throw new Error("FilePath must not be empty");return e}};function te(e){const t=[],{data:n}=e;t.push(`tree ${n.tree}`);for(const e of n.parents)t.push(`parent ${e}`);t.push(`author ${Y(n.author)}`),t.push(`committer ${Y(n.committer)}`),void 0!==n.gpgSignature&&t.push(z("gpgsig",n.gpgSignature));for(const e of n.extraHeaders)t.push(z(e.key,e.value));return B(`${t.join("\n")}\n\n${n.message}`)}const ne=new Set(["blob","tree","commit","tag"]);function re(e){const t=R(e,0,0);if(-1===t)throw r("missing null terminator");const n=W(e.subarray(0,t)),o=n.indexOf(" ");if(-1===o)throw r("missing space between type and size");const s=n.slice(0,o);if(!ne.has(s))throw r(`unknown object type: ${s}`);const i=n.slice(o+1),a=Number(i);if(!Number.isFinite(a)||a<0||i!==String(a))throw r(`invalid size: ${i}`);return{type:s,size:a,contentOffset:t+1}}const oe=new Set(["blob","tree","commit","tag"]);function se(e){const t=[],{data:n}=e;if(t.push(`object ${n.object}`),t.push(`type ${n.objectType}`),""===n.tagName||n.tagName.includes("\n")||n.tagName.includes("\0"))throw i(`invalid tag name: ${n.tagName}`);t.push(`tag ${n.tagName}`),void 0!==n.tagger&&t.push(`tagger ${Y(n.tagger)}`),void 0!==n.gpgSignature&&t.push(z("gpgsig",n.gpgSignature));for(const e of n.extraHeaders)t.push(z(e.key,e.value));return B(`${t.join("\n")}\n\n${n.message}`)}function ie(e,t){const n=ae(e.entries).map(e=>({mode:B(e.mode),name:B(e.name),hash:_(e.id)})),r=n.reduce((e,n)=>e+n.mode.length+1+n.name.length+1+t.digestLength,0),o=new Uint8Array(r);let s=0;for(const e of n)o.set(e.mode,s),s+=e.mode.length,o[s++]=32,o.set(e.name,s),s+=e.name.length,o[s++]=0,o.set(e.hash,s),s+=e.hash.length;return o}function ae(e){const t=e.map(e=>({entry:e,sortKey:de(e.name,y(e.mode))}));return t.sort((e,t)=>N(e.sortKey,t.sortKey)),t.map(e=>e.entry)}function ce(e,t){return N(de(e.name,y(e.mode)),de(t.name,y(t.mode)))}function de(e,t){const n=B(e);if(!t)return n;const r=new Uint8Array(n.length+1);return r.set(n),r[n.length]=47,r}function ue(e,t,n){const{type:a,size:c,contentOffset:d}=re(t),u=t.subarray(d);if(u.length!==c)throw r(`size mismatch: header says ${c}, actual content is ${u.length}`);switch(a){case"blob":return function(e,t){return{type:"blob",id:e,content:t}}(e,u);case"tree":return function(e,t,n){const r=[],s=new Set;let i=0;for(;i<t.length;){const e=R(t,32,i);if(-1===e)throw o(i,"missing space after mode");const a=W(t.subarray(i,e)),c=R(t,0,e+1);if(-1===c)throw o(i,"missing null after name");const d=W(t.subarray(e+1,c));if(""===d||"."===d||".."===d||d.includes("/"))throw o(i,`invalid entry name: ${d}`);const u=c+1,l=u+n.digestLength;if(l>t.length)throw o(i,"truncated hash");const f=t.subarray(u,l),h=J.fromRaw(f),p=m(a);if(s.has(d))throw o(i,`duplicate entry name: ${d}`);s.add(d),r.push({mode:p,name:d,id:h}),i=l}return{type:"tree",id:e,entries:r}}(e,u,n);case"commit":return function(e,t){const{headerPart:n,message:r}=j(W(t)),o=n.split("\n"),{tree:i,parents:a,author:c,committer:d,nextIndex:u}=function(e){if(!e[0].startsWith("tree "))throw s("first line must be tree");const t=J.from(e[0].slice(5)),n=[];let r=1;for(;r<e.length&&e[r].startsWith("parent ");)n.push(J.from(e[r].slice(7))),r++;if(r>=e.length||!e[r].startsWith("author "))throw s("missing author");const o=K(e[r].slice(7));if(r++,r>=e.length||!e[r].startsWith("committer "))throw s("missing committer");const i=K(e[r].slice(10));return r++,{tree:t,parents:n,author:o,committer:i,nextIndex:r}}(o),{gpgSignature:l,extraHeaders:f}=function(e,t){return V(e,t,e=>{throw s(e)},e=>{throw s(e)})}(o,u);return{type:"commit",id:e,data:{tree:i,parents:a,author:c,committer:d,message:r,...void 0!==l?{gpgSignature:l}:{},extraHeaders:f}}}(e,u);case"tag":return function(e,t){const{headerPart:n,message:r}=j(W(t)),o=n.split("\n"),{object:s,objectType:a,tagName:c,nextIndex:d}=function(e){if(!e[0].startsWith("object "))throw i("first line must be object");const t=J.from(e[0].slice(7));if(e.length<2||!e[1].startsWith("type "))throw i("second line must be type");const n=e[1].slice(5);if(!oe.has(n))throw i(`invalid object type: ${n}`);if(e.length<3||!e[2].startsWith("tag "))throw i("third line must be tag name");const r=e[2].slice(4);if(""===r||r.includes("\0")||r.includes("\n"))throw i(`invalid tag name: ${r}`);return{object:t,objectType:n,tagName:r,nextIndex:3}}(o),{tagger:u,nextIndex:l}=function(e,t){return t<e.length&&e[t].startsWith("tagger ")?{tagger:K(e[t].slice(7)),nextIndex:t+1}:{tagger:void 0,nextIndex:t}}(o,d),{gpgSignature:f,extraHeaders:h}=function(e,t){return V(e,t,e=>{throw i(e)},e=>{throw i(e)})}(o,l);return{type:"tag",id:e,data:{object:s,objectType:a,tagName:c,...void 0!==u?{tagger:u}:{},message:r,...void 0!==f?{gpgSignature:f}:{},extraHeaders:h}}}(e,u)}}function le(e,t){let n;switch(e.type){case"blob":n=e.content;break;case"tree":n=ie(e,t);break;case"commit":n=te(e);break;case"tag":n=se(e)}const r=B(`${e.type} ${n.length}\0`),o=new Uint8Array(r.length+n.length);return o.set(r,0),o.set(n,r.length),o}const fe=(e,t)=>{switch(e.type){case"blob":return e.content.byteLength;case"tree":return ie(e,t).byteLength;case"commit":return te(e).byteLength;case"tag":return se(e).byteLength}},he=new Set(["",".",".."]),pe=new Set([1564,8206,8207,8234,8235,8236,8237,8238,8294,8295,8296,8297]),we=e=>""===e?"empty segment rejected":"."===e?"'.' segment rejected":"'..' segment rejected",ge=e=>e<32||e>=127&&e<=159,me=(e,t)=>{if(e.startsWith("/"))throw S(t,"absolute path rejected");const n=(e=>{for(let t=0;t<e.length;t+=1){const n=e.charCodeAt(t);if(92===n)return"backslash rejected";if(ge(n))return"control character rejected";if(pe.has(n))return"bidi control character rejected"}})(e);if(void 0!==n)throw S(t,n);for(const n of e.split("/"))if(he.has(n))throw S(t,we(n))};function ye(e,t,n,r){const o=e.getUint16(t+60),s=!!(16384&o);if(s&&3!==n)throw S(t,"extended flag requires index v3");const i=s?2:0;if(t+62+i>r-20)throw S(t,"truncated extended flags");return{flags:(a=o,c=s?e.getUint16(t+62):0,{assumeValid:!!(32768&a),stage:a>>>12&3,skipWorktree:!!(16384&c),intentToAdd:!!(8192&c)}),extendedSize:i};var a,c}function ve(e,t){for(let n=t;n<e.length;n++)if(0===e[n])return n;return-1}function xe(e,t){const n=e.path,r=t.path;return n<r?-1:n>r?1:0}function be(e,t,n,r,o,s){t.setUint32(n,r.ctimeSeconds),t.setUint32(n+4,r.ctimeNanoseconds),t.setUint32(n+8,r.mtimeSeconds),t.setUint32(n+12,r.mtimeNanoseconds),t.setUint32(n+16,r.dev),t.setUint32(n+20,r.ino),t.setUint32(n+24,Number.parseInt(r.mode,8)),t.setUint32(n+28,r.uid),t.setUint32(n+32,r.gid),t.setUint32(n+36,r.fileSize);const i=_(r.id);e.set(i,n+40);const a=Math.min(o.length,4095);t.setUint16(n+60,(r.flags.assumeValid?32768:0)|(s?16384:0)|r.flags.stage<<12|a),s&&t.setUint16(n+62,(r.flags.skipWorktree?16384:0)|(r.flags.intentToAdd?8192:0)),e.set(o,n+62+(s?2:0))}function ke(e){switch(e.type){case"add":case"rename":case"copy":return e.newPath;case"delete":return e.oldPath;case"modify":case"type-change":return e.path}}function Ee(e){return e===p.REGULAR||e===p.EXECUTABLE?"file":e===p.SYMLINK?"symlink":e===p.DIRECTORY?"directory":"gitlink"}function Ie(e,t){return Ee(e)===Ee(t)}function Te(e){return"gitlink"===Ee(e)}const Ce=new TextEncoder;function Le(e,t){return N(Ce.encode(e),Ce.encode(t))}function Se(e,t){const n=e.map(e=>({item:e,key:Ce.encode(t(e))}));return n.sort((e,t)=>N(e.key,t.key)),n.map(e=>e.item)}function $e(e){return 32===e||9===e}function Ae(e){const t=e.length-1;return t>=0&&10===e[t]?t:e.length}function De(e,t){const n=function(e,t){return t.ignoreCrAtEol||"all"===t.mode||"change"===t.mode||"at-eol"===t.mode?function(e){const t=Ae(e),n=t-1;if(n<0||13!==e[n])return e;const r=new Uint8Array(e.length-1);return r.set(e.subarray(0,n)),t<e.length&&(r[n]=10),r}(e):e}(e,t);switch(t.mode){case"all":return function(e){const t=Ae(e),n=[];for(let r=0;r<t;r++){const t=e[r];$e(t)||n.push(t)}return t<e.length&&n.push(10),new Uint8Array(n)}(n);case"change":return function(e){const t=Ae(e),n=[];let r=!1;for(let o=0;o<t;o++){const t=e[o];$e(t)?r||(n.push(32),r=!0):(r=!1,n.push(t))}return n.length>0&&32===n[n.length-1]&&n.pop(),t<e.length&&n.push(10),new Uint8Array(n)}(n);case"at-eol":return function(e){const t=Ae(e);let n=t;for(;n>0&&$e(e[n-1]);)n--;if(n===t&&t===e.length)return e;const r=new Uint8Array(n+(t<e.length?1:0));return r.set(e.subarray(0,n)),t<e.length&&(r[n]=10),r}(n);case"none":return n}}const Oe={mode:"none",ignoreCrAtEol:!1};function _e(e,t){return 0===Ae(De(e,t))}const Ue=1e5;function Ne(e){const t=[];let n=0;for(let r=0;r<e.length;r++)10===e[r]&&(t.push(e.subarray(n,r+1)),n=r+1);return n<e.length&&t.push(e.subarray(n)),t}function Me(e){return function(e){const t=Math.min(e.length,8e3);for(let n=0;n<t;n++)if(0===e[n])return!0;return!1}(e)||function(e){let t=0,n=0;for(let r=0;r<e.length;r++){if(t++,t>=65536)return!0;if(10===e[r]){if(n++,n>=Ue)return!0;t=0}}return t>0&&(n++,n>=Ue)}(e)}function Re(e,t,n,r){return r===-n||e[r-1+t]<e[r+1+t]}function Pe(e,t,n,r,o,s,i){let a=Re(n,r,o,s)?n[s+1+r]:n[s-1+r]+1,c=a-s;for(;a<e.length&&c<t.length&&i(e[a],t[c]);)a++,c++;return{x:a,y:c}}function Fe(e){const t=[];let n=0,r=0,o=0;for(;o<e.length;){const s=e[o],i=n,a=r;for(;e[o]===s;)"equal"===s?(n++,r++):"delete"===s?n++:r++,o++;t.push({kind:"equal"===s?"common":"delete"===s?"ours-only":"theirs-only",oursStart:i,oursEnd:n,theirsStart:a,theirsEnd:r})}return t}function Be(e,t,n){const r=n?.lineKey,o=r?(e,t)=>function(e,t,n){return M(De(e,n),De(t,n))}(e,t,r):M,s=Ne(e),i=Ne(t),a=s.length,c=i.length;if(0===a&&0===c)return{hunks:[{kind:"common",oursStart:0,oursEnd:0,theirsStart:0,theirsEnd:0}],oursLines:s,theirsLines:i,degraded:!1};const d=function(e,t,n){const r=e.length,o=t.length;if(r+o>5e4)return;const s=r+o,i=s,a=new Array(2*s+1).fill(0),c=[],d=1e3*s;let u=0;for(let s=0;;s++){const l=2*s+1,f=new Array(l);for(let e=0;e<l;e++)f[e]=a[i-s+e];c.push(f);for(let l=-s;l<=s;l+=2){if(u++,u>d)return;const f=Pe(e,t,a,i,s,l,n);if(a[l+i]=f.x,f.x>=r&&f.y>=o)return{trace:c,totalD:s}}}}(s,i,o);return void 0===d?function(e,t){const n=[];return e.length>0&&n.push({kind:"ours-only",oursStart:0,oursEnd:e.length,theirsStart:0,theirsEnd:0}),t.length>0&&n.push({kind:"theirs-only",oursStart:e.length,oursEnd:e.length,theirsStart:0,theirsEnd:t.length}),{hunks:n,oursLines:e,theirsLines:t,degraded:!0}}(s,i):{hunks:Fe(function(e,t,n){const r=[];let o=e,s=t;for(let e=n.length-1;e>0;e--){const t=n[e],i=e,a=o-s,c=Re(t,i,e,a)?a+1:a-1,d=t[c+i],u=d-c;for(;o>d&&s>u;)r.push("equal"),o--,s--;r.push(o===d?"insert":"delete"),o===d?s--:o--}for(;o>0;)r.push("equal"),o--;return r.reverse(),r}(a,c,d.trace)),oursLines:s,theirsLines:i,degraded:!1}}const We=6e4,je=107927;function ze(e){const t=new Map,n=e.length;let r=0,o=0,s=0;for(let i=0;i<n;i++){const n=e[i],a=r;if(r=(r<<7^o>>>25)+n>>>0,o=(o<<7^a>>>25)>>>0,s++,s>=64||10===n){const e=(r+Math.imul(o,97))%je;t.set(e,(t.get(e)??0)+s),s=0,r=0,o=0}}if(s>0){const e=(r+Math.imul(o,97))%je;t.set(e,(t.get(e)??0)+s)}return t}function He(e,t){let n=0;for(const[r,o]of e){const e=t.get(r)??0;e>0&&(n+=Math.min(o,e))}return n}function Ve(e,t){const n=t.get(e.newId);if(void 0===n||1!==n.length)return;const r=n[0];return{rename:{type:"rename",oldPath:r.oldPath,newPath:e.newPath,oldId:r.oldId,newId:e.newId,oldMode:r.oldMode,newMode:e.newMode,similarity:{score:We,maxScore:We}},consumedDelete:r}}function Ke(e,t,n){if("ours-only"===t.kind){for(let r=t.oursStart;r<t.oursEnd;r++)if(!_e(e.oursLines[r],n))return!0;return!1}for(let r=t.theirsStart;r<t.theirsEnd;r++)if(!_e(e.theirsLines[r],n))return!0;return!1}function Ge(e,t,n){return"theirs-only"!==t.kind?0:void 0===n||Ke(e,t,n)?t.theirsEnd-t.theirsStart:0}function Ye(e,t,n){return"ours-only"!==t.kind?0:void 0===n||Ke(e,t,n)?t.oursEnd-t.oursStart:0}const qe=(e,t,n)=>{const r=n?.numstatBinaryOverride;if("binary"===r||void 0===r&&(Me(e)||Me(t)))return{added:0,deleted:0,binary:!0};const o=n?.lineKey,s=Be(e,t,void 0!==o?{lineKey:o}:void 0),i=!0===n?.ignoreBlankLines?o??Oe:void 0;let a=0,c=0;for(const e of s.hunks)a+=Ge(s,e,i),c+=Ye(s,e,i);return{added:a,deleted:c,binary:!1}};function Xe(e){return{type:"add",newPath:e.name,newId:e.id,newMode:e.mode}}function Je(e){return{type:"delete",oldPath:e.name,oldId:e.id,oldMode:e.mode}}function Qe(e,t){if(e.id!==t.id||e.mode!==t.mode)return Ie(e.mode,t.mode)?{type:"modify",path:e.name,oldId:e.id,newId:t.id,oldMode:e.mode,newMode:t.mode}:{type:"type-change",path:e.name,oldId:e.id,newId:t.id,oldMode:e.mode,newMode:t.mode}}function Ze(e){return void 0===e?[]:ae(e.entries)}function et(e,t){const n=Ze(e),r=Ze(t),o=[];let s=0,i=0;for(;s<n.length&&i<r.length;){const e=n[s],t=r[i],a=ce(e,t);if(a<0)o.push(Je(e)),s++;else if(a>0)o.push(Xe(t)),i++;else{const n=Qe(e,t);void 0!==n&&o.push(n),s++,i++}}for(;s<n.length;)o.push(Je(n[s])),s++;for(;i<r.length;)o.push(Xe(r[i])),i++;return{changes:o}}const tt=(e,t,n)=>{const r=((e,t,n)=>{let r;for(let o=0;o<e.length;o+=1){const s=e[o];s.directoryOnly&&!n||s.compiled.test(t)&&(r={rule:s,index:o})}return r})(e,t,n);return void 0===r?{verdict:"unset"}:{verdict:r.rule.negated?"unignored":"ignored",ruleIndex:r.index}},nt=(e,t)=>{if(""===t)return e;const n=`${t}/`;return e.startsWith(n)?e.slice(n.length):void 0},rt=(e,t,n)=>{let r={verdict:"unset"};for(const o of e){const e=nt(t,o.basedir);if(void 0===e)continue;const s=tt(o.rules,e,n);void 0!==s.ruleIndex&&(r={verdict:s.verdict,level:o,ruleIndex:s.ruleIndex})}return r},ot={kind:"star-slash"},st=(e,t)=>{const n=e[t];return"*"===n?((e,t)=>{if("*"!==e[t+1])return{token:{kind:"star"},next:t+1};const n=t+2;return"/"===e[n]?{token:{kind:"star-slash"},next:n+1}:{token:{kind:"star-star"},next:n}})(e,t):"?"===n?{token:{kind:"single"},next:t+1}:{token:{kind:"literal",char:n},next:t+1}},it=(e,t,n)=>{switch(e.kind){case"literal":return((e,t,n)=>{const r=new Uint8Array(t.length+1);for(let o=0;o<t.length;o++)t[o]===e&&1===n[o+1]&&(r[o]=1);return r})(e.char,t,n);case"single":return((e,t)=>{const n=new Uint8Array(e.length+1);for(let r=0;r<e.length;r++)"/"!==e[r]&&1===t[r+1]&&(n[r]=1);return n})(t,n);case"star":return((e,t)=>{const n=new Uint8Array(e.length+1);n[e.length]=1===t[e.length]?1:0;for(let r=e.length-1;r>=0;r--)n[r]=1===t[r]||"/"!==e[r]&&1===n[r+1]?1:0;return n})(t,n);case"star-star":return((e,t)=>{const n=new Uint8Array(e.length+1);n[e.length]=1===t[e.length]?1:0;for(let r=e.length-1;r>=0;r--)n[r]=1===t[r]||1===n[r+1]?1:0;return n})(t,n);case"star-slash":return((e,t)=>{const n=new Uint8Array(e.length+1);for(let r=e.length-1;r>=0;r--)n[r]="/"===e[r]&&1===t[r+1]||1===n[r+1]?1:0;const r=new Uint8Array(e.length+1);for(let o=0;o<=e.length;o++)r[o]=1===t[o]||1===n[o]?1:0;return r})(t,n)}},at=(e,t)=>{const n=(e=>{const t=[];let n=0;for(;n<e.length;){const r=st(e,n);t.push(r.token),n=r.next}return t})(e);return{test:e=>((e,t,n)=>{let r=((e,t)=>{const n=new Uint8Array(e.length+1);if(n[e.length]=1,t)for(let t=0;t<e.length;t++)"/"===e[t]&&(n[t]=1);return n})(n,!0===t.withDirSuffix);for(let t=e.length-1;t>=0;t--)r=it(e[t],n,r);return t.anchored||(r=it(ot,n,r)),1===r[0]})(n,t,e)}},ct=e=>{let t=e.length;for(;t>0&&32===e.charCodeAt(t-1)&&!(t>=2&&92===e.charCodeAt(t-2));)t-=1;return e.slice(0,t)},dt=e=>e.replace(/\\(.)/g,"$1"),ut=e=>{if(""===e)return;if(/^\s*$/.test(e))return;if(e.startsWith("#"))return;const t=ct(e),n=t.startsWith("!"),r=n?t.slice(1):t,o=r.endsWith("/"),s=o?r.slice(0,-1):r,i=s.startsWith("/")||s.includes("/"),a=s.startsWith("/")?s.slice(1):s;return{negated:n,anchored:i,directoryOnly:o,cleanPattern:dt(a)}},lt="agent=tsgit/0.0",ft=["multi_ack_detailed","side-band-64k","ofs-delta","thin-pack","no-progress","include-tag","filter",lt],ht=["report-status","side-band-64k","ofs-delta","atomic","delete-refs",lt],pt=e=>{const t=e.indexOf("=");return t<0?e:e.slice(0,t)},wt=t=>new e.TsgitError({code:"PKT_LENGTH_RESERVED",value:t}),gt=t=>new e.TsgitError({code:"PKT_TOO_LARGE",value:t}),mt=t=>new e.TsgitError({code:"INVALID_BASE_URL",reason:t}),yt=(t,n)=>new e.TsgitError({code:"MISSING_SERVICE_HEADER",expected:t,actual:n}),vt=t=>new e.TsgitError({code:"INVALID_REF_LINE",line:t}),xt=t=>new e.TsgitError({code:"INVALID_SIDEBAND_CHANNEL",channel:t}),bt=t=>new e.TsgitError({code:"SIDEBAND_FATAL",message:t}),kt=(t,n)=>new e.TsgitError({code:"TOO_MANY_ADVERTISED_REFS",count:t,limit:n}),Et=new TextEncoder,It=new TextDecoder("utf-8",{fatal:!1}),Tt=/^[0-9a-f]{4}$/i,Ct=65520,Lt=Et.encode("0000");Et.encode("0001"),Et.encode("0002");const St=e=>{const t=(e+65536).toString(16).slice(-4);return Et.encode(t)},$t=e=>{let t=Lt.byteLength;for(const n of e){if(n.byteLength>65516)throw new RangeError(`pkt-line: payload too large (${n.byteLength} > 65516)`);t+=n.byteLength+4}const n=new Uint8Array(t);let r=0;for(const t of e)n.set(St(t.byteLength+4),r),r+=4,n.set(t,r),r+=t.byteLength;return n.set(Lt,r),n},At=t=>{const n=It.decode(t.subarray(0,4));if(!Tt.test(n))throw new e.TsgitError({code:"INVALID_PKT_LENGTH",value:n});const r=Number.parseInt(n,16);if(r>Ct)throw gt(r);return r},Dt=(t,n)=>({[Symbol.asyncIterator]:()=>async function*(t){const n=new _t;for await(const e of t)n.accept(e),yield*Ut(n);if(n.used>0)throw new e.TsgitError({code:"PKT_TRUNCATED",remaining:n.used})}(t)}),Ot=(e,t,n)=>{if(0===e)return{kind:"flush",consume:4};if(1===e)throw wt(1);if(2===e)throw wt(2);if(e<4)throw wt(e);return t<e?{kind:"wait"}:{kind:"data",consume:e}};class _t{acc=new Uint8Array(Ct);used=0;accept(e){if(this.used+e.byteLength<=Ct)return this.acc.set(e,this.used),void(this.used+=e.byteLength);const t=Math.max(0,4-this.used),n=e.subarray(0,t);throw this.acc.set(n,this.used),this.used+=n.byteLength,At(this.acc),gt(this.used)}drop(e){this.acc.copyWithin(0,e,this.used),this.used-=e}slice(e,t){return this.acc.slice(e,t)}}function*Ut(e,t){for(;e.used>=4;){const t=At(e.acc),n=Ot(t,e.used);if("wait"===n.kind)return;if("data"===n.kind){const t=e.slice(4,n.consume);e.drop(n.consume),yield{kind:"data",payload:t};continue}e.drop(n.consume),yield{kind:n.kind}}}const Nt=new TextDecoder("utf-8",{fatal:!1}),Mt=(e,t)=>{if(e)try{e(t)}catch{}},Rt=(e,t)=>({[Symbol.asyncIterator]:()=>async function*(e,t){for await(const n of e){if("data"!==n.kind)return;if(0===n.payload.byteLength)throw xt(-1);const e=n.payload[0],r=n.payload.subarray(1);if(1!==e){if(2!==e){if(3===e){const e=Nt.decode(r);throw Mt(t.onError,e),bt(e)}throw xt(e)}Mt(t.onProgress,Nt.decode(r))}else yield r}}(e,t)}),Pt=new TextDecoder("utf-8",{fatal:!1}),Ft=new TextEncoder,Bt=/^[0-9a-f]{40}([0-9a-f]{24})?$/i,Wt=/^# service=(?<service>[^\n]+)\n?$/,jt=5e5,zt=e=>e.endsWith("\n")?e.slice(0,-1):e,Ht=e=>{if(!Bt.test(e))throw vt(e);return J.from(e)},Vt=e=>{const t=e.indexOf(" ");if(t<0)throw vt(e);const n=e.slice(0,t),r=e.slice(t+1);if(0===r.length)throw vt(e);return{id:n,name:r}},Kt=(t,n,r)=>{if(t.byName.has(n))throw(t=>new e.TsgitError({code:"DUPLICATE_REF",name:t}))(n);t.refs.push({id:r,name:n}),t.byName.set(n,t.refs.length-1)},Gt=(t,n,r)=>{if(void 0===n){const n=(t=>{const n=t.indexOf("\0");if(n<0)throw new e.TsgitError({code:"MISSING_CAPABILITIES"});const r=t.slice(0,n),o=t.slice(n+1),s=r.indexOf(" ");if(s<0)throw vt(t);const i=r.slice(0,s),a=r.slice(s+1);if(0===a.length)throw vt(t);return{id:i,name:a,tail:o}})(r);return Kt(t,n.name,Ht(n.id)),(e=>{const t=new Map;for(const n of e)t.set(pt(n),n);return Array.from(t.values())})(n.tail.split(" ").filter(e=>e.length>0))}if(r.endsWith("^{}"))return((e,t)=>{const n=t.slice(0,-3),r=Vt(n),o=Ht(r.id),s=e.byName.get(r.name);if(void 0===s)throw vt(t);e.refs[s]={...e.refs[s],peeled:o}})(t,r),n;const o=Vt(r);return Kt(t,o.name,Ht(o.id)),n},Yt=e=>Ft.encode(`have ${e}\n`),qt=(e=>{if(e.byteLength>65516)throw new RangeError(`pkt-line: payload too large (${e.byteLength} > 65516)`);const t=e.byteLength+4,n=new Uint8Array(t);return n.set(St(t),0),n.set(e,4),n})(Ft.encode("done\n")),Xt=t=>{const n=zt(t).split(" "),r=J.from(n[1]),o=n[2];if(void 0===o)return{id:r,status:"ack"};if("continue"===o||"common"===o||"ready"===o)return{id:r,status:o};throw new e.TsgitError({code:"UNKNOWN_ACK_STATUS",value:o})},Jt="shallow ",Qt="unshallow ",Zt=(e,t)=>{const n=zt(e),r=n.slice(t.length);if(!Bt.test(r))throw vt(n);return J.from(r)},en=(e,t)=>e.startsWith(Jt)?(t.shallow.push(Zt(e,Jt)),!0):!!e.startsWith(Qt)&&(t.unshallow.push(Zt(e,Qt)),!0),tn=new WeakMap,nn=t=>new e.TsgitError({code:"INVALID_REFLOG_ENTRY",reason:t}),rn=/[\n\r]/;function on(e){if(rn.test(e.message))throw nn("message contains a line break");const t=Y(e.identity),n=`${e.oldId} ${e.newId} ${t}`;return""===e.message?`${n}\n`:`${n}\t${e.message}\n`}function sn(e){const t=e.indexOf("\t"),n=-1===t?e:e.slice(0,t),r=-1===t?"":e.slice(t+1);if(" "!==n[40]||" "!==n[81])throw nn("misplaced field separator");return{oldId:cn(n.slice(0,40)),newId:cn(n.slice(41,81)),identity:function(e){try{return K(e)}catch{throw nn("invalid identity")}}(n.slice(82)),message:r}}function an(e){return e.replace(/[\r\n]+/g," ").trim()}function cn(e){try{return J.from(e)}catch{throw nn("invalid object id")}}const dn=["refs/heads/","refs/remotes/","refs/notes/"];const un=t=>new e.TsgitError({code:"INVALID_REF",reason:t}),ln=t=>new e.TsgitError({code:"INVALID_PACKED_REFS",reason:t}),fn=t=>new e.TsgitError({code:"REF_NOT_FOUND",name:t}),hn=(t,n)=>new e.TsgitError({code:"REF_CHAIN_TOO_DEEP",depth:t,chain:n}),pn=t=>new e.TsgitError({code:"REF_CYCLE_DETECTED",chain:t}),wn=t=>new e.TsgitError({code:"REF_LOCKED",name:t}),gn=new Set(["~","^",":","?","*","[","\\"," "]);function mn(e){if(""===e)throw un("ref name must not be empty");if(e.startsWith("/")||e.endsWith("/"))throw un("ref name must not start or end with /");if(e.startsWith("-"))throw un("ref name must not start with -");if("@"===e)throw un("ref name must not be single @");if(e.includes(".."))throw un("ref name must not contain ..");if(e.includes("//"))throw un("ref name must not contain consecutive slashes");if(e.includes("@{"))throw un("ref name must not contain @{");if(e.endsWith("."))throw un("ref name must not end with .");!function(e){for(let t=0;t<e.length;t++){const n=e.charCodeAt(t);if(n<=31||127===n)throw un("ref name contains forbidden character");const r=e[t];if(void 0!==r&&gn.has(r))throw un("ref name contains forbidden character");if(n>=8234&&n<=8238||n>=8294&&n<=8297)throw un("ref name contains forbidden Unicode override")}}(e);const t=e.split("/");for(const e of t){if(e.startsWith("."))throw un("ref name component must not start with .");if(e.endsWith(".lock"))throw un("ref name component must not end with .lock")}return e}function yn(e){const t=e.replace(/[\r\n]+$/,"");if(""===t)throw un("empty ref content");if(t.startsWith("ref: ")){const e=t.slice(5);if(""===e)throw un("empty symbolic ref target");return{type:"symbolic",target:mn(e)}}return{type:"direct",target:J.from(t)}}const vn=new Set(["HEAD","ORIG_HEAD","FETCH_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REVERT_HEAD","BISECT_HEAD"]),xn=["refs/bisect/","refs/worktree/","refs/rewritten/"],bn=e=>{const t=e.split("/"),n=[];for(let e=t.length-1;e>0;e-=1)n.push(t.slice(0,e).join("/"));return n},kn=e=>{const t=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");for(const n of t.split("/"))En(n,e);return t},En=(t,n)=>{const r=n.slice(0,128);if(""===t||"."===t||".."===t)throw e.invalidOption("patterns",`cone directory has an invalid segment: ${r}`);if(t.includes("*")||t.includes("?"))throw e.invalidOption("patterns",`cone directory must not contain glob metacharacters: ${r}`);if(/[\n\r\0]/.test(t))throw e.invalidOption("patterns",`cone directory must not contain control characters: ${r}`)},In=e=>{if(!e.startsWith("/")||!e.endsWith("/"))return;const t=e.slice(1,-1);return""===t||t.startsWith("!")?void 0:t},Tn=(e,t)=>{const n=(e=>{if(e.directoryOnly)return!0;const t=e.cleanPattern.split("/"),n=t[t.length-1];return!n.includes("*")&&!n.includes("?")})(e);return{source:t,negated:e.negated,matcher:at(e.cleanPattern,{anchored:e.anchored,withDirSuffix:n})}},Cn=new TextEncoder,Ln=t=>{const n=t.split("\n").map(e=>e.replace(/\r$/,"")),r=[];for(const t of n){if(Cn.encode(t).byteLength>256)throw e.invalidOption("patterns","pattern exceeds max length 256 bytes");const n=ut(t);if(void 0!==n){if(r.length>=2048)throw e.invalidOption("patterns","pattern file exceeds max 2048 patterns");r.push(Tn(n,t))}}return r},Sn=(e,t)=>{if(t){const t=(e=>{const t=e.split("\n").map(e=>e.replace(/\r$/,""));if("/*"!==t[0]||"!/*/"!==t[1])return;const n=new Set,r=new Set;let o=2;for(;o<t.length;){const e=t[o];if(""===e){o+=1;continue}const s=In(e);if(void 0===s)return;o+=1,t[o]===`!/${s}/*/`?(r.add(s),o+=1):n.add(s)}return{mode:"cone",recursive:n,parents:r}})(e);return void 0!==t?{spec:t,degraded:!1}:{spec:{mode:"no-cone",rules:Ln(e)},degraded:!0}}return{spec:{mode:"no-cone",rules:Ln(e)},degraded:!1}},$n=e=>{return"cone"===e.mode?(e=>t=>{const n=(e=>{const t=e.lastIndexOf("/");return-1===t?"":e.slice(0,t)})(t);if(""===n)return!0;if(e.parents.has(n))return!0;let r=n;for(;;){if(e.recursive.has(r))return!0;const t=r.lastIndexOf("/");if(-1===t)return!1;r=r.slice(0,t)}})(e):(t=e.rules,e=>{let n=!1;for(const r of t)r.matcher.test(e)&&(n=!r.negated);return n});var t},An=t=>new e.TsgitError({code:"INVALID_PACK_HEADER",reason:t}),Dn=t=>new e.TsgitError({code:"INVALID_PACK_INDEX",reason:t}),On=(t,n)=>new e.TsgitError({code:"INVALID_PACK_ENTRY",offset:t,reason:n}),_n=t=>new e.TsgitError({code:"INVALID_DELTA",reason:t}),Un=t=>new e.TsgitError({code:"DELTA_CHAIN_TOO_DEEP",depth:t});function Nn(e,t){if(t>=e.length)throw _n("truncated variable-length integer");let n=0,r=0,o=t,s=0,i=e[o];for(n=(127&i)<<r>>>0,r+=7,s+=1;128&i;){if(s>=5)throw _n("variable-length integer too long");if(o+=1,o>=e.length)throw _n("truncated variable-length integer");i=e[o],n=(n|(127&i)<<r)>>>0,r+=7,s+=1}return{value:n,nextOffset:o+1}}function Mn(e,t,n){const r=function(e){let t=0;return 1&e&&(t+=1),2&e&&(t+=1),4&e&&(t+=1),8&e&&(t+=1),16&e&&(t+=1),32&e&&(t+=1),64&e&&(t+=1),t}(n);if(t+r>e.length)throw _n(`COPY instruction truncated: needs ${r} bytes at position ${t}`);let o=t,s=0,i=0;return 1&n&&(s|=e[o],o+=1),2&n&&(s|=e[o]<<8,o+=1),4&n&&(s|=e[o]<<16,o+=1),8&n&&(s=(s|16777216*e[o])>>>0,o+=1),16&n&&(i|=e[o],o+=1),32&n&&(i|=e[o]<<8,o+=1),64&n&&(i|=e[o]<<16,o+=1),0===i&&(i=65536),{offset:s,size:i,nextPos:o}}function Rn(e,t,n,r,o){if(e+t>n)throw _n(`COPY out of bounds: offset=${e} size=${t} exceeds base length ${n}`);if(r+t>o)throw _n(`COPY overflows target: position=${r} size=${t} exceeds target length ${o}`)}function Pn(e,t,n,r,o,s){if(0===n)throw _n("INSERT with N=0 is reserved");if(t+n>e.length)throw _n(`INSERT data truncated: needs ${n} bytes at position ${t}`);if(o+n>s)throw _n(`INSERT overflows target: position=${o} size=${n} exceeds target length ${s}`);return r.set(e.subarray(t,t+n),o),{nextPos:t+n,nextResultPos:o+n}}function Fn(e,t){const{value:n,nextOffset:r}=Nn(t,0),{value:o,nextOffset:s}=Nn(t,r);!function(e,t,n){if(e.length!==t)throw _n(`source length mismatch: expected ${t}, got ${e.length}`);if(n>2147483648)throw _n(`target length ${n} exceeds maximum allowed size`)}(e,n,o);const i=new Uint8Array(o);let a=0,c=s;for(;c<t.length;){const n=t[c];if(c+=1,128&n){const{offset:r,size:s,nextPos:d}=Mn(t,c,n);c=d,Rn(r,s,e.length,a,o),i.set(e.subarray(r,r+s),a),a+=s}else{const e=Pn(t,c,n,i,a,o);c=e.nextPos,a=e.nextResultPos}}if(a!==o)throw _n(`underfill: produced ${a} bytes but target length is ${o}`);return i}const Bn=1346454347;function Wn(e,t,n){const{type:r,size:o,nextPos:s}=function(e,t){if(t>=e.length)throw On(t,"unexpected end of header");let n=t;const r=e[n],o=r>>4&7;let s=15&r,i=4,a=0;for(;128&e[n];){if(a+=1,a>5)throw On(t,"size encoding too long");if(n+=1,n>=e.length)throw On(t,"unexpected end of header");s|=(127&e[n])<<i,i+=7}return{type:o,size:s,nextPos:n+1}}(e,t);if(function(e,t){if(5===e)throw On(t,"reserved type 5");if(e<1||e>7)throw On(t,`unknown type ${e}`)}(r,t),6===r){const{distance:n,nextPos:r}=function(e,t,n){if(t>=e.length)throw On(n,"unexpected end of OFS_DELTA distance");let r=t,o=127&e[r],s=0;for(;128&e[r];){if(s+=1,s>4)throw On(n,"OFS_DELTA distance encoding too long");if(r+=1,r>=e.length)throw On(n,"unexpected end of OFS_DELTA distance");o=o+1<<7|127&e[r]}return{distance:o,nextPos:r+1}}(e,s,t);return{type:6,size:o,dataOffset:r,baseDistance:n}}if(7===r){const r=s+n.digestLength;if(r>e.length)throw On(t,"unexpected end of REF_DELTA base id");return{type:7,size:o,dataOffset:r,baseId:O(e.subarray(s,r))}}return{type:r,size:o,dataOffset:s}}function jn(e,t){const n=[];let r=(7&e)<<4|15&t,o=t>>>4;for(o>0&&(r|=128),n.push(r);o>0;){let e=127&o;o>>>=7,o>0&&(e|=128),n.push(e)}return new Uint8Array(n)}const zn=1032,Hn=20;function Vn(e,t){return e._view.getUint32(8+4*t)}function Kn(e,t,n){const r=zn+t*Hn;return N(e._bytes.subarray(r,r+Hn),n)}function Gn(e,t){const n=e._view.getUint32(e.smallOffsetsTableOffset+4*t);if(2147483648&n){const t=2147483647&n,r=e.largeOffsetsTableOffset+8*t;if(r+8>e.trailerOffset)throw Dn(`large offset index ${t} out of range`);const o=e._view.getUint32(r),s=e._view.getUint32(r+4);if(o>2097151)throw Dn(`pack offset exceeds safe JavaScript number range: high word=${o}`);return 4294967296*o+s}return n}function Yn(e,t){const n=_(t),r=n[0];let o=0===r?0:Vn(e,r-1),s=Vn(e,r);for(;o<s;){const t=o+s>>>1,r=Kn(e,t,n);if(r<0)o=t+1;else{if(!(r>0))return Gn(e,t);s=t}}}const qn=/^[0-9a-f]+$/;function Xn(e){const t=[];for(let n=0;n<e.objectCount;n++){const r=zn+n*Hn,o=e._bytes.subarray(r,r+Hn);t.push(O(o))}return t}function Jn(e,t){const n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}function Qn(e){const t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}const Zn=e=>e.layout.commonDir??e.layout.gitDir,er=(e,t)=>(e=>vn.has(e)||xn.some(t=>e.startsWith(t)))(t)?e.layout.gitDir:Zn(e),tr=(e,t)=>`${e}/objects/${function(e){return`${e.slice(0,2)}/${e.slice(2)}`}(t)}`,nr=(e,t)=>`${e}/${t}`,rr=e=>`${e}/index`,or=(e,t)=>`${e}/objects/${t}`,sr=(e,t)=>`${e}/logs/${t}`,ir=e=>`${e}/info/sparse-checkout`,ar=".lock";async function cr(e,t,n,r){const o=`${n}${ar}`;try{await e.fs.writeExclusive(o,r)}catch(e){if(dr(e))throw wn(t);throw e}try{await e.fs.rename(o,n)}catch(t){try{await e.fs.rm(o)}catch(e){if(!ur(e))throw e}throw t}}function dr(t){return t instanceof e.TsgitError&&"FILE_EXISTS"===t.data.code}function ur(t){return t instanceof e.TsgitError&&"FILE_NOT_FOUND"===t.data.code}let lr=new WeakMap;const fr=e=>hr(e).then(e=>e.parsed),hr=e=>{const t=lr.get(e);if(void 0!==t)return t;const n=wr(e);return lr.set(e,n),n},pr=e=>{lr.delete(e)},wr=async e=>{const t=`${Zn(e)}/config`,n=await gr(e,t);if(void 0===n)return{parsed:{},tokens:[],source:t};const r=Tr(n,t);return{parsed:Jr(Ur(r)),tokens:r,source:t}},gr=async(t,n)=>{try{return await t.fs.readUtf8(n)}catch(t){if(t instanceof e.TsgitError&&"FILE_NOT_FOUND"===t.data.code)return;throw t}},mr=(e,t,n,r)=>e.toLowerCase()===n.toLowerCase()&&t===r,yr=async(e,t,n,r)=>{const{tokens:o,source:s}=await hr(e),i=new Set(r.map(e=>e.toLowerCase()));let a=!1;for(const e of o){if("header"===e.kind){a=mr(e.section,e.subsection,t,n);continue}if(!a||"entry"!==e.kind||null!==e.value)continue;const r=e.key.toLowerCase();if(!i.has(r))continue;const o=t.toLowerCase();return{key:void 0===n?`${o}.${r}`:`${o}.${n}.${r}`,source:s,line:e.startLine+1}}},vr=new Set(["loosecompression","compression"]),xr=e=>e>="a"&&e<="z"||e>="A"&&e<="Z",br=e=>xr(e)||e>="0"&&e<="9"||"-"===e,kr=e=>" "===e||"\t"===e,Er=(t,n,r,o)=>{const s=t[n];if(r>=s.length||!xr(s[r]))throw e.configParseError(n+1,o);let i=r+1;for(;i<s.length&&br(s[i]);)i+=1;const a=s.slice(r,i);for(;i<s.length&&kr(s[i]);)i+=1;const c={key:a,value:null,nextLineIdx:n+1};if(i>=s.length)return c;const d=s[i];if("\r"===d&&i===s.length-1)return c;if("="!==d)throw e.configParseError(n+1,o);const u=Rr(t,n,i+1,o);return{key:a,value:u.value,nextLineIdx:u.nextLineIdx}},Ir=(e,t)=>{let n=t;for(;n<e.length&&kr(e[n]);)n+=1;return n},Tr=(e,t)=>Cr(e.split("\n"),e.endsWith("\n"),t),Cr=(e,t,n)=>{const r=[],o=t?e.length-1:e.length;let s=0;for(;s<o;)s=Lr(r,e,s,n);return r},Lr=(t,n,r,o)=>{const s=n[r];if(""===jr(s).trim())return t.push(""===s.trim()?{kind:"blank",line:r}:{kind:"comment",line:r}),r+1;const i=Hr(s);if("header"===i.parse.kind)return $r(t,n,r,i,o);if("malformed"===i.parse.kind)throw e.configParseError(r+1,o,i.parse.partialName);return Sr(t,n,r,o)},Sr=(e,t,n,r)=>{const o=Ir(t[n],0),s=Er(t,n,o,r);return e.push({kind:"entry",key:s.key,value:s.value,startLine:n,endLine:s.nextLineIdx}),s.nextLineIdx},$r=(t,n,r,o,s)=>{const i=n[r];let a=o,c=Or(i,a.endOffset);for(;"["===i[c];){if(Ar(t,a,r,!1),a=Hr(i,c),"header"!==a.parse.kind)throw e.configParseError(r+1,s,Dr(a.parse));c=Or(i,a.endOffset)}const d=i[c],u="#"===d||";"===d;if(Ar(t,a,r,u),c>=i.length||u)return r+1;const l=Er(n,r,c,s);return t.push({kind:"entry",key:l.key,value:l.value,startLine:r,endLine:l.nextLineIdx,sharesHeaderLine:!0,startCol:c}),l.nextLineIdx},Ar=(e,t,n,r)=>{const o=t.parse;e.push({kind:"header",section:o.section,subsection:o.subsection,line:n,hasComment:r})},Dr=e=>"malformed"===e.kind?e.partialName:void 0,Or=(e,t)=>{let n=t;for(;n<e.length&&Mr.has(e[n]);)n+=1;return n},_r=(e,t)=>Ur(Tr(e,t)),Ur=e=>{const t=[],n={section:"",subsection:void 0,entries:[]};let r=n;for(const n of e)"header"===n.kind?(r={section:n.section,subsection:n.subsection,entries:[]},t.push(r)):"entry"===n.kind&&r.entries.push({key:n.key,value:n.value});return n.entries.length>0?[n,...t]:t},Nr=new Map([["n","\n"],["t","\t"],["b","\b"],["\\","\\"],['"','"']]),Mr=new Set([" ","\t","\r"]),Rr=(t,n,r,o)=>{const s={lineIdx:n,col:r},i={out:"",trimLen:-1,inQuotes:!1,inComment:!1};for(;s.lineIdx<t.length;){if(s.col>=t[s.lineIdx].length){if(i.inQuotes)throw e.configParseError(s.lineIdx+1,o);return Wr(i,s.lineIdx+1)}Pr(t,s,i,o)}return Wr(i,s.lineIdx)},Pr=(e,t,n,r)=>{const o=e[t.lineIdx][t.col];if(t.col+=1,!n.inComment)if(n.inQuotes||!Mr.has(o))if(n.inQuotes||"#"!==o&&";"!==o)if("\\"!==o){if('"'===o)return n.inQuotes=!n.inQuotes,void(n.trimLen=-1);n.out+=o,n.trimLen=-1}else Fr(e,t,n,r);else n.inComment=!0;else Br(n,o)},Fr=(t,n,r,o)=>{const s=t[n.lineIdx];if(n.col>=s.length)return n.lineIdx+=1,void(n.col=0);const i=Nr.get(s[n.col]);if(void 0===i)throw e.configParseError(n.lineIdx+1,o);n.col+=1,r.out+=i,r.trimLen=-1},Br=(e,t)=>{""!==e.out&&(-1===e.trimLen&&(e.trimLen=e.out.length),e.out+=t)},Wr=(e,t)=>({value:-1===e.trimLen?e.out:e.out.slice(0,e.trimLen),nextLineIdx:t}),jr=e=>{const t=[zr(e,"#"),zr(e,";")].filter(e=>e>=0);return 0===t.length?e:e.slice(0,Math.min(...t))},zr=(e,t)=>{let n=!1;for(let r=0;r<e.length;r+=1){const o=e[r];if(n&&"\\"===o)r+=1;else if('"'===o)n=!n;else if(!n&&o===t)return r}return-1},Hr=(e,t=0)=>{const n=Ir(e,t);if("["!==e[n])return Kr;const r=n+1,o=e.indexOf("]",r),s=Vr(e,r,o);return-1===s?Yr(e,r,o):qr(e,r,s)},Vr=(e,t,n)=>{const r=-1===n?e.length:n;for(let n=t;n<r;n+=1)if('"'===e[n])return n;return-1},Kr={parse:{kind:"not-header"},endOffset:0},Gr=/^[A-Za-z0-9.-]+$/,Yr=(e,t,n)=>{if(-1===n)return Kr;const r=e.slice(t,n);return Gr.test(r)?{parse:{kind:"header",section:r,subsection:void 0},endOffset:n+1}:Kr},qr=(e,t,n)=>{const{parse:r,closeQuoteAt:o}=((e,t,n)=>{const r=e.slice(t,n).trim(),o=r.toLowerCase(),s=n>t?e[n-1]:void 0;return void 0!==s&&Mr.has(s)?((e,t,n,r)=>{const o=((e,t)=>{let n="",r=t+1;for(;r<e.length;){const t=e[r];if("\\"!==t){if('"'===t)return{subsection:n,closeQuoteAt:r};n+=t,r+=1}else{if(r+1>=e.length)return{partial:n};n+=e[r+1],r+=2}}return{partial:n}})(e,t);return"partial"in o?{parse:{kind:"malformed",partialName:`${r}.${o.partial}`}}:e.startsWith("]",o.closeQuoteAt+1)?{parse:{kind:"header",section:n,subsection:o.subsection},closeQuoteAt:o.closeQuoteAt}:{parse:{kind:"malformed",partialName:`${r}.${o.subsection}`}}})(e,n,r,o):{parse:{kind:"malformed",partialName:o}}})(e,t,n);return"header"!==r.kind||void 0===o?{parse:r,endOffset:0}:{parse:r,endOffset:o+2}},Xr=(e,t)=>{void 0!==t.subsection?((e,t,n)=>{"remote"===t.section?ro(e,n,t):"branch"===t.section?oo(e,n,t):"submodule"===t.section?so(e,n,t):"merge"===t.section?io(e,n,t):"diff"===t.section?ao(e,n,t):"filter"===t.section&&uo(e,n,t)})(e,t,t.subsection):"core"===t.section?Zr(e,t):"user"===t.section?to(e,t):"extensions"===t.section&&lo(e,t)},Jr=e=>{const t={};for(const n of e)Xr(t,n);return fo(t)},Qr=(e,t,n)=>"bare"===t?{...e,bare:po(n)}:"logallrefupdates"===t?{...e,logAllRefUpdates:eo(n)}:"sparsecheckout"===t?{...e,sparseCheckout:po(n)}:"sparsecheckoutcone"===t?{...e,sparseCheckoutCone:po(n)}:null!==n?"excludesfile"===t?{...e,excludesFile:n}:"attributesfile"===t?{...e,attributesFile:n}:"hookspath"===t?{...e,hooksPath:n}:"notesref"===t?{...e,notesRef:n}:"loosecompression"===t||"compression"===t?((e,t,n)=>{const r=yo(n);if(r.ok){if("loosecompression"===t)return{...e,looseCompression:r.value,looseCompressionFromLoose:!0};if(!0!==e.looseCompressionFromLoose)return{...e,looseCompression:r.value}}})(e,t,n):void 0:void 0,Zr=(e,t)=>{for(const{key:n,value:r}of t.entries){const t=Qr(e.core??{},n.toLowerCase(),r);void 0!==t&&(e.core=t)}},eo=e=>null!==e&&"always"===e.toLowerCase()?"always":po(e),to=(e,t)=>{for(const{key:n,value:r}of t.entries)null!==r&&("name"===n?e.user={...e.user,name:r}:"email"===n&&(e.user={...e.user,email:r}))},no=(e,t,n)=>{const r=t.toLowerCase();"url"===r?null!==n&&(e.url=n):"pushurl"===r?null!==n&&(e.pushUrl=n):"fetch"===r?null!==n&&(e.fetch??=[],e.fetch.push(n)):"promisor"===r?e.promisor=po(n):"partialclonefilter"===r&&null!==n&&(e.partialCloneFilter=n)},ro=(e,t,n)=>{e.remote??=new Map;const r=e.remote.get(t)??{},o={...r,fetch:r.fetch?[...r.fetch]:[]};for(const{key:e,value:t}of n.entries)no(o,e,t);e.remote.set(t,(e=>{const t={};return void 0!==e.url&&(t.url=e.url),void 0!==e.pushUrl&&(t.pushUrl=e.pushUrl),void 0!==e.fetch&&e.fetch.length>0&&(t.fetch=e.fetch),void 0!==e.promisor&&(t.promisor=e.promisor),void 0!==e.partialCloneFilter&&(t.partialCloneFilter=e.partialCloneFilter),t})(o))},oo=(e,t,n)=>{e.branch??=new Map;const r={...e.branch.get(t)??{}};for(const{key:e,value:t}of n.entries)null!==t&&("remote"===e?r.remote=t:"merge"===e&&(r.merge=t));e.branch.set(t,r)},so=(e,t,n)=>{e.submodule??=new Map;const r={...e.submodule.get(t)??{}};for(const{key:e,value:t}of n.entries){const n=e.toLowerCase();"url"===n?null!==t&&(r.url=t):"active"===n?r.active=po(t):"update"===n&&null!==t&&(r.update=t)}e.submodule.set(t,r)},io=(e,t,n)=>{e.merge??=new Map;const r={...e.merge.get(t)??{}};for(const{key:e,value:t}of n.entries){if(null===t)continue;const n=e.toLowerCase();"name"===n?r.name=t:"driver"===n?r.driver=t:"recursive"===n&&(r.recursive=t)}e.merge.set(t,r)},ao=(e,t,n)=>{e.diff??=new Map;const r={...e.diff.get(t)??{}};for(const{key:e,value:t}of n.entries){const n=e.toLowerCase();if("textconv"===n){if(null===t)continue;r.textconv=t}else"cachetextconv"===n&&(r.cachetextconv=po(t))}e.diff.set(t,r)},co=(e,t,n)=>{const r=t.toLowerCase();"required"!==r?null!==n&&("clean"===r?e.clean=n:"smudge"===r?e.smudge=n:"process"===r&&(e.process=n)):e.required=po(n)},uo=(e,t,n)=>{e.filter??=new Map;const r={...e.filter.get(t)??{}};for(const{key:e,value:t}of n.entries)co(r,e,t);e.filter.set(t,r)},lo=(e,t)=>{for(const{key:n,value:r}of t.entries)"partialclone"===n.toLowerCase()&&null!==r&&(e.extensions={...e.extensions,partialClone:r})},fo=e=>{const t={},n=(e=>{if(void 0!==e)return{...void 0!==e.bare?{bare:e.bare}:{},...void 0!==e.excludesFile?{excludesFile:e.excludesFile}:{},...void 0!==e.attributesFile?{attributesFile:e.attributesFile}:{},...void 0!==e.logAllRefUpdates?{logAllRefUpdates:e.logAllRefUpdates}:{},...void 0!==e.hooksPath?{hooksPath:e.hooksPath}:{},...void 0!==e.notesRef?{notesRef:e.notesRef}:{},...void 0!==e.sparseCheckout?{sparseCheckout:e.sparseCheckout}:{},...void 0!==e.sparseCheckoutCone?{sparseCheckoutCone:e.sparseCheckoutCone}:{},...void 0!==e.looseCompression?{looseCompression:e.looseCompression}:{}}})(e.core);return void 0!==n&&(t.core=n),void 0!==e.user?.name&&void 0!==e.user?.email&&(t.user={name:e.user.name,email:e.user.email}),void 0!==e.remote&&e.remote.size>0&&(t.remote=e.remote),void 0!==e.extensions&&(t.extensions=e.extensions),void 0!==e.branch&&e.branch.size>0&&(t.branch=e.branch),void 0!==e.submodule&&e.submodule.size>0&&(t.submodule=e.submodule),void 0!==e.merge&&e.merge.size>0&&(t.merge=e.merge),((e,t)=>{void 0!==e.diff&&e.diff.size>0&&(t.diff=e.diff),void 0!==e.filter&&e.filter.size>0&&(t.filter=e.filter)})(e,t),t},ho=new Set(["true","yes","on","1"]),po=e=>null===e||ho.has(e.toLowerCase()),wo=BigInt("9223372036854775807"),go=BigInt("-9223372036854775808"),mo=new Map([["k",BigInt(1024)],["K",BigInt(1024)],["m",BigInt(1024)*BigInt(1024)],["M",BigInt(1024)*BigInt(1024)],["g",BigInt(1024)*BigInt(1024)*BigInt(1024)],["G",BigInt(1024)*BigInt(1024)*BigInt(1024)]]),yo=e=>{const t=(e??"").replace(/^[ \t]+/,""),n="+"===t[0]||"-"===t[0]?t.slice(1):t,r=(e=>{const t=/^0[xX][0-9a-fA-F]+/.exec(e);if(null!==t)return{token:t[0],radix:16};if("0"===e[0])return{token:/^0[0-7]*/.exec(e)[0],radix:8};const n=/^[0-9]+/.exec(e);return null===n?null:{token:n[0],radix:10}})(n);if(null===r)return{ok:!1,reason:"invalid unit"};const o=n.slice(r.token.length),s=""===o?BigInt(1):mo.get(o);if(void 0===s)return{ok:!1,reason:"invalid unit"};const i=((e,t)=>{const n=(16===t?e.slice(2):8===t?e.slice(1):e).replace(/^0+/,"");return n.length>32?null:""===n?BigInt(0):BigInt(`${16===t?"0x":8===t?"0o":""}${n}`)})(r.token,r.radix);if(null===i)return{ok:!1,reason:"out of range"};const a=("-"===t[0]?-i:i)*s;return a<go||a>wo?{ok:!1,reason:"out of range"}:{ok:!0,value:Number(a)}};async function vo(e){const t=(await fr(e)).user;return{name:void 0===t?"tsgit":t.name,email:void 0===t?"tsgit@localhost":t.email,timestamp:Math.floor(Date.now()/1e3),timezoneOffset:"+0000"}}const xo=268435456,bo=1e6,ko=1048576;async function Eo(e,t,n){await e.fs.appendUtf8(sr(er(e,t),t),on(n))}async function Io(e,t){return e.fs.exists(sr(er(e,t),t))}async function To(e,t){const n=sr(er(e,t),t);await e.fs.exists(n)&&await e.fs.rm(n)}async function Co(e,t,n){const r=await e.fs.readdir(t),o=[];for(const s of r){const r=""===n?s.name:`${n}/${s.name}`;s.isDirectory?o.push(...await Co(e,`${t}/${s.name}`,r)):o.push(r)}return o}async function Lo(e,t,n,r,o){if(!await async function(e,t){if(await Io(e,t))return!0;return function(e,t){return"always"===t.logAllRefUpdates||!1!==t.logAllRefUpdates&&(!0===t.logAllRefUpdates||!0!==t.bare)&&function(e){return"HEAD"===e||dn.some(t=>e.startsWith(t))}(e)}(t,(await fr(e)).core??{})}(e,t))return;const s=await vo(e);await Eo(e,t,{oldId:n,newId:r,identity:s,message:an(o)})}const So=new WeakMap;function $o(e){let t=So.get(e);return void 0===t&&(t=function(e){let t;const n=t=>er(e,t);async function r(){const n=`${Zn(e)}/packed-refs`;if(!await e.fs.exists(n))return{entries:[],peeling:"none",sorted:!1};const r=await e.fs.stat(n),o=`${r.mtimeMs}:${r.size}`;if(void 0!==t&&t.mtimeKey===o)return t.parsed;const s=function(e){if(""===e)return{entries:[],peeling:"none",sorted:!1};const t=e.split("\n"),{peeling:n,sorted:r,startIndex:o}=function(e){const t=e[0];if(t?.startsWith("# pack-refs with:")){const e=t.slice(17).trim(),n=""===e?[]:e.split(/\s+/),r=n.includes("peeled");return{peeling:n.includes("fully-peeled")?"fully":r?"tags":"none",sorted:n.includes("sorted"),startIndex:1}}return{peeling:"none",sorted:!1,startIndex:0}}(t);return{entries:function(e,t){const n=[];for(let r=t;r<e.length;r++){const t=e[r];if(void 0===t||""===t||t.startsWith("#"))continue;if(t.startsWith("^")){if(0===n.length)throw ln("peel line without preceding ref entry");const e=J.from(t.slice(1)),r=n.length-1;n[r]={...n[r],peeled:e};continue}const o=t.indexOf(" ");if(-1===o)throw ln(`invalid ref line format: ${t.slice(0,80)}`);const s=t.slice(0,o),i=t.slice(o+1),a=J.from(s);n.push({name:Z.from(i),id:a})}return n}(t,o),peeling:n,sorted:r}}(await e.fs.readUtf8(n));return t={parsed:s,mtimeKey:o},s}async function o(t){const r=nr(n(t),t);if(await e.fs.exists(r))return e.fs.readUtf8(r)}return{async resolveDirect(e){const t=await o(e);if(void 0!==t){const e=yn(t);return"symbolic"===e.type?{kind:"symbolic",target:e.target}:{kind:"direct",id:e.target}}const n=await r();for(const t of n.entries)if(t.name===e)return{kind:"direct",id:t.id};return{kind:"missing"}},async writeLoose(t,r){const o=nr(n(t),t);await e.fs.writeUtf8(o,function(e){return`${e}\n`}(r))},async removeLoose(t){const r=nr(n(t),t);await e.fs.exists(r)&&await e.fs.rm(r)},isLoose:async t=>e.fs.exists(nr(n(t),t)),readLooseRaw:async e=>o(e),getPackedRefs:r}}(e),So.set(e,t)),t}const Ao="HEAD",Do=(e,t)=>e.endsWith("/")?`${e}${t}`:`${e}/${t}`,Oo=new Map([["binary",new Map([["diff",!1],["merge",!1],["text",!1]])]]),_o=(e,t)=>{const n=new Map;for(const[r,o]of e){const e=!0===o?t.get(r):void 0;if(n.set(r,o),void 0!==e)for(const[t,r]of e)n.set(t,r)}return n},Uo=e=>"t"===e?"\t":"n"===e?"\n":"r"===e?"\r":e,No=e=>{if(e.startsWith('"')){const{value:t,end:n}=(e=>{let t="",n=1;for(;n<e.length;){const r=e[n];if("\\"===r){const r=e[n+1];if(void 0===r)break;t+=Uo(r),n+=2;continue}if('"'===r){n+=1;break}t+=r,n+=1}return{value:t,end:n}})(e);return{pattern:t,rest:e.slice(n)}}const t=e.search(/\s/);return-1===t?{pattern:e,rest:""}:{pattern:e.slice(0,t),rest:e.slice(t)}},Mo=e=>e.split(/\s+/).filter(e=>""!==e),Ro=e=>{if(e.startsWith("-")){const t=e.slice(1);return""===t?void 0:{name:t,value:!1}}if(e.startsWith("!")){const t=e.slice(1);return""===t?void 0:{name:t,value:"unspecified"}}const t=e.indexOf("=");if(-1!==t){const n=e.slice(0,t);return""===n?void 0:{name:n,value:{set:e.slice(t+1)}}}return{name:e,value:!0}},Po=e=>{const t=new Map;for(const n of e){const e=Ro(n);void 0!==e&&t.set(e.name,e.value)}return t},Fo=(e,t,n)=>{const{anchored:r,directoryOnly:o,body:s}=(e=>{const t=e.endsWith("/"),n=t?e.slice(0,-1):e;return{anchored:n.includes("/"),directoryOnly:t,body:n.startsWith("/")?n.slice(1):n}})(e);return{pattern:e,anchored:r,directoryOnly:o,lineNumber:n,compiled:at(s,{anchored:r}),attributes:Po(Mo(t))}},Bo=e=>{const t=Mo(e),[n,...r]=t;if(void 0!==n)return{name:n,attributes:Po(r)}},Wo=(e,t,n,r)=>{const o=((e,t)=>{if(""===t)return e;const n=`${t}/`;return e.startsWith(n)?e.slice(n.length):void 0})(t,e.basedir);if(void 0===o)return;let s;for(const t of e.rules){if(!t.compiled.test(o))continue;const e=_o(t.attributes,r).get(n);void 0!==e&&(s=e)}return s},jo=(e,t,n,r)=>{for(const o of e){const e=Wo(o,t,n,r);if(void 0!==e)return e}return"unspecified"},zo=(e,t)=>{if("~"===t)return e.layout.homeDir;if(t.startsWith("~/")){if(void 0===e.layout.homeDir)return;return`${e.layout.homeDir}/${t.slice(2)}`}return t},Ho=async(t,n,r,o)=>{let s;try{s=await t.fs.lstat(n)}catch(t){if(t instanceof e.TsgitError&&"FILE_NOT_FOUND"===t.data.code)return;throw t}if(s.isFile&&!s.isSymbolicLink){if(s.size>r)throw o((e=>{const t=e.lastIndexOf("/");return-1===t?e:e.slice(t+1)})(n),s.size,r);return t.fs.readUtf8(n)}},Vo=async(t,n)=>{const r=await Ho(t,n,1048576,e.gitattributesFileTooLarge);return void 0===r?void 0:(e=>{const t=[],n=[],r=e.split("\n");for(let e=0;e<r.length;e+=1){const o=r[e].trim();if(""===o||o.startsWith("#"))continue;if(o.startsWith("[attr]")){const e=Bo(o.slice(6));void 0!==e&&n.push(e);continue}const{pattern:s,rest:i}=No(o);t.push(Fo(s,i,e+1))}return{rules:t,macros:n}})(r)},Ko=(e,t)=>Vo(e,Do(e.layout.workDir,""===t?".gitattributes":`${t}/.gitattributes`)),Go=async e=>{const t=await(e=>Vo(e,`${Zn(e)}/info/attributes`))(e),n=await(async e=>{const t=(await fr(e)).core?.attributesFile;if(void 0===t||""===t)return;const n=zo(e,t);return void 0!==n?Vo(e,n):void 0})(e),r=await Ko(e,""),o=((e,t=Oo)=>{const n=new Map(t);for(const t of e)n.set(t.name,t.attributes);return n})([...t?.macros??[],...r?.macros??[],...n?.macros??[]]),s=new Map([["",r]]),i=async t=>{if(s.has(t))return s.get(t);const n=await Ko(e,t);return s.set(t,n),n};return{sourcesForPath:async e=>{const r=[];void 0!==t&&r.push({basedir:"",rules:t.rules});for(const t of(e=>{const t=e.split("/");t.pop();const n=[];for(let e=t.length;e>=1;e-=1)n.push(t.slice(0,e).join("/"));return n.push(""),n})(e)){const e=await i(t);void 0!==e&&r.push({basedir:t,rules:e.rules})}return void 0!==n&&r.push({basedir:"",rules:n.rules}),{sources:r,macros:o}}}},Yo=async(e,t)=>{const n=le(t,e.hashConfig);return{bytes:n,id:await e.hash.hashHex(n)}},qo=new TextDecoder,Xo=async(e,t)=>{await e.fs.lstat(t).then(()=>!0).catch(()=>!1)&&await e.fs.rm(t)},Jo=async(e,t,n,r)=>{await Xo(e,t),await e.fs.write(t,n),void 0!==r&&await e.fs.chmod(t,r===p.EXECUTABLE?493:420)},Qo=async(e,t,n,r)=>{const o=Do(e.layout.workDir,t);if(r===p.SYMLINK)return await Xo(e,o),void await e.fs.symlink(qo.decode(n),o);r!==p.GITLINK?await Jo(e,o,n,r):await e.fs.mkdir(o)},Zo=async(e,t,n,r)=>{await Xo(e,t),await e.fs.writeStream(t,n),void 0!==r&&await e.fs.chmod(t,r===p.EXECUTABLE?493:420)},es="empty from",ts="too many seeds";function ns(e){return 0===e.length}function rs(e){return e.length>1024}function os(e){return!!(e.includes("\0")||e.includes("\r")||e.includes("\n\n")||e.startsWith("\n")||e.endsWith("\n"))}function ss(e){return 0===e.length||!!(e.includes("\0")||e.includes("\r")||e.includes("\n"))||!(!e.includes(" ")&&!e.includes("\t"))}const is="index file exceeds 256 MiB",as="pack .idx file exceeds 64 MiB";function cs(e){return e>268435456}function ds(e){return e>67108864}function us(e,t=5){return e>t}function ls(e,t=5){return e>t}function fs(e){return"160000"===e}function hs(e,t){return e>t}const ps=/^[0-9a-f]{40}$/,ws=/^[0-9a-f]{64}$/;function gs(e){return ps.test(e)||ws.test(e)}function ms(e){return e.isFile&&e.name.endsWith(".idx")&&!(t=e.name).includes("/")&&!t.includes("\\")&&!t.includes("..");var t}async function ys(e,t,n){const r=`${t}/${n}`,o=await async function(e,t){if(ds((await e.fs.stat(t)).size))throw Dn(as);const n=await e.fs.read(t);if(ds(n.length))throw Dn(as);return n}(e,r),s=function(e){if(e.length<1032)throw Dn("truncated: file too short for header and fanout");const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0);if(4285812579!==n)throw Dn(`invalid magic: expected 0xff744f63, got 0x${n.toString(16).padStart(8,"0")}`);const r=t.getUint32(4);if(2!==r)throw Dn(`unsupported version: expected 2, got ${r}`);!function(e){let t=0;for(let n=0;n<256;n++){const r=e.getUint32(8+4*n);if(r<t)throw Dn(`non-monotonic fanout at index ${n}: ${t} > ${r}`);t=r}}(t);const o=t.getUint32(1028),s=zn+o*Hn,i=s+4*o,a=i+4*o,c=e.length-40,d=zn+o*Hn+4*o+4*o+40;if(e.length<d)throw Dn(`truncated: expected at least ${d} bytes for ${o} objects, got ${e.length}`);return{objectCount:o,crc32TableOffset:s,smallOffsetsTableOffset:i,largeOffsetsTableOffset:a,trailerOffset:c,_bytes:e,_view:t}}(o),i=n.slice(0,-4),a=`${t}/${i}.pack`;let c;return{name:i,index:s,packPath:a,idxPath:r,offsetTable:async()=>{if(void 0!==c)return c;const t=(await e.fs.stat(a)).size,n=function(e){const t=[];for(let n=0;n<e.objectCount;n+=1)t.push(Gn(e,n));return t}(s),r=[...n].sort((e,t)=>e-t),o=t-e.hashConfig.digestLength;if(o<0)throw Dn("pack file too small to contain a trailer");return c={sortedOffsets:r,packFileSize:t,trailerStart:o},c}}}function vs(e,t){const{sortedOffsets:n,trailerStart:r}=e,o=function(e,t){let n=0,r=e.length;for(;n<r;){const o=n+r>>>1;e[o]<t?n=o+1:r=o}return n}(n,t);if(o>=n.length||n[o]!==t)throw Dn("offset not in pack index: corrupt index");return o===n.length-1?r:n[o+1]}function xs(e){let t;async function n(){if(void 0!==t)return t;const n=`${Zn(e)}/objects/pack`;if(!await e.fs.exists(n))return t=[],t;const r=await e.fs.readdir(n),o=[];for(const t of r)ms(t)&&o.push(await ys(e,n,t.name));return t=o,t}return{all:n,refresh(){t=void 0},async lookup(e){const t=await n();for(const n of t){const t=Yn(n.index,e);if(void 0!==t)return{pack:n,offset:t}}}}}async function bs(e,t,n,r,o){Is(e);const s=await async function(e,t){const n=tr(Zn(e),t);if(!await e.fs.exists(n))return;const r=await e.fs.read(n);return e.compressor.inflate(r)}(e,n);if(void 0!==s)return Is(e),function(e,t,n){if(void 0===n)return;const{contentOffset:r}=re(t),o=t.length-r;if(o>n)throw h(e,o,n)}(n,s,o),Cs(e,n,s,r);Is(e);const i=await t.lookup(n);if(void 0===i)throw c(n);Is(e);const a=await Ls(e,t,i,n,o);return Is(e),Cs(e,n,a,r)}function ks(e,t,n){if(void 0!==n&&t>n)throw h(e,t,n)}function Es(e,t,n,r){if(void 0===n)return;if(1!==r)return;const o=function(e){const{nextOffset:t}=Nn(e,0),{value:n}=Nn(e,t);return n}(t);if(o>n)throw h(e,o,n)}function Is(t){if(!0===t.signal?.aborted)throw e.operationAborted()}async function Ts(e,t){const n=tr(Zn(e),t);if(await e.fs.exists(n))return e.fs.read(n)}async function Cs(e,t,n,r){if(r){const r=await e.hash.hashHex(n);if(Is(e),r!==t)throw d(t,r)}return ue(t,n,e.hashConfig)}async function Ls(e,t,n,r,o){const s=await async function(e,t,n,r,o){const s=[];let i=n,a=0;const d=await n.pack.offsetTable();for(;;){Is(e);const n=vs(d,i.offset);if(n>d.packFileSize)throw Dn("next offset exceeds pack file size: corrupt index");const{header:u,chunk:l,headerEndInChunk:f}=await $s(e,i,n);if(Ss(u))return ks(r,u.size,o),{deltas:s,baseContent:await e.compressor.inflate(l.subarray(f)),baseType:u.type};if(a+=1,a>50)throw Un(a);const h=await e.compressor.inflate(l.subarray(f));if(Es(r,h,o,a),6===u.type){const e=i.offset-u.baseDistance;if(e<0)throw c(r);s.push({instructions:h,resolvedBaseId:void 0}),i={pack:i.pack,offset:e};continue}if(7===u.type){const n=u.baseId;s.push({instructions:h,resolvedBaseId:n});const r=await As(e,t,n,o);return{deltas:s,baseContent:r.content,baseType:r.type}}throw c(r)}}(e,t,n,r,o);let i=s.baseContent;for(let e=s.deltas.length-1;e>=0;e-=1){const t=s.deltas[e];if(void 0===t)break;i=Fn(i,t.instructions)}if(void 0!==o&&i.length>o)throw h(r,i.length,o);const a=function(e,t,n){const r=function(e,t){switch(e){case 1:return"commit";case 2:return"tree";case 3:return"blob";case 4:return"tag";default:throw c(t)}}(t,n),o=`${r} ${e.length}\0`,s=(new TextEncoder).encode(o),i=new Uint8Array(s.length+e.length);return i.set(s,0),i.set(e,s.length),i}(i,s.baseType,r);return _s(e.deltaCache,r,a),a}function Ss(e){return 1===e.type||2===e.type||3===e.type||4===e.type}async function $s(e,t,n){const r=n-t.offset;if(r<=0)throw Dn("slice length ≤ 0: next offset not beyond entry offset");const o=await e.fs.readSlice(t.pack.packPath,t.offset,r),s=Wn(o,0,e.hashConfig);return{header:s,chunk:o,headerEndInChunk:s.dataOffset}}async function As(e,t,n,r){const o=e.deltaCache.get(n);if(void 0!==o)return function(e,t,n){if(void 0===n)return;const r=t.indexOf(0);if(r<0)return;const o=t.length-(r+1);if(o>n)throw h(e,o,n)}(n,o,r),Ds(o,n);const s=le(await bs(e,t,n,!1,r),e.hashConfig);return _s(e.deltaCache,n,s),Ds(s,n)}function Ds(e,t){const n=e.indexOf(0);if(n<0)throw c(t);const r=e.subarray(0,n).indexOf(32);if(r<0)throw c(t);const o=(new TextDecoder).decode(e.subarray(0,r));return{content:e.subarray(n+1),type:Os(o,t)}}function Os(e,t){switch(e){case"commit":return 1;case"tree":return 2;case"blob":return 3;case"tag":return 4;default:throw c(t)}}function _s(e,t,n){e.set(t,n,n.length)}const Us=new WeakMap,Ns=new WeakMap;function Ms(e){let t=Us.get(e);return void 0===t&&(t=xs(e),Us.set(e,t)),t}async function Rs(t,n,r){const o=r?.verifyHash??!0,s=Ms(t);try{return await bs(t,s,n,o,r?.maxBytes)}catch(i){const a=t.promisor;if(void 0===a||!function(t){return t instanceof e.TsgitError&&"OBJECT_NOT_FOUND"===t.data.code}(i))throw i;if(!await async function(e,t,n){const r=function(e){let t=Ns.get(e);return void 0===t&&(t=new Map,Ns.set(e,t)),t}(e),o=r.get(n);if(void 0!==o)return o;const s=t.fetch([n]).then(e=>e.attempted);r.set(n,s);try{return await s}finally{r.delete(n)}}(t,a,n))throw i;return s.refresh(),bs(t,s,n,o,r?.maxBytes)}}async function Ps(e,t,n){const r=await Rs(e,t,n);if("blob"!==r.type)throw u("blob",r.type,t);return r}const Fs={kind:"identity"},Bs=async(e,t,n)=>{const{sources:r,macros:o}=await t.sourcesForPath(n);return((e,t)=>!1===t||!0===t||"unspecified"===t?Promise.resolve(Fs):(async(e,t)=>{const n=(await fr(e)).filter?.get(t);return void 0===n?Fs:{kind:"external",name:t,...void 0!==n.clean&&{clean:n.clean},...void 0!==n.smudge&&{smudge:n.smudge},required:n.required??!1}})(e,t.set))(e,jo(r,n,"filter",o))},Ws=async(e,t,n,r)=>{const{gitDir:o,workDir:s}=e.layout,i=await t.run({command:n,cwd:s,env:{GIT_DIR:o},stdin:r,...void 0!==e.signal?{signal:e.signal}:{}});return 0!==i.exitCode?{ok:!1,exitCode:i.exitCode}:{ok:!0,bytes:i.stdout??new Uint8Array(0)}};async function js(t,n,o){const s=o?.verifyHash??!0;if(!0===t.signal?.aborted)throw e.operationAborted();const i=await Ts(t,n);if(void 0!==i)return function(t,n,o,s){const i=async function*(t,n,o,s){const i=s?t.hash.createHasher():void 0,a=o[Symbol.asyncIterator](),c=await a.next();if(!0===c.done)throw r(`inflate stream produced no output for object ${n}`);const d=await async function(e,t,n){let o=n;for(;;){const n=o.indexOf(0);if(-1!==n){const{type:t}=re(o);if("blob"!==t)throw u("blob",t,e);return{headerBytes:o.subarray(0,n+1),content:o.subarray(n+1)}}const s=await t.next();if(!0===s.done)throw r(`no NUL terminator found in inflated object ${e}`);o=Vs(o,s.value)}}(n,a,c.value);i?.update(d.headerBytes),d.content.length>0&&(i?.update(d.content),yield d.content);for await(const n of{[Symbol.asyncIterator]:()=>a}){if(!0===t.signal?.aborted)throw e.operationAborted();i?.update(n),yield n}await zs(i,n)}(t,n,Hs(t,o),s);return Object.assign(i,{materialised:!1})}(t,n,i,s);const a=Ms(t),d=await a.lookup(n);if(void 0===d)throw c(n);const l=vs(await d.pack.offsetTable(),d.offset),{header:f,chunk:h,headerEndInChunk:p}=await $s(t,d,l);if(Ss(f)){if(3!==f.type)throw u("blob",function(e){switch(e){case 1:return"commit";case 2:return"tree";case 4:return"tag"}}(f.type),n);return function(t,n,r,o,s){const i=async function*(t,n,r,o,s){const i=s?t.hash.createHasher():void 0;if(void 0!==i){const e=(new TextEncoder).encode(`blob ${o}\0`);i.update(e)}for await(const n of r){if(!0===t.signal?.aborted)throw e.operationAborted();i?.update(n),yield n}await zs(i,n)}(t,n,Hs(t,r),o,s);return Object.assign(i,{materialised:!1})}(t,n,h.subarray(p),f.size,s)}return async function(e,t,n,r){const{type:o,contentOffset:s}=re(n);if("blob"!==o)throw u("blob",o,t);const i=n.subarray(0,s),a=n.subarray(s);return Object.assign(async function*(){const n=r?e.hash.createHasher():void 0;n?.update(i),a.length>0&&(n?.update(a),yield a),await zs(n,t)}(),{materialised:!0})}(t,n,await Ls(t,a,d,n,void 0),s)}async function zs(e,t){if(void 0===e)return;const n=await e.digestHex();if(n!==t)throw d(t,n)}function Hs(e,n){const r=new ReadableStream({start(e){e.enqueue(n),e.close()}}).pipeThrough(e.compressor.createInflateStream());return t.readableStreamToAsyncIterable(r)}function Vs(e,t){const n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}const Ks=async(t,n,r)=>!!await t.fs.exists(n)&&!await(async(t,n,r)=>{let o;try{o=await t.fs.read(n)}catch(t){if(t instanceof e.TsgitError&&"FILE_NOT_FOUND"===t.data.code)return!0;throw t}const{id:s}=await Yo(t,{type:"blob",content:o});return s===r})(t,n,r),Gs=async(e,t,n)=>{const r=Do(t,n.path);if("update"===n.kind||"delete"===n.kind){if(void 0===n.previousId)return;return await Ks(e,r,n.previousId)?{class:"local-changes",path:n.path}:void 0}if("add"===n.kind)return await(async(e,t)=>e.fs.exists(t))(e,r)?{class:"untracked",path:n.path}:void 0},Ys=async(t,n,r,o)=>{const s=Do(n,r.path);if("noop"!==r.kind)if("delete"!==r.kind){if(void 0!==r.id)return await(async(t,n,r,o,s)=>{if(o===p.GITLINK)return void await Qo(t,n,new Uint8Array,o);if(o===p.SYMLINK){const e=await Ps(t,r);return void await Qo(t,n,e.content,o)}if(void 0!==s&&void 0!==t.command){const i=await Bs(t,s,n);if("external"===i.kind&&void 0!==i.smudge){const s=await Ps(t,r),a=await Ws(t,t.command,i.smudge,s.content);if(!a.ok){if(i.required)throw e.smudgeFilterFailed(n,i.name,a.exitCode);return void await Qo(t,n,s.content,o)}return void await Qo(t,n,a.bytes,o)}}const i=await js(t,r);await(async(e,t,n,r)=>{await Zo(e,Do(e.layout.workDir,t),n,r)})(t,n,i,o)})(t,r.path,r.id,r.mode,o),(async(e,t,n,r,o)=>{const s=await e.fs.lstat(t);return{ctimeSeconds:Math.floor(s.ctimeMs/1e3),ctimeNanoseconds:Number(s.ctimeNs??0n)%1e9,mtimeSeconds:Math.floor(s.mtimeMs/1e3),mtimeNanoseconds:Number(s.mtimeNs??0n)%1e9,dev:s.dev,ino:s.ino,mode:o,uid:s.uid,gid:s.gid,fileSize:s.size,id:r,flags:$,path:n}})(t,s,r.path,r.id,r.mode)}else await Xo(t,s)},qs=async(t,n)=>{const{changeset:r,force:o,workdir:s}=n;if(!o){const n=await(async(e,t,n)=>{const r=[],o=[];for(const s of n.entries){const n=await Gs(e,t,s);void 0!==n&&("local-changes"===n.class?r.push(n.path):o.push(n.path))}return{localChanges:r.sort(Le),untracked:o.sort(Le)}})(t,s,r);if(n.localChanges.length>0||n.untracked.length>0)throw e.checkoutOverwriteDirty(n)}let i;return(async(e,t,n,r)=>{const o=[];let s=0,i=0;for(const a of t.entries){const c=void 0!==e.command?await r():void 0,d=await Ys(e,n,a,c);"delete"===a.kind?i+=1:"add"!==a.kind&&"update"!==a.kind||(s+=1,void 0!==d&&o.push(d)),"noop"!==a.kind&&e.progress.update("checkout:materialize",s+i,t.stats.add+t.stats.update+t.stats.delete,a.path)}return{writtenEntries:o,written:s,deleted:i}})(t,r,s,()=>i??=Go(t))},Xs=(e,t,n)=>void 0===t&&void 0!==n?{kind:"add",path:e,mode:n.mode,id:n.id,previousId:void 0,previousMode:void 0}:void 0!==t&&void 0===n?{kind:"delete",path:e,mode:t.mode,id:void 0,previousId:t.id,previousMode:t.mode}:{kind:t.id===n.id&&t.mode===n.mode?"noop":"update",path:e,mode:n.mode,id:n.id,previousId:t.id,previousMode:t.mode},Js=(e,t)=>{const n=(e=>{const t=new Map;for(const n of e.entries)0===n.flags.stage&&t.set(n.path,{id:n.id,mode:n.mode});return t})(e),r=(e=>{const t=new Map;for(const n of e)t.set(n.path,n);return t})(t),o=new Set;for(const e of n.keys())o.add(e);for(const e of r.keys())o.add(e);const s=[],i={add:0,update:0,delete:0,noop:0};for(const e of[...o].sort()){const t=Xs(e,n.get(e),r.get(e));s.push(t),i[t.kind]+=1}return{entries:s,stats:i}};async function*Qs(e,t,n){const r={ctx:e,recursive:n?.recursive??!0,maxDepth:n?.maxDepth??1024,maxEntries:n?.maxEntries??C},o="string"==typeof t?await async function(e,t){const n=await Rs(e,t);if("tree"!==n.type)throw u("tree",n.type,t);return n}(e,t):t;yield*Zs(r,{value:0},o,"",0,[])}async function*Zs(t,n,r,o,s,i){if(i.includes(r.id))throw new e.TsgitError({code:"TREE_CYCLE_DETECTED",id:r.id});if(function(e,t){return e>t}(s,t.maxDepth))throw l(s);const a=[...i,r.id];for(const i of r.entries){if(t.ctx.signal?.aborted)throw e.operationAborted();const r=""===o?i.name:`${o}/${i.name}`;if(n.value+=1,hs(n.value,t.maxEntries))throw f(n.value,t.maxEntries);if(yield{path:r,id:i.id,mode:i.mode},!ei(t.recursive,i.mode))continue;const c=await Rs(t.ctx,i.id);"tree"===c.type&&(yield*Zs(t,n,c,r,s+1,a))}}function ei(e,t){return!!e&&y(t)}const ti=(e,t)=>e.filter(e=>t.has(e.path)),ni=(e,t,n)=>t.get(e)??n.get(e),ri=e=>{const t={add:0,update:0,delete:0,noop:0};for(const n of e)t[n.kind]+=1;return t},oi=async(e,t)=>{const n=await(async(e,t)=>{const n=[];for await(const r of Qs(e,t))r.mode!==p.DIRECTORY&&n.push({path:r.path,id:r.id,mode:r.mode});return n})(e,t.targetTree),r=((e,t)=>{if(void 0!==t.paths)return{target:ti(e,t.paths),indexForDiff:{...t.currentIndex,entries:ti(t.currentIndex.entries,t.paths)},excluded:[]};const n=t.sparse;if(void 0!==n){const r=[],o=[];for(const t of e)(n(t.path)?r:o).push(t);return{target:r,indexForDiff:{...t.currentIndex,entries:t.currentIndex.entries.filter(e=>!e.flags.skipWorktree)},excluded:o}}return{target:e,indexForDiff:t.currentIndex,excluded:[]}})(n,t),o=Js(r.indexForDiff,r.target),s=!0===t.forceRewriteAll?(e=>{const t=e.entries.map(e=>"noop"===e.kind?{...e,kind:"update"}:e);return{entries:t,stats:ri(t)}})(o):o,i=await qs(e,{changeset:s,force:t.force??!1,workdir:e.layout.workDir}),a=((e,t,n,r)=>{const o=(e=>{const t=new Map;for(const n of e)t.set(n.path,n);return t})(e),s=(e=>{const t=new Map;for(const n of e.entries)0===n.flags.stage&&t.set(n.path,n);return t})(t),i=((e,t)=>{if(void 0===t)return[];const n=[];for(const[r,o]of e)t.has(r)||n.push(o);return n})(s,r);for(const e of n){const t=ni(e.path,o,s);void 0!==t&&i.push(t)}return i.sort((e,t)=>e.path<t.path?-1:1),i})(i.writtenEntries,t.currentIndex,r.target,t.paths);var c;return{newIndexEntries:0===r.excluded.length?a:(c=[...a,...r.excluded.map(A)],[...c].sort(xe)),written:i.written,deleted:i.deleted}};async function si(e){const t=rr(e.layout.gitDir);if(!await e.fs.exists(t))return{version:2,entries:[],extensions:[],trailerSha:new Uint8Array(0)};if(cs((await e.fs.stat(t)).size))throw L(is);const n=await e.fs.read(t);if(cs(n.length))throw L(is);const r=e.hashConfig.digestLength;if(n.length<r)throw L("file is shorter than the hash trailer");const o=n.subarray(0,n.length-r),s=O(n.subarray(n.length-r));if(await e.hash.hashHex(o)!==s)throw L("index trailer checksum mismatch");return function(e){if(e.length<12)throw L("truncated header");const t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(1145655875!==t.getUint32(0))throw L("invalid signature: expected DIRC");const n=t.getUint32(4);if(2!==n&&3!==n)throw L(`unsupported version: ${n}`);const r=t.getUint32(8);if(62*r>e.length-12-20)throw L(`entry count ${r} exceeds file capacity`);let o=12;const s=[];for(let i=0;i<r;i++){const r=o;if(o+62>e.length-20)throw S(o,"truncated entry");const i=t.getUint32(o),a=t.getUint32(o+4),c=t.getUint32(o+8),d=t.getUint32(o+12),u=t.getUint32(o+16),l=t.getUint32(o+20),f=t.getUint32(o+24),h=t.getUint32(o+28),p=t.getUint32(o+32),w=t.getUint32(o+36),g=O(e.subarray(o+40,o+60)),y=t.getUint16(o+60),{flags:v,extendedSize:x}=ye(t,o,n,e.length),b=m(f.toString(8));o+=62+x;const k=ve(e,o);if(-1===k)throw S(r,"missing NUL terminator");const E=4095&y,I=W(e.subarray(o,4095===E?k:o+E));me(I,r),o=k+1,o=r+(o-r+7&-8),s.push({ctimeSeconds:i,ctimeNanoseconds:a,mtimeSeconds:c,mtimeNanoseconds:d,dev:u,ino:l,mode:b,uid:h,gid:p,fileSize:w,id:g,flags:v,path:ee.from(I)})}const i=function(e,t,n){const r=[],o=e.length-20;for(;t+8<=o;){const s=W(e.subarray(t,t+4)),i=n.getUint32(t+4);if(t+8+i>o)throw S(t,"extension size exceeds remaining bytes");const a=s.charCodeAt(0);if(a>=97&&a<=122){const e=s.replace(/[^\x20-\x7e]/g,"?");throw S(t,`mandatory extension '${e}' not supported`)}const c=e.slice(t+8,t+8+i);r.push({signature:s,data:c}),t+=8+i}return r}(e,o,t);return{version:n,entries:s,extensions:i,trailerSha:e.slice(e.length-20)}}(n)}const ii=1048576,ai=new TextDecoder,ci=async t=>{const n=ir(t.layout.gitDir);let r;try{r=await t.fs.read(n)}catch(t){if(t instanceof e.TsgitError&&"FILE_NOT_FOUND"===t.data.code)return;throw t}if(r.byteLength>ii)throw e.sparsePatternFileTooLarge("info/sparse-checkout",r.byteLength,ii);return ai.decode(r)},di=(t,n)=>new e.TsgitError(void 0===n?{code:"RESOURCE_LOCKED",resource:"index",path:t}:{code:"RESOURCE_LOCKED",resource:"index",path:t,mtimeMs:n}),ui=async(t,n={})=>{const r=`${rr(t.layout.gitDir)}${ar}`,o=rr(t.layout.gitDir),s=n.now??(()=>Date.now()),i=t.config?.breakStaleLockMs;try{await t.fs.writeExclusive(r,new Uint8Array)}catch(n){if(!(n instanceof e.TsgitError)||"FILE_EXISTS"!==n.data.code)throw n;if(void 0===i)throw di(r,await li(t,r));await fi(t,r,i,s)}return hi(t,r,o)},li=async(e,t)=>{try{return(await e.fs.lstat(t)).mtimeMs}catch{return}},fi=async(t,n,r,o)=>{const s=await li(t,n);if(void 0===s)return void await t.fs.writeExclusive(n,new Uint8Array);const i=o()-s;if(i<0)throw di(n,s);if(i<r)throw di(n,s);await t.fs.rm(n);try{await t.fs.writeExclusive(n,new Uint8Array)}catch(r){if(r instanceof e.TsgitError&&"FILE_EXISTS"===r.data.code)throw di(n,await li(t,n));throw r}},hi=(t,n,r)=>{let o=!1,s=!1;return{release:async()=>{if(!o&&!s){s=!0;try{await t.fs.rm(n)}catch(t){if(!(t instanceof e.TsgitError)||"FILE_NOT_FOUND"!==t.data.code)throw t}}},commit:async e=>{if(o||s)return;const i=function(e){const t=[...e.entries].sort(xe),n=t.map(e=>{const t=B(e.path),n=e.flags.skipWorktree||e.flags.intentToAdd;return{entry:e,pathBytes:t,extended:n,paddedLength:62+(n?2:0)+t.length+8&-8}}),r=e.extensions.map(e=>({ext:e,sigBytes:B(e.signature),totalLength:8+e.data.length})),o=12+n.reduce((e,t)=>e+t.paddedLength,0)+r.reduce((e,t)=>e+t.totalLength,0),s=new Uint8Array(o),i=new DataView(s.buffer),a=n.some(e=>e.extended)?3:2;i.setUint32(0,1145655875),i.setUint32(4,a),i.setUint32(8,t.length);let c=12;for(const{entry:e,pathBytes:t,extended:r,paddedLength:o}of n)be(s,i,c,e,t,r),c+=o;for(const{ext:e,sigBytes:t,totalLength:n}of r)s.set(t,c),i.setUint32(c+4,e.data.length),s.set(e.data,c+8),c+=n;return s}({entries:[...e],extensions:[]}),a=await t.hash.hash(i),c=new Uint8Array(i.length+a.length);c.set(i,0),c.set(a,i.length),await t.fs.write(n,c),await t.fs.rename(n,r),o=!0}}},pi=new TextEncoder,wi=new Set([".git"]),gi=e=>{""===e&&yi(e),xi(e)>4096&&yi(e),e.startsWith("/")&&yi(e),e.includes("\\")&&yi(e),e.includes("\0")&&yi(e);const t=e.split("/");for(const n of t)vi(n,e);return e},mi=e=>{const t=e.toLowerCase();return!!wi.has(t)||".git"===t.replace(/[. ]+$/,"")},yi=t=>{throw e.pathspecOutsideRepo(t)},vi=(e,t)=>{""===e&&yi(t),"."!==e&&".."!==e||yi(t),xi(e)>255&&yi(t),mi(e)&&yi(t),e.includes(":")&&yi(t);for(let n=0;n<e.length;n+=1){const r=e.charCodeAt(n);(r<=31||127===r)&&yi(t)}},xi=e=>pi.encode(e).length,bi=(e,t)=>""===e?t:`${e}/${t}`;async function*ki(t,n,r,o,s){if(o>t.maxDepth)throw l(o);const i=await t.ctx.fs.readdir(Ii(t,r));if(s||!i.some(Ti))for(const s of i){if(t.ctx.signal?.aborted)throw e.operationAborted();mi(s.name)||(yield*Ei(t,n,r,o,s))}}async function*Ei(e,t,n,r,o){const s=bi(n,o.name);if(gi(s),o.isDirectory&&!o.isSymbolicLink){if(void 0!==e.ignore&&await e.ignore(s,!0))return;return void(yield*ki(e,t,s,r+1,!1))}if(!o.isFile&&!o.isSymbolicLink)return;if(void 0!==e.ignore&&await e.ignore(s,!1))return;if(t.value+=1,t.value>e.maxEntries)throw f(t.value,e.maxEntries);const i=await e.ctx.fs.lstat(Do(e.ctx.layout.workDir,s));yield{path:s,stat:i}}const Ii=(e,t)=>""===t?e.ctx.layout.workDir:Do(e.ctx.layout.workDir,t),Ti=e=>!!mi(e.name)&&(e.isDirectory||e.isFile&&!e.isSymbolicLink);async function Ci(t,n){if(t.signal?.aborted)throw e.operationAborted();const{bytes:r,id:o}=await Yo(t,n),s=n.id;if(""!==s&&s!==o)throw d(n.id,o);if(t.signal?.aborted)throw e.operationAborted();const i=await fr(t),a=i.core?.looseCompression,c=o.slice(0,2);await t.fs.mkdir(or(t.layout.gitDir,c));const u=tr(t.layout.gitDir,o),l=void 0!==a&&a>=-1&&a<=9?await t.compressor.deflate(r,a):await t.compressor.deflate(r);try{await t.fs.writeExclusive(u,l)}catch(e){if(Li(e))return o;throw e}return o}function Li(t){return t instanceof e.TsgitError&&"FILE_EXISTS"===t.data.code}const Si=async(e,t)=>{const n=Do(e.layout.workDir,""===t?".gitignore":`${t}/.gitignore`);return $i(e,n)},$i=async(t,n)=>{const r=await Ho(t,n,1048576,e.gitignoreFileTooLarge);return void 0===r?void 0:(e=>{const t=[],n=e.split("\n");for(let e=0;e<n.length;e+=1){const r=n[e],o=ut(r);if(void 0===o)continue;const{negated:s,anchored:i,directoryOnly:a,cleanPattern:c}=o;t.push({pattern:dt(ct(r)),negated:s,directoryOnly:a,anchored:i,lineNumber:e+1,compiled:at(c,{anchored:i})})}return t})(r)},Ai=async e=>{const t=[],n=await(async e=>{const t=await fr(e),n=t.core?.excludesFile;if(void 0===n||""===n)return;const r=zo(e,n);return void 0!==r?$i(e,r):void 0})(e);void 0!==n&&t.push({basedir:"",rules:n,kind:"global"});const r=await(async e=>$i(e,`${Zn(e)}/info/exclude`))(e);void 0!==r&&t.push({basedir:"",rules:r,kind:"info"});const o=await Si(e,"");void 0!==o&&t.push({basedir:"",rules:o,kind:"gitignore"});const s=new Map;return{base:t,loadDirRules:async t=>{const n=s.get(t);if(void 0!==n)return n;const r=await Si(e,t)??[];return s.set(t,r),r}}};async function Di(e,t,n){const r=n?.maxSymbolicDepth??5,o=n?.maxPeelDepth??5,s=n?.peel??!1,i=$o(e),a=await async function(e,t,n){const r=[];let o=t,s=0;for(;;){if("HEAD"!==o&&mn(o),r.includes(o))throw pn([...r,o]);r.push(o);const t=await e.resolveDirect(o);if("missing"===t.kind)throw fn(o);if("direct"===t.kind)return t.id;if(s+=1,us(s,n))throw hn(s,r);o=t.target}}(i,t,r);return s?async function(e,t,n){let r=t,o=0;for(;;){const t=await Rs(e,r);if("tag"!==t.type)return r;if(o+=1,ls(o,n))throw hn(o,[]);r=t.data.object}}(e,a,o):a}async function Oi(e,t){let n=gs(t)?t:await Di(e,t),r=await Rs(e,n),o=0;for(;"commit"===r.type||"tag"===r.type;){if(o+=1,o>5)throw hn(o,[]);n="commit"===r.type?r.data.tree:r.data.object,r=await Rs(e,n)}if("tree"!==r.type)throw u("tree",r.type,n);return r}const _i=(e,t)=>e.date>t.date||e.date===t.date&&e.oid<t.oid,Ui=(e,t)=>{let n=0;for(;n<e.length&&!_i(t,e[n]);)n+=1;e.splice(n,0,t)};async function Ni(e,t,n){const r=new Array(e.length);let o=0;const s=async()=>{for(;o<e.length;){const t=o++;r[t]=await n(e[t])}},i=Math.min(t,e.length),a=[];for(let e=0;e<i;e++)a.push(s());return await Promise.all(a),r}async function Mi(e,t){return Ni(t,32,async t=>({id:t,bytes:(await Ps(e,t)).content}))}function Ri(e,t){const n=[];for(const t of e)n.push({oldPath:t.oldPath,oldId:t.oldId,oldMode:t.oldMode});for(const e of t)"modify"!==e.type&&"type-change"!==e.type||Te(e.oldMode)||n.push({oldPath:e.path,oldId:e.oldId,oldMode:e.oldMode});return n}function Pi(e,t){const n=new Map;for(const r of e){if(n.has(r))continue;const e=t.get(r);void 0!==e&&n.set(r,{chunkMap:ze(e),size:e.length})}return n}function Fi(e,t,n,r,o){if(function(e,t,n){const r=Math.max(e,t),o=Math.min(e,t);return r*(We-n)<(r-o)*We}(e.size,t.size,n))return;const s=function(e,t,n,r){const o=Math.max(t,r);if(0===o)return We;if(0===t||0===r)return 0;const s=He(e,n);return Math.trunc(s*We/o)}(e.chunkMap,e.size,t.chunkMap,t.size);s>=n&&function(e,t){if(e.length<4)return void e.push(t);let n=0;for(let t=1;t<e.length;t++){const r=e[t],o=e[n];void 0!==r&&void 0!==o&&r.score<o.score&&(n=t)}const r=e[n];void 0!==r&&t.score>r.score&&(e[n]=t)}(o,{...r,score:s})}function Bi(e,t,n){return{type:"rename",oldPath:e.oldPath,newPath:t.newPath,oldId:e.oldId,newId:t.newId,oldMode:e.oldMode,newMode:t.newMode,similarity:{score:n,maxScore:We}}}function Wi(e,t,n){return{type:"copy",oldPath:e.oldPath,newPath:t.newPath,oldId:e.oldId,newId:t.newId,oldMode:e.oldMode,newMode:t.newMode,similarity:{score:n,maxScore:We}}}async function ji(e,t){const{adds:n,deletes:r,threshold:o,copyThreshold:s,copies:i,copySources:a}=t;if(0===r.length&&0===a.length)return null;const c=[...r.map(e=>e.oldId),...a.map(e=>e.oldId)],d=await async function(e,t,n){const[r,o]=await Promise.all([Mi(e,t),Mi(e,n.map(e=>e.newId))]),s=new Map(r.map(e=>[e.id,e.bytes])),i=new Map(o.map(e=>[e.id,e.bytes]));return{srcFingerprints:Pi(t,s),dstFingerprints:Pi(n.map(e=>e.newId),i)}}(e,c,n),u=function(e){const t=new Set,n=new Set,r=[];for(const o of e)if(!n.has(o.add))if("rename"===o.kind){if(t.has(o.src))continue;t.add(o.src),n.add(o.add),r.push({kind:"rename",change:Bi(o.src,o.add,o.score),del:o.src,add:o.add})}else n.add(o.add),r.push({kind:"copy",change:Wi(o.src,o.add,o.score),add:o.add});return r}(function(e,t,n,r,o,s,{srcFingerprints:i,dstFingerprints:a}){const c=function(e,t,n,r,o){const s=[];for(const i of t){const t=r.get(i.newId);if(void 0===t)continue;const a=[];for(const r of e){const e=n.get(r.oldId);void 0!==e&&Fi(e,t,o,{kind:"rename",src:r,add:i,score:0},a)}for(const e of a)s.push(e)}return s}(e,t,i,a,o),d="off"!==r?function(e,t,n,r,o){const s=[];for(const i of t){const t=r.get(i.newId);if(void 0===t)continue;const a=[];for(const r of e){const e=n.get(r.oldId);void 0!==e&&Fi(e,t,o,{kind:"copy",src:r,add:i,score:0},a)}for(const e of a)s.push(e)}return s}(n,t,i,a,s):[],u=[...c,...d];return u.sort((e,t)=>t.score!==e.score?t.score-e.score:"rename"===e.kind&&"copy"===t.kind?-1:"copy"===e.kind&&"rename"===t.kind?1:0),u}(r,n,a,i,o,s,d)),l=u.filter(e=>"rename"===e.kind),f=u.filter(e=>"copy"===e.kind);return{renames:l.map(e=>e.change),copyChanges:f.map(e=>e.change),consumedDeletes:new Set(l.map(e=>e.del)),consumedAdds:new Set(u.map(e=>e.add))}}function zi(e,t){const n=e.length,r=Math.max(n,t.length),{srcCopied:o,literalAdded:s}=function(e,t){const n=t.length;if(0===e.length||0===n)return{srcCopied:0,literalAdded:n};const r=He(ze(e),ze(t));return{srcCopied:r,literalAdded:n-r}}(e,t),i=n-o,a=Math.min(i+s,r);return{computedBreakScore:r>0?Math.trunc(a*We/r):0,dissimilarity:n>0?Math.trunc(i*We/n):0}}function Hi(e,t,n){const r=new Map(t.map(e=>[e.original.path,e])),o=[];for(const t of e.changes){const e="modify"===t.type&&n.has(t.path)?r.get(t.path):void 0;void 0!==e?o.push(e.del,e.add):o.push(t)}return{changes:o}}function Vi(e,t){return e.dissimilarity>=t?{...e.original,broken:{score:e.dissimilarity,maxScore:We}}:e.original}function Ki(e,t,n){if(0===t.length)return e;const{presentDels:r,presentAdds:o}=function(e,t){const n=new Set(t.map(e=>e.del)),r=new Set(t.map(e=>e.add)),o=new Set,s=new Set;for(const t of e)"delete"===t.type&&n.has(t)?o.add(t):"add"===t.type&&r.has(t)&&s.add(t);return{presentDels:o,presentAdds:s}}(e,t),s=new Set,i=[];for(const e of t){const t=r.has(e.del),a=o.has(e.add);(t||a)&&t&&a&&(s.add(e.del),s.add(e.add),i.push(Vi(e,n)))}return 0===s.size?e:[...e.filter(e=>!s.has(e)),...i]}function Gi(e,t,n){return 0===t.length?{changes:Se(e,ke)}:{changes:Se(Ki(e,t,n),ke)}}async function Yi(e,t,n,r){const{threshold:o,copyThreshold:s,limit:i,copies:a,breakRewrites:c}=function(e){const t=e?.threshold??3e4;return{threshold:t,copyThreshold:e?.copyThreshold??t,limit:e?.limit??1e3,copies:e?.copies??"off",breakRewrites:e?.breakRewrites??!1}}(n),d=function(e){return function(e){return{breakScore:e.score,mergeScore:0===e.merge?36e3:e.merge}}(!1!==e&&void 0!==e?e:{score:3e4,merge:36e3}).mergeScore}(c),{broken:u,workingDiff:l}=await async function(e,t,n){if(!1===n||void 0===n)return{broken:[],workingDiff:t};const r=0!==n.score?n.score:3e4,o=await async function(e,t,n){const r=t.changes.filter(e=>"modify"===e.type&&!Te(e.oldMode));if(0===r.length)return{broken:[],patchedDiff:t};const{records:o,paths:s}=await async function(e,t,n){const r=t.flatMap(e=>[e.oldId,e.newId]),o=await Mi(e,r),s=new Map(o.map(e=>[e.id,e.bytes])),i=[],a=new Set;for(const e of t){const t=s.get(e.oldId)??new Uint8Array(0),r=s.get(e.newId)??new Uint8Array(0),{computedBreakScore:o,dissimilarity:c}=zi(t,r);o<n||(i.push({original:e,del:{type:"delete",oldPath:e.path,oldId:e.oldId,oldMode:e.oldMode},add:{type:"add",newPath:e.path,newId:e.newId,newMode:e.newMode},dissimilarity:c}),a.add(e.path))}return{records:i,paths:a}}(e,r,n);return 0===o.length?{broken:[],patchedDiff:t}:{broken:o,patchedDiff:Hi(t,o,s)}}(e,t,r);return{broken:o.broken,workingDiff:o.patchedDiff}}(e,t,c),f=function(e,t={}){const n=t.limit??1e3,r=t.maxSameIdDeletes??100,{adds:o,deletes:s,other:i}=function(e){const t=[],n=[],r=[];for(const o of e)"add"===o.type?t.push(o):"delete"===o.type?n.push(o):r.push(o);return{adds:t,deletes:n,other:r}}(e.changes);if(o.length*s.length>n)return e;const a=function(e,t){const n=new Map;for(const t of e){const e=n.get(t.oldId);void 0===e?n.set(t.oldId,[t]):e.push(t)}const r=new Map;for(const[e,o]of n)o.length<=t&&r.set(e,o);return r}(s,r),c=new Set,d=[],u=[];for(const e of o){const t=Ve(e,a);void 0===t?u.push(e):(d.push(t.rename),c.add(t.consumedDelete))}const l=s.filter(e=>!c.has(e));return{changes:Se([...u,...l,...d,...i],ke)}}(l,{...n,limit:Number.MAX_SAFE_INTEGER}),{adds:h,deletes:p,other:w}=function(e){const t=[],n=[],r=[];for(const o of e)"add"===o.type?Te(o.newMode)?r.push(o):t.push(o):"delete"===o.type?Te(o.oldMode)?r.push(o):n.push(o):r.push(o);return{adds:t,deletes:n,other:r}}(f.changes);if(!(h.length>0&&p.length>0||"off"!==a&&h.length>0))return Gi(f.changes,u,d);const g=function(e,t,n,r,o,s){if("off"===e)return[];if("on"===e)return Ri(n,r);const i=void 0!==o?function(e){const t=[];for(const[n,r]of e)Te(r.mode)||t.push({oldPath:n,oldId:r.id,oldMode:r.mode});return t}(o):Ri(n,r);return 0!==s&&t.length*i.length>s*s?Ri(n,r):i}(a,h,p,w,r,i);return Gi(0!==i&&h.length*(p.length+g.length)>i*i?f.changes:function(e,t,n,r){const o=r?.consumedDeletes??new Set,s=r?.consumedAdds??new Set,i=r?.renames??[],a=r?.copyChanges??[];return[...e.filter(e=>!s.has(e)),...t.filter(e=>!o.has(e)),...i,...a,...n]}(h,p,w,await ji(e,{adds:h,deletes:p,threshold:o,copyThreshold:s,copies:a,copySources:g})),u,d)}const qi=async(e,t)=>{const n=new Map;for await(const r of Qs(e,t))r.mode!==p.DIRECTORY&&n.set(r.path,{id:r.id,mode:r.mode});return{entries:n}},Xi=new Uint8Array(0),Ji={},Qi={patch:"binary",numstat:"binary"},Zi={patch:"text",numstat:"text"},ea={patch:"text",numstat:"binary"},ta=new TextEncoder;function na(e){return ta.encode(`Subproject commit ${e}\n`)}async function ra(e,t,n){return Te(t)?na(n):(await Ps(e,n)).content}async function oa(e,t,n,r){const{sources:o,macros:s}=await t.sourcesForPath(n),i=jo(o,n,"diff",s);let a,c=!1;var d,u;return!1!==i&&!0!==i&&"unspecified"!==i&&(a=await async function(e,t){const n=(await fr(e)).diff?.get(t),r=n?.textconv;return void 0!==r&&""!==r?r:void 0}(e,i.set),c=void 0!==a),{pair:(d=i,u={textconvConfigured:c,rawIsBinary:!!c&&await r()},!1===d?Qi:!0===d?Zi:"unspecified"===d?Ji:u.textconvConfigured?u.rawIsBinary?ea:Zi:Ji),command:a}}async function sa(e,t,n,r,o,s,i){return Te(s)?i:(async(e,t,n,r,o)=>{const s=`${e.layout.gitDir}/TEXTCONV_INPUT_${o}`;await e.fs.write(s,r);try{return(await t.run({command:`${n} ${s}`,cwd:e.layout.workDir,env:{GIT_DIR:e.layout.gitDir},...void 0!==e.signal?{signal:e.signal}:{}})).stdout??Xi}finally{await e.fs.rm(s)}})(e,t,n,i,`${o}_${a=ke(r),a.replace(/[^a-zA-Z0-9]/g,"_").slice(0,64)}`);var a}function ia(e,t){return{...e,...void 0!==t.patch?{patchBinaryOverride:t.patch}:{},...void 0!==t.numstat?{numstatBinaryOverride:t.numstat}:{}}}async function aa(e,t,n,r,o,s,i,a){return void 0===t.runner||void 0===n?[o,s]:Promise.all([sa(e,t.runner,n,r,"old",i,o),sa(e,t.runner,n,r,"new",a,s)])}async function ca(e,t,n){let r;const o=!0===n?.applyTextconv?{runner:e.command,getProvider:()=>r??=Go(e)}:void 0;return Ni(t,32,t=>async function(e,t,n){return"add"===t.type?async function(e,t,n){if(Te(t.newMode))return{change:t,newContent:na(t.newId)};const r=(await Ps(e,t.newId)).content;if(void 0===n)return{change:t,newContent:r};const o=await n.getProvider(),{pair:s,command:i}=await oa(e,o,ke(t),()=>Me(r));return ia({change:t,newContent:void 0!==n.runner&&void 0!==i?await sa(e,n.runner,i,t,"new",t.newMode,r):r},s)}(e,t,n):"delete"===t.type?async function(e,t,n){if(Te(t.oldMode))return{change:t,oldContent:na(t.oldId)};const r=(await Ps(e,t.oldId)).content;if(void 0===n)return{change:t,oldContent:r};const o=await n.getProvider(),{pair:s,command:i}=await oa(e,o,ke(t),()=>Me(r));return ia({change:t,oldContent:void 0!==n.runner&&void 0!==i?await sa(e,n.runner,i,t,"old",t.oldMode,r):r},s)}(e,t,n):"rename"===t.type||"copy"===t.type?async function(e,t,n){if(t.similarity.score===We){if(void 0===n)return{change:t};const r=await n.getProvider(),{pair:o}=await oa(e,r,ke(t),async()=>!Te(t.newMode)&&Me((await Ps(e,t.newId)).content));return ia({change:t},o)}const[r,o]=await Promise.all([Ps(e,t.oldId),Ps(e,t.newId)]);if(void 0===n)return{change:t,oldContent:r.content,newContent:o.content};const s=await n.getProvider(),{pair:i,command:a}=await oa(e,s,ke(t),()=>Me(r.content)||Me(o.content)),[c,d]=await aa(e,n,a,t,r.content,o.content,t.oldMode,t.newMode);return ia({change:t,oldContent:c,newContent:d},i)}(e,t,n):t.oldId!==t.newId||Te(t.oldMode)||Te(t.newMode)?async function(e,t,n){const[r,o]=await Promise.all([ra(e,t.oldMode,t.oldId),ra(e,t.newMode,t.newId)]);if(void 0===n)return{change:t,oldContent:r,newContent:o};const s=Te(t.oldMode)?new Uint8Array(0):r,i=Te(t.newMode)?new Uint8Array(0):o,a=await n.getProvider(),{pair:c,command:d}=await oa(e,a,ke(t),()=>Me(s)||Me(i)),[u,l]=await aa(e,n,d,t,r,o,t.oldMode,t.newMode);return ia({change:t,oldContent:u,newContent:l},c)}(e,t,n):async function(e,t,n){const r=(await Ps(e,t.oldId)).content;if(void 0===n)return{change:t,oldContent:r,newContent:r};const o=await n.getProvider(),{pair:s,command:i}=await oa(e,o,ke(t),()=>Me(r)),[a,c]=await aa(e,n,i,t,r,r,t.oldMode,t.newMode);return ia({change:t,oldContent:a,newContent:c},s)}(e,t,n)}(e,t,o))}const da=new Uint8Array(0);function ua(e,t,n,r){const o=void 0!==r?{numstatBinaryOverride:r}:{};return t?{lineKey:e,ignoreBlankLines:n,...o}:n?{ignoreBlankLines:n,...o}:void 0!==r?{numstatBinaryOverride:r}:void 0}function la(e,t){return"modify"===e.type&&0===t.added&&0===t.deleted&&!t.binary}async function fa(e,t){if(void 0!==t)return"string"==typeof t?Oi(e,t):t}async function ha(e,t){if(void 0===t)return;const n=await qi(e,t),r=Array.from(n.entries,([e,t])=>({name:e,mode:t.mode,id:t.id}));return{type:"tree",id:t.id,entries:r}}const pa=async(e,t)=>{const n=le(t,e.hashConfig),r=n.indexOf(0),o=n.subarray(r+1),s=await e.compressor.deflate(o);return{type:wa(t.type),uncompressedSize:o.length,compressedData:s}},wa=e=>{switch(e){case"commit":return 1;case"tree":return 2;case"blob":return 3;case"tag":return 4}},ga=(t,n)=>{if(t.emitted.has(n))return!1;if(t.emitted.size>=t.cap)throw new e.TsgitError({code:"PACK_TOO_LARGE",objectCount:t.emitted.size+1,limit:t.cap});return t.emitted.add(n),!0},ma=async(e,t,n)=>{let r=t;for(let t=0;t<16;t+=1){const t=await Rs(e,r);if("tag"!==t.type)return r;n(r),r=t.data.object}return r},ya=async(e,t,n)=>{try{const r=await Rs(e,t,{verifyHash:n.verifyHash});return"commit"===r.type?r:void 0}catch(e){if(n.ignoreMissing&&va(e))return void n.missing.add(t);throw e}},va=t=>t instanceof e.TsgitError&&"OBJECT_NOT_FOUND"===t.data.code;async function*xa(t,n){!function(t){if(ns(t.from))throw e.invalidWalkInput(es);if(rs(t.from))throw e.invalidWalkInput(ts)}(n);const r=n.order??"topo",o=n.ignoreMissing??!1,s=n.verifyHash??!0,i={queue:[...n.from],visited:new Set,missing:new Set,until:new Set(n.until??[]),shallow:n.shallow??new Set};for(;i.queue.length>0;){if(t.signal?.aborted)throw e.operationAborted();const n=i.queue.shift();if(i.visited.has(n)||i.until.has(n))continue;const a=await ya(t,n,{verifyHash:s,ignoreMissing:o,missing:i.missing});void 0!==a&&(i.visited.add(n),yield a,ba(i,a,r))}}function ba(t,n,r){if(t.shallow.has(n.id))return;const o="first-parent"===r&&n.data.parents.length>0?[n.data.parents[0]]:n.data.parents;for(const n of o)if(!(t.visited.has(n)||t.missing.has(n)||t.until.has(n))){if(t.queue.length>=65536)throw e.invalidWalkInput("walk queue exceeds bound");t.queue.push(n)}}async function ka(e,t,n){const r=await e.fs.readdir(t),o=[];for(const s of r){const r=`${n}/${s.name}`;s.isDirectory?o.push(...await ka(e,`${t}/${s.name}`,r)):o.push(r)}return o}const Ea=(e,t)=>e.some(e=>!(4&(t.get(e.oid)??0))),Ia=async(e,t,n)=>{const r=new Map,o=[],s=async(t,n)=>{var s;r.set(t,(r.get(t)??0)|n),Ui(o,{oid:t,date:(s=await e(t),s?.data.committer.timestamp??0),value:void 0})};await s(t,1);for(const e of n)await s(e,2);for(;Ea(o,r);){const{oid:t}=o.shift();let n=7&(r.get(t)??0);3===n&&(r.set(t,8|(r.get(t)??0)),n|=4);const i=await e(t);for(const e of i?.data.parents??[])((r.get(e)??0)&n)!==n&&await s(e,n)}return r},Ta=async(e,t)=>{const n=[...new Set(t)];if(n.length<=1)return n;const r=[];for(const t of n){const o=n.filter(e=>e!==t);2&((await Ia(e,t,o)).get(t)??0)||r.push(t)}return r},Ca=async(e,t,n)=>{if(0===n.length)return[t];const r=(e=>{const t=[];for(const[n,r]of e)8&r&&t.push(n);return t})(await Ia(e,t,n));return Ta(e,r)},La=new TextEncoder,Sa=new Set(["side-band-64k","side-band"]),$a=async(n,r,o)=>{const s=(t=>{if(0===t.wants.length)throw new e.TsgitError({code:"EMPTY_WANTS"});const n=[];t.wants.forEach((e,r)=>{n.push(((e,t)=>{const n=0===t.length?"":` ${t.join(" ")}`;return Ft.encode(`want ${e}${n}\n`)})(e,0===r?t.capabilities:[]))}),void 0!==t.depth&&n.push(Ft.encode(`deepen ${t.depth}\n`)),void 0!==t.filter&&n.push(Ft.encode(`filter ${t.filter}\n`));const r=$t(n),o=0===t.haves.length?new Uint8Array(0):$t(t.haves.map(Yt)),s=t.done?qt:new Uint8Array(0),i=new Uint8Array(r.byteLength+o.byteLength+s.byteLength);let a=0;return i.set(r,a),a+=r.byteLength,i.set(o,a),a+=o.byteLength,i.set(s,a),i})({wants:o.wants,haves:o.haves,capabilities:o.capabilities,done:!0,...void 0!==o.depth?{depth:o.depth}:{},...void 0!==o.filter?{filter:o.filter}:{}}),i=Oa(o.url),a=await r.request({url:i,method:"POST",headers:{"content-type":"application/x-git-upload-pack-request",accept:"application/x-git-upload-pack-result"},body:s,...void 0!==n.signal?{signal:n.signal}:{}});if(200!==a.statusCode)throw e.httpError(a.statusCode,`git-upload-pack returned ${a.statusCode}`);const c=Dt(t.readableStreamToAsyncIterable(a.body)),d=await(async(e,t)=>{const n=e[Symbol.asyncIterator](),r=!0===t.expectShallow?await(async e=>{const t={shallow:[],unshallow:[]};let n=await e.next();for(;!n.done;){if("data"!==n.value.kind)return{shallow:t.shallow,unshallow:t.unshallow};const r=Pt.decode(n.value.payload);if(!en(r,t))return tn.set(e,n.value),{shallow:t.shallow,unshallow:t.unshallow};n=await e.next()}return{shallow:t.shallow,unshallow:t.unshallow}})(n):{shallow:[],unshallow:[]},o=await(async e=>{const t=[];let n=!1;const r=tn.get(e);void 0!==r&&tn.delete(e);let o=void 0!==r?{done:!1,value:r}:await e.next();for(;!o.done;){if("data"!==o.value.kind)return{acks:t,nak:n,buffered:[o.value]};const r=Pt.decode(o.value.payload);if(r.startsWith("ACK "))t.push(Xt(r)),o=await e.next();else{if(!r.startsWith("NAK"))return{acks:t,nak:n,buffered:[o.value]};n=!0,o=await e.next()}}return{acks:t,nak:n,buffered:[]}})(n);return{acks:o.acks,nak:o.nak,shallow:r.shallow,unshallow:r.unshallow,packBody:{[Symbol.asyncIterator]:()=>async function*(e,t,n){const r=async function*(e,t){for(const t of e)yield t;let n=await t.next();for(;!n.done;)yield n.value,n=await t.next()}(e,t);if(n.sideBand){const e=n.onProgress?{onProgress:n.onProgress}:{};return void(yield*Rt(r,e))}yield*async function*(e){for await(const t of e){if("data"!==t.kind)return;yield t.payload}}(r)}(o.buffered,n,t)}}})(c,{sideBand:_a(o.capabilities),onProgress:t=>n.progress.update(o.progressOp,0,void 0,e.sanitize(t)),expectShallow:void 0!==o.depth});return{packBytes:await Aa(n,o,d.packBody),shallow:d.shallow,unshallow:d.unshallow}},Aa=async(e,t,n)=>{const r=e.config?.maxResponseBytes??536870912,o=[];let s=0,i=0;for await(const a of n){if(s+a.byteLength>r)throw Da(r);o.push(a),s+=a.byteLength,s-i>=65536&&(e.progress.update(t.progressOp,s),i=s)}0!==s&&s!==i&&e.progress.update(t.progressOp,s);const a=new Uint8Array(s);let c=0;for(const e of o)a.set(e,c),c+=e.byteLength;return a},Da=t=>new e.TsgitError({code:"PACK_TOO_LARGE",objectCount:0,limit:t}),Oa=e=>{let t;try{t=new URL(e)}catch{throw mt("invalid URL")}if(""!==t.hash)throw mt("fragment must not be set");const n=t.pathname.endsWith("/")?t.pathname.slice(0,-1):t.pathname;return`${t.protocol}//${t.host}${n}/git-upload-pack${t.search}`},_a=e=>e.some(e=>Sa.has(e)),Ua=async(e,t)=>{const n=t.hash.digestLength;if(e.length<12+n)throw An("trailer mismatch: pack too short for header + trailer");const r=e.length-n,o=e.subarray(0,r),s=e.subarray(r),i=await t.hash.hashHex(o),a=O(s);if(i!==a)throw An(`trailer mismatch: expected ${i}, got ${a}`);return i},Na=async(e,t,n)=>{const r=await Ma(e,t);return(await Ra(e,r,n)).slice().sort((e,t)=>e.offset-t.offset).map(e=>({id:e.id,crc32:e.crc32,offset:e.offset}))},Ma=async(t,n)=>{const r=function(e){if(e.length<12)throw An("truncated: pack header requires 12 bytes");const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0);if(n!==Bn)throw An(`invalid magic: expected 0x5041434b, got 0x${n.toString(16).padStart(8,"0")}`);const r=t.getUint32(4);if(2!==r)throw An(`unsupported version: expected 2, got ${r}`);return{version:r,objectCount:t.getUint32(8)}}(n),o=t.config?.maxObjectsPerPack??5e7;if(r.objectCount>o)throw new e.TsgitError({code:"PACK_TOO_LARGE",objectCount:r.objectCount,limit:o});const s=n.length-t.hash.digestLength,i=[];let a=12;for(let e=0;e<r.objectCount;e+=1){const e=Wn(n,a,t.hashConfig),r=await t.compressor.streamInflate(n,e.dataOffset),o=e.dataOffset+r.bytesConsumed;if(o>s)throw An("entry extends past pack trailer");const c=b(n.subarray(a,o));i.push({offset:a,header:e,inflated:r.output,crc32:c}),a=o}if(a!==s)throw An("extra bytes between last entry and trailer");return i},Ra=async(e,t,n)=>{const r=new Map,o=new Map;let s=t;for(;s.length>0;){const t=[];let i=!1;for(const a of s){const s=await Ba(e,a,r,o,n);void 0===s?t.push(a):(r.set(s.offset,s),o.set(s.id,s),i=!0)}if(!i)throw Pa(t);s=t}return[...r.values()]},Pa=e=>{const t=e[0];if(void 0===t)return An("unresolved deltas: empty queue (internal invariant violated)");const n=Fa(t.header);return An(void 0!==n?`unresolved REF_DELTA: base ${n} not in pack`:`unresolved entry at offset ${t.offset}`)},Fa=e=>{if(!ja(e)&&6!==e.type)return e.baseId},Ba=async(e,t,n,r,o)=>{if(ja(t.header)){const n=za(t.header.type);return{id:await Ha(e,n,t.inflated),type:n,content:t.inflated,crc32:t.crc32,offset:t.offset}}if(6===t.header.type){const r=t.offset-t.header.baseDistance;if(r<12)throw An(`OFS_DELTA at offset ${t.offset} points before pack body: distance ${t.header.baseDistance}`);const o=n.get(r);if(void 0===o)return;return Wa(e,t,o)}const s=r.get(t.header.baseId);if(void 0!==s)return Wa(e,t,s);if(void 0===o)return;const i=await o(t.header.baseId);return void 0!==i?Wa(e,t,{type:i.type,content:i.content}):void 0},Wa=async(e,t,n)=>{const r=Fn(n.content,t.inflated);return{id:await Ha(e,n.type,r),type:n.type,content:r,crc32:t.crc32,offset:t.offset}},ja=e=>1===e.type||2===e.type||3===e.type||4===e.type,za=e=>{switch(e){case 1:return"commit";case 2:return"tree";case 3:return"blob";case 4:return"tag"}},Ha=async(e,t,n)=>{const r=La.encode(`${t} ${n.length}\0`),o=new Uint8Array(r.length+n.length);return o.set(r,0),o.set(n,r.length),e.hash.hashHex(o)},Va=t=>{if(t.signal?.aborted)throw e.operationAborted()},Ka=async(t,n,r)=>{try{return((e,t,n)=>({ok:!0,id:t,type:n.type,size:fe(n,e.hashConfig),object:n}))(t,n,await Rs(t,n,r))}catch(t){if((t=>t instanceof e.TsgitError&&"OBJECT_NOT_FOUND"===t.data.code)(t))return(e=>({ok:!1,id:e,reason:"missing"}))(n);throw t}},Ga=async(t,n,r,o)=>{const s=await yr(t,n,r,o);if(void 0!==s)throw e.configMissingValue(s.key,s.source,s.line)},Ya=(e,t)=>{const n=`${t.gitDir}/hooks`;return void 0===e?n:""===e?`${t.gitDir}/.tsgit-no-hooks`:e.startsWith("~/")?void 0===t.homeDir?n:`${t.homeDir}/${e.slice(2)}`:(r=e).startsWith("/")||/^[A-Za-z]:[\\/]/.test(r)?e:Do(t.workDir,e);var r},qa=async(e,t,n)=>{const r=e.hooks;if(void 0===r)return;await Ga(e,"core",void 0,["hookspath"]);const o=await fr(e),s={name:t,hooksDir:Ya(o.core?.hooksPath,e.layout),workDir:e.layout.workDir,gitDir:e.layout.gitDir,args:n.args??[],stdin:n.stdin??"",...void 0!==e.signal?{signal:e.signal}:{}};return r.run(s)};async function Xa(e,t){if(t.length>C)throw f(t.length,C);return Ci(e,{type:"tree",id:"",entries:t})}const Ja=e=>{let t=0;for(const n of e)"/"===n&&(t+=1);if(t>4096)throw l(t)},Qa=async(e,t)=>{const{files:n,subdirs:r}=(e=>{const t=[],n=new Map;for(const r of e){const e=r.path.indexOf("/");if(-1===e){t.push(r);continue}const o=r.path.slice(0,e),s=r.path.slice(e+1),i=n.get(o),a={path:s,id:r.id,mode:r.mode};void 0===i?n.set(o,[a]):i.push(a)}return{files:t,subdirs:n}})(t),o=[];for(const e of n)o.push({name:e.path,id:e.id,mode:e.mode});for(const[t,n]of r){const r=await Qa(e,n);o.push({name:t,id:r,mode:p.DIRECTORY})}return Xa(e,o)},Za=new TextEncoder,ec=async(e,t,n)=>{const r=Do(e.layout.workDir,t.path),o=await e.fs.lstat(r).catch(()=>{});if(void 0===o)return{status:"absent"};const s=v(o);if(t.mode!==p.GITLINK&&!Ie(s,t.mode))return{status:"type-changed",worktreeMode:s};try{const i=o.isSymbolicLink?Za.encode(await e.fs.readlink(r)):await e.fs.read(r),a=o.isSymbolicLink||void 0===n||void 0===e.command?i:await(async(e,t,n,r,o)=>{const s=await Bs(e,n,r);if("external"!==s.kind||void 0===s.clean)return o;const i=await Ws(e,t,s.clean,o);return i.ok?i.bytes:o})(e,e.command,n,t.path,i),{id:c}=await Yo(e,{type:"blob",id:"",content:a});return c!==t.id?{status:"modified",worktreeMode:s}:{status:s===t.mode?"unchanged":"mode-changed",worktreeMode:s}}catch{return{status:"modified",worktreeMode:s}}};async function tc(e,t){if(t.message.includes("\0"))throw s("message contains NUL");if(n=t.message,(new TextEncoder).encode(n).byteLength>16777216)throw s("message exceeds 16 MiB");var n;if(void 0!==t.gpgSignature&&os(t.gpgSignature))throw s("gpgSignature contains header-boundary chars");if(void 0!==t.extraHeaders)for(const e of t.extraHeaders){if(ss(e.key))throw s("extraHeader key contains forbidden characters");if(os(e.value))throw s("extraHeader value contains header-boundary chars")}return Y(t.author),Y(t.committer),Ci(e,{type:"commit",id:"",data:{tree:t.tree,parents:t.parents,author:t.author,committer:t.committer,message:t.message,...void 0!==t.gpgSignature?{gpgSignature:t.gpgSignature}:{},extraHeaders:t.extraHeaders??[]}})}const nc=e=>`${e.layout.gitDir}/shallow`,rc=t=>t instanceof e.TsgitError&&"FILE_NOT_FOUND"===t.data.code,oc=async e=>{let t;try{t=await e.fs.readUtf8(nc(e))}catch(e){if(rc(e))return new Set;throw e}const n=new Set;for(const e of t.split("\n")){const t=e.trim();0!==t.length&&ic(t)&&n.add(J.from(t))}return n},sc=/^[0-9a-f]{40}([0-9a-f]{24})?$/i,ic=e=>sc.test(e),ac=(e,t)=>e.section.toLowerCase()===t.section&&(void 0===t.subsection?void 0===e.subsection:e.subsection===t.subsection),cc=(e,t)=>{const n=[];for(const r of e)if(ac(r,t))for(const e of r.entries)e.key.toLowerCase()===t.name&&n.push({value:e.value});return n},dc=["system","global","local","worktree"],uc=async(e,t)=>{try{return await e.fs.exists(t)}catch{return!1}},lc=(t,n)=>{try{return n()}catch(n){if(n instanceof e.TsgitError&&"UNSUPPORTED_OPERATION"===n.data.code)throw e.configScopeNotAvailable(t,"browser-adapter");throw n}},fc=async(t,n)=>{if("local"===n)return`${Zn(t)}/config`;if("worktree"===n){if(!await(async t=>{const n=`${Zn(t)}/config`,r=await(async(t,n)=>{try{return await t.fs.readUtf8(n)}catch(t){if(t instanceof e.TsgitError&&"FILE_NOT_FOUND"===t.data.code)return;throw t}})(t,n);if(void 0===r)return!1;const o=_r(r,n);for(const e of o)if("extensions"===e.section.toLowerCase()&&void 0===e.subsection)for(const t of e.entries)if("worktreeconfig"===t.key.toLowerCase())return"true"===t.value;return!1})(t))throw e.configScopeNotAvailable("worktree","worktree-extension-unset");return`${t.layout.gitDir}/config.worktree`}if("global"===n){const e=lc("global",()=>t.fs.xdgConfigHome()),n=lc("global",()=>t.fs.homedir()),r=`${e}/git/config`;if(await uc(t,r))return r;const o=`${n}/.gitconfig`;return await uc(t,o),o}const r=lc("system",()=>t.fs.systemConfigPath());if(0===r.length)throw e.configSystemPathUnresolved();return r};let hc=new WeakMap;const pc=e=>{hc.delete(e)},wc=(t,n)=>{const r=(e=>{const t=hc.get(e);if(void 0!==t)return t;const n=new Map;return hc.set(e,n),n})(t),o=r.get(n);if(void 0!==o)return o;const s=(async(t,n)=>{const r=await fc(t,n);try{const e=await t.fs.readUtf8(r);return _r(e,r)}catch(t){if(t instanceof e.TsgitError){const e=t.data.code;if("FILE_NOT_FOUND"===e||"PERMISSION_DENIED"===e)return[]}throw t}})(t,n);return r.set(n,s),s},gc=async(t,n)=>{try{return{scope:n,sections:await wc(t,n)}}catch(t){if(t instanceof e.TsgitError){const e=t.data.code;if("CONFIG_SCOPE_NOT_AVAILABLE"===e)return;if("CONFIG_SYSTEM_PATH_UNRESOLVED"===e)return}throw t}},mc=async({ctx:e,scope:t})=>{if(void 0!==t)return(await wc(e,t)).map(e=>({scope:t,section:e}));const n=[];for(const t of dc){const r=await gc(e,t);void 0!==r&&n.push(r)}return(e=>{const t=new Map;for(const{scope:n,sections:r}of e)t.set(n,r);const n=[];for(const e of dc){const r=t.get(e);if(void 0!==r)for(const t of r)n.push({scope:e,section:t})}return n})(n)},yc=async(e,t,n)=>{if(void 0!==n){const r=await wc(e,n);return cc(r,t).map(e=>({value:e.value,scope:n}))}return((e,t)=>{const n=[];for(const{scope:r,section:o}of e)if(ac(o,t))for(const e of o.entries)e.key.toLowerCase()===t.name&&n.push({value:e.value,scope:r});return n})((await mc({ctx:e})).map(({scope:e,section:t})=>({scope:e,section:t})),t)},vc=(e,t)=>`\t${e} = ${(e=>{const t=e.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll("\n","\\n").replaceAll("\t","\\t");return(e=>e.startsWith(" ")||e.endsWith(" ")||e.includes(";")||e.includes("#")||e.includes("\r"))(e)?`"${t}"`:t})(t)}`,xc=(e,t)=>void 0===t?`[${e}]`:`[${e} "${(e=>e.replaceAll("\\","\\\\").replaceAll('"','\\"'))(t)}"]`,bc=(t,n)=>{if(/[\n\r\0]/.test(n))throw e.invalidOption("config",`${t} must not contain a newline or NUL`)},kc=t=>{if(t.includes("\0"))throw e.invalidOption("config","value must not contain a NUL byte")},Ec=t=>{if(/[\n\0]/.test(t))throw e.invalidOption("config","subsection must not contain a newline or NUL")},Ic=t=>{if(/[\s\0[\]"\\]/.test(t))throw e.invalidOption("config","section must not contain whitespace, NUL, brackets, quotes, or backslashes")},Tc=(t,n)=>{if(""===t&&void 0===n)throw e.invalidOption("config","section name must not be empty without a subsection")},Cc=e=>void 0===e.subsection?e.section:`${e.section}.${e.subsection}`,Lc=e=>{const t=Hr(e);if("header"===t.parse.kind)return{rawName:Cc(t.parse),endOffset:t.endOffset}},Sc=(e,t)=>{for(let n=0;n<e.length;n+=1)if(Lc(e[n])?.rawName===t)return n;return-1},$c=(e,t)=>{const n=e.split("\n"),r=[];let o=!1;for(const e of n){const n=Lc(e);void 0===n||(o=n.rawName===t),o||r.push(e)}return((e,t)=>""===e[e.length-1]&&t.length>0&&""!==t[t.length-1]?[...t,""]:t)(n,r).join("\n")},Ac=(e,t,n)=>{Ic(n.section),Tc(n.section,n.subsection),void 0!==n.subsection&&Ec(n.subsection);const r=e.split("\n").map(e=>{const r=Lc(e);return void 0===r||r.rawName!==t?e:((e,t,n)=>{const r=xc(n.section,n.subsection),o=Or(e,t);return o>=e.length?r:`${r}\n\t${e.slice(o)}`})(e,r.endOffset,n)});return r.join("\n")},Dc=async(t,n)=>{try{return await t.fs.readUtf8(n)}catch(t){if(t instanceof e.TsgitError&&"FILE_NOT_FOUND"===t.data.code)return"";throw t}},Oc=(e,t)=>({sectionLc:e.toLowerCase(),subsection:t}),_c=(e,t)=>e.section.toLowerCase()===t.sectionLc&&e.subsection===t.subsection,Uc=(e,t)=>{let n,r,o=!1;for(const s of e)"header"===s.kind?(o&&(n=r),o=_c(s,t),r=o?s.line+1:void 0):o&&"entry"===s.kind&&(r=s.endLine);return o&&(n=r),n},Nc=(e,t,n,r)=>{const o=r.endsWith("\n")?e.length-1:e.length,s=Math.min(t,o),i=[...e.slice(0,s),n,...e.slice(s)];return s===e.length&&i.push(""),i},Mc=(e,t,n,r,o)=>{Ic(t),Tc(t,n),bc("key",r),kc(o),void 0!==n&&Ec(n);const s=e.split("\n"),i=Cr(s,e.endsWith("\n")),a=Oc(t,n),c=((e,t,n)=>{const r=n.toLowerCase();let o=!1;for(const n of e)if("header"===n.kind)o=_c(n,t);else if(o&&"entry"===n.kind&&n.key.toLowerCase()===r)return n})(i,a,r);if(void 0!==c)return((e,t,n,r)=>{const o=n.sharesHeaderLine?((e,t)=>{for(const n of e)if("header"===n.kind&&n.line===t.startLine)return n})(t,n):void 0,s=void 0!==o?[xc(o.section,o.subsection),r]:[r],i=[...e.slice(0,n.startLine),...s,...e.slice(n.endLine)];return(n.endLine===e.length?[...i,""]:i).join("\n")})(s,i,c,vc(r,o));const d=Uc(i,a);return void 0===d?`${""===e?"":e.endsWith("\n")?e:`${e}\n`}${xc(t,n)}\n${vc(r,o)}\n`:Nc(s,d,vc(r,o),e).join("\n")},Rc=e=>[e.header.line,...e.bodyTokens.flatMap(e=>"entry"===e.kind?Pc([e]):[e.line])],Pc=e=>e.flatMap(e=>Array.from({length:e.endLine-e.startLine},(t,n)=>e.startLine+n)),Fc=(e,t,n,r)=>{Ic(t),void 0!==n&&Ec(n),bc("key",r);const o=e.split("\n"),s=Oc(t,n),i=(e=>{const t=[];for(let n=0;n<e.length;n++){const r=e[n];if("header"!==r.kind)continue;const o=[];let s=n+1;for(;s<e.length&&"header"!==e[s].kind;)o.push(e[s]),s++;t.push({header:r,bodyTokens:o}),n=s-1}return t})(Cr(o,e.endsWith("\n"))),a=r.toLowerCase(),c=i.filter(e=>_c(e.header,s)).map(e=>((e,t)=>{const n=((e,t)=>e.bodyTokens.flatMap(e=>"entry"===e.kind&&e.key.toLowerCase()===t?[{startLine:e.startLine,endLine:e.endLine}]:[]))(e,t);return 0===n.length?{excluded:[]}:((e,t)=>e.header.hasComment||e.bodyTokens.some(e=>"comment"===e.kind||"entry"===e.kind&&e.key.toLowerCase()!==t))(e,t)?n.some(t=>t.startLine===e.header.line)?{excluded:Pc(n).filter(t=>t!==e.header.line),headerRewrite:{line:e.header.line,text:xc(e.header.section,e.header.subsection)}}:{excluded:Pc(n)}:{excluded:Rc(e)}})(e,a));return((e,t)=>{const n=new Set(t.flatMap(e=>e.excluded)),r=new Map(t.flatMap(e=>e.headerRewrite?[[e.headerRewrite.line,e.headerRewrite.text]]:[]));if(0===n.size&&0===r.size)return;const o=[];for(const[t,s]of e.entries())n.has(t)||o.push(r.get(t)??s);return(n.has(e.length-1)?[...o,""]:o).join("\n")})(o,c)??e},Bc=async(e,t)=>{const n=`${e.layout.gitDir}/config`,r=await Dc(e,n);zc(r,n);const o=t.reduce((e,t)=>Mc(e,t.section,t.subsection,t.key,t.value),r);await e.fs.writeUtf8(n,o),pr(e)},Wc=(e,t)=>"set"===t.kind?Mc(e,t.section,t.subsection,t.key,t.value):"appendEntry"===t.kind?jc(e,t.section,t.subsection,t.key,t.value):"removeEntry"===t.kind?Fc(e,t.section,t.subsection,t.key):"removeSection"===t.kind?$c(e,Cc({section:t.section,subsection:t.subsection})):Ac(e,Cc({section:t.section,subsection:t.from}),{section:t.section,subsection:t.to}),jc=(e,t,n,r,o)=>{Ic(t),Tc(t,n),bc("key",r),kc(o),void 0!==n&&Ec(n);const s=e.split("\n"),i=Cr(s,e.endsWith("\n")),a=Oc(t,n),c=Uc(i,a);return void 0===c?`${""===e?"":e.endsWith("\n")?e:`${e}\n`}${xc(t,n)}\n${vc(r,o)}\n`:Nc(s,c,vc(r,o),e).join("\n")},zc=(t,n)=>{try{return _r(t,n)}catch(t){if(t instanceof e.TsgitError&&"CONFIG_PARSE_ERROR"===t.data.code&&void 0!==t.data.partialSectionName)throw e.configInvalidFile(t.data.partialSectionName,n);throw t}},Hc=(e,t)=>t?e.data.parents.slice(0,1):e.data.parents;async function*Vc(t,n){const r=n.shallow??new Set,o={queue:[],seen:new Set(n.from),until:new Set(n.until??[]),firstParent:n.firstParent??!1,read:Kc(t,n)};for(await Gc(o);o.queue.length>0;){if(t.signal?.aborted)throw e.operationAborted();const{value:n}=o.queue.shift();yield n,r.has(n.id)||await Yc(o,n)}}const Kc=(e,t)=>{const n=t.verifyHash??!0,r=t.ignoreMissing??!1,o=new Set;return t=>ya(e,t,{verifyHash:n,ignoreMissing:r,missing:o})},Gc=async e=>{for(const t of e.seen)e.until.has(t)||await qc(e,t)},Yc=async(e,t)=>{for(const n of Hc(t,e.firstParent))e.seen.has(n)||e.until.has(n)||(e.seen.add(n),await qc(e,n))},qc=async(e,t)=>{const n=await e.read(t);void 0!==n&&Ui(e.queue,{oid:t,date:n.data.committer.timestamp,value:n})},Xc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0")),Jc=/^[A-Za-z]:/,Qc=e=>{if(e.startsWith("-"))return!0;if(e.includes("\\"))return!0;if((e=>{for(let t=0;t<e.length;t+=1){const n=e.charCodeAt(t);if(n<=31)return!0;if(127===n)return!0}return!1})(e))return!0;if(Jc.test(e))return!0;for(const t of e.split("/")){if(""===t)return!0;if("."===t)return!0;if(".."===t)return!0}return!1},Zc=(e,t)=>void 0!==t?{...e,stage:0,skipWorktree:!1}:{...e,stage:0},ed=(e,t)=>e.path<t.path?-1:e.path>t.path?1:0,td={kind:"empty"},nd=()=>({slots:Array.from({length:16},()=>td),preserved:[]}),rd=e=>({kind:"internal",node:e}),od=(e,t,n)=>({...e,slots:e.slots.map((e,r)=>r===t?n:e)}),sd=(e,t)=>Number.parseInt(e.charAt(t),16),id=e=>"note"===e.kind?e.key:e.prefix,ad=(e,t,n)=>{const r=id(t),o=sd(r,n),s=e.slots[o];if("empty"===s.kind)return od(e,o,t);if("internal"===s.kind)return od(e,o,rd(ad(s.node,t,n+1)));if(id(s)===r)return od(e,o,t);const i=ad(ad(nd(),s,n+1),t,n+1);return od(e,o,rd(i))},cd=/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/,dd=/^[0-9a-f]{2}$/,ud=(e,t)=>{const n=[];return{...e.reduce((e,r)=>{const o=((e,t)=>{const n=t+e.name;return!y(e.mode)&&cd.test(n)?{kind:"note",key:J.from(n),val:e.id}:y(e.mode)&&dd.test(e.name)?{kind:"subtree",prefix:n,oid:e.id}:null})(r,t);return null===o?(n.push(r),e):ad(e,o,t.length)},nd()),preserved:n}},ld=e=>ud(e,""),fd=async(e,t)=>ud(await t(e.oid),e.prefix),hd="refs/notes/",pd=`${hd}commits`,wd=t=>{if(!t.startsWith(hd))throw e.notesRefOutside(t);return t},gd=(e,t,n)=>{const r=`${e.layout.gitDir}/modules/${t}`,o=Do(e.layout.workDir,n),{promisor:s,hooks:i,...a}=e;return Object.freeze({...a,layout:Object.freeze({workDir:o,gitDir:r,bare:!1,...void 0!==e.layout.homeDir?{homeDir:e.layout.homeDir}:{}}),cwd:o})},md=async(e,t,n,r=new Set)=>{if(void 0===t)return;const o=`${e.layout.gitDir}/modules/${t}`;return!r.has(o)&&await e.fs.exists(`${o}/HEAD`)?gd(e,t,n):void 0},yd=(e,t)=>{if(null===t.value)return e;const n=t.key.toLowerCase();return"path"===n?{...e,path:t.value}:"url"===n?{...e,url:t.value}:"update"===n?{...e,update:t.value}:"branch"===n?{...e,branch:t.value}:e},vd=e=>{if("submodule"!==e.section)return;if(void 0===e.subsection)return;if(Qc(e.subsection))return;const t=e.entries.reduce(yd,{});return{name:e.subsection,...void 0!==t.path?{path:t.path}:{},...void 0!==t.url?{url:t.url}:{},...void 0!==t.update?{update:t.update}:{},...void 0!==t.branch?{branch:t.branch}:{}}},xd=e=>{const t=[];for(const n of _r(e,".gitmodules")){const e=vd(n);void 0!==e&&t.push(e)}return t},bd=Z.from("HEAD"),kd=new TextDecoder;async function*Ed(e,t,n,r,o,s,i,a){const c=await Td(e,t);for await(const d of Qs(e,t,{recursive:!0})){if(d.mode!==p.GITLINK)continue;const t=bi(o,d.path),u=c.get(d.path);if(yield Id(u,d.path,d.id,t,n,r),!i)continue;if(n>=a)continue;const l=await md(e,u?.name,d.path,s);if(void 0===l)continue;const f=await Cd(l,d.id);if(void 0===f)continue;const h=new Set(s).add(l.layout.gitDir);yield*Ed(l,f,n+1,t,t,h,i,a)}}const Id=(e,t,n,r,o,s)=>({name:e?.name??t,path:r,commit:n,depth:o,...void 0!==e?.url?{url:e.url}:{},...void 0!==e?.branch?{branch:e.branch}:{},...void 0!==s?{parent:s}:{}}),Td=async(e,t)=>{const n=t.entries.find(e=>".gitmodules"===e.name);if(void 0===n)return new Map;if(n.mode!==p.REGULAR&&n.mode!==p.EXECUTABLE)return new Map;const r=await Ps(e,n.id,{maxBytes:ko}),o=kd.decode(r.content),s=new Map;for(const e of xd(o))void 0!==e.path&&s.set(e.path,e);return s},Cd=async(t,n)=>{try{return await Oi(t,n)}catch(t){if(t instanceof e.TsgitError&&"OBJECT_NOT_FOUND"===t.data.code)return;throw t}},Ld=(e,t)=>[...Array.from({length:t},(t,n)=>e.slice(2*n,2*n+2)),e.slice(2*t)].join("/"),Sd=e=>Array.from({length:e.length/2},(t,n)=>e.slice(2*n,2*n+2)).join("/"),$d=async(e,t,n,r,o,s)=>{return"empty"===e.kind?[]:"note"===e.kind?[{name:Ld(e.key,o),mode:p.REGULAR,oid:e.val}]:"internal"===e.kind?(await Ad(e.node,n,r+1,o,s+(i=t,i.toString(16)))).entries:r<2*o?[{name:Sd(e.prefix),mode:p.DIRECTORY,oid:e.oid}]:(await Ad(await fd(e,n),n,e.prefix.length,o,e.prefix)).entries;var i},Ad=async(e,t,n,r,o)=>{const s=((e,t,n)=>t%2!=0||t>2*n?n:e.slots.every(e=>{return"subtree"===(t=e.kind)||"internal"===t;var t})?n+1:n)(e,n,r),i=[];for(const[r,a]of e.slots.entries())i.push(...await $d(a,r,t,n,s,o));const a=e.preserved.map(e=>((e,t)=>({name:""===t?e.name:`${Sd(t)}/${e.name}`,mode:e.mode,oid:e.id}))(e,o));return{entries:[...i,...a]}};async function Dd(e,t){const n=[],r=new Map;for(const e of t){const t=e.name.indexOf("/");if(-1===t)n.push({id:e.oid,mode:e.mode,name:e.name});else{const n=e.name.slice(0,t),o=e.name.slice(t+1),s=r.get(n)??[];s.push({name:o,mode:e.mode,oid:e.oid}),r.set(n,s)}}const o=[];for(const[t,n]of r){const r=await Dd(e,n);o.push({id:r,mode:p.DIRECTORY,name:t})}return Xa(e,ae([...n,...o]))}exports.AGENT=lt,exports.CLIENT_CAPABILITIES_FETCH=ft,exports.CLIENT_CAPABILITIES_PUSH=ht,exports.DEFAULT_NOTES_REF=pd,exports.EMPTY_SLOT=td,exports.FILE_MODE=p,exports.FilePath=ee,exports.MAX_CONCURRENT_BLOB_LOADS=32,exports.MAX_FLAT_TREE_ENTRIES=C,exports.MAX_GITMODULES_BYTES=ko,exports.MAX_HAVES=256,exports.MAX_LINE_BYTES=65536,exports.MAX_PUSH_OBJECTS=bo,exports.MAX_SCORE=We,exports.MAX_SPARSE_PATTERN_FILE_BYTES=ii,exports.MAX_SUBMODULE_DEPTH=100,exports.MAX_WALK_SEEDS=1024,exports.MAX_WORKING_TREE_BLOB_BYTES=xo,exports.NONE_KEY=Oe,exports.ObjectId=J,exports.RefName=Z,exports.STAGE0_FLAGS=$,exports.ZERO_OID=Q,exports.acquireIndexLock=ui,exports.appendReflog=Eo,exports.applyChangeset=qs,exports.applyConfigOpInText=Wc,exports.assertNoValuelessConfig=Ga,exports.atomicWriteRef=cr,exports.boundedMap=Ni,exports.buildAttributeProvider=Go,exports.buildConeSpec=e=>{const t=new Set(e.map(kn)),n=new Set;for(const e of t)for(const r of bn(e))t.has(r)||n.add(r);return{mode:"cone",recursive:t,parents:n}},exports.buildDiscoveryUrl=(e,t)=>{let n;try{n=new URL(e)}catch{throw mt("invalid URL")}if(""!==n.hash)throw mt("fragment must not be set");const r=n.pathname.endsWith("/")?n.pathname.slice(0,-1):n.pathname;return`${n.protocol}//${n.host}${r}/info/refs${""===n.search?`?service=${t}`:`${n.search}&service=${t}`}`},exports.buildIgnoreEvaluator=Ai,exports.buildIndexFromTree=async(e,t)=>{const n=(e=>{const t=new Map;for(const n of e.entries)0===n.flags.stage&&t.set(n.path,n);return t})(t.currentIndex),r=await(async(e,t)=>{const n=[];for await(const r of Qs(e,t))r.mode!==p.DIRECTORY&&n.push({path:r.path,id:r.id,mode:r.mode});return n})(e,t.targetTree),o=r.map(e=>((e,t,n)=>{if(void 0!==n&&!n(e.path))return A(e);const r=t.get(e.path);return void 0!==r&&r.id===e.id&&r.mode===e.mode?{...r,flags:Zc(r.flags,n)}:(e=>({ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,mode:e.mode,uid:0,gid:0,fileSize:0,id:e.id,flags:$,path:e.path}))(e)})(e,n,t.sparse));return o.sort(ed),o},exports.buildPack=async(e,t)=>{const n=[];for(const r of t.oids){const t=await Rs(e,r);n.push(await pa(e,t))}const r=function(e){const t=function(e,t){const n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,Bn),r.setUint32(4,2),r.setUint32(8,t),n}(0,e.length),n=[t],r=[];let o=t.length;for(const t of e){const e=Jn(jn(t.type,t.uncompressedSize),t.compressedData),s=b(e);r.push({crc32:s,offset:o}),n.push(e),o+=e.length}return{data:Qn(n),entries:r}}(n),o=await e.hash.hash(r.data),s=O(o),i=new Uint8Array(r.data.length+o.length);return i.set(r.data,0),i.set(o,r.data.length),{bytes:i,sha:s,objectCount:n.length}},exports.buildRepoIgnorePredicate=async e=>{const t=await Ai(e),n=[...t.base],r=new Set([]);return async(e,o)=>{for(const o of(e=>{const t=e.split("/");if(t.length<=1)return[];const n=[];for(let e=1;e<t.length;e+=1)n.push(t.slice(0,e).join("/"));return n})(e)){if(r.has(o))continue;r.add(o);const e=await t.loadDirRules(o);e.length>0&&n.push({basedir:o,rules:e})}return"ignored"===((e,t,n)=>rt(e,t,n).verdict)(n,e,o)}},exports.buildSparseMatcher=$n,exports.bytesEqual=M,exports.catFileBatch=async function*(e,t,n){const r=void 0===n?.maxBytes?void 0:{maxBytes:n.maxBytes};for await(const n of t){Va(e);const t=await Ka(e,n,r);yield t,Va(e)}},exports.chainGap=(e,t,n)=>[...t.slice(n+1)].reduceRight((e,t)=>rd(od(nd(),sd(t,0),e)),rd(e)),exports.commitDateWalk=Vc,exports.commonGitDir=Zn,exports.compareBytes=N,exports.comparePaths=Le,exports.compareWorkingTreeDelta=ec,exports.compareWorkingTreeEntry=async(e,t,n)=>(await ec(e,t,n)).status,exports.compileGlob=at,exports.computeChangeset=Js,exports.containsGlob=e=>e.includes("*")||e.includes("?"),exports.crc32=b,exports.createCommit=tc,exports.createEmptyTrie=nd,exports.createPackRegistry=xs,exports.decodePktStream=Dt,exports.deleteReflog=To,exports.deriveSubmoduleCloneContext=(e,t,n)=>gd(e,t,n),exports.deriveSubmoduleContext=md,exports.deriveWorkingMode=v,exports.diffLines=Be,exports.diffTrees=async function(e,t,n,r){const[o,s]=await Promise.all([fa(e,t),fa(e,n)]),i=!0===r?.recursive?await async function(e,t,n){const[r,o]=await Promise.all([ha(e,t),ha(e,n)]);return et(r,o)}(e,o,s):et(o,s),a=!0===r?.detectRenames?await Yi(e,i,r.renameOptions,await async function(e,t,n){if("harder"!==n?.copies||void 0===t)return;return(await qi(e,t)).entries}(e,o,r.renameOptions)):i,c={mode:(d=r??{}).ignoreWhitespace??"none",ignoreCrAtEol:d.ignoreCrAtEol??!1};var d;const u="none"!==(l=c).mode||l.ignoreCrAtEol;var l;const f=!0===r?.ignoreBlankLines,h=!0===r?.withStat;return u||h?async function(e,t,n,r,o,s){const i=await ca(e,t.changes,{applyTextconv:!0}),a=[];for(const e of i){const t=qe(e.oldContent??da,e.newContent??da,ua(n,r,o,e.numstatBinaryOverride));r&&la(e.change,t)||a.push(s?{...e.change,...t}:e.change)}return{changes:a}}(e,a,c,u,f,h):a},exports.emptyReceiveUpdates=()=>new e.TsgitError({code:"EMPTY_RECEIVE_UPDATES"}),exports.encodePktStream=$t,exports.enqueue=Ui,exports.enumerateObjects=async function(e,t){const n=!1!==t?.includePacks,r=new Set;return await async function(e,t){const n=Zn(e);for(const r of Xc){const o=or(n,r);if(!await e.fs.exists(o))continue;const s=await e.fs.readdir(o);for(const e of s)e.isFile&&t.add(`${r}${e.name}`)}}(e,r),n&&await async function(e,t){const n=Ms(e),r=await n.all();for(const e of r)for(const n of Xn(e.index))t.add(n)}(e,r),[...r].sort()},exports.enumeratePushObjects=async function*(e,t){const n={emitted:new Set,cap:t.maxObjects??bo},r=await(async(e,t,n)=>{const r=[];for(const o of n){const n=await ma(e,o,e=>{ga(t,e)});r.push(n)}return r})(e,n,t.wants);for(const e of n.emitted)yield e;yield*async function*(e,t,n,r){for await(const o of xa(e,{from:n,until:r,ignoreMissing:!0})){ga(t,o.id)&&(yield o.id),ga(t,o.data.tree)&&(yield o.data.tree);for await(const n of Qs(e,o.data.tree,{recursive:!0}))fs(n.mode)||ga(t,n.id)&&(yield n.id)}}(e,n,r,t.haves)},exports.enumerateRefs=async function(e){const t=new Set;await e.fs.exists(`${e.layout.gitDir}/HEAD`)&&t.add("HEAD");for(const n of await async function(e){const t=`${e.layout.gitDir}/refs`;return await e.fs.exists(t)?ka(e,t,"refs"):[]}(e))t.add(n);for(const n of(await $o(e).getPackedRefs()).entries)t.add(n.name);return[...t]},exports.exceedsMaxPeelDepth=ls,exports.fetchPack=async(e,t,n)=>{e.progress.start(n.progressOp);try{const r=await $a(e,t,n);if(0===r.packBytes.length)return{packPath:"",idxPath:"",objectCount:0,packSha:"",shallow:r.shallow,unshallow:r.unshallow};const o=await Ua(r.packBytes,e),s=await Na(e,r.packBytes),i=await(async(e,t,n)=>{const r=function(e,t){if(20!==t.length)throw Dn(`packChecksum must be 20 bytes, got ${t.length}`);const n=e.map(e=>({shaBytes:_(e.id),entry:e}));n.sort((e,t)=>N(e.shaBytes,t.shaBytes));const r=n.length;let o=0;for(const e of n)e.entry.offset>2147483647&&(o+=1);const s=20*r,i=4*r,a=4*r,c=1032+s+i+a+8*o+20,d=new Uint8Array(c),u=new DataView(d.buffer);u.setUint32(0,4285812579),u.setUint32(4,2);const l=new Uint32Array(256);for(const{shaBytes:e}of n)l[e[0]]+=1;const f=new Uint32Array(256);let h=0;for(let e=0;e<256;e++)h+=l[e],f[e]=h;for(let e=0;e<256;e++)u.setUint32(8+4*e,f[e]);for(let e=0;e<r;e++)d.set(n[e].shaBytes,1032+20*e);const p=1032+s;for(let e=0;e<r;e++)u.setUint32(p+4*e,n[e].entry.crc32);const w=p+i;let g=0;const m=w+a;for(let e=0;e<r;e++){const t=n[e].entry.offset;if(t>2147483647){u.setUint32(w+4*e,2147483648|g);const n=Math.floor(t/4294967296),r=t>>>0;u.setUint32(m+8*g,n),u.setUint32(m+8*g+4,r),g+=1}else u.setUint32(w+4*e,t)}return d.set(t,c-20),d}(t.map(e=>({id:e.id,crc32:e.crc32,offset:e.offset})),_(n)),o=_(await e.hash.hashHex(r)),s=new Uint8Array(r.length+o.length);return s.set(r,0),s.set(o,r.length),s})(e,s,o),a=await(async(e,t,n,r,o,s)=>{const i=`${e.layout.gitDir}/objects/pack`;await e.fs.mkdir(i);const a=`${i}/pack-${r}.pack`,c=`${i}/pack-${r}.idx`;return await e.fs.writeExclusive(a,t),await e.fs.writeExclusive(c,n),s&&await e.fs.writeExclusive(`${i}/pack-${r}.promisor`,new Uint8Array(0)),{packPath:a,idxPath:c,objectCount:o,packSha:r}})(e,r.packBytes,i,o,s.length,!0===n.promisor);return function(e){Us.get(e)?.refresh()}(e),{...a,shallow:r.shallow,unshallow:r.unshallow}}finally{e.progress.end(n.progressOp)}},exports.findByPrefix=function(e,t){if(t.length<4)throw Dn(`prefix too short: minimum 4 hex chars, got ${t.length}`);if(t.length>40)throw Dn(`prefix too long: maximum 40 hex chars, got ${t.length}`);if(!qn.test(t))throw Dn("prefix contains non-hex characters");const n=t.padEnd(40,"0"),r=t.padEnd(40,"f"),o=_(n),s=_(r),i=o[0],a=0===i?0:Vn(e,i-1),c=Vn(e,s[0]),d=function(e,t,n,r){let o=t,s=n;for(;o<s;){const t=o+s>>>1;Kn(e,t,r)<0?o=t+1:s=t}return o}(e,a,c,o),u=function(e,t,n,r){let o=t,s=n;for(;o<s;){const t=o+s>>>1;Kn(e,t,r)<=0?o=t+1:s=t}return o}(e,a,c,s),l=[];for(let t=d;t<u;t++){const n=zn+t*Hn,r=e._bytes.subarray(n,n+Hn);l.push(O(r))}return l},exports.findFirstInvalidCompression=async e=>{const{tokens:t,source:n}=await hr(e);let r=!1;for(const e of t){if("header"===e.kind){r=mr(e.section,e.subsection,"core",void 0);continue}if(!r||"entry"!==e.kind)continue;const t=e.key.toLowerCase();if(!vr.has(t))continue;const o=`core.${t}`,s=e.startLine+1;if(null===e.value)return{key:o,source:n,line:s,failure:{kind:"numeric",value:"",reason:"invalid unit"}};const i=yo(e.value);if(!i.ok)return{key:o,source:n,line:s,failure:{kind:"numeric",value:e.value,reason:i.reason}};if(i.value<-1||i.value>9)return{key:o,source:n,line:s,failure:{kind:"zlib",level:i.value}}}},exports.findFirstValuelessEntry=yr,exports.findFirstValuelessInSection=async(e,t,n)=>{const{tokens:r,source:o}=await hr(e),s=new Set(n.map(e=>e.toLowerCase())),i=t.toLowerCase();let a,c=!1;for(const e of r){if("header"===e.kind){c=e.section.toLowerCase()===i,a=e.subsection;continue}if(!c||"entry"!==e.kind||null!==e.value)continue;const t=e.key.toLowerCase();if(s.has(t))return{key:void 0===a?`${i}.${t}`:`${i}.${a}.${t}`,source:o,line:e.startLine+1}}},exports.flattenTree=qi,exports.getAllConfigValues=async({ctx:e,key:t,scope:n})=>{const r=T(t);return{key:t,values:await yc(e,r,n)}},exports.getConfigValue=async({ctx:t,key:n,scope:r})=>{const o=T(n),s=await yc(t,o,r);if(0===s.length)return{key:n,value:void 0};if(s.length>1)throw e.configMultipleValues(n,s.length,"read",r);const[i]=s;return{key:n,value:i.value,scope:i.scope}},exports.getPackRegistry=Ms,exports.getRefStore=$o,exports.getRepoRoot=e=>e.layout.workDir,exports.hashBlob=async(t,n,r={})=>{if(t.signal?.aborted)throw e.operationAborted();if(n.byteLength>xo)throw e.workingTreeFileTooLarge("(hashBlob-content)",n.byteLength,xo);const{id:o}=await Yo(t,{type:"blob",content:n});return!0!==r.write?o:Ci(t,{type:"blob",id:o,content:n})},exports.indexOf=R,exports.indexPath=rr,exports.internalSlot=rd,exports.invalidBaseUrl=mt,exports.invalidCommit=s,exports.invalidFilterSpec=(t,n)=>new e.TsgitError({code:"INVALID_FILTER_SPEC",spec:t,reason:n}),exports.invalidIdentity=a,exports.invalidReportStatus=t=>new e.TsgitError({code:"INVALID_REPORT_STATUS",line:t}),exports.invalidateConfigCache=pr,exports.invalidateScopedConfigCache=pc,exports.isBinary=Me,exports.isBlankLine=_e,exports.isDirectory=y,exports.isGitlink=fs,exports.isSameKind=Ie,exports.isUnsafeSubmoduleName=Qc,exports.isWorkingTreeDirty=Ks,exports.isWorkingTreeModified=e=>"unchanged"!==e&&"absent"!==e,exports.joinPath=Do,exports.joinPathSegment=bi,exports.kindOf=Ee,exports.listReflogs=async function(e){const t=`${e.layout.gitDir}/logs`;return await e.fs.exists(t)?Co(e,t,""):[]},exports.loadNotesTree=async function(t,n){const r=new Map,o=e=>{const n=r.get(e);if(void 0!==n)return n;const o=async function(e,t){const n=await Rs(e,t);if("tree"!==n.type)throw u("tree",n.type,t);return n.entries}(t,e);return r.set(e,o),o},s=await Di(t,n).catch(t=>{if(!(t instanceof e.TsgitError&&"REF_NOT_FOUND"===t.data.code))throw t});if(void 0===s)return{trie:ld([]),read:o,notesCommitOid:void 0,notesTreeOid:void 0};const i=await Rs(t,s);if("commit"!==i.type)throw u("commit",i.type,s);const a=i.data.tree,c=await Rs(t,a);if("tree"!==c.type)throw u("tree",c.type,a);return{trie:ld(c.entries),read:o,notesCommitOid:s,notesTreeOid:a}},exports.loadSparseMatcher=async e=>{const t=await fr(e);if(!0!==t.core?.sparseCheckout)return;const n=!0===t.core.sparseCheckoutCone,r=await ci(e),o=Sn(r??"",n);return o.degraded&&void 0!==r&&e.logger?.warn?.(".git/info/sparse-checkout is not cone-shaped; falling back to non-cone matching"),$n(o.spec)},exports.looksLikeObjectId=gs,exports.looseCompressedBytes=Ts,exports.looseObjectPath=tr,exports.looseRefPath=nr,exports.matchInStackVerbose=rt,exports.materialisePatchFiles=ca,exports.materializeTree=oi,exports.materializeWorktreeFromHead=async e=>{const t=await Oi(e,"HEAD"),n=await ui(e);try{const r=await si(e),o=await oi(e,{targetTree:t.id,currentIndex:r});return await n.commit(o.newIndexEntries),o}finally{await n.release()}},exports.maybeBuildAttributeProvider=e=>void 0!==e.command?Go(e):Promise.resolve(void 0),exports.mergeBase=async(t,n,r)=>{if(0===n.length)throw e.invalidWalkInput("mergeBase requires at least one commit");const o=(e=>{const t=new Map;return async n=>{if(!t.has(n)){const r=await Rs(e,n);t.set(n,"commit"===r.type?r:void 0)}return t.get(n)}})(t),s=[...r?.octopus?await(async(e,t)=>{let n=[t[0]];for(let r=1;r<t.length;r+=1){const o=[];for(const s of n)o.push(...await Ca(e,t[r],[s]));n=o}return Ta(e,n)})(o,n):await Ca(o,n[0],n.slice(1))].sort();return!0===r?.all?s:s.slice(0,1)},exports.negotiateCapabilities=(e,t)=>{const n=new Map;for(const t of e)n.set(pt(t),t);const r=[];for(const e of t){const t=pt(e),o=n.get(t);void 0!==o&&r.push(o)}return r},exports.nibbleAt=sd,exports.objectNotFound=c,exports.objectsDir=or,exports.parseAdvertisedRefs=async(e,t)=>{const n=e[Symbol.asyncIterator]();try{await(async(e,t)=>{const n=await e.next();if(n.done||"data"!==n.value.kind)throw yt(t,"");const r=zt(Pt.decode(n.value.payload)),o=Wt.exec(`${r}\n`),s=o?.groups?.service;if(void 0===s)throw yt(t,r);if(s!==t)throw yt(t,s);const i=await e.next();if(i.done||"flush"!==i.value.kind)throw yt(t,s)})(n,t);const{capabilities:e,refs:r}=await(async e=>{const t={refs:[],byName:new Map};let n,r=await e.next();for(;!r.done&&"data"===r.value.kind;){if(t.refs.length>=jt)throw kt(t.refs.length+1,jt);const o=zt(Pt.decode(r.value.payload));n=Gt(t,n,o),r=await e.next()}return{capabilities:n??[],refs:t.refs}})(n),o=((e,t)=>{const n=t.find(e=>"HEAD"===e.name);if(n)return n;const r=e.find(e=>e.startsWith("symref=HEAD:"));if(!r)return;const o=r.slice(12),s=t.find(e=>e.name===o);return s?{name:"HEAD",id:s.id}:void 0})(e,r);return o?{capabilities:e,refs:r,head:o}:{capabilities:e,refs:r}}finally{await(n.return?.())}},exports.parseGitmodules=xd,exports.parseHeader=re,exports.parseIniSections=_r,exports.parseLooseRef=yn,exports.parseSideBand=Rt,exports.parseSparseCheckout=Sn,exports.placeLeaf=ad,exports.primaryPath=ke,exports.qualifyKey=(e,t)=>{const n=t.toLowerCase();if(""===e.section&&void 0===e.subsection)return n;const r=e.section.toLowerCase();return void 0===e.subsection?`${r}.${n}`:`${r}.${e.subsection}.${n}`},exports.readBlob=Ps,exports.readConfig=fr,exports.readConfigSections=mc,exports.readHeadTree=async t=>{const n=await Di(t,"HEAD").catch(t=>{if(!(t instanceof e.TsgitError&&"REF_NOT_FOUND"===t.data.code))throw t});if(void 0===n)return;const r=await Rs(t,n);if("commit"!==r.type)throw u("commit",r.type,n);return qi(t,r.data.tree)},exports.readIndex=si,exports.readObject=Rs,exports.readReflog=async function(e,t){const n=sr(er(e,t),t);if(!await e.fs.exists(n))return[];if((await e.fs.stat(n)).size>16777216)throw nn("reflog file exceeds 16777216 bytes");return(await e.fs.readUtf8(n)).split("\n").filter(e=>""!==e).map(sn)},exports.readShallow=oc,exports.readSparsePatternText=ci,exports.readTree=Oi,exports.recordRefUpdate=Lo,exports.refNotFound=fn,exports.reflogEntryOutOfRange=(t,n,r)=>new e.TsgitError({code:"REFLOG_ENTRY_OUT_OF_RANGE",ref:t,requested:n,available:r}),exports.reflogExists=Io,exports.reflogNotFound=t=>new e.TsgitError({code:"REFLOG_NOT_FOUND",ref:t}),exports.refspecInvalid=(t,n)=>new e.TsgitError({code:"REFSPEC_INVALID",raw:t,reason:n}),exports.remoteFilterUnsupported=()=>new e.TsgitError({code:"REMOTE_FILTER_UNSUPPORTED"}),exports.removeConfigSection=async({ctx:t,sectionName:n,scope:r})=>{const o=r??"local",s=await fc(t,o),i=await Dc(t,s);if(-1===Sc(i.split("\n"),n))throw e.configSectionNotFound(n,o);const a=$c(i,n);await t.fs.writeUtf8(s,a),pr(t),pc(t)},exports.removeWorkingTreeFile=async(e,t)=>{const n=Do(e.layout.workDir,t);await Xo(e,n)},exports.renameConfigSection=async({ctx:t,oldName:n,newName:r,scope:o})=>{const s=(t=>{if(""===t)throw e.invalidOption("config",`invalid section name: ${t}`);const n=t.indexOf("."),r=-1===n?t:t.slice(0,n);if(r.length>0&&!/^[a-zA-Z0-9-]+$/.test(r))throw e.invalidOption("config",`invalid section name: ${t}`);return-1===n?{section:r}:{section:r,subsection:t.slice(n+1)}})(r);void 0!==s.subsection&&Ec(s.subsection);const i=o??"local",a=await fc(t,i),c=await Dc(t,a);if(-1===Sc(c.split("\n"),n))throw e.configSectionNotFound(n,i);const d=Ac(c,n,s);await t.fs.writeUtf8(a,d),pr(t),pc(t)},exports.resolveAttribute=jo,exports.resolveFilterDriver=Bs,exports.resolveNotesRef=async function(e,t){if(void 0!==t)return mn((e=>e.startsWith(hd)?e:e.startsWith("notes/")?`refs/${e}`:`${hd}${e}`)(t));const n=e.env?.get("GIT_NOTES_REF");if(void 0!==n)return mn(wd(n));const r=await fr(e),o=r.core?.notesRef;return void 0!==o?mn(wd(o)):pd},exports.resolveRef=Di,exports.resolveReflogIdentity=vo,exports.resolveTagChain=ma,exports.runFilterDriver=Ws,exports.runHook=async(t,n,r={})=>{const o=await qa(t,n,r);if(void 0!==o&&"skipped"!==o.kind&&0!==o.exitCode)throw e.hookFailed(n,o.exitCode,o.stderr)},exports.runInformationalHook=async(e,t,n={})=>{await qa(e,t,n)},exports.sanitizeReflogMessage=an,exports.selectParents=Hc,exports.serializeCone=e=>{const t=[...e.parents,...e.recursive].sort();let n="";for(const r of t)n+=`/${r}/\n`,e.parents.has(r)&&(n+=`!/${r}/*/\n`);return"/*\n!/*/\n"+n},exports.serializeObject=le,exports.serializeSymbolicRef=function(e){return`ref: ${e}\n`},exports.setConfigEntry=async({ctx:t,key:n,value:r,scope:o})=>{const s=T(n);((t,n)=>{for(let r=0;r<n.length;r+=1)if(0===n.charCodeAt(r))throw e.configValueInvalid(t,r)})(n,r);const i=o??"local";await(async(e,t)=>{const n=await fc(e,t),o=await Dc(e,n);zc(o,n);const i=Mc(o,s.section,s.subsection,s.name,r);await e.fs.writeUtf8(n,i),pr(e),pc(e)})(t,i)},exports.setConfigEntryInText=Mc,exports.setCoreConfigEntryInText=(e,t,n)=>Mc(e,"core",void 0,t,n),exports.setSlot=od,exports.skipWorktreeEntry=A,exports.sortByPath=Se,exports.sparseCheckoutPath=ir,exports.splitLines=Ne,exports.streamBlob=js,exports.synthesizeTreeFromIndex=async(e,t)=>Qa(e,(e=>{const t=[];for(const n of e)0===n.flags.stage&&(me(n.path,-1),Ja(n.path),t.push({path:n.path,id:n.id,mode:n.mode}));return t})(t)),exports.toSimilarityPercent=function(e){return 100*e/We|0},exports.treeDepthExceeded=l,exports.tryEmit=ga,exports.unexpectedObjectType=u,exports.unpackSubtree=fd,exports.unsetAllConfigEntries=async({ctx:e,key:t,scope:n})=>{const r=T(t),o=n??"local",s=await fc(e,o),i=await Dc(e,s),a=zc(i,s);if(0===cc(a,r).length)return;const c=Fc(i,r.section,r.subsection,r.name);await e.fs.writeUtf8(s,c),pr(e),pc(e)},exports.unsetConfigEntry=async({ctx:t,key:n,scope:r})=>{const o=T(n),s=r??"local",i=await fc(t,s),a=await Dc(t,i),c=zc(a,i),d=cc(c,o);if(0===d.length)return;if(d.length>1)throw e.configMultipleValues(n,d.length,"remove",s);const u=Fc(a,o.section,o.subsection,o.name);await t.fs.writeUtf8(i,u),pr(t),pc(t)},exports.updateConfigEntries=Bc,exports.updateConfigOperations=async(e,t)=>{const n=`${e.layout.gitDir}/config`,r=await Dc(e,n);zc(r,n);const o=t.reduce(Wc,r);await e.fs.writeUtf8(n,o),pr(e)},exports.updateCoreConfig=async(e,t)=>{await Bc(e,Object.entries(t).map(([e,t])=>({section:"core",key:e,value:t})))},exports.updateRef=async function(t,n,r,o){mn(n);const s=nr(t.layout.gitDir,n),i=$o(t),a=await i.resolveDirect(n);if(void 0!==o.expected){const t="direct"===a.kind?a.id:"absent";if(o.expected!==t)throw((t,n,r)=>new e.TsgitError({code:"REF_UPDATE_CONFLICT",name:t,expected:n,actual:r}))(n,o.expected,t)}if(!0===o.delete)return await async function(t,n){if(await t.isLoose(n))return void await t.removeLoose(n);if("direct"===(await t.resolveDirect(n)).kind)throw e.unsupportedOperation("delete-packed-ref","deleting packed-only refs requires packed-refs rewrite");throw fn(n)}(i,n),void await To(t,n);const c="direct"===a.kind?a.id:Q,d=(new TextEncoder).encode(`${r}\n`);await cr(t,n,s,d),c!==r&&await Lo(t,n,c,r,o.reflogMessage),await async function(e,t,n,r,o,s){const i=await t.resolveDirect(Ao);"symbolic"===i.kind&&i.target===n&&await Lo(e,Ao,r,o,s)}(t,i,n,c,r,o.reflogMessage)},exports.updateShallow=async(e,t)=>{const n=new Set(await oc(e));for(const e of t.shallow)n.add(e);for(const e of t.unshallow)n.delete(e);const r=nc(e);if(0===n.size)return void await(async(e,t)=>{try{await e.fs.rm(t)}catch(e){if(rc(e))return;throw e}})(e,r);const o=[...n].sort(),s=(new TextEncoder).encode(o.map(e=>`${e}\n`).join(""));await(async(e,t,n)=>{const r=(e=>`${e.layout.gitDir}/shallow.lock`)(e);await e.fs.writeExclusive(r,n);try{await e.fs.rename(r,t)}catch(t){try{await e.fs.rm(r)}catch(e){if(!rc(e))throw e}throw t}})(e,r,s)},exports.validateRefName=mn,exports.validateWorkingTreePath=gi,exports.verifyPackTrailer=Ua,exports.walkCommits=xa,exports.walkCommitsByDate=async function*(t,n){(t=>{if(ns(t))throw e.invalidWalkInput(es);if(rs(t))throw e.invalidWalkInput(ts)})(n.from),yield*Vc(t,n)},exports.walkPackEntries=Na,exports.walkSubmodules=async function*(e,t){const n=t?.ref??bd,r=!0===t?.recursive,o=t?.maxDepth??100,s=await Oi(e,n),i=new Set([e.layout.gitDir]);yield*Ed(e,s,0,void 0,"",i,r,o)},exports.walkTree=Qs,exports.walkWorkingTree=async function*(e,t){const n={ctx:e,maxDepth:t?.maxDepth??4096,maxEntries:t?.maxEntries??C,ignore:t?.ignore};yield*ki(n,{value:0},"",0,!0)},exports.writeNotesTree=async function(e,t){const n=await((e,t,n=0,r=0)=>Ad(e,t,n,r,""))(t.trie,t.read);return tc(e,{tree:await Dd(e,n.entries),parents:void 0!==t.prevCommitOid?[t.prevCommitOid]:[],author:t.author,committer:t.author,message:t.message})},exports.writeObject=Ci,exports.writeReflog=async function(e,t,n){const r=n.map(on).join("");await e.fs.writeUtf8(sr(er(e,t),t),r)},exports.writeSparsePatternText=async(e,t)=>{await e.fs.mkdir(`${e.layout.gitDir}/info`),await e.fs.writeUtf8(ir(e.layout.gitDir),t)},exports.writeTree=Xa,exports.writeWorkingTreeEntry=Qo,exports.writeWorkingTreeFile=async(e,t,n)=>{await Jo(e,Do(e.layout.workDir,t),n)},exports.writeWorkingTreeFileStream=async(e,t,n)=>{await Zo(e,Do(e.layout.workDir,t),n)};
2
- //# sourceMappingURL=write-sparse-checkout-DzVubBcI.cjs.map