@statewalker/vcs-commands 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/dist/commands/add-command.d.ts +32 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/add-patch.d.ts +7 -0
  4. package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  6. package/dist/commands/am/am-command.d.ts +47 -0
  7. package/dist/commands/am/am-command.d.ts.map +1 -1
  8. package/dist/commands/apply/apply-command.d.ts +2 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-parse.d.ts +7 -0
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/apply/index.d.ts +1 -1
  13. package/dist/commands/apply/index.d.ts.map +1 -1
  14. package/dist/commands/blame-command.d.ts +303 -8
  15. package/dist/commands/blame-command.d.ts.map +1 -1
  16. package/dist/commands/blame-ignore.d.ts +48 -0
  17. package/dist/commands/blame-ignore.d.ts.map +1 -0
  18. package/dist/commands/check-mailmap-command.d.ts +49 -0
  19. package/dist/commands/check-mailmap-command.d.ts.map +1 -0
  20. package/dist/commands/checkout-command.d.ts +7 -0
  21. package/dist/commands/checkout-command.d.ts.map +1 -1
  22. package/dist/commands/checkout-paths.d.ts +4 -0
  23. package/dist/commands/checkout-paths.d.ts.map +1 -1
  24. package/dist/commands/cherry-command.d.ts +61 -0
  25. package/dist/commands/cherry-command.d.ts.map +1 -0
  26. package/dist/commands/cherry-pick-command.d.ts +23 -1
  27. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  28. package/dist/commands/clean-command.d.ts +32 -0
  29. package/dist/commands/clean-command.d.ts.map +1 -1
  30. package/dist/commands/clean-interactive.d.ts +56 -0
  31. package/dist/commands/clean-interactive.d.ts.map +1 -0
  32. package/dist/commands/clone-command.d.ts +116 -2
  33. package/dist/commands/clone-command.d.ts.map +1 -1
  34. package/dist/commands/commit-command.d.ts +50 -2
  35. package/dist/commands/commit-command.d.ts.map +1 -1
  36. package/dist/commands/describe-command.d.ts +71 -64
  37. package/dist/commands/describe-command.d.ts.map +1 -1
  38. package/dist/commands/diff-command.d.ts +118 -6
  39. package/dist/commands/diff-command.d.ts.map +1 -1
  40. package/dist/commands/fetch-command.d.ts +60 -0
  41. package/dist/commands/fetch-command.d.ts.map +1 -1
  42. package/dist/commands/fetch-multiple-command.d.ts +193 -0
  43. package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
  44. package/dist/commands/format-patch-command.d.ts +28 -2
  45. package/dist/commands/format-patch-command.d.ts.map +1 -1
  46. package/dist/commands/git-describe.d.ts +77 -4
  47. package/dist/commands/git-describe.d.ts.map +1 -1
  48. package/dist/commands/git-hooks.d.ts +15 -1
  49. package/dist/commands/git-hooks.d.ts.map +1 -1
  50. package/dist/commands/index.d.ts +12 -0
  51. package/dist/commands/index.d.ts.map +1 -1
  52. package/dist/commands/index.js +5 -3
  53. package/dist/commands/init-command.d.ts +89 -0
  54. package/dist/commands/init-command.d.ts.map +1 -1
  55. package/dist/commands/line-log.d.ts +161 -0
  56. package/dist/commands/line-log.d.ts.map +1 -0
  57. package/dist/commands/log-command.d.ts +235 -6
  58. package/dist/commands/log-command.d.ts.map +1 -1
  59. package/dist/commands/log-graph.d.ts +4 -2
  60. package/dist/commands/log-graph.d.ts.map +1 -1
  61. package/dist/commands/log-output.d.ts +66 -1
  62. package/dist/commands/log-output.d.ts.map +1 -1
  63. package/dist/commands/mailmap.d.ts +24 -1
  64. package/dist/commands/mailmap.d.ts.map +1 -1
  65. package/dist/commands/merge-command.d.ts +51 -1
  66. package/dist/commands/merge-command.d.ts.map +1 -1
  67. package/dist/commands/merge-drivers.d.ts +2 -0
  68. package/dist/commands/merge-drivers.d.ts.map +1 -1
  69. package/dist/commands/merge-strategy-options.d.ts +69 -0
  70. package/dist/commands/merge-strategy-options.d.ts.map +1 -0
  71. package/dist/commands/merge-support.d.ts +10 -0
  72. package/dist/commands/merge-support.d.ts.map +1 -1
  73. package/dist/commands/message-cleanup.d.ts +2 -0
  74. package/dist/commands/message-cleanup.d.ts.map +1 -1
  75. package/dist/commands/name-rev-command.d.ts +65 -0
  76. package/dist/commands/name-rev-command.d.ts.map +1 -0
  77. package/dist/commands/name-rev.d.ts +110 -22
  78. package/dist/commands/name-rev.d.ts.map +1 -1
  79. package/dist/commands/octopus-merge.d.ts +26 -1
  80. package/dist/commands/octopus-merge.d.ts.map +1 -1
  81. package/dist/commands/ort-merge.d.ts +16 -0
  82. package/dist/commands/ort-merge.d.ts.map +1 -1
  83. package/dist/commands/ort-recursive.d.ts.map +1 -1
  84. package/dist/commands/patch-id.d.ts +58 -0
  85. package/dist/commands/patch-id.d.ts.map +1 -1
  86. package/dist/commands/pull-command.d.ts +182 -38
  87. package/dist/commands/pull-command.d.ts.map +1 -1
  88. package/dist/commands/push-command.d.ts +65 -0
  89. package/dist/commands/push-command.d.ts.map +1 -1
  90. package/dist/commands/range-diff/index.d.ts +4 -0
  91. package/dist/commands/range-diff/index.d.ts.map +1 -0
  92. package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
  93. package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
  94. package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
  95. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
  96. package/dist/commands/range-diff/range-diff.d.ts +106 -0
  97. package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
  98. package/dist/commands/read-tree-command.d.ts +14 -0
  99. package/dist/commands/read-tree-command.d.ts.map +1 -1
  100. package/dist/commands/rebase-command.d.ts +21 -2
  101. package/dist/commands/rebase-command.d.ts.map +1 -1
  102. package/dist/commands/remerge-diff.d.ts +59 -0
  103. package/dist/commands/remerge-diff.d.ts.map +1 -0
  104. package/dist/commands/remote-command.d.ts +41 -0
  105. package/dist/commands/remote-command.d.ts.map +1 -1
  106. package/dist/commands/remote-show-command.d.ts +204 -0
  107. package/dist/commands/remote-show-command.d.ts.map +1 -0
  108. package/dist/commands/reset-command.d.ts +19 -1
  109. package/dist/commands/reset-command.d.ts.map +1 -1
  110. package/dist/commands/restore-command.d.ts +7 -0
  111. package/dist/commands/restore-command.d.ts.map +1 -1
  112. package/dist/commands/rev-list-command.d.ts +75 -3
  113. package/dist/commands/rev-list-command.d.ts.map +1 -1
  114. package/dist/commands/revert-command.d.ts +22 -1
  115. package/dist/commands/revert-command.d.ts.map +1 -1
  116. package/dist/commands/revision-range.d.ts +2 -0
  117. package/dist/commands/revision-range.d.ts.map +1 -1
  118. package/dist/commands/sequencer-pick.d.ts +102 -1
  119. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  120. package/dist/commands/sequencer-support.d.ts +10 -1
  121. package/dist/commands/sequencer-support.d.ts.map +1 -1
  122. package/dist/commands/shortlog-command.d.ts +109 -0
  123. package/dist/commands/shortlog-command.d.ts.map +1 -0
  124. package/dist/commands/shortlog.d.ts +151 -0
  125. package/dist/commands/shortlog.d.ts.map +1 -0
  126. package/dist/commands/status-command.d.ts +31 -2
  127. package/dist/commands/status-command.d.ts.map +1 -1
  128. package/dist/commands/submodule-commands.d.ts +90 -2
  129. package/dist/commands/submodule-commands.d.ts.map +1 -1
  130. package/dist/commands/submodule-fetch.d.ts +149 -0
  131. package/dist/commands/submodule-fetch.d.ts.map +1 -0
  132. package/dist/commands/submodule-model.d.ts +8 -0
  133. package/dist/commands/submodule-model.d.ts.map +1 -1
  134. package/dist/commands/submodule-unpack.d.ts +120 -0
  135. package/dist/commands/submodule-unpack.d.ts.map +1 -0
  136. package/dist/commands/submodule-update-command.d.ts +8 -0
  137. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  138. package/dist/commands/subtree-shift.d.ts +27 -0
  139. package/dist/commands/subtree-shift.d.ts.map +1 -0
  140. package/dist/commands/switch-command.d.ts +3 -0
  141. package/dist/commands/switch-command.d.ts.map +1 -1
  142. package/dist/commands/tree-restore.d.ts.map +1 -1
  143. package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
  144. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  145. package/dist/{commands-ISM52N0n.js → commands-CNvli5bl.js} +39426 -61169
  146. package/dist/errors/command-errors.d.ts +25 -0
  147. package/dist/errors/command-errors.d.ts.map +1 -1
  148. package/dist/errors/index.js +29 -1
  149. package/dist/fsck-CPeDh9fh.js +5138 -0
  150. package/dist/git-command.d.ts +31 -1
  151. package/dist/git-command.d.ts.map +1 -1
  152. package/dist/git.d.ts +97 -1
  153. package/dist/git.d.ts.map +1 -1
  154. package/dist/guarded-transport-command.d.ts +82 -0
  155. package/dist/guarded-transport-command.d.ts.map +1 -0
  156. package/dist/index.d.ts +1 -0
  157. package/dist/index.d.ts.map +1 -1
  158. package/dist/index.js +6 -5
  159. package/dist/remote-transport-CCmBadm-.js +1606 -0
  160. package/dist/rename/detect-renames.d.ts +20 -0
  161. package/dist/rename/detect-renames.d.ts.map +1 -1
  162. package/dist/rename/diffcore-break.d.ts +51 -0
  163. package/dist/rename/diffcore-break.d.ts.map +1 -0
  164. package/dist/rename/index.d.ts +1 -0
  165. package/dist/rename/index.d.ts.map +1 -1
  166. package/dist/results/blame-format.d.ts +62 -1
  167. package/dist/results/blame-format.d.ts.map +1 -1
  168. package/dist/results/clone-result.d.ts +9 -0
  169. package/dist/results/clone-result.d.ts.map +1 -1
  170. package/dist/results/diff-dirstat.d.ts +36 -0
  171. package/dist/results/diff-dirstat.d.ts.map +1 -0
  172. package/dist/results/diff-entry.d.ts +10 -0
  173. package/dist/results/diff-entry.d.ts.map +1 -1
  174. package/dist/results/diff-formatter.d.ts.map +1 -1
  175. package/dist/results/diff-output.d.ts +18 -0
  176. package/dist/results/diff-output.d.ts.map +1 -1
  177. package/dist/results/fetch-result.d.ts +12 -1
  178. package/dist/results/fetch-result.d.ts.map +1 -1
  179. package/dist/results/index.d.ts +2 -0
  180. package/dist/results/index.d.ts.map +1 -1
  181. package/dist/results/index.js +2 -2
  182. package/dist/results/init-result.d.ts +8 -1
  183. package/dist/results/init-result.d.ts.map +1 -1
  184. package/dist/results/line-range-hunks.d.ts +27 -0
  185. package/dist/results/line-range-hunks.d.ts.map +1 -0
  186. package/dist/results/merge-result.d.ts +8 -1
  187. package/dist/results/merge-result.d.ts.map +1 -1
  188. package/dist/results/pull-result.d.ts +11 -0
  189. package/dist/results/pull-result.d.ts.map +1 -1
  190. package/dist/results/push-result.d.ts +5 -0
  191. package/dist/results/push-result.d.ts.map +1 -1
  192. package/dist/results/status-result.d.ts +1 -1
  193. package/dist/results/status-result.d.ts.map +1 -1
  194. package/dist/results-BDuEgdLU.js +46847 -0
  195. package/dist/transport-command.d.ts +14 -0
  196. package/dist/transport-command.d.ts.map +1 -1
  197. package/package.json +12 -12
  198. package/src/commands/add-command.ts +115 -0
  199. package/src/commands/add-patch/add-patch.ts +8 -0
  200. package/src/commands/add-patch/patch-backend.ts +20 -2
  201. package/src/commands/am/am-command.ts +138 -4
  202. package/src/commands/apply/apply-command.ts +52 -9
  203. package/src/commands/apply/apply-parse.ts +10 -0
  204. package/src/commands/apply/index.ts +8 -1
  205. package/src/commands/blame-command.ts +1450 -51
  206. package/src/commands/blame-ignore.ts +307 -0
  207. package/src/commands/check-mailmap-command.ts +129 -0
  208. package/src/commands/checkout-command.ts +97 -12
  209. package/src/commands/checkout-paths.ts +28 -0
  210. package/src/commands/cherry-command.ts +187 -0
  211. package/src/commands/cherry-pick-command.ts +42 -1
  212. package/src/commands/clean-command.ts +92 -12
  213. package/src/commands/clean-interactive.ts +522 -0
  214. package/src/commands/clone-command.ts +596 -44
  215. package/src/commands/commit-command.ts +180 -47
  216. package/src/commands/describe-command.ts +341 -254
  217. package/src/commands/diff-command.ts +616 -56
  218. package/src/commands/fetch-command.ts +353 -6
  219. package/src/commands/fetch-multiple-command.ts +665 -0
  220. package/src/commands/format-patch-command.ts +189 -77
  221. package/src/commands/git-describe.ts +456 -217
  222. package/src/commands/git-hooks.ts +42 -3
  223. package/src/commands/index.ts +17 -0
  224. package/src/commands/init-command.ts +603 -49
  225. package/src/commands/line-log.ts +931 -0
  226. package/src/commands/log-command.ts +1414 -177
  227. package/src/commands/log-graph.ts +6 -3
  228. package/src/commands/log-output.ts +173 -10
  229. package/src/commands/mailmap.ts +41 -5
  230. package/src/commands/merge-command.ts +274 -16
  231. package/src/commands/merge-drivers.ts +3 -0
  232. package/src/commands/merge-strategy-options.ts +224 -0
  233. package/src/commands/merge-support.ts +101 -21
  234. package/src/commands/message-cleanup.ts +1 -1
  235. package/src/commands/name-rev-command.ts +184 -0
  236. package/src/commands/name-rev.ts +700 -109
  237. package/src/commands/octopus-merge.ts +35 -11
  238. package/src/commands/ort-merge.ts +41 -7
  239. package/src/commands/ort-recursive.ts +40 -2
  240. package/src/commands/patch-id.ts +109 -0
  241. package/src/commands/pull-command.ts +718 -224
  242. package/src/commands/push-command.ts +353 -3
  243. package/src/commands/range-diff/index.ts +3 -0
  244. package/src/commands/range-diff/linear-assignment.ts +203 -0
  245. package/src/commands/range-diff/range-diff-command.ts +433 -0
  246. package/src/commands/range-diff/range-diff.ts +617 -0
  247. package/src/commands/read-tree-command.ts +74 -3
  248. package/src/commands/rebase-command.ts +141 -65
  249. package/src/commands/remerge-diff.ts +241 -0
  250. package/src/commands/remote-command.ts +98 -10
  251. package/src/commands/remote-show-command.ts +836 -0
  252. package/src/commands/reset-command.ts +78 -3
  253. package/src/commands/restore-command.ts +15 -0
  254. package/src/commands/rev-list-command.ts +187 -11
  255. package/src/commands/revert-command.ts +41 -1
  256. package/src/commands/revision-range.ts +3 -1
  257. package/src/commands/sequencer-pick.ts +323 -29
  258. package/src/commands/sequencer-support.ts +164 -2
  259. package/src/commands/shortlog-command.ts +354 -0
  260. package/src/commands/shortlog.ts +361 -0
  261. package/src/commands/show-command.ts +2 -1
  262. package/src/commands/status-command.ts +115 -25
  263. package/src/commands/status-format.ts +1 -1
  264. package/src/commands/submodule-commands.ts +321 -3
  265. package/src/commands/submodule-fetch.ts +789 -0
  266. package/src/commands/submodule-model.ts +9 -1
  267. package/src/commands/submodule-unpack.ts +265 -0
  268. package/src/commands/submodule-update-command.ts +39 -5
  269. package/src/commands/subtree-shift.ts +215 -0
  270. package/src/commands/switch-command.ts +9 -0
  271. package/src/commands/tree-restore.ts +6 -1
  272. package/src/commands/worktree-overwrite-checks.ts +5 -0
  273. package/src/errors/command-errors.ts +35 -0
  274. package/src/git-command.ts +87 -1
  275. package/src/git.ts +146 -0
  276. package/src/guarded-transport-command.ts +171 -0
  277. package/src/index.ts +1 -0
  278. package/src/rename/detect-renames.ts +42 -8
  279. package/src/rename/diffcore-break.ts +166 -0
  280. package/src/rename/index.ts +1 -0
  281. package/src/results/blame-format.ts +268 -43
  282. package/src/results/clone-result.ts +6 -0
  283. package/src/results/diff-dirstat.ts +117 -0
  284. package/src/results/diff-entry.ts +12 -0
  285. package/src/results/diff-formatter.ts +1 -0
  286. package/src/results/diff-output.ts +127 -2
  287. package/src/results/fetch-result.ts +12 -1
  288. package/src/results/index.ts +2 -0
  289. package/src/results/init-result.ts +10 -1
  290. package/src/results/line-range-hunks.ts +126 -0
  291. package/src/results/merge-result.ts +9 -0
  292. package/src/results/pull-result.ts +7 -0
  293. package/src/results/push-result.ts +5 -0
  294. package/src/results/status-result.ts +2 -2
  295. package/src/transport-command.ts +34 -3
  296. package/dist/fsck-DLRpbwTj.js +0 -13405
  297. package/dist/results-TB2IJ64h.js +0 -4700
