@statewalker/vcs-commands 0.8.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 +32 -0
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-patch.d.ts +7 -0
- package/dist/commands/add-patch/add-patch.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 +88 -2
- package/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-command.d.ts +2 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.d.ts +7 -0
- package/dist/commands/apply/apply-parse.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 +345 -8
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/blame-ignore.d.ts +48 -0
- package/dist/commands/blame-ignore.d.ts.map +1 -0
- 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-mailmap-command.d.ts +49 -0
- package/dist/commands/check-mailmap-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 +7 -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/checkout-paths.d.ts +4 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -1
- package/dist/commands/cherry-command.d.ts +61 -0
- package/dist/commands/cherry-command.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +33 -1
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +32 -0
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clean-interactive.d.ts +56 -0
- package/dist/commands/clean-interactive.d.ts.map +1 -0
- package/dist/commands/clone-command.d.ts +135 -2
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +59 -3
- 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/describe-command.d.ts +71 -64
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +249 -10
- 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 +125 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fetch-multiple-command.d.ts +193 -0
- package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
- package/dist/commands/format-patch-command.d.ts +28 -2
- package/dist/commands/format-patch-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-describe.d.ts +77 -4
- package/dist/commands/git-describe.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +47 -1
- 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 +56 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +6 -3
- package/dist/commands/init-command.d.ts +89 -0
- 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/line-log.d.ts +161 -0
- package/dist/commands/line-log.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts.map +1 -1
- package/dist/commands/log-command.d.ts +261 -6
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +4 -2
- package/dist/commands/log-graph.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +88 -2
- 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/mailmap.d.ts +24 -1
- package/dist/commands/mailmap.d.ts.map +1 -1
- 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 +58 -1
- 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 +69 -5
- package/dist/commands/merge-drivers.d.ts.map +1 -1
- package/dist/commands/merge-strategy-options.d.ts +69 -0
- package/dist/commands/merge-strategy-options.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +16 -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/message-cleanup.d.ts +2 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -1
- package/dist/commands/mktag-command.d.ts +51 -0
- package/dist/commands/mktag-command.d.ts.map +1 -0
- package/dist/commands/name-rev-command.d.ts +65 -0
- package/dist/commands/name-rev-command.d.ts.map +1 -0
- package/dist/commands/name-rev.d.ts +110 -22
- package/dist/commands/name-rev.d.ts.map +1 -1
- 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/octopus-merge.d.ts +26 -1
- package/dist/commands/octopus-merge.d.ts.map +1 -1
- package/dist/commands/ort-merge.d.ts +40 -0
- package/dist/commands/ort-merge.d.ts.map +1 -1
- package/dist/commands/ort-recursive.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 +82 -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 +182 -38
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +82 -2
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/range-diff/index.d.ts +4 -0
- package/dist/commands/range-diff/index.d.ts.map +1 -0
- package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
- package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
- package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff.d.ts +106 -0
- package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
- package/dist/commands/read-tree-command.d.ts +14 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +129 -4
- 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/remerge-diff.d.ts +59 -0
- package/dist/commands/remerge-diff.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +41 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- 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-show-command.d.ts +204 -0
- package/dist/commands/remote-show-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/reset-command.d.ts +19 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +7 -0
- package/dist/commands/restore-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 +78 -3
- 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 +32 -1
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +7 -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 +120 -1
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts +10 -1
- package/dist/commands/sequencer-support.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/shortlog-command.d.ts +109 -0
- package/dist/commands/shortlog-command.d.ts.map +1 -0
- package/dist/commands/shortlog.d.ts +151 -0
- package/dist/commands/shortlog.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 +33 -3
- 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 +99 -3
- package/dist/commands/submodule-commands.d.ts.map +1 -1
- package/dist/commands/submodule-fetch.d.ts +149 -0
- package/dist/commands/submodule-fetch.d.ts.map +1 -0
- package/dist/commands/submodule-model.d.ts +8 -0
- package/dist/commands/submodule-model.d.ts.map +1 -1
- package/dist/commands/submodule-unpack.d.ts +120 -0
- package/dist/commands/submodule-unpack.d.ts.map +1 -0
- package/dist/commands/submodule-update-command.d.ts +21 -1
- package/dist/commands/submodule-update-command.d.ts.map +1 -1
- package/dist/commands/subtree-shift.d.ts +27 -0
- package/dist/commands/subtree-shift.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +3 -0
- package/dist/commands/switch-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/worktree-overwrite-checks.d.ts +2 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/{commands-ISM52N0n.js → commands-Mlo1dxQN.js} +56133 -70269
- package/dist/errors/command-errors.d.ts +58 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/index.js +67 -1
- package/dist/fsck-CrhVMNIH.js +5179 -0
- package/dist/git-command.d.ts +89 -3
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +628 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/guarded-transport-command.d.ts +84 -0
- package/dist/guarded-transport-command.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/maintenance-run-command-Bw21HEkH.js +13539 -0
- package/dist/remote-transport-Bu4PGSMD.js +2605 -0
- package/dist/rename/detect-renames.d.ts +20 -0
- package/dist/rename/detect-renames.d.ts.map +1 -1
- package/dist/rename/diffcore-break.d.ts +51 -0
- package/dist/rename/diffcore-break.d.ts.map +1 -0
- package/dist/rename/index.d.ts +1 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/blame-format.d.ts +62 -1
- package/dist/results/blame-format.d.ts.map +1 -1
- package/dist/results/cherry-pick-result.d.ts +6 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +9 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/diff-dirstat.d.ts +36 -0
- package/dist/results/diff-dirstat.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +20 -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 +67 -3
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/fetch-result.d.ts +24 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +2 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/init-result.d.ts +8 -1
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/line-range-hunks.d.ts +27 -0
- package/dist/results/line-range-hunks.d.ts.map +1 -0
- package/dist/results/merge-result.d.ts +13 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +11 -0
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +10 -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/status-result.d.ts +1 -1
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-ERo9vELd.js +49673 -0
- package/dist/transport-command.d.ts +93 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/commands/add-command.ts +118 -0
- package/src/commands/add-patch/add-patch.ts +8 -0
- package/src/commands/add-patch/patch-backend.ts +24 -3
- 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 +301 -12
- package/src/commands/apply/apply-command.ts +52 -9
- package/src/commands/apply/apply-parse.ts +10 -0
- package/src/commands/apply/index.ts +9 -1
- 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 +1551 -53
- package/src/commands/blame-ignore.ts +307 -0
- 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-mailmap-command.ts +129 -0
- package/src/commands/check-ref-format-command.ts +129 -0
- package/src/commands/checkout-command.ts +131 -28
- package/src/commands/checkout-index-command.ts +568 -0
- package/src/commands/checkout-paths.ts +35 -0
- package/src/commands/cherry-command.ts +187 -0
- package/src/commands/cherry-pick-command.ts +63 -2
- package/src/commands/clean-command.ts +92 -12
- package/src/commands/clean-interactive.ts +522 -0
- package/src/commands/clone-command.ts +803 -50
- package/src/commands/commit-command.ts +202 -51
- 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/describe-command.ts +341 -254
- package/src/commands/diff-command.ts +1186 -99
- 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 +665 -14
- package/src/commands/fetch-multiple-command.ts +668 -0
- package/src/commands/format-patch-command.ts +189 -77
- 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-describe.ts +456 -217
- package/src/commands/git-hooks.ts +165 -9
- 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 +62 -0
- package/src/commands/init-command.ts +617 -49
- 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/line-log.ts +931 -0
- package/src/commands/local-transport.ts +252 -4
- package/src/commands/log-command.ts +1518 -182
- package/src/commands/log-graph.ts +6 -3
- package/src/commands/log-output.ts +228 -15
- 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/mailmap.ts +41 -5
- package/src/commands/maintenance-run-command.ts +949 -0
- package/src/commands/merge-command.ts +351 -47
- package/src/commands/merge-config.ts +23 -1
- package/src/commands/merge-drivers.ts +112 -20
- package/src/commands/merge-strategy-options.ts +224 -0
- package/src/commands/merge-support.ts +130 -26
- package/src/commands/merge-tree-command.ts +786 -0
- package/src/commands/message-cleanup.ts +1 -1
- package/src/commands/mktag-command.ts +149 -0
- package/src/commands/name-rev-command.ts +184 -0
- package/src/commands/name-rev.ts +700 -109
- 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/octopus-merge.ts +35 -11
- package/src/commands/ort-merge.ts +124 -23
- package/src/commands/ort-recursive.ts +40 -2
- package/src/commands/patch-id-command.ts +65 -0
- package/src/commands/patch-id.ts +327 -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 +720 -224
- package/src/commands/push-command.ts +440 -8
- package/src/commands/range-diff/index.ts +3 -0
- package/src/commands/range-diff/linear-assignment.ts +203 -0
- package/src/commands/range-diff/range-diff-command.ts +433 -0
- package/src/commands/range-diff/range-diff.ts +617 -0
- package/src/commands/read-tree-command.ts +74 -3
- package/src/commands/rebase-command.ts +647 -83
- package/src/commands/refs-command.ts +274 -0
- package/src/commands/remerge-diff.ts +241 -0
- package/src/commands/remote-command.ts +98 -10
- package/src/commands/remote-object-info-command.ts +109 -0
- package/src/commands/remote-show-command.ts +836 -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/reset-command.ts +78 -3
- package/src/commands/restore-command.ts +15 -0
- package/src/commands/rev-filter/commit-grep.ts +7 -2
- package/src/commands/rev-list-command.ts +196 -11
- package/src/commands/rev-parse-command.ts +62 -4
- package/src/commands/revert-command.ts +62 -2
- package/src/commands/revision-range.ts +10 -3
- package/src/commands/revision-resolver.ts +44 -3
- package/src/commands/sequencer-pick.ts +370 -29
- package/src/commands/sequencer-support.ts +164 -2
- package/src/commands/serve-repository.ts +65 -0
- package/src/commands/session-id.ts +31 -0
- package/src/commands/shortlog-command.ts +354 -0
- package/src/commands/shortlog.ts +361 -0
- package/src/commands/show-branch-command.ts +981 -0
- package/src/commands/show-command.ts +3 -2
- 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 +158 -31
- package/src/commands/status-format.ts +1 -1
- 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 +333 -5
- package/src/commands/submodule-fetch.ts +789 -0
- package/src/commands/submodule-model.ts +9 -1
- package/src/commands/submodule-unpack.ts +265 -0
- package/src/commands/submodule-update-command.ts +68 -5
- package/src/commands/subtree-shift.ts +215 -0
- package/src/commands/switch-command.ts +9 -0
- package/src/commands/textconv-cache.ts +143 -0
- package/src/commands/tree-restore.ts +20 -1
- 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/commands/worktree-overwrite-checks.ts +5 -0
- package/src/errors/command-errors.ts +80 -0
- package/src/git-command.ts +218 -2
- package/src/git.ts +1033 -80
- package/src/guarded-transport-command.ts +176 -0
- package/src/index.ts +1 -0
- package/src/rename/detect-renames.ts +42 -8
- package/src/rename/diffcore-break.ts +166 -0
- package/src/rename/index.ts +1 -0
- package/src/results/blame-format.ts +268 -43
- package/src/results/cherry-pick-result.ts +6 -0
- package/src/results/clone-result.ts +6 -0
- package/src/results/diff-dirstat.ts +117 -0
- package/src/results/diff-entry.ts +24 -0
- package/src/results/diff-formatter.ts +8 -4
- package/src/results/diff-output.ts +239 -8
- package/src/results/diff-pickaxe.ts +1 -1
- package/src/results/fetch-result.ts +24 -1
- package/src/results/index.ts +2 -0
- package/src/results/init-result.ts +10 -1
- package/src/results/line-range-hunks.ts +126 -0
- package/src/results/merge-result.ts +14 -0
- package/src/results/pull-result.ts +7 -0
- package/src/results/push-result.ts +10 -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/results/status-result.ts +2 -2
- package/src/transport-command.ts +216 -4
- package/dist/fsck-DLRpbwTj.js +0 -13405
- package/dist/results-TB2IJ64h.js +0 -4700
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Commit, ObjectId, PersonIdent } from "@statewalker/vcs-core";
|
|
2
2
|
import { DEFAULT_BIG_FILE_THRESHOLD } from "@statewalker/vcs-core";
|
|
3
3
|
import {
|
|
4
|
+
ByteLines,
|
|
4
5
|
type InternedText,
|
|
5
6
|
LineInterner,
|
|
6
7
|
parseGitBool,
|
|
@@ -9,7 +10,11 @@ import {
|
|
|
9
10
|
type XdiffAlgorithm,
|
|
10
11
|
type XdiffOptions,
|
|
11
12
|
xdiffHunks,
|
|
13
|
+
xdlHashRecord,
|
|
12
14
|
} from "@statewalker/vcs-utils";
|
|
15
|
+
import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
16
|
+
import { computeObjectId } from "@statewalker/vcs-utils/pack";
|
|
17
|
+
import { expandUserPath } from "@statewalker/vcs-working-tree";
|
|
13
18
|
|
|
14
19
|
import { RefNotFoundError } from "../errors/ref-errors.js";
|
|
15
20
|
import { GitCommand } from "../git-command.js";
|
|
@@ -20,11 +25,28 @@ import {
|
|
|
20
25
|
detectRenames,
|
|
21
26
|
GIT_MAX_SCORE,
|
|
22
27
|
} from "../rename/index.js";
|
|
28
|
+
import {
|
|
29
|
+
type Fingerprint,
|
|
30
|
+
guessLineBlames,
|
|
31
|
+
type LineBlame,
|
|
32
|
+
lineFingerprints,
|
|
33
|
+
} from "./blame-ignore.js";
|
|
34
|
+
import { parseGitColor } from "./config-value-types.js";
|
|
23
35
|
import { abbrevLengths } from "./core-config.js";
|
|
36
|
+
import { DiffCommand } from "./diff-command.js";
|
|
37
|
+
import { type TextconvRunner, textconvRunnerOf } from "./diff-textconv.js";
|
|
38
|
+
import { localTimezoneOffset } from "./git-date.js";
|
|
39
|
+
import { hostEnvironmentOf } from "./git-ident.js";
|
|
40
|
+
import { type Mailmap, readMailmapFile, readRepositoryMailmap } from "./mailmap.js";
|
|
41
|
+
import { OperationState } from "./merge-support.js";
|
|
24
42
|
import { canonicalObjectId } from "./object-id-input.js";
|
|
25
43
|
|
|
26
44
|
/** Line bytes the interner holds before blame starts a new one (see `setInternerByteLimit`) */
|
|
27
45
|
const DEFAULT_INTERNER_BYTE_LIMIT = 64 * 1024 * 1024;
|
|
46
|
+
/** Bytes of the files looked in for copies kept interned between commits */
|
|
47
|
+
const COPY_SOURCE_CACHE_BYTES = 16 * 1024 * 1024;
|
|
48
|
+
/** Bytes of line hashes of the files looked in for copies kept between commits */
|
|
49
|
+
const COPY_HASH_CACHE_BYTES = 32 * 1024 * 1024;
|
|
28
50
|
|
|
29
51
|
/**
|
|
30
52
|
* A single blame entry - represents authorship of one or more consecutive lines.
|
|
@@ -49,6 +71,16 @@ export interface BlameEntry {
|
|
|
49
71
|
previous?: { commitId: ObjectId; path: string };
|
|
50
72
|
/** A boundary commit (a root commit, unless `setShowRoot(true)`): `^` in git's output */
|
|
51
73
|
boundary?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Lines an ignored commit changed, blamed on the line of its parent they resemble (`?` in
|
|
76
|
+
* git's output and `ignored` in the porcelain ones under `blame.markIgnoredLines`)
|
|
77
|
+
*/
|
|
78
|
+
ignored?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Lines an ignored commit changed that resemble no line of its parent, so stay its own
|
|
81
|
+
* (`*` and `unblamable` under `blame.markUnblamableLines`)
|
|
82
|
+
*/
|
|
83
|
+
unblamable?: boolean;
|
|
52
84
|
}
|
|
53
85
|
|
|
54
86
|
/**
|
|
@@ -85,8 +117,23 @@ export interface BlameResult {
|
|
|
85
117
|
* line ranges asked for
|
|
86
118
|
*/
|
|
87
119
|
entries: BlameEntry[];
|
|
88
|
-
/** The blamed file's content at the start commit */
|
|
120
|
+
/** The blamed file's content at the start commit (`--reverse`: at the commit reversed from) */
|
|
89
121
|
content?: Uint8Array;
|
|
122
|
+
/** Whether git's output marks ignored lines (`blame.markIgnoredLines`, `setMarkIgnoredLines`) */
|
|
123
|
+
markIgnoredLines?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Whether git's output marks unblamable lines (`blame.markUnblamableLines`,
|
|
126
|
+
* `setMarkUnblamableLines`)
|
|
127
|
+
*/
|
|
128
|
+
markUnblamableLines?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* The entries in the order blame found them, before sorting and coalescing: what
|
|
131
|
+
* `git blame --incremental` prints (`formatBlameIncremental`). Each entry's `boundary` is
|
|
132
|
+
* what git knew when it printed the entry.
|
|
133
|
+
*/
|
|
134
|
+
incremental?: BlameEntry[];
|
|
135
|
+
/** The output settings of the repository's configuration (defaults of `formatBlame`) */
|
|
136
|
+
output?: BlameOutputConfig;
|
|
90
137
|
/**
|
|
91
138
|
* Get the blame entry for a specific line (1-based).
|
|
92
139
|
*
|
|
@@ -137,8 +184,67 @@ export interface BlameResult {
|
|
|
137
184
|
autoAbbrev?(): Promise<number>;
|
|
138
185
|
}
|
|
139
186
|
|
|
187
|
+
/**
|
|
188
|
+
* The output settings `git blame` reads from the configuration (`git_blame_config`), which
|
|
189
|
+
* `formatBlame` takes as defaults of its options
|
|
190
|
+
*/
|
|
191
|
+
export interface BlameOutputConfig {
|
|
192
|
+
/** `blame.date`: the date mode (`--date`), as written */
|
|
193
|
+
date?: string;
|
|
194
|
+
/** `blame.showEmail` (`-e`) */
|
|
195
|
+
showEmail?: boolean;
|
|
196
|
+
/** `blame.blankBoundary` (`-b`) */
|
|
197
|
+
blankBoundary?: boolean;
|
|
198
|
+
/** `blame.coloring=repeatedLines` (`--color-lines`) */
|
|
199
|
+
colorLines?: boolean;
|
|
200
|
+
/** `blame.coloring=highlightRecent` (`--color-by-age`) */
|
|
201
|
+
colorByAge?: boolean;
|
|
202
|
+
/** `color.blame.repeatedLines`: the escape sequence of the color (default cyan) */
|
|
203
|
+
repeatedLinesColor?: string;
|
|
204
|
+
/** `color.blame.highlightRecent`: `<color>,<date>,<color>,...` as written */
|
|
205
|
+
highlightRecent?: string;
|
|
206
|
+
/** Warnings git prints while reading these settings (invalid values it skips) */
|
|
207
|
+
warnings?: string[];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The buffer blamed instead of the file of the start commit (`setContents`): git's fake
|
|
212
|
+
* working-tree commit on top of the start commit
|
|
213
|
+
*/
|
|
214
|
+
export interface BlameContentsOptions {
|
|
215
|
+
/**
|
|
216
|
+
* The `--contents` argument, named in the fake commit's summary (`-` reads "standard
|
|
217
|
+
* input", the default)
|
|
218
|
+
*/
|
|
219
|
+
name?: string;
|
|
220
|
+
/**
|
|
221
|
+
* The working tree's file blamed as `git blame <path>` without a revision does: the commit
|
|
222
|
+
* is "Not Committed Yet" instead of "External file (--contents)"
|
|
223
|
+
*/
|
|
224
|
+
workingTree?: boolean;
|
|
225
|
+
/** The fake commit's time in seconds (default now) */
|
|
226
|
+
time?: number;
|
|
227
|
+
/** Its zone, `+HHMM` (default the local zone at `time`) */
|
|
228
|
+
tzOffset?: string;
|
|
229
|
+
/**
|
|
230
|
+
* The file's mode, as git's `canon_mode` of the `--contents` file's stat or the working
|
|
231
|
+
* tree file's lstat (`120000` for a link, whose content is its target); default, as for
|
|
232
|
+
* standard input, the index entry's mode at the path, else `100644`
|
|
233
|
+
*/
|
|
234
|
+
mode?: number;
|
|
235
|
+
/**
|
|
236
|
+
* The file's bytes as read, before the clean filters made `content` of them: what a
|
|
237
|
+
* textconv converts (git converts the file as it lies, then cleans the output with the
|
|
238
|
+
* blamed path's attributes); default `content`. Standard input (`name` `-`) is never
|
|
239
|
+
* converted.
|
|
240
|
+
*/
|
|
241
|
+
file?: Uint8Array;
|
|
242
|
+
}
|
|
243
|
+
|
|
140
244
|
/** A version of the file in a commit (`struct blame_origin`) */
|
|
141
245
|
interface Origin {
|
|
246
|
+
/** Creation order: stands for the pointer order git sorts suspects by (`compare_blame_suspect`) */
|
|
247
|
+
seq: number;
|
|
142
248
|
commitId: ObjectId;
|
|
143
249
|
path: string;
|
|
144
250
|
blobId: ObjectId;
|
|
@@ -149,8 +255,12 @@ interface Origin {
|
|
|
149
255
|
guilty: boolean;
|
|
150
256
|
/** The next origin of the same commit */
|
|
151
257
|
next: Origin | null;
|
|
258
|
+
/** The previous origin of the same commit (the list is doubly linked to move one in O(1)) */
|
|
259
|
+
prev: Origin | null;
|
|
152
260
|
/** The blob's lines (split and hashed once), while the origin is compared */
|
|
153
261
|
lines?: InternedText;
|
|
262
|
+
/** The lines' fingerprints, while an ignored commit's origin passes blame */
|
|
263
|
+
fingerprints?: Fingerprint[];
|
|
154
264
|
}
|
|
155
265
|
|
|
156
266
|
/** A run of lines (`struct blame_entry`), 0-based */
|
|
@@ -162,6 +272,10 @@ interface Entry {
|
|
|
162
272
|
/** First line in the suspect's file */
|
|
163
273
|
sLno: number;
|
|
164
274
|
numLines: number;
|
|
275
|
+
/** Blamed on a parent of an ignored commit by resemblance */
|
|
276
|
+
ignored: boolean;
|
|
277
|
+
/** Changed by an ignored commit and like no line of its parent */
|
|
278
|
+
unblamable: boolean;
|
|
165
279
|
}
|
|
166
280
|
|
|
167
281
|
/** Something with a `next` link: a list head or an entry (`struct blame_entry **`) */
|
|
@@ -172,13 +286,46 @@ interface Slot {
|
|
|
172
286
|
interface CommitState {
|
|
173
287
|
commit: Commit;
|
|
174
288
|
origins: Origin | null;
|
|
289
|
+
/** The origins by path (git's list is searched linearly; `-C -C -C` makes it long) */
|
|
290
|
+
originsByPath: Map<string, Origin>;
|
|
175
291
|
uninteresting: boolean;
|
|
176
292
|
}
|
|
177
293
|
|
|
178
294
|
const S_IFMT = 0o170000;
|
|
179
295
|
const TREE_MODE = 0o040000;
|
|
296
|
+
const GITLINK_MODE = 0o160000;
|
|
297
|
+
/** blame.h's `BLAME_DEFAULT_MOVE_SCORE` and `BLAME_DEFAULT_COPY_SCORE` */
|
|
298
|
+
const BLAME_DEFAULT_MOVE_SCORE = 20;
|
|
299
|
+
const BLAME_DEFAULT_COPY_SCORE = 40;
|
|
180
300
|
const INT_MAX = Number.MAX_SAFE_INTEGER;
|
|
181
301
|
|
|
302
|
+
/** Whether any line hash is among `wanted` */
|
|
303
|
+
function sharesLine(hashes: Int32Array, wanted: Set<number>): boolean {
|
|
304
|
+
for (let i = 0; i < hashes.length; i++) if (wanted.has(hashes[i])) return true;
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** An origin moved to the front of its commit's list (`get_origin` finding it) */
|
|
309
|
+
function moveOriginToFront(st: CommitState, o: Origin): void {
|
|
310
|
+
if (!o.prev) return;
|
|
311
|
+
o.prev.next = o.next;
|
|
312
|
+
if (o.next) o.next.prev = o.prev;
|
|
313
|
+
o.prev = null;
|
|
314
|
+
o.next = st.origins;
|
|
315
|
+
if (st.origins) st.origins.prev = o;
|
|
316
|
+
st.origins = o;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** An origin no entry refers to taken off its commit's list (`blame_origin_decref` freeing it) */
|
|
320
|
+
function unlinkOrigin(st: CommitState, o: Origin): void {
|
|
321
|
+
if (o.prev) o.prev.next = o.next;
|
|
322
|
+
else if (st.origins === o) st.origins = o.next;
|
|
323
|
+
if (o.next) o.next.prev = o.prev;
|
|
324
|
+
o.prev = null;
|
|
325
|
+
o.next = null;
|
|
326
|
+
if (st.originsByPath.get(o.path) === o) st.originsByPath.delete(o.path);
|
|
327
|
+
}
|
|
328
|
+
|
|
182
329
|
/** `reverse_blame`: `head` reversed, ending in `tail` */
|
|
183
330
|
function reverseBlame(head: Entry | null, tail: Entry | null): Entry | null {
|
|
184
331
|
let h = head;
|
|
@@ -223,20 +370,136 @@ function splitBlameAt(e: Entry, len: number, suspect: Origin): Entry {
|
|
|
223
370
|
lno: e.lno + len,
|
|
224
371
|
sLno: e.sLno + len,
|
|
225
372
|
numLines: e.numLines - len,
|
|
373
|
+
ignored: e.ignored,
|
|
374
|
+
unblamable: e.unblamable,
|
|
226
375
|
};
|
|
227
376
|
e.numLines = len;
|
|
228
377
|
return n;
|
|
229
378
|
}
|
|
230
379
|
|
|
231
|
-
/**
|
|
380
|
+
/** One part of a split entry (the on-stack `struct blame_entry` of `split_overlap`) */
|
|
381
|
+
interface Part {
|
|
382
|
+
suspect: Origin | null;
|
|
383
|
+
lno: number;
|
|
384
|
+
sLno: number;
|
|
385
|
+
numLines: number;
|
|
386
|
+
ignored: boolean;
|
|
387
|
+
unblamable: boolean;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** `struct blame_entry split[3]`: before the chunk, the chunk the parent takes, after it */
|
|
391
|
+
type Split = [Part, Part, Part];
|
|
392
|
+
|
|
393
|
+
const emptyPart = (e?: Entry): Part => ({
|
|
394
|
+
suspect: null,
|
|
395
|
+
lno: 0,
|
|
396
|
+
sLno: 0,
|
|
397
|
+
numLines: 0,
|
|
398
|
+
ignored: e?.ignored ?? false,
|
|
399
|
+
unblamable: e?.unblamable ?? false,
|
|
400
|
+
});
|
|
401
|
+
const emptySplit = (e?: Entry): Split => [emptyPart(e), emptyPart(e), emptyPart(e)];
|
|
402
|
+
|
|
403
|
+
/** A queue appended at its tail (`struct blame_entry ***`); the tail's `next` is set at the end */
|
|
404
|
+
interface Queue {
|
|
405
|
+
tail: Slot;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** git's `split_overlap`: `e` cut where `[tlno, same)` (its suspect's lines) came from `parent` */
|
|
409
|
+
function splitOverlap(e: Entry, tlno: number, plno: number, same: number, parent: Origin): Split {
|
|
410
|
+
const split = emptySplit(e);
|
|
411
|
+
let chunkEnd: number;
|
|
412
|
+
if (e.sLno < tlno) {
|
|
413
|
+
// a part before the chunk, not blamed on the parent
|
|
414
|
+
split[0] = {
|
|
415
|
+
suspect: e.suspect,
|
|
416
|
+
lno: e.lno,
|
|
417
|
+
sLno: e.sLno,
|
|
418
|
+
numLines: tlno - e.sLno,
|
|
419
|
+
ignored: e.ignored,
|
|
420
|
+
unblamable: e.unblamable,
|
|
421
|
+
};
|
|
422
|
+
split[1].lno = e.lno + tlno - e.sLno;
|
|
423
|
+
split[1].sLno = plno;
|
|
424
|
+
} else {
|
|
425
|
+
split[1].lno = e.lno;
|
|
426
|
+
split[1].sLno = plno + (e.sLno - tlno);
|
|
427
|
+
}
|
|
428
|
+
if (same < e.sLno + e.numLines) {
|
|
429
|
+
// a part after the chunk, not blamed on the parent
|
|
430
|
+
split[2] = {
|
|
431
|
+
suspect: e.suspect,
|
|
432
|
+
lno: e.lno + (same - e.sLno),
|
|
433
|
+
sLno: same,
|
|
434
|
+
numLines: e.sLno + e.numLines - same,
|
|
435
|
+
ignored: e.ignored,
|
|
436
|
+
unblamable: e.unblamable,
|
|
437
|
+
};
|
|
438
|
+
chunkEnd = split[2].lno;
|
|
439
|
+
} else chunkEnd = e.lno + e.numLines;
|
|
440
|
+
split[1].numLines = chunkEnd - split[1].lno;
|
|
441
|
+
if (split[1].numLines >= 1) split[1].suspect = parent;
|
|
442
|
+
return split;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** git's `add_blame_entry`: a new entry from `src` appended */
|
|
446
|
+
function addBlameEntry(queue: Queue, src: Part): void {
|
|
447
|
+
const e: Entry = {
|
|
448
|
+
next: null,
|
|
449
|
+
suspect: src.suspect as Origin,
|
|
450
|
+
lno: src.lno,
|
|
451
|
+
sLno: src.sLno,
|
|
452
|
+
numLines: src.numLines,
|
|
453
|
+
ignored: src.ignored,
|
|
454
|
+
unblamable: src.unblamable,
|
|
455
|
+
};
|
|
456
|
+
queue.tail.next = e;
|
|
457
|
+
queue.tail = e;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** git's `dup_entry`: `dst` takes `src`'s place and is appended */
|
|
461
|
+
function dupEntry(queue: Queue, dst: Entry, src: Part): void {
|
|
462
|
+
dst.suspect = src.suspect as Origin;
|
|
463
|
+
dst.lno = src.lno;
|
|
464
|
+
dst.sLno = src.sLno;
|
|
465
|
+
dst.numLines = src.numLines;
|
|
466
|
+
dst.ignored = src.ignored;
|
|
467
|
+
dst.unblamable = src.unblamable;
|
|
468
|
+
queue.tail.next = dst;
|
|
469
|
+
queue.tail = dst;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** git's `split_blame`: the parts of `e` queued to the parent's (`blamed`) and its own lists */
|
|
473
|
+
function splitBlame(blamed: Queue, unblamed: Queue, split: Split, e: Entry): void {
|
|
474
|
+
if (split[0].suspect && split[2].suspect) {
|
|
475
|
+
dupEntry(unblamed, e, split[0]);
|
|
476
|
+
addBlameEntry(unblamed, split[2]);
|
|
477
|
+
addBlameEntry(blamed, split[1]);
|
|
478
|
+
} else if (!split[0].suspect && !split[2].suspect) {
|
|
479
|
+
dupEntry(blamed, e, split[1]);
|
|
480
|
+
} else if (split[0].suspect) {
|
|
481
|
+
dupEntry(unblamed, e, split[0]);
|
|
482
|
+
addBlameEntry(blamed, split[1]);
|
|
483
|
+
} else {
|
|
484
|
+
dupEntry(blamed, e, split[1]);
|
|
485
|
+
addBlameEntry(unblamed, split[2]);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* A priority queue of commits: newest committer date first (oldest first in reverse, as
|
|
491
|
+
* `compare_commits_by_reverse_commit_date`), ties first in, first out
|
|
492
|
+
*/
|
|
232
493
|
class CommitQueue {
|
|
233
494
|
private heap: Array<{ id: ObjectId; date: number; ctr: number }> = [];
|
|
234
495
|
private ctr = 0;
|
|
235
496
|
|
|
497
|
+
constructor(private readonly reverse = false) {}
|
|
498
|
+
|
|
236
499
|
private less(i: number, j: number): boolean {
|
|
237
500
|
const a = this.heap[i];
|
|
238
501
|
const b = this.heap[j];
|
|
239
|
-
if (a.date !== b.date) return a.date > b.date;
|
|
502
|
+
if (a.date !== b.date) return this.reverse ? a.date < b.date : a.date > b.date;
|
|
240
503
|
return a.ctr < b.ctr;
|
|
241
504
|
}
|
|
242
505
|
|
|
@@ -252,6 +515,16 @@ class CommitQueue {
|
|
|
252
515
|
}
|
|
253
516
|
}
|
|
254
517
|
|
|
518
|
+
/** The ids queued, in no particular order */
|
|
519
|
+
ids(): ObjectId[] {
|
|
520
|
+
return this.heap.map((e) => e.id);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** The date of the commit `get` returns next */
|
|
524
|
+
peekDate(): number | undefined {
|
|
525
|
+
return this.heap[0]?.date;
|
|
526
|
+
}
|
|
527
|
+
|
|
255
528
|
get(): ObjectId | undefined {
|
|
256
529
|
const h = this.heap;
|
|
257
530
|
if (h.length === 0) return undefined;
|
|
@@ -286,8 +559,14 @@ class CommitQueue {
|
|
|
286
559
|
* are its own. A parent with the same blob takes all lines. Root commits are boundaries
|
|
287
560
|
* unless `setShowRoot(true)` (`blame.showRoot`).
|
|
288
561
|
*
|
|
289
|
-
*
|
|
290
|
-
* are
|
|
562
|
+
* Lines moved within the file (`-M`, `setDetectMoves`) and copied from other files (`-C` up
|
|
563
|
+
* to three times, `setDetectCopies`) are found as git's `find_move_in_parent` and
|
|
564
|
+
* `find_copy_in_parent` find them, and names and emails go through the mailmap
|
|
565
|
+
* (`setUseMailmap`). Ignored revisions (`setIgnoreRevs`, `setIgnoreRevsFiles`,
|
|
566
|
+
* `blame.ignoreRevsFile`) pass their changed lines to the parent lines they resemble, by
|
|
567
|
+
* git's fingerprint matching (`guess_line_blames`); `setReverse` blames each line of an old
|
|
568
|
+
* version on the last commit it existed in (`--reverse`), and `setFirstParent` follows
|
|
569
|
+
* first parents only.
|
|
291
570
|
*
|
|
292
571
|
* @example
|
|
293
572
|
* ```typescript
|
|
@@ -314,8 +593,67 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
314
593
|
private lineRanges: Array<[number, number]> = [];
|
|
315
594
|
private diffOptions: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> = {};
|
|
316
595
|
private renameCountLastSpan?: boolean;
|
|
596
|
+
/** `-M`: look for lines moved within the file (`PICKAXE_BLAME_MOVE`) */
|
|
597
|
+
private detectMoves = false;
|
|
598
|
+
/** `-C` given this many times (`PICKAXE_BLAME_COPY`, `_HARDER`, `_HARDEST`) */
|
|
599
|
+
private copyLevel = 0;
|
|
600
|
+
private moveScore = BLAME_DEFAULT_MOVE_SCORE;
|
|
601
|
+
private copyScore = BLAME_DEFAULT_COPY_SCORE;
|
|
602
|
+
private useMailmap = true;
|
|
603
|
+
private ignoreRevs: string[] = [];
|
|
604
|
+
private ignoreRevsFiles: string[] = [];
|
|
605
|
+
private markIgnoredLines?: boolean;
|
|
606
|
+
private markUnblamableLines?: boolean;
|
|
607
|
+
/** `:(optional)` paths in the configuration (git 2.52+) */
|
|
608
|
+
private optionalPaths = true;
|
|
609
|
+
/** `--reverse`: the commit whose lines are followed forward */
|
|
610
|
+
private reverseFrom?: ObjectId;
|
|
611
|
+
private firstParent = false;
|
|
612
|
+
/** `--textconv` / `--no-textconv` (git's blame converts by default) */
|
|
613
|
+
private textconv = true;
|
|
614
|
+
/** The diff command whose textconv (and its caches) blame's reads go through */
|
|
615
|
+
private textconvDiff?: DiffCommand;
|
|
616
|
+
/** The buffer blamed instead of the start commit's file (`--contents`) */
|
|
617
|
+
private contents?: { content: Uint8Array } & BlameContentsOptions;
|
|
618
|
+
/** Commits older than this (committer time, seconds) are boundaries (`--since`) */
|
|
619
|
+
private since?: number;
|
|
620
|
+
/** Commits `--since` marked uninteresting before they were loaded */
|
|
621
|
+
private sinceUninteresting = new Set<ObjectId>();
|
|
622
|
+
/** Blobs that exist only here (the `--contents` buffer: git's `odb_pretend_object`) */
|
|
623
|
+
private pretend = new Map<ObjectId, Uint8Array>();
|
|
624
|
+
/** The entries in the order they were found guilty (`--incremental`) */
|
|
625
|
+
private guilty: Array<{ entry: Entry; origin: Origin; boundary: boolean }> = [];
|
|
626
|
+
/** The commits blamed lines pass to from each commit in reverse (`revs->children`) */
|
|
627
|
+
private children = new Map<ObjectId, ObjectId[]>();
|
|
628
|
+
/** The commits the reverse walk found uninteresting (boundaries) */
|
|
629
|
+
private reverseUninteresting = new Set<ObjectId>();
|
|
630
|
+
/** The commits whose changes are ignored (`sb->ignore_list`) */
|
|
631
|
+
private ignoreList = new Set<ObjectId>();
|
|
632
|
+
|
|
633
|
+
/** The blamed file at the start commit, its line starts and alphanumerics before each line */
|
|
634
|
+
private finalContent: Uint8Array = new Uint8Array(0);
|
|
635
|
+
private finalStarts: Int32Array = new Int32Array(1);
|
|
636
|
+
private finalAlnum: Int32Array = new Int32Array(1);
|
|
637
|
+
private originSeq = 0;
|
|
638
|
+
/**
|
|
639
|
+
* Files looked in for copies, interned, the most recently used last (`copySourceText`),
|
|
640
|
+
* by `copyKey`
|
|
641
|
+
*/
|
|
642
|
+
private copySources = new Map<string, InternedText>();
|
|
643
|
+
private copySourceBytes = 0;
|
|
644
|
+
/** Line hashes of the files looked in for copies (null: over the big file threshold) */
|
|
645
|
+
private copyHashes = new Map<string, Int32Array | null>();
|
|
646
|
+
private copyHashBytes = 0;
|
|
647
|
+
private copyHashCacheBytes = COPY_HASH_CACHE_BYTES;
|
|
648
|
+
private copySourceCacheBytes = COPY_SOURCE_CACHE_BYTES;
|
|
649
|
+
/** The hash of each line of the final file (`lineHashesOf`) */
|
|
650
|
+
private finalHashes: Int32Array = new Int32Array(0);
|
|
317
651
|
|
|
318
652
|
private states = new Map<ObjectId, CommitState>();
|
|
653
|
+
/** The `--contents` buffer's blob and mode */
|
|
654
|
+
private fakeEntry?: { id: ObjectId; mode: number };
|
|
655
|
+
/** The index's files with the `--contents` buffer at its path (the fake commit's "tree") */
|
|
656
|
+
private fakeFiles?: Map<string, { id: ObjectId; mode: number }>;
|
|
319
657
|
/** Numbers the lines of every version compared, so each is split and hashed once */
|
|
320
658
|
private interner?: LineInterner;
|
|
321
659
|
|
|
@@ -410,19 +748,162 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
410
748
|
}
|
|
411
749
|
|
|
412
750
|
/**
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
751
|
+
* Find lines moved or copied within the file (`-M[<num>]`): lines a commit moved are blamed
|
|
752
|
+
* on the commit that wrote them. A block is taken when it has more than `score`
|
|
753
|
+
* alphanumeric characters (default 20; 0 keeps the default, as git's).
|
|
754
|
+
*/
|
|
755
|
+
setDetectMoves(detect: boolean, score?: number): this {
|
|
756
|
+
this.checkCallable();
|
|
757
|
+
this.detectMoves = detect;
|
|
758
|
+
if (score) this.moveScore = score;
|
|
759
|
+
return this;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* Find lines copied from other files (`-C[<num>]` given `level` times; any level also
|
|
764
|
+
* finds moves): 1 looks in the files the commit changed, 2 also in every file of the parent
|
|
765
|
+
* when the blamed file was created or renamed, 3 in every file of the parent always. A block
|
|
766
|
+
* is taken when it has more than `score` alphanumeric characters (default 40; 0 keeps the
|
|
767
|
+
* default).
|
|
768
|
+
*/
|
|
769
|
+
setDetectCopies(level: number, score?: number): this {
|
|
770
|
+
this.checkCallable();
|
|
771
|
+
this.copyLevel = Math.max(0, Math.min(3, Math.floor(level)));
|
|
772
|
+
if (this.copyLevel > 0) this.detectMoves = true;
|
|
773
|
+
if (score) this.copyScore = score;
|
|
774
|
+
return this;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Map the names and emails of authors and committers through the mailmap (`.mailmap`,
|
|
779
|
+
* `mailmap.blob`, `mailmap.file`), as git blame always does (default true). The entries'
|
|
780
|
+
* commits then carry the mapped identities.
|
|
781
|
+
*/
|
|
782
|
+
setUseMailmap(use: boolean): this {
|
|
783
|
+
this.checkCallable();
|
|
784
|
+
this.useMailmap = use;
|
|
785
|
+
return this;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Ignore the changes these revisions made (`--ignore-rev <rev>`, each peeled to a commit):
|
|
790
|
+
* their lines are blamed on the lines of their parents they resemble most (git's fuzzy
|
|
791
|
+
* matching), or stay theirs (unblamable) when none does.
|
|
792
|
+
*
|
|
793
|
+
* @throws Error `cannot find revision <rev> to ignore` when a name gives no commit
|
|
794
|
+
*/
|
|
795
|
+
setIgnoreRevs(revs: string[]): this {
|
|
796
|
+
this.checkCallable();
|
|
797
|
+
this.ignoreRevs = [...revs];
|
|
798
|
+
return this;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Ignore the revisions listed in these files (`--ignore-revs-file <file>`, read after
|
|
803
|
+
* `blame.ignoreRevsFile`): full object ids, one per line, `#` comments; an empty name
|
|
804
|
+
* forgets the files before it. A relative path is read from the worktree's top.
|
|
805
|
+
*
|
|
806
|
+
* @throws Error `could not open object name list: <file>`, `invalid object name: <line>`
|
|
807
|
+
*/
|
|
808
|
+
setIgnoreRevsFiles(files: string[]): this {
|
|
809
|
+
this.checkCallable();
|
|
810
|
+
this.ignoreRevsFiles = [...files];
|
|
811
|
+
return this;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/** Mark lines blamed through an ignored commit (`?`; default `blame.markIgnoredLines`) */
|
|
815
|
+
setMarkIgnoredLines(mark: boolean): this {
|
|
816
|
+
this.checkCallable();
|
|
817
|
+
this.markIgnoredLines = mark;
|
|
818
|
+
return this;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/** Mark lines an ignored commit keeps (`*`; default `blame.markUnblamableLines`) */
|
|
822
|
+
setMarkUnblamableLines(mark: boolean): this {
|
|
823
|
+
this.checkCallable();
|
|
824
|
+
this.markUnblamableLines = mark;
|
|
825
|
+
return this;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Blame in reverse (`--reverse <from>..<start>`): the lines of the file at `from`, each
|
|
830
|
+
* blamed on the last commit up to the start commit (default HEAD) it still existed in.
|
|
831
|
+
*/
|
|
832
|
+
setReverse(from: ObjectId): this {
|
|
833
|
+
from = canonicalObjectId(from);
|
|
834
|
+
this.checkCallable();
|
|
835
|
+
this.reverseFrom = from;
|
|
836
|
+
return this;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Follow only first parents (`--first-parent`); with `setReverse`, the range must lie on
|
|
841
|
+
* the start commit's first-parent chain.
|
|
842
|
+
*/
|
|
843
|
+
setFirstParent(first: boolean): this {
|
|
844
|
+
this.checkCallable();
|
|
845
|
+
this.firstParent = first;
|
|
846
|
+
return this;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Blame a buffer instead of the start commit's file (`--contents <file>`): git's fake
|
|
851
|
+
* commit on top of the start commit (default HEAD) and the commits `MERGE_HEAD` names,
|
|
852
|
+
* with null id, holding `content` at the blamed path of the index. Its lines are blamed on
|
|
853
|
+
* "External file (--contents)" where the parents' file differs (`workingTree`: "Not
|
|
854
|
+
* Committed Yet", as `git blame <path>` blames the working tree's file); a path only the
|
|
855
|
+
* index has is all its own, a rename staged in the index is followed. The content is taken
|
|
856
|
+
* as git stores it (no clean filters).
|
|
857
|
+
*
|
|
858
|
+
* @throws Error `--contents and --reverse do not blend well.` with `setReverse`, and
|
|
859
|
+
* `no such path '<path>' in HEAD` when neither a parent nor the index has the path
|
|
860
|
+
*/
|
|
861
|
+
setContents(content: Uint8Array, options: BlameContentsOptions = {}): this {
|
|
862
|
+
this.checkCallable();
|
|
863
|
+
this.contents = { ...options, content };
|
|
864
|
+
return this;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* `--textconv` (the default) / `--no-textconv`: every version of a regular file is read
|
|
869
|
+
* through its `diff.<driver>.textconv` (blame.c's textconv_object, with the runner the
|
|
870
|
+
* host installed, `installTextconvRunner`), a blob through the driver's notes cache
|
|
871
|
+
* (`diff.<driver>.cachetextconv`); the `--contents` file too, unless read from standard
|
|
872
|
+
* input, without the cache.
|
|
873
|
+
*/
|
|
874
|
+
setTextconv(on: boolean): this {
|
|
875
|
+
this.checkCallable();
|
|
876
|
+
this.textconv = on;
|
|
877
|
+
return this;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Stop at commits older than `timestamp` (seconds, committer time; `--since`): they and
|
|
882
|
+
* their ancestors are boundaries, as git's `revs->max_age`
|
|
883
|
+
*/
|
|
884
|
+
setSince(timestamp: number): this {
|
|
885
|
+
this.checkCallable();
|
|
886
|
+
this.since = timestamp;
|
|
887
|
+
return this;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Details that changed between git versions: `histogramRediff` (git 2.54+, default
|
|
892
|
+
* true), `legacyMinimal` (git before 2.5x), `renameCountLastSpan` (rename scores of
|
|
893
|
+
* git 2.50+, default true) and `optionalPaths` (a `blame.ignoreRevsFile` of
|
|
894
|
+
* `:(optional)<path>` naming a missing file is skipped: git 2.52+, default true)
|
|
416
895
|
*/
|
|
417
896
|
setCompatibility(
|
|
418
897
|
options: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> & {
|
|
419
898
|
renameCountLastSpan?: boolean;
|
|
899
|
+
optionalPaths?: boolean;
|
|
420
900
|
},
|
|
421
901
|
): this {
|
|
422
902
|
this.checkCallable();
|
|
423
|
-
const { renameCountLastSpan, ...diff } = options;
|
|
903
|
+
const { renameCountLastSpan, optionalPaths, ...diff } = options;
|
|
424
904
|
this.diffOptions = { ...this.diffOptions, ...diff };
|
|
425
905
|
if (renameCountLastSpan !== undefined) this.renameCountLastSpan = renameCountLastSpan;
|
|
906
|
+
if (optionalPaths !== undefined) this.optionalPaths = optionalPaths;
|
|
426
907
|
return this;
|
|
427
908
|
}
|
|
428
909
|
|
|
@@ -456,6 +937,20 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
456
937
|
return this;
|
|
457
938
|
}
|
|
458
939
|
|
|
940
|
+
/**
|
|
941
|
+
* Set how many bytes the caches of `-C` keep between commits (default 32 MiB of line hashes
|
|
942
|
+
* of the files looked in, 16 MiB of their contents): a file not kept is read again for the
|
|
943
|
+
* next commit, as git reads it. The output does not change.
|
|
944
|
+
*
|
|
945
|
+
* @param bytes Size in bytes
|
|
946
|
+
*/
|
|
947
|
+
setCopyCacheByteLimit(bytes: number): this {
|
|
948
|
+
this.checkCallable();
|
|
949
|
+
this.copyHashCacheBytes = bytes;
|
|
950
|
+
this.copySourceCacheBytes = bytes;
|
|
951
|
+
return this;
|
|
952
|
+
}
|
|
953
|
+
|
|
459
954
|
/**
|
|
460
955
|
* Execute the blame command.
|
|
461
956
|
*
|
|
@@ -472,27 +967,40 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
472
967
|
this.algorithm ??= algorithmValue(config.value("diff.algorithm")) ?? "myers";
|
|
473
968
|
this.indentHeuristic ??= boolValue(config.value("diff.indentHeuristic")) ?? true;
|
|
474
969
|
this.showRoot ??= boolValue(config.value("blame.showRoot")) ?? false;
|
|
970
|
+
this.markIgnoredLines ??= boolValue(config.value("blame.markIgnoredLines")) ?? false;
|
|
971
|
+
this.markUnblamableLines ??= boolValue(config.value("blame.markUnblamableLines")) ?? false;
|
|
972
|
+
await this.buildIgnoreList(config);
|
|
475
973
|
|
|
974
|
+
if (this.contents && this.reverseFrom !== undefined) {
|
|
975
|
+
throw new Error("--contents and --reverse do not blend well.");
|
|
976
|
+
}
|
|
476
977
|
let startId = this.startCommit;
|
|
477
978
|
if (!startId) {
|
|
478
979
|
const head = await this.refsStore.resolve("HEAD");
|
|
479
980
|
if (!head?.objectId) {
|
|
480
|
-
throw new Error("
|
|
981
|
+
if (this.contents) throw new Error("no such ref: HEAD");
|
|
982
|
+
throw new Error(this.reverseFrom ? "No commit to dig up from?" : "No HEAD commit found");
|
|
481
983
|
}
|
|
482
984
|
startId = head.objectId;
|
|
483
985
|
}
|
|
986
|
+
if (this.reverseFrom !== undefined) {
|
|
987
|
+
// --reverse <from>..<start>: the lines of <from>, followed forward to <start>
|
|
988
|
+
await this.prepareReverse(this.reverseFrom, startId);
|
|
989
|
+
startId = this.reverseFrom;
|
|
990
|
+
}
|
|
484
991
|
|
|
485
992
|
const resultPath = this.filePath;
|
|
993
|
+
if (this.contents) startId = await this.fakeWorkingTreeCommit(startId, resultPath);
|
|
486
994
|
const start = await this.state(startId);
|
|
487
995
|
if (!start) {
|
|
488
996
|
throw new RefNotFoundError(`Cannot find commit: ${startId}`);
|
|
489
997
|
}
|
|
490
|
-
const entry = await this.lookup(start.commit.tree, resultPath);
|
|
998
|
+
const entry = this.contents ? this.fakeEntry : await this.lookup(start.commit.tree, resultPath);
|
|
491
999
|
if (!entry) {
|
|
492
1000
|
throw new Error(`File not found: ${resultPath}`);
|
|
493
1001
|
}
|
|
494
|
-
const size = await this.
|
|
495
|
-
if (size > this.bigFileThreshold) {
|
|
1002
|
+
const size = await this.blobSize(entry.id);
|
|
1003
|
+
if (!this.contents && size > this.bigFileThreshold) {
|
|
496
1004
|
throw new Error(
|
|
497
1005
|
`${resultPath} is ${size} bytes, larger than bigFileThreshold (${this.bigFileThreshold})`,
|
|
498
1006
|
);
|
|
@@ -500,21 +1008,30 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
500
1008
|
const finalOrigin = this.getOrigin(startId, resultPath);
|
|
501
1009
|
finalOrigin.blobId = entry.id;
|
|
502
1010
|
finalOrigin.mode = entry.mode;
|
|
503
|
-
const content = await this.
|
|
1011
|
+
const content = await this.originBlob(entry.id, resultPath, entry.mode);
|
|
504
1012
|
finalOrigin.lines = this.lineInterner().text(content);
|
|
505
1013
|
const lineCount = countLines(content);
|
|
1014
|
+
if (this.detectMoves || this.copyLevel > 0) this.prepareLines(content, lineCount);
|
|
506
1015
|
|
|
507
1016
|
// the initial entries: the whole file, or the -L ranges (sorted and merged)
|
|
508
1017
|
const ranges = this.ranges(lineCount);
|
|
509
1018
|
let head: Entry | null = null;
|
|
510
1019
|
for (let i = ranges.length - 1; i >= 0; i--) {
|
|
511
1020
|
const [s, e] = ranges[i];
|
|
512
|
-
head = {
|
|
1021
|
+
head = {
|
|
1022
|
+
next: head,
|
|
1023
|
+
suspect: finalOrigin,
|
|
1024
|
+
lno: s,
|
|
1025
|
+
sLno: s,
|
|
1026
|
+
numLines: e - s,
|
|
1027
|
+
ignored: false,
|
|
1028
|
+
unblamable: false,
|
|
1029
|
+
};
|
|
513
1030
|
}
|
|
514
1031
|
const final: Slot = { next: null };
|
|
515
1032
|
if (head) {
|
|
516
1033
|
finalOrigin.suspects = head;
|
|
517
|
-
const queue = new CommitQueue();
|
|
1034
|
+
const queue = new CommitQueue(this.reverseFrom !== undefined);
|
|
518
1035
|
queue.put(startId, start.commit.committer.timestamp);
|
|
519
1036
|
await this.assignBlame(queue, final);
|
|
520
1037
|
}
|
|
@@ -530,19 +1047,37 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
530
1047
|
last &&
|
|
531
1048
|
last.suspect === e.suspect &&
|
|
532
1049
|
last.sLno + last.numLines === e.sLno &&
|
|
533
|
-
last.lno + last.numLines === e.lno
|
|
1050
|
+
last.lno + last.numLines === e.lno &&
|
|
1051
|
+
last.ignored === e.ignored &&
|
|
1052
|
+
last.unblamable === e.unblamable
|
|
534
1053
|
) {
|
|
535
1054
|
last.numLines += e.numLines;
|
|
536
1055
|
} else coalesced.push({ ...e });
|
|
537
1056
|
}
|
|
538
1057
|
|
|
1058
|
+
const mailmap = this.useMailmap ? await this.loadMailmap() : undefined;
|
|
1059
|
+
const mapped = new Map<ObjectId, Commit>();
|
|
1060
|
+
const commitOf = (st: CommitState, id: ObjectId): Commit => {
|
|
1061
|
+
if (!mailmap || mailmap.empty) return st.commit;
|
|
1062
|
+
let c = mapped.get(id);
|
|
1063
|
+
if (!c) {
|
|
1064
|
+
const author = mapIdent(mailmap, st.commit.author);
|
|
1065
|
+
const committer = mapIdent(mailmap, st.commit.committer);
|
|
1066
|
+
c =
|
|
1067
|
+
author === st.commit.author && committer === st.commit.committer
|
|
1068
|
+
? st.commit
|
|
1069
|
+
: { ...st.commit, author, committer };
|
|
1070
|
+
mapped.set(id, c);
|
|
1071
|
+
}
|
|
1072
|
+
return c;
|
|
1073
|
+
};
|
|
539
1074
|
const entries: BlameEntry[] = [];
|
|
540
1075
|
for (const e of coalesced) {
|
|
541
1076
|
const st = this.states.get(e.suspect.commitId);
|
|
542
1077
|
if (!st) continue;
|
|
543
1078
|
const prev = e.suspect.previous;
|
|
544
1079
|
entries.push({
|
|
545
|
-
commit: st.
|
|
1080
|
+
commit: commitOf(st, e.suspect.commitId),
|
|
546
1081
|
commitId: e.suspect.commitId,
|
|
547
1082
|
sourcePath: e.suspect.path,
|
|
548
1083
|
sourceStart: e.sLno + 1,
|
|
@@ -550,9 +1085,30 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
550
1085
|
lineCount: e.numLines,
|
|
551
1086
|
...(prev ? { previous: { commitId: prev.commitId, path: prev.path } } : {}),
|
|
552
1087
|
boundary: st.uninteresting,
|
|
1088
|
+
...(e.ignored ? { ignored: true } : {}),
|
|
1089
|
+
...(e.unblamable ? { unblamable: true } : {}),
|
|
553
1090
|
});
|
|
554
1091
|
}
|
|
555
1092
|
const result = createBlameResult(resultPath, lineCount, entries, content);
|
|
1093
|
+
result.incremental = [];
|
|
1094
|
+
for (const g of this.guilty) {
|
|
1095
|
+
const st = this.states.get(g.origin.commitId);
|
|
1096
|
+
if (!st) continue;
|
|
1097
|
+
const prev = g.origin.previous;
|
|
1098
|
+
result.incremental.push({
|
|
1099
|
+
commit: commitOf(st, g.origin.commitId),
|
|
1100
|
+
commitId: g.origin.commitId,
|
|
1101
|
+
sourcePath: g.origin.path,
|
|
1102
|
+
sourceStart: g.entry.sLno + 1,
|
|
1103
|
+
resultStart: g.entry.lno + 1,
|
|
1104
|
+
lineCount: g.entry.numLines,
|
|
1105
|
+
...(prev ? { previous: { commitId: prev.commitId, path: prev.path } } : {}),
|
|
1106
|
+
boundary: g.boundary,
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
result.output = blameOutputConfig(config);
|
|
1110
|
+
result.markIgnoredLines = this.markIgnoredLines;
|
|
1111
|
+
result.markUnblamableLines = this.markUnblamableLines;
|
|
556
1112
|
const workingCopy = this.workingCopy;
|
|
557
1113
|
result.autoAbbrev = async () => {
|
|
558
1114
|
const lengths = await abbrevLengths(
|
|
@@ -564,6 +1120,187 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
564
1120
|
return result;
|
|
565
1121
|
}
|
|
566
1122
|
|
|
1123
|
+
/** The commits a commit's lines pass to: its parents, or its children in reverse */
|
|
1124
|
+
private scapegoats(st: CommitState, commitId: ObjectId): ObjectId[] {
|
|
1125
|
+
if (this.reverseFrom !== undefined) return this.children.get(commitId) ?? [];
|
|
1126
|
+
return this.firstParent ? st.commit.parents.slice(0, 1) : st.commit.parents;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/**
|
|
1130
|
+
* builtin/blame.c's `build_ignorelist`: `blame.ignoreRevsFile` (sorted, as git inserts
|
|
1131
|
+
* them), the files given, then the revisions given
|
|
1132
|
+
*/
|
|
1133
|
+
private async buildIgnoreList(config: RemoteConfigStore): Promise<void> {
|
|
1134
|
+
const environment = hostEnvironmentOf(this.workingCopy);
|
|
1135
|
+
const worktree = this.worktreeAccess;
|
|
1136
|
+
const configured = new Set<string>();
|
|
1137
|
+
for (let value of config.values("blame.ignoreRevsFile")) {
|
|
1138
|
+
const optional = this.optionalPaths && value.startsWith(":(optional)");
|
|
1139
|
+
if (optional) value = value.slice(":(optional)".length);
|
|
1140
|
+
const path = expandUserPath(value, environment);
|
|
1141
|
+
if (path === undefined) throw new Error(`failed to expand user dir in: '${value}'`);
|
|
1142
|
+
if (optional && path && !(await readMailmapFile(path, environment, worktree))) continue;
|
|
1143
|
+
configured.add(path);
|
|
1144
|
+
}
|
|
1145
|
+
// string_list_insert keeps the configured names sorted (strcmp) and unique
|
|
1146
|
+
const files = [...[...configured].sort(compareBytes), ...this.ignoreRevsFiles];
|
|
1147
|
+
const resolver = this.revisionResolver();
|
|
1148
|
+
const peelToCommit = async (id: ObjectId) => {
|
|
1149
|
+
const peeled = await resolver.peelTags(id).catch(() => undefined);
|
|
1150
|
+
return peeled?.type === "commit" ? peeled.id : undefined;
|
|
1151
|
+
};
|
|
1152
|
+
const hexLength = this.objectFormat.hexLength;
|
|
1153
|
+
const list = this.ignoreList;
|
|
1154
|
+
for (const file of files) {
|
|
1155
|
+
if (file === "") {
|
|
1156
|
+
list.clear();
|
|
1157
|
+
continue;
|
|
1158
|
+
}
|
|
1159
|
+
const bytes = await readMailmapFile(file, environment, worktree);
|
|
1160
|
+
if (!bytes) throw new Error(`could not open object name list: ${file}`);
|
|
1161
|
+
const text = decodeGitPath(bytes);
|
|
1162
|
+
const lines = text.split("\n");
|
|
1163
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
1164
|
+
for (const raw of lines) {
|
|
1165
|
+
const hash = raw.indexOf("#");
|
|
1166
|
+
const name = (hash < 0 ? raw : raw.slice(0, hash)).replace(/^[ \t\n\r]+|[ \t\n\r]+$/g, "");
|
|
1167
|
+
if (!name) continue;
|
|
1168
|
+
if (name.length !== hexLength || !/^[0-9a-fA-F]+$/.test(name)) {
|
|
1169
|
+
throw new Error(`invalid object name: ${name}`);
|
|
1170
|
+
}
|
|
1171
|
+
const id = await peelToCommit(name.toLowerCase());
|
|
1172
|
+
if (id) list.add(id);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
for (const rev of this.ignoreRevs) {
|
|
1176
|
+
const resolved = await resolver.resolve(rev).catch(() => undefined);
|
|
1177
|
+
const id = resolved ? await peelToCommit(resolved) : undefined;
|
|
1178
|
+
if (!id) throw new Error(`cannot find revision ${rev} to ignore`);
|
|
1179
|
+
list.add(id);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
/**
|
|
1184
|
+
* The children each commit passes its lines to in `--reverse` (git's `--children` walk of
|
|
1185
|
+
* `<from>..<start>`: `limit_list` then `set_children`, or the first-parent chain)
|
|
1186
|
+
*/
|
|
1187
|
+
private async prepareReverse(from: ObjectId, to: ObjectId): Promise<void> {
|
|
1188
|
+
this.reverseUninteresting.add(from);
|
|
1189
|
+
const children = this.children;
|
|
1190
|
+
if (this.firstParent) {
|
|
1191
|
+
let c = to;
|
|
1192
|
+
for (;;) {
|
|
1193
|
+
const st = await this.state(c);
|
|
1194
|
+
if (!st) throw new RefNotFoundError(`Cannot find commit: ${c}`);
|
|
1195
|
+
if (c === from || st.commit.parents.length === 0) break;
|
|
1196
|
+
const parent = st.commit.parents[0];
|
|
1197
|
+
children.set(parent, [c]);
|
|
1198
|
+
c = parent;
|
|
1199
|
+
}
|
|
1200
|
+
if (c !== from) {
|
|
1201
|
+
throw new Error("--reverse --first-parent together require range along first-parent chain");
|
|
1202
|
+
}
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
const UNINTERESTING = 1;
|
|
1206
|
+
const SEEN = 2;
|
|
1207
|
+
const ADDED = 4;
|
|
1208
|
+
const flags = new Map<ObjectId, number>();
|
|
1209
|
+
const flag = (id: ObjectId) => flags.get(id) ?? 0;
|
|
1210
|
+
const set = (id: ObjectId, f: number) => flags.set(id, flag(id) | f);
|
|
1211
|
+
const parentsOf = (id: ObjectId) => this.states.get(id)?.commit.parents ?? [];
|
|
1212
|
+
const dateOf = (id: ObjectId) => this.states.get(id)?.commit.committer.timestamp ?? 0;
|
|
1213
|
+
const parse = async (id: ObjectId) => (await this.state(id)) !== undefined;
|
|
1214
|
+
// mark_parents_uninteresting: through the commits already parsed
|
|
1215
|
+
const markParentsUninteresting = (id: ObjectId) => {
|
|
1216
|
+
const pending = [...parentsOf(id)];
|
|
1217
|
+
while (pending.length > 0) {
|
|
1218
|
+
const p = pending.pop() as ObjectId;
|
|
1219
|
+
if (flag(p) & UNINTERESTING) continue;
|
|
1220
|
+
set(p, UNINTERESTING);
|
|
1221
|
+
if (this.states.has(p)) pending.push(...parentsOf(p));
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
// prepare_revision_walk: the pending commits (<from> first), each once, by date
|
|
1225
|
+
const starts: Array<{ id: ObjectId; uninteresting: boolean }> = [
|
|
1226
|
+
{ id: from, uninteresting: true },
|
|
1227
|
+
{ id: to, uninteresting: false },
|
|
1228
|
+
];
|
|
1229
|
+
const queue = new CommitQueue();
|
|
1230
|
+
const initial: ObjectId[] = [];
|
|
1231
|
+
for (const s of starts) {
|
|
1232
|
+
if (!(await parse(s.id))) throw new RefNotFoundError(`Cannot find commit: ${s.id}`);
|
|
1233
|
+
if (s.uninteresting) {
|
|
1234
|
+
set(s.id, UNINTERESTING);
|
|
1235
|
+
markParentsUninteresting(s.id);
|
|
1236
|
+
}
|
|
1237
|
+
if (flag(s.id) & SEEN) continue;
|
|
1238
|
+
set(s.id, SEEN);
|
|
1239
|
+
initial.push(s.id);
|
|
1240
|
+
}
|
|
1241
|
+
initial
|
|
1242
|
+
.map((id, i) => ({ id, i }))
|
|
1243
|
+
.sort((a, b) => dateOf(b.id) - dateOf(a.id) || a.i - b.i)
|
|
1244
|
+
.forEach((e) => {
|
|
1245
|
+
queue.put(e.id, dateOf(e.id));
|
|
1246
|
+
});
|
|
1247
|
+
const everybodyUninteresting = () => queue.ids().every((id) => flag(id) & UNINTERESTING);
|
|
1248
|
+
const newlist: ObjectId[] = [];
|
|
1249
|
+
let slop = 5;
|
|
1250
|
+
let date = Number.POSITIVE_INFINITY;
|
|
1251
|
+
for (let id = queue.get(); id !== undefined; id = queue.get()) {
|
|
1252
|
+
// process_parents
|
|
1253
|
+
if (!(flag(id) & ADDED)) {
|
|
1254
|
+
set(id, ADDED);
|
|
1255
|
+
if (flag(id) & UNINTERESTING) {
|
|
1256
|
+
for (const p of parentsOf(id)) {
|
|
1257
|
+
set(p, UNINTERESTING);
|
|
1258
|
+
if (!(await parse(p))) continue;
|
|
1259
|
+
markParentsUninteresting(p);
|
|
1260
|
+
if (flag(p) & SEEN) continue;
|
|
1261
|
+
set(p, SEEN);
|
|
1262
|
+
queue.put(p, dateOf(p));
|
|
1263
|
+
}
|
|
1264
|
+
} else {
|
|
1265
|
+
for (const p of parentsOf(id)) {
|
|
1266
|
+
if (!(await parse(p))) throw new RefNotFoundError(`Cannot find commit: ${p}`);
|
|
1267
|
+
if (!(flag(p) & SEEN)) {
|
|
1268
|
+
set(p, SEEN);
|
|
1269
|
+
queue.put(p, dateOf(p));
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
if (flag(id) & UNINTERESTING) {
|
|
1275
|
+
markParentsUninteresting(id);
|
|
1276
|
+
// still_interesting
|
|
1277
|
+
const next = queue.peekDate();
|
|
1278
|
+
if (next === undefined) break;
|
|
1279
|
+
if (date <= next || !everybodyUninteresting()) slop = 5;
|
|
1280
|
+
else slop--;
|
|
1281
|
+
if (slop) continue;
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
date = dateOf(id);
|
|
1285
|
+
newlist.push(id);
|
|
1286
|
+
}
|
|
1287
|
+
// set_children: each child prepended to its parents' lists
|
|
1288
|
+
for (const c of newlist) {
|
|
1289
|
+
for (const p of parentsOf(c)) {
|
|
1290
|
+
const list = children.get(p);
|
|
1291
|
+
if (list) list.unshift(c);
|
|
1292
|
+
else children.set(p, [c]);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
for (const [id, f] of flags) {
|
|
1296
|
+
if (f & UNINTERESTING) {
|
|
1297
|
+
this.reverseUninteresting.add(id);
|
|
1298
|
+
const st = this.states.get(id);
|
|
1299
|
+
if (st) st.uninteresting = true;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
|
|
567
1304
|
/** The -L ranges as 0-based half-open ranges, sorted and merged; the whole file otherwise */
|
|
568
1305
|
private ranges(lineCount: number): Array<[number, number]> {
|
|
569
1306
|
if (this.lineRanges.length === 0) return lineCount > 0 ? [[0, lineCount]] : [];
|
|
@@ -600,13 +1337,30 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
600
1337
|
commitId = queue.get();
|
|
601
1338
|
continue;
|
|
602
1339
|
}
|
|
603
|
-
if (
|
|
1340
|
+
if (
|
|
1341
|
+
this.reverseFrom !== undefined ||
|
|
1342
|
+
(!st.uninteresting &&
|
|
1343
|
+
!(this.since !== undefined && st.commit.committer.timestamp < this.since))
|
|
1344
|
+
) {
|
|
1345
|
+
await this.passBlame(suspect, queue);
|
|
1346
|
+
} else {
|
|
1347
|
+
st.uninteresting = true;
|
|
1348
|
+
this.markParentsUninteresting(st);
|
|
1349
|
+
}
|
|
604
1350
|
// treat root commit as boundary
|
|
605
1351
|
if (st.commit.parents.length === 0 && !this.showRoot) st.uninteresting = true;
|
|
606
1352
|
// take responsibility for the remaining entries
|
|
607
1353
|
let ent = suspect.suspects;
|
|
608
1354
|
if (ent) {
|
|
609
1355
|
suspect.guilty = true;
|
|
1356
|
+
// found_guilty_entry: what --incremental prints, in this order
|
|
1357
|
+
for (let e: Entry | null = ent; e; e = e.next) {
|
|
1358
|
+
this.guilty.push({
|
|
1359
|
+
entry: { ...e, next: null },
|
|
1360
|
+
origin: suspect,
|
|
1361
|
+
boundary: st.uninteresting,
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
610
1364
|
while (ent.next) ent = ent.next;
|
|
611
1365
|
ent.next = final.next;
|
|
612
1366
|
final.next = suspect.suspects;
|
|
@@ -615,14 +1369,184 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
615
1369
|
}
|
|
616
1370
|
}
|
|
617
1371
|
|
|
618
|
-
/**
|
|
1372
|
+
/**
|
|
1373
|
+
* revision.c's `mark_parents_uninteresting`: the parents marked, and the parents of those
|
|
1374
|
+
* already loaded (parsed) recursively
|
|
1375
|
+
*/
|
|
1376
|
+
private markParentsUninteresting(st: CommitState): void {
|
|
1377
|
+
const pending = [...st.commit.parents];
|
|
1378
|
+
while (pending.length > 0) {
|
|
1379
|
+
const id = pending.pop() as ObjectId;
|
|
1380
|
+
const parent = this.states.get(id);
|
|
1381
|
+
if (!parent) {
|
|
1382
|
+
this.sinceUninteresting.add(id);
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
if (parent.uninteresting) continue;
|
|
1386
|
+
parent.uninteresting = true;
|
|
1387
|
+
pending.push(...parent.commit.parents);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* blame.c's `fake_working_tree_commit`: a commit with the null id on top of `parentId`
|
|
1393
|
+
* (and the commits MERGE_HEAD names, `append_merge_parents`) whose file at `path` is the
|
|
1394
|
+
* `--contents` buffer; its id is returned
|
|
1395
|
+
*/
|
|
1396
|
+
private async fakeWorkingTreeCommit(parentId: ObjectId, path: string): Promise<ObjectId> {
|
|
1397
|
+
const contents = this.contents as { content: Uint8Array } & BlameContentsOptions;
|
|
1398
|
+
const parent = await this.state(parentId);
|
|
1399
|
+
if (!parent) throw new Error(`no such commit ${parentId}`);
|
|
1400
|
+
const parents = [parentId];
|
|
1401
|
+
// append_parent: lookup_commit_reference, an annotated tag peeled to its commit
|
|
1402
|
+
const resolver = this.revisionResolver();
|
|
1403
|
+
for (const id of await this.mergeHeadParents()) {
|
|
1404
|
+
const peeled = await resolver.peelTags(id).catch(() => undefined);
|
|
1405
|
+
if (peeled?.type !== "commit" || !(await this.state(peeled.id))) {
|
|
1406
|
+
throw new Error(`no such commit ${id}`);
|
|
1407
|
+
}
|
|
1408
|
+
parents.push(peeled.id);
|
|
1409
|
+
}
|
|
1410
|
+
const index = await this.indexEntries();
|
|
1411
|
+
// verify_working_tree_path: a blob of a parent, else any stage of the index
|
|
1412
|
+
let known = false;
|
|
1413
|
+
for (const id of parents) {
|
|
1414
|
+
const st = this.states.get(id);
|
|
1415
|
+
const entry = st && (await this.lookup(st.commit.tree, path));
|
|
1416
|
+
if (entry && (entry.mode & S_IFMT) !== GITLINK_MODE) {
|
|
1417
|
+
known = true;
|
|
1418
|
+
break;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
if (!known && !index.some((e) => e.path === path)) {
|
|
1422
|
+
throw new Error(`no such path '${path}' in HEAD`);
|
|
1423
|
+
}
|
|
1424
|
+
const time = contents.time ?? Math.floor(Date.now() / 1000);
|
|
1425
|
+
const tzOffset = contents.tzOffset ?? localTimezoneOffset(time);
|
|
1426
|
+
const ident = contents.workingTree
|
|
1427
|
+
? { name: "Not Committed Yet", email: "not.committed.yet", timestamp: time, tzOffset }
|
|
1428
|
+
: { name: "External file (--contents)", email: "external.file", timestamp: time, tzOffset };
|
|
1429
|
+
const from = contents.workingTree
|
|
1430
|
+
? path
|
|
1431
|
+
: contents.name === undefined || contents.name === "-"
|
|
1432
|
+
? "standard input"
|
|
1433
|
+
: contents.name;
|
|
1434
|
+
const id = this.objectFormat.nullId;
|
|
1435
|
+
// without a mode (standard input): the index's stage-0 entry's, else a regular file's
|
|
1436
|
+
const staged = index.find((e) => e.path === path && e.stage === 0);
|
|
1437
|
+
const mode = contents.mode ?? staged?.mode ?? 0o100644;
|
|
1438
|
+
const content = (await this.textconvContents(contents, path, mode)) ?? contents.content;
|
|
1439
|
+
const blobId = await computeObjectId("blob", content, this.objectFormat);
|
|
1440
|
+
this.pretend.set(blobId, content);
|
|
1441
|
+
this.fakeEntry = { id: blobId, mode };
|
|
1442
|
+
// the index with the path replaced: what git diffs the parents against (do_diff_cache)
|
|
1443
|
+
const files = new Map<string, { id: ObjectId; mode: number }>();
|
|
1444
|
+
for (const e of index) {
|
|
1445
|
+
if (e.stage === 0 && (e.mode & S_IFMT) !== GITLINK_MODE) {
|
|
1446
|
+
files.set(e.path, { id: e.objectId, mode: e.mode });
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
files.set(path, { id: blobId, mode });
|
|
1450
|
+
this.fakeFiles = files;
|
|
1451
|
+
this.states.set(id, {
|
|
1452
|
+
commit: {
|
|
1453
|
+
// the parent's tree stands for the index where a tree is read (`-C`)
|
|
1454
|
+
tree: parent.commit.tree,
|
|
1455
|
+
parents,
|
|
1456
|
+
author: ident,
|
|
1457
|
+
committer: ident,
|
|
1458
|
+
message: `Version of ${path} from ${from}\n`,
|
|
1459
|
+
},
|
|
1460
|
+
origins: null,
|
|
1461
|
+
originsByPath: new Map(),
|
|
1462
|
+
uninteresting: false,
|
|
1463
|
+
});
|
|
1464
|
+
return id;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
/** The commits `.git/MERGE_HEAD` names, one per line (`append_merge_parents`) */
|
|
1468
|
+
private async mergeHeadParents(): Promise<ObjectId[]> {
|
|
1469
|
+
let text: string | undefined;
|
|
1470
|
+
try {
|
|
1471
|
+
text = await new OperationState(this.workingCopy.checkout, this.refsStore).read("MERGE_HEAD");
|
|
1472
|
+
} catch {
|
|
1473
|
+
return [];
|
|
1474
|
+
}
|
|
1475
|
+
const out: ObjectId[] = [];
|
|
1476
|
+
// strbuf_getwholeline_fd: only lines ending in a newline (a last one without is dropped)
|
|
1477
|
+
const lines = (text ?? "").split(/(?<=\n)/).filter((l) => l.endsWith("\n"));
|
|
1478
|
+
for (const line of lines) {
|
|
1479
|
+
// get_oid_hex: the line's first digits, the rest ignored; an empty line is refused
|
|
1480
|
+
const hex = line.slice(0, this.objectFormat.hexLength).toLowerCase();
|
|
1481
|
+
if (!this.isFullObjectId(hex)) {
|
|
1482
|
+
throw new Error(`unknown line in '.git/MERGE_HEAD': ${line}`);
|
|
1483
|
+
}
|
|
1484
|
+
out.push(hex);
|
|
1485
|
+
}
|
|
1486
|
+
return out;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
/** Every entry of the index, none without one (a bare repository) */
|
|
1490
|
+
private async indexEntries(): Promise<
|
|
1491
|
+
Array<{
|
|
1492
|
+
path: string;
|
|
1493
|
+
mode: number;
|
|
1494
|
+
objectId: ObjectId;
|
|
1495
|
+
stage: number;
|
|
1496
|
+
}>
|
|
1497
|
+
> {
|
|
1498
|
+
try {
|
|
1499
|
+
const staging = this.staging;
|
|
1500
|
+
if (await staging.isOutdated()) await staging.read();
|
|
1501
|
+
const out = [];
|
|
1502
|
+
for await (const e of staging.entries()) {
|
|
1503
|
+
out.push({ path: e.path, mode: e.mode, objectId: e.objectId, stage: e.stage });
|
|
1504
|
+
}
|
|
1505
|
+
return out;
|
|
1506
|
+
} catch {
|
|
1507
|
+
return [];
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
/** git's `pass_blame` */
|
|
619
1512
|
private async passBlame(origin: Origin, queue: CommitQueue): Promise<void> {
|
|
620
1513
|
const st = this.states.get(origin.commitId);
|
|
621
1514
|
if (!st) return;
|
|
622
|
-
const parents = st.
|
|
1515
|
+
const parents = this.scapegoats(st, origin.commitId);
|
|
623
1516
|
const n = parents.length;
|
|
624
|
-
if (n === 0) return;
|
|
625
1517
|
const sgOrigin: Array<Origin | undefined> = new Array(n).fill(undefined);
|
|
1518
|
+
const blames: Slot = { next: null };
|
|
1519
|
+
const blamed: Queue = { tail: blames };
|
|
1520
|
+
const toosmall: Slot = { next: null };
|
|
1521
|
+
await this.passBlameSteps(origin, parents, sgOrigin, blamed, toosmall, queue);
|
|
1522
|
+
blamed.tail.next = null;
|
|
1523
|
+
this.distributeBlame(blames.next, queue);
|
|
1524
|
+
// the entries too small to look for are the origin's again (unsorted, as git leaves them)
|
|
1525
|
+
if (toosmall.next) {
|
|
1526
|
+
let tail = toosmall.next;
|
|
1527
|
+
while (tail.next) tail = tail.next;
|
|
1528
|
+
tail.next = origin.suspects;
|
|
1529
|
+
origin.suspects = toosmall.next;
|
|
1530
|
+
}
|
|
1531
|
+
for (const porigin of sgOrigin) if (porigin && !porigin.suspects) porigin.lines = undefined;
|
|
1532
|
+
origin.lines = undefined;
|
|
1533
|
+
origin.fingerprints = undefined;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
/**
|
|
1537
|
+
* The steps of `pass_blame` before its `finish`: the parents' versions found and compared,
|
|
1538
|
+
* then moves and copies looked for; returning is git's `goto finish`
|
|
1539
|
+
*/
|
|
1540
|
+
private async passBlameSteps(
|
|
1541
|
+
origin: Origin,
|
|
1542
|
+
parents: ObjectId[],
|
|
1543
|
+
sgOrigin: Array<Origin | undefined>,
|
|
1544
|
+
blamed: Queue,
|
|
1545
|
+
toosmall: Slot,
|
|
1546
|
+
queue: CommitQueue,
|
|
1547
|
+
): Promise<void> {
|
|
1548
|
+
const n = parents.length;
|
|
1549
|
+
if (n === 0) return;
|
|
626
1550
|
for (let pass = 0; pass < (this.followRenames ? 2 : 1); pass++) {
|
|
627
1551
|
for (let i = 0; i < n; i++) {
|
|
628
1552
|
if (sgOrigin[i]) continue;
|
|
@@ -651,9 +1575,390 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
651
1575
|
if (!porigin) continue;
|
|
652
1576
|
if (!origin.previous) origin.previous = porigin;
|
|
653
1577
|
await this.passBlameToParent(origin, porigin, queue);
|
|
654
|
-
if (!origin.suspects)
|
|
1578
|
+
if (!origin.suspects) return;
|
|
655
1579
|
}
|
|
656
|
-
|
|
1580
|
+
// pass the remaining suspects of an ignored commit to its parents
|
|
1581
|
+
if (this.ignoreList.has(origin.commitId)) {
|
|
1582
|
+
for (let i = 0; i < n; i++) {
|
|
1583
|
+
const porigin = sgOrigin[i];
|
|
1584
|
+
if (!porigin) continue;
|
|
1585
|
+
await this.passBlameToParent(origin, porigin, queue, true);
|
|
1586
|
+
if (!origin.suspects) return;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
// optionally find moves in the parents' files
|
|
1590
|
+
if (this.detectMoves) {
|
|
1591
|
+
this.filterSuspects(toosmall, origin, this.moveScore);
|
|
1592
|
+
if (origin.suspects) {
|
|
1593
|
+
for (let i = 0; i < n; i++) {
|
|
1594
|
+
const porigin = sgOrigin[i];
|
|
1595
|
+
if (!porigin) continue;
|
|
1596
|
+
await this.findMoveInParent(blamed, toosmall, origin, porigin);
|
|
1597
|
+
if (!origin.suspects) break;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
// optionally find copies from the parents' files
|
|
1602
|
+
if (this.copyLevel > 0) {
|
|
1603
|
+
if (this.copyScore > this.moveScore) {
|
|
1604
|
+
this.filterSuspects(toosmall, origin, this.copyScore);
|
|
1605
|
+
} else if (this.copyScore < this.moveScore) {
|
|
1606
|
+
origin.suspects = blameMerge(origin.suspects, toosmall.next);
|
|
1607
|
+
toosmall.next = null;
|
|
1608
|
+
this.filterSuspects(toosmall, origin, this.copyScore);
|
|
1609
|
+
}
|
|
1610
|
+
if (!origin.suspects) return;
|
|
1611
|
+
for (let i = 0; i < n; i++) {
|
|
1612
|
+
await this.findCopyInParent(blamed, toosmall, origin, parents[i], sgOrigin[i]);
|
|
1613
|
+
if (!origin.suspects) return;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
/** `filter_small` of the origin's suspects into `toosmall` */
|
|
1619
|
+
private filterSuspects(toosmall: Slot, origin: Origin, scoreMin: number): void {
|
|
1620
|
+
const src: Slot = { next: origin.suspects };
|
|
1621
|
+
this.filterSmall(toosmall, src, scoreMin);
|
|
1622
|
+
origin.suspects = src.next;
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
/**
|
|
1626
|
+
* git's `filter_small`: the entries of `source` scoring at most `scoreMin` moved to the
|
|
1627
|
+
* front of the list after `small`; returns the link before the old head of that list
|
|
1628
|
+
*/
|
|
1629
|
+
private filterSmall(small: Slot, source: Slot, scoreMin: number): Slot {
|
|
1630
|
+
let p = source.next;
|
|
1631
|
+
const oldsmall = small.next;
|
|
1632
|
+
let sm = small;
|
|
1633
|
+
let src = source;
|
|
1634
|
+
while (p) {
|
|
1635
|
+
if (this.entryScore(p.lno, p.numLines) <= scoreMin) {
|
|
1636
|
+
sm.next = p;
|
|
1637
|
+
sm = p;
|
|
1638
|
+
} else {
|
|
1639
|
+
src.next = p;
|
|
1640
|
+
src = p;
|
|
1641
|
+
}
|
|
1642
|
+
p = p.next;
|
|
1643
|
+
}
|
|
1644
|
+
sm.next = oldsmall;
|
|
1645
|
+
src.next = null;
|
|
1646
|
+
return sm;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
/** git's `blame_entry_score`: one more than the alphanumerics of the lines in the final file */
|
|
1650
|
+
private entryScore(lno: number, numLines: number): number {
|
|
1651
|
+
return 1 + this.finalAlnum[lno + numLines] - this.finalAlnum[lno];
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
/** git's `prepare_lines`, and the alphanumerics before each line for `entryScore` */
|
|
1655
|
+
private prepareLines(content: Uint8Array, lineCount: number): void {
|
|
1656
|
+
const starts = new Int32Array(lineCount + 1);
|
|
1657
|
+
const alnum = new Int32Array(lineCount + 1);
|
|
1658
|
+
let line = 0;
|
|
1659
|
+
let count = 0;
|
|
1660
|
+
for (let i = 0; i < content.length; i++) {
|
|
1661
|
+
const c = content[i];
|
|
1662
|
+
if ((c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a)) {
|
|
1663
|
+
count++;
|
|
1664
|
+
} else if (c === 0x0a && ++line < lineCount) {
|
|
1665
|
+
starts[line] = i + 1;
|
|
1666
|
+
alnum[line] = count;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
starts[lineCount] = content.length;
|
|
1670
|
+
alnum[lineCount] = count;
|
|
1671
|
+
this.finalContent = content;
|
|
1672
|
+
this.finalStarts = starts;
|
|
1673
|
+
this.finalAlnum = alnum;
|
|
1674
|
+
if (this.copyLevel > 0) this.finalHashes = this.lineHashesOf(content);
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/** git's `copy_split_if_better`: `potential` kept in `best` when it scores no lower */
|
|
1678
|
+
private copySplitIfBetter(best: Split, potential: Split): void {
|
|
1679
|
+
if (!potential[1].suspect) return;
|
|
1680
|
+
if (
|
|
1681
|
+
best[1].suspect &&
|
|
1682
|
+
this.entryScore(potential[1].lno, potential[1].numLines) <
|
|
1683
|
+
this.entryScore(best[1].lno, best[1].numLines)
|
|
1684
|
+
) {
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
best[0] = potential[0];
|
|
1688
|
+
best[1] = potential[1];
|
|
1689
|
+
best[2] = potential[2];
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
/**
|
|
1693
|
+
* git's `find_copy_in_blob`: the best run of `ent`'s lines (in the final file) that the
|
|
1694
|
+
* parent's file has, as a split of `ent`
|
|
1695
|
+
*/
|
|
1696
|
+
private findCopyInBlob(ent: Entry, parent: Origin, file: { text: InternedText }): Split {
|
|
1697
|
+
const split = emptySplit();
|
|
1698
|
+
const interner = this.lineInterner();
|
|
1699
|
+
if (file.text.interner !== interner) file.text = interner.text(file.text.content);
|
|
1700
|
+
const slice = this.finalContent.subarray(
|
|
1701
|
+
this.finalStarts[ent.lno],
|
|
1702
|
+
this.finalStarts[ent.lno + ent.numLines],
|
|
1703
|
+
);
|
|
1704
|
+
const hunks = xdiffHunks(file.text, slice, this.xdiffOptions(interner));
|
|
1705
|
+
let tlno = 0;
|
|
1706
|
+
let plno = 0;
|
|
1707
|
+
const handleSplit = (same: number) => {
|
|
1708
|
+
if (ent.numLines <= tlno || tlno >= same) return;
|
|
1709
|
+
const potential = splitOverlap(ent, tlno + ent.sLno, plno, same + ent.sLno, parent);
|
|
1710
|
+
this.copySplitIfBetter(split, potential);
|
|
1711
|
+
};
|
|
1712
|
+
for (const h of hunks) {
|
|
1713
|
+
handleSplit(h.i2);
|
|
1714
|
+
plno = h.i1 + h.chg1;
|
|
1715
|
+
tlno = h.i2 + h.chg2;
|
|
1716
|
+
}
|
|
1717
|
+
// the rest, if any, matches the parent
|
|
1718
|
+
handleSplit(ent.numLines);
|
|
1719
|
+
return split;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
/** git's `find_move_in_parent`: lines the target is suspected for found in the parent's file */
|
|
1723
|
+
private async findMoveInParent(
|
|
1724
|
+
blamed: Queue,
|
|
1725
|
+
toosmallHead: Slot,
|
|
1726
|
+
target: Origin,
|
|
1727
|
+
parent: Origin,
|
|
1728
|
+
): Promise<void> {
|
|
1729
|
+
let unblamed = target.suspects;
|
|
1730
|
+
if (!unblamed) return;
|
|
1731
|
+
const file = { text: await this.originContent(parent) };
|
|
1732
|
+
let toosmall = toosmallHead;
|
|
1733
|
+
let leftover: Entry | null = null;
|
|
1734
|
+
do {
|
|
1735
|
+
const head: Slot = { next: null };
|
|
1736
|
+
const rest: Queue = { tail: head };
|
|
1737
|
+
let next: Entry | null;
|
|
1738
|
+
for (let e: Entry | null = unblamed; e; e = next) {
|
|
1739
|
+
next = e.next;
|
|
1740
|
+
const split = this.findCopyInBlob(e, parent, file);
|
|
1741
|
+
if (split[1].suspect && this.moveScore < this.entryScore(split[1].lno, split[1].numLines)) {
|
|
1742
|
+
splitBlame(blamed, rest, split, e);
|
|
1743
|
+
} else {
|
|
1744
|
+
e.next = leftover;
|
|
1745
|
+
leftover = e;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
rest.tail.next = null;
|
|
1749
|
+
toosmall = this.filterSmall(toosmall, head, this.moveScore);
|
|
1750
|
+
unblamed = head.next;
|
|
1751
|
+
} while (unblamed);
|
|
1752
|
+
parent.lines = file.text;
|
|
1753
|
+
target.suspects = reverseBlame(leftover, null);
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
/**
|
|
1757
|
+
* git's `find_copy_in_parent`: lines the target is suspected for found in other files of
|
|
1758
|
+
* the parent (`porigin`, the parent's version of the file, was tried by the move pass)
|
|
1759
|
+
*/
|
|
1760
|
+
private async findCopyInParent(
|
|
1761
|
+
blamed: Queue,
|
|
1762
|
+
toosmallHead: Slot,
|
|
1763
|
+
target: Origin,
|
|
1764
|
+
parentId: ObjectId,
|
|
1765
|
+
porigin: Origin | undefined,
|
|
1766
|
+
): Promise<void> {
|
|
1767
|
+
let unblamed = target.suspects;
|
|
1768
|
+
if (!unblamed) return;
|
|
1769
|
+
const parent = await this.state(parentId);
|
|
1770
|
+
const child = this.states.get(target.commitId);
|
|
1771
|
+
if (!parent || !child) return;
|
|
1772
|
+
const harder =
|
|
1773
|
+
this.copyLevel >= 3 || (this.copyLevel >= 2 && (!porigin || target.path !== porigin.path));
|
|
1774
|
+
const candidates = await this.copyCandidates(parent.commit.tree, child.commit.tree, harder);
|
|
1775
|
+
/** Origins this call made: git frees those no split took (`blame_origin_decref`) */
|
|
1776
|
+
const created = new Set<Origin>();
|
|
1777
|
+
const taken = new Set<Origin>();
|
|
1778
|
+
let toosmall = toosmallHead;
|
|
1779
|
+
let leftover: Entry | null = null;
|
|
1780
|
+
do {
|
|
1781
|
+
const head: Slot = { next: null };
|
|
1782
|
+
const rest: Queue = { tail: head };
|
|
1783
|
+
const list: Array<{ ent: Entry; split: Split }> = [];
|
|
1784
|
+
// the line hashes of the entries: a file sharing none of them cannot give a split
|
|
1785
|
+
const wanted = new Set<number>();
|
|
1786
|
+
for (let e: Entry | null = unblamed; e; e = e.next) {
|
|
1787
|
+
list.push({ ent: e, split: emptySplit() });
|
|
1788
|
+
for (let l = e.lno; l < e.lno + e.numLines; l++) wanted.add(this.finalHashes[l]);
|
|
1789
|
+
}
|
|
1790
|
+
for (const c of candidates) {
|
|
1791
|
+
// find_move already dealt with this path
|
|
1792
|
+
if (porigin && c.path === porigin.path) continue;
|
|
1793
|
+
const key = this.copyKey(c);
|
|
1794
|
+
let hashes = this.copyHashes.get(key);
|
|
1795
|
+
let content: Uint8Array | undefined;
|
|
1796
|
+
if (hashes === undefined) {
|
|
1797
|
+
if (c.id !== target.blobId && (await this.isBig(c.id))) hashes = null;
|
|
1798
|
+
else {
|
|
1799
|
+
content = await this.originBlob(c.id, c.path, c.mode, true);
|
|
1800
|
+
hashes = this.lineHashesOf(content);
|
|
1801
|
+
}
|
|
1802
|
+
this.keepCopyHashes(key, hashes);
|
|
1803
|
+
}
|
|
1804
|
+
if (hashes === null) continue;
|
|
1805
|
+
if (!sharesLine(hashes, wanted)) {
|
|
1806
|
+
// git's get_origin still moves a known origin to the front
|
|
1807
|
+
const known = parent.originsByPath.get(c.path);
|
|
1808
|
+
if (known) moveOriginToFront(parent, known);
|
|
1809
|
+
continue;
|
|
1810
|
+
}
|
|
1811
|
+
const isNew = !parent.originsByPath.has(c.path);
|
|
1812
|
+
const norigin = this.getOrigin(parentId, c.path);
|
|
1813
|
+
if (isNew) created.add(norigin);
|
|
1814
|
+
norigin.blobId = c.id;
|
|
1815
|
+
norigin.mode = c.mode;
|
|
1816
|
+
const file = {
|
|
1817
|
+
text:
|
|
1818
|
+
norigin.lines ??
|
|
1819
|
+
this.copySources.get(key) ??
|
|
1820
|
+
this.lineInterner().text(
|
|
1821
|
+
content ?? (await this.originBlob(c.id, c.path, c.mode, true)),
|
|
1822
|
+
),
|
|
1823
|
+
};
|
|
1824
|
+
for (const item of list) {
|
|
1825
|
+
this.copySplitIfBetter(item.split, this.findCopyInBlob(item.ent, norigin, file));
|
|
1826
|
+
}
|
|
1827
|
+
this.keepCopySourceText(key, file.text);
|
|
1828
|
+
}
|
|
1829
|
+
for (const { ent, split } of list) {
|
|
1830
|
+
if (split[1].suspect && this.copyScore < this.entryScore(split[1].lno, split[1].numLines)) {
|
|
1831
|
+
taken.add(split[1].suspect);
|
|
1832
|
+
splitBlame(blamed, rest, split, ent);
|
|
1833
|
+
} else {
|
|
1834
|
+
ent.next = leftover;
|
|
1835
|
+
leftover = ent;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
rest.tail.next = null;
|
|
1839
|
+
toosmall = this.filterSmall(toosmall, head, this.copyScore);
|
|
1840
|
+
unblamed = head.next;
|
|
1841
|
+
} while (unblamed);
|
|
1842
|
+
target.suspects = reverseBlame(leftover, null);
|
|
1843
|
+
for (const o of created) if (!taken.has(o) && !o.suspects) unlinkOrigin(parent, o);
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
/**
|
|
1847
|
+
* The hash of each line, as the line interner hashes it (`xdl_hash_record` under
|
|
1848
|
+
* whitespace flags): lines a diff can match hash alike
|
|
1849
|
+
*/
|
|
1850
|
+
private lineHashesOf(content: Uint8Array): Int32Array {
|
|
1851
|
+
const lines = new ByteLines(content);
|
|
1852
|
+
const ws = whitespaceFlags({ ignoreWhitespace: this.ignoreWhitespace });
|
|
1853
|
+
const n = lines.size();
|
|
1854
|
+
if (!ws) return lines.lineHashes.slice(0, n);
|
|
1855
|
+
const out = new Int32Array(n);
|
|
1856
|
+
for (let i = 0; i < n; i++)
|
|
1857
|
+
out[i] = xdlHashRecord(content, lines.start(i), lines.start(i + 1), ws);
|
|
1858
|
+
return out;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
/**
|
|
1862
|
+
* Kept while the cache has room (and never evicted): a commit scans its parent's files in
|
|
1863
|
+
* the order the next one scans them, so evicting the oldest would evict every file before
|
|
1864
|
+
* its next use
|
|
1865
|
+
*/
|
|
1866
|
+
private keepCopyHashes(key: string, hashes: Int32Array | null): void {
|
|
1867
|
+
const size = 64 + (hashes ? hashes.byteLength : 0);
|
|
1868
|
+
if (this.copyHashBytes + size > this.copyHashCacheBytes) return;
|
|
1869
|
+
this.copyHashes.set(key, hashes);
|
|
1870
|
+
this.copyHashBytes += size;
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
/** A file a copy was looked for in, interned, kept as `keepCopyHashes` keeps hashes */
|
|
1874
|
+
private keepCopySourceText(key: string, text: InternedText): void {
|
|
1875
|
+
const old = this.copySources.get(key);
|
|
1876
|
+
if (old) {
|
|
1877
|
+
this.copySources.set(key, text);
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
1880
|
+
if (this.copySourceBytes + text.content.length > this.copySourceCacheBytes) return;
|
|
1881
|
+
this.copySources.set(key, text);
|
|
1882
|
+
this.copySourceBytes += text.content.length;
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
/**
|
|
1886
|
+
* The parent's files `find_copy_in_parent` looks in, in the order git's tree diff lists
|
|
1887
|
+
* them: those the commit changed or removed, or (`harder`, find_copies_harder) all of
|
|
1888
|
+
* them; never gitlinks
|
|
1889
|
+
*/
|
|
1890
|
+
private async copyCandidates(
|
|
1891
|
+
parentTree: ObjectId,
|
|
1892
|
+
childTree: ObjectId,
|
|
1893
|
+
harder: boolean,
|
|
1894
|
+
): Promise<Array<{ path: string; id: ObjectId; mode: number }>> {
|
|
1895
|
+
const out: Array<{ path: string; id: ObjectId; mode: number }> = [];
|
|
1896
|
+
const walk = async (tree: ObjectId, other: ObjectId | undefined, prefix: string) => {
|
|
1897
|
+
if (!harder && tree === other) return;
|
|
1898
|
+
const others = new Map<string, { id: ObjectId; mode: number }>();
|
|
1899
|
+
if (other && !harder) {
|
|
1900
|
+
for await (const e of this.trees.loadTree(other)) others.set(e.name, e);
|
|
1901
|
+
}
|
|
1902
|
+
for await (const e of this.trees.loadTree(tree)) {
|
|
1903
|
+
const path = prefix + e.name;
|
|
1904
|
+
const o = others.get(e.name);
|
|
1905
|
+
const kind = e.mode & S_IFMT;
|
|
1906
|
+
if (kind === TREE_MODE) {
|
|
1907
|
+
await walk(e.id, o && (o.mode & S_IFMT) === TREE_MODE ? o.id : undefined, `${path}/`);
|
|
1908
|
+
} else if (kind !== GITLINK_MODE) {
|
|
1909
|
+
if (!harder && o && o.id === e.id && o.mode === e.mode) continue;
|
|
1910
|
+
out.push({ path, id: e.id, mode: e.mode });
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
await walk(parentTree, childTree, "");
|
|
1915
|
+
return out;
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
/** git's `distribute_blame`: the entries found in parents queued to their origins */
|
|
1919
|
+
private distributeBlame(blamed: Entry | null, queue: CommitQueue): void {
|
|
1920
|
+
const ents: Entry[] = [];
|
|
1921
|
+
for (let e = blamed; e; e = e.next) ents.push(e);
|
|
1922
|
+
ents.sort((a, b) => a.suspect.seq - b.suspect.seq || a.sLno - b.sLno);
|
|
1923
|
+
let i = 0;
|
|
1924
|
+
while (i < ents.length) {
|
|
1925
|
+
const porigin = ents[i].suspect;
|
|
1926
|
+
let j = i;
|
|
1927
|
+
while (j + 1 < ents.length && ents[j + 1].suspect === porigin) {
|
|
1928
|
+
ents[j].next = ents[j + 1];
|
|
1929
|
+
j++;
|
|
1930
|
+
}
|
|
1931
|
+
ents[j].next = null;
|
|
1932
|
+
this.queueBlames(porigin, ents[i], queue);
|
|
1933
|
+
i = j + 1;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
/** The diff options of every comparison (`sb->xdl_opts`) */
|
|
1938
|
+
private xdiffOptions(interner: LineInterner): XdiffOptions {
|
|
1939
|
+
return {
|
|
1940
|
+
interner,
|
|
1941
|
+
algorithm: this.algorithm,
|
|
1942
|
+
indentHeuristic: this.indentHeuristic,
|
|
1943
|
+
ignoreWhitespace: this.ignoreWhitespace,
|
|
1944
|
+
...this.diffOptions,
|
|
1945
|
+
};
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
/** mailmap.c's read_mailmap: `.mailmap` (not in a bare repository), `mailmap.blob`, `mailmap.file` */
|
|
1949
|
+
private async loadMailmap(): Promise<Mailmap> {
|
|
1950
|
+
const config = RemoteConfigStore.from(this.workingCopy);
|
|
1951
|
+
return readRepositoryMailmap({
|
|
1952
|
+
config: (key) => config.value(key),
|
|
1953
|
+
worktree: this.worktreeAccess,
|
|
1954
|
+
environment: hostEnvironmentOf(this.workingCopy),
|
|
1955
|
+
readBlobNamed: async (name) => {
|
|
1956
|
+
const id = await this.revisionResolver()
|
|
1957
|
+
.resolve(name)
|
|
1958
|
+
.catch(() => undefined);
|
|
1959
|
+
return id ? this.readBlob(id).catch(() => undefined) : undefined;
|
|
1960
|
+
},
|
|
1961
|
+
});
|
|
657
1962
|
}
|
|
658
1963
|
|
|
659
1964
|
/** git's `pass_whole_blame` */
|
|
@@ -685,11 +1990,15 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
685
1990
|
if (st) queue.put(porigin.commitId, st.commit.committer.timestamp);
|
|
686
1991
|
}
|
|
687
1992
|
|
|
688
|
-
/**
|
|
1993
|
+
/**
|
|
1994
|
+
* git's `pass_blame_to_parent`; `ignoreDiffs` (an ignored commit's second pass) passes the
|
|
1995
|
+
* changed lines too, to the parent lines they resemble
|
|
1996
|
+
*/
|
|
689
1997
|
private async passBlameToParent(
|
|
690
1998
|
target: Origin,
|
|
691
1999
|
parent: Origin,
|
|
692
2000
|
queue: CommitQueue,
|
|
2001
|
+
ignoreDiffs = false,
|
|
693
2002
|
): Promise<void> {
|
|
694
2003
|
if (!target.suspects) return;
|
|
695
2004
|
const newdest: Slot = { next: null };
|
|
@@ -702,28 +2011,41 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
702
2011
|
const interner = this.lineInterner();
|
|
703
2012
|
if (fileP.interner !== interner) fileP = parent.lines = interner.text(fileP.content);
|
|
704
2013
|
if (fileO.interner !== interner) fileO = target.lines = interner.text(fileO.content);
|
|
705
|
-
const hunks = xdiffHunks(fileP, fileO,
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
});
|
|
2014
|
+
const hunks = xdiffHunks(fileP, fileO, this.xdiffOptions(interner));
|
|
2015
|
+
// the parent's fingerprints are fresh for each pass (matching consumes them), the
|
|
2016
|
+
// target's kept while it passes blame
|
|
2017
|
+
const parentFps = ignoreDiffs ? lineFingerprints(fileP.content) : undefined;
|
|
2018
|
+
let targetFps: Fingerprint[] | undefined;
|
|
2019
|
+
if (ignoreDiffs) targetFps = target.fingerprints ??= lineFingerprints(fileO.content);
|
|
712
2020
|
for (const h of hunks) {
|
|
713
|
-
|
|
2021
|
+
const lineBlames =
|
|
2022
|
+
parentFps && targetFps && h.chg2 > 0
|
|
2023
|
+
? guessLineBlames(parentFps, targetFps, h.i2, h.i1 - h.i2, h.i2 + h.chg2, h.chg1)
|
|
2024
|
+
: undefined;
|
|
2025
|
+
blameChunk(d, h.i2, h.i1 - h.i2, h.i2 + h.chg2, parent, lineBlames);
|
|
714
2026
|
d.offset = h.i1 + h.chg1 - (h.i2 + h.chg2);
|
|
715
2027
|
}
|
|
716
2028
|
blameChunk(d, INT_MAX, d.offset, INT_MAX, parent);
|
|
717
2029
|
d.dstq.next = null;
|
|
718
2030
|
target.suspects = src.next;
|
|
719
|
-
|
|
2031
|
+
let passed = newdest.next;
|
|
2032
|
+
if (ignoreDiffs && passed) {
|
|
2033
|
+
// sort_blame_entries(compare_blame_suspect): one suspect, so by line (stable)
|
|
2034
|
+
const ents: Entry[] = [];
|
|
2035
|
+
for (let e: Entry | null = passed; e; e = e.next) ents.push(e);
|
|
2036
|
+
ents.sort((a, b) => a.sLno - b.sLno);
|
|
2037
|
+
for (let i = 0; i < ents.length; i++) ents[i].next = ents[i + 1] ?? null;
|
|
2038
|
+
passed = ents[0];
|
|
2039
|
+
}
|
|
2040
|
+
this.queueBlames(parent, passed, queue);
|
|
720
2041
|
}
|
|
721
2042
|
|
|
722
2043
|
/** git's `find_origin`: the parent's version at the same path, of the same kind */
|
|
723
2044
|
private async findOrigin(parentId: ObjectId, origin: Origin): Promise<Origin | undefined> {
|
|
724
2045
|
const parent = this.states.get(parentId);
|
|
725
2046
|
if (!parent) return undefined;
|
|
726
|
-
|
|
2047
|
+
const known = parent.originsByPath.get(origin.path);
|
|
2048
|
+
if (known) return known;
|
|
727
2049
|
const entry = await this.lookup(parent.commit.tree, origin.path);
|
|
728
2050
|
if (!entry || (entry.mode & S_IFMT) !== (origin.mode & S_IFMT)) return undefined;
|
|
729
2051
|
if (entry.id !== origin.blobId && (await this.isBig(entry.id))) return undefined;
|
|
@@ -744,7 +2066,9 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
744
2066
|
const before = new Map<string, { id: ObjectId; mode: number }>();
|
|
745
2067
|
const after = new Map<string, { id: ObjectId; mode: number }>();
|
|
746
2068
|
await this.collectBlobs(parent.commit.tree, "", before);
|
|
747
|
-
|
|
2069
|
+
if (origin.commitId === this.objectFormat.nullId && this.fakeFiles) {
|
|
2070
|
+
for (const [p, e] of this.fakeFiles) after.set(p, e);
|
|
2071
|
+
} else await this.collectBlobs(child.commit.tree, "", after);
|
|
748
2072
|
const sources = [];
|
|
749
2073
|
for (const [path, e] of before) {
|
|
750
2074
|
if (!after.has(path) && !(await this.isBig(e.id))) sources.push({ path, ...e });
|
|
@@ -759,7 +2083,7 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
759
2083
|
renameLimit: limit,
|
|
760
2084
|
minimumScore: Math.round((this.renameScore * GIT_MAX_SCORE) / 100),
|
|
761
2085
|
countLastSpan: this.renameCountLastSpan,
|
|
762
|
-
size: async (c) => this.
|
|
2086
|
+
size: async (c) => this.blobSize(c.id),
|
|
763
2087
|
load: async (c) => this.readBlob(c.id),
|
|
764
2088
|
},
|
|
765
2089
|
);
|
|
@@ -777,18 +2101,13 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
777
2101
|
private getOrigin(commitId: ObjectId, path: string): Origin {
|
|
778
2102
|
const st = this.states.get(commitId);
|
|
779
2103
|
if (!st) throw new Error(`commit ${commitId} not loaded`);
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
l.next = o.next;
|
|
785
|
-
o.next = st.origins;
|
|
786
|
-
st.origins = o;
|
|
787
|
-
}
|
|
788
|
-
return o;
|
|
789
|
-
}
|
|
2104
|
+
const known = st.originsByPath.get(path);
|
|
2105
|
+
if (known) {
|
|
2106
|
+
moveOriginToFront(st, known);
|
|
2107
|
+
return known;
|
|
790
2108
|
}
|
|
791
2109
|
const o: Origin = {
|
|
2110
|
+
seq: this.originSeq++,
|
|
792
2111
|
commitId,
|
|
793
2112
|
path,
|
|
794
2113
|
blobId: "",
|
|
@@ -796,8 +2115,11 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
796
2115
|
suspects: null,
|
|
797
2116
|
guilty: false,
|
|
798
2117
|
next: st.origins,
|
|
2118
|
+
prev: null,
|
|
799
2119
|
};
|
|
2120
|
+
if (st.origins) st.origins.prev = o;
|
|
800
2121
|
st.origins = o;
|
|
2122
|
+
st.originsByPath.set(path, o);
|
|
801
2123
|
return o;
|
|
802
2124
|
}
|
|
803
2125
|
|
|
@@ -806,13 +2128,19 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
806
2128
|
if (known) return known;
|
|
807
2129
|
const commit = await this.commits.load(commitId).catch(() => undefined);
|
|
808
2130
|
if (!commit) return undefined;
|
|
809
|
-
const st: CommitState = {
|
|
2131
|
+
const st: CommitState = {
|
|
2132
|
+
commit,
|
|
2133
|
+
origins: null,
|
|
2134
|
+
originsByPath: new Map(),
|
|
2135
|
+
uninteresting:
|
|
2136
|
+
this.reverseUninteresting.has(commitId) || this.sinceUninteresting.has(commitId),
|
|
2137
|
+
};
|
|
810
2138
|
this.states.set(commitId, st);
|
|
811
2139
|
return st;
|
|
812
2140
|
}
|
|
813
2141
|
|
|
814
2142
|
private async originContent(o: Origin): Promise<InternedText> {
|
|
815
|
-
o.lines ??= this.lineInterner().text(await this.
|
|
2143
|
+
o.lines ??= this.lineInterner().text(await this.originBlob(o.blobId, o.path, o.mode, true));
|
|
816
2144
|
return o.lines;
|
|
817
2145
|
}
|
|
818
2146
|
|
|
@@ -832,7 +2160,79 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
832
2160
|
|
|
833
2161
|
/** Whether a blob is over the threshold (from its size, without reading it). */
|
|
834
2162
|
private async isBig(blobId: ObjectId): Promise<boolean> {
|
|
835
|
-
return (await this.
|
|
2163
|
+
return (await this.blobSize(blobId)) > this.bigFileThreshold;
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
/** A blob's size, the `--contents` buffer's too */
|
|
2167
|
+
private async blobSize(blobId: ObjectId): Promise<number> {
|
|
2168
|
+
const pretended = this.pretend.get(blobId);
|
|
2169
|
+
return pretended ? pretended.length : this.blobs.size(blobId);
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
/** The textconv runner blame reads through, if textconv is on and the host installed one */
|
|
2173
|
+
private textconvRunner(): TextconvRunner | undefined {
|
|
2174
|
+
return this.textconv ? textconvRunnerOf(this._workingCopy) : undefined;
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
private textconvDiffCommand(): DiffCommand {
|
|
2178
|
+
this.textconvDiff ??= new DiffCommand(this._workingCopy);
|
|
2179
|
+
return this.textconvDiff;
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
/**
|
|
2183
|
+
* The key of a file looked in for copies: its blob, and with textconv its path and mode
|
|
2184
|
+
* too (the path's driver decides the converted content)
|
|
2185
|
+
*/
|
|
2186
|
+
private copyKey(c: { id: ObjectId; path: string; mode: number }): string {
|
|
2187
|
+
return this.textconvRunner() ? `${c.id}\0${c.path}\0${c.mode}` : c.id;
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
/**
|
|
2191
|
+
* blame.c's fill_origin_blob: a version of the file as blame compares it, the blob
|
|
2192
|
+
* through the path's textconv (textconv_object, the driver's cache keyed by the blob)
|
|
2193
|
+
* when one applies; the `--contents` buffer as it was made
|
|
2194
|
+
*/
|
|
2195
|
+
private async originBlob(
|
|
2196
|
+
blobId: ObjectId,
|
|
2197
|
+
path: string,
|
|
2198
|
+
mode: number,
|
|
2199
|
+
shared = false,
|
|
2200
|
+
): Promise<Uint8Array> {
|
|
2201
|
+
if (this.pretend.has(blobId) || !this.textconvRunner()) return this.readBlob(blobId, shared);
|
|
2202
|
+
let raw: Uint8Array | undefined;
|
|
2203
|
+
const read = async () => {
|
|
2204
|
+
raw ??= await this.readBlob(blobId, shared);
|
|
2205
|
+
return raw;
|
|
2206
|
+
};
|
|
2207
|
+
const converted = await this.textconvDiffCommand().textconvBlob(path, mode, read, blobId);
|
|
2208
|
+
return converted ?? read();
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
/**
|
|
2212
|
+
* fake_working_tree_commit's textconv: the `--contents` file (the working tree's at
|
|
2213
|
+
* `path`, or the named one; never standard input) through its textconv, the output then
|
|
2214
|
+
* cleaned as git's convert_to_git cleans it for `path`; undefined when none applies
|
|
2215
|
+
*/
|
|
2216
|
+
private async textconvContents(
|
|
2217
|
+
contents: { content: Uint8Array } & BlameContentsOptions,
|
|
2218
|
+
path: string,
|
|
2219
|
+
mode: number,
|
|
2220
|
+
): Promise<Uint8Array | undefined> {
|
|
2221
|
+
if (!this.textconvRunner()) return undefined;
|
|
2222
|
+
const from = contents.workingTree ? path : contents.name;
|
|
2223
|
+
if (from === undefined || from === "-") return undefined;
|
|
2224
|
+
const file = contents.file ?? contents.content;
|
|
2225
|
+
const converted = await this.textconvDiffCommand().textconvBlob(
|
|
2226
|
+
from,
|
|
2227
|
+
mode,
|
|
2228
|
+
async () => file,
|
|
2229
|
+
undefined,
|
|
2230
|
+
{ worktreeFile: true },
|
|
2231
|
+
);
|
|
2232
|
+
if (!converted) return undefined;
|
|
2233
|
+
const worktree = "worktree" in this._workingCopy ? this.worktreeAccess : undefined;
|
|
2234
|
+
const conversion = await worktree?.contentFilter?.checkin(path);
|
|
2235
|
+
return conversion ? conversion.apply(converted) : converted;
|
|
836
2236
|
}
|
|
837
2237
|
|
|
838
2238
|
/**
|
|
@@ -840,6 +2240,8 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
840
2240
|
* comes (a resolved pack object) instead of copying it
|
|
841
2241
|
*/
|
|
842
2242
|
private async readBlob(blobId: ObjectId, shared = false): Promise<Uint8Array> {
|
|
2243
|
+
const pretended = this.pretend.get(blobId);
|
|
2244
|
+
if (pretended) return pretended;
|
|
843
2245
|
const chunks: Uint8Array[] = [];
|
|
844
2246
|
let total = 0;
|
|
845
2247
|
const content = await this.blobs.load(blobId);
|
|
@@ -890,13 +2292,17 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
890
2292
|
}
|
|
891
2293
|
}
|
|
892
2294
|
|
|
893
|
-
/**
|
|
2295
|
+
/**
|
|
2296
|
+
* git's `blame_chunk`: lines before `tlno` go to the parent, `[tlno, same)` stay, unless
|
|
2297
|
+
* `lineBlames` (an ignored commit's guesses for `[tlno, same)`) passes them to the parent
|
|
2298
|
+
*/
|
|
894
2299
|
function blameChunk(
|
|
895
2300
|
d: { offset: number; dstq: Slot; srcq: Slot },
|
|
896
2301
|
tlno: number,
|
|
897
2302
|
offset: number,
|
|
898
2303
|
same: number,
|
|
899
2304
|
parent: Origin,
|
|
2305
|
+
lineBlames?: LineBlame[],
|
|
900
2306
|
): void {
|
|
901
2307
|
let e = d.srcq.next;
|
|
902
2308
|
let samep: Entry | null = null;
|
|
@@ -921,6 +2327,7 @@ function blameChunk(
|
|
|
921
2327
|
e = reverseBlame(diffp, e);
|
|
922
2328
|
samep = null;
|
|
923
2329
|
diffp = null;
|
|
2330
|
+
let ignoredp: Entry | null = null;
|
|
924
2331
|
while (e && e.sLno < same) {
|
|
925
2332
|
const next: Entry | null = e.next;
|
|
926
2333
|
if (e.sLno + e.numLines > same) {
|
|
@@ -928,14 +2335,67 @@ function blameChunk(
|
|
|
928
2335
|
n.next = samep;
|
|
929
2336
|
samep = n;
|
|
930
2337
|
}
|
|
931
|
-
|
|
932
|
-
|
|
2338
|
+
if (lineBlames) {
|
|
2339
|
+
// ignore_blame_entry: e carved into runs of adjacent lines of one side
|
|
2340
|
+
const base = e.sLno - tlno;
|
|
2341
|
+
const nrLines = e.numLines;
|
|
2342
|
+
let entryLen = 1;
|
|
2343
|
+
let cur: Entry | null = e;
|
|
2344
|
+
for (let i = 0; i < nrLines && cur; i++) {
|
|
2345
|
+
let after: Entry | null = null;
|
|
2346
|
+
if (i + 1 < nrLines) {
|
|
2347
|
+
const a = lineBlames[base + i];
|
|
2348
|
+
const b = lineBlames[base + i + 1];
|
|
2349
|
+
if (a.isParent === b.isParent && a.sLno + 1 === b.sLno) {
|
|
2350
|
+
entryLen++;
|
|
2351
|
+
continue;
|
|
2352
|
+
}
|
|
2353
|
+
after = splitBlameAt(cur, entryLen, cur.suspect);
|
|
2354
|
+
}
|
|
2355
|
+
if (lineBlames[base + i].isParent) {
|
|
2356
|
+
cur.ignored = true;
|
|
2357
|
+
cur.suspect = parent;
|
|
2358
|
+
cur.sLno = lineBlames[base + i - entryLen + 1].sLno;
|
|
2359
|
+
cur.next = ignoredp;
|
|
2360
|
+
ignoredp = cur;
|
|
2361
|
+
} else {
|
|
2362
|
+
cur.unblamable = true;
|
|
2363
|
+
cur.next = diffp;
|
|
2364
|
+
diffp = cur;
|
|
2365
|
+
}
|
|
2366
|
+
cur = after;
|
|
2367
|
+
entryLen = 1;
|
|
2368
|
+
}
|
|
2369
|
+
} else {
|
|
2370
|
+
e.next = diffp;
|
|
2371
|
+
diffp = e;
|
|
2372
|
+
}
|
|
933
2373
|
e = next;
|
|
934
2374
|
}
|
|
2375
|
+
if (ignoredp) {
|
|
2376
|
+
// not sorted yet: the parent's list is sorted once every chunk is done
|
|
2377
|
+
d.dstq.next = reverseBlame(ignoredp, d.dstq.next);
|
|
2378
|
+
d.dstq = ignoredp;
|
|
2379
|
+
}
|
|
935
2380
|
d.srcq.next = reverseBlame(diffp, reverseBlame(samep, e));
|
|
936
2381
|
if (diffp) d.srcq = diffp;
|
|
937
2382
|
}
|
|
938
2383
|
|
|
2384
|
+
/** An identity mapped through the mailmap (`map_user`), the same object when nothing changes */
|
|
2385
|
+
function mapIdent(mailmap: Mailmap, ident: PersonIdent): PersonIdent {
|
|
2386
|
+
const m = mailmap.map(ident.name, ident.email);
|
|
2387
|
+
if (m.name === ident.name && m.email === ident.email) return ident;
|
|
2388
|
+
return { ...ident, name: m.name, email: m.email };
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
/** Two names compared as strcmp compares their bytes */
|
|
2392
|
+
function compareBytes(a: string, b: string): number {
|
|
2393
|
+
const x = encodeGitPath(a);
|
|
2394
|
+
const y = encodeGitPath(b);
|
|
2395
|
+
for (let i = 0; i < x.length && i < y.length; i++) if (x[i] !== y[i]) return x[i] - y[i];
|
|
2396
|
+
return x.length - y.length;
|
|
2397
|
+
}
|
|
2398
|
+
|
|
939
2399
|
/** Lines as git counts them: LF-terminated, an unterminated last line one more */
|
|
940
2400
|
function countLines(content: Uint8Array): number {
|
|
941
2401
|
let n = 0;
|
|
@@ -960,6 +2420,44 @@ function algorithmValue(v: string | undefined): XdiffAlgorithm | undefined {
|
|
|
960
2420
|
return s === "myers" || s === "minimal" || s === "patience" || s === "histogram" ? s : undefined;
|
|
961
2421
|
}
|
|
962
2422
|
|
|
2423
|
+
/**
|
|
2424
|
+
* builtin/blame.c's `git_blame_config` for the output: `blame.date`, `blame.showEmail`,
|
|
2425
|
+
* `blame.blankBoundary`, `blame.coloring`, `color.blame.repeatedLines` and
|
|
2426
|
+
* `color.blame.highlightRecent`, read in config order as git reads them
|
|
2427
|
+
*/
|
|
2428
|
+
function blameOutputConfig(config: RemoteConfigStore): BlameOutputConfig {
|
|
2429
|
+
const out: BlameOutputConfig = {};
|
|
2430
|
+
const last = (key: string) => {
|
|
2431
|
+
const values = config.values(key);
|
|
2432
|
+
return values.length > 0 ? values[values.length - 1] : undefined;
|
|
2433
|
+
};
|
|
2434
|
+
const date = last("blame.date");
|
|
2435
|
+
if (date !== undefined) out.date = date;
|
|
2436
|
+
const email = last("blame.showEmail");
|
|
2437
|
+
if (email !== undefined) out.showEmail = boolValue(email) ?? false;
|
|
2438
|
+
const blank = last("blame.blankBoundary");
|
|
2439
|
+
if (blank !== undefined) out.blankBoundary = boolValue(blank) ?? false;
|
|
2440
|
+
const warnings: string[] = [];
|
|
2441
|
+
for (const value of config.values("blame.coloring")) {
|
|
2442
|
+
if (value === "repeatedLines") out.colorLines = true;
|
|
2443
|
+
else if (value === "highlightRecent") out.colorByAge = true;
|
|
2444
|
+
else if (value === "none") {
|
|
2445
|
+
out.colorLines = false;
|
|
2446
|
+
out.colorByAge = false;
|
|
2447
|
+
} else warnings.push(`warning: invalid value for 'blame.coloring': '${value}'`);
|
|
2448
|
+
}
|
|
2449
|
+
for (const value of config.values("color.blame.repeatedLines")) {
|
|
2450
|
+
const color = parseGitColor(value);
|
|
2451
|
+
if (color === undefined) {
|
|
2452
|
+
warnings.push(`warning: invalid value for 'color.blame.repeatedLines': '${value}'`);
|
|
2453
|
+
} else out.repeatedLinesColor = color;
|
|
2454
|
+
}
|
|
2455
|
+
const recent = last("color.blame.highlightRecent");
|
|
2456
|
+
if (recent !== undefined) out.highlightRecent = recent;
|
|
2457
|
+
if (warnings.length > 0) out.warnings = warnings;
|
|
2458
|
+
return out;
|
|
2459
|
+
}
|
|
2460
|
+
|
|
963
2461
|
/**
|
|
964
2462
|
* Create a BlameResult from entries.
|
|
965
2463
|
*/
|