@statewalker/vcs-commands 0.13.0 → 0.14.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 (102) hide show
  1. package/dist/commands/archive/archive-command.d.ts +6 -2
  2. package/dist/commands/archive/archive-command.d.ts.map +1 -1
  3. package/dist/commands/archive/remote-archive-command.d.ts +23 -1
  4. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -1
  5. package/dist/commands/archive/upload-archive-writer.d.ts +11 -5
  6. package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -1
  7. package/dist/commands/bundle/bundle-format.d.ts +6 -1
  8. package/dist/commands/bundle/bundle-format.d.ts.map +1 -1
  9. package/dist/commands/bundle/bundle-uri-host.d.ts +12 -1
  10. package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -1
  11. package/dist/commands/bundle/bundle-uri.d.ts +7 -1
  12. package/dist/commands/bundle/bundle-uri.d.ts.map +1 -1
  13. package/dist/commands/bundle/bundle-verify.d.ts +4 -1
  14. package/dist/commands/bundle/bundle-verify.d.ts.map +1 -1
  15. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
  16. package/dist/commands/check-ignore-command.d.ts.map +1 -1
  17. package/dist/commands/clone-command.d.ts +15 -0
  18. package/dist/commands/clone-command.d.ts.map +1 -1
  19. package/dist/commands/commit-command.d.ts +10 -1
  20. package/dist/commands/commit-command.d.ts.map +1 -1
  21. package/dist/commands/default-branch.d.ts +17 -3
  22. package/dist/commands/default-branch.d.ts.map +1 -1
  23. package/dist/commands/fetch-command.d.ts +2 -1
  24. package/dist/commands/fetch-command.d.ts.map +1 -1
  25. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
  26. package/dist/commands/git-hooks.d.ts +3 -3
  27. package/dist/commands/git-hooks.d.ts.map +1 -1
  28. package/dist/commands/index.js +6 -6
  29. package/dist/commands/init-command.d.ts.map +1 -1
  30. package/dist/commands/local-transport.d.ts +11 -1
  31. package/dist/commands/local-transport.d.ts.map +1 -1
  32. package/dist/commands/ls-tree-command.d.ts +10 -0
  33. package/dist/commands/ls-tree-command.d.ts.map +1 -1
  34. package/dist/commands/merge-command.d.ts +11 -1
  35. package/dist/commands/merge-command.d.ts.map +1 -1
  36. package/dist/commands/merge-support.d.ts +19 -2
  37. package/dist/commands/merge-support.d.ts.map +1 -1
  38. package/dist/commands/plumbing-input.d.ts.map +1 -1
  39. package/dist/commands/promisor-remote-reply.d.ts +31 -4
  40. package/dist/commands/promisor-remote-reply.d.ts.map +1 -1
  41. package/dist/commands/promisor-remote.d.ts +8 -1
  42. package/dist/commands/promisor-remote.d.ts.map +1 -1
  43. package/dist/commands/push-command.d.ts.map +1 -1
  44. package/dist/commands/ref-filter/index.d.ts +1 -0
  45. package/dist/commands/ref-filter/index.d.ts.map +1 -1
  46. package/dist/commands/ref-filter/peel-limit.d.ts +8 -0
  47. package/dist/commands/ref-filter/peel-limit.d.ts.map +1 -0
  48. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -1
  49. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -1
  50. package/dist/commands/serve-repository.d.ts +4 -3
  51. package/dist/commands/serve-repository.d.ts.map +1 -1
  52. package/dist/commands/signing.d.ts +29 -2
  53. package/dist/commands/signing.d.ts.map +1 -1
  54. package/dist/commands/split-cmdline.d.ts +6 -0
  55. package/dist/commands/split-cmdline.d.ts.map +1 -0
  56. package/dist/{commands-CPceUCP2.js → commands-C9M78Chn.js} +1186 -1036
  57. package/dist/errors/commit-errors.d.ts +17 -1
  58. package/dist/errors/commit-errors.d.ts.map +1 -1
  59. package/dist/errors/index.js +18 -3
  60. package/dist/{fsck-tbrPZX2q.js → fsck-C4US3l0B.js} +2 -2
  61. package/dist/index.js +7 -7
  62. package/dist/{maintenance-run-command-UiSIaeP8.js → maintenance-run-command-CoJFKr2p.js} +84 -32
  63. package/dist/{remote-transport-C0OSJtor.js → remote-transport-C43eykfK.js} +51 -16
  64. package/dist/results/index.js +1 -1
  65. package/dist/{results-CkS1p1CH.js → results-B0CWLCAp.js} +371 -53
  66. package/dist/transport-command.d.ts +3 -0
  67. package/dist/transport-command.d.ts.map +1 -1
  68. package/package.json +21 -13
  69. package/src/commands/archive/archive-command.ts +7 -3
  70. package/src/commands/archive/remote-archive-command.ts +37 -3
  71. package/src/commands/archive/upload-archive-writer.ts +34 -22
  72. package/src/commands/bundle/bundle-format.ts +10 -2
  73. package/src/commands/bundle/bundle-uri-host.ts +71 -11
  74. package/src/commands/bundle/bundle-uri.ts +11 -4
  75. package/src/commands/bundle/bundle-verify.ts +4 -1
  76. package/src/commands/cat-file/cat-file-command.ts +1 -33
  77. package/src/commands/check-ignore-command.ts +60 -15
  78. package/src/commands/clone-command.ts +89 -11
  79. package/src/commands/commit-command.ts +42 -7
  80. package/src/commands/default-branch.ts +19 -5
  81. package/src/commands/fetch-command.ts +13 -2
  82. package/src/commands/fsck/fsck-object-checks.ts +3 -1
  83. package/src/commands/git-hooks.ts +11 -5
  84. package/src/commands/init-command.ts +24 -4
  85. package/src/commands/local-transport.ts +53 -9
  86. package/src/commands/ls-tree-command.ts +20 -12
  87. package/src/commands/merge-command.ts +32 -8
  88. package/src/commands/merge-support.ts +42 -4
  89. package/src/commands/plumbing-input.ts +3 -1
  90. package/src/commands/promisor-remote-reply.ts +338 -56
  91. package/src/commands/promisor-remote.ts +25 -3
  92. package/src/commands/push-command.ts +5 -1
  93. package/src/commands/read-tree-command.ts +2 -2
  94. package/src/commands/ref-filter/index.ts +1 -0
  95. package/src/commands/ref-filter/peel-limit.ts +7 -0
  96. package/src/commands/ref-filter/ref-filter.ts +9 -3
  97. package/src/commands/ref-filter/ref-format.ts +2 -1
  98. package/src/commands/serve-repository.ts +8 -3
  99. package/src/commands/signing.ts +93 -10
  100. package/src/commands/split-cmdline.ts +32 -0
  101. package/src/errors/commit-errors.ts +24 -2
  102. package/src/transport-command.ts +31 -1
