@statewalker/vcs-commands 0.5.0 → 0.7.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 (561) hide show
  1. package/README.md +123 -8
  2. package/dist/commands/add-command.d.ts +265 -34
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/add-patch/add-interactive.d.ts +46 -0
  5. package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
  6. package/dist/commands/add-patch/add-patch.d.ts +139 -0
  7. package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
  8. package/dist/commands/add-patch/index.d.ts +6 -0
  9. package/dist/commands/add-patch/index.d.ts.map +1 -0
  10. package/dist/commands/add-patch/patch-backend.d.ts +80 -0
  11. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
  12. package/dist/commands/add-patch/patch-modes.d.ts +71 -0
  13. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
  14. package/dist/commands/add-patch/patch-session.d.ts +49 -0
  15. package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
  16. package/dist/commands/am/am-command.d.ts +175 -0
  17. package/dist/commands/am/am-command.d.ts.map +1 -0
  18. package/dist/commands/am/index.d.ts +3 -0
  19. package/dist/commands/am/index.d.ts.map +1 -0
  20. package/dist/commands/am/mailinfo.d.ts +58 -0
  21. package/dist/commands/am/mailinfo.d.ts.map +1 -0
  22. package/dist/commands/am/patch-format.d.ts +24 -0
  23. package/dist/commands/am/patch-format.d.ts.map +1 -0
  24. package/dist/commands/apply/apply-command.d.ts +153 -0
  25. package/dist/commands/apply/apply-command.d.ts.map +1 -0
  26. package/dist/commands/apply/apply-engine.d.ts +195 -0
  27. package/dist/commands/apply/apply-engine.d.ts.map +1 -0
  28. package/dist/commands/apply/apply-parse.d.ts +86 -0
  29. package/dist/commands/apply/apply-parse.d.ts.map +1 -0
  30. package/dist/commands/apply/apply-types.d.ts +70 -0
  31. package/dist/commands/apply/apply-types.d.ts.map +1 -0
  32. package/dist/commands/apply/index.d.ts +6 -0
  33. package/dist/commands/apply/index.d.ts.map +1 -0
  34. package/dist/commands/apply/latin1.d.ts +32 -0
  35. package/dist/commands/apply/latin1.d.ts.map +1 -0
  36. package/dist/commands/apply/whitespace.d.ts +58 -0
  37. package/dist/commands/apply/whitespace.d.ts.map +1 -0
  38. package/dist/commands/attributes-source.d.ts +26 -0
  39. package/dist/commands/attributes-source.d.ts.map +1 -0
  40. package/dist/commands/backfill-command.d.ts +110 -0
  41. package/dist/commands/backfill-command.d.ts.map +1 -0
  42. package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
  43. package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
  44. package/dist/commands/bisect/bisect-command.d.ts +201 -0
  45. package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
  46. package/dist/commands/bisect/bisect-engine.d.ts +219 -0
  47. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
  48. package/dist/commands/bisect/bisect-graph.d.ts +127 -0
  49. package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
  50. package/dist/commands/bisect/bisect-quote.d.ts +27 -0
  51. package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
  52. package/dist/commands/bisect/index.d.ts +5 -0
  53. package/dist/commands/bisect/index.d.ts.map +1 -0
  54. package/dist/commands/blame-command.d.ts +122 -131
  55. package/dist/commands/blame-command.d.ts.map +1 -1
  56. package/dist/commands/branch-command.d.ts +52 -2
  57. package/dist/commands/branch-command.d.ts.map +1 -1
  58. package/dist/commands/branch-tracking.d.ts +98 -0
  59. package/dist/commands/branch-tracking.d.ts.map +1 -0
  60. package/dist/commands/checkout-command.d.ts +300 -18
  61. package/dist/commands/checkout-command.d.ts.map +1 -1
  62. package/dist/commands/checkout-paths.d.ts +124 -0
  63. package/dist/commands/checkout-paths.d.ts.map +1 -0
  64. package/dist/commands/cherry-pick-command.d.ts +50 -42
  65. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  66. package/dist/commands/clean-command.d.ts +49 -16
  67. package/dist/commands/clean-command.d.ts.map +1 -1
  68. package/dist/commands/clone-command.d.ts +134 -0
  69. package/dist/commands/clone-command.d.ts.map +1 -1
  70. package/dist/commands/comment-char-config.d.ts +35 -0
  71. package/dist/commands/comment-char-config.d.ts.map +1 -0
  72. package/dist/commands/commit-command.d.ts +311 -17
  73. package/dist/commands/commit-command.d.ts.map +1 -1
  74. package/dist/commands/core-config.d.ts +78 -1
  75. package/dist/commands/core-config.d.ts.map +1 -1
  76. package/dist/commands/date-format.d.ts +58 -0
  77. package/dist/commands/date-format.d.ts.map +1 -0
  78. package/dist/commands/default-branch.d.ts +70 -0
  79. package/dist/commands/default-branch.d.ts.map +1 -0
  80. package/dist/commands/describe-command.d.ts.map +1 -1
  81. package/dist/commands/diff-command.d.ts +377 -30
  82. package/dist/commands/diff-command.d.ts.map +1 -1
  83. package/dist/commands/diff-textconv.d.ts +40 -0
  84. package/dist/commands/diff-textconv.d.ts.map +1 -0
  85. package/dist/commands/fetch-command.d.ts +149 -10
  86. package/dist/commands/fetch-command.d.ts.map +1 -1
  87. package/dist/commands/format-patch-command.d.ts +164 -0
  88. package/dist/commands/format-patch-command.d.ts.map +1 -0
  89. package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
  90. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
  91. package/dist/commands/fsck/fsck-command.d.ts +227 -0
  92. package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
  93. package/dist/commands/fsck/fsck-loose.d.ts +71 -0
  94. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
  95. package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
  96. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
  97. package/dist/commands/fsck/fsck-object-checks.d.ts +159 -0
  98. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
  99. package/dist/commands/fsck/fsck-object-table.d.ts +140 -0
  100. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
  101. package/dist/commands/fsck/fsck-pack.d.ts +122 -0
  102. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
  103. package/dist/commands/fsck/index.d.ts +6 -0
  104. package/dist/commands/fsck/index.d.ts.map +1 -0
  105. package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
  106. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
  107. package/dist/commands/gc-command.d.ts +106 -39
  108. package/dist/commands/gc-command.d.ts.map +1 -1
  109. package/dist/commands/git-date.d.ts +2 -0
  110. package/dist/commands/git-date.d.ts.map +1 -0
  111. package/dist/commands/git-describe.d.ts +67 -0
  112. package/dist/commands/git-describe.d.ts.map +1 -0
  113. package/dist/commands/git-hooks.d.ts +424 -0
  114. package/dist/commands/git-hooks.d.ts.map +1 -0
  115. package/dist/commands/git-ident.d.ts +128 -0
  116. package/dist/commands/git-ident.d.ts.map +1 -0
  117. package/dist/commands/hook-command.d.ts +96 -0
  118. package/dist/commands/hook-command.d.ts.map +1 -0
  119. package/dist/commands/index-adder.d.ts +233 -0
  120. package/dist/commands/index-adder.d.ts.map +1 -0
  121. package/dist/commands/index-host.d.ts +86 -0
  122. package/dist/commands/index-host.d.ts.map +1 -0
  123. package/dist/commands/index.d.ts +56 -0
  124. package/dist/commands/index.d.ts.map +1 -1
  125. package/dist/commands/index.js +3 -2
  126. package/dist/commands/init-command.d.ts +62 -4
  127. package/dist/commands/init-command.d.ts.map +1 -1
  128. package/dist/commands/legacy-remotes.d.ts +55 -0
  129. package/dist/commands/legacy-remotes.d.ts.map +1 -0
  130. package/dist/commands/local-clone.d.ts +60 -0
  131. package/dist/commands/local-clone.d.ts.map +1 -0
  132. package/dist/commands/local-transport.d.ts +117 -0
  133. package/dist/commands/local-transport.d.ts.map +1 -0
  134. package/dist/commands/log-command.d.ts +216 -24
  135. package/dist/commands/log-command.d.ts.map +1 -1
  136. package/dist/commands/log-graph.d.ts +120 -0
  137. package/dist/commands/log-graph.d.ts.map +1 -0
  138. package/dist/commands/log-output.d.ts +323 -0
  139. package/dist/commands/log-output.d.ts.map +1 -0
  140. package/dist/commands/ls-remote-command.d.ts +23 -7
  141. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  142. package/dist/commands/mailmap.d.ts +31 -0
  143. package/dist/commands/mailmap.d.ts.map +1 -0
  144. package/dist/commands/merge-bases.d.ts +85 -0
  145. package/dist/commands/merge-bases.d.ts.map +1 -0
  146. package/dist/commands/merge-command.d.ts +221 -74
  147. package/dist/commands/merge-command.d.ts.map +1 -1
  148. package/dist/commands/merge-config.d.ts +13 -0
  149. package/dist/commands/merge-config.d.ts.map +1 -0
  150. package/dist/commands/merge-drivers.d.ts +130 -0
  151. package/dist/commands/merge-drivers.d.ts.map +1 -0
  152. package/dist/commands/merge-support.d.ts +260 -0
  153. package/dist/commands/merge-support.d.ts.map +1 -0
  154. package/dist/commands/message-cleanup.d.ts +86 -0
  155. package/dist/commands/message-cleanup.d.ts.map +1 -0
  156. package/dist/commands/mv-command.d.ts +94 -0
  157. package/dist/commands/mv-command.d.ts.map +1 -0
  158. package/dist/commands/notes-command.d.ts +256 -0
  159. package/dist/commands/notes-command.d.ts.map +1 -0
  160. package/dist/commands/notes-commands.d.ts +41 -0
  161. package/dist/commands/notes-commands.d.ts.map +1 -0
  162. package/dist/commands/notes-merge-command.d.ts +105 -0
  163. package/dist/commands/notes-merge-command.d.ts.map +1 -0
  164. package/dist/commands/notes-support.d.ts +125 -0
  165. package/dist/commands/notes-support.d.ts.map +1 -0
  166. package/dist/commands/notes-tree.d.ts +116 -0
  167. package/dist/commands/notes-tree.d.ts.map +1 -0
  168. package/dist/commands/object-id-input.d.ts +20 -0
  169. package/dist/commands/object-id-input.d.ts.map +1 -0
  170. package/dist/commands/octopus-merge.d.ts +59 -0
  171. package/dist/commands/octopus-merge.d.ts.map +1 -0
  172. package/dist/commands/ort-merge.d.ts +126 -0
  173. package/dist/commands/ort-merge.d.ts.map +1 -0
  174. package/dist/commands/ort-recursive.d.ts +53 -0
  175. package/dist/commands/ort-recursive.d.ts.map +1 -0
  176. package/dist/commands/pack-refs-command.d.ts +20 -0
  177. package/dist/commands/pack-refs-command.d.ts.map +1 -1
  178. package/dist/commands/patch-id.d.ts +44 -0
  179. package/dist/commands/patch-id.d.ts.map +1 -0
  180. package/dist/commands/pathspec-attributes.d.ts +64 -0
  181. package/dist/commands/pathspec-attributes.d.ts.map +1 -0
  182. package/dist/commands/pathspec.d.ts +324 -0
  183. package/dist/commands/pathspec.d.ts.map +1 -0
  184. package/dist/commands/post-index-change.d.ts +33 -0
  185. package/dist/commands/post-index-change.d.ts.map +1 -0
  186. package/dist/commands/pretty-format.d.ts +222 -0
  187. package/dist/commands/pretty-format.d.ts.map +1 -0
  188. package/dist/commands/promisor-remote.d.ts +80 -0
  189. package/dist/commands/promisor-remote.d.ts.map +1 -0
  190. package/dist/commands/pull-command.d.ts +59 -8
  191. package/dist/commands/pull-command.d.ts.map +1 -1
  192. package/dist/commands/push-command.d.ts +24 -8
  193. package/dist/commands/push-command.d.ts.map +1 -1
  194. package/dist/commands/read-tree-command.d.ts +112 -0
  195. package/dist/commands/read-tree-command.d.ts.map +1 -0
  196. package/dist/commands/rebase-command.d.ts +507 -75
  197. package/dist/commands/rebase-command.d.ts.map +1 -1
  198. package/dist/commands/rebase-todo.d.ts +130 -0
  199. package/dist/commands/rebase-todo.d.ts.map +1 -0
  200. package/dist/commands/ref-decoration-filter.d.ts +53 -0
  201. package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
  202. package/dist/commands/reflog-messages.d.ts +98 -0
  203. package/dist/commands/reflog-messages.d.ts.map +1 -0
  204. package/dist/commands/remote-command.d.ts +31 -0
  205. package/dist/commands/remote-command.d.ts.map +1 -1
  206. package/dist/commands/remote-transport.d.ts +120 -0
  207. package/dist/commands/remote-transport.d.ts.map +1 -0
  208. package/dist/commands/reset-command.d.ts +161 -7
  209. package/dist/commands/reset-command.d.ts.map +1 -1
  210. package/dist/commands/restore-command.d.ts +103 -0
  211. package/dist/commands/restore-command.d.ts.map +1 -0
  212. package/dist/commands/rev-list-command.d.ts +78 -0
  213. package/dist/commands/rev-list-command.d.ts.map +1 -0
  214. package/dist/commands/rev-parse-command.d.ts +89 -0
  215. package/dist/commands/rev-parse-command.d.ts.map +1 -0
  216. package/dist/commands/revert-command.d.ts +46 -38
  217. package/dist/commands/revert-command.d.ts.map +1 -1
  218. package/dist/commands/revision-filenames.d.ts +95 -0
  219. package/dist/commands/revision-filenames.d.ts.map +1 -0
  220. package/dist/commands/revision-range.d.ts +67 -0
  221. package/dist/commands/revision-range.d.ts.map +1 -0
  222. package/dist/commands/revision-resolver.d.ts +325 -0
  223. package/dist/commands/revision-resolver.d.ts.map +1 -0
  224. package/dist/commands/rm-command.d.ts +69 -7
  225. package/dist/commands/rm-command.d.ts.map +1 -1
  226. package/dist/commands/sequencer-pick.d.ts +191 -0
  227. package/dist/commands/sequencer-pick.d.ts.map +1 -0
  228. package/dist/commands/sequencer-support.d.ts +125 -0
  229. package/dist/commands/sequencer-support.d.ts.map +1 -0
  230. package/dist/commands/serve-repository.d.ts +52 -0
  231. package/dist/commands/serve-repository.d.ts.map +1 -0
  232. package/dist/commands/sparse-checkout-command.d.ts +190 -0
  233. package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
  234. package/dist/commands/sparse-checkout-support.d.ts +268 -0
  235. package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
  236. package/dist/commands/stash-apply-command.d.ts +42 -8
  237. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  238. package/dist/commands/stash-create-command.d.ts +156 -2
  239. package/dist/commands/stash-create-command.d.ts.map +1 -1
  240. package/dist/commands/stash-drop-command.d.ts +2 -0
  241. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  242. package/dist/commands/stash-working-tree.d.ts +23 -0
  243. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  244. package/dist/commands/status-command.d.ts +300 -15
  245. package/dist/commands/status-command.d.ts.map +1 -1
  246. package/dist/commands/status-format.d.ts +155 -0
  247. package/dist/commands/status-format.d.ts.map +1 -0
  248. package/dist/commands/status-header.d.ts +64 -0
  249. package/dist/commands/status-header.d.ts.map +1 -0
  250. package/dist/commands/strerror.d.ts +7 -0
  251. package/dist/commands/strerror.d.ts.map +1 -0
  252. package/dist/commands/submodule-config.d.ts +38 -0
  253. package/dist/commands/submodule-config.d.ts.map +1 -0
  254. package/dist/commands/submodule-summary-command.d.ts +80 -0
  255. package/dist/commands/submodule-summary-command.d.ts.map +1 -0
  256. package/dist/commands/submodule-summary.d.ts +150 -0
  257. package/dist/commands/submodule-summary.d.ts.map +1 -0
  258. package/dist/commands/switch-command.d.ts +132 -0
  259. package/dist/commands/switch-command.d.ts.map +1 -0
  260. package/dist/commands/tag-command.d.ts +23 -2
  261. package/dist/commands/tag-command.d.ts.map +1 -1
  262. package/dist/commands/tracking-info.d.ts +64 -0
  263. package/dist/commands/tracking-info.d.ts.map +1 -0
  264. package/dist/commands/trailers.d.ts +73 -0
  265. package/dist/commands/trailers.d.ts.map +1 -0
  266. package/dist/commands/tree-restore.d.ts +85 -1
  267. package/dist/commands/tree-restore.d.ts.map +1 -1
  268. package/dist/commands/untracked-cache-support.d.ts +54 -0
  269. package/dist/commands/untracked-cache-support.d.ts.map +1 -0
  270. package/dist/commands/worktree-add-command.d.ts +108 -0
  271. package/dist/commands/worktree-add-command.d.ts.map +1 -0
  272. package/dist/commands/worktree-list-command.d.ts +69 -0
  273. package/dist/commands/worktree-list-command.d.ts.map +1 -0
  274. package/dist/commands/worktree-lock-command.d.ts +44 -0
  275. package/dist/commands/worktree-lock-command.d.ts.map +1 -0
  276. package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
  277. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  278. package/dist/commands/worktree-prune-command.d.ts +48 -0
  279. package/dist/commands/worktree-prune-command.d.ts.map +1 -0
  280. package/dist/commands/worktree-remove-command.d.ts +59 -0
  281. package/dist/commands/worktree-remove-command.d.ts.map +1 -0
  282. package/dist/commands/worktree-repair-command.d.ts +35 -0
  283. package/dist/commands/worktree-repair-command.d.ts.map +1 -0
  284. package/dist/commands/worktree-support.d.ts +64 -0
  285. package/dist/commands/worktree-support.d.ts.map +1 -0
  286. package/dist/commands-DIJ91NnD.js +62225 -0
  287. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  288. package/dist/errors/add-errors.d.ts +55 -0
  289. package/dist/errors/add-errors.d.ts.map +1 -1
  290. package/dist/errors/checkout-errors.d.ts +16 -0
  291. package/dist/errors/checkout-errors.d.ts.map +1 -1
  292. package/dist/errors/command-errors.d.ts +77 -0
  293. package/dist/errors/command-errors.d.ts.map +1 -1
  294. package/dist/errors/commit-errors.d.ts +9 -0
  295. package/dist/errors/commit-errors.d.ts.map +1 -1
  296. package/dist/errors/git-api-error.d.ts +59 -2
  297. package/dist/errors/git-api-error.d.ts.map +1 -1
  298. package/dist/errors/index.d.ts +1 -0
  299. package/dist/errors/index.d.ts.map +1 -1
  300. package/dist/errors/index.js +354 -19
  301. package/dist/errors/rebase-errors.d.ts +9 -0
  302. package/dist/errors/rebase-errors.d.ts.map +1 -1
  303. package/dist/errors/ref-errors.d.ts +32 -0
  304. package/dist/errors/ref-errors.d.ts.map +1 -1
  305. package/dist/errors/transport-errors.d.ts +12 -2
  306. package/dist/errors/transport-errors.d.ts.map +1 -1
  307. package/dist/errors/worktree-errors.d.ts +35 -0
  308. package/dist/errors/worktree-errors.d.ts.map +1 -0
  309. package/dist/git-command-BGiOJ8Zk.js +7246 -0
  310. package/dist/git-command.d.ts +428 -32
  311. package/dist/git-command.d.ts.map +1 -1
  312. package/dist/git.d.ts +315 -5
  313. package/dist/git.d.ts.map +1 -1
  314. package/dist/index.d.ts +1 -1
  315. package/dist/index.d.ts.map +1 -1
  316. package/dist/index.js +5 -5
  317. package/dist/remote-config/index.d.ts +1 -1
  318. package/dist/remote-config/index.d.ts.map +1 -1
  319. package/dist/remote-config/remote-config-store.d.ts +167 -6
  320. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  321. package/dist/remote-config/remote-refs.d.ts +7 -3
  322. package/dist/remote-config/remote-refs.d.ts.map +1 -1
  323. package/dist/rename/detect-renames.d.ts +148 -0
  324. package/dist/rename/detect-renames.d.ts.map +1 -0
  325. package/dist/rename/git-similarity.d.ts +44 -0
  326. package/dist/rename/git-similarity.d.ts.map +1 -0
  327. package/dist/rename/index.d.ts +2 -0
  328. package/dist/rename/index.d.ts.map +1 -1
  329. package/dist/results/binary-patch.d.ts +11 -0
  330. package/dist/results/binary-patch.d.ts.map +1 -0
  331. package/dist/results/blame-format.d.ts +55 -0
  332. package/dist/results/blame-format.d.ts.map +1 -0
  333. package/dist/results/cherry-pick-result.d.ts +10 -0
  334. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  335. package/dist/results/clone-result.d.ts +18 -0
  336. package/dist/results/clone-result.d.ts.map +1 -1
  337. package/dist/results/combined-diff.d.ts +77 -0
  338. package/dist/results/combined-diff.d.ts.map +1 -0
  339. package/dist/results/diff-entry.d.ts +32 -0
  340. package/dist/results/diff-entry.d.ts.map +1 -1
  341. package/dist/results/diff-formatter.d.ts +34 -60
  342. package/dist/results/diff-formatter.d.ts.map +1 -1
  343. package/dist/results/diff-order.d.ts +25 -0
  344. package/dist/results/diff-order.d.ts.map +1 -0
  345. package/dist/results/diff-output.d.ts +249 -0
  346. package/dist/results/diff-output.d.ts.map +1 -0
  347. package/dist/results/fetch-result.d.ts +15 -0
  348. package/dist/results/fetch-result.d.ts.map +1 -1
  349. package/dist/results/index.d.ts +5 -0
  350. package/dist/results/index.d.ts.map +1 -1
  351. package/dist/results/index.js +2 -252
  352. package/dist/results/init-result.d.ts +7 -0
  353. package/dist/results/init-result.d.ts.map +1 -1
  354. package/dist/results/merge-result.d.ts +15 -1
  355. package/dist/results/merge-result.d.ts.map +1 -1
  356. package/dist/results/pull-result.d.ts +17 -3
  357. package/dist/results/pull-result.d.ts.map +1 -1
  358. package/dist/results/push-result.d.ts +47 -0
  359. package/dist/results/push-result.d.ts.map +1 -1
  360. package/dist/results/quote-path.d.ts +27 -0
  361. package/dist/results/quote-path.d.ts.map +1 -0
  362. package/dist/results/rebase-result.d.ts +28 -1
  363. package/dist/results/rebase-result.d.ts.map +1 -1
  364. package/dist/results/revert-result.d.ts +10 -0
  365. package/dist/results/revert-result.d.ts.map +1 -1
  366. package/dist/results/stash-result.d.ts +5 -0
  367. package/dist/results/stash-result.d.ts.map +1 -1
  368. package/dist/results/status-result.d.ts +60 -6
  369. package/dist/results/status-result.d.ts.map +1 -1
  370. package/dist/results-WVlBhVb1.js +2935 -0
  371. package/dist/transport-command.d.ts +44 -1
  372. package/dist/transport-command.d.ts.map +1 -1
  373. package/package.json +15 -11
  374. package/src/commands/add-command.ts +1291 -226
  375. package/src/commands/add-patch/add-interactive.ts +941 -0
  376. package/src/commands/add-patch/add-patch.ts +1169 -0
  377. package/src/commands/add-patch/index.ts +5 -0
  378. package/src/commands/add-patch/patch-backend.ts +239 -0
  379. package/src/commands/add-patch/patch-modes.ts +249 -0
  380. package/src/commands/add-patch/patch-session.ts +159 -0
  381. package/src/commands/am/am-command.ts +1111 -0
  382. package/src/commands/am/index.ts +2 -0
  383. package/src/commands/am/mailinfo.ts +1015 -0
  384. package/src/commands/am/patch-format.ts +121 -0
  385. package/src/commands/apply/apply-command.ts +842 -0
  386. package/src/commands/apply/apply-engine.ts +1602 -0
  387. package/src/commands/apply/apply-parse.ts +1210 -0
  388. package/src/commands/apply/apply-types.ts +112 -0
  389. package/src/commands/apply/index.ts +5 -0
  390. package/src/commands/apply/latin1.ts +171 -0
  391. package/src/commands/apply/whitespace.ts +260 -0
  392. package/src/commands/attributes-source.ts +96 -0
  393. package/src/commands/backfill-command.ts +694 -0
  394. package/src/commands/bisect/bisect-checkout.ts +217 -0
  395. package/src/commands/bisect/bisect-command.ts +788 -0
  396. package/src/commands/bisect/bisect-engine.ts +1080 -0
  397. package/src/commands/bisect/bisect-graph.ts +595 -0
  398. package/src/commands/bisect/bisect-quote.ts +92 -0
  399. package/src/commands/bisect/index.ts +4 -0
  400. package/src/commands/blame-command.ts +711 -986
  401. package/src/commands/branch-command.ts +354 -32
  402. package/src/commands/branch-tracking.ts +331 -0
  403. package/src/commands/checkout-command.ts +1290 -243
  404. package/src/commands/checkout-paths.ts +784 -0
  405. package/src/commands/cherry-pick-command.ts +156 -396
  406. package/src/commands/clean-command.ts +504 -156
  407. package/src/commands/clone-command.ts +748 -69
  408. package/src/commands/comment-char-config.ts +160 -0
  409. package/src/commands/commit-command.ts +1782 -166
  410. package/src/commands/core-config.ts +166 -6
  411. package/src/commands/date-format.ts +668 -0
  412. package/src/commands/default-branch.ts +196 -0
  413. package/src/commands/describe-command.ts +2 -0
  414. package/src/commands/diff-command.ts +1916 -110
  415. package/src/commands/diff-textconv.ts +50 -0
  416. package/src/commands/fetch-command.ts +622 -68
  417. package/src/commands/format-patch-command.ts +974 -0
  418. package/src/commands/fsck/fetch-fsck.ts +229 -0
  419. package/src/commands/fsck/fsck-command.ts +3464 -0
  420. package/src/commands/fsck/fsck-loose.ts +297 -0
  421. package/src/commands/fsck/fsck-msg-ids.ts +176 -0
  422. package/src/commands/fsck/fsck-object-checks.ts +1085 -0
  423. package/src/commands/fsck/fsck-object-table.ts +373 -0
  424. package/src/commands/fsck/fsck-pack.ts +634 -0
  425. package/src/commands/fsck/index.ts +5 -0
  426. package/src/commands/fsck/verify-pack-command.ts +252 -0
  427. package/src/commands/gc-command.ts +324 -77
  428. package/src/commands/git-date.ts +9 -0
  429. package/src/commands/git-describe.ts +316 -0
  430. package/src/commands/git-hooks.ts +1483 -0
  431. package/src/commands/git-ident.ts +344 -0
  432. package/src/commands/hook-command.ts +247 -0
  433. package/src/commands/index-adder.ts +711 -0
  434. package/src/commands/index-host.ts +291 -0
  435. package/src/commands/index.ts +84 -0
  436. package/src/commands/init-command.ts +194 -14
  437. package/src/commands/legacy-remotes.ts +224 -0
  438. package/src/commands/local-clone.ts +183 -0
  439. package/src/commands/local-transport.ts +762 -0
  440. package/src/commands/log-command.ts +1930 -170
  441. package/src/commands/log-graph.ts +671 -0
  442. package/src/commands/log-output.ts +1359 -0
  443. package/src/commands/ls-remote-command.ts +105 -58
  444. package/src/commands/mailmap.ts +129 -0
  445. package/src/commands/merge-bases.ts +296 -0
  446. package/src/commands/merge-command.ts +1416 -491
  447. package/src/commands/merge-config.ts +25 -0
  448. package/src/commands/merge-drivers.ts +306 -0
  449. package/src/commands/merge-support.ts +1219 -0
  450. package/src/commands/message-cleanup.ts +275 -0
  451. package/src/commands/mv-command.ts +976 -0
  452. package/src/commands/notes-command.ts +890 -0
  453. package/src/commands/notes-commands.ts +87 -0
  454. package/src/commands/notes-merge-command.ts +777 -0
  455. package/src/commands/notes-support.ts +402 -0
  456. package/src/commands/notes-tree.ts +617 -0
  457. package/src/commands/object-id-input.ts +27 -0
  458. package/src/commands/octopus-merge.ts +378 -0
  459. package/src/commands/ort-merge.ts +1660 -0
  460. package/src/commands/ort-recursive.ts +160 -0
  461. package/src/commands/pack-refs-command.ts +39 -22
  462. package/src/commands/patch-id.ts +204 -0
  463. package/src/commands/pathspec-attributes.ts +162 -0
  464. package/src/commands/pathspec.ts +1199 -0
  465. package/src/commands/post-index-change.ts +62 -0
  466. package/src/commands/pretty-format.ts +1432 -0
  467. package/src/commands/promisor-remote.ts +298 -0
  468. package/src/commands/pull-command.ts +326 -33
  469. package/src/commands/push-command.ts +257 -29
  470. package/src/commands/read-tree-command.ts +861 -0
  471. package/src/commands/rebase-command.ts +3820 -372
  472. package/src/commands/rebase-todo.ts +584 -0
  473. package/src/commands/ref-decoration-filter.ts +118 -0
  474. package/src/commands/reflog-messages.ts +177 -0
  475. package/src/commands/remote-command.ts +124 -23
  476. package/src/commands/remote-transport.ts +383 -0
  477. package/src/commands/reset-command.ts +821 -104
  478. package/src/commands/restore-command.ts +350 -0
  479. package/src/commands/rev-list-command.ts +167 -0
  480. package/src/commands/rev-parse-command.ts +299 -0
  481. package/src/commands/revert-command.ts +152 -399
  482. package/src/commands/revision-filenames.ts +254 -0
  483. package/src/commands/revision-range.ts +222 -0
  484. package/src/commands/revision-resolver.ts +1397 -0
  485. package/src/commands/rm-command.ts +613 -67
  486. package/src/commands/sequencer-pick.ts +874 -0
  487. package/src/commands/sequencer-support.ts +876 -0
  488. package/src/commands/serve-repository.ts +125 -0
  489. package/src/commands/sparse-checkout-command.ts +1389 -0
  490. package/src/commands/sparse-checkout-support.ts +793 -0
  491. package/src/commands/stash-apply-command.ts +376 -343
  492. package/src/commands/stash-create-command.ts +625 -42
  493. package/src/commands/stash-drop-command.ts +15 -2
  494. package/src/commands/stash-working-tree.ts +168 -24
  495. package/src/commands/status-command.ts +1326 -105
  496. package/src/commands/status-format.ts +775 -0
  497. package/src/commands/status-header.ts +332 -0
  498. package/src/commands/strerror.ts +29 -0
  499. package/src/commands/submodule-config.ts +94 -0
  500. package/src/commands/submodule-summary-command.ts +333 -0
  501. package/src/commands/submodule-summary.ts +446 -0
  502. package/src/commands/switch-command.ts +402 -0
  503. package/src/commands/tag-command.ts +129 -41
  504. package/src/commands/tracking-info.ts +201 -0
  505. package/src/commands/trailers.ts +417 -0
  506. package/src/commands/tree-restore.ts +204 -4
  507. package/src/commands/untracked-cache-support.ts +198 -0
  508. package/src/commands/worktree-add-command.ts +458 -0
  509. package/src/commands/worktree-list-command.ts +206 -0
  510. package/src/commands/worktree-lock-command.ts +96 -0
  511. package/src/commands/worktree-overwrite-checks.ts +452 -26
  512. package/src/commands/worktree-prune-command.ts +99 -0
  513. package/src/commands/worktree-remove-command.ts +186 -0
  514. package/src/commands/worktree-repair-command.ts +59 -0
  515. package/src/commands/worktree-support.ts +214 -0
  516. package/src/core-commands/add.command.impl.ts +8 -2
  517. package/src/errors/add-errors.ts +45 -0
  518. package/src/errors/checkout-errors.ts +26 -2
  519. package/src/errors/command-errors.ts +101 -1
  520. package/src/errors/commit-errors.ts +18 -2
  521. package/src/errors/git-api-error.ts +82 -2
  522. package/src/errors/index.ts +1 -0
  523. package/src/errors/merge-errors.ts +2 -2
  524. package/src/errors/rebase-errors.ts +12 -0
  525. package/src/errors/ref-errors.ts +56 -2
  526. package/src/errors/remote-errors.ts +2 -2
  527. package/src/errors/stash-errors.ts +1 -1
  528. package/src/errors/transport-errors.ts +20 -4
  529. package/src/errors/worktree-errors.ts +49 -0
  530. package/src/git-command.ts +1207 -118
  531. package/src/git.ts +538 -12
  532. package/src/index.ts +1 -1
  533. package/src/remote-config/index.ts +2 -0
  534. package/src/remote-config/remote-config-store.ts +378 -18
  535. package/src/remote-config/remote-refs.ts +22 -6
  536. package/src/rename/detect-renames.ts +715 -0
  537. package/src/rename/git-similarity.ts +116 -0
  538. package/src/rename/index.ts +2 -0
  539. package/src/results/binary-patch.ts +401 -0
  540. package/src/results/blame-format.ts +239 -0
  541. package/src/results/cherry-pick-result.ts +10 -0
  542. package/src/results/clone-result.ts +21 -0
  543. package/src/results/combined-diff.ts +585 -0
  544. package/src/results/diff-entry.ts +35 -0
  545. package/src/results/diff-formatter.ts +152 -288
  546. package/src/results/diff-order.ts +64 -0
  547. package/src/results/diff-output.ts +1053 -0
  548. package/src/results/fetch-result.ts +15 -0
  549. package/src/results/index.ts +5 -0
  550. package/src/results/init-result.ts +9 -0
  551. package/src/results/merge-result.ts +15 -1
  552. package/src/results/pull-result.ts +17 -3
  553. package/src/results/push-result.ts +48 -0
  554. package/src/results/quote-path.ts +103 -0
  555. package/src/results/rebase-result.ts +37 -0
  556. package/src/results/revert-result.ts +10 -0
  557. package/src/results/stash-result.ts +6 -0
  558. package/src/results/status-result.ts +127 -46
  559. package/src/transport-command.ts +121 -2
  560. package/dist/commands-CsLNyvZ1.js +0 -12587
  561. package/dist/status-result-BpyUK1Sg.js +0 -519
