@statewalker/vcs-commands 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (481) hide show
  1. package/dist/commands/add-command.d.ts +38 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/am/am-command.d.ts +55 -1
  4. package/dist/commands/am/am-command.d.ts.map +1 -1
  5. package/dist/commands/am/index.d.ts +1 -0
  6. package/dist/commands/am/index.d.ts.map +1 -1
  7. package/dist/commands/am/mailsplit.d.ts +88 -0
  8. package/dist/commands/am/mailsplit.d.ts.map +1 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-engine.d.ts.map +1 -1
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/bisect/bisect-command.d.ts +2 -0
  13. package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
  14. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -1
  15. package/dist/commands/branch-command.d.ts +148 -18
  16. package/dist/commands/branch-command.d.ts.map +1 -1
  17. package/dist/commands/branch-info-command.d.ts +55 -0
  18. package/dist/commands/branch-info-command.d.ts.map +1 -0
  19. package/dist/commands/branch-tracking.d.ts +106 -17
  20. package/dist/commands/branch-tracking.d.ts.map +1 -1
  21. package/dist/commands/branch-upstream-command.d.ts +83 -0
  22. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  23. package/dist/commands/checkout-command.d.ts +19 -3
  24. package/dist/commands/checkout-command.d.ts.map +1 -1
  25. package/dist/commands/cherry-pick-command.d.ts +59 -0
  26. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  27. package/dist/commands/clean-command.d.ts +12 -0
  28. package/dist/commands/clean-command.d.ts.map +1 -1
  29. package/dist/commands/clone-command.d.ts +17 -0
  30. package/dist/commands/clone-command.d.ts.map +1 -1
  31. package/dist/commands/comment-char-config.d.ts +35 -0
  32. package/dist/commands/comment-char-config.d.ts.map +1 -0
  33. package/dist/commands/commit-command.d.ts +191 -5
  34. package/dist/commands/commit-command.d.ts.map +1 -1
  35. package/dist/commands/commit-reuse.d.ts +33 -0
  36. package/dist/commands/commit-reuse.d.ts.map +1 -0
  37. package/dist/commands/config-command.d.ts +236 -0
  38. package/dist/commands/config-command.d.ts.map +1 -0
  39. package/dist/commands/config-value-types.d.ts +91 -0
  40. package/dist/commands/config-value-types.d.ts.map +1 -0
  41. package/dist/commands/core-config.d.ts +20 -0
  42. package/dist/commands/core-config.d.ts.map +1 -1
  43. package/dist/commands/default-branch.d.ts +70 -0
  44. package/dist/commands/default-branch.d.ts.map +1 -0
  45. package/dist/commands/diff-color-config.d.ts +73 -0
  46. package/dist/commands/diff-color-config.d.ts.map +1 -0
  47. package/dist/commands/diff-command.d.ts +252 -5
  48. package/dist/commands/diff-command.d.ts.map +1 -1
  49. package/dist/commands/fetch-command.d.ts +20 -0
  50. package/dist/commands/fetch-command.d.ts.map +1 -1
  51. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  52. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  53. package/dist/commands/fork-point.d.ts +38 -0
  54. package/dist/commands/fork-point.d.ts.map +1 -0
  55. package/dist/commands/format-patch-command.d.ts +41 -1
  56. package/dist/commands/format-patch-command.d.ts.map +1 -1
  57. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  58. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  59. package/dist/commands/fsck/fsck-command.d.ts +2 -0
  60. package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
  61. package/dist/commands/fsck/fsck-loose.d.ts +3 -0
  62. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -1
  63. package/dist/commands/fsck/fsck-object-checks.d.ts +25 -14
  64. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
  65. package/dist/commands/fsck/fsck-object-table.d.ts +15 -7
  66. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -1
  67. package/dist/commands/fsck/fsck-pack.d.ts +11 -4
  68. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -1
  69. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -1
  70. package/dist/commands/gc-command.d.ts +80 -48
  71. package/dist/commands/gc-command.d.ts.map +1 -1
  72. package/dist/commands/git-date.d.ts +1 -65
  73. package/dist/commands/git-date.d.ts.map +1 -1
  74. package/dist/commands/git-describe.d.ts +4 -0
  75. package/dist/commands/git-describe.d.ts.map +1 -1
  76. package/dist/commands/git-hooks.d.ts +43 -0
  77. package/dist/commands/git-hooks.d.ts.map +1 -1
  78. package/dist/commands/grep/grep-command.d.ts +210 -0
  79. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  80. package/dist/commands/grep/grep-engine.d.ts +218 -0
  81. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  82. package/dist/commands/grep/index.d.ts +3 -0
  83. package/dist/commands/grep/index.d.ts.map +1 -0
  84. package/dist/commands/index-adder.d.ts +15 -2
  85. package/dist/commands/index-adder.d.ts.map +1 -1
  86. package/dist/commands/index.d.ts +28 -0
  87. package/dist/commands/index.d.ts.map +1 -1
  88. package/dist/commands/index.js +3 -3
  89. package/dist/commands/init-command.d.ts +50 -3
  90. package/dist/commands/init-command.d.ts.map +1 -1
  91. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  92. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  93. package/dist/commands/legacy-remotes.d.ts +55 -0
  94. package/dist/commands/legacy-remotes.d.ts.map +1 -0
  95. package/dist/commands/local-transport.d.ts +36 -5
  96. package/dist/commands/local-transport.d.ts.map +1 -1
  97. package/dist/commands/log-command.d.ts +296 -11
  98. package/dist/commands/log-command.d.ts.map +1 -1
  99. package/dist/commands/log-graph.d.ts +26 -1
  100. package/dist/commands/log-graph.d.ts.map +1 -1
  101. package/dist/commands/log-output.d.ts +133 -5
  102. package/dist/commands/log-output.d.ts.map +1 -1
  103. package/dist/commands/ls-remote-command.d.ts +2 -0
  104. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  105. package/dist/commands/mailmap.d.ts +30 -0
  106. package/dist/commands/mailmap.d.ts.map +1 -1
  107. package/dist/commands/merge-base-command.d.ts +60 -0
  108. package/dist/commands/merge-base-command.d.ts.map +1 -0
  109. package/dist/commands/merge-bases.d.ts +23 -0
  110. package/dist/commands/merge-bases.d.ts.map +1 -1
  111. package/dist/commands/merge-command.d.ts +108 -9
  112. package/dist/commands/merge-command.d.ts.map +1 -1
  113. package/dist/commands/merge-support.d.ts +11 -3
  114. package/dist/commands/merge-support.d.ts.map +1 -1
  115. package/dist/commands/mv-command.d.ts +4 -0
  116. package/dist/commands/mv-command.d.ts.map +1 -1
  117. package/dist/commands/name-rev.d.ts +48 -0
  118. package/dist/commands/name-rev.d.ts.map +1 -0
  119. package/dist/commands/notes-command.d.ts.map +1 -1
  120. package/dist/commands/notes-merge-command.d.ts.map +1 -1
  121. package/dist/commands/notes-tree.d.ts +11 -1
  122. package/dist/commands/notes-tree.d.ts.map +1 -1
  123. package/dist/commands/patch-id.d.ts +3 -0
  124. package/dist/commands/patch-id.d.ts.map +1 -1
  125. package/dist/commands/pathspec-file.d.ts +39 -0
  126. package/dist/commands/pathspec-file.d.ts.map +1 -0
  127. package/dist/commands/pathspec.d.ts +3 -0
  128. package/dist/commands/pathspec.d.ts.map +1 -1
  129. package/dist/commands/pretty-format.d.ts +43 -3
  130. package/dist/commands/pretty-format.d.ts.map +1 -1
  131. package/dist/commands/promisor-remote.d.ts.map +1 -1
  132. package/dist/commands/pull-command.d.ts +28 -0
  133. package/dist/commands/pull-command.d.ts.map +1 -1
  134. package/dist/commands/push-command.d.ts +160 -9
  135. package/dist/commands/push-command.d.ts.map +1 -1
  136. package/dist/commands/read-tree-command.d.ts +6 -0
  137. package/dist/commands/read-tree-command.d.ts.map +1 -1
  138. package/dist/commands/rebase-command.d.ts +168 -6
  139. package/dist/commands/rebase-command.d.ts.map +1 -1
  140. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  141. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  142. package/dist/commands/ref-filter/index.d.ts +8 -0
  143. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  144. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  145. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  146. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  147. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  148. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  149. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  150. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  151. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  152. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  153. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  154. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  155. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  156. package/dist/commands/reflog-command.d.ts +120 -0
  157. package/dist/commands/reflog-command.d.ts.map +1 -1
  158. package/dist/commands/reflog-walk.d.ts +72 -0
  159. package/dist/commands/reflog-walk.d.ts.map +1 -0
  160. package/dist/commands/remote-command.d.ts +138 -29
  161. package/dist/commands/remote-command.d.ts.map +1 -1
  162. package/dist/commands/remote-transport.d.ts +7 -1
  163. package/dist/commands/remote-transport.d.ts.map +1 -1
  164. package/dist/commands/reset-command.d.ts +2 -3
  165. package/dist/commands/reset-command.d.ts.map +1 -1
  166. package/dist/commands/restore-command.d.ts +2 -3
  167. package/dist/commands/restore-command.d.ts.map +1 -1
  168. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  169. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  170. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  171. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  172. package/dist/commands/rev-filter/index.d.ts +3 -0
  173. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  174. package/dist/commands/rev-list-command.d.ts +154 -2
  175. package/dist/commands/rev-list-command.d.ts.map +1 -1
  176. package/dist/commands/rev-parse-command.d.ts +9 -0
  177. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  178. package/dist/commands/revert-command.d.ts +32 -0
  179. package/dist/commands/revert-command.d.ts.map +1 -1
  180. package/dist/commands/revision-range.d.ts +32 -1
  181. package/dist/commands/revision-range.d.ts.map +1 -1
  182. package/dist/commands/revision-resolver.d.ts +21 -2
  183. package/dist/commands/revision-resolver.d.ts.map +1 -1
  184. package/dist/commands/rm-command.d.ts +70 -2
  185. package/dist/commands/rm-command.d.ts.map +1 -1
  186. package/dist/commands/sequencer-pick.d.ts +85 -5
  187. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  188. package/dist/commands/sequencer-support.d.ts +2 -0
  189. package/dist/commands/sequencer-support.d.ts.map +1 -1
  190. package/dist/commands/serve-repository.d.ts +7 -0
  191. package/dist/commands/serve-repository.d.ts.map +1 -1
  192. package/dist/commands/show-command.d.ts +130 -0
  193. package/dist/commands/show-command.d.ts.map +1 -0
  194. package/dist/commands/show-commit.d.ts +11 -0
  195. package/dist/commands/show-commit.d.ts.map +1 -0
  196. package/dist/commands/signature-check.d.ts +164 -0
  197. package/dist/commands/signature-check.d.ts.map +1 -0
  198. package/dist/commands/signing.d.ts +160 -0
  199. package/dist/commands/signing.d.ts.map +1 -0
  200. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  201. package/dist/commands/sparse-index-view.d.ts +45 -0
  202. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  203. package/dist/commands/ssh-signer.d.ts +29 -0
  204. package/dist/commands/ssh-signer.d.ts.map +1 -0
  205. package/dist/commands/ssh-verifier.d.ts +42 -0
  206. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  207. package/dist/commands/stash-apply-command.d.ts +5 -0
  208. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  209. package/dist/commands/stash-branch-command.d.ts +34 -0
  210. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  211. package/dist/commands/stash-create-command.d.ts +18 -1
  212. package/dist/commands/stash-create-command.d.ts.map +1 -1
  213. package/dist/commands/stash-info.d.ts +93 -0
  214. package/dist/commands/stash-info.d.ts.map +1 -0
  215. package/dist/commands/stash-list-command.d.ts +16 -0
  216. package/dist/commands/stash-list-command.d.ts.map +1 -1
  217. package/dist/commands/stash-pop-command.d.ts +39 -0
  218. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  219. package/dist/commands/stash-show-command.d.ts +48 -0
  220. package/dist/commands/stash-show-command.d.ts.map +1 -0
  221. package/dist/commands/stash-store-command.d.ts +29 -0
  222. package/dist/commands/stash-store-command.d.ts.map +1 -0
  223. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  224. package/dist/commands/status-command.d.ts.map +1 -1
  225. package/dist/commands/status-header.d.ts +5 -0
  226. package/dist/commands/status-header.d.ts.map +1 -1
  227. package/dist/commands/submodule-add-command.d.ts +89 -0
  228. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  229. package/dist/commands/submodule-auth.d.ts +90 -0
  230. package/dist/commands/submodule-auth.d.ts.map +1 -0
  231. package/dist/commands/submodule-commands.d.ts +375 -0
  232. package/dist/commands/submodule-commands.d.ts.map +1 -0
  233. package/dist/commands/submodule-model.d.ts +288 -0
  234. package/dist/commands/submodule-model.d.ts.map +1 -0
  235. package/dist/commands/submodule-summary-command.d.ts.map +1 -1
  236. package/dist/commands/submodule-update-command.d.ts +198 -0
  237. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  238. package/dist/commands/switch-command.d.ts.map +1 -1
  239. package/dist/commands/tag-command.d.ts +259 -10
  240. package/dist/commands/tag-command.d.ts.map +1 -1
  241. package/dist/commands/trailers.d.ts +218 -17
  242. package/dist/commands/trailers.d.ts.map +1 -1
  243. package/dist/commands/tree-restore.d.ts +7 -0
  244. package/dist/commands/tree-restore.d.ts.map +1 -1
  245. package/dist/commands/untracked-cache-support.d.ts +2 -1
  246. package/dist/commands/untracked-cache-support.d.ts.map +1 -1
  247. package/dist/commands/verify-command.d.ts +92 -0
  248. package/dist/commands/verify-command.d.ts.map +1 -0
  249. package/dist/commands/worktree-add-command.d.ts +79 -7
  250. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  251. package/dist/commands/worktree-list-command.d.ts.map +1 -1
  252. package/dist/commands/worktree-path-rules.d.ts +66 -0
  253. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  254. package/dist/commands/worktree-remove-command.d.ts +10 -3
  255. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  256. package/dist/commands/worktree-repair-command.d.ts +15 -2
  257. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  258. package/dist/commands/worktree-support.d.ts +5 -0
  259. package/dist/commands/worktree-support.d.ts.map +1 -1
  260. package/dist/{commands-DnmlfwGV.js → commands-ISM52N0n.js} +66120 -49271
  261. package/dist/errors/checkout-errors.d.ts +19 -0
  262. package/dist/errors/checkout-errors.d.ts.map +1 -1
  263. package/dist/errors/command-errors.d.ts.map +1 -1
  264. package/dist/errors/index.js +57 -3
  265. package/dist/errors/ref-errors.d.ts +19 -0
  266. package/dist/errors/ref-errors.d.ts.map +1 -1
  267. package/dist/errors/worktree-errors.d.ts +6 -1
  268. package/dist/errors/worktree-errors.d.ts.map +1 -1
  269. package/dist/{git-command-DxvwPrPB.js → fsck-DLRpbwTj.js} +6863 -1070
  270. package/dist/git-command.d.ts +43 -2
  271. package/dist/git-command.d.ts.map +1 -1
  272. package/dist/git.d.ts +276 -3
  273. package/dist/git.d.ts.map +1 -1
  274. package/dist/index.js +5 -5
  275. package/dist/remote-config/index.d.ts +1 -1
  276. package/dist/remote-config/index.d.ts.map +1 -1
  277. package/dist/remote-config/remote-config-store.d.ts +117 -3
  278. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  279. package/dist/rename/detect-renames.d.ts.map +1 -1
  280. package/dist/results/clone-result.d.ts +8 -0
  281. package/dist/results/clone-result.d.ts.map +1 -1
  282. package/dist/results/combined-diff.d.ts +3 -0
  283. package/dist/results/combined-diff.d.ts.map +1 -1
  284. package/dist/results/diff-check.d.ts +38 -0
  285. package/dist/results/diff-check.d.ts.map +1 -0
  286. package/dist/results/diff-color.d.ts +135 -0
  287. package/dist/results/diff-color.d.ts.map +1 -0
  288. package/dist/results/diff-output.d.ts +85 -1
  289. package/dist/results/diff-output.d.ts.map +1 -1
  290. package/dist/results/diff-pickaxe.d.ts +67 -0
  291. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  292. package/dist/results/diff-words.d.ts +55 -0
  293. package/dist/results/diff-words.d.ts.map +1 -0
  294. package/dist/results/index.d.ts +4 -0
  295. package/dist/results/index.d.ts.map +1 -1
  296. package/dist/results/index.js +2 -2
  297. package/dist/results/init-result.d.ts +7 -0
  298. package/dist/results/init-result.d.ts.map +1 -1
  299. package/dist/results/pull-result.d.ts +5 -0
  300. package/dist/results/pull-result.d.ts.map +1 -1
  301. package/dist/results/push-result.d.ts +12 -0
  302. package/dist/results/push-result.d.ts.map +1 -1
  303. package/dist/results/rebase-result.d.ts +2 -0
  304. package/dist/results/rebase-result.d.ts.map +1 -1
  305. package/dist/results/stash-result.d.ts +6 -0
  306. package/dist/results/stash-result.d.ts.map +1 -1
  307. package/dist/results/status-result.d.ts.map +1 -1
  308. package/dist/{results-BZGa2Z3I.js → results-TB2IJ64h.js} +2178 -412
  309. package/dist/whitespace/index.d.ts +2 -0
  310. package/dist/whitespace/index.d.ts.map +1 -0
  311. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  312. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  313. package/package.json +12 -12
  314. package/src/commands/add-command.ts +178 -17
  315. package/src/commands/add-patch/add-interactive.ts +3 -3
  316. package/src/commands/am/am-command.ts +263 -43
  317. package/src/commands/am/index.ts +1 -0
  318. package/src/commands/am/mailsplit.ts +326 -0
  319. package/src/commands/apply/apply-command.ts +18 -8
  320. package/src/commands/apply/apply-engine.ts +6 -7
  321. package/src/commands/apply/apply-parse.ts +10 -10
  322. package/src/commands/attributes-source.ts +1 -1
  323. package/src/commands/bisect/bisect-command.ts +18 -5
  324. package/src/commands/bisect/bisect-engine.ts +2 -1
  325. package/src/commands/branch-command.ts +528 -53
  326. package/src/commands/branch-info-command.ts +150 -0
  327. package/src/commands/branch-tracking.ts +335 -60
  328. package/src/commands/branch-upstream-command.ts +218 -0
  329. package/src/commands/checkout-command.ts +70 -44
  330. package/src/commands/cherry-pick-command.ts +143 -0
  331. package/src/commands/clean-command.ts +34 -3
  332. package/src/commands/clone-command.ts +118 -5
  333. package/src/commands/comment-char-config.ts +160 -0
  334. package/src/commands/commit-command.ts +790 -71
  335. package/src/commands/commit-reuse.ts +94 -0
  336. package/src/commands/config-command.ts +1256 -0
  337. package/src/commands/config-value-types.ts +358 -0
  338. package/src/commands/core-config.ts +47 -2
  339. package/src/commands/default-branch.ts +196 -0
  340. package/src/commands/diff-color-config.ts +274 -0
  341. package/src/commands/diff-command.ts +1053 -75
  342. package/src/commands/fetch-command.ts +161 -13
  343. package/src/commands/fmt-merge-msg-command.ts +715 -0
  344. package/src/commands/fork-point.ts +63 -0
  345. package/src/commands/format-patch-command.ts +316 -43
  346. package/src/commands/fsck/fetch-fsck.ts +172 -18
  347. package/src/commands/fsck/fsck-command.ts +183 -66
  348. package/src/commands/fsck/fsck-loose.ts +14 -4
  349. package/src/commands/fsck/fsck-object-checks.ts +87 -46
  350. package/src/commands/fsck/fsck-object-table.ts +52 -42
  351. package/src/commands/fsck/fsck-pack.ts +64 -34
  352. package/src/commands/fsck/verify-pack-command.ts +5 -2
  353. package/src/commands/gc-command.ts +238 -107
  354. package/src/commands/git-date.ts +9 -895
  355. package/src/commands/git-describe.ts +31 -11
  356. package/src/commands/git-hooks.ts +92 -0
  357. package/src/commands/grep/grep-command.ts +1077 -0
  358. package/src/commands/grep/grep-engine.ts +1024 -0
  359. package/src/commands/grep/index.ts +2 -0
  360. package/src/commands/index-adder.ts +54 -10
  361. package/src/commands/index.ts +28 -0
  362. package/src/commands/init-command.ts +167 -11
  363. package/src/commands/interpret-trailers-command.ts +256 -0
  364. package/src/commands/legacy-remotes.ts +224 -0
  365. package/src/commands/local-transport.ts +109 -10
  366. package/src/commands/log-command.ts +1283 -232
  367. package/src/commands/log-graph.ts +123 -26
  368. package/src/commands/log-output.ts +280 -21
  369. package/src/commands/ls-remote-command.ts +9 -0
  370. package/src/commands/mailmap.ts +119 -0
  371. package/src/commands/merge-base-command.ts +170 -0
  372. package/src/commands/merge-bases.ts +63 -8
  373. package/src/commands/merge-command.ts +360 -82
  374. package/src/commands/merge-support.ts +43 -9
  375. package/src/commands/mv-command.ts +6 -3
  376. package/src/commands/name-rev.ts +171 -0
  377. package/src/commands/notes-command.ts +11 -1
  378. package/src/commands/notes-merge-command.ts +23 -14
  379. package/src/commands/notes-tree.ts +28 -13
  380. package/src/commands/octopus-merge.ts +3 -2
  381. package/src/commands/patch-id.ts +16 -8
  382. package/src/commands/pathspec-file.ts +72 -0
  383. package/src/commands/pathspec.ts +14 -2
  384. package/src/commands/pretty-format.ts +105 -20
  385. package/src/commands/promisor-remote.ts +10 -1
  386. package/src/commands/pull-command.ts +149 -22
  387. package/src/commands/push-command.ts +704 -72
  388. package/src/commands/read-tree-command.ts +34 -3
  389. package/src/commands/rebase-command.ts +957 -142
  390. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  391. package/src/commands/ref-filter/index.ts +7 -0
  392. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  393. package/src/commands/ref-filter/ref-filter.ts +651 -0
  394. package/src/commands/ref-filter/ref-format.ts +1070 -0
  395. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  396. package/src/commands/ref-filter/ref-quote.ts +69 -0
  397. package/src/commands/ref-filter/version-compare.ts +177 -0
  398. package/src/commands/reflog-command.ts +492 -2
  399. package/src/commands/reflog-walk.ts +234 -0
  400. package/src/commands/remote-command.ts +484 -74
  401. package/src/commands/remote-transport.ts +9 -1
  402. package/src/commands/reset-command.ts +40 -42
  403. package/src/commands/restore-command.ts +12 -41
  404. package/src/commands/rev-filter/commit-filter.ts +159 -0
  405. package/src/commands/rev-filter/commit-grep.ts +444 -0
  406. package/src/commands/rev-filter/index.ts +2 -0
  407. package/src/commands/rev-list-command.ts +402 -15
  408. package/src/commands/rev-parse-command.ts +22 -0
  409. package/src/commands/revert-command.ts +82 -0
  410. package/src/commands/revision-range.ts +204 -4
  411. package/src/commands/revision-resolver.ts +55 -22
  412. package/src/commands/rm-command.ts +282 -21
  413. package/src/commands/sequencer-pick.ts +504 -86
  414. package/src/commands/sequencer-support.ts +30 -5
  415. package/src/commands/serve-repository.ts +18 -3
  416. package/src/commands/show-command.ts +490 -0
  417. package/src/commands/show-commit.ts +24 -0
  418. package/src/commands/signature-check.ts +657 -0
  419. package/src/commands/signing.ts +385 -0
  420. package/src/commands/sparse-checkout-command.ts +2 -9
  421. package/src/commands/sparse-checkout-support.ts +2 -2
  422. package/src/commands/sparse-index-view.ts +135 -0
  423. package/src/commands/ssh-signer.ts +199 -0
  424. package/src/commands/ssh-verifier.ts +523 -0
  425. package/src/commands/stash-apply-command.ts +17 -5
  426. package/src/commands/stash-branch-command.ts +88 -0
  427. package/src/commands/stash-create-command.ts +30 -2
  428. package/src/commands/stash-info.ts +243 -0
  429. package/src/commands/stash-list-command.ts +33 -0
  430. package/src/commands/stash-pop-command.ts +83 -0
  431. package/src/commands/stash-show-command.ts +141 -0
  432. package/src/commands/stash-store-command.ts +82 -0
  433. package/src/commands/stash-working-tree.ts +2 -2
  434. package/src/commands/status-command.ts +7 -6
  435. package/src/commands/status-header.ts +44 -8
  436. package/src/commands/submodule-add-command.ts +509 -0
  437. package/src/commands/submodule-auth.ts +276 -0
  438. package/src/commands/submodule-commands.ts +1517 -0
  439. package/src/commands/submodule-model.ts +930 -0
  440. package/src/commands/submodule-summary-command.ts +6 -7
  441. package/src/commands/submodule-update-command.ts +1092 -0
  442. package/src/commands/switch-command.ts +3 -1
  443. package/src/commands/tag-command.ts +876 -64
  444. package/src/commands/trailers.ts +837 -100
  445. package/src/commands/tree-restore.ts +38 -10
  446. package/src/commands/untracked-cache-support.ts +16 -12
  447. package/src/commands/verify-command.ts +235 -0
  448. package/src/commands/worktree-add-command.ts +268 -24
  449. package/src/commands/worktree-list-command.ts +3 -5
  450. package/src/commands/worktree-path-rules.ts +183 -0
  451. package/src/commands/worktree-remove-command.ts +39 -5
  452. package/src/commands/worktree-repair-command.ts +52 -5
  453. package/src/commands/worktree-support.ts +22 -1
  454. package/src/core-commands/add.command.impl.ts +1 -1
  455. package/src/errors/checkout-errors.ts +29 -0
  456. package/src/errors/command-errors.ts +2 -1
  457. package/src/errors/ref-errors.ts +23 -0
  458. package/src/errors/worktree-errors.ts +8 -1
  459. package/src/git-command.ts +98 -3
  460. package/src/git.ts +420 -4
  461. package/src/remote-config/index.ts +4 -0
  462. package/src/remote-config/remote-config-store.ts +238 -11
  463. package/src/rename/detect-renames.ts +5 -1
  464. package/src/results/clone-result.ts +9 -0
  465. package/src/results/combined-diff.ts +38 -18
  466. package/src/results/diff-check.ts +185 -0
  467. package/src/results/diff-color.ts +868 -0
  468. package/src/results/diff-output.ts +204 -37
  469. package/src/results/diff-pickaxe.ts +304 -0
  470. package/src/results/diff-words.ts +395 -0
  471. package/src/results/index.ts +4 -0
  472. package/src/results/init-result.ts +9 -0
  473. package/src/results/pull-result.ts +5 -0
  474. package/src/results/push-result.ts +12 -0
  475. package/src/results/rebase-result.ts +3 -0
  476. package/src/results/stash-result.ts +7 -0
  477. package/src/results/status-result.ts +5 -2
  478. package/src/whitespace/index.ts +1 -0
  479. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  480. package/dist/commands/apply/whitespace.d.ts +0 -58
  481. package/dist/commands/apply/whitespace.d.ts.map +0 -1
