@statewalker/vcs-commands 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +299 -34
  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 +67 -4
  67. package/dist/commands/clean-command.d.ts.map +1 -1
  68. package/dist/commands/clone-command.d.ts +179 -7
  69. package/dist/commands/clone-command.d.ts.map +1 -1
  70. package/dist/commands/commit-command.d.ts +311 -17
  71. package/dist/commands/commit-command.d.ts.map +1 -1
  72. package/dist/commands/core-config.d.ts +93 -0
  73. package/dist/commands/core-config.d.ts.map +1 -0
  74. package/dist/commands/date-format.d.ts +58 -0
  75. package/dist/commands/date-format.d.ts.map +1 -0
  76. package/dist/commands/describe-command.d.ts.map +1 -1
  77. package/dist/commands/diff-command.d.ts +377 -30
  78. package/dist/commands/diff-command.d.ts.map +1 -1
  79. package/dist/commands/diff-textconv.d.ts +40 -0
  80. package/dist/commands/diff-textconv.d.ts.map +1 -0
  81. package/dist/commands/fetch-command.d.ts +244 -23
  82. package/dist/commands/fetch-command.d.ts.map +1 -1
  83. package/dist/commands/format-patch-command.d.ts +164 -0
  84. package/dist/commands/format-patch-command.d.ts.map +1 -0
  85. package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
  86. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
  87. package/dist/commands/fsck/fsck-command.d.ts +225 -0
  88. package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
  89. package/dist/commands/fsck/fsck-loose.d.ts +68 -0
  90. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
  91. package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
  92. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
  93. package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
  94. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
  95. package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
  96. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
  97. package/dist/commands/fsck/fsck-pack.d.ts +115 -0
  98. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
  99. package/dist/commands/fsck/index.d.ts +6 -0
  100. package/dist/commands/fsck/index.d.ts.map +1 -0
  101. package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
  102. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
  103. package/dist/commands/gc-command.d.ts +43 -0
  104. package/dist/commands/gc-command.d.ts.map +1 -1
  105. package/dist/commands/git-date.d.ts +66 -0
  106. package/dist/commands/git-date.d.ts.map +1 -0
  107. package/dist/commands/git-describe.d.ts +67 -0
  108. package/dist/commands/git-describe.d.ts.map +1 -0
  109. package/dist/commands/git-hooks.d.ts +416 -0
  110. package/dist/commands/git-hooks.d.ts.map +1 -0
  111. package/dist/commands/git-ident.d.ts +128 -0
  112. package/dist/commands/git-ident.d.ts.map +1 -0
  113. package/dist/commands/hook-command.d.ts +96 -0
  114. package/dist/commands/hook-command.d.ts.map +1 -0
  115. package/dist/commands/index-adder.d.ts +231 -0
  116. package/dist/commands/index-adder.d.ts.map +1 -0
  117. package/dist/commands/index-host.d.ts +86 -0
  118. package/dist/commands/index-host.d.ts.map +1 -0
  119. package/dist/commands/index.d.ts +55 -0
  120. package/dist/commands/index.d.ts.map +1 -1
  121. package/dist/commands/index.js +3 -2
  122. package/dist/commands/init-command.d.ts +12 -1
  123. package/dist/commands/init-command.d.ts.map +1 -1
  124. package/dist/commands/local-clone.d.ts +60 -0
  125. package/dist/commands/local-clone.d.ts.map +1 -0
  126. package/dist/commands/local-transport.d.ts +117 -0
  127. package/dist/commands/local-transport.d.ts.map +1 -0
  128. package/dist/commands/log-command.d.ts +216 -24
  129. package/dist/commands/log-command.d.ts.map +1 -1
  130. package/dist/commands/log-graph.d.ts +120 -0
  131. package/dist/commands/log-graph.d.ts.map +1 -0
  132. package/dist/commands/log-output.d.ts +323 -0
  133. package/dist/commands/log-output.d.ts.map +1 -0
  134. package/dist/commands/ls-remote-command.d.ts +23 -7
  135. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  136. package/dist/commands/mailmap.d.ts +31 -0
  137. package/dist/commands/mailmap.d.ts.map +1 -0
  138. package/dist/commands/merge-bases.d.ts +85 -0
  139. package/dist/commands/merge-bases.d.ts.map +1 -0
  140. package/dist/commands/merge-command.d.ts +209 -74
  141. package/dist/commands/merge-command.d.ts.map +1 -1
  142. package/dist/commands/merge-config.d.ts +13 -0
  143. package/dist/commands/merge-config.d.ts.map +1 -0
  144. package/dist/commands/merge-drivers.d.ts +130 -0
  145. package/dist/commands/merge-drivers.d.ts.map +1 -0
  146. package/dist/commands/merge-support.d.ts +252 -0
  147. package/dist/commands/merge-support.d.ts.map +1 -0
  148. package/dist/commands/message-cleanup.d.ts +86 -0
  149. package/dist/commands/message-cleanup.d.ts.map +1 -0
  150. package/dist/commands/mv-command.d.ts +94 -0
  151. package/dist/commands/mv-command.d.ts.map +1 -0
  152. package/dist/commands/notes-command.d.ts +256 -0
  153. package/dist/commands/notes-command.d.ts.map +1 -0
  154. package/dist/commands/notes-commands.d.ts +41 -0
  155. package/dist/commands/notes-commands.d.ts.map +1 -0
  156. package/dist/commands/notes-merge-command.d.ts +105 -0
  157. package/dist/commands/notes-merge-command.d.ts.map +1 -0
  158. package/dist/commands/notes-support.d.ts +125 -0
  159. package/dist/commands/notes-support.d.ts.map +1 -0
  160. package/dist/commands/notes-tree.d.ts +106 -0
  161. package/dist/commands/notes-tree.d.ts.map +1 -0
  162. package/dist/commands/object-id-input.d.ts +20 -0
  163. package/dist/commands/object-id-input.d.ts.map +1 -0
  164. package/dist/commands/octopus-merge.d.ts +59 -0
  165. package/dist/commands/octopus-merge.d.ts.map +1 -0
  166. package/dist/commands/ort-merge.d.ts +126 -0
  167. package/dist/commands/ort-merge.d.ts.map +1 -0
  168. package/dist/commands/ort-recursive.d.ts +53 -0
  169. package/dist/commands/ort-recursive.d.ts.map +1 -0
  170. package/dist/commands/pack-refs-command.d.ts +20 -0
  171. package/dist/commands/pack-refs-command.d.ts.map +1 -1
  172. package/dist/commands/patch-id.d.ts +41 -0
  173. package/dist/commands/patch-id.d.ts.map +1 -0
  174. package/dist/commands/pathspec-attributes.d.ts +64 -0
  175. package/dist/commands/pathspec-attributes.d.ts.map +1 -0
  176. package/dist/commands/pathspec.d.ts +324 -0
  177. package/dist/commands/pathspec.d.ts.map +1 -0
  178. package/dist/commands/post-index-change.d.ts +33 -0
  179. package/dist/commands/post-index-change.d.ts.map +1 -0
  180. package/dist/commands/pretty-format.d.ts +222 -0
  181. package/dist/commands/pretty-format.d.ts.map +1 -0
  182. package/dist/commands/promisor-remote.d.ts +80 -0
  183. package/dist/commands/promisor-remote.d.ts.map +1 -0
  184. package/dist/commands/pull-command.d.ts +41 -8
  185. package/dist/commands/pull-command.d.ts.map +1 -1
  186. package/dist/commands/push-command.d.ts +24 -8
  187. package/dist/commands/push-command.d.ts.map +1 -1
  188. package/dist/commands/read-tree-command.d.ts +112 -0
  189. package/dist/commands/read-tree-command.d.ts.map +1 -0
  190. package/dist/commands/rebase-command.d.ts +507 -75
  191. package/dist/commands/rebase-command.d.ts.map +1 -1
  192. package/dist/commands/rebase-todo.d.ts +130 -0
  193. package/dist/commands/rebase-todo.d.ts.map +1 -0
  194. package/dist/commands/ref-decoration-filter.d.ts +53 -0
  195. package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
  196. package/dist/commands/reflog-messages.d.ts +98 -0
  197. package/dist/commands/reflog-messages.d.ts.map +1 -0
  198. package/dist/commands/remote-command.d.ts +146 -6
  199. package/dist/commands/remote-command.d.ts.map +1 -1
  200. package/dist/commands/remote-transport.d.ts +120 -0
  201. package/dist/commands/remote-transport.d.ts.map +1 -0
  202. package/dist/commands/reset-command.d.ts +161 -7
  203. package/dist/commands/reset-command.d.ts.map +1 -1
  204. package/dist/commands/restore-command.d.ts +103 -0
  205. package/dist/commands/restore-command.d.ts.map +1 -0
  206. package/dist/commands/rev-list-command.d.ts +78 -0
  207. package/dist/commands/rev-list-command.d.ts.map +1 -0
  208. package/dist/commands/rev-parse-command.d.ts +80 -0
  209. package/dist/commands/rev-parse-command.d.ts.map +1 -0
  210. package/dist/commands/revert-command.d.ts +46 -38
  211. package/dist/commands/revert-command.d.ts.map +1 -1
  212. package/dist/commands/revision-filenames.d.ts +95 -0
  213. package/dist/commands/revision-filenames.d.ts.map +1 -0
  214. package/dist/commands/revision-range.d.ts +67 -0
  215. package/dist/commands/revision-range.d.ts.map +1 -0
  216. package/dist/commands/revision-resolver.d.ts +321 -0
  217. package/dist/commands/revision-resolver.d.ts.map +1 -0
  218. package/dist/commands/rm-command.d.ts +69 -7
  219. package/dist/commands/rm-command.d.ts.map +1 -1
  220. package/dist/commands/sequencer-pick.d.ts +191 -0
  221. package/dist/commands/sequencer-pick.d.ts.map +1 -0
  222. package/dist/commands/sequencer-support.d.ts +125 -0
  223. package/dist/commands/sequencer-support.d.ts.map +1 -0
  224. package/dist/commands/serve-repository.d.ts +52 -0
  225. package/dist/commands/serve-repository.d.ts.map +1 -0
  226. package/dist/commands/sparse-checkout-command.d.ts +190 -0
  227. package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
  228. package/dist/commands/sparse-checkout-support.d.ts +268 -0
  229. package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
  230. package/dist/commands/stash-apply-command.d.ts +69 -13
  231. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  232. package/dist/commands/stash-create-command.d.ts +214 -26
  233. package/dist/commands/stash-create-command.d.ts.map +1 -1
  234. package/dist/commands/stash-drop-command.d.ts +10 -2
  235. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  236. package/dist/commands/stash-list-command.d.ts +2 -4
  237. package/dist/commands/stash-list-command.d.ts.map +1 -1
  238. package/dist/commands/stash-working-tree.d.ts +95 -0
  239. package/dist/commands/stash-working-tree.d.ts.map +1 -0
  240. package/dist/commands/status-command.d.ts +320 -28
  241. package/dist/commands/status-command.d.ts.map +1 -1
  242. package/dist/commands/status-format.d.ts +155 -0
  243. package/dist/commands/status-format.d.ts.map +1 -0
  244. package/dist/commands/status-header.d.ts +64 -0
  245. package/dist/commands/status-header.d.ts.map +1 -0
  246. package/dist/commands/strerror.d.ts +7 -0
  247. package/dist/commands/strerror.d.ts.map +1 -0
  248. package/dist/commands/submodule-config.d.ts +38 -0
  249. package/dist/commands/submodule-config.d.ts.map +1 -0
  250. package/dist/commands/submodule-summary-command.d.ts +80 -0
  251. package/dist/commands/submodule-summary-command.d.ts.map +1 -0
  252. package/dist/commands/submodule-summary.d.ts +150 -0
  253. package/dist/commands/submodule-summary.d.ts.map +1 -0
  254. package/dist/commands/switch-command.d.ts +132 -0
  255. package/dist/commands/switch-command.d.ts.map +1 -0
  256. package/dist/commands/tag-command.d.ts +23 -2
  257. package/dist/commands/tag-command.d.ts.map +1 -1
  258. package/dist/commands/tracking-info.d.ts +64 -0
  259. package/dist/commands/tracking-info.d.ts.map +1 -0
  260. package/dist/commands/trailers.d.ts +73 -0
  261. package/dist/commands/trailers.d.ts.map +1 -0
  262. package/dist/commands/tree-restore.d.ts +137 -6
  263. package/dist/commands/tree-restore.d.ts.map +1 -1
  264. package/dist/commands/untracked-cache-support.d.ts +53 -0
  265. package/dist/commands/untracked-cache-support.d.ts.map +1 -0
  266. package/dist/commands/worktree-add-command.d.ts +108 -0
  267. package/dist/commands/worktree-add-command.d.ts.map +1 -0
  268. package/dist/commands/worktree-list-command.d.ts +69 -0
  269. package/dist/commands/worktree-list-command.d.ts.map +1 -0
  270. package/dist/commands/worktree-lock-command.d.ts +44 -0
  271. package/dist/commands/worktree-lock-command.d.ts.map +1 -0
  272. package/dist/commands/worktree-overwrite-checks.d.ts +204 -0
  273. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
  274. package/dist/commands/worktree-prune-command.d.ts +48 -0
  275. package/dist/commands/worktree-prune-command.d.ts.map +1 -0
  276. package/dist/commands/worktree-remove-command.d.ts +59 -0
  277. package/dist/commands/worktree-remove-command.d.ts.map +1 -0
  278. package/dist/commands/worktree-repair-command.d.ts +35 -0
  279. package/dist/commands/worktree-repair-command.d.ts.map +1 -0
  280. package/dist/commands/worktree-support.d.ts +64 -0
  281. package/dist/commands/worktree-support.d.ts.map +1 -0
  282. package/dist/commands-DnmlfwGV.js +61620 -0
  283. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  284. package/dist/core-commands/index.d.ts +0 -3
  285. package/dist/core-commands/index.d.ts.map +1 -1
  286. package/dist/errors/add-errors.d.ts +55 -0
  287. package/dist/errors/add-errors.d.ts.map +1 -1
  288. package/dist/errors/checkout-errors.d.ts +29 -0
  289. package/dist/errors/checkout-errors.d.ts.map +1 -1
  290. package/dist/errors/command-errors.d.ts +77 -0
  291. package/dist/errors/command-errors.d.ts.map +1 -1
  292. package/dist/errors/commit-errors.d.ts +9 -0
  293. package/dist/errors/commit-errors.d.ts.map +1 -1
  294. package/dist/errors/git-api-error.d.ts +59 -2
  295. package/dist/errors/git-api-error.d.ts.map +1 -1
  296. package/dist/errors/index.d.ts +1 -0
  297. package/dist/errors/index.d.ts.map +1 -1
  298. package/dist/errors/index.js +371 -19
  299. package/dist/errors/rebase-errors.d.ts +9 -0
  300. package/dist/errors/rebase-errors.d.ts.map +1 -1
  301. package/dist/errors/ref-errors.d.ts +32 -0
  302. package/dist/errors/ref-errors.d.ts.map +1 -1
  303. package/dist/errors/transport-errors.d.ts +12 -2
  304. package/dist/errors/transport-errors.d.ts.map +1 -1
  305. package/dist/errors/worktree-errors.d.ts +35 -0
  306. package/dist/errors/worktree-errors.d.ts.map +1 -0
  307. package/dist/git-command-DxvwPrPB.js +7612 -0
  308. package/dist/git-command.d.ts +422 -32
  309. package/dist/git-command.d.ts.map +1 -1
  310. package/dist/git.d.ts +326 -5
  311. package/dist/git.d.ts.map +1 -1
  312. package/dist/index.d.ts +1 -1
  313. package/dist/index.d.ts.map +1 -1
  314. package/dist/index.js +5 -5
  315. package/dist/remote-config/index.d.ts +1 -0
  316. package/dist/remote-config/index.d.ts.map +1 -1
  317. package/dist/remote-config/remote-config-store.d.ts +123 -3
  318. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  319. package/dist/remote-config/remote-refs.d.ts +41 -0
  320. package/dist/remote-config/remote-refs.d.ts.map +1 -0
  321. package/dist/rename/detect-renames.d.ts +148 -0
  322. package/dist/rename/detect-renames.d.ts.map +1 -0
  323. package/dist/rename/git-similarity.d.ts +44 -0
  324. package/dist/rename/git-similarity.d.ts.map +1 -0
  325. package/dist/rename/index.d.ts +2 -0
  326. package/dist/rename/index.d.ts.map +1 -1
  327. package/dist/results/binary-patch.d.ts +11 -0
  328. package/dist/results/binary-patch.d.ts.map +1 -0
  329. package/dist/results/blame-format.d.ts +55 -0
  330. package/dist/results/blame-format.d.ts.map +1 -0
  331. package/dist/results/cherry-pick-result.d.ts +10 -0
  332. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  333. package/dist/results/clone-result.d.ts +16 -0
  334. package/dist/results/clone-result.d.ts.map +1 -1
  335. package/dist/results/combined-diff.d.ts +77 -0
  336. package/dist/results/combined-diff.d.ts.map +1 -0
  337. package/dist/results/diff-entry.d.ts +32 -0
  338. package/dist/results/diff-entry.d.ts.map +1 -1
  339. package/dist/results/diff-formatter.d.ts +34 -60
  340. package/dist/results/diff-formatter.d.ts.map +1 -1
  341. package/dist/results/diff-order.d.ts +25 -0
  342. package/dist/results/diff-order.d.ts.map +1 -0
  343. package/dist/results/diff-output.d.ts +249 -0
  344. package/dist/results/diff-output.d.ts.map +1 -0
  345. package/dist/results/fetch-result.d.ts +24 -1
  346. package/dist/results/fetch-result.d.ts.map +1 -1
  347. package/dist/results/index.d.ts +5 -0
  348. package/dist/results/index.d.ts.map +1 -1
  349. package/dist/results/index.js +2 -252
  350. package/dist/results/merge-result.d.ts +15 -1
  351. package/dist/results/merge-result.d.ts.map +1 -1
  352. package/dist/results/pull-result.d.ts +12 -3
  353. package/dist/results/pull-result.d.ts.map +1 -1
  354. package/dist/results/push-result.d.ts +42 -0
  355. package/dist/results/push-result.d.ts.map +1 -1
  356. package/dist/results/quote-path.d.ts +27 -0
  357. package/dist/results/quote-path.d.ts.map +1 -0
  358. package/dist/results/rebase-result.d.ts +28 -1
  359. package/dist/results/rebase-result.d.ts.map +1 -1
  360. package/dist/results/revert-result.d.ts +10 -0
  361. package/dist/results/revert-result.d.ts.map +1 -1
  362. package/dist/results/stash-result.d.ts +5 -0
  363. package/dist/results/stash-result.d.ts.map +1 -1
  364. package/dist/results/status-result.d.ts +143 -18
  365. package/dist/results/status-result.d.ts.map +1 -1
  366. package/dist/results-BZGa2Z3I.js +2934 -0
  367. package/dist/transport-command.d.ts +56 -1
  368. package/dist/transport-command.d.ts.map +1 -1
  369. package/package.json +15 -10
  370. package/src/commands/add-command.ts +1291 -224
  371. package/src/commands/add-patch/add-interactive.ts +941 -0
  372. package/src/commands/add-patch/add-patch.ts +1169 -0
  373. package/src/commands/add-patch/index.ts +5 -0
  374. package/src/commands/add-patch/patch-backend.ts +239 -0
  375. package/src/commands/add-patch/patch-modes.ts +249 -0
  376. package/src/commands/add-patch/patch-session.ts +159 -0
  377. package/src/commands/am/am-command.ts +1111 -0
  378. package/src/commands/am/index.ts +2 -0
  379. package/src/commands/am/mailinfo.ts +1015 -0
  380. package/src/commands/am/patch-format.ts +121 -0
  381. package/src/commands/apply/apply-command.ts +832 -0
  382. package/src/commands/apply/apply-engine.ts +1603 -0
  383. package/src/commands/apply/apply-parse.ts +1209 -0
  384. package/src/commands/apply/apply-types.ts +112 -0
  385. package/src/commands/apply/index.ts +5 -0
  386. package/src/commands/apply/latin1.ts +171 -0
  387. package/src/commands/apply/whitespace.ts +260 -0
  388. package/src/commands/attributes-source.ts +96 -0
  389. package/src/commands/backfill-command.ts +694 -0
  390. package/src/commands/bisect/bisect-checkout.ts +217 -0
  391. package/src/commands/bisect/bisect-command.ts +788 -0
  392. package/src/commands/bisect/bisect-engine.ts +1079 -0
  393. package/src/commands/bisect/bisect-graph.ts +595 -0
  394. package/src/commands/bisect/bisect-quote.ts +92 -0
  395. package/src/commands/bisect/index.ts +4 -0
  396. package/src/commands/blame-command.ts +711 -986
  397. package/src/commands/branch-command.ts +354 -32
  398. package/src/commands/branch-tracking.ts +331 -0
  399. package/src/commands/checkout-command.ts +1426 -297
  400. package/src/commands/checkout-paths.ts +784 -0
  401. package/src/commands/cherry-pick-command.ts +156 -396
  402. package/src/commands/clean-command.ts +532 -85
  403. package/src/commands/clone-command.ts +826 -55
  404. package/src/commands/commit-command.ts +1781 -166
  405. package/src/commands/core-config.ts +196 -0
  406. package/src/commands/date-format.ts +668 -0
  407. package/src/commands/describe-command.ts +2 -0
  408. package/src/commands/diff-command.ts +1898 -110
  409. package/src/commands/diff-textconv.ts +50 -0
  410. package/src/commands/fetch-command.ts +1038 -79
  411. package/src/commands/format-patch-command.ts +969 -0
  412. package/src/commands/fsck/fetch-fsck.ts +229 -0
  413. package/src/commands/fsck/fsck-command.ts +3347 -0
  414. package/src/commands/fsck/fsck-loose.ts +287 -0
  415. package/src/commands/fsck/fsck-msg-ids.ts +176 -0
  416. package/src/commands/fsck/fsck-object-checks.ts +1044 -0
  417. package/src/commands/fsck/fsck-object-table.ts +363 -0
  418. package/src/commands/fsck/fsck-pack.ts +604 -0
  419. package/src/commands/fsck/index.ts +5 -0
  420. package/src/commands/fsck/verify-pack-command.ts +249 -0
  421. package/src/commands/gc-command.ts +147 -1
  422. package/src/commands/git-date.ts +895 -0
  423. package/src/commands/git-describe.ts +316 -0
  424. package/src/commands/git-hooks.ts +1472 -0
  425. package/src/commands/git-ident.ts +344 -0
  426. package/src/commands/hook-command.ts +247 -0
  427. package/src/commands/index-adder.ts +706 -0
  428. package/src/commands/index-host.ts +291 -0
  429. package/src/commands/index.ts +83 -0
  430. package/src/commands/init-command.ts +60 -11
  431. package/src/commands/local-clone.ts +183 -0
  432. package/src/commands/local-transport.ts +762 -0
  433. package/src/commands/log-command.ts +1915 -170
  434. package/src/commands/log-graph.ts +671 -0
  435. package/src/commands/log-output.ts +1359 -0
  436. package/src/commands/ls-remote-command.ts +101 -58
  437. package/src/commands/mailmap.ts +129 -0
  438. package/src/commands/merge-bases.ts +296 -0
  439. package/src/commands/merge-command.ts +1386 -491
  440. package/src/commands/merge-config.ts +25 -0
  441. package/src/commands/merge-drivers.ts +306 -0
  442. package/src/commands/merge-support.ts +1198 -0
  443. package/src/commands/message-cleanup.ts +275 -0
  444. package/src/commands/mv-command.ts +976 -0
  445. package/src/commands/notes-command.ts +890 -0
  446. package/src/commands/notes-commands.ts +87 -0
  447. package/src/commands/notes-merge-command.ts +768 -0
  448. package/src/commands/notes-support.ts +402 -0
  449. package/src/commands/notes-tree.ts +602 -0
  450. package/src/commands/object-id-input.ts +27 -0
  451. package/src/commands/octopus-merge.ts +377 -0
  452. package/src/commands/ort-merge.ts +1660 -0
  453. package/src/commands/ort-recursive.ts +160 -0
  454. package/src/commands/pack-refs-command.ts +39 -22
  455. package/src/commands/patch-id.ts +196 -0
  456. package/src/commands/pathspec-attributes.ts +162 -0
  457. package/src/commands/pathspec.ts +1199 -0
  458. package/src/commands/post-index-change.ts +62 -0
  459. package/src/commands/pretty-format.ts +1431 -0
  460. package/src/commands/promisor-remote.ts +298 -0
  461. package/src/commands/pull-command.ts +207 -22
  462. package/src/commands/push-command.ts +236 -23
  463. package/src/commands/read-tree-command.ts +857 -0
  464. package/src/commands/rebase-command.ts +3808 -371
  465. package/src/commands/rebase-todo.ts +584 -0
  466. package/src/commands/ref-decoration-filter.ts +118 -0
  467. package/src/commands/reflog-messages.ts +177 -0
  468. package/src/commands/remote-command.ts +500 -19
  469. package/src/commands/remote-transport.ts +383 -0
  470. package/src/commands/reset-command.ts +828 -91
  471. package/src/commands/restore-command.ts +350 -0
  472. package/src/commands/rev-list-command.ts +167 -0
  473. package/src/commands/rev-parse-command.ts +277 -0
  474. package/src/commands/revert-command.ts +152 -399
  475. package/src/commands/revision-filenames.ts +254 -0
  476. package/src/commands/revision-range.ts +222 -0
  477. package/src/commands/revision-resolver.ts +1379 -0
  478. package/src/commands/rm-command.ts +613 -67
  479. package/src/commands/sequencer-pick.ts +869 -0
  480. package/src/commands/sequencer-support.ts +869 -0
  481. package/src/commands/serve-repository.ts +125 -0
  482. package/src/commands/sparse-checkout-command.ts +1389 -0
  483. package/src/commands/sparse-checkout-support.ts +793 -0
  484. package/src/commands/stash-apply-command.ts +692 -124
  485. package/src/commands/stash-create-command.ts +752 -89
  486. package/src/commands/stash-drop-command.ts +67 -6
  487. package/src/commands/stash-list-command.ts +10 -4
  488. package/src/commands/stash-working-tree.ts +387 -0
  489. package/src/commands/status-command.ts +1426 -97
  490. package/src/commands/status-format.ts +775 -0
  491. package/src/commands/status-header.ts +330 -0
  492. package/src/commands/strerror.ts +29 -0
  493. package/src/commands/submodule-config.ts +94 -0
  494. package/src/commands/submodule-summary-command.ts +334 -0
  495. package/src/commands/submodule-summary.ts +446 -0
  496. package/src/commands/switch-command.ts +402 -0
  497. package/src/commands/tag-command.ts +129 -41
  498. package/src/commands/tracking-info.ts +201 -0
  499. package/src/commands/trailers.ts +417 -0
  500. package/src/commands/tree-restore.ts +344 -15
  501. package/src/commands/untracked-cache-support.ts +194 -0
  502. package/src/commands/worktree-add-command.ts +458 -0
  503. package/src/commands/worktree-list-command.ts +208 -0
  504. package/src/commands/worktree-lock-command.ts +96 -0
  505. package/src/commands/worktree-overwrite-checks.ts +641 -0
  506. package/src/commands/worktree-prune-command.ts +99 -0
  507. package/src/commands/worktree-remove-command.ts +186 -0
  508. package/src/commands/worktree-repair-command.ts +59 -0
  509. package/src/commands/worktree-support.ts +214 -0
  510. package/src/core-commands/add.command.impl.ts +9 -5
  511. package/src/core-commands/index.ts +0 -8
  512. package/src/errors/add-errors.ts +45 -0
  513. package/src/errors/checkout-errors.ts +46 -2
  514. package/src/errors/command-errors.ts +101 -1
  515. package/src/errors/commit-errors.ts +18 -2
  516. package/src/errors/git-api-error.ts +82 -2
  517. package/src/errors/index.ts +1 -0
  518. package/src/errors/merge-errors.ts +2 -2
  519. package/src/errors/rebase-errors.ts +12 -0
  520. package/src/errors/ref-errors.ts +56 -2
  521. package/src/errors/remote-errors.ts +2 -2
  522. package/src/errors/stash-errors.ts +1 -1
  523. package/src/errors/transport-errors.ts +20 -4
  524. package/src/errors/worktree-errors.ts +49 -0
  525. package/src/git-command.ts +1218 -118
  526. package/src/git.ts +552 -11
  527. package/src/index.ts +1 -1
  528. package/src/remote-config/index.ts +1 -0
  529. package/src/remote-config/remote-config-store.ts +326 -16
  530. package/src/remote-config/remote-refs.ts +119 -0
  531. package/src/rename/detect-renames.ts +711 -0
  532. package/src/rename/git-similarity.ts +116 -0
  533. package/src/rename/index.ts +2 -0
  534. package/src/results/binary-patch.ts +401 -0
  535. package/src/results/blame-format.ts +239 -0
  536. package/src/results/cherry-pick-result.ts +10 -0
  537. package/src/results/clone-result.ts +18 -0
  538. package/src/results/combined-diff.ts +585 -0
  539. package/src/results/diff-entry.ts +35 -0
  540. package/src/results/diff-formatter.ts +152 -288
  541. package/src/results/diff-order.ts +64 -0
  542. package/src/results/diff-output.ts +1051 -0
  543. package/src/results/fetch-result.ts +24 -1
  544. package/src/results/index.ts +5 -0
  545. package/src/results/merge-result.ts +15 -1
  546. package/src/results/pull-result.ts +12 -3
  547. package/src/results/push-result.ts +43 -0
  548. package/src/results/quote-path.ts +103 -0
  549. package/src/results/rebase-result.ts +37 -0
  550. package/src/results/revert-result.ts +10 -0
  551. package/src/results/stash-result.ts +6 -0
  552. package/src/results/status-result.ts +288 -27
  553. package/src/transport-command.ts +139 -2
  554. package/dist/commands-BpeXZTC3.js +0 -10278
  555. package/dist/core-commands/checkout.command.d.ts +0 -103
  556. package/dist/core-commands/checkout.command.d.ts.map +0 -1
  557. package/dist/core-commands/checkout.command.impl.d.ts +0 -110
  558. package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
  559. package/dist/status-result-BapZoQaR.js +0 -411
  560. package/src/core-commands/checkout.command.impl.ts +0 -564
  561. package/src/core-commands/checkout.command.ts +0 -125
