@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,925 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's rerere (rerere.c): conflicts recorded in `rr-cache/<conflict id>/` (`preimage`,
|
|
3
|
+
* `postimage`, `thisimage`, a variant's `preimage.<n>`...) and the paths waiting for their
|
|
4
|
+
* resolution in `MERGE_RR` (`<id>[.<variant>]\t<path>\0`, sorted by path), in git's format
|
|
5
|
+
* byte for byte, so native git replays what ours recorded and the reverse.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // after a merge left conflicts in the index and the worktree (what `suggest_conflicts` runs)
|
|
10
|
+
* const { messages } = await runRerere(rerereHostOf(workingCopy, staging, worktree, blobs, format));
|
|
11
|
+
* // ["Recorded preimage for 'f'"], or ["Resolved 'f' using previous resolution."]
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* The conflict id is the hash (the repository's) of each conflict hunk's two sides, the
|
|
15
|
+
* smaller first, each followed by a NUL (`handle_path`); the preimage is the conflicted file
|
|
16
|
+
* with every hunk normalised (`<<<<<<<`, the sides in that order, no common ancestor's part).
|
|
17
|
+
* A recorded resolution is replayed as a three-way merge (`ll_merge`, Myers) of the preimage,
|
|
18
|
+
* the file now and the postimage.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { Blobs, ObjectId } from "@statewalker/vcs-core";
|
|
22
|
+
import type { ObjectFormat } from "@statewalker/vcs-utils";
|
|
23
|
+
import { decodeGitPath, encodeGitPath, parseGitBool } from "@statewalker/vcs-utils/encoding";
|
|
24
|
+
import type { FilesApi } from "@statewalker/vcs-utils/files";
|
|
25
|
+
import { joinPath } from "@statewalker/vcs-utils/files";
|
|
26
|
+
import type { Staging, WorkingCopy, Worktree } from "@statewalker/vcs-working-tree";
|
|
27
|
+
|
|
28
|
+
import { conflictMarkerSizeOf } from "../results/diff-check.js";
|
|
29
|
+
import { worktreeModeTrust } from "./core-config.js";
|
|
30
|
+
import { commonGitFileOf } from "./git-hooks.js";
|
|
31
|
+
import { IndexAdder } from "./index-adder.js";
|
|
32
|
+
import { configValue, conflictStyleOf } from "./merge-config.js";
|
|
33
|
+
import { lowLevelMerge, ortConfigOptions } from "./merge-drivers.js";
|
|
34
|
+
import type { MergeAttributes } from "./ort-merge.js";
|
|
35
|
+
import { worktreePathRules } from "./worktree-path-rules.js";
|
|
36
|
+
|
|
37
|
+
const RR_HAS_POSTIMAGE = 1;
|
|
38
|
+
const RR_HAS_PREIMAGE = 2;
|
|
39
|
+
const BOTH = RR_HAS_POSTIMAGE | RR_HAS_PREIMAGE;
|
|
40
|
+
|
|
41
|
+
/** What rerere works on: the working copy's config and state, its index, worktree and blobs. */
|
|
42
|
+
export interface RerereHost {
|
|
43
|
+
workingCopy: WorkingCopy;
|
|
44
|
+
staging: Staging;
|
|
45
|
+
worktree: Worktree;
|
|
46
|
+
blobs: Blobs;
|
|
47
|
+
objectFormat: ObjectFormat;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** What a rerere run printed on stderr, line by line. */
|
|
51
|
+
export interface RerereOutcome {
|
|
52
|
+
messages: string[];
|
|
53
|
+
/** Whether rerere is enabled (`rerere.enabled`, or unset and `rr-cache/` there) */
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `git rerere` died: its stderr lines (the last `fatal:`), exit status 128. */
|
|
58
|
+
export class RerereError extends Error {
|
|
59
|
+
readonly exitCode = 128;
|
|
60
|
+
constructor(readonly lines: string[]) {
|
|
61
|
+
super(lines.join("\n"));
|
|
62
|
+
this.name = "RerereError";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A conflict's directory (`rerere_dir`): the status bits of each variant. */
|
|
67
|
+
interface RerereDir {
|
|
68
|
+
hex: string;
|
|
69
|
+
status: number[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A conflict id and the variant a path uses (`rerere_id`; -1: not known yet). */
|
|
73
|
+
interface RerereId {
|
|
74
|
+
dir: RerereDir;
|
|
75
|
+
variant: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A sorted string list of paths (git's `string_list`, strcmp order) to their ids. */
|
|
79
|
+
type MergeRr = Map<string, RerereId | null>;
|
|
80
|
+
|
|
81
|
+
const enc = (s: string) => encodeGitPath(s);
|
|
82
|
+
|
|
83
|
+
/** strcmp over git's bytes. */
|
|
84
|
+
function compareBytes(a: Uint8Array, b: Uint8Array): number {
|
|
85
|
+
const n = Math.min(a.length, b.length);
|
|
86
|
+
for (let i = 0; i < n; i++) if (a[i] !== b[i]) return (a[i] as number) - (b[i] as number);
|
|
87
|
+
return a.length - b.length;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const comparePaths = (a: string, b: string) => compareBytes(enc(a), enc(b));
|
|
91
|
+
|
|
92
|
+
function sortedPaths(rr: MergeRr): string[] {
|
|
93
|
+
return [...rr.keys()].sort(comparePaths);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function concat(chunks: Uint8Array[]): Uint8Array {
|
|
97
|
+
let size = 0;
|
|
98
|
+
for (const c of chunks) size += c.length;
|
|
99
|
+
const out = new Uint8Array(size);
|
|
100
|
+
let at = 0;
|
|
101
|
+
for (const c of chunks) {
|
|
102
|
+
out.set(c, at);
|
|
103
|
+
at += c.length;
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const isDigit = (c: number | undefined) => c !== undefined && c >= 0x30 && c <= 0x39;
|
|
109
|
+
|
|
110
|
+
/** git's sane ctype isspace: `\t`, `\n`, `\r` and the space. */
|
|
111
|
+
const isSpace = (c: number | undefined) => c === 0x20 || c === 0x09 || c === 0x0a || c === 0x0d;
|
|
112
|
+
|
|
113
|
+
/** `is_cmarker`: `size` times `ch`, then (for `<` and `>`) a space, else any space. */
|
|
114
|
+
function isMarker(line: Uint8Array, ch: number, size: number): boolean {
|
|
115
|
+
for (let i = 0; i < size; i++) if (line[i] !== ch) return false;
|
|
116
|
+
const next = line[size];
|
|
117
|
+
if ((ch === 0x3c || ch === 0x3e) && next !== 0x20) return false;
|
|
118
|
+
return isSpace(next);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The lines of `bytes`, each with its LF (the last one without, when the file lacks it). */
|
|
122
|
+
class LineReader {
|
|
123
|
+
private at = 0;
|
|
124
|
+
constructor(private readonly bytes: Uint8Array) {}
|
|
125
|
+
next(): Uint8Array | undefined {
|
|
126
|
+
if (this.at >= this.bytes.length) return undefined;
|
|
127
|
+
const nl = this.bytes.indexOf(0x0a, this.at);
|
|
128
|
+
const end = nl < 0 ? this.bytes.length : nl + 1;
|
|
129
|
+
const line = this.bytes.subarray(this.at, end);
|
|
130
|
+
this.at = end;
|
|
131
|
+
return line;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** A hash being built from hunk sides (`ctx`). */
|
|
136
|
+
interface HunkHasher {
|
|
137
|
+
update(data: Uint8Array): unknown;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const NUL = new Uint8Array([0]);
|
|
141
|
+
|
|
142
|
+
function markerLine(ch: number, size: number): Uint8Array {
|
|
143
|
+
const out = new Uint8Array(size + 1).fill(ch);
|
|
144
|
+
out[size] = 0x0a;
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** `handle_conflict`: one hunk (after its `<` line), normalised into `out`. */
|
|
149
|
+
function handleConflict(
|
|
150
|
+
io: LineReader,
|
|
151
|
+
out: Uint8Array[],
|
|
152
|
+
size: number,
|
|
153
|
+
hasher: HunkHasher | undefined,
|
|
154
|
+
): number {
|
|
155
|
+
const SIDE_1 = 0;
|
|
156
|
+
const SIDE_2 = 1;
|
|
157
|
+
const ORIGINAL = 2;
|
|
158
|
+
let hunk = SIDE_1;
|
|
159
|
+
let one: Uint8Array[] = [];
|
|
160
|
+
let two: Uint8Array[] = [];
|
|
161
|
+
let status = -1;
|
|
162
|
+
for (let line = io.next(); line; line = io.next()) {
|
|
163
|
+
if (isMarker(line, 0x3c, size)) {
|
|
164
|
+
const nested: Uint8Array[] = [];
|
|
165
|
+
if (handleConflict(io, nested, size, undefined) < 0) break;
|
|
166
|
+
if (hunk === SIDE_1) one.push(...nested);
|
|
167
|
+
else two.push(...nested);
|
|
168
|
+
} else if (isMarker(line, 0x7c, size)) {
|
|
169
|
+
if (hunk !== SIDE_1) break;
|
|
170
|
+
hunk = ORIGINAL;
|
|
171
|
+
} else if (isMarker(line, 0x3d, size)) {
|
|
172
|
+
if (hunk !== SIDE_1 && hunk !== ORIGINAL) break;
|
|
173
|
+
hunk = SIDE_2;
|
|
174
|
+
} else if (isMarker(line, 0x3e, size)) {
|
|
175
|
+
if (hunk !== SIDE_2) break;
|
|
176
|
+
let a = concat(one);
|
|
177
|
+
let b = concat(two);
|
|
178
|
+
if (compareBytes(a, b) > 0) [a, b] = [b, a];
|
|
179
|
+
[one, two] = [[a], [b]];
|
|
180
|
+
status = 1;
|
|
181
|
+
out.push(markerLine(0x3c, size), a, markerLine(0x3d, size), b, markerLine(0x3e, size));
|
|
182
|
+
if (hasher) {
|
|
183
|
+
hasher.update(a);
|
|
184
|
+
hasher.update(NUL);
|
|
185
|
+
hasher.update(b);
|
|
186
|
+
hasher.update(NUL);
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
} else if (hunk === SIDE_1) one.push(line);
|
|
190
|
+
else if (hunk === SIDE_2) two.push(line);
|
|
191
|
+
// the common ancestor's lines are dropped
|
|
192
|
+
}
|
|
193
|
+
return status;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** What {@link normalizeConflicts} found. */
|
|
197
|
+
export interface NormalizedConflicts {
|
|
198
|
+
/** `handle_path`'s result: 1 when the last hunk parsed, 0 without any, -1 on a bad one */
|
|
199
|
+
status: number;
|
|
200
|
+
/** The conflict id (hex), when asked for */
|
|
201
|
+
id?: string;
|
|
202
|
+
/** The file with its hunks normalised, as far as it was parsed */
|
|
203
|
+
output: Uint8Array;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* git's `handle_path` over a file's bytes: the hunks normalised, their sides hashed into the
|
|
208
|
+
* conflict id.
|
|
209
|
+
*/
|
|
210
|
+
export function normalizeConflicts(
|
|
211
|
+
content: Uint8Array,
|
|
212
|
+
markerSize: number,
|
|
213
|
+
format?: ObjectFormat,
|
|
214
|
+
): NormalizedConflicts {
|
|
215
|
+
const io = new LineReader(content);
|
|
216
|
+
const hasher = format?.createHasher();
|
|
217
|
+
const out: Uint8Array[] = [];
|
|
218
|
+
let status = 0;
|
|
219
|
+
for (let line = io.next(); line; line = io.next()) {
|
|
220
|
+
if (isMarker(line, 0x3c, markerSize)) {
|
|
221
|
+
const hunk: Uint8Array[] = [];
|
|
222
|
+
status = handleConflict(io, hunk, markerSize, hasher);
|
|
223
|
+
if (status < 0) break;
|
|
224
|
+
out.push(...hunk);
|
|
225
|
+
} else out.push(line);
|
|
226
|
+
}
|
|
227
|
+
const result: NormalizedConflicts = { status, output: concat(out) };
|
|
228
|
+
if (hasher) {
|
|
229
|
+
result.id = Array.from(hasher.digest(), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The files of `rr-cache/` and the stderr lines a run collects. */
|
|
235
|
+
class RerereRun {
|
|
236
|
+
readonly messages: string[] = [];
|
|
237
|
+
private readonly dirs = new Map<string, RerereDir>();
|
|
238
|
+
readonly attributes: Partial<ReturnType<typeof ortConfigOptions>>;
|
|
239
|
+
|
|
240
|
+
constructor(
|
|
241
|
+
readonly host: RerereHost,
|
|
242
|
+
readonly files: FilesApi,
|
|
243
|
+
/** `rr-cache` as the FilesApi names it */
|
|
244
|
+
readonly cache: string,
|
|
245
|
+
) {
|
|
246
|
+
this.attributes = ortConfigOptions(host.workingCopy, host.worktree, {
|
|
247
|
+
indexAttributes: true,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
error(message: string): void {
|
|
252
|
+
this.messages.push(`error: ${message}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
path(id: RerereId, file?: string): string {
|
|
256
|
+
const dir = joinPath(this.cache, id.dir.hex);
|
|
257
|
+
if (file === undefined) return dir;
|
|
258
|
+
return joinPath(dir, id.variant <= 0 ? file : `${file}.${id.variant}`);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async attributesOf(path: string): Promise<MergeAttributes> {
|
|
262
|
+
return (await this.attributes.attributes?.(path)) ?? {};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async markerSize(path: string): Promise<number> {
|
|
266
|
+
const value = (await this.attributesOf(path)).conflictMarkerSize;
|
|
267
|
+
return conflictMarkerSizeOf(typeof value === "string" ? value : undefined);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** `find_rerere_dir`: the conflict's directory, its variants scanned once. */
|
|
271
|
+
async dir(hex: string): Promise<RerereDir> {
|
|
272
|
+
let dir = this.dirs.get(hex);
|
|
273
|
+
if (dir) return dir;
|
|
274
|
+
dir = { hex, status: [] };
|
|
275
|
+
this.dirs.set(hex, dir);
|
|
276
|
+
const path = joinPath(this.cache, hex);
|
|
277
|
+
if ((await this.files.stats(path))?.kind === "directory") {
|
|
278
|
+
for await (const entry of this.files.list(path)) {
|
|
279
|
+
const post = variantOf(entry.name, "postimage");
|
|
280
|
+
if (post !== undefined) {
|
|
281
|
+
fit(dir, post);
|
|
282
|
+
dir.status[post] = (dir.status[post] ?? 0) | RR_HAS_POSTIMAGE;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const pre = variantOf(entry.name, "preimage");
|
|
286
|
+
if (pre !== undefined) {
|
|
287
|
+
fit(dir, pre);
|
|
288
|
+
dir.status[pre] = (dir.status[pre] ?? 0) | RR_HAS_PREIMAGE;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return dir;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async newId(hex: string): Promise<RerereId> {
|
|
296
|
+
return { dir: await this.dir(hex), variant: -1 };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async readFile(path: string): Promise<Uint8Array | undefined> {
|
|
300
|
+
if ((await this.files.stats(path))?.kind !== "file") return undefined;
|
|
301
|
+
const chunks: Uint8Array[] = [];
|
|
302
|
+
for await (const chunk of this.files.read(path)) chunks.push(chunk);
|
|
303
|
+
return concat(chunks);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async writeFile(path: string, content: Uint8Array): Promise<void> {
|
|
307
|
+
await this.files.write(path, [content]);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async unlink(path: string): Promise<boolean> {
|
|
311
|
+
if ((await this.files.stats(path))?.kind !== "file") return false;
|
|
312
|
+
return this.files.remove(path);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async mkdir(path: string): Promise<void> {
|
|
316
|
+
if ((await this.files.stats(path))?.kind !== "directory") await this.files.mkdir(path);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** git's `rmdir`: only an empty directory goes. */
|
|
320
|
+
async rmdir(path: string): Promise<void> {
|
|
321
|
+
if ((await this.files.stats(path))?.kind !== "directory") return;
|
|
322
|
+
for await (const _ of this.files.list(path)) return;
|
|
323
|
+
await this.files.remove(path);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** The worktree file as `fopen` reads it, or the error line git prints. */
|
|
327
|
+
async readWorktree(path: string): Promise<Uint8Array | undefined> {
|
|
328
|
+
const entry = await this.host.worktree.getEntry(path).catch(() => undefined);
|
|
329
|
+
if (!entry) {
|
|
330
|
+
this.error(`could not open '${path}': No such file or directory`);
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
if (entry.isDirectory) {
|
|
334
|
+
this.error(`could not open '${path}': Is a directory`);
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
const chunks: Uint8Array[] = [];
|
|
338
|
+
for await (const chunk of this.host.worktree.readContent(path)) chunks.push(chunk);
|
|
339
|
+
return concat(chunks);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* `handle_file`: the worktree file's conflicts (1, 0 without any, -1 on an error); with
|
|
344
|
+
* `output`, its normalised form written there.
|
|
345
|
+
*/
|
|
346
|
+
async handleFile(
|
|
347
|
+
path: string,
|
|
348
|
+
wantId: boolean,
|
|
349
|
+
output?: string,
|
|
350
|
+
): Promise<{ status: number; id?: string }> {
|
|
351
|
+
const content = await this.readWorktree(path);
|
|
352
|
+
if (!content) return { status: -1 };
|
|
353
|
+
return this.handleBytes(path, content, wantId, output);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async handleBytes(
|
|
357
|
+
path: string,
|
|
358
|
+
content: Uint8Array,
|
|
359
|
+
wantId: boolean,
|
|
360
|
+
output?: string,
|
|
361
|
+
): Promise<{ status: number; id?: string }> {
|
|
362
|
+
const parsed = normalizeConflicts(
|
|
363
|
+
content,
|
|
364
|
+
await this.markerSize(path),
|
|
365
|
+
wantId ? this.host.objectFormat : undefined,
|
|
366
|
+
);
|
|
367
|
+
if (parsed.status < 0) {
|
|
368
|
+
// the output written so far is unlinked again
|
|
369
|
+
if (output) await this.unlink(output);
|
|
370
|
+
this.error(`could not parse conflict hunks in '${path}'`);
|
|
371
|
+
return { status: -1 };
|
|
372
|
+
}
|
|
373
|
+
if (output) await this.writeFile(output, parsed.output);
|
|
374
|
+
return { status: parsed.status, ...(parsed.id ? { id: parsed.id } : {}) };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** `try_merge`: the recorded resolution replayed onto `current`; undefined on a conflict. */
|
|
378
|
+
async tryMerge(id: RerereId, path: string, current: Uint8Array): Promise<Uint8Array | undefined> {
|
|
379
|
+
const base = await this.readFile(this.path(id, "preimage"));
|
|
380
|
+
const other = await this.readFile(this.path(id, "postimage"));
|
|
381
|
+
if (!base || !other) return undefined;
|
|
382
|
+
const a = this.attributes;
|
|
383
|
+
const merged = await lowLevelMerge(
|
|
384
|
+
{
|
|
385
|
+
path,
|
|
386
|
+
base,
|
|
387
|
+
ours: current,
|
|
388
|
+
theirs: other,
|
|
389
|
+
baseLabel: "",
|
|
390
|
+
oursLabel: "",
|
|
391
|
+
theirsLabel: "",
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
attributes: await this.attributesOf(path),
|
|
395
|
+
...(a.drivers ? { drivers: a.drivers } : {}),
|
|
396
|
+
...(a.defaultDriver ? { defaultDriver: a.defaultDriver } : {}),
|
|
397
|
+
...(a.driverCommand ? { driverCommand: a.driverCommand } : {}),
|
|
398
|
+
...(a.configuredDriver ? { configuredDriver: a.configuredDriver } : {}),
|
|
399
|
+
style: conflictStyleOf(this.host.workingCopy),
|
|
400
|
+
algorithm: "myers",
|
|
401
|
+
},
|
|
402
|
+
);
|
|
403
|
+
return merged.status === "ok" ? merged.content : undefined;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** `merge`: replays variant `id` onto the worktree file; whether it applied. */
|
|
407
|
+
async merge(id: RerereId, path: string): Promise<boolean> {
|
|
408
|
+
const thisimage = this.path(id, "thisimage");
|
|
409
|
+
const { status } = await this.handleFile(path, false, thisimage);
|
|
410
|
+
if (status < 0) return false;
|
|
411
|
+
const current = await this.readFile(thisimage);
|
|
412
|
+
if (!current) return false;
|
|
413
|
+
const result = await this.tryMerge(id, path, current);
|
|
414
|
+
if (!result) return false;
|
|
415
|
+
// the resolution was used: its mtime tells rerere gc
|
|
416
|
+
const postimage = this.path(id, "postimage");
|
|
417
|
+
if (!(await this.files.touch?.(postimage))) {
|
|
418
|
+
const bytes = await this.readFile(postimage);
|
|
419
|
+
if (bytes) await this.writeFile(postimage, bytes);
|
|
420
|
+
}
|
|
421
|
+
const entry = await this.host.worktree.getEntry(path).catch(() => undefined);
|
|
422
|
+
await this.host.worktree.writeContent(path, result, {
|
|
423
|
+
raw: true,
|
|
424
|
+
...(entry && !entry.isDirectory ? { mode: entry.mode } : {}),
|
|
425
|
+
});
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** `remove_variant`. */
|
|
430
|
+
async removeVariant(id: RerereId): Promise<void> {
|
|
431
|
+
await this.unlink(this.path(id, "postimage"));
|
|
432
|
+
await this.unlink(this.path(id, "preimage"));
|
|
433
|
+
id.dir.status[id.variant] = 0;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** `assign_variant`: the first free variant for a new id. */
|
|
437
|
+
assignVariant(id: RerereId): void {
|
|
438
|
+
let variant = id.variant;
|
|
439
|
+
if (variant < 0) {
|
|
440
|
+
for (variant = 0; variant < id.dir.status.length; variant++) {
|
|
441
|
+
if (!id.dir.status[variant]) break;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
fit(id.dir, variant);
|
|
445
|
+
id.variant = variant;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** `read_rr`. */
|
|
449
|
+
async readRr(): Promise<MergeRr> {
|
|
450
|
+
const rr: MergeRr = new Map();
|
|
451
|
+
const bytes = await this.host.workingCopy.checkout.readStateFile?.("MERGE_RR");
|
|
452
|
+
if (!bytes) return rr;
|
|
453
|
+
const hexLength = this.host.objectFormat.hexLength;
|
|
454
|
+
let at = 0;
|
|
455
|
+
while (at < bytes.length) {
|
|
456
|
+
let end = bytes.indexOf(0, at);
|
|
457
|
+
if (end < 0) end = bytes.length;
|
|
458
|
+
const record = bytes.subarray(at, end);
|
|
459
|
+
at = end + 1;
|
|
460
|
+
const corrupt = () => new RerereError(["fatal: corrupt MERGE_RR"]);
|
|
461
|
+
if (record.length < hexLength + 2) throw corrupt();
|
|
462
|
+
const hex = new TextDecoder().decode(record.subarray(0, hexLength));
|
|
463
|
+
if (!/^[0-9a-fA-F]+$/.test(hex)) throw corrupt();
|
|
464
|
+
let rest: number = hexLength;
|
|
465
|
+
let variant = 0;
|
|
466
|
+
if (record[rest] === 0x2e) {
|
|
467
|
+
let digits = rest + 1;
|
|
468
|
+
while (isDigit(record[digits])) {
|
|
469
|
+
digits++;
|
|
470
|
+
}
|
|
471
|
+
variant = Number.parseInt(new TextDecoder().decode(record.subarray(rest + 1, digits)), 10);
|
|
472
|
+
if (Number.isNaN(variant)) variant = 0;
|
|
473
|
+
rest = digits;
|
|
474
|
+
}
|
|
475
|
+
if (record[rest] !== 0x09) throw corrupt();
|
|
476
|
+
const path = decodeGitPath(record.subarray(rest + 1));
|
|
477
|
+
const dir = await this.dir(hex.toLowerCase());
|
|
478
|
+
fit(dir, variant);
|
|
479
|
+
rr.set(path, { dir, variant });
|
|
480
|
+
}
|
|
481
|
+
return rr;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** `write_rr`: every path still waiting, in path order. */
|
|
485
|
+
async writeRr(rr: MergeRr): Promise<void> {
|
|
486
|
+
const parts: Uint8Array[] = [];
|
|
487
|
+
for (const path of sortedPaths(rr)) {
|
|
488
|
+
const id = rr.get(path);
|
|
489
|
+
if (!id) continue;
|
|
490
|
+
const name = id.variant > 0 ? `${id.dir.hex}.${id.variant}` : id.dir.hex;
|
|
491
|
+
parts.push(enc(`${name}\t`), enc(path), NUL);
|
|
492
|
+
}
|
|
493
|
+
await this.host.workingCopy.checkout.writeStateFile?.("MERGE_RR", concat(parts));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** `has_rerere_resolution`. */
|
|
497
|
+
hasResolution(id: RerereId): boolean {
|
|
498
|
+
if (id.variant < 0) return false;
|
|
499
|
+
return ((id.dir.status[id.variant] ?? 0) & BOTH) === BOTH;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function fit(dir: RerereDir, variant: number): void {
|
|
504
|
+
while (dir.status.length <= variant) dir.status.push(0);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** `is_rr_file`: `file` (variant 0) or `file.<n>`. */
|
|
508
|
+
function variantOf(name: string, file: string): number | undefined {
|
|
509
|
+
if (name === file) return 0;
|
|
510
|
+
if (!name.startsWith(`${file}.`)) return undefined;
|
|
511
|
+
const rest = name.slice(file.length + 1);
|
|
512
|
+
if (!/^\s*[-+]?\d+$/.test(rest)) return undefined;
|
|
513
|
+
const n = Number.parseInt(rest, 10);
|
|
514
|
+
return n >= 0 ? n : undefined;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/** Whether `rerere.enabled` asks for rerere (`-1`: unset, then `rr-cache/` decides). */
|
|
518
|
+
function enabledSetting(workingCopy: WorkingCopy): number {
|
|
519
|
+
const value = configValue(workingCopy, "rerere.enabled");
|
|
520
|
+
if (value === undefined) return -1;
|
|
521
|
+
return parseGitBool(value) === false ? 0 : 1;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* `setup_rerere` (`is_rerere_enabled`): the run over `rr-cache/`, created where
|
|
526
|
+
* `rerere.enabled` is true; undefined where rerere is off (or the working copy keeps no
|
|
527
|
+
* git directory).
|
|
528
|
+
*/
|
|
529
|
+
async function setupRerere(host: RerereHost): Promise<RerereRun | undefined> {
|
|
530
|
+
const enabled = enabledSetting(host.workingCopy);
|
|
531
|
+
if (!enabled) return undefined;
|
|
532
|
+
if (typeof host.workingCopy.checkout.writeStateFile !== "function") return undefined;
|
|
533
|
+
const location = await commonGitFileOf(host.workingCopy, "rr-cache");
|
|
534
|
+
if (!location) return undefined;
|
|
535
|
+
const exists = (await location.files.stats(location.path))?.kind === "directory";
|
|
536
|
+
if (enabled < 0 && !exists) return undefined;
|
|
537
|
+
if (!exists) await location.files.mkdir(location.path);
|
|
538
|
+
return new RerereRun(host, location.files, location.path);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** One conflicted path of the index (`check_one_conflict`). */
|
|
542
|
+
type ConflictKind = "resolved" | "punted" | "three-staged";
|
|
543
|
+
|
|
544
|
+
/** The index's paths by kind, in index order (`find_conflict`, `rerere_remaining`). */
|
|
545
|
+
async function indexConflicts(
|
|
546
|
+
staging: Staging,
|
|
547
|
+
override?: Map<string, Array<{ stage: number; mode: number; objectId: ObjectId }>>,
|
|
548
|
+
): Promise<Array<{ path: string; kind: ConflictKind }>> {
|
|
549
|
+
const byPath = new Map<string, Array<{ stage: number; mode: number }>>();
|
|
550
|
+
const order: string[] = [];
|
|
551
|
+
for await (const entry of staging.entries()) {
|
|
552
|
+
if (override?.has(entry.path)) continue;
|
|
553
|
+
let list = byPath.get(entry.path);
|
|
554
|
+
if (!list) {
|
|
555
|
+
list = [];
|
|
556
|
+
byPath.set(entry.path, list);
|
|
557
|
+
order.push(entry.path);
|
|
558
|
+
}
|
|
559
|
+
list.push({ stage: entry.stage, mode: entry.mode });
|
|
560
|
+
}
|
|
561
|
+
for (const [path, entries] of override ?? []) {
|
|
562
|
+
byPath.set(path, entries);
|
|
563
|
+
order.push(path);
|
|
564
|
+
}
|
|
565
|
+
const out: Array<{ path: string; kind: ConflictKind }> = [];
|
|
566
|
+
const isRegular = (mode: number | undefined) =>
|
|
567
|
+
mode !== undefined && (mode & 0o170000) === 0o100000;
|
|
568
|
+
for (const path of order) {
|
|
569
|
+
const entries = byPath.get(path) ?? [];
|
|
570
|
+
if (entries.some((e) => e.stage === 0)) {
|
|
571
|
+
out.push({ path, kind: "resolved" });
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
const ours = entries.find((e) => e.stage === 2);
|
|
575
|
+
const theirs = entries.find((e) => e.stage === 3);
|
|
576
|
+
out.push({
|
|
577
|
+
path,
|
|
578
|
+
kind:
|
|
579
|
+
ours && theirs && isRegular(ours.mode) && isRegular(theirs.mode)
|
|
580
|
+
? "three-staged"
|
|
581
|
+
: "punted",
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
return out;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* git's `rerere()` (`do_plain_rerere`), as the merge family runs it on conflicts and `git
|
|
589
|
+
* commit` after its commit: each conflicted path's preimage recorded or a recorded
|
|
590
|
+
* resolution replayed, each resolved path's postimage recorded, `MERGE_RR` rewritten.
|
|
591
|
+
* `autoUpdate` is `--rerere-autoupdate` / `--no-rerere-autoupdate` (else
|
|
592
|
+
* `rerere.autoUpdate`): replayed resolutions are staged.
|
|
593
|
+
*/
|
|
594
|
+
export async function runRerere(
|
|
595
|
+
host: RerereHost,
|
|
596
|
+
options: { autoUpdate?: boolean } = {},
|
|
597
|
+
): Promise<RerereOutcome> {
|
|
598
|
+
const run = await setupRerere(host);
|
|
599
|
+
if (!run) return { messages: [], enabled: false };
|
|
600
|
+
const autoUpdate =
|
|
601
|
+
options.autoUpdate ??
|
|
602
|
+
parseGitBool(configValue(host.workingCopy, "rerere.autoUpdate") ?? "false") ??
|
|
603
|
+
false;
|
|
604
|
+
const rr = await run.readRr();
|
|
605
|
+
|
|
606
|
+
const conflicts = (await indexConflicts(host.staging))
|
|
607
|
+
.filter((c) => c.kind === "three-staged")
|
|
608
|
+
.map((c) => c.path)
|
|
609
|
+
.sort(comparePaths);
|
|
610
|
+
for (const path of conflicts) {
|
|
611
|
+
const { status, id: hex } = await run.handleFile(path, true);
|
|
612
|
+
if (status !== 0 && rr.has(path)) {
|
|
613
|
+
const old = rr.get(path);
|
|
614
|
+
if (old) await run.removeVariant(old);
|
|
615
|
+
rr.delete(path);
|
|
616
|
+
}
|
|
617
|
+
if (status < 1 || !hex) continue;
|
|
618
|
+
rr.set(path, await run.newId(hex));
|
|
619
|
+
await run.mkdir(run.path({ dir: await run.dir(hex), variant: 0 }));
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const update: string[] = [];
|
|
623
|
+
for (const path of sortedPaths(rr)) {
|
|
624
|
+
const id = rr.get(path);
|
|
625
|
+
if (!id) continue;
|
|
626
|
+
if (await doRerereOnePath(run, path, id, update, autoUpdate)) rr.set(path, null);
|
|
627
|
+
}
|
|
628
|
+
if (update.length > 0) await updatePaths(run, update);
|
|
629
|
+
await run.writeRr(rr);
|
|
630
|
+
return { messages: run.messages, enabled: true };
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** `do_rerere_one_path`; true when the path is done with (resolved or replayed). */
|
|
634
|
+
async function doRerereOnePath(
|
|
635
|
+
run: RerereRun,
|
|
636
|
+
path: string,
|
|
637
|
+
id: RerereId,
|
|
638
|
+
update: string[],
|
|
639
|
+
autoUpdate: boolean,
|
|
640
|
+
): Promise<boolean> {
|
|
641
|
+
const dir = id.dir;
|
|
642
|
+
// has the user resolved it already?
|
|
643
|
+
if (id.variant >= 0) {
|
|
644
|
+
if ((await run.handleFile(path, false)).status === 0) {
|
|
645
|
+
const postimage = run.path(id, "postimage");
|
|
646
|
+
// copy_file: O_EXCL, an existing postimage stays
|
|
647
|
+
if ((await run.files.stats(postimage)) === undefined) {
|
|
648
|
+
const content = await run.readWorktree(path);
|
|
649
|
+
if (content) await run.writeFile(postimage, content);
|
|
650
|
+
}
|
|
651
|
+
fit(dir, id.variant);
|
|
652
|
+
dir.status[id.variant] = (dir.status[id.variant] ?? 0) | RR_HAS_POSTIMAGE;
|
|
653
|
+
run.messages.push(`Recorded resolution for '${path}'.`);
|
|
654
|
+
return true;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
// does any existing resolution apply cleanly?
|
|
658
|
+
for (let variant = 0; variant < dir.status.length; variant++) {
|
|
659
|
+
if (((dir.status[variant] ?? 0) & BOTH) !== BOTH) continue;
|
|
660
|
+
if (!(await run.merge({ dir, variant }, path))) continue;
|
|
661
|
+
// a different variant applies cleanly: no point keeping our own
|
|
662
|
+
if (id.variant >= 0 && id.variant !== variant) await run.removeVariant(id);
|
|
663
|
+
if (autoUpdate) update.push(path);
|
|
664
|
+
else run.messages.push(`Resolved '${path}' using previous resolution.`);
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
// none applies: a new variant
|
|
668
|
+
run.assignVariant(id);
|
|
669
|
+
await run.handleFile(path, false, run.path(id, "preimage"));
|
|
670
|
+
if ((dir.status[id.variant] ?? 0) & RR_HAS_POSTIMAGE) {
|
|
671
|
+
await run.unlink(run.path(id, "postimage"));
|
|
672
|
+
dir.status[id.variant] = (dir.status[id.variant] ?? 0) & ~RR_HAS_POSTIMAGE;
|
|
673
|
+
}
|
|
674
|
+
dir.status[id.variant] = (dir.status[id.variant] ?? 0) | RR_HAS_PREIMAGE;
|
|
675
|
+
run.messages.push(`Recorded preimage for '${path}'`);
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/** `update_paths`: the replayed files staged (`add_file_to_index`). */
|
|
680
|
+
async function updatePaths(run: RerereRun, paths: string[]): Promise<void> {
|
|
681
|
+
const { staging, worktree, blobs, workingCopy } = run.host;
|
|
682
|
+
const adder = await IndexAdder.open(staging, blobs, worktreeModeTrust(workingCopy, worktree), {
|
|
683
|
+
pathRules: worktreePathRules(workingCopy),
|
|
684
|
+
});
|
|
685
|
+
for (const path of paths.sort(comparePaths)) {
|
|
686
|
+
const entry = await worktree.getEntry(path);
|
|
687
|
+
if (entry) await adder.add(worktree, path, entry);
|
|
688
|
+
run.messages.push(`Staged '${path}' using previous resolution.`);
|
|
689
|
+
}
|
|
690
|
+
await adder.finish();
|
|
691
|
+
await staging.write();
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* `rerere_clear` (`git rerere clear`, `rebase --skip`/`--abort`, `am --skip`/`--abort`): the
|
|
696
|
+
* waiting paths' records without a resolution removed, `MERGE_RR` deleted.
|
|
697
|
+
*/
|
|
698
|
+
export async function rerereClear(host: RerereHost): Promise<RerereOutcome> {
|
|
699
|
+
const run = await setupRerere(host);
|
|
700
|
+
if (!run) return { messages: [], enabled: false };
|
|
701
|
+
const rr = await run.readRr();
|
|
702
|
+
for (const path of sortedPaths(rr)) {
|
|
703
|
+
const id = rr.get(path);
|
|
704
|
+
if (!id || run.hasResolution(id)) continue;
|
|
705
|
+
// unlink_rr_item
|
|
706
|
+
await run.unlink(run.path(id, "thisimage"));
|
|
707
|
+
await run.removeVariant(id);
|
|
708
|
+
await run.rmdir(run.path(id));
|
|
709
|
+
}
|
|
710
|
+
await host.workingCopy.checkout.removeStateFile?.("MERGE_RR");
|
|
711
|
+
return { messages: run.messages, enabled: true };
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/** `git rerere status`: the paths `MERGE_RR` lists. */
|
|
715
|
+
export async function rerereStatus(host: RerereHost): Promise<string[]> {
|
|
716
|
+
const run = await setupRerere(host);
|
|
717
|
+
if (!run) return [];
|
|
718
|
+
return sortedPaths(await run.readRr());
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* `git rerere remaining`: the paths `MERGE_RR` lists that the index has not resolved, and
|
|
723
|
+
* the conflicts rerere cannot handle (not two regular files), in path order.
|
|
724
|
+
*/
|
|
725
|
+
export async function rerereRemaining(host: RerereHost): Promise<string[]> {
|
|
726
|
+
const run = await setupRerere(host);
|
|
727
|
+
if (!run) return [];
|
|
728
|
+
const rr = await run.readRr();
|
|
729
|
+
const resolved = new Set<string>();
|
|
730
|
+
for (const { path, kind } of await indexConflicts(host.staging)) {
|
|
731
|
+
if (kind === "punted") {
|
|
732
|
+
if (!rr.has(path)) rr.set(path, null);
|
|
733
|
+
} else if (kind === "resolved" && rr.has(path)) resolved.add(path);
|
|
734
|
+
}
|
|
735
|
+
return sortedPaths(rr).filter((p) => !resolved.has(p));
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* `git rerere diff`: for each path `MERGE_RR` lists, the diff from its preimage to the
|
|
740
|
+
* worktree file (`diff_two`, xdiff with 3 lines of context, no function names).
|
|
741
|
+
*/
|
|
742
|
+
export async function rerereDiff(
|
|
743
|
+
host: RerereHost,
|
|
744
|
+
diff: (minus: Uint8Array, plus: Uint8Array) => Uint8Array,
|
|
745
|
+
): Promise<{ stdout: Uint8Array[]; fatal?: string }> {
|
|
746
|
+
const run = await setupRerere(host);
|
|
747
|
+
const stdout: Uint8Array[] = [];
|
|
748
|
+
if (!run) return { stdout };
|
|
749
|
+
const rr = await run.readRr();
|
|
750
|
+
for (const path of sortedPaths(rr)) {
|
|
751
|
+
const id = rr.get(path);
|
|
752
|
+
if (!id) continue;
|
|
753
|
+
const minus = await run.readFile(run.path(id, "preimage"));
|
|
754
|
+
const entry = await host.worktree.getEntry(path).catch(() => undefined);
|
|
755
|
+
let plus: Uint8Array | undefined;
|
|
756
|
+
if (entry && !entry.isDirectory) {
|
|
757
|
+
const chunks: Uint8Array[] = [];
|
|
758
|
+
for await (const chunk of host.worktree.readContent(path)) chunks.push(chunk);
|
|
759
|
+
plus = concat(chunks);
|
|
760
|
+
}
|
|
761
|
+
if (!minus || !plus) {
|
|
762
|
+
return { stdout, fatal: `unable to generate diff for '${gitPathOf(run, id)}'` };
|
|
763
|
+
}
|
|
764
|
+
stdout.push(enc(`--- a/${path}\n+++ b/${path}\n`), diff(minus, plus));
|
|
765
|
+
}
|
|
766
|
+
return { stdout };
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/** `git_path("rr-cache/<hex>")` as git prints it (the git directory is `.git` there). */
|
|
770
|
+
function gitPathOf(_run: RerereRun, id: RerereId): string {
|
|
771
|
+
return `.git/rr-cache/${id.dir.hex}`;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/** A path's stages for `rerere forget` (the index's, or restored from resolve-undo). */
|
|
775
|
+
type Stages = Array<{ stage: number; mode: number; objectId: ObjectId }>;
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* `git rerere forget <pathspec>` (`rerere_forget`): the paths' conflicts recreated from the
|
|
779
|
+
* index (resolved ones from its resolve-undo records, in memory only), the resolution that
|
|
780
|
+
* replays cleanly onto each removed and its preimage written again, the path waiting in
|
|
781
|
+
* `MERGE_RR` once more.
|
|
782
|
+
*/
|
|
783
|
+
export async function rerereForget(
|
|
784
|
+
host: RerereHost,
|
|
785
|
+
matches: (path: string) => boolean,
|
|
786
|
+
): Promise<RerereOutcome> {
|
|
787
|
+
const run = await setupRerere(host);
|
|
788
|
+
if (!run) return { messages: [], enabled: false };
|
|
789
|
+
const rr = await run.readRr();
|
|
790
|
+
// unmerge_index: the resolve-undo records of the matching paths as conflict stages
|
|
791
|
+
const override = new Map<string, Stages>();
|
|
792
|
+
for (const record of host.staging.getResolveUndo?.() ?? []) {
|
|
793
|
+
if (!matches(record.path)) continue;
|
|
794
|
+
const stages: Stages = [];
|
|
795
|
+
for (let i = 0; i < 3; i++) {
|
|
796
|
+
const mode = record.modes[i] ?? 0;
|
|
797
|
+
const objectId = record.objectIds[i];
|
|
798
|
+
if (mode && objectId) stages.push({ stage: i + 1, mode, objectId });
|
|
799
|
+
}
|
|
800
|
+
override.set(record.path, stages);
|
|
801
|
+
}
|
|
802
|
+
const stagesOf = async (path: string): Promise<Stages> => {
|
|
803
|
+
const restored = override.get(path);
|
|
804
|
+
if (restored) return restored;
|
|
805
|
+
return (await host.staging.getEntries(path)).map((e) => ({
|
|
806
|
+
stage: e.stage,
|
|
807
|
+
mode: e.mode,
|
|
808
|
+
objectId: e.objectId,
|
|
809
|
+
}));
|
|
810
|
+
};
|
|
811
|
+
const conflicts = (await indexConflicts(host.staging, override))
|
|
812
|
+
.filter((c) => c.kind === "three-staged")
|
|
813
|
+
.map((c) => c.path)
|
|
814
|
+
.sort(comparePaths);
|
|
815
|
+
for (const path of conflicts) {
|
|
816
|
+
if (!matches(path)) continue;
|
|
817
|
+
await forgetOnePath(run, path, await stagesOf(path), rr);
|
|
818
|
+
}
|
|
819
|
+
await run.writeRr(rr);
|
|
820
|
+
return { messages: run.messages, enabled: true };
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/** `handle_cache`: the conflict recreated from the stages (ll_merge), handled as a file. */
|
|
824
|
+
async function handleCache(
|
|
825
|
+
run: RerereRun,
|
|
826
|
+
path: string,
|
|
827
|
+
stages: Stages,
|
|
828
|
+
output?: string,
|
|
829
|
+
): Promise<{ status: number; id?: string }> {
|
|
830
|
+
if (stages.some((s) => s.stage === 0)) return { status: -1 };
|
|
831
|
+
const read = async (stage: number): Promise<Uint8Array> => {
|
|
832
|
+
const entry = stages.find((s) => s.stage === stage);
|
|
833
|
+
if (!entry) return new Uint8Array(0);
|
|
834
|
+
const chunks: Uint8Array[] = [];
|
|
835
|
+
const stream = await run.host.blobs.load(entry.objectId);
|
|
836
|
+
if (stream) for await (const chunk of stream) chunks.push(chunk);
|
|
837
|
+
return concat(chunks);
|
|
838
|
+
};
|
|
839
|
+
const a = run.attributes;
|
|
840
|
+
const merged = await lowLevelMerge(
|
|
841
|
+
{
|
|
842
|
+
path,
|
|
843
|
+
base: await read(1),
|
|
844
|
+
ours: await read(2),
|
|
845
|
+
theirs: await read(3),
|
|
846
|
+
baseLabel: "",
|
|
847
|
+
oursLabel: "ours",
|
|
848
|
+
theirsLabel: "theirs",
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
attributes: await run.attributesOf(path),
|
|
852
|
+
...(a.drivers ? { drivers: a.drivers } : {}),
|
|
853
|
+
...(a.defaultDriver ? { defaultDriver: a.defaultDriver } : {}),
|
|
854
|
+
...(a.driverCommand ? { driverCommand: a.driverCommand } : {}),
|
|
855
|
+
...(a.configuredDriver ? { configuredDriver: a.configuredDriver } : {}),
|
|
856
|
+
style: conflictStyleOf(run.host.workingCopy),
|
|
857
|
+
algorithm: "myers",
|
|
858
|
+
},
|
|
859
|
+
);
|
|
860
|
+
const parsed = normalizeConflicts(
|
|
861
|
+
merged.content,
|
|
862
|
+
await run.markerSize(path),
|
|
863
|
+
run.host.objectFormat,
|
|
864
|
+
);
|
|
865
|
+
if (output) await run.writeFile(output, parsed.output);
|
|
866
|
+
return { status: parsed.status, ...(parsed.id ? { id: parsed.id } : {}) };
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** `rerere_forget_one_path`. */
|
|
870
|
+
async function forgetOnePath(
|
|
871
|
+
run: RerereRun,
|
|
872
|
+
path: string,
|
|
873
|
+
stages: Stages,
|
|
874
|
+
rr: MergeRr,
|
|
875
|
+
): Promise<void> {
|
|
876
|
+
const { status, id: hex } = await handleCache(run, path, stages);
|
|
877
|
+
if (status < 1 || !hex) {
|
|
878
|
+
run.error(`could not parse conflict hunks in '${path}'`);
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
const id = await run.newId(hex);
|
|
882
|
+
for (id.variant = 0; id.variant < id.dir.status.length; id.variant++) {
|
|
883
|
+
if (!run.hasResolution(id)) continue;
|
|
884
|
+
const thisimage = run.path(id, "thisimage");
|
|
885
|
+
await handleCache(run, path, stages, thisimage);
|
|
886
|
+
const current = await run.readFile(thisimage);
|
|
887
|
+
if (!current) {
|
|
888
|
+
run.error(`failed to update conflicted state in '${path}'`);
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
if (await run.tryMerge(id, path, current)) break;
|
|
892
|
+
}
|
|
893
|
+
if (id.dir.status.length <= id.variant) {
|
|
894
|
+
run.error(`no remembered resolution for '${path}'`);
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
if (!(await run.unlink(run.path(id, "postimage")))) {
|
|
898
|
+
run.error(`no remembered resolution for '${path}'`);
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
await handleCache(run, path, stages, run.path(id, "preimage"));
|
|
902
|
+
run.messages.push(`Updated preimage for '${path}'`);
|
|
903
|
+
rr.set(path, id);
|
|
904
|
+
run.messages.push(`Forgot resolution for '${path}'`);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/** The {@link RerereHost} of a working copy. */
|
|
908
|
+
export function rerereHostOf(
|
|
909
|
+
workingCopy: WorkingCopy,
|
|
910
|
+
staging: Staging,
|
|
911
|
+
worktree: Worktree,
|
|
912
|
+
blobs: Blobs,
|
|
913
|
+
objectFormat: ObjectFormat,
|
|
914
|
+
): RerereHost {
|
|
915
|
+
return { workingCopy, staging, worktree, blobs, objectFormat };
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/** Where rr-cache lives for `git rerere gc`: the FilesApi and the common git directory. */
|
|
919
|
+
export async function rerereGcLocation(
|
|
920
|
+
workingCopy: WorkingCopy,
|
|
921
|
+
): Promise<{ files: FilesApi; gitDir: string } | undefined> {
|
|
922
|
+
const location = await commonGitFileOf(workingCopy, "rr-cache");
|
|
923
|
+
if (!location) return undefined;
|
|
924
|
+
return { files: location.files, gitDir: location.path.replace(/\/?rr-cache$/, "") || "." };
|
|
925
|
+
}
|