@statewalker/vcs-commands 0.8.0 → 0.10.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 (622) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/add-command.d.ts +32 -0
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/add-patch/add-patch.d.ts +7 -0
  5. package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
  6. package/dist/commands/add-patch/patch-backend.d.ts +2 -0
  7. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  8. package/dist/commands/add-patch/patch-modes.d.ts +6 -2
  9. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -1
  10. package/dist/commands/add-patch/patch-session.d.ts +4 -0
  11. package/dist/commands/add-patch/patch-session.d.ts.map +1 -1
  12. package/dist/commands/am/am-command.d.ts +88 -2
  13. package/dist/commands/am/am-command.d.ts.map +1 -1
  14. package/dist/commands/apply/apply-command.d.ts +2 -0
  15. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  16. package/dist/commands/apply/apply-parse.d.ts +7 -0
  17. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  18. package/dist/commands/apply/index.d.ts +1 -1
  19. package/dist/commands/apply/index.d.ts.map +1 -1
  20. package/dist/commands/archive/archive-command.d.ts +169 -0
  21. package/dist/commands/archive/archive-command.d.ts.map +1 -0
  22. package/dist/commands/archive/archive-entry.d.ts +60 -0
  23. package/dist/commands/archive/archive-entry.d.ts.map +1 -0
  24. package/dist/commands/archive/index.d.ts +8 -0
  25. package/dist/commands/archive/index.d.ts.map +1 -0
  26. package/dist/commands/archive/remote-archive-command.d.ts +56 -0
  27. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -0
  28. package/dist/commands/archive/tar-archive.d.ts +31 -0
  29. package/dist/commands/archive/tar-archive.d.ts.map +1 -0
  30. package/dist/commands/archive/tar-commit-id.d.ts +13 -0
  31. package/dist/commands/archive/tar-commit-id.d.ts.map +1 -0
  32. package/dist/commands/archive/upload-archive-writer.d.ts +48 -0
  33. package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -0
  34. package/dist/commands/archive/zip-archive.d.ts +42 -0
  35. package/dist/commands/archive/zip-archive.d.ts.map +1 -0
  36. package/dist/commands/attributes-source.d.ts +10 -0
  37. package/dist/commands/attributes-source.d.ts.map +1 -1
  38. package/dist/commands/blame-command.d.ts +345 -8
  39. package/dist/commands/blame-command.d.ts.map +1 -1
  40. package/dist/commands/blame-ignore.d.ts +48 -0
  41. package/dist/commands/blame-ignore.d.ts.map +1 -0
  42. package/dist/commands/bundle/bundle-create-command.d.ts +67 -0
  43. package/dist/commands/bundle/bundle-create-command.d.ts.map +1 -0
  44. package/dist/commands/bundle/bundle-format.d.ts +89 -0
  45. package/dist/commands/bundle/bundle-format.d.ts.map +1 -0
  46. package/dist/commands/bundle/bundle-list.d.ts +92 -0
  47. package/dist/commands/bundle/bundle-list.d.ts.map +1 -0
  48. package/dist/commands/bundle/bundle-read-commands.d.ts +81 -0
  49. package/dist/commands/bundle/bundle-read-commands.d.ts.map +1 -0
  50. package/dist/commands/bundle/bundle-support.d.ts +32 -0
  51. package/dist/commands/bundle/bundle-support.d.ts.map +1 -0
  52. package/dist/commands/bundle/bundle-transport.d.ts +38 -0
  53. package/dist/commands/bundle/bundle-transport.d.ts.map +1 -0
  54. package/dist/commands/bundle/bundle-uri-host.d.ts +43 -0
  55. package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -0
  56. package/dist/commands/bundle/bundle-uri.d.ts +55 -0
  57. package/dist/commands/bundle/bundle-uri.d.ts.map +1 -0
  58. package/dist/commands/bundle/bundle-verify.d.ts +63 -0
  59. package/dist/commands/bundle/bundle-verify.d.ts.map +1 -0
  60. package/dist/commands/bundle/index.d.ts +14 -0
  61. package/dist/commands/bundle/index.d.ts.map +1 -0
  62. package/dist/commands/cat-file/batch-format.d.ts +58 -0
  63. package/dist/commands/cat-file/batch-format.d.ts.map +1 -0
  64. package/dist/commands/cat-file/cat-file-command.d.ts +135 -0
  65. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -0
  66. package/dist/commands/cat-file/index.d.ts +3 -0
  67. package/dist/commands/cat-file/index.d.ts.map +1 -0
  68. package/dist/commands/check-attr-command.d.ts +66 -0
  69. package/dist/commands/check-attr-command.d.ts.map +1 -0
  70. package/dist/commands/check-ignore-command.d.ts +58 -0
  71. package/dist/commands/check-ignore-command.d.ts.map +1 -0
  72. package/dist/commands/check-mailmap-command.d.ts +49 -0
  73. package/dist/commands/check-mailmap-command.d.ts.map +1 -0
  74. package/dist/commands/check-ref-format-command.d.ts +60 -0
  75. package/dist/commands/check-ref-format-command.d.ts.map +1 -0
  76. package/dist/commands/checkout-command.d.ts +7 -0
  77. package/dist/commands/checkout-command.d.ts.map +1 -1
  78. package/dist/commands/checkout-index-command.d.ts +96 -0
  79. package/dist/commands/checkout-index-command.d.ts.map +1 -0
  80. package/dist/commands/checkout-paths.d.ts +4 -0
  81. package/dist/commands/checkout-paths.d.ts.map +1 -1
  82. package/dist/commands/cherry-command.d.ts +61 -0
  83. package/dist/commands/cherry-command.d.ts.map +1 -0
  84. package/dist/commands/cherry-pick-command.d.ts +33 -1
  85. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  86. package/dist/commands/clean-command.d.ts +32 -0
  87. package/dist/commands/clean-command.d.ts.map +1 -1
  88. package/dist/commands/clean-interactive.d.ts +56 -0
  89. package/dist/commands/clean-interactive.d.ts.map +1 -0
  90. package/dist/commands/clone-command.d.ts +135 -2
  91. package/dist/commands/clone-command.d.ts.map +1 -1
  92. package/dist/commands/commit-command.d.ts +59 -3
  93. package/dist/commands/commit-command.d.ts.map +1 -1
  94. package/dist/commands/config-command.d.ts +2 -0
  95. package/dist/commands/config-command.d.ts.map +1 -1
  96. package/dist/commands/daemon-access-hook.d.ts +36 -0
  97. package/dist/commands/daemon-access-hook.d.ts.map +1 -0
  98. package/dist/commands/default-branch.d.ts +42 -0
  99. package/dist/commands/default-branch.d.ts.map +1 -1
  100. package/dist/commands/describe-command.d.ts +71 -64
  101. package/dist/commands/describe-command.d.ts.map +1 -1
  102. package/dist/commands/diff-command.d.ts +249 -10
  103. package/dist/commands/diff-command.d.ts.map +1 -1
  104. package/dist/commands/diff-external.d.ts +43 -0
  105. package/dist/commands/diff-external.d.ts.map +1 -0
  106. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts +27 -0
  107. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts.map +1 -0
  108. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts +129 -0
  109. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts.map +1 -0
  110. package/dist/commands/diff-plumbing/index.d.ts +3 -0
  111. package/dist/commands/diff-plumbing/index.d.ts.map +1 -0
  112. package/dist/commands/diff-textconv.d.ts +5 -1
  113. package/dist/commands/diff-textconv.d.ts.map +1 -1
  114. package/dist/commands/fast-export/fast-export-command.d.ts +135 -0
  115. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -0
  116. package/dist/commands/fast-export/fast-import-command.d.ts +182 -0
  117. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -0
  118. package/dist/commands/fast-export/fast-stream-support.d.ts +64 -0
  119. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -0
  120. package/dist/commands/fast-export/index.d.ts +4 -0
  121. package/dist/commands/fast-export/index.d.ts.map +1 -0
  122. package/dist/commands/fetch-command.d.ts +125 -0
  123. package/dist/commands/fetch-command.d.ts.map +1 -1
  124. package/dist/commands/fetch-multiple-command.d.ts +193 -0
  125. package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
  126. package/dist/commands/format-patch-command.d.ts +28 -2
  127. package/dist/commands/format-patch-command.d.ts.map +1 -1
  128. package/dist/commands/format-rev-command.d.ts +58 -0
  129. package/dist/commands/format-rev-command.d.ts.map +1 -0
  130. package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
  131. package/dist/commands/fsck/fsck-msg-ids.d.ts +18 -3
  132. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -1
  133. package/dist/commands/fsmonitor-refresh.d.ts +69 -0
  134. package/dist/commands/fsmonitor-refresh.d.ts.map +1 -0
  135. package/dist/commands/gc-command.d.ts +5 -0
  136. package/dist/commands/gc-command.d.ts.map +1 -1
  137. package/dist/commands/git-describe.d.ts +77 -4
  138. package/dist/commands/git-describe.d.ts.map +1 -1
  139. package/dist/commands/git-hooks.d.ts +47 -1
  140. package/dist/commands/git-hooks.d.ts.map +1 -1
  141. package/dist/commands/git-paths.d.ts +26 -0
  142. package/dist/commands/git-paths.d.ts.map +1 -0
  143. package/dist/commands/grep/grep-command.d.ts +2 -1
  144. package/dist/commands/grep/grep-command.d.ts.map +1 -1
  145. package/dist/commands/history-command.d.ts +156 -0
  146. package/dist/commands/history-command.d.ts.map +1 -0
  147. package/dist/commands/http-config.d.ts +38 -0
  148. package/dist/commands/http-config.d.ts.map +1 -0
  149. package/dist/commands/index-adder.d.ts +12 -1
  150. package/dist/commands/index-adder.d.ts.map +1 -1
  151. package/dist/commands/index-host.d.ts.map +1 -1
  152. package/dist/commands/index.d.ts +56 -1
  153. package/dist/commands/index.d.ts.map +1 -1
  154. package/dist/commands/index.js +6 -3
  155. package/dist/commands/init-command.d.ts +89 -0
  156. package/dist/commands/init-command.d.ts.map +1 -1
  157. package/dist/commands/last-modified-command.d.ts +102 -0
  158. package/dist/commands/last-modified-command.d.ts.map +1 -0
  159. package/dist/commands/lfs/go-url.d.ts +43 -0
  160. package/dist/commands/lfs/go-url.d.ts.map +1 -0
  161. package/dist/commands/lfs/index.d.ts +3 -0
  162. package/dist/commands/lfs/index.d.ts.map +1 -0
  163. package/dist/commands/lfs/lfs-config.d.ts +174 -0
  164. package/dist/commands/lfs/lfs-config.d.ts.map +1 -0
  165. package/dist/commands/lfs/lfs-endpoint-command.d.ts +83 -0
  166. package/dist/commands/lfs/lfs-endpoint-command.d.ts.map +1 -0
  167. package/dist/commands/line-log.d.ts +161 -0
  168. package/dist/commands/line-log.d.ts.map +1 -0
  169. package/dist/commands/local-transport.d.ts.map +1 -1
  170. package/dist/commands/log-command.d.ts +261 -6
  171. package/dist/commands/log-command.d.ts.map +1 -1
  172. package/dist/commands/log-graph.d.ts +4 -2
  173. package/dist/commands/log-graph.d.ts.map +1 -1
  174. package/dist/commands/log-output.d.ts +88 -2
  175. package/dist/commands/log-output.d.ts.map +1 -1
  176. package/dist/commands/ls-files-command.d.ts +153 -0
  177. package/dist/commands/ls-files-command.d.ts.map +1 -0
  178. package/dist/commands/ls-remote-command.d.ts +5 -0
  179. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  180. package/dist/commands/ls-tree-command.d.ts +105 -0
  181. package/dist/commands/ls-tree-command.d.ts.map +1 -0
  182. package/dist/commands/mailmap.d.ts +24 -1
  183. package/dist/commands/mailmap.d.ts.map +1 -1
  184. package/dist/commands/maintenance-run-command.d.ts +122 -0
  185. package/dist/commands/maintenance-run-command.d.ts.map +1 -0
  186. package/dist/commands/merge-command.d.ts +58 -1
  187. package/dist/commands/merge-command.d.ts.map +1 -1
  188. package/dist/commands/merge-config.d.ts +7 -0
  189. package/dist/commands/merge-config.d.ts.map +1 -1
  190. package/dist/commands/merge-drivers.d.ts +69 -5
  191. package/dist/commands/merge-drivers.d.ts.map +1 -1
  192. package/dist/commands/merge-strategy-options.d.ts +69 -0
  193. package/dist/commands/merge-strategy-options.d.ts.map +1 -0
  194. package/dist/commands/merge-support.d.ts +16 -0
  195. package/dist/commands/merge-support.d.ts.map +1 -1
  196. package/dist/commands/merge-tree-command.d.ts +122 -0
  197. package/dist/commands/merge-tree-command.d.ts.map +1 -0
  198. package/dist/commands/message-cleanup.d.ts +2 -0
  199. package/dist/commands/message-cleanup.d.ts.map +1 -1
  200. package/dist/commands/mktag-command.d.ts +51 -0
  201. package/dist/commands/mktag-command.d.ts.map +1 -0
  202. package/dist/commands/name-rev-command.d.ts +65 -0
  203. package/dist/commands/name-rev-command.d.ts.map +1 -0
  204. package/dist/commands/name-rev.d.ts +110 -22
  205. package/dist/commands/name-rev.d.ts.map +1 -1
  206. package/dist/commands/object-store/count-objects-command.d.ts +58 -0
  207. package/dist/commands/object-store/count-objects-command.d.ts.map +1 -0
  208. package/dist/commands/object-store/index.d.ts +5 -0
  209. package/dist/commands/object-store/index.d.ts.map +1 -0
  210. package/dist/commands/object-store/objects-directory.d.ts +12 -0
  211. package/dist/commands/object-store/objects-directory.d.ts.map +1 -0
  212. package/dist/commands/object-store/prune-command.d.ts +38 -0
  213. package/dist/commands/object-store/prune-command.d.ts.map +1 -0
  214. package/dist/commands/object-store/show-index-command.d.ts +23 -0
  215. package/dist/commands/object-store/show-index-command.d.ts.map +1 -0
  216. package/dist/commands/octopus-merge.d.ts +26 -1
  217. package/dist/commands/octopus-merge.d.ts.map +1 -1
  218. package/dist/commands/ort-merge.d.ts +40 -0
  219. package/dist/commands/ort-merge.d.ts.map +1 -1
  220. package/dist/commands/ort-recursive.d.ts.map +1 -1
  221. package/dist/commands/patch-id-command.d.ts +30 -0
  222. package/dist/commands/patch-id-command.d.ts.map +1 -0
  223. package/dist/commands/patch-id.d.ts +82 -0
  224. package/dist/commands/patch-id.d.ts.map +1 -1
  225. package/dist/commands/plumbing-command.d.ts +66 -0
  226. package/dist/commands/plumbing-command.d.ts.map +1 -0
  227. package/dist/commands/plumbing-input.d.ts +38 -0
  228. package/dist/commands/plumbing-input.d.ts.map +1 -0
  229. package/dist/commands/promisor-remote-reply.d.ts +35 -0
  230. package/dist/commands/promisor-remote-reply.d.ts.map +1 -0
  231. package/dist/commands/promisor-remote.d.ts.map +1 -1
  232. package/dist/commands/pull-command.d.ts +182 -38
  233. package/dist/commands/pull-command.d.ts.map +1 -1
  234. package/dist/commands/push-command.d.ts +82 -2
  235. package/dist/commands/push-command.d.ts.map +1 -1
  236. package/dist/commands/range-diff/index.d.ts +4 -0
  237. package/dist/commands/range-diff/index.d.ts.map +1 -0
  238. package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
  239. package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
  240. package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
  241. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
  242. package/dist/commands/range-diff/range-diff.d.ts +106 -0
  243. package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
  244. package/dist/commands/read-tree-command.d.ts +14 -0
  245. package/dist/commands/read-tree-command.d.ts.map +1 -1
  246. package/dist/commands/rebase-command.d.ts +129 -4
  247. package/dist/commands/rebase-command.d.ts.map +1 -1
  248. package/dist/commands/refs-command.d.ts +81 -0
  249. package/dist/commands/refs-command.d.ts.map +1 -0
  250. package/dist/commands/remerge-diff.d.ts +59 -0
  251. package/dist/commands/remerge-diff.d.ts.map +1 -0
  252. package/dist/commands/remote-command.d.ts +41 -0
  253. package/dist/commands/remote-command.d.ts.map +1 -1
  254. package/dist/commands/remote-object-info-command.d.ts +55 -0
  255. package/dist/commands/remote-object-info-command.d.ts.map +1 -0
  256. package/dist/commands/remote-show-command.d.ts +204 -0
  257. package/dist/commands/remote-show-command.d.ts.map +1 -0
  258. package/dist/commands/remote-transport.d.ts +40 -3
  259. package/dist/commands/remote-transport.d.ts.map +1 -1
  260. package/dist/commands/repack-command.d.ts +115 -0
  261. package/dist/commands/repack-command.d.ts.map +1 -0
  262. package/dist/commands/replace-command.d.ts +143 -0
  263. package/dist/commands/replace-command.d.ts.map +1 -0
  264. package/dist/commands/replay-command.d.ts +117 -0
  265. package/dist/commands/replay-command.d.ts.map +1 -0
  266. package/dist/commands/repo-command.d.ts +136 -0
  267. package/dist/commands/repo-command.d.ts.map +1 -0
  268. package/dist/commands/request-pull-command.d.ts +82 -0
  269. package/dist/commands/request-pull-command.d.ts.map +1 -0
  270. package/dist/commands/rerere-command.d.ts +36 -0
  271. package/dist/commands/rerere-command.d.ts.map +1 -0
  272. package/dist/commands/rerere.d.ts +102 -0
  273. package/dist/commands/rerere.d.ts.map +1 -0
  274. package/dist/commands/reset-command.d.ts +19 -1
  275. package/dist/commands/reset-command.d.ts.map +1 -1
  276. package/dist/commands/restore-command.d.ts +7 -0
  277. package/dist/commands/restore-command.d.ts.map +1 -1
  278. package/dist/commands/rev-filter/commit-grep.d.ts +3 -1
  279. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -1
  280. package/dist/commands/rev-list-command.d.ts +78 -3
  281. package/dist/commands/rev-list-command.d.ts.map +1 -1
  282. package/dist/commands/rev-parse-command.d.ts +9 -0
  283. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  284. package/dist/commands/revert-command.d.ts +32 -1
  285. package/dist/commands/revert-command.d.ts.map +1 -1
  286. package/dist/commands/revision-range.d.ts +7 -0
  287. package/dist/commands/revision-range.d.ts.map +1 -1
  288. package/dist/commands/revision-resolver.d.ts +12 -0
  289. package/dist/commands/revision-resolver.d.ts.map +1 -1
  290. package/dist/commands/sequencer-pick.d.ts +120 -1
  291. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  292. package/dist/commands/sequencer-support.d.ts +10 -1
  293. package/dist/commands/sequencer-support.d.ts.map +1 -1
  294. package/dist/commands/serve-repository.d.ts +23 -1
  295. package/dist/commands/serve-repository.d.ts.map +1 -1
  296. package/dist/commands/session-id.d.ts +18 -0
  297. package/dist/commands/session-id.d.ts.map +1 -0
  298. package/dist/commands/shortlog-command.d.ts +109 -0
  299. package/dist/commands/shortlog-command.d.ts.map +1 -0
  300. package/dist/commands/shortlog.d.ts +151 -0
  301. package/dist/commands/shortlog.d.ts.map +1 -0
  302. package/dist/commands/show-branch-command.d.ts +59 -0
  303. package/dist/commands/show-branch-command.d.ts.map +1 -0
  304. package/dist/commands/show-ref-command.d.ts +112 -0
  305. package/dist/commands/show-ref-command.d.ts.map +1 -0
  306. package/dist/commands/signature-check.d.ts +9 -2
  307. package/dist/commands/signature-check.d.ts.map +1 -1
  308. package/dist/commands/signing.d.ts +22 -1
  309. package/dist/commands/signing.d.ts.map +1 -1
  310. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  311. package/dist/commands/stash-export-command.d.ts +115 -0
  312. package/dist/commands/stash-export-command.d.ts.map +1 -0
  313. package/dist/commands/status-command.d.ts +33 -3
  314. package/dist/commands/status-command.d.ts.map +1 -1
  315. package/dist/commands/stripspace-command.d.ts +44 -0
  316. package/dist/commands/stripspace-command.d.ts.map +1 -0
  317. package/dist/commands/submodule-add-command.d.ts +10 -1
  318. package/dist/commands/submodule-add-command.d.ts.map +1 -1
  319. package/dist/commands/submodule-auth.d.ts +3 -1
  320. package/dist/commands/submodule-auth.d.ts.map +1 -1
  321. package/dist/commands/submodule-commands.d.ts +99 -3
  322. package/dist/commands/submodule-commands.d.ts.map +1 -1
  323. package/dist/commands/submodule-fetch.d.ts +149 -0
  324. package/dist/commands/submodule-fetch.d.ts.map +1 -0
  325. package/dist/commands/submodule-model.d.ts +8 -0
  326. package/dist/commands/submodule-model.d.ts.map +1 -1
  327. package/dist/commands/submodule-unpack.d.ts +120 -0
  328. package/dist/commands/submodule-unpack.d.ts.map +1 -0
  329. package/dist/commands/submodule-update-command.d.ts +21 -1
  330. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  331. package/dist/commands/subtree-shift.d.ts +27 -0
  332. package/dist/commands/subtree-shift.d.ts.map +1 -0
  333. package/dist/commands/switch-command.d.ts +3 -0
  334. package/dist/commands/switch-command.d.ts.map +1 -1
  335. package/dist/commands/textconv-cache.d.ts +58 -0
  336. package/dist/commands/textconv-cache.d.ts.map +1 -0
  337. package/dist/commands/tree-restore.d.ts +5 -0
  338. package/dist/commands/tree-restore.d.ts.map +1 -1
  339. package/dist/commands/unpack-objects-command.d.ts +47 -0
  340. package/dist/commands/unpack-objects-command.d.ts.map +1 -0
  341. package/dist/commands/update-index-command.d.ts +110 -0
  342. package/dist/commands/update-index-command.d.ts.map +1 -0
  343. package/dist/commands/uri-protocols.d.ts +13 -0
  344. package/dist/commands/uri-protocols.d.ts.map +1 -0
  345. package/dist/commands/url-parse-command.d.ts +30 -0
  346. package/dist/commands/url-parse-command.d.ts.map +1 -0
  347. package/dist/commands/var-command.d.ts +42 -0
  348. package/dist/commands/var-command.d.ts.map +1 -0
  349. package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
  350. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  351. package/dist/{commands-ISM52N0n.js → commands-Mlo1dxQN.js} +56133 -70269
  352. package/dist/errors/command-errors.d.ts +58 -0
  353. package/dist/errors/command-errors.d.ts.map +1 -1
  354. package/dist/errors/index.js +67 -1
  355. package/dist/fsck-CrhVMNIH.js +5179 -0
  356. package/dist/git-command.d.ts +89 -3
  357. package/dist/git-command.d.ts.map +1 -1
  358. package/dist/git.d.ts +628 -1
  359. package/dist/git.d.ts.map +1 -1
  360. package/dist/guarded-transport-command.d.ts +84 -0
  361. package/dist/guarded-transport-command.d.ts.map +1 -0
  362. package/dist/index.d.ts +1 -0
  363. package/dist/index.d.ts.map +1 -1
  364. package/dist/index.js +7 -5
  365. package/dist/maintenance-run-command-Bw21HEkH.js +13539 -0
  366. package/dist/remote-transport-Bu4PGSMD.js +2605 -0
  367. package/dist/rename/detect-renames.d.ts +20 -0
  368. package/dist/rename/detect-renames.d.ts.map +1 -1
  369. package/dist/rename/diffcore-break.d.ts +51 -0
  370. package/dist/rename/diffcore-break.d.ts.map +1 -0
  371. package/dist/rename/index.d.ts +1 -0
  372. package/dist/rename/index.d.ts.map +1 -1
  373. package/dist/results/blame-format.d.ts +62 -1
  374. package/dist/results/blame-format.d.ts.map +1 -1
  375. package/dist/results/cherry-pick-result.d.ts +6 -0
  376. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  377. package/dist/results/clone-result.d.ts +9 -0
  378. package/dist/results/clone-result.d.ts.map +1 -1
  379. package/dist/results/diff-dirstat.d.ts +36 -0
  380. package/dist/results/diff-dirstat.d.ts.map +1 -0
  381. package/dist/results/diff-entry.d.ts +20 -0
  382. package/dist/results/diff-entry.d.ts.map +1 -1
  383. package/dist/results/diff-formatter.d.ts.map +1 -1
  384. package/dist/results/diff-output.d.ts +67 -3
  385. package/dist/results/diff-output.d.ts.map +1 -1
  386. package/dist/results/fetch-result.d.ts +24 -1
  387. package/dist/results/fetch-result.d.ts.map +1 -1
  388. package/dist/results/index.d.ts +2 -0
  389. package/dist/results/index.d.ts.map +1 -1
  390. package/dist/results/index.js +2 -2
  391. package/dist/results/init-result.d.ts +8 -1
  392. package/dist/results/init-result.d.ts.map +1 -1
  393. package/dist/results/line-range-hunks.d.ts +27 -0
  394. package/dist/results/line-range-hunks.d.ts.map +1 -0
  395. package/dist/results/merge-result.d.ts +13 -1
  396. package/dist/results/merge-result.d.ts.map +1 -1
  397. package/dist/results/pull-result.d.ts +11 -0
  398. package/dist/results/pull-result.d.ts.map +1 -1
  399. package/dist/results/push-result.d.ts +10 -0
  400. package/dist/results/push-result.d.ts.map +1 -1
  401. package/dist/results/rebase-result.d.ts +7 -0
  402. package/dist/results/rebase-result.d.ts.map +1 -1
  403. package/dist/results/revert-result.d.ts +6 -0
  404. package/dist/results/revert-result.d.ts.map +1 -1
  405. package/dist/results/stash-result.d.ts +5 -0
  406. package/dist/results/stash-result.d.ts.map +1 -1
  407. package/dist/results/status-result.d.ts +1 -1
  408. package/dist/results/status-result.d.ts.map +1 -1
  409. package/dist/results-ERo9vELd.js +49673 -0
  410. package/dist/transport-command.d.ts +93 -1
  411. package/dist/transport-command.d.ts.map +1 -1
  412. package/package.json +12 -12
  413. package/src/commands/add-command.ts +118 -0
  414. package/src/commands/add-patch/add-patch.ts +8 -0
  415. package/src/commands/add-patch/patch-backend.ts +24 -3
  416. package/src/commands/add-patch/patch-modes.ts +26 -2
  417. package/src/commands/add-patch/patch-session.ts +6 -0
  418. package/src/commands/am/am-command.ts +301 -12
  419. package/src/commands/apply/apply-command.ts +52 -9
  420. package/src/commands/apply/apply-parse.ts +10 -0
  421. package/src/commands/apply/index.ts +9 -1
  422. package/src/commands/archive/archive-command.ts +1148 -0
  423. package/src/commands/archive/archive-entry.ts +93 -0
  424. package/src/commands/archive/index.ts +7 -0
  425. package/src/commands/archive/remote-archive-command.ts +140 -0
  426. package/src/commands/archive/tar-archive.ts +207 -0
  427. package/src/commands/archive/tar-commit-id.ts +72 -0
  428. package/src/commands/archive/upload-archive-writer.ts +213 -0
  429. package/src/commands/archive/zip-archive.ts +317 -0
  430. package/src/commands/attributes-source.ts +26 -12
  431. package/src/commands/blame-command.ts +1551 -53
  432. package/src/commands/blame-ignore.ts +307 -0
  433. package/src/commands/bundle/bundle-create-command.ts +405 -0
  434. package/src/commands/bundle/bundle-format.ts +228 -0
  435. package/src/commands/bundle/bundle-list.ts +276 -0
  436. package/src/commands/bundle/bundle-read-commands.ts +157 -0
  437. package/src/commands/bundle/bundle-support.ts +85 -0
  438. package/src/commands/bundle/bundle-transport.ts +107 -0
  439. package/src/commands/bundle/bundle-uri-host.ts +204 -0
  440. package/src/commands/bundle/bundle-uri.ts +236 -0
  441. package/src/commands/bundle/bundle-verify.ts +152 -0
  442. package/src/commands/bundle/index.ts +14 -0
  443. package/src/commands/cat-file/batch-format.ts +193 -0
  444. package/src/commands/cat-file/cat-file-command.ts +857 -0
  445. package/src/commands/cat-file/index.ts +2 -0
  446. package/src/commands/check-attr-command.ts +333 -0
  447. package/src/commands/check-ignore-command.ts +261 -0
  448. package/src/commands/check-mailmap-command.ts +129 -0
  449. package/src/commands/check-ref-format-command.ts +129 -0
  450. package/src/commands/checkout-command.ts +131 -28
  451. package/src/commands/checkout-index-command.ts +568 -0
  452. package/src/commands/checkout-paths.ts +35 -0
  453. package/src/commands/cherry-command.ts +187 -0
  454. package/src/commands/cherry-pick-command.ts +63 -2
  455. package/src/commands/clean-command.ts +92 -12
  456. package/src/commands/clean-interactive.ts +522 -0
  457. package/src/commands/clone-command.ts +803 -50
  458. package/src/commands/commit-command.ts +202 -51
  459. package/src/commands/config-command.ts +9 -0
  460. package/src/commands/daemon-access-hook.ts +78 -0
  461. package/src/commands/default-branch.ts +99 -1
  462. package/src/commands/describe-command.ts +341 -254
  463. package/src/commands/diff-command.ts +1186 -99
  464. package/src/commands/diff-external.ts +131 -0
  465. package/src/commands/diff-plumbing/diff-pairs-command.ts +193 -0
  466. package/src/commands/diff-plumbing/diff-plumbing-command.ts +424 -0
  467. package/src/commands/diff-plumbing/index.ts +2 -0
  468. package/src/commands/diff-textconv.ts +5 -1
  469. package/src/commands/fast-export/fast-export-command.ts +911 -0
  470. package/src/commands/fast-export/fast-import-command.ts +1553 -0
  471. package/src/commands/fast-export/fast-stream-support.ts +162 -0
  472. package/src/commands/fast-export/index.ts +3 -0
  473. package/src/commands/fetch-command.ts +665 -14
  474. package/src/commands/fetch-multiple-command.ts +668 -0
  475. package/src/commands/format-patch-command.ts +189 -77
  476. package/src/commands/format-rev-command.ts +251 -0
  477. package/src/commands/fsck/fsck-command.ts +47 -20
  478. package/src/commands/fsck/fsck-msg-ids.ts +19 -3
  479. package/src/commands/fsck/fsck-pack.ts +2 -2
  480. package/src/commands/fsmonitor-refresh.ts +315 -0
  481. package/src/commands/gc-command.ts +10 -0
  482. package/src/commands/git-describe.ts +456 -217
  483. package/src/commands/git-hooks.ts +165 -9
  484. package/src/commands/git-paths.ts +136 -0
  485. package/src/commands/grep/grep-command.ts +38 -15
  486. package/src/commands/history-command.ts +617 -0
  487. package/src/commands/http-config.ts +139 -0
  488. package/src/commands/index-adder.ts +37 -3
  489. package/src/commands/index-host.ts +6 -1
  490. package/src/commands/index.ts +62 -0
  491. package/src/commands/init-command.ts +617 -49
  492. package/src/commands/last-modified-command.ts +804 -0
  493. package/src/commands/lfs/go-url.ts +370 -0
  494. package/src/commands/lfs/index.ts +2 -0
  495. package/src/commands/lfs/lfs-config.ts +738 -0
  496. package/src/commands/lfs/lfs-endpoint-command.ts +180 -0
  497. package/src/commands/line-log.ts +931 -0
  498. package/src/commands/local-transport.ts +252 -4
  499. package/src/commands/log-command.ts +1518 -182
  500. package/src/commands/log-graph.ts +6 -3
  501. package/src/commands/log-output.ts +228 -15
  502. package/src/commands/ls-files-command.ts +1177 -0
  503. package/src/commands/ls-remote-command.ts +6 -0
  504. package/src/commands/ls-tree-command.ts +684 -0
  505. package/src/commands/mailmap.ts +41 -5
  506. package/src/commands/maintenance-run-command.ts +949 -0
  507. package/src/commands/merge-command.ts +351 -47
  508. package/src/commands/merge-config.ts +23 -1
  509. package/src/commands/merge-drivers.ts +112 -20
  510. package/src/commands/merge-strategy-options.ts +224 -0
  511. package/src/commands/merge-support.ts +130 -26
  512. package/src/commands/merge-tree-command.ts +786 -0
  513. package/src/commands/message-cleanup.ts +1 -1
  514. package/src/commands/mktag-command.ts +149 -0
  515. package/src/commands/name-rev-command.ts +184 -0
  516. package/src/commands/name-rev.ts +700 -109
  517. package/src/commands/object-store/count-objects-command.ts +404 -0
  518. package/src/commands/object-store/index.ts +4 -0
  519. package/src/commands/object-store/objects-directory.ts +24 -0
  520. package/src/commands/object-store/prune-command.ts +129 -0
  521. package/src/commands/object-store/show-index-command.ts +151 -0
  522. package/src/commands/octopus-merge.ts +35 -11
  523. package/src/commands/ort-merge.ts +124 -23
  524. package/src/commands/ort-recursive.ts +40 -2
  525. package/src/commands/patch-id-command.ts +65 -0
  526. package/src/commands/patch-id.ts +327 -0
  527. package/src/commands/plumbing-command.ts +141 -0
  528. package/src/commands/plumbing-input.ts +87 -0
  529. package/src/commands/promisor-remote-reply.ts +276 -0
  530. package/src/commands/promisor-remote.ts +25 -2
  531. package/src/commands/pull-command.ts +720 -224
  532. package/src/commands/push-command.ts +440 -8
  533. package/src/commands/range-diff/index.ts +3 -0
  534. package/src/commands/range-diff/linear-assignment.ts +203 -0
  535. package/src/commands/range-diff/range-diff-command.ts +433 -0
  536. package/src/commands/range-diff/range-diff.ts +617 -0
  537. package/src/commands/read-tree-command.ts +74 -3
  538. package/src/commands/rebase-command.ts +647 -83
  539. package/src/commands/refs-command.ts +274 -0
  540. package/src/commands/remerge-diff.ts +241 -0
  541. package/src/commands/remote-command.ts +98 -10
  542. package/src/commands/remote-object-info-command.ts +109 -0
  543. package/src/commands/remote-show-command.ts +836 -0
  544. package/src/commands/remote-transport.ts +116 -1
  545. package/src/commands/repack-command.ts +383 -0
  546. package/src/commands/replace-command.ts +816 -0
  547. package/src/commands/replay-command.ts +674 -0
  548. package/src/commands/repo-command.ts +967 -0
  549. package/src/commands/request-pull-command.ts +356 -0
  550. package/src/commands/rerere-command.ts +179 -0
  551. package/src/commands/rerere.ts +925 -0
  552. package/src/commands/reset-command.ts +78 -3
  553. package/src/commands/restore-command.ts +15 -0
  554. package/src/commands/rev-filter/commit-grep.ts +7 -2
  555. package/src/commands/rev-list-command.ts +196 -11
  556. package/src/commands/rev-parse-command.ts +62 -4
  557. package/src/commands/revert-command.ts +62 -2
  558. package/src/commands/revision-range.ts +10 -3
  559. package/src/commands/revision-resolver.ts +44 -3
  560. package/src/commands/sequencer-pick.ts +370 -29
  561. package/src/commands/sequencer-support.ts +164 -2
  562. package/src/commands/serve-repository.ts +65 -0
  563. package/src/commands/session-id.ts +31 -0
  564. package/src/commands/shortlog-command.ts +354 -0
  565. package/src/commands/shortlog.ts +361 -0
  566. package/src/commands/show-branch-command.ts +981 -0
  567. package/src/commands/show-command.ts +3 -2
  568. package/src/commands/show-ref-command.ts +439 -0
  569. package/src/commands/signature-check.ts +37 -5
  570. package/src/commands/signing.ts +122 -16
  571. package/src/commands/stash-apply-command.ts +3 -0
  572. package/src/commands/stash-export-command.ts +397 -0
  573. package/src/commands/status-command.ts +158 -31
  574. package/src/commands/status-format.ts +1 -1
  575. package/src/commands/stripspace-command.ts +118 -0
  576. package/src/commands/submodule-add-command.ts +22 -1
  577. package/src/commands/submodule-auth.ts +61 -6
  578. package/src/commands/submodule-commands.ts +333 -5
  579. package/src/commands/submodule-fetch.ts +789 -0
  580. package/src/commands/submodule-model.ts +9 -1
  581. package/src/commands/submodule-unpack.ts +265 -0
  582. package/src/commands/submodule-update-command.ts +68 -5
  583. package/src/commands/subtree-shift.ts +215 -0
  584. package/src/commands/switch-command.ts +9 -0
  585. package/src/commands/textconv-cache.ts +143 -0
  586. package/src/commands/tree-restore.ts +20 -1
  587. package/src/commands/unpack-objects-command.ts +235 -0
  588. package/src/commands/update-index-command.ts +1016 -0
  589. package/src/commands/uri-protocols.ts +13 -0
  590. package/src/commands/url-parse-command.ts +67 -0
  591. package/src/commands/var-command.ts +219 -0
  592. package/src/commands/worktree-overwrite-checks.ts +5 -0
  593. package/src/errors/command-errors.ts +80 -0
  594. package/src/git-command.ts +218 -2
  595. package/src/git.ts +1033 -80
  596. package/src/guarded-transport-command.ts +176 -0
  597. package/src/index.ts +1 -0
  598. package/src/rename/detect-renames.ts +42 -8
  599. package/src/rename/diffcore-break.ts +166 -0
  600. package/src/rename/index.ts +1 -0
  601. package/src/results/blame-format.ts +268 -43
  602. package/src/results/cherry-pick-result.ts +6 -0
  603. package/src/results/clone-result.ts +6 -0
  604. package/src/results/diff-dirstat.ts +117 -0
  605. package/src/results/diff-entry.ts +24 -0
  606. package/src/results/diff-formatter.ts +8 -4
  607. package/src/results/diff-output.ts +239 -8
  608. package/src/results/diff-pickaxe.ts +1 -1
  609. package/src/results/fetch-result.ts +24 -1
  610. package/src/results/index.ts +2 -0
  611. package/src/results/init-result.ts +10 -1
  612. package/src/results/line-range-hunks.ts +126 -0
  613. package/src/results/merge-result.ts +14 -0
  614. package/src/results/pull-result.ts +7 -0
  615. package/src/results/push-result.ts +10 -0
  616. package/src/results/rebase-result.ts +7 -0
  617. package/src/results/revert-result.ts +6 -0
  618. package/src/results/stash-result.ts +6 -0
  619. package/src/results/status-result.ts +2 -2
  620. package/src/transport-command.ts +216 -4
  621. package/dist/fsck-DLRpbwTj.js +0 -13405
  622. package/dist/results-TB2IJ64h.js +0 -4700
