~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/conflicts.py

  • Committer: IWATA Hidetaka
  • Date: 2010-12-26 13:19:11 UTC
  • mto: This revision was merged to the branch mainline in revision 5593.
  • Revision ID: iwata0303@gmail.com-20101226131911-o7txs0fnji5zekq1
add icon resources tbzrcommand(w)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# point down
19
19
 
20
20
import os
21
 
import re
22
21
 
23
22
from bzrlib.lazy_import import lazy_import
24
23
lazy_import(globals(), """
25
24
import errno
26
25
 
27
26
from bzrlib import (
28
 
    builtins,
29
27
    cleanup,
30
28
    commands,
31
29
    errors,
46
44
 
47
45
 
48
46
class cmd_conflicts(commands.Command):
49
 
    """List files with conflicts.
 
47
    __doc__ = """List files with conflicts.
50
48
 
51
49
    Merge will do its best to combine the changes in two branches, but there
52
50
    are some kinds of problems only a human can fix.  When it encounters those,
60
58
    Use bzr resolve when you have fixed a problem.
61
59
    """
62
60
    takes_options = [
 
61
            'directory',
63
62
            option.Option('text',
64
63
                          help='List paths of files with text conflicts.'),
65
64
        ]
66
65
    _see_also = ['resolve', 'conflict-types']
67
66
 
68
 
    def run(self, text=False):
69
 
        wt = workingtree.WorkingTree.open_containing(u'.')[0]
 
67
    def run(self, text=False, directory=u'.'):
 
68
        wt = workingtree.WorkingTree.open_containing(directory)[0]
70
69
        for conflict in wt.conflicts():
71
70
            if text:
72
71
                if conflict.typestring != 'text conflict':
99
98
 
100
99
 
101
100
class cmd_resolve(commands.Command):
102
 
    """Mark a conflict as resolved.
 
101
    __doc__ = """Mark a conflict as resolved.
103
102
 
104
103
    Merge will do its best to combine the changes in two branches, but there
105
104
    are some kinds of problems only a human can fix.  When it encounters those,
113
112
    aliases = ['resolved']
114
113
    takes_args = ['file*']
115
114
    takes_options = [
 
115
            'directory',
116
116
            option.Option('all', help='Resolve all conflicts in this tree.'),
117
117
            ResolveActionOption(),
118
118
            ]
119
119
    _see_also = ['conflicts']
120
 
    def run(self, file_list=None, all=False, action=None):
 
120
    def run(self, file_list=None, all=False, action=None, directory=None):
121
121
        if all:
122
122
            if file_list:
123
123
                raise errors.BzrCommandError("If --all is specified,"
124
124
                                             " no FILE may be provided")
125
 
            tree = workingtree.WorkingTree.open_containing('.')[0]
 
125
            if directory is None:
 
126
                directory = u'.'
 
127
            tree = workingtree.WorkingTree.open_containing(directory)[0]
126
128
            if action is None:
127
129
                action = 'done'
128
130
        else:
129
 
            tree, file_list = builtins.tree_files(file_list)
 
131
            tree, file_list = workingtree.WorkingTree.open_containing_paths(
 
132
                file_list, directory)
130
133
            if file_list is None:
131
134
                if action is None:
132
135
                    # FIXME: There is a special case here related to the option
156
159
                # conflict.auto(tree) --vila 091242
157
160
                pass
158
161
        else:
159
 
            resolve(tree, file_list, action=action)
 
162
            before, after = resolve(tree, file_list, action=action)
 
163
            trace.note('%d conflict(s) resolved, %d remaining'
 
164
                       % (before - after, after))
160
165
 
161
166
 
162
167
def resolve(tree, paths=None, ignore_misses=False, recursive=False,
175
180
    :param action: How the conflict should be resolved,
176
181
    """
177
182
    tree.lock_tree_write()
 
183
    nb_conflicts_after = None
178
184
    try:
179
185
        tree_conflicts = tree.conflicts()
 
186
        nb_conflicts_before = len(tree_conflicts)
180
187
        if paths is None:
181
188
            new_conflicts = ConflictList()
182
189
            to_process = tree_conflicts
190
197
            except NotImplementedError:
191
198
                new_conflicts.append(conflict)
192
199
        try:
 
200
            nb_conflicts_after = len(new_conflicts)
193
201
            tree.set_conflicts(new_conflicts)
194
202
        except errors.UnsupportedOperation:
195
203
            pass
196
204
    finally:
197
205
        tree.unlock()
 
206
    if nb_conflicts_after is None:
 
207
        nb_conflicts_after = nb_conflicts_before
 
208
    return nb_conflicts_before, nb_conflicts_after
198
209
 
199
210
 
200
211
def restore(filename):
599
610
        self._resolve_with_cleanups(tree, 'THIS')
600
611
 
601
612
 
602
 
# FIXME: TextConflict is about a single file-id, there never is a conflict_path
603
 
# attribute so we shouldn't inherit from PathConflict but simply from Conflict
604
 
 
605
613
# TODO: There should be a base revid attribute to better inform the user about
606
614
# how the conflicts were generated.
607
 
class TextConflict(PathConflict):
 
615
class TextConflict(Conflict):
608
616
    """The merge algorithm could not resolve all differences encountered."""
609
617
 
610
618
    has_files = True
613
621
 
614
622
    format = 'Text conflict in %(path)s'
615
623
 
 
624
    rformat = '%(class)s(%(path)r, %(file_id)r)'
 
625
 
616
626
    def associated_filenames(self):
617
627
        return [self.path + suffix for suffix in CONFLICT_SUFFIXES]
618
628