@@ -6,10 +6,11 @@ import {
6
6
  type CommitGraph,
7
7
  canonTreeMode,
8
8
  commitFromBytes,
9
- EMPTY_TREE_ID,
10
9
  type GitObject,
10
+ isSymbolicRef,
11
11
  type ObjectId,
12
12
  type ObjectReplacements,
13
+ type PersonIdent,
13
14
  parseGraphCommit,
14
15
  replacementOf,
15
16
  } from "@statewalker/vcs-core";
@@ -17,27 +18,44 @@ import { ByteSink, OrderedMap, parseGitBool, type XdiffAlgorithm } from "@statew
17
18
  import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
18
19
  import { bytesToHex, hexToBytes } from "@statewalker/vcs-utils/hash/utils";
19
20
 
20
- import {
21
- type AttributesResolver,
22
- type ContentAttributesContext,
23
- expandUserPath,
24
- } from "@statewalker/vcs-working-tree";
21
+ import type { AttributesResolver, ContentAttributesContext } from "@statewalker/vcs-working-tree";
25
22
 
26
- import { GitApiError, IncompatibleOptionsError } from "../errors/index.js";
23
+ import {
24
+ GitApiError,
25
+ IncompatibleOptionsError,
26
+ InvalidArgumentError,
27
+ InvalidConfigError,
28
+ NotImplementedError,
29
+ } from "../errors/index.js";
27
30
  import { GitCommand } from "../git-command.js";
