@statewalker/vcs-commands 0.6.0 → 0.7.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.
- package/dist/commands/apply/apply-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-engine.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.d.ts.map +1 -1
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +17 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/comment-char-config.d.ts +35 -0
- package/dist/commands/comment-char-config.d.ts.map +1 -0
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/default-branch.d.ts +70 -0
- package/dist/commands/default-branch.d.ts.map +1 -0
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-command.d.ts +2 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-loose.d.ts +3 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-object-checks.d.ts +25 -14
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-object-table.d.ts +15 -7
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-pack.d.ts +11 -4
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -1
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -1
- package/dist/commands/gc-command.d.ts +72 -48
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +1 -65
- package/dist/commands/git-date.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +8 -0
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/index-adder.d.ts +2 -0
- package/dist/commands/index-adder.d.ts.map +1 -1
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -3
- package/dist/commands/init-command.d.ts +50 -3
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/legacy-remotes.d.ts +55 -0
- package/dist/commands/legacy-remotes.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/merge-command.d.ts +12 -0
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-support.d.ts +11 -3
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/notes-merge-command.d.ts.map +1 -1
- package/dist/commands/notes-tree.d.ts +11 -1
- package/dist/commands/notes-tree.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +3 -0
- package/dist/commands/patch-id.d.ts.map +1 -1
- package/dist/commands/pretty-format.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts +18 -0
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/rev-parse-command.d.ts +9 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -1
- package/dist/commands/revision-resolver.d.ts +6 -2
- package/dist/commands/revision-resolver.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +1 -1
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +1 -1
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/submodule-summary-command.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +2 -1
- package/dist/commands/untracked-cache-support.d.ts.map +1 -1
- package/dist/commands/worktree-list-command.d.ts.map +1 -1
- package/dist/{commands-DnmlfwGV.js → commands-DIJ91NnD.js} +1111 -506
- package/dist/{git-command-DxvwPrPB.js → git-command-BGiOJ8Zk.js} +630 -996
- package/dist/git-command.d.ts +16 -1
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +9 -2
- package/dist/git.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/remote-config/index.d.ts +1 -1
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +62 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/rename/detect-renames.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +8 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/index.js +1 -1
- package/dist/results/init-result.d.ts +7 -0
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +5 -0
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +5 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/{results-BZGa2Z3I.js → results-WVlBhVb1.js} +11 -10
- package/package.json +12 -12
- package/src/commands/add-patch/add-interactive.ts +3 -3
- package/src/commands/am/am-command.ts +1 -1
- package/src/commands/apply/apply-command.ts +12 -2
- package/src/commands/apply/apply-engine.ts +5 -6
- package/src/commands/apply/apply-parse.ts +3 -2
- package/src/commands/attributes-source.ts +1 -1
- package/src/commands/bisect/bisect-engine.ts +2 -1
- package/src/commands/checkout-command.ts +1 -1
- package/src/commands/clone-command.ts +116 -4
- package/src/commands/comment-char-config.ts +160 -0
- package/src/commands/commit-command.ts +8 -7
- package/src/commands/core-config.ts +7 -2
- package/src/commands/default-branch.ts +196 -0
- package/src/commands/diff-command.ts +45 -27
- package/src/commands/fetch-command.ts +19 -5
- package/src/commands/format-patch-command.ts +7 -2
- package/src/commands/fsck/fsck-command.ts +183 -66
- package/src/commands/fsck/fsck-loose.ts +14 -4
- package/src/commands/fsck/fsck-object-checks.ts +87 -46
- package/src/commands/fsck/fsck-object-table.ts +52 -42
- package/src/commands/fsck/fsck-pack.ts +64 -34
- package/src/commands/fsck/verify-pack-command.ts +5 -2
- package/src/commands/gc-command.ts +208 -107
- package/src/commands/git-date.ts +9 -895
- package/src/commands/git-hooks.ts +11 -0
- package/src/commands/index-adder.ts +8 -3
- package/src/commands/index.ts +2 -0
- package/src/commands/init-command.ts +167 -11
- package/src/commands/legacy-remotes.ts +224 -0
- package/src/commands/log-command.ts +37 -22
- package/src/commands/ls-remote-command.ts +4 -0
- package/src/commands/merge-command.ts +31 -1
- package/src/commands/merge-support.ts +29 -8
- package/src/commands/notes-merge-command.ts +23 -14
- package/src/commands/notes-tree.ts +28 -13
- package/src/commands/octopus-merge.ts +3 -2
- package/src/commands/patch-id.ts +16 -8
- package/src/commands/pretty-format.ts +2 -1
- package/src/commands/pull-command.ts +128 -20
- package/src/commands/push-command.ts +23 -8
- package/src/commands/read-tree-command.ts +6 -2
- package/src/commands/rebase-command.ts +24 -13
- package/src/commands/remote-command.ts +35 -5
- package/src/commands/reset-command.ts +4 -11
- package/src/commands/rev-parse-command.ts +22 -0
- package/src/commands/revision-resolver.ts +32 -14
- package/src/commands/sequencer-pick.ts +7 -2
- package/src/commands/sequencer-support.ts +10 -3
- package/src/commands/stash-apply-command.ts +1 -1
- package/src/commands/stash-create-command.ts +2 -2
- package/src/commands/status-command.ts +2 -4
- package/src/commands/status-header.ts +3 -1
- package/src/commands/submodule-summary-command.ts +6 -7
- package/src/commands/untracked-cache-support.ts +16 -12
- package/src/commands/worktree-list-command.ts +3 -5
- package/src/core-commands/add.command.impl.ts +1 -1
- package/src/git-command.ts +32 -2
- package/src/git.ts +16 -3
- package/src/remote-config/index.ts +2 -0
- package/src/remote-config/remote-config-store.ts +137 -11
- package/src/rename/detect-renames.ts +5 -1
- package/src/results/clone-result.ts +9 -0
- package/src/results/diff-output.ts +9 -7
- package/src/results/init-result.ts +9 -0
- package/src/results/pull-result.ts +5 -0
- package/src/results/push-result.ts +5 -0
- package/src/results/status-result.ts +5 -2
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
type CommitGraph,
|
|
7
7
|
canonTreeMode,
|
|
8
8
|
commitFromBytes,
|
|
9
|
-
EMPTY_TREE_ID,
|
|
10
9
|
type GitObject,
|
|
11
10
|
type ObjectId,
|
|
12
11
|
type ObjectReplacements,
|
|
@@ -68,8 +67,6 @@ import { PathspecAttributes } from "./pathspec-attributes.js";
|
|
|
68
67
|
import { loadRefDecorations } from "./pretty-format.js";
|
|
69
68
|
import { readDiffSubmoduleConfig } from "./submodule-summary.js";
|
|
70
69
|
|
|
71
|
-
const NULL_OBJECT_ID = "0".repeat(40);
|
|
72
|
-
|
|
73
70
|
/** What {@link LogCommand.callBytes} asks of the walk. */
|
|
74
71
|
interface OutputWalk {
|
|
75
72
|
/** `--topo-order` (and `--graph`) */
|
|
@@ -1151,7 +1148,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
1151
1148
|
diff: async (entry, parent, formats, options) => {
|
|
1152
1149
|
// the trees themselves: a full id names its object, so no revision is looked up
|
|
1153
1150
|
const diff = new DiffCommand(this._workingCopy)
|
|
1154
|
-
.setOldTree(parent ? await treeOf(parent) :
|
|
1151
|
+
.setOldTree(parent ? await treeOf(parent) : this.objectFormat.emptyTreeId)
|
|
1155
1152
|
.setNewTree(entry.commit.tree)
|
|
1156
1153
|
.shareReadsOf(this);
|
|
1157
1154
|
diff.setOptions({
|
|
@@ -1219,7 +1216,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
1219
1216
|
prefix = "",
|
|
1220
1217
|
out = new Map<string, { mode: number; id: ObjectId }>(),
|
|
1221
1218
|
): Promise<Map<string, { mode: number; id: ObjectId }>> {
|
|
1222
|
-
if (tree ===
|
|
1219
|
+
if (tree === this.objectFormat.emptyTreeId) return out;
|
|
1223
1220
|
for await (const entry of this.trees.loadTree(tree)) {
|
|
1224
1221
|
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
1225
1222
|
if ((entry.mode & 0o170000) === 0o040000) await this.flatTree(entry.id, path, out);
|
|
@@ -1308,7 +1305,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
1308
1305
|
if (paths.length === 0 || !options.patch) {
|
|
1309
1306
|
return { paths: paths.length, names: names.bytes(), patch: sink.bytes() };
|
|
1310
1307
|
}
|
|
1311
|
-
const ids = new Set<string>([
|
|
1308
|
+
const ids = new Set<string>([this.objectFormat.nullId]);
|
|
1312
1309
|
for (const path of paths) {
|
|
1313
1310
|
const r = result.get(path);
|
|
1314
1311
|
if (r) ids.add(r.id);
|
|
@@ -1346,21 +1343,30 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
1346
1343
|
const sides = [];
|
|
1347
1344
|
for (let k = 0; k < parents.length; k++) {
|
|
1348
1345
|
const e = sideOf(parents[k] as Map<string, { mode: number; id: ObjectId }>, k, path);
|
|
1349
|
-
sides.push({
|
|
1346
|
+
sides.push({
|
|
1347
|
+
id: e?.id ?? this.objectFormat.nullId,
|
|
1348
|
+
mode: e?.mode ?? 0,
|
|
1349
|
+
content: await read(e),
|
|
1350
|
+
});
|
|
1350
1351
|
}
|
|
1351
1352
|
writeCombinedDiff(
|
|
1352
1353
|
sink,
|
|
1353
1354
|
{
|
|
1354
1355
|
path,
|
|
1355
1356
|
parents: sides,
|
|
1356
|
-
result: {
|
|
1357
|
+
result: {
|
|
1358
|
+
id: r?.id ?? this.objectFormat.nullId,
|
|
1359
|
+
mode: r?.mode ?? 0,
|
|
1360
|
+
content: await read(r),
|
|
1361
|
+
},
|
|
1357
1362
|
},
|
|
1358
1363
|
{
|
|
1359
1364
|
...xdiffOptions,
|
|
1360
1365
|
dense,
|
|
1361
1366
|
workingTreeFile: false,
|
|
1362
1367
|
context: this.diffOptions.context ?? (Number.isFinite(context) ? context : 3),
|
|
1363
|
-
abbreviate: (id) =>
|
|
1368
|
+
abbreviate: (id) =>
|
|
1369
|
+
id.slice(0, this.diffOptions.fullIndex ? id.length : (lengths.get(id) ?? 7)),
|
|
1364
1370
|
quotePath: quote,
|
|
1365
1371
|
},
|
|
1366
1372
|
);
|
|
@@ -1493,7 +1499,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
1493
1499
|
if (!obj && !failed) return undefined;
|
|
1494
1500
|
if (obj?.bytes && obj.type === "commit") {
|
|
1495
1501
|
try {
|
|
1496
|
-
const header = parseGraphCommit(obj.bytes, id);
|
|
1502
|
+
const header = parseGraphCommit(obj.bytes, id, this.objectFormat);
|
|
1497
1503
|
return { ...header, raw: obj.bytes };
|
|
1498
1504
|
} catch {
|
|
1499
1505
|
// read as the commit store reads it
|
|
@@ -1660,8 +1666,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
1660
1666
|
// git reads the parent's tree, then the commit's
|
|
1661
1667
|
const da = a ? await this.requireTree(a) : EMPTY_TREE;
|
|
1662
1668
|
const db = b ? await this.requireTree(b) : EMPTY_TREE;
|
|
1663
|
-
const ca = new RawEntries(da);
|
|
1664
|
-
const cb = new RawEntries(db);
|
|
1669
|
+
const ca = new RawEntries(da, this.objectFormat.rawLength);
|
|
1670
|
+
const cb = new RawEntries(db, this.objectFormat.rawLength);
|
|
1665
1671
|
// entries are matched where they lie in the tree's bytes: no name is decoded; an `:(attr)`
|
|
1666
1672
|
// element waits for the attributes of a path, then the entry is matched again
|
|
1667
1673
|
const skip = (c: RawEntries): Promise<void> | undefined => {
|
|
@@ -1793,7 +1799,8 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
1793
1799
|
i: number,
|
|
1794
1800
|
): Promise<boolean> {
|
|
1795
1801
|
// the whole tree (`.`, `:/`): a root commit compares with the empty tree, as in git
|
|
1796
|
-
|
|
1802
|
+
const empty = this.objectFormat.emptyTreeId;
|
|
1803
|
+
if (parts.length === 0) return (a ?? empty) !== (b ?? empty);
|
|
1797
1804
|
const name = parts[i] as Uint8Array;
|
|
1798
1805
|
const ea = a ? await this.entryOf(a, name) : undefined;
|
|
1799
1806
|
const eb = b ? await this.entryOf(b, name) : undefined;
|
|
@@ -1820,7 +1827,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
1820
1827
|
const raw = await this.rawTree(tree);
|
|
1821
1828
|
if (raw === null) return this.trees.getEntry(tree, NAME_DECODER.decode(name));
|
|
1822
1829
|
if (raw === undefined) throw new GitApiError(`unable to read tree (${tree})`);
|
|
1823
|
-
return findRawEntry(raw, name);
|
|
1830
|
+
return findRawEntry(raw, name, this.objectFormat.rawLength);
|
|
1824
1831
|
}
|
|
1825
1832
|
|
|
1826
1833
|
/** The replace refs a walk's tree reads follow; undefined without any. */
|
|
@@ -1834,7 +1841,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
1834
1841
|
private async rawTree(tree: ObjectId): Promise<Uint8Array | undefined | null> {
|
|
1835
1842
|
const id = this.treeReplacements ? replacementOf(this.treeReplacements, tree) : tree;
|
|
1836
1843
|
// the empty tree, which a store need not hold
|
|
1837
|
-
if (id ===
|
|
1844
|
+
if (id === this.objectFormat.emptyTreeId) return EMPTY_TREE;
|
|
1838
1845
|
const cached = this.rawTrees.get(id);
|
|
1839
1846
|
if (cached) {
|
|
1840
1847
|
this.rawTrees.delete(id);
|
|
@@ -2128,7 +2135,11 @@ function concatBytes(chunks: Uint8Array[]): Uint8Array {
|
|
|
2128
2135
|
}
|
|
2129
2136
|
|
|
2130
2137
|
/** The entry named `name` (raw bytes) in raw tree `d`: its id and mode, or undefined. */
|
|
2131
|
-
function findRawEntry(
|
|
2138
|
+
function findRawEntry(
|
|
2139
|
+
d: Uint8Array,
|
|
2140
|
+
name: Uint8Array,
|
|
2141
|
+
idLength: number,
|
|
2142
|
+
): { id: ObjectId; mode: number } | undefined {
|
|
2132
2143
|
let p = 0;
|
|
2133
2144
|
const n = name.length;
|
|
2134
2145
|
while (p < d.length) {
|
|
@@ -2141,9 +2152,9 @@ function findRawEntry(d: Uint8Array, name: Uint8Array): { id: ObjectId; mode: nu
|
|
|
2141
2152
|
if (p - start === n) {
|
|
2142
2153
|
let k = 0;
|
|
2143
2154
|
while (k < n && d[start + k] === name[k]) k++;
|
|
2144
|
-
if (k === n) return { id: bytesToHex(d.subarray(idAt, idAt +
|
|
2155
|
+
if (k === n) return { id: bytesToHex(d.subarray(idAt, idAt + idLength)), mode };
|
|
2145
2156
|
}
|
|
2146
|
-
p = idAt +
|
|
2157
|
+
p = idAt + idLength;
|
|
2147
2158
|
}
|
|
2148
2159
|
return undefined;
|
|
2149
2160
|
}
|
|
@@ -2233,7 +2244,11 @@ class RawEntries {
|
|
|
2233
2244
|
nameStart = 0;
|
|
2234
2245
|
/** where the name ends (its NUL; the id follows) */
|
|
2235
2246
|
nul = 0;
|
|
2236
|
-
|
|
2247
|
+
/** @param idLength raw id bytes per entry: 20 (SHA-1) or 32 (SHA-256) */
|
|
2248
|
+
constructor(
|
|
2249
|
+
readonly d: Uint8Array,
|
|
2250
|
+
readonly idLength = 20,
|
|
2251
|
+
) {}
|
|
2237
2252
|
get done(): boolean {
|
|
2238
2253
|
return this.at >= this.d.length;
|
|
2239
2254
|
}
|
|
@@ -2249,10 +2264,10 @@ class RawEntries {
|
|
|
2249
2264
|
this.nul = p;
|
|
2250
2265
|
}
|
|
2251
2266
|
next(): void {
|
|
2252
|
-
this.at = this.nul +
|
|
2267
|
+
this.at = this.nul + 1 + this.idLength;
|
|
2253
2268
|
}
|
|
2254
2269
|
id(): ObjectId {
|
|
2255
|
-
return bytesToHex(this.d.subarray(this.nul + 1, this.nul +
|
|
2270
|
+
return bytesToHex(this.d.subarray(this.nul + 1, this.nul + 1 + this.idLength));
|
|
2256
2271
|
}
|
|
2257
2272
|
/** The base of the entries below this one (a directory): `base`, its name and "/". */
|
|
2258
2273
|
below(base: Uint8Array): Uint8Array {
|
|
@@ -2264,7 +2279,7 @@ class RawEntries {
|
|
|
2264
2279
|
return out;
|
|
2265
2280
|
}
|
|
2266
2281
|
sameId(other: RawEntries): boolean {
|
|
2267
|
-
for (let k = 1; k <=
|
|
2282
|
+
for (let k = 1; k <= this.idLength; k++) {
|
|
2268
2283
|
if (this.d[this.nul + k] !== other.d[other.nul + k]) return false;
|
|
2269
2284
|
}
|
|
2270
2285
|
return true;
|
|
@@ -254,8 +254,10 @@ export class LsRemoteCommand extends TransportCommand<LsRemoteResult> {
|
|
|
254
254
|
/** The URL of the remote given, or of git's default remote (see {@link callGetUrl}). */
|
|
255
255
|
private async remoteUrl(): Promise<string> {
|
|
256
256
|
const store = RemoteConfigStore.from(this.workingCopy);
|
|
257
|
+
// remote_get reads a legacy remote (.git/remotes/, .git/branches/: git 2.x) first
|
|
257
258
|
if (this.remote !== undefined) {
|
|
258
259
|
this.remoteName = this.remote;
|
|
260
|
+
await this.loadLegacyRemote(this.remote);
|
|
259
261
|
return store.remoteUrlOf(this.remote);
|
|
260
262
|
}
|
|
261
263
|
// remotes_remote_for_branch: an explicit branch remote is "given" (add_url_alias)
|
|
@@ -265,11 +267,13 @@ export class LsRemoteCommand extends TransportCommand<LsRemoteResult> {
|
|
|
265
267
|
const explicit = store.value(`branch.${branch}.remote`);
|
|
266
268
|
if (explicit !== undefined) {
|
|
267
269
|
this.remoteName = explicit;
|
|
270
|
+
await this.loadLegacyRemote(explicit);
|
|
268
271
|
return store.remoteUrlOf(explicit);
|
|
269
272
|
}
|
|
270
273
|
}
|
|
271
274
|
const names = store.configuredNames();
|
|
272
275
|
const name = names.length === 1 ? (names[0] ?? "origin") : "origin";
|
|
276
|
+
await this.loadLegacyRemote(name);
|
|
273
277
|
const url = store.urlFor(name);
|
|
274
278
|
if (url === undefined) {
|
|
275
279
|
throw new InvalidRemoteError(name, "fatal: No remote configured to list refs from.");
|
|
@@ -451,6 +451,36 @@ export class MergeCommand extends GitCommand<MergeResult> {
|
|
|
451
451
|
return this.sparseWarnings.length > 0 ? { ...result, warnings: this.sparseWarnings } : result;
|
|
452
452
|
}
|
|
453
453
|
|
|
454
|
+
/**
|
|
455
|
+
* merge.c's `checkout_fast_forward(head, remote)`: a two-way switch of the index and worktree
|
|
456
|
+
* from `from`'s tree to `to`'s, refusing (unpack-trees' porcelain "merge" messages) where
|
|
457
|
+
* local changes are in the way; no ref moves. `git pull` runs it when the fetch moved the
|
|
458
|
+
* checked-out branch itself.
|
|
459
|
+
*
|
|
460
|
+
* @returns git's refusal, or undefined once the index and worktree are at `to`
|
|
461
|
+
*/
|
|
462
|
+
async callCheckoutFastForward(
|
|
463
|
+
from: ObjectId,
|
|
464
|
+
to: ObjectId,
|
|
465
|
+
): Promise<{ message: string; paths: string[] } | undefined> {
|
|
466
|
+
this.checkCallable();
|
|
467
|
+
this.setCallable(false);
|
|
468
|
+
await this.readCurrentIndex();
|
|
469
|
+
const worktree = this.worktreeAccess;
|
|
470
|
+
const run = async () => {
|
|
471
|
+
const head = await flatTree(this.trees, await this.commits.getTree(from));
|
|
472
|
+
const targetTree = await this.commits.getTree(to);
|
|
473
|
+
const target = await flatTree(this.trees, targetTree);
|
|
474
|
+
const refused = await switchTrees(this.context(worktree), head, target, {
|
|
475
|
+
action: "merge",
|
|
476
|
+
operation: "merge",
|
|
477
|
+
targetTree,
|
|
478
|
+
});
|
|
479
|
+
return refused ? { message: refused.message, paths: [...refused.paths] } : undefined;
|
|
480
|
+
};
|
|
481
|
+
return worktree?.batch ? worktree.batch(run) : run();
|
|
482
|
+
}
|
|
483
|
+
|
|
454
484
|
/** What the sparse checkout printed while the result was written (see MergeResult.warnings). */
|
|
455
485
|
private readonly sparseWarnings: string[] = [];
|
|
456
486
|
|
|
@@ -1278,7 +1308,7 @@ export class MergeCommand extends GitCommand<MergeResult> {
|
|
|
1278
1308
|
let savedTree: ObjectId | undefined;
|
|
1279
1309
|
let indexTree: ObjectId | undefined;
|
|
1280
1310
|
if (await provider.hasLocalChanges()) {
|
|
1281
|
-
indexTree = await writeIndexAsTree(this.staging, this.trees);
|
|
1311
|
+
indexTree = await writeIndexAsTree(this.staging, this.trees, this.objectFormat);
|
|
1282
1312
|
savedTree = await provider.getWorkingTree();
|
|
1283
1313
|
}
|
|
1284
1314
|
// nothing saved: the reset alone, which leaves the index exactly HEAD (read-tree's
|
|
@@ -11,11 +11,13 @@ import {
|
|
|
11
11
|
collectTreeBytes,
|
|
12
12
|
FileMode,
|
|
13
13
|
type ObjectId,
|
|
14
|
+
objectFormatOf,
|
|
14
15
|
type RefLogOptions,
|
|
15
16
|
type TreeEntry,
|
|
16
17
|
} from "@statewalker/vcs-core";
|
|
17
|
-
import { bytesToHex, createSha1 } from "@statewalker/vcs-utils";
|
|
18
|
+
import { bytesToHex, createSha1, objectFormatByHexLength } from "@statewalker/vcs-utils";
|
|
18
19
|
import { compareGitPaths, decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
20
|
+
import type { ObjectFormat } from "@statewalker/vcs-utils/hash";
|
|
19
21
|
import {
|
|
20
22
|
attributesIndexOf,
|
|
21
23
|
type CacheTree,
|
|
@@ -195,6 +197,9 @@ interface IndexDir {
|
|
|
195
197
|
/** The index's stage-0 entries as directories, each with the id its tree would have. */
|
|
196
198
|
async function indexDirs(index: Map<string, CheckedEntry>): Promise<IndexDir> {
|
|
197
199
|
const root: IndexDir = { files: new Map(), dirs: new Map() };
|
|
200
|
+
const first = index.values().next().value as CheckedEntry | undefined;
|
|
201
|
+
const newHasher =
|
|
202
|
+
objectFormatByHexLength(first?.objectId.length ?? 40)?.createHasher ?? createSha1;
|
|
198
203
|
for (const [path, entry] of index) {
|
|
199
204
|
let dir = root;
|
|
200
205
|
let from = 0;
|
|
@@ -218,7 +223,8 @@ async function indexDirs(index: Map<string, CheckedEntry>): Promise<IndexDir> {
|
|
|
218
223
|
let id: ObjectId;
|
|
219
224
|
try {
|
|
220
225
|
const bytes = await collectTreeBytes(entries);
|
|
221
|
-
|
|
226
|
+
// the index's own format: its ids are SHA-256 ones in a SHA-256 repository
|
|
227
|
+
const hasher = newHasher().update(new TextEncoder().encode(`tree ${bytes.length}\0`));
|
|
222
228
|
id = bytesToHex(hasher.update(bytes).digest());
|
|
223
229
|
} catch {
|
|
224
230
|
// a name no tree can hold: never the id of a stored tree
|
|
@@ -480,6 +486,8 @@ export async function readIndex(
|
|
|
480
486
|
export async function writeIndexAsTree(
|
|
481
487
|
staging: Staging,
|
|
482
488
|
trees: CommandTrees,
|
|
489
|
+
/** the repository's object format, the cache-tree's trees are hashed in */
|
|
490
|
+
format: ObjectFormat,
|
|
483
491
|
options: { write?: boolean } = {},
|
|
484
492
|
): Promise<ObjectId> {
|
|
485
493
|
if (!staging.getCacheTree || !staging.setCacheTree) return staging.writeTree(trees);
|
|
@@ -487,7 +495,7 @@ export async function writeIndexAsTree(
|
|
|
487
495
|
const treeId = await staging.writeTree(trees);
|
|
488
496
|
if (!previous || !cacheTreeFullyValid(previous)) {
|
|
489
497
|
// the valid directories kept, the others computed (cache_tree_update)
|
|
490
|
-
const cacheTree = await updateCacheTree(trees, treeId, previous);
|
|
498
|
+
const cacheTree = await updateCacheTree(trees, treeId, previous, format);
|
|
491
499
|
for (const entry of await indexEntryList(staging)) {
|
|
492
500
|
if (entry.intentToAdd) {
|
|
493
501
|
invalidateCacheTreeForIntentToAdd(cacheTree, entry.path);
|
|
@@ -507,13 +515,18 @@ export async function writeIndexAsTree(
|
|
|
507
515
|
* directories of intent-to-add entries left invalid; nothing where the index has conflicts.
|
|
508
516
|
* Sets the cache-tree the next `write` writes.
|
|
509
517
|
*/
|
|
510
|
-
export async function updateIndexCacheTree(
|
|
518
|
+
export async function updateIndexCacheTree(
|
|
519
|
+
staging: Staging,
|
|
520
|
+
trees: CommandTrees,
|
|
521
|
+
/** the repository's object format, the cache-tree's trees are hashed in */
|
|
522
|
+
format: ObjectFormat,
|
|
523
|
+
): Promise<void> {
|
|
511
524
|
if (!staging.getCacheTree || !staging.setCacheTree) return;
|
|
512
525
|
if (await staging.hasConflicts()) return;
|
|
513
526
|
const previous = staging.getCacheTree();
|
|
514
527
|
if (previous && cacheTreeFullyValid(previous)) return;
|
|
515
528
|
const treeId = await staging.writeTree(trees);
|
|
516
|
-
const cacheTree = await updateCacheTree(trees, treeId, previous);
|
|
529
|
+
const cacheTree = await updateCacheTree(trees, treeId, previous, format);
|
|
517
530
|
for (const entry of await indexEntryList(staging)) {
|
|
518
531
|
if (entry.intentToAdd) {
|
|
519
532
|
invalidateCacheTreeForIntentToAdd(cacheTree, entry.path);
|
|
@@ -542,7 +555,7 @@ export async function rewriteIndex(
|
|
|
542
555
|
staging: Staging,
|
|
543
556
|
changes: Map<string, IndexEntryInput[]>,
|
|
544
557
|
options: {
|
|
545
|
-
updateCacheTreeWith?: CommandTrees;
|
|
558
|
+
updateCacheTreeWith?: { trees: CommandTrees; format: ObjectFormat };
|
|
546
559
|
cacheTree?: CacheTree;
|
|
547
560
|
/**
|
|
548
561
|
* Whether the kept entries count as up to date (default true: the merge family refreshes
|
|
@@ -604,7 +617,10 @@ export async function rewriteIndex(
|
|
|
604
617
|
// a cache-tree computed for the entries just built
|
|
605
618
|
if (options.cacheTree) staging.setCacheTree?.(options.cacheTree);
|
|
606
619
|
// unpack-trees' cache_tree_update before its index write
|
|
607
|
-
if (options.updateCacheTreeWith)
|
|
620
|
+
if (options.updateCacheTreeWith) {
|
|
621
|
+
const { trees, format } = options.updateCacheTreeWith;
|
|
622
|
+
await updateIndexCacheTree(staging, trees, format);
|
|
623
|
+
}
|
|
608
624
|
if (options.write !== false) await staging.write();
|
|
609
625
|
}
|
|
610
626
|
|
|
@@ -1120,7 +1136,12 @@ async function switchTreesWith(
|
|
|
1120
1136
|
if (previous) {
|
|
1121
1137
|
for (const path of [...updates, ...removes]) invalidateCacheTreePath(previous, path);
|
|
1122
1138
|
}
|
|
1123
|
-
const cacheTree = await updateCacheTree(
|
|
1139
|
+
const cacheTree = await updateCacheTree(
|
|
1140
|
+
ctx.trees,
|
|
1141
|
+
options.targetTree,
|
|
1142
|
+
previous,
|
|
1143
|
+
objectFormatOf(ctx.workingCopy.history),
|
|
1144
|
+
);
|
|
1124
1145
|
// the index the switch leaves is the target only where it switched: an entry it kept
|
|
1125
1146
|
// (a staged change the two trees agree on, carried over) differs from the target, and
|
|
1126
1147
|
// its directories are invalid, as cache_tree_update computes them from the index
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ObjectId } from "@statewalker/vcs-core";
|
|
2
|
-
import { mergeLines } from "@statewalker/vcs-utils";
|
|
2
|
+
import { mergeLines, type ObjectFormat, SHA1_OBJECT_FORMAT } from "@statewalker/vcs-utils";
|
|
3
3
|
import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
4
4
|
import { collectChunks } from "@statewalker/vcs-working-tree";
|
|
5
5
|
import type { CommandRefs } from "../git-command.js";
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
combineNotesCatSortUniq,
|
|
20
20
|
combineNotesConcatenate,
|
|
21
21
|
combineNotesOverwrite,
|
|
22
|
-
NOTES_NULL_ID,
|
|
23
22
|
type NotesTree,
|
|
24
23
|
readNoteBytes,
|
|
25
24
|
} from "./notes-tree.js";
|
|
@@ -38,7 +37,6 @@ const STRATEGIES: readonly NotesMergeStrategy[] = [
|
|
|
38
37
|
const WORKTREE = "NOTES_MERGE_WORKTREE";
|
|
39
38
|
/** notes-merge.c's `uninitialized`: no local change recorded */
|
|
40
39
|
const UNINITIALIZED = "f".repeat(40);
|
|
41
|
-
const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
42
40
|
|
|
43
41
|
/** `git notes merge` (with `--commit` / `--abort`). */
|
|
44
42
|
export interface NotesMergeResult extends NotesResult {
|
|
@@ -314,13 +312,14 @@ export class NotesMergeCommand extends NotesSubcommand<NotesMergeResult> {
|
|
|
314
312
|
const ctx = this.ctx;
|
|
315
313
|
const msg = partial.message;
|
|
316
314
|
for (const name of names) {
|
|
317
|
-
|
|
315
|
+
const hexLength = this.objectFormat.hexLength;
|
|
316
|
+
if (!new RegExp(`^[0-9a-fA-F]{${hexLength}}`).test(name)) {
|
|
318
317
|
if (this.verbosity >= 3) {
|
|
319
318
|
output.push(`Skipping non-SHA1 entry '${this.gitPath(WORKTREE)}/${name}'\n`);
|
|
320
319
|
}
|
|
321
320
|
continue;
|
|
322
321
|
}
|
|
323
|
-
const obj = name.slice(0,
|
|
322
|
+
const obj = name.slice(0, hexLength).toLowerCase();
|
|
324
323
|
const blob = await this.storeResolvedNote(name, errors);
|
|
325
324
|
await tree.add(obj, blob);
|
|
326
325
|
if (this.verbosity >= 4) output.push(`Added resolved note for object ${obj}: ${blob}\n`);
|
|
@@ -501,6 +500,15 @@ class NotesMerge {
|
|
|
501
500
|
private hasWorktree = false;
|
|
502
501
|
private commitMsg: string;
|
|
503
502
|
|
|
503
|
+
/** The repository's object format: its null id, empty tree and note path lengths */
|
|
504
|
+
private get format(): ObjectFormat {
|
|
505
|
+
return this.ctx.objectFormat ?? SHA1_OBJECT_FORMAT;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
private get nullId(): ObjectId {
|
|
509
|
+
return this.format.nullId;
|
|
510
|
+
}
|
|
511
|
+
|
|
504
512
|
constructor(
|
|
505
513
|
private readonly ctx: NotesContext,
|
|
506
514
|
private readonly checkout: {
|
|
@@ -554,8 +562,8 @@ class NotesMerge {
|
|
|
554
562
|
let baseId: ObjectId;
|
|
555
563
|
let baseTree: ObjectId;
|
|
556
564
|
if (bases.length === 0) {
|
|
557
|
-
baseId =
|
|
558
|
-
baseTree =
|
|
565
|
+
baseId = this.nullId;
|
|
566
|
+
baseTree = this.format.emptyTreeId;
|
|
559
567
|
this.say(4, "No merge base found; doing history-less merge\n");
|
|
560
568
|
} else {
|
|
561
569
|
baseId = bases[0] as ObjectId;
|
|
@@ -588,7 +596,8 @@ class NotesMerge {
|
|
|
588
596
|
if ((e.mode & 0o170000) === 0o040000) await walk(e.id, `${prefix}${e.name}/`);
|
|
589
597
|
else {
|
|
590
598
|
const hex = `${prefix}${e.name}`.replaceAll("/", "");
|
|
591
|
-
if (/^[0-9a-fA-F]
|
|
599
|
+
if (hex.length === this.format.hexLength && /^[0-9a-fA-F]+$/.test(hex))
|
|
600
|
+
out.set(hex.toLowerCase(), e.id);
|
|
592
601
|
}
|
|
593
602
|
}
|
|
594
603
|
};
|
|
@@ -608,10 +617,10 @@ class NotesMerge {
|
|
|
608
617
|
const r = await this.flatNotes(remote);
|
|
609
618
|
const changes: MergePair[] = [];
|
|
610
619
|
for (const obj of [...new Set([...b.keys(), ...r.keys()])].sort()) {
|
|
611
|
-
const bv = b.get(obj) ??
|
|
612
|
-
const rv = r.get(obj) ??
|
|
620
|
+
const bv = b.get(obj) ?? this.nullId;
|
|
621
|
+
const rv = r.get(obj) ?? this.nullId;
|
|
613
622
|
if (bv === rv) continue;
|
|
614
|
-
const lv = l.get(obj) ??
|
|
623
|
+
const lv = l.get(obj) ?? this.nullId;
|
|
615
624
|
changes.push({ obj, base: bv, local: lv === bv ? UNINITIALIZED : lv, remote: rv });
|
|
616
625
|
}
|
|
617
626
|
let conflicts = 0;
|
|
@@ -690,20 +699,20 @@ class NotesMerge {
|
|
|
690
699
|
this.commitMsg += `\t${p.obj}\n`;
|
|
691
700
|
this.say(2, `Auto-merging notes for ${p.obj}\n`);
|
|
692
701
|
await this.checkWorktree();
|
|
693
|
-
if (p.local ===
|
|
702
|
+
if (p.local === this.nullId) {
|
|
694
703
|
this.say(
|
|
695
704
|
1,
|
|
696
705
|
`CONFLICT (delete/modify): Notes for object ${p.obj} deleted in ${lref} and modified in ${rref}. Version from ${rref} left in tree.\n`,
|
|
697
706
|
);
|
|
698
707
|
await this.writeToWorktree(p.obj, await this.readBlob(p.remote));
|
|
699
|
-
} else if (p.remote ===
|
|
708
|
+
} else if (p.remote === this.nullId) {
|
|
700
709
|
this.say(
|
|
701
710
|
1,
|
|
702
711
|
`CONFLICT (delete/modify): Notes for object ${p.obj} deleted in ${rref} and modified in ${lref}. Version from ${lref} left in tree.\n`,
|
|
703
712
|
);
|
|
704
713
|
await this.writeToWorktree(p.obj, await this.readBlob(p.local));
|
|
705
714
|
} else {
|
|
706
|
-
const reason = p.base ===
|
|
715
|
+
const reason = p.base === this.nullId ? "add/add" : "content";
|
|
707
716
|
this.say(1, `CONFLICT (${reason}): Merge conflict in notes for object ${p.obj}\n`);
|
|
708
717
|
await this.llMerge(p);
|
|
709
718
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Blobs, ObjectId, TreeEntry } from "@statewalker/vcs-core";
|
|
2
|
+
import { isNullObjectId, type ObjectFormat, SHA1_OBJECT_FORMAT } from "@statewalker/vcs-utils";
|
|
2
3
|
|
|
3
4
|
import type { CommandTrees } from "../git-command.js";
|
|
4
5
|
|
|
@@ -18,9 +19,8 @@ import type { CommandTrees } from "../git-command.js";
|
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
21
|
|
|
22
|
+
/** SHA-1's null id: `NOTES_NULL_ID` (a SHA-256 tree's is its format's, `NotesTree.nullId`) */
|
|
21
23
|
const NULL_ID = "0".repeat(40);
|
|
22
|
-
const RAW = 20;
|
|
23
|
-
const HEX = 40;
|
|
24
24
|
|
|
25
25
|
const PTR_NULL = 0;
|
|
26
26
|
const PTR_INTERNAL = 1;
|
|
@@ -61,11 +61,14 @@ export type CombineNotes = (
|
|
|
61
61
|
export interface NotesStores {
|
|
62
62
|
blobs: Blobs;
|
|
63
63
|
trees: CommandTrees;
|
|
64
|
+
/** The repository's object format (default: the blobs', else SHA-1) */
|
|
65
|
+
objectFormat?: ObjectFormat;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
const typeOf = (p: Ptr): number => (p === null ? PTR_NULL : p.type);
|
|
67
69
|
const nibble = (n: number, key: string): number => Number.parseInt(key[n] ?? "0", 16);
|
|
68
|
-
|
|
70
|
+
/** A subtree key's prefix length in bytes: its last byte (the key is an id's length long) */
|
|
71
|
+
const prefixLength = (subtreeKey: string): number => Number.parseInt(subtreeKey.slice(-2), 16);
|
|
69
72
|
/** SUBTREE_SHA1_PREFIXCMP: whether `key` starts with the prefix of `subtree` (0: it does). */
|
|
70
73
|
const prefixMatches = (key: string, subtreeKey: string): boolean => {
|
|
71
74
|
const len = prefixLength(subtreeKey) * 2;
|
|
@@ -88,7 +91,7 @@ function compareBytes(a: string, b: string): number {
|
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
async function readBytes(blobs: Blobs, id: ObjectId): Promise<Uint8Array | undefined> {
|
|
91
|
-
if (id
|
|
94
|
+
if (isNullObjectId(id)) return undefined;
|
|
92
95
|
const content = await blobs.load(id).catch(() => undefined);
|
|
93
96
|
if (!content) return undefined;
|
|
94
97
|
const chunks: Uint8Array[] = [];
|
|
@@ -193,11 +196,20 @@ export class NotesTree {
|
|
|
193
196
|
/** A change was made since loading (t->dirty) */
|
|
194
197
|
dirty = false;
|
|
195
198
|
|
|
199
|
+
/** Raw id bytes of the repository's format (20 for SHA-1, 32 for SHA-256): notes' path lengths */
|
|
200
|
+
private readonly raw: number;
|
|
201
|
+
/** The repository's null id: adding it as a note removes one */
|
|
202
|
+
readonly nullId: ObjectId;
|
|
203
|
+
|
|
196
204
|
private constructor(
|
|
197
205
|
private readonly stores: NotesStores,
|
|
198
206
|
/** The tree's combine function (t->combine_notes) */
|
|
199
207
|
readonly combine: CombineNotes,
|
|
200
|
-
) {
|
|
208
|
+
) {
|
|
209
|
+
const format = stores.objectFormat ?? stores.blobs.objectFormat ?? SHA1_OBJECT_FORMAT;
|
|
210
|
+
this.raw = format.rawLength;
|
|
211
|
+
this.nullId = format.nullId;
|
|
212
|
+
}
|
|
201
213
|
|
|
202
214
|
/**
|
|
203
215
|
* init_notes's load: the stored tree `treeId` as an unread subtree of the root (read
|
|
@@ -209,7 +221,7 @@ export class NotesTree {
|
|
|
209
221
|
combine: CombineNotes = combineNotesConcatenate,
|
|
210
222
|
): Promise<NotesTree> {
|
|
211
223
|
const t = new NotesTree(stores, combine);
|
|
212
|
-
if (treeId) await t.loadSubtree({ type: PTR_SUBTREE, key:
|
|
224
|
+
if (treeId) await t.loadSubtree({ type: PTR_SUBTREE, key: t.nullId, val: treeId }, t.root, 0);
|
|
213
225
|
return t;
|
|
214
226
|
}
|
|
215
227
|
|
|
@@ -254,7 +266,7 @@ export class NotesTree {
|
|
|
254
266
|
const existing = await this.get(to);
|
|
255
267
|
if (!force && existing) return false;
|
|
256
268
|
if (note) await this.add(to, note, combine);
|
|
257
|
-
else if (existing) await this.add(to,
|
|
269
|
+
else if (existing) await this.add(to, this.nullId, combine);
|
|
258
270
|
return true;
|
|
259
271
|
}
|
|
260
272
|
|
|
@@ -403,7 +415,7 @@ export class NotesTree {
|
|
|
403
415
|
const { node, n, i } = await this.search(tree, n0, entry.key);
|
|
404
416
|
const l = node.a[i] ?? null;
|
|
405
417
|
if (l === null) {
|
|
406
|
-
if (entry.val
|
|
418
|
+
if (!isNullObjectId(entry.val)) node.a[i] = entry;
|
|
407
419
|
return;
|
|
408
420
|
}
|
|
409
421
|
if (l.type === PTR_NOTE) {
|
|
@@ -411,7 +423,7 @@ export class NotesTree {
|
|
|
411
423
|
if (l.key === entry.key) {
|
|
412
424
|
if (l.val === entry.val) return;
|
|
413
425
|
l.val = await combine(this.stores, l.val, entry.val);
|
|
414
|
-
if (l.val
|
|
426
|
+
if (isNullObjectId(l.val)) await this.removeLeaf(node, n, entry.key);
|
|
415
427
|
return;
|
|
416
428
|
}
|
|
417
429
|
} else if (prefixMatches(l.key, entry.key)) {
|
|
@@ -426,7 +438,7 @@ export class NotesTree {
|
|
|
426
438
|
}
|
|
427
439
|
}
|
|
428
440
|
// a non-matching leaf: both under a new int_node
|
|
429
|
-
if (entry.val
|
|
441
|
+
if (isNullObjectId(entry.val)) return;
|
|
430
442
|
const created = newNode();
|
|
431
443
|
await this.insert(created, n + 1, l as Leaf, combine);
|
|
432
444
|
node.a[i] = created;
|
|
@@ -461,7 +473,7 @@ export class NotesTree {
|
|
|
461
473
|
for (const entry of entries) {
|
|
462
474
|
const name = entry.name;
|
|
463
475
|
let leaf: Leaf | undefined;
|
|
464
|
-
if (name.length === 2 * (
|
|
476
|
+
if (name.length === 2 * (this.raw - prefixLen)) {
|
|
465
477
|
if (isRegular(entry.mode) && isHex(name)) {
|
|
466
478
|
leaf = { type: PTR_NOTE, key: prefix + name.toLowerCase(), val: entry.id };
|
|
467
479
|
}
|
|
@@ -471,7 +483,7 @@ export class NotesTree {
|
|
|
471
483
|
const key =
|
|
472
484
|
prefix +
|
|
473
485
|
name.toLowerCase() +
|
|
474
|
-
"00".repeat(
|
|
486
|
+
"00".repeat(this.raw - len - 1) +
|
|
475
487
|
len.toString(16).padStart(2, "0");
|
|
476
488
|
leaf = { type: PTR_SUBTREE, key, val: entry.id };
|
|
477
489
|
}
|
|
@@ -593,7 +605,10 @@ function pathWithFanout(key: string, fanout: number): string {
|
|
|
593
605
|
/** notes.c's GIT_NOTES_DEFAULT_REF */
|
|
594
606
|
export const NOTES_DEFAULT_REF = "refs/notes/commits";
|
|
595
607
|
|
|
596
|
-
/**
|
|
608
|
+
/**
|
|
609
|
+
* SHA-1's null object id, which adding as a note removes one (any format's null id does: see
|
|
610
|
+
* `NotesTree.nullId` for the repository's own).
|
|
611
|
+
*/
|
|
597
612
|
export const NOTES_NULL_ID = NULL_ID;
|
|
598
613
|
|
|
599
614
|
/** Reads a note blob's bytes (undefined for a missing one). */
|
|
@@ -300,11 +300,12 @@ async function mergeOneFile(
|
|
|
300
300
|
}
|
|
301
301
|
const [n1, n2] = [tempName(), tempName()];
|
|
302
302
|
output.push(o ? `Auto-merging ${path}` : `Added ${path} in both, but differently.`);
|
|
303
|
-
|
|
303
|
+
const emptyBlob = ctx.blobs.objectFormat?.emptyBlobId ?? EMPTY_BLOB_ID;
|
|
304
|
+
if (!o && !(await ctx.blobs.has(emptyBlob))) {
|
|
304
305
|
// the script's base is the empty blob, which `hash-object` never stored: unpack-file
|
|
305
306
|
// and merge-file fail, ours stays in the worktree
|
|
306
307
|
errors.push(
|
|
307
|
-
`fatal: unable to read blob object ${
|
|
308
|
+
`fatal: unable to read blob object ${emptyBlob}`,
|
|
308
309
|
"error: Could not stat : No such file or directory",
|
|
309
310
|
`ERROR: content conflict in ${path}`,
|
|
310
311
|
);
|