/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: Canonical.com Patch Queue Manager
  • Date: 2007-12-19 21:17:25 UTC
  • mfrom: (3123.4.3 no-inventory2)
  • Revision ID: pqm@pqm.ubuntu.com-20071219211725-mgnpnt2keboqflwi
Sort diff results alphabetically

Show diffs side-by-side

added added

removed removed

Lines of Context:
813
813
        """
814
814
        # TODO: Generation of pseudo-diffs for added/deleted files could
815
815
        # be usefully made into a much faster special case.
816
 
 
817
 
        delta = self.new_tree.changes_from(self.old_tree,
818
 
            specific_files=specific_files,
819
 
            extra_trees=extra_trees, require_versioned=True)
820
 
 
 
816
        iterator = self.new_tree._iter_changes(self.old_tree,
 
817
                                               specific_files=specific_files,
 
818
                                               extra_trees=extra_trees,
 
819
                                               require_versioned=True)
821
820
        has_changes = 0
822
 
        for path, file_id, kind in delta.removed:
823
 
            has_changes = 1
824
 
            path_encoded = path.encode(self.path_encoding, "replace")
825
 
            self.to_file.write("=== removed %s '%s'\n" % (kind, path_encoded))
826
 
            self.diff(file_id, path, path)
827
 
 
828
 
        for path, file_id, kind in delta.added:
829
 
            has_changes = 1
830
 
            path_encoded = path.encode(self.path_encoding, "replace")
831
 
            self.to_file.write("=== added %s '%s'\n" % (kind, path_encoded))
832
 
            self.diff(file_id, path, path)
833
 
        for (old_path, new_path, file_id, kind,
834
 
             text_modified, meta_modified) in delta.renamed:
835
 
            has_changes = 1
836
 
            prop_str = get_prop_change(meta_modified)
837
 
            oldpath_encoded = old_path.encode(self.path_encoding, "replace")
838
 
            newpath_encoded = new_path.encode(self.path_encoding, "replace")
839
 
            self.to_file.write("=== renamed %s '%s' => '%s'%s\n" % (kind,
840
 
                                oldpath_encoded, newpath_encoded, prop_str))
841
 
            if text_modified:
842
 
                self.diff(file_id, old_path, new_path)
843
 
        for path, file_id, kind, text_modified, meta_modified in\
844
 
            delta.modified:
845
 
            has_changes = 1
846
 
            prop_str = get_prop_change(meta_modified)
847
 
            path_encoded = path.encode(self.path_encoding, "replace")
848
 
            self.to_file.write("=== modified %s '%s'%s\n" % (kind,
849
 
                                path_encoded, prop_str))
850
 
            # The file may be in a different location in the old tree (because
851
 
            # the containing dir was renamed, but the file itself was not)
852
 
            if text_modified:
853
 
                old_path = self.old_tree.id2path(file_id)
854
 
                self.diff(file_id, old_path, path)
 
821
        def changes_key(change):
 
822
            old_path, new_path = change[1]
 
823
            path = new_path
 
824
            if path is None:
 
825
                path = old_path
 
826
            return path
 
827
        def get_encoded_path(path):
 
828
            if path is not None:
 
829
                return path.encode(self.path_encoding, "replace")
 
830
        for (file_id, paths, changed_content, versioned, parent, name, kind,
 
831
             executable) in sorted(iterator, key=changes_key):
 
832
            if parent == (None, None):
 
833
                continue
 
834
            oldpath, newpath = paths
 
835
            oldpath_encoded = get_encoded_path(paths[0])
 
836
            newpath_encoded = get_encoded_path(paths[1])
 
837
            old_present = (kind[0] is not None and versioned[0])
 
838
            new_present = (kind[1] is not None and versioned[1])
 
839
            renamed = (parent[0], name[0]) != (parent[1], name[1])
 
840
            prop_str = get_prop_change(executable[0] != executable[1])
 
841
            if (old_present, new_present) == (True, False):
 
842
                self.to_file.write("=== removed %s '%s'\n" %
 
843
                                   (kind[0], oldpath_encoded))
 
844
                newpath = oldpath
 
845
            elif (old_present, new_present) == (False, True):
 
846
                self.to_file.write("=== added %s '%s'\n" %
 
847
                                   (kind[1], newpath_encoded))
 
848
                oldpath = newpath
 
849
            elif renamed:
 
850
                self.to_file.write("=== renamed %s '%s' => '%s'%s\n" %
 
851
                    (kind[0], oldpath_encoded, newpath_encoded, prop_str))
 
852
            else:
 
853
                # if it was produced by _iter_changes, it must be
 
854
                # modified *somehow*, either content or execute bit.
 
855
                self.to_file.write("=== modified %s '%s'%s\n" % (kind[0],
 
856
                                   newpath_encoded, prop_str))
 
857
            if changed_content:
 
858
                self.diff(file_id, oldpath, newpath)
 
859
                has_changes = 1
 
860
            if renamed:
 
861
                has_changes = 1
855
862
        return has_changes
856
863
 
857
864
    def diff(self, file_id, old_path, new_path):