@statewalker/vcs-commands 0.7.0 → 0.9.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 (568) hide show
  1. package/dist/commands/add-command.d.ts +70 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/add-patch.d.ts +7 -0
  4. package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  6. package/dist/commands/am/am-command.d.ts +102 -1
  7. package/dist/commands/am/am-command.d.ts.map +1 -1
  8. package/dist/commands/am/index.d.ts +1 -0
  9. package/dist/commands/am/index.d.ts.map +1 -1
  10. package/dist/commands/am/mailsplit.d.ts +88 -0
  11. package/dist/commands/am/mailsplit.d.ts.map +1 -0
  12. package/dist/commands/apply/apply-command.d.ts +2 -0
  13. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  14. package/dist/commands/apply/apply-engine.d.ts.map +1 -1
  15. package/dist/commands/apply/apply-parse.d.ts +7 -0
  16. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  17. package/dist/commands/apply/index.d.ts +1 -1
  18. package/dist/commands/apply/index.d.ts.map +1 -1
  19. package/dist/commands/bisect/bisect-command.d.ts +2 -0
  20. package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
  21. package/dist/commands/blame-command.d.ts +303 -8
  22. package/dist/commands/blame-command.d.ts.map +1 -1
  23. package/dist/commands/blame-ignore.d.ts +48 -0
  24. package/dist/commands/blame-ignore.d.ts.map +1 -0
  25. package/dist/commands/branch-command.d.ts +148 -18
  26. package/dist/commands/branch-command.d.ts.map +1 -1
  27. package/dist/commands/branch-info-command.d.ts +55 -0
  28. package/dist/commands/branch-info-command.d.ts.map +1 -0
  29. package/dist/commands/branch-tracking.d.ts +106 -17
  30. package/dist/commands/branch-tracking.d.ts.map +1 -1
  31. package/dist/commands/branch-upstream-command.d.ts +83 -0
  32. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  33. package/dist/commands/check-mailmap-command.d.ts +49 -0
  34. package/dist/commands/check-mailmap-command.d.ts.map +1 -0
  35. package/dist/commands/checkout-command.d.ts +26 -3
  36. package/dist/commands/checkout-command.d.ts.map +1 -1
  37. package/dist/commands/checkout-paths.d.ts +4 -0
  38. package/dist/commands/checkout-paths.d.ts.map +1 -1
  39. package/dist/commands/cherry-command.d.ts +61 -0
  40. package/dist/commands/cherry-command.d.ts.map +1 -0
  41. package/dist/commands/cherry-pick-command.d.ts +82 -1
  42. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  43. package/dist/commands/clean-command.d.ts +44 -0
  44. package/dist/commands/clean-command.d.ts.map +1 -1
  45. package/dist/commands/clean-interactive.d.ts +56 -0
  46. package/dist/commands/clean-interactive.d.ts.map +1 -0
  47. package/dist/commands/clone-command.d.ts +116 -2
  48. package/dist/commands/clone-command.d.ts.map +1 -1
  49. package/dist/commands/commit-command.d.ts +239 -5
  50. package/dist/commands/commit-command.d.ts.map +1 -1
  51. package/dist/commands/commit-reuse.d.ts +33 -0
  52. package/dist/commands/commit-reuse.d.ts.map +1 -0
  53. package/dist/commands/config-command.d.ts +236 -0
  54. package/dist/commands/config-command.d.ts.map +1 -0
  55. package/dist/commands/config-value-types.d.ts +91 -0
  56. package/dist/commands/config-value-types.d.ts.map +1 -0
  57. package/dist/commands/core-config.d.ts +20 -0
  58. package/dist/commands/core-config.d.ts.map +1 -1
  59. package/dist/commands/describe-command.d.ts +71 -64
  60. package/dist/commands/describe-command.d.ts.map +1 -1
  61. package/dist/commands/diff-color-config.d.ts +73 -0
  62. package/dist/commands/diff-color-config.d.ts.map +1 -0
  63. package/dist/commands/diff-command.d.ts +369 -10
  64. package/dist/commands/diff-command.d.ts.map +1 -1
  65. package/dist/commands/fetch-command.d.ts +80 -0
  66. package/dist/commands/fetch-command.d.ts.map +1 -1
  67. package/dist/commands/fetch-multiple-command.d.ts +193 -0
  68. package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
  69. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  70. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  71. package/dist/commands/fork-point.d.ts +38 -0
  72. package/dist/commands/fork-point.d.ts.map +1 -0
  73. package/dist/commands/format-patch-command.d.ts +69 -3
  74. package/dist/commands/format-patch-command.d.ts.map +1 -1
  75. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  76. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  77. package/dist/commands/gc-command.d.ts +8 -0
  78. package/dist/commands/gc-command.d.ts.map +1 -1
  79. package/dist/commands/git-describe.d.ts +81 -4
  80. package/dist/commands/git-describe.d.ts.map +1 -1
  81. package/dist/commands/git-hooks.d.ts +50 -1
  82. package/dist/commands/git-hooks.d.ts.map +1 -1
  83. package/dist/commands/grep/grep-command.d.ts +210 -0
  84. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  85. package/dist/commands/grep/grep-engine.d.ts +218 -0
  86. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  87. package/dist/commands/grep/index.d.ts +3 -0
  88. package/dist/commands/grep/index.d.ts.map +1 -0
  89. package/dist/commands/index-adder.d.ts +13 -2
  90. package/dist/commands/index-adder.d.ts.map +1 -1
  91. package/dist/commands/index.d.ts +38 -0
  92. package/dist/commands/index.d.ts.map +1 -1
  93. package/dist/commands/index.js +5 -3
  94. package/dist/commands/init-command.d.ts +89 -0
  95. package/dist/commands/init-command.d.ts.map +1 -1
  96. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  97. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  98. package/dist/commands/line-log.d.ts +161 -0
  99. package/dist/commands/line-log.d.ts.map +1 -0
  100. package/dist/commands/local-transport.d.ts +36 -5
  101. package/dist/commands/local-transport.d.ts.map +1 -1
  102. package/dist/commands/log-command.d.ts +527 -13
  103. package/dist/commands/log-command.d.ts.map +1 -1
  104. package/dist/commands/log-graph.d.ts +30 -3
  105. package/dist/commands/log-graph.d.ts.map +1 -1
  106. package/dist/commands/log-output.d.ts +199 -6
  107. package/dist/commands/log-output.d.ts.map +1 -1
  108. package/dist/commands/ls-remote-command.d.ts +2 -0
  109. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  110. package/dist/commands/mailmap.d.ts +53 -0
  111. package/dist/commands/mailmap.d.ts.map +1 -1
  112. package/dist/commands/merge-base-command.d.ts +60 -0
  113. package/dist/commands/merge-base-command.d.ts.map +1 -0
  114. package/dist/commands/merge-bases.d.ts +23 -0
  115. package/dist/commands/merge-bases.d.ts.map +1 -1
  116. package/dist/commands/merge-command.d.ts +147 -10
  117. package/dist/commands/merge-command.d.ts.map +1 -1
  118. package/dist/commands/merge-drivers.d.ts +2 -0
  119. package/dist/commands/merge-drivers.d.ts.map +1 -1
  120. package/dist/commands/merge-strategy-options.d.ts +69 -0
  121. package/dist/commands/merge-strategy-options.d.ts.map +1 -0
  122. package/dist/commands/merge-support.d.ts +10 -0
  123. package/dist/commands/merge-support.d.ts.map +1 -1
  124. package/dist/commands/message-cleanup.d.ts +2 -0
  125. package/dist/commands/message-cleanup.d.ts.map +1 -1
  126. package/dist/commands/mv-command.d.ts +4 -0
  127. package/dist/commands/mv-command.d.ts.map +1 -1
  128. package/dist/commands/name-rev-command.d.ts +65 -0
  129. package/dist/commands/name-rev-command.d.ts.map +1 -0
  130. package/dist/commands/name-rev.d.ts +136 -0
  131. package/dist/commands/name-rev.d.ts.map +1 -0
  132. package/dist/commands/notes-command.d.ts.map +1 -1
  133. package/dist/commands/octopus-merge.d.ts +26 -1
  134. package/dist/commands/octopus-merge.d.ts.map +1 -1
  135. package/dist/commands/ort-merge.d.ts +16 -0
  136. package/dist/commands/ort-merge.d.ts.map +1 -1
  137. package/dist/commands/ort-recursive.d.ts.map +1 -1
  138. package/dist/commands/patch-id.d.ts +58 -0
  139. package/dist/commands/patch-id.d.ts.map +1 -1
  140. package/dist/commands/pathspec-file.d.ts +39 -0
  141. package/dist/commands/pathspec-file.d.ts.map +1 -0
  142. package/dist/commands/pathspec.d.ts +3 -0
  143. package/dist/commands/pathspec.d.ts.map +1 -1
  144. package/dist/commands/pretty-format.d.ts +43 -3
  145. package/dist/commands/pretty-format.d.ts.map +1 -1
  146. package/dist/commands/promisor-remote.d.ts.map +1 -1
  147. package/dist/commands/pull-command.d.ts +186 -32
  148. package/dist/commands/pull-command.d.ts.map +1 -1
  149. package/dist/commands/push-command.d.ts +225 -9
  150. package/dist/commands/push-command.d.ts.map +1 -1
  151. package/dist/commands/range-diff/index.d.ts +4 -0
  152. package/dist/commands/range-diff/index.d.ts.map +1 -0
  153. package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
  154. package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
  155. package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
  156. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
  157. package/dist/commands/range-diff/range-diff.d.ts +106 -0
  158. package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
  159. package/dist/commands/read-tree-command.d.ts +20 -0
  160. package/dist/commands/read-tree-command.d.ts.map +1 -1
  161. package/dist/commands/rebase-command.d.ts +189 -8
  162. package/dist/commands/rebase-command.d.ts.map +1 -1
  163. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  164. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  165. package/dist/commands/ref-filter/index.d.ts +8 -0
  166. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  167. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  168. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  169. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  170. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  171. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  172. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  173. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  174. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  175. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  176. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  177. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  178. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  179. package/dist/commands/reflog-command.d.ts +120 -0
  180. package/dist/commands/reflog-command.d.ts.map +1 -1
  181. package/dist/commands/reflog-walk.d.ts +72 -0
  182. package/dist/commands/reflog-walk.d.ts.map +1 -0
  183. package/dist/commands/remerge-diff.d.ts +59 -0
  184. package/dist/commands/remerge-diff.d.ts.map +1 -0
  185. package/dist/commands/remote-command.d.ts +179 -29
  186. package/dist/commands/remote-command.d.ts.map +1 -1
  187. package/dist/commands/remote-show-command.d.ts +204 -0
  188. package/dist/commands/remote-show-command.d.ts.map +1 -0
  189. package/dist/commands/remote-transport.d.ts +7 -1
  190. package/dist/commands/remote-transport.d.ts.map +1 -1
  191. package/dist/commands/reset-command.d.ts +21 -4
  192. package/dist/commands/reset-command.d.ts.map +1 -1
  193. package/dist/commands/restore-command.d.ts +9 -3
  194. package/dist/commands/restore-command.d.ts.map +1 -1
  195. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  196. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  197. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  198. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  199. package/dist/commands/rev-filter/index.d.ts +3 -0
  200. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  201. package/dist/commands/rev-list-command.d.ts +226 -2
  202. package/dist/commands/rev-list-command.d.ts.map +1 -1
  203. package/dist/commands/revert-command.d.ts +54 -1
  204. package/dist/commands/revert-command.d.ts.map +1 -1
  205. package/dist/commands/revision-range.d.ts +34 -1
  206. package/dist/commands/revision-range.d.ts.map +1 -1
  207. package/dist/commands/revision-resolver.d.ts +15 -0
  208. package/dist/commands/revision-resolver.d.ts.map +1 -1
  209. package/dist/commands/rm-command.d.ts +70 -2
  210. package/dist/commands/rm-command.d.ts.map +1 -1
  211. package/dist/commands/sequencer-pick.d.ts +186 -5
  212. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  213. package/dist/commands/sequencer-support.d.ts +12 -1
  214. package/dist/commands/sequencer-support.d.ts.map +1 -1
  215. package/dist/commands/serve-repository.d.ts +7 -0
  216. package/dist/commands/serve-repository.d.ts.map +1 -1
  217. package/dist/commands/shortlog-command.d.ts +109 -0
  218. package/dist/commands/shortlog-command.d.ts.map +1 -0
  219. package/dist/commands/shortlog.d.ts +151 -0
  220. package/dist/commands/shortlog.d.ts.map +1 -0
  221. package/dist/commands/show-command.d.ts +130 -0
  222. package/dist/commands/show-command.d.ts.map +1 -0
  223. package/dist/commands/show-commit.d.ts +11 -0
  224. package/dist/commands/show-commit.d.ts.map +1 -0
  225. package/dist/commands/signature-check.d.ts +164 -0
  226. package/dist/commands/signature-check.d.ts.map +1 -0
  227. package/dist/commands/signing.d.ts +160 -0
  228. package/dist/commands/signing.d.ts.map +1 -0
  229. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  230. package/dist/commands/sparse-index-view.d.ts +45 -0
  231. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  232. package/dist/commands/ssh-signer.d.ts +29 -0
  233. package/dist/commands/ssh-signer.d.ts.map +1 -0
  234. package/dist/commands/ssh-verifier.d.ts +42 -0
  235. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  236. package/dist/commands/stash-apply-command.d.ts +5 -0
  237. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  238. package/dist/commands/stash-branch-command.d.ts +34 -0
  239. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  240. package/dist/commands/stash-create-command.d.ts +17 -0
  241. package/dist/commands/stash-create-command.d.ts.map +1 -1
  242. package/dist/commands/stash-info.d.ts +93 -0
  243. package/dist/commands/stash-info.d.ts.map +1 -0
  244. package/dist/commands/stash-list-command.d.ts +16 -0
  245. package/dist/commands/stash-list-command.d.ts.map +1 -1
  246. package/dist/commands/stash-pop-command.d.ts +39 -0
  247. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  248. package/dist/commands/stash-show-command.d.ts +48 -0
  249. package/dist/commands/stash-show-command.d.ts.map +1 -0
  250. package/dist/commands/stash-store-command.d.ts +29 -0
  251. package/dist/commands/stash-store-command.d.ts.map +1 -0
  252. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  253. package/dist/commands/status-command.d.ts +31 -2
  254. package/dist/commands/status-command.d.ts.map +1 -1
  255. package/dist/commands/status-header.d.ts +5 -0
  256. package/dist/commands/status-header.d.ts.map +1 -1
  257. package/dist/commands/submodule-add-command.d.ts +89 -0
  258. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  259. package/dist/commands/submodule-auth.d.ts +90 -0
  260. package/dist/commands/submodule-auth.d.ts.map +1 -0
  261. package/dist/commands/submodule-commands.d.ts +463 -0
  262. package/dist/commands/submodule-commands.d.ts.map +1 -0
  263. package/dist/commands/submodule-fetch.d.ts +149 -0
  264. package/dist/commands/submodule-fetch.d.ts.map +1 -0
  265. package/dist/commands/submodule-model.d.ts +296 -0
  266. package/dist/commands/submodule-model.d.ts.map +1 -0
  267. package/dist/commands/submodule-unpack.d.ts +120 -0
  268. package/dist/commands/submodule-unpack.d.ts.map +1 -0
  269. package/dist/commands/submodule-update-command.d.ts +206 -0
  270. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  271. package/dist/commands/subtree-shift.d.ts +27 -0
  272. package/dist/commands/subtree-shift.d.ts.map +1 -0
  273. package/dist/commands/switch-command.d.ts +3 -0
  274. package/dist/commands/switch-command.d.ts.map +1 -1
  275. package/dist/commands/tag-command.d.ts +259 -10
  276. package/dist/commands/tag-command.d.ts.map +1 -1
  277. package/dist/commands/trailers.d.ts +218 -17
  278. package/dist/commands/trailers.d.ts.map +1 -1
  279. package/dist/commands/tree-restore.d.ts +7 -0
  280. package/dist/commands/tree-restore.d.ts.map +1 -1
  281. package/dist/commands/verify-command.d.ts +92 -0
  282. package/dist/commands/verify-command.d.ts.map +1 -0
  283. package/dist/commands/worktree-add-command.d.ts +79 -7
  284. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  285. package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
  286. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  287. package/dist/commands/worktree-path-rules.d.ts +66 -0
  288. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  289. package/dist/commands/worktree-remove-command.d.ts +10 -3
  290. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  291. package/dist/commands/worktree-repair-command.d.ts +15 -2
  292. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  293. package/dist/commands/worktree-support.d.ts +5 -0
  294. package/dist/commands/worktree-support.d.ts.map +1 -1
  295. package/dist/{commands-DIJ91NnD.js → commands-CNvli5bl.js} +49442 -54941
  296. package/dist/errors/checkout-errors.d.ts +19 -0
  297. package/dist/errors/checkout-errors.d.ts.map +1 -1
  298. package/dist/errors/command-errors.d.ts +25 -0
  299. package/dist/errors/command-errors.d.ts.map +1 -1
  300. package/dist/errors/index.js +85 -3
  301. package/dist/errors/ref-errors.d.ts +19 -0
  302. package/dist/errors/ref-errors.d.ts.map +1 -1
  303. package/dist/errors/worktree-errors.d.ts +6 -1
  304. package/dist/errors/worktree-errors.d.ts.map +1 -1
  305. package/dist/fsck-CPeDh9fh.js +5138 -0
  306. package/dist/git-command.d.ts +58 -2
  307. package/dist/git-command.d.ts.map +1 -1
  308. package/dist/git.d.ts +363 -1
  309. package/dist/git.d.ts.map +1 -1
  310. package/dist/guarded-transport-command.d.ts +82 -0
  311. package/dist/guarded-transport-command.d.ts.map +1 -0
  312. package/dist/index.d.ts +1 -0
  313. package/dist/index.d.ts.map +1 -1
  314. package/dist/index.js +6 -5
  315. package/dist/remote-config/index.d.ts +1 -1
  316. package/dist/remote-config/index.d.ts.map +1 -1
  317. package/dist/remote-config/remote-config-store.d.ts +55 -0
  318. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  319. package/dist/remote-transport-CCmBadm-.js +1606 -0
  320. package/dist/rename/detect-renames.d.ts +20 -0
  321. package/dist/rename/detect-renames.d.ts.map +1 -1
  322. package/dist/rename/diffcore-break.d.ts +51 -0
  323. package/dist/rename/diffcore-break.d.ts.map +1 -0
  324. package/dist/rename/index.d.ts +1 -0
  325. package/dist/rename/index.d.ts.map +1 -1
  326. package/dist/results/blame-format.d.ts +62 -1
  327. package/dist/results/blame-format.d.ts.map +1 -1
  328. package/dist/results/clone-result.d.ts +9 -0
  329. package/dist/results/clone-result.d.ts.map +1 -1
  330. package/dist/results/combined-diff.d.ts +3 -0
  331. package/dist/results/combined-diff.d.ts.map +1 -1
  332. package/dist/results/diff-check.d.ts +38 -0
  333. package/dist/results/diff-check.d.ts.map +1 -0
  334. package/dist/results/diff-color.d.ts +135 -0
  335. package/dist/results/diff-color.d.ts.map +1 -0
  336. package/dist/results/diff-dirstat.d.ts +36 -0
  337. package/dist/results/diff-dirstat.d.ts.map +1 -0
  338. package/dist/results/diff-entry.d.ts +10 -0
  339. package/dist/results/diff-entry.d.ts.map +1 -1
  340. package/dist/results/diff-formatter.d.ts.map +1 -1
  341. package/dist/results/diff-output.d.ts +103 -1
  342. package/dist/results/diff-output.d.ts.map +1 -1
  343. package/dist/results/diff-pickaxe.d.ts +67 -0
  344. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  345. package/dist/results/diff-words.d.ts +55 -0
  346. package/dist/results/diff-words.d.ts.map +1 -0
  347. package/dist/results/fetch-result.d.ts +12 -1
  348. package/dist/results/fetch-result.d.ts.map +1 -1
  349. package/dist/results/index.d.ts +6 -0
  350. package/dist/results/index.d.ts.map +1 -1
  351. package/dist/results/index.js +2 -2
  352. package/dist/results/init-result.d.ts +8 -1
  353. package/dist/results/init-result.d.ts.map +1 -1
  354. package/dist/results/line-range-hunks.d.ts +27 -0
  355. package/dist/results/line-range-hunks.d.ts.map +1 -0
  356. package/dist/results/merge-result.d.ts +8 -1
  357. package/dist/results/merge-result.d.ts.map +1 -1
  358. package/dist/results/pull-result.d.ts +11 -0
  359. package/dist/results/pull-result.d.ts.map +1 -1
  360. package/dist/results/push-result.d.ts +12 -0
  361. package/dist/results/push-result.d.ts.map +1 -1
  362. package/dist/results/rebase-result.d.ts +2 -0
  363. package/dist/results/rebase-result.d.ts.map +1 -1
  364. package/dist/results/stash-result.d.ts +6 -0
  365. package/dist/results/stash-result.d.ts.map +1 -1
  366. package/dist/results/status-result.d.ts +1 -1
  367. package/dist/results/status-result.d.ts.map +1 -1
  368. package/dist/results-BDuEgdLU.js +46847 -0
  369. package/dist/transport-command.d.ts +14 -0
  370. package/dist/transport-command.d.ts.map +1 -1
  371. package/dist/whitespace/index.d.ts +2 -0
  372. package/dist/whitespace/index.d.ts.map +1 -0
  373. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  374. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  375. package/package.json +12 -12
  376. package/src/commands/add-command.ts +293 -17
  377. package/src/commands/add-patch/add-patch.ts +8 -0
  378. package/src/commands/add-patch/patch-backend.ts +20 -2
  379. package/src/commands/am/am-command.ts +400 -46
  380. package/src/commands/am/index.ts +1 -0
  381. package/src/commands/am/mailsplit.ts +326 -0
  382. package/src/commands/apply/apply-command.ts +58 -15
  383. package/src/commands/apply/apply-engine.ts +1 -1
  384. package/src/commands/apply/apply-parse.ts +17 -8
  385. package/src/commands/apply/index.ts +8 -1
  386. package/src/commands/bisect/bisect-command.ts +18 -5
  387. package/src/commands/blame-command.ts +1450 -51
  388. package/src/commands/blame-ignore.ts +307 -0
  389. package/src/commands/branch-command.ts +528 -53
  390. package/src/commands/branch-info-command.ts +150 -0
  391. package/src/commands/branch-tracking.ts +335 -60
  392. package/src/commands/branch-upstream-command.ts +218 -0
  393. package/src/commands/check-mailmap-command.ts +129 -0
  394. package/src/commands/checkout-command.ts +166 -55
  395. package/src/commands/checkout-paths.ts +28 -0
  396. package/src/commands/cherry-command.ts +187 -0
  397. package/src/commands/cherry-pick-command.ts +185 -1
  398. package/src/commands/clean-command.ts +126 -15
  399. package/src/commands/clean-interactive.ts +522 -0
  400. package/src/commands/clone-command.ts +598 -45
  401. package/src/commands/commit-command.ts +925 -74
  402. package/src/commands/commit-reuse.ts +94 -0
  403. package/src/commands/config-command.ts +1256 -0
  404. package/src/commands/config-value-types.ts +358 -0
  405. package/src/commands/core-config.ts +40 -0
  406. package/src/commands/describe-command.ts +341 -254
  407. package/src/commands/diff-color-config.ts +274 -0
  408. package/src/commands/diff-command.ts +1619 -99
  409. package/src/commands/fetch-command.ts +495 -14
  410. package/src/commands/fetch-multiple-command.ts +665 -0
  411. package/src/commands/fmt-merge-msg-command.ts +715 -0
  412. package/src/commands/fork-point.ts +63 -0
  413. package/src/commands/format-patch-command.ts +496 -116
  414. package/src/commands/fsck/fetch-fsck.ts +172 -18
  415. package/src/commands/gc-command.ts +31 -1
  416. package/src/commands/git-describe.ts +460 -201
  417. package/src/commands/git-hooks.ts +123 -3
  418. package/src/commands/grep/grep-command.ts +1077 -0
  419. package/src/commands/grep/grep-engine.ts +1024 -0
  420. package/src/commands/grep/index.ts +2 -0
  421. package/src/commands/index-adder.ts +46 -7
  422. package/src/commands/index.ts +43 -0
  423. package/src/commands/init-command.ts +603 -49
  424. package/src/commands/interpret-trailers-command.ts +256 -0
  425. package/src/commands/line-log.ts +931 -0
  426. package/src/commands/local-transport.ts +109 -10
  427. package/src/commands/log-command.ts +2599 -326
  428. package/src/commands/log-graph.ts +129 -29
  429. package/src/commands/log-output.ts +449 -27
  430. package/src/commands/ls-remote-command.ts +5 -0
  431. package/src/commands/mailmap.ts +155 -0
  432. package/src/commands/merge-base-command.ts +170 -0
  433. package/src/commands/merge-bases.ts +63 -8
  434. package/src/commands/merge-command.ts +601 -95
  435. package/src/commands/merge-drivers.ts +3 -0
  436. package/src/commands/merge-strategy-options.ts +224 -0
  437. package/src/commands/merge-support.ts +115 -22
  438. package/src/commands/message-cleanup.ts +1 -1
  439. package/src/commands/mv-command.ts +6 -3
  440. package/src/commands/name-rev-command.ts +184 -0
  441. package/src/commands/name-rev.ts +762 -0
  442. package/src/commands/notes-command.ts +11 -1
  443. package/src/commands/octopus-merge.ts +35 -11
  444. package/src/commands/ort-merge.ts +41 -7
  445. package/src/commands/ort-recursive.ts +40 -2
  446. package/src/commands/patch-id.ts +109 -0
  447. package/src/commands/pathspec-file.ts +72 -0
  448. package/src/commands/pathspec.ts +14 -2
  449. package/src/commands/pretty-format.ts +103 -19
  450. package/src/commands/promisor-remote.ts +10 -1
  451. package/src/commands/pull-command.ts +734 -221
  452. package/src/commands/push-command.ts +1035 -68
  453. package/src/commands/range-diff/index.ts +3 -0
  454. package/src/commands/range-diff/linear-assignment.ts +203 -0
  455. package/src/commands/range-diff/range-diff-command.ts +433 -0
  456. package/src/commands/range-diff/range-diff.ts +617 -0
  457. package/src/commands/read-tree-command.ts +102 -4
  458. package/src/commands/rebase-command.ts +1074 -194
  459. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  460. package/src/commands/ref-filter/index.ts +7 -0
  461. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  462. package/src/commands/ref-filter/ref-filter.ts +651 -0
  463. package/src/commands/ref-filter/ref-format.ts +1070 -0
  464. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  465. package/src/commands/ref-filter/ref-quote.ts +69 -0
  466. package/src/commands/ref-filter/version-compare.ts +177 -0
  467. package/src/commands/reflog-command.ts +492 -2
  468. package/src/commands/reflog-walk.ts +234 -0
  469. package/src/commands/remerge-diff.ts +241 -0
  470. package/src/commands/remote-command.ts +537 -69
  471. package/src/commands/remote-show-command.ts +836 -0
  472. package/src/commands/remote-transport.ts +9 -1
  473. package/src/commands/reset-command.ts +114 -34
  474. package/src/commands/restore-command.ts +27 -41
  475. package/src/commands/rev-filter/commit-filter.ts +159 -0
  476. package/src/commands/rev-filter/commit-grep.ts +444 -0
  477. package/src/commands/rev-filter/index.ts +2 -0
  478. package/src/commands/rev-list-command.ts +578 -15
  479. package/src/commands/revert-command.ts +123 -1
  480. package/src/commands/revision-range.ts +207 -5
  481. package/src/commands/revision-resolver.ts +23 -8
  482. package/src/commands/rm-command.ts +282 -21
  483. package/src/commands/sequencer-pick.ts +818 -111
  484. package/src/commands/sequencer-support.ts +184 -4
  485. package/src/commands/serve-repository.ts +18 -3
  486. package/src/commands/shortlog-command.ts +354 -0
  487. package/src/commands/shortlog.ts +361 -0
  488. package/src/commands/show-command.ts +491 -0
  489. package/src/commands/show-commit.ts +24 -0
  490. package/src/commands/signature-check.ts +657 -0
  491. package/src/commands/signing.ts +385 -0
  492. package/src/commands/sparse-checkout-command.ts +2 -9
  493. package/src/commands/sparse-checkout-support.ts +2 -2
  494. package/src/commands/sparse-index-view.ts +135 -0
  495. package/src/commands/ssh-signer.ts +199 -0
  496. package/src/commands/ssh-verifier.ts +523 -0
  497. package/src/commands/stash-apply-command.ts +16 -4
  498. package/src/commands/stash-branch-command.ts +88 -0
  499. package/src/commands/stash-create-command.ts +28 -0
  500. package/src/commands/stash-info.ts +243 -0
  501. package/src/commands/stash-list-command.ts +33 -0
  502. package/src/commands/stash-pop-command.ts +83 -0
  503. package/src/commands/stash-show-command.ts +141 -0
  504. package/src/commands/stash-store-command.ts +82 -0
  505. package/src/commands/stash-working-tree.ts +2 -2
  506. package/src/commands/status-command.ts +120 -27
  507. package/src/commands/status-format.ts +1 -1
  508. package/src/commands/status-header.ts +41 -7
  509. package/src/commands/submodule-add-command.ts +509 -0
  510. package/src/commands/submodule-auth.ts +276 -0
  511. package/src/commands/submodule-commands.ts +1835 -0
  512. package/src/commands/submodule-fetch.ts +789 -0
  513. package/src/commands/submodule-model.ts +938 -0
  514. package/src/commands/submodule-unpack.ts +265 -0
  515. package/src/commands/submodule-update-command.ts +1126 -0
  516. package/src/commands/subtree-shift.ts +215 -0
  517. package/src/commands/switch-command.ts +12 -1
  518. package/src/commands/tag-command.ts +876 -64
  519. package/src/commands/trailers.ts +837 -100
  520. package/src/commands/tree-restore.ts +44 -11
  521. package/src/commands/verify-command.ts +235 -0
  522. package/src/commands/worktree-add-command.ts +268 -24
  523. package/src/commands/worktree-overwrite-checks.ts +5 -0
  524. package/src/commands/worktree-path-rules.ts +183 -0
  525. package/src/commands/worktree-remove-command.ts +39 -5
  526. package/src/commands/worktree-repair-command.ts +52 -5
  527. package/src/commands/worktree-support.ts +22 -1
  528. package/src/errors/checkout-errors.ts +29 -0
  529. package/src/errors/command-errors.ts +37 -1
  530. package/src/errors/ref-errors.ts +23 -0
  531. package/src/errors/worktree-errors.ts +8 -1
  532. package/src/git-command.ts +153 -2
  533. package/src/git.ts +550 -1
  534. package/src/guarded-transport-command.ts +171 -0
  535. package/src/index.ts +1 -0
  536. package/src/remote-config/index.ts +2 -0
  537. package/src/remote-config/remote-config-store.ts +101 -0
  538. package/src/rename/detect-renames.ts +42 -8
  539. package/src/rename/diffcore-break.ts +166 -0
  540. package/src/rename/index.ts +1 -0
  541. package/src/results/blame-format.ts +268 -43
  542. package/src/results/clone-result.ts +6 -0
  543. package/src/results/combined-diff.ts +38 -18
  544. package/src/results/diff-check.ts +185 -0
  545. package/src/results/diff-color.ts +868 -0
  546. package/src/results/diff-dirstat.ts +117 -0
  547. package/src/results/diff-entry.ts +12 -0
  548. package/src/results/diff-formatter.ts +1 -0
  549. package/src/results/diff-output.ts +322 -32
  550. package/src/results/diff-pickaxe.ts +304 -0
  551. package/src/results/diff-words.ts +395 -0
  552. package/src/results/fetch-result.ts +12 -1
  553. package/src/results/index.ts +6 -0
  554. package/src/results/init-result.ts +10 -1
  555. package/src/results/line-range-hunks.ts +126 -0
  556. package/src/results/merge-result.ts +9 -0
  557. package/src/results/pull-result.ts +7 -0
  558. package/src/results/push-result.ts +12 -0
  559. package/src/results/rebase-result.ts +3 -0
  560. package/src/results/stash-result.ts +7 -0
  561. package/src/results/status-result.ts +2 -2
  562. package/src/transport-command.ts +34 -3
  563. package/src/whitespace/index.ts +1 -0
  564. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  565. package/dist/commands/apply/whitespace.d.ts +0 -58
  566. package/dist/commands/apply/whitespace.d.ts.map +0 -1
  567. package/dist/git-command-BGiOJ8Zk.js +0 -7246
  568. package/dist/results-WVlBhVb1.js +0 -2935
