@statewalker/vcs-commands 0.14.0 → 0.15.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 (265) hide show
  1. package/dist/commands/add-command.d.ts.map +1 -1
  2. package/dist/commands/add-patch/patch-backend.d.ts +1 -1
  3. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  4. package/dist/commands/archive/remote-archive-command.d.ts +4 -1
  5. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -1
  6. package/dist/commands/branch-command.d.ts +14 -2
  7. package/dist/commands/branch-command.d.ts.map +1 -1
  8. package/dist/commands/cat-file/batch-format.d.ts +8 -12
  9. package/dist/commands/cat-file/batch-format.d.ts.map +1 -1
  10. package/dist/commands/cat-file/cat-file-command.d.ts +39 -5
  11. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
  12. package/dist/commands/check-ignore-command.d.ts.map +1 -1
  13. package/dist/commands/checkout-command.d.ts +4 -0
  14. package/dist/commands/checkout-command.d.ts.map +1 -1
  15. package/dist/commands/checkout-paths.d.ts +9 -0
  16. package/dist/commands/checkout-paths.d.ts.map +1 -1
  17. package/dist/commands/cherry-pick-command.d.ts +3 -0
  18. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  19. package/dist/commands/clean-interactive.d.ts +0 -9
  20. package/dist/commands/clean-interactive.d.ts.map +1 -1
  21. package/dist/commands/clone-command.d.ts +2 -0
  22. package/dist/commands/clone-command.d.ts.map +1 -1
  23. package/dist/commands/column/column-config.d.ts +23 -0
  24. package/dist/commands/column/column-config.d.ts.map +1 -0
  25. package/dist/commands/column/column-layout.d.ts +129 -0
  26. package/dist/commands/column/column-layout.d.ts.map +1 -0
  27. package/dist/commands/column/index.d.ts +3 -0
  28. package/dist/commands/column/index.d.ts.map +1 -0
  29. package/dist/commands/column-command.d.ts +59 -0
  30. package/dist/commands/column-command.d.ts.map +1 -0
  31. package/dist/commands/comment-char-config.d.ts +15 -0
  32. package/dist/commands/comment-char-config.d.ts.map +1 -1
  33. package/dist/commands/commit-command.d.ts +21 -2
  34. package/dist/commands/commit-command.d.ts.map +1 -1
  35. package/dist/commands/config-command.d.ts +12 -0
  36. package/dist/commands/config-command.d.ts.map +1 -1
  37. package/dist/commands/credential-helper.d.ts +214 -0
  38. package/dist/commands/credential-helper.d.ts.map +1 -0
  39. package/dist/commands/default-branch.d.ts +17 -1
  40. package/dist/commands/default-branch.d.ts.map +1 -1
  41. package/dist/commands/diff-color-config.d.ts +4 -0
  42. package/dist/commands/diff-color-config.d.ts.map +1 -1
  43. package/dist/commands/diff-command.d.ts +12 -0
  44. package/dist/commands/diff-command.d.ts.map +1 -1
  45. package/dist/commands/fast-export/fast-export-command.d.ts +89 -2
  46. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -1
  47. package/dist/commands/fast-export/fast-import-command.d.ts +113 -8
  48. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -1
  49. package/dist/commands/fast-export/fast-stream-support.d.ts +0 -9
  50. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -1
  51. package/dist/commands/fetch-command.d.ts +21 -0
  52. package/dist/commands/fetch-command.d.ts.map +1 -1
  53. package/dist/commands/git-hooks.d.ts +28 -0
  54. package/dist/commands/git-hooks.d.ts.map +1 -1
  55. package/dist/commands/history-command.d.ts +173 -7
  56. package/dist/commands/history-command.d.ts.map +1 -1
  57. package/dist/commands/index-host.d.ts +19 -0
  58. package/dist/commands/index-host.d.ts.map +1 -1
  59. package/dist/commands/index-refresh.d.ts +36 -0
  60. package/dist/commands/index-refresh.d.ts.map +1 -0
  61. package/dist/commands/index.d.ts +9 -0
  62. package/dist/commands/index.d.ts.map +1 -1
  63. package/dist/commands/index.js +7 -6
  64. package/dist/commands/init-command.d.ts +20 -0
  65. package/dist/commands/init-command.d.ts.map +1 -1
  66. package/dist/commands/local-transport.d.ts +29 -1
  67. package/dist/commands/local-transport.d.ts.map +1 -1
  68. package/dist/commands/log-command.d.ts +7 -0
  69. package/dist/commands/log-command.d.ts.map +1 -1
  70. package/dist/commands/log-output.d.ts +11 -0
  71. package/dist/commands/log-output.d.ts.map +1 -1
  72. package/dist/commands/maintenance-schedule-command.d.ts +122 -0
  73. package/dist/commands/maintenance-schedule-command.d.ts.map +1 -0
  74. package/dist/commands/merge-command.d.ts +2 -0
  75. package/dist/commands/merge-command.d.ts.map +1 -1
  76. package/dist/commands/merge-index-command.d.ts +42 -0
  77. package/dist/commands/merge-index-command.d.ts.map +1 -0
  78. package/dist/commands/merge-one-file.d.ts +129 -0
  79. package/dist/commands/merge-one-file.d.ts.map +1 -0
  80. package/dist/commands/merge-support.d.ts +21 -2
  81. package/dist/commands/merge-support.d.ts.map +1 -1
  82. package/dist/commands/object-disk-info.d.ts +35 -0
  83. package/dist/commands/object-disk-info.d.ts.map +1 -0
  84. package/dist/commands/octopus-merge.d.ts +3 -3
  85. package/dist/commands/octopus-merge.d.ts.map +1 -1
  86. package/dist/commands/promisor-remote.d.ts.map +1 -1
  87. package/dist/commands/pull-command.d.ts +55 -7
  88. package/dist/commands/pull-command.d.ts.map +1 -1
  89. package/dist/commands/push-command.d.ts +18 -1
  90. package/dist/commands/push-command.d.ts.map +1 -1
  91. package/dist/commands/range-diff/range-diff-command.d.ts +37 -1
  92. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -1
  93. package/dist/commands/rebase-command.d.ts +13 -1
  94. package/dist/commands/rebase-command.d.ts.map +1 -1
  95. package/dist/commands/ref-filter/for-each-ref-command.d.ts +3 -2
  96. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -1
  97. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -1
  98. package/dist/commands/ref-filter/ref-format.d.ts +26 -1
  99. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -1
  100. package/dist/commands/ref-filter/ref-listing-command.d.ts +9 -0
  101. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -1
  102. package/dist/commands/remote-transport.d.ts +27 -0
  103. package/dist/commands/remote-transport.d.ts.map +1 -1
  104. package/dist/commands/repack-command.d.ts +18 -2
  105. package/dist/commands/repack-command.d.ts.map +1 -1
  106. package/dist/commands/repo-command.d.ts +2 -7
  107. package/dist/commands/repo-command.d.ts.map +1 -1
  108. package/dist/commands/reset-command.d.ts +4 -1
  109. package/dist/commands/reset-command.d.ts.map +1 -1
  110. package/dist/commands/restore-command.d.ts.map +1 -1
  111. package/dist/commands/rev-list-command.d.ts +65 -0
  112. package/dist/commands/rev-list-command.d.ts.map +1 -1
  113. package/dist/commands/revert-command.d.ts +3 -0
  114. package/dist/commands/revert-command.d.ts.map +1 -1
  115. package/dist/commands/revision-filenames.d.ts.map +1 -1
  116. package/dist/commands/revision-range.d.ts +17 -0
  117. package/dist/commands/revision-range.d.ts.map +1 -1
  118. package/dist/commands/revision-resolver.d.ts +12 -0
  119. package/dist/commands/revision-resolver.d.ts.map +1 -1
  120. package/dist/commands/serve-repository.d.ts +17 -1
  121. package/dist/commands/serve-repository.d.ts.map +1 -1
  122. package/dist/commands/served-lazy-fetch.d.ts +61 -0
  123. package/dist/commands/served-lazy-fetch.d.ts.map +1 -0
  124. package/dist/commands/signing.d.ts +10 -4
  125. package/dist/commands/signing.d.ts.map +1 -1
  126. package/dist/commands/status-color-config.d.ts +33 -0
  127. package/dist/commands/status-color-config.d.ts.map +1 -0
  128. package/dist/commands/status-command.d.ts +15 -0
  129. package/dist/commands/status-command.d.ts.map +1 -1
  130. package/dist/commands/status-format.d.ts +46 -4
  131. package/dist/commands/status-format.d.ts.map +1 -1
  132. package/dist/commands/tag-command.d.ts +15 -1
  133. package/dist/commands/tag-command.d.ts.map +1 -1
  134. package/dist/commands/tree-restore.d.ts +14 -0
  135. package/dist/commands/tree-restore.d.ts.map +1 -1
  136. package/dist/commands/verify-command.d.ts +22 -2
  137. package/dist/commands/verify-command.d.ts.map +1 -1
  138. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  139. package/dist/commands/worktree-overwrite-checks.d.ts +31 -6
  140. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  141. package/dist/{commands-C9M78Chn.js → commands-DT3VEv50.js} +14879 -16703
  142. package/dist/errors/commit-errors.d.ts +23 -3
  143. package/dist/errors/commit-errors.d.ts.map +1 -1
  144. package/dist/errors/git-api-error.d.ts +6 -0
  145. package/dist/errors/git-api-error.d.ts.map +1 -1
  146. package/dist/errors/index.js +30 -4
  147. package/dist/{fsck-C4US3l0B.js → fsck-BZ508Elg.js} +1 -1
  148. package/dist/git-command.d.ts +33 -1
  149. package/dist/git-command.d.ts.map +1 -1
  150. package/dist/git.d.ts +104 -1
  151. package/dist/git.d.ts.map +1 -1
  152. package/dist/index.js +8 -7
  153. package/dist/{remote-transport-C43eykfK.js → local-transport-D98U6p4d.js} +184 -683
  154. package/dist/{maintenance-run-command-CoJFKr2p.js → maintenance-run-command-DZFnbnbo.js} +2285 -79
  155. package/dist/remote-config/remote-config-store.d.ts +6 -0
  156. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  157. package/dist/remote-transport-zvSqwpOB.js +4865 -0
  158. package/dist/results/cherry-pick-result.d.ts +4 -3
  159. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  160. package/dist/results/diff-output.d.ts +7 -0
  161. package/dist/results/diff-output.d.ts.map +1 -1
  162. package/dist/results/diff-words.d.ts +14 -3
  163. package/dist/results/diff-words.d.ts.map +1 -1
  164. package/dist/results/index.js +1 -1
  165. package/dist/results/line-prefix-sink.d.ts +50 -0
  166. package/dist/results/line-prefix-sink.d.ts.map +1 -0
  167. package/dist/results/merge-result.d.ts +4 -3
  168. package/dist/results/merge-result.d.ts.map +1 -1
  169. package/dist/results/rebase-result.d.ts +5 -0
  170. package/dist/results/rebase-result.d.ts.map +1 -1
  171. package/dist/results/revert-result.d.ts +4 -3
  172. package/dist/results/revert-result.d.ts.map +1 -1
  173. package/dist/{results-B0CWLCAp.js → results-rF81cQse.js} +1425 -202
  174. package/dist/transport-command.d.ts +10 -0
  175. package/dist/transport-command.d.ts.map +1 -1
  176. package/package.json +12 -12
  177. package/src/commands/add-command.ts +15 -2
  178. package/src/commands/add-patch/patch-backend.ts +6 -44
  179. package/src/commands/archive/remote-archive-command.ts +10 -3
  180. package/src/commands/branch-command.ts +57 -4
  181. package/src/commands/cat-file/batch-format.ts +17 -18
  182. package/src/commands/cat-file/cat-file-command.ts +181 -15
  183. package/src/commands/check-ignore-command.ts +61 -17
  184. package/src/commands/checkout-command.ts +149 -21
  185. package/src/commands/checkout-index-command.ts +2 -1
  186. package/src/commands/checkout-paths.ts +13 -0
  187. package/src/commands/cherry-pick-command.ts +9 -0
  188. package/src/commands/clean-interactive.ts +20 -74
  189. package/src/commands/clone-command.ts +13 -0
  190. package/src/commands/column/column-config.ts +63 -0
  191. package/src/commands/column/column-layout.ts +396 -0
  192. package/src/commands/column/index.ts +2 -0
  193. package/src/commands/column-command.ts +171 -0
  194. package/src/commands/comment-char-config.ts +42 -0
  195. package/src/commands/commit-command.ts +61 -21
  196. package/src/commands/config-command.ts +28 -0
  197. package/src/commands/credential-helper.ts +807 -0
  198. package/src/commands/default-branch.ts +38 -0
  199. package/src/commands/diff-color-config.ts +23 -10
  200. package/src/commands/diff-command.ts +25 -2
  201. package/src/commands/fast-export/fast-export-command.ts +661 -35
  202. package/src/commands/fast-export/fast-import-command.ts +694 -94
  203. package/src/commands/fast-export/fast-stream-support.ts +18 -1
  204. package/src/commands/fetch-command.ts +103 -14
  205. package/src/commands/git-hooks.ts +85 -0
  206. package/src/commands/history-command.ts +952 -20
  207. package/src/commands/index-host.ts +51 -0
  208. package/src/commands/index-refresh.ts +121 -0
  209. package/src/commands/index.ts +9 -0
  210. package/src/commands/init-command.ts +34 -1
  211. package/src/commands/legacy-remotes.ts +4 -20
  212. package/src/commands/local-transport.ts +130 -9
  213. package/src/commands/log-command.ts +39 -1
  214. package/src/commands/log-output.ts +31 -4
  215. package/src/commands/maintenance-schedule-command.ts +418 -0
  216. package/src/commands/merge-command.ts +10 -0
  217. package/src/commands/merge-index-command.ts +202 -0
  218. package/src/commands/merge-one-file.ts +451 -0
  219. package/src/commands/merge-support.ts +127 -11
  220. package/src/commands/object-disk-info.ts +169 -0
  221. package/src/commands/octopus-merge.ts +37 -128
  222. package/src/commands/promisor-remote.ts +14 -3
  223. package/src/commands/pull-command.ts +173 -27
  224. package/src/commands/push-command.ts +50 -5
  225. package/src/commands/range-diff/range-diff-command.ts +86 -3
  226. package/src/commands/rebase-command.ts +46 -1
  227. package/src/commands/ref-filter/for-each-ref-command.ts +4 -3
  228. package/src/commands/ref-filter/ref-filter.ts +59 -4
  229. package/src/commands/ref-filter/ref-format.ts +83 -10
  230. package/src/commands/ref-filter/ref-listing-command.ts +30 -0
  231. package/src/commands/remote-command.ts +2 -2
  232. package/src/commands/remote-transport.ts +66 -3
  233. package/src/commands/repack-command.ts +75 -9
  234. package/src/commands/repo-command.ts +6 -70
  235. package/src/commands/reset-command.ts +11 -1
  236. package/src/commands/restore-command.ts +1 -0
  237. package/src/commands/rev-list-command.ts +205 -3
  238. package/src/commands/revert-command.ts +9 -0
  239. package/src/commands/revision-filenames.ts +32 -4
  240. package/src/commands/revision-range.ts +2 -2
  241. package/src/commands/revision-resolver.ts +21 -1
  242. package/src/commands/serve-repository.ts +34 -8
  243. package/src/commands/served-lazy-fetch.ts +164 -0
  244. package/src/commands/signing.ts +18 -10
  245. package/src/commands/status-color-config.ts +92 -0
  246. package/src/commands/status-command.ts +50 -2
  247. package/src/commands/status-format.ts +198 -50
  248. package/src/commands/tag-command.ts +57 -2
  249. package/src/commands/tree-restore.ts +17 -0
  250. package/src/commands/verify-command.ts +84 -12
  251. package/src/commands/worktree-add-command.ts +2 -0
  252. package/src/commands/worktree-overwrite-checks.ts +75 -14
  253. package/src/errors/commit-errors.ts +31 -3
  254. package/src/errors/git-api-error.ts +7 -0
  255. package/src/git-command.ts +105 -4
  256. package/src/git.ts +153 -0
  257. package/src/remote-config/remote-config-store.ts +16 -0
  258. package/src/results/cherry-pick-result.ts +4 -3
  259. package/src/results/diff-output.ts +8 -0
  260. package/src/results/diff-words.ts +160 -32
  261. package/src/results/line-prefix-sink.ts +102 -0
  262. package/src/results/merge-result.ts +4 -3
  263. package/src/results/rebase-result.ts +5 -0
  264. package/src/results/revert-result.ts +4 -3
  265. package/src/transport-command.ts +48 -2
