/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Aaron Bentley
  • Date: 2007-11-22 15:15:02 UTC
  • mto: This revision was merged to the branch mainline in revision 3036.
  • Revision ID: abentley@panoramicfeedback.com-20071122151502-m9kwy2ums0gddyev
Refactor differ to support registering differ factories

Show diffs side-by-side

added added

removed removed

Lines of Context:
426
426
    changed = object()
427
427
    unchanged = object()
428
428
 
429
 
    def __init__(self, old_tree, new_tree, to_file):
 
429
    def __init__(self, old_tree, new_tree, to_file, path_encoding='utf-8'):
430
430
        self.old_tree = old_tree
431
431
        self.new_tree = new_tree
432
432
        self.to_file = to_file
 
433
        self.path_encoding = path_encoding
433
434
 
434
435
    @staticmethod
435
436
    def _diff_many(differs, file_id, old_path, new_path, old_kind, new_kind):
492
493
    # or removed in a diff.
493
494
    EPOCH_DATE = '1970-01-01 00:00:00 +0000'
494
495
 
495
 
    def __init__(self, old_tree, new_tree, old_label, new_label, path_encoding,
496
 
                 to_file, text_differ):
497
 
        FileDiffer.__init__(self, old_tree, new_tree, to_file)
 
496
    def __init__(self, old_tree, new_tree, to_file, path_encoding='utf-8',
 
497
                 old_label='', new_label='', text_differ=internal_diff):
 
498
        FileDiffer.__init__(self, old_tree, new_tree, to_file, path_encoding)
498
499
        self.text_differ = text_differ
499
500
        self.old_label = old_label
500
501
        self.new_label = new_label
549
550
 
550
551
class TreeDiffer(object):
551
552
 
 
553
    differ_factories = [SymlinkDiffer]
 
554
 
552
555
    def __init__(self, old_tree, new_tree, to_file, path_encoding='utf-8',
553
556
                 text_differ=None):
554
557
        if text_differ is None:
555
 
            text_differ = TextDiffer(old_tree, new_tree, '', '', path_encoding,
556
 
                                     to_file, internal_diff)
 
558
            text_differ = TextDiffer(old_tree, new_tree, to_file,
 
559
                                     path_encoding, '', '',  internal_diff)
557
560
        self.old_tree = old_tree
558
561
        self.new_tree = new_tree
559
562
        self.to_file = to_file
560
 
        self.differs = [SymlinkDiffer(old_tree, new_tree, to_file),
561
 
                        text_differ]
 
563
        self.differs = []
 
564
        for differ in self.differ_factories:
 
565
            self.differs.append(differ(old_tree, new_tree, to_file,
 
566
                                       path_encoding))
 
567
        self.differs.extend([text_differ, KindChangeDiffer(self.differs)])
562
568
        kcd = KindChangeDiffer(self.differs)
563
 
        self.differs.append(kcd)
564
569
        self.path_encoding = path_encoding
565
570
 
566
571
    @classmethod
574
579
                external_diff(olab, olines, nlab, nlines, to_file, opts)
575
580
        else:
576
581
            diff_file = internal_diff
577
 
        text_differ = TextDiffer(old_tree, new_tree, old_label, new_label,
578
 
                                 path_encoding, to_file, diff_file)
 
582
        text_differ = TextDiffer(old_tree, new_tree, to_file, path_encoding,
 
583
                                 old_label, new_label, diff_file)
579
584
        return klass(old_tree, new_tree, to_file, path_encoding, text_differ)
580
585
 
581
586
    def show_diff(self, specific_files, extra_trees=None):