@@ -1,18 +1,30 @@
1
- import type { Commit, ObjectId, PersonIdent, TreeEntry } from "@statewalker/vcs-core";
1
+ import type { Commit, ObjectId, PersonIdent } from "@statewalker/vcs-core";
2
2
  import { DEFAULT_BIG_FILE_THRESHOLD } from "@statewalker/vcs-core";
3
- import type { Edit } from "@statewalker/vcs-utils";
4
3
  import {
5
- DEFAULT_ALGORITHM,
6
- type DiffAlgorithm,
7
- getAlgorithm,
8
- RawText,
9
- RawTextComparator,
4
+ type InternedText,
5
+ LineInterner,
6
+ parseGitBool,
10
7
  type SupportedAlgorithm,
8
+ whitespaceFlags,
9
+ type XdiffAlgorithm,
10
+ type XdiffOptions,
11
+ xdiffHunks,
11
12
  } from "@statewalker/vcs-utils";
12
13
 
13
14
  import { RefNotFoundError } from "../errors/ref-errors.js";
14
15
  import { GitCommand } from "../git-command.js";
15
- import { DEFAULT_RENAME_SCORE, SimilarityIndex } from "../rename/index.js";
16
+ import { RemoteConfigStore } from "../remote-config/index.js";
17
+ import {
18
+ DEFAULT_RENAME_LIMIT,
19
+ DEFAULT_RENAME_SCORE,
20
+ detectRenames,
21
+ GIT_MAX_SCORE,
22
+ } from "../rename/index.js";
23
+ import { abbrevLengths } from "./core-config.js";
24
+ import { canonicalObjectId } from "./object-id-input.js";
25
+
26
+ /** Line bytes the interner holds before blame starts a new one (see `setInternerByteLimit`) */
27
+ const DEFAULT_INTERNER_BYTE_LIMIT = 64 * 1024 * 1024;
16
28
 
