[MERGE] auto-resolve for commit

Martin Pool mbp at canonical.com
Tue Nov 7 01:09:19 GMT 2006

On  6 Nov 2006, Aaron Bentley <aaron.bentley at utoronto.ca> wrote:

> I've gotten sick on being pestered to mark conflicts as resolved.  And I
> don't like running 'resolve --all', because it disables a safeguard.

I think you're definitely on to something here; as you say forcing them
to mark conflicts as fixed doesn't seem to give good protection.  I'd
just like to make sure the model presented to the user is

It does seem a bit strange that bzr commit is more forgiving of
conflicts than other commands that display conflicts.

Will detection of those markers work properly if there was a conflict in
a binary file?

Can you add some text to doc/tutorial.txt explaining how conflicts will
work in this case?  I think this will do:

  Conflicts are
  shown by the merge command and can be seen again through the 
  ``bzr conflicts`` command.  As you fix conflicts, you can remove them 
  from the list using the ``bzr resolved`` command.  As a special case,
  text conflicts are considered fixed if the "herringbone" markers
  (<<<<<<<) are removed from the file.

  If there are conflicts in the tree, commit will normally refuse to

Trying to explain this does make me more sure the special case shouldn't
be confined to just commit.

> +def auto_resolve(tree):
> +    """Automatically resolve text conflicts according to contents.
> +
> +    Only text conflicts are auto_resolvable. Files with no conflict markers are
> +    considered 'resolved', because bzr always puts conflict markers into files
> +    that have text conflicts.  The corresponding .THIS .BASE and .OTHER files
> +    are deleted, as per 'resolve'.
> +    :param tree: The tree to 
> +    :return: a tuple of ConflictLists: (un_resolved, resolved).
> +    """
> +    un_resolved = ConflictList()
> +    resolved = ConflictList()
> +    conflict_re = re.compile('(<{7}|={7}|>{7})')
> +    try:
> +        tree.lock_tree_write()
> +        for conflict in tree.conflicts():
> +            if conflict.typestring != 'text conflict':
> +                un_resolved.append(conflict)
> +                continue
> +            my_file = open(tree.id2abspath(conflict.file_id), 'rb')
> +            try:
> +                for line in my_file:
> +                    if conflict_re.match(line):
> +                        un_resolved.append(conflict)
> +                        break
> +                else:
> +                    resolved.append(conflict)
> +            finally:
> +                my_file.close()
> +        resolved.remove_files(tree)
> +        tree.set_conflicts(un_resolved)
> +    finally:
> +        tree.unlock()
> +    return un_resolved, resolved
> +

I think this should be a Tree method not a function.


More information about the bazaar mailing list