@statewalker/vcs-commands 0.5.0 → 0.7.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 +134 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/comment-char-config.d.ts +35 -0
- package/dist/commands/comment-char-config.d.ts.map +1 -0
- 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/default-branch.d.ts +70 -0
- package/dist/commands/default-branch.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 +227 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +71 -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 +159 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +140 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +122 -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 +106 -39
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +2 -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 +424 -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 +233 -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 +56 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +62 -4
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/legacy-remotes.d.ts +55 -0
- package/dist/commands/legacy-remotes.d.ts.map +1 -0
- 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 +221 -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 +260 -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 +116 -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 +44 -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 +59 -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 +89 -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 +325 -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 +156 -2
- 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 +54 -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-DIJ91NnD.js +62225 -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-BGiOJ8Zk.js +7246 -0
- package/dist/git-command.d.ts +428 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +315 -5
- package/dist/git.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/index.d.ts +1 -1
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +167 -6
- 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 +18 -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/init-result.d.ts +7 -0
- package/dist/results/init-result.d.ts.map +1 -1
- 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 +17 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +47 -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-WVlBhVb1.js +2935 -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 +842 -0
- package/src/commands/apply/apply-engine.ts +1602 -0
- package/src/commands/apply/apply-parse.ts +1210 -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 +1080 -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 +748 -69
- package/src/commands/comment-char-config.ts +160 -0
- package/src/commands/commit-command.ts +1782 -166
- package/src/commands/core-config.ts +166 -6
- package/src/commands/date-format.ts +668 -0
- package/src/commands/default-branch.ts +196 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1916 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +622 -68
- package/src/commands/format-patch-command.ts +974 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3464 -0
- package/src/commands/fsck/fsck-loose.ts +297 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1085 -0
- package/src/commands/fsck/fsck-object-table.ts +373 -0
- package/src/commands/fsck/fsck-pack.ts +634 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +252 -0
- package/src/commands/gc-command.ts +324 -77
- package/src/commands/git-date.ts +9 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1483 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +711 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +84 -0
- package/src/commands/init-command.ts +194 -14
- package/src/commands/legacy-remotes.ts +224 -0
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1930 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +105 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1416 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1219 -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 +777 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +617 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +378 -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 +204 -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 +1432 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +326 -33
- package/src/commands/push-command.ts +257 -29
- package/src/commands/read-tree-command.ts +861 -0
- package/src/commands/rebase-command.ts +3820 -372
- 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 +124 -23
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +821 -104
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +299 -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 +1397 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +874 -0
- package/src/commands/sequencer-support.ts +876 -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 +1326 -105
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +332 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +333 -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 +198 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +206 -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 +8 -2
- 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 +1207 -118
- package/src/git.ts +538 -12
- package/src/index.ts +1 -1
- package/src/remote-config/index.ts +2 -0
- package/src/remote-config/remote-config-store.ts +378 -18
- package/src/remote-config/remote-refs.ts +22 -6
- package/src/rename/detect-renames.ts +715 -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 +21 -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 +1053 -0
- package/src/results/fetch-result.ts +15 -0
- package/src/results/index.ts +5 -0
- package/src/results/init-result.ts +9 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +17 -3
- package/src/results/push-result.ts +48 -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 +127 -46
- package/src/transport-command.ts +121 -2
- package/dist/commands-CsLNyvZ1.js +0 -12587
- package/dist/status-result-BpyUK1Sg.js +0 -519
|
@@ -1,6 +1,88 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type BloomFilterSettings,
|
|
3
|
+
bloomFilterContains,
|
|
4
|
+
bloomKey,
|
|
5
|
+
type Commit,
|
|
6
|
+
type CommitGraph,
|
|
7
|
+
canonTreeMode,
|
|
8
|
+
commitFromBytes,
|
|
9
|
+
type GitObject,
|
|
10
|
+
type ObjectId,
|
|
11
|
+
type ObjectReplacements,
|
|
12
|
+
parseGraphCommit,
|
|
13
|
+
replacementOf,
|
|
14
|
+
} from "@statewalker/vcs-core";
|
|
15
|
+
import { ByteSink, OrderedMap, parseGitBool, type XdiffAlgorithm } from "@statewalker/vcs-utils";
|
|
16
|
+
import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
17
|
+
import { bytesToHex, hexToBytes } from "@statewalker/vcs-utils/hash/utils";
|
|
2
18
|
|
|
19
|
+
import {
|
|
20
|
+
type AttributesResolver,
|
|
21
|
+
type ContentAttributesContext,
|
|
22
|
+
expandUserPath,
|
|
23
|
+
} from "@statewalker/vcs-working-tree";
|
|
24
|
+
|
|
25
|
+
import { GitApiError, IncompatibleOptionsError } from "../errors/index.js";
|
|
3
26
|
import { GitCommand } from "../git-command.js";
|
|
27
|
+
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
28
|
+
import { type CombinedDiffOptions, writeCombinedDiff } from "../results/combined-diff.js";
|
|
29
|
+
import { quotePath } from "../results/quote-path.js";
|
|
30
|
+
import { bareAttributesResolver } from "./attributes-source.js";
|
|
31
|
+
import { DiffCommand, type DiffTextOptions } from "./diff-command.js";
|
|
32
|
+
import { hostEnvironmentOf } from "./git-ident.js";
|
|
33
|
+
import {
|
|
34
|
+
type LogOutputEntry,
|
|
35
|
+
type LogOutputHost,
|
|
36
|
+
type LogOutputOptions,
|
|
37
|
+
LogPrinter,
|
|
38
|
+
} from "./log-output.js";
|
|
39
|
+
import { Mailmap } from "./mailmap.js";
|
|
40
|
+
import { configBool, configValue } from "./merge-config.js";
|
|
41
|
+
import {
|
|
42
|
+
addRefsByGlob,
|
|
43
|
+
addRefsFromColonSep,
|
|
44
|
+
defaultNotesRef,
|
|
45
|
+
expandNotesRef,
|
|
46
|
+
initNotes,
|
|
47
|
+
type NotesHandle,
|
|
48
|
+
notesEnvironmentOf,
|
|
49
|
+
} from "./notes-support.js";
|
|
50
|
+
import { combineNotesIgnore } from "./notes-tree.js";
|
|
51
|
+
import { canonicalObjectId } from "./object-id-input.js";
|
|
52
|
+
import {
|
|
53
|
+
ALL_ENTRIES_NOT_INTERESTING,
|
|
54
|
+
bloomPathOf,
|
|
55
|
+
ENTRY_NOT_INTERESTING,
|
|
56
|
+
matchPathspec,
|
|
57
|
+
NEED_ATTRIBUTES,
|
|
58
|
+
type PathspecAttributeValue,
|
|
59
|
+
type PathspecItem,
|
|
60
|
+
parsePathspecItem,
|
|
61
|
+
pathspecForbidsBloom,
|
|
62
|
+
type TreePathspec,
|
|
63
|
+
treeEntryInteresting,
|
|
64
|
+
treePathspec,
|
|
65
|
+
} from "./pathspec.js";
|
|
66
|
+
import { PathspecAttributes } from "./pathspec-attributes.js";
|
|
67
|
+
import { loadRefDecorations } from "./pretty-format.js";
|
|
68
|
+
import { readDiffSubmoduleConfig } from "./submodule-summary.js";
|
|
69
|
+
|
|
70
|
+
/** What {@link LogCommand.callBytes} asks of the walk. */
|
|
71
|
+
interface OutputWalk {
|
|
72
|
+
/** `--topo-order` (and `--graph`) */
|
|
73
|
+
topo: boolean;
|
|
74
|
+
/** `--graph`: parents rewritten past the commits not shown */
|
|
75
|
+
rewrite: boolean;
|
|
76
|
+
entries: LogOutputEntry[];
|
|
77
|
+
/**
|
|
78
|
+
* Parents the walk never reached (`--first-parent` walks only first parents) that git's
|
|
79
|
+
* get_commit_action would show: the graph counts them as interesting
|
|
80
|
+
*/
|
|
81
|
+
unwalkedShown?: Set<ObjectId>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** git log reads no index: the in-tree attributes files are the worktree's only. */
|
|
85
|
+
const NO_INDEX = { attributesBlob: () => undefined };
|
|
4
86
|
|
|
5
87
|
/**
|
|
6
88
|
* Result of a log command iteration.
|
|
@@ -12,6 +94,30 @@ export interface LogResult extends Commit {
|
|
|
12
94
|
id: ObjectId;
|
|
13
95
|
}
|
|
14
96
|
|
|
97
|
+
/**
|
|
98
|
+
* What a path-limited walk did (git's trace2 `bloom` statistics, and the tree work behind
|
|
99
|
+
* them): how often the changed-path filters answered, and how many tree entries the walk read
|
|
100
|
+
* to compare commits with their parents.
|
|
101
|
+
*/
|
|
102
|
+
export interface LogPathStatistics {
|
|
103
|
+
/** Comparisons a filter settled: the paths certainly did not change */
|
|
104
|
+
bloomDefinitelyNot: number;
|
|
105
|
+
/** Comparisons where a filter said the paths may have changed (trees compared then) */
|
|
106
|
+
bloomMaybe: number;
|
|
107
|
+
/** Of `bloomMaybe`, those where the trees did not differ */
|
|
108
|
+
bloomFalsePositive: number;
|
|
109
|
+
/** Comparisons of commits the graph has without a filter (its layer has none) */
|
|
110
|
+
bloomNotPresent: number;
|
|
111
|
+
/** Comparisons of a commit's trees with a parent's (or the empty tree), at the paths */
|
|
112
|
+
treeComparisons: number;
|
|
113
|
+
/** Tree entries looked up for those comparisons (each reads its tree, or finds it cached) */
|
|
114
|
+
treeEntryReads: number;
|
|
115
|
+
/** Commits the walk met (parsed, or seen as a parent) */
|
|
116
|
+
commitsWalked?: number;
|
|
117
|
+
/** Bytes the walk's table of commits takes (a few dozen per commit met) */
|
|
118
|
+
walkTableBytes?: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
15
121
|
/**
|
|
16
122
|
* Revision filter for LogCommand.
|
|
17
123
|
*
|
|
@@ -82,36 +188,61 @@ export enum RevFilter {
|
|
|
82
188
|
*/
|
|
83
189
|
export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
84
190
|
private startCommits: ObjectId[] = [];
|
|
85
|
-
|
|
191
|
+
/** The commits given, included and excluded, in the order given (git's pending list) */
|
|
192
|
+
private readonly pending: { id: ObjectId; exclude: boolean }[] = [];
|
|
86
193
|
private paths: string[] = [];
|
|
87
194
|
private excludePaths: string[] = [];
|
|
88
195
|
private maxCount?: number;
|
|
89
196
|
private skip = 0;
|
|
90
197
|
private includeAll = false;
|
|
198
|
+
/** Where `all()` puts the refs among the commits given (git's command-line order) */
|
|
199
|
+
private allAt = 0;
|
|
91
200
|
private firstParentOnly = false;
|
|
201
|
+
/** git's `simplify_history`: off with `--full-history` (and `-m`, `--diff-merges=separate`) */
|
|
202
|
+
private simplifyHistory = true;
|
|
92
203
|
private sinceTime?: number;
|
|
93
204
|
private untilTime?: number;
|
|
94
205
|
private authorPattern?: string;
|
|
95
206
|
private committerPattern?: string;
|
|
96
207
|
private revFilter = RevFilter.ALL;
|
|
208
|
+
private useBloomFilters = true;
|
|
209
|
+
private readonly statistics: LogPathStatistics = {
|
|
210
|
+
bloomDefinitelyNot: 0,
|
|
211
|
+
bloomMaybe: 0,
|
|
212
|
+
bloomFalsePositive: 0,
|
|
213
|
+
bloomNotPresent: 0,
|
|
214
|
+
treeComparisons: 0,
|
|
215
|
+
treeEntryReads: 0,
|
|
216
|
+
};
|
|
217
|
+
/** The commits of the last walk (for its statistics). */
|
|
218
|
+
private lastWalk: RevTable | undefined;
|
|
219
|
+
/** Set while {@link callBytes} collects the walk for its output */
|
|
220
|
+
private outputWalk: OutputWalk | undefined;
|
|
97
221
|
|
|
98
222
|
/**
|
|
99
223
|
* Add a starting commit for the log.
|
|
100
224
|
*
|
|
101
225
|
* Multiple start commits can be added - the log will include
|
|
102
|
-
* ancestors of all of them.
|
|
226
|
+
* ancestors of all of them. An annotated tag is walked from the commit it tags, as git
|
|
227
|
+
* peels it; with {@link all} the refs are walked besides (`git log --all <commit>`).
|
|
103
228
|
*
|
|
104
229
|
* @param commit ObjectId of commit to start from
|
|
105
230
|
*/
|
|
106
231
|
add(commit: ObjectId): this {
|
|
107
232
|
this.checkCallable();
|
|
108
233
|
this.startCommits.push(commit);
|
|
234
|
+
this.pending.push({ id: commit, exclude: false });
|
|
109
235
|
return this;
|
|
110
236
|
}
|
|
111
237
|
|
|
112
238
|
/**
|
|
113
239
|
* Filter commits to only those affecting the given path.
|
|
114
240
|
*
|
|
241
|
+
* The path is a git pathspec element, as `git log -- <path>` reads it: a path from the top
|
|
242
|
+
* of the repository (a directory names everything below it), with wildcards (`*`, `?`,
|
|
243
|
+
* `[...]`, matched as git's `git_fnmatch` does) and magic (`:(glob)`, `:(literal)`,
|
|
244
|
+
* `:(icase)`, `:(exclude)` or `:!`).
|
|
245
|
+
*
|
|
115
246
|
* @param path Repository-relative path to filter by
|
|
116
247
|
*/
|
|
117
248
|
addPath(path: string): this {
|
|
@@ -123,7 +254,9 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
123
254
|
/**
|
|
124
255
|
* Exclude commits that only affect the given path.
|
|
125
256
|
*
|
|
126
|
-
*
|
|
257
|
+
* The path is an `:(exclude)` pathspec element (`git log -- . ':!<path>'`): changes below
|
|
258
|
+
* it do not count when commits are compared with their parents. If a path is both added
|
|
259
|
+
* and excluded, the exclusion wins.
|
|
127
260
|
*
|
|
128
261
|
* @param path Repository-relative path to exclude
|
|
129
262
|
*/
|
|
@@ -156,13 +289,29 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
156
289
|
}
|
|
157
290
|
|
|
158
291
|
/**
|
|
159
|
-
* Include commits from all refs
|
|
292
|
+
* Include commits from all refs (`--all`): every ref under `refs/` in name order, then HEAD,
|
|
293
|
+
* as git's handle_refs adds them, where the call stands among {@link add}, {@link not} and
|
|
294
|
+
* {@link addRange} (the commits given so far come first).
|
|
160
295
|
*
|
|
161
296
|
* When set, starts from all refs instead of just HEAD.
|
|
162
297
|
*/
|
|
163
298
|
all(): this {
|
|
164
299
|
this.checkCallable();
|
|
165
300
|
this.includeAll = true;
|
|
301
|
+
this.allAt = this.pending.length;
|
|
302
|
+
return this;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* `--full-history`: a path-limited walk compares a merge with every parent and walks them
|
|
307
|
+
* all, even one the merge matches at the paths (git's `simplify_history` off; `git log -m`
|
|
308
|
+
* and `--diff-merges=separate` turn it off as well). Merges that match every relevant parent
|
|
309
|
+
* are still not shown, unless the output rewrites parents (`--graph`) and two of them are
|
|
310
|
+
* relevant.
|
|
311
|
+
*/
|
|
312
|
+
setFullHistory(fullHistory: boolean): this {
|
|
313
|
+
this.checkCallable();
|
|
314
|
+
this.simplifyHistory = !fullHistory;
|
|
166
315
|
return this;
|
|
167
316
|
}
|
|
168
317
|
|
|
@@ -187,7 +336,7 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
187
336
|
*/
|
|
188
337
|
not(commit: ObjectId): this {
|
|
189
338
|
this.checkCallable();
|
|
190
|
-
this.
|
|
339
|
+
this.pending.push({ id: commit, exclude: true });
|
|
191
340
|
return this;
|
|
192
341
|
}
|
|
193
342
|
|
|
@@ -260,6 +409,25 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
260
409
|
return this;
|
|
261
410
|
}
|
|
262
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Whether a path-limited walk asks the commit-graph's changed-path Bloom filters before it
|
|
414
|
+
* compares trees (default true, as git does whenever the graph has filters).
|
|
415
|
+
*/
|
|
416
|
+
setUseBloomFilters(use: boolean): this {
|
|
417
|
+
this.checkCallable();
|
|
418
|
+
this.useBloomFilters = use;
|
|
419
|
+
return this;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** What the path-limited walk did so far (see {@link LogPathStatistics}). */
|
|
423
|
+
getStatistics(): LogPathStatistics {
|
|
424
|
+
return {
|
|
425
|
+
...this.statistics,
|
|
426
|
+
commitsWalked: this.lastWalk?.size ?? 0,
|
|
427
|
+
walkTableBytes: this.lastWalk?.bytes ?? 0,
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
|
|
263
431
|
/**
|
|
264
432
|
* Add a commit range.
|
|
265
433
|
*
|
|
@@ -270,9 +438,11 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
270
438
|
* @param until Commits reachable from here are included (start point)
|
|
271
439
|
*/
|
|
272
440
|
addRange(since: ObjectId, until: ObjectId): this {
|
|
441
|
+
since = canonicalObjectId(since);
|
|
442
|
+
until = canonicalObjectId(until);
|
|
273
443
|
this.checkCallable();
|
|
274
|
-
this.excludeCommits.push(since);
|
|
275
444
|
this.startCommits.push(until);
|
|
445
|
+
this.pending.push({ id: since, exclude: true }, { id: until, exclude: false });
|
|
276
446
|
return this;
|
|
277
447
|
}
|
|
278
448
|
|
|
@@ -284,266 +454,1856 @@ export class LogCommand extends GitCommand<AsyncIterable<LogResult>> {
|
|
|
284
454
|
async call(): Promise<AsyncIterable<LogResult>> {
|
|
285
455
|
this.checkCallable();
|
|
286
456
|
this.setCallable(false);
|
|
457
|
+
// git_log_config ends in git_diff_ui_config: a diff.submodule without a value dies
|
|
458
|
+
readDiffSubmoduleConfig(this.workingCopy);
|
|
287
459
|
|
|
288
|
-
//
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
460
|
+
// the commits given, in order, the refs of `all()` where it was called; HEAD without
|
|
461
|
+
// either
|
|
462
|
+
const pending: { id: ObjectId; exclude: boolean }[] = [];
|
|
463
|
+
for (let i = 0; i <= this.pending.length; i++) {
|
|
464
|
+
if (this.includeAll && i === this.allAt) {
|
|
465
|
+
for (const id of await this.getAllRefs()) pending.push({ id, exclude: false });
|
|
466
|
+
}
|
|
467
|
+
const e = this.pending[i];
|
|
468
|
+
if (e) pending.push({ id: await this.peelToCommit(e.id), exclude: e.exclude });
|
|
469
|
+
}
|
|
470
|
+
if (this.startCommits.length === 0 && !this.includeAll) {
|
|
471
|
+
pending.push({ id: await this.resolveHead(), exclude: false });
|
|
297
472
|
}
|
|
473
|
+
return this.walk(pending);
|
|
474
|
+
}
|
|
298
475
|
|
|
299
|
-
|
|
476
|
+
/** The commit an annotated tag (or a chain of them) tags; any other id as it is. */
|
|
477
|
+
private async peelToCommit(start: ObjectId): Promise<ObjectId> {
|
|
478
|
+
const tags = this.tagsStore;
|
|
479
|
+
let id = start;
|
|
480
|
+
for (let depth = 0; depth < 32 && tags && (await tags.has(id).catch(() => false)); depth++) {
|
|
481
|
+
const tag = await tags.load(id).catch(() => undefined);
|
|
482
|
+
if (!tag) break;
|
|
483
|
+
id = tag.object;
|
|
484
|
+
}
|
|
485
|
+
return id;
|
|
300
486
|
}
|
|
301
487
|
|
|
302
488
|
/**
|
|
303
|
-
*
|
|
489
|
+
* The commits of `--all` (revision.c's handle_refs): each ref under `refs/` in name order
|
|
490
|
+
* (refs_for_each_ref, symbolic ones resolved), then HEAD (refs_head_ref); annotated tags
|
|
491
|
+
* peeled.
|
|
304
492
|
*/
|
|
305
493
|
private async getAllRefs(): Promise<ObjectId[]> {
|
|
306
|
-
const
|
|
494
|
+
const named: { name: Uint8Array; id: ObjectId }[] = [];
|
|
307
495
|
for await (const ref of this.refsStore.list()) {
|
|
308
|
-
if ("
|
|
309
|
-
|
|
310
|
-
|
|
496
|
+
if (!ref.name.startsWith("refs/")) continue;
|
|
497
|
+
let id = "objectId" in ref ? ref.objectId : undefined;
|
|
498
|
+
if (!id) id = (await this.refsStore.resolve(ref.name).catch(() => undefined))?.objectId;
|
|
499
|
+
if (id) named.push({ name: encodeGitPath(ref.name), id });
|
|
311
500
|
}
|
|
501
|
+
named.sort((a, b) => compareBytes(a.name, b.name));
|
|
502
|
+
const ids: ObjectId[] = [];
|
|
503
|
+
for (const { id } of named) ids.push(await this.peelToCommit(id));
|
|
504
|
+
const head = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
|
|
505
|
+
if (head) ids.push(await this.peelToCommit(head));
|
|
312
506
|
return ids;
|
|
313
507
|
}
|
|
314
508
|
|
|
315
509
|
/**
|
|
316
|
-
*
|
|
510
|
+
* The walk of `git log`, ported from git's revision.c. Commits come out newest first by
|
|
511
|
+
* committer date (equal dates in the order they were queued). With a pathspec, history is
|
|
512
|
+
* simplified as try_to_simplify_commit does it: a commit is compared with each parent at the
|
|
513
|
+
* paths; one that matches a relevant parent ("TREESAME") is not shown, and only that parent
|
|
514
|
+
* is walked further. A root commit is shown when it has any of the paths. Before comparing a
|
|
515
|
+
* commit with its first parent, the commit-graph's changed-path Bloom filter of the commit
|
|
516
|
+
* is asked (check_maybe_different_in_bloom_filter): when it says no path changed, no tree is
|
|
517
|
+
* read. Without a pathspec nothing is simplified (git's `revs->prune` is off).
|
|
518
|
+
*
|
|
519
|
+
* Without excluded commits the walk streams (get_revision_1). With some (`not`,
|
|
520
|
+
* `addRange`), it is limited first as limit_list does it: one date-ordered queue holds the
|
|
521
|
+
* included and the excluded commits, UNINTERESTING spreads to parents as commits are
|
|
522
|
+
* taken, a commit's relevance is judged with what is marked so far, `--since` marks older
|
|
523
|
+
* commits UNINTERESTING, and the walk stops once only uninteresting commits are left
|
|
524
|
+
* (still_interesting); what is shown is filtered by the final marks.
|
|
525
|
+
*
|
|
526
|
+
* The commits met are held in a `RevTable` (typed arrays, a few dozen bytes each); commits
|
|
527
|
+
* the commit-graph has are reached by their graph positions, without building their ids.
|
|
317
528
|
*/
|
|
318
|
-
private async *
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
529
|
+
private async *walk(pending: { id: ObjectId; exclude: boolean }[]): AsyncIterable<LogResult> {
|
|
530
|
+
const prune = this.paths.length > 0 || this.excludePaths.length > 0;
|
|
531
|
+
// a shallow commit has no parents (git's shallow grafts); the graph is off then
|
|
532
|
+
const shallowIds = (await this.refsStore.getShallow?.().catch(() => undefined)) ?? [];
|
|
533
|
+
const shallow = new Set(shallowIds);
|
|
534
|
+
// replace refs and grafts (git's parse_commit applies both; no commit-graph then)
|
|
535
|
+
const replacements = await this.objectReplacements();
|
|
536
|
+
this.markReplacementsRead();
|
|
537
|
+
// trees compared for paths read through replace refs too (read_object_file)
|
|
538
|
+
this.treeReplacements = replacements?.replace.size ? replacements.replace : undefined;
|
|
539
|
+
const graph =
|
|
540
|
+
shallow.size > 0 || replacements
|
|
541
|
+
? undefined
|
|
542
|
+
: await this.commits.commitGraph?.get().catch(() => undefined);
|
|
543
|
+
const pathspec = prune ? this.pathspec() : undefined;
|
|
544
|
+
const bloom =
|
|
545
|
+
pathspec && this.useBloomFilters ? this.bloomKeys(graph, pathspec.items) : undefined;
|
|
546
|
+
const bloomVersion = bloom ? this.changedPathsVersion() : -1;
|
|
547
|
+
const fast = pathspec?.literal;
|
|
548
|
+
const firstParentOnly = this.firstParentOnly;
|
|
549
|
+
const simplifyHistory = this.simplifyHistory;
|
|
550
|
+
/**
|
|
551
|
+
* Each merge's TREESAME to each parent (git's `treesame` decoration), kept when limiting
|
|
552
|
+
* can make it TREESAME later (limiting_can_increase_treesame: full history, a limited walk)
|
|
553
|
+
*/
|
|
554
|
+
const treesame = new Map<number, Uint8Array>();
|
|
555
|
+
let trackTreesame = false;
|
|
556
|
+
const t = new RevTable(graph);
|
|
557
|
+
this.lastWalk = t;
|
|
558
|
+
/** Raw commits read by `parse` (no graph), kept until shown: read once, not twice. */
|
|
559
|
+
const raw = new Map<number, Uint8Array>();
|
|
324
560
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (
|
|
330
|
-
|
|
561
|
+
/** git's parse_commit: tree, parents and date, from the graph when it has the commit */
|
|
562
|
+
const parse = async (n: number): Promise<boolean> => {
|
|
563
|
+
if (t.parsed(n)) return true;
|
|
564
|
+
const gpos = t.gpos[n] as number;
|
|
565
|
+
if (graph && gpos >= 0) {
|
|
566
|
+
let parents: number[] | undefined;
|
|
567
|
+
let date = 0;
|
|
568
|
+
try {
|
|
569
|
+
date = graph.commitTimeAt(gpos);
|
|
570
|
+
parents = graph.parentPositionsAt(gpos);
|
|
571
|
+
} catch {
|
|
572
|
+
// a corrupt record: the commit is read instead
|
|
573
|
+
parents = undefined;
|
|
574
|
+
}
|
|
575
|
+
if (parents) {
|
|
576
|
+
t.setParsed(n, date, true, undefined, parents.length);
|
|
577
|
+
for (let k = 0; k < parents.length; k++)
|
|
578
|
+
t.setParent(n, k, t.lookupPos(parents[k] as number));
|
|
579
|
+
return true;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
const id = t.idOf(n);
|
|
583
|
+
const header = await this.readCommitHeader(id, replacements);
|
|
584
|
+
if (!header) return false;
|
|
585
|
+
const parents = shallow.has(id) ? [] : header.parents;
|
|
586
|
+
t.setParsed(n, header.date, false, header.tree, parents.length);
|
|
587
|
+
for (let k = 0; k < parents.length; k++) t.setParent(n, k, t.lookup(parents[k] as ObjectId));
|
|
588
|
+
if (header.raw) raw.set(n, header.raw);
|
|
589
|
+
return true;
|
|
590
|
+
};
|
|
591
|
+
const relevant = (n: number) => (t.flag(n) & (UNINTERESTING | BOTTOM)) !== UNINTERESTING;
|
|
592
|
+
/** git's mark_parents_uninteresting: through the parents known (parsed) so far */
|
|
593
|
+
const markParentsUninteresting = (n: number): void => {
|
|
594
|
+
const stack: number[] = [];
|
|
595
|
+
const markOne = (p: number) => {
|
|
596
|
+
if (t.flag(p) & UNINTERESTING) return;
|
|
597
|
+
t.mark(p, UNINTERESTING);
|
|
598
|
+
for (let k = 0, c = t.parentCount(p); k < c; k++) stack.push(t.parent(p, k));
|
|
599
|
+
};
|
|
600
|
+
for (let k = 0, c = t.parentCount(n); k < c; k++) markOne(t.parent(n, k));
|
|
601
|
+
for (let p = stack.pop(); p !== undefined; p = stack.pop()) markOne(p);
|
|
602
|
+
};
|
|
603
|
+
const differs = (from: ObjectId | undefined, n: number, nth: number) =>
|
|
604
|
+
this.differsAtPaths(
|
|
605
|
+
from,
|
|
606
|
+
t.treeOf(n),
|
|
607
|
+
pathspec as TreePathspec,
|
|
608
|
+
fast,
|
|
609
|
+
nth === 0 ? bloom : undefined,
|
|
610
|
+
bloomVersion,
|
|
611
|
+
graph,
|
|
612
|
+
t.bloomPos(n),
|
|
613
|
+
);
|
|
614
|
+
/** git's try_to_simplify_commit (prune, dense, no show_pulls) */
|
|
615
|
+
const simplify = async (n: number): Promise<void> => {
|
|
616
|
+
if (!prune) return;
|
|
617
|
+
const count = t.parentCount(n);
|
|
618
|
+
if (count === 0) {
|
|
619
|
+
if (!(await differs(undefined, n, 0))) t.mark(n, TREESAME);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
let relevantParents = 0;
|
|
623
|
+
let relevantChange = false;
|
|
624
|
+
let irrelevantChange = false;
|
|
625
|
+
let ts: Uint8Array | undefined;
|
|
626
|
+
for (let nth = 0; nth < count; nth++) {
|
|
627
|
+
const p = t.parent(n, nth);
|
|
628
|
+
if (relevant(p)) relevantParents++;
|
|
629
|
+
if (nth === 1) {
|
|
630
|
+
if (firstParentOnly) break;
|
|
631
|
+
if (trackTreesame && !(t.flag(n) & UNINTERESTING)) {
|
|
632
|
+
ts = new Uint8Array(count);
|
|
633
|
+
treesame.set(n, ts);
|
|
634
|
+
if (!(irrelevantChange || relevantChange)) ts[0] = 1;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
if (!(await parse(p))) {
|
|
638
|
+
throw new GitApiError(`cannot simplify commit ${t.idOf(n)} (because of ${t.idOf(p)})`);
|
|
639
|
+
}
|
|
640
|
+
if (!(await differs(t.treeOf(p), n, nth))) {
|
|
641
|
+
// a merge with an irrelevant side that brought the whole change keeps its others;
|
|
642
|
+
// with the full history, every parent is kept
|
|
643
|
+
if (!simplifyHistory || !relevant(p)) {
|
|
644
|
+
if (ts) ts[nth] = 1;
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
t.keepOnlyParent(n, p);
|
|
648
|
+
t.mark(n, TREESAME);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (relevant(p)) relevantChange = true;
|
|
652
|
+
else irrelevantChange = true;
|
|
653
|
+
}
|
|
654
|
+
if (relevantParents ? !relevantChange : !irrelevantChange) t.mark(n, TREESAME);
|
|
655
|
+
};
|
|
656
|
+
/** git's process_parents */
|
|
657
|
+
const processParents = async (n: number, queue: CommitQueue<number>): Promise<void> => {
|
|
658
|
+
if (t.flag(n) & ADDED) return;
|
|
659
|
+
t.mark(n, ADDED);
|
|
660
|
+
if (t.flag(n) & UNINTERESTING) {
|
|
661
|
+
for (let k = 0, c = t.parentCount(n); k < c; k++) {
|
|
662
|
+
const p = t.parent(n, k);
|
|
663
|
+
t.mark(p, UNINTERESTING);
|
|
664
|
+
if (!(await parse(p))) continue;
|
|
665
|
+
if (t.parentCount(p) > 0) markParentsUninteresting(p);
|
|
666
|
+
if (t.flag(p) & SEEN) continue;
|
|
667
|
+
t.mark(p, SEEN);
|
|
668
|
+
queue.put(p, t.date(p));
|
|
669
|
+
}
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
await simplify(n);
|
|
673
|
+
for (let k = 0, c = t.parentCount(n); k < c; k++) {
|
|
674
|
+
const p = t.parent(n, k);
|
|
675
|
+
if (!(await parse(p))) {
|
|
676
|
+
throw new GitApiError(`Failed to traverse parents of commit ${t.idOf(n)}`);
|
|
677
|
+
}
|
|
678
|
+
if (!(t.flag(p) & SEEN)) {
|
|
679
|
+
t.mark(p, SEEN);
|
|
680
|
+
queue.put(p, t.date(p));
|
|
681
|
+
}
|
|
682
|
+
if (firstParentOnly) break;
|
|
331
683
|
}
|
|
684
|
+
};
|
|
685
|
+
/** git's get_commit_action (no parent rewriting: TREESAME commits are never shown) */
|
|
686
|
+
const shown = async (n: number, rewrite = false): Promise<LogResult | undefined> => {
|
|
687
|
+
const bytes = raw.get(n);
|
|
688
|
+
if (bytes) raw.delete(n);
|
|
689
|
+
if (t.flag(n) & UNINTERESTING) return undefined;
|
|
690
|
+
if (t.flag(n) & TREESAME) {
|
|
691
|
+
// with parents rewritten, a merge of two relevant lines ties the topology together
|
|
692
|
+
if (!rewrite) return undefined;
|
|
693
|
+
let relevantParents = 0;
|
|
694
|
+
for (let k = 0, c = t.parentCount(n); k < c; k++)
|
|
695
|
+
if (relevant(t.parent(n, k))) relevantParents++;
|
|
696
|
+
if (relevantParents < 2) return undefined;
|
|
697
|
+
}
|
|
698
|
+
if (this.untilTime !== undefined && t.date(n) > this.untilTime) return undefined;
|
|
699
|
+
const parents = t.parentCount(n);
|
|
700
|
+
if (this.revFilter === RevFilter.ONLY_MERGES && parents < 2) return undefined;
|
|
701
|
+
if (this.revFilter === RevFilter.NO_MERGES && parents > 1) return undefined;
|
|
702
|
+
const id = t.idOf(n);
|
|
703
|
+
const commit = bytes ? decodeCommit(bytes) : await this.walkCommits.load(id);
|
|
704
|
+
if (!commit) return undefined;
|
|
705
|
+
const grafted = bytes ? replacements?.grafts.get(id) : undefined;
|
|
706
|
+
if (grafted) commit.parents = [...grafted];
|
|
707
|
+
// a shallow commit is shown without parents (its diff against the empty tree)
|
|
708
|
+
if (shallow.has(id)) commit.parents = [];
|
|
709
|
+
if (this.authorPattern !== undefined && !this.matchesAuthor(commit)) return undefined;
|
|
710
|
+
if (this.committerPattern !== undefined && !this.matchesCommitter(commit)) return undefined;
|
|
711
|
+
return { ...commit, id };
|
|
712
|
+
};
|
|
332
713
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
714
|
+
// prepare_revision_walk: the flags of every argument first, then handle_commit in order
|
|
715
|
+
for (const e of pending) {
|
|
716
|
+
if (!e.exclude) continue;
|
|
717
|
+
const n = t.lookup(e.id);
|
|
718
|
+
t.mark(n, UNINTERESTING | BOTTOM);
|
|
719
|
+
}
|
|
720
|
+
const list: number[] = [];
|
|
721
|
+
let limited = false;
|
|
722
|
+
/** git's update_treesame: TREESAME again from the per-parent marks, relevance as it is now */
|
|
723
|
+
const updateTreesame = (n: number): void => {
|
|
724
|
+
const count = t.parentCount(n);
|
|
725
|
+
const st = treesame.get(n);
|
|
726
|
+
if (count < 2 || !st) return;
|
|
727
|
+
let relevantParents = 0;
|
|
728
|
+
let relevantChange = false;
|
|
729
|
+
let irrelevantChange = false;
|
|
730
|
+
for (let k = 0; k < count; k++) {
|
|
731
|
+
if (relevant(t.parent(n, k))) {
|
|
732
|
+
relevantChange ||= !st[k];
|
|
733
|
+
relevantParents++;
|
|
734
|
+
} else irrelevantChange ||= !st[k];
|
|
735
|
+
}
|
|
736
|
+
if (relevantParents ? relevantChange : irrelevantChange) t.unmark(n, TREESAME);
|
|
737
|
+
else t.mark(n, TREESAME);
|
|
738
|
+
};
|
|
739
|
+
for (const e of pending) {
|
|
740
|
+
const n = t.lookup(e.id);
|
|
741
|
+
if (!(await parse(n))) continue;
|
|
742
|
+
if (t.flag(n) & UNINTERESTING) {
|
|
743
|
+
markParentsUninteresting(n);
|
|
744
|
+
limited = true;
|
|
745
|
+
}
|
|
746
|
+
if (!(t.flag(n) & SEEN)) {
|
|
747
|
+
t.mark(n, SEEN);
|
|
748
|
+
list.push(n);
|
|
336
749
|
}
|
|
750
|
+
}
|
|
751
|
+
// commit_list_sort_by_date (stable), then into the date queue in that order
|
|
752
|
+
list.sort((a, b) => t.date(b) - t.date(a));
|
|
753
|
+
const queue = new CommitQueue<number>();
|
|
754
|
+
for (const n of list) queue.put(n, t.date(n));
|
|
337
755
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
756
|
+
let count = 0;
|
|
757
|
+
let skipped = 0;
|
|
758
|
+
// git's -n 0 reads nothing more in a streaming walk; a limited walk is done before
|
|
759
|
+
const none = this.maxCount !== undefined && this.maxCount <= 0;
|
|
760
|
+
const output = this.outputWalk;
|
|
761
|
+
// the output's walk is limited (git without generation numbers limits a topo walk)
|
|
762
|
+
trackTreesame = (limited || !!output) && prune && !simplifyHistory && !firstParentOnly;
|
|
763
|
+
if (!limited && !output) {
|
|
764
|
+
if (none) return;
|
|
765
|
+
// get_revision_1, streaming
|
|
766
|
+
for (let n = queue.get(); n !== undefined; n = queue.get()) {
|
|
767
|
+
// --since: older commits are dropped without walking their parents (max_age)
|
|
768
|
+
if (this.sinceTime !== undefined && t.date(n) < this.sinceTime) {
|
|
769
|
+
raw.delete(n);
|
|
342
770
|
continue;
|
|
343
771
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (commit
|
|
772
|
+
await processParents(n, queue);
|
|
773
|
+
const commit = await shown(n);
|
|
774
|
+
if (!commit) continue;
|
|
775
|
+
if (skipped < this.skip) {
|
|
776
|
+
skipped++;
|
|
347
777
|
continue;
|
|
348
778
|
}
|
|
779
|
+
yield commit;
|
|
780
|
+
if (this.maxCount !== undefined && ++count >= this.maxCount) return;
|
|
349
781
|
}
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
350
784
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
785
|
+
// limit_list
|
|
786
|
+
const newlist: number[] = [];
|
|
787
|
+
let date = Number.POSITIVE_INFINITY;
|
|
788
|
+
let slop = SLOP;
|
|
789
|
+
let interestingCache = -1;
|
|
790
|
+
/** git's everybody_uninteresting */
|
|
791
|
+
const everybodyUninteresting = (): boolean => {
|
|
792
|
+
if (interestingCache >= 0 && !(t.flag(interestingCache) & UNINTERESTING)) return false;
|
|
793
|
+
for (const n of queue.items()) {
|
|
794
|
+
if (t.flag(n) & UNINTERESTING) continue;
|
|
795
|
+
interestingCache = n;
|
|
796
|
+
return false;
|
|
797
|
+
}
|
|
798
|
+
return true;
|
|
799
|
+
};
|
|
800
|
+
/** git's still_interesting */
|
|
801
|
+
const stillInteresting = (): number => {
|
|
802
|
+
const head = queue.peek();
|
|
803
|
+
if (head === undefined) return 0;
|
|
804
|
+
if (date <= t.date(head)) return SLOP;
|
|
805
|
+
if (!everybodyUninteresting()) return SLOP;
|
|
806
|
+
return slop - 1;
|
|
807
|
+
};
|
|
808
|
+
for (let n = queue.get(); n !== undefined; n = queue.get()) {
|
|
809
|
+
// what is shown is read again at the end: a limited walk does not keep raw commits
|
|
810
|
+
raw.delete(n);
|
|
811
|
+
if (n === interestingCache) interestingCache = -1;
|
|
812
|
+
if (this.sinceTime !== undefined && t.date(n) < this.sinceTime) t.mark(n, UNINTERESTING);
|
|
813
|
+
await processParents(n, queue);
|
|
814
|
+
if (t.flag(n) & UNINTERESTING) {
|
|
815
|
+
markParentsUninteresting(n);
|
|
816
|
+
slop = stillInteresting();
|
|
817
|
+
if (slop) continue;
|
|
354
818
|
break;
|
|
355
819
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
820
|
+
if (this.untilTime !== undefined && t.date(n) > this.untilTime) continue;
|
|
821
|
+
date = t.date(n);
|
|
822
|
+
newlist.push(n);
|
|
823
|
+
}
|
|
824
|
+
// commits made TREESAME by parents that became UNINTERESTING
|
|
825
|
+
if (trackTreesame) {
|
|
826
|
+
for (const n of newlist) {
|
|
827
|
+
if (!(t.flag(n) & (UNINTERESTING | TREESAME))) updateTreesame(n);
|
|
360
828
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
829
|
+
}
|
|
830
|
+
raw.clear();
|
|
831
|
+
if (output) {
|
|
832
|
+
await this.finishOutputWalk(output, t, newlist, shown, relevant, parse);
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
if (none) return;
|
|
836
|
+
for (const n of newlist) {
|
|
837
|
+
const commit = await shown(n);
|
|
838
|
+
if (!commit) continue;
|
|
839
|
+
if (skipped < this.skip) {
|
|
840
|
+
skipped++;
|
|
364
841
|
continue;
|
|
365
842
|
}
|
|
843
|
+
yield commit;
|
|
844
|
+
if (this.maxCount !== undefined && ++count >= this.maxCount) return;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
366
847
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
848
|
+
/**
|
|
849
|
+
* The walk's commits for `git log`'s output (git's limited walk, then
|
|
850
|
+
* sort_in_topological_order when asked, then get_commit_action and rewrite_parents): the
|
|
851
|
+
* commits shown in order, with their parents as shown.
|
|
852
|
+
*/
|
|
853
|
+
private async finishOutputWalk(
|
|
854
|
+
output: OutputWalk,
|
|
855
|
+
t: RevTable,
|
|
856
|
+
newlist: number[],
|
|
857
|
+
shown: (n: number, rewrite?: boolean) => Promise<LogResult | undefined>,
|
|
858
|
+
relevant: (n: number) => boolean,
|
|
859
|
+
parse: (n: number) => Promise<boolean>,
|
|
860
|
+
): Promise<void> {
|
|
861
|
+
let order = newlist;
|
|
862
|
+
if (output.topo) {
|
|
863
|
+
// sort_in_topological_order (REV_SORT_IN_GRAPH_ORDER: a LIFO of the ready commits)
|
|
864
|
+
const indegree = new Map<number, number>();
|
|
865
|
+
for (const n of newlist) indegree.set(n, 1);
|
|
866
|
+
for (const n of newlist) {
|
|
867
|
+
for (let k = 0, c = t.parentCount(n); k < c; k++) {
|
|
868
|
+
const p = t.parent(n, k);
|
|
869
|
+
const d = indegree.get(p);
|
|
870
|
+
if (d) indegree.set(p, d + 1);
|
|
871
|
+
}
|
|
370
872
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
873
|
+
const stack: number[] = [];
|
|
874
|
+
for (const n of newlist) if (indegree.get(n) === 1) stack.push(n);
|
|
875
|
+
stack.reverse();
|
|
876
|
+
order = [];
|
|
877
|
+
for (let n = stack.pop(); n !== undefined; n = stack.pop()) {
|
|
878
|
+
for (let k = 0, c = t.parentCount(n); k < c; k++) {
|
|
879
|
+
const p = t.parent(n, k);
|
|
880
|
+
const d = indegree.get(p);
|
|
881
|
+
if (!d) continue;
|
|
882
|
+
indegree.set(p, d - 1);
|
|
883
|
+
if (d - 1 === 1) stack.push(p);
|
|
884
|
+
}
|
|
885
|
+
indegree.set(n, 0);
|
|
886
|
+
order.push(n);
|
|
375
887
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
888
|
+
}
|
|
889
|
+
const firstParentOnly = this.firstParentOnly;
|
|
890
|
+
/** revision.c's one_relevant_parent */
|
|
891
|
+
const oneRelevantParent = (n: number): number | undefined => {
|
|
892
|
+
const c = t.parentCount(n);
|
|
893
|
+
if (c === 0) return undefined;
|
|
894
|
+
if (firstParentOnly || c === 1) return t.parent(n, 0);
|
|
895
|
+
let found: number | undefined;
|
|
896
|
+
for (let k = 0; k < c; k++) {
|
|
897
|
+
const p = t.parent(n, k);
|
|
898
|
+
if (!relevant(p)) continue;
|
|
899
|
+
if (found !== undefined) return undefined;
|
|
900
|
+
found = p;
|
|
380
901
|
}
|
|
902
|
+
return found;
|
|
903
|
+
};
|
|
904
|
+
/** revision.c's rewrite_one: the parent shown in place of `p`; undefined to drop it */
|
|
905
|
+
const rewriteOne = (start: number): number | undefined => {
|
|
906
|
+
let p = start;
|
|
907
|
+
for (;;) {
|
|
908
|
+
if (t.flag(p) & UNINTERESTING) return p;
|
|
909
|
+
if (!(t.flag(p) & TREESAME)) return p;
|
|
910
|
+
if (t.parentCount(p) === 0) return undefined;
|
|
911
|
+
const next = oneRelevantParent(p);
|
|
912
|
+
if (next === undefined) return p;
|
|
913
|
+
p = next;
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
const prune = this.paths.length > 0 || this.excludePaths.length > 0;
|
|
917
|
+
/** Rewritten parents the walk never reached (only with `--first-parent`) */
|
|
918
|
+
const unwalked = new Set<number>();
|
|
919
|
+
for (const n of order) {
|
|
920
|
+
const commit = await shown(n, output.rewrite && prune);
|
|
921
|
+
if (!commit) continue;
|
|
922
|
+
let parents = commit.parents;
|
|
923
|
+
let savedParents: ObjectId[] | undefined;
|
|
924
|
+
if (output.rewrite && prune) {
|
|
925
|
+
// the parents before rewriting, which `--full-diff` diffs against (save_parents)
|
|
926
|
+
savedParents = [];
|
|
927
|
+
for (let k = 0, c = t.parentCount(n); k < c; k++) savedParents.push(t.idOf(t.parent(n, k)));
|
|
928
|
+
const ids: ObjectId[] = [];
|
|
929
|
+
for (let k = 0, c = t.parentCount(n); k < c; k++) {
|
|
930
|
+
const p = rewriteOne(t.parent(n, k));
|
|
931
|
+
if (p === undefined) continue;
|
|
932
|
+
if (!(t.flag(p) & SEEN)) unwalked.add(p);
|
|
933
|
+
const id = t.idOf(p);
|
|
934
|
+
// remove_duplicate_parents
|
|
935
|
+
if (!ids.includes(id)) ids.push(id);
|
|
936
|
+
}
|
|
937
|
+
parents = ids;
|
|
938
|
+
}
|
|
939
|
+
const { id, ...rest } = commit;
|
|
940
|
+
output.entries.push({ id, commit: rest, parents, ...(savedParents ? { savedParents } : {}) });
|
|
941
|
+
}
|
|
942
|
+
// graph.c's graph_is_interesting asks get_commit_action about a parent: one the walk
|
|
943
|
+
// never reached has no TREESAME or SHOWN flag, so only the filters can hide it (with
|
|
944
|
+
// `--first-parent` a merge whose first parent was rewritten away keeps a lane for it)
|
|
945
|
+
if (unwalked.size > 0) {
|
|
946
|
+
output.unwalkedShown = new Set();
|
|
947
|
+
for (const p of unwalked) {
|
|
948
|
+
if ((await parse(p)) && (await shown(p))) output.unwalkedShown.add(t.idOf(p));
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
381
952
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
953
|
+
/**
|
|
954
|
+
* The log printed as `git log <options>` prints it to a pipe (no colors, no pager): the
|
|
955
|
+
* walk set up by this command (start points, ranges, paths, `-n`, `--skip`, filters), each
|
|
956
|
+
* commit in the format asked for, with the graph and the diffs asked for. See
|
|
957
|
+
* {@link LogOutputOptions}.
|
|
958
|
+
*
|
|
959
|
+
* @example
|
|
960
|
+
* ```typescript
|
|
961
|
+
* await git.log().setMaxCount(2).callText({ pretty: "format:%h %s" });
|
|
962
|
+
* // "1a2b3c4 Second\n5d6e7f8 First"
|
|
963
|
+
* ```
|
|
964
|
+
*/
|
|
965
|
+
async callText(options: LogOutputOptions = {}): Promise<string> {
|
|
966
|
+
return decodeGitPath(await this.callBytes(options));
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/** {@link callText} as bytes (messages and file contents that are not UTF-8 kept as they are). */
|
|
970
|
+
async callBytes(options: LogOutputOptions = {}): Promise<Uint8Array> {
|
|
971
|
+
// one operation for the worktree: its attributes files (diff drivers) and configuration
|
|
972
|
+
// are read once for every commit's diff, as git keeps its attribute stack
|
|
973
|
+
const worktree = this.worktreeAccess;
|
|
974
|
+
if (worktree?.batch) return worktree.batch(() => this.printLog(options));
|
|
975
|
+
return this.printLog(options);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
private async printLog(options: LogOutputOptions): Promise<Uint8Array> {
|
|
979
|
+
// revision.c's setup_revisions: the graph cannot be reversed
|
|
980
|
+
if (options.graph && options.reverse) {
|
|
981
|
+
throw new IncompatibleOptionsError(
|
|
982
|
+
["--graph", "--reverse"],
|
|
983
|
+
"options '--graph' and '--reverse' cannot be used together",
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
const host = this.outputHost(options);
|
|
987
|
+
const paths = [...this.paths];
|
|
988
|
+
// the pathspec as git holds it: the excluded paths as `:(exclude)` elements, `.` when
|
|
989
|
+
// every element excludes
|
|
990
|
+
const pathspec = [...paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
|
|
991
|
+
if (paths.length === 0 && this.excludePaths.length > 0) pathspec.push(".");
|
|
992
|
+
const printer = new LogPrinter(host, options, {
|
|
993
|
+
interesting: (id) => shownIds.has(id) || unwalkedShown.has(id),
|
|
994
|
+
firstParentOnly: this.firstParentOnly,
|
|
995
|
+
paths: pathspec,
|
|
996
|
+
});
|
|
997
|
+
const follow = !printer.alwaysShowHeader;
|
|
998
|
+
const graph = !!options.graph;
|
|
999
|
+
const topo = graph || !!options.topoOrder;
|
|
1000
|
+
const maxCount = this.maxCount;
|
|
1001
|
+
const skip = this.skip;
|
|
1002
|
+
const simplifyHistory = this.simplifyHistory;
|
|
1003
|
+
if (printer.fullHistory) this.simplifyHistory = false;
|
|
1004
|
+
// --follow walks every commit: its path changes as it goes
|
|
1005
|
+
if (follow) this.paths = [];
|
|
1006
|
+
const shownIds = new Set<ObjectId>();
|
|
1007
|
+
const unwalkedShown = new Set<ObjectId>();
|
|
1008
|
+
let entries: LogOutputEntry[];
|
|
1009
|
+
if (topo) {
|
|
1010
|
+
this.outputWalk = { topo, rewrite: graph, entries: [] };
|
|
1011
|
+
for await (const _ of await this.call()) {
|
|
1012
|
+
// the output walk collects its commits
|
|
1013
|
+
}
|
|
1014
|
+
entries = this.outputWalk.entries;
|
|
1015
|
+
for (const id of this.outputWalk.unwalkedShown ?? []) unwalkedShown.add(id);
|
|
1016
|
+
this.outputWalk = undefined;
|
|
1017
|
+
for (const e of entries) shownIds.add(e.id);
|
|
1018
|
+
entries = entries.slice(skip);
|
|
1019
|
+
if (maxCount !== undefined && !follow) entries = entries.slice(0, Math.max(maxCount, 0));
|
|
1020
|
+
if (maxCount !== undefined && maxCount <= 0) entries = [];
|
|
1021
|
+
} else {
|
|
1022
|
+
// --follow counts the commits shown, not those walked; --reverse the newest walked
|
|
1023
|
+
if (follow && !options.reverse) this.maxCount = undefined;
|
|
1024
|
+
entries = [];
|
|
1025
|
+
for await (const c of await this.call()) {
|
|
1026
|
+
const { id, ...commit } = c;
|
|
1027
|
+
entries.push({ id, commit, parents: c.parents });
|
|
386
1028
|
}
|
|
1029
|
+
if (follow) this.maxCount = maxCount;
|
|
1030
|
+
}
|
|
1031
|
+
this.simplifyHistory = simplifyHistory;
|
|
1032
|
+
if (follow && options.reverse && maxCount !== undefined) {
|
|
1033
|
+
entries = entries.slice(0, Math.max(maxCount, 0));
|
|
1034
|
+
}
|
|
1035
|
+
if (options.reverse) entries.reverse();
|
|
1036
|
+
await printer.start();
|
|
1037
|
+
if (graph) {
|
|
1038
|
+
const parentsOf = new Map(entries.map((e) => [e.id, e.parents]));
|
|
1039
|
+
printer.useGraph((id) => parentsOf.get(id) ?? []);
|
|
1040
|
+
}
|
|
1041
|
+
let count = 0;
|
|
1042
|
+
// -n 0: nothing is walked
|
|
1043
|
+
if (maxCount !== undefined && maxCount <= 0) entries = [];
|
|
1044
|
+
const countShown = follow && maxCount !== undefined && !options.reverse;
|
|
1045
|
+
for (let k = 0; k < entries.length; k++) {
|
|
1046
|
+
const e = entries[k] as LogOutputEntry;
|
|
1047
|
+
const lookahead = entries.slice(k + 1, k + 3).map((x) => x.id);
|
|
1048
|
+
const shown = await printer.showCommit(e, lookahead);
|
|
1049
|
+
if (shown && countShown && ++count >= (maxCount as number)) break;
|
|
1050
|
+
}
|
|
1051
|
+
if (follow) this.paths = paths;
|
|
1052
|
+
return printer.result();
|
|
1053
|
+
}
|
|
387
1054
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
1055
|
+
/** What the log printer reads of the repository. */
|
|
1056
|
+
private outputHost(options: LogOutputOptions = {}): LogOutputHost {
|
|
1057
|
+
const config = RemoteConfigStore.from(this._workingCopy);
|
|
1058
|
+
const abbreviator = this.idAbbreviator();
|
|
1059
|
+
const abbrevs = new Map<string, string>();
|
|
1060
|
+
let notesTrees: Promise<NotesHandle[]> | undefined;
|
|
1061
|
+
let mailmap: Promise<Mailmap> | undefined;
|
|
1062
|
+
const trees = new OrderedMap<ObjectId, Promise<ObjectId>>();
|
|
1063
|
+
/** A commit's tree, as the walk parsed it (replace refs and grafts honoured) */
|
|
1064
|
+
const treeOf = (id: ObjectId): Promise<ObjectId> => {
|
|
1065
|
+
let tree = trees.get(id);
|
|
1066
|
+
if (!tree) {
|
|
1067
|
+
tree = (async () => {
|
|
1068
|
+
const header = await this.readCommitHeader(id, await this.objectReplacements());
|
|
1069
|
+
if (!header) throw new GitApiError(`could not parse commit ${id}`);
|
|
1070
|
+
return header.tree;
|
|
1071
|
+
})();
|
|
1072
|
+
trees.set(id, tree);
|
|
1073
|
+
if (trees.size > 4096) trees.deleteOldest();
|
|
391
1074
|
}
|
|
1075
|
+
return tree;
|
|
1076
|
+
};
|
|
1077
|
+
return {
|
|
1078
|
+
config: (key) => config.value(key),
|
|
1079
|
+
configAll: (key) => config.values(key),
|
|
1080
|
+
configNames: (section) => {
|
|
1081
|
+
const prefix = `${section.toLowerCase()}.`;
|
|
1082
|
+
const names = new Set<string>();
|
|
1083
|
+
for (const key of Object.keys(this._workingCopy.config ?? {})) {
|
|
1084
|
+
const parts = key.split(".");
|
|
1085
|
+
if (parts.length === 2 && key.toLowerCase().startsWith(prefix))
|
|
1086
|
+
names.add(parts[1] as string);
|
|
1087
|
+
}
|
|
1088
|
+
return [...names];
|
|
1089
|
+
},
|
|
1090
|
+
abbreviate: async (id, minLength) => {
|
|
1091
|
+
const key = `${id}:${minLength ?? ""}`;
|
|
1092
|
+
let short = abbrevs.get(key);
|
|
1093
|
+
if (short === undefined) {
|
|
1094
|
+
if (minLength === undefined) short = await abbreviator.abbreviate(id);
|
|
1095
|
+
else
|
|
1096
|
+
short = id.slice(0, (await abbreviator.lengths([id], minLength)).get(id) ?? minLength);
|
|
1097
|
+
abbrevs.set(key, short);
|
|
1098
|
+
}
|
|
1099
|
+
return short;
|
|
1100
|
+
},
|
|
1101
|
+
rawCommit: async (id) => {
|
|
1102
|
+
// the replacement's content, as git's commit buffer is (core.useReplaceRefs)
|
|
1103
|
+
const replace = (await this.objectReplacements())?.replace;
|
|
1104
|
+
const bytes = await this.readObjectBytes(replace?.size ? replacementOf(replace, id) : id);
|
|
1105
|
+
return bytes ? decodeGitPath(bytes) : undefined;
|
|
1106
|
+
},
|
|
1107
|
+
decorations: async (options) => {
|
|
1108
|
+
const replacements = await this.objectReplacements();
|
|
1109
|
+
const shallow = (await this.refsStore.getShallow?.().catch(() => undefined)) ?? [];
|
|
1110
|
+
const environment = hostEnvironmentOf(this._workingCopy);
|
|
1111
|
+
const objects = this._workingCopy.history?.objects;
|
|
1112
|
+
const tags = this.tagsStore;
|
|
1113
|
+
return loadRefDecorations({
|
|
1114
|
+
refs: this.refsStore,
|
|
1115
|
+
...(tags ? { tags } : {}),
|
|
1116
|
+
...(environment?.replaceRefBase !== undefined
|
|
1117
|
+
? { replaceRefBase: environment.replaceRefBase }
|
|
1118
|
+
: {}),
|
|
1119
|
+
useReplaceRefs: this.useReplaceRefs(),
|
|
1120
|
+
grafted: new Set([...(replacements?.grafts.keys() ?? []), ...shallow]),
|
|
1121
|
+
...(objects ? { hasObject: (id: ObjectId) => objects.has(id) } : {}),
|
|
1122
|
+
logOptions: {
|
|
1123
|
+
decorate: options.decorate,
|
|
1124
|
+
...(options.decorateRefs ? { decorateRefs: options.decorateRefs } : {}),
|
|
1125
|
+
...(options.decorateRefsExclude
|
|
1126
|
+
? { decorateRefsExclude: options.decorateRefsExclude }
|
|
1127
|
+
: {}),
|
|
1128
|
+
...(options.clearDecorations ? { clearDecorations: true } : {}),
|
|
1129
|
+
config,
|
|
1130
|
+
},
|
|
1131
|
+
});
|
|
1132
|
+
},
|
|
1133
|
+
notes: async (id) => {
|
|
1134
|
+
notesTrees ??= this.loadNotes(config, options);
|
|
1135
|
+
const out: { ref: string; text: string }[] = [];
|
|
1136
|
+
for (const { ref, tree } of await notesTrees) {
|
|
1137
|
+
const blob = await tree.get(id);
|
|
1138
|
+
if (!blob) continue;
|
|
1139
|
+
const bytes = await this.readBlob(blob);
|
|
1140
|
+
if (bytes) out.push({ ref, text: decodeGitPath(bytes) });
|
|
1141
|
+
}
|
|
1142
|
+
return out;
|
|
1143
|
+
},
|
|
1144
|
+
mailmap: () => {
|
|
1145
|
+
mailmap ??= this.loadMailmap(config);
|
|
1146
|
+
return mailmap;
|
|
1147
|
+
},
|
|
1148
|
+
diff: async (entry, parent, formats, options) => {
|
|
1149
|
+
// the trees themselves: a full id names its object, so no revision is looked up
|
|
1150
|
+
const diff = new DiffCommand(this._workingCopy)
|
|
1151
|
+
.setOldTree(parent ? await treeOf(parent) : this.objectFormat.emptyTreeId)
|
|
1152
|
+
.setNewTree(entry.commit.tree)
|
|
1153
|
+
.shareReadsOf(this);
|
|
1154
|
+
diff.setOptions({
|
|
1155
|
+
...this.diffOptions,
|
|
1156
|
+
...(options.statWidth !== undefined
|
|
1157
|
+
? { stat: { ...this.diffOptions.stat, width: options.statWidth } }
|
|
1158
|
+
: {}),
|
|
1159
|
+
...(options.abbrev !== undefined ? { abbrev: options.abbrev } : {}),
|
|
1160
|
+
});
|
|
1161
|
+
if (!options.fullDiff && options.follow === undefined) {
|
|
1162
|
+
const spec = [...this.paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
|
|
1163
|
+
if (spec.length > 0) diff.setPathspec(spec);
|
|
1164
|
+
}
|
|
1165
|
+
return diff.callFormats(formats, options.follow);
|
|
1166
|
+
},
|
|
1167
|
+
combinedDiff: (entry, options) => this.combinedDiff(entry, options),
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
private diffOptions: DiffTextOptions = {};
|
|
1172
|
+
|
|
1173
|
+
/** `log` stores no objects: its abbreviations read each loose fan-out directory once */
|
|
1174
|
+
protected override writesNoObjects(): boolean {
|
|
1175
|
+
return true;
|
|
1176
|
+
}
|
|
392
1177
|
|
|
393
|
-
|
|
394
|
-
|
|
1178
|
+
/** Options of the diffs {@link callBytes} prints (context, algorithm, `--stat` widths...) */
|
|
1179
|
+
setDiffOptions(options: DiffTextOptions): this {
|
|
1180
|
+
this.checkCallable();
|
|
1181
|
+
this.diffOptions = { ...this.diffOptions, ...options };
|
|
1182
|
+
return this;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
/** An object's content as stored (undefined when missing) */
|
|
1186
|
+
private async readObjectBytes(id: ObjectId): Promise<Uint8Array | undefined> {
|
|
1187
|
+
const objects = this._workingCopy.history?.objects;
|
|
1188
|
+
if (!objects) return undefined;
|
|
1189
|
+
try {
|
|
1190
|
+
const obj = await objects.get(id);
|
|
1191
|
+
if (!obj) return undefined;
|
|
1192
|
+
if (obj.bytes) return obj.bytes;
|
|
1193
|
+
const chunks: Uint8Array[] = [];
|
|
1194
|
+
for await (const c of obj.content) chunks.push(c);
|
|
1195
|
+
return concatBytes(chunks);
|
|
1196
|
+
} catch {
|
|
1197
|
+
return undefined;
|
|
395
1198
|
}
|
|
396
1199
|
}
|
|
397
1200
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
1201
|
+
private async readBlob(id: ObjectId): Promise<Uint8Array | undefined> {
|
|
1202
|
+
try {
|
|
1203
|
+
const content = await this.blobs.load(id);
|
|
1204
|
+
if (!content) return undefined;
|
|
1205
|
+
const chunks: Uint8Array[] = [];
|
|
1206
|
+
for await (const c of content) chunks.push(c);
|
|
1207
|
+
return concatBytes(chunks);
|
|
1208
|
+
} catch {
|
|
1209
|
+
return undefined;
|
|
404
1210
|
}
|
|
1211
|
+
}
|
|
405
1212
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
1213
|
+
/** The blobs of a tree, by path (empty for a missing tree) */
|
|
1214
|
+
private async flatTree(
|
|
1215
|
+
tree: ObjectId,
|
|
1216
|
+
prefix = "",
|
|
1217
|
+
out = new Map<string, { mode: number; id: ObjectId }>(),
|
|
1218
|
+
): Promise<Map<string, { mode: number; id: ObjectId }>> {
|
|
1219
|
+
if (tree === this.objectFormat.emptyTreeId) return out;
|
|
1220
|
+
for await (const entry of this.trees.loadTree(tree)) {
|
|
1221
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
1222
|
+
if ((entry.mode & 0o170000) === 0o040000) await this.flatTree(entry.id, path, out);
|
|
1223
|
+
// the mode as git's tree walk reads it (canon_mode), as the tree store reads it
|
|
1224
|
+
else out.set(path, { mode: entry.mode, id: entry.id });
|
|
411
1225
|
}
|
|
412
|
-
return
|
|
1226
|
+
return out;
|
|
413
1227
|
}
|
|
414
1228
|
|
|
415
1229
|
/**
|
|
416
|
-
*
|
|
1230
|
+
* combine-diff.c's diff_tree_combined for a merge: the paths that differ from every
|
|
1231
|
+
* parent (within the pathspec), each as a combined diff of the trees.
|
|
417
1232
|
*/
|
|
418
|
-
private
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
1233
|
+
private async combinedDiff(
|
|
1234
|
+
entry: LogOutputEntry,
|
|
1235
|
+
options: {
|
|
1236
|
+
dense: boolean;
|
|
1237
|
+
names?: "name-only" | "name-status";
|
|
1238
|
+
patch: boolean;
|
|
1239
|
+
follow?: string;
|
|
1240
|
+
parentPaths?: string[];
|
|
1241
|
+
parentStatus?: (string | undefined)[];
|
|
1242
|
+
},
|
|
1243
|
+
): Promise<{ paths: number; names: Uint8Array; patch: Uint8Array }> {
|
|
1244
|
+
const { dense } = options;
|
|
1245
|
+
/** A parent's entry for a path (under `--follow`, the path it had the file under) */
|
|
1246
|
+
const sideOf = (m: Map<string, { mode: number; id: ObjectId }>, k: number, path: string) =>
|
|
1247
|
+
m.get(options.parentPaths?.[k] ?? path);
|
|
1248
|
+
const result = await this.flatTree(entry.commit.tree);
|
|
1249
|
+
const parents: Map<string, { mode: number; id: ObjectId }>[] = [];
|
|
1250
|
+
for (const p of entry.parents) {
|
|
1251
|
+
const commit = await this.commits.load(p);
|
|
1252
|
+
parents.push(commit ? await this.flatTree(commit.tree) : new Map());
|
|
1253
|
+
}
|
|
1254
|
+
// --follow: the one path followed (the walk's pathspec is set aside then)
|
|
1255
|
+
const spec =
|
|
1256
|
+
options.follow !== undefined
|
|
1257
|
+
? [`:(literal)${options.follow}`]
|
|
1258
|
+
: [...this.paths, ...this.excludePaths.map((p) => `:(exclude)${p}`)];
|
|
1259
|
+
const items = spec.map((p) => parsePathspecItem(p, { attr: true }));
|
|
1260
|
+
if (items.length > 0 && items.every((i) => i.exclude)) items.push(parsePathspecItem("."));
|
|
1261
|
+
const all = new Set<string>(result.keys());
|
|
1262
|
+
for (const m of parents) for (const k of m.keys()) all.add(k);
|
|
1263
|
+
// `:(attr:...)`: the attributes of the paths, as the walk reads them
|
|
1264
|
+
if (items.some((i) => i.attr)) {
|
|
1265
|
+
await new PathspecAttributes(items, (path, names) => this.readAttributes(path, names)).load(
|
|
1266
|
+
all,
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
const differs = (a?: { mode: number; id: ObjectId }, b?: { mode: number; id: ObjectId }) =>
|
|
1270
|
+
!a || !b ? a !== b : a.id !== b.id || a.mode !== b.mode;
|
|
1271
|
+
const paths = [...all]
|
|
1272
|
+
.filter((path) => items.length === 0 || matchPathspec(items, path, 0) > 0)
|
|
1273
|
+
.filter((path) =>
|
|
1274
|
+
parents.every(
|
|
1275
|
+
(m, k) =>
|
|
1276
|
+
(options.parentPaths !== undefined && options.parentPaths[k] !== path) ||
|
|
1277
|
+
differs(sideOf(m, k, path), result.get(path)),
|
|
1278
|
+
),
|
|
1279
|
+
)
|
|
1280
|
+
.sort((a, b) => {
|
|
1281
|
+
const ea = encodeGitPath(a);
|
|
1282
|
+
const eb = encodeGitPath(b);
|
|
1283
|
+
for (let i = 0; i < ea.length && i < eb.length; i++) {
|
|
1284
|
+
if (ea[i] !== eb[i]) return (ea[i] as number) - (eb[i] as number);
|
|
1285
|
+
}
|
|
1286
|
+
return ea.length - eb.length;
|
|
1287
|
+
});
|
|
1288
|
+
const sink = new ByteSink();
|
|
1289
|
+
const quote =
|
|
1290
|
+
parseGitBool(RemoteConfigStore.from(this._workingCopy).value("core.quotePath")) ?? true;
|
|
1291
|
+
const names = new ByteSink();
|
|
1292
|
+
if (options.names) {
|
|
1293
|
+
for (const path of paths) {
|
|
1294
|
+
if (options.names === "name-status") {
|
|
1295
|
+
const r = result.get(path);
|
|
1296
|
+
parents.forEach((m, k) => {
|
|
1297
|
+
const found = options.parentStatus?.[k];
|
|
1298
|
+
names.text(found ?? (!sideOf(m, k, path) ? "A" : !r ? "D" : "M"));
|
|
1299
|
+
});
|
|
1300
|
+
names.text("\t");
|
|
1301
|
+
}
|
|
1302
|
+
names.text(`${quotePath(path, quote)}\n`);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
if (paths.length === 0 || !options.patch) {
|
|
1306
|
+
return { paths: paths.length, names: names.bytes(), patch: sink.bytes() };
|
|
1307
|
+
}
|
|
1308
|
+
const ids = new Set<string>([this.objectFormat.nullId]);
|
|
1309
|
+
for (const path of paths) {
|
|
1310
|
+
const r = result.get(path);
|
|
1311
|
+
if (r) ids.add(r.id);
|
|
1312
|
+
parents.forEach((m, k) => {
|
|
1313
|
+
const e = sideOf(m, k, path);
|
|
1314
|
+
if (e) ids.add(e.id);
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
// combine-diff.c's index lines take DEFAULT_ABBREV, whatever --abbrev says
|
|
1318
|
+
const lengths = await this.idAbbreviator().lengths(ids);
|
|
1319
|
+
const read = async (e?: { mode: number; id: ObjectId }) => {
|
|
1320
|
+
if (!e) return new Uint8Array(0);
|
|
1321
|
+
if ((e.mode & 0o170000) === 0o160000) return encodeGitPath(`Subproject commit ${e.id}\n`);
|
|
1322
|
+
return (await this.readBlob(e.id)) ?? new Uint8Array(0);
|
|
1323
|
+
};
|
|
1324
|
+
const config = RemoteConfigStore.from(this._workingCopy);
|
|
1325
|
+
const context = Number(config.value("diff.context") ?? 3);
|
|
1326
|
+
// combine-diff.c diffs each parent with the xpparam flags of the diff options
|
|
1327
|
+
// (opt->xdl_opts): the algorithm, the indent heuristic, the whitespace flags
|
|
1328
|
+
const d = this.diffOptions;
|
|
1329
|
+
const xdiffOptions = {
|
|
1330
|
+
algorithm: d.algorithm ?? configAlgorithm(config.value("diff.algorithm")) ?? "myers",
|
|
1331
|
+
indentHeuristic:
|
|
1332
|
+
d.indentHeuristic ?? parseGitBool(config.value("diff.indentHeuristic")) ?? true,
|
|
1333
|
+
histogramRediff: d.histogramRediff,
|
|
1334
|
+
legacyMinimal: d.legacyMinimal,
|
|
1335
|
+
ignoreWhitespace: d.ignoreWhitespace,
|
|
1336
|
+
ignoreWhitespaceChange: d.ignoreWhitespaceChange,
|
|
1337
|
+
ignoreWhitespaceAtEol: d.ignoreWhitespaceAtEol,
|
|
1338
|
+
ignoreCrAtEol: d.ignoreCrAtEol,
|
|
1339
|
+
ignoreBlankLines: d.ignoreBlankLines,
|
|
1340
|
+
} satisfies CombinedDiffOptions;
|
|
1341
|
+
for (const path of paths) {
|
|
1342
|
+
const r = result.get(path);
|
|
1343
|
+
const sides = [];
|
|
1344
|
+
for (let k = 0; k < parents.length; k++) {
|
|
1345
|
+
const e = sideOf(parents[k] as Map<string, { mode: number; id: ObjectId }>, k, path);
|
|
1346
|
+
sides.push({
|
|
1347
|
+
id: e?.id ?? this.objectFormat.nullId,
|
|
1348
|
+
mode: e?.mode ?? 0,
|
|
1349
|
+
content: await read(e),
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
writeCombinedDiff(
|
|
1353
|
+
sink,
|
|
1354
|
+
{
|
|
1355
|
+
path,
|
|
1356
|
+
parents: sides,
|
|
1357
|
+
result: {
|
|
1358
|
+
id: r?.id ?? this.objectFormat.nullId,
|
|
1359
|
+
mode: r?.mode ?? 0,
|
|
1360
|
+
content: await read(r),
|
|
1361
|
+
},
|
|
1362
|
+
},
|
|
1363
|
+
{
|
|
1364
|
+
...xdiffOptions,
|
|
1365
|
+
dense,
|
|
1366
|
+
workingTreeFile: false,
|
|
1367
|
+
context: this.diffOptions.context ?? (Number.isFinite(context) ? context : 3),
|
|
1368
|
+
abbreviate: (id) =>
|
|
1369
|
+
id.slice(0, this.diffOptions.fullIndex ? id.length : (lengths.get(id) ?? 7)),
|
|
1370
|
+
quotePath: quote,
|
|
1371
|
+
},
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
return { paths: paths.length, names: names.bytes(), patch: sink.bytes() };
|
|
422
1375
|
}
|
|
423
1376
|
|
|
424
1377
|
/**
|
|
425
|
-
*
|
|
1378
|
+
* notes.c's load_display_notes: the default notes ref (`GIT_NOTES_REF`, `core.notesRef`,
|
|
1379
|
+
* `refs/notes/commits`) and `GIT_NOTES_DISPLAY_REF` (else `notes.displayRef`), globs
|
|
1380
|
+
* expanded, unless only `--notes=<ref>` refs are asked for; then those refs.
|
|
426
1381
|
*/
|
|
427
|
-
private
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
1382
|
+
private async loadNotes(
|
|
1383
|
+
config: RemoteConfigStore,
|
|
1384
|
+
options: LogOutputOptions,
|
|
1385
|
+
): Promise<NotesHandle[]> {
|
|
1386
|
+
const ctx = this.notesContext();
|
|
1387
|
+
const extra = options.notesRefs ?? [];
|
|
1388
|
+
const refs: string[] = [];
|
|
1389
|
+
if (options.notes === true || extra.length === 0) {
|
|
1390
|
+
refs.push(defaultNotesRef(this._workingCopy));
|
|
1391
|
+
const env = notesEnvironmentOf(this._workingCopy).notesDisplayRef;
|
|
1392
|
+
if (env !== undefined) await addRefsFromColonSep(ctx, refs, env);
|
|
1393
|
+
else for (const r of config.values("notes.displayRef")) await addRefsByGlob(ctx, refs, r);
|
|
1394
|
+
}
|
|
1395
|
+
for (const r of extra) await addRefsByGlob(ctx, refs, expandNotesRef(r));
|
|
1396
|
+
const out: NotesHandle[] = [];
|
|
1397
|
+
for (const ref of refs) {
|
|
1398
|
+
try {
|
|
1399
|
+
out.push(await initNotes(ctx, ref, { combine: combineNotesIgnore }));
|
|
1400
|
+
} catch {
|
|
1401
|
+
// a ref that holds no tree-ish: git dies there, the log shows the others
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
return out;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
/** mailmap.c's read_mailmap: `.mailmap` (not in a bare repository), `mailmap.blob`, `mailmap.file` */
|
|
1408
|
+
private async loadMailmap(config: RemoteConfigStore): Promise<Mailmap> {
|
|
1409
|
+
const map = new Mailmap();
|
|
1410
|
+
const worktree = this.worktreeAccess;
|
|
1411
|
+
const bare = parseGitBool(config.value("core.bare")) ?? !worktree;
|
|
1412
|
+
if (!bare && worktree) {
|
|
1413
|
+
try {
|
|
1414
|
+
const entry = await worktree.getEntry(".mailmap");
|
|
1415
|
+
if (entry && !entry.isDirectory && (entry.mode & 0o170000) !== 0o120000) {
|
|
1416
|
+
const chunks: Uint8Array[] = [];
|
|
1417
|
+
for await (const c of worktree.readContent(".mailmap")) chunks.push(c);
|
|
1418
|
+
map.read(decodeGitPath(concatBytes(chunks)));
|
|
1419
|
+
}
|
|
1420
|
+
} catch {
|
|
1421
|
+
// no .mailmap
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
const blobName = config.value("mailmap.blob") ?? (bare ? "HEAD:.mailmap" : undefined);
|
|
1425
|
+
if (blobName) {
|
|
1426
|
+
const id = await this.revisionResolver()
|
|
1427
|
+
.resolve(blobName)
|
|
1428
|
+
.catch(() => undefined);
|
|
1429
|
+
const bytes = id ? await this.readBlob(id) : undefined;
|
|
1430
|
+
if (bytes) map.read(decodeGitPath(bytes));
|
|
1431
|
+
}
|
|
1432
|
+
const file = config.value("mailmap.file");
|
|
1433
|
+
if (file) {
|
|
1434
|
+
const environment = hostEnvironmentOf(this._workingCopy);
|
|
1435
|
+
const path = expandUserPath(file, environment);
|
|
1436
|
+
const bytes = path !== undefined ? await this.readMailmapFile(path, environment) : undefined;
|
|
1437
|
+
if (bytes) map.read(decodeGitPath(bytes));
|
|
1438
|
+
}
|
|
1439
|
+
return map;
|
|
431
1440
|
}
|
|
432
1441
|
|
|
433
1442
|
/**
|
|
434
|
-
*
|
|
1443
|
+
* `mailmap.file`, read as git reads it: through the host (a relative path from its current
|
|
1444
|
+
* directory). Without a host environment, a relative path is read from the worktree's top
|
|
1445
|
+
* (where git usually runs), and an absolute one inside the worktree through it as well.
|
|
435
1446
|
*/
|
|
436
|
-
private async
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
1447
|
+
private async readMailmapFile(
|
|
1448
|
+
path: string,
|
|
1449
|
+
environment: ReturnType<typeof hostEnvironmentOf>,
|
|
1450
|
+
): Promise<Uint8Array | undefined> {
|
|
1451
|
+
if (environment) return environment.readFile(path).catch(() => undefined);
|
|
1452
|
+
const worktree = "worktree" in this._workingCopy ? this.worktreeAccess : undefined;
|
|
1453
|
+
if (!worktree) return undefined;
|
|
1454
|
+
let relative = path;
|
|
1455
|
+
if (path.startsWith("/")) {
|
|
1456
|
+
const top = (worktree as { hostPath?: string }).hostPath?.replace(/\/+$/, "");
|
|
1457
|
+
if (!top || !path.startsWith(`${top}/`)) return undefined;
|
|
1458
|
+
relative = path.slice(top.length + 1);
|
|
440
1459
|
}
|
|
1460
|
+
if (relative.split("/").includes("..")) return undefined;
|
|
1461
|
+
try {
|
|
1462
|
+
const entry = await worktree.getEntry(relative);
|
|
1463
|
+
if (!entry || entry.isDirectory) return undefined;
|
|
1464
|
+
const chunks: Uint8Array[] = [];
|
|
1465
|
+
for await (const c of worktree.readContent(relative)) chunks.push(c);
|
|
1466
|
+
return concatBytes(chunks);
|
|
1467
|
+
} catch {
|
|
1468
|
+
return undefined;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
441
1471
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
1472
|
+
/**
|
|
1473
|
+
* The tree, parents and date of a commit (git's parse_commit_buffer), from its raw bytes
|
|
1474
|
+
* when the store gives them (kept in `raw` to be decoded whole if the commit is shown),
|
|
1475
|
+
* else from the commit store; undefined when it is missing or not a commit.
|
|
1476
|
+
*/
|
|
1477
|
+
private async readCommitHeader(
|
|
1478
|
+
id: ObjectId,
|
|
1479
|
+
replacements?: ObjectReplacements,
|
|
1480
|
+
): Promise<{ tree: ObjectId; parents: ObjectId[]; date: number; raw?: Uint8Array } | undefined> {
|
|
1481
|
+
if (replacements) {
|
|
1482
|
+
// the replacement's content read in place of the commit's; its grafted parents
|
|
1483
|
+
const read = replacementOf(replacements.replace, id);
|
|
1484
|
+
const header = await this.readCommitHeader(read);
|
|
1485
|
+
const grafted = replacements.grafts.get(id);
|
|
1486
|
+
return header && grafted ? { ...header, parents: [...grafted] } : header;
|
|
1487
|
+
}
|
|
1488
|
+
const objects = this._workingCopy.history?.objects;
|
|
1489
|
+
if (objects) {
|
|
1490
|
+
let obj: GitObject | undefined;
|
|
1491
|
+
let failed = false;
|
|
1492
|
+
try {
|
|
1493
|
+
const now = objects.getNow ? objects.getNow(id) : objects.get(id);
|
|
1494
|
+
obj = now instanceof Promise ? await now : now;
|
|
1495
|
+
} catch {
|
|
1496
|
+
obj = undefined;
|
|
1497
|
+
failed = true;
|
|
1498
|
+
}
|
|
1499
|
+
if (!obj && !failed) return undefined;
|
|
1500
|
+
if (obj?.bytes && obj.type === "commit") {
|
|
1501
|
+
try {
|
|
1502
|
+
const header = parseGraphCommit(obj.bytes, id, this.objectFormat);
|
|
1503
|
+
return { ...header, raw: obj.bytes };
|
|
1504
|
+
} catch {
|
|
1505
|
+
// read as the commit store reads it
|
|
1506
|
+
}
|
|
1507
|
+
} else if (obj) {
|
|
1508
|
+
await obj.content[Symbol.asyncIterator]().return?.();
|
|
1509
|
+
}
|
|
446
1510
|
}
|
|
447
|
-
const
|
|
1511
|
+
const commit = await this.commits.load(id).catch(() => undefined);
|
|
1512
|
+
if (!commit) return undefined;
|
|
1513
|
+
return { tree: commit.tree, parents: commit.parents, date: commit.committer.timestamp };
|
|
1514
|
+
}
|
|
448
1515
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
1516
|
+
/**
|
|
1517
|
+
* The pathspec of the walk: the paths added, the excluded ones as `:(exclude)` elements,
|
|
1518
|
+
* and `.` when every element excludes (git's parse_pathspec). `literal` holds each
|
|
1519
|
+
* element's path components when all are plain paths (no wildcard, no magic, no trailing
|
|
1520
|
+
* slash): those are compared by looking their entries up, without a tree diff.
|
|
1521
|
+
*/
|
|
1522
|
+
private pathspec(): TreePathspec & { literal: Uint8Array[][] | undefined } {
|
|
1523
|
+
const parse = (p: string) => parsePathspecItem(p, { attr: true });
|
|
1524
|
+
const items: PathspecItem[] = this.paths.map(parse);
|
|
1525
|
+
for (const p of this.excludePaths) items.push({ ...parse(p), exclude: true });
|
|
1526
|
+
if (items.every((i) => i.exclude)) items.push(parse("."));
|
|
1527
|
+
const plain = items.every(
|
|
1528
|
+
(i) =>
|
|
1529
|
+
!i.exclude &&
|
|
1530
|
+
!i.icase &&
|
|
1531
|
+
!i.attr &&
|
|
1532
|
+
i.prefix === undefined &&
|
|
1533
|
+
i.nowildcardLen === i.match.length &&
|
|
1534
|
+
!i.match.endsWith("/"),
|
|
1535
|
+
);
|
|
1536
|
+
return {
|
|
1537
|
+
...treePathspec(items),
|
|
1538
|
+
literal: plain
|
|
1539
|
+
? items.map((i) => pathParts(i.match).map((part) => encodeGitPath(part)))
|
|
1540
|
+
: undefined,
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
453
1543
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
1544
|
+
/** git's `commitGraph.changedPathsVersion` (-1: any; 0 when `readChangedPaths` is false). */
|
|
1545
|
+
private changedPathsVersion(): number {
|
|
1546
|
+
const raw = configValue(this._workingCopy, "commitGraph.changedPathsVersion");
|
|
1547
|
+
if (raw !== undefined && /^\s*[-+]?\d+\s*$/.test(raw)) return Number.parseInt(raw, 10);
|
|
1548
|
+
return configBool(this._workingCopy, "commitGraph.readChangedPaths", true) ? -1 : 0;
|
|
1549
|
+
}
|
|
457
1550
|
|
|
458
|
-
|
|
459
|
-
|
|
1551
|
+
/**
|
|
1552
|
+
* The Bloom keys of the pathspec, one vector per element (its path and each leading
|
|
1553
|
+
* directory, git's bloom_keyvec_new), hashed with the graph's settings; undefined when the
|
|
1554
|
+
* graph has no filters or the pathspec cannot use them (git's prepare_to_use_bloom_filter:
|
|
1555
|
+
* exclude or icase magic, or an element without a literal leading directory).
|
|
1556
|
+
*/
|
|
1557
|
+
private bloomKeys(
|
|
1558
|
+
graph: CommitGraph | undefined,
|
|
1559
|
+
items: PathspecItem[],
|
|
1560
|
+
): { settings: BloomFilterSettings; keys: number[][][] } | undefined {
|
|
1561
|
+
const settings = graph?.bloomSettings;
|
|
1562
|
+
if (!settings || pathspecForbidsBloom(items)) return undefined;
|
|
1563
|
+
const keys: number[][][] = [];
|
|
1564
|
+
for (const item of items) {
|
|
1565
|
+
const path = bloomPathOf(item);
|
|
1566
|
+
if (path === undefined) return undefined;
|
|
1567
|
+
const bytes = Uint8Array.from(path, (ch) => ch.charCodeAt(0));
|
|
1568
|
+
const vec = [bloomKey(bytes, settings)];
|
|
1569
|
+
for (let end = bytes.length - 1; end > 0; end--) {
|
|
1570
|
+
if (bytes[end] === 0x2f) vec.push(bloomKey(bytes.subarray(0, end), settings));
|
|
460
1571
|
}
|
|
1572
|
+
keys.push(vec);
|
|
461
1573
|
}
|
|
1574
|
+
return { settings, keys };
|
|
1575
|
+
}
|
|
462
1576
|
|
|
463
|
-
|
|
1577
|
+
private comparedPathspec?: TreePathspec & { literal: Uint8Array[][] | undefined };
|
|
1578
|
+
|
|
1579
|
+
/**
|
|
1580
|
+
* Whether trees `from` (undefined: the empty tree) and `to` differ at the paths added
|
|
1581
|
+
* ({@link addPath}, {@link excludePath}): the pruned tree comparison of this walk's
|
|
1582
|
+
* history simplification (git's rev_compare_tree, no Bloom filter asked), for the walks of
|
|
1583
|
+
* other commands (`git bisect`). Trees read are cached as the walk's are.
|
|
1584
|
+
*/
|
|
1585
|
+
async pathsDiffer(from: ObjectId | undefined, to: ObjectId): Promise<boolean> {
|
|
1586
|
+
this.comparedPathspec ??= this.pathspec();
|
|
1587
|
+
const ps = this.comparedPathspec;
|
|
1588
|
+
return this.differsAtPaths(from, to, ps, ps.literal, undefined, -1, undefined, -1);
|
|
464
1589
|
}
|
|
465
1590
|
|
|
466
1591
|
/**
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
1592
|
+
* Whether the paths differ between tree `from` (undefined: the empty tree) and tree `to` of
|
|
1593
|
+
* the commit at graph position `pos` (git's rev_compare_tree / rev_same_tree_as_empty):
|
|
1594
|
+
* with `bloom`, the commit's filter is asked first and a "certainly not" ends it. A filter
|
|
1595
|
+
* of another hash version than `commitGraph.changedPathsVersion` asks for is not there
|
|
1596
|
+
* (git's get_bloom_filter).
|
|
470
1597
|
*/
|
|
471
|
-
private async
|
|
472
|
-
|
|
473
|
-
|
|
1598
|
+
private async differsAtPaths(
|
|
1599
|
+
from: ObjectId | undefined,
|
|
1600
|
+
to: ObjectId,
|
|
1601
|
+
pathspec: TreePathspec,
|
|
1602
|
+
literal: Uint8Array[][] | undefined,
|
|
1603
|
+
bloom: { settings: BloomFilterSettings; keys: number[][][] } | undefined,
|
|
1604
|
+
bloomVersion: number,
|
|
1605
|
+
graph: CommitGraph | undefined,
|
|
1606
|
+
pos: number,
|
|
1607
|
+
): Promise<boolean> {
|
|
1608
|
+
const stats = this.statistics;
|
|
1609
|
+
let maybe = false;
|
|
1610
|
+
// a commit outside the graph is not asked (its generation is infinite)
|
|
1611
|
+
if (bloom && graph && pos >= 0) {
|
|
1612
|
+
const found = graph.bloomFilterAt(pos);
|
|
1613
|
+
const filter =
|
|
1614
|
+
found && (bloomVersion === -1 || found.settings.hashVersion === bloomVersion)
|
|
1615
|
+
? found
|
|
1616
|
+
: undefined;
|
|
1617
|
+
if (!filter) {
|
|
1618
|
+
stats.bloomNotPresent++;
|
|
1619
|
+
} else {
|
|
1620
|
+
// bloom_filter_contains_vec over each path: one "maybe" (or an empty filter) is enough
|
|
1621
|
+
let result = 0;
|
|
1622
|
+
for (let i = 0; result === 0 && i < bloom.keys.length; i++) {
|
|
1623
|
+
result = 1;
|
|
1624
|
+
for (const key of bloom.keys[i] as number[][]) {
|
|
1625
|
+
result = bloomFilterContains(filter.data, key);
|
|
1626
|
+
if (result <= 0) break;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
if (result === 0) {
|
|
1630
|
+
stats.bloomDefinitelyNot++;
|
|
1631
|
+
return false;
|
|
1632
|
+
}
|
|
1633
|
+
stats.bloomMaybe++;
|
|
1634
|
+
maybe = result === 1;
|
|
1635
|
+
}
|
|
474
1636
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (
|
|
478
|
-
|
|
479
|
-
|
|
1637
|
+
stats.treeComparisons++;
|
|
1638
|
+
let differs = false;
|
|
1639
|
+
if (literal) {
|
|
1640
|
+
for (const parts of literal) {
|
|
1641
|
+
if (await this.differsAtPath(from, to, parts, 0)) {
|
|
1642
|
+
differs = true;
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
} else {
|
|
1647
|
+
differs = await this.treesDiffer(from, to, pathspec, EMPTY_TREE);
|
|
480
1648
|
}
|
|
1649
|
+
if (maybe && !differs) stats.bloomFalsePositive++;
|
|
1650
|
+
return differs;
|
|
1651
|
+
}
|
|
481
1652
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
1653
|
+
/**
|
|
1654
|
+
* Whether trees `a` and `b` (undefined: empty) under `base` differ at a path in the
|
|
1655
|
+
* pathspec: git's pruned, recursive diff_tree_oid with `quick` (the first change ends it).
|
|
1656
|
+
* Entries are taken in git's tree order on both sides, those `tree_entry_interesting`
|
|
1657
|
+
* rejects skipped; a directory that differs, or is only on one side, is walked down.
|
|
1658
|
+
*/
|
|
1659
|
+
private async treesDiffer(
|
|
1660
|
+
a: ObjectId | undefined,
|
|
1661
|
+
b: ObjectId | undefined,
|
|
1662
|
+
ps: TreePathspec,
|
|
1663
|
+
base: Uint8Array,
|
|
1664
|
+
): Promise<boolean> {
|
|
1665
|
+
this.statistics.treeEntryReads++;
|
|
1666
|
+
// git reads the parent's tree, then the commit's
|
|
1667
|
+
const da = a ? await this.requireTree(a) : EMPTY_TREE;
|
|
1668
|
+
const db = b ? await this.requireTree(b) : EMPTY_TREE;
|
|
1669
|
+
const ca = new RawEntries(da, this.objectFormat.rawLength);
|
|
1670
|
+
const cb = new RawEntries(db, this.objectFormat.rawLength);
|
|
1671
|
+
// entries are matched where they lie in the tree's bytes: no name is decoded; an `:(attr)`
|
|
1672
|
+
// element waits for the attributes of a path, then the entry is matched again
|
|
1673
|
+
const skip = (c: RawEntries): Promise<void> | undefined => {
|
|
1674
|
+
while (!c.done) {
|
|
1675
|
+
c.read();
|
|
1676
|
+
const r = treeEntryInteresting(ps, c.d, c.nameStart, c.nul, c.mode, base);
|
|
1677
|
+
if (r === NEED_ATTRIBUTES) return this.loadAttributes(ps).then(() => skip(c));
|
|
1678
|
+
if (r === ALL_ENTRIES_NOT_INTERESTING) {
|
|
1679
|
+
c.at = c.d.length;
|
|
1680
|
+
return undefined;
|
|
1681
|
+
}
|
|
1682
|
+
if (r !== ENTRY_NOT_INTERESTING) return undefined;
|
|
1683
|
+
c.next();
|
|
1684
|
+
}
|
|
1685
|
+
return undefined;
|
|
1686
|
+
};
|
|
1687
|
+
for (;;) {
|
|
1688
|
+
const sa = skip(ca);
|
|
1689
|
+
if (sa) await sa;
|
|
1690
|
+
const sb = skip(cb);
|
|
1691
|
+
if (sb) await sb;
|
|
1692
|
+
if (ca.done && cb.done) return false;
|
|
1693
|
+
const cmp = ca.done ? 1 : cb.done ? -1 : ca.compare(cb);
|
|
1694
|
+
if (cmp === 0) {
|
|
1695
|
+
const same = ca.mode === cb.mode && ca.sameId(cb);
|
|
1696
|
+
if (!same) {
|
|
1697
|
+
if (!isTreeMode(ca.mode) || !isTreeMode(cb.mode)) return true;
|
|
1698
|
+
if (await this.treesDiffer(ca.id(), cb.id(), ps, ca.below(base))) return true;
|
|
1699
|
+
}
|
|
1700
|
+
ca.next();
|
|
1701
|
+
cb.next();
|
|
1702
|
+
continue;
|
|
1703
|
+
}
|
|
1704
|
+
// an entry on one side only: a file is a change, a directory is walked against nothing
|
|
1705
|
+
const one = cmp < 0 ? ca : cb;
|
|
1706
|
+
if (!isTreeMode(one.mode)) return true;
|
|
1707
|
+
const sub = one.id();
|
|
1708
|
+
const below =
|
|
1709
|
+
cmp < 0
|
|
1710
|
+
? await this.treesDiffer(sub, undefined, ps, one.below(base))
|
|
1711
|
+
: await this.treesDiffer(undefined, sub, ps, one.below(base));
|
|
1712
|
+
if (below) return true;
|
|
1713
|
+
one.next();
|
|
486
1714
|
}
|
|
1715
|
+
}
|
|
487
1716
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
1717
|
+
/**
|
|
1718
|
+
* The attributes `treeEntryInteresting` asks for (an `:(attr)` element), read as git's
|
|
1719
|
+
* match_pathspec_attrs reads them in `git log`: the check-in direction (the worktree's
|
|
1720
|
+
* `.gitattributes` first, then the index's) with no index read, so only the worktree's
|
|
1721
|
+
* files count, below `$GIT_DIR/info/attributes` and over `core.attributesFile` and the
|
|
1722
|
+
* system file; with an attribute source (`$GIT_ATTR_SOURCE`, `attr.tree`) the in-tree files
|
|
1723
|
+
* are its tree's. A bare repository has no in-tree files without one (git 2.56 reads none
|
|
1724
|
+
* without `attr.tree`): only the files outside the tree.
|
|
1725
|
+
*/
|
|
1726
|
+
private async loadAttributes(ps: TreePathspec): Promise<void> {
|
|
1727
|
+
const attributes = ps.attributes;
|
|
1728
|
+
const path = attributes?.pending;
|
|
1729
|
+
if (!attributes || path === undefined) return;
|
|
1730
|
+
attributes.pending = undefined;
|
|
1731
|
+
attributes.values.set(path, await this.readAttributes(path, attributes.names));
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
/** The attributes `names` of `path` as {@link loadAttributes} reads them. */
|
|
1735
|
+
private async readAttributes(
|
|
1736
|
+
path: string,
|
|
1737
|
+
names: readonly string[],
|
|
1738
|
+
): Promise<Map<string, PathspecAttributeValue>> {
|
|
1739
|
+
// a bare repository's working copy refuses its worktree: asked without touching it
|
|
1740
|
+
const worktree = "worktree" in this._workingCopy ? this.worktreeAccess : undefined;
|
|
1741
|
+
if (!worktree) return this.bareAttributes().get(path, names);
|
|
1742
|
+
const filter = worktree.contentFilter as
|
|
1743
|
+
| {
|
|
1744
|
+
attributes?(
|
|
1745
|
+
path: string,
|
|
1746
|
+
names: readonly string[],
|
|
1747
|
+
direction?: ContentAttributesContext,
|
|
1748
|
+
): Promise<Map<string, PathspecAttributeValue>>;
|
|
1749
|
+
}
|
|
1750
|
+
| undefined;
|
|
1751
|
+
if (!filter?.attributes)
|
|
1752
|
+
throw new GitApiError("pathspec magic 'attr' needs the attributes of a worktree");
|
|
1753
|
+
return filter.attributes(path, names, { direction: "checkin", index: NO_INDEX });
|
|
1754
|
+
}
|
|
492
1755
|
|
|
493
|
-
|
|
494
|
-
const parentId = entryInParent?.objectId;
|
|
1756
|
+
private bareResolver?: AttributesResolver;
|
|
495
1757
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
1758
|
+
/** The attributes of a bare repository (see {@link bareAttributesResolver}). */
|
|
1759
|
+
private bareAttributes(): AttributesResolver {
|
|
1760
|
+
this.bareResolver ??= bareAttributesResolver({
|
|
1761
|
+
workingCopy: this._workingCopy,
|
|
1762
|
+
trees: this.trees,
|
|
1763
|
+
blobs: this.blobs,
|
|
1764
|
+
revisions: () => this.revisionResolver(),
|
|
1765
|
+
});
|
|
1766
|
+
return this.bareResolver;
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
/** A tree's raw bytes; git's "unable to read tree" when it is missing. */
|
|
1770
|
+
private async requireTree(id: ObjectId): Promise<Uint8Array> {
|
|
1771
|
+
const raw = await this.rawTree(id);
|
|
1772
|
+
if (raw instanceof Uint8Array) return raw;
|
|
1773
|
+
if (raw === null) {
|
|
1774
|
+
// no raw object store: the entries are encoded back
|
|
1775
|
+
const entries = await this.trees.load(id);
|
|
1776
|
+
if (!entries) throw new GitApiError(`unable to read tree (${id})`);
|
|
1777
|
+
const parts: Uint8Array[] = [];
|
|
1778
|
+
for await (const e of entries) {
|
|
1779
|
+
parts.push(
|
|
1780
|
+
NAME_ENCODER.encode(`${e.mode.toString(8)} `),
|
|
1781
|
+
encodeGitPath(e.name),
|
|
1782
|
+
new Uint8Array(1),
|
|
1783
|
+
hexToBytes(e.id),
|
|
1784
|
+
);
|
|
500
1785
|
}
|
|
1786
|
+
return concatBytes(parts);
|
|
501
1787
|
}
|
|
1788
|
+
throw new GitApiError(`unable to read tree (${id})`);
|
|
1789
|
+
}
|
|
502
1790
|
|
|
503
|
-
|
|
1791
|
+
/**
|
|
1792
|
+
* Whether the entries at `parts[i..]` below trees `a` and `b` differ (git's pathspec match:
|
|
1793
|
+
* the path itself, or anything below it). Equal subtrees end the walk down.
|
|
1794
|
+
*/
|
|
1795
|
+
private async differsAtPath(
|
|
1796
|
+
a: ObjectId | undefined,
|
|
1797
|
+
b: ObjectId | undefined,
|
|
1798
|
+
parts: Uint8Array[],
|
|
1799
|
+
i: number,
|
|
1800
|
+
): Promise<boolean> {
|
|
1801
|
+
// the whole tree (`.`, `:/`): a root commit compares with the empty tree, as in git
|
|
1802
|
+
const empty = this.objectFormat.emptyTreeId;
|
|
1803
|
+
if (parts.length === 0) return (a ?? empty) !== (b ?? empty);
|
|
1804
|
+
const name = parts[i] as Uint8Array;
|
|
1805
|
+
const ea = a ? await this.entryOf(a, name) : undefined;
|
|
1806
|
+
const eb = b ? await this.entryOf(b, name) : undefined;
|
|
1807
|
+
if (!ea && !eb) return false;
|
|
1808
|
+
if (ea && eb && ea.id === eb.id && canonTreeMode(ea.mode) === canonTreeMode(eb.mode)) {
|
|
1809
|
+
return false;
|
|
1810
|
+
}
|
|
1811
|
+
if (i === parts.length - 1) return true;
|
|
1812
|
+
const ta = ea && isTreeMode(ea.mode) ? ea.id : undefined;
|
|
1813
|
+
const tb = eb && isTreeMode(eb.mode) ? eb.id : undefined;
|
|
1814
|
+
if (!ta && !tb) return false;
|
|
1815
|
+
return this.differsAtPath(ta, tb, parts, i + 1);
|
|
504
1816
|
}
|
|
505
1817
|
|
|
506
1818
|
/**
|
|
507
|
-
*
|
|
1819
|
+
* Entry `name` of tree `tree`: found in the tree's raw bytes (no entry is decoded but the
|
|
1820
|
+
* one asked for) when the store gives them, else through the tree store.
|
|
508
1821
|
*/
|
|
509
|
-
private async
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
1822
|
+
private async entryOf(
|
|
1823
|
+
tree: ObjectId,
|
|
1824
|
+
name: Uint8Array,
|
|
1825
|
+
): Promise<{ id: ObjectId; mode: number } | undefined> {
|
|
1826
|
+
this.statistics.treeEntryReads++;
|
|
1827
|
+
const raw = await this.rawTree(tree);
|
|
1828
|
+
if (raw === null) return this.trees.getEntry(tree, NAME_DECODER.decode(name));
|
|
1829
|
+
if (raw === undefined) throw new GitApiError(`unable to read tree (${tree})`);
|
|
1830
|
+
return findRawEntry(raw, name, this.objectFormat.rawLength);
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
/** The replace refs a walk's tree reads follow; undefined without any. */
|
|
1834
|
+
private treeReplacements?: ReadonlyMap<ObjectId, ObjectId>;
|
|
1835
|
+
|
|
1836
|
+
/** Raw trees read lately, most recently used last: a commit's trees are its child's parent trees. */
|
|
1837
|
+
private readonly rawTrees = new OrderedMap<ObjectId, Uint8Array>();
|
|
1838
|
+
private rawTreeBytes = 0;
|
|
1839
|
+
|
|
1840
|
+
/** The raw bytes of a tree; undefined when it is missing, null without a raw object store. */
|
|
1841
|
+
private async rawTree(tree: ObjectId): Promise<Uint8Array | undefined | null> {
|
|
1842
|
+
const id = this.treeReplacements ? replacementOf(this.treeReplacements, tree) : tree;
|
|
1843
|
+
// the empty tree, which a store need not hold
|
|
1844
|
+
if (id === this.objectFormat.emptyTreeId) return EMPTY_TREE;
|
|
1845
|
+
const cached = this.rawTrees.get(id);
|
|
1846
|
+
if (cached) {
|
|
1847
|
+
this.rawTrees.delete(id);
|
|
1848
|
+
this.rawTrees.set(id, cached);
|
|
1849
|
+
return cached;
|
|
1850
|
+
}
|
|
1851
|
+
const objects = this._workingCopy.history?.objects;
|
|
1852
|
+
if (!objects) return null;
|
|
1853
|
+
let obj: GitObject | undefined;
|
|
1854
|
+
try {
|
|
1855
|
+
const now = objects.getNow ? objects.getNow(id) : objects.get(id);
|
|
1856
|
+
obj = now instanceof Promise ? await now : now;
|
|
1857
|
+
} catch {
|
|
1858
|
+
return null;
|
|
1859
|
+
}
|
|
1860
|
+
if (!obj) return undefined;
|
|
1861
|
+
if (obj.type !== "tree") {
|
|
1862
|
+
await obj.content[Symbol.asyncIterator]().return?.();
|
|
1863
|
+
return null;
|
|
515
1864
|
}
|
|
516
|
-
|
|
1865
|
+
let bytes = obj.bytes;
|
|
1866
|
+
if (!bytes) {
|
|
1867
|
+
const chunks: Uint8Array[] = [];
|
|
1868
|
+
for await (const c of obj.content) chunks.push(c);
|
|
1869
|
+
bytes = concatBytes(chunks);
|
|
1870
|
+
}
|
|
1871
|
+
this.rawTrees.set(id, bytes);
|
|
1872
|
+
this.rawTreeBytes += bytes.length;
|
|
1873
|
+
while (this.rawTrees.size > RAW_TREE_CACHE || this.rawTreeBytes > RAW_TREE_CACHE_BYTES) {
|
|
1874
|
+
const oldest = this.rawTrees.oldestKey() as ObjectId;
|
|
1875
|
+
if (oldest === id) break;
|
|
1876
|
+
this.rawTreeBytes -= (this.rawTrees.get(oldest) as Uint8Array).length;
|
|
1877
|
+
this.rawTrees.delete(oldest);
|
|
1878
|
+
}
|
|
1879
|
+
return bytes;
|
|
517
1880
|
}
|
|
518
1881
|
|
|
519
1882
|
/**
|
|
520
|
-
*
|
|
1883
|
+
* Check if commit author matches the filter pattern.
|
|
521
1884
|
*/
|
|
522
|
-
private
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
let currentTreeId = treeId;
|
|
1885
|
+
private matchesAuthor(commit: Commit): boolean {
|
|
1886
|
+
if (!this.authorPattern) return true;
|
|
1887
|
+
const authorStr = `${commit.author.name} <${commit.author.email}>`.toLowerCase();
|
|
1888
|
+
return authorStr.includes(this.authorPattern);
|
|
1889
|
+
}
|
|
528
1890
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
1891
|
+
/**
|
|
1892
|
+
* Check if commit committer matches the filter pattern.
|
|
1893
|
+
*/
|
|
1894
|
+
private matchesCommitter(commit: Commit): boolean {
|
|
1895
|
+
if (!this.committerPattern) return true;
|
|
1896
|
+
const committerStr = `${commit.committer.name} <${commit.committer.email}>`.toLowerCase();
|
|
1897
|
+
return committerStr.includes(this.committerPattern);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
532
1900
|
|
|
533
|
-
|
|
1901
|
+
const isTreeMode = (mode: number) => (mode & 0o170000) === 0o040000;
|
|
534
1902
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
1903
|
+
const NAME_ENCODER = new TextEncoder();
|
|
1904
|
+
const NAME_DECODER = new TextDecoder();
|
|
538
1905
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
1906
|
+
/** Raw trees a path-limited walk keeps. */
|
|
1907
|
+
const RAW_TREE_CACHE = 512;
|
|
542
1908
|
|
|
543
|
-
|
|
544
|
-
|
|
1909
|
+
/** The bytes of raw trees a path-limited walk keeps at most (besides the one just read). */
|
|
1910
|
+
const RAW_TREE_CACHE_BYTES = 32 * 1024 * 1024;
|
|
1911
|
+
|
|
1912
|
+
const EMPTY_TREE = new Uint8Array(0);
|
|
1913
|
+
|
|
1914
|
+
// revision.c's object flags, as the walk uses them
|
|
1915
|
+
const UNINTERESTING = 1 << 1;
|
|
1916
|
+
const BOTTOM = 1 << 2;
|
|
1917
|
+
const SEEN = 1 << 3;
|
|
1918
|
+
const ADDED = 1 << 4;
|
|
1919
|
+
const TREESAME = 1 << 5;
|
|
1920
|
+
|
|
1921
|
+
/** How many extra uninteresting commits limit_list looks at (git's SLOP). */
|
|
1922
|
+
const SLOP = 5;
|
|
1923
|
+
|
|
1924
|
+
/**
|
|
1925
|
+
* The commits a walk meets, as revision.c's object table holds them: flags, and once parsed
|
|
1926
|
+
* the date, the parents and (outside the commit-graph) the tree. Each commit is a number
|
|
1927
|
+
* indexing typed arrays, a few dozen bytes per commit instead of an object with its id, tree
|
|
1928
|
+
* and parent array. Commits the graph has are found by graph position (`lookupPos`), their
|
|
1929
|
+
* ids and trees read from the graph when needed; others by id.
|
|
1930
|
+
*/
|
|
1931
|
+
class RevTable {
|
|
1932
|
+
/** commits held */
|
|
1933
|
+
size = 0;
|
|
1934
|
+
/** revision.c flags (UNINTERESTING, SEEN, ...) */
|
|
1935
|
+
flags = new Uint8Array(INITIAL_REVS);
|
|
1936
|
+
/** committer dates (seconds) */
|
|
1937
|
+
private dates = new Float64Array(INITIAL_REVS);
|
|
1938
|
+
/** position in the commit-graph, -1 for a commit it does not have */
|
|
1939
|
+
gpos = new Int32Array(INITIAL_REVS);
|
|
1940
|
+
/** where the parents start in `pool`, once parsed */
|
|
1941
|
+
private parentAt = new Int32Array(INITIAL_REVS);
|
|
1942
|
+
/** how many parents, -1 before the commit is parsed */
|
|
1943
|
+
private parents = new Int32Array(INITIAL_REVS);
|
|
1944
|
+
/** every parsed commit's parents, in turn */
|
|
1945
|
+
private pool = new Int32Array(INITIAL_REVS);
|
|
1946
|
+
private poolUsed = 0;
|
|
1947
|
+
/** ids known without the graph (looked up by id), by commit */
|
|
1948
|
+
private readonly ids: (ObjectId | undefined)[] = [];
|
|
1949
|
+
/** trees of commits parsed outside the graph, by commit */
|
|
1950
|
+
private readonly trees: (ObjectId | undefined)[] = [];
|
|
1951
|
+
/** commits outside the graph, by id */
|
|
1952
|
+
private readonly byId = new Map<ObjectId, number>();
|
|
1953
|
+
/** commit + 1 by graph position (0: not met yet) */
|
|
1954
|
+
private readonly byPos: Int32Array | undefined;
|
|
1955
|
+
|
|
1956
|
+
constructor(private readonly graph: CommitGraph | undefined) {
|
|
1957
|
+
this.byPos = graph ? new Int32Array(graph.size) : undefined;
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
/** Bytes the table's arrays take (the ids and trees kept besides them not counted). */
|
|
1961
|
+
get bytes(): number {
|
|
1962
|
+
return (
|
|
1963
|
+
this.flags.byteLength +
|
|
1964
|
+
this.dates.byteLength +
|
|
1965
|
+
this.gpos.byteLength +
|
|
1966
|
+
this.parentAt.byteLength +
|
|
1967
|
+
this.parents.byteLength +
|
|
1968
|
+
this.pool.byteLength +
|
|
1969
|
+
(this.byPos?.byteLength ?? 0)
|
|
1970
|
+
);
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
/** The commit `id`, added when first met (git's lookup_commit). */
|
|
1974
|
+
lookup(id: ObjectId): number {
|
|
1975
|
+
const known = this.byId.get(id);
|
|
1976
|
+
if (known !== undefined) return known;
|
|
1977
|
+
const pos = this.graph ? this.graph.position(id) : -1;
|
|
1978
|
+
if (pos >= 0) {
|
|
1979
|
+
const n = this.lookupPos(pos);
|
|
1980
|
+
this.ids[n] = id;
|
|
1981
|
+
return n;
|
|
545
1982
|
}
|
|
1983
|
+
const n = this.add(-1);
|
|
1984
|
+
this.ids[n] = id;
|
|
1985
|
+
this.byId.set(id, n);
|
|
1986
|
+
return n;
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
/** The commit at graph position `pos`, added when first met. */
|
|
1990
|
+
lookupPos(pos: number): number {
|
|
1991
|
+
const byPos = this.byPos as Int32Array;
|
|
1992
|
+
const known = (byPos[pos] as number) - 1;
|
|
1993
|
+
if (known >= 0) return known;
|
|
1994
|
+
const n = this.add(pos);
|
|
1995
|
+
byPos[pos] = n + 1;
|
|
1996
|
+
return n;
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
idOf(n: number): ObjectId {
|
|
2000
|
+
return this.ids[n] ?? (this.graph as CommitGraph).idAt(this.gpos[n] as number);
|
|
2001
|
+
}
|
|
546
2002
|
|
|
2003
|
+
flag(n: number): number {
|
|
2004
|
+
return this.flags[n] as number;
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
mark(n: number, flags: number): void {
|
|
2008
|
+
this.flags[n] = (this.flags[n] as number) | flags;
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
unmark(n: number, flags: number): void {
|
|
2012
|
+
this.flags[n] = (this.flags[n] as number) & ~flags;
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
parsed(n: number): boolean {
|
|
2016
|
+
return (this.parents[n] as number) >= 0;
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
date(n: number): number {
|
|
2020
|
+
return this.dates[n] as number;
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
/** The tree of a parsed commit. */
|
|
2024
|
+
treeOf(n: number): ObjectId {
|
|
2025
|
+
if ((this.flags[n] as number) & GRAPH_PARSED)
|
|
2026
|
+
return (this.graph as CommitGraph).treeAt(this.gpos[n] as number);
|
|
2027
|
+
return this.trees[n] as ObjectId;
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
/** The graph position of a commit parsed from the graph (its Bloom filter), else -1. */
|
|
2031
|
+
bloomPos(n: number): number {
|
|
2032
|
+
return (this.flags[n] as number) & GRAPH_PARSED ? (this.gpos[n] as number) : -1;
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
/** Records a commit as parsed, with room for `count` parents (`setParent`). */
|
|
2036
|
+
setParsed(
|
|
2037
|
+
n: number,
|
|
2038
|
+
date: number,
|
|
2039
|
+
fromGraph: boolean,
|
|
2040
|
+
tree: ObjectId | undefined,
|
|
2041
|
+
count: number,
|
|
2042
|
+
): void {
|
|
2043
|
+
this.dates[n] = date;
|
|
2044
|
+
if (fromGraph) this.mark(n, GRAPH_PARSED);
|
|
2045
|
+
else this.trees[n] = tree;
|
|
2046
|
+
if (this.poolUsed + count > this.pool.length) {
|
|
2047
|
+
const grown = new Int32Array(Math.max(this.pool.length * 2, this.poolUsed + count));
|
|
2048
|
+
grown.set(this.pool);
|
|
2049
|
+
this.pool = grown;
|
|
2050
|
+
}
|
|
2051
|
+
this.parentAt[n] = this.poolUsed;
|
|
2052
|
+
this.parents[n] = count;
|
|
2053
|
+
this.poolUsed += count;
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
setParent(n: number, k: number, p: number): void {
|
|
2057
|
+
this.pool[(this.parentAt[n] as number) + k] = p;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
/** The parents of a parsed commit (0 before it is parsed). */
|
|
2061
|
+
parentCount(n: number): number {
|
|
2062
|
+
return Math.max(0, this.parents[n] as number);
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
parent(n: number, k: number): number {
|
|
2066
|
+
return this.pool[(this.parentAt[n] as number) + k] as number;
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
/** Simplification keeps only parent `p` (git rewrites `commit->parents`). */
|
|
2070
|
+
keepOnlyParent(n: number, p: number): void {
|
|
2071
|
+
this.pool[this.parentAt[n] as number] = p;
|
|
2072
|
+
this.parents[n] = 1;
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
private add(pos: number): number {
|
|
2076
|
+
const n = this.size++;
|
|
2077
|
+
if (n === this.flags.length) this.grow();
|
|
2078
|
+
this.gpos[n] = pos;
|
|
2079
|
+
this.parents[n] = -1;
|
|
2080
|
+
return n;
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
private grow(): void {
|
|
2084
|
+
const size = this.flags.length * 2;
|
|
2085
|
+
const flags = new Uint8Array(size);
|
|
2086
|
+
flags.set(this.flags);
|
|
2087
|
+
this.flags = flags;
|
|
2088
|
+
const dates = new Float64Array(size);
|
|
2089
|
+
dates.set(this.dates);
|
|
2090
|
+
this.dates = dates;
|
|
2091
|
+
const gpos = new Int32Array(size);
|
|
2092
|
+
gpos.set(this.gpos);
|
|
2093
|
+
this.gpos = gpos;
|
|
2094
|
+
const parentAt = new Int32Array(size);
|
|
2095
|
+
parentAt.set(this.parentAt);
|
|
2096
|
+
this.parentAt = parentAt;
|
|
2097
|
+
const parents = new Int32Array(size);
|
|
2098
|
+
parents.set(this.parents);
|
|
2099
|
+
this.parents = parents;
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
/** Commits a `RevTable` has room for before it first grows. */
|
|
2104
|
+
const INITIAL_REVS = 1024;
|
|
2105
|
+
/** `RevTable` flag: parsed from the commit-graph (its tree and Bloom filter are there). */
|
|
2106
|
+
const GRAPH_PARSED = 1 << 6;
|
|
2107
|
+
|
|
2108
|
+
/** A commit read whole, as the commit store decodes it; undefined if it does not parse. */
|
|
2109
|
+
function decodeCommit(bytes: Uint8Array): Commit | undefined {
|
|
2110
|
+
try {
|
|
2111
|
+
return commitFromBytes(bytes);
|
|
2112
|
+
} catch {
|
|
547
2113
|
return undefined;
|
|
548
2114
|
}
|
|
549
2115
|
}
|
|
2116
|
+
|
|
2117
|
+
/** memcmp order of two byte strings */
|
|
2118
|
+
function compareBytes(a: Uint8Array, b: Uint8Array): number {
|
|
2119
|
+
const n = Math.min(a.length, b.length);
|
|
2120
|
+
for (let i = 0; i < n; i++) {
|
|
2121
|
+
if (a[i] !== b[i]) return (a[i] as number) - (b[i] as number);
|
|
2122
|
+
}
|
|
2123
|
+
return a.length - b.length;
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
function concatBytes(chunks: Uint8Array[]): Uint8Array {
|
|
2127
|
+
if (chunks.length === 1) return chunks[0] as Uint8Array;
|
|
2128
|
+
const out = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));
|
|
2129
|
+
let at = 0;
|
|
2130
|
+
for (const c of chunks) {
|
|
2131
|
+
out.set(c, at);
|
|
2132
|
+
at += c.length;
|
|
2133
|
+
}
|
|
2134
|
+
return out;
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
/** The entry named `name` (raw bytes) in raw tree `d`: its id and mode, or undefined. */
|
|
2138
|
+
function findRawEntry(
|
|
2139
|
+
d: Uint8Array,
|
|
2140
|
+
name: Uint8Array,
|
|
2141
|
+
idLength: number,
|
|
2142
|
+
): { id: ObjectId; mode: number } | undefined {
|
|
2143
|
+
let p = 0;
|
|
2144
|
+
const n = name.length;
|
|
2145
|
+
while (p < d.length) {
|
|
2146
|
+
let mode = 0;
|
|
2147
|
+
while (p < d.length && d[p] !== 0x20) mode = mode * 8 + ((d[p++] as number) - 0x30);
|
|
2148
|
+
p++;
|
|
2149
|
+
const start = p;
|
|
2150
|
+
while (p < d.length && d[p] !== 0) p++;
|
|
2151
|
+
const idAt = p + 1;
|
|
2152
|
+
if (p - start === n) {
|
|
2153
|
+
let k = 0;
|
|
2154
|
+
while (k < n && d[start + k] === name[k]) k++;
|
|
2155
|
+
if (k === n) return { id: bytesToHex(d.subarray(idAt, idAt + idLength)), mode };
|
|
2156
|
+
}
|
|
2157
|
+
p = idAt + idLength;
|
|
2158
|
+
}
|
|
2159
|
+
return undefined;
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
/** A path's components, without empty ones and "." (git's pathspec normalisation). */
|
|
2163
|
+
const pathParts = (path: string) =>
|
|
2164
|
+
path.split("/").filter((part) => part.length > 0 && part !== ".");
|
|
2165
|
+
|
|
2166
|
+
/**
|
|
2167
|
+
* git's prio_queue with compare_commits_by_commit_date: the newest commit first, commits of
|
|
2168
|
+
* one date in the order they were put.
|
|
2169
|
+
*/
|
|
2170
|
+
class CommitQueue<T> {
|
|
2171
|
+
private entries: T[] = [];
|
|
2172
|
+
private dates: number[] = [];
|
|
2173
|
+
private ctrs: number[] = [];
|
|
2174
|
+
private ctr = 0;
|
|
2175
|
+
|
|
2176
|
+
put(entry: T, date: number): void {
|
|
2177
|
+
const { entries, dates, ctrs } = this;
|
|
2178
|
+
let ix = entries.length;
|
|
2179
|
+
entries.push(entry);
|
|
2180
|
+
dates.push(date);
|
|
2181
|
+
ctrs.push(this.ctr++);
|
|
2182
|
+
while (ix > 0) {
|
|
2183
|
+
const parent = (ix - 1) >> 1;
|
|
2184
|
+
if (this.before(parent, ix)) break;
|
|
2185
|
+
this.swap(parent, ix);
|
|
2186
|
+
ix = parent;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
get(): T | undefined {
|
|
2191
|
+
const { entries } = this;
|
|
2192
|
+
if (entries.length === 0) return undefined;
|
|
2193
|
+
const top = entries[0];
|
|
2194
|
+
const last = entries.length - 1;
|
|
2195
|
+
this.swap(0, last);
|
|
2196
|
+
entries.pop();
|
|
2197
|
+
this.dates.pop();
|
|
2198
|
+
this.ctrs.pop();
|
|
2199
|
+
let ix = 0;
|
|
2200
|
+
for (;;) {
|
|
2201
|
+
let child = 2 * ix + 1;
|
|
2202
|
+
if (child >= entries.length) break;
|
|
2203
|
+
if (child + 1 < entries.length && this.before(child + 1, child)) child++;
|
|
2204
|
+
if (this.before(ix, child)) break;
|
|
2205
|
+
this.swap(ix, child);
|
|
2206
|
+
ix = child;
|
|
2207
|
+
}
|
|
2208
|
+
return top;
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
/** The entry `get` returns next (git's prio_queue_peek). */
|
|
2212
|
+
peek(): T | undefined {
|
|
2213
|
+
return this.entries[0];
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
/** The entries in heap order (git's prio_queue_for_each). */
|
|
2217
|
+
items(): readonly T[] {
|
|
2218
|
+
return this.entries;
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
/** Whether entry `a` comes out before entry `b`. */
|
|
2222
|
+
private before(a: number, b: number): boolean {
|
|
2223
|
+
const da = this.dates[a] as number;
|
|
2224
|
+
const db = this.dates[b] as number;
|
|
2225
|
+
if (da !== db) return da > db;
|
|
2226
|
+
return (this.ctrs[a] as number) < (this.ctrs[b] as number);
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
private swap(a: number, b: number): void {
|
|
2230
|
+
const { entries, dates, ctrs } = this;
|
|
2231
|
+
[entries[a], entries[b]] = [entries[b] as T, entries[a] as T];
|
|
2232
|
+
[dates[a], dates[b]] = [dates[b] as number, dates[a] as number];
|
|
2233
|
+
[ctrs[a], ctrs[b]] = [ctrs[b] as number, ctrs[a] as number];
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
/**
|
|
2238
|
+
* A cursor over a raw tree's entries for the pruned diff: `read()` decodes the entry at `at`
|
|
2239
|
+
* (its mode, where its name starts and ends), `next()` moves past it. Names stay bytes.
|
|
2240
|
+
*/
|
|
2241
|
+
class RawEntries {
|
|
2242
|
+
at = 0;
|
|
2243
|
+
mode = 0;
|
|
2244
|
+
nameStart = 0;
|
|
2245
|
+
/** where the name ends (its NUL; the id follows) */
|
|
2246
|
+
nul = 0;
|
|
2247
|
+
/** @param idLength raw id bytes per entry: 20 (SHA-1) or 32 (SHA-256) */
|
|
2248
|
+
constructor(
|
|
2249
|
+
readonly d: Uint8Array,
|
|
2250
|
+
readonly idLength = 20,
|
|
2251
|
+
) {}
|
|
2252
|
+
get done(): boolean {
|
|
2253
|
+
return this.at >= this.d.length;
|
|
2254
|
+
}
|
|
2255
|
+
read(): void {
|
|
2256
|
+
const d = this.d;
|
|
2257
|
+
let p = this.at;
|
|
2258
|
+
let mode = 0;
|
|
2259
|
+
while (p < d.length && d[p] !== 0x20) mode = mode * 8 + ((d[p++] as number) - 0x30);
|
|
2260
|
+
// the mode as git's tree walk reads it (canon_mode): 100664 is 100644
|
|
2261
|
+
this.mode = canonTreeMode(mode);
|
|
2262
|
+
this.nameStart = ++p;
|
|
2263
|
+
while (p < d.length && d[p] !== 0) p++;
|
|
2264
|
+
this.nul = p;
|
|
2265
|
+
}
|
|
2266
|
+
next(): void {
|
|
2267
|
+
this.at = this.nul + 1 + this.idLength;
|
|
2268
|
+
}
|
|
2269
|
+
id(): ObjectId {
|
|
2270
|
+
return bytesToHex(this.d.subarray(this.nul + 1, this.nul + 1 + this.idLength));
|
|
2271
|
+
}
|
|
2272
|
+
/** The base of the entries below this one (a directory): `base`, its name and "/". */
|
|
2273
|
+
below(base: Uint8Array): Uint8Array {
|
|
2274
|
+
const length = this.nul - this.nameStart;
|
|
2275
|
+
const out = new Uint8Array(base.length + length + 1);
|
|
2276
|
+
out.set(base);
|
|
2277
|
+
out.set(this.d.subarray(this.nameStart, this.nul), base.length);
|
|
2278
|
+
out[base.length + length] = 0x2f;
|
|
2279
|
+
return out;
|
|
2280
|
+
}
|
|
2281
|
+
sameId(other: RawEntries): boolean {
|
|
2282
|
+
for (let k = 1; k <= this.idLength; k++) {
|
|
2283
|
+
if (this.d[this.nul + k] !== other.d[other.nul + k]) return false;
|
|
2284
|
+
}
|
|
2285
|
+
return true;
|
|
2286
|
+
}
|
|
2287
|
+
/** git's base_name_compare of the names: a tree's name is followed by "/". */
|
|
2288
|
+
compare(other: RawEntries): number {
|
|
2289
|
+
const a = this.d;
|
|
2290
|
+
const b = other.d;
|
|
2291
|
+
const la = this.nul - this.nameStart;
|
|
2292
|
+
const lb = other.nul - other.nameStart;
|
|
2293
|
+
const n = Math.min(la, lb);
|
|
2294
|
+
for (let i = 0; i < n; i++) {
|
|
2295
|
+
const d = (a[this.nameStart + i] as number) - (b[other.nameStart + i] as number);
|
|
2296
|
+
if (d !== 0) return d;
|
|
2297
|
+
}
|
|
2298
|
+
const ca = n < la ? (a[this.nameStart + n] as number) : isTreeMode(this.mode) ? 0x2f : 0;
|
|
2299
|
+
const cb = n < lb ? (b[other.nameStart + n] as number) : isTreeMode(other.mode) ? 0x2f : 0;
|
|
2300
|
+
return ca - cb;
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
/** `diff.algorithm` as diff.c's parse_algorithm_value reads it (undefined: not one) */
|
|
2305
|
+
function configAlgorithm(v: string | undefined): XdiffAlgorithm | undefined {
|
|
2306
|
+
const s = v?.trim().toLowerCase();
|
|
2307
|
+
if (s === "default") return "myers";
|
|
2308
|
+
return s === "myers" || s === "minimal" || s === "patience" || s === "histogram" ? s : undefined;
|
|
2309
|
+
}
|