@statewalker/vcs-commands 0.6.0 → 0.8.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 (481) hide show
  1. package/dist/commands/add-command.d.ts +38 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/am/am-command.d.ts +55 -1
  4. package/dist/commands/am/am-command.d.ts.map +1 -1
  5. package/dist/commands/am/index.d.ts +1 -0
  6. package/dist/commands/am/index.d.ts.map +1 -1
  7. package/dist/commands/am/mailsplit.d.ts +88 -0
  8. package/dist/commands/am/mailsplit.d.ts.map +1 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-engine.d.ts.map +1 -1
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/bisect/bisect-command.d.ts +2 -0
  13. package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
  14. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -1
  15. package/dist/commands/branch-command.d.ts +148 -18
  16. package/dist/commands/branch-command.d.ts.map +1 -1
  17. package/dist/commands/branch-info-command.d.ts +55 -0
  18. package/dist/commands/branch-info-command.d.ts.map +1 -0
  19. package/dist/commands/branch-tracking.d.ts +106 -17
  20. package/dist/commands/branch-tracking.d.ts.map +1 -1
  21. package/dist/commands/branch-upstream-command.d.ts +83 -0
  22. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  23. package/dist/commands/checkout-command.d.ts +19 -3
  24. package/dist/commands/checkout-command.d.ts.map +1 -1
  25. package/dist/commands/cherry-pick-command.d.ts +59 -0
  26. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  27. package/dist/commands/clean-command.d.ts +12 -0
  28. package/dist/commands/clean-command.d.ts.map +1 -1
  29. package/dist/commands/clone-command.d.ts +17 -0
  30. package/dist/commands/clone-command.d.ts.map +1 -1
  31. package/dist/commands/comment-char-config.d.ts +35 -0
  32. package/dist/commands/comment-char-config.d.ts.map +1 -0
  33. package/dist/commands/commit-command.d.ts +191 -5
  34. package/dist/commands/commit-command.d.ts.map +1 -1
  35. package/dist/commands/commit-reuse.d.ts +33 -0
  36. package/dist/commands/commit-reuse.d.ts.map +1 -0
  37. package/dist/commands/config-command.d.ts +236 -0
  38. package/dist/commands/config-command.d.ts.map +1 -0
  39. package/dist/commands/config-value-types.d.ts +91 -0
  40. package/dist/commands/config-value-types.d.ts.map +1 -0
  41. package/dist/commands/core-config.d.ts +20 -0
  42. package/dist/commands/core-config.d.ts.map +1 -1
  43. package/dist/commands/default-branch.d.ts +70 -0
  44. package/dist/commands/default-branch.d.ts.map +1 -0
  45. package/dist/commands/diff-color-config.d.ts +73 -0
  46. package/dist/commands/diff-color-config.d.ts.map +1 -0
  47. package/dist/commands/diff-command.d.ts +252 -5
  48. package/dist/commands/diff-command.d.ts.map +1 -1
  49. package/dist/commands/fetch-command.d.ts +20 -0
  50. package/dist/commands/fetch-command.d.ts.map +1 -1
  51. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  52. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  53. package/dist/commands/fork-point.d.ts +38 -0
  54. package/dist/commands/fork-point.d.ts.map +1 -0
  55. package/dist/commands/format-patch-command.d.ts +41 -1
  56. package/dist/commands/format-patch-command.d.ts.map +1 -1
  57. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  58. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  59. package/dist/commands/fsck/fsck-command.d.ts +2 -0
  60. package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
  61. package/dist/commands/fsck/fsck-loose.d.ts +3 -0
  62. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -1
  63. package/dist/commands/fsck/fsck-object-checks.d.ts +25 -14
  64. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
  65. package/dist/commands/fsck/fsck-object-table.d.ts +15 -7
  66. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -1
  67. package/dist/commands/fsck/fsck-pack.d.ts +11 -4
  68. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -1
  69. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -1
  70. package/dist/commands/gc-command.d.ts +80 -48
  71. package/dist/commands/gc-command.d.ts.map +1 -1
  72. package/dist/commands/git-date.d.ts +1 -65
  73. package/dist/commands/git-date.d.ts.map +1 -1
  74. package/dist/commands/git-describe.d.ts +4 -0
  75. package/dist/commands/git-describe.d.ts.map +1 -1
  76. package/dist/commands/git-hooks.d.ts +43 -0
  77. package/dist/commands/git-hooks.d.ts.map +1 -1
  78. package/dist/commands/grep/grep-command.d.ts +210 -0
  79. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  80. package/dist/commands/grep/grep-engine.d.ts +218 -0
  81. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  82. package/dist/commands/grep/index.d.ts +3 -0
  83. package/dist/commands/grep/index.d.ts.map +1 -0
  84. package/dist/commands/index-adder.d.ts +15 -2
  85. package/dist/commands/index-adder.d.ts.map +1 -1
  86. package/dist/commands/index.d.ts +28 -0
  87. package/dist/commands/index.d.ts.map +1 -1
  88. package/dist/commands/index.js +3 -3
  89. package/dist/commands/init-command.d.ts +50 -3
  90. package/dist/commands/init-command.d.ts.map +1 -1
  91. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  92. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  93. package/dist/commands/legacy-remotes.d.ts +55 -0
  94. package/dist/commands/legacy-remotes.d.ts.map +1 -0
  95. package/dist/commands/local-transport.d.ts +36 -5
  96. package/dist/commands/local-transport.d.ts.map +1 -1
  97. package/dist/commands/log-command.d.ts +296 -11
  98. package/dist/commands/log-command.d.ts.map +1 -1
  99. package/dist/commands/log-graph.d.ts +26 -1
  100. package/dist/commands/log-graph.d.ts.map +1 -1
  101. package/dist/commands/log-output.d.ts +133 -5
  102. package/dist/commands/log-output.d.ts.map +1 -1
  103. package/dist/commands/ls-remote-command.d.ts +2 -0
  104. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  105. package/dist/commands/mailmap.d.ts +30 -0
  106. package/dist/commands/mailmap.d.ts.map +1 -1
  107. package/dist/commands/merge-base-command.d.ts +60 -0
  108. package/dist/commands/merge-base-command.d.ts.map +1 -0
  109. package/dist/commands/merge-bases.d.ts +23 -0
  110. package/dist/commands/merge-bases.d.ts.map +1 -1
  111. package/dist/commands/merge-command.d.ts +108 -9
  112. package/dist/commands/merge-command.d.ts.map +1 -1
  113. package/dist/commands/merge-support.d.ts +11 -3
  114. package/dist/commands/merge-support.d.ts.map +1 -1
  115. package/dist/commands/mv-command.d.ts +4 -0
  116. package/dist/commands/mv-command.d.ts.map +1 -1
  117. package/dist/commands/name-rev.d.ts +48 -0
  118. package/dist/commands/name-rev.d.ts.map +1 -0
  119. package/dist/commands/notes-command.d.ts.map +1 -1
  120. package/dist/commands/notes-merge-command.d.ts.map +1 -1
  121. package/dist/commands/notes-tree.d.ts +11 -1
  122. package/dist/commands/notes-tree.d.ts.map +1 -1
  123. package/dist/commands/patch-id.d.ts +3 -0
  124. package/dist/commands/patch-id.d.ts.map +1 -1
  125. package/dist/commands/pathspec-file.d.ts +39 -0
  126. package/dist/commands/pathspec-file.d.ts.map +1 -0
  127. package/dist/commands/pathspec.d.ts +3 -0
  128. package/dist/commands/pathspec.d.ts.map +1 -1
  129. package/dist/commands/pretty-format.d.ts +43 -3
  130. package/dist/commands/pretty-format.d.ts.map +1 -1
  131. package/dist/commands/promisor-remote.d.ts.map +1 -1
  132. package/dist/commands/pull-command.d.ts +28 -0
  133. package/dist/commands/pull-command.d.ts.map +1 -1
  134. package/dist/commands/push-command.d.ts +160 -9
  135. package/dist/commands/push-command.d.ts.map +1 -1
  136. package/dist/commands/read-tree-command.d.ts +6 -0
  137. package/dist/commands/read-tree-command.d.ts.map +1 -1
  138. package/dist/commands/rebase-command.d.ts +168 -6
  139. package/dist/commands/rebase-command.d.ts.map +1 -1
  140. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  141. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  142. package/dist/commands/ref-filter/index.d.ts +8 -0
  143. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  144. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  145. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  146. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  147. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  148. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  149. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  150. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  151. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  152. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  153. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  154. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  155. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  156. package/dist/commands/reflog-command.d.ts +120 -0
  157. package/dist/commands/reflog-command.d.ts.map +1 -1
  158. package/dist/commands/reflog-walk.d.ts +72 -0
  159. package/dist/commands/reflog-walk.d.ts.map +1 -0
  160. package/dist/commands/remote-command.d.ts +138 -29
  161. package/dist/commands/remote-command.d.ts.map +1 -1
  162. package/dist/commands/remote-transport.d.ts +7 -1
  163. package/dist/commands/remote-transport.d.ts.map +1 -1
  164. package/dist/commands/reset-command.d.ts +2 -3
  165. package/dist/commands/reset-command.d.ts.map +1 -1
  166. package/dist/commands/restore-command.d.ts +2 -3
  167. package/dist/commands/restore-command.d.ts.map +1 -1
  168. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  169. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  170. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  171. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  172. package/dist/commands/rev-filter/index.d.ts +3 -0
  173. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  174. package/dist/commands/rev-list-command.d.ts +154 -2
  175. package/dist/commands/rev-list-command.d.ts.map +1 -1
  176. package/dist/commands/rev-parse-command.d.ts +9 -0
  177. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  178. package/dist/commands/revert-command.d.ts +32 -0
  179. package/dist/commands/revert-command.d.ts.map +1 -1
  180. package/dist/commands/revision-range.d.ts +32 -1
  181. package/dist/commands/revision-range.d.ts.map +1 -1
  182. package/dist/commands/revision-resolver.d.ts +21 -2
  183. package/dist/commands/revision-resolver.d.ts.map +1 -1
  184. package/dist/commands/rm-command.d.ts +70 -2
  185. package/dist/commands/rm-command.d.ts.map +1 -1
  186. package/dist/commands/sequencer-pick.d.ts +85 -5
  187. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  188. package/dist/commands/sequencer-support.d.ts +2 -0
  189. package/dist/commands/sequencer-support.d.ts.map +1 -1
  190. package/dist/commands/serve-repository.d.ts +7 -0
  191. package/dist/commands/serve-repository.d.ts.map +1 -1
  192. package/dist/commands/show-command.d.ts +130 -0
  193. package/dist/commands/show-command.d.ts.map +1 -0
  194. package/dist/commands/show-commit.d.ts +11 -0
  195. package/dist/commands/show-commit.d.ts.map +1 -0
  196. package/dist/commands/signature-check.d.ts +164 -0
  197. package/dist/commands/signature-check.d.ts.map +1 -0
  198. package/dist/commands/signing.d.ts +160 -0
  199. package/dist/commands/signing.d.ts.map +1 -0
  200. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  201. package/dist/commands/sparse-index-view.d.ts +45 -0
  202. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  203. package/dist/commands/ssh-signer.d.ts +29 -0
  204. package/dist/commands/ssh-signer.d.ts.map +1 -0
  205. package/dist/commands/ssh-verifier.d.ts +42 -0
  206. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  207. package/dist/commands/stash-apply-command.d.ts +5 -0
  208. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  209. package/dist/commands/stash-branch-command.d.ts +34 -0
  210. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  211. package/dist/commands/stash-create-command.d.ts +18 -1
  212. package/dist/commands/stash-create-command.d.ts.map +1 -1
  213. package/dist/commands/stash-info.d.ts +93 -0
  214. package/dist/commands/stash-info.d.ts.map +1 -0
  215. package/dist/commands/stash-list-command.d.ts +16 -0
  216. package/dist/commands/stash-list-command.d.ts.map +1 -1
  217. package/dist/commands/stash-pop-command.d.ts +39 -0
  218. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  219. package/dist/commands/stash-show-command.d.ts +48 -0
  220. package/dist/commands/stash-show-command.d.ts.map +1 -0
  221. package/dist/commands/stash-store-command.d.ts +29 -0
  222. package/dist/commands/stash-store-command.d.ts.map +1 -0
  223. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  224. package/dist/commands/status-command.d.ts.map +1 -1
  225. package/dist/commands/status-header.d.ts +5 -0
  226. package/dist/commands/status-header.d.ts.map +1 -1
  227. package/dist/commands/submodule-add-command.d.ts +89 -0
  228. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  229. package/dist/commands/submodule-auth.d.ts +90 -0
  230. package/dist/commands/submodule-auth.d.ts.map +1 -0
  231. package/dist/commands/submodule-commands.d.ts +375 -0
  232. package/dist/commands/submodule-commands.d.ts.map +1 -0
  233. package/dist/commands/submodule-model.d.ts +288 -0
  234. package/dist/commands/submodule-model.d.ts.map +1 -0
  235. package/dist/commands/submodule-summary-command.d.ts.map +1 -1
  236. package/dist/commands/submodule-update-command.d.ts +198 -0
  237. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  238. package/dist/commands/switch-command.d.ts.map +1 -1
  239. package/dist/commands/tag-command.d.ts +259 -10
  240. package/dist/commands/tag-command.d.ts.map +1 -1
  241. package/dist/commands/trailers.d.ts +218 -17
  242. package/dist/commands/trailers.d.ts.map +1 -1
  243. package/dist/commands/tree-restore.d.ts +7 -0
  244. package/dist/commands/tree-restore.d.ts.map +1 -1
  245. package/dist/commands/untracked-cache-support.d.ts +2 -1
  246. package/dist/commands/untracked-cache-support.d.ts.map +1 -1
  247. package/dist/commands/verify-command.d.ts +92 -0
  248. package/dist/commands/verify-command.d.ts.map +1 -0
  249. package/dist/commands/worktree-add-command.d.ts +79 -7
  250. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  251. package/dist/commands/worktree-list-command.d.ts.map +1 -1
  252. package/dist/commands/worktree-path-rules.d.ts +66 -0
  253. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  254. package/dist/commands/worktree-remove-command.d.ts +10 -3
  255. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  256. package/dist/commands/worktree-repair-command.d.ts +15 -2
  257. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  258. package/dist/commands/worktree-support.d.ts +5 -0
  259. package/dist/commands/worktree-support.d.ts.map +1 -1
  260. package/dist/{commands-DnmlfwGV.js → commands-ISM52N0n.js} +66120 -49271
  261. package/dist/errors/checkout-errors.d.ts +19 -0
  262. package/dist/errors/checkout-errors.d.ts.map +1 -1
  263. package/dist/errors/command-errors.d.ts.map +1 -1
  264. package/dist/errors/index.js +57 -3
  265. package/dist/errors/ref-errors.d.ts +19 -0
  266. package/dist/errors/ref-errors.d.ts.map +1 -1
  267. package/dist/errors/worktree-errors.d.ts +6 -1
  268. package/dist/errors/worktree-errors.d.ts.map +1 -1
  269. package/dist/{git-command-DxvwPrPB.js → fsck-DLRpbwTj.js} +6863 -1070
  270. package/dist/git-command.d.ts +43 -2
  271. package/dist/git-command.d.ts.map +1 -1
  272. package/dist/git.d.ts +276 -3
  273. package/dist/git.d.ts.map +1 -1
  274. package/dist/index.js +5 -5
  275. package/dist/remote-config/index.d.ts +1 -1
  276. package/dist/remote-config/index.d.ts.map +1 -1
  277. package/dist/remote-config/remote-config-store.d.ts +117 -3
  278. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  279. package/dist/rename/detect-renames.d.ts.map +1 -1
  280. package/dist/results/clone-result.d.ts +8 -0
  281. package/dist/results/clone-result.d.ts.map +1 -1
  282. package/dist/results/combined-diff.d.ts +3 -0
  283. package/dist/results/combined-diff.d.ts.map +1 -1
  284. package/dist/results/diff-check.d.ts +38 -0
  285. package/dist/results/diff-check.d.ts.map +1 -0
  286. package/dist/results/diff-color.d.ts +135 -0
  287. package/dist/results/diff-color.d.ts.map +1 -0
  288. package/dist/results/diff-output.d.ts +85 -1
  289. package/dist/results/diff-output.d.ts.map +1 -1
  290. package/dist/results/diff-pickaxe.d.ts +67 -0
  291. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  292. package/dist/results/diff-words.d.ts +55 -0
  293. package/dist/results/diff-words.d.ts.map +1 -0
  294. package/dist/results/index.d.ts +4 -0
  295. package/dist/results/index.d.ts.map +1 -1
  296. package/dist/results/index.js +2 -2
  297. package/dist/results/init-result.d.ts +7 -0
  298. package/dist/results/init-result.d.ts.map +1 -1
  299. package/dist/results/pull-result.d.ts +5 -0
  300. package/dist/results/pull-result.d.ts.map +1 -1
  301. package/dist/results/push-result.d.ts +12 -0
  302. package/dist/results/push-result.d.ts.map +1 -1
  303. package/dist/results/rebase-result.d.ts +2 -0
  304. package/dist/results/rebase-result.d.ts.map +1 -1
  305. package/dist/results/stash-result.d.ts +6 -0
  306. package/dist/results/stash-result.d.ts.map +1 -1
  307. package/dist/results/status-result.d.ts.map +1 -1
  308. package/dist/{results-BZGa2Z3I.js → results-TB2IJ64h.js} +2178 -412
  309. package/dist/whitespace/index.d.ts +2 -0
  310. package/dist/whitespace/index.d.ts.map +1 -0
  311. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  312. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  313. package/package.json +12 -12
  314. package/src/commands/add-command.ts +178 -17
  315. package/src/commands/add-patch/add-interactive.ts +3 -3
  316. package/src/commands/am/am-command.ts +263 -43
  317. package/src/commands/am/index.ts +1 -0
  318. package/src/commands/am/mailsplit.ts +326 -0
  319. package/src/commands/apply/apply-command.ts +18 -8
  320. package/src/commands/apply/apply-engine.ts +6 -7
  321. package/src/commands/apply/apply-parse.ts +10 -10
  322. package/src/commands/attributes-source.ts +1 -1
  323. package/src/commands/bisect/bisect-command.ts +18 -5
  324. package/src/commands/bisect/bisect-engine.ts +2 -1
  325. package/src/commands/branch-command.ts +528 -53
  326. package/src/commands/branch-info-command.ts +150 -0
  327. package/src/commands/branch-tracking.ts +335 -60
  328. package/src/commands/branch-upstream-command.ts +218 -0
  329. package/src/commands/checkout-command.ts +70 -44
  330. package/src/commands/cherry-pick-command.ts +143 -0
  331. package/src/commands/clean-command.ts +34 -3
  332. package/src/commands/clone-command.ts +118 -5
  333. package/src/commands/comment-char-config.ts +160 -0
  334. package/src/commands/commit-command.ts +790 -71
  335. package/src/commands/commit-reuse.ts +94 -0
  336. package/src/commands/config-command.ts +1256 -0
  337. package/src/commands/config-value-types.ts +358 -0
  338. package/src/commands/core-config.ts +47 -2
  339. package/src/commands/default-branch.ts +196 -0
  340. package/src/commands/diff-color-config.ts +274 -0
  341. package/src/commands/diff-command.ts +1053 -75
  342. package/src/commands/fetch-command.ts +161 -13
  343. package/src/commands/fmt-merge-msg-command.ts +715 -0
  344. package/src/commands/fork-point.ts +63 -0
  345. package/src/commands/format-patch-command.ts +316 -43
  346. package/src/commands/fsck/fetch-fsck.ts +172 -18
  347. package/src/commands/fsck/fsck-command.ts +183 -66
  348. package/src/commands/fsck/fsck-loose.ts +14 -4
  349. package/src/commands/fsck/fsck-object-checks.ts +87 -46
  350. package/src/commands/fsck/fsck-object-table.ts +52 -42
  351. package/src/commands/fsck/fsck-pack.ts +64 -34
  352. package/src/commands/fsck/verify-pack-command.ts +5 -2
  353. package/src/commands/gc-command.ts +238 -107
  354. package/src/commands/git-date.ts +9 -895
  355. package/src/commands/git-describe.ts +31 -11
  356. package/src/commands/git-hooks.ts +92 -0
  357. package/src/commands/grep/grep-command.ts +1077 -0
  358. package/src/commands/grep/grep-engine.ts +1024 -0
  359. package/src/commands/grep/index.ts +2 -0
  360. package/src/commands/index-adder.ts +54 -10
  361. package/src/commands/index.ts +28 -0
  362. package/src/commands/init-command.ts +167 -11
  363. package/src/commands/interpret-trailers-command.ts +256 -0
  364. package/src/commands/legacy-remotes.ts +224 -0
  365. package/src/commands/local-transport.ts +109 -10
  366. package/src/commands/log-command.ts +1283 -232
  367. package/src/commands/log-graph.ts +123 -26
  368. package/src/commands/log-output.ts +280 -21
  369. package/src/commands/ls-remote-command.ts +9 -0
  370. package/src/commands/mailmap.ts +119 -0
  371. package/src/commands/merge-base-command.ts +170 -0
  372. package/src/commands/merge-bases.ts +63 -8
  373. package/src/commands/merge-command.ts +360 -82
  374. package/src/commands/merge-support.ts +43 -9
  375. package/src/commands/mv-command.ts +6 -3
  376. package/src/commands/name-rev.ts +171 -0
  377. package/src/commands/notes-command.ts +11 -1
  378. package/src/commands/notes-merge-command.ts +23 -14
  379. package/src/commands/notes-tree.ts +28 -13
  380. package/src/commands/octopus-merge.ts +3 -2
  381. package/src/commands/patch-id.ts +16 -8
  382. package/src/commands/pathspec-file.ts +72 -0
  383. package/src/commands/pathspec.ts +14 -2
  384. package/src/commands/pretty-format.ts +105 -20
  385. package/src/commands/promisor-remote.ts +10 -1
  386. package/src/commands/pull-command.ts +149 -22
  387. package/src/commands/push-command.ts +704 -72
  388. package/src/commands/read-tree-command.ts +34 -3
  389. package/src/commands/rebase-command.ts +957 -142
  390. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  391. package/src/commands/ref-filter/index.ts +7 -0
  392. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  393. package/src/commands/ref-filter/ref-filter.ts +651 -0
  394. package/src/commands/ref-filter/ref-format.ts +1070 -0
  395. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  396. package/src/commands/ref-filter/ref-quote.ts +69 -0
  397. package/src/commands/ref-filter/version-compare.ts +177 -0
  398. package/src/commands/reflog-command.ts +492 -2
  399. package/src/commands/reflog-walk.ts +234 -0
  400. package/src/commands/remote-command.ts +484 -74
  401. package/src/commands/remote-transport.ts +9 -1
  402. package/src/commands/reset-command.ts +40 -42
  403. package/src/commands/restore-command.ts +12 -41
  404. package/src/commands/rev-filter/commit-filter.ts +159 -0
  405. package/src/commands/rev-filter/commit-grep.ts +444 -0
  406. package/src/commands/rev-filter/index.ts +2 -0
  407. package/src/commands/rev-list-command.ts +402 -15
  408. package/src/commands/rev-parse-command.ts +22 -0
  409. package/src/commands/revert-command.ts +82 -0
  410. package/src/commands/revision-range.ts +204 -4
  411. package/src/commands/revision-resolver.ts +55 -22
  412. package/src/commands/rm-command.ts +282 -21
  413. package/src/commands/sequencer-pick.ts +504 -86
  414. package/src/commands/sequencer-support.ts +30 -5
  415. package/src/commands/serve-repository.ts +18 -3
  416. package/src/commands/show-command.ts +490 -0
  417. package/src/commands/show-commit.ts +24 -0
  418. package/src/commands/signature-check.ts +657 -0
  419. package/src/commands/signing.ts +385 -0
  420. package/src/commands/sparse-checkout-command.ts +2 -9
  421. package/src/commands/sparse-checkout-support.ts +2 -2
  422. package/src/commands/sparse-index-view.ts +135 -0
  423. package/src/commands/ssh-signer.ts +199 -0
  424. package/src/commands/ssh-verifier.ts +523 -0
  425. package/src/commands/stash-apply-command.ts +17 -5
  426. package/src/commands/stash-branch-command.ts +88 -0
  427. package/src/commands/stash-create-command.ts +30 -2
  428. package/src/commands/stash-info.ts +243 -0
  429. package/src/commands/stash-list-command.ts +33 -0
  430. package/src/commands/stash-pop-command.ts +83 -0
  431. package/src/commands/stash-show-command.ts +141 -0
  432. package/src/commands/stash-store-command.ts +82 -0
  433. package/src/commands/stash-working-tree.ts +2 -2
  434. package/src/commands/status-command.ts +7 -6
  435. package/src/commands/status-header.ts +44 -8
  436. package/src/commands/submodule-add-command.ts +509 -0
  437. package/src/commands/submodule-auth.ts +276 -0
  438. package/src/commands/submodule-commands.ts +1517 -0
  439. package/src/commands/submodule-model.ts +930 -0
  440. package/src/commands/submodule-summary-command.ts +6 -7
  441. package/src/commands/submodule-update-command.ts +1092 -0
  442. package/src/commands/switch-command.ts +3 -1
  443. package/src/commands/tag-command.ts +876 -64
  444. package/src/commands/trailers.ts +837 -100
  445. package/src/commands/tree-restore.ts +38 -10
  446. package/src/commands/untracked-cache-support.ts +16 -12
  447. package/src/commands/verify-command.ts +235 -0
  448. package/src/commands/worktree-add-command.ts +268 -24
  449. package/src/commands/worktree-list-command.ts +3 -5
  450. package/src/commands/worktree-path-rules.ts +183 -0
  451. package/src/commands/worktree-remove-command.ts +39 -5
  452. package/src/commands/worktree-repair-command.ts +52 -5
  453. package/src/commands/worktree-support.ts +22 -1
  454. package/src/core-commands/add.command.impl.ts +1 -1
  455. package/src/errors/checkout-errors.ts +29 -0
  456. package/src/errors/command-errors.ts +2 -1
  457. package/src/errors/ref-errors.ts +23 -0
  458. package/src/errors/worktree-errors.ts +8 -1
  459. package/src/git-command.ts +98 -3
  460. package/src/git.ts +420 -4
  461. package/src/remote-config/index.ts +4 -0
  462. package/src/remote-config/remote-config-store.ts +238 -11
  463. package/src/rename/detect-renames.ts +5 -1
  464. package/src/results/clone-result.ts +9 -0
  465. package/src/results/combined-diff.ts +38 -18
  466. package/src/results/diff-check.ts +185 -0
  467. package/src/results/diff-color.ts +868 -0
  468. package/src/results/diff-output.ts +204 -37
  469. package/src/results/diff-pickaxe.ts +304 -0
  470. package/src/results/diff-words.ts +395 -0
  471. package/src/results/index.ts +4 -0
  472. package/src/results/init-result.ts +9 -0
  473. package/src/results/pull-result.ts +5 -0
  474. package/src/results/push-result.ts +12 -0
  475. package/src/results/rebase-result.ts +3 -0
  476. package/src/results/stash-result.ts +7 -0
  477. package/src/results/status-result.ts +5 -2
  478. package/src/whitespace/index.ts +1 -0
  479. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  480. package/dist/commands/apply/whitespace.d.ts +0 -58
  481. package/dist/commands/apply/whitespace.d.ts.map +0 -1
