@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
@@ -193,6 +193,52 @@ function versionOrigin(config: RemoteConfigStore): string | undefined {
193
193
  }
194
194
  }
195
195
 
196
+ /**
197
+ * `index.recordEndOfIndexEntries`, `index.recordOffsetTable` and `index.threads` as git's
198
+ * `do_write_index` reads them: two booleans and git's `git_config_get_index_threads` (a
199
+ * boolean or an integer: true is 0, threads by the entries and processors; false is 1, none),
200
+ * with the processors online (`online_cpus`, `navigator.hardwareConcurrency`). A value git
201
+ * cannot parse (it dies) is left unset.
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * indexOffsetSettingsOf((key) => (key === "index.threads" ? "true" : undefined));
206
+ * // { threads: 0, onlineCpus: 8 }
207
+ * ```
208
+ */
209
+ export function indexOffsetSettingsOf(value: (key: string) => string | undefined): {
210
+ recordEndOfIndexEntries?: boolean;
211
+ recordOffsetTable?: boolean;
212
+ threads?: number;
213
+ onlineCpus?: number;
214
+ } {
215
+ const out: ReturnType<typeof indexOffsetSettingsOf> = {};
216
+ const eoie = parseGitBool(value("index.recordEndOfIndexEntries"));
217
+ if (eoie !== undefined) out.recordEndOfIndexEntries = eoie;
218
+ const ieot = parseGitBool(value("index.recordOffsetTable"));
219
+ if (ieot !== undefined) out.recordOffsetTable = ieot;
220
+ const threads = value("index.threads");
221
+ if (threads !== undefined) {
222
+ // git_config_bool_or_int: git_parse_maybe_bool_text first, then an int
223
+ const lower = threads.toLowerCase();
224
+ if (lower === "" || lower === "false" || lower === "no" || lower === "off") out.threads = 1;
225
+ else if (lower === "true" || lower === "yes" || lower === "on") out.threads = 0;
226
+ else {
227
+ const n = parseGitInt(threads);
228
+ if (n !== undefined) out.threads = n;
229
+ }
230
+ if (out.threads === 0) out.onlineCpus = onlineCpus();
231
+ }
232
+ return out;
233
+ }
234
+
235
+ /** git's `online_cpus`: the processors the runtime reports, else 1. */
236
+ function onlineCpus(): number {
237
+ const cpus = (globalThis as { navigator?: { hardwareConcurrency?: number } }).navigator
238
+ ?.hardwareConcurrency;
239
+ return typeof cpus === "number" && cpus > 0 ? cpus : 1;
240
+ }
241
+
196
242
  /** The settings of the next write of `staging`, from the working copy's configuration. */
