@statewalker/vcs-commands 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -8
- package/dist/commands/add-command.d.ts +265 -34
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-interactive.d.ts +46 -0
- package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
- package/dist/commands/add-patch/add-patch.d.ts +139 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
- package/dist/commands/add-patch/index.d.ts +6 -0
- package/dist/commands/add-patch/index.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-backend.d.ts +80 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-modes.d.ts +71 -0
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-session.d.ts +49 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
- package/dist/commands/am/am-command.d.ts +175 -0
- package/dist/commands/am/am-command.d.ts.map +1 -0
- package/dist/commands/am/index.d.ts +3 -0
- package/dist/commands/am/index.d.ts.map +1 -0
- package/dist/commands/am/mailinfo.d.ts +58 -0
- package/dist/commands/am/mailinfo.d.ts.map +1 -0
- package/dist/commands/am/patch-format.d.ts +24 -0
- package/dist/commands/am/patch-format.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts +153 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -0
- package/dist/commands/apply/apply-engine.d.ts +195 -0
- package/dist/commands/apply/apply-engine.d.ts.map +1 -0
- package/dist/commands/apply/apply-parse.d.ts +86 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -0
- package/dist/commands/apply/apply-types.d.ts +70 -0
- package/dist/commands/apply/apply-types.d.ts.map +1 -0
- package/dist/commands/apply/index.d.ts +6 -0
- package/dist/commands/apply/index.d.ts.map +1 -0
- package/dist/commands/apply/latin1.d.ts +32 -0
- package/dist/commands/apply/latin1.d.ts.map +1 -0
- package/dist/commands/apply/whitespace.d.ts +58 -0
- package/dist/commands/apply/whitespace.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +26 -0
- package/dist/commands/attributes-source.d.ts.map +1 -0
- package/dist/commands/backfill-command.d.ts +110 -0
- package/dist/commands/backfill-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
- package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-command.d.ts +201 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-engine.d.ts +219 -0
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-graph.d.ts +127 -0
- package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-quote.d.ts +27 -0
- package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
- package/dist/commands/bisect/index.d.ts +5 -0
- package/dist/commands/bisect/index.d.ts.map +1 -0
- package/dist/commands/blame-command.d.ts +122 -131
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +52 -2
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-tracking.d.ts +98 -0
- package/dist/commands/branch-tracking.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +300 -18
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +124 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +50 -42
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +49 -16
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +117 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +311 -17
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +78 -1
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/date-format.d.ts +58 -0
- package/dist/commands/date-format.d.ts.map +1 -0
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +377 -30
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-textconv.d.ts +40 -0
- package/dist/commands/diff-textconv.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +149 -10
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts +164 -0
- package/dist/commands/format-patch-command.d.ts.map +1 -0
- package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts +225 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +68 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +115 -0
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
- package/dist/commands/fsck/index.d.ts +6 -0
- package/dist/commands/fsck/index.d.ts.map +1 -0
- package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +43 -0
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +66 -0
- package/dist/commands/git-date.d.ts.map +1 -0
- package/dist/commands/git-describe.d.ts +67 -0
- package/dist/commands/git-describe.d.ts.map +1 -0
- package/dist/commands/git-hooks.d.ts +416 -0
- package/dist/commands/git-hooks.d.ts.map +1 -0
- package/dist/commands/git-ident.d.ts +128 -0
- package/dist/commands/git-ident.d.ts.map +1 -0
- package/dist/commands/hook-command.d.ts +96 -0
- package/dist/commands/hook-command.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +231 -0
- package/dist/commands/index-adder.d.ts.map +1 -0
- package/dist/commands/index-host.d.ts +86 -0
- package/dist/commands/index-host.d.ts.map +1 -0
- package/dist/commands/index.d.ts +54 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +12 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/local-clone.d.ts +60 -0
- package/dist/commands/local-clone.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +117 -0
- package/dist/commands/local-transport.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +216 -24
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +120 -0
- package/dist/commands/log-graph.d.ts.map +1 -0
- package/dist/commands/log-output.d.ts +323 -0
- package/dist/commands/log-output.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +23 -7
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +31 -0
- package/dist/commands/mailmap.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +85 -0
- package/dist/commands/merge-bases.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +209 -74
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +13 -0
- package/dist/commands/merge-config.d.ts.map +1 -0
- package/dist/commands/merge-drivers.d.ts +130 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +252 -0
- package/dist/commands/merge-support.d.ts.map +1 -0
- package/dist/commands/message-cleanup.d.ts +86 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -0
- package/dist/commands/mv-command.d.ts +94 -0
- package/dist/commands/mv-command.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts +256 -0
- package/dist/commands/notes-command.d.ts.map +1 -0
- package/dist/commands/notes-commands.d.ts +41 -0
- package/dist/commands/notes-commands.d.ts.map +1 -0
- package/dist/commands/notes-merge-command.d.ts +105 -0
- package/dist/commands/notes-merge-command.d.ts.map +1 -0
- package/dist/commands/notes-support.d.ts +125 -0
- package/dist/commands/notes-support.d.ts.map +1 -0
- package/dist/commands/notes-tree.d.ts +106 -0
- package/dist/commands/notes-tree.d.ts.map +1 -0
- package/dist/commands/object-id-input.d.ts +20 -0
- package/dist/commands/object-id-input.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +59 -0
- package/dist/commands/octopus-merge.d.ts.map +1 -0
- package/dist/commands/ort-merge.d.ts +126 -0
- package/dist/commands/ort-merge.d.ts.map +1 -0
- package/dist/commands/ort-recursive.d.ts +53 -0
- package/dist/commands/ort-recursive.d.ts.map +1 -0
- package/dist/commands/pack-refs-command.d.ts +20 -0
- package/dist/commands/pack-refs-command.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +41 -0
- package/dist/commands/patch-id.d.ts.map +1 -0
- package/dist/commands/pathspec-attributes.d.ts +64 -0
- package/dist/commands/pathspec-attributes.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +324 -0
- package/dist/commands/pathspec.d.ts.map +1 -0
- package/dist/commands/post-index-change.d.ts +33 -0
- package/dist/commands/post-index-change.d.ts.map +1 -0
- package/dist/commands/pretty-format.d.ts +222 -0
- package/dist/commands/pretty-format.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts +80 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -0
- package/dist/commands/pull-command.d.ts +41 -8
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +24 -8
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +112 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -0
- package/dist/commands/rebase-command.d.ts +507 -75
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/rebase-todo.d.ts +130 -0
- package/dist/commands/rebase-todo.d.ts.map +1 -0
- package/dist/commands/ref-decoration-filter.d.ts +53 -0
- package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
- package/dist/commands/reflog-messages.d.ts +98 -0
- package/dist/commands/reflog-messages.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +31 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +120 -0
- package/dist/commands/remote-transport.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +161 -7
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +103 -0
- package/dist/commands/restore-command.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +78 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -0
- package/dist/commands/rev-parse-command.d.ts +80 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -0
- package/dist/commands/revert-command.d.ts +46 -38
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-filenames.d.ts +95 -0
- package/dist/commands/revision-filenames.d.ts.map +1 -0
- package/dist/commands/revision-range.d.ts +67 -0
- package/dist/commands/revision-range.d.ts.map +1 -0
- package/dist/commands/revision-resolver.d.ts +321 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -0
- package/dist/commands/rm-command.d.ts +69 -7
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +191 -0
- package/dist/commands/sequencer-pick.d.ts.map +1 -0
- package/dist/commands/sequencer-support.d.ts +125 -0
- package/dist/commands/sequencer-support.d.ts.map +1 -0
- package/dist/commands/serve-repository.d.ts +52 -0
- package/dist/commands/serve-repository.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts +190 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-support.d.ts +268 -0
- package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +42 -8
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +155 -1
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +2 -0
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +23 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts +300 -15
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-format.d.ts +155 -0
- package/dist/commands/status-format.d.ts.map +1 -0
- package/dist/commands/status-header.d.ts +64 -0
- package/dist/commands/status-header.d.ts.map +1 -0
- package/dist/commands/strerror.d.ts +7 -0
- package/dist/commands/strerror.d.ts.map +1 -0
- package/dist/commands/submodule-config.d.ts +38 -0
- package/dist/commands/submodule-config.d.ts.map +1 -0
- package/dist/commands/submodule-summary-command.d.ts +80 -0
- package/dist/commands/submodule-summary-command.d.ts.map +1 -0
- package/dist/commands/submodule-summary.d.ts +150 -0
- package/dist/commands/submodule-summary.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +132 -0
- package/dist/commands/switch-command.d.ts.map +1 -0
- package/dist/commands/tag-command.d.ts +23 -2
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tracking-info.d.ts +64 -0
- package/dist/commands/tracking-info.d.ts.map +1 -0
- package/dist/commands/trailers.d.ts +73 -0
- package/dist/commands/trailers.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +85 -1
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +53 -0
- package/dist/commands/untracked-cache-support.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +108 -0
- package/dist/commands/worktree-add-command.d.ts.map +1 -0
- package/dist/commands/worktree-list-command.d.ts +69 -0
- package/dist/commands/worktree-list-command.d.ts.map +1 -0
- package/dist/commands/worktree-lock-command.d.ts +44 -0
- package/dist/commands/worktree-lock-command.d.ts.map +1 -0
- package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/commands/worktree-prune-command.d.ts +48 -0
- package/dist/commands/worktree-prune-command.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +59 -0
- package/dist/commands/worktree-remove-command.d.ts.map +1 -0
- package/dist/commands/worktree-repair-command.d.ts +35 -0
- package/dist/commands/worktree-repair-command.d.ts.map +1 -0
- package/dist/commands/worktree-support.d.ts +64 -0
- package/dist/commands/worktree-support.d.ts.map +1 -0
- package/dist/commands-DnmlfwGV.js +61620 -0
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/errors/add-errors.d.ts +55 -0
- package/dist/errors/add-errors.d.ts.map +1 -1
- package/dist/errors/checkout-errors.d.ts +16 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts +77 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/commit-errors.d.ts +9 -0
- package/dist/errors/commit-errors.d.ts.map +1 -1
- package/dist/errors/git-api-error.d.ts +59 -2
- package/dist/errors/git-api-error.d.ts.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +354 -19
- package/dist/errors/rebase-errors.d.ts +9 -0
- package/dist/errors/rebase-errors.d.ts.map +1 -1
- package/dist/errors/ref-errors.d.ts +32 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/transport-errors.d.ts +12 -2
- package/dist/errors/transport-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +35 -0
- package/dist/errors/worktree-errors.d.ts.map +1 -0
- package/dist/git-command-DxvwPrPB.js +7612 -0
- package/dist/git-command.d.ts +413 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +306 -3
- package/dist/git.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/remote-config-store.d.ts +105 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +7 -3
- package/dist/remote-config/remote-refs.d.ts.map +1 -1
- package/dist/rename/detect-renames.d.ts +148 -0
- package/dist/rename/detect-renames.d.ts.map +1 -0
- package/dist/rename/git-similarity.d.ts +44 -0
- package/dist/rename/git-similarity.d.ts.map +1 -0
- package/dist/rename/index.d.ts +2 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/binary-patch.d.ts +11 -0
- package/dist/results/binary-patch.d.ts.map +1 -0
- package/dist/results/blame-format.d.ts +55 -0
- package/dist/results/blame-format.d.ts.map +1 -0
- package/dist/results/cherry-pick-result.d.ts +10 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +10 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +77 -0
- package/dist/results/combined-diff.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +32 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +34 -60
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-order.d.ts +25 -0
- package/dist/results/diff-order.d.ts.map +1 -0
- package/dist/results/diff-output.d.ts +249 -0
- package/dist/results/diff-output.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +15 -0
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +5 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -252
- package/dist/results/merge-result.d.ts +15 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +12 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +42 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/quote-path.d.ts +27 -0
- package/dist/results/quote-path.d.ts.map +1 -0
- package/dist/results/rebase-result.d.ts +28 -1
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +10 -0
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +5 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +60 -6
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BZGa2Z3I.js +2934 -0
- package/dist/transport-command.d.ts +44 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -11
- package/src/commands/add-command.ts +1291 -226
- package/src/commands/add-patch/add-interactive.ts +941 -0
- package/src/commands/add-patch/add-patch.ts +1169 -0
- package/src/commands/add-patch/index.ts +5 -0
- package/src/commands/add-patch/patch-backend.ts +239 -0
- package/src/commands/add-patch/patch-modes.ts +249 -0
- package/src/commands/add-patch/patch-session.ts +159 -0
- package/src/commands/am/am-command.ts +1111 -0
- package/src/commands/am/index.ts +2 -0
- package/src/commands/am/mailinfo.ts +1015 -0
- package/src/commands/am/patch-format.ts +121 -0
- package/src/commands/apply/apply-command.ts +832 -0
- package/src/commands/apply/apply-engine.ts +1603 -0
- package/src/commands/apply/apply-parse.ts +1209 -0
- package/src/commands/apply/apply-types.ts +112 -0
- package/src/commands/apply/index.ts +5 -0
- package/src/commands/apply/latin1.ts +171 -0
- package/src/commands/apply/whitespace.ts +260 -0
- package/src/commands/attributes-source.ts +96 -0
- package/src/commands/backfill-command.ts +694 -0
- package/src/commands/bisect/bisect-checkout.ts +217 -0
- package/src/commands/bisect/bisect-command.ts +788 -0
- package/src/commands/bisect/bisect-engine.ts +1079 -0
- package/src/commands/bisect/bisect-graph.ts +595 -0
- package/src/commands/bisect/bisect-quote.ts +92 -0
- package/src/commands/bisect/index.ts +4 -0
- package/src/commands/blame-command.ts +711 -986
- package/src/commands/branch-command.ts +354 -32
- package/src/commands/branch-tracking.ts +331 -0
- package/src/commands/checkout-command.ts +1290 -243
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +504 -156
- package/src/commands/clone-command.ts +634 -67
- package/src/commands/commit-command.ts +1781 -166
- package/src/commands/core-config.ts +161 -6
- package/src/commands/date-format.ts +668 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1898 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +606 -66
- package/src/commands/format-patch-command.ts +969 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3347 -0
- package/src/commands/fsck/fsck-loose.ts +287 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1044 -0
- package/src/commands/fsck/fsck-object-table.ts +363 -0
- package/src/commands/fsck/fsck-pack.ts +604 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +249 -0
- package/src/commands/gc-command.ts +147 -1
- package/src/commands/git-date.ts +895 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1472 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +706 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +82 -0
- package/src/commands/init-command.ts +28 -4
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1915 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +101 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1386 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1198 -0
- package/src/commands/message-cleanup.ts +275 -0
- package/src/commands/mv-command.ts +976 -0
- package/src/commands/notes-command.ts +890 -0
- package/src/commands/notes-commands.ts +87 -0
- package/src/commands/notes-merge-command.ts +768 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +602 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +377 -0
- package/src/commands/ort-merge.ts +1660 -0
- package/src/commands/ort-recursive.ts +160 -0
- package/src/commands/pack-refs-command.ts +39 -22
- package/src/commands/patch-id.ts +196 -0
- package/src/commands/pathspec-attributes.ts +162 -0
- package/src/commands/pathspec.ts +1199 -0
- package/src/commands/post-index-change.ts +62 -0
- package/src/commands/pretty-format.ts +1431 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +207 -22
- package/src/commands/push-command.ts +236 -23
- package/src/commands/read-tree-command.ts +857 -0
- package/src/commands/rebase-command.ts +3808 -371
- package/src/commands/rebase-todo.ts +584 -0
- package/src/commands/ref-decoration-filter.ts +118 -0
- package/src/commands/reflog-messages.ts +177 -0
- package/src/commands/remote-command.ts +93 -22
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +827 -103
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +277 -0
- package/src/commands/revert-command.ts +152 -399
- package/src/commands/revision-filenames.ts +254 -0
- package/src/commands/revision-range.ts +222 -0
- package/src/commands/revision-resolver.ts +1379 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +869 -0
- package/src/commands/sequencer-support.ts +869 -0
- package/src/commands/serve-repository.ts +125 -0
- package/src/commands/sparse-checkout-command.ts +1389 -0
- package/src/commands/sparse-checkout-support.ts +793 -0
- package/src/commands/stash-apply-command.ts +376 -343
- package/src/commands/stash-create-command.ts +625 -42
- package/src/commands/stash-drop-command.ts +15 -2
- package/src/commands/stash-working-tree.ts +168 -24
- package/src/commands/status-command.ts +1328 -105
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +330 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +334 -0
- package/src/commands/submodule-summary.ts +446 -0
- package/src/commands/switch-command.ts +402 -0
- package/src/commands/tag-command.ts +129 -41
- package/src/commands/tracking-info.ts +201 -0
- package/src/commands/trailers.ts +417 -0
- package/src/commands/tree-restore.ts +204 -4
- package/src/commands/untracked-cache-support.ts +194 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +208 -0
- package/src/commands/worktree-lock-command.ts +96 -0
- package/src/commands/worktree-overwrite-checks.ts +452 -26
- package/src/commands/worktree-prune-command.ts +99 -0
- package/src/commands/worktree-remove-command.ts +186 -0
- package/src/commands/worktree-repair-command.ts +59 -0
- package/src/commands/worktree-support.ts +214 -0
- package/src/core-commands/add.command.impl.ts +7 -1
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +26 -2
- package/src/errors/command-errors.ts +101 -1
- package/src/errors/commit-errors.ts +18 -2
- package/src/errors/git-api-error.ts +82 -2
- package/src/errors/index.ts +1 -0
- package/src/errors/merge-errors.ts +2 -2
- package/src/errors/rebase-errors.ts +12 -0
- package/src/errors/ref-errors.ts +56 -2
- package/src/errors/remote-errors.ts +2 -2
- package/src/errors/stash-errors.ts +1 -1
- package/src/errors/transport-errors.ts +20 -4
- package/src/errors/worktree-errors.ts +49 -0
- package/src/git-command.ts +1177 -118
- package/src/git.ts +523 -10
- package/src/index.ts +1 -1
- package/src/remote-config/remote-config-store.ts +242 -8
- package/src/remote-config/remote-refs.ts +22 -6
- package/src/rename/detect-renames.ts +711 -0
- package/src/rename/git-similarity.ts +116 -0
- package/src/rename/index.ts +2 -0
- package/src/results/binary-patch.ts +401 -0
- package/src/results/blame-format.ts +239 -0
- package/src/results/cherry-pick-result.ts +10 -0
- package/src/results/clone-result.ts +12 -0
- package/src/results/combined-diff.ts +585 -0
- package/src/results/diff-entry.ts +35 -0
- package/src/results/diff-formatter.ts +152 -288
- package/src/results/diff-order.ts +64 -0
- package/src/results/diff-output.ts +1051 -0
- package/src/results/fetch-result.ts +15 -0
- package/src/results/index.ts +5 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +12 -3
- package/src/results/push-result.ts +43 -0
- package/src/results/quote-path.ts +103 -0
- package/src/results/rebase-result.ts +37 -0
- package/src/results/revert-result.ts +10 -0
- package/src/results/stash-result.ts +6 -0
- package/src/results/status-result.ts +123 -45
- package/src/transport-command.ts +121 -2
- package/dist/commands-CsLNyvZ1.js +0 -12587
- package/dist/status-result-BpyUK1Sg.js +0 -519
|
@@ -0,0 +1,1209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The patch reader of `git apply` (apply.c): finds each file's header (git diffs with their
|
|
3
|
+
* extended headers, or traditional `---`/`+++` pairs), its hunks and binary hunks, and
|
|
4
|
+
* records whitespace errors on the lines it adds. A port of git's parser: what it accepts,
|
|
5
|
+
* guesses and complains about (with git's messages) follows apply.c line by line.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createInflater } from "@statewalker/vcs-utils";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
BINARY_DELTA,
|
|
12
|
+
BINARY_LITERAL,
|
|
13
|
+
canonMode,
|
|
14
|
+
type FilePatch,
|
|
15
|
+
isLink,
|
|
16
|
+
type PatchFragment,
|
|
17
|
+
type WsErrorAction,
|
|
18
|
+
} from "./apply-types.js";
|
|
19
|
+
import { bytesToLatin1, cQuote, cUnquote, latin1ToBytes } from "./latin1.js";
|
|
20
|
+
import {
|
|
21
|
+
isGitSpace,
|
|
22
|
+
WS_CR_AT_EOL,
|
|
23
|
+
WS_INCOMPLETE_LINE,
|
|
24
|
+
whitespaceErrorString,
|
|
25
|
+
wsCheck,
|
|
26
|
+
} from "./whitespace.js";
|
|
27
|
+
|
|
28
|
+
const TERM_SPACE = 1;
|
|
29
|
+
const TERM_TAB = 2;
|
|
30
|
+
|
|
31
|
+
/** Verbosity: -1 quiet, 0 normal, 1 verbose. */
|
|
32
|
+
export type ApplyVerbosity = -1 | 0 | 1;
|
|
33
|
+
|
|
34
|
+
const isDigit = (c: string | undefined) => c !== undefined && c >= "0" && c <= "9";
|
|
35
|
+
const isSpaceCh = (c: string | undefined) => c !== undefined && isGitSpace(c.charCodeAt(0));
|
|
36
|
+
|
|
37
|
+
/** `linelen`: bytes up to and including the next LF, at most `size`. */
|
|
38
|
+
export function linelen(buf: string, at: number, size: number): number {
|
|
39
|
+
if (size <= 0) return 0;
|
|
40
|
+
const nl = buf.indexOf("\n", at);
|
|
41
|
+
if (nl < 0 || nl - at + 1 > size) return Math.min(size, buf.length - at);
|
|
42
|
+
return nl - at + 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isDevNull(buf: string, at: number): boolean {
|
|
46
|
+
return buf.startsWith("/dev/null", at) && isSpaceCh(buf[at + 9]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function squashSlash(name: string | null): string | null {
|
|
50
|
+
if (name === null) return null;
|
|
51
|
+
return name.replace(/\/\/+/g, "/");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** strtoul in base `radix` from `at`: the value and where it stopped. */
|
|
55
|
+
function strtoul(buf: string, at: number, radix: number): { value: number; end: number } {
|
|
56
|
+
let i = at;
|
|
57
|
+
while (buf[i] === " " || buf[i] === "\t") i++;
|
|
58
|
+
if (buf[i] === "+") i++;
|
|
59
|
+
let value = 0;
|
|
60
|
+
const start = i;
|
|
61
|
+
for (;;) {
|
|
62
|
+
const c = buf[i];
|
|
63
|
+
if (c === undefined) break;
|
|
64
|
+
const d = Number.parseInt(c, radix);
|
|
65
|
+
if (Number.isNaN(d) || (radix === 10 && !isDigit(c))) break;
|
|
66
|
+
value = value * radix + d;
|
|
67
|
+
i++;
|
|
68
|
+
}
|
|
69
|
+
return i === start ? { value: 0, end: at } : { value, end: i };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function sizeOfTz(line: string, len: number): number {
|
|
73
|
+
const n = 6; // " +0500"
|
|
74
|
+
if (len < n || line[len - n] !== " ") return 0;
|
|
75
|
+
const tz = len - n;
|
|
76
|
+
if (line[tz + 1] !== "+" && line[tz + 1] !== "-") return 0;
|
|
77
|
+
for (let p = tz + 2; p !== len; p++) if (!isDigit(line[p])) return 0;
|
|
78
|
+
return len - tz;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function tzWithColonLen(line: string, len: number): number {
|
|
82
|
+
if (len < 7 || line[len - 3] !== ":") return 0;
|
|
83
|
+
const tz = len - 7;
|
|
84
|
+
if (line[tz] !== " " || (line[tz + 1] !== "+" && line[tz + 1] !== "-")) return 0;
|
|
85
|
+
let p = tz + 2;
|
|
86
|
+
if (
|
|
87
|
+
!isDigit(line[p++]) ||
|
|
88
|
+
!isDigit(line[p++]) ||
|
|
89
|
+
line[p++] !== ":" ||
|
|
90
|
+
!isDigit(line[p++]) ||
|
|
91
|
+
!isDigit(line[p++])
|
|
92
|
+
)
|
|
93
|
+
return 0;
|
|
94
|
+
return len - tz;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function dateLen(line: string, len: number): number {
|
|
98
|
+
if (len < 8 || line[len - 3] !== "-") return 0;
|
|
99
|
+
let date = len - 8;
|
|
100
|
+
let p = date;
|
|
101
|
+
if (
|
|
102
|
+
!isDigit(line[p++]) ||
|
|
103
|
+
!isDigit(line[p++]) ||
|
|
104
|
+
line[p++] !== "-" ||
|
|
105
|
+
!isDigit(line[p++]) ||
|
|
106
|
+
!isDigit(line[p++]) ||
|
|
107
|
+
line[p++] !== "-" ||
|
|
108
|
+
!isDigit(line[p++]) ||
|
|
109
|
+
!isDigit(line[p++])
|
|
110
|
+
)
|
|
111
|
+
return 0;
|
|
112
|
+
if (date >= 2 && isDigit(line[date - 1]) && isDigit(line[date - 2])) date -= 2;
|
|
113
|
+
return len - date;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function shortTimeLen(line: string, len: number): number {
|
|
117
|
+
if (len < 9 || line[len - 3] !== ":") return 0;
|
|
118
|
+
const time = len - 9;
|
|
119
|
+
let p = time;
|
|
120
|
+
if (
|
|
121
|
+
line[p++] !== " " ||
|
|
122
|
+
!isDigit(line[p++]) ||
|
|
123
|
+
!isDigit(line[p++]) ||
|
|
124
|
+
line[p++] !== ":" ||
|
|
125
|
+
!isDigit(line[p++]) ||
|
|
126
|
+
!isDigit(line[p++]) ||
|
|
127
|
+
line[p++] !== ":" ||
|
|
128
|
+
!isDigit(line[p++]) ||
|
|
129
|
+
!isDigit(line[p++])
|
|
130
|
+
)
|
|
131
|
+
return 0;
|
|
132
|
+
return len - time;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function fractionalTimeLen(line: string, len: number): number {
|
|
136
|
+
if (!len || !isDigit(line[len - 1])) return 0;
|
|
137
|
+
let p = len - 1;
|
|
138
|
+
while (p > 0 && isDigit(line[p])) p--;
|
|
139
|
+
if (line[p] !== ".") return 0;
|
|
140
|
+
const n = shortTimeLen(line, p);
|
|
141
|
+
if (!n) return 0;
|
|
142
|
+
return len - p + n;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function trailingSpacesLen(line: string, len: number): number {
|
|
146
|
+
if (!len || line[len - 1] !== " ") return 0;
|
|
147
|
+
let p = len;
|
|
148
|
+
while (p !== 0) {
|
|
149
|
+
p--;
|
|
150
|
+
if (line[p] !== " ") return len - (p + 1);
|
|
151
|
+
}
|
|
152
|
+
return len;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** `diff_timestamp_len`: the length of a diff's date after a name, 0 when there is none. */
|
|
156
|
+
function diffTimestampLen(line: string, len: number): number {
|
|
157
|
+
let end = len;
|
|
158
|
+
if (!isDigit(line[end - 1])) return 0;
|
|
159
|
+
let n = sizeOfTz(line, end);
|
|
160
|
+
if (!n) n = tzWithColonLen(line, end);
|
|
161
|
+
end -= n;
|
|
162
|
+
n = shortTimeLen(line, end);
|
|
163
|
+
if (!n) n = fractionalTimeLen(line, end);
|
|
164
|
+
end -= n;
|
|
165
|
+
n = dateLen(line, end);
|
|
166
|
+
if (!n) return 0;
|
|
167
|
+
end -= n;
|
|
168
|
+
if (end === 0) return 0;
|
|
169
|
+
if (line[end - 1] === "\t") {
|
|
170
|
+
end--;
|
|
171
|
+
return len - end;
|
|
172
|
+
}
|
|
173
|
+
if (line[end - 1] !== " ") return 0;
|
|
174
|
+
end -= trailingSpacesLen(line, end);
|
|
175
|
+
return len - end;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function hasEpochTimestamp(buf: string, at: number): boolean {
|
|
179
|
+
let timestamp = -1;
|
|
180
|
+
let cp = at;
|
|
181
|
+
for (; buf[cp] !== "\n" && cp < buf.length; cp++) if (buf[cp] === "\t") timestamp = cp + 1;
|
|
182
|
+
if (timestamp < 0) return false;
|
|
183
|
+
let epochHour: number;
|
|
184
|
+
let rest = buf.slice(timestamp, buf.indexOf("\n", timestamp) + 1 || undefined);
|
|
185
|
+
if (rest.startsWith("1969-12-31 ")) epochHour = 24;
|
|
186
|
+
else if (rest.startsWith("1970-01-01 ")) epochHour = 0;
|
|
187
|
+
else return false;
|
|
188
|
+
rest = rest.slice(11);
|
|
189
|
+
const m = /^([0-2][0-9]):([0-5][0-9]):00(\.0+)? ([-+])([0-2][0-9]):?([0-5][0-9])\n/.exec(rest);
|
|
190
|
+
if (!m) return false;
|
|
191
|
+
const hour = Number(m[1]);
|
|
192
|
+
const minute = Number(m[2]);
|
|
193
|
+
let zone = Number(m[5]) * 60 + Number(m[6]);
|
|
194
|
+
if (m[4] === "-") zone = -zone;
|
|
195
|
+
return hour * 60 + minute - zone === epochHour * 60;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function skipTreePrefix(pValue: number, line: string, at: number, llen: number): number {
|
|
199
|
+
if (!pValue) return llen && line[at] === "/" ? -1 : at;
|
|
200
|
+
let nslash = pValue;
|
|
201
|
+
for (let i = 0; i < llen; i++) {
|
|
202
|
+
if (line[at + i] === "/" && --nslash <= 0) return i === 0 ? -1 : at + i + 1;
|
|
203
|
+
}
|
|
204
|
+
return -1;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** `git_header_name`: the name the `diff --git` line names twice, when it does. */
|
|
208
|
+
function gitHeaderName(pValue: number, buf: string, lineAt: number, llen0: number): string | null {
|
|
209
|
+
const line = lineAt + 11;
|
|
210
|
+
const llen = llen0 - 11;
|
|
211
|
+
const lineEnd = line + llen;
|
|
212
|
+
if (buf[line] === '"') {
|
|
213
|
+
const first = cUnquote(buf, line);
|
|
214
|
+
if (!first) return null;
|
|
215
|
+
let cp = skipTreePrefix(pValue, first.name, 0, first.name.length);
|
|
216
|
+
if (cp < 0) return null;
|
|
217
|
+
const firstName = first.name.slice(cp);
|
|
218
|
+
let second = first.end;
|
|
219
|
+
while (second < lineEnd && isSpaceCh(buf[second])) second++;
|
|
220
|
+
if (lineEnd <= second) return null;
|
|
221
|
+
if (buf[second] === '"') {
|
|
222
|
+
const sp = cUnquote(buf, second);
|
|
223
|
+
if (!sp) return null;
|
|
224
|
+
cp = skipTreePrefix(pValue, sp.name, 0, sp.name.length);
|
|
225
|
+
if (cp < 0) return null;
|
|
226
|
+
if (sp.name.slice(cp) !== firstName) return null;
|
|
227
|
+
return firstName;
|
|
228
|
+
}
|
|
229
|
+
cp = skipTreePrefix(pValue, buf, second, lineEnd - second);
|
|
230
|
+
if (cp < 0) return null;
|
|
231
|
+
if (lineEnd - cp !== firstName.length || buf.slice(cp, lineEnd) !== firstName) return null;
|
|
232
|
+
return firstName;
|
|
233
|
+
}
|
|
234
|
+
const name = skipTreePrefix(pValue, buf, line, llen);
|
|
235
|
+
if (name < 0) return null;
|
|
236
|
+
for (let second = name; second < lineEnd; second++) {
|
|
237
|
+
if (buf[second] === '"') {
|
|
238
|
+
const sp = cUnquote(buf, second);
|
|
239
|
+
if (!sp) return null;
|
|
240
|
+
const np = skipTreePrefix(pValue, sp.name, 0, sp.name.length);
|
|
241
|
+
if (np < 0) return null;
|
|
242
|
+
const len = sp.name.length - np;
|
|
243
|
+
if (
|
|
244
|
+
len < second - name &&
|
|
245
|
+
buf.slice(name, name + len) === sp.name.slice(np) &&
|
|
246
|
+
isSpaceCh(buf[name + len])
|
|
247
|
+
) {
|
|
248
|
+
return sp.name.slice(np);
|
|
249
|
+
}
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const nl = buf.indexOf("\n", name);
|
|
254
|
+
if (nl < 0) return null;
|
|
255
|
+
const lineLen = nl - name;
|
|
256
|
+
for (let len = 0; ; len++) {
|
|
257
|
+
const c = buf[name + len];
|
|
258
|
+
if (c === "\n" || c === undefined) return null;
|
|
259
|
+
if (c === "\t" || c === " ") {
|
|
260
|
+
if (buf[name + len + 1] === undefined) return null;
|
|
261
|
+
const second = skipTreePrefix(pValue, buf, name + len + 1, lineLen - (len + 1));
|
|
262
|
+
if (second < 0) continue;
|
|
263
|
+
if (
|
|
264
|
+
buf[second + len] === "\n" &&
|
|
265
|
+
buf.slice(name, name + len) === buf.slice(second, second + len)
|
|
266
|
+
)
|
|
267
|
+
return buf.slice(name, name + len);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Options and state the reader shares with the applier (apply.c's `apply_state`). */
|
|
273
|
+
export class ApplyParser {
|
|
274
|
+
root = "";
|
|
275
|
+
pValue = 1;
|
|
276
|
+
pValueKnown = false;
|
|
277
|
+
linenr = 1;
|
|
278
|
+
patchInputFile = "<stdin>";
|
|
279
|
+
/** git before 2.46 named lines without the patch file ("corrupt patch at line 5") */
|
|
280
|
+
legacyMessages = false;
|
|
281
|
+
applyInReverse = false;
|
|
282
|
+
wsErrorAction: WsErrorAction = "warn";
|
|
283
|
+
squelchWhitespaceErrors = 5;
|
|
284
|
+
whitespaceError = 0;
|
|
285
|
+
verbosity: ApplyVerbosity = 0;
|
|
286
|
+
apply = true;
|
|
287
|
+
check = false;
|
|
288
|
+
limitByName: { pattern: string; include: boolean }[] = [];
|
|
289
|
+
hasInclude = false;
|
|
290
|
+
quotePathFully = true;
|
|
291
|
+
stderr = "";
|
|
292
|
+
stdout = "";
|
|
293
|
+
|
|
294
|
+
error(message: string): number {
|
|
295
|
+
if (this.verbosity > -1) this.stderr += vreportf("error: ", message);
|
|
296
|
+
return -1;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
warning(message: string): void {
|
|
300
|
+
if (this.verbosity > -1) this.stderr += vreportf("warning: ", message);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* `inflate_it`: the data inflated into exactly `size` bytes, undefined otherwise; a
|
|
305
|
+
* corrupt stream reports zlib's error as `git_inflate` does.
|
|
306
|
+
*/
|
|
307
|
+
private inflateIt(data: Uint8Array, size: number): Uint8Array | undefined {
|
|
308
|
+
const inflater = createInflater();
|
|
309
|
+
let out: Uint8Array[];
|
|
310
|
+
let done: boolean;
|
|
311
|
+
try {
|
|
312
|
+
({ out, done } = inflater.push(data));
|
|
313
|
+
} catch (error) {
|
|
314
|
+
const message = (error as Error).message ?? "";
|
|
315
|
+
if (message.includes("preset dictionary"))
|
|
316
|
+
this.error("inflate: needs dictionary (no message)");
|
|
317
|
+
else if (message.startsWith("inflate failed: "))
|
|
318
|
+
this.error(`inflate: data stream error (${message.slice(16)})`);
|
|
319
|
+
return undefined;
|
|
320
|
+
} finally {
|
|
321
|
+
inflater.abort();
|
|
322
|
+
}
|
|
323
|
+
if (!done) return undefined;
|
|
324
|
+
let total = 0;
|
|
325
|
+
for (const o of out) total += o.length;
|
|
326
|
+
if (total !== size) return undefined;
|
|
327
|
+
const result = new Uint8Array(total);
|
|
328
|
+
let at = 0;
|
|
329
|
+
for (const o of out) {
|
|
330
|
+
result.set(o, at);
|
|
331
|
+
at += o.length;
|
|
332
|
+
}
|
|
333
|
+
return result;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** "at <file>:<line>" (git 2.46+) or "<legacy> <line>" ("on line 5", "at line 5"). */
|
|
337
|
+
protected at(linenr: number, legacy = "at line"): string {
|
|
338
|
+
return this.legacyMessages ? `${legacy} ${linenr}` : `at ${this.patchInputFile}:${linenr}`;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
protected quote(name: string): string {
|
|
342
|
+
return cQuote(name, this.quotePathFully);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** `use_patch`: whether --include/--exclude keep the patch. */
|
|
346
|
+
usePatch(p: FilePatch, wildmatch: (pattern: string, text: string) => boolean): boolean {
|
|
347
|
+
const pathname = (p.newName ?? p.oldName) as string;
|
|
348
|
+
for (const it of this.limitByName) {
|
|
349
|
+
if (wildmatch(it.pattern, pathname)) return it.include;
|
|
350
|
+
}
|
|
351
|
+
return !this.hasInclude;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
private findNameGnu(buf: string, at: number, pValue: number): string | null {
|
|
355
|
+
const q = cUnquote(buf, at);
|
|
356
|
+
if (!q) return null;
|
|
357
|
+
let cp = 0;
|
|
358
|
+
for (; pValue; pValue--) {
|
|
359
|
+
const s = q.name.indexOf("/", cp);
|
|
360
|
+
if (s < 0) return null;
|
|
361
|
+
cp = s + 1;
|
|
362
|
+
}
|
|
363
|
+
return squashSlash(this.root + q.name.slice(cp));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
private findNameCommon(
|
|
367
|
+
buf: string,
|
|
368
|
+
at: number,
|
|
369
|
+
def: string | null,
|
|
370
|
+
pValue: number,
|
|
371
|
+
end: number,
|
|
372
|
+
terminate: number,
|
|
373
|
+
): string | null {
|
|
374
|
+
let line = at;
|
|
375
|
+
let start = -1;
|
|
376
|
+
if (pValue === 0) start = line;
|
|
377
|
+
while (line !== end) {
|
|
378
|
+
const c = buf[line];
|
|
379
|
+
if (c === undefined) break;
|
|
380
|
+
if (end < 0 && isSpaceCh(c)) {
|
|
381
|
+
if (c === "\n") break;
|
|
382
|
+
if (!(c === " " && !(terminate & TERM_SPACE)) && !(c === "\t" && !(terminate & TERM_TAB)))
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
line++;
|
|
386
|
+
if (c === "/" && !--pValue) start = line;
|
|
387
|
+
}
|
|
388
|
+
if (start < 0) return squashSlash(def);
|
|
389
|
+
const len = line - start;
|
|
390
|
+
if (!len) return squashSlash(def);
|
|
391
|
+
if (def !== null) {
|
|
392
|
+
if (def.length < len && buf.startsWith(def, start)) return squashSlash(def);
|
|
393
|
+
}
|
|
394
|
+
return squashSlash(this.root + buf.slice(start, start + len));
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
private findName(
|
|
398
|
+
buf: string,
|
|
399
|
+
at: number,
|
|
400
|
+
def: string | null,
|
|
401
|
+
pValue: number,
|
|
402
|
+
terminate: number,
|
|
403
|
+
): string | null {
|
|
404
|
+
if (buf[at] === '"') {
|
|
405
|
+
const name = this.findNameGnu(buf, at, pValue);
|
|
406
|
+
if (name !== null) return name;
|
|
407
|
+
}
|
|
408
|
+
return this.findNameCommon(buf, at, def, pValue, -1, terminate);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
private findNameTraditional(
|
|
412
|
+
buf: string,
|
|
413
|
+
at: number,
|
|
414
|
+
def: string | null,
|
|
415
|
+
pValue: number,
|
|
416
|
+
): string | null {
|
|
417
|
+
if (buf[at] === '"') {
|
|
418
|
+
const name = this.findNameGnu(buf, at, pValue);
|
|
419
|
+
if (name !== null) return name;
|
|
420
|
+
}
|
|
421
|
+
let nl = buf.indexOf("\n", at);
|
|
422
|
+
if (nl < 0) nl = buf.length;
|
|
423
|
+
let len = nl - at;
|
|
424
|
+
const line = buf.slice(at, nl);
|
|
425
|
+
const dl = diffTimestampLen(line, len);
|
|
426
|
+
if (!dl) return this.findNameCommon(buf, at, def, pValue, -1, TERM_TAB);
|
|
427
|
+
len -= dl;
|
|
428
|
+
return this.findNameCommon(buf, at, def, pValue, at + len, 0);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
private guessPValue(buf: string, at: number): number {
|
|
432
|
+
if (isDevNull(buf, at)) return -1;
|
|
433
|
+
const name = this.findNameTraditional(buf, at, null, 0);
|
|
434
|
+
if (name === null) return -1;
|
|
435
|
+
return name.includes("/") ? -1 : 0;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
private parseTraditionalPatch(
|
|
439
|
+
buf: string,
|
|
440
|
+
first: number,
|
|
441
|
+
second: number,
|
|
442
|
+
patch: FilePatch,
|
|
443
|
+
): number {
|
|
444
|
+
first += 4;
|
|
445
|
+
second += 4;
|
|
446
|
+
if (!this.pValueKnown) {
|
|
447
|
+
let p = this.guessPValue(buf, first);
|
|
448
|
+
const q = this.guessPValue(buf, second);
|
|
449
|
+
if (p < 0) p = q;
|
|
450
|
+
if (0 <= p && p === q) {
|
|
451
|
+
this.pValue = p;
|
|
452
|
+
this.pValueKnown = true;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
let name: string | null;
|
|
456
|
+
if (isDevNull(buf, first)) {
|
|
457
|
+
patch.isNew = 1;
|
|
458
|
+
patch.isDelete = 0;
|
|
459
|
+
name = this.findNameTraditional(buf, second, null, this.pValue);
|
|
460
|
+
patch.newName = name;
|
|
461
|
+
} else if (isDevNull(buf, second)) {
|
|
462
|
+
patch.isNew = 0;
|
|
463
|
+
patch.isDelete = 1;
|
|
464
|
+
name = this.findNameTraditional(buf, first, null, this.pValue);
|
|
465
|
+
patch.oldName = name;
|
|
466
|
+
} else {
|
|
467
|
+
const firstName = this.findNameTraditional(buf, first, null, this.pValue);
|
|
468
|
+
name = this.findNameTraditional(buf, second, firstName, this.pValue);
|
|
469
|
+
if (hasEpochTimestamp(buf, first)) {
|
|
470
|
+
patch.isNew = 1;
|
|
471
|
+
patch.isDelete = 0;
|
|
472
|
+
patch.newName = name;
|
|
473
|
+
} else if (hasEpochTimestamp(buf, second)) {
|
|
474
|
+
patch.isNew = 0;
|
|
475
|
+
patch.isDelete = 1;
|
|
476
|
+
patch.oldName = name;
|
|
477
|
+
} else {
|
|
478
|
+
patch.oldName = name;
|
|
479
|
+
patch.newName = name;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (name === null)
|
|
483
|
+
return this.error(`unable to find filename in patch ${this.at(this.linenr)}`);
|
|
484
|
+
return 0;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
private verifyName(
|
|
488
|
+
buf: string,
|
|
489
|
+
at: number,
|
|
490
|
+
isNull: boolean,
|
|
491
|
+
side: "old" | "new",
|
|
492
|
+
patch: FilePatch,
|
|
493
|
+
linenr: number,
|
|
494
|
+
): number {
|
|
495
|
+
const key = side === "old" ? "oldName" : "newName";
|
|
496
|
+
const current = patch[key];
|
|
497
|
+
if (current === null && !isNull) {
|
|
498
|
+
patch[key] = this.findName(buf, at, null, this.pValue, TERM_TAB);
|
|
499
|
+
return 0;
|
|
500
|
+
}
|
|
501
|
+
if (current !== null) {
|
|
502
|
+
if (isNull) {
|
|
503
|
+
return this.error(
|
|
504
|
+
`git apply: bad git-diff - expected /dev/null, got ${current} ${this.at(linenr, "on line")}`,
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
const another = this.findName(buf, at, null, this.pValue, TERM_TAB);
|
|
508
|
+
if (another === null || another !== current) {
|
|
509
|
+
return this.error(
|
|
510
|
+
`git apply: bad git-diff - inconsistent ${side} filename ${this.at(linenr, "on line")}`,
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
} else if (!isDevNull(buf, at)) {
|
|
514
|
+
return this.error(
|
|
515
|
+
`git apply: bad git-diff - expected /dev/null ${this.at(linenr, "on line")}`,
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
return 0;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
private parseModeLine(buf: string, at: number, linenr: number): number {
|
|
522
|
+
const { value, end } = strtoul(buf, at, 8);
|
|
523
|
+
if (end === at || !isSpaceCh(buf[end])) {
|
|
524
|
+
// git prints the rest of the patch: the line is not cut at its end
|
|
525
|
+
const nul = buf.indexOf("\0", at);
|
|
526
|
+
const line = buf.slice(at, nul < 0 ? undefined : nul);
|
|
527
|
+
if (this.legacyMessages) this.error(`invalid mode on line ${linenr}: ${line}`);
|
|
528
|
+
else this.error(`invalid mode at ${this.patchInputFile}:${linenr}: ${line}`);
|
|
529
|
+
return -1;
|
|
530
|
+
}
|
|
531
|
+
return canonMode(value);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
private checkHeaderLine(linenr: number, patch: FilePatch): number {
|
|
535
|
+
const extensions =
|
|
536
|
+
(patch.isDelete === 1 ? 1 : 0) +
|
|
537
|
+
(patch.isNew === 1 ? 1 : 0) +
|
|
538
|
+
(patch.isRename ? 1 : 0) +
|
|
539
|
+
(patch.isCopy ? 1 : 0);
|
|
540
|
+
if (extensions > 1)
|
|
541
|
+
return this.error(`inconsistent header lines ${patch.extensionLinenr} and ${linenr}`);
|
|
542
|
+
if (extensions && !patch.extensionLinenr) patch.extensionLinenr = linenr;
|
|
543
|
+
return 0;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** One extended header line; 1 ends the header, -1 fails. */
|
|
547
|
+
private gitdiffLine(
|
|
548
|
+
buf: string,
|
|
549
|
+
at: number,
|
|
550
|
+
len: number,
|
|
551
|
+
patch: FilePatch,
|
|
552
|
+
linenr: number,
|
|
553
|
+
): number {
|
|
554
|
+
const p = this.pValue;
|
|
555
|
+
const sub = p ? p - 1 : 0;
|
|
556
|
+
const mode = (off: number, set: (m: number) => void) => {
|
|
557
|
+
const m = this.parseModeLine(buf, at + off, linenr);
|
|
558
|
+
if (m < 0) return -1;
|
|
559
|
+
set(m);
|
|
560
|
+
return 0;
|
|
561
|
+
};
|
|
562
|
+
const starts = (s: string) => len >= s.length && buf.startsWith(s, at);
|
|
563
|
+
if (starts("@@ -")) return 1;
|
|
564
|
+
if (starts("--- "))
|
|
565
|
+
return this.verifyName(buf, at + 4, patch.isNew === 1, "old", patch, linenr);
|
|
566
|
+
if (starts("+++ "))
|
|
567
|
+
return this.verifyName(buf, at + 4, patch.isDelete === 1, "new", patch, linenr);
|
|
568
|
+
if (starts("old mode ")) return mode(9, (m) => (patch.oldMode = m));
|
|
569
|
+
if (starts("new mode ")) return mode(9, (m) => (patch.newMode = m));
|
|
570
|
+
if (starts("deleted file mode ")) {
|
|
571
|
+
patch.isDelete = 1;
|
|
572
|
+
patch.oldName = patch.defName;
|
|
573
|
+
return mode(18, (m) => (patch.oldMode = m));
|
|
574
|
+
}
|
|
575
|
+
if (starts("new file mode ")) {
|
|
576
|
+
patch.isNew = 1;
|
|
577
|
+
patch.newName = patch.defName;
|
|
578
|
+
return mode(14, (m) => (patch.newMode = m));
|
|
579
|
+
}
|
|
580
|
+
if (starts("copy from ")) {
|
|
581
|
+
patch.isCopy = true;
|
|
582
|
+
patch.oldName = this.findName(buf, at + 10, null, sub, 0);
|
|
583
|
+
return 0;
|
|
584
|
+
}
|
|
585
|
+
if (starts("copy to ")) {
|
|
586
|
+
patch.isCopy = true;
|
|
587
|
+
patch.newName = this.findName(buf, at + 8, null, sub, 0);
|
|
588
|
+
return 0;
|
|
589
|
+
}
|
|
590
|
+
if (starts("rename old ")) {
|
|
591
|
+
patch.isRename = true;
|
|
592
|
+
patch.oldName = this.findName(buf, at + 11, null, sub, 0);
|
|
593
|
+
return 0;
|
|
594
|
+
}
|
|
595
|
+
if (starts("rename new ")) {
|
|
596
|
+
patch.isRename = true;
|
|
597
|
+
patch.newName = this.findName(buf, at + 11, null, sub, 0);
|
|
598
|
+
return 0;
|
|
599
|
+
}
|
|
600
|
+
if (starts("rename from ")) {
|
|
601
|
+
patch.isRename = true;
|
|
602
|
+
patch.oldName = this.findName(buf, at + 12, null, sub, 0);
|
|
603
|
+
return 0;
|
|
604
|
+
}
|
|
605
|
+
if (starts("rename to ")) {
|
|
606
|
+
patch.isRename = true;
|
|
607
|
+
patch.newName = this.findName(buf, at + 10, null, sub, 0);
|
|
608
|
+
return 0;
|
|
609
|
+
}
|
|
610
|
+
if (starts("similarity index ") || starts("dissimilarity index ")) {
|
|
611
|
+
const off = starts("similarity index ") ? 17 : 20;
|
|
612
|
+
const { value } = strtoul(buf, at + off, 10);
|
|
613
|
+
if (value <= 100) patch.score = value;
|
|
614
|
+
return 0;
|
|
615
|
+
}
|
|
616
|
+
if (starts("index ")) {
|
|
617
|
+
const line = at + 6;
|
|
618
|
+
const dot = buf.indexOf(".", line);
|
|
619
|
+
const eol0 = buf.indexOf("\n", line);
|
|
620
|
+
const eol = eol0 < 0 ? buf.length : eol0;
|
|
621
|
+
if (dot < 0 || buf[dot + 1] !== "." || 40 < dot - line) return 0;
|
|
622
|
+
const oldPrefix = buf.slice(line, dot);
|
|
623
|
+
const l2 = dot + 2;
|
|
624
|
+
let ptr = buf.indexOf(" ", l2);
|
|
625
|
+
if (ptr < 0 || eol < ptr) ptr = eol;
|
|
626
|
+
if (40 < ptr - l2) return 0;
|
|
627
|
+
patch.oldOidPrefix = oldPrefix;
|
|
628
|
+
patch.newOidPrefix = buf.slice(l2, ptr);
|
|
629
|
+
if (buf[ptr] === " ") return mode(ptr + 1 - at, (m) => (patch.oldMode = m));
|
|
630
|
+
return 0;
|
|
631
|
+
}
|
|
632
|
+
return 1;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/** `parse_git_diff_header`: the header's length, or -128. */
|
|
636
|
+
private parseGitDiffHeader(
|
|
637
|
+
buf: string,
|
|
638
|
+
at: number,
|
|
639
|
+
len: number,
|
|
640
|
+
size: number,
|
|
641
|
+
patch: FilePatch,
|
|
642
|
+
): number {
|
|
643
|
+
patch.isNew = 0;
|
|
644
|
+
patch.isDelete = 0;
|
|
645
|
+
patch.defName = gitHeaderName(this.pValue, buf, at, len);
|
|
646
|
+
if (patch.defName !== null && this.root) patch.defName = this.root + patch.defName;
|
|
647
|
+
let line = at + len;
|
|
648
|
+
size -= len;
|
|
649
|
+
this.linenr++;
|
|
650
|
+
let offset = len;
|
|
651
|
+
for (; size > 0; offset += len, size -= len, line += len, this.linenr++) {
|
|
652
|
+
len = linelen(buf, line, size);
|
|
653
|
+
if (!len || buf[line + len - 1] !== "\n") break;
|
|
654
|
+
const res = this.gitdiffLine(buf, line, len, patch, this.linenr);
|
|
655
|
+
if (res < 0) return -1;
|
|
656
|
+
if (this.checkHeaderLine(this.linenr, patch)) return -1;
|
|
657
|
+
if (res > 0) break;
|
|
658
|
+
}
|
|
659
|
+
if (patch.oldName === null && patch.newName === null) {
|
|
660
|
+
if (patch.defName === null) {
|
|
661
|
+
const n = this.pValue;
|
|
662
|
+
const comp = n === 1 ? "component" : "components";
|
|
663
|
+
if (this.legacyMessages)
|
|
664
|
+
this.error(
|
|
665
|
+
`git diff header lacks filename information when removing ${n} leading pathname ${comp} (line ${this.linenr})`,
|
|
666
|
+
);
|
|
667
|
+
else
|
|
668
|
+
this.error(
|
|
669
|
+
`git diff header lacks filename information when removing ${n} leading pathname ${comp} at ${this.patchInputFile}:${this.linenr}`,
|
|
670
|
+
);
|
|
671
|
+
return -128;
|
|
672
|
+
}
|
|
673
|
+
patch.oldName = patch.defName;
|
|
674
|
+
patch.newName = patch.defName;
|
|
675
|
+
}
|
|
676
|
+
if ((patch.newName === null && !patch.isDelete) || (patch.oldName === null && !patch.isNew)) {
|
|
677
|
+
if (this.legacyMessages)
|
|
678
|
+
this.error(`git diff header lacks filename information (line ${this.linenr})`);
|
|
679
|
+
else
|
|
680
|
+
this.error(
|
|
681
|
+
`git diff header lacks filename information at ${this.patchInputFile}:${this.linenr}`,
|
|
682
|
+
);
|
|
683
|
+
return -128;
|
|
684
|
+
}
|
|
685
|
+
patch.isToplevelRelative = true;
|
|
686
|
+
return offset;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/** `find_header`: the header's offset (and `hdrsize`), -1 when none, -128 on error. */
|
|
690
|
+
private findHeader(
|
|
691
|
+
buf: string,
|
|
692
|
+
at: number,
|
|
693
|
+
size: number,
|
|
694
|
+
patch: FilePatch,
|
|
695
|
+
): { offset: number; hdrsize: number } {
|
|
696
|
+
patch.isToplevelRelative = false;
|
|
697
|
+
patch.isRename = patch.isCopy = false;
|
|
698
|
+
patch.isNew = patch.isDelete = -1;
|
|
699
|
+
patch.oldMode = patch.newMode = 0;
|
|
700
|
+
patch.oldName = patch.newName = null;
|
|
701
|
+
let len = 0;
|
|
702
|
+
for (
|
|
703
|
+
let offset = 0, line = at;
|
|
704
|
+
size > 0;
|
|
705
|
+
offset += len, size -= len, line += len, this.linenr++
|
|
706
|
+
) {
|
|
707
|
+
len = linelen(buf, line, size);
|
|
708
|
+
if (!len) break;
|
|
709
|
+
if (len < 6) continue;
|
|
710
|
+
if (buf.startsWith("@@ -", line)) {
|
|
711
|
+
const dummy = emptyFragment();
|
|
712
|
+
if (parseFragmentHeader(buf, line, len, dummy) < 0) continue;
|
|
713
|
+
const shown = buf.slice(line, line + len - 1);
|
|
714
|
+
if (this.legacyMessages)
|
|
715
|
+
this.error(`patch fragment without header at line ${this.linenr}: ${shown}`);
|
|
716
|
+
else
|
|
717
|
+
this.error(
|
|
718
|
+
`patch fragment without header at ${this.patchInputFile}:${this.linenr}: ${shown}`,
|
|
719
|
+
);
|
|
720
|
+
return { offset: -128, hdrsize: 0 };
|
|
721
|
+
}
|
|
722
|
+
if (size < len + 6) break;
|
|
723
|
+
if (buf.startsWith("diff --git ", line)) {
|
|
724
|
+
const git = this.parseGitDiffHeader(buf, line, len, size, patch);
|
|
725
|
+
if (git < 0) return { offset: -128, hdrsize: 0 };
|
|
726
|
+
if (git <= len) continue;
|
|
727
|
+
return { offset, hdrsize: git };
|
|
728
|
+
}
|
|
729
|
+
if (!buf.startsWith("--- ", line) || !buf.startsWith("+++ ", line + len)) continue;
|
|
730
|
+
const nextlen = linelen(buf, line + len, size - len);
|
|
731
|
+
if (size < nextlen + 14 || !buf.startsWith("@@ -", line + len + nextlen)) continue;
|
|
732
|
+
if (this.parseTraditionalPatch(buf, line, line + len, patch))
|
|
733
|
+
return { offset: -128, hdrsize: 0 };
|
|
734
|
+
this.linenr += 2;
|
|
735
|
+
return { offset, hdrsize: len + nextlen };
|
|
736
|
+
}
|
|
737
|
+
return { offset: -1, hdrsize: 0 };
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/** `record_ws_error`. */
|
|
741
|
+
protected recordWsError(result: number, line: string, linenr: number): void {
|
|
742
|
+
if (!result) return;
|
|
743
|
+
this.whitespaceError++;
|
|
744
|
+
if (this.squelchWhitespaceErrors && this.squelchWhitespaceErrors < this.whitespaceError) return;
|
|
745
|
+
const err = whitespaceErrorString(result);
|
|
746
|
+
if (this.verbosity > -1) this.stderr += `${this.patchInputFile}:${linenr}: ${err}.\n${line}\n`;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/** `check_whitespace` of a hunk line (its first byte the +/-/space). */
|
|
750
|
+
private checkWhitespace(line: string, wsRule: number, incomplete: boolean): void {
|
|
751
|
+
const body = line.slice(1);
|
|
752
|
+
const result = wsCheck(body, wsRule);
|
|
753
|
+
// the shown line: without its LF, but an incomplete line keeps its last byte
|
|
754
|
+
let shown = body.length - 1;
|
|
755
|
+
if (result & WS_INCOMPLETE_LINE) shown++;
|
|
756
|
+
void incomplete;
|
|
757
|
+
this.recordWsError(result, body.slice(0, Math.max(0, shown)), this.linenr);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
private parseFragment(
|
|
761
|
+
buf: string,
|
|
762
|
+
at: number,
|
|
763
|
+
size: number,
|
|
764
|
+
patch: FilePatch,
|
|
765
|
+
fragment: PatchFragment,
|
|
766
|
+
): number {
|
|
767
|
+
let len = linelen(buf, at, size);
|
|
768
|
+
if (patch.wsRule & WS_INCOMPLETE_LINE) {
|
|
769
|
+
const mode = this.applyInReverse
|
|
770
|
+
? patch.oldMode
|
|
771
|
+
: patch.newMode
|
|
772
|
+
? patch.newMode
|
|
773
|
+
: patch.oldMode;
|
|
774
|
+
if (mode && isLink(mode)) patch.wsRule &= ~WS_INCOMPLETE_LINE;
|
|
775
|
+
}
|
|
776
|
+
let offset = parseFragmentHeader(buf, at, len, fragment);
|
|
777
|
+
if (offset < 0) return -1;
|
|
778
|
+
if (offset > 0 && patch.recount) this.recountDiff(buf, at + offset, size - offset, fragment);
|
|
779
|
+
let oldlines = fragment.oldlines;
|
|
780
|
+
let newlines = fragment.newlines;
|
|
781
|
+
let leading = 0;
|
|
782
|
+
let trailing = 0;
|
|
783
|
+
let line = at + len;
|
|
784
|
+
size -= len;
|
|
785
|
+
this.linenr++;
|
|
786
|
+
let added = 0;
|
|
787
|
+
let deleted = 0;
|
|
788
|
+
for (offset = len; size > 0; offset += len, size -= len, line += len, this.linenr++) {
|
|
789
|
+
if (!oldlines && !newlines) break;
|
|
790
|
+
len = linelen(buf, line, size);
|
|
791
|
+
if (!len || buf[line + len - 1] !== "\n") return -1;
|
|
792
|
+
let skipLen = adjustIncomplete(buf, line, len, size);
|
|
793
|
+
if (skipLen) {
|
|
794
|
+
len--;
|
|
795
|
+
skipLen++;
|
|
796
|
+
}
|
|
797
|
+
const text = buf.slice(line, line + len);
|
|
798
|
+
switch (buf[line]) {
|
|
799
|
+
case "\n":
|
|
800
|
+
case " ":
|
|
801
|
+
oldlines--;
|
|
802
|
+
newlines--;
|
|
803
|
+
if (!deleted && !added) leading++;
|
|
804
|
+
trailing++;
|
|
805
|
+
checkOldForCrlf(patch, text);
|
|
806
|
+
if (!this.applyInReverse && this.wsErrorAction === "fix") {
|
|
807
|
+
this.checkWhitespace(buf[line] === "\n" ? " \n" : text, patch.wsRule, skipLen > 0);
|
|
808
|
+
}
|
|
809
|
+
break;
|
|
810
|
+
case "-":
|
|
811
|
+
if (!this.applyInReverse) checkOldForCrlf(patch, text);
|
|
812
|
+
if (this.applyInReverse && this.wsErrorAction !== "nowarn")
|
|
813
|
+
this.checkWhitespace(text, patch.wsRule, skipLen > 0);
|
|
814
|
+
deleted++;
|
|
815
|
+
oldlines--;
|
|
816
|
+
trailing = 0;
|
|
817
|
+
break;
|
|
818
|
+
case "+":
|
|
819
|
+
if (this.applyInReverse) checkOldForCrlf(patch, text);
|
|
820
|
+
if (!this.applyInReverse && this.wsErrorAction !== "nowarn")
|
|
821
|
+
this.checkWhitespace(text, patch.wsRule, skipLen > 0);
|
|
822
|
+
added++;
|
|
823
|
+
newlines--;
|
|
824
|
+
trailing = 0;
|
|
825
|
+
break;
|
|
826
|
+
default:
|
|
827
|
+
return -1;
|
|
828
|
+
}
|
|
829
|
+
if (skipLen) {
|
|
830
|
+
len += skipLen;
|
|
831
|
+
this.linenr++;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
if (oldlines || newlines) return -1;
|
|
835
|
+
if (!patch.recount && !deleted && !added) return -1;
|
|
836
|
+
fragment.leading = leading;
|
|
837
|
+
fragment.trailing = trailing;
|
|
838
|
+
patch.linesAdded += added;
|
|
839
|
+
patch.linesDeleted += deleted;
|
|
840
|
+
if (0 < patch.isNew && oldlines) return this.error("new file depends on old contents");
|
|
841
|
+
if (0 < patch.isDelete && newlines) return this.error("deleted file still has contents");
|
|
842
|
+
return offset;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
private recountDiff(buf: string, at: number, size: number, fragment: PatchFragment): void {
|
|
846
|
+
let oldlines = 0;
|
|
847
|
+
let newlines = 0;
|
|
848
|
+
if (size < 1) {
|
|
849
|
+
this.warning("recount: ignore empty hunk");
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
let line = at;
|
|
853
|
+
for (;;) {
|
|
854
|
+
const len = linelen(buf, line, size);
|
|
855
|
+
size -= len;
|
|
856
|
+
line += len;
|
|
857
|
+
if (size < 1) break;
|
|
858
|
+
let ret = 0;
|
|
859
|
+
switch (buf[line]) {
|
|
860
|
+
case " ":
|
|
861
|
+
case "\n":
|
|
862
|
+
newlines++;
|
|
863
|
+
oldlines++;
|
|
864
|
+
continue;
|
|
865
|
+
case "-":
|
|
866
|
+
oldlines++;
|
|
867
|
+
continue;
|
|
868
|
+
case "+":
|
|
869
|
+
newlines++;
|
|
870
|
+
continue;
|
|
871
|
+
case "\\":
|
|
872
|
+
continue;
|
|
873
|
+
case "@":
|
|
874
|
+
ret = size < 3 || !buf.startsWith("@@ ", line) ? 1 : 0;
|
|
875
|
+
break;
|
|
876
|
+
case "d":
|
|
877
|
+
ret = size < 5 || !buf.startsWith("diff ", line) ? 1 : 0;
|
|
878
|
+
break;
|
|
879
|
+
default:
|
|
880
|
+
ret = -1;
|
|
881
|
+
}
|
|
882
|
+
if (ret) {
|
|
883
|
+
this.warning(
|
|
884
|
+
`recount: unexpected line: ${buf.slice(line, line + linelen(buf, line, size))}`,
|
|
885
|
+
);
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
break;
|
|
889
|
+
}
|
|
890
|
+
fragment.oldlines = oldlines;
|
|
891
|
+
fragment.newlines = newlines;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
private parseSinglePatch(buf: string, at: number, size: number, patch: FilePatch): number {
|
|
895
|
+
let offset = 0;
|
|
896
|
+
let oldlines = 0;
|
|
897
|
+
let newlines = 0;
|
|
898
|
+
let context = 0;
|
|
899
|
+
let line = at;
|
|
900
|
+
while (size > 4 && buf.startsWith("@@ -", line)) {
|
|
901
|
+
const fragment = emptyFragment();
|
|
902
|
+
fragment.linenr = this.linenr;
|
|
903
|
+
const len = this.parseFragment(buf, line, size, patch, fragment);
|
|
904
|
+
if (len <= 0) return this.error(`corrupt patch ${this.at(this.linenr)}`);
|
|
905
|
+
fragment.patch = buf.slice(line, line + len);
|
|
906
|
+
fragment.size = len;
|
|
907
|
+
oldlines += fragment.oldlines;
|
|
908
|
+
newlines += fragment.newlines;
|
|
909
|
+
context += fragment.leading + fragment.trailing;
|
|
910
|
+
patch.fragments.push(fragment);
|
|
911
|
+
offset += len;
|
|
912
|
+
line += len;
|
|
913
|
+
size -= len;
|
|
914
|
+
}
|
|
915
|
+
if (patch.isNew < 0 && (oldlines || patch.fragments.length > 1)) patch.isNew = 0;
|
|
916
|
+
if (patch.isDelete < 0 && (newlines || patch.fragments.length > 1)) patch.isDelete = 0;
|
|
917
|
+
if (0 < patch.isNew && oldlines)
|
|
918
|
+
return this.error(`new file ${patch.newName} depends on old contents`);
|
|
919
|
+
if (0 < patch.isDelete && newlines)
|
|
920
|
+
return this.error(`deleted file ${patch.oldName} still has contents`);
|
|
921
|
+
if (!patch.isDelete && !newlines && context && this.verbosity > -1)
|
|
922
|
+
this.stderr += `** warning: file ${patch.newName} becomes empty but is not deleted\n`;
|
|
923
|
+
return offset;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
private async parseBinaryHunk(
|
|
927
|
+
buf: string,
|
|
928
|
+
state: { at: number; size: number },
|
|
929
|
+
): Promise<{ status: number; used: number; frag?: PatchFragment }> {
|
|
930
|
+
let at = state.at;
|
|
931
|
+
let size = state.size;
|
|
932
|
+
let llen = linelen(buf, at, size);
|
|
933
|
+
let used = llen;
|
|
934
|
+
let method: number;
|
|
935
|
+
let origlen: number;
|
|
936
|
+
if (buf.startsWith("delta ", at)) {
|
|
937
|
+
method = BINARY_DELTA;
|
|
938
|
+
origlen = strtoul(buf, at + 6, 10).value;
|
|
939
|
+
} else if (buf.startsWith("literal ", at)) {
|
|
940
|
+
method = BINARY_LITERAL;
|
|
941
|
+
origlen = strtoul(buf, at + 8, 10).value;
|
|
942
|
+
} else return { status: 0, used: 0 };
|
|
943
|
+
this.linenr++;
|
|
944
|
+
at += llen;
|
|
945
|
+
size -= llen;
|
|
946
|
+
const data: number[] = [];
|
|
947
|
+
const corrupt = () => {
|
|
948
|
+
this.error(
|
|
949
|
+
`corrupt binary patch ${this.at(this.linenr - 1)}: ${buf.slice(at, at + llen - 1)}`,
|
|
950
|
+
);
|
|
951
|
+
return { status: -1, used: 0 };
|
|
952
|
+
};
|
|
953
|
+
for (;;) {
|
|
954
|
+
llen = linelen(buf, at, size);
|
|
955
|
+
used += llen;
|
|
956
|
+
this.linenr++;
|
|
957
|
+
if (llen === 1) {
|
|
958
|
+
at++;
|
|
959
|
+
size--;
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
if (llen < 7 || (llen - 2) % 5) return corrupt();
|
|
963
|
+
const max = ((llen - 2) / 5) * 4;
|
|
964
|
+
const c = buf.charCodeAt(at);
|
|
965
|
+
let byteLength: number;
|
|
966
|
+
if (c >= 65 && c <= 90) byteLength = c - 65 + 1;
|
|
967
|
+
else if (c >= 97 && c <= 122) byteLength = c - 97 + 27;
|
|
968
|
+
else return corrupt();
|
|
969
|
+
if (max < byteLength || byteLength <= max - 4) return corrupt();
|
|
970
|
+
const bad = decode85(data, buf, at + 1, byteLength);
|
|
971
|
+
if (bad !== undefined) {
|
|
972
|
+
this.error(bad);
|
|
973
|
+
return corrupt();
|
|
974
|
+
}
|
|
975
|
+
at += llen;
|
|
976
|
+
size -= llen;
|
|
977
|
+
}
|
|
978
|
+
const inflated = this.inflateIt(new Uint8Array(data), origlen);
|
|
979
|
+
if (!inflated) return corrupt();
|
|
980
|
+
state.at = at;
|
|
981
|
+
state.size = size;
|
|
982
|
+
const frag = emptyFragment();
|
|
983
|
+
frag.patch = bytesToLatin1(inflated);
|
|
984
|
+
frag.size = origlen;
|
|
985
|
+
frag.binaryMethod = method;
|
|
986
|
+
return { status: 0, used, frag };
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
private async parseBinary(
|
|
990
|
+
buf: string,
|
|
991
|
+
at: number,
|
|
992
|
+
size: number,
|
|
993
|
+
patch: FilePatch,
|
|
994
|
+
): Promise<number> {
|
|
995
|
+
const state = { at, size };
|
|
996
|
+
const forward = await this.parseBinaryHunk(buf, state);
|
|
997
|
+
if (!forward.frag && !forward.status)
|
|
998
|
+
return this.error(`unrecognized binary patch ${this.at(this.linenr - 1)}`);
|
|
999
|
+
if (forward.status || !forward.frag) return forward.status;
|
|
1000
|
+
let used = forward.used;
|
|
1001
|
+
const reverse = await this.parseBinaryHunk(buf, state);
|
|
1002
|
+
if (reverse.frag) used += reverse.used;
|
|
1003
|
+
else if (reverse.status) return reverse.status;
|
|
1004
|
+
patch.fragments = reverse.frag ? [forward.frag, reverse.frag] : [forward.frag];
|
|
1005
|
+
patch.isBinary = true;
|
|
1006
|
+
return used;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* `parse_chunk`: reads one file's patch at `at`; the bytes it took, -1 when there is no
|
|
1011
|
+
* more, -128 on a fatal error.
|
|
1012
|
+
*/
|
|
1013
|
+
async parseChunk(
|
|
1014
|
+
buf: string,
|
|
1015
|
+
at: number,
|
|
1016
|
+
size: number,
|
|
1017
|
+
patch: FilePatch,
|
|
1018
|
+
wsRuleOf: (patch: FilePatch) => Promise<number>,
|
|
1019
|
+
): Promise<number> {
|
|
1020
|
+
const { offset, hdrsize } = this.findHeader(buf, at, size, patch);
|
|
1021
|
+
if (offset < 0) return offset;
|
|
1022
|
+
patch.wsRule = await wsRuleOf(patch);
|
|
1023
|
+
let patchsize = this.parseSinglePatch(
|
|
1024
|
+
buf,
|
|
1025
|
+
at + offset + hdrsize,
|
|
1026
|
+
size - offset - hdrsize,
|
|
1027
|
+
patch,
|
|
1028
|
+
);
|
|
1029
|
+
if (patchsize < 0) return -128;
|
|
1030
|
+
if (!patchsize) {
|
|
1031
|
+
const gitBinary = "GIT binary patch\n";
|
|
1032
|
+
const hd = at + hdrsize + offset;
|
|
1033
|
+
const rest = size - hdrsize - offset;
|
|
1034
|
+
const llen = linelen(buf, hd, rest);
|
|
1035
|
+
if (llen === gitBinary.length && buf.startsWith(gitBinary, hd)) {
|
|
1036
|
+
this.linenr++;
|
|
1037
|
+
const used = await this.parseBinary(buf, hd + llen, rest - llen, patch);
|
|
1038
|
+
if (used < 0) return -1;
|
|
1039
|
+
patchsize = used ? used + llen : 0;
|
|
1040
|
+
} else if (buf.slice(hd + llen - 8, hd + llen) === " differ\n") {
|
|
1041
|
+
for (const h of ["Binary files ", "Files "]) {
|
|
1042
|
+
if (h.length < rest && buf.startsWith(h, hd)) {
|
|
1043
|
+
this.linenr++;
|
|
1044
|
+
patch.isBinary = true;
|
|
1045
|
+
patchsize = llen;
|
|
1046
|
+
break;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
if ((this.apply || this.check) && !patch.isBinary && !metadataChanges(patch)) {
|
|
1051
|
+
this.error(`patch with only garbage ${this.at(this.linenr)}`);
|
|
1052
|
+
return -128;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
return offset + hdrsize + patchsize;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
export function metadataChanges(patch: FilePatch): boolean {
|
|
1060
|
+
return (
|
|
1061
|
+
patch.isRename ||
|
|
1062
|
+
patch.isCopy ||
|
|
1063
|
+
patch.isNew > 0 ||
|
|
1064
|
+
patch.isDelete !== 0 ||
|
|
1065
|
+
(patch.oldMode !== 0 && patch.newMode !== 0 && patch.oldMode !== patch.newMode)
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
function emptyFragment(): PatchFragment {
|
|
1070
|
+
return {
|
|
1071
|
+
leading: 0,
|
|
1072
|
+
trailing: 0,
|
|
1073
|
+
oldpos: 0,
|
|
1074
|
+
oldlines: 0,
|
|
1075
|
+
newpos: 0,
|
|
1076
|
+
newlines: 0,
|
|
1077
|
+
patch: "",
|
|
1078
|
+
size: 0,
|
|
1079
|
+
linenr: 0,
|
|
1080
|
+
rejected: false,
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function checkOldForCrlf(patch: FilePatch, line: string): void {
|
|
1085
|
+
const len = line.length;
|
|
1086
|
+
if (len >= 2 && line[len - 1] === "\n" && line[len - 2] === "\r") {
|
|
1087
|
+
patch.wsRule |= WS_CR_AT_EOL;
|
|
1088
|
+
patch.crlfInOld = true;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
function adjustIncomplete(buf: string, at: number, len: number, size: number): number {
|
|
1093
|
+
const c = buf[at];
|
|
1094
|
+
if (c !== "\n" && c !== " " && c !== "+" && c !== "-") return 0;
|
|
1095
|
+
if (size - len < 12 || !buf.startsWith("\\ ", at + len)) return 0;
|
|
1096
|
+
const nextlen = linelen(buf, at + len, size - len);
|
|
1097
|
+
if (nextlen < 12) return 0;
|
|
1098
|
+
return nextlen;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
function parseNum(buf: string, at: number): { digits: number; value: number } {
|
|
1102
|
+
if (!isDigit(buf[at])) return { digits: 0, value: 0 };
|
|
1103
|
+
let i = at;
|
|
1104
|
+
let value = 0;
|
|
1105
|
+
while (isDigit(buf[i])) value = value * 10 + (buf.charCodeAt(i++) - 48);
|
|
1106
|
+
return { digits: i - at, value };
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
function parseRange(
|
|
1110
|
+
buf: string,
|
|
1111
|
+
at: number,
|
|
1112
|
+
len: number,
|
|
1113
|
+
offset: number,
|
|
1114
|
+
expect: string,
|
|
1115
|
+
): { offset: number; p1: number; p2: number } {
|
|
1116
|
+
if (offset < 0 || offset >= len) return { offset: -1, p1: 0, p2: 0 };
|
|
1117
|
+
let line = at + offset;
|
|
1118
|
+
len -= offset;
|
|
1119
|
+
const n1 = parseNum(buf, line);
|
|
1120
|
+
if (!n1.digits) return { offset: -1, p1: 0, p2: 0 };
|
|
1121
|
+
offset += n1.digits;
|
|
1122
|
+
line += n1.digits;
|
|
1123
|
+
len -= n1.digits;
|
|
1124
|
+
let p2 = 1;
|
|
1125
|
+
if (buf[line] === ",") {
|
|
1126
|
+
const n2 = parseNum(buf, line + 1);
|
|
1127
|
+
if (!n2.digits) return { offset: -1, p1: 0, p2: 0 };
|
|
1128
|
+
p2 = n2.value;
|
|
1129
|
+
offset += n2.digits + 1;
|
|
1130
|
+
line += n2.digits + 1;
|
|
1131
|
+
len -= n2.digits + 1;
|
|
1132
|
+
}
|
|
1133
|
+
if (expect.length > len) return { offset: -1, p1: 0, p2: 0 };
|
|
1134
|
+
if (!buf.startsWith(expect, line)) return { offset: -1, p1: 0, p2: 0 };
|
|
1135
|
+
return { offset: offset + expect.length, p1: n1.value, p2 };
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
/** `parse_fragment_header` of "@@ -a,b +c,d @@": the header's length, or -1. */
|
|
1139
|
+
function parseFragmentHeader(
|
|
1140
|
+
buf: string,
|
|
1141
|
+
at: number,
|
|
1142
|
+
len: number,
|
|
1143
|
+
fragment: PatchFragment,
|
|
1144
|
+
): number {
|
|
1145
|
+
if (!len || buf[at + len - 1] !== "\n") return -1;
|
|
1146
|
+
const o = parseRange(buf, at, len, 4, " +");
|
|
1147
|
+
fragment.oldpos = o.p1;
|
|
1148
|
+
fragment.oldlines = o.p2;
|
|
1149
|
+
const n = parseRange(buf, at, len, o.offset, " @@");
|
|
1150
|
+
fragment.newpos = n.p1;
|
|
1151
|
+
fragment.newlines = n.p2;
|
|
1152
|
+
return n.offset;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
const DE85: Int16Array = (() => {
|
|
1156
|
+
const table = new Int16Array(256).fill(0);
|
|
1157
|
+
const chars =
|
|
1158
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
|
|
1159
|
+
for (let i = 0; i < chars.length; i++) table[chars.charCodeAt(i)] = i + 1;
|
|
1160
|
+
return table;
|
|
1161
|
+
})();
|
|
1162
|
+
|
|
1163
|
+
/** base85.c's `decode_85`: appends `len` decoded bytes to `out`; its error on bad data. */
|
|
1164
|
+
function decode85(out: number[], buf: string, at: number, len: number): string | undefined {
|
|
1165
|
+
let i = at;
|
|
1166
|
+
// a NUL ends the message (vsnprintf's %c, then vreportf stops at it)
|
|
1167
|
+
const alphabet = (ch: number) =>
|
|
1168
|
+
`invalid base85 alphabet ${Number.isNaN(ch) ? "\0" : String.fromCharCode(ch)}`;
|
|
1169
|
+
while (len) {
|
|
1170
|
+
let acc = 0;
|
|
1171
|
+
let cnt = 4;
|
|
1172
|
+
let de: number;
|
|
1173
|
+
do {
|
|
1174
|
+
const ch = buf.charCodeAt(i++);
|
|
1175
|
+
de = DE85[ch & 0xff] ?? 0;
|
|
1176
|
+
if (Number.isNaN(ch) || --de < 0) return alphabet(ch);
|
|
1177
|
+
acc = acc * 85 + de;
|
|
1178
|
+
} while (--cnt);
|
|
1179
|
+
const ch = buf.charCodeAt(i++);
|
|
1180
|
+
de = DE85[ch & 0xff] ?? 0;
|
|
1181
|
+
if (Number.isNaN(ch) || --de < 0) return alphabet(ch);
|
|
1182
|
+
if (0xffffffff / 85 < acc || 0xffffffff - de < acc * 85)
|
|
1183
|
+
return `invalid base85 sequence ${buf.slice(i - 5, i)}`;
|
|
1184
|
+
acc = acc * 85 + de;
|
|
1185
|
+
cnt = len < 4 ? len : 4;
|
|
1186
|
+
len -= cnt;
|
|
1187
|
+
do {
|
|
1188
|
+
acc = ((acc << 8) | (acc >>> 24)) >>> 0;
|
|
1189
|
+
out.push(acc & 0xff);
|
|
1190
|
+
} while (--cnt);
|
|
1191
|
+
}
|
|
1192
|
+
return undefined;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* usage.c's `vreportf`: the prefixed message cut at a NUL and at 4095 bytes, control
|
|
1197
|
+
* characters but tab and newline shown as `?`, ended by a newline.
|
|
1198
|
+
*/
|
|
1199
|
+
export function vreportf(prefix: string, message: string): string {
|
|
1200
|
+
let msg = prefix + message;
|
|
1201
|
+
const nul = msg.indexOf("\0", prefix.length);
|
|
1202
|
+
if (nul >= 0) msg = msg.slice(0, nul);
|
|
1203
|
+
if (msg.length > 4095) msg = msg.slice(0, 4095);
|
|
1204
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: git's iscntrl
|
|
1205
|
+
msg = msg.replace(/[\x00-\x08\x0b-\x1f\x7f]/g, "?");
|
|
1206
|
+
return `${msg}\n`;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
export { latin1ToBytes };
|