@@ -1,6 +1,7 @@
1
1
  import type { Commit, ObjectId, PersonIdent } from "@statewalker/vcs-core";
2
2
  import { DEFAULT_BIG_FILE_THRESHOLD } from "@statewalker/vcs-core";
3
3
  import {
4
+ ByteLines,
4
5
  type InternedText,
5
6
  LineInterner,
6
7
  parseGitBool,
@@ -9,7 +10,11 @@ import {
9
10
  type XdiffAlgorithm,
10
11
  type XdiffOptions,
11
12
  xdiffHunks,
13
+ xdlHashRecord,
12
14
  } from "@statewalker/vcs-utils";
15
+ import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
16
+ import { computeObjectId } from "@statewalker/vcs-utils/pack";
17
+ import { expandUserPath } from "@statewalker/vcs-working-tree";
13
18
 
14
19
  import { RefNotFoundError } from "../errors/ref-errors.js";
15
20
  import { GitCommand } from "../git-command.js";
@@ -20,11 +25,26 @@ import {
20
25
  detectRenames,
21
26
  GIT_MAX_SCORE,
22
27
  } from "../rename/index.js";
28
+ import {
29
+ type Fingerprint,
30
+ guessLineBlames,
31
+ type LineBlame,
32
+ lineFingerprints,
33
+ } from "./blame-ignore.js";
34
+ import { parseGitColor } from "./config-value-types.js";
23
35
  import { abbrevLengths } from "./core-config.js";
36
+ import { localTimezoneOffset } from "./git-date.js";
37
+ import { hostEnvironmentOf } from "./git-ident.js";
38
+ import { type Mailmap, readMailmapFile, readRepositoryMailmap } from "./mailmap.js";
39
+ import { OperationState } from "./merge-support.js";
24
40
  import { canonicalObjectId } from "./object-id-input.js";
25
41
 
26
42
  /** Line bytes the interner holds before blame starts a new one (see `setInternerByteLimit`) */
27
43
  const DEFAULT_INTERNER_BYTE_LIMIT = 64 * 1024 * 1024;
44
+ /** Bytes of the files looked in for copies kept interned between commits */
45
+ const COPY_SOURCE_CACHE_BYTES = 16 * 1024 * 1024;
46
+ /** Bytes of line hashes of the files looked in for copies kept between commits */
47
+ const COPY_HASH_CACHE_BYTES = 32 * 1024 * 1024;
28
48
 
29
49
  /**
30
50
  * A single blame entry - represents authorship of one or more consecutive lines.
@@ -49,6 +69,16 @@ export interface BlameEntry {
49
69
  previous?: { commitId: ObjectId; path: string };
50
70
  /** A boundary commit (a root commit, unless `setShowRoot(true)`): `^` in git's output */
51
71
  boundary?: boolean;
72
+ /**
73
+ * Lines an ignored commit changed, blamed on the line of its parent they resemble (`?` in
74
+ * git's output and `ignored` in the porcelain ones under `blame.markIgnoredLines`)
75
+ */
76
+ ignored?: boolean;
77
+ /**
78
+ * Lines an ignored commit changed that resemble no line of its parent, so stay its own
79
+ * (`*` and `unblamable` under `blame.markUnblamableLines`)
80
+ */
81
+ unblamable?: boolean;
52
82
  }