17
29
  /**
18
30
  * A single blame entry - represents authorship of one or more consecutive lines.
@@ -30,6 +42,13 @@ export interface BlameEntry {
30
42
  resultStart: number;
31
43
  /** Number of lines in this region */
32
44
  lineCount: number;
45
+ /**
46
+ * The parent version the commit's lines were compared with (`previous` of
47
+ * `git blame --porcelain`), when the commit had the file in a parent
48
+ */
49
+ previous?: { commitId: ObjectId; path: string };
50
+ /** A boundary commit (a root commit, unless `setShowRoot(true)`): `^` in git's output */
51
+ boundary?: boolean;
33
52
  }
34
53
 
35
54
  /**
@@ -61,8 +80,13 @@ export interface BlameResult {
61
80
  path: string;
62
81
  /** Total number of lines in the file */
63
82
  lineCount: number;
64
- /** Blame entries covering all lines */
83
+ /**
84
+ * Blame entries in line order (git's, after coalescing); they cover all lines, or the
85
+ * line ranges asked for
86
+ */
65
87
  entries: BlameEntry[];
88
+ /** The blamed file's content at the start commit */
89
+ content?: Uint8Array;
66
90
  /**
67
91
  * Get the blame entry for a specific line (1-based).
68
92
  *
@@ -87,10 +111,6 @@ export interface BlameResult {
87
111
  /**
88
112
  * Get the source line number in the original file.
89
113
  *
90
- * This returns the line number in the source commit where this line originated.
91
- * When a file has been modified through history with insertions/deletions,
92
- * the source line number may differ from the result line number.
93
- *
94
114
  * @param line Line number in the result file (1-based)
95
115
  * @returns Source line number (1-based), or undefined if out of range
96
116
  */
