@statewalker/vcs-commands 0.9.0 → 0.10.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/README.md +1 -1
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-backend.d.ts +2 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-modes.d.ts +6 -2
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-session.d.ts +4 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -1
- package/dist/commands/am/am-command.d.ts +41 -2
- package/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/apply/index.d.ts +1 -1
- package/dist/commands/apply/index.d.ts.map +1 -1
- package/dist/commands/archive/archive-command.d.ts +169 -0
- package/dist/commands/archive/archive-command.d.ts.map +1 -0
- package/dist/commands/archive/archive-entry.d.ts +60 -0
- package/dist/commands/archive/archive-entry.d.ts.map +1 -0
- package/dist/commands/archive/index.d.ts +8 -0
- package/dist/commands/archive/index.d.ts.map +1 -0
- package/dist/commands/archive/remote-archive-command.d.ts +56 -0
- package/dist/commands/archive/remote-archive-command.d.ts.map +1 -0
- package/dist/commands/archive/tar-archive.d.ts +31 -0
- package/dist/commands/archive/tar-archive.d.ts.map +1 -0
- package/dist/commands/archive/tar-commit-id.d.ts +13 -0
- package/dist/commands/archive/tar-commit-id.d.ts.map +1 -0
- package/dist/commands/archive/upload-archive-writer.d.ts +48 -0
- package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -0
- package/dist/commands/archive/zip-archive.d.ts +42 -0
- package/dist/commands/archive/zip-archive.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +10 -0
- package/dist/commands/attributes-source.d.ts.map +1 -1
- package/dist/commands/blame-command.d.ts +43 -1
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/bundle/bundle-create-command.d.ts +67 -0
- package/dist/commands/bundle/bundle-create-command.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-format.d.ts +89 -0
- package/dist/commands/bundle/bundle-format.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-list.d.ts +92 -0
- package/dist/commands/bundle/bundle-list.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-read-commands.d.ts +81 -0
- package/dist/commands/bundle/bundle-read-commands.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-support.d.ts +32 -0
- package/dist/commands/bundle/bundle-support.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-transport.d.ts +38 -0
- package/dist/commands/bundle/bundle-transport.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-uri-host.d.ts +43 -0
- package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-uri.d.ts +55 -0
- package/dist/commands/bundle/bundle-uri.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-verify.d.ts +63 -0
- package/dist/commands/bundle/bundle-verify.d.ts.map +1 -0
- package/dist/commands/bundle/index.d.ts +14 -0
- package/dist/commands/bundle/index.d.ts.map +1 -0
- package/dist/commands/cat-file/batch-format.d.ts +58 -0
- package/dist/commands/cat-file/batch-format.d.ts.map +1 -0
- package/dist/commands/cat-file/cat-file-command.d.ts +135 -0
- package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -0
- package/dist/commands/cat-file/index.d.ts +3 -0
- package/dist/commands/cat-file/index.d.ts.map +1 -0
- package/dist/commands/check-attr-command.d.ts +66 -0
- package/dist/commands/check-attr-command.d.ts.map +1 -0
- package/dist/commands/check-ignore-command.d.ts +58 -0
- package/dist/commands/check-ignore-command.d.ts.map +1 -0
- package/dist/commands/check-ref-format-command.d.ts +60 -0
- package/dist/commands/check-ref-format-command.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-index-command.d.ts +96 -0
- package/dist/commands/checkout-index-command.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +10 -0
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +19 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +9 -1
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/config-command.d.ts +2 -0
- package/dist/commands/config-command.d.ts.map +1 -1
- package/dist/commands/daemon-access-hook.d.ts +36 -0
- package/dist/commands/daemon-access-hook.d.ts.map +1 -0
- package/dist/commands/default-branch.d.ts +42 -0
- package/dist/commands/default-branch.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +132 -5
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-external.d.ts +43 -0
- package/dist/commands/diff-external.d.ts.map +1 -0
- package/dist/commands/diff-plumbing/diff-pairs-command.d.ts +27 -0
- package/dist/commands/diff-plumbing/diff-pairs-command.d.ts.map +1 -0
- package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts +129 -0
- package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts.map +1 -0
- package/dist/commands/diff-plumbing/index.d.ts +3 -0
- package/dist/commands/diff-plumbing/index.d.ts.map +1 -0
- package/dist/commands/diff-textconv.d.ts +5 -1
- package/dist/commands/diff-textconv.d.ts.map +1 -1
- package/dist/commands/fast-export/fast-export-command.d.ts +135 -0
- package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -0
- package/dist/commands/fast-export/fast-import-command.d.ts +182 -0
- package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -0
- package/dist/commands/fast-export/fast-stream-support.d.ts +64 -0
- package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -0
- package/dist/commands/fast-export/index.d.ts +4 -0
- package/dist/commands/fast-export/index.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +65 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fetch-multiple-command.d.ts.map +1 -1
- package/dist/commands/format-rev-command.d.ts +58 -0
- package/dist/commands/format-rev-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-msg-ids.d.ts +18 -3
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -1
- package/dist/commands/fsmonitor-refresh.d.ts +69 -0
- package/dist/commands/fsmonitor-refresh.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +5 -0
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +32 -0
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/git-paths.d.ts +26 -0
- package/dist/commands/git-paths.d.ts.map +1 -0
- package/dist/commands/grep/grep-command.d.ts +2 -1
- package/dist/commands/grep/grep-command.d.ts.map +1 -1
- package/dist/commands/history-command.d.ts +156 -0
- package/dist/commands/history-command.d.ts.map +1 -0
- package/dist/commands/http-config.d.ts +38 -0
- package/dist/commands/http-config.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +12 -1
- package/dist/commands/index-adder.d.ts.map +1 -1
- package/dist/commands/index-host.d.ts.map +1 -1
- package/dist/commands/index.d.ts +44 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +6 -5
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/last-modified-command.d.ts +102 -0
- package/dist/commands/last-modified-command.d.ts.map +1 -0
- package/dist/commands/lfs/go-url.d.ts +43 -0
- package/dist/commands/lfs/go-url.d.ts.map +1 -0
- package/dist/commands/lfs/index.d.ts +3 -0
- package/dist/commands/lfs/index.d.ts.map +1 -0
- package/dist/commands/lfs/lfs-config.d.ts +174 -0
- package/dist/commands/lfs/lfs-config.d.ts.map +1 -0
- package/dist/commands/lfs/lfs-endpoint-command.d.ts +83 -0
- package/dist/commands/lfs/lfs-endpoint-command.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts.map +1 -1
- package/dist/commands/log-command.d.ts +26 -0
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +22 -1
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/ls-files-command.d.ts +153 -0
- package/dist/commands/ls-files-command.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +5 -0
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/ls-tree-command.d.ts +105 -0
- package/dist/commands/ls-tree-command.d.ts.map +1 -0
- package/dist/commands/maintenance-run-command.d.ts +122 -0
- package/dist/commands/maintenance-run-command.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +7 -0
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +7 -0
- package/dist/commands/merge-config.d.ts.map +1 -1
- package/dist/commands/merge-drivers.d.ts +67 -5
- package/dist/commands/merge-drivers.d.ts.map +1 -1
- package/dist/commands/merge-support.d.ts +6 -0
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/merge-tree-command.d.ts +122 -0
- package/dist/commands/merge-tree-command.d.ts.map +1 -0
- package/dist/commands/mktag-command.d.ts +51 -0
- package/dist/commands/mktag-command.d.ts.map +1 -0
- package/dist/commands/object-store/count-objects-command.d.ts +58 -0
- package/dist/commands/object-store/count-objects-command.d.ts.map +1 -0
- package/dist/commands/object-store/index.d.ts +5 -0
- package/dist/commands/object-store/index.d.ts.map +1 -0
- package/dist/commands/object-store/objects-directory.d.ts +12 -0
- package/dist/commands/object-store/objects-directory.d.ts.map +1 -0
- package/dist/commands/object-store/prune-command.d.ts +38 -0
- package/dist/commands/object-store/prune-command.d.ts.map +1 -0
- package/dist/commands/object-store/show-index-command.d.ts +23 -0
- package/dist/commands/object-store/show-index-command.d.ts.map +1 -0
- package/dist/commands/ort-merge.d.ts +24 -0
- package/dist/commands/ort-merge.d.ts.map +1 -1
- package/dist/commands/patch-id-command.d.ts +30 -0
- package/dist/commands/patch-id-command.d.ts.map +1 -0
- package/dist/commands/patch-id.d.ts +24 -0
- package/dist/commands/patch-id.d.ts.map +1 -1
- package/dist/commands/plumbing-command.d.ts +66 -0
- package/dist/commands/plumbing-command.d.ts.map +1 -0
- package/dist/commands/plumbing-input.d.ts +38 -0
- package/dist/commands/plumbing-input.d.ts.map +1 -0
- package/dist/commands/promisor-remote-reply.d.ts +35 -0
- package/dist/commands/promisor-remote-reply.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +17 -2
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +108 -2
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/refs-command.d.ts +81 -0
- package/dist/commands/refs-command.d.ts.map +1 -0
- package/dist/commands/remote-object-info-command.d.ts +55 -0
- package/dist/commands/remote-object-info-command.d.ts.map +1 -0
- package/dist/commands/remote-transport.d.ts +40 -3
- package/dist/commands/remote-transport.d.ts.map +1 -1
- package/dist/commands/repack-command.d.ts +115 -0
- package/dist/commands/repack-command.d.ts.map +1 -0
- package/dist/commands/replace-command.d.ts +143 -0
- package/dist/commands/replace-command.d.ts.map +1 -0
- package/dist/commands/replay-command.d.ts +117 -0
- package/dist/commands/replay-command.d.ts.map +1 -0
- package/dist/commands/repo-command.d.ts +136 -0
- package/dist/commands/repo-command.d.ts.map +1 -0
- package/dist/commands/request-pull-command.d.ts +82 -0
- package/dist/commands/request-pull-command.d.ts.map +1 -0
- package/dist/commands/rerere-command.d.ts +36 -0
- package/dist/commands/rerere-command.d.ts.map +1 -0
- package/dist/commands/rerere.d.ts +102 -0
- package/dist/commands/rerere.d.ts.map +1 -0
- package/dist/commands/rev-filter/commit-grep.d.ts +3 -1
- package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -1
- package/dist/commands/rev-list-command.d.ts +3 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -1
- package/dist/commands/rev-parse-command.d.ts +9 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -1
- package/dist/commands/revert-command.d.ts +10 -0
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +5 -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/sequencer-pick.d.ts +18 -0
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/serve-repository.d.ts +23 -1
- package/dist/commands/serve-repository.d.ts.map +1 -1
- package/dist/commands/session-id.d.ts +18 -0
- package/dist/commands/session-id.d.ts.map +1 -0
- package/dist/commands/show-branch-command.d.ts +59 -0
- package/dist/commands/show-branch-command.d.ts.map +1 -0
- package/dist/commands/show-ref-command.d.ts +112 -0
- package/dist/commands/show-ref-command.d.ts.map +1 -0
- package/dist/commands/signature-check.d.ts +9 -2
- package/dist/commands/signature-check.d.ts.map +1 -1
- package/dist/commands/signing.d.ts +22 -1
- package/dist/commands/signing.d.ts.map +1 -1
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-export-command.d.ts +115 -0
- package/dist/commands/stash-export-command.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +2 -1
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/stripspace-command.d.ts +44 -0
- package/dist/commands/stripspace-command.d.ts.map +1 -0
- package/dist/commands/submodule-add-command.d.ts +10 -1
- package/dist/commands/submodule-add-command.d.ts.map +1 -1
- package/dist/commands/submodule-auth.d.ts +3 -1
- package/dist/commands/submodule-auth.d.ts.map +1 -1
- package/dist/commands/submodule-commands.d.ts +9 -1
- package/dist/commands/submodule-commands.d.ts.map +1 -1
- package/dist/commands/submodule-update-command.d.ts +13 -1
- package/dist/commands/submodule-update-command.d.ts.map +1 -1
- package/dist/commands/textconv-cache.d.ts +58 -0
- package/dist/commands/textconv-cache.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +5 -0
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/unpack-objects-command.d.ts +47 -0
- package/dist/commands/unpack-objects-command.d.ts.map +1 -0
- package/dist/commands/update-index-command.d.ts +110 -0
- package/dist/commands/update-index-command.d.ts.map +1 -0
- package/dist/commands/uri-protocols.d.ts +13 -0
- package/dist/commands/uri-protocols.d.ts.map +1 -0
- package/dist/commands/url-parse-command.d.ts +30 -0
- package/dist/commands/url-parse-command.d.ts.map +1 -0
- package/dist/commands/var-command.d.ts +42 -0
- package/dist/commands/var-command.d.ts.map +1 -0
- package/dist/{commands-CNvli5bl.js → commands-Mlo1dxQN.js} +52078 -44471
- package/dist/errors/command-errors.d.ts +33 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/index.js +39 -1
- package/dist/{fsck-CPeDh9fh.js → fsck-CrhVMNIH.js} +184 -143
- package/dist/git-command.d.ts +58 -2
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +532 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/guarded-transport-command.d.ts +3 -1
- package/dist/guarded-transport-command.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/maintenance-run-command-Bw21HEkH.js +13539 -0
- package/dist/{remote-transport-CCmBadm-.js → remote-transport-Bu4PGSMD.js} +1009 -10
- package/dist/results/cherry-pick-result.d.ts +6 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/diff-entry.d.ts +10 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-output.d.ts +49 -3
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/fetch-result.d.ts +12 -0
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/merge-result.d.ts +5 -0
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +5 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/rebase-result.d.ts +7 -0
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +6 -0
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +5 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/{results-BDuEgdLU.js → results-ERo9vELd.js} +28511 -25685
- package/dist/transport-command.d.ts +79 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/commands/add-command.ts +3 -0
- package/src/commands/add-patch/patch-backend.ts +4 -1
- package/src/commands/add-patch/patch-modes.ts +26 -2
- package/src/commands/add-patch/patch-session.ts +6 -0
- package/src/commands/am/am-command.ts +163 -8
- package/src/commands/apply/index.ts +1 -0
- package/src/commands/archive/archive-command.ts +1148 -0
- package/src/commands/archive/archive-entry.ts +93 -0
- package/src/commands/archive/index.ts +7 -0
- package/src/commands/archive/remote-archive-command.ts +140 -0
- package/src/commands/archive/tar-archive.ts +207 -0
- package/src/commands/archive/tar-commit-id.ts +72 -0
- package/src/commands/archive/upload-archive-writer.ts +213 -0
- package/src/commands/archive/zip-archive.ts +317 -0
- package/src/commands/attributes-source.ts +26 -12
- package/src/commands/blame-command.ts +118 -19
- package/src/commands/bundle/bundle-create-command.ts +405 -0
- package/src/commands/bundle/bundle-format.ts +228 -0
- package/src/commands/bundle/bundle-list.ts +276 -0
- package/src/commands/bundle/bundle-read-commands.ts +157 -0
- package/src/commands/bundle/bundle-support.ts +85 -0
- package/src/commands/bundle/bundle-transport.ts +107 -0
- package/src/commands/bundle/bundle-uri-host.ts +204 -0
- package/src/commands/bundle/bundle-uri.ts +236 -0
- package/src/commands/bundle/bundle-verify.ts +152 -0
- package/src/commands/bundle/index.ts +14 -0
- package/src/commands/cat-file/batch-format.ts +193 -0
- package/src/commands/cat-file/cat-file-command.ts +857 -0
- package/src/commands/cat-file/index.ts +2 -0
- package/src/commands/check-attr-command.ts +333 -0
- package/src/commands/check-ignore-command.ts +261 -0
- package/src/commands/check-ref-format-command.ts +129 -0
- package/src/commands/checkout-command.ts +39 -21
- package/src/commands/checkout-index-command.ts +568 -0
- package/src/commands/checkout-paths.ts +7 -0
- package/src/commands/cherry-pick-command.ts +21 -1
- package/src/commands/clone-command.ts +208 -7
- package/src/commands/commit-command.ts +22 -4
- package/src/commands/config-command.ts +9 -0
- package/src/commands/daemon-access-hook.ts +78 -0
- package/src/commands/default-branch.ts +99 -1
- package/src/commands/diff-command.ts +573 -46
- package/src/commands/diff-external.ts +131 -0
- package/src/commands/diff-plumbing/diff-pairs-command.ts +193 -0
- package/src/commands/diff-plumbing/diff-plumbing-command.ts +424 -0
- package/src/commands/diff-plumbing/index.ts +2 -0
- package/src/commands/diff-textconv.ts +5 -1
- package/src/commands/fast-export/fast-export-command.ts +911 -0
- package/src/commands/fast-export/fast-import-command.ts +1553 -0
- package/src/commands/fast-export/fast-stream-support.ts +162 -0
- package/src/commands/fast-export/index.ts +3 -0
- package/src/commands/fetch-command.ts +312 -8
- package/src/commands/fetch-multiple-command.ts +4 -1
- package/src/commands/format-rev-command.ts +251 -0
- package/src/commands/fsck/fsck-command.ts +47 -20
- package/src/commands/fsck/fsck-msg-ids.ts +19 -3
- package/src/commands/fsck/fsck-pack.ts +2 -2
- package/src/commands/fsmonitor-refresh.ts +315 -0
- package/src/commands/gc-command.ts +10 -0
- package/src/commands/git-hooks.ts +123 -6
- package/src/commands/git-paths.ts +136 -0
- package/src/commands/grep/grep-command.ts +38 -15
- package/src/commands/history-command.ts +617 -0
- package/src/commands/http-config.ts +139 -0
- package/src/commands/index-adder.ts +37 -3
- package/src/commands/index-host.ts +6 -1
- package/src/commands/index.ts +45 -0
- package/src/commands/init-command.ts +14 -0
- package/src/commands/last-modified-command.ts +804 -0
- package/src/commands/lfs/go-url.ts +370 -0
- package/src/commands/lfs/index.ts +2 -0
- package/src/commands/lfs/lfs-config.ts +738 -0
- package/src/commands/lfs/lfs-endpoint-command.ts +180 -0
- package/src/commands/local-transport.ts +252 -4
- package/src/commands/log-command.ts +104 -5
- package/src/commands/log-output.ts +55 -5
- package/src/commands/ls-files-command.ts +1177 -0
- package/src/commands/ls-remote-command.ts +6 -0
- package/src/commands/ls-tree-command.ts +684 -0
- package/src/commands/maintenance-run-command.ts +949 -0
- package/src/commands/merge-command.ts +78 -32
- package/src/commands/merge-config.ts +23 -1
- package/src/commands/merge-drivers.ts +109 -20
- package/src/commands/merge-support.ts +29 -5
- package/src/commands/merge-tree-command.ts +786 -0
- package/src/commands/mktag-command.ts +149 -0
- package/src/commands/object-store/count-objects-command.ts +404 -0
- package/src/commands/object-store/index.ts +4 -0
- package/src/commands/object-store/objects-directory.ts +24 -0
- package/src/commands/object-store/prune-command.ts +129 -0
- package/src/commands/object-store/show-index-command.ts +151 -0
- package/src/commands/ort-merge.ts +92 -25
- package/src/commands/patch-id-command.ts +65 -0
- package/src/commands/patch-id.ts +218 -0
- package/src/commands/plumbing-command.ts +141 -0
- package/src/commands/plumbing-input.ts +87 -0
- package/src/commands/promisor-remote-reply.ts +276 -0
- package/src/commands/promisor-remote.ts +25 -2
- package/src/commands/pull-command.ts +2 -0
- package/src/commands/push-command.ts +87 -5
- package/src/commands/rebase-command.ts +507 -19
- package/src/commands/refs-command.ts +274 -0
- package/src/commands/remote-object-info-command.ts +109 -0
- package/src/commands/remote-transport.ts +116 -1
- package/src/commands/repack-command.ts +383 -0
- package/src/commands/replace-command.ts +816 -0
- package/src/commands/replay-command.ts +674 -0
- package/src/commands/repo-command.ts +967 -0
- package/src/commands/request-pull-command.ts +356 -0
- package/src/commands/rerere-command.ts +179 -0
- package/src/commands/rerere.ts +925 -0
- package/src/commands/rev-filter/commit-grep.ts +7 -2
- package/src/commands/rev-list-command.ts +9 -0
- package/src/commands/rev-parse-command.ts +62 -4
- package/src/commands/revert-command.ts +21 -1
- package/src/commands/revision-range.ts +7 -2
- package/src/commands/revision-resolver.ts +44 -3
- package/src/commands/sequencer-pick.ts +47 -0
- package/src/commands/serve-repository.ts +65 -0
- package/src/commands/session-id.ts +31 -0
- package/src/commands/show-branch-command.ts +981 -0
- package/src/commands/show-command.ts +1 -1
- package/src/commands/show-ref-command.ts +439 -0
- package/src/commands/signature-check.ts +37 -5
- package/src/commands/signing.ts +122 -16
- package/src/commands/stash-apply-command.ts +3 -0
- package/src/commands/stash-export-command.ts +397 -0
- package/src/commands/status-command.ts +43 -6
- package/src/commands/stripspace-command.ts +118 -0
- package/src/commands/submodule-add-command.ts +22 -1
- package/src/commands/submodule-auth.ts +61 -6
- package/src/commands/submodule-commands.ts +12 -2
- package/src/commands/submodule-update-command.ts +29 -0
- package/src/commands/textconv-cache.ts +143 -0
- package/src/commands/tree-restore.ts +14 -0
- package/src/commands/unpack-objects-command.ts +235 -0
- package/src/commands/update-index-command.ts +1016 -0
- package/src/commands/uri-protocols.ts +13 -0
- package/src/commands/url-parse-command.ts +67 -0
- package/src/commands/var-command.ts +219 -0
- package/src/errors/command-errors.ts +45 -0
- package/src/git-command.ts +131 -1
- package/src/git.ts +808 -1
- package/src/guarded-transport-command.ts +6 -1
- package/src/results/cherry-pick-result.ts +6 -0
- package/src/results/diff-entry.ts +12 -0
- package/src/results/diff-formatter.ts +7 -4
- package/src/results/diff-output.ts +117 -11
- package/src/results/diff-pickaxe.ts +1 -1
- package/src/results/fetch-result.ts +12 -0
- package/src/results/merge-result.ts +5 -0
- package/src/results/push-result.ts +5 -0
- package/src/results/rebase-result.ts +7 -0
- package/src/results/revert-result.ts +6 -0
- package/src/results/stash-result.ts +6 -0
- package/src/transport-command.ts +182 -1
|
@@ -0,0 +1,1553 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git fast-import` (builtin/fast-import.c): objects and refs written from a fast-import
|
|
3
|
+
* stream, as git writes them.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // git fast-import --quiet < stream
|
|
8
|
+
* const { exitCode, stderr } = await git.fastImport().setInput(stream).callOutput();
|
|
9
|
+
* // git fast-import --export-marks=marks --force < stream
|
|
10
|
+
* await git.fastImport().setInput(stream).setForce(true).setExportMarks("marks").setMarksFiles(files).call();
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ObjectId } from "@statewalker/vcs-core";
|
|
15
|
+
import { isSymbolicRef, isValidRefName, isValidWorktreePath } from "@statewalker/vcs-core";
|
|
16
|
+
import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
17
|
+
import { cUnquote } from "../apply/latin1.js";
|
|
18
|
+
import { localTimezoneOffset, parseGitDate } from "../git-date.js";
|
|
19
|
+
import { PlumbingCommand, PlumbingError } from "../plumbing-command.js";
|
|
20
|
+
import {
|
|
21
|
+
type FastMarksFiles,
|
|
22
|
+
isSignMode,
|
|
23
|
+
latin1,
|
|
24
|
+
latin1Bytes,
|
|
25
|
+
readObjectBytes,
|
|
26
|
+
type SignMode,
|
|
27
|
+
signatureStartOf,
|
|
28
|
+
writableSink,
|
|
29
|
+
} from "./fast-stream-support.js";
|
|
30
|
+
|
|
31
|
+
/** `--date-format=<fmt>` */
|
|
32
|
+
export type FastImportDateFormat = "raw" | "raw-permissive" | "rfc2822" | "now";
|
|
33
|
+
|
|
34
|
+
const S_IFMT = 0o170000;
|
|
35
|
+
const S_IFDIR = 0o040000;
|
|
36
|
+
const S_IFREG = 0o100000;
|
|
37
|
+
const S_IFLNK = 0o120000;
|
|
38
|
+
const S_IFGITLINK = 0o160000;
|
|
39
|
+
const BRANCH_TABLE_SIZE = 1039;
|
|
40
|
+
|
|
41
|
+
/** A tree entry being built (fast-import.c's tree_entry): `id` undefined while dirty. */
|
|
42
|
+
interface Node {
|
|
43
|
+
mode: number;
|
|
44
|
+
id: ObjectId | undefined;
|
|
45
|
+
/** The loaded entries, by name as a binary string; undefined until read */
|
|
46
|
+
entries?: Map<string, Node>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface Branch {
|
|
50
|
+
name: string;
|
|
51
|
+
/** The tip, or undefined for git's null oid */
|
|
52
|
+
oid: ObjectId | undefined;
|
|
53
|
+
root: Node;
|
|
54
|
+
delete: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface MarkedObject {
|
|
58
|
+
id: ObjectId;
|
|
59
|
+
type: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** fast-import.c's hc_str over the name's bytes as signed chars. */
|
|
63
|
+
function hcStr(name: string): number {
|
|
64
|
+
let r = 0;
|
|
65
|
+
for (const b of encodeGitPath(name)) {
|
|
66
|
+
const c = b > 127 ? b - 256 : b;
|
|
67
|
+
r = (Math.imul(r, 31) + c) >>> 0;
|
|
68
|
+
}
|
|
69
|
+
return r;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Thrown to end the run where git dies (its message, without `fatal: `). */
|
|
73
|
+
class FastImportDeath extends Error {}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Writes the objects and refs a fast-import stream describes (`git fast-import`).
|
|
77
|
+
*
|
|
78
|
+
* Supported: `blob`, `commit` (`M`, `D`, `R`, `C`, `deleteall`, `ls`, `cat-blob` among its
|
|
79
|
+
* changes; `from`, `merge`, `encoding`, `original-oid`, and 2.5x's `gpgsig`), `tag`,
|
|
80
|
+
* `reset`, `checkpoint`, `progress`, `done`, `alias`, `get-mark`, `cat-blob`, `ls`,
|
|
81
|
+
* `feature` and `option git`; marks files through {@link setMarksFiles}. Branches are
|
|
82
|
+
* updated at the end (and at each `checkpoint`) in git's order, refusing to rewind one
|
|
83
|
+
* unless {@link setForce} (`warning: not updating ...`, exit status 1); tags are written
|
|
84
|
+
* unconditionally, every update logged as `fast-import`. Where git dies, the objects
|
|
85
|
+
* written so far stay, marks are exported, and no ref moves.
|
|
86
|
+
*
|
|
87
|
+
* Not supported: notes (`N`), submodule rewriting (`rewrite-submodules-*`), the statistics
|
|
88
|
+
* report (`--stats`; ours prints none, as `--quiet`), the crash report file, and pack
|
|
89
|
+
* options (`--max-pack-size`, `--depth`, `--big-file-threshold`, accepted and ignored).
|
|
90
|
+
*
|
|
91
|
+
* Version differences (`setCompatibility("2.43")`): no `gpgsig` commands and no signature
|
|
92
|
+
* modes, and git's capitalised death messages.
|
|
93
|
+
*/
|
|
94
|
+
export class FastImportCommand extends PlumbingCommand {
|
|
95
|
+
private input: Uint8Array = new Uint8Array(0);
|
|
96
|
+
private compatibility: "2.43" | "2.56" = "2.56";
|
|
97
|
+
private marksFiles?: FastMarksFiles;
|
|
98
|
+
|
|
99
|
+
// command-line options (undefined: not given, a stream feature may set it)
|
|
100
|
+
private cliForce?: boolean;
|
|
101
|
+
private cliDone?: boolean;
|
|
102
|
+
private cliDateFormat?: FastImportDateFormat;
|
|
103
|
+
private cliImportMarks?: { path: string; ifExists: boolean };
|
|
104
|
+
private cliExportMarks?: string;
|
|
105
|
+
private cliRelativeMarks?: boolean;
|
|
106
|
+
private allowUnsafe = false;
|
|
107
|
+
private cliSignedTags?: SignMode;
|
|
108
|
+
private cliSignedCommits?: SignMode;
|
|
109
|
+
|
|
110
|
+
// effective settings
|
|
111
|
+
private force = false;
|
|
112
|
+
private requireDone = false;
|
|
113
|
+
private dateFormat: FastImportDateFormat = "raw";
|
|
114
|
+
private importMarksFile?: { path: string; relative: boolean; ifExists: boolean };
|
|
115
|
+
private importMarksFromStream = false;
|
|
116
|
+
private exportMarksFile?: { path: string; relative: boolean };
|
|
117
|
+
private relativeMarks = false;
|
|
118
|
+
private signedTags: SignMode = "verbatim";
|
|
119
|
+
private signedCommits: SignMode = "verbatim";
|
|
120
|
+
|
|
121
|
+
// the stream
|
|
122
|
+
private pos = 0;
|
|
123
|
+
private line = "";
|
|
124
|
+
private unread = false;
|
|
125
|
+
private eof = false;
|
|
126
|
+
private seenDataCommand = false;
|
|
127
|
+
|
|
128
|
+
// the import's state
|
|
129
|
+
private readonly marks = new Map<number, MarkedObject>();
|
|
130
|
+
private readonly objectTypes = new Map<ObjectId, string>();
|
|
131
|
+
private readonly branchTable: (Branch[] | undefined)[] = new Array(BRANCH_TABLE_SIZE);
|
|
132
|
+
private readonly branches = new Map<string, Branch>();
|
|
133
|
+
private tags: { name: string; id: ObjectId }[] = [];
|
|
134
|
+
private nextMark = 0;
|
|
135
|
+
private failure = false;
|
|
136
|
+
private importMarksDone = false;
|
|
137
|
+
|
|
138
|
+
private inputStream?: ReadableStream<Uint8Array>;
|
|
139
|
+
private outputStream?: WritableStream<Uint8Array>;
|
|
140
|
+
|
|
141
|
+
/** The stream (git reads it from stdin): bytes, text (UTF-8), or a Web Stream. */
|
|
142
|
+
setInput(input: string | Uint8Array | ReadableStream<Uint8Array>): this {
|
|
143
|
+
this.checkCallable();
|
|
144
|
+
if (input instanceof ReadableStream) this.inputStream = input;
|
|
145
|
+
else this.input = typeof input === "string" ? latin1Bytes(utf8Binary(input)) : input;
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Where the stream goes, as a Web Stream (in place of `setStdout`); not closed here. */
|
|
150
|
+
setOutput(stream: WritableStream<Uint8Array>): this {
|
|
151
|
+
this.checkCallable();
|
|
152
|
+
this.outputStream = stream;
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The input stream's reader while it is read as the commands need it (git's stdin) */
|
|
157
|
+
private reader?: ReadableStreamDefaultReader<Uint8Array>;
|
|
158
|
+
|
|
159
|
+
/** Pulls the next chunk of a streamed input; false at its end (or for bytes given whole). */
|
|
160
|
+
private async pull(): Promise<boolean> {
|
|
161
|
+
if (!this.reader) return false;
|
|
162
|
+
const { done, value } = await this.reader.read();
|
|
163
|
+
if (done) {
|
|
164
|
+
this.reader.releaseLock();
|
|
165
|
+
this.reader = undefined;
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const rest = this.input.subarray(this.pos);
|
|
169
|
+
const joined = new Uint8Array(rest.length + value.length);
|
|
170
|
+
joined.set(rest, 0);
|
|
171
|
+
joined.set(value, rest.length);
|
|
172
|
+
this.input = joined;
|
|
173
|
+
this.pos = 0;
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
override async call() {
|
|
178
|
+
if (this.inputStream) {
|
|
179
|
+
this.reader = this.inputStream.getReader();
|
|
180
|
+
this.input = new Uint8Array(0);
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
if (!this.outputStream) return await super.call();
|
|
184
|
+
const { sink, release } = writableSink(this.outputStream);
|
|
185
|
+
this.setStdout(sink);
|
|
186
|
+
try {
|
|
187
|
+
return await super.call();
|
|
188
|
+
} finally {
|
|
189
|
+
release();
|
|
190
|
+
}
|
|
191
|
+
} finally {
|
|
192
|
+
// git stops reading at `done` or a death: the rest of the stream stays the caller's
|
|
193
|
+
this.reader?.releaseLock();
|
|
194
|
+
this.reader = undefined;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** `--force`: branches may be rewound. */
|
|
199
|
+
setForce(force: boolean): this {
|
|
200
|
+
this.checkCallable();
|
|
201
|
+
this.cliForce = force;
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** `--done`: the stream must end with a `done` command. */
|
|
206
|
+
setDone(done: boolean): this {
|
|
207
|
+
this.checkCallable();
|
|
208
|
+
this.cliDone = done;
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** `--date-format=<fmt>` (default `raw`). */
|
|
213
|
+
setDateFormat(format: FastImportDateFormat): this {
|
|
214
|
+
this.checkCallable();
|
|
215
|
+
this.cliDateFormat = format;
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** `--import-marks=<file>` (or `--import-marks-if-exists=<file>` with `ifExists`). */
|
|
220
|
+
setImportMarks(path: string, options: { ifExists?: boolean } = {}): this {
|
|
221
|
+
this.checkCallable();
|
|
222
|
+
this.cliImportMarks = { path, ifExists: options.ifExists === true };
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** `--export-marks=<file>` */
|
|
227
|
+
setExportMarks(path: string): this {
|
|
228
|
+
this.checkCallable();
|
|
229
|
+
this.cliExportMarks = path;
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** `--[no-]relative-marks` */
|
|
234
|
+
setRelativeMarks(relative: boolean): this {
|
|
235
|
+
this.checkCallable();
|
|
236
|
+
this.cliRelativeMarks = relative;
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Where marks files are read and written. */
|
|
241
|
+
setMarksFiles(files: FastMarksFiles): this {
|
|
242
|
+
this.checkCallable();
|
|
243
|
+
this.marksFiles = files;
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** `--allow-unsafe-features`: the stream may name marks files. */
|
|
248
|
+
setAllowUnsafeFeatures(allow: boolean): this {
|
|
249
|
+
this.checkCallable();
|
|
250
|
+
this.allowUnsafe = allow;
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** `--signed-tags=<mode>` (git 2.50+, default `verbatim`). */
|
|
255
|
+
setSignedTags(mode: SignMode): this {
|
|
256
|
+
this.checkCallable();
|
|
257
|
+
this.cliSignedTags = mode;
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** `--signed-commits=<mode>` (git 2.50+, default `verbatim`). */
|
|
262
|
+
setSignedCommits(mode: SignMode): this {
|
|
263
|
+
this.checkCallable();
|
|
264
|
+
this.cliSignedCommits = mode;
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** The git version whose behaviour is followed (default 2.56). */
|
|
269
|
+
setCompatibility(version: "2.43" | "2.56"): this {
|
|
270
|
+
this.checkCallable();
|
|
271
|
+
this.compatibility = version;
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ---------------------------------------------------------------------------------------
|
|
276
|
+
|
|
277
|
+
private die(message: string, message243?: string): never {
|
|
278
|
+
throw new FastImportDeath(
|
|
279
|
+
this.compatibility === "2.43" ? (message243 ?? capitalized243(message)) : message,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private get objects() {
|
|
284
|
+
const objects = this.workingCopy.history?.objects;
|
|
285
|
+
if (!objects) throw new Error("fast-import needs the object store (history.objects)");
|
|
286
|
+
return objects;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
protected async run(): Promise<number> {
|
|
290
|
+
try {
|
|
291
|
+
while (await this.readNextCommand()) {
|
|
292
|
+
const cmd = this.line;
|
|
293
|
+
if (cmd === "blob") await this.parseNewBlob();
|
|
294
|
+
else if (cmd.startsWith("commit ")) await this.parseNewCommit(cmd.slice(7));
|
|
295
|
+
else if (cmd.startsWith("tag ")) await this.parseNewTag(cmd.slice(4));
|
|
296
|
+
else if (cmd.startsWith("reset ")) await this.parseResetBranch(cmd.slice(6));
|
|
297
|
+
else if (cmd.startsWith("ls ")) await this.parseLs(cmd.slice(3), undefined);
|
|
298
|
+
else if (cmd.startsWith("cat-blob ")) await this.parseCatBlob(cmd.slice(9));
|
|
299
|
+
else if (cmd.startsWith("get-mark ")) await this.parseGetMark(cmd.slice(9));
|
|
300
|
+
else if (cmd === "checkpoint") {
|
|
301
|
+
await this.skipOptionalLf();
|
|
302
|
+
await this.checkpoint();
|
|
303
|
+
} else if (cmd === "done") break;
|
|
304
|
+
else if (cmd === "alias") await this.parseAlias();
|
|
305
|
+
else if (cmd.startsWith("progress ")) {
|
|
306
|
+
await this.write(latin1Bytes(`${cmd}\n`));
|
|
307
|
+
await this.skipOptionalLf();
|
|
308
|
+
} else if (cmd.startsWith("feature ")) this.parseFeature(cmd.slice(8));
|
|
309
|
+
else if (cmd.startsWith("option git ")) this.parseOption(cmd.slice(11));
|
|
310
|
+
else if (cmd.startsWith("option ")) {
|
|
311
|
+
// non-git options are ignored
|
|
312
|
+
} else this.die(`unsupported command: ${cmd}`);
|
|
313
|
+
}
|
|
314
|
+
if (!this.seenDataCommand) await this.parseArgv();
|
|
315
|
+
if (this.requireDone && this.eof) this.die("stream ends early");
|
|
316
|
+
} catch (e) {
|
|
317
|
+
if (!(e instanceof FastImportDeath)) throw e;
|
|
318
|
+
// die_nicely: the objects stay, the marks are dumped, no ref moves
|
|
319
|
+
await this.dumpMarks().catch(() => undefined);
|
|
320
|
+
throw new PlumbingError(`fatal: ${e.message}`);
|
|
321
|
+
}
|
|
322
|
+
await this.dumpBranches();
|
|
323
|
+
await this.dumpTags();
|
|
324
|
+
await this.dumpMarks();
|
|
325
|
+
return this.failure ? 1 : 0;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ---------------------------------------------------------------- stream reading
|
|
329
|
+
|
|
330
|
+
/** strbuf_getline_lf: the next line without its newline; undefined at the end. */
|
|
331
|
+
private async readLine(): Promise<string | undefined> {
|
|
332
|
+
while (this.input.indexOf(10, this.pos) < 0 && (await this.pull())) {
|
|
333
|
+
// a line arrives in pieces
|
|
334
|
+
}
|
|
335
|
+
if (this.pos >= this.input.length) return undefined;
|
|
336
|
+
let end = this.input.indexOf(10, this.pos);
|
|
337
|
+
if (end < 0) end = this.input.length;
|
|
338
|
+
const line = latin1(this.input.subarray(this.pos, end));
|
|
339
|
+
this.pos = end + 1;
|
|
340
|
+
return line;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** read_next_command: false at the end of the stream. */
|
|
344
|
+
private async readNextCommand(): Promise<boolean> {
|
|
345
|
+
if (this.eof) {
|
|
346
|
+
this.unread = false;
|
|
347
|
+
this.line = "";
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
for (;;) {
|
|
351
|
+
if (this.unread) this.unread = false;
|
|
352
|
+
else {
|
|
353
|
+
const line = await this.readLine();
|
|
354
|
+
if (line === undefined) {
|
|
355
|
+
this.eof = true;
|
|
356
|
+
this.line = "";
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
this.line = line;
|
|
360
|
+
if (!this.seenDataCommand && !line.startsWith("feature ") && !line.startsWith("option ")) {
|
|
361
|
+
await this.parseArgv();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (this.line.startsWith("#")) continue;
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** git's fgetc/ungetc: waits for the next byte, consumed only when it is a newline. */
|
|
370
|
+
private async skipOptionalLf(): Promise<void> {
|
|
371
|
+
if (this.pos >= this.input.length) await this.pull();
|
|
372
|
+
if (this.input[this.pos] === 10) this.pos++;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** parse_data: the bytes of a `data` command, as a binary string. */
|
|
376
|
+
private async parseData(): Promise<string> {
|
|
377
|
+
const cmd = this.line;
|
|
378
|
+
if (!cmd.startsWith("data ")) this.die(`expected 'data n' command, found: ${cmd}`);
|
|
379
|
+
let data = cmd.slice(5);
|
|
380
|
+
let out: string;
|
|
381
|
+
if (data.startsWith("<<")) {
|
|
382
|
+
data = data.slice(2);
|
|
383
|
+
const parts: string[] = [];
|
|
384
|
+
for (;;) {
|
|
385
|
+
const line = await this.readLine();
|
|
386
|
+
if (line === undefined) this.die(`EOF in data (terminator '${data}' not found)`);
|
|
387
|
+
if (line === data) break;
|
|
388
|
+
parts.push(`${line}\n`);
|
|
389
|
+
}
|
|
390
|
+
out = parts.join("");
|
|
391
|
+
} else {
|
|
392
|
+
const length = Number(/^\s*\+?(\d*)/.exec(data)?.[1] || "0");
|
|
393
|
+
while (this.input.length - this.pos < length && (await this.pull())) {
|
|
394
|
+
// the data arrives in pieces
|
|
395
|
+
}
|
|
396
|
+
const available = this.input.length - this.pos;
|
|
397
|
+
if (available < length) {
|
|
398
|
+
this.pos = this.input.length;
|
|
399
|
+
this.die(`EOF in data (${length - available} bytes remaining)`);
|
|
400
|
+
}
|
|
401
|
+
out = latin1(this.input.subarray(this.pos, this.pos + length));
|
|
402
|
+
this.pos += length;
|
|
403
|
+
}
|
|
404
|
+
await this.skipOptionalLf();
|
|
405
|
+
return out;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
private parseMark(): Promise<void> | void {
|
|
409
|
+
if (this.line.startsWith("mark :")) {
|
|
410
|
+
this.nextMark = Number(/^\d*/.exec(this.line.slice(6))?.[0] || "0");
|
|
411
|
+
return this.readNextCommand().then(() => undefined);
|
|
412
|
+
}
|
|
413
|
+
this.nextMark = 0;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
private async parseOriginalIdentifier(): Promise<void> {
|
|
417
|
+
if (this.line.startsWith("original-oid ")) await this.readNextCommand();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// ---------------------------------------------------------------- options and features
|
|
421
|
+
|
|
422
|
+
/** parse_argv: the command line's options win over the stream's features. */
|
|
423
|
+
private async parseArgv(): Promise<void> {
|
|
424
|
+
if (this.cliForce !== undefined) this.force = this.cliForce;
|
|
425
|
+
if (this.cliDone !== undefined) this.requireDone = this.cliDone;
|
|
426
|
+
if (this.cliDateFormat !== undefined) this.dateFormat = this.cliDateFormat;
|
|
427
|
+
if (this.cliRelativeMarks !== undefined) this.relativeMarks = this.cliRelativeMarks;
|
|
428
|
+
if (this.cliSignedTags !== undefined) this.signedTags = this.cliSignedTags;
|
|
429
|
+
if (this.cliSignedCommits !== undefined) this.signedCommits = this.cliSignedCommits;
|
|
430
|
+
if (this.cliImportMarks) {
|
|
431
|
+
if (this.importMarksFile && !this.importMarksFromStream) await this.readMarks();
|
|
432
|
+
this.importMarksFile = {
|
|
433
|
+
path: this.cliImportMarks.path,
|
|
434
|
+
relative: this.relativeMarks,
|
|
435
|
+
ifExists: this.cliImportMarks.ifExists,
|
|
436
|
+
};
|
|
437
|
+
this.importMarksFromStream = false;
|
|
438
|
+
}
|
|
439
|
+
if (this.cliExportMarks !== undefined) {
|
|
440
|
+
this.exportMarksFile = { path: this.cliExportMarks, relative: this.relativeMarks };
|
|
441
|
+
}
|
|
442
|
+
this.seenDataCommand = true;
|
|
443
|
+
if (this.importMarksFile) await this.readMarks();
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
private checkUnsafe(feature: string, kind: "feature" | "option" = "feature"): void {
|
|
447
|
+
if (!this.allowUnsafe) {
|
|
448
|
+
this.die(`${kind} '${feature}' forbidden in input without --allow-unsafe-features`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private parseFeature(feature: string): void {
|
|
453
|
+
if (this.seenDataCommand) this.die(`got feature command '${feature}' after data command`);
|
|
454
|
+
const value = (prefix: string) =>
|
|
455
|
+
feature.startsWith(prefix) ? feature.slice(prefix.length) : undefined;
|
|
456
|
+
const dateFormat = value("date-format=");
|
|
457
|
+
const importMarks = value("import-marks=");
|
|
458
|
+
const importMarksIfExists = value("import-marks-if-exists=");
|
|
459
|
+
const exportMarks = value("export-marks=");
|
|
460
|
+
if (dateFormat !== undefined) {
|
|
461
|
+
this.dateFormat = parseDateFormat(dateFormat, (m) => this.die(m));
|
|
462
|
+
} else if (importMarks !== undefined) {
|
|
463
|
+
this.checkUnsafe("import-marks");
|
|
464
|
+
this.optionImportMarks(importMarks, false);
|
|
465
|
+
} else if (importMarksIfExists !== undefined) {
|
|
466
|
+
this.checkUnsafe("import-marks-if-exists");
|
|
467
|
+
this.optionImportMarks(importMarksIfExists, true);
|
|
468
|
+
} else if (exportMarks !== undefined) {
|
|
469
|
+
this.checkUnsafe(feature);
|
|
470
|
+
this.exportMarksFile = { path: exportMarks, relative: this.relativeMarks };
|
|
471
|
+
} else if (feature === "relative-marks") this.relativeMarks = true;
|
|
472
|
+
else if (feature === "no-relative-marks") this.relativeMarks = false;
|
|
473
|
+
else if (feature === "done") this.requireDone = true;
|
|
474
|
+
else if (feature === "force") this.force = true;
|
|
475
|
+
else if (["alias", "get-mark", "cat-blob", "notes", "ls"].includes(feature)) {
|
|
476
|
+
// supported
|
|
477
|
+
} else {
|
|
478
|
+
this.die(
|
|
479
|
+
`this version of fast-import does not support feature ${feature}.`,
|
|
480
|
+
`This version of fast-import does not support feature ${feature}.`,
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
private optionImportMarks(path: string, ifExists: boolean): void {
|
|
486
|
+
if (this.importMarksFile) this.die("only one import-marks command allowed per stream");
|
|
487
|
+
this.importMarksFile = { path, relative: this.relativeMarks, ifExists };
|
|
488
|
+
this.importMarksFromStream = true;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private parseOption(option: string): void {
|
|
492
|
+
if (this.seenDataCommand) this.die(`got option command '${option}' after data command`);
|
|
493
|
+
if (
|
|
494
|
+
option.startsWith("max-pack-size=") ||
|
|
495
|
+
option.startsWith("big-file-threshold=") ||
|
|
496
|
+
option.startsWith("depth=") ||
|
|
497
|
+
option.startsWith("active-branches=") ||
|
|
498
|
+
option === "stats" ||
|
|
499
|
+
option === "quiet" ||
|
|
500
|
+
option === "allow-unsafe-features"
|
|
501
|
+
) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (option.startsWith("export-pack-edges=")) {
|
|
505
|
+
this.checkUnsafe("export-pack-edges", "option");
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const mode = option.startsWith("signed-commits=")
|
|
509
|
+
? "commits"
|
|
510
|
+
: option.startsWith("signed-tags=")
|
|
511
|
+
? "tags"
|
|
512
|
+
: undefined;
|
|
513
|
+
if (mode && this.compatibility !== "2.43") {
|
|
514
|
+
const value = option.slice(option.indexOf("=") + 1);
|
|
515
|
+
if (!isSignMode(value)) this.die(`unknown --signed-${mode} mode '${value}'`);
|
|
516
|
+
if (mode === "commits") this.signedCommits = value;
|
|
517
|
+
else this.signedTags = value;
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
this.die(
|
|
521
|
+
`this version of fast-import does not support option: ${option}`,
|
|
522
|
+
`This version of fast-import does not support option: ${option}`,
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// ---------------------------------------------------------------- marks
|
|
527
|
+
|
|
528
|
+
private marksFilesOrDie(): FastMarksFiles {
|
|
529
|
+
if (!this.marksFiles) throw new Error("fast-import marks files need setMarksFiles");
|
|
530
|
+
return this.marksFiles;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
private async readMarks(): Promise<void> {
|
|
534
|
+
const file = this.importMarksFile;
|
|
535
|
+
if (!file) return;
|
|
536
|
+
const bytes = await this.marksFilesOrDie().read(file.path, { relative: file.relative });
|
|
537
|
+
if (bytes === undefined) {
|
|
538
|
+
if (file.ifExists) {
|
|
539
|
+
this.importMarksDone = true;
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
this.die(`cannot read '${file.path}': No such file or directory`);
|
|
543
|
+
}
|
|
544
|
+
const text = latin1(bytes as Uint8Array);
|
|
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();
|
|
554
|
+
let type = this.objectTypes.get(id);
|
|
555
|
+
if (!type) {
|
|
556
|
+
type = await this.odbType(id);
|
|
557
|
+
if (!type) this.die(`object not found: ${id}`);
|
|
558
|
+
this.objectTypes.set(id, type as string);
|
|
559
|
+
}
|
|
560
|
+
this.marks.set(mark, { id, type: type as string });
|
|
561
|
+
}
|
|
562
|
+
this.importMarksDone = true;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
private async dumpMarks(): Promise<void> {
|
|
566
|
+
const file = this.exportMarksFile;
|
|
567
|
+
if (!file || (this.importMarksFile && !this.importMarksDone)) return;
|
|
568
|
+
const sorted = [...this.marks.entries()].sort(([a], [b]) => a - b);
|
|
569
|
+
const text = sorted.map(([mark, o]) => `:${mark} ${o.id}\n`).join("");
|
|
570
|
+
await this.marksFilesOrDie().write(file.path, latin1Bytes(text), {
|
|
571
|
+
relative: file.relative,
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
private findMark(mark: number): MarkedObject {
|
|
576
|
+
const found = this.marks.get(mark);
|
|
577
|
+
if (!found) this.die(`mark :${mark} not declared`, `mark :${mark} not declared`);
|
|
578
|
+
return found as MarkedObject;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
private insertMark(mark: number, object: MarkedObject): void {
|
|
582
|
+
if (mark) this.marks.set(mark, object);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** parse_mark_ref: `:<n>` at the start of `text`, and what follows it. */
|
|
586
|
+
private parseMarkRef(text: string): { mark: number; rest: string } {
|
|
587
|
+
const m = /^:(\d*)/.exec(text) as RegExpExecArray;
|
|
588
|
+
if (!m[1]) this.die(`no value after ':' in mark: ${this.line}`);
|
|
589
|
+
return { mark: Number(m[1]), rest: text.slice(m[0].length) };
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
private parseMarkRefEol(text: string): number {
|
|
593
|
+
const { mark, rest } = this.parseMarkRef(text);
|
|
594
|
+
if (rest !== "") this.die(`garbage after mark: ${this.line}`);
|
|
595
|
+
return mark;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
private parseMarkRefSpace(text: string): { mark: number; rest: string } {
|
|
599
|
+
const { mark, rest } = this.parseMarkRef(text);
|
|
600
|
+
if (!rest.startsWith(" ")) this.die(`missing space after mark: ${this.line}`);
|
|
601
|
+
return { mark, rest: rest.slice(1) };
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// ---------------------------------------------------------------- objects
|
|
605
|
+
|
|
606
|
+
private async odbType(id: ObjectId): Promise<string | undefined> {
|
|
607
|
+
const header = await this.objects.header?.(id).catch(() => undefined);
|
|
608
|
+
if (header) return header.type;
|
|
609
|
+
return (await readObjectBytes(this.objects, id))?.type;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
private async typeOf(id: ObjectId): Promise<string | undefined> {
|
|
613
|
+
return this.objectTypes.get(id) ?? (await this.odbType(id));
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
private async storeObject(type: string, data: string, mark: number): Promise<ObjectId> {
|
|
617
|
+
const bytes = latin1Bytes(data);
|
|
618
|
+
const id = await this.objects.put(type as "blob", bytes.length, [bytes]);
|
|
619
|
+
this.objectTypes.set(id, type);
|
|
620
|
+
this.insertMark(mark, { id, type });
|
|
621
|
+
return id;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
private async parseNewBlob(): Promise<void> {
|
|
625
|
+
await this.readNextCommand();
|
|
626
|
+
await this.parseMark();
|
|
627
|
+
await this.parseOriginalIdentifier();
|
|
628
|
+
const data = await this.parseData();
|
|
629
|
+
await this.storeObject("blob", data, this.nextMark);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/** The tree of a commit (peeling tags), undefined when it is not one. */
|
|
633
|
+
private async commitTree(id: ObjectId): Promise<ObjectId | undefined> {
|
|
634
|
+
let current = id;
|
|
635
|
+
for (let depth = 0; depth < 64; depth++) {
|
|
636
|
+
const raw = await readObjectBytes(this.objects, current);
|
|
637
|
+
if (!raw) return undefined;
|
|
638
|
+
const text = latin1(raw.bytes);
|
|
639
|
+
if (raw.type === "commit") {
|
|
640
|
+
const m = /^tree ([0-9a-f]+)\n/.exec(text);
|
|
641
|
+
return m ? (m[1] as string) : undefined;
|
|
642
|
+
}
|
|
643
|
+
if (raw.type !== "tag") return undefined;
|
|
644
|
+
current = text.slice(7, text.indexOf("\n"));
|
|
645
|
+
}
|
|
646
|
+
return undefined;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
private async peelToCommit(id: ObjectId): Promise<ObjectId | undefined> {
|
|
650
|
+
let current = id;
|
|
651
|
+
for (let depth = 0; depth < 64; depth++) {
|
|
652
|
+
const raw = await readObjectBytes(this.objects, current);
|
|
653
|
+
if (!raw) return undefined;
|
|
654
|
+
if (raw.type === "commit") return current;
|
|
655
|
+
if (raw.type !== "tag") return undefined;
|
|
656
|
+
const text = latin1(raw.bytes);
|
|
657
|
+
current = text.slice(7, text.indexOf("\n"));
|
|
658
|
+
}
|
|
659
|
+
return undefined;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/** repo_get_oid, as fast-import resolves `from` and `merge` names. */
|
|
663
|
+
private async getOid(name: string): Promise<ObjectId | undefined> {
|
|
664
|
+
const hex = this.objectFormat.hexLength;
|
|
665
|
+
if (name.length === hex && /^[0-9a-fA-F]+$/.test(name)) return name.toLowerCase();
|
|
666
|
+
return this.revisionResolver()
|
|
667
|
+
.resolve(decodeGitPath(latin1Bytes(name)))
|
|
668
|
+
.catch(() => undefined);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// ---------------------------------------------------------------- idents
|
|
672
|
+
|
|
673
|
+
private parseIdent(text: string): string {
|
|
674
|
+
// ensure there is a space delimiter even if there is no name
|
|
675
|
+
const buf = text.startsWith("<") ? ` ${text}` : text;
|
|
676
|
+
const lt = buf.search(/[<>]/);
|
|
677
|
+
if (lt < 0 || buf[lt] !== "<") this.die(`missing < in ident string: ${buf}`);
|
|
678
|
+
if (lt !== 0 && buf[lt - 1] !== " ") {
|
|
679
|
+
this.die(`missing space before < in ident string: ${buf}`);
|
|
680
|
+
}
|
|
681
|
+
const rest = buf.slice(lt + 1);
|
|
682
|
+
const gt = rest.search(/[<>]/);
|
|
683
|
+
if (gt < 0 || rest[gt] !== ">") this.die(`missing > in ident string: ${buf}`);
|
|
684
|
+
const after = lt + 1 + gt + 1;
|
|
685
|
+
if (buf[after] !== " ") this.die(`missing space after > in ident string: ${buf}`);
|
|
686
|
+
const head = buf.slice(0, after + 1);
|
|
687
|
+
const when = buf.slice(after + 1);
|
|
688
|
+
switch (this.dateFormat) {
|
|
689
|
+
case "raw":
|
|
690
|
+
case "raw-permissive": {
|
|
691
|
+
if (!validRawDate(when, this.dateFormat === "raw")) {
|
|
692
|
+
this.die(`invalid raw date "${when}" in ident: ${buf}`);
|
|
693
|
+
}
|
|
694
|
+
return head + when;
|
|
695
|
+
}
|
|
696
|
+
case "rfc2822": {
|
|
697
|
+
const parsed = parseGitDate(when);
|
|
698
|
+
if (!parsed) this.die(`invalid rfc2822 date "${when}" in ident: ${buf}`);
|
|
699
|
+
const { timestamp, tzOffset } = parsed as { timestamp: number; tzOffset: string };
|
|
700
|
+
return `${head}${timestamp} ${tzOffset}`;
|
|
701
|
+
}
|
|
702
|
+
default: {
|
|
703
|
+
if (when !== "now") this.die(`date in ident must be 'now': ${buf}`);
|
|
704
|
+
const now = Math.floor(Date.now() / 1000);
|
|
705
|
+
return `${head}${now} ${localTimezoneOffset(now)}`;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// ---------------------------------------------------------------- branches and trees
|
|
711
|
+
|
|
712
|
+
private lookupBranch(name: string): Branch | undefined {
|
|
713
|
+
return this.branches.get(name);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
private newBranch(name: string): Branch {
|
|
717
|
+
if (this.branches.has(name)) this.die(`invalid attempt to create duplicate branch: ${name}`);
|
|
718
|
+
if (!isValidRefName(decodeGitPath(latin1Bytes(name)), { allowOneLevel: true })) {
|
|
719
|
+
this.die(
|
|
720
|
+
`branch name doesn't conform to Git standards: ${name}`,
|
|
721
|
+
`Branch name doesn't conform to GIT standards: ${name}`,
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
const b: Branch = {
|
|
725
|
+
name,
|
|
726
|
+
oid: undefined,
|
|
727
|
+
root: { mode: S_IFDIR, id: undefined, entries: new Map() },
|
|
728
|
+
delete: false,
|
|
729
|
+
};
|
|
730
|
+
const hc = hcStr(decodeGitPath(latin1Bytes(name))) % BRANCH_TABLE_SIZE;
|
|
731
|
+
const bucket = this.branchTable[hc] ?? [];
|
|
732
|
+
bucket.unshift(b);
|
|
733
|
+
this.branchTable[hc] = bucket;
|
|
734
|
+
this.branches.set(name, b);
|
|
735
|
+
return b;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
private async loadTree(node: Node): Promise<Map<string, Node>> {
|
|
739
|
+
if (node.entries) return node.entries;
|
|
740
|
+
const entries = new Map<string, Node>();
|
|
741
|
+
if (node.id !== undefined) {
|
|
742
|
+
const raw = await readObjectBytes(this.objects, node.id);
|
|
743
|
+
if (!raw) this.die(`can't load tree ${node.id}`);
|
|
744
|
+
if (raw?.type !== "tree") this.die(`can't load tree ${node.id}`);
|
|
745
|
+
parseRawTree(raw?.bytes as Uint8Array, this.objectFormat.rawLength, entries);
|
|
746
|
+
}
|
|
747
|
+
node.entries = entries;
|
|
748
|
+
return entries;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/** tree_content_set */
|
|
752
|
+
private async treeSet(
|
|
753
|
+
root: Node,
|
|
754
|
+
path: string,
|
|
755
|
+
id: ObjectId | undefined,
|
|
756
|
+
mode: number,
|
|
757
|
+
subtree?: Map<string, Node>,
|
|
758
|
+
): Promise<boolean> {
|
|
759
|
+
const slash = path.indexOf("/");
|
|
760
|
+
const name = slash < 0 ? path : path.slice(0, slash);
|
|
761
|
+
if (!name) this.die("empty path component found in input");
|
|
762
|
+
if (!isDir(root.mode)) this.die("non-directories cannot have subtrees");
|
|
763
|
+
const entries = await this.loadTree(root);
|
|
764
|
+
let e = entries.get(name);
|
|
765
|
+
if (e) {
|
|
766
|
+
if (slash < 0) {
|
|
767
|
+
if (!isDir(mode) && e.mode === mode && e.id === id) return false;
|
|
768
|
+
e.mode = mode;
|
|
769
|
+
e.id = id;
|
|
770
|
+
if (subtree) e.entries = subtree;
|
|
771
|
+
else delete e.entries;
|
|
772
|
+
root.id = undefined;
|
|
773
|
+
return true;
|
|
774
|
+
}
|
|
775
|
+
if (!isDir(e.mode)) {
|
|
776
|
+
e.entries = new Map();
|
|
777
|
+
e.mode = S_IFDIR;
|
|
778
|
+
}
|
|
779
|
+
if (await this.treeSet(e, path.slice(slash + 1), id, mode, subtree)) {
|
|
780
|
+
root.id = undefined;
|
|
781
|
+
return true;
|
|
782
|
+
}
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
e = { mode: S_IFDIR, id: undefined, entries: new Map() };
|
|
786
|
+
entries.set(name, e);
|
|
787
|
+
if (slash < 0) {
|
|
788
|
+
e.mode = mode;
|
|
789
|
+
e.id = id;
|
|
790
|
+
if (subtree) e.entries = subtree;
|
|
791
|
+
else delete e.entries;
|
|
792
|
+
} else {
|
|
793
|
+
await this.treeSet(e, path.slice(slash + 1), id, mode, subtree);
|
|
794
|
+
}
|
|
795
|
+
root.id = undefined;
|
|
796
|
+
return true;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/** tree_content_remove: the removed entry, or true when only something changed */
|
|
800
|
+
private async treeRemove(
|
|
801
|
+
root: Node,
|
|
802
|
+
path: string,
|
|
803
|
+
allowRoot: boolean,
|
|
804
|
+
): Promise<Node | true | undefined> {
|
|
805
|
+
const entries = await this.loadTree(root);
|
|
806
|
+
if (!path && allowRoot) {
|
|
807
|
+
const removed: Node = { mode: root.mode, id: root.id, entries: new Map(entries) };
|
|
808
|
+
root.entries = new Map();
|
|
809
|
+
root.id = undefined;
|
|
810
|
+
return removed;
|
|
811
|
+
}
|
|
812
|
+
const slash = path.indexOf("/");
|
|
813
|
+
const name = slash < 0 ? path : path.slice(0, slash);
|
|
814
|
+
const e = entries.get(name);
|
|
815
|
+
if (!e || (name === "" && slash >= 0)) return undefined;
|
|
816
|
+
if (slash >= 0 && !isDir(e.mode)) return true;
|
|
817
|
+
if (slash < 0 || !isDir(e.mode)) {
|
|
818
|
+
entries.delete(name);
|
|
819
|
+
root.id = undefined;
|
|
820
|
+
return e;
|
|
821
|
+
}
|
|
822
|
+
const removed = await this.treeRemove(e, path.slice(slash + 1), false);
|
|
823
|
+
if (removed === undefined) return undefined;
|
|
824
|
+
if ((e.entries?.size ?? 0) > 0) {
|
|
825
|
+
root.id = undefined;
|
|
826
|
+
return removed;
|
|
827
|
+
}
|
|
828
|
+
entries.delete(name);
|
|
829
|
+
root.id = undefined;
|
|
830
|
+
return removed;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/** tree_content_get */
|
|
834
|
+
private async treeGet(root: Node, path: string, allowRoot: boolean): Promise<Node | undefined> {
|
|
835
|
+
if (!path && allowRoot) return cloneNode(root);
|
|
836
|
+
const entries = await this.loadTree(root);
|
|
837
|
+
const slash = path.indexOf("/");
|
|
838
|
+
const name = slash < 0 ? path : path.slice(0, slash);
|
|
839
|
+
const e = entries.get(name);
|
|
840
|
+
if (!e) return undefined;
|
|
841
|
+
if (slash < 0) return cloneNode(e);
|
|
842
|
+
if (!isDir(e.mode)) return undefined;
|
|
843
|
+
return this.treeGet(e, path.slice(slash + 1), false);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** store_tree: writes every dirty tree, giving each its id. */
|
|
847
|
+
private async storeTree(node: Node): Promise<ObjectId> {
|
|
848
|
+
if (node.id !== undefined) return node.id;
|
|
849
|
+
const entries = await this.loadTree(node);
|
|
850
|
+
for (const e of entries.values())
|
|
851
|
+
if (isDir(e.mode) && e.id === undefined) await this.storeTree(e);
|
|
852
|
+
const sorted = [...entries.entries()].sort(([a, x], [b, y]) =>
|
|
853
|
+
compareBinary(isDir(x.mode) ? `${a}/` : a, isDir(y.mode) ? `${b}/` : b),
|
|
854
|
+
);
|
|
855
|
+
let data = "";
|
|
856
|
+
for (const [name, e] of sorted) {
|
|
857
|
+
data += `${e.mode.toString(8)} ${name}\0${hexToBinary(e.id as string)}`;
|
|
858
|
+
}
|
|
859
|
+
node.id = await this.storeObject("tree", data, 0);
|
|
860
|
+
return node.id;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// ---------------------------------------------------------------- paths
|
|
864
|
+
|
|
865
|
+
/** parse_path: a quoted or plain path, and what follows it */
|
|
866
|
+
private parsePath(text: string, last: boolean, field: string): { path: string; rest: string } {
|
|
867
|
+
if (text.startsWith('"')) {
|
|
868
|
+
const unq = cUnquote(text, 0);
|
|
869
|
+
if (!unq) this.die(`invalid ${field}: ${this.line}`, `Invalid ${field}: ${this.line}`);
|
|
870
|
+
const { name, end } = unq as { name: string; end: number };
|
|
871
|
+
if (name.includes("\0")) this.die(`NUL in ${field}: ${this.line}`);
|
|
872
|
+
return { path: name, rest: text.slice(end) };
|
|
873
|
+
}
|
|
874
|
+
if (last) return { path: text, rest: "" };
|
|
875
|
+
const space = text.indexOf(" ");
|
|
876
|
+
return space < 0
|
|
877
|
+
? { path: text, rest: "" }
|
|
878
|
+
: { path: text.slice(0, space), rest: text.slice(space) };
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
private parsePathEol(text: string, field: string): string {
|
|
882
|
+
const { path, rest } = this.parsePath(text, true, field);
|
|
883
|
+
if (rest !== "") {
|
|
884
|
+
this.die(`garbage after ${field}: ${this.line}`, `Garbage after ${field} in: ${this.line}`);
|
|
885
|
+
}
|
|
886
|
+
return path;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
private verifyPath(path: string, mode: number): void {
|
|
890
|
+
// git 2.43 checked no path (t9300's "invalid file path" cases are 2.44+)
|
|
891
|
+
if (this.compatibility === "2.43") return;
|
|
892
|
+
const ok = isValidWorktreePath(decodeGitPath(latin1Bytes(path)), mode, {
|
|
893
|
+
protectHFS: false,
|
|
894
|
+
protectNTFS: true,
|
|
895
|
+
});
|
|
896
|
+
if (!ok) this.die(`invalid path '${path}'`, `Invalid path: ${path}`);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// ---------------------------------------------------------------- commits
|
|
900
|
+
|
|
901
|
+
private async fileChangeM(text: string, b: Branch): Promise<void> {
|
|
902
|
+
const m = /^([0-7]+) /.exec(text);
|
|
903
|
+
if (!m || !/^[0-7]/.test(text)) this.die(`corrupt mode: ${this.line}`);
|
|
904
|
+
let mode = Number.parseInt((m as RegExpExecArray)[1] as string, 8) & 0xffff;
|
|
905
|
+
let p = text.slice((m as RegExpExecArray)[0].length);
|
|
906
|
+
switch (mode) {
|
|
907
|
+
case 0o644:
|
|
908
|
+
case 0o755:
|
|
909
|
+
mode |= S_IFREG;
|
|
910
|
+
break;
|
|
911
|
+
case S_IFREG | 0o644:
|
|
912
|
+
case S_IFREG | 0o755:
|
|
913
|
+
case S_IFLNK:
|
|
914
|
+
case S_IFDIR:
|
|
915
|
+
case S_IFGITLINK:
|
|
916
|
+
break;
|
|
917
|
+
default:
|
|
918
|
+
this.die(`corrupt mode: ${this.line}`);
|
|
919
|
+
}
|
|
920
|
+
let id: ObjectId | undefined;
|
|
921
|
+
let knownType: string | undefined;
|
|
922
|
+
let inline = false;
|
|
923
|
+
if (p.startsWith(":")) {
|
|
924
|
+
const { mark, rest } = this.parseMarkRefSpace(p);
|
|
925
|
+
const oe = this.findMark(mark);
|
|
926
|
+
id = oe.id;
|
|
927
|
+
knownType = oe.type;
|
|
928
|
+
p = rest;
|
|
929
|
+
} else if (p.startsWith("inline ")) {
|
|
930
|
+
inline = true;
|
|
931
|
+
p = p.slice(7);
|
|
932
|
+
} else {
|
|
933
|
+
const hex = this.objectFormat.hexLength;
|
|
934
|
+
const candidate = p.slice(0, hex);
|
|
935
|
+
if (!/^[0-9a-fA-F]+$/.test(candidate) || candidate.length !== hex) {
|
|
936
|
+
this.die(`invalid dataref: ${this.line}`);
|
|
937
|
+
}
|
|
938
|
+
id = candidate.toLowerCase();
|
|
939
|
+
knownType = this.objectTypes.get(id);
|
|
940
|
+
if (p[hex] !== " ") this.die(`missing space after SHA1: ${this.line}`);
|
|
941
|
+
p = p.slice(hex + 1);
|
|
942
|
+
}
|
|
943
|
+
const path = this.parsePathEol(p, "path");
|
|
944
|
+
|
|
945
|
+
// git does not track empty, non-toplevel directories
|
|
946
|
+
if (isDir(mode) && id === this.objectFormat.emptyTreeId && path) {
|
|
947
|
+
await this.treeRemove(b.root, path, false);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
if (mode === S_IFGITLINK) {
|
|
951
|
+
if (inline) this.die(`Git links cannot be specified 'inline': ${this.line}`);
|
|
952
|
+
if (knownType !== undefined && knownType !== "commit") {
|
|
953
|
+
this.die(`not a commit (actually a ${knownType}): ${this.line}`);
|
|
954
|
+
}
|
|
955
|
+
} else if (inline) {
|
|
956
|
+
if (isDir(mode)) this.die(`directories cannot be specified 'inline': ${this.line}`);
|
|
957
|
+
while (await this.readNextCommand()) {
|
|
958
|
+
if (this.line.startsWith("cat-blob ")) await this.parseCatBlob(this.line.slice(9));
|
|
959
|
+
else {
|
|
960
|
+
const data = await this.parseData();
|
|
961
|
+
id = await this.storeObject("blob", data, 0);
|
|
962
|
+
break;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
} else {
|
|
966
|
+
const expected = isDir(mode) ? "tree" : "blob";
|
|
967
|
+
const type = knownType ?? (await this.odbType(id as string));
|
|
968
|
+
if (type === undefined) {
|
|
969
|
+
this.die(
|
|
970
|
+
`${expected} not found: ${this.line}`,
|
|
971
|
+
`${capitalized243(expected)} not found: ${this.line}`,
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
if (type !== expected) this.die(`not a ${expected} (actually a ${type}): ${this.line}`);
|
|
975
|
+
}
|
|
976
|
+
if (!path) {
|
|
977
|
+
if (!isDir(mode)) this.die("root cannot be a non-directory");
|
|
978
|
+
b.root = { mode, id };
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
this.verifyPath(path, mode);
|
|
982
|
+
await this.treeSet(b.root, path, id, mode);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
private async fileChangeCR(text: string, b: Branch, rename: boolean): Promise<void> {
|
|
986
|
+
const src = this.parsePath(text, false, "source");
|
|
987
|
+
if (!src.rest.startsWith(" ")) {
|
|
988
|
+
this.die(
|
|
989
|
+
`missing space after source: ${this.line}`,
|
|
990
|
+
`Missing space after source: ${this.line}`,
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
const dest = this.parsePathEol(src.rest.slice(1), "dest");
|
|
994
|
+
const leaf = rename
|
|
995
|
+
? await this.treeRemove(b.root, src.path, true)
|
|
996
|
+
: await this.treeGet(b.root, src.path, true);
|
|
997
|
+
if (leaf === undefined || leaf === true || !leaf.mode) {
|
|
998
|
+
this.die(`path ${src.path} not in branch`);
|
|
999
|
+
}
|
|
1000
|
+
const node = leaf as Node;
|
|
1001
|
+
if (!dest) {
|
|
1002
|
+
if (!isDir(node.mode)) this.die("root cannot be a non-directory");
|
|
1003
|
+
b.root = { mode: node.mode, id: node.id, ...(node.entries ? { entries: node.entries } : {}) };
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
this.verifyPath(dest, node.mode);
|
|
1007
|
+
await this.treeSet(b.root, dest, node.id, node.mode, node.entries);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
private async parseObjectish(b: Branch, objectish: string): Promise<void> {
|
|
1011
|
+
const s = this.lookupBranch(objectish);
|
|
1012
|
+
if (s === b) this.die(`can't create a branch from itself: ${b.name}`);
|
|
1013
|
+
if (s) {
|
|
1014
|
+
b.oid = s.oid;
|
|
1015
|
+
b.root = { mode: S_IFDIR, id: s.oid ? await this.storeTree(s.root) : undefined };
|
|
1016
|
+
if (!s.oid) b.root.entries = new Map();
|
|
1017
|
+
} else if (objectish.startsWith(":")) {
|
|
1018
|
+
const mark = this.parseMarkRefEol(objectish);
|
|
1019
|
+
const oe = this.findMark(mark);
|
|
1020
|
+
if (oe.type !== "commit") this.die(`mark :${mark} not a commit`);
|
|
1021
|
+
if (b.oid !== oe.id) {
|
|
1022
|
+
b.oid = oe.id;
|
|
1023
|
+
await this.setRootFromCommit(b);
|
|
1024
|
+
}
|
|
1025
|
+
} else {
|
|
1026
|
+
const id = await this.getOid(objectish);
|
|
1027
|
+
if (id === undefined) {
|
|
1028
|
+
this.die(`invalid ref name or SHA1 expression: ${objectish}`);
|
|
1029
|
+
}
|
|
1030
|
+
b.oid = /^0+$/.test(id as string) ? undefined : id;
|
|
1031
|
+
if (b.oid === undefined) {
|
|
1032
|
+
b.root = { mode: S_IFDIR, id: undefined, entries: new Map() };
|
|
1033
|
+
b.delete = true;
|
|
1034
|
+
} else {
|
|
1035
|
+
const peeled = await this.peelToCommit(b.oid);
|
|
1036
|
+
if (!peeled) this.die(`not a valid commit: ${b.oid}`);
|
|
1037
|
+
b.oid = peeled;
|
|
1038
|
+
await this.setRootFromCommit(b);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
await this.readNextCommand();
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
private async setRootFromCommit(b: Branch): Promise<void> {
|
|
1045
|
+
const tree = await this.commitTree(b.oid as string);
|
|
1046
|
+
if (!tree) this.die(`not a valid commit: ${b.oid}`);
|
|
1047
|
+
b.root = { mode: S_IFDIR, id: tree };
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
private async parseMerge(): Promise<ObjectId[]> {
|
|
1051
|
+
const list: ObjectId[] = [];
|
|
1052
|
+
while (this.line.startsWith("merge ")) {
|
|
1053
|
+
const from = this.line.slice(6);
|
|
1054
|
+
const s = this.lookupBranch(from);
|
|
1055
|
+
let id: ObjectId;
|
|
1056
|
+
if (s) id = s.oid ?? this.objectFormat.nullId;
|
|
1057
|
+
else if (from.startsWith(":")) {
|
|
1058
|
+
const mark = this.parseMarkRefEol(from);
|
|
1059
|
+
const oe = this.findMark(mark);
|
|
1060
|
+
if (oe.type !== "commit") this.die(`mark :${mark} not a commit`);
|
|
1061
|
+
id = oe.id;
|
|
1062
|
+
} else {
|
|
1063
|
+
const named = await this.getOid(from);
|
|
1064
|
+
if (named === undefined) this.die(`invalid ref name or SHA1 expression: ${from}`);
|
|
1065
|
+
const peeled = await this.peelToCommit(named as string);
|
|
1066
|
+
if (!peeled) this.die(`not a valid commit: ${from}`);
|
|
1067
|
+
id = peeled as string;
|
|
1068
|
+
}
|
|
1069
|
+
list.push(id);
|
|
1070
|
+
await this.readNextCommand();
|
|
1071
|
+
}
|
|
1072
|
+
return list;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
private async parseSignature(v: string): Promise<{ hash: string; data: string }> {
|
|
1076
|
+
const space = v.indexOf(" ");
|
|
1077
|
+
if (space < 0) {
|
|
1078
|
+
this.die(
|
|
1079
|
+
`expected gpgsig format: 'gpgsig <hash-algo> <signature-format>', got 'gpgsig ${v}'`,
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
const hash = v.slice(0, space);
|
|
1083
|
+
const format = v.slice(space + 1);
|
|
1084
|
+
if (hash !== "sha1" && hash !== "sha256") {
|
|
1085
|
+
this.die(`unknown git hash algorithm in gpgsig: '${hash}'`);
|
|
1086
|
+
}
|
|
1087
|
+
if (!["openpgp", "x509", "ssh", "unknown"].includes(format)) {
|
|
1088
|
+
this.die(`invalid signature format in gpgsig: '${format}'`);
|
|
1089
|
+
}
|
|
1090
|
+
if (format === "unknown") this.warn("warning: 'unknown' signature format in gpgsig");
|
|
1091
|
+
await this.readNextCommand();
|
|
1092
|
+
return { hash, data: await this.parseData() };
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
private async parseNewCommit(arg: string): Promise<void> {
|
|
1096
|
+
const b = this.lookupBranch(arg) ?? this.newBranch(arg);
|
|
1097
|
+
await this.readNextCommand();
|
|
1098
|
+
await this.parseMark();
|
|
1099
|
+
const mark = this.nextMark;
|
|
1100
|
+
await this.parseOriginalIdentifier();
|
|
1101
|
+
let author: string | undefined;
|
|
1102
|
+
let committer: string | undefined;
|
|
1103
|
+
if (this.line.startsWith("author ")) {
|
|
1104
|
+
author = this.parseIdent(this.line.slice(7));
|
|
1105
|
+
await this.readNextCommand();
|
|
1106
|
+
}
|
|
1107
|
+
if (this.line.startsWith("committer ")) {
|
|
1108
|
+
committer = this.parseIdent(this.line.slice(10));
|
|
1109
|
+
await this.readNextCommand();
|
|
1110
|
+
}
|
|
1111
|
+
if (committer === undefined) this.die("expected committer but didn't get one");
|
|
1112
|
+
|
|
1113
|
+
const signatures: { sha1?: string; sha256?: string } = {};
|
|
1114
|
+
while (this.compatibility !== "2.43" && this.line.startsWith("gpgsig ")) {
|
|
1115
|
+
const v = this.line.slice(7);
|
|
1116
|
+
switch (this.signedCommits) {
|
|
1117
|
+
case "abort":
|
|
1118
|
+
this.die("encountered signed commit; use --signed-commits=<mode> to handle it");
|
|
1119
|
+
break;
|
|
1120
|
+
case "warn-strip":
|
|
1121
|
+
case "strip":
|
|
1122
|
+
if (this.signedCommits === "warn-strip") {
|
|
1123
|
+
this.warn("warning: stripping a commit signature");
|
|
1124
|
+
}
|
|
1125
|
+
await this.readNextCommand();
|
|
1126
|
+
await this.parseData();
|
|
1127
|
+
break;
|
|
1128
|
+
default: {
|
|
1129
|
+
if (this.signedCommits === "warn-verbatim" || this.signedCommits === "warn") {
|
|
1130
|
+
this.warn("warning: importing a commit signature verbatim");
|
|
1131
|
+
}
|
|
1132
|
+
const sig = await this.parseSignature(v);
|
|
1133
|
+
const key = sig.hash === "sha1" ? "sha1" : "sha256";
|
|
1134
|
+
if (signatures[key] !== undefined) {
|
|
1135
|
+
this.warn(
|
|
1136
|
+
`warning: multiple ${key === "sha1" ? "SHA-1" : "SHA-256"} signatures found, ignoring additional signature`,
|
|
1137
|
+
);
|
|
1138
|
+
} else signatures[key] = sig.data;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
await this.readNextCommand();
|
|
1142
|
+
}
|
|
1143
|
+
let encoding: string | undefined;
|
|
1144
|
+
if (this.line.startsWith("encoding ")) {
|
|
1145
|
+
encoding = this.line.slice(9);
|
|
1146
|
+
await this.readNextCommand();
|
|
1147
|
+
}
|
|
1148
|
+
const msg = await this.parseData();
|
|
1149
|
+
await this.readNextCommand();
|
|
1150
|
+
if (this.line.startsWith("from ")) await this.parseObjectish(b, this.line.slice(5));
|
|
1151
|
+
const merges = await this.parseMerge();
|
|
1152
|
+
|
|
1153
|
+
while (this.line.length > 0) {
|
|
1154
|
+
const cmd = this.line;
|
|
1155
|
+
if (cmd.startsWith("M ")) await this.fileChangeM(cmd.slice(2), b);
|
|
1156
|
+
else if (cmd.startsWith("D ")) {
|
|
1157
|
+
await this.treeRemove(b.root, this.parsePathEol(cmd.slice(2), "path"), true);
|
|
1158
|
+
} else if (cmd.startsWith("R ")) await this.fileChangeCR(cmd.slice(2), b, true);
|
|
1159
|
+
else if (cmd.startsWith("C ")) await this.fileChangeCR(cmd.slice(2), b, false);
|
|
1160
|
+
else if (cmd.startsWith("N ")) {
|
|
1161
|
+
throw new PlumbingError("fatal: fast-import notes (N) are not supported");
|
|
1162
|
+
} else if (cmd === "deleteall") {
|
|
1163
|
+
b.root = { mode: S_IFDIR, id: undefined, entries: new Map() };
|
|
1164
|
+
} else if (cmd.startsWith("ls ")) await this.parseLs(cmd.slice(3), b);
|
|
1165
|
+
else if (cmd.startsWith("cat-blob ")) await this.parseCatBlob(cmd.slice(9));
|
|
1166
|
+
else {
|
|
1167
|
+
this.unread = true;
|
|
1168
|
+
break;
|
|
1169
|
+
}
|
|
1170
|
+
if (!(await this.readNextCommand())) break;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
const tree = await this.storeTree(b.root);
|
|
1174
|
+
let data = `tree ${tree}\n`;
|
|
1175
|
+
if (b.oid !== undefined) data += `parent ${b.oid}\n`;
|
|
1176
|
+
for (const m of merges) data += `parent ${m}\n`;
|
|
1177
|
+
data += `author ${author ?? committer}\ncommitter ${committer}\n`;
|
|
1178
|
+
if (encoding !== undefined) data += `encoding ${encoding}\n`;
|
|
1179
|
+
for (const [header, sig] of [
|
|
1180
|
+
["gpgsig", signatures.sha1],
|
|
1181
|
+
["gpgsig-sha256", signatures.sha256],
|
|
1182
|
+
] as const) {
|
|
1183
|
+
if (sig === undefined) continue;
|
|
1184
|
+
data += `${header} ${sig.split("\n").join("\n ")}\n`;
|
|
1185
|
+
}
|
|
1186
|
+
data += `\n${msg}`;
|
|
1187
|
+
b.oid = await this.storeObject("commit", data, mark);
|
|
1188
|
+
b.delete = false;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// ---------------------------------------------------------------- tags and resets
|
|
1192
|
+
|
|
1193
|
+
private async parseNewTag(arg: string): Promise<void> {
|
|
1194
|
+
const entry = { name: arg, id: "" };
|
|
1195
|
+
this.tags.push(entry);
|
|
1196
|
+
await this.readNextCommand();
|
|
1197
|
+
await this.parseMark();
|
|
1198
|
+
const mark = this.nextMark;
|
|
1199
|
+
if (!this.line.startsWith("from ")) {
|
|
1200
|
+
this.die(
|
|
1201
|
+
`expected 'from' command, got '${this.line}'`,
|
|
1202
|
+
`Expected from command, got ${this.line}`,
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
const from = this.line.slice(5);
|
|
1206
|
+
let id: ObjectId;
|
|
1207
|
+
let type: string;
|
|
1208
|
+
const s = this.lookupBranch(from);
|
|
1209
|
+
if (s) {
|
|
1210
|
+
if (s.oid === undefined) this.die("can't tag an empty branch.");
|
|
1211
|
+
id = s.oid as string;
|
|
1212
|
+
type = "commit";
|
|
1213
|
+
} else if (from.startsWith(":")) {
|
|
1214
|
+
const oe = this.findMark(this.parseMarkRefEol(from));
|
|
1215
|
+
id = oe.id;
|
|
1216
|
+
type = oe.type;
|
|
1217
|
+
} else {
|
|
1218
|
+
const named = await this.getOid(from);
|
|
1219
|
+
if (named === undefined) this.die(`invalid ref name or SHA1 expression: ${from}`);
|
|
1220
|
+
id = named as string;
|
|
1221
|
+
const t = await this.typeOf(id);
|
|
1222
|
+
if (!t) this.die(`not a valid object: ${from}`);
|
|
1223
|
+
type = t as string;
|
|
1224
|
+
}
|
|
1225
|
+
await this.readNextCommand();
|
|
1226
|
+
await this.parseOriginalIdentifier();
|
|
1227
|
+
let tagger: string | undefined;
|
|
1228
|
+
if (this.line.startsWith("tagger ")) {
|
|
1229
|
+
tagger = this.parseIdent(this.line.slice(7));
|
|
1230
|
+
await this.readNextCommand();
|
|
1231
|
+
}
|
|
1232
|
+
let msg = await this.parseData();
|
|
1233
|
+
let data = `object ${id}\ntype ${type}\ntag ${arg}\n`;
|
|
1234
|
+
if (tagger !== undefined) data += `tagger ${tagger}\n`;
|
|
1235
|
+
if (this.compatibility !== "2.43") {
|
|
1236
|
+
const sigAt = signatureStartOf(msg, "2.56");
|
|
1237
|
+
if (sigAt < msg.length) {
|
|
1238
|
+
switch (this.signedTags) {
|
|
1239
|
+
case "warn-verbatim":
|
|
1240
|
+
case "warn":
|
|
1241
|
+
this.warn(`warning: importing a tag signature verbatim for tag '${arg}'`);
|
|
1242
|
+
break;
|
|
1243
|
+
case "verbatim":
|
|
1244
|
+
case "ignore":
|
|
1245
|
+
break;
|
|
1246
|
+
case "warn-strip":
|
|
1247
|
+
this.warn(`warning: stripping a tag signature for tag '${arg}'`);
|
|
1248
|
+
msg = msg.slice(0, sigAt);
|
|
1249
|
+
break;
|
|
1250
|
+
case "strip":
|
|
1251
|
+
msg = msg.slice(0, sigAt);
|
|
1252
|
+
break;
|
|
1253
|
+
default:
|
|
1254
|
+
this.die("encountered signed tag; use --signed-tags=<mode> to handle it");
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
data += `\n${msg}`;
|
|
1259
|
+
entry.id = await this.storeObject("tag", data, mark);
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
private async parseResetBranch(arg: string): Promise<void> {
|
|
1263
|
+
let b = this.lookupBranch(arg);
|
|
1264
|
+
if (b) {
|
|
1265
|
+
b.oid = undefined;
|
|
1266
|
+
b.root = { mode: S_IFDIR, id: undefined, entries: new Map() };
|
|
1267
|
+
} else b = this.newBranch(arg);
|
|
1268
|
+
await this.readNextCommand();
|
|
1269
|
+
if (this.line.startsWith("from ")) await this.parseObjectish(b, this.line.slice(5));
|
|
1270
|
+
if (b.delete && b.name.startsWith("refs/tags/")) {
|
|
1271
|
+
const tagName = b.name.slice(10);
|
|
1272
|
+
const at = this.tags.findIndex((t) => t.name === tagName);
|
|
1273
|
+
if (at >= 0) this.tags.splice(at, 1);
|
|
1274
|
+
}
|
|
1275
|
+
if (this.line.length > 0) this.unread = true;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
// ---------------------------------------------------------------- queries
|
|
1279
|
+
|
|
1280
|
+
private async catBlobWrite(text: string | Uint8Array): Promise<void> {
|
|
1281
|
+
await this.write(typeof text === "string" ? latin1Bytes(text) : text);
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
private async parseGetMark(p: string): Promise<void> {
|
|
1285
|
+
if (!p.startsWith(":")) this.die(`not a mark: ${p}`);
|
|
1286
|
+
const oe = this.findMark(this.parseMarkRefEol(p));
|
|
1287
|
+
await this.catBlobWrite(`${oe.id}\n`);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
private async parseCatBlob(p: string): Promise<void> {
|
|
1291
|
+
let id: ObjectId;
|
|
1292
|
+
if (p.startsWith(":")) id = this.findMark(this.parseMarkRefEol(p)).id;
|
|
1293
|
+
else {
|
|
1294
|
+
const hex = this.objectFormat.hexLength;
|
|
1295
|
+
const candidate = p.slice(0, hex);
|
|
1296
|
+
if (candidate.length !== hex || !/^[0-9a-fA-F]+$/.test(candidate)) {
|
|
1297
|
+
this.die(`invalid dataref: ${this.line}`);
|
|
1298
|
+
}
|
|
1299
|
+
if (p.length > hex) this.die(`garbage after SHA1: ${this.line}`);
|
|
1300
|
+
id = candidate.toLowerCase();
|
|
1301
|
+
}
|
|
1302
|
+
const raw = await readObjectBytes(this.objects, id);
|
|
1303
|
+
if (!raw) {
|
|
1304
|
+
await this.catBlobWrite(`${id} missing\n`);
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
if (raw.type !== "blob") this.die(`object ${id} is a ${raw.type} but a blob was expected.`);
|
|
1308
|
+
await this.catBlobWrite(`${id} blob ${raw.bytes.length}\n`);
|
|
1309
|
+
await this.catBlobWrite(raw.bytes);
|
|
1310
|
+
await this.catBlobWrite("\n");
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
private async parseLs(p: string, b: Branch | undefined): Promise<void> {
|
|
1314
|
+
let root: Node;
|
|
1315
|
+
let rest = p;
|
|
1316
|
+
if (p.startsWith('"')) {
|
|
1317
|
+
if (!b) this.die(`not in a commit: ${this.line}`);
|
|
1318
|
+
root = (b as Branch).root;
|
|
1319
|
+
} else {
|
|
1320
|
+
let id: ObjectId;
|
|
1321
|
+
if (p.startsWith(":")) {
|
|
1322
|
+
const { mark, rest: r } = this.parseMarkRefSpace(p);
|
|
1323
|
+
id = this.findMark(mark).id;
|
|
1324
|
+
rest = r;
|
|
1325
|
+
} else {
|
|
1326
|
+
const hex = this.objectFormat.hexLength;
|
|
1327
|
+
const candidate = p.slice(0, hex);
|
|
1328
|
+
if (candidate.length !== hex || !/^[0-9a-fA-F]+$/.test(candidate)) {
|
|
1329
|
+
this.die(`invalid dataref: ${this.line}`);
|
|
1330
|
+
}
|
|
1331
|
+
id = candidate.toLowerCase();
|
|
1332
|
+
if (p[hex] !== " ") this.die(`missing space after tree-ish: ${this.line}`);
|
|
1333
|
+
rest = p.slice(hex + 1);
|
|
1334
|
+
}
|
|
1335
|
+
// dereference: commits to their trees, tags to what they tag
|
|
1336
|
+
for (let depth = 0; depth < 64; depth++) {
|
|
1337
|
+
const raw = await readObjectBytes(this.objects, id);
|
|
1338
|
+
if (!raw) this.die(`can't load object ${id}`);
|
|
1339
|
+
const t = (raw as { type: string }).type;
|
|
1340
|
+
if (t === "tree") break;
|
|
1341
|
+
const text = latin1((raw as { bytes: Uint8Array }).bytes);
|
|
1342
|
+
if (t === "commit") id = text.slice(5, text.indexOf("\n"));
|
|
1343
|
+
else if (t === "tag") id = text.slice(7, text.indexOf("\n"));
|
|
1344
|
+
else this.die(`not a tree-ish: ${this.line}`);
|
|
1345
|
+
}
|
|
1346
|
+
root = { mode: S_IFDIR, id };
|
|
1347
|
+
}
|
|
1348
|
+
const path = this.parsePathEol(rest, "path");
|
|
1349
|
+
const leaf = await this.treeGet(root, path, true);
|
|
1350
|
+
const quoted = quotePathBinary(path);
|
|
1351
|
+
if (!leaf?.mode) {
|
|
1352
|
+
await this.catBlobWrite(`missing ${quoted}\n`);
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
if (isDir(leaf.mode)) await this.storeTree(leaf);
|
|
1356
|
+
const type = leaf.mode === S_IFGITLINK ? "commit" : isDir(leaf.mode) ? "tree" : "blob";
|
|
1357
|
+
await this.catBlobWrite(
|
|
1358
|
+
`${leaf.mode.toString(8).padStart(6, "0")} ${type} ${leaf.id}\t${quoted}\n`,
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
private async parseAlias(): Promise<void> {
|
|
1363
|
+
await this.skipOptionalLf();
|
|
1364
|
+
await this.readNextCommand();
|
|
1365
|
+
await this.parseMark();
|
|
1366
|
+
const mark = this.nextMark;
|
|
1367
|
+
if (!mark) this.die(`expected 'mark' command, got ${this.line}`);
|
|
1368
|
+
if (!this.line.startsWith("to ")) this.die(`expected 'to' command, got ${this.line}`);
|
|
1369
|
+
const b: Branch = {
|
|
1370
|
+
name: "",
|
|
1371
|
+
oid: undefined,
|
|
1372
|
+
root: { mode: S_IFDIR, id: undefined },
|
|
1373
|
+
delete: false,
|
|
1374
|
+
};
|
|
1375
|
+
await this.parseObjectish(b, this.line.slice(3));
|
|
1376
|
+
if (b.oid) this.insertMark(mark, { id: b.oid, type: "commit" });
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// ---------------------------------------------------------------- ref updates
|
|
1380
|
+
|
|
1381
|
+
private async checkpoint(): Promise<void> {
|
|
1382
|
+
await this.dumpBranches();
|
|
1383
|
+
await this.dumpTags();
|
|
1384
|
+
await this.dumpMarks();
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
private async dumpBranches(): Promise<void> {
|
|
1388
|
+
for (const bucket of this.branchTable) {
|
|
1389
|
+
for (const b of bucket ?? []) if (await this.updateBranch(b)) this.failure = true;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
private refName(name: string): string {
|
|
1394
|
+
return decodeGitPath(latin1Bytes(name));
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
/** update_branch: true on a failure */
|
|
1398
|
+
private async updateBranch(b: Branch): Promise<boolean> {
|
|
1399
|
+
const name = this.refName(b.name);
|
|
1400
|
+
if (name.startsWith("refs/replace/") && name.slice(13) === b.oid) {
|
|
1401
|
+
await this.refsStore.delete(name).catch(() => false);
|
|
1402
|
+
return false;
|
|
1403
|
+
}
|
|
1404
|
+
if (b.oid === undefined) {
|
|
1405
|
+
if (b.delete) await this.refsStore.delete(name).catch(() => false);
|
|
1406
|
+
return false;
|
|
1407
|
+
}
|
|
1408
|
+
const old = (await this.refsStore.resolve(name).catch(() => undefined))?.objectId;
|
|
1409
|
+
if (!this.force && old !== undefined) {
|
|
1410
|
+
const oldCommit = await this.peelToCommit(old);
|
|
1411
|
+
const newCommit = await this.peelToCommit(b.oid);
|
|
1412
|
+
if (!oldCommit || !newCommit) {
|
|
1413
|
+
const branch = this.compatibility === "2.43" ? "Branch" : "branch";
|
|
1414
|
+
this.warn(`error: ${branch} ${b.name} is missing commits.`);
|
|
1415
|
+
return true;
|
|
1416
|
+
}
|
|
1417
|
+
if (!(await this.commits.isAncestor(oldCommit, newCommit))) {
|
|
1418
|
+
const not = this.compatibility === "2.43" ? "Not" : "not";
|
|
1419
|
+
this.warn(`warning: ${not} updating ${b.name} (new tip ${b.oid} does not contain ${old})`);
|
|
1420
|
+
return true;
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
// a ref transaction without REF_NO_DEREF: a symbolic ref (`commit HEAD`) moves its target
|
|
1424
|
+
await this.refsStore.set(await this.symrefTarget(name), b.oid, this.reflogLine("fast-import"));
|
|
1425
|
+
return false;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/** The ref a name ends at through symbolic refs (what a dereferencing update writes). */
|
|
1429
|
+
private async symrefTarget(name: string): Promise<string> {
|
|
1430
|
+
let current = name;
|
|
1431
|
+
for (let depth = 0; depth < 5; depth++) {
|
|
1432
|
+
const ref = await this.refsStore.get(current).catch(() => undefined);
|
|
1433
|
+
if (!ref || !isSymbolicRef(ref)) break;
|
|
1434
|
+
current = ref.target;
|
|
1435
|
+
}
|
|
1436
|
+
return current;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
private async dumpTags(): Promise<void> {
|
|
1440
|
+
for (const t of this.tags) {
|
|
1441
|
+
const name = await this.symrefTarget(`refs/tags/${this.refName(t.name)}`);
|
|
1442
|
+
await this.refsStore.set(name, t.id, this.reflogLine("fast-import"));
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
function isDir(mode: number): boolean {
|
|
1448
|
+
return (mode & S_IFMT) === S_IFDIR;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
function cloneNode(node: Node): Node {
|
|
1452
|
+
const copy: Node = { mode: node.mode, id: node.id };
|
|
1453
|
+
if (node.entries && node.id === undefined) {
|
|
1454
|
+
copy.entries = new Map([...node.entries].map(([k, v]) => [k, cloneNode(v)]));
|
|
1455
|
+
}
|
|
1456
|
+
return copy;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/** git 2.43's wording: most of fast-import's messages started with a capital letter. */
|
|
1460
|
+
function capitalized243(message: string): string {
|
|
1461
|
+
if (
|
|
1462
|
+
/^(mark :|feature '|option '|corrupt mark line|object not found|cannot read|stream ends early|unknown --date-format|EOF in)/.test(
|
|
1463
|
+
message,
|
|
1464
|
+
)
|
|
1465
|
+
) {
|
|
1466
|
+
return message;
|
|
1467
|
+
}
|
|
1468
|
+
return message.charAt(0).toUpperCase() + message.slice(1);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
/** A JavaScript string's UTF-8 bytes as a binary string. */
|
|
1472
|
+
function utf8Binary(text: string): string {
|
|
1473
|
+
return latin1(new TextEncoder().encode(text));
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
function compareBinary(a: string, b: string): number {
|
|
1477
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
function hexToBinary(hex: string): string {
|
|
1481
|
+
let out = "";
|
|
1482
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
1483
|
+
out += String.fromCharCode(Number.parseInt(hex.slice(i, i + 2), 16));
|
|
1484
|
+
}
|
|
1485
|
+
return out;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
function parseRawTree(bytes: Uint8Array, rawLength: number, into: Map<string, Node>): void {
|
|
1489
|
+
let at = 0;
|
|
1490
|
+
while (at < bytes.length) {
|
|
1491
|
+
const space = bytes.indexOf(32, at);
|
|
1492
|
+
const nul = bytes.indexOf(0, space);
|
|
1493
|
+
if (space < 0 || nul < 0) break;
|
|
1494
|
+
const mode = Number.parseInt(latin1(bytes.subarray(at, space)), 8);
|
|
1495
|
+
const name = latin1(bytes.subarray(space + 1, nul));
|
|
1496
|
+
let id = "";
|
|
1497
|
+
for (const b of bytes.subarray(nul + 1, nul + 1 + rawLength)) {
|
|
1498
|
+
id += b.toString(16).padStart(2, "0");
|
|
1499
|
+
}
|
|
1500
|
+
into.set(name, { mode: canonMode(mode), id });
|
|
1501
|
+
at = nul + 1 + rawLength;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
/** canon_mode */
|
|
1506
|
+
function canonMode(mode: number): number {
|
|
1507
|
+
if ((mode & S_IFMT) === S_IFREG) return S_IFREG | (mode & 0o111 ? 0o755 : 0o644);
|
|
1508
|
+
if ((mode & S_IFMT) === S_IFLNK) return S_IFLNK;
|
|
1509
|
+
if ((mode & S_IFMT) === S_IFDIR) return S_IFDIR;
|
|
1510
|
+
return S_IFGITLINK;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/** validate_raw_date */
|
|
1514
|
+
function validRawDate(text: string, strict: boolean): boolean {
|
|
1515
|
+
const m = /^[ \t\n\v\f\r]*[+-]?\d+ ([+-])(\d+)$/.exec(text);
|
|
1516
|
+
if (!m) return false;
|
|
1517
|
+
return !(strict && Number(m[2]) > 1400);
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
function parseDateFormat(format: string, die: (message: string) => never): FastImportDateFormat {
|
|
1521
|
+
if (format === "raw" || format === "raw-permissive" || format === "rfc2822" || format === "now") {
|
|
1522
|
+
return format;
|
|
1523
|
+
}
|
|
1524
|
+
return die(`unknown --date-format argument ${format}`);
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
/** quote_c_style of a binary-string path, quoted only when it must be. */
|
|
1528
|
+
function quotePathBinary(path: string): string {
|
|
1529
|
+
let needs = false;
|
|
1530
|
+
let body = "";
|
|
1531
|
+
for (let i = 0; i < path.length; i++) {
|
|
1532
|
+
const c = path.charCodeAt(i);
|
|
1533
|
+
const esc: Record<number, string> = {
|
|
1534
|
+
7: "a",
|
|
1535
|
+
8: "b",
|
|
1536
|
+
9: "t",
|
|
1537
|
+
10: "n",
|
|
1538
|
+
11: "v",
|
|
1539
|
+
12: "f",
|
|
1540
|
+
13: "r",
|
|
1541
|
+
34: '"',
|
|
1542
|
+
92: "\\",
|
|
1543
|
+
};
|
|
1544
|
+
if (esc[c] !== undefined) {
|
|
1545
|
+
needs = true;
|
|
1546
|
+
body += `\\${esc[c]}`;
|
|
1547
|
+
} else if (c < 0x20 || c >= 0x7f) {
|
|
1548
|
+
needs = true;
|
|
1549
|
+
body += `\\${(c >> 6) & 3}${(c >> 3) & 7}${c & 7}`;
|
|
1550
|
+
} else body += path[i];
|
|
1551
|
+
}
|
|
1552
|
+
return needs ? `"${body}"` : path;
|
|
1553
|
+
}
|