@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,1199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's pathspecs: parsing (pathspec.c), matching a path (dir.c `match_pathspec_item`, for the
|
|
3
|
+
* worktree scans) and matching tree entries (tree-walk.c `tree_entry_interesting`, for the
|
|
4
|
+
* pruned tree diffs of `git log -- <pathspec>`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
decodeGitPath,
|
|
9
|
+
encodeGitPath,
|
|
10
|
+
foldAsciiCase,
|
|
11
|
+
unquoteGitPath,
|
|
12
|
+
} from "@statewalker/vcs-utils/encoding";
|
|
13
|
+
import { wildmatch, wildmatchBytes } from "@statewalker/vcs-working-tree";
|
|
14
|
+
|
|
15
|
+
export const MATCHED_RECURSIVELY = 1;
|
|
16
|
+
export const MATCHED_RECURSIVELY_LEADING_PATHSPEC = 2;
|
|
17
|
+
export const MATCHED_FNMATCH = 3;
|
|
18
|
+
export const MATCHED_EXACTLY = 4;
|
|
19
|
+
export const DO_MATCH_DIRECTORY = 1;
|
|
20
|
+
export const DO_MATCH_LEADING_PATHSPEC = 2;
|
|
21
|
+
export const DO_MATCH_EXCLUDE = 4;
|
|
22
|
+
|
|
23
|
+
/** One pathspec element as git's `init_pathspec_item` parses it. */
|
|
24
|
+
export interface PathspecItem {
|
|
25
|
+
/** The path from the top of the worktree (normalised), without its magic */
|
|
26
|
+
match: string;
|
|
27
|
+
/** The length of its leading literal part (git's `nowildcard_len`) */
|
|
28
|
+
nowildcardLen: number;
|
|
29
|
+
/** `*` followed by no other wildcard after the literal prefix (git's ONESTAR) */
|
|
30
|
+
oneStar: boolean;
|
|
31
|
+
/** `:(exclude)` / `:!` / `:^`: a path it matches is left out */
|
|
32
|
+
exclude: boolean;
|
|
33
|
+
/** `:(glob)`: wildmatch with WM_PATHNAME (`*` stops at `/`, `**` spans directories) */
|
|
34
|
+
glob: boolean;
|
|
35
|
+
/** `:(icase)`: case-insensitive */
|
|
36
|
+
icase: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* `match` holds the path's bytes, one character each ({@link pathspecItemBytes}, as
|
|
39
|
+
* `parsePathspec` and {@link treePathspec} hold every element); its lengths count bytes,
|
|
40
|
+
* and names are matched as their bytes ({@link pathspecName})
|
|
41
|
+
*/
|
|
42
|
+
bytes?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* `:(prefix:N)`: the first N bytes of the path are a literal prefix (git's `item->prefix`,
|
|
45
|
+
* set when a pathspec is handed to another command); `match` is then taken as written,
|
|
46
|
+
* not normalised, and held as bytes (`bytes`), so N may end inside a character as in git.
|
|
47
|
+
*/
|
|
48
|
+
prefix?: number;
|
|
49
|
+
/** `:(attr:...)`: the attributes a matching path must have (only where a caller allows it) */
|
|
50
|
+
attr?: AttrMatch[];
|
|
51
|
+
/**
|
|
52
|
+
* The attributes of a path for {@link attr} (git's `git_check_attr` through the command's
|
|
53
|
+
* index): undefined when they were not loaded ({@link PathspecAttributes} loads them
|
|
54
|
+
* before the paths are matched)
|
|
55
|
+
*/
|
|
56
|
+
attrLookup?: (path: string) => ReadonlyMap<string, PathspecAttributeValue> | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** One requirement of `:(attr:<spec>)` (git's `struct attr_match`). */
|
|
60
|
+
export interface AttrMatch {
|
|
61
|
+
name: string;
|
|
62
|
+
/** `name`: set; `-name`: unset; `!name`: unspecified; `name=value`: that value */
|
|
63
|
+
mode: "set" | "unset" | "unspecified" | "value";
|
|
64
|
+
value?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What {@link parsePathspecItem} accepts besides git's plain magic. */
|
|
68
|
+
export interface PathspecParseOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Accept `:(attr:...)` (git's PATHSPEC_ATTR, for commands that match attributes); without
|
|
71
|
+
* it the magic is refused as unsupported.
|
|
72
|
+
*/
|
|
73
|
+
attr?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The global magic of `GIT_LITERAL_PATHSPECS`, `GIT_GLOB_PATHSPECS`,
|
|
76
|
+
* `GIT_NOGLOB_PATHSPECS` and `GIT_ICASE_PATHSPECS` (git's `get_global_magic`), as
|
|
77
|
+
* {@link globalPathspecMagic} reads them
|
|
78
|
+
*/
|
|
79
|
+
global?: GlobalPathspecMagic;
|
|
80
|
+
/**
|
|
81
|
+
* Kept for compatibility: `:(attr:...)` without {@link attr} is always refused with git's
|
|
82
|
+
* `unsupported_magic` message, "<elem>: pathspec magic not supported by this command:
|
|
83
|
+
* 'attr'" (`pathspec.c`)
|
|
84
|
+
*
|
|
85
|
+
* @deprecated
|
|
86
|
+
*/
|
|
87
|
+
refuseAttrAsUnsupported?: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The pathspec settings of git's environment (`get_global_magic`), each on or off. */
|
|
91
|
+
export interface GlobalPathspecMagic {
|
|
92
|
+
/** `GIT_LITERAL_PATHSPECS`: no magic at all, every element literal */
|
|
93
|
+
literal?: boolean;
|
|
94
|
+
/** `GIT_GLOB_PATHSPECS`: every element `:(glob)` unless `:(literal)` */
|
|
95
|
+
glob?: boolean;
|
|
96
|
+
/** `GIT_NOGLOB_PATHSPECS`: every element `:(literal)` unless `:(glob)` */
|
|
97
|
+
noglob?: boolean;
|
|
98
|
+
/** `GIT_ICASE_PATHSPECS`: every element `:(icase)` */
|
|
99
|
+
icase?: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* git's `git_env_bool` of one variable (`git_config_bool`: a boolean word, else a number,
|
|
104
|
+
* non-zero being true); a value that is neither fails as git dies.
|
|
105
|
+
*/
|
|
106
|
+
function envBool(name: string, value: string | undefined): boolean {
|
|
107
|
+
if (value === undefined) return false;
|
|
108
|
+
const v = value.toLowerCase();
|
|
109
|
+
if (v === "" || v === "false" || v === "no" || v === "off") return false;
|
|
110
|
+
if (v === "true" || v === "yes" || v === "on") return true;
|
|
111
|
+
const m = /^\s*([-+]?\d+)([kmg]?)$/i.exec(value);
|
|
112
|
+
if (!m) throw new Error(`bad numeric config value '${value}' for '${name}': invalid unit`);
|
|
113
|
+
return Number(m[1]) !== 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The global pathspec magic from the variables as set (a `GitHostEnvironment`'s
|
|
118
|
+
* `pathspecs`), checked as git's `get_global_magic` checks them: `glob` with `noglob`, and
|
|
119
|
+
* `literal` with `glob` or `icase`, fail.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* globalPathspecMagic({ icase: "1" }); // { icase: true }
|
|
124
|
+
* globalPathspecMagic({ glob: "1", noglob: "1" }); // throws
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export function globalPathspecMagic(
|
|
128
|
+
vars: { literal?: string; glob?: string; noglob?: string; icase?: string } | undefined,
|
|
129
|
+
): GlobalPathspecMagic {
|
|
130
|
+
if (!vars) return {};
|
|
131
|
+
const literal = envBool("GIT_LITERAL_PATHSPECS", vars.literal);
|
|
132
|
+
const glob = envBool("GIT_GLOB_PATHSPECS", vars.glob);
|
|
133
|
+
const noglob = envBool("GIT_NOGLOB_PATHSPECS", vars.noglob);
|
|
134
|
+
const icase = envBool("GIT_ICASE_PATHSPECS", vars.icase);
|
|
135
|
+
if (glob && noglob) {
|
|
136
|
+
throw new Error("global 'glob' and 'noglob' pathspec settings are incompatible");
|
|
137
|
+
}
|
|
138
|
+
if (literal && (glob || icase)) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
"global 'literal' pathspec setting is incompatible with all other global pathspec settings",
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
...(literal ? { literal } : {}),
|
|
145
|
+
...(glob ? { glob } : {}),
|
|
146
|
+
...(noglob ? { noglob } : {}),
|
|
147
|
+
...(icase ? { icase } : {}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** git's `strcspn_escaped`: characters from `from` up to one of `stop`, backslash escapes skipped. */
|
|
152
|
+
function strcspnEscaped(s: string, from: number, stop: string): number {
|
|
153
|
+
let i = from;
|
|
154
|
+
for (; i < s.length; i++) {
|
|
155
|
+
if (s[i] === "\\" && i + 1 < s.length) {
|
|
156
|
+
i++;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (stop.includes(s[i] as string)) break;
|
|
160
|
+
}
|
|
161
|
+
return i - from;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** git's `attr_name_valid`: [-._0-9A-Za-z], not starting with "-". */
|
|
165
|
+
const validAttrName = (name: string) => /^[A-Za-z0-9._][-A-Za-z0-9._]*$/.test(name);
|
|
166
|
+
|
|
167
|
+
/** git's `parse_pathspec_attr_match` of the body of `attr:` (one element's). */
|
|
168
|
+
function parseAttrSpec(body: string, elem: string): AttrMatch[] {
|
|
169
|
+
if (body === "") throw new Error("attr spec must not be empty");
|
|
170
|
+
const out: AttrMatch[] = [];
|
|
171
|
+
for (const word of body.split(" ")) {
|
|
172
|
+
if (word === "") continue;
|
|
173
|
+
let match: AttrMatch;
|
|
174
|
+
if (word.startsWith("!")) match = { name: word.slice(1), mode: "unspecified" };
|
|
175
|
+
else if (word.startsWith("-")) match = { name: word.slice(1), mode: "unset" };
|
|
176
|
+
else {
|
|
177
|
+
const eq = word.indexOf("=");
|
|
178
|
+
if (eq < 0) match = { name: word, mode: "set" };
|
|
179
|
+
else
|
|
180
|
+
match = {
|
|
181
|
+
name: word.slice(0, eq),
|
|
182
|
+
mode: "value",
|
|
183
|
+
value: unescapeAttrValue(word.slice(eq + 1)),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
if (!validAttrName(match.name)) throw new Error(`invalid attribute name ${match.name}`);
|
|
187
|
+
out.push(match);
|
|
188
|
+
}
|
|
189
|
+
if (out.length === 0) throw new Error(`attr spec must not be empty in '${elem}'`);
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** git's `attr_value_unescape`: backslashes removed; only [A-Za-z0-9,-_] may be matched. */
|
|
194
|
+
function unescapeAttrValue(value: string): string {
|
|
195
|
+
let out = "";
|
|
196
|
+
for (let i = 0; i < value.length; i++) {
|
|
197
|
+
let ch = value[i] as string;
|
|
198
|
+
if (ch === "\\") {
|
|
199
|
+
if (i + 1 >= value.length)
|
|
200
|
+
throw new Error("Escape character '\\' not allowed as last character in attr value");
|
|
201
|
+
ch = value[++i] as string;
|
|
202
|
+
}
|
|
203
|
+
if (!/[A-Za-z0-9,\-_]/.test(ch)) throw new Error(`cannot use '${ch}' for value matching`);
|
|
204
|
+
out += ch;
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** git's characters that may introduce short pathspec magic (`GIT_PATHSPEC_MAGIC`). */
|
|
210
|
+
const SHORT_MAGIC_CHARS = new Set([..."!\"#%&',-;<=>@_`~^/"]);
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The pathspec elements as git's `parse_pathspec` reads them from the top of the worktree:
|
|
214
|
+
* short magic (`:/` top, `:!` and `:^` exclude) and long magic (`:(top,literal,glob,icase,
|
|
215
|
+
* exclude)`), the path normalised as `prefix_path` does (`.`, `..`, repeated slashes; above
|
|
216
|
+
* the top refused), and an implicit `.` when every element excludes.
|
|
217
|
+
*/
|
|
218
|
+
export function parsePathspec(paths: string[], options: PathspecParseOptions = {}): PathspecItem[] {
|
|
219
|
+
const items = paths.map((p) => parsePathspecItem(p, options));
|
|
220
|
+
if (items.length > 0 && items.every((i) => i.exclude)) {
|
|
221
|
+
// init_pathspec_item(item + n, 0, ...): the global magic applies to it too
|
|
222
|
+
items.push(parsePathspecItem(".", { global: options.global }));
|
|
223
|
+
}
|
|
224
|
+
// held as bytes: git matches names byte by byte, so an element may cut a character
|
|
225
|
+
return items.map(pathspecItemBytes);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The element with its path as bytes, one character each (`bytes`): its lengths then count
|
|
230
|
+
* bytes, as git's do, and it matches names as their bytes ({@link pathspecName}).
|
|
231
|
+
*/
|
|
232
|
+
export function pathspecItemBytes(item: PathspecItem): PathspecItem {
|
|
233
|
+
if (item.bytes) return item;
|
|
234
|
+
return {
|
|
235
|
+
...item,
|
|
236
|
+
match: byteString(item.match),
|
|
237
|
+
nowildcardLen: byteString(item.match.slice(0, item.nowildcardLen)).length,
|
|
238
|
+
bytes: true,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function parsePathspecItem(elem: string, options: PathspecParseOptions = {}): PathspecItem {
|
|
243
|
+
if (elem === "") {
|
|
244
|
+
// git's parse_pathspec
|
|
245
|
+
throw new Error(
|
|
246
|
+
"empty string is not a valid pathspec. please use . instead if you meant to match all paths",
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
let exclude = false;
|
|
250
|
+
let literal = false;
|
|
251
|
+
let glob = false;
|
|
252
|
+
let icase = false;
|
|
253
|
+
let prefix = -1;
|
|
254
|
+
let attr: AttrMatch[] | undefined;
|
|
255
|
+
let rest = elem;
|
|
256
|
+
const global = options.global ?? {};
|
|
257
|
+
// git's unsupported_magic
|
|
258
|
+
const refuseAttr = () =>
|
|
259
|
+
new Error(`${elem}: pathspec magic not supported by this command: 'attr'`);
|
|
260
|
+
if (global.literal) {
|
|
261
|
+
// parse_element_magic: no magic is read under GIT_LITERAL_PATHSPECS
|
|
262
|
+
literal = true;
|
|
263
|
+
} else if (elem.startsWith(":(")) {
|
|
264
|
+
// git's parse_long_magic: words up to "," or ")", backslash escapes skipped (attr values)
|
|
265
|
+
let pos = 2;
|
|
266
|
+
while (pos < elem.length && elem[pos] !== ")") {
|
|
267
|
+
const len = strcspnEscaped(elem, pos, ",)");
|
|
268
|
+
const next = elem[pos + len] === "," ? pos + len + 1 : pos + len;
|
|
269
|
+
const word = elem.slice(pos, pos + len);
|
|
270
|
+
pos = next;
|
|
271
|
+
if (word.startsWith("prefix:")) {
|
|
272
|
+
prefix = parsePrefixMagic(word.slice(7));
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (word.startsWith("attr:")) {
|
|
276
|
+
if (!options.attr) throw refuseAttr();
|
|
277
|
+
if (attr) throw new Error("Only one 'attr:' specification is allowed.");
|
|
278
|
+
attr = parseAttrSpec(word.slice(5), elem);
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const name = word.trim();
|
|
282
|
+
if (name === "" || name === "top") continue;
|
|
283
|
+
if (name === "literal") literal = true;
|
|
284
|
+
else if (name === "glob") glob = true;
|
|
285
|
+
else if (name === "icase") icase = true;
|
|
286
|
+
else if (name === "exclude") exclude = true;
|
|
287
|
+
else if (name === "attr") {
|
|
288
|
+
// the magic without a spec: nothing to match
|
|
289
|
+
if (!options.attr) throw refuseAttr();
|
|
290
|
+
} else throw new Error(`Invalid pathspec magic '${name}' in '${elem}'`);
|
|
291
|
+
}
|
|
292
|
+
if (elem[pos] !== ")") throw new Error(`Missing ')' at the end of pathspec magic in '${elem}'`);
|
|
293
|
+
rest = elem.slice(pos + 1);
|
|
294
|
+
} else if (elem.startsWith(":")) {
|
|
295
|
+
let pos = 1;
|
|
296
|
+
for (; pos < elem.length && elem[pos] !== ":"; pos++) {
|
|
297
|
+
const ch = elem[pos];
|
|
298
|
+
if (ch === "!" || ch === "^") exclude = true;
|
|
299
|
+
else if (ch === "/") {
|
|
300
|
+
// top: the paths are from the top already
|
|
301
|
+
} else if (!SHORT_MAGIC_CHARS.has(ch)) break;
|
|
302
|
+
else throw new Error(`Unimplemented pathspec magic '${ch}' in '${elem}'`);
|
|
303
|
+
}
|
|
304
|
+
if (elem[pos] === ":") pos++;
|
|
305
|
+
rest = elem.slice(pos);
|
|
306
|
+
}
|
|
307
|
+
// get_global_magic: glob unless the element is literal, noglob literal unless it is glob
|
|
308
|
+
if (!global.literal) {
|
|
309
|
+
const elementLiteral = literal;
|
|
310
|
+
const elementGlob = glob;
|
|
311
|
+
if (global.glob && !elementLiteral) glob = true;
|
|
312
|
+
if (global.icase) icase = true;
|
|
313
|
+
if (global.noglob && !elementGlob) literal = true;
|
|
314
|
+
}
|
|
315
|
+
if (literal && glob) throw new Error(`${elem}: 'literal' and 'glob' are incompatible`);
|
|
316
|
+
// with prefix magic the path is taken as written (git's init_pathspec_item), and its
|
|
317
|
+
// lengths are bytes: the prefix may end inside a character
|
|
318
|
+
const match = prefix >= 0 ? byteString(rest) : normalizePathspecPath(rest, elem);
|
|
319
|
+
if (prefix > match.length) throw new Error(`error initializing pathspec_item '${elem}'`);
|
|
320
|
+
let nowildcardLen = match.length;
|
|
321
|
+
if (!literal) {
|
|
322
|
+
nowildcardLen = 0;
|
|
323
|
+
while (nowildcardLen < match.length && !isGlobSpecial(match[nowildcardLen])) nowildcardLen++;
|
|
324
|
+
if (nowildcardLen < prefix) nowildcardLen = prefix;
|
|
325
|
+
}
|
|
326
|
+
const after = match.slice(nowildcardLen + 1);
|
|
327
|
+
const oneStar =
|
|
328
|
+
!glob &&
|
|
329
|
+
nowildcardLen < match.length &&
|
|
330
|
+
match[nowildcardLen] === "*" &&
|
|
331
|
+
![...after].some((c) => isGlobSpecial(c));
|
|
332
|
+
return {
|
|
333
|
+
match,
|
|
334
|
+
nowildcardLen,
|
|
335
|
+
oneStar,
|
|
336
|
+
exclude,
|
|
337
|
+
glob,
|
|
338
|
+
icase,
|
|
339
|
+
...(prefix >= 0 ? { prefix, bytes: true } : {}),
|
|
340
|
+
...(attr ? { attr } : {}),
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* git's `strtol(pos + 7, &endptr, 10)` of `prefix:<n>`, which must use up the word: leading
|
|
346
|
+
* blanks and a sign allowed, no digits at all read as 0 (only for an empty number), the value
|
|
347
|
+
* clamped to a `long` and kept as an `int`. A negative prefix is no prefix magic.
|
|
348
|
+
*/
|
|
349
|
+
function parsePrefixMagic(text: string): number {
|
|
350
|
+
if (text === "") return 0;
|
|
351
|
+
if (!/^[ \t\n\v\f\r]*[-+]?\d+$/.test(text))
|
|
352
|
+
throw new Error("invalid parameter for pathspec magic 'prefix'");
|
|
353
|
+
let n = BigInt(text.trim());
|
|
354
|
+
const LONG_MAX = (1n << 63n) - 1n;
|
|
355
|
+
if (n > LONG_MAX) n = LONG_MAX;
|
|
356
|
+
else if (n < -LONG_MAX - 1n) n = -LONG_MAX - 1n;
|
|
357
|
+
return Number(BigInt.asIntN(32, n));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const isGlobSpecial = (c: string) => c === "*" || c === "?" || c === "[" || c === "\\";
|
|
361
|
+
|
|
362
|
+
/** git's `normalize_path_copy` of a path from the top (trailing slash kept; "." is ""). */
|
|
363
|
+
function normalizePathspecPath(path: string, elem: string): string {
|
|
364
|
+
const trailing = path.endsWith("/") && path.replace(/\/+$/, "") !== "";
|
|
365
|
+
const out: string[] = [];
|
|
366
|
+
for (const part of path.split("/")) {
|
|
367
|
+
if (part === "" || part === ".") continue;
|
|
368
|
+
if (part === "..") {
|
|
369
|
+
if (out.length === 0) throw new Error(`'${elem}' is outside repository`);
|
|
370
|
+
out.pop();
|
|
371
|
+
} else out.push(part);
|
|
372
|
+
}
|
|
373
|
+
const joined = out.join("/");
|
|
374
|
+
return joined && trailing ? `${joined}/` : joined;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* git's `ps_strncmp` / `ps_strcmp`: equal, case-insensitively for `:(icase)` (`strncasecmp`:
|
|
379
|
+
* ASCII letters only, as git folds them).
|
|
380
|
+
*/
|
|
381
|
+
export const psEqual = (item: PathspecItem, a: string, b: string) =>
|
|
382
|
+
item.icase ? foldAsciiCase(a) === foldAsciiCase(b) : a === b;
|
|
383
|
+
|
|
384
|
+
/** git's `git_fnmatch` of an element against a name. */
|
|
385
|
+
function pathspecFnmatch(item: PathspecItem, name: string): boolean {
|
|
386
|
+
return gitFnmatch(item, item.match, name, item.nowildcardLen);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* git's `git_fnmatch`: whether `string` matches `pattern` (an element's pattern, or its tail),
|
|
391
|
+
* the first `prefix` characters compared literally.
|
|
392
|
+
*/
|
|
393
|
+
function gitFnmatch(item: PathspecItem, pattern: string, string: string, prefix: number): boolean {
|
|
394
|
+
if (prefix > 0) {
|
|
395
|
+
if (!psEqual(item, string.slice(0, prefix), pattern.slice(0, prefix))) return false;
|
|
396
|
+
pattern = pattern.slice(prefix);
|
|
397
|
+
string = string.slice(prefix);
|
|
398
|
+
}
|
|
399
|
+
if (item.oneStar) {
|
|
400
|
+
const tail = pattern.slice(1);
|
|
401
|
+
return (
|
|
402
|
+
string.length >= tail.length && psEqual(item, string.slice(string.length - tail.length), tail)
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
const options = { pathname: item.glob, casefold: item.icase };
|
|
406
|
+
if (item.bytes) return wildmatchBytes(latin1Bytes(pattern), latin1Bytes(string), options);
|
|
407
|
+
return wildmatch(pattern, string, options);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* A path as an element held as bytes ({@link pathspecItemBytes}) matches it: its bytes, one
|
|
412
|
+
* character each, as git compares them (an escaped byte as that byte).
|
|
413
|
+
*/
|
|
414
|
+
export const pathspecName = (name: string) => byteString(name);
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* git's `match_pathspec_item`, in byte space: the element as its bytes and the name as its
|
|
418
|
+
* bytes, so an element that cuts a character matches as in git (`:(icase)` folds ASCII only).
|
|
419
|
+
*/
|
|
420
|
+
function matchPathspecItem(element: PathspecItem, path: string, flags: number): number {
|
|
421
|
+
const how = matchPathspecItemPath(element, path, flags);
|
|
422
|
+
if (!how || !element.attr) return how;
|
|
423
|
+
// match_pathspec_attrs: the path's attributes as the element wants them, or no match
|
|
424
|
+
const values = element.attrLookup?.(path);
|
|
425
|
+
if (!values) throw new Error(`BUG: the attributes of '${path}' were not loaded for a pathspec`);
|
|
426
|
+
return attrsMatch(element.attr, values) ? how : 0;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** git's `match_pathspec_attrs` over the values read: each requirement as the element says. */
|
|
430
|
+
export function attrsMatch(
|
|
431
|
+
wanted: readonly AttrMatch[],
|
|
432
|
+
values: ReadonlyMap<string, PathspecAttributeValue>,
|
|
433
|
+
): boolean {
|
|
434
|
+
for (const a of wanted) {
|
|
435
|
+
const v = values.get(a.name);
|
|
436
|
+
const ok =
|
|
437
|
+
v === true
|
|
438
|
+
? a.mode === "set"
|
|
439
|
+
: v === false
|
|
440
|
+
? a.mode === "unset"
|
|
441
|
+
: v === undefined
|
|
442
|
+
? a.mode === "unspecified"
|
|
443
|
+
: a.mode === "value" && a.value === v;
|
|
444
|
+
if (!ok) return false;
|
|
445
|
+
}
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Whether the element can match `path` by its path alone (its attributes not asked): the
|
|
451
|
+
* paths {@link PathspecAttributes} loads the attributes of.
|
|
452
|
+
*/
|
|
453
|
+
export function pathspecItemMayMatch(item: PathspecItem, path: string): boolean {
|
|
454
|
+
return matchPathspecItemPath(item, path, DO_MATCH_DIRECTORY | DO_MATCH_LEADING_PATHSPEC) > 0;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** {@link matchPathspecItem} without the attributes. */
|
|
458
|
+
function matchPathspecItemPath(element: PathspecItem, path: string, flags: number): number {
|
|
459
|
+
const item = pathspecItemBytes(element);
|
|
460
|
+
const { match } = item;
|
|
461
|
+
const name = pathspecName(path);
|
|
462
|
+
const matchlen = match.length;
|
|
463
|
+
const namelen = name.length;
|
|
464
|
+
// the prefix of `:(prefix:N)` (bytes) compares exactly, even under icase (dir.c)
|
|
465
|
+
if (item.prefix && item.icase && name.slice(0, item.prefix) !== match.slice(0, item.prefix))
|
|
466
|
+
return 0;
|
|
467
|
+
if (matchlen === 0) return MATCHED_RECURSIVELY;
|
|
468
|
+
if (matchlen <= namelen && psEqual(item, name.slice(0, matchlen), match)) {
|
|
469
|
+
if (matchlen === namelen) return MATCHED_EXACTLY;
|
|
470
|
+
if (match[matchlen - 1] === "/" || name[matchlen] === "/") return MATCHED_RECURSIVELY;
|
|
471
|
+
} else if (
|
|
472
|
+
flags & DO_MATCH_DIRECTORY &&
|
|
473
|
+
match[matchlen - 1] === "/" &&
|
|
474
|
+
namelen === matchlen - 1 &&
|
|
475
|
+
psEqual(item, match.slice(0, namelen), name)
|
|
476
|
+
) {
|
|
477
|
+
return MATCHED_EXACTLY;
|
|
478
|
+
}
|
|
479
|
+
if (item.nowildcardLen < matchlen && pathspecFnmatch(item, name)) return MATCHED_FNMATCH;
|
|
480
|
+
if (flags & DO_MATCH_LEADING_PATHSPEC && !(flags & DO_MATCH_EXCLUDE)) {
|
|
481
|
+
const offset = name.endsWith("/") ? 1 : 0;
|
|
482
|
+
if (
|
|
483
|
+
namelen < matchlen &&
|
|
484
|
+
match[namelen - offset] === "/" &&
|
|
485
|
+
psEqual(item, match.slice(0, namelen), name)
|
|
486
|
+
) {
|
|
487
|
+
return MATCHED_RECURSIVELY_LEADING_PATHSPEC;
|
|
488
|
+
}
|
|
489
|
+
const n = item.nowildcardLen;
|
|
490
|
+
if (n < matchlen && !psEqual(item, name.slice(0, n), match.slice(0, n))) return 0;
|
|
491
|
+
if (n === matchlen) return 0;
|
|
492
|
+
return MATCHED_RECURSIVELY_LEADING_PATHSPEC;
|
|
493
|
+
}
|
|
494
|
+
return 0;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** git's `match_pathspec_with_flags`: the best positive match, unless an exclude matches. */
|
|
498
|
+
export function matchPathspec(items: PathspecItem[], name: string, flags: number): number {
|
|
499
|
+
if (items.length === 0) return MATCHED_RECURSIVELY;
|
|
500
|
+
let positive = 0;
|
|
501
|
+
for (const item of items) {
|
|
502
|
+
if (!item.exclude) positive = Math.max(positive, matchPathspecItem(item, name, flags));
|
|
503
|
+
}
|
|
504
|
+
if (!positive || !items.some((i) => i.exclude)) return positive;
|
|
505
|
+
for (const item of items) {
|
|
506
|
+
if (item.exclude && matchPathspecItem(item, name, flags | DO_MATCH_EXCLUDE)) return 0;
|
|
507
|
+
}
|
|
508
|
+
return positive;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* git's `match_pathspec_with_flags` with its `seen` array (`ps_matched`): as
|
|
513
|
+
* {@link matchPathspec}, and `seen[i]` raised to how element `i` matched (an exclude element
|
|
514
|
+
* visited counts as matched, as git never reports one), for {@link pathspecErrors}.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```typescript
|
|
518
|
+
* const items = parsePathspec(["d/", "*.md"]);
|
|
519
|
+
* const seen = items.map(() => 0);
|
|
520
|
+
* for (const path of paths) if (matchPathspecSeen(items, path, 0, seen)) take(path);
|
|
521
|
+
* const errors = pathspecErrors(["d/", "*.md"], seen); // the elements that matched nothing
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
export function matchPathspecSeen(
|
|
525
|
+
items: PathspecItem[],
|
|
526
|
+
name: string,
|
|
527
|
+
flags: number,
|
|
528
|
+
seen: number[],
|
|
529
|
+
/**
|
|
530
|
+
* git 2.43's `do_match_pathspec`: an element that matched a name exactly matches no later
|
|
531
|
+
* name, a glob-looking one included (`git rm 'b*'` with an entry `b*` removes only it,
|
|
532
|
+
* the index being sorted); 2.5x skips only elements without wildcards
|
|
533
|
+
*/
|
|
534
|
+
exactStopsGlobs = false,
|
|
535
|
+
): number {
|
|
536
|
+
if (items.length === 0) return MATCHED_RECURSIVELY;
|
|
537
|
+
const pass = (exclude: boolean, passFlags: number): number => {
|
|
538
|
+
let retval = 0;
|
|
539
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
540
|
+
const item = items[i] as PathspecItem;
|
|
541
|
+
if (item.exclude !== exclude) continue;
|
|
542
|
+
if (
|
|
543
|
+
seen[i] === MATCHED_EXACTLY &&
|
|
544
|
+
(exactStopsGlobs || item.nowildcardLen === item.match.length)
|
|
545
|
+
) {
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
if (item.exclude) seen[i] = MATCHED_FNMATCH;
|
|
549
|
+
const how = matchPathspecItem(item, name, passFlags);
|
|
550
|
+
if (how) {
|
|
551
|
+
if (retval < how) retval = how;
|
|
552
|
+
if ((seen[i] ?? 0) < how) seen[i] = how;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return retval;
|
|
556
|
+
};
|
|
557
|
+
const positive = pass(false, flags);
|
|
558
|
+
if (!positive || !items.some((i) => i.exclude)) return positive;
|
|
559
|
+
return pass(true, flags | DO_MATCH_EXCLUDE) ? 0 : positive;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* git's `report_path_error`: one "error: pathspec '<element>' did not match any file(s)
|
|
564
|
+
* known to git" line per element `seen` marks unmatched (an element given twice, once
|
|
565
|
+
* matched, is not reported). `originals` are the elements as given.
|
|
566
|
+
*/
|
|
567
|
+
export function pathspecErrors(originals: readonly string[], seen: readonly number[]): string[] {
|
|
568
|
+
const errors: string[] = [];
|
|
569
|
+
for (let num = 0; num < originals.length; num++) {
|
|
570
|
+
if (seen[num]) continue;
|
|
571
|
+
const dup = originals.some((o, other) => other !== num && seen[other] && o === originals[num]);
|
|
572
|
+
if (dup) continue;
|
|
573
|
+
errors.push(`error: pathspec '${originals[num]}' did not match any file(s) known to git`);
|
|
574
|
+
}
|
|
575
|
+
return errors;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* git's `exclude_matches_pathspec`: whether an ignored path found by the directory scan is
|
|
580
|
+
* one the pathspec names (an element's literal part is the path, or goes on below it as a
|
|
581
|
+
* directory), so `git add` reports it as ignored instead of passing over it in silence.
|
|
582
|
+
*/
|
|
583
|
+
export function excludeMatchesPathspec(items: readonly PathspecItem[], path: string): boolean {
|
|
584
|
+
const name = pathspecName(path);
|
|
585
|
+
for (const element of items) {
|
|
586
|
+
const item = pathspecItemBytes(element);
|
|
587
|
+
const len = item.nowildcardLen;
|
|
588
|
+
const n = name.length;
|
|
589
|
+
if (len < n) continue;
|
|
590
|
+
if (len > n && item.match[n] !== "/") continue;
|
|
591
|
+
if (psEqual(item, item.match.slice(0, n), name)) return true;
|
|
592
|
+
}
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* dir.c's `common_prefix_len`: the leading directories (each with its `/`, in bytes) every
|
|
598
|
+
* positive element shares in its literal part (an `:(icase)` element's only up to its
|
|
599
|
+
* `:(prefix:N)`), from the first positive element's match; "" when none.
|
|
600
|
+
*/
|
|
601
|
+
export function pathspecCommonPrefix(items: readonly PathspecItem[]): string {
|
|
602
|
+
let first: PathspecItem | undefined;
|
|
603
|
+
let max = 0;
|
|
604
|
+
for (const element of items) {
|
|
605
|
+
if (element.exclude) continue;
|
|
606
|
+
const item = pathspecItemBytes(element);
|
|
607
|
+
const isFirst = first === undefined;
|
|
608
|
+
if (isFirst) first = item;
|
|
609
|
+
const head = first as PathspecItem;
|
|
610
|
+
const itemLen = item.icase ? (item.prefix ?? 0) : item.nowildcardLen;
|
|
611
|
+
let len = 0;
|
|
612
|
+
for (let i = 0; i < itemLen && (isFirst || i < max); i++) {
|
|
613
|
+
const c = item.match[i];
|
|
614
|
+
if (c !== head.match[i]) break;
|
|
615
|
+
if (c === "/") len = i + 1;
|
|
616
|
+
}
|
|
617
|
+
if (isFirst || len < max) {
|
|
618
|
+
max = len;
|
|
619
|
+
if (!max) break;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return first ? first.match.slice(0, max) : "";
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* dir.c's `simplify_away`: no element (an exclude one included) can match `path` or
|
|
627
|
+
* anything below it, judged by the elements' literal parts.
|
|
628
|
+
*/
|
|
629
|
+
export function pathspecSimplifyAway(items: readonly PathspecItem[], path: string): boolean {
|
|
630
|
+
if (items.length === 0) return false;
|
|
631
|
+
const name = pathspecName(path);
|
|
632
|
+
for (const element of items) {
|
|
633
|
+
const item = pathspecItemBytes(element);
|
|
634
|
+
const len = Math.min(item.nowildcardLen, name.length);
|
|
635
|
+
if (psEqual(item, item.match.slice(0, len), name.slice(0, len))) return false;
|
|
636
|
+
}
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* The pathspec as `scanUntracked` (vcs-working-tree) asks it, dir.c's view of it: the
|
|
642
|
+
* walk starts at the elements' common leading directory (`common_prefix_len`, decoded to a
|
|
643
|
+
* path of the repository), skips what no element can reach (`simplify_away`), and matches
|
|
644
|
+
* names with `match_pathspec_with_flags` (a directory as `dir/` with
|
|
645
|
+
* `DO_MATCH_LEADING_PATHSPEC`, which `treat_directory` passes).
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* ```typescript
|
|
649
|
+
* const items = parsePathspec(["src/*.ts", ":!src/gen"]);
|
|
650
|
+
* await scanUntracked(host, { ..., matcher: untrackedScanPathspec(items) });
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
653
|
+
export function untrackedScanPathspec(
|
|
654
|
+
items: PathspecItem[],
|
|
655
|
+
/** The attributes of `:(attr:...)` elements, read for a name before it is matched */
|
|
656
|
+
attributes?: { needs(path: string): boolean; loadOne(path: string): Promise<void> },
|
|
657
|
+
): {
|
|
658
|
+
match(name: string, leading: boolean): number | Promise<number>;
|
|
659
|
+
simplifyAway(path: string): boolean;
|
|
660
|
+
commonPrefix(): string;
|
|
661
|
+
} {
|
|
662
|
+
return {
|
|
663
|
+
match: (name, leading) => {
|
|
664
|
+
const flags = leading ? DO_MATCH_LEADING_PATHSPEC : 0;
|
|
665
|
+
if (attributes?.needs(name)) {
|
|
666
|
+
return attributes.loadOne(name).then(() => matchPathspec(items, name, flags));
|
|
667
|
+
}
|
|
668
|
+
return matchPathspec(items, name, flags);
|
|
669
|
+
},
|
|
670
|
+
simplifyAway: (path) => pathspecSimplifyAway(items, path),
|
|
671
|
+
commonPrefix: () => {
|
|
672
|
+
const prefix = pathspecCommonPrefix(items);
|
|
673
|
+
return prefix ? decodeGitPath(latin1Bytes(prefix)) : "";
|
|
674
|
+
},
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** The path an element names, as a string of the repository (its literal match, decoded). */
|
|
679
|
+
export function pathspecItemPath(item: PathspecItem): string {
|
|
680
|
+
return item.bytes ? decodeGitPath(latin1Bytes(item.match)) : item.match;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// ============ tree entries (tree-walk.c tree_entry_interesting) ============
|
|
684
|
+
|
|
685
|
+
/** `tree_entry_interesting`: no later entry of this tree can match */
|
|
686
|
+
export const ALL_ENTRIES_NOT_INTERESTING = -1;
|
|
687
|
+
/** `tree_entry_interesting`: this entry does not match */
|
|
688
|
+
export const ENTRY_NOT_INTERESTING = 0;
|
|
689
|
+
/** `tree_entry_interesting`: this entry matches (a directory: some of it may) */
|
|
690
|
+
export const ENTRY_INTERESTING = 1;
|
|
691
|
+
/** `tree_entry_interesting`: this entry and everything below it matches */
|
|
692
|
+
export const ALL_ENTRIES_INTERESTING = 2;
|
|
693
|
+
/**
|
|
694
|
+
* `treeEntryInteresting` cannot tell yet: an `:(attr)` element needs the attributes of the
|
|
695
|
+
* path in `TreePathspec.attributes.pending`. Load them (`values`) and ask again.
|
|
696
|
+
*/
|
|
697
|
+
export const NEED_ATTRIBUTES = -3;
|
|
698
|
+
/** `doMatch`: the element does not match after all (its attributes differ); try the next */
|
|
699
|
+
const NEXT_ELEMENT = -4;
|
|
700
|
+
|
|
701
|
+
/** An attribute's value as the attributes resolver gives it (git's ATTR_TRUE/FALSE/UNSET or a string). */
|
|
702
|
+
export type PathspecAttributeValue = true | false | string | undefined;
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* A pathspec element prepared for raw tree entries: its path as UTF-8 bytes, compared with the
|
|
706
|
+
* bytes of entry names where they lie in the tree (no name is decoded).
|
|
707
|
+
*/
|
|
708
|
+
export interface TreePathspecElement {
|
|
709
|
+
/** The path's bytes */
|
|
710
|
+
match: Uint8Array;
|
|
711
|
+
/** The length in bytes of its leading literal part */
|
|
712
|
+
nowildcardLen: number;
|
|
713
|
+
oneStar: boolean;
|
|
714
|
+
exclude: boolean;
|
|
715
|
+
glob: boolean;
|
|
716
|
+
icase: boolean;
|
|
717
|
+
/** The pattern after its literal part (what wildmatch matches after the prefix) */
|
|
718
|
+
tail: Uint8Array;
|
|
719
|
+
/** wildmatch's options for the element */
|
|
720
|
+
wildmatch: { pathname: boolean; casefold: boolean };
|
|
721
|
+
/** `:(attr:...)` requirements */
|
|
722
|
+
attr: AttrMatch[] | undefined;
|
|
723
|
+
/** `:(prefix:N)`: its first N bytes compare case-sensitively even under icase (0: none) */
|
|
724
|
+
prefix: number;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* A pathspec prepared for tree entries: its elements with their paths as bytes, so names
|
|
729
|
+
* compare as git's `strncmp` compares them.
|
|
730
|
+
*/
|
|
731
|
+
export interface TreePathspec {
|
|
732
|
+
/** The elements, their paths one character per byte (for the Bloom keys) */
|
|
733
|
+
items: PathspecItem[];
|
|
734
|
+
/** The elements, their paths as bytes (for `treeEntryInteresting`) */
|
|
735
|
+
elements: TreePathspecElement[];
|
|
736
|
+
/** Some element has a wildcard (git's `has_wildcard`) */
|
|
737
|
+
hasWildcard: boolean;
|
|
738
|
+
/** Some element excludes (`PATHSPEC_EXCLUDE` in the pathspec's magic) */
|
|
739
|
+
hasExclude: boolean;
|
|
740
|
+
/**
|
|
741
|
+
* With `:(attr)` elements: the attributes they name, the values read so far by path, and
|
|
742
|
+
* the path `treeEntryInteresting` asks for when it returns `NEED_ATTRIBUTES`.
|
|
743
|
+
*/
|
|
744
|
+
attributes?: {
|
|
745
|
+
names: string[];
|
|
746
|
+
values: Map<string, Map<string, PathspecAttributeValue>>;
|
|
747
|
+
pending?: string;
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/** The elements as `tree_entry_interesting` matches them. */
|
|
752
|
+
export function treePathspec(items: PathspecItem[]): TreePathspec {
|
|
753
|
+
const byteItems = items.map(pathspecItemBytes);
|
|
754
|
+
const elements = items.map((item): TreePathspecElement => {
|
|
755
|
+
const match = item.bytes ? latin1Bytes(item.match) : encodeGitPath(item.match);
|
|
756
|
+
const nowildcardLen = item.bytes
|
|
757
|
+
? item.nowildcardLen
|
|
758
|
+
: encodeGitPath(item.match.slice(0, item.nowildcardLen)).length;
|
|
759
|
+
return {
|
|
760
|
+
match,
|
|
761
|
+
nowildcardLen,
|
|
762
|
+
oneStar: item.oneStar,
|
|
763
|
+
exclude: item.exclude,
|
|
764
|
+
glob: item.glob,
|
|
765
|
+
icase: item.icase,
|
|
766
|
+
tail: match.subarray(nowildcardLen),
|
|
767
|
+
wildmatch: { pathname: item.glob, casefold: item.icase },
|
|
768
|
+
attr: item.attr,
|
|
769
|
+
prefix: item.prefix && item.prefix > 0 ? item.prefix : 0,
|
|
770
|
+
};
|
|
771
|
+
});
|
|
772
|
+
const names = [...new Set(items.flatMap((i) => (i.attr ?? []).map((a) => a.name)))];
|
|
773
|
+
return {
|
|
774
|
+
items: byteItems,
|
|
775
|
+
elements,
|
|
776
|
+
hasWildcard: elements.some((e) => e.nowildcardLen < e.match.length),
|
|
777
|
+
hasExclude: elements.some((e) => e.exclude),
|
|
778
|
+
...(items.some((i) => i.attr) ? { attributes: { names, values: new Map() } } : {}),
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* git's `interesting:` label of `do_match`: an element with attributes matches a file only if
|
|
784
|
+
* the file has them (`match_pathspec_attrs`); every directory is interesting then.
|
|
785
|
+
*/
|
|
786
|
+
function interesting(ps: TreePathspec, el: TreePathspecElement, mode: number, result: number) {
|
|
787
|
+
if (!el.attr) return result;
|
|
788
|
+
never = ENTRY_NOT_INTERESTING;
|
|
789
|
+
if (isDirMode(mode)) return ENTRY_INTERESTING;
|
|
790
|
+
// the path as the worktree names it: bytes that are no UTF-8 kept apart (surrogateescape)
|
|
791
|
+
const path = decodeGitPath(baseBytes) + decodeGitPath(nameBytes.subarray(nameStart, nameEnd));
|
|
792
|
+
const attributes = ps.attributes as NonNullable<TreePathspec["attributes"]>;
|
|
793
|
+
const values = attributes.values.get(path);
|
|
794
|
+
if (!values) {
|
|
795
|
+
attributes.pending = path;
|
|
796
|
+
return NEED_ATTRIBUTES;
|
|
797
|
+
}
|
|
798
|
+
for (const a of el.attr) {
|
|
799
|
+
const v = values.get(a.name);
|
|
800
|
+
const ok =
|
|
801
|
+
v === true
|
|
802
|
+
? a.mode === "set"
|
|
803
|
+
: v === false
|
|
804
|
+
? a.mode === "unset"
|
|
805
|
+
: v === undefined
|
|
806
|
+
? a.mode === "unspecified"
|
|
807
|
+
: a.mode === "value" && a.value === v;
|
|
808
|
+
if (!ok) return NEXT_ELEMENT;
|
|
809
|
+
}
|
|
810
|
+
return ENTRY_INTERESTING;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/** A path's git bytes (`encodeGitPath`: escaped bytes as they were), one character each. */
|
|
814
|
+
export function byteString(s: string): string {
|
|
815
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: ASCII fast path
|
|
816
|
+
if (/^[\x00-\x7f]*$/.test(s)) return s;
|
|
817
|
+
return latin1String(encodeGitPath(s));
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/** A string of one character per byte as its bytes. */
|
|
821
|
+
export function latin1Bytes(s: string): Uint8Array {
|
|
822
|
+
const out = new Uint8Array(s.length);
|
|
823
|
+
for (let i = 0; i < s.length; i++) out[i] = s.charCodeAt(i);
|
|
824
|
+
return out;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/** Bytes as a string of one character per byte. */
|
|
828
|
+
export function latin1String(bytes: Uint8Array): string {
|
|
829
|
+
let out = "";
|
|
830
|
+
for (let i = 0; i < bytes.length; i += 4096) {
|
|
831
|
+
out += String.fromCharCode(...bytes.subarray(i, i + 4096));
|
|
832
|
+
}
|
|
833
|
+
return out;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
const isDirMode = (mode: number) => (mode & 0o170000) === 0o040000;
|
|
837
|
+
const isGitlinkMode = (mode: number) => (mode & 0o170000) === 0o160000;
|
|
838
|
+
const lowerByte = (c: number) => (c >= 0x41 && c <= 0x5a ? c + 32 : c);
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* C's `strncmp` (or `strncasecmp` with `icase`: ASCII letters folded, as git's `ps_strncmp`)
|
|
842
|
+
* of `a[aFrom, aEnd)` and `b[bFrom, bEnd)` over at most `n` bytes, each read as NUL past its
|
|
843
|
+
* end: a sign.
|
|
844
|
+
*/
|
|
845
|
+
function strncmpBytes(
|
|
846
|
+
a: Uint8Array,
|
|
847
|
+
aFrom: number,
|
|
848
|
+
aEnd: number,
|
|
849
|
+
b: Uint8Array,
|
|
850
|
+
bFrom: number,
|
|
851
|
+
bEnd: number,
|
|
852
|
+
n: number,
|
|
853
|
+
icase: boolean,
|
|
854
|
+
): number {
|
|
855
|
+
for (let i = 0; i < n; i++) {
|
|
856
|
+
let ca = aFrom + i < aEnd ? (a[aFrom + i] as number) : 0;
|
|
857
|
+
let cb = bFrom + i < bEnd ? (b[bFrom + i] as number) : 0;
|
|
858
|
+
if (icase) {
|
|
859
|
+
ca = lowerByte(ca);
|
|
860
|
+
cb = lowerByte(cb);
|
|
861
|
+
}
|
|
862
|
+
if (ca !== cb) return ca - cb;
|
|
863
|
+
if (ca === 0) return 0;
|
|
864
|
+
}
|
|
865
|
+
return 0;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* The name of the entry being matched (in its tree's bytes) and its base, set by
|
|
870
|
+
* `treeEntryInteresting` for the functions below (matching is synchronous).
|
|
871
|
+
*/
|
|
872
|
+
let nameBytes: Uint8Array = new Uint8Array(0);
|
|
873
|
+
let nameStart = 0;
|
|
874
|
+
let nameEnd = 0;
|
|
875
|
+
let baseBytes: Uint8Array = new Uint8Array(0);
|
|
876
|
+
/** git's `never_interesting` of the `do_match` running */
|
|
877
|
+
let never = ENTRY_NOT_INTERESTING;
|
|
878
|
+
/** base + name, for the wildcard matches of whole paths (grown as needed) */
|
|
879
|
+
let joined = new Uint8Array(256);
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* git's `match_entry`: the element (its part from `from` on, below the base) names the entry
|
|
883
|
+
* or lies below it.
|
|
884
|
+
*/
|
|
885
|
+
function matchEntry(el: TreePathspecElement, from: number, mode: number): boolean {
|
|
886
|
+
const match = el.match;
|
|
887
|
+
const pathlen = nameEnd - nameStart;
|
|
888
|
+
const matchlen = match.length - from;
|
|
889
|
+
let m: number | undefined;
|
|
890
|
+
if (el.icase) {
|
|
891
|
+
never = ENTRY_NOT_INTERESTING;
|
|
892
|
+
} else if (never !== ENTRY_NOT_INTERESTING) {
|
|
893
|
+
m = strncmpBytes(
|
|
894
|
+
match,
|
|
895
|
+
from,
|
|
896
|
+
match.length,
|
|
897
|
+
nameBytes,
|
|
898
|
+
nameStart,
|
|
899
|
+
nameEnd,
|
|
900
|
+
matchlen < pathlen ? matchlen : pathlen,
|
|
901
|
+
false,
|
|
902
|
+
);
|
|
903
|
+
if (m < 0) return false;
|
|
904
|
+
never = ENTRY_NOT_INTERESTING;
|
|
905
|
+
}
|
|
906
|
+
if (pathlen > matchlen) return false;
|
|
907
|
+
if (matchlen > pathlen) {
|
|
908
|
+
if (match[from + pathlen] !== 0x2f) return false;
|
|
909
|
+
if (!isDirMode(mode) && (!isGitlinkMode(mode) || matchlen > pathlen + 1)) return false;
|
|
910
|
+
}
|
|
911
|
+
if (m === undefined)
|
|
912
|
+
m = strncmpBytes(match, from, match.length, nameBytes, nameStart, nameEnd, pathlen, el.icase);
|
|
913
|
+
return m === 0;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/**
|
|
917
|
+
* git's `basecmp`: `strncmp`, or under icase the first `item->prefix` bytes exactly and the
|
|
918
|
+
* rest case-insensitively.
|
|
919
|
+
*/
|
|
920
|
+
function basecmp(el: TreePathspecElement, len: number): number {
|
|
921
|
+
const baseEnd = baseBytes.length;
|
|
922
|
+
const matchEnd = el.match.length;
|
|
923
|
+
if (el.icase && el.prefix > 0) {
|
|
924
|
+
const n = len > el.prefix ? el.prefix : len;
|
|
925
|
+
const r = strncmpBytes(baseBytes, 0, baseEnd, el.match, 0, matchEnd, n, false);
|
|
926
|
+
if (r) return r;
|
|
927
|
+
return strncmpBytes(baseBytes, n, baseEnd, el.match, n, matchEnd, len - n, true);
|
|
928
|
+
}
|
|
929
|
+
return strncmpBytes(baseBytes, 0, baseEnd, el.match, 0, matchEnd, len, el.icase);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/** git's `match_dir_prefix`: the base lies at or below the element. */
|
|
933
|
+
function matchDirPrefix(el: TreePathspecElement, matchlen: number): boolean {
|
|
934
|
+
if (basecmp(el, matchlen)) return false;
|
|
935
|
+
return (
|
|
936
|
+
matchlen === 0 ||
|
|
937
|
+
(matchlen < baseBytes.length && baseBytes[matchlen] === 0x2f) ||
|
|
938
|
+
el.match[matchlen - 1] === 0x2f
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/** git's `match_wildcard_base`: the base agrees with the element's literal part. */
|
|
943
|
+
function matchWildcardBase(el: TreePathspecElement): boolean {
|
|
944
|
+
const matchlen = el.nowildcardLen;
|
|
945
|
+
const baselen = baseBytes.length;
|
|
946
|
+
if (baselen) {
|
|
947
|
+
if (baselen >= matchlen) return !basecmp(el, matchlen);
|
|
948
|
+
if (basecmp(el, baselen)) return false;
|
|
949
|
+
}
|
|
950
|
+
return true;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* git's `git_fnmatch` of the element's pattern from `from` on and `text[tFrom, tEnd)`, the
|
|
955
|
+
* first `prefix` bytes compared literally.
|
|
956
|
+
*/
|
|
957
|
+
function fnmatchBytes(
|
|
958
|
+
el: TreePathspecElement,
|
|
959
|
+
from: number,
|
|
960
|
+
text: Uint8Array,
|
|
961
|
+
tFrom: number,
|
|
962
|
+
tEnd: number,
|
|
963
|
+
prefix: number,
|
|
964
|
+
): boolean {
|
|
965
|
+
const pattern = el.match;
|
|
966
|
+
if (prefix > 0) {
|
|
967
|
+
if (tEnd - tFrom < prefix) return false;
|
|
968
|
+
for (let i = 0; i < prefix; i++) {
|
|
969
|
+
let a = text[tFrom + i] as number;
|
|
970
|
+
let b = pattern[from + i] as number;
|
|
971
|
+
if (el.icase) {
|
|
972
|
+
a = lowerByte(a);
|
|
973
|
+
b = lowerByte(b);
|
|
974
|
+
}
|
|
975
|
+
if (a !== b) return false;
|
|
976
|
+
}
|
|
977
|
+
from += prefix;
|
|
978
|
+
tFrom += prefix;
|
|
979
|
+
}
|
|
980
|
+
if (el.oneStar) {
|
|
981
|
+
// the tail after the "*" ends the text
|
|
982
|
+
const tail = pattern.length - from - 1;
|
|
983
|
+
if (tEnd - tFrom < tail) return false;
|
|
984
|
+
for (let i = 0; i < tail; i++) {
|
|
985
|
+
let a = text[tEnd - tail + i] as number;
|
|
986
|
+
let b = pattern[from + 1 + i] as number;
|
|
987
|
+
if (el.icase) {
|
|
988
|
+
a = lowerByte(a);
|
|
989
|
+
b = lowerByte(b);
|
|
990
|
+
}
|
|
991
|
+
if (a !== b) return false;
|
|
992
|
+
}
|
|
993
|
+
return true;
|
|
994
|
+
}
|
|
995
|
+
// the pattern after the literal prefix is the element's tail (kept): only the text is a view
|
|
996
|
+
const rest = from === el.nowildcardLen ? el.tail : pattern.subarray(from);
|
|
997
|
+
return wildmatchBytes(rest, text.subarray(tFrom, tEnd), el.wildmatch);
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/** git's `do_match` (recursive, no depth limit, no attributes) over one kind of element. */
|
|
1001
|
+
function doMatch(ps: TreePathspec, mode: number, exclude: boolean): number {
|
|
1002
|
+
never = ps.hasWildcard ? ENTRY_NOT_INTERESTING : ALL_ENTRIES_NOT_INTERESTING;
|
|
1003
|
+
const baselen = baseBytes.length;
|
|
1004
|
+
const isDir = isDirMode(mode);
|
|
1005
|
+
const elements = ps.elements;
|
|
1006
|
+
for (let i = elements.length - 1; i >= 0; i--) {
|
|
1007
|
+
const el = elements[i] as TreePathspecElement;
|
|
1008
|
+
if (el.exclude !== exclude) continue;
|
|
1009
|
+
const matchlen = el.match.length;
|
|
1010
|
+
if (baselen >= matchlen) {
|
|
1011
|
+
if (matchDirPrefix(el, matchlen)) {
|
|
1012
|
+
const r = interesting(ps, el, mode, ALL_ENTRIES_INTERESTING);
|
|
1013
|
+
if (r !== NEXT_ELEMENT) return r;
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
} else if (baselen === 0 || !basecmp(el, baselen)) {
|
|
1017
|
+
if (matchEntry(el, baselen, mode)) {
|
|
1018
|
+
const r = interesting(ps, el, mode, ENTRY_INTERESTING);
|
|
1019
|
+
if (r !== NEXT_ELEMENT) return r;
|
|
1020
|
+
continue;
|
|
1021
|
+
}
|
|
1022
|
+
if (el.nowildcardLen < matchlen) {
|
|
1023
|
+
if (fnmatchBytes(el, baselen, nameBytes, nameStart, nameEnd, el.nowildcardLen - baselen)) {
|
|
1024
|
+
const r = interesting(ps, el, mode, ENTRY_INTERESTING);
|
|
1025
|
+
if (r !== NEXT_ELEMENT) return r;
|
|
1026
|
+
continue;
|
|
1027
|
+
}
|
|
1028
|
+
// all directories match: their files are matched later
|
|
1029
|
+
if (isDir) return ENTRY_INTERESTING;
|
|
1030
|
+
}
|
|
1031
|
+
continue;
|
|
1032
|
+
}
|
|
1033
|
+
// match_wildcards: the whole path (base and name) against the whole element
|
|
1034
|
+
if (el.nowildcardLen === matchlen) continue;
|
|
1035
|
+
if (el.nowildcardLen && !matchWildcardBase(el)) continue;
|
|
1036
|
+
const pathLength = baselen + nameEnd - nameStart;
|
|
1037
|
+
if (joined.length < pathLength)
|
|
1038
|
+
joined = new Uint8Array(Math.max(pathLength, 2 * joined.length));
|
|
1039
|
+
joined.set(baseBytes);
|
|
1040
|
+
joined.set(nameBytes.subarray(nameStart, nameEnd), baselen);
|
|
1041
|
+
if (fnmatchBytes(el, 0, joined, 0, pathLength, el.nowildcardLen)) {
|
|
1042
|
+
const r = interesting(ps, el, mode, ENTRY_INTERESTING);
|
|
1043
|
+
if (r !== NEXT_ELEMENT) return r;
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
if (isDir) return ENTRY_INTERESTING;
|
|
1047
|
+
}
|
|
1048
|
+
return never;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* git's `tree_entry_interesting`: whether the entry whose name is `tree[start, end)` (the raw
|
|
1053
|
+
* bytes of its tree), of mode `mode`, under `base` (empty, or the bytes of a directory path
|
|
1054
|
+
* ending in "/") is in the pathspec. Nothing is decoded or allocated for the common entries.
|
|
1055
|
+
*/
|
|
1056
|
+
export function treeEntryInteresting(
|
|
1057
|
+
ps: TreePathspec,
|
|
1058
|
+
tree: Uint8Array,
|
|
1059
|
+
start: number,
|
|
1060
|
+
end: number,
|
|
1061
|
+
mode: number,
|
|
1062
|
+
base: Uint8Array,
|
|
1063
|
+
): number {
|
|
1064
|
+
nameBytes = tree;
|
|
1065
|
+
nameStart = start;
|
|
1066
|
+
nameEnd = end;
|
|
1067
|
+
baseBytes = base;
|
|
1068
|
+
const positive = doMatch(ps, mode, false);
|
|
1069
|
+
if (!ps.hasExclude || positive <= ENTRY_NOT_INTERESTING) return positive;
|
|
1070
|
+
const negative = doMatch(ps, mode, true);
|
|
1071
|
+
if (negative === NEED_ATTRIBUTES) return NEED_ATTRIBUTES;
|
|
1072
|
+
if (positive === ALL_ENTRIES_INTERESTING && negative === ENTRY_NOT_INTERESTING) {
|
|
1073
|
+
return ENTRY_INTERESTING;
|
|
1074
|
+
}
|
|
1075
|
+
if (negative <= ENTRY_NOT_INTERESTING) return positive;
|
|
1076
|
+
if (isDirMode(mode) && positive >= ENTRY_INTERESTING && negative === ENTRY_INTERESTING) {
|
|
1077
|
+
return ENTRY_INTERESTING;
|
|
1078
|
+
}
|
|
1079
|
+
if (
|
|
1080
|
+
(positive === ENTRY_INTERESTING && negative >= ENTRY_INTERESTING) ||
|
|
1081
|
+
(positive === ALL_ENTRIES_INTERESTING && negative === ENTRY_INTERESTING)
|
|
1082
|
+
) {
|
|
1083
|
+
return ENTRY_NOT_INTERESTING;
|
|
1084
|
+
}
|
|
1085
|
+
return ALL_ENTRIES_NOT_INTERESTING;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* The path a pathspec element gives the changed-path Bloom filters (git's
|
|
1090
|
+
* convert_pathspec_to_bloom_keyvec): its literal part up to the last "/" before a wildcard,
|
|
1091
|
+
* without a trailing "/"; undefined when that is empty (no filter can be used then).
|
|
1092
|
+
*/
|
|
1093
|
+
export function bloomPathOf(item: PathspecItem): string | undefined {
|
|
1094
|
+
const match = item.bytes ? item.match : byteString(item.match);
|
|
1095
|
+
let len = item.bytes
|
|
1096
|
+
? item.nowildcardLen
|
|
1097
|
+
: byteString(item.match.slice(0, item.nowildcardLen)).length;
|
|
1098
|
+
if (len !== match.length) {
|
|
1099
|
+
while (len > 0 && match[len - 1] !== "/") len--;
|
|
1100
|
+
}
|
|
1101
|
+
if (len > 0 && match[len - 1] === "/") len--;
|
|
1102
|
+
return len > 0 ? match.slice(0, len) : undefined;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* git's `forbid_bloom_filters`: magic other than top, literal and glob (exclude, icase)
|
|
1107
|
+
* keeps the filters out of the walk.
|
|
1108
|
+
*/
|
|
1109
|
+
export const pathspecForbidsBloom = (items: PathspecItem[]) =>
|
|
1110
|
+
items.some((i) => i.exclude || i.icase);
|
|
1111
|
+
|
|
1112
|
+
/** The git version whose spelling of {@link prefixOriginElement} is reproduced. */
|
|
1113
|
+
export type PathspecOriginStyle = "2.43" | "2.56";
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* git's `item->original` of an element parsed with `PATHSPEC_PREFIX_ORIGIN` from the top of
|
|
1117
|
+
* the worktree (`git stash push -- <pathspec>`): the element's magic with `prefix:0` added,
|
|
1118
|
+
* then its path. git hands these to the commands it runs (`git add`, `git checkout`) and its
|
|
1119
|
+
* own pathspec errors name them. git 2.43 spells an element without magic `:(,prefix:0)x`
|
|
1120
|
+
* and long magic by its names; git 2.5x writes `:(prefix:0)x` and copies long magic as given
|
|
1121
|
+
* (`:(glob,prefix:0)*.c`). Short magic is spelled out in both (`:!x` is
|
|
1122
|
+
* `:(exclude,prefix:0)x`). An element that has prefix magic of its own is kept as given.
|
|
1123
|
+
*
|
|
1124
|
+
* @example
|
|
1125
|
+
* ```typescript
|
|
1126
|
+
* prefixOriginElement("u.txt", parsePathspecItem("u.txt"), "2.56"); // ":(prefix:0)u.txt"
|
|
1127
|
+
* prefixOriginElement("u.txt", parsePathspecItem("u.txt"), "2.43"); // ":(,prefix:0)u.txt"
|
|
1128
|
+
* ```
|
|
1129
|
+
*/
|
|
1130
|
+
export function prefixOriginElement(
|
|
1131
|
+
elem: string,
|
|
1132
|
+
item: PathspecItem,
|
|
1133
|
+
style: PathspecOriginStyle = "2.56",
|
|
1134
|
+
): string {
|
|
1135
|
+
if (item.prefix !== undefined) return elem;
|
|
1136
|
+
// the element's magic as git's pathspec_magic table lists it
|
|
1137
|
+
const names = new Set<string>();
|
|
1138
|
+
let longhand: string | undefined;
|
|
1139
|
+
if (elem.startsWith(":(")) {
|
|
1140
|
+
const close = elem.indexOf(")");
|
|
1141
|
+
longhand = elem.slice(0, close);
|
|
1142
|
+
for (const word of elem.slice(2, close).split(",")) {
|
|
1143
|
+
const name = word.trim();
|
|
1144
|
+
names.add(name.startsWith("attr:") ? "attr" : name);
|
|
1145
|
+
}
|
|
1146
|
+
} else if (elem.startsWith(":")) {
|
|
1147
|
+
for (let pos = 1; pos < elem.length && elem[pos] !== ":"; pos++) {
|
|
1148
|
+
const ch = elem[pos];
|
|
1149
|
+
if (ch === "/") names.add("top");
|
|
1150
|
+
else if (ch === "!" || ch === "^") names.add("exclude");
|
|
1151
|
+
else break;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
const table = ["top", "literal", "glob", "icase", "exclude", "attr"];
|
|
1155
|
+
const magic = table.filter((n) => names.has(n));
|
|
1156
|
+
const path = pathspecItemPath(item);
|
|
1157
|
+
if (style === "2.43") return `:(${magic.join(",")},prefix:0)${path}`;
|
|
1158
|
+
if (magic.length === 0) return `:(prefix:0)${path}`;
|
|
1159
|
+
const head = longhand ?? `:(${magic.filter((n) => n === "top" || n === "exclude").join(",")}`;
|
|
1160
|
+
return `${head},prefix:0)${path}`;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* git's `parse_pathspec_file` (`--pathspec-from-file`): one element per line (`\n`, a
|
|
1165
|
+
* trailing `\r` dropped as `strbuf_getline` drops it), a line starting with `"` unquoted
|
|
1166
|
+
* as a C string; with `nul`, elements separated by NUL and taken as they are.
|
|
1167
|
+
*
|
|
1168
|
+
* @example
|
|
1169
|
+
* ```typescript
|
|
1170
|
+
* parsePathspecFile('a.txt\n"caf\\303\\251"\n'); // ["a.txt", "café"]
|
|
1171
|
+
* ```
|
|
1172
|
+
*
|
|
1173
|
+
* @throws Error "line is badly quoted: <line>" as git dies
|
|
1174
|
+
*/
|
|
1175
|
+
export function parsePathspecFile(content: string | Uint8Array, nul = false): string[] {
|
|
1176
|
+
const bytes = typeof content === "string" ? encodeGitPath(content) : content;
|
|
1177
|
+
const out: string[] = [];
|
|
1178
|
+
const sep = nul ? 0 : 0x0a;
|
|
1179
|
+
let start = 0;
|
|
1180
|
+
while (start < bytes.length) {
|
|
1181
|
+
let end = bytes.indexOf(sep, start);
|
|
1182
|
+
if (end < 0) end = bytes.length;
|
|
1183
|
+
let lineEnd = end;
|
|
1184
|
+
if (!nul && lineEnd > start && bytes[lineEnd - 1] === 0x0d) lineEnd--;
|
|
1185
|
+
const line = bytes.subarray(start, lineEnd);
|
|
1186
|
+
if (!nul && line[0] === 0x22) {
|
|
1187
|
+
const unquoted = unquoteGitPath(line);
|
|
1188
|
+
// unquote_c_style without endp: what follows the closing quote is ignored
|
|
1189
|
+
if (!unquoted) {
|
|
1190
|
+
throw new Error(`line is badly quoted: ${decodeGitPath(line)}`);
|
|
1191
|
+
}
|
|
1192
|
+
out.push(unquoted.path);
|
|
1193
|
+
} else {
|
|
1194
|
+
out.push(decodeGitPath(line));
|
|
1195
|
+
}
|
|
1196
|
+
start = end + 1;
|
|
1197
|
+
}
|
|
1198
|
+
return out;
|
|
1199
|
+
}
|