28
31
  import { RemoteConfigStore } from "../remote-config/index.js";
29
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";
30
35
  import { quotePath } from "../results/quote-path.js";
31
36
  import { bareAttributesResolver } from "./attributes-source.js";
32
- 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";
33
49
  import { hostEnvironmentOf } from "./git-ident.js";
50
+ import { GRAPH_COLUMN_COLORS_ANSI, graphColumnColors } from "./log-graph.js";
34
51
  import {
35
52
  type LogOutputEntry,
36
53
  type LogOutputHost,
37
54
  type LogOutputOptions,
38
55
  LogPrinter,
56
+ type LogReflogEntry,
39
57
  } from "./log-output.js";
40
- import { Mailmap } from "./mailmap.js";
58
+ import { type Mailmap, readRepositoryMailmap } from "./mailmap.js";
41
59
  import { configBool, configValue } from "./merge-config.js";
42
60
  import {
43
61
  addRefsByGlob,
@@ -65,10 +83,24 @@ import {
65
83
  treePathspec,
66
84
  } from "./pathspec.js";
67
85
  import { PathspecAttributes } from "./pathspec-attributes.js";
68
- 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";
69
102
  import { readDiffSubmoduleConfig } from "./submodule-summary.js";
70
-
71
- const NULL_OBJECT_ID = "0".repeat(40);
103
+ import { shortenUnambiguousRef } from "./worktree-list-command.js";
72
104
 
73
105
  /** What {@link LogCommand.callBytes} asks of the walk. */
74
106
  interface OutputWalk {
@@ -84,6 +116,20 @@ interface OutputWalk {
84
116
  unwalkedShown?: Set<ObjectId>;
85
117
  }
86
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
+
87
133
  /** git log reads no index: the in-tree attributes files are the worktree's only. */
88
134
  const NO_INDEX = { attributesBlob: () => undefined };
89
135
 
@@ -95,8 +141,50 @@ const NO_INDEX = { attributesBlob: () => undefined };
95
141
  export interface LogResult extends Commit {
96
142
  /** The SHA-1 object ID of the commit */
97
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 };
98
178
  }
99
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
+
100
188
  /**
101
189
  * What a path-limited walk did (git's trace2 `bloom` statistics, and the tree work behind
102
190
  * them): how often the changed-path filters answered, and how many tree entries the walk read
@@ -192,7 +280,7 @@ export enum RevFilter {
192
280
  export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
193
281
  private startCommits: ObjectId[] = [];
194
282
  /** The commits given, included and excluded, in the order given (git's pending list) */
195
- private readonly pending: { id: ObjectId; exclude: boolean }[] = [];
283
+ private readonly pending: PendingCommit[] = [];
196
284
  private paths: string[] = [];
197
285
  private excludePaths: string[] = [];
198
286
  private maxCount?: number;
@@ -208,6 +296,21 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
208
296
  private authorPattern?: string;
209
297
  private committerPattern?: string;
210
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;
211
314
  private useBloomFilters = true;
212
315
  private readonly statistics: LogPathStatistics = {
213
316
  bloomDefinitelyNot: 0,
@@ -221,6 +324,140 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
221
324
  private lastWalk: RevTable | undefined;
222
325
  /** Set while {@link callBytes} collects the walk for its output */
223
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
+ }
224
461
 
225
462
  /**
226
463
  * Add a starting commit for the log.
@@ -230,11 +467,12 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
230
467
  * peels it; with {@link all} the refs are walked besides (`git log --all <commit>`).
231
468
  *
232
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)
233
471
  */
234
- add(commit: ObjectId): this {
472
+ add(commit: ObjectId, name?: string): this {
235
473
  this.checkCallable();
236
474
  this.startCommits.push(commit);
237
- this.pending.push({ id: commit, exclude: false });
475
+ this.pending.push({ id: commit, exclude: false, ...(name !== undefined ? { name } : {}) });
238
476
  return this;
239
477
  }
240
478
 
@@ -336,10 +574,11 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
336
574
  * Useful for finding commits in one branch but not another.
337
575
  *
338
576
  * @param commit ObjectId to exclude along with its ancestors
577
+ * @param name The name it was given by (see {@link add})
339
578
  */
340
- not(commit: ObjectId): this {
579
+ not(commit: ObjectId, name?: string): this {
341
580
  this.checkCallable();
342
- this.pending.push({ id: commit, exclude: true });
581
+ this.pending.push({ id: commit, exclude: true, ...(name !== undefined ? { name } : {}) });
343
582
  return this;
344
583
  }
345
584
 
@@ -412,6 +651,106 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
412
651
  return this;
413
652
  }
414
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
+
415
754
  /**
416
755
  * Whether a path-limited walk asks the commit-graph's changed-path Bloom filters before it
417
756
  * compares trees (default true, as git does whenever the graph has filters).
@@ -459,21 +798,126 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
459
798
  this.setCallable(false);
460
799
  // git_log_config ends in git_diff_ui_config: a diff.submodule without a value dies
461
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();
462
810
 
463
811
  // the commits given, in order, the refs of `all()` where it was called; HEAD without
464
812
  // either
465
- const pending: { id: ObjectId; exclude: boolean }[] = [];
813
+ const pending: PendingCommit[] = [];
466
814
  for (let i = 0; i <= this.pending.length; i++) {
467
815
  if (this.includeAll && i === this.allAt) {
468
- 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 });
469
818
  }
470
819
  const e = this.pending[i];
471
- 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
+ });
472
826
  }
473
827
  if (this.startCommits.length === 0 && !this.includeAll) {
474
- pending.push({ id: await this.resolveHead(), exclude: false });
828
+ pending.push({ id: await this.resolveHead(), exclude: false, name: "HEAD" });
475
829
  }
476
- 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;
477
921
  }
478
922
 
479
923
  /** The commit an annotated tag (or a chain of them) tags; any other id as it is. */
@@ -493,7 +937,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
493
937
  * (refs_for_each_ref, symbolic ones resolved), then HEAD (refs_head_ref); annotated tags
494
938
  * peeled.
495
939
  */
496
- private async getAllRefs(): Promise<ObjectId[]> {
940
+ private async getAllRefs(): Promise<{ id: ObjectId; name: string }[]> {
497
941
  const named: { name: Uint8Array; id: ObjectId }[] = [];
498
942
  for await (const ref of this.refsStore.list()) {
499
943
  if (!ref.name.startsWith("refs/")) continue;
@@ -502,10 +946,11 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
502
946
  if (id) named.push({ name: encodeGitPath(ref.name), id });
503
947
  }
504
948
  named.sort((a, b) => compareBytes(a.name, b.name));
505
- const ids: ObjectId[] = [];
506
- 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) });
507
952
  const head = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
508
- if (head) ids.push(await this.peelToCommit(head));
953
+ if (head) ids.push({ id: await this.peelToCommit(head), name: "HEAD" });
509
954
  return ids;
510
955
  }
