@statewalker/vcs-commands 0.13.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 (304) 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/archive-command.d.ts +6 -2
  5. package/dist/commands/archive/archive-command.d.ts.map +1 -1
  6. package/dist/commands/archive/remote-archive-command.d.ts +27 -2
  7. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -1
  8. package/dist/commands/archive/upload-archive-writer.d.ts +11 -5
  9. package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -1
  10. package/dist/commands/branch-command.d.ts +14 -2
  11. package/dist/commands/branch-command.d.ts.map +1 -1
  12. package/dist/commands/bundle/bundle-format.d.ts +6 -1
  13. package/dist/commands/bundle/bundle-format.d.ts.map +1 -1
  14. package/dist/commands/bundle/bundle-uri-host.d.ts +12 -1
  15. package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -1
  16. package/dist/commands/bundle/bundle-uri.d.ts +7 -1
  17. package/dist/commands/bundle/bundle-uri.d.ts.map +1 -1
  18. package/dist/commands/bundle/bundle-verify.d.ts +4 -1
  19. package/dist/commands/bundle/bundle-verify.d.ts.map +1 -1
  20. package/dist/commands/cat-file/batch-format.d.ts +8 -12
  21. package/dist/commands/cat-file/batch-format.d.ts.map +1 -1
  22. package/dist/commands/cat-file/cat-file-command.d.ts +39 -5
  23. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
  24. package/dist/commands/check-ignore-command.d.ts.map +1 -1
  25. package/dist/commands/checkout-command.d.ts +4 -0
  26. package/dist/commands/checkout-command.d.ts.map +1 -1
  27. package/dist/commands/checkout-paths.d.ts +9 -0
  28. package/dist/commands/checkout-paths.d.ts.map +1 -1
  29. package/dist/commands/cherry-pick-command.d.ts +3 -0
  30. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  31. package/dist/commands/clean-interactive.d.ts +0 -9
  32. package/dist/commands/clean-interactive.d.ts.map +1 -1
  33. package/dist/commands/clone-command.d.ts +17 -0
  34. package/dist/commands/clone-command.d.ts.map +1 -1
  35. package/dist/commands/column/column-config.d.ts +23 -0
  36. package/dist/commands/column/column-config.d.ts.map +1 -0
  37. package/dist/commands/column/column-layout.d.ts +129 -0
  38. package/dist/commands/column/column-layout.d.ts.map +1 -0
  39. package/dist/commands/column/index.d.ts +3 -0
  40. package/dist/commands/column/index.d.ts.map +1 -0
  41. package/dist/commands/column-command.d.ts +59 -0
  42. package/dist/commands/column-command.d.ts.map +1 -0
  43. package/dist/commands/comment-char-config.d.ts +15 -0
  44. package/dist/commands/comment-char-config.d.ts.map +1 -1
  45. package/dist/commands/commit-command.d.ts +30 -2
  46. package/dist/commands/commit-command.d.ts.map +1 -1
  47. package/dist/commands/config-command.d.ts +12 -0
  48. package/dist/commands/config-command.d.ts.map +1 -1
  49. package/dist/commands/credential-helper.d.ts +214 -0
  50. package/dist/commands/credential-helper.d.ts.map +1 -0
  51. package/dist/commands/default-branch.d.ts +33 -3
  52. package/dist/commands/default-branch.d.ts.map +1 -1
  53. package/dist/commands/diff-color-config.d.ts +4 -0
  54. package/dist/commands/diff-color-config.d.ts.map +1 -1
  55. package/dist/commands/diff-command.d.ts +12 -0
  56. package/dist/commands/diff-command.d.ts.map +1 -1
  57. package/dist/commands/fast-export/fast-export-command.d.ts +89 -2
  58. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -1
  59. package/dist/commands/fast-export/fast-import-command.d.ts +113 -8
  60. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -1
  61. package/dist/commands/fast-export/fast-stream-support.d.ts +0 -9
  62. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -1
  63. package/dist/commands/fetch-command.d.ts +23 -1
  64. package/dist/commands/fetch-command.d.ts.map +1 -1
  65. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
  66. package/dist/commands/git-hooks.d.ts +31 -3
  67. package/dist/commands/git-hooks.d.ts.map +1 -1
  68. package/dist/commands/history-command.d.ts +173 -7
  69. package/dist/commands/history-command.d.ts.map +1 -1
  70. package/dist/commands/index-host.d.ts +19 -0
  71. package/dist/commands/index-host.d.ts.map +1 -1
  72. package/dist/commands/index-refresh.d.ts +36 -0
  73. package/dist/commands/index-refresh.d.ts.map +1 -0
  74. package/dist/commands/index.d.ts +9 -0
  75. package/dist/commands/index.d.ts.map +1 -1
  76. package/dist/commands/index.js +7 -6
  77. package/dist/commands/init-command.d.ts +20 -0
  78. package/dist/commands/init-command.d.ts.map +1 -1
  79. package/dist/commands/local-transport.d.ts +40 -2
  80. package/dist/commands/local-transport.d.ts.map +1 -1
  81. package/dist/commands/log-command.d.ts +7 -0
  82. package/dist/commands/log-command.d.ts.map +1 -1
  83. package/dist/commands/log-output.d.ts +11 -0
  84. package/dist/commands/log-output.d.ts.map +1 -1
  85. package/dist/commands/ls-tree-command.d.ts +10 -0
  86. package/dist/commands/ls-tree-command.d.ts.map +1 -1
  87. package/dist/commands/maintenance-schedule-command.d.ts +122 -0
  88. package/dist/commands/maintenance-schedule-command.d.ts.map +1 -0
  89. package/dist/commands/merge-command.d.ts +13 -1
  90. package/dist/commands/merge-command.d.ts.map +1 -1
  91. package/dist/commands/merge-index-command.d.ts +42 -0
  92. package/dist/commands/merge-index-command.d.ts.map +1 -0
  93. package/dist/commands/merge-one-file.d.ts +129 -0
  94. package/dist/commands/merge-one-file.d.ts.map +1 -0
  95. package/dist/commands/merge-support.d.ts +40 -4
  96. package/dist/commands/merge-support.d.ts.map +1 -1
  97. package/dist/commands/object-disk-info.d.ts +35 -0
  98. package/dist/commands/object-disk-info.d.ts.map +1 -0
  99. package/dist/commands/octopus-merge.d.ts +3 -3
  100. package/dist/commands/octopus-merge.d.ts.map +1 -1
  101. package/dist/commands/plumbing-input.d.ts.map +1 -1
  102. package/dist/commands/promisor-remote-reply.d.ts +31 -4
  103. package/dist/commands/promisor-remote-reply.d.ts.map +1 -1
  104. package/dist/commands/promisor-remote.d.ts +8 -1
  105. package/dist/commands/promisor-remote.d.ts.map +1 -1
  106. package/dist/commands/pull-command.d.ts +55 -7
  107. package/dist/commands/pull-command.d.ts.map +1 -1
  108. package/dist/commands/push-command.d.ts +18 -1
  109. package/dist/commands/push-command.d.ts.map +1 -1
  110. package/dist/commands/range-diff/range-diff-command.d.ts +37 -1
  111. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -1
  112. package/dist/commands/rebase-command.d.ts +13 -1
  113. package/dist/commands/rebase-command.d.ts.map +1 -1
  114. package/dist/commands/ref-filter/for-each-ref-command.d.ts +3 -2
  115. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -1
  116. package/dist/commands/ref-filter/index.d.ts +1 -0
  117. package/dist/commands/ref-filter/index.d.ts.map +1 -1
  118. package/dist/commands/ref-filter/peel-limit.d.ts +8 -0
  119. package/dist/commands/ref-filter/peel-limit.d.ts.map +1 -0
  120. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -1
  121. package/dist/commands/ref-filter/ref-format.d.ts +26 -1
  122. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -1
  123. package/dist/commands/ref-filter/ref-listing-command.d.ts +9 -0
  124. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -1
  125. package/dist/commands/remote-transport.d.ts +27 -0
  126. package/dist/commands/remote-transport.d.ts.map +1 -1
  127. package/dist/commands/repack-command.d.ts +18 -2
  128. package/dist/commands/repack-command.d.ts.map +1 -1
  129. package/dist/commands/repo-command.d.ts +2 -7
  130. package/dist/commands/repo-command.d.ts.map +1 -1
  131. package/dist/commands/reset-command.d.ts +4 -1
  132. package/dist/commands/reset-command.d.ts.map +1 -1
  133. package/dist/commands/restore-command.d.ts.map +1 -1
  134. package/dist/commands/rev-list-command.d.ts +65 -0
  135. package/dist/commands/rev-list-command.d.ts.map +1 -1
  136. package/dist/commands/revert-command.d.ts +3 -0
  137. package/dist/commands/revert-command.d.ts.map +1 -1
  138. package/dist/commands/revision-filenames.d.ts.map +1 -1
  139. package/dist/commands/revision-range.d.ts +17 -0
  140. package/dist/commands/revision-range.d.ts.map +1 -1
  141. package/dist/commands/revision-resolver.d.ts +12 -0
  142. package/dist/commands/revision-resolver.d.ts.map +1 -1
  143. package/dist/commands/serve-repository.d.ts +21 -4
  144. package/dist/commands/serve-repository.d.ts.map +1 -1
  145. package/dist/commands/served-lazy-fetch.d.ts +61 -0
  146. package/dist/commands/served-lazy-fetch.d.ts.map +1 -0
  147. package/dist/commands/signing.d.ts +37 -4
  148. package/dist/commands/signing.d.ts.map +1 -1
  149. package/dist/commands/split-cmdline.d.ts +6 -0
  150. package/dist/commands/split-cmdline.d.ts.map +1 -0
  151. package/dist/commands/status-color-config.d.ts +33 -0
  152. package/dist/commands/status-color-config.d.ts.map +1 -0
  153. package/dist/commands/status-command.d.ts +15 -0
  154. package/dist/commands/status-command.d.ts.map +1 -1
  155. package/dist/commands/status-format.d.ts +46 -4
  156. package/dist/commands/status-format.d.ts.map +1 -1
  157. package/dist/commands/tag-command.d.ts +15 -1
  158. package/dist/commands/tag-command.d.ts.map +1 -1
  159. package/dist/commands/tree-restore.d.ts +14 -0
  160. package/dist/commands/tree-restore.d.ts.map +1 -1
  161. package/dist/commands/verify-command.d.ts +22 -2
  162. package/dist/commands/verify-command.d.ts.map +1 -1
  163. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  164. package/dist/commands/worktree-overwrite-checks.d.ts +31 -6
  165. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  166. package/dist/{commands-CPceUCP2.js → commands-DT3VEv50.js} +15168 -16842
  167. package/dist/errors/commit-errors.d.ts +37 -1
  168. package/dist/errors/commit-errors.d.ts.map +1 -1
  169. package/dist/errors/git-api-error.d.ts +6 -0
  170. package/dist/errors/git-api-error.d.ts.map +1 -1
  171. package/dist/errors/index.js +44 -3
  172. package/dist/{fsck-tbrPZX2q.js → fsck-BZ508Elg.js} +2 -2
  173. package/dist/git-command.d.ts +33 -1
  174. package/dist/git-command.d.ts.map +1 -1
  175. package/dist/git.d.ts +104 -1
  176. package/dist/git.d.ts.map +1 -1
  177. package/dist/index.js +8 -7
  178. package/dist/{remote-transport-C0OSJtor.js → local-transport-D98U6p4d.js} +228 -692
  179. package/dist/{maintenance-run-command-UiSIaeP8.js → maintenance-run-command-DZFnbnbo.js} +2366 -108
  180. package/dist/remote-config/remote-config-store.d.ts +6 -0
  181. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  182. package/dist/remote-transport-zvSqwpOB.js +4865 -0
  183. package/dist/results/cherry-pick-result.d.ts +4 -3
  184. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  185. package/dist/results/diff-output.d.ts +7 -0
  186. package/dist/results/diff-output.d.ts.map +1 -1
  187. package/dist/results/diff-words.d.ts +14 -3
  188. package/dist/results/diff-words.d.ts.map +1 -1
  189. package/dist/results/index.js +1 -1
  190. package/dist/results/line-prefix-sink.d.ts +50 -0
  191. package/dist/results/line-prefix-sink.d.ts.map +1 -0
  192. package/dist/results/merge-result.d.ts +4 -3
  193. package/dist/results/merge-result.d.ts.map +1 -1
  194. package/dist/results/rebase-result.d.ts +5 -0
  195. package/dist/results/rebase-result.d.ts.map +1 -1
  196. package/dist/results/revert-result.d.ts +4 -3
  197. package/dist/results/revert-result.d.ts.map +1 -1
  198. package/dist/{results-CkS1p1CH.js → results-rF81cQse.js} +1788 -247
  199. package/dist/transport-command.d.ts +13 -0
  200. package/dist/transport-command.d.ts.map +1 -1
  201. package/package.json +21 -13
  202. package/src/commands/add-command.ts +15 -2
  203. package/src/commands/add-patch/patch-backend.ts +6 -44
  204. package/src/commands/archive/archive-command.ts +7 -3
  205. package/src/commands/archive/remote-archive-command.ts +45 -4
  206. package/src/commands/archive/upload-archive-writer.ts +34 -22
  207. package/src/commands/branch-command.ts +57 -4
  208. package/src/commands/bundle/bundle-format.ts +10 -2
  209. package/src/commands/bundle/bundle-uri-host.ts +71 -11
  210. package/src/commands/bundle/bundle-uri.ts +11 -4
  211. package/src/commands/bundle/bundle-verify.ts +4 -1
  212. package/src/commands/cat-file/batch-format.ts +17 -18
  213. package/src/commands/cat-file/cat-file-command.ts +182 -48
  214. package/src/commands/check-ignore-command.ts +110 -21
  215. package/src/commands/checkout-command.ts +149 -21
  216. package/src/commands/checkout-index-command.ts +2 -1
  217. package/src/commands/checkout-paths.ts +13 -0
  218. package/src/commands/cherry-pick-command.ts +9 -0
  219. package/src/commands/clean-interactive.ts +20 -74
  220. package/src/commands/clone-command.ts +102 -11
  221. package/src/commands/column/column-config.ts +63 -0
  222. package/src/commands/column/column-layout.ts +396 -0
  223. package/src/commands/column/index.ts +2 -0
  224. package/src/commands/column-command.ts +171 -0
  225. package/src/commands/comment-char-config.ts +42 -0
  226. package/src/commands/commit-command.ts +93 -18
  227. package/src/commands/config-command.ts +28 -0
  228. package/src/commands/credential-helper.ts +807 -0
  229. package/src/commands/default-branch.ts +57 -5
  230. package/src/commands/diff-color-config.ts +23 -10
  231. package/src/commands/diff-command.ts +25 -2
  232. package/src/commands/fast-export/fast-export-command.ts +661 -35
  233. package/src/commands/fast-export/fast-import-command.ts +694 -94
  234. package/src/commands/fast-export/fast-stream-support.ts +18 -1
  235. package/src/commands/fetch-command.ts +116 -16
  236. package/src/commands/fsck/fsck-object-checks.ts +3 -1
  237. package/src/commands/git-hooks.ts +96 -5
  238. package/src/commands/history-command.ts +952 -20
  239. package/src/commands/index-host.ts +51 -0
  240. package/src/commands/index-refresh.ts +121 -0
  241. package/src/commands/index.ts +9 -0
  242. package/src/commands/init-command.ts +57 -4
  243. package/src/commands/legacy-remotes.ts +4 -20
  244. package/src/commands/local-transport.ts +183 -18
  245. package/src/commands/log-command.ts +39 -1
  246. package/src/commands/log-output.ts +31 -4
  247. package/src/commands/ls-tree-command.ts +20 -12
  248. package/src/commands/maintenance-schedule-command.ts +418 -0
  249. package/src/commands/merge-command.ts +42 -8
  250. package/src/commands/merge-index-command.ts +202 -0
  251. package/src/commands/merge-one-file.ts +451 -0
  252. package/src/commands/merge-support.ts +169 -15
  253. package/src/commands/object-disk-info.ts +169 -0
  254. package/src/commands/octopus-merge.ts +37 -128
  255. package/src/commands/plumbing-input.ts +3 -1
  256. package/src/commands/promisor-remote-reply.ts +338 -56
  257. package/src/commands/promisor-remote.ts +39 -6
  258. package/src/commands/pull-command.ts +173 -27
  259. package/src/commands/push-command.ts +55 -6
  260. package/src/commands/range-diff/range-diff-command.ts +86 -3
  261. package/src/commands/read-tree-command.ts +2 -2
  262. package/src/commands/rebase-command.ts +46 -1
  263. package/src/commands/ref-filter/for-each-ref-command.ts +4 -3
  264. package/src/commands/ref-filter/index.ts +1 -0
  265. package/src/commands/ref-filter/peel-limit.ts +7 -0
  266. package/src/commands/ref-filter/ref-filter.ts +68 -7
  267. package/src/commands/ref-filter/ref-format.ts +85 -11
  268. package/src/commands/ref-filter/ref-listing-command.ts +30 -0
  269. package/src/commands/remote-command.ts +2 -2
  270. package/src/commands/remote-transport.ts +66 -3
  271. package/src/commands/repack-command.ts +75 -9
  272. package/src/commands/repo-command.ts +6 -70
  273. package/src/commands/reset-command.ts +11 -1
  274. package/src/commands/restore-command.ts +1 -0
  275. package/src/commands/rev-list-command.ts +205 -3
  276. package/src/commands/revert-command.ts +9 -0
  277. package/src/commands/revision-filenames.ts +32 -4
  278. package/src/commands/revision-range.ts +2 -2
  279. package/src/commands/revision-resolver.ts +21 -1
  280. package/src/commands/serve-repository.ts +42 -11
  281. package/src/commands/served-lazy-fetch.ts +164 -0
  282. package/src/commands/signing.ts +103 -12
  283. package/src/commands/split-cmdline.ts +32 -0
  284. package/src/commands/status-color-config.ts +92 -0
  285. package/src/commands/status-command.ts +50 -2
  286. package/src/commands/status-format.ts +198 -50
  287. package/src/commands/tag-command.ts +57 -2
  288. package/src/commands/tree-restore.ts +17 -0
  289. package/src/commands/verify-command.ts +84 -12
  290. package/src/commands/worktree-add-command.ts +2 -0
  291. package/src/commands/worktree-overwrite-checks.ts +75 -14
  292. package/src/errors/commit-errors.ts +52 -2
  293. package/src/errors/git-api-error.ts +7 -0
  294. package/src/git-command.ts +105 -4
  295. package/src/git.ts +153 -0
  296. package/src/remote-config/remote-config-store.ts +16 -0
  297. package/src/results/cherry-pick-result.ts +4 -3
  298. package/src/results/diff-output.ts +8 -0
  299. package/src/results/diff-words.ts +160 -32
  300. package/src/results/line-prefix-sink.ts +102 -0
  301. package/src/results/merge-result.ts +4 -3
  302. package/src/results/rebase-result.ts +5 -0
  303. package/src/results/revert-result.ts +4 -3
  304. package/src/transport-command.ts +79 -3
