~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/conflicts.py

  • Committer: Andrew Bennetts
  • Date: 2007-08-02 06:40:58 UTC
  • mfrom: (2666 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2668.
  • Revision ID: andrew.bennetts@canonical.com-20070802064058-09eblz1qbc01fcr3
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007 Canonical Ltd
 
1
# Copyright (C) 2005 Aaron Bentley, Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
# TODO: Move this into builtins
18
18
 
19
 
# TODO: 'bzr resolve' should accept a directory name and work from that
 
19
# TODO: 'bzr resolve' should accept a directory name and work from that 
20
20
# point down
21
21
 
22
22
import os
117
117
                resolve(tree, file_list)
118
118
 
119
119
 
120
 
def resolve(tree, paths=None, ignore_misses=False, recursive=False):
121
 
    """Resolve some or all of the conflicts in a working tree.
122
 
 
123
 
    :param paths: If None, resolve all conflicts.  Otherwise, select only
124
 
        specified conflicts.
125
 
    :param recursive: If True, then elements of paths which are directories
126
 
        have all their children resolved, etc.  When invoked as part of
127
 
        recursive commands like revert, this should be True.  For commands
128
 
        or applications wishing finer-grained control, like the resolve
129
 
        command, this should be False.
130
 
    :ignore_misses: If False, warnings will be printed if the supplied paths
131
 
        do not have conflicts.
132
 
    """
 
120
def resolve(tree, paths=None, ignore_misses=False):
133
121
    tree.lock_tree_write()
134
122
    try:
135
123
        tree_conflicts = tree.conflicts()
138
126
            selected_conflicts = tree_conflicts
139
127
        else:
140
128
            new_conflicts, selected_conflicts = \
141
 
                tree_conflicts.select_conflicts(tree, paths, ignore_misses,
142
 
                    recursive)
 
129
                tree_conflicts.select_conflicts(tree, paths, ignore_misses)
143
130
        try:
144
131
            tree.set_conflicts(new_conflicts)
145
132
        except errors.UnsupportedOperation:
228
215
        """Generator of stanzas"""
229
216
        for conflict in self:
230
217
            yield conflict.as_stanza()
231
 
 
 
218
            
232
219
    def to_strings(self):
233
220
        """Generate strings for the provided conflicts"""
234
221
        for conflict in self:
249
236
    def select_conflicts(self, tree, paths, ignore_misses=False,
250
237
                         recurse=False):
251
238
        """Select the conflicts associated with paths in a tree.
252
 
 
 
239
        
253
240
        File-ids are also used for this.
254
241
        :return: a pair of ConflictLists: (not_selected, selected)
255
242
        """
299
286
                    print "%s is not conflicted" % path
300
287
        return new_conflicts, selected_conflicts
301
288
 
302
 
 
 
289
 
303
290
class Conflict(object):
304
291
    """Base class for all types of conflict"""
305
292
 
403
390
    """
404
391
 
405
392
    rformat = "%(class)s(%(action)r, %(path)r, %(file_id)r)"
406
 
 
 
393
    
407
394
    def __init__(self, action, path, file_id=None):
408
395
        Conflict.__init__(self, path, file_id)
409
396
        self.action = action
428
415
    def __init__(self, action, path, conflict_path, file_id=None,
429
416
                 conflict_file_id=None):
430
417
        HandledConflict.__init__(self, action, path, file_id)
431
 
        self.conflict_path = conflict_path
 
418
        self.conflict_path = conflict_path 
432
419
        # warn turned off, because the factory blindly transfers the Stanza
433
420
        # values to __init__.
434
421
        self.conflict_file_id = osutils.safe_file_id(conflict_file_id,
435
422
                                                     warn=False)
436
 
 
 
423
        
437
424
    def _cmp_list(self):
438
 
        return HandledConflict._cmp_list(self) + [self.conflict_path,
 
425
        return HandledConflict._cmp_list(self) + [self.conflict_path, 
439
426
                                                  self.conflict_file_id]
440
427
 
441
428
    def as_stanza(self):
443
430
        s.add('conflict_path', self.conflict_path)
444
431
        if self.conflict_file_id is not None:
445
432
            s.add('conflict_file_id', self.conflict_file_id.decode('utf8'))
446
 
 
 
433
            
447
434
        return s
448
435
 
449
436
 
515
502
             "%(action)s."
516
503
 
517
504
 
518
 
class NonDirectoryParent(HandledConflict):
519
 
    """An attempt to add files to a directory that is not a director or
520
 
    an attempt to change the kind of a directory with files.
521
 
    """
522
 
 
523
 
    typestring = 'non-directory parent'
524
 
 
525
 
    format = "Conflict: %(path)s is not a directory, but has files in it."\
526
 
             "  %(action)s."
527
 
 
528
505
ctype = {}
529
506
 
530
507
 
537
514
 
538
515
register_types(ContentsConflict, TextConflict, PathConflict, DuplicateID,
539
516
               DuplicateEntry, ParentLoop, UnversionedParent, MissingParent,
540
 
               DeletingParent, NonDirectoryParent)
 
517
               DeletingParent,)