511
956
 
@@ -529,7 +974,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
529
974
  * The commits met are held in a `RevTable` (typed arrays, a few dozen bytes each); commits
530
975
  * the commit-graph has are reached by their graph positions, without building their ids.
531
976
  */
532
- private async *walk(pending: { id: ObjectId; exclude: boolean }[]): AsyncIterable<LogResult> {
977
+ private async *walk(pending: PendingCommit[]): AsyncIterable<LogResult> {
533
978
  const prune = this.paths.length > 0 || this.excludePaths.length > 0;
534
979
  // a shallow commit has no parents (git's shallow grafts); the graph is off then
535
980
  const shallowIds = (await this.refsStore.getShallow?.().catch(() => undefined)) ?? [];
@@ -558,6 +1003,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
558
1003
  let trackTreesame = false;
559
1004
  const t = new RevTable(graph);
560
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;
561
1008
  /** Raw commits read by `parse` (no graph), kept until shown: read once, not twice. */
562
1009
  const raw = new Map<number, Uint8Array>();
563
1010
 
@@ -678,6 +1125,10 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
678
1125
  if (!(await parse(p))) {
679
1126
  throw new GitApiError(`Failed to traverse parents of commit ${t.idOf(n)}`);
680
1127
  }
1128
+ if (sources && !sources.has(p)) {
1129
+ const source = sources.get(n);
1130
+ if (source !== undefined) sources.set(p, source);
1131
+ }
681
1132
  if (!(t.flag(p) & SEEN)) {
682
1133
  t.mark(p, SEEN);
683
1134
  queue.put(p, t.date(p));
@@ -711,7 +1162,19 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
711
1162
  if (shallow.has(id)) commit.parents = [];
712
1163
  if (this.authorPattern !== undefined && !this.matchesAuthor(commit)) return undefined;
713
1164
  if (this.committerPattern !== undefined && !this.matchesCommitter(commit)) return undefined;
714
- 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 };
715
1178
  };
716
1179
 
717
1180
  // prepare_revision_walk: the flags of every argument first, then handle_commit in order
@@ -742,6 +1205,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
742
1205
  for (const e of pending) {
743
1206
  const n = t.lookup(e.id);
744
1207
  if (!(await parse(n))) continue;
1208
+ if (sources && !sources.has(n) && e.name !== undefined) sources.set(n, e.name);
745
1209
  if (t.flag(n) & UNINTERESTING) {
746
1210
  markParentsUninteresting(n);
747
1211
  limited = true;
@@ -756,95 +1220,178 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
756
1220
  const queue = new CommitQueue<number>();
757
1221
  for (const n of list) queue.put(n, t.date(n));
758
1222
 
759
- let count = 0;
760
- let skipped = 0;
761
- // git's -n 0 reads nothing more in a streaming walk; a limited walk is done before
762
1223
  const none = this.maxCount !== undefined && this.maxCount <= 0;
763
1224
  const output = this.outputWalk;
764
- // the output's walk is limited (git without generation numbers limits a topo walk)
765
- trackTreesame = (limited || !!output) && prune && !simplifyHistory && !firstParentOnly;
766
- if (!limited && !output) {
767
- 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) {
768
1279
  // get_revision_1, streaming
769
- for (let n = queue.get(); n !== undefined; n = queue.get()) {
770
- // --since: older commits are dropped without walking their parents (max_age)
771
- if (this.sinceTime !== undefined && t.date(n) < this.sinceTime) {
772
- raw.delete(n);
773
- 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;
774
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;
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);
775
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) {
776
1360
  const commit = await shown(n);
777
1361
  if (!commit) continue;
778
1362
  if (skipped < this.skip) {
779
1363
  skipped++;
780
1364
  continue;
781
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
+ }
782
1375
  yield commit;
783
- if (this.maxCount !== undefined && ++count >= this.maxCount) return;
784
- }
785
- return;
786
- }
787
-
788
- // limit_list
789
- const newlist: number[] = [];
790
- let date = Number.POSITIVE_INFINITY;
791
- let slop = SLOP;
792
- let interestingCache = -1;
793
- /** git's everybody_uninteresting */
794
- const everybodyUninteresting = (): boolean => {
795
- if (interestingCache >= 0 && !(t.flag(interestingCache) & UNINTERESTING)) return false;
796
- for (const n of queue.items()) {
797
- if (t.flag(n) & UNINTERESTING) continue;
798
- interestingCache = n;
799
- return false;
800
- }
801
- return true;
802
- };
803
- /** git's still_interesting */
804
- const stillInteresting = (): number => {
805
- const head = queue.peek();
806
- if (head === undefined) return 0;
807
- if (date <= t.date(head)) return SLOP;
808
- if (!everybodyUninteresting()) return SLOP;
809
- return slop - 1;
810
- };
811
- for (let n = queue.get(); n !== undefined; n = queue.get()) {
812
- // what is shown is read again at the end: a limited walk does not keep raw commits
813
- raw.delete(n);
814
- if (n === interestingCache) interestingCache = -1;
815
- if (this.sinceTime !== undefined && t.date(n) < this.sinceTime) t.mark(n, UNINTERESTING);
816
- await processParents(n, queue);
817
- if (t.flag(n) & UNINTERESTING) {
818
- markParentsUninteresting(n);
819
- slop = stillInteresting();
820
- if (slop) continue;
821
- break;
822
- }
823
- if (this.untilTime !== undefined && t.date(n) > this.untilTime) continue;
824
- date = t.date(n);
825
- newlist.push(n);
826
- }
827
- // commits made TREESAME by parents that became UNINTERESTING
828
- if (trackTreesame) {
829
- for (const n of newlist) {
830
- if (!(t.flag(n) & (UNINTERESTING | TREESAME))) updateTreesame(n);
1376
+ if (this.maxCount !== undefined && ++count >= this.maxCount) break;
831
1377
  }
832
1378
  }
833
- raw.clear();
834
- if (output) {
835
- await this.finishOutputWalk(output, t, newlist, shown, relevant, parse);
836
- 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);
837
1387
  }
838
- if (none) return;
839
- for (const n of newlist) {
840
- 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);
841
1391
  if (!commit) continue;
842
- if (skipped < this.skip) {
843
- skipped++;
844
- continue;
845
- }
846
- yield commit;
847
- 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 } : {}) };
848
1395
  }