53
83
 
54
84
  /**
@@ -85,8 +115,23 @@ export interface BlameResult {
85
115
  * line ranges asked for
86
116
  */
87
117
  entries: BlameEntry[];
88
- /** The blamed file's content at the start commit */
118
+ /** The blamed file's content at the start commit (`--reverse`: at the commit reversed from) */
89
119
  content?: Uint8Array;
120
+ /** Whether git's output marks ignored lines (`blame.markIgnoredLines`, `setMarkIgnoredLines`) */
121
+ markIgnoredLines?: boolean;
122
+ /**
123
+ * Whether git's output marks unblamable lines (`blame.markUnblamableLines`,
124
+ * `setMarkUnblamableLines`)
125
+ */
126
+ markUnblamableLines?: boolean;
127
+ /**
128
+ * The entries in the order blame found them, before sorting and coalescing: what
129
+ * `git blame --incremental` prints (`formatBlameIncremental`). Each entry's `boundary` is
130
+ * what git knew when it printed the entry.
131
+ */
132
+ incremental?: BlameEntry[];
133
+ /** The output settings of the repository's configuration (defaults of `formatBlame`) */
134
+ output?: BlameOutputConfig;
90
135
  /**
91
136
  * Get the blame entry for a specific line (1-based).
92
137
  *
@@ -137,8 +182,60 @@ export interface BlameResult {
137
182
  autoAbbrev?(): Promise<number>;
138
183
  }
139
184
 
185
+ /**
186
+ * The output settings `git blame` reads from the configuration (`git_blame_config`), which
187
+ * `formatBlame` takes as defaults of its options
188
+ */
189
+ export interface BlameOutputConfig {
190
+ /** `blame.date`: the date mode (`--date`), as written */
191
+ date?: string;
192
+ /** `blame.showEmail` (`-e`) */
193
+ showEmail?: boolean;
194
+ /** `blame.blankBoundary` (`-b`) */
195
+ blankBoundary?: boolean;
196
+ /** `blame.coloring=repeatedLines` (`--color-lines`) */
197
+ colorLines?: boolean;
198
+ /** `blame.coloring=highlightRecent` (`--color-by-age`) */
199
+ colorByAge?: boolean;
200
+ /** `color.blame.repeatedLines`: the escape sequence of the color (default cyan) */
201
+ repeatedLinesColor?: string;
202
+ /** `color.blame.highlightRecent`: `<color>,<date>,<color>,...` as written */
203
+ highlightRecent?: string;
204
+ /** Warnings git prints while reading these settings (invalid values it skips) */
205
+ warnings?: string[];
206
+ }
207
+
208
+ /**
209
+ * The buffer blamed instead of the file of the start commit (`setContents`): git's fake
210
+ * working-tree commit on top of the start commit
211
+ */
212
+ export interface BlameContentsOptions {
213
+ /**
214
+ * The `--contents` argument, named in the fake commit's summary (`-` reads "standard
215
+ * input", the default)
216
+ */
217
+ name?: string;
218
+ /**
219
+ * The working tree's file blamed as `git blame <path>` without a revision does: the commit
220
+ * is "Not Committed Yet" instead of "External file (--contents)"
221
+ */
222
+ workingTree?: boolean;
223
+ /** The fake commit's time in seconds (default now) */
224
+ time?: number;
225
+ /** Its zone, `+HHMM` (default the local zone at `time`) */
226
+ tzOffset?: string;
227
+ /**
228
+ * The file's mode, as git's `canon_mode` of the `--contents` file's stat or the working
229
+ * tree file's lstat (`120000` for a link, whose content is its target); default, as for
230
+ * standard input, the index entry's mode at the path, else `100644`
231
+ */
232
+ mode?: number;
233
+ }
234
+
140
235
  /** A version of the file in a commit (`struct blame_origin`) */