@@ -59,6 +59,7 @@ import {
59
59
  defaultRefFormat,
60
60
  InvalidInitialBranchError,
61
61
  isValidBranchName,
62
+ type NewRepositoryConfig,
62
63
  } from "./default-branch.js";
63
64
 
64
65
  /**
@@ -388,14 +389,16 @@ export class InitCommand {
388
389
  let initialBranch = "";
389
390
  let hints: string[] | undefined;
390
391
  const warnings: string[] = [];
391
- const chooseBranch = async () => {
392
+ // `config`: the new repository's (git reads init.defaultBranch once its templates are
393
+ // copied, `includeIf "gitdir:"` matching its git directory); none in memory
394
+ const chooseBranch = async (config?: NewRepositoryConfig) => {
392
395
  if (this.initialBranch !== undefined && !isValidBranchName(this.initialBranch)) {
393
396
  throw new InvalidInitialBranchError(this.initialBranch);
394
397
  }
395
398
  const chosen =
396
399
  this.initialBranch !== undefined
397
400
  ? { name: this.initialBranch }
398
- : await defaultInitialBranch(this.environment);
401
+ : await defaultInitialBranch(this.environment, config);
399
402
  initialBranch = chosen.name;
400
403
  hints = chosen.hint;
401
404
  };
@@ -478,8 +481,10 @@ export class InitCommand {
478
481
  throw new ReinitializeHashError();
479
482
  }
480
483
  }
481
- if (!hasHead) await chooseBranch();
482
- else if (this.initialBranch !== undefined) {
484
+ // --initial-branch is checked before anything is written; the configured default once
485
+ // the templates are in place (below)
486
+ if (!hasHead && this.initialBranch !== undefined) await chooseBranch();
487
+ else if (hasHead && this.initialBranch !== undefined) {
483
488
  warnings.push(`warning: re-init: ignored --initial-branch=${this.initialBranch}`);
484
489
  }
485
490
  // the ref storage of a repository created here (an existing one keeps its own)
@@ -500,6 +505,21 @@ export class InitCommand {
500
505
  await this.copyTemplates(sharedFiles, dir, warnings);
501
506
  shared = this.shared ?? (await this.configuredShared(repoFiles, dir));
502
507
  if (shared) await adjustSharedPerm(repoFiles, dir, shared);
508
+ // repo_default_branch_name after the templates (2.43's create_default_files, 2.5x's
509
+ // create_reference_database): the whole configuration of the new repository, its
510
+ // `includeIf "gitdir:"` conditions matched against its git directory as the host names it
511
+ if (!hasHead && this.initialBranch === undefined) {
512
+ const newConfig = await createWorkingCopyConfig(
513
+ configFilesApiOf(repoFiles, { readOnly: "init reads the configuration only" }),
514
+ dir,
515
+ undefined,
516
+ {
517
+ ...(this.environment ? { environment: this.environment } : {}),
518
+ gitDirPath: await this.hostPath(repoFiles, dir),
519
+ },
520
+ );
521
+ await chooseBranch(newConfig);
522
+ }
503
523
 
504
524
  // the config, set as create_default_files and init_db set it
505
525
  const configPath = `${dir}/config`;
@@ -67,35 +67,73 @@ const COULD_NOT_READ =
67
67
  const NOT_A_REPOSITORY = (path: string) =>
68
68
  `fatal: '${path}' does not appear to be a git repository\n${COULD_NOT_READ}`;
69
69
 
70
+ /** Options of {@link createDuplexPair}. */
71
+ export interface DuplexPairOptions {
72
+ /**
73
+ * Bounds what a side holds unread: a `write` returns a promise once this many bytes wait,
74
+ * resolved when the reader took them below it. With a bound, `close` (unlike `end`) also
75
+ * stops a side's reading: waiting and later writes into it reject, as a pipe whose reader
76
+ * is gone. Default: unbounded, every write queued.
77
+ */
78
+ highWaterMark?: number;
79
+ }
80
+
70
81
  /**
71
82
  * A connected pair of in-memory duplex streams: what one side writes, the other reads. `end`
72
83
  * half-closes a side (the other one reads to its end and can still answer); `close` ends it.
73
84
  */