849
1396
  }
850
1397
 
@@ -861,34 +1408,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
861
1408
  relevant: (n: number) => boolean,
862
1409
  parse: (n: number) => Promise<boolean>,
863
1410
  ): Promise<void> {
864
- let order = newlist;
865
- if (output.topo) {
866
- // sort_in_topological_order (REV_SORT_IN_GRAPH_ORDER: a LIFO of the ready commits)
867
- const indegree = new Map<number, number>();
868
- for (const n of newlist) indegree.set(n, 1);
869
- for (const n of newlist) {
870
- for (let k = 0, c = t.parentCount(n); k < c; k++) {
871
- const p = t.parent(n, k);
872
- const d = indegree.get(p);
873
- if (d) indegree.set(p, d + 1);
874
- }
875
- }
876
- const stack: number[] = [];
877
- for (const n of newlist) if (indegree.get(n) === 1) stack.push(n);
878
- stack.reverse();
879
- order = [];
880
- for (let n = stack.pop(); n !== undefined; n = stack.pop()) {
881
- for (let k = 0, c = t.parentCount(n); k < c; k++) {
882
- const p = t.parent(n, k);
883
- const d = indegree.get(p);
884
- if (!d) continue;
885
- indegree.set(p, d - 1);
886
- if (d - 1 === 1) stack.push(p);
887
- }
888
- indegree.set(n, 0);
889
- order.push(n);
890
- }
891
- }
1411
+ const order = newlist;
892
1412
  const firstParentOnly = this.firstParentOnly;
893
1413
  /** revision.c's one_relevant_parent */
894
1414
  const oneRelevantParent = (n: number): number | undefined => {
@@ -939,8 +1459,14 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
939
1459
  }
940
1460
  parents = ids;
941
1461
  }
