~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/conflicts.py

(gz) Remove bzrlib/util/elementtree/ package (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# TODO: 'bzr resolve' should accept a directory name and work from that
18
18
# point down
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
import os
21
23
 
22
24
from bzrlib.lazy_import import lazy_import
32
34
    transform,
33
35
    workingtree,
34
36
    )
 
37
from bzrlib.i18n import gettext, ngettext
35
38
""")
36
39
from bzrlib import (
37
40
    commands,
79
82
 
80
83
 
81
84
resolve_action_registry.register(
82
 
    'done', 'done', 'Marks the conflict as resolved' )
 
85
    'done', 'done', 'Marks the conflict as resolved.')
83
86
resolve_action_registry.register(
84
87
    'take-this', 'take_this',
85
 
    'Resolve the conflict preserving the version in the working tree' )
 
88
    'Resolve the conflict preserving the version in the working tree.')
86
89
resolve_action_registry.register(
87
90
    'take-other', 'take_other',
88
 
    'Resolve the conflict taking the merged version into account' )
 
91
    'Resolve the conflict taking the merged version into account.')
89
92
resolve_action_registry.default_key = 'done'
90
93
 
91
94
class ResolveActionOption(option.RegistryOption):
120
123
    def run(self, file_list=None, all=False, action=None, directory=None):
121
124
        if all:
122
125
            if file_list:
123
 
                raise errors.BzrCommandError("If --all is specified,"
124
 
                                             " no FILE may be provided")
 
126
                raise errors.BzrCommandError(gettext("If --all is specified,"
 
127
                                             " no FILE may be provided"))
125
128
            if directory is None:
126
129
                directory = u'.'
127
130
            tree = workingtree.WorkingTree.open_containing(directory)[0]
145
148
            if file_list is None:
146
149
                un_resolved, resolved = tree.auto_resolve()
147
150
                if len(un_resolved) > 0:
148
 
                    trace.note('%d conflict(s) auto-resolved.', len(resolved))
149
 
                    trace.note('Remaining conflicts:')
 
151
                    trace.note(ngettext('%d conflict auto-resolved.',
 
152
                        '%d conflicts auto-resolved.', len(resolved)),
 
153
                        len(resolved))
 
154
                    trace.note(gettext('Remaining conflicts:'))
150
155
                    for conflict in un_resolved:
151
156
                        trace.note(unicode(conflict))
152
157
                    return 1
153
158
                else:
154
 
                    trace.note('All conflicts resolved.')
 
159
                    trace.note(gettext('All conflicts resolved.'))
155
160
                    return 0
156
161
            else:
157
162
                # FIXME: This can never occur but the block above needs some
160
165
                pass
161
166
        else:
162
167
            before, after = resolve(tree, file_list, action=action)
163
 
            trace.note('%d conflict(s) resolved, %d remaining'
164
 
                       % (before - after, after))
 
168
            trace.note(ngettext('{0} conflict resolved, {1} remaining',
 
169
                                '{0} conflicts resolved, {1} remaining',
 
170
                                before-after).format(before - after, after))
165
171
 
166
172
 
167
173
def resolve(tree, paths=None, ignore_misses=False, recursive=False,
507
513
        if path_to_create is not None:
508
514
            tid = tt.trans_id_tree_path(path_to_create)
509
515
            transform.create_from_tree(
510
 
                tt, tt.trans_id_tree_path(path_to_create),
511
 
                self._revision_tree(tt._tree, revid), file_id)
 
516
                tt, tid, self._revision_tree(tt._tree, revid), file_id)
512
517
            tt.version_file(file_id, tid)
513
 
 
 
518
        else:
 
519
            tid = tt.trans_id_file_id(file_id)
514
520
        # Adjust the path for the retained file id
515
 
        tid = tt.trans_id_file_id(file_id)
516
521
        parent_tid = tt.get_tree_parent(tid)
517
522
        tt.adjust_path(osutils.basename(path), parent_tid, tid)
518
523
        tt.apply()
583
588
        :param tt: The TreeTransform where the conflict is resolved.
584
589
        :param suffix_to_remove: Either 'THIS' or 'OTHER'
585
590
 
586
 
        The resolution is symmetric, when taking THIS, OTHER is deleted and
 
591
        The resolution is symmetric: when taking THIS, OTHER is deleted and
587
592
        item.THIS is renamed into item and vice-versa.
588
593
        """
589
594
        try:
596
601
            # never existed or was already deleted (including the case
597
602
            # where the user deleted it)
598
603
            pass
599
 
        # Rename 'item.suffix_to_remove' (note that if
600
 
        # 'item.suffix_to_remove' has been deleted, this is a no-op)
601
 
        this_tid = tt.trans_id_file_id(self.file_id)
602
 
        parent_tid = tt.get_tree_parent(this_tid)
603
 
        tt.adjust_path(osutils.basename(self.path), parent_tid, this_tid)
604
 
        tt.apply()
 
604
        try:
 
605
            this_path = tt._tree.id2path(self.file_id)
 
606
        except errors.NoSuchId:
 
607
            # The file is not present anymore. This may happen if the user
 
608
            # deleted the file either manually or when resolving a conflict on
 
609
            # the parent.  We may raise some exception to indicate that the
 
610
            # conflict doesn't exist anymore and as such doesn't need to be
 
611
            # resolved ? -- vila 20110615 
 
612
            this_tid = None
 
613
        else:
 
614
            this_tid = tt.trans_id_tree_path(this_path)
 
615
        if this_tid is not None:
 
616
            # Rename 'item.suffix_to_remove' (note that if
 
617
            # 'item.suffix_to_remove' has been deleted, this is a no-op)
 
618
            parent_tid = tt.get_tree_parent(this_tid)
 
619
            tt.adjust_path(osutils.basename(self.path), parent_tid, this_tid)
 
620
            tt.apply()
605
621
 
606
622
    def action_take_this(self, tree):
607
623
        self._resolve_with_cleanups(tree, 'OTHER')