@statewalker/vcs-commands 0.4.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 +299 -34
- 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 +67 -4
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +179 -7
- 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 +93 -0
- package/dist/commands/core-config.d.ts.map +1 -0
- 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 +244 -23
- 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 +55 -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 +146 -6
- 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 +69 -13
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +214 -26
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +10 -2
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-list-command.d.ts +2 -4
- package/dist/commands/stash-list-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +95 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +320 -28
- 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 +137 -6
- 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 +204 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
- 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/core-commands/index.d.ts +0 -3
- package/dist/core-commands/index.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 +29 -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 +371 -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 +422 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +326 -5
- 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/index.d.ts +1 -0
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +123 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +41 -0
- package/dist/remote-config/remote-refs.d.ts.map +1 -0
- 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 +16 -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 +24 -1
- 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 +143 -18
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BZGa2Z3I.js +2934 -0
- package/dist/transport-command.d.ts +56 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -10
- package/src/commands/add-command.ts +1291 -224
- 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 +1426 -297
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +532 -85
- package/src/commands/clone-command.ts +826 -55
- package/src/commands/commit-command.ts +1781 -166
- package/src/commands/core-config.ts +196 -0
- 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 +1038 -79
- 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 +83 -0
- package/src/commands/init-command.ts +60 -11
- 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 +500 -19
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +828 -91
- 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 +692 -124
- package/src/commands/stash-create-command.ts +752 -89
- package/src/commands/stash-drop-command.ts +67 -6
- package/src/commands/stash-list-command.ts +10 -4
- package/src/commands/stash-working-tree.ts +387 -0
- package/src/commands/status-command.ts +1426 -97
- 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 +344 -15
- 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 +641 -0
- 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 +9 -5
- package/src/core-commands/index.ts +0 -8
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +46 -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 +1218 -118
- package/src/git.ts +552 -11
- package/src/index.ts +1 -1
- package/src/remote-config/index.ts +1 -0
- package/src/remote-config/remote-config-store.ts +326 -16
- package/src/remote-config/remote-refs.ts +119 -0
- 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 +18 -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 +24 -1
- 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 +288 -27
- package/src/transport-command.ts +139 -2
- package/dist/commands-BpeXZTC3.js +0 -10278
- package/dist/core-commands/checkout.command.d.ts +0 -103
- package/dist/core-commands/checkout.command.d.ts.map +0 -1
- package/dist/core-commands/checkout.command.impl.d.ts +0 -110
- package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
- package/dist/status-result-BapZoQaR.js +0 -411
- package/src/core-commands/checkout.command.impl.ts +0 -564
- package/src/core-commands/checkout.command.ts +0 -125
|
@@ -0,0 +1,2934 @@
|
|
|
1
|
+
import { DEFAULT_BIG_FILE_THRESHOLD, probeBlob } from "@statewalker/vcs-core";
|
|
2
|
+
import { compareGitPaths, decodeGitPath, encodeGitPath, gitCharWidthAt, gitStrWidth, parseGitBool } from "@statewalker/vcs-utils/encoding";
|
|
3
|
+
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
|
+
//#region src/results/quote-path.ts
|
|
6
|
+
/**
|
|
7
|
+
* Path quoting as git prints paths (`quote.c`'s `quote_c_style`): a path with a control
|
|
8
|
+
* character, `"` or `\`, or (with `core.quotePath`, the default) a byte above 0x7f, is put in
|
|
9
|
+
* double quotes with C escapes.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* quotePath("plain.txt"); // "plain.txt"
|
|
14
|
+
* quotePath("tab\there"); // "\"tab\\there\""
|
|
15
|
+
* quotePath("é.txt"); // "\"\\303\\251.txt\""
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
/** `cq_lookup` of quote.c: the escape letter, 1 for an octal escape, -1 for none */
|
|
21
|
+
function lookup(ch) {
|
|
22
|
+
if (ch >= 128) return 0;
|
|
23
|
+
switch (ch) {
|
|
24
|
+
case 7: return "a";
|
|
25
|
+
case 8: return "b";
|
|
26
|
+
case 9: return "t";
|
|
27
|
+
case 10: return "n";
|
|
28
|
+
case 11: return "v";
|
|
29
|
+
case 12: return "f";
|
|
30
|
+
case 13: return "r";
|
|
31
|
+
case 34: return "\"";
|
|
32
|
+
case 92: return "\\";
|
|
33
|
+
case 127: return 1;
|
|
34
|
+
}
|
|
35
|
+
return ch < 32 ? 1 : -1;
|
|
36
|
+
}
|
|
37
|
+
function mustQuote(ch, quotePathFully) {
|
|
38
|
+
const v = lookup(ch);
|
|
39
|
+
if (typeof v === "string") return true;
|
|
40
|
+
return v + (quotePathFully ? 1 : 0) > 0;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The bytes of `path` quoted as `quote_c_style` quotes them, without the double quotes;
|
|
44
|
+
* undefined when the path needs no quoting.
|
|
45
|
+
*/
|
|
46
|
+
function quoteCStyleBody(path, quotePathFully = true) {
|
|
47
|
+
const bytes = typeof path === "string" ? encodeGitPath(path) : path;
|
|
48
|
+
let needs = false;
|
|
49
|
+
for (const b of bytes) if (mustQuote(b, quotePathFully)) {
|
|
50
|
+
needs = true;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
if (!needs) return void 0;
|
|
54
|
+
let out = "";
|
|
55
|
+
let run = [];
|
|
56
|
+
const flush = () => {
|
|
57
|
+
if (run.length > 0) {
|
|
58
|
+
out += decodeGitPath(new Uint8Array(run));
|
|
59
|
+
run = [];
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
for (const b of bytes) {
|
|
63
|
+
if (!mustQuote(b, quotePathFully)) {
|
|
64
|
+
run.push(b);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
flush();
|
|
68
|
+
const v = lookup(b);
|
|
69
|
+
if (typeof v === "string") out += `\\${v}`;
|
|
70
|
+
else out += `\\${b >> 6 & 3}${b >> 3 & 7}${b & 7}`;
|
|
71
|
+
}
|
|
72
|
+
flush();
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
/** `path` as git prints it: in double quotes with C escapes when it needs quoting */
|
|
76
|
+
function quotePath(path, quotePathFully = true) {
|
|
77
|
+
const body = quoteCStyleBody(path, quotePathFully);
|
|
78
|
+
return body === void 0 ? path : `"${body}"`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* git's `quote_two_c_style`: `prefix` and `path` as they are, or both escaped inside one pair
|
|
82
|
+
* of quotes when either needs quoting
|
|
83
|
+
*/
|
|
84
|
+
function quoteTwo(prefix, path, quotePathFully = true) {
|
|
85
|
+
return quotePath(`${prefix}${path}`, quotePathFully);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/results/combined-diff.ts
|
|
89
|
+
/**
|
|
90
|
+
* git's combined diff (`combine-diff.c`), dense form (`diff --cc`): one result compared with
|
|
91
|
+
* several parents at once, as `git diff` shows a conflicted path, the worktree file against
|
|
92
|
+
* stages 2 ("ours") and 3 ("theirs").
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* writeCombinedDiff(sink, {
|
|
97
|
+
* path: "f.txt",
|
|
98
|
+
* parents: [ours, theirs], // { id, mode, content }
|
|
99
|
+
* result: { id: NULL_ID, mode: 0o100644, content: worktreeBytes },
|
|
100
|
+
* }, options);
|
|
101
|
+
* // diff --cc f.txt
|
|
102
|
+
* // index 1a2b3c4,5d6e7f8..0000000
|
|
103
|
+
* // ...
|
|
104
|
+
* // @@@ -1,5 -1,5 +1,9 @@@
|
|
105
|
+
* // 1
|
|
106
|
+
* // ++<<<<<<< HEAD
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* Each parent is diffed with the result without context (the same xdiff options as the
|
|
110
|
+
* patch); the lines a parent lost hang on the result line after them, merged across parents
|
|
111
|
+
* by their longest common subsequence. A hunk shows only where the result differs from more
|
|
112
|
+
* than one version (dense: a change taken from one parent alone is left out). Function lines
|
|
113
|
+
* of the hunk headers are the last line above the hunk starting with a letter, `_` or `$`,
|
|
114
|
+
* cut at 40 bytes, without its last non-blank byte (as git prints them).
|
|
115
|
+
*
|
|
116
|
+
* @module
|
|
117
|
+
*/
|
|
118
|
+
const FIRST_FEW_BYTES$1 = 8e3;
|
|
119
|
+
function isBinaryBuffer(content) {
|
|
120
|
+
const n = Math.min(content.length, FIRST_FEW_BYTES$1);
|
|
121
|
+
for (let i = 0; i < n; i++) if (content[i] === 0) return true;
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
/** combine-diff.c's `match_string_spaces` */
|
|
125
|
+
function matchStringSpaces(a, b, flags) {
|
|
126
|
+
let len1 = a.length;
|
|
127
|
+
let len2 = b.length;
|
|
128
|
+
if (flags & XDF_WHITESPACE_FLAGS) {
|
|
129
|
+
while (len1 > 0 && xdlIsSpace(a[len1 - 1])) len1--;
|
|
130
|
+
while (len2 > 0 && xdlIsSpace(b[len2 - 1])) len2--;
|
|
131
|
+
}
|
|
132
|
+
if (!(flags & (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE))) {
|
|
133
|
+
if (len1 !== len2) return false;
|
|
134
|
+
for (let i = 0; i < len1; i++) if (a[i] !== b[i]) return false;
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
while (len1 > 0 && len2 > 0) {
|
|
138
|
+
len1--;
|
|
139
|
+
len2--;
|
|
140
|
+
if (xdlIsSpace(a[len1]) || xdlIsSpace(b[len2])) {
|
|
141
|
+
if (flags & XDF_IGNORE_WHITESPACE_CHANGE && (!xdlIsSpace(a[len1]) || !xdlIsSpace(b[len2]))) return false;
|
|
142
|
+
while (len1 > 0 && xdlIsSpace(a[len1])) len1--;
|
|
143
|
+
while (len2 > 0 && xdlIsSpace(b[len2])) len2--;
|
|
144
|
+
}
|
|
145
|
+
if (a[len1] !== b[len2]) return false;
|
|
146
|
+
}
|
|
147
|
+
if (flags & XDF_IGNORE_WHITESPACE) {
|
|
148
|
+
while (len1 > 0 && xdlIsSpace(a[len1 - 1])) len1--;
|
|
149
|
+
while (len2 > 0 && xdlIsSpace(b[len2 - 1])) len2--;
|
|
150
|
+
}
|
|
151
|
+
return len1 === 0 && len2 === 0;
|
|
152
|
+
}
|
|
153
|
+
const MATCH = 0;
|
|
154
|
+
const BASE = 1;
|
|
155
|
+
const NEW = 2;
|
|
156
|
+
/** combine-diff.c's `coalesce_lines`: `newLines` merged into `base` by their LCS */
|
|
157
|
+
function coalesceLines(base, newLines, parent, flags) {
|
|
158
|
+
if (newLines.length === 0) return base;
|
|
159
|
+
if (base.length === 0) return newLines;
|
|
160
|
+
const nb = base.length;
|
|
161
|
+
const nn = newLines.length;
|
|
162
|
+
const lcs = [];
|
|
163
|
+
const dir = [];
|
|
164
|
+
for (let i = 0; i <= nb; i++) {
|
|
165
|
+
lcs.push(new Int32Array(nn + 1));
|
|
166
|
+
const d = new Uint8Array(nn + 1);
|
|
167
|
+
d[0] = BASE;
|
|
168
|
+
dir.push(d);
|
|
169
|
+
}
|
|
170
|
+
for (let j = 1; j <= nn; j++) dir[0][j] = NEW;
|
|
171
|
+
for (let i = 1; i <= nb; i++) for (let j = 1; j <= nn; j++) if (matchStringSpaces(base[i - 1].line, newLines[j - 1].line, flags)) {
|
|
172
|
+
lcs[i][j] = lcs[i - 1][j - 1] + 1;
|
|
173
|
+
dir[i][j] = MATCH;
|
|
174
|
+
} else if (lcs[i][j - 1] >= lcs[i - 1][j]) {
|
|
175
|
+
lcs[i][j] = lcs[i][j - 1];
|
|
176
|
+
dir[i][j] = NEW;
|
|
177
|
+
} else {
|
|
178
|
+
lcs[i][j] = lcs[i - 1][j];
|
|
179
|
+
dir[i][j] = BASE;
|
|
180
|
+
}
|
|
181
|
+
const out = [...base];
|
|
182
|
+
let i = nb;
|
|
183
|
+
let j = nn;
|
|
184
|
+
while (i !== 0 || j !== 0) if (dir[i][j] === MATCH) {
|
|
185
|
+
out[i - 1].parentMap |= 1 << parent;
|
|
186
|
+
i--;
|
|
187
|
+
j--;
|
|
188
|
+
} else if (dir[i][j] === NEW) {
|
|
189
|
+
out.splice(i, 0, newLines[j - 1]);
|
|
190
|
+
j--;
|
|
191
|
+
} else i--;
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
/** combine-diff.c's `combine_diff`: one parent's changes recorded in `sline` */
|
|
195
|
+
function combineDiff(parent, result, sline, cnt, n, options, flags) {
|
|
196
|
+
const nmask = 1 << n;
|
|
197
|
+
const diff = unifiedDiffHunks(parent.content, result, {
|
|
198
|
+
algorithm: options.algorithm,
|
|
199
|
+
indentHeuristic: options.indentHeuristic,
|
|
200
|
+
histogramRediff: options.histogramRediff,
|
|
201
|
+
legacyMinimal: options.legacyMinimal,
|
|
202
|
+
ignoreWhitespace: options.ignoreWhitespace,
|
|
203
|
+
ignoreWhitespaceChange: options.ignoreWhitespaceChange,
|
|
204
|
+
ignoreWhitespaceAtEol: options.ignoreWhitespaceAtEol,
|
|
205
|
+
ignoreCrAtEol: options.ignoreCrAtEol,
|
|
206
|
+
ignoreBlankLines: options.ignoreBlankLines,
|
|
207
|
+
context: 0,
|
|
208
|
+
interHunkContext: 0
|
|
209
|
+
});
|
|
210
|
+
for (const hunk of diff.hunks) {
|
|
211
|
+
const nb = hunk.newStart;
|
|
212
|
+
let lno = nb;
|
|
213
|
+
const bucket = hunk.newCount === 0 ? sline[nb] : sline[nb - 1];
|
|
214
|
+
for (const line of hunk.lines) if (line.kind === "-") {
|
|
215
|
+
let bytes = diff.old.line(line.index);
|
|
216
|
+
if (bytes.length > 0 && bytes[bytes.length - 1] === 10) bytes = bytes.subarray(0, bytes.length - 1);
|
|
217
|
+
bucket.plost.push({
|
|
218
|
+
line: bytes,
|
|
219
|
+
parentMap: nmask
|
|
220
|
+
});
|
|
221
|
+
} else if (line.kind === "+") {
|
|
222
|
+
sline[lno - 1].flag |= nmask;
|
|
223
|
+
lno++;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
let pLno = 1;
|
|
227
|
+
let lno = 0;
|
|
228
|
+
for (; lno <= cnt; lno++) {
|
|
229
|
+
const sl = sline[lno];
|
|
230
|
+
sl.pLno[n] = pLno;
|
|
231
|
+
if (sl.plost.length > 0) {
|
|
232
|
+
sl.lost = coalesceLines(sl.lost, sl.plost, n, flags);
|
|
233
|
+
sl.plost = [];
|
|
234
|
+
}
|
|
235
|
+
for (const ll of sl.lost) if (ll.parentMap & nmask) pLno++;
|
|
236
|
+
if (lno < cnt && !(sl.flag & nmask)) pLno++;
|
|
237
|
+
}
|
|
238
|
+
sline[lno].pLno[n] = pLno;
|
|
239
|
+
}
|
|
240
|
+
/** combine-diff.c's `reuse_combine_diff`: parent `i` is the same blob as parent `j` */
|
|
241
|
+
function reuseCombineDiff(sline, cnt, i, j) {
|
|
242
|
+
const imask = 1 << i;
|
|
243
|
+
const jmask = 1 << j;
|
|
244
|
+
for (let lno = 0; lno <= cnt; lno++) {
|
|
245
|
+
const sl = sline[lno];
|
|
246
|
+
sl.pLno[i] = sl.pLno[j];
|
|
247
|
+
for (const ll of sl.lost) if (ll.parentMap & jmask) ll.parentMap |= imask;
|
|
248
|
+
if (sl.flag & jmask) sl.flag |= imask;
|
|
249
|
+
}
|
|
250
|
+
sline[cnt + 1].pLno[i] = sline[cnt + 1].pLno[j];
|
|
251
|
+
}
|
|
252
|
+
function interesting(sl, allMask) {
|
|
253
|
+
return (sl.flag & allMask) !== 0 || sl.lost.length > 0;
|
|
254
|
+
}
|
|
255
|
+
function adjustHunkTail(sline, allMask, hunkBegin, i) {
|
|
256
|
+
if (hunkBegin + 1 <= i && !(sline[i - 1].flag & allMask)) return i - 1;
|
|
257
|
+
return i;
|
|
258
|
+
}
|
|
259
|
+
function findNext(sline, mark, start, cnt, lookForUninteresting) {
|
|
260
|
+
let i = start;
|
|
261
|
+
while (i <= cnt) {
|
|
262
|
+
if (lookForUninteresting ? !(sline[i].flag & mark) : sline[i].flag & mark) return i;
|
|
263
|
+
i++;
|
|
264
|
+
}
|
|
265
|
+
return i;
|
|
266
|
+
}
|
|
267
|
+
function giveContext(sline, cnt, numParent, context) {
|
|
268
|
+
const allMask = (1 << numParent) - 1;
|
|
269
|
+
const mark = 1 << numParent;
|
|
270
|
+
const noPreDelete = 2 << numParent;
|
|
271
|
+
let i = findNext(sline, mark, 0, cnt, false);
|
|
272
|
+
if (cnt < i) return false;
|
|
273
|
+
while (i <= cnt) {
|
|
274
|
+
let j = context < i ? i - context : 0;
|
|
275
|
+
while (j < i) {
|
|
276
|
+
if (!(sline[j].flag & mark)) sline[j].flag |= noPreDelete;
|
|
277
|
+
sline[j++].flag |= mark;
|
|
278
|
+
}
|
|
279
|
+
for (;;) {
|
|
280
|
+
j = findNext(sline, mark, i, cnt, true);
|
|
281
|
+
if (cnt < j) return true;
|
|
282
|
+
let k = findNext(sline, mark, j, cnt, false);
|
|
283
|
+
j = adjustHunkTail(sline, allMask, i, j);
|
|
284
|
+
if (k < j + context) {
|
|
285
|
+
while (j < k) sline[j++].flag |= mark;
|
|
286
|
+
i = k;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
i = k;
|
|
290
|
+
k = j + context < cnt + 1 ? j + context : cnt + 1;
|
|
291
|
+
while (j < k) sline[j++].flag |= mark;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
/** combine-diff.c's `make_hunks` */
|
|
298
|
+
function makeHunks(sline, cnt, numParent, context, dense = true) {
|
|
299
|
+
const allMask = (1 << numParent) - 1;
|
|
300
|
+
const mark = 1 << numParent;
|
|
301
|
+
for (let i = 0; i <= cnt; i++) if (interesting(sline[i], allMask)) sline[i].flag |= mark;
|
|
302
|
+
else sline[i].flag &= ~mark;
|
|
303
|
+
if (!dense) return giveContext(sline, cnt, numParent, context);
|
|
304
|
+
let i = 0;
|
|
305
|
+
while (i <= cnt) {
|
|
306
|
+
while (i <= cnt && !(sline[i].flag & mark)) i++;
|
|
307
|
+
if (cnt < i) break;
|
|
308
|
+
const hunkBegin = i;
|
|
309
|
+
let j = i + 1;
|
|
310
|
+
for (; j <= cnt; j++) if (!(sline[j].flag & mark)) {
|
|
311
|
+
let la = adjustHunkTail(sline, allMask, hunkBegin, j);
|
|
312
|
+
la = la + context < cnt + 1 ? la + context : cnt + 1;
|
|
313
|
+
let contin = false;
|
|
314
|
+
while (la && j <= --la) if (sline[la].flag & mark) {
|
|
315
|
+
contin = true;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
if (!contin) break;
|
|
319
|
+
j = la;
|
|
320
|
+
}
|
|
321
|
+
const hunkEnd = j;
|
|
322
|
+
let sameDiff = 0;
|
|
323
|
+
let hasInteresting = false;
|
|
324
|
+
for (j = i; j < hunkEnd && !hasInteresting; j++) {
|
|
325
|
+
let thisDiff = sline[j].flag & allMask;
|
|
326
|
+
if (thisDiff) {
|
|
327
|
+
if (!sameDiff) sameDiff = thisDiff;
|
|
328
|
+
else if (sameDiff !== thisDiff) {
|
|
329
|
+
hasInteresting = true;
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
for (const ll of sline[j].lost) {
|
|
334
|
+
if (hasInteresting) break;
|
|
335
|
+
thisDiff = ll.parentMap;
|
|
336
|
+
if (!sameDiff) sameDiff = thisDiff;
|
|
337
|
+
else if (sameDiff !== thisDiff) hasInteresting = true;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (!hasInteresting && sameDiff !== allMask) for (j = hunkBegin; j < hunkEnd; j++) sline[j].flag &= ~mark;
|
|
341
|
+
i = hunkEnd;
|
|
342
|
+
}
|
|
343
|
+
return giveContext(sline, cnt, numParent, context);
|
|
344
|
+
}
|
|
345
|
+
/** git's `isalpha` (ASCII) or `_` or `$`: a line fit for a hunk header comment */
|
|
346
|
+
function hunkCommentLine(bol) {
|
|
347
|
+
if (!bol || bol.length === 0) return false;
|
|
348
|
+
const ch = bol[0];
|
|
349
|
+
return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch === 95 || ch === 36;
|
|
350
|
+
}
|
|
351
|
+
/** `show_line_to_eol` without colors: the line and an LF */
|
|
352
|
+
function lineToEol(sink, line) {
|
|
353
|
+
sink.push(line);
|
|
354
|
+
sink.text("\n");
|
|
355
|
+
}
|
|
356
|
+
/** combine-diff.c's `dump_sline` */
|
|
357
|
+
function dumpSline(sink, sline, cnt, numParent, context, resultDeleted) {
|
|
358
|
+
const mark = 1 << numParent;
|
|
359
|
+
const noPreDelete = 2 << numParent;
|
|
360
|
+
if (resultDeleted) return;
|
|
361
|
+
let lno = 0;
|
|
362
|
+
for (;;) {
|
|
363
|
+
let hunkComment;
|
|
364
|
+
let nullContext = 0;
|
|
365
|
+
while (lno <= cnt && !(sline[lno].flag & mark)) {
|
|
366
|
+
if (hunkCommentLine(sline[lno].bol)) hunkComment = sline[lno].bol;
|
|
367
|
+
lno++;
|
|
368
|
+
}
|
|
369
|
+
if (cnt < lno) break;
|
|
370
|
+
let hunkEnd = lno + 1;
|
|
371
|
+
for (; hunkEnd <= cnt; hunkEnd++) if (!(sline[hunkEnd].flag & mark)) break;
|
|
372
|
+
let rlines = hunkEnd - lno;
|
|
373
|
+
if (cnt < hunkEnd) rlines--;
|
|
374
|
+
if (!context) {
|
|
375
|
+
for (let j = lno; j < hunkEnd; j++) if (!(sline[j].flag & mark - 1)) nullContext++;
|
|
376
|
+
rlines -= nullContext;
|
|
377
|
+
}
|
|
378
|
+
let head = "@".repeat(numParent + 1);
|
|
379
|
+
for (let i = 0; i < numParent; i++) {
|
|
380
|
+
const l0 = sline[lno].pLno[i];
|
|
381
|
+
const l1 = sline[hunkEnd].pLno[i];
|
|
382
|
+
head += ` -${l0},${unsignedLong(l1 - l0 - nullContext)}`;
|
|
383
|
+
}
|
|
384
|
+
head += ` +${lno + 1},${unsignedLong(rlines)} ${"@".repeat(numParent + 1)}`;
|
|
385
|
+
sink.text(head);
|
|
386
|
+
if (hunkComment) {
|
|
387
|
+
let commentEnd = 0;
|
|
388
|
+
for (let i = 0; i < 40 && i < hunkComment.length; i++) {
|
|
389
|
+
const ch = hunkComment[i];
|
|
390
|
+
if (ch === 0 || ch === 10) break;
|
|
391
|
+
if (!xdlIsSpace(ch)) commentEnd = i;
|
|
392
|
+
}
|
|
393
|
+
if (commentEnd) {
|
|
394
|
+
sink.text(" ");
|
|
395
|
+
sink.push(hunkComment.subarray(0, commentEnd));
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
sink.text("\n");
|
|
399
|
+
while (lno < hunkEnd) {
|
|
400
|
+
const sl = sline[lno++];
|
|
401
|
+
const lost = sl.flag & noPreDelete ? [] : sl.lost;
|
|
402
|
+
for (const ll of lost) {
|
|
403
|
+
let marks = "";
|
|
404
|
+
for (let j = 0; j < numParent; j++) marks += ll.parentMap & 1 << j ? "-" : " ";
|
|
405
|
+
sink.text(marks);
|
|
406
|
+
lineToEol(sink, ll.line);
|
|
407
|
+
}
|
|
408
|
+
if (cnt < lno) break;
|
|
409
|
+
if (!(sl.flag & mark - 1) && !context) continue;
|
|
410
|
+
let marks = "";
|
|
411
|
+
for (let j = 0; j < numParent; j++) marks += sl.flag & 1 << j ? "+" : " ";
|
|
412
|
+
sink.text(marks);
|
|
413
|
+
lineToEol(sink, sl.bol ?? /* @__PURE__ */ new Uint8Array(0));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function octal6$1(mode) {
|
|
418
|
+
return mode.toString(8).padStart(6, "0");
|
|
419
|
+
}
|
|
420
|
+
/** combine-diff.c's `show_combined_header` (dense, from the worktree) */
|
|
421
|
+
function writeHeader(sink, elem, options, modeDiffers, showFileHeader) {
|
|
422
|
+
const quote = options.quotePath ?? true;
|
|
423
|
+
const abbreviate = options.abbreviate ?? ((id) => id.slice(0, 7));
|
|
424
|
+
const dense = options.dense ?? true;
|
|
425
|
+
sink.text(`${dense ? "diff --cc " : "diff --combined "}${quoteTwo("", elem.path, quote)}\n`);
|
|
426
|
+
sink.text(`index ${elem.parents.map((p) => abbreviate(p.id)).join(",")}..${abbreviate(elem.result.id)}\n`);
|
|
427
|
+
const deleted = !elem.result.mode;
|
|
428
|
+
const added = !deleted && elem.parents.every((p) => !p.mode);
|
|
429
|
+
if (modeDiffers) {
|
|
430
|
+
if (added) sink.text(`new file mode ${octal6$1(elem.result.mode)}\n`);
|
|
431
|
+
else {
|
|
432
|
+
let line = deleted ? "deleted file mode " : "mode ";
|
|
433
|
+
line += elem.parents.map((p) => octal6$1(p.mode)).join(",");
|
|
434
|
+
if (elem.result.mode) line += `..${octal6$1(elem.result.mode)}`;
|
|
435
|
+
sink.text(`${line}\n`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (!showFileHeader) return;
|
|
439
|
+
const aPrefix = options.srcPrefix ?? "a/";
|
|
440
|
+
const bPrefix = options.dstPrefix ?? "b/";
|
|
441
|
+
sink.text(added ? "--- /dev/null\n" : `--- ${quoteTwo(aPrefix, elem.path, quote)}\n`);
|
|
442
|
+
sink.text(deleted ? "+++ /dev/null\n" : `+++ ${quoteTwo(bPrefix, elem.path, quote)}\n`);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* The dense combined diff of a path whose result is a worktree file (`show_patch_diff` with
|
|
446
|
+
* `working_tree_file`): always printed, with its header, even when no hunk is left.
|
|
447
|
+
*/
|
|
448
|
+
function writeCombinedDiff(sink, elem, options = {}) {
|
|
449
|
+
const context = options.context ?? 3;
|
|
450
|
+
const numParent = elem.parents.length;
|
|
451
|
+
const resultDeleted = !elem.result.mode && options.workingTreeFile !== false;
|
|
452
|
+
const result = !elem.result.mode ? /* @__PURE__ */ new Uint8Array(0) : elem.result.content;
|
|
453
|
+
const modeDiffers = elem.parents.some((p) => p.mode !== elem.result.mode);
|
|
454
|
+
if (options.binary ?? (isBinaryBuffer(result) || elem.parents.some((p) => isBinaryBuffer(p.content)))) {
|
|
455
|
+
writeHeader(sink, elem, options, modeDiffers, false);
|
|
456
|
+
sink.text("Binary files differ\n");
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
let cnt = 0;
|
|
460
|
+
for (let i = 0; i < result.length; i++) if (result[i] === 10) cnt++;
|
|
461
|
+
if (result.length > 0 && result[result.length - 1] !== 10) cnt++;
|
|
462
|
+
const sline = [];
|
|
463
|
+
for (let i = 0; i < cnt + 2; i++) sline.push({
|
|
464
|
+
lost: [],
|
|
465
|
+
plost: [],
|
|
466
|
+
flag: 0,
|
|
467
|
+
pLno: new Array(numParent).fill(0)
|
|
468
|
+
});
|
|
469
|
+
let start = 0;
|
|
470
|
+
let lno = 0;
|
|
471
|
+
for (let i = 0; i < result.length; i++) if (result[i] === 10) {
|
|
472
|
+
sline[lno++].bol = result.subarray(start, i);
|
|
473
|
+
start = i + 1;
|
|
474
|
+
}
|
|
475
|
+
if (start < result.length) sline[lno].bol = result.subarray(start);
|
|
476
|
+
const flags = whitespaceFlags(options);
|
|
477
|
+
for (let i = 0; i < numParent; i++) {
|
|
478
|
+
let j = 0;
|
|
479
|
+
for (; j < i; j++) if (elem.parents[i].id === elem.parents[j].id) {
|
|
480
|
+
reuseCombineDiff(sline, cnt, i, j);
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
if (i <= j && !resultDeleted) combineDiff(elem.parents[i], result, sline, cnt, i, options, flags);
|
|
484
|
+
}
|
|
485
|
+
if (!makeHunks(sline, cnt, numParent, context, options.dense ?? true) && !modeDiffers && options.workingTreeFile === false) return;
|
|
486
|
+
writeHeader(sink, elem, options, modeDiffers, true);
|
|
487
|
+
dumpSline(sink, sline, cnt, numParent, context, resultDeleted);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* A count as git's `%lu` prints it: git keeps the hunk header's counts in `unsigned long`, so
|
|
491
|
+
* one that goes below zero (a `-U0` hunk of only lines no parent removed) wraps around to
|
|
492
|
+
* 2^64 - n, `18446744073709551615` for -1.
|
|
493
|
+
*/
|
|
494
|
+
function unsignedLong(n) {
|
|
495
|
+
return n < 0 ? (2n ** 64n + BigInt(n)).toString() : String(n);
|
|
496
|
+
}
|
|
497
|
+
//#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
|
+
//#region src/results/binary-patch.ts
|
|
583
|
+
/**
|
|
584
|
+
* git's binary patch body (diff.c's `emit_binary_diff`): the postimage deflated (zlib
|
|
585
|
+
* level 1, git's default `core.compression` for loose data) or a deflated delta of it
|
|
586
|
+
* against the preimage (diff-delta.c, ported with its Rabin fingerprint tables so the
|
|
587
|
+
* deltas are git's bytes), whichever is smaller, in base85 lines of up to 52 bytes.
|
|
588
|
+
*/
|
|
589
|
+
const HASH_LIMIT = 64;
|
|
590
|
+
const RABIN_SHIFT = 23;
|
|
591
|
+
const RABIN_WINDOW = 16;
|
|
592
|
+
const MAX_OP_SIZE = 34;
|
|
593
|
+
const T = new Uint32Array([
|
|
594
|
+
0,
|
|
595
|
+
2874782929,
|
|
596
|
+
1454598562,
|
|
597
|
+
4260027763,
|
|
598
|
+
104818581,
|
|
599
|
+
2909197124,
|
|
600
|
+
1351355959,
|
|
601
|
+
4225088230,
|
|
602
|
+
209637162,
|
|
603
|
+
2804382715,
|
|
604
|
+
1523426952,
|
|
605
|
+
4053013081,
|
|
606
|
+
172075199,
|
|
607
|
+
2702711918,
|
|
608
|
+
1559413021,
|
|
609
|
+
4155209164,
|
|
610
|
+
419274324,
|
|
611
|
+
3013880453,
|
|
612
|
+
1313798134,
|
|
613
|
+
3843506983,
|
|
614
|
+
516094401,
|
|
615
|
+
3046853904,
|
|
616
|
+
1215402083,
|
|
617
|
+
3811058866,
|
|
618
|
+
344150398,
|
|
619
|
+
3218793903,
|
|
620
|
+
1110456540,
|
|
621
|
+
3916008461,
|
|
622
|
+
314324715,
|
|
623
|
+
3118826042,
|
|
624
|
+
1141858121,
|
|
625
|
+
4015451032,
|
|
626
|
+
838548648,
|
|
627
|
+
2594343033,
|
|
628
|
+
1732793610,
|
|
629
|
+
3423723995,
|
|
630
|
+
935615293,
|
|
631
|
+
2627596268,
|
|
632
|
+
1635201695,
|
|
633
|
+
3392046670,
|
|
634
|
+
1032188802,
|
|
635
|
+
2531018579,
|
|
636
|
+
1798740512,
|
|
637
|
+
3228511985,
|
|
638
|
+
1002083351,
|
|
639
|
+
2430804166,
|
|
640
|
+
1829371317,
|
|
641
|
+
3327150436,
|
|
642
|
+
688300796,
|
|
643
|
+
2187269677,
|
|
644
|
+
2142620510,
|
|
645
|
+
3572268943,
|
|
646
|
+
792315241,
|
|
647
|
+
2220913080,
|
|
648
|
+
2039131339,
|
|
649
|
+
3537049626,
|
|
650
|
+
628649430,
|
|
651
|
+
2384582919,
|
|
652
|
+
1942684788,
|
|
653
|
+
3633492133,
|
|
654
|
+
591858243,
|
|
655
|
+
2283716242,
|
|
656
|
+
1978950625,
|
|
657
|
+
3735934768,
|
|
658
|
+
1677097296,
|
|
659
|
+
3366964609,
|
|
660
|
+
893718770,
|
|
661
|
+
2652677155,
|
|
662
|
+
1707679429,
|
|
663
|
+
3465587220,
|
|
664
|
+
863663975,
|
|
665
|
+
2552480694,
|
|
666
|
+
1871230586,
|
|
667
|
+
3302032043,
|
|
668
|
+
960225240,
|
|
669
|
+
2455923465,
|
|
670
|
+
1773654511,
|
|
671
|
+
3270403390,
|
|
672
|
+
1057273933,
|
|
673
|
+
2489126044,
|
|
674
|
+
2064377604,
|
|
675
|
+
3495056341,
|
|
676
|
+
767069862,
|
|
677
|
+
2262907511,
|
|
678
|
+
2100592785,
|
|
679
|
+
3597481024,
|
|
680
|
+
730327347,
|
|
681
|
+
2162056674,
|
|
682
|
+
2004166702,
|
|
683
|
+
3693911295,
|
|
684
|
+
566641036,
|
|
685
|
+
2325738845,
|
|
686
|
+
1900695483,
|
|
687
|
+
3658742634,
|
|
688
|
+
670639641,
|
|
689
|
+
2359333576,
|
|
690
|
+
1376601592,
|
|
691
|
+
4183093545,
|
|
692
|
+
79572058,
|
|
693
|
+
2951190667,
|
|
694
|
+
1412571757,
|
|
695
|
+
4285241020,
|
|
696
|
+
42027983,
|
|
697
|
+
2849570590,
|
|
698
|
+
1584630482,
|
|
699
|
+
4113186307,
|
|
700
|
+
146858864,
|
|
701
|
+
2744735649,
|
|
702
|
+
1481436487,
|
|
703
|
+
4078262678,
|
|
704
|
+
251626725,
|
|
705
|
+
2779131956,
|
|
706
|
+
1257298860,
|
|
707
|
+
3785977725,
|
|
708
|
+
474198542,
|
|
709
|
+
3071936223,
|
|
710
|
+
1288682553,
|
|
711
|
+
3885369576,
|
|
712
|
+
444388763,
|
|
713
|
+
2972016970,
|
|
714
|
+
1183716486,
|
|
715
|
+
3990331479,
|
|
716
|
+
272465188,
|
|
717
|
+
3143944693,
|
|
718
|
+
1085371155,
|
|
719
|
+
3957901250,
|
|
720
|
+
369236657,
|
|
721
|
+
3176902240,
|
|
722
|
+
1823819377,
|
|
723
|
+
3354194592,
|
|
724
|
+
973483987,
|
|
725
|
+
2438961922,
|
|
726
|
+
1787437540,
|
|
727
|
+
3251868981,
|
|
728
|
+
1010387014,
|
|
729
|
+
2539715735,
|
|
730
|
+
1623951707,
|
|
731
|
+
3415358858,
|
|
732
|
+
913891577,
|
|
733
|
+
2636207144,
|
|
734
|
+
1727327950,
|
|
735
|
+
3450690079,
|
|
736
|
+
809994092,
|
|
737
|
+
2602447805,
|
|
738
|
+
1950930981,
|
|
739
|
+
3742461172,
|
|
740
|
+
586920327,
|
|
741
|
+
2309096790,
|
|
742
|
+
1920450480,
|
|
743
|
+
3643673441,
|
|
744
|
+
616879634,
|
|
745
|
+
2409456323,
|
|
746
|
+
2016810767,
|
|
747
|
+
3547309022,
|
|
748
|
+
780500653,
|
|
749
|
+
2245839484,
|
|
750
|
+
2114547866,
|
|
751
|
+
3578840139,
|
|
752
|
+
683284792,
|
|
753
|
+
2212736489,
|
|
754
|
+
1565424345,
|
|
755
|
+
4128755208,
|
|
756
|
+
201134971,
|
|
757
|
+
2695145386,
|
|
758
|
+
1534139724,
|
|
759
|
+
4029196701,
|
|
760
|
+
230847726,
|
|
761
|
+
2795225151,
|
|
762
|
+
1362146803,
|
|
763
|
+
4201185570,
|
|
764
|
+
126082129,
|
|
765
|
+
2899994752,
|
|
766
|
+
1460654694,
|
|
767
|
+
4233520823,
|
|
768
|
+
29146052,
|
|
769
|
+
2867138325,
|
|
770
|
+
1169417357,
|
|
771
|
+
4008333404,
|
|
772
|
+
318803247,
|
|
773
|
+
3092855294,
|
|
774
|
+
1133282072,
|
|
775
|
+
3906287561,
|
|
776
|
+
356510394,
|
|
777
|
+
3194379883,
|
|
778
|
+
1238182823,
|
|
779
|
+
3801390966,
|
|
780
|
+
528368133,
|
|
781
|
+
3022517972,
|
|
782
|
+
1341279282,
|
|
783
|
+
3836475619,
|
|
784
|
+
423699856,
|
|
785
|
+
2987954497,
|
|
786
|
+
256065313,
|
|
787
|
+
2753203184,
|
|
788
|
+
1508923011,
|
|
789
|
+
4071219794,
|
|
790
|
+
159144116,
|
|
791
|
+
2720394341,
|
|
792
|
+
1607414038,
|
|
793
|
+
4103505351,
|
|
794
|
+
54390795,
|
|
795
|
+
2825143514,
|
|
796
|
+
1435408809,
|
|
797
|
+
4275514744,
|
|
798
|
+
84055966,
|
|
799
|
+
2925208399,
|
|
800
|
+
1404173884,
|
|
801
|
+
4175973101,
|
|
802
|
+
398369141,
|
|
803
|
+
3169260964,
|
|
804
|
+
1091422423,
|
|
805
|
+
3931405318,
|
|
806
|
+
293717728,
|
|
807
|
+
3134747185,
|
|
808
|
+
1194504002,
|
|
809
|
+
3966442387,
|
|
810
|
+
465595999,
|
|
811
|
+
2962872974,
|
|
812
|
+
1299384317,
|
|
813
|
+
3861558060,
|
|
814
|
+
503253450,
|
|
815
|
+
3064380699,
|
|
816
|
+
1263296616,
|
|
817
|
+
3759527097,
|
|
818
|
+
1052246921,
|
|
819
|
+
2514597720,
|
|
820
|
+
1745578539,
|
|
821
|
+
3276988154,
|
|
822
|
+
948397084,
|
|
823
|
+
2480853197,
|
|
824
|
+
1848905150,
|
|
825
|
+
3312302447,
|
|
826
|
+
851889315,
|
|
827
|
+
2577365106,
|
|
828
|
+
1685431553,
|
|
829
|
+
3475771856,
|
|
830
|
+
888777526,
|
|
831
|
+
2678071271,
|
|
832
|
+
1649066644,
|
|
833
|
+
3373495877,
|
|
834
|
+
642096605,
|
|
835
|
+
2367432972,
|
|
836
|
+
1895232639,
|
|
837
|
+
3685695662,
|
|
838
|
+
544930376,
|
|
839
|
+
2334346905,
|
|
840
|
+
1992922090,
|
|
841
|
+
3717211963,
|
|
842
|
+
708530935,
|
|
843
|
+
2170742310,
|
|
844
|
+
2089302869,
|
|
845
|
+
3620835204,
|
|
846
|
+
738473314,
|
|
847
|
+
2271052211,
|
|
848
|
+
2058837184,
|
|
849
|
+
3522095121
|
|
850
|
+
]);
|
|
851
|
+
const U = new Uint32Array([
|
|
852
|
+
0,
|
|
853
|
+
2125799437,
|
|
854
|
+
1446245579,
|
|
855
|
+
679924934,
|
|
856
|
+
121527623,
|
|
857
|
+
2039184714,
|
|
858
|
+
1359849868,
|
|
859
|
+
800622977,
|
|
860
|
+
243055246,
|
|
861
|
+
1892260483,
|
|
862
|
+
1481592389,
|
|
863
|
+
653946440,
|
|
864
|
+
155379657,
|
|
865
|
+
2012727236,
|
|
866
|
+
1601245954,
|
|
867
|
+
566506255,
|
|
868
|
+
486110492,
|
|
869
|
+
1649169681,
|
|
870
|
+
1254785495,
|
|
871
|
+
880779738,
|
|
872
|
+
466036827,
|
|
873
|
+
1701972054,
|
|
874
|
+
1307892880,
|
|
875
|
+
859962525,
|
|
876
|
+
310759314,
|
|
877
|
+
1815146399,
|
|
878
|
+
1152793433,
|
|
879
|
+
973282132,
|
|
880
|
+
364614357,
|
|
881
|
+
1796125400,
|
|
882
|
+
1133012510,
|
|
883
|
+
1027425811,
|
|
884
|
+
972220984,
|
|
885
|
+
1195887157,
|
|
886
|
+
1874927347,
|
|
887
|
+
292830974,
|
|
888
|
+
1053603711,
|
|
889
|
+
1081710450,
|
|
890
|
+
1761559476,
|
|
891
|
+
373973945,
|
|
892
|
+
932073654,
|
|
893
|
+
1228632251,
|
|
894
|
+
1639818365,
|
|
895
|
+
520651888,
|
|
896
|
+
816844273,
|
|
897
|
+
1308962300,
|
|
898
|
+
1719925050,
|
|
899
|
+
406247735,
|
|
900
|
+
621518628,
|
|
901
|
+
1539227433,
|
|
902
|
+
1933077487,
|
|
903
|
+
227363810,
|
|
904
|
+
573948515,
|
|
905
|
+
1551950446,
|
|
906
|
+
1946564264,
|
|
907
|
+
179508901,
|
|
908
|
+
729228714,
|
|
909
|
+
1438778791,
|
|
910
|
+
2101662049,
|
|
911
|
+
66187628,
|
|
912
|
+
743012589,
|
|
913
|
+
1392269536,
|
|
914
|
+
2054851622,
|
|
915
|
+
80718891,
|
|
916
|
+
1944441968,
|
|
917
|
+
223409277,
|
|
918
|
+
634790075,
|
|
919
|
+
1533214902,
|
|
920
|
+
1960544567,
|
|
921
|
+
175024442,
|
|
922
|
+
585661948,
|
|
923
|
+
1549622769,
|
|
924
|
+
2107207422,
|
|
925
|
+
53235443,
|
|
926
|
+
732600885,
|
|
927
|
+
1428142648,
|
|
928
|
+
2057778105,
|
|
929
|
+
68293556,
|
|
930
|
+
747947890,
|
|
931
|
+
1377953663,
|
|
932
|
+
1864147308,
|
|
933
|
+
296321377,
|
|
934
|
+
959403431,
|
|
935
|
+
1201305002,
|
|
936
|
+
1747123243,
|
|
937
|
+
379051046,
|
|
938
|
+
1041303776,
|
|
939
|
+
1084500205,
|
|
940
|
+
1633688546,
|
|
941
|
+
534068207,
|
|
942
|
+
928247593,
|
|
943
|
+
1239863076,
|
|
944
|
+
1717454501,
|
|
945
|
+
418080424,
|
|
946
|
+
812495470,
|
|
947
|
+
1322816099,
|
|
948
|
+
1243037256,
|
|
949
|
+
883039813,
|
|
950
|
+
472173187,
|
|
951
|
+
1653729934,
|
|
952
|
+
1294557967,
|
|
953
|
+
865878786,
|
|
954
|
+
454727620,
|
|
955
|
+
1706014665,
|
|
956
|
+
1147897030,
|
|
957
|
+
987669707,
|
|
958
|
+
307785741,
|
|
959
|
+
1827491840,
|
|
960
|
+
1129699713,
|
|
961
|
+
1038154124,
|
|
962
|
+
359017802,
|
|
963
|
+
1808993607,
|
|
964
|
+
1458457428,
|
|
965
|
+
677079897,
|
|
966
|
+
14532511,
|
|
967
|
+
2120785810,
|
|
968
|
+
1372591635,
|
|
969
|
+
795162142,
|
|
970
|
+
132375256,
|
|
971
|
+
2035729109,
|
|
972
|
+
1486025178,
|
|
973
|
+
640143831,
|
|
974
|
+
245433617,
|
|
975
|
+
1880368412,
|
|
976
|
+
1605151901,
|
|
977
|
+
555322512,
|
|
978
|
+
161437782,
|
|
979
|
+
1999272027,
|
|
980
|
+
1284643889,
|
|
981
|
+
841432124,
|
|
982
|
+
446818554,
|
|
983
|
+
1679083767,
|
|
984
|
+
1269580150,
|
|
985
|
+
890855803,
|
|
986
|
+
497006013,
|
|
987
|
+
1663735216,
|
|
988
|
+
1122936511,
|
|
989
|
+
1012631218,
|
|
990
|
+
350048884,
|
|
991
|
+
1785229945,
|
|
992
|
+
1171323896,
|
|
993
|
+
996531189,
|
|
994
|
+
333647667,
|
|
995
|
+
1834364734,
|
|
996
|
+
1349216557,
|
|
997
|
+
786319648,
|
|
998
|
+
106470886,
|
|
999
|
+
2028846571,
|
|
1000
|
+
1465201770,
|
|
1001
|
+
702551143,
|
|
1002
|
+
23511201,
|
|
1003
|
+
2144592044,
|
|
1004
|
+
1578619811,
|
|
1005
|
+
547550126,
|
|
1006
|
+
136587112,
|
|
1007
|
+
1989216101,
|
|
1008
|
+
1495895780,
|
|
1009
|
+
664579817,
|
|
1010
|
+
253393455,
|
|
1011
|
+
1907317282,
|
|
1012
|
+
1969288713,
|
|
1013
|
+
198563332,
|
|
1014
|
+
592642754,
|
|
1015
|
+
1575363279,
|
|
1016
|
+
1918806862,
|
|
1017
|
+
216763203,
|
|
1018
|
+
611147653,
|
|
1019
|
+
1524137864,
|
|
1020
|
+
2065452167,
|
|
1021
|
+
94989450,
|
|
1022
|
+
758102092,
|
|
1023
|
+
1402640449,
|
|
1024
|
+
2082607552,
|
|
1025
|
+
43463117,
|
|
1026
|
+
705815819,
|
|
1027
|
+
1420084486,
|
|
1028
|
+
1771668245,
|
|
1029
|
+
388801304,
|
|
1030
|
+
1068136414,
|
|
1031
|
+
1092573139,
|
|
1032
|
+
1856495186,
|
|
1033
|
+
269680223,
|
|
1034
|
+
949234329,
|
|
1035
|
+
1176570516,
|
|
1036
|
+
1743075739,
|
|
1037
|
+
424679830,
|
|
1038
|
+
836160848,
|
|
1039
|
+
1331948893,
|
|
1040
|
+
1624990940,
|
|
1041
|
+
510543057,
|
|
1042
|
+
921210903,
|
|
1043
|
+
1214099482,
|
|
1044
|
+
1064814657,
|
|
1045
|
+
1103292492,
|
|
1046
|
+
1766079626,
|
|
1047
|
+
401677447,
|
|
1048
|
+
944346374,
|
|
1049
|
+
1190966539,
|
|
1050
|
+
1853514189,
|
|
1051
|
+
282018240,
|
|
1052
|
+
822833871,
|
|
1053
|
+
1337873090,
|
|
1054
|
+
1731757572,
|
|
1055
|
+
428713481,
|
|
1056
|
+
909455240,
|
|
1057
|
+
1216352133,
|
|
1058
|
+
1611062083,
|
|
1059
|
+
515111758,
|
|
1060
|
+
596557149,
|
|
1061
|
+
1564187984,
|
|
1062
|
+
1975339414,
|
|
1063
|
+
185100699,
|
|
1064
|
+
615571482,
|
|
1065
|
+
1510326295,
|
|
1066
|
+
1921193169,
|
|
1067
|
+
204879068,
|
|
1068
|
+
770836435,
|
|
1069
|
+
1397172190,
|
|
1070
|
+
2076308248,
|
|
1071
|
+
91542293,
|
|
1072
|
+
718035604,
|
|
1073
|
+
1417247385,
|
|
1074
|
+
2097131103,
|
|
1075
|
+
38440530,
|
|
1076
|
+
109388409,
|
|
1077
|
+
2016412276,
|
|
1078
|
+
1354159794,
|
|
1079
|
+
772011711,
|
|
1080
|
+
29065022,
|
|
1081
|
+
2131648307,
|
|
1082
|
+
1468566517,
|
|
1083
|
+
691907576,
|
|
1084
|
+
150575351,
|
|
1085
|
+
1984739578,
|
|
1086
|
+
1590324284,
|
|
1087
|
+
545213489,
|
|
1088
|
+
264750512,
|
|
1089
|
+
1903355325,
|
|
1090
|
+
1509175675,
|
|
1091
|
+
658575734,
|
|
1092
|
+
444356453,
|
|
1093
|
+
1690924904,
|
|
1094
|
+
1280287662,
|
|
1095
|
+
855278499,
|
|
1096
|
+
490867234,
|
|
1097
|
+
1677142575,
|
|
1098
|
+
1265762025,
|
|
1099
|
+
902094564,
|
|
1100
|
+
335605227,
|
|
1101
|
+
1790299622,
|
|
1102
|
+
1110645024,
|
|
1103
|
+
1015429421,
|
|
1104
|
+
322875564,
|
|
1105
|
+
1837863073,
|
|
1106
|
+
1158497383,
|
|
1107
|
+
1001940074
|
|
1108
|
+
]);
|
|
1109
|
+
/** `create_delta_index`. */
|
|
1110
|
+
function createDeltaIndex(buf) {
|
|
1111
|
+
const bufsize = buf.length;
|
|
1112
|
+
if (!bufsize) return void 0;
|
|
1113
|
+
let entries = Math.floor((bufsize - 1) / RABIN_WINDOW);
|
|
1114
|
+
let hsize = Math.floor(entries / 4);
|
|
1115
|
+
let i = 4;
|
|
1116
|
+
while (2 ** i < hsize) i++;
|
|
1117
|
+
hsize = 2 ** i;
|
|
1118
|
+
const hmask = hsize - 1;
|
|
1119
|
+
const ePtr = new Int32Array(entries);
|
|
1120
|
+
const eVal = new Uint32Array(entries);
|
|
1121
|
+
const eNext = new Int32Array(entries).fill(-1);
|
|
1122
|
+
const hash = new Int32Array(hsize).fill(-1);
|
|
1123
|
+
const hashCount = new Uint32Array(hsize);
|
|
1124
|
+
let n = 0;
|
|
1125
|
+
let prevVal = 4294967295;
|
|
1126
|
+
for (let data = entries * RABIN_WINDOW - RABIN_WINDOW; data >= 0; data -= RABIN_WINDOW) {
|
|
1127
|
+
let val = 0;
|
|
1128
|
+
for (let k = 1; k <= RABIN_WINDOW; k++) val = ((val << 8 | buf[data + k]) ^ T[val >>> RABIN_SHIFT]) >>> 0;
|
|
1129
|
+
if (val === prevVal) {
|
|
1130
|
+
ePtr[n - 1] = data + RABIN_WINDOW;
|
|
1131
|
+
entries--;
|
|
1132
|
+
} else {
|
|
1133
|
+
prevVal = val;
|
|
1134
|
+
const b = val & hmask;
|
|
1135
|
+
ePtr[n] = data + RABIN_WINDOW;
|
|
1136
|
+
eVal[n] = val;
|
|
1137
|
+
eNext[n] = hash[b];
|
|
1138
|
+
hash[b] = n;
|
|
1139
|
+
n++;
|
|
1140
|
+
hashCount[b] = hashCount[b] + 1;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
for (let b = 0; b < hsize; b++) {
|
|
1144
|
+
const count = hashCount[b];
|
|
1145
|
+
if (count <= HASH_LIMIT) continue;
|
|
1146
|
+
entries -= count - HASH_LIMIT;
|
|
1147
|
+
let entry = hash[b];
|
|
1148
|
+
let acc = 0;
|
|
1149
|
+
do {
|
|
1150
|
+
acc += count - HASH_LIMIT;
|
|
1151
|
+
if (acc > 0) {
|
|
1152
|
+
const keep = entry;
|
|
1153
|
+
do {
|
|
1154
|
+
entry = eNext[entry];
|
|
1155
|
+
acc -= HASH_LIMIT;
|
|
1156
|
+
} while (acc > 0);
|
|
1157
|
+
eNext[keep] = eNext[entry];
|
|
1158
|
+
}
|
|
1159
|
+
entry = eNext[entry];
|
|
1160
|
+
} while (entry >= 0);
|
|
1161
|
+
}
|
|
1162
|
+
const start = new Int32Array(hsize + 1);
|
|
1163
|
+
const ptr = new Int32Array(entries);
|
|
1164
|
+
const valOut = new Uint32Array(entries);
|
|
1165
|
+
let p = 0;
|
|
1166
|
+
for (let b = 0; b < hsize; b++) {
|
|
1167
|
+
start[b] = p;
|
|
1168
|
+
for (let e = hash[b]; e >= 0; e = eNext[e]) {
|
|
1169
|
+
ptr[p] = ePtr[e];
|
|
1170
|
+
valOut[p] = eVal[e];
|
|
1171
|
+
p++;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
start[hsize] = p;
|
|
1175
|
+
return {
|
|
1176
|
+
src: buf,
|
|
1177
|
+
mask: hmask,
|
|
1178
|
+
start,
|
|
1179
|
+
ptr,
|
|
1180
|
+
val: valOut
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
/** `create_delta`: undefined when the delta would exceed `maxSize` (0: no limit). */
|
|
1184
|
+
function createDelta(index, trg, maxSize) {
|
|
1185
|
+
const trgSize = trg.length;
|
|
1186
|
+
if (!trgSize) return void 0;
|
|
1187
|
+
let out = /* @__PURE__ */ new Uint8Array(8192);
|
|
1188
|
+
let outsize = 8192;
|
|
1189
|
+
if (maxSize && outsize >= maxSize) {
|
|
1190
|
+
outsize = maxSize + MAX_OP_SIZE + 1;
|
|
1191
|
+
out = new Uint8Array(outsize);
|
|
1192
|
+
}
|
|
1193
|
+
let outpos = 0;
|
|
1194
|
+
const grow = (size) => {
|
|
1195
|
+
const next = new Uint8Array(size);
|
|
1196
|
+
next.set(out.subarray(0, Math.min(out.length, size)));
|
|
1197
|
+
out = next;
|
|
1198
|
+
};
|
|
1199
|
+
let l = index.src.length;
|
|
1200
|
+
while (l >= 128) {
|
|
1201
|
+
out[outpos++] = (l | 128) & 255;
|
|
1202
|
+
l = Math.floor(l / 128);
|
|
1203
|
+
}
|
|
1204
|
+
out[outpos++] = l;
|
|
1205
|
+
l = trgSize;
|
|
1206
|
+
while (l >= 128) {
|
|
1207
|
+
out[outpos++] = (l | 128) & 255;
|
|
1208
|
+
l = Math.floor(l / 128);
|
|
1209
|
+
}
|
|
1210
|
+
out[outpos++] = l;
|
|
1211
|
+
const ref = index.src;
|
|
1212
|
+
const refTop = ref.length;
|
|
1213
|
+
let data = 0;
|
|
1214
|
+
const top = trgSize;
|
|
1215
|
+
outpos++;
|
|
1216
|
+
let val = 0;
|
|
1217
|
+
let i = 0;
|
|
1218
|
+
for (; i < RABIN_WINDOW && data < top; i++, data++) {
|
|
1219
|
+
out[outpos++] = trg[data];
|
|
1220
|
+
val = ((val << 8 | trg[data]) ^ T[val >>> RABIN_SHIFT]) >>> 0;
|
|
1221
|
+
}
|
|
1222
|
+
let inscnt = i;
|
|
1223
|
+
let moff = 0;
|
|
1224
|
+
let msize = 0;
|
|
1225
|
+
while (data < top) {
|
|
1226
|
+
if (msize < 4096) {
|
|
1227
|
+
val = (val ^ U[trg[data - RABIN_WINDOW]]) >>> 0;
|
|
1228
|
+
val = ((val << 8 | trg[data]) ^ T[val >>> RABIN_SHIFT]) >>> 0;
|
|
1229
|
+
const b = val & index.mask;
|
|
1230
|
+
for (let e = index.start[b]; e < index.start[b + 1]; e++) {
|
|
1231
|
+
const entryPtr = index.ptr[e];
|
|
1232
|
+
let r = entryPtr;
|
|
1233
|
+
let src = data;
|
|
1234
|
+
let refSize = refTop - r;
|
|
1235
|
+
if (index.val[e] !== val) continue;
|
|
1236
|
+
if (refSize > top - src) refSize = top - src;
|
|
1237
|
+
if (refSize <= msize) break;
|
|
1238
|
+
while (refSize-- && trg[src++] === ref[r]) r++;
|
|
1239
|
+
if (msize < r - entryPtr) {
|
|
1240
|
+
msize = r - entryPtr;
|
|
1241
|
+
moff = entryPtr;
|
|
1242
|
+
if (msize >= 4096) break;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
if (msize < 4) {
|
|
1247
|
+
if (!inscnt) outpos++;
|
|
1248
|
+
out[outpos++] = trg[data++];
|
|
1249
|
+
inscnt++;
|
|
1250
|
+
if (inscnt === 127) {
|
|
1251
|
+
out[outpos - inscnt - 1] = inscnt;
|
|
1252
|
+
inscnt = 0;
|
|
1253
|
+
}
|
|
1254
|
+
msize = 0;
|
|
1255
|
+
} else {
|
|
1256
|
+
if (inscnt) {
|
|
1257
|
+
while (moff && ref[moff - 1] === trg[data - 1]) {
|
|
1258
|
+
msize++;
|
|
1259
|
+
moff--;
|
|
1260
|
+
data--;
|
|
1261
|
+
outpos--;
|
|
1262
|
+
if (--inscnt) continue;
|
|
1263
|
+
outpos--;
|
|
1264
|
+
inscnt--;
|
|
1265
|
+
break;
|
|
1266
|
+
}
|
|
1267
|
+
out[outpos - inscnt - 1] = inscnt & 255;
|
|
1268
|
+
inscnt = 0;
|
|
1269
|
+
}
|
|
1270
|
+
const left = msize < 65536 ? 0 : msize - 65536;
|
|
1271
|
+
msize -= left;
|
|
1272
|
+
const op = outpos++;
|
|
1273
|
+
let cmd = 128;
|
|
1274
|
+
if (moff & 255) {
|
|
1275
|
+
out[outpos++] = moff & 255;
|
|
1276
|
+
cmd |= 1;
|
|
1277
|
+
}
|
|
1278
|
+
if (moff & 65280) {
|
|
1279
|
+
out[outpos++] = moff >>> 8 & 255;
|
|
1280
|
+
cmd |= 2;
|
|
1281
|
+
}
|
|
1282
|
+
if (moff & 16711680) {
|
|
1283
|
+
out[outpos++] = moff >>> 16 & 255;
|
|
1284
|
+
cmd |= 4;
|
|
1285
|
+
}
|
|
1286
|
+
if (moff & 4278190080) {
|
|
1287
|
+
out[outpos++] = moff >>> 24 & 255;
|
|
1288
|
+
cmd |= 8;
|
|
1289
|
+
}
|
|
1290
|
+
if (msize & 255) {
|
|
1291
|
+
out[outpos++] = msize & 255;
|
|
1292
|
+
cmd |= 16;
|
|
1293
|
+
}
|
|
1294
|
+
if (msize & 65280) {
|
|
1295
|
+
out[outpos++] = msize >>> 8 & 255;
|
|
1296
|
+
cmd |= 32;
|
|
1297
|
+
}
|
|
1298
|
+
out[op] = cmd;
|
|
1299
|
+
data += msize;
|
|
1300
|
+
moff += msize;
|
|
1301
|
+
msize = left;
|
|
1302
|
+
if (moff > 4294967295) msize = 0;
|
|
1303
|
+
if (msize < 4096) {
|
|
1304
|
+
val = 0;
|
|
1305
|
+
for (let j = -16; j < 0; j++) val = ((val << 8 | trg[data + j]) ^ T[val >>> RABIN_SHIFT]) >>> 0;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
if (outpos >= outsize - MAX_OP_SIZE) {
|
|
1309
|
+
outsize = Math.floor(outsize * 3 / 2);
|
|
1310
|
+
if (maxSize && outsize >= maxSize) outsize = maxSize + MAX_OP_SIZE + 1;
|
|
1311
|
+
if (maxSize && outpos > maxSize) break;
|
|
1312
|
+
grow(outsize);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
if (inscnt) out[outpos - inscnt - 1] = inscnt;
|
|
1316
|
+
if (maxSize && outpos > maxSize) return void 0;
|
|
1317
|
+
return out.slice(0, outpos);
|
|
1318
|
+
}
|
|
1319
|
+
/** `diff_delta`: the delta of `trg` against `src`, undefined past `maxSize`. */
|
|
1320
|
+
function gitDiffDelta(src, trg, maxSize) {
|
|
1321
|
+
const index = createDeltaIndex(src);
|
|
1322
|
+
if (!index) return void 0;
|
|
1323
|
+
return createDelta(index, trg, maxSize);
|
|
1324
|
+
}
|
|
1325
|
+
const EN85 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
|
|
1326
|
+
/** base85.c's `encode_85` of `bytes` bytes at `at`. */
|
|
1327
|
+
function encode85(data, at, bytes) {
|
|
1328
|
+
let out = "";
|
|
1329
|
+
while (bytes) {
|
|
1330
|
+
let acc = 0;
|
|
1331
|
+
for (let cnt = 24; cnt >= 0; cnt -= 8) {
|
|
1332
|
+
const ch = data[at++];
|
|
1333
|
+
acc = (acc | ch << cnt) >>> 0;
|
|
1334
|
+
if (--bytes === 0) break;
|
|
1335
|
+
}
|
|
1336
|
+
const chunk = [];
|
|
1337
|
+
for (let cnt = 4; cnt >= 0; cnt--) {
|
|
1338
|
+
const v = acc % 85;
|
|
1339
|
+
acc = Math.floor(acc / 85);
|
|
1340
|
+
chunk[cnt] = EN85[v];
|
|
1341
|
+
}
|
|
1342
|
+
out += chunk.join("");
|
|
1343
|
+
}
|
|
1344
|
+
return out;
|
|
1345
|
+
}
|
|
1346
|
+
function deflateIt(data) {
|
|
1347
|
+
return compressBlockPako(data, { level: 1 });
|
|
1348
|
+
}
|
|
1349
|
+
/** `emit_binary_diff_body`: one direction (`one` to `two`). */
|
|
1350
|
+
function binaryDiffBody(one, two) {
|
|
1351
|
+
const deflated = deflateIt(two);
|
|
1352
|
+
let delta;
|
|
1353
|
+
let origSize = 0;
|
|
1354
|
+
if (one.length && two.length) {
|
|
1355
|
+
const raw = gitDiffDelta(one, two, deflated.length);
|
|
1356
|
+
if (raw) {
|
|
1357
|
+
origSize = raw.length;
|
|
1358
|
+
delta = deflateIt(raw);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
let out;
|
|
1362
|
+
let data;
|
|
1363
|
+
if (delta && delta.length < deflated.length) {
|
|
1364
|
+
out = `delta ${origSize}\n`;
|
|
1365
|
+
data = delta;
|
|
1366
|
+
} else {
|
|
1367
|
+
out = `literal ${two.length}\n`;
|
|
1368
|
+
data = deflated;
|
|
1369
|
+
}
|
|
1370
|
+
for (let at = 0; at < data.length;) {
|
|
1371
|
+
const bytes = Math.min(52, data.length - at);
|
|
1372
|
+
const lead = bytes <= 26 ? String.fromCharCode(bytes + 64) : String.fromCharCode(bytes - 26 + 96);
|
|
1373
|
+
out += `${lead}${encode85(data, at, bytes)}\n`;
|
|
1374
|
+
at += bytes;
|
|
1375
|
+
}
|
|
1376
|
+
return `${out}\n`;
|
|
1377
|
+
}
|
|
1378
|
+
/** `emit_binary_diff`: "GIT binary patch", the forward and the reverse hunks. */
|
|
1379
|
+
function gitBinaryPatch(one, two) {
|
|
1380
|
+
return `GIT binary patch\n${binaryDiffBody(one, two)}${binaryDiffBody(two, one)}`;
|
|
1381
|
+
}
|
|
1382
|
+
//#endregion
|
|
1383
|
+
//#region src/results/diff-output.ts
|
|
1384
|
+
/**
|
|
1385
|
+
* git's diff output (`diff.c`) over file pairs: the patch (`git diff`), `--stat`,
|
|
1386
|
+
* `--numstat`, `--shortstat`, `--name-only` and `--name-status`, byte for byte as git prints
|
|
1387
|
+
* them.
|
|
1388
|
+
*
|
|
1389
|
+
* @example
|
|
1390
|
+
* ```typescript
|
|
1391
|
+
* const pairs: DiffFilePair[] = [{ status: "M", old: blobSide(...), new: blobSide(...) }];
|
|
1392
|
+
* const patch = await formatPatch(pairs, { context: 3, indentHeuristic: true });
|
|
1393
|
+
* const stat = formatStat(await computeDiffstat(pairs), { width: 80 });
|
|
1394
|
+
* ```
|
|
1395
|
+
*
|
|
1396
|
+
* A pair has an old and a new side; a side that does not exist (an added file's old side,
|
|
1397
|
+
* a deleted file's new side) is left out. Each file is shown as git's `builtin_diff` shows
|
|
1398
|
+
* it: the `diff --git` header with mode, rename and `index` lines, then "Binary files ...
|
|
1399
|
+
* differ" or the hunks of the text diff ({@link unifiedDiffHunks}). A pair between a file
|
|
1400
|
+
* and a symbolic link is shown as a deletion and an addition. The header of a file whose
|
|
1401
|
+
* diff comes out empty (only whitespace changes under `-w`) is printed only when it
|
|
1402
|
+
* carries news of its own (mode change, rename, new or deleted file).
|
|
1403
|
+
*
|
|
1404
|
+
* @module
|
|
1405
|
+
*/
|
|
1406
|
+
const S_IFMT = 61440;
|
|
1407
|
+
const GITLINK_MODE = 57344;
|
|
1408
|
+
const NULL_ID = "0".repeat(40);
|
|
1409
|
+
const FIRST_FEW_BYTES = 8e3;
|
|
1410
|
+
const GIT_DIFF_BIG_FILE_THRESHOLD = 536870912;
|
|
1411
|
+
const encoder = new TextEncoder();
|
|
1412
|
+
/**
|
|
1413
|
+
* The driver of a `diff` attribute value (git's `userdiff_find_by_path`): set means text,
|
|
1414
|
+
* unset means binary, a name means `diff.<name>.*` from `config` or a builtin driver.
|
|
1415
|
+
*/
|
|
1416
|
+
function diffDriverOf(attribute, config) {
|
|
1417
|
+
if (attribute === true) return { binary: false };
|
|
1418
|
+
if (attribute === false) return { binary: true };
|
|
1419
|
+
if (typeof attribute !== "string") return void 0;
|
|
1420
|
+
const name = attribute;
|
|
1421
|
+
const binary = boolValue(config?.(`diff.${name}.binary`));
|
|
1422
|
+
const algorithm = config?.(`diff.${name}.algorithm`);
|
|
1423
|
+
const findFunction = userdiffFindFunction(name, config);
|
|
1424
|
+
const textconvCommand = config?.(`diff.${name}.textconv`);
|
|
1425
|
+
const cacheTextconv = boolValue(config?.(`diff.${name}.cachetextconv`));
|
|
1426
|
+
if (binary === void 0 && !algorithm && !findFunction && textconvCommand === void 0) return;
|
|
1427
|
+
return {
|
|
1428
|
+
name,
|
|
1429
|
+
...binary !== void 0 ? { binary } : {},
|
|
1430
|
+
...algorithm ? { algorithm } : {},
|
|
1431
|
+
...findFunction ? { findFunction } : {},
|
|
1432
|
+
...textconvCommand !== void 0 ? { textconvCommand } : {},
|
|
1433
|
+
...cacheTextconv !== void 0 ? { cacheTextconv } : {}
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
/** A git boolean (`git_config_bool`), undefined when unset or not one. */
|
|
1437
|
+
const boolValue = (v) => parseGitBool(v);
|
|
1438
|
+
/** A side as the diff reads it: its content and binary state, read once */
|
|
1439
|
+
var LoadedSide = class {
|
|
1440
|
+
spec;
|
|
1441
|
+
driver;
|
|
1442
|
+
content;
|
|
1443
|
+
probed;
|
|
1444
|
+
constructor(spec, driver) {
|
|
1445
|
+
this.spec = spec;
|
|
1446
|
+
this.driver = driver;
|
|
1447
|
+
}
|
|
1448
|
+
get valid() {
|
|
1449
|
+
return this.spec !== void 0;
|
|
1450
|
+
}
|
|
1451
|
+
get mode() {
|
|
1452
|
+
return this.spec?.mode ?? 0;
|
|
1453
|
+
}
|
|
1454
|
+
get id() {
|
|
1455
|
+
return this.spec?.id ?? NULL_ID;
|
|
1456
|
+
}
|
|
1457
|
+
read() {
|
|
1458
|
+
this.content ??= this.spec ? this.spec.read() : Promise.resolve(/* @__PURE__ */ new Uint8Array(0));
|
|
1459
|
+
return this.content;
|
|
1460
|
+
}
|
|
1461
|
+
/** The bytes textconv converts ({@link DiffSideSpec.readTextconvInput}) */
|
|
1462
|
+
textconvInput() {
|
|
1463
|
+
return this.spec?.readTextconvInput ? this.spec.readTextconvInput() : this.read();
|
|
1464
|
+
}
|
|
1465
|
+
/** `diff_filespec_is_binary` */
|
|
1466
|
+
async isBinary(threshold) {
|
|
1467
|
+
if (this.driver?.binary !== void 0) return this.driver.binary;
|
|
1468
|
+
if (!this.spec) return false;
|
|
1469
|
+
return (await this.probe(threshold)).binary;
|
|
1470
|
+
}
|
|
1471
|
+
probe(threshold) {
|
|
1472
|
+
this.probed ??= (async () => {
|
|
1473
|
+
if (this.spec?.probe && !this.content) return this.spec.probe(threshold);
|
|
1474
|
+
const content = await this.read();
|
|
1475
|
+
return {
|
|
1476
|
+
size: content.length,
|
|
1477
|
+
binary: content.length > threshold || hasNul(content)
|
|
1478
|
+
};
|
|
1479
|
+
})();
|
|
1480
|
+
return this.probed;
|
|
1481
|
+
}
|
|
1482
|
+
async size(threshold) {
|
|
1483
|
+
if (!this.spec) return 0;
|
|
1484
|
+
return (await this.probe(threshold)).size;
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1487
|
+
function hasNul(content) {
|
|
1488
|
+
const n = Math.min(content.length, FIRST_FEW_BYTES);
|
|
1489
|
+
return (n === content.length ? content : content.subarray(0, n)).indexOf(0) >= 0;
|
|
1490
|
+
}
|
|
1491
|
+
function octal6(mode) {
|
|
1492
|
+
return mode.toString(8).padStart(6, "0");
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* The driver a side's content is read with (`diff_filespec_load_driver`): a regular file's;
|
|
1496
|
+
* an absent side, a symbolic link and a submodule take the default driver
|
|
1497
|
+
*/
|
|
1498
|
+
function contentDriver(spec, driver) {
|
|
1499
|
+
return spec && (spec.mode & S_IFMT) === 32768 ? driver : void 0;
|
|
1500
|
+
}
|
|
1501
|
+
async function driverOf(options, path) {
|
|
1502
|
+
if (!path || !options.driver) return void 0;
|
|
1503
|
+
return options.driver(path);
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* The patch of the pairs, as `git diff` prints it.
|
|
1507
|
+
*/
|
|
1508
|
+
async function formatPatch(pairs, options = {}) {
|
|
1509
|
+
const sink = new ByteSink();
|
|
1510
|
+
for (const pair of pairs) await writePairPatch(sink, pair, options);
|
|
1511
|
+
return sink.bytes();
|
|
1512
|
+
}
|
|
1513
|
+
/** Writes one pair as `run_diff` does: a file/symlink change as deletion and addition */
|
|
1514
|
+
async function writePairPatch(sink, pair, options = {}, report) {
|
|
1515
|
+
const { old: one, new: two } = pair;
|
|
1516
|
+
if (one && two && (one.mode & S_IFMT) !== (two.mode & S_IFMT)) {
|
|
1517
|
+
await builtinDiff(sink, {
|
|
1518
|
+
...pair,
|
|
1519
|
+
new: void 0
|
|
1520
|
+
}, options, two.path, report);
|
|
1521
|
+
await builtinDiff(sink, {
|
|
1522
|
+
...pair,
|
|
1523
|
+
old: void 0
|
|
1524
|
+
}, options, one.path, report);
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
await builtinDiff(sink, pair, options, void 0, report);
|
|
1528
|
+
}
|
|
1529
|
+
/** `fill_metainfo`: rename/copy lines and the index line; whether they force the header */
|
|
1530
|
+
function metainfo(pair, one, two, name, other, options, fullIndex = false) {
|
|
1531
|
+
const quote = options.quotePath ?? true;
|
|
1532
|
+
let text = "";
|
|
1533
|
+
let mustShow = false;
|
|
1534
|
+
if (pair.status === "R" || pair.status === "C") {
|
|
1535
|
+
const word = pair.status === "R" ? "rename" : "copy";
|
|
1536
|
+
text += `similarity index ${pair.score ?? 0}%\n`;
|
|
1537
|
+
text += `${word} from ${quotePath(name, quote)}\n`;
|
|
1538
|
+
text += `${word} to ${quotePath(other ?? name, quote)}\n`;
|
|
1539
|
+
mustShow = true;
|
|
1540
|
+
}
|
|
1541
|
+
if (one.id !== two.id) {
|
|
1542
|
+
const abbrev = (id) => id.slice(0, options.fullIndex || fullIndex ? 40 : options.abbrevLengths?.get(id) ?? options.abbrev ?? 7);
|
|
1543
|
+
text += `index ${abbrev(one.id)}..${abbrev(two.id)}`;
|
|
1544
|
+
if (one.mode === two.mode) text += ` ${octal6(one.mode)}`;
|
|
1545
|
+
text += "\n";
|
|
1546
|
+
}
|
|
1547
|
+
return {
|
|
1548
|
+
text,
|
|
1549
|
+
mustShow
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
/** git's `builtin_diff` for one pair (both sides of the same kind, or one side absent) */
|
|
1553
|
+
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)) {
|
|
1555
|
+
await options.submodulePatch(sink, pair, options);
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
const quote = options.quotePath ?? true;
|
|
1559
|
+
const threshold = options.bigFileThreshold ?? GIT_DIFF_BIG_FILE_THRESHOLD;
|
|
1560
|
+
const pathOne = pair.old?.path ?? absentPath ?? pair.new?.path ?? "";
|
|
1561
|
+
const pathTwo = pair.new?.path ?? absentPath ?? pair.old?.path ?? "";
|
|
1562
|
+
const name = pathOne;
|
|
1563
|
+
const other = pathTwo !== name ? pathTwo : void 0;
|
|
1564
|
+
const oneDriver = await driverOf(options, pathOne);
|
|
1565
|
+
const twoDriver = pathTwo === pathOne ? oneDriver : await driverOf(options, pathTwo);
|
|
1566
|
+
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver));
|
|
1567
|
+
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver));
|
|
1568
|
+
const textconvOne = one.driver?.textconv;
|
|
1569
|
+
const textconvTwo = two.driver?.textconv;
|
|
1570
|
+
const isBinary = async () => !options.text && (!textconvOne && await one.isBinary(threshold) || !textconvTwo && await two.isBinary(threshold));
|
|
1571
|
+
const meta = metainfo(pair, one, two, name, other, options, options.binaryPatch === true && one.id !== two.id && (one.valid && await one.isBinary(threshold) || two.valid && await two.isBinary(threshold)));
|
|
1572
|
+
let mustShow = meta.mustShow;
|
|
1573
|
+
const aPrefix = options.srcPrefix ?? "a/";
|
|
1574
|
+
const bPrefix = options.dstPrefix ?? "b/";
|
|
1575
|
+
const nameA = one.valid ? name : other ?? name;
|
|
1576
|
+
const nameB = two.valid ? other ?? name : nameA;
|
|
1577
|
+
const aOne = quoteTwo(aPrefix, stripSlash(nameA), quote);
|
|
1578
|
+
const bTwo = quoteTwo(bPrefix, stripSlash(nameB), quote);
|
|
1579
|
+
const lbl0 = one.valid ? aOne : "/dev/null";
|
|
1580
|
+
const lbl1 = two.valid ? bTwo : "/dev/null";
|
|
1581
|
+
let header = `diff --git ${aOne} ${bTwo}\n`;
|
|
1582
|
+
if (!one.valid) {
|
|
1583
|
+
header += `new file mode ${octal6(two.mode)}\n${meta.text}`;
|
|
1584
|
+
mustShow = true;
|
|
1585
|
+
} else if (!two.valid) {
|
|
1586
|
+
header += `deleted file mode ${octal6(one.mode)}\n${meta.text}`;
|
|
1587
|
+
mustShow = true;
|
|
1588
|
+
} else {
|
|
1589
|
+
if (one.mode !== two.mode) {
|
|
1590
|
+
header += `old mode ${octal6(one.mode)}\nnew mode ${octal6(two.mode)}\n`;
|
|
1591
|
+
mustShow = true;
|
|
1592
|
+
}
|
|
1593
|
+
header += meta.text;
|
|
1594
|
+
if ((one.mode ^ two.mode) & S_IFMT) return;
|
|
1595
|
+
}
|
|
1596
|
+
if (report) {
|
|
1597
|
+
report.gitLine = `diff --git ${aOne} ${bTwo}`;
|
|
1598
|
+
report.extended = header.slice(report.gitLine.length + 1);
|
|
1599
|
+
report.binary = false;
|
|
1600
|
+
report.result = void 0;
|
|
1601
|
+
report.oldLabel = void 0;
|
|
1602
|
+
report.newLabel = void 0;
|
|
1603
|
+
}
|
|
1604
|
+
if (await isBinary()) {
|
|
1605
|
+
if (report) report.binary = true;
|
|
1606
|
+
if (one.valid && two.valid ? one.id === two.id : await one.size(threshold) === 0 && await two.size(threshold) === 0) {
|
|
1607
|
+
if (mustShow) sink.text(header);
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1610
|
+
if (options.binaryPatch) {
|
|
1611
|
+
const a = one.valid ? await one.read() : /* @__PURE__ */ new Uint8Array(0);
|
|
1612
|
+
const b = two.valid ? await two.read() : /* @__PURE__ */ new Uint8Array(0);
|
|
1613
|
+
if (a.length === b.length && a.every((x, i) => x === b[i])) {
|
|
1614
|
+
if (mustShow) sink.text(header);
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1617
|
+
sink.text(header);
|
|
1618
|
+
sink.text(gitBinaryPatch(a, b));
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
sink.text(header);
|
|
1622
|
+
sink.text(`Binary files ${lbl0} and ${lbl1} differ\n`);
|
|
1623
|
+
return;
|
|
1624
|
+
}
|
|
1625
|
+
if (mustShow) {
|
|
1626
|
+
sink.text(header);
|
|
1627
|
+
header = "";
|
|
1628
|
+
}
|
|
1629
|
+
const driver = one.driver?.findFunction ? one.driver : two.driver;
|
|
1630
|
+
const algorithm = oneDriver?.algorithm ?? options.algorithm;
|
|
1631
|
+
const textOne = textconvOne ? await textconvOne(await one.textconvInput(), pathOne) : await one.read();
|
|
1632
|
+
const textTwo = textconvTwo ? await textconvTwo(await two.textconvInput(), pathTwo) : await two.read();
|
|
1633
|
+
const result = unifiedDiffHunks(textOne, textTwo, {
|
|
1634
|
+
...options,
|
|
1635
|
+
algorithm,
|
|
1636
|
+
indentHeuristic: options.indentHeuristic ?? true,
|
|
1637
|
+
findFunction: driver?.findFunction
|
|
1638
|
+
});
|
|
1639
|
+
if (report) report.result = result;
|
|
1640
|
+
if (result.hunks.length === 0) return;
|
|
1641
|
+
if (header) sink.text(header);
|
|
1642
|
+
const oldLabel = `--- ${lbl0}${lbl0.includes(" ") ? " " : ""}`;
|
|
1643
|
+
const newLabel = `+++ ${lbl1}${lbl1.includes(" ") ? " " : ""}`;
|
|
1644
|
+
if (report) {
|
|
1645
|
+
report.oldLabel = oldLabel;
|
|
1646
|
+
report.newLabel = newLabel;
|
|
1647
|
+
}
|
|
1648
|
+
sink.text(`${oldLabel}\n${newLabel}\n`);
|
|
1649
|
+
writeHunks(sink, result);
|
|
1650
|
+
}
|
|
1651
|
+
function stripSlash(name) {
|
|
1652
|
+
return name.startsWith("/") ? name.slice(1) : name;
|
|
1653
|
+
}
|
|
1654
|
+
/** The diffstat of the pairs (`builtin_diffstat` for each) */
|
|
1655
|
+
async function computeDiffstat(pairs, options = {}) {
|
|
1656
|
+
const threshold = options.bigFileThreshold ?? GIT_DIFF_BIG_FILE_THRESHOLD;
|
|
1657
|
+
const files = [];
|
|
1658
|
+
for (const pair of pairs) {
|
|
1659
|
+
const nameA = pair.old?.path ?? pair.new?.path ?? "";
|
|
1660
|
+
const nameB = pair.new?.path ?? nameA;
|
|
1661
|
+
const renamed = nameB !== nameA;
|
|
1662
|
+
const file = {
|
|
1663
|
+
...renamed ? { fromName: nameA } : {},
|
|
1664
|
+
name: renamed ? nameB : nameA,
|
|
1665
|
+
isRenamed: renamed,
|
|
1666
|
+
isBinary: false,
|
|
1667
|
+
added: 0,
|
|
1668
|
+
deleted: 0
|
|
1669
|
+
};
|
|
1670
|
+
files.push(file);
|
|
1671
|
+
const oneDriver = await driverOf(options, nameA);
|
|
1672
|
+
const twoDriver = nameB === nameA ? oneDriver : await driverOf(options, nameB);
|
|
1673
|
+
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver));
|
|
1674
|
+
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver));
|
|
1675
|
+
const mayDiffer = !(one.valid && two.valid && one.spec?.idValid !== false && two.spec?.idValid !== false && one.id === two.id);
|
|
1676
|
+
if (await one.isBinary(threshold) || await two.isBinary(threshold)) {
|
|
1677
|
+
file.isBinary = true;
|
|
1678
|
+
if (mayDiffer) {
|
|
1679
|
+
file.added = await two.size(threshold);
|
|
1680
|
+
file.deleted = await one.size(threshold);
|
|
1681
|
+
}
|
|
1682
|
+
} else if (mayDiffer) {
|
|
1683
|
+
const counts = diffLineCounts(await one.read(), await two.read(), {
|
|
1684
|
+
...options,
|
|
1685
|
+
algorithm: oneDriver?.algorithm ?? options.algorithm,
|
|
1686
|
+
indentHeuristic: options.indentHeuristic ?? true
|
|
1687
|
+
});
|
|
1688
|
+
file.added = counts.added;
|
|
1689
|
+
file.deleted = counts.deleted;
|
|
1690
|
+
if (one.valid && two.valid && pair.status === "M" && !file.added && !file.deleted && one.mode === two.mode) files.pop();
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
return files;
|
|
1694
|
+
}
|
|
1695
|
+
/** git's `pprint_rename`: `a/{b => c}/d` */
|
|
1696
|
+
function pprintRename(a, b, quote = true) {
|
|
1697
|
+
const qa = quoteCStyleBody(a, quote);
|
|
1698
|
+
const qb = quoteCStyleBody(b, quote);
|
|
1699
|
+
if (qa !== void 0 || qb !== void 0) return `${quotePath(a, quote)} => ${quotePath(b, quote)}`;
|
|
1700
|
+
const ea = encodeGitPath(a);
|
|
1701
|
+
const eb = encodeGitPath(b);
|
|
1702
|
+
const lenA = ea.length;
|
|
1703
|
+
const lenB = eb.length;
|
|
1704
|
+
let pfx = 0;
|
|
1705
|
+
let i = 0;
|
|
1706
|
+
while (i < lenA && i < lenB && ea[i] === eb[i]) {
|
|
1707
|
+
if (ea[i] === 47) pfx = i + 1;
|
|
1708
|
+
i++;
|
|
1709
|
+
}
|
|
1710
|
+
let oa = lenA;
|
|
1711
|
+
let ob = lenB;
|
|
1712
|
+
let sfx = 0;
|
|
1713
|
+
const adjust = pfx ? 1 : 0;
|
|
1714
|
+
const at = (arr, k) => k < arr.length ? arr[k] : 0;
|
|
1715
|
+
while (pfx - adjust <= oa && pfx - adjust <= ob && at(ea, oa) === at(eb, ob)) {
|
|
1716
|
+
if (at(ea, oa) === 47) sfx = lenA - oa;
|
|
1717
|
+
oa--;
|
|
1718
|
+
ob--;
|
|
1719
|
+
}
|
|
1720
|
+
const aMid = Math.max(0, lenA - pfx - sfx);
|
|
1721
|
+
const bMid = Math.max(0, lenB - pfx - sfx);
|
|
1722
|
+
const dec = (arr, s, e) => decodeGitPath(arr.subarray(s, e));
|
|
1723
|
+
let out = "";
|
|
1724
|
+
if (pfx + sfx) out += `${dec(ea, 0, pfx)}{`;
|
|
1725
|
+
out += `${dec(ea, pfx, pfx + aMid)} => ${dec(eb, pfx, pfx + bMid)}`;
|
|
1726
|
+
if (pfx + sfx) out += `}${dec(ea, lenA - sfx, lenA)}`;
|
|
1727
|
+
return out;
|
|
1728
|
+
}
|
|
1729
|
+
function printName(file, quote) {
|
|
1730
|
+
if (file.isRenamed && file.fromName !== void 0) return pprintRename(file.fromName, file.name, quote);
|
|
1731
|
+
return quotePath(file.name, quote);
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Display width of a name, as git's utf8_strwidth measures it (git 2.56's character widths:
|
|
1735
|
+
* wide East Asian characters and emoji two columns, combining marks none; a name that is not
|
|
1736
|
+
* valid UTF-8 its byte count)
|
|
1737
|
+
*/
|
|
1738
|
+
function displayWidth(s) {
|
|
1739
|
+
let ascii = true;
|
|
1740
|
+
let width = 0;
|
|
1741
|
+
for (let i = 0; i < s.length; i++) {
|
|
1742
|
+
const c = s.charCodeAt(i);
|
|
1743
|
+
if (c >= 127) {
|
|
1744
|
+
ascii = false;
|
|
1745
|
+
break;
|
|
1746
|
+
}
|
|
1747
|
+
if (c >= 32) width++;
|
|
1748
|
+
}
|
|
1749
|
+
return ascii ? width : gitStrWidth(encodeGitPath(s));
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* git's show_stats "scales" a name too wide for `width` columns: leading characters dropped
|
|
1753
|
+
* (diff.c's utf8_ish_width steps, byte by byte through what is not UTF-8) until the rest fits
|
|
1754
|
+
* in `width - 3`, then up to its first slash when it has one, behind a `...` prefix.
|
|
1755
|
+
*/
|
|
1756
|
+
function shortenName(name, width) {
|
|
1757
|
+
let nameLen = displayWidth(name);
|
|
1758
|
+
if (width >= nameLen) return {
|
|
1759
|
+
prefix: "",
|
|
1760
|
+
name,
|
|
1761
|
+
len: width
|
|
1762
|
+
};
|
|
1763
|
+
const len = Math.max(0, width - 3);
|
|
1764
|
+
const bytes = encodeGitPath(name);
|
|
1765
|
+
let at = 0;
|
|
1766
|
+
while (nameLen > len && at < bytes.length) {
|
|
1767
|
+
const [w, next] = gitCharWidthAt(bytes, at);
|
|
1768
|
+
nameLen -= w;
|
|
1769
|
+
at = next;
|
|
1770
|
+
}
|
|
1771
|
+
let rest = bytes.subarray(at);
|
|
1772
|
+
const slash = rest.indexOf(47);
|
|
1773
|
+
if (slash >= 0) rest = rest.subarray(slash);
|
|
1774
|
+
return {
|
|
1775
|
+
prefix: "...",
|
|
1776
|
+
name: decodeGitPath(rest),
|
|
1777
|
+
len
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
function decimalWidth(n) {
|
|
1781
|
+
let width = 1;
|
|
1782
|
+
for (let v = n; v >= 10; v = Math.floor(v / 10)) width++;
|
|
1783
|
+
return width;
|
|
1784
|
+
}
|
|
1785
|
+
function scaleLinear(it, width, maxChange) {
|
|
1786
|
+
if (!it) return 0;
|
|
1787
|
+
return 1 + Math.floor(it * (width - 1) / maxChange);
|
|
1788
|
+
}
|
|
1789
|
+
/** git's `print_stat_summary_inserts_deletes` */
|
|
1790
|
+
function statSummary(files, insertions, deletions) {
|
|
1791
|
+
if (!files) return " 0 files changed\n";
|
|
1792
|
+
let s = files === 1 ? ` ${files} file changed` : ` ${files} files changed`;
|
|
1793
|
+
if (insertions || deletions === 0) s += insertions === 1 ? `, ${insertions} insertion(+)` : `, ${insertions} insertions(+)`;
|
|
1794
|
+
if (deletions || insertions === 0) s += deletions === 1 ? `, ${deletions} deletion(-)` : `, ${deletions} deletions(-)`;
|
|
1795
|
+
return `${s}\n`;
|
|
1796
|
+
}
|
|
1797
|
+
/** `--stat`, as git's `show_stats` prints it */
|
|
1798
|
+
function formatStat(files, options = {}) {
|
|
1799
|
+
if (files.length === 0) return "";
|
|
1800
|
+
const quote = options.quotePath ?? true;
|
|
1801
|
+
const isInteresting = (_f) => true;
|
|
1802
|
+
let count = options.count ?? files.length;
|
|
1803
|
+
let maxChange = 0;
|
|
1804
|
+
let maxLen = 0;
|
|
1805
|
+
let numberWidth = 0;
|
|
1806
|
+
let binWidth = 0;
|
|
1807
|
+
const names = /* @__PURE__ */ new Map();
|
|
1808
|
+
let i = 0;
|
|
1809
|
+
for (; i < count && i < files.length; i++) {
|
|
1810
|
+
const file = files[i];
|
|
1811
|
+
const change = file.added + file.deleted;
|
|
1812
|
+
if (!isInteresting(file) && change === 0) {
|
|
1813
|
+
count++;
|
|
1814
|
+
continue;
|
|
1815
|
+
}
|
|
1816
|
+
const name = printName(file, quote);
|
|
1817
|
+
names.set(file, name);
|
|
1818
|
+
const len = displayWidth(name);
|
|
1819
|
+
if (maxLen < len) maxLen = len;
|
|
1820
|
+
if (file.isUnmerged) {
|
|
1821
|
+
binWidth = binWidth < 8 ? 8 : binWidth;
|
|
1822
|
+
continue;
|
|
1823
|
+
}
|
|
1824
|
+
if (file.isBinary) {
|
|
1825
|
+
const w = 14 + decimalWidth(file.added) + decimalWidth(file.deleted);
|
|
1826
|
+
binWidth = binWidth < w ? w : binWidth;
|
|
1827
|
+
numberWidth = 3;
|
|
1828
|
+
continue;
|
|
1829
|
+
}
|
|
1830
|
+
if (maxChange < change) maxChange = change;
|
|
1831
|
+
}
|
|
1832
|
+
count = i;
|
|
1833
|
+
let width = options.width ?? 80;
|
|
1834
|
+
numberWidth = decimalWidth(maxChange) > numberWidth ? decimalWidth(maxChange) : numberWidth;
|
|
1835
|
+
const statNameWidth = options.nameWidth ?? 0;
|
|
1836
|
+
const statGraphWidth = options.graphWidth ?? 0;
|
|
1837
|
+
if (width < 22 + numberWidth) width = 22 + numberWidth;
|
|
1838
|
+
let graphWidth = maxChange + 4 > binWidth ? maxChange : binWidth - 4;
|
|
1839
|
+
if (statGraphWidth && statGraphWidth < graphWidth) graphWidth = statGraphWidth;
|
|
1840
|
+
let nameWidth = statNameWidth > 0 && statNameWidth < maxLen ? statNameWidth : maxLen;
|
|
1841
|
+
if (nameWidth + numberWidth + 6 + graphWidth > width) {
|
|
1842
|
+
if (graphWidth > Math.trunc(width * 3 / 8) - numberWidth - 6) {
|
|
1843
|
+
graphWidth = Math.trunc(width * 3 / 8) - numberWidth - 6;
|
|
1844
|
+
if (graphWidth < 6) graphWidth = 6;
|
|
1845
|
+
}
|
|
1846
|
+
if (statGraphWidth && graphWidth > statGraphWidth) graphWidth = statGraphWidth;
|
|
1847
|
+
if (nameWidth > width - numberWidth - 6 - graphWidth) nameWidth = width - numberWidth - 6 - graphWidth;
|
|
1848
|
+
else graphWidth = width - numberWidth - 6 - nameWidth;
|
|
1849
|
+
}
|
|
1850
|
+
let out = "";
|
|
1851
|
+
for (i = 0; i < count; i++) {
|
|
1852
|
+
const file = files[i];
|
|
1853
|
+
const added = file.added;
|
|
1854
|
+
const deleted = file.deleted;
|
|
1855
|
+
if (!isInteresting(file) && added + deleted === 0) continue;
|
|
1856
|
+
let name = names.get(file) ?? printName(file, quote);
|
|
1857
|
+
const shortened = shortenName(name, nameWidth);
|
|
1858
|
+
const prefix = shortened.prefix;
|
|
1859
|
+
const len = shortened.len;
|
|
1860
|
+
name = shortened.name;
|
|
1861
|
+
const padding = Math.max(0, len - displayWidth(name));
|
|
1862
|
+
const pad = " ".repeat(padding);
|
|
1863
|
+
if (file.isBinary) {
|
|
1864
|
+
out += ` ${prefix}${name}${pad} | ${"Bin".padStart(numberWidth)}`;
|
|
1865
|
+
if (!added && !deleted) {
|
|
1866
|
+
out += "\n";
|
|
1867
|
+
continue;
|
|
1868
|
+
}
|
|
1869
|
+
out += ` ${deleted} -> ${added} bytes\n`;
|
|
1870
|
+
continue;
|
|
1871
|
+
}
|
|
1872
|
+
if (file.isUnmerged) {
|
|
1873
|
+
out += ` ${prefix}${name}${pad} | ${"Unmerged\n".padStart(numberWidth)}`;
|
|
1874
|
+
continue;
|
|
1875
|
+
}
|
|
1876
|
+
let add = added;
|
|
1877
|
+
let del = deleted;
|
|
1878
|
+
if (graphWidth <= maxChange) {
|
|
1879
|
+
let total = scaleLinear(add + del, graphWidth, maxChange);
|
|
1880
|
+
if (total < 2 && add && del) total = 2;
|
|
1881
|
+
if (add < del) {
|
|
1882
|
+
add = scaleLinear(add, graphWidth, maxChange);
|
|
1883
|
+
del = total - add;
|
|
1884
|
+
} else {
|
|
1885
|
+
del = scaleLinear(del, graphWidth, maxChange);
|
|
1886
|
+
add = total - del;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
out += ` ${prefix}${name}${pad} | ${String(added + deleted).padStart(numberWidth)}`;
|
|
1890
|
+
out += added + deleted ? " " : "";
|
|
1891
|
+
out += "+".repeat(Math.max(0, add));
|
|
1892
|
+
out += "-".repeat(Math.max(0, del));
|
|
1893
|
+
out += "\n";
|
|
1894
|
+
}
|
|
1895
|
+
let totalFiles = files.length;
|
|
1896
|
+
let adds = 0;
|
|
1897
|
+
let dels = 0;
|
|
1898
|
+
let extraShown = false;
|
|
1899
|
+
for (i = 0; i < files.length; i++) {
|
|
1900
|
+
const file = files[i];
|
|
1901
|
+
if (file.isUnmerged || !isInteresting(file) && file.added + file.deleted === 0) {
|
|
1902
|
+
totalFiles--;
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1905
|
+
if (!file.isBinary) {
|
|
1906
|
+
adds += file.added;
|
|
1907
|
+
dels += file.deleted;
|
|
1908
|
+
}
|
|
1909
|
+
if (i < count) continue;
|
|
1910
|
+
if (!extraShown) out += " ...\n";
|
|
1911
|
+
extraShown = true;
|
|
1912
|
+
}
|
|
1913
|
+
return out + statSummary(totalFiles, adds, dels);
|
|
1914
|
+
}
|
|
1915
|
+
/** `--shortstat` (git's `show_shortstats`) */
|
|
1916
|
+
function formatShortstat(files) {
|
|
1917
|
+
if (files.length === 0) return "";
|
|
1918
|
+
let totalFiles = files.length;
|
|
1919
|
+
let adds = 0;
|
|
1920
|
+
let dels = 0;
|
|
1921
|
+
for (const file of files) if (file.isUnmerged) totalFiles--;
|
|
1922
|
+
else if (!file.isBinary) {
|
|
1923
|
+
adds += file.added;
|
|
1924
|
+
dels += file.deleted;
|
|
1925
|
+
}
|
|
1926
|
+
return statSummary(totalFiles, adds, dels);
|
|
1927
|
+
}
|
|
1928
|
+
/** `--numstat` (git's `show_numstat`) */
|
|
1929
|
+
function formatNumstat(files, options = {}) {
|
|
1930
|
+
const quote = options.quotePath ?? true;
|
|
1931
|
+
let out = "";
|
|
1932
|
+
for (const file of files) {
|
|
1933
|
+
out += file.isBinary ? "- - " : `${file.added}\t${file.deleted}\t`;
|
|
1934
|
+
out += file.isRenamed ? printName(file, quote) : quotePath(file.name, quote);
|
|
1935
|
+
out += "\n";
|
|
1936
|
+
}
|
|
1937
|
+
return out;
|
|
1938
|
+
}
|
|
1939
|
+
/** `--name-only`: the new path of each pair */
|
|
1940
|
+
function formatNameOnly(pairs, options = {}) {
|
|
1941
|
+
const quote = options.quotePath ?? true;
|
|
1942
|
+
return pairs.map((p) => `${quotePath(p.new?.path ?? p.old?.path ?? "", quote)}\n`).join("");
|
|
1943
|
+
}
|
|
1944
|
+
/** `--name-status` (git's `diff_flush_raw` with `DIFF_FORMAT_NAME_STATUS`) */
|
|
1945
|
+
function formatNameStatus(pairs, options = {}) {
|
|
1946
|
+
const quote = options.quotePath ?? true;
|
|
1947
|
+
let out = "";
|
|
1948
|
+
for (const p of pairs) {
|
|
1949
|
+
const score = p.status === "R" || p.status === "C" ? p.score ?? 0 : 0;
|
|
1950
|
+
out += score ? `${p.status}${String(score).padStart(3, "0")}\t` : `${p.status}\t`;
|
|
1951
|
+
if (p.status === "R" || p.status === "C") out += `${quotePath(p.old?.path ?? "", quote)}\t${quotePath(p.new?.path ?? "", quote)}\n`;
|
|
1952
|
+
else out += `${quotePath(p.old ? p.old.path : p.new?.path ?? "", quote)}\n`;
|
|
1953
|
+
}
|
|
1954
|
+
return out;
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* `--summary` (diff.c's diff_summary for each pair): ` create mode 100644 <path>`, ` delete
|
|
1958
|
+
* mode ...`, ` rename <a => b> (<n>%)` and ` copy ...` (then their mode change), ` mode change
|
|
1959
|
+
* 100644 => 100755 <path>`; empty when nothing is to be said (git's is_summary_empty).
|
|
1960
|
+
*/
|
|
1961
|
+
function formatSummary(pairs, quote = true) {
|
|
1962
|
+
const mode6 = (mode) => mode.toString(8).padStart(6, "0");
|
|
1963
|
+
const modeChange = (p, showName) => {
|
|
1964
|
+
const a = p.old?.mode ?? 0;
|
|
1965
|
+
const b = p.new?.mode ?? 0;
|
|
1966
|
+
if (!a || !b || a === b) return "";
|
|
1967
|
+
const name = showName ? ` ${quotePath(p.new?.path ?? "", quote)}` : "";
|
|
1968
|
+
return ` mode change ${mode6(a)} => ${mode6(b)}${name}\n`;
|
|
1969
|
+
};
|
|
1970
|
+
const fileModeName = (what, side) => side?.mode ? ` ${what} mode ${mode6(side.mode)} ${quotePath(side.path, quote)}\n` : ` ${what} ${quotePath(side?.path ?? "", quote)}\n`;
|
|
1971
|
+
let out = "";
|
|
1972
|
+
for (const p of pairs) switch (p.status) {
|
|
1973
|
+
case "D":
|
|
1974
|
+
out += fileModeName("delete", p.old);
|
|
1975
|
+
break;
|
|
1976
|
+
case "A":
|
|
1977
|
+
out += fileModeName("create", p.new);
|
|
1978
|
+
break;
|
|
1979
|
+
case "R":
|
|
1980
|
+
case "C": {
|
|
1981
|
+
const kind = p.status === "R" ? "rename" : "copy";
|
|
1982
|
+
const names = pprintRename(p.old?.path ?? "", p.new?.path ?? "", quote);
|
|
1983
|
+
out += ` ${kind} ${names} (${p.score ?? 0}%)\n`;
|
|
1984
|
+
out += modeChange(p, false);
|
|
1985
|
+
break;
|
|
1986
|
+
}
|
|
1987
|
+
default:
|
|
1988
|
+
if (p.score) out += ` rewrite ${quotePath(p.new?.path ?? "", quote)} (${p.score}%)\n`;
|
|
1989
|
+
out += modeChange(p, !p.score);
|
|
1990
|
+
}
|
|
1991
|
+
return out;
|
|
1992
|
+
}
|
|
1993
|
+
/**
|
|
1994
|
+
* A side whose content is a stored blob (a submodule's: "Subproject commit <id>\n", as git
|
|
1995
|
+
* shows a gitlink). The probe reads a text blob once and keeps it for {@link DiffSideSpec.read}.
|
|
1996
|
+
*/
|
|
1997
|
+
function blobSide(blobs, path, mode, id) {
|
|
1998
|
+
if ((mode & S_IFMT) === 57344) {
|
|
1999
|
+
const content = encoder.encode(`Subproject commit ${id}\n`);
|
|
2000
|
+
return {
|
|
2001
|
+
path,
|
|
2002
|
+
mode,
|
|
2003
|
+
id,
|
|
2004
|
+
read: async () => content
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
let loaded;
|
|
2008
|
+
return {
|
|
2009
|
+
path,
|
|
2010
|
+
mode,
|
|
2011
|
+
id,
|
|
2012
|
+
async read() {
|
|
2013
|
+
if (loaded) return loaded;
|
|
2014
|
+
const chunks = [];
|
|
2015
|
+
let size = 0;
|
|
2016
|
+
for await (const chunk of await blobs.load(id) ?? []) {
|
|
2017
|
+
chunks.push(chunk);
|
|
2018
|
+
size += chunk.length;
|
|
2019
|
+
}
|
|
2020
|
+
const out = new Uint8Array(size);
|
|
2021
|
+
let at = 0;
|
|
2022
|
+
for (const c of chunks) {
|
|
2023
|
+
out.set(c, at);
|
|
2024
|
+
at += c.length;
|
|
2025
|
+
}
|
|
2026
|
+
loaded = out;
|
|
2027
|
+
return out;
|
|
2028
|
+
},
|
|
2029
|
+
async probe(bigFileThreshold) {
|
|
2030
|
+
const probe = await probeBlob(blobs, id, {
|
|
2031
|
+
bigFileThreshold,
|
|
2032
|
+
loadText: true
|
|
2033
|
+
});
|
|
2034
|
+
if (probe.content) loaded = probe.content;
|
|
2035
|
+
return {
|
|
2036
|
+
size: probe.size,
|
|
2037
|
+
binary: probe.binary
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
}
|
|
2042
|
+
/** A side whose content comes from elsewhere (a worktree file, a file outside a repository) */
|
|
2043
|
+
function contentSide(path, mode, id, read, idValid = false) {
|
|
2044
|
+
let content;
|
|
2045
|
+
return {
|
|
2046
|
+
path,
|
|
2047
|
+
mode,
|
|
2048
|
+
id,
|
|
2049
|
+
idValid,
|
|
2050
|
+
read: () => {
|
|
2051
|
+
content ??= read();
|
|
2052
|
+
return content;
|
|
2053
|
+
}
|
|
2054
|
+
};
|
|
2055
|
+
}
|
|
2056
|
+
/**
|
|
2057
|
+
* Bytes for a string (diff output pieces are UTF-8; a path's escaped bytes, unquoted with
|
|
2058
|
+
* `core.quotePath=false`, are written as the bytes they stand for)
|
|
2059
|
+
*/
|
|
2060
|
+
function utf8(s) {
|
|
2061
|
+
return encodeGitPath(s);
|
|
2062
|
+
}
|
|
2063
|
+
/** The blob id of `content` (as `hash-object` computes it) */
|
|
2064
|
+
function blobIdOf(content) {
|
|
2065
|
+
return bytesToHex(createSha1().update(encoder.encode(`blob ${content.length}\0`)).update(content).digest());
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* The pair `diff --no-index a b` compares for two files: a modification between two names
|
|
2069
|
+
* (no rename detection), or an addition or deletion against `/dev/null`.
|
|
2070
|
+
*/
|
|
2071
|
+
function noIndexPair(a, b) {
|
|
2072
|
+
const side = (f) => {
|
|
2073
|
+
if (!f.content) return void 0;
|
|
2074
|
+
const content = f.content;
|
|
2075
|
+
return contentSide(f.path, f.mode ?? 33188, blobIdOf(content), async () => content);
|
|
2076
|
+
};
|
|
2077
|
+
const old = side(a);
|
|
2078
|
+
const neu = side(b);
|
|
2079
|
+
if (!old && !neu) return void 0;
|
|
2080
|
+
if (old && neu && old.id === neu.id && old.mode === neu.mode) return void 0;
|
|
2081
|
+
return {
|
|
2082
|
+
status: !old ? "A" : !neu ? "D" : "M",
|
|
2083
|
+
old,
|
|
2084
|
+
new: neu
|
|
2085
|
+
};
|
|
2086
|
+
}
|
|
2087
|
+
/** `diff --no-index a b` for two files, as git prints it */
|
|
2088
|
+
async function formatNoIndexDiff(a, b, options = {}) {
|
|
2089
|
+
const pair = noIndexPair(a, b);
|
|
2090
|
+
return pair ? formatPatch([pair], options) : /* @__PURE__ */ new Uint8Array(0);
|
|
2091
|
+
}
|
|
2092
|
+
//#endregion
|
|
2093
|
+
//#region src/results/diff-formatter.ts
|
|
2094
|
+
/**
|
|
2095
|
+
* Formatter for unified diffs of DiffEntry objects, byte for byte as `git diff` prints them
|
|
2096
|
+
* (see {@link formatPatch} for the rules).
|
|
2097
|
+
*/
|
|
2098
|
+
const decoder = new TextDecoder();
|
|
2099
|
+
/** The file pair of a diff entry: blob sides, or the content the entry reads */
|
|
2100
|
+
function diffEntryToPair(entry, blobs) {
|
|
2101
|
+
const side = (path, mode, id, read, idValid = false) => {
|
|
2102
|
+
if (path === void 0 || id === void 0) return void 0;
|
|
2103
|
+
const m = mode ?? 33188;
|
|
2104
|
+
return read ? contentSide(path, m, id, read, idValid) : blobSide(blobs, path, m, id);
|
|
2105
|
+
};
|
|
2106
|
+
const status = entry.changeType === "ADD" ? "A" : entry.changeType === "DELETE" ? "D" : entry.changeType === "RENAME" ? "R" : entry.changeType === "COPY" ? "C" : entry.oldMode !== void 0 && entry.newMode !== void 0 && (entry.oldMode & 61440) !== (entry.newMode & 61440) ? "T" : "M";
|
|
2107
|
+
const newSide = status === "D" ? void 0 : side(entry.newPath ?? entry.oldPath, entry.newMode, entry.newId, entry.readNew, entry.newDirtySubmodule === true && entry.newIdUnknown !== true);
|
|
2108
|
+
if (newSide && entry.newSubmoduleDirt) newSide.submoduleDirt = entry.newSubmoduleDirt;
|
|
2109
|
+
return {
|
|
2110
|
+
status,
|
|
2111
|
+
old: status === "A" ? void 0 : side(entry.oldPath ?? entry.newPath, entry.oldMode, entry.oldId, entry.readOld),
|
|
2112
|
+
new: newSide,
|
|
2113
|
+
...entry.score !== void 0 ? { score: entry.score } : {}
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* Format DiffEntry objects into unified diff format, as `git diff` prints them.
|
|
2118
|
+
*
|
|
2119
|
+
* @example
|
|
2120
|
+
* ```typescript
|
|
2121
|
+
* const formatter = new DiffFormatter(store.blobs);
|
|
2122
|
+
*
|
|
2123
|
+
* // Get diff entries from DiffCommand
|
|
2124
|
+
* const entries = await git.diff().setOldTree(commitA).setNewTree(commitB).call();
|
|
2125
|
+
*
|
|
2126
|
+
* // Format as unified diff
|
|
2127
|
+
* process.stdout.write(await formatter.formatAll(entries));
|
|
2128
|
+
* ```
|
|
2129
|
+
*/
|
|
2130
|
+
var DiffFormatter = class {
|
|
2131
|
+
blobs;
|
|
2132
|
+
includeHeaders;
|
|
2133
|
+
output;
|
|
2134
|
+
constructor(blobs, options = {}) {
|
|
2135
|
+
this.blobs = blobs;
|
|
2136
|
+
const { contextLines, includeHeaders, abbreviateIds, abbreviationLength, algorithm, bigFileThreshold, ...rest } = options;
|
|
2137
|
+
this.includeHeaders = includeHeaders ?? true;
|
|
2138
|
+
this.output = {
|
|
2139
|
+
...rest,
|
|
2140
|
+
context: rest.context ?? contextLines ?? 3,
|
|
2141
|
+
algorithm: algorithm ? String(algorithm) : "myers",
|
|
2142
|
+
abbrev: abbreviationLength ?? rest.abbrev ?? 7,
|
|
2143
|
+
fullIndex: rest.fullIndex ?? abbreviateIds === false,
|
|
2144
|
+
bigFileThreshold: bigFileThreshold ?? DEFAULT_BIG_FILE_THRESHOLD
|
|
2145
|
+
};
|
|
2146
|
+
}
|
|
2147
|
+
/**
|
|
2148
|
+
* Format a DiffEntry into a content diff.
|
|
2149
|
+
*
|
|
2150
|
+
* Each side is probed first (its size, and a NUL byte in its first 8000
|
|
2151
|
+
* bytes, as git checks). A side over `bigFileThreshold` or binary makes the
|
|
2152
|
+
* entry binary, and then the other side is not loaded. Text sides are loaded
|
|
2153
|
+
* whole, as the diff algorithms need them, by the same single read as the probe.
|
|
2154
|
+
*
|
|
2155
|
+
* @param entry The diff entry to format
|
|
2156
|
+
* @returns Content diff with hunks
|
|
2157
|
+
*/
|
|
2158
|
+
async format(entry) {
|
|
2159
|
+
const sink = new ByteSink();
|
|
2160
|
+
const report = {
|
|
2161
|
+
binary: false,
|
|
2162
|
+
gitLine: "",
|
|
2163
|
+
extended: ""
|
|
2164
|
+
};
|
|
2165
|
+
await writePairPatch(sink, diffEntryToPair(entry, this.blobs), this.output, report);
|
|
2166
|
+
const result = {
|
|
2167
|
+
entry,
|
|
2168
|
+
isBinary: report.binary,
|
|
2169
|
+
header: report.gitLine,
|
|
2170
|
+
hunks: [],
|
|
2171
|
+
patch: sink.bytes()
|
|
2172
|
+
};
|
|
2173
|
+
if (this.includeHeaders) {
|
|
2174
|
+
result.extendedHeaders = report.extended;
|
|
2175
|
+
const index = /^index .*$/m.exec(report.extended);
|
|
2176
|
+
if (index) result.indexLine = index[0];
|
|
2177
|
+
if (report.oldLabel) result.oldFileHeader = report.oldLabel;
|
|
2178
|
+
if (report.newLabel) result.newFileHeader = report.newLabel;
|
|
2179
|
+
}
|
|
2180
|
+
const diff = report.result;
|
|
2181
|
+
if (diff) {
|
|
2182
|
+
if (entry.changeType !== "ADD") result.oldContent = diff.old.content;
|
|
2183
|
+
if (entry.changeType !== "DELETE") result.newContent = diff.new.content;
|
|
2184
|
+
for (const hunk of diff.hunks) {
|
|
2185
|
+
const lines = [];
|
|
2186
|
+
for (const line of hunk.lines) {
|
|
2187
|
+
const rec = (line.kind === "-" ? diff.old : diff.new).line(line.index);
|
|
2188
|
+
const complete = rec.length > 0 && rec[rec.length - 1] === 10;
|
|
2189
|
+
lines.push(line.kind + decoder.decode(complete ? rec.subarray(0, -1) : rec));
|
|
2190
|
+
if (!complete) lines.push("\");
|
|
2191
|
+
}
|
|
2192
|
+
result.hunks.push({
|
|
2193
|
+
oldStart: hunk.oldStart,
|
|
2194
|
+
oldCount: hunk.oldCount,
|
|
2195
|
+
newStart: hunk.newStart,
|
|
2196
|
+
newCount: hunk.newCount,
|
|
2197
|
+
functionName: decoder.decode(hunk.func),
|
|
2198
|
+
lines
|
|
2199
|
+
});
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
return result;
|
|
2203
|
+
}
|
|
2204
|
+
/**
|
|
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.
|
|
2208
|
+
*
|
|
2209
|
+
* @param diff The content diff to stringify
|
|
2210
|
+
* @returns Unified diff string
|
|
2211
|
+
*/
|
|
2212
|
+
toString(diff) {
|
|
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
|
+
}
|
|
2218
|
+
/**
|
|
2219
|
+
* Format all diff entries to a single string, as `git diff` prints them.
|
|
2220
|
+
*
|
|
2221
|
+
* @param entries Array of diff entries
|
|
2222
|
+
* @returns Complete unified diff output
|
|
2223
|
+
*/
|
|
2224
|
+
async formatAll(entries) {
|
|
2225
|
+
const parts = [];
|
|
2226
|
+
for (const entry of entries) parts.push(this.toString(await this.format(entry)));
|
|
2227
|
+
return parts.join("");
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* All diff entries as the bytes `git diff` prints (content that is not UTF-8 kept as it is).
|
|
2231
|
+
*/
|
|
2232
|
+
async formatBytes(entries) {
|
|
2233
|
+
const sink = new ByteSink();
|
|
2234
|
+
for (const entry of entries) sink.push((await this.format(entry)).patch);
|
|
2235
|
+
return sink.bytes();
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
//#endregion
|
|
2239
|
+
//#region src/results/diff-order.ts
|
|
2240
|
+
/**
|
|
2241
|
+
* git's `diffcore-order.c` (`-O<orderfile>`, `diff.orderFile`): file pairs reordered by the
|
|
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
|
|
2257
|
+
*/
|
|
2258
|
+
/** The patterns of an order file (git's `prepare_order`) */
|
|
2259
|
+
function parseOrderFile(content) {
|
|
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);
|
|
2290
|
+
}
|
|
2291
|
+
//#endregion
|
|
2292
|
+
//#region src/results/status-result.ts
|
|
2293
|
+
/**
|
|
2294
|
+
* Implementation of the Status interface.
|
|
2295
|
+
*/
|
|
2296
|
+
var StatusImpl = class {
|
|
2297
|
+
added;
|
|
2298
|
+
changed;
|
|
2299
|
+
removed;
|
|
2300
|
+
conflicting;
|
|
2301
|
+
modified;
|
|
2302
|
+
missing;
|
|
2303
|
+
untracked;
|
|
2304
|
+
ignored;
|
|
2305
|
+
conflictingStageState;
|
|
2306
|
+
files;
|
|
2307
|
+
renamed;
|
|
2308
|
+
warnings;
|
|
2309
|
+
constructor(added, changed, removed, conflicting, worktree = {}) {
|
|
2310
|
+
this.added = added;
|
|
2311
|
+
this.changed = changed;
|
|
2312
|
+
this.removed = removed;
|
|
2313
|
+
this.conflicting = conflicting;
|
|
2314
|
+
this.modified = worktree.modified ?? /* @__PURE__ */ new Set();
|
|
2315
|
+
this.missing = worktree.missing ?? /* @__PURE__ */ new Set();
|
|
2316
|
+
this.untracked = worktree.untracked ?? /* @__PURE__ */ new Set();
|
|
2317
|
+
this.ignored = worktree.ignored ?? /* @__PURE__ */ new Set();
|
|
2318
|
+
this.conflictingStageState = worktree.conflictingStageState ?? /* @__PURE__ */ new Map();
|
|
2319
|
+
this.files = worktree.files ?? [];
|
|
2320
|
+
this.renamed = worktree.renamed ?? /* @__PURE__ */ new Map();
|
|
2321
|
+
this.warnings = worktree.warnings ?? [];
|
|
2322
|
+
}
|
|
2323
|
+
isClean() {
|
|
2324
|
+
return !this.hasUncommittedChanges() && this.untracked.size === 0;
|
|
2325
|
+
}
|
|
2326
|
+
hasUncommittedChanges() {
|
|
2327
|
+
return this.added.size > 0 || this.changed.size > 0 || this.removed.size > 0 || this.conflicting.size > 0 || this.modified.size > 0 || this.missing.size > 0;
|
|
2328
|
+
}
|
|
2329
|
+
};
|
|
2330
|
+
/** git's byte order of paths (their bytes, as `strcmp`). */
|
|
2331
|
+
function comparePaths(a, b) {
|
|
2332
|
+
return compareGitPaths(a, b);
|
|
2333
|
+
}
|
|
2334
|
+
const ZERO_ID = "0".repeat(40);
|
|
2335
|
+
/**
|
|
2336
|
+
* The submodule field of a porcelain v2 line: `N...` for a path that is no submodule, else
|
|
2337
|
+
* `S` and whether its commit changed (`C`), it has tracked changes (`M`) and untracked files
|
|
2338
|
+
* (`U`) inside, as `SC.U`.
|
|
2339
|
+
*/
|
|
2340
|
+
function submoduleToken(e) {
|
|
2341
|
+
const gitlink = 57344;
|
|
2342
|
+
if (!(e.staged?.mode === gitlink || e.head?.mode === gitlink || e.worktreeMode === gitlink)) return "N...";
|
|
2343
|
+
return `S${e.submoduleCommitChanged ? "C" : "."}${e.submoduleModified ? "M" : "."}${e.submoduleUntracked ? "U" : "."}`;
|
|
2344
|
+
}
|
|
2345
|
+
const octal = (mode) => (mode ?? 0).toString(8).padStart(6, "0");
|
|
2346
|
+
/**
|
|
2347
|
+
* git's quoting of a path in status output (`quote_path`): C-quoted when it needs it, bytes
|
|
2348
|
+
* above 0x7f escaped only with `core.quotePath` (on by default); porcelain v1 puts a path
|
|
2349
|
+
* with a space in quotes too (`QUOTE_PATH_QUOTE_SP`), v2 does not.
|
|
2350
|
+
*/
|
|
2351
|
+
function quoteStatusPath(path, quoteSpace, quotePathFully) {
|
|
2352
|
+
const body = quoteCStyleBody(path, quotePathFully);
|
|
2353
|
+
if (body !== void 0) return `"${body}"`;
|
|
2354
|
+
return quoteSpace && path.includes(" ") ? `"${path}"` : path;
|
|
2355
|
+
}
|
|
2356
|
+
/**
|
|
2357
|
+
* The status as `git status --porcelain` (v1) or `--porcelain=v2` prints it, in the
|
|
2358
|
+
* untracked and ignored modes the status was made with (`?? dir/`, `!! dir/`): the changed
|
|
2359
|
+
* tracked paths first, then the untracked, then the ignored ones, each in git's path order.
|
|
2360
|
+
* A rename is one line at its new path: `R old -> new` (v1), `2 R. ... R<score> new<TAB>old`
|
|
2361
|
+
* (v2).
|
|
2362
|
+
*
|
|
2363
|
+
* @example
|
|
2364
|
+
* ```typescript
|
|
2365
|
+
* formatStatusPorcelain(await git.status().call());
|
|
2366
|
+
* // " M a.txt\nA b.txt\n?? new.txt\n"
|
|
2367
|
+
* ```
|
|
2368
|
+
*/
|
|
2369
|
+
function formatStatusPorcelain(status, version = 1, options = {}) {
|
|
2370
|
+
const fully = options.quotePath ?? true;
|
|
2371
|
+
const z = options.z === true;
|
|
2372
|
+
const quotePath = (path) => z ? path : quoteStatusPath(path, version === 1, fully);
|
|
2373
|
+
const entries = status.files;
|
|
2374
|
+
const tracked = entries.filter((e) => e.index !== "?" && e.index !== "!").sort((a, b) => (version === 2 ? (a.stages ? 1 : 0) - (b.stages ? 1 : 0) : 0) || comparePaths(a.path, b.path));
|
|
2375
|
+
const untracked = entries.filter((e) => e.index === "?").sort((a, b) => comparePaths(a.path, b.path));
|
|
2376
|
+
const ignored = entries.filter((e) => e.index === "!").sort((a, b) => comparePaths(a.path, b.path));
|
|
2377
|
+
const lines = [];
|
|
2378
|
+
for (const e of tracked) {
|
|
2379
|
+
const path = quotePath(e.path);
|
|
2380
|
+
const from = e.renamedFrom !== void 0 ? quotePath(e.renamedFrom) : void 0;
|
|
2381
|
+
if (version === 1) {
|
|
2382
|
+
if (z) lines.push(`${e.index}${e.worktree} ${path}${from !== void 0 ? `\0${from}` : ""}`);
|
|
2383
|
+
else lines.push(`${e.index}${e.worktree} ${from !== void 0 ? `${from} -> ` : ""}${path}`);
|
|
2384
|
+
continue;
|
|
2385
|
+
}
|
|
2386
|
+
const xy = `${e.index === " " ? "." : e.index}${e.worktree === " " ? "." : e.worktree}`;
|
|
2387
|
+
const sub = submoduleToken(e);
|
|
2388
|
+
if (from !== void 0) {
|
|
2389
|
+
lines.push([
|
|
2390
|
+
"2",
|
|
2391
|
+
xy,
|
|
2392
|
+
sub,
|
|
2393
|
+
octal(e.head?.mode),
|
|
2394
|
+
octal(e.staged?.mode),
|
|
2395
|
+
octal(e.worktreeMode),
|
|
2396
|
+
e.head?.id ?? ZERO_ID,
|
|
2397
|
+
e.staged?.id ?? ZERO_ID,
|
|
2398
|
+
`R${e.renameScore ?? 100}`,
|
|
2399
|
+
`${path}${z ? "\0" : " "}${from}`
|
|
2400
|
+
].join(" "));
|
|
2401
|
+
continue;
|
|
2402
|
+
}
|
|
2403
|
+
if (e.stages) {
|
|
2404
|
+
const [s1, s2, s3] = e.stages;
|
|
2405
|
+
lines.push([
|
|
2406
|
+
"u",
|
|
2407
|
+
xy,
|
|
2408
|
+
sub,
|
|
2409
|
+
octal(s1?.mode),
|
|
2410
|
+
octal(s2?.mode),
|
|
2411
|
+
octal(s3?.mode),
|
|
2412
|
+
octal(e.worktreeMode),
|
|
2413
|
+
s1?.id ?? ZERO_ID,
|
|
2414
|
+
s2?.id ?? ZERO_ID,
|
|
2415
|
+
s3?.id ?? ZERO_ID,
|
|
2416
|
+
path
|
|
2417
|
+
].join(" "));
|
|
2418
|
+
continue;
|
|
2419
|
+
}
|
|
2420
|
+
lines.push([
|
|
2421
|
+
"1",
|
|
2422
|
+
xy,
|
|
2423
|
+
sub,
|
|
2424
|
+
octal(e.head?.mode),
|
|
2425
|
+
octal(e.staged?.mode),
|
|
2426
|
+
octal(e.worktreeMode),
|
|
2427
|
+
e.head?.id ?? ZERO_ID,
|
|
2428
|
+
e.staged?.id ?? ZERO_ID,
|
|
2429
|
+
path
|
|
2430
|
+
].join(" "));
|
|
2431
|
+
}
|
|
2432
|
+
const mark = version === 1 ? ["??", "!!"] : ["?", "!"];
|
|
2433
|
+
for (const e of untracked) lines.push(`${mark[0]} ${quotePath(e.path)}`);
|
|
2434
|
+
for (const e of ignored) lines.push(`${mark[1]} ${quotePath(e.path)}`);
|
|
2435
|
+
const eol = z ? "\0" : "\n";
|
|
2436
|
+
return lines.map((l) => `${l}${eol}`).join("");
|
|
2437
|
+
}
|
|
2438
|
+
//#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
|
+
//#region src/results/blame-format.ts
|
|
2555
|
+
/**
|
|
2556
|
+
* `git blame` output of a {@link BlameResult}: the porcelain formats (`--porcelain`,
|
|
2557
|
+
* `--line-porcelain`) and the default one, byte for byte as git prints them.
|
|
2558
|
+
*
|
|
2559
|
+
* @example
|
|
2560
|
+
* ```typescript
|
|
2561
|
+
* const result = await git.blame().setFilePath("README.md").call();
|
|
2562
|
+
* process.stdout.write(formatBlamePorcelain(result));
|
|
2563
|
+
* process.stdout.write(formatBlame(result)); // ^1234567 (Alice 2024-01-02 10:00:00 +0100 1) line
|
|
2564
|
+
* ```
|
|
2565
|
+
*
|
|
2566
|
+
* @module
|
|
2567
|
+
*/
|
|
2568
|
+
/** The commit's subject as `find_commit_subject` finds it: its first non-blank line */
|
|
2569
|
+
function subjectOf(message, id) {
|
|
2570
|
+
const lines = message.split("\n");
|
|
2571
|
+
let i = 0;
|
|
2572
|
+
while (i < lines.length && /^[ \t\r\v\f]*$/.test(lines[i]) && i < lines.length - 1) i++;
|
|
2573
|
+
const subject = i < lines.length && !/^[ \t\r\v\f]*$/.test(lines[i]) ? lines[i] : "";
|
|
2574
|
+
return subject.length > 0 ? subject : `(${id})`;
|
|
2575
|
+
}
|
|
2576
|
+
/** The lines of the blamed file, each with its terminator */
|
|
2577
|
+
function fileLines(content) {
|
|
2578
|
+
const out = [];
|
|
2579
|
+
let start = 0;
|
|
2580
|
+
for (let i = 0; i < content.length; i++) if (content[i] === 10) {
|
|
2581
|
+
out.push(content.subarray(start, i + 1));
|
|
2582
|
+
start = i + 1;
|
|
2583
|
+
}
|
|
2584
|
+
if (start < content.length) out.push(content.subarray(start));
|
|
2585
|
+
return out;
|
|
2586
|
+
}
|
|
2587
|
+
function tzValue(tz) {
|
|
2588
|
+
const n = Number.parseInt(tz, 10);
|
|
2589
|
+
return Number.isNaN(n) ? 0 : n;
|
|
2590
|
+
}
|
|
2591
|
+
/** `show_date` with `DATE_ISO8601`: "2005-04-07 15:13:13 -0700" in the given zone */
|
|
2592
|
+
function isoDate(time, tz) {
|
|
2593
|
+
const t = tzValue(tz);
|
|
2594
|
+
const minutes = Math.sign(t) * (Math.floor(Math.abs(t) / 100) * 60 + Math.abs(t) % 100);
|
|
2595
|
+
const d = /* @__PURE__ */ new Date((time + minutes * 60) * 1e3);
|
|
2596
|
+
const p = (n, w = 2) => String(n).padStart(w, "0");
|
|
2597
|
+
const zone = `${t < 0 ? "-" : "+"}${p(Math.abs(t), 4)}`;
|
|
2598
|
+
return `${p(d.getUTCFullYear(), 4)}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())} ${p(d.getUTCHours())}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())} ${zone}`;
|
|
2599
|
+
}
|
|
2600
|
+
/** Commits blamed for more than one path (git's `MORE_THAN_ONE_PATH`) */
|
|
2601
|
+
function multiPathCommits(entries) {
|
|
2602
|
+
const paths = /* @__PURE__ */ new Map();
|
|
2603
|
+
for (const e of entries) {
|
|
2604
|
+
let set = paths.get(e.commitId);
|
|
2605
|
+
if (!set) {
|
|
2606
|
+
set = /* @__PURE__ */ new Set();
|
|
2607
|
+
paths.set(e.commitId, set);
|
|
2608
|
+
}
|
|
2609
|
+
set.add(e.sourcePath);
|
|
2610
|
+
}
|
|
2611
|
+
const out = /* @__PURE__ */ new Set();
|
|
2612
|
+
for (const [id, set] of paths) if (set.size > 1) out.add(id);
|
|
2613
|
+
return out;
|
|
2614
|
+
}
|
|
2615
|
+
/** `git blame --porcelain` (or `--line-porcelain`) */
|
|
2616
|
+
function formatBlamePorcelain(result, options = {}) {
|
|
2617
|
+
const quote = options.quotePath ?? true;
|
|
2618
|
+
const repeat = options.linePorcelain ?? false;
|
|
2619
|
+
const lines = fileLines(result.content ?? /* @__PURE__ */ new Uint8Array(0));
|
|
2620
|
+
const multi = multiPathCommits(result.entries);
|
|
2621
|
+
const shown = /* @__PURE__ */ new Set();
|
|
2622
|
+
const sink = new ByteSink();
|
|
2623
|
+
const details = (e, force) => {
|
|
2624
|
+
let wrote = false;
|
|
2625
|
+
if (force || !shown.has(e.commitId)) {
|
|
2626
|
+
shown.add(e.commitId);
|
|
2627
|
+
const c = e.commit;
|
|
2628
|
+
sink.text(`author ${c.author.name}\nauthor-mail <${c.author.email}>\nauthor-time ${c.author.timestamp}\nauthor-tz ${c.author.tzOffset}\ncommitter ${c.committer.name}\ncommitter-mail <${c.committer.email}>\ncommitter-time ${c.committer.timestamp}\ncommitter-tz ${c.committer.tzOffset}\nsummary ${subjectOf(c.message, e.commitId)}\n`);
|
|
2629
|
+
if (e.boundary) sink.text("boundary\n");
|
|
2630
|
+
wrote = true;
|
|
2631
|
+
}
|
|
2632
|
+
if (wrote || multi.has(e.commitId)) {
|
|
2633
|
+
if (e.previous) sink.text(`previous ${e.previous.commitId} ${quotePath(e.previous.path, quote)}\n`);
|
|
2634
|
+
sink.text(`filename ${quotePath(e.sourcePath, quote)}\n`);
|
|
2635
|
+
}
|
|
2636
|
+
};
|
|
2637
|
+
for (const e of result.entries) {
|
|
2638
|
+
sink.text(`${e.commitId} ${e.sourceStart} ${e.resultStart} ${e.lineCount}\n`);
|
|
2639
|
+
details(e, repeat);
|
|
2640
|
+
let last;
|
|
2641
|
+
for (let cnt = 0; cnt < e.lineCount; cnt++) {
|
|
2642
|
+
if (cnt) {
|
|
2643
|
+
sink.text(`${e.commitId} ${e.sourceStart + cnt} ${e.resultStart + cnt}\n`);
|
|
2644
|
+
if (repeat) details(e, true);
|
|
2645
|
+
}
|
|
2646
|
+
last = lines[e.resultStart - 1 + cnt] ?? /* @__PURE__ */ new Uint8Array(0);
|
|
2647
|
+
sink.text(" ");
|
|
2648
|
+
sink.push(last);
|
|
2649
|
+
}
|
|
2650
|
+
if (last && last.length > 0 && last[last.length - 1] !== 10) sink.text("\n");
|
|
2651
|
+
}
|
|
2652
|
+
return sink.bytes();
|
|
2653
|
+
}
|
|
2654
|
+
/** git's default `blame` output */
|
|
2655
|
+
function formatBlame(result, options = {}) {
|
|
2656
|
+
const lines = fileLines(result.content ?? /* @__PURE__ */ new Uint8Array(0));
|
|
2657
|
+
const entries = result.entries;
|
|
2658
|
+
let showName = options.showName ?? false;
|
|
2659
|
+
let longestFile = 0;
|
|
2660
|
+
let longestAuthor = 0;
|
|
2661
|
+
let longestSrc = 0;
|
|
2662
|
+
let longestDst = 0;
|
|
2663
|
+
let maxMarks = 0;
|
|
2664
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2665
|
+
const authorOf = (e) => options.showEmail ? `<${e.commit.author.email}>` : e.commit.author.name;
|
|
2666
|
+
for (const e of entries) {
|
|
2667
|
+
const marks = e.boundary && !options.blankBoundary ? 1 : 0;
|
|
2668
|
+
if (maxMarks < marks) maxMarks = marks;
|
|
2669
|
+
if (e.sourcePath !== result.path) showName = true;
|
|
2670
|
+
const len = encodeGitPath(e.sourcePath).length;
|
|
2671
|
+
if (longestFile < len) longestFile = len;
|
|
2672
|
+
if (!seen.has(e.commitId)) {
|
|
2673
|
+
seen.add(e.commitId);
|
|
2674
|
+
const w = displayWidth(authorOf(e));
|
|
2675
|
+
if (longestAuthor < w) longestAuthor = w;
|
|
2676
|
+
}
|
|
2677
|
+
longestSrc = Math.max(longestSrc, e.sourceStart - 1 + e.lineCount);
|
|
2678
|
+
longestDst = Math.max(longestDst, e.resultStart - 1 + e.lineCount);
|
|
2679
|
+
}
|
|
2680
|
+
const maxOrigDigits = String(longestSrc).length;
|
|
2681
|
+
const maxDigits = String(longestDst).length;
|
|
2682
|
+
const auto = options.abbrev === void 0;
|
|
2683
|
+
let abbrev = auto ? options.autoAbbrev ?? 7 : options.abbrev || 40;
|
|
2684
|
+
if (!options.alwaysWidenAbbrev) {
|
|
2685
|
+
if (abbrev < 40) abbrev = Math.min(40, abbrev + maxMarks);
|
|
2686
|
+
} else if (auto || abbrev < 40) abbrev += 1;
|
|
2687
|
+
const sink = new ByteSink();
|
|
2688
|
+
for (const e of entries) {
|
|
2689
|
+
const c = e.commit;
|
|
2690
|
+
let last;
|
|
2691
|
+
for (let cnt = 0; cnt < e.lineCount; cnt++) {
|
|
2692
|
+
let length = options.longObjectName ? 40 : abbrev;
|
|
2693
|
+
let hex = e.commitId;
|
|
2694
|
+
if (e.boundary && options.blankBoundary) hex = " ".repeat(hex.length);
|
|
2695
|
+
let line = "";
|
|
2696
|
+
if (e.boundary && !options.blankBoundary) {
|
|
2697
|
+
line += "^";
|
|
2698
|
+
length--;
|
|
2699
|
+
}
|
|
2700
|
+
line += hex.slice(0, Math.min(length, 40));
|
|
2701
|
+
if (showName) {
|
|
2702
|
+
const pad = Math.max(0, longestFile - encodeGitPath(e.sourcePath).length);
|
|
2703
|
+
line += ` ${e.sourcePath}${" ".repeat(pad)}`;
|
|
2704
|
+
}
|
|
2705
|
+
if (options.showNumber) line += ` ${String(e.sourceStart + cnt).padStart(maxOrigDigits)}`;
|
|
2706
|
+
if (!options.noAuthor) {
|
|
2707
|
+
const name = authorOf(e);
|
|
2708
|
+
const pad = Math.max(0, longestAuthor - displayWidth(name));
|
|
2709
|
+
const time = options.rawTimestamp ? `${c.author.timestamp} ${c.author.tzOffset}` : isoDate(c.author.timestamp, c.author.tzOffset);
|
|
2710
|
+
line += ` (${name}${" ".repeat(pad)} ${time.padStart(10)}`;
|
|
2711
|
+
}
|
|
2712
|
+
line += ` ${String(e.resultStart + cnt).padStart(maxDigits)}) `;
|
|
2713
|
+
sink.text(line);
|
|
2714
|
+
last = lines[e.resultStart - 1 + cnt] ?? /* @__PURE__ */ new Uint8Array(0);
|
|
2715
|
+
sink.push(last);
|
|
2716
|
+
}
|
|
2717
|
+
if (last && last.length > 0 && last[last.length - 1] !== 10) sink.text("\n");
|
|
2718
|
+
}
|
|
2719
|
+
return sink.bytes();
|
|
2720
|
+
}
|
|
2721
|
+
//#endregion
|
|
2722
|
+
//#region src/results/cherry-pick-result.ts
|
|
2723
|
+
/**
|
|
2724
|
+
* Status of a cherry-pick operation.
|
|
2725
|
+
*
|
|
2726
|
+
* Based on JGit's CherryPickResult.CherryPickStatus.
|
|
2727
|
+
*/
|
|
2728
|
+
let CherryPickStatus = /* @__PURE__ */ function(CherryPickStatus) {
|
|
2729
|
+
/** Cherry-pick completed successfully */
|
|
2730
|
+
CherryPickStatus["OK"] = "ok";
|
|
2731
|
+
/** Cherry-pick failed due to conflicts */
|
|
2732
|
+
CherryPickStatus["CONFLICTING"] = "conflicting";
|
|
2733
|
+
/** Cherry-pick failed (preconditions not met) */
|
|
2734
|
+
CherryPickStatus["FAILED"] = "failed";
|
|
2735
|
+
return CherryPickStatus;
|
|
2736
|
+
}({});
|
|
2737
|
+
//#endregion
|
|
2738
|
+
//#region src/results/fetch-result.ts
|
|
2739
|
+
/**
|
|
2740
|
+
* Status of a ref update.
|
|
2741
|
+
*
|
|
2742
|
+
* Based on JGit's RefUpdate.Result.
|
|
2743
|
+
*/
|
|
2744
|
+
let RefUpdateStatus = /* @__PURE__ */ function(RefUpdateStatus) {
|
|
2745
|
+
/** Update was performed successfully */
|
|
2746
|
+
RefUpdateStatus["NEW"] = "new";
|
|
2747
|
+
/** Update was a fast-forward */
|
|
2748
|
+
RefUpdateStatus["FAST_FORWARD"] = "fast-forward";
|
|
2749
|
+
/** Update was forced (non-fast-forward) */
|
|
2750
|
+
RefUpdateStatus["FORCED"] = "forced";
|
|
2751
|
+
/** No update needed (already up to date) */
|
|
2752
|
+
RefUpdateStatus["NO_CHANGE"] = "no-change";
|
|
2753
|
+
/** Update rejected (non-fast-forward without force) */
|
|
2754
|
+
RefUpdateStatus["REJECTED"] = "rejected";
|
|
2755
|
+
/** Update rejected (ref is locked) */
|
|
2756
|
+
RefUpdateStatus["LOCK_FAILURE"] = "lock-failure";
|
|
2757
|
+
/** Ref was deleted */
|
|
2758
|
+
RefUpdateStatus["DELETED"] = "deleted";
|
|
2759
|
+
/** Update renamed the ref */
|
|
2760
|
+
RefUpdateStatus["RENAMED"] = "renamed";
|
|
2761
|
+
return RefUpdateStatus;
|
|
2762
|
+
}({});
|
|
2763
|
+
/**
|
|
2764
|
+
* Check if fetch result has any updates.
|
|
2765
|
+
*/
|
|
2766
|
+
function hasUpdates(result) {
|
|
2767
|
+
return result.trackingRefUpdates.some((u) => u.status !== "no-change");
|
|
2768
|
+
}
|
|
2769
|
+
/**
|
|
2770
|
+
* Get successful updates from fetch result.
|
|
2771
|
+
*/
|
|
2772
|
+
function getSuccessfulUpdates(result) {
|
|
2773
|
+
return result.trackingRefUpdates.filter((u) => u.status === "new" || u.status === "fast-forward" || u.status === "forced");
|
|
2774
|
+
}
|
|
2775
|
+
//#endregion
|
|
2776
|
+
//#region src/results/pull-result.ts
|
|
2777
|
+
/**
|
|
2778
|
+
* Check if pull result was successful.
|
|
2779
|
+
*/
|
|
2780
|
+
function isPullSuccessful(result) {
|
|
2781
|
+
return result.successful;
|
|
2782
|
+
}
|
|
2783
|
+
//#endregion
|
|
2784
|
+
//#region src/results/push-result.ts
|
|
2785
|
+
/**
|
|
2786
|
+
* Status of a ref update during push.
|
|
2787
|
+
*
|
|
2788
|
+
* Based on JGit's RemoteRefUpdate.Status.
|
|
2789
|
+
*/
|
|
2790
|
+
let PushStatus = /* @__PURE__ */ function(PushStatus) {
|
|
2791
|
+
/** Update was performed successfully */
|
|
2792
|
+
PushStatus["OK"] = "ok";
|
|
2793
|
+
/** Update was rejected (not fast-forward) */
|
|
2794
|
+
PushStatus["REJECTED_NONFASTFORWARD"] = "rejected-nonfastforward";
|
|
2795
|
+
/** Update was rejected: the remote ref no longer has the leased value (`--force-with-lease`) */
|
|
2796
|
+
PushStatus["REJECTED_REMOTE_CHANGED"] = "rejected-remote-changed";
|
|
2797
|
+
/** Update was rejected (other reason) */
|
|
2798
|
+
PushStatus["REJECTED_OTHER"] = "rejected-other";
|
|
2799
|
+
/** Update failed (remote error) */
|
|
2800
|
+
PushStatus["FAILED"] = "failed";
|
|
2801
|
+
/** Update not attempted (nothing to push) */
|
|
2802
|
+
PushStatus["NOT_ATTEMPTED"] = "not-attempted";
|
|
2803
|
+
/** Update already up to date */
|
|
2804
|
+
PushStatus["UP_TO_DATE"] = "up-to-date";
|
|
2805
|
+
/** Waiting for other updates to complete (atomic push) */
|
|
2806
|
+
PushStatus["AWAITING_REPORT"] = "awaiting-report";
|
|
2807
|
+
return PushStatus;
|
|
2808
|
+
}({});
|
|
2809
|
+
/**
|
|
2810
|
+
* Check if all updates in push result were successful.
|
|
2811
|
+
*/
|
|
2812
|
+
function isPushSuccessful(result) {
|
|
2813
|
+
return result.remoteUpdates.every((u) => u.status === "ok" || u.status === "up-to-date");
|
|
2814
|
+
}
|
|
2815
|
+
/**
|
|
2816
|
+
* Get failed updates from push result.
|
|
2817
|
+
*/
|
|
2818
|
+
function getFailedUpdates(result) {
|
|
2819
|
+
return result.remoteUpdates.filter((u) => u.status !== "ok" && u.status !== "up-to-date" && u.status !== "not-attempted");
|
|
2820
|
+
}
|
|
2821
|
+
//#endregion
|
|
2822
|
+
//#region src/results/rebase-result.ts
|
|
2823
|
+
/**
|
|
2824
|
+
* Status of a rebase operation.
|
|
2825
|
+
*
|
|
2826
|
+
* Based on JGit's RebaseResult.Status.
|
|
2827
|
+
*/
|
|
2828
|
+
let RebaseStatus = /* @__PURE__ */ function(RebaseStatus) {
|
|
2829
|
+
/**
|
|
2830
|
+
* Rebase was successful.
|
|
2831
|
+
*/
|
|
2832
|
+
RebaseStatus["OK"] = "ok";
|
|
2833
|
+
/**
|
|
2834
|
+
* Fast-forward was performed (no actual rebase needed).
|
|
2835
|
+
*/
|
|
2836
|
+
RebaseStatus["FAST_FORWARD"] = "fast-forward";
|
|
2837
|
+
/**
|
|
2838
|
+
* Already up-to-date (no rebase needed).
|
|
2839
|
+
*/
|
|
2840
|
+
RebaseStatus["UP_TO_DATE"] = "up-to-date";
|
|
2841
|
+
/**
|
|
2842
|
+
* Rebase stopped due to conflict.
|
|
2843
|
+
*/
|
|
2844
|
+
RebaseStatus["STOPPED"] = "stopped";
|
|
2845
|
+
/**
|
|
2846
|
+
* Rebase was aborted.
|
|
2847
|
+
*/
|
|
2848
|
+
RebaseStatus["ABORTED"] = "aborted";
|
|
2849
|
+
/**
|
|
2850
|
+
* Rebase was aborted due to failure (not conflict).
|
|
2851
|
+
*/
|
|
2852
|
+
RebaseStatus["FAILED"] = "failed";
|
|
2853
|
+
/**
|
|
2854
|
+
* Uncommitted changes prevented rebase from starting.
|
|
2855
|
+
*/
|
|
2856
|
+
RebaseStatus["UNCOMMITTED_CHANGES"] = "uncommitted-changes";
|
|
2857
|
+
/**
|
|
2858
|
+
* Interactive rebase is prepared but not started.
|
|
2859
|
+
*/
|
|
2860
|
+
RebaseStatus["INTERACTIVE_PREPARED"] = "interactive-prepared";
|
|
2861
|
+
/**
|
|
2862
|
+
* Continue was called but there was nothing to commit.
|
|
2863
|
+
*/
|
|
2864
|
+
RebaseStatus["NOTHING_TO_COMMIT"] = "nothing-to-commit";
|
|
2865
|
+
/**
|
|
2866
|
+
* Stash apply failed after successful rebase.
|
|
2867
|
+
*/
|
|
2868
|
+
RebaseStatus["STASH_APPLY_CONFLICTS"] = "stash-apply-conflicts";
|
|
2869
|
+
/**
|
|
2870
|
+
* Rebase stopped at edit step.
|
|
2871
|
+
*/
|
|
2872
|
+
RebaseStatus["EDIT"] = "edit";
|
|
2873
|
+
return RebaseStatus;
|
|
2874
|
+
}({});
|
|
2875
|
+
/**
|
|
2876
|
+
* Rebase todo line action.
|
|
2877
|
+
*
|
|
2878
|
+
* Based on JGit's RebaseTodoLine.Action.
|
|
2879
|
+
*/
|
|
2880
|
+
let RebaseAction = /* @__PURE__ */ function(RebaseAction) {
|
|
2881
|
+
/** Pick the commit (apply it) */
|
|
2882
|
+
RebaseAction["PICK"] = "pick";
|
|
2883
|
+
/** Reword: pick but edit commit message */
|
|
2884
|
+
RebaseAction["REWORD"] = "reword";
|
|
2885
|
+
/** Edit: stop for amending */
|
|
2886
|
+
RebaseAction["EDIT"] = "edit";
|
|
2887
|
+
/** Squash into previous commit (combine messages) */
|
|
2888
|
+
RebaseAction["SQUASH"] = "squash";
|
|
2889
|
+
/** Fixup: squash but discard this commit's message */
|
|
2890
|
+
RebaseAction["FIXUP"] = "fixup";
|
|
2891
|
+
/** Comment line (ignored) */
|
|
2892
|
+
RebaseAction["COMMENT"] = "comment";
|
|
2893
|
+
/** `label <name>`: `refs/rewritten/<name>` set to HEAD (`--rebase-merges`) */
|
|
2894
|
+
RebaseAction["LABEL"] = "label";
|
|
2895
|
+
/** `reset <label>`: HEAD and the worktree moved to a label (`--rebase-merges`) */
|
|
2896
|
+
RebaseAction["RESET"] = "reset";
|
|
2897
|
+
/** `merge [-C <commit> | -c <commit>] <label> [# <oneline>]` (`--rebase-merges`) */
|
|
2898
|
+
RebaseAction["MERGE"] = "merge";
|
|
2899
|
+
/** `exec <command>`: the command run by the exec handler (git runs it in a shell) */
|
|
2900
|
+
RebaseAction["EXEC"] = "exec";
|
|
2901
|
+
/** `break`: the rebase stops here (`git rebase --continue` goes on) */
|
|
2902
|
+
RebaseAction["BREAK"] = "break";
|
|
2903
|
+
/** `drop <commit>`: the commit left out */
|
|
2904
|
+
RebaseAction["DROP"] = "drop";
|
|
2905
|
+
/** `noop`: nothing (the list of a rebase with nothing to pick) */
|
|
2906
|
+
RebaseAction["NOOP"] = "noop";
|
|
2907
|
+
/** `update-ref <ref>`: the ref moved to HEAD at the end of the rebase (`--update-refs`) */
|
|
2908
|
+
RebaseAction["UPDATE_REF"] = "update-ref";
|
|
2909
|
+
return RebaseAction;
|
|
2910
|
+
}({});
|
|
2911
|
+
/**
|
|
2912
|
+
* Check if rebase status indicates success.
|
|
2913
|
+
*/
|
|
2914
|
+
function isRebaseSuccessful(status) {
|
|
2915
|
+
return status === "ok" || status === "fast-forward" || status === "up-to-date";
|
|
2916
|
+
}
|
|
2917
|
+
//#endregion
|
|
2918
|
+
//#region src/results/revert-result.ts
|
|
2919
|
+
/**
|
|
2920
|
+
* Status of a revert operation.
|
|
2921
|
+
*
|
|
2922
|
+
* Based on JGit's RevertCommand result patterns.
|
|
2923
|
+
*/
|
|
2924
|
+
let RevertStatus = /* @__PURE__ */ function(RevertStatus) {
|
|
2925
|
+
/** Revert completed successfully */
|
|
2926
|
+
RevertStatus["OK"] = "ok";
|
|
2927
|
+
/** Revert resulted in conflicts */
|
|
2928
|
+
RevertStatus["CONFLICTING"] = "conflicting";
|
|
2929
|
+
/** Revert failed due to dirty working tree or other issues */
|
|
2930
|
+
RevertStatus["FAILED"] = "failed";
|
|
2931
|
+
return RevertStatus;
|
|
2932
|
+
}({});
|
|
2933
|
+
//#endregion
|
|
2934
|
+
export { createRenameEntry as $, blobSide as A, formatShortstat as B, submoduleToken as C, DiffFormatter as D, parseOrderFile as E, formatNameOnly as F, statSummary as G, formatSummary as H, formatNameStatus as I, ChangeType as J, utf8 as K, formatNoIndexDiff as L, contentSide as M, diffDriverOf as N, diffEntryToPair as O, displayWidth as P, createModifyEntry as Q, formatNumstat as R, formatStatusPorcelain as S, orderRank as T, noIndexPair as U, formatStat as V, pprintRename as W, createCopyEntry as X, createAddEntry as Y, createDeleteEntry as Z, MergeStatus as _, PushStatus as a, StashApplyStatus as b, isPullSuccessful as c, hasUpdates as d, writeCombinedDiff as et, CherryPickStatus as f, FastForwardMode as g, ContentMergeStrategy as h, isRebaseSuccessful as i, computeDiffstat as j, blobIdOf as k, RefUpdateStatus as l, formatBlamePorcelain as m, RebaseAction as n, quotePath as nt, getFailedUpdates as o, formatBlame as p, writePairPatch as q, RebaseStatus as r, quoteTwo as rt, isPushSuccessful as s, RevertStatus as t, quoteCStyleBody as tt, getSuccessfulUpdates as u, MergeStrategy as v, orderByPatterns as w, StatusImpl as x, isMergeSuccessful as y, formatPatch as z };
|