@@ -1,4700 +0,0 @@
1
- import { GitApiError } from "./errors/index.js";
2
- import { DEFAULT_BIG_FILE_THRESHOLD, probeBlob } from "@statewalker/vcs-core";
3
- import { compareGitPaths, decodeGitPath, encodeGitPath, gitCharWidthAt, gitStrWidth, parseGitBool } from "@statewalker/vcs-utils/encoding";
4
- import { wildmatch } from "@statewalker/vcs-working-tree";
5
- import { BUILTIN_FUNCNAME_PATTERNS, BUILTIN_FUNCNAME_PATTERNS_2_43, BUILTIN_WORD_REGEXES, BUILTIN_WORD_REGEXES_2_43, ByteSink, PosixRegexError, XDF_IGNORE_WHITESPACE, XDF_IGNORE_WHITESPACE_CHANGE, XDF_WHITESPACE_FLAGS, bytesToHex, compilePosixRegex, compressBlockPako, createSha1, diffLineCounts, formatHunkHeader, nullObjectIdLike, unifiedDiffHunks, userdiffFindFunction, userdiffWordRegex, whitespaceFlags, writeHunks, xdiffHunks, xdlHashRecord, xdlIsSpace, xdlRecmatch } from "@statewalker/vcs-utils";
6
- const WS_BLANK_AT_EOF = 1024;
7
- const WS_TAB_IN_INDENT = 2048;
8
- const WS_INCOMPLETE_LINE = 4096;
9
- const WS_TRAILING_SPACE = 1088;
10
- const WS_DEFAULT_RULE = 1224;
11
- /** The tab width a rule carries (`ws_tab_width`). */
12
- function wsTabWidth(rule) {
13
- return rule & 63;
14
- }
15
- const RULE_NAMES = [
16
- {
17
- name: "trailing-space",
18
- bits: WS_TRAILING_SPACE,
19
- loosens: false,
20
- excludeDefault: false
21
- },
22
- {
23
- name: "space-before-tab",
24
- bits: 128,
25
- loosens: false,
26
- excludeDefault: false
27
- },
28
- {
29
- name: "indent-with-non-tab",
30
- bits: 256,
31
- loosens: false,
32
- excludeDefault: false
33
- },
34
- {
35
- name: "cr-at-eol",
36
- bits: 512,
37
- loosens: true,
38
- excludeDefault: false
39
- },
40
- {
41
- name: "blank-at-eol",
42
- bits: 64,
43
- loosens: false,
44
- excludeDefault: false
45
- },
46
- {
47
- name: "blank-at-eof",
48
- bits: WS_BLANK_AT_EOF,
49
- loosens: false,
50
- excludeDefault: false
51
- },
52
- {
53
- name: "tab-in-indent",
54
- bits: WS_TAB_IN_INDENT,
55
- loosens: false,
56
- excludeDefault: true
57
- },
58
- {
59
- name: "incomplete-line",
60
- bits: WS_INCOMPLETE_LINE,
61
- loosens: false,
62
- excludeDefault: false
63
- }
64
- ];
65
- /** git's `isspace`: space, tab, LF and CR only (not VT or FF). */
66
- function isGitSpace(ch) {
67
- return ch === 32 || ch === 9 || ch === 10 || ch === 13;
68
- }
69
- /** An invalid rule combination (git dies). */
70
- var WhitespaceRuleError = class extends Error {};
71
- /**
72
- * Parses a `core.whitespace` value (or a `whitespace=<rules>` attribute) as
73
- * `parse_whitespace_rule` does: comma-separated names (or a prefix of one), `-name` to turn
74
- * one off, `tabwidth=<n>`.
75
- *
76
- * @throws WhitespaceRuleError for `tab-in-indent` with `indent-with-non-tab` (git dies)
77
- */
78
- function parseWhitespaceRule(value, warn, options = {}) {
79
- const names = options.compatibility === "2.43" ? RULE_NAMES.filter((r) => r.bits !== WS_INCOMPLETE_LINE) : RULE_NAMES;
80
- let rule = WS_DEFAULT_RULE;
81
- let at = 0;
82
- while (at <= value.length) {
83
- while (at < value.length && ", \n\r".includes(value[at])) at++;
84
- let ep = value.indexOf(",", at);
85
- if (ep < 0) ep = value.length;
86
- let start = at;
87
- let len = ep - start;
88
- let negated = false;
89
- if (value[start] === "-") {
90
- negated = true;
91
- start++;
92
- len--;
93
- }
94
- if (len <= 0) break;
95
- const word = value.slice(start, start + len);
96
- for (const r of names) {
97
- if (r.name.slice(0, len) !== word || len > r.name.length && word !== r.name) continue;
98
- if (negated) rule &= ~r.bits;
99
- else rule |= r.bits;
100
- break;
101
- }
102
- if (value.startsWith("tabwidth=", start)) {
103
- const arg = value.slice(start + 9, ep);
104
- const tabwidth = Number.parseInt(arg, 10) || 0;
105
- if (tabwidth > 0 && tabwidth < 64) {
106
- rule &= -64;
107
- rule |= tabwidth;
108
- } else warn?.(`tabwidth ${arg} out of range`);
109
- }
110
- if (ep >= value.length) break;
111
- at = ep;
112
- }
113
- if (rule & 2048 && rule & 256) throw new WhitespaceRuleError("cannot enforce both tab-in-indent and indent-with-non-tab");
114
- return rule;
115
- }
116
- /**
117
- * The rule for one path (`whitespace_rule`): from its `whitespace` attribute (true, false,
118
- * unset or a rule list), `configRule` (`core.whitespace`) by default.
119
- */
120
- function whitespaceRuleOf(attribute, configRule) {
121
- if (attribute === true) {
122
- let all = wsTabWidth(configRule);
123
- for (const r of RULE_NAMES) if (!r.loosens && !r.excludeDefault) all |= r.bits;
124
- return all;
125
- }
126
- if (attribute === false) return wsTabWidth(configRule);
127
- if (attribute === void 0) return configRule;
128
- return parseWhitespaceRule(attribute);
129
- }
130
- /** The message naming the errors in `ws` (`whitespace_error_string`). */
131
- function whitespaceErrorString(ws) {
132
- const parts = [];
133
- if ((ws & 1088) === 1088) parts.push("trailing whitespace");
134
- else {
135
- if (ws & 64) parts.push("trailing whitespace");
136
- if (ws & 1024) parts.push("new blank line at EOF");
137
- }
138
- if (ws & 128) parts.push("space before tab in indent");
139
- if (ws & 256) parts.push("indent with spaces");
140
- if (ws & 2048) parts.push("tab in indent");
141
- if (ws & 4096) parts.push("no newline at the end of file");
142
- return parts.join(", ");
143
- }
144
- const codeAt = (line, i) => typeof line === "string" ? line.charCodeAt(i) : line[i];
145
- /**
146
- * ws.c's `ws_check_emit_1`: the errors of `rule` in `line` (its LF included, if any),
147
- * writing the line to `out` with the errors in `ws` and the rest in `set` when given.
148
- */
149
- function wsCheckEmit1(line, rule, emit) {
150
- let result = 0;
151
- let written = 0;
152
- let trailingWhitespace = -1;
153
- let trailingNewline = false;
154
- let trailingCarriageReturn = false;
155
- let len = line.length;
156
- const out = emit?.out;
157
- const part = (from, to) => {
158
- if (!out || to <= from) return;
159
- if (typeof line === "string") {
160
- const bytes = new Uint8Array(to - from);
161
- for (let i = from; i < to; i++) bytes[i - from] = line.charCodeAt(i) & 255;
162
- out.bytes(bytes);
163
- } else out.bytes(line.subarray(from, to));
164
- };
165
- if (len > 0 && codeAt(line, len - 1) === 10) {
166
- trailingNewline = true;
167
- len--;
168
- }
169
- if (rule & 512 && len > 0 && codeAt(line, len - 1) === 13) {
170
- trailingCarriageReturn = true;
171
- len--;
172
- }
173
- if (rule & 64) for (let i = len - 1; i >= 0; i--) if (isGitSpace(codeAt(line, i))) {
174
- trailingWhitespace = i;
175
- result |= 64;
176
- } else break;
177
- if (trailingWhitespace === -1) trailingWhitespace = len;
178
- if (!trailingNewline && rule & 4096) result |= WS_INCOMPLETE_LINE;
179
- let i = 0;
180
- for (; i < trailingWhitespace; i++) {
181
- const ch = codeAt(line, i);
182
- if (ch === 32) continue;
183
- if (ch !== 9) break;
184
- if (rule & 128 && written < i) {
185
- result |= 128;
186
- if (emit) {
187
- emit.out.str(emit.ws);
188
- part(written, i);
189
- emit.out.str(emit.reset);
190
- part(i, i + 1);
191
- }
192
- } else if (rule & 2048) {
193
- result |= WS_TAB_IN_INDENT;
194
- if (emit) {
195
- part(written, i);
196
- emit.out.str(emit.ws);
197
- part(i, i + 1);
198
- emit.out.str(emit.reset);
199
- }
200
- } else part(written, i + 1);
201
- written = i + 1;
202
- }
203
- if (rule & 256 && i - written >= wsTabWidth(rule)) {
204
- result |= 256;
205
- if (emit) {
206
- emit.out.str(emit.ws);
207
- part(written, i);
208
- emit.out.str(emit.reset);
209
- }
210
- written = i;
211
- }
212
- if (emit) {
213
- if (trailingWhitespace - written > 0) {
214
- emit.out.str(emit.set);
215
- part(written, trailingWhitespace);
216
- emit.out.str(emit.reset);
217
- }
218
- if (trailingWhitespace !== len) {
219
- emit.out.str(emit.ws);
220
- part(trailingWhitespace, len);
221
- emit.out.str(emit.reset);
222
- }
223
- if (trailingCarriageReturn) part(len, len + 1);
224
- if (trailingNewline) part(line.length - 1, line.length);
225
- }
226
- return result;
227
- }
228
- /** The whitespace errors of one line (with or without its LF), as `ws_check` finds them. */
229
- function wsCheck(line, rule) {
230
- return wsCheckEmit1(line, rule);
231
- }
232
- /**
233
- * ws.c's `ws_check_emit`: writes the line (its LF included, if any) to `out`, the errors of
234
- * `rule` in the `ws` color and the rest in `set`; returns the errors.
235
- */
236
- function wsCheckEmit(line, rule, out, set, reset, ws) {
237
- return wsCheckEmit1(line, rule, {
238
- out,
239
- set,
240
- reset,
241
- ws
242
- });
243
- }
244
- /** Whether a line (or its part from `start` to `end`) holds whitespace only (`ws_blank_line`). */
245
- function wsBlankLine(line, start = 0, end = line.length) {
246
- for (let i = start; i < end; i++) if (!isGitSpace(codeAt(line, i))) return false;
247
- return true;
248
- }
249
- /** diff.c's `count_trailing_blank`: the blank lines at the end of a file */
250
- function countTrailingBlank(mf) {
251
- let cnt = 0;
252
- if (mf.length === 0) return 0;
253
- let ptr = mf.length - 1;
254
- if (mf[ptr] === 10) ptr--;
255
- while (0 < ptr) {
256
- let prevEol = ptr;
257
- for (; 0 <= prevEol; prevEol--) if (mf[prevEol] === 10) break;
258
- if (!wsBlankLine(mf, prevEol + 1, ptr + 1)) break;
259
- cnt++;
260
- ptr = prevEol - 1;
261
- }
262
- return cnt;
263
- }
264
- /** diff.c's `count_lines` */
265
- function countLines(data) {
266
- if (data.length === 0) return 0;
267
- let count = 0;
268
- for (const c of data) if (c === 10) count++;
269
- if (data[data.length - 1] !== 10) count++;
270
- return count;
271
- }
272
- /**
273
- * diff.c's `check_blank_at_eof`: where the blank lines a change adds at the end of the file
274
- * start, in each image (1-based), or zeros when it adds none
275
- */
276
- function checkBlankAtEof(preimage, postimage) {
277
- const l1 = countTrailingBlank(preimage);
278
- const l2 = countTrailingBlank(postimage);
279
- if (l2 <= l1) return {
280
- preimage: 0,
281
- postimage: 0
282
- };
283
- return {
284
- preimage: countLines(preimage) - l1 + 1,
285
- postimage: countLines(postimage) - l2 + 1
286
- };
287
- }
288
- /**
289
- * The line with its whitespace errors fixed (`ws_fix_copy`); `fixed` tells whether anything
290
- * changed.
291
- */
292
- function wsFixCopy(src, rule) {
293
- let len = src.length;
294
- let start = 0;
295
- let addNl = false;
296
- let addCr = false;
297
- let fixed = false;
298
- let lastTab = -1;
299
- let lastSpace = -1;
300
- let needFix = false;
301
- if (rule & 4096 && len > 0 && src.charCodeAt(len - 1) !== 10) {
302
- fixed = true;
303
- addNl = true;
304
- }
305
- if (rule & 64) {
306
- if (len > 0 && src.charCodeAt(len - 1) === 10) {
307
- addNl = true;
308
- len--;
309
- if (len > 0 && src.charCodeAt(len - 1) === 13) {
310
- addCr = (rule & 512) !== 0;
311
- len--;
312
- }
313
- }
314
- if (len > 0 && isGitSpace(src.charCodeAt(len - 1))) {
315
- while (len > 0 && isGitSpace(src.charCodeAt(len - 1))) len--;
316
- fixed = true;
317
- }
318
- }
319
- for (let i = 0; i < len; i++) {
320
- const ch = src.charCodeAt(i);
321
- if (ch === 9) {
322
- lastTab = i;
323
- if (rule & 128 && lastSpace >= 0) needFix = true;
324
- } else if (ch === 32) {
325
- lastSpace = i;
326
- if (rule & 256 && wsTabWidth(rule) <= i - lastTab) needFix = true;
327
- } else break;
328
- }
329
- let out = "";
330
- const width = wsTabWidth(rule);
331
- if (needFix) {
332
- let consecutive = 0;
333
- let last = lastTab + 1;
334
- if (rule & 256) last = lastTab < lastSpace ? lastSpace + 1 : lastTab + 1;
335
- for (let i = 0; i < last; i++) {
336
- const ch = src[i];
337
- if (ch !== " ") {
338
- consecutive = 0;
339
- out += ch;
340
- } else {
341
- consecutive++;
342
- if (consecutive === width) {
343
- out += " ";
344
- consecutive = 0;
345
- }
346
- }
347
- }
348
- while (consecutive-- > 0) out += " ";
349
- start = last;
350
- fixed = true;
351
- } else if (rule & 2048 && lastTab >= 0) {
352
- const last = lastTab + 1;
353
- for (let i = 0; i < last; i++) if (src[i] === " ") do
354
- out += " ";
355
- while (out.length % width);
356
- else out += src[i];
357
- start = last;
358
- fixed = true;
359
- }
360
- out += src.slice(start, len);
361
- if (addCr) out += "\r";
362
- if (addNl) out += "\n";
363
- return {
364
- text: out,
365
- fixed
366
- };
367
- }
368
- //#endregion
369
- //#region src/results/quote-path.ts
370
- /**
371
- * Path quoting as git prints paths (`quote.c`'s `quote_c_style`): a path with a control
372
- * character, `"` or `\`, or (with `core.quotePath`, the default) a byte above 0x7f, is put in
373
- * double quotes with C escapes.
374
- *
375
- * @example
376
- * ```typescript
377
- * quotePath("plain.txt"); // "plain.txt"
378
- * quotePath("tab\there"); // "\"tab\\there\""
379
- * quotePath("é.txt"); // "\"\\303\\251.txt\""
380
- * ```
381
- *
382
- * @module
383
- */
384
- /** `cq_lookup` of quote.c: the escape letter, 1 for an octal escape, -1 for none */
385
- function lookup(ch) {
386
- if (ch >= 128) return 0;
387
- switch (ch) {
388
- case 7: return "a";
389
- case 8: return "b";
390
- case 9: return "t";
391
- case 10: return "n";
392
- case 11: return "v";
393
- case 12: return "f";
394
- case 13: return "r";
395
- case 34: return "\"";
396
- case 92: return "\\";
397
- case 127: return 1;
398
- }
399
- return ch < 32 ? 1 : -1;
400
- }
401
- function mustQuote(ch, quotePathFully) {
402
- const v = lookup(ch);
403
- if (typeof v === "string") return true;
404
- return v + (quotePathFully ? 1 : 0) > 0;
405
- }
406
- /**
407
- * The bytes of `path` quoted as `quote_c_style` quotes them, without the double quotes;
408
- * undefined when the path needs no quoting.
409
- */
410
- function quoteCStyleBody(path, quotePathFully = true) {
411
- const bytes = typeof path === "string" ? encodeGitPath(path) : path;
412
- let needs = false;
413
- for (const b of bytes) if (mustQuote(b, quotePathFully)) {
414
- needs = true;
415
- break;
416
- }
417
- if (!needs) return void 0;
418
- let out = "";
419
- let run = [];
420
- const flush = () => {
421
- if (run.length > 0) {
422
- out += decodeGitPath(new Uint8Array(run));
423
- run = [];
424
- }
425
- };
426
- for (const b of bytes) {
427
- if (!mustQuote(b, quotePathFully)) {
428
- run.push(b);
429
- continue;
430
- }
431
- flush();
432
- const v = lookup(b);
433
- if (typeof v === "string") out += `\\${v}`;
434
- else out += `\\${b >> 6 & 3}${b >> 3 & 7}${b & 7}`;
435
- }
436
- flush();
437
- return out;
438
- }
439
- /** `path` as git prints it: in double quotes with C escapes when it needs quoting */
440
- function quotePath(path, quotePathFully = true) {
441
- const body = quoteCStyleBody(path, quotePathFully);
442
- return body === void 0 ? path : `"${body}"`;
443
- }
444
- /**
445
- * git's `quote_two_c_style`: `prefix` and `path` as they are, or both escaped inside one pair
446
- * of quotes when either needs quoting
447
- */
448
- function quoteTwo(prefix, path, quotePathFully = true) {
449
- return quotePath(`${prefix}${path}`, quotePathFully);
450
- }
451
- //#endregion
452
- //#region src/results/combined-diff.ts
453
- /**
454
- * git's combined diff (`combine-diff.c`), dense form (`diff --cc`): one result compared with
455
- * several parents at once, as `git diff` shows a conflicted path, the worktree file against
456
- * stages 2 ("ours") and 3 ("theirs").
457
- *
458
- * @example
459
- * ```typescript
460
- * writeCombinedDiff(sink, {
461
- * path: "f.txt",
462
- * parents: [ours, theirs], // { id, mode, content }
463
- * result: { id: NULL_ID, mode: 0o100644, content: worktreeBytes },
464
- * }, options);
465
- * // diff --cc f.txt
466
- * // index 1a2b3c4,5d6e7f8..0000000
467
- * // ...
468
- * // @@@ -1,5 -1,5 +1,9 @@@
469
- * // 1
470
- * // ++<<<<<<< HEAD
471
- * ```
472
- *
473
- * Each parent is diffed with the result without context (the same xdiff options as the
474
- * patch); the lines a parent lost hang on the result line after them, merged across parents
475
- * by their longest common subsequence. A hunk shows only where the result differs from more
476
- * than one version (dense: a change taken from one parent alone is left out). Function lines
477
- * of the hunk headers are the last line above the hunk starting with a letter, `_` or `$`,
478
- * cut at 40 bytes, without its last non-blank byte (as git prints them).
479
- *
480
- * @module
481
- */
482
- const FIRST_FEW_BYTES$1 = 8e3;
483
- function isBinaryBuffer(content) {
484
- const n = Math.min(content.length, FIRST_FEW_BYTES$1);
485
- for (let i = 0; i < n; i++) if (content[i] === 0) return true;
486
- return false;
487
- }
488
- /** combine-diff.c's `match_string_spaces` */
489
- function matchStringSpaces(a, b, flags) {
490
- let len1 = a.length;
491
- let len2 = b.length;
492
- if (flags & XDF_WHITESPACE_FLAGS) {
493
- while (len1 > 0 && xdlIsSpace(a[len1 - 1])) len1--;
494
- while (len2 > 0 && xdlIsSpace(b[len2 - 1])) len2--;
495
- }
496
- if (!(flags & (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE))) {
497
- if (len1 !== len2) return false;
498
- for (let i = 0; i < len1; i++) if (a[i] !== b[i]) return false;
499
- return true;
500
- }
501
- while (len1 > 0 && len2 > 0) {
502
- len1--;
503
- len2--;
504
- if (xdlIsSpace(a[len1]) || xdlIsSpace(b[len2])) {
505
- if (flags & XDF_IGNORE_WHITESPACE_CHANGE && (!xdlIsSpace(a[len1]) || !xdlIsSpace(b[len2]))) return false;
506
- while (len1 > 0 && xdlIsSpace(a[len1])) len1--;
507
- while (len2 > 0 && xdlIsSpace(b[len2])) len2--;
508
- }
509
- if (a[len1] !== b[len2]) return false;
510
- }
511
- if (flags & XDF_IGNORE_WHITESPACE) {
512
- while (len1 > 0 && xdlIsSpace(a[len1 - 1])) len1--;
513
- while (len2 > 0 && xdlIsSpace(b[len2 - 1])) len2--;
514
- }
515
- return len1 === 0 && len2 === 0;
516
- }
517
- const MATCH = 0;
518
- const BASE = 1;
519
- const NEW = 2;
520
- /** combine-diff.c's `coalesce_lines`: `newLines` merged into `base` by their LCS */
521
- function coalesceLines(base, newLines, parent, flags) {
522
- if (newLines.length === 0) return base;
523
- if (base.length === 0) return newLines;
524
- const nb = base.length;
525
- const nn = newLines.length;
526
- const lcs = [];
527
- const dir = [];
528
- for (let i = 0; i <= nb; i++) {
529
- lcs.push(new Int32Array(nn + 1));
530
- const d = new Uint8Array(nn + 1);
531
- d[0] = BASE;
532
- dir.push(d);
533
- }
534
- for (let j = 1; j <= nn; j++) dir[0][j] = NEW;
535
- for (let i = 1; i <= nb; i++) for (let j = 1; j <= nn; j++) if (matchStringSpaces(base[i - 1].line, newLines[j - 1].line, flags)) {
536
- lcs[i][j] = lcs[i - 1][j - 1] + 1;
537
- dir[i][j] = MATCH;
538
- } else if (lcs[i][j - 1] >= lcs[i - 1][j]) {
539
- lcs[i][j] = lcs[i][j - 1];
540
- dir[i][j] = NEW;
541
- } else {
542
- lcs[i][j] = lcs[i - 1][j];
543
- dir[i][j] = BASE;
544
- }
545
- const out = [...base];
546
- let i = nb;
547
- let j = nn;
548
- while (i !== 0 || j !== 0) if (dir[i][j] === MATCH) {
549
- out[i - 1].parentMap |= 1 << parent;
550
- i--;
551
- j--;
552
- } else if (dir[i][j] === NEW) {
553
- out.splice(i, 0, newLines[j - 1]);
554
- j--;
555
- } else i--;
556
- return out;
557
- }
558
- /** combine-diff.c's `combine_diff`: one parent's changes recorded in `sline` */
559
- function combineDiff(parent, result, sline, cnt, n, options, flags) {
560
- const nmask = 1 << n;
561
- const diff = unifiedDiffHunks(parent.content, result, {
562
- algorithm: options.algorithm,
563
- indentHeuristic: options.indentHeuristic,
564
- histogramRediff: options.histogramRediff,
565
- legacyMinimal: options.legacyMinimal,
566
- ignoreWhitespace: options.ignoreWhitespace,
567
- ignoreWhitespaceChange: options.ignoreWhitespaceChange,
568
- ignoreWhitespaceAtEol: options.ignoreWhitespaceAtEol,
569
- ignoreCrAtEol: options.ignoreCrAtEol,
570
- ignoreBlankLines: options.ignoreBlankLines,
571
- context: 0,
572
- interHunkContext: 0
573
- });
574
- for (const hunk of diff.hunks) {
575
- const nb = hunk.newStart;
576
- let lno = nb;
577
- const bucket = hunk.newCount === 0 ? sline[nb] : sline[nb - 1];
578
- for (const line of hunk.lines) if (line.kind === "-") {
579
- let bytes = diff.old.line(line.index);
580
- if (bytes.length > 0 && bytes[bytes.length - 1] === 10) bytes = bytes.subarray(0, bytes.length - 1);
581
- bucket.plost.push({
582
- line: bytes,
583
- parentMap: nmask
584
- });
585
- } else if (line.kind === "+") {
586
- sline[lno - 1].flag |= nmask;
587
- lno++;
588
- }
589
- }
590
- let pLno = 1;
591
- let lno = 0;
592
- for (; lno <= cnt; lno++) {
593
- const sl = sline[lno];
594
- sl.pLno[n] = pLno;
595
- if (sl.plost.length > 0) {
596
- sl.lost = coalesceLines(sl.lost, sl.plost, n, flags);
597
- sl.plost = [];
598
- }
599
- for (const ll of sl.lost) if (ll.parentMap & nmask) pLno++;
600
- if (lno < cnt && !(sl.flag & nmask)) pLno++;
601
- }
602
- sline[lno].pLno[n] = pLno;
603
- }
604
- /** combine-diff.c's `reuse_combine_diff`: parent `i` is the same blob as parent `j` */
605
- function reuseCombineDiff(sline, cnt, i, j) {
606
- const imask = 1 << i;
607
- const jmask = 1 << j;
608
- for (let lno = 0; lno <= cnt; lno++) {
609
- const sl = sline[lno];
610
- sl.pLno[i] = sl.pLno[j];
611
- for (const ll of sl.lost) if (ll.parentMap & jmask) ll.parentMap |= imask;
612
- if (sl.flag & jmask) sl.flag |= imask;
613
- }
614
- sline[cnt + 1].pLno[i] = sline[cnt + 1].pLno[j];
615
- }
616
- function interesting(sl, allMask) {
617
- return (sl.flag & allMask) !== 0 || sl.lost.length > 0;
618
- }
619
- function adjustHunkTail(sline, allMask, hunkBegin, i) {
620
- if (hunkBegin + 1 <= i && !(sline[i - 1].flag & allMask)) return i - 1;
621
- return i;
622
- }
623
- function findNext(sline, mark, start, cnt, lookForUninteresting) {
624
- let i = start;
625
- while (i <= cnt) {
626
- if (lookForUninteresting ? !(sline[i].flag & mark) : sline[i].flag & mark) return i;
627
- i++;
628
- }
629
- return i;
630
- }
631
- function giveContext(sline, cnt, numParent, context) {
632
- const allMask = (1 << numParent) - 1;
633
- const mark = 1 << numParent;
634
- const noPreDelete = 2 << numParent;
635
- let i = findNext(sline, mark, 0, cnt, false);
636
- if (cnt < i) return false;
637
- while (i <= cnt) {
638
- let j = context < i ? i - context : 0;
639
- while (j < i) {
640
- if (!(sline[j].flag & mark)) sline[j].flag |= noPreDelete;
641
- sline[j++].flag |= mark;
642
- }
643
- for (;;) {
644
- j = findNext(sline, mark, i, cnt, true);
645
- if (cnt < j) return true;
646
- let k = findNext(sline, mark, j, cnt, false);
647
- j = adjustHunkTail(sline, allMask, i, j);
648
- if (k < j + context) {
649
- while (j < k) sline[j++].flag |= mark;
650
- i = k;
651
- continue;
652
- }
653
- i = k;
654
- k = j + context < cnt + 1 ? j + context : cnt + 1;
655
- while (j < k) sline[j++].flag |= mark;
656
- break;
657
- }
658
- }
659
- return true;
660
- }
661
- /** combine-diff.c's `make_hunks` */
662
- function makeHunks(sline, cnt, numParent, context, dense = true) {
663
- const allMask = (1 << numParent) - 1;
664
- const mark = 1 << numParent;
665
- for (let i = 0; i <= cnt; i++) if (interesting(sline[i], allMask)) sline[i].flag |= mark;
666
- else sline[i].flag &= ~mark;
667
- if (!dense) return giveContext(sline, cnt, numParent, context);
668
- let i = 0;
669
- while (i <= cnt) {
670
- while (i <= cnt && !(sline[i].flag & mark)) i++;
671
- if (cnt < i) break;
672
- const hunkBegin = i;
673
- let j = i + 1;
674
- for (; j <= cnt; j++) if (!(sline[j].flag & mark)) {
675
- let la = adjustHunkTail(sline, allMask, hunkBegin, j);
676
- la = la + context < cnt + 1 ? la + context : cnt + 1;
677
- let contin = false;
678
- while (la && j <= --la) if (sline[la].flag & mark) {
679
- contin = true;
680
- break;
681
- }
682
- if (!contin) break;
683
- j = la;
684
- }
685
- const hunkEnd = j;
686
- let sameDiff = 0;
687
- let hasInteresting = false;
688
- for (j = i; j < hunkEnd && !hasInteresting; j++) {
689
- let thisDiff = sline[j].flag & allMask;
690
- if (thisDiff) {
691
- if (!sameDiff) sameDiff = thisDiff;
692
- else if (sameDiff !== thisDiff) {
693
- hasInteresting = true;
694
- break;
695
- }
696
- }
697
- for (const ll of sline[j].lost) {
698
- if (hasInteresting) break;
699
- thisDiff = ll.parentMap;
700
- if (!sameDiff) sameDiff = thisDiff;
701
- else if (sameDiff !== thisDiff) hasInteresting = true;
702
- }
703
- }
704
- if (!hasInteresting && sameDiff !== allMask) for (j = hunkBegin; j < hunkEnd; j++) sline[j].flag &= ~mark;
705
- i = hunkEnd;
706
- }
707
- return giveContext(sline, cnt, numParent, context);
708
- }
709
- /** git's `isalpha` (ASCII) or `_` or `$`: a line fit for a hunk header comment */
710
- function hunkCommentLine(bol) {
711
- if (!bol || bol.length === 0) return false;
712
- const ch = bol[0];
713
- return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch === 95 || ch === 36;
714
- }
715
- /** `show_line_to_eol`: the line, the reset, then its CR and an LF */
716
- function lineToEol(sink, line, reset) {
717
- if (!reset) {
718
- sink.push(line);
719
- sink.text("\n");
720
- return;
721
- }
722
- const cr = line.length > 0 && line[line.length - 1] === 13;
723
- sink.push(cr ? line.subarray(0, line.length - 1) : line);
724
- sink.text(`${reset}${cr ? "\r" : ""}\n`);
725
- }
726
- /** combine-diff.c's `dump_sline` */
727
- function dumpSline(sink, sline, cnt, numParent, context, resultDeleted, colors) {
728
- const cFrag = colors?.frag ?? "";
729
- const cFunc = colors?.func ?? "";
730
- const cNew = colors?.new ?? "";
731
- const cOld = colors?.old ?? "";
732
- const cContext = colors?.context ?? "";
733
- const cReset = colors?.reset ?? "";
734
- const mark = 1 << numParent;
735
- const noPreDelete = 2 << numParent;
736
- if (resultDeleted) return;
737
- let lno = 0;
738
- for (;;) {
739
- let hunkComment;
740
- let nullContext = 0;
741
- while (lno <= cnt && !(sline[lno].flag & mark)) {
742
- if (hunkCommentLine(sline[lno].bol)) hunkComment = sline[lno].bol;
743
- lno++;
744
- }
745
- if (cnt < lno) break;
746
- let hunkEnd = lno + 1;
747
- for (; hunkEnd <= cnt; hunkEnd++) if (!(sline[hunkEnd].flag & mark)) break;
748
- let rlines = hunkEnd - lno;
749
- if (cnt < hunkEnd) rlines--;
750
- if (!context) {
751
- for (let j = lno; j < hunkEnd; j++) if (!(sline[j].flag & mark - 1)) nullContext++;
752
- rlines -= nullContext;
753
- }
754
- let head = "@".repeat(numParent + 1);
755
- for (let i = 0; i < numParent; i++) {
756
- const l0 = sline[lno].pLno[i];
757
- const l1 = sline[hunkEnd].pLno[i];
758
- head += ` -${l0},${unsignedLong(l1 - l0 - nullContext)}`;
759
- }
760
- head += ` +${lno + 1},${unsignedLong(rlines)} ${"@".repeat(numParent + 1)}`;
761
- sink.text(cFrag + head);
762
- if (hunkComment) {
763
- let commentEnd = 0;
764
- for (let i = 0; i < 40 && i < hunkComment.length; i++) {
765
- const ch = hunkComment[i];
766
- if (ch === 0 || ch === 10) break;
767
- if (!xdlIsSpace(ch)) commentEnd = i;
768
- }
769
- if (commentEnd) {
770
- sink.text(`${cReset}${cContext} ${cReset}${cFunc}`);
771
- sink.push(hunkComment.subarray(0, commentEnd));
772
- }
773
- }
774
- sink.text(`${cReset}\n`);
775
- while (lno < hunkEnd) {
776
- const sl = sline[lno++];
777
- const lost = sl.flag & noPreDelete ? [] : sl.lost;
778
- for (const ll of lost) {
779
- let marks = "";
780
- for (let j = 0; j < numParent; j++) marks += ll.parentMap & 1 << j ? "-" : " ";
781
- sink.text(cOld + marks);
782
- lineToEol(sink, ll.line, cReset);
783
- }
784
- if (cnt < lno) break;
785
- if (!(sl.flag & mark - 1) && !context) continue;
786
- let marks = sl.flag & mark - 1 ? cNew : cContext;
787
- for (let j = 0; j < numParent; j++) marks += sl.flag & 1 << j ? "+" : " ";
788
- sink.text(marks);
789
- lineToEol(sink, sl.bol ?? /* @__PURE__ */ new Uint8Array(0), cReset);
790
- }
791
- }
792
- }
793
- function octal6$1(mode) {
794
- return mode.toString(8).padStart(6, "0");
795
- }
796
- /** combine-diff.c's `show_combined_header` (dense, from the worktree) */
797
- function writeHeader(sink, elem, options, modeDiffers, showFileHeader) {
798
- const quote = options.quotePath ?? true;
799
- const abbreviate = options.abbreviate ?? ((id) => id.slice(0, 7));
800
- const dense = options.dense ?? true;
801
- const m = options.colors?.meta ?? "";
802
- const r = options.colors?.reset ?? "";
803
- sink.text(`${m}${dense ? "diff --cc " : "diff --combined "}${quoteTwo("", elem.path, quote)}${r}\n`);
804
- sink.text(`${m}index ${elem.parents.map((p) => abbreviate(p.id)).join(",")}..${abbreviate(elem.result.id)}${r}\n`);
805
- const deleted = !elem.result.mode;
806
- const added = !deleted && elem.parents.every((p) => !p.mode);
807
- if (modeDiffers) {
808
- if (added) sink.text(`${m}new file mode ${octal6$1(elem.result.mode)}${r}\n`);
809
- else {
810
- let line = deleted ? "deleted file mode " : "mode ";
811
- line += elem.parents.map((p) => octal6$1(p.mode)).join(",");
812
- if (elem.result.mode) line += `..${octal6$1(elem.result.mode)}`;
813
- sink.text(`${m}${line}${r}\n`);
814
- }
815
- }
816
- if (!showFileHeader) return;
817
- const aPrefix = options.srcPrefix ?? "a/";
818
- const bPrefix = options.dstPrefix ?? "b/";
819
- sink.text(`${m}--- ${added ? "/dev/null" : quoteTwo(aPrefix, elem.path, quote)}${r}\n`);
820
- sink.text(`${m}+++ ${deleted ? "/dev/null" : quoteTwo(bPrefix, elem.path, quote)}${r}\n`);
821
- }
822
- /**
823
- * The dense combined diff of a path whose result is a worktree file (`show_patch_diff` with
824
- * `working_tree_file`): always printed, with its header, even when no hunk is left.
825
- */
826
- function writeCombinedDiff(sink, elem, options = {}) {
827
- const context = options.context ?? 3;
828
- const numParent = elem.parents.length;
829
- const resultDeleted = !elem.result.mode && options.workingTreeFile !== false;
830
- const result = !elem.result.mode ? /* @__PURE__ */ new Uint8Array(0) : elem.result.content;
831
- const modeDiffers = elem.parents.some((p) => p.mode !== elem.result.mode);
832
- if (options.binary ?? (isBinaryBuffer(result) || elem.parents.some((p) => isBinaryBuffer(p.content)))) {
833
- writeHeader(sink, elem, options, modeDiffers, false);
834
- sink.text("Binary files differ\n");
835
- return;
836
- }
837
- let cnt = 0;
838
- for (let i = 0; i < result.length; i++) if (result[i] === 10) cnt++;
839
- if (result.length > 0 && result[result.length - 1] !== 10) cnt++;
840
- const sline = [];
841
- for (let i = 0; i < cnt + 2; i++) sline.push({
842
- lost: [],
843
- plost: [],
844
- flag: 0,
845
- pLno: new Array(numParent).fill(0)
846
- });
847
- let start = 0;
848
- let lno = 0;
849
- for (let i = 0; i < result.length; i++) if (result[i] === 10) {
850
- sline[lno++].bol = result.subarray(start, i);
851
- start = i + 1;
852
- }
853
- if (start < result.length) sline[lno].bol = result.subarray(start);
854
- const flags = whitespaceFlags(options);
855
- for (let i = 0; i < numParent; i++) {
856
- let j = 0;
857
- for (; j < i; j++) if (elem.parents[i].id === elem.parents[j].id) {
858
- reuseCombineDiff(sline, cnt, i, j);
859
- break;
860
- }
861
- if (i <= j && !resultDeleted) combineDiff(elem.parents[i], result, sline, cnt, i, options, flags);
862
- }
863
- if (!makeHunks(sline, cnt, numParent, context, options.dense ?? true) && !modeDiffers && options.workingTreeFile === false) return;
864
- writeHeader(sink, elem, options, modeDiffers, true);
865
- dumpSline(sink, sline, cnt, numParent, context, resultDeleted, options.colors);
866
- }
867
- /**
868
- * A count as git's `%lu` prints it: git keeps the hunk header's counts in `unsigned long`, so
869
- * one that goes below zero (a `-U0` hunk of only lines no parent removed) wraps around to
870
- * 2^64 - n, `18446744073709551615` for -1.
871
- */
872
- function unsignedLong(n) {
873
- return n < 0 ? (2n ** 64n + BigInt(n)).toString() : String(n);
874
- }
875
- //#endregion
876
- //#region src/results/binary-patch.ts
877
- /**
878
- * git's binary patch body (diff.c's `emit_binary_diff`): the postimage deflated (zlib
879
- * level 1, git's default `core.compression` for loose data) or a deflated delta of it
880
- * against the preimage (diff-delta.c, ported with its Rabin fingerprint tables so the
881
- * deltas are git's bytes), whichever is smaller, in base85 lines of up to 52 bytes.
882
- */
883
- const HASH_LIMIT = 64;
884
- const RABIN_SHIFT = 23;
885
- const RABIN_WINDOW = 16;
886
- const MAX_OP_SIZE = 34;
887
- const T = new Uint32Array([
888
- 0,
889
- 2874782929,
890
- 1454598562,
891
- 4260027763,
892
- 104818581,
893
- 2909197124,
894
- 1351355959,
895
- 4225088230,
896
- 209637162,
897
- 2804382715,
898
- 1523426952,
899
- 4053013081,
900
- 172075199,
901
- 2702711918,
902
- 1559413021,
903
- 4155209164,
904
- 419274324,
905
- 3013880453,
906
- 1313798134,
907
- 3843506983,
908
- 516094401,
909
- 3046853904,
910
- 1215402083,
911
- 3811058866,
912
- 344150398,
913
- 3218793903,
914
- 1110456540,
915
- 3916008461,
916
- 314324715,
917
- 3118826042,
918
- 1141858121,
919
- 4015451032,
920
- 838548648,
921
- 2594343033,
922
- 1732793610,
923
- 3423723995,
924
- 935615293,
925
- 2627596268,
926
- 1635201695,
927
- 3392046670,
928
- 1032188802,
929
- 2531018579,
930
- 1798740512,
931
- 3228511985,
932
- 1002083351,
933
- 2430804166,
934
- 1829371317,
935
- 3327150436,
936
- 688300796,
937
- 2187269677,
938
- 2142620510,
939
- 3572268943,
940
- 792315241,
941
- 2220913080,
942
- 2039131339,
943
- 3537049626,
944
- 628649430,
945
- 2384582919,
946
- 1942684788,
947
- 3633492133,
948
- 591858243,
949
- 2283716242,
950
- 1978950625,
951
- 3735934768,
952
- 1677097296,
953
- 3366964609,
954
- 893718770,
955
- 2652677155,
956
- 1707679429,
957
- 3465587220,
958
- 863663975,
959
- 2552480694,
960
- 1871230586,
961
- 3302032043,
962
- 960225240,
963
- 2455923465,
964
- 1773654511,
965
- 3270403390,
966
- 1057273933,
967
- 2489126044,
968
- 2064377604,
969
- 3495056341,
970
- 767069862,
971
- 2262907511,
972
- 2100592785,
973
- 3597481024,
974
- 730327347,
975
- 2162056674,
976
- 2004166702,
977
- 3693911295,
978
- 566641036,
979
- 2325738845,
980
- 1900695483,
981
- 3658742634,
982
- 670639641,
983
- 2359333576,
984
- 1376601592,
985
- 4183093545,
986
- 79572058,
987
- 2951190667,
988
- 1412571757,
989
- 4285241020,
990
- 42027983,
991
- 2849570590,
992
- 1584630482,
993
- 4113186307,
994
- 146858864,
995
- 2744735649,
996
- 1481436487,
997
- 4078262678,
998
- 251626725,
999
- 2779131956,
1000
- 1257298860,
1001
- 3785977725,
1002
- 474198542,
1003
- 3071936223,
1004
- 1288682553,
1005
- 3885369576,
1006
- 444388763,
1007
- 2972016970,
1008
- 1183716486,
1009
- 3990331479,
1010
- 272465188,
1011
- 3143944693,
1012
- 1085371155,
1013
- 3957901250,
1014
- 369236657,
1015
- 3176902240,
1016
- 1823819377,
1017
- 3354194592,
1018
- 973483987,
1019
- 2438961922,
1020
- 1787437540,
1021
- 3251868981,
1022
- 1010387014,
1023
- 2539715735,
1024
- 1623951707,
1025
- 3415358858,
1026
- 913891577,
1027
- 2636207144,
1028
- 1727327950,
1029
- 3450690079,
1030
- 809994092,
1031
- 2602447805,
1032
- 1950930981,
1033
- 3742461172,
1034
- 586920327,
1035
- 2309096790,
1036
- 1920450480,
1037
- 3643673441,
1038
- 616879634,
1039
- 2409456323,
1040
- 2016810767,
1041
- 3547309022,
1042
- 780500653,
1043
- 2245839484,
1044
- 2114547866,
1045
- 3578840139,
1046
- 683284792,
1047
- 2212736489,
1048
- 1565424345,
1049
- 4128755208,
1050
- 201134971,
1051
- 2695145386,
1052
- 1534139724,
1053
- 4029196701,
1054
- 230847726,
1055
- 2795225151,
1056
- 1362146803,
1057
- 4201185570,
1058
- 126082129,
1059
- 2899994752,
1060
- 1460654694,
1061
- 4233520823,
1062
- 29146052,
1063
- 2867138325,
1064
- 1169417357,
1065
- 4008333404,
1066
- 318803247,
1067
- 3092855294,
1068
- 1133282072,
1069
- 3906287561,
1070
- 356510394,
1071
- 3194379883,
1072
- 1238182823,
1073
- 3801390966,
1074
- 528368133,
1075
- 3022517972,
1076
- 1341279282,
1077
- 3836475619,
1078
- 423699856,
1079
- 2987954497,
1080
- 256065313,
1081
- 2753203184,
1082
- 1508923011,
1083
- 4071219794,
1084
- 159144116,
1085
- 2720394341,
1086
- 1607414038,
1087
- 4103505351,
1088
- 54390795,
1089
- 2825143514,
1090
- 1435408809,
1091
- 4275514744,
1092
- 84055966,
1093
- 2925208399,
1094
- 1404173884,
1095
- 4175973101,
1096
- 398369141,
1097
- 3169260964,
1098
- 1091422423,
1099
- 3931405318,
1100
- 293717728,
1101
- 3134747185,
1102
- 1194504002,
1103
- 3966442387,
1104
- 465595999,
1105
- 2962872974,
1106
- 1299384317,
1107
- 3861558060,
1108
- 503253450,
1109
- 3064380699,
1110
- 1263296616,
1111
- 3759527097,
1112
- 1052246921,
1113
- 2514597720,
1114
- 1745578539,
1115
- 3276988154,
1116
- 948397084,
1117
- 2480853197,
1118
- 1848905150,
1119
- 3312302447,
1120
- 851889315,
1121
- 2577365106,
1122
- 1685431553,
1123
- 3475771856,
1124
- 888777526,
1125
- 2678071271,
1126
- 1649066644,
1127
- 3373495877,
1128
- 642096605,
1129
- 2367432972,
1130
- 1895232639,
1131
- 3685695662,
1132
- 544930376,
1133
- 2334346905,
1134
- 1992922090,
1135
- 3717211963,
1136
- 708530935,
1137
- 2170742310,
1138
- 2089302869,
1139
- 3620835204,
1140
- 738473314,
1141
- 2271052211,
1142
- 2058837184,
1143
- 3522095121
1144
- ]);
1145
- const U = new Uint32Array([
1146
- 0,
1147
- 2125799437,
1148
- 1446245579,
1149
- 679924934,
1150
- 121527623,
1151
- 2039184714,
1152
- 1359849868,
1153
- 800622977,
1154
- 243055246,
1155
- 1892260483,
1156
- 1481592389,
1157
- 653946440,
1158
- 155379657,
1159
- 2012727236,
1160
- 1601245954,
1161
- 566506255,
1162
- 486110492,
1163
- 1649169681,
1164
- 1254785495,
1165
- 880779738,
1166
- 466036827,
1167
- 1701972054,
1168
- 1307892880,
1169
- 859962525,
1170
- 310759314,
1171
- 1815146399,
1172
- 1152793433,
1173
- 973282132,
1174
- 364614357,
1175
- 1796125400,
1176
- 1133012510,
1177
- 1027425811,
1178
- 972220984,
1179
- 1195887157,
1180
- 1874927347,
1181
- 292830974,
1182
- 1053603711,
1183
- 1081710450,
1184
- 1761559476,
1185
- 373973945,
1186
- 932073654,
1187
- 1228632251,
1188
- 1639818365,
1189
- 520651888,
1190
- 816844273,
1191
- 1308962300,
1192
- 1719925050,
1193
- 406247735,
1194
- 621518628,
1195
- 1539227433,
1196
- 1933077487,
1197
- 227363810,
1198
- 573948515,
1199
- 1551950446,
1200
- 1946564264,
1201
- 179508901,
1202
- 729228714,
1203
- 1438778791,
1204
- 2101662049,
1205
- 66187628,
1206
- 743012589,
1207
- 1392269536,
1208
- 2054851622,
1209
- 80718891,
1210
- 1944441968,
1211
- 223409277,
1212
- 634790075,
1213
- 1533214902,
1214
- 1960544567,
1215
- 175024442,
1216
- 585661948,
1217
- 1549622769,
1218
- 2107207422,
1219
- 53235443,
1220
- 732600885,
1221
- 1428142648,
1222
- 2057778105,
1223
- 68293556,
1224
- 747947890,
1225
- 1377953663,
1226
- 1864147308,
1227
- 296321377,
1228
- 959403431,
1229
- 1201305002,
1230
- 1747123243,
1231
- 379051046,
1232
- 1041303776,
1233
- 1084500205,
1234
- 1633688546,
1235
- 534068207,
1236
- 928247593,
1237
- 1239863076,
1238
- 1717454501,
1239
- 418080424,
1240
- 812495470,
1241
- 1322816099,
1242
- 1243037256,
1243
- 883039813,
1244
- 472173187,
1245
- 1653729934,
1246
- 1294557967,
1247
- 865878786,
1248
- 454727620,
1249
- 1706014665,
1250
- 1147897030,
1251
- 987669707,
1252
- 307785741,
1253
- 1827491840,
1254
- 1129699713,
1255
- 1038154124,
1256
- 359017802,
1257
- 1808993607,
1258
- 1458457428,
1259
- 677079897,
1260
- 14532511,
1261
- 2120785810,
1262
- 1372591635,
1263
- 795162142,
1264
- 132375256,
1265
- 2035729109,
1266
- 1486025178,
1267
- 640143831,
1268
- 245433617,
1269
- 1880368412,
1270
- 1605151901,
1271
- 555322512,
1272
- 161437782,
1273
- 1999272027,
1274
- 1284643889,
1275
- 841432124,
1276
- 446818554,
1277
- 1679083767,
1278
- 1269580150,
1279
- 890855803,
1280
- 497006013,
1281
- 1663735216,
1282
- 1122936511,
1283
- 1012631218,
1284
- 350048884,
1285
- 1785229945,
1286
- 1171323896,
1287
- 996531189,
1288
- 333647667,
1289
- 1834364734,
1290
- 1349216557,
1291
- 786319648,
1292
- 106470886,
1293
- 2028846571,
1294
- 1465201770,
1295
- 702551143,
1296
- 23511201,
1297
- 2144592044,
1298
- 1578619811,
1299
- 547550126,
1300
- 136587112,
1301
- 1989216101,
1302
- 1495895780,
1303
- 664579817,
1304
- 253393455,
1305
- 1907317282,
1306
- 1969288713,
1307
- 198563332,
1308
- 592642754,
1309
- 1575363279,
1310
- 1918806862,
1311
- 216763203,
1312
- 611147653,
1313
- 1524137864,
1314
- 2065452167,
1315
- 94989450,
1316
- 758102092,
1317
- 1402640449,
1318
- 2082607552,
1319
- 43463117,
1320
- 705815819,
1321
- 1420084486,
1322
- 1771668245,
1323
- 388801304,
1324
- 1068136414,
1325
- 1092573139,
1326
- 1856495186,
1327
- 269680223,
1328
- 949234329,
1329
- 1176570516,
1330
- 1743075739,
1331
- 424679830,
1332
- 836160848,
1333
- 1331948893,
1334
- 1624990940,
1335
- 510543057,
1336
- 921210903,
1337
- 1214099482,
1338
- 1064814657,
1339
- 1103292492,
1340
- 1766079626,
1341
- 401677447,
1342
- 944346374,
1343
- 1190966539,
1344
- 1853514189,
1345
- 282018240,
1346
- 822833871,
1347
- 1337873090,
1348
- 1731757572,
1349
- 428713481,
1350
- 909455240,
1351
- 1216352133,
1352
- 1611062083,
1353
- 515111758,
1354
- 596557149,
1355
- 1564187984,
1356
- 1975339414,
1357
- 185100699,
1358
- 615571482,
1359
- 1510326295,
1360
- 1921193169,
1361
- 204879068,
1362
- 770836435,
1363
- 1397172190,
1364
- 2076308248,
1365
- 91542293,
1366
- 718035604,
1367
- 1417247385,
1368
- 2097131103,
1369
- 38440530,
1370
- 109388409,
1371
- 2016412276,
1372
- 1354159794,
1373
- 772011711,
1374
- 29065022,
1375
- 2131648307,
1376
- 1468566517,
1377
- 691907576,
1378
- 150575351,
1379
- 1984739578,
1380
- 1590324284,
1381
- 545213489,
1382
- 264750512,
1383
- 1903355325,
1384
- 1509175675,
1385
- 658575734,
1386
- 444356453,
1387
- 1690924904,
1388
- 1280287662,
1389
- 855278499,
1390
- 490867234,
1391
- 1677142575,
1392
- 1265762025,
1393
- 902094564,
1394
- 335605227,
1395
- 1790299622,
1396
- 1110645024,
1397
- 1015429421,
1398
- 322875564,
1399
- 1837863073,
1400
- 1158497383,
1401
- 1001940074
1402
- ]);
1403
- /** `create_delta_index`. */
1404
- function createDeltaIndex(buf) {
1405
- const bufsize = buf.length;
1406
- if (!bufsize) return void 0;
1407
- let entries = Math.floor((bufsize - 1) / RABIN_WINDOW);
1408
- let hsize = Math.floor(entries / 4);
1409
- let i = 4;
1410
- while (2 ** i < hsize) i++;
1411
- hsize = 2 ** i;
1412
- const hmask = hsize - 1;
1413
- const ePtr = new Int32Array(entries);
1414
- const eVal = new Uint32Array(entries);
1415
- const eNext = new Int32Array(entries).fill(-1);
1416
- const hash = new Int32Array(hsize).fill(-1);
1417
- const hashCount = new Uint32Array(hsize);
1418
- let n = 0;
1419
- let prevVal = 4294967295;
1420
- for (let data = entries * RABIN_WINDOW - RABIN_WINDOW; data >= 0; data -= RABIN_WINDOW) {
1421
- let val = 0;
1422
- for (let k = 1; k <= RABIN_WINDOW; k++) val = ((val << 8 | buf[data + k]) ^ T[val >>> RABIN_SHIFT]) >>> 0;
1423
- if (val === prevVal) {
1424
- ePtr[n - 1] = data + RABIN_WINDOW;
1425
- entries--;
1426
- } else {
1427
- prevVal = val;
1428
- const b = val & hmask;
1429
- ePtr[n] = data + RABIN_WINDOW;
1430
- eVal[n] = val;
1431
- eNext[n] = hash[b];
1432
- hash[b] = n;
1433
- n++;
1434
- hashCount[b] = hashCount[b] + 1;
1435
- }
1436
- }
1437
- for (let b = 0; b < hsize; b++) {
1438
- const count = hashCount[b];
1439
- if (count <= HASH_LIMIT) continue;
1440
- entries -= count - HASH_LIMIT;
1441
- let entry = hash[b];
1442
- let acc = 0;
1443
- do {
1444
- acc += count - HASH_LIMIT;
1445
- if (acc > 0) {
1446
- const keep = entry;
1447
- do {
1448
- entry = eNext[entry];
1449
- acc -= HASH_LIMIT;
1450
- } while (acc > 0);
1451
- eNext[keep] = eNext[entry];
1452
- }
1453
- entry = eNext[entry];
1454
- } while (entry >= 0);
1455
- }
1456
- const start = new Int32Array(hsize + 1);
1457
- const ptr = new Int32Array(entries);
1458
- const valOut = new Uint32Array(entries);
1459
- let p = 0;
1460
- for (let b = 0; b < hsize; b++) {
1461
- start[b] = p;
1462
- for (let e = hash[b]; e >= 0; e = eNext[e]) {
1463
- ptr[p] = ePtr[e];
1464
- valOut[p] = eVal[e];
1465
- p++;
1466
- }
1467
- }
1468
- start[hsize] = p;
1469
- return {
1470
- src: buf,
1471
- mask: hmask,
1472
- start,
1473
- ptr,
1474
- val: valOut
1475
- };
1476
- }
1477
- /** `create_delta`: undefined when the delta would exceed `maxSize` (0: no limit). */
1478
- function createDelta(index, trg, maxSize) {
1479
- const trgSize = trg.length;
1480
- if (!trgSize) return void 0;
1481
- let out = /* @__PURE__ */ new Uint8Array(8192);
1482
- let outsize = 8192;
1483
- if (maxSize && outsize >= maxSize) {
1484
- outsize = maxSize + MAX_OP_SIZE + 1;
1485
- out = new Uint8Array(outsize);
1486
- }
1487
- let outpos = 0;
1488
- const grow = (size) => {
1489
- const next = new Uint8Array(size);
1490
- next.set(out.subarray(0, Math.min(out.length, size)));
1491
- out = next;
1492
- };
1493
- let l = index.src.length;
1494
- while (l >= 128) {
1495
- out[outpos++] = (l | 128) & 255;
1496
- l = Math.floor(l / 128);
1497
- }
1498
- out[outpos++] = l;
1499
- l = trgSize;
1500
- while (l >= 128) {
1501
- out[outpos++] = (l | 128) & 255;
1502
- l = Math.floor(l / 128);
1503
- }
1504
- out[outpos++] = l;
1505
- const ref = index.src;
1506
- const refTop = ref.length;
1507
- let data = 0;
1508
- const top = trgSize;
1509
- outpos++;
1510
- let val = 0;
1511
- let i = 0;
1512
- for (; i < RABIN_WINDOW && data < top; i++, data++) {
1513
- out[outpos++] = trg[data];
1514
- val = ((val << 8 | trg[data]) ^ T[val >>> RABIN_SHIFT]) >>> 0;
1515
- }
1516
- let inscnt = i;
1517
- let moff = 0;
1518
- let msize = 0;
1519
- while (data < top) {
1520
- if (msize < 4096) {
1521
- val = (val ^ U[trg[data - RABIN_WINDOW]]) >>> 0;
1522
- val = ((val << 8 | trg[data]) ^ T[val >>> RABIN_SHIFT]) >>> 0;
1523
- const b = val & index.mask;
1524
- for (let e = index.start[b]; e < index.start[b + 1]; e++) {
1525
- const entryPtr = index.ptr[e];
1526
- let r = entryPtr;
1527
- let src = data;
1528
- let refSize = refTop - r;
1529
- if (index.val[e] !== val) continue;
1530
- if (refSize > top - src) refSize = top - src;
1531
- if (refSize <= msize) break;
1532
- while (refSize-- && trg[src++] === ref[r]) r++;
1533
- if (msize < r - entryPtr) {
1534
- msize = r - entryPtr;
1535
- moff = entryPtr;
1536
- if (msize >= 4096) break;
1537
- }
1538
- }
1539
- }
1540
- if (msize < 4) {
1541
- if (!inscnt) outpos++;
1542
- out[outpos++] = trg[data++];
1543
- inscnt++;
1544
- if (inscnt === 127) {
1545
- out[outpos - inscnt - 1] = inscnt;
1546
- inscnt = 0;
1547
- }
1548
- msize = 0;
1549
- } else {
1550
- if (inscnt) {
1551
- while (moff && ref[moff - 1] === trg[data - 1]) {
1552
- msize++;
1553
- moff--;
1554
- data--;
1555
- outpos--;
1556
- if (--inscnt) continue;
1557
- outpos--;
1558
- inscnt--;
1559
- break;
1560
- }
1561
- out[outpos - inscnt - 1] = inscnt & 255;
1562
- inscnt = 0;
1563
- }
1564
- const left = msize < 65536 ? 0 : msize - 65536;
1565
- msize -= left;
1566
- const op = outpos++;
1567
- let cmd = 128;
1568
- if (moff & 255) {
1569
- out[outpos++] = moff & 255;
1570
- cmd |= 1;
1571
- }
1572
- if (moff & 65280) {
1573
- out[outpos++] = moff >>> 8 & 255;
1574
- cmd |= 2;
1575
- }
1576
- if (moff & 16711680) {
1577
- out[outpos++] = moff >>> 16 & 255;
1578
- cmd |= 4;
1579
- }
1580
- if (moff & 4278190080) {
1581
- out[outpos++] = moff >>> 24 & 255;
1582
- cmd |= 8;
1583
- }
1584
- if (msize & 255) {
1585
- out[outpos++] = msize & 255;
1586
- cmd |= 16;
1587
- }
1588
- if (msize & 65280) {
1589
- out[outpos++] = msize >>> 8 & 255;
1590
- cmd |= 32;
1591
- }
1592
- out[op] = cmd;
1593
- data += msize;
1594
- moff += msize;
1595
- msize = left;
1596
- if (moff > 4294967295) msize = 0;
1597
- if (msize < 4096) {
1598
- val = 0;
1599
- for (let j = -16; j < 0; j++) val = ((val << 8 | trg[data + j]) ^ T[val >>> RABIN_SHIFT]) >>> 0;
1600
- }
1601
- }
1602
- if (outpos >= outsize - MAX_OP_SIZE) {
1603
- outsize = Math.floor(outsize * 3 / 2);
1604
- if (maxSize && outsize >= maxSize) outsize = maxSize + MAX_OP_SIZE + 1;
1605
- if (maxSize && outpos > maxSize) break;
1606
- grow(outsize);
1607
- }
1608
- }
1609
- if (inscnt) out[outpos - inscnt - 1] = inscnt;
1610
- if (maxSize && outpos > maxSize) return void 0;
1611
- return out.slice(0, outpos);
1612
- }
1613
- /** `diff_delta`: the delta of `trg` against `src`, undefined past `maxSize`. */
1614
- function gitDiffDelta(src, trg, maxSize) {
1615
- const index = createDeltaIndex(src);
1616
- if (!index) return void 0;
1617
- return createDelta(index, trg, maxSize);
1618
- }
1619
- const EN85 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
1620
- /** base85.c's `encode_85` of `bytes` bytes at `at`. */
1621
- function encode85(data, at, bytes) {
1622
- let out = "";
1623
- while (bytes) {
1624
- let acc = 0;
1625
- for (let cnt = 24; cnt >= 0; cnt -= 8) {
1626
- const ch = data[at++];
1627
- acc = (acc | ch << cnt) >>> 0;
1628
- if (--bytes === 0) break;
1629
- }
1630
- const chunk = [];
1631
- for (let cnt = 4; cnt >= 0; cnt--) {
1632
- const v = acc % 85;
1633
- acc = Math.floor(acc / 85);
1634
- chunk[cnt] = EN85[v];
1635
- }
1636
- out += chunk.join("");
1637
- }
1638
- return out;
1639
- }
1640
- function deflateIt(data) {
1641
- return compressBlockPako(data, { level: 1 });
1642
- }
1643
- /** `emit_binary_diff_body`: one direction (`one` to `two`). */
1644
- function binaryDiffBody(one, two) {
1645
- const deflated = deflateIt(two);
1646
- let delta;
1647
- let origSize = 0;
1648
- if (one.length && two.length) {
1649
- const raw = gitDiffDelta(one, two, deflated.length);
1650
- if (raw) {
1651
- origSize = raw.length;
1652
- delta = deflateIt(raw);
1653
- }
1654
- }
1655
- let out;
1656
- let data;
1657
- if (delta && delta.length < deflated.length) {
1658
- out = `delta ${origSize}\n`;
1659
- data = delta;
1660
- } else {
1661
- out = `literal ${two.length}\n`;
1662
- data = deflated;
1663
- }
1664
- for (let at = 0; at < data.length;) {
1665
- const bytes = Math.min(52, data.length - at);
1666
- const lead = bytes <= 26 ? String.fromCharCode(bytes + 64) : String.fromCharCode(bytes - 26 + 96);
1667
- out += `${lead}${encode85(data, at, bytes)}\n`;
1668
- at += bytes;
1669
- }
1670
- return `${out}\n`;
1671
- }
1672
- /** `emit_binary_diff`: "GIT binary patch", the forward and the reverse hunks. */
1673
- function gitBinaryPatch(one, two) {
1674
- return `GIT binary patch\n${binaryDiffBody(one, two)}${binaryDiffBody(two, one)}`;
1675
- }
1676
- //#endregion
1677
- //#region src/results/diff-color.ts
1678
- /**
1679
- * git's colored diff output (diff.c's `emit_*` functions, ws.c's `ws_check_emit`) and its
1680
- * moved-line detection (`--color-moved`: `add_lines_to_move_detection`,
1681
- * `mark_color_as_moved`, `dim_moved_lines`), byte for byte as `git diff --color=always`
1682
- * prints them.
1683
- *
1684
- * @example
1685
- * ```typescript
1686
- * const colors = { ...DEFAULT_DIFF_COLORS, old: parseGitColor("magenta") ?? "" };
1687
- * const patch = await formatPatch(pairs, { colors, colorMoved: "zebra" });
1688
- * // "\x1b[1mdiff --git a/f b/f\x1b[m\n...\x1b[31m-old line\x1b[m\n..."
1689
- * ```
1690
- *
1691
- * The palette ({@link DiffColors}) holds the escape sequence of each of git's
1692
- * `color.diff.<slot>` slots; an empty string is git's `normal` (nothing written before the
1693
- * text, a reset still written after it). With a palette, every `+` line (`-` and context
1694
- * lines too, with `--ws-error-highlight`) shows the whitespace errors of the path's
1695
- * whitespace rule (`core.whitespace`, the `whitespace` attribute) in the `whitespace` color.
1696
- * Moved lines are found over all the files of one diff: a writer buffers the lines in a
1697
- * {@link MovedLineBuffer} and {@link MovedLineBuffer.flushTo} marks and prints them.
1698
- *
1699
- * @module
1700
- */
1701
- /** git's color slots of the diff (`color.diff.<slot>`, diff.c's `color_diff_slots`) */
1702
- const DIFF_COLOR_SLOTS = [
1703
- "context",
1704
- "meta",
1705
- "frag",
1706
- "old",
1707
- "new",
1708
- "commit",
1709
- "whitespace",
1710
- "func",
1711
- "oldMoved",
1712
- "oldMovedAlternative",
1713
- "oldMovedDimmed",
1714
- "oldMovedAlternativeDimmed",
1715
- "newMoved",
1716
- "newMovedAlternative",
1717
- "newMovedDimmed",
1718
- "newMovedAlternativeDimmed",
1719
- "contextDimmed",
1720
- "oldDimmed",
1721
- "newDimmed",
1722
- "contextBold",
1723
- "oldBold",
1724
- "newBold"
1725
- ];
1726
- /** diff.c's `diff_colors`: git's default palette */
1727
- const DEFAULT_DIFF_COLORS = Object.freeze({
1728
- reset: "\x1B[m",
1729
- context: "",
1730
- meta: "\x1B[1m",
1731
- frag: "\x1B[36m",
1732
- old: "\x1B[31m",
1733
- new: "\x1B[32m",
1734
- commit: "\x1B[33m",
1735
- whitespace: "\x1B[41m",
1736
- func: "",
1737
- oldMoved: "\x1B[1;35m",
1738
- oldMovedAlternative: "\x1B[1;34m",
1739
- oldMovedDimmed: "\x1B[2m",
1740
- oldMovedAlternativeDimmed: "\x1B[2;3m",
1741
- newMoved: "\x1B[1;36m",
1742
- newMovedAlternative: "\x1B[1;33m",
1743
- newMovedDimmed: "\x1B[2m",
1744
- newMovedAlternativeDimmed: "\x1B[2;3m",
1745
- contextDimmed: "\x1B[2m",
1746
- oldDimmed: "\x1B[2;31m",
1747
- newDimmed: "\x1B[2;32m",
1748
- contextBold: "\x1B[1m",
1749
- oldBold: "\x1B[1;31m",
1750
- newBold: "\x1B[1;32m"
1751
- });
1752
- /** `parse_diff_color_slot`: the slot a `color.diff.<name>` names (any case), `plain` the context */
1753
- function diffColorSlotOf(name) {
1754
- const lower = name.toLowerCase();
1755
- if (lower === "plain") return "context";
1756
- return DIFF_COLOR_SLOTS.find((s) => s.toLowerCase() === lower);
1757
- }
1758
- /**
1759
- * `parse_color_moved`: a boolean (`true` is `zebra`), `no`, `plain`, `blocks`, `zebra`,
1760
- * `default`, `dimmed-zebra` (or `dimmed_zebra`); undefined for anything else
1761
- */
1762
- function parseColorMoved(arg) {
1763
- const bool = maybeBool(arg);
1764
- if (bool === false) return "no";
1765
- if (bool === true) return "zebra";
1766
- switch (arg) {
1767
- case "no": return "no";
1768
- case "plain":
1769
- case "blocks":
1770
- case "zebra": return arg;
1771
- case "default": return "zebra";
1772
- case "dimmed-zebra":
1773
- case "dimmed_zebra": return "dimmed-zebra";
1774
- default: return;
1775
- }
1776
- }
1777
- /** git's `git_parse_maybe_bool` (no value is true) */
1778
- function maybeBool(value) {
1779
- if (value === void 0) return true;
1780
- const v = value.toLowerCase();
1781
- if (v === "" || v === "false" || v === "no" || v === "off") return false;
1782
- if (v === "true" || v === "yes" || v === "on") return true;
1783
- if (/^[-+]?\d+$/.test(v)) return Number(v) !== 0;
1784
- }
1785
- /** The message git gives a `--color-moved` mode it does not know */
1786
- const COLOR_MOVED_MODE_ERROR = "error: color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed-zebra', 'plain'";
1787
- /** `COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE` (the `XDF_*` whitespace bits are xdiff's) */
1788
- const COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE = 32;
1789
- const XDF_IGNORE_WHITESPACE$1 = 2;
1790
- const XDF_IGNORE_WHITESPACE_CHANGE$1 = 4;
1791
- const XDF_IGNORE_WHITESPACE_AT_EOL = 8;
1792
- /**
1793
- * `parse_color_moved_ws`: the comma-separated modes as flags, with git's `error:` lines
1794
- * for the modes it refuses (the flags are not to be used then)
1795
- */
1796
- function parseColorMovedWs(arg) {
1797
- let flags = 0;
1798
- const errors = [];
1799
- for (const raw of arg.split(",")) {
1800
- const item = raw.trim();
1801
- if (item === "no") flags = 0;
1802
- else if (item === "ignore-space-change") flags |= XDF_IGNORE_WHITESPACE_CHANGE$1;
1803
- else if (item === "ignore-space-at-eol") flags |= XDF_IGNORE_WHITESPACE_AT_EOL;
1804
- else if (item === "ignore-all-space") flags |= XDF_IGNORE_WHITESPACE$1;
1805
- else if (item === "allow-indentation-change") flags |= 32;
1806
- else errors.push(`error: unknown color-moved-ws mode '${item}', possible values are 'ignore-space-change', 'ignore-space-at-eol', 'ignore-all-space', 'allow-indentation-change'`);
1807
- }
1808
- if (flags & 32 && flags & XDF_WHITESPACE_FLAGS) errors.push("error: color-moved-ws: allow-indentation-change cannot be combined with other whitespace modes");
1809
- return {
1810
- flags,
1811
- errors
1812
- };
1813
- }
1814
- /** `WSEH_NEW`: whitespace errors highlighted on `+` lines */
1815
- const WSEH_NEW = 65536;
1816
- /** `WSEH_CONTEXT`: on context lines */
1817
- const WSEH_CONTEXT = 1 << 17;
1818
- /** `WSEH_OLD`: on `-` lines */
1819
- const WSEH_OLD = 1 << 18;
1820
- /**
1821
- * `parse_ws_error_highlight`: `none`, `default`, `all`, `new`, `old`, `context`, comma
1822
- * separated; undefined for anything else
1823
- */
1824
- function parseWsErrorHighlight(arg) {
1825
- const r = wsErrorHighlightOf(arg);
1826
- return typeof r === "number" ? r : void 0;
1827
- }
1828
- /**
1829
- * {@link parseWsErrorHighlight}, or for a value git refuses the text before the token it
1830
- * stopped at (what its error message quotes)
1831
- */
1832
- function wsErrorHighlightOf(arg) {
1833
- let val = 0;
1834
- let at = 0;
1835
- const tokens = [
1836
- ["none", () => 0],
1837
- ["default", () => WSEH_NEW],
1838
- ["all", () => 458752],
1839
- ["new", (v) => v | WSEH_NEW],
1840
- ["old", (v) => v | WSEH_OLD],
1841
- ["context", (v) => v | WSEH_CONTEXT]
1842
- ];
1843
- while (at < arg.length) {
1844
- const found = tokens.find(([t]) => arg.startsWith(t, at) && (at + t.length === arg.length || arg[at + t.length] === ","));
1845
- if (!found) return { badPrefix: arg.slice(0, at) };
1846
- val = found[1](val);
1847
- at += found[0].length;
1848
- if (at < arg.length) at++;
1849
- }
1850
- return val;
1851
- }
1852
- const BLANK_LINE_EOF = 1 << 19;
1853
- const MOVED_LINE = 1 << 20;
1854
- const MOVED_LINE_ALT = 1 << 21;
1855
- const MOVED_LINE_UNINTERESTING = 1 << 22;
1856
- const ZEBRA_MASK = 3145728;
1857
- const CONTENT_WS_MASK = 524287;
1858
- /** `COLOR_MOVED_MIN_ALNUM_COUNT` */
1859
- const MIN_ALNUM_COUNT = 20;
1860
- /** git's `isalnum` (ASCII) */
1861
- const isAlnum = (c) => c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122;
1862
- /** Bytes written as the colored output is built */
1863
- var Out = class {
1864
- parts = [];
1865
- size = 0;
1866
- str(s) {
1867
- if (s.length === 0) return;
1868
- this.bytes(encodeGitPath(s));
1869
- }
1870
- bytes(b) {
1871
- if (b.length === 0) return;
1872
- this.parts.push(b);
1873
- this.size += b.length;
1874
- }
1875
- byte(c) {
1876
- this.bytes(Uint8Array.of(c));
1877
- }
1878
- done() {
1879
- const out = new Uint8Array(this.size);
1880
- let at = 0;
1881
- for (const p of this.parts) {
1882
- out.set(p, at);
1883
- at += p.length;
1884
- }
1885
- return out;
1886
- }
1887
- };
1888
- /**
1889
- * diff.c's `emit_line_0` (no line prefix): `setSign` before the sign, `set` before the
1890
- * text, the reset after them, the CR and LF of the line after the reset
1891
- */
1892
- function emitLine0(out, setSign, set, reset, first, line) {
1893
- let len = line.length;
1894
- let needsReset = false;
1895
- const hasNewline = len > 0 && line[len - 1] === 10;
1896
- if (hasNewline) len--;
1897
- const hasCr = len > 0 && line[len - 1] === 13;
1898
- if (hasCr) len--;
1899
- if (len > 0 || first) {
1900
- if (setSign !== void 0) {
1901
- out.str(setSign);
1902
- needsReset = true;
1903
- }
1904
- if (first) out.byte(first);
1905
- if (len > 0) {
1906
- if (set !== void 0) {
1907
- out.str(set);
1908
- needsReset = true;
1909
- }
1910
- out.bytes(line.subarray(0, len));
1911
- needsReset = true;
1912
- }
1913
- }
1914
- if (needsReset) out.str(reset);
1915
- if (hasCr) out.byte(13);
1916
- if (hasNewline) out.byte(10);
1917
- }
1918
- /** diff.c's `emit_line_ws_markup` */
1919
- function emitLineWsMarkup(out, o, set, sign, line, wsRule, blankAtEof) {
1920
- const { reset } = o.colors;
1921
- let ws;
1922
- if (o.wsErrorHighlight & wsRule) {
1923
- ws = o.colors.whitespace;
1924
- if (!ws) ws = void 0;
1925
- }
1926
- if (ws === void 0) emitLine0(out, set, void 0, reset, sign, line);
1927
- else if (blankAtEof) emitLine0(out, ws, void 0, reset, sign, line);
1928
- else {
1929
- emitLine0(out, set, void 0, reset, sign, /* @__PURE__ */ new Uint8Array(0));
1930
- wsCheckEmit(line, wsRule, out, set, reset, ws);
1931
- }
1932
- }
1933
- /** diff.c's `DIFF_SYMBOL_PLUS` and `DIFF_SYMBOL_MINUS` */
1934
- function renderContent(out, o, s) {
1935
- const c = o.colors;
1936
- const moved = s.flags & 7340032;
1937
- const plus = s.kind === "+";
1938
- let set;
1939
- switch (moved) {
1940
- case 7340032:
1941
- set = plus ? c.newMovedAlternativeDimmed : c.oldMovedAlternativeDimmed;
1942
- break;
1943
- case 3145728:
1944
- set = plus ? c.newMovedAlternative : c.oldMovedAlternative;
1945
- break;
1946
- case 5242880:
1947
- set = plus ? c.newMovedDimmed : c.oldMovedDimmed;
1948
- break;
1949
- case MOVED_LINE:
1950
- set = plus ? c.newMoved : c.oldMoved;
1951
- break;
1952
- default: set = plus ? c.new : c.old;
1953
- }
1954
- emitLineWsMarkup(out, o, set, plus ? 43 : 45, s.line, s.flags & CONTENT_WS_MASK, plus && (s.flags & BLANK_LINE_EOF) !== 0);
1955
- }
1956
- /**
1957
- * The output of one diff's patches while moved lines are looked for: what the writers push
1958
- * is kept, `+` and `-` lines apart ({@link MovedLineBuffer.content}), until
1959
- * {@link MovedLineBuffer.flushTo} marks the moved lines and prints everything.
1960
- */
1961
- var MovedLineBuffer = class extends ByteSink {
1962
- mode;
1963
- wsFlags;
1964
- symbols = [];
1965
- buffered = 0;
1966
- constructor(mode, wsFlags) {
1967
- super();
1968
- this.mode = mode;
1969
- this.wsFlags = wsFlags;
1970
- }
1971
- push(bytes) {
1972
- if (bytes.length === 0) return;
1973
- this.symbols.push({
1974
- kind: "raw",
1975
- bytes
1976
- });
1977
- this.buffered += bytes.length;
1978
- }
1979
- get length() {
1980
- return this.buffered;
1981
- }
1982
- bytes() {
1983
- throw new Error("MovedLineBuffer: flushTo() prints the buffered output");
1984
- }
1985
- /** A `+` or `-` line (the line without its sign, LF included) and its flags */
1986
- content(kind, line, flags) {
1987
- this.symbols.push({
1988
- kind,
1989
- line,
1990
- flags,
1991
- id: 0,
1992
- indentOff: 0,
1993
- indentWidth: 0
1994
- });
1995
- this.buffered += line.length + 1;
1996
- }
1997
- /** diff_flush_patch_all_file_pairs' end: marks the moved lines and prints everything */
1998
- flushTo(sink, o) {
1999
- const list = addLinesToMoveDetection(this.symbols, this.wsFlags);
2000
- markColorAsMoved(this.symbols, list, this.mode, this.wsFlags);
2001
- if (this.mode === "dimmed-zebra") dimMovedLines(this.symbols);
2002
- for (const s of this.symbols) if (s.kind === "raw") sink.push(s.bytes);
2003
- else {
2004
- const out = new Out();
2005
- renderContent(out, o, s);
2006
- sink.push(out.done());
2007
- }
2008
- this.symbols.length = 0;
2009
- this.buffered = 0;
2010
- }
2011
- };
2012
- const INDENT_BLANKLINE = -2147483648;
2013
- /** `fill_es_indent_data` */
2014
- function fillIndentData(s) {
2015
- const line = s.line;
2016
- const len = line.length;
2017
- const tabWidth = s.flags & 63;
2018
- let off = 0;
2019
- let width = 0;
2020
- while (off < len && (line[off] === 12 || line[off] === 11 || off < len - 1 && line[off] === 13)) off++;
2021
- for (;;) if (line[off] === 32) {
2022
- width++;
2023
- off++;
2024
- } else if (line[off] === 9) {
2025
- width += tabWidth - width % tabWidth;
2026
- while (line[++off] === 9) width += tabWidth;
2027
- } else break;
2028
- let i = off;
2029
- for (; i < len; i++) if (!isGitSpace(line[i])) break;
2030
- if (i === len) {
2031
- s.indentWidth = INDENT_BLANKLINE;
2032
- s.indentOff = len;
2033
- } else {
2034
- s.indentOff = off;
2035
- s.indentWidth = width;
2036
- }
2037
- }
2038
- /** `add_lines_to_move_detection`: each `+`/`-` line's id, and the lines of each id */
2039
- function addLinesToMoveDetection(symbols, wsFlags) {
2040
- const flags = wsFlags & XDF_WHITESPACE_FLAGS;
2041
- const interned = /* @__PURE__ */ new Map();
2042
- const list = [];
2043
- let prev;
2044
- for (const l of symbols) {
2045
- if (l.kind === "raw") {
2046
- prev = void 0;
2047
- continue;
2048
- }
2049
- if (wsFlags & 32) fillIndentData(l);
2050
- const hash = xdlHashRecord(l.line, l.indentOff, l.line.length, flags);
2051
- let bucket = interned.get(hash);
2052
- if (!bucket) {
2053
- bucket = [];
2054
- interned.set(hash, bucket);
2055
- }
2056
- const same = bucket.find((s) => xdlRecmatch(s.line, s.indentOff, s.line.length, l.line, l.indentOff, l.line.length, flags));
2057
- if (same) l.id = same.id;
2058
- else {
2059
- l.id = list.length;
2060
- list.push({});
2061
- bucket.push(l);
2062
- }
2063
- const entry = { es: l };
2064
- if (prev && prev.es.kind === l.kind) prev.nextLine = entry;
2065
- prev = entry;
2066
- const slot = list[l.id];
2067
- if (l.kind === "+") {
2068
- entry.nextMatch = slot.add;
2069
- slot.add = entry;
2070
- } else {
2071
- entry.nextMatch = slot.del;
2072
- slot.del = entry;
2073
- }
2074
- }
2075
- return list;
2076
- }
2077
- /** `cmp_in_block_with_wsd`: whether `l` does not continue the block (true: no match) */
2078
- function cmpInBlockWithWsd(cur, l, pmb) {
2079
- if (cur.es.id !== l.id) return true;
2080
- const aWidth = cur.es.indentWidth;
2081
- if (aWidth === INDENT_BLANKLINE) return false;
2082
- const delta = l.indentWidth - aWidth;
2083
- if (pmb.wsd === INDENT_BLANKLINE) pmb.wsd = delta;
2084
- return delta !== pmb.wsd;
2085
- }
2086
- /** `compute_ws_delta` */
2087
- function computeWsDelta(a, b) {
2088
- if (a.indentWidth === INDENT_BLANKLINE && b.indentWidth === INDENT_BLANKLINE) return INDENT_BLANKLINE;
2089
- return a.indentWidth - b.indentWidth;
2090
- }
2091
- /** `mark_color_as_moved` */
2092
- function markColorAsMoved(symbols, list, mode, wsFlags) {
2093
- const allowIndent = (wsFlags & 32) !== 0;
2094
- let pmb = [];
2095
- let flippedBlock = 0;
2096
- let blockLength = 0;
2097
- let movedSymbol;
2098
- /** `adjust_last_block`: unmarks a block of too few alphanumerics; whether it stays */
2099
- const adjustLastBlock = (n, length) => {
2100
- if (mode === "plain") return length !== 0;
2101
- let alnum = 0;
2102
- for (let i = 1; i < length + 1; i++) {
2103
- const s = symbols[n - i];
2104
- const line = s.kind === "raw" ? s.bytes : s.line;
2105
- for (let k = 0; k < line.length && line[k] !== 0; k++) {
2106
- if (!isAlnum(line[k])) continue;
2107
- alnum++;
2108
- if (alnum >= MIN_ALNUM_COUNT) return true;
2109
- }
2110
- }
2111
- for (let i = 1; i < length + 1; i++) {
2112
- const s = symbols[n - i];
2113
- if (s.kind !== "raw") s.flags &= -3145729;
2114
- }
2115
- return false;
2116
- };
2117
- let n = 0;
2118
- for (; n < symbols.length; n++) {
2119
- const l = symbols[n];
2120
- let match;
2121
- if (l.kind === "+") match = list[l.id]?.del;
2122
- else if (l.kind === "-") match = list[l.id]?.add;
2123
- else flippedBlock = 0;
2124
- if (pmb.length > 0 && (!match || l.kind !== movedSymbol)) {
2125
- if (!adjustLastBlock(n, blockLength) && blockLength > 1) {
2126
- match = void 0;
2127
- n -= blockLength;
2128
- }
2129
- pmb = [];
2130
- blockLength = 0;
2131
- flippedBlock = 0;
2132
- }
2133
- if (!match || l.kind === "raw") {
2134
- movedSymbol = void 0;
2135
- continue;
2136
- }
2137
- if (mode === "plain") {
2138
- l.flags |= MOVED_LINE;
2139
- continue;
2140
- }
2141
- const kept = [];
2142
- for (const block of pmb) {
2143
- const cur = block.match?.nextLine;
2144
- if (allowIndent ? cur !== void 0 && !cmpInBlockWithWsd(cur, l, block) : cur !== void 0 && cur.es.id === l.id) {
2145
- block.match = cur;
2146
- kept.push(block);
2147
- }
2148
- }
2149
- pmb = kept;
2150
- if (pmb.length === 0) {
2151
- const contiguous = adjustLastBlock(n, blockLength);
2152
- if (!contiguous && blockLength > 1) n -= blockLength;
2153
- else for (let m = match; m; m = m.nextMatch) pmb.push({
2154
- match: m,
2155
- wsd: allowIndent ? computeWsDelta(l, m.es) : 0
2156
- });
2157
- if (contiguous && pmb.length > 0 && movedSymbol === l.kind) flippedBlock = (flippedBlock + 1) % 2;
2158
- else flippedBlock = 0;
2159
- movedSymbol = pmb.length > 0 ? l.kind : void 0;
2160
- blockLength = 0;
2161
- }
2162
- if (pmb.length > 0) {
2163
- blockLength++;
2164
- l.flags |= MOVED_LINE;
2165
- if (flippedBlock && mode !== "blocks") l.flags |= MOVED_LINE_ALT;
2166
- }
2167
- }
2168
- adjustLastBlock(n, blockLength);
2169
- }
2170
- /** `dim_moved_lines` */
2171
- function dimMovedLines(symbols) {
2172
- for (let n = 0; n < symbols.length; n++) {
2173
- const l = symbols[n];
2174
- if (l.kind === "raw") continue;
2175
- if (!(l.flags & MOVED_LINE)) continue;
2176
- let prev = n > 0 ? symbols[n - 1] : void 0;
2177
- let next = n < symbols.length - 1 ? symbols[n + 1] : void 0;
2178
- if (prev && prev.kind === "raw") prev = void 0;
2179
- if (next && next.kind === "raw") next = void 0;
2180
- const p = prev;
2181
- const x = next;
2182
- if (p && (p.flags & ZEBRA_MASK) === (l.flags & ZEBRA_MASK) && x && (x.flags & ZEBRA_MASK) === (l.flags & ZEBRA_MASK)) {
2183
- l.flags |= MOVED_LINE_UNINTERESTING;
2184
- continue;
2185
- }
2186
- if (p && p.flags & MOVED_LINE && (p.flags & MOVED_LINE_ALT) !== (l.flags & MOVED_LINE_ALT)) continue;
2187
- if (x && x.flags & MOVED_LINE && (x.flags & MOVED_LINE_ALT) !== (l.flags & MOVED_LINE_ALT)) continue;
2188
- l.flags |= MOVED_LINE_UNINTERESTING;
2189
- }
2190
- }
2191
- /**
2192
- * The hunks of a text pair as diff.c's `fn_out_consume` prints them in color: the header
2193
- * in `frag` (`func` for its function line), each line in its color with its whitespace
2194
- * errors marked; into a {@link MovedLineBuffer}, the `+` and `-` lines are kept for move
2195
- * detection.
2196
- */
2197
- function writeColoredHunks(sink, hunks, ctx) {
2198
- const c = ctx.colors;
2199
- const reset = c.reset;
2200
- const buffer = sink instanceof MovedLineBuffer ? sink : void 0;
2201
- let blankPre = 0;
2202
- let blankPost = 0;
2203
- if (ctx.wsRule & 1024) {
2204
- const at = checkBlankAtEof(ctx.oldContent, ctx.newContent);
2205
- blankPre = at.preimage;
2206
- blankPost = at.postimage;
2207
- }
2208
- const emit = (out) => sink.push(out.done());
2209
- for (const hunk of hunks) {
2210
- emit(hunkHeader(hunk.header, c));
2211
- let lnoPre = hunk.oldStart;
2212
- let lnoPost = hunk.newStart;
2213
- let lastKind = "";
2214
- for (const line of hunk.lines) {
2215
- const complete = line.bytes.length > 0 && line.bytes[line.bytes.length - 1] === 10;
2216
- const text = complete ? line.bytes : withNewline$2(line.bytes);
2217
- if (line.kind === "+") {
2218
- lnoPost++;
2219
- let flags = WSEH_NEW | ctx.wsRule;
2220
- if (ctx.wsRule & 1024 && blankPre && blankPost && blankPre <= lnoPre && blankPost <= lnoPost && wsBlankLine(text, 0, text.length)) flags |= BLANK_LINE_EOF;
2221
- if (buffer) buffer.content("+", text, flags);
2222
- else {
2223
- const out = new Out();
2224
- renderContent(out, ctx, {
2225
- kind: "+",
2226
- line: text,
2227
- flags,
2228
- id: 0,
2229
- indentOff: 0,
2230
- indentWidth: 0
2231
- });
2232
- emit(out);
2233
- }
2234
- } else if (line.kind === "-") {
2235
- lnoPre++;
2236
- const flags = WSEH_OLD | ctx.wsRule;
2237
- if (buffer) buffer.content("-", text, flags);
2238
- else {
2239
- const out = new Out();
2240
- renderContent(out, ctx, {
2241
- kind: "-",
2242
- line: text,
2243
- flags,
2244
- id: 0,
2245
- indentOff: 0,
2246
- indentWidth: 0
2247
- });
2248
- emit(out);
2249
- }
2250
- } else {
2251
- lnoPre++;
2252
- lnoPost++;
2253
- const out = new Out();
2254
- emitLineWsMarkup(out, ctx, c.context, 32, text, (WSEH_CONTEXT | ctx.wsRule) & CONTENT_WS_MASK, false);
2255
- emit(out);
2256
- }
2257
- lastKind = line.kind;
2258
- if (!complete && line.bytes.length > 0) {
2259
- lnoPre++;
2260
- const flags = (lastKind === "+" ? WSEH_NEW : lastKind === "-" ? WSEH_OLD : WSEH_CONTEXT) | ctx.wsRule;
2261
- const set = flags & 4096 && flags & ctx.wsErrorHighlight ? c.whitespace : c.context;
2262
- const out = new Out();
2263
- emitLine0(out, set, void 0, reset, 0, NO_NEWLINE);
2264
- emit(out);
2265
- }
2266
- }
2267
- }
2268
- }
2269
- const NO_NEWLINE = encodeGitPath("\\n");
2270
- function withNewline$2(bytes) {
2271
- const out = new Uint8Array(bytes.length + 1);
2272
- out.set(bytes);
2273
- out[bytes.length] = 10;
2274
- return out;
2275
- }
2276
- /** diff.c's `emit_hunk_header` (the header as xdiff made it, LF included) */
2277
- function hunkHeader(line, c) {
2278
- const out = new Out();
2279
- const orgLen = line.length;
2280
- let len = orgLen;
2281
- let ep = -1;
2282
- for (let i = 2; i + 1 < len; i++) if (line[i] === 64 && line[i + 1] === 64) {
2283
- ep = i;
2284
- break;
2285
- }
2286
- if (len < 10 || line[0] !== 64 || line[1] !== 64 || ep < 0) {
2287
- emitLine0(out, c.context, void 0, c.reset, 0, line);
2288
- return out;
2289
- }
2290
- ep += 2;
2291
- out.str(c.frag);
2292
- out.bytes(line.subarray(0, ep));
2293
- out.str(c.reset);
2294
- for (let i = 1; i < 3; i++) {
2295
- const ch = line[len - i];
2296
- if (ch === 13 || ch === 10) len--;
2297
- }
2298
- const cp = ep;
2299
- while (ep < len && (line[ep] === 32 || line[ep] === 9)) ep++;
2300
- if (ep !== cp) {
2301
- out.str(c.context);
2302
- out.bytes(line.subarray(cp, ep));
2303
- out.str(c.reset);
2304
- }
2305
- if (ep < len) {
2306
- out.str(c.func);
2307
- out.bytes(line.subarray(ep, len));
2308
- out.str(c.reset);
2309
- }
2310
- out.bytes(line.subarray(len, orgLen));
2311
- if (orgLen === len || line[orgLen - 1] !== 10) out.byte(10);
2312
- return out;
2313
- }
2314
- /**
2315
- * diff.c's `emit_hunk_header` in color: the `@@ ... @@` part in `frag`, the function line in
2316
- * `func` (the header as xdiff made it, LF included)
2317
- */
2318
- function coloredHunkHeader(line, c) {
2319
- return hunkHeader(line, c).done();
2320
- }
2321
- //#endregion
2322
- //#region src/results/diff-words.ts
2323
- /**
2324
- * git's word diff (diff.c's `diff_words_*` and `fn_out_diff_words_*`): `--word-diff=plain`,
2325
- * `--word-diff=color` (`--color-words`) and `--word-diff=porcelain`, byte for byte as git
2326
- * prints the hunks of a text pair.
2327
- *
2328
- * @example
2329
- * ```typescript
2330
- * const words = compileWordRegex("[a-z]+");
2331
- * writeWordDiffHunks(sink, hunks, { mode: "plain", regex: words });
2332
- * // "@@ -1 +1 @@\nh(4),{+hh+}[44]\n"
2333
- * ```
2334
- *
2335
- * The removed and added lines between two context lines are gathered, split into words
2336
- * (each match of the word regex, cut at a newline; without one, each run of non-spaces),
2337
- * and the two word lists are diffed as lines (xdiff with no context, the common tail
2338
- * trimmed). The added side's text is printed with the removed words before the added ones
2339
- * that replace them: `[-old-]{+new+}` in plain mode, the `old` and `new` colors in color
2340
- * mode, one `-`/`+`/` ` line per piece with `~` for each newline in porcelain mode. Context
2341
- * lines are printed without their sign (porcelain: with it, followed by `~`).
2342
- *
2343
- * Not reproduced: under `log --graph` git writes the graph's line prefix in word mode only
2344
- * where a word hunk starts on a new line or a piece's text has a newline, so porcelain lines
2345
- * (and some plain or color lines) go without it; `git log` prefixes every line of ours.
2346
- *
2347
- * @module
2348
- */
2349
- /** The modes `--word-diff=` takes (`none` turns the word diff off) */
2350
- const WORD_DIFF_MODES = [
2351
- "plain",
2352
- "color",
2353
- "porcelain",
2354
- "none"
2355
- ];
2356
- const enc = (s) => encodeGitPath(s);
2357
- /** diff.c's `diff_words_styles` */
2358
- function styleOf(mode, colors) {
2359
- const elem = (prefix, suffix, color) => ({
2360
- prefix: enc(prefix),
2361
- suffix: enc(suffix),
2362
- color
2363
- });
2364
- const c = colors;
2365
- switch (mode) {
2366
- case "porcelain": return {
2367
- newWord: elem("+", "\n", c?.new),
2368
- oldWord: elem("-", "\n", c?.old),
2369
- ctx: elem(" ", "\n", c?.context),
2370
- newline: enc("~\n")
2371
- };
2372
- case "plain": return {
2373
- newWord: elem("{+", "+}", c?.new),
2374
- oldWord: elem("[-", "-]", c?.old),
2375
- ctx: elem("", "", c?.context),
2376
- newline: enc("\n")
2377
- };
2378
- default: return {
2379
- newWord: elem("", "", c?.new),
2380
- oldWord: elem("", "", c?.old),
2381
- ctx: elem("", "", c?.context),
2382
- newline: enc("\n")
2383
- };
2384
- }
2385
- }
2386
- /** `GIT_COLOR_RESET`, which ends a colored word whatever `DiffColors.reset` says */
2387
- const GIT_COLOR_RESET = enc("\x1B[m");
2388
- const TILDE_LINE = enc("~\n");
2389
- const NEWLINE = 10;
2390
- /** git's `isspace` (space, TAB, LF, CR) */
2391
- const isSpace = (c) => c === 32 || c === 9 || c === 10 || c === 13;
2392
- /** Compiled word regexes by pattern: a log compiles each once */
2393
- const compiled = /* @__PURE__ */ new Map();
2394
- /**
2395
- * The word regex as `init_diff_words_data` compiles it (`REG_EXTENDED | REG_NEWLINE`).
2396
- *
2397
- * @throws GitApiError git's `fatal: invalid regular expression: <regex>` (exit 128)
2398
- */
2399
- function compileWordRegex(pattern) {
2400
- const key = typeof pattern === "string" ? `s${pattern}` : `b${Array.from(pattern).join(",")}`;
2401
- let re = compiled.get(key);
2402
- if (!re) {
2403
- try {
2404
- re = compilePosixRegex(pattern, {
2405
- extended: true,
2406
- newline: true
2407
- });
2408
- } catch {
2409
- const text = typeof pattern === "string" ? pattern : new TextDecoder("latin1").decode(pattern);
2410
- throw new GitApiError(`fatal: invalid regular expression: ${text}`);
2411
- }
2412
- if (compiled.size >= 64) compiled.clear();
2413
- compiled.set(key, re);
2414
- }
2415
- return re;
2416
- }
2417
- /** The bytes of one word diff, gathered as git's `strbuf` and printed per symbol */
2418
- var Pieces = class {
2419
- parts = [];
2420
- bytes(b) {
2421
- if (b.length > 0) this.parts.push(b);
2422
- }
2423
- str(s) {
2424
- if (s) this.parts.push(enc(s));
2425
- }
2426
- /**
2427
- * Prints the piece as `DIFF_SYMBOL_WORD_DIFF` does (`fprintf("%.*s")`): up to its first NUL
2428
- * byte, whatever follows (suffix, reset, newline) dropped with it
2429
- */
2430
- flushTo(sink) {
2431
- for (const p of this.parts) {
2432
- const nul = p.indexOf(0);
2433
- if (nul < 0) {
2434
- sink.push(p);
2435
- continue;
2436
- }
2437
- if (nul > 0) sink.push(p.subarray(0, nul));
2438
- break;
2439
- }
2440
- this.parts = [];
2441
- }
2442
- };
2443
- /** `fn_out_diff_words_write_helper`: `text` as pieces of `el`, `newline` for each LF */
2444
- function writeHelper(sink, el, newline, text) {
2445
- const sb = new Pieces();
2446
- let at = 0;
2447
- let count = text.length;
2448
- while (count > 0) {
2449
- const nl = text.subarray(at, at + count).indexOf(NEWLINE);
2450
- if (nl !== 0) {
2451
- const colored = el.color !== void 0 && el.color !== "";
2452
- if (colored) sb.str(el.color);
2453
- sb.bytes(el.prefix);
2454
- sb.bytes(text.subarray(at, nl < 0 ? at + count : at + nl));
2455
- sb.bytes(el.suffix);
2456
- if (colored) sb.bytes(GIT_COLOR_RESET);
2457
- }
2458
- if (nl < 0) break;
2459
- sb.bytes(newline);
2460
- count -= nl + 1;
2461
- at += nl + 1;
2462
- if (count > 0) sb.flushTo(sink);
2463
- }
2464
- sb.flushTo(sink);
2465
- }
2466
- /** `find_word_boundaries`: the next word at or after `begin`, or undefined */
2467
- function findWord(text, regex, start) {
2468
- let begin = start;
2469
- const size = text.length;
2470
- while (regex && begin < size) {
2471
- const m = regex.exec(text.subarray(begin), size - begin, 1);
2472
- if (!m) return void 0;
2473
- const from = begin + m.start;
2474
- const nl = text.subarray(from, begin + m.end).indexOf(NEWLINE);
2475
- const end = nl >= 0 ? from + nl : begin + m.end;
2476
- begin = from;
2477
- if (begin === end) begin++;
2478
- else return begin > end ? void 0 : [begin, end];
2479
- }
2480
- while (begin < size && isSpace(text[begin])) begin++;
2481
- if (begin >= size) return void 0;
2482
- let end = begin + 1;
2483
- while (end < size && !isSpace(text[end])) end++;
2484
- return [begin, end];
2485
- }
2486
- /** `diff_words_fill`: the words of `text`, one per line */
2487
- function fillWords(text, regex) {
2488
- const orig = [[0, 0]];
2489
- const words = [];
2490
- let size = 0;
2491
- for (let i = 0; i < text.length;) {
2492
- const found = findWord(text, regex, i);
2493
- if (!found) break;
2494
- orig.push(found);
2495
- words.push(found);
2496
- size += found[1] - found[0] + 1;
2497
- i = found[1];
2498
- }
2499
- const lines = new Uint8Array(size);
2500
- let at = 0;
2501
- for (const [b, e] of words) {
2502
- lines.set(text.subarray(b, e), at);
2503
- at += e - b;
2504
- lines[at++] = NEWLINE;
2505
- }
2506
- return {
2507
- lines,
2508
- orig
2509
- };
2510
- }
2511
- /** The removed and added lines gathered since the last context line (`diff_words_data`) */
2512
- var WordDiffState = class {
2513
- sink;
2514
- regex;
2515
- minus = [];
2516
- plus = [];
2517
- style;
2518
- constructor(sink, regex, mode, colors) {
2519
- this.sink = sink;
2520
- this.regex = regex;
2521
- this.style = styleOf(mode, colors);
2522
- }
2523
- /** `diff_words_append`: a line without its sign, its LF included */
2524
- append(kind, line) {
2525
- (kind === "-" ? this.minus : this.plus).push(line);
2526
- }
2527
- /** `diff_words_flush` */
2528
- flush() {
2529
- if (this.minus.length > 0 || this.plus.length > 0) this.show();
2530
- }
2531
- /** `diff_words_show` */
2532
- show() {
2533
- const minus = concat(this.minus);
2534
- const plus = concat(this.plus);
2535
- this.minus = [];
2536
- this.plus = [];
2537
- const style = this.style;
2538
- if (plus.length === 0) {
2539
- writeHelper(this.sink, style.oldWord, style.newline, minus);
2540
- return;
2541
- }
2542
- let currentPlus = 0;
2543
- const mw = fillWords(minus, this.regex);
2544
- const pw = fillWords(plus, this.regex);
2545
- for (const change of xdiffHunks(mw.lines, pw.lines)) {
2546
- const minusFirst = change.chg1 ? change.i1 + 1 : change.i1;
2547
- const plusFirst = change.chg2 ? change.i2 + 1 : change.i2;
2548
- const [minusBegin, minusEnd] = span(mw.orig, minusFirst, change.chg1);
2549
- const [plusBegin, plusEnd] = span(pw.orig, plusFirst, change.chg2);
2550
- if (currentPlus !== plusBegin) writeHelper(this.sink, style.ctx, style.newline, plus.subarray(currentPlus, plusBegin));
2551
- if (minusBegin !== minusEnd) writeHelper(this.sink, style.oldWord, style.newline, minus.subarray(minusBegin, minusEnd));
2552
- if (plusBegin !== plusEnd) writeHelper(this.sink, style.newWord, style.newline, plus.subarray(plusBegin, plusEnd));
2553
- currentPlus = plusEnd;
2554
- }
2555
- if (currentPlus !== plus.length) writeHelper(this.sink, style.ctx, style.newline, plus.subarray(currentPlus));
2556
- }
2557
- };
2558
- /** The text a hunk of words covers: from its first word's start to its last word's end */
2559
- function span(orig, first, len) {
2560
- if (len === 0) {
2561
- const end = orig[first][1];
2562
- return [end, end];
2563
- }
2564
- return [orig[first][0], orig[first + len - 1][1]];
2565
- }
2566
- function concat(parts) {
2567
- if (parts.length === 1) return parts[0];
2568
- let size = 0;
2569
- for (const p of parts) size += p.length;
2570
- const out = new Uint8Array(size);
2571
- let at = 0;
2572
- for (const p of parts) {
2573
- out.set(p, at);
2574
- at += p.length;
2575
- }
2576
- return out;
2577
- }
2578
- /** diff.c's `emit_line_0` without a sign: `set` before the text, the reset after it */
2579
- function emitLine(sink, set, reset, line) {
2580
- let len = line.length;
2581
- const hasNewline = len > 0 && line[len - 1] === NEWLINE;
2582
- if (hasNewline) len--;
2583
- const hasCr = len > 0 && line[len - 1] === 13;
2584
- if (hasCr) len--;
2585
- if (len > 0) {
2586
- if (set) sink.push(enc(set));
2587
- sink.push(line.subarray(0, len));
2588
- if (reset) sink.push(enc(reset));
2589
- }
2590
- if (hasCr) sink.push(Uint8Array.of(13));
2591
- if (hasNewline) sink.push(Uint8Array.of(NEWLINE));
2592
- }
2593
- /**
2594
- * The hunks of a text pair as diff.c's `fn_out_consume` prints them under `--word-diff`:
2595
- * each header as usual (in color, `frag` and `func`), the removed and added lines between
2596
- * two context lines as their word diff, context lines without their sign (porcelain mode:
2597
- * with it, then `~`). An incomplete last line counts as ending in a newline; git's
2598
- * "" is not printed.
2599
- */
2600
- function writeWordDiffHunks(sink, hunks, options) {
2601
- const colors = options.colors;
2602
- const state = new WordDiffState(sink, options.regex, options.mode, colors);
2603
- const context = colors?.context ?? "";
2604
- const reset = colors?.reset ?? "";
2605
- for (const hunk of hunks) {
2606
- state.flush();
2607
- sink.push(colors ? coloredHunkHeader(hunk.header, colors) : hunk.header);
2608
- for (const line of hunk.lines) {
2609
- const bytes = line.bytes;
2610
- const text = bytes.length > 0 && bytes[bytes.length - 1] !== NEWLINE ? withNewline$1(bytes) : bytes;
2611
- if (line.kind === "-" || line.kind === "+") {
2612
- state.append(line.kind, text);
2613
- continue;
2614
- }
2615
- state.flush();
2616
- if (options.mode === "porcelain") {
2617
- emitLine(sink, context, reset, concat([Uint8Array.of(32), text]));
2618
- sink.push(TILDE_LINE);
2619
- } else emitLine(sink, context, reset, text);
2620
- }
2621
- }
2622
- state.flush();
2623
- }
2624
- function withNewline$1(bytes) {
2625
- const out = new Uint8Array(bytes.length + 1);
2626
- out.set(bytes);
2627
- out[bytes.length] = NEWLINE;
2628
- return out;
2629
- }
2630
- //#endregion
2631
- //#region src/results/diff-output.ts
2632
- /**
2633
- * git's diff output (`diff.c`) over file pairs: the patch (`git diff`), `--stat`,
2634
- * `--numstat`, `--shortstat`, `--name-only` and `--name-status`, byte for byte as git prints
2635
- * them.
2636
- *
2637
- * @example
2638
- * ```typescript
2639
- * const pairs: DiffFilePair[] = [{ status: "M", old: blobSide(...), new: blobSide(...) }];
2640
- * const patch = await formatPatch(pairs, { context: 3, indentHeuristic: true });
2641
- * const stat = formatStat(await computeDiffstat(pairs), { width: 80 });
2642
- * ```
2643
- *
2644
- * A pair has an old and a new side; a side that does not exist (an added file's old side,
2645
- * a deleted file's new side) is left out. Each file is shown as git's `builtin_diff` shows
2646
- * it: the `diff --git` header with mode, rename and `index` lines, then "Binary files ...
2647
- * differ" or the hunks of the text diff ({@link unifiedDiffHunks}). A pair between a file
2648
- * and a symbolic link is shown as a deletion and an addition. The header of a file whose
2649
- * diff comes out empty (only whitespace changes under `-w`) is printed only when it
2650
- * carries news of its own (mode change, rename, new or deleted file).
2651
- *
2652
- * @module
2653
- */
2654
- const S_IFMT$1 = 61440;
2655
- const GITLINK_MODE = 57344;
2656
- const FIRST_FEW_BYTES = 8e3;
2657
- /** @internal git diff's `big_file_threshold` default (512 MiB) */
2658
- const GIT_DIFF_BIG_FILE_THRESHOLD = 536870912;
2659
- const encoder = new TextEncoder();
2660
- /**
2661
- * The driver of a `diff` attribute value (git's `userdiff_find_by_path`): set means text,
2662
- * unset means binary, a name means `diff.<name>.*` from `config` or a builtin driver.
2663
- */
2664
- function diffDriverOf(attribute, config, compatibility = "2.56") {
2665
- if (attribute === true) return { binary: false };
2666
- if (attribute === false) return { binary: true };
2667
- if (typeof attribute !== "string") return void 0;
2668
- const name = attribute;
2669
- const binary = boolValue(config?.(`diff.${name}.binary`));
2670
- const algorithm = config?.(`diff.${name}.algorithm`);
2671
- const legacy = compatibility === "2.43";
2672
- const findFunction = userdiffFindFunction(name, config, legacy ? BUILTIN_FUNCNAME_PATTERNS_2_43 : BUILTIN_FUNCNAME_PATTERNS);
2673
- const wordRegex = userdiffWordRegex(name, config, legacy ? BUILTIN_WORD_REGEXES_2_43 : BUILTIN_WORD_REGEXES);
2674
- const textconvCommand = config?.(`diff.${name}.textconv`);
2675
- const cacheTextconv = boolValue(config?.(`diff.${name}.cachetextconv`));
2676
- if (binary === void 0 && !algorithm && !findFunction && !wordRegex && textconvCommand === void 0) return;
2677
- return {
2678
- name,
2679
- ...binary !== void 0 ? { binary } : {},
2680
- ...algorithm ? { algorithm } : {},
2681
- ...findFunction ? { findFunction } : {},
2682
- ...wordRegex ? { wordRegex } : {},
2683
- ...textconvCommand !== void 0 ? { textconvCommand } : {},
2684
- ...cacheTextconv !== void 0 ? { cacheTextconv } : {}
2685
- };
2686
- }
2687
- /** A git boolean (`git_config_bool`), undefined when unset or not one. */
2688
- const boolValue = (v) => parseGitBool(v);
2689
- /**
2690
- * A side as the diff reads it: its content and binary state, read once
2691
- *
2692
- * @internal
2693
- */
2694
- var LoadedSide = class {
2695
- spec;
2696
- driver;
2697
- otherId;
2698
- content;
2699
- probed;
2700
- constructor(spec, driver, otherId) {
2701
- this.spec = spec;
2702
- this.driver = driver;
2703
- this.otherId = otherId;
2704
- }
2705
- get valid() {
2706
- return this.spec !== void 0;
2707
- }
2708
- get mode() {
2709
- return this.spec?.mode ?? 0;
2710
- }
2711
- get id() {
2712
- return this.spec?.id ?? nullObjectIdLike(this.otherId);
2713
- }
2714
- read() {
2715
- this.content ??= this.spec ? this.spec.read() : Promise.resolve(/* @__PURE__ */ new Uint8Array(0));
2716
- return this.content;
2717
- }
2718
- /** The bytes textconv converts ({@link DiffSideSpec.readTextconvInput}) */
2719
- textconvInput() {
2720
- return this.spec?.readTextconvInput ? this.spec.readTextconvInput() : this.read();
2721
- }
2722
- /** `diff_filespec_is_binary` */
2723
- async isBinary(threshold) {
2724
- if (this.driver?.binary !== void 0) return this.driver.binary;
2725
- if (!this.spec) return false;
2726
- return (await this.probe(threshold)).binary;
2727
- }
2728
- probe(threshold) {
2729
- this.probed ??= (async () => {
2730
- if (this.spec?.probe && !this.content) return this.spec.probe(threshold);
2731
- const content = await this.read();
2732
- return {
2733
- size: content.length,
2734
- binary: content.length > threshold || hasNul(content)
2735
- };
2736
- })();
2737
- return this.probed;
2738
- }
2739
- async size(threshold) {
2740
- if (!this.spec) return 0;
2741
- return (await this.probe(threshold)).size;
2742
- }
2743
- };
2744
- function hasNul(content) {
2745
- const n = Math.min(content.length, FIRST_FEW_BYTES);
2746
- return (n === content.length ? content : content.subarray(0, n)).indexOf(0) >= 0;
2747
- }
2748
- function octal6(mode) {
2749
- return mode.toString(8).padStart(6, "0");
2750
- }
2751
- /**
2752
- * The driver a side's content is read with (`diff_filespec_load_driver`): a regular file's;
2753
- * an absent side, a symbolic link and a submodule take the default driver
2754
- *
2755
- * @internal
2756
- */
2757
- function contentDriver(spec, driver) {
2758
- return spec && (spec.mode & S_IFMT$1) === 32768 ? driver : void 0;
2759
- }
2760
- /**
2761
- * The full path of a pair's side for attributes; the other side's for an absent one
2762
- *
2763
- * @internal
2764
- */
2765
- function attrPathOf(side, other, fallback) {
2766
- const spec = side ?? other;
2767
- return spec ? spec.attrPath ?? spec.path : fallback;
2768
- }
2769
- /** @internal The diff driver of a path, from {@link DiffOutputOptions.driver} */
2770
- async function driverOf(options, path) {
2771
- if (!path || !options.driver) return void 0;
2772
- return options.driver(path);
2773
- }
2774
- /**
2775
- * The patch of the pairs, as `git diff` prints it.
2776
- */
2777
- async function formatPatch(pairs, options = {}) {
2778
- const sink = new ByteSink();
2779
- for (const pair of pairs) await writePairPatch(sink, pair, options);
2780
- return sink.bytes();
2781
- }
2782
- /** A side that is a directory (a subtree a diff lists for `--find-object`) */
2783
- function isTreeSide(side) {
2784
- return side !== void 0 && (side.mode & S_IFMT$1) === 16384;
2785
- }
2786
- /** Writes one pair as `run_diff` does: a file/symlink change as deletion and addition */
2787
- async function writePairPatch(sink, pair, options = {}, report) {
2788
- const { old: one, new: two } = pair;
2789
- if (isTreeSide(one) || isTreeSide(two)) return;
2790
- if (one && two && (one.mode & S_IFMT$1) !== (two.mode & S_IFMT$1)) {
2791
- await builtinDiff(sink, {
2792
- ...pair,
2793
- new: void 0
2794
- }, options, two.path, report);
2795
- await builtinDiff(sink, {
2796
- ...pair,
2797
- old: void 0
2798
- }, options, one.path, report);
2799
- return;
2800
- }
2801
- await builtinDiff(sink, pair, options, void 0, report);
2802
- }
2803
- /** `fill_metainfo`: rename/copy lines and the index line; whether they force the header */
2804
- function metainfo(pair, one, two, name, other, options, fullIndex = false) {
2805
- const quote = options.quotePath ?? true;
2806
- const set = options.colors?.meta ?? "";
2807
- const reset = options.colors?.reset ?? "";
2808
- let text = "";
2809
- let mustShow = false;
2810
- if (pair.status === "R" || pair.status === "C") {
2811
- const word = pair.status === "R" ? "rename" : "copy";
2812
- text += `${set}similarity index ${pair.score ?? 0}%${reset}\n`;
2813
- text += `${set}${word} from ${quotePath(name, quote)}${reset}\n`;
2814
- text += `${set}${word} to ${quotePath(other ?? name, quote)}${reset}\n`;
2815
- mustShow = true;
2816
- }
2817
- if (one.id !== two.id) {
2818
- const abbrev = (id) => id.slice(0, options.fullIndex || fullIndex ? id.length : options.abbrevLengths?.get(id) ?? options.abbrev ?? 7);
2819
- text += `${set}index ${abbrev(one.id)}..${abbrev(two.id)}`;
2820
- if (one.mode === two.mode) text += ` ${octal6(one.mode)}`;
2821
- text += `${reset}\n`;
2822
- }
2823
- return {
2824
- text,
2825
- mustShow
2826
- };
2827
- }
2828
- /** git's `builtin_diff` for one pair (both sides of the same kind, or one side absent) */
2829
- async function builtinDiff(sink, pair, options, absentPath, report) {
2830
- if (options.submodulePatch && (pair.old || pair.new) && (!pair.old || (pair.old.mode & S_IFMT$1) === GITLINK_MODE) && (!pair.new || (pair.new.mode & S_IFMT$1) === GITLINK_MODE)) {
2831
- await options.submodulePatch(sink, pair, options);
2832
- return;
2833
- }
2834
- const quote = options.quotePath ?? true;
2835
- const threshold = options.bigFileThreshold ?? 536870912;
2836
- const pathOne = pair.old?.path ?? absentPath ?? pair.new?.path ?? "";
2837
- const pathTwo = pair.new?.path ?? absentPath ?? pair.old?.path ?? "";
2838
- const name = pathOne;
2839
- const other = pathTwo !== name ? pathTwo : void 0;
2840
- const attrOne = attrPathOf(pair.old, pair.new, pathOne);
2841
- const attrTwo = attrPathOf(pair.new, pair.old, pathTwo);
2842
- const oneDriver = await driverOf(options, attrOne);
2843
- const twoDriver = attrTwo === attrOne ? oneDriver : await driverOf(options, attrTwo);
2844
- const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver), pair.new?.id);
2845
- const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver), pair.old?.id);
2846
- const textconvOne = one.driver?.textconv;
2847
- const textconvTwo = two.driver?.textconv;
2848
- const isBinary = async () => !options.text && (!textconvOne && await one.isBinary(threshold) || !textconvTwo && await two.isBinary(threshold));
2849
- const meta = metainfo(pair, one, two, name, other, options, options.binaryPatch === true && one.id !== two.id && (one.valid && await one.isBinary(threshold) || two.valid && await two.isBinary(threshold)));
2850
- let mustShow = meta.mustShow;
2851
- const aPrefix = options.srcPrefix ?? "a/";
2852
- const bPrefix = options.dstPrefix ?? "b/";
2853
- const nameA = one.valid ? name : other ?? name;
2854
- const nameB = two.valid ? other ?? name : nameA;
2855
- const aOne = quoteTwo(aPrefix, stripSlash(nameA), quote);
2856
- const bTwo = quoteTwo(bPrefix, stripSlash(nameB), quote);
2857
- const lbl0 = one.valid ? aOne : "/dev/null";
2858
- const lbl1 = two.valid ? bTwo : "/dev/null";
2859
- const cMeta = options.colors?.meta ?? "";
2860
- const cReset = options.colors?.reset ?? "";
2861
- let header = `${cMeta}diff --git ${aOne} ${bTwo}${cReset}\n`;
2862
- if (!one.valid) {
2863
- header += `${cMeta}new file mode ${octal6(two.mode)}${cReset}\n${meta.text}`;
2864
- mustShow = true;
2865
- } else if (!two.valid) {
2866
- header += `${cMeta}deleted file mode ${octal6(one.mode)}${cReset}\n${meta.text}`;
2867
- mustShow = true;
2868
- } else {
2869
- if (one.mode !== two.mode) {
2870
- header += `${cMeta}old mode ${octal6(one.mode)}${cReset}\n${cMeta}new mode ${octal6(two.mode)}${cReset}\n`;
2871
- mustShow = true;
2872
- }
2873
- header += meta.text;
2874
- if ((one.mode ^ two.mode) & S_IFMT$1) return;
2875
- }
2876
- if (report) {
2877
- report.gitLine = `diff --git ${aOne} ${bTwo}`;
2878
- report.extended = header.slice(header.indexOf("\n") + 1);
2879
- report.binary = false;
2880
- report.result = void 0;
2881
- report.oldLabel = void 0;
2882
- report.newLabel = void 0;
2883
- }
2884
- if (await isBinary()) {
2885
- if (report) report.binary = true;
2886
- if (one.valid && two.valid ? one.id === two.id : await one.size(threshold) === 0 && await two.size(threshold) === 0) {
2887
- if (mustShow) sink.text(header);
2888
- return;
2889
- }
2890
- if (options.binaryPatch) {
2891
- const a = one.valid ? await one.read() : /* @__PURE__ */ new Uint8Array(0);
2892
- const b = two.valid ? await two.read() : /* @__PURE__ */ new Uint8Array(0);
2893
- if (a.length === b.length && a.every((x, i) => x === b[i])) {
2894
- if (mustShow) sink.text(header);
2895
- return;
2896
- }
2897
- sink.text(header);
2898
- sink.text(gitBinaryPatch(a, b));
2899
- return;
2900
- }
2901
- sink.text(header);
2902
- sink.text(`Binary files ${lbl0} and ${lbl1} differ\n`);
2903
- return;
2904
- }
2905
- if (mustShow) {
2906
- sink.text(header);
2907
- header = "";
2908
- }
2909
- const driver = one.driver?.findFunction ? one.driver : two.driver;
2910
- const algorithm = oneDriver?.algorithm ?? options.algorithm;
2911
- const textOne = textconvOne ? await textconvOne(await one.textconvInput(), attrOne) : await one.read();
2912
- const textTwo = textconvTwo ? await textconvTwo(await two.textconvInput(), attrTwo) : await two.read();
2913
- const result = unifiedDiffHunks(textOne, textTwo, {
2914
- ...options,
2915
- algorithm,
2916
- indentHeuristic: options.indentHeuristic ?? true,
2917
- findFunction: driver?.findFunction
2918
- });
2919
- if (report) report.result = result;
2920
- if (result.hunks.length === 0) return;
2921
- if (header) sink.text(header);
2922
- const oldLabel = `--- ${lbl0}${lbl0.includes(" ") ? " " : ""}`;
2923
- const newLabel = `+++ ${lbl1}${lbl1.includes(" ") ? " " : ""}`;
2924
- if (report) {
2925
- report.oldLabel = oldLabel;
2926
- report.newLabel = newLabel;
2927
- }
2928
- const colors = options.colors;
2929
- const wordDiff = options.wordDiff === "none" ? void 0 : options.wordDiff ?? (options.wordDiffRegex !== void 0 ? "plain" : void 0);
2930
- if (wordDiff) {
2931
- sink.text(colors ? `${colors.meta}--- ${lbl0}${colors.reset}${lbl0.includes(" ") ? " " : ""}\n${colors.meta}+++ ${lbl1}${colors.reset}${lbl1.includes(" ") ? " " : ""}\n` : `${oldLabel}\n${newLabel}\n`);
2932
- const pattern = options.wordDiffRegex ?? contentDriver(pair.old, oneDriver)?.wordRegex ?? contentDriver(pair.new, twoDriver)?.wordRegex ?? options.defaultWordRegex;
2933
- writeWordDiffHunks(sink, coloredHunksOf(result), {
2934
- mode: wordDiff,
2935
- ...pattern !== void 0 ? { regex: compileWordRegex(pattern) } : {},
2936
- ...colors ? { colors } : {}
2937
- });
2938
- return;
2939
- }
2940
- if (!colors) {
2941
- sink.text(`${oldLabel}\n${newLabel}\n`);
2942
- writeHunks(sink, result);
2943
- return;
2944
- }
2945
- sink.text(`${colors.meta}--- ${lbl0}${colors.reset}${lbl0.includes(" ") ? " " : ""}\n${colors.meta}+++ ${lbl1}${colors.reset}${lbl1.includes(" ") ? " " : ""}\n`);
2946
- let wsRule = await options.whitespaceRule?.(two.valid ? attrTwo : attrOne) ?? 1224;
2947
- if (two.valid && (two.mode & S_IFMT$1) === 40960) wsRule &= -4097;
2948
- writeColoredHunks(sink, coloredHunksOf(result), {
2949
- colors,
2950
- wsErrorHighlight: options.wsHighlight ?? 65536,
2951
- wsRule,
2952
- oldContent: textOne,
2953
- newContent: textTwo
2954
- });
2955
- }
2956
- /** The hunks of a text diff with their lines' bytes, for the colored writer */
2957
- function coloredHunksOf(result) {
2958
- return result.hunks.map((hunk) => ({
2959
- header: formatHunkHeader(hunk),
2960
- oldStart: hunk.oldStart,
2961
- newStart: hunk.newStart,
2962
- lines: hunk.lines.map((line) => {
2963
- const lines = line.kind === "-" ? result.old : result.new;
2964
- const starts = lines.lineStarts;
2965
- return {
2966
- kind: line.kind,
2967
- bytes: lines.content.subarray(starts[line.index], starts[line.index + 1])
2968
- };
2969
- })
2970
- }));
2971
- }
2972
- function stripSlash(name) {
2973
- return name.startsWith("/") ? name.slice(1) : name;
2974
- }
2975
- /** The diffstat of the pairs (`builtin_diffstat` for each) */
2976
- async function computeDiffstat(pairs, options = {}) {
2977
- const threshold = options.bigFileThreshold ?? 536870912;
2978
- const files = [];
2979
- for (const pair of pairs) {
2980
- if (isTreeSide(pair.old) || isTreeSide(pair.new)) continue;
2981
- const nameA = pair.old?.path ?? pair.new?.path ?? "";
2982
- const nameB = pair.new?.path ?? nameA;
2983
- const renamed = nameB !== nameA;
2984
- const file = {
2985
- ...renamed ? { fromName: nameA } : {},
2986
- name: renamed ? nameB : nameA,
2987
- isRenamed: renamed,
2988
- isBinary: false,
2989
- added: 0,
2990
- deleted: 0
2991
- };
2992
- files.push(file);
2993
- const attrOne = attrPathOf(pair.old, pair.new, nameA);
2994
- const attrTwo = attrPathOf(pair.new, pair.old, nameB);
2995
- const oneDriver = await driverOf(options, attrOne);
2996
- const twoDriver = attrTwo === attrOne ? oneDriver : await driverOf(options, attrTwo);
2997
- const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver), pair.new?.id);
2998
- const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver), pair.old?.id);
2999
- const mayDiffer = !(one.valid && two.valid && one.spec?.idValid !== false && two.spec?.idValid !== false && one.id === two.id);
3000
- if (await one.isBinary(threshold) || await two.isBinary(threshold)) {
3001
- file.isBinary = true;
3002
- if (mayDiffer) {
3003
- file.added = await two.size(threshold);
3004
- file.deleted = await one.size(threshold);
3005
- }
3006
- } else if (mayDiffer) {
3007
- const counts = diffLineCounts(await one.read(), await two.read(), {
3008
- ...options,
3009
- algorithm: oneDriver?.algorithm ?? options.algorithm,
3010
- indentHeuristic: options.indentHeuristic ?? true
3011
- });
3012
- file.added = counts.added;
3013
- file.deleted = counts.deleted;
3014
- if (one.valid && two.valid && pair.status === "M" && !file.added && !file.deleted && one.mode === two.mode) files.pop();
3015
- }
3016
- }
3017
- return files;
3018
- }
3019
- /** git's `pprint_rename`: `a/{b => c}/d` */
3020
- function pprintRename(a, b, quote = true) {
3021
- const qa = quoteCStyleBody(a, quote);
3022
- const qb = quoteCStyleBody(b, quote);
3023
- if (qa !== void 0 || qb !== void 0) return `${quotePath(a, quote)} => ${quotePath(b, quote)}`;
3024
- const ea = encodeGitPath(a);
3025
- const eb = encodeGitPath(b);
3026
- const lenA = ea.length;
3027
- const lenB = eb.length;
3028
- let pfx = 0;
3029
- let i = 0;
3030
- while (i < lenA && i < lenB && ea[i] === eb[i]) {
3031
- if (ea[i] === 47) pfx = i + 1;
3032
- i++;
3033
- }
3034
- let oa = lenA;
3035
- let ob = lenB;
3036
- let sfx = 0;
3037
- const adjust = pfx ? 1 : 0;
3038
- const at = (arr, k) => k < arr.length ? arr[k] : 0;
3039
- while (pfx - adjust <= oa && pfx - adjust <= ob && at(ea, oa) === at(eb, ob)) {
3040
- if (at(ea, oa) === 47) sfx = lenA - oa;
3041
- oa--;
3042
- ob--;
3043
- }
3044
- const aMid = Math.max(0, lenA - pfx - sfx);
3045
- const bMid = Math.max(0, lenB - pfx - sfx);
3046
- const dec = (arr, s, e) => decodeGitPath(arr.subarray(s, e));
3047
- let out = "";
3048
- if (pfx + sfx) out += `${dec(ea, 0, pfx)}{`;
3049
- out += `${dec(ea, pfx, pfx + aMid)} => ${dec(eb, pfx, pfx + bMid)}`;
3050
- if (pfx + sfx) out += `}${dec(ea, lenA - sfx, lenA)}`;
3051
- return out;
3052
- }
3053
- function printName(file, quote) {
3054
- if (file.isRenamed && file.fromName !== void 0) return pprintRename(file.fromName, file.name, quote);
3055
- return quotePath(file.name, quote);
3056
- }
3057
- /**
3058
- * Display width of a name, as git's utf8_strwidth measures it (git 2.56's character widths:
3059
- * wide East Asian characters and emoji two columns, combining marks none; a name that is not
3060
- * valid UTF-8 its byte count)
3061
- */
3062
- function displayWidth(s) {
3063
- let ascii = true;
3064
- let width = 0;
3065
- for (let i = 0; i < s.length; i++) {
3066
- const c = s.charCodeAt(i);
3067
- if (c >= 127) {
3068
- ascii = false;
3069
- break;
3070
- }
3071
- if (c >= 32) width++;
3072
- }
3073
- return ascii ? width : gitStrWidth(encodeGitPath(s));
3074
- }
3075
- /**
3076
- * git's show_stats "scales" a name too wide for `width` columns: leading characters dropped
3077
- * (diff.c's utf8_ish_width steps, byte by byte through what is not UTF-8) until the rest fits
3078
- * in `width - 3`, then up to its first slash when it has one, behind a `...` prefix.
3079
- */
3080
- function shortenName(name, width) {
3081
- let nameLen = displayWidth(name);
3082
- if (width >= nameLen) return {
3083
- prefix: "",
3084
- name,
3085
- len: width
3086
- };
3087
- const len = Math.max(0, width - 3);
3088
- const bytes = encodeGitPath(name);
3089
- let at = 0;
3090
- while (nameLen > len && at < bytes.length) {
3091
- const [w, next] = gitCharWidthAt(bytes, at);
3092
- nameLen -= w;
3093
- at = next;
3094
- }
3095
- let rest = bytes.subarray(at);
3096
- const slash = rest.indexOf(47);
3097
- if (slash >= 0) rest = rest.subarray(slash);
3098
- return {
3099
- prefix: "...",
3100
- name: decodeGitPath(rest),
3101
- len
3102
- };
3103
- }
3104
- function decimalWidth(n) {
3105
- let width = 1;
3106
- for (let v = n; v >= 10; v = Math.floor(v / 10)) width++;
3107
- return width;
3108
- }
3109
- function scaleLinear(it, width, maxChange) {
3110
- if (!it) return 0;
3111
- return 1 + Math.floor(it * (width - 1) / maxChange);
3112
- }
3113
- /** git's `print_stat_summary_inserts_deletes` */
3114
- function statSummary(files, insertions, deletions) {
3115
- if (!files) return " 0 files changed\n";
3116
- let s = files === 1 ? ` ${files} file changed` : ` ${files} files changed`;
3117
- if (insertions || deletions === 0) s += insertions === 1 ? `, ${insertions} insertion(+)` : `, ${insertions} insertions(+)`;
3118
- if (deletions || insertions === 0) s += deletions === 1 ? `, ${deletions} deletion(-)` : `, ${deletions} deletions(-)`;
3119
- return `${s}\n`;
3120
- }
3121
- /** `--stat`, as git's `show_stats` prints it */
3122
- function formatStat(files, options = {}) {
3123
- if (files.length === 0) return "";
3124
- const quote = options.quotePath ?? true;
3125
- const isInteresting = (_f) => true;
3126
- let count = options.count ?? files.length;
3127
- let maxChange = 0;
3128
- let maxLen = 0;
3129
- let numberWidth = 0;
3130
- let binWidth = 0;
3131
- const names = /* @__PURE__ */ new Map();
3132
- let i = 0;
3133
- for (; i < count && i < files.length; i++) {
3134
- const file = files[i];
3135
- const change = file.added + file.deleted;
3136
- if (!isInteresting(file) && change === 0) {
3137
- count++;
3138
- continue;
3139
- }
3140
- const name = printName(file, quote);
3141
- names.set(file, name);
3142
- const len = displayWidth(name);
3143
- if (maxLen < len) maxLen = len;
3144
- if (file.isUnmerged) {
3145
- binWidth = binWidth < 8 ? 8 : binWidth;
3146
- continue;
3147
- }
3148
- if (file.isBinary) {
3149
- const w = 14 + decimalWidth(file.added) + decimalWidth(file.deleted);
3150
- binWidth = binWidth < w ? w : binWidth;
3151
- numberWidth = 3;
3152
- continue;
3153
- }
3154
- if (maxChange < change) maxChange = change;
3155
- }
3156
- count = i;
3157
- let width = options.width ?? 80;
3158
- numberWidth = decimalWidth(maxChange) > numberWidth ? decimalWidth(maxChange) : numberWidth;
3159
- const statNameWidth = options.nameWidth ?? 0;
3160
- const statGraphWidth = options.graphWidth ?? 0;
3161
- if (width < 22 + numberWidth) width = 22 + numberWidth;
3162
- let graphWidth = maxChange + 4 > binWidth ? maxChange : binWidth - 4;
3163
- if (statGraphWidth && statGraphWidth < graphWidth) graphWidth = statGraphWidth;
3164
- let nameWidth = statNameWidth > 0 && statNameWidth < maxLen ? statNameWidth : maxLen;
3165
- if (nameWidth + numberWidth + 6 + graphWidth > width) {
3166
- if (graphWidth > Math.trunc(width * 3 / 8) - numberWidth - 6) {
3167
- graphWidth = Math.trunc(width * 3 / 8) - numberWidth - 6;
3168
- if (graphWidth < 6) graphWidth = 6;
3169
- }
3170
- if (statGraphWidth && graphWidth > statGraphWidth) graphWidth = statGraphWidth;
3171
- if (nameWidth > width - numberWidth - 6 - graphWidth) nameWidth = width - numberWidth - 6 - graphWidth;
3172
- else graphWidth = width - numberWidth - 6 - nameWidth;
3173
- }
3174
- let out = "";
3175
- for (i = 0; i < count; i++) {
3176
- const file = files[i];
3177
- const added = file.added;
3178
- const deleted = file.deleted;
3179
- if (!isInteresting(file) && added + deleted === 0) continue;
3180
- let name = names.get(file) ?? printName(file, quote);
3181
- const shortened = shortenName(name, nameWidth);
3182
- const prefix = shortened.prefix;
3183
- const len = shortened.len;
3184
- name = shortened.name;
3185
- const padding = Math.max(0, len - displayWidth(name));
3186
- const pad = " ".repeat(padding);
3187
- if (file.isBinary) {
3188
- out += ` ${prefix}${name}${pad} | ${"Bin".padStart(numberWidth)}`;
3189
- if (!added && !deleted) {
3190
- out += "\n";
3191
- continue;
3192
- }
3193
- const c = options.colors;
3194
- out += ` ${c?.old ?? ""}${deleted}${c?.reset ?? ""} -> ${c?.new ?? ""}${added}${c?.reset ?? ""} bytes\n`;
3195
- continue;
3196
- }
3197
- if (file.isUnmerged) {
3198
- out += ` ${prefix}${name}${pad} | ${"Unmerged\n".padStart(numberWidth)}`;
3199
- continue;
3200
- }
3201
- let add = added;
3202
- let del = deleted;
3203
- if (graphWidth <= maxChange) {
3204
- let total = scaleLinear(add + del, graphWidth, maxChange);
3205
- if (total < 2 && add && del) total = 2;
3206
- if (add < del) {
3207
- add = scaleLinear(add, graphWidth, maxChange);
3208
- del = total - add;
3209
- } else {
3210
- del = scaleLinear(del, graphWidth, maxChange);
3211
- add = total - del;
3212
- }
3213
- }
3214
- out += ` ${prefix}${name}${pad} | ${String(added + deleted).padStart(numberWidth)}`;
3215
- out += added + deleted ? " " : "";
3216
- if (add > 0) out += `${options.colors?.new ?? ""}${"+".repeat(add)}${options.colors?.reset ?? ""}`;
3217
- if (del > 0) out += `${options.colors?.old ?? ""}${"-".repeat(del)}${options.colors?.reset ?? ""}`;
3218
- out += "\n";
3219
- }
3220
- let totalFiles = files.length;
3221
- let adds = 0;
3222
- let dels = 0;
3223
- let extraShown = false;
3224
- for (i = 0; i < files.length; i++) {
3225
- const file = files[i];
3226
- if (file.isUnmerged || !isInteresting(file) && file.added + file.deleted === 0) {
3227
- totalFiles--;
3228
- continue;
3229
- }
3230
- if (!file.isBinary) {
3231
- adds += file.added;
3232
- dels += file.deleted;
3233
- }
3234
- if (i < count) continue;
3235
- if (!extraShown) out += " ...\n";
3236
- extraShown = true;
3237
- }
3238
- return out + statSummary(totalFiles, adds, dels);
3239
- }
3240
- /** `--shortstat` (git's `show_shortstats`) */
3241
- function formatShortstat(files) {
3242
- if (files.length === 0) return "";
3243
- let totalFiles = files.length;
3244
- let adds = 0;
3245
- let dels = 0;
3246
- for (const file of files) if (file.isUnmerged) totalFiles--;
3247
- else if (!file.isBinary) {
3248
- adds += file.added;
3249
- dels += file.deleted;
3250
- }
3251
- return statSummary(totalFiles, adds, dels);
3252
- }
3253
- /** `--numstat` (git's `show_numstat`) */
3254
- function formatNumstat(files, options = {}) {
3255
- const quote = options.quotePath ?? true;
3256
- let out = "";
3257
- for (const file of files) {
3258
- out += file.isBinary ? "- - " : `${file.added}\t${file.deleted}\t`;
3259
- out += file.isRenamed ? printName(file, quote) : quotePath(file.name, quote);
3260
- out += "\n";
3261
- }
3262
- return out;
3263
- }
3264
- /** `--name-only`: the new path of each pair */
3265
- function formatNameOnly(pairs, options = {}) {
3266
- const quote = options.quotePath ?? true;
3267
- return pairs.map((p) => `${quotePath(p.new?.path ?? p.old?.path ?? "", quote)}\n`).join("");
3268
- }
3269
- /** `--name-status` (git's `diff_flush_raw` with `DIFF_FORMAT_NAME_STATUS`) */
3270
- function formatNameStatus(pairs, options = {}) {
3271
- const quote = options.quotePath ?? true;
3272
- let out = "";
3273
- for (const p of pairs) {
3274
- const score = p.status === "R" || p.status === "C" ? p.score ?? 0 : 0;
3275
- out += score ? `${p.status}${String(score).padStart(3, "0")}\t` : `${p.status}\t`;
3276
- if (p.status === "R" || p.status === "C") out += `${quotePath(p.old?.path ?? "", quote)}\t${quotePath(p.new?.path ?? "", quote)}\n`;
3277
- else out += `${quotePath(p.old ? p.old.path : p.new?.path ?? "", quote)}\n`;
3278
- }
3279
- return out;
3280
- }
3281
- /**
3282
- * `--summary` (diff.c's diff_summary for each pair): ` create mode 100644 <path>`, ` delete
3283
- * mode ...`, ` rename <a => b> (<n>%)` and ` copy ...` (then their mode change), ` mode change
3284
- * 100644 => 100755 <path>`; empty when nothing is to be said (git's is_summary_empty).
3285
- */
3286
- function formatSummary(pairs, quote = true) {
3287
- const mode6 = (mode) => mode.toString(8).padStart(6, "0");
3288
- const modeChange = (p, showName) => {
3289
- const a = p.old?.mode ?? 0;
3290
- const b = p.new?.mode ?? 0;
3291
- if (!a || !b || a === b) return "";
3292
- const name = showName ? ` ${quotePath(p.new?.path ?? "", quote)}` : "";
3293
- return ` mode change ${mode6(a)} => ${mode6(b)}${name}\n`;
3294
- };
3295
- const fileModeName = (what, side) => side?.mode ? ` ${what} mode ${mode6(side.mode)} ${quotePath(side.path, quote)}\n` : ` ${what} ${quotePath(side?.path ?? "", quote)}\n`;
3296
- let out = "";
3297
- for (const p of pairs) switch (p.status) {
3298
- case "D":
3299
- out += fileModeName("delete", p.old);
3300
- break;
3301
- case "A":
3302
- out += fileModeName("create", p.new);
3303
- break;
3304
- case "R":
3305
- case "C": {
3306
- const kind = p.status === "R" ? "rename" : "copy";
3307
- const names = pprintRename(p.old?.path ?? "", p.new?.path ?? "", quote);
3308
- out += ` ${kind} ${names} (${p.score ?? 0}%)\n`;
3309
- out += modeChange(p, false);
3310
- break;
3311
- }
3312
- default:
3313
- if (p.score) out += ` rewrite ${quotePath(p.new?.path ?? "", quote)} (${p.score}%)\n`;
3314
- out += modeChange(p, !p.score);
3315
- }
3316
- return out;
3317
- }
3318
- /**
3319
- * A side whose content is a stored blob (a submodule's: "Subproject commit <id>\n", as git
3320
- * shows a gitlink). The probe reads a text blob once and keeps it for {@link DiffSideSpec.read}.
3321
- */
3322
- function blobSide(blobs, path, mode, id) {
3323
- if ((mode & S_IFMT$1) === 57344) {
3324
- const content = encoder.encode(`Subproject commit ${id}\n`);
3325
- return {
3326
- path,
3327
- mode,
3328
- id,
3329
- read: async () => content
3330
- };
3331
- }
3332
- let loaded;
3333
- return {
3334
- path,
3335
- mode,
3336
- id,
3337
- async read() {
3338
- if (loaded) return loaded;
3339
- const chunks = [];
3340
- let size = 0;
3341
- for await (const chunk of await blobs.load(id) ?? []) {
3342
- chunks.push(chunk);
3343
- size += chunk.length;
3344
- }
3345
- const out = new Uint8Array(size);
3346
- let at = 0;
3347
- for (const c of chunks) {
3348
- out.set(c, at);
3349
- at += c.length;
3350
- }
3351
- loaded = out;
3352
- return out;
3353
- },
3354
- async probe(bigFileThreshold) {
3355
- const probe = await probeBlob(blobs, id, {
3356
- bigFileThreshold,
3357
- loadText: true
3358
- });
3359
- if (probe.content) loaded = probe.content;
3360
- return {
3361
- size: probe.size,
3362
- binary: probe.binary
3363
- };
3364
- }
3365
- };
3366
- }
3367
- /** A side whose content comes from elsewhere (a worktree file, a file outside a repository) */
3368
- function contentSide(path, mode, id, read, idValid = false) {
3369
- let content;
3370
- return {
3371
- path,
3372
- mode,
3373
- id,
3374
- idValid,
3375
- read: () => {
3376
- content ??= read();
3377
- return content;
3378
- }
3379
- };
3380
- }
3381
- /**
3382
- * Bytes for a string (diff output pieces are UTF-8; a path's escaped bytes, unquoted with
3383
- * `core.quotePath=false`, are written as the bytes they stand for)
3384
- */
3385
- function utf8(s) {
3386
- return encodeGitPath(s);
3387
- }
3388
- /** The blob id of `content` (as `hash-object` computes it) */
3389
- function blobIdOf(content) {
3390
- return bytesToHex(createSha1().update(encoder.encode(`blob ${content.length}\0`)).update(content).digest());
3391
- }
3392
- /**
3393
- * The pair `diff --no-index a b` compares for two files: a modification between two names
3394
- * (no rename detection), or an addition or deletion against `/dev/null`.
3395
- */
3396
- function noIndexPair(a, b) {
3397
- const side = (f) => {
3398
- if (!f.content) return void 0;
3399
- const content = f.content;
3400
- return contentSide(f.path, f.mode ?? 33188, blobIdOf(content), async () => content);
3401
- };
3402
- const old = side(a);
3403
- const neu = side(b);
3404
- if (!old && !neu) return void 0;
3405
- if (old && neu && old.id === neu.id && old.mode === neu.mode) return void 0;
3406
- return {
3407
- status: !old ? "A" : !neu ? "D" : "M",
3408
- old,
3409
- new: neu
3410
- };
3411
- }
3412
- /** `diff --no-index a b` for two files, as git prints it */
3413
- async function formatNoIndexDiff(a, b, options = {}) {
3414
- const pair = noIndexPair(a, b);
3415
- return pair ? formatPatch([pair], options) : /* @__PURE__ */ new Uint8Array(0);
3416
- }
3417
- //#endregion
3418
- //#region src/results/diff-check.ts
3419
- /**
3420
- * `git diff --check` (diff.c's `builtin_checkdiff` and `checkdiff_consume`): the whitespace
3421
- * errors and leftover conflict markers the new side of a pair adds, one
3422
- * `<file>:<line>: <error>.` line each, followed by the offending line with its errors in the
3423
- * `whitespace` color.
3424
- *
3425
- * @example
3426
- * ```typescript
3427
- * const sink = new ByteSink();
3428
- * const failed = await writePairCheck(sink, pair, { whitespaceRule: () => WS_DEFAULT_RULE });
3429
- * // sink: "x:2: trailing whitespace.\n+foo(); \n"
3430
- * ```
3431
- *
3432
- * @module
3433
- */
3434
- const S_IFMT = 61440;
3435
- const S_IFLNK = 40960;
3436
- const S_IFDIR = 16384;
3437
- /** `DEFAULT_CONFLICT_MARKER_SIZE` */
3438
- const DEFAULT_CONFLICT_MARKER_SIZE = 7;
3439
- /**
3440
- * merge-ll.c's `ll_merge_marker_size` over a `conflict-marker-size` attribute value: its
3441
- * integer, else 7 (with git's warning for a value that is no integer)
3442
- */
3443
- function conflictMarkerSizeOf(attribute, warn) {
3444
- if (attribute === void 0) return 7;
3445
- const text = typeof attribute === "string" ? attribute : "";
3446
- const m = /^[ \t\n\v\f\r]*([+-]?\d+)$/.exec(text);
3447
- const value = m ? Number.parseInt(m[1], 10) : NaN;
3448
- if (!Number.isSafeInteger(value) || value > 2147483647 || value < -2147483648) {
3449
- warn?.(`invalid marker-size '${typeof attribute === "string" ? attribute : attribute ? "true" : "false"}', expecting an integer`);
3450
- return 7;
3451
- }
3452
- return value <= 0 ? 7 : value;
3453
- }
3454
- /** merge-ll.c's `is_conflict_marker_line` over a line (its LF included) */
3455
- function isConflictMarkerLine(line, markerSize) {
3456
- if (line.length < markerSize + 1) return false;
3457
- const first = line[0];
3458
- if (first !== 61 && first !== 62 && first !== 60 && first !== 124) return false;
3459
- for (let i = 1; i < markerSize; i++) if (line[i] !== first) return false;
3460
- const after = line[markerSize];
3461
- if ((first === 60 || first === 62) && after !== 32) return false;
3462
- return after === 32 || after >= 9 && after <= 13;
3463
- }
3464
- const PLUS = Uint8Array.of(43);
3465
- function withNewline(bytes) {
3466
- const out = new Uint8Array(bytes.length + 1);
3467
- out.set(bytes);
3468
- out[bytes.length] = 10;
3469
- return out;
3470
- }
3471
- /**
3472
- * Writes the `--check` report of one pair (`run_checkdiff`); true when it found an error
3473
- * (git's `check_failed`). A tree side or an unmerged pair is not checked; the new side's
3474
- * whitespace rule and marker size are those of its path, and a binary new side is not read.
3475
- */
3476
- async function writePairCheck(sink, pair, options = {}, check = {}) {
3477
- const { old: one, new: two } = pair;
3478
- if (one && (one.mode & S_IFMT) === S_IFDIR || two && (two.mode & S_IFMT) === S_IFDIR) return false;
3479
- const name = (two ?? one)?.path ?? "";
3480
- const attrPath = attrPathOf(two, one, name);
3481
- let wsRule = await options.whitespaceRule?.(attrPath) ?? 1224;
3482
- const markerSize = await check.conflictMarkerSize?.(attrPath) ?? 7;
3483
- if (two && (two.mode & S_IFMT) === S_IFLNK) wsRule &= -4097;
3484
- const threshold = options.bigFileThreshold ?? 536870912;
3485
- const newSide = new LoadedSide(two, contentDriver(two, await driverOf(options, attrPath)));
3486
- if (await newSide.isBinary(threshold)) return false;
3487
- const a = await new LoadedSide(one, void 0).read();
3488
- const b = await newSide.read();
3489
- const colors = options.colors;
3490
- const ws = colors?.whitespace ?? "";
3491
- const reset = colors?.reset ?? "";
3492
- const set = colors?.new ?? "";
3493
- const out = {
3494
- str: (s) => {
3495
- if (s) sink.push(encodeGitPath(s));
3496
- },
3497
- bytes: (bytes) => {
3498
- if (bytes.length > 0) sink.push(bytes);
3499
- }
3500
- };
3501
- const text = (s) => sink.push(encodeGitPath(s));
3502
- let failed = false;
3503
- const result = unifiedDiffHunks(a, b, {
3504
- algorithm: "myers",
3505
- indentHeuristic: false,
3506
- context: 1
3507
- });
3508
- const lines = result.new;
3509
- for (const hunk of result.hunks) for (const line of hunk.lines) {
3510
- const kind = line.kind;
3511
- if (kind === "-") continue;
3512
- const start = lines.lineStarts[line.index];
3513
- const end = lines.lineStarts[line.index + 1];
3514
- const raw = lines.content.subarray(start, end);
3515
- const complete = raw.length > 0 && raw[raw.length - 1] === 10;
3516
- const body = complete ? raw : withNewline(raw);
3517
- const lineno = line.index + 1;
3518
- if (kind === "+") {
3519
- if (isConflictMarkerLine(body, markerSize)) {
3520
- failed = true;
3521
- text(`${name}:${lineno}: leftover conflict marker\n`);
3522
- }
3523
- const bad = wsCheck(body, wsRule);
3524
- if (bad) {
3525
- failed = true;
3526
- text(`${name}:${lineno}: ${whitespaceErrorString(bad)}.\n`);
3527
- out.str(set);
3528
- sink.push(PLUS);
3529
- out.str(reset);
3530
- wsCheckEmit(body, wsRule, out, set, reset, ws);
3531
- }
3532
- }
3533
- if (!complete && raw.length > 0 && kind === "+" && wsRule & 4096) {
3534
- failed = true;
3535
- text(`${name}:${lineno}: ${whitespaceErrorString(WS_INCOMPLETE_LINE)}.\n`);
3536
- }
3537
- }
3538
- if (wsRule & 1024) {
3539
- const at = checkBlankAtEof(a, b).postimage;
3540
- if (at) {
3541
- text(`${name}:${at}: ${whitespaceErrorString(WS_BLANK_AT_EOF)}.\n`);
3542
- failed = true;
3543
- }
3544
- }
3545
- return failed;
3546
- }
3547
- //#endregion
3548
- //#region src/results/diff-entry.ts
3549
- /**
3550
- * Type of change in a diff entry.
3551
- */
3552
- let ChangeType = /* @__PURE__ */ function(ChangeType) {
3553
- /** File was added */
3554
- ChangeType["ADD"] = "ADD";
3555
- /** File was modified */
3556
- ChangeType["MODIFY"] = "MODIFY";
3557
- /** File was deleted */
3558
- ChangeType["DELETE"] = "DELETE";
3559
- /** File was renamed */
3560
- ChangeType["RENAME"] = "RENAME";
3561
- /** File was copied */
3562
- ChangeType["COPY"] = "COPY";
3563
- return ChangeType;
3564
- }({});
3565
- /**
3566
- * Create a DiffEntry for an added file.
3567
- */
3568
- function createAddEntry(path, id, mode) {
3569
- return {
3570
- changeType: "ADD",
3571
- newPath: path,
3572
- newId: id,
3573
- newMode: mode
3574
- };
3575
- }
3576
- /**
3577
- * Create a DiffEntry for a deleted file.
3578
- */
3579
- function createDeleteEntry(path, id, mode) {
3580
- return {
3581
- changeType: "DELETE",
3582
- oldPath: path,
3583
- oldId: id,
3584
- oldMode: mode
3585
- };
3586
- }
3587
- /**
3588
- * Create a DiffEntry for a modified file.
3589
- */
3590
- function createModifyEntry(path, oldId, newId, oldMode, newMode) {
3591
- return {
3592
- changeType: "MODIFY",
3593
- oldPath: path,
3594
- newPath: path,
3595
- oldId,
3596
- newId,
3597
- oldMode,
3598
- newMode
3599
- };
3600
- }
3601
- /**
3602
- * Create a DiffEntry for a renamed file.
3603
- */
3604
- function createRenameEntry(oldPath, newPath, oldId, newId, oldMode, newMode, score) {
3605
- return {
3606
- changeType: "RENAME",
3607
- oldPath,
3608
- newPath,
3609
- oldId,
3610
- newId,
3611
- oldMode,
3612
- newMode,
3613
- score
3614
- };
3615
- }
3616
- /**
3617
- * Create a DiffEntry for a copied file.
3618
- */
3619
- function createCopyEntry(oldPath, newPath, oldId, newId, oldMode, newMode, score) {
3620
- return {
3621
- changeType: "COPY",
3622
- oldPath,
3623
- newPath,
3624
- oldId,
3625
- newId,
3626
- oldMode,
3627
- newMode,
3628
- score
3629
- };
3630
- }
3631
- //#endregion
3632
- //#region src/results/diff-formatter.ts
3633
- /**
3634
- * Formatter for unified diffs of DiffEntry objects, byte for byte as `git diff` prints them
3635
- * (see {@link formatPatch} for the rules).
3636
- */
3637
- const decoder = new TextDecoder();
3638
- /** The file pair of a diff entry: blob sides, or the content the entry reads */
3639
- function diffEntryToPair(entry, blobs) {
3640
- const side = (path, mode, id, read, idValid = false) => {
3641
- if (path === void 0 || id === void 0) return void 0;
3642
- const m = mode ?? 33188;
3643
- return read ? contentSide(path, m, id, read, idValid) : blobSide(blobs, path, m, id);
3644
- };
3645
- const status = entry.changeType === "ADD" ? "A" : entry.changeType === "DELETE" ? "D" : entry.changeType === "RENAME" ? "R" : entry.changeType === "COPY" ? "C" : entry.oldMode !== void 0 && entry.newMode !== void 0 && (entry.oldMode & 61440) !== (entry.newMode & 61440) ? "T" : "M";
3646
- const newSide = status === "D" ? void 0 : side(entry.newPath ?? entry.oldPath, entry.newMode, entry.newId, entry.readNew, entry.newDirtySubmodule === true && entry.newIdUnknown !== true);
3647
- if (newSide && entry.newSubmoduleDirt) newSide.submoduleDirt = entry.newSubmoduleDirt;
3648
- return {
3649
- status,
3650
- old: status === "A" ? void 0 : side(entry.oldPath ?? entry.newPath, entry.oldMode, entry.oldId, entry.readOld),
3651
- new: newSide,
3652
- ...entry.score !== void 0 ? { score: entry.score } : {}
3653
- };
3654
- }
3655
- /**
3656
- * Format DiffEntry objects into unified diff format, as `git diff` prints them.
3657
- *
3658
- * @example
3659
- * ```typescript
3660
- * const formatter = new DiffFormatter(store.blobs);
3661
- *
3662
- * // Get diff entries from DiffCommand
3663
- * const entries = await git.diff().setOldTree(commitA).setNewTree(commitB).call();
3664
- *
3665
- * // Format as unified diff
3666
- * process.stdout.write(await formatter.formatAll(entries));
3667
- * ```
3668
- */
3669
- var DiffFormatter = class {
3670
- blobs;
3671
- includeHeaders;
3672
- output;
3673
- constructor(blobs, options = {}) {
3674
- this.blobs = blobs;
3675
- const { contextLines, includeHeaders, abbreviateIds, abbreviationLength, algorithm, bigFileThreshold, ...rest } = options;
3676
- this.includeHeaders = includeHeaders ?? true;
3677
- this.output = {
3678
- ...rest,
3679
- context: rest.context ?? contextLines ?? 3,
3680
- algorithm: algorithm ? String(algorithm) : "myers",
3681
- abbrev: abbreviationLength ?? rest.abbrev ?? 7,
3682
- fullIndex: rest.fullIndex ?? abbreviateIds === false,
3683
- bigFileThreshold: bigFileThreshold ?? DEFAULT_BIG_FILE_THRESHOLD
3684
- };
3685
- }
3686
- /**
3687
- * Format a DiffEntry into a content diff.
3688
- *
3689
- * Each side is probed first (its size, and a NUL byte in its first 8000
3690
- * bytes, as git checks). A side over `bigFileThreshold` or binary makes the
3691
- * entry binary, and then the other side is not loaded. Text sides are loaded
3692
- * whole, as the diff algorithms need them, by the same single read as the probe.
3693
- *
3694
- * @param entry The diff entry to format
3695
- * @returns Content diff with hunks
3696
- */
3697
- async format(entry) {
3698
- const sink = new ByteSink();
3699
- const report = {
3700
- binary: false,
3701
- gitLine: "",
3702
- extended: ""
3703
- };
3704
- await writePairPatch(sink, diffEntryToPair(entry, this.blobs), this.output, report);
3705
- const result = {
3706
- entry,
3707
- isBinary: report.binary,
3708
- header: report.gitLine,
3709
- hunks: [],
3710
- patch: sink.bytes()
3711
- };
3712
- if (this.includeHeaders) {
3713
- result.extendedHeaders = report.extended;
3714
- const index = /^index .*$/m.exec(report.extended);
3715
- if (index) result.indexLine = index[0];
3716
- if (report.oldLabel) result.oldFileHeader = report.oldLabel;
3717
- if (report.newLabel) result.newFileHeader = report.newLabel;
3718
- }
3719
- const diff = report.result;
3720
- if (diff) {
3721
- if (entry.changeType !== "ADD") result.oldContent = diff.old.content;
3722
- if (entry.changeType !== "DELETE") result.newContent = diff.new.content;
3723
- for (const hunk of diff.hunks) {
3724
- const lines = [];
3725
- for (const line of hunk.lines) {
3726
- const rec = (line.kind === "-" ? diff.old : diff.new).line(line.index);
3727
- const complete = rec.length > 0 && rec[rec.length - 1] === 10;
3728
- lines.push(line.kind + decoder.decode(complete ? rec.subarray(0, -1) : rec));
3729
- if (!complete) lines.push("\");
3730
- }
3731
- result.hunks.push({
3732
- oldStart: hunk.oldStart,
3733
- oldCount: hunk.oldCount,
3734
- newStart: hunk.newStart,
3735
- newCount: hunk.newCount,
3736
- functionName: decoder.decode(hunk.func),
3737
- lines
3738
- });
3739
- }
3740
- }
3741
- return result;
3742
- }
3743
- /**
3744
- * The file's part of the diff as text: exactly git's output (LF-terminated lines), or
3745
- * without the file headers when `includeHeaders` is false. Bytes that are no UTF-8 decode
3746
- * as paths do (`decodeGitPath`), so `encodeGitPath` of the text gives the bytes back.
3747
- *
3748
- * @param diff The content diff to stringify
3749
- * @returns Unified diff string
3750
- */
3751
- toString(diff) {
3752
- const text = decodeGitPath(diff.patch);
3753
- if (this.includeHeaders) return text;
3754
- const at = text.search(/^(@@ |Binary files )/m);
3755
- return at < 0 ? "" : text.slice(at);
3756
- }
3757
- /**
3758
- * Format all diff entries to a single string, as `git diff` prints them.
3759
- *
3760
- * @param entries Array of diff entries
3761
- * @returns Complete unified diff output
3762
- */
3763
- async formatAll(entries) {
3764
- const parts = [];
3765
- for (const entry of entries) parts.push(this.toString(await this.format(entry)));
3766
- return parts.join("");
3767
- }
3768
- /**
3769
- * All diff entries as the bytes `git diff` prints (content that is not UTF-8 kept as it is).
3770
- */
3771
- async formatBytes(entries) {
3772
- const sink = new ByteSink();
3773
- for (const entry of entries) sink.push((await this.format(entry)).patch);
3774
- return sink.bytes();
3775
- }
3776
- };
3777
- //#endregion
3778
- //#region src/results/diff-order.ts
3779
- /**
3780
- * git's `diffcore-order.c` (`-O<orderfile>`, `diff.orderFile`): file pairs reordered by the
3781
- * glob patterns of an order file.
3782
- *
3783
- * @example
3784
- * ```typescript
3785
- * const patterns = parseOrderFile(new TextEncoder().encode("*.h\n# headers first\n*.c\n"));
3786
- * orderByPatterns(["b.c", "a.h", "README"], patterns, (p) => p);
3787
- * // ["a.h", "b.c", "README"]
3788
- * ```
3789
- *
3790
- * Each line of the file is a pattern, taken as it is (no trimming); empty lines and lines
3791
- * starting with `#` are skipped. A path's rank is the first pattern that matches it or one
3792
- * of its leading directories (wildmatch without `WM_PATHNAME`, so `*` also matches `/`);
3793
- * paths no pattern matches come last, and paths of the same rank keep their order.
3794
- *
3795
- * @module
3796
- */
3797
- /** The patterns of an order file (git's `prepare_order`) */
3798
- function parseOrderFile(content) {
3799
- const patterns = [];
3800
- let start = 0;
3801
- while (start < content.length) {
3802
- let end = start;
3803
- while (end < content.length && content[end] !== 10) end++;
3804
- if (content[start] !== 10 && content[start] !== 35) patterns.push(decodeGitPath(content.subarray(start, end)));
3805
- start = end < content.length ? end + 1 : end;
3806
- }
3807
- return patterns;
3808
- }
3809
- /** The rank of `path`: the first pattern matching it or a leading directory (`match_order`) */
3810
- function orderRank(patterns, path) {
3811
- for (let i = 0; i < patterns.length; i++) {
3812
- let p = path;
3813
- while (p) {
3814
- if (wildmatch(patterns[i], p)) return i;
3815
- const slash = p.lastIndexOf("/");
3816
- if (slash < 0) break;
3817
- p = p.slice(0, slash);
3818
- }
3819
- }
3820
- return patterns.length;
3821
- }
3822
- /** The items ordered by the rank of their paths, stably (`order_objects`) */
3823
- function orderByPatterns(items, patterns, pathOf) {
3824
- return items.map((item, index) => ({
3825
- item,
3826
- index,
3827
- rank: orderRank(patterns, pathOf(item))
3828
- })).sort((a, b) => a.rank - b.rank || a.index - b.index).map((e) => e.item);
3829
- }
3830
- //#endregion
3831
- //#region src/results/diff-pickaxe.ts
3832
- /**
3833
- * Pickaxe (git's diffcore-pickaxe.c): which pairs of a diff queue mention a string, a regex
3834
- * or an object. `-S<string>` keeps a pair whose two sides hold the string a different number
3835
- * of times, `-G<regex>` a pair whose added or removed lines match the regex, `--find-object`
3836
- * a pair with that object on either side.
3837
- *
3838
- * @example
3839
- * ```ts
3840
- * const pickaxe = DiffPickaxe.compile({ string: "frotz" });
3841
- * const kept = await pickaxe.filter(pairs, (p) => p, outputOptions);
3842
- * ```
3843
- *
3844
- * Both sides are read as the patch reads them: through the path's textconv when one applies,
3845
- * and `-G` passes over binary pairs unless `--text` is given (or textconv makes them text),
3846
- * as git does. `-S` counts non-overlapping occurrences, ASCII case folded under `-i`;
3847
- * `--pickaxe-regex` and `-G` compile POSIX extended regexes with `REG_NEWLINE` (and
3848
- * `REG_ICASE` under `-i`), so no JavaScript `RegExp` ever runs a user's pattern. `-G`
3849
- * diffs the two texts with xdiff's defaults (Myers, no indent heuristic, no whitespace
3850
- * options), whatever the patch shown uses.
3851
- *
3852
- * @module
3853
- */
3854
- const LF = 10;
3855
- /** ASCII lowercase (git's `tolower_trans_tbl` in the C locale) */
3856
- function lowerAscii(bytes) {
3857
- const out = new Uint8Array(bytes.length);
3858
- for (let i = 0; i < bytes.length; i++) {
3859
- const c = bytes[i];
3860
- out[i] = c >= 65 && c <= 90 ? c + 32 : c;
3861
- }
3862
- return out;
3863
- }
3864
- /** quote.c's basic_regex_quote_buf: a string as a basic regex matching it literally */
3865
- function basicRegexQuote(s) {
3866
- const out = [];
3867
- let i = 0;
3868
- if (s[i] === 94) out.push(92, s[i++]);
3869
- if (s[i] === 42) out.push(s[i++]);
3870
- for (; i < s.length; i++) {
3871
- const c = s[i];
3872
- if (c === 91 || c === 46 || c === 92 || c === 42) out.push(92, c);
3873
- else if (c === 36 && i + 1 === s.length) out.push(92, c);
3874
- else out.push(c);
3875
- }
3876
- return Uint8Array.from(out);
3877
- }
3878
- /** A pair's side whose object id git knows (`oid_valid`): a worktree file's is not */
3879
- function knownId(side) {
3880
- return side && side.idValid !== false ? side.id : void 0;
3881
- }
3882
- /** The compiled pickaxe of a diff (git's `diffcore_pickaxe`) */
3883
- var DiffPickaxe = class DiffPickaxe {
3884
- spec;
3885
- regex;
3886
- needle;
3887
- constructor(spec, regex, needle) {
3888
- this.spec = spec;
3889
- this.regex = regex;
3890
- this.needle = needle;
3891
- }
3892
- /**
3893
- * Compiles a pickaxe as diffcore_pickaxe does; an invalid regex throws git's `fatal:
3894
- * invalid regex: <glibc's message>` (exit 128).
3895
- */
3896
- static compile(spec) {
3897
- const compile = (pattern, extended) => {
3898
- try {
3899
- return compilePosixRegex(pattern, {
3900
- extended,
3901
- newline: true,
3902
- icase: spec.ignoreCase ?? false
3903
- });
3904
- } catch (e) {
3905
- if (e instanceof PosixRegexError) throw new GitApiError(`fatal: invalid regex: ${e.message}`).withExitCode(128);
3906
- throw e;
3907
- }
3908
- };
3909
- if (spec.grep !== void 0) return new DiffPickaxe(spec, compile(spec.grep, true), void 0);
3910
- if (spec.string !== void 0) {
3911
- if (spec.regex) return new DiffPickaxe(spec, compile(spec.string, true), void 0);
3912
- const bytes = new TextEncoder().encode(spec.string);
3913
- if (spec.ignoreCase && bytes.some((b) => b >= 128)) return new DiffPickaxe(spec, compile(basicRegexQuote(bytes), false), void 0);
3914
- return new DiffPickaxe(spec, void 0, spec.ignoreCase ? lowerAscii(bytes) : bytes);
3915
- }
3916
- return new DiffPickaxe(spec, void 0, void 0);
3917
- }
3918
- /** Whether the pickaxe reads the blobs of the pairs (`-S`, `-G`; not `--find-object`) */
3919
- get readsContent() {
3920
- return this.spec.objects === void 0;
3921
- }
3922
- /**
3923
- * The queue the pickaxe leaves (git's `pickaxe`): the items whose pair matches, or, under
3924
- * `--pickaxe-all`, every item when one matches and none otherwise. An item without a pair
3925
- * (an unmerged path) never matches.
3926
- */
3927
- async filter(queue, pairOf, options) {
3928
- if (this.spec.all) {
3929
- for (const item of queue) {
3930
- const pair = pairOf(item);
3931
- if (pair && await this.matches(pair, options)) return [...queue];
3932
- }
3933
- return [];
3934
- }
3935
- const out = [];
3936
- for (const item of queue) {
3937
- const pair = pairOf(item);
3938
- if (pair && await this.matches(pair, options)) out.push(item);
3939
- }
3940
- return out;
3941
- }
3942
- /** pickaxe_match: whether one pair matches */
3943
- async matches(pair, options) {
3944
- if (!pair.old && !pair.new) return false;
3945
- const objects = this.spec.objects;
3946
- if (objects) {
3947
- const a = knownId(pair.old);
3948
- const b = knownId(pair.new);
3949
- return a !== void 0 && objects.has(a) || b !== void 0 && objects.has(b);
3950
- }
3951
- const threshold = options.bigFileThreshold ?? 536870912;
3952
- const pathOne = pair.old?.path ?? pair.new?.path ?? "";
3953
- const pathTwo = pair.new?.path ?? pair.old?.path ?? "";
3954
- const attrOne = attrPathOf(pair.old, pair.new, pathOne);
3955
- const attrTwo = attrPathOf(pair.new, pair.old, pathTwo);
3956
- const oneDriver = await driverOf(options, attrOne);
3957
- const twoDriver = attrTwo === attrOne ? oneDriver : await driverOf(options, attrTwo);
3958
- const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver), pair.new?.id);
3959
- const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver), pair.old?.id);
3960
- const textconvOne = one.driver?.textconv ? one.driver : void 0;
3961
- const textconvTwo = two.driver?.textconv ? two.driver : void 0;
3962
- if ((textconvOne === textconvTwo || textconvOne !== void 0 && textconvTwo !== void 0 && textconvOne.name === textconvTwo.name) && unmodifiedPair(pair)) return false;
3963
- if (this.spec.grep !== void 0 && !options.text && (!textconvOne && await one.isBinary(threshold) || !textconvTwo && await two.isBinary(threshold))) return false;
3964
- const fill = async (side, attrPath) => {
3965
- const textconv = side.driver?.textconv;
3966
- if (!side.valid) return /* @__PURE__ */ new Uint8Array(0);
3967
- if (!textconv) return side.read();
3968
- try {
3969
- return await textconv(await side.textconvInput(), attrPath);
3970
- } catch (e) {
3971
- const message = e instanceof Error ? e.message : String(e);
3972
- throw new GitApiError(`${message ? `${message}\n` : ""}fatal: unable to read files to diff`).withExitCode(128);
3973
- }
3974
- };
3975
- const a = await fill(one, attrOne);
3976
- const b = await fill(two, attrTwo);
3977
- if (this.spec.grep !== void 0) return this.diffGrep(a, b, options);
3978
- const c1 = this.contains(a, 0);
3979
- return c1 !== this.contains(b, c1 + 1);
3980
- }
3981
- /** diff_grep: whether an added or removed line of the xdiff of `a` and `b` matches */
3982
- diffGrep(a, b, options) {
3983
- const regex = this.regex;
3984
- const result = unifiedDiffHunks(a, b, {
3985
- algorithm: "myers",
3986
- indentHeuristic: false,
3987
- context: options.context ?? 3,
3988
- interHunkContext: options.interHunkContext ?? 0
3989
- });
3990
- for (const hunk of result.hunks) for (const line of hunk.lines) {
3991
- if (line.kind === " ") continue;
3992
- const lines = line.kind === "-" ? result.old : result.new;
3993
- const start = lines.start(line.index);
3994
- const end = lines.start(line.index + 1);
3995
- const text = lines.content.subarray(start, end);
3996
- if (regex.test(text)) return true;
3997
- if (end > start && text[text.length - 1] !== LF) {
3998
- const withLf = new Uint8Array(text.length + 1);
3999
- withLf.set(text);
4000
- withLf[text.length] = LF;
4001
- if (regex.test(withLf)) return true;
4002
- }
4003
- }
4004
- return false;
4005
- }
4006
- /** contains(): the occurrences in `data`, up to `limit` (0: all) */
4007
- contains(data, limit) {
4008
- let count = 0;
4009
- const regex = this.regex;
4010
- if (regex) {
4011
- const subject = data;
4012
- let at = 0;
4013
- let notbol = false;
4014
- while (at < subject.length) {
4015
- const m = regex.exec(subject.subarray(at), void 0, 1, notbol);
4016
- if (!m) break;
4017
- notbol = true;
4018
- at += m.end;
4019
- if (at < subject.length && m.start === m.end) at++;
4020
- count++;
4021
- if (limit && count === limit) return count;
4022
- }
4023
- return count;
4024
- }
4025
- const needle = this.needle;
4026
- const hay = this.spec.ignoreCase ? lowerAscii(data) : data;
4027
- const n = needle.length;
4028
- if (n === 0) return 0;
4029
- const first = needle[0];
4030
- let at = 0;
4031
- while (at + n <= hay.length) {
4032
- const i = hay.indexOf(first, at);
4033
- if (i < 0 || i + n > hay.length) break;
4034
- let k = 1;
4035
- while (k < n && hay[i + k] === needle[k]) k++;
4036
- if (k < n) {
4037
- at = i + 1;
4038
- continue;
4039
- }
4040
- count++;
4041
- if (limit && count === limit) return count;
4042
- at = i + n;
4043
- }
4044
- return count;
4045
- }
4046
- };
4047
- /** diff_unmodified_pair: both sides valid, at one path, of one mode and known equal content */
4048
- function unmodifiedPair(pair) {
4049
- const { old: one, new: two } = pair;
4050
- if (!one || !two) return false;
4051
- if (one.mode !== two.mode || one.path !== two.path) return false;
4052
- const oneValid = one.idValid !== false;
4053
- const twoValid = two.idValid !== false;
4054
- if (oneValid && twoValid && one.id === two.id && !one.submoduleDirt && !two.submoduleDirt) return true;
4055
- return !oneValid && !twoValid;
4056
- }
4057
- //#endregion
4058
- //#region src/results/stash-result.ts
4059
- /**
4060
- * Status of stash apply operation.
4061
- */
4062
- let StashApplyStatus = /* @__PURE__ */ function(StashApplyStatus) {
4063
- /** Stash was applied successfully */
4064
- StashApplyStatus["OK"] = "ok";
4065
- /** Stash apply resulted in conflicts */
4066
- StashApplyStatus["CONFLICTS"] = "conflicts";
4067
- /** Stash apply failed */
4068
- StashApplyStatus["FAILED"] = "failed";
4069
- return StashApplyStatus;
4070
- }({});
4071
- //#endregion
4072
- //#region src/results/merge-result.ts
4073
- /**
4074
- * Status of a merge operation.
4075
- *
4076
- * Based on JGit's MergeResult.MergeStatus.
4077
- */
4078
- let MergeStatus = /* @__PURE__ */ function(MergeStatus) {
4079
- /** Merge is a fast-forward (only HEAD moved) */
4080
- MergeStatus["FAST_FORWARD"] = "fast-forward";
4081
- /** Fast-forward merge with squash (HEAD not moved, changes staged) */
4082
- MergeStatus["FAST_FORWARD_SQUASHED"] = "fast-forward-squashed";
4083
- /** Merge was a no-op - already up to date */
4084
- MergeStatus["ALREADY_UP_TO_DATE"] = "already-up-to-date";
4085
- /** Merge completed successfully (merge commit created) */
4086
- MergeStatus["MERGED"] = "merged";
4087
- /** Merge completed but not committed (--no-commit) */
4088
- MergeStatus["MERGED_NOT_COMMITTED"] = "merged-not-committed";
4089
- /** Merge was squashed (not committed, HEAD not updated) */
4090
- MergeStatus["MERGED_SQUASHED"] = "merged-squashed";
4091
- /** Merge has conflicts that need to be resolved */
4092
- MergeStatus["CONFLICTING"] = "conflicting";
4093
- /** Merge failed (preconditions not met) */
4094
- MergeStatus["FAILED"] = "failed";
4095
- /** Merge aborted (e.g., FF_ONLY when not possible) */
4096
- MergeStatus["ABORTED"] = "aborted";
4097
- return MergeStatus;
4098
- }({});
4099
- /**
4100
- * Fast-forward merge mode.
4101
- *
4102
- * Based on JGit's MergeCommand.FastForwardMode.
4103
- */
4104
- let FastForwardMode = /* @__PURE__ */ function(FastForwardMode) {
4105
- /** Allow fast-forward when possible (default) */
4106
- FastForwardMode["FF"] = "ff";
4107
- /** Never fast-forward, always create merge commit */
4108
- FastForwardMode["NO_FF"] = "no-ff";
4109
- /** Only allow fast-forward, abort if not possible */
4110
- FastForwardMode["FF_ONLY"] = "ff-only";
4111
- return FastForwardMode;
4112
- }({});
4113
- /**
4114
- * Content merge strategy.
4115
- *
4116
- * Determines how to handle file-level conflicts.
4117
- * Based on JGit's ContentMergeStrategy.
4118
- */
4119
- let ContentMergeStrategy = /* @__PURE__ */ function(ContentMergeStrategy) {
4120
- /** Take our version for conflicts */
4121
- ContentMergeStrategy["OURS"] = "ours";
4122
- /** Take their version for conflicts */
4123
- ContentMergeStrategy["THEIRS"] = "theirs";
4124
- /** Perform union merge (both sides) */
4125
- ContentMergeStrategy["UNION"] = "union";
4126
- return ContentMergeStrategy;
4127
- }({});
4128
- /**
4129
- * Merge strategy.
4130
- *
4131
- * Based on JGit's MergeStrategy.
4132
- */
4133
- let MergeStrategy = /* @__PURE__ */ function(MergeStrategy) {
4134
- /**
4135
- * Recursive three-way merge (default).
4136
- *
4137
- * Standard merge algorithm that finds common ancestor and
4138
- * performs three-way merge on each file.
4139
- */
4140
- MergeStrategy["RECURSIVE"] = "recursive";
4141
- /**
4142
- * Always take our side.
4143
- *
4144
- * Creates a merge commit but keeps our tree unchanged.
4145
- * The other branch's changes are completely ignored.
4146
- * Use case: record that merge happened without accepting changes.
4147
- */
4148
- MergeStrategy["OURS"] = "ours";
4149
- /**
4150
- * Always take their side.
4151
- *
4152
- * Creates a merge commit but replaces our tree with theirs.
4153
- * Our changes are completely discarded.
4154
- * Use case: replace our branch with theirs while preserving history.
4155
- */
4156
- MergeStrategy["THEIRS"] = "theirs";
4157
- /**
4158
- * Simple resolve strategy.
4159
- *
4160
- * Similar to recursive but doesn't handle criss-cross merges.
4161
- * Uses a single merge base.
4162
- */
4163
- MergeStrategy["RESOLVE"] = "resolve";
4164
- return MergeStrategy;
4165
- }({});
4166
- /**
4167
- * Check if merge status represents a successful merge.
4168
- */
4169
- function isMergeSuccessful(status) {
4170
- return status === "fast-forward" || status === "fast-forward-squashed" || status === "already-up-to-date" || status === "merged" || status === "merged-not-committed" || status === "merged-squashed";
4171
- }
4172
- //#endregion
4173
- //#region src/results/status-result.ts
4174
- /**
4175
- * Implementation of the Status interface.
4176
- */
4177
- var StatusImpl = class {
4178
- added;
4179
- changed;
4180
- removed;
4181
- conflicting;
4182
- modified;
4183
- missing;
4184
- untracked;
4185
- ignored;
4186
- conflictingStageState;
4187
- files;
4188
- renamed;
4189
- warnings;
4190
- constructor(added, changed, removed, conflicting, worktree = {}) {
4191
- this.added = added;
4192
- this.changed = changed;
4193
- this.removed = removed;
4194
- this.conflicting = conflicting;
4195
- this.modified = worktree.modified ?? /* @__PURE__ */ new Set();
4196
- this.missing = worktree.missing ?? /* @__PURE__ */ new Set();
4197
- this.untracked = worktree.untracked ?? /* @__PURE__ */ new Set();
4198
- this.ignored = worktree.ignored ?? /* @__PURE__ */ new Set();
4199
- this.conflictingStageState = worktree.conflictingStageState ?? /* @__PURE__ */ new Map();
4200
- this.files = worktree.files ?? [];
4201
- this.renamed = worktree.renamed ?? /* @__PURE__ */ new Map();
4202
- this.warnings = worktree.warnings ?? [];
4203
- }
4204
- isClean() {
4205
- return !this.hasUncommittedChanges() && this.untracked.size === 0;
4206
- }
4207
- hasUncommittedChanges() {
4208
- return this.added.size > 0 || this.changed.size > 0 || this.removed.size > 0 || this.conflicting.size > 0 || this.modified.size > 0 || this.missing.size > 0;
4209
- }
4210
- };
4211
- /** git's byte order of paths (their bytes, as `strcmp`). */
4212
- function comparePaths(a, b) {
4213
- return compareGitPaths(a, b);
4214
- }
4215
- /**
4216
- * The submodule field of a porcelain v2 line: `N...` for a path that is no submodule, else
4217
- * `S` and whether its commit changed (`C`), it has tracked changes (`M`) and untracked files
4218
- * (`U`) inside, as `SC.U`.
4219
- */
4220
- function submoduleToken(e) {
4221
- const gitlink = 57344;
4222
- if (!(e.staged?.mode === gitlink || e.head?.mode === gitlink || e.worktreeMode === gitlink)) return "N...";
4223
- return `S${e.submoduleCommitChanged ? "C" : "."}${e.submoduleModified ? "M" : "."}${e.submoduleUntracked ? "U" : "."}`;
4224
- }
4225
- const octal = (mode) => (mode ?? 0).toString(8).padStart(6, "0");
4226
- /**
4227
- * git's quoting of a path in status output (`quote_path`): C-quoted when it needs it, bytes
4228
- * above 0x7f escaped only with `core.quotePath` (on by default); porcelain v1 puts a path
4229
- * with a space in quotes too (`QUOTE_PATH_QUOTE_SP`), v2 does not.
4230
- */
4231
- function quoteStatusPath(path, quoteSpace, quotePathFully) {
4232
- const body = quoteCStyleBody(path, quotePathFully);
4233
- if (body !== void 0) return `"${body}"`;
4234
- return quoteSpace && path.includes(" ") ? `"${path}"` : path;
4235
- }
4236
- /**
4237
- * The status as `git status --porcelain` (v1) or `--porcelain=v2` prints it, in the
4238
- * untracked and ignored modes the status was made with (`?? dir/`, `!! dir/`): the changed
4239
- * tracked paths first, then the untracked, then the ignored ones, each in git's path order.
4240
- * A rename is one line at its new path: `R old -> new` (v1), `2 R. ... R<score> new<TAB>old`
4241
- * (v2).
4242
- *
4243
- * @example
4244
- * ```typescript
4245
- * formatStatusPorcelain(await git.status().call());
4246
- * // " M a.txt\nA b.txt\n?? new.txt\n"
4247
- * ```
4248
- */
4249
- function formatStatusPorcelain(status, version = 1, options = {}) {
4250
- const fully = options.quotePath ?? true;
4251
- const z = options.z === true;
4252
- const quotePath = (path) => z ? path : quoteStatusPath(path, version === 1, fully);
4253
- const entries = status.files;
4254
- const tracked = entries.filter((e) => e.index !== "?" && e.index !== "!").sort((a, b) => (version === 2 ? (a.stages ? 1 : 0) - (b.stages ? 1 : 0) : 0) || comparePaths(a.path, b.path));
4255
- const untracked = entries.filter((e) => e.index === "?").sort((a, b) => comparePaths(a.path, b.path));
4256
- const ignored = entries.filter((e) => e.index === "!").sort((a, b) => comparePaths(a.path, b.path));
4257
- const lines = [];
4258
- for (const e of tracked) {
4259
- const path = quotePath(e.path);
4260
- const from = e.renamedFrom !== void 0 ? quotePath(e.renamedFrom) : void 0;
4261
- if (version === 1) {
4262
- if (z) lines.push(`${e.index}${e.worktree} ${path}${from !== void 0 ? `\0${from}` : ""}`);
4263
- else lines.push(`${e.index}${e.worktree} ${from !== void 0 ? `${from} -> ` : ""}${path}`);
4264
- continue;
4265
- }
4266
- const xy = `${e.index === " " ? "." : e.index}${e.worktree === " " ? "." : e.worktree}`;
4267
- const sub = submoduleToken(e);
4268
- const ZERO_ID = nullObjectIdLike(e.head?.id ?? e.staged?.id ?? e.stages?.find((x) => x !== void 0)?.id);
4269
- if (from !== void 0) {
4270
- lines.push([
4271
- "2",
4272
- xy,
4273
- sub,
4274
- octal(e.head?.mode),
4275
- octal(e.staged?.mode),
4276
- octal(e.worktreeMode),
4277
- e.head?.id ?? ZERO_ID,
4278
- e.staged?.id ?? ZERO_ID,
4279
- `R${e.renameScore ?? 100}`,
4280
- `${path}${z ? "\0" : " "}${from}`
4281
- ].join(" "));
4282
- continue;
4283
- }
4284
- if (e.stages) {
4285
- const [s1, s2, s3] = e.stages;
4286
- lines.push([
4287
- "u",
4288
- xy,
4289
- sub,
4290
- octal(s1?.mode),
4291
- octal(s2?.mode),
4292
- octal(s3?.mode),
4293
- octal(e.worktreeMode),
4294
- s1?.id ?? ZERO_ID,
4295
- s2?.id ?? ZERO_ID,
4296
- s3?.id ?? ZERO_ID,
4297
- path
4298
- ].join(" "));
4299
- continue;
4300
- }
4301
- lines.push([
4302
- "1",
4303
- xy,
4304
- sub,
4305
- octal(e.head?.mode),
4306
- octal(e.staged?.mode),
4307
- octal(e.worktreeMode),
4308
- e.head?.id ?? ZERO_ID,
4309
- e.staged?.id ?? ZERO_ID,
4310
- path
4311
- ].join(" "));
4312
- }
4313
- const mark = version === 1 ? ["??", "!!"] : ["?", "!"];
4314
- for (const e of untracked) lines.push(`${mark[0]} ${quotePath(e.path)}`);
4315
- for (const e of ignored) lines.push(`${mark[1]} ${quotePath(e.path)}`);
4316
- const eol = z ? "\0" : "\n";
4317
- return lines.map((l) => `${l}${eol}`).join("");
4318
- }
4319
- //#endregion
4320
- //#region src/results/blame-format.ts
4321
- /**
4322
- * `git blame` output of a {@link BlameResult}: the porcelain formats (`--porcelain`,
4323
- * `--line-porcelain`) and the default one, byte for byte as git prints them.
4324
- *
4325
- * @example
4326
- * ```typescript
4327
- * const result = await git.blame().setFilePath("README.md").call();
4328
- * process.stdout.write(formatBlamePorcelain(result));
4329
- * process.stdout.write(formatBlame(result)); // ^1234567 (Alice 2024-01-02 10:00:00 +0100 1) line
4330
- * ```
4331
- *
4332
- * @module
4333
- */
4334
- /** The commit's subject as `find_commit_subject` finds it: its first non-blank line */
4335
- function subjectOf(message, id) {
4336
- const lines = message.split("\n");
4337
- let i = 0;
4338
- while (i < lines.length && /^[ \t\r\v\f]*$/.test(lines[i]) && i < lines.length - 1) i++;
4339
- const subject = i < lines.length && !/^[ \t\r\v\f]*$/.test(lines[i]) ? lines[i] : "";
4340
- return subject.length > 0 ? subject : `(${id})`;
4341
- }
4342
- /** The lines of the blamed file, each with its terminator */
4343
- function fileLines(content) {
4344
- const out = [];
4345
- let start = 0;
4346
- for (let i = 0; i < content.length; i++) if (content[i] === 10) {
4347
- out.push(content.subarray(start, i + 1));
4348
- start = i + 1;
4349
- }
4350
- if (start < content.length) out.push(content.subarray(start));
4351
- return out;
4352
- }
4353
- function tzValue(tz) {
4354
- const n = Number.parseInt(tz, 10);
4355
- return Number.isNaN(n) ? 0 : n;
4356
- }
4357
- /** `show_date` with `DATE_ISO8601`: "2005-04-07 15:13:13 -0700" in the given zone */
4358
- function isoDate(time, tz) {
4359
- const t = tzValue(tz);
4360
- const minutes = Math.sign(t) * (Math.floor(Math.abs(t) / 100) * 60 + Math.abs(t) % 100);
4361
- const d = /* @__PURE__ */ new Date((time + minutes * 60) * 1e3);
4362
- const p = (n, w = 2) => String(n).padStart(w, "0");
4363
- const zone = `${t < 0 ? "-" : "+"}${p(Math.abs(t), 4)}`;
4364
- return `${p(d.getUTCFullYear(), 4)}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())} ${p(d.getUTCHours())}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())} ${zone}`;
4365
- }
4366
- /** Commits blamed for more than one path (git's `MORE_THAN_ONE_PATH`) */
4367
- function multiPathCommits(entries) {
4368
- const paths = /* @__PURE__ */ new Map();
4369
- for (const e of entries) {
4370
- let set = paths.get(e.commitId);
4371
- if (!set) {
4372
- set = /* @__PURE__ */ new Set();
4373
- paths.set(e.commitId, set);
4374
- }
4375
- set.add(e.sourcePath);
4376
- }
4377
- const out = /* @__PURE__ */ new Set();
4378
- for (const [id, set] of paths) if (set.size > 1) out.add(id);
4379
- return out;
4380
- }
4381
- /** `git blame --porcelain` (or `--line-porcelain`) */
4382
- function formatBlamePorcelain(result, options = {}) {
4383
- const quote = options.quotePath ?? true;
4384
- const repeat = options.linePorcelain ?? false;
4385
- const lines = fileLines(result.content ?? /* @__PURE__ */ new Uint8Array(0));
4386
- const multi = multiPathCommits(result.entries);
4387
- const shown = /* @__PURE__ */ new Set();
4388
- const sink = new ByteSink();
4389
- const details = (e, force) => {
4390
- let wrote = false;
4391
- if (force || !shown.has(e.commitId)) {
4392
- shown.add(e.commitId);
4393
- const c = e.commit;
4394
- sink.text(`author ${c.author.name}\nauthor-mail <${c.author.email}>\nauthor-time ${c.author.timestamp}\nauthor-tz ${c.author.tzOffset}\ncommitter ${c.committer.name}\ncommitter-mail <${c.committer.email}>\ncommitter-time ${c.committer.timestamp}\ncommitter-tz ${c.committer.tzOffset}\nsummary ${subjectOf(c.message, e.commitId)}\n`);
4395
- if (e.boundary) sink.text("boundary\n");
4396
- wrote = true;
4397
- }
4398
- if (wrote || multi.has(e.commitId)) {
4399
- if (e.previous) sink.text(`previous ${e.previous.commitId} ${quotePath(e.previous.path, quote)}\n`);
4400
- sink.text(`filename ${quotePath(e.sourcePath, quote)}\n`);
4401
- }
4402
- };
4403
- for (const e of result.entries) {
4404
- sink.text(`${e.commitId} ${e.sourceStart} ${e.resultStart} ${e.lineCount}\n`);
4405
- details(e, repeat);
4406
- let last;
4407
- for (let cnt = 0; cnt < e.lineCount; cnt++) {
4408
- if (cnt) {
4409
- sink.text(`${e.commitId} ${e.sourceStart + cnt} ${e.resultStart + cnt}\n`);
4410
- if (repeat) details(e, true);
4411
- }
4412
- last = lines[e.resultStart - 1 + cnt] ?? /* @__PURE__ */ new Uint8Array(0);
4413
- sink.text(" ");
4414
- sink.push(last);
4415
- }
4416
- if (last && last.length > 0 && last[last.length - 1] !== 10) sink.text("\n");
4417
- }
4418
- return sink.bytes();
4419
- }
4420
- /** git's default `blame` output */
4421
- function formatBlame(result, options = {}) {
4422
- const lines = fileLines(result.content ?? /* @__PURE__ */ new Uint8Array(0));
4423
- const entries = result.entries;
4424
- let showName = options.showName ?? false;
4425
- let longestFile = 0;
4426
- let longestAuthor = 0;
4427
- let longestSrc = 0;
4428
- let longestDst = 0;
4429
- let maxMarks = 0;
4430
- const seen = /* @__PURE__ */ new Set();
4431
- const authorOf = (e) => options.showEmail ? `<${e.commit.author.email}>` : e.commit.author.name;
4432
- for (const e of entries) {
4433
- const marks = e.boundary && !options.blankBoundary ? 1 : 0;
4434
- if (maxMarks < marks) maxMarks = marks;
4435
- if (e.sourcePath !== result.path) showName = true;
4436
- const len = encodeGitPath(e.sourcePath).length;
4437
- if (longestFile < len) longestFile = len;
4438
- if (!seen.has(e.commitId)) {
4439
- seen.add(e.commitId);
4440
- const w = displayWidth(authorOf(e));
4441
- if (longestAuthor < w) longestAuthor = w;
4442
- }
4443
- longestSrc = Math.max(longestSrc, e.sourceStart - 1 + e.lineCount);
4444
- longestDst = Math.max(longestDst, e.resultStart - 1 + e.lineCount);
4445
- }
4446
- const maxOrigDigits = String(longestSrc).length;
4447
- const maxDigits = String(longestDst).length;
4448
- const auto = options.abbrev === void 0;
4449
- let abbrev = auto ? options.autoAbbrev ?? 7 : options.abbrev || 40;
4450
- if (!options.alwaysWidenAbbrev) {
4451
- if (abbrev < 40) abbrev = Math.min(40, abbrev + maxMarks);
4452
- } else if (auto || abbrev < 40) abbrev += 1;
4453
- const sink = new ByteSink();
4454
- for (const e of entries) {
4455
- const c = e.commit;
4456
- let last;
4457
- for (let cnt = 0; cnt < e.lineCount; cnt++) {
4458
- let length = options.longObjectName ? 40 : abbrev;
4459
- let hex = e.commitId;
4460
- if (e.boundary && options.blankBoundary) hex = " ".repeat(hex.length);
4461
- let line = "";
4462
- if (e.boundary && !options.blankBoundary) {
4463
- line += "^";
4464
- length--;
4465
- }
4466
- line += hex.slice(0, Math.min(length, 40));
4467
- if (showName) {
4468
- const pad = Math.max(0, longestFile - encodeGitPath(e.sourcePath).length);
4469
- line += ` ${e.sourcePath}${" ".repeat(pad)}`;
4470
- }
4471
- if (options.showNumber) line += ` ${String(e.sourceStart + cnt).padStart(maxOrigDigits)}`;
4472
- if (!options.noAuthor) {
4473
- const name = authorOf(e);
4474
- const pad = Math.max(0, longestAuthor - displayWidth(name));
4475
- const time = options.rawTimestamp ? `${c.author.timestamp} ${c.author.tzOffset}` : isoDate(c.author.timestamp, c.author.tzOffset);
4476
- line += ` (${name}${" ".repeat(pad)} ${time.padStart(10)}`;
4477
- }
4478
- line += ` ${String(e.resultStart + cnt).padStart(maxDigits)}) `;
4479
- sink.text(line);
4480
- last = lines[e.resultStart - 1 + cnt] ?? /* @__PURE__ */ new Uint8Array(0);
4481
- sink.push(last);
4482
- }
4483
- if (last && last.length > 0 && last[last.length - 1] !== 10) sink.text("\n");
4484
- }
4485
- return sink.bytes();
4486
- }
4487
- //#endregion
4488
- //#region src/results/cherry-pick-result.ts
4489
- /**
4490
- * Status of a cherry-pick operation.
4491
- *
4492
- * Based on JGit's CherryPickResult.CherryPickStatus.
4493
- */
4494
- let CherryPickStatus = /* @__PURE__ */ function(CherryPickStatus) {
4495
- /** Cherry-pick completed successfully */
4496
- CherryPickStatus["OK"] = "ok";
4497
- /** Cherry-pick failed due to conflicts */
4498
- CherryPickStatus["CONFLICTING"] = "conflicting";
4499
- /** Cherry-pick failed (preconditions not met) */
4500
- CherryPickStatus["FAILED"] = "failed";
4501
- return CherryPickStatus;
4502
- }({});
4503
- //#endregion
4504
- //#region src/results/fetch-result.ts
4505
- /**
4506
- * Status of a ref update.
4507
- *
4508
- * Based on JGit's RefUpdate.Result.
4509
- */
4510
- let RefUpdateStatus = /* @__PURE__ */ function(RefUpdateStatus) {
4511
- /** Update was performed successfully */
4512
- RefUpdateStatus["NEW"] = "new";
4513
- /** Update was a fast-forward */
4514
- RefUpdateStatus["FAST_FORWARD"] = "fast-forward";
4515
- /** Update was forced (non-fast-forward) */
4516
- RefUpdateStatus["FORCED"] = "forced";
4517
- /** No update needed (already up to date) */
4518
- RefUpdateStatus["NO_CHANGE"] = "no-change";
4519
- /** Update rejected (non-fast-forward without force) */
4520
- RefUpdateStatus["REJECTED"] = "rejected";
4521
- /** Update rejected (ref is locked) */
4522
- RefUpdateStatus["LOCK_FAILURE"] = "lock-failure";
4523
- /** Ref was deleted */
4524
- RefUpdateStatus["DELETED"] = "deleted";
4525
- /** Update renamed the ref */
4526
- RefUpdateStatus["RENAMED"] = "renamed";
4527
- return RefUpdateStatus;
4528
- }({});
4529
- /**
4530
- * Check if fetch result has any updates.
4531
- */
4532
- function hasUpdates(result) {
4533
- return result.trackingRefUpdates.some((u) => u.status !== "no-change");
4534
- }
4535
- /**
4536
- * Get successful updates from fetch result.
4537
- */
4538
- function getSuccessfulUpdates(result) {
4539
- return result.trackingRefUpdates.filter((u) => u.status === "new" || u.status === "fast-forward" || u.status === "forced");
4540
- }
4541
- //#endregion
4542
- //#region src/results/pull-result.ts
4543
- /**
4544
- * Check if pull result was successful.
4545
- */
4546
- function isPullSuccessful(result) {
4547
- return result.successful;
4548
- }
4549
- //#endregion
4550
- //#region src/results/push-result.ts
4551
- /**
4552
- * Status of a ref update during push.
4553
- *
4554
- * Based on JGit's RemoteRefUpdate.Status.
4555
- */
4556
- let PushStatus = /* @__PURE__ */ function(PushStatus) {
4557
- /** Update was performed successfully */
4558
- PushStatus["OK"] = "ok";
4559
- /** Update was rejected (not fast-forward) */
4560
- PushStatus["REJECTED_NONFASTFORWARD"] = "rejected-nonfastforward";
4561
- /** Update was rejected: the remote ref no longer has the leased value (`--force-with-lease`) */
4562
- PushStatus["REJECTED_REMOTE_CHANGED"] = "rejected-remote-changed";
4563
- /** Update was rejected (other reason) */
4564
- PushStatus["REJECTED_OTHER"] = "rejected-other";
4565
- /** Update failed (remote error) */
4566
- PushStatus["FAILED"] = "failed";
4567
- /** Update not attempted (nothing to push) */
4568
- PushStatus["NOT_ATTEMPTED"] = "not-attempted";
4569
- /** Update already up to date */
4570
- PushStatus["UP_TO_DATE"] = "up-to-date";
4571
- /** Waiting for other updates to complete (atomic push) */
4572
- PushStatus["AWAITING_REPORT"] = "awaiting-report";
4573
- return PushStatus;
4574
- }({});
4575
- /**
4576
- * Check if all updates in push result were successful.
4577
- */
4578
- function isPushSuccessful(result) {
4579
- return result.remoteUpdates.every((u) => u.status === "ok" || u.status === "up-to-date");
4580
- }
4581
- /**
4582
- * Get failed updates from push result.
4583
- */
4584
- function getFailedUpdates(result) {
4585
- return result.remoteUpdates.filter((u) => u.status !== "ok" && u.status !== "up-to-date" && u.status !== "not-attempted");
4586
- }
4587
- //#endregion
4588
- //#region src/results/rebase-result.ts
4589
- /**
4590
- * Status of a rebase operation.
4591
- *
4592
- * Based on JGit's RebaseResult.Status.
4593
- */
4594
- let RebaseStatus = /* @__PURE__ */ function(RebaseStatus) {
4595
- /**
4596
- * Rebase was successful.
4597
- */
4598
- RebaseStatus["OK"] = "ok";
4599
- /**
4600
- * Fast-forward was performed (no actual rebase needed).
4601
- */
4602
- RebaseStatus["FAST_FORWARD"] = "fast-forward";
4603
- /**
4604
- * Already up-to-date (no rebase needed).
4605
- */
4606
- RebaseStatus["UP_TO_DATE"] = "up-to-date";
4607
- /**
4608
- * Rebase stopped due to conflict.
4609
- */
4610
- RebaseStatus["STOPPED"] = "stopped";
4611
- /**
4612
- * Rebase was aborted.
4613
- */
4614
- RebaseStatus["ABORTED"] = "aborted";
4615
- /**
4616
- * Rebase was aborted due to failure (not conflict).
4617
- */
4618
- RebaseStatus["FAILED"] = "failed";
4619
- /**
4620
- * Uncommitted changes prevented rebase from starting.
4621
- */
4622
- RebaseStatus["UNCOMMITTED_CHANGES"] = "uncommitted-changes";
4623
- /**
4624
- * Interactive rebase is prepared but not started.
4625
- */
4626
- RebaseStatus["INTERACTIVE_PREPARED"] = "interactive-prepared";
4627
- /**
4628
- * Continue was called but there was nothing to commit.
4629
- */
4630
- RebaseStatus["NOTHING_TO_COMMIT"] = "nothing-to-commit";
4631
- /**
4632
- * Stash apply failed after successful rebase.
4633
- */
4634
- RebaseStatus["STASH_APPLY_CONFLICTS"] = "stash-apply-conflicts";
4635
- /**
4636
- * Rebase stopped at edit step.
4637
- */
4638
- RebaseStatus["EDIT"] = "edit";
4639
- return RebaseStatus;
4640
- }({});
4641
- /**
4642
- * Rebase todo line action.
4643
- *
4644
- * Based on JGit's RebaseTodoLine.Action.
4645
- */
4646
- let RebaseAction = /* @__PURE__ */ function(RebaseAction) {
4647
- /** Pick the commit (apply it) */
4648
- RebaseAction["PICK"] = "pick";
4649
- /** Reword: pick but edit commit message */
4650
- RebaseAction["REWORD"] = "reword";
4651
- /** Edit: stop for amending */
4652
- RebaseAction["EDIT"] = "edit";
4653
- /** Squash into previous commit (combine messages) */
4654
- RebaseAction["SQUASH"] = "squash";
4655
- /** Fixup: squash but discard this commit's message */
4656
- RebaseAction["FIXUP"] = "fixup";
4657
- /** Comment line (ignored) */
4658
- RebaseAction["COMMENT"] = "comment";
4659
- /** `label <name>`: `refs/rewritten/<name>` set to HEAD (`--rebase-merges`) */
4660
- RebaseAction["LABEL"] = "label";
4661
- /** `reset <label>`: HEAD and the worktree moved to a label (`--rebase-merges`) */
4662
- RebaseAction["RESET"] = "reset";
4663
- /** `merge [-C <commit> | -c <commit>] <label> [# <oneline>]` (`--rebase-merges`) */
4664
- RebaseAction["MERGE"] = "merge";
4665
- /** `exec <command>`: the command run by the exec handler (git runs it in a shell) */
4666
- RebaseAction["EXEC"] = "exec";
4667
- /** `break`: the rebase stops here (`git rebase --continue` goes on) */
4668
- RebaseAction["BREAK"] = "break";
4669
- /** `drop <commit>`: the commit left out */
4670
- RebaseAction["DROP"] = "drop";
4671
- /** `noop`: nothing (the list of a rebase with nothing to pick) */
4672
- RebaseAction["NOOP"] = "noop";
4673
- /** `update-ref <ref>`: the ref moved to HEAD at the end of the rebase (`--update-refs`) */
4674
- RebaseAction["UPDATE_REF"] = "update-ref";
4675
- return RebaseAction;
4676
- }({});
4677
- /**
4678
- * Check if rebase status indicates success.
4679
- */
4680
- function isRebaseSuccessful(status) {
4681
- return status === "ok" || status === "fast-forward" || status === "up-to-date";
4682
- }
4683
- //#endregion
4684
- //#region src/results/revert-result.ts
4685
- /**
4686
- * Status of a revert operation.
4687
- *
4688
- * Based on JGit's RevertCommand result patterns.
4689
- */
4690
- let RevertStatus = /* @__PURE__ */ function(RevertStatus) {
4691
- /** Revert completed successfully */
4692
- RevertStatus["OK"] = "ok";
4693
- /** Revert resulted in conflicts */
4694
- RevertStatus["CONFLICTING"] = "conflicting";
4695
- /** Revert failed due to dirty working tree or other issues */
4696
- RevertStatus["FAILED"] = "failed";
4697
- return RevertStatus;
4698
- }({});
4699
- //#endregion
4700
- export { formatNoIndexDiff as $, ChangeType as A, quotePath as At, GIT_DIFF_BIG_FILE_THRESHOLD as B, wsBlankLine as Bt, StashApplyStatus as C, parseColorMoved as Ct, parseOrderFile as D, wsErrorHighlightOf as Dt, orderRank as E, writeColoredHunks as Et, createRenameEntry as F, WhitespaceRuleError as Ft, computeDiffstat as G, attrPathOf as H, wsFixCopy as Ht, DEFAULT_CONFLICT_MARKER_SIZE as I, isGitSpace as It, diffDriverOf as J, contentDriver as K, conflictMarkerSizeOf as L, parseWhitespaceRule as Lt, createCopyEntry as M, WS_BLANK_AT_EOF as Mt, createDeleteEntry as N, WS_DEFAULT_RULE as Nt, DiffFormatter as O, writeCombinedDiff as Ot, createModifyEntry as P, WS_INCOMPLETE_LINE as Pt, formatNameStatus as Q, isConflictMarkerLine as R, whitespaceErrorString as Rt, isMergeSuccessful as S, diffColorSlotOf as St, orderByPatterns as T, parseWsErrorHighlight as Tt, blobIdOf as U, LoadedSide as V, wsCheck as Vt, blobSide as W, driverOf as X, displayWidth as Y, formatNameOnly as Z, submoduleToken as _, MovedLineBuffer as _t, PushStatus as a, noIndexPair as at, MergeStatus as b, WSEH_OLD as bt, isPullSuccessful as c, utf8 as ct, hasUpdates as d, compileWordRegex as dt, formatNumstat as et, CherryPickStatus as f, writeWordDiffHunks as ft, formatStatusPorcelain as g, DIFF_COLOR_SLOTS as gt, StatusImpl as h, DEFAULT_DIFF_COLORS as ht, isRebaseSuccessful as i, formatSummary as it, createAddEntry as j, quoteTwo as jt, diffEntryToPair as k, quoteCStyleBody as kt, RefUpdateStatus as l, writePairPatch as lt, formatBlamePorcelain as m, COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE as mt, RebaseAction as n, formatShortstat as nt, getFailedUpdates as o, pprintRename as ot, formatBlame as p, COLOR_MOVED_MODE_ERROR as pt, contentSide as q, RebaseStatus as r, formatStat as rt, isPushSuccessful as s, statSummary as st, RevertStatus as t, formatPatch as tt, getSuccessfulUpdates as u, WORD_DIFF_MODES as ut, ContentMergeStrategy as v, WSEH_CONTEXT as vt, DiffPickaxe as w, parseColorMovedWs as wt, MergeStrategy as x, coloredHunkHeader as xt, FastForwardMode as y, WSEH_NEW as yt, writePairCheck as z, whitespaceRuleOf as zt };