@statewalker/vcs-commands 0.7.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 (410) 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/branch-command.d.ts +148 -18
  15. package/dist/commands/branch-command.d.ts.map +1 -1
  16. package/dist/commands/branch-info-command.d.ts +55 -0
  17. package/dist/commands/branch-info-command.d.ts.map +1 -0
  18. package/dist/commands/branch-tracking.d.ts +106 -17
  19. package/dist/commands/branch-tracking.d.ts.map +1 -1
  20. package/dist/commands/branch-upstream-command.d.ts +83 -0
  21. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  22. package/dist/commands/checkout-command.d.ts +19 -3
  23. package/dist/commands/checkout-command.d.ts.map +1 -1
  24. package/dist/commands/cherry-pick-command.d.ts +59 -0
  25. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  26. package/dist/commands/clean-command.d.ts +12 -0
  27. package/dist/commands/clean-command.d.ts.map +1 -1
  28. package/dist/commands/clone-command.d.ts.map +1 -1
  29. package/dist/commands/commit-command.d.ts +191 -5
  30. package/dist/commands/commit-command.d.ts.map +1 -1
  31. package/dist/commands/commit-reuse.d.ts +33 -0
  32. package/dist/commands/commit-reuse.d.ts.map +1 -0
  33. package/dist/commands/config-command.d.ts +236 -0
  34. package/dist/commands/config-command.d.ts.map +1 -0
  35. package/dist/commands/config-value-types.d.ts +91 -0
  36. package/dist/commands/config-value-types.d.ts.map +1 -0
  37. package/dist/commands/core-config.d.ts +20 -0
  38. package/dist/commands/core-config.d.ts.map +1 -1
  39. package/dist/commands/diff-color-config.d.ts +73 -0
  40. package/dist/commands/diff-color-config.d.ts.map +1 -0
  41. package/dist/commands/diff-command.d.ts +252 -5
  42. package/dist/commands/diff-command.d.ts.map +1 -1
  43. package/dist/commands/fetch-command.d.ts +20 -0
  44. package/dist/commands/fetch-command.d.ts.map +1 -1
  45. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  46. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  47. package/dist/commands/fork-point.d.ts +38 -0
  48. package/dist/commands/fork-point.d.ts.map +1 -0
  49. package/dist/commands/format-patch-command.d.ts +41 -1
  50. package/dist/commands/format-patch-command.d.ts.map +1 -1
  51. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  52. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  53. package/dist/commands/gc-command.d.ts +8 -0
  54. package/dist/commands/gc-command.d.ts.map +1 -1
  55. package/dist/commands/git-describe.d.ts +4 -0
  56. package/dist/commands/git-describe.d.ts.map +1 -1
  57. package/dist/commands/git-hooks.d.ts +35 -0
  58. package/dist/commands/git-hooks.d.ts.map +1 -1
  59. package/dist/commands/grep/grep-command.d.ts +210 -0
  60. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  61. package/dist/commands/grep/grep-engine.d.ts +218 -0
  62. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  63. package/dist/commands/grep/index.d.ts +3 -0
  64. package/dist/commands/grep/index.d.ts.map +1 -0
  65. package/dist/commands/index-adder.d.ts +13 -2
  66. package/dist/commands/index-adder.d.ts.map +1 -1
  67. package/dist/commands/index.d.ts +26 -0
  68. package/dist/commands/index.d.ts.map +1 -1
  69. package/dist/commands/index.js +3 -3
  70. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  71. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  72. package/dist/commands/local-transport.d.ts +36 -5
  73. package/dist/commands/local-transport.d.ts.map +1 -1
  74. package/dist/commands/log-command.d.ts +296 -11
  75. package/dist/commands/log-command.d.ts.map +1 -1
  76. package/dist/commands/log-graph.d.ts +26 -1
  77. package/dist/commands/log-graph.d.ts.map +1 -1
  78. package/dist/commands/log-output.d.ts +133 -5
  79. package/dist/commands/log-output.d.ts.map +1 -1
  80. package/dist/commands/ls-remote-command.d.ts +2 -0
  81. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  82. package/dist/commands/mailmap.d.ts +30 -0
  83. package/dist/commands/mailmap.d.ts.map +1 -1
  84. package/dist/commands/merge-base-command.d.ts +60 -0
  85. package/dist/commands/merge-base-command.d.ts.map +1 -0
  86. package/dist/commands/merge-bases.d.ts +23 -0
  87. package/dist/commands/merge-bases.d.ts.map +1 -1
  88. package/dist/commands/merge-command.d.ts +96 -9
  89. package/dist/commands/merge-command.d.ts.map +1 -1
  90. package/dist/commands/merge-support.d.ts.map +1 -1
  91. package/dist/commands/mv-command.d.ts +4 -0
  92. package/dist/commands/mv-command.d.ts.map +1 -1
  93. package/dist/commands/name-rev.d.ts +48 -0
  94. package/dist/commands/name-rev.d.ts.map +1 -0
  95. package/dist/commands/notes-command.d.ts.map +1 -1
  96. package/dist/commands/pathspec-file.d.ts +39 -0
  97. package/dist/commands/pathspec-file.d.ts.map +1 -0
  98. package/dist/commands/pathspec.d.ts +3 -0
  99. package/dist/commands/pathspec.d.ts.map +1 -1
  100. package/dist/commands/pretty-format.d.ts +43 -3
  101. package/dist/commands/pretty-format.d.ts.map +1 -1
  102. package/dist/commands/promisor-remote.d.ts.map +1 -1
  103. package/dist/commands/pull-command.d.ts +10 -0
  104. package/dist/commands/pull-command.d.ts.map +1 -1
  105. package/dist/commands/push-command.d.ts +160 -9
  106. package/dist/commands/push-command.d.ts.map +1 -1
  107. package/dist/commands/read-tree-command.d.ts +6 -0
  108. package/dist/commands/read-tree-command.d.ts.map +1 -1
  109. package/dist/commands/rebase-command.d.ts +168 -6
  110. package/dist/commands/rebase-command.d.ts.map +1 -1
  111. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  112. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  113. package/dist/commands/ref-filter/index.d.ts +8 -0
  114. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  115. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  116. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  117. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  118. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  119. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  120. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  121. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  122. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  123. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  124. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  125. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  126. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  127. package/dist/commands/reflog-command.d.ts +120 -0
  128. package/dist/commands/reflog-command.d.ts.map +1 -1
  129. package/dist/commands/reflog-walk.d.ts +72 -0
  130. package/dist/commands/reflog-walk.d.ts.map +1 -0
  131. package/dist/commands/remote-command.d.ts +138 -29
  132. package/dist/commands/remote-command.d.ts.map +1 -1
  133. package/dist/commands/remote-transport.d.ts +7 -1
  134. package/dist/commands/remote-transport.d.ts.map +1 -1
  135. package/dist/commands/reset-command.d.ts +2 -3
  136. package/dist/commands/reset-command.d.ts.map +1 -1
  137. package/dist/commands/restore-command.d.ts +2 -3
  138. package/dist/commands/restore-command.d.ts.map +1 -1
  139. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  140. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  141. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  142. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  143. package/dist/commands/rev-filter/index.d.ts +3 -0
  144. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  145. package/dist/commands/rev-list-command.d.ts +154 -2
  146. package/dist/commands/rev-list-command.d.ts.map +1 -1
  147. package/dist/commands/revert-command.d.ts +32 -0
  148. package/dist/commands/revert-command.d.ts.map +1 -1
  149. package/dist/commands/revision-range.d.ts +32 -1
  150. package/dist/commands/revision-range.d.ts.map +1 -1
  151. package/dist/commands/revision-resolver.d.ts +15 -0
  152. package/dist/commands/revision-resolver.d.ts.map +1 -1
  153. package/dist/commands/rm-command.d.ts +70 -2
  154. package/dist/commands/rm-command.d.ts.map +1 -1
  155. package/dist/commands/sequencer-pick.d.ts +84 -4
  156. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  157. package/dist/commands/sequencer-support.d.ts +2 -0
  158. package/dist/commands/sequencer-support.d.ts.map +1 -1
  159. package/dist/commands/serve-repository.d.ts +7 -0
  160. package/dist/commands/serve-repository.d.ts.map +1 -1
  161. package/dist/commands/show-command.d.ts +130 -0
  162. package/dist/commands/show-command.d.ts.map +1 -0
  163. package/dist/commands/show-commit.d.ts +11 -0
  164. package/dist/commands/show-commit.d.ts.map +1 -0
  165. package/dist/commands/signature-check.d.ts +164 -0
  166. package/dist/commands/signature-check.d.ts.map +1 -0
  167. package/dist/commands/signing.d.ts +160 -0
  168. package/dist/commands/signing.d.ts.map +1 -0
  169. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  170. package/dist/commands/sparse-index-view.d.ts +45 -0
  171. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  172. package/dist/commands/ssh-signer.d.ts +29 -0
  173. package/dist/commands/ssh-signer.d.ts.map +1 -0
  174. package/dist/commands/ssh-verifier.d.ts +42 -0
  175. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  176. package/dist/commands/stash-apply-command.d.ts +5 -0
  177. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  178. package/dist/commands/stash-branch-command.d.ts +34 -0
  179. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  180. package/dist/commands/stash-create-command.d.ts +17 -0
  181. package/dist/commands/stash-create-command.d.ts.map +1 -1
  182. package/dist/commands/stash-info.d.ts +93 -0
  183. package/dist/commands/stash-info.d.ts.map +1 -0
  184. package/dist/commands/stash-list-command.d.ts +16 -0
  185. package/dist/commands/stash-list-command.d.ts.map +1 -1
  186. package/dist/commands/stash-pop-command.d.ts +39 -0
  187. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  188. package/dist/commands/stash-show-command.d.ts +48 -0
  189. package/dist/commands/stash-show-command.d.ts.map +1 -0
  190. package/dist/commands/stash-store-command.d.ts +29 -0
  191. package/dist/commands/stash-store-command.d.ts.map +1 -0
  192. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  193. package/dist/commands/status-command.d.ts.map +1 -1
  194. package/dist/commands/status-header.d.ts +5 -0
  195. package/dist/commands/status-header.d.ts.map +1 -1
  196. package/dist/commands/submodule-add-command.d.ts +89 -0
  197. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  198. package/dist/commands/submodule-auth.d.ts +90 -0
  199. package/dist/commands/submodule-auth.d.ts.map +1 -0
  200. package/dist/commands/submodule-commands.d.ts +375 -0
  201. package/dist/commands/submodule-commands.d.ts.map +1 -0
  202. package/dist/commands/submodule-model.d.ts +288 -0
  203. package/dist/commands/submodule-model.d.ts.map +1 -0
  204. package/dist/commands/submodule-update-command.d.ts +198 -0
  205. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  206. package/dist/commands/switch-command.d.ts.map +1 -1
  207. package/dist/commands/tag-command.d.ts +259 -10
  208. package/dist/commands/tag-command.d.ts.map +1 -1
  209. package/dist/commands/trailers.d.ts +218 -17
  210. package/dist/commands/trailers.d.ts.map +1 -1
  211. package/dist/commands/tree-restore.d.ts +7 -0
  212. package/dist/commands/tree-restore.d.ts.map +1 -1
  213. package/dist/commands/verify-command.d.ts +92 -0
  214. package/dist/commands/verify-command.d.ts.map +1 -0
  215. package/dist/commands/worktree-add-command.d.ts +79 -7
  216. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  217. package/dist/commands/worktree-path-rules.d.ts +66 -0
  218. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  219. package/dist/commands/worktree-remove-command.d.ts +10 -3
  220. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  221. package/dist/commands/worktree-repair-command.d.ts +15 -2
  222. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  223. package/dist/commands/worktree-support.d.ts +5 -0
  224. package/dist/commands/worktree-support.d.ts.map +1 -1
  225. package/dist/{commands-DIJ91NnD.js → commands-ISM52N0n.js} +70736 -54492
  226. package/dist/errors/checkout-errors.d.ts +19 -0
  227. package/dist/errors/checkout-errors.d.ts.map +1 -1
  228. package/dist/errors/command-errors.d.ts.map +1 -1
  229. package/dist/errors/index.js +57 -3
  230. package/dist/errors/ref-errors.d.ts +19 -0
  231. package/dist/errors/ref-errors.d.ts.map +1 -1
  232. package/dist/errors/worktree-errors.d.ts +6 -1
  233. package/dist/errors/worktree-errors.d.ts.map +1 -1
  234. package/dist/{git-command-BGiOJ8Zk.js → fsck-DLRpbwTj.js} +6230 -71
  235. package/dist/git-command.d.ts +27 -1
  236. package/dist/git-command.d.ts.map +1 -1
  237. package/dist/git.d.ts +267 -1
  238. package/dist/git.d.ts.map +1 -1
  239. package/dist/index.js +5 -5
  240. package/dist/remote-config/index.d.ts +1 -1
  241. package/dist/remote-config/index.d.ts.map +1 -1
  242. package/dist/remote-config/remote-config-store.d.ts +55 -0
  243. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  244. package/dist/results/combined-diff.d.ts +3 -0
  245. package/dist/results/combined-diff.d.ts.map +1 -1
  246. package/dist/results/diff-check.d.ts +38 -0
  247. package/dist/results/diff-check.d.ts.map +1 -0
  248. package/dist/results/diff-color.d.ts +135 -0
  249. package/dist/results/diff-color.d.ts.map +1 -0
  250. package/dist/results/diff-output.d.ts +85 -1
  251. package/dist/results/diff-output.d.ts.map +1 -1
  252. package/dist/results/diff-pickaxe.d.ts +67 -0
  253. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  254. package/dist/results/diff-words.d.ts +55 -0
  255. package/dist/results/diff-words.d.ts.map +1 -0
  256. package/dist/results/index.d.ts +4 -0
  257. package/dist/results/index.d.ts.map +1 -1
  258. package/dist/results/index.js +2 -2
  259. package/dist/results/push-result.d.ts +7 -0
  260. package/dist/results/push-result.d.ts.map +1 -1
  261. package/dist/results/rebase-result.d.ts +2 -0
  262. package/dist/results/rebase-result.d.ts.map +1 -1
  263. package/dist/results/stash-result.d.ts +6 -0
  264. package/dist/results/stash-result.d.ts.map +1 -1
  265. package/dist/{results-WVlBhVb1.js → results-TB2IJ64h.js} +2168 -403
  266. package/dist/whitespace/index.d.ts +2 -0
  267. package/dist/whitespace/index.d.ts.map +1 -0
  268. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  269. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  270. package/package.json +12 -12
  271. package/src/commands/add-command.ts +178 -17
  272. package/src/commands/am/am-command.ts +262 -42
  273. package/src/commands/am/index.ts +1 -0
  274. package/src/commands/am/mailsplit.ts +326 -0
  275. package/src/commands/apply/apply-command.ts +6 -6
  276. package/src/commands/apply/apply-engine.ts +1 -1
  277. package/src/commands/apply/apply-parse.ts +7 -8
  278. package/src/commands/bisect/bisect-command.ts +18 -5
  279. package/src/commands/branch-command.ts +528 -53
  280. package/src/commands/branch-info-command.ts +150 -0
  281. package/src/commands/branch-tracking.ts +335 -60
  282. package/src/commands/branch-upstream-command.ts +218 -0
  283. package/src/commands/checkout-command.ts +69 -43
  284. package/src/commands/cherry-pick-command.ts +143 -0
  285. package/src/commands/clean-command.ts +34 -3
  286. package/src/commands/clone-command.ts +2 -1
  287. package/src/commands/commit-command.ts +782 -64
  288. package/src/commands/commit-reuse.ts +94 -0
  289. package/src/commands/config-command.ts +1256 -0
  290. package/src/commands/config-value-types.ts +358 -0
  291. package/src/commands/core-config.ts +40 -0
  292. package/src/commands/diff-color-config.ts +274 -0
  293. package/src/commands/diff-command.ts +1009 -49
  294. package/src/commands/fetch-command.ts +142 -8
  295. package/src/commands/fmt-merge-msg-command.ts +715 -0
  296. package/src/commands/fork-point.ts +63 -0
  297. package/src/commands/format-patch-command.ts +314 -46
  298. package/src/commands/fsck/fetch-fsck.ts +172 -18
  299. package/src/commands/gc-command.ts +31 -1
  300. package/src/commands/git-describe.ts +31 -11
  301. package/src/commands/git-hooks.ts +81 -0
  302. package/src/commands/grep/grep-command.ts +1077 -0
  303. package/src/commands/grep/grep-engine.ts +1024 -0
  304. package/src/commands/grep/index.ts +2 -0
  305. package/src/commands/index-adder.ts +46 -7
  306. package/src/commands/index.ts +26 -0
  307. package/src/commands/interpret-trailers-command.ts +256 -0
  308. package/src/commands/local-transport.ts +109 -10
  309. package/src/commands/log-command.ts +1246 -210
  310. package/src/commands/log-graph.ts +123 -26
  311. package/src/commands/log-output.ts +280 -21
  312. package/src/commands/ls-remote-command.ts +5 -0
  313. package/src/commands/mailmap.ts +119 -0
  314. package/src/commands/merge-base-command.ts +170 -0
  315. package/src/commands/merge-bases.ts +63 -8
  316. package/src/commands/merge-command.ts +330 -82
  317. package/src/commands/merge-support.ts +14 -1
  318. package/src/commands/mv-command.ts +6 -3
  319. package/src/commands/name-rev.ts +171 -0
  320. package/src/commands/notes-command.ts +11 -1
  321. package/src/commands/pathspec-file.ts +72 -0
  322. package/src/commands/pathspec.ts +14 -2
  323. package/src/commands/pretty-format.ts +103 -19
  324. package/src/commands/promisor-remote.ts +10 -1
  325. package/src/commands/pull-command.ts +26 -7
  326. package/src/commands/push-command.ts +682 -65
  327. package/src/commands/read-tree-command.ts +28 -1
  328. package/src/commands/rebase-command.ts +933 -129
  329. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  330. package/src/commands/ref-filter/index.ts +7 -0
  331. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  332. package/src/commands/ref-filter/ref-filter.ts +651 -0
  333. package/src/commands/ref-filter/ref-format.ts +1070 -0
  334. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  335. package/src/commands/ref-filter/ref-quote.ts +69 -0
  336. package/src/commands/ref-filter/version-compare.ts +177 -0
  337. package/src/commands/reflog-command.ts +492 -2
  338. package/src/commands/reflog-walk.ts +234 -0
  339. package/src/commands/remote-command.ts +449 -69
  340. package/src/commands/remote-transport.ts +9 -1
  341. package/src/commands/reset-command.ts +36 -31
  342. package/src/commands/restore-command.ts +12 -41
  343. package/src/commands/rev-filter/commit-filter.ts +159 -0
  344. package/src/commands/rev-filter/commit-grep.ts +444 -0
  345. package/src/commands/rev-filter/index.ts +2 -0
  346. package/src/commands/rev-list-command.ts +402 -15
  347. package/src/commands/revert-command.ts +82 -0
  348. package/src/commands/revision-range.ts +204 -4
  349. package/src/commands/revision-resolver.ts +23 -8
  350. package/src/commands/rm-command.ts +282 -21
  351. package/src/commands/sequencer-pick.ts +498 -85
  352. package/src/commands/sequencer-support.ts +20 -2
  353. package/src/commands/serve-repository.ts +18 -3
  354. package/src/commands/show-command.ts +490 -0
  355. package/src/commands/show-commit.ts +24 -0
  356. package/src/commands/signature-check.ts +657 -0
  357. package/src/commands/signing.ts +385 -0
  358. package/src/commands/sparse-checkout-command.ts +2 -9
  359. package/src/commands/sparse-checkout-support.ts +2 -2
  360. package/src/commands/sparse-index-view.ts +135 -0
  361. package/src/commands/ssh-signer.ts +199 -0
  362. package/src/commands/ssh-verifier.ts +523 -0
  363. package/src/commands/stash-apply-command.ts +16 -4
  364. package/src/commands/stash-branch-command.ts +88 -0
  365. package/src/commands/stash-create-command.ts +28 -0
  366. package/src/commands/stash-info.ts +243 -0
  367. package/src/commands/stash-list-command.ts +33 -0
  368. package/src/commands/stash-pop-command.ts +83 -0
  369. package/src/commands/stash-show-command.ts +141 -0
  370. package/src/commands/stash-store-command.ts +82 -0
  371. package/src/commands/stash-working-tree.ts +2 -2
  372. package/src/commands/status-command.ts +5 -2
  373. package/src/commands/status-header.ts +41 -7
  374. package/src/commands/submodule-add-command.ts +509 -0
  375. package/src/commands/submodule-auth.ts +276 -0
  376. package/src/commands/submodule-commands.ts +1517 -0
  377. package/src/commands/submodule-model.ts +930 -0
  378. package/src/commands/submodule-update-command.ts +1092 -0
  379. package/src/commands/switch-command.ts +3 -1
  380. package/src/commands/tag-command.ts +876 -64
  381. package/src/commands/trailers.ts +837 -100
  382. package/src/commands/tree-restore.ts +38 -10
  383. package/src/commands/verify-command.ts +235 -0
  384. package/src/commands/worktree-add-command.ts +268 -24
  385. package/src/commands/worktree-path-rules.ts +183 -0
  386. package/src/commands/worktree-remove-command.ts +39 -5
  387. package/src/commands/worktree-repair-command.ts +52 -5
  388. package/src/commands/worktree-support.ts +22 -1
  389. package/src/errors/checkout-errors.ts +29 -0
  390. package/src/errors/command-errors.ts +2 -1
  391. package/src/errors/ref-errors.ts +23 -0
  392. package/src/errors/worktree-errors.ts +8 -1
  393. package/src/git-command.ts +66 -1
  394. package/src/git.ts +404 -1
  395. package/src/remote-config/index.ts +2 -0
  396. package/src/remote-config/remote-config-store.ts +101 -0
  397. package/src/results/combined-diff.ts +38 -18
  398. package/src/results/diff-check.ts +185 -0
  399. package/src/results/diff-color.ts +868 -0
  400. package/src/results/diff-output.ts +195 -30
  401. package/src/results/diff-pickaxe.ts +304 -0
  402. package/src/results/diff-words.ts +395 -0
  403. package/src/results/index.ts +4 -0
  404. package/src/results/push-result.ts +7 -0
  405. package/src/results/rebase-result.ts +3 -0
  406. package/src/results/stash-result.ts +7 -0
  407. package/src/whitespace/index.ts +1 -0
  408. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  409. package/dist/commands/apply/whitespace.d.ts +0 -58
  410. package/dist/commands/apply/whitespace.d.ts.map +0 -1