@@ -1,6 +1,91 @@
1
- import type { Commit, ObjectId } from "@statewalker/vcs-core";
1
+ import {
2
+ type BloomFilterSettings,
3
+ bloomFilterContains,
4
+ bloomKey,
5
+ type Commit,
6
+ type CommitGraph,
7
+ canonTreeMode,
8
+ commitFromBytes,
9
+ EMPTY_TREE_ID,
10
+ type GitObject,
11
+ type ObjectId,
12
+ type ObjectReplacements,
13
+ parseGraphCommit,
14
+ replacementOf,
15
+ } from "@statewalker/vcs-core";
16
+ import { ByteSink, OrderedMap, parseGitBool, type XdiffAlgorithm } from "@statewalker/vcs-utils";
17
+ import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
18
+ import { bytesToHex, hexToBytes } from "@statewalker/vcs-utils/hash/utils";
2
19
 
20
+ import {
21
+ type AttributesResolver,
22
+ type ContentAttributesContext,
23
+ expandUserPath,
24
+ } from "@statewalker/vcs-working-tree";
25
+
26
+ import { GitApiError, IncompatibleOptionsError } from "../errors/index.js";
3
27
  import { GitCommand } from "../git-command.js";
28
+ import { RemoteConfigStore } from "../remote-config/index.js";
29
+ import { type CombinedDiffOptions, writeCombinedDiff } from "../results/combined-diff.js";
30
+ import { quotePath } from "../results/quote-path.js";
31
+ import { bareAttributesResolver } from "./attributes-source.js";
32
+ import { DiffCommand, type DiffTextOptions } from "./diff-command.js";
33
+ import { hostEnvironmentOf } from "./git-ident.js";
34
+ import {
35
+ type LogOutputEntry,
36
+ type LogOutputHost,
37
+ type LogOutputOptions,
38
+ LogPrinter,
39
+ } from "./log-output.js";
40
+ import { Mailmap } from "./mailmap.js";
41
+ import { configBool, configValue } from "./merge-config.js";
42
+ import {
43
+ addRefsByGlob,
44
+ addRefsFromColonSep,
45
+ defaultNotesRef,
46
+ expandNotesRef,
47
+ initNotes,
48
+ type NotesHandle,
49
+ notesEnvironmentOf,
50
+ } from "./notes-support.js";
51
+ import { combineNotesIgnore } from "./notes-tree.js";
52
+ import { canonicalObjectId } from "./object-id-input.js";
53
+ import {
54
+ ALL_ENTRIES_NOT_INTERESTING,
55
+ bloomPathOf,
56
+ ENTRY_NOT_INTERESTING,
57
+ matchPathspec,
58
+ NEED_ATTRIBUTES,
59
+ type PathspecAttributeValue,
60
+ type PathspecItem,
61
+ parsePathspecItem,
62
+ pathspecForbidsBloom,
63
+ type TreePathspec,
64
+ treeEntryInteresting,
65
+ treePathspec,
66
+ } from "./pathspec.js";
67
+ import { PathspecAttributes } from "./pathspec-attributes.js";
68
+ import { loadRefDecorations } from "./pretty-format.js";
69
+ import { readDiffSubmoduleConfig } from "./submodule-summary.js";
70
+
71
+ const NULL_OBJECT_ID = "0".repeat(40);
72
+
73
+ /** What {@link LogCommand.callBytes} asks of the walk. */
74
+ interface OutputWalk {
75
+ /** `--topo-order` (and `--graph`) */
76
+ topo: boolean;
77
+ /** `--graph`: parents rewritten past the commits not shown */
78
+ rewrite: boolean;
79
+ entries: LogOutputEntry[];
80
+ /**
81
+ * Parents the walk never reached (`--first-parent` walks only first parents) that git's
82
+ * get_commit_action would show: the graph counts them as interesting
83
+ */
84
+ unwalkedShown?: Set<ObjectId>;
85
+ }
86
+
87
+ /** git log reads no index: the in-tree attributes files are the worktree's only. */
88
+ const NO_INDEX = { attributesBlob: () => undefined };
4
89
 