@@ -0,0 +1,1024 @@
1
+ /**
2
+ * git's grep matcher and printer (`grep.c`): the patterns compiled as `compile_grep_patterns`
3
+ * compiles them, each line of a source matched as `grep_source_1` matches it, and the output
4
+ * written as `show_line`, `show_pre_context` and `show_funcname_line` write it.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const engine = new GrepEngine([grepPattern("foo")], { lineNumber: true });
9
+ * engine.grepSource({ name: encode("file"), content: encode("a foo\nb\n") });
10
+ * new TextDecoder().decode(engine.output()); // "file:1:a foo\n"
11
+ * ```
12
+ *
13
+ * What git does, kept here:
14
+ * - A pattern with newlines is one pattern per line. Patterns are basic POSIX regexes by
15
+ * default (`extended`, `fixed`, `perl`), compiled with `REG_NEWLINE`, `-i` as `REG_ICASE`;
16
+ * one without a regex character (`$()*+.?[\^{|`) is a literal, as with `-F`. A pattern
17
+ * holding a NUL byte dies unless it is `-P`. `-P` is a git built without PCRE: a literal
18
+ * `-P` pattern matches, any other dies.
19
+ * - `-w` takes a match only between non-word characters (or the line's ends), and retries
20
+ * from after the next non-word character as `headerless_match_one_pattern` does.
21
+ * - `--and`, `--not`, `(`, `)` (and `--all-match`) build git's expression tree; `--or` is the
22
+ * default between patterns. `--column` evaluates every branch, a `--not` swapping the
23
+ * column of a match and of an inverted one.
24
+ * - Context (`-A`, `-B`), function lines (`-p`) and function bodies (`-W`) through the
25
+ * source's funcname pattern, or git's default (a line starting with a letter, `_` or `$`).
26
+ * - Several sources print as git's threaded grep prints them (its default): each source's
27
+ * output starts with a hunk mark (`--`, or an empty line with `--break`), and the first line
28
+ * of the first output is dropped. {@link GrepEngineOptions.threads} `1` prints as git's
29
+ * single-threaded grep (`--threads=1`).
30
+ *
31
+ * @module
32
+ */
33
+
34
+ import { compilePosixRegex, PosixRegexError } from "@statewalker/vcs-utils";
35
+ import type { FindFunction } from "@statewalker/vcs-utils/diff";
36
+
37
+ import { GitApiError } from "../../errors/index.js";
38
+ import { GrepPatternError, type GrepPatternType } from "../rev-filter/index.js";
39
+
40
+ /** One element of git's pattern list: a pattern or an expression operator. */
41
+ export type GrepToken =
42
+ | {
43
+ kind: "pattern";
44
+ /** The pattern's bytes */
45
+ pattern: Uint8Array;
46
+ /** Where it came from: `-e option`, `command line`, or a `-f` file's name */
47
+ origin: string;
48
+ /** Its line in a `-f` file (1-based, empty lines not counted), else 0 */
49
+ no: number;
50
+ }
51
+ | { kind: "and" }
52
+ | { kind: "not" }
53
+ | { kind: "open" }
54
+ | { kind: "close" };
55
+
56
+ const encoder = new TextEncoder();
57
+
58
+ /** A pattern token (`-e <pattern>`), its origin `-e option` unless given. */
59
+ export function grepPattern(pattern: string | Uint8Array, origin = "-e option", no = 0): GrepToken {
60
+ return {
61
+ kind: "pattern",
62
+ pattern: typeof pattern === "string" ? encoder.encode(pattern) : pattern,
63
+ origin,
64
+ no,
65
+ };
66
+ }
67
+
68
+ /**
69
+ * The patterns of a `-f` file (builtin/grep.c `file_callback`): one per line (a CR before
70
+ * the newline dropped), empty lines skipped, each numbered by the non-empty lines before it.
71
+ */
72
+ export function grepPatternFile(content: string | Uint8Array, name: string): GrepToken[] {
73
+ const bytes = typeof content === "string" ? encoder.encode(content) : content;
74
+ const out: GrepToken[] = [];
75
+ let lno = 0;
76
+ let pos = 0;
77
+ while (pos < bytes.length) {
78
+ let end = bytes.indexOf(0x0a, pos);
79
+ const next = end < 0 ? bytes.length : end + 1;
80
+ if (end < 0) end = bytes.length;
81
+ let stop = end;
82
+ if (end < bytes.length && stop > pos && bytes[stop - 1] === 0x0d) stop--;
83
+ if (stop > pos) out.push(grepPattern(bytes.slice(pos, stop), name, ++lno));
84
+ pos = next;
85
+ }
86
+ return out;
87
+ }
88
+
89
+ /** git's die() of grep (an expression or option it refuses): exit status 128. */
90
+ export class GrepError extends GitApiError {
91
+ /** git's lines */
92
+ readonly lines: string[];
93
+
94
+ constructor(line: string) {
95
+ super(line, { exitCode: 128 });
96
+ this.name = "GrepError";
97
+ this.lines = [line];
98
+ }
99
+ }
100
+
101
+ /** The escape sequences of the colored output (`color.grep.<slot>`); "" for none. */
102
+ export interface GrepColors {
103
+ context: string;
104
+ filename: string;
105
+ function: string;
106
+ lineNumber: string;
107
+ column: string;
108
+ matchContext: string;
109
+ matchSelected: string;
110
+ selected: string;
111
+ separator: string;
112
+ }
113
+
114
+ /** git's default grep colors (`GREP_OPT_INIT`). */
115
+ export const DEFAULT_GREP_COLORS: Readonly<GrepColors> = {
116
+ context: "",
117
+ filename: "\x1b[35m",
118
+ function: "",
119
+ lineNumber: "\x1b[32m",
120
+ column: "\x1b[32m",
121
+ matchContext: "\x1b[1;31m",
122
+ matchSelected: "\x1b[1;31m",
123
+ selected: "",
124
+ separator: "\x1b[36m",
125
+ };
126
+
127
+ /** How binary sources are searched (`-a`, `-I`). */
128
+ export type GrepBinaryMode = "default" | "text" | "nomatch";
129
+
130
+ /** What the engine matches and prints (git's `struct grep_opt`). */
131
+ export interface GrepEngineOptions {
132
+ /** The pattern type (default basic) */
133
+ patternType?: GrepPatternType;
134
+ /** `-i` */
135
+ ignoreCase?: boolean;
136
+ /** `-w` */
137
+ wordRegexp?: boolean;
138
+ /** `-v` */
139
+ invert?: boolean;
140
+ /** `--all-match` */
141
+ allMatch?: boolean;
142
+ /** `-n` */
143
+ lineNumber?: boolean;
144
+ /** `--column` */
145
+ column?: boolean;
146
+ /** Names before the lines (default true; `-h` false, `-H` true) */
147
+ pathname?: boolean;
148
+ /** `-z`: names followed by NUL, unquoted */
149
+ nullFollowingName?: boolean;
150
+ /** `-o` (ignored with `-v`, as git does) */
151
+ onlyMatching?: boolean;
152
+ /** `-c` */
153
+ count?: boolean;
154
+ /** `-l` */
155
+ nameOnly?: boolean;
156
+ /** `-L` */
157
+ unmatchNameOnly?: boolean;
158
+ /** `-q` */
159
+ statusOnly?: boolean;
160
+ /** `--break` */
161
+ fileBreak?: boolean;
162
+ /** `--heading` */
163
+ heading?: boolean;
164
+ /** `-B` */
165
+ preContext?: number;
166
+ /** `-A` */
167
+ postContext?: number;
168
+ /** `-p` */
169
+ funcname?: boolean;
170
+ /** `-W` */
171
+ funcbody?: boolean;
172
+ /** `-m` (negative: no limit) */
173
+ maxCount?: number;
174
+ /** `-a` (`text`), `-I` (`nomatch`) */
175
+ binary?: GrepBinaryMode;
176
+ /** Colors, or none (undefined) */
177
+ colors?: GrepColors;
178
+ /**
179
+ * The git version whose output and messages to follow (default `2.56`): 2.43 counts `-o`
180
+ * columns after the first from the end of the previous match, keeps a trailing empty line
181
+ * in a `-W` body, and words two expression errors differently
182
+ */
183
+ compatibility?: "2.43" | "2.56";
184
+ /**
185
+ * git's worker threads: undefined or more than one prints as git's threaded grep (its
186
+ * default), 1 as `--threads=1`
187
+ */
188
+ threads?: number;
189
+ }
190
+
191
+ /** One file or blob to search. */
192
+ export interface GrepSourceInput {
193
+ /** The name printed for it (relative, quoted, `<rev>:` before it) */
194
+ name: Uint8Array;
195
+ /** Its content (textconv applied when {@link textconv}), undefined when it cannot be read */
196
+ content: Uint8Array | undefined;
197
+ /** The diff driver's verdict (`-diff`, `diff.<driver>.binary`), else the content decides */
198
+ binary?: boolean;
199
+ /** The content is a textconv's output: never binary */
200
+ textconv?: boolean;
201
+ /**
202
+ * The function lines of `-p`/`-W` (the diff driver's funcname pattern); undefined: git's
203
+ * default rule. Asked only when needed; may throw as git dies on a bad pattern.
204
+ */
205
+ findFunction?: () => FindFunction | undefined;
206
+ }
207
+
208
+ type Matcher = (
209
+ buf: Uint8Array,
210
+ bol: number,
211
+ eol: number,
212
+ notbol: boolean,
213
+ ) => [number, number] | undefined;
214
+
215
+ interface Pattern {
216
+ token: Extract<GrepToken, { kind: "pattern" }>;
217
+ exec: Matcher;
218
+ word: boolean;
219
+ }
220
+
221
+ type Expr =
222
+ | { k: "atom"; p: Pattern; hit: boolean }
223
+ | { k: "not"; x: Expr; hit: boolean }
224
+ | { k: "and"; l: Expr; r: Expr; hit: boolean }
225
+ | { k: "or"; l: Expr; r: Expr; hit: boolean };
226
+
227
+ /** Characters that make a pattern a regex (git's `is_regex_special`) */
228
+ const REGEX_SPECIAL = new Uint8Array(256);
229
+ for (const c of "$()*+.?[\\^{|") REGEX_SPECIAL[c.charCodeAt(0)] = 1;
230
+
231
+ const isAlpha = (b: number) => (b >= 0x41 && b <= 0x5a) || (b >= 0x61 && b <= 0x7a);
232
+ const isDigit = (b: number) => b >= 0x30 && b <= 0x39;
233
+ /** grep.c's word_char: git's ASCII isalnum, or `_` */
234
+ const wordChar = (b: number | undefined) =>
235
+ b !== undefined && (isAlpha(b) || isDigit(b) || b === 0x5f);
236
+ /** git's isspace: space, tab, LF, CR */
237
+ const isSpace = (b: number) => b === 0x20 || b === 0x09 || b === 0x0a || b === 0x0d;
238
+ const lowerAscii = (b: number) => (b >= 0x41 && b <= 0x5a ? b + 32 : b);
239
+
240
+ /** A C string: the bytes up to the first NUL, as `%s` prints them */
241
+ function cString(bytes: Uint8Array): string {
242
+ const nul = bytes.indexOf(0);
243
+ return new TextDecoder("latin1").decode(nul < 0 ? bytes : bytes.subarray(0, nul));
244
+ }
245
+
246
+ /** A literal pattern (compile_fixed_regexp: the pattern quoted, `REG_ICASE` for `-i`) */
247
+ function literalMatcher(needle: Uint8Array, ignoreCase: boolean): Matcher {
248
+ const n = ignoreCase ? needle.map(lowerAscii) : needle;
249
+ return (buf, bol, eol) => {
250
+ const last = eol - n.length;
251
+ outer: for (let i = bol; i <= last; i++) {
252
+ for (let k = 0; k < n.length; k++) {
253
+ const b = buf[i + k] as number;
254
+ if ((ignoreCase ? lowerAscii(b) : b) !== n[k]) continue outer;
255
+ }
256
+ return [i - bol, i - bol + n.length];
257
+ }
258
+ return undefined;
259
+ };
260
+ }
261
+
262
+ /** grep.c's compile_regexp of one pattern (a git built without PCRE) */
263
+ function compilePattern(
264
+ token: Extract<GrepToken, { kind: "pattern" }>,
265
+ type: GrepPatternType,
266
+ ignoreCase: boolean,
267
+ ): Matcher {
268
+ const bytes = token.pattern;
269
+ const where = token.no
270
+ ? `In '${token.origin}' at ${token.no}, `
271
+ : token.origin
272
+ ? `${token.origin}, `
273
+ : "";
274
+ const text = cString(bytes);
275
+ if (type !== "perl" && bytes.includes(0)) {
276
+ throw new GrepPatternError(
277
+ text,
278
+ "fatal: given pattern contains NULL byte (via -f <file>). This is only supported with -P under PCRE v2",
279
+ );
280
+ }
281
+ const isFixed = !bytes.some((b) => REGEX_SPECIAL[b] === 1);
282
+ // compile_fixed_regexp quotes the pattern as a C string: a `-P` one ends at its first NUL
283
+ if (type === "fixed" || isFixed) return literalMatcher(encodeLatin1(text), ignoreCase);
284
+ if (type === "perl") {
285
+ // a git built without PCRE: no JavaScript RegExp ever runs a user's pattern
286
+ throw new GrepPatternError(
287
+ text,
288
+ "fatal: cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE",
289
+ );
290
+ }
291
+ try {
292
+ const re = compilePosixRegex(bytes, {
293
+ extended: type === "extended",
294
+ icase: ignoreCase,
295
+ newline: true,
296
+ });
297
+ return (buf, bol, eol, notbol) => {
298
+ const m = re.exec(buf.subarray(bol, eol), eol - bol, 1, notbol);
299
+ return m ? [m.start, m.end] : undefined;
300
+ };
301
+ } catch (e) {
302
+ if (e instanceof PosixRegexError) {
303
+ throw new GrepPatternError(text, `fatal: ${where}'${text}': ${e.message}`);
304
+ }
305
+ throw e;
306
+ }
307
+ }
308
+
309
+ function encodeLatin1(s: string): Uint8Array {
310
+ const out = new Uint8Array(s.length);
311
+ for (let i = 0; i < s.length; i++) out[i] = s.charCodeAt(i);
312
+ return out;
313
+ }
314
+
315
+ /** The text git prints for a token (`p->pattern`) */
316
+ function tokenText(t: GrepToken): string {
317
+ switch (t.kind) {
318
+ case "pattern":
319
+ return cString(t.pattern);
320
+ case "and":
321
+ return "--and";
322
+ case "not":
323
+ return "--not";
324
+ case "open":
325
+ return "(";
326
+ case "close":
327
+ return ")";
328
+ }
329
+ }
330
+
331
+ /** grep.c's compile_pattern_or and friends over the token list */
332
+ class ExpressionParser {
333
+ pos = 0;
334
+ constructor(
335
+ private readonly tokens: GrepToken[],
336
+ private readonly patterns: Map<GrepToken, Pattern>,
337
+ private readonly legacy = false,
338
+ ) {}
339
+
340
+ private die(message: string): never {
341
+ throw new GrepError(`fatal: ${message}`);
342
+ }
343
+
344
+ private get cur(): GrepToken | undefined {
345
+ return this.tokens[this.pos];
346
+ }
347
+
348
+ atom(): Expr | undefined {
349
+ const p = this.cur;
350
+ if (!p) return undefined;
351
+ if (p.kind === "pattern") {
352
+ this.pos++;
353
+ return { k: "atom", p: this.patterns.get(p) as Pattern, hit: false };
354
+ }
355
+ if (p.kind === "open") {
356
+ this.pos++;
357
+ const x = this.or();
358
+ if (this.cur?.kind !== "close") {
359
+ this.die(this.legacy ? "unmatched parenthesis" : "unmatched ( for expression group");
360
+ }
361
+ this.pos++;
362
+ return x;
363
+ }
364
+ return undefined;
365
+ }
366
+
367
+ not(): Expr | undefined {
368
+ const p = this.cur;
369
+ if (!p) return undefined;
370
+ if (p.kind === "not") {
371
+ if (this.pos + 1 >= this.tokens.length) this.die("--not not followed by pattern expression");
372
+ this.pos++;
373
+ const x = this.not();
374
+ if (!x) this.die("--not followed by non pattern expression");
375
+ return { k: "not", x, hit: false };
376
+ }
377
+ return this.atom();
378
+ }
379
+
380
+ and(): Expr | undefined {
381
+ const x = this.not();
382
+ const p = this.cur;
383
+ if (p && p.kind === "and") {
384
+ if (!x) this.die("--and not preceded by pattern expression");
385
+ if (this.pos + 1 >= this.tokens.length) this.die("--and not followed by pattern expression");
386
+ this.pos++;
387
+ const y = this.and();
388
+ if (!y) this.die("--and not followed by pattern expression");
389
+ return { k: "and", l: x, r: y, hit: false };
390
+ }
391
+ return x;
392
+ }
393
+
394
+ or(): Expr | undefined {
395
+ const x = this.and();
396
+ const p = this.cur;
397
+ if (x && p && p.kind !== "close") {
398
+ const y = this.or();
399
+ if (!y) this.die(`not a pattern expression ${tokenText(p)}`);
400
+ return { k: "or", l: x, r: y, hit: false };
401
+ }
402
+ return x;
403
+ }
404
+ }
405
+
406
+ /** A growing byte buffer */
407
+ class Out {
408
+ chunks: Uint8Array[] = [];
409
+ length = 0;
410
+ push(bytes: Uint8Array): void {
411
+ if (bytes.length === 0) return;
412
+ this.chunks.push(bytes);
413
+ this.length += bytes.length;
414
+ }
415
+ bytes(): Uint8Array {
416
+ const out = new Uint8Array(this.length);
417
+ let at = 0;
418
+ for (const c of this.chunks) {
419
+ out.set(c, at);
420
+ at += c.length;
421
+ }
422
+ return out;
423
+ }
424
+ }
425
+
426
+ const NL = new Uint8Array([0x0a]);
427
+ const NUL = new Uint8Array([0]);
428
+ const HUNK = encoder.encode("--");
429
+ const RESET = encoder.encode("\x1b[m");
430
+ const FIRST_FEW_BYTES = 8000;
431
+
432
+ /** `buffer_is_binary`: a NUL among the first 8000 bytes */
433
+ export function bufferIsBinary(content: Uint8Array): boolean {
434
+ const end = Math.min(content.length, FIRST_FEW_BYTES);
435
+ for (let i = 0; i < end; i++) if (content[i] === 0) return true;
436
+ return false;
437
+ }
438
+
439
+ /**
440
+ * Matches sources and collects git grep's output. Create one per `git grep` run (its hunk
441
+ * marks depend on what earlier sources printed); {@link output} gives what was printed.
442
+ *
443
+ * @throws GrepPatternError, GrepError (from the constructor) where git dies compiling
444
+ */
445
+ export class GrepEngine {
446
+ private readonly patterns: Pattern[] = [];
447
+ private readonly expr?: Expr;
448
+ private readonly allMatch: boolean;
449
+ private readonly o: Required<
450
+ Omit<GrepEngineOptions, "colors" | "threads" | "patternType" | "compatibility">
451
+ >;
452
+ private readonly colors?: GrepColors;
453
+ private readonly threaded: boolean;
454
+ /** git 2.43 compatibility */
455
+ private readonly legacy: boolean;
456
+ private readonly skipFirstLineSetting: boolean;
457
+ private skipFirstLine: boolean;
458
+ private lastShown = 0;
459
+ private showHunkMark = false;
460
+ private readonly out = new Out();
461
+ private cur = new Out();
462
+ /** The current source's funcname matcher: undefined not asked yet, null the default rule */
463
+ private findFunc: FindFunction | null | undefined;
464
+ private source?: GrepSourceInput;
465
+ private buf: Uint8Array = new Uint8Array(0);
466
+
467
+ constructor(tokens: readonly GrepToken[], options: GrepEngineOptions = {}) {
468
+ const type = options.patternType ?? "basic";
469
+ this.legacy = options.compatibility === "2.43";
470
+ const ignoreCase = !!options.ignoreCase;
471
+ const word = !!options.wordRegexp;
472
+ // do_append_grep_pat: a pattern with newlines is one pattern per line
473
+ const list: GrepToken[] = [];
474
+ for (const t of tokens) {
475
+ if (t.kind !== "pattern" || !t.pattern.includes(0x0a)) {
476
+ list.push(t);
477
+ continue;
478
+ }
479
+ let pos = 0;
480
+ for (;;) {
481
+ const nl = t.pattern.indexOf(0x0a, pos);
482
+ const end = nl < 0 ? t.pattern.length : nl;
483
+ list.push({ ...t, pattern: t.pattern.slice(pos, end) });
484
+ if (nl < 0) break;
485
+ pos = nl + 1;
486
+ }
487
+ }
488
+ if (list.length === 0) throw new GrepError("fatal: no pattern given");
489
+ const byToken = new Map<GrepToken, Pattern>();
490
+ let extended = false;
491
+ for (const t of list) {
492
+ if (t.kind !== "pattern") {
493
+ extended = true;
494
+ continue;
495
+ }
496
+ const p: Pattern = { token: t, exec: compilePattern(t, type, ignoreCase), word };
497
+ this.patterns.push(p);
498
+ byToken.set(t, p);
499
+ }
500
+ if (options.allMatch) extended = true;
501
+ if (extended) {
502
+ const parser = new ExpressionParser(list, byToken, this.legacy);
503
+ this.expr = parser.or();
504
+ const left = list[parser.pos];
505
+ if (left) {
506
+ const what = this.legacy
507
+ ? "incomplete pattern expression"
508
+ : "incomplete pattern expression group";
509
+ throw new GrepError(`fatal: ${what}: ${tokenText(left)}`);
510
+ }
511
+ }
512
+ this.allMatch = !!options.allMatch && this.expr !== undefined;
513
+ const invert = !!options.invert;
514
+ this.o = {
515
+ ignoreCase,
516
+ wordRegexp: word,
517
+ invert,
518
+ allMatch: !!options.allMatch,
519
+ lineNumber: !!options.lineNumber,
520
+ column: !!options.column,
521
+ pathname: options.pathname ?? true,
522
+ nullFollowingName: !!options.nullFollowingName,
523
+ onlyMatching: !invert && !!options.onlyMatching,
524
+ count: !!options.count,
525
+ nameOnly: !!options.nameOnly,
526
+ unmatchNameOnly: !!options.unmatchNameOnly,
527
+ statusOnly: !!options.statusOnly,
528
+ fileBreak: !!options.fileBreak,
529
+ heading: !!options.heading,
530
+ preContext: Math.max(0, options.preContext ?? 0),
531
+ postContext: Math.max(0, options.postContext ?? 0),
532
+ funcname: !!options.funcname,
533
+ funcbody: !!options.funcbody,
534
+ maxCount: options.maxCount ?? -1,
535
+ binary: options.binary ?? "default",
536
+ };
537
+ this.colors = options.colors;
538
+ this.threaded = options.threads === undefined || options.threads > 1;
539
+ const o = this.o;
540
+ this.skipFirstLineSetting =
541
+ this.threaded &&
542
+ !(o.nameOnly || o.unmatchNameOnly || o.count) &&
543
+ (o.preContext > 0 || o.postContext > 0 || o.fileBreak || o.funcbody);
544
+ this.skipFirstLine = this.skipFirstLineSetting;
545
+ }
546
+
547
+ /** Everything printed so far */
548
+ output(): Uint8Array {
549
+ return this.out.bytes();
550
+ }
551
+
552
+ /** Searches one source (grep.c's `grep_source`); returns whether it hit. */
553
+ grepSource(source: GrepSourceInput): boolean {
554
+ this.source = source;
555
+ this.cur = new Out();
556
+ let hit: boolean;
557
+ if (!this.allMatch) {
558
+ hit = this.grepSource1(source, false);
559
+ } else {
560
+ const expr = this.expr as Expr;
561
+ clearHitMarkers(expr);
562
+ this.grepSource1(source, true);
563
+ hit = checkHitMarkers(expr) ? this.grepSource1(source, false) : false;
564
+ }
565
+ this.workDone();
566
+ this.source = undefined;
567
+ return hit;
568
+ }
569
+
570
+ /** builtin/grep.c's work_done: the source's output, the first line of all dropped when threaded */
571
+ private workDone(): void {
572
+ if (this.cur.length === 0) return;
573
+ let bytes = this.cur.bytes();
574
+ if (this.skipFirstLine) {
575
+ const nl = bytes.indexOf(0x0a);
576
+ bytes = nl < 0 ? new Uint8Array(0) : bytes.subarray(nl + 1);
577
+ this.skipFirstLine = false;
578
+ }
579
+ this.out.push(bytes);
580
+ }
581
+
582
+ private emit(bytes: Uint8Array): void {
583
+ this.cur.push(bytes);
584
+ }
585
+
586
+ private emitColor(bytes: Uint8Array, color: string | undefined): void {
587
+ if (this.colors && color) {
588
+ this.emit(encoder.encode(color));
589
+ this.emit(bytes);
590
+ this.emit(RESET);
591
+ } else this.emit(bytes);
592
+ }
593
+
594
+ private emitSep(sign: number): void {
595
+ if (this.o.nullFollowingName) this.emit(NUL);
596
+ else this.emitColor(new Uint8Array([sign]), this.colors?.separator);
597
+ }
598
+
599
+ private showName(name: Uint8Array): void {
600
+ this.emitColor(name, this.colors?.filename);
601
+ this.emit(this.o.nullFollowingName ? NUL : NL);
602
+ }
603
+
604
+ /** headerless_match_one_pattern: `[so, eo]` from `bol` */
605
+ private matchOne(
606
+ p: Pattern,
607
+ bol: number,
608
+ eol: number,
609
+ notbolIn: boolean,
610
+ ): [number, number] | undefined {
611
+ const buf = this.buf;
612
+ const start = bol;
613
+ let notbol = notbolIn;
614
+ for (;;) {
615
+ const m = p.exec(buf, bol, eol, notbol);
616
+ let hit = m !== undefined;
617
+ if (m && p.word) {
618
+ const [so, eo] = m;
619
+ const okStart = so === 0 || !wordChar(buf[bol + so - 1]);
620
+ const okEnd = eo === eol - bol || !wordChar(buf[bol + eo]);
621
+ if (!(okStart && okEnd)) hit = false;
622
+ // words consist of at least one character
623
+ if (so === eo) hit = false;
624
+ if (!hit && bol + so + 1 < eol) {
625
+ // a later match may be a word: retry after the next non-word character
626
+ bol = bol + so + 1;
627
+ while (wordChar(buf[bol - 1]) && bol < eol) bol++;
628
+ notbol = true;
629
+ if (bol < eol) continue;
630
+ }
631
+ }
632
+ if (!hit || !m) return undefined;
633
+ return [m[0] + bol - start, m[1] + bol - start];
634
+ }
635
+ }
636
+
637
+ /** match_expr_eval; `col` and `icol` are the earliest match and inverted match columns */
638
+ private evaluate(
639
+ x: Expr,
640
+ bol: number,
641
+ eol: number,
642
+ col: { v: number },
643
+ icol: { v: number },
644
+ collect: boolean,
645
+ ): boolean {
646
+ let h = false;
647
+ switch (x.k) {
648
+ case "atom": {
649
+ const m = this.matchOne(x.p, bol, eol, false);
650
+ h = m !== undefined;
651
+ if (m && (col.v < 0 || m[0] < col.v)) col.v = m[0];
652
+ break;
653
+ }
654
+ case "not":
655
+ // a NOT swaps the columns
656
+ h = !this.evaluate(x.x, bol, eol, icol, col, false);
657
+ break;
658
+ case "and":
659
+ h = this.evaluate(x.l, bol, eol, col, icol, false);
660
+ if (h || this.o.column) {
661
+ h = this.evaluate(x.r, bol, eol, col, icol, false) && h;
662
+ }
663
+ break;
664
+ case "or":
665
+ if (!(collect || this.o.column)) {
666
+ return (
667
+ this.evaluate(x.l, bol, eol, col, icol, false) ||
668
+ this.evaluate(x.r, bol, eol, col, icol, false)
669
+ );
670
+ }
671
+ h = this.evaluate(x.l, bol, eol, col, icol, false);
672
+ if (collect) x.l.hit ||= h;
673
+ h = this.evaluate(x.r, bol, eol, col, icol, collect) || h;
674
+ break;
675
+ }
676
+ if (collect) x.hit ||= h;
677
+ return h;
678
+ }
679
+
680
+ /** match_line */
681
+ private matchLine(
682
+ bol: number,
683
+ eol: number,
684
+ col: { v: number },
685
+ icol: { v: number },
686
+ collect: boolean,
687
+ ): boolean {
688
+ if (this.expr) return this.evaluate(this.expr, bol, eol, col, icol, collect);
689
+ let hit = false;
690
+ for (const p of this.patterns) {
691
+ const m = this.matchOne(p, bol, eol, false);
692
+ if (!m) continue;
693
+ hit = true;
694
+ // with --column every pattern is asked, for the earliest match
695
+ if (!this.o.column) break;
696
+ if (col.v < 0 || m[0] < col.v) col.v = m[0];
697
+ }
698
+ return hit;
699
+ }
700
+
701
+ /** grep_next_match over every pattern: the earliest match (the longest of those) */
702
+ private nextMatch(bol: number, eol: number, notbol: boolean): [number, number] | undefined {
703
+ let best: [number, number] | undefined;
704
+ if (bol >= eol) return undefined;
705
+ for (const p of this.patterns) {
706
+ const m = this.matchOne(p, bol, eol, notbol);
707
+ if (!m) continue;
708
+ if (best && (m[0] > best[0] || (m[0] === best[0] && m[1] < best[1]))) continue;
709
+ best = m;
710
+ }
711
+ return best;
712
+ }
713
+
714
+ private showLineHeader(name: Uint8Array, lno: number, cno: number, sign: number): void {
715
+ const o = this.o;
716
+ if (o.heading && this.lastShown === 0) {
717
+ this.emitColor(name, this.colors?.filename);
718
+ this.emit(NL);
719
+ }
720
+ this.lastShown = lno;
721
+ if (!o.heading && o.pathname) {
722
+ this.emitColor(name, this.colors?.filename);
723
+ this.emitSep(sign);
724
+ }
725
+ if (o.lineNumber) {
726
+ this.emitColor(encoder.encode(String(lno)), this.colors?.lineNumber);
727
+ this.emitSep(sign);
728
+ }
729
+ if (o.column && cno) {
730
+ this.emitColor(encoder.encode(String(cno)), this.colors?.column);
731
+ this.emitSep(sign);
732
+ }
733
+ }
734
+
735
+ /** show_line */
736
+ private showLine(bol: number, eol: number, lno: number, cnoIn: number, sign: number): void {
737
+ const o = this.o;
738
+ const buf = this.buf;
739
+ const name = (this.source as GrepSourceInput).name;
740
+ let cno = cnoIn;
741
+ if (o.fileBreak && this.lastShown === 0) {
742
+ if (this.showHunkMark) this.emit(NL);
743
+ } else if (o.preContext || o.postContext || o.funcbody) {
744
+ if (this.lastShown === 0) {
745
+ if (this.showHunkMark) {
746
+ this.emitColor(HUNK, this.colors?.separator);
747
+ this.emit(NL);
748
+ }
749
+ } else if (lno > this.lastShown + 1) {
750
+ this.emitColor(HUNK, this.colors?.separator);
751
+ this.emit(NL);
752
+ }
753
+ }
754
+ if (!o.onlyMatching) this.showLineHeader(name, lno, cno, sign);
755
+ let at = bol;
756
+ if (this.colors || o.onlyMatching) {
757
+ let matchColor: string | undefined;
758
+ let lineColor: string | undefined;
759
+ if (this.colors) {
760
+ matchColor = sign === 0x3a ? this.colors.matchSelected : this.colors.matchContext;
761
+ if (sign === 0x3a) lineColor = this.colors.selected;
762
+ else if (sign === 0x2d) lineColor = this.colors.context;
763
+ else if (sign === 0x3d) lineColor = this.colors.function;
764
+ }
765
+ let notbol = false;
766
+ for (;;) {
767
+ const m = this.nextMatch(at, eol, notbol);
768
+ if (!m || m[0] === m[1]) break;
769
+ // 2.43 starts from the line's column and adds each match's end
770
+ if (!this.legacy) cno = at - bol + m[0] + 1;
771
+ if (o.onlyMatching) this.showLineHeader(name, lno, cno, sign);
772
+ else this.emitColor(buf.subarray(at, at + m[0]), lineColor);
773
+ this.emitColor(buf.subarray(at + m[0], at + m[1]), matchColor);
774
+ if (o.onlyMatching) this.emit(NL);
775
+ at += m[1];
776
+ if (this.legacy) cno += m[1];
777
+ notbol = true;
778
+ }
779
+ if (!o.onlyMatching) {
780
+ this.emitColor(buf.subarray(at, eol), lineColor);
781
+ this.emit(NL);
782
+ }
783
+ return;
784
+ }
785
+ this.emit(buf.subarray(at, eol));
786
+ this.emit(NL);
787
+ }
788
+
789
+ /** match_funcname */
790
+ private matchFuncname(bol: number, eol: number): boolean {
791
+ if (this.findFunc === undefined) {
792
+ this.findFunc = this.source?.findFunction?.() ?? null;
793
+ }
794
+ if (this.findFunc) return this.findFunc(this.buf.subarray(bol, eol)) !== undefined;
795
+ if (bol === eol) return false;
796
+ const c = this.buf[bol] ?? 0;
797
+ return isAlpha(c) || c === 0x5f || c === 0x24;
798
+ }
799
+
800
+ private isEmptyLine(bol: number, eol: number): boolean {
801
+ let at = bol;
802
+ while (at < eol && at < this.buf.length && isSpace(this.buf[at] as number)) at++;
803
+ return at === eol;
804
+ }
805
+
806
+ /** show_funcname_line */
807
+ private showFuncnameLine(bolIn: number, lnoIn: number): void {
808
+ const buf = this.buf;
809
+ let bol = bolIn;
810
+ let lno = lnoIn;
811
+ while (bol > 0) {
812
+ const eol = --bol;
813
+ while (bol > 0 && buf[bol - 1] !== 0x0a) bol--;
814
+ lno--;
815
+ if (lno <= this.lastShown) break;
816
+ if (this.matchFuncname(bol, eol)) {
817
+ this.showLine(bol, eol, lno, 0, 0x3d);
818
+ break;
819
+ }
820
+ }
821
+ }
822
+
823
+ /** show_pre_context */
824
+ private showPreContext(bolIn: number, end: number, lno: number): void {
825
+ const o = this.o;
826
+ const buf = this.buf;
827
+ let bol = bolIn;
828
+ let cur = lno;
829
+ let from = 1;
830
+ let funcnameLno = 0;
831
+ let funcnameNeeded = o.funcname;
832
+ let commentNeeded = false;
833
+ if (o.preContext < lno) from = lno - o.preContext;
834
+ if (from <= this.lastShown) from = this.lastShown + 1;
835
+ const origFrom = from;
836
+ if (o.funcbody) {
837
+ if (this.matchFuncname(bol, end)) commentNeeded = true;
838
+ else funcnameNeeded = true;
839
+ from = this.lastShown + 1;
840
+ }
841
+ // rewind
842
+ while (bol > 0 && cur > from) {
843
+ const nextBol = bol;
844
+ const eol = --bol;
845
+ while (bol > 0 && buf[bol - 1] !== 0x0a) bol--;
846
+ cur--;
847
+ if (commentNeeded && (this.isEmptyLine(bol, eol) || this.matchFuncname(bol, eol))) {
848
+ commentNeeded = false;
849
+ from = origFrom;
850
+ if (cur < from) {
851
+ cur++;
852
+ bol = nextBol;
853
+ break;
854
+ }
855
+ }
856
+ if (funcnameNeeded && this.matchFuncname(bol, eol)) {
857
+ funcnameLno = cur;
858
+ funcnameNeeded = false;
859
+ if (o.funcbody) commentNeeded = true;
860
+ else from = origFrom;
861
+ }
862
+ }
863
+ // a function signature further back
864
+ if (o.funcname && funcnameNeeded) this.showFuncnameLine(bol, cur);
865
+ // back forward
866
+ while (cur < lno) {
867
+ let eol = bol;
868
+ while (buf[eol] !== 0x0a) eol++;
869
+ this.showLine(bol, eol, cur, 0, cur === funcnameLno ? 0x3d : 0x2d);
870
+ bol = eol + 1;
871
+ cur++;
872
+ }
873
+ }
874
+
875
+ /** grep_source_1 */
876
+ private grepSource1(source: GrepSourceInput, collect: boolean): boolean {
877
+ const o = this.o;
878
+ if (o.preContext || o.postContext || o.fileBreak || o.funcbody) {
879
+ // hunk marks, except before the first file (threaded: always, the first line dropped)
880
+ if (this.lastShown) this.showHunkMark = true;
881
+ if (this.threaded) this.showHunkMark = true;
882
+ }
883
+ this.lastShown = 0;
884
+ let binaryMatchOnly = false;
885
+ if (!source.textconv) {
886
+ const binary = source.binary ?? (source.content ? bufferIsBinary(source.content) : false);
887
+ if (o.binary === "default" && binary) binaryMatchOnly = true;
888
+ else if (o.binary === "nomatch" && binary) return false;
889
+ }
890
+ this.findFunc = undefined;
891
+ const buf = source.content;
892
+ if (!buf) return false;
893
+ this.buf = buf;
894
+ const size = buf.length;
895
+ let bol = 0;
896
+ let left = size;
897
+ let lno = 1;
898
+ let lastHit = 0;
899
+ let count = 0;
900
+ let showFunction = false;
901
+ let peekBol = -1;
902
+ // should_lookahead: plain patterns, no inversion
903
+ const tryLookahead = !this.expr && !o.invert;
904
+ while (left) {
905
+ if (tryLookahead && !(lastHit && (showFunction || lno <= lastHit + o.postContext))) {
906
+ // look_ahead: skip to the line of the earliest match in the rest of the buffer
907
+ let earliest = -1;
908
+ for (const p of this.patterns) {
909
+ const m = p.exec(buf, bol, size, false);
910
+ if (m && (earliest < 0 || m[0] < earliest)) earliest = m[0];
911
+ }
912
+ if (earliest < 0) break;
913
+ let sp = bol + earliest;
914
+ while (sp > bol && buf[sp - 1] !== 0x0a) sp--;
915
+ for (let at = buf.indexOf(0x0a, bol); at >= 0 && at < sp; at = buf.indexOf(0x0a, at + 1)) {
916
+ lno++;
917
+ }
918
+ left -= sp - bol;
919
+ bol = sp;
920
+ }
921
+ let eol = buf.indexOf(0x0a, bol);
922
+ if (eol < 0) eol = size;
923
+ left = size - eol;
924
+ const col = { v: -1 };
925
+ const icol = { v: -1 };
926
+ let hit = this.matchLine(bol, eol, col, icol, collect);
927
+ if (!collect) {
928
+ if (o.invert) hit = !hit;
929
+ if (o.unmatchNameOnly) {
930
+ if (hit) return false;
931
+ } else if (hit && (o.maxCount < 0 || count < o.maxCount)) {
932
+ count++;
933
+ if (o.statusOnly) return true;
934
+ if (o.nameOnly) {
935
+ this.showName(source.name);
936
+ return true;
937
+ }
938
+ if (!o.count) {
939
+ if (binaryMatchOnly) {
940
+ this.emit(encoder.encode("Binary file "));
941
+ this.emitColor(source.name, this.colors?.filename);
942
+ this.emit(encoder.encode(" matches\n"));
943
+ return true;
944
+ }
945
+ // the pre-context lines not shown yet
946
+ if (o.preContext || o.funcbody) this.showPreContext(bol, eol, lno);
947
+ else if (o.funcname) this.showFuncnameLine(bol, lno);
948
+ let cno = o.invert ? icol.v : col.v;
949
+ if (cno < 0) cno = 0;
950
+ this.showLine(bol, eol, lno, cno + 1, 0x3a);
951
+ lastHit = lno;
952
+ if (o.funcbody) showFunction = true;
953
+ }
954
+ } else {
955
+ if (showFunction && (peekBol < 0 || peekBol < bol)) {
956
+ // trailing empty lines are not interesting: peek past them (the byte after the
957
+ // buffer reads as git's terminating NUL)
958
+ let peekLeft = left;
959
+ let peekEol = eol;
960
+ peekBol = bol;
961
+ while (this.isEmptyLine(peekBol, peekEol)) {
962
+ peekBol = peekEol + 1;
963
+ let e = peekBol;
964
+ while (peekLeft && (e < size ? buf[e] : 0) !== 0x0a) {
965
+ peekLeft--;
966
+ e++;
967
+ }
968
+ peekEol = e;
969
+ }
970
+ // git 2.43 has no end-of-buffer check: a trailing empty line stays in the body
971
+ if ((!this.legacy && peekBol >= size) || this.matchFuncname(peekBol, peekEol)) {
972
+ showFunction = false;
973
+ }
974
+ }
975
+ if (showFunction || (lastHit && lno <= lastHit + o.postContext)) {
976
+ // within the post-context of the last hit
977
+ this.showLine(bol, eol, lno, col.v + 1, 0x2d);
978
+ }
979
+ }
980
+ }
981
+ bol = eol + 1;
982
+ if (!left) break;
983
+ left--;
984
+ lno++;
985
+ }
986
+ if (collect) return false;
987
+ if (o.statusOnly) return o.unmatchNameOnly;
988
+ if (o.unmatchNameOnly) {
989
+ // no hit: the name is shown
990
+ this.showName(source.name);
991
+ return true;
992
+ }
993
+ if (o.count && count) {
994
+ if (o.pathname) {
995
+ this.emitColor(source.name, this.colors?.filename);
996
+ this.emitSep(0x3a);
997
+ }
998
+ this.emit(encoder.encode(`${count}\n`));
999
+ return true;
1000
+ }
1001
+ return lastHit !== 0;
1002
+ }
1003
+ }
1004
+
1005
+ /** clr_hit_marker: the top-level or chain's markers */
1006
+ function clearHitMarkers(xIn: Expr): void {
1007
+ let x = xIn;
1008
+ for (;;) {
1009
+ x.hit = false;
1010
+ if (x.k !== "or") return;
1011
+ x.l.hit = false;
1012
+ x = x.r;
1013
+ }
1014
+ }
1015
+
1016
+ /** chk_hit_marker: every term of the top-level or chain hit some line */
1017
+ function checkHitMarkers(xIn: Expr): boolean {
1018
+ let x = xIn;
1019
+ for (;;) {
1020
+ if (x.k !== "or") return x.hit;
1021
+ if (!x.l.hit) return false;
1022
+ x = x.r;
1023
+ }
1024
+ }