@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,1070 @@
1
+ /**
2
+ * The format language of git's ref-filter.c: a format's atoms parsed once, each ref's values
3
+ * computed when first needed (its object read only if an atom needs it), and the format
4
+ * expanded with `%(if)`/`%(then)`/`%(else)`, `%(align)` and the quoting styles, byte for byte
5
+ * as `git for-each-ref --format` prints it.
6
+ *
7
+ * Values are text as vcs-utils' `decodeGitPath` gives bytes (UTF-8, other bytes as U+DC80 +
8
+ * byte), so `encodeGitPath` of the output is git's bytes.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const format = new RefFormat("%(refname:short) %(objectname:short)", source);
13
+ * const line = await format.format(item); // "main 1a2b3c4"
14
+ * ```
15
+ *
16
+ * @module
17
+ */
18
+
19
+ import type { ObjectId } from "@statewalker/vcs-core";
20
+ import { decodeGitPath, encodeGitPath, gitStrWidth } from "@statewalker/vcs-utils";
21
+
22
+ import { RefFilterError } from "../../errors/index.js";
23
+ import { type DateMode, parseDateMode, type ShowDateContext, showDate } from "../date-format.js";
24
+ import type { Mailmap } from "../mailmap.js";
25
+ import { sanitizedSubject } from "../pretty-format.js";
26
+ import { appendTrailers, type TrailerConfig } from "../trailers.js";
27
+ import { type AtomCmpType, parseAtom, type UsedAtom } from "./ref-atoms.js";
28
+ import { quoteRefValue, type RefQuoteStyle } from "./ref-quote.js";
29
+
30
+ /** The kinds of refs (ref-filter.h's `FILTER_REFS_*`). */
31
+ export const RefKind = {
32
+ TAGS: 0x0002,
33
+ BRANCHES: 0x0004,
34
+ REMOTES: 0x0008,
35
+ OTHERS: 0x0010,
36
+ REGULAR: 0x001e,
37
+ DETACHED_HEAD: 0x0020,
38
+ PSEUDOREFS: 0x0040,
39
+ ROOT_REFS: 0x0080,
40
+ } as const;
41
+
42
+ /** A ref the filter kept (git's `struct ref_array_item`). */
43
+ export interface RefFilterItem {
44
+ /** The full name (`refs/heads/main`, `HEAD`) */
45
+ refname: string;
46
+ /** The object it names (a symbolic ref's target's) */
47
+ objectId: ObjectId;
48
+ /** What it peels to, when the ref store knows (packed-refs `^` lines) */
49
+ peeledId?: ObjectId;
50
+ /** A symbolic ref's target */
51
+ symref?: string;
52
+ /** git's REF_ISSYMREF / REF_ISPACKED */
53
+ flags: { symref: boolean; packed: boolean };
54
+ /** Its {@link RefKind} */
55
+ kind: number;
56
+ /** The commit it peels to, when a reachability filter asked for it */
57
+ commit?: ObjectId;
58
+ /** `%(rest)`'s text (none for for-each-ref) */
59
+ rest?: string;
60
+ /** `%(ahead-behind:...)` counts, one per such atom, for a ref that peels to a commit */
61
+ counts?: { ahead: number; behind: number }[];
62
+ /** `%(is-base:...)` names, one per such atom */
63
+ isBase?: (string | undefined)[];
64
+ /** The values of the format's atoms, once computed */
65
+ values?: AtomValue[];
66
+ }
67
+
68
+ /** A computed atom value (git's `struct atom_value`). */
69
+ export interface AtomValue {
70
+ s: string;
71
+ /** The value has a length of its own (`%(raw)`: NULs kept) */
72
+ sized?: boolean;
73
+ /** The number sorted on for numeric and date atoms */
74
+ value: number;
75
+ atom: UsedAtom;
76
+ }
77
+
78
+ /** An object as the format reads it. */
79
+ export interface RefFormatObject {
80
+ type: "commit" | "tree" | "blob" | "tag";
81
+ bytes: Uint8Array;
82
+ }
83
+
84
+ /** What the format reads of the repository; see {@link RefFormat}. */
85
+ export interface RefFormatSource {
86
+ /** The object (its replacement when a replace ref names one), undefined when missing */
87
+ readObject(id: ObjectId): Promise<RefFormatObject | undefined>;
88
+ /** `id` abbreviated as git prints it: its default length, or at least `minLength` */
89
+ abbreviate(id: ObjectId, minLength?: number): Promise<string>;
90
+ /** Whether a ref of this full name exists */
91
+ refExists(name: string): Promise<boolean>;
92
+ /** A configuration value (the last one) */
93
+ config(key: string): string | undefined;
94
+ /** The ref HEAD resolves to (`HEAD` when detached), undefined when unborn */
95
+ headRef(): Promise<string | undefined>;
96
+ /** `branch@{upstream}`'s full ref name, undefined when none */
97
+ upstreamOf(branch: string): Promise<string | undefined>;
98
+ /** `branch@{push}`'s full ref name, undefined when none */
99
+ pushOf(branch: string): Promise<string | undefined>;
100
+ /** `remote_for_branch` / `pushremote_for_branch` when configured (explicit), else "" */
101
+ remoteName(branch: string, push: boolean): string;
102
+ /** `remote_ref_for_branch`: the merge source, or the push refspec's destination */
103
+ remoteRef(branch: string, push: boolean): string | undefined;
104
+ /** The commit a ref names (tags peeled), undefined when it names none */
105
+ refCommit(ref: string): Promise<ObjectId | undefined>;
106
+ /** The commits only `ours` and only `theirs` reach */
107
+ aheadBehind(ours: ObjectId, theirs: ObjectId): Promise<{ ahead: number; behind: number }>;
108
+ /** The worktree a branch is checked out in, undefined when none */
109
+ worktreePath(ref: string): Promise<string | undefined>;
110
+ /** The repository's mailmap */
111
+ mailmap(): Promise<Mailmap>;
112
+ /** `git describe <args> <id>`'s output, "" when it fails */
113
+ describe(id: ObjectId, options: NonNullable<UsedAtom["describe"]>): Promise<string>;
114
+ /** The trailer configuration */
115
+ trailerConfig(): TrailerConfig;
116
+ /** get_head_description: `(HEAD detached at ...)` for a detached HEAD listed as such */
117
+ headDescription?(): Promise<string>;
118
+ /** The clock and local zone dates are shown with */
119
+ dateContext?: ShowDateContext;
120
+ }
121
+
122
+ /** How {@link RefFormat} expands its format. */
123
+ export interface RefFormatOptions {
124
+ /** `--shell`, `--perl`, `--python`, `--tcl` */
125
+ quoteStyle?: RefQuoteStyle;
126
+ /** `--color`: `%(color:...)` atoms give their escapes */
127
+ useColor?: boolean;
128
+ /**
129
+ * The git version whose output to follow where versions differ (default 2.56). git 2.43's
130
+ * `%(*atom)` reads the object a tag names (a tag of a tag shows the inner tag), not what
131
+ * nested tags peel to, and its `%(trailers)` look for the trailer block in the message with
132
+ * its signature (a signed tag's trailers are not found), and a date atom with a format
133
+ * still sorts by time.
134
+ */
135
+ compatibility?: "2.43" | "2.56";
136
+ }
137
+
138
+ const fatal = (message: string) => new RefFilterError(`fatal: ${message}`, 128);
139
+
140
+ /** The ref name rules `shorten_unambiguous_ref` walks (git's ref_rev_parse_rules). */
141
+ const RULES = [
142
+ "%s",
143
+ "refs/%s",
144
+ "refs/tags/%s",
145
+ "refs/heads/%s",
146
+ "refs/remotes/%s",
147
+ "refs/remotes/%s/HEAD",
148
+ ];
149
+
150
+ /**
151
+ * refs.c's `refs_shorten_unambiguous_ref`: the shortest name a rule maps back to `ref`
152
+ * that no other rule (strict: any; else only the earlier ones) resolves to an existing ref.
153
+ */
154
+ export async function shortenRefName(
155
+ ref: string,
156
+ strict: boolean,
157
+ exists: (name: string) => Promise<boolean>,
158
+ ): Promise<string> {
159
+ for (let i = RULES.length - 1; i > 0; i--) {
160
+ const [prefix, suffix] = (RULES[i] as string).split("%s") as [string, string];
161
+ if (ref.length <= prefix.length + suffix.length) continue;
162
+ if (!ref.startsWith(prefix) || !ref.endsWith(suffix)) continue;
163
+ const short = ref.slice(prefix.length, ref.length - suffix.length);
164
+ const toFail = strict ? RULES.length : i;
165
+ let ambiguous = false;
166
+ for (let j = 0; j < toFail && !ambiguous; j++) {
167
+ if (j === i) continue;
168
+ if (await exists((RULES[j] as string).replace("%s", short))) ambiguous = true;
169
+ }
170
+ if (!ambiguous) return short;
171
+ }
172
+ return ref;
173
+ }
174
+
175
+ function slashes(name: string): number {
176
+ let n = 0;
177
+ for (const c of name) if (c === "/") n++;
178
+ return n;
179
+ }
180
+
181
+ /** normalize_component_count. */
182
+ const componentCount = (name: string, len: number) => (len < 0 ? slashes(name) + len + 1 : len);
183
+
184
+ /** lstrip_ref_components. */
185
+ export function lstripRef(name: string, len: number): string {
186
+ let remaining = componentCount(name, len);
187
+ let i = 0;
188
+ while (remaining > 0) {
189
+ if (i >= name.length) return "";
190
+ if (name[i++] === "/") remaining--;
191
+ }
192
+ return name.slice(i);
193
+ }
194
+
195
+ /** rstrip_ref_components. */
196
+ export function rstripRef(name: string, len: number): string {
197
+ let remaining = componentCount(name, len);
198
+ let end = name.length;
199
+ while (remaining > 0) {
200
+ if (end === 0) return "";
201
+ if (name[--end] === "/") remaining--;
202
+ }
203
+ return name.slice(0, end);
204
+ }
205
+
206
+ const isSpace = (c: string) =>
207
+ c === " " || c === "\t" || c === "\n" || c === "\v" || c === "\f" || c === "\r";
208
+
209
+ /**
210
+ * The offset of a trailing signature in `text` (gpg-interface.c's `parse_signed_buffer`): the
211
+ * last line starting a PGP, X.509 or SSH signature block, else `text.length`.
212
+ */
213
+ export function signatureStart(text: string): number {
214
+ const sigs = [
215
+ "-----BEGIN PGP SIGNATURE-----",
216
+ "-----BEGIN PGP MESSAGE-----",
217
+ "-----BEGIN SIGNED MESSAGE-----",
218
+ "-----BEGIN SSH SIGNATURE-----",
219
+ ];
220
+ let match = text.length;
221
+ let at = 0;
222
+ while (at < text.length) {
223
+ if (sigs.some((s) => text.startsWith(s, at))) match = at;
224
+ const eol = text.indexOf("\n", at);
225
+ at = eol >= 0 ? eol + 1 : text.length;
226
+ }
227
+ return match;
228
+ }
229
+
230
+ interface SubPos {
231
+ sub: number;
232
+ sublen: number;
233
+ body: number;
234
+ nonsiglen: number;
235
+ sig: number;
236
+ buf: string;
237
+ }
238
+
239
+ /** ref-filter.c's find_subpos over an object's text (up to its first NUL, a C string). */
240
+ function findSubpos(content: string): SubPos {
241
+ const nul = content.indexOf("\0");
242
+ const buf = nul >= 0 ? content.slice(0, nul) : content;
243
+ let at = 0;
244
+ // skip past the header until an empty line
245
+ while (at < buf.length && buf[at] !== "\n") {
246
+ const eol = buf.indexOf("\n", at);
247
+ at = eol >= 0 ? eol + 1 : buf.length;
248
+ }
249
+ while (buf[at] === "\n") at++;
250
+ const sigstart = at + signatureStart(buf.slice(at));
251
+ const sub = at;
252
+ let eol = buf.indexOf("\n\n", sub);
253
+ if (eol < 0) eol = buf.indexOf("\r\n\r\n", sub);
254
+ eol = eol >= 0 ? Math.min(eol, sigstart) : sigstart;
255
+ at = eol;
256
+ let sublen = at - sub;
257
+ while (sublen && (buf[sub + sublen - 1] === "\n" || buf[sub + sublen - 1] === "\r")) sublen--;
258
+ while (buf[at] === "\n" || buf[at] === "\r") at++;
259
+ return { sub, sublen, body: at, nonsiglen: sigstart - at, sig: sigstart, buf };
260
+ }
261
+
262
+ /** copy_subject: newlines as spaces, the CR of a CRLF dropped. */
263
+ function copySubject(text: string): string {
264
+ let out = "";
265
+ for (let i = 0; i < text.length; i++) {
266
+ const c = text[i] as string;
267
+ if (c === "\r" && text[i + 1] === "\n") continue;
268
+ out += c === "\n" ? " " : c;
269
+ }
270
+ return out;
271
+ }
272
+
273
+ /** append_lines: `lines` lines, joined with a newline and four spaces. */
274
+ function appendLines(text: string, lines: number): string {
275
+ let out = "";
276
+ let sp = 0;
277
+ for (let i = 0; i < lines && sp < text.length; i++) {
278
+ if (i) out += "\n ";
279
+ const eol = text.indexOf("\n", sp);
280
+ out += eol >= 0 ? text.slice(sp, eol) : text.slice(sp);
281
+ if (eol < 0) break;
282
+ sp = eol + 1;
283
+ }
284
+ return out;
285
+ }
286
+
287
+ /** find_wholine: the rest of the header line `who ...`, "" when there is none. */
288
+ function findWholine(who: string, buf: string): string {
289
+ let at = 0;
290
+ while (at < buf.length) {
291
+ if (buf.startsWith(`${who} `, at)) {
292
+ const start = at + who.length + 1;
293
+ const eol = buf.indexOf("\n", start);
294
+ return eol >= 0 ? buf.slice(start, eol) : buf.slice(start);
295
+ }
296
+ const eol = buf.indexOf("\n", at);
297
+ if (eol < 0) return "";
298
+ if (buf[eol + 1] === "\n") return "";
299
+ at = eol + 1;
300
+ }
301
+ return "";
302
+ }
303
+
304
+ /** copy_name: the identity's name (up to ` <`), "" without one. */
305
+ function copyName(line: string): string {
306
+ const at = line.indexOf(" <");
307
+ return at >= 0 ? line.slice(0, at) : "";
308
+ }
309
+
310
+ /** copy_email with the atom's options. */
311
+ function copyEmail(line: string, opt: NonNullable<UsedAtom["email"]>): string {
312
+ let start = line.indexOf("<");
313
+ if (start < 0) return "";
314
+ if (opt.localpart || opt.trim) start++;
315
+ const rest = line.slice(start);
316
+ let end: number;
317
+ if (opt.localpart) {
318
+ end = rest.indexOf("@");
319
+ if (end < 0) end = rest.indexOf(">");
320
+ } else if (opt.trim) end = rest.indexOf(">");
321
+ else {
322
+ end = rest.indexOf(">");
323
+ if (end >= 0) end++;
324
+ }
325
+ return end < 0 ? "" : rest.slice(0, end);
326
+ }
327
+
328
+ /**
329
+ * `s` without its trailing spaces, in one backwards pass (split_ident_line's trim). Never a
330
+ * `/ +$/` regex: V8 retries it from every space of a long run, quadratic on the hostile
331
+ * author names a fetched commit may carry.
332
+ */
333
+ export function trimTrailingSpaces(s: string): string {
334
+ let end = s.length;
335
+ while (end > 0 && s.charCodeAt(end - 1) === 32) end--;
336
+ return end === s.length ? s : s.slice(0, end);
337
+ }
338
+
339
+ /** apply_mailmap_to_header for one identity line's value (`name <email> rest`). */
340
+ function mailmapLine(line: string, mailmap: Mailmap): string {
341
+ const lt = line.indexOf("<");
342
+ const gt = line.indexOf(">", lt + 1);
343
+ if (lt < 0 || gt < 0) return line;
344
+ const name = trimTrailingSpaces(line.slice(0, lt));
345
+ const email = line.slice(lt + 1, gt);
346
+ const mapped = mailmap.map(name, email);
347
+ if (mapped.name === name && mapped.email === email) return line;
348
+ return `${mapped.name} <${mapped.email}>${line.slice(gt + 1)}`;
349
+ }
350
+
351
+ /** The commit's tree and parents from its header. */
352
+ function commitLinks(buf: string): { tree?: string; parents: string[] } {
353
+ const out: { tree?: string; parents: string[] } = { parents: [] };
354
+ for (const line of buf.slice(0, Math.max(buf.indexOf("\n\n"), 0) || buf.length).split("\n")) {
355
+ if (line.startsWith("tree ") && out.tree === undefined) out.tree = line.slice(5);
356
+ else if (line.startsWith("parent ")) out.parents.push(line.slice(7));
357
+ }
358
+ return out;
359
+ }
360
+
361
+ /** A tag's `object`, `type` and `tag` header values. */
362
+ export function tagHeader(buf: string): { object?: string; type?: string; tag?: string } {
363
+ const out: { object?: string; type?: string; tag?: string } = {};
364
+ const end = buf.indexOf("\n\n");
365
+ for (const line of (end >= 0 ? buf.slice(0, end) : buf).split("\n")) {
366
+ if (line.startsWith("object ") && out.object === undefined) out.object = line.slice(7);
367
+ else if (line.startsWith("type ") && out.type === undefined) out.type = line.slice(5);
368
+ else if (line.startsWith("tag ") && out.tag === undefined) out.tag = line.slice(4);
369
+ }
370
+ return out;
371
+ }
372
+
373
+ /** One level of the format's output stack (ref-filter.c's ref_formatting_stack). */
374
+ interface Stack {
375
+ prev?: Stack;
376
+ output: string;
377
+ atEnd?: "align" | "if";
378
+ align?: NonNullable<UsedAtom["align"]>;
379
+ ifState?: IfState;
380
+ }
381
+
382
+ interface IfState {
383
+ cmp: "equal" | "unequal" | "none";
384
+ str?: string;
385
+ thenSeen: boolean;
386
+ elseSeen: boolean;
387
+ satisfied: boolean;
388
+ }
389
+
390
+ /** A piece of a parsed format: literal text or an atom. */
391
+ type Piece = { literal: string } | { atom: number; text: string };
392
+
393
+ /** append_literal: `%%` and `%<hex><hex>` expanded. */
394
+ function expandLiteral(text: string): string {
395
+ let out = "";
396
+ for (let i = 0; i < text.length; i++) {
397
+ const c = text[i] as string;
398
+ if (c === "%") {
399
+ if (text[i + 1] === "%") {
400
+ out += "%";
401
+ i++;
402
+ continue;
403
+ }
404
+ const hex = /^[0-9a-fA-F]{2}/.exec(text.slice(i + 1, i + 3));
405
+ if (hex) {
406
+ const n = Number.parseInt(hex[0], 16);
407
+ // a byte above 0x7f is kept as the byte it is
408
+ out += n < 0x80 ? String.fromCharCode(n) : decodeGitPath(Uint8Array.of(n));
409
+ i += 2;
410
+ continue;
411
+ }
412
+ }
413
+ out += c;
414
+ }
415
+ return out;
416
+ }
417
+
418
+ /** utf8 width of a text, git's `utf8_strnwidth` (bytes that are no UTF-8 count one each). */
419
+ const textWidth = (text: string) => gitStrWidth(encodeGitPath(text));
420
+
421
+ /**
422
+ * A format and the sort keys of one listing, with the atoms they use (git keeps one list
423
+ * for both), and each ref's values.
424
+ */
425
+ export class RefFormat {
426
+ /** The atoms parsed, in order (git's `used_atom`) */
427
+ readonly atoms: UsedAtom[] = [];
428
+ private readonly pieces: Piece[] = [];
429
+ private needColorReset = false;
430
+ private needTagged = false;
431
+ private readonly quoteStyle: RefQuoteStyle;
432
+ private readonly useColor: boolean;
433
+ private readonly peelNested: boolean;
434
+ private headTarget?: Promise<string | undefined>;
435
+ private mailmapLoad?: Promise<Mailmap>;
436
+ private dateModes = new Map<string, DateMode>();
437
+
438
+ /**
439
+ * `format` verified as git's verify_ref_format does (atoms parsed, `%(rest)` refused,
440
+ * `%(raw)` refused with `--shell`/`--python`/`--tcl`).
441
+ *
442
+ * @throws RefFilterError with git's message
443
+ */
444
+ constructor(
445
+ format: string,
446
+ private readonly source: RefFormatSource,
447
+ options: RefFormatOptions = {},
448
+ ) {
449
+ this.quoteStyle = options.quoteStyle ?? "none";
450
+ this.useColor = options.useColor ?? false;
451
+ this.peelNested = options.compatibility !== "2.43";
452
+ let cp = 0;
453
+ for (;;) {
454
+ const sp = findNext(format, cp);
455
+ if (sp < 0) break;
456
+ const ep = format.indexOf(")", sp);
457
+ if (ep < 0) {
458
+ throw new RefFilterError(`error: malformed format string ${format.slice(sp)}`, 129);
459
+ }
460
+ const text = format.slice(sp + 2, ep);
461
+ const at = this.atomIndex(text);
462
+ const atom = this.atoms[at] as UsedAtom;
463
+ if (atom.type === "rest") throw fatal(`this command reject atom %(${text})`);
464
+ if (
465
+ (this.quoteStyle === "python" ||
466
+ this.quoteStyle === "shell" ||
467
+ this.quoteStyle === "tcl") &&
468
+ atom.type === "raw" &&
469
+ atom.raw === "bare"
470
+ ) {
471
+ throw fatal(`--format=${text} cannot be used with --python, --shell, --tcl`);
472
+ }
473
+ if (sp > cp) this.pieces.push({ literal: expandLiteral(format.slice(cp, sp)) });
474
+ this.pieces.push({ atom: at, text });
475
+ if (text.startsWith("color:")) this.needColorReset = text !== "color:reset";
476
+ cp = ep + 1;
477
+ }
478
+ if (cp < format.length) this.pieces.push({ literal: expandLiteral(format.slice(cp)) });
479
+ if (!this.useColor) this.needColorReset = false;
480
+ }
481
+
482
+ /**
483
+ * The index of an atom (parse_ref_filter_atom): one used before with the same text, else
484
+ * a new one; sort keys are parsed through this too.
485
+ */
486
+ atomIndex(text: string): number {
487
+ const known = this.atoms.findIndex((a) => a.name === text);
488
+ if (known >= 0) return known;
489
+ const atom = parseAtom(text, { useColor: this.useColor });
490
+ if (atom.deref) this.needTagged = true;
491
+ this.atoms.push(atom);
492
+ return this.atoms.length - 1;
493
+ }
494
+
495
+ /** The sort type an atom compares by (a date atom with a format compares as text). */
496
+ cmpTypeOf(index: number): AtomCmpType {
497
+ return (this.atoms[index] as UsedAtom).cmpType;
498
+ }
499
+
500
+ /** Whether an atom of this kind is used (`ahead-behind`, `is-base`, ...). */
501
+ uses(type: UsedAtom["type"]): boolean {
502
+ return this.atoms.some((a) => a.type === type);
503
+ }
504
+
505
+ /** The value of atom `index` for `item`, its values computed first if needed. */
506
+ async value(item: RefFilterItem, index: number): Promise<AtomValue> {
507
+ if (!item.values || item.values.length < this.atoms.length) await this.populate(item);
508
+ return (item.values as AtomValue[])[index] as AtomValue;
509
+ }
510
+
511
+ /**
512
+ * format_ref_array_item: the format expanded for `item`.
513
+ *
514
+ * @throws RefFilterError where git dies
515
+ */
516
+ async format(item: RefFilterItem): Promise<string> {
517
+ let stack: Stack = { output: "" };
518
+ const quote = this.quoteStyle;
519
+ const append = (v: { s: string; sized?: boolean }) => {
520
+ if (!stack.prev) stack.output += quoteRefValue(v.s, quote, v.sized);
521
+ else stack.output += quoteRefValue(v.s, "none", v.sized);
522
+ };
523
+ for (const piece of this.pieces) {
524
+ if ("literal" in piece) {
525
+ stack.output += piece.literal;
526
+ continue;
527
+ }
528
+ const v = await this.value(item, piece.atom);
529
+ const atom = v.atom;
530
+ switch (atom.type) {
531
+ case "align":
532
+ stack = {
533
+ prev: stack,
534
+ output: "",
535
+ atEnd: "align",
536
+ ...(atom.align ? { align: atom.align } : {}),
537
+ };
538
+ break;
539
+ case "if":
540
+ stack = {
541
+ prev: stack,
542
+ output: "",
543
+ atEnd: "if",
544
+ ifState: {
545
+ cmp: atom.ifThenElse?.cmp ?? "none",
546
+ ...(atom.ifThenElse?.str !== undefined ? { str: atom.ifThenElse.str } : {}),
547
+ thenSeen: false,
548
+ elseSeen: false,
549
+ satisfied: false,
550
+ },
551
+ };
552
+ break;
553
+ case "then": {
554
+ const state = stack.atEnd === "if" ? stack.ifState : undefined;
555
+ if (!state) throw fatal("format: %(then) atom used without a %(if) atom");
556
+ if (state.thenSeen) throw fatal("format: %(then) atom used more than once");
557
+ if (state.elseSeen) throw fatal("format: %(then) atom used after %(else)");
558
+ state.thenSeen = true;
559
+ const out = stack.output;
560
+ if (state.cmp === "equal") state.satisfied = out === (state.str ?? "");
561
+ else if (state.cmp === "unequal") state.satisfied = out !== (state.str ?? "");
562
+ else state.satisfied = out.length > 0 && ![...out].every(isSpace);
563
+ stack.output = "";
564
+ break;
565
+ }
566
+ case "else": {
567
+ const state = stack.atEnd === "if" ? stack.ifState : undefined;
568
+ if (!state) throw fatal("format: %(else) atom used without a %(if) atom");
569
+ if (!state.thenSeen) throw fatal("format: %(else) atom used without a %(then) atom");
570
+ if (state.elseSeen) throw fatal("format: %(else) atom used more than once");
571
+ state.elseSeen = true;
572
+ stack = { prev: stack, output: "", atEnd: "if", ifState: state };
573
+ break;
574
+ }
575
+ case "end": {
576
+ if (!stack.atEnd) throw fatal("format: %(end) atom used without corresponding atom");
577
+ stack = endHandler(stack);
578
+ const current = stack;
579
+ const prev = current.prev as Stack;
580
+ if (!prev.prev) current.output = quoteRefValue(current.output, quote);
581
+ prev.output += current.output;
582
+ stack = prev;
583
+ break;
584
+ }
585
+ default:
586
+ append(v);
587
+ }
588
+ }
589
+ if (this.needColorReset) append({ s: "\x1b[m" });
590
+ if (stack.prev) throw fatal("format: %(end) atom missing");
591
+ return stack.output;
592
+ }
593
+
594
+ /** populate_value: every atom's value for `item`. */
595
+ private async populate(item: RefFilterItem): Promise<void> {
596
+ const values: AtomValue[] = this.atoms.map((atom) => ({
597
+ s: undefined as unknown as string,
598
+ value: 0,
599
+ atom,
600
+ }));
601
+ const source = this.source;
602
+ let aheadBehindIndex = 0;
603
+ let isBaseIndex = 0;
604
+ for (const v of values) {
605
+ const atom = v.atom;
606
+ let refname: string | undefined;
607
+ switch (atom.type) {
608
+ case "refname":
609
+ refname =
610
+ item.kind & RefKind.DETACHED_HEAD
611
+ ? ((await source.headDescription?.()) ?? "(no branch)")
612
+ : await this.showRef(atom.refname, item.refname);
613
+ break;
614
+ case "worktreepath":
615
+ v.s =
616
+ item.kind === RefKind.BRANCHES ? ((await source.worktreePath(item.refname)) ?? "") : "";
617
+ continue;
618
+ case "symref":
619
+ refname = item.symref === undefined ? "" : await this.showRef(atom.refname, item.symref);
620
+ break;
621
+ case "upstream": {
622
+ if (!item.refname.startsWith("refs/heads/")) {
623
+ v.s = "";
624
+ continue;
625
+ }
626
+ const branch = item.refname.slice(11);
627
+ const upstream = await source.upstreamOf(branch);
628
+ v.s = upstream ? await this.remoteDetails(atom, upstream, item.refname, branch) : "";
629
+ continue;
630
+ }
631
+ case "push": {
632
+ v.s = "";
633
+ if (!item.refname.startsWith("refs/heads/")) continue;
634
+ const branch = item.refname.slice(11);
635
+ let ref: string | undefined;
636
+ if (!atom.remote?.pushRemote) {
637
+ ref = await source.pushOf(branch);
638
+ if (!ref) continue;
639
+ }
640
+ v.s = await this.remoteDetails(atom, ref, item.refname, branch);
641
+ continue;
642
+ }
643
+ case "color":
644
+ v.s = atom.color ?? "";
645
+ continue;
646
+ case "flag": {
647
+ const flags: string[] = [];
648
+ if (item.flags.symref) flags.push("symref");
649
+ if (item.flags.packed) flags.push("packed");
650
+ v.s = flags.join(",");
651
+ continue;
652
+ }
653
+ case "objectname":
654
+ if (atom.deref) continue;
655
+ v.s = await this.oidText(item.objectId, atom);
656
+ continue;
657
+ case "HEAD": {
658
+ this.headTarget ??= source.headRef();
659
+ const head = await this.headTarget;
660
+ v.s = head !== undefined && head === item.refname ? "*" : " ";
661
+ continue;
662
+ }
663
+ case "align":
664
+ case "end":
665
+ case "if":
666
+ case "then":
667
+ case "else":
668
+ v.s = "";
669
+ continue;
670
+ case "rest":
671
+ v.s = item.rest ?? "";
672
+ continue;
673
+ case "ahead-behind": {
674
+ const count = item.counts?.[aheadBehindIndex++];
675
+ v.s = count ? `${count.ahead} ${count.behind}` : "";
676
+ continue;
677
+ }
678
+ case "is-base": {
679
+ const name = item.isBase?.[isBaseIndex++];
680
+ v.s = name !== undefined ? `(${name})` : "";
681
+ continue;
682
+ }
683
+ default:
684
+ continue;
685
+ }
686
+ v.s = atom.deref ? `${refname}^{}` : (refname as string);
687
+ }
688
+ const needsObject = this.atoms.some(
689
+ (a) =>
690
+ a.deref ||
691
+ a.source === "obj" ||
692
+ a.type === "objecttype" ||
693
+ a.type === "objectsize" ||
694
+ a.type === "deltabase",
695
+ );
696
+ if (needsObject) {
697
+ const object = await source.readObject(item.objectId);
698
+ if (!object) throw fatal(`missing object ${item.objectId} for ${item.refname}`);
699
+ await this.grabValues(values, false, item.objectId, object, item.refname);
700
+ if (this.needTagged && object.type === "tag") {
701
+ const peeled = this.peelNested
702
+ ? (item.peeledId ?? (await this.peel(item.objectId, object)))
703
+ : tagHeader(decodeGitPath(object.bytes)).object;
704
+ if (peeled === undefined) throw fatal("bad tag");
705
+ const target = await source.readObject(peeled);
706
+ if (!target) throw fatal(`missing object ${peeled} for ${item.refname}`);
707
+ await this.grabValues(values, true, peeled, target, item.refname);
708
+ }
709
+ }
710
+ for (const v of values) if (v.s === undefined) v.s = "";
711
+ item.values = values;
712
+ }
713
+
714
+ /** peel_object with PEEL_OBJECT_VERIFY_TAGGED_OBJECT_TYPE: undefined for a bad tag. */
715
+ private async peel(id: ObjectId, object: RefFormatObject): Promise<ObjectId | undefined> {
716
+ let current = object;
717
+ let currentId = id;
718
+ for (let depth = 0; current.type === "tag" && depth < 1000; depth++) {
719
+ const header = tagHeader(decodeGitPath(current.bytes));
720
+ if (!header.object || !header.type) return undefined;
721
+ const next = await this.source.readObject(header.object);
722
+ if (!next) return undefined;
723
+ if (next.type !== header.type) {
724
+ // object_as_type: the object was looked up as the type the tag declares
725
+ throw new RefFilterError(
726
+ `error: object ${header.object} is a ${header.type}, not a ${next.type}\nfatal: bad tag`,
727
+ 128,
728
+ );
729
+ }
730
+ current = next;
731
+ currentId = header.object;
732
+ }
733
+ return currentId;
734
+ }
735
+
736
+ private async showRef(option: UsedAtom["refname"], name: string): Promise<string> {
737
+ switch (option?.option) {
738
+ case "short": {
739
+ const warn = this.source.config("core.warnAmbiguousRefs");
740
+ const strict = warn === undefined ? true : parseBool(warn);
741
+ return shortenRefName(name, strict, (n) => this.source.refExists(n));
742
+ }
743
+ case "lstrip":
744
+ return lstripRef(name, option.lstrip ?? 0);
745
+ case "rstrip":
746
+ return rstripRef(name, option.rstrip ?? 0);
747
+ default:
748
+ return name;
749
+ }
750
+ }
751
+
752
+ /** fill_remote_ref_details. */
753
+ private async remoteDetails(
754
+ atom: UsedAtom,
755
+ ref: string | undefined,
756
+ branchRef: string,
757
+ branch: string,
758
+ ): Promise<string> {
759
+ const remote = atom.remote as NonNullable<UsedAtom["remote"]>;
760
+ const source = this.source;
761
+ const stat = async (): Promise<{ ahead: number; behind: number } | undefined> => {
762
+ const base = remote.push ? await source.pushOf(branch) : await source.upstreamOf(branch);
763
+ if (!base) return undefined;
764
+ const theirs = await source.refCommit(base);
765
+ const ours = theirs ? await source.refCommit(branchRef) : undefined;
766
+ if (!theirs || !ours) return undefined;
767
+ if (theirs === ours) return { ahead: 0, behind: 0 };
768
+ return source.aheadBehind(ours, theirs);
769
+ };
770
+ switch (remote.option) {
771
+ case "ref":
772
+ return this.showRef(atom.refname, ref ?? "");
773
+ case "track": {
774
+ const counts = await stat();
775
+ let s: string;
776
+ if (!counts) s = "gone";
777
+ else if (!counts.ahead && !counts.behind) s = "";
778
+ else if (!counts.ahead) s = `behind ${counts.behind}`;
779
+ else if (!counts.behind) s = `ahead ${counts.ahead}`;
780
+ else s = `ahead ${counts.ahead}, behind ${counts.behind}`;
781
+ return !remote.nobracket && s ? `[${s}]` : s;
782
+ }
783
+ case "trackshort": {
784
+ const counts = await stat();
785
+ if (!counts) return "";
786
+ if (!counts.ahead && !counts.behind) return "=";
787
+ if (!counts.ahead) return "<";
788
+ if (!counts.behind) return ">";
789
+ return "<>";
790
+ }
791
+ case "remotename":
792
+ return source.remoteName(branch, remote.push);
793
+ case "remoteref":
794
+ return source.remoteRef(branch, remote.push) ?? "";
795
+ }
796
+ }
797
+
798
+ private async oidText(id: ObjectId, atom: UsedAtom): Promise<string> {
799
+ switch (atom.oid?.option) {
800
+ case "short":
801
+ return this.source.abbreviate(id);
802
+ case "length":
803
+ return this.source.abbreviate(id, atom.oid.length);
804
+ default:
805
+ return id;
806
+ }
807
+ }
808
+
809
+ /** grab_values (and grab_common_values) of one object, the ref's own or the peeled one. */
810
+ private async grabValues(
811
+ values: AtomValue[],
812
+ deref: boolean,
813
+ id: ObjectId,
814
+ object: RefFormatObject,
815
+ refname: string,
816
+ ): Promise<void> {
817
+ const mine = values.filter((v) => v.atom.deref === deref);
818
+ if (mine.length === 0) return;
819
+ const buf = decodeGitPath(object.bytes);
820
+ // common values
821
+ for (const v of mine) {
822
+ const atom = v.atom;
823
+ if (atom.type === "objecttype") v.s = object.type;
824
+ else if (atom.type === "objectsize") {
825
+ if (atom.objectsize === "disk") {
826
+ throw fatal(`%(${atom.name}) is not supported: object disk sizes are not available`);
827
+ }
828
+ v.value = object.bytes.length;
829
+ v.s = String(object.bytes.length);
830
+ } else if (atom.type === "deltabase") {
831
+ throw fatal(`%(${atom.name}) is not supported: delta bases are not available`);
832
+ } else if (atom.type === "objectname" && deref) v.s = await this.oidText(id, atom);
833
+ }
834
+ if (object.type === "tag") {
835
+ const header = tagHeader(buf);
836
+ if (!header.object || !header.type || header.tag === undefined) {
837
+ throw fatal(`parse_object_buffer failed on ${id} for ${refname}`);
838
+ }
839
+ for (const v of mine) {
840
+ if (v.atom.type === "tag") v.s = header.tag;
841
+ else if (v.atom.type === "type") v.s = header.type;
842
+ else if (v.atom.type === "object") v.s = header.object;
843
+ }
844
+ await this.grabContents(mine, object, buf);
845
+ await this.grabPerson("tagger", mine, buf);
846
+ await this.grabDescribe(mine, id, object);
847
+ } else if (object.type === "commit") {
848
+ const links = commitLinks(buf);
849
+ for (const v of mine) {
850
+ const atom = v.atom;
851
+ if (atom.type === "tree" && links.tree) v.s = await this.oidText(links.tree, atom);
852
+ else if (atom.type === "numparent") {
853
+ v.value = links.parents.length;
854
+ v.s = String(links.parents.length);
855
+ } else if (atom.type === "parent") {
856
+ const parts: string[] = [];
857
+ for (const p of links.parents) parts.push(await this.oidText(p, atom));
858
+ v.s = parts.join(" ");
859
+ }
860
+ }
861
+ await this.grabContents(mine, object, buf);
862
+ await this.grabPerson("author", mine, buf);
863
+ await this.grabPerson("committer", mine, buf);
864
+ this.grabSignature(mine, buf);
865
+ await this.grabDescribe(mine, id, object);
866
+ } else {
867
+ await this.grabContents(mine, object, buf);
868
+ }
869
+ }
870
+
871
+ /** grab_sub_body_contents. */
872
+ private async grabContents(values: AtomValue[], object: RefFormatObject, buf: string) {
873
+ let pos: SubPos | undefined;
874
+ for (const v of values) {
875
+ const atom = v.atom;
876
+ if (atom.type === "raw") {
877
+ if (atom.raw === "bare") {
878
+ v.s = buf;
879
+ v.sized = true;
880
+ } else {
881
+ v.value = object.bytes.length;
882
+ v.s = String(object.bytes.length);
883
+ }
884
+ continue;
885
+ }
886
+ if (object.type !== "tag" && object.type !== "commit") continue;
887
+ if (!["body", "subject", "trailers", "contents"].includes(atom.type)) continue;
888
+ pos ??= findSubpos(buf);
889
+ const { sub, sublen, body, nonsiglen, sig } = pos;
890
+ const text = pos.buf;
891
+ switch (atom.contents?.option) {
892
+ case "sub":
893
+ v.s = copySubject(text.slice(sub, sub + sublen));
894
+ break;
895
+ case "sub-sanitize":
896
+ v.s = sanitizedSubject(text.slice(sub, sub + sublen));
897
+ break;
898
+ case "body-dep":
899
+ v.s = text.slice(body);
900
+ break;
901
+ case "length":
902
+ v.value = encodeGitPath(text.slice(sub)).length;
903
+ v.s = String(v.value);
904
+ break;
905
+ case "body":
906
+ v.s = text.slice(body, body + nonsiglen);
907
+ break;
908
+ case "sig":
909
+ v.s = text.slice(sig);
910
+ break;
911
+ case "lines":
912
+ v.s = appendLines(text.slice(sub, body + nonsiglen), atom.contents.lines ?? 0);
913
+ break;
914
+ case "trailers": {
915
+ const msg = sig < text.length && this.peelNested ? text.slice(sub, sig) : text.slice(sub);
916
+ v.s = appendTrailers("", msg, atom.contents.trailers ?? {}, this.source.trailerConfig());
917
+ break;
918
+ }
919
+ case "bare":
920
+ v.s = text.slice(sub);
921
+ break;
922
+ }
923
+ }
924
+ }
925
+
926
+ /** grab_person: `who`'s name, email, date, line, and the creator atoms. */
927
+ private async grabPerson(
928
+ who: "author" | "committer" | "tagger",
929
+ values: AtomValue[],
930
+ buf: string,
931
+ ) {
932
+ let wholine: string | undefined;
933
+ for (const v of values) {
934
+ const atom = v.atom;
935
+ const base = atom.type.startsWith(who) ? atom.type.slice(who.length) : undefined;
936
+ if (base === undefined || !["", "name", "email", "date"].includes(base)) continue;
937
+ const mapped =
938
+ (base === "name" && atom.nameMailmap) || (base === "email" && atom.email?.mailmap);
939
+ if (mapped) {
940
+ this.mailmapLoad ??= this.source.mailmap();
941
+ const mailmap = await this.mailmapLoad;
942
+ const line = findWholine(who, buf);
943
+ wholine = line === "" ? "" : mailmapLine(line, mailmap);
944
+ } else wholine = findWholine(who, buf);
945
+ if (base === "") v.s = wholine;
946
+ else if (base === "name") v.s = copyName(wholine);
947
+ else if (base === "email")
948
+ v.s = copyEmail(wholine, atom.email as NonNullable<UsedAtom["email"]>);
949
+ else this.grabDate(wholine, v);
950
+ }
951
+ if (who !== "tagger" && who !== "committer") return;
952
+ wholine ??= findWholine(who, buf);
953
+ for (const v of values) {
954
+ if (v.atom.type === "creatordate") this.grabDate(wholine, v);
955
+ else if (v.atom.type === "creator") v.s = wholine;
956
+ }
957
+ }
958
+
959
+ /** grab_date: the date of an identity line as the atom's format shows it. */
960
+ private grabDate(line: string, v: AtomValue): void {
961
+ const name = v.atom.deref ? v.atom.name.slice(1) : v.atom.name;
962
+ const colon = name.indexOf(":");
963
+ let mode: DateMode = { type: "normal", local: false };
964
+ if (colon >= 0) {
965
+ const spec = name.slice(colon + 1);
966
+ let parsed = this.dateModes.get(spec);
967
+ if (!parsed) {
968
+ try {
969
+ parsed = parseDateMode(spec);
970
+ } catch (e) {
971
+ throw new RefFilterError((e as Error).message, 128);
972
+ }
973
+ this.dateModes.set(spec, parsed);
974
+ }
975
+ mode = parsed;
976
+ // a formatted date sorts as text (git 2.43: by its time still)
977
+ if (this.peelNested) v.atom.cmpType = "str";
978
+ }
979
+ const eoemail = line.indexOf("> ");
980
+ const m = eoemail >= 0 ? /^[ \t\n\v\f\r]*\+?(\d+)(.*)$/s.exec(line.slice(eoemail + 2)) : null;
981
+ if (!m) {
982
+ v.s = "";
983
+ v.value = 0;
984
+ return;
985
+ }
986
+ const timestamp = Number(m[1]);
987
+ const zone = /^[ \t\n\v\f\r]*([+-]?\d+)/.exec(m[2] as string)?.[1] ?? "+0000";
988
+ const tz = Number.parseInt(zone, 10);
989
+ const tzText = `${tz < 0 ? "-" : "+"}${String(Math.abs(tz)).padStart(4, "0")}`;
990
+ v.s = showDate(timestamp, tzText, mode, this.source.dateContext);
991
+ v.value = timestamp;
992
+ }
993
+
994
+ /** grab_signature for an unsigned commit; a signed one cannot be verified here. */
995
+ private grabSignature(values: AtomValue[], buf: string): void {
996
+ const atoms = values.filter((v) => v.atom.type === "signature");
997
+ if (atoms.length === 0) return;
998
+ const header = buf.slice(0, Math.max(buf.indexOf("\n\n"), 0));
999
+ if (/(^|\n)gpgsig(-sha256)? /.test(header)) {
1000
+ throw fatal("%(signature) is not supported: signatures cannot be verified");
1001
+ }
1002
+ for (const v of atoms) {
1003
+ const option = v.atom.signature;
1004
+ v.s = option === "grade" ? "N" : option === "trustlevel" ? "undefined" : "";
1005
+ }
1006
+ }
1007
+
1008
+ private async grabDescribe(values: AtomValue[], id: ObjectId, object: RefFormatObject) {
1009
+ for (const v of values) {
1010
+ if (v.atom.type !== "describe") continue;
1011
+ let target = id;
1012
+ if (object.type === "tag") target = (await this.peel(id, object)) ?? id;
1013
+ const out = await this.source.describe(
1014
+ target,
1015
+ v.atom.describe as NonNullable<UsedAtom["describe"]>,
1016
+ );
1017
+ v.s = out.replace(/[ \t\n\v\f\r]+$/, "");
1018
+ }
1019
+ }
1020
+ }
1021
+
1022
+ function parseBool(value: string): boolean {
1023
+ const v = value.toLowerCase();
1024
+ if (v === "true" || v === "yes" || v === "on") return true;
1025
+ if (v === "false" || v === "no" || v === "off" || v === "") return false;
1026
+ return Number(v) !== 0;
1027
+ }
1028
+
1029
+ /** find_next: the next `%(` not escaped as `%%`. */
1030
+ function findNext(format: string, from: number): number {
1031
+ for (let i = from; i < format.length; i++) {
1032
+ if (format[i] === "%") {
1033
+ if (format[i + 1] === "(") return i;
1034
+ if (format[i + 1] === "%") i++;
1035
+ }
1036
+ }
1037
+ return -1;
1038
+ }
1039
+
1040
+ /** The handlers of `%(end)`: align's padding, if/then/else's choice. */
1041
+ function endHandler(cur: Stack): Stack {
1042
+ if (cur.atEnd === "align") {
1043
+ const align = cur.align as NonNullable<UsedAtom["align"]>;
1044
+ const nul = cur.output.indexOf("\0");
1045
+ const s = nul >= 0 ? cur.output.slice(0, nul) : cur.output;
1046
+ const width = textWidth(s);
1047
+ if (width >= align.width) cur.output = s;
1048
+ else if (align.position === "left") cur.output = s + " ".repeat(align.width - width);
1049
+ else if (align.position === "right") cur.output = " ".repeat(align.width - width) + s;
1050
+ else {
1051
+ const left = Math.floor((align.width - width) / 2);
1052
+ cur.output = " ".repeat(left) + s + " ".repeat(align.width - width - left);
1053
+ }
1054
+ return cur;
1055
+ }
1056
+ const state = cur.ifState as IfState;
1057
+ if (!state.thenSeen) throw fatal("format: %(if) atom used without a %(then) atom");
1058
+ if (state.elseSeen) {
1059
+ const prev = cur.prev as Stack;
1060
+ if (state.satisfied) {
1061
+ prev.output += "";
1062
+ return prev;
1063
+ }
1064
+ // the else branch's text replaces the then branch's
1065
+ prev.output = cur.output;
1066
+ return prev;
1067
+ }
1068
+ if (!state.satisfied) cur.output = "";
1069
+ return cur;
1070
+ }