@@ -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";
@@ -67,35 +71,73 @@ const COULD_NOT_READ =
67
71
  const NOT_A_REPOSITORY = (path: string) =>
68
72
  `fatal: '${path}' does not appear to be a git repository\n${COULD_NOT_READ}`;
69
73
 
74
+ /** Options of {@link createDuplexPair}. */
75
+ export interface DuplexPairOptions {
76
+ /**
77
+ * Bounds what a side holds unread: a `write` returns a promise once this many bytes wait,
78
+ * resolved when the reader took them below it. With a bound, `close` (unlike `end`) also
79
+ * stops a side's reading: waiting and later writes into it reject, as a pipe whose reader
80
+ * is gone. Default: unbounded, every write queued.
81
+ */
82
+ highWaterMark?: number;
83
+ }
84
+
70
85
  /**
71
86
  * A connected pair of in-memory duplex streams: what one side writes, the other reads. `end`
72
87
  * half-closes a side (the other one reads to its end and can still answer); `close` ends it.
73
88
  */
74
- export function createDuplexPair(): [Duplex, Duplex] {
89
+ export function createDuplexPair(options: DuplexPairOptions = {}): [Duplex, Duplex] {
90
+ const highWaterMark = options.highWaterMark;
75
91
  const make = () => {
76
92
  const queue: Uint8Array[] = [];
93
+ let queued = 0;
77
94
  let ended = false;
95
+ let abandoned = false;
78
96
  let wake: (() => void) | undefined;
79
- const push = (chunk: Uint8Array | null) => {
97
+ let writers: Array<{ resolve: () => void; reject: (error: Error) => void }> = [];
98
+ const release = (error?: Error) => {
99
+ const waiting = writers;
100
+ writers = [];
101
+ for (const w of waiting) {
102
+ if (error) w.reject(error);
103
+ else w.resolve();
104
+ }
105
+ };
106
+ const push = (chunk: Uint8Array | null): Promise<void> | undefined => {
80
107
  if (chunk === null) ended = true;
81
- else queue.push(chunk);
108
+ else {
109
+ if (abandoned) return Promise.reject(new Error("the stream's reader stopped"));
110
+ queue.push(chunk);
111
+ queued += chunk.length;
112
+ }
82
113
  wake?.();
83
114
  wake = undefined;
115
+ if (chunk === null || highWaterMark === undefined || queued < highWaterMark) return;
116
+ return new Promise<void>((resolve, reject) => writers.push({ resolve, reject }));
117
+ };
118
+ const abandon = () => {
119
+ if (highWaterMark === undefined) return;
120
+ abandoned = true;
121
+ queue.length = 0;
122
+ queued = 0;
123
+ release(new Error("the stream's reader stopped"));
84
124
  };
85
125
  async function* read(): AsyncGenerator<Uint8Array> {
86
126
  while (true) {
87
127
  const next = queue.shift();
88
128
  if (next) {
129
+ queued -= next.length;
130
+ if (highWaterMark === undefined || queued < highWaterMark) release();
89
131
  yield next;
90
132
  continue;
91
133
  }
92
- if (ended) return;
134
+ if (ended || abandoned) return;
93
135
  await new Promise<void>((resolve) => {
94
136
  wake = resolve;
95
137
  });
96
138
  }
97
139
  }
98
- return { push, read };
140
+ return { push, read, abandon };
99
141
  };
100
142
  const a = make();
101
143
  const b = make();
@@ -114,18 +156,24 @@ export function createDuplexPair(): [Duplex, Duplex] {
114
156
  const left: Duplex = {
115
157
  [Symbol.asyncIterator]: () => a.read()[Symbol.asyncIterator](),
116
158
  write: (data) => {
117
- if (!aClosed) b.push(data.slice());
159
+ if (!aClosed) return b.push(data.slice());
118
160
  },
119
161
  end: endLeft,
120
- close: endLeft,
162
+ close: async () => {
163
+ a.abandon();
164
+ await endLeft();
165
+ },
121
166
  };
122
167
  const right: Duplex = {
123
168
  [Symbol.asyncIterator]: () => b.read()[Symbol.asyncIterator](),
124
169
  write: (data) => {
125
- if (!bClosed) a.push(data.slice());
170
+ if (!bClosed) return a.push(data.slice());
126
171
  },
127
172
  end: endRight,
128
- close: endRight,
173
+ close: async () => {
174
+ b.abandon();
175
+ await endRight();
176
+ },
129
177
  };
130
178
  return [left, right];
131
179
  }
@@ -148,6 +196,23 @@ export async function openLocalRemote(
148
196
  return opened;
149
197
  }
150
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
+
151
216
  /**
152
217
  * Runs `run` over a connection to upload-pack serving a local repository (opened by
153
218
  * {@link openLocalRemote}) with protocol v2, git's default `protocol.version` (v0 when the
@@ -157,18 +222,42 @@ export async function openLocalRemote(
157
222
  export async function withLocalUploadPack<T>(
158
223
  remote: OpenedRepository,
159
224
  run: (connection: UploadPackConnection) => Promise<T>,
160
- 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
+ } = {},
161
244
  ): Promise<T> {
245
+ checkLocalNamespace(options.namespace, (options.protocolVersion ?? 2) === 2);
162
246
  const head = await remote.history.refs.get("HEAD").catch(() => undefined);
163
247
  const settings = serverSettingsOf(remote);
164
248
  const [client, server] = createDuplexPair();
165
- // upload-pack never fetches lazily (GIT_NO_LAZY_FETCH): it reads through the history's
166
- // 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
+ );
167
256
  const serving = (async () =>
168
257
  serveOverDuplex({
169
258
  duplex: server,
170
259
  repository: createRepositoryFacade({
171
- history: historyWithoutLazyFetch(remote.history),
260
+ history,
172
261
  useBitmaps: servedUseBitmaps(remote),
173
262
  sparseFilterPatterns: sparseFilterMatcher,
174
263
  maxTreeDepth: servedMaxTreeDepth(remote),
@@ -200,14 +289,18 @@ export async function withLocalUploadPack<T>(
200
289
  ...(settings.promisorRemoteInfo !== undefined
201
290
  ? { promisorRemoteInfo: settings.promisorRemoteInfo }
202
291
  : {}),
292
+ // uploadpack.packObjectsHook (protected configuration, never the repository's)
293
+ ...(options.packObjectsHook ? { packObjectsHook: options.packObjectsHook } : {}),
203
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 } : {}),
204
297
  }))().finally(() => server.close?.());
205
298
  try {
206
299
  const connection = await openDuplexConnection(client, { closeDuplex: true });
207
300
  try {
208
301
  return await run(connection);
209
302
  } catch (error) {
210
- throw packFailure(error) ?? error;
303
+ throw packFailure(error) ?? (await packObjectsDeath(error, serving)) ?? error;
211
304
  } finally {
212
305
  await connection.close();
213
306
  }
@@ -217,6 +310,38 @@ export async function withLocalUploadPack<T>(
217
310
  }
218
311
  }
219
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
+
220
345
  /**
221
346
  * The lines git prints when upload-pack's pack-objects fails on an object it cannot read
222
347
  * (upload-pack.c's create_pack_file): its own error and death (upload-pack's stderr, which
@@ -425,8 +550,14 @@ export async function withLocalReceivePack<T>(
425
550
  protocolVersion?: 0 | 1 | 2;
426
551
  host?: ReceivePackHost;
427
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;
428
558
  } = {},
429
559
  ): Promise<T> {
560
+ checkLocalNamespace(options.namespace);
430
561
  // receive-pack's enter_repo(path, 0): a repository another user owns is refused (git's
431
562
  // die_upon_dubious_ownership in the child), and the client sees the connection fail
432
563
  try {
@@ -439,8 +570,13 @@ export async function withLocalReceivePack<T>(
439
570
  }
440
571
  const receiveHooks = hooks?.enabled ? scriptReceiveHooks(hooks) : undefined;
441
572
  // the remote's reference-transaction hook on its ref store while receive-pack runs (its
442
- // output goes to the pushing user's stderr directly, not through the side-band)
443
- 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, () =>
444
580
  receiveOver(remote, run, hooks, receiveHooks, options.protocolVersion === 1, options),
445
581
  );
446
582
  }
@@ -511,6 +647,12 @@ export interface ReceivePackHost {
511
647
  * repository reads them as git does
512
648
  */
513
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;
514
656
  }
515
657
 
516
658
  /**
@@ -610,6 +752,8 @@ export async function receivePackSettingsOf(
610
752
  ? { advertiseAtomic: settings.advertiseAtomic }
611
753
  : {}),
612
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 } : {}),
613
757
  // receive.certNonceSeed, receive.certNonceSlop: signed pushes, their signature checked with
614
758
  // the repository's gpg.* through the host's verifier
615
759
  ...(settings.certNonceSeed !== undefined ? { certNonceSeed: settings.certNonceSeed } : {}),
@@ -762,7 +906,11 @@ async function receiveOver<T>(
762
906
  hooks: HookSession | undefined,
763
907
  receiveHooks: ReceivePackHooks | undefined,
764
908
  version1: boolean,
765
- options: { host?: ReceivePackHost; onWarning?: (line: string) => void } = {},
909
+ options: {
910
+ host?: ReceivePackHost;
911
+ onWarning?: (line: string) => void;
912
+ namespace?: string;
913
+ } = {},
766
914
  ): Promise<T> {
767
915
  const [client, server] = createDuplexPair();
768
916
  const host = options.host ?? {};
@@ -783,6 +931,8 @@ async function receiveOver<T>(
783
931
  refStore: createTransportRefStore(remote.history.refs),
784
932
  service: "git-receive-pack",
785
933
  ...(version1 ? { announceVersion1: true } : {}),
934
+ // GIT_NAMESPACE (inherited): the namespace's refs; the hooks get the variable
935
+ ...(options.namespace ? { namespace: options.namespace } : {}),
786
936
  }).finally(() => server.close?.());
787
937
  // receive-pack died (its reference-transaction hook aborted the update): its message on
788
938
  // the shared stderr, then send-pack's, as git's local transport shows them
@@ -967,8 +1117,23 @@ export function httpBackendEnv(
967
1117
  return env;
968
1118
  }
969
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
+
970
1135
  /** {@link httpBackendEnv} of a push its hook context describes (HTTP: it has a request). */
971
- function hookClientEnv(hooks: HookSession, ctx: ReceivePackHookContext | undefined) {
1136
+ function httpEnvOf(hooks: HookSession, ctx: ReceivePackHookContext | undefined) {
972
1137
  return httpBackendEnv(
973
1138
  hooks,
974
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;
@@ -37,6 +37,7 @@ import { decodeGitPath, encodeGitPath, gitCharWidth } from "@statewalker/vcs-uti
37
37
  import { InvalidArgumentError } from "../errors/index.js";
38
38
  import type { DiffColors } from "../results/diff-color.js";
39
39
  import { ChangeType } from "../results/diff-entry.js";
40
+ import { insertLinePrefix } from "../results/line-prefix-sink.js";
40
41
  import { type DateMode, DEFAULT_DATE_MODE, parseDateMode, showDate } from "./date-format.js";
41
42
  import { type DiffOutputFormat, type DiffTextOptions, hasPickaxe } from "./diff-command.js";
42
43
  import { LogGraph } from "./log-graph.js";
@@ -351,11 +352,24 @@ export interface LogOutputHost {
351
352
  entry: LogOutputEntry,
352
353
  parent: ObjectId | undefined,
353
354
  formats: DiffOutputFormat[],
354
- options: { statWidth?: number; follow?: string; fullDiff?: boolean; abbrev?: number },
355
+ options: {
356
+ statWidth?: number;
357
+ follow?: string;
358
+ fullDiff?: boolean;
359
+ abbrev?: number;
360
+ /**
361
+ * diff.c's `diff_line_prefix` (the graph's padding) is inserted by the log: a host
362
+ * may say where with `prefixPoints` (git's word diff leaves it out of most lines);
363
+ * without them the log prefixes every line
364
+ */
365
+ linePrefix?: boolean;
366
+ },
355
367
  ): Promise<{
356
368
  bytes?: Uint8Array;
357
369
  followPath?: string;
358
370
  followChange?: ChangeType.RENAME | ChangeType.COPY;
371
+ /** The offsets in `bytes` where the line prefix goes, ascending */
372
+ prefixPoints?: readonly number[];
359
373
  }>;
360
374
  /**
361
375
  * The combined diff of a merge (`-c`, `--cc`): the paths that differ from every parent,
@@ -376,10 +390,12 @@ export interface LogOutputHost {
376
390
  follow?: string;
377
391
  fullDiff?: boolean;
378
392
  abbrev?: number;
393
+ /** As {@link LogOutputHost.diff}'s */
394
+ linePrefix?: boolean;
379
395
  /** The commits the log has processed before this one (git 2.43 freed their parents) */
380
396
  processed?: ReadonlySet<ObjectId>;
381
397
  },
382
- ): Promise<{ bytes?: Uint8Array; followPath?: string }>;
398
+ ): Promise<{ bytes?: Uint8Array; followPath?: string; prefixPoints?: readonly number[] }>;
383
399
  combinedDiff(
384
400
  entry: LogOutputEntry,
385
401
  options: {
@@ -1286,6 +1302,7 @@ export class LogPrinter {
1286
1302
  const width = this.graph ? this.graph.getWidth() : 0;
1287
1303
  const diffOptions = {
1288
1304
  ...(width ? { statWidth: 80 - width } : {}),
1305
+ ...(this.graph ? { linePrefix: true } : {}),
1289
1306
  ...(this.follow && this.followPath !== undefined ? { follow: this.followPath } : {}),
1290
1307
  ...(this.options.fullDiff ? { fullDiff: true } : {}),
1291
1308
  ...this.diffAbbrev(),
@@ -1293,7 +1310,11 @@ export class LogPrinter {
1293
1310
  if (remerge && !this.host.remergeDiff) {
1294
1311
  throw new Error("--remerge-diff: the log's host cannot re-merge");
1295
1312
  }
1296
- const result: { bytes?: Uint8Array; followPath?: string } =
1313
+ const result: {
1314
+ bytes?: Uint8Array;
1315
+ followPath?: string;
1316
+ prefixPoints?: readonly number[];
1317
+ } =
1297
1318
  lineLog && this.host.lineLogDiff
1298
1319
  ? await this.host.lineLogDiff(entry, this.formats, this.diffAbbrev())
1299
1320
  : remerge && this.host.remergeDiff
@@ -1319,7 +1340,13 @@ export class LogPrinter {
1319
1340
  this.out.text("\n");
1320
1341
  }
1321
1342
  }
1322
- this.out.bytes(prefixLines(result.bytes, this.padding()));
1343
+ // the graph's padding once the commit's header is out (git's prefix callback runs then)
1344
+ const padding = this.padding();
1345
+ this.out.bytes(
1346
+ result.prefixPoints
1347
+ ? insertLinePrefix(result.bytes, result.prefixPoints, bytesOf(padding))
1348
+ : prefixLines(result.bytes, padding),
1349
+ );
1323
1350
  }
1324
1351
 
1325
1352
  /** combine-diff.c's diff_tree_combined for a merge */
@@ -343,17 +343,8 @@ export class LsTreeCommand extends PlumbingCommand {
343
343
  }
344
344
  match = normalized;
345
345
  }
346
- const unsupported = MAGIC.filter((m) => m.name !== "top" && m.name !== "literal").filter(
347
- (m) => magic.has(m.name),
348
- );
349
- if (unsupported.length > 0) {
350
- const names = unsupported
351
- .map((m) => (m.mnemonic ? `'${m.name}' (mnemonic: '${m.mnemonic}')` : `'${m.name}'`))
352
- .join(", ");
353
- throw new PlumbingError(
354
- `fatal: ${elem}: pathspec magic not supported by this command: ${names}`,
355
- );
356
- }
346
+ const unsupported = unsupportedPathspecMagic(elem, magic, ["top", "literal"]);
347
+ if (unsupported) throw new PlumbingError(`fatal: ${unsupported}`);
357
348
  items.push(literal(match));
358
349
  }
359
350
  return items;
@@ -639,8 +630,25 @@ function quoteBytes(path: string, quoteFully: boolean): string {
639
630
  return latin1String(encodeGitPath(`"${body}"`));
640
631
  }
641
632
 
633
+ /**
634
+ * git's `unsupported_magic` message for the magic of `elem` outside `allowed` (a command's
635
+ * `magic_mask`), undefined when it has none.
636
+ */
637
+ export function unsupportedPathspecMagic(
638
+ elem: string,
639
+ magic: ReadonlySet<string>,
640
+ allowed: readonly string[],
641
+ ): string | undefined {
642
+ const unsupported = MAGIC.filter((m) => !allowed.includes(m.name) && magic.has(m.name));
643
+ if (unsupported.length === 0) return undefined;
644
+ const names = unsupported
645
+ .map((m) => (m.mnemonic ? `'${m.name}' (mnemonic: '${m.mnemonic}')` : `'${m.name}'`))
646
+ .join(", ");
647
+ return `${elem}: pathspec magic not supported by this command: ${names}`;
648
+ }
649
+
642
650
  /** parse_element_magic: the magic names an element carries and the path after them. */
643
- function parseElementMagic(elem: string): { magic: Set<string>; rest: string } {
651
+ export function parseElementMagic(elem: string): { magic: Set<string>; rest: string } {
644
652
  const magic = new Set<string>();
645
653
  if (!elem.startsWith(":")) return { magic, rest: elem };
646
654
  if (elem[1] === "(") {