@statewalker/vcs-commands 0.9.0 → 0.11.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 +144 -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 +28 -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 +54 -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 +60 -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-ipc.d.ts +30 -0
- package/dist/commands/fsmonitor-ipc.d.ts.map +1 -0
- 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 +45 -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 +28 -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 +158 -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/reset-command.d.ts +19 -2
- package/dist/commands/reset-command.d.ts.map +1 -1
- 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 +5 -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 +27 -1
- 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 +30 -2
- 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 +16 -2
- 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 +22 -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 +27 -1
- package/dist/commands/submodule-update-command.d.ts.map +1 -1
- package/dist/commands/tag-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 +131 -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-bQQ9OmCh.js} +52514 -44630
- 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-BHT9bUS-.js} +184 -143
- package/dist/git-command.d.ts +66 -4
- 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-Cx2PlGV9.js +13544 -0
- package/dist/{remote-transport-CCmBadm-.js → remote-transport-BrQZfyHu.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-CNHQnU5Y.js} +13707 -10608
- package/dist/transport-command.d.ts +79 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +13 -13
- 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 +193 -22
- 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 +895 -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 +61 -22
- 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 +249 -9
- 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 +118 -1
- package/src/commands/diff-command.ts +592 -47
- 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 +267 -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-ipc.ts +121 -0
- package/src/commands/fsmonitor-refresh.ts +320 -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 +46 -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 +66 -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 +708 -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 +1066 -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/reset-command.ts +75 -3
- 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 +49 -5
- package/src/commands/revert-command.ts +21 -1
- package/src/commands/revision-range.ts +7 -2
- package/src/commands/revision-resolver.ts +97 -14
- 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 +176 -23
- package/src/commands/stash-apply-command.ts +3 -0
- package/src/commands/stash-export-command.ts +397 -0
- package/src/commands/status-command.ts +74 -8
- package/src/commands/stripspace-command.ts +118 -0
- package/src/commands/submodule-add-command.ts +40 -2
- package/src/commands/submodule-auth.ts +61 -6
- package/src/commands/submodule-commands.ts +12 -2
- package/src/commands/submodule-update-command.ts +47 -1
- package/src/commands/tag-command.ts +33 -11
- 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 +1148 -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 +177 -3
- 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,1066 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git repo info` and `git repo structure` (builtin/repo.c, git 2.52+).
|
|
3
|
+
*
|
|
4
|
+
* ```typescript
|
|
5
|
+
* const { stdout } = await git.repoInfo().addKeys("layout.bare", "object.format").callOutput();
|
|
6
|
+
* // "layout.bare=false\nobject.format=sha1\n"
|
|
7
|
+
* const table = await git.repoStructure().callOutput(); // the "Repository structure" table
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Both write stdout as git does and return git's exit status ({@link PlumbingCommand}). The
|
|
11
|
+
* keys of `repo info` depend on the git version ({@link RepoInfoCommand.setCompatibility}).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
decodeTreeBytes,
|
|
16
|
+
type FilesApi,
|
|
17
|
+
joinPath,
|
|
18
|
+
type ObjectId,
|
|
19
|
+
type ObjectTypeString,
|
|
20
|
+
type Pack,
|
|
21
|
+
packNameOf,
|
|
22
|
+
} from "@statewalker/vcs-core";
|
|
23
|
+
import { readRepositoryFormat, setupGitDirectory } from "@statewalker/vcs-store-files";
|
|
24
|
+
import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
|
|
25
|
+
import { normalizePath } from "@statewalker/vcs-utils/files";
|
|
26
|
+
import { type GitHostEnvironment, readIndexFileEntries } from "@statewalker/vcs-working-tree";
|
|
27
|
+
import { quotePath } from "../results/quote-path.js";
|
|
28
|
+
import { hookHostOf } from "./git-hooks.js";
|
|
29
|
+
import { hostEnvironmentOf } from "./git-ident.js";
|
|
30
|
+
import { PlumbingCommand, PlumbingError } from "./plumbing-command.js";
|
|
31
|
+
import { RevListCommand } from "./rev-list-command.js";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The `repo info` key sets: "2.54" (2.54 and 2.55: `layout.*`, `object.format`,
|
|
35
|
+
* `references.format`), "2.56" (2.56.x: also `path.commondir.*` and `path.gitdir.*`), "2.57"
|
|
36
|
+
* (git master after 2.56: `objects.storageFormat`, the other `path.*` keys, and
|
|
37
|
+
* `references.format` renamed `references.storageFormat`). `repo structure` is the same in all.
|
|
38
|
+
*/
|
|
39
|
+
export type RepoCompatibility = "2.54" | "2.56" | "2.57";
|
|
40
|
+
|
|
41
|
+
type OutputFormat = "table" | "lines" | "nul";
|
|
42
|
+
|
|
43
|
+
/** git's `parse_format_cb`: `nul`, `lines`, `table`, else `invalid format`. */
|
|
44
|
+
function parseFormat(format: string): OutputFormat {
|
|
45
|
+
if (format === "nul" || format === "lines" || format === "table") return format;
|
|
46
|
+
throw new PlumbingError(`fatal: invalid format '${format}'`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** path.c's relative_path (POSIX: `/` the only separator). */
|
|
50
|
+
export function gitRelativePath(input: string, prefix: string): string {
|
|
51
|
+
const inLen = input.length;
|
|
52
|
+
const prefixLen = prefix.length;
|
|
53
|
+
if (!inLen) return "./";
|
|
54
|
+
if (!prefixLen) return input;
|
|
55
|
+
if (input.startsWith("/") !== prefix.startsWith("/")) return input;
|
|
56
|
+
let i = 0;
|
|
57
|
+
let j = 0;
|
|
58
|
+
let inOff = 0;
|
|
59
|
+
let prefixOff = 0;
|
|
60
|
+
while (i < prefixLen && j < inLen && prefix[i] === input[j]) {
|
|
61
|
+
if (prefix[i] === "/") {
|
|
62
|
+
while (prefix[i] === "/") i++;
|
|
63
|
+
while (input[j] === "/") j++;
|
|
64
|
+
prefixOff = i;
|
|
65
|
+
inOff = j;
|
|
66
|
+
} else {
|
|
67
|
+
i++;
|
|
68
|
+
j++;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (i >= prefixLen && prefixOff < prefixLen) {
|
|
72
|
+
if (j >= inLen) inOff = inLen;
|
|
73
|
+
else if (input[j] === "/") {
|
|
74
|
+
while (input[j] === "/") j++;
|
|
75
|
+
inOff = j;
|
|
76
|
+
} else i = prefixOff;
|
|
77
|
+
} else if (j >= inLen && inOff < inLen) {
|
|
78
|
+
if (prefix[i] === "/") {
|
|
79
|
+
while (prefix[i] === "/") i++;
|
|
80
|
+
inOff = inLen;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const rest = input.slice(inOff);
|
|
84
|
+
if (i >= prefixLen) return rest.length ? rest : "./";
|
|
85
|
+
let out = "";
|
|
86
|
+
while (i < prefixLen) {
|
|
87
|
+
if (prefix[i] === "/") {
|
|
88
|
+
out += "../";
|
|
89
|
+
while (prefix[i] === "/") i++;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
i++;
|
|
93
|
+
}
|
|
94
|
+
if (prefix[prefixLen - 1] !== "/") out += "../";
|
|
95
|
+
return out + rest;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The repository as `repo info` reads it. */
|
|
99
|
+
interface RepoFacts {
|
|
100
|
+
bare: boolean;
|
|
101
|
+
shallow: boolean;
|
|
102
|
+
objectFormat: string;
|
|
103
|
+
refStorage: string;
|
|
104
|
+
/** host paths (realpath'ed where the host can), undefined where there is none */
|
|
105
|
+
gitDir?: string;
|
|
106
|
+
commonDir?: string;
|
|
107
|
+
index?: string;
|
|
108
|
+
workTree?: string;
|
|
109
|
+
superproject?: string;
|
|
110
|
+
/** git's current directory after its setup (host path), when the caller gave it */
|
|
111
|
+
setupDirectory?: string;
|
|
112
|
+
/** git's `repo->prefix`: the current directory below the worktree top, with a `/` */
|
|
113
|
+
prefix: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type InfoField = (facts: RepoFacts) => string;
|
|
117
|
+
|
|
118
|
+
const relativeTo = (facts: RepoFacts, path: string | undefined): string => {
|
|
119
|
+
if (path === undefined) return "";
|
|
120
|
+
// git runs from where its setup went: the worktree top (the git directory when a bare one
|
|
121
|
+
// is discovered), else where it started; the prefix is below it
|
|
122
|
+
const base = facts.setupDirectory ?? facts.workTree ?? facts.gitDir ?? "";
|
|
123
|
+
const cwd = facts.prefix ? `${base}/${facts.prefix}` : base;
|
|
124
|
+
return gitRelativePath(path, cwd);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const COMMON_FIELDS: [string, InfoField][] = [
|
|
128
|
+
["layout.bare", (f) => (f.bare ? "true" : "false")],
|
|
129
|
+
["layout.shallow", (f) => (f.shallow ? "true" : "false")],
|
|
130
|
+
["object.format", (f) => f.objectFormat],
|
|
131
|
+
];
|
|
132
|
+
const PATH_DIR_FIELDS: [string, InfoField][] = [
|
|
133
|
+
["path.commondir.absolute", (f) => f.commonDir ?? ""],
|
|
134
|
+
["path.commondir.relative", (f) => relativeTo(f, f.commonDir)],
|
|
135
|
+
["path.gitdir.absolute", (f) => f.gitDir ?? ""],
|
|
136
|
+
["path.gitdir.relative", (f) => relativeTo(f, f.gitDir)],
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
/** builtin/repo.c's `repo_info_field` table of a version, in its (sorted) order. */
|
|
140
|
+
function infoFields(compatibility: RepoCompatibility): [string, InfoField][] {
|
|
141
|
+
const refFormat: InfoField = (f) => f.refStorage;
|
|
142
|
+
if (compatibility === "2.54") return [...COMMON_FIELDS, ["references.format", refFormat]];
|
|
143
|
+
if (compatibility === "2.56")
|
|
144
|
+
return [...COMMON_FIELDS, ...PATH_DIR_FIELDS, ["references.format", refFormat]];
|
|
145
|
+
return [
|
|
146
|
+
...COMMON_FIELDS,
|
|
147
|
+
["objects.storageFormat", () => "files"],
|
|
148
|
+
...PATH_DIR_FIELDS,
|
|
149
|
+
["path.index.absolute", (f) => f.index ?? ""],
|
|
150
|
+
["path.index.relative", (f) => relativeTo(f, f.index)],
|
|
151
|
+
["path.prefix", (f) => f.prefix],
|
|
152
|
+
["path.superprojectworkingtree.absolute", (f) => f.superproject ?? ""],
|
|
153
|
+
["path.superprojectworkingtree.relative", (f) => relativeTo(f, f.superproject)],
|
|
154
|
+
["path.workingtree.absolute", (f) => f.workTree ?? ""],
|
|
155
|
+
["path.workingtree.relative", (f) => relativeTo(f, f.workTree)],
|
|
156
|
+
["references.storageFormat", refFormat],
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The host path of a FilesApi path (its root directory joined), undefined without one. */
|
|
161
|
+
function hostPathOf(files: FilesApi, path: string): string | undefined {
|
|
162
|
+
const root = (files as { rootDirectory?: string }).rootDirectory;
|
|
163
|
+
if (!root) return undefined;
|
|
164
|
+
const base = root.replace(/\/+$/, "");
|
|
165
|
+
const rest = path.replace(/^\/+|\/+$/g, "");
|
|
166
|
+
return rest ? `${base}/${rest}` : base || "/";
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* `git repo info [--format=(lines|nul) | -z] [--all | <key>...]` and `git repo info --keys`.
|
|
171
|
+
*
|
|
172
|
+
* Paths are host paths: the FilesApi's root directory joined with its paths, resolved through
|
|
173
|
+
* the host's `realPath`; without a root directory the path keys are empty. The git directory
|
|
174
|
+
* and worktree are the working copy's: open it where git's setup puts them
|
|
175
|
+
* (`openRepositoryFromEnvironment` for `$GIT_DIR`/`$GIT_WORK_TREE`) and pass its `prefix` to
|
|
176
|
+
* {@link setCurrentDirectory}, and the setup's current directory (`setup.cwd`, as a host path)
|
|
177
|
+
* to {@link setSetupDirectory}; `$GIT_COMMON_DIR` and `$GIT_INDEX_FILE` are read from the host
|
|
178
|
+
* environment. Relative keys are relative to the setup directory plus the prefix, and a relative
|
|
179
|
+
* `$GIT_INDEX_FILE` is read in the setup directory (the worktree top, else where git started:
|
|
180
|
+
* outside the worktree, or with a bare `$GIT_DIR`). Without a setup directory git is taken to
|
|
181
|
+
* have gone to the worktree top (the git directory when bare), and a relative index is the
|
|
182
|
+
* file the working copy's staging opened.
|
|
183
|
+
* `path.superprojectworkingtree.*` is submodule.c's `get_superproject_working_tree`: the
|
|
184
|
+
* repository of the worktree's parent directory (reached through `hostFilesOf`, else the
|
|
185
|
+
* FilesApi) must hold a gitlink at the worktree's path in its index.
|
|
186
|
+
*/
|
|
187
|
+
export class RepoInfoCommand extends PlumbingCommand {
|
|
188
|
+
private format = "lines";
|
|
189
|
+
private all = false;
|
|
190
|
+
private showKeys = false;
|
|
191
|
+
private keys: string[] = [];
|
|
192
|
+
private compatibility: RepoCompatibility = "2.57";
|
|
193
|
+
private currentDirectory = "";
|
|
194
|
+
private setupDirectory: string | undefined;
|
|
195
|
+
|
|
196
|
+
/** `--format=<format>` (`lines`, `nul`; `table` is refused when printing values) */
|
|
197
|
+
setFormat(format: string): this {
|
|
198
|
+
this.checkCallable();
|
|
199
|
+
// git dies as it parses the option: a later valid one does not save it
|
|
200
|
+
this.format = this.format.startsWith("!") ? this.format : format;
|
|
201
|
+
if (!["nul", "lines", "table"].includes(format)) this.format = `!${format}`;
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** `-z`: `--format=nul` */
|
|
206
|
+
setNul(): this {
|
|
207
|
+
return this.setFormat("nul");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** `--all`: every key */
|
|
211
|
+
setAll(all: boolean): this {
|
|
212
|
+
this.checkCallable();
|
|
213
|
+
this.all = all;
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** `--keys`: the key names instead of values */
|
|
218
|
+
setShowKeys(keys: boolean): this {
|
|
219
|
+
this.checkCallable();
|
|
220
|
+
this.showKeys = keys;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** The keys asked for, in order (repeats allowed). */
|
|
225
|
+
addKeys(...keys: string[]): this {
|
|
226
|
+
this.checkCallable();
|
|
227
|
+
this.keys.push(...keys);
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The git version whose keys are known (default 2.57: git master). */
|
|
232
|
+
setCompatibility(compatibility: RepoCompatibility): this {
|
|
233
|
+
this.checkCallable();
|
|
234
|
+
this.compatibility = compatibility;
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The directory git runs from, below the worktree top (`path.prefix`, relative paths). */
|
|
239
|
+
setCurrentDirectory(path: string): this {
|
|
240
|
+
this.checkCallable();
|
|
241
|
+
this.currentDirectory = path.replace(/^\/+|\/+$/g, "");
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* The directory git's setup went to, as a host path (`setupGitDirectory`'s `cwd` joined to
|
|
247
|
+
* the FilesApi's root): the worktree top when git started inside it, else where it started.
|
|
248
|
+
*/
|
|
249
|
+
setSetupDirectory(hostPath: string | undefined): this {
|
|
250
|
+
this.checkCallable();
|
|
251
|
+
this.setupDirectory = hostPath === undefined ? undefined : hostPath.replace(/(.)\/+$/, "$1");
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
protected async run(): Promise<number> {
|
|
256
|
+
const format = parseFormat(this.format.replace(/^!/, ""));
|
|
257
|
+
const fields = infoFields(this.compatibility);
|
|
258
|
+
const keysAsked = this.keys.length > 0;
|
|
259
|
+
if (this.showKeys && (this.all || keysAsked))
|
|
260
|
+
throw new PlumbingError("fatal: --keys cannot be used with a <key> or --all");
|
|
261
|
+
if (this.showKeys) {
|
|
262
|
+
if (format === "table")
|
|
263
|
+
throw new PlumbingError(
|
|
264
|
+
"fatal: --keys can only be used with --format=lines or --format=nul",
|
|
265
|
+
);
|
|
266
|
+
const sep = format === "nul" ? "\0" : "\n";
|
|
267
|
+
await this.write(fields.map(([key]) => `${key}${sep}`).join(""));
|
|
268
|
+
return 0;
|
|
269
|
+
}
|
|
270
|
+
if (format === "table") throw new PlumbingError("fatal: unsupported output format");
|
|
271
|
+
if (this.all && keysAsked)
|
|
272
|
+
throw new PlumbingError("fatal: --all and <key> cannot be used together");
|
|
273
|
+
const facts = await this.facts();
|
|
274
|
+
const table = new Map(fields);
|
|
275
|
+
const print = async (key: string, value: string) => {
|
|
276
|
+
if (format === "lines") await this.write(`${key}=${quotePath(value)}\n`);
|
|
277
|
+
else await this.write(`${key}\n${value}\0`);
|
|
278
|
+
};
|
|
279
|
+
if (this.all) {
|
|
280
|
+
for (const [key, field] of fields) await print(key, field(facts));
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
let status = 0;
|
|
284
|
+
for (const key of this.keys) {
|
|
285
|
+
const field = table.get(key);
|
|
286
|
+
if (!field) {
|
|
287
|
+
this.warn(`error: key '${key}' not found`);
|
|
288
|
+
status = 255;
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
await print(key, field(facts));
|
|
292
|
+
}
|
|
293
|
+
return status;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private async facts(): Promise<RepoFacts> {
|
|
297
|
+
const history = this.workingCopy.history;
|
|
298
|
+
const layout = await hookHostOf(this.workingCopy).layout();
|
|
299
|
+
const environment = hostEnvironmentOf(this.workingCopy);
|
|
300
|
+
const real = async (path: string | undefined) =>
|
|
301
|
+
path === undefined
|
|
302
|
+
? undefined
|
|
303
|
+
: ((await environment?.realPath?.(path).catch(() => undefined)) ?? path);
|
|
304
|
+
const shallow = (await history.refs.getShallow?.()) ?? [];
|
|
305
|
+
const format = layout
|
|
306
|
+
? await readRepositoryFormat(layout.files, layout.gitDir).catch(() => undefined)
|
|
307
|
+
: undefined;
|
|
308
|
+
const refStorage = format?.refStorage ?? "files";
|
|
309
|
+
const facts: RepoFacts = {
|
|
310
|
+
bare: layout?.bare ?? false,
|
|
311
|
+
shallow: shallow.length > 0,
|
|
312
|
+
objectFormat: this.objectFormat.name,
|
|
313
|
+
refStorage,
|
|
314
|
+
prefix: this.currentDirectory ? `${this.currentDirectory}/` : "",
|
|
315
|
+
setupDirectory: await real(this.setupDirectory),
|
|
316
|
+
};
|
|
317
|
+
if (!layout) return facts;
|
|
318
|
+
const files = layout.files;
|
|
319
|
+
// a gitfile's target (a submodule, a linked worktree) may lie outside the FilesApi
|
|
320
|
+
facts.gitDir = await real(
|
|
321
|
+
layout.gitDirEnv?.startsWith("/") ? layout.gitDirEnv : hostPathOf(files, layout.gitDir),
|
|
322
|
+
);
|
|
323
|
+
// repo_get_common_dir: $GIT_COMMON_DIR, else the git directory's `commondir` file
|
|
324
|
+
// (a linked worktree's), else the git directory itself
|
|
325
|
+
const commondirFile = facts.gitDir
|
|
326
|
+
? await environment?.readFile(`${facts.gitDir}/commondir`).catch(() => undefined)
|
|
327
|
+
: undefined;
|
|
328
|
+
const named = commondirFile ? new TextDecoder().decode(commondirFile).trim() : undefined;
|
|
329
|
+
facts.commonDir = environment?.commonDir
|
|
330
|
+
? await real(environment.commonDir)
|
|
331
|
+
: named
|
|
332
|
+
? await real(named.startsWith("/") ? named : `${facts.gitDir}/${named}`)
|
|
333
|
+
: facts.gitDir;
|
|
334
|
+
// repo_get_index_file: `$GIT_INDEX_FILE` (an absolute one as given; a relative one is the
|
|
335
|
+
// file in the directory git's setup went to: the worktree top, else where it started; the
|
|
336
|
+
// file the working copy opened when the caller did not say), else `<git dir>/index`
|
|
337
|
+
const indexFile = environment?.indexFile;
|
|
338
|
+
const location =
|
|
339
|
+
indexFile && !indexFile.startsWith("/") && facts.setupDirectory === undefined
|
|
340
|
+
? this.indexLocation()
|
|
341
|
+
: undefined;
|
|
342
|
+
facts.index =
|
|
343
|
+
indexFile === undefined
|
|
344
|
+
? facts.gitDir
|
|
345
|
+
? `${facts.gitDir}/index`
|
|
346
|
+
: undefined
|
|
347
|
+
: indexFile.startsWith("/")
|
|
348
|
+
? indexFile
|
|
349
|
+
: facts.setupDirectory !== undefined
|
|
350
|
+
? `${facts.setupDirectory.replace(/\/$/, "")}/${indexFile}`
|
|
351
|
+
: await real(
|
|
352
|
+
location
|
|
353
|
+
? hostPathOf(location.files, location.path)
|
|
354
|
+
: `${hostPathOf(files, layout.bare ? layout.gitDir : layout.top) ?? ""}/${indexFile}`,
|
|
355
|
+
);
|
|
356
|
+
if (!layout.bare) {
|
|
357
|
+
facts.workTree = await real(hostPathOf(files, layout.top));
|
|
358
|
+
facts.superproject = await this.superprojectOf(files, layout.top, facts.workTree);
|
|
359
|
+
}
|
|
360
|
+
return facts;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** The index file of the working copy's staging; undefined without one (bare, memory). */
|
|
364
|
+
private indexLocation(): { files: FilesApi; path: string } | undefined {
|
|
365
|
+
try {
|
|
366
|
+
return this.resolveStaging().indexLocation?.();
|
|
367
|
+
} catch {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* submodule.c's `get_superproject_working_tree`: the repository found from the directory
|
|
374
|
+
* above the worktree (discovered as git's child `git -C <parent> ls-files` discovers it,
|
|
375
|
+
* the repository variables cleared) must hold a gitlink at the worktree's path in its
|
|
376
|
+
* index; the superproject is the worktree less that path. Whatever the submodule's git
|
|
377
|
+
* directory is (embedded `.git`, `.git/modules/<name>`, a linked worktree's modules).
|
|
378
|
+
*/
|
|
379
|
+
private async superprojectOf(
|
|
380
|
+
files: FilesApi,
|
|
381
|
+
top: string,
|
|
382
|
+
workTree: string | undefined,
|
|
383
|
+
): Promise<string | undefined> {
|
|
384
|
+
if (!workTree) return undefined;
|
|
385
|
+
const environment = hostEnvironmentOf(this.workingCopy);
|
|
386
|
+
const real = async (path: string) =>
|
|
387
|
+
(await environment?.realPath?.(path).catch(() => undefined)) ?? path;
|
|
388
|
+
const oneUp = await real(parentHostPath(workTree));
|
|
389
|
+
const subpath = gitRelativePath(workTree, oneUp).replace(/\/$/, "");
|
|
390
|
+
if (!subpath || subpath === "./" || subpath.startsWith("../")) return undefined;
|
|
391
|
+
// the parent directory through the host, else inside the repository's own storage
|
|
392
|
+
const host = await environment?.hostFilesOf?.(oneUp).catch(() => undefined);
|
|
393
|
+
const parent = host
|
|
394
|
+
? { files: host.files, cwd: host.path }
|
|
395
|
+
: top
|
|
396
|
+
? { files, cwd: normalizePath(top.slice(0, Math.max(0, top.lastIndexOf("/")))) }
|
|
397
|
+
: undefined;
|
|
398
|
+
if (!parent) return undefined;
|
|
399
|
+
// prepare_submodule_repo_env: none of the repository variables reach the child
|
|
400
|
+
const {
|
|
401
|
+
gitDir: _gitDir,
|
|
402
|
+
workTree: _workTree,
|
|
403
|
+
commonDir: _commonDir,
|
|
404
|
+
indexFile: _indexFile,
|
|
405
|
+
objectDirectory: _objectDirectory,
|
|
406
|
+
implicitWorkTree: _implicitWorkTree,
|
|
407
|
+
...childEnvironment
|
|
408
|
+
} = environment ?? ({} as GitHostEnvironment);
|
|
409
|
+
let setup: Awaited<ReturnType<typeof setupGitDirectory>>;
|
|
410
|
+
try {
|
|
411
|
+
setup = await setupGitDirectory({
|
|
412
|
+
files: parent.files,
|
|
413
|
+
cwd: parent.cwd,
|
|
414
|
+
...(environment ? { environment: childEnvironment as GitHostEnvironment } : {}),
|
|
415
|
+
});
|
|
416
|
+
} catch {
|
|
417
|
+
return undefined; // not a git repository (ls-files' exit 128)
|
|
418
|
+
}
|
|
419
|
+
if (setup.workTree === undefined) return undefined; // ls-files needs a worktree
|
|
420
|
+
const format = await readRepositoryFormat(parent.files, setup.commonDir).catch(() => undefined);
|
|
421
|
+
const index = await readIndexFileEntries(parent.files, setup.indexFile, {
|
|
422
|
+
gitDir: setup.gitDir,
|
|
423
|
+
...(format ? { objectFormat: format.objectFormat } : {}),
|
|
424
|
+
}).catch(() => undefined);
|
|
425
|
+
if (!index) return undefined;
|
|
426
|
+
// `ls-files --stage --full-name -- <subpath>`: the first entry at or below the path
|
|
427
|
+
const fullName = `${setup.prefix ?? ""}${subpath}`;
|
|
428
|
+
const first = index.entries.find(
|
|
429
|
+
(e) => e.path === fullName || e.path.startsWith(`${fullName}/`),
|
|
430
|
+
);
|
|
431
|
+
if (!first || first.mode !== S_IFGITLINK) return undefined;
|
|
432
|
+
if (!workTree.endsWith(`/${fullName}`)) return undefined; // git's BUG()
|
|
433
|
+
const superTop = workTree.slice(0, workTree.length - fullName.length - 1) || "/";
|
|
434
|
+
return real(superTop);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const S_IFGITLINK = 0o160000;
|
|
439
|
+
|
|
440
|
+
/** The host directory holding `path` (`/a/b` → `/a`). */
|
|
441
|
+
function parentHostPath(path: string): string {
|
|
442
|
+
const trimmed = path.replace(/\/+$/, "");
|
|
443
|
+
const at = trimmed.lastIndexOf("/");
|
|
444
|
+
return at <= 0 ? "/" : trimmed.slice(0, at);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/** Counts and sizes `repo structure` prints of each object type. */
|
|
448
|
+
interface ObjectValues {
|
|
449
|
+
commits: number;
|
|
450
|
+
trees: number;
|
|
451
|
+
blobs: number;
|
|
452
|
+
tags: number;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
interface Largest {
|
|
456
|
+
id: ObjectId | undefined;
|
|
457
|
+
value: number;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** What `git repo structure` counted. */
|
|
461
|
+
export interface RepoStructure {
|
|
462
|
+
references: { branches: number; tags: number; remotes: number; others: number };
|
|
463
|
+
counts: ObjectValues;
|
|
464
|
+
inflatedSizes: ObjectValues;
|
|
465
|
+
diskSizes: ObjectValues;
|
|
466
|
+
largest: {
|
|
467
|
+
commitSize: Largest;
|
|
468
|
+
treeSize: Largest;
|
|
469
|
+
blobSize: Largest;
|
|
470
|
+
tagSize: Largest;
|
|
471
|
+
parentCount: Largest;
|
|
472
|
+
treeEntries: Largest;
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const emptyValues = (): ObjectValues => ({ commits: 0, trees: 0, blobs: 0, tags: 0 });
|
|
477
|
+
const total = (v: ObjectValues) => v.commits + v.trees + v.blobs + v.tags;
|
|
478
|
+
|
|
479
|
+
/** strbuf.c's humanise_count. */
|
|
480
|
+
export function humaniseCount(count: number): { value: string; unit?: string } {
|
|
481
|
+
const frac = (x: number, d: number) => String(Math.floor(x / d) % 100).padStart(2, "0");
|
|
482
|
+
if (count >= 1e9) {
|
|
483
|
+
const x = count + 5000000;
|
|
484
|
+
return { value: `${Math.floor(x / 1e9)}.${frac(x % 1e9, 1e7)}`, unit: "G" };
|
|
485
|
+
}
|
|
486
|
+
if (count >= 1e6) {
|
|
487
|
+
const x = count + 5000;
|
|
488
|
+
return { value: `${Math.floor(x / 1e6)}.${frac(x % 1e6, 1e4)}`, unit: "M" };
|
|
489
|
+
}
|
|
490
|
+
if (count >= 1000) {
|
|
491
|
+
const x = count + 5;
|
|
492
|
+
return { value: `${Math.floor(x / 1000)}.${frac(x % 1000, 10)}`, unit: "k" };
|
|
493
|
+
}
|
|
494
|
+
return { value: String(count) };
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** strbuf.c's humanise_bytes with HUMANISE_COMPACT. */
|
|
498
|
+
export function humaniseBytesCompact(bytes: number): { value: string; unit: string } {
|
|
499
|
+
const pad = (n: number) => String(n).padStart(2, "0");
|
|
500
|
+
if (bytes > 2 ** 30) {
|
|
501
|
+
const low = bytes % 2 ** 30;
|
|
502
|
+
return {
|
|
503
|
+
value: `${Math.floor(bytes / 2 ** 30)}.${pad(Math.floor(low / 10737419) >>> 0)}`,
|
|
504
|
+
unit: "GiB",
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
if (bytes > 2 ** 20) {
|
|
508
|
+
const x = (bytes + 5243) >>> 0;
|
|
509
|
+
return {
|
|
510
|
+
value: `${x >>> 20}.${pad(Math.floor(((x & 0xfffff) * 100) / 2 ** 20))}`,
|
|
511
|
+
unit: "MiB",
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
if (bytes > 2 ** 10) {
|
|
515
|
+
const x = (bytes + 5) >>> 0;
|
|
516
|
+
return { value: `${x >>> 10}.${pad(Math.floor(((x & 0x3ff) * 100) / 1024))}`, unit: "KiB" };
|
|
517
|
+
}
|
|
518
|
+
return { value: String(bytes), unit: "B" };
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** git's utf8_strwidth for the table's (ASCII) cells. */
|
|
522
|
+
const width = (text: string) => text.length;
|
|
523
|
+
|
|
524
|
+
/** path-walk.c's compare_by_type: tags first, then blobs, then trees; else by path. */
|
|
525
|
+
const TYPE_RANK: Record<string, number> = { tag: 0, blob: 1, tree: 2, commit: 3 };
|
|
526
|
+
|
|
527
|
+
/** A binary heap ordered by `compare` (git's prio_queue without ties). */
|
|
528
|
+
class Heap<T> {
|
|
529
|
+
private items: T[] = [];
|
|
530
|
+
constructor(private readonly compare: (a: T, b: T) => number) {}
|
|
531
|
+
get size(): number {
|
|
532
|
+
return this.items.length;
|
|
533
|
+
}
|
|
534
|
+
push(item: T): void {
|
|
535
|
+
const a = this.items;
|
|
536
|
+
a.push(item);
|
|
537
|
+
let i = a.length - 1;
|
|
538
|
+
while (i > 0) {
|
|
539
|
+
const p = (i - 1) >> 1;
|
|
540
|
+
if (this.compare(a[p] as T, a[i] as T) <= 0) break;
|
|
541
|
+
[a[p], a[i]] = [a[i] as T, a[p] as T];
|
|
542
|
+
i = p;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
pop(): T | undefined {
|
|
546
|
+
const a = this.items;
|
|
547
|
+
if (a.length === 0) return undefined;
|
|
548
|
+
const top = a[0];
|
|
549
|
+
const last = a.pop() as T;
|
|
550
|
+
if (a.length > 0) {
|
|
551
|
+
a[0] = last;
|
|
552
|
+
let i = 0;
|
|
553
|
+
for (;;) {
|
|
554
|
+
const l = 2 * i + 1;
|
|
555
|
+
const r = l + 1;
|
|
556
|
+
let m = i;
|
|
557
|
+
if (l < a.length && this.compare(a[l] as T, a[m] as T) < 0) m = l;
|
|
558
|
+
if (r < a.length && this.compare(a[r] as T, a[m] as T) < 0) m = r;
|
|
559
|
+
if (m === i) break;
|
|
560
|
+
[a[m], a[i]] = [a[i] as T, a[m] as T];
|
|
561
|
+
i = m;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return top;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/** Reads an object whole: its type and bytes, undefined when missing. */
|
|
569
|
+
async function readWhole(
|
|
570
|
+
objects: {
|
|
571
|
+
get(
|
|
572
|
+
id: ObjectId,
|
|
573
|
+
): Promise<{ type: ObjectTypeString; content: AsyncIterable<Uint8Array> } | undefined>;
|
|
574
|
+
},
|
|
575
|
+
id: ObjectId,
|
|
576
|
+
): Promise<{ type: ObjectTypeString; bytes: Uint8Array } | undefined> {
|
|
577
|
+
let object: Awaited<ReturnType<typeof objects.get>>;
|
|
578
|
+
try {
|
|
579
|
+
object = await objects.get(id);
|
|
580
|
+
} catch {
|
|
581
|
+
return undefined;
|
|
582
|
+
}
|
|
583
|
+
if (!object) return undefined;
|
|
584
|
+
const chunks: Uint8Array[] = [];
|
|
585
|
+
let length = 0;
|
|
586
|
+
for await (const c of object.content) {
|
|
587
|
+
chunks.push(c);
|
|
588
|
+
length += c.length;
|
|
589
|
+
}
|
|
590
|
+
if (chunks.length === 1) return { type: object.type, bytes: chunks[0] as Uint8Array };
|
|
591
|
+
const bytes = new Uint8Array(length);
|
|
592
|
+
let at = 0;
|
|
593
|
+
for (const c of chunks) {
|
|
594
|
+
bytes.set(c, at);
|
|
595
|
+
at += c.length;
|
|
596
|
+
}
|
|
597
|
+
return { type: object.type, bytes };
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/** The pack-relevant part of a `PackFile`. */
|
|
601
|
+
interface OffsetPack extends Pack {
|
|
602
|
+
indexOf?(id: ObjectId): number;
|
|
603
|
+
offsetAt?(i: number): number;
|
|
604
|
+
packOrder?(): Uint32Array;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* `git repo structure [--format=(table|lines|nul) | -z] [--[no-]progress]`: the references
|
|
609
|
+
* by kind and the objects reachable from them (path-walk.c's walk over every ref, as git
|
|
610
|
+
* walks it, so ties of the largest objects go to the object git meets first), with their
|
|
611
|
+
* inflated and on-disk sizes (a packed object's entry, a loose object's file; an object only
|
|
612
|
+
* an alternate holds counts 0 bytes on disk).
|
|
613
|
+
*/
|
|
614
|
+
export class RepoStructureCommand extends PlumbingCommand {
|
|
615
|
+
private format = "table";
|
|
616
|
+
private showProgress = false;
|
|
617
|
+
private counted?: RepoStructure;
|
|
618
|
+
|
|
619
|
+
/** `--format=<format>` (`table`, `lines`, `nul`) */
|
|
620
|
+
setFormat(format: string): this {
|
|
621
|
+
this.checkCallable();
|
|
622
|
+
// git dies as it parses the option: a later valid one does not save it
|
|
623
|
+
this.format = this.format.startsWith("!") ? this.format : format;
|
|
624
|
+
if (!["nul", "lines", "table"].includes(format)) this.format = `!${format}`;
|
|
625
|
+
return this;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/** `-z`: `--format=nul` */
|
|
629
|
+
setNul(): this {
|
|
630
|
+
return this.setFormat("nul");
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** `--progress`: the final progress lines on stderr (git's default: on a terminal only) */
|
|
634
|
+
setShowProgress(progress: boolean): this {
|
|
635
|
+
this.checkCallable();
|
|
636
|
+
this.showProgress = progress;
|
|
637
|
+
return this;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** What the last run counted. */
|
|
641
|
+
getStructure(): RepoStructure | undefined {
|
|
642
|
+
return this.counted;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
protected async run(): Promise<number> {
|
|
646
|
+
const format = parseFormat(this.format.replace(/^!/, ""));
|
|
647
|
+
const s: RepoStructure = {
|
|
648
|
+
references: { branches: 0, tags: 0, remotes: 0, others: 0 },
|
|
649
|
+
counts: emptyValues(),
|
|
650
|
+
inflatedSizes: emptyValues(),
|
|
651
|
+
diskSizes: emptyValues(),
|
|
652
|
+
largest: {
|
|
653
|
+
commitSize: { id: undefined, value: 0 },
|
|
654
|
+
treeSize: { id: undefined, value: 0 },
|
|
655
|
+
blobSize: { id: undefined, value: 0 },
|
|
656
|
+
tagSize: { id: undefined, value: 0 },
|
|
657
|
+
parentCount: { id: undefined, value: 0 },
|
|
658
|
+
treeEntries: { id: undefined, value: 0 },
|
|
659
|
+
},
|
|
660
|
+
};
|
|
661
|
+
const pending = await this.countReferences(s);
|
|
662
|
+
if (this.showProgress) {
|
|
663
|
+
const r = s.references;
|
|
664
|
+
this.warn(`Counting references: ${r.branches + r.tags + r.remotes + r.others}, done.`);
|
|
665
|
+
}
|
|
666
|
+
await this.countObjects(s, pending);
|
|
667
|
+
if (this.showProgress) this.warn(`Counting objects: ${total(s.counts)}, done.`);
|
|
668
|
+
this.counted = s;
|
|
669
|
+
if (format === "table") await this.write(this.table(s));
|
|
670
|
+
else if (format === "lines") await this.write(this.keyValues(s, "=", "\n"));
|
|
671
|
+
else await this.write(this.keyValues(s, "\n", "\0"));
|
|
672
|
+
return 0;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/** count_references: every ref under refs/ (symbolic ones resolved), in name order. */
|
|
676
|
+
private async countReferences(s: RepoStructure): Promise<ObjectId[]> {
|
|
677
|
+
const refs = this.workingCopy.history.refs;
|
|
678
|
+
const names: string[] = [];
|
|
679
|
+
for await (const ref of refs.list("refs/")) names.push(ref.name);
|
|
680
|
+
names.sort(compareGitPaths);
|
|
681
|
+
const pending: ObjectId[] = [];
|
|
682
|
+
for (const name of names) {
|
|
683
|
+
const resolved = await refs.resolve(name).catch(() => undefined);
|
|
684
|
+
const id = resolved?.objectId;
|
|
685
|
+
if (!id) continue;
|
|
686
|
+
if (name.startsWith("refs/heads/")) s.references.branches++;
|
|
687
|
+
else if (name.startsWith("refs/remotes/")) s.references.remotes++;
|
|
688
|
+
else if (name.startsWith("refs/tags/")) s.references.tags++;
|
|
689
|
+
else s.references.others++;
|
|
690
|
+
pending.push(id);
|
|
691
|
+
}
|
|
692
|
+
return pending;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/** structure_count_objects: path-walk.c's walk_objects_by_path from the refs. */
|
|
696
|
+
private async countObjects(s: RepoStructure, pending: ObjectId[]): Promise<void> {
|
|
697
|
+
const history = this.workingCopy.history;
|
|
698
|
+
const objects = history.objects;
|
|
699
|
+
if (!objects) throw new PlumbingError("fatal: repo structure needs an object store");
|
|
700
|
+
const types = new Map<ObjectId, ObjectTypeString>();
|
|
701
|
+
const typeOf = async (id: ObjectId): Promise<ObjectTypeString | undefined> => {
|
|
702
|
+
let t = types.get(id);
|
|
703
|
+
if (t) return t;
|
|
704
|
+
try {
|
|
705
|
+
t = (await objects.header?.(id))?.type ?? (await objects.get(id))?.type;
|
|
706
|
+
} catch {
|
|
707
|
+
t = undefined;
|
|
708
|
+
}
|
|
709
|
+
if (t) types.set(id, t);
|
|
710
|
+
return t;
|
|
711
|
+
};
|
|
712
|
+
const seen = new Set<ObjectId>();
|
|
713
|
+
const lists = new Map<string, { type: ObjectTypeString; ids: ObjectId[] }>();
|
|
714
|
+
const pushed = new Set<string>();
|
|
715
|
+
const heap = new Heap<string>((a, b) => {
|
|
716
|
+
const la = lists.get(a);
|
|
717
|
+
const lb = lists.get(b);
|
|
718
|
+
if (!la || !lb || la.type === lb.type) return compareGitPaths(a, b);
|
|
719
|
+
return (TYPE_RANK[la.type] ?? 9) - (TYPE_RANK[lb.type] ?? 9);
|
|
720
|
+
});
|
|
721
|
+
const push = (path: string) => {
|
|
722
|
+
if (pushed.has(path)) return;
|
|
723
|
+
pushed.add(path);
|
|
724
|
+
heap.push(path);
|
|
725
|
+
};
|
|
726
|
+
const addToList = (path: string, type: ObjectTypeString, id: ObjectId) => {
|
|
727
|
+
let list = lists.get(path);
|
|
728
|
+
if (!list) {
|
|
729
|
+
list = { type, ids: [] };
|
|
730
|
+
lists.set(path, list);
|
|
731
|
+
}
|
|
732
|
+
list.ids.push(id);
|
|
733
|
+
};
|
|
734
|
+
lists.set("", { type: "tree", ids: [] });
|
|
735
|
+
push("");
|
|
736
|
+
|
|
737
|
+
// setup_pending_objects (after prepare_revision_walk): tags, tagged trees and blobs
|
|
738
|
+
const starts: ObjectId[] = [];
|
|
739
|
+
const tags: ObjectId[] = [];
|
|
740
|
+
const taggedTrees: ObjectId[] = [];
|
|
741
|
+
const taggedBlobs: ObjectId[] = [];
|
|
742
|
+
for (const tip of pending) {
|
|
743
|
+
let id: ObjectId | undefined = tip;
|
|
744
|
+
let type = await typeOf(id);
|
|
745
|
+
let stopped = false;
|
|
746
|
+
while (type === "tag" && id) {
|
|
747
|
+
if (seen.has(id)) {
|
|
748
|
+
stopped = true;
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
seen.add(id);
|
|
752
|
+
tags.push(id);
|
|
753
|
+
const tag = await readWhole(objects, id);
|
|
754
|
+
id = tag
|
|
755
|
+
? /^object ([0-9a-f]+)/.exec(new TextDecoder().decode(tag.bytes.subarray(0, 200)))?.[1]
|
|
756
|
+
: undefined;
|
|
757
|
+
type = id ? await typeOf(id) : undefined;
|
|
758
|
+
}
|
|
759
|
+
if (stopped || !id || !type) continue;
|
|
760
|
+
if (type === "commit") {
|
|
761
|
+
starts.push(id);
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
if (seen.has(id)) continue;
|
|
765
|
+
seen.add(id);
|
|
766
|
+
if (type === "tree") taggedTrees.push(id);
|
|
767
|
+
else if (type === "blob") taggedBlobs.push(id);
|
|
768
|
+
}
|
|
769
|
+
for (const [path, type, ids] of [
|
|
770
|
+
["/tagged-blobs", "blob", taggedBlobs],
|
|
771
|
+
["/tagged-trees", "tree", taggedTrees],
|
|
772
|
+
["/tags", "tag", tags],
|
|
773
|
+
] as const) {
|
|
774
|
+
if (ids.length === 0) continue;
|
|
775
|
+
lists.set(path, { type, ids: [...ids] });
|
|
776
|
+
push(path);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// the commit walk: commits in walk order, each new root tree
|
|
780
|
+
const commits: ObjectId[] = [];
|
|
781
|
+
const roots = lists.get("") as { ids: ObjectId[] };
|
|
782
|
+
if (starts.length > 0) {
|
|
783
|
+
const walk = new RevListCommand(this.workingCopy);
|
|
784
|
+
for (const id of starts) walk.addRevision(id);
|
|
785
|
+
for await (const c of await walk.call()) {
|
|
786
|
+
commits.push(c.id);
|
|
787
|
+
if (seen.has(c.tree)) continue;
|
|
788
|
+
seen.add(c.tree);
|
|
789
|
+
roots.ids.push(c.tree);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
const disk = await this.diskSizer();
|
|
794
|
+
const check = (largest: Largest, id: ObjectId, value: number) => {
|
|
795
|
+
if (value > largest.value || largest.id === undefined) {
|
|
796
|
+
largest.id = id;
|
|
797
|
+
largest.value = value;
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
const idLength = this.objectFormat.rawLength;
|
|
801
|
+
const count = async (type: ObjectTypeString, ids: ObjectId[]) => {
|
|
802
|
+
for (const id of ids) {
|
|
803
|
+
if (type === "blob") {
|
|
804
|
+
let size: number | undefined;
|
|
805
|
+
try {
|
|
806
|
+
size = (await objects.header?.(id))?.size;
|
|
807
|
+
if (size === undefined) size = (await readWhole(objects, id))?.bytes.length;
|
|
808
|
+
} catch {
|
|
809
|
+
size = undefined;
|
|
810
|
+
}
|
|
811
|
+
if (size === undefined) continue;
|
|
812
|
+
s.counts.blobs++;
|
|
813
|
+
s.inflatedSizes.blobs += size;
|
|
814
|
+
s.diskSizes.blobs += await disk(id);
|
|
815
|
+
check(s.largest.blobSize, id, size);
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
const object = await readWhole(objects, id);
|
|
819
|
+
if (!object) continue;
|
|
820
|
+
const size = object.bytes.length;
|
|
821
|
+
if (type === "tag") {
|
|
822
|
+
s.counts.tags++;
|
|
823
|
+
s.inflatedSizes.tags += size;
|
|
824
|
+
s.diskSizes.tags += await disk(id);
|
|
825
|
+
check(s.largest.tagSize, id, size);
|
|
826
|
+
} else if (type === "commit") {
|
|
827
|
+
s.counts.commits++;
|
|
828
|
+
s.inflatedSizes.commits += size;
|
|
829
|
+
s.diskSizes.commits += await disk(id);
|
|
830
|
+
check(s.largest.commitSize, id, size);
|
|
831
|
+
check(s.largest.parentCount, id, parentCount(object.bytes));
|
|
832
|
+
} else if (type === "tree") {
|
|
833
|
+
s.counts.trees++;
|
|
834
|
+
s.inflatedSizes.trees += size;
|
|
835
|
+
s.diskSizes.trees += await disk(id);
|
|
836
|
+
check(s.largest.treeSize, id, size);
|
|
837
|
+
check(
|
|
838
|
+
s.largest.treeEntries,
|
|
839
|
+
id,
|
|
840
|
+
decodeTreeBytes(object.bytes, { idLength, checkNames: false }).length,
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
if (commits.length > 0) await count("commit", commits);
|
|
846
|
+
|
|
847
|
+
for (let path = heap.pop(); path !== undefined; path = heap.pop()) {
|
|
848
|
+
const list = lists.get(path);
|
|
849
|
+
pushed.delete(path);
|
|
850
|
+
if (!list || list.ids.length === 0) continue;
|
|
851
|
+
await count(list.type, list.ids);
|
|
852
|
+
if (list.type === "tree") {
|
|
853
|
+
const base = path === "/tagged-trees" ? "" : path;
|
|
854
|
+
for (const treeId of list.ids) {
|
|
855
|
+
const tree = await readWhole(objects, treeId);
|
|
856
|
+
if (!tree) {
|
|
857
|
+
this.warn(`error: bad tree object ${treeId}`);
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
for (const entry of decodeTreeBytes(tree.bytes, { idLength, checkNames: false })) {
|
|
861
|
+
if (entry.mode === 0o160000) continue;
|
|
862
|
+
const isTree = (entry.mode & 0o170000) === 0o040000;
|
|
863
|
+
const child = `${base}${entry.name}${isTree ? "/" : ""}`;
|
|
864
|
+
if (seen.has(entry.id)) continue;
|
|
865
|
+
seen.add(entry.id);
|
|
866
|
+
addToList(child, isTree ? "tree" : "blob", entry.id);
|
|
867
|
+
push(child);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
lists.delete(path);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* The bytes an object takes on disk, as odb_read_object_info_extended's `disk_sizep`: its
|
|
877
|
+
* pack entry (to the next entry by offset, or the trailer), else its loose file.
|
|
878
|
+
*/
|
|
879
|
+
private async diskSizer(): Promise<(id: ObjectId) => Promise<number>> {
|
|
880
|
+
const objectsFile = await this.hooks.commonGitFile("objects");
|
|
881
|
+
const packSet = this.workingCopy.history.packs;
|
|
882
|
+
const packs = ((await packSet?.packs().catch(() => [])) ?? []) as OffsetPack[];
|
|
883
|
+
const hashLength = this.objectFormat.rawLength;
|
|
884
|
+
const sorted = new Map<OffsetPack, Float64Array>();
|
|
885
|
+
const packSizes = new Map<OffsetPack, number>();
|
|
886
|
+
const offsetsOf = (pack: OffsetPack): Float64Array => {
|
|
887
|
+
let offsets = sorted.get(pack);
|
|
888
|
+
if (!offsets) {
|
|
889
|
+
offsets = new Float64Array(pack.count);
|
|
890
|
+
for (let i = 0; i < pack.count; i++) offsets[i] = pack.offsetAt?.(i) ?? 0;
|
|
891
|
+
offsets.sort();
|
|
892
|
+
sorted.set(pack, offsets);
|
|
893
|
+
}
|
|
894
|
+
return offsets;
|
|
895
|
+
};
|
|
896
|
+
const packSizeOf = async (pack: OffsetPack): Promise<number> => {
|
|
897
|
+
let size = packSizes.get(pack);
|
|
898
|
+
if (size === undefined) {
|
|
899
|
+
size = 0;
|
|
900
|
+
if (objectsFile) {
|
|
901
|
+
const path = joinPath(objectsFile.path, "pack", `${packNameOf(pack)}.pack`);
|
|
902
|
+
size = (await objectsFile.files.stats(path))?.size ?? 0;
|
|
903
|
+
}
|
|
904
|
+
packSizes.set(pack, size);
|
|
905
|
+
}
|
|
906
|
+
return size;
|
|
907
|
+
};
|
|
908
|
+
return async (id) => {
|
|
909
|
+
for (const pack of packs) {
|
|
910
|
+
if (!pack.has(id) || !pack.indexOf || !pack.offsetAt) continue;
|
|
911
|
+
const index = pack.indexOf(id);
|
|
912
|
+
if (index < 0) continue;
|
|
913
|
+
const offset = pack.offsetAt(index);
|
|
914
|
+
const offsets = offsetsOf(pack);
|
|
915
|
+
let lo = 0;
|
|
916
|
+
let hi = offsets.length;
|
|
917
|
+
while (lo < hi) {
|
|
918
|
+
const mid = (lo + hi) >> 1;
|
|
919
|
+
if ((offsets[mid] as number) <= offset) lo = mid + 1;
|
|
920
|
+
else hi = mid;
|
|
921
|
+
}
|
|
922
|
+
const next =
|
|
923
|
+
lo < offsets.length ? (offsets[lo] as number) : (await packSizeOf(pack)) - hashLength;
|
|
924
|
+
return next - offset;
|
|
925
|
+
}
|
|
926
|
+
if (!objectsFile) return 0;
|
|
927
|
+
const path = joinPath(objectsFile.path, id.slice(0, 2), id.slice(2));
|
|
928
|
+
return (await objectsFile.files.stats(path).catch(() => undefined))?.size ?? 0;
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/** stats_table_setup_structure + stats_table_print_structure. */
|
|
933
|
+
private table(s: RepoStructure): string {
|
|
934
|
+
type Entry = { value: string; unit?: string; index?: number };
|
|
935
|
+
const rows: { name: string; entry?: Entry }[] = [];
|
|
936
|
+
const annotations: string[] = [];
|
|
937
|
+
let nameWidth = 0;
|
|
938
|
+
let valueWidth = 0;
|
|
939
|
+
let unitWidth = 0;
|
|
940
|
+
const add = (name: string, entry?: Entry, id?: ObjectId) => {
|
|
941
|
+
rows.push({ name, entry });
|
|
942
|
+
nameWidth = Math.max(nameWidth, width(name));
|
|
943
|
+
if (!entry) return;
|
|
944
|
+
if (id) {
|
|
945
|
+
entry.index = annotations.length + 1;
|
|
946
|
+
annotations.push(`[${entry.index}] ${id}`);
|
|
947
|
+
}
|
|
948
|
+
valueWidth = Math.max(valueWidth, width(entry.value));
|
|
949
|
+
if (entry.unit) unitWidth = Math.max(unitWidth, width(entry.unit));
|
|
950
|
+
};
|
|
951
|
+
const countRow = (name: string, n: number, id?: ObjectId) => add(name, humaniseCount(n), id);
|
|
952
|
+
const sizeRow = (name: string, n: number, id?: ObjectId) =>
|
|
953
|
+
add(name, humaniseBytesCompact(n), id);
|
|
954
|
+
const r = s.references;
|
|
955
|
+
add("* References");
|
|
956
|
+
countRow(" * Count", r.branches + r.tags + r.remotes + r.others);
|
|
957
|
+
countRow(" * Branches", r.branches);
|
|
958
|
+
countRow(" * Tags", r.tags);
|
|
959
|
+
countRow(" * Remotes", r.remotes);
|
|
960
|
+
countRow(" * Others", r.others);
|
|
961
|
+
const byType = (values: ObjectValues, row: (name: string, n: number) => void) => {
|
|
962
|
+
row(" * Commits", values.commits);
|
|
963
|
+
row(" * Trees", values.trees);
|
|
964
|
+
row(" * Blobs", values.blobs);
|
|
965
|
+
row(" * Tags", values.tags);
|
|
966
|
+
};
|
|
967
|
+
add("");
|
|
968
|
+
add("* Reachable objects");
|
|
969
|
+
countRow(" * Count", total(s.counts));
|
|
970
|
+
byType(s.counts, countRow);
|
|
971
|
+
sizeRow(" * Inflated size", total(s.inflatedSizes));
|
|
972
|
+
byType(s.inflatedSizes, sizeRow);
|
|
973
|
+
sizeRow(" * Disk size", total(s.diskSizes));
|
|
974
|
+
byType(s.diskSizes, sizeRow);
|
|
975
|
+
const l = s.largest;
|
|
976
|
+
add("");
|
|
977
|
+
add("* Largest objects");
|
|
978
|
+
add(" * Commits");
|
|
979
|
+
sizeRow(" * Maximum size", l.commitSize.value, l.commitSize.id);
|
|
980
|
+
countRow(" * Maximum parents", l.parentCount.value, l.parentCount.id);
|
|
981
|
+
add(" * Trees");
|
|
982
|
+
sizeRow(" * Maximum size", l.treeSize.value, l.treeSize.id);
|
|
983
|
+
countRow(" * Maximum entries", l.treeEntries.value, l.treeEntries.id);
|
|
984
|
+
add(" * Blobs");
|
|
985
|
+
sizeRow(" * Maximum size", l.blobSize.value, l.blobSize.id);
|
|
986
|
+
add(" * Tags");
|
|
987
|
+
sizeRow(" * Maximum size", l.tagSize.value, l.tagSize.id);
|
|
988
|
+
|
|
989
|
+
const nameTitle = "Repository structure";
|
|
990
|
+
const valueTitle = "Value";
|
|
991
|
+
nameWidth = Math.max(nameWidth, width(nameTitle));
|
|
992
|
+
if (width(valueTitle) > valueWidth + unitWidth + 1) valueWidth = width(valueTitle) - unitWidth;
|
|
993
|
+
const INDEX_WIDTH = 4;
|
|
994
|
+
const left = (text: string, w: number) => text.padEnd(w);
|
|
995
|
+
const right = (text: string, w: number) => text.padStart(w);
|
|
996
|
+
const valueCol = valueWidth + unitWidth + 1;
|
|
997
|
+
let out = `| ${left(nameTitle, nameWidth + INDEX_WIDTH)} | ${left(valueTitle, valueCol)} |\n`;
|
|
998
|
+
out += `| ${"-".repeat(nameWidth + INDEX_WIDTH)} | ${"-".repeat(valueCol)} |\n`;
|
|
999
|
+
for (const { name, entry } of rows) {
|
|
1000
|
+
out += `| ${left(name, nameWidth)}`;
|
|
1001
|
+
out += entry?.index !== undefined ? ` [${entry.index}]` : " ".repeat(INDEX_WIDTH);
|
|
1002
|
+
out += ` | ${right(entry?.value ?? "", valueWidth)} ${left(entry?.unit ?? "", unitWidth)} |\n`;
|
|
1003
|
+
}
|
|
1004
|
+
if (annotations.length > 0) out += `\n${annotations.map((a) => `${a}\n`).join("")}`;
|
|
1005
|
+
return out;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/** structure_keyvalue_print. */
|
|
1009
|
+
private keyValues(s: RepoStructure, keyDelim: string, valueDelim: string): string {
|
|
1010
|
+
const nullId = this.objectFormat.nullId;
|
|
1011
|
+
let out = "";
|
|
1012
|
+
const kv = (key: string, value: number) => {
|
|
1013
|
+
out += `${key}${keyDelim}${value}${valueDelim}`;
|
|
1014
|
+
};
|
|
1015
|
+
const data = (key: string, largest: Largest) => {
|
|
1016
|
+
kv(key, largest.value);
|
|
1017
|
+
out += `${key}_oid${keyDelim}${largest.id ?? nullId}${valueDelim}`;
|
|
1018
|
+
};
|
|
1019
|
+
const r = s.references;
|
|
1020
|
+
kv("references.branches.count", r.branches);
|
|
1021
|
+
kv("references.tags.count", r.tags);
|
|
1022
|
+
kv("references.remotes.count", r.remotes);
|
|
1023
|
+
kv("references.others.count", r.others);
|
|
1024
|
+
for (const [suffix, values] of [
|
|
1025
|
+
["count", s.counts],
|
|
1026
|
+
["inflated_size", s.inflatedSizes],
|
|
1027
|
+
["disk_size", s.diskSizes],
|
|
1028
|
+
] as const) {
|
|
1029
|
+
kv(`objects.commits.${suffix}`, values.commits);
|
|
1030
|
+
kv(`objects.trees.${suffix}`, values.trees);
|
|
1031
|
+
kv(`objects.blobs.${suffix}`, values.blobs);
|
|
1032
|
+
kv(`objects.tags.${suffix}`, values.tags);
|
|
1033
|
+
}
|
|
1034
|
+
const l = s.largest;
|
|
1035
|
+
data("objects.commits.max_size", l.commitSize);
|
|
1036
|
+
data("objects.trees.max_size", l.treeSize);
|
|
1037
|
+
data("objects.blobs.max_size", l.blobSize);
|
|
1038
|
+
data("objects.tags.max_size", l.tagSize);
|
|
1039
|
+
data("objects.commits.max_parents", l.parentCount);
|
|
1040
|
+
data("objects.trees.max_entries", l.treeEntries);
|
|
1041
|
+
return out;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/** The `parent` lines of a commit's header. */
|
|
1046
|
+
function parentCount(bytes: Uint8Array): number {
|
|
1047
|
+
const end = bytes.indexOf(0x0a, 0);
|
|
1048
|
+
let n = 0;
|
|
1049
|
+
let at = end + 1;
|
|
1050
|
+
while (at > 0 && at < bytes.length) {
|
|
1051
|
+
const next = bytes.indexOf(0x0a, at);
|
|
1052
|
+
if (next === at) break;
|
|
1053
|
+
// "parent "
|
|
1054
|
+
if (
|
|
1055
|
+
bytes[at] === 0x70 &&
|
|
1056
|
+
bytes[at + 1] === 0x61 &&
|
|
1057
|
+
bytes[at + 2] === 0x72 &&
|
|
1058
|
+
bytes[at + 6] === 0x20
|
|
1059
|
+
)
|
|
1060
|
+
n++;
|
|
1061
|
+
else if (n > 0) break;
|
|
1062
|
+
if (next < 0) break;
|
|
1063
|
+
at = next + 1;
|
|
1064
|
+
}
|
|
1065
|
+
return n;
|
|
1066
|
+
}
|