@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
|
@@ -45,8 +45,9 @@ import {
|
|
|
45
45
|
readPackIndex,
|
|
46
46
|
} from "@statewalker/vcs-core";
|
|
47
47
|
import { applyGitDelta } from "@statewalker/vcs-utils/diff";
|
|
48
|
+
import { type ObjectFormat, SHA1_OBJECT_FORMAT } from "@statewalker/vcs-utils/hash";
|
|
48
49
|
import { CRC32 } from "@statewalker/vcs-utils/hash/crc32";
|
|
49
|
-
import {
|
|
50
|
+
import { type Hasher, sha1Of } from "@statewalker/vcs-utils/hash/hasher";
|
|
50
51
|
import { bytesToHex } from "@statewalker/vcs-utils/hash/utils";
|
|
51
52
|
import { allocBytes } from "@statewalker/vcs-utils/streams";
|
|
52
53
|
|
|
@@ -58,7 +59,7 @@ export interface PackScanEntry {
|
|
|
58
59
|
sizeInPack: number;
|
|
59
60
|
/** False when its CRC-32 is not the one the idx records (v2 idx only). */
|
|
60
61
|
crcOk: boolean;
|
|
61
|
-
/** The idx's bytes, holding the id's 20
|
|
62
|
+
/** The idx's bytes, holding the id's bytes (20, or 32 in SHA-256) at `idAt`. */
|
|
62
63
|
ids: Uint8Array;
|
|
63
64
|
idAt: number;
|
|
64
65
|
/**
|
|
@@ -106,6 +107,8 @@ export interface PackCheckOptions {
|
|
|
106
107
|
read?: { bytes: Uint8Array; idx: PackIndex };
|
|
107
108
|
/** Whether a blob's content is wanted (otherwise its entry's `content` is empty). */
|
|
108
109
|
keepBlob: (id: string) => boolean;
|
|
110
|
+
/** The repository's object format (default SHA-1): ids, checksums and the hash checked */
|
|
111
|
+
objectFormat?: ObjectFormat;
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
/** What `checkPack` found. */
|
|
@@ -158,17 +161,22 @@ export async function checkPack(
|
|
|
158
161
|
let idxBytes: Uint8Array;
|
|
159
162
|
let idx: PackIndex;
|
|
160
163
|
const read = options.read;
|
|
164
|
+
const format = options.objectFormat ?? SHA1_OBJECT_FORMAT;
|
|
165
|
+
const raw = format.rawLength;
|
|
161
166
|
try {
|
|
162
167
|
// the idx as the caller read it, or read here: once either way
|
|
163
168
|
idxBytes = read?.bytes ?? (await readAll(files, idxPath));
|
|
164
|
-
idx = read?.idx ?? readPackIndex(idxBytes);
|
|
169
|
+
idx = read?.idx ?? readPackIndex(idxBytes, raw);
|
|
165
170
|
} catch {
|
|
166
171
|
hooks.error(`packfile ${packPath} index not opened`);
|
|
167
172
|
return { failed: true, opened: false };
|
|
168
173
|
}
|
|
169
174
|
// verify_pack_index
|
|
170
|
-
const idxSum =
|
|
171
|
-
|
|
175
|
+
const idxSum = format
|
|
176
|
+
.createHasher()
|
|
177
|
+
.update(idxBytes.subarray(0, idxBytes.length - raw))
|
|
178
|
+
.digest();
|
|
179
|
+
if (!sameBytes(idxSum, 0, idxBytes, idxBytes.length - raw, raw)) {
|
|
172
180
|
hooks.error(`Packfile index for ${packPath} hash mismatch`);
|
|
173
181
|
failed = true;
|
|
174
182
|
}
|
|
@@ -178,6 +186,7 @@ export async function checkPack(
|
|
|
178
186
|
try {
|
|
179
187
|
pack = await openPack(files, packPath, idxPath, {
|
|
180
188
|
idxBytes,
|
|
189
|
+
...(format === SHA1_OBJECT_FORMAT ? {} : { objectFormat: format }),
|
|
181
190
|
externalBase: externalBase
|
|
182
191
|
? async (id) => {
|
|
183
192
|
const obj = await externalBase(id);
|
|
@@ -195,18 +204,18 @@ export async function checkPack(
|
|
|
195
204
|
try {
|
|
196
205
|
const stats = await files.stats(packPath);
|
|
197
206
|
const packLength = stats?.size ?? 0;
|
|
198
|
-
const trailerAt = packLength -
|
|
207
|
+
const trailerAt = packLength - raw;
|
|
199
208
|
|
|
200
209
|
// the entries in pack order, with where each one's id is in the idx
|
|
201
210
|
const v2 = idx.version > 1;
|
|
202
211
|
const idsAt = v2 ? 8 + 1024 : 1024 + 4;
|
|
203
|
-
const idStride = v2 ?
|
|
212
|
+
const idStride = v2 ? raw : raw + 4;
|
|
204
213
|
const count = idx.objectCount;
|
|
205
|
-
const lookups = idLookups(idxBytes, v2, count);
|
|
206
|
-
const ids = hexIds(idxBytes, idsAt, idStride, count);
|
|
207
|
-
const crcAt = idsAt + count *
|
|
214
|
+
const lookups = idLookups(idxBytes, v2, count, raw);
|
|
215
|
+
const ids = hexIds(idxBytes, idsAt, idStride, count, raw);
|
|
216
|
+
const crcAt = idsAt + count * raw;
|
|
208
217
|
// in pack order (sorted by offset): each entry's idx position and offset
|
|
209
|
-
const { order, sorted } = packEntryOrder(idxBytes, v2, count);
|
|
218
|
+
const { order, sorted } = packEntryOrder(idxBytes, v2, count, raw);
|
|
210
219
|
const n = count;
|
|
211
220
|
const offsetOf = (k: number) => sorted[k] as number;
|
|
212
221
|
const posOf = (k: number) => order[k] as number;
|
|
@@ -277,7 +286,7 @@ export async function checkPack(
|
|
|
277
286
|
} else {
|
|
278
287
|
return undefined;
|
|
279
288
|
}
|
|
280
|
-
if (!hashesTo(type, data, idxBytes, idAtK(k))) return undefined;
|
|
289
|
+
if (!hashesTo(type, data, idxBytes, idAtK(k), format)) return undefined;
|
|
281
290
|
keepBase(k, type, data);
|
|
282
291
|
return { type, data };
|
|
283
292
|
};
|
|
@@ -289,7 +298,7 @@ export async function checkPack(
|
|
|
289
298
|
const offset = offsetOf(k);
|
|
290
299
|
const head =
|
|
291
300
|
v2 && bytes && fastAt(k)
|
|
292
|
-
? parseEntryHead(bytes, sorted, k, entryEnd(k), (b) => ids(posOf(b)))
|
|
301
|
+
? parseEntryHead(bytes, sorted, k, entryEnd(k), (b) => ids(posOf(b)), raw)
|
|
293
302
|
: undefined;
|
|
294
303
|
const id = ids(posOf(k));
|
|
295
304
|
const entry: PackScanEntry = {
|
|
@@ -322,14 +331,14 @@ export async function checkPack(
|
|
|
322
331
|
base: `failed to read delta base object ${baseId} at offset ${baseAt} from ${packPath}`,
|
|
323
332
|
};
|
|
324
333
|
};
|
|
325
|
-
const slow = unpackEntry(pack, packPath, entry, keepBlob);
|
|
334
|
+
const slow = unpackEntry(pack, packPath, entry, keepBlob, format);
|
|
326
335
|
if (slow instanceof Promise) return slow.then((u) => hooks.entry(entry, noted(u), pack));
|
|
327
336
|
return hooks.entry(entry, noted(slow), pack);
|
|
328
337
|
};
|
|
329
338
|
|
|
330
|
-
// One pass: the pack's
|
|
331
|
-
const sha =
|
|
332
|
-
const trailer = new Uint8Array(
|
|
339
|
+
// One pass: the pack's hash, each entry's CRC-32 and bytes
|
|
340
|
+
const sha = format.createHasher();
|
|
341
|
+
const trailer = new Uint8Array(raw);
|
|
333
342
|
let at = 0;
|
|
334
343
|
let k = 0;
|
|
335
344
|
let crc = new CRC32();
|
|
@@ -405,11 +414,11 @@ export async function checkPack(
|
|
|
405
414
|
const r = visit(k, undefined);
|
|
406
415
|
if (r instanceof Promise) await r;
|
|
407
416
|
}
|
|
408
|
-
if (!sameBytes(sha.digest(), 0, trailer, 0)) {
|
|
417
|
+
if (!sameBytes(sha.digest(), 0, trailer, 0, raw)) {
|
|
409
418
|
hooks.checksumError(`${packPath} pack checksum mismatch`);
|
|
410
419
|
failed = true;
|
|
411
420
|
}
|
|
412
|
-
if (!sameBytes(idx.packChecksum, 0, trailer, 0)) {
|
|
421
|
+
if (!sameBytes(idx.packChecksum, 0, trailer, 0, raw)) {
|
|
413
422
|
hooks.checksumError(`${packPath} pack checksum does not match its index`);
|
|
414
423
|
failed = true;
|
|
415
424
|
}
|
|
@@ -442,36 +451,47 @@ function hexIds(
|
|
|
442
451
|
idsAt: number,
|
|
443
452
|
stride: number,
|
|
444
453
|
n: number,
|
|
454
|
+
raw = 20,
|
|
445
455
|
): (pos: number) => string {
|
|
446
|
-
const
|
|
456
|
+
const hex = 2 * raw;
|
|
457
|
+
const text = new Uint8Array(n * hex);
|
|
447
458
|
for (let i = 0; i < n; i++) {
|
|
448
|
-
for (let k = 0, at = idsAt + i * stride, o = i *
|
|
459
|
+
for (let k = 0, at = idsAt + i * stride, o = i * hex; k < raw; k++, o += 2) {
|
|
449
460
|
const b = (idx[at + k] as number) ?? 0;
|
|
450
461
|
text[o] = HEX_DIGITS[b >> 4] as number;
|
|
451
462
|
text[o + 1] = HEX_DIGITS[b & 15] as number;
|
|
452
463
|
}
|
|
453
464
|
}
|
|
454
465
|
const all = new TextDecoder().decode(text);
|
|
455
|
-
return (pos) => all.slice(pos *
|
|
466
|
+
return (pos) => all.slice(pos * hex, pos * hex + hex);
|
|
456
467
|
}
|
|
457
468
|
|
|
458
|
-
function sameBytes(a: Uint8Array, at: number, b: Uint8Array, bt: number): boolean {
|
|
459
|
-
for (let i = 0; i <
|
|
469
|
+
function sameBytes(a: Uint8Array, at: number, b: Uint8Array, bt: number, n = 20): boolean {
|
|
470
|
+
for (let i = 0; i < n; i++) if (a[at + i] !== b[bt + i]) return false;
|
|
460
471
|
return true;
|
|
461
472
|
}
|
|
462
473
|
|
|
463
474
|
/** Where `hashesTo` writes an object's `"<type> <size>\0"` header (it runs synchronously). */
|
|
464
475
|
const header = new Uint8Array(32);
|
|
465
476
|
|
|
466
|
-
/** Whether `content` as `type` hashes to the
|
|
467
|
-
function hashesTo(
|
|
477
|
+
/** Whether `content` as `type` hashes (in `format`) to the id bytes at `idAt` in `ids`. */
|
|
478
|
+
function hashesTo(
|
|
479
|
+
type: string,
|
|
480
|
+
content: Uint8Array,
|
|
481
|
+
ids: Uint8Array,
|
|
482
|
+
idAt: number,
|
|
483
|
+
format: ObjectFormat,
|
|
484
|
+
): boolean {
|
|
468
485
|
let n = 0;
|
|
469
486
|
for (let i = 0; i < type.length; i++) header[n++] = type.charCodeAt(i);
|
|
470
487
|
header[n++] = 0x20;
|
|
471
488
|
const size = String(content.length);
|
|
472
489
|
for (let i = 0; i < size.length; i++) header[n++] = size.charCodeAt(i);
|
|
473
490
|
header[n++] = 0;
|
|
474
|
-
|
|
491
|
+
if (format.name === "sha1")
|
|
492
|
+
return sameBytes(sha1Of(header.subarray(0, n), content), 0, ids, idAt);
|
|
493
|
+
const digest = format.createHasher().update(header.subarray(0, n)).update(content).digest();
|
|
494
|
+
return sameBytes(digest, 0, ids, idAt, format.rawLength);
|
|
475
495
|
}
|
|
476
496
|
|
|
477
497
|
/** The whole content of an object read from a store. */
|
|
@@ -510,6 +530,7 @@ export function unpackEntry(
|
|
|
510
530
|
packPath: string,
|
|
511
531
|
entry: PackScanEntry,
|
|
512
532
|
keepBlob: (id: string) => boolean,
|
|
533
|
+
format: ObjectFormat = SHA1_OBJECT_FORMAT,
|
|
513
534
|
): UnpackedEntry | Promise<UnpackedEntry> {
|
|
514
535
|
let obj: GitObject | undefined | Promise<GitObject | undefined>;
|
|
515
536
|
try {
|
|
@@ -519,11 +540,11 @@ export function unpackEntry(
|
|
|
519
540
|
}
|
|
520
541
|
if (obj instanceof Promise) {
|
|
521
542
|
return obj.then(
|
|
522
|
-
(o) => hashEntry(o, packPath, entry, keepBlob),
|
|
543
|
+
(o) => hashEntry(o, packPath, entry, keepBlob, format),
|
|
523
544
|
(e) => unpackError(entry, packPath, e),
|
|
524
545
|
);
|
|
525
546
|
}
|
|
526
|
-
return hashEntry(obj, packPath, entry, keepBlob);
|
|
547
|
+
return hashEntry(obj, packPath, entry, keepBlob, format);
|
|
527
548
|
}
|
|
528
549
|
|
|
529
550
|
function hashEntry(
|
|
@@ -531,11 +552,13 @@ function hashEntry(
|
|
|
531
552
|
packPath: string,
|
|
532
553
|
entry: PackScanEntry,
|
|
533
554
|
keepBlob: (id: string) => boolean,
|
|
555
|
+
format: ObjectFormat,
|
|
534
556
|
): UnpackedEntry | Promise<UnpackedEntry> {
|
|
535
557
|
if (!obj) return { error: cannotUnpack(entry, packPath), corrupt: false };
|
|
536
558
|
const bytes = obj.bytes;
|
|
537
|
-
if (!bytes) return streamEntry(obj, packPath, entry, keepBlob);
|
|
538
|
-
|
|
559
|
+
if (!bytes) return streamEntry(obj, packPath, entry, keepBlob, format);
|
|
560
|
+
const sha1 = format.name === "sha1";
|
|
561
|
+
if (objectIdOf(obj.type, bytes, sha1 ? undefined : format.createHasher) !== entry.id) {
|
|
539
562
|
return { error: `packed ${entry.id} from ${packPath} is corrupt`, corrupt: true };
|
|
540
563
|
}
|
|
541
564
|
return { type: obj.type, content: obj.type === "blob" && !keepBlob(entry.id) ? EMPTY : bytes };
|
|
@@ -547,9 +570,10 @@ async function streamEntry(
|
|
|
547
570
|
packPath: string,
|
|
548
571
|
entry: PackScanEntry,
|
|
549
572
|
keepBlob: (id: string) => boolean,
|
|
573
|
+
format: ObjectFormat,
|
|
550
574
|
): Promise<UnpackedEntry> {
|
|
551
575
|
const keep = obj.type !== "blob" || keepBlob(entry.id);
|
|
552
|
-
const h =
|
|
576
|
+
const h = format.createHasher().update(enc.encode(`${obj.type} ${obj.size}\0`));
|
|
553
577
|
const parts: Uint8Array[] = [];
|
|
554
578
|
let n = 0;
|
|
555
579
|
try {
|
|
@@ -588,14 +612,20 @@ function unpackError(entry: PackScanEntry, packPath: string, e: unknown): Unpack
|
|
|
588
612
|
|
|
589
613
|
const enc = new TextEncoder();
|
|
590
614
|
|
|
591
|
-
/**
|
|
592
|
-
|
|
615
|
+
/**
|
|
616
|
+
* The git object id of `content` as `type`: SHA-1 (or `newHasher`'s hash) over its header and
|
|
617
|
+
* content, as hex.
|
|
618
|
+
*/
|
|
619
|
+
export function objectIdOf(type: string, content: Uint8Array, newHasher?: () => Hasher): string {
|
|
593
620
|
let n = 0;
|
|
594
621
|
for (let i = 0; i < type.length; i++) header[n++] = type.charCodeAt(i);
|
|
595
622
|
header[n++] = 0x20;
|
|
596
623
|
const size = String(content.length);
|
|
597
624
|
for (let i = 0; i < size.length; i++) header[n++] = size.charCodeAt(i);
|
|
598
625
|
header[n++] = 0;
|
|
626
|
+
if (newHasher) {
|
|
627
|
+
return bytesToHex(newHasher().update(header.subarray(0, n)).update(content).digest());
|
|
628
|
+
}
|
|
599
629
|
return bytesToHex(sha1Of(header.subarray(0, n), content));
|
|
600
630
|
}
|
|
601
631
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FilesApi } from "@statewalker/vcs-core";
|
|
2
|
+
import type { ObjectFormat } from "@statewalker/vcs-utils/hash";
|
|
2
3
|
|
|
3
4
|
import { GitCommand } from "../../git-command.js";
|
|
4
5
|
import { checkPack, type PackScanEntry, type UnpackedEntry } from "./fsck-pack.js";
|
|
@@ -116,7 +117,8 @@ export class VerifyPackCommand extends GitCommand<VerifyPackResult> {
|
|
|
116
117
|
: path.endsWith(".pack")
|
|
117
118
|
? path.slice(0, -5)
|
|
118
119
|
: path;
|
|
119
|
-
|
|
120
|
+
// the repository's object format, as git's verify-pack reads packs with the_hash_algo
|
|
121
|
+
const report = await verifyOnePack(files, `${base}.pack`, `${base}.idx`, this.objectFormat);
|
|
120
122
|
packs.push(report);
|
|
121
123
|
for (const e of report.errors) err.push(`${e}\n`);
|
|
122
124
|
if (report.ok && (this._verbose || this._statOnly)) {
|
|
@@ -151,6 +153,7 @@ async function verifyOnePack(
|
|
|
151
153
|
files: FilesApi,
|
|
152
154
|
packPath: string,
|
|
153
155
|
idxPath: string,
|
|
156
|
+
objectFormat: ObjectFormat,
|
|
154
157
|
): Promise<VerifyPackReport> {
|
|
155
158
|
const errors: string[] = [];
|
|
156
159
|
const report: VerifyPackReport = {
|
|
@@ -214,7 +217,7 @@ async function verifyOnePack(
|
|
|
214
217
|
);
|
|
215
218
|
},
|
|
216
219
|
},
|
|
217
|
-
{ keepBlob: noBlob },
|
|
220
|
+
{ keepBlob: noBlob, ...(objectFormat.name === "sha1" ? {} : { objectFormat }) },
|
|
218
221
|
);
|
|
219
222
|
if (!result.opened) return report;
|
|
220
223
|
if (result.failed) ok = false;
|