@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,1051 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's diff output (`diff.c`) over file pairs: the patch (`git diff`), `--stat`,
|
|
3
|
+
* `--numstat`, `--shortstat`, `--name-only` and `--name-status`, byte for byte as git prints
|
|
4
|
+
* them.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const pairs: DiffFilePair[] = [{ status: "M", old: blobSide(...), new: blobSide(...) }];
|
|
9
|
+
* const patch = await formatPatch(pairs, { context: 3, indentHeuristic: true });
|
|
10
|
+
* const stat = formatStat(await computeDiffstat(pairs), { width: 80 });
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* A pair has an old and a new side; a side that does not exist (an added file's old side,
|
|
14
|
+
* a deleted file's new side) is left out. Each file is shown as git's `builtin_diff` shows
|
|
15
|
+
* it: the `diff --git` header with mode, rename and `index` lines, then "Binary files ...
|
|
16
|
+
* differ" or the hunks of the text diff ({@link unifiedDiffHunks}). A pair between a file
|
|
17
|
+
* and a symbolic link is shown as a deletion and an addition. The header of a file whose
|
|
18
|
+
* diff comes out empty (only whitespace changes under `-w`) is printed only when it
|
|
19
|
+
* carries news of its own (mode change, rename, new or deleted file).
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { type Blobs, probeBlob } from "@statewalker/vcs-core";
|
|
25
|
+
import {
|
|
26
|
+
ByteSink,
|
|
27
|
+
bytesToHex,
|
|
28
|
+
createSha1,
|
|
29
|
+
diffLineCounts,
|
|
30
|
+
type FindFunction,
|
|
31
|
+
type UnifiedDiffOptions,
|
|
32
|
+
type UnifiedDiffResult,
|
|
33
|
+
unifiedDiffHunks,
|
|
34
|
+
userdiffFindFunction,
|
|
35
|
+
writeHunks,
|
|
36
|
+
type XdiffAlgorithm,
|
|
37
|
+
} from "@statewalker/vcs-utils";
|
|
38
|
+
import {
|
|
39
|
+
decodeGitPath,
|
|
40
|
+
encodeGitPath,
|
|
41
|
+
gitCharWidthAt,
|
|
42
|
+
gitStrWidth,
|
|
43
|
+
parseGitBool,
|
|
44
|
+
} from "@statewalker/vcs-utils/encoding";
|
|
45
|
+
import { gitBinaryPatch } from "./binary-patch.js";
|
|
46
|
+
|
|
47
|
+
import { quoteCStyleBody, quotePath, quoteTwo } from "./quote-path.js";
|
|
48
|
+
|
|
49
|
+
/** One side of a file pair */
|
|
50
|
+
export interface DiffSideSpec {
|
|
51
|
+
path: string;
|
|
52
|
+
/** git file mode, e.g. `0o100644` */
|
|
53
|
+
mode: number;
|
|
54
|
+
/** Object id of the content (a worktree file: the id of its cleaned content) */
|
|
55
|
+
id: string;
|
|
56
|
+
/** The content (a symbolic link: its target; a submodule: "Subproject commit <id>\n") */
|
|
57
|
+
read(): Promise<Uint8Array>;
|
|
58
|
+
/**
|
|
59
|
+
* The bytes a textconv command reads, as git's `prepare_temp_file` writes them: a stored
|
|
60
|
+
* blob as checkout would write it (smudged), a worktree file as it is (not cleaned);
|
|
61
|
+
* default {@link read}
|
|
62
|
+
*/
|
|
63
|
+
readTextconvInput?(): Promise<Uint8Array>;
|
|
64
|
+
/**
|
|
65
|
+
* Whether `id` is known as git knows a stored object's (default true); false for content
|
|
66
|
+
* hashed here, a worktree file or a file outside the repository (git's `oid_valid` unset):
|
|
67
|
+
* the diffstat then compares the contents even when the ids are equal
|
|
68
|
+
*/
|
|
69
|
+
idValid?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Size and binary probe without reading everything (big files): when absent, the content
|
|
72
|
+
* is read
|
|
73
|
+
*/
|
|
74
|
+
probe?(bigFileThreshold: number): Promise<{ size: number; binary: boolean }>;
|
|
75
|
+
/**
|
|
76
|
+
* A submodule's own changes in the worktree (git's `dirty_submodule`): tracked changes
|
|
77
|
+
* (`modified`) and untracked files (`untracked`) inside it
|
|
78
|
+
*/
|
|
79
|
+
submoduleDirt?: { modified?: boolean; untracked?: boolean };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** git's status letters of a file pair */
|
|
83
|
+
export type DiffStatus = "A" | "D" | "M" | "R" | "C" | "T";
|
|
84
|
+
|
|
85
|
+
/** A file pair as git's diff queue holds it */
|
|
86
|
+
export interface DiffFilePair {
|
|
87
|
+
status: DiffStatus;
|
|
88
|
+
/** The old side; absent for an added file */
|
|
89
|
+
old?: DiffSideSpec;
|
|
90
|
+
/** The new side; absent for a deleted file */
|
|
91
|
+
new?: DiffSideSpec;
|
|
92
|
+
/** Similarity percentage of a rename or copy */
|
|
93
|
+
score?: number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** What a diff driver (`diff=<name>` attribute) changes */
|
|
97
|
+
export interface DiffDriver {
|
|
98
|
+
/** Binary (`-diff`, `diff.<name>.binary`) or text (`diff`) regardless of content */
|
|
99
|
+
binary?: boolean;
|
|
100
|
+
/** Hunk header function lines (`diff.<name>.xfuncname`, builtin drivers) */
|
|
101
|
+
findFunction?: FindFunction;
|
|
102
|
+
/** `diff.<name>.algorithm` */
|
|
103
|
+
algorithm?: XdiffAlgorithm;
|
|
104
|
+
/** The driver's name (`diff=<name>`) */
|
|
105
|
+
name?: string;
|
|
106
|
+
/** `diff.<name>.textconv`: the command git would run to turn the content into text */
|
|
107
|
+
textconvCommand?: string;
|
|
108
|
+
/** `diff.<name>.cachetextconv` (output is the same with or without the cache) */
|
|
109
|
+
cacheTextconv?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Turns a side's content into the text the patch compares (git's `fill_textconv`): set
|
|
112
|
+
* when textconv is allowed and the host can run `textconvCommand`. A side converted this
|
|
113
|
+
* way is never binary.
|
|
114
|
+
*/
|
|
115
|
+
textconv?: TextconvFunction;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** A textconv conversion: the text of `content`, the content of the file `path` */
|
|
119
|
+
export type TextconvFunction = (content: Uint8Array, path: string) => Promise<Uint8Array>;
|
|
120
|
+
|
|
121
|
+
/** Options of the diff output */
|
|
122
|
+
export interface DiffOutputOptions
|
|
123
|
+
extends Omit<UnifiedDiffOptions, "findFunction" | "indentHeuristic"> {
|
|
124
|
+
/** Slide changes as the indentation suggests (`diff.indentHeuristic`, default true) */
|
|
125
|
+
indentHeuristic?: boolean;
|
|
126
|
+
/** Length of abbreviated object ids in `index` lines (default 7) */
|
|
127
|
+
abbrev?: number;
|
|
128
|
+
/**
|
|
129
|
+
* The length of each id in `index` lines, as git abbreviates them (`DiffCommand` finds
|
|
130
|
+
* them from `core.abbrev`, the repository's size and the other objects); ids not in it
|
|
131
|
+
* take `abbrev`
|
|
132
|
+
*/
|
|
133
|
+
abbrevLengths?: ReadonlyMap<string, number>;
|
|
134
|
+
/** Full object ids in `index` lines (`--full-index`) */
|
|
135
|
+
fullIndex?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* `--submodule=log` / `--submodule=diff`: writes a pair whose sides are submodules (or
|
|
138
|
+
* absent) in place of its patch (builtin_diff's submodule branch); unset, a submodule's
|
|
139
|
+
* change is a `Subproject commit` patch (`--submodule=short`)
|
|
140
|
+
*/
|
|
141
|
+
submodulePatch?: (
|
|
142
|
+
sink: ByteSink,
|
|
143
|
+
pair: DiffFilePair,
|
|
144
|
+
options: DiffOutputOptions,
|
|
145
|
+
) => Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* `--binary`: binary files as "GIT binary patch" hunks `git apply` can apply (their `index`
|
|
148
|
+
* lines with full ids), instead of "Binary files ... differ"
|
|
149
|
+
*/
|
|
150
|
+
binaryPatch?: boolean;
|
|
151
|
+
/** `core.quotePath` (default true): bytes above 0x7f in paths are escaped */
|
|
152
|
+
quotePath?: boolean;
|
|
153
|
+
/** Larger files are binary (`core.bigFileThreshold`, default 512 MiB as git's diff) */
|
|
154
|
+
bigFileThreshold?: number;
|
|
155
|
+
/** Treat every file as text (`-a`, `--text`) */
|
|
156
|
+
text?: boolean;
|
|
157
|
+
/** Prefix of old paths (default "a/"; `--src-prefix`, `--no-prefix`) */
|
|
158
|
+
srcPrefix?: string;
|
|
159
|
+
/** Prefix of new paths (default "b/") */
|
|
160
|
+
dstPrefix?: string;
|
|
161
|
+
/** The diff driver of a path (from its `diff` attribute), if any */
|
|
162
|
+
driver?: (path: string) => Promise<DiffDriver | undefined> | DiffDriver | undefined;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const S_IFMT = 0o170000;
|
|
166
|
+
const GITLINK_MODE = 0o160000;
|
|
167
|
+
const NULL_ID = "0".repeat(40);
|
|
168
|
+
const FIRST_FEW_BYTES = 8000;
|
|
169
|
+
const GIT_DIFF_BIG_FILE_THRESHOLD = 512 * 1024 * 1024;
|
|
170
|
+
|
|
171
|
+
const encoder = new TextEncoder();
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The driver of a `diff` attribute value (git's `userdiff_find_by_path`): set means text,
|
|
175
|
+
* unset means binary, a name means `diff.<name>.*` from `config` or a builtin driver.
|
|
176
|
+
*/
|
|
177
|
+
export function diffDriverOf(
|
|
178
|
+
attribute: true | false | string | undefined | null,
|
|
179
|
+
config?: (key: string) => string | undefined,
|
|
180
|
+
): DiffDriver | undefined {
|
|
181
|
+
if (attribute === true) return { binary: false };
|
|
182
|
+
if (attribute === false) return { binary: true };
|
|
183
|
+
if (typeof attribute !== "string") return undefined;
|
|
184
|
+
const name = attribute;
|
|
185
|
+
const binary = boolValue(config?.(`diff.${name}.binary`));
|
|
186
|
+
const algorithm = config?.(`diff.${name}.algorithm`) as XdiffAlgorithm | undefined;
|
|
187
|
+
const findFunction = userdiffFindFunction(name, config);
|
|
188
|
+
const textconvCommand = config?.(`diff.${name}.textconv`);
|
|
189
|
+
const cacheTextconv = boolValue(config?.(`diff.${name}.cachetextconv`));
|
|
190
|
+
if (binary === undefined && !algorithm && !findFunction && textconvCommand === undefined) {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
name,
|
|
195
|
+
...(binary !== undefined ? { binary } : {}),
|
|
196
|
+
...(algorithm ? { algorithm } : {}),
|
|
197
|
+
...(findFunction ? { findFunction } : {}),
|
|
198
|
+
...(textconvCommand !== undefined ? { textconvCommand } : {}),
|
|
199
|
+
...(cacheTextconv !== undefined ? { cacheTextconv } : {}),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** A git boolean (`git_config_bool`), undefined when unset or not one. */
|
|
204
|
+
const boolValue = (v: string | undefined): boolean | undefined => parseGitBool(v);
|
|
205
|
+
|
|
206
|
+
/** A side as the diff reads it: its content and binary state, read once */
|
|
207
|
+
class LoadedSide {
|
|
208
|
+
private content?: Promise<Uint8Array>;
|
|
209
|
+
private probed?: Promise<{ size: number; binary: boolean }>;
|
|
210
|
+
|
|
211
|
+
constructor(
|
|
212
|
+
readonly spec: DiffSideSpec | undefined,
|
|
213
|
+
readonly driver: DiffDriver | undefined,
|
|
214
|
+
) {}
|
|
215
|
+
|
|
216
|
+
get valid(): boolean {
|
|
217
|
+
return this.spec !== undefined;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
get mode(): number {
|
|
221
|
+
return this.spec?.mode ?? 0;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
get id(): string {
|
|
225
|
+
return this.spec?.id ?? NULL_ID;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
read(): Promise<Uint8Array> {
|
|
229
|
+
this.content ??= this.spec ? this.spec.read() : Promise.resolve(new Uint8Array(0));
|
|
230
|
+
return this.content;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** The bytes textconv converts ({@link DiffSideSpec.readTextconvInput}) */
|
|
234
|
+
textconvInput(): Promise<Uint8Array> {
|
|
235
|
+
return this.spec?.readTextconvInput ? this.spec.readTextconvInput() : this.read();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** `diff_filespec_is_binary` */
|
|
239
|
+
async isBinary(threshold: number): Promise<boolean> {
|
|
240
|
+
if (this.driver?.binary !== undefined) return this.driver.binary;
|
|
241
|
+
if (!this.spec) return false;
|
|
242
|
+
return (await this.probe(threshold)).binary;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
probe(threshold: number): Promise<{ size: number; binary: boolean }> {
|
|
246
|
+
this.probed ??= (async () => {
|
|
247
|
+
if (this.spec?.probe && !this.content) return this.spec.probe(threshold);
|
|
248
|
+
const content = await this.read();
|
|
249
|
+
return {
|
|
250
|
+
size: content.length,
|
|
251
|
+
binary: content.length > threshold || hasNul(content),
|
|
252
|
+
};
|
|
253
|
+
})();
|
|
254
|
+
return this.probed;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async size(threshold: number): Promise<number> {
|
|
258
|
+
if (!this.spec) return 0;
|
|
259
|
+
return (await this.probe(threshold)).size;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function hasNul(content: Uint8Array): boolean {
|
|
264
|
+
const n = Math.min(content.length, FIRST_FEW_BYTES);
|
|
265
|
+
return (n === content.length ? content : content.subarray(0, n)).indexOf(0) >= 0;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function octal6(mode: number): string {
|
|
269
|
+
return mode.toString(8).padStart(6, "0");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The driver a side's content is read with (`diff_filespec_load_driver`): a regular file's;
|
|
274
|
+
* an absent side, a symbolic link and a submodule take the default driver
|
|
275
|
+
*/
|
|
276
|
+
function contentDriver(
|
|
277
|
+
spec: DiffSideSpec | undefined,
|
|
278
|
+
driver: DiffDriver | undefined,
|
|
279
|
+
): DiffDriver | undefined {
|
|
280
|
+
return spec && (spec.mode & S_IFMT) === 0o100000 ? driver : undefined;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function driverOf(
|
|
284
|
+
options: DiffOutputOptions,
|
|
285
|
+
path: string | undefined,
|
|
286
|
+
): Promise<DiffDriver | undefined> {
|
|
287
|
+
if (!path || !options.driver) return undefined;
|
|
288
|
+
return options.driver(path);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* The patch of the pairs, as `git diff` prints it.
|
|
293
|
+
*/
|
|
294
|
+
export async function formatPatch(
|
|
295
|
+
pairs: DiffFilePair[],
|
|
296
|
+
options: DiffOutputOptions = {},
|
|
297
|
+
): Promise<Uint8Array> {
|
|
298
|
+
const sink = new ByteSink();
|
|
299
|
+
for (const pair of pairs) await writePairPatch(sink, pair, options);
|
|
300
|
+
return sink.bytes();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** What {@link writePairPatch} found for a pair (the last part, for a split pair) */
|
|
304
|
+
export interface PairPatchReport {
|
|
305
|
+
/** "Binary files ... differ" (or binary and equal) */
|
|
306
|
+
binary: boolean;
|
|
307
|
+
/** The `diff --git` line, without its LF */
|
|
308
|
+
gitLine: string;
|
|
309
|
+
/** The lines between `diff --git` and `---` (mode, rename, index lines), each with LF */
|
|
310
|
+
extended: string;
|
|
311
|
+
/** The `---` and `+++` lines, without LF, when hunks were printed */
|
|
312
|
+
oldLabel?: string;
|
|
313
|
+
newLabel?: string;
|
|
314
|
+
/** The text diff, for a text pair */
|
|
315
|
+
result?: UnifiedDiffResult;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Writes one pair as `run_diff` does: a file/symlink change as deletion and addition */
|
|
319
|
+
export async function writePairPatch(
|
|
320
|
+
sink: ByteSink,
|
|
321
|
+
pair: DiffFilePair,
|
|
322
|
+
options: DiffOutputOptions = {},
|
|
323
|
+
report?: PairPatchReport,
|
|
324
|
+
): Promise<void> {
|
|
325
|
+
const { old: one, new: two } = pair;
|
|
326
|
+
if (one && two && (one.mode & S_IFMT) !== (two.mode & S_IFMT)) {
|
|
327
|
+
await builtinDiff(sink, { ...pair, new: undefined }, options, two.path, report);
|
|
328
|
+
await builtinDiff(sink, { ...pair, old: undefined }, options, one.path, report);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
await builtinDiff(sink, pair, options, undefined, report);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** `fill_metainfo`: rename/copy lines and the index line; whether they force the header */
|
|
335
|
+
function metainfo(
|
|
336
|
+
pair: DiffFilePair,
|
|
337
|
+
one: LoadedSide,
|
|
338
|
+
two: LoadedSide,
|
|
339
|
+
name: string,
|
|
340
|
+
other: string | undefined,
|
|
341
|
+
options: DiffOutputOptions,
|
|
342
|
+
fullIndex = false,
|
|
343
|
+
): { text: string; mustShow: boolean } {
|
|
344
|
+
const quote = options.quotePath ?? true;
|
|
345
|
+
let text = "";
|
|
346
|
+
let mustShow = false;
|
|
347
|
+
if (pair.status === "R" || pair.status === "C") {
|
|
348
|
+
const word = pair.status === "R" ? "rename" : "copy";
|
|
349
|
+
text += `similarity index ${pair.score ?? 0}%\n`;
|
|
350
|
+
text += `${word} from ${quotePath(name, quote)}\n`;
|
|
351
|
+
text += `${word} to ${quotePath(other ?? name, quote)}\n`;
|
|
352
|
+
mustShow = true;
|
|
353
|
+
}
|
|
354
|
+
if (one.id !== two.id) {
|
|
355
|
+
const abbrev = (id: string) =>
|
|
356
|
+
id.slice(
|
|
357
|
+
0,
|
|
358
|
+
options.fullIndex || fullIndex
|
|
359
|
+
? 40
|
|
360
|
+
: (options.abbrevLengths?.get(id) ?? options.abbrev ?? 7),
|
|
361
|
+
);
|
|
362
|
+
text += `index ${abbrev(one.id)}..${abbrev(two.id)}`;
|
|
363
|
+
if (one.mode === two.mode) text += ` ${octal6(one.mode)}`;
|
|
364
|
+
text += "\n";
|
|
365
|
+
}
|
|
366
|
+
return { text, mustShow };
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** git's `builtin_diff` for one pair (both sides of the same kind, or one side absent) */
|
|
370
|
+
async function builtinDiff(
|
|
371
|
+
sink: ByteSink,
|
|
372
|
+
pair: DiffFilePair,
|
|
373
|
+
options: DiffOutputOptions,
|
|
374
|
+
absentPath?: string,
|
|
375
|
+
report?: PairPatchReport,
|
|
376
|
+
): Promise<void> {
|
|
377
|
+
// builtin_diff: a submodule's change in the log or diff format
|
|
378
|
+
if (
|
|
379
|
+
options.submodulePatch &&
|
|
380
|
+
(pair.old || pair.new) &&
|
|
381
|
+
(!pair.old || (pair.old.mode & S_IFMT) === GITLINK_MODE) &&
|
|
382
|
+
(!pair.new || (pair.new.mode & S_IFMT) === GITLINK_MODE)
|
|
383
|
+
) {
|
|
384
|
+
await options.submodulePatch(sink, pair, options);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const quote = options.quotePath ?? true;
|
|
388
|
+
const threshold = options.bigFileThreshold ?? GIT_DIFF_BIG_FILE_THRESHOLD;
|
|
389
|
+
// names as run_diff passes them: the pair's paths even for the absent side
|
|
390
|
+
const pathOne = pair.old?.path ?? absentPath ?? pair.new?.path ?? "";
|
|
391
|
+
const pathTwo = pair.new?.path ?? absentPath ?? pair.old?.path ?? "";
|
|
392
|
+
const name = pathOne;
|
|
393
|
+
const other = pathTwo !== name ? pathTwo : undefined;
|
|
394
|
+
const oneDriver = await driverOf(options, pathOne);
|
|
395
|
+
const twoDriver = pathTwo === pathOne ? oneDriver : await driverOf(options, pathTwo);
|
|
396
|
+
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver));
|
|
397
|
+
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver));
|
|
398
|
+
// a side with a textconv driver (git's get_textconv: valid sides only) is text
|
|
399
|
+
const textconvOne = one.driver?.textconv;
|
|
400
|
+
const textconvTwo = two.driver?.textconv;
|
|
401
|
+
const isBinary = async () =>
|
|
402
|
+
!options.text &&
|
|
403
|
+
((!textconvOne && (await one.isBinary(threshold))) ||
|
|
404
|
+
(!textconvTwo && (await two.isBinary(threshold))));
|
|
405
|
+
// fill_metainfo: with --binary a binary pair's index line has full ids
|
|
406
|
+
const binaryFull =
|
|
407
|
+
options.binaryPatch === true &&
|
|
408
|
+
one.id !== two.id &&
|
|
409
|
+
((one.valid && (await one.isBinary(threshold))) ||
|
|
410
|
+
(two.valid && (await two.isBinary(threshold))));
|
|
411
|
+
const meta = metainfo(pair, one, two, name, other, options, binaryFull);
|
|
412
|
+
let mustShow = meta.mustShow;
|
|
413
|
+
|
|
414
|
+
const aPrefix = options.srcPrefix ?? "a/";
|
|
415
|
+
const bPrefix = options.dstPrefix ?? "b/";
|
|
416
|
+
const nameA = one.valid ? name : (other ?? name);
|
|
417
|
+
const nameB = two.valid ? (other ?? name) : nameA;
|
|
418
|
+
const aOne = quoteTwo(aPrefix, stripSlash(nameA), quote);
|
|
419
|
+
const bTwo = quoteTwo(bPrefix, stripSlash(nameB), quote);
|
|
420
|
+
const lbl0 = one.valid ? aOne : "/dev/null";
|
|
421
|
+
const lbl1 = two.valid ? bTwo : "/dev/null";
|
|
422
|
+
let header = `diff --git ${aOne} ${bTwo}\n`;
|
|
423
|
+
if (!one.valid) {
|
|
424
|
+
header += `new file mode ${octal6(two.mode)}\n${meta.text}`;
|
|
425
|
+
mustShow = true;
|
|
426
|
+
} else if (!two.valid) {
|
|
427
|
+
header += `deleted file mode ${octal6(one.mode)}\n${meta.text}`;
|
|
428
|
+
mustShow = true;
|
|
429
|
+
} else {
|
|
430
|
+
if (one.mode !== two.mode) {
|
|
431
|
+
header += `old mode ${octal6(one.mode)}\nnew mode ${octal6(two.mode)}\n`;
|
|
432
|
+
mustShow = true;
|
|
433
|
+
}
|
|
434
|
+
header += meta.text;
|
|
435
|
+
if ((one.mode ^ two.mode) & S_IFMT) return;
|
|
436
|
+
}
|
|
437
|
+
if (report) {
|
|
438
|
+
report.gitLine = `diff --git ${aOne} ${bTwo}`;
|
|
439
|
+
report.extended = header.slice(report.gitLine.length + 1);
|
|
440
|
+
report.binary = false;
|
|
441
|
+
report.result = undefined;
|
|
442
|
+
report.oldLabel = undefined;
|
|
443
|
+
report.newLabel = undefined;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const binary = await isBinary();
|
|
447
|
+
if (binary) {
|
|
448
|
+
if (report) report.binary = true;
|
|
449
|
+
// ids name the contents: equal ids, equal contents; an absent side is empty
|
|
450
|
+
const same =
|
|
451
|
+
one.valid && two.valid
|
|
452
|
+
? one.id === two.id
|
|
453
|
+
: (await one.size(threshold)) === 0 && (await two.size(threshold)) === 0;
|
|
454
|
+
if (same) {
|
|
455
|
+
if (mustShow) sink.text(header);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (options.binaryPatch) {
|
|
459
|
+
const a = one.valid ? await one.read() : new Uint8Array(0);
|
|
460
|
+
const b = two.valid ? await two.read() : new Uint8Array(0);
|
|
461
|
+
// "quite common confusing case": equal bytes under different ids
|
|
462
|
+
if (a.length === b.length && a.every((x, i) => x === b[i])) {
|
|
463
|
+
if (mustShow) sink.text(header);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
sink.text(header);
|
|
467
|
+
sink.text(gitBinaryPatch(a, b));
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
sink.text(header);
|
|
471
|
+
sink.text(`Binary files ${lbl0} and ${lbl1} differ\n`);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (mustShow) {
|
|
476
|
+
sink.text(header);
|
|
477
|
+
header = "";
|
|
478
|
+
}
|
|
479
|
+
const driver = one.driver?.findFunction ? one.driver : two.driver;
|
|
480
|
+
const algorithm = oneDriver?.algorithm ?? options.algorithm;
|
|
481
|
+
const textOne = textconvOne
|
|
482
|
+
? await textconvOne(await one.textconvInput(), pathOne)
|
|
483
|
+
: await one.read();
|
|
484
|
+
const textTwo = textconvTwo
|
|
485
|
+
? await textconvTwo(await two.textconvInput(), pathTwo)
|
|
486
|
+
: await two.read();
|
|
487
|
+
const result = unifiedDiffHunks(textOne, textTwo, {
|
|
488
|
+
...options,
|
|
489
|
+
algorithm,
|
|
490
|
+
indentHeuristic: options.indentHeuristic ?? true,
|
|
491
|
+
findFunction: driver?.findFunction,
|
|
492
|
+
});
|
|
493
|
+
if (report) report.result = result;
|
|
494
|
+
if (result.hunks.length === 0) return;
|
|
495
|
+
if (header) sink.text(header);
|
|
496
|
+
const oldLabel = `--- ${lbl0}${lbl0.includes(" ") ? "\t" : ""}`;
|
|
497
|
+
const newLabel = `+++ ${lbl1}${lbl1.includes(" ") ? "\t" : ""}`;
|
|
498
|
+
if (report) {
|
|
499
|
+
report.oldLabel = oldLabel;
|
|
500
|
+
report.newLabel = newLabel;
|
|
501
|
+
}
|
|
502
|
+
sink.text(`${oldLabel}\n${newLabel}\n`);
|
|
503
|
+
writeHunks(sink, result);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function stripSlash(name: string): string {
|
|
507
|
+
return name.startsWith("/") ? name.slice(1) : name;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// --- diffstat ---------------------------------------------------------------------------
|
|
511
|
+
|
|
512
|
+
/** One file of a diffstat (`struct diffstat_file`) */
|
|
513
|
+
export interface DiffstatFile {
|
|
514
|
+
/** The old name of a renamed (or differently named) pair */
|
|
515
|
+
fromName?: string;
|
|
516
|
+
name: string;
|
|
517
|
+
isRenamed: boolean;
|
|
518
|
+
isBinary: boolean;
|
|
519
|
+
isUnmerged?: boolean;
|
|
520
|
+
/** Lines added (binary: new size in bytes) */
|
|
521
|
+
added: number;
|
|
522
|
+
/** Lines deleted (binary: old size in bytes) */
|
|
523
|
+
deleted: number;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** The diffstat of the pairs (`builtin_diffstat` for each) */
|
|
527
|
+
export async function computeDiffstat(
|
|
528
|
+
pairs: DiffFilePair[],
|
|
529
|
+
options: DiffOutputOptions = {},
|
|
530
|
+
): Promise<DiffstatFile[]> {
|
|
531
|
+
const threshold = options.bigFileThreshold ?? GIT_DIFF_BIG_FILE_THRESHOLD;
|
|
532
|
+
const files: DiffstatFile[] = [];
|
|
533
|
+
for (const pair of pairs) {
|
|
534
|
+
const nameA = pair.old?.path ?? pair.new?.path ?? "";
|
|
535
|
+
const nameB = pair.new?.path ?? nameA;
|
|
536
|
+
const renamed = nameB !== nameA;
|
|
537
|
+
const file: DiffstatFile = {
|
|
538
|
+
...(renamed ? { fromName: nameA } : {}),
|
|
539
|
+
name: renamed ? nameB : nameA,
|
|
540
|
+
isRenamed: renamed,
|
|
541
|
+
isBinary: false,
|
|
542
|
+
added: 0,
|
|
543
|
+
deleted: 0,
|
|
544
|
+
};
|
|
545
|
+
files.push(file);
|
|
546
|
+
const pathOne = nameA;
|
|
547
|
+
const oneDriver = await driverOf(options, pathOne);
|
|
548
|
+
const twoDriver = nameB === nameA ? oneDriver : await driverOf(options, nameB);
|
|
549
|
+
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver));
|
|
550
|
+
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver));
|
|
551
|
+
// git's may_differ: both ids known and equal, or the contents are compared
|
|
552
|
+
const mayDiffer = !(
|
|
553
|
+
one.valid &&
|
|
554
|
+
two.valid &&
|
|
555
|
+
one.spec?.idValid !== false &&
|
|
556
|
+
two.spec?.idValid !== false &&
|
|
557
|
+
one.id === two.id
|
|
558
|
+
);
|
|
559
|
+
// builtin_diffstat: `--text` does not apply, binary files count bytes
|
|
560
|
+
if ((await one.isBinary(threshold)) || (await two.isBinary(threshold))) {
|
|
561
|
+
file.isBinary = true;
|
|
562
|
+
if (mayDiffer) {
|
|
563
|
+
file.added = await two.size(threshold);
|
|
564
|
+
file.deleted = await one.size(threshold);
|
|
565
|
+
}
|
|
566
|
+
} else if (mayDiffer) {
|
|
567
|
+
const counts = diffLineCounts(await one.read(), await two.read(), {
|
|
568
|
+
...options,
|
|
569
|
+
algorithm: oneDriver?.algorithm ?? options.algorithm,
|
|
570
|
+
indentHeuristic: options.indentHeuristic ?? true,
|
|
571
|
+
});
|
|
572
|
+
file.added = counts.added;
|
|
573
|
+
file.deleted = counts.deleted;
|
|
574
|
+
if (
|
|
575
|
+
one.valid &&
|
|
576
|
+
two.valid &&
|
|
577
|
+
pair.status === "M" &&
|
|
578
|
+
!file.added &&
|
|
579
|
+
!file.deleted &&
|
|
580
|
+
one.mode === two.mode
|
|
581
|
+
) {
|
|
582
|
+
files.pop();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return files;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** Options of {@link formatStat} (`--stat=<width>[,<name-width>[,<count>]]`) */
|
|
590
|
+
export interface DiffstatOptions {
|
|
591
|
+
/** Total width (`COLUMNS`, default 80) */
|
|
592
|
+
width?: number;
|
|
593
|
+
/** Width of the name part (`--stat-name-width`, `diff.statNameWidth`) */
|
|
594
|
+
nameWidth?: number;
|
|
595
|
+
/** Width of the graph part (`--stat-graph-width`, `diff.statGraphWidth`) */
|
|
596
|
+
graphWidth?: number;
|
|
597
|
+
/** Files shown (`--stat-count`) */
|
|
598
|
+
count?: number;
|
|
599
|
+
/** `core.quotePath` (default true) */
|
|
600
|
+
quotePath?: boolean;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** git's `pprint_rename`: `a/{b => c}/d` */
|
|
604
|
+
export function pprintRename(a: string, b: string, quote = true): string {
|
|
605
|
+
const qa = quoteCStyleBody(a, quote);
|
|
606
|
+
const qb = quoteCStyleBody(b, quote);
|
|
607
|
+
if (qa !== undefined || qb !== undefined) {
|
|
608
|
+
return `${quotePath(a, quote)} => ${quotePath(b, quote)}`;
|
|
609
|
+
}
|
|
610
|
+
const ea = encodeGitPath(a);
|
|
611
|
+
const eb = encodeGitPath(b);
|
|
612
|
+
const lenA = ea.length;
|
|
613
|
+
const lenB = eb.length;
|
|
614
|
+
let pfx = 0;
|
|
615
|
+
let i = 0;
|
|
616
|
+
while (i < lenA && i < lenB && ea[i] === eb[i]) {
|
|
617
|
+
if (ea[i] === 0x2f) pfx = i + 1;
|
|
618
|
+
i++;
|
|
619
|
+
}
|
|
620
|
+
let oa = lenA;
|
|
621
|
+
let ob = lenB;
|
|
622
|
+
let sfx = 0;
|
|
623
|
+
const adjust = pfx ? 1 : 0;
|
|
624
|
+
// compares the byte at oa/ob (the terminating NUL at the ends, equal on both sides)
|
|
625
|
+
const at = (arr: Uint8Array, k: number) => (k < arr.length ? arr[k] : 0);
|
|
626
|
+
while (pfx - adjust <= oa && pfx - adjust <= ob && at(ea, oa) === at(eb, ob)) {
|
|
627
|
+
if (at(ea, oa) === 0x2f) sfx = lenA - oa;
|
|
628
|
+
oa--;
|
|
629
|
+
ob--;
|
|
630
|
+
}
|
|
631
|
+
const aMid = Math.max(0, lenA - pfx - sfx);
|
|
632
|
+
const bMid = Math.max(0, lenB - pfx - sfx);
|
|
633
|
+
const dec = (arr: Uint8Array, s: number, e: number) => decodeGitPath(arr.subarray(s, e));
|
|
634
|
+
let out = "";
|
|
635
|
+
if (pfx + sfx) out += `${dec(ea, 0, pfx)}{`;
|
|
636
|
+
out += `${dec(ea, pfx, pfx + aMid)} => ${dec(eb, pfx, pfx + bMid)}`;
|
|
637
|
+
if (pfx + sfx) out += `}${dec(ea, lenA - sfx, lenA)}`;
|
|
638
|
+
return out;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function printName(file: DiffstatFile, quote: boolean): string {
|
|
642
|
+
if (file.isRenamed && file.fromName !== undefined)
|
|
643
|
+
return pprintRename(file.fromName, file.name, quote);
|
|
644
|
+
return quotePath(file.name, quote);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Display width of a name, as git's utf8_strwidth measures it (git 2.56's character widths:
|
|
649
|
+
* wide East Asian characters and emoji two columns, combining marks none; a name that is not
|
|
650
|
+
* valid UTF-8 its byte count)
|
|
651
|
+
*/
|
|
652
|
+
export function displayWidth(s: string): number {
|
|
653
|
+
let ascii = true;
|
|
654
|
+
let width = 0;
|
|
655
|
+
for (let i = 0; i < s.length; i++) {
|
|
656
|
+
const c = s.charCodeAt(i);
|
|
657
|
+
if (c >= 0x7f) {
|
|
658
|
+
ascii = false;
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
if (c >= 0x20) width++;
|
|
662
|
+
}
|
|
663
|
+
return ascii ? width : gitStrWidth(encodeGitPath(s));
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* git's show_stats "scales" a name too wide for `width` columns: leading characters dropped
|
|
668
|
+
* (diff.c's utf8_ish_width steps, byte by byte through what is not UTF-8) until the rest fits
|
|
669
|
+
* in `width - 3`, then up to its first slash when it has one, behind a `...` prefix.
|
|
670
|
+
*/
|
|
671
|
+
function shortenName(name: string, width: number): { prefix: string; name: string; len: number } {
|
|
672
|
+
let nameLen = displayWidth(name);
|
|
673
|
+
if (width >= nameLen) return { prefix: "", name, len: width };
|
|
674
|
+
const len = Math.max(0, width - 3);
|
|
675
|
+
const bytes = encodeGitPath(name);
|
|
676
|
+
let at = 0;
|
|
677
|
+
while (nameLen > len && at < bytes.length) {
|
|
678
|
+
const [w, next] = gitCharWidthAt(bytes, at);
|
|
679
|
+
nameLen -= w;
|
|
680
|
+
at = next;
|
|
681
|
+
}
|
|
682
|
+
let rest = bytes.subarray(at);
|
|
683
|
+
const slash = rest.indexOf(0x2f);
|
|
684
|
+
if (slash >= 0) rest = rest.subarray(slash);
|
|
685
|
+
return { prefix: "...", name: decodeGitPath(rest), len };
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function decimalWidth(n: number): number {
|
|
689
|
+
let width = 1;
|
|
690
|
+
for (let v = n; v >= 10; v = Math.floor(v / 10)) width++;
|
|
691
|
+
return width;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function scaleLinear(it: number, width: number, maxChange: number): number {
|
|
695
|
+
if (!it) return 0;
|
|
696
|
+
return 1 + Math.floor((it * (width - 1)) / maxChange);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/** git's `print_stat_summary_inserts_deletes` */
|
|
700
|
+
export function statSummary(files: number, insertions: number, deletions: number): string {
|
|
701
|
+
if (!files) return " 0 files changed\n";
|
|
702
|
+
let s = files === 1 ? ` ${files} file changed` : ` ${files} files changed`;
|
|
703
|
+
if (insertions || deletions === 0) {
|
|
704
|
+
s += insertions === 1 ? `, ${insertions} insertion(+)` : `, ${insertions} insertions(+)`;
|
|
705
|
+
}
|
|
706
|
+
if (deletions || insertions === 0) {
|
|
707
|
+
s += deletions === 1 ? `, ${deletions} deletion(-)` : `, ${deletions} deletions(-)`;
|
|
708
|
+
}
|
|
709
|
+
return `${s}\n`;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/** `--stat`, as git's `show_stats` prints it */
|
|
713
|
+
export function formatStat(files: DiffstatFile[], options: DiffstatOptions = {}): string {
|
|
714
|
+
if (files.length === 0) return "";
|
|
715
|
+
const quote = options.quotePath ?? true;
|
|
716
|
+
const isInteresting = (_f: DiffstatFile) => true;
|
|
717
|
+
let count = options.count ?? files.length;
|
|
718
|
+
let maxChange = 0;
|
|
719
|
+
let maxLen = 0;
|
|
720
|
+
let numberWidth = 0;
|
|
721
|
+
let binWidth = 0;
|
|
722
|
+
const names = new Map<DiffstatFile, string>();
|
|
723
|
+
let i = 0;
|
|
724
|
+
for (; i < count && i < files.length; i++) {
|
|
725
|
+
const file = files[i];
|
|
726
|
+
const change = file.added + file.deleted;
|
|
727
|
+
if (!isInteresting(file) && change === 0) {
|
|
728
|
+
count++;
|
|
729
|
+
continue;
|
|
730
|
+
}
|
|
731
|
+
const name = printName(file, quote);
|
|
732
|
+
names.set(file, name);
|
|
733
|
+
const len = displayWidth(name);
|
|
734
|
+
if (maxLen < len) maxLen = len;
|
|
735
|
+
if (file.isUnmerged) {
|
|
736
|
+
binWidth = binWidth < 8 ? 8 : binWidth;
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
if (file.isBinary) {
|
|
740
|
+
const w = 14 + decimalWidth(file.added) + decimalWidth(file.deleted);
|
|
741
|
+
binWidth = binWidth < w ? w : binWidth;
|
|
742
|
+
numberWidth = 3;
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
if (maxChange < change) maxChange = change;
|
|
746
|
+
}
|
|
747
|
+
count = i;
|
|
748
|
+
|
|
749
|
+
let width = options.width ?? 80;
|
|
750
|
+
numberWidth = decimalWidth(maxChange) > numberWidth ? decimalWidth(maxChange) : numberWidth;
|
|
751
|
+
const statNameWidth = options.nameWidth ?? 0;
|
|
752
|
+
const statGraphWidth = options.graphWidth ?? 0;
|
|
753
|
+
if (width < 16 + 6 + numberWidth) width = 16 + 6 + numberWidth;
|
|
754
|
+
let graphWidth = maxChange + 4 > binWidth ? maxChange : binWidth - 4;
|
|
755
|
+
if (statGraphWidth && statGraphWidth < graphWidth) graphWidth = statGraphWidth;
|
|
756
|
+
let nameWidth = statNameWidth > 0 && statNameWidth < maxLen ? statNameWidth : maxLen;
|
|
757
|
+
if (nameWidth + numberWidth + 6 + graphWidth > width) {
|
|
758
|
+
if (graphWidth > Math.trunc((width * 3) / 8) - numberWidth - 6) {
|
|
759
|
+
graphWidth = Math.trunc((width * 3) / 8) - numberWidth - 6;
|
|
760
|
+
if (graphWidth < 6) graphWidth = 6;
|
|
761
|
+
}
|
|
762
|
+
if (statGraphWidth && graphWidth > statGraphWidth) graphWidth = statGraphWidth;
|
|
763
|
+
if (nameWidth > width - numberWidth - 6 - graphWidth) {
|
|
764
|
+
nameWidth = width - numberWidth - 6 - graphWidth;
|
|
765
|
+
} else {
|
|
766
|
+
graphWidth = width - numberWidth - 6 - nameWidth;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
let out = "";
|
|
771
|
+
for (i = 0; i < count; i++) {
|
|
772
|
+
const file = files[i];
|
|
773
|
+
const added = file.added;
|
|
774
|
+
const deleted = file.deleted;
|
|
775
|
+
if (!isInteresting(file) && added + deleted === 0) continue;
|
|
776
|
+
let name = names.get(file) ?? printName(file, quote);
|
|
777
|
+
const shortened = shortenName(name, nameWidth);
|
|
778
|
+
const prefix = shortened.prefix;
|
|
779
|
+
const len = shortened.len;
|
|
780
|
+
name = shortened.name;
|
|
781
|
+
const padding = Math.max(0, len - displayWidth(name));
|
|
782
|
+
const pad = " ".repeat(padding);
|
|
783
|
+
if (file.isBinary) {
|
|
784
|
+
out += ` ${prefix}${name}${pad} | ${"Bin".padStart(numberWidth)}`;
|
|
785
|
+
if (!added && !deleted) {
|
|
786
|
+
out += "\n";
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
out += ` ${deleted} -> ${added} bytes\n`;
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
if (file.isUnmerged) {
|
|
793
|
+
out += ` ${prefix}${name}${pad} | ${"Unmerged\n".padStart(numberWidth)}`;
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
let add = added;
|
|
797
|
+
let del = deleted;
|
|
798
|
+
if (graphWidth <= maxChange) {
|
|
799
|
+
let total = scaleLinear(add + del, graphWidth, maxChange);
|
|
800
|
+
if (total < 2 && add && del) total = 2;
|
|
801
|
+
if (add < del) {
|
|
802
|
+
add = scaleLinear(add, graphWidth, maxChange);
|
|
803
|
+
del = total - add;
|
|
804
|
+
} else {
|
|
805
|
+
del = scaleLinear(del, graphWidth, maxChange);
|
|
806
|
+
add = total - del;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
out += ` ${prefix}${name}${pad} | ${String(added + deleted).padStart(numberWidth)}`;
|
|
810
|
+
out += added + deleted ? " " : "";
|
|
811
|
+
out += "+".repeat(Math.max(0, add));
|
|
812
|
+
out += "-".repeat(Math.max(0, del));
|
|
813
|
+
out += "\n";
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
let totalFiles = files.length;
|
|
817
|
+
let adds = 0;
|
|
818
|
+
let dels = 0;
|
|
819
|
+
let extraShown = false;
|
|
820
|
+
for (i = 0; i < files.length; i++) {
|
|
821
|
+
const file = files[i];
|
|
822
|
+
if (file.isUnmerged || (!isInteresting(file) && file.added + file.deleted === 0)) {
|
|
823
|
+
totalFiles--;
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
if (!file.isBinary) {
|
|
827
|
+
adds += file.added;
|
|
828
|
+
dels += file.deleted;
|
|
829
|
+
}
|
|
830
|
+
if (i < count) continue;
|
|
831
|
+
if (!extraShown) out += " ...\n";
|
|
832
|
+
extraShown = true;
|
|
833
|
+
}
|
|
834
|
+
return out + statSummary(totalFiles, adds, dels);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/** `--shortstat` (git's `show_shortstats`) */
|
|
838
|
+
export function formatShortstat(files: DiffstatFile[]): string {
|
|
839
|
+
if (files.length === 0) return "";
|
|
840
|
+
let totalFiles = files.length;
|
|
841
|
+
let adds = 0;
|
|
842
|
+
let dels = 0;
|
|
843
|
+
for (const file of files) {
|
|
844
|
+
if (file.isUnmerged) totalFiles--;
|
|
845
|
+
else if (!file.isBinary) {
|
|
846
|
+
adds += file.added;
|
|
847
|
+
dels += file.deleted;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return statSummary(totalFiles, adds, dels);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/** `--numstat` (git's `show_numstat`) */
|
|
854
|
+
export function formatNumstat(
|
|
855
|
+
files: DiffstatFile[],
|
|
856
|
+
options: { quotePath?: boolean } = {},
|
|
857
|
+
): string {
|
|
858
|
+
const quote = options.quotePath ?? true;
|
|
859
|
+
let out = "";
|
|
860
|
+
for (const file of files) {
|
|
861
|
+
out += file.isBinary ? "-\t-\t" : `${file.added}\t${file.deleted}\t`;
|
|
862
|
+
out += file.isRenamed ? printName(file, quote) : quotePath(file.name, quote);
|
|
863
|
+
out += "\n";
|
|
864
|
+
}
|
|
865
|
+
return out;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/** `--name-only`: the new path of each pair */
|
|
869
|
+
export function formatNameOnly(
|
|
870
|
+
pairs: DiffFilePair[],
|
|
871
|
+
options: { quotePath?: boolean } = {},
|
|
872
|
+
): string {
|
|
873
|
+
const quote = options.quotePath ?? true;
|
|
874
|
+
return pairs.map((p) => `${quotePath(p.new?.path ?? p.old?.path ?? "", quote)}\n`).join("");
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/** `--name-status` (git's `diff_flush_raw` with `DIFF_FORMAT_NAME_STATUS`) */
|
|
878
|
+
export function formatNameStatus(
|
|
879
|
+
pairs: DiffFilePair[],
|
|
880
|
+
options: { quotePath?: boolean } = {},
|
|
881
|
+
): string {
|
|
882
|
+
const quote = options.quotePath ?? true;
|
|
883
|
+
let out = "";
|
|
884
|
+
for (const p of pairs) {
|
|
885
|
+
const score = p.status === "R" || p.status === "C" ? (p.score ?? 0) : 0;
|
|
886
|
+
out += score ? `${p.status}${String(score).padStart(3, "0")}\t` : `${p.status}\t`;
|
|
887
|
+
if (p.status === "R" || p.status === "C") {
|
|
888
|
+
out += `${quotePath(p.old?.path ?? "", quote)}\t${quotePath(p.new?.path ?? "", quote)}\n`;
|
|
889
|
+
} else {
|
|
890
|
+
out += `${quotePath(p.old ? p.old.path : (p.new?.path ?? ""), quote)}\n`;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
return out;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* `--summary` (diff.c's diff_summary for each pair): ` create mode 100644 <path>`, ` delete
|
|
898
|
+
* mode ...`, ` rename <a => b> (<n>%)` and ` copy ...` (then their mode change), ` mode change
|
|
899
|
+
* 100644 => 100755 <path>`; empty when nothing is to be said (git's is_summary_empty).
|
|
900
|
+
*/
|
|
901
|
+
export function formatSummary(pairs: DiffFilePair[], quote = true): string {
|
|
902
|
+
const mode6 = (mode: number) => mode.toString(8).padStart(6, "0");
|
|
903
|
+
const modeChange = (p: DiffFilePair, showName: boolean) => {
|
|
904
|
+
const a = p.old?.mode ?? 0;
|
|
905
|
+
const b = p.new?.mode ?? 0;
|
|
906
|
+
if (!a || !b || a === b) return "";
|
|
907
|
+
const name = showName ? ` ${quotePath(p.new?.path ?? "", quote)}` : "";
|
|
908
|
+
return ` mode change ${mode6(a)} => ${mode6(b)}${name}\n`;
|
|
909
|
+
};
|
|
910
|
+
const fileModeName = (what: string, side: DiffSideSpec | undefined) =>
|
|
911
|
+
side?.mode
|
|
912
|
+
? ` ${what} mode ${mode6(side.mode)} ${quotePath(side.path, quote)}\n`
|
|
913
|
+
: ` ${what} ${quotePath(side?.path ?? "", quote)}\n`;
|
|
914
|
+
let out = "";
|
|
915
|
+
for (const p of pairs) {
|
|
916
|
+
switch (p.status) {
|
|
917
|
+
case "D":
|
|
918
|
+
out += fileModeName("delete", p.old);
|
|
919
|
+
break;
|
|
920
|
+
case "A":
|
|
921
|
+
out += fileModeName("create", p.new);
|
|
922
|
+
break;
|
|
923
|
+
case "R":
|
|
924
|
+
case "C": {
|
|
925
|
+
const kind = p.status === "R" ? "rename" : "copy";
|
|
926
|
+
const names = pprintRename(p.old?.path ?? "", p.new?.path ?? "", quote);
|
|
927
|
+
out += ` ${kind} ${names} (${p.score ?? 0}%)\n`;
|
|
928
|
+
out += modeChange(p, false);
|
|
929
|
+
break;
|
|
930
|
+
}
|
|
931
|
+
default:
|
|
932
|
+
// a rewrite (a broken pair, `-B`) has a score
|
|
933
|
+
if (p.score) out += ` rewrite ${quotePath(p.new?.path ?? "", quote)} (${p.score}%)\n`;
|
|
934
|
+
out += modeChange(p, !p.score);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
return out;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* A side whose content is a stored blob (a submodule's: "Subproject commit <id>\n", as git
|
|
942
|
+
* shows a gitlink). The probe reads a text blob once and keeps it for {@link DiffSideSpec.read}.
|
|
943
|
+
*/
|
|
944
|
+
export function blobSide(blobs: Blobs, path: string, mode: number, id: string): DiffSideSpec {
|
|
945
|
+
if ((mode & S_IFMT) === 0o160000) {
|
|
946
|
+
const content = encoder.encode(`Subproject commit ${id}\n`);
|
|
947
|
+
return { path, mode, id, read: async () => content };
|
|
948
|
+
}
|
|
949
|
+
let loaded: Uint8Array | undefined;
|
|
950
|
+
return {
|
|
951
|
+
path,
|
|
952
|
+
mode,
|
|
953
|
+
id,
|
|
954
|
+
async read() {
|
|
955
|
+
if (loaded) return loaded;
|
|
956
|
+
const chunks: Uint8Array[] = [];
|
|
957
|
+
let size = 0;
|
|
958
|
+
for await (const chunk of (await blobs.load(id)) ?? []) {
|
|
959
|
+
chunks.push(chunk);
|
|
960
|
+
size += chunk.length;
|
|
961
|
+
}
|
|
962
|
+
const out = new Uint8Array(size);
|
|
963
|
+
let at = 0;
|
|
964
|
+
for (const c of chunks) {
|
|
965
|
+
out.set(c, at);
|
|
966
|
+
at += c.length;
|
|
967
|
+
}
|
|
968
|
+
loaded = out;
|
|
969
|
+
return out;
|
|
970
|
+
},
|
|
971
|
+
async probe(bigFileThreshold: number) {
|
|
972
|
+
const probe = await probeBlob(blobs, id, { bigFileThreshold, loadText: true });
|
|
973
|
+
if (probe.content) loaded = probe.content;
|
|
974
|
+
return { size: probe.size, binary: probe.binary };
|
|
975
|
+
},
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/** A side whose content comes from elsewhere (a worktree file, a file outside a repository) */
|
|
980
|
+
export function contentSide(
|
|
981
|
+
path: string,
|
|
982
|
+
mode: number,
|
|
983
|
+
id: string,
|
|
984
|
+
read: () => Promise<Uint8Array>,
|
|
985
|
+
idValid = false,
|
|
986
|
+
): DiffSideSpec {
|
|
987
|
+
let content: Promise<Uint8Array> | undefined;
|
|
988
|
+
return {
|
|
989
|
+
path,
|
|
990
|
+
mode,
|
|
991
|
+
id,
|
|
992
|
+
idValid,
|
|
993
|
+
read: () => {
|
|
994
|
+
content ??= read();
|
|
995
|
+
return content;
|
|
996
|
+
},
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* Bytes for a string (diff output pieces are UTF-8; a path's escaped bytes, unquoted with
|
|
1002
|
+
* `core.quotePath=false`, are written as the bytes they stand for)
|
|
1003
|
+
*/
|
|
1004
|
+
export function utf8(s: string): Uint8Array {
|
|
1005
|
+
return encodeGitPath(s);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/** A file of a `--no-index` diff: its path as given, content, and mode (default 100644) */
|
|
1009
|
+
export interface NoIndexFile {
|
|
1010
|
+
path: string;
|
|
1011
|
+
/** Undefined for a side that does not exist (`/dev/null`) */
|
|
1012
|
+
content?: Uint8Array;
|
|
1013
|
+
mode?: number;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/** The blob id of `content` (as `hash-object` computes it) */
|
|
1017
|
+
export function blobIdOf(content: Uint8Array): string {
|
|
1018
|
+
return bytesToHex(
|
|
1019
|
+
createSha1()
|
|
1020
|
+
.update(encoder.encode(`blob ${content.length}\0`))
|
|
1021
|
+
.update(content)
|
|
1022
|
+
.digest(),
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* The pair `diff --no-index a b` compares for two files: a modification between two names
|
|
1028
|
+
* (no rename detection), or an addition or deletion against `/dev/null`.
|
|
1029
|
+
*/
|
|
1030
|
+
export function noIndexPair(a: NoIndexFile, b: NoIndexFile): DiffFilePair | undefined {
|
|
1031
|
+
const side = (f: NoIndexFile): DiffSideSpec | undefined => {
|
|
1032
|
+
if (!f.content) return undefined;
|
|
1033
|
+
const content = f.content;
|
|
1034
|
+
return contentSide(f.path, f.mode ?? 0o100644, blobIdOf(content), async () => content);
|
|
1035
|
+
};
|
|
1036
|
+
const old = side(a);
|
|
1037
|
+
const neu = side(b);
|
|
1038
|
+
if (!old && !neu) return undefined;
|
|
1039
|
+
if (old && neu && old.id === neu.id && old.mode === neu.mode) return undefined;
|
|
1040
|
+
return { status: !old ? "A" : !neu ? "D" : "M", old, new: neu };
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
/** `diff --no-index a b` for two files, as git prints it */
|
|
1044
|
+
export async function formatNoIndexDiff(
|
|
1045
|
+
a: NoIndexFile,
|
|
1046
|
+
b: NoIndexFile,
|
|
1047
|
+
options: DiffOutputOptions = {},
|
|
1048
|
+
): Promise<Uint8Array> {
|
|
1049
|
+
const pair = noIndexPair(a, b);
|
|
1050
|
+
return pair ? formatPatch([pair], options) : new Uint8Array(0);
|
|
1051
|
+
}
|