@@ -98,10 +118,6 @@ export interface BlameResult {
98
118
  /**
99
119
  * Get the source path for a specific line.
100
120
  *
101
- * This returns the file path in the source commit. When rename tracking
102
- * is enabled, this may differ from the result path if the line originated
103
- * from a file with a different name.
104
- *
105
121
  * @param line Line number in the result file (1-based)
106
122
  * @returns Source path, or undefined if out of range
107
123
  */
@@ -109,96 +125,199 @@ export interface BlameResult {
109
125
  /**
110
126
  * Get detailed tracking information for all lines.
111
127
  *
112
- * Returns an array of LineTracking objects, one per line in the result file.
113
- * Each object contains complete origin information including the commit,
114
- * source path, and source line number.
115
- *
116
128
  * @returns Array of LineTracking objects ordered by result line number
117
129
  */
118
130
  getLineTracking(): LineTracking[];
131
+ /**
132
+ * The length git's default output abbreviates the commits to before room for boundary
133
+ * marks (`update_auto_abbrev`): the longest of their unique abbreviations, from
134
+ * `core.abbrev` (auto: from the repository's approximate object count). Pass it to
135
+ * `formatBlame` as `autoAbbrev`.
136
+ */
137
+ autoAbbrev?(): Promise<number>;
138
+ }
139
+
140
+ /** A version of the file in a commit (`struct blame_origin`) */
141
+ interface Origin {
142
+ commitId: ObjectId;
143
+ path: string;
144
+ blobId: ObjectId;
145
+ mode: number;
146
+ /** Lines still suspected on this origin, sorted by `sLno` */
147
+ suspects: Entry | null;
148
+ previous?: Origin;
149
+ guilty: boolean;
150
+ /** The next origin of the same commit */
151
+ next: Origin | null;
152
+ /** The blob's lines (split and hashed once), while the origin is compared */
153
+ lines?: InternedText;
154
+ }
155
+
156
+ /** A run of lines (`struct blame_entry`), 0-based */
157
+ interface Entry {
158
+ next: Entry | null;
159
+ suspect: Origin;
160
+ /** First line in the final file */
161
+ lno: number;
162
+ /** First line in the suspect's file */
163
+ sLno: number;
164
+ numLines: number;
165
+ }
166
+
167
+ /** Something with a `next` link: a list head or an entry (`struct blame_entry **`) */
168
+ interface Slot {
169
+ next: Entry | null;
170
+ }
171
+
172
+ interface CommitState {
173
+ commit: Commit;
174
+ origins: Origin | null;
175
+ uninteresting: boolean;
176
+ }
177
+
178
+ const S_IFMT = 0o170000;
179
+ const TREE_MODE = 0o040000;
180
+ const INT_MAX = Number.MAX_SAFE_INTEGER;
181
+
182
+ /** `reverse_blame`: `head` reversed, ending in `tail` */
183
+ function reverseBlame(head: Entry | null, tail: Entry | null): Entry | null {
184
+ let h = head;
185
+ let t = tail;
186
+ while (h) {
187
+ const next = h.next;
188
+ h.next = t;
189
+ t = h;
190
+ h = next;
191
+ }
192
+ return t;
193
+ }
194
+
195
+ /** `blame_merge`: two lists sorted by `sLno` merged */
196
+ function blameMerge(list1: Entry | null, list2: Entry | null): Entry | null {
197
+ if (!list1) return list2;
198
+ if (!list2) return list1;
199
+ const head: Slot = { next: null };
200
+ let tail: Slot = head;
201
+ let p1: Entry | null = list1;
202
+ let p2: Entry | null = list2;
203
+ while (p1 && p2) {
204
+ if (p1.sLno <= p2.sLno) {
205
+ tail.next = p1;
206
+ tail = p1;
207
+ p1 = p1.next;
208
+ } else {
209
+ tail.next = p2;
210
+ tail = p2;
211
+ p2 = p2.next;
212
+ }
213
+ }
214
+ tail.next = p1 ?? p2;
215
+ return head.next;
216
+ }
217
+
218
+ /** `split_blame_at`: `e` keeps `len` lines, the rest is returned */
219
+ function splitBlameAt(e: Entry, len: number, suspect: Origin): Entry {
220
+ const n: Entry = {
221
+ next: null,
222
+ suspect,
223
+ lno: e.lno + len,
224
+ sLno: e.sLno + len,
225
+ numLines: e.numLines - len,
226
+ };
227
+ e.numLines = len;
228
+ return n;
229
+ }
230
+
231
+ /** A priority queue of commits: newest committer date first, ties first in, first out */
232
+ class CommitQueue {
233
+ private heap: Array<{ id: ObjectId; date: number; ctr: number }> = [];
234
+ private ctr = 0;
235
+
236
+ private less(i: number, j: number): boolean {
237
+ const a = this.heap[i];
238
+ const b = this.heap[j];
239
+ if (a.date !== b.date) return a.date > b.date;
240
+ return a.ctr < b.ctr;
241
+ }
242
+
243
+ put(id: ObjectId, date: number): void {
244
+ const h = this.heap;
245
+ h.push({ id, date, ctr: this.ctr++ });
246
+ let i = h.length - 1;
247
+ while (i > 0) {
248
+ const p = (i - 1) >> 1;
249
+ if (!this.less(i, p)) break;
250
+ [h[i], h[p]] = [h[p], h[i]];
251
+ i = p;
252
+ }
253
+ }
254
+
255
+ get(): ObjectId | undefined {
256
+ const h = this.heap;
257
+ if (h.length === 0) return undefined;
258
+ const top = h[0];
259
+ const last = h.pop();
260
+ if (h.length > 0 && last) {
261
+ h[0] = last;
262
+ let i = 0;
263
+ for (;;) {
264
+ const l = 2 * i + 1;
265
+ const r = l + 1;
266
+ let m = i;
267
+ if (l < h.length && this.less(l, m)) m = l;
268
+ if (r < h.length && this.less(r, m)) m = r;
269
+ if (m === i) break;
270
+ [h[i], h[m]] = [h[m], h[i]];
271
+ i = m;
272
+ }
273
+ }
274
+ return top.id;
275
+ }
119
276
  }
120
277
 
121
278
  /**
122
- * Annotate each line of a file with authorship information.
123
- *
124
- * Equivalent to `git blame`.
279
+ * Annotate each line of a file with the commit that last changed it.
125
280
  *
126
- * Based on JGit's BlameCommand and BlameGenerator.
281
+ * Equivalent to `git blame`, and a port of git's algorithm (`blame.c`): the commits are
282
+ * visited newest first (committer date); each passes the lines it did not change to the
283
+ * parents that have the file (found by path, else, following renames, by git's rename
284
+ * detection), comparing with each parent's version through the same xdiff diff git uses
285
+ * (`diff.algorithm`, default myers, and `diff.indentHeuristic`, default on); the lines left
286
+ * are its own. A parent with the same blob takes all lines. Root commits are boundaries
287
+ * unless `setShowRoot(true)` (`blame.showRoot`).
127
288
  *
128
- * This command tracks line-by-line history to determine which commit
129
- * introduced each line in a file. It walks commit history backward,
130
- * using diff algorithms to trace the origin of each line.
289
+ * Moves and copies across lines (`-M`, `-C`), `--reverse`, `--ignore-rev` and the mailmap
290
+ * are not supported.
131
291
  *
132
292
  * @example
133
293
  * ```typescript
134
- * // Blame a file at HEAD
135
- * const result = await git.blame()
136
- * .setFilePath("src/main.ts")
137
- * .call();
138
- *
139
- * // Get author of line 42
294
+ * const result = await git.blame().setFilePath("src/main.ts").call();
140
295
  * const author = result.getSourceAuthor(42);
141
- * console.log(`Line 42 written by: ${author?.name}`);
142
- *
143
- * // Blame at a specific commit
144
- * const result = await git.blame()
145
- * .setFilePath("README.md")
146
- * .setStartCommit(commitId)
147
- * .call();
148
296
  *
149
- * // Iterate over blame entries
150
- * for (const entry of result.entries) {
151
- * console.log(`Lines ${entry.resultStart}-${entry.resultStart + entry.lineCount - 1}: ${entry.commit.author.name}`);
152
- * }
297
+ * // `git blame --porcelain -w -L 10,20 README.md`
298
+ * const blame = await git.blame().setFilePath("README.md").setIgnoreWhitespace(true)
299
+ * .setLineRanges([[10, 20]]).call();
300
+ * process.stdout.write(formatBlamePorcelain(blame));
153
301
  * ```
154
302
  */
155
-
156
- /**
157
- * Represents a region of the result file that still needs blame attribution.
158
- * Modeled after JGit's Region class.
159
- *
160
- * Regions track both the position in the result file and the current source position
161
- * (which may differ as we trace back through history due to insertions/deletions).
162
- */
163
- interface BlameRegion {
164
- /** Position in the result file (1-based) */
165
- resultStart: number;
166
- /** Position in the current source file being examined (1-based) */
167
- sourceStart: number;
168
- /** Number of lines in this region */
169
- length: number;
170
- }
171
-
172
- /**
173
- * Represents a candidate commit that may have contributed lines to the result.
174
- * Modeled after JGit's Candidate class.
175
- */
176
- interface BlameCandidate {
177
- /** The commit being examined */
178
- commit: Commit;
179
- /** Commit ID */
180
- commitId: ObjectId;
181
- /** Current path being tracked */
182
- path: string;
183
- /** Blob ID of the file in this commit */
184
- blobId: ObjectId;
185
- /** Content of the file */
186
- content: Uint8Array;
187
- /** RawText for diff operations */
188
- rawText: RawText;
189
- /** Regions this candidate is responsible for */
190
- regions: BlameRegion[];
191
- /** Commit time for priority queue ordering */
192
- time: number;
193
- }
194
-
195
303
  export class BlameCommand extends GitCommand<BlameResult> {
196
304
  private filePath?: string;
197
305
  private startCommit?: ObjectId;
198
- private followRenames = false;
306
+ private followRenames = true;
199
307
  private renameScore = DEFAULT_RENAME_SCORE;
200
- private diffAlgorithm: DiffAlgorithm = getAlgorithm(DEFAULT_ALGORITHM);
308
+ private algorithm?: XdiffAlgorithm;
201
309
  private bigFileThreshold = DEFAULT_BIG_FILE_THRESHOLD;
310
+ private ignoreWhitespace = false;
311
+ private internerByteLimit = DEFAULT_INTERNER_BYTE_LIMIT;
312
+ private indentHeuristic?: boolean;
313
+ private showRoot?: boolean;
314
+ private lineRanges: Array<[number, number]> = [];
315
+ private diffOptions: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> = {};
316
+ private renameCountLastSpan?: boolean;
317
+
318
+ private states = new Map<ObjectId, CommitState>();
319
+ /** Numbers the lines of every version compared, so each is split and hashed once */
320
+ private interner?: LineInterner;
202
321
 
203
322
  /**
204
323
  * Set the file path to blame.
@@ -219,16 +338,15 @@ export class BlameCommand extends GitCommand<BlameResult> {
219
338
  * @param commit ObjectId of the starting commit
220
339
  */
221
340
  setStartCommit(commit: ObjectId): this {
341
+ commit = canonicalObjectId(commit);
222
342
  this.checkCallable();
223
343
  this.startCommit = commit;
224
344
  return this;
225
345
  }
226
346
 
227
347
  /**
228
- * Set whether to follow file renames.
229
- *
230
- * When enabled, the blame will track lines through renames.
231
- * This is more accurate but slower.
348
+ * Set whether to follow whole-file renames (default true, as git; false is
349
+ * `--no-follow`).
232
350
  *
233
351
  * @param follow Whether to follow renames
234
352
  */
@@ -250,13 +368,61 @@ export class BlameCommand extends GitCommand<BlameResult> {
250
368
  }
251
369
 
252
370
  /**
253
- * Set the diff algorithm to use.
371
+ * Set the diff algorithm (`--diff-algorithm`; default `diff.algorithm`, else myers).
254
372
  *
255
- * @param algorithm The algorithm to use (default: histogram)
373
+ * @param algorithm The algorithm to use
256
374
  */
257
- setAlgorithm(algorithm: SupportedAlgorithm): this {
375
+ setAlgorithm(algorithm: SupportedAlgorithm | XdiffAlgorithm): this {
258
376
  this.checkCallable();
259
- this.diffAlgorithm = getAlgorithm(algorithm);
377
+ this.algorithm = String(algorithm) as XdiffAlgorithm;
378
+ return this;
379
+ }
380
+
381
+ /** Ignore whitespace when comparing versions (`-w`) */
382
+ setIgnoreWhitespace(ignore: boolean): this {
383
+ this.checkCallable();
384
+ this.ignoreWhitespace = ignore;
385
+ return this;
386
+ }
387
+
388
+ /** The indent heuristic (default `diff.indentHeuristic`, true) */
389
+ setIndentHeuristic(on: boolean): this {
390
+ this.checkCallable();
391
+ this.indentHeuristic = on;
392
+ return this;
393
+ }
394
+
395
+ /** Do not treat root commits as boundaries (`--root`; default `blame.showRoot`) */
396
+ setShowRoot(show: boolean): this {
397
+ this.checkCallable();
398
+ this.showRoot = show;
399
+ return this;
400
+ }
401
+
402
+ /**
403
+ * Blame only these line ranges (`-L <start>,<end>`, 1-based, inclusive), merged as git
404
+ * merges overlapping ranges.
405
+ */
406
+ setLineRanges(ranges: Array<[number, number]>): this {
407
+ this.checkCallable();
408
+ this.lineRanges = ranges.map(([s, e]) => [s, e]);
409
+ return this;
410
+ }
411
+
412
+ /**
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)
416
+ */
417
+ setCompatibility(
418
+ options: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> & {
419
+ renameCountLastSpan?: boolean;
420
+ },
421
+ ): this {
422
+ this.checkCallable();
423
+ const { renameCountLastSpan, ...diff } = options;
424
+ this.diffOptions = { ...this.diffOptions, ...diff };
425
+ if (renameCountLastSpan !== undefined) this.renameCountLastSpan = renameCountLastSpan;
260
426
  return this;
261
427
  }
262
428
 
@@ -277,10 +443,21 @@ export class BlameCommand extends GitCommand<BlameResult> {
277
443
  }
278
444
 
279
445
  /**
280
- * Execute the blame command.
446
+ * Set how many bytes of distinct lines the line interner may hold (default 64 MiB). The
447
+ * interner keeps every distinct line it has seen; past this size blame starts a new one for
448
+ * the versions it reads next, and re-interns a version from the old one when it is compared
449
+ * with one from the new. The output does not change.
281
450
  *
282
- * Uses a queue-based algorithm similar to JGit's BlameGenerator.
283
- * For merge commits, checks all parents to correctly attribute lines.
451
+ * @param bytes Size in bytes
452
+ */
453
+ setInternerByteLimit(bytes: number): this {
454
+ this.checkCallable();
455
+ this.internerByteLimit = bytes;
456
+ return this;
457
+ }
458
+
459
+ /**
460
+ * Execute the blame command.
284
461
  *
285
462
  * @returns BlameResult with per-line authorship
286
463
  */
@@ -291,8 +468,11 @@ export class BlameCommand extends GitCommand<BlameResult> {
291
468
  if (!this.filePath) {
292
469
  throw new Error("File path must be set");
293
470
  }
471
+ const config = RemoteConfigStore.from(this.workingCopy);
472
+ this.algorithm ??= algorithmValue(config.value("diff.algorithm")) ?? "myers";
473
+ this.indentHeuristic ??= boolValue(config.value("diff.indentHeuristic")) ?? true;
474
+ this.showRoot ??= boolValue(config.value("blame.showRoot")) ?? false;
294
475
 
295
- // Resolve starting commit
296
476
  let startId = this.startCommit;
297
477
  if (!startId) {
298
478
  const head = await this.refsStore.resolve("HEAD");
@@ -303,776 +483,351 @@ export class BlameCommand extends GitCommand<BlameResult> {
303
483
  }
304
484
 
305
485
  const resultPath = this.filePath;
306
- const entries: BlameEntry[] = [];
307
-
308
- // Load the file content at the starting commit
309
- const startCommit = await this.commits.load(startId);
310
- if (!startCommit) {
486
+ const start = await this.state(startId);
487
+ if (!start) {
311
488
  throw new RefNotFoundError(`Cannot find commit: ${startId}`);
312
489
  }
313
- const blobId = await this.getFileBlob(startCommit.tree, resultPath);
314
-
315
- if (!blobId) {
490
+ const entry = await this.lookup(start.commit.tree, resultPath);
491
+ if (!entry) {
316
492
  throw new Error(`File not found: ${resultPath}`);
317
493
  }
318
-
319
- const size = await this.blobs.size(blobId);
494
+ const size = await this.blobs.size(entry.id);
320
495
  if (size > this.bigFileThreshold) {
321
496
  throw new Error(
322
497
  `${resultPath} is ${size} bytes, larger than bigFileThreshold (${this.bigFileThreshold})`,
323
498
  );
324
499
  }
325
-
326
- // Get file content and count lines
327
- const content = await this.collectBlob(blobId);
328
- const lineCount = this.countLines(content);
329
-
330
- if (lineCount === 0) {
331
- // Empty file
332
- return this.createBlameResult(resultPath, 0, []);
333
- }
334
-
335
- // Initialize the candidate queue with the starting commit
336
- // Queue is sorted by commit time descending (most recent first)
337
- const queue: BlameCandidate[] = [];
338
- const seen = new Set<ObjectId>();
339
-
340
- const initialCandidate: BlameCandidate = {
341
- commit: startCommit,
342
- commitId: startId,
343
- path: resultPath,
344
- blobId,
345
- content,
346
- rawText: new RawText(content),
347
- regions: [{ resultStart: 1, sourceStart: 1, length: lineCount }],
348
- time: startCommit.author.timestamp * 1000,
349
- };
350
-
351
- this.pushCandidate(queue, initialCandidate, seen);
352
-
353
- // Track remaining lines to blame
354
- let remaining = lineCount;
355
-
356
- // Process candidates until all lines are blamed or queue is empty
357
- while (queue.length > 0 && remaining > 0) {
358
- const candidate = queue.shift();
359
- if (!candidate) break;
360
-
361
- if (candidate.regions.length === 0) {
362
- continue;
363
- }
364
-
365
- const parentCount = candidate.commit.parents.length;
366
-
367
- if (parentCount === 0) {
368
- // Root commit - blame all remaining regions to this commit
369
- this.blameRegions(entries, candidate);
370
- remaining -= this.countRegionLines(candidate.regions);
371
- } else if (parentCount === 1) {
372
- // Single parent - process normally
373
- const blamed = await this.processOneParent(candidate, queue, seen, entries);
374
- remaining -= blamed;
375
- } else {
376
- // Merge commit - process all parents (JGit's processMerge)
377
- const blamed = await this.processMerge(candidate, queue, seen, entries);
378
- remaining -= blamed;
379
- }
500
+ const finalOrigin = this.getOrigin(startId, resultPath);
501
+ finalOrigin.blobId = entry.id;
502
+ finalOrigin.mode = entry.mode;
503
+ const content = await this.readBlob(entry.id);
504
+ finalOrigin.lines = this.lineInterner().text(content);
505
+ const lineCount = countLines(content);
506
+
507
+ // the initial entries: the whole file, or the -L ranges (sorted and merged)
508
+ const ranges = this.ranges(lineCount);
509
+ let head: Entry | null = null;
510
+ for (let i = ranges.length - 1; i >= 0; i--) {
511
+ const [s, e] = ranges[i];
512
+ head = { next: head, suspect: finalOrigin, lno: s, sLno: s, numLines: e - s };
513
+ }
514
+ const final: Slot = { next: null };
515
+ if (head) {
516
+ finalOrigin.suspects = head;
517
+ const queue = new CommitQueue();
518
+ queue.put(startId, start.commit.committer.timestamp);
519
+ await this.assignBlame(queue, final);
520
+ }
521
+
522
+ // blame_sort_final, blame_coalesce
523
+ const ents: Entry[] = [];
524
+ for (let e = final.next; e; e = e.next) ents.push(e);
525
+ ents.sort((a, b) => a.lno - b.lno);
526
+ const coalesced: Entry[] = [];
527
+ for (const e of ents) {
528
+ const last = coalesced[coalesced.length - 1];
529
+ if (
530
+ last &&
531
+ last.suspect === e.suspect &&
532
+ last.sLno + last.numLines === e.sLno &&
533
+ last.lno + last.numLines === e.lno
534
+ ) {
535
+ last.numLines += e.numLines;
536
+ } else coalesced.push({ ...e });
380
537
  }
381
538
 
382
- // Sort entries by result line number
383
- entries.sort((a, b) => a.resultStart - b.resultStart);
384
-
385
- // Merge adjacent entries from the same commit and path
386
- const mergedEntries = this.mergeAdjacentEntries(entries);
387
-
388
- return this.createBlameResult(resultPath, lineCount, mergedEntries);
389
- }
390
-
391
- /**
392
- * Process a commit with a single parent.
393
- *
394
- * @returns Number of lines blamed to this commit
395
- */
396
- private async processOneParent(
397
- candidate: BlameCandidate,
398
- queue: BlameCandidate[],
399
- seen: Set<ObjectId>,
400
- entries: BlameEntry[],
401
- ): Promise<number> {
402
- const parentId = candidate.commit.parents[0];
403
- const parentCommit = await this.commits.load(parentId);
404
- if (!parentCommit) {
405
- // Parent commit not found - blame all regions to this commit
406
- this.blameRegions(entries, candidate);
407
- return this.countRegionLines(candidate.regions);
539
+ const entries: BlameEntry[] = [];
540
+ for (const e of coalesced) {
541
+ const st = this.states.get(e.suspect.commitId);
542
+ if (!st) continue;
543
+ const prev = e.suspect.previous;
544
+ entries.push({
545
+ commit: st.commit,
546
+ commitId: e.suspect.commitId,
547
+ sourcePath: e.suspect.path,
548
+ sourceStart: e.sLno + 1,
549
+ resultStart: e.lno + 1,
550
+ lineCount: e.numLines,
551
+ ...(prev ? { previous: { commitId: prev.commitId, path: prev.path } } : {}),
552
+ boundary: st.uninteresting,
553
+ });
408
554
  }
409
-
410
- // Check if file exists in parent
411
- let parentBlobId = await this.getFileBlob(parentCommit.tree, candidate.path);
412
- let parentPath = candidate.path;
413
-
414
- // If file doesn't exist in parent and rename following is enabled, search for rename
415
- if (!parentBlobId && this.followRenames) {
416
- const rename = await this.findRename(
417
- parentCommit.tree,
418
- candidate.commit.tree,
419
- candidate.path,
420
- candidate.content,
555
+ const result = createBlameResult(resultPath, lineCount, entries, content);
556
+ const workingCopy = this.workingCopy;
557
+ result.autoAbbrev = async () => {
558
+ const lengths = await abbrevLengths(
559
+ workingCopy,
560
+ entries.map((e) => e.commitId),
421
561
  );
562
+ return lengths.size > 0 ? Math.max(...lengths.values()) : 7;
563
+ };
564
+ return result;
565
+ }
422
566
 
423
- if (rename) {
424
- parentBlobId = rename.oldBlobId;
425
- parentPath = rename.oldPath;
567
+ /** The -L ranges as 0-based half-open ranges, sorted and merged; the whole file otherwise */
568
+ private ranges(lineCount: number): Array<[number, number]> {
569
+ if (this.lineRanges.length === 0) return lineCount > 0 ? [[0, lineCount]] : [];
570
+ const out: Array<[number, number]> = [];
571
+ for (const [s, e] of this.lineRanges) {
572
+ let bottom = s;
573
+ let top = e;
574
+ if (top < bottom) [bottom, top] = [top, bottom];
575
+ if (bottom < 1) bottom = 1;
576
+ if (lineCount < bottom) {
577
+ throw new Error(`file ${this.filePath} has only ${lineCount} lines`);
426
578
  }
579
+ if (top > lineCount) top = lineCount;
580
+ out.push([bottom - 1, top]);
427
581
  }
428
-
429
- // A parent version over the threshold is never loaded: treat it as unrelated
430
- if (parentBlobId && parentBlobId !== candidate.blobId && (await this.isBig(parentBlobId))) {
431
- parentBlobId = undefined;
432
- }
433
-
434
- if (!parentBlobId) {
435
- // File was introduced in this commit - blame all regions
436
- this.blameRegions(entries, candidate);
437
- return this.countRegionLines(candidate.regions);
438
- }
439
-
440
- // If blob is identical, pass blame to parent without diffing
441
- if (parentBlobId === candidate.blobId) {
442
- const parentContent = await this.collectBlob(parentBlobId);
443
- const parentCandidate: BlameCandidate = {
444
- commit: parentCommit,
445
- commitId: parentId,
446
- path: parentPath,
447
- blobId: parentBlobId,
448
- content: parentContent,
449
- rawText: new RawText(parentContent),
450
- regions: candidate.regions,
451
- time: parentCommit.author.timestamp * 1000,
452
- };
453
- this.pushCandidate(queue, parentCandidate, seen);
454
- return 0;
582
+ out.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
583
+ const merged: Array<[number, number]> = [];
584
+ for (const r of out) {
585
+ const last = merged[merged.length - 1];
586
+ if (last && r[0] <= last[1]) last[1] = Math.max(last[1], r[1]);
587
+ else merged.push([r[0], r[1]]);
455
588
  }
456
-
457
- // Compute diff and split blame
458
- const parentContent = await this.collectBlob(parentBlobId);
459
- const parentRawText = new RawText(parentContent);
460
-
461
- return this.splitBlame(
462
- candidate,
463
- parentCommit,
464
- parentId,
465
- parentPath,
466
- parentBlobId,
467
- parentContent,
468
- parentRawText,
469
- queue,
470
- seen,
471
- entries,
472
- );
589
+ return merged;
473
590
  }
474
591
 
475
- /**
476
- * Process a merge commit with multiple parents.
477
- * Based on JGit's processMerge() algorithm.
478
- *
479
- * Key algorithm:
480
- * 1. If any parent has identical blob, pass all blame to that parent
481
- * 2. Otherwise, for each parent that has the file, compute diff
482
- * 3. Lines that match a parent go to that parent's history
483
- * 4. Lines that don't match any parent (conflict resolution) are blamed to merge commit
484
- *
485
- * @returns Number of lines blamed to the merge commit
486
- */
487
- private async processMerge(
488
- candidate: BlameCandidate,
489
- queue: BlameCandidate[],
490
- seen: Set<ObjectId>,
491
- entries: BlameEntry[],
492
- ): Promise<number> {
493
- const parentCount = candidate.commit.parents.length;
494
-
495
- // Collect parent info
496
- interface ParentInfo {
497
- commit: Commit;
498
- commitId: ObjectId;
499
- blobId: ObjectId;
500
- path: string;
501
- content: Uint8Array;
502
- rawText: RawText;
503
- }
504
-
505
- const parentInfos: (ParentInfo | null)[] = [];
506
-
507
- // First pass: check all parents for the file
508
- for (let pIdx = 0; pIdx < parentCount; pIdx++) {
509
- const parentId = candidate.commit.parents[pIdx];
510
- const parentCommit = await this.commits.load(parentId);
511
- if (!parentCommit) {
512
- parentInfos.push(null);
592
+ /** git's `assign_blame` */
593
+ private async assignBlame(queue: CommitQueue, final: Slot): Promise<void> {
594
+ let commitId = queue.get();
595
+ while (commitId) {
596
+ const st = this.states.get(commitId);
597
+ let suspect = st?.origins ?? null;
598
+ while (suspect && !suspect.suspects) suspect = suspect.next;
599
+ if (!st || !suspect) {
600
+ commitId = queue.get();
513
601
  continue;
514
602
  }
515
-
516
- let parentBlobId = await this.getFileBlob(parentCommit.tree, candidate.path);
517
- let parentPath = candidate.path;
518
-
519
- // Check for rename if file not found
520
- if (!parentBlobId && this.followRenames) {
521
- const rename = await this.findRename(
522
- parentCommit.tree,
523
- candidate.commit.tree,
524
- candidate.path,
525
- candidate.content,
526
- );
527
- if (rename) {
528
- parentBlobId = rename.oldBlobId;
529
- parentPath = rename.oldPath;
530
- }
531
- }
532
-
533
- if (parentBlobId && parentBlobId !== candidate.blobId && (await this.isBig(parentBlobId))) {
534
- parentBlobId = undefined;
535
- }
536
-
537
- if (parentBlobId) {
538
- // If any parent has identical blob, pass all blame to that parent
539
- if (parentBlobId === candidate.blobId) {
540
- const parentContent = await this.collectBlob(parentBlobId);
541
- const parentCandidate: BlameCandidate = {
542
- commit: parentCommit,
543
- commitId: parentId,
544
- path: parentPath,
545
- blobId: parentBlobId,
546
- content: parentContent,
547
- rawText: new RawText(parentContent),
548
- regions: candidate.regions,
549
- time: parentCommit.author.timestamp * 1000,
550
- };
551
- this.pushCandidate(queue, parentCandidate, seen);
552
- return 0;
553
- }
554
-
555
- const parentContent = await this.collectBlob(parentBlobId);
556
- parentInfos.push({
557
- commit: parentCommit,
558
- commitId: parentId,
559
- blobId: parentBlobId,
560
- path: parentPath,
561
- content: parentContent,
562
- rawText: new RawText(parentContent),
563
- });
564
- } else {
565
- parentInfos.push(null);
603
+ if (!st.uninteresting) await this.passBlame(suspect, queue);
604
+ // treat root commit as boundary
605
+ if (st.commit.parents.length === 0 && !this.showRoot) st.uninteresting = true;
606
+ // take responsibility for the remaining entries
607
+ let ent = suspect.suspects;
608
+ if (ent) {
609
+ suspect.guilty = true;
610
+ while (ent.next) ent = ent.next;
611
+ ent.next = final.next;
612
+ final.next = suspect.suspects;
613
+ suspect.suspects = null;
566
614
  }
567
615
  }
568
-
569
- // If no parents have the file, blame everything to this commit
570
- const validParents = parentInfos.filter((p): p is ParentInfo => p !== null);
571
- if (validParents.length === 0) {
572
- this.blameRegions(entries, candidate);
573
- return this.countRegionLines(candidate.regions);
574
- }
575
-
576
- // Process each parent and split blame
577
- // We track which regions have been passed to parents
578
- let currentRegions = candidate.regions;
579
-
580
- for (const parentInfo of validParents) {
581
- if (currentRegions.length === 0) break;
582
-
583
- // Compute diff between parent and candidate
584
- const comparator = RawTextComparator.DEFAULT;
585
- const edits = this.diffAlgorithm(comparator, parentInfo.rawText, candidate.rawText);
586
-
587
- // Split regions between parent and candidate
588
- const { parentRegions, childRegions } = this.takeBlame(edits, currentRegions);
589
-
590
- // Push parent candidate if it has regions
591
- if (parentRegions.length > 0) {
592
- const parentCandidate: BlameCandidate = {
593
- commit: parentInfo.commit,
594
- commitId: parentInfo.commitId,
595
- path: parentInfo.path,
596
- blobId: parentInfo.blobId,
597
- content: parentInfo.content,
598
- rawText: parentInfo.rawText,
599
- regions: parentRegions,
600
- time: parentInfo.commit.author.timestamp * 1000,
601
- };
602
- this.pushCandidate(queue, parentCandidate, seen);
603
- }
604
-
605
- // Remaining regions stay with the merge commit
606
- currentRegions = childRegions;
607
- }
608
-
609
- // Any remaining regions are blamed to the merge commit
610
- // (these are conflict resolution lines)
611
- if (currentRegions.length > 0) {
612
- const mergeCandidate: BlameCandidate = {
613
- ...candidate,
614
- regions: currentRegions,
615
- };
616
- this.blameRegions(entries, mergeCandidate);
617
- return this.countRegionLines(currentRegions);
618
- }
619
-
620
- return 0;
621
616
  }
622
617
 
623
- /**
624
- * Split blame between a candidate and its parent using diff edits.
625
- * Based on JGit's Candidate.takeBlame() method.
626
- *
627
- * For each line in the child that is unchanged (not covered by an edit),
628
- * we need to find where that line came from in the parent. Due to insertions
629
- * and deletions, unchanged lines in the child may not be contiguous in the parent.
630
- *
631
- * @returns Object with regions for parent and regions remaining with child
632
- */
633
- private takeBlame(
634
- edits: Edit[],
635
- regions: BlameRegion[],
636
- ): { parentRegions: BlameRegion[]; childRegions: BlameRegion[] } {
637
- const parentRegions: BlameRegion[] = [];
638
- const childRegions: BlameRegion[] = [];
639
-
640
- // Process each region against the edit list
641
- // Edits are in terms of 0-based line numbers
642
- // Regions use 1-based line numbers
643
-
644
- for (const region of regions) {
645
- // Convert to 0-based for comparison with edits
646
- const regionStart = region.sourceStart - 1;
647
- const regionEnd = regionStart + region.length;
648
-
649
- // Track what parts of this region are covered by edits (changes)
650
- // and what parts are unchanged (should go to parent)
651
- const changedRanges: Array<{ start: number; end: number }> = [];
652
-
653
- for (const edit of edits) {
654
- // Edit's B side (child/new) tells us which lines in the child are different
655
- const editStart = edit.beginB;
656
- const editEnd = edit.endB;
657
-
658
- // Check if edit overlaps with region
659
- if (editEnd <= regionStart || editStart >= regionEnd) {
660
- continue; // No overlap
661
- }
662
-
663
- // Compute overlap
664
- const overlapStart = Math.max(editStart, regionStart);
665
- const overlapEnd = Math.min(editEnd, regionEnd);
666
-
667
- if (overlapEnd > overlapStart) {
668
- changedRanges.push({ start: overlapStart, end: overlapEnd });
669
- }
670
- }
671
-
672
- // Sort and merge overlapping changed ranges
673
- changedRanges.sort((a, b) => a.start - b.start);
674
- const mergedChanges: Array<{ start: number; end: number }> = [];
675
- for (const range of changedRanges) {
676
- if (
677
- mergedChanges.length === 0 ||
678
- mergedChanges[mergedChanges.length - 1].end < range.start
679
- ) {
680
- mergedChanges.push({ ...range });
681
- } else {
682
- mergedChanges[mergedChanges.length - 1].end = Math.max(
683
- mergedChanges[mergedChanges.length - 1].end,
684
- range.end,
685
- );
686
- }
687
- }
688
-
689
- // Now split the region: unchanged parts go to parent, changed parts stay with child
690
- // For unchanged parts, we need to create separate regions for each contiguous block
691
- // in the parent, since mapping through edits may create gaps.
692
- let pos = regionStart;
693
-
694
- for (const change of mergedChanges) {
695
- // Unchanged part before this change - process line by line to handle non-contiguous mapping
696
- if (change.start > pos) {
697
- this.addParentRegionsForUnchangedBlock(
698
- pos,
699
- change.start,
700
- region.resultStart,
701
- regionStart,
702
- edits,
703
- parentRegions,
704
- );
618
+ /** git's `pass_blame` (without -M/-C) */
619
+ private async passBlame(origin: Origin, queue: CommitQueue): Promise<void> {
620
+ const st = this.states.get(origin.commitId);
621
+ if (!st) return;
622
+ const parents = st.commit.parents;
623
+ const n = parents.length;
624
+ if (n === 0) return;
625
+ const sgOrigin: Array<Origin | undefined> = new Array(n).fill(undefined);
626
+ for (let pass = 0; pass < (this.followRenames ? 2 : 1); pass++) {
627
+ for (let i = 0; i < n; i++) {
628
+ if (sgOrigin[i]) continue;
629
+ const parent = await this.state(parents[i]);
630
+ if (!parent) continue;
631
+ const porigin = pass
632
+ ? await this.findRename(parents[i], origin)
633
+ : await this.findOrigin(parents[i], origin);
634
+ if (!porigin) continue;
635
+ if (porigin.blobId === origin.blobId) {
636
+ this.passWholeBlame(origin, porigin, queue);
637
+ return;
705
638
  }
706
-
707
- // Changed part stays with child
708
- if (change.end > change.start) {
709
- childRegions.push({
710
- resultStart: region.resultStart + (change.start - regionStart),
711
- sourceStart: change.start + 1, // Convert back to 1-based
712
- length: change.end - change.start,
713
- });
639
+ let same = false;
640
+ for (let j = 0; j < i; j++) {
641
+ if (sgOrigin[j] && sgOrigin[j]?.blobId === porigin.blobId) {
642
+ same = true;
643
+ break;
644
+ }
714
645
  }
715
-
716
- pos = change.end;
717
- }
718
-
719
- // Remaining unchanged part after last change
720
- if (pos < regionEnd) {
721
- this.addParentRegionsForUnchangedBlock(
722
- pos,
723
- regionEnd,
724
- region.resultStart,
725
- regionStart,
726
- edits,
727
- parentRegions,
728
- );
729
- }
730
- }
731
-
732
- return { parentRegions, childRegions };
733
- }
734
-
735
- /**
736
- * Add parent regions for an unchanged block of lines.
737
- * Since lines may map to non-contiguous positions in the parent
738
- * (due to deletions), we need to create separate regions for each
739
- * contiguous block in the parent.
740
- */
741
- private addParentRegionsForUnchangedBlock(
742
- startPos: number,
743
- endPos: number,
744
- resultStart: number,
745
- regionStart: number,
746
- edits: Edit[],
747
- parentRegions: BlameRegion[],
748
- ): void {
749
- // Map each line position and group into contiguous regions in the parent
750
- let currentParentStart = -1;
751
- let currentResultStart = -1;
752
- let currentLength = 0;
753
- let lastParentPos = -1;
754
-
755
- for (let childPos = startPos; childPos < endPos; childPos++) {
756
- const parentPos = this.mapPositionToParent(childPos, edits);
757
-
758
- if (currentLength === 0) {
759
- // Start a new region
760
- currentParentStart = parentPos;
761
- currentResultStart = resultStart + (childPos - regionStart);
762
- currentLength = 1;
763
- lastParentPos = parentPos;
764
- } else if (parentPos === lastParentPos + 1) {
765
- // Extend current region (contiguous in parent)
766
- currentLength++;
767
- lastParentPos = parentPos;
768
- } else {
769
- // Gap in parent - push current region and start new one
770
- parentRegions.push({
771
- resultStart: currentResultStart,
772
- sourceStart: currentParentStart + 1, // Convert to 1-based
773
- length: currentLength,
774
- });
775
- currentParentStart = parentPos;
776
- currentResultStart = resultStart + (childPos - regionStart);
777
- currentLength = 1;
778
- lastParentPos = parentPos;
646
+ if (!same) sgOrigin[i] = porigin;
779
647
  }
780
648
  }
781
-
782
- // Push final region
783
- if (currentLength > 0) {
784
- parentRegions.push({
785
- resultStart: currentResultStart,
786
- sourceStart: currentParentStart + 1, // Convert to 1-based
787
- length: currentLength,
788
- });
649
+ for (let i = 0; i < n; i++) {
650
+ const porigin = sgOrigin[i];
651
+ if (!porigin) continue;
652
+ if (!origin.previous) origin.previous = porigin;
653
+ await this.passBlameToParent(origin, porigin, queue);
654
+ if (!origin.suspects) break;
789
655
  }
656
+ origin.lines = undefined;
790
657
  }
791
658
 
792
- /**
793
- * Map a position in the child file back to the corresponding position in the parent.
794
- * Takes into account insertions and deletions.
795
- *
796
- * @param childPos 0-based position in child
797
- * @param edits Edit list from diff
798
- * @returns 0-based position in parent
799
- */
800
- private mapPositionToParent(childPos: number, edits: Edit[]): number {
801
- let offset = 0;
802
-
803
- for (const edit of edits) {
804
- if (edit.endB <= childPos) {
805
- // This edit is before our position
806
- // Adjust offset: lengthA - lengthB gives the shift
807
- const lengthA = edit.endA - edit.beginA;
808
- const lengthB = edit.endB - edit.beginB;
809
- offset += lengthA - lengthB;
810
- } else if (edit.beginB <= childPos) {
811
- // Position is within an edit - this shouldn't happen for unchanged lines
812
- // but handle gracefully by mapping to edit start in parent
813
- return edit.beginA;
814
- }
659
+ /** git's `pass_whole_blame` */
660
+ private passWholeBlame(origin: Origin, porigin: Origin, queue: CommitQueue): void {
661
+ if (!porigin.lines && origin.lines) {
662
+ porigin.lines = origin.lines;
663
+ origin.lines = undefined;
815
664
  }
816
-
817
- return childPos + offset;
665
+ const suspects = origin.suspects;
666
+ origin.suspects = null;
667
+ for (let e = suspects; e; e = e.next) e.suspect = porigin;
668
+ this.queueBlames(porigin, suspects, queue);
818
669
  }
819
670
 
820
- /**
821
- * Split blame between a candidate and a single parent.
822
- *
823
- * @returns Number of lines blamed to the candidate
824
- */
825
- private async splitBlame(
826
- candidate: BlameCandidate,
827
- parentCommit: Commit,
828
- parentId: ObjectId,
829
- parentPath: string,
830
- parentBlobId: ObjectId,
831
- parentContent: Uint8Array,
832
- parentRawText: RawText,
833
- queue: BlameCandidate[],
834
- seen: Set<ObjectId>,
835
- entries: BlameEntry[],
836
- ): Promise<number> {
837
- // Compute diff
838
- const comparator = RawTextComparator.DEFAULT;
839
- const edits = this.diffAlgorithm(comparator, parentRawText, candidate.rawText);
840
-
841
- if (edits.length === 0) {
842
- // No changes (might happen with whitespace-ignoring comparator)
843
- const parentCandidate: BlameCandidate = {
844
- commit: parentCommit,
845
- commitId: parentId,
846
- path: parentPath,
847
- blobId: parentBlobId,
848
- content: parentContent,
849
- rawText: parentRawText,
850
- regions: candidate.regions,
851
- time: parentCommit.author.timestamp * 1000,
852
- };
853
- this.pushCandidate(queue, parentCandidate, seen);
854
- return 0;
855
- }
856
-
857
- // Split regions
858
- const { parentRegions, childRegions } = this.takeBlame(edits, candidate.regions);
859
-
860
- // Push parent candidate
861
- if (parentRegions.length > 0) {
862
- const parentCandidate: BlameCandidate = {
863
- commit: parentCommit,
864
- commitId: parentId,
865
- path: parentPath,
866
- blobId: parentBlobId,
867
- content: parentContent,
868
- rawText: parentRawText,
869
- regions: parentRegions,
870
- time: parentCommit.author.timestamp * 1000,
871
- };
872
- this.pushCandidate(queue, parentCandidate, seen);
873
- }
874
-
875
- // Blame child regions to this commit
876
- if (childRegions.length > 0) {
877
- const childCandidate: BlameCandidate = {
878
- ...candidate,
879
- regions: childRegions,
880
- };
881
- this.blameRegions(entries, childCandidate);
882
- return this.countRegionLines(childRegions);
671
+ /** git's `queue_blames` */
672
+ private queueBlames(porigin: Origin, sorted: Entry | null, queue: CommitQueue): void {
673
+ if (porigin.suspects) {
674
+ porigin.suspects = blameMerge(porigin.suspects, sorted);
675
+ return;
883
676
  }
884
-
885
- return 0;
886
- }
887
-
888
- /**
889
- * Push a candidate onto the queue, maintaining descending time order.
890
- * Handles merging of candidates for the same commit.
891
- */
892
- private pushCandidate(
893
- queue: BlameCandidate[],
894
- candidate: BlameCandidate,
895
- seen: Set<ObjectId>,
896
- ): void {
897
- // Check if we already have a candidate for this commit
898
- if (seen.has(candidate.commitId)) {
899
- // Find and merge with existing candidate
900
- const existing = queue.find(
901
- (c) => c.commitId === candidate.commitId && c.path === candidate.path,
902
- );
903
- if (existing) {
904
- // Merge regions
905
- existing.regions = this.mergeBlameRegions(existing.regions, candidate.regions);
677
+ const st = this.states.get(porigin.commitId);
678
+ for (let o = st?.origins ?? null; o; o = o.next) {
679
+ if (o.suspects) {
680
+ porigin.suspects = sorted;
906
681
  return;
907
682
  }
908
683
  }
909
-
910
- seen.add(candidate.commitId);
911
-
912
- // Insert in descending time order
913
- let insertIdx = 0;
914
- while (insertIdx < queue.length && queue[insertIdx].time > candidate.time) {
915
- insertIdx++;
916
- }
917
- queue.splice(insertIdx, 0, candidate);
684
+ porigin.suspects = sorted;
685
+ if (st) queue.put(porigin.commitId, st.commit.committer.timestamp);
918
686
  }
919
687
 
920
- /**
921
- * Merge two region lists, maintaining sorted order by resultStart.
922
- */
923
- private mergeBlameRegions(a: BlameRegion[], b: BlameRegion[]): BlameRegion[] {
924
- const result: BlameRegion[] = [...a, ...b];
925
- result.sort((x, y) => x.resultStart - y.resultStart);
926
-
927
- // Merge adjacent regions
928
- const merged: BlameRegion[] = [];
929
- for (const region of result) {
930
- if (merged.length === 0) {
931
- merged.push({ ...region });
932
- } else {
933
- const last = merged[merged.length - 1];
934
- if (
935
- last.resultStart + last.length === region.resultStart &&
936
- last.sourceStart + last.length === region.sourceStart
937
- ) {
938
- last.length += region.length;
939
- } else {
940
- merged.push({ ...region });
941
- }
942
- }
943
- }
944
-
945
- return merged;
688
+ /** git's `pass_blame_to_parent` */
689
+ private async passBlameToParent(
690
+ target: Origin,
691
+ parent: Origin,
692
+ queue: CommitQueue,
693
+ ): Promise<void> {
694
+ if (!target.suspects) return;
695
+ const newdest: Slot = { next: null };
696
+ const src: Slot = { next: target.suspects };
697
+ const d = { offset: 0, dstq: newdest as Slot, srcq: src as Slot };
698
+ let fileP = await this.originContent(parent);
699
+ let fileO = await this.originContent(target);
700
+ // ids are comparable only within one interner: a version interned before blame started
701
+ // a new interner is interned again in the current one
702
+ const interner = this.lineInterner();
703
+ if (fileP.interner !== interner) fileP = parent.lines = interner.text(fileP.content);
704
+ 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
+ });
712
+ for (const h of hunks) {
713
+ blameChunk(d, h.i2, h.i1 - h.i2, h.i2 + h.chg2, parent);
714
+ d.offset = h.i1 + h.chg1 - (h.i2 + h.chg2);
715
+ }
716
+ blameChunk(d, INT_MAX, d.offset, INT_MAX, parent);
717
+ d.dstq.next = null;
718
+ target.suspects = src.next;
719
+ this.queueBlames(parent, newdest.next, queue);
946
720
  }
947
721
 
948
- /**
949
- * Blame all regions in a candidate to its commit.
950
- */
951
- private blameRegions(entries: BlameEntry[], candidate: BlameCandidate): void {
952
- for (const region of candidate.regions) {
953
- entries.push({
954
- commit: candidate.commit,
955
- commitId: candidate.commitId,
956
- sourcePath: candidate.path,
957
- sourceStart: region.sourceStart,
958
- resultStart: region.resultStart,
959
- lineCount: region.length,
960
- });
961
- }
722
+ /** git's `find_origin`: the parent's version at the same path, of the same kind */
723
+ private async findOrigin(parentId: ObjectId, origin: Origin): Promise<Origin | undefined> {
724
+ const parent = this.states.get(parentId);
725
+ if (!parent) return undefined;
726
+ for (let o = parent.origins; o; o = o.next) if (o.path === origin.path) return o;
727
+ const entry = await this.lookup(parent.commit.tree, origin.path);
728
+ if (!entry || (entry.mode & S_IFMT) !== (origin.mode & S_IFMT)) return undefined;
729
+ if (entry.id !== origin.blobId && (await this.isBig(entry.id))) return undefined;
730
+ const porigin = this.getOrigin(parentId, origin.path);
731
+ porigin.blobId = entry.id;
732
+ porigin.mode = entry.mode;
733
+ return porigin;
962
734
  }
963
735
 
964
- /**
965
- * Count total lines in a list of regions.
966
- */
967
- private countRegionLines(regions: BlameRegion[]): number {
968
- return regions.reduce((sum, r) => sum + r.length, 0);
736
+ /** git's `find_rename`: a file of the parent the commit's file was renamed from */
737
+ private async findRename(parentId: ObjectId, origin: Origin): Promise<Origin | undefined> {
738
+ const parent = this.states.get(parentId);
739
+ const child = this.states.get(origin.commitId);
740
+ if (!parent || !child) return undefined;
741
+ // the path is a rename destination only when added (not a kind change)
742
+ const inParent = await this.lookup(parent.commit.tree, origin.path);
743
+ if (inParent) return undefined;
744
+ const before = new Map<string, { id: ObjectId; mode: number }>();
745
+ const after = new Map<string, { id: ObjectId; mode: number }>();
746
+ await this.collectBlobs(parent.commit.tree, "", before);
747
+ await this.collectBlobs(child.commit.tree, "", after);
748
+ const sources = [];
749
+ for (const [path, e] of before) {
750
+ if (!after.has(path) && !(await this.isBig(e.id))) sources.push({ path, ...e });
751
+ }
752
+ if (sources.length === 0) return undefined;
753
+ const config = RemoteConfigStore.from(this.workingCopy);
754
+ const limit = intValue(config.value("diff.renameLimit")) ?? DEFAULT_RENAME_LIMIT;
755
+ const pairs = await detectRenames(
756
+ sources,
757
+ [{ path: origin.path, id: origin.blobId, mode: origin.mode }],
758
+ {
759
+ renameLimit: limit,
760
+ minimumScore: Math.round((this.renameScore * GIT_MAX_SCORE) / 100),
761
+ countLastSpan: this.renameCountLastSpan,
762
+ size: async (c) => this.blobs.size(c.id),
763
+ load: async (c) => this.readBlob(c.id),
764
+ },
765
+ );
766
+ const pair = pairs.find((p) => p.to === origin.path);
767
+ if (!pair) return undefined;
768
+ const src = before.get(pair.from);
769
+ if (!src) return undefined;
770
+ const porigin = this.getOrigin(parentId, pair.from);
771
+ porigin.blobId = src.id;
772
+ porigin.mode = src.mode;
773
+ return porigin;
969
774
  }
970
775
 
971
- /**
972
- * Find a rename candidate for a file that doesn't exist in the parent commit.
973
- *
974
- * Searches for deleted files in the parent that have similar content to the
975
- * file in the current commit.
976
- *
977
- * @param parentTreeId Tree ID of the parent commit
978
- * @param currentTreeId Tree ID of the current commit
979
- * @param newPath Path of the file in the current commit
980
- * @param newContent Content of the file in the current commit
981
- * @returns Rename information if found, undefined otherwise
982
- */
983
- private async findRename(
984
- parentTreeId: ObjectId,
985
- currentTreeId: ObjectId,
986
- _newPath: string,
987
- newContent: Uint8Array,
988
- ): Promise<{ oldPath: string; oldBlobId: ObjectId; score: number } | undefined> {
989
- // Skip binary files for rename detection
990
- if (SimilarityIndex.isBinary(newContent)) {
991
- return undefined;
992
- }
993
-
994
- // Collect all blob entries from both trees
995
- const parentBlobs = new Map<string, TreeEntry>();
996
- const currentBlobs = new Map<string, TreeEntry>();
997
-
998
- await this.collectTreeEntries(parentTreeId, "", parentBlobs);
999
- await this.collectTreeEntries(currentTreeId, "", currentBlobs);
1000
-
1001
- // Find files that exist in parent but not in current (potential rename sources)
1002
- const deletedFiles: Array<{ path: string; entry: TreeEntry }> = [];
1003
- for (const [path, entry] of parentBlobs) {
1004
- if (!currentBlobs.has(path)) {
1005
- deletedFiles.push({ path, entry });
1006
- }
1007
- }
1008
-
1009
- if (deletedFiles.length === 0) {
1010
- return undefined;
1011
- }
1012
-
1013
- // Compute similarity index for the new file
1014
- const newIndex = SimilarityIndex.create(newContent);
1015
-
1016
- // Find the best matching deleted file
1017
- let bestMatch: { path: string; blobId: ObjectId; score: number } | undefined;
1018
-
1019
- for (const { path: oldPath, entry } of deletedFiles) {
1020
- if (await this.isBig(entry.id)) continue;
1021
-
1022
- // Load the old file content
1023
- const oldContent = await this.collectBlob(entry.id);
1024
-
1025
- // Skip binary files
1026
- if (SimilarityIndex.isBinary(oldContent)) {
1027
- continue;
1028
- }
1029
-
1030
- // Compute similarity
1031
- const oldIndex = SimilarityIndex.create(oldContent);
1032
- const score = newIndex.score(oldIndex);
1033
-
1034
- // Check if this is a better match than what we have
1035
- if (score >= this.renameScore && (!bestMatch || score > bestMatch.score)) {
1036
- bestMatch = {
1037
- path: oldPath,
1038
- blobId: entry.id,
1039
- score,
1040
- };
776
+ /** git's `get_origin`: the commit's origin for a path, moved to the front, or a new one */
777
+ private getOrigin(commitId: ObjectId, path: string): Origin {
778
+ const st = this.states.get(commitId);
779
+ 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;
1041
789
  }
1042
790
  }
791
+ const o: Origin = {
792
+ commitId,
793
+ path,
794
+ blobId: "",
795
+ mode: 0,
796
+ suspects: null,
797
+ guilty: false,
798
+ next: st.origins,
799
+ };
800
+ st.origins = o;
801
+ return o;
802
+ }
1043
803
 
1044
- if (bestMatch) {
1045
- return {
1046
- oldPath: bestMatch.path,
1047
- oldBlobId: bestMatch.blobId,
1048
- score: bestMatch.score,
1049
- };
1050
- }
804
+ private async state(commitId: ObjectId): Promise<CommitState | undefined> {
805
+ const known = this.states.get(commitId);
806
+ if (known) return known;
807
+ const commit = await this.commits.load(commitId).catch(() => undefined);
808
+ if (!commit) return undefined;
809
+ const st: CommitState = { commit, origins: null, uninteresting: false };
810
+ this.states.set(commitId, st);
811
+ return st;
812
+ }
1051
813
 
1052
- return undefined;
814
+ private async originContent(o: Origin): Promise<InternedText> {
815
+ o.lines ??= this.lineInterner().text(await this.readBlob(o.blobId, true));
816
+ return o.lines;
1053
817
  }
1054
818
 
1055
819
  /**
1056
- * Collect all blob entries from a tree recursively.
820
+ * The interner compared versions' lines go through (see `passBlameToParent`); a new one
821
+ * once the current one holds more than `internerByteLimit` bytes of lines, so a long walk
822
+ * does not keep every distinct line it has seen
1057
823
  */
1058
- private async collectTreeEntries(
1059
- treeId: ObjectId,
1060
- prefix: string,
1061
- entries: Map<string, TreeEntry>,
1062
- ): Promise<void> {
1063
- const TREE_MODE = 0o40000;
1064
-
1065
- for await (const entry of this.trees.loadTree(treeId)) {
1066
- const path = prefix ? `${prefix}/${entry.name}` : entry.name;
1067
-
1068
- if (entry.mode === TREE_MODE) {
1069
- // Recurse into subtree
1070
- await this.collectTreeEntries(entry.id, path, entries);
1071
- } else {
1072
- // Blob entry
1073
- entries.set(path, entry);
1074
- }
824
+ private lineInterner(): LineInterner {
825
+ if (!this.interner || this.interner.byteSize > this.internerByteLimit) {
826
+ this.interner = new LineInterner(
827
+ whitespaceFlags({ ignoreWhitespace: this.ignoreWhitespace }),
828
+ );
1075
829
  }
830
+ return this.interner;
1076
831
  }
1077
832
 
1078
833
  /** Whether a blob is over the threshold (from its size, without reading it). */
@@ -1081,202 +836,172 @@ export class BlameCommand extends GitCommand<BlameResult> {
1081
836
  }
1082
837
 
1083
838
  /**
1084
- * Collect blob content into a single buffer.
839
+ * A blob's content; `shared` (for content only read here) takes a single chunk as it
840
+ * comes (a resolved pack object) instead of copying it
1085
841
  */
1086
- private async collectBlob(blobId: ObjectId): Promise<Uint8Array> {
842
+ private async readBlob(blobId: ObjectId, shared = false): Promise<Uint8Array> {
1087
843
  const chunks: Uint8Array[] = [];
1088
- let totalLength = 0;
1089
-
1090
- const blobContent = await this.blobs.load(blobId);
1091
- if (blobContent) {
1092
- for await (const chunk of blobContent) {
844
+ let total = 0;
845
+ const content = await this.blobs.load(blobId);
846
+ if (content) {
847
+ for await (const chunk of content) {
1093
848
  chunks.push(chunk);
1094
- totalLength += chunk.length;
849
+ total += chunk.length;
1095
850
  }
1096
851
  }
1097
-
1098
- // Combine chunks into single buffer
1099
- const result = new Uint8Array(totalLength);
1100
- let offset = 0;
1101
- for (const chunk of chunks) {
1102
- result.set(chunk, offset);
1103
- offset += chunk.length;
852
+ if (shared && chunks.length === 1) return chunks[0];
853
+ const out = new Uint8Array(total);
854
+ let at = 0;
855
+ for (const c of chunks) {
856
+ out.set(c, at);
857
+ at += c.length;
1104
858
  }
1105
-
1106
- return result;
859
+ return out;
1107
860
  }
1108
861
 
1109
- /**
1110
- * Get blob ID for a file in a tree.
1111
- */
1112
- private async getFileBlob(treeId: ObjectId, path: string): Promise<ObjectId | undefined> {
862
+ /** The non-tree entry at `path` in a tree */
863
+ private async lookup(
864
+ treeId: ObjectId,
865
+ path: string,
866
+ ): Promise<{ id: ObjectId; mode: number } | undefined> {
1113
867
  const parts = path.split("/").filter((p) => p.length > 0);
1114
- let currentTreeId = treeId;
1115
-
868
+ let current = treeId;
1116
869
  for (let i = 0; i < parts.length; i++) {
1117
- const name = parts[i];
1118
- const isLast = i === parts.length - 1;
1119
-
1120
- const entry = await this.trees.getEntry(currentTreeId, name);
1121
- if (!entry) {
1122
- return undefined;
1123
- }
1124
-
1125
- if (isLast) {
1126
- return entry.id;
1127
- }
1128
-
1129
- // Navigate into subtree
1130
- currentTreeId = entry.id;
870
+ const entry = await this.trees.getEntry(current, parts[i]);
871
+ if (!entry) return undefined;
872
+ const isTree = (entry.mode & S_IFMT) === TREE_MODE;
873
+ if (i === parts.length - 1) return isTree ? undefined : { id: entry.id, mode: entry.mode };
874
+ if (!isTree) return undefined;
875
+ current = entry.id;
1131
876
  }
1132
-
1133
877
  return undefined;
1134
878
  }
1135
879
 
1136
- /**
1137
- * Count lines in content.
1138
- *
1139
- * Recognizes three types of line endings:
1140
- * - LF (\n) - Unix style
1141
- * - CRLF (\r\n) - Windows style (counts as one line ending)
1142
- * - CR (\r) - Classic Mac style (standalone CR without following LF)
1143
- */
1144
- private countLines(content: Uint8Array): number {
1145
- if (content.length === 0) {
1146
- return 0;
1147
- }
1148
-
1149
- let count = 1;
1150
- for (let i = 0; i < content.length; i++) {
1151
- const byte = content[i];
1152
- if (byte === 0x0a) {
1153
- // '\n' - LF (Unix) or second byte of CRLF (Windows)
1154
- count++;
1155
- } else if (byte === 0x0d) {
1156
- // '\r' - Check if it's CRLF or standalone CR
1157
- if (i + 1 < content.length && content[i + 1] === 0x0a) {
1158
- // CRLF - skip the CR, the LF will be handled in next iteration
1159
- continue;
1160
- }
1161
- // Standalone CR (classic Mac style)
1162
- count++;
1163
- }
1164
- }
1165
-
1166
- // If file ends with newline (LF or CR), don't count the empty "line" after it
1167
- const lastByte = content[content.length - 1];
1168
- if (lastByte === 0x0a || lastByte === 0x0d) {
1169
- count--;
880
+ private async collectBlobs(
881
+ treeId: ObjectId,
882
+ prefix: string,
883
+ out: Map<string, { id: ObjectId; mode: number }>,
884
+ ): Promise<void> {
885
+ for await (const entry of this.trees.loadTree(treeId)) {
886
+ const path = prefix ? `${prefix}/${entry.name}` : entry.name;
887
+ if ((entry.mode & S_IFMT) === TREE_MODE) await this.collectBlobs(entry.id, path, out);
888
+ else out.set(path, { id: entry.id, mode: entry.mode });
1170
889
  }
1171
-
1172
- return count;
1173
890
  }
891
+ }
1174
892
 
1175
- /**
1176
- * Merge adjacent entries from the same commit and source path.
1177
- */
1178
- private mergeAdjacentEntries(entries: BlameEntry[]): BlameEntry[] {
1179
- if (entries.length <= 1) {
1180
- return entries;
1181
- }
1182
-
1183
- const merged: BlameEntry[] = [];
1184
- let current = entries[0];
1185
-
1186
- for (let i = 1; i < entries.length; i++) {
1187
- const next = entries[i];
1188
-
1189
- // Check if can merge: same commit, same source path, and adjacent lines
1190
- if (
1191
- current.commitId === next.commitId &&
1192
- current.sourcePath === next.sourcePath &&
1193
- current.resultStart + current.lineCount === next.resultStart
1194
- ) {
1195
- // Merge
1196
- current = {
1197
- ...current,
1198
- lineCount: current.lineCount + next.lineCount,
1199
- };
1200
- } else {
1201
- merged.push(current);
1202
- current = next;
1203
- }
1204
- }
1205
-
1206
- merged.push(current);
1207
- return merged;
893
+ /** git's `blame_chunk`: lines before `tlno` go to the parent, `[tlno, same)` stay */
894
+ function blameChunk(
895
+ d: { offset: number; dstq: Slot; srcq: Slot },
896
+ tlno: number,
897
+ offset: number,
898
+ same: number,
899
+ parent: Origin,
900
+ ): void {
901
+ let e = d.srcq.next;
902
+ let samep: Entry | null = null;
903
+ let diffp: Entry | null = null;
904
+ while (e && e.sLno < tlno) {
905
+ const next: Entry | null = e.next;
906
+ if (e.sLno + e.numLines > tlno) {
907
+ const n = splitBlameAt(e, tlno - e.sLno, e.suspect);
908
+ n.next = diffp;
909
+ diffp = n;
910
+ }
911
+ e.suspect = parent;
912
+ e.sLno += offset;
913
+ e.next = samep;
914
+ samep = e;
915
+ e = next;
1208
916
  }
917
+ if (samep) {
918
+ d.dstq.next = reverseBlame(samep, d.dstq.next);
919
+ d.dstq = samep;
920
+ }
921
+ e = reverseBlame(diffp, e);
922
+ samep = null;
923
+ diffp = null;
924
+ while (e && e.sLno < same) {
925
+ const next: Entry | null = e.next;
926
+ if (e.sLno + e.numLines > same) {
927
+ const n = splitBlameAt(e, same - e.sLno, e.suspect);
928
+ n.next = samep;
929
+ samep = n;
930
+ }
931
+ e.next = diffp;
932
+ diffp = e;
933
+ e = next;
934
+ }
935
+ d.srcq.next = reverseBlame(diffp, reverseBlame(samep, e));
936
+ if (diffp) d.srcq = diffp;
937
+ }
1209
938
 
1210
- /**
1211
- * Create a BlameResult from entries.
1212
- */
1213
- private createBlameResult(path: string, lineCount: number, entries: BlameEntry[]): BlameResult {
1214
- // Build line-to-entry index for fast lookups
1215
- const lineToEntry = new Map<number, BlameEntry>();
1216
- for (const entry of entries) {
1217
- for (let i = 0; i < entry.lineCount; i++) {
1218
- lineToEntry.set(entry.resultStart + i, entry);
1219
- }
1220
- }
1221
-
1222
- /**
1223
- * Get the source line number for a given result line.
1224
- * The source line is computed based on the entry's sourceStart and the offset
1225
- * within the entry.
1226
- */
1227
- function getSourceLineForResult(line: number): number | undefined {
1228
- const entry = lineToEntry.get(line);
1229
- if (!entry) return undefined;
1230
- // Compute offset within the entry and add to sourceStart
1231
- const offset = line - entry.resultStart;
1232
- return entry.sourceStart + offset;
1233
- }
1234
-
1235
- return {
1236
- path,
1237
- lineCount,
1238
- entries,
1239
-
1240
- getEntry(line: number): BlameEntry | undefined {
1241
- return lineToEntry.get(line);
1242
- },
939
+ /** Lines as git counts them: LF-terminated, an unterminated last line one more */
940
+ function countLines(content: Uint8Array): number {
941
+ let n = 0;
942
+ for (let i = 0; i < content.length; i++) if (content[i] === 0x0a) n++;
943
+ if (content.length > 0 && content[content.length - 1] !== 0x0a) n++;
944
+ return n;
945
+ }
1243
946
 
1244
- getSourceCommit(line: number): Commit | undefined {
1245
- const entry = lineToEntry.get(line);
1246
- return entry?.commit;
1247
- },
947
+ /** A git boolean (`git_config_bool`), undefined when unset or not one. */
948
+ const boolValue = (v: string | undefined): boolean | undefined => parseGitBool(v);
1248
949
 
1249
- getSourceAuthor(line: number): PersonIdent | undefined {
1250
- const entry = lineToEntry.get(line);
1251
- return entry?.commit.author;
1252
- },
950
+ function intValue(value: string | undefined): number | undefined {
951
+ const m = value?.trim().match(/^(-?\d+)([kmg]?)$/i);
952
+ if (!m) return undefined;
953
+ const unit = { "": 1, k: 1024, m: 1024 ** 2, g: 1024 ** 3 }[m[2].toLowerCase()] ?? 1;
954
+ return Number(m[1]) * unit;
955
+ }
1253
956
 
1254
- getSourceLine(line: number): number | undefined {
1255
- return getSourceLineForResult(line);
1256
- },
957
+ function algorithmValue(v: string | undefined): XdiffAlgorithm | undefined {
958
+ const s = v?.trim().toLowerCase();
959
+ if (s === "default") return "myers";
960
+ return s === "myers" || s === "minimal" || s === "patience" || s === "histogram" ? s : undefined;
961
+ }
1257
962
 
1258
- getSourcePath(line: number): string | undefined {
963
+ /**
964
+ * Create a BlameResult from entries.
965
+ */
966
+ function createBlameResult(
967
+ path: string,
968
+ lineCount: number,
969
+ entries: BlameEntry[],
970
+ content: Uint8Array,
971
+ ): BlameResult {
972
+ const lineToEntry = new Map<number, BlameEntry>();
973
+ for (const entry of entries) {
974
+ for (let i = 0; i < entry.lineCount; i++) lineToEntry.set(entry.resultStart + i, entry);
975
+ }
976
+ const sourceLine = (line: number): number | undefined => {
977
+ const entry = lineToEntry.get(line);
978
+ return entry ? entry.sourceStart + (line - entry.resultStart) : undefined;
979
+ };
980
+ return {
981
+ path,
982
+ lineCount,
983
+ entries,
984
+ content,
985
+ getEntry: (line) => lineToEntry.get(line),
986
+ getSourceCommit: (line) => lineToEntry.get(line)?.commit,
987
+ getSourceAuthor: (line) => lineToEntry.get(line)?.commit.author,
988
+ getSourceLine: sourceLine,
989
+ getSourcePath: (line) => lineToEntry.get(line)?.sourcePath,
990
+ getLineTracking(): LineTracking[] {
991
+ const tracking: LineTracking[] = [];
992
+ for (let line = 1; line <= lineCount; line++) {
1259
993
  const entry = lineToEntry.get(line);
1260
- return entry?.sourcePath;
1261
- },
1262
-
1263
- getLineTracking(): LineTracking[] {
1264
- const tracking: LineTracking[] = [];
1265
- for (let line = 1; line <= lineCount; line++) {
1266
- const entry = lineToEntry.get(line);
1267
- if (entry) {
1268
- const offset = line - entry.resultStart;
1269
- tracking.push({
1270
- resultLine: line,
1271
- commit: entry.commit,
1272
- commitId: entry.commitId,
1273
- sourcePath: entry.sourcePath,
1274
- sourceLine: entry.sourceStart + offset,
1275
- });
1276
- }
994
+ if (entry) {
995
+ tracking.push({
996
+ resultLine: line,
997
+ commit: entry.commit,
998
+ commitId: entry.commitId,
999
+ sourcePath: entry.sourcePath,
1000
+ sourceLine: entry.sourceStart + (line - entry.resultStart),
1001
+ });
1277
1002
  }
1278
- return tracking;
1279
- },
1280
- };
1281
- }
1003
+ }
1004
+ return tracking;
1005
+ },
1006
+ };
1282
1007
  }