942
- const { id, ...rest } = commit;
943
- 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
+ });
944
1470
  }
945
1471
  // graph.c's graph_is_interesting asks get_commit_action about a parent: one the walk
946
1472
  // never reached has no TREESAME or SHOWN flag, so only the filters can hide it (with
@@ -954,7 +1480,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
954
1480
  }
955
1481
 
956
1482
  /**
957
- * 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
958
1485
  * walk set up by this command (start points, ranges, paths, `-n`, `--skip`, filters), each
959
1486
  * commit in the format asked for, with the graph and the diffs asked for. See
960
1487
  * {@link LogOutputOptions}.
@@ -979,27 +1506,56 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
979
1506
  }
980
1507
 
981
1508
  private async printLog(options: LogOutputOptions): Promise<Uint8Array> {
1509
+ const reverse = !!options.reverse || this.reverse;
1510
+ await this.checkReflogWalkOptions(options);
982
1511
  // revision.c's setup_revisions: the graph cannot be reversed
983
- if (options.graph && options.reverse) {
1512
+ if (options.graph && reverse) {
984
1513
  throw new IncompatibleOptionsError(
985
1514
  ["--graph", "--reverse"],
986
1515
  "options '--graph' and '--reverse' cannot be used together",
987
1516
  );
988
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();
989
1525
  const host = this.outputHost(options);
990
1526
  const paths = [...this.paths];
991
1527
  // the pathspec as git holds it: the excluded paths as `:(exclude)` elements, `.` when
992
1528
  // every element excludes
993
1529
  const pathspec = [...paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
994
1530
  if (paths.length === 0 && this.excludePaths.length > 0) pathspec.push(".");
995
- const printer = new LogPrinter(host, options, {
996
- interesting: (id) => shownIds.has(id) || unwalkedShown.has(id),
997
- firstParentOnly: this.firstParentOnly,
998
- paths: pathspec,
999
- });
1000
- 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;
1001
1543
  const graph = !!options.graph;
1002
- 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;
1003
1559
  const maxCount = this.maxCount;
1004
1560
  const skip = this.skip;
1005
1561
  const simplifyHistory = this.simplifyHistory;
@@ -1009,7 +1565,10 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1009
1565
  const shownIds = new Set<ObjectId>();
1010
1566
  const unwalkedShown = new Set<ObjectId>();
1011
1567
  let entries: LogOutputEntry[];
1012
- 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) {
1013
1572
  this.outputWalk = { topo, rewrite: graph, entries: [] };
1014
1573
  for await (const _ of await this.call()) {
1015
1574
  // the output walk collects its commits
@@ -1019,23 +1578,64 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1019
1578
  this.outputWalk = undefined;
1020
1579
  for (const e of entries) shownIds.add(e.id);
1021
1580
  entries = entries.slice(skip);
1022
- 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));
1023
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();
1024
1616
  } else {
1025
- // --follow counts the commits shown, not those walked; --reverse the newest walked
1026
- if (follow && !options.reverse) this.maxCount = undefined;
1617
+ // --reverse: the newest commits walked, reversed, then shown
1027
1618
  entries = [];
1028
1619
  for await (const c of await this.call()) {
1029
- const { id, ...commit } = c;
1030
- 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
+ });
1031
1628
  }
1032
- if (follow) this.maxCount = maxCount;
1033
1629
  }
1034
1630
  this.simplifyHistory = simplifyHistory;
1035
- 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) {
1036
1636
  entries = entries.slice(0, Math.max(maxCount, 0));
1037
1637
  }
1038
- if (options.reverse) entries.reverse();
1638
+ if (reverse) entries.reverse();
1039
1639
  await printer.start();
1040
1640
  if (graph) {
1041
1641
  const parentsOf = new Map(entries.map((e) => [e.id, e.parents]));
@@ -1044,7 +1644,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1044
1644
  let count = 0;
1045
1645
  // -n 0: nothing is walked
1046
1646
  if (maxCount !== undefined && maxCount <= 0) entries = [];
1047
- const countShown = follow && maxCount !== undefined && !options.reverse;
1647
+ const countShown = countsShown && maxCount !== undefined && !reverse;
1048
1648
  for (let k = 0; k < entries.length; k++) {
1049
1649
  const e = entries[k] as LogOutputEntry;
1050
1650
  const lookahead = entries.slice(k + 1, k + 3).map((x) => x.id);
@@ -1055,6 +1655,245 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1055
1655
  return printer.result();
1056
1656
  }
1057
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
+
1058
1897
  /** What the log printer reads of the repository. */
1059
1898
  private outputHost(options: LogOutputOptions = {}): LogOutputHost {
1060
1899
  const config = RemoteConfigStore.from(this._workingCopy);
@@ -1101,6 +1940,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1101
1940
  }
