@statewalker/vcs-commands 0.10.0 → 0.12.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 (115) hide show
  1. package/dist/commands/am/am-command.d.ts.map +1 -1
  2. package/dist/commands/archive/archive-command.d.ts +81 -7
  3. package/dist/commands/archive/archive-command.d.ts.map +1 -1
  4. package/dist/commands/archive/archive-entry.d.ts +48 -5
  5. package/dist/commands/archive/archive-entry.d.ts.map +1 -1
  6. package/dist/commands/archive/tar-archive.d.ts +5 -2
  7. package/dist/commands/archive/tar-archive.d.ts.map +1 -1
  8. package/dist/commands/archive/zip-archive.d.ts +9 -2
  9. package/dist/commands/archive/zip-archive.d.ts.map +1 -1
  10. package/dist/commands/attributes-source.d.ts +5 -0
  11. package/dist/commands/attributes-source.d.ts.map +1 -1
  12. package/dist/commands/cat-file/cat-file-command.d.ts +9 -0
  13. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
  14. package/dist/commands/checkout-command.d.ts.map +1 -1
  15. package/dist/commands/clone-command.d.ts +9 -0
  16. package/dist/commands/clone-command.d.ts.map +1 -1
  17. package/dist/commands/default-branch.d.ts +12 -0
  18. package/dist/commands/default-branch.d.ts.map +1 -1
  19. package/dist/commands/diff-command.d.ts.map +1 -1
  20. package/dist/commands/format-rev-command.d.ts +6 -4
  21. package/dist/commands/format-rev-command.d.ts.map +1 -1
  22. package/dist/commands/fsmonitor-ipc.d.ts +30 -0
  23. package/dist/commands/fsmonitor-ipc.d.ts.map +1 -0
  24. package/dist/commands/fsmonitor-refresh.d.ts.map +1 -1
  25. package/dist/commands/http-config.d.ts +4 -2
  26. package/dist/commands/http-config.d.ts.map +1 -1
  27. package/dist/commands/index.d.ts +2 -0
  28. package/dist/commands/index.d.ts.map +1 -1
  29. package/dist/commands/index.js +6 -6
  30. package/dist/commands/log-output.d.ts +6 -0
  31. package/dist/commands/log-output.d.ts.map +1 -1
  32. package/dist/commands/ls-files-command.d.ts.map +1 -1
  33. package/dist/commands/ls-tree-command.d.ts.map +1 -1
  34. package/dist/commands/mv-command.d.ts.map +1 -1
  35. package/dist/commands/pathspec.d.ts.map +1 -1
  36. package/dist/commands/plumbing-shared.d.ts +72 -0
  37. package/dist/commands/plumbing-shared.d.ts.map +1 -0
  38. package/dist/commands/repack-command.d.ts +12 -3
  39. package/dist/commands/repack-command.d.ts.map +1 -1
  40. package/dist/commands/replace-command.d.ts.map +1 -1
  41. package/dist/commands/repo-command.d.ts +28 -6
  42. package/dist/commands/repo-command.d.ts.map +1 -1
  43. package/dist/commands/rerere-command.d.ts +12 -0
  44. package/dist/commands/rerere-command.d.ts.map +1 -1
  45. package/dist/commands/rerere.d.ts +22 -0
  46. package/dist/commands/rerere.d.ts.map +1 -1
  47. package/dist/commands/reset-command.d.ts +19 -2
  48. package/dist/commands/reset-command.d.ts.map +1 -1
  49. package/dist/commands/rev-parse-command.d.ts +3 -7
  50. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  51. package/dist/commands/revision-resolver.d.ts +24 -5
  52. package/dist/commands/revision-resolver.d.ts.map +1 -1
  53. package/dist/commands/signing.d.ts +8 -1
  54. package/dist/commands/signing.d.ts.map +1 -1
  55. package/dist/commands/status-command.d.ts +14 -1
  56. package/dist/commands/status-command.d.ts.map +1 -1
  57. package/dist/commands/submodule-add-command.d.ts +12 -0
  58. package/dist/commands/submodule-add-command.d.ts.map +1 -1
  59. package/dist/commands/submodule-update-command.d.ts +14 -0
  60. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  61. package/dist/commands/tag-command.d.ts.map +1 -1
  62. package/dist/commands/update-index-command.d.ts +21 -0
  63. package/dist/commands/update-index-command.d.ts.map +1 -1
  64. package/dist/{commands-Mlo1dxQN.js → commands-C2E51T1z.js} +942 -293
  65. package/dist/{fsck-CrhVMNIH.js → fsck-BjlxStsM.js} +1 -1
  66. package/dist/git-command.d.ts +14 -6
  67. package/dist/git-command.d.ts.map +1 -1
  68. package/dist/index.js +6 -6
  69. package/dist/{maintenance-run-command-Bw21HEkH.js → maintenance-run-command-G_eWdA8O.js} +48 -17
  70. package/dist/remote-config/remote-config-store.d.ts +4 -1
  71. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  72. package/dist/{remote-transport-Bu4PGSMD.js → remote-transport-CSgTJ1BH.js} +3 -3
  73. package/dist/results/index.js +1 -1
  74. package/dist/{results-ERo9vELd.js → results-Dg1KHG8y.js} +669 -96
  75. package/dist/transport-command.d.ts.map +1 -1
  76. package/package.json +13 -13
  77. package/src/commands/am/am-command.ts +30 -14
  78. package/src/commands/archive/archive-command.ts +395 -59
  79. package/src/commands/archive/archive-entry.ts +88 -5
  80. package/src/commands/archive/tar-archive.ts +40 -9
  81. package/src/commands/archive/zip-archive.ts +72 -21
  82. package/src/commands/attributes-source.ts +13 -1
  83. package/src/commands/cat-file/cat-file-command.ts +64 -52
  84. package/src/commands/checkout-command.ts +22 -1
  85. package/src/commands/clone-command.ts +41 -2
  86. package/src/commands/default-branch.ts +19 -0
  87. package/src/commands/diff-command.ts +19 -1
  88. package/src/commands/format-rev-command.ts +28 -12
  89. package/src/commands/fsmonitor-ipc.ts +121 -0
  90. package/src/commands/fsmonitor-refresh.ts +7 -2
  91. package/src/commands/http-config.ts +14 -2
  92. package/src/commands/index.ts +2 -0
  93. package/src/commands/log-output.ts +11 -0
  94. package/src/commands/ls-files-command.ts +25 -33
  95. package/src/commands/ls-tree-command.ts +30 -22
  96. package/src/commands/mv-command.ts +37 -6
  97. package/src/commands/pathspec.ts +2 -4
  98. package/src/commands/plumbing-shared.ts +197 -0
  99. package/src/commands/repack-command.ts +44 -11
  100. package/src/commands/replace-command.ts +16 -4
  101. package/src/commands/repo-command.ts +124 -25
  102. package/src/commands/rerere-command.ts +17 -0
  103. package/src/commands/rerere.ts +144 -3
  104. package/src/commands/reset-command.ts +75 -3
  105. package/src/commands/rev-parse-command.ts +14 -28
  106. package/src/commands/revision-resolver.ts +85 -34
  107. package/src/commands/signing.ts +54 -7
  108. package/src/commands/status-command.ts +31 -2
  109. package/src/commands/submodule-add-command.ts +18 -1
  110. package/src/commands/submodule-update-command.ts +18 -1
  111. package/src/commands/tag-command.ts +33 -11
  112. package/src/commands/update-index-command.ts +137 -5
  113. package/src/git-command.ts +60 -19
  114. package/src/remote-config/remote-config-store.ts +11 -3
  115. package/src/transport-command.ts +4 -1
