Mercurial > hg
comparison mercurial/configitems.py @ 48981:f3aafd785e65
filemerge: add support for partial conflict resolution by external tool
A common class of merge conflicts is in imports/#includes/etc. It's
relatively easy to write a tool that can resolve these conflicts,
perhaps by naively just unioning the statements and leaving any
cleanup to other tools to do later [1]. Such specialized tools cannot
generally resolve all conflicts in a file, of course. Let's therefore
call them "partial merge tools". Note that the internal simplemerge
algorithm is such a partial merge tool - one that only resolves
trivial "conflicts" where one side is unchanged or both sides change
in the same way.
One can also imagine having smarter language-aware partial tools that
merge the AST. It may be useful for such tools to interactively let
the user resolve any conflicts it can't resolve itself. However,
having the option of implementing it as a partial merge tool means
that the developer doesn't *need* to create a UI for it. Instead, the
user can resolve any remaining conflicts with their regular merge tool
(e.g. `:merge3` or `meld).
We don't currently have a way to let the user define such partial
merge tools. That's what this patch addresses. It lets the user
configure partial merge tools to run. Each tool can be configured to
run only on files matching certain patterns (e.g. "*.py"). The tool
takes three inputs (local, base, other) and resolves conflicts by
updating these in place. For example, let's say the inputs are these:
base:
```
import sys
def main():
print('Hello')
```
local:
```
import os
import sys
def main():
print('Hi')
```
other:
```
import re
import sys
def main():
print('Howdy')
```
A partial merge tool could now resolve the conflicting imports by
replacing the import statements in *all* files by the following
snippet, while leaving the remainder of the files unchanged.
```
import os
import re
import sys
```
As a result, simplemerge and any regular merge tool that runs after
the partial merge tool(s) will consider the imports to be
non-conflicting and will only present the conflict in `main()` to the
user.
Differential Revision: https://phab.mercurial-scm.org/D12356
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 18 Jan 2022 13:05:21 -0800 |
parents | 642e31cb55f0 |
children | 9dfbea54b680 |
comparison
equal
deleted
inserted
replaced
48978:c80544aa4971 | 48981:f3aafd785e65 |
---|---|
1568 b'merge', | 1568 b'merge', |
1569 b'strict-capability-check', | 1569 b'strict-capability-check', |
1570 default=False, | 1570 default=False, |
1571 ) | 1571 ) |
1572 coreconfigitem( | 1572 coreconfigitem( |
1573 b'partial-merge-tools', | |
1574 b'.*', | |
1575 default=None, | |
1576 generic=True, | |
1577 experimental=True, | |
1578 ) | |
1579 coreconfigitem( | |
1580 b'partial-merge-tools', | |
1581 br'.*\.patterns', | |
1582 default=dynamicdefault, | |
1583 generic=True, | |
1584 priority=-1, | |
1585 experimental=True, | |
1586 ) | |
1587 coreconfigitem( | |
1588 b'partial-merge-tools', | |
1589 br'.*\.executable$', | |
1590 default=dynamicdefault, | |
1591 generic=True, | |
1592 priority=-1, | |
1593 experimental=True, | |
1594 ) | |
1595 coreconfigitem( | |
1596 b'partial-merge-tools', | |
1597 br'.*\.order', | |
1598 default=0, | |
1599 generic=True, | |
1600 priority=-1, | |
1601 experimental=True, | |
1602 ) | |
1603 coreconfigitem( | |
1573 b'merge-tools', | 1604 b'merge-tools', |
1574 b'.*', | 1605 b'.*', |
1575 default=None, | 1606 default=None, |
1576 generic=True, | 1607 generic=True, |
1577 ) | 1608 ) |