141
236
  interface Origin {
237
+ /** Creation order: stands for the pointer order git sorts suspects by (`compare_blame_suspect`) */
238
+ seq: number;
142
239
  commitId: ObjectId;
143
240
  path: string;
144
241
  blobId: ObjectId;
@@ -149,8 +246,12 @@ interface Origin {
149
246
  guilty: boolean;
150
247
  /** The next origin of the same commit */
151
248
  next: Origin | null;
249
+ /** The previous origin of the same commit (the list is doubly linked to move one in O(1)) */
250
+ prev: Origin | null;
152
251
  /** The blob's lines (split and hashed once), while the origin is compared */
153
252
  lines?: InternedText;
253
+ /** The lines' fingerprints, while an ignored commit's origin passes blame */
254
+ fingerprints?: Fingerprint[];
154
255
  }
155
256
 
156
257
  /** A run of lines (`struct blame_entry`), 0-based */
@@ -162,6 +263,10 @@ interface Entry {
162
263
  /** First line in the suspect's file */
163
264
  sLno: number;
164
265
  numLines: number;
266
+ /** Blamed on a parent of an ignored commit by resemblance */
267
+ ignored: boolean;
268
+ /** Changed by an ignored commit and like no line of its parent */
269
+ unblamable: boolean;
165
270
  }
166
271
 
167
272
  /** Something with a `next` link: a list head or an entry (`struct blame_entry **`) */
@@ -172,13 +277,46 @@ interface Slot {
172
277
  interface CommitState {
173
278
  commit: Commit;
174
279
  origins: Origin | null;
280
+ /** The origins by path (git's list is searched linearly; `-C -C -C` makes it long) */
281
+ originsByPath: Map<string, Origin>;
175
282
  uninteresting: boolean;
176
283
  }
177
284
 
178
285
  const S_IFMT = 0o170000;
179
286
  const TREE_MODE = 0o040000;
287
+ const GITLINK_MODE = 0o160000;
288
+ /** blame.h's `BLAME_DEFAULT_MOVE_SCORE` and `BLAME_DEFAULT_COPY_SCORE` */
289
+ const BLAME_DEFAULT_MOVE_SCORE = 20;
290
+ const BLAME_DEFAULT_COPY_SCORE = 40;
180
291
  const INT_MAX = Number.MAX_SAFE_INTEGER;
181
292
 
293
+ /** Whether any line hash is among `wanted` */
294
+ function sharesLine(hashes: Int32Array, wanted: Set<number>): boolean {
295
+ for (let i = 0; i < hashes.length; i++) if (wanted.has(hashes[i])) return true;
296
+ return false;
297
+ }
298
+
299
+ /** An origin moved to the front of its commit's list (`get_origin` finding it) */
300
+ function moveOriginToFront(st: CommitState, o: Origin): void {
301
+ if (!o.prev) return;
302
+ o.prev.next = o.next;
303
+ if (o.next) o.next.prev = o.prev;
304
+ o.prev = null;
305
+ o.next = st.origins;
306
+ if (st.origins) st.origins.prev = o;
307
+ st.origins = o;
308
+ }
309
+
310
+ /** An origin no entry refers to taken off its commit's list (`blame_origin_decref` freeing it) */
311
+ function unlinkOrigin(st: CommitState, o: Origin): void {
312
+ if (o.prev) o.prev.next = o.next;
313
+ else if (st.origins === o) st.origins = o.next;
314
+ if (o.next) o.next.prev = o.prev;
315
+ o.prev = null;
316
+ o.next = null;
317
+ if (st.originsByPath.get(o.path) === o) st.originsByPath.delete(o.path);
318
+ }
319
+
182
320
  /** `reverse_blame`: `head` reversed, ending in `tail` */
183
321
  function reverseBlame(head: Entry | null, tail: Entry | null): Entry | null {
184
322
  let h = head;
@@ -223,20 +361,136 @@ function splitBlameAt(e: Entry, len: number, suspect: Origin): Entry {
223
361
  lno: e.lno + len,
224
362
  sLno: e.sLno + len,
225
363
  numLines: e.numLines - len,
364
+ ignored: e.ignored,
365
+ unblamable: e.unblamable,
226
366
  };
227
367
  e.numLines = len;
228
368
  return n;
229
369
  }
230
370
 
231
- /** A priority queue of commits: newest committer date first, ties first in, first out */
371
+ /** One part of a split entry (the on-stack `struct blame_entry` of `split_overlap`) */
372
+ interface Part {
373
+ suspect: Origin | null;
374
+ lno: number;
375
+ sLno: number;
376
+ numLines: number;
377
+ ignored: boolean;
378
+ unblamable: boolean;
379
+ }
380
+
381
+ /** `struct blame_entry split[3]`: before the chunk, the chunk the parent takes, after it */
382
+ type Split = [Part, Part, Part];
383
+
384
+ const emptyPart = (e?: Entry): Part => ({
385
+ suspect: null,
386
+ lno: 0,
387
+ sLno: 0,
388
+ numLines: 0,
389
+ ignored: e?.ignored ?? false,
390
+ unblamable: e?.unblamable ?? false,
391
+ });
392
+ const emptySplit = (e?: Entry): Split => [emptyPart(e), emptyPart(e), emptyPart(e)];
393
+
394
+ /** A queue appended at its tail (`struct blame_entry ***`); the tail's `next` is set at the end */
395
+ interface Queue {
396
+ tail: Slot;
397
+ }
398
+
399
+ /** git's `split_overlap`: `e` cut where `[tlno, same)` (its suspect's lines) came from `parent` */
400
+ function splitOverlap(e: Entry, tlno: number, plno: number, same: number, parent: Origin): Split {
401
+ const split = emptySplit(e);
402
+ let chunkEnd: number;
403
+ if (e.sLno < tlno) {
404
+ // a part before the chunk, not blamed on the parent
405
+ split[0] = {
406
+ suspect: e.suspect,
407
+ lno: e.lno,
408
+ sLno: e.sLno,
409
+ numLines: tlno - e.sLno,
410
+ ignored: e.ignored,
411
+ unblamable: e.unblamable,
412
+ };
413
+ split[1].lno = e.lno + tlno - e.sLno;
414
+ split[1].sLno = plno;
415
+ } else {
416
+ split[1].lno = e.lno;
417
+ split[1].sLno = plno + (e.sLno - tlno);
418
+ }
419
+ if (same < e.sLno + e.numLines) {
420
+ // a part after the chunk, not blamed on the parent
421
+ split[2] = {
422
+ suspect: e.suspect,
423
+ lno: e.lno + (same - e.sLno),
424
+ sLno: same,
425
+ numLines: e.sLno + e.numLines - same,
426
+ ignored: e.ignored,
427
+ unblamable: e.unblamable,
428
+ };
429
+ chunkEnd = split[2].lno;
430
+ } else chunkEnd = e.lno + e.numLines;
431
+ split[1].numLines = chunkEnd - split[1].lno;
432
+ if (split[1].numLines >= 1) split[1].suspect = parent;
433
+ return split;
434
+ }
435
+
436
+ /** git's `add_blame_entry`: a new entry from `src` appended */
437
+ function addBlameEntry(queue: Queue, src: Part): void {
438
+ const e: Entry = {
439
+ next: null,
440
+ suspect: src.suspect as Origin,
441
+ lno: src.lno,
442
+ sLno: src.sLno,
443
+ numLines: src.numLines,
444
+ ignored: src.ignored,
445
+ unblamable: src.unblamable,
446
+ };
447
+ queue.tail.next = e;
448
+ queue.tail = e;
449
+ }
450
+
451
+ /** git's `dup_entry`: `dst` takes `src`'s place and is appended */
452
+ function dupEntry(queue: Queue, dst: Entry, src: Part): void {
453
+ dst.suspect = src.suspect as Origin;
454
+ dst.lno = src.lno;
455
+ dst.sLno = src.sLno;
456
+ dst.numLines = src.numLines;
457
+ dst.ignored = src.ignored;
458
+ dst.unblamable = src.unblamable;
459
+ queue.tail.next = dst;
460
+ queue.tail = dst;
461
+ }
462
+
463
+ /** git's `split_blame`: the parts of `e` queued to the parent's (`blamed`) and its own lists */
464
+ function splitBlame(blamed: Queue, unblamed: Queue, split: Split, e: Entry): void {
465
+ if (split[0].suspect && split[2].suspect) {
466
+ dupEntry(unblamed, e, split[0]);
467
+ addBlameEntry(unblamed, split[2]);
468
+ addBlameEntry(blamed, split[1]);
469
+ } else if (!split[0].suspect && !split[2].suspect) {
470
+ dupEntry(blamed, e, split[1]);
471
+ } else if (split[0].suspect) {
472
+ dupEntry(unblamed, e, split[0]);
473
+ addBlameEntry(blamed, split[1]);
474
+ } else {
475
+ dupEntry(blamed, e, split[1]);
476
+ addBlameEntry(unblamed, split[2]);
477
+ }
478
+ }
479
+
480
+ /**
481
+ * A priority queue of commits: newest committer date first (oldest first in reverse, as
482
+ * `compare_commits_by_reverse_commit_date`), ties first in, first out
483
+ */
232
484
  class CommitQueue {
233
485
  private heap: Array<{ id: ObjectId; date: number; ctr: number }> = [];
234
486
  private ctr = 0;
235
487
 
488
+ constructor(private readonly reverse = false) {}
489
+
236
490
  private less(i: number, j: number): boolean {
237
491
  const a = this.heap[i];
238
492
  const b = this.heap[j];
239
- if (a.date !== b.date) return a.date > b.date;
493
+ if (a.date !== b.date) return this.reverse ? a.date < b.date : a.date > b.date;
240
494
  return a.ctr < b.ctr;
241
495
  }
242
496
 
@@ -252,6 +506,16 @@ class CommitQueue {
252
506
  }
253
507
  }
254
508
 
509
+ /** The ids queued, in no particular order */
510
+ ids(): ObjectId[] {
511
+ return this.heap.map((e) => e.id);
512
+ }
513
+
514
+ /** The date of the commit `get` returns next */
515
+ peekDate(): number | undefined {
516
+ return this.heap[0]?.date;
517
+ }
518
+
255
519
  get(): ObjectId | undefined {
256
520
  const h = this.heap;
257
521
  if (h.length === 0) return undefined;
@@ -286,8 +550,14 @@ class CommitQueue {
286
550
  * are its own. A parent with the same blob takes all lines. Root commits are boundaries
287
551
  * unless `setShowRoot(true)` (`blame.showRoot`).
288
552
  *
289
- * Moves and copies across lines (`-M`, `-C`), `--reverse`, `--ignore-rev` and the mailmap
290
- * are not supported.
553
+ * Lines moved within the file (`-M`, `setDetectMoves`) and copied from other files (`-C` up
554
+ * to three times, `setDetectCopies`) are found as git's `find_move_in_parent` and
555
+ * `find_copy_in_parent` find them, and names and emails go through the mailmap
556
+ * (`setUseMailmap`). Ignored revisions (`setIgnoreRevs`, `setIgnoreRevsFiles`,
557
+ * `blame.ignoreRevsFile`) pass their changed lines to the parent lines they resemble, by
558
+ * git's fingerprint matching (`guess_line_blames`); `setReverse` blames each line of an old
559
+ * version on the last commit it existed in (`--reverse`), and `setFirstParent` follows
560
+ * first parents only.
291
561
  *
292
562
  * @example
293
563
  * ```typescript
@@ -314,8 +584,60 @@ export class BlameCommand extends GitCommand<BlameResult> {
314
584
  private lineRanges: Array<[number, number]> = [];
315
585
  private diffOptions: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> = {};
316
586
  private renameCountLastSpan?: boolean;
587
+ /** `-M`: look for lines moved within the file (`PICKAXE_BLAME_MOVE`) */
588
+ private detectMoves = false;
589
+ /** `-C` given this many times (`PICKAXE_BLAME_COPY`, `_HARDER`, `_HARDEST`) */
590
+ private copyLevel = 0;
591
+ private moveScore = BLAME_DEFAULT_MOVE_SCORE;
592
+ private copyScore = BLAME_DEFAULT_COPY_SCORE;
593
+ private useMailmap = true;
594
+ private ignoreRevs: string[] = [];
595
+ private ignoreRevsFiles: string[] = [];
596
+ private markIgnoredLines?: boolean;
597
+ private markUnblamableLines?: boolean;
598
+ /** `:(optional)` paths in the configuration (git 2.52+) */
599
+ private optionalPaths = true;
600
+ /** `--reverse`: the commit whose lines are followed forward */
601
+ private reverseFrom?: ObjectId;
602
+ private firstParent = false;
603
+ /** The buffer blamed instead of the start commit's file (`--contents`) */
604
+ private contents?: { content: Uint8Array } & BlameContentsOptions;
605
+ /** Commits older than this (committer time, seconds) are boundaries (`--since`) */
606
+ private since?: number;
607
+ /** Commits `--since` marked uninteresting before they were loaded */
608
+ private sinceUninteresting = new Set<ObjectId>();
609
+ /** Blobs that exist only here (the `--contents` buffer: git's `odb_pretend_object`) */
610
+ private pretend = new Map<ObjectId, Uint8Array>();
611
+ /** The entries in the order they were found guilty (`--incremental`) */
612
+ private guilty: Array<{ entry: Entry; origin: Origin; boundary: boolean }> = [];
613
+ /** The commits blamed lines pass to from each commit in reverse (`revs->children`) */
614
+ private children = new Map<ObjectId, ObjectId[]>();
615
+ /** The commits the reverse walk found uninteresting (boundaries) */
616
+ private reverseUninteresting = new Set<ObjectId>();
617
+ /** The commits whose changes are ignored (`sb->ignore_list`) */
618
+ private ignoreList = new Set<ObjectId>();
619
+
620
+ /** The blamed file at the start commit, its line starts and alphanumerics before each line */
621
+ private finalContent: Uint8Array = new Uint8Array(0);
622
+ private finalStarts: Int32Array = new Int32Array(1);
623
+ private finalAlnum: Int32Array = new Int32Array(1);
624
+ private originSeq = 0;
625
+ /** Files looked in for copies, interned, the most recently used last (`copySourceText`) */
626
+ private copySources = new Map<ObjectId, InternedText>();
627
+ private copySourceBytes = 0;
628
+ /** Line hashes of the files looked in for copies (null: over the big file threshold) */
629
+ private copyHashes = new Map<ObjectId, Int32Array | null>();
630
+ private copyHashBytes = 0;
631
+ private copyHashCacheBytes = COPY_HASH_CACHE_BYTES;
632
+ private copySourceCacheBytes = COPY_SOURCE_CACHE_BYTES;
633
+ /** The hash of each line of the final file (`lineHashesOf`) */
634
+ private finalHashes: Int32Array = new Int32Array(0);
317
635
 
318
636
  private states = new Map<ObjectId, CommitState>();
637
+ /** The `--contents` buffer's blob and mode */
638
+ private fakeEntry?: { id: ObjectId; mode: number };
639
+ /** The index's files with the `--contents` buffer at its path (the fake commit's "tree") */
640
+ private fakeFiles?: Map<string, { id: ObjectId; mode: number }>;
319
641
  /** Numbers the lines of every version compared, so each is split and hashed once */
320
642
  private interner?: LineInterner;
321
643
 
@@ -410,19 +732,149 @@ export class BlameCommand extends GitCommand<BlameResult> {
410
732
  }
411
733
 
412
734
  /**
413
- * Diff details that changed between git versions: `histogramRediff` (git 2.54+, default
414
- * true), `legacyMinimal` (git before 2.5x), and `renameCountLastSpan` (rename scores of
415
- * git 2.50+, default true)
735
+ * Find lines moved or copied within the file (`-M[<num>]`): lines a commit moved are blamed
736
+ * on the commit that wrote them. A block is taken when it has more than `score`
737
+ * alphanumeric characters (default 20; 0 keeps the default, as git's).
738
+ */
739
+ setDetectMoves(detect: boolean, score?: number): this {
740
+ this.checkCallable();
741
+ this.detectMoves = detect;
742
+ if (score) this.moveScore = score;
743
+ return this;
744
+ }
745
+
746
+ /**
747
+ * Find lines copied from other files (`-C[<num>]` given `level` times; any level also
748
+ * finds moves): 1 looks in the files the commit changed, 2 also in every file of the parent
749
+ * when the blamed file was created or renamed, 3 in every file of the parent always. A block
750
+ * is taken when it has more than `score` alphanumeric characters (default 40; 0 keeps the
751
+ * default).
752
+ */
753
+ setDetectCopies(level: number, score?: number): this {
754
+ this.checkCallable();
755
+ this.copyLevel = Math.max(0, Math.min(3, Math.floor(level)));
756
+ if (this.copyLevel > 0) this.detectMoves = true;
757
+ if (score) this.copyScore = score;
758
+ return this;
759
+ }
760
+
761
+ /**
762
+ * Map the names and emails of authors and committers through the mailmap (`.mailmap`,
763
+ * `mailmap.blob`, `mailmap.file`), as git blame always does (default true). The entries'
764
+ * commits then carry the mapped identities.
765
+ */
766
+ setUseMailmap(use: boolean): this {
767
+ this.checkCallable();
768
+ this.useMailmap = use;
769
+ return this;
770
+ }
771
+
772
+ /**
773
+ * Ignore the changes these revisions made (`--ignore-rev <rev>`, each peeled to a commit):
774
+ * their lines are blamed on the lines of their parents they resemble most (git's fuzzy
775
+ * matching), or stay theirs (unblamable) when none does.
776
+ *
777
+ * @throws Error `cannot find revision <rev> to ignore` when a name gives no commit
778
+ */
779
+ setIgnoreRevs(revs: string[]): this {
780
+ this.checkCallable();
781
+ this.ignoreRevs = [...revs];
782
+ return this;
783
+ }
784
+
785
+ /**
786
+ * Ignore the revisions listed in these files (`--ignore-revs-file <file>`, read after
787
+ * `blame.ignoreRevsFile`): full object ids, one per line, `#` comments; an empty name
788
+ * forgets the files before it. A relative path is read from the worktree's top.
789
+ *
790
+ * @throws Error `could not open object name list: <file>`, `invalid object name: <line>`
791
+ */
792
+ setIgnoreRevsFiles(files: string[]): this {
793
+ this.checkCallable();
794
+ this.ignoreRevsFiles = [...files];
795
+ return this;
796
+ }
797
+
798
+ /** Mark lines blamed through an ignored commit (`?`; default `blame.markIgnoredLines`) */
799
+ setMarkIgnoredLines(mark: boolean): this {
800
+ this.checkCallable();
801
+ this.markIgnoredLines = mark;
802
+ return this;
803
+ }
804
+
805
+ /** Mark lines an ignored commit keeps (`*`; default `blame.markUnblamableLines`) */
806
+ setMarkUnblamableLines(mark: boolean): this {
807
+ this.checkCallable();
808
+ this.markUnblamableLines = mark;
809
+ return this;
810
+ }
811
+
812
+ /**
813
+ * Blame in reverse (`--reverse <from>..<start>`): the lines of the file at `from`, each
814
+ * blamed on the last commit up to the start commit (default HEAD) it still existed in.
815
+ */
816
+ setReverse(from: ObjectId): this {
817
+ from = canonicalObjectId(from);
818
+ this.checkCallable();
819
+ this.reverseFrom = from;
820
+ return this;
821
+ }
822
+
823
+ /**
824
+ * Follow only first parents (`--first-parent`); with `setReverse`, the range must lie on
825
+ * the start commit's first-parent chain.
826
+ */
827
+ setFirstParent(first: boolean): this {
828
+ this.checkCallable();
829
+ this.firstParent = first;
830
+ return this;
831
+ }
832
+
833
+ /**
834
+ * Blame a buffer instead of the start commit's file (`--contents <file>`): git's fake
835
+ * commit on top of the start commit (default HEAD) and the commits `MERGE_HEAD` names,
836
+ * with null id, holding `content` at the blamed path of the index. Its lines are blamed on
837
+ * "External file (--contents)" where the parents' file differs (`workingTree`: "Not
838
+ * Committed Yet", as `git blame <path>` blames the working tree's file); a path only the
839
+ * index has is all its own, a rename staged in the index is followed. The content is taken
840
+ * as git stores it (no clean filters).
841
+ *
842
+ * @throws Error `--contents and --reverse do not blend well.` with `setReverse`, and
843
+ * `no such path '<path>' in HEAD` when neither a parent nor the index has the path
844
+ */
845
+ setContents(content: Uint8Array, options: BlameContentsOptions = {}): this {
846
+ this.checkCallable();
847
+ this.contents = { ...options, content };
848
+ return this;
849
+ }
850
+
851
+ /**
852
+ * Stop at commits older than `timestamp` (seconds, committer time; `--since`): they and
853
+ * their ancestors are boundaries, as git's `revs->max_age`
854
+ */
855
+ setSince(timestamp: number): this {
856
+ this.checkCallable();
857
+ this.since = timestamp;
858
+ return this;
859
+ }
860
+
861
+ /**
862
+ * Details that changed between git versions: `histogramRediff` (git 2.54+, default
863
+ * true), `legacyMinimal` (git before 2.5x), `renameCountLastSpan` (rename scores of
864
+ * git 2.50+, default true) and `optionalPaths` (a `blame.ignoreRevsFile` of
865
+ * `:(optional)<path>` naming a missing file is skipped: git 2.52+, default true)
416
866
  */
417
867
  setCompatibility(
418
868
  options: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> & {
419
869
  renameCountLastSpan?: boolean;
870
+ optionalPaths?: boolean;
420
871
  },
421
872
  ): this {
422
873
  this.checkCallable();
423
- const { renameCountLastSpan, ...diff } = options;
874
+ const { renameCountLastSpan, optionalPaths, ...diff } = options;
424
875
  this.diffOptions = { ...this.diffOptions, ...diff };
425
876
  if (renameCountLastSpan !== undefined) this.renameCountLastSpan = renameCountLastSpan;
877
+ if (optionalPaths !== undefined) this.optionalPaths = optionalPaths;
426
878
  return this;
427
879
  }
428
880
 
@@ -456,6 +908,20 @@ export class BlameCommand extends GitCommand<BlameResult> {
456
908
  return this;
457
909
  }
458
910
 
911
+ /**
912
+ * Set how many bytes the caches of `-C` keep between commits (default 32 MiB of line hashes
913
+ * of the files looked in, 16 MiB of their contents): a file not kept is read again for the
914
+ * next commit, as git reads it. The output does not change.
915
+ *
916
+ * @param bytes Size in bytes
917
+ */
918
+ setCopyCacheByteLimit(bytes: number): this {
919
+ this.checkCallable();
920
+ this.copyHashCacheBytes = bytes;
921
+ this.copySourceCacheBytes = bytes;
922
+ return this;
923
+ }
924
+
459
925
  /**
460
926
  * Execute the blame command.
461
927
  *
@@ -472,27 +938,40 @@ export class BlameCommand extends GitCommand<BlameResult> {
472
938
  this.algorithm ??= algorithmValue(config.value("diff.algorithm")) ?? "myers";
473
939
  this.indentHeuristic ??= boolValue(config.value("diff.indentHeuristic")) ?? true;
474
940
  this.showRoot ??= boolValue(config.value("blame.showRoot")) ?? false;
941
+ this.markIgnoredLines ??= boolValue(config.value("blame.markIgnoredLines")) ?? false;
942
+ this.markUnblamableLines ??= boolValue(config.value("blame.markUnblamableLines")) ?? false;
943
+ await this.buildIgnoreList(config);
475
944
 
945
+ if (this.contents && this.reverseFrom !== undefined) {
946
+ throw new Error("--contents and --reverse do not blend well.");
947
+ }
476
948
  let startId = this.startCommit;
477
949
  if (!startId) {
478
950
  const head = await this.refsStore.resolve("HEAD");
479
951
  if (!head?.objectId) {
480
- throw new Error("No HEAD commit found");
952
+ if (this.contents) throw new Error("no such ref: HEAD");
953
+ throw new Error(this.reverseFrom ? "No commit to dig up from?" : "No HEAD commit found");
481
954
  }
482
955
  startId = head.objectId;
483
956
  }
957
+ if (this.reverseFrom !== undefined) {
958
+ // --reverse <from>..<start>: the lines of <from>, followed forward to <start>
959
+ await this.prepareReverse(this.reverseFrom, startId);
960
+ startId = this.reverseFrom;
961
+ }
484
962
 
485
963
  const resultPath = this.filePath;
964
+ if (this.contents) startId = await this.fakeWorkingTreeCommit(startId, resultPath);
486
965
  const start = await this.state(startId);
487
966
  if (!start) {
488
967
  throw new RefNotFoundError(`Cannot find commit: ${startId}`);
489
968
  }
490
- const entry = await this.lookup(start.commit.tree, resultPath);
969
+ const entry = this.contents ? this.fakeEntry : await this.lookup(start.commit.tree, resultPath);
491
970
  if (!entry) {
492
971
  throw new Error(`File not found: ${resultPath}`);
493
972
  }
494
- const size = await this.blobs.size(entry.id);
495
- if (size > this.bigFileThreshold) {
973
+ const size = await this.blobSize(entry.id);
974
+ if (!this.contents && size > this.bigFileThreshold) {
496
975
  throw new Error(
497
976
  `${resultPath} is ${size} bytes, larger than bigFileThreshold (${this.bigFileThreshold})`,
498
977
  );
@@ -503,18 +982,27 @@ export class BlameCommand extends GitCommand<BlameResult> {
503
982
  const content = await this.readBlob(entry.id);
504
983
  finalOrigin.lines = this.lineInterner().text(content);
505
984
  const lineCount = countLines(content);
985
+ if (this.detectMoves || this.copyLevel > 0) this.prepareLines(content, lineCount);
506
986
 
507
987
  // the initial entries: the whole file, or the -L ranges (sorted and merged)
508
988
  const ranges = this.ranges(lineCount);
509
989
  let head: Entry | null = null;
510
990
  for (let i = ranges.length - 1; i >= 0; i--) {
511
991
  const [s, e] = ranges[i];
512
- head = { next: head, suspect: finalOrigin, lno: s, sLno: s, numLines: e - s };
992
+ head = {
993
+ next: head,
994
+ suspect: finalOrigin,
995
+ lno: s,
996
+ sLno: s,
997
+ numLines: e - s,
998
+ ignored: false,
999
+ unblamable: false,
1000
+ };
513
1001
  }
514
1002
  const final: Slot = { next: null };
515
1003
  if (head) {
516
1004
  finalOrigin.suspects = head;
517
- const queue = new CommitQueue();
1005
+ const queue = new CommitQueue(this.reverseFrom !== undefined);
518
1006
  queue.put(startId, start.commit.committer.timestamp);
519
1007
  await this.assignBlame(queue, final);
520
1008
  }
@@ -530,19 +1018,37 @@ export class BlameCommand extends GitCommand<BlameResult> {
530
1018
  last &&
531
1019
  last.suspect === e.suspect &&
532
1020
  last.sLno + last.numLines === e.sLno &&
533
- last.lno + last.numLines === e.lno
1021
+ last.lno + last.numLines === e.lno &&
1022
+ last.ignored === e.ignored &&
1023
+ last.unblamable === e.unblamable
534
1024
  ) {
535
1025
  last.numLines += e.numLines;
536
1026
  } else coalesced.push({ ...e });
537
1027
  }
538
1028
 
1029
+ const mailmap = this.useMailmap ? await this.loadMailmap() : undefined;
1030
+ const mapped = new Map<ObjectId, Commit>();
1031
+ const commitOf = (st: CommitState, id: ObjectId): Commit => {
1032
+ if (!mailmap || mailmap.empty) return st.commit;
1033
+ let c = mapped.get(id);
1034
+ if (!c) {
1035
+ const author = mapIdent(mailmap, st.commit.author);
1036
+ const committer = mapIdent(mailmap, st.commit.committer);
1037
+ c =
1038
+ author === st.commit.author && committer === st.commit.committer
1039
+ ? st.commit
1040
+ : { ...st.commit, author, committer };
1041
+ mapped.set(id, c);
1042
+ }
1043
+ return c;
1044
+ };
539
1045
  const entries: BlameEntry[] = [];
540
1046
  for (const e of coalesced) {
541
1047
  const st = this.states.get(e.suspect.commitId);
542
1048
  if (!st) continue;
543
1049
  const prev = e.suspect.previous;
544
1050
  entries.push({
545
- commit: st.commit,
1051
+ commit: commitOf(st, e.suspect.commitId),
546
1052
  commitId: e.suspect.commitId,
547
1053
  sourcePath: e.suspect.path,
548
1054
  sourceStart: e.sLno + 1,
@@ -550,9 +1056,30 @@ export class BlameCommand extends GitCommand<BlameResult> {
550
1056
  lineCount: e.numLines,
551
1057
  ...(prev ? { previous: { commitId: prev.commitId, path: prev.path } } : {}),
552
1058
  boundary: st.uninteresting,
1059
+ ...(e.ignored ? { ignored: true } : {}),
1060
+ ...(e.unblamable ? { unblamable: true } : {}),
553
1061
  });
554
1062
  }
555
1063
  const result = createBlameResult(resultPath, lineCount, entries, content);
1064
+ result.incremental = [];
1065
+ for (const g of this.guilty) {
1066
+ const st = this.states.get(g.origin.commitId);
1067
+ if (!st) continue;
1068
+ const prev = g.origin.previous;
1069
+ result.incremental.push({
1070
+ commit: commitOf(st, g.origin.commitId),
1071
+ commitId: g.origin.commitId,
1072
+ sourcePath: g.origin.path,
1073
+ sourceStart: g.entry.sLno + 1,
1074
+ resultStart: g.entry.lno + 1,
1075
+ lineCount: g.entry.numLines,
1076
+ ...(prev ? { previous: { commitId: prev.commitId, path: prev.path } } : {}),
1077
+ boundary: g.boundary,
1078
+ });
1079
+ }
1080
+ result.output = blameOutputConfig(config);
1081
+ result.markIgnoredLines = this.markIgnoredLines;
1082
+ result.markUnblamableLines = this.markUnblamableLines;
556
1083
  const workingCopy = this.workingCopy;
557
1084
  result.autoAbbrev = async () => {
558
1085
  const lengths = await abbrevLengths(
@@ -564,6 +1091,187 @@ export class BlameCommand extends GitCommand<BlameResult> {
564
1091
  return result;
565
1092
  }
566
1093
 
1094
+ /** The commits a commit's lines pass to: its parents, or its children in reverse */
1095
+ private scapegoats(st: CommitState, commitId: ObjectId): ObjectId[] {
1096
+ if (this.reverseFrom !== undefined) return this.children.get(commitId) ?? [];
1097
+ return this.firstParent ? st.commit.parents.slice(0, 1) : st.commit.parents;
1098
+ }
1099
+
1100
+ /**
1101
+ * builtin/blame.c's `build_ignorelist`: `blame.ignoreRevsFile` (sorted, as git inserts
1102
+ * them), the files given, then the revisions given
1103
+ */
1104
+ private async buildIgnoreList(config: RemoteConfigStore): Promise<void> {
1105
+ const environment = hostEnvironmentOf(this.workingCopy);
1106
+ const worktree = this.worktreeAccess;
1107
+ const configured = new Set<string>();
1108
+ for (let value of config.values("blame.ignoreRevsFile")) {
1109
+ const optional = this.optionalPaths && value.startsWith(":(optional)");
1110
+ if (optional) value = value.slice(":(optional)".length);
1111
+ const path = expandUserPath(value, environment);
1112
+ if (path === undefined) throw new Error(`failed to expand user dir in: '${value}'`);
1113
+ if (optional && path && !(await readMailmapFile(path, environment, worktree))) continue;
1114
+ configured.add(path);
1115
+ }
1116
+ // string_list_insert keeps the configured names sorted (strcmp) and unique
1117
+ const files = [...[...configured].sort(compareBytes), ...this.ignoreRevsFiles];
1118
+ const resolver = this.revisionResolver();
1119
+ const peelToCommit = async (id: ObjectId) => {
1120
+ const peeled = await resolver.peelTags(id).catch(() => undefined);
1121
+ return peeled?.type === "commit" ? peeled.id : undefined;
1122
+ };
1123
+ const hexLength = this.objectFormat.hexLength;
1124
+ const list = this.ignoreList;
1125
+ for (const file of files) {
1126
+ if (file === "") {
1127
+ list.clear();
1128
+ continue;
1129
+ }
1130
+ const bytes = await readMailmapFile(file, environment, worktree);
1131
+ if (!bytes) throw new Error(`could not open object name list: ${file}`);
1132
+ const text = decodeGitPath(bytes);
1133
+ const lines = text.split("\n");
1134
+ if (lines[lines.length - 1] === "") lines.pop();
1135
+ for (const raw of lines) {
1136
+ const hash = raw.indexOf("#");
1137
+ const name = (hash < 0 ? raw : raw.slice(0, hash)).replace(/^[ \t\n\r]+|[ \t\n\r]+$/g, "");
1138
+ if (!name) continue;
1139
+ if (name.length !== hexLength || !/^[0-9a-fA-F]+$/.test(name)) {
1140
+ throw new Error(`invalid object name: ${name}`);
1141
+ }
1142
+ const id = await peelToCommit(name.toLowerCase());
1143
+ if (id) list.add(id);
1144
+ }
1145
+ }
1146
+ for (const rev of this.ignoreRevs) {
1147
+ const resolved = await resolver.resolve(rev).catch(() => undefined);
1148
+ const id = resolved ? await peelToCommit(resolved) : undefined;
1149
+ if (!id) throw new Error(`cannot find revision ${rev} to ignore`);
1150
+ list.add(id);
1151
+ }
1152
+ }
1153
+
1154
+ /**
1155
+ * The children each commit passes its lines to in `--reverse` (git's `--children` walk of
1156
+ * `<from>..<start>`: `limit_list` then `set_children`, or the first-parent chain)
1157
+ */
1158
+ private async prepareReverse(from: ObjectId, to: ObjectId): Promise<void> {
1159
+ this.reverseUninteresting.add(from);
1160
+ const children = this.children;
1161
+ if (this.firstParent) {
1162
+ let c = to;
1163
+ for (;;) {
1164
+ const st = await this.state(c);
1165
+ if (!st) throw new RefNotFoundError(`Cannot find commit: ${c}`);
1166
+ if (c === from || st.commit.parents.length === 0) break;
1167
+ const parent = st.commit.parents[0];
1168
+ children.set(parent, [c]);
1169
+ c = parent;
1170
+ }
1171
+ if (c !== from) {
1172
+ throw new Error("--reverse --first-parent together require range along first-parent chain");
1173
+ }
1174
+ return;
1175
+ }
1176
+ const UNINTERESTING = 1;
1177
+ const SEEN = 2;
1178
+ const ADDED = 4;
1179
+ const flags = new Map<ObjectId, number>();
1180
+ const flag = (id: ObjectId) => flags.get(id) ?? 0;
1181
+ const set = (id: ObjectId, f: number) => flags.set(id, flag(id) | f);
1182
+ const parentsOf = (id: ObjectId) => this.states.get(id)?.commit.parents ?? [];
1183
+ const dateOf = (id: ObjectId) => this.states.get(id)?.commit.committer.timestamp ?? 0;
1184
+ const parse = async (id: ObjectId) => (await this.state(id)) !== undefined;
1185
+ // mark_parents_uninteresting: through the commits already parsed
1186
+ const markParentsUninteresting = (id: ObjectId) => {
1187
+ const pending = [...parentsOf(id)];
1188
+ while (pending.length > 0) {
1189
+ const p = pending.pop() as ObjectId;
1190
+ if (flag(p) & UNINTERESTING) continue;
1191
+ set(p, UNINTERESTING);
1192
+ if (this.states.has(p)) pending.push(...parentsOf(p));
1193
+ }
1194
+ };
1195
+ // prepare_revision_walk: the pending commits (<from> first), each once, by date
1196
+ const starts: Array<{ id: ObjectId; uninteresting: boolean }> = [
1197
+ { id: from, uninteresting: true },
1198
+ { id: to, uninteresting: false },
1199
+ ];
1200
+ const queue = new CommitQueue();
1201
+ const initial: ObjectId[] = [];
1202
+ for (const s of starts) {
1203
+ if (!(await parse(s.id))) throw new RefNotFoundError(`Cannot find commit: ${s.id}`);
1204
+ if (s.uninteresting) {
1205
+ set(s.id, UNINTERESTING);
1206
+ markParentsUninteresting(s.id);
1207
+ }
1208
+ if (flag(s.id) & SEEN) continue;
1209
+ set(s.id, SEEN);
1210
+ initial.push(s.id);
1211
+ }
1212
+ initial
1213
+ .map((id, i) => ({ id, i }))
1214
+ .sort((a, b) => dateOf(b.id) - dateOf(a.id) || a.i - b.i)
1215
+ .forEach((e) => {
1216
+ queue.put(e.id, dateOf(e.id));
1217
+ });
1218
+ const everybodyUninteresting = () => queue.ids().every((id) => flag(id) & UNINTERESTING);
1219
+ const newlist: ObjectId[] = [];
1220
+ let slop = 5;
1221
+ let date = Number.POSITIVE_INFINITY;
1222
+ for (let id = queue.get(); id !== undefined; id = queue.get()) {
1223
+ // process_parents
1224
+ if (!(flag(id) & ADDED)) {
1225
+ set(id, ADDED);
1226
+ if (flag(id) & UNINTERESTING) {
1227
+ for (const p of parentsOf(id)) {
1228
+ set(p, UNINTERESTING);
1229
+ if (!(await parse(p))) continue;
1230
+ markParentsUninteresting(p);
1231
+ if (flag(p) & SEEN) continue;
1232
+ set(p, SEEN);
1233
+ queue.put(p, dateOf(p));
1234
+ }
1235
+ } else {
1236
+ for (const p of parentsOf(id)) {
1237
+ if (!(await parse(p))) throw new RefNotFoundError(`Cannot find commit: ${p}`);
1238
+ if (!(flag(p) & SEEN)) {
1239
+ set(p, SEEN);
1240
+ queue.put(p, dateOf(p));
1241
+ }
1242
+ }
1243
+ }
1244
+ }
1245
+ if (flag(id) & UNINTERESTING) {
1246
+ markParentsUninteresting(id);
1247
+ // still_interesting
1248
+ const next = queue.peekDate();
1249
+ if (next === undefined) break;
1250
+ if (date <= next || !everybodyUninteresting()) slop = 5;
1251
+ else slop--;
1252
+ if (slop) continue;
1253
+ break;
1254
+ }
1255
+ date = dateOf(id);
1256
+ newlist.push(id);
1257
+ }
1258
+ // set_children: each child prepended to its parents' lists
1259
+ for (const c of newlist) {
1260
+ for (const p of parentsOf(c)) {
1261
+ const list = children.get(p);
1262
+ if (list) list.unshift(c);
1263
+ else children.set(p, [c]);
1264
+ }
1265
+ }
1266
+ for (const [id, f] of flags) {
1267
+ if (f & UNINTERESTING) {
1268
+ this.reverseUninteresting.add(id);
1269
+ const st = this.states.get(id);
1270
+ if (st) st.uninteresting = true;
1271
+ }
1272
+ }
1273
+ }
1274
+
567
1275
  /** The -L ranges as 0-based half-open ranges, sorted and merged; the whole file otherwise */
568
1276
  private ranges(lineCount: number): Array<[number, number]> {
569
1277
  if (this.lineRanges.length === 0) return lineCount > 0 ? [[0, lineCount]] : [];
@@ -600,13 +1308,30 @@ export class BlameCommand extends GitCommand<BlameResult> {
600
1308
  commitId = queue.get();
601
1309
  continue;
602
1310
  }
603
- if (!st.uninteresting) await this.passBlame(suspect, queue);
1311
+ if (
1312
+ this.reverseFrom !== undefined ||
1313
+ (!st.uninteresting &&
1314
+ !(this.since !== undefined && st.commit.committer.timestamp < this.since))
1315
+ ) {
1316
+ await this.passBlame(suspect, queue);
1317
+ } else {
1318
+ st.uninteresting = true;
1319
+ this.markParentsUninteresting(st);
1320
+ }
604
1321
  // treat root commit as boundary
605
1322
  if (st.commit.parents.length === 0 && !this.showRoot) st.uninteresting = true;
606
1323
  // take responsibility for the remaining entries
607
1324
  let ent = suspect.suspects;
608
1325
  if (ent) {
609
1326
  suspect.guilty = true;
1327
+ // found_guilty_entry: what --incremental prints, in this order
1328
+ for (let e: Entry | null = ent; e; e = e.next) {
1329
+ this.guilty.push({
1330
+ entry: { ...e, next: null },
1331
+ origin: suspect,
1332
+ boundary: st.uninteresting,
1333
+ });
1334
+ }
610
1335
  while (ent.next) ent = ent.next;
611
1336
  ent.next = final.next;
612
1337
  final.next = suspect.suspects;
@@ -615,14 +1340,183 @@ export class BlameCommand extends GitCommand<BlameResult> {
615
1340
  }
616
1341
  }
617
1342
 
618
- /** git's `pass_blame` (without -M/-C) */
1343
+ /**
1344
+ * revision.c's `mark_parents_uninteresting`: the parents marked, and the parents of those
1345
+ * already loaded (parsed) recursively
1346
+ */
1347
+ private markParentsUninteresting(st: CommitState): void {
1348
+ const pending = [...st.commit.parents];
1349
+ while (pending.length > 0) {
1350
+ const id = pending.pop() as ObjectId;
1351
+ const parent = this.states.get(id);
1352
+ if (!parent) {
1353
+ this.sinceUninteresting.add(id);
1354
+ continue;
1355
+ }
1356
+ if (parent.uninteresting) continue;
1357
+ parent.uninteresting = true;
1358
+ pending.push(...parent.commit.parents);
1359
+ }
1360
+ }
1361
+
1362
+ /**
1363
+ * blame.c's `fake_working_tree_commit`: a commit with the null id on top of `parentId`
1364
+ * (and the commits MERGE_HEAD names, `append_merge_parents`) whose file at `path` is the
1365
+ * `--contents` buffer; its id is returned
1366
+ */
1367
+ private async fakeWorkingTreeCommit(parentId: ObjectId, path: string): Promise<ObjectId> {
1368
+ const contents = this.contents as { content: Uint8Array } & BlameContentsOptions;
1369
+ const parent = await this.state(parentId);
1370
+ if (!parent) throw new Error(`no such commit ${parentId}`);
1371
+ const parents = [parentId];
1372
+ // append_parent: lookup_commit_reference, an annotated tag peeled to its commit
1373
+ const resolver = this.revisionResolver();
1374
+ for (const id of await this.mergeHeadParents()) {
1375
+ const peeled = await resolver.peelTags(id).catch(() => undefined);
1376
+ if (peeled?.type !== "commit" || !(await this.state(peeled.id))) {
1377
+ throw new Error(`no such commit ${id}`);
1378
+ }
1379
+ parents.push(peeled.id);
1380
+ }
1381
+ const index = await this.indexEntries();
1382
+ // verify_working_tree_path: a blob of a parent, else any stage of the index
1383
+ let known = false;
1384
+ for (const id of parents) {
1385
+ const st = this.states.get(id);
1386
+ const entry = st && (await this.lookup(st.commit.tree, path));
1387
+ if (entry && (entry.mode & S_IFMT) !== GITLINK_MODE) {
1388
+ known = true;
1389
+ break;
1390
+ }
1391
+ }
1392
+ if (!known && !index.some((e) => e.path === path)) {
1393
+ throw new Error(`no such path '${path}' in HEAD`);
1394
+ }
1395
+ const time = contents.time ?? Math.floor(Date.now() / 1000);
1396
+ const tzOffset = contents.tzOffset ?? localTimezoneOffset(time);
1397
+ const ident = contents.workingTree
1398
+ ? { name: "Not Committed Yet", email: "not.committed.yet", timestamp: time, tzOffset }
1399
+ : { name: "External file (--contents)", email: "external.file", timestamp: time, tzOffset };
1400
+ const from = contents.workingTree
1401
+ ? path
1402
+ : contents.name === undefined || contents.name === "-"
1403
+ ? "standard input"
1404
+ : contents.name;
1405
+ const id = this.objectFormat.nullId;
1406
+ const blobId = await computeObjectId("blob", contents.content, this.objectFormat);
1407
+ this.pretend.set(blobId, contents.content);
1408
+ // without a mode (standard input): the index's stage-0 entry's, else a regular file's
1409
+ const staged = index.find((e) => e.path === path && e.stage === 0);
1410
+ const mode = contents.mode ?? staged?.mode ?? 0o100644;
1411
+ this.fakeEntry = { id: blobId, mode };
1412
+ // the index with the path replaced: what git diffs the parents against (do_diff_cache)
1413
+ const files = new Map<string, { id: ObjectId; mode: number }>();
1414
+ for (const e of index) {
1415
+ if (e.stage === 0 && (e.mode & S_IFMT) !== GITLINK_MODE) {
1416
+ files.set(e.path, { id: e.objectId, mode: e.mode });
1417
+ }
1418
+ }
1419
+ files.set(path, { id: blobId, mode });
1420
+ this.fakeFiles = files;
1421
+ this.states.set(id, {
1422
+ commit: {
1423
+ // the parent's tree stands for the index where a tree is read (`-C`)
1424
+ tree: parent.commit.tree,
1425
+ parents,
1426
+ author: ident,
1427
+ committer: ident,
1428
+ message: `Version of ${path} from ${from}\n`,
1429
+ },
1430
+ origins: null,
1431
+ originsByPath: new Map(),
1432
+ uninteresting: false,
1433
+ });
1434
+ return id;
1435
+ }
1436
+
1437
+ /** The commits `.git/MERGE_HEAD` names, one per line (`append_merge_parents`) */
1438
+ private async mergeHeadParents(): Promise<ObjectId[]> {
1439
+ let text: string | undefined;
1440
+ try {
1441
+ text = await new OperationState(this.workingCopy.checkout, this.refsStore).read("MERGE_HEAD");
1442
+ } catch {
1443
+ return [];
1444
+ }
1445
+ const out: ObjectId[] = [];
1446
+ // strbuf_getwholeline_fd: only lines ending in a newline (a last one without is dropped)
1447
+ const lines = (text ?? "").split(/(?<=\n)/).filter((l) => l.endsWith("\n"));
1448
+ for (const line of lines) {
1449
+ // get_oid_hex: the line's first digits, the rest ignored; an empty line is refused
1450
+ const hex = line.slice(0, this.objectFormat.hexLength).toLowerCase();
1451
+ if (!this.isFullObjectId(hex)) {
1452
+ throw new Error(`unknown line in '.git/MERGE_HEAD': ${line}`);
1453
+ }
1454
+ out.push(hex);
1455
+ }
1456
+ return out;
1457
+ }
1458
+
1459
+ /** Every entry of the index, none without one (a bare repository) */
1460
+ private async indexEntries(): Promise<
1461
+ Array<{
1462
+ path: string;
1463
+ mode: number;
1464
+ objectId: ObjectId;
1465
+ stage: number;
1466
+ }>
1467
+ > {
1468
+ try {
1469
+ const staging = this.staging;
1470
+ if (await staging.isOutdated()) await staging.read();
1471
+ const out = [];
1472
+ for await (const e of staging.entries()) {
1473
+ out.push({ path: e.path, mode: e.mode, objectId: e.objectId, stage: e.stage });
1474
+ }
1475
+ return out;
1476
+ } catch {
1477
+ return [];
1478
+ }
1479
+ }
1480
+
1481
+ /** git's `pass_blame` */
619
1482
  private async passBlame(origin: Origin, queue: CommitQueue): Promise<void> {
620
1483
  const st = this.states.get(origin.commitId);
621
1484
  if (!st) return;
622
- const parents = st.commit.parents;
1485
+ const parents = this.scapegoats(st, origin.commitId);
623
1486
  const n = parents.length;
624
- if (n === 0) return;
625
1487
  const sgOrigin: Array<Origin | undefined> = new Array(n).fill(undefined);
1488
+ const blames: Slot = { next: null };
1489
+ const blamed: Queue = { tail: blames };
1490
+ const toosmall: Slot = { next: null };
1491
+ await this.passBlameSteps(origin, parents, sgOrigin, blamed, toosmall, queue);
1492
+ blamed.tail.next = null;
1493
+ this.distributeBlame(blames.next, queue);
1494
+ // the entries too small to look for are the origin's again (unsorted, as git leaves them)
1495
+ if (toosmall.next) {
1496
+ let tail = toosmall.next;
1497
+ while (tail.next) tail = tail.next;
1498
+ tail.next = origin.suspects;
1499
+ origin.suspects = toosmall.next;
1500
+ }
1501
+ for (const porigin of sgOrigin) if (porigin && !porigin.suspects) porigin.lines = undefined;
1502
+ origin.lines = undefined;
1503
+ origin.fingerprints = undefined;
1504
+ }
1505
+
1506
+ /**
1507
+ * The steps of `pass_blame` before its `finish`: the parents' versions found and compared,
1508
+ * then moves and copies looked for; returning is git's `goto finish`
1509
+ */
1510
+ private async passBlameSteps(
1511
+ origin: Origin,
1512
+ parents: ObjectId[],
1513
+ sgOrigin: Array<Origin | undefined>,
1514
+ blamed: Queue,
1515
+ toosmall: Slot,
1516
+ queue: CommitQueue,
1517
+ ): Promise<void> {
1518
+ const n = parents.length;
1519
+ if (n === 0) return;
626
1520
  for (let pass = 0; pass < (this.followRenames ? 2 : 1); pass++) {
627
1521
  for (let i = 0; i < n; i++) {
628
1522
  if (sgOrigin[i]) continue;
@@ -651,9 +1545,387 @@ export class BlameCommand extends GitCommand<BlameResult> {
651
1545
  if (!porigin) continue;
652
1546
  if (!origin.previous) origin.previous = porigin;
653
1547
  await this.passBlameToParent(origin, porigin, queue);
654
- if (!origin.suspects) break;
1548
+ if (!origin.suspects) return;
655
1549
  }
656
- origin.lines = undefined;
1550
+ // pass the remaining suspects of an ignored commit to its parents
1551
+ if (this.ignoreList.has(origin.commitId)) {
1552
+ for (let i = 0; i < n; i++) {
1553
+ const porigin = sgOrigin[i];
1554
+ if (!porigin) continue;
1555
+ await this.passBlameToParent(origin, porigin, queue, true);
1556
+ if (!origin.suspects) return;
1557
+ }
1558
+ }
1559
+ // optionally find moves in the parents' files
1560
+ if (this.detectMoves) {
1561
+ this.filterSuspects(toosmall, origin, this.moveScore);
1562
+ if (origin.suspects) {
1563
+ for (let i = 0; i < n; i++) {
1564
+ const porigin = sgOrigin[i];
1565
+ if (!porigin) continue;
1566
+ await this.findMoveInParent(blamed, toosmall, origin, porigin);
1567
+ if (!origin.suspects) break;
1568
+ }
1569
+ }
1570
+ }
1571
+ // optionally find copies from the parents' files
1572
+ if (this.copyLevel > 0) {
1573
+ if (this.copyScore > this.moveScore) {
1574
+ this.filterSuspects(toosmall, origin, this.copyScore);
1575
+ } else if (this.copyScore < this.moveScore) {
1576
+ origin.suspects = blameMerge(origin.suspects, toosmall.next);
1577
+ toosmall.next = null;
1578
+ this.filterSuspects(toosmall, origin, this.copyScore);
1579
+ }
1580
+ if (!origin.suspects) return;
1581
+ for (let i = 0; i < n; i++) {
1582
+ await this.findCopyInParent(blamed, toosmall, origin, parents[i], sgOrigin[i]);
1583
+ if (!origin.suspects) return;
1584
+ }
1585
+ }
1586
+ }
1587
+
1588
+ /** `filter_small` of the origin's suspects into `toosmall` */
1589
+ private filterSuspects(toosmall: Slot, origin: Origin, scoreMin: number): void {
1590
+ const src: Slot = { next: origin.suspects };
1591
+ this.filterSmall(toosmall, src, scoreMin);
1592
+ origin.suspects = src.next;
1593
+ }
1594
+
1595
+ /**
1596
+ * git's `filter_small`: the entries of `source` scoring at most `scoreMin` moved to the
1597
+ * front of the list after `small`; returns the link before the old head of that list
1598
+ */
1599
+ private filterSmall(small: Slot, source: Slot, scoreMin: number): Slot {
1600
+ let p = source.next;
1601
+ const oldsmall = small.next;
1602
+ let sm = small;
1603
+ let src = source;
1604
+ while (p) {
1605
+ if (this.entryScore(p.lno, p.numLines) <= scoreMin) {
1606
+ sm.next = p;
1607
+ sm = p;
1608
+ } else {
1609
+ src.next = p;
1610
+ src = p;
1611
+ }
1612
+ p = p.next;
1613
+ }
1614
+ sm.next = oldsmall;
1615
+ src.next = null;
1616
+ return sm;
1617
+ }
1618
+
1619
+ /** git's `blame_entry_score`: one more than the alphanumerics of the lines in the final file */
1620
+ private entryScore(lno: number, numLines: number): number {
1621
+ return 1 + this.finalAlnum[lno + numLines] - this.finalAlnum[lno];
1622
+ }
1623
+
1624
+ /** git's `prepare_lines`, and the alphanumerics before each line for `entryScore` */
1625
+ private prepareLines(content: Uint8Array, lineCount: number): void {
1626
+ const starts = new Int32Array(lineCount + 1);
1627
+ const alnum = new Int32Array(lineCount + 1);
1628
+ let line = 0;
1629
+ let count = 0;
1630
+ for (let i = 0; i < content.length; i++) {
1631
+ const c = content[i];
1632
+ if ((c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a)) {
1633
+ count++;
1634
+ } else if (c === 0x0a && ++line < lineCount) {
1635
+ starts[line] = i + 1;
1636
+ alnum[line] = count;
1637
+ }
1638
+ }
1639
+ starts[lineCount] = content.length;
1640
+ alnum[lineCount] = count;
1641
+ this.finalContent = content;
1642
+ this.finalStarts = starts;
1643
+ this.finalAlnum = alnum;
1644
+ if (this.copyLevel > 0) this.finalHashes = this.lineHashesOf(content);
1645
+ }
1646
+
1647
+ /** git's `copy_split_if_better`: `potential` kept in `best` when it scores no lower */
1648
+ private copySplitIfBetter(best: Split, potential: Split): void {
1649
+ if (!potential[1].suspect) return;
1650
+ if (
1651
+ best[1].suspect &&
1652
+ this.entryScore(potential[1].lno, potential[1].numLines) <
1653
+ this.entryScore(best[1].lno, best[1].numLines)
1654
+ ) {
1655
+ return;
1656
+ }
1657
+ best[0] = potential[0];
1658
+ best[1] = potential[1];
1659
+ best[2] = potential[2];
1660
+ }
1661
+
1662
+ /**
1663
+ * git's `find_copy_in_blob`: the best run of `ent`'s lines (in the final file) that the
1664
+ * parent's file has, as a split of `ent`
1665
+ */
1666
+ private findCopyInBlob(ent: Entry, parent: Origin, file: { text: InternedText }): Split {
1667
+ const split = emptySplit();
1668
+ const interner = this.lineInterner();
1669
+ if (file.text.interner !== interner) file.text = interner.text(file.text.content);
1670
+ const slice = this.finalContent.subarray(
1671
+ this.finalStarts[ent.lno],
1672
+ this.finalStarts[ent.lno + ent.numLines],
1673
+ );
1674
+ const hunks = xdiffHunks(file.text, slice, this.xdiffOptions(interner));
1675
+ let tlno = 0;
1676
+ let plno = 0;
1677
+ const handleSplit = (same: number) => {
1678
+ if (ent.numLines <= tlno || tlno >= same) return;
1679
+ const potential = splitOverlap(ent, tlno + ent.sLno, plno, same + ent.sLno, parent);
1680
+ this.copySplitIfBetter(split, potential);
1681
+ };
1682
+ for (const h of hunks) {
1683
+ handleSplit(h.i2);
1684
+ plno = h.i1 + h.chg1;
1685
+ tlno = h.i2 + h.chg2;
1686
+ }
1687
+ // the rest, if any, matches the parent
1688
+ handleSplit(ent.numLines);
1689
+ return split;
1690
+ }
1691
+
1692
+ /** git's `find_move_in_parent`: lines the target is suspected for found in the parent's file */
1693
+ private async findMoveInParent(
1694
+ blamed: Queue,
1695
+ toosmallHead: Slot,
1696
+ target: Origin,
1697
+ parent: Origin,
1698
+ ): Promise<void> {
1699
+ let unblamed = target.suspects;
1700
+ if (!unblamed) return;
1701
+ const file = { text: await this.originContent(parent) };
1702
+ let toosmall = toosmallHead;
1703
+ let leftover: Entry | null = null;
1704
+ do {
1705
+ const head: Slot = { next: null };
1706
+ const rest: Queue = { tail: head };
1707
+ let next: Entry | null;
1708
+ for (let e: Entry | null = unblamed; e; e = next) {
1709
+ next = e.next;
1710
+ const split = this.findCopyInBlob(e, parent, file);
1711
+ if (split[1].suspect && this.moveScore < this.entryScore(split[1].lno, split[1].numLines)) {
1712
+ splitBlame(blamed, rest, split, e);
1713
+ } else {
1714
+ e.next = leftover;
1715
+ leftover = e;
1716
+ }
1717
+ }
1718
+ rest.tail.next = null;
1719
+ toosmall = this.filterSmall(toosmall, head, this.moveScore);
1720
+ unblamed = head.next;
1721
+ } while (unblamed);
1722
+ parent.lines = file.text;
1723
+ target.suspects = reverseBlame(leftover, null);
1724
+ }
1725
+
1726
+ /**
1727
+ * git's `find_copy_in_parent`: lines the target is suspected for found in other files of
1728
+ * the parent (`porigin`, the parent's version of the file, was tried by the move pass)
1729
+ */
1730
+ private async findCopyInParent(
1731
+ blamed: Queue,
1732
+ toosmallHead: Slot,
1733
+ target: Origin,
1734
+ parentId: ObjectId,
1735
+ porigin: Origin | undefined,
1736
+ ): Promise<void> {
1737
+ let unblamed = target.suspects;
1738
+ if (!unblamed) return;
1739
+ const parent = await this.state(parentId);
1740
+ const child = this.states.get(target.commitId);
1741
+ if (!parent || !child) return;
1742
+ const harder =
1743
+ this.copyLevel >= 3 || (this.copyLevel >= 2 && (!porigin || target.path !== porigin.path));
1744
+ const candidates = await this.copyCandidates(parent.commit.tree, child.commit.tree, harder);
1745
+ /** Origins this call made: git frees those no split took (`blame_origin_decref`) */
1746
+ const created = new Set<Origin>();
1747
+ const taken = new Set<Origin>();
1748
+ let toosmall = toosmallHead;
1749
+ let leftover: Entry | null = null;
1750
+ do {
1751
+ const head: Slot = { next: null };
1752
+ const rest: Queue = { tail: head };
1753
+ const list: Array<{ ent: Entry; split: Split }> = [];
1754
+ // the line hashes of the entries: a file sharing none of them cannot give a split
1755
+ const wanted = new Set<number>();
1756
+ for (let e: Entry | null = unblamed; e; e = e.next) {
1757
+ list.push({ ent: e, split: emptySplit() });
1758
+ for (let l = e.lno; l < e.lno + e.numLines; l++) wanted.add(this.finalHashes[l]);
1759
+ }
1760
+ for (const c of candidates) {
1761
+ // find_move already dealt with this path
1762
+ if (porigin && c.path === porigin.path) continue;
1763
+ let hashes = this.copyHashes.get(c.id);
1764
+ let content: Uint8Array | undefined;
1765
+ if (hashes === undefined) {
1766
+ if (c.id !== target.blobId && (await this.isBig(c.id))) hashes = null;
1767
+ else {
1768
+ content = await this.readBlob(c.id, true);
1769
+ hashes = this.lineHashesOf(content);
1770
+ }
1771
+ this.keepCopyHashes(c.id, hashes);
1772
+ }
1773
+ if (hashes === null) continue;
1774
+ if (!sharesLine(hashes, wanted)) {
1775
+ // git's get_origin still moves a known origin to the front
1776
+ const known = parent.originsByPath.get(c.path);
1777
+ if (known) moveOriginToFront(parent, known);
1778
+ continue;
1779
+ }
1780
+ const isNew = !parent.originsByPath.has(c.path);
1781
+ const norigin = this.getOrigin(parentId, c.path);
1782
+ if (isNew) created.add(norigin);
1783
+ norigin.blobId = c.id;
1784
+ norigin.mode = c.mode;
1785
+ const file = {
1786
+ text:
1787
+ norigin.lines ??
1788
+ this.copySources.get(c.id) ??
1789
+ this.lineInterner().text(content ?? (await this.readBlob(c.id, true))),
1790
+ };
1791
+ for (const item of list) {
1792
+ this.copySplitIfBetter(item.split, this.findCopyInBlob(item.ent, norigin, file));
1793
+ }
1794
+ this.keepCopySourceText(c.id, file.text);
1795
+ }
1796
+ for (const { ent, split } of list) {
1797
+ if (split[1].suspect && this.copyScore < this.entryScore(split[1].lno, split[1].numLines)) {
1798
+ taken.add(split[1].suspect);
1799
+ splitBlame(blamed, rest, split, ent);
1800
+ } else {
1801
+ ent.next = leftover;
1802
+ leftover = ent;
1803
+ }
1804
+ }
1805
+ rest.tail.next = null;
1806
+ toosmall = this.filterSmall(toosmall, head, this.copyScore);
1807
+ unblamed = head.next;
1808
+ } while (unblamed);
1809
+ target.suspects = reverseBlame(leftover, null);
1810
+ for (const o of created) if (!taken.has(o) && !o.suspects) unlinkOrigin(parent, o);
1811
+ }
1812
+
1813
+ /**
1814
+ * The hash of each line, as the line interner hashes it (`xdl_hash_record` under
1815
+ * whitespace flags): lines a diff can match hash alike
1816
+ */
1817
+ private lineHashesOf(content: Uint8Array): Int32Array {
1818
+ const lines = new ByteLines(content);
1819
+ const ws = whitespaceFlags({ ignoreWhitespace: this.ignoreWhitespace });
1820
+ const n = lines.size();
1821
+ if (!ws) return lines.lineHashes.slice(0, n);
1822
+ const out = new Int32Array(n);
1823
+ for (let i = 0; i < n; i++)
1824
+ out[i] = xdlHashRecord(content, lines.start(i), lines.start(i + 1), ws);
1825
+ return out;
1826
+ }
1827
+
1828
+ /**
1829
+ * Kept while the cache has room (and never evicted): a commit scans its parent's files in
1830
+ * the order the next one scans them, so evicting the oldest would evict every file before
1831
+ * its next use
1832
+ */
1833
+ private keepCopyHashes(blobId: ObjectId, hashes: Int32Array | null): void {
1834
+ const size = 64 + (hashes ? hashes.byteLength : 0);
1835
+ if (this.copyHashBytes + size > this.copyHashCacheBytes) return;
1836
+ this.copyHashes.set(blobId, hashes);
1837
+ this.copyHashBytes += size;
1838
+ }
1839
+
1840
+ /** A file a copy was looked for in, interned, kept as `keepCopyHashes` keeps hashes */
1841
+ private keepCopySourceText(blobId: ObjectId, text: InternedText): void {
1842
+ const old = this.copySources.get(blobId);
1843
+ if (old) {
1844
+ this.copySources.set(blobId, text);
1845
+ return;
1846
+ }
1847
+ if (this.copySourceBytes + text.content.length > this.copySourceCacheBytes) return;
1848
+ this.copySources.set(blobId, text);
1849
+ this.copySourceBytes += text.content.length;
1850
+ }
1851
+
1852
+ /**
1853
+ * The parent's files `find_copy_in_parent` looks in, in the order git's tree diff lists
1854
+ * them: those the commit changed or removed, or (`harder`, find_copies_harder) all of
1855
+ * them; never gitlinks
1856
+ */
1857
+ private async copyCandidates(
1858
+ parentTree: ObjectId,
1859
+ childTree: ObjectId,
1860
+ harder: boolean,
1861
+ ): Promise<Array<{ path: string; id: ObjectId; mode: number }>> {
1862
+ const out: Array<{ path: string; id: ObjectId; mode: number }> = [];
1863
+ const walk = async (tree: ObjectId, other: ObjectId | undefined, prefix: string) => {
1864
+ if (!harder && tree === other) return;
1865
+ const others = new Map<string, { id: ObjectId; mode: number }>();
1866
+ if (other && !harder) {
1867
+ for await (const e of this.trees.loadTree(other)) others.set(e.name, e);
1868
+ }
1869
+ for await (const e of this.trees.loadTree(tree)) {
1870
+ const path = prefix + e.name;
1871
+ const o = others.get(e.name);
1872
+ const kind = e.mode & S_IFMT;
1873
+ if (kind === TREE_MODE) {
1874
+ await walk(e.id, o && (o.mode & S_IFMT) === TREE_MODE ? o.id : undefined, `${path}/`);
1875
+ } else if (kind !== GITLINK_MODE) {
1876
+ if (!harder && o && o.id === e.id && o.mode === e.mode) continue;
1877
+ out.push({ path, id: e.id, mode: e.mode });
1878
+ }
1879
+ }
1880
+ };
1881
+ await walk(parentTree, childTree, "");
1882
+ return out;
1883
+ }
1884
+
1885
+ /** git's `distribute_blame`: the entries found in parents queued to their origins */
1886
+ private distributeBlame(blamed: Entry | null, queue: CommitQueue): void {
1887
+ const ents: Entry[] = [];
1888
+ for (let e = blamed; e; e = e.next) ents.push(e);
1889
+ ents.sort((a, b) => a.suspect.seq - b.suspect.seq || a.sLno - b.sLno);
1890
+ let i = 0;
1891
+ while (i < ents.length) {
1892
+ const porigin = ents[i].suspect;
1893
+ let j = i;
1894
+ while (j + 1 < ents.length && ents[j + 1].suspect === porigin) {
1895
+ ents[j].next = ents[j + 1];
1896
+ j++;
1897
+ }
1898
+ ents[j].next = null;
1899
+ this.queueBlames(porigin, ents[i], queue);
1900
+ i = j + 1;
1901
+ }
1902
+ }
1903
+
1904
+ /** The diff options of every comparison (`sb->xdl_opts`) */
1905
+ private xdiffOptions(interner: LineInterner): XdiffOptions {
1906
+ return {
1907
+ interner,
1908
+ algorithm: this.algorithm,
1909
+ indentHeuristic: this.indentHeuristic,
1910
+ ignoreWhitespace: this.ignoreWhitespace,
1911
+ ...this.diffOptions,
1912
+ };
1913
+ }
1914
+
1915
+ /** mailmap.c's read_mailmap: `.mailmap` (not in a bare repository), `mailmap.blob`, `mailmap.file` */
1916
+ private async loadMailmap(): Promise<Mailmap> {
1917
+ const config = RemoteConfigStore.from(this.workingCopy);
1918
+ return readRepositoryMailmap({
1919
+ config: (key) => config.value(key),
1920
+ worktree: this.worktreeAccess,
1921
+ environment: hostEnvironmentOf(this.workingCopy),
1922
+ readBlobNamed: async (name) => {
1923
+ const id = await this.revisionResolver()
1924
+ .resolve(name)
1925
+ .catch(() => undefined);
1926
+ return id ? this.readBlob(id).catch(() => undefined) : undefined;
1927
+ },
1928
+ });
657
1929
  }
658
1930
 
659
1931
  /** git's `pass_whole_blame` */
@@ -685,11 +1957,15 @@ export class BlameCommand extends GitCommand<BlameResult> {
685
1957
  if (st) queue.put(porigin.commitId, st.commit.committer.timestamp);
686
1958
  }
687
1959
 
688
- /** git's `pass_blame_to_parent` */
1960
+ /**
1961
+ * git's `pass_blame_to_parent`; `ignoreDiffs` (an ignored commit's second pass) passes the
1962
+ * changed lines too, to the parent lines they resemble
1963
+ */
689
1964
  private async passBlameToParent(
690
1965
  target: Origin,
691
1966
  parent: Origin,
692
1967
  queue: CommitQueue,
1968
+ ignoreDiffs = false,
693
1969
  ): Promise<void> {
694
1970
  if (!target.suspects) return;
695
1971
  const newdest: Slot = { next: null };
@@ -702,28 +1978,41 @@ export class BlameCommand extends GitCommand<BlameResult> {
702
1978
  const interner = this.lineInterner();
703
1979
  if (fileP.interner !== interner) fileP = parent.lines = interner.text(fileP.content);
704
1980
  if (fileO.interner !== interner) fileO = target.lines = interner.text(fileO.content);
705
- const hunks = xdiffHunks(fileP, fileO, {
706
- interner,
707
- algorithm: this.algorithm,
708
- indentHeuristic: this.indentHeuristic,
709
- ignoreWhitespace: this.ignoreWhitespace,
710
- ...this.diffOptions,
711
- });
1981
+ const hunks = xdiffHunks(fileP, fileO, this.xdiffOptions(interner));
1982
+ // the parent's fingerprints are fresh for each pass (matching consumes them), the
1983
+ // target's kept while it passes blame
1984
+ const parentFps = ignoreDiffs ? lineFingerprints(fileP.content) : undefined;
1985
+ let targetFps: Fingerprint[] | undefined;
1986
+ if (ignoreDiffs) targetFps = target.fingerprints ??= lineFingerprints(fileO.content);
712
1987
  for (const h of hunks) {
713
- blameChunk(d, h.i2, h.i1 - h.i2, h.i2 + h.chg2, parent);
1988
+ const lineBlames =
1989
+ parentFps && targetFps && h.chg2 > 0
1990
+ ? guessLineBlames(parentFps, targetFps, h.i2, h.i1 - h.i2, h.i2 + h.chg2, h.chg1)
1991
+ : undefined;
1992
+ blameChunk(d, h.i2, h.i1 - h.i2, h.i2 + h.chg2, parent, lineBlames);
714
1993
  d.offset = h.i1 + h.chg1 - (h.i2 + h.chg2);
715
1994
  }
716
1995
  blameChunk(d, INT_MAX, d.offset, INT_MAX, parent);
717
1996
  d.dstq.next = null;
718
1997
  target.suspects = src.next;
719
- this.queueBlames(parent, newdest.next, queue);
1998
+ let passed = newdest.next;
1999
+ if (ignoreDiffs && passed) {
2000
+ // sort_blame_entries(compare_blame_suspect): one suspect, so by line (stable)
2001
+ const ents: Entry[] = [];
2002
+ for (let e: Entry | null = passed; e; e = e.next) ents.push(e);
2003
+ ents.sort((a, b) => a.sLno - b.sLno);
2004
+ for (let i = 0; i < ents.length; i++) ents[i].next = ents[i + 1] ?? null;
2005
+ passed = ents[0];
2006
+ }
2007
+ this.queueBlames(parent, passed, queue);
720
2008
  }
721
2009
 
722
2010
  /** git's `find_origin`: the parent's version at the same path, of the same kind */
723
2011
  private async findOrigin(parentId: ObjectId, origin: Origin): Promise<Origin | undefined> {
724
2012
  const parent = this.states.get(parentId);
725
2013
  if (!parent) return undefined;
726
- for (let o = parent.origins; o; o = o.next) if (o.path === origin.path) return o;
2014
+ const known = parent.originsByPath.get(origin.path);
2015
+ if (known) return known;
727
2016
  const entry = await this.lookup(parent.commit.tree, origin.path);
728
2017
  if (!entry || (entry.mode & S_IFMT) !== (origin.mode & S_IFMT)) return undefined;
729
2018
  if (entry.id !== origin.blobId && (await this.isBig(entry.id))) return undefined;
@@ -744,7 +2033,9 @@ export class BlameCommand extends GitCommand<BlameResult> {
744
2033
  const before = new Map<string, { id: ObjectId; mode: number }>();
745
2034
  const after = new Map<string, { id: ObjectId; mode: number }>();
746
2035
  await this.collectBlobs(parent.commit.tree, "", before);
747
- await this.collectBlobs(child.commit.tree, "", after);
2036
+ if (origin.commitId === this.objectFormat.nullId && this.fakeFiles) {
2037
+ for (const [p, e] of this.fakeFiles) after.set(p, e);
2038
+ } else await this.collectBlobs(child.commit.tree, "", after);
748
2039
  const sources = [];
749
2040
  for (const [path, e] of before) {
750
2041
  if (!after.has(path) && !(await this.isBig(e.id))) sources.push({ path, ...e });
@@ -759,7 +2050,7 @@ export class BlameCommand extends GitCommand<BlameResult> {
759
2050
  renameLimit: limit,
760
2051
  minimumScore: Math.round((this.renameScore * GIT_MAX_SCORE) / 100),
761
2052
  countLastSpan: this.renameCountLastSpan,
762
- size: async (c) => this.blobs.size(c.id),
2053
+ size: async (c) => this.blobSize(c.id),
763
2054
  load: async (c) => this.readBlob(c.id),
764
2055
  },
765
2056
  );
@@ -777,18 +2068,13 @@ export class BlameCommand extends GitCommand<BlameResult> {
777
2068
  private getOrigin(commitId: ObjectId, path: string): Origin {
778
2069
  const st = this.states.get(commitId);
779
2070
  if (!st) throw new Error(`commit ${commitId} not loaded`);
780
- let l: Origin | null = null;
781
- for (let o = st.origins; o; l = o, o = o.next) {
782
- if (o.path === path) {
783
- if (l) {
784
- l.next = o.next;
785
- o.next = st.origins;
786
- st.origins = o;
787
- }
788
- return o;
789
- }
2071
+ const known = st.originsByPath.get(path);
2072
+ if (known) {
2073
+ moveOriginToFront(st, known);
2074
+ return known;
790
2075
  }
791
2076
  const o: Origin = {
2077
+ seq: this.originSeq++,
792
2078
  commitId,
793
2079
  path,
794
2080
  blobId: "",
@@ -796,8 +2082,11 @@ export class BlameCommand extends GitCommand<BlameResult> {
796
2082
  suspects: null,
797
2083
  guilty: false,
798
2084
  next: st.origins,
2085
+ prev: null,
799
2086
  };
2087
+ if (st.origins) st.origins.prev = o;
800
2088
  st.origins = o;
2089
+ st.originsByPath.set(path, o);
801
2090
  return o;
802
2091
  }
803
2092
 
@@ -806,7 +2095,13 @@ export class BlameCommand extends GitCommand<BlameResult> {
806
2095
  if (known) return known;
807
2096
  const commit = await this.commits.load(commitId).catch(() => undefined);
808
2097
  if (!commit) return undefined;
809
- const st: CommitState = { commit, origins: null, uninteresting: false };
2098
+ const st: CommitState = {
2099
+ commit,
2100
+ origins: null,
2101
+ originsByPath: new Map(),
2102
+ uninteresting:
2103
+ this.reverseUninteresting.has(commitId) || this.sinceUninteresting.has(commitId),
2104
+ };
810
2105
  this.states.set(commitId, st);
811
2106
  return st;
812
2107
  }
@@ -832,7 +2127,13 @@ export class BlameCommand extends GitCommand<BlameResult> {
832
2127
 
833
2128
  /** Whether a blob is over the threshold (from its size, without reading it). */
834
2129
  private async isBig(blobId: ObjectId): Promise<boolean> {
835
- return (await this.blobs.size(blobId)) > this.bigFileThreshold;
2130
+ return (await this.blobSize(blobId)) > this.bigFileThreshold;
2131
+ }
2132
+
2133
+ /** A blob's size, the `--contents` buffer's too */
2134
+ private async blobSize(blobId: ObjectId): Promise<number> {
2135
+ const pretended = this.pretend.get(blobId);
2136
+ return pretended ? pretended.length : this.blobs.size(blobId);
836
2137
  }
837
2138
 
838
2139
  /**
@@ -840,6 +2141,8 @@ export class BlameCommand extends GitCommand<BlameResult> {
840
2141
  * comes (a resolved pack object) instead of copying it
841
2142
  */
842
2143
  private async readBlob(blobId: ObjectId, shared = false): Promise<Uint8Array> {
2144
+ const pretended = this.pretend.get(blobId);
2145
+ if (pretended) return pretended;
843
2146
  const chunks: Uint8Array[] = [];
844
2147
  let total = 0;
845
2148
  const content = await this.blobs.load(blobId);
@@ -890,13 +2193,17 @@ export class BlameCommand extends GitCommand<BlameResult> {
890
2193
  }
891
2194
  }
892
2195
 
893
- /** git's `blame_chunk`: lines before `tlno` go to the parent, `[tlno, same)` stay */
2196
+ /**
2197
+ * git's `blame_chunk`: lines before `tlno` go to the parent, `[tlno, same)` stay, unless
2198
+ * `lineBlames` (an ignored commit's guesses for `[tlno, same)`) passes them to the parent
2199
+ */
894
2200
  function blameChunk(
895
2201
  d: { offset: number; dstq: Slot; srcq: Slot },
896
2202
  tlno: number,
897
2203
  offset: number,
898
2204
  same: number,
899
2205
  parent: Origin,
2206
+ lineBlames?: LineBlame[],
900
2207
  ): void {
901
2208
  let e = d.srcq.next;
902
2209
  let samep: Entry | null = null;
@@ -921,6 +2228,7 @@ function blameChunk(
921
2228
  e = reverseBlame(diffp, e);
922
2229
  samep = null;
923
2230
  diffp = null;
2231
+ let ignoredp: Entry | null = null;
924
2232
  while (e && e.sLno < same) {
925
2233
  const next: Entry | null = e.next;
926
2234
  if (e.sLno + e.numLines > same) {
@@ -928,14 +2236,67 @@ function blameChunk(
928
2236
  n.next = samep;
929
2237
  samep = n;
930
2238
  }
931
- e.next = diffp;
932
- diffp = e;
2239
+ if (lineBlames) {
2240
+ // ignore_blame_entry: e carved into runs of adjacent lines of one side
2241
+ const base = e.sLno - tlno;
2242
+ const nrLines = e.numLines;
2243
+ let entryLen = 1;
2244
+ let cur: Entry | null = e;
2245
+ for (let i = 0; i < nrLines && cur; i++) {
2246
+ let after: Entry | null = null;
2247
+ if (i + 1 < nrLines) {
2248
+ const a = lineBlames[base + i];
2249
+ const b = lineBlames[base + i + 1];
2250
+ if (a.isParent === b.isParent && a.sLno + 1 === b.sLno) {
2251
+ entryLen++;
2252
+ continue;
2253
+ }
2254
+ after = splitBlameAt(cur, entryLen, cur.suspect);
2255
+ }
2256
+ if (lineBlames[base + i].isParent) {
2257
+ cur.ignored = true;
2258
+ cur.suspect = parent;
2259
+ cur.sLno = lineBlames[base + i - entryLen + 1].sLno;
2260
+ cur.next = ignoredp;
2261
+ ignoredp = cur;
2262
+ } else {
2263
+ cur.unblamable = true;
2264
+ cur.next = diffp;
2265
+ diffp = cur;
2266
+ }
2267
+ cur = after;
2268
+ entryLen = 1;
2269
+ }
2270
+ } else {
2271
+ e.next = diffp;
2272
+ diffp = e;
2273
+ }
933
2274
  e = next;
934
2275
  }
2276
+ if (ignoredp) {
2277
+ // not sorted yet: the parent's list is sorted once every chunk is done
2278
+ d.dstq.next = reverseBlame(ignoredp, d.dstq.next);
2279
+ d.dstq = ignoredp;
2280
+ }
935
2281
  d.srcq.next = reverseBlame(diffp, reverseBlame(samep, e));
936
2282
  if (diffp) d.srcq = diffp;
937
2283
  }
938
2284
 
2285
+ /** An identity mapped through the mailmap (`map_user`), the same object when nothing changes */
2286
+ function mapIdent(mailmap: Mailmap, ident: PersonIdent): PersonIdent {
2287
+ const m = mailmap.map(ident.name, ident.email);
2288
+ if (m.name === ident.name && m.email === ident.email) return ident;
2289
+ return { ...ident, name: m.name, email: m.email };
2290
+ }
2291
+
2292
+ /** Two names compared as strcmp compares their bytes */
2293
+ function compareBytes(a: string, b: string): number {
2294
+ const x = encodeGitPath(a);
2295
+ const y = encodeGitPath(b);
2296
+ for (let i = 0; i < x.length && i < y.length; i++) if (x[i] !== y[i]) return x[i] - y[i];
2297
+ return x.length - y.length;
2298
+ }
2299
+
939
2300
  /** Lines as git counts them: LF-terminated, an unterminated last line one more */
940
2301
  function countLines(content: Uint8Array): number {
941
2302
  let n = 0;
@@ -960,6 +2321,44 @@ function algorithmValue(v: string | undefined): XdiffAlgorithm | undefined {
960
2321
  return s === "myers" || s === "minimal" || s === "patience" || s === "histogram" ? s : undefined;
961
2322
  }
962
2323
 
2324
+ /**
2325
+ * builtin/blame.c's `git_blame_config` for the output: `blame.date`, `blame.showEmail`,
2326
+ * `blame.blankBoundary`, `blame.coloring`, `color.blame.repeatedLines` and
2327
+ * `color.blame.highlightRecent`, read in config order as git reads them
2328
+ */
2329
+ function blameOutputConfig(config: RemoteConfigStore): BlameOutputConfig {
2330
+ const out: BlameOutputConfig = {};
2331
+ const last = (key: string) => {
2332
+ const values = config.values(key);
2333
+ return values.length > 0 ? values[values.length - 1] : undefined;
2334
+ };
2335
+ const date = last("blame.date");
2336
+ if (date !== undefined) out.date = date;
2337
+ const email = last("blame.showEmail");
2338
+ if (email !== undefined) out.showEmail = boolValue(email) ?? false;
2339
+ const blank = last("blame.blankBoundary");
2340
+ if (blank !== undefined) out.blankBoundary = boolValue(blank) ?? false;
2341
+ const warnings: string[] = [];
2342
+ for (const value of config.values("blame.coloring")) {
2343
+ if (value === "repeatedLines") out.colorLines = true;
2344
+ else if (value === "highlightRecent") out.colorByAge = true;
2345
+ else if (value === "none") {
2346
+ out.colorLines = false;
2347
+ out.colorByAge = false;
2348
+ } else warnings.push(`warning: invalid value for 'blame.coloring': '${value}'`);
2349
+ }
2350
+ for (const value of config.values("color.blame.repeatedLines")) {
2351
+ const color = parseGitColor(value);
2352
+ if (color === undefined) {
2353
+ warnings.push(`warning: invalid value for 'color.blame.repeatedLines': '${value}'`);
2354
+ } else out.repeatedLinesColor = color;
2355
+ }
2356
+ const recent = last("color.blame.highlightRecent");
2357
+ if (recent !== undefined) out.highlightRecent = recent;
2358
+ if (warnings.length > 0) out.warnings = warnings;
2359
+ return out;
2360
+ }
2361
+
963
2362
  /**
964
2363
  * Create a BlameResult from entries.
965
2364
  */