5
90
  /**
6
91
  * Result of a log command iteration.
@@ -12,6 +97,30 @@ export interface LogResult extends Commit {
12
97
  id: ObjectId;
13
98
  }
14
99
 
100
+ /**
101
+ * What a path-limited walk did (git's trace2 `bloom` statistics, and the tree work behind
102
+ * them): how often the changed-path filters answered, and how many tree entries the walk read
103
+ * to compare commits with their parents.
104
+ */
105
+ export interface LogPathStatistics {
106
+ /** Comparisons a filter settled: the paths certainly did not change */
107
+ bloomDefinitelyNot: number;
108
+ /** Comparisons where a filter said the paths may have changed (trees compared then) */
109
+ bloomMaybe: number;
110
+ /** Of `bloomMaybe`, those where the trees did not differ */
111
+ bloomFalsePositive: number;
112
+ /** Comparisons of commits the graph has without a filter (its layer has none) */
113
+ bloomNotPresent: number;
114
+ /** Comparisons of a commit's trees with a parent's (or the empty tree), at the paths */
115
+ treeComparisons: number;
116
+ /** Tree entries looked up for those comparisons (each reads its tree, or finds it cached) */
117
+ treeEntryReads: number;
118
+ /** Commits the walk met (parsed, or seen as a parent) */
119
+ commitsWalked?: number;
120
+ /** Bytes the walk's table of commits takes (a few dozen per commit met) */
121
+ walkTableBytes?: number;
122
+ }
123
+
15
124
  /**
16
125
  * Revision filter for LogCommand.
17
126
  *
@@ -82,36 +191,61 @@ export enum RevFilter {
82
191
  */
83
192
  export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
84
193
  private startCommits: ObjectId[] = [];
85
- private excludeCommits: ObjectId[] = [];
194
+ /** The commits given, included and excluded, in the order given (git's pending list) */
195
+ private readonly pending: { id: ObjectId; exclude: boolean }[] = [];
86
196
  private paths: string[] = [];
87
197
  private excludePaths: string[] = [];
88
198
  private maxCount?: number;
89
199
  private skip = 0;
90
200
  private includeAll = false;
201
+ /** Where `all()` puts the refs among the commits given (git's command-line order) */
202
+ private allAt = 0;
91
203
  private firstParentOnly = false;
204
+ /** git's `simplify_history`: off with `--full-history` (and `-m`, `--diff-merges=separate`) */
205
+ private simplifyHistory = true;
92
206
  private sinceTime?: number;
93
207
  private untilTime?: number;
94
208
  private authorPattern?: string;
95
209
  private committerPattern?: string;
96
210
  private revFilter = RevFilter.ALL;
211
+ private useBloomFilters = true;
212
+ private readonly statistics: LogPathStatistics = {
213
+ bloomDefinitelyNot: 0,
214
+ bloomMaybe: 0,
215
+ bloomFalsePositive: 0,
216
+ bloomNotPresent: 0,
217
+ treeComparisons: 0,
218
+ treeEntryReads: 0,
219
+ };
220
+ /** The commits of the last walk (for its statistics). */
221
+ private lastWalk: RevTable | undefined;
222
+ /** Set while {@link callBytes} collects the walk for its output */
223
+ private outputWalk: OutputWalk | undefined;
97
224
 
98
225
  /**
99
226
  * Add a starting commit for the log.
100
227
  *
101
228
  * Multiple start commits can be added - the log will include
102
- * ancestors of all of them.
229
+ * ancestors of all of them. An annotated tag is walked from the commit it tags, as git
230
+ * peels it; with {@link all} the refs are walked besides (`git log --all <commit>`).
103
231
  *
104
232
  * @param commit ObjectId of commit to start from
105
233
  */
106
234
  add(commit: ObjectId): this {
107
235
  this.checkCallable();
108
236
  this.startCommits.push(commit);
237
+ this.pending.push({ id: commit, exclude: false });
109
238
  return this;
110
239
  }
111
240
 
112
241
  /**
113
242
  * Filter commits to only those affecting the given path.
114
243
  *
244
+ * The path is a git pathspec element, as `git log -- <path>` reads it: a path from the top
245
+ * of the repository (a directory names everything below it), with wildcards (`*`, `?`,
246
+ * `[...]`, matched as git's `git_fnmatch` does) and magic (`:(glob)`, `:(literal)`,
247
+ * `:(icase)`, `:(exclude)` or `:!`).
248
+ *
115
249
  * @param path Repository-relative path to filter by
116
250
  */
117
251
  addPath(path: string): this {
@@ -123,7 +257,9 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
123
257
  /**
124
258
  * Exclude commits that only affect the given path.
125
259
  *
126
- * If a path is both added and excluded, the exclusion wins.
260
+ * The path is an `:(exclude)` pathspec element (`git log -- . ':!<path>'`): changes below
261
+ * it do not count when commits are compared with their parents. If a path is both added
262
+ * and excluded, the exclusion wins.
127
263
  *
128
264
  * @param path Repository-relative path to exclude
129
265
  */
@@ -156,13 +292,29 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
156
292
  }
157
293
 
158
294
  /**
159
- * Include commits from all refs.
295
+ * Include commits from all refs (`--all`): every ref under `refs/` in name order, then HEAD,
296
+ * as git's handle_refs adds them, where the call stands among {@link add}, {@link not} and
297
+ * {@link addRange} (the commits given so far come first).
160
298
  *
161
299
  * When set, starts from all refs instead of just HEAD.
162
300
  */
163
301
  all(): this {
164
302
  this.checkCallable();
165
303
  this.includeAll = true;
304
+ this.allAt = this.pending.length;
305
+ return this;
306
+ }
307
+
308
+ /**
309
+ * `--full-history`: a path-limited walk compares a merge with every parent and walks them
310
+ * all, even one the merge matches at the paths (git's `simplify_history` off; `git log -m`
311
+ * and `--diff-merges=separate` turn it off as well). Merges that match every relevant parent
312
+ * are still not shown, unless the output rewrites parents (`--graph`) and two of them are
313
+ * relevant.
314
+ */
315
+ setFullHistory(fullHistory: boolean): this {
316
+ this.checkCallable();
317
+ this.simplifyHistory = !fullHistory;
166
318
  return this;
167
319
  }
168
320
 
@@ -187,7 +339,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
187
339
  */
188
340
  not(commit: ObjectId): this {
189
341
  this.checkCallable();
190
- this.excludeCommits.push(commit);
342
+ this.pending.push({ id: commit, exclude: true });
191
343
  return this;
192
344
  }
193
345
 
@@ -260,6 +412,25 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
260
412
  return this;
261
413
  }
262
414
 
415
+ /**
416
+ * Whether a path-limited walk asks the commit-graph's changed-path Bloom filters before it
417
+ * compares trees (default true, as git does whenever the graph has filters).
418
+ */
419
+ setUseBloomFilters(use: boolean): this {
420
+ this.checkCallable();
421
+ this.useBloomFilters = use;
422
+ return this;
423
+ }
424
+
425
+ /** What the path-limited walk did so far (see {@link LogPathStatistics}). */
426
+ getStatistics(): LogPathStatistics {
427
+ return {
428
+ ...this.statistics,
429
+ commitsWalked: this.lastWalk?.size ?? 0,
430
+ walkTableBytes: this.lastWalk?.bytes ?? 0,
431
+ };
432
+ }
433
+
263
434
  /**
264
435
  * Add a commit range.
265
436
  *
@@ -270,9 +441,11 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
270
441
  * @param until Commits reachable from here are included (start point)
271
442
  */
272
443
  addRange(since: ObjectId, until: ObjectId): this {
444
+ since = canonicalObjectId(since);
445
+ until = canonicalObjectId(until);
273
446
  this.checkCallable();
274
- this.excludeCommits.push(since);
275
447
  this.startCommits.push(until);
448
+ this.pending.push({ id: since, exclude: true }, { id: until, exclude: false });
276
449
  return this;
277
450
  }
278
451
 
