/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/conflicts.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-03 23:48:08 UTC
  • mfrom: (7316 work)
  • mto: This revision was merged to the branch mainline in revision 7328.
  • Revision ID: jelmer@jelmer.uk-20190603234808-15yk5c7054tj8e2b
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from __future__ import absolute_import
21
21
 
22
22
import os
23
 
import re
24
23
 
25
24
from .lazy_import import lazy_import
26
25
lazy_import(globals(), """
27
26
import errno
28
27
 
29
28
from breezy import (
 
29
    cleanup,
 
30
    errors,
30
31
    osutils,
31
32
    rio,
32
33
    trace,
37
38
""")
38
39
from . import (
39
40
    cache_utf8,
40
 
    errors,
41
41
    commands,
42
42
    option,
43
43
    registry,
84
84
 
85
85
 
86
86
resolve_action_registry.register(
87
 
    'auto', 'auto', 'Detect whether conflict has been resolved by user.')
88
 
resolve_action_registry.register(
89
87
    'done', 'done', 'Marks the conflict as resolved.')
90
88
resolve_action_registry.register(
91
89
    'take-this', 'take_this',
139
137
        else:
140
138
            tree, file_list = workingtree.WorkingTree.open_containing_paths(
141
139
                file_list, directory)
142
 
            if action is None:
143
 
                if file_list is None:
 
140
            if file_list is None:
 
141
                if action is None:
 
142
                    # FIXME: There is a special case here related to the option
 
143
                    # handling that could be clearer and easier to discover by
 
144
                    # providing an --auto action (bug #344013 and #383396) and
 
145
                    # make it mandatory instead of implicit and active only
 
146
                    # when no file_list is provided -- vila 091229
144
147
                    action = 'auto'
145
 
                else:
 
148
            else:
 
149
                if action is None:
146
150
                    action = 'done'
147
 
        before, after = resolve(tree, file_list, action=action)
148
 
        # GZ 2012-07-27: Should unify UI below now that auto is less magical.
149
 
        if action == 'auto' and file_list is None:
150
 
            if after > 0:
151
 
                trace.note(
152
 
                    ngettext('%d conflict auto-resolved.',
153
 
                             '%d conflicts auto-resolved.', before - after),
154
 
                    before - after)
155
 
                trace.note(gettext('Remaining conflicts:'))
156
 
                for conflict in tree.conflicts():
157
 
                    trace.note(text_type(conflict))
158
 
                return 1
 
151
        if action == 'auto':
 
152
            if file_list is None:
 
153
                un_resolved, resolved = tree.auto_resolve()
 
154
                if len(un_resolved) > 0:
 
155
                    trace.note(ngettext('%d conflict auto-resolved.',
 
156
                                        '%d conflicts auto-resolved.', len(resolved)),
 
157
                               len(resolved))
 
158
                    trace.note(gettext('Remaining conflicts:'))
 
159
                    for conflict in un_resolved:
 
160
                        trace.note(text_type(conflict))
 
161
                    return 1
 
162
                else:
 
163
                    trace.note(gettext('All conflicts resolved.'))
 
164
                    return 0
159
165
            else:
160
 
                trace.note(gettext('All conflicts resolved.'))
161
 
                return 0
 
166
                # FIXME: This can never occur but the block above needs some
 
167
                # refactoring to transfer tree.auto_resolve() to
 
168
                # conflict.auto(tree) --vila 091242
 
169
                pass
162
170
        else:
 
171
            before, after = resolve(tree, file_list, action=action)
163
172
            trace.note(ngettext('{0} conflict resolved, {1} remaining',
164
173
                                '{0} conflicts resolved, {1} remaining',
165
174
                                before - after).format(before - after, after))
444
453
                if e.errno != errno.ENOENT:
445
454
                    raise
446
455
 
447
 
    def action_auto(self, tree):
448
 
        raise NotImplementedError(self.action_auto)
449
 
 
450
456
    def action_done(self, tree):
451
457
        """Mark the conflict as solved once it has been handled."""
452
458
        # This method does nothing but simplifies the design of upper levels.
459
465
        raise NotImplementedError(self.action_take_other)
460
466
 
461
467
    def _resolve_with_cleanups(self, tree, *args, **kwargs):
462
 
        with tree.get_transform() as tt:
463
 
            self._resolve(tt, *args, **kwargs)
 
468
        tt = transform.TreeTransform(tree)
 
469
        op = cleanup.OperationWithCleanups(self._resolve)
 
470
        op.add_cleanup(tt.finalize)
 
471
        op.run_simple(tt, *args, **kwargs)
464
472
 
465
473
 
466
474
class PathConflict(Conflict):
517
525
            tid = tt.trans_id_tree_path(path_to_create)
518
526
            tree = self._revision_tree(tt._tree, revid)
519
527
            transform.create_from_tree(
520
 
                tt, tid, tree, tree.id2path(file_id))
 
528
                tt, tid, tree, tree.id2path(file_id), file_id=file_id)
521
529
            tt.version_file(file_id, tid)
522
530
        else:
523
531
            tid = tt.trans_id_file_id(file_id)
643
651
 
644
652
    rformat = '%(class)s(%(path)r, %(file_id)r)'
645
653
 
646
 
    _conflict_re = re.compile(b'^(<{7}|={7}|>{7})')
647
 
 
648
654
    def associated_filenames(self):
649
655
        return [self.path + suffix for suffix in CONFLICT_SUFFIXES]
650
656
 
675
681
        tt.version_file(self.file_id, winner_tid)
676
682
        tt.apply()
677
683
 
678
 
    def action_auto(self, tree):
679
 
        # GZ 2012-07-27: Using NotImplementedError to signal that a conflict
680
 
        #                can't be auto resolved does not seem ideal.
681
 
        try:
682
 
            kind = tree.kind(self.path)
683
 
        except errors.NoSuchFile:
684
 
            return
685
 
        if kind != 'file':
686
 
            raise NotImplementedError("Conflict is not a file")
687
 
        conflict_markers_in_line = self._conflict_re.search
688
 
        # GZ 2012-07-27: What if not tree.has_id(self.file_id) due to removal?
689
 
        with tree.get_file(self.path) as f:
690
 
            for line in f:
691
 
                if conflict_markers_in_line(line):
692
 
                    raise NotImplementedError("Conflict markers present")
693
 
 
694
684
    def action_take_this(self, tree):
695
685
        self._resolve_with_cleanups(tree, 'THIS')
696
686
 
796
786
        pass
797
787
 
798
788
    def action_take_other(self, tree):
799
 
        with tree.get_transform() as tt:
 
789
        tt = transform.TreeTransform(tree)
 
790
        try:
800
791
            p_tid = tt.trans_id_file_id(self.file_id)
801
792
            parent_tid = tt.get_tree_parent(p_tid)
802
793
            cp_tid = tt.trans_id_file_id(self.conflict_file_id)
805
796
            tt.adjust_path(osutils.basename(self.conflict_path),
806
797
                           parent_tid, p_tid)
807
798
            tt.apply()
 
799
        finally:
 
800
            tt.finalize()
808
801
 
809
802
 
810
803
class UnversionedParent(HandledConflict):