@statewalker/vcs-commands 0.5.0 → 0.6.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 +123 -8
- package/dist/commands/add-command.d.ts +265 -34
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-interactive.d.ts +46 -0
- package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
- package/dist/commands/add-patch/add-patch.d.ts +139 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
- package/dist/commands/add-patch/index.d.ts +6 -0
- package/dist/commands/add-patch/index.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-backend.d.ts +80 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-modes.d.ts +71 -0
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-session.d.ts +49 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
- package/dist/commands/am/am-command.d.ts +175 -0
- package/dist/commands/am/am-command.d.ts.map +1 -0
- package/dist/commands/am/index.d.ts +3 -0
- package/dist/commands/am/index.d.ts.map +1 -0
- package/dist/commands/am/mailinfo.d.ts +58 -0
- package/dist/commands/am/mailinfo.d.ts.map +1 -0
- package/dist/commands/am/patch-format.d.ts +24 -0
- package/dist/commands/am/patch-format.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts +153 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -0
- package/dist/commands/apply/apply-engine.d.ts +195 -0
- package/dist/commands/apply/apply-engine.d.ts.map +1 -0
- package/dist/commands/apply/apply-parse.d.ts +86 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -0
- package/dist/commands/apply/apply-types.d.ts +70 -0
- package/dist/commands/apply/apply-types.d.ts.map +1 -0
- package/dist/commands/apply/index.d.ts +6 -0
- package/dist/commands/apply/index.d.ts.map +1 -0
- package/dist/commands/apply/latin1.d.ts +32 -0
- package/dist/commands/apply/latin1.d.ts.map +1 -0
- package/dist/commands/apply/whitespace.d.ts +58 -0
- package/dist/commands/apply/whitespace.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +26 -0
- package/dist/commands/attributes-source.d.ts.map +1 -0
- package/dist/commands/backfill-command.d.ts +110 -0
- package/dist/commands/backfill-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
- package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-command.d.ts +201 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-engine.d.ts +219 -0
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-graph.d.ts +127 -0
- package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-quote.d.ts +27 -0
- package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
- package/dist/commands/bisect/index.d.ts +5 -0
- package/dist/commands/bisect/index.d.ts.map +1 -0
- package/dist/commands/blame-command.d.ts +122 -131
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +52 -2
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-tracking.d.ts +98 -0
- package/dist/commands/branch-tracking.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +300 -18
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +124 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +50 -42
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +49 -16
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +117 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +311 -17
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +78 -1
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/date-format.d.ts +58 -0
- package/dist/commands/date-format.d.ts.map +1 -0
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +377 -30
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-textconv.d.ts +40 -0
- package/dist/commands/diff-textconv.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +149 -10
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts +164 -0
- package/dist/commands/format-patch-command.d.ts.map +1 -0
- package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts +225 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +68 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +115 -0
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
- package/dist/commands/fsck/index.d.ts +6 -0
- package/dist/commands/fsck/index.d.ts.map +1 -0
- package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +43 -0
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +66 -0
- package/dist/commands/git-date.d.ts.map +1 -0
- package/dist/commands/git-describe.d.ts +67 -0
- package/dist/commands/git-describe.d.ts.map +1 -0
- package/dist/commands/git-hooks.d.ts +416 -0
- package/dist/commands/git-hooks.d.ts.map +1 -0
- package/dist/commands/git-ident.d.ts +128 -0
- package/dist/commands/git-ident.d.ts.map +1 -0
- package/dist/commands/hook-command.d.ts +96 -0
- package/dist/commands/hook-command.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +231 -0
- package/dist/commands/index-adder.d.ts.map +1 -0
- package/dist/commands/index-host.d.ts +86 -0
- package/dist/commands/index-host.d.ts.map +1 -0
- package/dist/commands/index.d.ts +54 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +12 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/local-clone.d.ts +60 -0
- package/dist/commands/local-clone.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +117 -0
- package/dist/commands/local-transport.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +216 -24
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +120 -0
- package/dist/commands/log-graph.d.ts.map +1 -0
- package/dist/commands/log-output.d.ts +323 -0
- package/dist/commands/log-output.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +23 -7
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +31 -0
- package/dist/commands/mailmap.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +85 -0
- package/dist/commands/merge-bases.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +209 -74
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +13 -0
- package/dist/commands/merge-config.d.ts.map +1 -0
- package/dist/commands/merge-drivers.d.ts +130 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +252 -0
- package/dist/commands/merge-support.d.ts.map +1 -0
- package/dist/commands/message-cleanup.d.ts +86 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -0
- package/dist/commands/mv-command.d.ts +94 -0
- package/dist/commands/mv-command.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts +256 -0
- package/dist/commands/notes-command.d.ts.map +1 -0
- package/dist/commands/notes-commands.d.ts +41 -0
- package/dist/commands/notes-commands.d.ts.map +1 -0
- package/dist/commands/notes-merge-command.d.ts +105 -0
- package/dist/commands/notes-merge-command.d.ts.map +1 -0
- package/dist/commands/notes-support.d.ts +125 -0
- package/dist/commands/notes-support.d.ts.map +1 -0
- package/dist/commands/notes-tree.d.ts +106 -0
- package/dist/commands/notes-tree.d.ts.map +1 -0
- package/dist/commands/object-id-input.d.ts +20 -0
- package/dist/commands/object-id-input.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +59 -0
- package/dist/commands/octopus-merge.d.ts.map +1 -0
- package/dist/commands/ort-merge.d.ts +126 -0
- package/dist/commands/ort-merge.d.ts.map +1 -0
- package/dist/commands/ort-recursive.d.ts +53 -0
- package/dist/commands/ort-recursive.d.ts.map +1 -0
- package/dist/commands/pack-refs-command.d.ts +20 -0
- package/dist/commands/pack-refs-command.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +41 -0
- package/dist/commands/patch-id.d.ts.map +1 -0
- package/dist/commands/pathspec-attributes.d.ts +64 -0
- package/dist/commands/pathspec-attributes.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +324 -0
- package/dist/commands/pathspec.d.ts.map +1 -0
- package/dist/commands/post-index-change.d.ts +33 -0
- package/dist/commands/post-index-change.d.ts.map +1 -0
- package/dist/commands/pretty-format.d.ts +222 -0
- package/dist/commands/pretty-format.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts +80 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -0
- package/dist/commands/pull-command.d.ts +41 -8
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +24 -8
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +112 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -0
- package/dist/commands/rebase-command.d.ts +507 -75
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/rebase-todo.d.ts +130 -0
- package/dist/commands/rebase-todo.d.ts.map +1 -0
- package/dist/commands/ref-decoration-filter.d.ts +53 -0
- package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
- package/dist/commands/reflog-messages.d.ts +98 -0
- package/dist/commands/reflog-messages.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +31 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +120 -0
- package/dist/commands/remote-transport.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +161 -7
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +103 -0
- package/dist/commands/restore-command.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +78 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -0
- package/dist/commands/rev-parse-command.d.ts +80 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -0
- package/dist/commands/revert-command.d.ts +46 -38
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-filenames.d.ts +95 -0
- package/dist/commands/revision-filenames.d.ts.map +1 -0
- package/dist/commands/revision-range.d.ts +67 -0
- package/dist/commands/revision-range.d.ts.map +1 -0
- package/dist/commands/revision-resolver.d.ts +321 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -0
- package/dist/commands/rm-command.d.ts +69 -7
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +191 -0
- package/dist/commands/sequencer-pick.d.ts.map +1 -0
- package/dist/commands/sequencer-support.d.ts +125 -0
- package/dist/commands/sequencer-support.d.ts.map +1 -0
- package/dist/commands/serve-repository.d.ts +52 -0
- package/dist/commands/serve-repository.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts +190 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-support.d.ts +268 -0
- package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +42 -8
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +155 -1
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +2 -0
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +23 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts +300 -15
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-format.d.ts +155 -0
- package/dist/commands/status-format.d.ts.map +1 -0
- package/dist/commands/status-header.d.ts +64 -0
- package/dist/commands/status-header.d.ts.map +1 -0
- package/dist/commands/strerror.d.ts +7 -0
- package/dist/commands/strerror.d.ts.map +1 -0
- package/dist/commands/submodule-config.d.ts +38 -0
- package/dist/commands/submodule-config.d.ts.map +1 -0
- package/dist/commands/submodule-summary-command.d.ts +80 -0
- package/dist/commands/submodule-summary-command.d.ts.map +1 -0
- package/dist/commands/submodule-summary.d.ts +150 -0
- package/dist/commands/submodule-summary.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +132 -0
- package/dist/commands/switch-command.d.ts.map +1 -0
- package/dist/commands/tag-command.d.ts +23 -2
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tracking-info.d.ts +64 -0
- package/dist/commands/tracking-info.d.ts.map +1 -0
- package/dist/commands/trailers.d.ts +73 -0
- package/dist/commands/trailers.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +85 -1
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +53 -0
- package/dist/commands/untracked-cache-support.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +108 -0
- package/dist/commands/worktree-add-command.d.ts.map +1 -0
- package/dist/commands/worktree-list-command.d.ts +69 -0
- package/dist/commands/worktree-list-command.d.ts.map +1 -0
- package/dist/commands/worktree-lock-command.d.ts +44 -0
- package/dist/commands/worktree-lock-command.d.ts.map +1 -0
- package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/commands/worktree-prune-command.d.ts +48 -0
- package/dist/commands/worktree-prune-command.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +59 -0
- package/dist/commands/worktree-remove-command.d.ts.map +1 -0
- package/dist/commands/worktree-repair-command.d.ts +35 -0
- package/dist/commands/worktree-repair-command.d.ts.map +1 -0
- package/dist/commands/worktree-support.d.ts +64 -0
- package/dist/commands/worktree-support.d.ts.map +1 -0
- package/dist/commands-DnmlfwGV.js +61620 -0
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/errors/add-errors.d.ts +55 -0
- package/dist/errors/add-errors.d.ts.map +1 -1
- package/dist/errors/checkout-errors.d.ts +16 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts +77 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/commit-errors.d.ts +9 -0
- package/dist/errors/commit-errors.d.ts.map +1 -1
- package/dist/errors/git-api-error.d.ts +59 -2
- package/dist/errors/git-api-error.d.ts.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +354 -19
- package/dist/errors/rebase-errors.d.ts +9 -0
- package/dist/errors/rebase-errors.d.ts.map +1 -1
- package/dist/errors/ref-errors.d.ts +32 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/transport-errors.d.ts +12 -2
- package/dist/errors/transport-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +35 -0
- package/dist/errors/worktree-errors.d.ts.map +1 -0
- package/dist/git-command-DxvwPrPB.js +7612 -0
- package/dist/git-command.d.ts +413 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +306 -3
- package/dist/git.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/remote-config-store.d.ts +105 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +7 -3
- package/dist/remote-config/remote-refs.d.ts.map +1 -1
- package/dist/rename/detect-renames.d.ts +148 -0
- package/dist/rename/detect-renames.d.ts.map +1 -0
- package/dist/rename/git-similarity.d.ts +44 -0
- package/dist/rename/git-similarity.d.ts.map +1 -0
- package/dist/rename/index.d.ts +2 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/binary-patch.d.ts +11 -0
- package/dist/results/binary-patch.d.ts.map +1 -0
- package/dist/results/blame-format.d.ts +55 -0
- package/dist/results/blame-format.d.ts.map +1 -0
- package/dist/results/cherry-pick-result.d.ts +10 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +10 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +77 -0
- package/dist/results/combined-diff.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +32 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +34 -60
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-order.d.ts +25 -0
- package/dist/results/diff-order.d.ts.map +1 -0
- package/dist/results/diff-output.d.ts +249 -0
- package/dist/results/diff-output.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +15 -0
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +5 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -252
- package/dist/results/merge-result.d.ts +15 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +12 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +42 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/quote-path.d.ts +27 -0
- package/dist/results/quote-path.d.ts.map +1 -0
- package/dist/results/rebase-result.d.ts +28 -1
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +10 -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 +60 -6
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BZGa2Z3I.js +2934 -0
- package/dist/transport-command.d.ts +44 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -11
- package/src/commands/add-command.ts +1291 -226
- package/src/commands/add-patch/add-interactive.ts +941 -0
- package/src/commands/add-patch/add-patch.ts +1169 -0
- package/src/commands/add-patch/index.ts +5 -0
- package/src/commands/add-patch/patch-backend.ts +239 -0
- package/src/commands/add-patch/patch-modes.ts +249 -0
- package/src/commands/add-patch/patch-session.ts +159 -0
- package/src/commands/am/am-command.ts +1111 -0
- package/src/commands/am/index.ts +2 -0
- package/src/commands/am/mailinfo.ts +1015 -0
- package/src/commands/am/patch-format.ts +121 -0
- package/src/commands/apply/apply-command.ts +832 -0
- package/src/commands/apply/apply-engine.ts +1603 -0
- package/src/commands/apply/apply-parse.ts +1209 -0
- package/src/commands/apply/apply-types.ts +112 -0
- package/src/commands/apply/index.ts +5 -0
- package/src/commands/apply/latin1.ts +171 -0
- package/src/commands/apply/whitespace.ts +260 -0
- package/src/commands/attributes-source.ts +96 -0
- package/src/commands/backfill-command.ts +694 -0
- package/src/commands/bisect/bisect-checkout.ts +217 -0
- package/src/commands/bisect/bisect-command.ts +788 -0
- package/src/commands/bisect/bisect-engine.ts +1079 -0
- package/src/commands/bisect/bisect-graph.ts +595 -0
- package/src/commands/bisect/bisect-quote.ts +92 -0
- package/src/commands/bisect/index.ts +4 -0
- package/src/commands/blame-command.ts +711 -986
- package/src/commands/branch-command.ts +354 -32
- package/src/commands/branch-tracking.ts +331 -0
- package/src/commands/checkout-command.ts +1290 -243
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +504 -156
- package/src/commands/clone-command.ts +634 -67
- package/src/commands/commit-command.ts +1781 -166
- package/src/commands/core-config.ts +161 -6
- package/src/commands/date-format.ts +668 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1898 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +606 -66
- package/src/commands/format-patch-command.ts +969 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3347 -0
- package/src/commands/fsck/fsck-loose.ts +287 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1044 -0
- package/src/commands/fsck/fsck-object-table.ts +363 -0
- package/src/commands/fsck/fsck-pack.ts +604 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +249 -0
- package/src/commands/gc-command.ts +147 -1
- package/src/commands/git-date.ts +895 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1472 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +706 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +82 -0
- package/src/commands/init-command.ts +28 -4
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1915 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +101 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1386 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1198 -0
- package/src/commands/message-cleanup.ts +275 -0
- package/src/commands/mv-command.ts +976 -0
- package/src/commands/notes-command.ts +890 -0
- package/src/commands/notes-commands.ts +87 -0
- package/src/commands/notes-merge-command.ts +768 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +602 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +377 -0
- package/src/commands/ort-merge.ts +1660 -0
- package/src/commands/ort-recursive.ts +160 -0
- package/src/commands/pack-refs-command.ts +39 -22
- package/src/commands/patch-id.ts +196 -0
- package/src/commands/pathspec-attributes.ts +162 -0
- package/src/commands/pathspec.ts +1199 -0
- package/src/commands/post-index-change.ts +62 -0
- package/src/commands/pretty-format.ts +1431 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +207 -22
- package/src/commands/push-command.ts +236 -23
- package/src/commands/read-tree-command.ts +857 -0
- package/src/commands/rebase-command.ts +3808 -371
- package/src/commands/rebase-todo.ts +584 -0
- package/src/commands/ref-decoration-filter.ts +118 -0
- package/src/commands/reflog-messages.ts +177 -0
- package/src/commands/remote-command.ts +93 -22
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +827 -103
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +277 -0
- package/src/commands/revert-command.ts +152 -399
- package/src/commands/revision-filenames.ts +254 -0
- package/src/commands/revision-range.ts +222 -0
- package/src/commands/revision-resolver.ts +1379 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +869 -0
- package/src/commands/sequencer-support.ts +869 -0
- package/src/commands/serve-repository.ts +125 -0
- package/src/commands/sparse-checkout-command.ts +1389 -0
- package/src/commands/sparse-checkout-support.ts +793 -0
- package/src/commands/stash-apply-command.ts +376 -343
- package/src/commands/stash-create-command.ts +625 -42
- package/src/commands/stash-drop-command.ts +15 -2
- package/src/commands/stash-working-tree.ts +168 -24
- package/src/commands/status-command.ts +1328 -105
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +330 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +334 -0
- package/src/commands/submodule-summary.ts +446 -0
- package/src/commands/switch-command.ts +402 -0
- package/src/commands/tag-command.ts +129 -41
- package/src/commands/tracking-info.ts +201 -0
- package/src/commands/trailers.ts +417 -0
- package/src/commands/tree-restore.ts +204 -4
- package/src/commands/untracked-cache-support.ts +194 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +208 -0
- package/src/commands/worktree-lock-command.ts +96 -0
- package/src/commands/worktree-overwrite-checks.ts +452 -26
- package/src/commands/worktree-prune-command.ts +99 -0
- package/src/commands/worktree-remove-command.ts +186 -0
- package/src/commands/worktree-repair-command.ts +59 -0
- package/src/commands/worktree-support.ts +214 -0
- package/src/core-commands/add.command.impl.ts +7 -1
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +26 -2
- package/src/errors/command-errors.ts +101 -1
- package/src/errors/commit-errors.ts +18 -2
- package/src/errors/git-api-error.ts +82 -2
- package/src/errors/index.ts +1 -0
- package/src/errors/merge-errors.ts +2 -2
- package/src/errors/rebase-errors.ts +12 -0
- package/src/errors/ref-errors.ts +56 -2
- package/src/errors/remote-errors.ts +2 -2
- package/src/errors/stash-errors.ts +1 -1
- package/src/errors/transport-errors.ts +20 -4
- package/src/errors/worktree-errors.ts +49 -0
- package/src/git-command.ts +1177 -118
- package/src/git.ts +523 -10
- package/src/index.ts +1 -1
- package/src/remote-config/remote-config-store.ts +242 -8
- package/src/remote-config/remote-refs.ts +22 -6
- package/src/rename/detect-renames.ts +711 -0
- package/src/rename/git-similarity.ts +116 -0
- package/src/rename/index.ts +2 -0
- package/src/results/binary-patch.ts +401 -0
- package/src/results/blame-format.ts +239 -0
- package/src/results/cherry-pick-result.ts +10 -0
- package/src/results/clone-result.ts +12 -0
- package/src/results/combined-diff.ts +585 -0
- package/src/results/diff-entry.ts +35 -0
- package/src/results/diff-formatter.ts +152 -288
- package/src/results/diff-order.ts +64 -0
- package/src/results/diff-output.ts +1051 -0
- package/src/results/fetch-result.ts +15 -0
- package/src/results/index.ts +5 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +12 -3
- package/src/results/push-result.ts +43 -0
- package/src/results/quote-path.ts +103 -0
- package/src/results/rebase-result.ts +37 -0
- package/src/results/revert-result.ts +10 -0
- package/src/results/stash-result.ts +6 -0
- package/src/results/status-result.ts +123 -45
- package/src/transport-command.ts +121 -2
- package/dist/commands-CsLNyvZ1.js +0 -12587
- package/dist/status-result-BpyUK1Sg.js +0 -519
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
import type { Commit, ObjectId, PersonIdent
|
|
1
|
+
import type { Commit, ObjectId, PersonIdent } from "@statewalker/vcs-core";
|
|
2
2
|
import { DEFAULT_BIG_FILE_THRESHOLD } from "@statewalker/vcs-core";
|
|
3
|
-
import type { Edit } from "@statewalker/vcs-utils";
|
|
4
3
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
RawText,
|
|
9
|
-
RawTextComparator,
|
|
4
|
+
type InternedText,
|
|
5
|
+
LineInterner,
|
|
6
|
+
parseGitBool,
|
|
10
7
|
type SupportedAlgorithm,
|
|
8
|
+
whitespaceFlags,
|
|
9
|
+
type XdiffAlgorithm,
|
|
10
|
+
type XdiffOptions,
|
|
11
|
+
xdiffHunks,
|
|
11
12
|
} from "@statewalker/vcs-utils";
|
|
12
13
|
|
|
13
14
|
import { RefNotFoundError } from "../errors/ref-errors.js";
|
|
14
15
|
import { GitCommand } from "../git-command.js";
|
|
15
|
-
import {
|
|
16
|
+
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_RENAME_LIMIT,
|
|
19
|
+
DEFAULT_RENAME_SCORE,
|
|
20
|
+
detectRenames,
|
|
21
|
+
GIT_MAX_SCORE,
|
|
22
|
+
} from "../rename/index.js";
|
|
23
|
+
import { abbrevLengths } from "./core-config.js";
|
|
24
|
+
import { canonicalObjectId } from "./object-id-input.js";
|
|
25
|
+
|
|
26
|
+
/** Line bytes the interner holds before blame starts a new one (see `setInternerByteLimit`) */
|
|
27
|
+
const DEFAULT_INTERNER_BYTE_LIMIT = 64 * 1024 * 1024;
|
|
16
28
|
|
|
17
29
|
/**
|
|
18
30
|
* A single blame entry - represents authorship of one or more consecutive lines.
|
|
@@ -30,6 +42,13 @@ export interface BlameEntry {
|
|
|
30
42
|
resultStart: number;
|
|
31
43
|
/** Number of lines in this region */
|
|
32
44
|
lineCount: number;
|
|
45
|
+
/**
|
|
46
|
+
* The parent version the commit's lines were compared with (`previous` of
|
|
47
|
+
* `git blame --porcelain`), when the commit had the file in a parent
|
|
48
|
+
*/
|
|
49
|
+
previous?: { commitId: ObjectId; path: string };
|
|
50
|
+
/** A boundary commit (a root commit, unless `setShowRoot(true)`): `^` in git's output */
|
|
51
|
+
boundary?: boolean;
|
|
33
52
|
}
|
|
34
53
|
|
|
35
54
|
/**
|
|
@@ -61,8 +80,13 @@ export interface BlameResult {
|
|
|
61
80
|
path: string;
|
|
62
81
|
/** Total number of lines in the file */
|
|
63
82
|
lineCount: number;
|
|
64
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Blame entries in line order (git's, after coalescing); they cover all lines, or the
|
|
85
|
+
* line ranges asked for
|
|
86
|
+
*/
|
|
65
87
|
entries: BlameEntry[];
|
|
88
|
+
/** The blamed file's content at the start commit */
|
|
89
|
+
content?: Uint8Array;
|
|
66
90
|
/**
|
|
67
91
|
* Get the blame entry for a specific line (1-based).
|
|
68
92
|
*
|
|
@@ -87,10 +111,6 @@ export interface BlameResult {
|
|
|
87
111
|
/**
|
|
88
112
|
* Get the source line number in the original file.
|
|
89
113
|
*
|
|
90
|
-
* This returns the line number in the source commit where this line originated.
|
|
91
|
-
* When a file has been modified through history with insertions/deletions,
|
|
92
|
-
* the source line number may differ from the result line number.
|
|
93
|
-
*
|
|
94
114
|
* @param line Line number in the result file (1-based)
|
|
95
115
|
* @returns Source line number (1-based), or undefined if out of range
|
|
96
116
|
*/
|
|
@@ -98,10 +118,6 @@ export interface BlameResult {
|
|
|
98
118
|
/**
|
|
99
119
|
* Get the source path for a specific line.
|
|
100
120
|
*
|
|
101
|
-
* This returns the file path in the source commit. When rename tracking
|
|
102
|
-
* is enabled, this may differ from the result path if the line originated
|
|
103
|
-
* from a file with a different name.
|
|
104
|
-
*
|
|
105
121
|
* @param line Line number in the result file (1-based)
|
|
106
122
|
* @returns Source path, or undefined if out of range
|
|
107
123
|
*/
|
|
@@ -109,96 +125,199 @@ export interface BlameResult {
|
|
|
109
125
|
/**
|
|
110
126
|
* Get detailed tracking information for all lines.
|
|
111
127
|
*
|
|
112
|
-
* Returns an array of LineTracking objects, one per line in the result file.
|
|
113
|
-
* Each object contains complete origin information including the commit,
|
|
114
|
-
* source path, and source line number.
|
|
115
|
-
*
|
|
116
128
|
* @returns Array of LineTracking objects ordered by result line number
|
|
117
129
|
*/
|
|
118
130
|
getLineTracking(): LineTracking[];
|
|
131
|
+
/**
|
|
132
|
+
* The length git's default output abbreviates the commits to before room for boundary
|
|
133
|
+
* marks (`update_auto_abbrev`): the longest of their unique abbreviations, from
|
|
134
|
+
* `core.abbrev` (auto: from the repository's approximate object count). Pass it to
|
|
135
|
+
* `formatBlame` as `autoAbbrev`.
|
|
136
|
+
*/
|
|
137
|
+
autoAbbrev?(): Promise<number>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** A version of the file in a commit (`struct blame_origin`) */
|
|
141
|
+
interface Origin {
|
|
142
|
+
commitId: ObjectId;
|
|
143
|
+
path: string;
|
|
144
|
+
blobId: ObjectId;
|
|
145
|
+
mode: number;
|
|
146
|
+
/** Lines still suspected on this origin, sorted by `sLno` */
|
|
147
|
+
suspects: Entry | null;
|
|
148
|
+
previous?: Origin;
|
|
149
|
+
guilty: boolean;
|
|
150
|
+
/** The next origin of the same commit */
|
|
151
|
+
next: Origin | null;
|
|
152
|
+
/** The blob's lines (split and hashed once), while the origin is compared */
|
|
153
|
+
lines?: InternedText;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** A run of lines (`struct blame_entry`), 0-based */
|
|
157
|
+
interface Entry {
|
|
158
|
+
next: Entry | null;
|
|
159
|
+
suspect: Origin;
|
|
160
|
+
/** First line in the final file */
|
|
161
|
+
lno: number;
|
|
162
|
+
/** First line in the suspect's file */
|
|
163
|
+
sLno: number;
|
|
164
|
+
numLines: number;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Something with a `next` link: a list head or an entry (`struct blame_entry **`) */
|
|
168
|
+
interface Slot {
|
|
169
|
+
next: Entry | null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
interface CommitState {
|
|
173
|
+
commit: Commit;
|
|
174
|
+
origins: Origin | null;
|
|
175
|
+
uninteresting: boolean;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const S_IFMT = 0o170000;
|
|
179
|
+
const TREE_MODE = 0o040000;
|
|
180
|
+
const INT_MAX = Number.MAX_SAFE_INTEGER;
|
|
181
|
+
|
|
182
|
+
/** `reverse_blame`: `head` reversed, ending in `tail` */
|
|
183
|
+
function reverseBlame(head: Entry | null, tail: Entry | null): Entry | null {
|
|
184
|
+
let h = head;
|
|
185
|
+
let t = tail;
|
|
186
|
+
while (h) {
|
|
187
|
+
const next = h.next;
|
|
188
|
+
h.next = t;
|
|
189
|
+
t = h;
|
|
190
|
+
h = next;
|
|
191
|
+
}
|
|
192
|
+
return t;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** `blame_merge`: two lists sorted by `sLno` merged */
|
|
196
|
+
function blameMerge(list1: Entry | null, list2: Entry | null): Entry | null {
|
|
197
|
+
if (!list1) return list2;
|
|
198
|
+
if (!list2) return list1;
|
|
199
|
+
const head: Slot = { next: null };
|
|
200
|
+
let tail: Slot = head;
|
|
201
|
+
let p1: Entry | null = list1;
|
|
202
|
+
let p2: Entry | null = list2;
|
|
203
|
+
while (p1 && p2) {
|
|
204
|
+
if (p1.sLno <= p2.sLno) {
|
|
205
|
+
tail.next = p1;
|
|
206
|
+
tail = p1;
|
|
207
|
+
p1 = p1.next;
|
|
208
|
+
} else {
|
|
209
|
+
tail.next = p2;
|
|
210
|
+
tail = p2;
|
|
211
|
+
p2 = p2.next;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
tail.next = p1 ?? p2;
|
|
215
|
+
return head.next;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** `split_blame_at`: `e` keeps `len` lines, the rest is returned */
|
|
219
|
+
function splitBlameAt(e: Entry, len: number, suspect: Origin): Entry {
|
|
220
|
+
const n: Entry = {
|
|
221
|
+
next: null,
|
|
222
|
+
suspect,
|
|
223
|
+
lno: e.lno + len,
|
|
224
|
+
sLno: e.sLno + len,
|
|
225
|
+
numLines: e.numLines - len,
|
|
226
|
+
};
|
|
227
|
+
e.numLines = len;
|
|
228
|
+
return n;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** A priority queue of commits: newest committer date first, ties first in, first out */
|
|
232
|
+
class CommitQueue {
|
|
233
|
+
private heap: Array<{ id: ObjectId; date: number; ctr: number }> = [];
|
|
234
|
+
private ctr = 0;
|
|
235
|
+
|
|
236
|
+
private less(i: number, j: number): boolean {
|
|
237
|
+
const a = this.heap[i];
|
|
238
|
+
const b = this.heap[j];
|
|
239
|
+
if (a.date !== b.date) return a.date > b.date;
|
|
240
|
+
return a.ctr < b.ctr;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
put(id: ObjectId, date: number): void {
|
|
244
|
+
const h = this.heap;
|
|
245
|
+
h.push({ id, date, ctr: this.ctr++ });
|
|
246
|
+
let i = h.length - 1;
|
|
247
|
+
while (i > 0) {
|
|
248
|
+
const p = (i - 1) >> 1;
|
|
249
|
+
if (!this.less(i, p)) break;
|
|
250
|
+
[h[i], h[p]] = [h[p], h[i]];
|
|
251
|
+
i = p;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
get(): ObjectId | undefined {
|
|
256
|
+
const h = this.heap;
|
|
257
|
+
if (h.length === 0) return undefined;
|
|
258
|
+
const top = h[0];
|
|
259
|
+
const last = h.pop();
|
|
260
|
+
if (h.length > 0 && last) {
|
|
261
|
+
h[0] = last;
|
|
262
|
+
let i = 0;
|
|
263
|
+
for (;;) {
|
|
264
|
+
const l = 2 * i + 1;
|
|
265
|
+
const r = l + 1;
|
|
266
|
+
let m = i;
|
|
267
|
+
if (l < h.length && this.less(l, m)) m = l;
|
|
268
|
+
if (r < h.length && this.less(r, m)) m = r;
|
|
269
|
+
if (m === i) break;
|
|
270
|
+
[h[i], h[m]] = [h[m], h[i]];
|
|
271
|
+
i = m;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return top.id;
|
|
275
|
+
}
|
|
119
276
|
}
|
|
120
277
|
|
|
121
278
|
/**
|
|
122
|
-
* Annotate each line of a file with
|
|
123
|
-
*
|
|
124
|
-
* Equivalent to `git blame`.
|
|
279
|
+
* Annotate each line of a file with the commit that last changed it.
|
|
125
280
|
*
|
|
126
|
-
*
|
|
281
|
+
* Equivalent to `git blame`, and a port of git's algorithm (`blame.c`): the commits are
|
|
282
|
+
* visited newest first (committer date); each passes the lines it did not change to the
|
|
283
|
+
* parents that have the file (found by path, else, following renames, by git's rename
|
|
284
|
+
* detection), comparing with each parent's version through the same xdiff diff git uses
|
|
285
|
+
* (`diff.algorithm`, default myers, and `diff.indentHeuristic`, default on); the lines left
|
|
286
|
+
* are its own. A parent with the same blob takes all lines. Root commits are boundaries
|
|
287
|
+
* unless `setShowRoot(true)` (`blame.showRoot`).
|
|
127
288
|
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* using diff algorithms to trace the origin of each line.
|
|
289
|
+
* Moves and copies across lines (`-M`, `-C`), `--reverse`, `--ignore-rev` and the mailmap
|
|
290
|
+
* are not supported.
|
|
131
291
|
*
|
|
132
292
|
* @example
|
|
133
293
|
* ```typescript
|
|
134
|
-
*
|
|
135
|
-
* const result = await git.blame()
|
|
136
|
-
* .setFilePath("src/main.ts")
|
|
137
|
-
* .call();
|
|
138
|
-
*
|
|
139
|
-
* // Get author of line 42
|
|
294
|
+
* const result = await git.blame().setFilePath("src/main.ts").call();
|
|
140
295
|
* const author = result.getSourceAuthor(42);
|
|
141
|
-
* console.log(`Line 42 written by: ${author?.name}`);
|
|
142
|
-
*
|
|
143
|
-
* // Blame at a specific commit
|
|
144
|
-
* const result = await git.blame()
|
|
145
|
-
* .setFilePath("README.md")
|
|
146
|
-
* .setStartCommit(commitId)
|
|
147
|
-
* .call();
|
|
148
296
|
*
|
|
149
|
-
* //
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
297
|
+
* // `git blame --porcelain -w -L 10,20 README.md`
|
|
298
|
+
* const blame = await git.blame().setFilePath("README.md").setIgnoreWhitespace(true)
|
|
299
|
+
* .setLineRanges([[10, 20]]).call();
|
|
300
|
+
* process.stdout.write(formatBlamePorcelain(blame));
|
|
153
301
|
* ```
|
|
154
302
|
*/
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Represents a region of the result file that still needs blame attribution.
|
|
158
|
-
* Modeled after JGit's Region class.
|
|
159
|
-
*
|
|
160
|
-
* Regions track both the position in the result file and the current source position
|
|
161
|
-
* (which may differ as we trace back through history due to insertions/deletions).
|
|
162
|
-
*/
|
|
163
|
-
interface BlameRegion {
|
|
164
|
-
/** Position in the result file (1-based) */
|
|
165
|
-
resultStart: number;
|
|
166
|
-
/** Position in the current source file being examined (1-based) */
|
|
167
|
-
sourceStart: number;
|
|
168
|
-
/** Number of lines in this region */
|
|
169
|
-
length: number;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Represents a candidate commit that may have contributed lines to the result.
|
|
174
|
-
* Modeled after JGit's Candidate class.
|
|
175
|
-
*/
|
|
176
|
-
interface BlameCandidate {
|
|
177
|
-
/** The commit being examined */
|
|
178
|
-
commit: Commit;
|
|
179
|
-
/** Commit ID */
|
|
180
|
-
commitId: ObjectId;
|
|
181
|
-
/** Current path being tracked */
|
|
182
|
-
path: string;
|
|
183
|
-
/** Blob ID of the file in this commit */
|
|
184
|
-
blobId: ObjectId;
|
|
185
|
-
/** Content of the file */
|
|
186
|
-
content: Uint8Array;
|
|
187
|
-
/** RawText for diff operations */
|
|
188
|
-
rawText: RawText;
|
|
189
|
-
/** Regions this candidate is responsible for */
|
|
190
|
-
regions: BlameRegion[];
|
|
191
|
-
/** Commit time for priority queue ordering */
|
|
192
|
-
time: number;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
303
|
export class BlameCommand extends GitCommand<BlameResult> {
|
|
196
304
|
private filePath?: string;
|
|
197
305
|
private startCommit?: ObjectId;
|
|
198
|
-
private followRenames =
|
|
306
|
+
private followRenames = true;
|
|
199
307
|
private renameScore = DEFAULT_RENAME_SCORE;
|
|
200
|
-
private
|
|
308
|
+
private algorithm?: XdiffAlgorithm;
|
|
201
309
|
private bigFileThreshold = DEFAULT_BIG_FILE_THRESHOLD;
|
|
310
|
+
private ignoreWhitespace = false;
|
|
311
|
+
private internerByteLimit = DEFAULT_INTERNER_BYTE_LIMIT;
|
|
312
|
+
private indentHeuristic?: boolean;
|
|
313
|
+
private showRoot?: boolean;
|
|
314
|
+
private lineRanges: Array<[number, number]> = [];
|
|
315
|
+
private diffOptions: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> = {};
|
|
316
|
+
private renameCountLastSpan?: boolean;
|
|
317
|
+
|
|
318
|
+
private states = new Map<ObjectId, CommitState>();
|
|
319
|
+
/** Numbers the lines of every version compared, so each is split and hashed once */
|
|
320
|
+
private interner?: LineInterner;
|
|
202
321
|
|
|
203
322
|
/**
|
|
204
323
|
* Set the file path to blame.
|
|
@@ -219,16 +338,15 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
219
338
|
* @param commit ObjectId of the starting commit
|
|
220
339
|
*/
|
|
221
340
|
setStartCommit(commit: ObjectId): this {
|
|
341
|
+
commit = canonicalObjectId(commit);
|
|
222
342
|
this.checkCallable();
|
|
223
343
|
this.startCommit = commit;
|
|
224
344
|
return this;
|
|
225
345
|
}
|
|
226
346
|
|
|
227
347
|
/**
|
|
228
|
-
* Set whether to follow file renames
|
|
229
|
-
*
|
|
230
|
-
* When enabled, the blame will track lines through renames.
|
|
231
|
-
* This is more accurate but slower.
|
|
348
|
+
* Set whether to follow whole-file renames (default true, as git; false is
|
|
349
|
+
* `--no-follow`).
|
|
232
350
|
*
|
|
233
351
|
* @param follow Whether to follow renames
|
|
234
352
|
*/
|
|
@@ -250,13 +368,61 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
250
368
|
}
|
|
251
369
|
|
|
252
370
|
/**
|
|
253
|
-
* Set the diff algorithm
|
|
371
|
+
* Set the diff algorithm (`--diff-algorithm`; default `diff.algorithm`, else myers).
|
|
254
372
|
*
|
|
255
|
-
* @param algorithm The algorithm to use
|
|
373
|
+
* @param algorithm The algorithm to use
|
|
256
374
|
*/
|
|
257
|
-
setAlgorithm(algorithm: SupportedAlgorithm): this {
|
|
375
|
+
setAlgorithm(algorithm: SupportedAlgorithm | XdiffAlgorithm): this {
|
|
258
376
|
this.checkCallable();
|
|
259
|
-
this.
|
|
377
|
+
this.algorithm = String(algorithm) as XdiffAlgorithm;
|
|
378
|
+
return this;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** Ignore whitespace when comparing versions (`-w`) */
|
|
382
|
+
setIgnoreWhitespace(ignore: boolean): this {
|
|
383
|
+
this.checkCallable();
|
|
384
|
+
this.ignoreWhitespace = ignore;
|
|
385
|
+
return this;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** The indent heuristic (default `diff.indentHeuristic`, true) */
|
|
389
|
+
setIndentHeuristic(on: boolean): this {
|
|
390
|
+
this.checkCallable();
|
|
391
|
+
this.indentHeuristic = on;
|
|
392
|
+
return this;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** Do not treat root commits as boundaries (`--root`; default `blame.showRoot`) */
|
|
396
|
+
setShowRoot(show: boolean): this {
|
|
397
|
+
this.checkCallable();
|
|
398
|
+
this.showRoot = show;
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Blame only these line ranges (`-L <start>,<end>`, 1-based, inclusive), merged as git
|
|
404
|
+
* merges overlapping ranges.
|
|
405
|
+
*/
|
|
406
|
+
setLineRanges(ranges: Array<[number, number]>): this {
|
|
407
|
+
this.checkCallable();
|
|
408
|
+
this.lineRanges = ranges.map(([s, e]) => [s, e]);
|
|
409
|
+
return this;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Diff details that changed between git versions: `histogramRediff` (git 2.54+, default
|
|
414
|
+
* true), `legacyMinimal` (git before 2.5x), and `renameCountLastSpan` (rename scores of
|
|
415
|
+
* git 2.50+, default true)
|
|
416
|
+
*/
|
|
417
|
+
setCompatibility(
|
|
418
|
+
options: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> & {
|
|
419
|
+
renameCountLastSpan?: boolean;
|
|
420
|
+
},
|
|
421
|
+
): this {
|
|
422
|
+
this.checkCallable();
|
|
423
|
+
const { renameCountLastSpan, ...diff } = options;
|
|
424
|
+
this.diffOptions = { ...this.diffOptions, ...diff };
|
|
425
|
+
if (renameCountLastSpan !== undefined) this.renameCountLastSpan = renameCountLastSpan;
|
|
260
426
|
return this;
|
|
261
427
|
}
|
|
262
428
|
|
|
@@ -277,10 +443,21 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
277
443
|
}
|
|
278
444
|
|
|
279
445
|
/**
|
|
280
|
-
*
|
|
446
|
+
* Set how many bytes of distinct lines the line interner may hold (default 64 MiB). The
|
|
447
|
+
* interner keeps every distinct line it has seen; past this size blame starts a new one for
|
|
448
|
+
* the versions it reads next, and re-interns a version from the old one when it is compared
|
|
449
|
+
* with one from the new. The output does not change.
|
|
281
450
|
*
|
|
282
|
-
*
|
|
283
|
-
|
|
451
|
+
* @param bytes Size in bytes
|
|
452
|
+
*/
|
|
453
|
+
setInternerByteLimit(bytes: number): this {
|
|
454
|
+
this.checkCallable();
|
|
455
|
+
this.internerByteLimit = bytes;
|
|
456
|
+
return this;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Execute the blame command.
|
|
284
461
|
*
|
|
285
462
|
* @returns BlameResult with per-line authorship
|
|
286
463
|
*/
|
|
@@ -291,8 +468,11 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
291
468
|
if (!this.filePath) {
|
|
292
469
|
throw new Error("File path must be set");
|
|
293
470
|
}
|
|
471
|
+
const config = RemoteConfigStore.from(this.workingCopy);
|
|
472
|
+
this.algorithm ??= algorithmValue(config.value("diff.algorithm")) ?? "myers";
|
|
473
|
+
this.indentHeuristic ??= boolValue(config.value("diff.indentHeuristic")) ?? true;
|
|
474
|
+
this.showRoot ??= boolValue(config.value("blame.showRoot")) ?? false;
|
|
294
475
|
|
|
295
|
-
// Resolve starting commit
|
|
296
476
|
let startId = this.startCommit;
|
|
297
477
|
if (!startId) {
|
|
298
478
|
const head = await this.refsStore.resolve("HEAD");
|
|
@@ -303,776 +483,351 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
303
483
|
}
|
|
304
484
|
|
|
305
485
|
const resultPath = this.filePath;
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
// Load the file content at the starting commit
|
|
309
|
-
const startCommit = await this.commits.load(startId);
|
|
310
|
-
if (!startCommit) {
|
|
486
|
+
const start = await this.state(startId);
|
|
487
|
+
if (!start) {
|
|
311
488
|
throw new RefNotFoundError(`Cannot find commit: ${startId}`);
|
|
312
489
|
}
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
if (!blobId) {
|
|
490
|
+
const entry = await this.lookup(start.commit.tree, resultPath);
|
|
491
|
+
if (!entry) {
|
|
316
492
|
throw new Error(`File not found: ${resultPath}`);
|
|
317
493
|
}
|
|
318
|
-
|
|
319
|
-
const size = await this.blobs.size(blobId);
|
|
494
|
+
const size = await this.blobs.size(entry.id);
|
|
320
495
|
if (size > this.bigFileThreshold) {
|
|
321
496
|
throw new Error(
|
|
322
497
|
`${resultPath} is ${size} bytes, larger than bigFileThreshold (${this.bigFileThreshold})`,
|
|
323
498
|
);
|
|
324
499
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
const parentCount = candidate.commit.parents.length;
|
|
366
|
-
|
|
367
|
-
if (parentCount === 0) {
|
|
368
|
-
// Root commit - blame all remaining regions to this commit
|
|
369
|
-
this.blameRegions(entries, candidate);
|
|
370
|
-
remaining -= this.countRegionLines(candidate.regions);
|
|
371
|
-
} else if (parentCount === 1) {
|
|
372
|
-
// Single parent - process normally
|
|
373
|
-
const blamed = await this.processOneParent(candidate, queue, seen, entries);
|
|
374
|
-
remaining -= blamed;
|
|
375
|
-
} else {
|
|
376
|
-
// Merge commit - process all parents (JGit's processMerge)
|
|
377
|
-
const blamed = await this.processMerge(candidate, queue, seen, entries);
|
|
378
|
-
remaining -= blamed;
|
|
379
|
-
}
|
|
500
|
+
const finalOrigin = this.getOrigin(startId, resultPath);
|
|
501
|
+
finalOrigin.blobId = entry.id;
|
|
502
|
+
finalOrigin.mode = entry.mode;
|
|
503
|
+
const content = await this.readBlob(entry.id);
|
|
504
|
+
finalOrigin.lines = this.lineInterner().text(content);
|
|
505
|
+
const lineCount = countLines(content);
|
|
506
|
+
|
|
507
|
+
// the initial entries: the whole file, or the -L ranges (sorted and merged)
|
|
508
|
+
const ranges = this.ranges(lineCount);
|
|
509
|
+
let head: Entry | null = null;
|
|
510
|
+
for (let i = ranges.length - 1; i >= 0; i--) {
|
|
511
|
+
const [s, e] = ranges[i];
|
|
512
|
+
head = { next: head, suspect: finalOrigin, lno: s, sLno: s, numLines: e - s };
|
|
513
|
+
}
|
|
514
|
+
const final: Slot = { next: null };
|
|
515
|
+
if (head) {
|
|
516
|
+
finalOrigin.suspects = head;
|
|
517
|
+
const queue = new CommitQueue();
|
|
518
|
+
queue.put(startId, start.commit.committer.timestamp);
|
|
519
|
+
await this.assignBlame(queue, final);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// blame_sort_final, blame_coalesce
|
|
523
|
+
const ents: Entry[] = [];
|
|
524
|
+
for (let e = final.next; e; e = e.next) ents.push(e);
|
|
525
|
+
ents.sort((a, b) => a.lno - b.lno);
|
|
526
|
+
const coalesced: Entry[] = [];
|
|
527
|
+
for (const e of ents) {
|
|
528
|
+
const last = coalesced[coalesced.length - 1];
|
|
529
|
+
if (
|
|
530
|
+
last &&
|
|
531
|
+
last.suspect === e.suspect &&
|
|
532
|
+
last.sLno + last.numLines === e.sLno &&
|
|
533
|
+
last.lno + last.numLines === e.lno
|
|
534
|
+
) {
|
|
535
|
+
last.numLines += e.numLines;
|
|
536
|
+
} else coalesced.push({ ...e });
|
|
380
537
|
}
|
|
381
538
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
candidate: BlameCandidate,
|
|
398
|
-
queue: BlameCandidate[],
|
|
399
|
-
seen: Set<ObjectId>,
|
|
400
|
-
entries: BlameEntry[],
|
|
401
|
-
): Promise<number> {
|
|
402
|
-
const parentId = candidate.commit.parents[0];
|
|
403
|
-
const parentCommit = await this.commits.load(parentId);
|
|
404
|
-
if (!parentCommit) {
|
|
405
|
-
// Parent commit not found - blame all regions to this commit
|
|
406
|
-
this.blameRegions(entries, candidate);
|
|
407
|
-
return this.countRegionLines(candidate.regions);
|
|
539
|
+
const entries: BlameEntry[] = [];
|
|
540
|
+
for (const e of coalesced) {
|
|
541
|
+
const st = this.states.get(e.suspect.commitId);
|
|
542
|
+
if (!st) continue;
|
|
543
|
+
const prev = e.suspect.previous;
|
|
544
|
+
entries.push({
|
|
545
|
+
commit: st.commit,
|
|
546
|
+
commitId: e.suspect.commitId,
|
|
547
|
+
sourcePath: e.suspect.path,
|
|
548
|
+
sourceStart: e.sLno + 1,
|
|
549
|
+
resultStart: e.lno + 1,
|
|
550
|
+
lineCount: e.numLines,
|
|
551
|
+
...(prev ? { previous: { commitId: prev.commitId, path: prev.path } } : {}),
|
|
552
|
+
boundary: st.uninteresting,
|
|
553
|
+
});
|
|
408
554
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (!parentBlobId && this.followRenames) {
|
|
416
|
-
const rename = await this.findRename(
|
|
417
|
-
parentCommit.tree,
|
|
418
|
-
candidate.commit.tree,
|
|
419
|
-
candidate.path,
|
|
420
|
-
candidate.content,
|
|
555
|
+
const result = createBlameResult(resultPath, lineCount, entries, content);
|
|
556
|
+
const workingCopy = this.workingCopy;
|
|
557
|
+
result.autoAbbrev = async () => {
|
|
558
|
+
const lengths = await abbrevLengths(
|
|
559
|
+
workingCopy,
|
|
560
|
+
entries.map((e) => e.commitId),
|
|
421
561
|
);
|
|
562
|
+
return lengths.size > 0 ? Math.max(...lengths.values()) : 7;
|
|
563
|
+
};
|
|
564
|
+
return result;
|
|
565
|
+
}
|
|
422
566
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
567
|
+
/** The -L ranges as 0-based half-open ranges, sorted and merged; the whole file otherwise */
|
|
568
|
+
private ranges(lineCount: number): Array<[number, number]> {
|
|
569
|
+
if (this.lineRanges.length === 0) return lineCount > 0 ? [[0, lineCount]] : [];
|
|
570
|
+
const out: Array<[number, number]> = [];
|
|
571
|
+
for (const [s, e] of this.lineRanges) {
|
|
572
|
+
let bottom = s;
|
|
573
|
+
let top = e;
|
|
574
|
+
if (top < bottom) [bottom, top] = [top, bottom];
|
|
575
|
+
if (bottom < 1) bottom = 1;
|
|
576
|
+
if (lineCount < bottom) {
|
|
577
|
+
throw new Error(`file ${this.filePath} has only ${lineCount} lines`);
|
|
426
578
|
}
|
|
579
|
+
if (top > lineCount) top = lineCount;
|
|
580
|
+
out.push([bottom - 1, top]);
|
|
427
581
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
if (!parentBlobId) {
|
|
435
|
-
// File was introduced in this commit - blame all regions
|
|
436
|
-
this.blameRegions(entries, candidate);
|
|
437
|
-
return this.countRegionLines(candidate.regions);
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// If blob is identical, pass blame to parent without diffing
|
|
441
|
-
if (parentBlobId === candidate.blobId) {
|
|
442
|
-
const parentContent = await this.collectBlob(parentBlobId);
|
|
443
|
-
const parentCandidate: BlameCandidate = {
|
|
444
|
-
commit: parentCommit,
|
|
445
|
-
commitId: parentId,
|
|
446
|
-
path: parentPath,
|
|
447
|
-
blobId: parentBlobId,
|
|
448
|
-
content: parentContent,
|
|
449
|
-
rawText: new RawText(parentContent),
|
|
450
|
-
regions: candidate.regions,
|
|
451
|
-
time: parentCommit.author.timestamp * 1000,
|
|
452
|
-
};
|
|
453
|
-
this.pushCandidate(queue, parentCandidate, seen);
|
|
454
|
-
return 0;
|
|
582
|
+
out.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
583
|
+
const merged: Array<[number, number]> = [];
|
|
584
|
+
for (const r of out) {
|
|
585
|
+
const last = merged[merged.length - 1];
|
|
586
|
+
if (last && r[0] <= last[1]) last[1] = Math.max(last[1], r[1]);
|
|
587
|
+
else merged.push([r[0], r[1]]);
|
|
455
588
|
}
|
|
456
|
-
|
|
457
|
-
// Compute diff and split blame
|
|
458
|
-
const parentContent = await this.collectBlob(parentBlobId);
|
|
459
|
-
const parentRawText = new RawText(parentContent);
|
|
460
|
-
|
|
461
|
-
return this.splitBlame(
|
|
462
|
-
candidate,
|
|
463
|
-
parentCommit,
|
|
464
|
-
parentId,
|
|
465
|
-
parentPath,
|
|
466
|
-
parentBlobId,
|
|
467
|
-
parentContent,
|
|
468
|
-
parentRawText,
|
|
469
|
-
queue,
|
|
470
|
-
seen,
|
|
471
|
-
entries,
|
|
472
|
-
);
|
|
589
|
+
return merged;
|
|
473
590
|
}
|
|
474
591
|
|
|
475
|
-
/**
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
*
|
|
485
|
-
* @returns Number of lines blamed to the merge commit
|
|
486
|
-
*/
|
|
487
|
-
private async processMerge(
|
|
488
|
-
candidate: BlameCandidate,
|
|
489
|
-
queue: BlameCandidate[],
|
|
490
|
-
seen: Set<ObjectId>,
|
|
491
|
-
entries: BlameEntry[],
|
|
492
|
-
): Promise<number> {
|
|
493
|
-
const parentCount = candidate.commit.parents.length;
|
|
494
|
-
|
|
495
|
-
// Collect parent info
|
|
496
|
-
interface ParentInfo {
|
|
497
|
-
commit: Commit;
|
|
498
|
-
commitId: ObjectId;
|
|
499
|
-
blobId: ObjectId;
|
|
500
|
-
path: string;
|
|
501
|
-
content: Uint8Array;
|
|
502
|
-
rawText: RawText;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
const parentInfos: (ParentInfo | null)[] = [];
|
|
506
|
-
|
|
507
|
-
// First pass: check all parents for the file
|
|
508
|
-
for (let pIdx = 0; pIdx < parentCount; pIdx++) {
|
|
509
|
-
const parentId = candidate.commit.parents[pIdx];
|
|
510
|
-
const parentCommit = await this.commits.load(parentId);
|
|
511
|
-
if (!parentCommit) {
|
|
512
|
-
parentInfos.push(null);
|
|
592
|
+
/** git's `assign_blame` */
|
|
593
|
+
private async assignBlame(queue: CommitQueue, final: Slot): Promise<void> {
|
|
594
|
+
let commitId = queue.get();
|
|
595
|
+
while (commitId) {
|
|
596
|
+
const st = this.states.get(commitId);
|
|
597
|
+
let suspect = st?.origins ?? null;
|
|
598
|
+
while (suspect && !suspect.suspects) suspect = suspect.next;
|
|
599
|
+
if (!st || !suspect) {
|
|
600
|
+
commitId = queue.get();
|
|
513
601
|
continue;
|
|
514
602
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
if (
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
);
|
|
527
|
-
if (rename) {
|
|
528
|
-
parentBlobId = rename.oldBlobId;
|
|
529
|
-
parentPath = rename.oldPath;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
if (parentBlobId && parentBlobId !== candidate.blobId && (await this.isBig(parentBlobId))) {
|
|
534
|
-
parentBlobId = undefined;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
if (parentBlobId) {
|
|
538
|
-
// If any parent has identical blob, pass all blame to that parent
|
|
539
|
-
if (parentBlobId === candidate.blobId) {
|
|
540
|
-
const parentContent = await this.collectBlob(parentBlobId);
|
|
541
|
-
const parentCandidate: BlameCandidate = {
|
|
542
|
-
commit: parentCommit,
|
|
543
|
-
commitId: parentId,
|
|
544
|
-
path: parentPath,
|
|
545
|
-
blobId: parentBlobId,
|
|
546
|
-
content: parentContent,
|
|
547
|
-
rawText: new RawText(parentContent),
|
|
548
|
-
regions: candidate.regions,
|
|
549
|
-
time: parentCommit.author.timestamp * 1000,
|
|
550
|
-
};
|
|
551
|
-
this.pushCandidate(queue, parentCandidate, seen);
|
|
552
|
-
return 0;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const parentContent = await this.collectBlob(parentBlobId);
|
|
556
|
-
parentInfos.push({
|
|
557
|
-
commit: parentCommit,
|
|
558
|
-
commitId: parentId,
|
|
559
|
-
blobId: parentBlobId,
|
|
560
|
-
path: parentPath,
|
|
561
|
-
content: parentContent,
|
|
562
|
-
rawText: new RawText(parentContent),
|
|
563
|
-
});
|
|
564
|
-
} else {
|
|
565
|
-
parentInfos.push(null);
|
|
603
|
+
if (!st.uninteresting) await this.passBlame(suspect, queue);
|
|
604
|
+
// treat root commit as boundary
|
|
605
|
+
if (st.commit.parents.length === 0 && !this.showRoot) st.uninteresting = true;
|
|
606
|
+
// take responsibility for the remaining entries
|
|
607
|
+
let ent = suspect.suspects;
|
|
608
|
+
if (ent) {
|
|
609
|
+
suspect.guilty = true;
|
|
610
|
+
while (ent.next) ent = ent.next;
|
|
611
|
+
ent.next = final.next;
|
|
612
|
+
final.next = suspect.suspects;
|
|
613
|
+
suspect.suspects = null;
|
|
566
614
|
}
|
|
567
615
|
}
|
|
568
|
-
|
|
569
|
-
// If no parents have the file, blame everything to this commit
|
|
570
|
-
const validParents = parentInfos.filter((p): p is ParentInfo => p !== null);
|
|
571
|
-
if (validParents.length === 0) {
|
|
572
|
-
this.blameRegions(entries, candidate);
|
|
573
|
-
return this.countRegionLines(candidate.regions);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// Process each parent and split blame
|
|
577
|
-
// We track which regions have been passed to parents
|
|
578
|
-
let currentRegions = candidate.regions;
|
|
579
|
-
|
|
580
|
-
for (const parentInfo of validParents) {
|
|
581
|
-
if (currentRegions.length === 0) break;
|
|
582
|
-
|
|
583
|
-
// Compute diff between parent and candidate
|
|
584
|
-
const comparator = RawTextComparator.DEFAULT;
|
|
585
|
-
const edits = this.diffAlgorithm(comparator, parentInfo.rawText, candidate.rawText);
|
|
586
|
-
|
|
587
|
-
// Split regions between parent and candidate
|
|
588
|
-
const { parentRegions, childRegions } = this.takeBlame(edits, currentRegions);
|
|
589
|
-
|
|
590
|
-
// Push parent candidate if it has regions
|
|
591
|
-
if (parentRegions.length > 0) {
|
|
592
|
-
const parentCandidate: BlameCandidate = {
|
|
593
|
-
commit: parentInfo.commit,
|
|
594
|
-
commitId: parentInfo.commitId,
|
|
595
|
-
path: parentInfo.path,
|
|
596
|
-
blobId: parentInfo.blobId,
|
|
597
|
-
content: parentInfo.content,
|
|
598
|
-
rawText: parentInfo.rawText,
|
|
599
|
-
regions: parentRegions,
|
|
600
|
-
time: parentInfo.commit.author.timestamp * 1000,
|
|
601
|
-
};
|
|
602
|
-
this.pushCandidate(queue, parentCandidate, seen);
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// Remaining regions stay with the merge commit
|
|
606
|
-
currentRegions = childRegions;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
// Any remaining regions are blamed to the merge commit
|
|
610
|
-
// (these are conflict resolution lines)
|
|
611
|
-
if (currentRegions.length > 0) {
|
|
612
|
-
const mergeCandidate: BlameCandidate = {
|
|
613
|
-
...candidate,
|
|
614
|
-
regions: currentRegions,
|
|
615
|
-
};
|
|
616
|
-
this.blameRegions(entries, mergeCandidate);
|
|
617
|
-
return this.countRegionLines(currentRegions);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
return 0;
|
|
621
616
|
}
|
|
622
617
|
|
|
623
|
-
/**
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
for (const region of regions) {
|
|
645
|
-
// Convert to 0-based for comparison with edits
|
|
646
|
-
const regionStart = region.sourceStart - 1;
|
|
647
|
-
const regionEnd = regionStart + region.length;
|
|
648
|
-
|
|
649
|
-
// Track what parts of this region are covered by edits (changes)
|
|
650
|
-
// and what parts are unchanged (should go to parent)
|
|
651
|
-
const changedRanges: Array<{ start: number; end: number }> = [];
|
|
652
|
-
|
|
653
|
-
for (const edit of edits) {
|
|
654
|
-
// Edit's B side (child/new) tells us which lines in the child are different
|
|
655
|
-
const editStart = edit.beginB;
|
|
656
|
-
const editEnd = edit.endB;
|
|
657
|
-
|
|
658
|
-
// Check if edit overlaps with region
|
|
659
|
-
if (editEnd <= regionStart || editStart >= regionEnd) {
|
|
660
|
-
continue; // No overlap
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// Compute overlap
|
|
664
|
-
const overlapStart = Math.max(editStart, regionStart);
|
|
665
|
-
const overlapEnd = Math.min(editEnd, regionEnd);
|
|
666
|
-
|
|
667
|
-
if (overlapEnd > overlapStart) {
|
|
668
|
-
changedRanges.push({ start: overlapStart, end: overlapEnd });
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
// Sort and merge overlapping changed ranges
|
|
673
|
-
changedRanges.sort((a, b) => a.start - b.start);
|
|
674
|
-
const mergedChanges: Array<{ start: number; end: number }> = [];
|
|
675
|
-
for (const range of changedRanges) {
|
|
676
|
-
if (
|
|
677
|
-
mergedChanges.length === 0 ||
|
|
678
|
-
mergedChanges[mergedChanges.length - 1].end < range.start
|
|
679
|
-
) {
|
|
680
|
-
mergedChanges.push({ ...range });
|
|
681
|
-
} else {
|
|
682
|
-
mergedChanges[mergedChanges.length - 1].end = Math.max(
|
|
683
|
-
mergedChanges[mergedChanges.length - 1].end,
|
|
684
|
-
range.end,
|
|
685
|
-
);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
// Now split the region: unchanged parts go to parent, changed parts stay with child
|
|
690
|
-
// For unchanged parts, we need to create separate regions for each contiguous block
|
|
691
|
-
// in the parent, since mapping through edits may create gaps.
|
|
692
|
-
let pos = regionStart;
|
|
693
|
-
|
|
694
|
-
for (const change of mergedChanges) {
|
|
695
|
-
// Unchanged part before this change - process line by line to handle non-contiguous mapping
|
|
696
|
-
if (change.start > pos) {
|
|
697
|
-
this.addParentRegionsForUnchangedBlock(
|
|
698
|
-
pos,
|
|
699
|
-
change.start,
|
|
700
|
-
region.resultStart,
|
|
701
|
-
regionStart,
|
|
702
|
-
edits,
|
|
703
|
-
parentRegions,
|
|
704
|
-
);
|
|
618
|
+
/** git's `pass_blame` (without -M/-C) */
|
|
619
|
+
private async passBlame(origin: Origin, queue: CommitQueue): Promise<void> {
|
|
620
|
+
const st = this.states.get(origin.commitId);
|
|
621
|
+
if (!st) return;
|
|
622
|
+
const parents = st.commit.parents;
|
|
623
|
+
const n = parents.length;
|
|
624
|
+
if (n === 0) return;
|
|
625
|
+
const sgOrigin: Array<Origin | undefined> = new Array(n).fill(undefined);
|
|
626
|
+
for (let pass = 0; pass < (this.followRenames ? 2 : 1); pass++) {
|
|
627
|
+
for (let i = 0; i < n; i++) {
|
|
628
|
+
if (sgOrigin[i]) continue;
|
|
629
|
+
const parent = await this.state(parents[i]);
|
|
630
|
+
if (!parent) continue;
|
|
631
|
+
const porigin = pass
|
|
632
|
+
? await this.findRename(parents[i], origin)
|
|
633
|
+
: await this.findOrigin(parents[i], origin);
|
|
634
|
+
if (!porigin) continue;
|
|
635
|
+
if (porigin.blobId === origin.blobId) {
|
|
636
|
+
this.passWholeBlame(origin, porigin, queue);
|
|
637
|
+
return;
|
|
705
638
|
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
length: change.end - change.start,
|
|
713
|
-
});
|
|
639
|
+
let same = false;
|
|
640
|
+
for (let j = 0; j < i; j++) {
|
|
641
|
+
if (sgOrigin[j] && sgOrigin[j]?.blobId === porigin.blobId) {
|
|
642
|
+
same = true;
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
714
645
|
}
|
|
715
|
-
|
|
716
|
-
pos = change.end;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
// Remaining unchanged part after last change
|
|
720
|
-
if (pos < regionEnd) {
|
|
721
|
-
this.addParentRegionsForUnchangedBlock(
|
|
722
|
-
pos,
|
|
723
|
-
regionEnd,
|
|
724
|
-
region.resultStart,
|
|
725
|
-
regionStart,
|
|
726
|
-
edits,
|
|
727
|
-
parentRegions,
|
|
728
|
-
);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
return { parentRegions, childRegions };
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
/**
|
|
736
|
-
* Add parent regions for an unchanged block of lines.
|
|
737
|
-
* Since lines may map to non-contiguous positions in the parent
|
|
738
|
-
* (due to deletions), we need to create separate regions for each
|
|
739
|
-
* contiguous block in the parent.
|
|
740
|
-
*/
|
|
741
|
-
private addParentRegionsForUnchangedBlock(
|
|
742
|
-
startPos: number,
|
|
743
|
-
endPos: number,
|
|
744
|
-
resultStart: number,
|
|
745
|
-
regionStart: number,
|
|
746
|
-
edits: Edit[],
|
|
747
|
-
parentRegions: BlameRegion[],
|
|
748
|
-
): void {
|
|
749
|
-
// Map each line position and group into contiguous regions in the parent
|
|
750
|
-
let currentParentStart = -1;
|
|
751
|
-
let currentResultStart = -1;
|
|
752
|
-
let currentLength = 0;
|
|
753
|
-
let lastParentPos = -1;
|
|
754
|
-
|
|
755
|
-
for (let childPos = startPos; childPos < endPos; childPos++) {
|
|
756
|
-
const parentPos = this.mapPositionToParent(childPos, edits);
|
|
757
|
-
|
|
758
|
-
if (currentLength === 0) {
|
|
759
|
-
// Start a new region
|
|
760
|
-
currentParentStart = parentPos;
|
|
761
|
-
currentResultStart = resultStart + (childPos - regionStart);
|
|
762
|
-
currentLength = 1;
|
|
763
|
-
lastParentPos = parentPos;
|
|
764
|
-
} else if (parentPos === lastParentPos + 1) {
|
|
765
|
-
// Extend current region (contiguous in parent)
|
|
766
|
-
currentLength++;
|
|
767
|
-
lastParentPos = parentPos;
|
|
768
|
-
} else {
|
|
769
|
-
// Gap in parent - push current region and start new one
|
|
770
|
-
parentRegions.push({
|
|
771
|
-
resultStart: currentResultStart,
|
|
772
|
-
sourceStart: currentParentStart + 1, // Convert to 1-based
|
|
773
|
-
length: currentLength,
|
|
774
|
-
});
|
|
775
|
-
currentParentStart = parentPos;
|
|
776
|
-
currentResultStart = resultStart + (childPos - regionStart);
|
|
777
|
-
currentLength = 1;
|
|
778
|
-
lastParentPos = parentPos;
|
|
646
|
+
if (!same) sgOrigin[i] = porigin;
|
|
779
647
|
}
|
|
780
648
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
length: currentLength,
|
|
788
|
-
});
|
|
649
|
+
for (let i = 0; i < n; i++) {
|
|
650
|
+
const porigin = sgOrigin[i];
|
|
651
|
+
if (!porigin) continue;
|
|
652
|
+
if (!origin.previous) origin.previous = porigin;
|
|
653
|
+
await this.passBlameToParent(origin, porigin, queue);
|
|
654
|
+
if (!origin.suspects) break;
|
|
789
655
|
}
|
|
656
|
+
origin.lines = undefined;
|
|
790
657
|
}
|
|
791
658
|
|
|
792
|
-
/**
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
* @param edits Edit list from diff
|
|
798
|
-
* @returns 0-based position in parent
|
|
799
|
-
*/
|
|
800
|
-
private mapPositionToParent(childPos: number, edits: Edit[]): number {
|
|
801
|
-
let offset = 0;
|
|
802
|
-
|
|
803
|
-
for (const edit of edits) {
|
|
804
|
-
if (edit.endB <= childPos) {
|
|
805
|
-
// This edit is before our position
|
|
806
|
-
// Adjust offset: lengthA - lengthB gives the shift
|
|
807
|
-
const lengthA = edit.endA - edit.beginA;
|
|
808
|
-
const lengthB = edit.endB - edit.beginB;
|
|
809
|
-
offset += lengthA - lengthB;
|
|
810
|
-
} else if (edit.beginB <= childPos) {
|
|
811
|
-
// Position is within an edit - this shouldn't happen for unchanged lines
|
|
812
|
-
// but handle gracefully by mapping to edit start in parent
|
|
813
|
-
return edit.beginA;
|
|
814
|
-
}
|
|
659
|
+
/** git's `pass_whole_blame` */
|
|
660
|
+
private passWholeBlame(origin: Origin, porigin: Origin, queue: CommitQueue): void {
|
|
661
|
+
if (!porigin.lines && origin.lines) {
|
|
662
|
+
porigin.lines = origin.lines;
|
|
663
|
+
origin.lines = undefined;
|
|
815
664
|
}
|
|
816
|
-
|
|
817
|
-
|
|
665
|
+
const suspects = origin.suspects;
|
|
666
|
+
origin.suspects = null;
|
|
667
|
+
for (let e = suspects; e; e = e.next) e.suspect = porigin;
|
|
668
|
+
this.queueBlames(porigin, suspects, queue);
|
|
818
669
|
}
|
|
819
670
|
|
|
820
|
-
/**
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
private async splitBlame(
|
|
826
|
-
candidate: BlameCandidate,
|
|
827
|
-
parentCommit: Commit,
|
|
828
|
-
parentId: ObjectId,
|
|
829
|
-
parentPath: string,
|
|
830
|
-
parentBlobId: ObjectId,
|
|
831
|
-
parentContent: Uint8Array,
|
|
832
|
-
parentRawText: RawText,
|
|
833
|
-
queue: BlameCandidate[],
|
|
834
|
-
seen: Set<ObjectId>,
|
|
835
|
-
entries: BlameEntry[],
|
|
836
|
-
): Promise<number> {
|
|
837
|
-
// Compute diff
|
|
838
|
-
const comparator = RawTextComparator.DEFAULT;
|
|
839
|
-
const edits = this.diffAlgorithm(comparator, parentRawText, candidate.rawText);
|
|
840
|
-
|
|
841
|
-
if (edits.length === 0) {
|
|
842
|
-
// No changes (might happen with whitespace-ignoring comparator)
|
|
843
|
-
const parentCandidate: BlameCandidate = {
|
|
844
|
-
commit: parentCommit,
|
|
845
|
-
commitId: parentId,
|
|
846
|
-
path: parentPath,
|
|
847
|
-
blobId: parentBlobId,
|
|
848
|
-
content: parentContent,
|
|
849
|
-
rawText: parentRawText,
|
|
850
|
-
regions: candidate.regions,
|
|
851
|
-
time: parentCommit.author.timestamp * 1000,
|
|
852
|
-
};
|
|
853
|
-
this.pushCandidate(queue, parentCandidate, seen);
|
|
854
|
-
return 0;
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
// Split regions
|
|
858
|
-
const { parentRegions, childRegions } = this.takeBlame(edits, candidate.regions);
|
|
859
|
-
|
|
860
|
-
// Push parent candidate
|
|
861
|
-
if (parentRegions.length > 0) {
|
|
862
|
-
const parentCandidate: BlameCandidate = {
|
|
863
|
-
commit: parentCommit,
|
|
864
|
-
commitId: parentId,
|
|
865
|
-
path: parentPath,
|
|
866
|
-
blobId: parentBlobId,
|
|
867
|
-
content: parentContent,
|
|
868
|
-
rawText: parentRawText,
|
|
869
|
-
regions: parentRegions,
|
|
870
|
-
time: parentCommit.author.timestamp * 1000,
|
|
871
|
-
};
|
|
872
|
-
this.pushCandidate(queue, parentCandidate, seen);
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
// Blame child regions to this commit
|
|
876
|
-
if (childRegions.length > 0) {
|
|
877
|
-
const childCandidate: BlameCandidate = {
|
|
878
|
-
...candidate,
|
|
879
|
-
regions: childRegions,
|
|
880
|
-
};
|
|
881
|
-
this.blameRegions(entries, childCandidate);
|
|
882
|
-
return this.countRegionLines(childRegions);
|
|
671
|
+
/** git's `queue_blames` */
|
|
672
|
+
private queueBlames(porigin: Origin, sorted: Entry | null, queue: CommitQueue): void {
|
|
673
|
+
if (porigin.suspects) {
|
|
674
|
+
porigin.suspects = blameMerge(porigin.suspects, sorted);
|
|
675
|
+
return;
|
|
883
676
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
/**
|
|
889
|
-
* Push a candidate onto the queue, maintaining descending time order.
|
|
890
|
-
* Handles merging of candidates for the same commit.
|
|
891
|
-
*/
|
|
892
|
-
private pushCandidate(
|
|
893
|
-
queue: BlameCandidate[],
|
|
894
|
-
candidate: BlameCandidate,
|
|
895
|
-
seen: Set<ObjectId>,
|
|
896
|
-
): void {
|
|
897
|
-
// Check if we already have a candidate for this commit
|
|
898
|
-
if (seen.has(candidate.commitId)) {
|
|
899
|
-
// Find and merge with existing candidate
|
|
900
|
-
const existing = queue.find(
|
|
901
|
-
(c) => c.commitId === candidate.commitId && c.path === candidate.path,
|
|
902
|
-
);
|
|
903
|
-
if (existing) {
|
|
904
|
-
// Merge regions
|
|
905
|
-
existing.regions = this.mergeBlameRegions(existing.regions, candidate.regions);
|
|
677
|
+
const st = this.states.get(porigin.commitId);
|
|
678
|
+
for (let o = st?.origins ?? null; o; o = o.next) {
|
|
679
|
+
if (o.suspects) {
|
|
680
|
+
porigin.suspects = sorted;
|
|
906
681
|
return;
|
|
907
682
|
}
|
|
908
683
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
// Insert in descending time order
|
|
913
|
-
let insertIdx = 0;
|
|
914
|
-
while (insertIdx < queue.length && queue[insertIdx].time > candidate.time) {
|
|
915
|
-
insertIdx++;
|
|
916
|
-
}
|
|
917
|
-
queue.splice(insertIdx, 0, candidate);
|
|
684
|
+
porigin.suspects = sorted;
|
|
685
|
+
if (st) queue.put(porigin.commitId, st.commit.committer.timestamp);
|
|
918
686
|
}
|
|
919
687
|
|
|
920
|
-
/**
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
|
|
688
|
+
/** git's `pass_blame_to_parent` */
|
|
689
|
+
private async passBlameToParent(
|
|
690
|
+
target: Origin,
|
|
691
|
+
parent: Origin,
|
|
692
|
+
queue: CommitQueue,
|
|
693
|
+
): Promise<void> {
|
|
694
|
+
if (!target.suspects) return;
|
|
695
|
+
const newdest: Slot = { next: null };
|
|
696
|
+
const src: Slot = { next: target.suspects };
|
|
697
|
+
const d = { offset: 0, dstq: newdest as Slot, srcq: src as Slot };
|
|
698
|
+
let fileP = await this.originContent(parent);
|
|
699
|
+
let fileO = await this.originContent(target);
|
|
700
|
+
// ids are comparable only within one interner: a version interned before blame started
|
|
701
|
+
// a new interner is interned again in the current one
|
|
702
|
+
const interner = this.lineInterner();
|
|
703
|
+
if (fileP.interner !== interner) fileP = parent.lines = interner.text(fileP.content);
|
|
704
|
+
if (fileO.interner !== interner) fileO = target.lines = interner.text(fileO.content);
|
|
705
|
+
const hunks = xdiffHunks(fileP, fileO, {
|
|
706
|
+
interner,
|
|
707
|
+
algorithm: this.algorithm,
|
|
708
|
+
indentHeuristic: this.indentHeuristic,
|
|
709
|
+
ignoreWhitespace: this.ignoreWhitespace,
|
|
710
|
+
...this.diffOptions,
|
|
711
|
+
});
|
|
712
|
+
for (const h of hunks) {
|
|
713
|
+
blameChunk(d, h.i2, h.i1 - h.i2, h.i2 + h.chg2, parent);
|
|
714
|
+
d.offset = h.i1 + h.chg1 - (h.i2 + h.chg2);
|
|
715
|
+
}
|
|
716
|
+
blameChunk(d, INT_MAX, d.offset, INT_MAX, parent);
|
|
717
|
+
d.dstq.next = null;
|
|
718
|
+
target.suspects = src.next;
|
|
719
|
+
this.queueBlames(parent, newdest.next, queue);
|
|
946
720
|
}
|
|
947
721
|
|
|
948
|
-
/**
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
for (
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
});
|
|
961
|
-
}
|
|
722
|
+
/** git's `find_origin`: the parent's version at the same path, of the same kind */
|
|
723
|
+
private async findOrigin(parentId: ObjectId, origin: Origin): Promise<Origin | undefined> {
|
|
724
|
+
const parent = this.states.get(parentId);
|
|
725
|
+
if (!parent) return undefined;
|
|
726
|
+
for (let o = parent.origins; o; o = o.next) if (o.path === origin.path) return o;
|
|
727
|
+
const entry = await this.lookup(parent.commit.tree, origin.path);
|
|
728
|
+
if (!entry || (entry.mode & S_IFMT) !== (origin.mode & S_IFMT)) return undefined;
|
|
729
|
+
if (entry.id !== origin.blobId && (await this.isBig(entry.id))) return undefined;
|
|
730
|
+
const porigin = this.getOrigin(parentId, origin.path);
|
|
731
|
+
porigin.blobId = entry.id;
|
|
732
|
+
porigin.mode = entry.mode;
|
|
733
|
+
return porigin;
|
|
962
734
|
}
|
|
963
735
|
|
|
964
|
-
/**
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
736
|
+
/** git's `find_rename`: a file of the parent the commit's file was renamed from */
|
|
737
|
+
private async findRename(parentId: ObjectId, origin: Origin): Promise<Origin | undefined> {
|
|
738
|
+
const parent = this.states.get(parentId);
|
|
739
|
+
const child = this.states.get(origin.commitId);
|
|
740
|
+
if (!parent || !child) return undefined;
|
|
741
|
+
// the path is a rename destination only when added (not a kind change)
|
|
742
|
+
const inParent = await this.lookup(parent.commit.tree, origin.path);
|
|
743
|
+
if (inParent) return undefined;
|
|
744
|
+
const before = new Map<string, { id: ObjectId; mode: number }>();
|
|
745
|
+
const after = new Map<string, { id: ObjectId; mode: number }>();
|
|
746
|
+
await this.collectBlobs(parent.commit.tree, "", before);
|
|
747
|
+
await this.collectBlobs(child.commit.tree, "", after);
|
|
748
|
+
const sources = [];
|
|
749
|
+
for (const [path, e] of before) {
|
|
750
|
+
if (!after.has(path) && !(await this.isBig(e.id))) sources.push({ path, ...e });
|
|
751
|
+
}
|
|
752
|
+
if (sources.length === 0) return undefined;
|
|
753
|
+
const config = RemoteConfigStore.from(this.workingCopy);
|
|
754
|
+
const limit = intValue(config.value("diff.renameLimit")) ?? DEFAULT_RENAME_LIMIT;
|
|
755
|
+
const pairs = await detectRenames(
|
|
756
|
+
sources,
|
|
757
|
+
[{ path: origin.path, id: origin.blobId, mode: origin.mode }],
|
|
758
|
+
{
|
|
759
|
+
renameLimit: limit,
|
|
760
|
+
minimumScore: Math.round((this.renameScore * GIT_MAX_SCORE) / 100),
|
|
761
|
+
countLastSpan: this.renameCountLastSpan,
|
|
762
|
+
size: async (c) => this.blobs.size(c.id),
|
|
763
|
+
load: async (c) => this.readBlob(c.id),
|
|
764
|
+
},
|
|
765
|
+
);
|
|
766
|
+
const pair = pairs.find((p) => p.to === origin.path);
|
|
767
|
+
if (!pair) return undefined;
|
|
768
|
+
const src = before.get(pair.from);
|
|
769
|
+
if (!src) return undefined;
|
|
770
|
+
const porigin = this.getOrigin(parentId, pair.from);
|
|
771
|
+
porigin.blobId = src.id;
|
|
772
|
+
porigin.mode = src.mode;
|
|
773
|
+
return porigin;
|
|
969
774
|
}
|
|
970
775
|
|
|
971
|
-
/**
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
parentTreeId: ObjectId,
|
|
985
|
-
currentTreeId: ObjectId,
|
|
986
|
-
_newPath: string,
|
|
987
|
-
newContent: Uint8Array,
|
|
988
|
-
): Promise<{ oldPath: string; oldBlobId: ObjectId; score: number } | undefined> {
|
|
989
|
-
// Skip binary files for rename detection
|
|
990
|
-
if (SimilarityIndex.isBinary(newContent)) {
|
|
991
|
-
return undefined;
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
// Collect all blob entries from both trees
|
|
995
|
-
const parentBlobs = new Map<string, TreeEntry>();
|
|
996
|
-
const currentBlobs = new Map<string, TreeEntry>();
|
|
997
|
-
|
|
998
|
-
await this.collectTreeEntries(parentTreeId, "", parentBlobs);
|
|
999
|
-
await this.collectTreeEntries(currentTreeId, "", currentBlobs);
|
|
1000
|
-
|
|
1001
|
-
// Find files that exist in parent but not in current (potential rename sources)
|
|
1002
|
-
const deletedFiles: Array<{ path: string; entry: TreeEntry }> = [];
|
|
1003
|
-
for (const [path, entry] of parentBlobs) {
|
|
1004
|
-
if (!currentBlobs.has(path)) {
|
|
1005
|
-
deletedFiles.push({ path, entry });
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
if (deletedFiles.length === 0) {
|
|
1010
|
-
return undefined;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
// Compute similarity index for the new file
|
|
1014
|
-
const newIndex = SimilarityIndex.create(newContent);
|
|
1015
|
-
|
|
1016
|
-
// Find the best matching deleted file
|
|
1017
|
-
let bestMatch: { path: string; blobId: ObjectId; score: number } | undefined;
|
|
1018
|
-
|
|
1019
|
-
for (const { path: oldPath, entry } of deletedFiles) {
|
|
1020
|
-
if (await this.isBig(entry.id)) continue;
|
|
1021
|
-
|
|
1022
|
-
// Load the old file content
|
|
1023
|
-
const oldContent = await this.collectBlob(entry.id);
|
|
1024
|
-
|
|
1025
|
-
// Skip binary files
|
|
1026
|
-
if (SimilarityIndex.isBinary(oldContent)) {
|
|
1027
|
-
continue;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
// Compute similarity
|
|
1031
|
-
const oldIndex = SimilarityIndex.create(oldContent);
|
|
1032
|
-
const score = newIndex.score(oldIndex);
|
|
1033
|
-
|
|
1034
|
-
// Check if this is a better match than what we have
|
|
1035
|
-
if (score >= this.renameScore && (!bestMatch || score > bestMatch.score)) {
|
|
1036
|
-
bestMatch = {
|
|
1037
|
-
path: oldPath,
|
|
1038
|
-
blobId: entry.id,
|
|
1039
|
-
score,
|
|
1040
|
-
};
|
|
776
|
+
/** git's `get_origin`: the commit's origin for a path, moved to the front, or a new one */
|
|
777
|
+
private getOrigin(commitId: ObjectId, path: string): Origin {
|
|
778
|
+
const st = this.states.get(commitId);
|
|
779
|
+
if (!st) throw new Error(`commit ${commitId} not loaded`);
|
|
780
|
+
let l: Origin | null = null;
|
|
781
|
+
for (let o = st.origins; o; l = o, o = o.next) {
|
|
782
|
+
if (o.path === path) {
|
|
783
|
+
if (l) {
|
|
784
|
+
l.next = o.next;
|
|
785
|
+
o.next = st.origins;
|
|
786
|
+
st.origins = o;
|
|
787
|
+
}
|
|
788
|
+
return o;
|
|
1041
789
|
}
|
|
1042
790
|
}
|
|
791
|
+
const o: Origin = {
|
|
792
|
+
commitId,
|
|
793
|
+
path,
|
|
794
|
+
blobId: "",
|
|
795
|
+
mode: 0,
|
|
796
|
+
suspects: null,
|
|
797
|
+
guilty: false,
|
|
798
|
+
next: st.origins,
|
|
799
|
+
};
|
|
800
|
+
st.origins = o;
|
|
801
|
+
return o;
|
|
802
|
+
}
|
|
1043
803
|
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
804
|
+
private async state(commitId: ObjectId): Promise<CommitState | undefined> {
|
|
805
|
+
const known = this.states.get(commitId);
|
|
806
|
+
if (known) return known;
|
|
807
|
+
const commit = await this.commits.load(commitId).catch(() => undefined);
|
|
808
|
+
if (!commit) return undefined;
|
|
809
|
+
const st: CommitState = { commit, origins: null, uninteresting: false };
|
|
810
|
+
this.states.set(commitId, st);
|
|
811
|
+
return st;
|
|
812
|
+
}
|
|
1051
813
|
|
|
1052
|
-
|
|
814
|
+
private async originContent(o: Origin): Promise<InternedText> {
|
|
815
|
+
o.lines ??= this.lineInterner().text(await this.readBlob(o.blobId, true));
|
|
816
|
+
return o.lines;
|
|
1053
817
|
}
|
|
1054
818
|
|
|
1055
819
|
/**
|
|
1056
|
-
*
|
|
820
|
+
* The interner compared versions' lines go through (see `passBlameToParent`); a new one
|
|
821
|
+
* once the current one holds more than `internerByteLimit` bytes of lines, so a long walk
|
|
822
|
+
* does not keep every distinct line it has seen
|
|
1057
823
|
*/
|
|
1058
|
-
private
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
const TREE_MODE = 0o40000;
|
|
1064
|
-
|
|
1065
|
-
for await (const entry of this.trees.loadTree(treeId)) {
|
|
1066
|
-
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
1067
|
-
|
|
1068
|
-
if (entry.mode === TREE_MODE) {
|
|
1069
|
-
// Recurse into subtree
|
|
1070
|
-
await this.collectTreeEntries(entry.id, path, entries);
|
|
1071
|
-
} else {
|
|
1072
|
-
// Blob entry
|
|
1073
|
-
entries.set(path, entry);
|
|
1074
|
-
}
|
|
824
|
+
private lineInterner(): LineInterner {
|
|
825
|
+
if (!this.interner || this.interner.byteSize > this.internerByteLimit) {
|
|
826
|
+
this.interner = new LineInterner(
|
|
827
|
+
whitespaceFlags({ ignoreWhitespace: this.ignoreWhitespace }),
|
|
828
|
+
);
|
|
1075
829
|
}
|
|
830
|
+
return this.interner;
|
|
1076
831
|
}
|
|
1077
832
|
|
|
1078
833
|
/** Whether a blob is over the threshold (from its size, without reading it). */
|
|
@@ -1081,202 +836,172 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
1081
836
|
}
|
|
1082
837
|
|
|
1083
838
|
/**
|
|
1084
|
-
*
|
|
839
|
+
* A blob's content; `shared` (for content only read here) takes a single chunk as it
|
|
840
|
+
* comes (a resolved pack object) instead of copying it
|
|
1085
841
|
*/
|
|
1086
|
-
private async
|
|
842
|
+
private async readBlob(blobId: ObjectId, shared = false): Promise<Uint8Array> {
|
|
1087
843
|
const chunks: Uint8Array[] = [];
|
|
1088
|
-
let
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
for await (const chunk of blobContent) {
|
|
844
|
+
let total = 0;
|
|
845
|
+
const content = await this.blobs.load(blobId);
|
|
846
|
+
if (content) {
|
|
847
|
+
for await (const chunk of content) {
|
|
1093
848
|
chunks.push(chunk);
|
|
1094
|
-
|
|
849
|
+
total += chunk.length;
|
|
1095
850
|
}
|
|
1096
851
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
offset += chunk.length;
|
|
852
|
+
if (shared && chunks.length === 1) return chunks[0];
|
|
853
|
+
const out = new Uint8Array(total);
|
|
854
|
+
let at = 0;
|
|
855
|
+
for (const c of chunks) {
|
|
856
|
+
out.set(c, at);
|
|
857
|
+
at += c.length;
|
|
1104
858
|
}
|
|
1105
|
-
|
|
1106
|
-
return result;
|
|
859
|
+
return out;
|
|
1107
860
|
}
|
|
1108
861
|
|
|
1109
|
-
/**
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
862
|
+
/** The non-tree entry at `path` in a tree */
|
|
863
|
+
private async lookup(
|
|
864
|
+
treeId: ObjectId,
|
|
865
|
+
path: string,
|
|
866
|
+
): Promise<{ id: ObjectId; mode: number } | undefined> {
|
|
1113
867
|
const parts = path.split("/").filter((p) => p.length > 0);
|
|
1114
|
-
let
|
|
1115
|
-
|
|
868
|
+
let current = treeId;
|
|
1116
869
|
for (let i = 0; i < parts.length; i++) {
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
if (!
|
|
1122
|
-
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
if (isLast) {
|
|
1126
|
-
return entry.id;
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
// Navigate into subtree
|
|
1130
|
-
currentTreeId = entry.id;
|
|
870
|
+
const entry = await this.trees.getEntry(current, parts[i]);
|
|
871
|
+
if (!entry) return undefined;
|
|
872
|
+
const isTree = (entry.mode & S_IFMT) === TREE_MODE;
|
|
873
|
+
if (i === parts.length - 1) return isTree ? undefined : { id: entry.id, mode: entry.mode };
|
|
874
|
+
if (!isTree) return undefined;
|
|
875
|
+
current = entry.id;
|
|
1131
876
|
}
|
|
1132
|
-
|
|
1133
877
|
return undefined;
|
|
1134
878
|
}
|
|
1135
879
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
if (content.length === 0) {
|
|
1146
|
-
return 0;
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
let count = 1;
|
|
1150
|
-
for (let i = 0; i < content.length; i++) {
|
|
1151
|
-
const byte = content[i];
|
|
1152
|
-
if (byte === 0x0a) {
|
|
1153
|
-
// '\n' - LF (Unix) or second byte of CRLF (Windows)
|
|
1154
|
-
count++;
|
|
1155
|
-
} else if (byte === 0x0d) {
|
|
1156
|
-
// '\r' - Check if it's CRLF or standalone CR
|
|
1157
|
-
if (i + 1 < content.length && content[i + 1] === 0x0a) {
|
|
1158
|
-
// CRLF - skip the CR, the LF will be handled in next iteration
|
|
1159
|
-
continue;
|
|
1160
|
-
}
|
|
1161
|
-
// Standalone CR (classic Mac style)
|
|
1162
|
-
count++;
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
// If file ends with newline (LF or CR), don't count the empty "line" after it
|
|
1167
|
-
const lastByte = content[content.length - 1];
|
|
1168
|
-
if (lastByte === 0x0a || lastByte === 0x0d) {
|
|
1169
|
-
count--;
|
|
880
|
+
private async collectBlobs(
|
|
881
|
+
treeId: ObjectId,
|
|
882
|
+
prefix: string,
|
|
883
|
+
out: Map<string, { id: ObjectId; mode: number }>,
|
|
884
|
+
): Promise<void> {
|
|
885
|
+
for await (const entry of this.trees.loadTree(treeId)) {
|
|
886
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
887
|
+
if ((entry.mode & S_IFMT) === TREE_MODE) await this.collectBlobs(entry.id, path, out);
|
|
888
|
+
else out.set(path, { id: entry.id, mode: entry.mode });
|
|
1170
889
|
}
|
|
1171
|
-
|
|
1172
|
-
return count;
|
|
1173
890
|
}
|
|
891
|
+
}
|
|
1174
892
|
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
lineCount: current.lineCount + next.lineCount,
|
|
1199
|
-
};
|
|
1200
|
-
} else {
|
|
1201
|
-
merged.push(current);
|
|
1202
|
-
current = next;
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
merged.push(current);
|
|
1207
|
-
return merged;
|
|
893
|
+
/** git's `blame_chunk`: lines before `tlno` go to the parent, `[tlno, same)` stay */
|
|
894
|
+
function blameChunk(
|
|
895
|
+
d: { offset: number; dstq: Slot; srcq: Slot },
|
|
896
|
+
tlno: number,
|
|
897
|
+
offset: number,
|
|
898
|
+
same: number,
|
|
899
|
+
parent: Origin,
|
|
900
|
+
): void {
|
|
901
|
+
let e = d.srcq.next;
|
|
902
|
+
let samep: Entry | null = null;
|
|
903
|
+
let diffp: Entry | null = null;
|
|
904
|
+
while (e && e.sLno < tlno) {
|
|
905
|
+
const next: Entry | null = e.next;
|
|
906
|
+
if (e.sLno + e.numLines > tlno) {
|
|
907
|
+
const n = splitBlameAt(e, tlno - e.sLno, e.suspect);
|
|
908
|
+
n.next = diffp;
|
|
909
|
+
diffp = n;
|
|
910
|
+
}
|
|
911
|
+
e.suspect = parent;
|
|
912
|
+
e.sLno += offset;
|
|
913
|
+
e.next = samep;
|
|
914
|
+
samep = e;
|
|
915
|
+
e = next;
|
|
1208
916
|
}
|
|
917
|
+
if (samep) {
|
|
918
|
+
d.dstq.next = reverseBlame(samep, d.dstq.next);
|
|
919
|
+
d.dstq = samep;
|
|
920
|
+
}
|
|
921
|
+
e = reverseBlame(diffp, e);
|
|
922
|
+
samep = null;
|
|
923
|
+
diffp = null;
|
|
924
|
+
while (e && e.sLno < same) {
|
|
925
|
+
const next: Entry | null = e.next;
|
|
926
|
+
if (e.sLno + e.numLines > same) {
|
|
927
|
+
const n = splitBlameAt(e, same - e.sLno, e.suspect);
|
|
928
|
+
n.next = samep;
|
|
929
|
+
samep = n;
|
|
930
|
+
}
|
|
931
|
+
e.next = diffp;
|
|
932
|
+
diffp = e;
|
|
933
|
+
e = next;
|
|
934
|
+
}
|
|
935
|
+
d.srcq.next = reverseBlame(diffp, reverseBlame(samep, e));
|
|
936
|
+
if (diffp) d.srcq = diffp;
|
|
937
|
+
}
|
|
1209
938
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
for (let i = 0; i < entry.lineCount; i++) {
|
|
1218
|
-
lineToEntry.set(entry.resultStart + i, entry);
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
/**
|
|
1223
|
-
* Get the source line number for a given result line.
|
|
1224
|
-
* The source line is computed based on the entry's sourceStart and the offset
|
|
1225
|
-
* within the entry.
|
|
1226
|
-
*/
|
|
1227
|
-
function getSourceLineForResult(line: number): number | undefined {
|
|
1228
|
-
const entry = lineToEntry.get(line);
|
|
1229
|
-
if (!entry) return undefined;
|
|
1230
|
-
// Compute offset within the entry and add to sourceStart
|
|
1231
|
-
const offset = line - entry.resultStart;
|
|
1232
|
-
return entry.sourceStart + offset;
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
return {
|
|
1236
|
-
path,
|
|
1237
|
-
lineCount,
|
|
1238
|
-
entries,
|
|
1239
|
-
|
|
1240
|
-
getEntry(line: number): BlameEntry | undefined {
|
|
1241
|
-
return lineToEntry.get(line);
|
|
1242
|
-
},
|
|
939
|
+
/** Lines as git counts them: LF-terminated, an unterminated last line one more */
|
|
940
|
+
function countLines(content: Uint8Array): number {
|
|
941
|
+
let n = 0;
|
|
942
|
+
for (let i = 0; i < content.length; i++) if (content[i] === 0x0a) n++;
|
|
943
|
+
if (content.length > 0 && content[content.length - 1] !== 0x0a) n++;
|
|
944
|
+
return n;
|
|
945
|
+
}
|
|
1243
946
|
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
return entry?.commit;
|
|
1247
|
-
},
|
|
947
|
+
/** A git boolean (`git_config_bool`), undefined when unset or not one. */
|
|
948
|
+
const boolValue = (v: string | undefined): boolean | undefined => parseGitBool(v);
|
|
1248
949
|
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
950
|
+
function intValue(value: string | undefined): number | undefined {
|
|
951
|
+
const m = value?.trim().match(/^(-?\d+)([kmg]?)$/i);
|
|
952
|
+
if (!m) return undefined;
|
|
953
|
+
const unit = { "": 1, k: 1024, m: 1024 ** 2, g: 1024 ** 3 }[m[2].toLowerCase()] ?? 1;
|
|
954
|
+
return Number(m[1]) * unit;
|
|
955
|
+
}
|
|
1253
956
|
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
957
|
+
function algorithmValue(v: string | undefined): XdiffAlgorithm | undefined {
|
|
958
|
+
const s = v?.trim().toLowerCase();
|
|
959
|
+
if (s === "default") return "myers";
|
|
960
|
+
return s === "myers" || s === "minimal" || s === "patience" || s === "histogram" ? s : undefined;
|
|
961
|
+
}
|
|
1257
962
|
|
|
1258
|
-
|
|
963
|
+
/**
|
|
964
|
+
* Create a BlameResult from entries.
|
|
965
|
+
*/
|
|
966
|
+
function createBlameResult(
|
|
967
|
+
path: string,
|
|
968
|
+
lineCount: number,
|
|
969
|
+
entries: BlameEntry[],
|
|
970
|
+
content: Uint8Array,
|
|
971
|
+
): BlameResult {
|
|
972
|
+
const lineToEntry = new Map<number, BlameEntry>();
|
|
973
|
+
for (const entry of entries) {
|
|
974
|
+
for (let i = 0; i < entry.lineCount; i++) lineToEntry.set(entry.resultStart + i, entry);
|
|
975
|
+
}
|
|
976
|
+
const sourceLine = (line: number): number | undefined => {
|
|
977
|
+
const entry = lineToEntry.get(line);
|
|
978
|
+
return entry ? entry.sourceStart + (line - entry.resultStart) : undefined;
|
|
979
|
+
};
|
|
980
|
+
return {
|
|
981
|
+
path,
|
|
982
|
+
lineCount,
|
|
983
|
+
entries,
|
|
984
|
+
content,
|
|
985
|
+
getEntry: (line) => lineToEntry.get(line),
|
|
986
|
+
getSourceCommit: (line) => lineToEntry.get(line)?.commit,
|
|
987
|
+
getSourceAuthor: (line) => lineToEntry.get(line)?.commit.author,
|
|
988
|
+
getSourceLine: sourceLine,
|
|
989
|
+
getSourcePath: (line) => lineToEntry.get(line)?.sourcePath,
|
|
990
|
+
getLineTracking(): LineTracking[] {
|
|
991
|
+
const tracking: LineTracking[] = [];
|
|
992
|
+
for (let line = 1; line <= lineCount; line++) {
|
|
1259
993
|
const entry = lineToEntry.get(line);
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
const offset = line - entry.resultStart;
|
|
1269
|
-
tracking.push({
|
|
1270
|
-
resultLine: line,
|
|
1271
|
-
commit: entry.commit,
|
|
1272
|
-
commitId: entry.commitId,
|
|
1273
|
-
sourcePath: entry.sourcePath,
|
|
1274
|
-
sourceLine: entry.sourceStart + offset,
|
|
1275
|
-
});
|
|
1276
|
-
}
|
|
994
|
+
if (entry) {
|
|
995
|
+
tracking.push({
|
|
996
|
+
resultLine: line,
|
|
997
|
+
commit: entry.commit,
|
|
998
|
+
commitId: entry.commitId,
|
|
999
|
+
sourcePath: entry.sourcePath,
|
|
1000
|
+
sourceLine: entry.sourceStart + (line - entry.resultStart),
|
|
1001
|
+
});
|
|
1277
1002
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1003
|
+
}
|
|
1004
|
+
return tracking;
|
|
1005
|
+
},
|
|
1006
|
+
};
|
|
1282
1007
|
}
|