74
- export function createDuplexPair(): [Duplex, Duplex] {
85
+ export function createDuplexPair(options: DuplexPairOptions = {}): [Duplex, Duplex] {
86
+ const highWaterMark = options.highWaterMark;
75
87
  const make = () => {
76
88
  const queue: Uint8Array[] = [];
89
+ let queued = 0;
77
90
  let ended = false;
91
+ let abandoned = false;
78
92
  let wake: (() => void) | undefined;
79
- const push = (chunk: Uint8Array | null) => {
93
+ let writers: Array<{ resolve: () => void; reject: (error: Error) => void }> = [];
94
+ const release = (error?: Error) => {
95
+ const waiting = writers;
96
+ writers = [];
97
+ for (const w of waiting) {
98
+ if (error) w.reject(error);
99
+ else w.resolve();
100
+ }
101
+ };
102
+ const push = (chunk: Uint8Array | null): Promise<void> | undefined => {
80
103
  if (chunk === null) ended = true;
81
- else queue.push(chunk);
104
+ else {
105
+ if (abandoned) return Promise.reject(new Error("the stream's reader stopped"));
106
+ queue.push(chunk);
107
+ queued += chunk.length;
108
+ }
82
109
  wake?.();
83
110
  wake = undefined;
111
+ if (chunk === null || highWaterMark === undefined || queued < highWaterMark) return;
112
+ return new Promise<void>((resolve, reject) => writers.push({ resolve, reject }));
113
+ };
114
+ const abandon = () => {
115
+ if (highWaterMark === undefined) return;
116
+ abandoned = true;
117
+ queue.length = 0;
118
+ queued = 0;
119
+ release(new Error("the stream's reader stopped"));
84
120
  };
85
121
  async function* read(): AsyncGenerator<Uint8Array> {
86
122
  while (true) {
87
123
  const next = queue.shift();
88
124
  if (next) {
125
+ queued -= next.length;
126
+ if (highWaterMark === undefined || queued < highWaterMark) release();
89
127
  yield next;
90
128
  continue;
91
129
  }
92
- if (ended) return;
130
+ if (ended || abandoned) return;
93
131
  await new Promise<void>((resolve) => {
94
132
  wake = resolve;
95
133
  });
96
134
  }
97
135
  }
98
- return { push, read };
136
+ return { push, read, abandon };
99
137
  };
100
138
  const a = make();
101
139
  const b = make();
@@ -114,18 +152,24 @@ export function createDuplexPair(): [Duplex, Duplex] {
114
152
  const left: Duplex = {
115
153
  [Symbol.asyncIterator]: () => a.read()[Symbol.asyncIterator](),
116
154
  write: (data) => {
117
- if (!aClosed) b.push(data.slice());
155
+ if (!aClosed) return b.push(data.slice());
118
156
  },
119
157
  end: endLeft,
120
- close: endLeft,
158
+ close: async () => {
159
+ a.abandon();
160
+ await endLeft();
161
+ },
121
162
  };
122
163
  const right: Duplex = {
123
164
  [Symbol.asyncIterator]: () => b.read()[Symbol.asyncIterator](),
124
165
  write: (data) => {
125
- if (!bClosed) a.push(data.slice());
166
+ if (!bClosed) return a.push(data.slice());
126
167
  },
127
168
  end: endRight,
128
- close: endRight,
169
+ close: async () => {
170
+ b.abandon();
171
+ await endRight();
172
+ },
129
173
  };
130
174
  return [left, right];
131
175
  }
@@ -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] === "(") {
@@ -51,6 +51,7 @@ import {
51
51
  indexChanges,
52
52
  indexChangesFromTree,
53
53
  OperationState,
54
+ peelMergeHeads,
54
55
  readIndex,
55
56
  rewriteIndex,
56
57
  storeFlatTree,
@@ -148,6 +149,11 @@ export const UNMERGED_FILES_MESSAGE = (action: "Merging" | "Committing") =>
148
149
  */
149
150
  export class MergeCommand extends GitCommand<MergeResult> {
150
151
  private includes: string[] = [];
152
+ /**
153
+ * The object each merged commit was named by (git's `merge_remote_desc.obj`, the first
154
+ * name's): an annotated tag's own id, which `write_merge_heads` puts in MERGE_HEAD.
155
+ */
156
+ private readonly mergeObjects = new Map<ObjectId, ObjectId>();
151
157
  private fastForwardMode = FastForwardMode.FF;
152
158
  private strategy = MergeStrategy.RECURSIVE;
153
159
  /** Whether `-s` was given (`-s recursive` names itself in git's messages) */
@@ -1514,7 +1520,10 @@ export class MergeCommand extends GitCommand<MergeResult> {
1514
1520
  return giveUp([refused.message], stop ? output.slice(0, stop.output) : output);
1515
1521
  }
1516
1522
  const writeState = async (text: string) => {
1517
- await state.write("MERGE_HEAD", remoteIds.map((id) => `${id}\n`).join(""));
1523
+ await state.write(
1524
+ "MERGE_HEAD",
1525
+ remoteIds.map((id) => `${this.mergeObjectOf(id)}\n`).join(""),
1526
+ );
1518
1527
  await state.write("MERGE_MSG", text);
1519
1528
  await state.write("MERGE_MODE", this.ffMode() === FastForwardMode.NO_FF ? "no-ff" : "");
1520
1529
  };
@@ -1590,13 +1599,23 @@ export class MergeCommand extends GitCommand<MergeResult> {
1590
1599
  return { status: MergeStatus.MERGED, newHead: newCommitId, mergedCommits, output };
1591
1600
  }
1592
1601
 
1593
- /** The heads MERGE_HEAD names (one per line: several for an octopus). */
1602
+ /**
1603
+ * The commits MERGE_HEAD names (one per line: several for an octopus), each peeled as
1604
+ * git's `read_merge_heads` → `lookup_commit_reference` (a merged tag is named by its own id).
1605
+ */
1594
1606
  private async mergeHeads(state: OperationState): Promise<ObjectId[]> {
1595
1607
  const text = await state.read("MERGE_HEAD");
1596
- const lines = (text ?? "").split("\n").filter((l) => /^[0-9a-f]{40,64}$/.test(l));
1597
- if (lines.length > 0) return lines;
1598
- const single = await state.ref("MERGE_HEAD");
1599
- return single ? [single] : [];
1608
+ let lines = (text ?? "").split("\n").filter((l) => /^[0-9a-f]{40,64}$/.test(l));
1609
+ if (lines.length === 0) {
1610
+ const single = await state.ref("MERGE_HEAD");
1611
+ lines = single ? [single] : [];
1612
+ }
1613
+ return peelMergeHeads(this.revisionResolver(), lines);
1614
+ }
1615
+
1616
+ /** The object a merged commit was named by (the commit itself unless a tag named it). */
1617
+ private mergeObjectOf(commitId: ObjectId): ObjectId {
1618
+ return this.mergeObjects.get(commitId) ?? commitId;
1600
1619
  }
1601
1620
 
1602
1621
  /** `git merge --continue`: commits the resolved merge with MERGE_MSG. */
@@ -2052,7 +2071,7 @@ export class MergeCommand extends GitCommand<MergeResult> {
2052
2071
  srcId: ObjectId,
2053
2072
  message: string,
2054
2073
  ): Promise<void> {
2055
- await state.setRef("MERGE_HEAD", srcId);
2074
+ await state.setRef("MERGE_HEAD", this.mergeObjectOf(srcId));
2056
2075
  await state.write("MERGE_MSG", message);
2057
2076
  await state.write("MERGE_MODE", this.ffMode() === FastForwardMode.NO_FF ? "no-ff" : "");
2058
2077
  }
@@ -2185,7 +2204,12 @@ export class MergeCommand extends GitCommand<MergeResult> {
2185
2204
  */
2186
2205
  private async mergeHeadOf(name: string): Promise<ObjectId> {
2187
2206
  try {
2188
- return await this.resolveRef(name);
2207
+ const commitId = await this.resolveRef(name);
2208
+ if (!this.mergeObjects.has(commitId)) {
2209
+ const objectId = await this.resolveRevision(name, { hint: "committish" });
2210
+ this.mergeObjects.set(commitId, objectId);
2211
+ }
2212
+ return commitId;
2189
2213
  } catch (error) {
2190
2214
  if (!(error instanceof NotACommitError)) throw error;
2191
2215
  const lines = error.objectType
@@ -43,6 +43,7 @@ import type { CommandRefs, CommandTrees } from "../git-command.js";
43
43
  import { coreBool, worktreeModeTrust } from "./core-config.js";
44
44
  import type { OrtConflict } from "./ort-merge.js";
45
45
  import { markIndexUpdate } from "./post-index-change.js";
46
+ import type { RevisionResolver } from "./revision-resolver.js";
46
47
  import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
47
48
  import type { SubmoduleUnpack } from "./submodule-unpack.js";
48
49
  import {
@@ -65,19 +66,39 @@ import { firstInvalidPath, worktreePathRules } from "./worktree-path-rules.js";
65
66
  const sameEntry = (a: CheckedEntry | undefined, b: CheckedEntry | undefined) =>
66
67
  a === undefined || b === undefined ? a === b : a.objectId === b.objectId && a.mode === b.mode;
67
68
 
68
- /** The blobs, links and gitlinks of a tree, by path (none for no tree). */
69
+ /**
70
+ * The blobs, links and gitlinks of a tree, by path (none for no tree).
71
+ *
72
+ * @param options.asIndex The entries as unpack-trees adds them to an index
73
+ * (`add_index_entry`'s `OK_TO_REPLACE`): a file the directory of its name follows in the
74
+ * same tree (a crafted tree holding both, which fsck calls `duplicateEntries`) is dropped
75
+ * once a file of that directory is read, so the map never holds a file/directory clash
76
+ * (webrun-vcs#247)
77
+ */
69
78
  export async function flatTree(
70
79
  trees: CommandTrees,
71
80
  treeId: ObjectId | undefined,
81
+ options?: { asIndex?: boolean },
72
82
  ): Promise<Map<string, CheckedEntry>> {
73
83
  const out = new Map<string, CheckedEntry>();
74
84
  if (!treeId) return out;
75
- const walk = async (id: ObjectId, prefix: string): Promise<void> => {
85
+ const asIndex = options?.asIndex === true;
86
+ const walk = async (id: ObjectId, prefix: string): Promise<boolean> => {
87
+ let added = false;
76
88
  for await (const entry of trees.loadTree(id)) {
77
89
  const path = prefix ? `${prefix}/${entry.name}` : entry.name;
78
- if (entry.mode === FileMode.TREE) await walk(entry.id, path);
79
- else out.set(path, { objectId: entry.id, mode: entry.mode });
90
+ if (entry.mode === FileMode.TREE) {
91
+ // an empty directory adds nothing, so a file of its name stays
92
+ if (await walk(entry.id, path)) {
93
+ if (asIndex) out.delete(path);
94
+ added = true;
95
+ }
96
+ } else {
97
+ out.set(path, { objectId: entry.id, mode: entry.mode });
98
+ added = true;
99
+ }
80
100
  }
101
+ return added;
81
102
  };
82
103
  await walk(treeId, "");
83
104
  return out;
@@ -1334,3 +1355,20 @@ export function subjectOf(message: string): string {
1334
1355
  for (; i < lines.length && lines[i] !== ""; i++) subject.push(lines[i] as string);
1335
1356
  return subject.join(" ");
1336
1357
  }
1358
+
1359
+ /**
1360
+ * MERGE_HEAD's entries as commits (git's `read_merge_heads` → `lookup_commit_reference`): a
1361
+ * merged annotated tag is written by its own id (`write_merge_heads`) and peeled when read;
1362
+ * an entry that peels to no commit is kept as written.
1363
+ */
1364
+ export async function peelMergeHeads(
1365
+ resolver: Pick<RevisionResolver, "peelTags">,
1366
+ ids: ObjectId[],
1367
+ ): Promise<ObjectId[]> {
1368
+ const out: ObjectId[] = [];
1369
+ for (const id of ids) {
1370
+ const peeled = await resolver.peelTags(id).catch(() => undefined);
1371
+ out.push(peeled?.type === "commit" ? peeled.id : id);
1372
+ }
1373
+ return out;
1374
+ }
@@ -31,7 +31,9 @@ export function inputRecords(
31
31
  if (!nul && line[0] === 0x22) {
32
32
  const unquoted = unquoteGitPath(line, 0);
33
33
  if (!unquoted) return { records, badlyQuoted: true };
34
- records.push(unquoted.path);
34
+ // the caller reads the strbuf as a C string: an unquoted `\000` ends the path
35
+ const nul = unquoted.path.indexOf("\0");
36
+ records.push(nul < 0 ? unquoted.path : unquoted.path.slice(0, nul));
35
37
  } else records.push(decodeGitPath(line));
36
38
  }
37
39
  return { records, badlyQuoted: false };