@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
|
@@ -0,0 +1,1660 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's merge-ort on flat trees (path -> blob, link or gitlink): the merge `merge`,
|
|
3
|
+
* `cherry-pick`, `revert`, `rebase` and `stash apply` run, without writing anything but the
|
|
4
|
+
* blobs of content merges.
|
|
5
|
+
*
|
|
6
|
+
* A port of merge-ort.c's structure: every path (file or directory) of the three trees gets
|
|
7
|
+
* an entry with its three versions (`collect_merge_info`); renames are detected on each side
|
|
8
|
+
* (exact, by basename, then by similarity, for the paths the merge needs), directory renames
|
|
9
|
+
* derived from them move what the other side added into the new directory
|
|
10
|
+
* (`merge.directoryRenames`); then each entry is resolved (`process_entry`), children before
|
|
11
|
+
* their directory, so that a file meeting a directory moves aside only when the directory
|
|
12
|
+
* stays. The result is merge-ort's tree, the conflicted index entries and the messages,
|
|
13
|
+
* sorted by path as git prints them.
|
|
14
|
+
*
|
|
15
|
+
* With `callDepth` > 0 it is one of the inner merges of merge bases that build a virtual
|
|
16
|
+
* merge base (`merge_ort_internal`): longer conflict markers, no messages, conflicts
|
|
17
|
+
* resolved to the base's version where git does, no directory renames.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { type Blobs, FileMode, type ObjectId } from "@statewalker/vcs-core";
|
|
21
|
+
import type { ConflictStyle } from "@statewalker/vcs-utils";
|
|
22
|
+
import { encodeGitPath, foldAsciiCase } from "@statewalker/vcs-utils/encoding";
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
detectRenames,
|
|
26
|
+
RELEVANT_CONTENT,
|
|
27
|
+
RELEVANT_FOR_ANCESTOR,
|
|
28
|
+
RELEVANT_FOR_SELF,
|
|
29
|
+
RELEVANT_LOCATION,
|
|
30
|
+
type RenameCandidate,
|
|
31
|
+
} from "../rename/index.js";
|
|
32
|
+
import {
|
|
33
|
+
lowLevelMerge,
|
|
34
|
+
type MergeAttributeValue,
|
|
35
|
+
type MergeDriverRegistry,
|
|
36
|
+
} from "./merge-drivers.js";
|
|
37
|
+
import type { CheckedEntry } from "./worktree-overwrite-checks.js";
|
|
38
|
+
|
|
39
|
+
/** A path the merge could not resolve, as merge-ort leaves it in the index. */
|
|
40
|
+
export interface OrtConflict {
|
|
41
|
+
base?: CheckedEntry;
|
|
42
|
+
ours?: CheckedEntry;
|
|
43
|
+
theirs?: CheckedEntry;
|
|
44
|
+
/** Where the stages (and the worktree file) go: the path, or `<path>~<side>` */
|
|
45
|
+
stagePath: string;
|
|
46
|
+
/** The file with conflict markers, for a text conflict (unused: see `tree`) */
|
|
47
|
+
content?: Uint8Array;
|
|
48
|
+
/** What the worktree gets at `stagePath` where it differs from our side's version */
|
|
49
|
+
write?: CheckedEntry;
|
|
50
|
+
/** The path a file/directory or distinct-types conflict moves ours away from */
|
|
51
|
+
moveFrom?: string;
|
|
52
|
+
/** What merge-ort's result tree holds at `stagePath` (none: nothing there) */
|
|
53
|
+
tree?: CheckedEntry;
|
|
54
|
+
mode: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `merge.directoryRenames`: apply them, leave paths as they are, or apply with a conflict. */
|
|
58
|
+
export type DirectoryRenames = "true" | "false" | "conflict";
|
|
59
|
+
|
|
60
|
+
/** The attributes a content merge reads for a path (`merge`, `conflict-marker-size`). */
|
|
61
|
+
export interface MergeAttributes {
|
|
62
|
+
merge?: MergeAttributeValue;
|
|
63
|
+
conflictMarkerSize?: MergeAttributeValue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Options of {@link ortMerge}. */
|
|
67
|
+
export interface OrtMergeOptions {
|
|
68
|
+
/** Our side's name in markers and messages (git's branch1, e.g. `HEAD`) */
|
|
69
|
+
oursLabel: string;
|
|
70
|
+
/** Their side's name (git's branch2: the branch, or `<abbrev> (<subject>)`) */
|
|
71
|
+
theirsLabel: string;
|
|
72
|
+
/** The base's name after `|||||||` (diff3, zdiff3) */
|
|
73
|
+
baseLabel?: string;
|
|
74
|
+
/** Names a file moved aside gets (`<path>~<name>`); default the labels */
|
|
75
|
+
oursName?: string;
|
|
76
|
+
theirsName?: string;
|
|
77
|
+
/** merge.conflictStyle */
|
|
78
|
+
style?: ConflictStyle;
|
|
79
|
+
/** `-X ours`, `-X theirs`: conflicting hunks (and binary files) resolved to a side */
|
|
80
|
+
favor?: "ours" | "theirs" | "union";
|
|
81
|
+
/** A case-folding worktree (core.ignorecase): names taken in another case are taken */
|
|
82
|
+
ignoreCase?: boolean;
|
|
83
|
+
/** Detect renames (default true) */
|
|
84
|
+
renames?: boolean;
|
|
85
|
+
/** merge.directoryRenames (default `conflict`, as git) */
|
|
86
|
+
directoryRenames?: DirectoryRenames;
|
|
87
|
+
/** merge.renameLimit (default 7000, as merge-ort) */
|
|
88
|
+
renameLimit?: number;
|
|
89
|
+
/** Files above this size are binary to the merge (core.bigFileThreshold) */
|
|
90
|
+
bigFileThreshold?: number;
|
|
91
|
+
/** The recursion level of a merge of merge bases (merge-ort's call_depth; default 0) */
|
|
92
|
+
callDepth?: number;
|
|
93
|
+
/** merge.renormalize / `-X renormalize`: content compared and merged as checked in afresh */
|
|
94
|
+
renormalize?: boolean;
|
|
95
|
+
/** The `merge` and `conflict-marker-size` attributes of a path (none: unspecified) */
|
|
96
|
+
attributes?: (path: string) => Promise<MergeAttributes>;
|
|
97
|
+
/** git's renormalize_buffer for a path (with `renormalize`) */
|
|
98
|
+
renormalizeContent?: (path: string, content: Uint8Array) => Promise<Uint8Array>;
|
|
99
|
+
/** Merge drivers by name (the `merge` attribute, `merge.default`) */
|
|
100
|
+
drivers?: MergeDriverRegistry;
|
|
101
|
+
/** merge.default: the driver of a path without a `merge` attribute */
|
|
102
|
+
defaultDriver?: string;
|
|
103
|
+
/** merge.<driver>.recursive: the driver used in merges of merge bases */
|
|
104
|
+
recursiveDriver?: (name: string) => string | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* The trees given as {@link prunedFlatTrees} reads them (directories all three hold alike
|
|
107
|
+
* stand as one TREE entry): per tree (base, ours, theirs), the id of each directory, so a
|
|
108
|
+
* directory taken whole from a side is the side's tree, never read.
|
|
109
|
+
*/
|
|
110
|
+
dirTrees?: Map<string, ObjectId>[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** What {@link ortMerge} found. */
|
|
114
|
+
export interface OrtMergeResult {
|
|
115
|
+
/** The cleanly merged entries */
|
|
116
|
+
result: Map<string, CheckedEntry>;
|
|
117
|
+
/** The conflicts, by the path they are staged at */
|
|
118
|
+
conflicts: Map<string, OrtConflict>;
|
|
119
|
+
/** Whether merge-ort calls the merge clean (no conflicts, no directory rename trouble) */
|
|
120
|
+
clean: boolean;
|
|
121
|
+
/** merge-ort's messages (`Auto-merging x`, `CONFLICT (...)`), in git's order */
|
|
122
|
+
messages: string[];
|
|
123
|
+
/** Whether directory renames were found (paths may move into any directory) */
|
|
124
|
+
directoryRenames?: boolean;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const sameEntry = (a: CheckedEntry | undefined, b: CheckedEntry | undefined) =>
|
|
128
|
+
a === undefined || b === undefined ? a === b : a.objectId === b.objectId && a.mode === b.mode;
|
|
129
|
+
|
|
130
|
+
const S_IFMT = 0o170000;
|
|
131
|
+
const typeOf = (e?: CheckedEntry) => (e ? e.mode & S_IFMT : 0);
|
|
132
|
+
const isReg = (e?: CheckedEntry) => typeOf(e) === 0o100000;
|
|
133
|
+
const isLink = (e?: CheckedEntry) => typeOf(e) === 0o120000;
|
|
134
|
+
const isGitlink = (e?: CheckedEntry) => typeOf(e) === 0o160000;
|
|
135
|
+
const TREE: CheckedEntry = { objectId: "", mode: FileMode.TREE };
|
|
136
|
+
|
|
137
|
+
function concatBytes(chunks: Uint8Array[]): Uint8Array {
|
|
138
|
+
if (chunks.length === 1) return chunks[0];
|
|
139
|
+
const out = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));
|
|
140
|
+
let offset = 0;
|
|
141
|
+
for (const c of chunks) {
|
|
142
|
+
out.set(c, offset);
|
|
143
|
+
offset += c.length;
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Reads a blob whole. */
|
|
149
|
+
export async function readBlob(blobs: Blobs, id: ObjectId): Promise<Uint8Array> {
|
|
150
|
+
const chunks: Uint8Array[] = [];
|
|
151
|
+
for await (const chunk of (await blobs.load(id)) ?? []) chunks.push(chunk);
|
|
152
|
+
return concatBytes(chunks);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type Stages = [CheckedEntry | undefined, CheckedEntry | undefined, CheckedEntry | undefined];
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A path's entry (merge-ort's merged_info, with conflict_info's fields when `resolved` is
|
|
159
|
+
* false).
|
|
160
|
+
*/
|
|
161
|
+
interface Info {
|
|
162
|
+
/** The directory holding the path ("" for the top) */
|
|
163
|
+
dir: string;
|
|
164
|
+
/** Resolved while the trees were read (merged_info only) */
|
|
165
|
+
resolved: boolean;
|
|
166
|
+
/** merged.clean */
|
|
167
|
+
clean: boolean;
|
|
168
|
+
/** merged.is_null: nothing at the path in the result */
|
|
169
|
+
isNull: boolean;
|
|
170
|
+
/** merged.result */
|
|
171
|
+
result?: CheckedEntry;
|
|
172
|
+
stages: Stages;
|
|
173
|
+
pathnames: [string, string, string];
|
|
174
|
+
filemask: number;
|
|
175
|
+
dirmask: number;
|
|
176
|
+
matchMask: number;
|
|
177
|
+
dfConflict: boolean;
|
|
178
|
+
pathConflict: boolean;
|
|
179
|
+
/** The path a file/directory or distinct-types conflict moved this entry away from */
|
|
180
|
+
movedFrom?: string;
|
|
181
|
+
/** Moved by a file/directory conflict (its conflict is listed under `movedFrom`) */
|
|
182
|
+
dfMoved?: boolean;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** A rename or add of one side (a diff_filepair after rename detection). */
|
|
186
|
+
interface Pair {
|
|
187
|
+
status: "A" | "R";
|
|
188
|
+
/** The source path (the path itself for an add) */
|
|
189
|
+
one: string;
|
|
190
|
+
/** The destination path (changed by a directory rename) */
|
|
191
|
+
two: string;
|
|
192
|
+
/** The side (1: ours, 2: theirs) */
|
|
193
|
+
side: 1 | 2;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const dirnameOf = (path: string) => {
|
|
197
|
+
const k = path.lastIndexOf("/");
|
|
198
|
+
return k < 0 ? "" : path.slice(0, k);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/** git's strcmp order on paths. */
|
|
202
|
+
const compareStrings = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);
|
|
203
|
+
|
|
204
|
+
const digestCache = new WeakMap<Map<string, CheckedEntry>, Map<string, string>>();
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* A digest of each directory of a flat tree (what its tree id tells git): two directories
|
|
208
|
+
* of two trees hold the same entries when their digests are equal. Kept per map (the flat
|
|
209
|
+
* trees of a rebase are shared).
|
|
210
|
+
*/
|
|
211
|
+
function dirDigests(tree: Map<string, CheckedEntry>): Map<string, string> {
|
|
212
|
+
const known = digestCache.get(tree);
|
|
213
|
+
if (known) return known;
|
|
214
|
+
const sums = new Map<string, [number, number, number]>();
|
|
215
|
+
for (const [path, entry] of tree) {
|
|
216
|
+
// two independent 32-bit hashes of the entry, summed per directory
|
|
217
|
+
let h1 = 0x811c9dc5;
|
|
218
|
+
let h2 = 0x01000193;
|
|
219
|
+
const text = `${path}\0${entry.mode}\0${entry.objectId}`;
|
|
220
|
+
for (let i = 0; i < text.length; i++) {
|
|
221
|
+
const c = text.charCodeAt(i);
|
|
222
|
+
h1 = Math.imul(h1 ^ c, 0x01000193) >>> 0;
|
|
223
|
+
h2 = (Math.imul(h2, 31) + c + (h2 >>> 13)) >>> 0;
|
|
224
|
+
}
|
|
225
|
+
for (let dir = dirnameOf(path); ; dir = dirnameOf(dir)) {
|
|
226
|
+
const s = sums.get(dir) ?? [0, 0, 0];
|
|
227
|
+
s[0] = (s[0] + h1) >>> 0;
|
|
228
|
+
s[1] = (s[1] + h2) >>> 0;
|
|
229
|
+
s[2]++;
|
|
230
|
+
sums.set(dir, s);
|
|
231
|
+
if (dir === "") break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const out = new Map<string, string>();
|
|
235
|
+
for (const [dir, [a, b, n]] of sums) out.set(dir, `${a}:${b}:${n}`);
|
|
236
|
+
digestCache.set(tree, out);
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** git's strhash (FNV-1, 32 bits) over the bytes of a path. */
|
|
241
|
+
function strhash(text: string): number {
|
|
242
|
+
let hash = 0x811c9dc5;
|
|
243
|
+
for (const byte of encodeGitPath(text)) {
|
|
244
|
+
hash = (Math.imul(hash, 0x01000193) ^ byte) >>> 0;
|
|
245
|
+
}
|
|
246
|
+
return hash;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The order git's hashmap (a strmap) iterates keys added in this order: buckets by
|
|
251
|
+
* `strhash & (size - 1)`, each a list with the newest first, the table growing fourfold
|
|
252
|
+
* past 80% full (git's hashmap.c).
|
|
253
|
+
*/
|
|
254
|
+
function gitHashOrder(keys: Iterable<string>): string[] {
|
|
255
|
+
let size = 64;
|
|
256
|
+
let table: string[][] = Array.from({ length: size }, () => []);
|
|
257
|
+
let count = 0;
|
|
258
|
+
for (const key of keys) {
|
|
259
|
+
table[strhash(key) & (size - 1)].unshift(key);
|
|
260
|
+
count++;
|
|
261
|
+
if (count > Math.floor((size * 80) / 100)) {
|
|
262
|
+
const old = table;
|
|
263
|
+
size <<= 2;
|
|
264
|
+
table = Array.from({ length: size }, () => []);
|
|
265
|
+
for (const chain of old) for (const k of chain) table[strhash(k) & (size - 1)].unshift(k);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return table.flat();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** merge-ort's sort_dirs_next_to_their_children: a directory right before its children. */
|
|
272
|
+
function sortDirsNextToChildren(one: string, two: string): number {
|
|
273
|
+
const n = Math.min(one.length, two.length);
|
|
274
|
+
let i = 0;
|
|
275
|
+
while (i < n && one.charCodeAt(i) === two.charCodeAt(i)) i++;
|
|
276
|
+
const c1 = i < one.length ? one.charCodeAt(i) : 47;
|
|
277
|
+
const c2 = i < two.length ? two.charCodeAt(i) : 47;
|
|
278
|
+
if (c1 === c2) return i < one.length ? 1 : -1;
|
|
279
|
+
return c1 - c2;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* How often merges took merge-ort's paths that leave no trace in their result, for tests:
|
|
284
|
+
* `redos` counts the merges redone with the renames the first pass found
|
|
285
|
+
* (redo_after_renames). Not part of the package's API.
|
|
286
|
+
*/
|
|
287
|
+
export const ortMergeCounters = { redos: 0 };
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Merges `theirs` into `ours` against `base`, as git's merge-ort
|
|
291
|
+
* (`merge_ort_nonrecursive_internal`). Content-merged blobs are stored in `blobs`.
|
|
292
|
+
*/
|
|
293
|
+
export async function ortMerge(
|
|
294
|
+
blobs: Blobs,
|
|
295
|
+
baseIn: Map<string, CheckedEntry>,
|
|
296
|
+
oursIn: Map<string, CheckedEntry>,
|
|
297
|
+
theirsIn: Map<string, CheckedEntry>,
|
|
298
|
+
options: OrtMergeOptions,
|
|
299
|
+
): Promise<OrtMergeResult> {
|
|
300
|
+
return new OrtMerge(blobs, options).run(baseIn, oursIn, theirsIn);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
class OrtMerge {
|
|
304
|
+
private readonly paths = new Map<string, Info>();
|
|
305
|
+
/** Folded keys of `paths` (core.ignorecase), for unique names */
|
|
306
|
+
private readonly folded = new Set<string>();
|
|
307
|
+
private readonly conflicted = new Map<string, Info>();
|
|
308
|
+
private readonly notes: { path: string; order: number; text: string }[] = [];
|
|
309
|
+
private order = 0;
|
|
310
|
+
private readonly depth: number;
|
|
311
|
+
private readonly branch1: string;
|
|
312
|
+
private readonly branch2: string;
|
|
313
|
+
private readonly ancestor: string;
|
|
314
|
+
private readonly dirRenamesMode: DirectoryRenames;
|
|
315
|
+
|
|
316
|
+
// rename bookkeeping, per side (index 1, 2)
|
|
317
|
+
private readonly deletes: string[][] = [[], [], []];
|
|
318
|
+
private readonly adds: string[][] = [[], [], []];
|
|
319
|
+
private readonly relevant: Map<string, number>[] = [new Map(), new Map(), new Map()];
|
|
320
|
+
private readonly dirsRemoved: Map<string, number>[] = [new Map(), new Map(), new Map()];
|
|
321
|
+
private readonly dirRenameCount: Map<string, Map<string, number>>[] = [
|
|
322
|
+
new Map(),
|
|
323
|
+
new Map(),
|
|
324
|
+
new Map(),
|
|
325
|
+
];
|
|
326
|
+
private readonly dirRenames: Map<string, string>[] = [new Map(), new Map(), new Map()];
|
|
327
|
+
/** merge-ort's dir_rename_mask while the trees are walked */
|
|
328
|
+
private dirRenameMask = 0;
|
|
329
|
+
/** Whether rename and directory rename processing left the merge clean */
|
|
330
|
+
private renamesClean = true;
|
|
331
|
+
/** merge-ort's deferred[side].trivial_merges_okay */
|
|
332
|
+
private readonly trivialOkay = [false, true, true];
|
|
333
|
+
/** merge-ort's possible_trivial_merges, by side: directory -> dir_rename_mask */
|
|
334
|
+
private possibleTrivial: Map<string, number>[] = [new Map(), new Map(), new Map()];
|
|
335
|
+
/** Directories taken whole from a side (resolve_trivial_directory_merge) */
|
|
336
|
+
private readonly trivialSide = new Map<string, 1 | 2>();
|
|
337
|
+
/** merge-ort's deferred[side].target_dirs: deferred directories a known rename goes into */
|
|
338
|
+
private readonly targetDirs: Set<string>[] = [new Set(), new Set(), new Set()];
|
|
339
|
+
/** Each side's deletions and additions in the order the trees are read (its diff queue) */
|
|
340
|
+
private readonly queue: { path: string; add: boolean }[][] = [[], [], []];
|
|
341
|
+
/**
|
|
342
|
+
* merge-ort's redo_after_renames: 1 when reading the deferred directories tripled the
|
|
343
|
+
* paths read (the merge is then run again with the renames found), 2 while redoing
|
|
344
|
+
*/
|
|
345
|
+
private redoAfterRenames = 0;
|
|
346
|
+
/** Whether rename detection gave up on inexact renames (needed_rename_limit) */
|
|
347
|
+
private renameLimitHit = false;
|
|
348
|
+
// what a redo keeps from the first pass, by side: cached_pairs (source -> destination,
|
|
349
|
+
// none for a deletion), cached_target_names, cached_irrelevant
|
|
350
|
+
private readonly cachedPairs: Map<string, string | undefined>[] = [
|
|
351
|
+
new Map(),
|
|
352
|
+
new Map(),
|
|
353
|
+
new Map(),
|
|
354
|
+
];
|
|
355
|
+
private readonly cachedTargets: Set<string>[] = [new Set(), new Set(), new Set()];
|
|
356
|
+
private readonly cachedIrrelevant: Set<string>[] = [new Set(), new Set(), new Set()];
|
|
357
|
+
/** The three trees */
|
|
358
|
+
private trees: Map<string, CheckedEntry>[] = [];
|
|
359
|
+
|
|
360
|
+
constructor(
|
|
361
|
+
private readonly blobs: Blobs,
|
|
362
|
+
private readonly options: OrtMergeOptions,
|
|
363
|
+
) {
|
|
364
|
+
this.depth = options.callDepth ?? 0;
|
|
365
|
+
this.branch1 = options.oursLabel;
|
|
366
|
+
this.branch2 = options.theirsLabel;
|
|
367
|
+
this.ancestor = options.baseLabel ?? "";
|
|
368
|
+
this.dirRenamesMode = options.directoryRenames ?? "conflict";
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
private say(path: string, text: string): void {
|
|
372
|
+
// inner merges are silent (path_msg at call_depth > 0)
|
|
373
|
+
if (this.depth > 0) return;
|
|
374
|
+
this.notes.push({ path, order: this.order++, text });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** A name as git's case-insensitive name hashing sees it (`memihash`: ASCII folded) */
|
|
378
|
+
private fold(name: string): string {
|
|
379
|
+
return this.options.ignoreCase ? foldAsciiCase(name) : name;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
private put(path: string, info: Info): void {
|
|
383
|
+
this.paths.set(path, info);
|
|
384
|
+
if (this.options.ignoreCase) this.folded.add(this.fold(path));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private has(path: string): boolean {
|
|
388
|
+
return (
|
|
389
|
+
this.paths.has(path) || (this.options.ignoreCase === true && this.folded.has(this.fold(path)))
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** merge-ort's unique_path: `<path>~<branch>` (`/` flattened), numbered while taken. */
|
|
394
|
+
private uniquePath(path: string, branch: string): string {
|
|
395
|
+
const base = `${path}~${branch.replaceAll("/", "_")}`;
|
|
396
|
+
let candidate = base;
|
|
397
|
+
for (let n = 0; this.has(candidate); n++) candidate = `${base}_${n}`;
|
|
398
|
+
// the name is taken from now on (merge-ort puts the entry there)
|
|
399
|
+
if (this.options.ignoreCase) this.folded.add(this.fold(candidate));
|
|
400
|
+
return candidate;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
private newInfo(dir: string, path: string): Info {
|
|
404
|
+
return {
|
|
405
|
+
dir,
|
|
406
|
+
resolved: false,
|
|
407
|
+
clean: false,
|
|
408
|
+
isNull: false,
|
|
409
|
+
stages: [undefined, undefined, undefined],
|
|
410
|
+
pathnames: [path, path, path],
|
|
411
|
+
filemask: 0,
|
|
412
|
+
dirmask: 0,
|
|
413
|
+
matchMask: 0,
|
|
414
|
+
dfConflict: false,
|
|
415
|
+
pathConflict: false,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
async run(
|
|
420
|
+
base: Map<string, CheckedEntry>,
|
|
421
|
+
ours: Map<string, CheckedEntry>,
|
|
422
|
+
theirs: Map<string, CheckedEntry>,
|
|
423
|
+
): Promise<OrtMergeResult> {
|
|
424
|
+
this.collect([base, ours, theirs]);
|
|
425
|
+
if (this.options.renames !== false && (await this.detectAndProcessRenames())) {
|
|
426
|
+
// redo_after_renames: the trees read again, knowing the renames the merge needs
|
|
427
|
+
ortMergeCounters.redos++;
|
|
428
|
+
this.reset();
|
|
429
|
+
this.collect([base, ours, theirs]);
|
|
430
|
+
await this.detectAndProcessRenames();
|
|
431
|
+
}
|
|
432
|
+
await this.processEntries();
|
|
433
|
+
return this.output(ours);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* merge-ort's prefetch_for_content_merges: a partial clone fetches, in one batch, the
|
|
438
|
+
* regular files of each path whose content both sides changed differently (and neither
|
|
439
|
+
* like the base), in reverse path order
|
|
440
|
+
*/
|
|
441
|
+
private async prefetchForContentMerges(plist: readonly string[]): Promise<void> {
|
|
442
|
+
if (!this.blobs.prefetch) return;
|
|
443
|
+
const ids: ObjectId[] = [];
|
|
444
|
+
const regular = (e: CheckedEntry | undefined): e is CheckedEntry =>
|
|
445
|
+
e !== undefined && (e.mode & 0o170000) === 0o100000;
|
|
446
|
+
for (let k = plist.length - 1; k >= 0; k--) {
|
|
447
|
+
const info = this.paths.get(plist[k] as string);
|
|
448
|
+
if (!info || info.clean) continue;
|
|
449
|
+
const [base, ours, theirs] = info.stages;
|
|
450
|
+
if (info.matchMask || info.filemask < 6 || !regular(ours) || !regular(theirs)) continue;
|
|
451
|
+
if (ours.objectId === theirs.objectId) continue;
|
|
452
|
+
if (
|
|
453
|
+
info.filemask === 7 &&
|
|
454
|
+
regular(base) &&
|
|
455
|
+
(base.objectId === ours.objectId || base.objectId === theirs.objectId)
|
|
456
|
+
) {
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
for (let i = 0; i < 3; i++) {
|
|
460
|
+
const e = info.stages[i];
|
|
461
|
+
if (info.filemask & (1 << i) && regular(e)) ids.push(e.objectId);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
await this.blobs.prefetch(ids);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* clear_or_reinit_internal_opts(reinitialize) for a redo: everything but the renames the
|
|
469
|
+
* first pass found (and the directory rename counts, as git keeps them)
|
|
470
|
+
*/
|
|
471
|
+
private reset(): void {
|
|
472
|
+
this.paths.clear();
|
|
473
|
+
this.folded.clear();
|
|
474
|
+
this.conflicted.clear();
|
|
475
|
+
this.notes.length = 0;
|
|
476
|
+
for (let i = 0; i < 3; i++) {
|
|
477
|
+
this.deletes[i] = [];
|
|
478
|
+
this.adds[i] = [];
|
|
479
|
+
this.queue[i] = [];
|
|
480
|
+
this.relevant[i].clear();
|
|
481
|
+
this.dirsRemoved[i].clear();
|
|
482
|
+
this.dirRenames[i].clear();
|
|
483
|
+
this.possibleTrivial[i] = new Map();
|
|
484
|
+
this.targetDirs[i].clear();
|
|
485
|
+
this.trivialOkay[i] = i !== 0;
|
|
486
|
+
}
|
|
487
|
+
this.trivialSide.clear();
|
|
488
|
+
this.dirRenameMask = 0;
|
|
489
|
+
this.renamesClean = true;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// ---- collect_merge_info -------------------------------------------------------------
|
|
493
|
+
|
|
494
|
+
private collect(trees: Map<string, CheckedEntry>[]): void {
|
|
495
|
+
interface Node {
|
|
496
|
+
files: Stages;
|
|
497
|
+
dirmask: number;
|
|
498
|
+
children?: string[];
|
|
499
|
+
}
|
|
500
|
+
const nodes = new Map<string, Node>();
|
|
501
|
+
const node = (path: string) => {
|
|
502
|
+
let n = nodes.get(path);
|
|
503
|
+
if (!n) {
|
|
504
|
+
n = { files: [undefined, undefined, undefined], dirmask: 0 };
|
|
505
|
+
nodes.set(path, n);
|
|
506
|
+
if (path !== "") {
|
|
507
|
+
const parent = dirnameOf(path);
|
|
508
|
+
const p = node(parent);
|
|
509
|
+
if (!p.children) p.children = [];
|
|
510
|
+
p.children.push(path);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return n;
|
|
514
|
+
};
|
|
515
|
+
node("");
|
|
516
|
+
trees.forEach((tree, i) => {
|
|
517
|
+
for (const [path, entry] of tree) {
|
|
518
|
+
node(path).files[i] = entry;
|
|
519
|
+
for (let dir = dirnameOf(path); dir !== ""; dir = dirnameOf(dir)) {
|
|
520
|
+
const d = node(dir);
|
|
521
|
+
if (d.dirmask & (1 << i)) break;
|
|
522
|
+
d.dirmask |= 1 << i;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
const filemaskOf = (n: Node) =>
|
|
527
|
+
(n.files[0] ? 1 : 0) | (n.files[1] ? 2 : 0) | (n.files[2] ? 4 : 0);
|
|
528
|
+
// the same directory in two trees (git compares the tree ids)
|
|
529
|
+
const digests = trees.map((tree) => dirDigests(tree));
|
|
530
|
+
const sameDir = (path: string, i: number, j: number) => {
|
|
531
|
+
const x = digests[i].get(path);
|
|
532
|
+
return x !== undefined && x === digests[j].get(path);
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const traverse = (path: string) => {
|
|
536
|
+
const n = nodes.get(path) as Node;
|
|
537
|
+
// tree order: a directory sorts as `name/`
|
|
538
|
+
const key = (c: string) => {
|
|
539
|
+
const m = nodes.get(c) as Node;
|
|
540
|
+
// a directory, or one all three trees hold alike (a TREE entry standing for it)
|
|
541
|
+
return (m.dirmask && !filemaskOf(m)) || m.files[0]?.mode === FileMode.TREE ? `${c}/` : c;
|
|
542
|
+
};
|
|
543
|
+
const children = (n.children ?? []).sort((x, y) => compareStrings(key(x), key(y)));
|
|
544
|
+
// a directory one side removed: its children read first, to see whether the side
|
|
545
|
+
// that kept it added a file there (traverse_trees_wrapper)
|
|
546
|
+
if (this.dirRenameMask === 2 || this.dirRenameMask === 4) {
|
|
547
|
+
for (const child of children) {
|
|
548
|
+
const fm = filemaskOf(nodes.get(child) as Node);
|
|
549
|
+
if (fm && fm === this.dirRenameMask) this.dirRenameMask = 7;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
for (const child of children) visit(child, path);
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
const visit = (path: string, dir: string) => {
|
|
556
|
+
const n = nodes.get(path) as Node;
|
|
557
|
+
const filemask = filemaskOf(n);
|
|
558
|
+
const dirmask = n.dirmask;
|
|
559
|
+
const [b, s1, s2] = n.files;
|
|
560
|
+
const side1MatchesBase = !!b && !!s1 && sameEntry(b, s1);
|
|
561
|
+
const side2MatchesBase = !!b && !!s2 && sameEntry(b, s2);
|
|
562
|
+
const sidesMatch = !!s1 && !!s2 && sameEntry(s1, s2);
|
|
563
|
+
const dirs1 = !b && !s1 && sameDir(path, 0, 1);
|
|
564
|
+
const dirs2 = !b && !s2 && sameDir(path, 0, 2);
|
|
565
|
+
let matchMask = 0;
|
|
566
|
+
if (side1MatchesBase) matchMask = side2MatchesBase ? 7 : 3;
|
|
567
|
+
else if (side2MatchesBase) matchMask = 5;
|
|
568
|
+
else if (sidesMatch) matchMask = 6;
|
|
569
|
+
const prevMask = this.dirRenameMask;
|
|
570
|
+
if (dirmask === 0) {
|
|
571
|
+
const resolvedTo =
|
|
572
|
+
side1MatchesBase && side2MatchesBase
|
|
573
|
+
? b
|
|
574
|
+
: filemask === 7 && sidesMatch
|
|
575
|
+
? s1
|
|
576
|
+
: filemask === 7 && side1MatchesBase
|
|
577
|
+
? s2
|
|
578
|
+
: filemask === 7 && side2MatchesBase
|
|
579
|
+
? s1
|
|
580
|
+
: undefined;
|
|
581
|
+
if (resolvedTo) {
|
|
582
|
+
const info = this.newInfo(dir, path);
|
|
583
|
+
info.resolved = true;
|
|
584
|
+
info.clean = true;
|
|
585
|
+
info.result = resolvedTo;
|
|
586
|
+
this.put(path, info);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
this.collectRenameInfo(path, dir, filemask, dirmask, matchMask, n.files);
|
|
591
|
+
const info = this.newInfo(dir, path);
|
|
592
|
+
info.stages = [...n.files] as Stages;
|
|
593
|
+
info.filemask = filemask;
|
|
594
|
+
info.dirmask = dirmask;
|
|
595
|
+
info.dfConflict = filemask !== 0 && dirmask !== 0;
|
|
596
|
+
if (dirmask) info.isNull = true;
|
|
597
|
+
info.matchMask = dirmask ? matchMask & filemask : matchMask;
|
|
598
|
+
this.put(path, info);
|
|
599
|
+
if (dirmask) {
|
|
600
|
+
// a directory one side left as it was: the other side's version may be taken whole,
|
|
601
|
+
// decided once the trees are read (possible_trivial_merges)
|
|
602
|
+
const s1m = side1MatchesBase || dirs1;
|
|
603
|
+
const s2m = side2MatchesBase || dirs2;
|
|
604
|
+
let side = s1m && !s2m ? 2 : s2m && !s1m ? 1 : 0;
|
|
605
|
+
if (filemask === 0 && (dirmask === 2 || dirmask === 4)) side = dirmask / 2;
|
|
606
|
+
if (
|
|
607
|
+
this.dirRenameMask !== 7 &&
|
|
608
|
+
side !== 0 &&
|
|
609
|
+
this.trivialOkay[side] &&
|
|
610
|
+
!this.targetDirs[side].has(path)
|
|
611
|
+
) {
|
|
612
|
+
this.possibleTrivial[side].set(path, this.dirRenameMask);
|
|
613
|
+
this.dirRenameMask = prevMask;
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
traverse(path);
|
|
617
|
+
this.dirRenameMask = prevMask;
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
traverse("");
|
|
621
|
+
|
|
622
|
+
// the paths git would have read: a directory all three trees hold alike is one entry
|
|
623
|
+
// (the trees given whole hold its files too)
|
|
624
|
+
const identical = new Map<string, boolean>();
|
|
625
|
+
const isIdentical = (dir: string) => {
|
|
626
|
+
let known = identical.get(dir);
|
|
627
|
+
if (known === undefined) {
|
|
628
|
+
known = sameDir(dir, 0, 1) && sameDir(dir, 0, 2);
|
|
629
|
+
identical.set(dir, known);
|
|
630
|
+
}
|
|
631
|
+
return known;
|
|
632
|
+
};
|
|
633
|
+
const countPaths = () => {
|
|
634
|
+
let count = 0;
|
|
635
|
+
for (const path of this.paths.keys()) {
|
|
636
|
+
let inside = false;
|
|
637
|
+
for (let dir = dirnameOf(path); dir !== "" && !inside; dir = dirnameOf(dir)) {
|
|
638
|
+
inside = isIdentical(dir);
|
|
639
|
+
}
|
|
640
|
+
if (!inside) count++;
|
|
641
|
+
}
|
|
642
|
+
return count;
|
|
643
|
+
};
|
|
644
|
+
const countBefore = countPaths();
|
|
645
|
+
let readDeferred = false;
|
|
646
|
+
|
|
647
|
+
// handle_deferred_entries: a side whose rename sources the merge needs are all known
|
|
648
|
+
// (none, or found by a first pass) takes its directories whole, but those a known
|
|
649
|
+
// rename goes into; otherwise they are read now (their paths after all the others)
|
|
650
|
+
for (const side of [1, 2] as const) {
|
|
651
|
+
let okay = true;
|
|
652
|
+
for (const source of this.relevant[side].keys()) {
|
|
653
|
+
if (this.cachedIrrelevant[side].has(source)) continue;
|
|
654
|
+
if (!this.cachedPairs[side].has(source)) {
|
|
655
|
+
okay = false;
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
const target = this.cachedPairs[side].get(source);
|
|
659
|
+
if (target === undefined || this.paths.has(target)) continue;
|
|
660
|
+
let dir = target;
|
|
661
|
+
for (let k = dir.lastIndexOf("/"); k >= 0; k = dir.lastIndexOf("/")) {
|
|
662
|
+
dir = dir.slice(0, k);
|
|
663
|
+
if (this.targetDirs[side].has(dir)) break;
|
|
664
|
+
this.targetDirs[side].add(dir);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (!okay) readDeferred = true;
|
|
668
|
+
this.trivialOkay[side] = okay;
|
|
669
|
+
const deferred = this.possibleTrivial[side];
|
|
670
|
+
this.possibleTrivial[side] = new Map();
|
|
671
|
+
for (const path of gitHashOrder(deferred.keys())) {
|
|
672
|
+
if (okay && !this.targetDirs[side].has(path)) {
|
|
673
|
+
this.resolveTrivial(path, side);
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
this.dirRenameMask = deferred.get(path) as number;
|
|
677
|
+
traverse(path);
|
|
678
|
+
this.dirRenameMask = 0;
|
|
679
|
+
}
|
|
680
|
+
for (const path of gitHashOrder(this.possibleTrivial[side].keys())) {
|
|
681
|
+
this.resolveTrivial(path, side);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
if (readDeferred) {
|
|
685
|
+
// reading the deferred directories tripled the paths: worth a second pass once the
|
|
686
|
+
// renames are known (redo_after_renames)
|
|
687
|
+
const countAfter = countPaths();
|
|
688
|
+
if (this.redoAfterRenames === 0 && countBefore > 0) {
|
|
689
|
+
if (Math.floor(countAfter / countBefore) >= 3) this.redoAfterRenames = 1;
|
|
690
|
+
}
|
|
691
|
+
} else if (this.redoAfterRenames === 2) {
|
|
692
|
+
this.redoAfterRenames = 0;
|
|
693
|
+
}
|
|
694
|
+
this.trees = trees;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/** resolve_trivial_directory_merge: the directory is the side's, whole. */
|
|
698
|
+
private resolveTrivial(path: string, side: 1 | 2): void {
|
|
699
|
+
const info = this.paths.get(path) as Info;
|
|
700
|
+
info.matchMask = 0;
|
|
701
|
+
info.clean = true;
|
|
702
|
+
this.trivialSide.set(path, side);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/** merge-ort's collect_rename_info: the rename sources and destinations, their relevance. */
|
|
706
|
+
private collectRenameInfo(
|
|
707
|
+
fullname: string,
|
|
708
|
+
dirname: string,
|
|
709
|
+
filemask: number,
|
|
710
|
+
dirmask: number,
|
|
711
|
+
matchMask: number,
|
|
712
|
+
files: Stages,
|
|
713
|
+
): void {
|
|
714
|
+
if (this.dirRenameMask !== 7 && (dirmask === 3 || dirmask === 5)) {
|
|
715
|
+
this.dirRenameMask = dirmask & ~1;
|
|
716
|
+
}
|
|
717
|
+
if (dirmask === 1 || dirmask === 3 || dirmask === 5) {
|
|
718
|
+
const sides = (7 - dirmask) / 2;
|
|
719
|
+
const relevance = this.dirRenameMask === 7 ? RELEVANT_FOR_ANCESTOR : 0;
|
|
720
|
+
if (sides & 1) this.dirsRemoved[1].set(fullname, relevance);
|
|
721
|
+
if (sides & 2) this.dirsRemoved[2].set(fullname, relevance);
|
|
722
|
+
}
|
|
723
|
+
if (this.dirRenameMask === 7 && (filemask === 2 || filemask === 4)) {
|
|
724
|
+
const side = 3 - (filemask >> 1);
|
|
725
|
+
this.dirsRemoved[side].set(dirname, RELEVANT_FOR_SELF);
|
|
726
|
+
}
|
|
727
|
+
if (filemask === 0 || filemask === 7) return;
|
|
728
|
+
for (const side of [1, 2] as const) {
|
|
729
|
+
const sideMask = 1 << side;
|
|
730
|
+
if (filemask & 1 && !(filemask & sideMask)) {
|
|
731
|
+
const contentRelevant = (matchMask & filemask) === 0;
|
|
732
|
+
const locationRelevant = this.dirRenameMask === 7;
|
|
733
|
+
if (contentRelevant) this.cachedIrrelevant[side].delete(fullname);
|
|
734
|
+
if (contentRelevant || locationRelevant) {
|
|
735
|
+
this.relevant[side].set(fullname, contentRelevant ? RELEVANT_CONTENT : RELEVANT_LOCATION);
|
|
736
|
+
}
|
|
737
|
+
// a rename (or deletion) a first pass found is not detected again
|
|
738
|
+
if (this.cachedPairs[side].has(fullname) || this.cachedIrrelevant[side].has(fullname)) {
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
if (files[0]) {
|
|
742
|
+
this.deletes[side].push(fullname);
|
|
743
|
+
this.queue[side].push({ path: fullname, add: false });
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
if (!(filemask & 1) && filemask & sideMask && !this.cachedTargets[side].has(fullname)) {
|
|
747
|
+
this.adds[side].push(fullname);
|
|
748
|
+
this.queue[side].push({ path: fullname, add: true });
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// ---- renames --------------------------------------------------------------------------
|
|
754
|
+
|
|
755
|
+
/** Rename detection of one side (detect_regular_renames): its renames and adds. */
|
|
756
|
+
private async detectSide(side: 1 | 2): Promise<{ pairs: Pair[]; ran: boolean }> {
|
|
757
|
+
const deletes = this.deletes[side];
|
|
758
|
+
const adds = this.adds[side];
|
|
759
|
+
const pairs: Pair[] = [];
|
|
760
|
+
const addPairs = () => adds.map((p): Pair => ({ status: "A", one: p, two: p, side }));
|
|
761
|
+
// prune_cached_from_relevant: what a first pass found is not looked for again
|
|
762
|
+
for (const path of this.cachedPairs[side].keys()) this.relevant[side].delete(path);
|
|
763
|
+
for (const path of this.cachedIrrelevant[side]) this.relevant[side].delete(path);
|
|
764
|
+
if (deletes.length + adds.length === 0) return { pairs, ran: false };
|
|
765
|
+
// no source the merge needs: no rename detection at all
|
|
766
|
+
if (this.relevant[side].size === 0) return { pairs: addPairs(), ran: false };
|
|
767
|
+
const candidate = (path: string, stage: number): RenameCandidate => {
|
|
768
|
+
const e = this.paths.get(path)?.stages[stage] as CheckedEntry;
|
|
769
|
+
return { path, mode: e.mode, id: e.objectId };
|
|
770
|
+
};
|
|
771
|
+
const renames = await detectRenames(
|
|
772
|
+
deletes.map((p) => candidate(p, 0)),
|
|
773
|
+
adds.map((p) => candidate(p, side)),
|
|
774
|
+
{
|
|
775
|
+
renameEmpty: false,
|
|
776
|
+
renameLimit: this.options.renameLimit ?? 7000,
|
|
777
|
+
load: (c) => readBlob(this.blobs, c.id),
|
|
778
|
+
prefetch: async (wanted) => {
|
|
779
|
+
await this.blobs.prefetch?.(
|
|
780
|
+
wanted.filter((w) => w.candidate.mode !== FileMode.GITLINK).map((w) => w.candidate.id),
|
|
781
|
+
);
|
|
782
|
+
},
|
|
783
|
+
relevantSources: this.relevant[side],
|
|
784
|
+
dirsRemoved: this.dirsRemoved[side],
|
|
785
|
+
dirRenameCount: this.dirRenameCount[side],
|
|
786
|
+
cachedPairs: this.cachedPairs[side],
|
|
787
|
+
onRenameLimit: () => {
|
|
788
|
+
this.renameLimitHit = true;
|
|
789
|
+
},
|
|
790
|
+
keepOrder: true,
|
|
791
|
+
},
|
|
792
|
+
);
|
|
793
|
+
const renamedTo = new Map(renames.map((r) => [r.to, r.from]));
|
|
794
|
+
for (const p of adds) {
|
|
795
|
+
const from = renamedTo.get(p);
|
|
796
|
+
pairs.push(
|
|
797
|
+
from !== undefined
|
|
798
|
+
? { status: "R", one: from, two: p, side }
|
|
799
|
+
: { status: "A", one: p, two: p, side },
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
return { pairs, ran: true };
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* possibly_cache_new_pair for each pair of a side's diff queue after rename detection:
|
|
807
|
+
* the renames and deletions of the sources the merge needs, for a redo.
|
|
808
|
+
*/
|
|
809
|
+
private cacheRenames(side: 1 | 2, pairs: Pair[]): void {
|
|
810
|
+
const renamedTo = new Map<string, string>();
|
|
811
|
+
for (const p of pairs) if (p.status === "R") renamedTo.set(p.two, p.one);
|
|
812
|
+
const renamedFrom = new Set(renamedTo.values());
|
|
813
|
+
const relevance = (path: string) => this.relevant[side].get(path) ?? -1;
|
|
814
|
+
for (const { path, add } of this.queue[side]) {
|
|
815
|
+
if (add) {
|
|
816
|
+
const from = renamedTo.get(path);
|
|
817
|
+
if (from === undefined || relevance(from) <= 0) continue;
|
|
818
|
+
this.cachedPairs[side].set(from, path);
|
|
819
|
+
this.cachedTargets[side].add(path);
|
|
820
|
+
} else if (!renamedFrom.has(path)) {
|
|
821
|
+
const value = relevance(path);
|
|
822
|
+
if (value === 0) this.cachedIrrelevant[side].add(path);
|
|
823
|
+
if (value > 0) this.cachedPairs[side].set(path, undefined);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* use_cached_pairs: the renames a first pass found, but those into a path the merge has
|
|
830
|
+
* no (or a clean) entry for (git >= 2.55).
|
|
831
|
+
*/
|
|
832
|
+
private cachedRenamePairs(side: 1 | 2): Pair[] {
|
|
833
|
+
const pairs: Pair[] = [];
|
|
834
|
+
for (const from of gitHashOrder(this.cachedPairs[side].keys())) {
|
|
835
|
+
const to = this.cachedPairs[side].get(from);
|
|
836
|
+
if (to === undefined) continue;
|
|
837
|
+
const info = this.paths.get(to);
|
|
838
|
+
if (!info || info.clean) continue;
|
|
839
|
+
pairs.push({ status: "R", one: from, two: to, side });
|
|
840
|
+
}
|
|
841
|
+
return pairs;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/** detect_and_process_renames; true when the merge is to be redone (redo_after_renames). */
|
|
845
|
+
private async detectAndProcessRenames(): Promise<boolean> {
|
|
846
|
+
const detected = [await this.detectSide(1), await this.detectSide(2)];
|
|
847
|
+
if (this.renameLimitHit) this.redoAfterRenames = 0;
|
|
848
|
+
if (this.redoAfterRenames === 1 && detected.some((d) => d.ran)) {
|
|
849
|
+
this.cacheRenames(1, detected[0].pairs);
|
|
850
|
+
this.cacheRenames(2, detected[1].pairs);
|
|
851
|
+
this.redoAfterRenames = 2;
|
|
852
|
+
return true;
|
|
853
|
+
}
|
|
854
|
+
const sidePairs: Pair[][] = [
|
|
855
|
+
[],
|
|
856
|
+
[...detected[0].pairs, ...this.cachedRenamePairs(1)],
|
|
857
|
+
[...detected[1].pairs, ...this.cachedRenamePairs(2)],
|
|
858
|
+
];
|
|
859
|
+
if (this.depth === 0 && this.dirRenamesMode !== "false") {
|
|
860
|
+
this.provisionalDirectoryRenames(1);
|
|
861
|
+
this.provisionalDirectoryRenames(2);
|
|
862
|
+
// a directory both sides renamed is no directory rename at all
|
|
863
|
+
for (const dir of [...this.dirRenames[1].keys()]) {
|
|
864
|
+
if (this.dirRenames[2].has(dir)) {
|
|
865
|
+
this.dirRenames[1].delete(dir);
|
|
866
|
+
this.dirRenames[2].delete(dir);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
const collisions: Map<string, { sources: string[]; reported: boolean }>[] = [
|
|
871
|
+
new Map(),
|
|
872
|
+
this.computeCollisions(this.dirRenames[2], sidePairs[1]),
|
|
873
|
+
this.computeCollisions(this.dirRenames[1], sidePairs[2]),
|
|
874
|
+
];
|
|
875
|
+
const combined: Pair[] = [];
|
|
876
|
+
for (const side of [1, 2] as const) {
|
|
877
|
+
const other = (3 - side) as 1 | 2;
|
|
878
|
+
for (const pair of sidePairs[side]) {
|
|
879
|
+
if (this.dirRenamesMode === "false" && pair.status === "R") {
|
|
880
|
+
combined.push(pair);
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
const newPath = this.checkForDirectoryRename(
|
|
884
|
+
pair,
|
|
885
|
+
this.dirRenames[other],
|
|
886
|
+
this.dirRenames[side],
|
|
887
|
+
collisions,
|
|
888
|
+
);
|
|
889
|
+
if (pair.status !== "R" && newPath === undefined) continue;
|
|
890
|
+
if (newPath !== undefined) this.applyDirectoryRenameModifications(pair, newPath);
|
|
891
|
+
combined.push(pair);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
// stable, by source path
|
|
895
|
+
combined.sort((a, b) => compareStrings(a.one, b.one));
|
|
896
|
+
await this.processRenames(combined);
|
|
897
|
+
return false;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/** merge-ort's get_provisional_directory_renames: each removed directory's majority. */
|
|
901
|
+
private provisionalDirectoryRenames(side: 1 | 2): void {
|
|
902
|
+
for (const [sourceDir, counts] of this.dirRenameCount[side]) {
|
|
903
|
+
let max = 0;
|
|
904
|
+
let badMax = 0;
|
|
905
|
+
let best: string | undefined;
|
|
906
|
+
for (const [targetDir, count] of counts) {
|
|
907
|
+
if (count === max) badMax = max;
|
|
908
|
+
else if (count > max) {
|
|
909
|
+
max = count;
|
|
910
|
+
best = targetDir;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (max === 0) continue;
|
|
914
|
+
if (badMax === max) {
|
|
915
|
+
this.say(
|
|
916
|
+
sourceDir,
|
|
917
|
+
`CONFLICT (directory rename split): Unclear where to rename ${sourceDir} to; it was renamed to multiple other directories, with no destination getting a majority of the files.`,
|
|
918
|
+
);
|
|
919
|
+
this.renamesClean = false;
|
|
920
|
+
} else if (best !== undefined) {
|
|
921
|
+
this.dirRenames[side].set(sourceDir, best);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/** The nearest renamed directory above `path` (check_dir_renamed). */
|
|
927
|
+
private checkDirRenamed(
|
|
928
|
+
path: string,
|
|
929
|
+
dirRenames: Map<string, string>,
|
|
930
|
+
): [string, string] | undefined {
|
|
931
|
+
// each directory above the path, never the top
|
|
932
|
+
let rest = path;
|
|
933
|
+
for (let k = rest.lastIndexOf("/"); k >= 0; k = rest.lastIndexOf("/")) {
|
|
934
|
+
rest = rest.slice(0, k);
|
|
935
|
+
const to = dirRenames.get(rest);
|
|
936
|
+
if (to !== undefined) return [rest, to];
|
|
937
|
+
}
|
|
938
|
+
return undefined;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** merge-ort's apply_dir_rename. */
|
|
942
|
+
private applyDirRename([oldDir, newDir]: [string, string], oldPath: string): string {
|
|
943
|
+
const oldLen = oldDir.length + (newDir === "" ? 1 : 0);
|
|
944
|
+
return newDir + oldPath.slice(oldLen);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
private computeCollisions(
|
|
948
|
+
dirRenames: Map<string, string>,
|
|
949
|
+
pairs: Pair[],
|
|
950
|
+
): Map<string, { sources: string[]; reported: boolean }> {
|
|
951
|
+
const collisions = new Map<string, { sources: string[]; reported: boolean }>();
|
|
952
|
+
if (dirRenames.size === 0) return collisions;
|
|
953
|
+
for (const pair of pairs) {
|
|
954
|
+
const rename = this.checkDirRenamed(pair.two, dirRenames);
|
|
955
|
+
if (!rename) continue;
|
|
956
|
+
const newPath = this.applyDirRename(rename, pair.two);
|
|
957
|
+
let info = collisions.get(newPath);
|
|
958
|
+
if (!info) {
|
|
959
|
+
info = { sources: [], reported: false };
|
|
960
|
+
collisions.set(newPath, info);
|
|
961
|
+
}
|
|
962
|
+
if (!info.sources.includes(pair.two)) {
|
|
963
|
+
info.sources.push(pair.two);
|
|
964
|
+
info.sources.sort(compareStrings);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return collisions;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/** merge-ort's path_in_way. */
|
|
971
|
+
private pathInWay(path: string, sideMask: number, pair: Pair): boolean {
|
|
972
|
+
const info = this.paths.get(path);
|
|
973
|
+
if (!info) return false;
|
|
974
|
+
return (
|
|
975
|
+
info.clean ||
|
|
976
|
+
(sideMask & (info.filemask | info.dirmask)) !== 0 ||
|
|
977
|
+
((info.filemask & 1) !== 0 && pair.one !== path)
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/** merge-ort's check_for_directory_rename (with handle_path_level_conflicts). */
|
|
982
|
+
private checkForDirectoryRename(
|
|
983
|
+
pair: Pair,
|
|
984
|
+
dirRenames: Map<string, string>,
|
|
985
|
+
exclusions: Map<string, string>,
|
|
986
|
+
collisions: Map<string, { sources: string[]; reported: boolean }>[],
|
|
987
|
+
): string | undefined {
|
|
988
|
+
const path = pair.two;
|
|
989
|
+
const side = pair.side;
|
|
990
|
+
if (dirRenames.size === 0) return undefined;
|
|
991
|
+
if (collisions[3 - side].has(path)) return undefined;
|
|
992
|
+
const rename = this.checkDirRenamed(path, dirRenames);
|
|
993
|
+
if (!rename) return undefined;
|
|
994
|
+
const [oldDir, newDir] = rename;
|
|
995
|
+
if (exclusions.has(newDir)) {
|
|
996
|
+
this.say(
|
|
997
|
+
oldDir,
|
|
998
|
+
`WARNING: Avoiding applying ${oldDir} -> ${newDir} rename to ${path}, because ${newDir} itself was renamed.`,
|
|
999
|
+
);
|
|
1000
|
+
return undefined;
|
|
1001
|
+
}
|
|
1002
|
+
const newPath = this.applyDirRename(rename, path);
|
|
1003
|
+
const info = collisions[side].get(newPath) as { sources: string[]; reported: boolean };
|
|
1004
|
+
if (info.reported) {
|
|
1005
|
+
this.renamesClean = false;
|
|
1006
|
+
return undefined;
|
|
1007
|
+
}
|
|
1008
|
+
if (this.pathInWay(newPath, 1 << side, pair)) {
|
|
1009
|
+
info.reported = true;
|
|
1010
|
+
this.renamesClean = false;
|
|
1011
|
+
this.say(
|
|
1012
|
+
newPath,
|
|
1013
|
+
`CONFLICT (implicit dir rename): Existing file/dir at ${newPath} in the way of implicit directory rename(s) putting the following path(s) there: ${info.sources.join(", ")}.`,
|
|
1014
|
+
);
|
|
1015
|
+
return undefined;
|
|
1016
|
+
}
|
|
1017
|
+
if (info.sources.length > 1) {
|
|
1018
|
+
info.reported = true;
|
|
1019
|
+
this.renamesClean = false;
|
|
1020
|
+
this.say(
|
|
1021
|
+
newPath,
|
|
1022
|
+
`CONFLICT (implicit dir rename): Cannot map more than one path to ${newPath}; implicit directory renames tried to put these paths there: ${info.sources.join(", ")}`,
|
|
1023
|
+
);
|
|
1024
|
+
return undefined;
|
|
1025
|
+
}
|
|
1026
|
+
return newPath;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/** merge-ort's apply_directory_rename_modifications: the path moves into the new directory. */
|
|
1030
|
+
private applyDirectoryRenameModifications(pair: Pair, newPath: string): void {
|
|
1031
|
+
const oldPath = pair.two;
|
|
1032
|
+
let ci = this.paths.get(oldPath) as Info;
|
|
1033
|
+
// the missing directories above the new path
|
|
1034
|
+
const dirsToInsert: string[] = [];
|
|
1035
|
+
let parent = "";
|
|
1036
|
+
for (let cur = newPath; ; ) {
|
|
1037
|
+
const k = cur.lastIndexOf("/");
|
|
1038
|
+
if (k < 0) {
|
|
1039
|
+
parent = "";
|
|
1040
|
+
break;
|
|
1041
|
+
}
|
|
1042
|
+
parent = cur.slice(0, k);
|
|
1043
|
+
if (this.paths.has(parent)) break;
|
|
1044
|
+
dirsToInsert.push(parent);
|
|
1045
|
+
cur = parent;
|
|
1046
|
+
}
|
|
1047
|
+
for (let i = dirsToInsert.length - 1; i >= 0; i--) {
|
|
1048
|
+
const dirCi = this.newInfo(parent, dirsToInsert[i]);
|
|
1049
|
+
dirCi.dirmask = ci.filemask;
|
|
1050
|
+
this.put(dirsToInsert[i], dirCi);
|
|
1051
|
+
parent = dirsToInsert[i];
|
|
1052
|
+
}
|
|
1053
|
+
if (ci.dirmask === 0) this.paths.delete(oldPath);
|
|
1054
|
+
else {
|
|
1055
|
+
const moved: Info = { ...ci, stages: [...ci.stages] as Stages, pathnames: [...ci.pathnames] };
|
|
1056
|
+
moved.dirmask = 0;
|
|
1057
|
+
moved.stages[1] = undefined;
|
|
1058
|
+
ci.filemask = 0;
|
|
1059
|
+
ci.clean = true;
|
|
1060
|
+
for (let i = 0; i < 3; i++) if (!(ci.dirmask & (1 << i))) ci.stages[i] = undefined;
|
|
1061
|
+
ci = moved;
|
|
1062
|
+
}
|
|
1063
|
+
const withNewPath = ci.filemask === 2 ? this.branch1 : this.branch2;
|
|
1064
|
+
const withDirRename = ci.filemask === 2 ? this.branch2 : this.branch1;
|
|
1065
|
+
ci.dir = parent;
|
|
1066
|
+
const existing = this.paths.get(newPath);
|
|
1067
|
+
if (!existing) this.put(newPath, ci);
|
|
1068
|
+
else {
|
|
1069
|
+
existing.filemask |= ci.filemask;
|
|
1070
|
+
if (existing.dirmask) existing.dfConflict = true;
|
|
1071
|
+
const index = ci.filemask >> 1;
|
|
1072
|
+
existing.pathnames[index] = ci.pathnames[index];
|
|
1073
|
+
existing.stages[index] = ci.stages[index];
|
|
1074
|
+
ci = existing;
|
|
1075
|
+
}
|
|
1076
|
+
if (this.dirRenamesMode === "true") {
|
|
1077
|
+
this.say(
|
|
1078
|
+
newPath,
|
|
1079
|
+
pair.status === "A"
|
|
1080
|
+
? `Path updated: ${oldPath} added in ${withNewPath} inside a directory that was renamed in ${withDirRename}; moving it to ${newPath}.`
|
|
1081
|
+
: `Path updated: ${pair.one} renamed to ${oldPath} in ${withNewPath}, inside a directory that was renamed in ${withDirRename}; moving it to ${newPath}.`,
|
|
1082
|
+
);
|
|
1083
|
+
} else {
|
|
1084
|
+
ci.pathConflict = true;
|
|
1085
|
+
this.say(
|
|
1086
|
+
newPath,
|
|
1087
|
+
pair.status === "A"
|
|
1088
|
+
? `CONFLICT (file location): ${oldPath} added in ${withNewPath} inside a directory that was renamed in ${withDirRename}, suggesting it should perhaps be moved to ${newPath}.`
|
|
1089
|
+
: `CONFLICT (file location): ${pair.one} renamed to ${oldPath} in ${withNewPath}, inside a directory that was renamed in ${withDirRename}, suggesting it should perhaps be moved to ${newPath}.`,
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1092
|
+
pair.two = newPath;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/** merge-ort's process_renames. */
|
|
1096
|
+
private async processRenames(renames: Pair[]): Promise<void> {
|
|
1097
|
+
// process_renames answers the clean flag of its last rename/rename content merge
|
|
1098
|
+
let cleanMerge = true;
|
|
1099
|
+
for (let i = 0; i < renames.length; i++) {
|
|
1100
|
+
const pair = renames[i];
|
|
1101
|
+
const oldPath = pair.one;
|
|
1102
|
+
const newPath = pair.two;
|
|
1103
|
+
const oldinfo = this.paths.get(oldPath);
|
|
1104
|
+
const newinfo = this.paths.get(newPath);
|
|
1105
|
+
// a directory rename can move a renamed path back where it was (rename-to-self):
|
|
1106
|
+
// nothing to move (git >= 2.5x; older versions resolved the path away)
|
|
1107
|
+
if (oldPath === newPath) continue;
|
|
1108
|
+
if (!oldinfo || oldinfo.clean) continue;
|
|
1109
|
+
|
|
1110
|
+
if (i + 1 < renames.length && renames[i + 1].one === oldPath) {
|
|
1111
|
+
// rename/rename(1to2) or rename/rename(1to1)
|
|
1112
|
+
const pathnames: [string, string, string] = [oldPath, newPath, renames[i + 1].two];
|
|
1113
|
+
const base = this.paths.get(pathnames[0]) as Info;
|
|
1114
|
+
const side1 = this.paths.get(pathnames[1]) as Info;
|
|
1115
|
+
const side2 = this.paths.get(pathnames[2]) as Info;
|
|
1116
|
+
if (pathnames[1] === pathnames[2]) {
|
|
1117
|
+
// both sides renamed the same way
|
|
1118
|
+
side1.stages[0] = base.stages[0];
|
|
1119
|
+
side1.filemask |= 1;
|
|
1120
|
+
base.isNull = true;
|
|
1121
|
+
base.clean = true;
|
|
1122
|
+
i++;
|
|
1123
|
+
continue;
|
|
1124
|
+
}
|
|
1125
|
+
const merged = await this.handleContentMerge(
|
|
1126
|
+
oldPath,
|
|
1127
|
+
base.stages[0],
|
|
1128
|
+
side1.stages[1] as CheckedEntry,
|
|
1129
|
+
side2.stages[2] as CheckedEntry,
|
|
1130
|
+
pathnames,
|
|
1131
|
+
1 + 2 * this.depth,
|
|
1132
|
+
);
|
|
1133
|
+
cleanMerge = merged.clean;
|
|
1134
|
+
const wasBinary =
|
|
1135
|
+
!merged.clean &&
|
|
1136
|
+
merged.entry.mode === side1.stages[1]?.mode &&
|
|
1137
|
+
merged.entry.objectId === side1.stages[1]?.objectId;
|
|
1138
|
+
side1.stages[1] = merged.entry;
|
|
1139
|
+
side2.stages[2] = wasBinary ? side2.stages[2] : merged.entry;
|
|
1140
|
+
side1.pathConflict = true;
|
|
1141
|
+
side2.pathConflict = true;
|
|
1142
|
+
base.pathConflict = true;
|
|
1143
|
+
this.say(
|
|
1144
|
+
pathnames[0],
|
|
1145
|
+
`CONFLICT (rename/rename): ${pathnames[0]} renamed to ${pathnames[1]} in ${this.branch1} and to ${pathnames[2]} in ${this.branch2}.`,
|
|
1146
|
+
);
|
|
1147
|
+
i++;
|
|
1148
|
+
continue;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
const target = pair.side;
|
|
1152
|
+
const otherSource = 3 - target;
|
|
1153
|
+
const ni = newinfo as Info;
|
|
1154
|
+
const oldSideMask = 1 << otherSource;
|
|
1155
|
+
const sourceDeleted = oldinfo.filemask === 1;
|
|
1156
|
+
let collision = (ni.filemask & oldSideMask) !== 0;
|
|
1157
|
+
const typeChanged =
|
|
1158
|
+
!sourceDeleted && isReg(oldinfo.stages[otherSource]) !== isReg(ni.stages[target]);
|
|
1159
|
+
if (typeChanged && collision) collision = false;
|
|
1160
|
+
const [renameBranch, deleteBranch] =
|
|
1161
|
+
target === 1 ? [this.branch1, this.branch2] : [this.branch2, this.branch1];
|
|
1162
|
+
if (collision && !sourceDeleted) {
|
|
1163
|
+
// rename/add or rename/rename(2to1)
|
|
1164
|
+
const pathnames: [string, string, string] = [oldPath, oldPath, oldPath];
|
|
1165
|
+
pathnames[target] = newPath;
|
|
1166
|
+
const base = this.paths.get(pathnames[0]) as Info;
|
|
1167
|
+
const side1 = this.paths.get(pathnames[1]) as Info;
|
|
1168
|
+
const side2 = this.paths.get(pathnames[2]) as Info;
|
|
1169
|
+
const merged = await this.handleContentMerge(
|
|
1170
|
+
oldPath,
|
|
1171
|
+
base.stages[0],
|
|
1172
|
+
side1.stages[1] as CheckedEntry,
|
|
1173
|
+
side2.stages[2] as CheckedEntry,
|
|
1174
|
+
pathnames,
|
|
1175
|
+
1 + 2 * this.depth,
|
|
1176
|
+
);
|
|
1177
|
+
ni.stages[target] = merged.entry;
|
|
1178
|
+
if (!merged.clean) {
|
|
1179
|
+
this.say(
|
|
1180
|
+
newPath,
|
|
1181
|
+
`CONFLICT (rename involved in collision): rename of ${oldPath} -> ${newPath} has content conflicts AND collides with another path; this may result in nested conflict markers.`,
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
} else if (collision && sourceDeleted) {
|
|
1185
|
+
ni.pathConflict = true;
|
|
1186
|
+
this.say(
|
|
1187
|
+
newPath,
|
|
1188
|
+
`CONFLICT (rename/delete): ${oldPath} renamed to ${newPath} in ${renameBranch}, but deleted in ${deleteBranch}.`,
|
|
1189
|
+
);
|
|
1190
|
+
} else {
|
|
1191
|
+
ni.stages[0] = oldinfo.stages[0];
|
|
1192
|
+
ni.filemask |= 1;
|
|
1193
|
+
ni.pathnames[0] = oldPath;
|
|
1194
|
+
if (typeChanged) {
|
|
1195
|
+
// rename vs. typechange: the original is resolved by removal
|
|
1196
|
+
oldinfo.stages[0] = undefined;
|
|
1197
|
+
oldinfo.filemask &= 6;
|
|
1198
|
+
} else if (sourceDeleted) {
|
|
1199
|
+
ni.pathConflict = true;
|
|
1200
|
+
this.say(
|
|
1201
|
+
newPath,
|
|
1202
|
+
`CONFLICT (rename/delete): ${oldPath} renamed to ${newPath} in ${renameBranch}, but deleted in ${deleteBranch}.`,
|
|
1203
|
+
);
|
|
1204
|
+
} else {
|
|
1205
|
+
ni.stages[otherSource] = oldinfo.stages[otherSource];
|
|
1206
|
+
ni.filemask |= 1 << otherSource;
|
|
1207
|
+
ni.pathnames[otherSource] = oldPath;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
if (!typeChanged) {
|
|
1211
|
+
oldinfo.isNull = true;
|
|
1212
|
+
oldinfo.clean = true;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
if (!cleanMerge) this.renamesClean = false;
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
// ---- content merges -------------------------------------------------------------------
|
|
1219
|
+
|
|
1220
|
+
private async read(e?: CheckedEntry): Promise<Uint8Array> {
|
|
1221
|
+
return e && isReg(e) ? readBlob(this.blobs, e.objectId) : new Uint8Array(0);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* merge-ort's merge_3way (ll_merge): the merge driver of the path's `merge` attribute
|
|
1226
|
+
* (text, binary, union or a registered one) with its markers.
|
|
1227
|
+
*/
|
|
1228
|
+
private async merge3way(
|
|
1229
|
+
path: string,
|
|
1230
|
+
o: CheckedEntry | undefined,
|
|
1231
|
+
a: CheckedEntry,
|
|
1232
|
+
b: CheckedEntry,
|
|
1233
|
+
pathnames: [string, string, string],
|
|
1234
|
+
extraMarkerSize: number,
|
|
1235
|
+
): Promise<{ status: "ok" | "conflict" | "binary"; content: Uint8Array }> {
|
|
1236
|
+
const same = pathnames[0] === pathnames[1] && pathnames[1] === pathnames[2];
|
|
1237
|
+
const baseLabel = same ? this.ancestor : `${this.ancestor}:${pathnames[0]}`;
|
|
1238
|
+
const oursLabel = same ? this.branch1 : `${this.branch1}:${pathnames[1]}`;
|
|
1239
|
+
const theirsLabel = same ? this.branch2 : `${this.branch2}:${pathnames[2]}`;
|
|
1240
|
+
let [orig, src1, src2] = [await this.read(o), await this.read(a), await this.read(b)];
|
|
1241
|
+
if (this.options.renormalize && this.options.renormalizeContent) {
|
|
1242
|
+
const norm = this.options.renormalizeContent;
|
|
1243
|
+
[orig, src1, src2] = [await norm(path, orig), await norm(path, src1), await norm(path, src2)];
|
|
1244
|
+
}
|
|
1245
|
+
return lowLevelMerge(
|
|
1246
|
+
{ path, base: orig, ours: src1, theirs: src2, baseLabel, oursLabel, theirsLabel },
|
|
1247
|
+
{
|
|
1248
|
+
attributes: (await this.options.attributes?.(path)) ?? {},
|
|
1249
|
+
...(this.options.drivers ? { drivers: this.options.drivers } : {}),
|
|
1250
|
+
...(this.options.defaultDriver ? { defaultDriver: this.options.defaultDriver } : {}),
|
|
1251
|
+
...(this.options.recursiveDriver ? { recursiveDriver: this.options.recursiveDriver } : {}),
|
|
1252
|
+
virtualAncestor: this.depth > 0,
|
|
1253
|
+
...(this.options.favor ? { favor: this.options.favor } : {}),
|
|
1254
|
+
...(this.options.style ? { style: this.options.style } : {}),
|
|
1255
|
+
extraMarkerSize,
|
|
1256
|
+
...(this.options.bigFileThreshold !== undefined
|
|
1257
|
+
? { bigFileThreshold: this.options.bigFileThreshold }
|
|
1258
|
+
: {}),
|
|
1259
|
+
},
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/** merge-ort's handle_content_merge: two versions of a type merged, with their mode. */
|
|
1264
|
+
private async handleContentMerge(
|
|
1265
|
+
path: string,
|
|
1266
|
+
o: CheckedEntry | undefined,
|
|
1267
|
+
a: CheckedEntry,
|
|
1268
|
+
b: CheckedEntry,
|
|
1269
|
+
pathnames: [string, string, string],
|
|
1270
|
+
extraMarkerSize: number,
|
|
1271
|
+
): Promise<{ entry: CheckedEntry; clean: boolean }> {
|
|
1272
|
+
let clean = true;
|
|
1273
|
+
let mode: number;
|
|
1274
|
+
if (a.mode === b.mode || a.mode === o?.mode) mode = b.mode;
|
|
1275
|
+
else {
|
|
1276
|
+
mode = a.mode;
|
|
1277
|
+
clean = b.mode === o?.mode;
|
|
1278
|
+
}
|
|
1279
|
+
if (a.objectId === b.objectId || a.objectId === o?.objectId) {
|
|
1280
|
+
return { entry: { objectId: b.objectId, mode }, clean };
|
|
1281
|
+
}
|
|
1282
|
+
if (b.objectId === o?.objectId) return { entry: { objectId: a.objectId, mode }, clean };
|
|
1283
|
+
if (isReg(a)) {
|
|
1284
|
+
const twoWay = typeOf(o) !== typeOf(a);
|
|
1285
|
+
const merged = await this.merge3way(
|
|
1286
|
+
path,
|
|
1287
|
+
twoWay ? undefined : o,
|
|
1288
|
+
a,
|
|
1289
|
+
b,
|
|
1290
|
+
pathnames,
|
|
1291
|
+
extraMarkerSize,
|
|
1292
|
+
);
|
|
1293
|
+
const objectId = await this.blobs.store([merged.content]);
|
|
1294
|
+
if (merged.status === "binary") {
|
|
1295
|
+
const [, n1, n2] =
|
|
1296
|
+
pathnames[0] === pathnames[1] && pathnames[1] === pathnames[2]
|
|
1297
|
+
? [this.ancestor, this.branch1, this.branch2]
|
|
1298
|
+
: [
|
|
1299
|
+
`${this.ancestor}:${pathnames[0]}`,
|
|
1300
|
+
`${this.branch1}:${pathnames[1]}`,
|
|
1301
|
+
`${this.branch2}:${pathnames[2]}`,
|
|
1302
|
+
];
|
|
1303
|
+
this.say(path, `warning: Cannot merge binary files: ${path} (${n1} vs. ${n2})`);
|
|
1304
|
+
}
|
|
1305
|
+
this.say(path, `Auto-merging ${path}`);
|
|
1306
|
+
return { entry: { objectId, mode }, clean: clean && merged.status === "ok" };
|
|
1307
|
+
}
|
|
1308
|
+
if (isGitlink(a)) {
|
|
1309
|
+
// merge_submodule cannot look into the submodule: ours stands (the base's inside
|
|
1310
|
+
// a merge of merge bases), a conflict
|
|
1311
|
+
const twoWay = typeOf(o) !== typeOf(a);
|
|
1312
|
+
if (this.depth > 0) {
|
|
1313
|
+
if (twoWay) return { entry: o ?? { objectId: "", mode: 0 }, clean: false };
|
|
1314
|
+
return { entry: { objectId: (o as CheckedEntry).objectId, mode }, clean: false };
|
|
1315
|
+
}
|
|
1316
|
+
return { entry: { objectId: a.objectId, mode }, clean: false };
|
|
1317
|
+
}
|
|
1318
|
+
if (isLink(a)) {
|
|
1319
|
+
if (this.depth > 0) {
|
|
1320
|
+
return { entry: o ? { ...o } : { objectId: "", mode: 0 }, clean: false };
|
|
1321
|
+
}
|
|
1322
|
+
if (this.options.favor === "ours") return { entry: { objectId: a.objectId, mode }, clean };
|
|
1323
|
+
if (this.options.favor === "theirs") {
|
|
1324
|
+
return { entry: { objectId: b.objectId, mode }, clean };
|
|
1325
|
+
}
|
|
1326
|
+
return { entry: { objectId: a.objectId, mode }, clean: false };
|
|
1327
|
+
}
|
|
1328
|
+
return { entry: { objectId: a.objectId, mode }, clean: false };
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
/** merge-ort's blob_unchanged (with renormalize): the side's change only a renormalization. */
|
|
1332
|
+
private async blobUnchanged(
|
|
1333
|
+
base: CheckedEntry | undefined,
|
|
1334
|
+
side: CheckedEntry | undefined,
|
|
1335
|
+
path: string,
|
|
1336
|
+
): Promise<boolean> {
|
|
1337
|
+
if (!base || !side || base.mode !== side.mode) return false;
|
|
1338
|
+
if (base.objectId === side.objectId) return true;
|
|
1339
|
+
const norm = this.options.renormalizeContent;
|
|
1340
|
+
if (!norm) return false;
|
|
1341
|
+
const [x, y] = [
|
|
1342
|
+
await norm(path, await readBlob(this.blobs, base.objectId)),
|
|
1343
|
+
await norm(path, await readBlob(this.blobs, side.objectId)),
|
|
1344
|
+
];
|
|
1345
|
+
if (x.length !== y.length) return false;
|
|
1346
|
+
for (let i = 0; i < x.length; i++) if (x[i] !== y[i]) return false;
|
|
1347
|
+
return true;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// ---- process_entries ------------------------------------------------------------------
|
|
1351
|
+
|
|
1352
|
+
private readonly nonEmptyDirs = new Set<string>();
|
|
1353
|
+
private readonly recorded = new Map<string, CheckedEntry>();
|
|
1354
|
+
|
|
1355
|
+
/** record_entry_for_tree: the entry is in the result tree (its directories not empty). */
|
|
1356
|
+
private record(path: string, info: Info): void {
|
|
1357
|
+
if (info.isNull || !info.result) return;
|
|
1358
|
+
// a directory's own entry is no content (TREE), unless it stands for a stored tree
|
|
1359
|
+
if (info.result !== TREE) this.recorded.set(path, info.result);
|
|
1360
|
+
for (let dir = dirnameOf(path); ; dir = dirnameOf(dir)) {
|
|
1361
|
+
if (this.nonEmptyDirs.has(dir)) break;
|
|
1362
|
+
this.nonEmptyDirs.add(dir);
|
|
1363
|
+
if (dir === "") break;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
private async processEntries(): Promise<void> {
|
|
1368
|
+
const plist = [...this.paths.keys()].sort(sortDirsNextToChildren);
|
|
1369
|
+
await this.prefetchForContentMerges(plist);
|
|
1370
|
+
for (let k = plist.length - 1; k >= 0; k--) {
|
|
1371
|
+
const path = plist[k];
|
|
1372
|
+
const info = this.paths.get(path);
|
|
1373
|
+
if (!info) continue;
|
|
1374
|
+
const trivial = this.trivialSide.get(path);
|
|
1375
|
+
if (trivial !== undefined && info.clean) {
|
|
1376
|
+
// a directory taken whole from one side (its file, or everything under it)
|
|
1377
|
+
const kept = info.stages[trivial];
|
|
1378
|
+
if (kept) {
|
|
1379
|
+
info.result = kept;
|
|
1380
|
+
info.isNull = false;
|
|
1381
|
+
this.record(path, info);
|
|
1382
|
+
} else if (this.options.dirTrees?.[trivial]?.has(path)) {
|
|
1383
|
+
// the side's tree as it is
|
|
1384
|
+
const id = this.options.dirTrees[trivial].get(path) as ObjectId;
|
|
1385
|
+
this.record(path, {
|
|
1386
|
+
...info,
|
|
1387
|
+
result: { objectId: id, mode: FileMode.TREE },
|
|
1388
|
+
isNull: false,
|
|
1389
|
+
});
|
|
1390
|
+
} else {
|
|
1391
|
+
const prefix = `${path}/`;
|
|
1392
|
+
for (const [p, e] of this.trees[trivial]) {
|
|
1393
|
+
if (p.startsWith(prefix)) this.record(p, { ...info, result: e, isNull: false });
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
continue;
|
|
1397
|
+
}
|
|
1398
|
+
if (info.dirmask && !info.resolved) {
|
|
1399
|
+
// write_completed_directory: the directory holds something, or nothing
|
|
1400
|
+
if (this.nonEmptyDirs.has(path)) {
|
|
1401
|
+
info.isNull = false;
|
|
1402
|
+
info.result = TREE;
|
|
1403
|
+
} else {
|
|
1404
|
+
info.isNull = true;
|
|
1405
|
+
info.result = undefined;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
if (info.clean) this.record(path, info);
|
|
1409
|
+
else await this.processEntry(path, info);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
private async processEntry(pathIn: string, ciIn: Info): Promise<void> {
|
|
1414
|
+
let path = pathIn;
|
|
1415
|
+
let ci = ciIn;
|
|
1416
|
+
let dfFileIndex = 0;
|
|
1417
|
+
if (ci.dirmask) {
|
|
1418
|
+
this.record(path, ci);
|
|
1419
|
+
if (ci.filemask === 0) return;
|
|
1420
|
+
}
|
|
1421
|
+
if (ci.dfConflict && !ci.result) {
|
|
1422
|
+
// the directory went away: the file takes the path
|
|
1423
|
+
ci.dfConflict = false;
|
|
1424
|
+
ci.clean = false;
|
|
1425
|
+
ci.isNull = false;
|
|
1426
|
+
ci.matchMask &= ~ci.dirmask;
|
|
1427
|
+
ci.dirmask = 0;
|
|
1428
|
+
for (let i = 0; i < 3; i++) if (!(ci.filemask & (1 << i))) ci.stages[i] = undefined;
|
|
1429
|
+
} else if (ci.dfConflict && ci.result) {
|
|
1430
|
+
// the directory stays: the file moves aside
|
|
1431
|
+
if (ci.filemask === 1) {
|
|
1432
|
+
ci.filemask = 0;
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
const moved: Info = {
|
|
1436
|
+
...ci,
|
|
1437
|
+
stages: [...ci.stages] as Stages,
|
|
1438
|
+
pathnames: [...ci.pathnames],
|
|
1439
|
+
result: undefined,
|
|
1440
|
+
isNull: false,
|
|
1441
|
+
};
|
|
1442
|
+
moved.matchMask &= ~moved.dirmask;
|
|
1443
|
+
moved.dirmask = 0;
|
|
1444
|
+
for (let i = 0; i < 3; i++) if (!(moved.filemask & (1 << i))) moved.stages[i] = undefined;
|
|
1445
|
+
dfFileIndex = ci.dirmask & 2 ? 2 : 1;
|
|
1446
|
+
const branch = dfFileIndex === 1 ? this.branch1 : this.branch2;
|
|
1447
|
+
const oldPath = path;
|
|
1448
|
+
path = this.uniquePath(path, this.nameOf(dfFileIndex));
|
|
1449
|
+
moved.movedFrom = oldPath;
|
|
1450
|
+
moved.dfMoved = true;
|
|
1451
|
+
this.put(path, moved);
|
|
1452
|
+
this.say(
|
|
1453
|
+
path,
|
|
1454
|
+
`CONFLICT (file/directory): directory in the way of ${oldPath} from ${branch}; moving it to ${path} instead.`,
|
|
1455
|
+
);
|
|
1456
|
+
ci.filemask = 0;
|
|
1457
|
+
ci = moved;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
if (ci.matchMask) {
|
|
1461
|
+
ci.clean = !ci.dfConflict && !ci.pathConflict;
|
|
1462
|
+
if (ci.matchMask === 6) {
|
|
1463
|
+
ci.result = ci.stages[1];
|
|
1464
|
+
} else {
|
|
1465
|
+
const othermask = 7 & ~ci.matchMask;
|
|
1466
|
+
const side = othermask === 4 ? 2 : 1;
|
|
1467
|
+
ci.result = ci.stages[side];
|
|
1468
|
+
ci.isNull = !ci.result;
|
|
1469
|
+
if (ci.isNull) ci.clean = true;
|
|
1470
|
+
}
|
|
1471
|
+
} else if (ci.filemask >= 6 && typeOf(ci.stages[1]) !== typeOf(ci.stages[2])) {
|
|
1472
|
+
// two different kinds of things (file, link, submodule)
|
|
1473
|
+
if (this.depth > 0) {
|
|
1474
|
+
ci.clean = false;
|
|
1475
|
+
ci.result = ci.stages[0];
|
|
1476
|
+
ci.isNull = !ci.result;
|
|
1477
|
+
} else {
|
|
1478
|
+
const [o, a, b] = ci.stages;
|
|
1479
|
+
let renameA = false;
|
|
1480
|
+
let renameB = false;
|
|
1481
|
+
if (isReg(a)) renameA = true;
|
|
1482
|
+
else if (isReg(b)) renameB = true;
|
|
1483
|
+
else {
|
|
1484
|
+
renameA = true;
|
|
1485
|
+
renameB = true;
|
|
1486
|
+
}
|
|
1487
|
+
const aPath = renameA ? this.uniquePath(path, this.nameOf(1)) : undefined;
|
|
1488
|
+
let bPath = renameB ? this.uniquePath(path, this.nameOf(2)) : undefined;
|
|
1489
|
+
this.say(
|
|
1490
|
+
path,
|
|
1491
|
+
renameA && renameB
|
|
1492
|
+
? `CONFLICT (distinct types): ${path} had different types on each side; renamed both of them so each can be recorded somewhere.`
|
|
1493
|
+
: `CONFLICT (distinct types): ${path} had different types on each side; renamed one of them so each can be recorded somewhere.`,
|
|
1494
|
+
);
|
|
1495
|
+
ci.clean = false;
|
|
1496
|
+
const newCi: Info = {
|
|
1497
|
+
...ci,
|
|
1498
|
+
stages: [...ci.stages] as Stages,
|
|
1499
|
+
pathnames: [...ci.pathnames],
|
|
1500
|
+
};
|
|
1501
|
+
newCi.result = b;
|
|
1502
|
+
newCi.stages[1] = undefined;
|
|
1503
|
+
newCi.filemask = 5;
|
|
1504
|
+
if (typeOf(b) !== typeOf(o)) {
|
|
1505
|
+
newCi.stages[0] = undefined;
|
|
1506
|
+
newCi.filemask = 4;
|
|
1507
|
+
}
|
|
1508
|
+
ci.result = a;
|
|
1509
|
+
ci.stages[2] = undefined;
|
|
1510
|
+
ci.filemask = 3;
|
|
1511
|
+
if (typeOf(a) !== typeOf(o)) {
|
|
1512
|
+
ci.stages[0] = undefined;
|
|
1513
|
+
ci.filemask = 2;
|
|
1514
|
+
}
|
|
1515
|
+
if (aPath) {
|
|
1516
|
+
ci.movedFrom = path;
|
|
1517
|
+
this.put(aPath, ci);
|
|
1518
|
+
}
|
|
1519
|
+
if (!bPath) bPath = path;
|
|
1520
|
+
else newCi.movedFrom = path;
|
|
1521
|
+
this.put(bPath, newCi);
|
|
1522
|
+
if (renameA && renameB) this.paths.delete(path);
|
|
1523
|
+
this.conflicted.set(bPath, newCi);
|
|
1524
|
+
this.record(bPath, newCi);
|
|
1525
|
+
if (aPath) path = aPath;
|
|
1526
|
+
}
|
|
1527
|
+
} else if (ci.filemask >= 6) {
|
|
1528
|
+
// a two-way or three-way content merge
|
|
1529
|
+
const merged = await this.handleContentMerge(
|
|
1530
|
+
path,
|
|
1531
|
+
ci.stages[0],
|
|
1532
|
+
ci.stages[1] as CheckedEntry,
|
|
1533
|
+
ci.stages[2] as CheckedEntry,
|
|
1534
|
+
ci.pathnames,
|
|
1535
|
+
this.depth * 2,
|
|
1536
|
+
);
|
|
1537
|
+
ci.clean = merged.clean && !ci.dfConflict && !ci.pathConflict;
|
|
1538
|
+
ci.result = merged.entry.mode ? merged.entry : undefined;
|
|
1539
|
+
ci.isNull = !merged.entry.mode;
|
|
1540
|
+
if (merged.clean && ci.dfConflict) {
|
|
1541
|
+
ci.filemask = 1 << dfFileIndex;
|
|
1542
|
+
ci.stages[dfFileIndex] = merged.entry;
|
|
1543
|
+
}
|
|
1544
|
+
if (!merged.clean) {
|
|
1545
|
+
let reason = "content";
|
|
1546
|
+
if (ci.filemask === 6) reason = "add/add";
|
|
1547
|
+
if (isGitlink(merged.entry)) reason = "submodule";
|
|
1548
|
+
this.say(path, `CONFLICT (${reason}): Merge conflict in ${path}`);
|
|
1549
|
+
}
|
|
1550
|
+
} else if (ci.filemask === 3 || ci.filemask === 5) {
|
|
1551
|
+
// modify/delete
|
|
1552
|
+
const side = ci.filemask === 5 ? 2 : 1;
|
|
1553
|
+
const index = this.depth > 0 ? 0 : side;
|
|
1554
|
+
ci.result = ci.stages[index];
|
|
1555
|
+
ci.isNull = !ci.result;
|
|
1556
|
+
ci.clean = false;
|
|
1557
|
+
const modifyBranch = side === 1 ? this.branch1 : this.branch2;
|
|
1558
|
+
const deleteBranch = side === 1 ? this.branch2 : this.branch1;
|
|
1559
|
+
if (
|
|
1560
|
+
this.options.renormalize &&
|
|
1561
|
+
(await this.blobUnchanged(ci.stages[0], ci.stages[side], path))
|
|
1562
|
+
) {
|
|
1563
|
+
if (!ci.pathConflict) {
|
|
1564
|
+
// unchanged after renormalization: no modify/delete after all
|
|
1565
|
+
ci.isNull = true;
|
|
1566
|
+
ci.result = undefined;
|
|
1567
|
+
ci.clean = true;
|
|
1568
|
+
ci.dfConflict = false;
|
|
1569
|
+
}
|
|
1570
|
+
} else if (ci.pathConflict && ci.stages[0]?.objectId === ci.stages[side]?.objectId) {
|
|
1571
|
+
// a rename/delete of an unchanged file: reported already
|
|
1572
|
+
} else {
|
|
1573
|
+
this.say(
|
|
1574
|
+
path,
|
|
1575
|
+
`CONFLICT (modify/delete): ${path} deleted in ${deleteBranch} and modified in ${modifyBranch}. Version ${modifyBranch} of ${path} left in tree.`,
|
|
1576
|
+
);
|
|
1577
|
+
}
|
|
1578
|
+
} else if (ci.filemask === 2 || ci.filemask === 4) {
|
|
1579
|
+
// added on one side
|
|
1580
|
+
const side = ci.filemask === 4 ? 2 : 1;
|
|
1581
|
+
ci.result = ci.stages[side];
|
|
1582
|
+
ci.isNull = false;
|
|
1583
|
+
ci.clean = !ci.dfConflict && !ci.pathConflict;
|
|
1584
|
+
} else if (ci.filemask === 1) {
|
|
1585
|
+
// deleted on both sides
|
|
1586
|
+
ci.isNull = true;
|
|
1587
|
+
ci.result = undefined;
|
|
1588
|
+
ci.clean = !ci.pathConflict;
|
|
1589
|
+
}
|
|
1590
|
+
if (!ci.clean) this.conflicted.set(path, ci);
|
|
1591
|
+
this.record(path, ci);
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
/** The name a side's file moved aside takes (`<path>~<name>`). */
|
|
1595
|
+
private nameOf(side: number): string {
|
|
1596
|
+
return side === 1
|
|
1597
|
+
? (this.options.oursName ?? this.branch1)
|
|
1598
|
+
: (this.options.theirsName ?? this.branch2);
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
// ---- result ---------------------------------------------------------------------------
|
|
1602
|
+
|
|
1603
|
+
private output(ours: Map<string, CheckedEntry>): OrtMergeResult {
|
|
1604
|
+
const result = new Map<string, CheckedEntry>();
|
|
1605
|
+
for (const [path, entry] of this.recorded) {
|
|
1606
|
+
if (!this.conflicted.has(path)) result.set(path, entry);
|
|
1607
|
+
}
|
|
1608
|
+
const conflicts = new Map<string, OrtConflict>();
|
|
1609
|
+
for (const [path, ci] of [...this.conflicted].sort((x, y) => compareStrings(x[0], y[0]))) {
|
|
1610
|
+
const tree = ci.isNull ? undefined : this.recorded.get(path);
|
|
1611
|
+
const stage = (i: number) => (ci.filemask & (1 << i) ? ci.stages[i] : undefined);
|
|
1612
|
+
const conflict: OrtConflict = {
|
|
1613
|
+
stagePath: path,
|
|
1614
|
+
mode: tree?.mode ?? stage(1)?.mode ?? stage(2)?.mode ?? stage(0)?.mode ?? 0,
|
|
1615
|
+
};
|
|
1616
|
+
const [b, o, t] = [stage(0), stage(1), stage(2)];
|
|
1617
|
+
if (b) conflict.base = b;
|
|
1618
|
+
if (o) conflict.ours = o;
|
|
1619
|
+
if (t) conflict.theirs = t;
|
|
1620
|
+
if (tree) {
|
|
1621
|
+
conflict.tree = tree;
|
|
1622
|
+
if (!sameEntry(tree, ours.get(path))) conflict.write = tree;
|
|
1623
|
+
}
|
|
1624
|
+
if (ci.movedFrom && o && ours.has(ci.movedFrom)) conflict.moveFrom = ci.movedFrom;
|
|
1625
|
+
conflicts.set(ci.dfMoved && ci.movedFrom ? ci.movedFrom : path, conflict);
|
|
1626
|
+
}
|
|
1627
|
+
const messages = this.notes
|
|
1628
|
+
.sort((x, y) => compareStrings(x.path, y.path) || x.order - y.order)
|
|
1629
|
+
.map((n) => n.text);
|
|
1630
|
+
return {
|
|
1631
|
+
result,
|
|
1632
|
+
conflicts,
|
|
1633
|
+
messages,
|
|
1634
|
+
clean: this.renamesClean && this.conflicted.size === 0,
|
|
1635
|
+
directoryRenames: this.dirRenames[1].size > 0 || this.dirRenames[2].size > 0,
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
/**
|
|
1641
|
+
* merge-ort's result tree as a flat map: the merged entries, and at each conflict's path
|
|
1642
|
+
* what git's result tree holds there (the file with markers, the surviving side, ours).
|
|
1643
|
+
*/
|
|
1644
|
+
export async function ortResultEntries(
|
|
1645
|
+
blobs: Blobs,
|
|
1646
|
+
merge: OrtMergeResult,
|
|
1647
|
+
): Promise<Map<string, CheckedEntry>> {
|
|
1648
|
+
const out = new Map(merge.result);
|
|
1649
|
+
for (const conflict of merge.conflicts.values()) {
|
|
1650
|
+
if (conflict.content) {
|
|
1651
|
+
out.set(conflict.stagePath, {
|
|
1652
|
+
objectId: await blobs.store([conflict.content]),
|
|
1653
|
+
mode: conflict.mode,
|
|
1654
|
+
});
|
|
1655
|
+
} else if (conflict.tree) {
|
|
1656
|
+
out.set(conflict.stagePath, conflict.tree);
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
return out;
|
|
1660
|
+
}
|