@@ -1,11 +1,12 @@
1
1
  import type { FilesApi, History } from "@statewalker/vcs-core";
2
2
  import {
3
3
  FileRawStorage,
4
+ IncrementalMidxError,
4
5
  parseExpiryDate,
5
6
  type RepackResult,
6
7
  repack as storeRepack,
7
8
  } from "@statewalker/vcs-store-files";
8
- import { parseGitBool } from "@statewalker/vcs-utils/encoding";
9
+ import { parseGitBool, parseGitInt } from "@statewalker/vcs-utils/encoding";
9
10
  import { AttributesMemo, attributesSourceSetting } from "@statewalker/vcs-working-tree";
10
11
  import { GitApiError } from "../errors/index.js";
11
12
  import { GitCommand } from "../git-command.js";
@@ -57,7 +58,8 @@ export class RepackCommand extends GitCommand<RepackCommandResult> {
57
58
  private _reuseDeltas = true;
58
59
  private _reuseObjects = true;
59
60
  private _writeBitmaps?: boolean;
60
- private _writeMidx = false;
61
+ private _writeMidx: boolean | string = false;
62
+ private _compatibility?: "2.43" | "2.56" | "2.57";
61
63
  private _geometric?: number;
62
64
  private _filter?: string;
63
65
  private _keepPacks: string[] = [];
@@ -158,13 +160,43 @@ export class RepackCommand extends GitCommand<RepackCommandResult> {
158
160
  return this;
159
161
  }
160
162
 
161
- /** `-m` (`--write-midx`): a multi-pack-index over the packs that stay. */
162
- setWriteMidx(write: boolean): this {
163
+ /**
164
+ * `-m` (`--write-midx[=<mode>]`): a multi-pack-index over the packs that stay (`true` or
165
+ * `""`), or (`"incremental"`, git 2.55+) the incremental chain rebuilt with a new layer on top,
166
+ * its layers compacted by `repack.midxSplitFactor` under `--geometric`. Any other value is
167
+ * git's `error: unknown value for write-midx` (exit 129); under 2.43 compatibility every value
168
+ * is (`option `write-midx' takes no value`).
169
+ */
170
+ setWriteMidx(mode: boolean | string): this {
163
171
  this.checkCallable();
164
- this._writeMidx = write;
172
+ this._writeMidx = mode;
165
173
  return this;
166
174
  }
167
175
 
176
+ /**
177
+ * The git version followed where versions differ: "2.43", "2.56" (2.55 and 2.56 alike), or
178
+ * "2.57" (git master after 2.56, whose incremental midx layer also takes the packs its bitmap
179
+ * needs: kept packs, packs that stay, cruft packs). Default: the hooks' compatibility (2.43 or
180
+ * 2.56).
181
+ */
182
+ setCompatibility(compatibility: "2.43" | "2.56" | "2.57"): this {
183
+ this.checkCallable();
184
+ this._compatibility = compatibility;
185
+ return this;
186
+ }
187
+
188
+ /** git_config_int of the configuration: `fallback` when unset, git's death on a bad unit. */
189
+ private configInt(key: string, fallback: number): number {
190
+ const value = RemoteConfigStore.from(this.workingCopy).value(key);
191
+ if (value === undefined) return fallback;
192
+ const n = parseGitInt(value);
193
+ if (n === undefined)
194
+ throw new GitApiError(
195
+ `fatal: bad numeric config value '${value}' for '${key.toLowerCase()}': invalid unit`,
196
+ );
197
+ return n;
198
+ }
199
+
168
200
  /** `--geometric=<factor>` (`-g`): roll small packs up into a geometric progression. */
169
201
  setGeometric(factor: number): this {
170
202
  this.checkCallable();
@@ -301,6 +333,21 @@ export class RepackCommand extends GitCommand<RepackCommandResult> {
301
333
  async call(): Promise<RepackCommandResult> {
302
334
  this.checkCallable();
303
335
  this.setCallable(false);
336
+ const compatibility = this._compatibility ?? this.hooks.compatibility;
337
+ const legacy = compatibility === "2.43";
338
+ // repack_config (before the options): git_config_int dies on a value that is no number
339
+ const midxSplitFactor = legacy ? 2 : this.configInt("repack.midxSplitFactor", 2);
340
+ const midxNewLayerThreshold = legacy ? 8 : this.configInt("repack.midxNewLayerThreshold", 8);
341
+ // option_parse_write_midx (2.43: a boolean option, which takes no value)
342
+ let writeMidx: boolean | "incremental" = false;
343
+ if (typeof this._writeMidx === "string" && legacy)
344
+ throw new GitApiError("error: option `write-midx' takes no value", { exitCode: 129 });
345
+ if (this._writeMidx === true || this._writeMidx === "") writeMidx = true;
346
+ else if (this._writeMidx === "incremental") writeMidx = "incremental";
347
+ else if (typeof this._writeMidx === "string")
348
+ throw new GitApiError(`error: unknown value for write-midx: ${this._writeMidx}`, {
349
+ exitCode: 129,
350
+ });
304
351
  // die_for_incompatible_opt3: --unpack-unreachable counts as -A there
305
352
  const loosenAsked = this._loosen || this._unpackUnreachable !== undefined;
306
353
  const incompatible = [
@@ -309,7 +356,7 @@ export class RepackCommand extends GitCommand<RepackCommandResult> {
309
356
  ...(this._cruft ? ["--cruft"] : []),
310
357
  ];
311
358
  // 2.43 checks the pairs one by one, in its own words
312
- if (this.hooks.compatibility === "2.43") {
359
+ if (legacy) {
313
360
  const pair = (x: string, y: string) =>
314
361
  new GitApiError(`fatal: options '${x}' and '${y}' cannot be used together`);
315
362
  if (this._keepUnreachable && loosenAsked) throw pair("--keep-unreachable", "-A");
@@ -325,6 +372,13 @@ export class RepackCommand extends GitCommand<RepackCommandResult> {
325
372
  `fatal: options '${incompatible[0]}' and '${incompatible[1]}' cannot be used together`,
326
373
  );
327
374
  const all = this._all || this._loosen || this._cruft;
375
+ // whatever the mode, git (2.55+) dies on a split factor below 2 or a threshold below 1
376
+ if (midxSplitFactor < 2)
377
+ throw new GitApiError(`fatal: invalid value for --midx-split-factor: ${midxSplitFactor}`);
378
+ if (midxNewLayerThreshold < 1)
379
+ throw new GitApiError(
380
+ `fatal: invalid value for --midx-new-layer-threshold: ${midxNewLayerThreshold}`,
381
+ );
328
382
  // git's split_factor 0 is no geometric repack
329
383
  const geometric = this._geometric ? this._geometric : undefined;
330
384
  if (geometric !== undefined && all)
@@ -366,7 +420,8 @@ export class RepackCommand extends GitCommand<RepackCommandResult> {
366
420
  files,
367
421
  gitDir,
368
422
  ...(environment ? { environment } : {}),
369
- compatibility: this.hooks.compatibility,
423
+ compatibility: legacy ? "2.43" : "2.56",
424
+ ...(compatibility === "2.57" ? { incrementalMidxClosure: true } : {}),
370
425
  // -q: no progress (git's show_progress = !quiet && isatty(2))
371
426
  ...(this.progress && !this._quiet ? { progress: this.progress } : {}),
372
427
  all,
@@ -388,7 +443,7 @@ export class RepackCommand extends GitCommand<RepackCommandResult> {
388
443
  }
389
444
  : {}),
390
445
  ...(this._writeBitmaps !== undefined ? { writeBitmaps: this._writeBitmaps } : {}),
391
- ...(this._writeMidx ? { writeMidx: true } : {}),
446
+ ...(writeMidx ? { writeMidx, midxSplitFactor, midxNewLayerThreshold } : {}),
392
447
  ...(geometric !== undefined ? { geometric } : {}),
393
448
  ...(this._filter !== undefined ? { filter: this._filter } : {}),
394
449
  ...(this._keepPacks.length ? { keepPacks: this._keepPacks } : {}),
@@ -399,7 +454,18 @@ export class RepackCommand extends GitCommand<RepackCommandResult> {
399
454
  ...(noDelta ? { noDelta } : {}),
400
455
  onWarning: (line) => geometricWarnings.push(line),
401
456
  });
402
- const result = noDelta && worktree?.batch ? await worktree.batch(run) : await run();
457
+ let result: RepackResult | null;
458
+ try {
459
+ result = noDelta && worktree?.batch ? await worktree.batch(run) : await run();
460
+ } catch (e) {
461
+ // write_midx_incremental's failures: git's error lines, repack returning -1 (exit 255);
462
+ // its lock taken by another process is a death (128)
463
+ if (e instanceof IncrementalMidxError)
464
+ throw new GitApiError(e.lines.join("\n"), {
465
+ exitCode: e.lines[0]?.startsWith("fatal:") ? 128 : 255,
466
+ });
467
+ throw e;
468
+ }
403
469
  const output: string[] = [];
404
470
  if ((!result || result.nothingNew) && !this._quiet) output.push("Nothing new to pack.");
405
471
  return {
@@ -14,11 +14,8 @@
14
14
  import {
15
15
  decodeTreeBytes,
16
16
  type FilesApi,
17
- joinPath,
18
17
  type ObjectId,
19
18
  type ObjectTypeString,
20
- type Pack,
21
- packNameOf,
22
19
  } from "@statewalker/vcs-core";
23
20
  import { readRepositoryFormat, setupGitDirectory } from "@statewalker/vcs-store-files";
24
21
  import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
@@ -27,6 +24,7 @@ import { type GitHostEnvironment, readIndexFileEntries } from "@statewalker/vcs-
27
24
  import { quotePath } from "../results/quote-path.js";
28
25
  import { hookHostOf } from "./git-hooks.js";
29
26
  import { hostEnvironmentOf } from "./git-ident.js";
27
+ import { objectDiskInfoOf } from "./object-disk-info.js";
30
28
  import { PlumbingCommand, PlumbingError } from "./plumbing-command.js";
31
29
  import { RevListCommand } from "./rev-list-command.js";
32
30
 
@@ -597,19 +595,12 @@ async function readWhole(
597
595
  return { type: object.type, bytes };
598
596
  }
599
597
 
600
- /** The pack-relevant part of a `PackFile`. */
601
- interface OffsetPack extends Pack {
602
- indexOf?(id: ObjectId): number;
603
- offsetAt?(i: number): number;
604
- packOrder?(): Uint32Array;
605
- }
606
-
607
598
  /**
608
599
  * `git repo structure [--format=(table|lines|nul) | -z] [--[no-]progress]`: the references
609
600
  * by kind and the objects reachable from them (path-walk.c's walk over every ref, as git
610
601
  * walks it, so ties of the largest objects go to the object git meets first), with their
611
- * inflated and on-disk sizes (a packed object's entry, a loose object's file; an object only
612
- * an alternate holds counts 0 bytes on disk).
602
+ * inflated and on-disk sizes (a packed object's entry, a loose object's file, in the
603
+ * repository or its alternates: `objectDiskInfoOf`).
613
604
  */
614
605
  export class RepoStructureCommand extends PlumbingCommand {
615
606
  private format = "table";
@@ -790,7 +781,9 @@ export class RepoStructureCommand extends PlumbingCommand {
790
781
  }
791
782
  }
792
783
 
793
- const disk = await this.diskSizer();
784
+ const info = await objectDiskInfoOf(this.workingCopy);
785
+ // an object no pack or loose file holds counts 0 bytes on disk
786
+ const disk = async (id: ObjectId) => (await info.diskSize(id)) ?? 0;
794
787
  const check = (largest: Largest, id: ObjectId, value: number) => {
795
788
  if (value > largest.value || largest.id === undefined) {
796
789
  largest.id = id;
@@ -872,63 +865,6 @@ export class RepoStructureCommand extends PlumbingCommand {
872
865
  }
873
866
  }
874
867
 
875
- /**
876
- * The bytes an object takes on disk, as odb_read_object_info_extended's `disk_sizep`: its
877
- * pack entry (to the next entry by offset, or the trailer), else its loose file.
878
- */
879
- private async diskSizer(): Promise<(id: ObjectId) => Promise<number>> {
880
- const objectsFile = await this.hooks.commonGitFile("objects");
881
- const packSet = this.workingCopy.history.packs;
882
- const packs = ((await packSet?.packs().catch(() => [])) ?? []) as OffsetPack[];
883
- const hashLength = this.objectFormat.rawLength;
884
- const sorted = new Map<OffsetPack, Float64Array>();
885
- const packSizes = new Map<OffsetPack, number>();
886
- const offsetsOf = (pack: OffsetPack): Float64Array => {
887
- let offsets = sorted.get(pack);
888
- if (!offsets) {
889
- offsets = new Float64Array(pack.count);
890
- for (let i = 0; i < pack.count; i++) offsets[i] = pack.offsetAt?.(i) ?? 0;
891
- offsets.sort();
892
- sorted.set(pack, offsets);
893
- }
894
- return offsets;
895
- };
896
- const packSizeOf = async (pack: OffsetPack): Promise<number> => {
897
- let size = packSizes.get(pack);
898
- if (size === undefined) {
899
- size = 0;
900
- if (objectsFile) {
901
- const path = joinPath(objectsFile.path, "pack", `${packNameOf(pack)}.pack`);
902
- size = (await objectsFile.files.stats(path))?.size ?? 0;
903
- }
904
- packSizes.set(pack, size);
905
- }
906
- return size;
907
- };
908
- return async (id) => {
909
- for (const pack of packs) {
910
- if (!pack.has(id) || !pack.indexOf || !pack.offsetAt) continue;
911
- const index = pack.indexOf(id);
912
- if (index < 0) continue;
913
- const offset = pack.offsetAt(index);
914
- const offsets = offsetsOf(pack);
915
- let lo = 0;
916
- let hi = offsets.length;
917
- while (lo < hi) {
918
- const mid = (lo + hi) >> 1;
919
- if ((offsets[mid] as number) <= offset) lo = mid + 1;
920
- else hi = mid;
921
- }
922
- const next =
923
- lo < offsets.length ? (offsets[lo] as number) : (await packSizeOf(pack)) - hashLength;
924
- return next - offset;
925
- }
926
- if (!objectsFile) return 0;
927
- const path = joinPath(objectsFile.path, id.slice(0, 2), id.slice(2));
928
- return (await objectsFile.files.stats(path).catch(() => undefined))?.size ?? 0;
929
- };
930
- }
931
-
932
868
  /** stats_table_setup_structure + stats_table_print_structure. */
933
869
  private table(s: RepoStructure): string {
934
870
  type Entry = { value: string; unit?: string; index?: number };
@@ -54,7 +54,12 @@ import { reflogMessages } from "./reflog-messages.js";
54
54
  import { moveHeadAsReset, removeBranchState, resetKeep, resetMerge } from "./sequencer-support.js";
55
55
  import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
56
56
  import { recursesIntoSubmodules, SubmoduleUnpack } from "./submodule-unpack.js";
57
- import { planTreeRestore, restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
57
+ import {
58
+ type CheckoutRef,
59
+ planTreeRestore,
60
+ restoreCaseOptions,
61
+ writeTreeRestorePlan,
62
+ } from "./tree-restore.js";
58
63
  import { flaggedEntryDiffers, pruneEmptyParents } from "./worktree-overwrite-checks.js";
59
64
  import { treePathRefusal, worktreePathRules } from "./worktree-path-rules.js";
60
65
 
@@ -846,6 +851,8 @@ export class ResetCommand extends GitCommand<Ref> {
846
851
  sparse,
847
852
  submodules,
848
853
  unchanged,
854
+ // reset_index's init_checkout_metadata: a ref only when the name dwims under refs/
855
+ await this.checkoutRefOf(this.ref ?? "HEAD", targetId, { fullRefsOnly: true }),
849
856
  );
850
857
  }
851
858
 
@@ -949,6 +956,8 @@ export async function restoreWorktreeHard(
949
956
  submodules?: HardResetSubmodules,
950
957
  /** Entries oneway_merge leaves alone (fsmonitor-valid and unchanged: `fsmonitorKeptEntries`) */
951
958
  unchanged?: ReadonlySet<string>,
959
+ /** git's checkout metadata (`o->meta`), for a long-running filter process */
960
+ metadata?: CheckoutRef,
952
961
  ): Promise<Set<string>> {
953
962
  const { trees, blobs, workingCopy, worktree } = deps;
954
963
  const subs = submodules?.unpack;
@@ -1023,6 +1032,7 @@ export async function restoreWorktreeHard(
1023
1032
  replaceInTheWay: true,
1024
1033
  // git's reset --hard overwrites untracked files (UNPACK_RESET_OVERWRITE_UNTRACKED)
1025
1034
  discardUntracked: true,
1035
+ ...(metadata ? { metadata } : {}),
1026
1036
  });
1027
1037
  if (subs) {
1028
1038
  // check_updates: `.gitmodules` read again, then every submodule checked out (oneway_merge
@@ -303,6 +303,7 @@ export class RestoreCommand extends GitCommand<CheckoutResult> {
303
303
  const id = await this.resolveRevision(rev === "-" ? "@{-1}" : rev);
304
304
  return { id, tree: await this.revisionResolver().peelToType(id, "tree") };
305
305
  },
306
+ checkoutRefOf: (rev: string, id: ObjectId) => this.checkoutRefOf(rev, id),
306
307
  },
307
308
  {
308
309
  command: "restore",
@@ -16,8 +16,16 @@
16
16
  * ```
17
17
  */
18
18
 
19
- import type { ObjectId } from "@statewalker/vcs-core";
19
+ import {
20
+ listObjects,
21
+ ObjectFilterError,
22
+ type ObjectId,
23
+ parseObjectFilter,
24
+ type ResolvedObjectFilter,
25
+ resolveObjectFilter,
26
+ } from "@statewalker/vcs-core";
20
27
  import { encodeGitPath } from "@statewalker/vcs-utils/encoding";
28
+ import { sparseFilterMatcher } from "@statewalker/vcs-working-tree";
21
29
 
22
30
  import { GitApiError } from "../errors/index.js";
23
31
  import { GitCommand } from "../git-command.js";
@@ -31,6 +39,8 @@ import {
31
39
  import type { DiffTextOptions } from "./diff-command.js";
32
40
  import { LogCommand, type LogOrder, type LogResult, RevFilter } from "./log-command.js";
33
41
  import type { LogOutputOptions } from "./log-output.js";
42
+ import { objectDiskInfoOf } from "./object-disk-info.js";
43
+ import { humaniseBytes } from "./range-diff/index.js";
34
44
  import type { CommitFilter, GrepPatternType } from "./rev-filter/index.js";
35
45
  import { revisionMergeBases } from "./rev-parse-command.js";
36
46
  import { parseRevisionAndPathArgs, type RevisionAndPathArgs } from "./revision-filenames.js";
@@ -84,6 +94,16 @@ export class RevListCommand extends GitCommand<AsyncIterable<LogResult>> {
84
94
  private printParents = false;
85
95
  /** `--ancestry-path=<commit>` revisions, resolved when called */
86
96
  private readonly ancestryPaths: string[] = [];
97
+ /** `--objects` */
98
+ private objects = false;
99
+ /** `--disk-usage` (true) or `--disk-usage=<format>` (its format, checked when called) */
100
+ private diskUsage: boolean | string = false;
101
+ /** `--filter=<spec>` */
102
+ private filterSpec?: string;
103
+ /** `--use-bitmap-index` */
104
+ private useBitmapIndex = false;
105
+ /** Whether an option changing which commits the walk shows was given */
106
+ private walkLimited = false;
87
107
 
88
108
  /** What git prints while reading replace refs and grafts (see GitCommand). */
89
109
  override async replacementMessages(): Promise<string[]> {
@@ -132,7 +152,9 @@ export class RevListCommand extends GitCommand<AsyncIterable<LogResult>> {
132
152
 
133
153
  /** The git version to follow where versions differ (see `LogCommand.setCompatibility`). */
134
154
  setCompatibility(version: "2.43" | "2.56"): this {
135
- return this.configured((log) => log.setCompatibility(version));
155
+ this.checkCallable();
156
+ this.configure.push((log) => log.setCompatibility(version));
157
+ return this;
136
158
  }
137
159
 
138
160
  /** `--grep-reflog=<pattern>` (see `LogCommand.addGrepReflog`). */
@@ -280,6 +302,58 @@ export class RevListCommand extends GitCommand<AsyncIterable<LogResult>> {
280
302
  return this;
281
303
  }
282
304
 
305
+ /**
306
+ * `--objects`: the trees, blobs and tags the walk reaches count too. Supported with
307
+ * {@link setDiskUsage} only, and there with revisions alone (no paths or options limiting
308
+ * the commits): the listing itself refuses it.
309
+ */
310
+ setObjects(objects: boolean): this {
311
+ this.checkCallable();
312
+ this.objects = objects;
313
+ return this;
314
+ }
315
+
316
+ /**
317
+ * `--disk-usage` (`true`) or `--disk-usage=<format>` (its format): {@link callText} prints,
318
+ * instead of the list, the bytes on disk of the objects the walk shows (the commits, and
319
+ * with {@link setObjects} every listed object; each counted once, as a pack entry or a loose
320
+ * file), as `<n>`, or with `"human"` in git's units (`1.50 KiB`, `12 bytes`). Any other
321
+ * format dies as git's option parsing does.
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * // git rev-list --disk-usage=human --objects --all
326
+ * await git.revList().addRevision("--all").setObjects(true).setDiskUsage("human").callText();
327
+ * // "3.04 KiB\n"
328
+ * ```
329
+ */
330
+ setDiskUsage(diskUsage: boolean | string): this {
331
+ this.checkCallable();
332
+ this.diskUsage = diskUsage;
333
+ return this;
334
+ }
335
+
336
+ /**
337
+ * `--filter=<spec>` (`--no-filter` with undefined): a partial clone filter of the objects
338
+ * {@link setObjects} counts (list-objects-filter.c); git dies without `--objects`.
339
+ */
340
+ setFilter(spec: string | undefined): this {
341
+ this.checkCallable();
342
+ this.filterSpec = spec;
343
+ return this;
344
+ }
345
+
346
+ /**
347
+ * `--use-bitmap-index`: {@link setObjects}' objects come from the reachability bitmap when
348
+ * the walk allows it, which counts exactly what the wants reach and the haves do not (the
349
+ * plain walk may count more of a range's trees and blobs, as git's does).
350
+ */
351
+ setUseBitmapIndex(use: boolean): this {
352
+ this.checkCallable();
353
+ this.useBitmapIndex = use;
354
+ return this;
355
+ }
356
+
283
357
  /** `--full-history` (see `LogCommand.setFullHistory`). */
284
358
  setFullHistory(fullHistory: boolean): this {
285
359
  return this.configured((log) => log.setFullHistory(fullHistory));
@@ -489,6 +563,7 @@ export class RevListCommand extends GitCommand<AsyncIterable<LogResult>> {
489
563
  private configured(step: (log: LogCommand) => void): this {
490
564
  this.checkCallable();
491
565
  this.configure.push(step);
566
+ this.walkLimited = true;
492
567
  return this;
493
568
  }
494
569
 
@@ -521,7 +596,7 @@ export class RevListCommand extends GitCommand<AsyncIterable<LogResult>> {
521
596
  return {
522
597
  entries: [...parsed.entries, ...more.entries],
523
598
  warnings: resolver.warnings,
524
- inputGiven: !!parsed.inputGiven || more.entries.length > 0,
599
+ inputGiven: !!parsed.inputGiven || !!more.inputGiven,
525
600
  paths: [...stdinPaths, ...more.paths],
526
601
  };
527
602
  }
@@ -551,6 +626,13 @@ export class RevListCommand extends GitCommand<AsyncIterable<LogResult>> {
551
626
  * `--cherry-mark`. With {@link setCount}, the counts instead.
552
627
  */
553
628
  async callText(): Promise<string> {
629
+ const human = this.checkDiskUsage();
630
+ if (this.filterSpec !== undefined && !this.objects) {
631
+ throw new GitApiError("fatal: object filtering requires --objects", { exitCode: 128 });
632
+ }
633
+ if (this.diskUsage !== false) return this.diskUsageText(human);
634
+ if (this.objects)
635
+ throw new GitApiError("rev-list --objects is supported with --disk-usage only");
554
636
  let out = "";
555
637
  // git rev-list has no default revision: nothing given, nothing listed
556
638
  const log = await this.prepare(false);
@@ -577,6 +659,118 @@ export class RevListCommand extends GitCommand<AsyncIterable<LogResult>> {
577
659
  return `${left + right}\n`;
578
660
  }
579
661
 
662
+ /** `--disk-usage=<format>` as builtin/rev-list.c reads it: whether it asks for `human`. */
663
+ private checkDiskUsage(): boolean {
664
+ if (typeof this.diskUsage !== "string") return false;
665
+ if (this.diskUsage === "human") return true;
666
+ throw new GitApiError(
667
+ `fatal: invalid value for '--disk-usage=<format>': '${this.diskUsage}', the only allowed format is 'human'`,
668
+ { exitCode: 128 },
669
+ );
670
+ }
671
+
672
+ /**
673
+ * `--disk-usage`: the bytes on disk of what the walk shows (show_commit and show_object's
674
+ * get_object_disk_usage), printed by print_disk_usage.
675
+ */
676
+ private async diskUsageText(human: boolean): Promise<string> {
677
+ const info = await objectDiskInfoOf(this._workingCopy);
678
+ let total = 0;
679
+ const add = async (id: ObjectId) => {
680
+ const size = await info.diskSize(id);
681
+ if (size === undefined) {
682
+ throw new GitApiError(`fatal: unable to get disk usage of ${id}`, { exitCode: 128 });
683
+ }
684
+ total += size;
685
+ };
686
+ if (this.objects) {
687
+ for (const id of await this.listedObjects()) await add(id);
688
+ } else {
689
+ const log = await this.prepare(false);
690
+ if (log) for await (const commit of await log.call()) await add(commit.id);
691
+ }
692
+ return `${human ? humaniseBytes(BigInt(total)) : total}\n`;
693
+ }
694
+
695
+ /**
696
+ * `--objects`' walk (list-objects.c over the revisions: the commits shown, then the tags,
697
+ * trees and blobs), through the bitmap under {@link setUseBitmapIndex} where git's
698
+ * prepare_bitmap_walk would answer.
699
+ */
700
+ private async listedObjects(): Promise<ObjectId[]> {
701
+ this.checkCallable();
702
+ this.setCallable(false);
703
+ const objects = this._workingCopy.history.objects;
704
+ if (!objects) throw new GitApiError("rev-list --objects needs the object store");
705
+ if (this.walkLimited || this.mixed.length > 0 || this.walkReflogs) {
706
+ throw new GitApiError(
707
+ "rev-list --objects --disk-usage is supported with revisions alone (no paths or walk options)",
708
+ );
709
+ }
710
+ const { entries, warnings } = await this.resolve();
711
+ this.warnings = [...warnings];
712
+ const wants: ObjectId[] = [];
713
+ const haves: ObjectId[] = [];
714
+ for (const entry of entries) (entry.exclude ? haves : wants).push(entry.id);
715
+ if (wants.length === 0) return [];
716
+ const filter = await this.resolvedFilter();
717
+ const bitmap = this.useBitmapIndex
718
+ ? await this._workingCopy.history.packs?.bitmap?.().catch(() => undefined)
719
+ : undefined;
720
+ const ids: ObjectId[] = [];
721
+ for await (const o of listObjects(objects, {
722
+ wants,
723
+ haves,
724
+ ...(filter ? { filter } : {}),
725
+ ...(bitmap ? { bitmap } : {}),
726
+ })) {
727
+ ids.push(o.id);
728
+ }
729
+ return ids;
730
+ }
731
+
732
+ /** `--filter=<spec>` parsed, a `sparse:oid` blob read (git dies on a bad one). */
733
+ private async resolvedFilter(): Promise<ResolvedObjectFilter | undefined> {
734
+ if (this.filterSpec === undefined) return undefined;
735
+ let parsed: ReturnType<typeof parseObjectFilter>;
736
+ try {
737
+ parsed = parseObjectFilter(this.filterSpec);
738
+ } catch (error) {
739
+ if (error instanceof ObjectFilterError) {
740
+ throw new GitApiError(`fatal: ${error.message}`, { exitCode: 128 });
741
+ }
742
+ throw error;
743
+ }
744
+ return resolveObjectFilter(parsed, async (name) => {
745
+ const resolver = this.revisionResolver();
746
+ const id = await resolver.resolve(name).catch(() => undefined);
747
+ const object = id !== undefined ? await this.loadBlobText(id) : undefined;
748
+ if (object === undefined) {
749
+ throw new GitApiError(`fatal: unable to access sparse blob in '${name}'`, {
750
+ exitCode: 128,
751
+ });
752
+ }
753
+ return sparseFilterMatcher(object);
754
+ });
755
+ }
756
+
757
+ /** A blob's content as text, undefined when `id` names no blob. */
758
+ private async loadBlobText(id: ObjectId): Promise<string | undefined> {
759
+ const blobs = this._workingCopy.history.blobs;
760
+ if (!(await blobs.has(id).catch(() => false))) return undefined;
761
+ const chunks: Uint8Array[] = [];
762
+ for await (const chunk of (await blobs.load(id)) ?? []) chunks.push(chunk);
763
+ let length = 0;
764
+ for (const c of chunks) length += c.length;
765
+ const bytes = new Uint8Array(length);
766
+ let at = 0;
767
+ for (const c of chunks) {
768
+ bytes.set(c, at);
769
+ at += c.length;
770
+ }
771
+ return new TextDecoder().decode(bytes);
772
+ }
773
+
580
774
  /** revision.c's get_revision_mark for rev-list (no graph). */
581
775
  private revisionMark(commit: LogResult): string {
582
776
  if (commit.boundary) return "-";
@@ -655,6 +849,14 @@ export class RevListCommand extends GitCommand<AsyncIterable<LogResult>> {
655
849
  ].join("\n");
656
850
  }
657
851
 
852
+ /**
853
+ * fast-export.c's rewrite_commit over the walk {@link call} made (see
854
+ * `LogCommand.rewriteCommit`): `id` itself before a walk.
855
+ */
856
+ rewriteCommit(id: ObjectId): ObjectId | null {
857
+ return this.log ? this.log.rewriteCommit(id) : id;
858
+ }
859
+
658
860
  /** The log walking the revisions; undefined when they name nothing to walk. */
659
861
  private async prepare(defaultHead = true): Promise<LogCommand | undefined> {
660
862
  this.checkCallable();
@@ -323,6 +323,15 @@ export class RevertCommand extends GitCommand<RevertResult> {
323
323
  return made.id;
324
324
  }
325
325
 
326
+ /** git sets `warn_on_auto_comment_char`: 2.5x warns of `core.commentChar=auto` here. */
327
+ protected override autoCommentCharWarningEntryPoints(): readonly string[] {
328
+ return ["call"];
329
+ }
330
+
331
+ protected override gitCompatibility(): "2.43" | "2.56" {
332
+ return this.compatibility ?? this.hooks.compatibility;
333
+ }
334
+
326
335
  async call(): Promise<RevertResult> {
327
336
  this.checkCallable();
328
337
  this.setCallable(false);
@@ -14,10 +14,12 @@
14
14
 
15
15
  import { RevisionError } from "../errors/index.js";
16
16
  import {
17
+ handleRefOption,
17
18
  handleRevisionArg,
18
19
  type ParsedRevisionArgs,
19
20
  type RevisionArgEntry,
20
21
  type RevisionArgOptions,
22
+ type RevisionArgState,
21
23
  unknownRevisionMessage,
22
24
  } from "./revision-range.js";
23
25
  import type { RevisionResolver } from "./revision-resolver.js";
@@ -227,11 +229,27 @@ export async function parseRevisionAndPathArgs(
227
229
  const revisions = dashdash < 0 ? args : args.slice(0, dashdash);
228
230
  const paths = dashdash < 0 ? [] : args.slice(dashdash + 1);
229
231
  let not = false;
230
- for (const [i, arg] of revisions.entries()) {
231
- if (arg === "--not") {
232
+ let endOfOptions = false;
233
+ const state: RevisionArgState = { excludes: [], inputGiven: false, stdinPaths: [] };
234
+ for (let i = 0; i < revisions.length; i++) {
235
+ const arg = revisions[i] as string;
236
+ // setup_revisions: the pseudo options (`--not`, `--all`, `--branches`...) and
237
+ // `--end-of-options` wherever they stand among the revisions
238
+ if (!endOfOptions && arg === "--not") {
232
239
  not = !not;
233
240
  continue;
234
241
  }
242
+ if (!endOfOptions && arg === "--end-of-options") {
243
+ endOfOptions = true;
244
+ continue;
245
+ }
246
+ if (!endOfOptions && arg.startsWith("--")) {
247
+ const taken = await handleRefOption(revisions, i, not, options, state, entries);
248
+ if (taken > 0) {
249
+ i += taken - 1;
250
+ continue;
251
+ }
252
+ }
235
253
  const handled = await handleRevisionArg(resolver, arg, not, options, entries, dashdash >= 0);
236
254
  if (handled === false) {
237
255
  if (dashdash >= 0 || arg.startsWith("^")) {
@@ -243,12 +261,22 @@ export async function parseRevisionAndPathArgs(
243
261
  for (let j = i; j < revisions.length; j++) {
244
262
  await verifyFilename(files, resolver, revisions[j], j === i);
245
263
  }
246
- return { entries, warnings: resolver.warnings, paths: [...revisions.slice(i), ...paths] };
264
+ return {
265
+ entries,
266
+ warnings: resolver.warnings,
267
+ inputGiven: state.inputGiven || entries.length > 0,
268
+ paths: [...revisions.slice(i), ...paths],
269
+ };
247
270
  }
248
271
  if (dashdash < 0 && handled.verifyName !== undefined) {
249
272
  const message = await verifyNonFilename(files, handled.verifyName);
250
273
  if (message) throw new RevisionError(arg, [...resolver.warnings, message].join("\n"));
251
274
  }
252
275
  }
253
- return { entries, warnings: resolver.warnings, paths };
276
+ return {
277
+ entries,
278
+ warnings: resolver.warnings,
279
+ inputGiven: state.inputGiven || entries.length > 0,
280
+ paths,
281
+ };
254
282
  }