@statewalker/vcs-commands 0.5.0 → 0.6.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 (546) hide show
  1. package/README.md +123 -8
  2. package/dist/commands/add-command.d.ts +265 -34
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/add-patch/add-interactive.d.ts +46 -0
  5. package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
  6. package/dist/commands/add-patch/add-patch.d.ts +139 -0
  7. package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
  8. package/dist/commands/add-patch/index.d.ts +6 -0
  9. package/dist/commands/add-patch/index.d.ts.map +1 -0
  10. package/dist/commands/add-patch/patch-backend.d.ts +80 -0
  11. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
  12. package/dist/commands/add-patch/patch-modes.d.ts +71 -0
  13. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
  14. package/dist/commands/add-patch/patch-session.d.ts +49 -0
  15. package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
  16. package/dist/commands/am/am-command.d.ts +175 -0
  17. package/dist/commands/am/am-command.d.ts.map +1 -0
  18. package/dist/commands/am/index.d.ts +3 -0
  19. package/dist/commands/am/index.d.ts.map +1 -0
  20. package/dist/commands/am/mailinfo.d.ts +58 -0
  21. package/dist/commands/am/mailinfo.d.ts.map +1 -0
  22. package/dist/commands/am/patch-format.d.ts +24 -0
  23. package/dist/commands/am/patch-format.d.ts.map +1 -0
  24. package/dist/commands/apply/apply-command.d.ts +153 -0
  25. package/dist/commands/apply/apply-command.d.ts.map +1 -0
  26. package/dist/commands/apply/apply-engine.d.ts +195 -0
  27. package/dist/commands/apply/apply-engine.d.ts.map +1 -0
  28. package/dist/commands/apply/apply-parse.d.ts +86 -0
  29. package/dist/commands/apply/apply-parse.d.ts.map +1 -0
  30. package/dist/commands/apply/apply-types.d.ts +70 -0
  31. package/dist/commands/apply/apply-types.d.ts.map +1 -0
  32. package/dist/commands/apply/index.d.ts +6 -0
  33. package/dist/commands/apply/index.d.ts.map +1 -0
  34. package/dist/commands/apply/latin1.d.ts +32 -0
  35. package/dist/commands/apply/latin1.d.ts.map +1 -0
  36. package/dist/commands/apply/whitespace.d.ts +58 -0
  37. package/dist/commands/apply/whitespace.d.ts.map +1 -0
  38. package/dist/commands/attributes-source.d.ts +26 -0
  39. package/dist/commands/attributes-source.d.ts.map +1 -0
  40. package/dist/commands/backfill-command.d.ts +110 -0
  41. package/dist/commands/backfill-command.d.ts.map +1 -0
  42. package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
  43. package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
  44. package/dist/commands/bisect/bisect-command.d.ts +201 -0
  45. package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
  46. package/dist/commands/bisect/bisect-engine.d.ts +219 -0
  47. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
  48. package/dist/commands/bisect/bisect-graph.d.ts +127 -0
  49. package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
  50. package/dist/commands/bisect/bisect-quote.d.ts +27 -0
  51. package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
  52. package/dist/commands/bisect/index.d.ts +5 -0
  53. package/dist/commands/bisect/index.d.ts.map +1 -0
  54. package/dist/commands/blame-command.d.ts +122 -131
  55. package/dist/commands/blame-command.d.ts.map +1 -1
  56. package/dist/commands/branch-command.d.ts +52 -2
  57. package/dist/commands/branch-command.d.ts.map +1 -1
  58. package/dist/commands/branch-tracking.d.ts +98 -0
  59. package/dist/commands/branch-tracking.d.ts.map +1 -0
  60. package/dist/commands/checkout-command.d.ts +300 -18
  61. package/dist/commands/checkout-command.d.ts.map +1 -1
  62. package/dist/commands/checkout-paths.d.ts +124 -0
  63. package/dist/commands/checkout-paths.d.ts.map +1 -0
  64. package/dist/commands/cherry-pick-command.d.ts +50 -42
  65. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  66. package/dist/commands/clean-command.d.ts +49 -16
  67. package/dist/commands/clean-command.d.ts.map +1 -1
  68. package/dist/commands/clone-command.d.ts +117 -0
  69. package/dist/commands/clone-command.d.ts.map +1 -1
  70. package/dist/commands/commit-command.d.ts +311 -17
  71. package/dist/commands/commit-command.d.ts.map +1 -1
  72. package/dist/commands/core-config.d.ts +78 -1
  73. package/dist/commands/core-config.d.ts.map +1 -1
  74. package/dist/commands/date-format.d.ts +58 -0
  75. package/dist/commands/date-format.d.ts.map +1 -0
  76. package/dist/commands/describe-command.d.ts.map +1 -1
  77. package/dist/commands/diff-command.d.ts +377 -30
  78. package/dist/commands/diff-command.d.ts.map +1 -1
  79. package/dist/commands/diff-textconv.d.ts +40 -0
  80. package/dist/commands/diff-textconv.d.ts.map +1 -0
  81. package/dist/commands/fetch-command.d.ts +149 -10
  82. package/dist/commands/fetch-command.d.ts.map +1 -1
  83. package/dist/commands/format-patch-command.d.ts +164 -0
  84. package/dist/commands/format-patch-command.d.ts.map +1 -0
  85. package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
  86. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
  87. package/dist/commands/fsck/fsck-command.d.ts +225 -0
  88. package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
  89. package/dist/commands/fsck/fsck-loose.d.ts +68 -0
  90. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
  91. package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
  92. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
  93. package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
  94. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
  95. package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
  96. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
  97. package/dist/commands/fsck/fsck-pack.d.ts +115 -0
  98. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
  99. package/dist/commands/fsck/index.d.ts +6 -0
  100. package/dist/commands/fsck/index.d.ts.map +1 -0
  101. package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
  102. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
  103. package/dist/commands/gc-command.d.ts +43 -0
  104. package/dist/commands/gc-command.d.ts.map +1 -1
  105. package/dist/commands/git-date.d.ts +66 -0
  106. package/dist/commands/git-date.d.ts.map +1 -0
  107. package/dist/commands/git-describe.d.ts +67 -0
  108. package/dist/commands/git-describe.d.ts.map +1 -0
  109. package/dist/commands/git-hooks.d.ts +416 -0
  110. package/dist/commands/git-hooks.d.ts.map +1 -0
  111. package/dist/commands/git-ident.d.ts +128 -0
  112. package/dist/commands/git-ident.d.ts.map +1 -0
  113. package/dist/commands/hook-command.d.ts +96 -0
  114. package/dist/commands/hook-command.d.ts.map +1 -0
  115. package/dist/commands/index-adder.d.ts +231 -0
  116. package/dist/commands/index-adder.d.ts.map +1 -0
  117. package/dist/commands/index-host.d.ts +86 -0
  118. package/dist/commands/index-host.d.ts.map +1 -0
  119. package/dist/commands/index.d.ts +54 -0
  120. package/dist/commands/index.d.ts.map +1 -1
  121. package/dist/commands/index.js +3 -2
  122. package/dist/commands/init-command.d.ts +12 -1
  123. package/dist/commands/init-command.d.ts.map +1 -1
  124. package/dist/commands/local-clone.d.ts +60 -0
  125. package/dist/commands/local-clone.d.ts.map +1 -0
  126. package/dist/commands/local-transport.d.ts +117 -0
  127. package/dist/commands/local-transport.d.ts.map +1 -0
  128. package/dist/commands/log-command.d.ts +216 -24
  129. package/dist/commands/log-command.d.ts.map +1 -1
  130. package/dist/commands/log-graph.d.ts +120 -0
  131. package/dist/commands/log-graph.d.ts.map +1 -0
  132. package/dist/commands/log-output.d.ts +323 -0
  133. package/dist/commands/log-output.d.ts.map +1 -0
  134. package/dist/commands/ls-remote-command.d.ts +23 -7
  135. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  136. package/dist/commands/mailmap.d.ts +31 -0
  137. package/dist/commands/mailmap.d.ts.map +1 -0
  138. package/dist/commands/merge-bases.d.ts +85 -0
  139. package/dist/commands/merge-bases.d.ts.map +1 -0
  140. package/dist/commands/merge-command.d.ts +209 -74
  141. package/dist/commands/merge-command.d.ts.map +1 -1
  142. package/dist/commands/merge-config.d.ts +13 -0
  143. package/dist/commands/merge-config.d.ts.map +1 -0
  144. package/dist/commands/merge-drivers.d.ts +130 -0
  145. package/dist/commands/merge-drivers.d.ts.map +1 -0
  146. package/dist/commands/merge-support.d.ts +252 -0
  147. package/dist/commands/merge-support.d.ts.map +1 -0
  148. package/dist/commands/message-cleanup.d.ts +86 -0
  149. package/dist/commands/message-cleanup.d.ts.map +1 -0
  150. package/dist/commands/mv-command.d.ts +94 -0
  151. package/dist/commands/mv-command.d.ts.map +1 -0
  152. package/dist/commands/notes-command.d.ts +256 -0
  153. package/dist/commands/notes-command.d.ts.map +1 -0
  154. package/dist/commands/notes-commands.d.ts +41 -0
  155. package/dist/commands/notes-commands.d.ts.map +1 -0
  156. package/dist/commands/notes-merge-command.d.ts +105 -0
  157. package/dist/commands/notes-merge-command.d.ts.map +1 -0
  158. package/dist/commands/notes-support.d.ts +125 -0
  159. package/dist/commands/notes-support.d.ts.map +1 -0
  160. package/dist/commands/notes-tree.d.ts +106 -0
  161. package/dist/commands/notes-tree.d.ts.map +1 -0
  162. package/dist/commands/object-id-input.d.ts +20 -0
  163. package/dist/commands/object-id-input.d.ts.map +1 -0
  164. package/dist/commands/octopus-merge.d.ts +59 -0
  165. package/dist/commands/octopus-merge.d.ts.map +1 -0
  166. package/dist/commands/ort-merge.d.ts +126 -0
  167. package/dist/commands/ort-merge.d.ts.map +1 -0
  168. package/dist/commands/ort-recursive.d.ts +53 -0
  169. package/dist/commands/ort-recursive.d.ts.map +1 -0
  170. package/dist/commands/pack-refs-command.d.ts +20 -0
  171. package/dist/commands/pack-refs-command.d.ts.map +1 -1
  172. package/dist/commands/patch-id.d.ts +41 -0
  173. package/dist/commands/patch-id.d.ts.map +1 -0
  174. package/dist/commands/pathspec-attributes.d.ts +64 -0
  175. package/dist/commands/pathspec-attributes.d.ts.map +1 -0
  176. package/dist/commands/pathspec.d.ts +324 -0
  177. package/dist/commands/pathspec.d.ts.map +1 -0
  178. package/dist/commands/post-index-change.d.ts +33 -0
  179. package/dist/commands/post-index-change.d.ts.map +1 -0
  180. package/dist/commands/pretty-format.d.ts +222 -0
  181. package/dist/commands/pretty-format.d.ts.map +1 -0
  182. package/dist/commands/promisor-remote.d.ts +80 -0
  183. package/dist/commands/promisor-remote.d.ts.map +1 -0
  184. package/dist/commands/pull-command.d.ts +41 -8
  185. package/dist/commands/pull-command.d.ts.map +1 -1
  186. package/dist/commands/push-command.d.ts +24 -8
  187. package/dist/commands/push-command.d.ts.map +1 -1
  188. package/dist/commands/read-tree-command.d.ts +112 -0
  189. package/dist/commands/read-tree-command.d.ts.map +1 -0
  190. package/dist/commands/rebase-command.d.ts +507 -75
  191. package/dist/commands/rebase-command.d.ts.map +1 -1
  192. package/dist/commands/rebase-todo.d.ts +130 -0
  193. package/dist/commands/rebase-todo.d.ts.map +1 -0
  194. package/dist/commands/ref-decoration-filter.d.ts +53 -0
  195. package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
  196. package/dist/commands/reflog-messages.d.ts +98 -0
  197. package/dist/commands/reflog-messages.d.ts.map +1 -0
  198. package/dist/commands/remote-command.d.ts +31 -0
  199. package/dist/commands/remote-command.d.ts.map +1 -1
  200. package/dist/commands/remote-transport.d.ts +120 -0
  201. package/dist/commands/remote-transport.d.ts.map +1 -0
  202. package/dist/commands/reset-command.d.ts +161 -7
  203. package/dist/commands/reset-command.d.ts.map +1 -1
  204. package/dist/commands/restore-command.d.ts +103 -0
  205. package/dist/commands/restore-command.d.ts.map +1 -0
  206. package/dist/commands/rev-list-command.d.ts +78 -0
  207. package/dist/commands/rev-list-command.d.ts.map +1 -0
  208. package/dist/commands/rev-parse-command.d.ts +80 -0
  209. package/dist/commands/rev-parse-command.d.ts.map +1 -0
  210. package/dist/commands/revert-command.d.ts +46 -38
  211. package/dist/commands/revert-command.d.ts.map +1 -1
  212. package/dist/commands/revision-filenames.d.ts +95 -0
  213. package/dist/commands/revision-filenames.d.ts.map +1 -0
  214. package/dist/commands/revision-range.d.ts +67 -0
  215. package/dist/commands/revision-range.d.ts.map +1 -0
  216. package/dist/commands/revision-resolver.d.ts +321 -0
  217. package/dist/commands/revision-resolver.d.ts.map +1 -0
  218. package/dist/commands/rm-command.d.ts +69 -7
  219. package/dist/commands/rm-command.d.ts.map +1 -1
  220. package/dist/commands/sequencer-pick.d.ts +191 -0
  221. package/dist/commands/sequencer-pick.d.ts.map +1 -0
  222. package/dist/commands/sequencer-support.d.ts +125 -0
  223. package/dist/commands/sequencer-support.d.ts.map +1 -0
  224. package/dist/commands/serve-repository.d.ts +52 -0
  225. package/dist/commands/serve-repository.d.ts.map +1 -0
  226. package/dist/commands/sparse-checkout-command.d.ts +190 -0
  227. package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
  228. package/dist/commands/sparse-checkout-support.d.ts +268 -0
  229. package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
  230. package/dist/commands/stash-apply-command.d.ts +42 -8
  231. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  232. package/dist/commands/stash-create-command.d.ts +155 -1
  233. package/dist/commands/stash-create-command.d.ts.map +1 -1
  234. package/dist/commands/stash-drop-command.d.ts +2 -0
  235. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  236. package/dist/commands/stash-working-tree.d.ts +23 -0
  237. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  238. package/dist/commands/status-command.d.ts +300 -15
  239. package/dist/commands/status-command.d.ts.map +1 -1
  240. package/dist/commands/status-format.d.ts +155 -0
  241. package/dist/commands/status-format.d.ts.map +1 -0
  242. package/dist/commands/status-header.d.ts +64 -0
  243. package/dist/commands/status-header.d.ts.map +1 -0
  244. package/dist/commands/strerror.d.ts +7 -0
  245. package/dist/commands/strerror.d.ts.map +1 -0
  246. package/dist/commands/submodule-config.d.ts +38 -0
  247. package/dist/commands/submodule-config.d.ts.map +1 -0
  248. package/dist/commands/submodule-summary-command.d.ts +80 -0
  249. package/dist/commands/submodule-summary-command.d.ts.map +1 -0
  250. package/dist/commands/submodule-summary.d.ts +150 -0
  251. package/dist/commands/submodule-summary.d.ts.map +1 -0
  252. package/dist/commands/switch-command.d.ts +132 -0
  253. package/dist/commands/switch-command.d.ts.map +1 -0
  254. package/dist/commands/tag-command.d.ts +23 -2
  255. package/dist/commands/tag-command.d.ts.map +1 -1
  256. package/dist/commands/tracking-info.d.ts +64 -0
  257. package/dist/commands/tracking-info.d.ts.map +1 -0
  258. package/dist/commands/trailers.d.ts +73 -0
  259. package/dist/commands/trailers.d.ts.map +1 -0
  260. package/dist/commands/tree-restore.d.ts +85 -1
  261. package/dist/commands/tree-restore.d.ts.map +1 -1
  262. package/dist/commands/untracked-cache-support.d.ts +53 -0
  263. package/dist/commands/untracked-cache-support.d.ts.map +1 -0
  264. package/dist/commands/worktree-add-command.d.ts +108 -0
  265. package/dist/commands/worktree-add-command.d.ts.map +1 -0
  266. package/dist/commands/worktree-list-command.d.ts +69 -0
  267. package/dist/commands/worktree-list-command.d.ts.map +1 -0
  268. package/dist/commands/worktree-lock-command.d.ts +44 -0
  269. package/dist/commands/worktree-lock-command.d.ts.map +1 -0
  270. package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
  271. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  272. package/dist/commands/worktree-prune-command.d.ts +48 -0
  273. package/dist/commands/worktree-prune-command.d.ts.map +1 -0
  274. package/dist/commands/worktree-remove-command.d.ts +59 -0
  275. package/dist/commands/worktree-remove-command.d.ts.map +1 -0
  276. package/dist/commands/worktree-repair-command.d.ts +35 -0
  277. package/dist/commands/worktree-repair-command.d.ts.map +1 -0
  278. package/dist/commands/worktree-support.d.ts +64 -0
  279. package/dist/commands/worktree-support.d.ts.map +1 -0
  280. package/dist/commands-DnmlfwGV.js +61620 -0
  281. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  282. package/dist/errors/add-errors.d.ts +55 -0
  283. package/dist/errors/add-errors.d.ts.map +1 -1
  284. package/dist/errors/checkout-errors.d.ts +16 -0
  285. package/dist/errors/checkout-errors.d.ts.map +1 -1
  286. package/dist/errors/command-errors.d.ts +77 -0
  287. package/dist/errors/command-errors.d.ts.map +1 -1
  288. package/dist/errors/commit-errors.d.ts +9 -0
  289. package/dist/errors/commit-errors.d.ts.map +1 -1
  290. package/dist/errors/git-api-error.d.ts +59 -2
  291. package/dist/errors/git-api-error.d.ts.map +1 -1
  292. package/dist/errors/index.d.ts +1 -0
  293. package/dist/errors/index.d.ts.map +1 -1
  294. package/dist/errors/index.js +354 -19
  295. package/dist/errors/rebase-errors.d.ts +9 -0
  296. package/dist/errors/rebase-errors.d.ts.map +1 -1
  297. package/dist/errors/ref-errors.d.ts +32 -0
  298. package/dist/errors/ref-errors.d.ts.map +1 -1
  299. package/dist/errors/transport-errors.d.ts +12 -2
  300. package/dist/errors/transport-errors.d.ts.map +1 -1
  301. package/dist/errors/worktree-errors.d.ts +35 -0
  302. package/dist/errors/worktree-errors.d.ts.map +1 -0
  303. package/dist/git-command-DxvwPrPB.js +7612 -0
  304. package/dist/git-command.d.ts +413 -32
  305. package/dist/git-command.d.ts.map +1 -1
  306. package/dist/git.d.ts +306 -3
  307. package/dist/git.d.ts.map +1 -1
  308. package/dist/index.d.ts +1 -1
  309. package/dist/index.d.ts.map +1 -1
  310. package/dist/index.js +5 -5
  311. package/dist/remote-config/remote-config-store.d.ts +105 -3
  312. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  313. package/dist/remote-config/remote-refs.d.ts +7 -3
  314. package/dist/remote-config/remote-refs.d.ts.map +1 -1
  315. package/dist/rename/detect-renames.d.ts +148 -0
  316. package/dist/rename/detect-renames.d.ts.map +1 -0
  317. package/dist/rename/git-similarity.d.ts +44 -0
  318. package/dist/rename/git-similarity.d.ts.map +1 -0
  319. package/dist/rename/index.d.ts +2 -0
  320. package/dist/rename/index.d.ts.map +1 -1
  321. package/dist/results/binary-patch.d.ts +11 -0
  322. package/dist/results/binary-patch.d.ts.map +1 -0
  323. package/dist/results/blame-format.d.ts +55 -0
  324. package/dist/results/blame-format.d.ts.map +1 -0
  325. package/dist/results/cherry-pick-result.d.ts +10 -0
  326. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  327. package/dist/results/clone-result.d.ts +10 -0
  328. package/dist/results/clone-result.d.ts.map +1 -1
  329. package/dist/results/combined-diff.d.ts +77 -0
  330. package/dist/results/combined-diff.d.ts.map +1 -0
  331. package/dist/results/diff-entry.d.ts +32 -0
  332. package/dist/results/diff-entry.d.ts.map +1 -1
  333. package/dist/results/diff-formatter.d.ts +34 -60
  334. package/dist/results/diff-formatter.d.ts.map +1 -1
  335. package/dist/results/diff-order.d.ts +25 -0
  336. package/dist/results/diff-order.d.ts.map +1 -0
  337. package/dist/results/diff-output.d.ts +249 -0
  338. package/dist/results/diff-output.d.ts.map +1 -0
  339. package/dist/results/fetch-result.d.ts +15 -0
  340. package/dist/results/fetch-result.d.ts.map +1 -1
  341. package/dist/results/index.d.ts +5 -0
  342. package/dist/results/index.d.ts.map +1 -1
  343. package/dist/results/index.js +2 -252
  344. package/dist/results/merge-result.d.ts +15 -1
  345. package/dist/results/merge-result.d.ts.map +1 -1
  346. package/dist/results/pull-result.d.ts +12 -3
  347. package/dist/results/pull-result.d.ts.map +1 -1
  348. package/dist/results/push-result.d.ts +42 -0
  349. package/dist/results/push-result.d.ts.map +1 -1
  350. package/dist/results/quote-path.d.ts +27 -0
  351. package/dist/results/quote-path.d.ts.map +1 -0
  352. package/dist/results/rebase-result.d.ts +28 -1
  353. package/dist/results/rebase-result.d.ts.map +1 -1
  354. package/dist/results/revert-result.d.ts +10 -0
  355. package/dist/results/revert-result.d.ts.map +1 -1
  356. package/dist/results/stash-result.d.ts +5 -0
  357. package/dist/results/stash-result.d.ts.map +1 -1
  358. package/dist/results/status-result.d.ts +60 -6
  359. package/dist/results/status-result.d.ts.map +1 -1
  360. package/dist/results-BZGa2Z3I.js +2934 -0
  361. package/dist/transport-command.d.ts +44 -1
  362. package/dist/transport-command.d.ts.map +1 -1
  363. package/package.json +15 -11
  364. package/src/commands/add-command.ts +1291 -226
  365. package/src/commands/add-patch/add-interactive.ts +941 -0
  366. package/src/commands/add-patch/add-patch.ts +1169 -0
  367. package/src/commands/add-patch/index.ts +5 -0
  368. package/src/commands/add-patch/patch-backend.ts +239 -0
  369. package/src/commands/add-patch/patch-modes.ts +249 -0
  370. package/src/commands/add-patch/patch-session.ts +159 -0
  371. package/src/commands/am/am-command.ts +1111 -0
  372. package/src/commands/am/index.ts +2 -0
  373. package/src/commands/am/mailinfo.ts +1015 -0
  374. package/src/commands/am/patch-format.ts +121 -0
  375. package/src/commands/apply/apply-command.ts +832 -0
  376. package/src/commands/apply/apply-engine.ts +1603 -0
  377. package/src/commands/apply/apply-parse.ts +1209 -0
  378. package/src/commands/apply/apply-types.ts +112 -0
  379. package/src/commands/apply/index.ts +5 -0
  380. package/src/commands/apply/latin1.ts +171 -0
  381. package/src/commands/apply/whitespace.ts +260 -0
  382. package/src/commands/attributes-source.ts +96 -0
  383. package/src/commands/backfill-command.ts +694 -0
  384. package/src/commands/bisect/bisect-checkout.ts +217 -0
  385. package/src/commands/bisect/bisect-command.ts +788 -0
  386. package/src/commands/bisect/bisect-engine.ts +1079 -0
  387. package/src/commands/bisect/bisect-graph.ts +595 -0
  388. package/src/commands/bisect/bisect-quote.ts +92 -0
  389. package/src/commands/bisect/index.ts +4 -0
  390. package/src/commands/blame-command.ts +711 -986
  391. package/src/commands/branch-command.ts +354 -32
  392. package/src/commands/branch-tracking.ts +331 -0
  393. package/src/commands/checkout-command.ts +1290 -243
  394. package/src/commands/checkout-paths.ts +784 -0
  395. package/src/commands/cherry-pick-command.ts +156 -396
  396. package/src/commands/clean-command.ts +504 -156
  397. package/src/commands/clone-command.ts +634 -67
  398. package/src/commands/commit-command.ts +1781 -166
  399. package/src/commands/core-config.ts +161 -6
  400. package/src/commands/date-format.ts +668 -0
  401. package/src/commands/describe-command.ts +2 -0
  402. package/src/commands/diff-command.ts +1898 -110
  403. package/src/commands/diff-textconv.ts +50 -0
  404. package/src/commands/fetch-command.ts +606 -66
  405. package/src/commands/format-patch-command.ts +969 -0
  406. package/src/commands/fsck/fetch-fsck.ts +229 -0
  407. package/src/commands/fsck/fsck-command.ts +3347 -0
  408. package/src/commands/fsck/fsck-loose.ts +287 -0
  409. package/src/commands/fsck/fsck-msg-ids.ts +176 -0
  410. package/src/commands/fsck/fsck-object-checks.ts +1044 -0
  411. package/src/commands/fsck/fsck-object-table.ts +363 -0
  412. package/src/commands/fsck/fsck-pack.ts +604 -0
  413. package/src/commands/fsck/index.ts +5 -0
  414. package/src/commands/fsck/verify-pack-command.ts +249 -0
  415. package/src/commands/gc-command.ts +147 -1
  416. package/src/commands/git-date.ts +895 -0
  417. package/src/commands/git-describe.ts +316 -0
  418. package/src/commands/git-hooks.ts +1472 -0
  419. package/src/commands/git-ident.ts +344 -0
  420. package/src/commands/hook-command.ts +247 -0
  421. package/src/commands/index-adder.ts +706 -0
  422. package/src/commands/index-host.ts +291 -0
  423. package/src/commands/index.ts +82 -0
  424. package/src/commands/init-command.ts +28 -4
  425. package/src/commands/local-clone.ts +183 -0
  426. package/src/commands/local-transport.ts +762 -0
  427. package/src/commands/log-command.ts +1915 -170
  428. package/src/commands/log-graph.ts +671 -0
  429. package/src/commands/log-output.ts +1359 -0
  430. package/src/commands/ls-remote-command.ts +101 -58
  431. package/src/commands/mailmap.ts +129 -0
  432. package/src/commands/merge-bases.ts +296 -0
  433. package/src/commands/merge-command.ts +1386 -491
  434. package/src/commands/merge-config.ts +25 -0
  435. package/src/commands/merge-drivers.ts +306 -0
  436. package/src/commands/merge-support.ts +1198 -0
  437. package/src/commands/message-cleanup.ts +275 -0
  438. package/src/commands/mv-command.ts +976 -0
  439. package/src/commands/notes-command.ts +890 -0
  440. package/src/commands/notes-commands.ts +87 -0
  441. package/src/commands/notes-merge-command.ts +768 -0
  442. package/src/commands/notes-support.ts +402 -0
  443. package/src/commands/notes-tree.ts +602 -0
  444. package/src/commands/object-id-input.ts +27 -0
  445. package/src/commands/octopus-merge.ts +377 -0
  446. package/src/commands/ort-merge.ts +1660 -0
  447. package/src/commands/ort-recursive.ts +160 -0
  448. package/src/commands/pack-refs-command.ts +39 -22
  449. package/src/commands/patch-id.ts +196 -0
  450. package/src/commands/pathspec-attributes.ts +162 -0
  451. package/src/commands/pathspec.ts +1199 -0
  452. package/src/commands/post-index-change.ts +62 -0
  453. package/src/commands/pretty-format.ts +1431 -0
  454. package/src/commands/promisor-remote.ts +298 -0
  455. package/src/commands/pull-command.ts +207 -22
  456. package/src/commands/push-command.ts +236 -23
  457. package/src/commands/read-tree-command.ts +857 -0
  458. package/src/commands/rebase-command.ts +3808 -371
  459. package/src/commands/rebase-todo.ts +584 -0
  460. package/src/commands/ref-decoration-filter.ts +118 -0
  461. package/src/commands/reflog-messages.ts +177 -0
  462. package/src/commands/remote-command.ts +93 -22
  463. package/src/commands/remote-transport.ts +383 -0
  464. package/src/commands/reset-command.ts +827 -103
  465. package/src/commands/restore-command.ts +350 -0
  466. package/src/commands/rev-list-command.ts +167 -0
  467. package/src/commands/rev-parse-command.ts +277 -0
  468. package/src/commands/revert-command.ts +152 -399
  469. package/src/commands/revision-filenames.ts +254 -0
  470. package/src/commands/revision-range.ts +222 -0
  471. package/src/commands/revision-resolver.ts +1379 -0
  472. package/src/commands/rm-command.ts +613 -67
  473. package/src/commands/sequencer-pick.ts +869 -0
  474. package/src/commands/sequencer-support.ts +869 -0
  475. package/src/commands/serve-repository.ts +125 -0
  476. package/src/commands/sparse-checkout-command.ts +1389 -0
  477. package/src/commands/sparse-checkout-support.ts +793 -0
  478. package/src/commands/stash-apply-command.ts +376 -343
  479. package/src/commands/stash-create-command.ts +625 -42
  480. package/src/commands/stash-drop-command.ts +15 -2
  481. package/src/commands/stash-working-tree.ts +168 -24
  482. package/src/commands/status-command.ts +1328 -105
  483. package/src/commands/status-format.ts +775 -0
  484. package/src/commands/status-header.ts +330 -0
  485. package/src/commands/strerror.ts +29 -0
  486. package/src/commands/submodule-config.ts +94 -0
  487. package/src/commands/submodule-summary-command.ts +334 -0
  488. package/src/commands/submodule-summary.ts +446 -0
  489. package/src/commands/switch-command.ts +402 -0
  490. package/src/commands/tag-command.ts +129 -41
  491. package/src/commands/tracking-info.ts +201 -0
  492. package/src/commands/trailers.ts +417 -0
  493. package/src/commands/tree-restore.ts +204 -4
  494. package/src/commands/untracked-cache-support.ts +194 -0
  495. package/src/commands/worktree-add-command.ts +458 -0
  496. package/src/commands/worktree-list-command.ts +208 -0
  497. package/src/commands/worktree-lock-command.ts +96 -0
  498. package/src/commands/worktree-overwrite-checks.ts +452 -26
  499. package/src/commands/worktree-prune-command.ts +99 -0
  500. package/src/commands/worktree-remove-command.ts +186 -0
  501. package/src/commands/worktree-repair-command.ts +59 -0
  502. package/src/commands/worktree-support.ts +214 -0
  503. package/src/core-commands/add.command.impl.ts +7 -1
  504. package/src/errors/add-errors.ts +45 -0
  505. package/src/errors/checkout-errors.ts +26 -2
  506. package/src/errors/command-errors.ts +101 -1
  507. package/src/errors/commit-errors.ts +18 -2
  508. package/src/errors/git-api-error.ts +82 -2
  509. package/src/errors/index.ts +1 -0
  510. package/src/errors/merge-errors.ts +2 -2
  511. package/src/errors/rebase-errors.ts +12 -0
  512. package/src/errors/ref-errors.ts +56 -2
  513. package/src/errors/remote-errors.ts +2 -2
  514. package/src/errors/stash-errors.ts +1 -1
  515. package/src/errors/transport-errors.ts +20 -4
  516. package/src/errors/worktree-errors.ts +49 -0
  517. package/src/git-command.ts +1177 -118
  518. package/src/git.ts +523 -10
  519. package/src/index.ts +1 -1
  520. package/src/remote-config/remote-config-store.ts +242 -8
  521. package/src/remote-config/remote-refs.ts +22 -6
  522. package/src/rename/detect-renames.ts +711 -0
  523. package/src/rename/git-similarity.ts +116 -0
  524. package/src/rename/index.ts +2 -0
  525. package/src/results/binary-patch.ts +401 -0
  526. package/src/results/blame-format.ts +239 -0
  527. package/src/results/cherry-pick-result.ts +10 -0
  528. package/src/results/clone-result.ts +12 -0
  529. package/src/results/combined-diff.ts +585 -0
  530. package/src/results/diff-entry.ts +35 -0
  531. package/src/results/diff-formatter.ts +152 -288
  532. package/src/results/diff-order.ts +64 -0
  533. package/src/results/diff-output.ts +1051 -0
  534. package/src/results/fetch-result.ts +15 -0
  535. package/src/results/index.ts +5 -0
  536. package/src/results/merge-result.ts +15 -1
  537. package/src/results/pull-result.ts +12 -3
  538. package/src/results/push-result.ts +43 -0
  539. package/src/results/quote-path.ts +103 -0
  540. package/src/results/rebase-result.ts +37 -0
  541. package/src/results/revert-result.ts +10 -0
  542. package/src/results/stash-result.ts +6 -0
  543. package/src/results/status-result.ts +123 -45
  544. package/src/transport-command.ts +121 -2
  545. package/dist/commands-CsLNyvZ1.js +0 -12587
  546. package/dist/status-result-BpyUK1Sg.js +0 -519
