~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/conflicts.py

  • Committer: John Arbash Meinel
  • Date: 2009-08-25 18:45:40 UTC
  • mto: (4634.6.15 2.0)
  • mto: This revision was merged to the branch mainline in revision 4667.
  • Revision ID: john@arbash-meinel.com-20090825184540-6dn3xjq62xhgj2gq
Add support for skipping ghost nodes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Aaron Bentley, Canonical Ltd
 
1
# Copyright (C) 2005, 2007 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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):
 
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
    """
121
133
    tree.lock_tree_write()
122
134
    try:
123
135
        tree_conflicts = tree.conflicts()
126
138
            selected_conflicts = tree_conflicts
127
139
        else:
128
140
            new_conflicts, selected_conflicts = \
129
 
                tree_conflicts.select_conflicts(tree, paths, ignore_misses)
 
141
                tree_conflicts.select_conflicts(tree, paths, ignore_misses,
 
142
                    recursive)
130
143
        try:
131
144
            tree.set_conflicts(new_conflicts)
132
145
        except errors.UnsupportedOperation:
215
228
        """Generator of stanzas"""
216
229
        for conflict in self:
217
230
            yield conflict.as_stanza()
218
 
            
 
231
 
219
232
    def to_strings(self):
220
233
        """Generate strings for the provided conflicts"""
221
234
        for conflict in self:
236
249
    def select_conflicts(self, tree, paths, ignore_misses=False,
237
250
                         recurse=False):
238
251
        """Select the conflicts associated with paths in a tree.
239
 
        
 
252
 
240
253
        File-ids are also used for this.
241
254
        :return: a pair of ConflictLists: (not_selected, selected)
242
255
        """
286
299
                    print "%s is not conflicted" % path
287
300
        return new_conflicts, selected_conflicts
288
301
 
289
 
 
 
302
 
290
303
class Conflict(object):
291
304
    """Base class for all types of conflict"""
292
305
 
390
403
    """
391
404
 
392
405
    rformat = "%(class)s(%(action)r, %(path)r, %(file_id)r)"
393
 
    
 
406
 
394
407
    def __init__(self, action, path, file_id=None):
395
408
        Conflict.__init__(self, path, file_id)
396
409
        self.action = action
415
428
    def __init__(self, action, path, conflict_path, file_id=None,
416
429
                 conflict_file_id=None):
417
430
        HandledConflict.__init__(self, action, path, file_id)
418
 
        self.conflict_path = conflict_path 
 
431
        self.conflict_path = conflict_path
419
432
        # warn turned off, because the factory blindly transfers the Stanza
420
433
        # values to __init__.
421
434
        self.conflict_file_id = osutils.safe_file_id(conflict_file_id,
422
435
                                                     warn=False)
423
 
        
 
436
 
424
437
    def _cmp_list(self):
425
 
        return HandledConflict._cmp_list(self) + [self.conflict_path, 
 
438
        return HandledConflict._cmp_list(self) + [self.conflict_path,
426
439
                                                  self.conflict_file_id]
427
440
 
428
441
    def as_stanza(self):
430
443
        s.add('conflict_path', self.conflict_path)
431
444
        if self.conflict_file_id is not None:
432
445
            s.add('conflict_file_id', self.conflict_file_id.decode('utf8'))
433
 
            
 
446
 
434
447
        return s
435
448
 
436
449
 
502
515
             "%(action)s."
503
516
 
504
517
 
 
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
 
505
528
ctype = {}
506
529
 
507
530
 
514
537
 
515
538
register_types(ContentsConflict, TextConflict, PathConflict, DuplicateID,
516
539
               DuplicateEntry, ParentLoop, UnversionedParent, MissingParent,
517
 
               DeletingParent,)
 
540
               DeletingParent, NonDirectoryParent)