@@ -29,8 +29,15 @@ import {
29
29
  } from "../errors/index.js";
30
30
  import { GitCommand } from "../git-command.js";
31
31
  import { RemoteConfigStore } from "../remote-config/index.js";
32
+ import {
33
+ DEFAULT_RENAME_LIMIT,
34
+ detectRenames,
35
+ renameScoreOption,
36
+ scorePercent,
37
+ } from "../rename/index.js";
32
38
  import { type CombinedDiffOptions, writeCombinedDiff } from "../results/combined-diff.js";
33
39
  import type { DiffColors } from "../results/diff-color.js";
40
+ import type { DiffEntry } from "../results/diff-entry.js";
34
41
  import { DiffPickaxe } from "../results/diff-pickaxe.js";
35
42
  import { quotePath } from "../results/quote-path.js";
36
43
  import { bareAttributesResolver } from "./attributes-source.js";
@@ -43,10 +50,20 @@ import {
43
50
  import {
44
51
  checkPickaxeOptions,
45
52
  DiffCommand,
53
+ type DiffOutputFormat,
46
54
  type DiffTextOptions,
47
55
  hasPickaxe,
56
+ renamesValue,
48
57
  } from "./diff-command.js";
49
58
  import { hostEnvironmentOf } from "./git-ident.js";
59
+ import {
60
+ gitlinkText,
61
+ type LineLogHost,
62
+ type LineLogPair,
63
+ LineLogWalk,
64
+ lineLogEntry,
65
+ parseLineRanges,
66
+ } from "./line-log.js";
50
67
  import { GRAPH_COLUMN_COLORS_ANSI, graphColumnColors } from "./log-graph.js";
51
68
  import {
52
69
  type LogOutputEntry,
@@ -55,7 +72,7 @@ import {
55
72
  LogPrinter,
56
73
  type LogReflogEntry,
57
74
  } from "./log-output.js";
58
- import { type Mailmap, readRepositoryMailmap } from "./mailmap.js";
75
+ import type { Mailmap } from "./mailmap.js";
59
76
  import { configBool, configValue } from "./merge-config.js";
60
77
  import {
61
78
  addRefsByGlob,
@@ -68,6 +85,7 @@ import {
68
85
  } from "./notes-support.js";
69
86
  import { combineNotesIgnore } from "./notes-tree.js";
70
87
  import { canonicalObjectId } from "./object-id-input.js";
88
+ import { PatchIds } from "./patch-id.js";
71
89
  import {
72
90
  ALL_ENTRIES_NOT_INTERESTING,
73
91
  bloomPathOf,
@@ -83,8 +101,14 @@ import {
83
101
  treePathspec,
84
102
  } from "./pathspec.js";
85
103
  import { PathspecAttributes } from "./pathspec-attributes.js";
86
- import { type DecorationPalette, loadRefDecorations } from "./pretty-format.js";
104
+ import {
105
+ type DecorationPalette,
106
+ type LoadRefDecorationsOptions,
107
+ loadRefDecorations,
108
+ type RefDecorations,
109
+ } from "./pretty-format.js";
87
110
  import { openReflogWalk, walkReflogs } from "./reflog-walk.js";
111
+ import { RemergeTreeCommand, remergeObjectsView } from "./remerge-diff.js";
88
112
  import {
89
113
  type CommitFilter,
90
114
  CommitFilters,
@@ -121,6 +145,23 @@ interface PendingCommit {
121
145
  id: ObjectId;
122
146
  exclude: boolean;
123
147
  name?: string;
148
+ /** The left side of a symmetric difference (`a` of `a...b`, git's SYMMETRIC_LEFT) */
149
+ left?: boolean;
150
+ }
151
+
152
+ /** A commit of the walk as the log printer takes it. */
153
+ function outputEntry(c: LogResult): LogOutputEntry {
154
+ const { id, boundary, source, left, patchSame, reflog: _reflog, savedParents, ...commit } = c;
155
+ return {
156
+ id,
157
+ commit,
158
+ parents: c.parents,
159
+ ...(savedParents ? { savedParents } : {}),
160
+ ...(boundary ? { boundary: true } : {}),
161
+ ...(source !== undefined ? { source } : {}),
162
+ ...(left ? { left: true } : {}),
163
+ ...(patchSame ? { patchSame: true } : {}),
164
+ };
124
165
  }
125
166
 
126
167
  /** git's get_revision under `--reverse`: every commit read first, then given oldest first. */
@@ -130,6 +171,18 @@ async function* reversed<T>(source: AsyncIterable<T>): AsyncIterable<T> {
130
171
  for (let i = all.length - 1; i >= 0; i--) yield all[i] as T;
131
172
  }
132
173
 
174
+ /** A commit's parents as the walk holds them, by id */
175
+ function lineLogParentIds(t: RevTable, n: number): ObjectId[] {
176
+ const ids: ObjectId[] = [];
177
+ for (let k = 0, c = t.parentCount(n); k < c; k++) ids.push(t.idOf(t.parent(n, k)));
178
+ return ids;
179
+ }
180
+
181
+ /** A death of `git log -L` (`die()`: `fatal:`, exit 128) */
182
+ function lineLogDeath(message: string): GitApiError {
183
+ return new GitApiError(`fatal: ${message}`).withExitCode(128);
184
+ }
185
+
133
186
  /** git log reads no index: the in-tree attributes files are the worktree's only. */
134
187
  const NO_INDEX = { attributesBlob: () => undefined };
135
188
 
@@ -146,6 +199,16 @@ export interface LogResult extends Commit {
146
199
  * not listed itself, given after the others (git's `BOUNDARY`, the `-` mark)
147
200
  */
148
201
  boundary?: boolean;
202
+ /**
203
+ * On the left side of a symmetric difference (`a` of `a...b`, reached from it only): git's
204
+ * SYMMETRIC_LEFT, the `<` mark of {@link LogCommand.setLeftRight} (`>` otherwise)
205
+ */
206
+ left?: boolean;
207
+ /**
208
+ * {@link LogCommand.setCherryMark}: the other side of the symmetric difference has a commit
209
+ * with the same patch-id (git's PATCHSAME, the `=` mark)
210
+ */
211
+ patchSame?: boolean;
149
212
  /**
150
213
  * The name the commit was reached from ({@link LogCommand.setSource}, git's `--source`):
151
214
  * the revision as given, or the ref `--all`, `--branches`... named
@@ -153,6 +216,11 @@ export interface LogResult extends Commit {
153
216
  source?: string;
154
217
  /** In a reflog walk ({@link LogCommand.addReflogWalk}), the entry the commit is listed for */
155
218
  reflog?: LogReflogEntry;
219
+ /**
220
+ * The parents before {@link LogCommand.setParents} rewrote `parents` (git's saved parents,
221
+ * which `--full-diff` diffs against)
222
+ */
223
+ savedParents?: ObjectId[];
156
224
  }
157
225
 
158
226
  /**
@@ -330,6 +398,10 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
330
398
  private readonly grepReflogs: string[] = [];
331
399
  /** The git version whose behaviour differs where versions differ */
332
400
  private compatibility: "2.43" | "2.56" = "2.56";
401
+ /** `-L` arguments, as given */
402
+ private readonly lineRangeArgs: string[] = [];
403
+ /** The ranges `-L` follows through the walk under way */
404
+ private lineLog?: LineLogWalk;
333
405
  /** `--topo-order`, `--date-order`, `--author-date-order` */
334
406
  private order?: LogOrder;
335
407
  /** `--reverse` */
@@ -338,6 +410,41 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
338
410
  private boundary = false;
339
411
  /** `--source` */
340
412
  private source = false;
413
+ /** `--left-right` */
414
+ private leftRight = false;
415
+ /** `--left-only` */
416
+ private leftOnly = false;
417
+ /** `--right-only` (and `--cherry`) */
418
+ private rightOnly = false;
419
+ /** `--cherry-pick` */
420
+ private cherryPick = false;
421
+ /** `--cherry-mark` (and `--cherry`) */
422
+ private cherryMark = false;
423
+ /** `--cherry`: no merges (git's max_parents 1) */
424
+ private cherry = false;
425
+ /** `--simplify-merges` (and `--simplify-by-decoration`) */
426
+ private simplifyMerges = false;
427
+ /** `--simplify-by-decoration` */
428
+ private simplifyByDecoration = false;
429
+ /** git's `dense`: `--dense` (the default), off with `--sparse` */
430
+ private dense = true;
431
+ /** `--show-pulls` */
432
+ private showPulls = false;
433
+ /** `--parents` (git's `rewrite_parents` by itself) */
434
+ private rewriteParents = false;
435
+ /** `--ancestry-path` without a commit: the bottom commits are the ones */
436
+ private ancestryPathImplicit = false;
437
+ /** `--ancestry-path=<commit>`: the commits given */
438
+ private readonly ancestryPathCommits: ObjectId[] = [];
439
+ /**
440
+ * Commits a revision reaches through an annotated tag `--ancestry-path=<tag>` names: the
441
+ * tag's ANCESTRY_PATH passes to them (handle_commit's `object->flags |= flags`)
442
+ */
443
+ private readonly ancestryPathPeeled: ObjectId[] = [];
444
+ /** `git log --reverse` collects the walk itself: shown commits keep their parents */
445
+ private keepShownParents = false;
446
+ /** Loads the decorations `--simplify-by-decoration` keeps (the log's filter), when set */
447
+ private decorationLoader?: () => Promise<RefDecorations>;
341
448
 
342
449
  /**
343
450
  * The order of the commits ({@link LogOrder}); undefined is git's default, newest commit
@@ -395,6 +502,118 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
395
502
  return this;
396
503
  }
397
504
 
505
+ /**
506
+ * `--left-right`: each commit is marked by the side of the symmetric difference it is
507
+ * reached from: `<` for the left (`a` of `a...b`, {@link add} with `left`), `>` for the
508
+ * right (`commit < <id>`, `< <id> <subject>` under `--oneline`, the graph's `<`/`>` in place
509
+ * of `*`); `left` on each {@link LogResult} says it whatever this says.
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * // git log --left-right --oneline main...topic
514
+ * await git.revList().addRevision("main...topic").setLeftRight(true).callLogText({ oneline: true });
515
+ * ```
516
+ */
517
+ setLeftRight(leftRight: boolean): this {
518
+ this.checkCallable();
519
+ this.leftRight = leftRight;
520
+ return this;
521
+ }
522
+
523
+ /**
524
+ * `--left-only`: only the commits of the left side of a symmetric difference (none without
525
+ * one). Refused with {@link setRightOnly} or {@link setCherry}, as git refuses them.
526
+ */
527
+ setLeftOnly(leftOnly: boolean): this {
528
+ this.checkCallable();
529
+ if (leftOnly && this.rightOnly) {
530
+ throw new IncompatibleOptionsError(
531
+ ["--left-only", "--right-only/--cherry"],
532
+ "options '--left-only' and '--right-only/--cherry' cannot be used together",
533
+ );
534
+ }
535
+ this.leftOnly = leftOnly;
536
+ return this;
537
+ }
538
+
539
+ /** `--right-only`: only the commits of the right side (see {@link setLeftOnly}). */
540
+ setRightOnly(rightOnly: boolean): this {
541
+ this.checkCallable();
542
+ if (rightOnly && this.leftOnly) {
543
+ throw new IncompatibleOptionsError(
544
+ ["--right-only", "--left-only"],
545
+ "options '--right-only' and '--left-only' cannot be used together",
546
+ );
547
+ }
548
+ this.rightOnly = rightOnly;
549
+ return this;
550
+ }
551
+
552
+ /**
553
+ * `--cherry-pick`: commits whose change (patch-id, as `git patch-id` computes it, limited to
554
+ * the paths) a commit on the other side of the symmetric difference makes too are left out,
555
+ * on both sides. The cheap id of each diff's headers is computed for the smaller side, and
556
+ * full patch-ids only where those collide (revision.c's cherry_pick_list).
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * // git rev-list --left-right --cherry-pick main...topic
561
+ * await git.revList().addRevision("main...topic").setLeftRight(true).setCherryPick(true).callText();
562
+ * ```
563
+ */
564
+ setCherryPick(cherryPick: boolean): this {
565
+ this.checkCallable();
566
+ if (cherryPick && this.cherryMark) {
567
+ throw new IncompatibleOptionsError(
568
+ ["--cherry-pick", "--cherry-mark"],
569
+ "options '--cherry-pick' and '--cherry-mark' cannot be used together",
570
+ );
571
+ }
572
+ this.cherryPick = cherryPick;
573
+ return this;
574
+ }
575
+
576
+ /**
577
+ * `--cherry-mark`: as {@link setCherryPick}, but the equivalent commits are kept and marked
578
+ * (`patchSame`, the `=` mark; the others `+` when nothing else marks them).
579
+ */
580
+ setCherryMark(cherryMark: boolean): this {
581
+ this.checkCallable();
582
+ if (cherryMark && this.cherryPick) {
583
+ throw new IncompatibleOptionsError(
584
+ ["--cherry-mark", "--cherry-pick"],
585
+ "options '--cherry-mark' and '--cherry-pick' cannot be used together",
586
+ );
587
+ }
588
+ this.cherryMark = cherryMark;
589
+ return this;
590
+ }
591
+
592
+ /**
593
+ * `--cherry`: `--right-only --cherry-mark --no-merges`, the commits of the right side marked
594
+ * by whether the left side has their change (`git cherry` as a walk).
595
+ */
596
+ setCherry(cherry: boolean): this {
597
+ this.checkCallable();
598
+ if (cherry && this.leftOnly) {
599
+ throw new IncompatibleOptionsError(
600
+ ["--cherry", "--left-only"],
601
+ "options '--cherry' and '--left-only' cannot be used together",
602
+ );
603
+ }
604
+ this.cherry = cherry;
605
+ if (cherry) {
606
+ this.cherryMark = true;
607
+ this.rightOnly = true;
608
+ }
609
+ return this;
610
+ }
611
+
612
+ /** The revision options of the marks the output prints (get_revision_mark). */
613
+ private revisionMarks(): { leftRight: boolean; cherryMark: boolean } {
614
+ return { leftRight: this.leftRight, cherryMark: this.cherryMark };
615
+ }
616
+
398
617
  /**
399
618
  * `git log -g <ref>` (`--walk-reflogs`) for the printed log ({@link callText}): the
400
619
  * commits of `ref`'s reflog, newest entry first, each shown with its entry (`Reflog:`
@@ -440,7 +659,9 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
440
659
 
441
660
  /**
442
661
  * The git version to follow where versions differ (default 2.56): 2.43 refuses a reflog
443
- * walk's `--reverse` before a sorted walk (`--topo-order`, `--graph`), 2.56 after.
662
+ * walk's `--reverse` before a sorted walk (`--topo-order`, `--graph`), 2.56 after; 2.43's
663
+ * `--left-only`/`--right-only` hide nothing in a walk nothing else limits (no excluded
664
+ * commit: `a...b` of unrelated histories, or no range at all).
444
665
  */
445
666
  setCompatibility(version: "2.43" | "2.56"): this {
446
667
  this.checkCallable();
@@ -468,11 +689,41 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
468
689
  *
469
690
  * @param commit ObjectId of commit to start from
470
691
  * @param name The name it was given by, which {@link setSource} reports (the id without)
692
+ * @param options `left`: the commit is the left side of a symmetric difference (`a` of
693
+ * `a...b`): it and what only it reaches are marked so ({@link setLeftRight})
471
694
  */
472
- add(commit: ObjectId, name?: string): this {
695
+ add(commit: ObjectId, name?: string, options: { left?: boolean } = {}): this {
473
696
  this.checkCallable();
474
697
  this.startCommits.push(commit);
475
- this.pending.push({ id: commit, exclude: false, ...(name !== undefined ? { name } : {}) });
698
+ this.pending.push({
699
+ id: commit,
700
+ exclude: false,
701
+ ...(name !== undefined ? { name } : {}),
702
+ ...(options.left ? { left: true } : {}),
703
+ });
704
+ return this;
705
+ }
706
+
707
+ /**
708
+ * `-L <start>,<end>:<file>` / `-L :<funcname>:<file>`: follow lines of a file back through
709
+ * history ({@link callBytes} only). The range is given as git takes it: `<start>` and
710
+ * `<end>` line numbers, `+<n>`/`-<n>` offsets, `/<regex>/` (searched from the previous
711
+ * range of the file, or the top with `^/<regex>/`), or `:<regex>` naming a function as the
712
+ * path's diff driver finds them (`diff.<driver>.xfuncname`, the builtin drivers). Each
713
+ * commit whose change touches the lines is shown with its diff cut to them; renames are
714
+ * followed (`diff.renames`, `-M`). Several ranges, of one file or several, are followed
715
+ * together. The log starts from one commit (HEAD by default), and paths cannot be given.
716
+ * Errors are git's deaths (`fatal: ...`, exit 128).
717
+ *
718
+ * @example
719
+ * ```typescript
720
+ * // git log -L 4,12:a.c -L :main:a.c
721
+ * await git.log().addLineRange("4,12:a.c").addLineRange(":main:a.c").callText();
722
+ * ```
723
+ */
724
+ addLineRange(range: string): this {
725
+ this.checkCallable();
726
+ this.lineRangeArgs.push(range);
476
727
  return this;
477
728
  }
478
729
 
@@ -556,6 +807,86 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
556
807
  return this;
557
808
  }
558
809
 
810
+ /**
811
+ * `--simplify-merges`: a path-limited walk keeps every parent of a merge (as
812
+ * {@link setFullHistory}), then removes the merges whose parents simplify to one commit and
813
+ * the parents another parent reaches (revision.c's simplify_merges). Commits come in
814
+ * topological order (`--topo-order` unless another order is set), with their parents
815
+ * rewritten past the commits not shown.
816
+ */
817
+ setSimplifyMerges(simplify: boolean): this {
818
+ this.checkCallable();
819
+ this.simplifyMerges = simplify;
820
+ return this;
821
+ }
822
+
823
+ /**
824
+ * `--simplify-by-decoration`: only commits a ref names (git's ref decorations: every ref and
825
+ * HEAD, or `git log`'s decoration filter in {@link callText}), commits that change the
826
+ * paths when paths are given, and merges tying them together; merges simplified as
827
+ * {@link setSimplifyMerges}.
828
+ */
829
+ setSimplifyByDecoration(simplify: boolean): this {
830
+ this.checkCallable();
831
+ this.simplifyByDecoration = simplify;
832
+ return this;
833
+ }
834
+
835
+ /**
836
+ * `--dense` (true, the default) / `--sparse` (false): with `--sparse` a path-limited walk
837
+ * shows every commit it walks, also those that change none of the paths (merges are still
838
+ * simplified to the parent they match).
839
+ */
840
+ setDense(dense: boolean): this {
841
+ this.checkCallable();
842
+ this.dense = dense;
843
+ return this;
844
+ }
845
+
846
+ /**
847
+ * `--show-pulls`: a merge that differs from its first parent at the paths but matches
848
+ * another parent is shown too (it "pulled" the change into the first-parent history).
849
+ */
850
+ setShowPulls(showPulls: boolean): this {
851
+ this.checkCallable();
852
+ this.showPulls = showPulls;
853
+ return this;
854
+ }
855
+
856
+ /**
857
+ * `--parents`: each commit's `parents` are the ones the walk shows (rewritten past the
858
+ * commits a path-limited walk leaves out, as git's `rewrite_parents`), and TREESAME merges
859
+ * of two relevant lines are kept to tie them together.
860
+ */
861
+ setParents(parents: boolean): this {
862
+ this.checkCallable();
863
+ this.rewriteParents = parents;
864
+ return this;
865
+ }
866
+
867
+ /**
868
+ * `--ancestry-path`: of `A..B`, only the commits that are descendants of an excluded
869
+ * (bottom) commit and ancestors of B. A walk without bottom commits fails (`--ancestry-path
870
+ * given but there are no bottom commits`). Turns history simplification off, as
871
+ * {@link setFullHistory}.
872
+ */
873
+ setAncestryPath(ancestryPath: boolean): this {
874
+ this.checkCallable();
875
+ this.ancestryPathImplicit = ancestryPath;
876
+ return this;
877
+ }
878
+
879
+ /**
880
+ * `--ancestry-path=<commit>` (repeatable): only the commits that are the commit, its
881
+ * ancestors or its descendants (of any commit given). A tag is peeled: its commit then
882
+ * keeps only its descendants, as git marks the tag object and not the commit.
883
+ */
884
+ addAncestryPath(commit: ObjectId): this {
885
+ this.checkCallable();
886
+ this.ancestryPathCommits.push(canonicalObjectId(commit));
887
+ return this;
888
+ }
889
+
559
890
  /**
560
891
  * Follow only the first parent on merges.
561
892
  *
@@ -576,9 +907,14 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
576
907
  * @param commit ObjectId to exclude along with its ancestors
577
908
  * @param name The name it was given by (see {@link add})
578
909
  */
579
- not(commit: ObjectId, name?: string): this {
910
+ not(commit: ObjectId, name?: string, options: { left?: boolean } = {}): this {
580
911
  this.checkCallable();
581
- this.pending.push({ id: commit, exclude: true, ...(name !== undefined ? { name } : {}) });
912
+ this.pending.push({
913
+ id: commit,
914
+ exclude: true,
915
+ ...(name !== undefined ? { name } : {}),
916
+ ...(options.left ? { left: true } : {}),
917
+ });
582
918
  return this;
583
919
  }
584
920
 
@@ -813,20 +1149,27 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
813
1149
  const pending: PendingCommit[] = [];
814
1150
  for (let i = 0; i <= this.pending.length; i++) {
815
1151
  if (this.includeAll && i === this.allAt) {
816
- for (const { id, name } of await this.getAllRefs())
1152
+ for (const { id, name, raw } of await this.getAllRefs()) {
1153
+ if (raw !== id && this.ancestryPathCommits.includes(raw))
1154
+ this.ancestryPathPeeled.push(id);
817
1155
  pending.push({ id, exclude: false, name });
1156
+ }
818
1157
  }
819
1158
  const e = this.pending[i];
1159
+ if (e && e.id !== (await this.peelToCommit(e.id)) && this.ancestryPathCommits.includes(e.id))
1160
+ this.ancestryPathPeeled.push(await this.peelToCommit(e.id));
820
1161
  if (e)
821
1162
  pending.push({
822
1163
  id: await this.peelToCommit(e.id),
823
1164
  exclude: e.exclude,
824
1165
  name: e.name ?? e.id,
1166
+ ...(e.left ? { left: true } : {}),
825
1167
  });
826
1168
  }
827
1169
  if (this.startCommits.length === 0 && !this.includeAll) {
828
1170
  pending.push({ id: await this.resolveHead(), exclude: false, name: "HEAD" });
829
1171
  }
1172
+ if (this.lineRangeArgs.length > 0) await this.startLineLog(pending);
830
1173
  const walk = this.walk(pending);
831
1174
  return this.reverse ? reversed(walk) : walk;
832
1175
  }
@@ -857,8 +1200,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
857
1200
  const mapped =
858
1201
  this.useMailmap ??
859
1202
  (this.logConfig ? configBool(this.workingCopy, "log.mailmap", true) : false);
860
- if (headers && mapped)
861
- mailmap = await this.loadMailmap(RemoteConfigStore.from(this._workingCopy));
1203
+ if (headers && mapped) mailmap = await this.loadedMailmap();
862
1204
  filters.push(
863
1205
  CommitFilters.grep({
864
1206
  messages: this.grepMessages,
@@ -937,7 +1279,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
937
1279
  * (refs_for_each_ref, symbolic ones resolved), then HEAD (refs_head_ref); annotated tags
938
1280
  * peeled.
939
1281
  */
940
- private async getAllRefs(): Promise<{ id: ObjectId; name: string }[]> {
1282
+ private async getAllRefs(): Promise<{ id: ObjectId; name: string; raw: ObjectId }[]> {
941
1283
  const named: { name: Uint8Array; id: ObjectId }[] = [];
942
1284
  for await (const ref of this.refsStore.list()) {
943
1285
  if (!ref.name.startsWith("refs/")) continue;
@@ -946,11 +1288,11 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
946
1288
  if (id) named.push({ name: encodeGitPath(ref.name), id });
947
1289
  }
948
1290
  named.sort((a, b) => compareBytes(a.name, b.name));
949
- const ids: { id: ObjectId; name: string }[] = [];
1291
+ const ids: { id: ObjectId; name: string; raw: ObjectId }[] = [];
950
1292
  for (const { id, name } of named)
951
- ids.push({ id: await this.peelToCommit(id), name: decodeGitPath(name) });
1293
+ ids.push({ id: await this.peelToCommit(id), name: decodeGitPath(name), raw: id });
952
1294
  const head = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
953
- if (head) ids.push({ id: await this.peelToCommit(head), name: "HEAD" });
1295
+ if (head) ids.push({ id: await this.peelToCommit(head), name: "HEAD", raw: head });
954
1296
  return ids;
955
1297
  }
956
1298
 
@@ -975,7 +1317,20 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
975
1317
  * the commit-graph has are reached by their graph positions, without building their ids.
976
1318
  */
977
1319
  private async *walk(pending: PendingCommit[]): AsyncIterable<LogResult> {
978
- const prune = this.paths.length > 0 || this.excludePaths.length > 0;
1320
+ const hasPaths = this.paths.length > 0 || this.excludePaths.length > 0;
1321
+ const simplifyByDecoration = this.simplifyByDecoration;
1322
+ // --simplify-by-decoration prunes without paths: a commit no ref names is TREESAME
1323
+ const prune = hasPaths || simplifyByDecoration;
1324
+ const simplifyMerges = this.simplifyMerges || simplifyByDecoration;
1325
+ const ancestryPath = this.ancestryPathImplicit || this.ancestryPathCommits.length > 0;
1326
+ const dense = this.dense;
1327
+ const showPulls = this.showPulls;
1328
+ // git's want_ancestry: rewrite_parents (--parents, --graph, --simplify-merges)
1329
+ const wantAncestry = this.rewriteParents || simplifyMerges || !!this.outputWalk?.rewrite;
1330
+ const rewrite = prune && dense && wantAncestry;
1331
+ const decorations = simplifyByDecoration
1332
+ ? await (this.decorationLoader?.() ?? this.refDecorations())
1333
+ : undefined;
979
1334
  // a shallow commit has no parents (git's shallow grafts); the graph is off then
980
1335
  const shallowIds = (await this.refsStore.getShallow?.().catch(() => undefined)) ?? [];
981
1336
  const shallow = new Set(shallowIds);
@@ -988,13 +1343,13 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
988
1343
  shallow.size > 0 || replacements
989
1344
  ? undefined
990
1345
  : await this.commits.commitGraph?.get().catch(() => undefined);
991
- const pathspec = prune ? this.pathspec() : undefined;
1346
+ const pathspec = hasPaths ? this.pathspec() : undefined;
992
1347
  const bloom =
993
1348
  pathspec && this.useBloomFilters ? this.bloomKeys(graph, pathspec.items) : undefined;
994
1349
  const bloomVersion = bloom ? this.changedPathsVersion() : -1;
995
1350
  const fast = pathspec?.literal;
996
1351
  const firstParentOnly = this.firstParentOnly;
997
- const simplifyHistory = this.simplifyHistory;
1352
+ const simplifyHistory = this.simplifyHistory && !simplifyMerges && !ancestryPath;
998
1353
  /**
999
1354
  * Each merge's TREESAME to each parent (git's `treesame` decoration), kept when limiting
1000
1355
  * can make it TREESAME later (limiting_can_increase_treesame: full history, a limited walk)
@@ -1050,8 +1405,20 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1050
1405
  for (let k = 0, c = t.parentCount(n); k < c; k++) markOne(t.parent(n, k));
1051
1406
  for (let p = stack.pop(); p !== undefined; p = stack.pop()) markOne(p);
1052
1407
  };
1053
- const differs = (from: ObjectId | undefined, n: number, nth: number) =>
1054
- this.differsAtPaths(
1408
+ const emptyTree = this.objectFormat.emptyTreeId;
1409
+ /** git's rev_compare_tree (`from` given) and rev_same_tree_as_empty: whether n differs */
1410
+ const differs = async (
1411
+ from: ObjectId | undefined,
1412
+ n: number,
1413
+ nth: number,
1414
+ ): Promise<boolean> => {
1415
+ if (decorations && from !== undefined) {
1416
+ // a commit a ref names is worth showing; without paths, no other is
1417
+ if ((decorations.get(t.idOf(n))?.length ?? 0) > 0) return true;
1418
+ if (!pathspec) return false;
1419
+ }
1420
+ if (!pathspec) return t.treeOf(n) !== emptyTree;
1421
+ return this.differsAtPaths(
1055
1422
  from,
1056
1423
  t.treeOf(n),
1057
1424
  pathspec as TreePathspec,
@@ -1061,14 +1428,18 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1061
1428
  graph,
1062
1429
  t.bloomPos(n),
1063
1430
  );
1064
- /** git's try_to_simplify_commit (prune, dense, no show_pulls) */
1431
+ };
1432
+ /** git's try_to_simplify_commit */
1065
1433
  const simplify = async (n: number): Promise<void> => {
1066
- if (!prune) return;
1434
+ // an unparsed commit has no tree (a parent --first-parent never read, met by rewriting)
1435
+ if (!prune || !t.parsed(n)) return;
1067
1436
  const count = t.parentCount(n);
1068
1437
  if (count === 0) {
1069
1438
  if (!(await differs(undefined, n, 0))) t.mark(n, TREESAME);
1070
1439
  return;
1071
1440
  }
1441
+ // --sparse: a non-merge always counts as a change
1442
+ if (!dense && count === 1) return;
1072
1443
  let relevantParents = 0;
1073
1444
  let relevantChange = false;
1074
1445
  let irrelevantChange = false;
@@ -1095,11 +1466,13 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1095
1466
  continue;
1096
1467
  }
1097
1468
  t.keepOnlyParent(n, p);
1098
- t.mark(n, TREESAME);
1469
+ // a merge diverted to a later parent is shown under --show-pulls
1470
+ if (!showPulls || nth === 0) t.mark(n, TREESAME);
1099
1471
  return;
1100
1472
  }
1101
1473
  if (relevant(p)) relevantChange = true;
1102
1474
  else irrelevantChange = true;
1475
+ if (nth === 0) t.mark(n, PULL_MERGE);
1103
1476
  }
1104
1477
  if (relevantParents ? !relevantChange : !irrelevantChange) t.mark(n, TREESAME);
1105
1478
  };
@@ -1120,11 +1493,13 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1120
1493
  return;
1121
1494
  }
1122
1495
  await simplify(n);
1496
+ const passFlags = t.flag(n) & (SYMMETRIC_LEFT | ANCESTRY_PATH);
1123
1497
  for (let k = 0, c = t.parentCount(n); k < c; k++) {
1124
1498
  const p = t.parent(n, k);
1125
1499
  if (!(await parse(p))) {
1126
1500
  throw new GitApiError(`Failed to traverse parents of commit ${t.idOf(n)}`);
1127
1501
  }
1502
+ if (passFlags) t.mark(p, passFlags);
1128
1503
  if (sources && !sources.has(p)) {
1129
1504
  const source = sources.get(n);
1130
1505
  if (source !== undefined) sources.set(p, source);
@@ -1137,22 +1512,25 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1137
1512
  }
1138
1513
  };
1139
1514
  /** git's get_commit_action (no parent rewriting: TREESAME commits are never shown) */
1140
- const shown = async (n: number, rewrite = false): Promise<LogResult | undefined> => {
1515
+ const shown = async (n: number, ancestry = false): Promise<LogResult | undefined> => {
1141
1516
  const bytes = raw.get(n);
1142
1517
  if (bytes) raw.delete(n);
1143
- if (t.flag(n) & UNINTERESTING) return undefined;
1144
- if (t.flag(n) & TREESAME) {
1518
+ // commit_early_ignore
1519
+ if (t.flag(n) & (UNINTERESTING | SHOWN)) return undefined;
1520
+ if (dense && t.flag(n) & TREESAME) {
1145
1521
  // with parents rewritten, a merge of two relevant lines ties the topology together
1146
- if (!rewrite) return undefined;
1147
- let relevantParents = 0;
1148
- for (let k = 0, c = t.parentCount(n); k < c; k++)
1149
- if (relevant(t.parent(n, k))) relevantParents++;
1150
- if (relevantParents < 2) return undefined;
1522
+ if (!ancestry) return undefined;
1523
+ if (!(showPulls && t.flag(n) & PULL_MERGE)) {
1524
+ let relevantParents = 0;
1525
+ for (let k = 0, c = t.parentCount(n); k < c; k++)
1526
+ if (relevant(t.parent(n, k))) relevantParents++;
1527
+ if (relevantParents < 2) return undefined;
1528
+ }
1151
1529
  }
1152
1530
  if (this.untilTime !== undefined && t.date(n) > this.untilTime) return undefined;
1153
1531
  const parents = t.parentCount(n);
1154
1532
  if (this.revFilter === RevFilter.ONLY_MERGES && parents < 2) return undefined;
1155
- if (this.revFilter === RevFilter.NO_MERGES && parents > 1) return undefined;
1533
+ if ((this.revFilter === RevFilter.NO_MERGES || this.cherry) && parents > 1) return undefined;
1156
1534
  const id = t.idOf(n);
1157
1535
  const commit = bytes ? decodeCommit(bytes) : await this.walkCommits.load(id);
1158
1536
  if (!commit) return undefined;
@@ -1174,17 +1552,51 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1174
1552
  if (!(await filter.include(view))) return undefined;
1175
1553
  }
1176
1554
  const source = sources?.get(n);
1177
- return source !== undefined ? { ...commit, id, source } : { ...commit, id };
1555
+ return {
1556
+ ...commit,
1557
+ id,
1558
+ ...(source !== undefined ? { source } : {}),
1559
+ ...sideOf(n),
1560
+ };
1561
+ };
1562
+ /** The side marks of a commit (SYMMETRIC_LEFT, PATCHSAME) */
1563
+ const sideOf = (n: number): { left?: true; patchSame?: true } => {
1564
+ const f = t.flag(n);
1565
+ return {
1566
+ ...(f & SYMMETRIC_LEFT ? { left: true } : {}),
1567
+ ...(f & PATCHSAME ? { patchSame: true } : {}),
1568
+ };
1178
1569
  };
1179
1570
 
1571
+ // --ancestry-path=<commit>: the commits (git marks the object named: a tag's commit is
1572
+ // not marked, only listed among the bottoms)
1573
+ const ancestryBottoms: number[] = [];
1574
+ for (const id of this.ancestryPathCommits) {
1575
+ const commit = await this.peelToCommit(id);
1576
+ const n = t.lookup(commit);
1577
+ if (commit === id) t.mark(n, ANCESTRY_PATH);
1578
+ ancestryBottoms.unshift(n);
1579
+ }
1580
+ for (const id of this.ancestryPathPeeled) t.mark(t.lookup(id), ANCESTRY_PATH);
1180
1581
  // prepare_revision_walk: the flags of every argument first, then handle_commit in order
1181
1582
  for (const e of pending) {
1583
+ if (e.left) t.mark(t.lookup(e.id), SYMMETRIC_LEFT);
1182
1584
  if (!e.exclude) continue;
1183
1585
  const n = t.lookup(e.id);
1184
1586
  t.mark(n, UNINTERESTING | BOTTOM);
1185
1587
  }
1186
1588
  const list: number[] = [];
1187
- let limited = false;
1589
+ // --cherry-pick and --cherry-mark need limit_list, and so do --left-only and
1590
+ // --right-only from git 2.44 on (2.43 applies them only to a walk limited otherwise)
1591
+ // --ancestry-path and --simplify-merges limit the walk too (--parents does not: a
1592
+ // streaming walk rewrites parents as it goes)
1593
+ let limited =
1594
+ !!this.lineLog ||
1595
+ this.cherryPick ||
1596
+ this.cherryMark ||
1597
+ (this.compatibility !== "2.43" && (this.leftOnly || this.rightOnly)) ||
1598
+ ancestryPath ||
1599
+ simplifyMerges;
1188
1600
  /** git's update_treesame: TREESAME again from the per-parent marks, relevance as it is now */
1189
1601
  const updateTreesame = (n: number): void => {
1190
1602
  const count = t.parentCount(n);
@@ -1202,6 +1614,277 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1202
1614
  if (relevantParents ? relevantChange : irrelevantChange) t.unmark(n, TREESAME);
1203
1615
  else t.mark(n, TREESAME);
1204
1616
  };
1617
+ /**
1618
+ * revision.c's limit_to_ancestry: of `list`, the commits neither descending from a bottom
1619
+ * (TMP_MARK) nor marked ANCESTRY_PATH (ancestors of a commit given) become UNINTERESTING.
1620
+ */
1621
+ const limitToAncestry = (bottoms: number[], list: number[]): void => {
1622
+ const marked = new Set(bottoms);
1623
+ const rlist = [...list].reverse();
1624
+ let progress: boolean;
1625
+ do {
1626
+ progress = false;
1627
+ for (const c of rlist) {
1628
+ if (marked.has(c) || t.flag(c) & UNINTERESTING) continue;
1629
+ for (let k = 0, n = t.parentCount(c); k < n; k++) {
1630
+ if (!marked.has(t.parent(c, k))) continue;
1631
+ marked.add(c);
1632
+ progress = true;
1633
+ break;
1634
+ }
1635
+ }
1636
+ } while (progress);
1637
+ for (const c of list) {
1638
+ if (marked.has(c) || t.flag(c) & ANCESTRY_PATH) continue;
1639
+ t.mark(c, UNINTERESTING);
1640
+ }
1641
+ for (const c of list) t.unmark(c, ANCESTRY_PATH);
1642
+ for (const c of bottoms) t.unmark(c, ANCESTRY_PATH);
1643
+ };
1644
+ /**
1645
+ * revision.c's compact_treesame: parent `nth` was just removed from n's parents (git's
1646
+ * treesame decoration follows; a merge become a non-merge takes its TREESAME at once).
1647
+ */
1648
+ const compactTreesame = async (n: number, nth: number): Promise<void> => {
1649
+ if (t.parentCount(n) === 0) {
1650
+ if (await differs(undefined, n, nth)) t.unmark(n, TREESAME);
1651
+ else t.mark(n, TREESAME);
1652
+ return;
1653
+ }
1654
+ const st = treesame.get(n);
1655
+ if (!st || nth >= st.length) throw new GitApiError(`compact_treesame ${nth}`);
1656
+ const next = new Uint8Array(st.length - 1);
1657
+ next.set(st.subarray(0, nth));
1658
+ next.set(st.subarray(nth + 1), nth);
1659
+ if (next.length === 1) {
1660
+ if (next[0] && dense) t.mark(n, TREESAME);
1661
+ else t.unmark(n, TREESAME);
1662
+ treesame.delete(n);
1663
+ } else treesame.set(n, next);
1664
+ };
1665
+ /** revision.c's remove_duplicate_parents: how many parents are left */
1666
+ const removeDuplicateParents = async (n: number): Promise<number> => {
1667
+ const tracked = treesame.has(n);
1668
+ const parents = t.parentList(n);
1669
+ const current = [...parents];
1670
+ let surviving = 0;
1671
+ for (const p of parents) {
1672
+ if (current.slice(0, surviving).includes(p)) {
1673
+ // the list shrinks before the treesame marks follow
1674
+ current.splice(surviving, 1);
1675
+ t.setParentList(n, current);
1676
+ if (tracked) await compactTreesame(n, surviving);
1677
+ continue;
1678
+ }
1679
+ surviving++;
1680
+ }
1681
+ return surviving;
1682
+ };
1683
+ /**
1684
+ * commit-reach.c's paint_down_to_common for remove_redundant (no generation cut): the
1685
+ * PARENT1 (from `one`) and PARENT2 (from `twos`) marks of the commits, through the
1686
+ * parents as the walk holds them (simplified ones included, as git's in-memory commits).
1687
+ */
1688
+ const paintDown = async (one: number, twos: number[]): Promise<Map<number, number>> => {
1689
+ const P1 = 1;
1690
+ const P2 = 2;
1691
+ const STALE = 4;
1692
+ const RESULT = 8;
1693
+ const marks = new Map<number, number>();
1694
+ const queue = new CommitQueue<number>();
1695
+ const markOf = (c: number) => marks.get(c) ?? 0;
1696
+ marks.set(one, P1);
1697
+ queue.put(one, t.date(one));
1698
+ for (const c of twos) {
1699
+ if (c === one) return marks;
1700
+ marks.set(c, markOf(c) | P2);
1701
+ queue.put(c, t.date(c));
1702
+ }
1703
+ const nonStale = () => queue.items().some((c) => !(markOf(c) & STALE));
1704
+ while (nonStale()) {
1705
+ const c = queue.get() as number;
1706
+ let flags = markOf(c) & (P1 | P2 | STALE);
1707
+ if (flags === (P1 | P2)) {
1708
+ marks.set(c, markOf(c) | RESULT);
1709
+ flags |= STALE;
1710
+ }
1711
+ for (let k = 0, n = t.parentCount(c); k < n; k++) {
1712
+ const p = t.parent(c, k);
1713
+ if ((markOf(p) & flags) === flags) continue;
1714
+ if (!(await parse(p))) {
1715
+ throw new GitApiError(`could not parse commit ${t.idOf(p)}`);
1716
+ }
1717
+ marks.set(p, markOf(p) | flags);
1718
+ queue.put(p, t.date(p));
1719
+ }
1720
+ }
1721
+ return marks;
1722
+ };
1723
+ /** commit-reach.c's reduce_heads: the commits no other one of `heads` reaches, in order */
1724
+ const reduceHeads = async (heads: number[]): Promise<number[]> => {
1725
+ const array = [...new Set(heads)];
1726
+ for (const c of array) await parse(c);
1727
+ const redundant = new Array<boolean>(array.length).fill(false);
1728
+ for (let i = 0; i < array.length; i++) {
1729
+ if (redundant[i]) continue;
1730
+ const others: number[] = [];
1731
+ const index: number[] = [];
1732
+ for (let j = 0; j < array.length; j++) {
1733
+ if (i === j || redundant[j]) continue;
1734
+ others.push(array[j] as number);
1735
+ index.push(j);
1736
+ }
1737
+ const marks = await paintDown(array[i] as number, others);
1738
+ if ((marks.get(array[i] as number) ?? 0) & 2) redundant[i] = true;
1739
+ for (let j = 0; j < others.length; j++) {
1740
+ if ((marks.get(others[j] as number) ?? 0) & 1) redundant[index[j] as number] = true;
1741
+ }
1742
+ }
1743
+ return array.filter((_, i) => !redundant[i]);
1744
+ };
1745
+ /** revision.c's simplify_merges over the sorted list: the commits that stay */
1746
+ const simplifyMergesOf = async (list: number[]): Promise<number[]> => {
1747
+ const simplified = new Map<number, number>();
1748
+ const simplifyOne = async (commit: number, tail: number[]): Promise<void> => {
1749
+ if (simplified.has(commit)) return;
1750
+ // an UNINTERESTING commit and a root simplify to themselves
1751
+ if (t.flag(commit) & UNINTERESTING || t.parentCount(commit) === 0) {
1752
+ simplified.set(commit, commit);
1753
+ return;
1754
+ }
1755
+ let pending = 0;
1756
+ for (let k = 0, c = t.parentCount(commit); k < c; k++) {
1757
+ const p = t.parent(commit, k);
1758
+ if (!simplified.has(p)) {
1759
+ tail.push(p);
1760
+ pending++;
1761
+ }
1762
+ if (firstParentOnly) break;
1763
+ }
1764
+ if (pending) {
1765
+ tail.push(commit);
1766
+ return;
1767
+ }
1768
+ // each parent rewritten to what it simplifies to
1769
+ for (let k = 0, c = t.parentCount(commit); k < c; k++) {
1770
+ t.setParent(commit, k, simplified.get(t.parent(commit, k)) as number);
1771
+ if (firstParentOnly) break;
1772
+ }
1773
+ let cnt = firstParentOnly ? 1 : await removeDuplicateParents(commit);
1774
+ if (cnt > 1) {
1775
+ // mark_redundant_parents and mark_treesame_root_parents (git's TMP_MARK)
1776
+ const parents = t.parentList(commit);
1777
+ const reduced = await reduceHeads(parents);
1778
+ const marked = new Set<number>();
1779
+ let count = 0;
1780
+ for (const p of parents) {
1781
+ if (!reduced.includes(p)) {
1782
+ marked.add(p);
1783
+ count++;
1784
+ }
1785
+ }
1786
+ for (const p of parents) {
1787
+ if (t.parentCount(p) === 0 && t.flag(p) & TREESAME) {
1788
+ marked.add(p);
1789
+ count++;
1790
+ }
1791
+ }
1792
+ if (count) {
1793
+ // leave_one_treesame_to_parent
1794
+ const ts = treesame.get(commit);
1795
+ let unmarked: number | undefined;
1796
+ let markedOne: number | undefined;
1797
+ for (let k = 0; k < parents.length; k++) {
1798
+ if (!ts?.[k]) continue;
1799
+ const p = parents[k] as number;
1800
+ if (marked.has(p)) markedOne ??= p;
1801
+ else {
1802
+ unmarked = p;
1803
+ break;
1804
+ }
1805
+ }
1806
+ if (unmarked === undefined && markedOne !== undefined) {
1807
+ marked.delete(markedOne);
1808
+ count--;
1809
+ }
1810
+ }
1811
+ if (count) {
1812
+ // remove_marked_parents
1813
+ const current = [...parents];
1814
+ let nth = 0;
1815
+ let removed = 0;
1816
+ for (const p of parents) {
1817
+ if (marked.has(p)) {
1818
+ current.splice(nth, 1);
1819
+ t.setParentList(commit, current);
1820
+ removed++;
1821
+ await compactTreesame(commit, nth);
1822
+ continue;
1823
+ }
1824
+ nth++;
1825
+ }
1826
+ // removing parents can only make the commit TREESAME
1827
+ if (removed && !(t.flag(commit) & TREESAME)) updateTreesame(commit);
1828
+ cnt = nth;
1829
+ }
1830
+ }
1831
+ const parent =
1832
+ !cnt || t.flag(commit) & UNINTERESTING || !(t.flag(commit) & TREESAME)
1833
+ ? undefined
1834
+ : oneRelevantParent(t, commit, firstParentOnly, relevant);
1835
+ if (parent === undefined || (showPulls && t.flag(commit) & PULL_MERGE)) {
1836
+ simplified.set(commit, commit);
1837
+ } else simplified.set(commit, simplified.get(parent) as number);
1838
+ };
1839
+ let yetToDo = [...list].reverse();
1840
+ while (yetToDo.length > 0) {
1841
+ const todo = yetToDo;
1842
+ yetToDo = [];
1843
+ for (const commit of todo) await simplifyOne(commit, yetToDo);
1844
+ }
1845
+ return list.filter((c) => simplified.get(c) === c);
1846
+ };
1847
+ /**
1848
+ * revision.c's rewrite_parents with rewrite_one in a streaming walk: each commit passed on
1849
+ * the way down is processed first (process_parents, its parents queued through a queue
1850
+ * of its own merged into the walk's), as git rewrites while it streams.
1851
+ */
1852
+ const rewriteStreaming = async (n: number, walkQueue: CommitQueue<number>) => {
1853
+ const out: number[] = [];
1854
+ for (let k = 0, c = t.parentCount(n); k < c; k++) {
1855
+ let p: number | undefined = t.parent(n, k);
1856
+ const own = new CommitQueue<number>();
1857
+ for (;;) {
1858
+ await processParents(p, own);
1859
+ if (t.flag(p) & UNINTERESTING || !(t.flag(p) & TREESAME)) break;
1860
+ if (t.parentCount(p) === 0) {
1861
+ p = undefined;
1862
+ break;
1863
+ }
1864
+ const next = oneRelevantParent(t, p, firstParentOnly, relevant);
1865
+ if (next === undefined) break;
1866
+ p = next;
1867
+ }
1868
+ for (let q = own.get(); q !== undefined; q = own.get()) walkQueue.put(q, t.date(q));
1869
+ if (p !== undefined && !out.includes(p)) out.push(p);
1870
+ }
1871
+ return out;
1872
+ };
1873
+ // `a...b`: git's get_merge_bases parsed every commit it painted while reading the
1874
+ // arguments, so mark_parents_uninteresting from the merge bases reaches through them
1875
+ for (let i = 0; i + 1 < pending.length; i++) {
1876
+ const a = pending[i] as PendingCommit;
1877
+ const b = pending[i + 1] as PendingCommit;
1878
+ if (!a.left || b.left || a.exclude !== b.exclude) continue;
1879
+ const na = t.lookup(a.id);
1880
+ const nb = t.lookup(b.id);
1881
+ if (!(await parse(na)) || !(await parse(nb))) continue;
1882
+ const marks = await paintDown(na, [nb]);
1883
+ const bases: number[] = [];
1884
+ for (const [c, m] of marks) if (m & 8 && !(m & 4)) bases.push(c);
1885
+ // get_merge_bases_many_0's remove_redundant over several candidates parses more
1886
+ if (bases.length > 1) await reduceHeads(bases);
1887
+ }
1205
1888
  for (const e of pending) {
1206
1889
  const n = t.lookup(e.id);
1207
1890
  if (!(await parse(n))) continue;
@@ -1217,16 +1900,27 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1217
1900
  }
1218
1901
  // commit_list_sort_by_date (stable), then into the date queue in that order
1219
1902
  list.sort((a, b) => t.date(b) - t.date(a));
1903
+ // limit_list's collect_bottom_commits
1904
+ if (this.ancestryPathImplicit) {
1905
+ for (const n of list) if (t.flag(n) & BOTTOM) ancestryBottoms.unshift(n);
1906
+ if (ancestryBottoms.length === 0) {
1907
+ throw new GitApiError("--ancestry-path given but there are no bottom commits");
1908
+ }
1909
+ }
1220
1910
  const queue = new CommitQueue<number>();
1221
1911
  for (const n of list) queue.put(n, t.date(n));
1222
1912
 
1223
1913
  const none = this.maxCount !== undefined && this.maxCount <= 0;
1224
1914
  const output = this.outputWalk;
1225
- const order = this.order;
1915
+ // --simplify-merges sorts topologically (in graph order unless another order is set)
1916
+ const order = this.order ?? (simplifyMerges ? "topo" : undefined);
1226
1917
  // the output's walk and a sorted one are limited (git without generation numbers limits
1227
- // a topo walk)
1918
+ // a topo walk); per-parent TREESAME is kept where limiting or simplify_merges needs it
1228
1919
  trackTreesame =
1229
- (limited || !!output || !!order) && prune && !simplifyHistory && !firstParentOnly;
1920
+ prune &&
1921
+ !simplifyHistory &&
1922
+ !firstParentOnly &&
1923
+ (simplifyMerges || ((limited || !!output || !!order) && dense));
1230
1924
  /** git's sort_in_topological_order of `list` (parents as simplified, unparsed: none) */
1231
1925
  const sortTopo = async (list: number[], sort: LogOrder | undefined): Promise<number[]> => {
1232
1926
  if (list.length === 0) return list;
@@ -1275,7 +1969,10 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1275
1969
 
1276
1970
  /** get_revision_1's commits, in the order they come out */
1277
1971
  let candidates: AsyncIterable<number> | Iterable<number>;
1972
+ /** The streaming walk's queue, which rewriting parents walks on (rewrite_one_1) */
1973
+ let streamQueue: CommitQueue<number> | undefined;
1278
1974
  if (!limited && !output && !order) {
1975
+ streamQueue = queue;
1279
1976
  // get_revision_1, streaming
1280
1977
  const since = this.sinceTime;
1281
1978
  candidates = (async function* () {
@@ -1325,23 +2022,81 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1325
2022
  if (slop) continue;
1326
2023
  break;
1327
2024
  }
1328
- if (this.untilTime !== undefined && t.date(n) > this.untilTime) continue;
2025
+ // -L: every commit is followed, --until hides it when shown (get_commit_action)
2026
+ if (this.untilTime !== undefined && t.date(n) > this.untilTime && !this.lineLog) continue;
1329
2027
  date = t.date(n);
1330
2028
  newlist.push(n);
1331
2029
  }
2030
+ if (this.cherryPick || this.cherryMark) {
2031
+ await this.cherryPickList(newlist, t, parse, pathspec ? this.pathspecItems() : undefined);
2032
+ }
2033
+ // limit_left_right
2034
+ if (this.leftOnly || this.rightOnly) {
2035
+ for (const n of newlist) {
2036
+ const left = !!(t.flag(n) & SYMMETRIC_LEFT);
2037
+ if (this.rightOnly ? left : !left) t.mark(n, SHOWN);
2038
+ }
2039
+ }
2040
+ if (ancestryPath) limitToAncestry(ancestryBottoms, newlist);
1332
2041
  // commits made TREESAME by parents that became UNINTERESTING
1333
- if (trackTreesame) {
2042
+ if (trackTreesame && dense) {
1334
2043
  for (const n of newlist) {
1335
2044
  if (!(t.flag(n) & (UNINTERESTING | TREESAME))) updateTreesame(n);
1336
2045
  }
1337
2046
  }
1338
2047
  raw.clear();
2048
+ if (this.lineLog) {
2049
+ // -L sorts topologically (revs->topo_order), children before parents
2050
+ const sorted = await sortTopo(newlist, order ?? "topo");
2051
+ const lineOutput = output ?? { topo: true, rewrite: false, entries: [] };
2052
+ if (wantAncestry) {
2053
+ // want_ancestry (`--graph`, `--parents`, `--simplify-merges`,
2054
+ // `--simplify-by-decoration`): line_log_filter with its own parent rewriting, then
2055
+ // simplify_merges (which does nothing without prune: `-L` alone has none,
2056
+ // `--simplify-by-decoration` prunes), then get_commit_action and rewrite_parents
2057
+ const filtered = await this.lineLogFilter(t, sorted);
2058
+ const kept =
2059
+ simplifyMerges && prune ? await simplifyMergesOf(filtered.kept) : filtered.kept;
2060
+ await this.finishOutputWalk(lineOutput, t, kept, shown, relevant, parse, {
2061
+ ancestry: wantAncestry,
2062
+ rewrite,
2063
+ });
2064
+ for (const p of filtered.unwalked) {
2065
+ if (t.flag(p) & SEEN || !(await parse(p)) || !(await shown(p))) continue;
2066
+ lineOutput.unwalkedShown ??= new Set();
2067
+ lineOutput.unwalkedShown.add(t.idOf(p));
2068
+ }
2069
+ } else await this.finishLineLogWalk(lineOutput, t, sorted, shown);
2070
+ if (!output) {
2071
+ let count = 0;
2072
+ let toSkip = this.skip;
2073
+ for (const e of lineOutput.entries) {
2074
+ if (toSkip > 0) {
2075
+ toSkip--;
2076
+ continue;
2077
+ }
2078
+ yield { ...e.commit, id: e.id, parents: e.parents };
2079
+ if (this.maxCount !== undefined && ++count >= this.maxCount) break;
2080
+ }
2081
+ }
2082
+ return;
2083
+ }
2084
+ let sorted = output
2085
+ ? output.topo
2086
+ ? await sortTopo(newlist, order ?? "topo")
2087
+ : newlist
2088
+ : order
2089
+ ? await sortTopo(newlist, order)
2090
+ : newlist;
2091
+ if (simplifyMerges && prune) sorted = await simplifyMergesOf(sorted);
1339
2092
  if (output) {
1340
- const sorted = output.topo ? await sortTopo(newlist, order ?? "topo") : newlist;
1341
- await this.finishOutputWalk(output, t, sorted, shown, relevant, parse);
2093
+ await this.finishOutputWalk(output, t, sorted, shown, relevant, parse, {
2094
+ ancestry: wantAncestry,
2095
+ rewrite,
2096
+ });
1342
2097
  return;
1343
2098
  }
1344
- candidates = order ? await sortTopo(newlist, order) : newlist;
2099
+ candidates = sorted;
1345
2100
  }
1346
2101
 
1347
2102
  // get_revision_internal: --skip, -n, then (--boundary) the parents of the commits
@@ -1357,8 +2112,21 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1357
2112
  // git's -n 0 reads nothing more in a streaming walk; a limited walk is done before
1358
2113
  if (!none) {
1359
2114
  for await (const n of candidates) {
1360
- const commit = await shown(n);
2115
+ const commit = await shown(n, wantAncestry);
1361
2116
  if (!commit) continue;
2117
+ if (wantAncestry && t.parsed(n)) {
2118
+ // the parents shown: as the walk holds them (simplified), rewritten past the
2119
+ // commits not shown (simplify_commit's rewrite_parents changes commit->parents)
2120
+ const held = t.parentList(n);
2121
+ if (rewrite) {
2122
+ commit.savedParents = held.map((p) => t.idOf(p));
2123
+ const rewritten = streamQueue
2124
+ ? await rewriteStreaming(n, streamQueue)
2125
+ : rewriteParents(t, n, firstParentOnly, relevant);
2126
+ t.setParentList(n, rewritten);
2127
+ commit.parents = rewritten.map((p) => t.idOf(p));
2128
+ } else commit.parents = held.map((p) => t.idOf(p));
2129
+ }
1362
2130
  if (skipped < this.skip) {
1363
2131
  skipped++;
1364
2132
  continue;
@@ -1367,12 +2135,16 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1367
2135
  if (collectBoundary) {
1368
2136
  for (let k = 0, c = t.parentCount(n); k < c; k++) {
1369
2137
  const p = t.parent(n, k);
1370
- if (shownSet.has(p) || childShown.has(p)) continue;
2138
+ if (shownSet.has(p) || childShown.has(p) || t.flag(p) & SHOWN) continue;
1371
2139
  childShown.add(p);
1372
2140
  boundaryCommits.push(p);
1373
2141
  }
1374
2142
  }
1375
2143
  yield commit;
2144
+ // git log and rev-list free a shown commit's parents (cmd_log_walk, finish_commit):
2145
+ // a later rewrite passing through it finds none (not under --reverse, which reads
2146
+ // the whole walk first)
2147
+ if (rewrite && !this.reverse && !this.keepShownParents) t.setParentList(n, []);
1376
2148
  if (this.maxCount !== undefined && ++count >= this.maxCount) break;
1377
2149
  }
1378
2150
  }
@@ -1381,7 +2153,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1381
2153
  const boundaryList: number[] = [];
1382
2154
  const marked = new Set<number>();
1383
2155
  for (const n of boundaryCommits) {
1384
- if (shownSet.has(n) || marked.has(n)) continue;
2156
+ if (shownSet.has(n) || marked.has(n) || t.flag(n) & SHOWN) continue;
1385
2157
  marked.add(n);
1386
2158
  boundaryList.unshift(n);
1387
2159
  }
@@ -1391,7 +2163,13 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1391
2163
  if (!commit) continue;
1392
2164
  if (shallow.has(id)) commit.parents = [];
1393
2165
  const source = sources?.get(n);
1394
- yield { ...commit, id, boundary: true, ...(source !== undefined ? { source } : {}) };
2166
+ yield {
2167
+ ...commit,
2168
+ id,
2169
+ boundary: true,
2170
+ ...(source !== undefined ? { source } : {}),
2171
+ ...sideOf(n),
2172
+ };
1395
2173
  }
1396
2174
  }
1397
2175
 
@@ -1404,68 +2182,39 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1404
2182
  output: OutputWalk,
1405
2183
  t: RevTable,
1406
2184
  newlist: number[],
1407
- shown: (n: number, rewrite?: boolean) => Promise<LogResult | undefined>,
2185
+ shown: (n: number, ancestry?: boolean) => Promise<LogResult | undefined>,
1408
2186
  relevant: (n: number) => boolean,
1409
2187
  parse: (n: number) => Promise<boolean>,
2188
+ mode: { ancestry: boolean; rewrite: boolean },
1410
2189
  ): Promise<void> {
1411
2190
  const order = newlist;
1412
2191
  const firstParentOnly = this.firstParentOnly;
1413
- /** revision.c's one_relevant_parent */
1414
- const oneRelevantParent = (n: number): number | undefined => {
1415
- const c = t.parentCount(n);
1416
- if (c === 0) return undefined;
1417
- if (firstParentOnly || c === 1) return t.parent(n, 0);
1418
- let found: number | undefined;
1419
- for (let k = 0; k < c; k++) {
1420
- const p = t.parent(n, k);
1421
- if (!relevant(p)) continue;
1422
- if (found !== undefined) return undefined;
1423
- found = p;
1424
- }
1425
- return found;
1426
- };
1427
- /** revision.c's rewrite_one: the parent shown in place of `p`; undefined to drop it */
1428
- const rewriteOne = (start: number): number | undefined => {
1429
- let p = start;
1430
- for (;;) {
1431
- if (t.flag(p) & UNINTERESTING) return p;
1432
- if (!(t.flag(p) & TREESAME)) return p;
1433
- if (t.parentCount(p) === 0) return undefined;
1434
- const next = oneRelevantParent(p);
1435
- if (next === undefined) return p;
1436
- p = next;
1437
- }
1438
- };
1439
- const prune = this.paths.length > 0 || this.excludePaths.length > 0;
1440
2192
  /** Rewritten parents the walk never reached (only with `--first-parent`) */
1441
2193
  const unwalked = new Set<number>();
1442
2194
  for (const n of order) {
1443
- const commit = await shown(n, output.rewrite && prune);
2195
+ const commit = await shown(n, mode.ancestry);
1444
2196
  if (!commit) continue;
1445
- let parents = commit.parents;
2197
+ // the parents as the walk holds them (simplified), as git's commit->parents
2198
+ let parents = t.parsed(n) ? t.parentList(n).map((p) => t.idOf(p)) : commit.parents;
1446
2199
  let savedParents: ObjectId[] | undefined;
1447
- if (output.rewrite && prune) {
2200
+ if (mode.rewrite) {
1448
2201
  // the parents before rewriting, which `--full-diff` diffs against (save_parents)
1449
- savedParents = [];
1450
- for (let k = 0, c = t.parentCount(n); k < c; k++) savedParents.push(t.idOf(t.parent(n, k)));
1451
- const ids: ObjectId[] = [];
1452
- for (let k = 0, c = t.parentCount(n); k < c; k++) {
1453
- const p = rewriteOne(t.parent(n, k));
1454
- if (p === undefined) continue;
1455
- if (!(t.flag(p) & SEEN)) unwalked.add(p);
1456
- const id = t.idOf(p);
1457
- // remove_duplicate_parents
1458
- if (!ids.includes(id)) ids.push(id);
1459
- }
1460
- parents = ids;
2202
+ savedParents = parents;
2203
+ const rewritten = rewriteParents(t, n, firstParentOnly, relevant);
2204
+ for (const p of rewritten) if (!(t.flag(p) & SEEN)) unwalked.add(p);
2205
+ parents = rewritten.map((p) => t.idOf(p));
1461
2206
  }
1462
- const { id, source, boundary: _boundary, ...rest } = commit;
2207
+ const { id, source, boundary: _boundary, left, patchSame, ...rest } = commit;
2208
+ // the parents git frees once the commit is shown (cmd_log_walk; --skip's are not)
2209
+ if (mode.rewrite && output.entries.length >= this.skip) t.setParentList(n, []);
1463
2210
  output.entries.push({
1464
2211
  id,
1465
2212
  commit: rest,
1466
2213
  parents,
1467
2214
  ...(savedParents ? { savedParents } : {}),
1468
2215
  ...(source !== undefined ? { source } : {}),
2216
+ ...(left ? { left } : {}),
2217
+ ...(patchSame ? { patchSame } : {}),
1469
2218
  });
1470
2219
  }
1471
2220
  // graph.c's graph_is_interesting asks get_commit_action about a parent: one the walk
@@ -1479,6 +2228,268 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1479
2228
  }
1480
2229
  }
1481
2230
 
2231
+ /**
2232
+ * line-log.c's line_log_init: the one commit the log starts from (check_single_commit),
2233
+ * the `-L` ranges parsed against it, and the walk that follows them
2234
+ */
2235
+ private async startLineLog(pending: PendingCommit[]): Promise<void> {
2236
+ let found: PendingCommit | undefined;
2237
+ for (const e of pending) {
2238
+ if (e.exclude) continue;
2239
+ const name = e.name ?? e.id;
2240
+ if (!(await this.readCommitHeader(e.id).catch(() => undefined))) {
2241
+ throw lineLogDeath(`Non commit ${name}?`);
2242
+ }
2243
+ if (found) {
2244
+ throw lineLogDeath(
2245
+ `More than one commit to dig from: ${name} and ${found.name ?? found.id}?`,
2246
+ );
2247
+ }
2248
+ found = e;
2249
+ }
2250
+ if (!found) throw lineLogDeath("No commit specified?");
2251
+ const host = this.lineLogHost();
2252
+ const tree = await host.treeOf(found.id);
2253
+ const drivers = new DiffCommand(this._workingCopy)
2254
+ .setOldTree(tree)
2255
+ .setNewTree(tree)
2256
+ .shareReadsOf(this)
2257
+ .setOptions(this.lineLogDiffOptions());
2258
+ const ranges = await parseLineRanges(this.lineRangeArgs, {
2259
+ blob: async (path) => {
2260
+ const e = await this.treeEntryAt(tree, path);
2261
+ if (!e) return undefined;
2262
+ // a submodule reads as its commit line (diff_populate_filespec)
2263
+ if ((e.mode & 0o170000) === 0o160000) return { ...e, data: gitlinkText(e.id) };
2264
+ const data = await this.readBlob(e.id);
2265
+ if (!data) throw lineLogDeath(`Cannot read blob ${e.id}`);
2266
+ return { ...e, data };
2267
+ },
2268
+ findFunction: async (path) => (await drivers.driverOf(path))?.findFunction,
2269
+ });
2270
+ this.lineLog = new LineLogWalk(host, this.compatibility, this.firstParentOnly);
2271
+ this.lineLog.start(found.id, ranges);
2272
+ }
2273
+
2274
+ /** The diff options of `-L`'s diffs: the builtin drivers of the version followed */
2275
+ private lineLogDiffOptions(): DiffTextOptions {
2276
+ return {
2277
+ ...this.diffOptions,
2278
+ driverCompatibility: this.diffOptions.driverCompatibility ?? this.compatibility,
2279
+ };
2280
+ }
2281
+
2282
+ /** The entry at a path of a tree (its mode canonical), undefined when none */
2283
+ private async treeEntryAt(
2284
+ tree: ObjectId,
2285
+ path: string,
2286
+ ): Promise<{ id: ObjectId; mode: number } | undefined> {
2287
+ const parts = path.split("/");
2288
+ let cur = tree;
2289
+ for (let i = 0; i < parts.length; i++) {
2290
+ const e = await this.entryOf(cur, encodeGitPath(parts[i] as string));
2291
+ if (!e) return undefined;
2292
+ if (i === parts.length - 1) return { id: e.id, mode: canonTreeMode(e.mode) };
2293
+ if (!isTreeMode(e.mode)) return undefined;
2294
+ cur = e.id;
2295
+ }
2296
+ return undefined;
2297
+ }
2298
+
2299
+ /** What `-L`'s walk reads: trees, entries, blobs, and renames as queue_diffs finds them */
2300
+ private lineLogHost(): LineLogHost {
2301
+ const o = this.diffOptions;
2302
+ let detect =
2303
+ o.findRenames !== undefined
2304
+ ? o.findRenames !== false
2305
+ : (renamesValue(configValue(this.workingCopy, "diff.renames")) ?? true) !== false;
2306
+ if (o.findCopies !== undefined && o.findCopies !== false) detect = true;
2307
+ const score =
2308
+ typeof o.findRenames === "string"
2309
+ ? renameScoreOption(o.findRenames, "find-renames")
2310
+ : undefined;
2311
+ const limit = Number(configValue(this.workingCopy, "diff.renameLimit"));
2312
+ const renameLimit =
2313
+ Number.isFinite(limit) && configValue(this.workingCopy, "diff.renameLimit") !== undefined
2314
+ ? limit
2315
+ : DEFAULT_RENAME_LIMIT;
2316
+ const blob = async (id: ObjectId): Promise<Uint8Array> => {
2317
+ const data = await this.readBlob(id);
2318
+ if (!data) throw lineLogDeath(`Cannot read blob ${id}`);
2319
+ return data;
2320
+ };
2321
+ return {
2322
+ treeOf: async (id) => {
2323
+ const header = await this.readCommitHeader(id, await this.objectReplacements());
2324
+ if (!header) throw new GitApiError(`could not parse commit ${id}`);
2325
+ return header.tree;
2326
+ },
2327
+ entry: (tree, path) => this.treeEntryAt(tree, path),
2328
+ blob,
2329
+ ...(hasPickaxe(o) || o.diffFilter !== undefined
2330
+ ? {
2331
+ diffcore: async (pairs: LineLogPair[]) => {
2332
+ const entries = new Map<DiffEntry, LineLogPair>();
2333
+ for (const pair of pairs) entries.set(lineLogEntry(pair), pair);
2334
+ const kept = await new DiffCommand(this._workingCopy)
2335
+ .shareReadsOf(this)
2336
+ .setOptions(this.lineLogDiffOptions())
2337
+ .filterQueue([...entries.keys()]);
2338
+ const out: LineLogPair[] = [];
2339
+ for (const e of kept) {
2340
+ const pair = entries.get(e) ?? pairs.find((p) => p.two.path === e.newPath);
2341
+ if (pair) out.push(pair);
2342
+ }
2343
+ return out;
2344
+ },
2345
+ }
2346
+ : {}),
2347
+ ...(detect
2348
+ ? {
2349
+ renames: async (
2350
+ parentTree: ObjectId,
2351
+ tree: ObjectId,
2352
+ created: { path: string; id: ObjectId; mode: number }[],
2353
+ ) => {
2354
+ const before = await this.flatTree(parentTree);
2355
+ const after = await this.flatTree(tree);
2356
+ const sources = [...before]
2357
+ .filter(([path]) => !after.has(path))
2358
+ .map(([path, e]) => ({ path, mode: e.mode, id: e.id }));
2359
+ if (sources.length === 0) return [];
2360
+ const pairs = await detectRenames(
2361
+ sources,
2362
+ created.map((c) => ({ path: c.path, mode: c.mode, id: c.id })),
2363
+ {
2364
+ load: async (c) =>
2365
+ (c.mode & 0o170000) === 0o160000 ? gitlinkText(c.id) : blob(c.id),
2366
+ renameLimit,
2367
+ ...(score !== undefined ? { minimumScore: score } : {}),
2368
+ },
2369
+ );
2370
+ const out: {
2371
+ from: { path: string; id: ObjectId; mode: number };
2372
+ to: string;
2373
+ score: number;
2374
+ }[] = [];
2375
+ for (const pair of pairs) {
2376
+ const from = before.get(pair.from);
2377
+ if (!from) continue;
2378
+ out.push({
2379
+ from: { path: pair.from, id: from.id, mode: canonTreeMode(from.mode) },
2380
+ to: pair.to,
2381
+ score: scorePercent(pair.score),
2382
+ });
2383
+ }
2384
+ return out;
2385
+ },
2386
+ }
2387
+ : {}),
2388
+ };
2389
+ }
2390
+
2391
+ /**
2392
+ * The walk's commits under `-L` without parents rewritten, sorted topologically: each
2393
+ * followed in turn (git's simplify_commit), shown when its diff touched the ranges and the
2394
+ * other filters keep it, with the parents a merge kept (one when a parent took it all).
2395
+ */
2396
+ private async finishLineLogWalk(
2397
+ output: OutputWalk,
2398
+ t: RevTable,
2399
+ order: number[],
2400
+ shown: (n: number, ancestry?: boolean) => Promise<LogResult | undefined>,
2401
+ ): Promise<void> {
2402
+ const ll = this.lineLog as LineLogWalk;
2403
+ for (const n of order) {
2404
+ const id = t.idOf(n);
2405
+ if (!(await ll.process(id, lineLogParentIds(t, n)))) continue;
2406
+ const commit = await shown(n);
2407
+ if (!commit) continue;
2408
+ const { id: _id, source, boundary: _boundary, left, patchSame, ...rest } = commit;
2409
+ output.entries.push({
2410
+ id,
2411
+ commit: rest,
2412
+ parents: ll.parentsOf(id) ?? commit.parents,
2413
+ ...(source !== undefined ? { source } : {}),
2414
+ ...(left ? { left } : {}),
2415
+ ...(patchSame ? { patchSame } : {}),
2416
+ });
2417
+ }
2418
+ }
2419
+
2420
+ /**
2421
+ * line-log.c's line_log_filter: every commit of the sorted list followed, those whose diff
2422
+ * touched no range marked TREESAME (a merge one parent took whole left with that parent),
2423
+ * the others kept with their parents rewritten past TREESAME commits
2424
+ * (line_log_rewrite_one); `unwalked` the parents rewritten to that the walk never reached
2425
+ */
2426
+ private async lineLogFilter(
2427
+ t: RevTable,
2428
+ order: number[],
2429
+ ): Promise<{ kept: number[]; unwalked: Set<number> }> {
2430
+ const ll = this.lineLog as LineLogWalk;
2431
+ const kept: number[] = [];
2432
+ for (const n of order) {
2433
+ const id = t.idOf(n);
2434
+ if (await ll.process(id, lineLogParentIds(t, n))) kept.push(n);
2435
+ else t.mark(n, TREESAME);
2436
+ const narrowed = ll.parentsOf(id);
2437
+ if (narrowed)
2438
+ t.setParentList(
2439
+ n,
2440
+ narrowed.map((p) => t.lookup(p)),
2441
+ );
2442
+ }
2443
+ /** line_log_rewrite_one */
2444
+ const rewriteOne = (start: number): number | undefined => {
2445
+ let p = start;
2446
+ for (;;) {
2447
+ const parents = t.parsed(p) ? t.parentList(p) : [];
2448
+ if (parents.length > 1 || t.flag(p) & UNINTERESTING || !(t.flag(p) & TREESAME)) return p;
2449
+ if (parents.length === 0) return undefined;
2450
+ p = parents[0] as number;
2451
+ }
2452
+ };
2453
+ const unwalked = new Set<number>();
2454
+ for (const n of kept) {
2455
+ const rewritten: number[] = [];
2456
+ for (const q of t.parentList(n)) {
2457
+ const p = rewriteOne(q);
2458
+ if (p === undefined) continue;
2459
+ if (!(t.flag(p) & SEEN)) unwalked.add(p);
2460
+ if (!rewritten.includes(p)) rewritten.push(p);
2461
+ }
2462
+ t.setParentList(n, rewritten);
2463
+ }
2464
+ return { kept, unwalked };
2465
+ }
2466
+
2467
+ /**
2468
+ * setup_revisions' and cmd_log_init_finish's refusals of `-L`: the diff formats it cannot
2469
+ * show (2.43: anything but `-p` and `-s`), then a pathspec
2470
+ */
2471
+ private checkLineLogOptions(options: LogOutputOptions): void {
2472
+ const o = options;
2473
+ if (this.compatibility === "2.43") {
2474
+ if (
2475
+ o.stat ||
2476
+ o.shortstat ||
2477
+ o.numstat ||
2478
+ o.nameOnly ||
2479
+ o.nameStatus ||
2480
+ o.summary ||
2481
+ o.check
2482
+ ) {
2483
+ throw lineLogDeath("-L does not yet support diff formats besides -p and -s");
2484
+ }
2485
+ } else if (o.stat || o.shortstat || o.numstat || o.check || o.fullDiff) {
2486
+ throw lineLogDeath("-L does not yet support the requested diff format");
2487
+ }
2488
+ if (this.paths.length > 0 || this.excludePaths.length > 0) {
2489
+ throw lineLogDeath("-L<range>:<file> cannot be used with pathspec");
2490
+ }
2491
+ }
2492
+
1482
2493
  /**
1483
2494
  * The log printed as `git log <options>` prints it to a pipe (no pager; colors only when
1484
2495
  * `setDiffOptions({ color })` or `color.ui`/`color.diff` say `always`): the
@@ -1499,13 +2510,18 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1499
2510
  /** {@link callText} as bytes (messages and file contents that are not UTF-8 kept as they are). */
1500
2511
  async callBytes(options: LogOutputOptions = {}): Promise<Uint8Array> {
1501
2512
  // one operation for the worktree: its attributes files (diff drivers) and configuration
1502
- // are read once for every commit's diff, as git keeps its attribute stack
1503
- const worktree = this.worktreeAccess;
1504
- if (worktree?.batch) return worktree.batch(() => this.printLog(options));
1505
- return this.printLog(options);
2513
+ // are read once for every commit's diff, as git keeps its attribute stack (a bare
2514
+ // repository's working copy has none)
2515
+ return this.inOneOperation(() => this.printLog(options));
1506
2516
  }
1507
2517
 
1508
2518
  private async printLog(options: LogOutputOptions): Promise<Uint8Array> {
2519
+ const result = await this.printLogOutput(options);
2520
+ if (this.logConfig) await this.reportMailmapErrors(options, result.length > 0);
2521
+ return result;
2522
+ }
2523
+
2524
+ private async printLogOutput(options: LogOutputOptions): Promise<Uint8Array> {
1509
2525
  const reverse = !!options.reverse || this.reverse;
1510
2526
  await this.checkReflogWalkOptions(options);
1511
2527
  // revision.c's setup_revisions: the graph cannot be reversed
@@ -1524,6 +2540,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1524
2540
  const colors = this.readColors();
1525
2541
  const host = this.outputHost(options);
1526
2542
  const paths = [...this.paths];
2543
+ // -L: the walk is sorted, its commits followed before the first is shown
2544
+ const lineLog = this.lineRangeArgs.length > 0;
1527
2545
  // the pathspec as git holds it: the excluded paths as `:(exclude)` elements, `.` when
1528
2546
  // every element excludes
1529
2547
  const pathspec = [...paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
@@ -1535,13 +2553,16 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1535
2553
  interesting: (id) => shownIds.has(id) || unwalkedShown.has(id),
1536
2554
  firstParentOnly: this.firstParentOnly,
1537
2555
  paths: pathspec,
2556
+ ...this.revisionMarks(),
1538
2557
  ...(colors ? { colors } : {}),
2558
+ ...(lineLog ? { lineLog: this.compatibility } : {}),
1539
2559
  },
1540
2560
  );
2561
+ if (lineLog) this.checkLineLogOptions(options);
1541
2562
  const follow = printer.followsPath;
1542
2563
  const countsShown = !printer.alwaysShowHeader;
1543
2564
  const graph = !!options.graph;
1544
- const topo = graph;
2565
+ const topo = graph || lineLog;
1545
2566
  const boundary = !!options.boundary || this.boundary;
1546
2567
  if (graph && boundary) {
1547
2568
  // graph.c draws boundary commits as `o` in columns of their own: not reproduced
@@ -1560,6 +2581,19 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1560
2581
  const skip = this.skip;
1561
2582
  const simplifyHistory = this.simplifyHistory;
1562
2583
  if (printer.fullHistory) this.simplifyHistory = false;
2584
+ // --parents: rewritten parents (the header's ids, %P)
2585
+ if (options.parents) this.rewriteParents = true;
2586
+ // --simplify-by-decoration keeps the commits git log's decoration filter decorates
2587
+ this.decorationLoader = () =>
2588
+ host.decorations({
2589
+ decorate: "short",
2590
+ ...(options.decorateRefs ? { decorateRefs: options.decorateRefs } : {}),
2591
+ ...(options.decorateRefsExclude
2592
+ ? { decorateRefsExclude: options.decorateRefsExclude }
2593
+ : {}),
2594
+ ...(options.clearDecorations ? { clearDecorations: true } : {}),
2595
+ });
2596
+ this.keepShownParents = reverse;
1563
2597
  // --follow walks every commit: its path changes as it goes
1564
2598
  if (follow) this.paths = [];
1565
2599
  const shownIds = new Set<ObjectId>();
@@ -1591,14 +2625,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1591
2625
  if (maxCount === undefined || maxCount > 0) {
1592
2626
  let shownCount = 0;
1593
2627
  for await (const c of await this.call()) {
1594
- const { id, boundary: isBoundary, source, ...commit } = c;
1595
- const entry: LogOutputEntry = {
1596
- id,
1597
- commit,
1598
- parents: c.parents,
1599
- ...(isBoundary ? { boundary: true } : {}),
1600
- ...(source !== undefined ? { source } : {}),
1601
- };
2628
+ const entry = outputEntry(c);
1602
2629
  const shown = await printer.showCommit(entry, []);
1603
2630
  if (shown && countsShown && maxCount !== undefined && ++shownCount >= maxCount) break;
1604
2631
  }
@@ -1617,14 +2644,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1617
2644
  // --reverse: the newest commits walked, reversed, then shown
1618
2645
  entries = [];
1619
2646
  for await (const c of await this.call()) {
1620
- const { id, boundary: isBoundary, source, ...commit } = c;
1621
- entries.push({
1622
- id,
1623
- commit,
1624
- parents: c.parents,
1625
- ...(isBoundary ? { boundary: true } : {}),
1626
- ...(source !== undefined ? { source } : {}),
1627
- });
2647
+ entries.push(outputEntry(c));
1628
2648
  }
1629
2649
  }
1630
2650
  this.simplifyHistory = simplifyHistory;
@@ -1655,6 +2675,55 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1655
2675
  return printer.result();
1656
2676
  }
1657
2677
 
2678
+ /**
2679
+ * The refs' decorations (log-tree.c's load_ref_decorations): with `logOptions`, git log's
2680
+ * decoration filter; without, every ref and HEAD (get_name_decoration's own load).
2681
+ */
2682
+ private async refDecorations(
2683
+ logOptions?: LoadRefDecorationsOptions["logOptions"],
2684
+ ): Promise<RefDecorations> {
2685
+ const replacements = await this.objectReplacements();
2686
+ const shallow = (await this.refsStore.getShallow?.().catch(() => undefined)) ?? [];
2687
+ const environment = hostEnvironmentOf(this._workingCopy);
2688
+ const objects = this._workingCopy.history?.objects;
2689
+ const tags = this.tagsStore;
2690
+ return loadRefDecorations({
2691
+ refs: this.refsStore,
2692
+ ...(tags ? { tags } : {}),
2693
+ ...(environment?.replaceRefBase !== undefined
2694
+ ? { replaceRefBase: environment.replaceRefBase }
2695
+ : {}),
2696
+ useReplaceRefs: this.useReplaceRefs(),
2697
+ grafted: new Set([...(replacements?.grafts.keys() ?? []), ...shallow]),
2698
+ ...(objects ? { hasObject: (id: ObjectId) => objects.has(id) } : {}),
2699
+ ...(logOptions ? { logOptions } : {}),
2700
+ });
2701
+ }
2702
+
2703
+ /** The mailmap, read once for the walk's filters and the output alike. */
2704
+ private loadedMailmap(): Promise<Mailmap> {
2705
+ this.mailmapLoad ??= this.readMailmap((line) => this.mailmapErrors.push(line));
2706
+ return this.mailmapLoad;
2707
+ }
2708
+
2709
+ /**
2710
+ * git's `error:` lines of reading the mailmap (a `mailmap.blob` that is no blob), as git
2711
+ * log prints them: once when it reads the mailmap for the log (`log.mailmap`,
2712
+ * `--use-mailmap`), once more when a user format maps an identity (`%aN`, pretty.c's own
2713
+ * read) of a commit it shows.
2714
+ */
2715
+ private async reportMailmapErrors(options: LogOutputOptions, shown: boolean): Promise<void> {
2716
+ const forLog =
2717
+ options.mailmap ?? this.useMailmap ?? configBool(this.workingCopy, "log.mailmap", true);
2718
+ const pretty = options.pretty ?? configValue(this.workingCopy, "format.pretty") ?? "";
2719
+ const user = /^t?format:/.test(pretty) || (pretty.includes("%") && !options.oneline);
2720
+ const forFormat = shown && user && /%[ac][NEL]/.test(pretty);
2721
+ const times = (forLog ? 1 : 0) + (forFormat ? 1 : 0);
2722
+ if (times === 0) return;
2723
+ await this.loadedMailmap();
2724
+ for (let k = 0; k < times; k++) this.outputWarnings.push(...this.mailmapErrors);
2725
+ }
2726
+
1658
2727
  /**
1659
2728
  * `git show`'s output of objects one at a time (builtin/log.c's cmd_show without a walk):
1660
2729
  * one printer for every object, so commits, tags and trees share git's `shown_one`
@@ -1701,7 +2770,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1701
2770
  if (!loaded) throw new GitApiError(`fatal: bad object ${id}`);
1702
2771
  // try_to_simplify_commit, then get_commit_action: a commit TREESAME to a parent (a
1703
2772
  // root without the paths) is ignored
1704
- if (limited && (await this.treesameForShow(id, loaded))) return false;
2773
+ if (limited && (await this.treesameForShow(id, loaded, printer.fullHistory))) return false;
1705
2774
  const filter = this.activeFilter;
1706
2775
  if (filter) {
1707
2776
  const view: FilteredCommit = {
@@ -1733,9 +2802,15 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1733
2802
  };
1734
2803
  }
1735
2804
 
1736
- /** revision.c's try_to_simplify_commit for a commit git shows without walking */
1737
- private async treesameForShow(id: ObjectId, commit: Commit): Promise<boolean> {
2805
+ /**
2806
+ * revision.c's try_to_simplify_commit for a commit git shows without walking; without
2807
+ * `simplify_history` (`--full-history`, `-m`, `--remerge-diff`) a merge is TREESAME only
2808
+ * to every parent it looks at (update_treesame)
2809
+ */
2810
+ private async treesameForShow(id: ObjectId, commit: Commit, full = false): Promise<boolean> {
1738
2811
  if (commit.parents.length === 0) return !(await this.pathsDiffer(undefined, commit.tree));
2812
+ const merge = commit.parents.length > 1 && !this.firstParentOnly;
2813
+ const all = full || !this.simplifyHistory;
1739
2814
  for (let k = 0; k < commit.parents.length; k++) {
1740
2815
  if (k === 1 && this.firstParentOnly) break;
1741
2816
  const parent = await this.walkCommits.load(commit.parents[k] as ObjectId);
@@ -1744,9 +2819,12 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1744
2819
  `fatal: cannot simplify commit ${id} (because of ${commit.parents[k]})`,
1745
2820
  );
1746
2821
  }
1747
- if (!(await this.pathsDiffer(parent.tree, commit.tree))) return true;
2822
+ const same = !(await this.pathsDiffer(parent.tree, commit.tree));
2823
+ if (merge && all) {
2824
+ if (!same) return false;
2825
+ } else if (same) return true;
1748
2826
  }
1749
- return false;
2827
+ return merge && all;
1750
2828
  }
1751
2829
 
1752
2830
  /**
@@ -1916,6 +2994,38 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1916
2994
  }
1917
2995
  return tree;
1918
2996
  };
2997
+ const runDiff = async (
2998
+ oldTree: ObjectId,
2999
+ newTree: ObjectId,
3000
+ formats: DiffOutputFormat[],
3001
+ options: { statWidth?: number; follow?: string; fullDiff?: boolean; abbrev?: number },
3002
+ prepare?: (diff: DiffCommand) => void,
3003
+ ) => {
3004
+ // the trees themselves: a full id names its object, so no revision is looked up
3005
+ const diff = new DiffCommand(this._workingCopy);
3006
+ prepare?.(diff);
3007
+ diff
3008
+ .setOldTree(oldTree)
3009
+ .setNewTree(newTree)
3010
+ // log's diffcore_rotate starts at the first path after a missing one
3011
+ .setRotateStrict(false)
3012
+ .shareReadsOf(this);
3013
+ if (this.colorSettings) diff.setColorSettings(this.colorSettings);
3014
+ diff.setOptions({
3015
+ ...this.diffOptions,
3016
+ ...(options.statWidth !== undefined
3017
+ ? { stat: { ...this.diffOptions.stat, width: options.statWidth } }
3018
+ : {}),
3019
+ ...(options.abbrev !== undefined ? { abbrev: options.abbrev } : {}),
3020
+ });
3021
+ if (!options.fullDiff && options.follow === undefined) {
3022
+ const spec = [...this.paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
3023
+ if (spec.length > 0) diff.setPathspec(spec);
3024
+ }
3025
+ const shown = await diff.callFormats(formats, options.follow);
3026
+ if (diff.checkFoundErrors) this.checkFailed = true;
3027
+ return shown;
3028
+ };
1919
3029
  return {
1920
3030
  config: (key) => config.value(key),
1921
3031
  configAll: (key) => config.values(key),
@@ -1948,32 +3058,16 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1948
3058
  const bytes = await this.readObjectBytes(replace?.size ? replacementOf(replace, id) : id);
1949
3059
  return bytes ? decodeGitPath(bytes) : undefined;
1950
3060
  },
1951
- decorations: async (options) => {
1952
- const replacements = await this.objectReplacements();
1953
- const shallow = (await this.refsStore.getShallow?.().catch(() => undefined)) ?? [];
1954
- const environment = hostEnvironmentOf(this._workingCopy);
1955
- const objects = this._workingCopy.history?.objects;
1956
- const tags = this.tagsStore;
1957
- return loadRefDecorations({
1958
- refs: this.refsStore,
1959
- ...(tags ? { tags } : {}),
1960
- ...(environment?.replaceRefBase !== undefined
1961
- ? { replaceRefBase: environment.replaceRefBase }
3061
+ decorations: (options) =>
3062
+ this.refDecorations({
3063
+ decorate: options.decorate,
3064
+ ...(options.decorateRefs ? { decorateRefs: options.decorateRefs } : {}),
3065
+ ...(options.decorateRefsExclude
3066
+ ? { decorateRefsExclude: options.decorateRefsExclude }
1962
3067
  : {}),
1963
- useReplaceRefs: this.useReplaceRefs(),
1964
- grafted: new Set([...(replacements?.grafts.keys() ?? []), ...shallow]),
1965
- ...(objects ? { hasObject: (id: ObjectId) => objects.has(id) } : {}),
1966
- logOptions: {
1967
- decorate: options.decorate,
1968
- ...(options.decorateRefs ? { decorateRefs: options.decorateRefs } : {}),
1969
- ...(options.decorateRefsExclude
1970
- ? { decorateRefsExclude: options.decorateRefsExclude }
1971
- : {}),
1972
- ...(options.clearDecorations ? { clearDecorations: true } : {}),
1973
- config,
1974
- },
1975
- });
1976
- },
3068
+ ...(options.clearDecorations ? { clearDecorations: true } : {}),
3069
+ config,
3070
+ }),
1977
3071
  notes: async (id) => {
1978
3072
  notesTrees ??= this.loadNotes(config, options);
1979
3073
  const out: { ref: string; text: string }[] = [];
@@ -1986,34 +3080,60 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1986
3080
  return out;
1987
3081
  },
1988
3082
  mailmap: () => {
1989
- mailmap ??= this.loadMailmap(config);
3083
+ mailmap ??= this.loadedMailmap();
1990
3084
  return mailmap;
1991
3085
  },
1992
- diff: async (entry, parent, formats, options) => {
1993
- // the trees themselves: a full id names its object, so no revision is looked up
3086
+ diff: async (entry, parent, formats, options) =>
3087
+ runDiff(
3088
+ parent ? await treeOf(parent) : this.objectFormat.emptyTreeId,
3089
+ entry.commit.tree,
3090
+ formats,
3091
+ options,
3092
+ ),
3093
+ remergeDiff: async (entry, parents, formats, options) => {
3094
+ // log-tree.c's do_remerge_diff: the re-merge's objects live in a view of their own
3095
+ // (git's tmp_objdir), dropped after this merge
3096
+ const history = this._workingCopy.history;
3097
+ if (!history) throw new Error("WorkingCopy.history is required for commands");
3098
+ const view = remergeObjectsView(history);
3099
+ const remerge = new RemergeTreeCommand(this._workingCopy)
3100
+ .setObjectsView(view)
3101
+ .shareReadsOf(this)
3102
+ .setParents(parents[0], parents[1]);
3103
+ // git 2.43's cmd_log_walk freed the parents of every commit it had processed (2.44
3104
+ // keeps them under --remerge-diff), so its merge bases stop there (`--reverse`)
3105
+ if (
3106
+ this.compatibility === "2.43" &&
3107
+ this.reflogWalkNames === undefined &&
3108
+ options.processed?.size
3109
+ ) {
3110
+ remerge.setParentlessCommits(options.processed);
3111
+ }
3112
+ const remerged = await remerge.call();
3113
+ return runDiff(remerged.treeId, entry.commit.tree, formats, options, (diff) =>
3114
+ diff.setObjectsView(view).setAdditionalHeaders(remerged.pathMessages),
3115
+ );
3116
+ },
3117
+ combinedDiff: (entry, options) => this.combinedDiff(entry, options),
3118
+ lineLogDiff: async (entry, formats, options) => {
3119
+ const lineLog = this.lineLog;
3120
+ if (!lineLog) return {};
3121
+ const tree = entry.commit.tree;
1994
3122
  const diff = new DiffCommand(this._workingCopy)
1995
- .setOldTree(parent ? await treeOf(parent) : this.objectFormat.emptyTreeId)
1996
- .setNewTree(entry.commit.tree)
1997
- // log's diffcore_rotate starts at the first path after a missing one
3123
+ .setOldTree(tree)
3124
+ .setNewTree(tree)
1998
3125
  .setRotateStrict(false)
1999
- .shareReadsOf(this);
3126
+ .shareReadsOf(this)
3127
+ .setQueue(lineLog.queuedPairs(entry.id));
2000
3128
  if (this.colorSettings) diff.setColorSettings(this.colorSettings);
2001
3129
  diff.setOptions({
2002
- ...this.diffOptions,
2003
- ...(options.statWidth !== undefined
2004
- ? { stat: { ...this.diffOptions.stat, width: options.statWidth } }
2005
- : {}),
3130
+ ...this.lineLogDiffOptions(),
2006
3131
  ...(options.abbrev !== undefined ? { abbrev: options.abbrev } : {}),
2007
3132
  });
2008
- if (!options.fullDiff && options.follow === undefined) {
2009
- const spec = [...this.paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
2010
- if (spec.length > 0) diff.setPathspec(spec);
2011
- }
2012
- const shown = await diff.callFormats(formats, options.follow);
2013
- if (diff.checkFoundErrors) this.checkFailed = true;
2014
- return shown;
3133
+ return diff.callFormats(formats);
2015
3134
  },
2016
- combinedDiff: (entry, options) => this.combinedDiff(entry, options),
3135
+ lineLogHacky: async (entry, prefix, colors) =>
3136
+ this.lineLog ? this.lineLog.hackyDiff(entry.id, prefix, colors) : new Uint8Array(0),
2017
3137
  };
2018
3138
  }
2019
3139
 
@@ -2032,6 +3152,9 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
2032
3152
  /** The colors {@link callBytes} prints with */
2033
3153
  private colorSettings?: DiffColorSettings;
2034
3154
  private readonly outputWarnings: string[] = [];
3155
+ /** The mailmap as read once ({@link loadedMailmap}), and git's errors of reading it */
3156
+ private mailmapLoad?: Promise<Mailmap>;
3157
+ private readonly mailmapErrors: string[] = [];
2035
3158
 
2036
3159
  /**
2037
3160
  * What git prints on stderr while {@link callBytes} prints the log without dying: the
@@ -2472,21 +3595,6 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
2472
3595
  return out;
2473
3596
  }
2474
3597
 
2475
- /** mailmap.c's read_mailmap: `.mailmap` (not in a bare repository), `mailmap.blob`, `mailmap.file` */
2476
- private async loadMailmap(config: RemoteConfigStore): Promise<Mailmap> {
2477
- return readRepositoryMailmap({
2478
- config: (key) => config.value(key),
2479
- worktree: this.worktreeAccess,
2480
- environment: hostEnvironmentOf(this._workingCopy),
2481
- readBlobNamed: async (name) => {
2482
- const id = await this.revisionResolver()
2483
- .resolve(name)
2484
- .catch(() => undefined);
2485
- return id ? this.readBlob(id) : undefined;
2486
- },
2487
- });
2488
- }
2489
-
2490
3598
  /**
2491
3599
  * The tree, parents and date of a commit (git's parse_commit_buffer), from its raw bytes
2492
3600
  * when the store gives them (kept in `raw` to be decoded whole if the commit is shown),
@@ -2537,11 +3645,66 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
2537
3645
  * element's path components when all are plain paths (no wildcard, no magic, no trailing
2538
3646
  * slash): those are compared by looking their entries up, without a tree diff.
2539
3647
  */
2540
- private pathspec(): TreePathspec & { literal: Uint8Array[][] | undefined } {
3648
+ /** The walk's pathspec elements: the paths, the excluded ones, `.` when every one excludes */
3649
+ private pathspecItems(): PathspecItem[] {
2541
3650
  const parse = (p: string) => parsePathspecItem(p, { attr: true });
2542
3651
  const items: PathspecItem[] = this.paths.map(parse);
2543
3652
  for (const p of this.excludePaths) items.push({ ...parse(p), exclude: true });
2544
3653
  if (items.every((i) => i.exclude)) items.push(parse("."));
3654
+ return items;
3655
+ }
3656
+
3657
+ /**
3658
+ * revision.c's cherry_pick_list over the limited list: the patch-ids of the side with fewer
3659
+ * commits are added (header ids only, see {@link PatchIds}), each commit of the other side
3660
+ * looked up, and every match on either side marked PATCHSAME (`--cherry-mark`) or SHOWN
3661
+ * (`--cherry-pick`, hidden). The diffs are limited to the walk's paths, and compare a
3662
+ * commit with its parent as the walk has it (simplified), as git's do.
3663
+ */
3664
+ private async cherryPickList(
3665
+ list: number[],
3666
+ t: RevTable,
3667
+ parse: (n: number) => Promise<boolean>,
3668
+ items: PathspecItem[] | undefined,
3669
+ ): Promise<void> {
3670
+ let leftCount = 0;
3671
+ let rightCount = 0;
3672
+ for (const n of list) {
3673
+ if (t.flag(n) & SYMMETRIC_LEFT) leftCount++;
3674
+ else rightCount++;
3675
+ }
3676
+ if (!leftCount || !rightCount) return;
3677
+ const leftFirst = leftCount < rightCount;
3678
+ const ids = new PatchIds<number>({
3679
+ trees: this.trees,
3680
+ blobs: this.blobs,
3681
+ objectFormat: this.objectFormat,
3682
+ change: async (n) => {
3683
+ const count = t.parentCount(n);
3684
+ if (count > 1) return undefined;
3685
+ if (count === 0) return { tree: t.treeOf(n) };
3686
+ const p = t.parent(n, 0);
3687
+ if (!(await parse(p))) return undefined;
3688
+ return { parentTree: t.treeOf(p), tree: t.treeOf(n) };
3689
+ },
3690
+ ...(items ? { paths: (path: string) => matchPathspec(items, path, 0) > 0 } : {}),
3691
+ });
3692
+ for (const n of list) {
3693
+ if (leftFirst !== !!(t.flag(n) & SYMMETRIC_LEFT)) continue;
3694
+ await ids.add(n);
3695
+ }
3696
+ const flag = this.cherryMark ? PATCHSAME : SHOWN;
3697
+ for (const n of list) {
3698
+ if (leftFirst === !!(t.flag(n) & SYMMETRIC_LEFT)) continue;
3699
+ const found = await ids.matches(n);
3700
+ if (found.length === 0) continue;
3701
+ t.mark(n, flag);
3702
+ for (const m of found) t.mark(m, flag);
3703
+ }
3704
+ }
3705
+
3706
+ private pathspec(): TreePathspec & { literal: Uint8Array[][] | undefined } {
3707
+ const items = this.pathspecItems();
2545
3708
  const plain = items.every(
2546
3709
  (i) =>
2547
3710
  !i.exclude &&
@@ -2935,6 +4098,16 @@ const BOTTOM = 1 << 2;
2935
4098
  const SEEN = 1 << 3;
2936
4099
  const ADDED = 1 << 4;
2937
4100
  const TREESAME = 1 << 5;
4101
+ /** The left side of `a...b` (passed from child to parent) */
4102
+ const SYMMETRIC_LEFT = 1 << 8;
4103
+ /** `--cherry-mark`: a commit whose change the other side has as well */
4104
+ const PATCHSAME = 1 << 9;
4105
+ /** Shown already, or hidden by `--cherry-pick`/`--left-only`/`--right-only` (git's SHOWN) */
4106
+ const SHOWN = 1 << 10;
4107
+ /** `--ancestry-path=<commit>`: an ancestor of a commit named (passed from child to parent) */
4108
+ const ANCESTRY_PATH = 1 << 11;
4109
+ /** `--show-pulls`: a merge that differs from its first parent at the paths */
4110
+ const PULL_MERGE = 1 << 12;
2938
4111
 
2939
4112
  /** How many extra uninteresting commits limit_list looks at (git's SLOP). */
2940
4113
  const SLOP = 5;
@@ -2950,7 +4123,7 @@ class RevTable {
2950
4123
  /** commits held */
2951
4124
  size = 0;
2952
4125
  /** revision.c flags (UNINTERESTING, SEEN, ...) */
2953
- flags = new Uint8Array(INITIAL_REVS);
4126
+ flags = new Uint16Array(INITIAL_REVS);
2954
4127
  /** committer dates (seconds) */
2955
4128
  private dates = new Float64Array(INITIAL_REVS);
2956
4129
  /** position in the commit-graph, -1 for a commit it does not have */
@@ -3084,6 +4257,21 @@ class RevTable {
3084
4257
  return this.pool[(this.parentAt[n] as number) + k] as number;
3085
4258
  }
3086
4259
 
4260
+ /** The parents of a parsed commit, as numbers. */
4261
+ parentList(n: number): number[] {
4262
+ const out: number[] = [];
4263
+ for (let k = 0, c = this.parentCount(n); k < c; k++) out.push(this.parent(n, k));
4264
+ return out;
4265
+ }
4266
+
4267
+ /** Replaces the parents of a parsed commit by `list`, no longer than they were. */
4268
+ setParentList(n: number, list: readonly number[]): void {
4269
+ if (list.length > this.parentCount(n)) throw new Error("parents cannot grow");
4270
+ const at = this.parentAt[n] as number;
4271
+ for (let k = 0; k < list.length; k++) this.pool[at + k] = list[k] as number;
4272
+ this.parents[n] = list.length;
4273
+ }
4274
+
3087
4275
  /** Simplification keeps only parent `p` (git rewrites `commit->parents`). */
3088
4276
  keepOnlyParent(n: number, p: number): void {
3089
4277
  this.pool[this.parentAt[n] as number] = p;
@@ -3100,7 +4288,7 @@ class RevTable {
3100
4288
 
3101
4289
  private grow(): void {
3102
4290
  const size = this.flags.length * 2;
3103
- const flags = new Uint8Array(size);
4291
+ const flags = new Uint16Array(size);
3104
4292
  flags.set(this.flags);
3105
4293
  this.flags = flags;
3106
4294
  const dates = new Float64Array(size);
@@ -3123,6 +4311,55 @@ const INITIAL_REVS = 1024;
3123
4311
  /** `RevTable` flag: parsed from the commit-graph (its tree and Bloom filter are there). */
3124
4312
  const GRAPH_PARSED = 1 << 6;
3125
4313
 
4314
+ /** revision.c's one_relevant_parent: the one parent a TREESAME commit simplifies to */
4315
+ function oneRelevantParent(
4316
+ t: RevTable,
4317
+ n: number,
4318
+ firstParentOnly: boolean,
4319
+ relevant: (n: number) => boolean,
4320
+ ): number | undefined {
4321
+ const c = t.parentCount(n);
4322
+ if (c === 0) return undefined;
4323
+ if (firstParentOnly || c === 1) return t.parent(n, 0);
4324
+ let found: number | undefined;
4325
+ for (let k = 0; k < c; k++) {
4326
+ const p = t.parent(n, k);
4327
+ if (!relevant(p)) continue;
4328
+ if (found !== undefined) return undefined;
4329
+ found = p;
4330
+ }
4331
+ return found;
4332
+ }
4333
+
4334
+ /**
4335
+ * revision.c's rewrite_parents: n's parents, each replaced by the first commit shown on its
4336
+ * way down (rewrite_one), roots TREESAME dropped, duplicates removed.
4337
+ */
4338
+ function rewriteParents(
4339
+ t: RevTable,
4340
+ n: number,
4341
+ firstParentOnly: boolean,
4342
+ relevant: (n: number) => boolean,
4343
+ ): number[] {
4344
+ const out: number[] = [];
4345
+ for (let k = 0, c = t.parentCount(n); k < c; k++) {
4346
+ let p: number | undefined = t.parent(n, k);
4347
+ for (;;) {
4348
+ if (t.flag(p) & UNINTERESTING) break;
4349
+ if (!(t.flag(p) & TREESAME)) break;
4350
+ if (t.parentCount(p) === 0) {
4351
+ p = undefined;
4352
+ break;
4353
+ }
4354
+ const next = oneRelevantParent(t, p, firstParentOnly, relevant);
4355
+ if (next === undefined) break;
4356
+ p = next;
4357
+ }
4358
+ if (p !== undefined && !out.includes(p)) out.push(p);
4359
+ }
4360
+ return out;
4361
+ }
4362
+
3126
4363
  /** A commit read whole, as the commit store decodes it; undefined if it does not parse. */
3127
4364
  function decodeCommit(bytes: Uint8Array): Commit | undefined {
3128
4365
  try {