@@ -90,7 +90,13 @@ import { globalPathspecMagic } from "./pathspec.js";
90
90
  import { PathspecFile } from "./pathspec-file.js";
91
91
  import { markIndexUpdate } from "./post-index-change.js";
92
92
  import { reflogMessages } from "./reflog-messages.js";
93
- import { checkFlaggedEntries, recordWrittenStat, restoreWorktreeHard } from "./reset-command.js";
93
+ import {
94
+ checkFlaggedEntries,
95
+ fsmonitorKeptEntries,
96
+ recordWrittenStat,
97
+ restoreKeptEntries,
98
+ restoreWorktreeHard,
99
+ } from "./reset-command.js";
94
100
  import { removeBranchState } from "./sequencer-support.js";
95
101
  import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
96
102
  import { StashApplyCommand } from "./stash-apply-command.js";
@@ -974,7 +980,12 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
974
980
  treeId,
975
981
  sparse,
976
982
  );
983
+ // oneway_merge: what the file system monitor holds unchanged is neither stat'ed nor written
984
+ const fsmKept = worktree
985
+ ? await fsmonitorKeptEntries(this.trees, this.staging, treeId)
986
+ : new Map<string, StagingEntry>();
977
987
  await this.staging.readTree(this.trees, treeId, { keepMatching: "flags" });
988
+ await restoreKeptEntries(this.staging, fsmKept);
978
989
  // reset_head's prime_cache_tree: the index is HEAD's tree
979
990
  this.staging.setCacheTree?.(await cacheTreeOfTree(this.trees, treeId));
980
991
  markIndexUpdate(this.staging, { workdir: true });
@@ -986,6 +997,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
986
997
  trackedBefore,
987
998
  keptOut,
988
999
  sparse,
1000
+ undefined,
1001
+ new Set(fsmKept.keys()),
989
1002
  );
990
1003
  // check_updates: the entries written carry the stat of their new files
991
1004
  await recordWrittenStat(this.staging, worktree, written);
@@ -1188,6 +1201,12 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1188
1201
  });
1189
1202
  const quiet = (path: string) => sparse?.leavesAlone(path) === true;
1190
1203
  const writes = (path: string) => !sparse || sparse.writes(path);
