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',
140
138
tree, file_list = workingtree.WorkingTree.open_containing_paths(
141
139
file_list, directory)
143
if file_list is None:
140
if file_list 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
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:
152
ngettext('%d conflict auto-resolved.',
153
'%d conflicts auto-resolved.', before - after),
155
trace.note(gettext('Remaining conflicts:'))
156
for conflict in tree.conflicts():
157
trace.note(text_type(conflict))
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)),
158
trace.note(gettext('Remaining conflicts:'))
159
for conflict in un_resolved:
160
trace.note(text_type(conflict))
163
trace.note(gettext('All conflicts resolved.'))
160
trace.note(gettext('All conflicts resolved.'))
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
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:
447
def action_auto(self, tree):
448
raise NotImplementedError(self.action_auto)
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)
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)
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)
523
531
tid = tt.trans_id_file_id(file_id)
644
652
rformat = '%(class)s(%(path)r, %(file_id)r)'
646
_conflict_re = re.compile(b'^(<{7}|={7}|>{7})')
648
654
def associated_filenames(self):
649
655
return [self.path + suffix for suffix in CONFLICT_SUFFIXES]
675
681
tt.version_file(self.file_id, winner_tid)
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.
682
kind = tree.kind(self.path)
683
except errors.NoSuchFile:
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:
691
if conflict_markers_in_line(line):
692
raise NotImplementedError("Conflict markers present")
694
684
def action_take_this(self, tree):
695
685
self._resolve_with_cleanups(tree, 'THIS')
798
788
def action_take_other(self, tree):
799
with tree.get_transform() as tt:
789
tt = transform.TreeTransform(tree)
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)