This module contains algorithms for performing conflict resolution after Git performs its recursive merge. It defines a simple domain specific language (that, at its simplest form, merely involves copying conflict markers and writing in the form that they should be resolved as) for specifying how to resolve conflicts. These are mostly relevant for resolving conflicts in configuration files.
The conflict resolution DSL is described here:
Resolutions are specified as input-output pairs. An input is a string with the conflict resolution markers ("<" * 7, "=" * 7 and ">" * 7), with the HEAD content above the equals divider, and the upstream content below the equals divider. Lines can also be marked as ***N*** where N is a natural number greater than 0 (i.e. 1 or more), which means that an arbitrary number of lines may be matched and available for output.
Output is a list of integers and strings. Integers expand to lines that were specified earlier; -1 and 0 are special integers that correspond to the entire HEAD text, and the entire upstream text, respectively. Strings can be used to insert custom lines.
The DSL does not currently claim to support character level granularity. It also does not claim to support contiguous conflicts. Our hope is that this simple syntax will be sufficient to cover most common merge failures.
Here are some examples:
<<<<<<< downstream ||||||| common ======= upstream >>>>>>>
With [-1] would discard all upstream changes, whereas with  would discard downstream changes (you would probably want to be careful about wildcarding in the upstream string).
Pattern matching in action:
<<<<<<< ***1*** old upstream ***2*** old upstream ***3*** ======= new upstream >>>>>>>
With [0, 1, 2, 3] would resolve with the new upstream text, and then the user matched globs.
Given a conflicted file, whose contents are contents, attempt to resolve all conflicts that match spec with result.
Given contents, return True if there are any conflicts in it.
Translates a specification string into a regular expression tuple. Note that pattern matches are out of order, so the second element of the tuple is a dict specified strings to subpattern numbers. Requires re.DOTALL for correct operation.
Converts a list of replacement strings and or references into a replacement string appropriate for a regular expression.