1204
+ // checkout -f's oneway_merge: an entry the file system monitor holds unchanged and the
1205
+ // target keeps is neither stat'ed nor written, and stays in the index as it is
1206
+ const fsmKept =
1207
+ this.force && targetTreeId && this.worktreeAccess
1208
+ ? await fsmonitorKeptEntries(this.trees, this.staging, targetTreeId)
1209
+ : new Map<string, StagingEntry>();
1191
1210
  // --recurse-submodules: unpack-trees' submodule checks and moves (forced: o->reset)
1192
1211
  const subs = this.worktreeAccess
1193
1212
  ? await SubmoduleUnpack.start(this.workingCopy, {
@@ -1272,6 +1291,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1272
1291
  if ((i as { skipWorktree?: boolean } | undefined)?.skipWorktree && sameSide(i, t)) {
1273
1292
  continue;
1274
1293
  }
1294
+ if (fsmKept.has(path) && sameSide(i, t)) continue;
1275
1295
  if (quiet(path)) continue;
1276
1296
  // merged_entry's submodule check (FORCE): the submodule must be able to move
1277
1297
  if (subs && t && !sameSide(i, t)) await subs.mergedRefuses(path, i, t);
@@ -1573,6 +1593,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1573
1593
  // oneway_merge: an unchanged entry keeps its flags and stat, a changed one its
1574
1594
  // skip-worktree bit
1575
1595
  await this.staging.readTree(this.trees as any, targetTreeId, { keepMatching: "flags" });
1596
+ await restoreKeptEntries(this.staging, fsmKept);
1576
1597
  // check_updates: the entries written carry the stat of their new files
1577
1598
  if (worktree) await recordWrittenStat(this.staging, worktree, written);
1578
1599
  await this.writeSwitchedIndex();
@@ -13,6 +13,7 @@ import {
13
13
  GitWorkingCopyConfig,
14
14
  HostPaths,
15
15
  hostRootOf,
16
+ objectStorageFormatByUri,
16
17
  parseConfigKey,
17
18
  setConfigMultivarText,
18
19
  } from "@statewalker/vcs-store-files";
@@ -56,7 +57,11 @@ import {
56
57
  parseBundleListLine,
57
58
  } from "./bundle/index.js";
58
59
  import { coreBool, worktreeModeTrust } from "./core-config.js";
59
- import { defaultInitialBranch } from "./default-branch.js";
60
+ import {
61
+ defaultInitialBranch,
62
+ UnsupportedObjectStorageError,
63
+ unknownObjectStorageFormat,
64
+ } from "./default-branch.js";
60
65
  import { TagOption, toTagMode, toTrackingRefUpdate } from "./fetch-command.js";
61
66
  import { fetchFsckOf } from "./fsck/index.js";
62
67
  import { runPostCheckoutHook } from "./git-hooks.js";
@@ -106,6 +111,7 @@ const CLONE_SETTINGS = [
106
111
  "dissociate",
107
112
  "references",
108
113
  "recurseSubmodules",
114
+ "objectStorageFormat",
109
115
  "shallowSubmodules",
110
116
  "alsoFilterSubmodules",
111
117
  "remoteSubmodules",
@@ -232,6 +238,7 @@ export class CloneCommand extends TransportCommand<CloneResult> {
232
238
  private references: { path: string; required: boolean }[] = [];
233
239
  /** `--recurse-submodules[=<pathspec>]` values, in the order given */
234
240
  private recurseSubmodules: string[] = [];
241
+ private objectStorageFormat?: string;
235
242
  private shallowSubmodules = false;
236
243
  /** `--[no-]also-filter-submodules`; unset: `clone.filterSubmodules` */
237
244
  private alsoFilterSubmodules?: boolean;
@@ -743,6 +750,19 @@ export class CloneCommand extends TransportCommand<CloneResult> {
743
750
  * `protocol.file.allow=always`. Credentials and headers reach a submodule's URL only as
744
751
  * `SubmoduleUpdateCommand.setCredentials` allows (the clone's own origin).
745
752
  */
753
+ /**
754
+ * `--object-storage-format=<format>`: the clone's object storage (git master). `files` is
755
+ * the repository as always and is passed on to the submodules a recursive clone makes; a
756
+ * name git does not know dies as git (`unknown object storage format '<v>'`), and
757
+ * `files://<directory>`, objects outside `objects/`, which we do not read, is refused
758
+ * before anything is fetched (`UnsupportedObjectStorageError`).
759
+ */
760
+ setObjectStorageFormat(format: string): this {
761
+ this.checkCallable();
762
+ this.objectStorageFormat = format;
763
+ return this;
764
+ }
765
+
746
766
  setRecurseSubmodules(recurse: boolean | string[]): this {
747
767
  this.checkCallable();
748
768
  this.recurseSubmodules = recurse === true ? ["."] : recurse === false ? [] : [...recurse];
@@ -842,6 +862,14 @@ export class CloneCommand extends TransportCommand<CloneResult> {
842
862
  if (!this.uri) {
843
863
  throw new InvalidRemoteError("", "URI must be specified for clone");
844
864
  }
865
+ // cmd_clone: the object storage format is checked with the options, before anything
866
+ if (this.objectStorageFormat !== undefined) {
867
+ const unknown = unknownObjectStorageFormat(this.objectStorageFormat, "uri");
868
+ if (unknown) throw new GitApiError(unknown);
869
+ if (objectStorageFormatByUri(this.objectStorageFormat)?.payload !== undefined) {
870
+ throw new UnsupportedObjectStorageError(this.objectStorageFormat);
871
+ }
872
+ }
845
873
  // cmd_clone: what --recurse-submodules adds to the -c values (option_config)
846
874
  const submoduleConfig: string[] = [];
847
875
  if (this.recurseSubmodules.length > 0) {
@@ -908,10 +936,19 @@ export class CloneCommand extends TransportCommand<CloneResult> {
908
936
  const uri = this.uri;
909
937
  // a bare repository's working copy opens it from its git directory
910
938
  const worktree = repositoryPlaceOf(this.workingCopy);
939
+ // a repository whose format we cannot open (an `extensions.objectStorage` payload, which
940
+ // git master clones non-locally) is refused with that format, never "does not exist"
941
+ let formatRefusal: Error | undefined;
911
942
  const isRepositoryPath = await worktree
912
943
  ?.openRepository?.(uri, { checkOwnership: false, commandLineConfig: false })
913
944
  .then((opened) => opened !== undefined)
914
- .catch(() => false);
945
+ .catch((error: unknown) => {
946
+ if (error instanceof Error && error.name === "UnsupportedRepositoryFormatError") {
947
+ formatRefusal = error;
948
+ }
949
+ return false;
950
+ });
951
+ if (formatRefusal) throw new TransportError(`fatal: ${formatRefusal.message}`);
915
952
  // get_repo_path: then a regular file, `<path>.bundle` first (a bundle: the transport reads
916
953
  // it there, remote.<name>.url keeps the path as given)
917
954
  let bundleFile: string | undefined;
@@ -1568,6 +1605,8 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1568
1605
  if (this.shallowSubmodules) update.setDepth(1);
1569
1606
  if (this.remoteSubmodules) update.setRemote(true).setNoFetch(true);
1570
1607
  if (filterSubmodules && this.filterSpec !== undefined) update.setFilter(this.filterSpec);
1608
+ // object_storage_format_to_name: the name alone (`files`), never a payload
1609
+ if (this.objectStorageFormat !== undefined) update.setObjectStorageFormat("files");
1571
1610
  // option_single_branch, settled before (a deepening clone is a single-branch one, a
1572
1611
  // --revision clone none): always passed on, as --single-branch or --no-single-branch
1573
1612
  update.setSingleBranch(
@@ -226,6 +226,25 @@ export class UnsupportedObjectStorageError extends Error {
226
226
  }
227
227
  }
228
228
 
229
+ /**
230
+ * The death of an `--object-storage-format` option git master does not know: clone takes a
231
+ * URI (`files`, `files://<dir>`: `object_storage_format_by_uri`), `submodule add`/`update` a
232
+ * name (`files` alone: `object_storage_format_by_name`, so `files://objs` is unknown there).
233
+ * Undefined when git takes the value.
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * unknownObjectStorageFormat("files://objs", "name"); // "fatal: unknown object storage format 'files://objs'"
238
+ * ```
239
+ */
240
+ export function unknownObjectStorageFormat(
241
+ value: string,
242
+ kind: "uri" | "name",
243
+ ): string | undefined {
244
+ const known = kind === "name" ? value === "files" : objectStorageFormatByUri(value) !== undefined;
245
+ return known ? undefined : `fatal: unknown object storage format '${value}'`;
246
+ }
247
+
229
248
  /** A reinitialization naming another object storage payload: git dies (exit 128). */
230
249
  export class ReinitializeObjectStorageError extends Error {
231
250
  override name = "ReinitializeObjectStorageError";
@@ -3874,12 +3874,26 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
3874
3874
  const trust = worktreeModeTrust(this.workingCopy, worktree);
3875
3875
  const indexTime = this.staging.getUpdateTime();
3876
3876
  const ignoreOf = await this.submoduleIgnoreOf();
3877
+ // the file system monitor, asked as git asks it on reading the index (tweak_fsmonitor,
3878
+ // refresh_fsmonitor): an entry it reported nothing for since its token is unchanged.
3879
+ // diff-files never stats it (run_diff_files, as CE_VALID); diff-index of git 2.5x neither
3880
+ // (check_removed's fake_lstat), while 2.43's check_removed still lstats it (a deleted file
3881
+ // is a deletion there), only ie_match_stat's comparison skipped
3882
+ const fsm = await this.fsmonitorRefresh(this.staging);
3883
+ const fsmValid = (entry: StageEntry) => !!fsm && entry.stage === 0 && fsm.state.isValid(entry);
3884
+ const statsValid = unmergedAsFiles && this.hooks.compatibility === "2.43";
3885
+ const fsmUnstated = (entry: StageEntry) => !statsValid && fsmValid(entry);
3877
3886
  const compareWith = async (
3878
3887
  entry: StageEntry,
3879
3888
  current?: WorktreeEntry | null,
3880
3889
  ): Promise<Side | undefined> => {
3881
3890
  const indexSide: Side = { mode: entry.mode, id: entry.objectId };
3882
- if (entry.skipWorktree || entry.assumeValid) return indexSide;
3891
+ if (entry.skipWorktree || entry.assumeValid || fsmUnstated(entry)) return indexSide;
3892
+ if (fsmValid(entry)) {
3893
+ const file =
3894
+ current !== undefined ? current : await worktree.getEntry(entry.path).catch(() => null);
3895
+ return file ? indexSide : undefined;
3896
+ }
3883
3897
  const ignore = entry.mode === GITLINK ? ignoreOf(entry.path) : undefined;
3884
3898
  if (entry.mode === GITLINK && ignore === "all") return indexSide;
3885
3899
  const result = await compareWithWorktree(worktree, entry, { trust, indexTime }, current);
@@ -3899,6 +3913,9 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
3899
3913
  result.worktreeEntry?.isDirectory
3900
3914
  ) {
3901
3915
  const found = await readSubmoduleDirt(worktree, entry.path, ignore !== "none");
3916
+ for (const line of found.unreadable ?? []) {
3917
+ if (!this.configWarnings.includes(line)) this.configWarnings.push(line);
3918
+ }
3902
3919
  if (found.modified) dirt.modified = true;
3903
3920
  if (ignore === "none" && found.untracked) dirt.untracked = true;
3904
3921
  dirty = !!dirt.modified || !!dirt.untracked;
@@ -3950,6 +3967,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
3950
3967
  !entry.skipWorktree &&
3951
3968
  !entry.assumeValid &&
3952
3969
  entry.mode !== GITLINK &&
3970
+ !fsmUnstated(entry) &&
3953
3971
  this.matches(entry.path);
3954
3972
  for await (const { item: entry, current } of withWorktreeEntries(
3955
3973
  worktree,
@@ -12,10 +12,12 @@
12
12
  * .callOutput();
13
13
  * ```
14
14
  *
15
- * The formats are git's user formats (`format:`, `tformat:`, a text with `%`, a `pretty.<name>`
16
- * alias) and the builtin `reference`; the other builtin formats (`medium`, `oneline`, ...) are
17
- * refused. Each commit is formatted by `git log`'s pretty engine with no configuration of its
18
- * own: `log.*` settings do not apply, as format-rev starts from a fresh `rev_info`.
15
+ * The formats are git's: user formats (`format:`, `tformat:`, a text with `%`, a `pretty.<name>`
16
+ * alias) and the builtin ones (`reference`, `oneline`, `medium`, `short`, `full`, `fuller`,
17
+ * `raw`, `email`, `mboxrd`), the latter as pretty.c's `pretty_print_commit` prints them: no
18
+ * `commit <id>` line (log-tree's), no notes, tabs kept, a mail's subject without `[PATCH]`.
19
+ * Each commit is formatted by `git log`'s pretty engine with no configuration of its own:
20
+ * `log.*` settings do not apply, as format-rev starts from a fresh `rev_info`.
19
21
  */
20
22
 
21
23
  import type { ObjectId } from "@statewalker/vcs-core";
@@ -27,6 +29,9 @@ import { PlumbingCommand, PlumbingError } from "./plumbing-command.js";
27
29
  /** `--stdin-mode`: lines of revisions, or running text holding object ids. */
28
30
  export type FormatRevStdinMode = "text" | "revs";
29
31
 
32
+ /** A format as get_commit_format reads it: a user format, or a builtin `CMIT_FMT_*` one. */
33
+ type Pretty = { format: string; date?: string; builtin?: never } | { builtin: string };
34
+
30
35
  /** A builtin format git's get_commit_format knows, with its default date mode. */
31
36
  const BUILTIN_USER_FORMATS: Record<string, { format: string; date?: string }> = {
32
37
  reference: { format: "%C(auto)%h (%s, %ad)", date: "short" },
@@ -192,7 +197,7 @@ export class FormatRevCommand extends PlumbingCommand {
192
197
  }
193
198
 
194
199
  /** get_commit_format: the user format and its date mode. */
195
- private prettyOf(format: string, depth = 0): { format: string; date?: string } {
200
+ private prettyOf(format: string, depth = 0): Pretty {
196
201
  if (format.startsWith("format:")) return { format: format.slice(7) };
197
202
  if (format.startsWith("tformat:")) return { format: format.slice(8) };
198
203
  if (format.includes("%")) return { format };
@@ -202,19 +207,30 @@ export class FormatRevCommand extends PlumbingCommand {
202
207
  const alias = RemoteConfigStore.from(this.workingCopy).value(`pretty.${format}`);
203
208
  if (alias !== undefined) return this.prettyOf(alias, depth + 1);
204
209
  }
205
- if (BUILTIN_OTHER.has(format))
206
- throw new PlumbingError(`fatal: format-rev: the '${format}' format is not supported`);
210
+ if (BUILTIN_OTHER.has(format)) return { builtin: format };
207
211
  throw new PlumbingError(`fatal: invalid --pretty format: ${format}`);
208
212
  }
209
213
 
210
214
  /** pretty_print_commit of one commit (with its notes when the format shows `%N`). */
211
- private async formatOne(
212
- id: ObjectId,
213
- pretty: { format: string; date?: string },
214
- ): Promise<string | undefined> {
215
+ private async formatOne(id: ObjectId, pretty: Pretty): Promise<string | undefined> {
215
216
  const log = new LogCommand(this.workingCopy).setNoWalk([{ id }]).setLogConfig(false);
216
- const wantsNotes = /%N/.test(pretty.format);
217
217
  try {
218
+ if (pretty.builtin !== undefined) {
219
+ // pretty_print_commit with format-rev's context: fmt_output_email_subject of a
220
+ // rev_info without a subject prefix, encode_email_headers off, no mailmap, and the
221
+ // default date mode of a fresh rev_info (`log.date` is never read)
222
+ return decodeGitPath(
223
+ await log.callBytes({
224
+ pretty: pretty.builtin,
225
+ prettyOnly: true,
226
+ notes: false,
227
+ mailmap: false,
228
+ date: "default",
229
+ mail: { subject: () => "Subject: ", encodeHeaders: false },
230
+ }),
231
+ );
232
+ }
233
+ const wantsNotes = /%N/.test(pretty.format);
218
234
  return decodeGitPath(
219
235
  await log.callBytes({
220
236
  pretty: `format:${pretty.format}`,
@@ -0,0 +1,121 @@
1
+ /**
2
+ * git's builtin file system monitor daemon asked over a `MessagePort` (fsmonitor-ipc.c's
3
+ * `fsmonitor_ipc__send_query` over simple-ipc): the request is the token, the answer the new
4
+ * token and the changed paths, both sent as pkt-lines ended by a flush packet.
5
+ *
6
+ * ```typescript
7
+ * const port = await environment.openIpcPort({ service: "fsmonitor--daemon", path });
8
+ * const answer = await queryFsmonitorDaemon(port, "builtin:fake");
9
+ * // answer: "<token>\0<path>\0<path>\0..." as the daemon wrote it, or undefined on failure
10
+ * ```
11
+ *
12
+ * The protocol code never sees a socket: the port speaks webrun-rpc's stream tier (one
13
+ * stream per port, bounded both ways), whatever carries it (a Unix socket through
14
+ * `connectSocketPort` of `@statewalker/vcs-utils-node`, a `MessageChannel`, a worker).
15
+ */
16
+
17
+ import { duplexOverPort } from "@statewalker/webrun-rpc";
18
+
19
+ /** git's `LARGE_PACKET_DATA_MAX`: the largest payload of one pkt-line. */
20
+ const LARGE_PACKET_DATA_MAX = 65520 - 4;
21
+
22
+ /** The daemon's socket in the git directory (`fsmonitor_ipc__get_default_path`). */
23
+ export const FSMONITOR_DAEMON_IPC_NAME = "fsmonitor--daemon.ipc";
24
+
25
+ const hex = (n: number) => n.toString(16).padStart(4, "0");
26
+
27
+ /**
28
+ * `write_packetized_from_buf_no_flush` then `packet_flush`: `payload` as pkt-lines of at
29
+ * most {@link LARGE_PACKET_DATA_MAX} bytes (none for an empty payload), then `0000`.
30
+ */
31
+ export function encodePacketized(payload: Uint8Array): Uint8Array {
32
+ const lines = Math.ceil(payload.byteLength / LARGE_PACKET_DATA_MAX);
33
+ const out = new Uint8Array(payload.byteLength + lines * 4 + 4);
34
+ let at = 0;
35
+ for (let from = 0; from < payload.byteLength; from += LARGE_PACKET_DATA_MAX) {
36
+ const chunk = payload.subarray(from, from + LARGE_PACKET_DATA_MAX);
37
+ for (const c of hex(chunk.byteLength + 4)) out[at++] = c.charCodeAt(0);
38
+ out.set(chunk, at);
39
+ at += chunk.byteLength;
40
+ }
41
+ for (let i = 0; i < 4; i++) out[at++] = 0x30;
42
+ return out;
43
+ }
44
+
45
+ /**
46
+ * Reads pkt-lines from `chunks` up to the first flush packet (`read_packetized_to_strbuf`):
47
+ * their payloads joined, or undefined when the stream ends first or a length is malformed.
48
+ */
49
+ async function readPacketized(chunks: AsyncIterator<Uint8Array>): Promise<Uint8Array | undefined> {
50
+ let buffer = new Uint8Array(0);
51
+ const parts: Uint8Array[] = [];
52
+ let size = 0;
53
+ const fill = async (need: number): Promise<boolean> => {
54
+ while (buffer.byteLength < need) {
55
+ const next = await chunks.next();
56
+ if (next.done) return false;
57
+ const joined = new Uint8Array(buffer.byteLength + next.value.byteLength);
58
+ joined.set(buffer);
59
+ joined.set(next.value, buffer.byteLength);
60
+ buffer = joined;
61
+ }
62
+ return true;
63
+ };
64
+ for (;;) {
65
+ if (!(await fill(4))) return undefined;
66
+ let length = 0;
67
+ for (let i = 0; i < 4; i++) {
68
+ const digit = Number.parseInt(String.fromCharCode(buffer[i] as number), 16);
69
+ if (Number.isNaN(digit)) return undefined;
70
+ length = length * 16 + digit;
71
+ }
72
+ if (length === 0) break;
73
+ // a delimiter or response-end packet, or a length shorter than its header: protocol error
74
+ if (length < 4) return undefined;
75
+ if (!(await fill(length))) return undefined;
76
+ const payload = buffer.slice(4, length);
77
+ parts.push(payload);
78
+ size += payload.byteLength;
79
+ buffer = buffer.subarray(length);
80
+ }
81
+ const out = new Uint8Array(size);
82
+ let at = 0;
83
+ for (const part of parts) {
84
+ out.set(part, at);
85
+ at += part.byteLength;
86
+ }
87
+ return out;
88
+ }
89
+
90
+ /**
91
+ * Sends `token` to the daemon behind `port` and returns its answer (the new token, a NUL,
92
+ * then the changed paths, each ended by a NUL); undefined when the exchange fails (the
93
+ * stream fails or ends before the answer's flush packet), as git's
94
+ * `ipc_client_send_command_to_connection` fails. The port is closed afterwards.
95
+ */
96
+ export async function queryFsmonitorDaemon(
97
+ port: MessagePort,
98
+ token: string,
99
+ ): Promise<Uint8Array | undefined> {
100
+ let answered: () => void = () => {};
101
+ const done = new Promise<void>((resolve) => {
102
+ answered = resolve;
103
+ });
104
+ // as git's client: the request and its flush, then the connection held open (no
105
+ // half-close) until the answer is read
106
+ async function* request() {
107
+ yield encodePacketized(new TextEncoder().encode(token));
108
+ await done;
109
+ }
110
+ const output = duplexOverPort(port)(request());
111
+ port.start();
112
+ try {
113
+ return await readPacketized(output);
114
+ } catch {
115
+ return undefined;
116
+ } finally {
117
+ answered();
118
+ await output.return(undefined).catch(() => undefined);
119
+ port.close();
120
+ }
121
+ }
@@ -103,6 +103,7 @@ export async function refreshFsmonitor(
103
103
  if (done && done.owner === options.owner) return done.run;
104
104
  }
105
105
  const nanotime = options.nanotime ?? (() => BigInt(Date.now()) * 1_000_000n);
106
+ const added = !state;
106
107
  if (!state) {
107
108
  // add_fsmonitor: a V1-like token for now, every entry dirty, the index changed
108
109
  state = new FsmonitorState(String(nanotime()));
@@ -112,7 +113,7 @@ export async function refreshFsmonitor(
112
113
  const run: FsmonitorRun = { state, untrackedPaths: [], warnings: [] };
113
114
  runs.set(state, { owner: options.owner, run });
114
115
  state.hasRun = true;
115
- await refresh(run, mode, options, nanotime);
116
+ await refresh(run, mode, options, nanotime, added);
116
117
  // the untracked cache in memory loses the reported directories (refresh_fsmonitor's
117
118
  // untracked_cache_invalidate_trimmed_path), carried by whatever writes the index next:
118
119
  // the new token must never be written beside directories the monitor reported
@@ -154,6 +155,7 @@ async function refresh(
154
155
  mode: Exclude<FsmonitorMode, { kind: "disabled" }>,
155
156
  options: RefreshFsmonitorOptions,
156
157
  nanotime: () => bigint,
158
+ added: boolean,
157
159
  ): Promise<void> {
158
160
  const { state } = run;
159
161
  let result: Uint8Array | undefined;
@@ -161,7 +163,8 @@ async function refresh(
161
163
  let bol = 0;
162
164
  let trivial = false;
163
165
  if (mode.kind === "ipc") {
164
- result = await ask(options, { mode: "ipc", token: state.token });
166
+ // add_fsmonitor leaves no token: the daemon is asked since "builtin:fake"
167
+ result = await ask(options, { mode: "ipc", token: added ? "builtin:fake" : state.token });
165
168
  if (result) {
166
169
  token = cString(result, 0);
167
170
  bol = token.length + 1;
@@ -287,6 +290,8 @@ function onPath(
287
290
  run.state.markInvalid(e);
288
291
  count++;
289
292
  }
293
+ // a sparse index's directory entry in the cone (held apart from the expanded entries)
294
+ if (run.state.markSparseDirectoriesInvalid(prefix)) count++;
290
295
  };
291
296
  if (name.endsWith("/")) {
292
297
  cone(name);
@@ -7,8 +7,8 @@
7
7
  * an empty value clearing the list. `GIT_HTTP_USER_AGENT`, `GIT_HTTP_MAX_RETRIES`,
8
8
  * `GIT_HTTP_RETRY_AFTER` and `GIT_HTTP_MAX_RETRY_TIME` override the configuration.
9
9
  *
10
- * Read here: `extraHeader`, `userAgent`, `followRedirects`, `emptyAuth`, `maxRetries`,
11
- * `retryAfter`, `maxRetryTime`. TLS, proxy, cookie, version and speed keys are the host
10
+ * Read here: `extraHeader`, `userAgent`, `followRedirects`, `emptyAuth`, `proactiveAuth`
11
+ * (2.46+), `maxRetries`, `retryAfter`, `maxRetryTime`. TLS, proxy, cookie, version and speed keys are the host
12
12
  * `fetch`'s business and are not read.
13
13
  *
14
14
  * @example
@@ -31,6 +31,8 @@ import type { RemoteConfigStore } from "../remote-config/index.js";
31
31
  export interface HttpConfigOptions {
32
32
  /** As git 2.43: no retries on 429 (`http.maxRetries` came with 2.52) */
33
33
  compatibility?: "2.43" | "2.56";
34
+ /** git's `warning:` lines about the configuration (`Unknown value for http.proactiveauth`) */
35
+ onWarning?(line: string): void;
34
36
  }
35
37
 
36
38
  /**
@@ -76,6 +78,16 @@ export function httpClientSettingsOf(
76
78
  case "emptyauth":
77
79
  settings.emptyAuth = value === "auto" ? "auto" : bool(key, value);
78
80
  break;
81
+ case "proactiveauth":
82
+ // git 2.46: an unknown value warns and leaves the setting as it was
83
+ if (options.compatibility === "2.43") break;
84
+ if (value === undefined) throw missingValue(key);
85
+ if (value === "auto" || value === "basic" || value === "none") {
86
+ settings.proactiveAuth = value;
87
+ } else {
88
+ options.onWarning?.("warning: Unknown value for http.proactiveauth");
89
+ }
90
+ break;
79
91
  case "followredirects":
80
92
  settings.followRedirects =
81
93
  value === "initial" ? "initial" : bool(key, value) ? "always" : "none";
@@ -43,6 +43,7 @@ export * from "./fmt-merge-msg-command.js";
43
43
  export * from "./format-patch-command.js";
44
44
  export * from "./format-rev-command.js";
45
45
  export * from "./fsck/index.js";
46
+ export * from "./fsmonitor-ipc.js";
46
47
  export * from "./gc-command.js";
47
48
  export * from "./git-describe.js";
48
49
  export * from "./git-hooks.js";
@@ -112,6 +113,7 @@ export * from "./pack-refs-command.js";
112
113
  export { type PatchIdTextOptions, patchIdsOfPatchText } from "./patch-id.js";
113
114
  export * from "./patch-id-command.js";
114
115
  export * from "./plumbing-command.js";
116
+ export { CorruptTreeError } from "./plumbing-shared.js";
115
117
  export * from "./pretty-format.js";
116
118
  export * from "./promisor-remote.js";
117
119
  export * from "./promisor-remote-reply.js";
@@ -216,6 +216,12 @@ export interface LogOutputOptions {
216
216
  * `mergetag`'s, after the commit's header
217
217
  */
218
218
  showSignature?: boolean;
219
+ /**
220
+ * pretty.c's `pretty_print_commit` alone, as `git format-rev` prints a commit: no
221
+ * `commit <id>` (or mail `From <id>`) header line, no separator between commits, no notes,
222
+ * and tabs not expanded (format-rev's pretty context is zeroed: `expand_tabs_in_log` 0)
223
+ */
224
+ prettyOnly?: boolean;
219
225
  }
220
226
 
221
227
  /** What `git format-patch` adds to the `email` format (log-tree.c, pretty.c). */
@@ -913,6 +919,7 @@ export class LogPrinter {
913
919
  this.verboseHeader = !options.diffTree || prettyGiven;
914
920
  const pretty = options.oneline ? "oneline" : (options.pretty ?? host.config("format.pretty"));
915
921
  this.format = parseCommitFormat(pretty, host);
922
+ if (options.prettyOnly) this.format = { ...this.format, expandTabs: 0 };
916
923
  const dateSpec = options.date ?? host.config("log.date");
917
924
  this.dateMode = dateSpec
918
925
  ? parseDateMode(dateSpec)
@@ -1406,6 +1413,10 @@ export class LogPrinter {
1406
1413
  log.pending = false;
1407
1414
  const { fmt } = this.format;
1408
1415
  if (this.options.noCommitId) return;
1416
+ if (this.options.prettyOnly) {
1417
+ this.out.text(await this.prettyPrint(entry, ""));
1418
+ return;
1419
+ }
1409
1420
  if (!this.verboseHeader) {
1410
1421
  // show_log without verbose_header: the id (and parents), the line termination
1411
1422
  if (this.graph) this.out.text(this.graph.showCommit());