@@ -7,8 +7,10 @@ import {
7
7
  canonTreeMode,
8
8
  commitFromBytes,
9
9
  type GitObject,
10
+ isSymbolicRef,
10
11
  type ObjectId,
11
12
  type ObjectReplacements,
13
+ type PersonIdent,
12
14
  parseGraphCommit,
13
15
  replacementOf,
14
16
  } from "@statewalker/vcs-core";
@@ -16,27 +18,44 @@ import { ByteSink, OrderedMap, parseGitBool, type XdiffAlgorithm } from "@statew
16
18
  import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
17
19
  import { bytesToHex, hexToBytes } from "@statewalker/vcs-utils/hash/utils";
18
20
 
19
- import {
20
- type AttributesResolver,
21
- type ContentAttributesContext,
22
- expandUserPath,
23
- } from "@statewalker/vcs-working-tree";
21
+ import type { AttributesResolver, ContentAttributesContext } from "@statewalker/vcs-working-tree";
24
22
 
25
- import { GitApiError, IncompatibleOptionsError } from "../errors/index.js";
23
+ import {
24
+ GitApiError,
25
+ IncompatibleOptionsError,
26
+ InvalidArgumentError,
27
+ InvalidConfigError,
28
+ NotImplementedError,
29
+ } from "../errors/index.js";
26
30
  import { GitCommand } from "../git-command.js";
27
31
  import { RemoteConfigStore } from "../remote-config/index.js";
28
32
  import { type CombinedDiffOptions, writeCombinedDiff } from "../results/combined-diff.js";
33
+ import type { DiffColors } from "../results/diff-color.js";
34
+ import { DiffPickaxe } from "../results/diff-pickaxe.js";
29
35
  import { quotePath } from "../results/quote-path.js";
30
36
  import { bareAttributesResolver } from "./attributes-source.js";
31
- import { DiffCommand, type DiffTextOptions } from "./diff-command.js";
37
+ import { parseGitColor } from "./config-value-types.js";
38
+ import {
39
+ DEFAULT_DECORATION_COLORS,
40
+ type DiffColorSettings,
41
+ readDiffColorSettings,
42
+ } from "./diff-color-config.js";
43
+ import {
44
+ checkPickaxeOptions,
45
+ DiffCommand,
46
+ type DiffTextOptions,
47
+ hasPickaxe,
48
+ } from "./diff-command.js";
32
49
  import { hostEnvironmentOf } from "./git-ident.js";
50
+ import { GRAPH_COLUMN_COLORS_ANSI, graphColumnColors } from "./log-graph.js";
33
51
  import {
34
52
  type LogOutputEntry,
35
53
  type LogOutputHost,
36
54
  type LogOutputOptions,
37
55
  LogPrinter,
56
+ type LogReflogEntry,
38
57
  } from "./log-output.js";
39
- import { Mailmap } from "./mailmap.js";
58
+ import { type Mailmap, readRepositoryMailmap } from "./mailmap.js";
40
59
  import { configBool, configValue } from "./merge-config.js";
