@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
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
graftFileReader,
|
|
11
11
|
isSymbolicRef,
|
|
12
12
|
loadMultiPackIndex,
|
|
13
|
+
objectFormatOf,
|
|
13
14
|
objectsWithoutLazyFetch,
|
|
14
15
|
openPack,
|
|
15
16
|
type PackFile,
|
|
@@ -25,11 +26,12 @@ import {
|
|
|
25
26
|
scanPackObjects,
|
|
26
27
|
type Trees,
|
|
27
28
|
verifyCommitGraph,
|
|
29
|
+
verifyReverseIndexFile,
|
|
28
30
|
} from "@statewalker/vcs-core";
|
|
29
31
|
import { multiPackIndexVerify } from "@statewalker/vcs-store-files";
|
|
30
32
|
import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
31
33
|
import { readFile } from "@statewalker/vcs-utils/files";
|
|
32
|
-
import {
|
|
34
|
+
import { isNullObjectId, type ObjectFormat } from "@statewalker/vcs-utils/hash";
|
|
33
35
|
import { bytesToHex } from "@statewalker/vcs-utils/hash/utils";
|
|
34
36
|
import {
|
|
35
37
|
type CacheTree,
|
|
@@ -87,6 +89,8 @@ export const FSCK_ERROR_REFS = 0o10;
|
|
|
87
89
|
export const FSCK_ERROR_COMMIT_GRAPH = 0o20;
|
|
88
90
|
/** `git multi-pack-index verify` failed, in git 2.43 (its ERROR_MULTI_PACK_INDEX; 2.5x: object bit). */
|
|
89
91
|
export const FSCK_ERROR_MULTI_PACK_INDEX_243 = 0o40;
|
|
92
|
+
/** A pack's `.rev` file is invalid, in git 2.43 (its ERROR_PACK_REV_INDEX; 2.5x: object bit). */
|
|
93
|
+
export const FSCK_ERROR_PACK_REV_INDEX_243 = 0o100;
|
|
90
94
|
/** A bitmap file's checksum is wrong, in git 2.43 (its ERROR_BITMAP; 2.5x sets the object bit). */
|
|
91
95
|
export const FSCK_ERROR_BITMAP_243 = 0o200;
|
|
92
96
|
|
|
@@ -184,10 +188,8 @@ export interface FsckRepositoryFiles {
|
|
|
184
188
|
gitDir?: string;
|
|
185
189
|
}
|
|
186
190
|
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
const LOOSE_NAME = /^[0-9a-f]{38}$/;
|
|
190
|
-
const PACK_IDX = /^pack-[0-9a-f]{40}\.idx$/;
|
|
191
|
+
const OID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
192
|
+
const PACK_IDX = /^pack-(?:[0-9a-f]{40}|[0-9a-f]{64})\.idx$/;
|
|
191
193
|
/** Refs one worktree has of its own (git's `is_per_worktree_ref`). */
|
|
192
194
|
const PER_WORKTREE = /^(?:refs\/(?:bisect|worktree|rewritten)\/|[A-Z_]+$)/;
|
|
193
195
|
const dec = new TextDecoder();
|
|
@@ -614,7 +616,13 @@ interface WorktreeState {
|
|
|
614
616
|
|
|
615
617
|
/** One `git fsck` run (builtin/fsck.c's globals). */
|
|
616
618
|
class FsckRun {
|
|
617
|
-
private readonly t
|
|
619
|
+
private readonly t: ObjectTable;
|
|
620
|
+
/** The repository's object format: its ids' lengths in trees, commits, tags and names */
|
|
621
|
+
private readonly format: ObjectFormat;
|
|
622
|
+
/** Whether the format is SHA-1 (its own fast hash paths) */
|
|
623
|
+
private readonly sha1: boolean;
|
|
624
|
+
/** A loose object's file name: the id after its fan-out directory (38 or 62 digits) */
|
|
625
|
+
private readonly looseName: RegExp;
|
|
618
626
|
private readonly findings: FsckFinding[] = [];
|
|
619
627
|
private errorsFound = 0;
|
|
620
628
|
private readonly pending: number[] = [];
|
|
@@ -669,7 +677,7 @@ class FsckRun {
|
|
|
669
677
|
*/
|
|
670
678
|
private readonly badCopy = new Set<string>();
|
|
671
679
|
/** Where an id parsed from hex is written for a lookup. */
|
|
672
|
-
private readonly idScratch
|
|
680
|
+
private readonly idScratch: Uint8Array;
|
|
673
681
|
/**
|
|
674
682
|
* The object `parseObject` read last: the connectivity walk of a tree it parsed walks these
|
|
675
683
|
* bytes instead of reading the tree again (git's parse_tree reads it once).
|
|
@@ -713,6 +721,11 @@ class FsckRun {
|
|
|
713
721
|
private readonly types: FsckMessageTypes,
|
|
714
722
|
private readonly o: RunOptions,
|
|
715
723
|
) {
|
|
724
|
+
this.format = objectFormatOf(objects);
|
|
725
|
+
this.sha1 = this.format.name === "sha1";
|
|
726
|
+
this.t = new ObjectTable(this.format.rawLength);
|
|
727
|
+
this.idScratch = new Uint8Array(this.format.rawLength);
|
|
728
|
+
this.looseName = new RegExp(`^[0-9a-f]{${this.format.hexLength - 2}}$`);
|
|
716
729
|
if (o.nameObjects) this.names = new Map();
|
|
717
730
|
this.showUnreachable = o.unreachable;
|
|
718
731
|
this.recordTrees = !o.connectivityOnly && !o.nameObjects;
|
|
@@ -720,6 +733,11 @@ class FsckRun {
|
|
|
720
733
|
this.gitDir = (o.repository?.gitDir ?? ".git").replace(/\/+$/, "");
|
|
721
734
|
}
|
|
722
735
|
|
|
736
|
+
/** The commit-graph read settings, in the repository's object format. */
|
|
737
|
+
private get graphSettings() {
|
|
738
|
+
return { ...this.o.commitGraph, objectFormat: this.format };
|
|
739
|
+
}
|
|
740
|
+
|
|
723
741
|
async run(): Promise<FsckResult> {
|
|
724
742
|
// git loads the midx when it first reads a packed object and dies on one it refuses
|
|
725
743
|
// fatally (a wrong signature or version, a required chunk missing; 2.5x: a fan-out out of
|
|
@@ -727,6 +745,7 @@ class FsckRun {
|
|
|
727
745
|
if (this.files && this.o.multiPackIndex !== false) {
|
|
728
746
|
const loaded = await loadMultiPackIndex(this.files, pathOf(this.looseDir(), "pack"), {
|
|
729
747
|
compatibility: this.o.compatibility,
|
|
748
|
+
objectFormat: this.format,
|
|
730
749
|
});
|
|
731
750
|
if (loaded.fatal) return this.death(loaded.errors);
|
|
732
751
|
const bad = loaded.midx && badPackIntIdAt(loaded.midx);
|
|
@@ -778,6 +797,9 @@ class FsckRun {
|
|
|
778
797
|
else {
|
|
779
798
|
const packs = step.packs.map((k) => this.packs[k] as RepoPack);
|
|
780
799
|
await this.fsckPacks(packs);
|
|
800
|
+
// 2.5x's verify_reverse_indices, then verify_bitmap_files
|
|
801
|
+
if (this.o.compatibility === "2.56" && (await this.verifyReverseIndexes(packs)))
|
|
802
|
+
this.errorsFound |= FSCK_ERROR_OBJECT;
|
|
781
803
|
// 2.5x's verify_bitmap_files, after the source's packs (2.43: at the end)
|
|
782
804
|
if (
|
|
783
805
|
this.o.compatibility === "2.56" &&
|
|
@@ -846,6 +868,13 @@ class FsckRun {
|
|
|
846
868
|
}
|
|
847
869
|
}
|
|
848
870
|
await this.verifyCommitGraph();
|
|
871
|
+
// 2.43's check_pack_rev_indexes, --connectivity-only too (ERROR_PACK_REV_INDEX, 0100)
|
|
872
|
+
if (
|
|
873
|
+
this.files &&
|
|
874
|
+
this.o.compatibility === "2.43" &&
|
|
875
|
+
(await this.verifyReverseIndexes(this.packs))
|
|
876
|
+
)
|
|
877
|
+
this.errorsFound |= FSCK_ERROR_PACK_REV_INDEX_243;
|
|
849
878
|
// 2.43 checks every pack's bitmap last, --connectivity-only too (ERROR_BITMAP, 0200)
|
|
850
879
|
if (
|
|
851
880
|
this.files &&
|
|
@@ -952,7 +981,7 @@ class FsckRun {
|
|
|
952
981
|
* stderr follows, and a failure sets ERROR_COMMIT_GRAPH.
|
|
953
982
|
*/
|
|
954
983
|
private async verifyCommitGraph(): Promise<void> {
|
|
955
|
-
const settings = this.
|
|
984
|
+
const settings = this.graphSettings;
|
|
956
985
|
if (!this.files || !settings.enabled) return;
|
|
957
986
|
// fsck itself loads the graph when it parses the commit of a ref (parse_object looks it
|
|
958
987
|
// up there first; fsck disables replace refs): what loading prints comes once from fsck,
|
|
@@ -963,6 +992,7 @@ class FsckRun {
|
|
|
963
992
|
files: this.files,
|
|
964
993
|
gitDir: this.gitDir,
|
|
965
994
|
useReplaceRefs: false,
|
|
995
|
+
objectFormat: this.format,
|
|
966
996
|
readGraftFile: () => this.graftFileText(),
|
|
967
997
|
}))
|
|
968
998
|
) {
|
|
@@ -979,7 +1009,7 @@ class FsckRun {
|
|
|
979
1009
|
|
|
980
1010
|
/** One `git commit-graph verify --object-dir <objectsDir>` child of fsck. */
|
|
981
1011
|
private async verifySourceCommitGraph(objectsDir: string): Promise<void> {
|
|
982
|
-
const settings = this.
|
|
1012
|
+
const settings = this.graphSettings;
|
|
983
1013
|
if (!this.files) return;
|
|
984
1014
|
// git's `git commit-graph verify` reads each commit (in the graph's order) from the first
|
|
985
1015
|
// pack of its most-recently-used list that has it: a commit in several packs is read from
|
|
@@ -1062,7 +1092,7 @@ class FsckRun {
|
|
|
1062
1092
|
const parse = (o: GitObject | undefined, data: Uint8Array) => {
|
|
1063
1093
|
if (o?.type !== "commit") return undefined;
|
|
1064
1094
|
reachGrafts(note, data);
|
|
1065
|
-
return parseGraphCommit(data, id);
|
|
1095
|
+
return parseGraphCommit(data, id, this.format);
|
|
1066
1096
|
};
|
|
1067
1097
|
const slow = async (o: GitObject | undefined | Promise<GitObject | undefined>) => {
|
|
1068
1098
|
try {
|
|
@@ -1098,7 +1128,7 @@ class FsckRun {
|
|
|
1098
1128
|
if (obj?.type !== "commit") return undefined;
|
|
1099
1129
|
const data = await collect(obj);
|
|
1100
1130
|
parsing(data);
|
|
1101
|
-
return parseGraphCommit(data, id);
|
|
1131
|
+
return parseGraphCommit(data, id, this.format);
|
|
1102
1132
|
} catch {
|
|
1103
1133
|
return undefined;
|
|
1104
1134
|
}
|
|
@@ -1126,7 +1156,7 @@ class FsckRun {
|
|
|
1126
1156
|
const map = this.graphCommits;
|
|
1127
1157
|
if (!map || this.graphCommitsKept >= this.o.graphCommitsKept || map.has(id)) return;
|
|
1128
1158
|
try {
|
|
1129
|
-
map.set(id, parseGraphCommit(content, id));
|
|
1159
|
+
map.set(id, parseGraphCommit(content, id, this.format));
|
|
1130
1160
|
this.graphCommitsKept++;
|
|
1131
1161
|
} catch {
|
|
1132
1162
|
// read again (and failed again) by the verification
|
|
@@ -1146,7 +1176,7 @@ class FsckRun {
|
|
|
1146
1176
|
* loads. Undefined otherwise: commits are read from the object store.
|
|
1147
1177
|
*/
|
|
1148
1178
|
private async loadCommitGraph(): Promise<CommitGraph | undefined> {
|
|
1149
|
-
const settings = this.
|
|
1179
|
+
const settings = this.graphSettings;
|
|
1150
1180
|
if (!this.files || !settings.enabled) return undefined;
|
|
1151
1181
|
try {
|
|
1152
1182
|
if (
|
|
@@ -1154,6 +1184,7 @@ class FsckRun {
|
|
|
1154
1184
|
files: this.files,
|
|
1155
1185
|
gitDir: this.gitDir,
|
|
1156
1186
|
useReplaceRefs: false,
|
|
1187
|
+
objectFormat: this.format,
|
|
1157
1188
|
readGraftFile: () => this.graftFileText(),
|
|
1158
1189
|
}))
|
|
1159
1190
|
) {
|
|
@@ -1519,14 +1550,16 @@ class FsckRun {
|
|
|
1519
1550
|
if ((await files.stats(dir))?.kind !== "directory") return [];
|
|
1520
1551
|
const found: (RepoPack & { mtime: number })[] = [];
|
|
1521
1552
|
for await (const e of files.list(dir)) {
|
|
1553
|
+
// the repository's format: a pack named in another is not one of its packs
|
|
1522
1554
|
if (e.kind !== "file" || !PACK_IDX.test(e.name)) continue;
|
|
1555
|
+
if (e.name.length !== "pack-.idx".length + this.format.hexLength) continue;
|
|
1523
1556
|
const idxPath = pathOf(dir, e.name);
|
|
1524
1557
|
const packPath = `${idxPath.slice(0, -4)}.pack`;
|
|
1525
1558
|
const stats = await files.stats(packPath);
|
|
1526
1559
|
if (stats?.kind !== "file") continue;
|
|
1527
1560
|
try {
|
|
1528
1561
|
const idxBytes = await readAll(files, idxPath);
|
|
1529
|
-
const idx = readPackIndex(idxBytes);
|
|
1562
|
+
const idx = readPackIndex(idxBytes, this.format.rawLength);
|
|
1530
1563
|
found.push({ packPath, idxPath, idx, idxBytes, source, mtime: stats.lastModified ?? 0 });
|
|
1531
1564
|
} catch {
|
|
1532
1565
|
// git does not list a pack whose idx cannot be opened
|
|
@@ -1554,7 +1587,7 @@ class FsckRun {
|
|
|
1554
1587
|
// in the order the files list them, as git's readdir loop: it decides hash collisions
|
|
1555
1588
|
for (const e of entries) {
|
|
1556
1589
|
const path = pathOf(dir, e.name);
|
|
1557
|
-
yield
|
|
1590
|
+
yield this.looseName.test(e.name)
|
|
1558
1591
|
? { id: sub + e.name, path, name: e.name }
|
|
1559
1592
|
: { path, name: e.name };
|
|
1560
1593
|
}
|
|
@@ -1586,11 +1619,12 @@ class FsckRun {
|
|
|
1586
1619
|
private async forEachStored(
|
|
1587
1620
|
visit: (raw: Uint8Array, at: number, pack: number, pos: number) => void | Promise<void>,
|
|
1588
1621
|
): Promise<void> {
|
|
1589
|
-
const
|
|
1590
|
-
|
|
1622
|
+
const raw = this.format.rawLength;
|
|
1623
|
+
const scratch = new Uint8Array(raw);
|
|
1624
|
+
// ids listed here are 40 (64) lowercase hex digits
|
|
1591
1625
|
const nibble = (c: number) => (c <= 0x39 ? c - 0x30 : c - 0x57);
|
|
1592
1626
|
const parsed = (id: string) => {
|
|
1593
|
-
for (let i = 0; i <
|
|
1627
|
+
for (let i = 0; i < raw; i++)
|
|
1594
1628
|
scratch[i] = (nibble(id.charCodeAt(2 * i)) << 4) | nibble(id.charCodeAt(2 * i + 1));
|
|
1595
1629
|
return scratch;
|
|
1596
1630
|
};
|
|
@@ -1655,7 +1689,7 @@ class FsckRun {
|
|
|
1655
1689
|
if (type === OBJ_COMMIT) {
|
|
1656
1690
|
if (this.graftsHint) this.adviseGrafts();
|
|
1657
1691
|
if (this.graftErrors.length > 0) this.reportGraftErrors();
|
|
1658
|
-
const parsed = parseCommitLinks(content, id);
|
|
1692
|
+
const parsed = parseCommitLinks(content, id, this.format);
|
|
1659
1693
|
if ("error" in parsed) {
|
|
1660
1694
|
this.error(parsed.error, id);
|
|
1661
1695
|
return undefined;
|
|
@@ -1664,7 +1698,10 @@ class FsckRun {
|
|
|
1664
1698
|
const tree = t.lookupTypedRaw(rawIdAt(content, parsed.tree, raw), 0, OBJ_TREE);
|
|
1665
1699
|
if (typeof tree !== "number") {
|
|
1666
1700
|
this.error(tree.error);
|
|
1667
|
-
this.error(
|
|
1701
|
+
this.error(
|
|
1702
|
+
`bad tree pointer ${hexIdAt(content, parsed.tree, this.format)} in commit ${id}`,
|
|
1703
|
+
id,
|
|
1704
|
+
);
|
|
1668
1705
|
return undefined;
|
|
1669
1706
|
}
|
|
1670
1707
|
const parents: number[] = [];
|
|
@@ -1684,7 +1721,7 @@ class FsckRun {
|
|
|
1684
1721
|
const parent = t.lookupTypedRaw(rawIdAt(content, at, raw), 0, OBJ_COMMIT);
|
|
1685
1722
|
if (typeof parent !== "number") {
|
|
1686
1723
|
this.error(parent.error);
|
|
1687
|
-
this.error(`bad parent ${hexIdAt(content, at)} in commit ${id}`, id);
|
|
1724
|
+
this.error(`bad parent ${hexIdAt(content, at, this.format)} in commit ${id}`, id);
|
|
1688
1725
|
return undefined;
|
|
1689
1726
|
}
|
|
1690
1727
|
parents.push(parent);
|
|
@@ -1695,7 +1732,7 @@ class FsckRun {
|
|
|
1695
1732
|
return n;
|
|
1696
1733
|
}
|
|
1697
1734
|
// tag
|
|
1698
|
-
const parsed = parseTagBuffer(content, id);
|
|
1735
|
+
const parsed = parseTagBuffer(content, id, this.format);
|
|
1699
1736
|
if ("error" in parsed) {
|
|
1700
1737
|
if (parsed.error) this.error(parsed.error, id);
|
|
1701
1738
|
return undefined;
|
|
@@ -1736,7 +1773,10 @@ class FsckRun {
|
|
|
1736
1773
|
* the store: a verified read would mark the copy bad there, and git reads it again as it is.
|
|
1737
1774
|
*/
|
|
1738
1775
|
private parseVerified(id: string, obj: Whole | undefined): number | undefined {
|
|
1739
|
-
if (
|
|
1776
|
+
if (
|
|
1777
|
+
obj &&
|
|
1778
|
+
objectIdOf(obj.type, obj.content, this.sha1 ? undefined : this.format.createHasher) !== id
|
|
1779
|
+
) {
|
|
1740
1780
|
this.error(`hash mismatch ${id}`, id);
|
|
1741
1781
|
return undefined;
|
|
1742
1782
|
}
|
|
@@ -1892,7 +1932,7 @@ class FsckRun {
|
|
|
1892
1932
|
const t = this.t;
|
|
1893
1933
|
const type = t.type(n);
|
|
1894
1934
|
if (type === OBJ_TREE) {
|
|
1895
|
-
const walk = scanTree(content, this.usedTable);
|
|
1935
|
+
const walk = scanTree(content, this.usedTable, this.format);
|
|
1896
1936
|
this.lastTree = { content, table: walk };
|
|
1897
1937
|
if (walk.initError) {
|
|
1898
1938
|
this.error(walk.initError);
|
|
@@ -1962,15 +2002,19 @@ class FsckRun {
|
|
|
1962
2002
|
(m) => this.error(m),
|
|
1963
2003
|
found,
|
|
1964
2004
|
last?.content === content ? last.table : undefined,
|
|
2005
|
+
this.format,
|
|
1965
2006
|
);
|
|
1966
2007
|
for (const g of found.gitmodules) this.gitmodulesFound.add(g);
|
|
1967
2008
|
for (const g of found.gitattributes) this.gitattributesFound.add(g);
|
|
1968
2009
|
return r;
|
|
1969
2010
|
}
|
|
1970
2011
|
case OBJ_COMMIT:
|
|
1971
|
-
return fsckCommit(content, report);
|
|
2012
|
+
return fsckCommit(content, report, this.format);
|
|
1972
2013
|
case OBJ_TAG:
|
|
1973
|
-
return fsckTag(content, report, {
|
|
2014
|
+
return fsckTag(content, report, {
|
|
2015
|
+
gpgsig: this.o.compatibility !== "2.43",
|
|
2016
|
+
shape: this.format,
|
|
2017
|
+
});
|
|
1974
2018
|
default:
|
|
1975
2019
|
return report("unknownType", `unknown type '${type}' (internal fsck error)`);
|
|
1976
2020
|
}
|
|
@@ -2054,6 +2098,7 @@ class FsckRun {
|
|
|
2054
2098
|
}
|
|
2055
2099
|
const read = await readLooseObject(files, e.path, e.id, {
|
|
2056
2100
|
bigFileThreshold: this.o.bigFileThreshold,
|
|
2101
|
+
newHasher: this.format.createHasher,
|
|
2057
2102
|
});
|
|
2058
2103
|
for (const m of read.errors) this.error(m, e.id);
|
|
2059
2104
|
if (read.errors.length > 0) this.badCopy.add(e.id);
|
|
@@ -2079,8 +2124,30 @@ class FsckRun {
|
|
|
2079
2124
|
}
|
|
2080
2125
|
|
|
2081
2126
|
/**
|
|
2082
|
-
* git's
|
|
2083
|
-
* is fine
|
|
2127
|
+
* git's check of each pack's `.rev` (`verify_reverse_indices`; 2.43's
|
|
2128
|
+
* check_pack_rev_indexes): a missing file is fine. True if one is wrong.
|
|
2129
|
+
*/
|
|
2130
|
+
private async verifyReverseIndexes(packs: readonly RepoPack[]): Promise<boolean> {
|
|
2131
|
+
const files = this.files as FilesApi;
|
|
2132
|
+
let bad = false;
|
|
2133
|
+
for (const p of packs) {
|
|
2134
|
+
const lines = await verifyReverseIndexFile(
|
|
2135
|
+
files,
|
|
2136
|
+
p.packPath,
|
|
2137
|
+
p.idx.objectCount,
|
|
2138
|
+
(i) => p.idx.getOffset(i),
|
|
2139
|
+
this.format,
|
|
2140
|
+
);
|
|
2141
|
+
if (!lines) continue;
|
|
2142
|
+
for (const line of lines) this.error(line.replace(/^error: /, ""));
|
|
2143
|
+
bad = true;
|
|
2144
|
+
}
|
|
2145
|
+
return bad;
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
/**
|
|
2149
|
+
* git's `verify_bitmap_files`: the trailing hash (SHA-1, or SHA-256 in a SHA-256 repository)
|
|
2150
|
+
* of each pack's `.bitmap` (a missing file is fine). True if one is wrong.
|
|
2084
2151
|
*/
|
|
2085
2152
|
private async verifyBitmapFiles(
|
|
2086
2153
|
packs: readonly RepoPack[],
|
|
@@ -2093,6 +2160,7 @@ class FsckRun {
|
|
|
2093
2160
|
if (this.o.multiPackIndex !== false) {
|
|
2094
2161
|
const loaded = await loadMultiPackIndex(files, pathOf(objectsDir, "pack"), {
|
|
2095
2162
|
compatibility: this.o.compatibility,
|
|
2163
|
+
objectFormat: this.format,
|
|
2096
2164
|
});
|
|
2097
2165
|
if (loaded.midx)
|
|
2098
2166
|
paths.push(pathOf(objectsDir, "pack", `multi-pack-index-${loaded.midx.checksum}.bitmap`));
|
|
@@ -2102,14 +2170,15 @@ class FsckRun {
|
|
|
2102
2170
|
const st = await files.stats(path).catch(() => undefined);
|
|
2103
2171
|
if (st?.kind !== "file") continue;
|
|
2104
2172
|
const size = st.size ?? 0;
|
|
2105
|
-
|
|
2173
|
+
const raw = this.format.rawLength;
|
|
2174
|
+
let valid = size >= raw;
|
|
2106
2175
|
if (valid) {
|
|
2107
|
-
const hasher =
|
|
2108
|
-
for await (const c of files.read(path, { start: 0, length: size -
|
|
2176
|
+
const hasher = this.format.createHasher();
|
|
2177
|
+
for await (const c of files.read(path, { start: 0, length: size - raw })) hasher.update(c);
|
|
2109
2178
|
const sum = hasher.digest();
|
|
2110
2179
|
const tail: number[] = [];
|
|
2111
|
-
for await (const c of files.read(path, { start: size -
|
|
2112
|
-
valid = tail.length ===
|
|
2180
|
+
for await (const c of files.read(path, { start: size - raw, length: raw })) tail.push(...c);
|
|
2181
|
+
valid = tail.length === raw && sum.every((b, i) => b === tail[i]);
|
|
2113
2182
|
}
|
|
2114
2183
|
if (!valid) {
|
|
2115
2184
|
this.error(`bitmap file '${path}' has invalid checksum`);
|
|
@@ -2183,6 +2252,7 @@ class FsckRun {
|
|
|
2183
2252
|
externalBase: (id) => this.readObject(id),
|
|
2184
2253
|
read: { bytes: p.idxBytes, idx: p.idx },
|
|
2185
2254
|
keepBlob: this.keepBlob,
|
|
2255
|
+
...(this.sha1 ? {} : { objectFormat: this.format }),
|
|
2186
2256
|
},
|
|
2187
2257
|
);
|
|
2188
2258
|
if (result.failed) err = 1;
|
|
@@ -2360,7 +2430,7 @@ class FsckRun {
|
|
|
2360
2430
|
|
|
2361
2431
|
/** git's `fsck_handle_reflog_oid`. */
|
|
2362
2432
|
private async handleReflogOid(refname: string, id: string, timestamp: number): Promise<void> {
|
|
2363
|
-
if (id
|
|
2433
|
+
if (isNullObjectId(id)) return;
|
|
2364
2434
|
const n = this.t.lookup(id);
|
|
2365
2435
|
if (n >= 0 && this.t.flags(n) & HAS_OBJ) {
|
|
2366
2436
|
if (timestamp) this.putName(id, `${refname}@{${timestamp}}`);
|
|
@@ -2378,9 +2448,9 @@ class FsckRun {
|
|
|
2378
2448
|
*/
|
|
2379
2449
|
private async resolvedId(name: string): Promise<string> {
|
|
2380
2450
|
try {
|
|
2381
|
-
return (await this.followChain(name, 0))?.id ||
|
|
2451
|
+
return (await this.followChain(name, 0))?.id || this.format.nullId;
|
|
2382
2452
|
} catch {
|
|
2383
|
-
return
|
|
2453
|
+
return this.format.nullId;
|
|
2384
2454
|
}
|
|
2385
2455
|
}
|
|
2386
2456
|
|
|
@@ -2434,7 +2504,7 @@ class FsckRun {
|
|
|
2434
2504
|
for (const name of [...new Set(listed)]) await snapshotRef(name, await this.resolvedId(name));
|
|
2435
2505
|
for (const wt of await this.worktrees()) {
|
|
2436
2506
|
const id = await this.headId(wt);
|
|
2437
|
-
if (id && id
|
|
2507
|
+
if (id && !isNullObjectId(id)) await snapshotRef(wt.headName, id);
|
|
2438
2508
|
}
|
|
2439
2509
|
return snapshot;
|
|
2440
2510
|
}
|
|
@@ -2473,8 +2543,10 @@ class FsckRun {
|
|
|
2473
2543
|
|
|
2474
2544
|
/** What a worktree's HEAD resolves to, if anything (within git's 5 reads, HEAD's included). */
|
|
2475
2545
|
private async headId(wt: WorktreeState): Promise<string | undefined> {
|
|
2476
|
-
|
|
2477
|
-
|
|
2546
|
+
// a reftable repository keeps a linked worktree's HEAD in that worktree's stack (its
|
|
2547
|
+
// `HEAD` file is git's `ref: refs/heads/.invalid` stub), read as `worktrees/<id>/HEAD`
|
|
2548
|
+
if (wt.current || this.isReftable()) {
|
|
2549
|
+
const head = await this.repositoryRefs().get(wt.headName);
|
|
2478
2550
|
if (!head) return undefined;
|
|
2479
2551
|
if (!isSymbolicRef(head)) return head.objectId;
|
|
2480
2552
|
return (await this.followChain(head.target, 1))?.id;
|
|
@@ -2482,7 +2554,8 @@ class FsckRun {
|
|
|
2482
2554
|
const text = (await readText(this.files as FilesApi, pathOf(wt.dir as string, "HEAD")))?.trim();
|
|
2483
2555
|
if (!text) return undefined;
|
|
2484
2556
|
if (text.startsWith("ref:")) return (await this.followChain(text.slice(4).trim(), 1))?.id;
|
|
2485
|
-
|
|
2557
|
+
const id = text.slice(0, this.format.hexLength);
|
|
2558
|
+
return OID.test(id) ? id : undefined;
|
|
2486
2559
|
}
|
|
2487
2560
|
|
|
2488
2561
|
/**
|
|
@@ -2497,6 +2570,10 @@ class FsckRun {
|
|
|
2497
2570
|
}
|
|
2498
2571
|
if (logName.startsWith("worktrees/")) {
|
|
2499
2572
|
if (!wt.dir || !logName.endsWith("/HEAD") || logName.split("/").length !== 3) return false;
|
|
2573
|
+
if (this.isReftable()) {
|
|
2574
|
+
const head = await this.repositoryRefs().get(logName);
|
|
2575
|
+
return !!head && isSymbolicRef(head) && !(await this.followChain(head.target, 1));
|
|
2576
|
+
}
|
|
2500
2577
|
const text = (await readText(this.files as FilesApi, pathOf(wt.dir, "HEAD")))?.trim();
|
|
2501
2578
|
return !!text?.startsWith("ref:") && !(await this.followChain(text.slice(4).trim(), 1));
|
|
2502
2579
|
}
|
|
@@ -2506,6 +2583,21 @@ class FsckRun {
|
|
|
2506
2583
|
}
|
|
2507
2584
|
}
|
|
2508
2585
|
|
|
2586
|
+
/**
|
|
2587
|
+
* The refs of the repository's own git directory: a reftable store opened for a linked
|
|
2588
|
+
* worktree reads that worktree's HEAD, so fsck asks the repository's store
|
|
2589
|
+
* (`ReftableRefStore.repositoryStore`) for the main worktree's; other stores as they are.
|
|
2590
|
+
*/
|
|
2591
|
+
private repositoryRefs(): Refs {
|
|
2592
|
+
const refs = this.stores.refs as Refs & { repositoryStore?(): Refs };
|
|
2593
|
+
return refs.repositoryStore?.() ?? refs;
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
/** Whether the refs are a reftable store (whose linked worktrees' HEADs are in their stacks). */
|
|
2597
|
+
private isReftable(): boolean {
|
|
2598
|
+
return "reflogNames" in this.stores.refs;
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2509
2601
|
/** The main worktree, then the linked ones (`.git/worktrees/<id>`). */
|
|
2510
2602
|
private async worktrees(): Promise<WorktreeState[]> {
|
|
2511
2603
|
const list: WorktreeState[] = [{ headName: "HEAD", dir: this.gitDir, current: true }];
|
|
@@ -2557,7 +2649,13 @@ class FsckRun {
|
|
|
2557
2649
|
};
|
|
2558
2650
|
let symref: string | undefined;
|
|
2559
2651
|
if (wt.current) {
|
|
2560
|
-
const head = await this.
|
|
2652
|
+
const head = await this.repositoryRefs().get("HEAD");
|
|
2653
|
+
if (!head) return invalid();
|
|
2654
|
+
if (isSymbolicRef(head)) symref = head.target;
|
|
2655
|
+
else id = head.objectId;
|
|
2656
|
+
} else if (this.isReftable()) {
|
|
2657
|
+
// a reftable repository: the linked worktree's HEAD is in its own stack
|
|
2658
|
+
const head = await this.repositoryRefs().get(name);
|
|
2561
2659
|
if (!head) return invalid();
|
|
2562
2660
|
if (isSymbolicRef(head)) symref = head.target;
|
|
2563
2661
|
else id = head.objectId;
|
|
@@ -2567,7 +2665,8 @@ class FsckRun {
|
|
|
2567
2665
|
)?.trim();
|
|
2568
2666
|
if (!text) return invalid();
|
|
2569
2667
|
if (text.startsWith("ref:")) symref = text.slice(4).trim();
|
|
2570
|
-
else if (OID.test(text.slice(0,
|
|
2668
|
+
else if (OID.test(text.slice(0, this.format.hexLength)))
|
|
2669
|
+
id = text.slice(0, this.format.hexLength);
|
|
2571
2670
|
else return invalid();
|
|
2572
2671
|
}
|
|
2573
2672
|
if (symref !== undefined) {
|
|
@@ -2582,10 +2681,10 @@ class FsckRun {
|
|
|
2582
2681
|
this.errorsFound |= FSCK_ERROR_REFS;
|
|
2583
2682
|
this.error(`${name} points to something strange (${target})`);
|
|
2584
2683
|
// git still takes what HEAD resolves to as a root
|
|
2585
|
-
if (id && id
|
|
2684
|
+
if (id && !isNullObjectId(id)) await this.handleRef(name, id);
|
|
2586
2685
|
return;
|
|
2587
2686
|
}
|
|
2588
|
-
if (!id || id
|
|
2687
|
+
if (!id || isNullObjectId(id)) {
|
|
2589
2688
|
if (target === undefined) {
|
|
2590
2689
|
this.errorsFound |= FSCK_ERROR_REFS;
|
|
2591
2690
|
this.error(`${name}: detached HEAD points at nothing`);
|
|
@@ -2604,6 +2703,15 @@ class FsckRun {
|
|
|
2604
2703
|
/** The reflogs of one worktree, in git's order (sorted by name, as git 2.45+ lists them). */
|
|
2605
2704
|
private async reflogs(wt: WorktreeState): Promise<Reflog[]> {
|
|
2606
2705
|
const files = this.files;
|
|
2706
|
+
// a reftable repository keeps its reflogs in its tables: listed by the ref store
|
|
2707
|
+
const reftable = this.repositoryRefs() as {
|
|
2708
|
+
reflogNames?(worktree?: string): Promise<string[]>;
|
|
2709
|
+
};
|
|
2710
|
+
if (reftable.reflogNames) {
|
|
2711
|
+
const dir = wt.dir as string;
|
|
2712
|
+
const id = wt.current ? undefined : dir.slice(dir.lastIndexOf("/") + 1);
|
|
2713
|
+
return this.storeReflogs(await reftable.reflogNames(id), this.repositoryRefs());
|
|
2714
|
+
}
|
|
2607
2715
|
if (!files) return wt.current ? this.storeReflogs() : [];
|
|
2608
2716
|
const logs: Reflog[] = [];
|
|
2609
2717
|
const collectDir = async (base: string, keep: (name: string) => boolean, prefix: string) => {
|
|
@@ -2624,7 +2732,7 @@ class FsckRun {
|
|
|
2624
2732
|
logs.push({
|
|
2625
2733
|
name: prefix + f.name,
|
|
2626
2734
|
path: pathOf(base, f.name),
|
|
2627
|
-
entries: parseReflog(await readText(files, f.path)),
|
|
2735
|
+
entries: parseReflog(await readText(files, f.path), this.format.hexLength),
|
|
2628
2736
|
});
|
|
2629
2737
|
}
|
|
2630
2738
|
};
|
|
@@ -2645,12 +2753,14 @@ class FsckRun {
|
|
|
2645
2753
|
}
|
|
2646
2754
|
|
|
2647
2755
|
/** Reflogs through the refs store (a store without files): HEAD and every ref. */
|
|
2648
|
-
private async storeReflogs(): Promise<Reflog[]> {
|
|
2649
|
-
const refs = this.stores.refs;
|
|
2756
|
+
private async storeReflogs(listed?: string[], refs = this.stores.refs): Promise<Reflog[]> {
|
|
2650
2757
|
if (!refs.getReflog) return [];
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2758
|
+
let sorted = listed;
|
|
2759
|
+
if (!sorted) {
|
|
2760
|
+
const names = ["HEAD"];
|
|
2761
|
+
for await (const ref of refs.list("refs/")) names.push(ref.name);
|
|
2762
|
+
sorted = [...new Set(names)].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
2763
|
+
}
|
|
2654
2764
|
const logs: Reflog[] = [];
|
|
2655
2765
|
for (const name of sorted) {
|
|
2656
2766
|
const reader = await refs.getReflog(name);
|
|
@@ -2692,13 +2802,17 @@ class FsckRun {
|
|
|
2692
2802
|
gitDir: wt.dir as string,
|
|
2693
2803
|
trees: this.stores.trees(),
|
|
2694
2804
|
verifyChecksum: true,
|
|
2805
|
+
objectFormat: this.format,
|
|
2695
2806
|
});
|
|
2696
2807
|
} catch (error) {
|
|
2697
2808
|
if (error instanceof IndexCorruptError) return error.lines;
|
|
2698
2809
|
// a sparse directory whose tree is missing: its own entry stands for it (the index
|
|
2699
2810
|
// and its shared index were hashed before the expansion failed)
|
|
2700
2811
|
try {
|
|
2701
|
-
read = await readIndexFileEntries(files, indexPath, {
|
|
2812
|
+
read = await readIndexFileEntries(files, indexPath, {
|
|
2813
|
+
gitDir: wt.dir as string,
|
|
2814
|
+
objectFormat: this.format,
|
|
2815
|
+
});
|
|
2702
2816
|
} catch (again) {
|
|
2703
2817
|
if (again instanceof IndexCorruptError) return again.lines;
|
|
2704
2818
|
throw again;
|
|
@@ -2715,8 +2829,9 @@ class FsckRun {
|
|
|
2715
2829
|
let cacheTree: CacheTree | undefined;
|
|
2716
2830
|
let resolveUndo: ResolveUndoRecord[] = [];
|
|
2717
2831
|
for (const ext of parsed.extensionData) {
|
|
2718
|
-
|
|
2719
|
-
|
|
2832
|
+
const raw = this.format.rawLength;
|
|
2833
|
+
if (ext.signature === "TREE") cacheTree = parseCacheTree(ext.data, raw);
|
|
2834
|
+
else if (ext.signature === "REUC") resolveUndo = parseResolveUndo(ext.data, raw);
|
|
2720
2835
|
}
|
|
2721
2836
|
await this.fsckIndex(entries, cacheTree, resolveUndo, indexPath, prefix);
|
|
2722
2837
|
}
|
|
@@ -2836,8 +2951,9 @@ class FsckRun {
|
|
|
2836
2951
|
const n = ns[pos] as number;
|
|
2837
2952
|
if (type === OBJ_COMMIT && decided && !decided[n]) {
|
|
2838
2953
|
decided[n] = 1;
|
|
2839
|
-
const
|
|
2840
|
-
|
|
2954
|
+
const raw = this.format.rawLength;
|
|
2955
|
+
const at = p.idx.version > 1 ? 8 + 1024 + pos * raw : 1024 + 4 + pos * (raw + 4);
|
|
2956
|
+
this.keepGraphCommit(bytesToHex(p.idxBytes.subarray(at, at + raw)), content);
|
|
2841
2957
|
}
|
|
2842
2958
|
if (type === OBJ_COMMIT && !withCommits) return;
|
|
2843
2959
|
if (claimed[n]) return;
|
|
@@ -2870,12 +2986,13 @@ class FsckRun {
|
|
|
2870
2986
|
// the entries as `scanTree` decodes them, for a tree it decodes without an error (any
|
|
2871
2987
|
// other is left to the walk, which reports it)
|
|
2872
2988
|
const len = content.length;
|
|
2873
|
-
|
|
2874
|
-
if (
|
|
2989
|
+
const raw = this.format.rawLength;
|
|
2990
|
+
if (len > 0 && (len < raw + 3 || content[len - raw - 1] !== 0)) return true;
|
|
2991
|
+
if (!this.reserveScanKids(1 + Math.floor(len / (raw + 3)))) return false;
|
|
2875
2992
|
const kids = this.scanKids;
|
|
2876
2993
|
let p = 0;
|
|
2877
2994
|
while (p < len) {
|
|
2878
|
-
if (len - p <
|
|
2995
|
+
if (len - p < raw + 3 || content[p] === 0x20) return true;
|
|
2879
2996
|
let mode = 0;
|
|
2880
2997
|
for (;;) {
|
|
2881
2998
|
const c = content[p++] as number;
|
|
@@ -2885,9 +3002,9 @@ class FsckRun {
|
|
|
2885
3002
|
}
|
|
2886
3003
|
if (content[p] === 0) return true;
|
|
2887
3004
|
while (p < len && content[p] !== 0) p++;
|
|
2888
|
-
if (p +
|
|
3005
|
+
if (p + 1 + raw > len) return true;
|
|
2889
3006
|
const idAt = p + 1;
|
|
2890
|
-
p = idAt +
|
|
3007
|
+
p = idAt + raw;
|
|
2891
3008
|
const format = mode & 0o170000;
|
|
2892
3009
|
// gitlinks are not walked (canon_mode makes every other format one)
|
|
2893
3010
|
if (format !== 0o100000 && format !== 0o120000 && format !== 0o040000) continue;
|
|
@@ -2896,7 +3013,7 @@ class FsckRun {
|
|
|
2896
3013
|
kids[at++] = (c << 1) | (format === 0o040000 ? 1 : 0);
|
|
2897
3014
|
}
|
|
2898
3015
|
} else {
|
|
2899
|
-
const parsed = parseCommitLinks(content, "");
|
|
3016
|
+
const parsed = parseCommitLinks(content, "", this.format);
|
|
2900
3017
|
if ("error" in parsed) return true;
|
|
2901
3018
|
if (!this.reserveScanKids(2 + parsed.parents.length)) return false;
|
|
2902
3019
|
const kids = this.scanKids;
|
|
@@ -3059,7 +3176,7 @@ class FsckRun {
|
|
|
3059
3176
|
return;
|
|
3060
3177
|
}
|
|
3061
3178
|
t.addFlags(n, PARSED);
|
|
3062
|
-
const walk = scanTree(obj.content, this.walkTable);
|
|
3179
|
+
const walk = scanTree(obj.content, this.walkTable, this.format);
|
|
3063
3180
|
if (walk.initError) {
|
|
3064
3181
|
this.error(walk.initError);
|
|
3065
3182
|
return;
|
|
@@ -3332,14 +3449,14 @@ async function readText(files: FilesApi, path: string): Promise<string | undefin
|
|
|
3332
3449
|
}
|
|
3333
3450
|
|
|
3334
3451
|
/** The entries of a reflog file, oldest first: old id, new id and the entry's timestamp. */
|
|
3335
|
-
function parseReflog(text: string | undefined): Reflog["entries"] {
|
|
3452
|
+
function parseReflog(text: string | undefined, hex = 40): Reflog["entries"] {
|
|
3336
3453
|
const entries: Reflog["entries"] = [];
|
|
3337
3454
|
for (const line of text?.split("\n") ?? []) {
|
|
3338
|
-
const oldId = line.slice(0,
|
|
3339
|
-
const newId = line.slice(
|
|
3455
|
+
const oldId = line.slice(0, hex);
|
|
3456
|
+
const newId = line.slice(hex + 1, 2 * hex + 1);
|
|
3340
3457
|
if (!OID.test(oldId) || !OID.test(newId)) continue;
|
|
3341
3458
|
const tab = line.indexOf("\t");
|
|
3342
|
-
const ident = tab < 0 ? line.slice(
|
|
3459
|
+
const ident = tab < 0 ? line.slice(2 * hex + 2) : line.slice(2 * hex + 2, tab);
|
|
3343
3460
|
const m = /> (\d+) [+-]\d{4}$/.exec(ident);
|
|
3344
3461
|
entries.push({ oldId, newId, timestamp: m ? Number(m[1]) : 0 });
|
|
3345
3462
|
}
|