@@ -0,0 +1,1359 @@
1
+ /**
2
+ * `git log`'s output: the commits of a walk printed as git prints them (log-tree.c's
3
+ * log_tree_commit and show_log, pretty.c's pretty_print_commit), with the history graph
4
+ * (graph.c, see {@link LogGraph}) and each commit's diff.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const text = await git.log().setMaxCount(3).callText({ pretty: "oneline", graph: true });
9
+ * // "* 1a2b3c4 Merge branch 'topic'\n|\\ \n| * 5d6e7f8 Topic work\n..."
10
+ * const patch = await git.log().addPath("src").callText({ patch: true, stat: true });
11
+ * ```
12
+ *
13
+ * The options are `git log`'s: `pretty` takes what `--pretty=`/`--format=` take (`medium`,
14
+ * `short`, `full`, `fuller`, `reference`, `email`, `mboxrd`, `raw`, `oneline`, a
15
+ * `pretty.<name>` alias, `format:<fmt>`, `tformat:<fmt>`, or a format with a `%`), `date`
16
+ * what `--date=` takes, and so on; unset, the configuration's defaults apply (`format.pretty`,
17
+ * `log.date`, `log.abbrevCommit`, `log.decorate`, `log.showRoot`, `log.mailmap`,
18
+ * `log.follow`, `log.graphIndent`, `log.excludeDecoration`, `notes.displayRef`...). Colors
19
+ * are never written (git without a terminal).
20
+ *
21
+ * A commit with an `encoding` header is shown in UTF-8 (git's default `i18n.logOutputEncoding`);
22
+ * another output encoding is not supported. One quirk of git is not reproduced: where its C
23
+ * code takes a user format's output as a NUL-terminated string under `--graph`, a `%x00`
24
+ * can cut what git prints; the whole text is printed here. Combined diffs (`-c`, `--cc`)
25
+ * compare each path with the same path in every parent: git's per-parent rename detection
26
+ * there (find_paths_generic under `diff.renames`, which pairs a merge's path with the file a
27
+ * parent has it under) is not reproduced, but for the one path `--follow` follows.
28
+ *
29
+ * @module
30
+ */
31
+
32
+ import type { Commit, ObjectId, PersonIdent } from "@statewalker/vcs-core";
33
+ import { decodeGitPath, encodeGitPath, gitCharWidth } from "@statewalker/vcs-utils/encoding";
34
+
35
+ import { InvalidArgumentError } from "../errors/index.js";
36
+ import { ChangeType } from "../results/diff-entry.js";
37
+ import { type DateMode, DEFAULT_DATE_MODE, parseDateMode, showDate } from "./date-format.js";
38
+ import type { DiffOutputFormat, DiffTextOptions } from "./diff-command.js";
39
+ import { LogGraph } from "./log-graph.js";
40
+ import type { Mailmap } from "./mailmap.js";
41
+ import { parsePathspecItem } from "./pathspec.js";
42
+ import {
43
+ formatCommitPretty,
44
+ formatRefDecorations,
45
+ type PrettyCommit,
46
+ PrettyFormatError,
47
+ type RefDecorations,
48
+ wrapText,
49
+ } from "./pretty-format.js";
50
+ import { appendSignoff } from "./trailers.js";
51
+
52
+ /** How `git log` treats merges in its diffs (`--diff-merges=<mode>`, `-m`, `-c`, `--cc`). */
53
+ export type LogDiffMerges = "off" | "first-parent" | "separate" | "combined" | "dense-combined";
54
+
55
+ /** What `git log` prints of each commit (its command-line options). */
56
+ export interface LogOutputOptions {
57
+ /** `--pretty=<format>` / `--format=<format>` (default `format.pretty`, else `medium`) */
58
+ pretty?: string;
59
+ /** `--oneline`: `--pretty=oneline --abbrev-commit` */
60
+ oneline?: boolean;
61
+ /** `--abbrev-commit` / `--no-abbrev-commit` (default `log.abbrevCommit`, false) */
62
+ abbrevCommit?: boolean;
63
+ /**
64
+ * `--abbrev=<n>` (default `core.abbrev`, automatic): at least n digits (4 to 40, as git
65
+ * clamps it), in the commits' ids and in the diffs' `index` lines (combined diffs keep the
66
+ * default length, as git's do)
67
+ */
68
+ abbrev?: number;
69
+ /** `--no-abbrev`: full ids everywhere */
70
+ noAbbrev?: boolean;
71
+ /** `--date=<mode>` (default `log.date`, else `default`) */
72
+ date?: string;
73
+ /**
74
+ * `--decorate[=short|full|auto|no]` / `--no-decorate` (default `log.decorate`, else none,
75
+ * as without a terminal); `true` is `short`
76
+ */
77
+ decorate?: boolean | "short" | "full" | "auto" | "no";
78
+ /** `--decorate-refs=<pattern>` */
79
+ decorateRefs?: string[];
80
+ /** `--decorate-refs-exclude=<pattern>` */
81
+ decorateRefsExclude?: string[];
82
+ /** `--clear-decorations` */
83
+ clearDecorations?: boolean;
84
+ /** `--graph` */
85
+ graph?: boolean;
86
+ /** `--graph-indent` / `--no-graph-indent` (git 2.5x; default `log.graphIndent`, true) */
87
+ graphIndent?: boolean;
88
+ /** `--graph-lane-limit=<n>` (git 2.5x) */
89
+ graphLaneLimit?: number;
90
+ /** `--topo-order` (`--graph` implies it) */
91
+ topoOrder?: boolean;
92
+ /** `--reverse` */
93
+ reverse?: boolean;
94
+ /** `-p` / `--patch` */
95
+ patch?: boolean;
96
+ /** `-s` / `--no-patch`: no diff output, whatever else asks for it */
97
+ noPatch?: boolean;
98
+ /** `--stat` */
99
+ stat?: boolean;
100
+ /** `--shortstat` */
101
+ shortstat?: boolean;
102
+ /**
103
+ * `--summary`: the files created and deleted, renamed and copied (with their similarity),
104
+ * and the mode changes (diff.c's diff_summary)
105
+ */
106
+ summary?: boolean;
107
+ /** `--numstat` */
108
+ numstat?: boolean;
109
+ /** `--name-only` */
110
+ nameOnly?: boolean;
111
+ /** `--name-status` */
112
+ nameStatus?: boolean;
113
+ /** `-m`: merges' diffs against each parent (`log.diffMerges`, default `separate`) */
114
+ m?: boolean;
115
+ /** `-c`: combined diffs of merges (implies `-p`) */
116
+ c?: boolean;
117
+ /** `--cc`: dense combined diffs of merges (implies `-p`) */
118
+ cc?: boolean;
119
+ /** `--diff-merges=<mode>` */
120
+ diffMerges?: LogDiffMerges;
121
+ /**
122
+ * `--full-diff`: a path-limited log shows the commits' whole diffs (against their parents
123
+ * before `--graph` rewrote them)
124
+ */
125
+ fullDiff?: boolean;
126
+ /**
127
+ * `--follow`: follow the one path given across renames and copies (default `log.follow`,
128
+ * which needs exactly one plain path; `--follow` throws git's error otherwise)
129
+ */
130
+ follow?: boolean;
131
+ /** `--root` / `log.showRoot` (default true): a root commit's diff against the empty tree */
132
+ showRoot?: boolean;
133
+ /**
134
+ * `--notes` / `--no-notes` (default: notes shown unless a format is given, or the format
135
+ * has `%N`)
136
+ */
137
+ notes?: boolean;
138
+ /**
139
+ * `--notes=<ref>` (each one): the notes of these refs shown (`x` is `refs/notes/x`, globs
140
+ * expanded); without `notes: true` (`--notes`) only these, not the default notes ref
141
+ */
142
+ notesRefs?: string[];
143
+ /** `--use-mailmap` / `--no-mailmap` (default `log.mailmap`, true) */
144
+ mailmap?: boolean;
145
+ /** Options of the diff text (context, algorithm, `--stat=<width>`...) */
146
+ diff?: DiffTextOptions;
147
+ /** Now, in seconds, for relative and human dates (git's GIT_TEST_DATE_NOW) */
148
+ now?: number;
149
+ /** The local zone's offset east of UTC in minutes at a time (default the host's) */
150
+ localTzOffset?: (time: number) => number;
151
+ /** The local zone's name at a time, for `%Z` of `format-local:` (default `Intl`'s) */
152
+ localTzName?: (time: number) => string;
153
+ /** `git format-patch`'s mail settings (with the `email` or `mboxrd` format) */
154
+ mail?: LogMailOptions;
155
+ }
156
+
157
+ /** What `git format-patch` adds to the `email` format (log-tree.c, pretty.c). */
158
+ export interface LogMailOptions {
159
+ /** The subject's start (`fmt_output_email_subject`), e.g. `Subject: [PATCH 1/3] ` */
160
+ subject?: (id: ObjectId) => string;
161
+ /** `Message-ID`, `In-Reply-To` and `References` lines after the `From <id>` line */
162
+ threadHeaders?: (id: ObjectId) => string;
163
+ /** Headers after the subject (`format.headers`, `To:`, `Cc:`), each with its LF */
164
+ afterSubject?: string;
165
+ /** `--zero-commit`: an all-zero id on the `From` line */
166
+ zeroCommit?: boolean;
167
+ /** `-k`: the subject kept as it is (its lines not joined) */
168
+ preserveSubject?: boolean;
169
+ /** `--signoff`: this `Signed-off-by: ...` line (with LF) appended, unless already there */
170
+ signoff?: string;
171
+ /** `--from=<ident>`: the `From:` header's ident (the author moves to an in-body From) */
172
+ from?: { name: string; email: string };
173
+ /** `--force-in-body-from` */
174
+ forceInBodyFrom?: boolean;
175
+ /** `format.encodeEmailHeaders` (default true): RFC 2047 for non-ASCII subjects and names */
176
+ encodeHeaders?: boolean;
177
+ /**
178
+ * The mail's character set (`i18n.logOutputEncoding`, else `i18n.commitEncoding`, else
179
+ * UTF-8): the commit converted to it (kept as stored when it is in it already), named in
180
+ * `Content-Type` and the RFC 2047 words. Conversions are to UTF-8 and ISO-8859-1 only; a
181
+ * commit that cannot be converted is shown as stored, as git shows it when iconv fails.
182
+ */
183
+ outputEncoding?: string;
184
+ }
185
+
186
+ /** A commit the walk shows, with the parents it is shown with (rewritten under `--graph`). */
187
+ export interface LogOutputEntry {
188
+ id: ObjectId;
189
+ commit: Commit;
190
+ parents: ObjectId[];
191
+ /** The parents before `--graph` rewrote them (git's saved parents, for `--full-diff`) */
192
+ savedParents?: ObjectId[];
193
+ }
194
+
195
+ /** What the printer reads of the repository (see `LogCommand.callBytes`). */
196
+ export interface LogOutputHost {
197
+ /** A configuration value (the last), undefined when unset */
198
+ config(key: string): string | undefined;
199
+ /** Every value of a configuration key */
200
+ configAll(key: string): string[];
201
+ /** The names configured under `<section>.` (for `pretty.<name>`) */
202
+ configNames(section: string): string[];
203
+ /** An id abbreviated to at least `minLength` digits (default: automatic, `core.abbrev`) */
204
+ abbreviate(id: ObjectId, minLength?: number): Promise<string>;
205
+ /** The commit as stored, decoded as paths decode (header and message) */
206
+ rawCommit(id: ObjectId): Promise<string | undefined>;
207
+ /** The decorations shown (loaded when asked for) */
208
+ decorations(options: {
209
+ decorate: "short" | "full";
210
+ decorateRefs?: string[];
211
+ decorateRefsExclude?: string[];
212
+ clearDecorations?: boolean;
213
+ }): Promise<RefDecorations>;
214
+ /** The notes of a commit in each display notes ref: the ref and the note's text */
215
+ notes(id: ObjectId): Promise<{ ref: string; text: string }[]>;
216
+ /** The mailmap */
217
+ mailmap(): Promise<Mailmap>;
218
+ /**
219
+ * The diff of a commit against a parent (the empty tree for none): undefined bytes when
220
+ * nothing differs; `follow` the path followed, `followPath` the path to follow in the
221
+ * parent, `followChange` set when it was found as a rename or a copy
222
+ */
223
+ diff(
224
+ entry: LogOutputEntry,
225
+ parent: ObjectId | undefined,
226
+ formats: DiffOutputFormat[],
227
+ options: { statWidth?: number; follow?: string; fullDiff?: boolean; abbrev?: number },
228
+ ): Promise<{
229
+ bytes?: Uint8Array;
230
+ followPath?: string;
231
+ followChange?: ChangeType.RENAME | ChangeType.COPY;
232
+ }>;
233
+ /**
234
+ * The combined diff of a merge (`-c`, `--cc`): the paths that differ from every parent,
235
+ * `names` as `--name-only` / `--name-status` list them (undefined for neither), `patch`
236
+ * the combined patch (when asked); `follow` the one path `--follow` limits it to
237
+ */
238
+ combinedDiff(
239
+ entry: LogOutputEntry,
240
+ options: {
241
+ dense: boolean;
242
+ names?: "name-only" | "name-status";
243
+ patch: boolean;
244
+ follow?: string;
245
+ /** With `follow`: the path each parent has it under (a rename or copy found) */
246
+ parentPaths?: string[];
247
+ /** With `parentPaths`: `R` or `C` for a parent whose path was found as a rename or copy */
248
+ parentStatus?: (string | undefined)[];
249
+ },
250
+ ): Promise<{ paths: number; names: Uint8Array; patch: Uint8Array }>;
251
+ }
252
+
253
+ type Fmt = "raw" | "medium" | "short" | "email" | "mboxrd" | "fuller" | "full" | "oneline" | "user";
254
+
255
+ interface CommitFormat {
256
+ fmt: Fmt;
257
+ user?: string;
258
+ useTerminator: boolean;
259
+ expandTabs: number;
260
+ dateShort?: boolean;
261
+ }
262
+
263
+ const BUILTIN_FORMATS: { name: string; fmt: Fmt; terminator: boolean; tabs: number }[] = [
264
+ { name: "raw", fmt: "raw", terminator: false, tabs: 0 },
265
+ { name: "medium", fmt: "medium", terminator: false, tabs: 8 },
266
+ { name: "short", fmt: "short", terminator: false, tabs: 0 },
267
+ { name: "email", fmt: "email", terminator: false, tabs: 0 },
268
+ { name: "mboxrd", fmt: "mboxrd", terminator: false, tabs: 0 },
269
+ { name: "fuller", fmt: "fuller", terminator: false, tabs: 8 },
270
+ { name: "full", fmt: "full", terminator: false, tabs: 8 },
271
+ { name: "oneline", fmt: "oneline", terminator: true, tabs: 0 },
272
+ { name: "reference", fmt: "user", terminator: true, tabs: 0 },
273
+ ];
274
+
275
+ /** pretty.c's get_commit_format (with the `pretty.<name>` aliases of the configuration). */
276
+ function parseCommitFormat(arg: string | undefined, host: LogOutputHost): CommitFormat {
277
+ if (arg === undefined) return { fmt: "medium", useTerminator: false, expandTabs: 8 };
278
+ if (arg.startsWith("format:")) {
279
+ return { fmt: "user", user: arg.slice(7), useTerminator: false, expandTabs: 0 };
280
+ }
281
+ if (arg === "" || arg.startsWith("tformat:") || arg.includes("%")) {
282
+ const user = arg.startsWith("tformat:") ? arg.slice(8) : arg;
283
+ return { fmt: "user", user, useTerminator: true, expandTabs: 0 };
284
+ }
285
+ // find_commit_format: the shortest name that starts with it, aliases followed
286
+ const custom = host
287
+ .configNames("pretty")
288
+ .filter((name) => !BUILTIN_FORMATS.some((b) => b.name === name));
289
+ const names = [...BUILTIN_FORMATS.map((b) => b.name), ...custom];
290
+ let sought = arg;
291
+ for (let depth = 0; depth <= names.length; depth++) {
292
+ const lower = sought.toLowerCase();
293
+ let found: string | undefined;
294
+ for (const name of names) {
295
+ if (!name.toLowerCase().startsWith(lower)) continue;
296
+ if (found === undefined || found.length > name.length) found = name;
297
+ }
298
+ if (found === undefined) throw new PrettyFormatError(`fatal: invalid --pretty format: ${arg}`);
299
+ const builtin = BUILTIN_FORMATS.find((b) => b.name === found);
300
+ if (builtin) {
301
+ if (builtin.name === "reference") {
302
+ return {
303
+ fmt: "user",
304
+ user: "%C(auto)%h (%s, %ad)",
305
+ useTerminator: true,
306
+ expandTabs: 0,
307
+ dateShort: true,
308
+ };
309
+ }
310
+ return { fmt: builtin.fmt, useTerminator: builtin.terminator, expandTabs: builtin.tabs };
311
+ }
312
+ const value = host.config(`pretty.${found}`) ?? "";
313
+ if (value.startsWith("format:")) {
314
+ return { fmt: "user", user: value.slice(7), useTerminator: false, expandTabs: 0 };
315
+ }
316
+ if (value.startsWith("tformat:")) {
317
+ return { fmt: "user", user: value.slice(8), useTerminator: true, expandTabs: 0 };
318
+ }
319
+ if (value.includes("%"))
320
+ return { fmt: "user", user: value, useTerminator: true, expandTabs: 0 };
321
+ sought = value;
322
+ }
323
+ throw new PrettyFormatError(
324
+ `fatal: invalid --pretty format: '${arg}' references an alias which points to itself`,
325
+ );
326
+ }
327
+
328
+ /** git_parse_maybe_bool */
329
+ function bool(value: string | undefined): boolean | undefined {
330
+ if (value === undefined) return undefined;
331
+ const v = value.trim().toLowerCase();
332
+ if (v === "true" || v === "yes" || v === "on" || v === "1") return true;
333
+ if (v === "false" || v === "no" || v === "off" || v === "0" || v === "") return false;
334
+ if (/^-?\d+$/.test(v)) return Number(v) !== 0;
335
+ return undefined;
336
+ }
337
+
338
+ /** log-tree.c's parse_decoration_style */
339
+ function decorationStyle(value: string | boolean | undefined): "short" | "full" | undefined {
340
+ if (value === undefined) return undefined;
341
+ if (value === true) return "short";
342
+ if (value === false) return undefined;
343
+ const b = bool(value);
344
+ if (b !== undefined) return b ? "short" : undefined;
345
+ if (value === "full") return "full";
346
+ if (value === "short") return "short";
347
+ // auto: decorated only on a terminal
348
+ return undefined;
349
+ }
350
+
351
+ const isSpace = (c: string | undefined) => c === " " || c === "\t" || c === "\n" || c === "\r";
352
+
353
+ /** The text with git's isspace trimmed at the end (strbuf_rtrim). */
354
+ function rtrim(text: string): string {
355
+ let end = text.length;
356
+ while (end > 0 && isSpace(text[end - 1])) end--;
357
+ return text.slice(0, end);
358
+ }
359
+
360
+ /** The lines of a message, each with its newline (get_one_line). */
361
+ function linesOf(msg: string): string[] {
362
+ const out: string[] = [];
363
+ let at = 0;
364
+ while (at < msg.length) {
365
+ const nl = msg.indexOf("\n", at);
366
+ const next = nl < 0 ? msg.length : nl + 1;
367
+ out.push(msg.slice(at, next));
368
+ at = next;
369
+ }
370
+ return out;
371
+ }
372
+
373
+ /** pretty.c's skip_blank_lines over line arrays: the index of the first non-blank line */
374
+ function skipBlank(lines: string[], from: number): number {
375
+ let i = from;
376
+ while (i < lines.length && rtrim(lines[i] as string) === "") i++;
377
+ return i;
378
+ }
379
+
380
+ /** pp_utf8_width: the columns of a text, -1 when it has a control or invalid character */
381
+ function utf8Width(text: string): number {
382
+ let w = 0;
383
+ for (let i = 0; i < text.length; ) {
384
+ const cp = text.codePointAt(i) as number;
385
+ i += cp > 0xffff ? 2 : 1;
386
+ if (cp >= 0xd800 && cp <= 0xdfff) return -1;
387
+ const cw = gitCharWidth(cp);
388
+ if (cw < 0) return -1;
389
+ w += cw;
390
+ }
391
+ return w;
392
+ }
393
+
394
+ /** strbuf_add_tabexpand */
395
+ function tabExpand(line: string, tabWidth: number): string {
396
+ let out = "";
397
+ let rest = line;
398
+ for (let tab = rest.indexOf("\t"); tab >= 0; tab = rest.indexOf("\t")) {
399
+ const width = utf8Width(rest.slice(0, tab));
400
+ if (width < 0) break;
401
+ out += rest.slice(0, tab) + " ".repeat(tabWidth - (width % tabWidth));
402
+ rest = rest.slice(tab + 1);
403
+ }
404
+ return out + rest;
405
+ }
406
+
407
+ /** The UTF-8 bytes of a string whose raw bytes are escaped as paths escape them */
408
+ const bytesOf = encodeGitPath;
409
+
410
+ const hasNonAscii = (text: string) => [...text].some((c) => c.charCodeAt(0) > 0x7f);
411
+
412
+ /** pretty.c's needs_rfc2047_encoding */
413
+ function needsRfc2047(text: string): boolean {
414
+ for (let i = 0; i < text.length; i++) {
415
+ const c = text.charCodeAt(i);
416
+ if (c >= 0x80 || c === 0x0a) return true;
417
+ if (c === 0x3d && text[i + 1] === "?") return true;
418
+ }
419
+ return false;
420
+ }
421
+
422
+ const RFC822_SPECIALS = '()<>[]:;@,."\\';
423
+
424
+ /** pretty.c's last_line_length, in bytes */
425
+ function lastLineLength(sb: string): number {
426
+ const nl = sb.lastIndexOf("\n");
427
+ return bytesOf(sb.slice(nl + 1)).length;
428
+ }
429
+
430
+ /** pretty.c's add_rfc2047 */
431
+ function addRfc2047(sb: string, text: string, address: boolean, encoding = "UTF-8"): string {
432
+ const max = 76;
433
+ let lineLen = lastLineLength(sb);
434
+ let out = `=?${encoding}?q?`;
435
+ lineLen += encoding.length + 5;
436
+ // mbs_chrlen: UTF-8 sequences are one character, any other encoding goes byte by byte
437
+ const utf8 = isUtf8(encoding);
438
+ const bytes = bytesOf(text);
439
+ const special = (ch: number) => {
440
+ if (ch >= 0x80 || ch < 0x20 || ch === 0x7f) return true;
441
+ if (ch === 0x20 || ch === 0x09 || ch === 0x3d || ch === 0x3f || ch === 0x5f) return true;
442
+ if (!address) return false;
443
+ const c = String.fromCharCode(ch);
444
+ return !(/[A-Za-z0-9]/.test(c) || "!*+-/".includes(c));
445
+ };
446
+ for (let i = 0; i < bytes.length; ) {
447
+ const lead = bytes[i] as number;
448
+ let len = 1;
449
+ if (utf8 && lead >= 0xc0) {
450
+ const want = lead >= 0xf0 ? 4 : lead >= 0xe0 ? 3 : 2;
451
+ let ok = i + want <= bytes.length;
452
+ for (let k = 1; ok && k < want; k++) ok = ((bytes[i + k] as number) & 0xc0) === 0x80;
453
+ if (ok) len = want;
454
+ }
455
+ const isSpecial = len > 1 || special(lead);
456
+ const encodedLen = isSpecial ? 3 * len : 1;
457
+ if (lineLen + encodedLen + 2 > max) {
458
+ out += `?=\n =?${encoding}?q?`;
459
+ lineLen = encoding.length + 5 + 1;
460
+ }
461
+ for (let k = 0; k < len; k++) {
462
+ const b = bytes[i + k] as number;
463
+ out += isSpecial
464
+ ? `=${b.toString(16).toUpperCase().padStart(2, "0")}`
465
+ : String.fromCharCode(b);
466
+ }
467
+ lineLen += encodedLen;
468
+ i += len;
469
+ }
470
+ return `${out}?=`;
471
+ }
472
+
473
+ /**
474
+ * The `From:` header of the email format (pp_user_info): RFC 2047 (unless
475
+ * `format.encodeEmailHeaders` is off) or quoted as needed.
476
+ */
477
+ export function mailFromHeader(
478
+ name: string,
479
+ email: string,
480
+ options: { encodeHeaders?: boolean; encoding?: string } = {},
481
+ ): string {
482
+ let max = 78;
483
+ let out = "From: ";
484
+ if ((options.encodeHeaders ?? true) && needsRfc2047(name)) {
485
+ out += addRfc2047(out, name, true, options.encoding);
486
+ max = 76;
487
+ } else if ([...name].some((c) => RFC822_SPECIALS.includes(c))) {
488
+ const quoted = `"${name.replace(/["\\]/g, (c) => `\\${c}`)}"`;
489
+ out += wrapText(quoted, -6, 1, max);
490
+ } else out += wrapText(name, -6, 1, max);
491
+ if (max < lastLineLength(out) + 2 + bytesOf(email).length + 1) out += "\n";
492
+ return `${out} <${email}>\n`;
493
+ }
494
+
495
+ /** The parts of a commit as git's pretty printer reads them. */
496
+ interface ParsedCommit {
497
+ headerLines: string[];
498
+ body: string;
499
+ }
500
+
501
+ function parseRaw(raw: string): ParsedCommit {
502
+ const lines = linesOf(raw);
503
+ const headerLines: string[] = [];
504
+ let i = 0;
505
+ for (; i < lines.length; i++) {
506
+ const line = lines[i] as string;
507
+ if (line === "\n") {
508
+ i++;
509
+ break;
510
+ }
511
+ headerLines.push(line);
512
+ }
513
+ return { headerLines, body: lines.slice(i).join("") };
514
+ }
515
+
516
+ /** utf8.c's is_encoding_utf8 */
517
+ const isUtf8 = (name: string) => /^utf-?8$/i.test(name);
518
+
519
+ /** The ISO-8859-1 names iconv knows (TextDecoder reads them as windows-1252). */
520
+ const LATIN1 = /^(iso[-_]?8859-1|iso8859-1|latin-?1|l1|iso-ir-100|cp819|ibm819|csisolatin1)$/i;
521
+
522
+ /** Bytes in a character set as text; undefined when it is unknown or the bytes are not in it */
523
+ function decodeCharset(bytes: Uint8Array, charset: string): string | undefined {
524
+ if (LATIN1.test(charset)) {
525
+ let out = "";
526
+ for (const b of bytes) out += String.fromCharCode(b);
527
+ return out;
528
+ }
529
+ try {
530
+ return new TextDecoder(charset, { fatal: true }).decode(bytes);
531
+ } catch {
532
+ return undefined;
533
+ }
534
+ }
535
+
536
+ /** utf8.c's same_encoding */
537
+ const sameEncoding = (a: string, b: string) =>
538
+ (isUtf8(a) && isUtf8(b)) || a.toLowerCase() === b.toLowerCase();
539
+
540
+ /**
541
+ * pretty.c's repo_logmsg_reencode into the output encoding (UTF-8 by default: git's
542
+ * `i18n.logOutputEncoding`, `i18n.commitEncoding` default): a commit with an `encoding`
543
+ * header (UTF-8 without one) is converted from it, then the header dropped when the output
544
+ * is UTF-8 (an `encoding UTF-8` header too) or naming the output encoding; one already in
545
+ * the output encoding keeps its bytes. One whose bytes do not convert (or with a character
546
+ * set this host cannot convert) is kept as it is, header and all, as git keeps it when
547
+ * iconv fails. Undefined when nothing changes.
548
+ */
549
+ function reencodeCommit(
550
+ raw: string,
551
+ parsed: ParsedCommit,
552
+ outputEncoding = "UTF-8",
553
+ ): string | undefined {
554
+ const at = parsed.headerLines.findIndex((l) => l.startsWith("encoding "));
555
+ const charset =
556
+ at < 0 ? undefined : (parsed.headerLines[at] as string).slice(9).replace(/\n$/, "");
557
+ const use = charset ?? "UTF-8";
558
+ let text = raw;
559
+ if (sameEncoding(use, outputEncoding)) {
560
+ if (charset === undefined) return undefined;
561
+ } else {
562
+ const decoded = isUtf8(use)
563
+ ? decodeCharset(encodeGitPath(raw), "UTF-8")
564
+ : decodeCharset(encodeGitPath(raw), use);
565
+ if (decoded === undefined) return undefined;
566
+ if (isUtf8(outputEncoding)) text = decoded;
567
+ else if (LATIN1.test(outputEncoding)) {
568
+ const bytes = new Uint8Array(decoded.length);
569
+ for (let i = 0; i < decoded.length; i++) {
570
+ const c = decoded.charCodeAt(i);
571
+ if (c > 0xff) return undefined;
572
+ bytes[i] = c;
573
+ }
574
+ text = decodeGitPath(bytes);
575
+ } else return undefined;
576
+ }
577
+ // replace_encoding_header: the first `encoding ` line of the header removed (UTF-8) or
578
+ // naming the output encoding
579
+ const lines = linesOf(text);
580
+ const k = lines.findIndex((l, i) => l.startsWith("encoding ") && i < parsed.headerLines.length);
581
+ if (k >= 0) {
582
+ if (isUtf8(outputEncoding)) lines.splice(k, 1);
583
+ else lines[k] = `encoding ${outputEncoding}\n`;
584
+ }
585
+ return lines.join("");
586
+ }
587
+
588
+ /** An `author`/`committer` header line's ident (`Name <email> time zone`) */
589
+ function identOf(line: string): PersonIdent | undefined {
590
+ const m = /^[a-z]+ (.*?) ?<([^>]*)> ?(\d*) ?([+-]?\d*)\n?$/.exec(line);
591
+ if (!m) return undefined;
592
+ return {
593
+ name: m[1] as string,
594
+ email: m[2] as string,
595
+ timestamp: Number(m[3] || 0),
596
+ tzOffset: m[4] || "+0000",
597
+ };
598
+ }
599
+
600
+ /** A commit's raw text synthesized from its fields (a store that keeps no raw bytes). */
601
+ function synthesizeRaw(commit: Commit): string {
602
+ const ident = (p: PersonIdent) => `${p.name} <${p.email}> ${p.timestamp} ${p.tzOffset}`;
603
+ let out = `tree ${commit.tree}\n`;
604
+ for (const p of commit.parents) out += `parent ${p}\n`;
605
+ out += `author ${ident(commit.author)}\ncommitter ${ident(commit.committer)}\n`;
606
+ if (commit.encoding) out += `encoding ${commit.encoding}\n`;
607
+ return `${out}\n${commit.message}`;
608
+ }
609
+
610
+ /** A sink of text and bytes. */
611
+ class Output {
612
+ private readonly chunks: Uint8Array[] = [];
613
+ private pendingText = "";
614
+
615
+ text(s: string): void {
616
+ this.pendingText += s;
617
+ }
618
+
619
+ bytes(b: Uint8Array): void {
620
+ this.flush();
621
+ this.chunks.push(b);
622
+ }
623
+
624
+ private flush(): void {
625
+ if (this.pendingText) {
626
+ this.chunks.push(bytesOf(this.pendingText));
627
+ this.pendingText = "";
628
+ }
629
+ }
630
+
631
+ result(): Uint8Array {
632
+ this.flush();
633
+ const size = this.chunks.reduce((n, c) => n + c.length, 0);
634
+ const out = new Uint8Array(size);
635
+ let at = 0;
636
+ for (const c of this.chunks) {
637
+ out.set(c, at);
638
+ at += c.length;
639
+ }
640
+ return out;
641
+ }
642
+ }
643
+
644
+ /**
645
+ * Each line of `bytes` with `prefix` before it (diff_line_prefix); `bare` lines are left
646
+ * without it (combine-diff.c prints its `mode` and `Binary files differ` lines with a plain
647
+ * printf, without the prefix).
648
+ */
649
+ function prefixLines(
650
+ bytes: Uint8Array,
651
+ prefix: string,
652
+ bare?: (line: string) => boolean,
653
+ ): Uint8Array {
654
+ if (!prefix || bytes.length === 0) return bytes;
655
+ const p = bytesOf(prefix);
656
+ let lines = 0;
657
+ for (let at = bytes.indexOf(0x0a); at >= 0; at = bytes.indexOf(0x0a, at + 1)) lines++;
658
+ const out = new Uint8Array(bytes.length + (lines + 1) * p.length);
659
+ let size = 0;
660
+ let at = 0;
661
+ while (at < bytes.length) {
662
+ let end = bytes.indexOf(0x0a, at);
663
+ end = end < 0 ? bytes.length : end + 1;
664
+ const head = bare ? String.fromCharCode(...bytes.subarray(at, Math.min(end, at + 19))) : "";
665
+ if (!bare?.(head)) {
666
+ out.set(p, size);
667
+ size += p.length;
668
+ }
669
+ out.set(bytes.subarray(at, end), size);
670
+ size += end - at;
671
+ at = end;
672
+ }
673
+ return out.subarray(0, size);
674
+ }
675
+
676
+ const combinedBare = (head: string) =>
677
+ head.startsWith("mode ") || head.startsWith("Binary files differ");
678
+
679
+ /** The commit printer: git's rev_info output state over one walk. */
680
+ export class LogPrinter {
681
+ private readonly out = new Output();
682
+ private readonly format: CommitFormat;
683
+ private readonly dateMode: DateMode;
684
+ private readonly abbrevCommit: boolean;
685
+ private readonly abbrevLength: number | undefined;
686
+ private readonly formats: DiffOutputFormat[];
687
+ /** git's `revs->diff`: every commit's diff is run (diff formats asked for, `-c`, `--follow`) */
688
+ private readonly allNeedDiff: boolean;
689
+ private readonly diffMerges: LogDiffMerges | undefined;
690
+ private readonly mergesNeedDiff: boolean;
691
+ /** git's `simplify_history` turned off (`-m`, `--diff-merges=separate`) */
692
+ readonly fullHistory: boolean;
693
+ private readonly showRoot: boolean;
694
+ private readonly useMailmap: boolean;
695
+ private readonly showNotes: boolean;
696
+ private readonly decorate: "short" | "full" | undefined;
697
+ private readonly follow: boolean;
698
+ private decorations?: RefDecorations;
699
+ private mailmap?: Mailmap;
700
+ private graph?: LogGraph;
701
+ private shownOne = false;
702
+ private missingNewline = false;
703
+ private shownDashes = false;
704
+ /** The path `--follow` follows in each commit still to come */
705
+ private readonly followPaths = new Map<ObjectId, string>();
706
+ private followPath: string | undefined;
707
+
708
+ constructor(
709
+ private readonly host: LogOutputHost,
710
+ private readonly options: LogOutputOptions,
711
+ private readonly walk: {
712
+ interesting: (id: ObjectId) => boolean;
713
+ firstParentOnly: boolean;
714
+ paths: string[];
715
+ },
716
+ ) {
717
+ const prettyGiven = options.pretty !== undefined || !!options.oneline;
718
+ const pretty = options.oneline ? "oneline" : (options.pretty ?? host.config("format.pretty"));
719
+ this.format = parseCommitFormat(pretty, host);
720
+ const dateSpec = options.date ?? host.config("log.date");
721
+ this.dateMode = dateSpec
722
+ ? parseDateMode(dateSpec)
723
+ : this.format.dateShort
724
+ ? { type: "short", local: false }
725
+ : DEFAULT_DATE_MODE;
726
+ if (options.date === undefined && this.format.dateShort) {
727
+ this.dateMode = { type: "short", local: false };
728
+ }
729
+ const raw = prettyGiven && this.format.fmt === "raw";
730
+ this.abbrevCommit =
731
+ options.abbrevCommit ??
732
+ (options.oneline ? true : raw ? false : (bool(host.config("log.abbrevCommit")) ?? false));
733
+ // --abbrev=<n> is clamped to 4..40 (an --abbrev=0 is 4)
734
+ if (options.noAbbrev) this.abbrevLength = 40;
735
+ else if (options.abbrev !== undefined) {
736
+ this.abbrevLength = Math.min(40, Math.max(4, Math.trunc(options.abbrev)));
737
+ }
738
+ // decorations: a user format decorates only when it shows them
739
+ let decorate =
740
+ options.decorate !== undefined
741
+ ? decorationStyle(options.decorate)
742
+ : raw
743
+ ? undefined
744
+ : decorationStyle(host.config("log.decorate"));
745
+ if (this.format.fmt === "user") {
746
+ const wants = /%(d|D|\(decorate)/.test(this.format.user ?? "");
747
+ decorate = wants ? (decorate ?? "short") : undefined;
748
+ }
749
+ this.decorate = decorate;
750
+ // diffs
751
+ const formats: DiffOutputFormat[] = [];
752
+ if (options.nameOnly) formats.push("name-only");
753
+ else if (options.nameStatus) formats.push("name-status");
754
+ if (options.numstat) formats.push("numstat");
755
+ if (options.stat) formats.push("stat");
756
+ if (options.shortstat) formats.push("shortstat");
757
+ if (options.summary) formats.push("summary");
758
+ if (options.patch) formats.push("patch");
759
+ // revs->diff: decided from the formats asked for before the merges' default patch
760
+ const userDiff = !options.noPatch && formats.length > 0;
761
+ let diffMerges: LogDiffMerges | undefined = options.diffMerges;
762
+ let mergesNeedDiff = diffMerges !== undefined && diffMerges !== "off";
763
+ let implyPatch = false;
764
+ // diff-merges.c's set_separate turns simplify_history off, and nothing turns it back on
765
+ const configuredMerges = host.config("log.diffMerges");
766
+ const mDefault = configuredMerges ? mergesMode(configuredMerges) : "separate";
767
+ this.fullHistory =
768
+ diffMerges === "separate" ||
769
+ diffMerges === "first-parent" ||
770
+ (!!options.m && (mDefault === "separate" || mDefault === "first-parent"));
771
+ if (options.cc) {
772
+ diffMerges = "dense-combined";
773
+ mergesNeedDiff = true;
774
+ implyPatch = true;
775
+ } else if (options.c) {
776
+ diffMerges = "combined";
777
+ mergesNeedDiff = true;
778
+ implyPatch = true;
779
+ } else if (options.m && diffMerges === undefined) {
780
+ diffMerges = mDefault;
781
+ mergesNeedDiff = false;
782
+ }
783
+ // log_setup_revisions_tweak's diff_merges_default_to_first_parent: under --first-parent a
784
+ // merge's separate diff (the default, -m, --diff-merges=separate) is against the first
785
+ // parent only
786
+ if (walk.firstParentOnly && (diffMerges === undefined || diffMerges === "separate")) {
787
+ diffMerges = "first-parent";
788
+ }
789
+ if ((implyPatch || mergesNeedDiff) && formats.length === 0) formats.push("patch");
790
+ // --name-only and --name-status turn the other formats off (diff_setup_done)
791
+ const names = formats.find((f) => f === "name-only" || f === "name-status");
792
+ this.formats = options.noPatch ? [] : names ? [names] : formats;
793
+ this.diffMerges = diffMerges;
794
+ this.mergesNeedDiff = mergesNeedDiff;
795
+ this.showRoot = options.showRoot ?? bool(host.config("log.showRoot")) ?? true;
796
+ this.useMailmap = options.mailmap ?? bool(host.config("log.mailmap")) ?? true;
797
+ this.showNotes =
798
+ options.notes ??
799
+ ((options.notesRefs?.length ?? 0) > 0 || !prettyGiven || /%N/.test(this.format.user ?? ""));
800
+ // --follow needs one path, without magic but `:(top)` and `:(literal)`
801
+ // (diff_check_follow_pathspec); log.follow is ignored otherwise
802
+ const followPath = followPathOf(walk.paths, options.follow === true);
803
+ this.follow = (options.follow ?? bool(host.config("log.follow")) ?? false) && !!followPath;
804
+ if (this.follow) this.followPath = followPath;
805
+ // revision.c: --full-diff sets revs->diff too
806
+ this.allNeedDiff = userDiff || implyPatch || this.follow || !!options.fullDiff;
807
+ }
808
+
809
+ /** Whether commits not shown (their diff empty) do not count (`--follow`) */
810
+ get alwaysShowHeader(): boolean {
811
+ return !this.follow;
812
+ }
813
+
814
+ /** Prepares what the format reads (decorations, mailmap) and the graph */
815
+ async start(): Promise<void> {
816
+ if (this.decorate) {
817
+ this.decorations = await this.host.decorations({
818
+ decorate: this.decorate,
819
+ ...(this.options.decorateRefs ? { decorateRefs: this.options.decorateRefs } : {}),
820
+ ...(this.options.decorateRefsExclude
821
+ ? { decorateRefsExclude: this.options.decorateRefsExclude }
822
+ : {}),
823
+ ...(this.options.clearDecorations ? { clearDecorations: true } : {}),
824
+ });
825
+ }
826
+ this.mailmap = await this.host.mailmap();
827
+ }
828
+
829
+ /** Starts the graph over the entries shown */
830
+ useGraph(parentsOf: (id: ObjectId) => readonly ObjectId[]): void {
831
+ const indent = this.options.graphIndent ?? bool(this.host.config("log.graphIndent")) ?? true;
832
+ this.graph = new LogGraph({
833
+ parents: parentsOf,
834
+ interesting: this.walk.interesting,
835
+ firstParentOnly: this.walk.firstParentOnly,
836
+ indent,
837
+ ...(this.options.graphLaneLimit ? { maxLanes: this.options.graphLaneLimit } : {}),
838
+ });
839
+ }
840
+
841
+ private padding(): string {
842
+ return this.graph ? this.graph.showPadding() : "";
843
+ }
844
+
845
+ private oneline(): string {
846
+ return this.graph ? this.graph.showOneline() : "";
847
+ }
848
+
849
+ private async abbrevId(id: ObjectId, abbreviated: boolean): Promise<string> {
850
+ if (!abbreviated || this.abbrevLength === 40) return id;
851
+ return this.host.abbreviate(id, this.abbrevLength);
852
+ }
853
+
854
+ private formatDate(ident: PersonIdent, mode: DateMode = this.dateMode): string {
855
+ return showDate(ident.timestamp, ident.tzOffset, mode, {
856
+ ...(this.options.now !== undefined ? { now: this.options.now } : {}),
857
+ ...(this.options.localTzOffset ? { localTzOffset: this.options.localTzOffset } : {}),
858
+ ...(this.options.localTzName ? { localTzName: this.options.localTzName } : {}),
859
+ });
860
+ }
861
+
862
+ private mapped(ident: PersonIdent): { name: string; email: string } {
863
+ if (this.useMailmap && this.mailmap && !this.mailmap.empty) {
864
+ return this.mailmap.map(ident.name, ident.email);
865
+ }
866
+ return { name: ident.name, email: ident.email };
867
+ }
868
+
869
+ /**
870
+ * One commit (log_tree_commit): its header and message, and its diff; false when it was
871
+ * not shown (`--follow` and nothing of the path changed).
872
+ */
873
+ async showCommit(entry: LogOutputEntry, lookahead: ObjectId[]): Promise<boolean> {
874
+ this.graph?.update(entry.id, lookahead);
875
+ if (this.follow) {
876
+ const stored = this.followPaths.get(entry.id);
877
+ if (stored !== undefined) this.followPath = stored;
878
+ }
879
+ const log = { pending: true, parent: undefined as ObjectId | undefined };
880
+ let shown = await this.logTreeDiff(entry, log);
881
+ if (!shown && log.pending && this.alwaysShowHeader) {
882
+ log.parent = undefined;
883
+ await this.showLog(entry, log);
884
+ shown = true;
885
+ }
886
+ if (this.follow) {
887
+ const parents = entry.parents;
888
+ if (parents.length > 1) {
889
+ // each parent gets the path its own diff follows to
890
+ for (const p of parents) {
891
+ const r = await this.host.diff(entry, p, [], { follow: this.followPath as string });
892
+ if (r.followPath !== undefined) this.followPaths.set(p, r.followPath);
893
+ }
894
+ } else if (parents.length === 1 && this.followPath !== undefined) {
895
+ this.followPaths.set(parents[0] as ObjectId, this.followPath);
896
+ }
897
+ }
898
+ return shown;
899
+ }
900
+
901
+ /** log-tree.c's log_tree_diff: true when it showed the log */
902
+ private async logTreeDiff(
903
+ entry: LogOutputEntry,
904
+ log: { pending: boolean; parent: ObjectId | undefined },
905
+ ): Promise<boolean> {
906
+ const allNeedDiff = this.allNeedDiff;
907
+ if (!allNeedDiff && !this.mergesNeedDiff) return false;
908
+ const parents = this.diffParents(entry);
909
+ const isMerge = parents.length > 1;
910
+ if (!isMerge && !allNeedDiff) return false;
911
+ if (parents.length === 0) {
912
+ if (this.showRoot) await this.diffFlush(entry, undefined, log);
913
+ return !log.pending;
914
+ }
915
+ const firstParentMerges = this.diffMerges === "first-parent";
916
+ if (isMerge) {
917
+ if (this.diffMerges === "combined" || this.diffMerges === "dense-combined") {
918
+ await this.combined(entry, log, this.diffMerges === "dense-combined");
919
+ return !log.pending;
920
+ }
921
+ if (this.diffMerges === "separate" || this.diffMerges === "first-parent") {
922
+ if (!firstParentMerges) log.parent = parents[0];
923
+ } else return false;
924
+ }
925
+ let showed = false;
926
+ for (let k = 0; k < parents.length; k++) {
927
+ await this.diffFlush(entry, parents[k], log);
928
+ showed ||= !log.pending;
929
+ if (k + 1 >= parents.length || firstParentMerges) break;
930
+ log.parent = parents[k + 1];
931
+ log.pending = true;
932
+ }
933
+ return showed;
934
+ }
935
+
936
+ /** get_saved_parents: the parents before rewriting under `--full-diff`, else as shown */
937
+ private diffParents(entry: LogOutputEntry): ObjectId[] {
938
+ return this.options.fullDiff && entry.savedParents ? entry.savedParents : entry.parents;
939
+ }
940
+
941
+ /** The `--abbrev=<n>` of the diffs' `index` lines (revs->diffopt.abbrev) */
942
+ private diffAbbrev(): { abbrev?: number } {
943
+ return this.options.abbrev !== undefined && !this.options.noAbbrev && this.abbrevLength
944
+ ? { abbrev: this.abbrevLength }
945
+ : {};
946
+ }
947
+
948
+ private formatIsEmpty(): boolean {
949
+ return this.format.fmt === "user" && this.format.user === "";
950
+ }
951
+
952
+ /** log-tree.c's log_tree_diff_flush */
953
+ private async diffFlush(
954
+ entry: LogOutputEntry,
955
+ parent: ObjectId | undefined,
956
+ log: { pending: boolean; parent: ObjectId | undefined },
957
+ ): Promise<void> {
958
+ this.shownDashes = false;
959
+ const width = this.graph ? this.graph.getWidth() : 0;
960
+ const result = await this.host.diff(entry, parent, this.formats, {
961
+ ...(width ? { statWidth: 80 - width } : {}),
962
+ ...(this.follow && this.followPath !== undefined ? { follow: this.followPath } : {}),
963
+ ...(this.options.fullDiff ? { fullDiff: true } : {}),
964
+ ...this.diffAbbrev(),
965
+ });
966
+ if (this.follow && result.followPath !== undefined) this.followPath = result.followPath;
967
+ if (!result.bytes) return;
968
+ if (log.pending) {
969
+ await this.showLog(entry, log);
970
+ if (this.formats.length > 0 && this.format.fmt !== "oneline" && !this.formatIsEmpty()) {
971
+ this.out.text(this.padding());
972
+ if (!this.shownDashes && this.formats.includes("stat") && this.formats.includes("patch")) {
973
+ this.out.text("---");
974
+ }
975
+ this.out.text("\n");
976
+ }
977
+ }
978
+ this.out.bytes(prefixLines(result.bytes, this.padding()));
979
+ }
980
+
981
+ /** combine-diff.c's diff_tree_combined for a merge */
982
+ private async combined(
983
+ entry: LogOutputEntry,
984
+ log: { pending: boolean; parent: ObjectId | undefined },
985
+ dense: boolean,
986
+ ): Promise<void> {
987
+ if (log.pending) {
988
+ await this.showLog(entry, log);
989
+ if (this.formats.length > 0 && !this.formatIsEmpty()) {
990
+ this.out.text(`${this.padding()}\n`);
991
+ }
992
+ }
993
+ // find_paths_generic prints the stat of the diff against the first parent as it scans
994
+ // (STAT_FORMAT_MASK: the summary too)
995
+ const stats = this.formats.filter(
996
+ (f) => f === "numstat" || f === "stat" || f === "shortstat" || f === "summary",
997
+ );
998
+ const follow = this.follow && this.followPath !== undefined ? this.followPath : undefined;
999
+ const first = this.diffParents(entry)[0];
1000
+ if (stats.length > 0 && first) {
1001
+ const width = this.graph ? this.graph.getWidth() : 0;
1002
+ const r = await this.host.diff(entry, first, stats, {
1003
+ ...(width ? { statWidth: 80 - width } : {}),
1004
+ ...(this.options.fullDiff ? { fullDiff: true } : {}),
1005
+ ...(follow !== undefined ? { follow } : {}),
1006
+ });
1007
+ if (r.bytes) this.out.bytes(prefixLines(r.bytes, this.padding()));
1008
+ }
1009
+ const names = this.formats.includes("name-only")
1010
+ ? "name-only"
1011
+ : this.formats.includes("name-status")
1012
+ ? "name-status"
1013
+ : undefined;
1014
+ const patch = this.formats.includes("patch");
1015
+ const parents = this.diffParents(entry);
1016
+ // --follow: find_paths_generic diffs the parents in order with one set of options, whose
1017
+ // pathspec try_to_follow_renames moves to the file a parent renamed or copied: the next
1018
+ // parents' diffs then list that path, not the one followed, and intersect_paths keeps
1019
+ // nothing; a rename or copy only the last parent finds is shown
1020
+ let parentPaths: string[] | undefined;
1021
+ let parentStatus: (string | undefined)[] | undefined;
1022
+ if (follow !== undefined) {
1023
+ parentPaths = [];
1024
+ parentStatus = [];
1025
+ for (let k = 0; k < parents.length; k++) {
1026
+ const r = await this.host.diff(entry, parents[k], [], { follow });
1027
+ if (r.followChange === undefined) {
1028
+ parentPaths.push(follow);
1029
+ parentStatus.push(undefined);
1030
+ continue;
1031
+ }
1032
+ if (k + 1 < parents.length) return;
1033
+ parentPaths.push(r.followPath ?? follow);
1034
+ parentStatus.push(r.followChange === ChangeType.COPY ? "C" : "R");
1035
+ }
1036
+ }
1037
+ const result = await this.host.combinedDiff(
1038
+ { ...entry, parents },
1039
+ {
1040
+ dense,
1041
+ ...(names ? { names } : {}),
1042
+ patch,
1043
+ ...(follow !== undefined ? { follow } : {}),
1044
+ ...(parentPaths ? { parentPaths } : {}),
1045
+ ...(parentStatus ? { parentStatus } : {}),
1046
+ },
1047
+ );
1048
+ if (!result.paths) return;
1049
+ // show_raw_diff writes names without the line prefix
1050
+ this.out.bytes(result.names);
1051
+ const needsep =
1052
+ names !== undefined ||
1053
+ this.formats.some(
1054
+ (f) => f === "stat" || f === "numstat" || f === "shortstat" || f === "summary",
1055
+ );
1056
+ if (patch) {
1057
+ if (needsep) this.out.text(`${this.padding()}\n`);
1058
+ this.out.bytes(prefixLines(result.patch, this.padding(), combinedBare));
1059
+ }
1060
+ }
1061
+
1062
+ /** log-tree.c's show_log */
1063
+ private async showLog(
1064
+ entry: LogOutputEntry,
1065
+ log: { pending: boolean; parent: ObjectId | undefined },
1066
+ ): Promise<void> {
1067
+ log.pending = false;
1068
+ const { fmt } = this.format;
1069
+ if (this.shownOne && !this.format.useTerminator) {
1070
+ if (!this.missingNewline) this.out.text(this.padding());
1071
+ this.out.text("\n");
1072
+ }
1073
+ this.shownOne = true;
1074
+ if (this.graph) this.out.text(this.graph.showCommit());
1075
+ const isMail = fmt === "email" || fmt === "mboxrd";
1076
+ if (isMail) {
1077
+ const mail = this.options.mail;
1078
+ const shownId = mail?.zeroCommit ? "0".repeat(entry.id.length) : entry.id;
1079
+ this.out.text(`From ${shownId} Mon Sep 17 00:00:00 2001\n`);
1080
+ this.out.text(this.oneline());
1081
+ const thread = mail?.threadHeaders?.(entry.id);
1082
+ if (thread) this.out.text(thread);
1083
+ } else if (fmt !== "user") {
1084
+ if (fmt !== "oneline") this.out.text("commit ");
1085
+ this.out.text(await this.abbrevId(entry.id, this.abbrevCommit));
1086
+ if (log.parent)
1087
+ this.out.text(` (from ${await this.abbrevId(log.parent, this.abbrevCommit)})`);
1088
+ if (this.decorate) this.out.text(formatRefDecorations(this.decorations, entry.id, {}));
1089
+ if (fmt === "oneline") this.out.text(" ");
1090
+ else {
1091
+ this.out.text("\n");
1092
+ this.out.text(this.oneline());
1093
+ }
1094
+ }
1095
+ let notes: string | undefined;
1096
+ if (this.showNotes) notes = await this.notesText(entry.id, fmt === "user");
1097
+ let msg = await this.prettyPrint(entry, notes ?? "");
1098
+ if (isMail && this.options.mail?.signoff)
1099
+ msg = appendSignoff(msg, this.options.mail.signoff, {}, true);
1100
+ if (fmt !== "user" && notes) {
1101
+ if (isMail) {
1102
+ msg += this.shownDashes ? "\n" : "---\n";
1103
+ this.shownDashes = true;
1104
+ }
1105
+ msg += notes;
1106
+ }
1107
+ this.missingNewline = !msg.endsWith("\n");
1108
+ this.out.text(this.graph ? this.graph.showCommitMessage(msg) : msg);
1109
+ if (this.format.useTerminator && !this.formatIsEmpty()) {
1110
+ if (!this.missingNewline) this.out.text(this.padding());
1111
+ this.out.text("\n");
1112
+ }
1113
+ }
1114
+
1115
+ /** notes.c's format_display_notes */
1116
+ private async notesText(id: ObjectId, raw: boolean): Promise<string> {
1117
+ let out = "";
1118
+ for (const { ref, text } of await this.host.notes(id)) {
1119
+ let msg = text;
1120
+ if (msg.endsWith("\n")) msg = msg.slice(0, -1);
1121
+ if (!raw) {
1122
+ if (ref === "refs/notes/commits") out += "\nNotes:\n";
1123
+ else out += `\nNotes (${ref.replace(/^refs\//, "").replace(/^notes\//, "")}):\n`;
1124
+ }
1125
+ if (msg === "") continue;
1126
+ for (const line of msg.split("\n")) out += `${raw ? "" : " "}${line}\n`;
1127
+ }
1128
+ return out;
1129
+ }
1130
+
1131
+ /** pretty.c's pretty_print_commit */
1132
+ private async prettyPrint(entry: LogOutputEntry, notes: string): Promise<string> {
1133
+ const { fmt } = this.format;
1134
+ const stored = (await this.host.rawCommit(entry.id)) ?? synthesizeRaw(entry.commit);
1135
+ let parsed = parseRaw(stored);
1136
+ // the message and the idents in UTF-8 (logmsg_reencode); the idents read from the
1137
+ // converted header then
1138
+ const reencoded = reencodeCommit(
1139
+ stored,
1140
+ parsed,
1141
+ fmt === "email" || fmt === "mboxrd" ? this.options.mail?.outputEncoding : undefined,
1142
+ );
1143
+ if (reencoded !== undefined) parsed = parseRaw(reencoded);
1144
+ // the idents as the (converted) header has them: bytes that are no UTF-8 kept
1145
+ const author = parsed.headerLines.find((l) => l.startsWith("author "));
1146
+ const committer = parsed.headerLines.find((l) => l.startsWith("committer "));
1147
+ const idents: { author: PersonIdent; committer: PersonIdent } = {
1148
+ author: (author && identOf(author)) || entry.commit.author,
1149
+ committer: (committer && identOf(committer)) || entry.commit.committer,
1150
+ };
1151
+ if (fmt === "user") {
1152
+ const commit: PrettyCommit = {
1153
+ ...entry.commit,
1154
+ ...idents,
1155
+ parents: entry.parents,
1156
+ message: parsed.body,
1157
+ };
1158
+ const mailmap = this.mailmap;
1159
+ return formatCommitPretty(this.format.user ?? "", commit, entry.id, {
1160
+ abbreviate: (id) => this.abbrevId(id, this.abbrevLength !== 40),
1161
+ ...(this.decorations ? { decorations: this.decorations } : {}),
1162
+ mark: this.graph ? "*" : "",
1163
+ // %N stays as written unless notes are shown
1164
+ ...(this.showNotes ? { notes } : {}),
1165
+ formatDate: (ident) => this.formatDate(ident),
1166
+ ...(mailmap && !mailmap.empty ? { mailmap: (n, e) => mailmap.map(n, e) } : {}),
1167
+ ...(this.options.now !== undefined ? { now: this.options.now } : {}),
1168
+ ...(this.options.localTzOffset ? { localTzOffset: this.options.localTzOffset } : {}),
1169
+ });
1170
+ }
1171
+ const isMail = fmt === "email" || fmt === "mboxrd";
1172
+ const indent = fmt === "oneline" || isMail ? 0 : 4;
1173
+ const mail = isMail ? this.options.mail : undefined;
1174
+ const inBody: string[] = [];
1175
+ let sb = "";
1176
+ // pp_header
1177
+ if (fmt === "raw") {
1178
+ for (const line of parsed.headerLines) sb += line;
1179
+ } else {
1180
+ if (fmt !== "oneline" && !isMail && entry.parents.length > 1) {
1181
+ sb += "Merge:";
1182
+ for (const p of entry.parents) sb += ` ${await this.abbrevId(p, this.abbrevLength !== 40)}`;
1183
+ sb += "\n";
1184
+ }
1185
+ if (fmt !== "oneline") {
1186
+ sb = this.userInfo(sb, "Author", idents.author, isMail, inBody);
1187
+ if (fmt === "full" || fmt === "fuller") {
1188
+ sb = this.userInfo(sb, "Commit", idents.committer, false);
1189
+ }
1190
+ }
1191
+ }
1192
+ if (fmt !== "oneline" && !isMail) sb += "\n";
1193
+ const lines = linesOf(parsed.body);
1194
+ let at = skipBlank(lines, 0);
1195
+ if (fmt === "oneline" || isMail) {
1196
+ const parts: string[] = [];
1197
+ for (; at < lines.length; at++) {
1198
+ const trimmed = rtrim(lines[at] as string);
1199
+ if (trimmed === "") {
1200
+ at++;
1201
+ break;
1202
+ }
1203
+ parts.push(trimmed);
1204
+ }
1205
+ const title = parts.join(mail?.preserveSubject ? "\n" : " ");
1206
+ if (fmt === "oneline") sb += `${title}\n`;
1207
+ else {
1208
+ sb += mail?.subject ? mail.subject(entry.id) : "Subject: [PATCH] ";
1209
+ if ((mail?.encodeHeaders ?? true) && needsRfc2047(title))
1210
+ sb += addRfc2047(sb, title, false, mail?.outputEncoding ?? "UTF-8");
1211
+ else sb += wrapText(title, -lastLineLength(sb), 1, 78);
1212
+ sb += "\n";
1213
+ // need_8bit_cte: a body (after the header) with a byte above 0x7f, or an in-body
1214
+ // header with one
1215
+ if (hasNonAscii(parsed.body) || inBody.some(hasNonAscii)) {
1216
+ sb += `MIME-Version: 1.0\nContent-Type: text/plain; charset=${mail?.outputEncoding ?? "UTF-8"}\nContent-Transfer-Encoding: 8bit\n`;
1217
+ }
1218
+ if (mail?.afterSubject) sb += mail.afterSubject;
1219
+ sb += "\n";
1220
+ if (inBody.length) sb += `${inBody.join("")}\n`;
1221
+ }
1222
+ }
1223
+ const beginningOfBody = sb.length;
1224
+ if (fmt !== "oneline") {
1225
+ // pp_remainder
1226
+ let first = true;
1227
+ for (; at < lines.length; at++) {
1228
+ const line = rtrim(lines[at] as string);
1229
+ if (line === "") {
1230
+ if (first) continue;
1231
+ if (fmt === "short") break;
1232
+ }
1233
+ first = false;
1234
+ const tabs = this.format.expandTabs;
1235
+ if (indent) sb += " ".repeat(indent) + (tabs ? tabExpand(line, tabs) : line);
1236
+ else if (tabs) sb += tabExpand(line, tabs);
1237
+ else {
1238
+ if (fmt === "mboxrd" && line.length > 4 && line.replace(/^>*/, "").startsWith("From ")) {
1239
+ sb += ">";
1240
+ }
1241
+ sb += line;
1242
+ }
1243
+ sb += "\n";
1244
+ }
1245
+ }
1246
+ sb = rtrim(sb);
1247
+ if (fmt !== "oneline") sb += "\n";
1248
+ if (isMail && sb.length <= beginningOfBody) sb += "\n";
1249
+ return sb;
1250
+ }
1251
+
1252
+ /** pretty.c's pp_user_info */
1253
+ private userInfo(
1254
+ sb: string,
1255
+ what: string,
1256
+ ident: PersonIdent,
1257
+ mail: boolean,
1258
+ inBody: string[] = [],
1259
+ ): string {
1260
+ let { name, email } = this.mapped(ident);
1261
+ let out = sb;
1262
+ const from = mail ? this.options.mail?.from : undefined;
1263
+ if (
1264
+ from &&
1265
+ (this.options.mail?.forceInBodyFrom || from.email !== email || from.name !== name)
1266
+ ) {
1267
+ inBody.push(`From: ${name} <${email}>\n`);
1268
+ name = from.name;
1269
+ email = from.email;
1270
+ }
1271
+ if (mail) {
1272
+ out += mailFromHeader(name, email, {
1273
+ encodeHeaders: this.options.mail?.encodeHeaders ?? true,
1274
+ encoding: this.options.mail?.outputEncoding ?? "UTF-8",
1275
+ });
1276
+ } else {
1277
+ out += `${what}: `;
1278
+ if (this.format.fmt === "fuller") out += " ";
1279
+ out += `${name} <${email}>\n`;
1280
+ }
1281
+ switch (this.format.fmt) {
1282
+ case "medium":
1283
+ out += `Date: ${this.formatDate(ident)}\n`;
1284
+ break;
1285
+ case "email":
1286
+ case "mboxrd":
1287
+ out += `Date: ${this.formatDate(ident, { type: "rfc2822", local: false })}\n`;
1288
+ break;
1289
+ case "fuller":
1290
+ out += `${what}Date: ${this.formatDate(ident)}\n`;
1291
+ break;
1292
+ }
1293
+ return out;
1294
+ }
1295
+
1296
+ /** The output so far */
1297
+ result(): Uint8Array {
1298
+ return this.out.result();
1299
+ }
1300
+ }
1301
+
1302
+ /** pathspec.c's magic names, as git lists them in its errors */
1303
+ const MAGIC_NAMES: [keyof { glob: 1; icase: 1; exclude: 1 }, string][] = [
1304
+ ["glob", "'glob'"],
1305
+ ["icase", "'icase'"],
1306
+ ["exclude", "'exclude' (mnemonic: '!')"],
1307
+ ];
1308
+
1309
+ /**
1310
+ * The path `--follow` follows (diff_check_follow_pathspec): exactly one element, with no
1311
+ * magic but `:(top)` and `:(literal)`; undefined otherwise, or git's error when `--follow`
1312
+ * was given.
1313
+ */
1314
+ function followPathOf(paths: string[], explicit: boolean): string | undefined {
1315
+ if (paths.length !== 1) {
1316
+ if (explicit) {
1317
+ throw new InvalidArgumentError("follow", paths, "--follow requires exactly one pathspec");
1318
+ }
1319
+ return undefined;
1320
+ }
1321
+ const item = parsePathspecItem(paths[0] as string, { attr: true });
1322
+ const names = MAGIC_NAMES.filter(([key]) => item[key]).map(([, name]) => name);
1323
+ if (item.attr) names.push("'attr'");
1324
+ if (names.length > 0) {
1325
+ if (explicit) {
1326
+ throw new InvalidArgumentError(
1327
+ "follow",
1328
+ paths,
1329
+ `pathspec magic not supported by --follow: ${names.join(", ")}`,
1330
+ );
1331
+ }
1332
+ return undefined;
1333
+ }
1334
+ return item.match;
1335
+ }
1336
+
1337
+ /** diff-merges.c's func_by_opt */
1338
+ export function mergesMode(value: string): LogDiffMerges | undefined {
1339
+ switch (value) {
1340
+ case "off":
1341
+ case "none":
1342
+ return "off";
1343
+ case "1":
1344
+ case "first-parent":
1345
+ return "first-parent";
1346
+ case "separate":
1347
+ case "m":
1348
+ case "on":
1349
+ return "separate";
1350
+ case "c":
1351
+ case "combined":
1352
+ return "combined";
1353
+ case "cc":
1354
+ case "dense-combined":
1355
+ return "dense-combined";
1356
+ default:
1357
+ return undefined;
1358
+ }
1359
+ }