41
60
  import {
42
61
  addRefsByGlob,
@@ -64,8 +83,24 @@ import {
64
83
  treePathspec,
65
84
  } from "./pathspec.js";
66
85
  import { PathspecAttributes } from "./pathspec-attributes.js";
67
- import { loadRefDecorations } from "./pretty-format.js";
86
+ import { type DecorationPalette, loadRefDecorations } from "./pretty-format.js";
87
+ import { openReflogWalk, walkReflogs } from "./reflog-walk.js";
88
+ import {
89
+ type CommitFilter,
90
+ CommitFilters,
91
+ type FilteredCommit,
92
+ type GrepPatternType,
93
+ } from "./rev-filter/index.js";
94
+ import {
95
+ checkSignature,
96
+ mergetagsOf,
97
+ parseBufferSignedByHeader,
98
+ parseSignature,
99
+ type SignatureCheck,
100
+ verifyCommitBytes,
101
+ } from "./signature-check.js";
68
102
  import { readDiffSubmoduleConfig } from "./submodule-summary.js";
103
+ import { shortenUnambiguousRef } from "./worktree-list-command.js";
69
104
 
70
105
  /** What {@link LogCommand.callBytes} asks of the walk. */
71
106
  interface OutputWalk {
@@ -81,6 +116,20 @@ interface OutputWalk {
81
116
  unwalkedShown?: Set<ObjectId>;
82
117
  }
83
118
 
119
+ /** A commit given to the walk: excluded or not, and the name it was given by. */
120
+ interface PendingCommit {
121
+ id: ObjectId;
122
+ exclude: boolean;
123
+ name?: string;
124
+ }
125
+
126
+ /** git's get_revision under `--reverse`: every commit read first, then given oldest first. */
127
+ async function* reversed<T>(source: AsyncIterable<T>): AsyncIterable<T> {
128
+ const all: T[] = [];
129
+ for await (const item of source) all.push(item);
130
+ for (let i = all.length - 1; i >= 0; i--) yield all[i] as T;
131
+ }
132
+
84
133
  /** git log reads no index: the in-tree attributes files are the worktree's only. */
85
134
  const NO_INDEX = { attributesBlob: () => undefined };
86
135
 
@@ -92,8 +141,50 @@ const NO_INDEX = { attributesBlob: () => undefined };
92
141
  export interface LogResult extends Commit {
93
142
  /** The SHA-1 object ID of the commit */
94
143
  id: ObjectId;
144
+ /**
145
+ * A boundary commit ({@link LogCommand.setBoundary}): a parent of a commit listed that is
146
+ * not listed itself, given after the others (git's `BOUNDARY`, the `-` mark)
147
+ */
148
+ boundary?: boolean;
149
+ /**
150
+ * The name the commit was reached from ({@link LogCommand.setSource}, git's `--source`):
151
+ * the revision as given, or the ref `--all`, `--branches`... named
152
+ */
153
+ source?: string;
154
+ /** In a reflog walk ({@link LogCommand.addReflogWalk}), the entry the commit is listed for */
155
+ reflog?: LogReflogEntry;
156
+ }
157
+
158
+ /**
159
+ * What `git show` prints through one log printer (see {@link LogCommand.showSession}).
160
+ *
161
+ * @internal
162
+ */
163
+ export interface ShowSession {
164
+ /** Shows a commit as git show does; false when it was not shown (already, or TREESAME) */
165
+ commit(id: ObjectId): Promise<boolean>;
166
+ /** The newline before a tag or tree once something was shown */
167
+ separate(): void;
168
+ /** Marks something shown (a tag's or tree's header) */
169
+ markShown(): void;
170
+ text(text: string): void;
171
+ bytes(bytes: Uint8Array): void;
172
+ /** A tag's `tagger` line as `Tagger:` (and its date) in the format */
173
+ tagger(ident: PersonIdent): void;
174
+ /** Everything printed */
175
+ result(): Uint8Array;
176
+ /** The `color.diff.commit` color and its reset of a tag's or tree's header ("" without color) */
177
+ readonly commitColor: { set: string; reset: string };
95
178
  }
96
179
 
180
+ /**
181
+ * The order of the commits listed: git's `--topo-order` (`topo`: no parent before all its
182
+ * children, a line of history kept together), `--date-order` (`date`: no parent before its
183
+ * children, else newest commit date first), `--author-date-order` (`author-date`: as `date`
184
+ * by author date).
185
+ */
186
+ export type LogOrder = "topo" | "date" | "author-date";
187
+
97
188
  /**
98
189
  * What a path-limited walk did (git's trace2 `bloom` statistics, and the tree work behind
99
190
  * them): how often the changed-path filters answered, and how many tree entries the walk read
@@ -189,7 +280,7 @@ export enum RevFilter {
189
280
  export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
190
281
  private startCommits: ObjectId[] = [];
191
282
  /** The commits given, included and excluded, in the order given (git's pending list) */
192
- private readonly pending: { id: ObjectId; exclude: boolean }[] = [];
283
+ private readonly pending: PendingCommit[] = [];
193
284
  private paths: string[] = [];
194
285
  private excludePaths: string[] = [];
195
286
  private maxCount?: number;
@@ -205,6 +296,21 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
205
296
  private authorPattern?: string;
206
297
  private committerPattern?: string;
207
298
  private revFilter = RevFilter.ALL;
299
+ /** `--grep` patterns */
300
+ private readonly grepMessages: string[] = [];
301
+ /** `--author` patterns */
302
+ private readonly grepAuthors: string[] = [];
303
+ /** `--committer` patterns */
304
+ private readonly grepCommitters: string[] = [];
305
+ private allMatch = false;
306
+ private invertGrep = false;
307
+ private regexpIgnoreCase = false;
308
+ private patternType?: GrepPatternType;
309
+ private useMailmap?: boolean;
310
+ private logConfig = true;
311
+ private readonly commitFilters: CommitFilter[] = [];
312
+ /** The filter of the walk under way (git's options and the added filters) */
313
+ private activeFilter?: CommitFilter;
208
314
  private useBloomFilters = true;
209
315
  private readonly statistics: LogPathStatistics = {
210
316
  bloomDefinitelyNot: 0,
@@ -218,6 +324,140 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
218
324
  private lastWalk: RevTable | undefined;
219
325
  /** Set while {@link callBytes} collects the walk for its output */
220
326
  private outputWalk: OutputWalk | undefined;
327
+ /** `-g <ref>...`: the reflogs walked instead of the history (names as given) */
328
+ private reflogWalkNames?: string[];
329
+ /** `--grep-reflog` patterns */
330
+ private readonly grepReflogs: string[] = [];
331
+ /** The git version whose behaviour differs where versions differ */
332
+ private compatibility: "2.43" | "2.56" = "2.56";
333
+ /** `--topo-order`, `--date-order`, `--author-date-order` */
334
+ private order?: LogOrder;
335
+ /** `--reverse` */
336
+ private reverse = false;
337
+ /** `--boundary` */
338
+ private boundary = false;
339
+ /** `--source` */
340
+ private source = false;
341
+
342
+ /**
343
+ * The order of the commits ({@link LogOrder}); undefined is git's default, newest commit
344
+ * date first as the walk meets them. A sorted walk reads the whole history it lists
345
+ * before giving the first commit.
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * // git rev-list --topo-order main
350
+ * await git.log().add(main).setOrder("topo").call();
351
+ * ```
352
+ */
353
+ setOrder(order: LogOrder | undefined): this {
354
+ this.checkCallable();
355
+ this.order = order;
356
+ return this;
357
+ }
358
+
359
+ /**
360
+ * `--reverse`: the commits chosen (after `-n` and `--skip`, boundary commits included)
361
+ * given oldest first.
362
+ */
363
+ setReverse(reverse: boolean): this {
364
+ this.checkCallable();
365
+ this.reverse = reverse;
366
+ return this;
367
+ }
368
+
369
+ /**
370
+ * `--boundary`: after the commits listed, the parents of those that are not listed
371
+ * themselves (excluded, cut by `-n`, `--since` or a filter), each with `boundary: true`,
372
+ * as git's get_revision lists them (sorted as `sort_in_topological_order` sorts them).
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * // git rev-list --boundary main..topic
377
+ * for await (const c of await git.log().addRange(main, topic).setBoundary(true).call())
378
+ * console.log(`${c.boundary ? "-" : ""}${c.id}`);
379
+ * ```
380
+ */
381
+ setBoundary(boundary: boolean): this {
382
+ this.checkCallable();
383
+ this.boundary = boundary;
384
+ return this;
385
+ }
386
+
387
+ /**
388
+ * `--source`: each commit carries the name it was reached from (`source`): the name given
389
+ * to {@link add}/{@link not}, the ref of {@link all}, `HEAD` for the default, passed from
390
+ * child to parent as the walk goes (the first name to reach a commit wins).
391
+ */
392
+ setSource(source: boolean): this {
393
+ this.checkCallable();
394
+ this.source = source;
395
+ return this;
396
+ }
397
+
398
+ /**
399
+ * `git log -g <ref>` (`--walk-reflogs`) for the printed log ({@link callText}): the
400
+ * commits of `ref`'s reflog, newest entry first, each shown with its entry (`Reflog:`
401
+ * lines, `<sel>: <message>` under `--oneline`, `%gd`/`%gD`/`%gs`/`%gn`/`%ge` in a format,
402
+ * `<ref>@{<date>}` under an explicit `--date`). `-n`, `--skip` and the commit filters
403
+ * (`--grep`, `--author`...) apply; entries whose object is no commit are passed over.
404
+ */
405
+ setReflogWalk(ref: string): this {
406
+ this.checkCallable();
407
+ this.reflogWalkNames = [ref];
408
+ return this;
409
+ }
410
+
411
+ /**
412
+ * One more reflog of a reflog walk (`git log -g <name>...`): `HEAD`, `main`,
413
+ * `refs/heads/main`, with a selector of its first entry (`main@{2}`, `HEAD@{now}`,
414
+ * `@{0}` for the current branch, `@{-1}`). The walk takes the newest of the logs' entries
415
+ * each time (reflog-walk.c), so several logs interleave by date; a name without a reflog
416
+ * shows nothing. {@link call} gives the commits, {@link callText} the log with each entry.
417
+ *
418
+ * @example
419
+ * ```typescript
420
+ * // git log -g --format='%gd %gs' HEAD main
421
+ * await git.log().addReflogWalk("HEAD").addReflogWalk("main").callText({ pretty: "format:%gd %gs" });
422
+ * ```
423
+ */
424
+ addReflogWalk(name: string): this {
425
+ this.checkCallable();
426
+ this.reflogWalkNames = [...(this.reflogWalkNames ?? []), name];
427
+ return this;
428
+ }
429
+
430
+ /**
431
+ * `-g` / `--walk-reflogs`: walk reflogs instead of history, those {@link addReflogWalk}
432
+ * names, HEAD's when it names none (`git log -g`).
433
+ */
434
+ setWalkReflogs(walk: boolean): this {
435
+ this.checkCallable();
436
+ if (!walk) this.reflogWalkNames = undefined;
437
+ else this.reflogWalkNames ??= [];
438
+ return this;
439
+ }
440
+
441
+ /**
442
+ * The git version to follow where versions differ (default 2.56): 2.43 refuses a reflog
443
+ * walk's `--reverse` before a sorted walk (`--topo-order`, `--graph`), 2.56 after.
444
+ */
445
+ setCompatibility(version: "2.43" | "2.56"): this {
446
+ this.checkCallable();
447
+ this.compatibility = version;
448
+ return this;
449
+ }
450
+
451
+ /**
452
+ * `--grep-reflog=<pattern>`: a reflog walk shows only entries whose message matches (a
453
+ * header pattern beside `--author`/`--committer`, combined with `--grep` as git's
454
+ * commit_match). Without a reflog walk the log dies, as git does.
455
+ */
456
+ addGrepReflog(pattern: string): this {
457
+ this.checkCallable();
458
+ this.grepReflogs.push(pattern);
459
+ return this;
460
+ }
221
461
 
222
462
  /**
223
463
  * Add a starting commit for the log.
@@ -227,11 +467,12 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
227
467
  * peels it; with {@link all} the refs are walked besides (`git log --all <commit>`).
228
468
  *
229
469
  * @param commit ObjectId of commit to start from
470
+ * @param name The name it was given by, which {@link setSource} reports (the id without)
230
471
  */
231
- add(commit: ObjectId): this {
472
+ add(commit: ObjectId, name?: string): this {
232
473
  this.checkCallable();
233
474
  this.startCommits.push(commit);
234
- this.pending.push({ id: commit, exclude: false });
475
+ this.pending.push({ id: commit, exclude: false, ...(name !== undefined ? { name } : {}) });
235
476
  return this;
236
477
  }
237
478
 
@@ -333,10 +574,11 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
333
574
  * Useful for finding commits in one branch but not another.
334
575
  *
335
576
  * @param commit ObjectId to exclude along with its ancestors
577
+ * @param name The name it was given by (see {@link add})
336
578
  */
337
- not(commit: ObjectId): this {
579
+ not(commit: ObjectId, name?: string): this {
338
580
  this.checkCallable();
339
- this.pending.push({ id: commit, exclude: true });
581
+ this.pending.push({ id: commit, exclude: true, ...(name !== undefined ? { name } : {}) });
340
582
  return this;
341
583
  }
342
584
 
@@ -409,6 +651,106 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
409
651
  return this;
410
652
  }
411
653
 
654
+ /**
655
+ * `--grep=<pattern>`: commits whose message has a line matching the pattern (several:
656
+ * any of them, every one with {@link setAllMatch}). Patterns are basic POSIX regexes unless
657
+ * {@link setPatternType} or `grep.patternType`/`grep.extendedRegexp` say otherwise, matched
658
+ * as git's grep.c matches them (`--grep=` matches every commit with a message part).
659
+ *
660
+ * @example
661
+ * ```typescript
662
+ * // git log --grep=fix --grep=bug --all-match -i
663
+ * await git.log().addGrep("fix").addGrep("bug").setAllMatch(true).setRegexpIgnoreCase(true).call();
664
+ * ```
665
+ */
666
+ addGrep(pattern: string): this {
667
+ this.checkCallable();
668
+ this.grepMessages.push(pattern);
669
+ return this;
670
+ }
671
+
672
+ /**
673
+ * `--author=<pattern>`: commits whose `author` header line (name and email, the date left
674
+ * out; mapped through the mailmap under `log.mailmap`) matches the pattern; several are
675
+ * or-ed. Unlike {@link setAuthorFilter}, the pattern is git's (a basic regex, case-sensitive
676
+ * without {@link setRegexpIgnoreCase}).
677
+ */
678
+ addAuthor(pattern: string): this {
679
+ this.checkCallable();
680
+ this.grepAuthors.push(pattern);
681
+ return this;
682
+ }
683
+
684
+ /** `--committer=<pattern>`: as {@link addAuthor}, on the `committer` header line. */
685
+ addCommitter(pattern: string): this {
686
+ this.checkCallable();
687
+ this.grepCommitters.push(pattern);
688
+ return this;
689
+ }
690
+
691
+ /** `--all-match`: every `--grep` pattern must match (author and committer patterns always must). */
692
+ setAllMatch(allMatch: boolean): this {
693
+ this.checkCallable();
694
+ this.allMatch = allMatch;
695
+ return this;
696
+ }
697
+
698
+ /** `--invert-grep`: commits whose message matches no `--grep` pattern (not `--author`'s). */
699
+ setInvertGrep(invert: boolean): this {
700
+ this.checkCallable();
701
+ this.invertGrep = invert;
702
+ return this;
703
+ }
704
+
705
+ /** `-i` / `--regexp-ignore-case`: the patterns fold ASCII case. */
706
+ setRegexpIgnoreCase(ignoreCase: boolean): this {
707
+ this.checkCallable();
708
+ this.regexpIgnoreCase = ignoreCase;
709
+ return this;
710
+ }
711
+
712
+ /**
713
+ * The patterns' type: `--basic-regexp`, `-E` (`extended`), `-F` (`fixed`) or `-P`
714
+ * (`perl`: refused as a git built without PCRE refuses it, unless the pattern has no regex
715
+ * character). Default: `grep.patternType`, else `grep.extendedRegexp`, else basic.
716
+ */
717
+ setPatternType(type: GrepPatternType): this {
718
+ this.checkCallable();
719
+ this.patternType = type;
720
+ return this;
721
+ }
722
+
723
+ /**
724
+ * Whether `--author`/`--committer` match the identities as the mailmap maps them
725
+ * (`--use-mailmap`/`--no-mailmap`; default `log.mailmap`, true, as `git log`).
726
+ */
727
+ setUseMailmap(use: boolean): this {
728
+ this.checkCallable();
729
+ this.useMailmap = use;
730
+ return this;
731
+ }
732
+
733
+ /**
734
+ * Whether the filters read `git log`'s configuration (default true): `grep.patternType`,
735
+ * `grep.extendedRegexp` and `log.mailmap`. False reads none of them, as `git rev-list`.
736
+ */
737
+ setLogConfig(read: boolean): this {
738
+ this.checkCallable();
739
+ this.logConfig = read;
740
+ return this;
741
+ }
742
+
743
+ /**
744
+ * A filter of the commits shown (see `CommitFilters`); several must all include a commit,
745
+ * as must git's options above. The walk still goes through the commits a filter hides, and
746
+ * `setMaxCount`/`setSkip` count only shown ones.
747
+ */
748
+ addCommitFilter(filter: CommitFilter): this {
749
+ this.checkCallable();
750
+ this.commitFilters.push(filter);
751
+ return this;
752
+ }
753
+
412
754
  /**
413
755
  * Whether a path-limited walk asks the commit-graph's changed-path Bloom filters before it
414
756
  * compares trees (default true, as git does whenever the graph has filters).
@@ -456,21 +798,126 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
456
798
  this.setCallable(false);
457
799
  // git_log_config ends in git_diff_ui_config: a diff.submodule without a value dies
458
800
  readDiffSubmoduleConfig(this.workingCopy);
801
+ if (this.reflogWalkNames !== undefined || this.grepReflogs.length > 0) {
802
+ await this.checkReflogWalkOptions({});
803
+ const entries = await this.reflogEntries(this.reflogWalkNames ?? [], false);
804
+ const walk = (async function* () {
805
+ for (const e of entries) yield { ...e.commit, id: e.id, reflog: e.reflog } as LogResult;
806
+ })();
807
+ return walk;
808
+ }
809
+ this.activeFilter = await this.buildCommitFilter();
459
810
 
460
811
  // the commits given, in order, the refs of `all()` where it was called; HEAD without
461
812
  // either
462
- const pending: { id: ObjectId; exclude: boolean }[] = [];
813
+ const pending: PendingCommit[] = [];
463
814
  for (let i = 0; i <= this.pending.length; i++) {
464
815
  if (this.includeAll && i === this.allAt) {
465
- for (const id of await this.getAllRefs()) pending.push({ id, exclude: false });
816
+ for (const { id, name } of await this.getAllRefs())
817
+ pending.push({ id, exclude: false, name });
466
818
  }
467
819
  const e = this.pending[i];
468
- if (e) pending.push({ id: await this.peelToCommit(e.id), exclude: e.exclude });
820
+ if (e)
821
+ pending.push({
822
+ id: await this.peelToCommit(e.id),
823
+ exclude: e.exclude,
824
+ name: e.name ?? e.id,
825
+ });
469
826
  }
470
827
  if (this.startCommits.length === 0 && !this.includeAll) {
471
- pending.push({ id: await this.resolveHead(), exclude: false });
828
+ pending.push({ id: await this.resolveHead(), exclude: false, name: "HEAD" });
472
829
  }
473
- return this.walk(pending);
830
+ const walk = this.walk(pending);
831
+ return this.reverse ? reversed(walk) : walk;
832
+ }
833
+
834
+ /**
835
+ * The walk's filter: git's `--grep`/`--author`/`--committer` options as one `commit_match`
836
+ * (revision.c), then the filters added. The walk reads `grep.patternType` (and refuses a
837
+ * value git does not know) only when a pattern is given; the log output (`callBytes`, git
838
+ * log and git show) reads it on every run, as git does.
839
+ */
840
+ private async buildCommitFilter(): Promise<CommitFilter | undefined> {
841
+ const filters: CommitFilter[] = [];
842
+ const headers =
843
+ this.grepAuthors.length > 0 || this.grepCommitters.length > 0 || this.grepReflogs.length > 0;
844
+ // the grep configuration and the mailmap are read only for a walk that greps: the
845
+ // commands walking through LogCommand for git's other commands (bisect, notes, rev-list)
846
+ // never see them
847
+ if (this.grepMessages.length > 0 || headers) {
848
+ let type = this.patternType;
849
+ if (this.logConfig) {
850
+ const configured = this.configuredPatternType();
851
+ if (type === undefined) type = configured;
852
+ if (type === undefined && configBool(this.workingCopy, "grep.extendedRegexp", false)) {
853
+ type = "extended";
854
+ }
855
+ }
856
+ let mailmap: Mailmap | undefined;
857
+ const mapped =
858
+ this.useMailmap ??
859
+ (this.logConfig ? configBool(this.workingCopy, "log.mailmap", true) : false);
860
+ if (headers && mapped)
861
+ mailmap = await this.loadMailmap(RemoteConfigStore.from(this._workingCopy));
862
+ filters.push(
863
+ CommitFilters.grep({
864
+ messages: this.grepMessages,
865
+ authors: this.grepAuthors,
866
+ committers: this.grepCommitters,
867
+ ...(this.grepReflogs.length > 0 ? { reflogs: this.grepReflogs } : {}),
868
+ allMatch: this.allMatch,
869
+ invertGrep: this.invertGrep,
870
+ ignoreCase: this.regexpIgnoreCase,
871
+ patternType: type,
872
+ mailmap,
873
+ }),
874
+ );
875
+ }
876
+ filters.push(...this.commitFilters);
877
+ return filters.length > 0 ? CommitFilters.and(...filters) : undefined;
878
+ }
879
+
880
+ /**
881
+ * `grep.patternType` as grep_config reads it (`default` is undefined); a value git does not
882
+ * know dies, as every `git log`/`git show` dies on it whatever it is asked.
883
+ */
884
+ private configuredPatternType(): GrepPatternType | undefined {
885
+ const value = configValue(this.workingCopy, "grep.patternType");
886
+ if (value === undefined || value === "default") return undefined;
887
+ if (value === "basic" || value === "extended" || value === "fixed" || value === "perl") {
888
+ return value;
889
+ }
890
+ throw new InvalidConfigError(
891
+ "grep.patternType",
892
+ `fatal: bad grep.patterntype argument: ${value}`,
893
+ );
894
+ }
895
+
896
+ /** The bytes of a commit as the walk reads it (the replacement's under replace refs) */
897
+ private async rawCommit(id: ObjectId, replacements?: ObjectReplacements): Promise<Uint8Array> {
898
+ const read = replacements ? replacementOf(replacements.replace, id) : id;
899
+ const bytes = await this.readObjectBytes(read);
900
+ if (!bytes) throw new GitApiError(`could not read commit ${id}`);
901
+ return bytes;
902
+ }
903
+
904
+ /**
905
+ * The author date of a commit as commit.c's record_author_date reads it (0 when the
906
+ * header has no well-formed author line).
907
+ */
908
+ private async authorDate(id: ObjectId): Promise<number> {
909
+ const bytes = await this.readObjectBytes(
910
+ replacementOf((await this.objectReplacements())?.replace ?? new Map(), id),
911
+ ).catch(() => undefined);
912
+ if (!bytes) return 0;
913
+ const text = NAME_DECODER.decode(bytes);
914
+ const end = text.indexOf("\n\n");
915
+ for (const line of (end < 0 ? text : text.slice(0, end)).split("\n")) {
916
+ if (!line.startsWith("author ")) continue;
917
+ const m = /> (\d+) [+-]?\d+$/.exec(line) ?? /> (\d+)$/.exec(line);
918
+ return m ? Number(m[1]) : 0;
919
+ }
920
+ return 0;
474
921
  }
475
922
 
476
923
  /** The commit an annotated tag (or a chain of them) tags; any other id as it is. */
@@ -490,7 +937,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
490
937
  * (refs_for_each_ref, symbolic ones resolved), then HEAD (refs_head_ref); annotated tags
491
938
  * peeled.
492
939
  */
493
- private async getAllRefs(): Promise<ObjectId[]> {
940
+ private async getAllRefs(): Promise<{ id: ObjectId; name: string }[]> {
494
941
  const named: { name: Uint8Array; id: ObjectId }[] = [];
495
942
  for await (const ref of this.refsStore.list()) {
496
943
  if (!ref.name.startsWith("refs/")) continue;
@@ -499,10 +946,11 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
499
946
  if (id) named.push({ name: encodeGitPath(ref.name), id });
500
947
  }
501
948
  named.sort((a, b) => compareBytes(a.name, b.name));
502
- const ids: ObjectId[] = [];
503
- for (const { id } of named) ids.push(await this.peelToCommit(id));
949
+ const ids: { id: ObjectId; name: string }[] = [];
950
+ for (const { id, name } of named)
951
+ ids.push({ id: await this.peelToCommit(id), name: decodeGitPath(name) });
504
952
  const head = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
505
- if (head) ids.push(await this.peelToCommit(head));
953
+ if (head) ids.push({ id: await this.peelToCommit(head), name: "HEAD" });
506
954
  return ids;
507
955
  }
508
956
 
@@ -526,7 +974,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
526
974
  * The commits met are held in a `RevTable` (typed arrays, a few dozen bytes each); commits
527
975
  * the commit-graph has are reached by their graph positions, without building their ids.
528
976
  */
529
- private async *walk(pending: { id: ObjectId; exclude: boolean }[]): AsyncIterable<LogResult> {
977
+ private async *walk(pending: PendingCommit[]): AsyncIterable<LogResult> {
530
978
  const prune = this.paths.length > 0 || this.excludePaths.length > 0;
531
979
  // a shallow commit has no parents (git's shallow grafts); the graph is off then
532
980
  const shallowIds = (await this.refsStore.getShallow?.().catch(() => undefined)) ?? [];
@@ -555,6 +1003,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
555
1003
  let trackTreesame = false;
556
1004
  const t = new RevTable(graph);
557
1005
  this.lastWalk = t;
1006
+ /** `--source`: the name each commit was reached from (git's revision_sources slab) */
1007
+ const sources = this.source ? new Map<number, string>() : undefined;
558
1008
  /** Raw commits read by `parse` (no graph), kept until shown: read once, not twice. */
559
1009
  const raw = new Map<number, Uint8Array>();
560
1010
 
@@ -675,6 +1125,10 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
675
1125
  if (!(await parse(p))) {
676
1126
  throw new GitApiError(`Failed to traverse parents of commit ${t.idOf(n)}`);
677
1127
  }
1128
+ if (sources && !sources.has(p)) {
1129
+ const source = sources.get(n);
1130
+ if (source !== undefined) sources.set(p, source);
1131
+ }
678
1132
  if (!(t.flag(p) & SEEN)) {
679
1133
  t.mark(p, SEEN);
680
1134
  queue.put(p, t.date(p));
@@ -708,7 +1162,19 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
708
1162
  if (shallow.has(id)) commit.parents = [];
709
1163
  if (this.authorPattern !== undefined && !this.matchesAuthor(commit)) return undefined;
710
1164
  if (this.committerPattern !== undefined && !this.matchesCommitter(commit)) return undefined;
711
- return { ...commit, id };
1165
+ const filter = this.activeFilter;
1166
+ if (filter) {
1167
+ const view: FilteredCommit = {
1168
+ id,
1169
+ parentCount: parents,
1170
+ commitTime: t.date(n),
1171
+ raw: async () => bytes ?? (await this.rawCommit(id, replacements)),
1172
+ commit: async () => commit,
1173
+ };
1174
+ if (!(await filter.include(view))) return undefined;
1175
+ }
1176
+ const source = sources?.get(n);
1177
+ return source !== undefined ? { ...commit, id, source } : { ...commit, id };
712
1178
  };
713
1179
 
714
1180
  // prepare_revision_walk: the flags of every argument first, then handle_commit in order
@@ -739,6 +1205,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
739
1205
  for (const e of pending) {
740
1206
  const n = t.lookup(e.id);
741
1207
  if (!(await parse(n))) continue;
1208
+ if (sources && !sources.has(n) && e.name !== undefined) sources.set(n, e.name);
742
1209
  if (t.flag(n) & UNINTERESTING) {
743
1210
  markParentsUninteresting(n);
744
1211
  limited = true;
@@ -753,95 +1220,178 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
753
1220
  const queue = new CommitQueue<number>();
754
1221
  for (const n of list) queue.put(n, t.date(n));
755
1222
 
756
- let count = 0;
757
- let skipped = 0;
758
- // git's -n 0 reads nothing more in a streaming walk; a limited walk is done before
759
1223
  const none = this.maxCount !== undefined && this.maxCount <= 0;
760
1224
  const output = this.outputWalk;
761
- // the output's walk is limited (git without generation numbers limits a topo walk)
762
- trackTreesame = (limited || !!output) && prune && !simplifyHistory && !firstParentOnly;
763
- if (!limited && !output) {
764
- if (none) return;
1225
+ const order = this.order;
1226
+ // the output's walk and a sorted one are limited (git without generation numbers limits
1227
+ // a topo walk)
1228
+ trackTreesame =
1229
+ (limited || !!output || !!order) && prune && !simplifyHistory && !firstParentOnly;
1230
+ /** git's sort_in_topological_order of `list` (parents as simplified, unparsed: none) */
1231
+ const sortTopo = async (list: number[], sort: LogOrder | undefined): Promise<number[]> => {
1232
+ if (list.length === 0) return list;
1233
+ const indegree = new Map<number, number>();
1234
+ for (const n of list) indegree.set(n, 1);
1235
+ const parentCount = (n: number) => (t.parsed(n) ? t.parentCount(n) : 0);
1236
+ for (const n of list) {
1237
+ for (let k = 0, c = parentCount(n); k < c; k++) {
1238
+ const p = t.parent(n, k);
1239
+ const d = indegree.get(p);
1240
+ if (d) indegree.set(p, d + 1);
1241
+ }
1242
+ }
1243
+ const out: number[] = [];
1244
+ let put: (n: number) => void;
1245
+ let get: () => number | undefined;
1246
+ if (sort === undefined || sort === "topo") {
1247
+ // REV_SORT_IN_GRAPH_ORDER: a LIFO, the tips first in the order given
1248
+ const stack: number[] = [];
1249
+ for (const n of list) if (indegree.get(n) === 1) stack.push(n);
1250
+ stack.reverse();
1251
+ put = (n) => stack.push(n);
1252
+ get = () => stack.pop();
1253
+ } else {
1254
+ const dates = new Map<number, number>();
1255
+ for (const n of list)
1256
+ dates.set(n, sort === "date" ? t.date(n) : await this.authorDate(t.idOf(n)));
1257
+ const queue = new CommitQueue<number>();
1258
+ put = (n) => queue.put(n, dates.get(n) ?? 0);
1259
+ get = () => queue.get();
1260
+ for (const n of list) if (indegree.get(n) === 1) put(n);
1261
+ }
1262
+ for (let n = get(); n !== undefined; n = get()) {
1263
+ for (let k = 0, c = parentCount(n); k < c; k++) {
1264
+ const p = t.parent(n, k);
1265
+ const d = indegree.get(p);
1266
+ if (!d) continue;
1267
+ indegree.set(p, d - 1);
1268
+ if (d - 1 === 1) put(p);
1269
+ }
1270
+ indegree.set(n, 0);
1271
+ out.push(n);
1272
+ }
1273
+ return out;
1274
+ };
1275
+
1276
+ /** get_revision_1's commits, in the order they come out */
1277
+ let candidates: AsyncIterable<number> | Iterable<number>;
1278
+ if (!limited && !output && !order) {
765
1279
  // get_revision_1, streaming
766
- for (let n = queue.get(); n !== undefined; n = queue.get()) {
767
- // --since: older commits are dropped without walking their parents (max_age)
768
- if (this.sinceTime !== undefined && t.date(n) < this.sinceTime) {
769
- raw.delete(n);
770
- continue;
1280
+ const since = this.sinceTime;
1281
+ candidates = (async function* () {
1282
+ for (let n = queue.get(); n !== undefined; n = queue.get()) {
1283
+ // --since: older commits are dropped without walking their parents (max_age)
1284
+ if (since !== undefined && t.date(n) < since) {
1285
+ raw.delete(n);
1286
+ continue;
1287
+ }
1288
+ await processParents(n, queue);
1289
+ yield n;
1290
+ }
1291
+ })();
1292
+ } else {
1293
+ // limit_list
1294
+ const newlist: number[] = [];
1295
+ let date = Number.POSITIVE_INFINITY;
1296
+ let slop = SLOP;
1297
+ let interestingCache = -1;
1298
+ /** git's everybody_uninteresting */
1299
+ const everybodyUninteresting = (): boolean => {
1300
+ if (interestingCache >= 0 && !(t.flag(interestingCache) & UNINTERESTING)) return false;
1301
+ for (const n of queue.items()) {
1302
+ if (t.flag(n) & UNINTERESTING) continue;
1303
+ interestingCache = n;
1304
+ return false;
771
1305
  }
1306
+ return true;
1307
+ };
1308
+ /** git's still_interesting */
1309
+ const stillInteresting = (): number => {
1310
+ const head = queue.peek();
1311
+ if (head === undefined) return 0;
1312
+ if (date <= t.date(head)) return SLOP;
1313
+ if (!everybodyUninteresting()) return SLOP;
1314
+ return slop - 1;
1315
+ };
1316
+ for (let n = queue.get(); n !== undefined; n = queue.get()) {
1317
+ // what is shown is read again at the end: a limited walk does not keep raw commits
1318
+ raw.delete(n);
1319
+ if (n === interestingCache) interestingCache = -1;
1320
+ if (this.sinceTime !== undefined && t.date(n) < this.sinceTime) t.mark(n, UNINTERESTING);
772
1321
  await processParents(n, queue);
1322
+ if (t.flag(n) & UNINTERESTING) {
1323
+ markParentsUninteresting(n);
1324
+ slop = stillInteresting();
1325
+ if (slop) continue;
1326
+ break;
1327
+ }
1328
+ if (this.untilTime !== undefined && t.date(n) > this.untilTime) continue;
1329
+ date = t.date(n);
1330
+ newlist.push(n);
1331
+ }
1332
+ // commits made TREESAME by parents that became UNINTERESTING
1333
+ if (trackTreesame) {
1334
+ for (const n of newlist) {
1335
+ if (!(t.flag(n) & (UNINTERESTING | TREESAME))) updateTreesame(n);
1336
+ }
1337
+ }
1338
+ raw.clear();
1339
+ if (output) {
1340
+ const sorted = output.topo ? await sortTopo(newlist, order ?? "topo") : newlist;
1341
+ await this.finishOutputWalk(output, t, sorted, shown, relevant, parse);
1342
+ return;
1343
+ }
1344
+ candidates = order ? await sortTopo(newlist, order) : newlist;
1345
+ }
1346
+
1347
+ // get_revision_internal: --skip, -n, then (--boundary) the parents of the commits
1348
+ // shown that were not shown themselves
1349
+ const collectBoundary = this.boundary;
1350
+ /** SHOWN */
1351
+ const shownSet = new Set<number>();
1352
+ /** CHILD_SHOWN, and git's boundary_commits array in the order marked */
1353
+ const childShown = new Set<number>();
1354
+ const boundaryCommits: number[] = [];
1355
+ let count = 0;
1356
+ let skipped = 0;
1357
+ // git's -n 0 reads nothing more in a streaming walk; a limited walk is done before
1358
+ if (!none) {
1359
+ for await (const n of candidates) {
773
1360
  const commit = await shown(n);
774
1361
  if (!commit) continue;
775
1362
  if (skipped < this.skip) {
776
1363
  skipped++;
777
1364
  continue;
778
1365
  }
1366
+ shownSet.add(n);
1367
+ if (collectBoundary) {
1368
+ for (let k = 0, c = t.parentCount(n); k < c; k++) {
1369
+ const p = t.parent(n, k);
1370
+ if (shownSet.has(p) || childShown.has(p)) continue;
1371
+ childShown.add(p);
1372
+ boundaryCommits.push(p);
1373
+ }
1374
+ }
779
1375
  yield commit;
780
- if (this.maxCount !== undefined && ++count >= this.maxCount) return;
781
- }
782
- return;
783
- }
784
-
785
- // limit_list
786
- const newlist: number[] = [];
787
- let date = Number.POSITIVE_INFINITY;
788
- let slop = SLOP;
789
- let interestingCache = -1;
790
- /** git's everybody_uninteresting */
791
- const everybodyUninteresting = (): boolean => {
792
- if (interestingCache >= 0 && !(t.flag(interestingCache) & UNINTERESTING)) return false;
793
- for (const n of queue.items()) {
794
- if (t.flag(n) & UNINTERESTING) continue;
795
- interestingCache = n;
796
- return false;
797
- }
798
- return true;
799
- };
800
- /** git's still_interesting */
801
- const stillInteresting = (): number => {
802
- const head = queue.peek();
803
- if (head === undefined) return 0;
804
- if (date <= t.date(head)) return SLOP;
805
- if (!everybodyUninteresting()) return SLOP;
806
- return slop - 1;
807
- };
808
- for (let n = queue.get(); n !== undefined; n = queue.get()) {
809
- // what is shown is read again at the end: a limited walk does not keep raw commits
810
- raw.delete(n);
811
- if (n === interestingCache) interestingCache = -1;
812
- if (this.sinceTime !== undefined && t.date(n) < this.sinceTime) t.mark(n, UNINTERESTING);
813
- await processParents(n, queue);
814
- if (t.flag(n) & UNINTERESTING) {
815
- markParentsUninteresting(n);
816
- slop = stillInteresting();
817
- if (slop) continue;
818
- break;
819
- }
820
- if (this.untilTime !== undefined && t.date(n) > this.untilTime) continue;
821
- date = t.date(n);
822
- newlist.push(n);
823
- }
824
- // commits made TREESAME by parents that became UNINTERESTING
825
- if (trackTreesame) {
826
- for (const n of newlist) {
827
- if (!(t.flag(n) & (UNINTERESTING | TREESAME))) updateTreesame(n);
1376
+ if (this.maxCount !== undefined && ++count >= this.maxCount) break;
828
1377
  }
829
1378
  }
830
- raw.clear();
831
- if (output) {
832
- await this.finishOutputWalk(output, t, newlist, shown, relevant, parse);
833
- return;
1379
+ if (!collectBoundary) return;
1380
+ // create_boundary_commit_list: each prepended (commit_list_insert), then sorted
1381
+ const boundaryList: number[] = [];
1382
+ const marked = new Set<number>();
1383
+ for (const n of boundaryCommits) {
1384
+ if (shownSet.has(n) || marked.has(n)) continue;
1385
+ marked.add(n);
1386
+ boundaryList.unshift(n);
834
1387
  }
835
- if (none) return;
836
- for (const n of newlist) {
837
- const commit = await shown(n);
1388
+ for (const n of await sortTopo(boundaryList, order)) {
1389
+ const id = t.idOf(n);
1390
+ const commit = await this.walkCommits.load(id);
838
1391
  if (!commit) continue;
839
- if (skipped < this.skip) {
840
- skipped++;
841
- continue;
842
- }
843
- yield commit;
844
- if (this.maxCount !== undefined && ++count >= this.maxCount) return;
1392
+ if (shallow.has(id)) commit.parents = [];
1393
+ const source = sources?.get(n);
1394
+ yield { ...commit, id, boundary: true, ...(source !== undefined ? { source } : {}) };
845
1395
  }
846
1396
  }
847
1397
 
@@ -858,34 +1408,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
858
1408
  relevant: (n: number) => boolean,
859
1409
  parse: (n: number) => Promise<boolean>,
860
1410
  ): Promise<void> {
861
- let order = newlist;
862
- if (output.topo) {
863
- // sort_in_topological_order (REV_SORT_IN_GRAPH_ORDER: a LIFO of the ready commits)
864
- const indegree = new Map<number, number>();
865
- for (const n of newlist) indegree.set(n, 1);
866
- for (const n of newlist) {
867
- for (let k = 0, c = t.parentCount(n); k < c; k++) {
868
- const p = t.parent(n, k);
869
- const d = indegree.get(p);
870
- if (d) indegree.set(p, d + 1);
871
- }
872
- }
873
- const stack: number[] = [];
874
- for (const n of newlist) if (indegree.get(n) === 1) stack.push(n);
875
- stack.reverse();
876
- order = [];
877
- for (let n = stack.pop(); n !== undefined; n = stack.pop()) {
878
- for (let k = 0, c = t.parentCount(n); k < c; k++) {
879
- const p = t.parent(n, k);
880
- const d = indegree.get(p);
881
- if (!d) continue;
882
- indegree.set(p, d - 1);
883
- if (d - 1 === 1) stack.push(p);
884
- }
885
- indegree.set(n, 0);
886
- order.push(n);
887
- }
888
- }
1411
+ const order = newlist;
889
1412
  const firstParentOnly = this.firstParentOnly;
890
1413
  /** revision.c's one_relevant_parent */
891
1414
  const oneRelevantParent = (n: number): number | undefined => {
@@ -936,8 +1459,14 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
936
1459
  }
937
1460
  parents = ids;
938
1461
  }
939
- const { id, ...rest } = commit;
940
- output.entries.push({ id, commit: rest, parents, ...(savedParents ? { savedParents } : {}) });
1462
+ const { id, source, boundary: _boundary, ...rest } = commit;
1463
+ output.entries.push({
1464
+ id,
1465
+ commit: rest,
1466
+ parents,
1467
+ ...(savedParents ? { savedParents } : {}),
1468
+ ...(source !== undefined ? { source } : {}),
1469
+ });
941
1470
  }
942
1471
  // graph.c's graph_is_interesting asks get_commit_action about a parent: one the walk
943
1472
  // never reached has no TREESAME or SHOWN flag, so only the filters can hide it (with
@@ -951,7 +1480,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
951
1480
  }
952
1481
 
953
1482
  /**
954
- * The log printed as `git log <options>` prints it to a pipe (no colors, no pager): the
1483
+ * The log printed as `git log <options>` prints it to a pipe (no pager; colors only when
1484
+ * `setDiffOptions({ color })` or `color.ui`/`color.diff` say `always`): the
955
1485
  * walk set up by this command (start points, ranges, paths, `-n`, `--skip`, filters), each
956
1486
  * commit in the format asked for, with the graph and the diffs asked for. See
957
1487
  * {@link LogOutputOptions}.
@@ -976,27 +1506,56 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
976
1506
  }
977
1507
 
978
1508
  private async printLog(options: LogOutputOptions): Promise<Uint8Array> {
1509
+ const reverse = !!options.reverse || this.reverse;
1510
+ await this.checkReflogWalkOptions(options);
979
1511
  // revision.c's setup_revisions: the graph cannot be reversed
980
- if (options.graph && options.reverse) {
1512
+ if (options.graph && reverse) {
981
1513
  throw new IncompatibleOptionsError(
982
1514
  ["--graph", "--reverse"],
983
1515
  "options '--graph' and '--reverse' cannot be used together",
984
1516
  );
985
1517
  }
1518
+ // git log and git show read grep_config before anything else (a bad grep.patternType
1519
+ // dies there); the walk alone (rev-list, bisect's own walks) reads it only to grep
1520
+ if (this.logConfig) this.configuredPatternType();
1521
+ await this.preparePickaxe();
1522
+ // --use-mailmap/--no-mailmap: what --author/--committer match too
1523
+ if (options.mailmap !== undefined) this.useMailmap ??= options.mailmap;
1524
+ const colors = this.readColors();
986
1525
  const host = this.outputHost(options);
987
1526
  const paths = [...this.paths];
988
1527
  // the pathspec as git holds it: the excluded paths as `:(exclude)` elements, `.` when
989
1528
  // every element excludes
990
1529
  const pathspec = [...paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
991
1530
  if (paths.length === 0 && this.excludePaths.length > 0) pathspec.push(".");
992
- const printer = new LogPrinter(host, options, {
993
- interesting: (id) => shownIds.has(id) || unwalkedShown.has(id),
994
- firstParentOnly: this.firstParentOnly,
995
- paths: pathspec,
996
- });
997
- const follow = !printer.alwaysShowHeader;
1531
+ const printer = new LogPrinter(
1532
+ host,
1533
+ { ...options, diff: { ...options.diff, ...this.diffOptions } },
1534
+ {
1535
+ interesting: (id) => shownIds.has(id) || unwalkedShown.has(id),
1536
+ firstParentOnly: this.firstParentOnly,
1537
+ paths: pathspec,
1538
+ ...(colors ? { colors } : {}),
1539
+ },
1540
+ );
1541
+ const follow = printer.followsPath;
1542
+ const countsShown = !printer.alwaysShowHeader;
998
1543
  const graph = !!options.graph;
999
- const topo = graph || !!options.topoOrder;
1544
+ const topo = graph;
1545
+ const boundary = !!options.boundary || this.boundary;
1546
+ if (graph && boundary) {
1547
+ // graph.c draws boundary commits as `o` in columns of their own: not reproduced
1548
+ throw new NotImplementedError("git log --graph --boundary");
1549
+ }
1550
+ // the walk's order, sources and boundary for the output (it reverses the list itself)
1551
+ const saved = { order: this.order, reverse: this.reverse, boundary: this.boundary };
1552
+ const saveSource = this.source;
1553
+ if (options.authorDateOrder) this.order = "author-date";
1554
+ else if (options.dateOrder) this.order = "date";
1555
+ else if (options.topoOrder) this.order ??= "topo";
1556
+ this.reverse = false;
1557
+ this.boundary = boundary;
1558
+ if (options.source || printer.wantsSource) this.source = true;
1000
1559
  const maxCount = this.maxCount;
1001
1560
  const skip = this.skip;
1002
1561
  const simplifyHistory = this.simplifyHistory;
@@ -1006,7 +1565,10 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1006
1565
  const shownIds = new Set<ObjectId>();
1007
1566
  const unwalkedShown = new Set<ObjectId>();
1008
1567
  let entries: LogOutputEntry[];
1009
- if (topo) {
1568
+ if (this.reflogWalkNames !== undefined) {
1569
+ entries = await this.reflogEntries(this.reflogWalkNames);
1570
+ for (const e of entries) shownIds.add(e.id);
1571
+ } else if (topo) {
1010
1572
  this.outputWalk = { topo, rewrite: graph, entries: [] };
1011
1573
  for await (const _ of await this.call()) {
1012
1574
  // the output walk collects its commits
@@ -1016,23 +1578,64 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1016
1578
  this.outputWalk = undefined;
1017
1579
  for (const e of entries) shownIds.add(e.id);
1018
1580
  entries = entries.slice(skip);
1019
- if (maxCount !== undefined && !follow) entries = entries.slice(0, Math.max(maxCount, 0));
1581
+ // the commits shown count (--follow, pickaxe, --diff-filter): the print loop stops
1582
+ if (maxCount !== undefined && !countsShown) entries = entries.slice(0, Math.max(maxCount, 0));
1020
1583
  if (maxCount !== undefined && maxCount <= 0) entries = [];
1584
+ } else if (!reverse) {
1585
+ // cmd_log_walk: each commit shown as the walk gives it; --follow, pickaxe and
1586
+ // --diff-filter count the commits shown, not those walked (log.c gives max_count back
1587
+ // for a commit log_tree_commit did not show), so the walk stops once enough are shown
1588
+ if (countsShown) this.maxCount = undefined;
1589
+ await printer.start();
1590
+ try {
1591
+ if (maxCount === undefined || maxCount > 0) {
1592
+ let shownCount = 0;
1593
+ for await (const c of await this.call()) {
1594
+ const { id, boundary: isBoundary, source, ...commit } = c;
1595
+ const entry: LogOutputEntry = {
1596
+ id,
1597
+ commit,
1598
+ parents: c.parents,
1599
+ ...(isBoundary ? { boundary: true } : {}),
1600
+ ...(source !== undefined ? { source } : {}),
1601
+ };
1602
+ const shown = await printer.showCommit(entry, []);
1603
+ if (shown && countsShown && maxCount !== undefined && ++shownCount >= maxCount) break;
1604
+ }
1605
+ }
1606
+ } finally {
1607
+ this.maxCount = maxCount;
1608
+ this.simplifyHistory = simplifyHistory;
1609
+ this.order = saved.order;
1610
+ this.reverse = saved.reverse;
1611
+ this.boundary = saved.boundary;
1612
+ this.source = saveSource;
1613
+ if (follow) this.paths = paths;
1614
+ }
1615
+ return printer.result();
1021
1616
  } else {
1022
- // --follow counts the commits shown, not those walked; --reverse the newest walked
1023
- if (follow && !options.reverse) this.maxCount = undefined;
1617
+ // --reverse: the newest commits walked, reversed, then shown
1024
1618
  entries = [];
1025
1619
  for await (const c of await this.call()) {
1026
- const { id, ...commit } = c;
1027
- entries.push({ id, commit, parents: c.parents });
1620
+ const { id, boundary: isBoundary, source, ...commit } = c;
1621
+ entries.push({
1622
+ id,
1623
+ commit,
1624
+ parents: c.parents,
1625
+ ...(isBoundary ? { boundary: true } : {}),
1626
+ ...(source !== undefined ? { source } : {}),
1627
+ });
1028
1628
  }
1029
- if (follow) this.maxCount = maxCount;
1030
1629
  }
1031
1630
  this.simplifyHistory = simplifyHistory;
1032
- if (follow && options.reverse && maxCount !== undefined) {
1631
+ this.order = saved.order;
1632
+ this.reverse = saved.reverse;
1633
+ this.boundary = saved.boundary;
1634
+ this.source = saveSource;
1635
+ if (follow && reverse && maxCount !== undefined) {
1033
1636
  entries = entries.slice(0, Math.max(maxCount, 0));
1034
1637
  }
1035
- if (options.reverse) entries.reverse();
1638
+ if (reverse) entries.reverse();
1036
1639
  await printer.start();
1037
1640
  if (graph) {
1038
1641
  const parentsOf = new Map(entries.map((e) => [e.id, e.parents]));
@@ -1041,7 +1644,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1041
1644
  let count = 0;
1042
1645
  // -n 0: nothing is walked
1043
1646
  if (maxCount !== undefined && maxCount <= 0) entries = [];
1044
- const countShown = follow && maxCount !== undefined && !options.reverse;
1647
+ const countShown = countsShown && maxCount !== undefined && !reverse;
1045
1648
  for (let k = 0; k < entries.length; k++) {
1046
1649
  const e = entries[k] as LogOutputEntry;
1047
1650
  const lookahead = entries.slice(k + 1, k + 3).map((x) => x.id);
@@ -1052,6 +1655,245 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1052
1655
  return printer.result();
1053
1656
  }
1054
1657
 
1658
+ /**
1659
+ * `git show`'s output of objects one at a time (builtin/log.c's cmd_show without a walk):
1660
+ * one printer for every object, so commits, tags and trees share git's `shown_one`
1661
+ * separators. Used by {@link ShowCommand}; the paths and filters set on this command
1662
+ * decide which commits show, as revision.c's no-walk mode simplifies each one.
1663
+ *
1664
+ * @internal
1665
+ */
1666
+ async showSession(options: LogOutputOptions): Promise<ShowSession> {
1667
+ this.checkCallable();
1668
+ this.setCallable(false);
1669
+ if (options.graph) {
1670
+ throw new IncompatibleOptionsError(
1671
+ ["--no-walk", "--graph"],
1672
+ "fatal: options '--no-walk' and '--graph' cannot be used together",
1673
+ );
1674
+ }
1675
+ if (this.logConfig) this.configuredPatternType();
1676
+ await this.preparePickaxe();
1677
+ if (options.mailmap !== undefined) this.useMailmap ??= options.mailmap;
1678
+ readDiffSubmoduleConfig(this.workingCopy);
1679
+ const colors = this.readColors();
1680
+ this.activeFilter = await this.buildCommitFilter();
1681
+ const host = this.outputHost(options);
1682
+ const pathspec = [...this.paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
1683
+ if (this.paths.length === 0 && this.excludePaths.length > 0) pathspec.push(".");
1684
+ const printer = new LogPrinter(
1685
+ host,
1686
+ { ...options, diff: { ...options.diff, ...this.diffOptions } },
1687
+ {
1688
+ interesting: () => true,
1689
+ firstParentOnly: this.firstParentOnly,
1690
+ paths: pathspec,
1691
+ ...(colors ? { colors } : {}),
1692
+ },
1693
+ );
1694
+ await printer.start();
1695
+ const shown = new Set<ObjectId>();
1696
+ const limited = pathspec.length > 0;
1697
+ const commit = async (id: ObjectId): Promise<boolean> => {
1698
+ // get_revision's SHOWN flag: a commit named again is not shown again
1699
+ if (shown.has(id)) return false;
1700
+ const loaded = await this.walkCommits.load(id);
1701
+ if (!loaded) throw new GitApiError(`fatal: bad object ${id}`);
1702
+ // try_to_simplify_commit, then get_commit_action: a commit TREESAME to a parent (a
1703
+ // root without the paths) is ignored
1704
+ if (limited && (await this.treesameForShow(id, loaded))) return false;
1705
+ const filter = this.activeFilter;
1706
+ if (filter) {
1707
+ const view: FilteredCommit = {
1708
+ id,
1709
+ parentCount: loaded.parents.length,
1710
+ commitTime: loaded.committer.timestamp,
1711
+ raw: async () => this.rawCommit(id),
1712
+ commit: async () => loaded,
1713
+ };
1714
+ if (!(await filter.include(view))) return false;
1715
+ }
1716
+ shown.add(id);
1717
+ await printer.showCommit({ id, commit: loaded, parents: loaded.parents }, []);
1718
+ return true;
1719
+ };
1720
+ const run = <T>(fn: () => Promise<T>): Promise<T> => {
1721
+ const worktree = this.worktreeAccess;
1722
+ return worktree?.batch ? worktree.batch(fn) : fn();
1723
+ };
1724
+ return {
1725
+ commit: (id) => run(() => commit(id)),
1726
+ separate: () => printer.separateObject(),
1727
+ markShown: () => printer.markShown(),
1728
+ text: (text) => printer.writeText(text),
1729
+ bytes: (bytes) => printer.writeBytes(bytes),
1730
+ tagger: (ident) => printer.writeTagger(ident),
1731
+ result: () => printer.result(),
1732
+ commitColor: { set: colors?.diff.commit ?? "", reset: colors?.diff.reset ?? "" },
1733
+ };
1734
+ }
1735
+
1736
+ /** revision.c's try_to_simplify_commit for a commit git shows without walking */
1737
+ private async treesameForShow(id: ObjectId, commit: Commit): Promise<boolean> {
1738
+ if (commit.parents.length === 0) return !(await this.pathsDiffer(undefined, commit.tree));
1739
+ for (let k = 0; k < commit.parents.length; k++) {
1740
+ if (k === 1 && this.firstParentOnly) break;
1741
+ const parent = await this.walkCommits.load(commit.parents[k] as ObjectId);
1742
+ if (!parent) {
1743
+ throw new GitApiError(
1744
+ `fatal: cannot simplify commit ${id} (because of ${commit.parents[k]})`,
1745
+ );
1746
+ }
1747
+ if (!(await this.pathsDiffer(parent.tree, commit.tree))) return true;
1748
+ }
1749
+ return false;
1750
+ }
1751
+
1752
+ /**
1753
+ * setup_revisions' refusals of a reflog walk: a sorted walk (`--topo-order`, `--graph`
1754
+ * without generation numbers: git's `limited`), then `--graph`/`--reverse`, then
1755
+ * `--grep-reflog` without `-g`.
1756
+ */
1757
+ private async checkReflogWalkOptions(options: LogOutputOptions): Promise<void> {
1758
+ const walking = this.reflogWalkNames !== undefined;
1759
+ if (walking) {
1760
+ const graph = !!options.graph;
1761
+ const reverse = !!options.reverse || this.reverse;
1762
+ if (reverse && this.compatibility === "2.43") {
1763
+ throw new IncompatibleOptionsError(
1764
+ ["--reverse", "--walk-reflogs"],
1765
+ "options '--reverse' and '--walk-reflogs' cannot be used together",
1766
+ );
1767
+ }
1768
+ const sorted =
1769
+ graph ||
1770
+ this.order !== undefined ||
1771
+ !!options.topoOrder ||
1772
+ !!options.dateOrder ||
1773
+ !!options.authorDateOrder;
1774
+ // a sorted walk is limited unless the commit-graph gives generation numbers
1775
+ if (sorted && !(await this.commits.commitGraph?.get().catch(() => undefined))) {
1776
+ throw new GitApiError("cannot combine --walk-reflogs with history-limiting options");
1777
+ }
1778
+ const set = [
1779
+ ...(graph ? ["--graph"] : []),
1780
+ ...(reverse ? ["--reverse"] : []),
1781
+ "--walk-reflogs",
1782
+ ];
1783
+ if (set.length > 1) {
1784
+ const quoted = set.map((o) => `'${o}'`);
1785
+ const list =
1786
+ quoted.length === 2
1787
+ ? `${quoted[0]} and ${quoted[1]}`
1788
+ : `${quoted[0]}, ${quoted[1]}, and ${quoted[2]}`;
1789
+ throw new IncompatibleOptionsError(set, `options ${list} cannot be used together`);
1790
+ }
1791
+ }
1792
+ if (!walking && this.grepReflogs.length > 0) {
1793
+ throw new GitApiError("the option '--grep-reflog' requires '--walk-reflogs'");
1794
+ }
1795
+ }
1796
+
1797
+ /**
1798
+ * The entries of a reflog walk (reflog-walk.c's next_reflog_entry over the names given,
1799
+ * HEAD without): each entry's new commit, filtered as get_revision_1 filters a reflog walk
1800
+ * (`--since`/`--until` against the entry's date, path limiting against the commit's parents,
1801
+ * get_commit_action), then skipped and counted.
1802
+ */
1803
+ private async reflogEntries(names: readonly string[], claim = true): Promise<LogOutputEntry[]> {
1804
+ if (claim) {
1805
+ this.checkCallable();
1806
+ this.setCallable(false);
1807
+ readDiffSubmoduleConfig(this.workingCopy);
1808
+ }
1809
+ this.activeFilter = await this.buildCommitFilter();
1810
+ const resolver = this.revisionResolver();
1811
+ const refs = this.refsStore;
1812
+ const logs = await openReflogWalk(names.length > 0 ? names : ["HEAD"], {
1813
+ reflog: async (ref) => {
1814
+ const reader = await refs.getReflog?.(ref);
1815
+ return reader ? (await reader.getReverseEntries()).reverse() : undefined;
1816
+ },
1817
+ resolveRef: async (ref, reading) => {
1818
+ const value = await refs.get(ref).catch(() => undefined);
1819
+ if (!value) return undefined;
1820
+ if (!isSymbolicRef(value)) return reading && !value.objectId ? undefined : ref;
1821
+ let target = value.target;
1822
+ for (let i = 0; i < 10; i++) {
1823
+ const next = await refs.get(target).catch(() => undefined);
1824
+ if (!next || !isSymbolicRef(next)) {
1825
+ if (reading && !next) return undefined;
1826
+ return target;
1827
+ }
1828
+ target = next.target;
1829
+ }
1830
+ return undefined;
1831
+ },
1832
+ interpretBranchPrefix: (name) => resolver.interpretBranchPrefix(name),
1833
+ dwimLogRefs: (name) => resolver.dwimLogRefs(name),
1834
+ shortenRef: (ref) => shortenUnambiguousRef(refs, ref),
1835
+ now: () => resolver.currentTime(),
1836
+ });
1837
+ const out: LogOutputEntry[] = [];
1838
+ let skip = this.skip;
1839
+ const max = this.maxCount;
1840
+ if (max !== undefined && max <= 0) return out;
1841
+ const prune = this.paths.length > 0 || this.excludePaths.length > 0;
1842
+ const loadCommit = (id: ObjectId) => this.walkCommits.load(id).catch(() => undefined);
1843
+ for await (const step of walkReflogs(logs, loadCommit)) {
1844
+ const { id, commit } = step;
1845
+ if (this.sinceTime !== undefined && step.time < this.sinceTime) continue;
1846
+ if (this.untilTime !== undefined && step.time > this.untilTime) continue;
1847
+ const parents = commit.parents.length;
1848
+ if (this.revFilter === RevFilter.ONLY_MERGES && parents < 2) continue;
1849
+ if (this.revFilter === RevFilter.NO_MERGES && parents > 1) continue;
1850
+ if (this.authorPattern !== undefined && !this.matchesAuthor(commit)) continue;
1851
+ if (this.committerPattern !== undefined && !this.matchesCommitter(commit)) continue;
1852
+ const filter = this.activeFilter;
1853
+ if (filter) {
1854
+ const view: FilteredCommit = {
1855
+ id,
1856
+ parentCount: parents,
1857
+ commitTime: commit.committer.timestamp,
1858
+ raw: async () => this.rawCommit(id),
1859
+ commit: async () => commit,
1860
+ reflogMessage: step.reflog.message,
1861
+ };
1862
+ if (!(await filter.include(view))) continue;
1863
+ }
1864
+ if (prune && (await this.reflogCommitTreesame(commit))) continue;
1865
+ if (skip > 0) {
1866
+ skip--;
1867
+ continue;
1868
+ }
1869
+ out.push({ id, commit, parents: commit.parents, reflog: step.reflog });
1870
+ if (max !== undefined && out.length >= max) break;
1871
+ }
1872
+ return out;
1873
+ }
1874
+
1875
+ /**
1876
+ * try_to_simplify_commit for a commit of a reflog walk (every parent relevant): TREESAME
1877
+ * at the paths to a parent (to every parent under `--full-history`), a root commit to the
1878
+ * empty tree.
1879
+ */
1880
+ private async reflogCommitTreesame(commit: Commit): Promise<boolean> {
1881
+ if (commit.parents.length === 0) return !(await this.pathsDiffer(undefined, commit.tree));
1882
+ let same = 0;
1883
+ let compared = 0;
1884
+ for (const parent of commit.parents) {
1885
+ if (compared === 1 && this.firstParentOnly) break;
1886
+ compared++;
1887
+ const p = await this.walkCommits.load(parent).catch(() => undefined);
1888
+ if (!p) throw new GitApiError(`cannot simplify commit ${parent}`);
1889
+ if (!(await this.pathsDiffer(p.tree, commit.tree))) {
1890
+ if (this.simplifyHistory) return true;
1891
+ same++;
1892
+ }
1893
+ }
1894
+ return same === compared;
1895
+ }
1896
+
1055
1897
  /** What the log printer reads of the repository. */
1056
1898
  private outputHost(options: LogOutputOptions = {}): LogOutputHost {
1057
1899
  const config = RemoteConfigStore.from(this._workingCopy);
@@ -1098,6 +1940,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1098
1940
  }
1099
1941
  return short;
1100
1942
  },
1943
+ signature: (id) => this.signatureOf(id),
1944
+ signatureLines: (entry) => this.signatureLines(entry),
1101
1945
  rawCommit: async (id) => {
1102
1946
  // the replacement's content, as git's commit buffer is (core.useReplaceRefs)
1103
1947
  const replace = (await this.objectReplacements())?.replace;
@@ -1150,7 +1994,10 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1150
1994
  const diff = new DiffCommand(this._workingCopy)
1151
1995
  .setOldTree(parent ? await treeOf(parent) : this.objectFormat.emptyTreeId)
1152
1996
  .setNewTree(entry.commit.tree)
1997
+ // log's diffcore_rotate starts at the first path after a missing one
1998
+ .setRotateStrict(false)
1153
1999
  .shareReadsOf(this);
2000
+ if (this.colorSettings) diff.setColorSettings(this.colorSettings);
1154
2001
  diff.setOptions({
1155
2002
  ...this.diffOptions,
1156
2003
  ...(options.statWidth !== undefined
@@ -1162,13 +2009,116 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1162
2009
  const spec = [...this.paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
1163
2010
  if (spec.length > 0) diff.setPathspec(spec);
1164
2011
  }
1165
- return diff.callFormats(formats, options.follow);
2012
+ const shown = await diff.callFormats(formats, options.follow);
2013
+ if (diff.checkFoundErrors) this.checkFailed = true;
2014
+ return shown;
1166
2015
  },
1167
2016
  combinedDiff: (entry, options) => this.combinedDiff(entry, options),
1168
2017
  };
1169
2018
  }
1170
2019
 
1171
2020
  private diffOptions: DiffTextOptions = {};
2021
+ /** `--check` found errors in a commit's diff (git's `check_failed`) */
2022
+ private checkFailed = false;
2023
+
2024
+ /**
2025
+ * The exit status `git log` ends with: 2 when `--check` ({@link LogOutputOptions.check})
2026
+ * found errors in the diffs shown, else 0 (cmd_log_walk)
2027
+ */
2028
+ get exitCode(): number {
2029
+ return this.checkFailed ? 2 : 0;
2030
+ }
2031
+
2032
+ /** The colors {@link callBytes} prints with */
2033
+ private colorSettings?: DiffColorSettings;
2034
+ private readonly outputWarnings: string[] = [];
2035
+
2036
+ /**
2037
+ * What git prints on stderr while {@link callBytes} prints the log without dying: the
2038
+ * `log.graphColors` colors it cannot parse (`error: invalid color value: <c>`, then
2039
+ * `warning: ignored invalid color '<c>' in log.graphColors`)
2040
+ */
2041
+ get warnings(): readonly string[] {
2042
+ return this.outputWarnings;
2043
+ }
2044
+
2045
+ /**
2046
+ * git_log_config (git_diff_ui_config): the colors, read once for every commit's diff; the
2047
+ * palettes of the log's own lines, undefined without color
2048
+ */
2049
+ private readColors():
2050
+ | { diff: DiffColors; decorations: DecorationPalette; graph: readonly string[] }
2051
+ | undefined {
2052
+ this.colorSettings = readDiffColorSettings(
2053
+ this.workingCopy,
2054
+ this.diffOptions,
2055
+ this.diffOptions.uiConfig !== false,
2056
+ );
2057
+ const colors = this.colorSettings.colors;
2058
+ if (!colors) return undefined;
2059
+ // graph_read_config: `log.graphColors` (its invalid colors left out with git's warning)
2060
+ const configured = configValue(this.workingCopy, "log.graphColors");
2061
+ const compatibility = this.diffOptions.colorCompatibility ?? "2.56";
2062
+ const graph =
2063
+ configured === undefined
2064
+ ? GRAPH_COLUMN_COLORS_ANSI
2065
+ : graphColumnColors(
2066
+ configured,
2067
+ (spec) => {
2068
+ const color = parseGitColor(spec, compatibility);
2069
+ // color_parse_mem's own error, before graph.c's warning
2070
+ if (color === undefined)
2071
+ this.outputWarnings.push(`error: invalid color value: ${spec}`);
2072
+ return color;
2073
+ },
2074
+ (message) => this.outputWarnings.push(message),
2075
+ );
2076
+ return {
2077
+ diff: colors,
2078
+ decorations: {
2079
+ ...(this.colorSettings.decorationColors ?? DEFAULT_DECORATION_COLORS),
2080
+ commit: colors.commit,
2081
+ },
2082
+ graph,
2083
+ };
2084
+ }
2085
+
2086
+ /**
2087
+ * The pickaxe options checked before anything is shown, as git parses them (empty `-S`/
2088
+ * `-G`, `--find-object` names resolved once, the combinations, the regex compiled); `-i`
2089
+ * (`setRegexpIgnoreCase`) folds `-S`/`-G` too, as revision.c's `--regexp-ignore-case`
2090
+ */
2091
+ private async preparePickaxe(): Promise<void> {
2092
+ let o = this.diffOptions;
2093
+ if (!hasPickaxe(o)) return;
2094
+ if (this.regexpIgnoreCase && o.pickaxeIgnoreCase === undefined) {
2095
+ o = { ...o, pickaxeIgnoreCase: true };
2096
+ }
2097
+ checkPickaxeOptions(o);
2098
+ if (o.findObjects && o.findObjects.length > 0) {
2099
+ const ids: string[] = [];
2100
+ for (const name of o.findObjects) {
2101
+ const id = await this.revisionResolver()
2102
+ .resolve(name)
2103
+ .catch(() => undefined);
2104
+ if (id === undefined) {
2105
+ throw new InvalidArgumentError(
2106
+ "findObjects",
2107
+ name,
2108
+ `error: unable to resolve '${name}'`,
2109
+ ).withExitCode(129);
2110
+ }
2111
+ ids.push(id);
2112
+ }
2113
+ o = { ...o, findObjects: ids };
2114
+ }
2115
+ DiffPickaxe.compile({
2116
+ ...(o.pickaxeString !== undefined ? { string: o.pickaxeString } : {}),
2117
+ ...(o.pickaxeGrep !== undefined ? { grep: o.pickaxeGrep } : {}),
2118
+ regex: o.pickaxeRegex ?? false,
2119
+ });
2120
+ this.diffOptions = o;
2121
+ }
1172
2122
 
1173
2123
  /** `log` stores no objects: its abbreviations read each loose fan-out directory once */
1174
2124
  protected override writesNoObjects(): boolean {
@@ -1182,6 +2132,81 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1182
2132
  return this;
1183
2133
  }
1184
2134
 
2135
+ private readonly signatureChecks = new OrderedMap<ObjectId, Promise<SignatureCheck>>();
2136
+ private signatureCwd?: Promise<string | undefined>;
2137
+
2138
+ /** A commit's bytes as its buffer is read (the replacement's, core.useReplaceRefs) */
2139
+ private async commitBuffer(id: ObjectId): Promise<Uint8Array | undefined> {
2140
+ const replace = (await this.objectReplacements())?.replace;
2141
+ return this.readObjectBytes(replace?.size ? replacementOf(replace, id) : id);
2142
+ }
2143
+
2144
+ /** `check_commit_signature` of a commit, made once */
2145
+ private signatureOf(id: ObjectId): Promise<SignatureCheck> {
2146
+ let check = this.signatureChecks.get(id);
2147
+ if (!check) {
2148
+ check = (async () => {
2149
+ const bytes = await this.commitBuffer(id);
2150
+ if (!bytes) return { result: "N", trustLevel: "undefined", failed: true, messages: [] };
2151
+ this.signatureCwd ??= this.hostWorkingDir();
2152
+ const cwd = await this.signatureCwd;
2153
+ return verifyCommitBytes(this._workingCopy, bytes, {
2154
+ objectFormat: this.objectFormat,
2155
+ ...(cwd !== undefined ? { cwd } : {}),
2156
+ });
2157
+ })();
2158
+ this.signatureChecks.set(id, check);
2159
+ if (this.signatureChecks.size > 1024) this.signatureChecks.deleteOldest();
2160
+ }
2161
+ return check;
2162
+ }
2163
+
2164
+ /** log-tree.c's `show_signature` and `show_mergetag` for one commit */
2165
+ private async signatureLines(
2166
+ entry: LogOutputEntry,
2167
+ ): Promise<{ failed: boolean; text: string }[]> {
2168
+ const bytes = await this.commitBuffer(entry.id);
2169
+ if (!bytes) return [];
2170
+ this.signatureCwd ??= this.hostWorkingDir();
2171
+ const cwd = await this.signatureCwd;
2172
+ const out: { failed: boolean; text: string }[] = [];
2173
+ if (parseBufferSignedByHeader(bytes, this.objectFormat.signatureHeader)) {
2174
+ const check = await this.signatureOf(entry.id);
2175
+ out.push(
2176
+ check.failed && check.output === undefined
2177
+ ? { failed: true, text: "No signature\n" }
2178
+ : { failed: check.failed, text: check.output ?? "" },
2179
+ );
2180
+ }
2181
+ const parents = entry.commit.parents;
2182
+ for (const tag of mergetagsOf(bytes)) {
2183
+ const header = parseMergetag(tag, this.objectFormat.hexLength);
2184
+ let text: string;
2185
+ if (!header) text = "malformed mergetag\n";
2186
+ else if (parents.length === 2 && header.object === parents[1])
2187
+ text = `merged tag '${header.tag}'\n`;
2188
+ else {
2189
+ const nth = parents.indexOf(header.object);
2190
+ text =
2191
+ nth < 0
2192
+ ? `tag ${header.tag} names a non-parent ${header.object}\n`
2193
+ : `parent #${nth + 1}, tagged '${header.tag}'\n`;
2194
+ }
2195
+ let failed = true;
2196
+ const signed = parseSignature(tag);
2197
+ if (signed) {
2198
+ const check = await checkSignature(this._workingCopy, signed.payload, signed.signature, {
2199
+ payloadType: "tag",
2200
+ ...(cwd !== undefined ? { cwd } : {}),
2201
+ });
2202
+ failed = check.failed;
2203
+ text += check.output ?? "No signature\n";
2204
+ }
2205
+ out.push({ failed, text });
2206
+ }
2207
+ return out;
2208
+ }
2209
+
1185
2210
  /** An object's content as stored (undefined when missing) */
1186
2211
  private async readObjectBytes(id: ObjectId): Promise<Uint8Array | undefined> {
1187
2212
  const objects = this._workingCopy.history?.objects;
@@ -1226,6 +2251,44 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1226
2251
  return out;
1227
2252
  }
1228
2253
 
2254
+ /**
2255
+ * The pickaxe of a combined diff: without rename detection `--find-object` keeps the paths
2256
+ * with the object in the merge or a parent (combined_objfind); with it, and for `-S`/`-G`,
2257
+ * find_paths_generic's way: a diff against each parent through diffcore (renames, pickaxe
2258
+ * and `--diff-filter`), keeping the paths every one of them still lists (intersect_paths)
2259
+ */
2260
+ private async combinedPickaxe(
2261
+ entry: LogOutputEntry,
2262
+ paths: string[],
2263
+ idsOf: (path: string) => (ObjectId | undefined)[],
2264
+ ): Promise<string[]> {
2265
+ const d = this.diffOptions;
2266
+ if (!hasPickaxe(d) || paths.length === 0) return paths;
2267
+ // need_generic_pathscan: rename detection (log's diff.renames, default on) or -S/-G
2268
+ const renames = configBool(this.workingCopy, "diff.renames", true);
2269
+ if (d.findObjects && d.findObjects.length > 0 && !renames) {
2270
+ const wanted = new Set(d.findObjects);
2271
+ return paths.filter((path) => idsOf(path).some((id) => id !== undefined && wanted.has(id)));
2272
+ }
2273
+ let kept = paths;
2274
+ for (const p of entry.parents) {
2275
+ const commit = await this.commits.load(p);
2276
+ const diff = new DiffCommand(this._workingCopy)
2277
+ .setOldTree(commit ? commit.tree : this.objectFormat.emptyTreeId)
2278
+ .setNewTree(entry.commit.tree)
2279
+ .shareReadsOf(this)
2280
+ .setRenames(renames)
2281
+ .setOptions(d);
2282
+ // the walk's pathspec: --pickaxe-all looks at the whole queue of each parent
2283
+ const spec = [...this.paths, ...this.excludePaths.map((x) => `:(exclude)${x}`)];
2284
+ if (spec.length > 0) diff.setPathspec(spec);
2285
+ const listed = new Set((await diff.call()).map((e) => e.newPath ?? e.oldPath));
2286
+ kept = kept.filter((path) => listed.has(path));
2287
+ if (kept.length === 0) break;
2288
+ }
2289
+ return kept;
2290
+ }
2291
+
1229
2292
  /**
1230
2293
  * combine-diff.c's diff_tree_combined for a merge: the paths that differ from every
1231
2294
  * parent (within the pathspec), each as a combined diff of the trees.
@@ -1268,7 +2331,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1268
2331
  }
1269
2332
  const differs = (a?: { mode: number; id: ObjectId }, b?: { mode: number; id: ObjectId }) =>
1270
2333
  !a || !b ? a !== b : a.id !== b.id || a.mode !== b.mode;
1271
- const paths = [...all]
2334
+ let paths = [...all]
1272
2335
  .filter((path) => items.length === 0 || matchPathspec(items, path, 0) > 0)
1273
2336
  .filter((path) =>
1274
2337
  parents.every(
@@ -1285,6 +2348,10 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1285
2348
  }
1286
2349
  return ea.length - eb.length;
1287
2350
  });
2351
+ paths = await this.combinedPickaxe(entry, paths, (path) => [
2352
+ result.get(path)?.id,
2353
+ ...parents.map((m, k) => sideOf(m, k, path)?.id),
2354
+ ]);
1288
2355
  const sink = new ByteSink();
1289
2356
  const quote =
1290
2357
  parseGitBool(RemoteConfigStore.from(this._workingCopy).value("core.quotePath")) ?? true;
@@ -1368,6 +2435,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1368
2435
  abbreviate: (id) =>
1369
2436
  id.slice(0, this.diffOptions.fullIndex ? id.length : (lengths.get(id) ?? 7)),
1370
2437
  quotePath: quote,
2438
+ ...(this.colorSettings?.colors ? { colors: this.colorSettings.colors } : {}),
1371
2439
  },
1372
2440
  );
1373
2441
  }
@@ -1406,67 +2474,17 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1406
2474
 
1407
2475
  /** mailmap.c's read_mailmap: `.mailmap` (not in a bare repository), `mailmap.blob`, `mailmap.file` */
1408
2476
  private async loadMailmap(config: RemoteConfigStore): Promise<Mailmap> {
1409
- const map = new Mailmap();
1410
- const worktree = this.worktreeAccess;
1411
- const bare = parseGitBool(config.value("core.bare")) ?? !worktree;
1412
- if (!bare && worktree) {
1413
- try {
1414
- const entry = await worktree.getEntry(".mailmap");
1415
- if (entry && !entry.isDirectory && (entry.mode & 0o170000) !== 0o120000) {
1416
- const chunks: Uint8Array[] = [];
1417
- for await (const c of worktree.readContent(".mailmap")) chunks.push(c);
1418
- map.read(decodeGitPath(concatBytes(chunks)));
1419
- }
1420
- } catch {
1421
- // no .mailmap
1422
- }
1423
- }
1424
- const blobName = config.value("mailmap.blob") ?? (bare ? "HEAD:.mailmap" : undefined);
1425
- if (blobName) {
1426
- const id = await this.revisionResolver()
1427
- .resolve(blobName)
1428
- .catch(() => undefined);
1429
- const bytes = id ? await this.readBlob(id) : undefined;
1430
- if (bytes) map.read(decodeGitPath(bytes));
1431
- }
1432
- const file = config.value("mailmap.file");
1433
- if (file) {
1434
- const environment = hostEnvironmentOf(this._workingCopy);
1435
- const path = expandUserPath(file, environment);
1436
- const bytes = path !== undefined ? await this.readMailmapFile(path, environment) : undefined;
1437
- if (bytes) map.read(decodeGitPath(bytes));
1438
- }
1439
- return map;
1440
- }
1441
-
1442
- /**
1443
- * `mailmap.file`, read as git reads it: through the host (a relative path from its current
1444
- * directory). Without a host environment, a relative path is read from the worktree's top
1445
- * (where git usually runs), and an absolute one inside the worktree through it as well.
1446
- */
1447
- private async readMailmapFile(
1448
- path: string,
1449
- environment: ReturnType<typeof hostEnvironmentOf>,
1450
- ): Promise<Uint8Array | undefined> {
1451
- if (environment) return environment.readFile(path).catch(() => undefined);
1452
- const worktree = "worktree" in this._workingCopy ? this.worktreeAccess : undefined;
1453
- if (!worktree) return undefined;
1454
- let relative = path;
1455
- if (path.startsWith("/")) {
1456
- const top = (worktree as { hostPath?: string }).hostPath?.replace(/\/+$/, "");
1457
- if (!top || !path.startsWith(`${top}/`)) return undefined;
1458
- relative = path.slice(top.length + 1);
1459
- }
1460
- if (relative.split("/").includes("..")) return undefined;
1461
- try {
1462
- const entry = await worktree.getEntry(relative);
1463
- if (!entry || entry.isDirectory) return undefined;
1464
- const chunks: Uint8Array[] = [];
1465
- for await (const c of worktree.readContent(relative)) chunks.push(c);
1466
- return concatBytes(chunks);
1467
- } catch {
1468
- return undefined;
1469
- }
2477
+ return readRepositoryMailmap({
2478
+ config: (key) => config.value(key),
2479
+ worktree: this.worktreeAccess,
2480
+ environment: hostEnvironmentOf(this._workingCopy),
2481
+ readBlobNamed: async (name) => {
2482
+ const id = await this.revisionResolver()
2483
+ .resolve(name)
2484
+ .catch(() => undefined);
2485
+ return id ? this.readBlob(id) : undefined;
2486
+ },
2487
+ });
1470
2488
  }
1471
2489
 
1472
2490
  /**
@@ -2307,3 +3325,21 @@ function configAlgorithm(v: string | undefined): XdiffAlgorithm | undefined {
2307
3325
  if (s === "default") return "myers";
2308
3326
  return s === "myers" || s === "minimal" || s === "patience" || s === "histogram" ? s : undefined;
2309
3327
  }
3328
+
3329
+ /** tag.c's `parse_tag_buffer` of a mergetag: the object tagged and the tag's name. */
3330
+ function parseMergetag(
3331
+ bytes: Uint8Array,
3332
+ hexLength: number,
3333
+ ): { object: ObjectId; tag: string } | undefined {
3334
+ const text = decodeGitPath(bytes);
3335
+ if (bytes.length < hexLength + 24) return undefined;
3336
+ const object = new RegExp(`^object ([0-9a-f]{${hexLength}})\n`).exec(text);
3337
+ if (!object) return undefined;
3338
+ let rest = text.slice(object[0].length);
3339
+ if (!rest.startsWith("type ")) return undefined;
3340
+ const nl = rest.indexOf("\n");
3341
+ if (nl < 0) return undefined;
3342
+ rest = rest.slice(nl + 1);
3343
+ const tag = /^tag ([^\n]*)\n/.exec(rest);
3344
+ return { object: object[1] as ObjectId, tag: tag ? (tag[1] as string) : "(null)" };
3345
+ }