@statewalker/vcs-commands 0.6.0 → 0.8.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/dist/commands/add-command.d.ts +38 -0
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/am/am-command.d.ts +55 -1
- package/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/am/index.d.ts +1 -0
- package/dist/commands/am/index.d.ts.map +1 -1
- package/dist/commands/am/mailsplit.d.ts +88 -0
- package/dist/commands/am/mailsplit.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-engine.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.d.ts.map +1 -1
- package/dist/commands/bisect/bisect-command.d.ts +2 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +148 -18
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-info-command.d.ts +55 -0
- package/dist/commands/branch-info-command.d.ts.map +1 -0
- package/dist/commands/branch-tracking.d.ts +106 -17
- package/dist/commands/branch-tracking.d.ts.map +1 -1
- package/dist/commands/branch-upstream-command.d.ts +83 -0
- package/dist/commands/branch-upstream-command.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +19 -3
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/cherry-pick-command.d.ts +59 -0
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +12 -0
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +17 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/comment-char-config.d.ts +35 -0
- package/dist/commands/comment-char-config.d.ts.map +1 -0
- package/dist/commands/commit-command.d.ts +191 -5
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/commit-reuse.d.ts +33 -0
- package/dist/commands/commit-reuse.d.ts.map +1 -0
- package/dist/commands/config-command.d.ts +236 -0
- package/dist/commands/config-command.d.ts.map +1 -0
- package/dist/commands/config-value-types.d.ts +91 -0
- package/dist/commands/config-value-types.d.ts.map +1 -0
- package/dist/commands/core-config.d.ts +20 -0
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/default-branch.d.ts +70 -0
- package/dist/commands/default-branch.d.ts.map +1 -0
- package/dist/commands/diff-color-config.d.ts +73 -0
- package/dist/commands/diff-color-config.d.ts.map +1 -0
- package/dist/commands/diff-command.d.ts +252 -5
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/fetch-command.d.ts +20 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
- package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
- package/dist/commands/fork-point.d.ts +38 -0
- package/dist/commands/fork-point.d.ts.map +1 -0
- package/dist/commands/format-patch-command.d.ts +41 -1
- package/dist/commands/format-patch-command.d.ts.map +1 -1
- package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-command.d.ts +2 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-loose.d.ts +3 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-object-checks.d.ts +25 -14
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-object-table.d.ts +15 -7
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-pack.d.ts +11 -4
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -1
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -1
- package/dist/commands/gc-command.d.ts +80 -48
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +1 -65
- package/dist/commands/git-date.d.ts.map +1 -1
- package/dist/commands/git-describe.d.ts +4 -0
- package/dist/commands/git-describe.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +43 -0
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/grep/grep-command.d.ts +210 -0
- package/dist/commands/grep/grep-command.d.ts.map +1 -0
- package/dist/commands/grep/grep-engine.d.ts +218 -0
- package/dist/commands/grep/grep-engine.d.ts.map +1 -0
- package/dist/commands/grep/index.d.ts +3 -0
- package/dist/commands/grep/index.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +15 -2
- package/dist/commands/index-adder.d.ts.map +1 -1
- package/dist/commands/index.d.ts +28 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -3
- package/dist/commands/init-command.d.ts +50 -3
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/interpret-trailers-command.d.ts +90 -0
- package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
- package/dist/commands/legacy-remotes.d.ts +55 -0
- package/dist/commands/legacy-remotes.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +36 -5
- package/dist/commands/local-transport.d.ts.map +1 -1
- package/dist/commands/log-command.d.ts +296 -11
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +26 -1
- package/dist/commands/log-graph.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +133 -5
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/ls-remote-command.d.ts +2 -0
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +30 -0
- package/dist/commands/mailmap.d.ts.map +1 -1
- package/dist/commands/merge-base-command.d.ts +60 -0
- package/dist/commands/merge-base-command.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +23 -0
- package/dist/commands/merge-bases.d.ts.map +1 -1
- package/dist/commands/merge-command.d.ts +108 -9
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-support.d.ts +11 -3
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/mv-command.d.ts +4 -0
- package/dist/commands/mv-command.d.ts.map +1 -1
- package/dist/commands/name-rev.d.ts +48 -0
- package/dist/commands/name-rev.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts.map +1 -1
- package/dist/commands/notes-merge-command.d.ts.map +1 -1
- package/dist/commands/notes-tree.d.ts +11 -1
- package/dist/commands/notes-tree.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +3 -0
- package/dist/commands/patch-id.d.ts.map +1 -1
- package/dist/commands/pathspec-file.d.ts +39 -0
- package/dist/commands/pathspec-file.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +3 -0
- package/dist/commands/pathspec.d.ts.map +1 -1
- package/dist/commands/pretty-format.d.ts +43 -3
- package/dist/commands/pretty-format.d.ts.map +1 -1
- package/dist/commands/promisor-remote.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts +28 -0
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +160 -9
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +6 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +168 -6
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
- package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
- package/dist/commands/ref-filter/index.d.ts +8 -0
- package/dist/commands/ref-filter/index.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
- package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
- package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-format.d.ts +222 -0
- package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
- package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
- package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
- package/dist/commands/ref-filter/version-compare.d.ts +20 -0
- package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
- package/dist/commands/reflog-command.d.ts +120 -0
- package/dist/commands/reflog-command.d.ts.map +1 -1
- package/dist/commands/reflog-walk.d.ts +72 -0
- package/dist/commands/reflog-walk.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +138 -29
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +7 -1
- package/dist/commands/remote-transport.d.ts.map +1 -1
- package/dist/commands/reset-command.d.ts +2 -3
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +2 -3
- package/dist/commands/restore-command.d.ts.map +1 -1
- package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
- package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
- package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
- package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
- package/dist/commands/rev-filter/index.d.ts +3 -0
- package/dist/commands/rev-filter/index.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +154 -2
- package/dist/commands/rev-list-command.d.ts.map +1 -1
- package/dist/commands/rev-parse-command.d.ts +9 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -1
- package/dist/commands/revert-command.d.ts +32 -0
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +32 -1
- package/dist/commands/revision-range.d.ts.map +1 -1
- package/dist/commands/revision-resolver.d.ts +21 -2
- package/dist/commands/revision-resolver.d.ts.map +1 -1
- package/dist/commands/rm-command.d.ts +70 -2
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +85 -5
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts +2 -0
- package/dist/commands/sequencer-support.d.ts.map +1 -1
- package/dist/commands/serve-repository.d.ts +7 -0
- package/dist/commands/serve-repository.d.ts.map +1 -1
- package/dist/commands/show-command.d.ts +130 -0
- package/dist/commands/show-command.d.ts.map +1 -0
- package/dist/commands/show-commit.d.ts +11 -0
- package/dist/commands/show-commit.d.ts.map +1 -0
- package/dist/commands/signature-check.d.ts +164 -0
- package/dist/commands/signature-check.d.ts.map +1 -0
- package/dist/commands/signing.d.ts +160 -0
- package/dist/commands/signing.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
- package/dist/commands/sparse-index-view.d.ts +45 -0
- package/dist/commands/sparse-index-view.d.ts.map +1 -0
- package/dist/commands/ssh-signer.d.ts +29 -0
- package/dist/commands/ssh-signer.d.ts.map +1 -0
- package/dist/commands/ssh-verifier.d.ts +42 -0
- package/dist/commands/ssh-verifier.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +5 -0
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-branch-command.d.ts +34 -0
- package/dist/commands/stash-branch-command.d.ts.map +1 -0
- package/dist/commands/stash-create-command.d.ts +18 -1
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-info.d.ts +93 -0
- package/dist/commands/stash-info.d.ts.map +1 -0
- package/dist/commands/stash-list-command.d.ts +16 -0
- package/dist/commands/stash-list-command.d.ts.map +1 -1
- package/dist/commands/stash-pop-command.d.ts +39 -0
- package/dist/commands/stash-pop-command.d.ts.map +1 -0
- package/dist/commands/stash-show-command.d.ts +48 -0
- package/dist/commands/stash-show-command.d.ts.map +1 -0
- package/dist/commands/stash-store-command.d.ts +29 -0
- package/dist/commands/stash-store-command.d.ts.map +1 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-header.d.ts +5 -0
- package/dist/commands/status-header.d.ts.map +1 -1
- package/dist/commands/submodule-add-command.d.ts +89 -0
- package/dist/commands/submodule-add-command.d.ts.map +1 -0
- package/dist/commands/submodule-auth.d.ts +90 -0
- package/dist/commands/submodule-auth.d.ts.map +1 -0
- package/dist/commands/submodule-commands.d.ts +375 -0
- package/dist/commands/submodule-commands.d.ts.map +1 -0
- package/dist/commands/submodule-model.d.ts +288 -0
- package/dist/commands/submodule-model.d.ts.map +1 -0
- package/dist/commands/submodule-summary-command.d.ts.map +1 -1
- package/dist/commands/submodule-update-command.d.ts +198 -0
- package/dist/commands/submodule-update-command.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts.map +1 -1
- package/dist/commands/tag-command.d.ts +259 -10
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/trailers.d.ts +218 -17
- package/dist/commands/trailers.d.ts.map +1 -1
- package/dist/commands/tree-restore.d.ts +7 -0
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +2 -1
- package/dist/commands/untracked-cache-support.d.ts.map +1 -1
- package/dist/commands/verify-command.d.ts +92 -0
- package/dist/commands/verify-command.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +79 -7
- package/dist/commands/worktree-add-command.d.ts.map +1 -1
- package/dist/commands/worktree-list-command.d.ts.map +1 -1
- package/dist/commands/worktree-path-rules.d.ts +66 -0
- package/dist/commands/worktree-path-rules.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +10 -3
- package/dist/commands/worktree-remove-command.d.ts.map +1 -1
- package/dist/commands/worktree-repair-command.d.ts +15 -2
- package/dist/commands/worktree-repair-command.d.ts.map +1 -1
- package/dist/commands/worktree-support.d.ts +5 -0
- package/dist/commands/worktree-support.d.ts.map +1 -1
- package/dist/{commands-DnmlfwGV.js → commands-ISM52N0n.js} +66120 -49271
- package/dist/errors/checkout-errors.d.ts +19 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/index.js +57 -3
- package/dist/errors/ref-errors.d.ts +19 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +6 -1
- package/dist/errors/worktree-errors.d.ts.map +1 -1
- package/dist/{git-command-DxvwPrPB.js → fsck-DLRpbwTj.js} +6863 -1070
- package/dist/git-command.d.ts +43 -2
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +276 -3
- package/dist/git.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/index.d.ts +1 -1
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +117 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/rename/detect-renames.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +8 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +3 -0
- package/dist/results/combined-diff.d.ts.map +1 -1
- package/dist/results/diff-check.d.ts +38 -0
- package/dist/results/diff-check.d.ts.map +1 -0
- package/dist/results/diff-color.d.ts +135 -0
- package/dist/results/diff-color.d.ts.map +1 -0
- package/dist/results/diff-output.d.ts +85 -1
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/diff-pickaxe.d.ts +67 -0
- package/dist/results/diff-pickaxe.d.ts.map +1 -0
- package/dist/results/diff-words.d.ts +55 -0
- package/dist/results/diff-words.d.ts.map +1 -0
- package/dist/results/index.d.ts +4 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/init-result.d.ts +7 -0
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +5 -0
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +12 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/rebase-result.d.ts +2 -0
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +6 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/{results-BZGa2Z3I.js → results-TB2IJ64h.js} +2178 -412
- package/dist/whitespace/index.d.ts +2 -0
- package/dist/whitespace/index.d.ts.map +1 -0
- package/dist/whitespace/whitespace-rule.d.ts +94 -0
- package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
- package/package.json +12 -12
- package/src/commands/add-command.ts +178 -17
- package/src/commands/add-patch/add-interactive.ts +3 -3
- package/src/commands/am/am-command.ts +263 -43
- package/src/commands/am/index.ts +1 -0
- package/src/commands/am/mailsplit.ts +326 -0
- package/src/commands/apply/apply-command.ts +18 -8
- package/src/commands/apply/apply-engine.ts +6 -7
- package/src/commands/apply/apply-parse.ts +10 -10
- package/src/commands/attributes-source.ts +1 -1
- package/src/commands/bisect/bisect-command.ts +18 -5
- package/src/commands/bisect/bisect-engine.ts +2 -1
- package/src/commands/branch-command.ts +528 -53
- package/src/commands/branch-info-command.ts +150 -0
- package/src/commands/branch-tracking.ts +335 -60
- package/src/commands/branch-upstream-command.ts +218 -0
- package/src/commands/checkout-command.ts +70 -44
- package/src/commands/cherry-pick-command.ts +143 -0
- package/src/commands/clean-command.ts +34 -3
- package/src/commands/clone-command.ts +118 -5
- package/src/commands/comment-char-config.ts +160 -0
- package/src/commands/commit-command.ts +790 -71
- package/src/commands/commit-reuse.ts +94 -0
- package/src/commands/config-command.ts +1256 -0
- package/src/commands/config-value-types.ts +358 -0
- package/src/commands/core-config.ts +47 -2
- package/src/commands/default-branch.ts +196 -0
- package/src/commands/diff-color-config.ts +274 -0
- package/src/commands/diff-command.ts +1053 -75
- package/src/commands/fetch-command.ts +161 -13
- package/src/commands/fmt-merge-msg-command.ts +715 -0
- package/src/commands/fork-point.ts +63 -0
- package/src/commands/format-patch-command.ts +316 -43
- package/src/commands/fsck/fetch-fsck.ts +172 -18
- package/src/commands/fsck/fsck-command.ts +183 -66
- package/src/commands/fsck/fsck-loose.ts +14 -4
- package/src/commands/fsck/fsck-object-checks.ts +87 -46
- package/src/commands/fsck/fsck-object-table.ts +52 -42
- package/src/commands/fsck/fsck-pack.ts +64 -34
- package/src/commands/fsck/verify-pack-command.ts +5 -2
- package/src/commands/gc-command.ts +238 -107
- package/src/commands/git-date.ts +9 -895
- package/src/commands/git-describe.ts +31 -11
- package/src/commands/git-hooks.ts +92 -0
- package/src/commands/grep/grep-command.ts +1077 -0
- package/src/commands/grep/grep-engine.ts +1024 -0
- package/src/commands/grep/index.ts +2 -0
- package/src/commands/index-adder.ts +54 -10
- package/src/commands/index.ts +28 -0
- package/src/commands/init-command.ts +167 -11
- package/src/commands/interpret-trailers-command.ts +256 -0
- package/src/commands/legacy-remotes.ts +224 -0
- package/src/commands/local-transport.ts +109 -10
- package/src/commands/log-command.ts +1283 -232
- package/src/commands/log-graph.ts +123 -26
- package/src/commands/log-output.ts +280 -21
- package/src/commands/ls-remote-command.ts +9 -0
- package/src/commands/mailmap.ts +119 -0
- package/src/commands/merge-base-command.ts +170 -0
- package/src/commands/merge-bases.ts +63 -8
- package/src/commands/merge-command.ts +360 -82
- package/src/commands/merge-support.ts +43 -9
- package/src/commands/mv-command.ts +6 -3
- package/src/commands/name-rev.ts +171 -0
- package/src/commands/notes-command.ts +11 -1
- package/src/commands/notes-merge-command.ts +23 -14
- package/src/commands/notes-tree.ts +28 -13
- package/src/commands/octopus-merge.ts +3 -2
- package/src/commands/patch-id.ts +16 -8
- package/src/commands/pathspec-file.ts +72 -0
- package/src/commands/pathspec.ts +14 -2
- package/src/commands/pretty-format.ts +105 -20
- package/src/commands/promisor-remote.ts +10 -1
- package/src/commands/pull-command.ts +149 -22
- package/src/commands/push-command.ts +704 -72
- package/src/commands/read-tree-command.ts +34 -3
- package/src/commands/rebase-command.ts +957 -142
- package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
- package/src/commands/ref-filter/index.ts +7 -0
- package/src/commands/ref-filter/ref-atoms.ts +581 -0
- package/src/commands/ref-filter/ref-filter.ts +651 -0
- package/src/commands/ref-filter/ref-format.ts +1070 -0
- package/src/commands/ref-filter/ref-listing-command.ts +421 -0
- package/src/commands/ref-filter/ref-quote.ts +69 -0
- package/src/commands/ref-filter/version-compare.ts +177 -0
- package/src/commands/reflog-command.ts +492 -2
- package/src/commands/reflog-walk.ts +234 -0
- package/src/commands/remote-command.ts +484 -74
- package/src/commands/remote-transport.ts +9 -1
- package/src/commands/reset-command.ts +40 -42
- package/src/commands/restore-command.ts +12 -41
- package/src/commands/rev-filter/commit-filter.ts +159 -0
- package/src/commands/rev-filter/commit-grep.ts +444 -0
- package/src/commands/rev-filter/index.ts +2 -0
- package/src/commands/rev-list-command.ts +402 -15
- package/src/commands/rev-parse-command.ts +22 -0
- package/src/commands/revert-command.ts +82 -0
- package/src/commands/revision-range.ts +204 -4
- package/src/commands/revision-resolver.ts +55 -22
- package/src/commands/rm-command.ts +282 -21
- package/src/commands/sequencer-pick.ts +504 -86
- package/src/commands/sequencer-support.ts +30 -5
- package/src/commands/serve-repository.ts +18 -3
- package/src/commands/show-command.ts +490 -0
- package/src/commands/show-commit.ts +24 -0
- package/src/commands/signature-check.ts +657 -0
- package/src/commands/signing.ts +385 -0
- package/src/commands/sparse-checkout-command.ts +2 -9
- package/src/commands/sparse-checkout-support.ts +2 -2
- package/src/commands/sparse-index-view.ts +135 -0
- package/src/commands/ssh-signer.ts +199 -0
- package/src/commands/ssh-verifier.ts +523 -0
- package/src/commands/stash-apply-command.ts +17 -5
- package/src/commands/stash-branch-command.ts +88 -0
- package/src/commands/stash-create-command.ts +30 -2
- package/src/commands/stash-info.ts +243 -0
- package/src/commands/stash-list-command.ts +33 -0
- package/src/commands/stash-pop-command.ts +83 -0
- package/src/commands/stash-show-command.ts +141 -0
- package/src/commands/stash-store-command.ts +82 -0
- package/src/commands/stash-working-tree.ts +2 -2
- package/src/commands/status-command.ts +7 -6
- package/src/commands/status-header.ts +44 -8
- package/src/commands/submodule-add-command.ts +509 -0
- package/src/commands/submodule-auth.ts +276 -0
- package/src/commands/submodule-commands.ts +1517 -0
- package/src/commands/submodule-model.ts +930 -0
- package/src/commands/submodule-summary-command.ts +6 -7
- package/src/commands/submodule-update-command.ts +1092 -0
- package/src/commands/switch-command.ts +3 -1
- package/src/commands/tag-command.ts +876 -64
- package/src/commands/trailers.ts +837 -100
- package/src/commands/tree-restore.ts +38 -10
- package/src/commands/untracked-cache-support.ts +16 -12
- package/src/commands/verify-command.ts +235 -0
- package/src/commands/worktree-add-command.ts +268 -24
- package/src/commands/worktree-list-command.ts +3 -5
- package/src/commands/worktree-path-rules.ts +183 -0
- package/src/commands/worktree-remove-command.ts +39 -5
- package/src/commands/worktree-repair-command.ts +52 -5
- package/src/commands/worktree-support.ts +22 -1
- package/src/core-commands/add.command.impl.ts +1 -1
- package/src/errors/checkout-errors.ts +29 -0
- package/src/errors/command-errors.ts +2 -1
- package/src/errors/ref-errors.ts +23 -0
- package/src/errors/worktree-errors.ts +8 -1
- package/src/git-command.ts +98 -3
- package/src/git.ts +420 -4
- package/src/remote-config/index.ts +4 -0
- package/src/remote-config/remote-config-store.ts +238 -11
- package/src/rename/detect-renames.ts +5 -1
- package/src/results/clone-result.ts +9 -0
- package/src/results/combined-diff.ts +38 -18
- package/src/results/diff-check.ts +185 -0
- package/src/results/diff-color.ts +868 -0
- package/src/results/diff-output.ts +204 -37
- package/src/results/diff-pickaxe.ts +304 -0
- package/src/results/diff-words.ts +395 -0
- package/src/results/index.ts +4 -0
- package/src/results/init-result.ts +9 -0
- package/src/results/pull-result.ts +5 -0
- package/src/results/push-result.ts +12 -0
- package/src/results/rebase-result.ts +3 -0
- package/src/results/stash-result.ts +7 -0
- package/src/results/status-result.ts +5 -2
- package/src/whitespace/index.ts +1 -0
- package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
- package/dist/commands/apply/whitespace.d.ts +0 -58
- package/dist/commands/apply/whitespace.d.ts.map +0 -1
|
@@ -1,7 +1,371 @@
|
|
|
1
|
+
import { GitApiError } from "./errors/index.js";
|
|
1
2
|
import { DEFAULT_BIG_FILE_THRESHOLD, probeBlob } from "@statewalker/vcs-core";
|
|
2
3
|
import { compareGitPaths, decodeGitPath, encodeGitPath, gitCharWidthAt, gitStrWidth, parseGitBool } from "@statewalker/vcs-utils/encoding";
|
|
3
4
|
import { wildmatch } from "@statewalker/vcs-working-tree";
|
|
4
|
-
import { ByteSink, XDF_IGNORE_WHITESPACE, XDF_IGNORE_WHITESPACE_CHANGE, XDF_WHITESPACE_FLAGS, bytesToHex, compressBlockPako, createSha1, diffLineCounts, unifiedDiffHunks, userdiffFindFunction, whitespaceFlags, writeHunks, xdlIsSpace } from "@statewalker/vcs-utils";
|
|
5
|
+
import { BUILTIN_FUNCNAME_PATTERNS, BUILTIN_FUNCNAME_PATTERNS_2_43, BUILTIN_WORD_REGEXES, BUILTIN_WORD_REGEXES_2_43, ByteSink, PosixRegexError, XDF_IGNORE_WHITESPACE, XDF_IGNORE_WHITESPACE_CHANGE, XDF_WHITESPACE_FLAGS, bytesToHex, compilePosixRegex, compressBlockPako, createSha1, diffLineCounts, formatHunkHeader, nullObjectIdLike, unifiedDiffHunks, userdiffFindFunction, userdiffWordRegex, whitespaceFlags, writeHunks, xdiffHunks, xdlHashRecord, xdlIsSpace, xdlRecmatch } from "@statewalker/vcs-utils";
|
|
6
|
+
const WS_BLANK_AT_EOF = 1024;
|
|
7
|
+
const WS_TAB_IN_INDENT = 2048;
|
|
8
|
+
const WS_INCOMPLETE_LINE = 4096;
|
|
9
|
+
const WS_TRAILING_SPACE = 1088;
|
|
10
|
+
const WS_DEFAULT_RULE = 1224;
|
|
11
|
+
/** The tab width a rule carries (`ws_tab_width`). */
|
|
12
|
+
function wsTabWidth(rule) {
|
|
13
|
+
return rule & 63;
|
|
14
|
+
}
|
|
15
|
+
const RULE_NAMES = [
|
|
16
|
+
{
|
|
17
|
+
name: "trailing-space",
|
|
18
|
+
bits: WS_TRAILING_SPACE,
|
|
19
|
+
loosens: false,
|
|
20
|
+
excludeDefault: false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "space-before-tab",
|
|
24
|
+
bits: 128,
|
|
25
|
+
loosens: false,
|
|
26
|
+
excludeDefault: false
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "indent-with-non-tab",
|
|
30
|
+
bits: 256,
|
|
31
|
+
loosens: false,
|
|
32
|
+
excludeDefault: false
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "cr-at-eol",
|
|
36
|
+
bits: 512,
|
|
37
|
+
loosens: true,
|
|
38
|
+
excludeDefault: false
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "blank-at-eol",
|
|
42
|
+
bits: 64,
|
|
43
|
+
loosens: false,
|
|
44
|
+
excludeDefault: false
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "blank-at-eof",
|
|
48
|
+
bits: WS_BLANK_AT_EOF,
|
|
49
|
+
loosens: false,
|
|
50
|
+
excludeDefault: false
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "tab-in-indent",
|
|
54
|
+
bits: WS_TAB_IN_INDENT,
|
|
55
|
+
loosens: false,
|
|
56
|
+
excludeDefault: true
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "incomplete-line",
|
|
60
|
+
bits: WS_INCOMPLETE_LINE,
|
|
61
|
+
loosens: false,
|
|
62
|
+
excludeDefault: false
|
|
63
|
+
}
|
|
64
|
+
];
|
|
65
|
+
/** git's `isspace`: space, tab, LF and CR only (not VT or FF). */
|
|
66
|
+
function isGitSpace(ch) {
|
|
67
|
+
return ch === 32 || ch === 9 || ch === 10 || ch === 13;
|
|
68
|
+
}
|
|
69
|
+
/** An invalid rule combination (git dies). */
|
|
70
|
+
var WhitespaceRuleError = class extends Error {};
|
|
71
|
+
/**
|
|
72
|
+
* Parses a `core.whitespace` value (or a `whitespace=<rules>` attribute) as
|
|
73
|
+
* `parse_whitespace_rule` does: comma-separated names (or a prefix of one), `-name` to turn
|
|
74
|
+
* one off, `tabwidth=<n>`.
|
|
75
|
+
*
|
|
76
|
+
* @throws WhitespaceRuleError for `tab-in-indent` with `indent-with-non-tab` (git dies)
|
|
77
|
+
*/
|
|
78
|
+
function parseWhitespaceRule(value, warn, options = {}) {
|
|
79
|
+
const names = options.compatibility === "2.43" ? RULE_NAMES.filter((r) => r.bits !== WS_INCOMPLETE_LINE) : RULE_NAMES;
|
|
80
|
+
let rule = WS_DEFAULT_RULE;
|
|
81
|
+
let at = 0;
|
|
82
|
+
while (at <= value.length) {
|
|
83
|
+
while (at < value.length && ", \n\r".includes(value[at])) at++;
|
|
84
|
+
let ep = value.indexOf(",", at);
|
|
85
|
+
if (ep < 0) ep = value.length;
|
|
86
|
+
let start = at;
|
|
87
|
+
let len = ep - start;
|
|
88
|
+
let negated = false;
|
|
89
|
+
if (value[start] === "-") {
|
|
90
|
+
negated = true;
|
|
91
|
+
start++;
|
|
92
|
+
len--;
|
|
93
|
+
}
|
|
94
|
+
if (len <= 0) break;
|
|
95
|
+
const word = value.slice(start, start + len);
|
|
96
|
+
for (const r of names) {
|
|
97
|
+
if (r.name.slice(0, len) !== word || len > r.name.length && word !== r.name) continue;
|
|
98
|
+
if (negated) rule &= ~r.bits;
|
|
99
|
+
else rule |= r.bits;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
if (value.startsWith("tabwidth=", start)) {
|
|
103
|
+
const arg = value.slice(start + 9, ep);
|
|
104
|
+
const tabwidth = Number.parseInt(arg, 10) || 0;
|
|
105
|
+
if (tabwidth > 0 && tabwidth < 64) {
|
|
106
|
+
rule &= -64;
|
|
107
|
+
rule |= tabwidth;
|
|
108
|
+
} else warn?.(`tabwidth ${arg} out of range`);
|
|
109
|
+
}
|
|
110
|
+
if (ep >= value.length) break;
|
|
111
|
+
at = ep;
|
|
112
|
+
}
|
|
113
|
+
if (rule & 2048 && rule & 256) throw new WhitespaceRuleError("cannot enforce both tab-in-indent and indent-with-non-tab");
|
|
114
|
+
return rule;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The rule for one path (`whitespace_rule`): from its `whitespace` attribute (true, false,
|
|
118
|
+
* unset or a rule list), `configRule` (`core.whitespace`) by default.
|
|
119
|
+
*/
|
|
120
|
+
function whitespaceRuleOf(attribute, configRule) {
|
|
121
|
+
if (attribute === true) {
|
|
122
|
+
let all = wsTabWidth(configRule);
|
|
123
|
+
for (const r of RULE_NAMES) if (!r.loosens && !r.excludeDefault) all |= r.bits;
|
|
124
|
+
return all;
|
|
125
|
+
}
|
|
126
|
+
if (attribute === false) return wsTabWidth(configRule);
|
|
127
|
+
if (attribute === void 0) return configRule;
|
|
128
|
+
return parseWhitespaceRule(attribute);
|
|
129
|
+
}
|
|
130
|
+
/** The message naming the errors in `ws` (`whitespace_error_string`). */
|
|
131
|
+
function whitespaceErrorString(ws) {
|
|
132
|
+
const parts = [];
|
|
133
|
+
if ((ws & 1088) === 1088) parts.push("trailing whitespace");
|
|
134
|
+
else {
|
|
135
|
+
if (ws & 64) parts.push("trailing whitespace");
|
|
136
|
+
if (ws & 1024) parts.push("new blank line at EOF");
|
|
137
|
+
}
|
|
138
|
+
if (ws & 128) parts.push("space before tab in indent");
|
|
139
|
+
if (ws & 256) parts.push("indent with spaces");
|
|
140
|
+
if (ws & 2048) parts.push("tab in indent");
|
|
141
|
+
if (ws & 4096) parts.push("no newline at the end of file");
|
|
142
|
+
return parts.join(", ");
|
|
143
|
+
}
|
|
144
|
+
const codeAt = (line, i) => typeof line === "string" ? line.charCodeAt(i) : line[i];
|
|
145
|
+
/**
|
|
146
|
+
* ws.c's `ws_check_emit_1`: the errors of `rule` in `line` (its LF included, if any),
|
|
147
|
+
* writing the line to `out` with the errors in `ws` and the rest in `set` when given.
|
|
148
|
+
*/
|
|
149
|
+
function wsCheckEmit1(line, rule, emit) {
|
|
150
|
+
let result = 0;
|
|
151
|
+
let written = 0;
|
|
152
|
+
let trailingWhitespace = -1;
|
|
153
|
+
let trailingNewline = false;
|
|
154
|
+
let trailingCarriageReturn = false;
|
|
155
|
+
let len = line.length;
|
|
156
|
+
const out = emit?.out;
|
|
157
|
+
const part = (from, to) => {
|
|
158
|
+
if (!out || to <= from) return;
|
|
159
|
+
if (typeof line === "string") {
|
|
160
|
+
const bytes = new Uint8Array(to - from);
|
|
161
|
+
for (let i = from; i < to; i++) bytes[i - from] = line.charCodeAt(i) & 255;
|
|
162
|
+
out.bytes(bytes);
|
|
163
|
+
} else out.bytes(line.subarray(from, to));
|
|
164
|
+
};
|
|
165
|
+
if (len > 0 && codeAt(line, len - 1) === 10) {
|
|
166
|
+
trailingNewline = true;
|
|
167
|
+
len--;
|
|
168
|
+
}
|
|
169
|
+
if (rule & 512 && len > 0 && codeAt(line, len - 1) === 13) {
|
|
170
|
+
trailingCarriageReturn = true;
|
|
171
|
+
len--;
|
|
172
|
+
}
|
|
173
|
+
if (rule & 64) for (let i = len - 1; i >= 0; i--) if (isGitSpace(codeAt(line, i))) {
|
|
174
|
+
trailingWhitespace = i;
|
|
175
|
+
result |= 64;
|
|
176
|
+
} else break;
|
|
177
|
+
if (trailingWhitespace === -1) trailingWhitespace = len;
|
|
178
|
+
if (!trailingNewline && rule & 4096) result |= WS_INCOMPLETE_LINE;
|
|
179
|
+
let i = 0;
|
|
180
|
+
for (; i < trailingWhitespace; i++) {
|
|
181
|
+
const ch = codeAt(line, i);
|
|
182
|
+
if (ch === 32) continue;
|
|
183
|
+
if (ch !== 9) break;
|
|
184
|
+
if (rule & 128 && written < i) {
|
|
185
|
+
result |= 128;
|
|
186
|
+
if (emit) {
|
|
187
|
+
emit.out.str(emit.ws);
|
|
188
|
+
part(written, i);
|
|
189
|
+
emit.out.str(emit.reset);
|
|
190
|
+
part(i, i + 1);
|
|
191
|
+
}
|
|
192
|
+
} else if (rule & 2048) {
|
|
193
|
+
result |= WS_TAB_IN_INDENT;
|
|
194
|
+
if (emit) {
|
|
195
|
+
part(written, i);
|
|
196
|
+
emit.out.str(emit.ws);
|
|
197
|
+
part(i, i + 1);
|
|
198
|
+
emit.out.str(emit.reset);
|
|
199
|
+
}
|
|
200
|
+
} else part(written, i + 1);
|
|
201
|
+
written = i + 1;
|
|
202
|
+
}
|
|
203
|
+
if (rule & 256 && i - written >= wsTabWidth(rule)) {
|
|
204
|
+
result |= 256;
|
|
205
|
+
if (emit) {
|
|
206
|
+
emit.out.str(emit.ws);
|
|
207
|
+
part(written, i);
|
|
208
|
+
emit.out.str(emit.reset);
|
|
209
|
+
}
|
|
210
|
+
written = i;
|
|
211
|
+
}
|
|
212
|
+
if (emit) {
|
|
213
|
+
if (trailingWhitespace - written > 0) {
|
|
214
|
+
emit.out.str(emit.set);
|
|
215
|
+
part(written, trailingWhitespace);
|
|
216
|
+
emit.out.str(emit.reset);
|
|
217
|
+
}
|
|
218
|
+
if (trailingWhitespace !== len) {
|
|
219
|
+
emit.out.str(emit.ws);
|
|
220
|
+
part(trailingWhitespace, len);
|
|
221
|
+
emit.out.str(emit.reset);
|
|
222
|
+
}
|
|
223
|
+
if (trailingCarriageReturn) part(len, len + 1);
|
|
224
|
+
if (trailingNewline) part(line.length - 1, line.length);
|
|
225
|
+
}
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
/** The whitespace errors of one line (with or without its LF), as `ws_check` finds them. */
|
|
229
|
+
function wsCheck(line, rule) {
|
|
230
|
+
return wsCheckEmit1(line, rule);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* ws.c's `ws_check_emit`: writes the line (its LF included, if any) to `out`, the errors of
|
|
234
|
+
* `rule` in the `ws` color and the rest in `set`; returns the errors.
|
|
235
|
+
*/
|
|
236
|
+
function wsCheckEmit(line, rule, out, set, reset, ws) {
|
|
237
|
+
return wsCheckEmit1(line, rule, {
|
|
238
|
+
out,
|
|
239
|
+
set,
|
|
240
|
+
reset,
|
|
241
|
+
ws
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/** Whether a line (or its part from `start` to `end`) holds whitespace only (`ws_blank_line`). */
|
|
245
|
+
function wsBlankLine(line, start = 0, end = line.length) {
|
|
246
|
+
for (let i = start; i < end; i++) if (!isGitSpace(codeAt(line, i))) return false;
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
/** diff.c's `count_trailing_blank`: the blank lines at the end of a file */
|
|
250
|
+
function countTrailingBlank(mf) {
|
|
251
|
+
let cnt = 0;
|
|
252
|
+
if (mf.length === 0) return 0;
|
|
253
|
+
let ptr = mf.length - 1;
|
|
254
|
+
if (mf[ptr] === 10) ptr--;
|
|
255
|
+
while (0 < ptr) {
|
|
256
|
+
let prevEol = ptr;
|
|
257
|
+
for (; 0 <= prevEol; prevEol--) if (mf[prevEol] === 10) break;
|
|
258
|
+
if (!wsBlankLine(mf, prevEol + 1, ptr + 1)) break;
|
|
259
|
+
cnt++;
|
|
260
|
+
ptr = prevEol - 1;
|
|
261
|
+
}
|
|
262
|
+
return cnt;
|
|
263
|
+
}
|
|
264
|
+
/** diff.c's `count_lines` */
|
|
265
|
+
function countLines(data) {
|
|
266
|
+
if (data.length === 0) return 0;
|
|
267
|
+
let count = 0;
|
|
268
|
+
for (const c of data) if (c === 10) count++;
|
|
269
|
+
if (data[data.length - 1] !== 10) count++;
|
|
270
|
+
return count;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* diff.c's `check_blank_at_eof`: where the blank lines a change adds at the end of the file
|
|
274
|
+
* start, in each image (1-based), or zeros when it adds none
|
|
275
|
+
*/
|
|
276
|
+
function checkBlankAtEof(preimage, postimage) {
|
|
277
|
+
const l1 = countTrailingBlank(preimage);
|
|
278
|
+
const l2 = countTrailingBlank(postimage);
|
|
279
|
+
if (l2 <= l1) return {
|
|
280
|
+
preimage: 0,
|
|
281
|
+
postimage: 0
|
|
282
|
+
};
|
|
283
|
+
return {
|
|
284
|
+
preimage: countLines(preimage) - l1 + 1,
|
|
285
|
+
postimage: countLines(postimage) - l2 + 1
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* The line with its whitespace errors fixed (`ws_fix_copy`); `fixed` tells whether anything
|
|
290
|
+
* changed.
|
|
291
|
+
*/
|
|
292
|
+
function wsFixCopy(src, rule) {
|
|
293
|
+
let len = src.length;
|
|
294
|
+
let start = 0;
|
|
295
|
+
let addNl = false;
|
|
296
|
+
let addCr = false;
|
|
297
|
+
let fixed = false;
|
|
298
|
+
let lastTab = -1;
|
|
299
|
+
let lastSpace = -1;
|
|
300
|
+
let needFix = false;
|
|
301
|
+
if (rule & 4096 && len > 0 && src.charCodeAt(len - 1) !== 10) {
|
|
302
|
+
fixed = true;
|
|
303
|
+
addNl = true;
|
|
304
|
+
}
|
|
305
|
+
if (rule & 64) {
|
|
306
|
+
if (len > 0 && src.charCodeAt(len - 1) === 10) {
|
|
307
|
+
addNl = true;
|
|
308
|
+
len--;
|
|
309
|
+
if (len > 0 && src.charCodeAt(len - 1) === 13) {
|
|
310
|
+
addCr = (rule & 512) !== 0;
|
|
311
|
+
len--;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (len > 0 && isGitSpace(src.charCodeAt(len - 1))) {
|
|
315
|
+
while (len > 0 && isGitSpace(src.charCodeAt(len - 1))) len--;
|
|
316
|
+
fixed = true;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
for (let i = 0; i < len; i++) {
|
|
320
|
+
const ch = src.charCodeAt(i);
|
|
321
|
+
if (ch === 9) {
|
|
322
|
+
lastTab = i;
|
|
323
|
+
if (rule & 128 && lastSpace >= 0) needFix = true;
|
|
324
|
+
} else if (ch === 32) {
|
|
325
|
+
lastSpace = i;
|
|
326
|
+
if (rule & 256 && wsTabWidth(rule) <= i - lastTab) needFix = true;
|
|
327
|
+
} else break;
|
|
328
|
+
}
|
|
329
|
+
let out = "";
|
|
330
|
+
const width = wsTabWidth(rule);
|
|
331
|
+
if (needFix) {
|
|
332
|
+
let consecutive = 0;
|
|
333
|
+
let last = lastTab + 1;
|
|
334
|
+
if (rule & 256) last = lastTab < lastSpace ? lastSpace + 1 : lastTab + 1;
|
|
335
|
+
for (let i = 0; i < last; i++) {
|
|
336
|
+
const ch = src[i];
|
|
337
|
+
if (ch !== " ") {
|
|
338
|
+
consecutive = 0;
|
|
339
|
+
out += ch;
|
|
340
|
+
} else {
|
|
341
|
+
consecutive++;
|
|
342
|
+
if (consecutive === width) {
|
|
343
|
+
out += " ";
|
|
344
|
+
consecutive = 0;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
while (consecutive-- > 0) out += " ";
|
|
349
|
+
start = last;
|
|
350
|
+
fixed = true;
|
|
351
|
+
} else if (rule & 2048 && lastTab >= 0) {
|
|
352
|
+
const last = lastTab + 1;
|
|
353
|
+
for (let i = 0; i < last; i++) if (src[i] === " ") do
|
|
354
|
+
out += " ";
|
|
355
|
+
while (out.length % width);
|
|
356
|
+
else out += src[i];
|
|
357
|
+
start = last;
|
|
358
|
+
fixed = true;
|
|
359
|
+
}
|
|
360
|
+
out += src.slice(start, len);
|
|
361
|
+
if (addCr) out += "\r";
|
|
362
|
+
if (addNl) out += "\n";
|
|
363
|
+
return {
|
|
364
|
+
text: out,
|
|
365
|
+
fixed
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
//#endregion
|
|
5
369
|
//#region src/results/quote-path.ts
|
|
6
370
|
/**
|
|
7
371
|
* Path quoting as git prints paths (`quote.c`'s `quote_c_style`): a path with a control
|
|
@@ -348,13 +712,25 @@ function hunkCommentLine(bol) {
|
|
|
348
712
|
const ch = bol[0];
|
|
349
713
|
return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch === 95 || ch === 36;
|
|
350
714
|
}
|
|
351
|
-
/** `show_line_to_eol
|
|
352
|
-
function lineToEol(sink, line) {
|
|
353
|
-
|
|
354
|
-
|
|
715
|
+
/** `show_line_to_eol`: the line, the reset, then its CR and an LF */
|
|
716
|
+
function lineToEol(sink, line, reset) {
|
|
717
|
+
if (!reset) {
|
|
718
|
+
sink.push(line);
|
|
719
|
+
sink.text("\n");
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
const cr = line.length > 0 && line[line.length - 1] === 13;
|
|
723
|
+
sink.push(cr ? line.subarray(0, line.length - 1) : line);
|
|
724
|
+
sink.text(`${reset}${cr ? "\r" : ""}\n`);
|
|
355
725
|
}
|
|
356
726
|
/** combine-diff.c's `dump_sline` */
|
|
357
|
-
function dumpSline(sink, sline, cnt, numParent, context, resultDeleted) {
|
|
727
|
+
function dumpSline(sink, sline, cnt, numParent, context, resultDeleted, colors) {
|
|
728
|
+
const cFrag = colors?.frag ?? "";
|
|
729
|
+
const cFunc = colors?.func ?? "";
|
|
730
|
+
const cNew = colors?.new ?? "";
|
|
731
|
+
const cOld = colors?.old ?? "";
|
|
732
|
+
const cContext = colors?.context ?? "";
|
|
733
|
+
const cReset = colors?.reset ?? "";
|
|
358
734
|
const mark = 1 << numParent;
|
|
359
735
|
const noPreDelete = 2 << numParent;
|
|
360
736
|
if (resultDeleted) return;
|
|
@@ -382,7 +758,7 @@ function dumpSline(sink, sline, cnt, numParent, context, resultDeleted) {
|
|
|
382
758
|
head += ` -${l0},${unsignedLong(l1 - l0 - nullContext)}`;
|
|
383
759
|
}
|
|
384
760
|
head += ` +${lno + 1},${unsignedLong(rlines)} ${"@".repeat(numParent + 1)}`;
|
|
385
|
-
sink.text(head);
|
|
761
|
+
sink.text(cFrag + head);
|
|
386
762
|
if (hunkComment) {
|
|
387
763
|
let commentEnd = 0;
|
|
388
764
|
for (let i = 0; i < 40 && i < hunkComment.length; i++) {
|
|
@@ -391,26 +767,26 @@ function dumpSline(sink, sline, cnt, numParent, context, resultDeleted) {
|
|
|
391
767
|
if (!xdlIsSpace(ch)) commentEnd = i;
|
|
392
768
|
}
|
|
393
769
|
if (commentEnd) {
|
|
394
|
-
sink.text(
|
|
770
|
+
sink.text(`${cReset}${cContext} ${cReset}${cFunc}`);
|
|
395
771
|
sink.push(hunkComment.subarray(0, commentEnd));
|
|
396
772
|
}
|
|
397
773
|
}
|
|
398
|
-
sink.text(
|
|
774
|
+
sink.text(`${cReset}\n`);
|
|
399
775
|
while (lno < hunkEnd) {
|
|
400
776
|
const sl = sline[lno++];
|
|
401
777
|
const lost = sl.flag & noPreDelete ? [] : sl.lost;
|
|
402
778
|
for (const ll of lost) {
|
|
403
779
|
let marks = "";
|
|
404
780
|
for (let j = 0; j < numParent; j++) marks += ll.parentMap & 1 << j ? "-" : " ";
|
|
405
|
-
sink.text(marks);
|
|
406
|
-
lineToEol(sink, ll.line);
|
|
781
|
+
sink.text(cOld + marks);
|
|
782
|
+
lineToEol(sink, ll.line, cReset);
|
|
407
783
|
}
|
|
408
784
|
if (cnt < lno) break;
|
|
409
785
|
if (!(sl.flag & mark - 1) && !context) continue;
|
|
410
|
-
let marks =
|
|
786
|
+
let marks = sl.flag & mark - 1 ? cNew : cContext;
|
|
411
787
|
for (let j = 0; j < numParent; j++) marks += sl.flag & 1 << j ? "+" : " ";
|
|
412
788
|
sink.text(marks);
|
|
413
|
-
lineToEol(sink, sl.bol ?? /* @__PURE__ */ new Uint8Array(0));
|
|
789
|
+
lineToEol(sink, sl.bol ?? /* @__PURE__ */ new Uint8Array(0), cReset);
|
|
414
790
|
}
|
|
415
791
|
}
|
|
416
792
|
}
|
|
@@ -422,24 +798,26 @@ function writeHeader(sink, elem, options, modeDiffers, showFileHeader) {
|
|
|
422
798
|
const quote = options.quotePath ?? true;
|
|
423
799
|
const abbreviate = options.abbreviate ?? ((id) => id.slice(0, 7));
|
|
424
800
|
const dense = options.dense ?? true;
|
|
425
|
-
|
|
426
|
-
|
|
801
|
+
const m = options.colors?.meta ?? "";
|
|
802
|
+
const r = options.colors?.reset ?? "";
|
|
803
|
+
sink.text(`${m}${dense ? "diff --cc " : "diff --combined "}${quoteTwo("", elem.path, quote)}${r}\n`);
|
|
804
|
+
sink.text(`${m}index ${elem.parents.map((p) => abbreviate(p.id)).join(",")}..${abbreviate(elem.result.id)}${r}\n`);
|
|
427
805
|
const deleted = !elem.result.mode;
|
|
428
806
|
const added = !deleted && elem.parents.every((p) => !p.mode);
|
|
429
807
|
if (modeDiffers) {
|
|
430
|
-
if (added) sink.text(
|
|
808
|
+
if (added) sink.text(`${m}new file mode ${octal6$1(elem.result.mode)}${r}\n`);
|
|
431
809
|
else {
|
|
432
810
|
let line = deleted ? "deleted file mode " : "mode ";
|
|
433
811
|
line += elem.parents.map((p) => octal6$1(p.mode)).join(",");
|
|
434
812
|
if (elem.result.mode) line += `..${octal6$1(elem.result.mode)}`;
|
|
435
|
-
sink.text(`${line}\n`);
|
|
813
|
+
sink.text(`${m}${line}${r}\n`);
|
|
436
814
|
}
|
|
437
815
|
}
|
|
438
816
|
if (!showFileHeader) return;
|
|
439
817
|
const aPrefix = options.srcPrefix ?? "a/";
|
|
440
818
|
const bPrefix = options.dstPrefix ?? "b/";
|
|
441
|
-
sink.text(added ? "
|
|
442
|
-
sink.text(deleted ? "
|
|
819
|
+
sink.text(`${m}--- ${added ? "/dev/null" : quoteTwo(aPrefix, elem.path, quote)}${r}\n`);
|
|
820
|
+
sink.text(`${m}+++ ${deleted ? "/dev/null" : quoteTwo(bPrefix, elem.path, quote)}${r}\n`);
|
|
443
821
|
}
|
|
444
822
|
/**
|
|
445
823
|
* The dense combined diff of a path whose result is a worktree file (`show_patch_diff` with
|
|
@@ -484,7 +862,7 @@ function writeCombinedDiff(sink, elem, options = {}) {
|
|
|
484
862
|
}
|
|
485
863
|
if (!makeHunks(sline, cnt, numParent, context, options.dense ?? true) && !modeDiffers && options.workingTreeFile === false) return;
|
|
486
864
|
writeHeader(sink, elem, options, modeDiffers, true);
|
|
487
|
-
dumpSline(sink, sline, cnt, numParent, context, resultDeleted);
|
|
865
|
+
dumpSline(sink, sline, cnt, numParent, context, resultDeleted, options.colors);
|
|
488
866
|
}
|
|
489
867
|
/**
|
|
490
868
|
* A count as git's `%lu` prints it: git keeps the hunk header's counts in `unsigned long`, so
|
|
@@ -495,90 +873,6 @@ function unsignedLong(n) {
|
|
|
495
873
|
return n < 0 ? (2n ** 64n + BigInt(n)).toString() : String(n);
|
|
496
874
|
}
|
|
497
875
|
//#endregion
|
|
498
|
-
//#region src/results/diff-entry.ts
|
|
499
|
-
/**
|
|
500
|
-
* Type of change in a diff entry.
|
|
501
|
-
*/
|
|
502
|
-
let ChangeType = /* @__PURE__ */ function(ChangeType) {
|
|
503
|
-
/** File was added */
|
|
504
|
-
ChangeType["ADD"] = "ADD";
|
|
505
|
-
/** File was modified */
|
|
506
|
-
ChangeType["MODIFY"] = "MODIFY";
|
|
507
|
-
/** File was deleted */
|
|
508
|
-
ChangeType["DELETE"] = "DELETE";
|
|
509
|
-
/** File was renamed */
|
|
510
|
-
ChangeType["RENAME"] = "RENAME";
|
|
511
|
-
/** File was copied */
|
|
512
|
-
ChangeType["COPY"] = "COPY";
|
|
513
|
-
return ChangeType;
|
|
514
|
-
}({});
|
|
515
|
-
/**
|
|
516
|
-
* Create a DiffEntry for an added file.
|
|
517
|
-
*/
|
|
518
|
-
function createAddEntry(path, id, mode) {
|
|
519
|
-
return {
|
|
520
|
-
changeType: "ADD",
|
|
521
|
-
newPath: path,
|
|
522
|
-
newId: id,
|
|
523
|
-
newMode: mode
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Create a DiffEntry for a deleted file.
|
|
528
|
-
*/
|
|
529
|
-
function createDeleteEntry(path, id, mode) {
|
|
530
|
-
return {
|
|
531
|
-
changeType: "DELETE",
|
|
532
|
-
oldPath: path,
|
|
533
|
-
oldId: id,
|
|
534
|
-
oldMode: mode
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Create a DiffEntry for a modified file.
|
|
539
|
-
*/
|
|
540
|
-
function createModifyEntry(path, oldId, newId, oldMode, newMode) {
|
|
541
|
-
return {
|
|
542
|
-
changeType: "MODIFY",
|
|
543
|
-
oldPath: path,
|
|
544
|
-
newPath: path,
|
|
545
|
-
oldId,
|
|
546
|
-
newId,
|
|
547
|
-
oldMode,
|
|
548
|
-
newMode
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* Create a DiffEntry for a renamed file.
|
|
553
|
-
*/
|
|
554
|
-
function createRenameEntry(oldPath, newPath, oldId, newId, oldMode, newMode, score) {
|
|
555
|
-
return {
|
|
556
|
-
changeType: "RENAME",
|
|
557
|
-
oldPath,
|
|
558
|
-
newPath,
|
|
559
|
-
oldId,
|
|
560
|
-
newId,
|
|
561
|
-
oldMode,
|
|
562
|
-
newMode,
|
|
563
|
-
score
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Create a DiffEntry for a copied file.
|
|
568
|
-
*/
|
|
569
|
-
function createCopyEntry(oldPath, newPath, oldId, newId, oldMode, newMode, score) {
|
|
570
|
-
return {
|
|
571
|
-
changeType: "COPY",
|
|
572
|
-
oldPath,
|
|
573
|
-
newPath,
|
|
574
|
-
oldId,
|
|
575
|
-
newId,
|
|
576
|
-
oldMode,
|
|
577
|
-
newMode,
|
|
578
|
-
score
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
//#endregion
|
|
582
876
|
//#region src/results/binary-patch.ts
|
|
583
877
|
/**
|
|
584
878
|
* git's binary patch body (diff.c's `emit_binary_diff`): the postimage deflated (zlib
|
|
@@ -1380,110 +1674,1073 @@ function gitBinaryPatch(one, two) {
|
|
|
1380
1674
|
return `GIT binary patch\n${binaryDiffBody(one, two)}${binaryDiffBody(two, one)}`;
|
|
1381
1675
|
}
|
|
1382
1676
|
//#endregion
|
|
1383
|
-
//#region src/results/diff-
|
|
1677
|
+
//#region src/results/diff-color.ts
|
|
1384
1678
|
/**
|
|
1385
|
-
* git's diff output (
|
|
1386
|
-
*
|
|
1387
|
-
*
|
|
1679
|
+
* git's colored diff output (diff.c's `emit_*` functions, ws.c's `ws_check_emit`) and its
|
|
1680
|
+
* moved-line detection (`--color-moved`: `add_lines_to_move_detection`,
|
|
1681
|
+
* `mark_color_as_moved`, `dim_moved_lines`), byte for byte as `git diff --color=always`
|
|
1682
|
+
* prints them.
|
|
1388
1683
|
*
|
|
1389
1684
|
* @example
|
|
1390
1685
|
* ```typescript
|
|
1391
|
-
* const
|
|
1392
|
-
* const patch = await formatPatch(pairs, {
|
|
1393
|
-
*
|
|
1686
|
+
* const colors = { ...DEFAULT_DIFF_COLORS, old: parseGitColor("magenta") ?? "" };
|
|
1687
|
+
* const patch = await formatPatch(pairs, { colors, colorMoved: "zebra" });
|
|
1688
|
+
* // "\x1b[1mdiff --git a/f b/f\x1b[m\n...\x1b[31m-old line\x1b[m\n..."
|
|
1394
1689
|
* ```
|
|
1395
1690
|
*
|
|
1396
|
-
*
|
|
1397
|
-
*
|
|
1398
|
-
*
|
|
1399
|
-
*
|
|
1400
|
-
*
|
|
1401
|
-
*
|
|
1402
|
-
*
|
|
1691
|
+
* The palette ({@link DiffColors}) holds the escape sequence of each of git's
|
|
1692
|
+
* `color.diff.<slot>` slots; an empty string is git's `normal` (nothing written before the
|
|
1693
|
+
* text, a reset still written after it). With a palette, every `+` line (`-` and context
|
|
1694
|
+
* lines too, with `--ws-error-highlight`) shows the whitespace errors of the path's
|
|
1695
|
+
* whitespace rule (`core.whitespace`, the `whitespace` attribute) in the `whitespace` color.
|
|
1696
|
+
* Moved lines are found over all the files of one diff: a writer buffers the lines in a
|
|
1697
|
+
* {@link MovedLineBuffer} and {@link MovedLineBuffer.flushTo} marks and prints them.
|
|
1403
1698
|
*
|
|
1404
1699
|
* @module
|
|
1405
1700
|
*/
|
|
1406
|
-
|
|
1407
|
-
const
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1701
|
+
/** git's color slots of the diff (`color.diff.<slot>`, diff.c's `color_diff_slots`) */
|
|
1702
|
+
const DIFF_COLOR_SLOTS = [
|
|
1703
|
+
"context",
|
|
1704
|
+
"meta",
|
|
1705
|
+
"frag",
|
|
1706
|
+
"old",
|
|
1707
|
+
"new",
|
|
1708
|
+
"commit",
|
|
1709
|
+
"whitespace",
|
|
1710
|
+
"func",
|
|
1711
|
+
"oldMoved",
|
|
1712
|
+
"oldMovedAlternative",
|
|
1713
|
+
"oldMovedDimmed",
|
|
1714
|
+
"oldMovedAlternativeDimmed",
|
|
1715
|
+
"newMoved",
|
|
1716
|
+
"newMovedAlternative",
|
|
1717
|
+
"newMovedDimmed",
|
|
1718
|
+
"newMovedAlternativeDimmed",
|
|
1719
|
+
"contextDimmed",
|
|
1720
|
+
"oldDimmed",
|
|
1721
|
+
"newDimmed",
|
|
1722
|
+
"contextBold",
|
|
1723
|
+
"oldBold",
|
|
1724
|
+
"newBold"
|
|
1725
|
+
];
|
|
1726
|
+
/** diff.c's `diff_colors`: git's default palette */
|
|
1727
|
+
const DEFAULT_DIFF_COLORS = Object.freeze({
|
|
1728
|
+
reset: "\x1B[m",
|
|
1729
|
+
context: "",
|
|
1730
|
+
meta: "\x1B[1m",
|
|
1731
|
+
frag: "\x1B[36m",
|
|
1732
|
+
old: "\x1B[31m",
|
|
1733
|
+
new: "\x1B[32m",
|
|
1734
|
+
commit: "\x1B[33m",
|
|
1735
|
+
whitespace: "\x1B[41m",
|
|
1736
|
+
func: "",
|
|
1737
|
+
oldMoved: "\x1B[1;35m",
|
|
1738
|
+
oldMovedAlternative: "\x1B[1;34m",
|
|
1739
|
+
oldMovedDimmed: "\x1B[2m",
|
|
1740
|
+
oldMovedAlternativeDimmed: "\x1B[2;3m",
|
|
1741
|
+
newMoved: "\x1B[1;36m",
|
|
1742
|
+
newMovedAlternative: "\x1B[1;33m",
|
|
1743
|
+
newMovedDimmed: "\x1B[2m",
|
|
1744
|
+
newMovedAlternativeDimmed: "\x1B[2;3m",
|
|
1745
|
+
contextDimmed: "\x1B[2m",
|
|
1746
|
+
oldDimmed: "\x1B[2;31m",
|
|
1747
|
+
newDimmed: "\x1B[2;32m",
|
|
1748
|
+
contextBold: "\x1B[1m",
|
|
1749
|
+
oldBold: "\x1B[1;31m",
|
|
1750
|
+
newBold: "\x1B[1;32m"
|
|
1751
|
+
});
|
|
1752
|
+
/** `parse_diff_color_slot`: the slot a `color.diff.<name>` names (any case), `plain` the context */
|
|
1753
|
+
function diffColorSlotOf(name) {
|
|
1754
|
+
const lower = name.toLowerCase();
|
|
1755
|
+
if (lower === "plain") return "context";
|
|
1756
|
+
return DIFF_COLOR_SLOTS.find((s) => s.toLowerCase() === lower);
|
|
1757
|
+
}
|
|
1412
1758
|
/**
|
|
1413
|
-
*
|
|
1414
|
-
*
|
|
1759
|
+
* `parse_color_moved`: a boolean (`true` is `zebra`), `no`, `plain`, `blocks`, `zebra`,
|
|
1760
|
+
* `default`, `dimmed-zebra` (or `dimmed_zebra`); undefined for anything else
|
|
1415
1761
|
*/
|
|
1416
|
-
function
|
|
1417
|
-
|
|
1418
|
-
if (
|
|
1419
|
-
if (
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1762
|
+
function parseColorMoved(arg) {
|
|
1763
|
+
const bool = maybeBool(arg);
|
|
1764
|
+
if (bool === false) return "no";
|
|
1765
|
+
if (bool === true) return "zebra";
|
|
1766
|
+
switch (arg) {
|
|
1767
|
+
case "no": return "no";
|
|
1768
|
+
case "plain":
|
|
1769
|
+
case "blocks":
|
|
1770
|
+
case "zebra": return arg;
|
|
1771
|
+
case "default": return "zebra";
|
|
1772
|
+
case "dimmed-zebra":
|
|
1773
|
+
case "dimmed_zebra": return "dimmed-zebra";
|
|
1774
|
+
default: return;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
/** git's `git_parse_maybe_bool` (no value is true) */
|
|
1778
|
+
function maybeBool(value) {
|
|
1779
|
+
if (value === void 0) return true;
|
|
1780
|
+
const v = value.toLowerCase();
|
|
1781
|
+
if (v === "" || v === "false" || v === "no" || v === "off") return false;
|
|
1782
|
+
if (v === "true" || v === "yes" || v === "on") return true;
|
|
1783
|
+
if (/^[-+]?\d+$/.test(v)) return Number(v) !== 0;
|
|
1784
|
+
}
|
|
1785
|
+
/** The message git gives a `--color-moved` mode it does not know */
|
|
1786
|
+
const COLOR_MOVED_MODE_ERROR = "error: color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed-zebra', 'plain'";
|
|
1787
|
+
/** `COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE` (the `XDF_*` whitespace bits are xdiff's) */
|
|
1788
|
+
const COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE = 32;
|
|
1789
|
+
const XDF_IGNORE_WHITESPACE$1 = 2;
|
|
1790
|
+
const XDF_IGNORE_WHITESPACE_CHANGE$1 = 4;
|
|
1791
|
+
const XDF_IGNORE_WHITESPACE_AT_EOL = 8;
|
|
1792
|
+
/**
|
|
1793
|
+
* `parse_color_moved_ws`: the comma-separated modes as flags, with git's `error:` lines
|
|
1794
|
+
* for the modes it refuses (the flags are not to be used then)
|
|
1795
|
+
*/
|
|
1796
|
+
function parseColorMovedWs(arg) {
|
|
1797
|
+
let flags = 0;
|
|
1798
|
+
const errors = [];
|
|
1799
|
+
for (const raw of arg.split(",")) {
|
|
1800
|
+
const item = raw.trim();
|
|
1801
|
+
if (item === "no") flags = 0;
|
|
1802
|
+
else if (item === "ignore-space-change") flags |= XDF_IGNORE_WHITESPACE_CHANGE$1;
|
|
1803
|
+
else if (item === "ignore-space-at-eol") flags |= XDF_IGNORE_WHITESPACE_AT_EOL;
|
|
1804
|
+
else if (item === "ignore-all-space") flags |= XDF_IGNORE_WHITESPACE$1;
|
|
1805
|
+
else if (item === "allow-indentation-change") flags |= 32;
|
|
1806
|
+
else errors.push(`error: unknown color-moved-ws mode '${item}', possible values are 'ignore-space-change', 'ignore-space-at-eol', 'ignore-all-space', 'allow-indentation-change'`);
|
|
1807
|
+
}
|
|
1808
|
+
if (flags & 32 && flags & XDF_WHITESPACE_FLAGS) errors.push("error: color-moved-ws: allow-indentation-change cannot be combined with other whitespace modes");
|
|
1427
1809
|
return {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
...algorithm ? { algorithm } : {},
|
|
1431
|
-
...findFunction ? { findFunction } : {},
|
|
1432
|
-
...textconvCommand !== void 0 ? { textconvCommand } : {},
|
|
1433
|
-
...cacheTextconv !== void 0 ? { cacheTextconv } : {}
|
|
1810
|
+
flags,
|
|
1811
|
+
errors
|
|
1434
1812
|
};
|
|
1435
1813
|
}
|
|
1436
|
-
/**
|
|
1437
|
-
const
|
|
1438
|
-
/**
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1814
|
+
/** `WSEH_NEW`: whitespace errors highlighted on `+` lines */
|
|
1815
|
+
const WSEH_NEW = 65536;
|
|
1816
|
+
/** `WSEH_CONTEXT`: on context lines */
|
|
1817
|
+
const WSEH_CONTEXT = 1 << 17;
|
|
1818
|
+
/** `WSEH_OLD`: on `-` lines */
|
|
1819
|
+
const WSEH_OLD = 1 << 18;
|
|
1820
|
+
/**
|
|
1821
|
+
* `parse_ws_error_highlight`: `none`, `default`, `all`, `new`, `old`, `context`, comma
|
|
1822
|
+
* separated; undefined for anything else
|
|
1823
|
+
*/
|
|
1824
|
+
function parseWsErrorHighlight(arg) {
|
|
1825
|
+
const r = wsErrorHighlightOf(arg);
|
|
1826
|
+
return typeof r === "number" ? r : void 0;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* {@link parseWsErrorHighlight}, or for a value git refuses the text before the token it
|
|
1830
|
+
* stopped at (what its error message quotes)
|
|
1831
|
+
*/
|
|
1832
|
+
function wsErrorHighlightOf(arg) {
|
|
1833
|
+
let val = 0;
|
|
1834
|
+
let at = 0;
|
|
1835
|
+
const tokens = [
|
|
1836
|
+
["none", () => 0],
|
|
1837
|
+
["default", () => WSEH_NEW],
|
|
1838
|
+
["all", () => 458752],
|
|
1839
|
+
["new", (v) => v | WSEH_NEW],
|
|
1840
|
+
["old", (v) => v | WSEH_OLD],
|
|
1841
|
+
["context", (v) => v | WSEH_CONTEXT]
|
|
1842
|
+
];
|
|
1843
|
+
while (at < arg.length) {
|
|
1844
|
+
const found = tokens.find(([t]) => arg.startsWith(t, at) && (at + t.length === arg.length || arg[at + t.length] === ","));
|
|
1845
|
+
if (!found) return { badPrefix: arg.slice(0, at) };
|
|
1846
|
+
val = found[1](val);
|
|
1847
|
+
at += found[0].length;
|
|
1848
|
+
if (at < arg.length) at++;
|
|
1450
1849
|
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1850
|
+
return val;
|
|
1851
|
+
}
|
|
1852
|
+
const BLANK_LINE_EOF = 1 << 19;
|
|
1853
|
+
const MOVED_LINE = 1 << 20;
|
|
1854
|
+
const MOVED_LINE_ALT = 1 << 21;
|
|
1855
|
+
const MOVED_LINE_UNINTERESTING = 1 << 22;
|
|
1856
|
+
const ZEBRA_MASK = 3145728;
|
|
1857
|
+
const CONTENT_WS_MASK = 524287;
|
|
1858
|
+
/** `COLOR_MOVED_MIN_ALNUM_COUNT` */
|
|
1859
|
+
const MIN_ALNUM_COUNT = 20;
|
|
1860
|
+
/** git's `isalnum` (ASCII) */
|
|
1861
|
+
const isAlnum = (c) => c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
1862
|
+
/** Bytes written as the colored output is built */
|
|
1863
|
+
var Out = class {
|
|
1864
|
+
parts = [];
|
|
1865
|
+
size = 0;
|
|
1866
|
+
str(s) {
|
|
1867
|
+
if (s.length === 0) return;
|
|
1868
|
+
this.bytes(encodeGitPath(s));
|
|
1453
1869
|
}
|
|
1454
|
-
|
|
1455
|
-
|
|
1870
|
+
bytes(b) {
|
|
1871
|
+
if (b.length === 0) return;
|
|
1872
|
+
this.parts.push(b);
|
|
1873
|
+
this.size += b.length;
|
|
1456
1874
|
}
|
|
1457
|
-
|
|
1458
|
-
this.
|
|
1459
|
-
return this.content;
|
|
1875
|
+
byte(c) {
|
|
1876
|
+
this.bytes(Uint8Array.of(c));
|
|
1460
1877
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1878
|
+
done() {
|
|
1879
|
+
const out = new Uint8Array(this.size);
|
|
1880
|
+
let at = 0;
|
|
1881
|
+
for (const p of this.parts) {
|
|
1882
|
+
out.set(p, at);
|
|
1883
|
+
at += p.length;
|
|
1884
|
+
}
|
|
1885
|
+
return out;
|
|
1464
1886
|
}
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1887
|
+
};
|
|
1888
|
+
/**
|
|
1889
|
+
* diff.c's `emit_line_0` (no line prefix): `setSign` before the sign, `set` before the
|
|
1890
|
+
* text, the reset after them, the CR and LF of the line after the reset
|
|
1891
|
+
*/
|
|
1892
|
+
function emitLine0(out, setSign, set, reset, first, line) {
|
|
1893
|
+
let len = line.length;
|
|
1894
|
+
let needsReset = false;
|
|
1895
|
+
const hasNewline = len > 0 && line[len - 1] === 10;
|
|
1896
|
+
if (hasNewline) len--;
|
|
1897
|
+
const hasCr = len > 0 && line[len - 1] === 13;
|
|
1898
|
+
if (hasCr) len--;
|
|
1899
|
+
if (len > 0 || first) {
|
|
1900
|
+
if (setSign !== void 0) {
|
|
1901
|
+
out.str(setSign);
|
|
1902
|
+
needsReset = true;
|
|
1903
|
+
}
|
|
1904
|
+
if (first) out.byte(first);
|
|
1905
|
+
if (len > 0) {
|
|
1906
|
+
if (set !== void 0) {
|
|
1907
|
+
out.str(set);
|
|
1908
|
+
needsReset = true;
|
|
1909
|
+
}
|
|
1910
|
+
out.bytes(line.subarray(0, len));
|
|
1911
|
+
needsReset = true;
|
|
1912
|
+
}
|
|
1470
1913
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1914
|
+
if (needsReset) out.str(reset);
|
|
1915
|
+
if (hasCr) out.byte(13);
|
|
1916
|
+
if (hasNewline) out.byte(10);
|
|
1917
|
+
}
|
|
1918
|
+
/** diff.c's `emit_line_ws_markup` */
|
|
1919
|
+
function emitLineWsMarkup(out, o, set, sign, line, wsRule, blankAtEof) {
|
|
1920
|
+
const { reset } = o.colors;
|
|
1921
|
+
let ws;
|
|
1922
|
+
if (o.wsErrorHighlight & wsRule) {
|
|
1923
|
+
ws = o.colors.whitespace;
|
|
1924
|
+
if (!ws) ws = void 0;
|
|
1481
1925
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1926
|
+
if (ws === void 0) emitLine0(out, set, void 0, reset, sign, line);
|
|
1927
|
+
else if (blankAtEof) emitLine0(out, ws, void 0, reset, sign, line);
|
|
1928
|
+
else {
|
|
1929
|
+
emitLine0(out, set, void 0, reset, sign, /* @__PURE__ */ new Uint8Array(0));
|
|
1930
|
+
wsCheckEmit(line, wsRule, out, set, reset, ws);
|
|
1485
1931
|
}
|
|
1486
|
-
}
|
|
1932
|
+
}
|
|
1933
|
+
/** diff.c's `DIFF_SYMBOL_PLUS` and `DIFF_SYMBOL_MINUS` */
|
|
1934
|
+
function renderContent(out, o, s) {
|
|
1935
|
+
const c = o.colors;
|
|
1936
|
+
const moved = s.flags & 7340032;
|
|
1937
|
+
const plus = s.kind === "+";
|
|
1938
|
+
let set;
|
|
1939
|
+
switch (moved) {
|
|
1940
|
+
case 7340032:
|
|
1941
|
+
set = plus ? c.newMovedAlternativeDimmed : c.oldMovedAlternativeDimmed;
|
|
1942
|
+
break;
|
|
1943
|
+
case 3145728:
|
|
1944
|
+
set = plus ? c.newMovedAlternative : c.oldMovedAlternative;
|
|
1945
|
+
break;
|
|
1946
|
+
case 5242880:
|
|
1947
|
+
set = plus ? c.newMovedDimmed : c.oldMovedDimmed;
|
|
1948
|
+
break;
|
|
1949
|
+
case MOVED_LINE:
|
|
1950
|
+
set = plus ? c.newMoved : c.oldMoved;
|
|
1951
|
+
break;
|
|
1952
|
+
default: set = plus ? c.new : c.old;
|
|
1953
|
+
}
|
|
1954
|
+
emitLineWsMarkup(out, o, set, plus ? 43 : 45, s.line, s.flags & CONTENT_WS_MASK, plus && (s.flags & BLANK_LINE_EOF) !== 0);
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* The output of one diff's patches while moved lines are looked for: what the writers push
|
|
1958
|
+
* is kept, `+` and `-` lines apart ({@link MovedLineBuffer.content}), until
|
|
1959
|
+
* {@link MovedLineBuffer.flushTo} marks the moved lines and prints everything.
|
|
1960
|
+
*/
|
|
1961
|
+
var MovedLineBuffer = class extends ByteSink {
|
|
1962
|
+
mode;
|
|
1963
|
+
wsFlags;
|
|
1964
|
+
symbols = [];
|
|
1965
|
+
buffered = 0;
|
|
1966
|
+
constructor(mode, wsFlags) {
|
|
1967
|
+
super();
|
|
1968
|
+
this.mode = mode;
|
|
1969
|
+
this.wsFlags = wsFlags;
|
|
1970
|
+
}
|
|
1971
|
+
push(bytes) {
|
|
1972
|
+
if (bytes.length === 0) return;
|
|
1973
|
+
this.symbols.push({
|
|
1974
|
+
kind: "raw",
|
|
1975
|
+
bytes
|
|
1976
|
+
});
|
|
1977
|
+
this.buffered += bytes.length;
|
|
1978
|
+
}
|
|
1979
|
+
get length() {
|
|
1980
|
+
return this.buffered;
|
|
1981
|
+
}
|
|
1982
|
+
bytes() {
|
|
1983
|
+
throw new Error("MovedLineBuffer: flushTo() prints the buffered output");
|
|
1984
|
+
}
|
|
1985
|
+
/** A `+` or `-` line (the line without its sign, LF included) and its flags */
|
|
1986
|
+
content(kind, line, flags) {
|
|
1987
|
+
this.symbols.push({
|
|
1988
|
+
kind,
|
|
1989
|
+
line,
|
|
1990
|
+
flags,
|
|
1991
|
+
id: 0,
|
|
1992
|
+
indentOff: 0,
|
|
1993
|
+
indentWidth: 0
|
|
1994
|
+
});
|
|
1995
|
+
this.buffered += line.length + 1;
|
|
1996
|
+
}
|
|
1997
|
+
/** diff_flush_patch_all_file_pairs' end: marks the moved lines and prints everything */
|
|
1998
|
+
flushTo(sink, o) {
|
|
1999
|
+
const list = addLinesToMoveDetection(this.symbols, this.wsFlags);
|
|
2000
|
+
markColorAsMoved(this.symbols, list, this.mode, this.wsFlags);
|
|
2001
|
+
if (this.mode === "dimmed-zebra") dimMovedLines(this.symbols);
|
|
2002
|
+
for (const s of this.symbols) if (s.kind === "raw") sink.push(s.bytes);
|
|
2003
|
+
else {
|
|
2004
|
+
const out = new Out();
|
|
2005
|
+
renderContent(out, o, s);
|
|
2006
|
+
sink.push(out.done());
|
|
2007
|
+
}
|
|
2008
|
+
this.symbols.length = 0;
|
|
2009
|
+
this.buffered = 0;
|
|
2010
|
+
}
|
|
2011
|
+
};
|
|
2012
|
+
const INDENT_BLANKLINE = -2147483648;
|
|
2013
|
+
/** `fill_es_indent_data` */
|
|
2014
|
+
function fillIndentData(s) {
|
|
2015
|
+
const line = s.line;
|
|
2016
|
+
const len = line.length;
|
|
2017
|
+
const tabWidth = s.flags & 63;
|
|
2018
|
+
let off = 0;
|
|
2019
|
+
let width = 0;
|
|
2020
|
+
while (off < len && (line[off] === 12 || line[off] === 11 || off < len - 1 && line[off] === 13)) off++;
|
|
2021
|
+
for (;;) if (line[off] === 32) {
|
|
2022
|
+
width++;
|
|
2023
|
+
off++;
|
|
2024
|
+
} else if (line[off] === 9) {
|
|
2025
|
+
width += tabWidth - width % tabWidth;
|
|
2026
|
+
while (line[++off] === 9) width += tabWidth;
|
|
2027
|
+
} else break;
|
|
2028
|
+
let i = off;
|
|
2029
|
+
for (; i < len; i++) if (!isGitSpace(line[i])) break;
|
|
2030
|
+
if (i === len) {
|
|
2031
|
+
s.indentWidth = INDENT_BLANKLINE;
|
|
2032
|
+
s.indentOff = len;
|
|
2033
|
+
} else {
|
|
2034
|
+
s.indentOff = off;
|
|
2035
|
+
s.indentWidth = width;
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
/** `add_lines_to_move_detection`: each `+`/`-` line's id, and the lines of each id */
|
|
2039
|
+
function addLinesToMoveDetection(symbols, wsFlags) {
|
|
2040
|
+
const flags = wsFlags & XDF_WHITESPACE_FLAGS;
|
|
2041
|
+
const interned = /* @__PURE__ */ new Map();
|
|
2042
|
+
const list = [];
|
|
2043
|
+
let prev;
|
|
2044
|
+
for (const l of symbols) {
|
|
2045
|
+
if (l.kind === "raw") {
|
|
2046
|
+
prev = void 0;
|
|
2047
|
+
continue;
|
|
2048
|
+
}
|
|
2049
|
+
if (wsFlags & 32) fillIndentData(l);
|
|
2050
|
+
const hash = xdlHashRecord(l.line, l.indentOff, l.line.length, flags);
|
|
2051
|
+
let bucket = interned.get(hash);
|
|
2052
|
+
if (!bucket) {
|
|
2053
|
+
bucket = [];
|
|
2054
|
+
interned.set(hash, bucket);
|
|
2055
|
+
}
|
|
2056
|
+
const same = bucket.find((s) => xdlRecmatch(s.line, s.indentOff, s.line.length, l.line, l.indentOff, l.line.length, flags));
|
|
2057
|
+
if (same) l.id = same.id;
|
|
2058
|
+
else {
|
|
2059
|
+
l.id = list.length;
|
|
2060
|
+
list.push({});
|
|
2061
|
+
bucket.push(l);
|
|
2062
|
+
}
|
|
2063
|
+
const entry = { es: l };
|
|
2064
|
+
if (prev && prev.es.kind === l.kind) prev.nextLine = entry;
|
|
2065
|
+
prev = entry;
|
|
2066
|
+
const slot = list[l.id];
|
|
2067
|
+
if (l.kind === "+") {
|
|
2068
|
+
entry.nextMatch = slot.add;
|
|
2069
|
+
slot.add = entry;
|
|
2070
|
+
} else {
|
|
2071
|
+
entry.nextMatch = slot.del;
|
|
2072
|
+
slot.del = entry;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
return list;
|
|
2076
|
+
}
|
|
2077
|
+
/** `cmp_in_block_with_wsd`: whether `l` does not continue the block (true: no match) */
|
|
2078
|
+
function cmpInBlockWithWsd(cur, l, pmb) {
|
|
2079
|
+
if (cur.es.id !== l.id) return true;
|
|
2080
|
+
const aWidth = cur.es.indentWidth;
|
|
2081
|
+
if (aWidth === INDENT_BLANKLINE) return false;
|
|
2082
|
+
const delta = l.indentWidth - aWidth;
|
|
2083
|
+
if (pmb.wsd === INDENT_BLANKLINE) pmb.wsd = delta;
|
|
2084
|
+
return delta !== pmb.wsd;
|
|
2085
|
+
}
|
|
2086
|
+
/** `compute_ws_delta` */
|
|
2087
|
+
function computeWsDelta(a, b) {
|
|
2088
|
+
if (a.indentWidth === INDENT_BLANKLINE && b.indentWidth === INDENT_BLANKLINE) return INDENT_BLANKLINE;
|
|
2089
|
+
return a.indentWidth - b.indentWidth;
|
|
2090
|
+
}
|
|
2091
|
+
/** `mark_color_as_moved` */
|
|
2092
|
+
function markColorAsMoved(symbols, list, mode, wsFlags) {
|
|
2093
|
+
const allowIndent = (wsFlags & 32) !== 0;
|
|
2094
|
+
let pmb = [];
|
|
2095
|
+
let flippedBlock = 0;
|
|
2096
|
+
let blockLength = 0;
|
|
2097
|
+
let movedSymbol;
|
|
2098
|
+
/** `adjust_last_block`: unmarks a block of too few alphanumerics; whether it stays */
|
|
2099
|
+
const adjustLastBlock = (n, length) => {
|
|
2100
|
+
if (mode === "plain") return length !== 0;
|
|
2101
|
+
let alnum = 0;
|
|
2102
|
+
for (let i = 1; i < length + 1; i++) {
|
|
2103
|
+
const s = symbols[n - i];
|
|
2104
|
+
const line = s.kind === "raw" ? s.bytes : s.line;
|
|
2105
|
+
for (let k = 0; k < line.length && line[k] !== 0; k++) {
|
|
2106
|
+
if (!isAlnum(line[k])) continue;
|
|
2107
|
+
alnum++;
|
|
2108
|
+
if (alnum >= MIN_ALNUM_COUNT) return true;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
for (let i = 1; i < length + 1; i++) {
|
|
2112
|
+
const s = symbols[n - i];
|
|
2113
|
+
if (s.kind !== "raw") s.flags &= -3145729;
|
|
2114
|
+
}
|
|
2115
|
+
return false;
|
|
2116
|
+
};
|
|
2117
|
+
let n = 0;
|
|
2118
|
+
for (; n < symbols.length; n++) {
|
|
2119
|
+
const l = symbols[n];
|
|
2120
|
+
let match;
|
|
2121
|
+
if (l.kind === "+") match = list[l.id]?.del;
|
|
2122
|
+
else if (l.kind === "-") match = list[l.id]?.add;
|
|
2123
|
+
else flippedBlock = 0;
|
|
2124
|
+
if (pmb.length > 0 && (!match || l.kind !== movedSymbol)) {
|
|
2125
|
+
if (!adjustLastBlock(n, blockLength) && blockLength > 1) {
|
|
2126
|
+
match = void 0;
|
|
2127
|
+
n -= blockLength;
|
|
2128
|
+
}
|
|
2129
|
+
pmb = [];
|
|
2130
|
+
blockLength = 0;
|
|
2131
|
+
flippedBlock = 0;
|
|
2132
|
+
}
|
|
2133
|
+
if (!match || l.kind === "raw") {
|
|
2134
|
+
movedSymbol = void 0;
|
|
2135
|
+
continue;
|
|
2136
|
+
}
|
|
2137
|
+
if (mode === "plain") {
|
|
2138
|
+
l.flags |= MOVED_LINE;
|
|
2139
|
+
continue;
|
|
2140
|
+
}
|
|
2141
|
+
const kept = [];
|
|
2142
|
+
for (const block of pmb) {
|
|
2143
|
+
const cur = block.match?.nextLine;
|
|
2144
|
+
if (allowIndent ? cur !== void 0 && !cmpInBlockWithWsd(cur, l, block) : cur !== void 0 && cur.es.id === l.id) {
|
|
2145
|
+
block.match = cur;
|
|
2146
|
+
kept.push(block);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
pmb = kept;
|
|
2150
|
+
if (pmb.length === 0) {
|
|
2151
|
+
const contiguous = adjustLastBlock(n, blockLength);
|
|
2152
|
+
if (!contiguous && blockLength > 1) n -= blockLength;
|
|
2153
|
+
else for (let m = match; m; m = m.nextMatch) pmb.push({
|
|
2154
|
+
match: m,
|
|
2155
|
+
wsd: allowIndent ? computeWsDelta(l, m.es) : 0
|
|
2156
|
+
});
|
|
2157
|
+
if (contiguous && pmb.length > 0 && movedSymbol === l.kind) flippedBlock = (flippedBlock + 1) % 2;
|
|
2158
|
+
else flippedBlock = 0;
|
|
2159
|
+
movedSymbol = pmb.length > 0 ? l.kind : void 0;
|
|
2160
|
+
blockLength = 0;
|
|
2161
|
+
}
|
|
2162
|
+
if (pmb.length > 0) {
|
|
2163
|
+
blockLength++;
|
|
2164
|
+
l.flags |= MOVED_LINE;
|
|
2165
|
+
if (flippedBlock && mode !== "blocks") l.flags |= MOVED_LINE_ALT;
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
adjustLastBlock(n, blockLength);
|
|
2169
|
+
}
|
|
2170
|
+
/** `dim_moved_lines` */
|
|
2171
|
+
function dimMovedLines(symbols) {
|
|
2172
|
+
for (let n = 0; n < symbols.length; n++) {
|
|
2173
|
+
const l = symbols[n];
|
|
2174
|
+
if (l.kind === "raw") continue;
|
|
2175
|
+
if (!(l.flags & MOVED_LINE)) continue;
|
|
2176
|
+
let prev = n > 0 ? symbols[n - 1] : void 0;
|
|
2177
|
+
let next = n < symbols.length - 1 ? symbols[n + 1] : void 0;
|
|
2178
|
+
if (prev && prev.kind === "raw") prev = void 0;
|
|
2179
|
+
if (next && next.kind === "raw") next = void 0;
|
|
2180
|
+
const p = prev;
|
|
2181
|
+
const x = next;
|
|
2182
|
+
if (p && (p.flags & ZEBRA_MASK) === (l.flags & ZEBRA_MASK) && x && (x.flags & ZEBRA_MASK) === (l.flags & ZEBRA_MASK)) {
|
|
2183
|
+
l.flags |= MOVED_LINE_UNINTERESTING;
|
|
2184
|
+
continue;
|
|
2185
|
+
}
|
|
2186
|
+
if (p && p.flags & MOVED_LINE && (p.flags & MOVED_LINE_ALT) !== (l.flags & MOVED_LINE_ALT)) continue;
|
|
2187
|
+
if (x && x.flags & MOVED_LINE && (x.flags & MOVED_LINE_ALT) !== (l.flags & MOVED_LINE_ALT)) continue;
|
|
2188
|
+
l.flags |= MOVED_LINE_UNINTERESTING;
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
/**
|
|
2192
|
+
* The hunks of a text pair as diff.c's `fn_out_consume` prints them in color: the header
|
|
2193
|
+
* in `frag` (`func` for its function line), each line in its color with its whitespace
|
|
2194
|
+
* errors marked; into a {@link MovedLineBuffer}, the `+` and `-` lines are kept for move
|
|
2195
|
+
* detection.
|
|
2196
|
+
*/
|
|
2197
|
+
function writeColoredHunks(sink, hunks, ctx) {
|
|
2198
|
+
const c = ctx.colors;
|
|
2199
|
+
const reset = c.reset;
|
|
2200
|
+
const buffer = sink instanceof MovedLineBuffer ? sink : void 0;
|
|
2201
|
+
let blankPre = 0;
|
|
2202
|
+
let blankPost = 0;
|
|
2203
|
+
if (ctx.wsRule & 1024) {
|
|
2204
|
+
const at = checkBlankAtEof(ctx.oldContent, ctx.newContent);
|
|
2205
|
+
blankPre = at.preimage;
|
|
2206
|
+
blankPost = at.postimage;
|
|
2207
|
+
}
|
|
2208
|
+
const emit = (out) => sink.push(out.done());
|
|
2209
|
+
for (const hunk of hunks) {
|
|
2210
|
+
emit(hunkHeader(hunk.header, c));
|
|
2211
|
+
let lnoPre = hunk.oldStart;
|
|
2212
|
+
let lnoPost = hunk.newStart;
|
|
2213
|
+
let lastKind = "";
|
|
2214
|
+
for (const line of hunk.lines) {
|
|
2215
|
+
const complete = line.bytes.length > 0 && line.bytes[line.bytes.length - 1] === 10;
|
|
2216
|
+
const text = complete ? line.bytes : withNewline$2(line.bytes);
|
|
2217
|
+
if (line.kind === "+") {
|
|
2218
|
+
lnoPost++;
|
|
2219
|
+
let flags = WSEH_NEW | ctx.wsRule;
|
|
2220
|
+
if (ctx.wsRule & 1024 && blankPre && blankPost && blankPre <= lnoPre && blankPost <= lnoPost && wsBlankLine(text, 0, text.length)) flags |= BLANK_LINE_EOF;
|
|
2221
|
+
if (buffer) buffer.content("+", text, flags);
|
|
2222
|
+
else {
|
|
2223
|
+
const out = new Out();
|
|
2224
|
+
renderContent(out, ctx, {
|
|
2225
|
+
kind: "+",
|
|
2226
|
+
line: text,
|
|
2227
|
+
flags,
|
|
2228
|
+
id: 0,
|
|
2229
|
+
indentOff: 0,
|
|
2230
|
+
indentWidth: 0
|
|
2231
|
+
});
|
|
2232
|
+
emit(out);
|
|
2233
|
+
}
|
|
2234
|
+
} else if (line.kind === "-") {
|
|
2235
|
+
lnoPre++;
|
|
2236
|
+
const flags = WSEH_OLD | ctx.wsRule;
|
|
2237
|
+
if (buffer) buffer.content("-", text, flags);
|
|
2238
|
+
else {
|
|
2239
|
+
const out = new Out();
|
|
2240
|
+
renderContent(out, ctx, {
|
|
2241
|
+
kind: "-",
|
|
2242
|
+
line: text,
|
|
2243
|
+
flags,
|
|
2244
|
+
id: 0,
|
|
2245
|
+
indentOff: 0,
|
|
2246
|
+
indentWidth: 0
|
|
2247
|
+
});
|
|
2248
|
+
emit(out);
|
|
2249
|
+
}
|
|
2250
|
+
} else {
|
|
2251
|
+
lnoPre++;
|
|
2252
|
+
lnoPost++;
|
|
2253
|
+
const out = new Out();
|
|
2254
|
+
emitLineWsMarkup(out, ctx, c.context, 32, text, (WSEH_CONTEXT | ctx.wsRule) & CONTENT_WS_MASK, false);
|
|
2255
|
+
emit(out);
|
|
2256
|
+
}
|
|
2257
|
+
lastKind = line.kind;
|
|
2258
|
+
if (!complete && line.bytes.length > 0) {
|
|
2259
|
+
lnoPre++;
|
|
2260
|
+
const flags = (lastKind === "+" ? WSEH_NEW : lastKind === "-" ? WSEH_OLD : WSEH_CONTEXT) | ctx.wsRule;
|
|
2261
|
+
const set = flags & 4096 && flags & ctx.wsErrorHighlight ? c.whitespace : c.context;
|
|
2262
|
+
const out = new Out();
|
|
2263
|
+
emitLine0(out, set, void 0, reset, 0, NO_NEWLINE);
|
|
2264
|
+
emit(out);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
const NO_NEWLINE = encodeGitPath("\\n");
|
|
2270
|
+
function withNewline$2(bytes) {
|
|
2271
|
+
const out = new Uint8Array(bytes.length + 1);
|
|
2272
|
+
out.set(bytes);
|
|
2273
|
+
out[bytes.length] = 10;
|
|
2274
|
+
return out;
|
|
2275
|
+
}
|
|
2276
|
+
/** diff.c's `emit_hunk_header` (the header as xdiff made it, LF included) */
|
|
2277
|
+
function hunkHeader(line, c) {
|
|
2278
|
+
const out = new Out();
|
|
2279
|
+
const orgLen = line.length;
|
|
2280
|
+
let len = orgLen;
|
|
2281
|
+
let ep = -1;
|
|
2282
|
+
for (let i = 2; i + 1 < len; i++) if (line[i] === 64 && line[i + 1] === 64) {
|
|
2283
|
+
ep = i;
|
|
2284
|
+
break;
|
|
2285
|
+
}
|
|
2286
|
+
if (len < 10 || line[0] !== 64 || line[1] !== 64 || ep < 0) {
|
|
2287
|
+
emitLine0(out, c.context, void 0, c.reset, 0, line);
|
|
2288
|
+
return out;
|
|
2289
|
+
}
|
|
2290
|
+
ep += 2;
|
|
2291
|
+
out.str(c.frag);
|
|
2292
|
+
out.bytes(line.subarray(0, ep));
|
|
2293
|
+
out.str(c.reset);
|
|
2294
|
+
for (let i = 1; i < 3; i++) {
|
|
2295
|
+
const ch = line[len - i];
|
|
2296
|
+
if (ch === 13 || ch === 10) len--;
|
|
2297
|
+
}
|
|
2298
|
+
const cp = ep;
|
|
2299
|
+
while (ep < len && (line[ep] === 32 || line[ep] === 9)) ep++;
|
|
2300
|
+
if (ep !== cp) {
|
|
2301
|
+
out.str(c.context);
|
|
2302
|
+
out.bytes(line.subarray(cp, ep));
|
|
2303
|
+
out.str(c.reset);
|
|
2304
|
+
}
|
|
2305
|
+
if (ep < len) {
|
|
2306
|
+
out.str(c.func);
|
|
2307
|
+
out.bytes(line.subarray(ep, len));
|
|
2308
|
+
out.str(c.reset);
|
|
2309
|
+
}
|
|
2310
|
+
out.bytes(line.subarray(len, orgLen));
|
|
2311
|
+
if (orgLen === len || line[orgLen - 1] !== 10) out.byte(10);
|
|
2312
|
+
return out;
|
|
2313
|
+
}
|
|
2314
|
+
/**
|
|
2315
|
+
* diff.c's `emit_hunk_header` in color: the `@@ ... @@` part in `frag`, the function line in
|
|
2316
|
+
* `func` (the header as xdiff made it, LF included)
|
|
2317
|
+
*/
|
|
2318
|
+
function coloredHunkHeader(line, c) {
|
|
2319
|
+
return hunkHeader(line, c).done();
|
|
2320
|
+
}
|
|
2321
|
+
//#endregion
|
|
2322
|
+
//#region src/results/diff-words.ts
|
|
2323
|
+
/**
|
|
2324
|
+
* git's word diff (diff.c's `diff_words_*` and `fn_out_diff_words_*`): `--word-diff=plain`,
|
|
2325
|
+
* `--word-diff=color` (`--color-words`) and `--word-diff=porcelain`, byte for byte as git
|
|
2326
|
+
* prints the hunks of a text pair.
|
|
2327
|
+
*
|
|
2328
|
+
* @example
|
|
2329
|
+
* ```typescript
|
|
2330
|
+
* const words = compileWordRegex("[a-z]+");
|
|
2331
|
+
* writeWordDiffHunks(sink, hunks, { mode: "plain", regex: words });
|
|
2332
|
+
* // "@@ -1 +1 @@\nh(4),{+hh+}[44]\n"
|
|
2333
|
+
* ```
|
|
2334
|
+
*
|
|
2335
|
+
* The removed and added lines between two context lines are gathered, split into words
|
|
2336
|
+
* (each match of the word regex, cut at a newline; without one, each run of non-spaces),
|
|
2337
|
+
* and the two word lists are diffed as lines (xdiff with no context, the common tail
|
|
2338
|
+
* trimmed). The added side's text is printed with the removed words before the added ones
|
|
2339
|
+
* that replace them: `[-old-]{+new+}` in plain mode, the `old` and `new` colors in color
|
|
2340
|
+
* mode, one `-`/`+`/` ` line per piece with `~` for each newline in porcelain mode. Context
|
|
2341
|
+
* lines are printed without their sign (porcelain: with it, followed by `~`).
|
|
2342
|
+
*
|
|
2343
|
+
* Not reproduced: under `log --graph` git writes the graph's line prefix in word mode only
|
|
2344
|
+
* where a word hunk starts on a new line or a piece's text has a newline, so porcelain lines
|
|
2345
|
+
* (and some plain or color lines) go without it; `git log` prefixes every line of ours.
|
|
2346
|
+
*
|
|
2347
|
+
* @module
|
|
2348
|
+
*/
|
|
2349
|
+
/** The modes `--word-diff=` takes (`none` turns the word diff off) */
|
|
2350
|
+
const WORD_DIFF_MODES = [
|
|
2351
|
+
"plain",
|
|
2352
|
+
"color",
|
|
2353
|
+
"porcelain",
|
|
2354
|
+
"none"
|
|
2355
|
+
];
|
|
2356
|
+
const enc = (s) => encodeGitPath(s);
|
|
2357
|
+
/** diff.c's `diff_words_styles` */
|
|
2358
|
+
function styleOf(mode, colors) {
|
|
2359
|
+
const elem = (prefix, suffix, color) => ({
|
|
2360
|
+
prefix: enc(prefix),
|
|
2361
|
+
suffix: enc(suffix),
|
|
2362
|
+
color
|
|
2363
|
+
});
|
|
2364
|
+
const c = colors;
|
|
2365
|
+
switch (mode) {
|
|
2366
|
+
case "porcelain": return {
|
|
2367
|
+
newWord: elem("+", "\n", c?.new),
|
|
2368
|
+
oldWord: elem("-", "\n", c?.old),
|
|
2369
|
+
ctx: elem(" ", "\n", c?.context),
|
|
2370
|
+
newline: enc("~\n")
|
|
2371
|
+
};
|
|
2372
|
+
case "plain": return {
|
|
2373
|
+
newWord: elem("{+", "+}", c?.new),
|
|
2374
|
+
oldWord: elem("[-", "-]", c?.old),
|
|
2375
|
+
ctx: elem("", "", c?.context),
|
|
2376
|
+
newline: enc("\n")
|
|
2377
|
+
};
|
|
2378
|
+
default: return {
|
|
2379
|
+
newWord: elem("", "", c?.new),
|
|
2380
|
+
oldWord: elem("", "", c?.old),
|
|
2381
|
+
ctx: elem("", "", c?.context),
|
|
2382
|
+
newline: enc("\n")
|
|
2383
|
+
};
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
/** `GIT_COLOR_RESET`, which ends a colored word whatever `DiffColors.reset` says */
|
|
2387
|
+
const GIT_COLOR_RESET = enc("\x1B[m");
|
|
2388
|
+
const TILDE_LINE = enc("~\n");
|
|
2389
|
+
const NEWLINE = 10;
|
|
2390
|
+
/** git's `isspace` (space, TAB, LF, CR) */
|
|
2391
|
+
const isSpace = (c) => c === 32 || c === 9 || c === 10 || c === 13;
|
|
2392
|
+
/** Compiled word regexes by pattern: a log compiles each once */
|
|
2393
|
+
const compiled = /* @__PURE__ */ new Map();
|
|
2394
|
+
/**
|
|
2395
|
+
* The word regex as `init_diff_words_data` compiles it (`REG_EXTENDED | REG_NEWLINE`).
|
|
2396
|
+
*
|
|
2397
|
+
* @throws GitApiError git's `fatal: invalid regular expression: <regex>` (exit 128)
|
|
2398
|
+
*/
|
|
2399
|
+
function compileWordRegex(pattern) {
|
|
2400
|
+
const key = typeof pattern === "string" ? `s${pattern}` : `b${Array.from(pattern).join(",")}`;
|
|
2401
|
+
let re = compiled.get(key);
|
|
2402
|
+
if (!re) {
|
|
2403
|
+
try {
|
|
2404
|
+
re = compilePosixRegex(pattern, {
|
|
2405
|
+
extended: true,
|
|
2406
|
+
newline: true
|
|
2407
|
+
});
|
|
2408
|
+
} catch {
|
|
2409
|
+
const text = typeof pattern === "string" ? pattern : new TextDecoder("latin1").decode(pattern);
|
|
2410
|
+
throw new GitApiError(`fatal: invalid regular expression: ${text}`);
|
|
2411
|
+
}
|
|
2412
|
+
if (compiled.size >= 64) compiled.clear();
|
|
2413
|
+
compiled.set(key, re);
|
|
2414
|
+
}
|
|
2415
|
+
return re;
|
|
2416
|
+
}
|
|
2417
|
+
/** The bytes of one word diff, gathered as git's `strbuf` and printed per symbol */
|
|
2418
|
+
var Pieces = class {
|
|
2419
|
+
parts = [];
|
|
2420
|
+
bytes(b) {
|
|
2421
|
+
if (b.length > 0) this.parts.push(b);
|
|
2422
|
+
}
|
|
2423
|
+
str(s) {
|
|
2424
|
+
if (s) this.parts.push(enc(s));
|
|
2425
|
+
}
|
|
2426
|
+
/**
|
|
2427
|
+
* Prints the piece as `DIFF_SYMBOL_WORD_DIFF` does (`fprintf("%.*s")`): up to its first NUL
|
|
2428
|
+
* byte, whatever follows (suffix, reset, newline) dropped with it
|
|
2429
|
+
*/
|
|
2430
|
+
flushTo(sink) {
|
|
2431
|
+
for (const p of this.parts) {
|
|
2432
|
+
const nul = p.indexOf(0);
|
|
2433
|
+
if (nul < 0) {
|
|
2434
|
+
sink.push(p);
|
|
2435
|
+
continue;
|
|
2436
|
+
}
|
|
2437
|
+
if (nul > 0) sink.push(p.subarray(0, nul));
|
|
2438
|
+
break;
|
|
2439
|
+
}
|
|
2440
|
+
this.parts = [];
|
|
2441
|
+
}
|
|
2442
|
+
};
|
|
2443
|
+
/** `fn_out_diff_words_write_helper`: `text` as pieces of `el`, `newline` for each LF */
|
|
2444
|
+
function writeHelper(sink, el, newline, text) {
|
|
2445
|
+
const sb = new Pieces();
|
|
2446
|
+
let at = 0;
|
|
2447
|
+
let count = text.length;
|
|
2448
|
+
while (count > 0) {
|
|
2449
|
+
const nl = text.subarray(at, at + count).indexOf(NEWLINE);
|
|
2450
|
+
if (nl !== 0) {
|
|
2451
|
+
const colored = el.color !== void 0 && el.color !== "";
|
|
2452
|
+
if (colored) sb.str(el.color);
|
|
2453
|
+
sb.bytes(el.prefix);
|
|
2454
|
+
sb.bytes(text.subarray(at, nl < 0 ? at + count : at + nl));
|
|
2455
|
+
sb.bytes(el.suffix);
|
|
2456
|
+
if (colored) sb.bytes(GIT_COLOR_RESET);
|
|
2457
|
+
}
|
|
2458
|
+
if (nl < 0) break;
|
|
2459
|
+
sb.bytes(newline);
|
|
2460
|
+
count -= nl + 1;
|
|
2461
|
+
at += nl + 1;
|
|
2462
|
+
if (count > 0) sb.flushTo(sink);
|
|
2463
|
+
}
|
|
2464
|
+
sb.flushTo(sink);
|
|
2465
|
+
}
|
|
2466
|
+
/** `find_word_boundaries`: the next word at or after `begin`, or undefined */
|
|
2467
|
+
function findWord(text, regex, start) {
|
|
2468
|
+
let begin = start;
|
|
2469
|
+
const size = text.length;
|
|
2470
|
+
while (regex && begin < size) {
|
|
2471
|
+
const m = regex.exec(text.subarray(begin), size - begin, 1);
|
|
2472
|
+
if (!m) return void 0;
|
|
2473
|
+
const from = begin + m.start;
|
|
2474
|
+
const nl = text.subarray(from, begin + m.end).indexOf(NEWLINE);
|
|
2475
|
+
const end = nl >= 0 ? from + nl : begin + m.end;
|
|
2476
|
+
begin = from;
|
|
2477
|
+
if (begin === end) begin++;
|
|
2478
|
+
else return begin > end ? void 0 : [begin, end];
|
|
2479
|
+
}
|
|
2480
|
+
while (begin < size && isSpace(text[begin])) begin++;
|
|
2481
|
+
if (begin >= size) return void 0;
|
|
2482
|
+
let end = begin + 1;
|
|
2483
|
+
while (end < size && !isSpace(text[end])) end++;
|
|
2484
|
+
return [begin, end];
|
|
2485
|
+
}
|
|
2486
|
+
/** `diff_words_fill`: the words of `text`, one per line */
|
|
2487
|
+
function fillWords(text, regex) {
|
|
2488
|
+
const orig = [[0, 0]];
|
|
2489
|
+
const words = [];
|
|
2490
|
+
let size = 0;
|
|
2491
|
+
for (let i = 0; i < text.length;) {
|
|
2492
|
+
const found = findWord(text, regex, i);
|
|
2493
|
+
if (!found) break;
|
|
2494
|
+
orig.push(found);
|
|
2495
|
+
words.push(found);
|
|
2496
|
+
size += found[1] - found[0] + 1;
|
|
2497
|
+
i = found[1];
|
|
2498
|
+
}
|
|
2499
|
+
const lines = new Uint8Array(size);
|
|
2500
|
+
let at = 0;
|
|
2501
|
+
for (const [b, e] of words) {
|
|
2502
|
+
lines.set(text.subarray(b, e), at);
|
|
2503
|
+
at += e - b;
|
|
2504
|
+
lines[at++] = NEWLINE;
|
|
2505
|
+
}
|
|
2506
|
+
return {
|
|
2507
|
+
lines,
|
|
2508
|
+
orig
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
/** The removed and added lines gathered since the last context line (`diff_words_data`) */
|
|
2512
|
+
var WordDiffState = class {
|
|
2513
|
+
sink;
|
|
2514
|
+
regex;
|
|
2515
|
+
minus = [];
|
|
2516
|
+
plus = [];
|
|
2517
|
+
style;
|
|
2518
|
+
constructor(sink, regex, mode, colors) {
|
|
2519
|
+
this.sink = sink;
|
|
2520
|
+
this.regex = regex;
|
|
2521
|
+
this.style = styleOf(mode, colors);
|
|
2522
|
+
}
|
|
2523
|
+
/** `diff_words_append`: a line without its sign, its LF included */
|
|
2524
|
+
append(kind, line) {
|
|
2525
|
+
(kind === "-" ? this.minus : this.plus).push(line);
|
|
2526
|
+
}
|
|
2527
|
+
/** `diff_words_flush` */
|
|
2528
|
+
flush() {
|
|
2529
|
+
if (this.minus.length > 0 || this.plus.length > 0) this.show();
|
|
2530
|
+
}
|
|
2531
|
+
/** `diff_words_show` */
|
|
2532
|
+
show() {
|
|
2533
|
+
const minus = concat(this.minus);
|
|
2534
|
+
const plus = concat(this.plus);
|
|
2535
|
+
this.minus = [];
|
|
2536
|
+
this.plus = [];
|
|
2537
|
+
const style = this.style;
|
|
2538
|
+
if (plus.length === 0) {
|
|
2539
|
+
writeHelper(this.sink, style.oldWord, style.newline, minus);
|
|
2540
|
+
return;
|
|
2541
|
+
}
|
|
2542
|
+
let currentPlus = 0;
|
|
2543
|
+
const mw = fillWords(minus, this.regex);
|
|
2544
|
+
const pw = fillWords(plus, this.regex);
|
|
2545
|
+
for (const change of xdiffHunks(mw.lines, pw.lines)) {
|
|
2546
|
+
const minusFirst = change.chg1 ? change.i1 + 1 : change.i1;
|
|
2547
|
+
const plusFirst = change.chg2 ? change.i2 + 1 : change.i2;
|
|
2548
|
+
const [minusBegin, minusEnd] = span(mw.orig, minusFirst, change.chg1);
|
|
2549
|
+
const [plusBegin, plusEnd] = span(pw.orig, plusFirst, change.chg2);
|
|
2550
|
+
if (currentPlus !== plusBegin) writeHelper(this.sink, style.ctx, style.newline, plus.subarray(currentPlus, plusBegin));
|
|
2551
|
+
if (minusBegin !== minusEnd) writeHelper(this.sink, style.oldWord, style.newline, minus.subarray(minusBegin, minusEnd));
|
|
2552
|
+
if (plusBegin !== plusEnd) writeHelper(this.sink, style.newWord, style.newline, plus.subarray(plusBegin, plusEnd));
|
|
2553
|
+
currentPlus = plusEnd;
|
|
2554
|
+
}
|
|
2555
|
+
if (currentPlus !== plus.length) writeHelper(this.sink, style.ctx, style.newline, plus.subarray(currentPlus));
|
|
2556
|
+
}
|
|
2557
|
+
};
|
|
2558
|
+
/** The text a hunk of words covers: from its first word's start to its last word's end */
|
|
2559
|
+
function span(orig, first, len) {
|
|
2560
|
+
if (len === 0) {
|
|
2561
|
+
const end = orig[first][1];
|
|
2562
|
+
return [end, end];
|
|
2563
|
+
}
|
|
2564
|
+
return [orig[first][0], orig[first + len - 1][1]];
|
|
2565
|
+
}
|
|
2566
|
+
function concat(parts) {
|
|
2567
|
+
if (parts.length === 1) return parts[0];
|
|
2568
|
+
let size = 0;
|
|
2569
|
+
for (const p of parts) size += p.length;
|
|
2570
|
+
const out = new Uint8Array(size);
|
|
2571
|
+
let at = 0;
|
|
2572
|
+
for (const p of parts) {
|
|
2573
|
+
out.set(p, at);
|
|
2574
|
+
at += p.length;
|
|
2575
|
+
}
|
|
2576
|
+
return out;
|
|
2577
|
+
}
|
|
2578
|
+
/** diff.c's `emit_line_0` without a sign: `set` before the text, the reset after it */
|
|
2579
|
+
function emitLine(sink, set, reset, line) {
|
|
2580
|
+
let len = line.length;
|
|
2581
|
+
const hasNewline = len > 0 && line[len - 1] === NEWLINE;
|
|
2582
|
+
if (hasNewline) len--;
|
|
2583
|
+
const hasCr = len > 0 && line[len - 1] === 13;
|
|
2584
|
+
if (hasCr) len--;
|
|
2585
|
+
if (len > 0) {
|
|
2586
|
+
if (set) sink.push(enc(set));
|
|
2587
|
+
sink.push(line.subarray(0, len));
|
|
2588
|
+
if (reset) sink.push(enc(reset));
|
|
2589
|
+
}
|
|
2590
|
+
if (hasCr) sink.push(Uint8Array.of(13));
|
|
2591
|
+
if (hasNewline) sink.push(Uint8Array.of(NEWLINE));
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
* The hunks of a text pair as diff.c's `fn_out_consume` prints them under `--word-diff`:
|
|
2595
|
+
* each header as usual (in color, `frag` and `func`), the removed and added lines between
|
|
2596
|
+
* two context lines as their word diff, context lines without their sign (porcelain mode:
|
|
2597
|
+
* with it, then `~`). An incomplete last line counts as ending in a newline; git's
|
|
2598
|
+
* "" is not printed.
|
|
2599
|
+
*/
|
|
2600
|
+
function writeWordDiffHunks(sink, hunks, options) {
|
|
2601
|
+
const colors = options.colors;
|
|
2602
|
+
const state = new WordDiffState(sink, options.regex, options.mode, colors);
|
|
2603
|
+
const context = colors?.context ?? "";
|
|
2604
|
+
const reset = colors?.reset ?? "";
|
|
2605
|
+
for (const hunk of hunks) {
|
|
2606
|
+
state.flush();
|
|
2607
|
+
sink.push(colors ? coloredHunkHeader(hunk.header, colors) : hunk.header);
|
|
2608
|
+
for (const line of hunk.lines) {
|
|
2609
|
+
const bytes = line.bytes;
|
|
2610
|
+
const text = bytes.length > 0 && bytes[bytes.length - 1] !== NEWLINE ? withNewline$1(bytes) : bytes;
|
|
2611
|
+
if (line.kind === "-" || line.kind === "+") {
|
|
2612
|
+
state.append(line.kind, text);
|
|
2613
|
+
continue;
|
|
2614
|
+
}
|
|
2615
|
+
state.flush();
|
|
2616
|
+
if (options.mode === "porcelain") {
|
|
2617
|
+
emitLine(sink, context, reset, concat([Uint8Array.of(32), text]));
|
|
2618
|
+
sink.push(TILDE_LINE);
|
|
2619
|
+
} else emitLine(sink, context, reset, text);
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
state.flush();
|
|
2623
|
+
}
|
|
2624
|
+
function withNewline$1(bytes) {
|
|
2625
|
+
const out = new Uint8Array(bytes.length + 1);
|
|
2626
|
+
out.set(bytes);
|
|
2627
|
+
out[bytes.length] = NEWLINE;
|
|
2628
|
+
return out;
|
|
2629
|
+
}
|
|
2630
|
+
//#endregion
|
|
2631
|
+
//#region src/results/diff-output.ts
|
|
2632
|
+
/**
|
|
2633
|
+
* git's diff output (`diff.c`) over file pairs: the patch (`git diff`), `--stat`,
|
|
2634
|
+
* `--numstat`, `--shortstat`, `--name-only` and `--name-status`, byte for byte as git prints
|
|
2635
|
+
* them.
|
|
2636
|
+
*
|
|
2637
|
+
* @example
|
|
2638
|
+
* ```typescript
|
|
2639
|
+
* const pairs: DiffFilePair[] = [{ status: "M", old: blobSide(...), new: blobSide(...) }];
|
|
2640
|
+
* const patch = await formatPatch(pairs, { context: 3, indentHeuristic: true });
|
|
2641
|
+
* const stat = formatStat(await computeDiffstat(pairs), { width: 80 });
|
|
2642
|
+
* ```
|
|
2643
|
+
*
|
|
2644
|
+
* A pair has an old and a new side; a side that does not exist (an added file's old side,
|
|
2645
|
+
* a deleted file's new side) is left out. Each file is shown as git's `builtin_diff` shows
|
|
2646
|
+
* it: the `diff --git` header with mode, rename and `index` lines, then "Binary files ...
|
|
2647
|
+
* differ" or the hunks of the text diff ({@link unifiedDiffHunks}). A pair between a file
|
|
2648
|
+
* and a symbolic link is shown as a deletion and an addition. The header of a file whose
|
|
2649
|
+
* diff comes out empty (only whitespace changes under `-w`) is printed only when it
|
|
2650
|
+
* carries news of its own (mode change, rename, new or deleted file).
|
|
2651
|
+
*
|
|
2652
|
+
* @module
|
|
2653
|
+
*/
|
|
2654
|
+
const S_IFMT$1 = 61440;
|
|
2655
|
+
const GITLINK_MODE = 57344;
|
|
2656
|
+
const FIRST_FEW_BYTES = 8e3;
|
|
2657
|
+
/** @internal git diff's `big_file_threshold` default (512 MiB) */
|
|
2658
|
+
const GIT_DIFF_BIG_FILE_THRESHOLD = 536870912;
|
|
2659
|
+
const encoder = new TextEncoder();
|
|
2660
|
+
/**
|
|
2661
|
+
* The driver of a `diff` attribute value (git's `userdiff_find_by_path`): set means text,
|
|
2662
|
+
* unset means binary, a name means `diff.<name>.*` from `config` or a builtin driver.
|
|
2663
|
+
*/
|
|
2664
|
+
function diffDriverOf(attribute, config, compatibility = "2.56") {
|
|
2665
|
+
if (attribute === true) return { binary: false };
|
|
2666
|
+
if (attribute === false) return { binary: true };
|
|
2667
|
+
if (typeof attribute !== "string") return void 0;
|
|
2668
|
+
const name = attribute;
|
|
2669
|
+
const binary = boolValue(config?.(`diff.${name}.binary`));
|
|
2670
|
+
const algorithm = config?.(`diff.${name}.algorithm`);
|
|
2671
|
+
const legacy = compatibility === "2.43";
|
|
2672
|
+
const findFunction = userdiffFindFunction(name, config, legacy ? BUILTIN_FUNCNAME_PATTERNS_2_43 : BUILTIN_FUNCNAME_PATTERNS);
|
|
2673
|
+
const wordRegex = userdiffWordRegex(name, config, legacy ? BUILTIN_WORD_REGEXES_2_43 : BUILTIN_WORD_REGEXES);
|
|
2674
|
+
const textconvCommand = config?.(`diff.${name}.textconv`);
|
|
2675
|
+
const cacheTextconv = boolValue(config?.(`diff.${name}.cachetextconv`));
|
|
2676
|
+
if (binary === void 0 && !algorithm && !findFunction && !wordRegex && textconvCommand === void 0) return;
|
|
2677
|
+
return {
|
|
2678
|
+
name,
|
|
2679
|
+
...binary !== void 0 ? { binary } : {},
|
|
2680
|
+
...algorithm ? { algorithm } : {},
|
|
2681
|
+
...findFunction ? { findFunction } : {},
|
|
2682
|
+
...wordRegex ? { wordRegex } : {},
|
|
2683
|
+
...textconvCommand !== void 0 ? { textconvCommand } : {},
|
|
2684
|
+
...cacheTextconv !== void 0 ? { cacheTextconv } : {}
|
|
2685
|
+
};
|
|
2686
|
+
}
|
|
2687
|
+
/** A git boolean (`git_config_bool`), undefined when unset or not one. */
|
|
2688
|
+
const boolValue = (v) => parseGitBool(v);
|
|
2689
|
+
/**
|
|
2690
|
+
* A side as the diff reads it: its content and binary state, read once
|
|
2691
|
+
*
|
|
2692
|
+
* @internal
|
|
2693
|
+
*/
|
|
2694
|
+
var LoadedSide = class {
|
|
2695
|
+
spec;
|
|
2696
|
+
driver;
|
|
2697
|
+
otherId;
|
|
2698
|
+
content;
|
|
2699
|
+
probed;
|
|
2700
|
+
constructor(spec, driver, otherId) {
|
|
2701
|
+
this.spec = spec;
|
|
2702
|
+
this.driver = driver;
|
|
2703
|
+
this.otherId = otherId;
|
|
2704
|
+
}
|
|
2705
|
+
get valid() {
|
|
2706
|
+
return this.spec !== void 0;
|
|
2707
|
+
}
|
|
2708
|
+
get mode() {
|
|
2709
|
+
return this.spec?.mode ?? 0;
|
|
2710
|
+
}
|
|
2711
|
+
get id() {
|
|
2712
|
+
return this.spec?.id ?? nullObjectIdLike(this.otherId);
|
|
2713
|
+
}
|
|
2714
|
+
read() {
|
|
2715
|
+
this.content ??= this.spec ? this.spec.read() : Promise.resolve(/* @__PURE__ */ new Uint8Array(0));
|
|
2716
|
+
return this.content;
|
|
2717
|
+
}
|
|
2718
|
+
/** The bytes textconv converts ({@link DiffSideSpec.readTextconvInput}) */
|
|
2719
|
+
textconvInput() {
|
|
2720
|
+
return this.spec?.readTextconvInput ? this.spec.readTextconvInput() : this.read();
|
|
2721
|
+
}
|
|
2722
|
+
/** `diff_filespec_is_binary` */
|
|
2723
|
+
async isBinary(threshold) {
|
|
2724
|
+
if (this.driver?.binary !== void 0) return this.driver.binary;
|
|
2725
|
+
if (!this.spec) return false;
|
|
2726
|
+
return (await this.probe(threshold)).binary;
|
|
2727
|
+
}
|
|
2728
|
+
probe(threshold) {
|
|
2729
|
+
this.probed ??= (async () => {
|
|
2730
|
+
if (this.spec?.probe && !this.content) return this.spec.probe(threshold);
|
|
2731
|
+
const content = await this.read();
|
|
2732
|
+
return {
|
|
2733
|
+
size: content.length,
|
|
2734
|
+
binary: content.length > threshold || hasNul(content)
|
|
2735
|
+
};
|
|
2736
|
+
})();
|
|
2737
|
+
return this.probed;
|
|
2738
|
+
}
|
|
2739
|
+
async size(threshold) {
|
|
2740
|
+
if (!this.spec) return 0;
|
|
2741
|
+
return (await this.probe(threshold)).size;
|
|
2742
|
+
}
|
|
2743
|
+
};
|
|
1487
2744
|
function hasNul(content) {
|
|
1488
2745
|
const n = Math.min(content.length, FIRST_FEW_BYTES);
|
|
1489
2746
|
return (n === content.length ? content : content.subarray(0, n)).indexOf(0) >= 0;
|
|
@@ -1494,10 +2751,22 @@ function octal6(mode) {
|
|
|
1494
2751
|
/**
|
|
1495
2752
|
* The driver a side's content is read with (`diff_filespec_load_driver`): a regular file's;
|
|
1496
2753
|
* an absent side, a symbolic link and a submodule take the default driver
|
|
2754
|
+
*
|
|
2755
|
+
* @internal
|
|
1497
2756
|
*/
|
|
1498
2757
|
function contentDriver(spec, driver) {
|
|
1499
|
-
return spec && (spec.mode & S_IFMT) === 32768 ? driver : void 0;
|
|
2758
|
+
return spec && (spec.mode & S_IFMT$1) === 32768 ? driver : void 0;
|
|
2759
|
+
}
|
|
2760
|
+
/**
|
|
2761
|
+
* The full path of a pair's side for attributes; the other side's for an absent one
|
|
2762
|
+
*
|
|
2763
|
+
* @internal
|
|
2764
|
+
*/
|
|
2765
|
+
function attrPathOf(side, other, fallback) {
|
|
2766
|
+
const spec = side ?? other;
|
|
2767
|
+
return spec ? spec.attrPath ?? spec.path : fallback;
|
|
1500
2768
|
}
|
|
2769
|
+
/** @internal The diff driver of a path, from {@link DiffOutputOptions.driver} */
|
|
1501
2770
|
async function driverOf(options, path) {
|
|
1502
2771
|
if (!path || !options.driver) return void 0;
|
|
1503
2772
|
return options.driver(path);
|
|
@@ -1510,10 +2779,15 @@ async function formatPatch(pairs, options = {}) {
|
|
|
1510
2779
|
for (const pair of pairs) await writePairPatch(sink, pair, options);
|
|
1511
2780
|
return sink.bytes();
|
|
1512
2781
|
}
|
|
2782
|
+
/** A side that is a directory (a subtree a diff lists for `--find-object`) */
|
|
2783
|
+
function isTreeSide(side) {
|
|
2784
|
+
return side !== void 0 && (side.mode & S_IFMT$1) === 16384;
|
|
2785
|
+
}
|
|
1513
2786
|
/** Writes one pair as `run_diff` does: a file/symlink change as deletion and addition */
|
|
1514
2787
|
async function writePairPatch(sink, pair, options = {}, report) {
|
|
1515
2788
|
const { old: one, new: two } = pair;
|
|
1516
|
-
if (
|
|
2789
|
+
if (isTreeSide(one) || isTreeSide(two)) return;
|
|
2790
|
+
if (one && two && (one.mode & S_IFMT$1) !== (two.mode & S_IFMT$1)) {
|
|
1517
2791
|
await builtinDiff(sink, {
|
|
1518
2792
|
...pair,
|
|
1519
2793
|
new: void 0
|
|
@@ -1529,20 +2803,22 @@ async function writePairPatch(sink, pair, options = {}, report) {
|
|
|
1529
2803
|
/** `fill_metainfo`: rename/copy lines and the index line; whether they force the header */
|
|
1530
2804
|
function metainfo(pair, one, two, name, other, options, fullIndex = false) {
|
|
1531
2805
|
const quote = options.quotePath ?? true;
|
|
2806
|
+
const set = options.colors?.meta ?? "";
|
|
2807
|
+
const reset = options.colors?.reset ?? "";
|
|
1532
2808
|
let text = "";
|
|
1533
2809
|
let mustShow = false;
|
|
1534
2810
|
if (pair.status === "R" || pair.status === "C") {
|
|
1535
2811
|
const word = pair.status === "R" ? "rename" : "copy";
|
|
1536
|
-
text +=
|
|
1537
|
-
text += `${word} from ${quotePath(name, quote)}\n`;
|
|
1538
|
-
text += `${word} to ${quotePath(other ?? name, quote)}\n`;
|
|
2812
|
+
text += `${set}similarity index ${pair.score ?? 0}%${reset}\n`;
|
|
2813
|
+
text += `${set}${word} from ${quotePath(name, quote)}${reset}\n`;
|
|
2814
|
+
text += `${set}${word} to ${quotePath(other ?? name, quote)}${reset}\n`;
|
|
1539
2815
|
mustShow = true;
|
|
1540
2816
|
}
|
|
1541
2817
|
if (one.id !== two.id) {
|
|
1542
|
-
const abbrev = (id) => id.slice(0, options.fullIndex || fullIndex ?
|
|
1543
|
-
text +=
|
|
2818
|
+
const abbrev = (id) => id.slice(0, options.fullIndex || fullIndex ? id.length : options.abbrevLengths?.get(id) ?? options.abbrev ?? 7);
|
|
2819
|
+
text += `${set}index ${abbrev(one.id)}..${abbrev(two.id)}`;
|
|
1544
2820
|
if (one.mode === two.mode) text += ` ${octal6(one.mode)}`;
|
|
1545
|
-
text +=
|
|
2821
|
+
text += `${reset}\n`;
|
|
1546
2822
|
}
|
|
1547
2823
|
return {
|
|
1548
2824
|
text,
|
|
@@ -1551,20 +2827,22 @@ function metainfo(pair, one, two, name, other, options, fullIndex = false) {
|
|
|
1551
2827
|
}
|
|
1552
2828
|
/** git's `builtin_diff` for one pair (both sides of the same kind, or one side absent) */
|
|
1553
2829
|
async function builtinDiff(sink, pair, options, absentPath, report) {
|
|
1554
|
-
if (options.submodulePatch && (pair.old || pair.new) && (!pair.old || (pair.old.mode & S_IFMT) === GITLINK_MODE) && (!pair.new || (pair.new.mode & S_IFMT) === GITLINK_MODE)) {
|
|
2830
|
+
if (options.submodulePatch && (pair.old || pair.new) && (!pair.old || (pair.old.mode & S_IFMT$1) === GITLINK_MODE) && (!pair.new || (pair.new.mode & S_IFMT$1) === GITLINK_MODE)) {
|
|
1555
2831
|
await options.submodulePatch(sink, pair, options);
|
|
1556
2832
|
return;
|
|
1557
2833
|
}
|
|
1558
2834
|
const quote = options.quotePath ?? true;
|
|
1559
|
-
const threshold = options.bigFileThreshold ??
|
|
2835
|
+
const threshold = options.bigFileThreshold ?? 536870912;
|
|
1560
2836
|
const pathOne = pair.old?.path ?? absentPath ?? pair.new?.path ?? "";
|
|
1561
2837
|
const pathTwo = pair.new?.path ?? absentPath ?? pair.old?.path ?? "";
|
|
1562
2838
|
const name = pathOne;
|
|
1563
2839
|
const other = pathTwo !== name ? pathTwo : void 0;
|
|
1564
|
-
const
|
|
1565
|
-
const
|
|
1566
|
-
const
|
|
1567
|
-
const
|
|
2840
|
+
const attrOne = attrPathOf(pair.old, pair.new, pathOne);
|
|
2841
|
+
const attrTwo = attrPathOf(pair.new, pair.old, pathTwo);
|
|
2842
|
+
const oneDriver = await driverOf(options, attrOne);
|
|
2843
|
+
const twoDriver = attrTwo === attrOne ? oneDriver : await driverOf(options, attrTwo);
|
|
2844
|
+
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver), pair.new?.id);
|
|
2845
|
+
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver), pair.old?.id);
|
|
1568
2846
|
const textconvOne = one.driver?.textconv;
|
|
1569
2847
|
const textconvTwo = two.driver?.textconv;
|
|
1570
2848
|
const isBinary = async () => !options.text && (!textconvOne && await one.isBinary(threshold) || !textconvTwo && await two.isBinary(threshold));
|
|
@@ -1578,24 +2856,26 @@ async function builtinDiff(sink, pair, options, absentPath, report) {
|
|
|
1578
2856
|
const bTwo = quoteTwo(bPrefix, stripSlash(nameB), quote);
|
|
1579
2857
|
const lbl0 = one.valid ? aOne : "/dev/null";
|
|
1580
2858
|
const lbl1 = two.valid ? bTwo : "/dev/null";
|
|
1581
|
-
|
|
2859
|
+
const cMeta = options.colors?.meta ?? "";
|
|
2860
|
+
const cReset = options.colors?.reset ?? "";
|
|
2861
|
+
let header = `${cMeta}diff --git ${aOne} ${bTwo}${cReset}\n`;
|
|
1582
2862
|
if (!one.valid) {
|
|
1583
|
-
header +=
|
|
2863
|
+
header += `${cMeta}new file mode ${octal6(two.mode)}${cReset}\n${meta.text}`;
|
|
1584
2864
|
mustShow = true;
|
|
1585
2865
|
} else if (!two.valid) {
|
|
1586
|
-
header +=
|
|
2866
|
+
header += `${cMeta}deleted file mode ${octal6(one.mode)}${cReset}\n${meta.text}`;
|
|
1587
2867
|
mustShow = true;
|
|
1588
2868
|
} else {
|
|
1589
2869
|
if (one.mode !== two.mode) {
|
|
1590
|
-
header +=
|
|
2870
|
+
header += `${cMeta}old mode ${octal6(one.mode)}${cReset}\n${cMeta}new mode ${octal6(two.mode)}${cReset}\n`;
|
|
1591
2871
|
mustShow = true;
|
|
1592
2872
|
}
|
|
1593
2873
|
header += meta.text;
|
|
1594
|
-
if ((one.mode ^ two.mode) & S_IFMT) return;
|
|
2874
|
+
if ((one.mode ^ two.mode) & S_IFMT$1) return;
|
|
1595
2875
|
}
|
|
1596
2876
|
if (report) {
|
|
1597
2877
|
report.gitLine = `diff --git ${aOne} ${bTwo}`;
|
|
1598
|
-
report.extended = header.slice(
|
|
2878
|
+
report.extended = header.slice(header.indexOf("\n") + 1);
|
|
1599
2879
|
report.binary = false;
|
|
1600
2880
|
report.result = void 0;
|
|
1601
2881
|
report.oldLabel = void 0;
|
|
@@ -1628,8 +2908,8 @@ async function builtinDiff(sink, pair, options, absentPath, report) {
|
|
|
1628
2908
|
}
|
|
1629
2909
|
const driver = one.driver?.findFunction ? one.driver : two.driver;
|
|
1630
2910
|
const algorithm = oneDriver?.algorithm ?? options.algorithm;
|
|
1631
|
-
const textOne = textconvOne ? await textconvOne(await one.textconvInput(),
|
|
1632
|
-
const textTwo = textconvTwo ? await textconvTwo(await two.textconvInput(),
|
|
2911
|
+
const textOne = textconvOne ? await textconvOne(await one.textconvInput(), attrOne) : await one.read();
|
|
2912
|
+
const textTwo = textconvTwo ? await textconvTwo(await two.textconvInput(), attrTwo) : await two.read();
|
|
1633
2913
|
const result = unifiedDiffHunks(textOne, textTwo, {
|
|
1634
2914
|
...options,
|
|
1635
2915
|
algorithm,
|
|
@@ -1645,17 +2925,59 @@ async function builtinDiff(sink, pair, options, absentPath, report) {
|
|
|
1645
2925
|
report.oldLabel = oldLabel;
|
|
1646
2926
|
report.newLabel = newLabel;
|
|
1647
2927
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
2928
|
+
const colors = options.colors;
|
|
2929
|
+
const wordDiff = options.wordDiff === "none" ? void 0 : options.wordDiff ?? (options.wordDiffRegex !== void 0 ? "plain" : void 0);
|
|
2930
|
+
if (wordDiff) {
|
|
2931
|
+
sink.text(colors ? `${colors.meta}--- ${lbl0}${colors.reset}${lbl0.includes(" ") ? " " : ""}\n${colors.meta}+++ ${lbl1}${colors.reset}${lbl1.includes(" ") ? " " : ""}\n` : `${oldLabel}\n${newLabel}\n`);
|
|
2932
|
+
const pattern = options.wordDiffRegex ?? contentDriver(pair.old, oneDriver)?.wordRegex ?? contentDriver(pair.new, twoDriver)?.wordRegex ?? options.defaultWordRegex;
|
|
2933
|
+
writeWordDiffHunks(sink, coloredHunksOf(result), {
|
|
2934
|
+
mode: wordDiff,
|
|
2935
|
+
...pattern !== void 0 ? { regex: compileWordRegex(pattern) } : {},
|
|
2936
|
+
...colors ? { colors } : {}
|
|
2937
|
+
});
|
|
2938
|
+
return;
|
|
2939
|
+
}
|
|
2940
|
+
if (!colors) {
|
|
2941
|
+
sink.text(`${oldLabel}\n${newLabel}\n`);
|
|
2942
|
+
writeHunks(sink, result);
|
|
2943
|
+
return;
|
|
2944
|
+
}
|
|
2945
|
+
sink.text(`${colors.meta}--- ${lbl0}${colors.reset}${lbl0.includes(" ") ? " " : ""}\n${colors.meta}+++ ${lbl1}${colors.reset}${lbl1.includes(" ") ? " " : ""}\n`);
|
|
2946
|
+
let wsRule = await options.whitespaceRule?.(two.valid ? attrTwo : attrOne) ?? 1224;
|
|
2947
|
+
if (two.valid && (two.mode & S_IFMT$1) === 40960) wsRule &= -4097;
|
|
2948
|
+
writeColoredHunks(sink, coloredHunksOf(result), {
|
|
2949
|
+
colors,
|
|
2950
|
+
wsErrorHighlight: options.wsHighlight ?? 65536,
|
|
2951
|
+
wsRule,
|
|
2952
|
+
oldContent: textOne,
|
|
2953
|
+
newContent: textTwo
|
|
2954
|
+
});
|
|
2955
|
+
}
|
|
2956
|
+
/** The hunks of a text diff with their lines' bytes, for the colored writer */
|
|
2957
|
+
function coloredHunksOf(result) {
|
|
2958
|
+
return result.hunks.map((hunk) => ({
|
|
2959
|
+
header: formatHunkHeader(hunk),
|
|
2960
|
+
oldStart: hunk.oldStart,
|
|
2961
|
+
newStart: hunk.newStart,
|
|
2962
|
+
lines: hunk.lines.map((line) => {
|
|
2963
|
+
const lines = line.kind === "-" ? result.old : result.new;
|
|
2964
|
+
const starts = lines.lineStarts;
|
|
2965
|
+
return {
|
|
2966
|
+
kind: line.kind,
|
|
2967
|
+
bytes: lines.content.subarray(starts[line.index], starts[line.index + 1])
|
|
2968
|
+
};
|
|
2969
|
+
})
|
|
2970
|
+
}));
|
|
1650
2971
|
}
|
|
1651
2972
|
function stripSlash(name) {
|
|
1652
2973
|
return name.startsWith("/") ? name.slice(1) : name;
|
|
1653
2974
|
}
|
|
1654
2975
|
/** The diffstat of the pairs (`builtin_diffstat` for each) */
|
|
1655
2976
|
async function computeDiffstat(pairs, options = {}) {
|
|
1656
|
-
const threshold = options.bigFileThreshold ??
|
|
2977
|
+
const threshold = options.bigFileThreshold ?? 536870912;
|
|
1657
2978
|
const files = [];
|
|
1658
2979
|
for (const pair of pairs) {
|
|
2980
|
+
if (isTreeSide(pair.old) || isTreeSide(pair.new)) continue;
|
|
1659
2981
|
const nameA = pair.old?.path ?? pair.new?.path ?? "";
|
|
1660
2982
|
const nameB = pair.new?.path ?? nameA;
|
|
1661
2983
|
const renamed = nameB !== nameA;
|
|
@@ -1668,10 +2990,12 @@ async function computeDiffstat(pairs, options = {}) {
|
|
|
1668
2990
|
deleted: 0
|
|
1669
2991
|
};
|
|
1670
2992
|
files.push(file);
|
|
1671
|
-
const
|
|
1672
|
-
const
|
|
1673
|
-
const
|
|
1674
|
-
const
|
|
2993
|
+
const attrOne = attrPathOf(pair.old, pair.new, nameA);
|
|
2994
|
+
const attrTwo = attrPathOf(pair.new, pair.old, nameB);
|
|
2995
|
+
const oneDriver = await driverOf(options, attrOne);
|
|
2996
|
+
const twoDriver = attrTwo === attrOne ? oneDriver : await driverOf(options, attrTwo);
|
|
2997
|
+
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver), pair.new?.id);
|
|
2998
|
+
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver), pair.old?.id);
|
|
1675
2999
|
const mayDiffer = !(one.valid && two.valid && one.spec?.idValid !== false && two.spec?.idValid !== false && one.id === two.id);
|
|
1676
3000
|
if (await one.isBinary(threshold) || await two.isBinary(threshold)) {
|
|
1677
3001
|
file.isBinary = true;
|
|
@@ -1866,7 +3190,8 @@ function formatStat(files, options = {}) {
|
|
|
1866
3190
|
out += "\n";
|
|
1867
3191
|
continue;
|
|
1868
3192
|
}
|
|
1869
|
-
|
|
3193
|
+
const c = options.colors;
|
|
3194
|
+
out += ` ${c?.old ?? ""}${deleted}${c?.reset ?? ""} -> ${c?.new ?? ""}${added}${c?.reset ?? ""} bytes\n`;
|
|
1870
3195
|
continue;
|
|
1871
3196
|
}
|
|
1872
3197
|
if (file.isUnmerged) {
|
|
@@ -1888,8 +3213,8 @@ function formatStat(files, options = {}) {
|
|
|
1888
3213
|
}
|
|
1889
3214
|
out += ` ${prefix}${name}${pad} | ${String(added + deleted).padStart(numberWidth)}`;
|
|
1890
3215
|
out += added + deleted ? " " : "";
|
|
1891
|
-
out += "+".repeat(
|
|
1892
|
-
out += "-".repeat(
|
|
3216
|
+
if (add > 0) out += `${options.colors?.new ?? ""}${"+".repeat(add)}${options.colors?.reset ?? ""}`;
|
|
3217
|
+
if (del > 0) out += `${options.colors?.old ?? ""}${"-".repeat(del)}${options.colors?.reset ?? ""}`;
|
|
1893
3218
|
out += "\n";
|
|
1894
3219
|
}
|
|
1895
3220
|
let totalFiles = files.length;
|
|
@@ -1995,7 +3320,7 @@ function formatSummary(pairs, quote = true) {
|
|
|
1995
3320
|
* shows a gitlink). The probe reads a text blob once and keeps it for {@link DiffSideSpec.read}.
|
|
1996
3321
|
*/
|
|
1997
3322
|
function blobSide(blobs, path, mode, id) {
|
|
1998
|
-
if ((mode & S_IFMT) === 57344) {
|
|
3323
|
+
if ((mode & S_IFMT$1) === 57344) {
|
|
1999
3324
|
const content = encoder.encode(`Subproject commit ${id}\n`);
|
|
2000
3325
|
return {
|
|
2001
3326
|
path,
|
|
@@ -2090,6 +3415,220 @@ async function formatNoIndexDiff(a, b, options = {}) {
|
|
|
2090
3415
|
return pair ? formatPatch([pair], options) : /* @__PURE__ */ new Uint8Array(0);
|
|
2091
3416
|
}
|
|
2092
3417
|
//#endregion
|
|
3418
|
+
//#region src/results/diff-check.ts
|
|
3419
|
+
/**
|
|
3420
|
+
* `git diff --check` (diff.c's `builtin_checkdiff` and `checkdiff_consume`): the whitespace
|
|
3421
|
+
* errors and leftover conflict markers the new side of a pair adds, one
|
|
3422
|
+
* `<file>:<line>: <error>.` line each, followed by the offending line with its errors in the
|
|
3423
|
+
* `whitespace` color.
|
|
3424
|
+
*
|
|
3425
|
+
* @example
|
|
3426
|
+
* ```typescript
|
|
3427
|
+
* const sink = new ByteSink();
|
|
3428
|
+
* const failed = await writePairCheck(sink, pair, { whitespaceRule: () => WS_DEFAULT_RULE });
|
|
3429
|
+
* // sink: "x:2: trailing whitespace.\n+foo(); \n"
|
|
3430
|
+
* ```
|
|
3431
|
+
*
|
|
3432
|
+
* @module
|
|
3433
|
+
*/
|
|
3434
|
+
const S_IFMT = 61440;
|
|
3435
|
+
const S_IFLNK = 40960;
|
|
3436
|
+
const S_IFDIR = 16384;
|
|
3437
|
+
/** `DEFAULT_CONFLICT_MARKER_SIZE` */
|
|
3438
|
+
const DEFAULT_CONFLICT_MARKER_SIZE = 7;
|
|
3439
|
+
/**
|
|
3440
|
+
* merge-ll.c's `ll_merge_marker_size` over a `conflict-marker-size` attribute value: its
|
|
3441
|
+
* integer, else 7 (with git's warning for a value that is no integer)
|
|
3442
|
+
*/
|
|
3443
|
+
function conflictMarkerSizeOf(attribute, warn) {
|
|
3444
|
+
if (attribute === void 0) return 7;
|
|
3445
|
+
const text = typeof attribute === "string" ? attribute : "";
|
|
3446
|
+
const m = /^[ \t\n\v\f\r]*([+-]?\d+)$/.exec(text);
|
|
3447
|
+
const value = m ? Number.parseInt(m[1], 10) : NaN;
|
|
3448
|
+
if (!Number.isSafeInteger(value) || value > 2147483647 || value < -2147483648) {
|
|
3449
|
+
warn?.(`invalid marker-size '${typeof attribute === "string" ? attribute : attribute ? "true" : "false"}', expecting an integer`);
|
|
3450
|
+
return 7;
|
|
3451
|
+
}
|
|
3452
|
+
return value <= 0 ? 7 : value;
|
|
3453
|
+
}
|
|
3454
|
+
/** merge-ll.c's `is_conflict_marker_line` over a line (its LF included) */
|
|
3455
|
+
function isConflictMarkerLine(line, markerSize) {
|
|
3456
|
+
if (line.length < markerSize + 1) return false;
|
|
3457
|
+
const first = line[0];
|
|
3458
|
+
if (first !== 61 && first !== 62 && first !== 60 && first !== 124) return false;
|
|
3459
|
+
for (let i = 1; i < markerSize; i++) if (line[i] !== first) return false;
|
|
3460
|
+
const after = line[markerSize];
|
|
3461
|
+
if ((first === 60 || first === 62) && after !== 32) return false;
|
|
3462
|
+
return after === 32 || after >= 9 && after <= 13;
|
|
3463
|
+
}
|
|
3464
|
+
const PLUS = Uint8Array.of(43);
|
|
3465
|
+
function withNewline(bytes) {
|
|
3466
|
+
const out = new Uint8Array(bytes.length + 1);
|
|
3467
|
+
out.set(bytes);
|
|
3468
|
+
out[bytes.length] = 10;
|
|
3469
|
+
return out;
|
|
3470
|
+
}
|
|
3471
|
+
/**
|
|
3472
|
+
* Writes the `--check` report of one pair (`run_checkdiff`); true when it found an error
|
|
3473
|
+
* (git's `check_failed`). A tree side or an unmerged pair is not checked; the new side's
|
|
3474
|
+
* whitespace rule and marker size are those of its path, and a binary new side is not read.
|
|
3475
|
+
*/
|
|
3476
|
+
async function writePairCheck(sink, pair, options = {}, check = {}) {
|
|
3477
|
+
const { old: one, new: two } = pair;
|
|
3478
|
+
if (one && (one.mode & S_IFMT) === S_IFDIR || two && (two.mode & S_IFMT) === S_IFDIR) return false;
|
|
3479
|
+
const name = (two ?? one)?.path ?? "";
|
|
3480
|
+
const attrPath = attrPathOf(two, one, name);
|
|
3481
|
+
let wsRule = await options.whitespaceRule?.(attrPath) ?? 1224;
|
|
3482
|
+
const markerSize = await check.conflictMarkerSize?.(attrPath) ?? 7;
|
|
3483
|
+
if (two && (two.mode & S_IFMT) === S_IFLNK) wsRule &= -4097;
|
|
3484
|
+
const threshold = options.bigFileThreshold ?? 536870912;
|
|
3485
|
+
const newSide = new LoadedSide(two, contentDriver(two, await driverOf(options, attrPath)));
|
|
3486
|
+
if (await newSide.isBinary(threshold)) return false;
|
|
3487
|
+
const a = await new LoadedSide(one, void 0).read();
|
|
3488
|
+
const b = await newSide.read();
|
|
3489
|
+
const colors = options.colors;
|
|
3490
|
+
const ws = colors?.whitespace ?? "";
|
|
3491
|
+
const reset = colors?.reset ?? "";
|
|
3492
|
+
const set = colors?.new ?? "";
|
|
3493
|
+
const out = {
|
|
3494
|
+
str: (s) => {
|
|
3495
|
+
if (s) sink.push(encodeGitPath(s));
|
|
3496
|
+
},
|
|
3497
|
+
bytes: (bytes) => {
|
|
3498
|
+
if (bytes.length > 0) sink.push(bytes);
|
|
3499
|
+
}
|
|
3500
|
+
};
|
|
3501
|
+
const text = (s) => sink.push(encodeGitPath(s));
|
|
3502
|
+
let failed = false;
|
|
3503
|
+
const result = unifiedDiffHunks(a, b, {
|
|
3504
|
+
algorithm: "myers",
|
|
3505
|
+
indentHeuristic: false,
|
|
3506
|
+
context: 1
|
|
3507
|
+
});
|
|
3508
|
+
const lines = result.new;
|
|
3509
|
+
for (const hunk of result.hunks) for (const line of hunk.lines) {
|
|
3510
|
+
const kind = line.kind;
|
|
3511
|
+
if (kind === "-") continue;
|
|
3512
|
+
const start = lines.lineStarts[line.index];
|
|
3513
|
+
const end = lines.lineStarts[line.index + 1];
|
|
3514
|
+
const raw = lines.content.subarray(start, end);
|
|
3515
|
+
const complete = raw.length > 0 && raw[raw.length - 1] === 10;
|
|
3516
|
+
const body = complete ? raw : withNewline(raw);
|
|
3517
|
+
const lineno = line.index + 1;
|
|
3518
|
+
if (kind === "+") {
|
|
3519
|
+
if (isConflictMarkerLine(body, markerSize)) {
|
|
3520
|
+
failed = true;
|
|
3521
|
+
text(`${name}:${lineno}: leftover conflict marker\n`);
|
|
3522
|
+
}
|
|
3523
|
+
const bad = wsCheck(body, wsRule);
|
|
3524
|
+
if (bad) {
|
|
3525
|
+
failed = true;
|
|
3526
|
+
text(`${name}:${lineno}: ${whitespaceErrorString(bad)}.\n`);
|
|
3527
|
+
out.str(set);
|
|
3528
|
+
sink.push(PLUS);
|
|
3529
|
+
out.str(reset);
|
|
3530
|
+
wsCheckEmit(body, wsRule, out, set, reset, ws);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
if (!complete && raw.length > 0 && kind === "+" && wsRule & 4096) {
|
|
3534
|
+
failed = true;
|
|
3535
|
+
text(`${name}:${lineno}: ${whitespaceErrorString(WS_INCOMPLETE_LINE)}.\n`);
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
if (wsRule & 1024) {
|
|
3539
|
+
const at = checkBlankAtEof(a, b).postimage;
|
|
3540
|
+
if (at) {
|
|
3541
|
+
text(`${name}:${at}: ${whitespaceErrorString(WS_BLANK_AT_EOF)}.\n`);
|
|
3542
|
+
failed = true;
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
return failed;
|
|
3546
|
+
}
|
|
3547
|
+
//#endregion
|
|
3548
|
+
//#region src/results/diff-entry.ts
|
|
3549
|
+
/**
|
|
3550
|
+
* Type of change in a diff entry.
|
|
3551
|
+
*/
|
|
3552
|
+
let ChangeType = /* @__PURE__ */ function(ChangeType) {
|
|
3553
|
+
/** File was added */
|
|
3554
|
+
ChangeType["ADD"] = "ADD";
|
|
3555
|
+
/** File was modified */
|
|
3556
|
+
ChangeType["MODIFY"] = "MODIFY";
|
|
3557
|
+
/** File was deleted */
|
|
3558
|
+
ChangeType["DELETE"] = "DELETE";
|
|
3559
|
+
/** File was renamed */
|
|
3560
|
+
ChangeType["RENAME"] = "RENAME";
|
|
3561
|
+
/** File was copied */
|
|
3562
|
+
ChangeType["COPY"] = "COPY";
|
|
3563
|
+
return ChangeType;
|
|
3564
|
+
}({});
|
|
3565
|
+
/**
|
|
3566
|
+
* Create a DiffEntry for an added file.
|
|
3567
|
+
*/
|
|
3568
|
+
function createAddEntry(path, id, mode) {
|
|
3569
|
+
return {
|
|
3570
|
+
changeType: "ADD",
|
|
3571
|
+
newPath: path,
|
|
3572
|
+
newId: id,
|
|
3573
|
+
newMode: mode
|
|
3574
|
+
};
|
|
3575
|
+
}
|
|
3576
|
+
/**
|
|
3577
|
+
* Create a DiffEntry for a deleted file.
|
|
3578
|
+
*/
|
|
3579
|
+
function createDeleteEntry(path, id, mode) {
|
|
3580
|
+
return {
|
|
3581
|
+
changeType: "DELETE",
|
|
3582
|
+
oldPath: path,
|
|
3583
|
+
oldId: id,
|
|
3584
|
+
oldMode: mode
|
|
3585
|
+
};
|
|
3586
|
+
}
|
|
3587
|
+
/**
|
|
3588
|
+
* Create a DiffEntry for a modified file.
|
|
3589
|
+
*/
|
|
3590
|
+
function createModifyEntry(path, oldId, newId, oldMode, newMode) {
|
|
3591
|
+
return {
|
|
3592
|
+
changeType: "MODIFY",
|
|
3593
|
+
oldPath: path,
|
|
3594
|
+
newPath: path,
|
|
3595
|
+
oldId,
|
|
3596
|
+
newId,
|
|
3597
|
+
oldMode,
|
|
3598
|
+
newMode
|
|
3599
|
+
};
|
|
3600
|
+
}
|
|
3601
|
+
/**
|
|
3602
|
+
* Create a DiffEntry for a renamed file.
|
|
3603
|
+
*/
|
|
3604
|
+
function createRenameEntry(oldPath, newPath, oldId, newId, oldMode, newMode, score) {
|
|
3605
|
+
return {
|
|
3606
|
+
changeType: "RENAME",
|
|
3607
|
+
oldPath,
|
|
3608
|
+
newPath,
|
|
3609
|
+
oldId,
|
|
3610
|
+
newId,
|
|
3611
|
+
oldMode,
|
|
3612
|
+
newMode,
|
|
3613
|
+
score
|
|
3614
|
+
};
|
|
3615
|
+
}
|
|
3616
|
+
/**
|
|
3617
|
+
* Create a DiffEntry for a copied file.
|
|
3618
|
+
*/
|
|
3619
|
+
function createCopyEntry(oldPath, newPath, oldId, newId, oldMode, newMode, score) {
|
|
3620
|
+
return {
|
|
3621
|
+
changeType: "COPY",
|
|
3622
|
+
oldPath,
|
|
3623
|
+
newPath,
|
|
3624
|
+
oldId,
|
|
3625
|
+
newId,
|
|
3626
|
+
oldMode,
|
|
3627
|
+
newMode,
|
|
3628
|
+
score
|
|
3629
|
+
};
|
|
3630
|
+
}
|
|
3631
|
+
//#endregion
|
|
2093
3632
|
//#region src/results/diff-formatter.ts
|
|
2094
3633
|
/**
|
|
2095
3634
|
* Formatter for unified diffs of DiffEntry objects, byte for byte as `git diff` prints them
|
|
@@ -2202,91 +3741,433 @@ var DiffFormatter = class {
|
|
|
2202
3741
|
return result;
|
|
2203
3742
|
}
|
|
2204
3743
|
/**
|
|
2205
|
-
* The file's part of the diff as text: exactly git's output (LF-terminated lines), or
|
|
2206
|
-
* without the file headers when `includeHeaders` is false. Bytes that are no UTF-8 decode
|
|
2207
|
-
* as paths do (`decodeGitPath`), so `encodeGitPath` of the text gives the bytes back.
|
|
3744
|
+
* The file's part of the diff as text: exactly git's output (LF-terminated lines), or
|
|
3745
|
+
* without the file headers when `includeHeaders` is false. Bytes that are no UTF-8 decode
|
|
3746
|
+
* as paths do (`decodeGitPath`), so `encodeGitPath` of the text gives the bytes back.
|
|
3747
|
+
*
|
|
3748
|
+
* @param diff The content diff to stringify
|
|
3749
|
+
* @returns Unified diff string
|
|
3750
|
+
*/
|
|
3751
|
+
toString(diff) {
|
|
3752
|
+
const text = decodeGitPath(diff.patch);
|
|
3753
|
+
if (this.includeHeaders) return text;
|
|
3754
|
+
const at = text.search(/^(@@ |Binary files )/m);
|
|
3755
|
+
return at < 0 ? "" : text.slice(at);
|
|
3756
|
+
}
|
|
3757
|
+
/**
|
|
3758
|
+
* Format all diff entries to a single string, as `git diff` prints them.
|
|
3759
|
+
*
|
|
3760
|
+
* @param entries Array of diff entries
|
|
3761
|
+
* @returns Complete unified diff output
|
|
3762
|
+
*/
|
|
3763
|
+
async formatAll(entries) {
|
|
3764
|
+
const parts = [];
|
|
3765
|
+
for (const entry of entries) parts.push(this.toString(await this.format(entry)));
|
|
3766
|
+
return parts.join("");
|
|
3767
|
+
}
|
|
3768
|
+
/**
|
|
3769
|
+
* All diff entries as the bytes `git diff` prints (content that is not UTF-8 kept as it is).
|
|
3770
|
+
*/
|
|
3771
|
+
async formatBytes(entries) {
|
|
3772
|
+
const sink = new ByteSink();
|
|
3773
|
+
for (const entry of entries) sink.push((await this.format(entry)).patch);
|
|
3774
|
+
return sink.bytes();
|
|
3775
|
+
}
|
|
3776
|
+
};
|
|
3777
|
+
//#endregion
|
|
3778
|
+
//#region src/results/diff-order.ts
|
|
3779
|
+
/**
|
|
3780
|
+
* git's `diffcore-order.c` (`-O<orderfile>`, `diff.orderFile`): file pairs reordered by the
|
|
3781
|
+
* glob patterns of an order file.
|
|
3782
|
+
*
|
|
3783
|
+
* @example
|
|
3784
|
+
* ```typescript
|
|
3785
|
+
* const patterns = parseOrderFile(new TextEncoder().encode("*.h\n# headers first\n*.c\n"));
|
|
3786
|
+
* orderByPatterns(["b.c", "a.h", "README"], patterns, (p) => p);
|
|
3787
|
+
* // ["a.h", "b.c", "README"]
|
|
3788
|
+
* ```
|
|
3789
|
+
*
|
|
3790
|
+
* Each line of the file is a pattern, taken as it is (no trimming); empty lines and lines
|
|
3791
|
+
* starting with `#` are skipped. A path's rank is the first pattern that matches it or one
|
|
3792
|
+
* of its leading directories (wildmatch without `WM_PATHNAME`, so `*` also matches `/`);
|
|
3793
|
+
* paths no pattern matches come last, and paths of the same rank keep their order.
|
|
3794
|
+
*
|
|
3795
|
+
* @module
|
|
3796
|
+
*/
|
|
3797
|
+
/** The patterns of an order file (git's `prepare_order`) */
|
|
3798
|
+
function parseOrderFile(content) {
|
|
3799
|
+
const patterns = [];
|
|
3800
|
+
let start = 0;
|
|
3801
|
+
while (start < content.length) {
|
|
3802
|
+
let end = start;
|
|
3803
|
+
while (end < content.length && content[end] !== 10) end++;
|
|
3804
|
+
if (content[start] !== 10 && content[start] !== 35) patterns.push(decodeGitPath(content.subarray(start, end)));
|
|
3805
|
+
start = end < content.length ? end + 1 : end;
|
|
3806
|
+
}
|
|
3807
|
+
return patterns;
|
|
3808
|
+
}
|
|
3809
|
+
/** The rank of `path`: the first pattern matching it or a leading directory (`match_order`) */
|
|
3810
|
+
function orderRank(patterns, path) {
|
|
3811
|
+
for (let i = 0; i < patterns.length; i++) {
|
|
3812
|
+
let p = path;
|
|
3813
|
+
while (p) {
|
|
3814
|
+
if (wildmatch(patterns[i], p)) return i;
|
|
3815
|
+
const slash = p.lastIndexOf("/");
|
|
3816
|
+
if (slash < 0) break;
|
|
3817
|
+
p = p.slice(0, slash);
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
return patterns.length;
|
|
3821
|
+
}
|
|
3822
|
+
/** The items ordered by the rank of their paths, stably (`order_objects`) */
|
|
3823
|
+
function orderByPatterns(items, patterns, pathOf) {
|
|
3824
|
+
return items.map((item, index) => ({
|
|
3825
|
+
item,
|
|
3826
|
+
index,
|
|
3827
|
+
rank: orderRank(patterns, pathOf(item))
|
|
3828
|
+
})).sort((a, b) => a.rank - b.rank || a.index - b.index).map((e) => e.item);
|
|
3829
|
+
}
|
|
3830
|
+
//#endregion
|
|
3831
|
+
//#region src/results/diff-pickaxe.ts
|
|
3832
|
+
/**
|
|
3833
|
+
* Pickaxe (git's diffcore-pickaxe.c): which pairs of a diff queue mention a string, a regex
|
|
3834
|
+
* or an object. `-S<string>` keeps a pair whose two sides hold the string a different number
|
|
3835
|
+
* of times, `-G<regex>` a pair whose added or removed lines match the regex, `--find-object`
|
|
3836
|
+
* a pair with that object on either side.
|
|
3837
|
+
*
|
|
3838
|
+
* @example
|
|
3839
|
+
* ```ts
|
|
3840
|
+
* const pickaxe = DiffPickaxe.compile({ string: "frotz" });
|
|
3841
|
+
* const kept = await pickaxe.filter(pairs, (p) => p, outputOptions);
|
|
3842
|
+
* ```
|
|
3843
|
+
*
|
|
3844
|
+
* Both sides are read as the patch reads them: through the path's textconv when one applies,
|
|
3845
|
+
* and `-G` passes over binary pairs unless `--text` is given (or textconv makes them text),
|
|
3846
|
+
* as git does. `-S` counts non-overlapping occurrences, ASCII case folded under `-i`;
|
|
3847
|
+
* `--pickaxe-regex` and `-G` compile POSIX extended regexes with `REG_NEWLINE` (and
|
|
3848
|
+
* `REG_ICASE` under `-i`), so no JavaScript `RegExp` ever runs a user's pattern. `-G`
|
|
3849
|
+
* diffs the two texts with xdiff's defaults (Myers, no indent heuristic, no whitespace
|
|
3850
|
+
* options), whatever the patch shown uses.
|
|
3851
|
+
*
|
|
3852
|
+
* @module
|
|
3853
|
+
*/
|
|
3854
|
+
const LF = 10;
|
|
3855
|
+
/** ASCII lowercase (git's `tolower_trans_tbl` in the C locale) */
|
|
3856
|
+
function lowerAscii(bytes) {
|
|
3857
|
+
const out = new Uint8Array(bytes.length);
|
|
3858
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
3859
|
+
const c = bytes[i];
|
|
3860
|
+
out[i] = c >= 65 && c <= 90 ? c + 32 : c;
|
|
3861
|
+
}
|
|
3862
|
+
return out;
|
|
3863
|
+
}
|
|
3864
|
+
/** quote.c's basic_regex_quote_buf: a string as a basic regex matching it literally */
|
|
3865
|
+
function basicRegexQuote(s) {
|
|
3866
|
+
const out = [];
|
|
3867
|
+
let i = 0;
|
|
3868
|
+
if (s[i] === 94) out.push(92, s[i++]);
|
|
3869
|
+
if (s[i] === 42) out.push(s[i++]);
|
|
3870
|
+
for (; i < s.length; i++) {
|
|
3871
|
+
const c = s[i];
|
|
3872
|
+
if (c === 91 || c === 46 || c === 92 || c === 42) out.push(92, c);
|
|
3873
|
+
else if (c === 36 && i + 1 === s.length) out.push(92, c);
|
|
3874
|
+
else out.push(c);
|
|
3875
|
+
}
|
|
3876
|
+
return Uint8Array.from(out);
|
|
3877
|
+
}
|
|
3878
|
+
/** A pair's side whose object id git knows (`oid_valid`): a worktree file's is not */
|
|
3879
|
+
function knownId(side) {
|
|
3880
|
+
return side && side.idValid !== false ? side.id : void 0;
|
|
3881
|
+
}
|
|
3882
|
+
/** The compiled pickaxe of a diff (git's `diffcore_pickaxe`) */
|
|
3883
|
+
var DiffPickaxe = class DiffPickaxe {
|
|
3884
|
+
spec;
|
|
3885
|
+
regex;
|
|
3886
|
+
needle;
|
|
3887
|
+
constructor(spec, regex, needle) {
|
|
3888
|
+
this.spec = spec;
|
|
3889
|
+
this.regex = regex;
|
|
3890
|
+
this.needle = needle;
|
|
3891
|
+
}
|
|
3892
|
+
/**
|
|
3893
|
+
* Compiles a pickaxe as diffcore_pickaxe does; an invalid regex throws git's `fatal:
|
|
3894
|
+
* invalid regex: <glibc's message>` (exit 128).
|
|
3895
|
+
*/
|
|
3896
|
+
static compile(spec) {
|
|
3897
|
+
const compile = (pattern, extended) => {
|
|
3898
|
+
try {
|
|
3899
|
+
return compilePosixRegex(pattern, {
|
|
3900
|
+
extended,
|
|
3901
|
+
newline: true,
|
|
3902
|
+
icase: spec.ignoreCase ?? false
|
|
3903
|
+
});
|
|
3904
|
+
} catch (e) {
|
|
3905
|
+
if (e instanceof PosixRegexError) throw new GitApiError(`fatal: invalid regex: ${e.message}`).withExitCode(128);
|
|
3906
|
+
throw e;
|
|
3907
|
+
}
|
|
3908
|
+
};
|
|
3909
|
+
if (spec.grep !== void 0) return new DiffPickaxe(spec, compile(spec.grep, true), void 0);
|
|
3910
|
+
if (spec.string !== void 0) {
|
|
3911
|
+
if (spec.regex) return new DiffPickaxe(spec, compile(spec.string, true), void 0);
|
|
3912
|
+
const bytes = new TextEncoder().encode(spec.string);
|
|
3913
|
+
if (spec.ignoreCase && bytes.some((b) => b >= 128)) return new DiffPickaxe(spec, compile(basicRegexQuote(bytes), false), void 0);
|
|
3914
|
+
return new DiffPickaxe(spec, void 0, spec.ignoreCase ? lowerAscii(bytes) : bytes);
|
|
3915
|
+
}
|
|
3916
|
+
return new DiffPickaxe(spec, void 0, void 0);
|
|
3917
|
+
}
|
|
3918
|
+
/** Whether the pickaxe reads the blobs of the pairs (`-S`, `-G`; not `--find-object`) */
|
|
3919
|
+
get readsContent() {
|
|
3920
|
+
return this.spec.objects === void 0;
|
|
3921
|
+
}
|
|
3922
|
+
/**
|
|
3923
|
+
* The queue the pickaxe leaves (git's `pickaxe`): the items whose pair matches, or, under
|
|
3924
|
+
* `--pickaxe-all`, every item when one matches and none otherwise. An item without a pair
|
|
3925
|
+
* (an unmerged path) never matches.
|
|
3926
|
+
*/
|
|
3927
|
+
async filter(queue, pairOf, options) {
|
|
3928
|
+
if (this.spec.all) {
|
|
3929
|
+
for (const item of queue) {
|
|
3930
|
+
const pair = pairOf(item);
|
|
3931
|
+
if (pair && await this.matches(pair, options)) return [...queue];
|
|
3932
|
+
}
|
|
3933
|
+
return [];
|
|
3934
|
+
}
|
|
3935
|
+
const out = [];
|
|
3936
|
+
for (const item of queue) {
|
|
3937
|
+
const pair = pairOf(item);
|
|
3938
|
+
if (pair && await this.matches(pair, options)) out.push(item);
|
|
3939
|
+
}
|
|
3940
|
+
return out;
|
|
3941
|
+
}
|
|
3942
|
+
/** pickaxe_match: whether one pair matches */
|
|
3943
|
+
async matches(pair, options) {
|
|
3944
|
+
if (!pair.old && !pair.new) return false;
|
|
3945
|
+
const objects = this.spec.objects;
|
|
3946
|
+
if (objects) {
|
|
3947
|
+
const a = knownId(pair.old);
|
|
3948
|
+
const b = knownId(pair.new);
|
|
3949
|
+
return a !== void 0 && objects.has(a) || b !== void 0 && objects.has(b);
|
|
3950
|
+
}
|
|
3951
|
+
const threshold = options.bigFileThreshold ?? 536870912;
|
|
3952
|
+
const pathOne = pair.old?.path ?? pair.new?.path ?? "";
|
|
3953
|
+
const pathTwo = pair.new?.path ?? pair.old?.path ?? "";
|
|
3954
|
+
const attrOne = attrPathOf(pair.old, pair.new, pathOne);
|
|
3955
|
+
const attrTwo = attrPathOf(pair.new, pair.old, pathTwo);
|
|
3956
|
+
const oneDriver = await driverOf(options, attrOne);
|
|
3957
|
+
const twoDriver = attrTwo === attrOne ? oneDriver : await driverOf(options, attrTwo);
|
|
3958
|
+
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver), pair.new?.id);
|
|
3959
|
+
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver), pair.old?.id);
|
|
3960
|
+
const textconvOne = one.driver?.textconv ? one.driver : void 0;
|
|
3961
|
+
const textconvTwo = two.driver?.textconv ? two.driver : void 0;
|
|
3962
|
+
if ((textconvOne === textconvTwo || textconvOne !== void 0 && textconvTwo !== void 0 && textconvOne.name === textconvTwo.name) && unmodifiedPair(pair)) return false;
|
|
3963
|
+
if (this.spec.grep !== void 0 && !options.text && (!textconvOne && await one.isBinary(threshold) || !textconvTwo && await two.isBinary(threshold))) return false;
|
|
3964
|
+
const fill = async (side, attrPath) => {
|
|
3965
|
+
const textconv = side.driver?.textconv;
|
|
3966
|
+
if (!side.valid) return /* @__PURE__ */ new Uint8Array(0);
|
|
3967
|
+
if (!textconv) return side.read();
|
|
3968
|
+
try {
|
|
3969
|
+
return await textconv(await side.textconvInput(), attrPath);
|
|
3970
|
+
} catch (e) {
|
|
3971
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
3972
|
+
throw new GitApiError(`${message ? `${message}\n` : ""}fatal: unable to read files to diff`).withExitCode(128);
|
|
3973
|
+
}
|
|
3974
|
+
};
|
|
3975
|
+
const a = await fill(one, attrOne);
|
|
3976
|
+
const b = await fill(two, attrTwo);
|
|
3977
|
+
if (this.spec.grep !== void 0) return this.diffGrep(a, b, options);
|
|
3978
|
+
const c1 = this.contains(a, 0);
|
|
3979
|
+
return c1 !== this.contains(b, c1 + 1);
|
|
3980
|
+
}
|
|
3981
|
+
/** diff_grep: whether an added or removed line of the xdiff of `a` and `b` matches */
|
|
3982
|
+
diffGrep(a, b, options) {
|
|
3983
|
+
const regex = this.regex;
|
|
3984
|
+
const result = unifiedDiffHunks(a, b, {
|
|
3985
|
+
algorithm: "myers",
|
|
3986
|
+
indentHeuristic: false,
|
|
3987
|
+
context: options.context ?? 3,
|
|
3988
|
+
interHunkContext: options.interHunkContext ?? 0
|
|
3989
|
+
});
|
|
3990
|
+
for (const hunk of result.hunks) for (const line of hunk.lines) {
|
|
3991
|
+
if (line.kind === " ") continue;
|
|
3992
|
+
const lines = line.kind === "-" ? result.old : result.new;
|
|
3993
|
+
const start = lines.start(line.index);
|
|
3994
|
+
const end = lines.start(line.index + 1);
|
|
3995
|
+
const text = lines.content.subarray(start, end);
|
|
3996
|
+
if (regex.test(text)) return true;
|
|
3997
|
+
if (end > start && text[text.length - 1] !== LF) {
|
|
3998
|
+
const withLf = new Uint8Array(text.length + 1);
|
|
3999
|
+
withLf.set(text);
|
|
4000
|
+
withLf[text.length] = LF;
|
|
4001
|
+
if (regex.test(withLf)) return true;
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
return false;
|
|
4005
|
+
}
|
|
4006
|
+
/** contains(): the occurrences in `data`, up to `limit` (0: all) */
|
|
4007
|
+
contains(data, limit) {
|
|
4008
|
+
let count = 0;
|
|
4009
|
+
const regex = this.regex;
|
|
4010
|
+
if (regex) {
|
|
4011
|
+
const subject = data;
|
|
4012
|
+
let at = 0;
|
|
4013
|
+
let notbol = false;
|
|
4014
|
+
while (at < subject.length) {
|
|
4015
|
+
const m = regex.exec(subject.subarray(at), void 0, 1, notbol);
|
|
4016
|
+
if (!m) break;
|
|
4017
|
+
notbol = true;
|
|
4018
|
+
at += m.end;
|
|
4019
|
+
if (at < subject.length && m.start === m.end) at++;
|
|
4020
|
+
count++;
|
|
4021
|
+
if (limit && count === limit) return count;
|
|
4022
|
+
}
|
|
4023
|
+
return count;
|
|
4024
|
+
}
|
|
4025
|
+
const needle = this.needle;
|
|
4026
|
+
const hay = this.spec.ignoreCase ? lowerAscii(data) : data;
|
|
4027
|
+
const n = needle.length;
|
|
4028
|
+
if (n === 0) return 0;
|
|
4029
|
+
const first = needle[0];
|
|
4030
|
+
let at = 0;
|
|
4031
|
+
while (at + n <= hay.length) {
|
|
4032
|
+
const i = hay.indexOf(first, at);
|
|
4033
|
+
if (i < 0 || i + n > hay.length) break;
|
|
4034
|
+
let k = 1;
|
|
4035
|
+
while (k < n && hay[i + k] === needle[k]) k++;
|
|
4036
|
+
if (k < n) {
|
|
4037
|
+
at = i + 1;
|
|
4038
|
+
continue;
|
|
4039
|
+
}
|
|
4040
|
+
count++;
|
|
4041
|
+
if (limit && count === limit) return count;
|
|
4042
|
+
at = i + n;
|
|
4043
|
+
}
|
|
4044
|
+
return count;
|
|
4045
|
+
}
|
|
4046
|
+
};
|
|
4047
|
+
/** diff_unmodified_pair: both sides valid, at one path, of one mode and known equal content */
|
|
4048
|
+
function unmodifiedPair(pair) {
|
|
4049
|
+
const { old: one, new: two } = pair;
|
|
4050
|
+
if (!one || !two) return false;
|
|
4051
|
+
if (one.mode !== two.mode || one.path !== two.path) return false;
|
|
4052
|
+
const oneValid = one.idValid !== false;
|
|
4053
|
+
const twoValid = two.idValid !== false;
|
|
4054
|
+
if (oneValid && twoValid && one.id === two.id && !one.submoduleDirt && !two.submoduleDirt) return true;
|
|
4055
|
+
return !oneValid && !twoValid;
|
|
4056
|
+
}
|
|
4057
|
+
//#endregion
|
|
4058
|
+
//#region src/results/stash-result.ts
|
|
4059
|
+
/**
|
|
4060
|
+
* Status of stash apply operation.
|
|
4061
|
+
*/
|
|
4062
|
+
let StashApplyStatus = /* @__PURE__ */ function(StashApplyStatus) {
|
|
4063
|
+
/** Stash was applied successfully */
|
|
4064
|
+
StashApplyStatus["OK"] = "ok";
|
|
4065
|
+
/** Stash apply resulted in conflicts */
|
|
4066
|
+
StashApplyStatus["CONFLICTS"] = "conflicts";
|
|
4067
|
+
/** Stash apply failed */
|
|
4068
|
+
StashApplyStatus["FAILED"] = "failed";
|
|
4069
|
+
return StashApplyStatus;
|
|
4070
|
+
}({});
|
|
4071
|
+
//#endregion
|
|
4072
|
+
//#region src/results/merge-result.ts
|
|
4073
|
+
/**
|
|
4074
|
+
* Status of a merge operation.
|
|
4075
|
+
*
|
|
4076
|
+
* Based on JGit's MergeResult.MergeStatus.
|
|
4077
|
+
*/
|
|
4078
|
+
let MergeStatus = /* @__PURE__ */ function(MergeStatus) {
|
|
4079
|
+
/** Merge is a fast-forward (only HEAD moved) */
|
|
4080
|
+
MergeStatus["FAST_FORWARD"] = "fast-forward";
|
|
4081
|
+
/** Fast-forward merge with squash (HEAD not moved, changes staged) */
|
|
4082
|
+
MergeStatus["FAST_FORWARD_SQUASHED"] = "fast-forward-squashed";
|
|
4083
|
+
/** Merge was a no-op - already up to date */
|
|
4084
|
+
MergeStatus["ALREADY_UP_TO_DATE"] = "already-up-to-date";
|
|
4085
|
+
/** Merge completed successfully (merge commit created) */
|
|
4086
|
+
MergeStatus["MERGED"] = "merged";
|
|
4087
|
+
/** Merge completed but not committed (--no-commit) */
|
|
4088
|
+
MergeStatus["MERGED_NOT_COMMITTED"] = "merged-not-committed";
|
|
4089
|
+
/** Merge was squashed (not committed, HEAD not updated) */
|
|
4090
|
+
MergeStatus["MERGED_SQUASHED"] = "merged-squashed";
|
|
4091
|
+
/** Merge has conflicts that need to be resolved */
|
|
4092
|
+
MergeStatus["CONFLICTING"] = "conflicting";
|
|
4093
|
+
/** Merge failed (preconditions not met) */
|
|
4094
|
+
MergeStatus["FAILED"] = "failed";
|
|
4095
|
+
/** Merge aborted (e.g., FF_ONLY when not possible) */
|
|
4096
|
+
MergeStatus["ABORTED"] = "aborted";
|
|
4097
|
+
return MergeStatus;
|
|
4098
|
+
}({});
|
|
4099
|
+
/**
|
|
4100
|
+
* Fast-forward merge mode.
|
|
4101
|
+
*
|
|
4102
|
+
* Based on JGit's MergeCommand.FastForwardMode.
|
|
4103
|
+
*/
|
|
4104
|
+
let FastForwardMode = /* @__PURE__ */ function(FastForwardMode) {
|
|
4105
|
+
/** Allow fast-forward when possible (default) */
|
|
4106
|
+
FastForwardMode["FF"] = "ff";
|
|
4107
|
+
/** Never fast-forward, always create merge commit */
|
|
4108
|
+
FastForwardMode["NO_FF"] = "no-ff";
|
|
4109
|
+
/** Only allow fast-forward, abort if not possible */
|
|
4110
|
+
FastForwardMode["FF_ONLY"] = "ff-only";
|
|
4111
|
+
return FastForwardMode;
|
|
4112
|
+
}({});
|
|
4113
|
+
/**
|
|
4114
|
+
* Content merge strategy.
|
|
4115
|
+
*
|
|
4116
|
+
* Determines how to handle file-level conflicts.
|
|
4117
|
+
* Based on JGit's ContentMergeStrategy.
|
|
4118
|
+
*/
|
|
4119
|
+
let ContentMergeStrategy = /* @__PURE__ */ function(ContentMergeStrategy) {
|
|
4120
|
+
/** Take our version for conflicts */
|
|
4121
|
+
ContentMergeStrategy["OURS"] = "ours";
|
|
4122
|
+
/** Take their version for conflicts */
|
|
4123
|
+
ContentMergeStrategy["THEIRS"] = "theirs";
|
|
4124
|
+
/** Perform union merge (both sides) */
|
|
4125
|
+
ContentMergeStrategy["UNION"] = "union";
|
|
4126
|
+
return ContentMergeStrategy;
|
|
4127
|
+
}({});
|
|
4128
|
+
/**
|
|
4129
|
+
* Merge strategy.
|
|
4130
|
+
*
|
|
4131
|
+
* Based on JGit's MergeStrategy.
|
|
4132
|
+
*/
|
|
4133
|
+
let MergeStrategy = /* @__PURE__ */ function(MergeStrategy) {
|
|
4134
|
+
/**
|
|
4135
|
+
* Recursive three-way merge (default).
|
|
2208
4136
|
*
|
|
2209
|
-
*
|
|
2210
|
-
*
|
|
4137
|
+
* Standard merge algorithm that finds common ancestor and
|
|
4138
|
+
* performs three-way merge on each file.
|
|
2211
4139
|
*/
|
|
2212
|
-
|
|
2213
|
-
const text = decodeGitPath(diff.patch);
|
|
2214
|
-
if (this.includeHeaders) return text;
|
|
2215
|
-
const at = text.search(/^(@@ |Binary files )/m);
|
|
2216
|
-
return at < 0 ? "" : text.slice(at);
|
|
2217
|
-
}
|
|
4140
|
+
MergeStrategy["RECURSIVE"] = "recursive";
|
|
2218
4141
|
/**
|
|
2219
|
-
*
|
|
4142
|
+
* Always take our side.
|
|
2220
4143
|
*
|
|
2221
|
-
*
|
|
2222
|
-
*
|
|
4144
|
+
* Creates a merge commit but keeps our tree unchanged.
|
|
4145
|
+
* The other branch's changes are completely ignored.
|
|
4146
|
+
* Use case: record that merge happened without accepting changes.
|
|
2223
4147
|
*/
|
|
2224
|
-
|
|
2225
|
-
const parts = [];
|
|
2226
|
-
for (const entry of entries) parts.push(this.toString(await this.format(entry)));
|
|
2227
|
-
return parts.join("");
|
|
2228
|
-
}
|
|
4148
|
+
MergeStrategy["OURS"] = "ours";
|
|
2229
4149
|
/**
|
|
2230
|
-
*
|
|
4150
|
+
* Always take their side.
|
|
4151
|
+
*
|
|
4152
|
+
* Creates a merge commit but replaces our tree with theirs.
|
|
4153
|
+
* Our changes are completely discarded.
|
|
4154
|
+
* Use case: replace our branch with theirs while preserving history.
|
|
2231
4155
|
*/
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
4156
|
+
MergeStrategy["THEIRS"] = "theirs";
|
|
4157
|
+
/**
|
|
4158
|
+
* Simple resolve strategy.
|
|
4159
|
+
*
|
|
4160
|
+
* Similar to recursive but doesn't handle criss-cross merges.
|
|
4161
|
+
* Uses a single merge base.
|
|
4162
|
+
*/
|
|
4163
|
+
MergeStrategy["RESOLVE"] = "resolve";
|
|
4164
|
+
return MergeStrategy;
|
|
4165
|
+
}({});
|
|
2240
4166
|
/**
|
|
2241
|
-
*
|
|
2242
|
-
* glob patterns of an order file.
|
|
2243
|
-
*
|
|
2244
|
-
* @example
|
|
2245
|
-
* ```typescript
|
|
2246
|
-
* const patterns = parseOrderFile(new TextEncoder().encode("*.h\n# headers first\n*.c\n"));
|
|
2247
|
-
* orderByPatterns(["b.c", "a.h", "README"], patterns, (p) => p);
|
|
2248
|
-
* // ["a.h", "b.c", "README"]
|
|
2249
|
-
* ```
|
|
2250
|
-
*
|
|
2251
|
-
* Each line of the file is a pattern, taken as it is (no trimming); empty lines and lines
|
|
2252
|
-
* starting with `#` are skipped. A path's rank is the first pattern that matches it or one
|
|
2253
|
-
* of its leading directories (wildmatch without `WM_PATHNAME`, so `*` also matches `/`);
|
|
2254
|
-
* paths no pattern matches come last, and paths of the same rank keep their order.
|
|
2255
|
-
*
|
|
2256
|
-
* @module
|
|
4167
|
+
* Check if merge status represents a successful merge.
|
|
2257
4168
|
*/
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
const patterns = [];
|
|
2261
|
-
let start = 0;
|
|
2262
|
-
while (start < content.length) {
|
|
2263
|
-
let end = start;
|
|
2264
|
-
while (end < content.length && content[end] !== 10) end++;
|
|
2265
|
-
if (content[start] !== 10 && content[start] !== 35) patterns.push(decodeGitPath(content.subarray(start, end)));
|
|
2266
|
-
start = end < content.length ? end + 1 : end;
|
|
2267
|
-
}
|
|
2268
|
-
return patterns;
|
|
2269
|
-
}
|
|
2270
|
-
/** The rank of `path`: the first pattern matching it or a leading directory (`match_order`) */
|
|
2271
|
-
function orderRank(patterns, path) {
|
|
2272
|
-
for (let i = 0; i < patterns.length; i++) {
|
|
2273
|
-
let p = path;
|
|
2274
|
-
while (p) {
|
|
2275
|
-
if (wildmatch(patterns[i], p)) return i;
|
|
2276
|
-
const slash = p.lastIndexOf("/");
|
|
2277
|
-
if (slash < 0) break;
|
|
2278
|
-
p = p.slice(0, slash);
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
return patterns.length;
|
|
2282
|
-
}
|
|
2283
|
-
/** The items ordered by the rank of their paths, stably (`order_objects`) */
|
|
2284
|
-
function orderByPatterns(items, patterns, pathOf) {
|
|
2285
|
-
return items.map((item, index) => ({
|
|
2286
|
-
item,
|
|
2287
|
-
index,
|
|
2288
|
-
rank: orderRank(patterns, pathOf(item))
|
|
2289
|
-
})).sort((a, b) => a.rank - b.rank || a.index - b.index).map((e) => e.item);
|
|
4169
|
+
function isMergeSuccessful(status) {
|
|
4170
|
+
return status === "fast-forward" || status === "fast-forward-squashed" || status === "already-up-to-date" || status === "merged" || status === "merged-not-committed" || status === "merged-squashed";
|
|
2290
4171
|
}
|
|
2291
4172
|
//#endregion
|
|
2292
4173
|
//#region src/results/status-result.ts
|
|
@@ -2331,7 +4212,6 @@ var StatusImpl = class {
|
|
|
2331
4212
|
function comparePaths(a, b) {
|
|
2332
4213
|
return compareGitPaths(a, b);
|
|
2333
4214
|
}
|
|
2334
|
-
const ZERO_ID = "0".repeat(40);
|
|
2335
4215
|
/**
|
|
2336
4216
|
* The submodule field of a porcelain v2 line: `N...` for a path that is no submodule, else
|
|
2337
4217
|
* `S` and whether its commit changed (`C`), it has tracked changes (`M`) and untracked files
|
|
@@ -2385,6 +4265,7 @@ function formatStatusPorcelain(status, version = 1, options = {}) {
|
|
|
2385
4265
|
}
|
|
2386
4266
|
const xy = `${e.index === " " ? "." : e.index}${e.worktree === " " ? "." : e.worktree}`;
|
|
2387
4267
|
const sub = submoduleToken(e);
|
|
4268
|
+
const ZERO_ID = nullObjectIdLike(e.head?.id ?? e.staged?.id ?? e.stages?.find((x) => x !== void 0)?.id);
|
|
2388
4269
|
if (from !== void 0) {
|
|
2389
4270
|
lines.push([
|
|
2390
4271
|
"2",
|
|
@@ -2436,121 +4317,6 @@ function formatStatusPorcelain(status, version = 1, options = {}) {
|
|
|
2436
4317
|
return lines.map((l) => `${l}${eol}`).join("");
|
|
2437
4318
|
}
|
|
2438
4319
|
//#endregion
|
|
2439
|
-
//#region src/results/stash-result.ts
|
|
2440
|
-
/**
|
|
2441
|
-
* Status of stash apply operation.
|
|
2442
|
-
*/
|
|
2443
|
-
let StashApplyStatus = /* @__PURE__ */ function(StashApplyStatus) {
|
|
2444
|
-
/** Stash was applied successfully */
|
|
2445
|
-
StashApplyStatus["OK"] = "ok";
|
|
2446
|
-
/** Stash apply resulted in conflicts */
|
|
2447
|
-
StashApplyStatus["CONFLICTS"] = "conflicts";
|
|
2448
|
-
/** Stash apply failed */
|
|
2449
|
-
StashApplyStatus["FAILED"] = "failed";
|
|
2450
|
-
return StashApplyStatus;
|
|
2451
|
-
}({});
|
|
2452
|
-
//#endregion
|
|
2453
|
-
//#region src/results/merge-result.ts
|
|
2454
|
-
/**
|
|
2455
|
-
* Status of a merge operation.
|
|
2456
|
-
*
|
|
2457
|
-
* Based on JGit's MergeResult.MergeStatus.
|
|
2458
|
-
*/
|
|
2459
|
-
let MergeStatus = /* @__PURE__ */ function(MergeStatus) {
|
|
2460
|
-
/** Merge is a fast-forward (only HEAD moved) */
|
|
2461
|
-
MergeStatus["FAST_FORWARD"] = "fast-forward";
|
|
2462
|
-
/** Fast-forward merge with squash (HEAD not moved, changes staged) */
|
|
2463
|
-
MergeStatus["FAST_FORWARD_SQUASHED"] = "fast-forward-squashed";
|
|
2464
|
-
/** Merge was a no-op - already up to date */
|
|
2465
|
-
MergeStatus["ALREADY_UP_TO_DATE"] = "already-up-to-date";
|
|
2466
|
-
/** Merge completed successfully (merge commit created) */
|
|
2467
|
-
MergeStatus["MERGED"] = "merged";
|
|
2468
|
-
/** Merge completed but not committed (--no-commit) */
|
|
2469
|
-
MergeStatus["MERGED_NOT_COMMITTED"] = "merged-not-committed";
|
|
2470
|
-
/** Merge was squashed (not committed, HEAD not updated) */
|
|
2471
|
-
MergeStatus["MERGED_SQUASHED"] = "merged-squashed";
|
|
2472
|
-
/** Merge has conflicts that need to be resolved */
|
|
2473
|
-
MergeStatus["CONFLICTING"] = "conflicting";
|
|
2474
|
-
/** Merge failed (preconditions not met) */
|
|
2475
|
-
MergeStatus["FAILED"] = "failed";
|
|
2476
|
-
/** Merge aborted (e.g., FF_ONLY when not possible) */
|
|
2477
|
-
MergeStatus["ABORTED"] = "aborted";
|
|
2478
|
-
return MergeStatus;
|
|
2479
|
-
}({});
|
|
2480
|
-
/**
|
|
2481
|
-
* Fast-forward merge mode.
|
|
2482
|
-
*
|
|
2483
|
-
* Based on JGit's MergeCommand.FastForwardMode.
|
|
2484
|
-
*/
|
|
2485
|
-
let FastForwardMode = /* @__PURE__ */ function(FastForwardMode) {
|
|
2486
|
-
/** Allow fast-forward when possible (default) */
|
|
2487
|
-
FastForwardMode["FF"] = "ff";
|
|
2488
|
-
/** Never fast-forward, always create merge commit */
|
|
2489
|
-
FastForwardMode["NO_FF"] = "no-ff";
|
|
2490
|
-
/** Only allow fast-forward, abort if not possible */
|
|
2491
|
-
FastForwardMode["FF_ONLY"] = "ff-only";
|
|
2492
|
-
return FastForwardMode;
|
|
2493
|
-
}({});
|
|
2494
|
-
/**
|
|
2495
|
-
* Content merge strategy.
|
|
2496
|
-
*
|
|
2497
|
-
* Determines how to handle file-level conflicts.
|
|
2498
|
-
* Based on JGit's ContentMergeStrategy.
|
|
2499
|
-
*/
|
|
2500
|
-
let ContentMergeStrategy = /* @__PURE__ */ function(ContentMergeStrategy) {
|
|
2501
|
-
/** Take our version for conflicts */
|
|
2502
|
-
ContentMergeStrategy["OURS"] = "ours";
|
|
2503
|
-
/** Take their version for conflicts */
|
|
2504
|
-
ContentMergeStrategy["THEIRS"] = "theirs";
|
|
2505
|
-
/** Perform union merge (both sides) */
|
|
2506
|
-
ContentMergeStrategy["UNION"] = "union";
|
|
2507
|
-
return ContentMergeStrategy;
|
|
2508
|
-
}({});
|
|
2509
|
-
/**
|
|
2510
|
-
* Merge strategy.
|
|
2511
|
-
*
|
|
2512
|
-
* Based on JGit's MergeStrategy.
|
|
2513
|
-
*/
|
|
2514
|
-
let MergeStrategy = /* @__PURE__ */ function(MergeStrategy) {
|
|
2515
|
-
/**
|
|
2516
|
-
* Recursive three-way merge (default).
|
|
2517
|
-
*
|
|
2518
|
-
* Standard merge algorithm that finds common ancestor and
|
|
2519
|
-
* performs three-way merge on each file.
|
|
2520
|
-
*/
|
|
2521
|
-
MergeStrategy["RECURSIVE"] = "recursive";
|
|
2522
|
-
/**
|
|
2523
|
-
* Always take our side.
|
|
2524
|
-
*
|
|
2525
|
-
* Creates a merge commit but keeps our tree unchanged.
|
|
2526
|
-
* The other branch's changes are completely ignored.
|
|
2527
|
-
* Use case: record that merge happened without accepting changes.
|
|
2528
|
-
*/
|
|
2529
|
-
MergeStrategy["OURS"] = "ours";
|
|
2530
|
-
/**
|
|
2531
|
-
* Always take their side.
|
|
2532
|
-
*
|
|
2533
|
-
* Creates a merge commit but replaces our tree with theirs.
|
|
2534
|
-
* Our changes are completely discarded.
|
|
2535
|
-
* Use case: replace our branch with theirs while preserving history.
|
|
2536
|
-
*/
|
|
2537
|
-
MergeStrategy["THEIRS"] = "theirs";
|
|
2538
|
-
/**
|
|
2539
|
-
* Simple resolve strategy.
|
|
2540
|
-
*
|
|
2541
|
-
* Similar to recursive but doesn't handle criss-cross merges.
|
|
2542
|
-
* Uses a single merge base.
|
|
2543
|
-
*/
|
|
2544
|
-
MergeStrategy["RESOLVE"] = "resolve";
|
|
2545
|
-
return MergeStrategy;
|
|
2546
|
-
}({});
|
|
2547
|
-
/**
|
|
2548
|
-
* Check if merge status represents a successful merge.
|
|
2549
|
-
*/
|
|
2550
|
-
function isMergeSuccessful(status) {
|
|
2551
|
-
return status === "fast-forward" || status === "fast-forward-squashed" || status === "already-up-to-date" || status === "merged" || status === "merged-not-committed" || status === "merged-squashed";
|
|
2552
|
-
}
|
|
2553
|
-
//#endregion
|
|
2554
4320
|
//#region src/results/blame-format.ts
|
|
2555
4321
|
/**
|
|
2556
4322
|
* `git blame` output of a {@link BlameResult}: the porcelain formats (`--porcelain`,
|
|
@@ -2931,4 +4697,4 @@ let RevertStatus = /* @__PURE__ */ function(RevertStatus) {
|
|
|
2931
4697
|
return RevertStatus;
|
|
2932
4698
|
}({});
|
|
2933
4699
|
//#endregion
|
|
2934
|
-
export {
|
|
4700
|
+
export { formatNoIndexDiff as $, ChangeType as A, quotePath as At, GIT_DIFF_BIG_FILE_THRESHOLD as B, wsBlankLine as Bt, StashApplyStatus as C, parseColorMoved as Ct, parseOrderFile as D, wsErrorHighlightOf as Dt, orderRank as E, writeColoredHunks as Et, createRenameEntry as F, WhitespaceRuleError as Ft, computeDiffstat as G, attrPathOf as H, wsFixCopy as Ht, DEFAULT_CONFLICT_MARKER_SIZE as I, isGitSpace as It, diffDriverOf as J, contentDriver as K, conflictMarkerSizeOf as L, parseWhitespaceRule as Lt, createCopyEntry as M, WS_BLANK_AT_EOF as Mt, createDeleteEntry as N, WS_DEFAULT_RULE as Nt, DiffFormatter as O, writeCombinedDiff as Ot, createModifyEntry as P, WS_INCOMPLETE_LINE as Pt, formatNameStatus as Q, isConflictMarkerLine as R, whitespaceErrorString as Rt, isMergeSuccessful as S, diffColorSlotOf as St, orderByPatterns as T, parseWsErrorHighlight as Tt, blobIdOf as U, LoadedSide as V, wsCheck as Vt, blobSide as W, driverOf as X, displayWidth as Y, formatNameOnly as Z, submoduleToken as _, MovedLineBuffer as _t, PushStatus as a, noIndexPair as at, MergeStatus as b, WSEH_OLD as bt, isPullSuccessful as c, utf8 as ct, hasUpdates as d, compileWordRegex as dt, formatNumstat as et, CherryPickStatus as f, writeWordDiffHunks as ft, formatStatusPorcelain as g, DIFF_COLOR_SLOTS as gt, StatusImpl as h, DEFAULT_DIFF_COLORS as ht, isRebaseSuccessful as i, formatSummary as it, createAddEntry as j, quoteTwo as jt, diffEntryToPair as k, quoteCStyleBody as kt, RefUpdateStatus as l, writePairPatch as lt, formatBlamePorcelain as m, COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE as mt, RebaseAction as n, formatShortstat as nt, getFailedUpdates as o, pprintRename as ot, formatBlame as p, COLOR_MOVED_MODE_ERROR as pt, contentSide as q, RebaseStatus as r, formatStat as rt, isPushSuccessful as s, statSummary as st, RevertStatus as t, formatPatch as tt, getSuccessfulUpdates as u, WORD_DIFF_MODES as ut, ContentMergeStrategy as v, WSEH_CONTEXT as vt, DiffPickaxe as w, parseColorMovedWs as wt, MergeStrategy as x, coloredHunkHeader as xt, FastForwardMode as y, WSEH_NEW as yt, writePairCheck as z, whitespaceRuleOf as zt };
|