@statewalker/vcs-commands 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -8
- package/dist/commands/add-command.d.ts +265 -34
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-interactive.d.ts +46 -0
- package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
- package/dist/commands/add-patch/add-patch.d.ts +139 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
- package/dist/commands/add-patch/index.d.ts +6 -0
- package/dist/commands/add-patch/index.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-backend.d.ts +80 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-modes.d.ts +71 -0
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-session.d.ts +49 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
- package/dist/commands/am/am-command.d.ts +175 -0
- package/dist/commands/am/am-command.d.ts.map +1 -0
- package/dist/commands/am/index.d.ts +3 -0
- package/dist/commands/am/index.d.ts.map +1 -0
- package/dist/commands/am/mailinfo.d.ts +58 -0
- package/dist/commands/am/mailinfo.d.ts.map +1 -0
- package/dist/commands/am/patch-format.d.ts +24 -0
- package/dist/commands/am/patch-format.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts +153 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -0
- package/dist/commands/apply/apply-engine.d.ts +195 -0
- package/dist/commands/apply/apply-engine.d.ts.map +1 -0
- package/dist/commands/apply/apply-parse.d.ts +86 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -0
- package/dist/commands/apply/apply-types.d.ts +70 -0
- package/dist/commands/apply/apply-types.d.ts.map +1 -0
- package/dist/commands/apply/index.d.ts +6 -0
- package/dist/commands/apply/index.d.ts.map +1 -0
- package/dist/commands/apply/latin1.d.ts +32 -0
- package/dist/commands/apply/latin1.d.ts.map +1 -0
- package/dist/commands/apply/whitespace.d.ts +58 -0
- package/dist/commands/apply/whitespace.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +26 -0
- package/dist/commands/attributes-source.d.ts.map +1 -0
- package/dist/commands/backfill-command.d.ts +110 -0
- package/dist/commands/backfill-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
- package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-command.d.ts +201 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-engine.d.ts +219 -0
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-graph.d.ts +127 -0
- package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-quote.d.ts +27 -0
- package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
- package/dist/commands/bisect/index.d.ts +5 -0
- package/dist/commands/bisect/index.d.ts.map +1 -0
- package/dist/commands/blame-command.d.ts +122 -131
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +52 -2
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-tracking.d.ts +98 -0
- package/dist/commands/branch-tracking.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +300 -18
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +124 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +50 -42
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +49 -16
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +117 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +311 -17
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +78 -1
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/date-format.d.ts +58 -0
- package/dist/commands/date-format.d.ts.map +1 -0
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +377 -30
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-textconv.d.ts +40 -0
- package/dist/commands/diff-textconv.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +149 -10
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts +164 -0
- package/dist/commands/format-patch-command.d.ts.map +1 -0
- package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts +225 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +68 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +115 -0
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
- package/dist/commands/fsck/index.d.ts +6 -0
- package/dist/commands/fsck/index.d.ts.map +1 -0
- package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +43 -0
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +66 -0
- package/dist/commands/git-date.d.ts.map +1 -0
- package/dist/commands/git-describe.d.ts +67 -0
- package/dist/commands/git-describe.d.ts.map +1 -0
- package/dist/commands/git-hooks.d.ts +416 -0
- package/dist/commands/git-hooks.d.ts.map +1 -0
- package/dist/commands/git-ident.d.ts +128 -0
- package/dist/commands/git-ident.d.ts.map +1 -0
- package/dist/commands/hook-command.d.ts +96 -0
- package/dist/commands/hook-command.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +231 -0
- package/dist/commands/index-adder.d.ts.map +1 -0
- package/dist/commands/index-host.d.ts +86 -0
- package/dist/commands/index-host.d.ts.map +1 -0
- package/dist/commands/index.d.ts +54 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +12 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/local-clone.d.ts +60 -0
- package/dist/commands/local-clone.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +117 -0
- package/dist/commands/local-transport.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +216 -24
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +120 -0
- package/dist/commands/log-graph.d.ts.map +1 -0
- package/dist/commands/log-output.d.ts +323 -0
- package/dist/commands/log-output.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +23 -7
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +31 -0
- package/dist/commands/mailmap.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +85 -0
- package/dist/commands/merge-bases.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +209 -74
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +13 -0
- package/dist/commands/merge-config.d.ts.map +1 -0
- package/dist/commands/merge-drivers.d.ts +130 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +252 -0
- package/dist/commands/merge-support.d.ts.map +1 -0
- package/dist/commands/message-cleanup.d.ts +86 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -0
- package/dist/commands/mv-command.d.ts +94 -0
- package/dist/commands/mv-command.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts +256 -0
- package/dist/commands/notes-command.d.ts.map +1 -0
- package/dist/commands/notes-commands.d.ts +41 -0
- package/dist/commands/notes-commands.d.ts.map +1 -0
- package/dist/commands/notes-merge-command.d.ts +105 -0
- package/dist/commands/notes-merge-command.d.ts.map +1 -0
- package/dist/commands/notes-support.d.ts +125 -0
- package/dist/commands/notes-support.d.ts.map +1 -0
- package/dist/commands/notes-tree.d.ts +106 -0
- package/dist/commands/notes-tree.d.ts.map +1 -0
- package/dist/commands/object-id-input.d.ts +20 -0
- package/dist/commands/object-id-input.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +59 -0
- package/dist/commands/octopus-merge.d.ts.map +1 -0
- package/dist/commands/ort-merge.d.ts +126 -0
- package/dist/commands/ort-merge.d.ts.map +1 -0
- package/dist/commands/ort-recursive.d.ts +53 -0
- package/dist/commands/ort-recursive.d.ts.map +1 -0
- package/dist/commands/pack-refs-command.d.ts +20 -0
- package/dist/commands/pack-refs-command.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +41 -0
- package/dist/commands/patch-id.d.ts.map +1 -0
- package/dist/commands/pathspec-attributes.d.ts +64 -0
- package/dist/commands/pathspec-attributes.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +324 -0
- package/dist/commands/pathspec.d.ts.map +1 -0
- package/dist/commands/post-index-change.d.ts +33 -0
- package/dist/commands/post-index-change.d.ts.map +1 -0
- package/dist/commands/pretty-format.d.ts +222 -0
- package/dist/commands/pretty-format.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts +80 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -0
- package/dist/commands/pull-command.d.ts +41 -8
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +24 -8
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +112 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -0
- package/dist/commands/rebase-command.d.ts +507 -75
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/rebase-todo.d.ts +130 -0
- package/dist/commands/rebase-todo.d.ts.map +1 -0
- package/dist/commands/ref-decoration-filter.d.ts +53 -0
- package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
- package/dist/commands/reflog-messages.d.ts +98 -0
- package/dist/commands/reflog-messages.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +31 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +120 -0
- package/dist/commands/remote-transport.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +161 -7
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +103 -0
- package/dist/commands/restore-command.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +78 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -0
- package/dist/commands/rev-parse-command.d.ts +80 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -0
- package/dist/commands/revert-command.d.ts +46 -38
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-filenames.d.ts +95 -0
- package/dist/commands/revision-filenames.d.ts.map +1 -0
- package/dist/commands/revision-range.d.ts +67 -0
- package/dist/commands/revision-range.d.ts.map +1 -0
- package/dist/commands/revision-resolver.d.ts +321 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -0
- package/dist/commands/rm-command.d.ts +69 -7
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +191 -0
- package/dist/commands/sequencer-pick.d.ts.map +1 -0
- package/dist/commands/sequencer-support.d.ts +125 -0
- package/dist/commands/sequencer-support.d.ts.map +1 -0
- package/dist/commands/serve-repository.d.ts +52 -0
- package/dist/commands/serve-repository.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts +190 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-support.d.ts +268 -0
- package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +42 -8
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +155 -1
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +2 -0
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +23 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts +300 -15
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-format.d.ts +155 -0
- package/dist/commands/status-format.d.ts.map +1 -0
- package/dist/commands/status-header.d.ts +64 -0
- package/dist/commands/status-header.d.ts.map +1 -0
- package/dist/commands/strerror.d.ts +7 -0
- package/dist/commands/strerror.d.ts.map +1 -0
- package/dist/commands/submodule-config.d.ts +38 -0
- package/dist/commands/submodule-config.d.ts.map +1 -0
- package/dist/commands/submodule-summary-command.d.ts +80 -0
- package/dist/commands/submodule-summary-command.d.ts.map +1 -0
- package/dist/commands/submodule-summary.d.ts +150 -0
- package/dist/commands/submodule-summary.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +132 -0
- package/dist/commands/switch-command.d.ts.map +1 -0
- package/dist/commands/tag-command.d.ts +23 -2
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tracking-info.d.ts +64 -0
- package/dist/commands/tracking-info.d.ts.map +1 -0
- package/dist/commands/trailers.d.ts +73 -0
- package/dist/commands/trailers.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +85 -1
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +53 -0
- package/dist/commands/untracked-cache-support.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +108 -0
- package/dist/commands/worktree-add-command.d.ts.map +1 -0
- package/dist/commands/worktree-list-command.d.ts +69 -0
- package/dist/commands/worktree-list-command.d.ts.map +1 -0
- package/dist/commands/worktree-lock-command.d.ts +44 -0
- package/dist/commands/worktree-lock-command.d.ts.map +1 -0
- package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/commands/worktree-prune-command.d.ts +48 -0
- package/dist/commands/worktree-prune-command.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +59 -0
- package/dist/commands/worktree-remove-command.d.ts.map +1 -0
- package/dist/commands/worktree-repair-command.d.ts +35 -0
- package/dist/commands/worktree-repair-command.d.ts.map +1 -0
- package/dist/commands/worktree-support.d.ts +64 -0
- package/dist/commands/worktree-support.d.ts.map +1 -0
- package/dist/commands-DnmlfwGV.js +61620 -0
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/errors/add-errors.d.ts +55 -0
- package/dist/errors/add-errors.d.ts.map +1 -1
- package/dist/errors/checkout-errors.d.ts +16 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts +77 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/commit-errors.d.ts +9 -0
- package/dist/errors/commit-errors.d.ts.map +1 -1
- package/dist/errors/git-api-error.d.ts +59 -2
- package/dist/errors/git-api-error.d.ts.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +354 -19
- package/dist/errors/rebase-errors.d.ts +9 -0
- package/dist/errors/rebase-errors.d.ts.map +1 -1
- package/dist/errors/ref-errors.d.ts +32 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/transport-errors.d.ts +12 -2
- package/dist/errors/transport-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +35 -0
- package/dist/errors/worktree-errors.d.ts.map +1 -0
- package/dist/git-command-DxvwPrPB.js +7612 -0
- package/dist/git-command.d.ts +413 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +306 -3
- package/dist/git.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/remote-config-store.d.ts +105 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +7 -3
- package/dist/remote-config/remote-refs.d.ts.map +1 -1
- package/dist/rename/detect-renames.d.ts +148 -0
- package/dist/rename/detect-renames.d.ts.map +1 -0
- package/dist/rename/git-similarity.d.ts +44 -0
- package/dist/rename/git-similarity.d.ts.map +1 -0
- package/dist/rename/index.d.ts +2 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/binary-patch.d.ts +11 -0
- package/dist/results/binary-patch.d.ts.map +1 -0
- package/dist/results/blame-format.d.ts +55 -0
- package/dist/results/blame-format.d.ts.map +1 -0
- package/dist/results/cherry-pick-result.d.ts +10 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +10 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +77 -0
- package/dist/results/combined-diff.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +32 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +34 -60
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-order.d.ts +25 -0
- package/dist/results/diff-order.d.ts.map +1 -0
- package/dist/results/diff-output.d.ts +249 -0
- package/dist/results/diff-output.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +15 -0
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +5 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -252
- package/dist/results/merge-result.d.ts +15 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +12 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +42 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/quote-path.d.ts +27 -0
- package/dist/results/quote-path.d.ts.map +1 -0
- package/dist/results/rebase-result.d.ts +28 -1
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +10 -0
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +5 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +60 -6
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BZGa2Z3I.js +2934 -0
- package/dist/transport-command.d.ts +44 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -11
- package/src/commands/add-command.ts +1291 -226
- package/src/commands/add-patch/add-interactive.ts +941 -0
- package/src/commands/add-patch/add-patch.ts +1169 -0
- package/src/commands/add-patch/index.ts +5 -0
- package/src/commands/add-patch/patch-backend.ts +239 -0
- package/src/commands/add-patch/patch-modes.ts +249 -0
- package/src/commands/add-patch/patch-session.ts +159 -0
- package/src/commands/am/am-command.ts +1111 -0
- package/src/commands/am/index.ts +2 -0
- package/src/commands/am/mailinfo.ts +1015 -0
- package/src/commands/am/patch-format.ts +121 -0
- package/src/commands/apply/apply-command.ts +832 -0
- package/src/commands/apply/apply-engine.ts +1603 -0
- package/src/commands/apply/apply-parse.ts +1209 -0
- package/src/commands/apply/apply-types.ts +112 -0
- package/src/commands/apply/index.ts +5 -0
- package/src/commands/apply/latin1.ts +171 -0
- package/src/commands/apply/whitespace.ts +260 -0
- package/src/commands/attributes-source.ts +96 -0
- package/src/commands/backfill-command.ts +694 -0
- package/src/commands/bisect/bisect-checkout.ts +217 -0
- package/src/commands/bisect/bisect-command.ts +788 -0
- package/src/commands/bisect/bisect-engine.ts +1079 -0
- package/src/commands/bisect/bisect-graph.ts +595 -0
- package/src/commands/bisect/bisect-quote.ts +92 -0
- package/src/commands/bisect/index.ts +4 -0
- package/src/commands/blame-command.ts +711 -986
- package/src/commands/branch-command.ts +354 -32
- package/src/commands/branch-tracking.ts +331 -0
- package/src/commands/checkout-command.ts +1290 -243
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +504 -156
- package/src/commands/clone-command.ts +634 -67
- package/src/commands/commit-command.ts +1781 -166
- package/src/commands/core-config.ts +161 -6
- package/src/commands/date-format.ts +668 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1898 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +606 -66
- package/src/commands/format-patch-command.ts +969 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3347 -0
- package/src/commands/fsck/fsck-loose.ts +287 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1044 -0
- package/src/commands/fsck/fsck-object-table.ts +363 -0
- package/src/commands/fsck/fsck-pack.ts +604 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +249 -0
- package/src/commands/gc-command.ts +147 -1
- package/src/commands/git-date.ts +895 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1472 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +706 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +82 -0
- package/src/commands/init-command.ts +28 -4
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1915 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +101 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1386 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1198 -0
- package/src/commands/message-cleanup.ts +275 -0
- package/src/commands/mv-command.ts +976 -0
- package/src/commands/notes-command.ts +890 -0
- package/src/commands/notes-commands.ts +87 -0
- package/src/commands/notes-merge-command.ts +768 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +602 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +377 -0
- package/src/commands/ort-merge.ts +1660 -0
- package/src/commands/ort-recursive.ts +160 -0
- package/src/commands/pack-refs-command.ts +39 -22
- package/src/commands/patch-id.ts +196 -0
- package/src/commands/pathspec-attributes.ts +162 -0
- package/src/commands/pathspec.ts +1199 -0
- package/src/commands/post-index-change.ts +62 -0
- package/src/commands/pretty-format.ts +1431 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +207 -22
- package/src/commands/push-command.ts +236 -23
- package/src/commands/read-tree-command.ts +857 -0
- package/src/commands/rebase-command.ts +3808 -371
- package/src/commands/rebase-todo.ts +584 -0
- package/src/commands/ref-decoration-filter.ts +118 -0
- package/src/commands/reflog-messages.ts +177 -0
- package/src/commands/remote-command.ts +93 -22
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +827 -103
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +277 -0
- package/src/commands/revert-command.ts +152 -399
- package/src/commands/revision-filenames.ts +254 -0
- package/src/commands/revision-range.ts +222 -0
- package/src/commands/revision-resolver.ts +1379 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +869 -0
- package/src/commands/sequencer-support.ts +869 -0
- package/src/commands/serve-repository.ts +125 -0
- package/src/commands/sparse-checkout-command.ts +1389 -0
- package/src/commands/sparse-checkout-support.ts +793 -0
- package/src/commands/stash-apply-command.ts +376 -343
- package/src/commands/stash-create-command.ts +625 -42
- package/src/commands/stash-drop-command.ts +15 -2
- package/src/commands/stash-working-tree.ts +168 -24
- package/src/commands/status-command.ts +1328 -105
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +330 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +334 -0
- package/src/commands/submodule-summary.ts +446 -0
- package/src/commands/switch-command.ts +402 -0
- package/src/commands/tag-command.ts +129 -41
- package/src/commands/tracking-info.ts +201 -0
- package/src/commands/trailers.ts +417 -0
- package/src/commands/tree-restore.ts +204 -4
- package/src/commands/untracked-cache-support.ts +194 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +208 -0
- package/src/commands/worktree-lock-command.ts +96 -0
- package/src/commands/worktree-overwrite-checks.ts +452 -26
- package/src/commands/worktree-prune-command.ts +99 -0
- package/src/commands/worktree-remove-command.ts +186 -0
- package/src/commands/worktree-repair-command.ts +59 -0
- package/src/commands/worktree-support.ts +214 -0
- package/src/core-commands/add.command.impl.ts +7 -1
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +26 -2
- package/src/errors/command-errors.ts +101 -1
- package/src/errors/commit-errors.ts +18 -2
- package/src/errors/git-api-error.ts +82 -2
- package/src/errors/index.ts +1 -0
- package/src/errors/merge-errors.ts +2 -2
- package/src/errors/rebase-errors.ts +12 -0
- package/src/errors/ref-errors.ts +56 -2
- package/src/errors/remote-errors.ts +2 -2
- package/src/errors/stash-errors.ts +1 -1
- package/src/errors/transport-errors.ts +20 -4
- package/src/errors/worktree-errors.ts +49 -0
- package/src/git-command.ts +1177 -118
- package/src/git.ts +523 -10
- package/src/index.ts +1 -1
- package/src/remote-config/remote-config-store.ts +242 -8
- package/src/remote-config/remote-refs.ts +22 -6
- package/src/rename/detect-renames.ts +711 -0
- package/src/rename/git-similarity.ts +116 -0
- package/src/rename/index.ts +2 -0
- package/src/results/binary-patch.ts +401 -0
- package/src/results/blame-format.ts +239 -0
- package/src/results/cherry-pick-result.ts +10 -0
- package/src/results/clone-result.ts +12 -0
- package/src/results/combined-diff.ts +585 -0
- package/src/results/diff-entry.ts +35 -0
- package/src/results/diff-formatter.ts +152 -288
- package/src/results/diff-order.ts +64 -0
- package/src/results/diff-output.ts +1051 -0
- package/src/results/fetch-result.ts +15 -0
- package/src/results/index.ts +5 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +12 -3
- package/src/results/push-result.ts +43 -0
- package/src/results/quote-path.ts +103 -0
- package/src/results/rebase-result.ts +37 -0
- package/src/results/revert-result.ts +10 -0
- package/src/results/stash-result.ts +6 -0
- package/src/results/status-result.ts +123 -45
- package/src/transport-command.ts +121 -2
- package/dist/commands-CsLNyvZ1.js +0 -12587
- package/dist/status-result-BpyUK1Sg.js +0 -519
|
@@ -0,0 +1,1431 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's user formats (`--format=<format>`, `rebase.instructionFormat`): the placeholders
|
|
3
|
+
* pretty.c's format_commit_message expands for one commit.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* await formatCommitPretty("# %s (%an)", commit, id, { abbreviate });
|
|
8
|
+
* // "# Fix the parser (A U Thor)"
|
|
9
|
+
* const decorations = await loadRefDecorations({ refs, tags });
|
|
10
|
+
* await formatCommitPretty("%h%d", commit, id, { abbreviate, decorations });
|
|
11
|
+
* // "1a2b3c4 (HEAD -> main, tag: v1, origin/main)"
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Supported: `%H %h %T %t %P %p`, the author and committer parts `%an %aN %ae %aE %al %aL
|
|
15
|
+
* %ad %aD %ar %at %ai %aI %as %ah` (and `%c…`; `%aN`, `%aE`, `%aL` through the mailmap given, `%ad` in the date mode given),
|
|
16
|
+
* `%s %f %b %B %e`, `%n %%` and `%x<hex>` (a byte above 0x7f as the repository's byte strings
|
|
17
|
+
* keep a raw byte: U+DC80 to U+DCFF, which `encodeGitPath` writes back as that byte), `%d %D`
|
|
18
|
+
* and `%(decorate:…)` from {@link loadRefDecorations}, `%m` (`>`, or the mark given), `%G?`
|
|
19
|
+
* (`N` unsigned; a signed commit is `E`, as git prints for a signature it cannot check) and
|
|
20
|
+
* the other `%G` parts (empty; `%GT` `undefined`), `%N` (the notes given, else kept as
|
|
21
|
+
* written, as git's sequencer keeps it), `%gd %gD %gs %gn %gN %ge %gE` (the reflog entry
|
|
22
|
+
* given, else empty), colors (`%Cred`, `%C(...)`: written only with `color`, or `always,`),
|
|
23
|
+
* padding (`%<(N)`, `%>(N)`, `%><(N)`, `%>>(N)`, the `|` column forms, `trunc`, `ltrunc`,
|
|
24
|
+
* `mtrunc`), wrapping (`%w(width,indent1,indent2)`), the `%+`, `%-` and `% ` magic,
|
|
25
|
+
* `%(trailers[:options])` (trailer.c's block detection and formatting, with the
|
|
26
|
+
* {@link TrailerConfig} given), `%(describe[:options])` (with the describer given), `%S`
|
|
27
|
+
* (the source given) and git 2.5x's `%(count)`/`%(total)`. A placeholder git does not
|
|
28
|
+
* know is kept as written, as git keeps an unknown one.
|
|
29
|
+
*
|
|
30
|
+
* @module
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import type { ObjectId, PersonIdent } from "@statewalker/vcs-core";
|
|
34
|
+
import { gitCharWidth } from "@statewalker/vcs-utils/encoding";
|
|
35
|
+
import { formatRfc2822Date } from "./git-date.js";
|
|
36
|
+
import type { DescribeOptions } from "./git-describe.js";
|
|
37
|
+
import {
|
|
38
|
+
createRefDecorationFilter,
|
|
39
|
+
decorateFullRefs,
|
|
40
|
+
type RefDecorationFilterOptions,
|
|
41
|
+
} from "./ref-decoration-filter.js";
|
|
42
|
+
import { formatGitDate } from "./sequencer-support.js";
|
|
43
|
+
import { appendTrailers, type TrailerConfig, type TrailerFormatOptions } from "./trailers.js";
|
|
44
|
+
|
|
45
|
+
/** What a format reads of the commit besides its fields. */
|
|
46
|
+
export interface PrettyFormatOptions {
|
|
47
|
+
/**
|
|
48
|
+
* The abbreviation of an id for `%h`, `%t`, `%p` (git's find_unique_abbrev with the
|
|
49
|
+
* context's `abbrev`); the full id when absent, as with an abbrev of 0
|
|
50
|
+
*/
|
|
51
|
+
abbreviate?: (id: ObjectId) => Promise<string>;
|
|
52
|
+
/** Now, in seconds since the epoch, for `%ar` and `%ah` (default: the clock) */
|
|
53
|
+
now?: number;
|
|
54
|
+
/**
|
|
55
|
+
* The local time zone's offset east of UTC, in minutes, at a time in seconds (`%ah` hides
|
|
56
|
+
* the zone of a date in it); default: the host's (`Date.getTimezoneOffset`)
|
|
57
|
+
*/
|
|
58
|
+
localTzOffset?: (time: number) => number;
|
|
59
|
+
/** The decorations `%d`, `%D` and `%(decorate)` show (see {@link loadRefDecorations}) */
|
|
60
|
+
decorations?: RefDecorations;
|
|
61
|
+
/** `%m`: the commit's mark (`<`, `>`, `-` boundary, `^` uninteresting); default `>` */
|
|
62
|
+
mark?: string;
|
|
63
|
+
/** `%N`: the commit's notes; without, `%N` is kept as written (git's sequencer) */
|
|
64
|
+
notes?: string;
|
|
65
|
+
/** `%gd`, `%gD`, `%gs`, `%gn`…: the reflog entry shown; empty without */
|
|
66
|
+
reflog?: { selector?: string; shortSelector?: string; message?: string; ident?: PersonIdent };
|
|
67
|
+
/** Whether colors are written (git's want_color; default false, as without a terminal) */
|
|
68
|
+
color?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* `%(trailers)`: the trailer configuration (`trailer.separators`, `trailer.<name>.key`,
|
|
71
|
+
* the comment prefix; see {@link trailerConfigOf}); default git's (`:`, `#`, no items)
|
|
72
|
+
*/
|
|
73
|
+
trailers?: TrailerConfig;
|
|
74
|
+
/**
|
|
75
|
+
* `%(describe)`: git describe of a commit (see {@link createDescriber}); without, the
|
|
76
|
+
* placeholder is kept as written
|
|
77
|
+
*/
|
|
78
|
+
describe?: (id: ObjectId, options: DescribeOptions) => Promise<string>;
|
|
79
|
+
/**
|
|
80
|
+
* `%S`: the name on the command line the commit was reached from (`git log --source`, or
|
|
81
|
+
* a `%S` in log's format); without, `%S` is kept as written, as git keeps it without a
|
|
82
|
+
* revision walk's sources
|
|
83
|
+
*/
|
|
84
|
+
source?: string;
|
|
85
|
+
/**
|
|
86
|
+
* `%(count)` and `%(total)` (git 2.5x): the walk's number of this commit and the count
|
|
87
|
+
* (`git log` gives 0 and 0, `format-patch` the patch numbers); without, git's "not
|
|
88
|
+
* supported by this command"
|
|
89
|
+
*/
|
|
90
|
+
count?: { nr: number; total: number };
|
|
91
|
+
/**
|
|
92
|
+
* `%ad` and `%cd`: the date in the walk's date mode (`--date`, `log.date`); default git's
|
|
93
|
+
* default mode
|
|
94
|
+
*/
|
|
95
|
+
formatDate?: (ident: PersonIdent) => string;
|
|
96
|
+
/**
|
|
97
|
+
* `%aN`, `%aE`, `%aL` (and `%c…`): the identity through the mailmap (see `Mailmap`);
|
|
98
|
+
* without, they are `%an`, `%ae`, `%al`
|
|
99
|
+
*/
|
|
100
|
+
mailmap?: (name: string, email: string) => { name: string; email: string };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** One name a commit is decorated with (log-tree.c's name_decoration). */
|
|
104
|
+
export interface RefDecoration {
|
|
105
|
+
type: "head" | "local" | "remote" | "tag" | "stash" | "grafted" | "none";
|
|
106
|
+
/** The full ref name, `HEAD`, `grafted` or `replaced` */
|
|
107
|
+
name: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The decorations of each object, as load_ref_decorations collects them. */
|
|
111
|
+
export interface RefDecorations {
|
|
112
|
+
/** An object's decorations, in git's order (the last added first) */
|
|
113
|
+
get(id: ObjectId): readonly RefDecoration[] | undefined;
|
|
114
|
+
/** The branch HEAD names (`refs/heads/main`); undefined when detached */
|
|
115
|
+
headBranch?: string;
|
|
116
|
+
/** Full ref names are shown (`log.decorate=full`, `--decorate=full`); short ones by default */
|
|
117
|
+
fullRefs?: boolean;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Options of {@link loadRefDecorations}. */
|
|
121
|
+
export interface LoadRefDecorationsOptions {
|
|
122
|
+
/** The refs decorated (every ref, then HEAD) */
|
|
123
|
+
refs: {
|
|
124
|
+
list(prefix?: string): AsyncIterable<{ name: string; objectId?: ObjectId; target?: string }>;
|
|
125
|
+
resolve(name: string): Promise<{ objectId?: ObjectId } | undefined>;
|
|
126
|
+
};
|
|
127
|
+
/** Annotated tags: a tag ref decorates each object of its chain */
|
|
128
|
+
tags?: {
|
|
129
|
+
has(id: ObjectId): Promise<boolean>;
|
|
130
|
+
load(id: ObjectId): Promise<{ object: ObjectId } | undefined>;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* `git log`'s default decoration filter: only HEAD, `refs/heads/`, `refs/tags/`,
|
|
134
|
+
* `refs/remotes/`, `refs/stash` and the replace refs (default false: every ref, as git's
|
|
135
|
+
* sequencer loads them)
|
|
136
|
+
*/
|
|
137
|
+
logFilter?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* `git log`'s decoration options and settings (see `createRefDecorationFilter`):
|
|
140
|
+
* `--decorate-refs`, `--decorate-refs-exclude`, `--clear-decorations`, and the
|
|
141
|
+
* configuration's `log.excludeDecoration`, `log.initialDecorationSet` and `log.decorate`
|
|
142
|
+
* (`full`: full ref names). Given, the refs are filtered as `git log` filters them, as with
|
|
143
|
+
* `logFilter`.
|
|
144
|
+
*/
|
|
145
|
+
logOptions?: Omit<RefDecorationFilterOptions, "replaceRefBase"> & {
|
|
146
|
+
/** `--decorate=short|full` (default `log.decorate`, else short) */
|
|
147
|
+
decorate?: "short" | "full";
|
|
148
|
+
};
|
|
149
|
+
/** Where replace refs live (default `refs/replace/`); their originals read `replaced` */
|
|
150
|
+
replaceRefBase?: string;
|
|
151
|
+
/** Whether replace refs apply (default true); off, they decorate nothing */
|
|
152
|
+
useReplaceRefs?: boolean;
|
|
153
|
+
/** The grafted commits (and shallow ones), each decorated `grafted` */
|
|
154
|
+
grafted?: Iterable<ObjectId>;
|
|
155
|
+
/** Whether an object is stored (a replaced original that is not is not decorated) */
|
|
156
|
+
hasObject?: (id: ObjectId) => Promise<boolean>;
|
|
157
|
+
/**
|
|
158
|
+
* Receives what git prints on stderr while decorating: `warning: invalid replace ref
|
|
159
|
+
* <name>` for a ref under the replace base that does not start with an object id below it
|
|
160
|
+
*/
|
|
161
|
+
onWarning?: (message: string) => void;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The decorations of a repository's objects, as git's load_ref_decorations makes them: each
|
|
166
|
+
* ref in name order, then HEAD, then each graft, every one put before those its object
|
|
167
|
+
* already has; a ref is typed by its namespace, an annotated tag decorates every object of
|
|
168
|
+
* its chain as a tag, a replace ref decorates the object it replaces as `replaced`.
|
|
169
|
+
*/
|
|
170
|
+
export async function loadRefDecorations(
|
|
171
|
+
options: LoadRefDecorationsOptions,
|
|
172
|
+
): Promise<RefDecorations> {
|
|
173
|
+
const map = new Map<ObjectId, RefDecoration[]>();
|
|
174
|
+
const add = (id: ObjectId, decoration: RefDecoration) => {
|
|
175
|
+
const list = map.get(id);
|
|
176
|
+
if (list) list.unshift(decoration);
|
|
177
|
+
else map.set(id, [decoration]);
|
|
178
|
+
};
|
|
179
|
+
const replaceBase = options.replaceRefBase ?? "refs/replace/";
|
|
180
|
+
const logOptions = options.logOptions;
|
|
181
|
+
const included =
|
|
182
|
+
options.logFilter || logOptions
|
|
183
|
+
? createRefDecorationFilter({ ...logOptions, replaceRefBase: replaceBase })
|
|
184
|
+
: () => true;
|
|
185
|
+
const fullRefs = logOptions?.decorate
|
|
186
|
+
? logOptions.decorate === "full"
|
|
187
|
+
: decorateFullRefs(logOptions?.config);
|
|
188
|
+
const typeOf = (name: string): RefDecoration["type"] => {
|
|
189
|
+
if (name === "HEAD") return "head";
|
|
190
|
+
if (name.startsWith("refs/heads/")) return "local";
|
|
191
|
+
if (name.startsWith("refs/tags/")) return "tag";
|
|
192
|
+
if (name.startsWith("refs/remotes/")) return "remote";
|
|
193
|
+
if (name === "refs/stash") return "stash";
|
|
194
|
+
return "none";
|
|
195
|
+
};
|
|
196
|
+
const decorateRef = async (name: string, value: ObjectId | undefined) => {
|
|
197
|
+
if (!included(name)) return;
|
|
198
|
+
if (name.startsWith(replaceBase)) {
|
|
199
|
+
if (options.useReplaceRefs === false) return;
|
|
200
|
+
const hex = name.slice(replaceBase.length);
|
|
201
|
+
if (!/^[0-9a-fA-F]{40}/.test(hex)) {
|
|
202
|
+
// add_ref_decoration: get_oid_hex of what follows the base
|
|
203
|
+
options.onWarning?.(`warning: invalid replace ref ${name}`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const original = hex.slice(0, 40).toLowerCase();
|
|
207
|
+
if (options.hasObject && !(await options.hasObject(original))) return;
|
|
208
|
+
add(original, { type: "grafted", name: "replaced" });
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!value) return;
|
|
212
|
+
add(value, { type: typeOf(name), name });
|
|
213
|
+
// an annotated tag: each object of its chain is decorated as a tag
|
|
214
|
+
let id = value;
|
|
215
|
+
for (let depth = 0; depth < 32 && options.tags && (await options.tags.has(id)); depth++) {
|
|
216
|
+
const tag = await options.tags.load(id);
|
|
217
|
+
if (!tag) break;
|
|
218
|
+
id = tag.object;
|
|
219
|
+
add(id, { type: "tag", name });
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
const names: { name: string; objectId?: ObjectId; target?: string }[] = [];
|
|
223
|
+
for await (const ref of options.refs.list()) {
|
|
224
|
+
if (ref.name === "HEAD" || !ref.name.startsWith("refs/")) continue;
|
|
225
|
+
names.push(ref);
|
|
226
|
+
}
|
|
227
|
+
names.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
228
|
+
for (const ref of names) {
|
|
229
|
+
const value =
|
|
230
|
+
ref.objectId && ref.target === undefined
|
|
231
|
+
? ref.objectId
|
|
232
|
+
: (await options.refs.resolve(ref.name))?.objectId;
|
|
233
|
+
await decorateRef(ref.name, value);
|
|
234
|
+
}
|
|
235
|
+
let headBranch: string | undefined;
|
|
236
|
+
for await (const ref of options.refs.list("HEAD")) {
|
|
237
|
+
if (ref.name === "HEAD" && ref.target !== undefined) headBranch = ref.target;
|
|
238
|
+
}
|
|
239
|
+
await decorateRef("HEAD", (await options.refs.resolve("HEAD"))?.objectId);
|
|
240
|
+
for (const id of options.grafted ?? []) add(id, { type: "grafted", name: "grafted" });
|
|
241
|
+
return {
|
|
242
|
+
get: (id) => map.get(id),
|
|
243
|
+
...(headBranch?.startsWith("refs/") ? { headBranch } : {}),
|
|
244
|
+
...(fullRefs ? { fullRefs } : {}),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** git's prettify_refname: `refs/heads/`, `refs/tags/`, `refs/remotes/` dropped. */
|
|
249
|
+
function prettifyRefName(name: string): string {
|
|
250
|
+
for (const prefix of ["refs/heads/", "refs/tags/", "refs/remotes/"]) {
|
|
251
|
+
if (name.startsWith(prefix)) return name.slice(prefix.length);
|
|
252
|
+
}
|
|
253
|
+
return name;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* log-tree.c's format_decorations, without colors: ` (HEAD -> main, tag: v1)` by default,
|
|
258
|
+
* the separators given otherwise; empty when the object has no decorations.
|
|
259
|
+
*/
|
|
260
|
+
export function formatRefDecorations(
|
|
261
|
+
decorations: RefDecorations | undefined,
|
|
262
|
+
id: ObjectId,
|
|
263
|
+
opts: { prefix?: string; suffix?: string; separator?: string; pointer?: string; tag?: string },
|
|
264
|
+
): string {
|
|
265
|
+
const list = decorations?.get(id);
|
|
266
|
+
if (!list) return "";
|
|
267
|
+
let prefix = opts.prefix ?? " (";
|
|
268
|
+
const suffix = opts.suffix ?? ")";
|
|
269
|
+
const separator = opts.separator ?? ", ";
|
|
270
|
+
const pointer = opts.pointer ?? " -> ";
|
|
271
|
+
const tag = opts.tag ?? "tag: ";
|
|
272
|
+
// current_pointed_by_HEAD: HEAD's branch, when both are in the list
|
|
273
|
+
const head = list.find((d) => d.type === "head");
|
|
274
|
+
const current =
|
|
275
|
+
head && decorations?.headBranch
|
|
276
|
+
? list.find((d) => d.type === "local" && d.name === decorations.headBranch)
|
|
277
|
+
: undefined;
|
|
278
|
+
let out = "";
|
|
279
|
+
for (const d of list) {
|
|
280
|
+
if (d === current) continue;
|
|
281
|
+
out += prefix;
|
|
282
|
+
if (tag && d.type === "tag") out += tag;
|
|
283
|
+
// show_name: full names with --decorate=full
|
|
284
|
+
const show = (name: string) => (decorations?.fullRefs ? name : prettifyRefName(name));
|
|
285
|
+
out += show(d.name);
|
|
286
|
+
if (current && d.type === "head") out += pointer + show(current.name);
|
|
287
|
+
prefix = separator;
|
|
288
|
+
}
|
|
289
|
+
return out + suffix;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** What {@link formatCommitPretty} reads of a commit. */
|
|
293
|
+
export interface PrettyCommit {
|
|
294
|
+
tree: ObjectId;
|
|
295
|
+
parents: ObjectId[];
|
|
296
|
+
author: PersonIdent;
|
|
297
|
+
committer: PersonIdent;
|
|
298
|
+
message: string;
|
|
299
|
+
encoding?: string;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const pad2 = (n: number) => String(n).padStart(2, "0");
|
|
303
|
+
|
|
304
|
+
/** The ident's time shifted into its own zone, as a UTC Date, and the zone in minutes. */
|
|
305
|
+
function zoned(ident: PersonIdent): { d: Date; minutes: number; tz: string } {
|
|
306
|
+
const tz = /^[+-]\d{4}$/.test(ident.tzOffset) ? ident.tzOffset : "+0000";
|
|
307
|
+
const sign = tz.startsWith("-") ? -1 : 1;
|
|
308
|
+
const minutes = sign * (Number(tz.slice(1, 3)) * 60 + Number(tz.slice(3, 5)));
|
|
309
|
+
return { d: new Date((ident.timestamp + minutes * 60) * 1000), minutes, tz };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** git's DATE_ISO8601: `2005-04-07 22:13:13 +0200`. */
|
|
313
|
+
function isoDate(ident: PersonIdent): string {
|
|
314
|
+
const { d, tz } = zoned(ident);
|
|
315
|
+
return (
|
|
316
|
+
`${d.getUTCFullYear()}-${pad2(d.getUTCMonth() + 1)}-${pad2(d.getUTCDate())} ` +
|
|
317
|
+
`${pad2(d.getUTCHours())}:${pad2(d.getUTCMinutes())}:${pad2(d.getUTCSeconds())} ${tz}`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** git's DATE_ISO8601_STRICT (2.5x): `2005-04-07T22:13:13+02:00`, `Z` for UTC. */
|
|
322
|
+
function strictIsoDate(ident: PersonIdent): string {
|
|
323
|
+
const { d, minutes, tz } = zoned(ident);
|
|
324
|
+
const zone = minutes === 0 ? "Z" : `${tz.slice(0, 3)}:${tz.slice(3)}`;
|
|
325
|
+
return (
|
|
326
|
+
`${d.getUTCFullYear()}-${pad2(d.getUTCMonth() + 1)}-${pad2(d.getUTCDate())}T` +
|
|
327
|
+
`${pad2(d.getUTCHours())}:${pad2(d.getUTCMinutes())}:${pad2(d.getUTCSeconds())}${zone}`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** git's DATE_SHORT: `2005-04-07`. */
|
|
332
|
+
function shortDate(ident: PersonIdent): string {
|
|
333
|
+
const { d } = zoned(ident);
|
|
334
|
+
return `${d.getUTCFullYear()}-${pad2(d.getUTCMonth() + 1)}-${pad2(d.getUTCDate())}`;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
338
|
+
const MONTH_NAMES = [
|
|
339
|
+
"Jan",
|
|
340
|
+
"Feb",
|
|
341
|
+
"Mar",
|
|
342
|
+
"Apr",
|
|
343
|
+
"May",
|
|
344
|
+
"Jun",
|
|
345
|
+
"Jul",
|
|
346
|
+
"Aug",
|
|
347
|
+
"Sep",
|
|
348
|
+
"Oct",
|
|
349
|
+
"Nov",
|
|
350
|
+
"Dec",
|
|
351
|
+
];
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* git's DATE_HUMAN (date.c show_date_normal with the current time): today's dates relative,
|
|
355
|
+
* this week's `Wed 14:03`, this year's `Mar 3`, older ones `Mar 3 2019`; the zone shown only
|
|
356
|
+
* when it is not the local one (and the date is near).
|
|
357
|
+
*/
|
|
358
|
+
export function humanDate(
|
|
359
|
+
ident: PersonIdent,
|
|
360
|
+
now: number,
|
|
361
|
+
localTzOffset: (time: number) => number,
|
|
362
|
+
): string {
|
|
363
|
+
const { d, tz } = zoned(ident);
|
|
364
|
+
const nowMinutes = localTzOffset(now);
|
|
365
|
+
const human = new Date((now + nowMinutes * 60) * 1000);
|
|
366
|
+
const sign = nowMinutes < 0 ? "-" : "+";
|
|
367
|
+
const abs = Math.abs(nowMinutes);
|
|
368
|
+
const humanTz = `${sign}${pad2(Math.floor(abs / 60))}${pad2(abs % 60)}`;
|
|
369
|
+
const hide = { year: false, date: false, wday: false, time: false, seconds: false, tz: false };
|
|
370
|
+
hide.tz = tz === humanTz;
|
|
371
|
+
hide.year = d.getUTCFullYear() === human.getUTCFullYear();
|
|
372
|
+
if (hide.year && d.getUTCMonth() === human.getUTCMonth()) {
|
|
373
|
+
if (d.getUTCDate() > human.getUTCDate()) {
|
|
374
|
+
// a future date: think time zones
|
|
375
|
+
} else if (d.getUTCDate() === human.getUTCDate()) {
|
|
376
|
+
hide.date = hide.wday = true;
|
|
377
|
+
} else if (d.getUTCDate() + 5 > human.getUTCDate()) {
|
|
378
|
+
hide.date = true;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (hide.wday) return relativeDate(ident.timestamp, now);
|
|
382
|
+
hide.seconds = true;
|
|
383
|
+
hide.tz ||= !hide.date;
|
|
384
|
+
hide.wday = hide.time = !hide.year;
|
|
385
|
+
let out = "";
|
|
386
|
+
if (!hide.wday) out += `${WEEKDAYS[d.getUTCDay()]} `;
|
|
387
|
+
if (!hide.date) out += `${MONTH_NAMES[d.getUTCMonth()]} ${d.getUTCDate()} `;
|
|
388
|
+
if (!hide.time) out += `${pad2(d.getUTCHours())}:${pad2(d.getUTCMinutes())}`;
|
|
389
|
+
else out = out.replace(/[ \t\n\r]+$/, "");
|
|
390
|
+
if (!hide.year) out += ` ${d.getUTCFullYear()}`;
|
|
391
|
+
if (!hide.tz) out += ` ${tz}`;
|
|
392
|
+
return out;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** git's show_date_relative: `5 minutes ago`, `2 years, 3 months ago`, `in the future`. */
|
|
396
|
+
export function relativeDate(time: number, now: number): string {
|
|
397
|
+
if (now < time) return "in the future";
|
|
398
|
+
const n = (count: number, one: string) => `${count} ${one}${count === 1 ? "" : "s"}`;
|
|
399
|
+
let diff = now - time;
|
|
400
|
+
if (diff < 90) return `${n(diff, "second")} ago`;
|
|
401
|
+
diff = Math.floor((diff + 30) / 60);
|
|
402
|
+
if (diff < 90) return `${n(diff, "minute")} ago`;
|
|
403
|
+
diff = Math.floor((diff + 30) / 60);
|
|
404
|
+
if (diff < 36) return `${n(diff, "hour")} ago`;
|
|
405
|
+
diff = Math.floor((diff + 12) / 24);
|
|
406
|
+
if (diff < 14) return `${n(diff, "day")} ago`;
|
|
407
|
+
if (diff < 70) return `${n(Math.floor((diff + 3) / 7), "week")} ago`;
|
|
408
|
+
if (diff < 365) return `${n(Math.floor((diff + 15) / 30), "month")} ago`;
|
|
409
|
+
if (diff < 1825) {
|
|
410
|
+
const total = Math.floor((diff * 12 * 2 + 365) / (365 * 2));
|
|
411
|
+
const years = Math.floor(total / 12);
|
|
412
|
+
const months = total % 12;
|
|
413
|
+
return months ? `${n(years, "year")}, ${n(months, "month")} ago` : `${n(years, "year")} ago`;
|
|
414
|
+
}
|
|
415
|
+
return `${n(Math.floor((diff + 183) / 365), "year")} ago`;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** The message's lines: each with its line end. */
|
|
419
|
+
function lineAt(msg: string, at: number): { line: string; next: number } {
|
|
420
|
+
const nl = msg.indexOf("\n", at);
|
|
421
|
+
const next = nl < 0 ? msg.length : nl + 1;
|
|
422
|
+
return { line: msg.slice(at, next), next };
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** git's isspace (sane_ctype): space, tab, LF and CR only, never NBSP or other spaces */
|
|
426
|
+
const GIT_SPACE = /[ \t\n\r]/;
|
|
427
|
+
const TRAILING_SPACE = /[ \t\n\r]+$/;
|
|
428
|
+
const isBlank = (line: string) => line.replace(TRAILING_SPACE, "") === "";
|
|
429
|
+
|
|
430
|
+
/** pretty.c's skip_blank_lines. */
|
|
431
|
+
function skipBlankLines(msg: string, at: number): number {
|
|
432
|
+
let i = at;
|
|
433
|
+
while (i < msg.length) {
|
|
434
|
+
const { line, next } = lineAt(msg, i);
|
|
435
|
+
if (!isBlank(line)) break;
|
|
436
|
+
i = next;
|
|
437
|
+
}
|
|
438
|
+
return i;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** pretty.c's format_subject: the first paragraph's lines, right-trimmed, joined by `sep`. */
|
|
442
|
+
function formatSubject(msg: string, at: number, sep: string): { text: string; end: number } {
|
|
443
|
+
const parts: string[] = [];
|
|
444
|
+
let i = at;
|
|
445
|
+
while (i < msg.length) {
|
|
446
|
+
const { line, next } = lineAt(msg, i);
|
|
447
|
+
i = next;
|
|
448
|
+
const trimmed = line.replace(TRAILING_SPACE, "");
|
|
449
|
+
if (trimmed === "") break;
|
|
450
|
+
parts.push(trimmed);
|
|
451
|
+
}
|
|
452
|
+
return { text: parts.join(sep), end: i };
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const isTitleChar = (c: string) => /^[A-Za-z0-9._]$/.test(c);
|
|
456
|
+
|
|
457
|
+
/** pretty.c's format_sanitized_subject: `Fix the parser.` → `Fix-the-parser`. */
|
|
458
|
+
export function sanitizedSubject(line: string): string {
|
|
459
|
+
let out = "";
|
|
460
|
+
let space = 2;
|
|
461
|
+
for (let i = 0; i < line.length; i++) {
|
|
462
|
+
const c = line[i] as string;
|
|
463
|
+
if (isTitleChar(c)) {
|
|
464
|
+
if (space === 1) out += "-";
|
|
465
|
+
space = 0;
|
|
466
|
+
out += c;
|
|
467
|
+
if (c === ".") while (line[i + 1] === ".") i++;
|
|
468
|
+
} else space |= 1;
|
|
469
|
+
}
|
|
470
|
+
return out.replace(/[.-]+$/, "");
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** A byte of `%x`: ASCII as itself, a byte above 0x7f as the byte strings keep it raw. */
|
|
474
|
+
const rawByte = (n: number) => String.fromCharCode(n < 0x80 ? n : 0xdc00 + n);
|
|
475
|
+
|
|
476
|
+
/** git's hex2chr: two hex digits; -1 when not. */
|
|
477
|
+
function hex2chr(text: string, at: number): number {
|
|
478
|
+
const hex = /^[0-9a-fA-F]{2}/.exec(text.slice(at, at + 2));
|
|
479
|
+
return hex ? Number.parseInt(hex[0], 16) : -1;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** strbuf_expand_literal: `%n` and `%x<hex>`; 0 when the placeholder is neither. */
|
|
483
|
+
function expandLiteral(fmt: string, at: number): { text: string; taken: number } {
|
|
484
|
+
if (fmt[at] === "n") return { text: "\n", taken: 1 };
|
|
485
|
+
if (fmt[at] === "x") {
|
|
486
|
+
const ch = hex2chr(fmt, at + 1);
|
|
487
|
+
if (ch >= 0) return { text: rawByte(ch), taken: 3 };
|
|
488
|
+
}
|
|
489
|
+
return { text: "", taken: 0 };
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** pretty.c's expand_string_arg: an argument's `%n`, `%x<hex>` and `%%` expanded. */
|
|
493
|
+
function expandStringArg(arg: string): string {
|
|
494
|
+
let out = "";
|
|
495
|
+
for (let i = 0; i < arg.length; i++) {
|
|
496
|
+
if (arg[i] !== "%") {
|
|
497
|
+
out += arg[i];
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
if (arg[i + 1] === "%") {
|
|
501
|
+
out += "%";
|
|
502
|
+
i++;
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
const literal = expandLiteral(arg, i + 1);
|
|
506
|
+
if (literal.taken > 0) {
|
|
507
|
+
out += literal.text;
|
|
508
|
+
i += literal.taken;
|
|
509
|
+
} else out += "%";
|
|
510
|
+
}
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const ANSI_COLORS = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"];
|
|
515
|
+
const ATTRS: Record<string, [number, number]> = {
|
|
516
|
+
bold: [1, 22],
|
|
517
|
+
dim: [2, 22],
|
|
518
|
+
italic: [3, 23],
|
|
519
|
+
ul: [4, 24],
|
|
520
|
+
blink: [5, 25],
|
|
521
|
+
reverse: [7, 27],
|
|
522
|
+
strike: [9, 29],
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
/** Thrown for a color git cannot parse ("unable to parse --pretty format"). */
|
|
526
|
+
export class PrettyFormatError extends Error {
|
|
527
|
+
constructor(message: string) {
|
|
528
|
+
super(message);
|
|
529
|
+
this.name = "PrettyFormatError";
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** color.c's color_parse_mem: the escape sequence of a color spec (`bold red`, `#ff0000`). */
|
|
534
|
+
export function parseColorSpec(spec: string): string {
|
|
535
|
+
const words = spec.split(/[ \t\n\r]+/).filter((w) => w !== "");
|
|
536
|
+
if (words.length === 0) return "";
|
|
537
|
+
type Color =
|
|
538
|
+
| { kind: "normal" }
|
|
539
|
+
| { kind: "ansi"; value: number }
|
|
540
|
+
| { kind: "256"; value: number }
|
|
541
|
+
| { kind: "rgb"; r: number; g: number; b: number };
|
|
542
|
+
const parseOne = (word: string): Color | undefined => {
|
|
543
|
+
const w = word.toLowerCase();
|
|
544
|
+
if (w === "normal") return { kind: "normal" };
|
|
545
|
+
if ((word.length === 7 || word.length === 4) && word[0] === "#") {
|
|
546
|
+
const per = word.length === 7 ? 2 : 1;
|
|
547
|
+
const parts = [1, 1 + per, 1 + 2 * per].map((at) => word.slice(at, at + per));
|
|
548
|
+
if (parts.every((p) => /^[0-9a-fA-F]+$/.test(p))) {
|
|
549
|
+
const [r, g, b] = parts.map((p) => Number.parseInt(per === 1 ? p + p : p, 16)) as [
|
|
550
|
+
number,
|
|
551
|
+
number,
|
|
552
|
+
number,
|
|
553
|
+
];
|
|
554
|
+
return { kind: "rgb", r, g, b };
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (w === "default") return { kind: "ansi", value: 39 };
|
|
558
|
+
let base = 30;
|
|
559
|
+
let name = w;
|
|
560
|
+
if (name.startsWith("bright")) {
|
|
561
|
+
base = 90;
|
|
562
|
+
name = name.slice(6);
|
|
563
|
+
}
|
|
564
|
+
const index = ANSI_COLORS.indexOf(name);
|
|
565
|
+
if (index >= 0) return { kind: "ansi", value: base + index };
|
|
566
|
+
if (/^-?\d+$/.test(word)) {
|
|
567
|
+
const val = Number(word);
|
|
568
|
+
if (val === -1) return { kind: "normal" };
|
|
569
|
+
if (val >= 0 && val < 8) return { kind: "ansi", value: 30 + val };
|
|
570
|
+
if (val >= 8 && val < 16) return { kind: "ansi", value: 90 + val - 8 };
|
|
571
|
+
if (val >= 16 && val < 256) return { kind: "256", value: val };
|
|
572
|
+
}
|
|
573
|
+
return undefined;
|
|
574
|
+
};
|
|
575
|
+
let reset = false;
|
|
576
|
+
let attr = 0;
|
|
577
|
+
let fg: Color | undefined;
|
|
578
|
+
let bg: Color | undefined;
|
|
579
|
+
for (const word of words) {
|
|
580
|
+
if (word.toLowerCase() === "reset") {
|
|
581
|
+
reset = true;
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
const color = parseOne(word);
|
|
585
|
+
if (color) {
|
|
586
|
+
if (!fg) fg = color;
|
|
587
|
+
else if (!bg) bg = color;
|
|
588
|
+
else throw new PrettyFormatError("fatal: unable to parse --pretty format");
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
let name = word.toLowerCase();
|
|
592
|
+
let negate = false;
|
|
593
|
+
if (name.startsWith("no")) {
|
|
594
|
+
negate = true;
|
|
595
|
+
name = name.slice(2).replace(/^-/, "");
|
|
596
|
+
}
|
|
597
|
+
const a = ATTRS[name];
|
|
598
|
+
if (!a) throw new PrettyFormatError("fatal: unable to parse --pretty format");
|
|
599
|
+
attr |= 1 << (negate ? a[1] : a[0]);
|
|
600
|
+
}
|
|
601
|
+
const output = (c: Color, background: boolean): string | undefined => {
|
|
602
|
+
const offset = background ? 10 : 0;
|
|
603
|
+
switch (c.kind) {
|
|
604
|
+
case "normal":
|
|
605
|
+
return undefined;
|
|
606
|
+
case "ansi":
|
|
607
|
+
return String(c.value + offset);
|
|
608
|
+
case "256":
|
|
609
|
+
return `${38 + offset};5;${c.value}`;
|
|
610
|
+
case "rgb":
|
|
611
|
+
return `${38 + offset};2;${c.r};${c.g};${c.b}`;
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
const fgOut = fg ? output(fg, false) : undefined;
|
|
615
|
+
const bgOut = bg ? output(bg, true) : undefined;
|
|
616
|
+
if (!reset && attr === 0 && fgOut === undefined && bgOut === undefined) return "";
|
|
617
|
+
const parts: string[] = [];
|
|
618
|
+
if (reset) parts.push("");
|
|
619
|
+
for (let i = 0; attr; i++) {
|
|
620
|
+
if (!(attr & (1 << i))) continue;
|
|
621
|
+
attr &= ~(1 << i);
|
|
622
|
+
parts.push(String(i));
|
|
623
|
+
}
|
|
624
|
+
if (fgOut !== undefined) parts.push(fgOut);
|
|
625
|
+
if (bgOut !== undefined) parts.push(bgOut);
|
|
626
|
+
// a reset is an empty first field: "\x1b[;31m"
|
|
627
|
+
return `\x1b[${parts.join(";")}m`;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** The length of the ANSI color sequence at `at` (display_mode_esc_sequence_len); 0 if none. */
|
|
631
|
+
function escapeLength(text: string, at: number): number {
|
|
632
|
+
if (text[at] !== "\x1b" || text[at + 1] !== "[") return 0;
|
|
633
|
+
let i = at + 2;
|
|
634
|
+
while (i < text.length && /[0-9;]/.test(text[i] as string)) i++;
|
|
635
|
+
return text[i] === "m" ? i + 1 - at : 0;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* The columns a code point takes (git's utf8_width, its unicode-width tables: wide East Asian
|
|
640
|
+
* 2, combining and other non-spacing 0), a control character none.
|
|
641
|
+
*/
|
|
642
|
+
function charWidth(cp: number): number {
|
|
643
|
+
return Math.max(gitCharWidth(cp), 0);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/** utf8_strnwidth with skip_ansi: the columns of `text`, color sequences taking none. */
|
|
647
|
+
function displayWidth(text: string): number {
|
|
648
|
+
let w = 0;
|
|
649
|
+
for (let i = 0; i < text.length; ) {
|
|
650
|
+
const esc = escapeLength(text, i);
|
|
651
|
+
if (esc) {
|
|
652
|
+
i += esc;
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
const cp = text.codePointAt(i) as number;
|
|
656
|
+
w += charWidth(cp);
|
|
657
|
+
i += cp > 0xffff ? 2 : 1;
|
|
658
|
+
}
|
|
659
|
+
return w;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/** strbuf_utf8_replace: the columns [pos, pos + width) of `text` replaced by `subst`. */
|
|
663
|
+
function utf8Replace(text: string, pos: number, width: number, subst: string): string {
|
|
664
|
+
let out = "";
|
|
665
|
+
let w = 0;
|
|
666
|
+
let replaced = false;
|
|
667
|
+
for (let i = 0; i < text.length; ) {
|
|
668
|
+
const esc = escapeLength(text, i);
|
|
669
|
+
if (esc) {
|
|
670
|
+
out += text.slice(i, i + esc);
|
|
671
|
+
i += esc;
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
const cp = text.codePointAt(i) as number;
|
|
675
|
+
const len = cp > 0xffff ? 2 : 1;
|
|
676
|
+
const cw = charWidth(cp);
|
|
677
|
+
// a character of no width (a combining mark) is kept, attached to what precedes it
|
|
678
|
+
if (cw && w >= pos && w < pos + width) {
|
|
679
|
+
if (!replaced) {
|
|
680
|
+
out += subst;
|
|
681
|
+
replaced = true;
|
|
682
|
+
}
|
|
683
|
+
} else out += text.slice(i, i + len);
|
|
684
|
+
w += cw;
|
|
685
|
+
i += len;
|
|
686
|
+
}
|
|
687
|
+
if (!replaced) out += subst;
|
|
688
|
+
return out;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const isAlnum = (c: string | undefined) => c !== undefined && /^[A-Za-z0-9]$/.test(c);
|
|
692
|
+
|
|
693
|
+
/** utf8.c's strbuf_add_wrapped_text: `text` wrapped at `width` columns. */
|
|
694
|
+
export function wrapText(text: string, indent1: number, indent2: number, width: number): string {
|
|
695
|
+
if (width <= 0) {
|
|
696
|
+
// strbuf_add_indented_text
|
|
697
|
+
let out = "";
|
|
698
|
+
let indent = Math.max(indent1, 0);
|
|
699
|
+
let i = 0;
|
|
700
|
+
while (i < text.length) {
|
|
701
|
+
const nl = text.indexOf("\n", i);
|
|
702
|
+
const eol = nl < 0 ? text.length : nl + 1;
|
|
703
|
+
out += " ".repeat(indent) + text.slice(i, eol);
|
|
704
|
+
i = eol;
|
|
705
|
+
indent = indent2;
|
|
706
|
+
}
|
|
707
|
+
return out;
|
|
708
|
+
}
|
|
709
|
+
let out = "";
|
|
710
|
+
let bol = 0;
|
|
711
|
+
let w = indent1;
|
|
712
|
+
let indent = indent1;
|
|
713
|
+
let space: number | undefined;
|
|
714
|
+
if (indent < 0) {
|
|
715
|
+
w = -indent;
|
|
716
|
+
space = 0;
|
|
717
|
+
}
|
|
718
|
+
let i = 0;
|
|
719
|
+
for (;;) {
|
|
720
|
+
let esc = escapeLength(text, i);
|
|
721
|
+
while (esc) {
|
|
722
|
+
i += esc;
|
|
723
|
+
esc = escapeLength(text, i);
|
|
724
|
+
}
|
|
725
|
+
const c = text[i];
|
|
726
|
+
if (c === undefined || GIT_SPACE.test(c)) {
|
|
727
|
+
if (w <= width || space === undefined) {
|
|
728
|
+
let start = bol;
|
|
729
|
+
if (c === undefined && i === start) return out;
|
|
730
|
+
if (space !== undefined) start = space;
|
|
731
|
+
else out += " ".repeat(Math.max(indent, 0));
|
|
732
|
+
out += text.slice(start, i);
|
|
733
|
+
if (c === undefined) return out;
|
|
734
|
+
space = i;
|
|
735
|
+
if (c === "\t") w |= 0x07;
|
|
736
|
+
else if (c === "\n") {
|
|
737
|
+
space++;
|
|
738
|
+
if (text[space] === "\n") {
|
|
739
|
+
out += "\n";
|
|
740
|
+
// new line
|
|
741
|
+
out += "\n";
|
|
742
|
+
bol = space + (GIT_SPACE.test(text[space] ?? "") ? 1 : 0);
|
|
743
|
+
i = bol;
|
|
744
|
+
space = undefined;
|
|
745
|
+
w = indent = indent2;
|
|
746
|
+
continue;
|
|
747
|
+
} else if (!isAlnum(text[space])) {
|
|
748
|
+
out += "\n";
|
|
749
|
+
bol = space + (GIT_SPACE.test(text[space] ?? "") ? 1 : 0);
|
|
750
|
+
i = bol;
|
|
751
|
+
space = undefined;
|
|
752
|
+
w = indent = indent2;
|
|
753
|
+
continue;
|
|
754
|
+
} else out += " ";
|
|
755
|
+
}
|
|
756
|
+
w++;
|
|
757
|
+
i++;
|
|
758
|
+
} else {
|
|
759
|
+
out += "\n";
|
|
760
|
+
bol = space + (GIT_SPACE.test(text[space] ?? "") ? 1 : 0);
|
|
761
|
+
i = bol;
|
|
762
|
+
space = undefined;
|
|
763
|
+
w = indent = indent2;
|
|
764
|
+
}
|
|
765
|
+
continue;
|
|
766
|
+
}
|
|
767
|
+
const cp = text.codePointAt(i) as number;
|
|
768
|
+
// utf8_width as is: a control character takes a column back (-1)
|
|
769
|
+
w += gitCharWidth(cp);
|
|
770
|
+
i += cp > 0xffff ? 2 : 1;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/** The output being built, and the state git's format_commit_context keeps. */
|
|
775
|
+
interface FormatState {
|
|
776
|
+
sb: string;
|
|
777
|
+
/** %w: where the text to wrap starts, and the wrapping in force */
|
|
778
|
+
wrapStart: number;
|
|
779
|
+
width: number;
|
|
780
|
+
indent1: number;
|
|
781
|
+
indent2: number;
|
|
782
|
+
/** %<( and friends: the padding of the next placeholder */
|
|
783
|
+
flush: "none" | "left" | "right" | "both" | "left-steal";
|
|
784
|
+
padding: number;
|
|
785
|
+
truncate: "none" | "left" | "middle" | "right";
|
|
786
|
+
/** whether %C(auto) is in force (colors only with options.color) */
|
|
787
|
+
autoColor: boolean;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/** git's rewrap_message_tail. */
|
|
791
|
+
function rewrapTail(st: FormatState, width: number, indent1: number, indent2: number): void {
|
|
792
|
+
if (st.width === width && st.indent1 === indent1 && st.indent2 === indent2) return;
|
|
793
|
+
if (st.wrapStart < st.sb.length) {
|
|
794
|
+
st.sb =
|
|
795
|
+
st.sb.slice(0, st.wrapStart) +
|
|
796
|
+
wrapText(st.sb.slice(st.wrapStart), st.indent1, st.indent2, st.width);
|
|
797
|
+
}
|
|
798
|
+
st.wrapStart = st.sb.length;
|
|
799
|
+
st.width = width;
|
|
800
|
+
st.indent1 = indent1;
|
|
801
|
+
st.indent2 = indent2;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/** git's FORMATTING_LIMIT */
|
|
805
|
+
const FORMATTING_LIMIT = 16 * 1024;
|
|
806
|
+
|
|
807
|
+
/** pretty.c's parse_padding_placeholder; 0 when it is none. */
|
|
808
|
+
function parsePadding(fmt: string, at: number, st: FormatState): number {
|
|
809
|
+
let ch = at;
|
|
810
|
+
let flush: FormatState["flush"];
|
|
811
|
+
const first = fmt[ch++];
|
|
812
|
+
if (first === "<") flush = "right";
|
|
813
|
+
else if (first === ">") {
|
|
814
|
+
if (fmt[ch] === "<") {
|
|
815
|
+
flush = "both";
|
|
816
|
+
ch++;
|
|
817
|
+
} else if (fmt[ch] === ">") {
|
|
818
|
+
flush = "left-steal";
|
|
819
|
+
ch++;
|
|
820
|
+
} else flush = "left";
|
|
821
|
+
} else return 0;
|
|
822
|
+
let toColumn = false;
|
|
823
|
+
if (fmt[ch] === "|") {
|
|
824
|
+
toColumn = true;
|
|
825
|
+
ch++;
|
|
826
|
+
}
|
|
827
|
+
if (fmt[ch] !== "(") return 0;
|
|
828
|
+
const start = ch + 1;
|
|
829
|
+
let end = start;
|
|
830
|
+
while (end < fmt.length && fmt[end] !== "," && fmt[end] !== ")") end++;
|
|
831
|
+
if (end >= fmt.length || end === start) return 0;
|
|
832
|
+
const num = /^[ \t\n\r]*[+-]?\d+/.exec(fmt.slice(start, end));
|
|
833
|
+
if (!num) return 0;
|
|
834
|
+
let width = Number.parseInt(num[0], 10);
|
|
835
|
+
if (width < -FORMATTING_LIMIT || width > FORMATTING_LIMIT || width === 0) return 0;
|
|
836
|
+
if (width < 0) {
|
|
837
|
+
// the terminal's width: 80 without a terminal
|
|
838
|
+
if (toColumn) width += 80;
|
|
839
|
+
if (width < 0) return 0;
|
|
840
|
+
}
|
|
841
|
+
let truncate: FormatState["truncate"] = "none";
|
|
842
|
+
let close = end;
|
|
843
|
+
if (fmt[end] === ",") {
|
|
844
|
+
const s = end + 1;
|
|
845
|
+
close = fmt.indexOf(")", s);
|
|
846
|
+
if (close < 0 || close === s) return 0;
|
|
847
|
+
const rest = fmt.slice(s);
|
|
848
|
+
if (rest.startsWith("trunc)")) truncate = "right";
|
|
849
|
+
else if (rest.startsWith("ltrunc)")) truncate = "left";
|
|
850
|
+
else if (rest.startsWith("mtrunc)")) truncate = "middle";
|
|
851
|
+
else return 0;
|
|
852
|
+
}
|
|
853
|
+
st.padding = toColumn ? -width : width;
|
|
854
|
+
st.flush = flush;
|
|
855
|
+
st.truncate = truncate;
|
|
856
|
+
return close - at + 1;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* pretty.c's match_placeholder_arg_value: `<name>` or `<name>=<value>` at `at`, followed by
|
|
861
|
+
* `,` (taken) or `)` (left); the value runs to the next `,` or `)`.
|
|
862
|
+
*/
|
|
863
|
+
function matchArgValue(
|
|
864
|
+
fmt: string,
|
|
865
|
+
at: number,
|
|
866
|
+
name: string,
|
|
867
|
+
): { value?: string; end: number } | undefined {
|
|
868
|
+
if (!fmt.startsWith(name, at)) return undefined;
|
|
869
|
+
let p = at + name.length;
|
|
870
|
+
let value: string | undefined;
|
|
871
|
+
if (fmt[p] === "=") {
|
|
872
|
+
let e = p + 1;
|
|
873
|
+
while (e < fmt.length && fmt[e] !== "," && fmt[e] !== ")") e++;
|
|
874
|
+
value = fmt.slice(p + 1, e);
|
|
875
|
+
p = e;
|
|
876
|
+
} else if (fmt[p] !== "," && fmt[p] !== ")") return undefined;
|
|
877
|
+
if (fmt[p] === ",") return { ...(value !== undefined ? { value } : {}), end: p + 1 };
|
|
878
|
+
if (fmt[p] === ")") return { ...(value !== undefined ? { value } : {}), end: p };
|
|
879
|
+
return undefined;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/** git_parse_maybe_bool: true/yes/on, false/no/off, "" (false), a number; else -1. */
|
|
883
|
+
function parseMaybeBool(value: string): boolean | undefined {
|
|
884
|
+
const v = value.toLowerCase();
|
|
885
|
+
if (v === "true" || v === "yes" || v === "on") return true;
|
|
886
|
+
if (v === "false" || v === "no" || v === "off" || v === "") return false;
|
|
887
|
+
const n = /^([+-]?\d+)([kmg]?)$/.exec(v);
|
|
888
|
+
if (n) return Number(n[1]) !== 0;
|
|
889
|
+
return undefined;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/** pretty.c's match_placeholder_bool_arg: `<name>` (true) or `<name>=<bool>`. */
|
|
893
|
+
function matchBoolArg(
|
|
894
|
+
fmt: string,
|
|
895
|
+
at: number,
|
|
896
|
+
name: string,
|
|
897
|
+
): { value: boolean; end: number } | undefined {
|
|
898
|
+
const arg = matchArgValue(fmt, at, name);
|
|
899
|
+
if (!arg) return undefined;
|
|
900
|
+
if (arg.value === undefined) return { value: true, end: arg.end };
|
|
901
|
+
const value = parseMaybeBool(arg.value);
|
|
902
|
+
return value === undefined ? undefined : { value, end: arg.end };
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/** The commit and what the format reads besides it. */
|
|
906
|
+
interface FormatContext {
|
|
907
|
+
commit: PrettyCommit;
|
|
908
|
+
id: ObjectId;
|
|
909
|
+
options: PrettyFormatOptions;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* pretty.c's format_commit_one: one placeholder at `fmt[at]` (after `%`) expanded at the end
|
|
914
|
+
* of `st.sb`; the characters it takes, 0 for one git does not know (or this does not
|
|
915
|
+
* support).
|
|
916
|
+
*/
|
|
917
|
+
async function formatOne(
|
|
918
|
+
fmt: string,
|
|
919
|
+
at: number,
|
|
920
|
+
st: FormatState,
|
|
921
|
+
cx: FormatContext,
|
|
922
|
+
): Promise<number> {
|
|
923
|
+
const { commit, id, options } = cx;
|
|
924
|
+
const literal = expandLiteral(fmt, at);
|
|
925
|
+
if (literal.taken > 0) {
|
|
926
|
+
st.sb += literal.text;
|
|
927
|
+
return literal.taken;
|
|
928
|
+
}
|
|
929
|
+
const c = fmt[at];
|
|
930
|
+
const abbrev = (oid: ObjectId) => (options.abbreviate ? options.abbreviate(oid) : oid);
|
|
931
|
+
switch (c) {
|
|
932
|
+
case "C": {
|
|
933
|
+
if (fmt.startsWith("(auto)", at + 1)) {
|
|
934
|
+
st.autoColor = !!options.color;
|
|
935
|
+
if (options.color && st.sb.length > 0) st.sb += "\x1b[m";
|
|
936
|
+
return 7;
|
|
937
|
+
}
|
|
938
|
+
if (fmt[at + 1] === "(") {
|
|
939
|
+
const end = fmt.indexOf(")", at + 2);
|
|
940
|
+
if (end < 0) return 0;
|
|
941
|
+
let spec = fmt.slice(at + 2, end);
|
|
942
|
+
let want = !!options.color;
|
|
943
|
+
if (spec.startsWith("auto,")) spec = spec.slice(5);
|
|
944
|
+
else if (spec.startsWith("always,")) {
|
|
945
|
+
spec = spec.slice(7);
|
|
946
|
+
want = true;
|
|
947
|
+
}
|
|
948
|
+
st.autoColor = false;
|
|
949
|
+
if (!want) return end - at + 1;
|
|
950
|
+
st.sb += parseColorSpec(spec);
|
|
951
|
+
return end - at + 1;
|
|
952
|
+
}
|
|
953
|
+
const basic: Record<string, string> = {
|
|
954
|
+
red: "\x1b[31m",
|
|
955
|
+
green: "\x1b[32m",
|
|
956
|
+
blue: "\x1b[34m",
|
|
957
|
+
reset: "\x1b[m",
|
|
958
|
+
};
|
|
959
|
+
for (const name of ["red", "green", "blue", "reset"]) {
|
|
960
|
+
if (fmt.startsWith(name, at + 1)) {
|
|
961
|
+
st.autoColor = false;
|
|
962
|
+
if (options.color) st.sb += basic[name];
|
|
963
|
+
return 1 + name.length;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
// %C<unknown> is a literal and the previous %C(auto) stays
|
|
967
|
+
return 0;
|
|
968
|
+
}
|
|
969
|
+
case "w": {
|
|
970
|
+
if (fmt[at + 1] !== "(") return 0;
|
|
971
|
+
const end = fmt.indexOf(")", at + 2);
|
|
972
|
+
if (end < 0) return 0;
|
|
973
|
+
const args = fmt.slice(at + 2, end);
|
|
974
|
+
let width = 0;
|
|
975
|
+
let indent1 = 0;
|
|
976
|
+
let indent2 = 0;
|
|
977
|
+
if (args !== "") {
|
|
978
|
+
const m = /^[ \t\n\r]*\+?(\d*)(?:,[ \t\n\r]*\+?(\d*)(?:,[ \t\n\r]*\+?(\d*))?)?$/.exec(args);
|
|
979
|
+
if (!m) return 0;
|
|
980
|
+
width = Number(m[1] || 0);
|
|
981
|
+
indent1 = Number(m[2] || 0);
|
|
982
|
+
indent2 = Number(m[3] || 0);
|
|
983
|
+
}
|
|
984
|
+
if (width > FORMATTING_LIMIT || indent1 > FORMATTING_LIMIT || indent2 > FORMATTING_LIMIT)
|
|
985
|
+
return 0;
|
|
986
|
+
rewrapTail(st, width, indent1, indent2);
|
|
987
|
+
return end - at + 1;
|
|
988
|
+
}
|
|
989
|
+
case "<":
|
|
990
|
+
case ">":
|
|
991
|
+
return parsePadding(fmt, at, st);
|
|
992
|
+
}
|
|
993
|
+
switch (c) {
|
|
994
|
+
case "H":
|
|
995
|
+
st.sb += id;
|
|
996
|
+
return 1;
|
|
997
|
+
case "h":
|
|
998
|
+
st.sb += await abbrev(id);
|
|
999
|
+
return 1;
|
|
1000
|
+
case "T":
|
|
1001
|
+
st.sb += commit.tree;
|
|
1002
|
+
return 1;
|
|
1003
|
+
case "t":
|
|
1004
|
+
st.sb += await abbrev(commit.tree);
|
|
1005
|
+
return 1;
|
|
1006
|
+
case "P":
|
|
1007
|
+
st.sb += commit.parents.join(" ");
|
|
1008
|
+
return 1;
|
|
1009
|
+
case "p": {
|
|
1010
|
+
const parts: string[] = [];
|
|
1011
|
+
for (const p of commit.parents) parts.push(await abbrev(p));
|
|
1012
|
+
st.sb += parts.join(" ");
|
|
1013
|
+
return 1;
|
|
1014
|
+
}
|
|
1015
|
+
case "m":
|
|
1016
|
+
st.sb += options.mark ?? ">";
|
|
1017
|
+
return 1;
|
|
1018
|
+
case "d":
|
|
1019
|
+
st.sb += formatRefDecorations(options.decorations, id, {});
|
|
1020
|
+
return 1;
|
|
1021
|
+
case "D":
|
|
1022
|
+
st.sb += formatRefDecorations(options.decorations, id, { prefix: "", suffix: "" });
|
|
1023
|
+
return 1;
|
|
1024
|
+
case "g": {
|
|
1025
|
+
const reflog = options.reflog;
|
|
1026
|
+
switch (fmt[at + 1]) {
|
|
1027
|
+
case "d":
|
|
1028
|
+
st.sb += reflog?.selector ?? "";
|
|
1029
|
+
return 2;
|
|
1030
|
+
case "D":
|
|
1031
|
+
st.sb += reflog?.selector ?? "";
|
|
1032
|
+
return 2;
|
|
1033
|
+
case "s":
|
|
1034
|
+
st.sb += reflog?.message ?? "";
|
|
1035
|
+
return 2;
|
|
1036
|
+
case "n":
|
|
1037
|
+
case "N":
|
|
1038
|
+
case "e":
|
|
1039
|
+
case "E": {
|
|
1040
|
+
if (!reflog?.ident) return 2;
|
|
1041
|
+
const part = formatPersonPart(reflog.ident, fmt[at + 1], options);
|
|
1042
|
+
if (part !== undefined) st.sb += part;
|
|
1043
|
+
return 2;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
return 0;
|
|
1047
|
+
}
|
|
1048
|
+
case "N":
|
|
1049
|
+
if (options.notes === undefined) return 0;
|
|
1050
|
+
st.sb += options.notes;
|
|
1051
|
+
return 1;
|
|
1052
|
+
case "G": {
|
|
1053
|
+
const signed = !!(commit as { gpgSignature?: string }).gpgSignature;
|
|
1054
|
+
switch (fmt[at + 1]) {
|
|
1055
|
+
case "?":
|
|
1056
|
+
st.sb += signed ? "E" : "N";
|
|
1057
|
+
return 2;
|
|
1058
|
+
case "G":
|
|
1059
|
+
case "S":
|
|
1060
|
+
case "K":
|
|
1061
|
+
case "F":
|
|
1062
|
+
case "P":
|
|
1063
|
+
return 2;
|
|
1064
|
+
case "T":
|
|
1065
|
+
st.sb += "undefined";
|
|
1066
|
+
return 2;
|
|
1067
|
+
}
|
|
1068
|
+
return 0;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (fmt.startsWith("(decorate", at)) {
|
|
1072
|
+
let i = at + 9;
|
|
1073
|
+
const opts: Record<string, string> = {};
|
|
1074
|
+
if (fmt[i] === ":") {
|
|
1075
|
+
i++;
|
|
1076
|
+
for (;;) {
|
|
1077
|
+
const m = /^(prefix|suffix|separator|pointer|tag)=/.exec(fmt.slice(i));
|
|
1078
|
+
if (!m) break;
|
|
1079
|
+
// match_placeholder_arg_value: the value runs to the next "," or ")"
|
|
1080
|
+
const valueStart = i + m[0].length;
|
|
1081
|
+
let valueEnd = valueStart;
|
|
1082
|
+
while (valueEnd < fmt.length && fmt[valueEnd] !== "," && fmt[valueEnd] !== ")") valueEnd++;
|
|
1083
|
+
if (valueEnd >= fmt.length) break;
|
|
1084
|
+
opts[m[1] as string] = expandStringArg(fmt.slice(valueStart, valueEnd));
|
|
1085
|
+
i = fmt[valueEnd] === "," ? valueEnd + 1 : valueEnd;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
if (fmt[i] !== ")") return 0;
|
|
1089
|
+
st.sb += formatRefDecorations(options.decorations, id, opts);
|
|
1090
|
+
return i - at + 1;
|
|
1091
|
+
}
|
|
1092
|
+
if (fmt.startsWith("(describe", at)) {
|
|
1093
|
+
let i = at + 9;
|
|
1094
|
+
const describeOptions: { tags?: boolean; abbrev?: number; match: string[]; exclude: string[] } =
|
|
1095
|
+
{ match: [], exclude: [] };
|
|
1096
|
+
if (fmt[i] === ":") {
|
|
1097
|
+
i++;
|
|
1098
|
+
// parse_describe_args: the options it knows, up to the first it does not
|
|
1099
|
+
for (;;) {
|
|
1100
|
+
const tagsArg = matchBoolArg(fmt, i, "tags");
|
|
1101
|
+
if (tagsArg) {
|
|
1102
|
+
describeOptions.tags = tagsArg.value;
|
|
1103
|
+
i = tagsArg.end;
|
|
1104
|
+
continue;
|
|
1105
|
+
}
|
|
1106
|
+
const abbrevArg = matchArgValue(fmt, i, "abbrev");
|
|
1107
|
+
if (abbrevArg) {
|
|
1108
|
+
if (abbrevArg.value === undefined || !/^[+-]?\d+$/.test(abbrevArg.value)) return 0;
|
|
1109
|
+
let n = Number.parseInt(abbrevArg.value, 10);
|
|
1110
|
+
// parse_opt_abbrev_cb: at least 4 (MINIMUM_ABBREV), at most the hash's length
|
|
1111
|
+
if (n && n < 4) n = 4;
|
|
1112
|
+
else if (n > 40) n = 40;
|
|
1113
|
+
describeOptions.abbrev = n;
|
|
1114
|
+
i = abbrevArg.end;
|
|
1115
|
+
continue;
|
|
1116
|
+
}
|
|
1117
|
+
const listArg = matchArgValue(fmt, i, "exclude") ?? matchArgValue(fmt, i, "match");
|
|
1118
|
+
if (listArg) {
|
|
1119
|
+
if (!listArg.value) return 0;
|
|
1120
|
+
(fmt.startsWith("exclude", i) ? describeOptions.exclude : describeOptions.match).push(
|
|
1121
|
+
listArg.value,
|
|
1122
|
+
);
|
|
1123
|
+
i = listArg.end;
|
|
1124
|
+
continue;
|
|
1125
|
+
}
|
|
1126
|
+
break;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
if (fmt[i] !== ")" || !options.describe) return 0;
|
|
1130
|
+
const out = await options.describe(id, {
|
|
1131
|
+
...(describeOptions.tags !== undefined ? { tags: describeOptions.tags } : {}),
|
|
1132
|
+
...(describeOptions.abbrev !== undefined ? { abbrev: describeOptions.abbrev } : {}),
|
|
1133
|
+
...(describeOptions.match.length ? { match: describeOptions.match } : {}),
|
|
1134
|
+
...(describeOptions.exclude.length ? { exclude: describeOptions.exclude } : {}),
|
|
1135
|
+
});
|
|
1136
|
+
st.sb += out.replace(/[ \t\n\r]+$/, "");
|
|
1137
|
+
return i - at + 1;
|
|
1138
|
+
}
|
|
1139
|
+
if (fmt.startsWith("(count)", at) || fmt.startsWith("(total)", at)) {
|
|
1140
|
+
const name = fmt.slice(at, at + 7);
|
|
1141
|
+
if (!options.count)
|
|
1142
|
+
throw new PrettyFormatError(`fatal: %${name} is not supported by this command`);
|
|
1143
|
+
const { nr, total } = options.count;
|
|
1144
|
+
st.sb +=
|
|
1145
|
+
name === "(count)" ? String(nr).padStart(String(Math.abs(total)).length, "0") : String(total);
|
|
1146
|
+
return 7;
|
|
1147
|
+
}
|
|
1148
|
+
if (c === "S") {
|
|
1149
|
+
if (options.source === undefined || options.source === "") return 0;
|
|
1150
|
+
st.sb += options.source;
|
|
1151
|
+
return 1;
|
|
1152
|
+
}
|
|
1153
|
+
if (fmt.startsWith("(trailers", at)) {
|
|
1154
|
+
let i = at + 9;
|
|
1155
|
+
const trailerOptions: TrailerFormatOptions & { keys?: string[] } = {};
|
|
1156
|
+
if (fmt[i] === ":") {
|
|
1157
|
+
i++;
|
|
1158
|
+
// format_set_trailers_options
|
|
1159
|
+
for (;;) {
|
|
1160
|
+
if (fmt[i] === ")") break;
|
|
1161
|
+
const key = matchArgValue(fmt, i, "key");
|
|
1162
|
+
if (key) {
|
|
1163
|
+
if (key.value === undefined) return 0;
|
|
1164
|
+
trailerOptions.keys = [...(trailerOptions.keys ?? []), key.value];
|
|
1165
|
+
trailerOptions.onlyTrailers = true;
|
|
1166
|
+
i = key.end;
|
|
1167
|
+
continue;
|
|
1168
|
+
}
|
|
1169
|
+
const separator = matchArgValue(fmt, i, "separator");
|
|
1170
|
+
if (separator) {
|
|
1171
|
+
trailerOptions.separator = expandStringArg(separator.value ?? "");
|
|
1172
|
+
i = separator.end;
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
const kvSeparator = matchArgValue(fmt, i, "key_value_separator");
|
|
1176
|
+
if (kvSeparator) {
|
|
1177
|
+
trailerOptions.keyValueSeparator = expandStringArg(kvSeparator.value ?? "");
|
|
1178
|
+
i = kvSeparator.end;
|
|
1179
|
+
continue;
|
|
1180
|
+
}
|
|
1181
|
+
const flag = (
|
|
1182
|
+
[
|
|
1183
|
+
["only", "onlyTrailers"],
|
|
1184
|
+
["unfold", "unfold"],
|
|
1185
|
+
["keyonly", "keyOnly"],
|
|
1186
|
+
["valueonly", "valueOnly"],
|
|
1187
|
+
] as const
|
|
1188
|
+
).find(([name]) => matchBoolArg(fmt, i, name));
|
|
1189
|
+
if (!flag) return 0;
|
|
1190
|
+
const arg = matchBoolArg(fmt, i, flag[0]) as { value: boolean; end: number };
|
|
1191
|
+
trailerOptions[flag[1]] = arg.value;
|
|
1192
|
+
i = arg.end;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
if (fmt[i] !== ")") return 0;
|
|
1196
|
+
const start = skipBlankLines(commit.message, 0);
|
|
1197
|
+
st.sb = appendTrailers(st.sb, commit.message.slice(start), trailerOptions, options.trailers);
|
|
1198
|
+
return i - at + 1;
|
|
1199
|
+
}
|
|
1200
|
+
switch (c) {
|
|
1201
|
+
case "a":
|
|
1202
|
+
case "c": {
|
|
1203
|
+
const ident = c === "a" ? commit.author : commit.committer;
|
|
1204
|
+
const part = formatPersonPart(ident, fmt[at + 1], options);
|
|
1205
|
+
if (part === undefined) return 0;
|
|
1206
|
+
st.sb += part;
|
|
1207
|
+
return 2;
|
|
1208
|
+
}
|
|
1209
|
+
case "e":
|
|
1210
|
+
st.sb += commit.encoding ?? "";
|
|
1211
|
+
return 1;
|
|
1212
|
+
case "B":
|
|
1213
|
+
st.sb += commit.message;
|
|
1214
|
+
return 1;
|
|
1215
|
+
case "s": {
|
|
1216
|
+
const start = skipBlankLines(commit.message, 0);
|
|
1217
|
+
st.sb += formatSubject(commit.message, start, " ").text;
|
|
1218
|
+
return 1;
|
|
1219
|
+
}
|
|
1220
|
+
case "f": {
|
|
1221
|
+
const start = skipBlankLines(commit.message, 0);
|
|
1222
|
+
const nl = commit.message.indexOf("\n", start);
|
|
1223
|
+
const line = commit.message.slice(start, nl < 0 ? commit.message.length : nl);
|
|
1224
|
+
st.sb += sanitizedSubject(line);
|
|
1225
|
+
return 1;
|
|
1226
|
+
}
|
|
1227
|
+
case "b": {
|
|
1228
|
+
const start = skipBlankLines(commit.message, 0);
|
|
1229
|
+
const { end } = formatSubject(commit.message, start, " ");
|
|
1230
|
+
st.sb += commit.message.slice(skipBlankLines(commit.message, end));
|
|
1231
|
+
return 1;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
return 0;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/** pretty.c's format_and_pad_commit: the next placeholder, padded or truncated. */
|
|
1238
|
+
async function formatAndPad(
|
|
1239
|
+
fmt: string,
|
|
1240
|
+
at: number,
|
|
1241
|
+
st: FormatState,
|
|
1242
|
+
cx: FormatContext,
|
|
1243
|
+
): Promise<number> {
|
|
1244
|
+
let padding = st.padding;
|
|
1245
|
+
if (padding < 0) {
|
|
1246
|
+
const nl = st.sb.lastIndexOf("\n");
|
|
1247
|
+
const occupied = displayWidth(nl < 0 ? st.sb : st.sb.slice(nl));
|
|
1248
|
+
padding = -padding - occupied;
|
|
1249
|
+
}
|
|
1250
|
+
const outer = st.sb;
|
|
1251
|
+
st.sb = "";
|
|
1252
|
+
const flushType = st.flush;
|
|
1253
|
+
const truncate = st.truncate;
|
|
1254
|
+
st.flush = "none";
|
|
1255
|
+
let total = 0;
|
|
1256
|
+
let p = at;
|
|
1257
|
+
for (;;) {
|
|
1258
|
+
const modifier = fmt[p] === "C";
|
|
1259
|
+
const consumed = await formatOne(fmt, p, st, cx);
|
|
1260
|
+
total += consumed;
|
|
1261
|
+
if (!modifier) break;
|
|
1262
|
+
p += consumed;
|
|
1263
|
+
if (fmt[p] !== "%") break;
|
|
1264
|
+
p++;
|
|
1265
|
+
total++;
|
|
1266
|
+
}
|
|
1267
|
+
let local = st.sb;
|
|
1268
|
+
let sb = outer;
|
|
1269
|
+
const len = displayWidth(local);
|
|
1270
|
+
let flush = flushType;
|
|
1271
|
+
if (flush === "left-steal") {
|
|
1272
|
+
// take the spaces (and keep the colors) at the end of what is already written
|
|
1273
|
+
let ch = sb.length - 1;
|
|
1274
|
+
while (len > padding && ch > 0) {
|
|
1275
|
+
if (sb[ch] === " ") {
|
|
1276
|
+
ch--;
|
|
1277
|
+
padding++;
|
|
1278
|
+
continue;
|
|
1279
|
+
}
|
|
1280
|
+
if (sb[ch] !== "m") break;
|
|
1281
|
+
let q = ch - 1;
|
|
1282
|
+
while (q > 0 && ch - q < 10 && sb[q] !== "\x1b") q--;
|
|
1283
|
+
if (sb[q] !== "\x1b" || ch + 1 - q !== escapeLength(sb, q)) break;
|
|
1284
|
+
local = sb.slice(q, ch + 1) + local;
|
|
1285
|
+
ch = q - 1;
|
|
1286
|
+
}
|
|
1287
|
+
sb = sb.slice(0, ch + 1);
|
|
1288
|
+
flush = "left";
|
|
1289
|
+
}
|
|
1290
|
+
if (len > padding) {
|
|
1291
|
+
switch (truncate) {
|
|
1292
|
+
case "left":
|
|
1293
|
+
local = utf8Replace(local, 0, len - (padding - 2), "..");
|
|
1294
|
+
break;
|
|
1295
|
+
case "middle":
|
|
1296
|
+
local = utf8Replace(local, Math.trunc(padding / 2) - 1, len - (padding - 2), "..");
|
|
1297
|
+
break;
|
|
1298
|
+
case "right":
|
|
1299
|
+
local = utf8Replace(local, padding - 2, len - (padding - 2), "..");
|
|
1300
|
+
break;
|
|
1301
|
+
}
|
|
1302
|
+
sb += local;
|
|
1303
|
+
} else {
|
|
1304
|
+
let offset = 0;
|
|
1305
|
+
if (flush === "left") offset = padding - len;
|
|
1306
|
+
else if (flush === "both") offset = Math.trunc((padding - len) / 2);
|
|
1307
|
+
sb += " ".repeat(offset) + local + " ".repeat(padding - len - offset);
|
|
1308
|
+
}
|
|
1309
|
+
st.sb = sb;
|
|
1310
|
+
return total;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
/** pretty.c's format_person_part; undefined for a part it does not know. */
|
|
1314
|
+
function formatPersonPart(
|
|
1315
|
+
ident: PersonIdent,
|
|
1316
|
+
part: string | undefined,
|
|
1317
|
+
options: PrettyFormatOptions,
|
|
1318
|
+
): string | undefined {
|
|
1319
|
+
let { name, email } = ident;
|
|
1320
|
+
if ((part === "N" || part === "E" || part === "L") && options.mailmap) {
|
|
1321
|
+
({ name, email } = options.mailmap(name, email));
|
|
1322
|
+
}
|
|
1323
|
+
switch (part) {
|
|
1324
|
+
case "n":
|
|
1325
|
+
case "N":
|
|
1326
|
+
return name;
|
|
1327
|
+
case "e":
|
|
1328
|
+
case "E":
|
|
1329
|
+
return email;
|
|
1330
|
+
case "l":
|
|
1331
|
+
case "L": {
|
|
1332
|
+
const at = email.indexOf("@");
|
|
1333
|
+
return at < 0 ? email : email.slice(0, at);
|
|
1334
|
+
}
|
|
1335
|
+
case "t":
|
|
1336
|
+
return String(ident.timestamp);
|
|
1337
|
+
case "d":
|
|
1338
|
+
return options.formatDate ? options.formatDate(ident) : formatGitDate(ident);
|
|
1339
|
+
case "D":
|
|
1340
|
+
return formatRfc2822Date(ident.timestamp, zoned(ident).tz);
|
|
1341
|
+
case "r":
|
|
1342
|
+
return relativeDate(ident.timestamp, options.now ?? Math.floor(Date.now() / 1000));
|
|
1343
|
+
case "i":
|
|
1344
|
+
return isoDate(ident);
|
|
1345
|
+
case "I":
|
|
1346
|
+
return strictIsoDate(ident);
|
|
1347
|
+
case "s":
|
|
1348
|
+
return shortDate(ident);
|
|
1349
|
+
case "h":
|
|
1350
|
+
return humanDate(
|
|
1351
|
+
ident,
|
|
1352
|
+
options.now ?? Math.floor(Date.now() / 1000),
|
|
1353
|
+
options.localTzOffset ?? ((time) => -new Date(time * 1000).getTimezoneOffset()),
|
|
1354
|
+
);
|
|
1355
|
+
default:
|
|
1356
|
+
return undefined;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* `format` expanded for commit `id` as git's format_commit_message expands a user format:
|
|
1362
|
+
* each `%<placeholder>`, with the `%+` (a newline before a non-empty expansion), `%-` (the
|
|
1363
|
+
* newlines before an empty one removed) and `% ` (a space before a non-empty one) magic,
|
|
1364
|
+
* the padding a `%<(…)` gives the next placeholder, and the wrapping of `%w(…)`.
|
|
1365
|
+
*/
|
|
1366
|
+
export async function formatCommitPretty(
|
|
1367
|
+
format: string,
|
|
1368
|
+
commit: PrettyCommit,
|
|
1369
|
+
id: ObjectId,
|
|
1370
|
+
options: PrettyFormatOptions = {},
|
|
1371
|
+
): Promise<string> {
|
|
1372
|
+
const st: FormatState = {
|
|
1373
|
+
sb: "",
|
|
1374
|
+
wrapStart: 0,
|
|
1375
|
+
width: 0,
|
|
1376
|
+
indent1: 0,
|
|
1377
|
+
indent2: 0,
|
|
1378
|
+
flush: "none",
|
|
1379
|
+
padding: 0,
|
|
1380
|
+
truncate: "none",
|
|
1381
|
+
autoColor: false,
|
|
1382
|
+
};
|
|
1383
|
+
const cx: FormatContext = { commit, id, options };
|
|
1384
|
+
let i = 0;
|
|
1385
|
+
while (i < format.length) {
|
|
1386
|
+
const pct = format.indexOf("%", i);
|
|
1387
|
+
if (pct < 0) {
|
|
1388
|
+
st.sb += format.slice(i);
|
|
1389
|
+
break;
|
|
1390
|
+
}
|
|
1391
|
+
st.sb += format.slice(i, pct);
|
|
1392
|
+
i = pct + 1;
|
|
1393
|
+
if (format[i] === "%") {
|
|
1394
|
+
st.sb += "%";
|
|
1395
|
+
i++;
|
|
1396
|
+
continue;
|
|
1397
|
+
}
|
|
1398
|
+
const consumed = await formatItem(format, i, st, cx);
|
|
1399
|
+
if (consumed === 0) st.sb += "%";
|
|
1400
|
+
else i += consumed;
|
|
1401
|
+
}
|
|
1402
|
+
rewrapTail(st, 0, 0, 0);
|
|
1403
|
+
return st.sb;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
/** pretty.c's format_commit_item: the magic, then the placeholder (padded when asked). */
|
|
1407
|
+
async function formatItem(
|
|
1408
|
+
fmt: string,
|
|
1409
|
+
at: number,
|
|
1410
|
+
st: FormatState,
|
|
1411
|
+
cx: FormatContext,
|
|
1412
|
+
): Promise<number> {
|
|
1413
|
+
const first = fmt[at];
|
|
1414
|
+
const magic = first === "-" || first === "+" || first === " " ? first : "";
|
|
1415
|
+
let p = at;
|
|
1416
|
+
if (magic) {
|
|
1417
|
+
p++;
|
|
1418
|
+
// `%+w()` cannot be handled: refused, kept as written
|
|
1419
|
+
if (fmt[p] === "w") return 0;
|
|
1420
|
+
}
|
|
1421
|
+
const before = st.sb.length;
|
|
1422
|
+
const consumed =
|
|
1423
|
+
st.flush === "none" ? await formatOne(fmt, p, st, cx) : await formatAndPad(fmt, p, st, cx);
|
|
1424
|
+
if (!magic) return consumed;
|
|
1425
|
+
if (st.sb.length === before && magic === "-") st.sb = st.sb.replace(/\n+$/, "");
|
|
1426
|
+
else if (st.sb.length !== before) {
|
|
1427
|
+
if (magic === "+") st.sb = `${st.sb.slice(0, before)}\n${st.sb.slice(before)}`;
|
|
1428
|
+
else if (magic === " ") st.sb = `${st.sb.slice(0, before)} ${st.sb.slice(before)}`;
|
|
1429
|
+
}
|
|
1430
|
+
return consumed + 1;
|
|
1431
|
+
}
|