@statewalker/vcs-commands 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-backend.d.ts +1 -1
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
- package/dist/commands/archive/archive-command.d.ts +6 -2
- package/dist/commands/archive/archive-command.d.ts.map +1 -1
- package/dist/commands/archive/remote-archive-command.d.ts +27 -2
- package/dist/commands/archive/remote-archive-command.d.ts.map +1 -1
- package/dist/commands/archive/upload-archive-writer.d.ts +11 -5
- package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +14 -2
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/bundle/bundle-format.d.ts +6 -1
- package/dist/commands/bundle/bundle-format.d.ts.map +1 -1
- package/dist/commands/bundle/bundle-uri-host.d.ts +12 -1
- package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -1
- package/dist/commands/bundle/bundle-uri.d.ts +7 -1
- package/dist/commands/bundle/bundle-uri.d.ts.map +1 -1
- package/dist/commands/bundle/bundle-verify.d.ts +4 -1
- package/dist/commands/bundle/bundle-verify.d.ts.map +1 -1
- package/dist/commands/cat-file/batch-format.d.ts +8 -12
- package/dist/commands/cat-file/batch-format.d.ts.map +1 -1
- package/dist/commands/cat-file/cat-file-command.d.ts +39 -5
- package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
- package/dist/commands/check-ignore-command.d.ts.map +1 -1
- package/dist/commands/checkout-command.d.ts +4 -0
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +9 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -1
- package/dist/commands/cherry-pick-command.d.ts +3 -0
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-interactive.d.ts +0 -9
- package/dist/commands/clean-interactive.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/column/column-config.d.ts +23 -0
- package/dist/commands/column/column-config.d.ts.map +1 -0
- package/dist/commands/column/column-layout.d.ts +129 -0
- package/dist/commands/column/column-layout.d.ts.map +1 -0
- package/dist/commands/column/index.d.ts +3 -0
- package/dist/commands/column/index.d.ts.map +1 -0
- package/dist/commands/column-command.d.ts +59 -0
- package/dist/commands/column-command.d.ts.map +1 -0
- package/dist/commands/comment-char-config.d.ts +15 -0
- package/dist/commands/comment-char-config.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +30 -2
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/config-command.d.ts +12 -0
- package/dist/commands/config-command.d.ts.map +1 -1
- package/dist/commands/credential-helper.d.ts +214 -0
- package/dist/commands/credential-helper.d.ts.map +1 -0
- package/dist/commands/default-branch.d.ts +33 -3
- package/dist/commands/default-branch.d.ts.map +1 -1
- package/dist/commands/diff-color-config.d.ts +4 -0
- package/dist/commands/diff-color-config.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +12 -0
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/fast-export/fast-export-command.d.ts +89 -2
- package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -1
- package/dist/commands/fast-export/fast-import-command.d.ts +113 -8
- package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -1
- package/dist/commands/fast-export/fast-stream-support.d.ts +0 -9
- package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -1
- package/dist/commands/fetch-command.d.ts +23 -1
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +31 -3
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/history-command.d.ts +173 -7
- package/dist/commands/history-command.d.ts.map +1 -1
- package/dist/commands/index-host.d.ts +19 -0
- package/dist/commands/index-host.d.ts.map +1 -1
- package/dist/commands/index-refresh.d.ts +36 -0
- package/dist/commands/index-refresh.d.ts.map +1 -0
- package/dist/commands/index.d.ts +9 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +7 -6
- package/dist/commands/init-command.d.ts +20 -0
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/local-transport.d.ts +40 -2
- package/dist/commands/local-transport.d.ts.map +1 -1
- package/dist/commands/log-command.d.ts +7 -0
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +11 -0
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/ls-tree-command.d.ts +10 -0
- package/dist/commands/ls-tree-command.d.ts.map +1 -1
- package/dist/commands/maintenance-schedule-command.d.ts +122 -0
- package/dist/commands/maintenance-schedule-command.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +13 -1
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-index-command.d.ts +42 -0
- package/dist/commands/merge-index-command.d.ts.map +1 -0
- package/dist/commands/merge-one-file.d.ts +129 -0
- package/dist/commands/merge-one-file.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +40 -4
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/object-disk-info.d.ts +35 -0
- package/dist/commands/object-disk-info.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +3 -3
- package/dist/commands/octopus-merge.d.ts.map +1 -1
- package/dist/commands/plumbing-input.d.ts.map +1 -1
- package/dist/commands/promisor-remote-reply.d.ts +31 -4
- package/dist/commands/promisor-remote-reply.d.ts.map +1 -1
- package/dist/commands/promisor-remote.d.ts +8 -1
- package/dist/commands/promisor-remote.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts +55 -7
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +18 -1
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/range-diff/range-diff-command.d.ts +37 -1
- package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +13 -1
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/ref-filter/for-each-ref-command.d.ts +3 -2
- package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -1
- package/dist/commands/ref-filter/index.d.ts +1 -0
- package/dist/commands/ref-filter/index.d.ts.map +1 -1
- package/dist/commands/ref-filter/peel-limit.d.ts +8 -0
- package/dist/commands/ref-filter/peel-limit.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -1
- package/dist/commands/ref-filter/ref-format.d.ts +26 -1
- package/dist/commands/ref-filter/ref-format.d.ts.map +1 -1
- package/dist/commands/ref-filter/ref-listing-command.d.ts +9 -0
- package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +27 -0
- package/dist/commands/remote-transport.d.ts.map +1 -1
- package/dist/commands/repack-command.d.ts +18 -2
- package/dist/commands/repack-command.d.ts.map +1 -1
- package/dist/commands/repo-command.d.ts +2 -7
- package/dist/commands/repo-command.d.ts.map +1 -1
- package/dist/commands/reset-command.d.ts +4 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts.map +1 -1
- package/dist/commands/rev-list-command.d.ts +65 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -1
- package/dist/commands/revert-command.d.ts +3 -0
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-filenames.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +17 -0
- package/dist/commands/revision-range.d.ts.map +1 -1
- package/dist/commands/revision-resolver.d.ts +12 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -1
- package/dist/commands/serve-repository.d.ts +21 -4
- package/dist/commands/serve-repository.d.ts.map +1 -1
- package/dist/commands/served-lazy-fetch.d.ts +61 -0
- package/dist/commands/served-lazy-fetch.d.ts.map +1 -0
- package/dist/commands/signing.d.ts +37 -4
- package/dist/commands/signing.d.ts.map +1 -1
- package/dist/commands/split-cmdline.d.ts +6 -0
- package/dist/commands/split-cmdline.d.ts.map +1 -0
- package/dist/commands/status-color-config.d.ts +33 -0
- package/dist/commands/status-color-config.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +15 -0
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-format.d.ts +46 -4
- package/dist/commands/status-format.d.ts.map +1 -1
- package/dist/commands/tag-command.d.ts +15 -1
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tree-restore.d.ts +14 -0
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/verify-command.d.ts +22 -2
- package/dist/commands/verify-command.d.ts.map +1 -1
- package/dist/commands/worktree-add-command.d.ts.map +1 -1
- package/dist/commands/worktree-overwrite-checks.d.ts +31 -6
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/{commands-CPceUCP2.js → commands-DT3VEv50.js} +15168 -16842
- package/dist/errors/commit-errors.d.ts +37 -1
- package/dist/errors/commit-errors.d.ts.map +1 -1
- package/dist/errors/git-api-error.d.ts +6 -0
- package/dist/errors/git-api-error.d.ts.map +1 -1
- package/dist/errors/index.js +44 -3
- package/dist/{fsck-tbrPZX2q.js → fsck-BZ508Elg.js} +2 -2
- package/dist/git-command.d.ts +33 -1
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +104 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/{remote-transport-C0OSJtor.js → local-transport-D98U6p4d.js} +228 -692
- package/dist/{maintenance-run-command-UiSIaeP8.js → maintenance-run-command-DZFnbnbo.js} +2366 -108
- package/dist/remote-config/remote-config-store.d.ts +6 -0
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-transport-zvSqwpOB.js +4865 -0
- package/dist/results/cherry-pick-result.d.ts +4 -3
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/diff-output.d.ts +7 -0
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/diff-words.d.ts +14 -3
- package/dist/results/diff-words.d.ts.map +1 -1
- package/dist/results/index.js +1 -1
- package/dist/results/line-prefix-sink.d.ts +50 -0
- package/dist/results/line-prefix-sink.d.ts.map +1 -0
- package/dist/results/merge-result.d.ts +4 -3
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/rebase-result.d.ts +5 -0
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +4 -3
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/{results-CkS1p1CH.js → results-rF81cQse.js} +1788 -247
- package/dist/transport-command.d.ts +13 -0
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +21 -13
- package/src/commands/add-command.ts +15 -2
- package/src/commands/add-patch/patch-backend.ts +6 -44
- package/src/commands/archive/archive-command.ts +7 -3
- package/src/commands/archive/remote-archive-command.ts +45 -4
- package/src/commands/archive/upload-archive-writer.ts +34 -22
- package/src/commands/branch-command.ts +57 -4
- package/src/commands/bundle/bundle-format.ts +10 -2
- package/src/commands/bundle/bundle-uri-host.ts +71 -11
- package/src/commands/bundle/bundle-uri.ts +11 -4
- package/src/commands/bundle/bundle-verify.ts +4 -1
- package/src/commands/cat-file/batch-format.ts +17 -18
- package/src/commands/cat-file/cat-file-command.ts +182 -48
- package/src/commands/check-ignore-command.ts +110 -21
- package/src/commands/checkout-command.ts +149 -21
- package/src/commands/checkout-index-command.ts +2 -1
- package/src/commands/checkout-paths.ts +13 -0
- package/src/commands/cherry-pick-command.ts +9 -0
- package/src/commands/clean-interactive.ts +20 -74
- package/src/commands/clone-command.ts +102 -11
- package/src/commands/column/column-config.ts +63 -0
- package/src/commands/column/column-layout.ts +396 -0
- package/src/commands/column/index.ts +2 -0
- package/src/commands/column-command.ts +171 -0
- package/src/commands/comment-char-config.ts +42 -0
- package/src/commands/commit-command.ts +93 -18
- package/src/commands/config-command.ts +28 -0
- package/src/commands/credential-helper.ts +807 -0
- package/src/commands/default-branch.ts +57 -5
- package/src/commands/diff-color-config.ts +23 -10
- package/src/commands/diff-command.ts +25 -2
- package/src/commands/fast-export/fast-export-command.ts +661 -35
- package/src/commands/fast-export/fast-import-command.ts +694 -94
- package/src/commands/fast-export/fast-stream-support.ts +18 -1
- package/src/commands/fetch-command.ts +116 -16
- package/src/commands/fsck/fsck-object-checks.ts +3 -1
- package/src/commands/git-hooks.ts +96 -5
- package/src/commands/history-command.ts +952 -20
- package/src/commands/index-host.ts +51 -0
- package/src/commands/index-refresh.ts +121 -0
- package/src/commands/index.ts +9 -0
- package/src/commands/init-command.ts +57 -4
- package/src/commands/legacy-remotes.ts +4 -20
- package/src/commands/local-transport.ts +183 -18
- package/src/commands/log-command.ts +39 -1
- package/src/commands/log-output.ts +31 -4
- package/src/commands/ls-tree-command.ts +20 -12
- package/src/commands/maintenance-schedule-command.ts +418 -0
- package/src/commands/merge-command.ts +42 -8
- package/src/commands/merge-index-command.ts +202 -0
- package/src/commands/merge-one-file.ts +451 -0
- package/src/commands/merge-support.ts +169 -15
- package/src/commands/object-disk-info.ts +169 -0
- package/src/commands/octopus-merge.ts +37 -128
- package/src/commands/plumbing-input.ts +3 -1
- package/src/commands/promisor-remote-reply.ts +338 -56
- package/src/commands/promisor-remote.ts +39 -6
- package/src/commands/pull-command.ts +173 -27
- package/src/commands/push-command.ts +55 -6
- package/src/commands/range-diff/range-diff-command.ts +86 -3
- package/src/commands/read-tree-command.ts +2 -2
- package/src/commands/rebase-command.ts +46 -1
- package/src/commands/ref-filter/for-each-ref-command.ts +4 -3
- package/src/commands/ref-filter/index.ts +1 -0
- package/src/commands/ref-filter/peel-limit.ts +7 -0
- package/src/commands/ref-filter/ref-filter.ts +68 -7
- package/src/commands/ref-filter/ref-format.ts +85 -11
- package/src/commands/ref-filter/ref-listing-command.ts +30 -0
- package/src/commands/remote-command.ts +2 -2
- package/src/commands/remote-transport.ts +66 -3
- package/src/commands/repack-command.ts +75 -9
- package/src/commands/repo-command.ts +6 -70
- package/src/commands/reset-command.ts +11 -1
- package/src/commands/restore-command.ts +1 -0
- package/src/commands/rev-list-command.ts +205 -3
- package/src/commands/revert-command.ts +9 -0
- package/src/commands/revision-filenames.ts +32 -4
- package/src/commands/revision-range.ts +2 -2
- package/src/commands/revision-resolver.ts +21 -1
- package/src/commands/serve-repository.ts +42 -11
- package/src/commands/served-lazy-fetch.ts +164 -0
- package/src/commands/signing.ts +103 -12
- package/src/commands/split-cmdline.ts +32 -0
- package/src/commands/status-color-config.ts +92 -0
- package/src/commands/status-command.ts +50 -2
- package/src/commands/status-format.ts +198 -50
- package/src/commands/tag-command.ts +57 -2
- package/src/commands/tree-restore.ts +17 -0
- package/src/commands/verify-command.ts +84 -12
- package/src/commands/worktree-add-command.ts +2 -0
- package/src/commands/worktree-overwrite-checks.ts +75 -14
- package/src/errors/commit-errors.ts +52 -2
- package/src/errors/git-api-error.ts +7 -0
- package/src/git-command.ts +105 -4
- package/src/git.ts +153 -0
- package/src/remote-config/remote-config-store.ts +16 -0
- package/src/results/cherry-pick-result.ts +4 -3
- package/src/results/diff-output.ts +8 -0
- package/src/results/diff-words.ts +160 -32
- package/src/results/line-prefix-sink.ts +102 -0
- package/src/results/merge-result.ts +4 -3
- package/src/results/rebase-result.ts +5 -0
- package/src/results/revert-result.ts +4 -3
- package/src/transport-command.ts +79 -3
|
@@ -15,8 +15,12 @@ import type { ObjectId } from "@statewalker/vcs-core";
|
|
|
15
15
|
import { isSymbolicRef, isValidRefName, isValidWorktreePath } from "@statewalker/vcs-core";
|
|
16
16
|
import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
17
17
|
import { cUnquote } from "../apply/latin1.js";
|
|
18
|
+
import { coreBool } from "../core-config.js";
|
|
18
19
|
import { localTimezoneOffset, parseGitDate } from "../git-date.js";
|
|
20
|
+
import { committerIdentOf } from "../git-ident.js";
|
|
19
21
|
import { PlumbingCommand, PlumbingError } from "../plumbing-command.js";
|
|
22
|
+
import { checkSignature, verifyCommitBytes } from "../signature-check.js";
|
|
23
|
+
import { SigningFailedError, signPayload } from "../signing.js";
|
|
20
24
|
import {
|
|
21
25
|
type FastMarksFiles,
|
|
22
26
|
isSignMode,
|
|
@@ -28,6 +32,52 @@ import {
|
|
|
28
32
|
writableSink,
|
|
29
33
|
} from "./fast-stream-support.js";
|
|
30
34
|
|
|
35
|
+
/**
|
|
36
|
+
* fast-import's `--signed-commits`/`--signed-tags` modes (gpg-interface.c's
|
|
37
|
+
* `parse_sign_mode`): those of {@link SignMode}, and the verifying ones of git 2.53+
|
|
38
|
+
* (`strip-if-invalid`) and 2.54+ (`sign-if-invalid[=<keyid>]`, `abort-if-invalid`).
|
|
39
|
+
*/
|
|
40
|
+
export type FastImportSignMode =
|
|
41
|
+
| SignMode
|
|
42
|
+
| "strip-if-invalid"
|
|
43
|
+
| "sign-if-invalid"
|
|
44
|
+
| `sign-if-invalid=${string}`
|
|
45
|
+
| "abort-if-invalid";
|
|
46
|
+
|
|
47
|
+
type ImportSignMode = Exclude<FastImportSignMode, `sign-if-invalid=${string}`>;
|
|
48
|
+
|
|
49
|
+
/** parse_sign_mode: the mode and the key of `sign-if-invalid=<keyid>`; undefined if unknown. */
|
|
50
|
+
function parseImportSignMode(value: string): { mode: ImportSignMode; keyid?: string } | undefined {
|
|
51
|
+
if (value.startsWith("sign-if-invalid=")) {
|
|
52
|
+
return { mode: "sign-if-invalid", keyid: value.slice("sign-if-invalid=".length) };
|
|
53
|
+
}
|
|
54
|
+
if (isSignMode(value)) return { mode: value };
|
|
55
|
+
if (["strip-if-invalid", "sign-if-invalid", "abort-if-invalid"].includes(value)) {
|
|
56
|
+
return { mode: value as ImportSignMode };
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isIfInvalid(mode: ImportSignMode): boolean {
|
|
62
|
+
return mode === "strip-if-invalid" || mode === "sign-if-invalid" || mode === "abort-if-invalid";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** find_commit_subject over a message alone: the first line after its first blank line. */
|
|
66
|
+
function subjectOfMessage(msg: string): string {
|
|
67
|
+
const at = msg.indexOf("\n\n");
|
|
68
|
+
if (at < 0) return "";
|
|
69
|
+
let p = at + 2;
|
|
70
|
+
// skip_blank_lines
|
|
71
|
+
for (;;) {
|
|
72
|
+
const nl = msg.indexOf("\n", p);
|
|
73
|
+
const line = nl < 0 ? msg.slice(p) : msg.slice(p, nl);
|
|
74
|
+
if (nl < 0 || line.trim() !== "") break;
|
|
75
|
+
p = nl + 1;
|
|
76
|
+
}
|
|
77
|
+
const eol = msg.indexOf("\n", p);
|
|
78
|
+
return eol < 0 ? msg.slice(p) : msg.slice(p, eol);
|
|
79
|
+
}
|
|
80
|
+
|
|
31
81
|
/** `--date-format=<fmt>` */
|
|
32
82
|
export type FastImportDateFormat = "raw" | "raw-permissive" | "rfc2822" | "now";
|
|
33
83
|
|
|
@@ -37,6 +87,7 @@ const S_IFREG = 0o100000;
|
|
|
37
87
|
const S_IFLNK = 0o120000;
|
|
38
88
|
const S_IFGITLINK = 0o160000;
|
|
39
89
|
const BRANCH_TABLE_SIZE = 1039;
|
|
90
|
+
const MAX_DEPTH = (1 << 13) - 1;
|
|
40
91
|
|
|
41
92
|
/** A tree entry being built (fast-import.c's tree_entry): `id` undefined while dirty. */
|
|
42
93
|
interface Node {
|
|
@@ -52,6 +103,8 @@ interface Branch {
|
|
|
52
103
|
oid: ObjectId | undefined;
|
|
53
104
|
root: Node;
|
|
54
105
|
delete: boolean;
|
|
106
|
+
/** The notes counted in the branch's tree (fast-import.c's uintmax_t num_notes) */
|
|
107
|
+
numNotes: bigint;
|
|
55
108
|
}
|
|
56
109
|
|
|
57
110
|
interface MarkedObject {
|
|
@@ -59,6 +112,16 @@ interface MarkedObject {
|
|
|
59
112
|
type: string;
|
|
60
113
|
}
|
|
61
114
|
|
|
115
|
+
/** uintmax_t's range: fast-import's note count wraps below zero */
|
|
116
|
+
const UINTMAX = (1n << 64n) - 1n;
|
|
117
|
+
|
|
118
|
+
/** convert_num_notes_to_fanout */
|
|
119
|
+
function noteFanoutOf(numNotes: bigint): number {
|
|
120
|
+
let fanout = 0;
|
|
121
|
+
for (let n = numNotes >> 8n; n > 0n; n >>= 8n) fanout++;
|
|
122
|
+
return fanout;
|
|
123
|
+
}
|
|
124
|
+
|
|
62
125
|
/** fast-import.c's hc_str over the name's bytes as signed chars. */
|
|
63
126
|
function hcStr(name: string): number {
|
|
64
127
|
let r = 0;
|
|
@@ -69,13 +132,20 @@ function hcStr(name: string): number {
|
|
|
69
132
|
return r;
|
|
70
133
|
}
|
|
71
134
|
|
|
72
|
-
/** Thrown to end the run where git dies (its message, without `fatal:
|
|
73
|
-
class FastImportDeath extends Error {
|
|
135
|
+
/** Thrown to end the run where git dies (its message, without `fatal: `; or whole lines). */
|
|
136
|
+
class FastImportDeath extends Error {
|
|
137
|
+
constructor(
|
|
138
|
+
message: string,
|
|
139
|
+
readonly lines?: string,
|
|
140
|
+
) {
|
|
141
|
+
super(message);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
74
144
|
|
|
75
145
|
/**
|
|
76
146
|
* Writes the objects and refs a fast-import stream describes (`git fast-import`).
|
|
77
147
|
*
|
|
78
|
-
* Supported: `blob`, `commit` (`M`, `D`, `R`, `C`, `deleteall`, `ls`, `cat-blob` among its
|
|
148
|
+
* Supported: `blob`, `commit` (`M`, `D`, `R`, `C`, `N`, `deleteall`, `ls`, `cat-blob` among its
|
|
79
149
|
* changes; `from`, `merge`, `encoding`, `original-oid`, and 2.5x's `gpgsig`), `tag`,
|
|
80
150
|
* `reset`, `checkpoint`, `progress`, `done`, `alias`, `get-mark`, `cat-blob`, `ls`,
|
|
81
151
|
* `feature` and `option git`; marks files through {@link setMarksFiles}. Branches are
|
|
@@ -84,12 +154,26 @@ class FastImportDeath extends Error {}
|
|
|
84
154
|
* unconditionally, every update logged as `fast-import`. Where git dies, the objects
|
|
85
155
|
* written so far stay, marks are exported, and no ref moves.
|
|
86
156
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
157
|
+
* Notes (`N <dataref> <commit-ish>`, `N inline`, a null id removing the note) are laid out
|
|
158
|
+
* with fast-import's fanout: one more level of two-digit directories for every factor of 256
|
|
159
|
+
* notes the branch holds, the tree re-fanned when a commit crosses a level (as
|
|
160
|
+
* `do_change_note_fanout`), so trees and commits are native git's.
|
|
161
|
+
*
|
|
162
|
+
* `rewrite-submodules-from`/`-to` ({@link addRewriteSubmodulesFrom}) rewrite every hex
|
|
163
|
+
* dataref (`M`, `N`, `ls`, `cat-blob`) one of a submodule's `from` marks names to the id of
|
|
164
|
+
* the same mark in its `to` marks, the files read through {@link setMarksFiles}.
|
|
165
|
+
*
|
|
166
|
+
* Not supported: the statistics report (`--stats`; ours prints none, as `--quiet`), the crash report file, and pack
|
|
89
167
|
* options (`--max-pack-size`, `--depth`, `--big-file-threshold`, accepted and ignored).
|
|
90
168
|
*
|
|
169
|
+
* Signature modes ({@link setSignedCommits}, {@link setSignedTags}) include git 2.53+'s
|
|
170
|
+
* verifying ones: each signature is checked through the host's verifier
|
|
171
|
+
* (`GitHostEnvironment.verifier`, as `verify-commit`/`verify-tag`); a bad one is stripped
|
|
172
|
+
* (`strip-if-invalid`), replaced through the host's signer (`sign-if-invalid[=<keyid>]`), or
|
|
173
|
+
* ends the import (`abort-if-invalid`).
|
|
174
|
+
*
|
|
91
175
|
* Version differences (`setCompatibility("2.43")`): no `gpgsig` commands and no signature
|
|
92
|
-
* modes, and git's capitalised death messages.
|
|
176
|
+
* modes (`--signed-*` is `unknown option`), and git's capitalised death messages.
|
|
93
177
|
*/
|
|
94
178
|
export class FastImportCommand extends PlumbingCommand {
|
|
95
179
|
private input: Uint8Array = new Uint8Array(0);
|
|
@@ -104,8 +188,11 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
104
188
|
private cliExportMarks?: string;
|
|
105
189
|
private cliRelativeMarks?: boolean;
|
|
106
190
|
private allowUnsafe = false;
|
|
107
|
-
|
|
108
|
-
private
|
|
191
|
+
/** The `--signed-*` options as given, in order (git 2.43 dies on the first) */
|
|
192
|
+
private readonly cliSignedOptions: string[] = [];
|
|
193
|
+
private cliSignedTags?: { mode: ImportSignMode; keyid?: string };
|
|
194
|
+
private cliSignedCommits?: { mode: ImportSignMode; keyid?: string };
|
|
195
|
+
private readonly cliRewriteSubmodules: { from: boolean; spec: string }[] = [];
|
|
109
196
|
|
|
110
197
|
// effective settings
|
|
111
198
|
private force = false;
|
|
@@ -115,8 +202,10 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
115
202
|
private importMarksFromStream = false;
|
|
116
203
|
private exportMarksFile?: { path: string; relative: boolean };
|
|
117
204
|
private relativeMarks = false;
|
|
118
|
-
private signedTags:
|
|
119
|
-
private signedCommits:
|
|
205
|
+
private signedTags: ImportSignMode = "verbatim";
|
|
206
|
+
private signedCommits: ImportSignMode = "verbatim";
|
|
207
|
+
private signedTagKeyid?: string;
|
|
208
|
+
private signedCommitKeyid?: string;
|
|
120
209
|
|
|
121
210
|
// the stream
|
|
122
211
|
private pos = 0;
|
|
@@ -127,6 +216,19 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
127
216
|
|
|
128
217
|
// the import's state
|
|
129
218
|
private readonly marks = new Map<number, MarkedObject>();
|
|
219
|
+
/** `core.ignorecase`: tree paths match ignoring ASCII case */
|
|
220
|
+
private ignoreCase = false;
|
|
221
|
+
/**
|
|
222
|
+
* Under `core.ignorecase`, the names of entries removed from a tree since it was last stored,
|
|
223
|
+
* by folded name: git leaves a removed entry in place (mode 0) until `store_tree`, so a later
|
|
224
|
+
* set of another spelling in the same tree reuses it and keeps the stored name.
|
|
225
|
+
*/
|
|
226
|
+
private removedNames = new WeakMap<Map<string, Node>, Map<string, string>>();
|
|
227
|
+
/** `rewrite-submodules-from`/`-to`: each submodule's marks, by name */
|
|
228
|
+
private readonly subMarksFrom = new Map<string, Map<number, ObjectId>>();
|
|
229
|
+
private readonly subMarksTo = new Map<string, Map<number, ObjectId>>();
|
|
230
|
+
/** the ids gitlinks (and every other hex dataref) are rewritten to */
|
|
231
|
+
private readonly subOidMap = new Map<ObjectId, ObjectId>();
|
|
130
232
|
private readonly objectTypes = new Map<ObjectId, string>();
|
|
131
233
|
private readonly branchTable: (Branch[] | undefined)[] = new Array(BRANCH_TABLE_SIZE);
|
|
132
234
|
private readonly branches = new Map<string, Branch>();
|
|
@@ -251,17 +353,46 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
251
353
|
return this;
|
|
252
354
|
}
|
|
253
355
|
|
|
254
|
-
/**
|
|
255
|
-
|
|
356
|
+
/**
|
|
357
|
+
* `--rewrite-submodules-from=<name>:<file>`: the marks file the submodule `<name>` was
|
|
358
|
+
* exported with; with the `to` file of the same name, every hex dataref (gitlinks first of
|
|
359
|
+
* all) that one of its ids names is rewritten to the id of the same mark in the `to` file.
|
|
360
|
+
*/
|
|
361
|
+
addRewriteSubmodulesFrom(spec: string): this {
|
|
362
|
+
this.checkCallable();
|
|
363
|
+
this.cliRewriteSubmodules.push({ from: true, spec });
|
|
364
|
+
return this;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** `--rewrite-submodules-to=<name>:<file>`: the marks file the submodule was imported with. */
|
|
368
|
+
addRewriteSubmodulesTo(spec: string): this {
|
|
256
369
|
this.checkCallable();
|
|
257
|
-
this.
|
|
370
|
+
this.cliRewriteSubmodules.push({ from: false, spec });
|
|
258
371
|
return this;
|
|
259
372
|
}
|
|
260
373
|
|
|
261
|
-
/**
|
|
262
|
-
|
|
374
|
+
/**
|
|
375
|
+
* `--signed-tags=<mode>` (git 2.50+, default `verbatim`). The verifying modes check each
|
|
376
|
+
* tag's signature through the host's verifier: a bad one is stripped, replaced through the
|
|
377
|
+
* host's signer (the configured key, or `sign-if-invalid=<keyid>`'s), or ends the import.
|
|
378
|
+
*/
|
|
379
|
+
setSignedTags(mode: FastImportSignMode): this {
|
|
263
380
|
this.checkCallable();
|
|
264
|
-
this.
|
|
381
|
+
this.cliSignedTags = parseImportSignMode(mode);
|
|
382
|
+
this.cliSignedOptions.push(`--signed-tags=${mode}`);
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* `--signed-commits=<mode>` (git 2.50+, default `verbatim`). The verifying modes check each
|
|
388
|
+
* commit's signature as `verify-commit` does: a bad one (or a commit with signatures of
|
|
389
|
+
* another hash only) is stripped with git's warning, replaced through the host's signer,
|
|
390
|
+
* or ends the import.
|
|
391
|
+
*/
|
|
392
|
+
setSignedCommits(mode: FastImportSignMode): this {
|
|
393
|
+
this.checkCallable();
|
|
394
|
+
this.cliSignedCommits = parseImportSignMode(mode);
|
|
395
|
+
this.cliSignedOptions.push(`--signed-commits=${mode}`);
|
|
265
396
|
return this;
|
|
266
397
|
}
|
|
267
398
|
|
|
@@ -287,6 +418,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
287
418
|
}
|
|
288
419
|
|
|
289
420
|
protected async run(): Promise<number> {
|
|
421
|
+
this.ignoreCase = coreBool(this.workingCopy, "ignorecase", false);
|
|
290
422
|
try {
|
|
291
423
|
while (await this.readNextCommand()) {
|
|
292
424
|
const cmd = this.line;
|
|
@@ -305,7 +437,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
305
437
|
else if (cmd.startsWith("progress ")) {
|
|
306
438
|
await this.write(latin1Bytes(`${cmd}\n`));
|
|
307
439
|
await this.skipOptionalLf();
|
|
308
|
-
} else if (cmd.startsWith("feature ")) this.parseFeature(cmd.slice(8));
|
|
440
|
+
} else if (cmd.startsWith("feature ")) await this.parseFeature(cmd.slice(8));
|
|
309
441
|
else if (cmd.startsWith("option git ")) this.parseOption(cmd.slice(11));
|
|
310
442
|
else if (cmd.startsWith("option ")) {
|
|
311
443
|
// non-git options are ignored
|
|
@@ -317,7 +449,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
317
449
|
if (!(e instanceof FastImportDeath)) throw e;
|
|
318
450
|
// die_nicely: the objects stay, the marks are dumped, no ref moves
|
|
319
451
|
await this.dumpMarks().catch(() => undefined);
|
|
320
|
-
throw new PlumbingError(`fatal: ${e.message}`);
|
|
452
|
+
throw new PlumbingError(e.lines ?? `fatal: ${e.message}`);
|
|
321
453
|
}
|
|
322
454
|
await this.dumpBranches();
|
|
323
455
|
await this.dumpTags();
|
|
@@ -421,12 +553,34 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
421
553
|
|
|
422
554
|
/** parse_argv: the command line's options win over the stream's features. */
|
|
423
555
|
private async parseArgv(): Promise<void> {
|
|
556
|
+
if (this.cliExportMarks !== undefined) {
|
|
557
|
+
this.exportMarksFile = { path: this.cliExportMarks, relative: this.relativeMarks };
|
|
558
|
+
}
|
|
559
|
+
for (const option of this.cliSignedOptions) {
|
|
560
|
+
// git 2.43 has no --signed-commits or --signed-tags
|
|
561
|
+
if (this.compatibility === "2.43") {
|
|
562
|
+
this.die(`unknown option ${option}`, `unknown option ${option}`);
|
|
563
|
+
}
|
|
564
|
+
const at = option.indexOf("=");
|
|
565
|
+
const value = option.slice(at + 1);
|
|
566
|
+
if (!parseImportSignMode(value)) {
|
|
567
|
+
// usagef: no crash report, no marks
|
|
568
|
+
const which = option.slice(2, at);
|
|
569
|
+
throw new PlumbingError(`usage: unknown --${which} mode '${value}'`, 129);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
424
572
|
if (this.cliForce !== undefined) this.force = this.cliForce;
|
|
425
573
|
if (this.cliDone !== undefined) this.requireDone = this.cliDone;
|
|
426
574
|
if (this.cliDateFormat !== undefined) this.dateFormat = this.cliDateFormat;
|
|
427
575
|
if (this.cliRelativeMarks !== undefined) this.relativeMarks = this.cliRelativeMarks;
|
|
428
|
-
if (this.cliSignedTags !== undefined)
|
|
429
|
-
|
|
576
|
+
if (this.cliSignedTags !== undefined) {
|
|
577
|
+
this.signedTags = this.cliSignedTags.mode;
|
|
578
|
+
this.signedTagKeyid = this.cliSignedTags.keyid;
|
|
579
|
+
}
|
|
580
|
+
if (this.cliSignedCommits !== undefined) {
|
|
581
|
+
this.signedCommits = this.cliSignedCommits.mode;
|
|
582
|
+
this.signedCommitKeyid = this.cliSignedCommits.keyid;
|
|
583
|
+
}
|
|
430
584
|
if (this.cliImportMarks) {
|
|
431
585
|
if (this.importMarksFile && !this.importMarksFromStream) await this.readMarks();
|
|
432
586
|
this.importMarksFile = {
|
|
@@ -439,8 +593,21 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
439
593
|
if (this.cliExportMarks !== undefined) {
|
|
440
594
|
this.exportMarksFile = { path: this.cliExportMarks, relative: this.relativeMarks };
|
|
441
595
|
}
|
|
596
|
+
for (const { from, spec } of this.cliRewriteSubmodules) {
|
|
597
|
+
await this.optionRewriteSubmodules(spec, from ? this.subMarksFrom : this.subMarksTo);
|
|
598
|
+
}
|
|
442
599
|
this.seenDataCommand = true;
|
|
443
600
|
if (this.importMarksFile) await this.readMarks();
|
|
601
|
+
this.buildMarkMap();
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** ulong_arg: strtoul's number (base 0), refused when negative or followed by anything. */
|
|
605
|
+
private ulongArg(option: string, arg: string): number {
|
|
606
|
+
const m = /^\s*\+?(0[xX][0-9a-fA-F]+|0[0-7]*|[1-9][0-9]*)/.exec(arg);
|
|
607
|
+
if (arg.includes("-") || !m || m[0].length !== arg.length) {
|
|
608
|
+
this.die(`${option}: argument must be a non-negative integer`);
|
|
609
|
+
}
|
|
610
|
+
return strtoulValue((m as RegExpExecArray)[1] as string);
|
|
444
611
|
}
|
|
445
612
|
|
|
446
613
|
private checkUnsafe(feature: string, kind: "feature" | "option" = "feature"): void {
|
|
@@ -449,7 +616,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
449
616
|
}
|
|
450
617
|
}
|
|
451
618
|
|
|
452
|
-
private parseFeature(feature: string): void {
|
|
619
|
+
private async parseFeature(feature: string): Promise<void> {
|
|
453
620
|
if (this.seenDataCommand) this.die(`got feature command '${feature}' after data command`);
|
|
454
621
|
const value = (prefix: string) =>
|
|
455
622
|
feature.startsWith(prefix) ? feature.slice(prefix.length) : undefined;
|
|
@@ -457,6 +624,8 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
457
624
|
const importMarks = value("import-marks=");
|
|
458
625
|
const importMarksIfExists = value("import-marks-if-exists=");
|
|
459
626
|
const exportMarks = value("export-marks=");
|
|
627
|
+
const rewriteTo = value("rewrite-submodules-to=");
|
|
628
|
+
const rewriteFrom = value("rewrite-submodules-from=");
|
|
460
629
|
if (dateFormat !== undefined) {
|
|
461
630
|
this.dateFormat = parseDateFormat(dateFormat, (m) => this.die(m));
|
|
462
631
|
} else if (importMarks !== undefined) {
|
|
@@ -468,6 +637,15 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
468
637
|
} else if (exportMarks !== undefined) {
|
|
469
638
|
this.checkUnsafe(feature);
|
|
470
639
|
this.exportMarksFile = { path: exportMarks, relative: this.relativeMarks };
|
|
640
|
+
} else if (rewriteTo !== undefined) {
|
|
641
|
+
// git 2.43 let a stream name these files without --allow-unsafe-features; ours refuses
|
|
642
|
+
// under 2.43 compatibility too (a deliberate divergence: a stream never reads a file
|
|
643
|
+
// the caller did not allow)
|
|
644
|
+
this.checkUnsafe("rewrite-submodules-to");
|
|
645
|
+
await this.optionRewriteSubmodules(rewriteTo, this.subMarksTo);
|
|
646
|
+
} else if (rewriteFrom !== undefined) {
|
|
647
|
+
this.checkUnsafe("rewrite-submodules-from");
|
|
648
|
+
await this.optionRewriteSubmodules(rewriteFrom, this.subMarksFrom);
|
|
471
649
|
} else if (feature === "relative-marks") this.relativeMarks = true;
|
|
472
650
|
else if (feature === "no-relative-marks") this.relativeMarks = false;
|
|
473
651
|
else if (feature === "done") this.requireDone = true;
|
|
@@ -490,19 +668,43 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
490
668
|
|
|
491
669
|
private parseOption(option: string): void {
|
|
492
670
|
if (this.seenDataCommand) this.die(`got option command '${option}' after data command`);
|
|
493
|
-
|
|
494
|
-
option.startsWith(
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
671
|
+
const value = (prefix: string) =>
|
|
672
|
+
option.startsWith(prefix) ? option.slice(prefix.length) : undefined;
|
|
673
|
+
const depth = value("depth=");
|
|
674
|
+
const activeBranches = value("active-branches=");
|
|
675
|
+
if (depth !== undefined) {
|
|
676
|
+
if (this.ulongArg("--depth", depth) > MAX_DEPTH)
|
|
677
|
+
this.die(`--depth cannot exceed ${MAX_DEPTH}`);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
if (activeBranches !== undefined) {
|
|
681
|
+
this.ulongArg("--active-branches", activeBranches);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
for (const name of ["max-pack-size", "big-file-threshold"]) {
|
|
685
|
+
const v = value(`${name}=`);
|
|
686
|
+
if (v === undefined) continue;
|
|
687
|
+
const parsed = parseGitUlong(v);
|
|
688
|
+
if (parsed === undefined) {
|
|
689
|
+
// git 2.43 took a bad value for an unknown option
|
|
690
|
+
if (this.compatibility === "2.43") {
|
|
691
|
+
this.die("", `This version of fast-import does not support option: ${option}`);
|
|
692
|
+
}
|
|
693
|
+
this.die(`--${name}: argument must be a non-negative integer`);
|
|
694
|
+
}
|
|
695
|
+
if (name === "max-pack-size" && (parsed as number) < 8192) {
|
|
696
|
+
this.warn(`warning: max-pack-size is now in bytes, assuming --max-pack-size=${parsed}m`);
|
|
697
|
+
} else if (name === "max-pack-size" && (parsed as number) < 1024 * 1024) {
|
|
698
|
+
this.warn("warning: minimum max-pack-size is 1 MiB");
|
|
699
|
+
}
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (option === "stats" || option === "quiet" || option === "allow-unsafe-features") {
|
|
502
703
|
return;
|
|
503
704
|
}
|
|
504
705
|
if (option.startsWith("export-pack-edges=")) {
|
|
505
|
-
this
|
|
706
|
+
// git 2.43 let a stream name this file without --allow-unsafe-features
|
|
707
|
+
if (this.compatibility !== "2.43") this.checkUnsafe("export-pack-edges", "option");
|
|
506
708
|
return;
|
|
507
709
|
}
|
|
508
710
|
const mode = option.startsWith("signed-commits=")
|
|
@@ -512,9 +714,17 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
512
714
|
: undefined;
|
|
513
715
|
if (mode && this.compatibility !== "2.43") {
|
|
514
716
|
const value = option.slice(option.indexOf("=") + 1);
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
717
|
+
const parsed = parseImportSignMode(value);
|
|
718
|
+
// usagef: no crash report, no marks
|
|
719
|
+
if (!parsed) throw new PlumbingError(`usage: unknown --signed-${mode} mode '${value}'`, 129);
|
|
720
|
+
const { mode: m, keyid } = parsed as { mode: ImportSignMode; keyid?: string };
|
|
721
|
+
if (mode === "commits") {
|
|
722
|
+
this.signedCommits = m;
|
|
723
|
+
this.signedCommitKeyid = keyid;
|
|
724
|
+
} else {
|
|
725
|
+
this.signedTags = m;
|
|
726
|
+
this.signedTagKeyid = keyid;
|
|
727
|
+
}
|
|
518
728
|
return;
|
|
519
729
|
}
|
|
520
730
|
this.die(
|
|
@@ -541,16 +751,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
541
751
|
}
|
|
542
752
|
this.die(`cannot read '${file.path}': No such file or directory`);
|
|
543
753
|
}
|
|
544
|
-
const
|
|
545
|
-
let at = 0;
|
|
546
|
-
while (at < text.length) {
|
|
547
|
-
const nl = text.indexOf("\n", at);
|
|
548
|
-
const line = nl < 0 ? text.slice(at) : text.slice(at, nl);
|
|
549
|
-
at = nl < 0 ? text.length : nl + 1;
|
|
550
|
-
const m = /^:(\d+) ([0-9a-fA-F]{40}|[0-9a-fA-F]{64})/.exec(line);
|
|
551
|
-
if (!m || nl < 0 || Number(m[1]) === 0) this.die(`corrupt mark line: ${line}`);
|
|
552
|
-
const mark = Number((m as RegExpExecArray)[1]);
|
|
553
|
-
const id = ((m as RegExpExecArray)[2] as string).toLowerCase();
|
|
754
|
+
for (const [mark, id] of this.readMarkFile(bytes as Uint8Array)) {
|
|
554
755
|
let type = this.objectTypes.get(id);
|
|
555
756
|
if (!type) {
|
|
556
757
|
type = await this.odbType(id);
|
|
@@ -562,6 +763,73 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
562
763
|
this.importMarksDone = true;
|
|
563
764
|
}
|
|
564
765
|
|
|
766
|
+
/** read_mark_file: each `:<mark> <id>` line in order (an id of either hash). */
|
|
767
|
+
private *readMarkFile(bytes: Uint8Array): Generator<[number, ObjectId]> {
|
|
768
|
+
const text = latin1(bytes);
|
|
769
|
+
let at = 0;
|
|
770
|
+
while (at < text.length) {
|
|
771
|
+
const nl = text.indexOf("\n", at);
|
|
772
|
+
// fgets: the line keeps its newline while git has not cut it
|
|
773
|
+
const raw = nl < 0 ? text.slice(at) : text.slice(at, nl + 1);
|
|
774
|
+
at = nl < 0 ? text.length : nl + 1;
|
|
775
|
+
if (raw[0] !== ":" || nl < 0) this.die(`corrupt mark line: ${raw}`);
|
|
776
|
+
const line = raw.slice(0, -1);
|
|
777
|
+
const m = /^:(\d+) /.exec(line);
|
|
778
|
+
const hex = m ? hexIdAt(line, m[0].length) : undefined;
|
|
779
|
+
if (!m || Number(m[1]) === 0 || !hex) this.die(`corrupt mark line: ${line}`);
|
|
780
|
+
yield [Number((m as RegExpExecArray)[1]), (hex as string).toLowerCase()];
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/** option_rewrite_submodules: `<name>:<file>`, the file read now. */
|
|
785
|
+
private async optionRewriteSubmodules(
|
|
786
|
+
arg: string,
|
|
787
|
+
list: Map<string, Map<number, ObjectId>>,
|
|
788
|
+
): Promise<void> {
|
|
789
|
+
const colon = arg.indexOf(":");
|
|
790
|
+
if (colon < 0) this.die("expected format name:filename for submodule rewrite option");
|
|
791
|
+
const name = arg.slice(0, colon);
|
|
792
|
+
const file = arg.slice(colon + 1);
|
|
793
|
+
const bytes = await this.marksFilesOrDie().read(file, { relative: false });
|
|
794
|
+
if (bytes === undefined) this.die(`cannot read '${file}': No such file or directory`);
|
|
795
|
+
const marks = new Map<number, ObjectId>();
|
|
796
|
+
for (const [mark, id] of this.readMarkFile(bytes as Uint8Array)) marks.set(mark, id);
|
|
797
|
+
list.set(name, marks);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/** build_mark_map: each `from` id to the id of its mark in the submodule's `to` file. */
|
|
801
|
+
private buildMarkMap(): void {
|
|
802
|
+
this.subOidMap.clear();
|
|
803
|
+
const names = [...this.subMarksFrom.keys()].sort(compareBinary);
|
|
804
|
+
for (const name of names) {
|
|
805
|
+
const to = this.subMarksTo.get(name);
|
|
806
|
+
if (!to) this.die(`missing to marks for submodule '${name}'`);
|
|
807
|
+
const from = this.subMarksFrom.get(name) as Map<number, ObjectId>;
|
|
808
|
+
for (const mark of [...from.keys()].sort((a, b) => a - b)) {
|
|
809
|
+
const toId = (to as Map<number, ObjectId>).get(mark);
|
|
810
|
+
if (toId === undefined)
|
|
811
|
+
this.die(`mark :${mark} not declared`, `mark :${mark} not declared`);
|
|
812
|
+
const fromId = from.get(mark) as ObjectId;
|
|
813
|
+
if (!this.subOidMap.has(fromId)) this.subOidMap.set(fromId, toId as ObjectId);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* parse_mapped_oid_hex: an id of either hash at the start of `text` (SHA-256's tried
|
|
820
|
+
* first), through the submodule rewrite map; one of another hash than the repository's
|
|
821
|
+
* that nothing maps is no id.
|
|
822
|
+
*/
|
|
823
|
+
private parseMappedOidHex(text: string): { id: ObjectId; rest: string } | undefined {
|
|
824
|
+
const hex = hexIdAt(text, 0);
|
|
825
|
+
if (!hex) return undefined;
|
|
826
|
+
const rest = text.slice(hex.length);
|
|
827
|
+
const mapped = this.subOidMap.get(hex.toLowerCase());
|
|
828
|
+
if (mapped !== undefined) return { id: mapped, rest };
|
|
829
|
+
if (hex.length !== this.objectFormat.hexLength) return undefined;
|
|
830
|
+
return { id: hex.toLowerCase(), rest };
|
|
831
|
+
}
|
|
832
|
+
|
|
565
833
|
private async dumpMarks(): Promise<void> {
|
|
566
834
|
const file = this.exportMarksFile;
|
|
567
835
|
if (!file || (this.importMarksFile && !this.importMarksDone)) return;
|
|
@@ -726,6 +994,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
726
994
|
oid: undefined,
|
|
727
995
|
root: { mode: S_IFDIR, id: undefined, entries: new Map() },
|
|
728
996
|
delete: false,
|
|
997
|
+
numNotes: 0n,
|
|
729
998
|
};
|
|
730
999
|
const hc = hcStr(decodeGitPath(latin1Bytes(name))) % BRANCH_TABLE_SIZE;
|
|
731
1000
|
const bucket = this.branchTable[hc] ?? [];
|
|
@@ -748,6 +1017,19 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
748
1017
|
return entries;
|
|
749
1018
|
}
|
|
750
1019
|
|
|
1020
|
+
/**
|
|
1021
|
+
* The entry a tree walk takes for `name`: under `core.ignorecase` the first one whose name
|
|
1022
|
+
* matches ignoring ASCII case (fast-import.c's `fspathncmp`), the name it was stored under
|
|
1023
|
+
* kept.
|
|
1024
|
+
*/
|
|
1025
|
+
private findEntry(entries: Map<string, Node>, name: string): [string, Node] | undefined {
|
|
1026
|
+
const exact = entries.get(name);
|
|
1027
|
+
if (!this.ignoreCase) return exact ? [name, exact] : undefined;
|
|
1028
|
+
const folded = asciiLower(name);
|
|
1029
|
+
for (const entry of entries) if (asciiLower(entry[0]) === folded) return entry;
|
|
1030
|
+
return undefined;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
751
1033
|
/** tree_content_set */
|
|
752
1034
|
private async treeSet(
|
|
753
1035
|
root: Node,
|
|
@@ -761,7 +1043,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
761
1043
|
if (!name) this.die("empty path component found in input");
|
|
762
1044
|
if (!isDir(root.mode)) this.die("non-directories cannot have subtrees");
|
|
763
1045
|
const entries = await this.loadTree(root);
|
|
764
|
-
let e =
|
|
1046
|
+
let e = this.findEntry(entries, name)?.[1];
|
|
765
1047
|
if (e) {
|
|
766
1048
|
if (slash < 0) {
|
|
767
1049
|
if (!isDir(mode) && e.mode === mode && e.id === id) return false;
|
|
@@ -783,7 +1065,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
783
1065
|
return false;
|
|
784
1066
|
}
|
|
785
1067
|
e = { mode: S_IFDIR, id: undefined, entries: new Map() };
|
|
786
|
-
entries.set(name, e);
|
|
1068
|
+
entries.set(this.ignoreCase ? this.revivedName(entries, name) : name, e);
|
|
787
1069
|
if (slash < 0) {
|
|
788
1070
|
e.mode = mode;
|
|
789
1071
|
e.id = id;
|
|
@@ -811,11 +1093,11 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
811
1093
|
}
|
|
812
1094
|
const slash = path.indexOf("/");
|
|
813
1095
|
const name = slash < 0 ? path : path.slice(0, slash);
|
|
814
|
-
const e =
|
|
1096
|
+
const [key, e] = this.findEntry(entries, name) ?? [name, undefined];
|
|
815
1097
|
if (!e || (name === "" && slash >= 0)) return undefined;
|
|
816
1098
|
if (slash >= 0 && !isDir(e.mode)) return true;
|
|
817
1099
|
if (slash < 0 || !isDir(e.mode)) {
|
|
818
|
-
|
|
1100
|
+
this.removeEntry(entries, key);
|
|
819
1101
|
root.id = undefined;
|
|
820
1102
|
return e;
|
|
821
1103
|
}
|
|
@@ -825,18 +1107,45 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
825
1107
|
root.id = undefined;
|
|
826
1108
|
return removed;
|
|
827
1109
|
}
|
|
828
|
-
|
|
1110
|
+
this.removeEntry(entries, key);
|
|
829
1111
|
root.id = undefined;
|
|
830
1112
|
return removed;
|
|
831
1113
|
}
|
|
832
1114
|
|
|
1115
|
+
private removeEntry(entries: Map<string, Node>, key: string): void {
|
|
1116
|
+
entries.delete(key);
|
|
1117
|
+
if (!this.ignoreCase) return;
|
|
1118
|
+
let names = this.removedNames.get(entries);
|
|
1119
|
+
if (!names) {
|
|
1120
|
+
names = new Map();
|
|
1121
|
+
this.removedNames.set(entries, names);
|
|
1122
|
+
}
|
|
1123
|
+
const folded = asciiLower(key);
|
|
1124
|
+
if (!names.has(folded)) names.set(folded, key);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
/** The name a new entry takes: that of an entry of its spelling removed before the store. */
|
|
1128
|
+
private revivedName(entries: Map<string, Node>, name: string): string {
|
|
1129
|
+
const names = this.removedNames.get(entries);
|
|
1130
|
+
const folded = asciiLower(name);
|
|
1131
|
+
const stored = names?.get(folded);
|
|
1132
|
+
if (stored === undefined) return name;
|
|
1133
|
+
names?.delete(folded);
|
|
1134
|
+
return stored;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
833
1137
|
/** tree_content_get */
|
|
834
1138
|
private async treeGet(root: Node, path: string, allowRoot: boolean): Promise<Node | undefined> {
|
|
835
1139
|
if (!path && allowRoot) return cloneNode(root);
|
|
836
|
-
const entries = await this.loadTree(root);
|
|
837
1140
|
const slash = path.indexOf("/");
|
|
838
1141
|
const name = slash < 0 ? path : path.slice(0, slash);
|
|
839
|
-
|
|
1142
|
+
if (!name) {
|
|
1143
|
+
// tree_content_get: an empty first component is the root, whatever follows it
|
|
1144
|
+
if (!allowRoot) this.die("empty path component found in input");
|
|
1145
|
+
return cloneNode(root);
|
|
1146
|
+
}
|
|
1147
|
+
const entries = await this.loadTree(root);
|
|
1148
|
+
const e = this.findEntry(entries, name)?.[1];
|
|
840
1149
|
if (!e) return undefined;
|
|
841
1150
|
if (slash < 0) return cloneNode(e);
|
|
842
1151
|
if (!isDir(e.mode)) return undefined;
|
|
@@ -847,6 +1156,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
847
1156
|
private async storeTree(node: Node): Promise<ObjectId> {
|
|
848
1157
|
if (node.id !== undefined) return node.id;
|
|
849
1158
|
const entries = await this.loadTree(node);
|
|
1159
|
+
this.removedNames.delete(entries);
|
|
850
1160
|
for (const e of entries.values())
|
|
851
1161
|
if (isDir(e.mode) && e.id === undefined) await this.storeTree(e);
|
|
852
1162
|
const sorted = [...entries.entries()].sort(([a, x], [b, y]) =>
|
|
@@ -863,8 +1173,23 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
863
1173
|
// ---------------------------------------------------------------- paths
|
|
864
1174
|
|
|
865
1175
|
/** parse_path: a quoted or plain path, and what follows it */
|
|
866
|
-
private parsePath(
|
|
867
|
-
|
|
1176
|
+
private parsePath(
|
|
1177
|
+
text: string,
|
|
1178
|
+
last: boolean,
|
|
1179
|
+
field: string,
|
|
1180
|
+
strict = false,
|
|
1181
|
+
): { path: string; rest: string } {
|
|
1182
|
+
// git 2.43 took a path whose unquoting failed as written (its `ls` alone refused it),
|
|
1183
|
+
// and one that unquoted only up to a NUL
|
|
1184
|
+
if (this.compatibility === "2.43" && text.startsWith('"')) {
|
|
1185
|
+
const unq = cUnquote(text, 0);
|
|
1186
|
+
if (!unq && strict)
|
|
1187
|
+
this.die(`invalid ${field}: ${this.line}`, `Invalid ${field}: ${this.line}`);
|
|
1188
|
+
if (unq) {
|
|
1189
|
+
const nul = unq.name.indexOf("\0");
|
|
1190
|
+
return { path: nul < 0 ? unq.name : unq.name.slice(0, nul), rest: text.slice(unq.end) };
|
|
1191
|
+
}
|
|
1192
|
+
} else if (text.startsWith('"')) {
|
|
868
1193
|
const unq = cUnquote(text, 0);
|
|
869
1194
|
if (!unq) this.die(`invalid ${field}: ${this.line}`, `Invalid ${field}: ${this.line}`);
|
|
870
1195
|
const { name, end } = unq as { name: string; end: number };
|
|
@@ -878,8 +1203,8 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
878
1203
|
: { path: text.slice(0, space), rest: text.slice(space) };
|
|
879
1204
|
}
|
|
880
1205
|
|
|
881
|
-
private parsePathEol(text: string, field: string): string {
|
|
882
|
-
const { path, rest } = this.parsePath(text, true, field);
|
|
1206
|
+
private parsePathEol(text: string, field: string, strict = false): string {
|
|
1207
|
+
const { path, rest } = this.parsePath(text, true, field, strict);
|
|
883
1208
|
if (rest !== "") {
|
|
884
1209
|
this.die(`garbage after ${field}: ${this.line}`, `Garbage after ${field} in: ${this.line}`);
|
|
885
1210
|
}
|
|
@@ -891,7 +1216,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
891
1216
|
if (this.compatibility === "2.43") return;
|
|
892
1217
|
const ok = isValidWorktreePath(decodeGitPath(latin1Bytes(path)), mode, {
|
|
893
1218
|
protectHFS: false,
|
|
894
|
-
protectNTFS: true,
|
|
1219
|
+
protectNTFS: coreBool(this.workingCopy, "protectNTFS", true),
|
|
895
1220
|
});
|
|
896
1221
|
if (!ok) this.die(`invalid path '${path}'`, `Invalid path: ${path}`);
|
|
897
1222
|
}
|
|
@@ -930,15 +1255,12 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
930
1255
|
inline = true;
|
|
931
1256
|
p = p.slice(7);
|
|
932
1257
|
} else {
|
|
933
|
-
const
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
this.die(`invalid dataref: ${this.line}`);
|
|
937
|
-
}
|
|
938
|
-
id = candidate.toLowerCase();
|
|
1258
|
+
const parsed = this.parseMappedOidHex(p);
|
|
1259
|
+
if (!parsed) this.die(`invalid dataref: ${this.line}`);
|
|
1260
|
+
({ id, rest: p } = parsed as { id: ObjectId; rest: string });
|
|
939
1261
|
knownType = this.objectTypes.get(id);
|
|
940
|
-
if (p[
|
|
941
|
-
p = p.slice(
|
|
1262
|
+
if (p[0] !== " ") this.die(`missing space after SHA1: ${this.line}`);
|
|
1263
|
+
p = p.slice(1);
|
|
942
1264
|
}
|
|
943
1265
|
const path = this.parsePathEol(p, "path");
|
|
944
1266
|
|
|
@@ -990,6 +1312,10 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
990
1312
|
`Missing space after source: ${this.line}`,
|
|
991
1313
|
);
|
|
992
1314
|
}
|
|
1315
|
+
// git 2.43 wanted something after the space (an empty dest was `""`)
|
|
1316
|
+
if (this.compatibility === "2.43" && src.rest.length === 1) {
|
|
1317
|
+
this.die(`missing dest: ${this.line}`, `Missing dest: ${this.line}`);
|
|
1318
|
+
}
|
|
993
1319
|
const dest = this.parsePathEol(src.rest.slice(1), "dest");
|
|
994
1320
|
const leaf = rename
|
|
995
1321
|
? await this.treeRemove(b.root, src.path, true)
|
|
@@ -1007,6 +1333,130 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1007
1333
|
await this.treeSet(b.root, dest, node.id, node.mode, node.entries);
|
|
1008
1334
|
}
|
|
1009
1335
|
|
|
1336
|
+
// ---------------------------------------------------------------- notes
|
|
1337
|
+
|
|
1338
|
+
/** construct_path_with_fanout: `fanout` levels of two hex digits, then the rest */
|
|
1339
|
+
private notePath(hex: string, fanout: number): string {
|
|
1340
|
+
if (fanout >= this.objectFormat.rawLength) this.die(`too large fanout (${fanout})`);
|
|
1341
|
+
let path = "";
|
|
1342
|
+
let at = 0;
|
|
1343
|
+
for (let i = 0; i < fanout; i++, at += 2) path += `${hex.slice(at, at + 2)}/`;
|
|
1344
|
+
return path + hex.slice(at);
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
/**
|
|
1348
|
+
* change_note_fanout: moves every note (a path of exactly one id's hex digits, in
|
|
1349
|
+
* components of even length) of the tree to its place under `fanout`, and gives the
|
|
1350
|
+
* number of notes; 0xff only counts them.
|
|
1351
|
+
*/
|
|
1352
|
+
private changeNoteFanout(root: Node, fanout: number): Promise<bigint> {
|
|
1353
|
+
return this.doChangeNoteFanout(root, root, "", "", fanout);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
private async doChangeNoteFanout(
|
|
1357
|
+
origRoot: Node,
|
|
1358
|
+
root: Node,
|
|
1359
|
+
hexPrefix: string,
|
|
1360
|
+
fullPath: string,
|
|
1361
|
+
fanout: number,
|
|
1362
|
+
): Promise<bigint> {
|
|
1363
|
+
const hexsz = this.objectFormat.hexLength;
|
|
1364
|
+
let count = 0n;
|
|
1365
|
+
// entries in tree order, those added on the way (moved notes) visited too
|
|
1366
|
+
for (const [name, e] of await this.loadTree(root)) {
|
|
1367
|
+
const hex = hexPrefix + name;
|
|
1368
|
+
if (hex.length > hexsz || name.length % 2) continue;
|
|
1369
|
+
const path = fullPath ? `${fullPath}/${name}` : name;
|
|
1370
|
+
if (hex.length === hexsz && /^[0-9a-fA-F]+$/.test(hex)) {
|
|
1371
|
+
if (fanout === 0xff) {
|
|
1372
|
+
count++;
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
const realPath = this.notePath(hex, fanout);
|
|
1376
|
+
if (path === realPath) {
|
|
1377
|
+
count++;
|
|
1378
|
+
continue;
|
|
1379
|
+
}
|
|
1380
|
+
const leaf = await this.treeRemove(origRoot, path, false);
|
|
1381
|
+
if (leaf === undefined || leaf === true) this.die(`failed to remove path ${path}`);
|
|
1382
|
+
const moved = leaf as Node;
|
|
1383
|
+
await this.treeSet(origRoot, realPath, moved.id, moved.mode, moved.entries);
|
|
1384
|
+
} else if (isDir(e.mode)) {
|
|
1385
|
+
count += await this.doChangeNoteFanout(origRoot, e, hex, path, fanout);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
return count;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
/** note_change_n: `N <dataref> <commit-ish>` (or `N inline <commit-ish>` and its data). */
|
|
1392
|
+
private async noteChangeN(text: string, b: Branch, fanout: { value: number }): Promise<void> {
|
|
1393
|
+
// a notes ref loaded from a commit has not been counted yet
|
|
1394
|
+
if (b.numNotes === 0n && fanout.value === 0) {
|
|
1395
|
+
b.numNotes = await this.changeNoteFanout(b.root, 0xff);
|
|
1396
|
+
fanout.value = noteFanoutOf(b.numNotes);
|
|
1397
|
+
}
|
|
1398
|
+
let p = text;
|
|
1399
|
+
let id: ObjectId | undefined;
|
|
1400
|
+
let knownType: string | undefined;
|
|
1401
|
+
let inline = false;
|
|
1402
|
+
if (p.startsWith(":")) {
|
|
1403
|
+
const { mark, rest } = this.parseMarkRefSpace(p);
|
|
1404
|
+
const oe = this.findMark(mark);
|
|
1405
|
+
id = oe.id;
|
|
1406
|
+
knownType = oe.type;
|
|
1407
|
+
p = rest;
|
|
1408
|
+
} else if (p.startsWith("inline ")) {
|
|
1409
|
+
inline = true;
|
|
1410
|
+
p = p.slice(7);
|
|
1411
|
+
} else {
|
|
1412
|
+
const parsed = this.parseMappedOidHex(p);
|
|
1413
|
+
if (!parsed) this.die(`invalid dataref: ${this.line}`);
|
|
1414
|
+
({ id, rest: p } = parsed as { id: ObjectId; rest: string });
|
|
1415
|
+
knownType = this.objectTypes.get(id);
|
|
1416
|
+
if (p[0] !== " ") this.die(`missing space after SHA1: ${this.line}`);
|
|
1417
|
+
p = p.slice(1);
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
let commit: ObjectId;
|
|
1421
|
+
const s = this.lookupBranch(p);
|
|
1422
|
+
if (s) {
|
|
1423
|
+
if (s.oid === undefined) this.die("can't add a note on empty branch.");
|
|
1424
|
+
commit = s.oid as string;
|
|
1425
|
+
} else if (p.startsWith(":")) {
|
|
1426
|
+
const mark = this.parseMarkRefEol(p);
|
|
1427
|
+
const oe = this.findMark(mark);
|
|
1428
|
+
if (oe.type !== "commit")
|
|
1429
|
+
this.die(`mark :${mark} not a commit`, `Mark :${mark} not a commit`);
|
|
1430
|
+
commit = oe.id;
|
|
1431
|
+
} else {
|
|
1432
|
+
const named = await this.getOid(p);
|
|
1433
|
+
if (named === undefined) this.die(`invalid ref name or SHA1 expression: ${p}`);
|
|
1434
|
+
const peeled = await this.peelToCommit(named as string);
|
|
1435
|
+
if (!peeled) this.die(`not a valid commit: ${p}`);
|
|
1436
|
+
commit = peeled as string;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
const isNull = id !== undefined && /^0+$/.test(id);
|
|
1440
|
+
if (inline) {
|
|
1441
|
+
await this.readNextCommand();
|
|
1442
|
+
id = await this.storeObject("blob", await this.parseData(), 0);
|
|
1443
|
+
} else if (knownType !== undefined) {
|
|
1444
|
+
if (knownType !== "blob") this.die(`not a blob (actually a ${knownType}): ${this.line}`);
|
|
1445
|
+
} else if (!isNull) {
|
|
1446
|
+
const type = await this.odbType(id as string);
|
|
1447
|
+
if (type === undefined) this.die(`blob not found: ${this.line}`);
|
|
1448
|
+
if (type !== "blob") this.die(`not a blob (actually a ${type}): ${this.line}`);
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
if (await this.treeRemove(b.root, this.notePath(commit, fanout.value), false)) {
|
|
1452
|
+
b.numNotes = (b.numNotes - 1n) & UINTMAX;
|
|
1453
|
+
}
|
|
1454
|
+
if (isNull) return;
|
|
1455
|
+
b.numNotes = (b.numNotes + 1n) & UINTMAX;
|
|
1456
|
+
const path = this.notePath(commit, noteFanoutOf(b.numNotes));
|
|
1457
|
+
await this.treeSet(b.root, path, id, S_IFREG | 0o644);
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1010
1460
|
private async parseObjectish(b: Branch, objectish: string): Promise<void> {
|
|
1011
1461
|
const s = this.lookupBranch(objectish);
|
|
1012
1462
|
if (s === b) this.die(`can't create a branch from itself: ${b.name}`);
|
|
@@ -1017,7 +1467,8 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1017
1467
|
} else if (objectish.startsWith(":")) {
|
|
1018
1468
|
const mark = this.parseMarkRefEol(objectish);
|
|
1019
1469
|
const oe = this.findMark(mark);
|
|
1020
|
-
if (oe.type !== "commit")
|
|
1470
|
+
if (oe.type !== "commit")
|
|
1471
|
+
this.die(`mark :${mark} not a commit`, `Mark :${mark} not a commit`);
|
|
1021
1472
|
if (b.oid !== oe.id) {
|
|
1022
1473
|
b.oid = oe.id;
|
|
1023
1474
|
await this.setRootFromCommit(b);
|
|
@@ -1057,7 +1508,8 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1057
1508
|
else if (from.startsWith(":")) {
|
|
1058
1509
|
const mark = this.parseMarkRefEol(from);
|
|
1059
1510
|
const oe = this.findMark(mark);
|
|
1060
|
-
if (oe.type !== "commit")
|
|
1511
|
+
if (oe.type !== "commit")
|
|
1512
|
+
this.die(`mark :${mark} not a commit`, `Mark :${mark} not a commit`);
|
|
1061
1513
|
id = oe.id;
|
|
1062
1514
|
} else {
|
|
1063
1515
|
const named = await this.getOid(from);
|
|
@@ -1150,6 +1602,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1150
1602
|
if (this.line.startsWith("from ")) await this.parseObjectish(b, this.line.slice(5));
|
|
1151
1603
|
const merges = await this.parseMerge();
|
|
1152
1604
|
|
|
1605
|
+
const fanout = { value: noteFanoutOf(b.numNotes) };
|
|
1153
1606
|
while (this.line.length > 0) {
|
|
1154
1607
|
const cmd = this.line;
|
|
1155
1608
|
if (cmd.startsWith("M ")) await this.fileChangeM(cmd.slice(2), b);
|
|
@@ -1157,10 +1610,10 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1157
1610
|
await this.treeRemove(b.root, this.parsePathEol(cmd.slice(2), "path"), true);
|
|
1158
1611
|
} else if (cmd.startsWith("R ")) await this.fileChangeCR(cmd.slice(2), b, true);
|
|
1159
1612
|
else if (cmd.startsWith("C ")) await this.fileChangeCR(cmd.slice(2), b, false);
|
|
1160
|
-
else if (cmd.startsWith("N "))
|
|
1161
|
-
|
|
1162
|
-
} else if (cmd === "deleteall") {
|
|
1613
|
+
else if (cmd.startsWith("N ")) await this.noteChangeN(cmd.slice(2), b, fanout);
|
|
1614
|
+
else if (cmd === "deleteall") {
|
|
1163
1615
|
b.root = { mode: S_IFDIR, id: undefined, entries: new Map() };
|
|
1616
|
+
b.numNotes = 0n;
|
|
1164
1617
|
} else if (cmd.startsWith("ls ")) await this.parseLs(cmd.slice(3), b);
|
|
1165
1618
|
else if (cmd.startsWith("cat-blob ")) await this.parseCatBlob(cmd.slice(9));
|
|
1166
1619
|
else {
|
|
@@ -1169,6 +1622,8 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1169
1622
|
}
|
|
1170
1623
|
if (!(await this.readNextCommand())) break;
|
|
1171
1624
|
}
|
|
1625
|
+
const newFanout = noteFanoutOf(b.numNotes);
|
|
1626
|
+
if (newFanout !== fanout.value) b.numNotes = await this.changeNoteFanout(b.root, newFanout);
|
|
1172
1627
|
|
|
1173
1628
|
const tree = await this.storeTree(b.root);
|
|
1174
1629
|
let data = `tree ${tree}\n`;
|
|
@@ -1176,14 +1631,23 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1176
1631
|
for (const m of merges) data += `parent ${m}\n`;
|
|
1177
1632
|
data += `author ${author ?? committer}\ncommitter ${committer}\n`;
|
|
1178
1633
|
if (encoding !== undefined) data += `encoding ${encoding}\n`;
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
[
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1634
|
+
const finalized = (header: string, sigs: typeof signatures) => {
|
|
1635
|
+
let out = header;
|
|
1636
|
+
for (const [name, sig] of [
|
|
1637
|
+
["gpgsig", sigs.sha1],
|
|
1638
|
+
["gpgsig-sha256", sigs.sha256],
|
|
1639
|
+
] as const) {
|
|
1640
|
+
if (sig === undefined) continue;
|
|
1641
|
+
out += `${name} ${sig.split("\n").join("\n ")}\n`;
|
|
1642
|
+
}
|
|
1643
|
+
return `${out}\n${msg}`;
|
|
1644
|
+
};
|
|
1645
|
+
if (
|
|
1646
|
+
isIfInvalid(this.signedCommits) &&
|
|
1647
|
+
(signatures.sha1 !== undefined || signatures.sha256 !== undefined)
|
|
1648
|
+
) {
|
|
1649
|
+
data = await this.handleSignatureIfInvalid(data, finalized(data, signatures), msg);
|
|
1650
|
+
} else data = finalized(data, signatures);
|
|
1187
1651
|
b.oid = await this.storeObject("commit", data, mark);
|
|
1188
1652
|
b.delete = false;
|
|
1189
1653
|
}
|
|
@@ -1250,6 +1714,11 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1250
1714
|
case "strip":
|
|
1251
1715
|
msg = msg.slice(0, sigAt);
|
|
1252
1716
|
break;
|
|
1717
|
+
case "strip-if-invalid":
|
|
1718
|
+
case "sign-if-invalid":
|
|
1719
|
+
case "abort-if-invalid":
|
|
1720
|
+
msg = await this.handleTagSignatureIfInvalid(data, msg, sigAt);
|
|
1721
|
+
break;
|
|
1253
1722
|
default:
|
|
1254
1723
|
this.die("encountered signed tag; use --signed-tags=<mode> to handle it");
|
|
1255
1724
|
}
|
|
@@ -1259,6 +1728,102 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1259
1728
|
entry.id = await this.storeObject("tag", data, mark);
|
|
1260
1729
|
}
|
|
1261
1730
|
|
|
1731
|
+
/** The lines a check printed (git's check_signature errors) go to stderr. */
|
|
1732
|
+
private printCheckMessages(messages: readonly string[]): void {
|
|
1733
|
+
for (const line of messages) this.warn(line);
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
/** sign_buffer with `keyid` (else the configured key); git's death with `failure`. */
|
|
1737
|
+
private async signOrDie(payload: Uint8Array, keyid: string | undefined, failure: string) {
|
|
1738
|
+
const cwd = await this.hostWorkingDir().catch(() => undefined);
|
|
1739
|
+
try {
|
|
1740
|
+
return latin1(
|
|
1741
|
+
await signPayload(this.workingCopy, keyid ?? "", payload, {
|
|
1742
|
+
committer: committerIdentOf(this.workingCopy),
|
|
1743
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
1744
|
+
tail: [`fatal: ${failure}`],
|
|
1745
|
+
}),
|
|
1746
|
+
);
|
|
1747
|
+
} catch (e) {
|
|
1748
|
+
if (e instanceof SigningFailedError) throw new FastImportDeath(failure, e.message);
|
|
1749
|
+
throw e;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
/**
|
|
1754
|
+
* handle_signature_if_invalid: the commit with its signatures checked as
|
|
1755
|
+
* `verify_commit_buffer` checks it; kept when good, else stripped (with git's warning),
|
|
1756
|
+
* re-signed, or the import ends. Gives the commit's bytes (as a binary string).
|
|
1757
|
+
*/
|
|
1758
|
+
private async handleSignatureIfInvalid(
|
|
1759
|
+
header: string,
|
|
1760
|
+
signed: string,
|
|
1761
|
+
msg: string,
|
|
1762
|
+
): Promise<string> {
|
|
1763
|
+
const cwd = await this.hostWorkingDir().catch(() => undefined);
|
|
1764
|
+
const check = await verifyCommitBytes(this.workingCopy, latin1Bytes(signed), {
|
|
1765
|
+
objectFormat: this.objectFormat,
|
|
1766
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
1767
|
+
});
|
|
1768
|
+
this.printCheckMessages(check.messages);
|
|
1769
|
+
if (!check.failed) return signed;
|
|
1770
|
+
const mode = this.signedCommits;
|
|
1771
|
+
if (mode === "abort-if-invalid") this.die("aborting due to invalid signature");
|
|
1772
|
+
const signer = check.signer ?? "unknown";
|
|
1773
|
+
const subject = subjectOfMessage(msg);
|
|
1774
|
+
const verb = mode === "strip-if-invalid" ? "stripping" : "replacing";
|
|
1775
|
+
const what =
|
|
1776
|
+
subject.length > 100
|
|
1777
|
+
? ` '${subject.slice(0, 100)}...'`
|
|
1778
|
+
: subject.length > 0
|
|
1779
|
+
? ` '${subject}'`
|
|
1780
|
+
: "";
|
|
1781
|
+
this.warn(`warning: ${verb} invalid signature for commit${what}\n allegedly by ${signer}`);
|
|
1782
|
+
let out = header;
|
|
1783
|
+
if (mode === "sign-if-invalid") {
|
|
1784
|
+
if (this.workingCopy.history?.objects?.compat) {
|
|
1785
|
+
this.die("signing commits in interoperability mode is unsupported");
|
|
1786
|
+
}
|
|
1787
|
+
const signature = await this.signOrDie(
|
|
1788
|
+
check.payload ?? new Uint8Array(0),
|
|
1789
|
+
this.signedCommitKeyid,
|
|
1790
|
+
"failed to sign commit object",
|
|
1791
|
+
);
|
|
1792
|
+
// add_header_signature: every line with its newline, after a space
|
|
1793
|
+
const lines = signature.split("\n");
|
|
1794
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
1795
|
+
const ends = signature.endsWith("\n") ? "\n" : "";
|
|
1796
|
+
out += `${this.objectFormat.signatureHeader} ${lines.join("\n ")}${ends}`;
|
|
1797
|
+
}
|
|
1798
|
+
return `${out}\n${msg}`;
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
/**
|
|
1802
|
+
* handle_tag_signature_if_invalid: the signature ending a tag's message checked over the
|
|
1803
|
+
* tag before it; kept when good, else dropped, replaced, or the import ends. Gives the
|
|
1804
|
+
* message.
|
|
1805
|
+
*/
|
|
1806
|
+
private async handleTagSignatureIfInvalid(
|
|
1807
|
+
header: string,
|
|
1808
|
+
msg: string,
|
|
1809
|
+
sigAt: number,
|
|
1810
|
+
): Promise<string> {
|
|
1811
|
+
const payload = latin1Bytes(`${header}\n${msg.slice(0, sigAt)}`);
|
|
1812
|
+
const cwd = await this.hostWorkingDir().catch(() => undefined);
|
|
1813
|
+
const check = await checkSignature(this.workingCopy, payload, latin1Bytes(msg.slice(sigAt)), {
|
|
1814
|
+
payloadType: "tag",
|
|
1815
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
1816
|
+
});
|
|
1817
|
+
this.printCheckMessages(check.messages);
|
|
1818
|
+
if (!check.failed) return msg;
|
|
1819
|
+
if (this.signedTags === "abort-if-invalid") this.die("aborting due to invalid signature");
|
|
1820
|
+
const stripped = msg.slice(0, sigAt);
|
|
1821
|
+
if (this.signedTags !== "sign-if-invalid") return stripped;
|
|
1822
|
+
return (
|
|
1823
|
+
stripped + (await this.signOrDie(payload, this.signedTagKeyid, "failed to sign tag object"))
|
|
1824
|
+
);
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1262
1827
|
private async parseResetBranch(arg: string): Promise<void> {
|
|
1263
1828
|
let b = this.lookupBranch(arg);
|
|
1264
1829
|
if (b) {
|
|
@@ -1291,13 +1856,11 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1291
1856
|
let id: ObjectId;
|
|
1292
1857
|
if (p.startsWith(":")) id = this.findMark(this.parseMarkRefEol(p)).id;
|
|
1293
1858
|
else {
|
|
1294
|
-
const
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
if (p.length > hex) this.die(`garbage after SHA1: ${this.line}`);
|
|
1300
|
-
id = candidate.toLowerCase();
|
|
1859
|
+
const parsed = this.parseMappedOidHex(p);
|
|
1860
|
+
if (!parsed) this.die(`invalid dataref: ${this.line}`);
|
|
1861
|
+
const { id: named, rest } = parsed as { id: ObjectId; rest: string };
|
|
1862
|
+
if (rest !== "") this.die(`garbage after SHA1: ${this.line}`);
|
|
1863
|
+
id = named;
|
|
1301
1864
|
}
|
|
1302
1865
|
const raw = await readObjectBytes(this.objects, id);
|
|
1303
1866
|
if (!raw) {
|
|
@@ -1323,14 +1886,11 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1323
1886
|
id = this.findMark(mark).id;
|
|
1324
1887
|
rest = r;
|
|
1325
1888
|
} else {
|
|
1326
|
-
const
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
id = candidate.toLowerCase();
|
|
1332
|
-
if (p[hex] !== " ") this.die(`missing space after tree-ish: ${this.line}`);
|
|
1333
|
-
rest = p.slice(hex + 1);
|
|
1889
|
+
const parsed = this.parseMappedOidHex(p);
|
|
1890
|
+
if (!parsed) this.die(`invalid dataref: ${this.line}`);
|
|
1891
|
+
({ id, rest } = parsed as { id: ObjectId; rest: string });
|
|
1892
|
+
if (rest[0] !== " ") this.die(`missing space after tree-ish: ${this.line}`);
|
|
1893
|
+
rest = rest.slice(1);
|
|
1334
1894
|
}
|
|
1335
1895
|
// dereference: commits to their trees, tags to what they tag
|
|
1336
1896
|
for (let depth = 0; depth < 64; depth++) {
|
|
@@ -1345,7 +1905,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1345
1905
|
}
|
|
1346
1906
|
root = { mode: S_IFDIR, id };
|
|
1347
1907
|
}
|
|
1348
|
-
const path = this.parsePathEol(rest, "path");
|
|
1908
|
+
const path = this.parsePathEol(rest, "path", true);
|
|
1349
1909
|
const leaf = await this.treeGet(root, path, true);
|
|
1350
1910
|
const quoted = quotePathBinary(path);
|
|
1351
1911
|
if (!leaf?.mode) {
|
|
@@ -1371,6 +1931,7 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1371
1931
|
oid: undefined,
|
|
1372
1932
|
root: { mode: S_IFDIR, id: undefined },
|
|
1373
1933
|
delete: false,
|
|
1934
|
+
numNotes: 0n,
|
|
1374
1935
|
};
|
|
1375
1936
|
await this.parseObjectish(b, this.line.slice(3));
|
|
1376
1937
|
if (b.oid) this.insertMark(mark, { id: b.oid, type: "commit" });
|
|
@@ -1397,7 +1958,12 @@ export class FastImportCommand extends PlumbingCommand {
|
|
|
1397
1958
|
/** update_branch: true on a failure */
|
|
1398
1959
|
private async updateBranch(b: Branch): Promise<boolean> {
|
|
1399
1960
|
const name = this.refName(b.name);
|
|
1400
|
-
|
|
1961
|
+
// git 2.5x drops a replace ref that would name itself (2.43 wrote it)
|
|
1962
|
+
if (
|
|
1963
|
+
this.compatibility !== "2.43" &&
|
|
1964
|
+
name.startsWith("refs/replace/") &&
|
|
1965
|
+
name.slice(13) === b.oid
|
|
1966
|
+
) {
|
|
1401
1967
|
await this.refsStore.delete(name).catch(() => false);
|
|
1402
1968
|
return false;
|
|
1403
1969
|
}
|
|
@@ -1473,6 +2039,40 @@ function utf8Binary(text: string): string {
|
|
|
1473
2039
|
return latin1(new TextEncoder().encode(text));
|
|
1474
2040
|
}
|
|
1475
2041
|
|
|
2042
|
+
/** get_oid_hex_any: the hex digits of an id of either hash at `at` (SHA-256's tried first). */
|
|
2043
|
+
function hexIdAt(text: string, at: number): string | undefined {
|
|
2044
|
+
for (const length of [64, 40]) {
|
|
2045
|
+
const hex = text.slice(at, at + length);
|
|
2046
|
+
if (hex.length === length && /^[0-9a-fA-F]+$/.test(hex)) return hex;
|
|
2047
|
+
}
|
|
2048
|
+
return undefined;
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
/** git_parse_ulong: a number (base 0) with an optional k, m or g; undefined if refused. */
|
|
2052
|
+
function parseGitUlong(value: string): number | undefined {
|
|
2053
|
+
if (!value || value.includes("-")) return undefined;
|
|
2054
|
+
const m = /^\s*\+?(0[xX][0-9a-fA-F]+|0[0-7]*|[1-9][0-9]*)(.*)$/.exec(value);
|
|
2055
|
+
if (!m) return undefined;
|
|
2056
|
+
const unit = (m[2] as string).toLowerCase();
|
|
2057
|
+
const factor =
|
|
2058
|
+
unit === "" ? 1 : unit === "k" ? 1024 : unit === "m" ? 1 << 20 : unit === "g" ? 1 << 30 : 0;
|
|
2059
|
+
if (!factor) return undefined;
|
|
2060
|
+
const parsed = strtoulValue(m[1] as string) * factor;
|
|
2061
|
+
// git_parse_unsigned refuses what overflows an unsigned 64-bit value (ERANGE)
|
|
2062
|
+
return parsed > 2 ** 64 - 1 ? undefined : parsed;
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
/** strtoul's digits with base 0: hex after 0x, octal after 0, else decimal */
|
|
2066
|
+
function strtoulValue(digits: string): number {
|
|
2067
|
+
if (/^0[xX]/.test(digits)) return Number.parseInt(digits.slice(2), 16);
|
|
2068
|
+
if (digits.length > 1 && digits.startsWith("0")) return Number.parseInt(digits.slice(1), 8);
|
|
2069
|
+
return Number(digits);
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
function asciiLower(text: string): string {
|
|
2073
|
+
return text.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
2074
|
+
}
|
|
2075
|
+
|
|
1476
2076
|
function compareBinary(a: string, b: string): number {
|
|
1477
2077
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
1478
2078
|
}
|