1102
1941
  return short;
1103
1942
  },
1943
+ signature: (id) => this.signatureOf(id),
1944
+ signatureLines: (entry) => this.signatureLines(entry),
1104
1945
  rawCommit: async (id) => {
1105
1946
  // the replacement's content, as git's commit buffer is (core.useReplaceRefs)
1106
1947
  const replace = (await this.objectReplacements())?.replace;
@@ -1151,9 +1992,12 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1151
1992
  diff: async (entry, parent, formats, options) => {
1152
1993
  // the trees themselves: a full id names its object, so no revision is looked up
1153
1994
  const diff = new DiffCommand(this._workingCopy)
1154
- .setOldTree(parent ? await treeOf(parent) : EMPTY_TREE_ID)
1995
+ .setOldTree(parent ? await treeOf(parent) : this.objectFormat.emptyTreeId)
1155
1996
  .setNewTree(entry.commit.tree)
1997
+ // log's diffcore_rotate starts at the first path after a missing one
1998
+ .setRotateStrict(false)
1156
1999
  .shareReadsOf(this);
2000
+ if (this.colorSettings) diff.setColorSettings(this.colorSettings);
1157
2001
  diff.setOptions({
1158
2002
  ...this.diffOptions,
1159
2003
  ...(options.statWidth !== undefined
@@ -1165,13 +2009,116 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1165
2009
  const spec = [...this.paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
1166
2010
  if (spec.length > 0) diff.setPathspec(spec);
1167
2011
  }
1168
- 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;
1169
2015
  },
1170
2016
  combinedDiff: (entry, options) => this.combinedDiff(entry, options),
1171
2017
  };
1172
2018
  }
1173
2019
 
1174
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
+ }
1175
2122
 
1176
2123
  /** `log` stores no objects: its abbreviations read each loose fan-out directory once */
1177
2124
  protected override writesNoObjects(): boolean {
@@ -1185,6 +2132,81 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1185
2132
  return this;
1186
2133
  }
1187
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
+
1188
2210
  /** An object's content as stored (undefined when missing) */
1189
2211
  private async readObjectBytes(id: ObjectId): Promise<Uint8Array | undefined> {
1190
2212
  const objects = this._workingCopy.history?.objects;
@@ -1219,7 +2241,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1219
2241
  prefix = "",
1220
2242
  out = new Map<string, { mode: number; id: ObjectId }>(),
1221
2243
  ): Promise<Map<string, { mode: number; id: ObjectId }>> {
1222
- if (tree === EMPTY_TREE_ID) return out;
2244
+ if (tree === this.objectFormat.emptyTreeId) return out;
1223
2245
  for await (const entry of this.trees.loadTree(tree)) {
1224
2246
  const path = prefix ? `${prefix}/${entry.name}` : entry.name;
1225
2247
  if ((entry.mode & 0o170000) === 0o040000) await this.flatTree(entry.id, path, out);
@@ -1229,6 +2251,44 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1229
2251
  return out;
1230
2252
  }
1231
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
+
1232
2292
  /**
1233
2293
  * combine-diff.c's diff_tree_combined for a merge: the paths that differ from every
1234
2294
  * parent (within the pathspec), each as a combined diff of the trees.
@@ -1271,7 +2331,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1271
2331
  }
1272
2332
  const differs = (a?: { mode: number; id: ObjectId }, b?: { mode: number; id: ObjectId }) =>
1273
2333
  !a || !b ? a !== b : a.id !== b.id || a.mode !== b.mode;
1274
- const paths = [...all]
2334
+ let paths = [...all]
1275
2335
  .filter((path) => items.length === 0 || matchPathspec(items, path, 0) > 0)
1276
2336
  .filter((path) =>
1277
2337
  parents.every(
@@ -1288,6 +2348,10 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1288
2348
  }
1289
2349
  return ea.length - eb.length;
1290
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
+ ]);
1291
2355
  const sink = new ByteSink();
1292
2356
  const quote =
1293
2357
  parseGitBool(RemoteConfigStore.from(this._workingCopy).value("core.quotePath")) ?? true;
@@ -1308,7 +2372,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1308
2372
  if (paths.length === 0 || !options.patch) {
1309
2373
  return { paths: paths.length, names: names.bytes(), patch: sink.bytes() };
1310
2374
  }
1311
- const ids = new Set<string>([NULL_OBJECT_ID]);
2375
+ const ids = new Set<string>([this.objectFormat.nullId]);
1312
2376
  for (const path of paths) {
1313
2377
  const r = result.get(path);
1314
2378
  if (r) ids.add(r.id);
@@ -1346,22 +2410,32 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1346
2410
  const sides = [];
1347
2411
  for (let k = 0; k < parents.length; k++) {
1348
2412
  const e = sideOf(parents[k] as Map<string, { mode: number; id: ObjectId }>, k, path);
1349
- sides.push({ id: e?.id ?? NULL_OBJECT_ID, mode: e?.mode ?? 0, content: await read(e) });
2413
+ sides.push({
2414
+ id: e?.id ?? this.objectFormat.nullId,
2415
+ mode: e?.mode ?? 0,
2416
+ content: await read(e),
2417
+ });
1350
2418
  }
1351
2419
  writeCombinedDiff(
1352
2420
  sink,
1353
2421
  {
1354
2422
  path,
1355
2423
  parents: sides,
1356
- result: { id: r?.id ?? NULL_OBJECT_ID, mode: r?.mode ?? 0, content: await read(r) },
2424
+ result: {
2425
+ id: r?.id ?? this.objectFormat.nullId,
2426
+ mode: r?.mode ?? 0,
2427
+ content: await read(r),
2428
+ },
1357
2429
  },
1358
2430
  {
1359
2431
  ...xdiffOptions,
1360
2432
  dense,
1361
2433
  workingTreeFile: false,
1362
2434
  context: this.diffOptions.context ?? (Number.isFinite(context) ? context : 3),
1363
- abbreviate: (id) => id.slice(0, this.diffOptions.fullIndex ? 40 : (lengths.get(id) ?? 7)),
2435
+ abbreviate: (id) =>
2436
+ id.slice(0, this.diffOptions.fullIndex ? id.length : (lengths.get(id) ?? 7)),
1364
2437
  quotePath: quote,
2438
+ ...(this.colorSettings?.colors ? { colors: this.colorSettings.colors } : {}),
1365
2439
  },
1366
2440
  );
1367
2441
  }
@@ -1400,67 +2474,17 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1400
2474
 
1401
2475
  /** mailmap.c's read_mailmap: `.mailmap` (not in a bare repository), `mailmap.blob`, `mailmap.file` */
1402
2476
  private async loadMailmap(config: RemoteConfigStore): Promise<Mailmap> {
1403
- const map = new Mailmap();
1404
- const worktree = this.worktreeAccess;
1405
- const bare = parseGitBool(config.value("core.bare")) ?? !worktree;
1406
- if (!bare && worktree) {
1407
- try {
1408
- const entry = await worktree.getEntry(".mailmap");
1409
- if (entry && !entry.isDirectory && (entry.mode & 0o170000) !== 0o120000) {
1410
- const chunks: Uint8Array[] = [];
1411
- for await (const c of worktree.readContent(".mailmap")) chunks.push(c);
1412
- map.read(decodeGitPath(concatBytes(chunks)));
1413
- }
1414
- } catch {
1415
- // no .mailmap
1416
- }
1417
- }
1418
- const blobName = config.value("mailmap.blob") ?? (bare ? "HEAD:.mailmap" : undefined);
1419
- if (blobName) {
1420
- const id = await this.revisionResolver()
1421
- .resolve(blobName)
1422
- .catch(() => undefined);
1423
- const bytes = id ? await this.readBlob(id) : undefined;
1424
- if (bytes) map.read(decodeGitPath(bytes));
1425
- }
1426
- const file = config.value("mailmap.file");
1427
- if (file) {
1428
- const environment = hostEnvironmentOf(this._workingCopy);
1429
- const path = expandUserPath(file, environment);
1430
- const bytes = path !== undefined ? await this.readMailmapFile(path, environment) : undefined;
1431
- if (bytes) map.read(decodeGitPath(bytes));
1432
- }
1433
- return map;
1434
- }
1435
-
1436
- /**
1437
- * `mailmap.file`, read as git reads it: through the host (a relative path from its current
1438
- * directory). Without a host environment, a relative path is read from the worktree's top
1439
- * (where git usually runs), and an absolute one inside the worktree through it as well.
1440
- */
1441
- private async readMailmapFile(
1442
- path: string,
1443
- environment: ReturnType<typeof hostEnvironmentOf>,
1444
- ): Promise<Uint8Array | undefined> {
1445
- if (environment) return environment.readFile(path).catch(() => undefined);
1446
- const worktree = "worktree" in this._workingCopy ? this.worktreeAccess : undefined;
1447
- if (!worktree) return undefined;
1448
- let relative = path;
1449
- if (path.startsWith("/")) {
1450
- const top = (worktree as { hostPath?: string }).hostPath?.replace(/\/+$/, "");
1451
- if (!top || !path.startsWith(`${top}/`)) return undefined;
1452
- relative = path.slice(top.length + 1);
1453
- }
1454
- if (relative.split("/").includes("..")) return undefined;
1455
- try {
1456
- const entry = await worktree.getEntry(relative);
1457
- if (!entry || entry.isDirectory) return undefined;
1458
- const chunks: Uint8Array[] = [];
1459
- for await (const c of worktree.readContent(relative)) chunks.push(c);
1460
- return concatBytes(chunks);
1461
- } catch {
1462
- return undefined;
1463
- }
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
+ });
1464
2488
  }