197
243
  export async function indexSettingsOf(
198
244
  workingCopy: WorkingCopy,
@@ -215,6 +261,11 @@ export async function indexSettingsOf(
215
261
  if (skipHash === undefined ? manyFilesOn : (parseGitBool(skipHash) ?? manyFilesOn)) {
216
262
  settings.skipHash = true;
217
263
  }
264
+ // do_write_index's EOIE and IEOT (record_eoie, record_ieot, git_config_get_index_threads)
265
+ Object.assign(
266
+ settings,
267
+ indexOffsetSettingsOf((key) => configValueOf(config, key)),
268
+ );
218
269
  // tweak_fsmonitor's remove_fsmonitor: with the monitor off, no FSMN is written
219
270
  if (fsmonitorModeOf(configValueOf(config, "core.fsmonitor")).kind === "disabled") {
220
271
  settings.fsmonitor = false;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * git's `refresh_index(REFRESH_QUIET)` over a staging area's entries (read-cache.c's
3
+ * `refresh_cache_ent` for each one):
4
+ *
5
+ * ```ts
6
+ * const refresh = await refreshIndexEntries(staging, worktree, { trust, fsmonitor });
7
+ * if (refresh.unmerged.length > 0) refuse();
8
+ * await applyIndexStatUpdates(staging, refresh.updates); // in memory, written with the index
9
+ * ```
10
+ *
11
+ * An entry whose stat no longer matches its file but whose content still does takes the
12
+ * file's current stat; a changed entry is left as it is and nothing is printed. Unmerged
13
+ * paths are reported once each. Skip-worktree and assume-unchanged entries, the ones the
14
+ * file system monitor holds valid, intent-to-add entries and gitlinks are never stat'ed.
15
+ */
16
+
17
+ import { FileMode } from "@statewalker/vcs-core";
18
+ import {
19
+ applyStatUpdate,
20
+ compareWithWorktree,
21
+ type FsmonitorState,
22
+ type IndexStatUpdate,
23
+ type Staging,
24
+ type StagingEntry,
25
+ statUpdateOf,
26
+ type Worktree,
27
+ type WorktreeModeTrust,
28
+ withWorktreeEntries,
29
+ } from "@statewalker/vcs-working-tree";
30
+
31
+ export interface IndexRefreshOptions {
32
+ /** What the worktree's modes and stat fields can be trusted for (`worktreeModeTrust`) */
33
+ trust: WorktreeModeTrust;
34
+ /**
35
+ * The index's file system monitor state: a valid entry is taken as up to date unseen,
36
+ * and an entry found up to date by its stat is marked valid (`mark_fsmonitor_valid`)
37
+ */
38
+ fsmonitor?: FsmonitorState;
39
+ }
40
+
41
+ export interface IndexRefreshResult {
42
+ /** The fresh stats of the entries proved clean by reading them */
43
+ updates: IndexStatUpdate[];
44
+ /** The unmerged paths, once each, in index order */
45
+ unmerged: string[];
46
+ }
47
+
48
+ /** `refresh_index(REFRESH_QUIET)`: what the refresh would store (see the module comment). */
49
+ export async function refreshIndexEntries(
50
+ staging: Staging,
51
+ worktree: Worktree,
52
+ options: IndexRefreshOptions,
53
+ ): Promise<IndexRefreshResult> {
54
+ const { trust, fsmonitor } = options;
55
+ const entries: StagingEntry[] = [];
56
+ for await (const entry of staging.entryList?.() ?? staging.entries()) entries.push(entry);
57
+ const indexTime = staging.getUpdateTime();
58
+ // refresh_cache_ent passes over what it cannot or need not stat
59
+ const stated = (entry: StagingEntry) =>
60
+ entry.stage === 0 &&
61
+ !entry.skipWorktree &&
62
+ !entry.assumeValid &&
63
+ !entry.intentToAdd &&
64
+ entry.mode !== FileMode.GITLINK &&
65
+ !fsmonitor?.isValid(entry);
66
+ const updates: IndexStatUpdate[] = [];
67
+ const unmerged: string[] = [];
68
+ for await (const { item: entry, current } of withWorktreeEntries(worktree, entries, stated)) {
69
+ if (entry.stage !== 0) {
70
+ if (unmerged[unmerged.length - 1] !== entry.path) unmerged.push(entry.path);
71
+ continue;
72
+ }
73
+ if (!stated(entry)) continue;
74
+ const compared = await compareWithWorktree(worktree, entry, { trust, indexTime }, current);
75
+ if (compared.kind) continue;
76
+ const update = statUpdateOf(entry, compared);
77
+ if (update && !update.smudge) {
78
+ // replaced (its stat stored): no longer fsmonitor-valid (replace_index_entry)
79
+ if (!sameStatAsEntry(entry, update)) {
80
+ updates.push(update);
81
+ continue;
82
+ }
83
+ }
84
+ // up to date as it is: mark_fsmonitor_valid
85
+ fsmonitor?.markValid(entry);
86
+ }
87
+ return { updates, unmerged };
88
+ }
89
+
90
+ /** Stores the stats of a refresh in the staging area, in memory (compare-and-set per entry). */
91
+ export async function applyIndexStatUpdates(
92
+ staging: Staging,
93
+ updates: readonly IndexStatUpdate[],
94
+ ): Promise<void> {
95
+ if (updates.length === 0) return;
96
+ const now = Date.now();
97
+ const editor = staging.createEditor();
98
+ for (const update of updates) {
99
+ editor.add({
100
+ path: update.path,
101
+ apply: (existing) => applyStatUpdate(existing, update, now) ?? existing,
102
+ });
103
+ }
104
+ await editor.finish();
105
+ }
106
+
107
+ /** Whether a stat update would store exactly what the entry holds. */
108
+ function sameStatAsEntry(entry: StagingEntry, update: IndexStatUpdate): boolean {
109
+ const same = (a: number | undefined, b: number | undefined) => b === undefined || a === b;
110
+ return (
111
+ entry.size === update.size &&
112
+ entry.mtime === update.mtime &&
113
+ same(entry.mtimeNs, update.mtimeNs) &&
114
+ same(entry.ctime, update.ctime) &&
115
+ same(entry.ctimeNs, update.ctimeNs) &&
116
+ same(entry.dev, update.dev) &&
117
+ same(entry.ino, update.ino) &&
118
+ same(entry.uid, update.uid) &&
119
+ same(entry.gid, update.gid)
120
+ );
121
+ }
@@ -24,9 +24,12 @@ export * from "./cherry-pick-command.js";
24
24
  export * from "./clean-command.js";
25
25
  export * from "./clean-interactive.js";
26
26
  export * from "./clone-command.js";
27
+ export * from "./column/index.js";
28
+ export * from "./column-command.js";
27
29
  export * from "./comment-char-config.js";
28
30
  export * from "./commit-command.js";
29
31
  export * from "./config-command.js";
32
+ export * from "./credential-helper.js";
30
33
  export * from "./daemon-access-hook.js";
31
34
  export * from "./date-format.js";
32
35
  export * from "./default-branch.js";
@@ -71,6 +74,7 @@ export * from "./ls-remote-command.js";
71
74
  export * from "./ls-tree-command.js";
72
75
  export * from "./mailmap.js";
73
76
  export * from "./maintenance-run-command.js";
77
+ export * from "./maintenance-schedule-command.js";
74
78
  export * from "./merge-base-command.js";
75
79
  export * from "./merge-command.js";
76
80
  export {
@@ -85,6 +89,8 @@ export {
85
89
  type MergeDriverResult,
86
90
  mergeDriversOf,
87
91
  } from "./merge-drivers.js";
92
+ export * from "./merge-index-command.js";
93
+ export * from "./merge-one-file.js";
88
94
  export {
89
95
  applyStrategyOption,
90
96
  type MergeStrategyOptions,
@@ -108,6 +114,7 @@ export {
108
114
  combineNotesOverwrite,
109
115
  NotesTree,
110
116
  } from "./notes-tree.js";
117
+ export * from "./object-disk-info.js";
111
118
  export * from "./object-store/index.js";
112
119
  export * from "./pack-refs-command.js";
113
120
  export { type PatchIdTextOptions, patchIdsOfPatchText } from "./patch-id.js";
@@ -154,6 +161,7 @@ export * from "./revision-resolver.js";
154
161
  export * from "./rm-command.js";
155
162
  export { SequencerOperation } from "./sequencer-pick.js";
156
163
  export * from "./serve-repository.js";
164
+ export * from "./served-lazy-fetch.js";
157
165
  export * from "./shortlog.js";
158
166
  export * from "./shortlog-command.js";
159
167
  export * from "./show-branch-command.js";
@@ -175,6 +183,7 @@ export * from "./stash-pop-command.js";
175
183
  export * from "./stash-show-command.js";
176
184
  export * from "./stash-store-command.js";
177
185
  export * from "./stash-working-tree.js";
186
+ export * from "./status-color-config.js";
178
187
  export * from "./status-command.js";
179
188
  export * from "./status-format.js";
180
189
  export * from "./stripspace-command.js";
@@ -120,8 +120,38 @@ export class InitCommand {
120
120
  private template?: { path: string; files?: FilesApi };
121
121
  /** `--shared` as git_config_perm reads it; undefined: core.sharedRepository decides */
122
122
  private shared?: number;
123
+ /** The git version whose hint is given; undefined: the hook runner's, else 2.56 */
124
+ private compatibility?: "2.43" | "2.56";
125
+ /** `-q`: no default-branch hint */
126
+ private quiet = false;
123
127
  private callable = true;
124
128
 
129
+ /**
130
+ * Follow git `version` where versions differ (`setCompatibility("2.43")`): 2.43 hints
131
+ * about the default branch in its own words whatever `advice.defaultBranchName` says,
132
+ * 2.5x reads the setting. Default: the hook runner's compatibility, else 2.56.
133
+ *
134
+ * @param version The git version to follow
135
+ * @returns this for method chaining
136
+ */
137
+ setCompatibility(version: "2.43" | "2.56"): this {
138
+ this.checkCallable();
139
+ this.compatibility = version;
140
+ return this;
141
+ }
142
+
143
+ /**
144
+ * `git init -q`: no default-branch hint ({@link InitResult.hints} undefined) in any version.
145
+ *
146
+ * @param quiet Whether to be quiet
147
+ * @returns this for method chaining
148
+ */
149
+ setQuiet(quiet: boolean): this {
150
+ this.checkCallable();
151
+ this.quiet = quiet;
152
+ return this;
153
+ }
154
+
125
155
  /**
126
156
  * Put the repository at `path` (`git init --separate-git-dir <path>`, a path of the
127
157
  * FilesApi) and write a gitfile in its place (`<directory>/.git`: `gitdir: <path>`, the
@@ -398,7 +428,10 @@ export class InitCommand {
398
428
  const chosen =
399
429
  this.initialBranch !== undefined
400
430
  ? { name: this.initialBranch }
401
- : await defaultInitialBranch(this.environment, config);
431
+ : await defaultInitialBranch(this.environment, config, {
432
+ quiet: this.quiet,
433
+ ...(this.compatibility ? { compatibility: this.compatibility } : {}),
434
+ });
402
435
  initialBranch = chosen.name;
403
436
  hints = chosen.hint;
404
437
  };
@@ -23,7 +23,7 @@ import type { FilesApi } from "@statewalker/vcs-utils/files";
23
23
  import type { WorkingCopy } from "@statewalker/vcs-working-tree";
24
24
 
25
25
  import { type LegacyRemote, RemoteConfigStore, setLegacyRemote } from "../remote-config/index.js";
26
- import { defaultBranchHint } from "./default-branch.js";
26
+ import { defaultBranchHint, defaultBranchHint243 } from "./default-branch.js";
27
27
  import { commonGitFileOf } from "./git-hooks.js";
28
28
  import { hostEnvironmentOf } from "./git-ident.js";
29
29
 
@@ -173,27 +173,11 @@ function defaultBranchName(
173
173
  const configured = store.value("init.defaultBranch");
174
174
  if (configured !== undefined && configured !== "") return { name: configured };
175
175
  const name = "master";
176
+ // 2.43 calls advise(), whatever advice.defaultBranchName says; 2.5x advise_if_enabled()
177
+ if (compatibility === "2.43") return { name, hint: defaultBranchHint243(name).join("\n") };
176
178
  const advice = store.value("advice.defaultBranchName");
177
179
  if (advice !== undefined && parseGitBool(advice) === false) return { name };
178
- const hint =
179
- compatibility === "2.43" ? defaultBranchHint243(name) : defaultBranchHint(name, false);
180
- return { name, hint: hint.join("\n") };
181
- }
182
-
183
- /** git 2.43's `default_branch_name_advice` (an empty line is `hint: `, with its space). */
184
- function defaultBranchHint243(name: string): string[] {
185
- return [
186
- `Using '${name}' as the name for the initial branch. This default branch name`,
187
- "is subject to change. To configure the initial branch name to use in all",
188
- "of your new repositories, which will suppress this warning, call:",
189
- "",
190
- "\tgit config --global init.defaultBranch <name>",
191
- "",
192
- "Names commonly chosen instead of 'master' are 'main', 'trunk' and",
193
- "'development'. The just-created branch can be renamed via this command:",
194
- "",
195
- "\tgit branch -m <name>",
196
- ].map((line) => `hint: ${line}`);
180
+ return { name, hint: defaultBranchHint(name, false).join("\n") };
197
181
  }
198
182
 
199
183
  /**
@@ -11,9 +11,12 @@ import {
11
11
  createRepositoryFacade,
12
12
  createTransportRefStore,
13
13
  type Duplex,
14
+ GitNamespaceError,
14
15
  type GitServeSettings,
16
+ gitNamespacePrefix,
15
17
  openDuplexConnection,
16
18
  openDuplexReceivePackConnection,
19
+ type PackObjectsHook,
17
20
  type PushCertSignatureCheck,
18
21
  pushCertificateEnv,
19
22
  type ReceiveCommand,
@@ -49,6 +52,7 @@ import {
49
52
  refTransactionHookOf,
50
53
  } from "./git-hooks.js";
51
54
  import { ReadTreeCommand } from "./read-tree-command.js";
55
+ import { type ServedLazyFetchOptions, uploadPackHistory } from "./served-lazy-fetch.js";
52
56
  import { checkSignatureWith } from "./signature-check.js";
53
57
  import { signingConfigFromEntries } from "./signing.js";
54
58
  import { StatusCommand } from "./status-command.js";
@@ -192,6 +196,23 @@ export async function openLocalRemote(
192
196
  return opened;
193
197
  }
194
198
 
199
+ /**
200
+ * The death of a local upload-pack or receive-pack started under a `GIT_NAMESPACE` git
201
+ * refuses (`get_git_namespace`'s `bad git namespace path "<ns>"`), as a git 2.5x client shows
202
+ * it: then its own death, which for a v2 fetch is its ls-refs reader's (`v2`).
203
+ */
204
+ function checkLocalNamespace(namespace: string | undefined, v2 = false): void {
205
+ try {
206
+ gitNamespacePrefix(namespace);
207
+ } catch (error) {
208
+ if (error instanceof GitNamespaceError) {
209
+ const client = v2 ? "fatal: expected flush after ref listing" : COULD_NOT_READ;
210
+ throw new TransportError(`fatal: ${error.message}\n${client}`);
211
+ }
212
+ throw error;
213
+ }
214
+ }
215
+
195
216
  /**
196
217
  * Runs `run` over a connection to upload-pack serving a local repository (opened by
197
218
  * {@link openLocalRemote}) with protocol v2, git's default `protocol.version` (v0 when the
@@ -201,18 +222,42 @@ export async function openLocalRemote(
201
222
  export async function withLocalUploadPack<T>(
202
223
  remote: OpenedRepository,
203
224
  run: (connection: UploadPackConnection) => Promise<T>,
204
- options: { protocolVersion?: 0 | 1 | 2 } = {},
225
+ options: {
226
+ protocolVersion?: 0 | 1 | 2;
227
+ /**
228
+ * git's `uploadpack.packObjectsHook` as the spawned upload-pack reads it (system and
229
+ * global files only: `packObjectsHookOf(hooks, { commandLine: false })`)
230
+ */
231
+ packObjectsHook?: PackObjectsHook;
232
+ /**
233
+ * `$GIT_NAMESPACE`, which the spawned upload-pack inherits: it serves that namespace
234
+ * (gitnamespaces(7)); a bad value is its death
235
+ */
236
+ namespace?: string;
237
+ /**
238
+ * The client's `GIT_NO_LAZY_FETCH=0`, which the spawned upload-pack inherits: it fetches
239
+ * the absent promisor objects a pack needs from the remote's promisor remotes, through
240
+ * the client's transports (never its static credentials); else refused as git's
241
+ */
242
+ lazyFetch?: ServedLazyFetchOptions;
243
+ } = {},
205
244
  ): Promise<T> {
245
+ checkLocalNamespace(options.namespace, (options.protocolVersion ?? 2) === 2);
206
246
  const head = await remote.history.refs.get("HEAD").catch(() => undefined);
207
247
  const settings = serverSettingsOf(remote);
208
248
  const [client, server] = createDuplexPair();
209
- // upload-pack never fetches lazily (GIT_NO_LAZY_FETCH): it reads through the history's
210
- // view without lazy fetch, as receive-pack does (rev-list --exclude-promisor-objects)
249
+ // upload-pack's GIT_NO_LAZY_FETCH (set unless inherited): absent promisor objects are
250
+ // refused with git's warning and death, or fetched under the client's GIT_NO_LAZY_FETCH=0
251
+ const history = await uploadPackHistory(
252
+ remote,
253
+ options.lazyFetch,
254
+ options.lazyFetch?.environment,
255
+ );
211
256
  const serving = (async () =>
212
257
  serveOverDuplex({
213
258
  duplex: server,
214
259
  repository: createRepositoryFacade({
215
- history: historyWithoutLazyFetch(remote.history),
260
+ history,
216
261
  useBitmaps: servedUseBitmaps(remote),
217
262
  sparseFilterPatterns: sparseFilterMatcher,
218
263
  maxTreeDepth: servedMaxTreeDepth(remote),
@@ -244,14 +289,18 @@ export async function withLocalUploadPack<T>(
244
289
  ...(settings.promisorRemoteInfo !== undefined
245
290
  ? { promisorRemoteInfo: settings.promisorRemoteInfo }
246
291
  : {}),
292
+ // uploadpack.packObjectsHook (protected configuration, never the repository's)
293
+ ...(options.packObjectsHook ? { packObjectsHook: options.packObjectsHook } : {}),
247
294
  ...(head && "target" in head ? { currentBranch: head.target } : {}),
295
+ // GIT_NAMESPACE (inherited): the namespace's refs, HEAD and hidden-ref matching
296
+ ...(options.namespace ? { namespace: options.namespace } : {}),
248
297
  }))().finally(() => server.close?.());
249
298
  try {
250
299
  const connection = await openDuplexConnection(client, { closeDuplex: true });
251
300
  try {
252
301
  return await run(connection);
253
302
  } catch (error) {
254
- throw packFailure(error) ?? error;
303
+ throw packFailure(error) ?? (await packObjectsDeath(error, serving)) ?? error;
255
304
  } finally {
256
305
  await connection.close();
257
306
  }
@@ -261,6 +310,38 @@ export async function withLocalUploadPack<T>(
261
310
  }
262
311
  }
263
312
 
313
+ /**
314
+ * pack-objects died before the pack's first byte (its stderr already relayed on the
315
+ * progress band, upload-pack's abort on band 3: `PackObjectsError`): the lines git's local
316
+ * transport prints after that, upload-pack's own (on the shared stderr: create_pack_file's
317
+ * error, a failed `uploadpack.packObjectsHook`'s own, then its death), the abort as the client
318
+ * shows it, and index-pack finding no pack.
319
+ */
320
+ async function packObjectsDeath(
321
+ error: unknown,
322
+ serving: Promise<{ error?: string }>,
323
+ ): Promise<TransportError | undefined> {
324
+ const abort = "aborting due to possible repository corruption on the remote side.";
325
+ if (!(error instanceof Error) || error.name !== "ServerError") return undefined;
326
+ if (!error.message.startsWith(abort)) return undefined;
327
+ const served = await serving.catch(() => undefined);
328
+ const reported = served?.error;
329
+ if (reported === undefined) return undefined;
330
+ const died = reported.startsWith("fatal: ")
331
+ ? "error: git upload-pack: git-pack-objects died with error."
332
+ : `error: ${reported}`;
333
+ return new TransportError(
334
+ [
335
+ died,
336
+ `fatal: git upload-pack: ${abort}`,
337
+ `remote: ${abort}`,
338
+ "fatal: protocol error: bad pack header",
339
+ ].join("\n"),
340
+ undefined,
341
+ { cause: error },
342
+ );
343
+ }
344
+
264
345
  /**
265
346
  * The lines git prints when upload-pack's pack-objects fails on an object it cannot read
266
347
  * (upload-pack.c's create_pack_file): its own error and death (upload-pack's stderr, which
@@ -469,8 +550,14 @@ export async function withLocalReceivePack<T>(
469
550
  protocolVersion?: 0 | 1 | 2;
470
551
  host?: ReceivePackHost;
471
552
  onWarning?: (line: string) => void;
553
+ /**
554
+ * `$GIT_NAMESPACE`, which the spawned receive-pack and its hooks inherit: it serves that
555
+ * namespace and every hook it runs sees the variable; a bad value is its death
556
+ */
557
+ namespace?: string;
472
558
  } = {},
473
559
  ): Promise<T> {
560
+ checkLocalNamespace(options.namespace);
474
561
  // receive-pack's enter_repo(path, 0): a repository another user owns is refused (git's
475
562
  // die_upon_dubious_ownership in the child), and the client sees the connection fail
476
563
  try {
@@ -483,8 +570,13 @@ export async function withLocalReceivePack<T>(
483
570
  }
484
571
  const receiveHooks = hooks?.enabled ? scriptReceiveHooks(hooks) : undefined;
485
572
  // the remote's reference-transaction hook on its ref store while receive-pack runs (its
486
- // output goes to the pushing user's stderr directly, not through the side-band)
487
- return withReceiveTransactionHook(remote, transactionHooks, () =>
573
+ // output goes to the pushing user's stderr directly, not through the side-band); it
574
+ // inherits GIT_NAMESPACE as every child of receive-pack does
575
+ const transactionSession =
576
+ options.namespace && transactionHooks
577
+ ? transactionHooks.withEnv({ GIT_NAMESPACE: options.namespace })
578
+ : transactionHooks;
579
+ return withReceiveTransactionHook(remote, transactionSession, () =>
488
580
  receiveOver(remote, run, hooks, receiveHooks, options.protocolVersion === 1, options),
489
581
  );
490
582
  }
@@ -555,6 +647,12 @@ export interface ReceivePackHost {
555
647
  * repository reads them as git does
556
648
  */
557
649
  confineFiles?: boolean;
650
+ /**
651
+ * The largest object a pushed pack may hold (`ReceivePackConfig.maxObjectSize`, JGit's
652
+ * `ReceivePack.setMaxObjectSizeLimit`): the caller's choice, never read from the
653
+ * repository's config (git has no such setting). Absent: the import's 1 GiB.
654
+ */
655
+ maxObjectSize?: number;
558
656
  }
559
657
 
560
658
  /**
@@ -654,6 +752,8 @@ export async function receivePackSettingsOf(
654
752
  ? { advertiseAtomic: settings.advertiseAtomic }
655
753
  : {}),
656
754
  ...(settings.maxInputSize !== undefined ? { maxInputSize: settings.maxInputSize } : {}),
755
+ // the caller's per-object limit (no git config key)
756
+ ...(host.maxObjectSize !== undefined ? { maxObjectSize: host.maxObjectSize } : {}),
657
757
  // receive.certNonceSeed, receive.certNonceSlop: signed pushes, their signature checked with
658
758
  // the repository's gpg.* through the host's verifier
659
759
  ...(settings.certNonceSeed !== undefined ? { certNonceSeed: settings.certNonceSeed } : {}),
@@ -806,7 +906,11 @@ async function receiveOver<T>(
806
906
  hooks: HookSession | undefined,
807
907
  receiveHooks: ReceivePackHooks | undefined,
808
908
  version1: boolean,
809
- options: { host?: ReceivePackHost; onWarning?: (line: string) => void } = {},
909
+ options: {
910
+ host?: ReceivePackHost;
911
+ onWarning?: (line: string) => void;
912
+ namespace?: string;
913
+ } = {},
810
914
  ): Promise<T> {
811
915
  const [client, server] = createDuplexPair();
812
916
  const host = options.host ?? {};
@@ -827,6 +931,8 @@ async function receiveOver<T>(
827
931
  refStore: createTransportRefStore(remote.history.refs),
828
932
  service: "git-receive-pack",
829
933
  ...(version1 ? { announceVersion1: true } : {}),
934
+ // GIT_NAMESPACE (inherited): the namespace's refs; the hooks get the variable
935
+ ...(options.namespace ? { namespace: options.namespace } : {}),
830
936
  }).finally(() => server.close?.());
831
937
  // receive-pack died (its reference-transaction hook aborted the update): its message on
832
938
  // the shared stderr, then send-pack's, as git's local transport shows them
@@ -1011,8 +1117,23 @@ export function httpBackendEnv(
1011
1117
  return env;
1012
1118
  }
1013
1119
 
1120
+ /**
1121
+ * The variables receive-pack's hooks inherit from it for a push its hook context describes:
1122
+ * `GIT_NAMESPACE` when the push is served in a namespace, and {@link httpBackendEnv} for one
1123
+ * over HTTP (it has a request).
1124
+ */
1125
+ function hookClientEnv(
1126
+ hooks: HookSession,
1127
+ ctx: ReceivePackHookContext | undefined,
1128
+ ): Record<string, string> {
1129
+ return {
1130
+ ...(ctx?.namespace ? { GIT_NAMESPACE: ctx.namespace } : {}),
1131
+ ...httpEnvOf(hooks, ctx),
1132
+ };
1133
+ }
1134
+
1014
1135
  /** {@link httpBackendEnv} of a push its hook context describes (HTTP: it has a request). */
1015
- function hookClientEnv(hooks: HookSession, ctx: ReceivePackHookContext | undefined) {
1136
+ function httpEnvOf(hooks: HookSession, ctx: ReceivePackHookContext | undefined) {
1016
1137
  return httpBackendEnv(
1017
1138
  hooks,
1018
1139
  ctx?.request
@@ -1097,6 +1097,27 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
1097
1097
  return this;
1098
1098
  }
1099
1099
 
1100
+ /**
1101
+ * fast-export.c's rewrite_commit over the walk just made: from `id`, the first commit along
1102
+ * first parents that is a merge, UNINTERESTING or not TREESAME (the commit a ref or tag of a
1103
+ * path-limited export is moved to); `null` when the line ends in TREESAME commits (git's
1104
+ * NULL: the ref is filtered to nothing). A commit the walk never met is its own answer.
1105
+ */
1106
+ rewriteCommit(id: ObjectId): ObjectId | null {
1107
+ const t = this.lastWalk;
1108
+ let n = t?.find(id);
1109
+ if (t === undefined || n === undefined) return id;
1110
+ for (;;) {
1111
+ const parents = t.parsed(n) ? t.parentList(n) : [];
1112
+ if (parents.length > 1) break;
1113
+ if (t.flag(n) & UNINTERESTING) break;
1114
+ if (!(t.flag(n) & TREESAME)) break;
1115
+ if (parents.length === 0) return null;
1116
+ n = parents[0] as number;
1117
+ }
1118
+ return t.idOf(n);
1119
+ }
1120
+
1100
1121
  /** What the path-limited walk did so far (see {@link LogPathStatistics}). */
1101
1122
  getStatistics(): LogPathStatistics {
1102
1123
  return {
@@ -3031,7 +3052,13 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
3031
3052
  oldTree: ObjectId,
3032
3053
  newTree: ObjectId,
3033
3054
  formats: DiffOutputFormat[],
3034
- options: { statWidth?: number; follow?: string; fullDiff?: boolean; abbrev?: number },
3055
+ options: {
3056
+ statWidth?: number;
3057
+ follow?: string;
3058
+ fullDiff?: boolean;
3059
+ abbrev?: number;
3060
+ linePrefix?: boolean;
3061
+ },
3035
3062
  prepare?: (diff: DiffCommand) => void,
3036
3063
  ) => {
3037
3064
  // the trees themselves: a full id names its object, so no revision is looked up
@@ -3044,6 +3071,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
3044
3071
  .setRotateStrict(false)
3045
3072
  .setTreeWalk(this.treeWalk)
3046
3073
  .shareReadsOf(this);
3074
+ if (options.linePrefix) diff.setLinePrefixPoints(true);
3047
3075
  if (this.colorSettings) diff.setColorSettings(this.colorSettings);
3048
3076
  diff.setOptions({
3049
3077
  ...this.diffOptions,
@@ -4276,6 +4304,16 @@ class RevTable {
4276
4304
  return n;
4277
4305
  }
4278
4306
 
4307
+ /** The commit `id` when the table holds it (nothing is added). */
4308
+ find(id: ObjectId): number | undefined {
4309
+ const known = this.byId.get(id);
4310
+ if (known !== undefined) return known;
4311
+ const pos = this.graph ? this.graph.position(id) : -1;
4312
+ if (pos < 0) return undefined;
4313
+ const n = ((this.byPos as Int32Array)[pos] as number) - 1;
4314
+ return n >= 0 ? n : undefined;
4315
+ }
4316
+
4279
4317
  /** The commit at graph position `pos`, added when first met. */
4280
4318
  lookupPos(pos: number): number {
4281
4319
  const byPos = this.byPos as Int32Array;