@@ -284,266 +457,1838 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
284
457
  async call(): Promise<AsyncIterable<LogResult>> {
285
458
  this.checkCallable();
286
459
  this.setCallable(false);
460
+ // git_log_config ends in git_diff_ui_config: a diff.submodule without a value dies
461
+ readDiffSubmoduleConfig(this.workingCopy);
287
462
 
288
- // Determine starting commits
289
- let starts: ObjectId[];
290
- if (this.startCommits.length > 0) {
291
- starts = this.startCommits;
292
- } else if (this.includeAll) {
293
- starts = await this.getAllRefs();
294
- } else {
295
- const headId = await this.resolveHead();
296
- starts = [headId];
463
+ // the commits given, in order, the refs of `all()` where it was called; HEAD without
464
+ // either
465
+ const pending: { id: ObjectId; exclude: boolean }[] = [];
466
+ for (let i = 0; i <= this.pending.length; i++) {
467
+ if (this.includeAll && i === this.allAt) {
468
+ for (const id of await this.getAllRefs()) pending.push({ id, exclude: false });
469
+ }
470
+ const e = this.pending[i];
471
+ if (e) pending.push({ id: await this.peelToCommit(e.id), exclude: e.exclude });
472
+ }
473
+ if (this.startCommits.length === 0 && !this.includeAll) {
474
+ pending.push({ id: await this.resolveHead(), exclude: false });
297
475
  }
476
+ return this.walk(pending);
477
+ }
298
478
 
299
- return this.walkCommits(starts);
479
+ /** The commit an annotated tag (or a chain of them) tags; any other id as it is. */
480
+ private async peelToCommit(start: ObjectId): Promise<ObjectId> {
481
+ const tags = this.tagsStore;
482
+ let id = start;
483
+ for (let depth = 0; depth < 32 && tags && (await tags.has(id).catch(() => false)); depth++) {
484
+ const tag = await tags.load(id).catch(() => undefined);
485
+ if (!tag) break;
486
+ id = tag.object;
487
+ }
488
+ return id;
300
489
  }
301
490
 
302
491
  /**
303
- * Get all commit IDs from all refs.
492
+ * The commits of `--all` (revision.c's handle_refs): each ref under `refs/` in name order
493
+ * (refs_for_each_ref, symbolic ones resolved), then HEAD (refs_head_ref); annotated tags
494
+ * peeled.
304
495
  */
305
496
  private async getAllRefs(): Promise<ObjectId[]> {
306
- const ids: ObjectId[] = [];
497
+ const named: { name: Uint8Array; id: ObjectId }[] = [];
307
498
  for await (const ref of this.refsStore.list()) {
308
- if ("objectId" in ref && ref.objectId) {
309
- ids.push(ref.objectId);
310
- }
499
+ if (!ref.name.startsWith("refs/")) continue;
500
+ let id = "objectId" in ref ? ref.objectId : undefined;
501
+ if (!id) id = (await this.refsStore.resolve(ref.name).catch(() => undefined))?.objectId;
502
+ if (id) named.push({ name: encodeGitPath(ref.name), id });
311
503
  }
504
+ named.sort((a, b) => compareBytes(a.name, b.name));
505
+ const ids: ObjectId[] = [];
506
+ for (const { id } of named) ids.push(await this.peelToCommit(id));
507
+ const head = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
508
+ if (head) ids.push(await this.peelToCommit(head));
312
509
  return ids;
313
510
  }
314
511
 
315
512
  /**
316
- * Walk commits and yield them.
513
+ * The walk of `git log`, ported from git's revision.c. Commits come out newest first by
514
+ * committer date (equal dates in the order they were queued). With a pathspec, history is
515
+ * simplified as try_to_simplify_commit does it: a commit is compared with each parent at the
516
+ * paths; one that matches a relevant parent ("TREESAME") is not shown, and only that parent
517
+ * is walked further. A root commit is shown when it has any of the paths. Before comparing a
518
+ * commit with its first parent, the commit-graph's changed-path Bloom filter of the commit
519
+ * is asked (check_maybe_different_in_bloom_filter): when it says no path changed, no tree is
520
+ * read. Without a pathspec nothing is simplified (git's `revs->prune` is off).
521
+ *
522
+ * Without excluded commits the walk streams (get_revision_1). With some (`not`,
523
+ * `addRange`), it is limited first as limit_list does it: one date-ordered queue holds the
524
+ * included and the excluded commits, UNINTERESTING spreads to parents as commits are
525
+ * taken, a commit's relevance is judged with what is marked so far, `--since` marks older
526
+ * commits UNINTERESTING, and the walk stops once only uninteresting commits are left
527
+ * (still_interesting); what is shown is filtered by the final marks.
528
+ *
529
+ * The commits met are held in a `RevTable` (typed arrays, a few dozen bytes each); commits
530
+ * the commit-graph has are reached by their graph positions, without building their ids.
317
531
  */
318
- private async *walkCommits(starts: ObjectId[]): AsyncIterable<LogResult> {
319
- let count = 0;
320
- let skipped = 0;
321
-
322
- // Build set of excluded commits (including their ancestors)
323
- const excludedSet = await this.buildExcludedSet();
532
+ private async *walk(pending: { id: ObjectId; exclude: boolean }[]): AsyncIterable<LogResult> {
533
+ const prune = this.paths.length > 0 || this.excludePaths.length > 0;
534
+ // a shallow commit has no parents (git's shallow grafts); the graph is off then
535
+ const shallowIds = (await this.refsStore.getShallow?.().catch(() => undefined)) ?? [];
536
+ const shallow = new Set(shallowIds);
537
+ // replace refs and grafts (git's parse_commit applies both; no commit-graph then)
538
+ const replacements = await this.objectReplacements();
539
+ this.markReplacementsRead();
540
+ // trees compared for paths read through replace refs too (read_object_file)
541
+ this.treeReplacements = replacements?.replace.size ? replacements.replace : undefined;
542
+ const graph =
543
+ shallow.size > 0 || replacements
544
+ ? undefined
545
+ : await this.commits.commitGraph?.get().catch(() => undefined);
546
+ const pathspec = prune ? this.pathspec() : undefined;
547
+ const bloom =
548
+ pathspec && this.useBloomFilters ? this.bloomKeys(graph, pathspec.items) : undefined;
549
+ const bloomVersion = bloom ? this.changedPathsVersion() : -1;
550
+ const fast = pathspec?.literal;
551
+ const firstParentOnly = this.firstParentOnly;
552
+ const simplifyHistory = this.simplifyHistory;
553
+ /**
554
+ * Each merge's TREESAME to each parent (git's `treesame` decoration), kept when limiting
555
+ * can make it TREESAME later (limiting_can_increase_treesame: full history, a limited walk)
556
+ */
557
+ const treesame = new Map<number, Uint8Array>();
558
+ let trackTreesame = false;
559
+ const t = new RevTable(graph);
560
+ this.lastWalk = t;
561
+ /** Raw commits read by `parse` (no graph), kept until shown: read once, not twice. */
562
+ const raw = new Map<number, Uint8Array>();
324
563
 
325
- for await (const commitId of this.commits.walkAncestry(starts, {
326
- firstParentOnly: this.firstParentOnly,
327
- })) {
328
- // Skip excluded commits
329
- if (excludedSet.has(commitId)) {
330
- continue;
564
+ /** git's parse_commit: tree, parents and date, from the graph when it has the commit */
565
+ const parse = async (n: number): Promise<boolean> => {
566
+ if (t.parsed(n)) return true;
567
+ const gpos = t.gpos[n] as number;
568
+ if (graph && gpos >= 0) {
569
+ let parents: number[] | undefined;
570
+ let date = 0;
571
+ try {
572
+ date = graph.commitTimeAt(gpos);
573
+ parents = graph.parentPositionsAt(gpos);
574
+ } catch {
575
+ // a corrupt record: the commit is read instead
576
+ parents = undefined;
577
+ }
578
+ if (parents) {
579
+ t.setParsed(n, date, true, undefined, parents.length);
580
+ for (let k = 0; k < parents.length; k++)
581
+ t.setParent(n, k, t.lookupPos(parents[k] as number));
582
+ return true;
583
+ }
584
+ }
585
+ const id = t.idOf(n);
586
+ const header = await this.readCommitHeader(id, replacements);
587
+ if (!header) return false;
588
+ const parents = shallow.has(id) ? [] : header.parents;
589
+ t.setParsed(n, header.date, false, header.tree, parents.length);
590
+ for (let k = 0; k < parents.length; k++) t.setParent(n, k, t.lookup(parents[k] as ObjectId));
591
+ if (header.raw) raw.set(n, header.raw);
592
+ return true;
593
+ };
594
+ const relevant = (n: number) => (t.flag(n) & (UNINTERESTING | BOTTOM)) !== UNINTERESTING;
595
+ /** git's mark_parents_uninteresting: through the parents known (parsed) so far */
596
+ const markParentsUninteresting = (n: number): void => {
597
+ const stack: number[] = [];
598
+ const markOne = (p: number) => {
599
+ if (t.flag(p) & UNINTERESTING) return;
600
+ t.mark(p, UNINTERESTING);
601
+ for (let k = 0, c = t.parentCount(p); k < c; k++) stack.push(t.parent(p, k));
602
+ };
603
+ for (let k = 0, c = t.parentCount(n); k < c; k++) markOne(t.parent(n, k));
604
+ for (let p = stack.pop(); p !== undefined; p = stack.pop()) markOne(p);
605
+ };
606
+ const differs = (from: ObjectId | undefined, n: number, nth: number) =>
607
+ this.differsAtPaths(
608
+ from,
609
+ t.treeOf(n),
610
+ pathspec as TreePathspec,
611
+ fast,
612
+ nth === 0 ? bloom : undefined,
613
+ bloomVersion,
614
+ graph,
615
+ t.bloomPos(n),
616
+ );
617
+ /** git's try_to_simplify_commit (prune, dense, no show_pulls) */
618
+ const simplify = async (n: number): Promise<void> => {
619
+ if (!prune) return;
620
+ const count = t.parentCount(n);
621
+ if (count === 0) {
622
+ if (!(await differs(undefined, n, 0))) t.mark(n, TREESAME);
623
+ return;
331
624
  }
625
+ let relevantParents = 0;
626
+ let relevantChange = false;
627
+ let irrelevantChange = false;
628
+ let ts: Uint8Array | undefined;
629
+ for (let nth = 0; nth < count; nth++) {
630
+ const p = t.parent(n, nth);
631
+ if (relevant(p)) relevantParents++;
632
+ if (nth === 1) {
633
+ if (firstParentOnly) break;
634
+ if (trackTreesame && !(t.flag(n) & UNINTERESTING)) {
635
+ ts = new Uint8Array(count);
636
+ treesame.set(n, ts);
637
+ if (!(irrelevantChange || relevantChange)) ts[0] = 1;
638
+ }
639
+ }
640
+ if (!(await parse(p))) {
641
+ throw new GitApiError(`cannot simplify commit ${t.idOf(n)} (because of ${t.idOf(p)})`);
642
+ }
643
+ if (!(await differs(t.treeOf(p), n, nth))) {
644
+ // a merge with an irrelevant side that brought the whole change keeps its others;
645
+ // with the full history, every parent is kept
646
+ if (!simplifyHistory || !relevant(p)) {
647
+ if (ts) ts[nth] = 1;
648
+ continue;
649
+ }
650
+ t.keepOnlyParent(n, p);
651
+ t.mark(n, TREESAME);
652
+ return;
653
+ }
654
+ if (relevant(p)) relevantChange = true;
655
+ else irrelevantChange = true;
656
+ }
657
+ if (relevantParents ? !relevantChange : !irrelevantChange) t.mark(n, TREESAME);
658
+ };
659
+ /** git's process_parents */
660
+ const processParents = async (n: number, queue: CommitQueue<number>): Promise<void> => {
661
+ if (t.flag(n) & ADDED) return;
662
+ t.mark(n, ADDED);
663
+ if (t.flag(n) & UNINTERESTING) {
664
+ for (let k = 0, c = t.parentCount(n); k < c; k++) {
665
+ const p = t.parent(n, k);
666
+ t.mark(p, UNINTERESTING);
667
+ if (!(await parse(p))) continue;
668
+ if (t.parentCount(p) > 0) markParentsUninteresting(p);
669
+ if (t.flag(p) & SEEN) continue;
670
+ t.mark(p, SEEN);
671
+ queue.put(p, t.date(p));
672
+ }
673
+ return;
674
+ }
675
+ await simplify(n);
676
+ for (let k = 0, c = t.parentCount(n); k < c; k++) {
677
+ const p = t.parent(n, k);
678
+ if (!(await parse(p))) {
679
+ throw new GitApiError(`Failed to traverse parents of commit ${t.idOf(n)}`);
680
+ }
681
+ if (!(t.flag(p) & SEEN)) {
682
+ t.mark(p, SEEN);
683
+ queue.put(p, t.date(p));
684
+ }
685
+ if (firstParentOnly) break;
686
+ }
687
+ };
688
+ /** git's get_commit_action (no parent rewriting: TREESAME commits are never shown) */
689
+ const shown = async (n: number, rewrite = false): Promise<LogResult | undefined> => {
690
+ const bytes = raw.get(n);
691
+ if (bytes) raw.delete(n);
692
+ if (t.flag(n) & UNINTERESTING) return undefined;
693
+ if (t.flag(n) & TREESAME) {
694
+ // with parents rewritten, a merge of two relevant lines ties the topology together
695
+ if (!rewrite) return undefined;
696
+ let relevantParents = 0;
697
+ for (let k = 0, c = t.parentCount(n); k < c; k++)
698
+ if (relevant(t.parent(n, k))) relevantParents++;
699
+ if (relevantParents < 2) return undefined;
700
+ }
701
+ if (this.untilTime !== undefined && t.date(n) > this.untilTime) return undefined;
702
+ const parents = t.parentCount(n);
703
+ if (this.revFilter === RevFilter.ONLY_MERGES && parents < 2) return undefined;
704
+ if (this.revFilter === RevFilter.NO_MERGES && parents > 1) return undefined;
705
+ const id = t.idOf(n);
706
+ const commit = bytes ? decodeCommit(bytes) : await this.walkCommits.load(id);
707
+ if (!commit) return undefined;
708
+ const grafted = bytes ? replacements?.grafts.get(id) : undefined;
709
+ if (grafted) commit.parents = [...grafted];
710
+ // a shallow commit is shown without parents (its diff against the empty tree)
711
+ if (shallow.has(id)) commit.parents = [];
712
+ if (this.authorPattern !== undefined && !this.matchesAuthor(commit)) return undefined;
713
+ if (this.committerPattern !== undefined && !this.matchesCommitter(commit)) return undefined;
714
+ return { ...commit, id };
715
+ };
332
716
 
333
- const commit = await this.commits.load(commitId);
334
- if (!commit) {
335
- continue;
717
+ // prepare_revision_walk: the flags of every argument first, then handle_commit in order
718
+ for (const e of pending) {
719
+ if (!e.exclude) continue;
720
+ const n = t.lookup(e.id);
721
+ t.mark(n, UNINTERESTING | BOTTOM);
722
+ }
723
+ const list: number[] = [];
724
+ let limited = false;
725
+ /** git's update_treesame: TREESAME again from the per-parent marks, relevance as it is now */
726
+ const updateTreesame = (n: number): void => {
727
+ const count = t.parentCount(n);
728
+ const st = treesame.get(n);
729
+ if (count < 2 || !st) return;
730
+ let relevantParents = 0;
731
+ let relevantChange = false;
732
+ let irrelevantChange = false;
733
+ for (let k = 0; k < count; k++) {
734
+ if (relevant(t.parent(n, k))) {
735
+ relevantChange ||= !st[k];
736
+ relevantParents++;
737
+ } else irrelevantChange ||= !st[k];
738
+ }
739
+ if (relevantParents ? relevantChange : irrelevantChange) t.unmark(n, TREESAME);
740
+ else t.mark(n, TREESAME);
741
+ };
742
+ for (const e of pending) {
743
+ const n = t.lookup(e.id);
744
+ if (!(await parse(n))) continue;
745
+ if (t.flag(n) & UNINTERESTING) {
746
+ markParentsUninteresting(n);
747
+ limited = true;
336
748
  }
749
+ if (!(t.flag(n) & SEEN)) {
750
+ t.mark(n, SEEN);
751
+ list.push(n);
752
+ }
753
+ }
754
+ // commit_list_sort_by_date (stable), then into the date queue in that order
755
+ list.sort((a, b) => t.date(b) - t.date(a));
756
+ const queue = new CommitQueue<number>();
757
+ for (const n of list) queue.put(n, t.date(n));
337
758
 
338
- // RevFilter - ONLY_MERGES or NO_MERGES
339
- if (this.revFilter === RevFilter.ONLY_MERGES) {
340
- // Only include merge commits (more than one parent)
341
- if (commit.parents.length <= 1) {
759
+ let count = 0;
760
+ let skipped = 0;
761
+ // git's -n 0 reads nothing more in a streaming walk; a limited walk is done before
762
+ const none = this.maxCount !== undefined && this.maxCount <= 0;
763
+ const output = this.outputWalk;
764
+ // the output's walk is limited (git without generation numbers limits a topo walk)
765
+ trackTreesame = (limited || !!output) && prune && !simplifyHistory && !firstParentOnly;
766
+ if (!limited && !output) {
767
+ if (none) return;
768
+ // get_revision_1, streaming
769
+ for (let n = queue.get(); n !== undefined; n = queue.get()) {
770
+ // --since: older commits are dropped without walking their parents (max_age)
771
+ if (this.sinceTime !== undefined && t.date(n) < this.sinceTime) {
772
+ raw.delete(n);
342
773
  continue;
343
774
  }
344
- } else if (this.revFilter === RevFilter.NO_MERGES) {
345
- // Exclude merge commits
346
- if (commit.parents.length > 1) {
775
+ await processParents(n, queue);
776
+ const commit = await shown(n);
777
+ if (!commit) continue;
778
+ if (skipped < this.skip) {
779
+ skipped++;
347
780
  continue;
348
781
  }
782
+ yield commit;
783
+ if (this.maxCount !== undefined && ++count >= this.maxCount) return;
349
784
  }
785
+ return;
786
+ }
350
787
 
351
- // Date filtering - since (after)
352
- if (this.sinceTime !== undefined && commit.committer.timestamp < this.sinceTime) {
353
- // Commits are in reverse chronological order, so we can stop early
788
+ // limit_list
789
+ const newlist: number[] = [];
790
+ let date = Number.POSITIVE_INFINITY;
791
+ let slop = SLOP;
792
+ let interestingCache = -1;
793
+ /** git's everybody_uninteresting */
794
+ const everybodyUninteresting = (): boolean => {
795
+ if (interestingCache >= 0 && !(t.flag(interestingCache) & UNINTERESTING)) return false;
796
+ for (const n of queue.items()) {
797
+ if (t.flag(n) & UNINTERESTING) continue;
798
+ interestingCache = n;
799
+ return false;
800
+ }
801
+ return true;
802
+ };
803
+ /** git's still_interesting */
804
+ const stillInteresting = (): number => {
805
+ const head = queue.peek();
806
+ if (head === undefined) return 0;
807
+ if (date <= t.date(head)) return SLOP;
808
+ if (!everybodyUninteresting()) return SLOP;
809
+ return slop - 1;
810
+ };
811
+ for (let n = queue.get(); n !== undefined; n = queue.get()) {
812
+ // what is shown is read again at the end: a limited walk does not keep raw commits
813
+ raw.delete(n);
814
+ if (n === interestingCache) interestingCache = -1;
815
+ if (this.sinceTime !== undefined && t.date(n) < this.sinceTime) t.mark(n, UNINTERESTING);
816
+ await processParents(n, queue);
817
+ if (t.flag(n) & UNINTERESTING) {
818
+ markParentsUninteresting(n);
819
+ slop = stillInteresting();
820
+ if (slop) continue;
354
821
  break;
355
822
  }
356
-
357
- // Date filtering - until (before)
358
- if (this.untilTime !== undefined && commit.committer.timestamp > this.untilTime) {
359
- continue;
823
+ if (this.untilTime !== undefined && t.date(n) > this.untilTime) continue;
824
+ date = t.date(n);
825
+ newlist.push(n);
826
+ }
827
+ // commits made TREESAME by parents that became UNINTERESTING
828
+ if (trackTreesame) {
829
+ for (const n of newlist) {
830
+ if (!(t.flag(n) & (UNINTERESTING | TREESAME))) updateTreesame(n);
360
831
  }
361
-
362
- // Author filtering
363
- if (this.authorPattern !== undefined && !this.matchesAuthor(commit)) {
832
+ }
833
+ raw.clear();
834
+ if (output) {
835
+ await this.finishOutputWalk(output, t, newlist, shown, relevant, parse);
836
+ return;
837
+ }
838
+ if (none) return;
839
+ for (const n of newlist) {
840
+ const commit = await shown(n);
841
+ if (!commit) continue;
842
+ if (skipped < this.skip) {
843
+ skipped++;
364
844
  continue;
365
845
  }
846
+ yield commit;
847
+ if (this.maxCount !== undefined && ++count >= this.maxCount) return;
848
+ }
849
+ }
366
850
 
367
- // Committer filtering
368
- if (this.committerPattern !== undefined && !this.matchesCommitter(commit)) {
369
- continue;
851
+ /**
852
+ * The walk's commits for `git log`'s output (git's limited walk, then
853
+ * sort_in_topological_order when asked, then get_commit_action and rewrite_parents): the
854
+ * commits shown in order, with their parents as shown.
855
+ */
856
+ private async finishOutputWalk(
857
+ output: OutputWalk,
858
+ t: RevTable,
859
+ newlist: number[],
860
+ shown: (n: number, rewrite?: boolean) => Promise<LogResult | undefined>,
861
+ relevant: (n: number) => boolean,
862
+ parse: (n: number) => Promise<boolean>,
863
+ ): Promise<void> {
864
+ let order = newlist;
865
+ if (output.topo) {
866
+ // sort_in_topological_order (REV_SORT_IN_GRAPH_ORDER: a LIFO of the ready commits)
867
+ const indegree = new Map<number, number>();
868
+ for (const n of newlist) indegree.set(n, 1);
869
+ for (const n of newlist) {
870
+ for (let k = 0, c = t.parentCount(n); k < c; k++) {
871
+ const p = t.parent(n, k);
872
+ const d = indegree.get(p);
873
+ if (d) indegree.set(p, d + 1);
874
+ }
370
875
  }
371
-
372
- // Path filtering (include paths)
373
- if (this.paths.length > 0 && !(await this.affectsPath(commit, commitId))) {
374
- continue;
876
+ const stack: number[] = [];
877
+ for (const n of newlist) if (indegree.get(n) === 1) stack.push(n);
878
+ stack.reverse();
879
+ order = [];
880
+ for (let n = stack.pop(); n !== undefined; n = stack.pop()) {
881
+ for (let k = 0, c = t.parentCount(n); k < c; k++) {
882
+ const p = t.parent(n, k);
883
+ const d = indegree.get(p);
884
+ if (!d) continue;
885
+ indegree.set(p, d - 1);
886
+ if (d - 1 === 1) stack.push(p);
887
+ }
888
+ indegree.set(n, 0);
889
+ order.push(n);
375
890
  }
376
-
377
- // Path filtering (exclude paths) - if commit only affects excluded paths, skip it
378
- if (this.excludePaths.length > 0 && (await this.onlyAffectsExcludedPaths(commit))) {
379
- continue;
891
+ }
892
+ const firstParentOnly = this.firstParentOnly;
893
+ /** revision.c's one_relevant_parent */
894
+ const oneRelevantParent = (n: number): number | undefined => {
895
+ const c = t.parentCount(n);
896
+ if (c === 0) return undefined;
897
+ if (firstParentOnly || c === 1) return t.parent(n, 0);
898
+ let found: number | undefined;
899
+ for (let k = 0; k < c; k++) {
900
+ const p = t.parent(n, k);
901
+ if (!relevant(p)) continue;
902
+ if (found !== undefined) return undefined;
903
+ found = p;
904
+ }
905
+ return found;
906
+ };
907
+ /** revision.c's rewrite_one: the parent shown in place of `p`; undefined to drop it */
908
+ const rewriteOne = (start: number): number | undefined => {
909
+ let p = start;
910
+ for (;;) {
911
+ if (t.flag(p) & UNINTERESTING) return p;
912
+ if (!(t.flag(p) & TREESAME)) return p;
913
+ if (t.parentCount(p) === 0) return undefined;
914
+ const next = oneRelevantParent(p);
915
+ if (next === undefined) return p;
916
+ p = next;
917
+ }
918
+ };
919
+ const prune = this.paths.length > 0 || this.excludePaths.length > 0;
920
+ /** Rewritten parents the walk never reached (only with `--first-parent`) */
921
+ const unwalked = new Set<number>();
922
+ for (const n of order) {
923
+ const commit = await shown(n, output.rewrite && prune);
924
+ if (!commit) continue;
925
+ let parents = commit.parents;
926
+ let savedParents: ObjectId[] | undefined;
927
+ if (output.rewrite && prune) {
928
+ // the parents before rewriting, which `--full-diff` diffs against (save_parents)
929
+ savedParents = [];
930
+ for (let k = 0, c = t.parentCount(n); k < c; k++) savedParents.push(t.idOf(t.parent(n, k)));
931
+ const ids: ObjectId[] = [];
932
+ for (let k = 0, c = t.parentCount(n); k < c; k++) {
933
+ const p = rewriteOne(t.parent(n, k));
934
+ if (p === undefined) continue;
935
+ if (!(t.flag(p) & SEEN)) unwalked.add(p);
936
+ const id = t.idOf(p);
937
+ // remove_duplicate_parents
938
+ if (!ids.includes(id)) ids.push(id);
939
+ }
940
+ parents = ids;
941
+ }
942
+ const { id, ...rest } = commit;
943
+ output.entries.push({ id, commit: rest, parents, ...(savedParents ? { savedParents } : {}) });
944
+ }
945
+ // graph.c's graph_is_interesting asks get_commit_action about a parent: one the walk
946
+ // never reached has no TREESAME or SHOWN flag, so only the filters can hide it (with
947
+ // `--first-parent` a merge whose first parent was rewritten away keeps a lane for it)
948
+ if (unwalked.size > 0) {
949
+ output.unwalkedShown = new Set();
950
+ for (const p of unwalked) {
951
+ if ((await parse(p)) && (await shown(p))) output.unwalkedShown.add(t.idOf(p));
380
952
  }
953
+ }
954
+ }
381
955
 
382
- // Skip first N commits
383
- if (skipped < this.skip) {
384
- skipped++;
385
- continue;
956
+ /**
957
+ * The log printed as `git log <options>` prints it to a pipe (no colors, no pager): the
958
+ * walk set up by this command (start points, ranges, paths, `-n`, `--skip`, filters), each
959
+ * commit in the format asked for, with the graph and the diffs asked for. See
960
+ * {@link LogOutputOptions}.
961
+ *
962
+ * @example
963
+ * ```typescript
964
+ * await git.log().setMaxCount(2).callText({ pretty: "format:%h %s" });
965
+ * // "1a2b3c4 Second\n5d6e7f8 First"
966
+ * ```
967
+ */
968
+ async callText(options: LogOutputOptions = {}): Promise<string> {
969
+ return decodeGitPath(await this.callBytes(options));
970
+ }
971
+
972
+ /** {@link callText} as bytes (messages and file contents that are not UTF-8 kept as they are). */
973
+ async callBytes(options: LogOutputOptions = {}): Promise<Uint8Array> {
974
+ // one operation for the worktree: its attributes files (diff drivers) and configuration
975
+ // are read once for every commit's diff, as git keeps its attribute stack
976
+ const worktree = this.worktreeAccess;
977
+ if (worktree?.batch) return worktree.batch(() => this.printLog(options));
978
+ return this.printLog(options);
979
+ }
980
+
981
+ private async printLog(options: LogOutputOptions): Promise<Uint8Array> {
982
+ // revision.c's setup_revisions: the graph cannot be reversed
983
+ if (options.graph && options.reverse) {
984
+ throw new IncompatibleOptionsError(
985
+ ["--graph", "--reverse"],
986
+ "options '--graph' and '--reverse' cannot be used together",
987
+ );
988
+ }
989
+ const host = this.outputHost(options);
990
+ const paths = [...this.paths];
991
+ // the pathspec as git holds it: the excluded paths as `:(exclude)` elements, `.` when
992
+ // every element excludes
993
+ const pathspec = [...paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
994
+ if (paths.length === 0 && this.excludePaths.length > 0) pathspec.push(".");
995
+ const printer = new LogPrinter(host, options, {
996
+ interesting: (id) => shownIds.has(id) || unwalkedShown.has(id),
997
+ firstParentOnly: this.firstParentOnly,
998
+ paths: pathspec,
999
+ });
1000
+ const follow = !printer.alwaysShowHeader;
1001
+ const graph = !!options.graph;
1002
+ const topo = graph || !!options.topoOrder;
1003
+ const maxCount = this.maxCount;
1004
+ const skip = this.skip;
1005
+ const simplifyHistory = this.simplifyHistory;
1006
+ if (printer.fullHistory) this.simplifyHistory = false;
1007
+ // --follow walks every commit: its path changes as it goes
1008
+ if (follow) this.paths = [];
1009
+ const shownIds = new Set<ObjectId>();
1010
+ const unwalkedShown = new Set<ObjectId>();
1011
+ let entries: LogOutputEntry[];
1012
+ if (topo) {
1013
+ this.outputWalk = { topo, rewrite: graph, entries: [] };
1014
+ for await (const _ of await this.call()) {
1015
+ // the output walk collects its commits
386
1016
  }
1017
+ entries = this.outputWalk.entries;
1018
+ for (const id of this.outputWalk.unwalkedShown ?? []) unwalkedShown.add(id);
1019
+ this.outputWalk = undefined;
1020
+ for (const e of entries) shownIds.add(e.id);
1021
+ entries = entries.slice(skip);
1022
+ if (maxCount !== undefined && !follow) entries = entries.slice(0, Math.max(maxCount, 0));
1023
+ if (maxCount !== undefined && maxCount <= 0) entries = [];
1024
+ } else {
1025
+ // --follow counts the commits shown, not those walked; --reverse the newest walked
1026
+ if (follow && !options.reverse) this.maxCount = undefined;
1027
+ entries = [];
1028
+ for await (const c of await this.call()) {
1029
+ const { id, ...commit } = c;
1030
+ entries.push({ id, commit, parents: c.parents });
1031
+ }
1032
+ if (follow) this.maxCount = maxCount;
1033
+ }
1034
+ this.simplifyHistory = simplifyHistory;
1035
+ if (follow && options.reverse && maxCount !== undefined) {
1036
+ entries = entries.slice(0, Math.max(maxCount, 0));
1037
+ }
1038
+ if (options.reverse) entries.reverse();
1039
+ await printer.start();
1040
+ if (graph) {
1041
+ const parentsOf = new Map(entries.map((e) => [e.id, e.parents]));
1042
+ printer.useGraph((id) => parentsOf.get(id) ?? []);
1043
+ }
1044
+ let count = 0;
1045
+ // -n 0: nothing is walked
1046
+ if (maxCount !== undefined && maxCount <= 0) entries = [];
1047
+ const countShown = follow && maxCount !== undefined && !options.reverse;
1048
+ for (let k = 0; k < entries.length; k++) {
1049
+ const e = entries[k] as LogOutputEntry;
1050
+ const lookahead = entries.slice(k + 1, k + 3).map((x) => x.id);
1051
+ const shown = await printer.showCommit(e, lookahead);
1052
+ if (shown && countShown && ++count >= (maxCount as number)) break;
1053
+ }
1054
+ if (follow) this.paths = paths;
1055
+ return printer.result();
1056
+ }
387
1057
 
388
- // Check max count
389
- if (this.maxCount !== undefined && count >= this.maxCount) {
390
- break;
1058
+ /** What the log printer reads of the repository. */
1059
+ private outputHost(options: LogOutputOptions = {}): LogOutputHost {
1060
+ const config = RemoteConfigStore.from(this._workingCopy);
1061
+ const abbreviator = this.idAbbreviator();
1062
+ const abbrevs = new Map<string, string>();
1063
+ let notesTrees: Promise<NotesHandle[]> | undefined;
1064
+ let mailmap: Promise<Mailmap> | undefined;
1065
+ const trees = new OrderedMap<ObjectId, Promise<ObjectId>>();
1066
+ /** A commit's tree, as the walk parsed it (replace refs and grafts honoured) */
1067
+ const treeOf = (id: ObjectId): Promise<ObjectId> => {
1068
+ let tree = trees.get(id);
1069
+ if (!tree) {
1070
+ tree = (async () => {
1071
+ const header = await this.readCommitHeader(id, await this.objectReplacements());
1072
+ if (!header) throw new GitApiError(`could not parse commit ${id}`);
1073
+ return header.tree;
1074
+ })();
1075
+ trees.set(id, tree);
1076
+ if (trees.size > 4096) trees.deleteOldest();
391
1077
  }
1078
+ return tree;
1079
+ };
1080
+ return {
1081
+ config: (key) => config.value(key),
1082
+ configAll: (key) => config.values(key),
1083
+ configNames: (section) => {
1084
+ const prefix = `${section.toLowerCase()}.`;
1085
+ const names = new Set<string>();
1086
+ for (const key of Object.keys(this._workingCopy.config ?? {})) {
1087
+ const parts = key.split(".");
1088
+ if (parts.length === 2 && key.toLowerCase().startsWith(prefix))
1089
+ names.add(parts[1] as string);
1090
+ }
1091
+ return [...names];
1092
+ },
1093
+ abbreviate: async (id, minLength) => {
1094
+ const key = `${id}:${minLength ?? ""}`;
1095
+ let short = abbrevs.get(key);
1096
+ if (short === undefined) {
1097
+ if (minLength === undefined) short = await abbreviator.abbreviate(id);
1098
+ else
1099
+ short = id.slice(0, (await abbreviator.lengths([id], minLength)).get(id) ?? minLength);
1100
+ abbrevs.set(key, short);
1101
+ }
1102
+ return short;
1103
+ },
1104
+ rawCommit: async (id) => {
1105
+ // the replacement's content, as git's commit buffer is (core.useReplaceRefs)
1106
+ const replace = (await this.objectReplacements())?.replace;
1107
+ const bytes = await this.readObjectBytes(replace?.size ? replacementOf(replace, id) : id);
1108
+ return bytes ? decodeGitPath(bytes) : undefined;
1109
+ },
1110
+ decorations: async (options) => {
1111
+ const replacements = await this.objectReplacements();
1112
+ const shallow = (await this.refsStore.getShallow?.().catch(() => undefined)) ?? [];
1113
+ const environment = hostEnvironmentOf(this._workingCopy);
1114
+ const objects = this._workingCopy.history?.objects;
1115
+ const tags = this.tagsStore;
1116
+ return loadRefDecorations({
1117
+ refs: this.refsStore,
1118
+ ...(tags ? { tags } : {}),
1119
+ ...(environment?.replaceRefBase !== undefined
1120
+ ? { replaceRefBase: environment.replaceRefBase }
1121
+ : {}),
1122
+ useReplaceRefs: this.useReplaceRefs(),
1123
+ grafted: new Set([...(replacements?.grafts.keys() ?? []), ...shallow]),
1124
+ ...(objects ? { hasObject: (id: ObjectId) => objects.has(id) } : {}),
1125
+ logOptions: {
1126
+ decorate: options.decorate,
1127
+ ...(options.decorateRefs ? { decorateRefs: options.decorateRefs } : {}),
1128
+ ...(options.decorateRefsExclude
1129
+ ? { decorateRefsExclude: options.decorateRefsExclude }
1130
+ : {}),
1131
+ ...(options.clearDecorations ? { clearDecorations: true } : {}),
1132
+ config,
1133
+ },
1134
+ });
1135
+ },
1136
+ notes: async (id) => {
1137
+ notesTrees ??= this.loadNotes(config, options);
1138
+ const out: { ref: string; text: string }[] = [];
1139
+ for (const { ref, tree } of await notesTrees) {
1140
+ const blob = await tree.get(id);
1141
+ if (!blob) continue;
1142
+ const bytes = await this.readBlob(blob);
1143
+ if (bytes) out.push({ ref, text: decodeGitPath(bytes) });
1144
+ }
1145
+ return out;
1146
+ },
1147
+ mailmap: () => {
1148
+ mailmap ??= this.loadMailmap(config);
1149
+ return mailmap;
1150
+ },
1151
+ diff: async (entry, parent, formats, options) => {
1152
+ // the trees themselves: a full id names its object, so no revision is looked up
1153
+ const diff = new DiffCommand(this._workingCopy)
1154
+ .setOldTree(parent ? await treeOf(parent) : EMPTY_TREE_ID)
1155
+ .setNewTree(entry.commit.tree)
1156
+ .shareReadsOf(this);
1157
+ diff.setOptions({
1158
+ ...this.diffOptions,
1159
+ ...(options.statWidth !== undefined
1160
+ ? { stat: { ...this.diffOptions.stat, width: options.statWidth } }
1161
+ : {}),
1162
+ ...(options.abbrev !== undefined ? { abbrev: options.abbrev } : {}),
1163
+ });
1164
+ if (!options.fullDiff && options.follow === undefined) {
1165
+ const spec = [...this.paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
1166
+ if (spec.length > 0) diff.setPathspec(spec);
1167
+ }
1168
+ return diff.callFormats(formats, options.follow);
1169
+ },
1170
+ combinedDiff: (entry, options) => this.combinedDiff(entry, options),
1171
+ };
1172
+ }
1173
+
1174
+ private diffOptions: DiffTextOptions = {};
1175
+
1176
+ /** `log` stores no objects: its abbreviations read each loose fan-out directory once */
1177
+ protected override writesNoObjects(): boolean {
1178
+ return true;
1179
+ }
1180
+
1181
+ /** Options of the diffs {@link callBytes} prints (context, algorithm, `--stat` widths...) */
1182
+ setDiffOptions(options: DiffTextOptions): this {
1183
+ this.checkCallable();
1184
+ this.diffOptions = { ...this.diffOptions, ...options };
1185
+ return this;
1186
+ }
392
1187
 
393
- count++;
394
- yield { ...commit, id: commitId };
1188
+ /** An object's content as stored (undefined when missing) */
1189
+ private async readObjectBytes(id: ObjectId): Promise<Uint8Array | undefined> {
1190
+ const objects = this._workingCopy.history?.objects;
1191
+ if (!objects) return undefined;
1192
+ try {
1193
+ const obj = await objects.get(id);
1194
+ if (!obj) return undefined;
1195
+ if (obj.bytes) return obj.bytes;
1196
+ const chunks: Uint8Array[] = [];
1197
+ for await (const c of obj.content) chunks.push(c);
1198
+ return concatBytes(chunks);
1199
+ } catch {
1200
+ return undefined;
395
1201
  }
396
1202
  }
397
1203
 
398
- /**
399
- * Build set of commits to exclude.
400
- */
401
- private async buildExcludedSet(): Promise<Set<ObjectId>> {
402
- if (this.excludeCommits.length === 0) {
403
- return new Set();
1204
+ private async readBlob(id: ObjectId): Promise<Uint8Array | undefined> {
1205
+ try {
1206
+ const content = await this.blobs.load(id);
1207
+ if (!content) return undefined;
1208
+ const chunks: Uint8Array[] = [];
1209
+ for await (const c of content) chunks.push(c);
1210
+ return concatBytes(chunks);
1211
+ } catch {
1212
+ return undefined;
404
1213
  }
1214
+ }
405
1215
 
406
- const excluded = new Set<ObjectId>();
407
- for await (const commitId of this.commits.walkAncestry(this.excludeCommits, {
408
- firstParentOnly: false,
409
- })) {
410
- excluded.add(commitId);
1216
+ /** The blobs of a tree, by path (empty for a missing tree) */
1217
+ private async flatTree(
1218
+ tree: ObjectId,
1219
+ prefix = "",
1220
+ out = new Map<string, { mode: number; id: ObjectId }>(),
1221
+ ): Promise<Map<string, { mode: number; id: ObjectId }>> {
1222
+ if (tree === EMPTY_TREE_ID) return out;
1223
+ for await (const entry of this.trees.loadTree(tree)) {
1224
+ const path = prefix ? `${prefix}/${entry.name}` : entry.name;
1225
+ if ((entry.mode & 0o170000) === 0o040000) await this.flatTree(entry.id, path, out);
1226
+ // the mode as git's tree walk reads it (canon_mode), as the tree store reads it
1227
+ else out.set(path, { mode: entry.mode, id: entry.id });
411
1228
  }
412
- return excluded;
1229
+ return out;
413
1230
  }
414
1231
 
415
1232
  /**
416
- * Check if commit author matches the filter pattern.
1233
+ * combine-diff.c's diff_tree_combined for a merge: the paths that differ from every
1234
+ * parent (within the pathspec), each as a combined diff of the trees.
417
1235
  */
418
- private matchesAuthor(commit: Commit): boolean {
419
- if (!this.authorPattern) return true;
420
- const authorStr = `${commit.author.name} <${commit.author.email}>`.toLowerCase();
421
- return authorStr.includes(this.authorPattern);
1236
+ private async combinedDiff(
1237
+ entry: LogOutputEntry,
1238
+ options: {
1239
+ dense: boolean;
1240
+ names?: "name-only" | "name-status";
1241
+ patch: boolean;
1242
+ follow?: string;
1243
+ parentPaths?: string[];
1244
+ parentStatus?: (string | undefined)[];
1245
+ },
1246
+ ): Promise<{ paths: number; names: Uint8Array; patch: Uint8Array }> {
1247
+ const { dense } = options;
1248
+ /** A parent's entry for a path (under `--follow`, the path it had the file under) */
1249
+ const sideOf = (m: Map<string, { mode: number; id: ObjectId }>, k: number, path: string) =>
1250
+ m.get(options.parentPaths?.[k] ?? path);
1251
+ const result = await this.flatTree(entry.commit.tree);
1252
+ const parents: Map<string, { mode: number; id: ObjectId }>[] = [];
1253
+ for (const p of entry.parents) {
1254
+ const commit = await this.commits.load(p);
1255
+ parents.push(commit ? await this.flatTree(commit.tree) : new Map());
1256
+ }
1257
+ // --follow: the one path followed (the walk's pathspec is set aside then)
1258
+ const spec =
1259
+ options.follow !== undefined
1260
+ ? [`:(literal)${options.follow}`]
1261
+ : [...this.paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
1262
+ const items = spec.map((p) => parsePathspecItem(p, { attr: true }));
1263
+ if (items.length > 0 && items.every((i) => i.exclude)) items.push(parsePathspecItem("."));
1264
+ const all = new Set<string>(result.keys());
1265
+ for (const m of parents) for (const k of m.keys()) all.add(k);
1266
+ // `:(attr:...)`: the attributes of the paths, as the walk reads them
1267
+ if (items.some((i) => i.attr)) {
1268
+ await new PathspecAttributes(items, (path, names) => this.readAttributes(path, names)).load(
1269
+ all,
1270
+ );
1271
+ }
1272
+ const differs = (a?: { mode: number; id: ObjectId }, b?: { mode: number; id: ObjectId }) =>
1273
+ !a || !b ? a !== b : a.id !== b.id || a.mode !== b.mode;
1274
+ const paths = [...all]
1275
+ .filter((path) => items.length === 0 || matchPathspec(items, path, 0) > 0)
1276
+ .filter((path) =>
1277
+ parents.every(
1278
+ (m, k) =>
1279
+ (options.parentPaths !== undefined && options.parentPaths[k] !== path) ||
1280
+ differs(sideOf(m, k, path), result.get(path)),
1281
+ ),
1282
+ )
1283
+ .sort((a, b) => {
1284
+ const ea = encodeGitPath(a);
1285
+ const eb = encodeGitPath(b);
1286
+ for (let i = 0; i < ea.length && i < eb.length; i++) {
1287
+ if (ea[i] !== eb[i]) return (ea[i] as number) - (eb[i] as number);
1288
+ }
1289
+ return ea.length - eb.length;
1290
+ });
1291
+ const sink = new ByteSink();
1292
+ const quote =
1293
+ parseGitBool(RemoteConfigStore.from(this._workingCopy).value("core.quotePath")) ?? true;
1294
+ const names = new ByteSink();
1295
+ if (options.names) {
1296
+ for (const path of paths) {
1297
+ if (options.names === "name-status") {
1298
+ const r = result.get(path);
1299
+ parents.forEach((m, k) => {
1300
+ const found = options.parentStatus?.[k];
1301
+ names.text(found ?? (!sideOf(m, k, path) ? "A" : !r ? "D" : "M"));
1302
+ });
1303
+ names.text("\t");
1304
+ }
1305
+ names.text(`${quotePath(path, quote)}\n`);
1306
+ }
1307
+ }
1308
+ if (paths.length === 0 || !options.patch) {
1309
+ return { paths: paths.length, names: names.bytes(), patch: sink.bytes() };
1310
+ }
1311
+ const ids = new Set<string>([NULL_OBJECT_ID]);
1312
+ for (const path of paths) {
1313
+ const r = result.get(path);
1314
+ if (r) ids.add(r.id);
1315
+ parents.forEach((m, k) => {
1316
+ const e = sideOf(m, k, path);
1317
+ if (e) ids.add(e.id);
1318
+ });
1319
+ }
1320
+ // combine-diff.c's index lines take DEFAULT_ABBREV, whatever --abbrev says
1321
+ const lengths = await this.idAbbreviator().lengths(ids);
1322
+ const read = async (e?: { mode: number; id: ObjectId }) => {
1323
+ if (!e) return new Uint8Array(0);
1324
+ if ((e.mode & 0o170000) === 0o160000) return encodeGitPath(`Subproject commit ${e.id}\n`);
1325
+ return (await this.readBlob(e.id)) ?? new Uint8Array(0);
1326
+ };
1327
+ const config = RemoteConfigStore.from(this._workingCopy);
1328
+ const context = Number(config.value("diff.context") ?? 3);
1329
+ // combine-diff.c diffs each parent with the xpparam flags of the diff options
1330
+ // (opt->xdl_opts): the algorithm, the indent heuristic, the whitespace flags
1331
+ const d = this.diffOptions;
1332
+ const xdiffOptions = {
1333
+ algorithm: d.algorithm ?? configAlgorithm(config.value("diff.algorithm")) ?? "myers",
1334
+ indentHeuristic:
1335
+ d.indentHeuristic ?? parseGitBool(config.value("diff.indentHeuristic")) ?? true,
1336
+ histogramRediff: d.histogramRediff,
1337
+ legacyMinimal: d.legacyMinimal,
1338
+ ignoreWhitespace: d.ignoreWhitespace,
1339
+ ignoreWhitespaceChange: d.ignoreWhitespaceChange,
1340
+ ignoreWhitespaceAtEol: d.ignoreWhitespaceAtEol,
1341
+ ignoreCrAtEol: d.ignoreCrAtEol,
1342
+ ignoreBlankLines: d.ignoreBlankLines,
1343
+ } satisfies CombinedDiffOptions;
1344
+ for (const path of paths) {
1345
+ const r = result.get(path);
1346
+ const sides = [];
1347
+ for (let k = 0; k < parents.length; k++) {
1348
+ const e = sideOf(parents[k] as Map<string, { mode: number; id: ObjectId }>, k, path);
1349
+ sides.push({ id: e?.id ?? NULL_OBJECT_ID, mode: e?.mode ?? 0, content: await read(e) });
1350
+ }
1351
+ writeCombinedDiff(
1352
+ sink,
1353
+ {
1354
+ path,
1355
+ parents: sides,
1356
+ result: { id: r?.id ?? NULL_OBJECT_ID, mode: r?.mode ?? 0, content: await read(r) },
1357
+ },
1358
+ {
1359
+ ...xdiffOptions,
1360
+ dense,
1361
+ workingTreeFile: false,
1362
+ context: this.diffOptions.context ?? (Number.isFinite(context) ? context : 3),
1363
+ abbreviate: (id) => id.slice(0, this.diffOptions.fullIndex ? 40 : (lengths.get(id) ?? 7)),
1364
+ quotePath: quote,
1365
+ },
1366
+ );
1367
+ }
1368
+ return { paths: paths.length, names: names.bytes(), patch: sink.bytes() };
422
1369
  }
423
1370
 
424
1371
  /**
425
- * Check if commit committer matches the filter pattern.
1372
+ * notes.c's load_display_notes: the default notes ref (`GIT_NOTES_REF`, `core.notesRef`,
1373
+ * `refs/notes/commits`) and `GIT_NOTES_DISPLAY_REF` (else `notes.displayRef`), globs
1374
+ * expanded, unless only `--notes=<ref>` refs are asked for; then those refs.
426
1375
  */
427
- private matchesCommitter(commit: Commit): boolean {
428
- if (!this.committerPattern) return true;
429
- const committerStr = `${commit.committer.name} <${commit.committer.email}>`.toLowerCase();
430
- return committerStr.includes(this.committerPattern);
1376
+ private async loadNotes(
1377
+ config: RemoteConfigStore,
1378
+ options: LogOutputOptions,
1379
+ ): Promise<NotesHandle[]> {
1380
+ const ctx = this.notesContext();
1381
+ const extra = options.notesRefs ?? [];
1382
+ const refs: string[] = [];
1383
+ if (options.notes === true || extra.length === 0) {
1384
+ refs.push(defaultNotesRef(this._workingCopy));
1385
+ const env = notesEnvironmentOf(this._workingCopy).notesDisplayRef;
1386
+ if (env !== undefined) await addRefsFromColonSep(ctx, refs, env);
1387
+ else for (const r of config.values("notes.displayRef")) await addRefsByGlob(ctx, refs, r);
1388
+ }
1389
+ for (const r of extra) await addRefsByGlob(ctx, refs, expandNotesRef(r));
1390
+ const out: NotesHandle[] = [];
1391
+ for (const ref of refs) {
1392
+ try {
1393
+ out.push(await initNotes(ctx, ref, { combine: combineNotesIgnore }));
1394
+ } catch {
1395
+ // a ref that holds no tree-ish: git dies there, the log shows the others
1396
+ }
1397
+ }
1398
+ return out;
1399
+ }
1400
+
1401
+ /** mailmap.c's read_mailmap: `.mailmap` (not in a bare repository), `mailmap.blob`, `mailmap.file` */
1402
+ private async loadMailmap(config: RemoteConfigStore): Promise<Mailmap> {
1403
+ const map = new Mailmap();
1404
+ const worktree = this.worktreeAccess;
1405
+ const bare = parseGitBool(config.value("core.bare")) ?? !worktree;
1406
+ if (!bare && worktree) {
1407
+ try {
1408
+ const entry = await worktree.getEntry(".mailmap");
1409
+ if (entry && !entry.isDirectory && (entry.mode & 0o170000) !== 0o120000) {
1410
+ const chunks: Uint8Array[] = [];
1411
+ for await (const c of worktree.readContent(".mailmap")) chunks.push(c);
1412
+ map.read(decodeGitPath(concatBytes(chunks)));
1413
+ }
1414
+ } catch {
1415
+ // no .mailmap
1416
+ }
1417
+ }
1418
+ const blobName = config.value("mailmap.blob") ?? (bare ? "HEAD:.mailmap" : undefined);
1419
+ if (blobName) {
1420
+ const id = await this.revisionResolver()
1421
+ .resolve(blobName)
1422
+ .catch(() => undefined);
1423
+ const bytes = id ? await this.readBlob(id) : undefined;
1424
+ if (bytes) map.read(decodeGitPath(bytes));
1425
+ }
1426
+ const file = config.value("mailmap.file");
1427
+ if (file) {
1428
+ const environment = hostEnvironmentOf(this._workingCopy);
1429
+ const path = expandUserPath(file, environment);
1430
+ const bytes = path !== undefined ? await this.readMailmapFile(path, environment) : undefined;
1431
+ if (bytes) map.read(decodeGitPath(bytes));
1432
+ }
1433
+ return map;
431
1434
  }
432
1435
 
433
1436
  /**
434
- * Check if a commit affects any of the filtered paths.
1437
+ * `mailmap.file`, read as git reads it: through the host (a relative path from its current
1438
+ * directory). Without a host environment, a relative path is read from the worktree's top
1439
+ * (where git usually runs), and an absolute one inside the worktree through it as well.
435
1440
  */
436
- private async affectsPath(commit: Commit, _commitId: ObjectId): Promise<boolean> {
437
- // If no parents, this is the initial commit - include if tree has the path
438
- if (commit.parents.length === 0) {
439
- return this.treeHasPath(commit.tree);
1441
+ private async readMailmapFile(
1442
+ path: string,
1443
+ environment: ReturnType<typeof hostEnvironmentOf>,
1444
+ ): Promise<Uint8Array | undefined> {
1445
+ if (environment) return environment.readFile(path).catch(() => undefined);
1446
+ const worktree = "worktree" in this._workingCopy ? this.worktreeAccess : undefined;
1447
+ if (!worktree) return undefined;
1448
+ let relative = path;
1449
+ if (path.startsWith("/")) {
1450
+ const top = (worktree as { hostPath?: string }).hostPath?.replace(/\/+$/, "");
1451
+ if (!top || !path.startsWith(`${top}/`)) return undefined;
1452
+ relative = path.slice(top.length + 1);
440
1453
  }
1454
+ if (relative.split("/").includes("..")) return undefined;
1455
+ try {
1456
+ const entry = await worktree.getEntry(relative);
1457
+ if (!entry || entry.isDirectory) return undefined;
1458
+ const chunks: Uint8Array[] = [];
1459
+ for await (const c of worktree.readContent(relative)) chunks.push(c);
1460
+ return concatBytes(chunks);
1461
+ } catch {
1462
+ return undefined;
1463
+ }
1464
+ }
441
1465
 
442
- // Compare with first parent's tree
443
- const parentCommit = await this.commits.load(commit.parents[0]);
444
- if (!parentCommit) {
445
- return true; // No parent found, consider it affects paths
1466
+ /**
1467
+ * The tree, parents and date of a commit (git's parse_commit_buffer), from its raw bytes
1468
+ * when the store gives them (kept in `raw` to be decoded whole if the commit is shown),
1469
+ * else from the commit store; undefined when it is missing or not a commit.
1470
+ */
1471
+ private async readCommitHeader(
1472
+ id: ObjectId,
1473
+ replacements?: ObjectReplacements,
1474
+ ): Promise<{ tree: ObjectId; parents: ObjectId[]; date: number; raw?: Uint8Array } | undefined> {
1475
+ if (replacements) {
1476
+ // the replacement's content read in place of the commit's; its grafted parents
1477
+ const read = replacementOf(replacements.replace, id);
1478
+ const header = await this.readCommitHeader(read);
1479
+ const grafted = replacements.grafts.get(id);
1480
+ return header && grafted ? { ...header, parents: [...grafted] } : header;
446
1481
  }
447
- const parentTree = parentCommit.tree;
1482
+ const objects = this._workingCopy.history?.objects;
1483
+ if (objects) {
1484
+ let obj: GitObject | undefined;
1485
+ let failed = false;
1486
+ try {
1487
+ const now = objects.getNow ? objects.getNow(id) : objects.get(id);
1488
+ obj = now instanceof Promise ? await now : now;
1489
+ } catch {
1490
+ obj = undefined;
1491
+ failed = true;
1492
+ }
1493
+ if (!obj && !failed) return undefined;
1494
+ if (obj?.bytes && obj.type === "commit") {
1495
+ try {
1496
+ const header = parseGraphCommit(obj.bytes, id);
1497
+ return { ...header, raw: obj.bytes };
1498
+ } catch {
1499
+ // read as the commit store reads it
1500
+ }
1501
+ } else if (obj) {
1502
+ await obj.content[Symbol.asyncIterator]().return?.();
1503
+ }
1504
+ }
1505
+ const commit = await this.commits.load(id).catch(() => undefined);
1506
+ if (!commit) return undefined;
1507
+ return { tree: commit.tree, parents: commit.parents, date: commit.committer.timestamp };
1508
+ }
448
1509
 
449
- // Check if any path differs between trees
450
- for (const path of this.paths) {
451
- const entryInCurrent = await this.getTreeEntryForPath(commit.tree, path);
452
- const entryInParent = await this.getTreeEntryForPath(parentTree, path);
1510
+ /**
1511
+ * The pathspec of the walk: the paths added, the excluded ones as `:(exclude)` elements,
1512
+ * and `.` when every element excludes (git's parse_pathspec). `literal` holds each
1513
+ * element's path components when all are plain paths (no wildcard, no magic, no trailing
1514
+ * slash): those are compared by looking their entries up, without a tree diff.
1515
+ */
1516
+ private pathspec(): TreePathspec & { literal: Uint8Array[][] | undefined } {
1517
+ const parse = (p: string) => parsePathspecItem(p, { attr: true });
1518
+ const items: PathspecItem[] = this.paths.map(parse);
1519
+ for (const p of this.excludePaths) items.push({ ...parse(p), exclude: true });
1520
+ if (items.every((i) => i.exclude)) items.push(parse("."));
1521
+ const plain = items.every(
1522
+ (i) =>
1523
+ !i.exclude &&
1524
+ !i.icase &&
1525
+ !i.attr &&
1526
+ i.prefix === undefined &&
1527
+ i.nowildcardLen === i.match.length &&
1528
+ !i.match.endsWith("/"),
1529
+ );
1530
+ return {
1531
+ ...treePathspec(items),
1532
+ literal: plain
1533
+ ? items.map((i) => pathParts(i.match).map((part) => encodeGitPath(part)))
1534
+ : undefined,
1535
+ };
1536
+ }
453
1537
 
454
- // Different if one exists and other doesn't, or if object IDs differ
455
- const currentId = entryInCurrent?.objectId;
456
- const parentId = entryInParent?.objectId;
1538
+ /** git's `commitGraph.changedPathsVersion` (-1: any; 0 when `readChangedPaths` is false). */
1539
+ private changedPathsVersion(): number {
1540
+ const raw = configValue(this._workingCopy, "commitGraph.changedPathsVersion");
1541
+ if (raw !== undefined && /^\s*[-+]?\d+\s*$/.test(raw)) return Number.parseInt(raw, 10);
1542
+ return configBool(this._workingCopy, "commitGraph.readChangedPaths", true) ? -1 : 0;
1543
+ }
457
1544
 
458
- if (currentId !== parentId) {
459
- return true;
1545
+ /**
1546
+ * The Bloom keys of the pathspec, one vector per element (its path and each leading
1547
+ * directory, git's bloom_keyvec_new), hashed with the graph's settings; undefined when the
1548
+ * graph has no filters or the pathspec cannot use them (git's prepare_to_use_bloom_filter:
1549
+ * exclude or icase magic, or an element without a literal leading directory).
1550
+ */
1551
+ private bloomKeys(
1552
+ graph: CommitGraph | undefined,
1553
+ items: PathspecItem[],
1554
+ ): { settings: BloomFilterSettings; keys: number[][][] } | undefined {
1555
+ const settings = graph?.bloomSettings;
1556
+ if (!settings || pathspecForbidsBloom(items)) return undefined;
1557
+ const keys: number[][][] = [];
1558
+ for (const item of items) {
1559
+ const path = bloomPathOf(item);
1560
+ if (path === undefined) return undefined;
1561
+ const bytes = Uint8Array.from(path, (ch) => ch.charCodeAt(0));
1562
+ const vec = [bloomKey(bytes, settings)];
1563
+ for (let end = bytes.length - 1; end > 0; end--) {
1564
+ if (bytes[end] === 0x2f) vec.push(bloomKey(bytes.subarray(0, end), settings));
460
1565
  }
1566
+ keys.push(vec);
461
1567
  }
1568
+ return { settings, keys };
1569
+ }
462
1570
 
463
- return false;
1571
+ private comparedPathspec?: TreePathspec & { literal: Uint8Array[][] | undefined };
1572
+
1573
+ /**
1574
+ * Whether trees `from` (undefined: the empty tree) and `to` differ at the paths added
1575
+ * ({@link addPath}, {@link excludePath}): the pruned tree comparison of this walk's
1576
+ * history simplification (git's rev_compare_tree, no Bloom filter asked), for the walks of
1577
+ * other commands (`git bisect`). Trees read are cached as the walk's are.
1578
+ */
1579
+ async pathsDiffer(from: ObjectId | undefined, to: ObjectId): Promise<boolean> {
1580
+ this.comparedPathspec ??= this.pathspec();
1581
+ const ps = this.comparedPathspec;
1582
+ return this.differsAtPaths(from, to, ps, ps.literal, undefined, -1, undefined, -1);
464
1583
  }
465
1584
 
466
1585
  /**
467
- * Check if a commit only affects excluded paths.
468
- *
469
- * If the commit only changes files in excludePaths, it should be filtered out.
1586
+ * Whether the paths differ between tree `from` (undefined: the empty tree) and tree `to` of
1587
+ * the commit at graph position `pos` (git's rev_compare_tree / rev_same_tree_as_empty):
1588
+ * with `bloom`, the commit's filter is asked first and a "certainly not" ends it. A filter
1589
+ * of another hash version than `commitGraph.changedPathsVersion` asks for is not there
1590
+ * (git's get_bloom_filter).
470
1591
  */
471
- private async onlyAffectsExcludedPaths(commit: Commit): Promise<boolean> {
472
- if (this.excludePaths.length === 0) {
473
- return false;
1592
+ private async differsAtPaths(
1593
+ from: ObjectId | undefined,
1594
+ to: ObjectId,
1595
+ pathspec: TreePathspec,
1596
+ literal: Uint8Array[][] | undefined,
1597
+ bloom: { settings: BloomFilterSettings; keys: number[][][] } | undefined,
1598
+ bloomVersion: number,
1599
+ graph: CommitGraph | undefined,
1600
+ pos: number,
1601
+ ): Promise<boolean> {
1602
+ const stats = this.statistics;
1603
+ let maybe = false;
1604
+ // a commit outside the graph is not asked (its generation is infinite)
1605
+ if (bloom && graph && pos >= 0) {
1606
+ const found = graph.bloomFilterAt(pos);
1607
+ const filter =
1608
+ found && (bloomVersion === -1 || found.settings.hashVersion === bloomVersion)
1609
+ ? found
1610
+ : undefined;
1611
+ if (!filter) {
1612
+ stats.bloomNotPresent++;
1613
+ } else {
1614
+ // bloom_filter_contains_vec over each path: one "maybe" (or an empty filter) is enough
1615
+ let result = 0;
1616
+ for (let i = 0; result === 0 && i < bloom.keys.length; i++) {
1617
+ result = 1;
1618
+ for (const key of bloom.keys[i] as number[][]) {
1619
+ result = bloomFilterContains(filter.data, key);
1620
+ if (result <= 0) break;
1621
+ }
1622
+ }
1623
+ if (result === 0) {
1624
+ stats.bloomDefinitelyNot++;
1625
+ return false;
1626
+ }
1627
+ stats.bloomMaybe++;
1628
+ maybe = result === 1;
1629
+ }
474
1630
  }
475
-
476
- // For initial commit, check if all paths in tree are excluded
477
- if (commit.parents.length === 0) {
478
- // For simplicity, don't exclude initial commits based on path
479
- return false;
1631
+ stats.treeComparisons++;
1632
+ let differs = false;
1633
+ if (literal) {
1634
+ for (const parts of literal) {
1635
+ if (await this.differsAtPath(from, to, parts, 0)) {
1636
+ differs = true;
1637
+ break;
1638
+ }
1639
+ }
1640
+ } else {
1641
+ differs = await this.treesDiffer(from, to, pathspec, EMPTY_TREE);
480
1642
  }
1643
+ if (maybe && !differs) stats.bloomFalsePositive++;
1644
+ return differs;
1645
+ }
481
1646
 
482
- // Compare with first parent's tree
483
- const parentCommit = await this.commits.load(commit.parents[0]);
484
- if (!parentCommit) {
485
- return false; // No parent found, don't filter out
1647
+ /**
1648
+ * Whether trees `a` and `b` (undefined: empty) under `base` differ at a path in the
1649
+ * pathspec: git's pruned, recursive diff_tree_oid with `quick` (the first change ends it).
1650
+ * Entries are taken in git's tree order on both sides, those `tree_entry_interesting`
1651
+ * rejects skipped; a directory that differs, or is only on one side, is walked down.
1652
+ */
1653
+ private async treesDiffer(
1654
+ a: ObjectId | undefined,
1655
+ b: ObjectId | undefined,
1656
+ ps: TreePathspec,
1657
+ base: Uint8Array,
1658
+ ): Promise<boolean> {
1659
+ this.statistics.treeEntryReads++;
1660
+ // git reads the parent's tree, then the commit's
1661
+ const da = a ? await this.requireTree(a) : EMPTY_TREE;
1662
+ const db = b ? await this.requireTree(b) : EMPTY_TREE;
1663
+ const ca = new RawEntries(da);
1664
+ const cb = new RawEntries(db);
1665
+ // entries are matched where they lie in the tree's bytes: no name is decoded; an `:(attr)`
1666
+ // element waits for the attributes of a path, then the entry is matched again
1667
+ const skip = (c: RawEntries): Promise<void> | undefined => {
1668
+ while (!c.done) {
1669
+ c.read();
1670
+ const r = treeEntryInteresting(ps, c.d, c.nameStart, c.nul, c.mode, base);
1671
+ if (r === NEED_ATTRIBUTES) return this.loadAttributes(ps).then(() => skip(c));
1672
+ if (r === ALL_ENTRIES_NOT_INTERESTING) {
1673
+ c.at = c.d.length;
1674
+ return undefined;
1675
+ }
1676
+ if (r !== ENTRY_NOT_INTERESTING) return undefined;
1677
+ c.next();
1678
+ }
1679
+ return undefined;
1680
+ };
1681
+ for (;;) {
1682
+ const sa = skip(ca);
1683
+ if (sa) await sa;
1684
+ const sb = skip(cb);
1685
+ if (sb) await sb;
1686
+ if (ca.done && cb.done) return false;
1687
+ const cmp = ca.done ? 1 : cb.done ? -1 : ca.compare(cb);
1688
+ if (cmp === 0) {
1689
+ const same = ca.mode === cb.mode && ca.sameId(cb);
1690
+ if (!same) {
1691
+ if (!isTreeMode(ca.mode) || !isTreeMode(cb.mode)) return true;
1692
+ if (await this.treesDiffer(ca.id(), cb.id(), ps, ca.below(base))) return true;
1693
+ }
1694
+ ca.next();
1695
+ cb.next();
1696
+ continue;
1697
+ }
1698
+ // an entry on one side only: a file is a change, a directory is walked against nothing
1699
+ const one = cmp < 0 ? ca : cb;
1700
+ if (!isTreeMode(one.mode)) return true;
1701
+ const sub = one.id();
1702
+ const below =
1703
+ cmp < 0
1704
+ ? await this.treesDiffer(sub, undefined, ps, one.below(base))
1705
+ : await this.treesDiffer(undefined, sub, ps, one.below(base));
1706
+ if (below) return true;
1707
+ one.next();
486
1708
  }
1709
+ }
487
1710
 
488
- // Check each excluded path - if ALL changes are to excluded paths, return true
489
- for (const path of this.excludePaths) {
490
- const entryInCurrent = await this.getTreeEntryForPath(commit.tree, path);
491
- const entryInParent = await this.getTreeEntryForPath(parentCommit.tree, path);
1711
+ /**
1712
+ * The attributes `treeEntryInteresting` asks for (an `:(attr)` element), read as git's
1713
+ * match_pathspec_attrs reads them in `git log`: the check-in direction (the worktree's
1714
+ * `.gitattributes` first, then the index's) with no index read, so only the worktree's
1715
+ * files count, below `$GIT_DIR/info/attributes` and over `core.attributesFile` and the
1716
+ * system file; with an attribute source (`$GIT_ATTR_SOURCE`, `attr.tree`) the in-tree files
1717
+ * are its tree's. A bare repository has no in-tree files without one (git 2.56 reads none
1718
+ * without `attr.tree`): only the files outside the tree.
1719
+ */
1720
+ private async loadAttributes(ps: TreePathspec): Promise<void> {
1721
+ const attributes = ps.attributes;
1722
+ const path = attributes?.pending;
1723
+ if (!attributes || path === undefined) return;
1724
+ attributes.pending = undefined;
1725
+ attributes.values.set(path, await this.readAttributes(path, attributes.names));
1726
+ }
1727
+
1728
+ /** The attributes `names` of `path` as {@link loadAttributes} reads them. */
1729
+ private async readAttributes(
1730
+ path: string,
1731
+ names: readonly string[],
1732
+ ): Promise<Map<string, PathspecAttributeValue>> {
1733
+ // a bare repository's working copy refuses its worktree: asked without touching it
1734
+ const worktree = "worktree" in this._workingCopy ? this.worktreeAccess : undefined;
1735
+ if (!worktree) return this.bareAttributes().get(path, names);
1736
+ const filter = worktree.contentFilter as
1737
+ | {
1738
+ attributes?(
1739
+ path: string,
1740
+ names: readonly string[],
1741
+ direction?: ContentAttributesContext,
1742
+ ): Promise<Map<string, PathspecAttributeValue>>;
1743
+ }
1744
+ | undefined;
1745
+ if (!filter?.attributes)
1746
+ throw new GitApiError("pathspec magic 'attr' needs the attributes of a worktree");
1747
+ return filter.attributes(path, names, { direction: "checkin", index: NO_INDEX });
1748
+ }
492
1749
 
493
- const currentId = entryInCurrent?.objectId;
494
- const parentId = entryInParent?.objectId;
1750
+ private bareResolver?: AttributesResolver;
495
1751
 
496
- if (currentId !== parentId) {
497
- // This excluded path was modified - check if there are non-excluded changes
498
- // For simplicity, we filter out commits that touch any excluded path
499
- return true;
1752
+ /** The attributes of a bare repository (see {@link bareAttributesResolver}). */
1753
+ private bareAttributes(): AttributesResolver {
1754
+ this.bareResolver ??= bareAttributesResolver({
1755
+ workingCopy: this._workingCopy,
1756
+ trees: this.trees,
1757
+ blobs: this.blobs,
1758
+ revisions: () => this.revisionResolver(),
1759
+ });
1760
+ return this.bareResolver;
1761
+ }
1762
+
1763
+ /** A tree's raw bytes; git's "unable to read tree" when it is missing. */
1764
+ private async requireTree(id: ObjectId): Promise<Uint8Array> {
1765
+ const raw = await this.rawTree(id);
1766
+ if (raw instanceof Uint8Array) return raw;
1767
+ if (raw === null) {
1768
+ // no raw object store: the entries are encoded back
1769
+ const entries = await this.trees.load(id);
1770
+ if (!entries) throw new GitApiError(`unable to read tree (${id})`);
1771
+ const parts: Uint8Array[] = [];
1772
+ for await (const e of entries) {
1773
+ parts.push(
1774
+ NAME_ENCODER.encode(`${e.mode.toString(8)} `),
1775
+ encodeGitPath(e.name),
1776
+ new Uint8Array(1),
1777
+ hexToBytes(e.id),
1778
+ );
500
1779
  }
1780
+ return concatBytes(parts);
501
1781
  }
1782
+ throw new GitApiError(`unable to read tree (${id})`);
1783
+ }
502
1784
 
503
- return false;
1785
+ /**
1786
+ * Whether the entries at `parts[i..]` below trees `a` and `b` differ (git's pathspec match:
1787
+ * the path itself, or anything below it). Equal subtrees end the walk down.
1788
+ */
1789
+ private async differsAtPath(
1790
+ a: ObjectId | undefined,
1791
+ b: ObjectId | undefined,
1792
+ parts: Uint8Array[],
1793
+ i: number,
1794
+ ): Promise<boolean> {
1795
+ // the whole tree (`.`, `:/`): a root commit compares with the empty tree, as in git
1796
+ if (parts.length === 0) return (a ?? EMPTY_TREE_ID) !== (b ?? EMPTY_TREE_ID);
1797
+ const name = parts[i] as Uint8Array;
1798
+ const ea = a ? await this.entryOf(a, name) : undefined;
1799
+ const eb = b ? await this.entryOf(b, name) : undefined;
1800
+ if (!ea && !eb) return false;
1801
+ if (ea && eb && ea.id === eb.id && canonTreeMode(ea.mode) === canonTreeMode(eb.mode)) {
1802
+ return false;
1803
+ }
1804
+ if (i === parts.length - 1) return true;
1805
+ const ta = ea && isTreeMode(ea.mode) ? ea.id : undefined;
1806
+ const tb = eb && isTreeMode(eb.mode) ? eb.id : undefined;
1807
+ if (!ta && !tb) return false;
1808
+ return this.differsAtPath(ta, tb, parts, i + 1);
504
1809
  }
505
1810
 
506
1811
  /**
507
- * Check if tree contains any of the filtered paths.
1812
+ * Entry `name` of tree `tree`: found in the tree's raw bytes (no entry is decoded but the
1813
+ * one asked for) when the store gives them, else through the tree store.
508
1814
  */
509
- private async treeHasPath(treeId: ObjectId): Promise<boolean> {
510
- for (const path of this.paths) {
511
- const entry = await this.getTreeEntryForPath(treeId, path);
512
- if (entry) {
513
- return true;
514
- }
1815
+ private async entryOf(
1816
+ tree: ObjectId,
1817
+ name: Uint8Array,
1818
+ ): Promise<{ id: ObjectId; mode: number } | undefined> {
1819
+ this.statistics.treeEntryReads++;
1820
+ const raw = await this.rawTree(tree);
1821
+ if (raw === null) return this.trees.getEntry(tree, NAME_DECODER.decode(name));
1822
+ if (raw === undefined) throw new GitApiError(`unable to read tree (${tree})`);
1823
+ return findRawEntry(raw, name);
1824
+ }
1825
+
1826
+ /** The replace refs a walk's tree reads follow; undefined without any. */
1827
+ private treeReplacements?: ReadonlyMap<ObjectId, ObjectId>;
1828
+
1829
+ /** Raw trees read lately, most recently used last: a commit's trees are its child's parent trees. */
1830
+ private readonly rawTrees = new OrderedMap<ObjectId, Uint8Array>();
1831
+ private rawTreeBytes = 0;
1832
+
1833
+ /** The raw bytes of a tree; undefined when it is missing, null without a raw object store. */
1834
+ private async rawTree(tree: ObjectId): Promise<Uint8Array | undefined | null> {
1835
+ const id = this.treeReplacements ? replacementOf(this.treeReplacements, tree) : tree;
1836
+ // the empty tree, which a store need not hold
1837
+ if (id === EMPTY_TREE_ID) return EMPTY_TREE;
1838
+ const cached = this.rawTrees.get(id);
1839
+ if (cached) {
1840
+ this.rawTrees.delete(id);
1841
+ this.rawTrees.set(id, cached);
1842
+ return cached;
1843
+ }
1844
+ const objects = this._workingCopy.history?.objects;
1845
+ if (!objects) return null;
1846
+ let obj: GitObject | undefined;
1847
+ try {
1848
+ const now = objects.getNow ? objects.getNow(id) : objects.get(id);
1849
+ obj = now instanceof Promise ? await now : now;
1850
+ } catch {
1851
+ return null;
1852
+ }
1853
+ if (!obj) return undefined;
1854
+ if (obj.type !== "tree") {
1855
+ await obj.content[Symbol.asyncIterator]().return?.();
1856
+ return null;
515
1857
  }
516
- return false;
1858
+ let bytes = obj.bytes;
1859
+ if (!bytes) {
1860
+ const chunks: Uint8Array[] = [];
1861
+ for await (const c of obj.content) chunks.push(c);
1862
+ bytes = concatBytes(chunks);
1863
+ }
1864
+ this.rawTrees.set(id, bytes);
1865
+ this.rawTreeBytes += bytes.length;
1866
+ while (this.rawTrees.size > RAW_TREE_CACHE || this.rawTreeBytes > RAW_TREE_CACHE_BYTES) {
1867
+ const oldest = this.rawTrees.oldestKey() as ObjectId;
1868
+ if (oldest === id) break;
1869
+ this.rawTreeBytes -= (this.rawTrees.get(oldest) as Uint8Array).length;
1870
+ this.rawTrees.delete(oldest);
1871
+ }
1872
+ return bytes;
517
1873
  }
518
1874
 
519
1875
  /**
520
- * Get tree entry for a path (supports nested paths).
1876
+ * Check if commit author matches the filter pattern.
521
1877
  */
522
- private async getTreeEntryForPath(
523
- treeId: ObjectId,
524
- path: string,
525
- ): Promise<{ objectId: ObjectId; mode: number } | undefined> {
526
- const parts = path.split("/").filter((p) => p.length > 0);
527
- let currentTreeId = treeId;
1878
+ private matchesAuthor(commit: Commit): boolean {
1879
+ if (!this.authorPattern) return true;
1880
+ const authorStr = `${commit.author.name} <${commit.author.email}>`.toLowerCase();
1881
+ return authorStr.includes(this.authorPattern);
1882
+ }
528
1883
 
529
- for (let i = 0; i < parts.length; i++) {
530
- const name = parts[i];
531
- const isLast = i === parts.length - 1;
1884
+ /**
1885
+ * Check if commit committer matches the filter pattern.
1886
+ */
1887
+ private matchesCommitter(commit: Commit): boolean {
1888
+ if (!this.committerPattern) return true;
1889
+ const committerStr = `${commit.committer.name} <${commit.committer.email}>`.toLowerCase();
1890
+ return committerStr.includes(this.committerPattern);
1891
+ }
1892
+ }
532
1893
 
533
- const entry = await this.trees.getEntry(currentTreeId, name);
1894
+ const isTreeMode = (mode: number) => (mode & 0o170000) === 0o040000;
534
1895
 
535
- if (!entry) {
536
- return undefined;
537
- }
1896
+ const NAME_ENCODER = new TextEncoder();
1897
+ const NAME_DECODER = new TextDecoder();
538
1898
 
539
- if (isLast) {
540
- return { objectId: entry.id, mode: entry.mode };
541
- }
1899
+ /** Raw trees a path-limited walk keeps. */
1900
+ const RAW_TREE_CACHE = 512;
542
1901
 
543
- // Navigate into subtree
544
- currentTreeId = entry.id;
1902
+ /** The bytes of raw trees a path-limited walk keeps at most (besides the one just read). */
1903
+ const RAW_TREE_CACHE_BYTES = 32 * 1024 * 1024;
1904
+
1905
+ const EMPTY_TREE = new Uint8Array(0);
1906
+
1907
+ // revision.c's object flags, as the walk uses them
1908
+ const UNINTERESTING = 1 << 1;
1909
+ const BOTTOM = 1 << 2;
1910
+ const SEEN = 1 << 3;
1911
+ const ADDED = 1 << 4;
1912
+ const TREESAME = 1 << 5;
1913
+
1914
+ /** How many extra uninteresting commits limit_list looks at (git's SLOP). */
1915
+ const SLOP = 5;
1916
+
1917
+ /**
1918
+ * The commits a walk meets, as revision.c's object table holds them: flags, and once parsed
1919
+ * the date, the parents and (outside the commit-graph) the tree. Each commit is a number
1920
+ * indexing typed arrays, a few dozen bytes per commit instead of an object with its id, tree
1921
+ * and parent array. Commits the graph has are found by graph position (`lookupPos`), their
1922
+ * ids and trees read from the graph when needed; others by id.
1923
+ */
1924
+ class RevTable {
1925
+ /** commits held */
1926
+ size = 0;
1927
+ /** revision.c flags (UNINTERESTING, SEEN, ...) */
1928
+ flags = new Uint8Array(INITIAL_REVS);
1929
+ /** committer dates (seconds) */
1930
+ private dates = new Float64Array(INITIAL_REVS);
1931
+ /** position in the commit-graph, -1 for a commit it does not have */
1932
+ gpos = new Int32Array(INITIAL_REVS);
1933
+ /** where the parents start in `pool`, once parsed */
1934
+ private parentAt = new Int32Array(INITIAL_REVS);
1935
+ /** how many parents, -1 before the commit is parsed */
1936
+ private parents = new Int32Array(INITIAL_REVS);
1937
+ /** every parsed commit's parents, in turn */
1938
+ private pool = new Int32Array(INITIAL_REVS);
1939
+ private poolUsed = 0;
1940
+ /** ids known without the graph (looked up by id), by commit */
1941
+ private readonly ids: (ObjectId | undefined)[] = [];
1942
+ /** trees of commits parsed outside the graph, by commit */
1943
+ private readonly trees: (ObjectId | undefined)[] = [];
1944
+ /** commits outside the graph, by id */
1945
+ private readonly byId = new Map<ObjectId, number>();
1946
+ /** commit + 1 by graph position (0: not met yet) */
1947
+ private readonly byPos: Int32Array | undefined;
1948
+
1949
+ constructor(private readonly graph: CommitGraph | undefined) {
1950
+ this.byPos = graph ? new Int32Array(graph.size) : undefined;
1951
+ }
1952
+
1953
+ /** Bytes the table's arrays take (the ids and trees kept besides them not counted). */
1954
+ get bytes(): number {
1955
+ return (
1956
+ this.flags.byteLength +
1957
+ this.dates.byteLength +
1958
+ this.gpos.byteLength +
1959
+ this.parentAt.byteLength +
1960
+ this.parents.byteLength +
1961
+ this.pool.byteLength +
1962
+ (this.byPos?.byteLength ?? 0)
1963
+ );
1964
+ }
1965
+
1966
+ /** The commit `id`, added when first met (git's lookup_commit). */
1967
+ lookup(id: ObjectId): number {
1968
+ const known = this.byId.get(id);
1969
+ if (known !== undefined) return known;
1970
+ const pos = this.graph ? this.graph.position(id) : -1;
1971
+ if (pos >= 0) {
1972
+ const n = this.lookupPos(pos);
1973
+ this.ids[n] = id;
1974
+ return n;
545
1975
  }
1976
+ const n = this.add(-1);
1977
+ this.ids[n] = id;
1978
+ this.byId.set(id, n);
1979
+ return n;
1980
+ }
1981
+
1982
+ /** The commit at graph position `pos`, added when first met. */
1983
+ lookupPos(pos: number): number {
1984
+ const byPos = this.byPos as Int32Array;
1985
+ const known = (byPos[pos] as number) - 1;
1986
+ if (known >= 0) return known;
1987
+ const n = this.add(pos);
1988
+ byPos[pos] = n + 1;
1989
+ return n;
1990
+ }
1991
+
1992
+ idOf(n: number): ObjectId {
1993
+ return this.ids[n] ?? (this.graph as CommitGraph).idAt(this.gpos[n] as number);
1994
+ }
546
1995
 
1996
+ flag(n: number): number {
1997
+ return this.flags[n] as number;
1998
+ }
1999
+
2000
+ mark(n: number, flags: number): void {
2001
+ this.flags[n] = (this.flags[n] as number) | flags;
2002
+ }
2003
+
2004
+ unmark(n: number, flags: number): void {
2005
+ this.flags[n] = (this.flags[n] as number) & ~flags;
2006
+ }
2007
+
2008
+ parsed(n: number): boolean {
2009
+ return (this.parents[n] as number) >= 0;
2010
+ }
2011
+
2012
+ date(n: number): number {
2013
+ return this.dates[n] as number;
2014
+ }
2015
+
2016
+ /** The tree of a parsed commit. */
2017
+ treeOf(n: number): ObjectId {
2018
+ if ((this.flags[n] as number) & GRAPH_PARSED)
2019
+ return (this.graph as CommitGraph).treeAt(this.gpos[n] as number);
2020
+ return this.trees[n] as ObjectId;
2021
+ }
2022
+
2023
+ /** The graph position of a commit parsed from the graph (its Bloom filter), else -1. */
2024
+ bloomPos(n: number): number {
2025
+ return (this.flags[n] as number) & GRAPH_PARSED ? (this.gpos[n] as number) : -1;
2026
+ }
2027
+
2028
+ /** Records a commit as parsed, with room for `count` parents (`setParent`). */
2029
+ setParsed(
2030
+ n: number,
2031
+ date: number,
2032
+ fromGraph: boolean,
2033
+ tree: ObjectId | undefined,
2034
+ count: number,
2035
+ ): void {
2036
+ this.dates[n] = date;
2037
+ if (fromGraph) this.mark(n, GRAPH_PARSED);
2038
+ else this.trees[n] = tree;
2039
+ if (this.poolUsed + count > this.pool.length) {
2040
+ const grown = new Int32Array(Math.max(this.pool.length * 2, this.poolUsed + count));
2041
+ grown.set(this.pool);
2042
+ this.pool = grown;
2043
+ }
2044
+ this.parentAt[n] = this.poolUsed;
2045
+ this.parents[n] = count;
2046
+ this.poolUsed += count;
2047
+ }
2048
+
2049
+ setParent(n: number, k: number, p: number): void {
2050
+ this.pool[(this.parentAt[n] as number) + k] = p;
2051
+ }
2052
+
2053
+ /** The parents of a parsed commit (0 before it is parsed). */
2054
+ parentCount(n: number): number {
2055
+ return Math.max(0, this.parents[n] as number);
2056
+ }
2057
+
2058
+ parent(n: number, k: number): number {
2059
+ return this.pool[(this.parentAt[n] as number) + k] as number;
2060
+ }
2061
+
2062
+ /** Simplification keeps only parent `p` (git rewrites `commit->parents`). */
2063
+ keepOnlyParent(n: number, p: number): void {
2064
+ this.pool[this.parentAt[n] as number] = p;
2065
+ this.parents[n] = 1;
2066
+ }
2067
+
2068
+ private add(pos: number): number {
2069
+ const n = this.size++;
2070
+ if (n === this.flags.length) this.grow();
2071
+ this.gpos[n] = pos;
2072
+ this.parents[n] = -1;
2073
+ return n;
2074
+ }
2075
+
2076
+ private grow(): void {
2077
+ const size = this.flags.length * 2;
2078
+ const flags = new Uint8Array(size);
2079
+ flags.set(this.flags);
2080
+ this.flags = flags;
2081
+ const dates = new Float64Array(size);
2082
+ dates.set(this.dates);
2083
+ this.dates = dates;
2084
+ const gpos = new Int32Array(size);
2085
+ gpos.set(this.gpos);
2086
+ this.gpos = gpos;
2087
+ const parentAt = new Int32Array(size);
2088
+ parentAt.set(this.parentAt);
2089
+ this.parentAt = parentAt;
2090
+ const parents = new Int32Array(size);
2091
+ parents.set(this.parents);
2092
+ this.parents = parents;
2093
+ }
2094
+ }
2095
+
2096
+ /** Commits a `RevTable` has room for before it first grows. */
2097
+ const INITIAL_REVS = 1024;
2098
+ /** `RevTable` flag: parsed from the commit-graph (its tree and Bloom filter are there). */
2099
+ const GRAPH_PARSED = 1 << 6;
2100
+
2101
+ /** A commit read whole, as the commit store decodes it; undefined if it does not parse. */
2102
+ function decodeCommit(bytes: Uint8Array): Commit | undefined {
2103
+ try {
2104
+ return commitFromBytes(bytes);
2105
+ } catch {
547
2106
  return undefined;
548
2107
  }
549
2108
  }
2109
+
2110
+ /** memcmp order of two byte strings */
2111
+ function compareBytes(a: Uint8Array, b: Uint8Array): number {
2112
+ const n = Math.min(a.length, b.length);
2113
+ for (let i = 0; i < n; i++) {
2114
+ if (a[i] !== b[i]) return (a[i] as number) - (b[i] as number);
2115
+ }
2116
+ return a.length - b.length;
2117
+ }
2118
+
2119
+ function concatBytes(chunks: Uint8Array[]): Uint8Array {
2120
+ if (chunks.length === 1) return chunks[0] as Uint8Array;
2121
+ const out = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));
2122
+ let at = 0;
2123
+ for (const c of chunks) {
2124
+ out.set(c, at);
2125
+ at += c.length;
2126
+ }
2127
+ return out;
2128
+ }
2129
+
2130
+ /** The entry named `name` (raw bytes) in raw tree `d`: its id and mode, or undefined. */
2131
+ function findRawEntry(d: Uint8Array, name: Uint8Array): { id: ObjectId; mode: number } | undefined {
2132
+ let p = 0;
2133
+ const n = name.length;
2134
+ while (p < d.length) {
2135
+ let mode = 0;
2136
+ while (p < d.length && d[p] !== 0x20) mode = mode * 8 + ((d[p++] as number) - 0x30);
2137
+ p++;
2138
+ const start = p;
2139
+ while (p < d.length && d[p] !== 0) p++;
2140
+ const idAt = p + 1;
2141
+ if (p - start === n) {
2142
+ let k = 0;
2143
+ while (k < n && d[start + k] === name[k]) k++;
2144
+ if (k === n) return { id: bytesToHex(d.subarray(idAt, idAt + 20)), mode };
2145
+ }
2146
+ p = idAt + 20;
2147
+ }
2148
+ return undefined;
2149
+ }
2150
+
2151
+ /** A path's components, without empty ones and "." (git's pathspec normalisation). */
2152
+ const pathParts = (path: string) =>
2153
+ path.split("/").filter((part) => part.length > 0 && part !== ".");
2154
+
2155
+ /**
2156
+ * git's prio_queue with compare_commits_by_commit_date: the newest commit first, commits of
2157
+ * one date in the order they were put.
2158
+ */
2159
+ class CommitQueue<T> {
2160
+ private entries: T[] = [];
2161
+ private dates: number[] = [];
2162
+ private ctrs: number[] = [];
2163
+ private ctr = 0;
2164
+
2165
+ put(entry: T, date: number): void {
2166
+ const { entries, dates, ctrs } = this;
2167
+ let ix = entries.length;
2168
+ entries.push(entry);
2169
+ dates.push(date);
2170
+ ctrs.push(this.ctr++);
2171
+ while (ix > 0) {
2172
+ const parent = (ix - 1) >> 1;
2173
+ if (this.before(parent, ix)) break;
2174
+ this.swap(parent, ix);
2175
+ ix = parent;
2176
+ }
2177
+ }
2178
+
2179
+ get(): T | undefined {
2180
+ const { entries } = this;
2181
+ if (entries.length === 0) return undefined;
2182
+ const top = entries[0];
2183
+ const last = entries.length - 1;
2184
+ this.swap(0, last);
2185
+ entries.pop();
2186
+ this.dates.pop();
2187
+ this.ctrs.pop();
2188
+ let ix = 0;
2189
+ for (;;) {
2190
+ let child = 2 * ix + 1;
2191
+ if (child >= entries.length) break;
2192
+ if (child + 1 < entries.length && this.before(child + 1, child)) child++;
2193
+ if (this.before(ix, child)) break;
2194
+ this.swap(ix, child);
2195
+ ix = child;
2196
+ }
2197
+ return top;
2198
+ }
2199
+
2200
+ /** The entry `get` returns next (git's prio_queue_peek). */
2201
+ peek(): T | undefined {
2202
+ return this.entries[0];
2203
+ }
2204
+
2205
+ /** The entries in heap order (git's prio_queue_for_each). */
2206
+ items(): readonly T[] {
2207
+ return this.entries;
2208
+ }
2209
+
2210
+ /** Whether entry `a` comes out before entry `b`. */
2211
+ private before(a: number, b: number): boolean {
2212
+ const da = this.dates[a] as number;
2213
+ const db = this.dates[b] as number;
2214
+ if (da !== db) return da > db;
2215
+ return (this.ctrs[a] as number) < (this.ctrs[b] as number);
2216
+ }
2217
+
2218
+ private swap(a: number, b: number): void {
2219
+ const { entries, dates, ctrs } = this;
2220
+ [entries[a], entries[b]] = [entries[b] as T, entries[a] as T];
2221
+ [dates[a], dates[b]] = [dates[b] as number, dates[a] as number];
2222
+ [ctrs[a], ctrs[b]] = [ctrs[b] as number, ctrs[a] as number];
2223
+ }
2224
+ }
2225
+
2226
+ /**
2227
+ * A cursor over a raw tree's entries for the pruned diff: `read()` decodes the entry at `at`
2228
+ * (its mode, where its name starts and ends), `next()` moves past it. Names stay bytes.
2229
+ */
2230
+ class RawEntries {
2231
+ at = 0;
2232
+ mode = 0;
2233
+ nameStart = 0;
2234
+ /** where the name ends (its NUL; the id follows) */
2235
+ nul = 0;
2236
+ constructor(readonly d: Uint8Array) {}
2237
+ get done(): boolean {
2238
+ return this.at >= this.d.length;
2239
+ }
2240
+ read(): void {
2241
+ const d = this.d;
2242
+ let p = this.at;
2243
+ let mode = 0;
2244
+ while (p < d.length && d[p] !== 0x20) mode = mode * 8 + ((d[p++] as number) - 0x30);
2245
+ // the mode as git's tree walk reads it (canon_mode): 100664 is 100644
2246
+ this.mode = canonTreeMode(mode);
2247
+ this.nameStart = ++p;
2248
+ while (p < d.length && d[p] !== 0) p++;
2249
+ this.nul = p;
2250
+ }
2251
+ next(): void {
2252
+ this.at = this.nul + 21;
2253
+ }
2254
+ id(): ObjectId {
2255
+ return bytesToHex(this.d.subarray(this.nul + 1, this.nul + 21));
2256
+ }
2257
+ /** The base of the entries below this one (a directory): `base`, its name and "/". */
2258
+ below(base: Uint8Array): Uint8Array {
2259
+ const length = this.nul - this.nameStart;
2260
+ const out = new Uint8Array(base.length + length + 1);
2261
+ out.set(base);
2262
+ out.set(this.d.subarray(this.nameStart, this.nul), base.length);
2263
+ out[base.length + length] = 0x2f;
2264
+ return out;
2265
+ }
2266
+ sameId(other: RawEntries): boolean {
2267
+ for (let k = 1; k <= 20; k++) {
2268
+ if (this.d[this.nul + k] !== other.d[other.nul + k]) return false;
2269
+ }
2270
+ return true;
2271
+ }
2272
+ /** git's base_name_compare of the names: a tree's name is followed by "/". */
2273
+ compare(other: RawEntries): number {
2274
+ const a = this.d;
2275
+ const b = other.d;
2276
+ const la = this.nul - this.nameStart;
2277
+ const lb = other.nul - other.nameStart;
2278
+ const n = Math.min(la, lb);
2279
+ for (let i = 0; i < n; i++) {
2280
+ const d = (a[this.nameStart + i] as number) - (b[other.nameStart + i] as number);
2281
+ if (d !== 0) return d;
2282
+ }
2283
+ const ca = n < la ? (a[this.nameStart + n] as number) : isTreeMode(this.mode) ? 0x2f : 0;
2284
+ const cb = n < lb ? (b[other.nameStart + n] as number) : isTreeMode(other.mode) ? 0x2f : 0;
2285
+ return ca - cb;
2286
+ }
2287
+ }
2288
+
2289
+ /** `diff.algorithm` as diff.c's parse_algorithm_value reads it (undefined: not one) */
2290
+ function configAlgorithm(v: string | undefined): XdiffAlgorithm | undefined {
2291
+ const s = v?.trim().toLowerCase();
2292
+ if (s === "default") return "myers";
2293
+ return s === "myers" || s === "minimal" || s === "patience" || s === "histogram" ? s : undefined;
2294
+ }