1465
2489
 
1466
2490
  /**
@@ -1493,7 +2517,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1493
2517
  if (!obj && !failed) return undefined;
1494
2518
  if (obj?.bytes && obj.type === "commit") {
1495
2519
  try {
1496
- const header = parseGraphCommit(obj.bytes, id);
2520
+ const header = parseGraphCommit(obj.bytes, id, this.objectFormat);
1497
2521
  return { ...header, raw: obj.bytes };
1498
2522
  } catch {
1499
2523
  // read as the commit store reads it
@@ -1660,8 +2684,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1660
2684
  // git reads the parent's tree, then the commit's
1661
2685
  const da = a ? await this.requireTree(a) : EMPTY_TREE;
1662
2686
  const db = b ? await this.requireTree(b) : EMPTY_TREE;
1663
- const ca = new RawEntries(da);
1664
- const cb = new RawEntries(db);
2687
+ const ca = new RawEntries(da, this.objectFormat.rawLength);
2688
+ const cb = new RawEntries(db, this.objectFormat.rawLength);
1665
2689
  // entries are matched where they lie in the tree's bytes: no name is decoded; an `:(attr)`
1666
2690
  // element waits for the attributes of a path, then the entry is matched again
1667
2691
  const skip = (c: RawEntries): Promise<void> | undefined => {
@@ -1793,7 +2817,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1793
2817
  i: number,
1794
2818
  ): Promise<boolean> {
1795
2819
  // the whole tree (`.`, `:/`): a root commit compares with the empty tree, as in git
1796
- if (parts.length === 0) return (a ?? EMPTY_TREE_ID) !== (b ?? EMPTY_TREE_ID);
2820
+ const empty = this.objectFormat.emptyTreeId;
2821
+ if (parts.length === 0) return (a ?? empty) !== (b ?? empty);
1797
2822
  const name = parts[i] as Uint8Array;
1798
2823
  const ea = a ? await this.entryOf(a, name) : undefined;
1799
2824
  const eb = b ? await this.entryOf(b, name) : undefined;
@@ -1820,7 +2845,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1820
2845
  const raw = await this.rawTree(tree);
1821
2846
  if (raw === null) return this.trees.getEntry(tree, NAME_DECODER.decode(name));
1822
2847
  if (raw === undefined) throw new GitApiError(`unable to read tree (${tree})`);
1823
- return findRawEntry(raw, name);
2848
+ return findRawEntry(raw, name, this.objectFormat.rawLength);
1824
2849
  }
1825
2850
 
1826
2851
  /** The replace refs a walk's tree reads follow; undefined without any. */
@@ -1834,7 +2859,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1834
2859
  private async rawTree(tree: ObjectId): Promise<Uint8Array | undefined | null> {
1835
2860
  const id = this.treeReplacements ? replacementOf(this.treeReplacements, tree) : tree;
1836
2861
  // the empty tree, which a store need not hold
1837
- if (id === EMPTY_TREE_ID) return EMPTY_TREE;
2862
+ if (id === this.objectFormat.emptyTreeId) return EMPTY_TREE;
1838
2863
  const cached = this.rawTrees.get(id);
1839
2864
  if (cached) {
1840
2865
  this.rawTrees.delete(id);
@@ -2128,7 +3153,11 @@ function concatBytes(chunks: Uint8Array[]): Uint8Array {
2128
3153
  }
2129
3154
 
2130
3155
  /** The entry named `name` (raw bytes) in raw tree `d`: its id and mode, or undefined. */
2131
- function findRawEntry(d: Uint8Array, name: Uint8Array): { id: ObjectId; mode: number } | undefined {
3156
+ function findRawEntry(
3157
+ d: Uint8Array,
3158
+ name: Uint8Array,
3159
+ idLength: number,
3160
+ ): { id: ObjectId; mode: number } | undefined {
2132
3161
  let p = 0;
2133
3162
  const n = name.length;
2134
3163
  while (p < d.length) {
@@ -2141,9 +3170,9 @@ function findRawEntry(d: Uint8Array, name: Uint8Array): { id: ObjectId; mode: nu
2141
3170
  if (p - start === n) {
2142
3171
  let k = 0;
2143
3172
  while (k < n && d[start + k] === name[k]) k++;
2144
- if (k === n) return { id: bytesToHex(d.subarray(idAt, idAt + 20)), mode };
3173
+ if (k === n) return { id: bytesToHex(d.subarray(idAt, idAt + idLength)), mode };
2145
3174
  }
2146
- p = idAt + 20;
3175
+ p = idAt + idLength;
2147
3176
  }
2148
3177
  return undefined;
2149
3178
  }
@@ -2233,7 +3262,11 @@ class RawEntries {
2233
3262
  nameStart = 0;
2234
3263
  /** where the name ends (its NUL; the id follows) */
2235
3264
  nul = 0;
2236
- constructor(readonly d: Uint8Array) {}
3265
+ /** @param idLength raw id bytes per entry: 20 (SHA-1) or 32 (SHA-256) */
3266
+ constructor(
3267
+ readonly d: Uint8Array,
3268
+ readonly idLength = 20,
3269
+ ) {}
2237
3270
  get done(): boolean {
2238
3271
  return this.at >= this.d.length;
2239
3272
  }
@@ -2249,10 +3282,10 @@ class RawEntries {
2249
3282
  this.nul = p;
2250
3283
  }
2251
3284
  next(): void {
2252
- this.at = this.nul + 21;
3285
+ this.at = this.nul + 1 + this.idLength;
2253
3286
  }
2254
3287
  id(): ObjectId {
2255
- return bytesToHex(this.d.subarray(this.nul + 1, this.nul + 21));
3288
+ return bytesToHex(this.d.subarray(this.nul + 1, this.nul + 1 + this.idLength));
2256
3289
  }
2257
3290
  /** The base of the entries below this one (a directory): `base`, its name and "/". */
2258
3291
  below(base: Uint8Array): Uint8Array {
@@ -2264,7 +3297,7 @@ class RawEntries {
2264
3297
  return out;
2265
3298
  }
2266
3299
  sameId(other: RawEntries): boolean {
2267
- for (let k = 1; k <= 20; k++) {
3300
+ for (let k = 1; k <= this.idLength; k++) {
2268
3301
  if (this.d[this.nul + k] !== other.d[other.nul + k]) return false;
2269
3302
  }
2270
3303
  return true;
@@ -2292,3 +3325,21 @@ function configAlgorithm(v: string | undefined): XdiffAlgorithm | undefined {
2292
3325
  if (s === "default") return "myers";
2293
3326
  return s === "myers" || s === "minimal" || s === "patience" || s === "histogram" ? s : undefined;
2294
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
+ }