~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Aaron Bentley
  • Date: 2007-11-21 14:55:46 UTC
  • mto: (3008.1.2 transform_preview)
  • mto: This revision was merged to the branch mainline in revision 3036.
  • Revision ID: abentley@panoramicfeedback.com-20071121145546-dsbz0266amz9q1w3
Factor symlink and file diffing into differ

Show diffs side-by-side

added added

removed removed

Lines of Context:
619
619
    def _diff(self, text_diff, from_label, tree, to_label, to_entry, to_tree,
620
620
             output_to, reverse=False):
621
621
        """See InventoryEntry._diff."""
622
 
        try:
623
 
            from_text = tree.get_file(self.file_id).readlines()
624
 
            if to_entry:
625
 
                to_text = to_tree.get_file(to_entry.file_id).readlines()
626
 
            else:
627
 
                to_text = []
628
 
            if not reverse:
629
 
                text_diff(from_label, from_text,
630
 
                          to_label, to_text, output_to)
631
 
            else:
632
 
                text_diff(to_label, to_text,
633
 
                          from_label, from_text, output_to)
634
 
        except errors.BinaryFile:
635
 
            if reverse:
636
 
                label_pair = (to_label, from_label)
637
 
            else:
638
 
                label_pair = (from_label, to_label)
639
 
            output_to.write(
640
 
                  ("Binary files %s and %s differ\n" % label_pair).encode('utf8'))
 
622
        from bzrlib.diff import Differ
 
623
        from_file_id = self.file_id
 
624
        if to_entry:
 
625
            to_file_id = to_entry.file_id
 
626
        else:
 
627
            to_file_id = None
 
628
        if reverse:
 
629
            to_file_id, from_file_id = from_file_id, to_file_id
 
630
            tree, to_tree = to_tree, tree
 
631
            from_label, to_label = to_label, from_label
 
632
        differ = Differ(tree, to_tree, output_to, text_diff)
 
633
        return differ.diff_text(from_file_id, to_file_id, from_label, to_label)
641
634
 
642
635
    def has_text(self):
643
636
        """See InventoryEntry.has_text."""
735
728
    def _diff(self, text_diff, from_label, tree, to_label, to_entry, to_tree,
736
729
             output_to, reverse=False):
737
730
        """See InventoryEntry._diff."""
738
 
        from_text = self.symlink_target
 
731
        from bzrlib.diff import Differ
 
732
        old_target = self.symlink_target
739
733
        if to_entry is not None:
740
 
            to_text = to_entry.symlink_target
741
 
            if reverse:
742
 
                temp = from_text
743
 
                from_text = to_text
744
 
                to_text = temp
745
 
            output_to.write('=== target changed %r => %r\n' % (from_text, to_text))
746
 
        else:
747
 
            if not reverse:
748
 
                output_to.write('=== target was %r\n' % self.symlink_target)
749
 
            else:
750
 
                output_to.write('=== target is %r\n' % self.symlink_target)
 
734
            new_target = to_entry.symlink_target
 
735
        else:
 
736
            new_target = None
 
737
        if not reverse:
 
738
            old_tree = tree
 
739
            new_tree = to_tree
 
740
        else:
 
741
            old_tree = to_tree
 
742
            new_tree = tree
 
743
            new_target, old_target = old_target, new_target
 
744
        differ = Differ(old_tree, new_tree, output_to, text_diff)
 
745
        return differ.diff_symlink(old_target, new_target)
751
746
 
752
747
    def __init__(self, file_id, name, parent_id):
753
748
        super(InventoryLink, self).__init__(file_id, name, parent_id)