@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
|
@@ -4,14 +4,24 @@
|
|
|
4
4
|
* written under `refs/bundles/`) and `fetch.bundleCreationToken`.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
historyWithoutLazyFetch,
|
|
9
|
+
type ObjectId,
|
|
10
|
+
objectFormatOf,
|
|
11
|
+
type RefLogOptions,
|
|
12
|
+
} from "@statewalker/vcs-core";
|
|
8
13
|
import {
|
|
9
14
|
type Credentials,
|
|
15
|
+
checkReceivedPack,
|
|
10
16
|
createRepositoryFacade,
|
|
17
|
+
FetchCheckError,
|
|
11
18
|
type HttpClientSettings,
|
|
12
19
|
type HttpCredentialHelper,
|
|
20
|
+
ReceivedObjects,
|
|
21
|
+
type ReceivedObjectsFsck,
|
|
13
22
|
SmartHttpClient,
|
|
14
23
|
} from "@statewalker/vcs-transport";
|
|
24
|
+
import type { ObjectFormat } from "@statewalker/vcs-utils/hash";
|
|
15
25
|
|
|
16
26
|
import type { WorkingCopy } from "../../types.js";
|
|
17
27
|
import type { BundleUriHost } from "./bundle-uri.js";
|
|
@@ -47,6 +57,16 @@ export interface BundleUriHostOptions {
|
|
|
47
57
|
message(line: string): void;
|
|
48
58
|
/** How the downloaded list file is named in errors */
|
|
49
59
|
tempFileName?(): string;
|
|
60
|
+
/**
|
|
61
|
+
* The hash a bundle header without `@object-format=` is read in (git's `the_hash_algo`):
|
|
62
|
+
* default the repository's
|
|
63
|
+
*/
|
|
64
|
+
objectFormat?: ObjectFormat;
|
|
65
|
+
/**
|
|
66
|
+
* git 2.46+'s `VERIFY_BUNDLE_FSCK` (`fetch.fsckObjects`, else `transfer.fsckObjects`): the
|
|
67
|
+
* fsck index-pack's `--fsck-objects` runs over the bundle's objects, or undefined for none
|
|
68
|
+
*/
|
|
69
|
+
fsckObjects?(): Promise<ReceivedObjectsFsck | undefined>;
|
|
50
70
|
}
|
|
51
71
|
|
|
52
72
|
/** The origin of a URL, or undefined for one `new URL` cannot read. */
|
|
@@ -61,6 +81,7 @@ function originOf(url: string): string | undefined {
|
|
|
61
81
|
/** A host over a repository (see {@link BundleUriHostOptions}). */
|
|
62
82
|
export function createBundleUriHost(options: BundleUriHostOptions): BundleUriHost {
|
|
63
83
|
const history = options.workingCopy.history;
|
|
84
|
+
const objectFormat = options.objectFormat ?? objectFormatOf(history);
|
|
64
85
|
return {
|
|
65
86
|
async download(uri) {
|
|
66
87
|
if (/^https?:/.test(uri)) return downloadHttp(options, uri);
|
|
@@ -69,7 +90,7 @@ export function createBundleUriHost(options: BundleUriHostOptions): BundleUriHos
|
|
|
69
90
|
return options.readLocalFile(path).catch(() => undefined);
|
|
70
91
|
},
|
|
71
92
|
async unbundle(bytes) {
|
|
72
|
-
const opened = openBundle(bytes, "<bundle>");
|
|
93
|
+
const opened = openBundle(bytes, "<bundle>", objectFormat);
|
|
73
94
|
if (!opened.ok) return false;
|
|
74
95
|
const { header, pack } = opened.bundle;
|
|
75
96
|
const objects = historyWithoutLazyFetch(history);
|
|
@@ -85,18 +106,56 @@ export function createBundleUriHost(options: BundleUriHostOptions): BundleUriHos
|
|
|
85
106
|
for (const line of verified.stderr.split("\n")) if (line) options.message(line);
|
|
86
107
|
if (!verified.ok) return false;
|
|
87
108
|
const facade = createRepositoryFacade({ history: objects });
|
|
109
|
+
const fsck = await options.fsckObjects?.();
|
|
88
110
|
let packId: string | undefined;
|
|
89
111
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
if (fsck) {
|
|
113
|
+
// index-pack --fsck-objects: the objects checked in a quarantine (no links: a bundle
|
|
114
|
+
// has prerequisites), which a refusal discards
|
|
115
|
+
const received = new ReceivedObjects(objectFormat.rawLength);
|
|
116
|
+
const { quarantine, ...imported } = await facade.importPack(
|
|
117
|
+
(async function* () {
|
|
118
|
+
yield pack;
|
|
119
|
+
})(),
|
|
120
|
+
{
|
|
121
|
+
keepPack: true,
|
|
122
|
+
quarantine: true,
|
|
123
|
+
onObject: (id, type, entry) => received.add(id, type, entry),
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
let committed = false;
|
|
127
|
+
try {
|
|
128
|
+
const checked = await checkReceivedPack(quarantine?.repository ?? facade, received, {
|
|
129
|
+
fsck,
|
|
130
|
+
links: false,
|
|
131
|
+
shallow: new Set<string>(),
|
|
132
|
+
kept: true,
|
|
133
|
+
tail: null,
|
|
134
|
+
});
|
|
135
|
+
// index-pack's fsck warnings (stderr; VERIFY_BUNDLE_QUIET quiets verify_bundle only)
|
|
136
|
+
for (const line of checked.messages) options.message(line);
|
|
137
|
+
await quarantine?.commit();
|
|
138
|
+
committed = true;
|
|
139
|
+
} finally {
|
|
140
|
+
if (!committed) await quarantine?.discard().catch(() => {});
|
|
141
|
+
}
|
|
142
|
+
packId = imported.packId;
|
|
143
|
+
} else {
|
|
144
|
+
const imported = await facade.importPack(
|
|
145
|
+
(async function* () {
|
|
146
|
+
yield pack;
|
|
147
|
+
})(),
|
|
148
|
+
{ keepPack: true },
|
|
149
|
+
);
|
|
150
|
+
packId = imported.packId;
|
|
151
|
+
}
|
|
97
152
|
} catch (error) {
|
|
98
|
-
|
|
99
|
-
|
|
153
|
+
if (error instanceof FetchCheckError) {
|
|
154
|
+
for (const line of error.lines) options.message(line);
|
|
155
|
+
} else {
|
|
156
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
157
|
+
options.message(message.startsWith("fatal: ") ? message : `fatal: ${message}`);
|
|
158
|
+
}
|
|
100
159
|
options.message("error: index-pack died");
|
|
101
160
|
return false;
|
|
102
161
|
}
|
|
@@ -130,6 +189,7 @@ export function createBundleUriHost(options: BundleUriHostOptions): BundleUriHos
|
|
|
130
189
|
creationToken: () => options.configValue("fetch.bundleCreationToken"),
|
|
131
190
|
setCreationToken: (value) => options.setConfigValue("fetch.bundleCreationToken", value),
|
|
132
191
|
message: (line) => options.message(line),
|
|
192
|
+
objectFormat,
|
|
133
193
|
...(options.tempFileName ? { tempFileName: options.tempFileName } : {}),
|
|
134
194
|
};
|
|
135
195
|
}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* heuristic, and give git's warnings in order.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import type { ObjectFormat } from "@statewalker/vcs-utils/hash";
|
|
15
|
+
|
|
14
16
|
import { parseBundleHeader } from "./bundle-format.js";
|
|
15
17
|
import { BundleList, parseBundleListConfig, type RemoteBundleInfo } from "./bundle-list.js";
|
|
16
18
|
|
|
@@ -37,14 +39,19 @@ export interface BundleUriHost {
|
|
|
37
39
|
* `<objects>/bundles/tmp_uri_XXXXXX`)
|
|
38
40
|
*/
|
|
39
41
|
tempFileName?(): string;
|
|
42
|
+
/**
|
|
43
|
+
* The hash a bundle header without `@object-format=` is read in (git's `the_hash_algo`, the
|
|
44
|
+
* repository's; default SHA-1)
|
|
45
|
+
*/
|
|
46
|
+
objectFormat?: ObjectFormat;
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
/** bundle-uri.c's `max_bundle_uri_depth`. */
|
|
43
50
|
const MAX_BUNDLE_URI_DEPTH = 4;
|
|
44
51
|
|
|
45
52
|
/** Whether the bytes read as a bundle (`is_bundle`: the whole header parses). */
|
|
46
|
-
export function isBundle(bytes: Uint8Array): boolean {
|
|
47
|
-
return parseBundleHeader(bytes).ok;
|
|
53
|
+
export function isBundle(bytes: Uint8Array, objectFormat?: ObjectFormat): boolean {
|
|
54
|
+
return parseBundleHeader(bytes, undefined, objectFormat).ok;
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
/**
|
|
@@ -72,7 +79,7 @@ async function fetchBundleUriInternal(
|
|
|
72
79
|
return false;
|
|
73
80
|
}
|
|
74
81
|
bundle.file = bytes;
|
|
75
|
-
if (!isBundle(bytes)) {
|
|
82
|
+
if (!isBundle(bytes, host.objectFormat)) {
|
|
76
83
|
const ok = await fetchBundleListInConfigFormat(host, global, bundle, bytes, depth);
|
|
77
84
|
if (!ok) {
|
|
78
85
|
bundle.file = null;
|
|
@@ -160,7 +167,7 @@ async function fetchBundlesByToken(host: BundleUriHost, list: BundleList): Promi
|
|
|
160
167
|
bundle.unbundled = true;
|
|
161
168
|
direction = 1;
|
|
162
169
|
skipUnbundle = true;
|
|
163
|
-
} else if (!bundle.file || !isBundle(bundle.file)) {
|
|
170
|
+
} else if (!bundle.file || !isBundle(bundle.file, host.objectFormat)) {
|
|
164
171
|
host.message(`warning: file downloaded from '${bundle.uri}' is not a bundle`);
|
|
165
172
|
break;
|
|
166
173
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { type History, historyWithoutLazyFetch, type ObjectId } from "@statewalker/vcs-core";
|
|
8
8
|
import { connectivityErrors, createRepositoryFacade } from "@statewalker/vcs-transport";
|
|
9
|
+
import type { ObjectFormat } from "@statewalker/vcs-utils/hash";
|
|
9
10
|
|
|
10
11
|
import { type BundleHeader, listBundleRefs, parseBundleHeader } from "./bundle-format.js";
|
|
11
12
|
|
|
@@ -61,8 +62,10 @@ export interface OpenedBundle {
|
|
|
61
62
|
export function openBundle(
|
|
62
63
|
bytes: Uint8Array,
|
|
63
64
|
name: string,
|
|
65
|
+
/** The hash of a header without `@object-format=` (the repository's) */
|
|
66
|
+
defaultFormat?: ObjectFormat,
|
|
64
67
|
): { ok: true; bundle: OpenedBundle } | { ok: false; error: string } {
|
|
65
|
-
const parsed = parseBundleHeader(bytes, name);
|
|
68
|
+
const parsed = parseBundleHeader(bytes, name, defaultFormat);
|
|
66
69
|
if (!parsed.ok) return { ok: false, error: `error: ${parsed.error}\n` };
|
|
67
70
|
return { ok: true, bundle: { header: parsed.header, pack: bytes.subarray(parsed.packOffset) } };
|
|
68
71
|
}
|
|
@@ -15,6 +15,10 @@ export interface BatchObjectData {
|
|
|
15
15
|
mode?: number;
|
|
16
16
|
/** `%(rest)`: the input line after the object name and its whitespace */
|
|
17
17
|
rest?: string;
|
|
18
|
+
/** `%(objectsize:disk)`: its pack entry's or loose file's size */
|
|
19
|
+
diskSize?: number;
|
|
20
|
+
/** `%(deltabase)`: its pack entry's delta base, else the null id */
|
|
21
|
+
deltaBase?: string;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
type Part =
|
|
@@ -38,12 +42,8 @@ export interface BatchFormat {
|
|
|
38
42
|
needsSize: boolean;
|
|
39
43
|
/** `%(rest)`: input lines are split at their first whitespace */
|
|
40
44
|
splitOnWhitespace: boolean;
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
* `deferUnsupported`: refused only when a local object needs it (`remote-object-info`
|
|
44
|
-
* expands it to nothing, as git)
|
|
45
|
-
*/
|
|
46
|
-
unsupported?: string;
|
|
45
|
+
/** `%(objectsize:disk)` or `%(deltabase)`: the object's pack entry or loose file is asked */
|
|
46
|
+
needsDisk: boolean;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/** The default format, `%(objectname) %(objecttype) %(objectsize)`. */
|
|
@@ -52,20 +52,15 @@ export const DEFAULT_BATCH_FORMAT = "%(objectname) %(objecttype) %(objectsize)";
|
|
|
52
52
|
/**
|
|
53
53
|
* Parses `format` as git's mark_query pass reads it: an atom git does not know dies there
|
|
54
54
|
* (2.43 `unknown format element: <atom>`, 2.5x `bad cat-file format: %(<atom>)`).
|
|
55
|
-
* `%(objectsize:disk)` and `%(deltabase)` are refused: the stores do not report on-disk sizes
|
|
56
|
-
* or delta bases, and printing a made-up value would lie.
|
|
57
55
|
*/
|
|
58
|
-
export function parseBatchFormat(
|
|
59
|
-
format: string,
|
|
60
|
-
compatibility: "2.43" | "2.56",
|
|
61
|
-
options: { deferUnsupported?: boolean } = {},
|
|
62
|
-
): BatchFormat {
|
|
56
|
+
export function parseBatchFormat(format: string, compatibility: "2.43" | "2.56"): BatchFormat {
|
|
63
57
|
const parts: Part[] = [];
|
|
64
58
|
const result: BatchFormat = {
|
|
65
59
|
parts,
|
|
66
60
|
needsType: false,
|
|
67
61
|
needsSize: false,
|
|
68
62
|
splitOnWhitespace: false,
|
|
63
|
+
needsDisk: false,
|
|
69
64
|
};
|
|
70
65
|
let literal = "";
|
|
71
66
|
let at = 0;
|
|
@@ -114,8 +109,7 @@ export function parseBatchFormat(
|
|
|
114
109
|
break;
|
|
115
110
|
case "objectsize:disk":
|
|
116
111
|
case "deltabase":
|
|
117
|
-
|
|
118
|
-
result.unsupported ??= atom;
|
|
112
|
+
result.needsDisk = true;
|
|
119
113
|
break;
|
|
120
114
|
default:
|
|
121
115
|
throw unknownAtom(atom, compatibility);
|
|
@@ -129,9 +123,9 @@ export function parseBatchFormat(
|
|
|
129
123
|
return result;
|
|
130
124
|
}
|
|
131
125
|
|
|
132
|
-
/** The refusal of an atom the
|
|
126
|
+
/** The refusal of an on-disk atom where the store keeps no pack or loose file. */
|
|
133
127
|
export function unsupportedAtom(atom: string): PlumbingError {
|
|
134
|
-
return new PlumbingError(`fatal: cat-file: %(${atom}) is not supported`);
|
|
128
|
+
return new PlumbingError(`fatal: cat-file: %(${atom}) is not supported by this store`);
|
|
135
129
|
}
|
|
136
130
|
|
|
137
131
|
function unknownAtom(atom: string, compatibility: "2.43" | "2.56"): PlumbingError {
|
|
@@ -185,8 +179,13 @@ export function expandBatchFormat(
|
|
|
185
179
|
if (data.mode !== undefined) out += data.mode.toString(8).padStart(6, "0");
|
|
186
180
|
break;
|
|
187
181
|
case "objectsize:disk":
|
|
182
|
+
if (data.diskSize === undefined) throw unsupportedAtom(part.atom);
|
|
183
|
+
out += String(data.diskSize);
|
|
184
|
+
break;
|
|
188
185
|
case "deltabase":
|
|
189
|
-
throw unsupportedAtom(part.atom);
|
|
186
|
+
if (data.deltaBase === undefined) throw unsupportedAtom(part.atom);
|
|
187
|
+
out += data.deltaBase;
|
|
188
|
+
break;
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
return out;
|
|
@@ -16,8 +16,12 @@ import type { CompatObjects, GitObjects, ObjectId } from "@statewalker/vcs-core"
|
|
|
16
16
|
import { ObjectInfoError } from "@statewalker/vcs-transport";
|
|
17
17
|
import { parseGitBool } from "@statewalker/vcs-utils";
|
|
18
18
|
import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
19
|
+
import { FilterDriverError } from "@statewalker/vcs-working-tree";
|
|
20
|
+
import { GitApiError } from "../../errors/index.js";
|
|
19
21
|
import { RemoteConfigStore } from "../../remote-config/index.js";
|
|
20
22
|
import { quotePath } from "../../results/quote-path.js";
|
|
23
|
+
import { DiffCommand } from "../diff-command.js";
|
|
24
|
+
import { type ObjectDiskInfo, objectDiskInfoOf } from "../object-disk-info.js";
|
|
21
25
|
import { PlumbingCommand, PlumbingError } from "../plumbing-command.js";
|
|
22
26
|
import { concatBytes, objectTypeOfMode } from "../plumbing-shared.js";
|
|
23
27
|
import {
|
|
@@ -27,6 +31,7 @@ import {
|
|
|
27
31
|
} from "../remote-object-info-command.js";
|
|
28
32
|
import { applyMailmapToHeader } from "../rev-filter/index.js";
|
|
29
33
|
import type { RevisionResolver } from "../revision-resolver.js";
|
|
34
|
+
import { splitCmdline } from "../split-cmdline.js";
|
|
30
35
|
import {
|
|
31
36
|
type BatchFormat,
|
|
32
37
|
type BatchObjectData,
|
|
@@ -35,8 +40,11 @@ import {
|
|
|
35
40
|
parseBatchFormat,
|
|
36
41
|
} from "./batch-format.js";
|
|
37
42
|
|
|
38
|
-
/**
|
|
39
|
-
|
|
43
|
+
/**
|
|
44
|
+
* `-t`, `-s`, `-e`, `-p`, `--textconv` (the path's textconv driver over the blob, else `-p`)
|
|
45
|
+
* and `--filters` (the blob as checkout writes it to the worktree).
|
|
46
|
+
*/
|
|
47
|
+
export type CatFileMode = "type" | "size" | "exists" | "pretty" | "textconv" | "filters";
|
|
40
48
|
|
|
41
49
|
/** `--batch` (contents), `--batch-check` (info), `--batch-command` (command). */
|
|
42
50
|
export type CatFileBatchMode = "contents" | "info" | "command";
|
|
@@ -47,6 +55,7 @@ export type CatFileInput = string | Uint8Array | AsyncIterable<Uint8Array> | Ite
|
|
|
47
55
|
const OBJECT_TYPES = new Set(["blob", "tree", "commit", "tag"]);
|
|
48
56
|
const S_IFMT = 0o170000;
|
|
49
57
|
const S_IFGITLINK = 0o160000;
|
|
58
|
+
const S_IFREG = 0o100000;
|
|
50
59
|
const encoder = new TextEncoder();
|
|
51
60
|
const MAILMAP_HEADERS = ["author ", "committer ", "tagger "].map((h) => encoder.encode(h));
|
|
52
61
|
/** git's `MAXREPLACEDEPTH` */
|
|
@@ -70,16 +79,27 @@ interface ObjectInfo {
|
|
|
70
79
|
* `object-info` through {@link setRemoteObjectInfo}'s command: only the atoms the server
|
|
71
80
|
* answered expand (`%(objectname)` always), and an object it lacks prints `<id> missing`.
|
|
72
81
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
82
|
+
* `--textconv` and `--filters` (git's `textconv_object` and `filter_object`) convert a blob for
|
|
83
|
+
* the path its name reads (`<rev>:<path>`, `:<path>`) or {@link setPath} gives, with the mode
|
|
84
|
+
* of its entry (a symbolic link is left as it is); textconv goes through the driver's cache
|
|
85
|
+
* (`diff.<driver>.cachetextconv`) and needs a host textconv runner, without which the blob is
|
|
86
|
+
* printed as `-p` prints it. In the batch modes the path is each line's rest (the header keeps
|
|
87
|
+
* the object's own size, as git's) and a converted blob is held whole, as git holds it.
|
|
88
|
+
*
|
|
89
|
+
* `%(objectsize:disk)` and `%(deltabase)` read the object's pack entry header or loose file
|
|
90
|
+
* (`objectDiskInfoOf`); a `remote-object-info` line prints them empty, as git.
|
|
91
|
+
*
|
|
92
|
+
* Not implemented: `--follow-symlinks`, `--filter` (2.5x). `--unordered` lists objects in
|
|
76
93
|
* the store's listing order, not pack order. The promisor-remote warning of
|
|
77
94
|
* `--batch-all-objects` is not printed.
|
|
78
95
|
*/
|
|
79
96
|
export class CatFileCommand extends PlumbingCommand {
|
|
80
97
|
private mode?: CatFileMode;
|
|
98
|
+
/** The on-disk measures, for `%(objectsize:disk)` and `%(deltabase)` */
|
|
99
|
+
private diskInfo?: Promise<ObjectDiskInfo>;
|
|
81
100
|
private type?: string;
|
|
82
101
|
private object?: string;
|
|
102
|
+
private path?: string;
|
|
83
103
|
private batch?: CatFileBatchMode;
|
|
84
104
|
private format?: string;
|
|
85
105
|
private buffer?: boolean;
|
|
@@ -95,6 +115,7 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
95
115
|
setMode(mode: CatFileMode): this {
|
|
96
116
|
this.checkCallable();
|
|
97
117
|
this.mode = mode;
|
|
118
|
+
this.modeSetLast = true;
|
|
98
119
|
return this;
|
|
99
120
|
}
|
|
100
121
|
|
|
@@ -105,6 +126,13 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
105
126
|
return this;
|
|
106
127
|
}
|
|
107
128
|
|
|
129
|
+
/** `--path=<path>`: the path `--textconv`/`--filters` convert for (ignored in batch modes). */
|
|
130
|
+
setPath(path: string): this {
|
|
131
|
+
this.checkCallable();
|
|
132
|
+
this.path = path;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
108
136
|
/** The object named on the command line. */
|
|
109
137
|
setObject(name: string): this {
|
|
110
138
|
this.checkCallable();
|
|
@@ -148,9 +176,13 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
148
176
|
setBatchAllObjects(all: boolean): this {
|
|
149
177
|
this.checkCallable();
|
|
150
178
|
this.allObjects = all;
|
|
179
|
+
if (all) this.modeSetLast = false;
|
|
151
180
|
return this;
|
|
152
181
|
}
|
|
153
182
|
|
|
183
|
+
/** Whether {@link setMode} came after {@link setBatchAllObjects} (both git's cmdmodes) */
|
|
184
|
+
private modeSetLast = false;
|
|
185
|
+
|
|
154
186
|
/** `--unordered` (with `--batch-all-objects`): the store's order, not sorted by id. */
|
|
155
187
|
setUnordered(unordered: boolean): this {
|
|
156
188
|
this.checkCallable();
|
|
@@ -204,9 +236,27 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
204
236
|
/** The option checks of cmd_cat_file that the setters can still break. */
|
|
205
237
|
private checkOptions(): void {
|
|
206
238
|
const usage = (message: string) => new PlumbingError(`fatal: ${message}`, 129);
|
|
239
|
+
const transform = this.mode === "textconv" || this.mode === "filters";
|
|
240
|
+
if (this.path !== undefined && !transform) {
|
|
241
|
+
throw usage("'--path=<path|tree-ish>' needs '--filters' or '--textconv'");
|
|
242
|
+
}
|
|
243
|
+
if (transform && this.allObjects) {
|
|
244
|
+
// OPT_CMDMODE: --batch-all-objects is a cmdmode too, refused by parse_options
|
|
245
|
+
const [first, second] = this.modeSetLast
|
|
246
|
+
? ["--batch-all-objects", `--${this.mode}`]
|
|
247
|
+
: [`--${this.mode}`, "--batch-all-objects"];
|
|
248
|
+
throw new PlumbingError(
|
|
249
|
+
this.compatibility === "2.43"
|
|
250
|
+
? `error: ${second} is incompatible with ${first}`
|
|
251
|
+
: `error: options '${second}' and '${first}' cannot be used together`,
|
|
252
|
+
129,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
207
255
|
if (this.batch) {
|
|
208
|
-
if (this.mode
|
|
209
|
-
|
|
256
|
+
if (this.mode && !transform)
|
|
257
|
+
throw usage(`'-${modeLetter(this.mode)}' is incompatible with batch mode`);
|
|
258
|
+
// with --textconv/--filters git takes the transform branch first and ignores arguments
|
|
259
|
+
if (!transform && (this.object !== undefined || this.type !== undefined)) {
|
|
210
260
|
throw usage("batch modes take no arguments");
|
|
211
261
|
}
|
|
212
262
|
return;
|
|
@@ -223,6 +273,9 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
223
273
|
: undefined;
|
|
224
274
|
if (batchOption) throw usage(`'${batchOption}' requires a batch mode`);
|
|
225
275
|
if (this.mode) {
|
|
276
|
+
if (this.object === undefined && transform) {
|
|
277
|
+
throw usage(`<rev> required with '--${this.mode}'`);
|
|
278
|
+
}
|
|
226
279
|
if (this.object === undefined) {
|
|
227
280
|
throw usage(`<object> required with '-${modeLetter(this.mode)}'`);
|
|
228
281
|
}
|
|
@@ -232,6 +285,13 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
232
285
|
}
|
|
233
286
|
}
|
|
234
287
|
|
|
288
|
+
/** The batch modes' transform (`--textconv`, `--filters`) */
|
|
289
|
+
private get transformMode(): "textconv" | "filters" | undefined {
|
|
290
|
+
return this.batch && (this.mode === "textconv" || this.mode === "filters")
|
|
291
|
+
? this.mode
|
|
292
|
+
: undefined;
|
|
293
|
+
}
|
|
294
|
+
|
|
235
295
|
private get objects(): GitObjects {
|
|
236
296
|
const objects = this._workingCopy.history?.objects;
|
|
237
297
|
if (!objects) throw new Error("WorkingCopy.history is required for commands");
|
|
@@ -299,15 +359,23 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
299
359
|
private async catOne(name: string): Promise<number> {
|
|
300
360
|
const resolver = this.revisionResolver();
|
|
301
361
|
let id: ObjectId | undefined;
|
|
362
|
+
const transform = this.mode === "textconv" || this.mode === "filters";
|
|
302
363
|
try {
|
|
303
364
|
// GET_OID_HASH_ANY: an id of the compatibility format (full or abbreviated) names the
|
|
304
365
|
// object as that format sees it (its storage object converted)
|
|
305
|
-
id = await resolver.resolve(name, {
|
|
366
|
+
id = await resolver.resolve(name, {
|
|
367
|
+
onlyToDie: true,
|
|
368
|
+
hashAny: true,
|
|
369
|
+
requirePath: transform && this.path === undefined,
|
|
370
|
+
});
|
|
306
371
|
} finally {
|
|
307
372
|
for (const line of resolver.warnings) this.warn(line);
|
|
308
373
|
resolver.warnings.length = 0;
|
|
309
374
|
}
|
|
310
375
|
if (id === undefined) throw new PlumbingError(`fatal: Not a valid object name ${name}`);
|
|
376
|
+
// GET_OID_RECORD_PATH: the path and mode the name read (a mode it did not read: 0100644)
|
|
377
|
+
const path = this.path ?? resolver.lastPath ?? "";
|
|
378
|
+
const mode = resolver.lastMode ?? 0o100644;
|
|
311
379
|
const compat = this.compatIdOf(id);
|
|
312
380
|
if (compat) return this.catOneCompat(id, compat);
|
|
313
381
|
const couldNotGetInfo = () =>
|
|
@@ -335,6 +403,25 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
335
403
|
return (await this.objects.has(id)) ? 0 : 1;
|
|
336
404
|
case "pretty":
|
|
337
405
|
return this.pretty(name, await this.replaced(id));
|
|
406
|
+
case "filters": {
|
|
407
|
+
const object = await this.read(await this.replaced(id));
|
|
408
|
+
if (!object) {
|
|
409
|
+
this.warn(`error: cannot read object ${id} '${path}'`);
|
|
410
|
+
return 255;
|
|
411
|
+
}
|
|
412
|
+
await this.write(
|
|
413
|
+
object.type === "blob" ? await this.filtered(path, mode, id, object.bytes) : object.bytes,
|
|
414
|
+
);
|
|
415
|
+
return 0;
|
|
416
|
+
}
|
|
417
|
+
case "textconv": {
|
|
418
|
+
const converted = await this.textconv(path, mode, await this.replaced(id), id);
|
|
419
|
+
if (converted) {
|
|
420
|
+
await this.write(converted);
|
|
421
|
+
return 0;
|
|
422
|
+
}
|
|
423
|
+
return this.pretty(name, await this.replaced(id));
|
|
424
|
+
}
|
|
338
425
|
default:
|
|
339
426
|
return this.catTyped(name, id, this.type as string);
|
|
340
427
|
}
|
|
@@ -405,6 +492,67 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
405
492
|
}
|
|
406
493
|
}
|
|
407
494
|
|
|
495
|
+
/**
|
|
496
|
+
* filter_object's conversion of a blob: `convert_to_working_tree` for `path` when `mode` is
|
|
497
|
+
* a regular file's (smudge filter, `eol`, `ident`, `working-tree-encoding`).
|
|
498
|
+
*/
|
|
499
|
+
private async filtered(
|
|
500
|
+
path: string,
|
|
501
|
+
mode: number,
|
|
502
|
+
id: ObjectId,
|
|
503
|
+
bytes: Uint8Array,
|
|
504
|
+
): Promise<Uint8Array> {
|
|
505
|
+
if ((mode & S_IFMT) !== S_IFREG) return bytes;
|
|
506
|
+
const filter = this.worktreeAccess?.contentFilter;
|
|
507
|
+
if (!filter) return bytes;
|
|
508
|
+
try {
|
|
509
|
+
const conversion = await filter.checkout(path);
|
|
510
|
+
if (!conversion) return bytes;
|
|
511
|
+
return await conversion.apply(bytes, {
|
|
512
|
+
onWarning: (message) => this.warn(message),
|
|
513
|
+
metadata: { blob: id },
|
|
514
|
+
});
|
|
515
|
+
} catch (error) {
|
|
516
|
+
if (
|
|
517
|
+
error instanceof FilterDriverError ||
|
|
518
|
+
(error instanceof Error &&
|
|
519
|
+
error.message === "true/false are no valid working-tree-encodings")
|
|
520
|
+
) {
|
|
521
|
+
throw new PlumbingError(`fatal: ${(error as Error).message}`);
|
|
522
|
+
}
|
|
523
|
+
throw error;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** The diff command whose textconv caches this run shares (git's per-process caches) */
|
|
528
|
+
private textconvDiff?: DiffCommand;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* textconv_object: the output of `path`'s textconv driver over the blob `target` (read for
|
|
532
|
+
* `id`, the name the cache is keyed by), or undefined when no driver applies.
|
|
533
|
+
*/
|
|
534
|
+
private async textconv(
|
|
535
|
+
path: string,
|
|
536
|
+
mode: number,
|
|
537
|
+
target: ObjectId,
|
|
538
|
+
id: ObjectId,
|
|
539
|
+
): Promise<Uint8Array | undefined> {
|
|
540
|
+
this.textconvDiff ??= new DiffCommand(this._workingCopy);
|
|
541
|
+
const read = async () => {
|
|
542
|
+
const object = await this.read(target);
|
|
543
|
+
if (!object) throw new PlumbingError(`fatal: unable to read ${id}`);
|
|
544
|
+
return object.bytes;
|
|
545
|
+
};
|
|
546
|
+
try {
|
|
547
|
+
return await this.textconvDiff.textconvBlob(path, mode, read, id);
|
|
548
|
+
} catch (error) {
|
|
549
|
+
if (error instanceof GitApiError) throw error;
|
|
550
|
+
// fill_textconv: run_textconv fails without a line of its own (finish_command's
|
|
551
|
+
// status), then the death
|
|
552
|
+
throw new PlumbingError("fatal: unable to read files to diff");
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
408
556
|
/** `-p` */
|
|
409
557
|
private async pretty(name: string, id: ObjectId): Promise<number> {
|
|
410
558
|
const info = await this.info(id);
|
|
@@ -490,11 +638,9 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
490
638
|
/** batch_objects */
|
|
491
639
|
private async runBatch(): Promise<number> {
|
|
492
640
|
const compatibility = this.compatibility;
|
|
493
|
-
// --batch-command
|
|
494
|
-
//
|
|
495
|
-
const format = parseBatchFormat(this.format ?? DEFAULT_BATCH_FORMAT, compatibility
|
|
496
|
-
deferUnsupported: this.batch === "command",
|
|
497
|
-
});
|
|
641
|
+
// a remote-object-info line of --batch-command prints %(objectsize:disk)/%(deltabase)
|
|
642
|
+
// empty, as git
|
|
643
|
+
const format = parseBatchFormat(this.format ?? DEFAULT_BATCH_FORMAT, compatibility);
|
|
498
644
|
const plain = this.format === undefined || this.format === DEFAULT_BATCH_FORMAT;
|
|
499
645
|
const state: BatchState = {
|
|
500
646
|
format,
|
|
@@ -524,7 +670,7 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
524
670
|
for await (const line of lines) {
|
|
525
671
|
let name = line;
|
|
526
672
|
let rest: string | undefined;
|
|
527
|
-
if (format.splitOnWhitespace) {
|
|
673
|
+
if (format.splitOnWhitespace || this.transformMode) {
|
|
528
674
|
const split = /[ \t]/.exec(line);
|
|
529
675
|
if (split) {
|
|
530
676
|
name = line.slice(0, split.index);
|
|
@@ -730,6 +876,16 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
730
876
|
await this.write(state.delim);
|
|
731
877
|
}
|
|
732
878
|
|
|
879
|
+
/** `disk_sizep` and `delta_base_oid` of the object info batch_object_write asks for. */
|
|
880
|
+
private async onDisk(id: ObjectId, data: BatchObjectData): Promise<void> {
|
|
881
|
+
this.diskInfo ??= objectDiskInfoOf(this._workingCopy);
|
|
882
|
+
const info = await this.diskInfo;
|
|
883
|
+
const diskSize = await info.diskSize(id);
|
|
884
|
+
const deltaBase = await info.deltaBase(id);
|
|
885
|
+
if (diskSize !== undefined) data.diskSize = diskSize;
|
|
886
|
+
if (deltaBase !== undefined) data.deltaBase = deltaBase;
|
|
887
|
+
}
|
|
888
|
+
|
|
733
889
|
/** batch_object_write */
|
|
734
890
|
private async batchObjectWrite(
|
|
735
891
|
state: BatchState,
|
|
@@ -752,6 +908,7 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
752
908
|
}
|
|
753
909
|
data.type = info.type;
|
|
754
910
|
data.size = info.size;
|
|
911
|
+
if (state.format.needsDisk) await this.onDisk(target, data);
|
|
755
912
|
let content: Uint8Array | undefined;
|
|
756
913
|
if (this.useMailmap && (info.type === "commit" || info.type === "tag")) {
|
|
757
914
|
const object = await this.read(target);
|
|
@@ -764,7 +921,17 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
764
921
|
: `${expandBatchFormat(state.format, data)}${state.delim}`;
|
|
765
922
|
await this.write(header);
|
|
766
923
|
if (!state.contents) return;
|
|
767
|
-
if (info.type === "blob") {
|
|
924
|
+
if (info.type === "blob" && this.transformMode) {
|
|
925
|
+
// print_object_or_die: the line's rest is the path, the blob held whole
|
|
926
|
+
if (data.rest === undefined) throw new PlumbingError(`fatal: missing path for '${data.id}'`);
|
|
927
|
+
const object = await this.read(target);
|
|
928
|
+
if (!object) throw new PlumbingError(`fatal: could not convert '${data.id}' ${data.rest}`);
|
|
929
|
+
const converted =
|
|
930
|
+
this.transformMode === "filters"
|
|
931
|
+
? await this.filtered(data.rest, 0o100644, data.id, object.bytes)
|
|
932
|
+
: ((await this.textconv(data.rest, 0o100644, target, data.id)) ?? object.bytes);
|
|
933
|
+
await this.write(converted);
|
|
934
|
+
} else if (info.type === "blob") {
|
|
768
935
|
await this.streamBlob(target);
|
|
769
936
|
} else {
|
|
770
937
|
if (!content) {
|
|
@@ -795,39 +962,6 @@ const MAX_ALLOWED_OBJ_LIMIT = 10000;
|
|
|
795
962
|
/** cat-file.c's MAX_REMOTE_OBJ_INFO_LINE: a URL of 8 KiB and the ids (GIT_MAX_HEXSZ + 1 each). */
|
|
796
963
|
const MAX_REMOTE_OBJ_INFO_LINE = 8 * 1024 + MAX_ALLOWED_OBJ_LIMIT * (64 + 1);
|
|
797
964
|
|
|
798
|
-
/**
|
|
799
|
-
* alias.c's split_cmdline: words split on whitespace, quotes removed, a backslash escaping
|
|
800
|
-
* the next character outside single quotes; split_cmdline_strerror's text on an error.
|
|
801
|
-
*/
|
|
802
|
-
function splitCmdline(line: string): string[] | string {
|
|
803
|
-
// one word to begin with; every whitespace run ends one and starts the next (a trailing
|
|
804
|
-
// run leaves an empty last word, as git's)
|
|
805
|
-
const args: string[] = [];
|
|
806
|
-
let current = "";
|
|
807
|
-
let quoted = "";
|
|
808
|
-
for (let i = 0; i < line.length; i++) {
|
|
809
|
-
const c = line[i] as string;
|
|
810
|
-
if (!quoted && /[ \t\n\r]/.test(c)) {
|
|
811
|
-
args.push(current);
|
|
812
|
-
current = "";
|
|
813
|
-
while (i + 1 < line.length && /[ \t\n\r]/.test(line[i + 1] as string)) i++;
|
|
814
|
-
} else if (!quoted && (c === "'" || c === '"')) {
|
|
815
|
-
quoted = c;
|
|
816
|
-
} else if (c === quoted) {
|
|
817
|
-
quoted = "";
|
|
818
|
-
} else {
|
|
819
|
-
if (c === "\\" && quoted !== "'") {
|
|
820
|
-
i++;
|
|
821
|
-
if (i >= line.length) return "cmdline ends with \\";
|
|
822
|
-
}
|
|
823
|
-
current += line[i];
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
if (quoted) return "unclosed quote";
|
|
827
|
-
args.push(current);
|
|
828
|
-
return args;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
965
|
function modeLetter(mode: CatFileMode): string {
|
|
832
966
|
return mode === "type" ? "t" : mode === "size" ? "s" : mode === "exists" ? "e" : "p";
|
|
833
967
|
}
|